pdf.combined.js 1.4 MB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791207922079320794207952079620797207982079920800208012080220803208042080520806208072080820809208102081120812208132081420815208162081720818208192082020821208222082320824208252082620827208282082920830208312083220833208342083520836208372083820839208402084120842208432084420845208462084720848208492085020851208522085320854208552085620857208582085920860208612086220863208642086520866208672086820869208702087120872208732087420875208762087720878208792088020881208822088320884208852088620887208882088920890208912089220893208942089520896208972089820899209002090120902209032090420905209062090720908209092091020911209122091320914209152091620917209182091920920209212092220923209242092520926209272092820929209302093120932209332093420935209362093720938209392094020941209422094320944209452094620947209482094920950209512095220953209542095520956209572095820959209602096120962209632096420965209662096720968209692097020971209722097320974209752097620977209782097920980209812098220983209842098520986209872098820989209902099120992209932099420995209962099720998209992100021001210022100321004210052100621007210082100921010210112101221013210142101521016210172101821019210202102121022210232102421025210262102721028210292103021031210322103321034210352103621037210382103921040210412104221043210442104521046210472104821049210502105121052210532105421055210562105721058210592106021061210622106321064210652106621067210682106921070210712107221073210742107521076210772107821079210802108121082210832108421085210862108721088210892109021091210922109321094210952109621097210982109921100211012110221103211042110521106211072110821109211102111121112211132111421115211162111721118211192112021121211222112321124211252112621127211282112921130211312113221133211342113521136211372113821139211402114121142211432114421145211462114721148211492115021151211522115321154211552115621157211582115921160211612116221163211642116521166211672116821169211702117121172211732117421175211762117721178211792118021181211822118321184211852118621187211882118921190211912119221193211942119521196211972119821199212002120121202212032120421205212062120721208212092121021211212122121321214212152121621217212182121921220212212122221223212242122521226212272122821229212302123121232212332123421235212362123721238212392124021241212422124321244212452124621247212482124921250212512125221253212542125521256212572125821259212602126121262212632126421265212662126721268212692127021271212722127321274212752127621277212782127921280212812128221283212842128521286212872128821289212902129121292212932129421295212962129721298212992130021301213022130321304213052130621307213082130921310213112131221313213142131521316213172131821319213202132121322213232132421325213262132721328213292133021331213322133321334213352133621337213382133921340213412134221343213442134521346213472134821349213502135121352213532135421355213562135721358213592136021361213622136321364213652136621367213682136921370213712137221373213742137521376213772137821379213802138121382213832138421385213862138721388213892139021391213922139321394213952139621397213982139921400214012140221403214042140521406214072140821409214102141121412214132141421415214162141721418214192142021421214222142321424214252142621427214282142921430214312143221433214342143521436214372143821439214402144121442214432144421445214462144721448214492145021451214522145321454214552145621457214582145921460214612146221463214642146521466214672146821469214702147121472214732147421475214762147721478214792148021481214822148321484214852148621487214882148921490214912149221493214942149521496214972149821499215002150121502215032150421505215062150721508215092151021511215122151321514215152151621517215182151921520215212152221523215242152521526215272152821529215302153121532215332153421535215362153721538215392154021541215422154321544215452154621547215482154921550215512155221553215542155521556215572155821559215602156121562215632156421565215662156721568215692157021571215722157321574215752157621577215782157921580215812158221583215842158521586215872158821589215902159121592215932159421595215962159721598215992160021601216022160321604216052160621607216082160921610216112161221613216142161521616216172161821619216202162121622216232162421625216262162721628216292163021631216322163321634216352163621637216382163921640216412164221643216442164521646216472164821649216502165121652216532165421655216562165721658216592166021661216622166321664216652166621667216682166921670216712167221673216742167521676216772167821679216802168121682216832168421685216862168721688216892169021691216922169321694216952169621697216982169921700217012170221703217042170521706217072170821709217102171121712217132171421715217162171721718217192172021721217222172321724217252172621727217282172921730217312173221733217342173521736217372173821739217402174121742217432174421745217462174721748217492175021751217522175321754217552175621757217582175921760217612176221763217642176521766217672176821769217702177121772217732177421775217762177721778217792178021781217822178321784217852178621787217882178921790217912179221793217942179521796217972179821799218002180121802218032180421805218062180721808218092181021811218122181321814218152181621817218182181921820218212182221823218242182521826218272182821829218302183121832218332183421835218362183721838218392184021841218422184321844218452184621847218482184921850218512185221853218542185521856218572185821859218602186121862218632186421865218662186721868218692187021871218722187321874218752187621877218782187921880218812188221883218842188521886218872188821889218902189121892218932189421895218962189721898218992190021901219022190321904219052190621907219082190921910219112191221913219142191521916219172191821919219202192121922219232192421925219262192721928219292193021931219322193321934219352193621937219382193921940219412194221943219442194521946219472194821949219502195121952219532195421955219562195721958219592196021961219622196321964219652196621967219682196921970219712197221973219742197521976219772197821979219802198121982219832198421985219862198721988219892199021991219922199321994219952199621997219982199922000220012200222003220042200522006220072200822009220102201122012220132201422015220162201722018220192202022021220222202322024220252202622027220282202922030220312203222033220342203522036220372203822039220402204122042220432204422045220462204722048220492205022051220522205322054220552205622057220582205922060220612206222063220642206522066220672206822069220702207122072220732207422075220762207722078220792208022081220822208322084220852208622087220882208922090220912209222093220942209522096220972209822099221002210122102221032210422105221062210722108221092211022111221122211322114221152211622117221182211922120221212212222123221242212522126221272212822129221302213122132221332213422135221362213722138221392214022141221422214322144221452214622147221482214922150221512215222153221542215522156221572215822159221602216122162221632216422165221662216722168221692217022171221722217322174221752217622177221782217922180221812218222183221842218522186221872218822189221902219122192221932219422195221962219722198221992220022201222022220322204222052220622207222082220922210222112221222213222142221522216222172221822219222202222122222222232222422225222262222722228222292223022231222322223322234222352223622237222382223922240222412224222243222442224522246222472224822249222502225122252222532225422255222562225722258222592226022261222622226322264222652226622267222682226922270222712227222273222742227522276222772227822279222802228122282222832228422285222862228722288222892229022291222922229322294222952229622297222982229922300223012230222303223042230522306223072230822309223102231122312223132231422315223162231722318223192232022321223222232322324223252232622327223282232922330223312233222333223342233522336223372233822339223402234122342223432234422345223462234722348223492235022351223522235322354223552235622357223582235922360223612236222363223642236522366223672236822369223702237122372223732237422375223762237722378223792238022381223822238322384223852238622387223882238922390223912239222393223942239522396223972239822399224002240122402224032240422405224062240722408224092241022411224122241322414224152241622417224182241922420224212242222423224242242522426224272242822429224302243122432224332243422435224362243722438224392244022441224422244322444224452244622447224482244922450224512245222453224542245522456224572245822459224602246122462224632246422465224662246722468224692247022471224722247322474224752247622477224782247922480224812248222483224842248522486224872248822489224902249122492224932249422495224962249722498224992250022501225022250322504225052250622507225082250922510225112251222513225142251522516225172251822519225202252122522225232252422525225262252722528225292253022531225322253322534225352253622537225382253922540225412254222543225442254522546225472254822549225502255122552225532255422555225562255722558225592256022561225622256322564225652256622567225682256922570225712257222573225742257522576225772257822579225802258122582225832258422585225862258722588225892259022591225922259322594225952259622597225982259922600226012260222603226042260522606226072260822609226102261122612226132261422615226162261722618226192262022621226222262322624226252262622627226282262922630226312263222633226342263522636226372263822639226402264122642226432264422645226462264722648226492265022651226522265322654226552265622657226582265922660226612266222663226642266522666226672266822669226702267122672226732267422675226762267722678226792268022681226822268322684226852268622687226882268922690226912269222693226942269522696226972269822699227002270122702227032270422705227062270722708227092271022711227122271322714227152271622717227182271922720227212272222723227242272522726227272272822729227302273122732227332273422735227362273722738227392274022741227422274322744227452274622747227482274922750227512275222753227542275522756227572275822759227602276122762227632276422765227662276722768227692277022771227722277322774227752277622777227782277922780227812278222783227842278522786227872278822789227902279122792227932279422795227962279722798227992280022801228022280322804228052280622807228082280922810228112281222813228142281522816228172281822819228202282122822228232282422825228262282722828228292283022831228322283322834228352283622837228382283922840228412284222843228442284522846228472284822849228502285122852228532285422855228562285722858228592286022861228622286322864228652286622867228682286922870228712287222873228742287522876228772287822879228802288122882228832288422885228862288722888228892289022891228922289322894228952289622897228982289922900229012290222903229042290522906229072290822909229102291122912229132291422915229162291722918229192292022921229222292322924229252292622927229282292922930229312293222933229342293522936229372293822939229402294122942229432294422945229462294722948229492295022951229522295322954229552295622957229582295922960229612296222963229642296522966229672296822969229702297122972229732297422975229762297722978229792298022981229822298322984229852298622987229882298922990229912299222993229942299522996229972299822999230002300123002230032300423005230062300723008230092301023011230122301323014230152301623017230182301923020230212302223023230242302523026230272302823029230302303123032230332303423035230362303723038230392304023041230422304323044230452304623047230482304923050230512305223053230542305523056230572305823059230602306123062230632306423065230662306723068230692307023071230722307323074230752307623077230782307923080230812308223083230842308523086230872308823089230902309123092230932309423095230962309723098230992310023101231022310323104231052310623107231082310923110231112311223113231142311523116231172311823119231202312123122231232312423125231262312723128231292313023131231322313323134231352313623137231382313923140231412314223143231442314523146231472314823149231502315123152231532315423155231562315723158231592316023161231622316323164231652316623167231682316923170231712317223173231742317523176231772317823179231802318123182231832318423185231862318723188231892319023191231922319323194231952319623197231982319923200232012320223203232042320523206232072320823209232102321123212232132321423215232162321723218232192322023221232222322323224232252322623227232282322923230232312323223233232342323523236232372323823239232402324123242232432324423245232462324723248232492325023251232522325323254232552325623257232582325923260232612326223263232642326523266232672326823269232702327123272232732327423275232762327723278232792328023281232822328323284232852328623287232882328923290232912329223293232942329523296232972329823299233002330123302233032330423305233062330723308233092331023311233122331323314233152331623317233182331923320233212332223323233242332523326233272332823329233302333123332233332333423335233362333723338233392334023341233422334323344233452334623347233482334923350233512335223353233542335523356233572335823359233602336123362233632336423365233662336723368233692337023371233722337323374233752337623377233782337923380233812338223383233842338523386233872338823389233902339123392233932339423395233962339723398233992340023401234022340323404234052340623407234082340923410234112341223413234142341523416234172341823419234202342123422234232342423425234262342723428234292343023431234322343323434234352343623437234382343923440234412344223443234442344523446234472344823449234502345123452234532345423455234562345723458234592346023461234622346323464234652346623467234682346923470234712347223473234742347523476234772347823479234802348123482234832348423485234862348723488234892349023491234922349323494234952349623497234982349923500235012350223503235042350523506235072350823509235102351123512235132351423515235162351723518235192352023521235222352323524235252352623527235282352923530235312353223533235342353523536235372353823539235402354123542235432354423545235462354723548235492355023551235522355323554235552355623557235582355923560235612356223563235642356523566235672356823569235702357123572235732357423575235762357723578235792358023581235822358323584235852358623587235882358923590235912359223593235942359523596235972359823599236002360123602236032360423605236062360723608236092361023611236122361323614236152361623617236182361923620236212362223623236242362523626236272362823629236302363123632236332363423635236362363723638236392364023641236422364323644236452364623647236482364923650236512365223653236542365523656236572365823659236602366123662236632366423665236662366723668236692367023671236722367323674236752367623677236782367923680236812368223683236842368523686236872368823689236902369123692236932369423695236962369723698236992370023701237022370323704237052370623707237082370923710237112371223713237142371523716237172371823719237202372123722237232372423725237262372723728237292373023731237322373323734237352373623737237382373923740237412374223743237442374523746237472374823749237502375123752237532375423755237562375723758237592376023761237622376323764237652376623767237682376923770237712377223773237742377523776237772377823779237802378123782237832378423785237862378723788237892379023791237922379323794237952379623797237982379923800238012380223803238042380523806238072380823809238102381123812238132381423815238162381723818238192382023821238222382323824238252382623827238282382923830238312383223833238342383523836238372383823839238402384123842238432384423845238462384723848238492385023851238522385323854238552385623857238582385923860238612386223863238642386523866238672386823869238702387123872238732387423875238762387723878238792388023881238822388323884238852388623887238882388923890238912389223893238942389523896238972389823899239002390123902239032390423905239062390723908239092391023911239122391323914239152391623917239182391923920239212392223923239242392523926239272392823929239302393123932239332393423935239362393723938239392394023941239422394323944239452394623947239482394923950239512395223953239542395523956239572395823959239602396123962239632396423965239662396723968239692397023971239722397323974239752397623977239782397923980239812398223983239842398523986239872398823989239902399123992239932399423995239962399723998239992400024001240022400324004240052400624007240082400924010240112401224013240142401524016240172401824019240202402124022240232402424025240262402724028240292403024031240322403324034240352403624037240382403924040240412404224043240442404524046240472404824049240502405124052240532405424055240562405724058240592406024061240622406324064240652406624067240682406924070240712407224073240742407524076240772407824079240802408124082240832408424085240862408724088240892409024091240922409324094240952409624097240982409924100241012410224103241042410524106241072410824109241102411124112241132411424115241162411724118241192412024121241222412324124241252412624127241282412924130241312413224133241342413524136241372413824139241402414124142241432414424145241462414724148241492415024151241522415324154241552415624157241582415924160241612416224163241642416524166241672416824169241702417124172241732417424175241762417724178241792418024181241822418324184241852418624187241882418924190241912419224193241942419524196241972419824199242002420124202242032420424205242062420724208242092421024211242122421324214242152421624217242182421924220242212422224223242242422524226242272422824229242302423124232242332423424235242362423724238242392424024241242422424324244242452424624247242482424924250242512425224253242542425524256242572425824259242602426124262242632426424265242662426724268242692427024271242722427324274242752427624277242782427924280242812428224283242842428524286242872428824289242902429124292242932429424295242962429724298242992430024301243022430324304243052430624307243082430924310243112431224313243142431524316243172431824319243202432124322243232432424325243262432724328243292433024331243322433324334243352433624337243382433924340243412434224343243442434524346243472434824349243502435124352243532435424355243562435724358243592436024361243622436324364243652436624367243682436924370243712437224373243742437524376243772437824379243802438124382243832438424385243862438724388243892439024391243922439324394243952439624397243982439924400244012440224403244042440524406244072440824409244102441124412244132441424415244162441724418244192442024421244222442324424244252442624427244282442924430244312443224433244342443524436244372443824439244402444124442244432444424445244462444724448244492445024451244522445324454244552445624457244582445924460244612446224463244642446524466244672446824469244702447124472244732447424475244762447724478244792448024481244822448324484244852448624487244882448924490244912449224493244942449524496244972449824499245002450124502245032450424505245062450724508245092451024511245122451324514245152451624517245182451924520245212452224523245242452524526245272452824529245302453124532245332453424535245362453724538245392454024541245422454324544245452454624547245482454924550245512455224553245542455524556245572455824559245602456124562245632456424565245662456724568245692457024571245722457324574245752457624577245782457924580245812458224583245842458524586245872458824589245902459124592245932459424595245962459724598245992460024601246022460324604246052460624607246082460924610246112461224613246142461524616246172461824619246202462124622246232462424625246262462724628246292463024631246322463324634246352463624637246382463924640246412464224643246442464524646246472464824649246502465124652246532465424655246562465724658246592466024661246622466324664246652466624667246682466924670246712467224673246742467524676246772467824679246802468124682246832468424685246862468724688246892469024691246922469324694246952469624697246982469924700247012470224703247042470524706247072470824709247102471124712247132471424715247162471724718247192472024721247222472324724247252472624727247282472924730247312473224733247342473524736247372473824739247402474124742247432474424745247462474724748247492475024751247522475324754247552475624757247582475924760247612476224763247642476524766247672476824769247702477124772247732477424775247762477724778247792478024781247822478324784247852478624787247882478924790247912479224793247942479524796247972479824799248002480124802248032480424805248062480724808248092481024811248122481324814248152481624817248182481924820248212482224823248242482524826248272482824829248302483124832248332483424835248362483724838248392484024841248422484324844248452484624847248482484924850248512485224853248542485524856248572485824859248602486124862248632486424865248662486724868248692487024871248722487324874248752487624877248782487924880248812488224883248842488524886248872488824889248902489124892248932489424895248962489724898248992490024901249022490324904249052490624907249082490924910249112491224913249142491524916249172491824919249202492124922249232492424925249262492724928249292493024931249322493324934249352493624937249382493924940249412494224943249442494524946249472494824949249502495124952249532495424955249562495724958249592496024961249622496324964249652496624967249682496924970249712497224973249742497524976249772497824979249802498124982249832498424985249862498724988249892499024991249922499324994249952499624997249982499925000250012500225003250042500525006250072500825009250102501125012250132501425015250162501725018250192502025021250222502325024250252502625027250282502925030250312503225033250342503525036250372503825039250402504125042250432504425045250462504725048250492505025051250522505325054250552505625057250582505925060250612506225063250642506525066250672506825069250702507125072250732507425075250762507725078250792508025081250822508325084250852508625087250882508925090250912509225093250942509525096250972509825099251002510125102251032510425105251062510725108251092511025111251122511325114251152511625117251182511925120251212512225123251242512525126251272512825129251302513125132251332513425135251362513725138251392514025141251422514325144251452514625147251482514925150251512515225153251542515525156251572515825159251602516125162251632516425165251662516725168251692517025171251722517325174251752517625177251782517925180251812518225183251842518525186251872518825189251902519125192251932519425195251962519725198251992520025201252022520325204252052520625207252082520925210252112521225213252142521525216252172521825219252202522125222252232522425225252262522725228252292523025231252322523325234252352523625237252382523925240252412524225243252442524525246252472524825249252502525125252252532525425255252562525725258252592526025261252622526325264252652526625267252682526925270252712527225273252742527525276252772527825279252802528125282252832528425285252862528725288252892529025291252922529325294252952529625297252982529925300253012530225303253042530525306253072530825309253102531125312253132531425315253162531725318253192532025321253222532325324253252532625327253282532925330253312533225333253342533525336253372533825339253402534125342253432534425345253462534725348253492535025351253522535325354253552535625357253582535925360253612536225363253642536525366253672536825369253702537125372253732537425375253762537725378253792538025381253822538325384253852538625387253882538925390253912539225393253942539525396253972539825399254002540125402254032540425405254062540725408254092541025411254122541325414254152541625417254182541925420254212542225423254242542525426254272542825429254302543125432254332543425435254362543725438254392544025441254422544325444254452544625447254482544925450254512545225453254542545525456254572545825459254602546125462254632546425465254662546725468254692547025471254722547325474254752547625477254782547925480254812548225483254842548525486254872548825489254902549125492254932549425495254962549725498254992550025501255022550325504255052550625507255082550925510255112551225513255142551525516255172551825519255202552125522255232552425525255262552725528255292553025531255322553325534255352553625537255382553925540255412554225543255442554525546255472554825549255502555125552255532555425555255562555725558255592556025561255622556325564255652556625567255682556925570255712557225573255742557525576255772557825579255802558125582255832558425585255862558725588255892559025591255922559325594255952559625597255982559925600256012560225603256042560525606256072560825609256102561125612256132561425615256162561725618256192562025621256222562325624256252562625627256282562925630256312563225633256342563525636256372563825639256402564125642256432564425645256462564725648256492565025651256522565325654256552565625657256582565925660256612566225663256642566525666256672566825669256702567125672256732567425675256762567725678256792568025681256822568325684256852568625687256882568925690256912569225693256942569525696256972569825699257002570125702257032570425705257062570725708257092571025711257122571325714257152571625717257182571925720257212572225723257242572525726257272572825729257302573125732257332573425735257362573725738257392574025741257422574325744257452574625747257482574925750257512575225753257542575525756257572575825759257602576125762257632576425765257662576725768257692577025771257722577325774257752577625777257782577925780257812578225783257842578525786257872578825789257902579125792257932579425795257962579725798257992580025801258022580325804258052580625807258082580925810258112581225813258142581525816258172581825819258202582125822258232582425825258262582725828258292583025831258322583325834258352583625837258382583925840258412584225843258442584525846258472584825849258502585125852258532585425855258562585725858258592586025861258622586325864258652586625867258682586925870258712587225873258742587525876258772587825879258802588125882258832588425885258862588725888258892589025891258922589325894258952589625897258982589925900259012590225903259042590525906259072590825909259102591125912259132591425915259162591725918259192592025921259222592325924259252592625927259282592925930259312593225933259342593525936259372593825939259402594125942259432594425945259462594725948259492595025951259522595325954259552595625957259582595925960259612596225963259642596525966259672596825969259702597125972259732597425975259762597725978259792598025981259822598325984259852598625987259882598925990259912599225993259942599525996259972599825999260002600126002260032600426005260062600726008260092601026011260122601326014260152601626017260182601926020260212602226023260242602526026260272602826029260302603126032260332603426035260362603726038260392604026041260422604326044260452604626047260482604926050260512605226053260542605526056260572605826059260602606126062260632606426065260662606726068260692607026071260722607326074260752607626077260782607926080260812608226083260842608526086260872608826089260902609126092260932609426095260962609726098260992610026101261022610326104261052610626107261082610926110261112611226113261142611526116261172611826119261202612126122261232612426125261262612726128261292613026131261322613326134261352613626137261382613926140261412614226143261442614526146261472614826149261502615126152261532615426155261562615726158261592616026161261622616326164261652616626167261682616926170261712617226173261742617526176261772617826179261802618126182261832618426185261862618726188261892619026191261922619326194261952619626197261982619926200262012620226203262042620526206262072620826209262102621126212262132621426215262162621726218262192622026221262222622326224262252622626227262282622926230262312623226233262342623526236262372623826239262402624126242262432624426245262462624726248262492625026251262522625326254262552625626257262582625926260262612626226263262642626526266262672626826269262702627126272262732627426275262762627726278262792628026281262822628326284262852628626287262882628926290262912629226293262942629526296262972629826299263002630126302263032630426305263062630726308263092631026311263122631326314263152631626317263182631926320263212632226323263242632526326263272632826329263302633126332263332633426335263362633726338263392634026341263422634326344263452634626347263482634926350263512635226353263542635526356263572635826359263602636126362263632636426365263662636726368263692637026371263722637326374263752637626377263782637926380263812638226383263842638526386263872638826389263902639126392263932639426395263962639726398263992640026401264022640326404264052640626407264082640926410264112641226413264142641526416264172641826419264202642126422264232642426425264262642726428264292643026431264322643326434264352643626437264382643926440264412644226443264442644526446264472644826449264502645126452264532645426455264562645726458264592646026461264622646326464264652646626467264682646926470264712647226473264742647526476264772647826479264802648126482264832648426485264862648726488264892649026491264922649326494264952649626497264982649926500265012650226503265042650526506265072650826509265102651126512265132651426515265162651726518265192652026521265222652326524265252652626527265282652926530265312653226533265342653526536265372653826539265402654126542265432654426545265462654726548265492655026551265522655326554265552655626557265582655926560265612656226563265642656526566265672656826569265702657126572265732657426575265762657726578265792658026581265822658326584265852658626587265882658926590265912659226593265942659526596265972659826599266002660126602266032660426605266062660726608266092661026611266122661326614266152661626617266182661926620266212662226623266242662526626266272662826629266302663126632266332663426635266362663726638266392664026641266422664326644266452664626647266482664926650266512665226653266542665526656266572665826659266602666126662266632666426665266662666726668266692667026671266722667326674266752667626677266782667926680266812668226683266842668526686266872668826689266902669126692266932669426695266962669726698266992670026701267022670326704267052670626707267082670926710267112671226713267142671526716267172671826719267202672126722267232672426725267262672726728267292673026731267322673326734267352673626737267382673926740267412674226743267442674526746267472674826749267502675126752267532675426755267562675726758267592676026761267622676326764267652676626767267682676926770267712677226773267742677526776267772677826779267802678126782267832678426785267862678726788267892679026791267922679326794267952679626797267982679926800268012680226803268042680526806268072680826809268102681126812268132681426815268162681726818268192682026821268222682326824268252682626827268282682926830268312683226833268342683526836268372683826839268402684126842268432684426845268462684726848268492685026851268522685326854268552685626857268582685926860268612686226863268642686526866268672686826869268702687126872268732687426875268762687726878268792688026881268822688326884268852688626887268882688926890268912689226893268942689526896268972689826899269002690126902269032690426905269062690726908269092691026911269122691326914269152691626917269182691926920269212692226923269242692526926269272692826929269302693126932269332693426935269362693726938269392694026941269422694326944269452694626947269482694926950269512695226953269542695526956269572695826959269602696126962269632696426965269662696726968269692697026971269722697326974269752697626977269782697926980269812698226983269842698526986269872698826989269902699126992269932699426995269962699726998269992700027001270022700327004270052700627007270082700927010270112701227013270142701527016270172701827019270202702127022270232702427025270262702727028270292703027031270322703327034270352703627037270382703927040270412704227043270442704527046270472704827049270502705127052270532705427055270562705727058270592706027061270622706327064270652706627067270682706927070270712707227073270742707527076270772707827079270802708127082270832708427085270862708727088270892709027091270922709327094270952709627097270982709927100271012710227103271042710527106271072710827109271102711127112271132711427115271162711727118271192712027121271222712327124271252712627127271282712927130271312713227133271342713527136271372713827139271402714127142271432714427145271462714727148271492715027151271522715327154271552715627157271582715927160271612716227163271642716527166271672716827169271702717127172271732717427175271762717727178271792718027181271822718327184271852718627187271882718927190271912719227193271942719527196271972719827199272002720127202272032720427205272062720727208272092721027211272122721327214272152721627217272182721927220272212722227223272242722527226272272722827229272302723127232272332723427235272362723727238272392724027241272422724327244272452724627247272482724927250272512725227253272542725527256272572725827259272602726127262272632726427265272662726727268272692727027271272722727327274272752727627277272782727927280272812728227283272842728527286272872728827289272902729127292272932729427295272962729727298272992730027301273022730327304273052730627307273082730927310273112731227313273142731527316273172731827319273202732127322273232732427325273262732727328273292733027331273322733327334273352733627337273382733927340273412734227343273442734527346273472734827349273502735127352273532735427355273562735727358273592736027361273622736327364273652736627367273682736927370273712737227373273742737527376273772737827379273802738127382273832738427385273862738727388273892739027391273922739327394273952739627397273982739927400274012740227403274042740527406274072740827409274102741127412274132741427415274162741727418274192742027421274222742327424274252742627427274282742927430274312743227433274342743527436274372743827439274402744127442274432744427445274462744727448274492745027451274522745327454274552745627457274582745927460274612746227463274642746527466274672746827469274702747127472274732747427475274762747727478274792748027481274822748327484274852748627487274882748927490274912749227493274942749527496274972749827499275002750127502275032750427505275062750727508275092751027511275122751327514275152751627517275182751927520275212752227523275242752527526275272752827529275302753127532275332753427535275362753727538275392754027541275422754327544275452754627547275482754927550275512755227553275542755527556275572755827559275602756127562275632756427565275662756727568275692757027571275722757327574275752757627577275782757927580275812758227583275842758527586275872758827589275902759127592275932759427595275962759727598275992760027601276022760327604276052760627607276082760927610276112761227613276142761527616276172761827619276202762127622276232762427625276262762727628276292763027631276322763327634276352763627637276382763927640276412764227643276442764527646276472764827649276502765127652276532765427655276562765727658276592766027661276622766327664276652766627667276682766927670276712767227673276742767527676276772767827679276802768127682276832768427685276862768727688276892769027691276922769327694276952769627697276982769927700277012770227703277042770527706277072770827709277102771127712277132771427715277162771727718277192772027721277222772327724277252772627727277282772927730277312773227733277342773527736277372773827739277402774127742277432774427745277462774727748277492775027751277522775327754277552775627757277582775927760277612776227763277642776527766277672776827769277702777127772277732777427775277762777727778277792778027781277822778327784277852778627787277882778927790277912779227793277942779527796277972779827799278002780127802278032780427805278062780727808278092781027811278122781327814278152781627817278182781927820278212782227823278242782527826278272782827829278302783127832278332783427835278362783727838278392784027841278422784327844278452784627847278482784927850278512785227853278542785527856278572785827859278602786127862278632786427865278662786727868278692787027871278722787327874278752787627877278782787927880278812788227883278842788527886278872788827889278902789127892278932789427895278962789727898278992790027901279022790327904279052790627907279082790927910279112791227913279142791527916279172791827919279202792127922279232792427925279262792727928279292793027931279322793327934279352793627937279382793927940279412794227943279442794527946279472794827949279502795127952279532795427955279562795727958279592796027961279622796327964279652796627967279682796927970279712797227973279742797527976279772797827979279802798127982279832798427985279862798727988279892799027991279922799327994279952799627997279982799928000280012800228003280042800528006280072800828009280102801128012280132801428015280162801728018280192802028021280222802328024280252802628027280282802928030280312803228033280342803528036280372803828039280402804128042280432804428045280462804728048280492805028051280522805328054280552805628057280582805928060280612806228063280642806528066280672806828069280702807128072280732807428075280762807728078280792808028081280822808328084280852808628087280882808928090280912809228093280942809528096280972809828099281002810128102281032810428105281062810728108281092811028111281122811328114281152811628117281182811928120281212812228123281242812528126281272812828129281302813128132281332813428135281362813728138281392814028141281422814328144281452814628147281482814928150281512815228153281542815528156281572815828159281602816128162281632816428165281662816728168281692817028171281722817328174281752817628177281782817928180281812818228183281842818528186281872818828189281902819128192281932819428195281962819728198281992820028201282022820328204282052820628207282082820928210282112821228213282142821528216282172821828219282202822128222282232822428225282262822728228282292823028231282322823328234282352823628237282382823928240282412824228243282442824528246282472824828249282502825128252282532825428255282562825728258282592826028261282622826328264282652826628267282682826928270282712827228273282742827528276282772827828279282802828128282282832828428285282862828728288282892829028291282922829328294282952829628297282982829928300283012830228303283042830528306283072830828309283102831128312283132831428315283162831728318283192832028321283222832328324283252832628327283282832928330283312833228333283342833528336283372833828339283402834128342283432834428345283462834728348283492835028351283522835328354283552835628357283582835928360283612836228363283642836528366283672836828369283702837128372283732837428375283762837728378283792838028381283822838328384283852838628387283882838928390283912839228393283942839528396283972839828399284002840128402284032840428405284062840728408284092841028411284122841328414284152841628417284182841928420284212842228423284242842528426284272842828429284302843128432284332843428435284362843728438284392844028441284422844328444284452844628447284482844928450284512845228453284542845528456284572845828459284602846128462284632846428465284662846728468284692847028471284722847328474284752847628477284782847928480284812848228483284842848528486284872848828489284902849128492284932849428495284962849728498284992850028501285022850328504285052850628507285082850928510285112851228513285142851528516285172851828519285202852128522285232852428525285262852728528285292853028531285322853328534285352853628537285382853928540285412854228543285442854528546285472854828549285502855128552285532855428555285562855728558285592856028561285622856328564285652856628567285682856928570285712857228573285742857528576285772857828579285802858128582285832858428585285862858728588285892859028591285922859328594285952859628597285982859928600286012860228603286042860528606286072860828609286102861128612286132861428615286162861728618286192862028621286222862328624286252862628627286282862928630286312863228633286342863528636286372863828639286402864128642286432864428645286462864728648286492865028651286522865328654286552865628657286582865928660286612866228663286642866528666286672866828669286702867128672286732867428675286762867728678286792868028681286822868328684286852868628687286882868928690286912869228693286942869528696286972869828699287002870128702287032870428705287062870728708287092871028711287122871328714287152871628717287182871928720287212872228723287242872528726287272872828729287302873128732287332873428735287362873728738287392874028741287422874328744287452874628747287482874928750287512875228753287542875528756287572875828759287602876128762287632876428765287662876728768287692877028771287722877328774287752877628777287782877928780287812878228783287842878528786287872878828789287902879128792287932879428795287962879728798287992880028801288022880328804288052880628807288082880928810288112881228813288142881528816288172881828819288202882128822288232882428825288262882728828288292883028831288322883328834288352883628837288382883928840288412884228843288442884528846288472884828849288502885128852288532885428855288562885728858288592886028861288622886328864288652886628867288682886928870288712887228873288742887528876288772887828879288802888128882288832888428885288862888728888288892889028891288922889328894288952889628897288982889928900289012890228903289042890528906289072890828909289102891128912289132891428915289162891728918289192892028921289222892328924289252892628927289282892928930289312893228933289342893528936289372893828939289402894128942289432894428945289462894728948289492895028951289522895328954289552895628957289582895928960289612896228963289642896528966289672896828969289702897128972289732897428975289762897728978289792898028981289822898328984289852898628987289882898928990289912899228993289942899528996289972899828999290002900129002290032900429005290062900729008290092901029011290122901329014290152901629017290182901929020290212902229023290242902529026290272902829029290302903129032290332903429035290362903729038290392904029041290422904329044290452904629047290482904929050290512905229053290542905529056290572905829059290602906129062290632906429065290662906729068290692907029071290722907329074290752907629077290782907929080290812908229083290842908529086290872908829089290902909129092290932909429095290962909729098290992910029101291022910329104291052910629107291082910929110291112911229113291142911529116291172911829119291202912129122291232912429125291262912729128291292913029131291322913329134291352913629137291382913929140291412914229143291442914529146291472914829149291502915129152291532915429155291562915729158291592916029161291622916329164291652916629167291682916929170291712917229173291742917529176291772917829179291802918129182291832918429185291862918729188291892919029191291922919329194291952919629197291982919929200292012920229203292042920529206292072920829209292102921129212292132921429215292162921729218292192922029221292222922329224292252922629227292282922929230292312923229233292342923529236292372923829239292402924129242292432924429245292462924729248292492925029251292522925329254292552925629257292582925929260292612926229263292642926529266292672926829269292702927129272292732927429275292762927729278292792928029281292822928329284292852928629287292882928929290292912929229293292942929529296292972929829299293002930129302293032930429305293062930729308293092931029311293122931329314293152931629317293182931929320293212932229323293242932529326293272932829329293302933129332293332933429335293362933729338293392934029341293422934329344293452934629347293482934929350293512935229353293542935529356293572935829359293602936129362293632936429365293662936729368293692937029371293722937329374293752937629377293782937929380293812938229383293842938529386293872938829389293902939129392293932939429395293962939729398293992940029401294022940329404294052940629407294082940929410294112941229413294142941529416294172941829419294202942129422294232942429425294262942729428294292943029431294322943329434294352943629437294382943929440294412944229443294442944529446294472944829449294502945129452294532945429455294562945729458294592946029461294622946329464294652946629467294682946929470294712947229473294742947529476294772947829479294802948129482294832948429485294862948729488294892949029491294922949329494294952949629497294982949929500295012950229503295042950529506295072950829509295102951129512295132951429515295162951729518295192952029521295222952329524295252952629527295282952929530295312953229533295342953529536295372953829539295402954129542295432954429545295462954729548295492955029551295522955329554295552955629557295582955929560295612956229563295642956529566295672956829569295702957129572295732957429575295762957729578295792958029581295822958329584295852958629587295882958929590295912959229593295942959529596295972959829599296002960129602296032960429605296062960729608296092961029611296122961329614296152961629617296182961929620296212962229623296242962529626296272962829629296302963129632296332963429635296362963729638296392964029641296422964329644296452964629647296482964929650296512965229653296542965529656296572965829659296602966129662296632966429665296662966729668296692967029671296722967329674296752967629677296782967929680296812968229683296842968529686296872968829689296902969129692296932969429695296962969729698296992970029701297022970329704297052970629707297082970929710297112971229713297142971529716297172971829719297202972129722297232972429725297262972729728297292973029731297322973329734297352973629737297382973929740297412974229743297442974529746297472974829749297502975129752297532975429755297562975729758297592976029761297622976329764297652976629767297682976929770297712977229773297742977529776297772977829779297802978129782297832978429785297862978729788297892979029791297922979329794297952979629797297982979929800298012980229803298042980529806298072980829809298102981129812298132981429815298162981729818298192982029821298222982329824298252982629827298282982929830298312983229833298342983529836298372983829839298402984129842298432984429845298462984729848298492985029851298522985329854298552985629857298582985929860298612986229863298642986529866298672986829869298702987129872298732987429875298762987729878298792988029881298822988329884298852988629887298882988929890298912989229893298942989529896298972989829899299002990129902299032990429905299062990729908299092991029911299122991329914299152991629917299182991929920299212992229923299242992529926299272992829929299302993129932299332993429935299362993729938299392994029941299422994329944299452994629947299482994929950299512995229953299542995529956299572995829959299602996129962299632996429965299662996729968299692997029971299722997329974299752997629977299782997929980299812998229983299842998529986299872998829989299902999129992299932999429995299962999729998299993000030001300023000330004300053000630007300083000930010300113001230013300143001530016300173001830019300203002130022300233002430025300263002730028300293003030031300323003330034300353003630037300383003930040300413004230043300443004530046300473004830049300503005130052300533005430055300563005730058300593006030061300623006330064300653006630067300683006930070300713007230073300743007530076300773007830079300803008130082300833008430085300863008730088300893009030091300923009330094300953009630097300983009930100301013010230103301043010530106301073010830109301103011130112301133011430115301163011730118301193012030121301223012330124301253012630127301283012930130301313013230133301343013530136301373013830139301403014130142301433014430145301463014730148301493015030151301523015330154301553015630157301583015930160301613016230163301643016530166301673016830169301703017130172301733017430175301763017730178301793018030181301823018330184301853018630187301883018930190301913019230193301943019530196301973019830199302003020130202302033020430205302063020730208302093021030211302123021330214302153021630217302183021930220302213022230223302243022530226302273022830229302303023130232302333023430235302363023730238302393024030241302423024330244302453024630247302483024930250302513025230253302543025530256302573025830259302603026130262302633026430265302663026730268302693027030271302723027330274302753027630277302783027930280302813028230283302843028530286302873028830289302903029130292302933029430295302963029730298302993030030301303023030330304303053030630307303083030930310303113031230313303143031530316303173031830319303203032130322303233032430325303263032730328303293033030331303323033330334303353033630337303383033930340303413034230343303443034530346303473034830349303503035130352303533035430355303563035730358303593036030361303623036330364303653036630367303683036930370303713037230373303743037530376303773037830379303803038130382303833038430385303863038730388303893039030391303923039330394303953039630397303983039930400304013040230403304043040530406304073040830409304103041130412304133041430415304163041730418304193042030421304223042330424304253042630427304283042930430304313043230433304343043530436304373043830439304403044130442304433044430445304463044730448304493045030451304523045330454304553045630457304583045930460304613046230463304643046530466304673046830469304703047130472304733047430475304763047730478304793048030481304823048330484304853048630487304883048930490304913049230493304943049530496304973049830499305003050130502305033050430505305063050730508305093051030511305123051330514305153051630517305183051930520305213052230523305243052530526305273052830529305303053130532305333053430535305363053730538305393054030541305423054330544305453054630547305483054930550305513055230553305543055530556305573055830559305603056130562305633056430565305663056730568305693057030571305723057330574305753057630577305783057930580305813058230583305843058530586305873058830589305903059130592305933059430595305963059730598305993060030601306023060330604306053060630607306083060930610306113061230613306143061530616306173061830619306203062130622306233062430625306263062730628306293063030631306323063330634306353063630637306383063930640306413064230643306443064530646306473064830649306503065130652306533065430655306563065730658306593066030661306623066330664306653066630667306683066930670306713067230673306743067530676306773067830679306803068130682306833068430685306863068730688306893069030691306923069330694306953069630697306983069930700307013070230703307043070530706307073070830709307103071130712307133071430715307163071730718307193072030721307223072330724307253072630727307283072930730307313073230733307343073530736307373073830739307403074130742307433074430745307463074730748307493075030751307523075330754307553075630757307583075930760307613076230763307643076530766307673076830769307703077130772307733077430775307763077730778307793078030781307823078330784307853078630787307883078930790307913079230793307943079530796307973079830799308003080130802308033080430805308063080730808308093081030811308123081330814308153081630817308183081930820308213082230823308243082530826308273082830829308303083130832308333083430835308363083730838308393084030841308423084330844308453084630847308483084930850308513085230853308543085530856308573085830859308603086130862308633086430865308663086730868308693087030871308723087330874308753087630877308783087930880308813088230883308843088530886308873088830889308903089130892308933089430895308963089730898308993090030901309023090330904309053090630907309083090930910309113091230913309143091530916309173091830919309203092130922309233092430925309263092730928309293093030931309323093330934309353093630937309383093930940309413094230943309443094530946309473094830949309503095130952309533095430955309563095730958309593096030961309623096330964309653096630967309683096930970309713097230973309743097530976309773097830979309803098130982309833098430985309863098730988309893099030991309923099330994309953099630997309983099931000310013100231003310043100531006310073100831009310103101131012310133101431015310163101731018310193102031021310223102331024310253102631027310283102931030310313103231033310343103531036310373103831039310403104131042310433104431045310463104731048310493105031051310523105331054310553105631057310583105931060310613106231063310643106531066310673106831069310703107131072310733107431075310763107731078310793108031081310823108331084310853108631087310883108931090310913109231093310943109531096310973109831099311003110131102311033110431105311063110731108311093111031111311123111331114311153111631117311183111931120311213112231123311243112531126311273112831129311303113131132311333113431135311363113731138311393114031141311423114331144311453114631147311483114931150311513115231153311543115531156311573115831159311603116131162311633116431165311663116731168311693117031171311723117331174311753117631177311783117931180311813118231183311843118531186311873118831189311903119131192311933119431195311963119731198311993120031201312023120331204312053120631207312083120931210312113121231213312143121531216312173121831219312203122131222312233122431225312263122731228312293123031231312323123331234312353123631237312383123931240312413124231243312443124531246312473124831249312503125131252312533125431255312563125731258312593126031261312623126331264312653126631267312683126931270312713127231273312743127531276312773127831279312803128131282312833128431285312863128731288312893129031291312923129331294312953129631297312983129931300313013130231303313043130531306313073130831309313103131131312313133131431315313163131731318313193132031321313223132331324313253132631327313283132931330313313133231333313343133531336313373133831339313403134131342313433134431345313463134731348313493135031351313523135331354313553135631357313583135931360313613136231363313643136531366313673136831369313703137131372313733137431375313763137731378313793138031381313823138331384313853138631387313883138931390313913139231393313943139531396313973139831399314003140131402314033140431405314063140731408314093141031411314123141331414314153141631417314183141931420314213142231423314243142531426314273142831429314303143131432314333143431435314363143731438314393144031441314423144331444314453144631447314483144931450314513145231453314543145531456314573145831459314603146131462314633146431465314663146731468314693147031471314723147331474314753147631477314783147931480314813148231483314843148531486314873148831489314903149131492314933149431495314963149731498314993150031501315023150331504315053150631507315083150931510315113151231513315143151531516315173151831519315203152131522315233152431525315263152731528315293153031531315323153331534315353153631537315383153931540315413154231543315443154531546315473154831549315503155131552315533155431555315563155731558315593156031561315623156331564315653156631567315683156931570315713157231573315743157531576315773157831579315803158131582315833158431585315863158731588315893159031591315923159331594315953159631597315983159931600316013160231603316043160531606316073160831609316103161131612316133161431615316163161731618316193162031621316223162331624316253162631627316283162931630316313163231633316343163531636316373163831639316403164131642316433164431645316463164731648316493165031651316523165331654316553165631657316583165931660316613166231663316643166531666316673166831669316703167131672316733167431675316763167731678316793168031681316823168331684316853168631687316883168931690316913169231693316943169531696316973169831699317003170131702317033170431705317063170731708317093171031711317123171331714317153171631717317183171931720317213172231723317243172531726317273172831729317303173131732317333173431735317363173731738317393174031741317423174331744317453174631747317483174931750317513175231753317543175531756317573175831759317603176131762317633176431765317663176731768317693177031771317723177331774317753177631777317783177931780317813178231783317843178531786317873178831789317903179131792317933179431795317963179731798317993180031801318023180331804318053180631807318083180931810318113181231813318143181531816318173181831819318203182131822318233182431825318263182731828318293183031831318323183331834318353183631837318383183931840318413184231843318443184531846318473184831849318503185131852318533185431855318563185731858318593186031861318623186331864318653186631867318683186931870318713187231873318743187531876318773187831879318803188131882318833188431885318863188731888318893189031891318923189331894318953189631897318983189931900319013190231903319043190531906319073190831909319103191131912319133191431915319163191731918319193192031921319223192331924319253192631927319283192931930319313193231933319343193531936319373193831939319403194131942319433194431945319463194731948319493195031951319523195331954319553195631957319583195931960319613196231963319643196531966319673196831969319703197131972319733197431975319763197731978319793198031981319823198331984319853198631987319883198931990319913199231993319943199531996319973199831999320003200132002320033200432005320063200732008320093201032011320123201332014320153201632017320183201932020320213202232023320243202532026320273202832029320303203132032320333203432035320363203732038320393204032041320423204332044320453204632047320483204932050320513205232053320543205532056320573205832059320603206132062320633206432065320663206732068320693207032071320723207332074320753207632077320783207932080320813208232083320843208532086320873208832089320903209132092320933209432095320963209732098320993210032101321023210332104321053210632107321083210932110321113211232113321143211532116321173211832119321203212132122321233212432125321263212732128321293213032131321323213332134321353213632137321383213932140321413214232143321443214532146321473214832149321503215132152321533215432155321563215732158321593216032161321623216332164321653216632167321683216932170321713217232173321743217532176321773217832179321803218132182321833218432185321863218732188321893219032191321923219332194321953219632197321983219932200322013220232203322043220532206322073220832209322103221132212322133221432215322163221732218322193222032221322223222332224322253222632227322283222932230322313223232233322343223532236322373223832239322403224132242322433224432245322463224732248322493225032251322523225332254322553225632257322583225932260322613226232263322643226532266322673226832269322703227132272322733227432275322763227732278322793228032281322823228332284322853228632287322883228932290322913229232293322943229532296322973229832299323003230132302323033230432305323063230732308323093231032311323123231332314323153231632317323183231932320323213232232323323243232532326323273232832329323303233132332323333233432335323363233732338323393234032341323423234332344323453234632347323483234932350323513235232353323543235532356323573235832359323603236132362323633236432365323663236732368323693237032371323723237332374323753237632377323783237932380323813238232383323843238532386323873238832389323903239132392323933239432395323963239732398323993240032401324023240332404324053240632407324083240932410324113241232413324143241532416324173241832419324203242132422324233242432425324263242732428324293243032431324323243332434324353243632437324383243932440324413244232443324443244532446324473244832449324503245132452324533245432455324563245732458324593246032461324623246332464324653246632467324683246932470324713247232473324743247532476324773247832479324803248132482324833248432485324863248732488324893249032491324923249332494324953249632497324983249932500325013250232503325043250532506325073250832509325103251132512325133251432515325163251732518325193252032521325223252332524325253252632527325283252932530325313253232533325343253532536325373253832539325403254132542325433254432545325463254732548325493255032551325523255332554325553255632557325583255932560325613256232563325643256532566325673256832569325703257132572325733257432575325763257732578325793258032581325823258332584325853258632587325883258932590325913259232593325943259532596325973259832599326003260132602326033260432605326063260732608326093261032611326123261332614326153261632617326183261932620326213262232623326243262532626326273262832629326303263132632326333263432635326363263732638326393264032641326423264332644326453264632647326483264932650326513265232653326543265532656326573265832659326603266132662326633266432665326663266732668326693267032671326723267332674326753267632677326783267932680326813268232683326843268532686326873268832689326903269132692326933269432695326963269732698326993270032701327023270332704327053270632707327083270932710327113271232713327143271532716327173271832719327203272132722327233272432725327263272732728327293273032731327323273332734327353273632737327383273932740327413274232743327443274532746327473274832749327503275132752327533275432755327563275732758327593276032761327623276332764327653276632767327683276932770327713277232773327743277532776327773277832779327803278132782327833278432785327863278732788327893279032791327923279332794327953279632797327983279932800328013280232803328043280532806328073280832809328103281132812328133281432815328163281732818328193282032821328223282332824328253282632827328283282932830328313283232833328343283532836328373283832839328403284132842328433284432845328463284732848328493285032851328523285332854328553285632857328583285932860328613286232863328643286532866328673286832869328703287132872328733287432875328763287732878328793288032881328823288332884328853288632887328883288932890328913289232893328943289532896328973289832899329003290132902329033290432905329063290732908329093291032911329123291332914329153291632917329183291932920329213292232923329243292532926329273292832929329303293132932329333293432935329363293732938329393294032941329423294332944329453294632947329483294932950329513295232953329543295532956329573295832959329603296132962329633296432965329663296732968329693297032971329723297332974329753297632977329783297932980329813298232983329843298532986329873298832989329903299132992329933299432995329963299732998329993300033001330023300333004330053300633007330083300933010330113301233013330143301533016330173301833019330203302133022330233302433025330263302733028330293303033031330323303333034330353303633037330383303933040330413304233043330443304533046330473304833049330503305133052330533305433055330563305733058330593306033061330623306333064330653306633067330683306933070330713307233073330743307533076330773307833079330803308133082330833308433085330863308733088330893309033091330923309333094330953309633097330983309933100331013310233103331043310533106331073310833109331103311133112331133311433115331163311733118331193312033121331223312333124331253312633127331283312933130331313313233133331343313533136331373313833139331403314133142331433314433145331463314733148331493315033151331523315333154331553315633157331583315933160331613316233163331643316533166331673316833169331703317133172331733317433175331763317733178331793318033181331823318333184331853318633187331883318933190331913319233193331943319533196331973319833199332003320133202332033320433205332063320733208332093321033211332123321333214332153321633217332183321933220332213322233223332243322533226332273322833229332303323133232332333323433235332363323733238332393324033241332423324333244332453324633247332483324933250332513325233253332543325533256332573325833259332603326133262332633326433265332663326733268332693327033271332723327333274332753327633277332783327933280332813328233283332843328533286332873328833289332903329133292332933329433295332963329733298332993330033301333023330333304333053330633307333083330933310333113331233313333143331533316333173331833319333203332133322333233332433325333263332733328333293333033331333323333333334333353333633337333383333933340333413334233343333443334533346333473334833349333503335133352333533335433355333563335733358333593336033361333623336333364333653336633367333683336933370333713337233373333743337533376333773337833379333803338133382333833338433385333863338733388333893339033391333923339333394333953339633397333983339933400334013340233403334043340533406334073340833409334103341133412334133341433415334163341733418334193342033421334223342333424334253342633427334283342933430334313343233433334343343533436334373343833439334403344133442334433344433445334463344733448334493345033451334523345333454334553345633457334583345933460334613346233463334643346533466334673346833469334703347133472334733347433475334763347733478334793348033481334823348333484334853348633487334883348933490334913349233493334943349533496334973349833499335003350133502335033350433505335063350733508335093351033511335123351333514335153351633517335183351933520335213352233523335243352533526335273352833529335303353133532335333353433535335363353733538335393354033541335423354333544335453354633547335483354933550335513355233553335543355533556335573355833559335603356133562335633356433565335663356733568335693357033571335723357333574335753357633577335783357933580335813358233583335843358533586335873358833589335903359133592335933359433595335963359733598335993360033601336023360333604336053360633607336083360933610336113361233613336143361533616336173361833619336203362133622336233362433625336263362733628336293363033631336323363333634336353363633637336383363933640336413364233643336443364533646336473364833649336503365133652336533365433655336563365733658336593366033661336623366333664336653366633667336683366933670336713367233673336743367533676336773367833679336803368133682336833368433685336863368733688336893369033691336923369333694336953369633697336983369933700337013370233703337043370533706337073370833709337103371133712337133371433715337163371733718337193372033721337223372333724337253372633727337283372933730337313373233733337343373533736337373373833739337403374133742337433374433745337463374733748337493375033751337523375333754337553375633757337583375933760337613376233763337643376533766337673376833769337703377133772337733377433775337763377733778337793378033781337823378333784337853378633787337883378933790337913379233793337943379533796337973379833799338003380133802338033380433805338063380733808338093381033811338123381333814338153381633817338183381933820338213382233823338243382533826338273382833829338303383133832338333383433835338363383733838338393384033841338423384333844338453384633847338483384933850338513385233853338543385533856338573385833859338603386133862338633386433865338663386733868338693387033871338723387333874338753387633877338783387933880338813388233883338843388533886338873388833889338903389133892338933389433895338963389733898338993390033901339023390333904339053390633907339083390933910339113391233913339143391533916339173391833919339203392133922339233392433925339263392733928339293393033931339323393333934339353393633937339383393933940339413394233943339443394533946339473394833949339503395133952339533395433955339563395733958339593396033961339623396333964339653396633967339683396933970339713397233973339743397533976339773397833979339803398133982339833398433985339863398733988339893399033991339923399333994339953399633997339983399934000340013400234003340043400534006340073400834009340103401134012340133401434015340163401734018340193402034021340223402334024340253402634027340283402934030340313403234033340343403534036340373403834039340403404134042340433404434045340463404734048340493405034051340523405334054340553405634057340583405934060340613406234063340643406534066340673406834069340703407134072340733407434075340763407734078340793408034081340823408334084340853408634087340883408934090340913409234093340943409534096340973409834099341003410134102341033410434105341063410734108341093411034111341123411334114341153411634117341183411934120341213412234123341243412534126341273412834129341303413134132341333413434135341363413734138341393414034141341423414334144341453414634147341483414934150341513415234153341543415534156341573415834159341603416134162341633416434165341663416734168341693417034171341723417334174341753417634177341783417934180341813418234183341843418534186341873418834189341903419134192341933419434195341963419734198341993420034201342023420334204342053420634207342083420934210342113421234213342143421534216342173421834219342203422134222342233422434225342263422734228342293423034231342323423334234342353423634237342383423934240342413424234243342443424534246342473424834249342503425134252342533425434255342563425734258342593426034261342623426334264342653426634267342683426934270342713427234273342743427534276342773427834279342803428134282342833428434285342863428734288342893429034291342923429334294342953429634297342983429934300343013430234303343043430534306343073430834309343103431134312343133431434315343163431734318343193432034321343223432334324343253432634327343283432934330343313433234333343343433534336343373433834339343403434134342343433434434345343463434734348343493435034351343523435334354343553435634357343583435934360343613436234363343643436534366343673436834369343703437134372343733437434375343763437734378343793438034381343823438334384343853438634387343883438934390343913439234393343943439534396343973439834399344003440134402344033440434405344063440734408344093441034411344123441334414344153441634417344183441934420344213442234423344243442534426344273442834429344303443134432344333443434435344363443734438344393444034441344423444334444344453444634447344483444934450344513445234453344543445534456344573445834459344603446134462344633446434465344663446734468344693447034471344723447334474344753447634477344783447934480344813448234483344843448534486344873448834489344903449134492344933449434495344963449734498344993450034501345023450334504345053450634507345083450934510345113451234513345143451534516345173451834519345203452134522345233452434525345263452734528345293453034531345323453334534345353453634537345383453934540345413454234543345443454534546345473454834549345503455134552345533455434555345563455734558345593456034561345623456334564345653456634567345683456934570345713457234573345743457534576345773457834579345803458134582345833458434585345863458734588345893459034591345923459334594345953459634597345983459934600346013460234603346043460534606346073460834609346103461134612346133461434615346163461734618346193462034621346223462334624346253462634627346283462934630346313463234633346343463534636346373463834639346403464134642346433464434645346463464734648346493465034651346523465334654346553465634657346583465934660346613466234663346643466534666346673466834669346703467134672346733467434675346763467734678346793468034681346823468334684346853468634687346883468934690346913469234693346943469534696346973469834699347003470134702347033470434705347063470734708347093471034711347123471334714347153471634717347183471934720347213472234723347243472534726347273472834729347303473134732347333473434735347363473734738347393474034741347423474334744347453474634747347483474934750347513475234753347543475534756347573475834759347603476134762347633476434765347663476734768347693477034771347723477334774347753477634777347783477934780347813478234783347843478534786347873478834789347903479134792347933479434795347963479734798347993480034801348023480334804348053480634807348083480934810348113481234813348143481534816348173481834819348203482134822348233482434825348263482734828348293483034831348323483334834348353483634837348383483934840348413484234843348443484534846348473484834849348503485134852348533485434855348563485734858348593486034861348623486334864348653486634867348683486934870348713487234873348743487534876348773487834879348803488134882348833488434885348863488734888348893489034891348923489334894348953489634897348983489934900349013490234903349043490534906349073490834909349103491134912349133491434915349163491734918349193492034921349223492334924349253492634927349283492934930349313493234933349343493534936349373493834939349403494134942349433494434945349463494734948349493495034951349523495334954349553495634957349583495934960349613496234963349643496534966349673496834969349703497134972349733497434975349763497734978349793498034981349823498334984349853498634987349883498934990349913499234993349943499534996349973499834999350003500135002350033500435005350063500735008350093501035011350123501335014350153501635017350183501935020350213502235023350243502535026350273502835029350303503135032350333503435035350363503735038350393504035041350423504335044350453504635047350483504935050350513505235053350543505535056350573505835059350603506135062350633506435065350663506735068350693507035071350723507335074350753507635077350783507935080350813508235083350843508535086350873508835089350903509135092350933509435095350963509735098350993510035101351023510335104351053510635107351083510935110351113511235113351143511535116351173511835119351203512135122351233512435125351263512735128351293513035131351323513335134351353513635137351383513935140351413514235143351443514535146351473514835149351503515135152351533515435155351563515735158351593516035161351623516335164351653516635167351683516935170351713517235173351743517535176351773517835179351803518135182351833518435185351863518735188351893519035191351923519335194351953519635197351983519935200352013520235203352043520535206352073520835209352103521135212352133521435215352163521735218352193522035221352223522335224352253522635227352283522935230352313523235233352343523535236352373523835239352403524135242352433524435245352463524735248352493525035251352523525335254352553525635257352583525935260352613526235263352643526535266352673526835269352703527135272352733527435275352763527735278352793528035281352823528335284352853528635287352883528935290352913529235293352943529535296352973529835299353003530135302353033530435305353063530735308353093531035311353123531335314353153531635317353183531935320353213532235323353243532535326353273532835329353303533135332353333533435335353363533735338353393534035341353423534335344353453534635347353483534935350353513535235353353543535535356353573535835359353603536135362353633536435365353663536735368353693537035371353723537335374353753537635377353783537935380353813538235383353843538535386353873538835389353903539135392353933539435395353963539735398353993540035401354023540335404354053540635407354083540935410354113541235413354143541535416354173541835419354203542135422354233542435425354263542735428354293543035431354323543335434354353543635437354383543935440354413544235443354443544535446354473544835449354503545135452354533545435455354563545735458354593546035461354623546335464354653546635467354683546935470354713547235473354743547535476354773547835479354803548135482354833548435485354863548735488354893549035491354923549335494354953549635497354983549935500355013550235503355043550535506355073550835509355103551135512355133551435515355163551735518355193552035521355223552335524355253552635527355283552935530355313553235533355343553535536355373553835539355403554135542355433554435545355463554735548355493555035551355523555335554355553555635557355583555935560355613556235563355643556535566355673556835569355703557135572355733557435575355763557735578355793558035581355823558335584355853558635587355883558935590355913559235593355943559535596355973559835599356003560135602356033560435605356063560735608356093561035611356123561335614356153561635617356183561935620356213562235623356243562535626356273562835629356303563135632356333563435635356363563735638356393564035641356423564335644356453564635647356483564935650356513565235653356543565535656356573565835659356603566135662356633566435665356663566735668356693567035671356723567335674356753567635677356783567935680356813568235683356843568535686356873568835689356903569135692356933569435695356963569735698356993570035701357023570335704357053570635707357083570935710357113571235713357143571535716357173571835719357203572135722357233572435725357263572735728357293573035731357323573335734357353573635737357383573935740357413574235743357443574535746357473574835749357503575135752357533575435755357563575735758357593576035761357623576335764357653576635767357683576935770357713577235773357743577535776357773577835779357803578135782357833578435785357863578735788357893579035791357923579335794357953579635797357983579935800358013580235803358043580535806358073580835809358103581135812358133581435815358163581735818358193582035821358223582335824358253582635827358283582935830358313583235833358343583535836358373583835839358403584135842358433584435845358463584735848358493585035851358523585335854358553585635857358583585935860358613586235863358643586535866358673586835869358703587135872358733587435875358763587735878358793588035881358823588335884358853588635887358883588935890358913589235893358943589535896358973589835899359003590135902359033590435905359063590735908359093591035911359123591335914359153591635917359183591935920359213592235923359243592535926359273592835929359303593135932359333593435935359363593735938359393594035941359423594335944359453594635947359483594935950359513595235953359543595535956359573595835959359603596135962359633596435965359663596735968359693597035971359723597335974359753597635977359783597935980359813598235983359843598535986359873598835989359903599135992359933599435995359963599735998359993600036001360023600336004360053600636007360083600936010360113601236013360143601536016360173601836019360203602136022360233602436025360263602736028360293603036031360323603336034360353603636037360383603936040360413604236043360443604536046360473604836049360503605136052360533605436055360563605736058360593606036061360623606336064360653606636067360683606936070360713607236073360743607536076360773607836079360803608136082360833608436085360863608736088360893609036091360923609336094360953609636097360983609936100361013610236103361043610536106361073610836109361103611136112361133611436115361163611736118361193612036121361223612336124361253612636127361283612936130361313613236133361343613536136361373613836139361403614136142361433614436145361463614736148361493615036151361523615336154361553615636157361583615936160361613616236163361643616536166361673616836169361703617136172361733617436175361763617736178361793618036181361823618336184361853618636187361883618936190361913619236193361943619536196361973619836199362003620136202362033620436205362063620736208362093621036211362123621336214362153621636217362183621936220362213622236223362243622536226362273622836229362303623136232362333623436235362363623736238362393624036241362423624336244362453624636247362483624936250362513625236253362543625536256362573625836259362603626136262362633626436265362663626736268362693627036271362723627336274362753627636277362783627936280362813628236283362843628536286362873628836289362903629136292362933629436295362963629736298362993630036301363023630336304363053630636307363083630936310363113631236313363143631536316363173631836319363203632136322363233632436325363263632736328363293633036331363323633336334363353633636337363383633936340363413634236343363443634536346363473634836349363503635136352363533635436355363563635736358363593636036361363623636336364363653636636367363683636936370363713637236373363743637536376363773637836379363803638136382363833638436385363863638736388363893639036391363923639336394363953639636397363983639936400364013640236403364043640536406364073640836409364103641136412364133641436415364163641736418364193642036421364223642336424364253642636427364283642936430364313643236433364343643536436364373643836439364403644136442364433644436445364463644736448364493645036451364523645336454364553645636457364583645936460364613646236463364643646536466364673646836469364703647136472364733647436475364763647736478364793648036481364823648336484364853648636487364883648936490364913649236493364943649536496364973649836499365003650136502365033650436505365063650736508365093651036511365123651336514365153651636517365183651936520365213652236523365243652536526365273652836529365303653136532365333653436535365363653736538365393654036541365423654336544365453654636547365483654936550365513655236553365543655536556365573655836559365603656136562365633656436565365663656736568365693657036571365723657336574365753657636577365783657936580365813658236583365843658536586365873658836589365903659136592365933659436595365963659736598365993660036601366023660336604366053660636607366083660936610366113661236613366143661536616366173661836619366203662136622366233662436625366263662736628366293663036631366323663336634366353663636637366383663936640366413664236643366443664536646366473664836649366503665136652366533665436655366563665736658366593666036661366623666336664366653666636667366683666936670366713667236673366743667536676366773667836679366803668136682366833668436685366863668736688366893669036691366923669336694366953669636697366983669936700367013670236703367043670536706367073670836709367103671136712367133671436715367163671736718367193672036721367223672336724367253672636727367283672936730367313673236733367343673536736367373673836739367403674136742367433674436745367463674736748367493675036751367523675336754367553675636757367583675936760367613676236763367643676536766367673676836769367703677136772367733677436775367763677736778367793678036781367823678336784367853678636787367883678936790367913679236793367943679536796367973679836799368003680136802368033680436805368063680736808368093681036811368123681336814368153681636817368183681936820368213682236823368243682536826368273682836829368303683136832368333683436835368363683736838368393684036841368423684336844368453684636847368483684936850368513685236853368543685536856368573685836859368603686136862368633686436865368663686736868368693687036871368723687336874368753687636877368783687936880368813688236883368843688536886368873688836889368903689136892368933689436895368963689736898368993690036901369023690336904369053690636907369083690936910369113691236913369143691536916369173691836919369203692136922369233692436925369263692736928369293693036931369323693336934369353693636937369383693936940369413694236943369443694536946369473694836949369503695136952369533695436955369563695736958369593696036961369623696336964369653696636967369683696936970369713697236973369743697536976369773697836979369803698136982369833698436985369863698736988369893699036991369923699336994369953699636997369983699937000370013700237003370043700537006370073700837009370103701137012370133701437015370163701737018370193702037021370223702337024370253702637027370283702937030370313703237033370343703537036370373703837039370403704137042370433704437045370463704737048370493705037051370523705337054370553705637057370583705937060370613706237063370643706537066370673706837069370703707137072370733707437075370763707737078370793708037081370823708337084370853708637087370883708937090370913709237093370943709537096370973709837099371003710137102371033710437105371063710737108371093711037111371123711337114371153711637117371183711937120371213712237123371243712537126371273712837129371303713137132371333713437135371363713737138371393714037141371423714337144371453714637147371483714937150371513715237153371543715537156371573715837159371603716137162371633716437165371663716737168371693717037171371723717337174371753717637177371783717937180371813718237183371843718537186371873718837189371903719137192371933719437195371963719737198371993720037201372023720337204372053720637207372083720937210372113721237213372143721537216372173721837219372203722137222372233722437225372263722737228372293723037231372323723337234372353723637237372383723937240372413724237243372443724537246372473724837249372503725137252372533725437255372563725737258372593726037261372623726337264372653726637267372683726937270372713727237273372743727537276372773727837279372803728137282372833728437285372863728737288372893729037291372923729337294372953729637297372983729937300373013730237303373043730537306373073730837309373103731137312373133731437315373163731737318373193732037321373223732337324373253732637327373283732937330373313733237333373343733537336373373733837339373403734137342373433734437345373463734737348373493735037351373523735337354373553735637357373583735937360373613736237363373643736537366373673736837369373703737137372373733737437375373763737737378373793738037381373823738337384373853738637387373883738937390373913739237393373943739537396373973739837399374003740137402374033740437405374063740737408374093741037411374123741337414374153741637417374183741937420374213742237423374243742537426374273742837429374303743137432374333743437435374363743737438374393744037441374423744337444374453744637447374483744937450374513745237453374543745537456374573745837459374603746137462374633746437465374663746737468374693747037471374723747337474374753747637477374783747937480374813748237483374843748537486374873748837489374903749137492374933749437495374963749737498374993750037501375023750337504375053750637507375083750937510375113751237513375143751537516375173751837519375203752137522375233752437525375263752737528375293753037531375323753337534375353753637537375383753937540375413754237543375443754537546375473754837549375503755137552375533755437555375563755737558375593756037561375623756337564375653756637567375683756937570375713757237573375743757537576375773757837579375803758137582375833758437585375863758737588375893759037591375923759337594375953759637597375983759937600376013760237603376043760537606376073760837609376103761137612376133761437615376163761737618376193762037621376223762337624376253762637627376283762937630376313763237633376343763537636376373763837639376403764137642376433764437645376463764737648376493765037651376523765337654376553765637657376583765937660376613766237663376643766537666376673766837669376703767137672376733767437675376763767737678376793768037681376823768337684376853768637687376883768937690376913769237693376943769537696376973769837699377003770137702377033770437705377063770737708377093771037711377123771337714377153771637717377183771937720377213772237723377243772537726377273772837729377303773137732377333773437735377363773737738377393774037741377423774337744377453774637747377483774937750377513775237753377543775537756377573775837759377603776137762377633776437765377663776737768377693777037771377723777337774377753777637777377783777937780377813778237783377843778537786377873778837789377903779137792377933779437795377963779737798377993780037801378023780337804378053780637807378083780937810378113781237813378143781537816378173781837819378203782137822378233782437825378263782737828378293783037831378323783337834378353783637837378383783937840378413784237843378443784537846378473784837849378503785137852378533785437855378563785737858378593786037861378623786337864378653786637867378683786937870378713787237873378743787537876378773787837879378803788137882378833788437885378863788737888378893789037891378923789337894378953789637897378983789937900379013790237903379043790537906379073790837909379103791137912379133791437915379163791737918379193792037921379223792337924379253792637927379283792937930379313793237933379343793537936379373793837939379403794137942379433794437945379463794737948379493795037951379523795337954379553795637957379583795937960379613796237963379643796537966379673796837969379703797137972379733797437975379763797737978379793798037981379823798337984379853798637987379883798937990379913799237993379943799537996379973799837999380003800138002380033800438005380063800738008380093801038011380123801338014380153801638017380183801938020380213802238023380243802538026380273802838029380303803138032380333803438035380363803738038380393804038041380423804338044380453804638047380483804938050380513805238053380543805538056380573805838059380603806138062380633806438065380663806738068380693807038071380723807338074380753807638077380783807938080380813808238083380843808538086380873808838089380903809138092380933809438095380963809738098380993810038101381023810338104381053810638107381083810938110381113811238113381143811538116381173811838119381203812138122381233812438125381263812738128381293813038131381323813338134381353813638137381383813938140381413814238143381443814538146381473814838149381503815138152381533815438155381563815738158381593816038161381623816338164381653816638167381683816938170381713817238173381743817538176381773817838179381803818138182381833818438185381863818738188381893819038191381923819338194381953819638197381983819938200382013820238203382043820538206382073820838209382103821138212382133821438215382163821738218382193822038221382223822338224382253822638227382283822938230382313823238233382343823538236382373823838239382403824138242382433824438245382463824738248382493825038251382523825338254382553825638257382583825938260382613826238263382643826538266382673826838269382703827138272382733827438275382763827738278382793828038281382823828338284382853828638287382883828938290382913829238293382943829538296382973829838299383003830138302383033830438305383063830738308383093831038311383123831338314383153831638317383183831938320383213832238323383243832538326383273832838329383303833138332383333833438335383363833738338383393834038341383423834338344383453834638347383483834938350383513835238353383543835538356383573835838359383603836138362383633836438365383663836738368383693837038371383723837338374383753837638377383783837938380383813838238383383843838538386383873838838389383903839138392383933839438395383963839738398383993840038401384023840338404384053840638407384083840938410384113841238413384143841538416384173841838419384203842138422384233842438425384263842738428384293843038431384323843338434384353843638437384383843938440384413844238443384443844538446384473844838449384503845138452384533845438455384563845738458384593846038461384623846338464384653846638467384683846938470384713847238473384743847538476384773847838479384803848138482384833848438485384863848738488384893849038491384923849338494384953849638497384983849938500385013850238503385043850538506385073850838509385103851138512385133851438515385163851738518385193852038521385223852338524385253852638527385283852938530385313853238533385343853538536385373853838539385403854138542385433854438545385463854738548385493855038551385523855338554385553855638557385583855938560385613856238563385643856538566385673856838569385703857138572385733857438575385763857738578385793858038581385823858338584385853858638587385883858938590385913859238593385943859538596385973859838599386003860138602386033860438605386063860738608386093861038611386123861338614386153861638617386183861938620386213862238623386243862538626386273862838629386303863138632386333863438635386363863738638386393864038641386423864338644386453864638647386483864938650386513865238653386543865538656386573865838659386603866138662386633866438665386663866738668386693867038671386723867338674386753867638677386783867938680386813868238683386843868538686386873868838689386903869138692386933869438695386963869738698386993870038701387023870338704387053870638707387083870938710387113871238713387143871538716387173871838719387203872138722387233872438725387263872738728387293873038731387323873338734387353873638737387383873938740387413874238743387443874538746387473874838749387503875138752387533875438755387563875738758387593876038761387623876338764387653876638767387683876938770387713877238773387743877538776387773877838779387803878138782387833878438785387863878738788387893879038791387923879338794387953879638797387983879938800388013880238803388043880538806388073880838809388103881138812388133881438815388163881738818388193882038821388223882338824388253882638827388283882938830388313883238833388343883538836388373883838839388403884138842388433884438845388463884738848388493885038851388523885338854388553885638857388583885938860388613886238863388643886538866388673886838869388703887138872388733887438875388763887738878388793888038881388823888338884388853888638887388883888938890388913889238893388943889538896388973889838899389003890138902389033890438905389063890738908389093891038911389123891338914389153891638917389183891938920389213892238923389243892538926389273892838929389303893138932389333893438935389363893738938389393894038941389423894338944389453894638947389483894938950389513895238953389543895538956389573895838959389603896138962389633896438965389663896738968389693897038971389723897338974389753897638977389783897938980389813898238983389843898538986389873898838989389903899138992389933899438995389963899738998389993900039001390023900339004390053900639007390083900939010390113901239013390143901539016390173901839019390203902139022390233902439025390263902739028390293903039031390323903339034390353903639037390383903939040390413904239043390443904539046390473904839049390503905139052390533905439055390563905739058390593906039061390623906339064390653906639067390683906939070390713907239073390743907539076390773907839079390803908139082390833908439085390863908739088390893909039091390923909339094390953909639097390983909939100391013910239103391043910539106391073910839109391103911139112391133911439115391163911739118391193912039121391223912339124391253912639127391283912939130391313913239133391343913539136391373913839139391403914139142391433914439145391463914739148391493915039151391523915339154391553915639157391583915939160391613916239163391643916539166391673916839169391703917139172391733917439175391763917739178391793918039181391823918339184391853918639187391883918939190391913919239193391943919539196391973919839199392003920139202392033920439205392063920739208392093921039211392123921339214392153921639217392183921939220392213922239223392243922539226392273922839229392303923139232392333923439235392363923739238392393924039241392423924339244392453924639247392483924939250392513925239253392543925539256392573925839259392603926139262392633926439265392663926739268392693927039271392723927339274392753927639277392783927939280392813928239283392843928539286392873928839289392903929139292392933929439295392963929739298392993930039301393023930339304393053930639307393083930939310393113931239313393143931539316393173931839319393203932139322393233932439325393263932739328393293933039331393323933339334393353933639337393383933939340393413934239343393443934539346393473934839349393503935139352393533935439355393563935739358393593936039361393623936339364393653936639367393683936939370393713937239373393743937539376393773937839379393803938139382393833938439385393863938739388393893939039391393923939339394393953939639397393983939939400394013940239403394043940539406394073940839409394103941139412394133941439415394163941739418394193942039421394223942339424394253942639427394283942939430394313943239433394343943539436394373943839439394403944139442394433944439445394463944739448394493945039451394523945339454394553945639457394583945939460394613946239463394643946539466394673946839469394703947139472394733947439475394763947739478394793948039481394823948339484394853948639487394883948939490394913949239493394943949539496394973949839499395003950139502395033950439505395063950739508395093951039511395123951339514395153951639517395183951939520395213952239523395243952539526395273952839529395303953139532395333953439535395363953739538395393954039541395423954339544395453954639547395483954939550395513955239553395543955539556395573955839559395603956139562395633956439565395663956739568395693957039571395723957339574395753957639577395783957939580395813958239583395843958539586395873958839589395903959139592395933959439595395963959739598395993960039601396023960339604396053960639607396083960939610396113961239613396143961539616396173961839619396203962139622396233962439625396263962739628396293963039631396323963339634396353963639637396383963939640396413964239643396443964539646396473964839649396503965139652396533965439655396563965739658396593966039661396623966339664396653966639667396683966939670396713967239673396743967539676396773967839679396803968139682396833968439685396863968739688396893969039691396923969339694396953969639697396983969939700397013970239703397043970539706397073970839709397103971139712397133971439715397163971739718397193972039721397223972339724397253972639727397283972939730397313973239733397343973539736397373973839739397403974139742397433974439745397463974739748397493975039751397523975339754397553975639757397583975939760397613976239763397643976539766397673976839769397703977139772397733977439775397763977739778397793978039781397823978339784397853978639787397883978939790397913979239793397943979539796397973979839799398003980139802398033980439805398063980739808398093981039811398123981339814398153981639817398183981939820398213982239823398243982539826398273982839829398303983139832398333983439835398363983739838398393984039841398423984339844398453984639847398483984939850398513985239853398543985539856398573985839859398603986139862398633986439865398663986739868398693987039871398723987339874398753987639877398783987939880398813988239883398843988539886398873988839889398903989139892398933989439895398963989739898398993990039901399023990339904399053990639907399083990939910399113991239913399143991539916399173991839919399203992139922399233992439925399263992739928399293993039931399323993339934399353993639937399383993939940399413994239943399443994539946399473994839949399503995139952399533995439955399563995739958399593996039961399623996339964399653996639967399683996939970399713997239973399743997539976399773997839979399803998139982399833998439985399863998739988399893999039991399923999339994399953999639997399983999940000400014000240003400044000540006400074000840009400104001140012400134001440015400164001740018400194002040021400224002340024400254002640027400284002940030400314003240033400344003540036400374003840039400404004140042400434004440045400464004740048400494005040051400524005340054400554005640057400584005940060400614006240063400644006540066400674006840069400704007140072400734007440075400764007740078400794008040081400824008340084400854008640087400884008940090400914009240093400944009540096400974009840099401004010140102401034010440105401064010740108401094011040111401124011340114401154011640117401184011940120401214012240123401244012540126401274012840129401304013140132401334013440135401364013740138401394014040141401424014340144401454014640147401484014940150401514015240153401544015540156401574015840159401604016140162401634016440165401664016740168401694017040171401724017340174401754017640177401784017940180401814018240183401844018540186401874018840189401904019140192401934019440195401964019740198401994020040201402024020340204402054020640207402084020940210402114021240213402144021540216402174021840219402204022140222402234022440225402264022740228402294023040231402324023340234402354023640237402384023940240402414024240243402444024540246402474024840249402504025140252402534025440255402564025740258402594026040261402624026340264402654026640267402684026940270402714027240273402744027540276402774027840279402804028140282402834028440285402864028740288402894029040291402924029340294402954029640297402984029940300403014030240303403044030540306403074030840309403104031140312403134031440315403164031740318403194032040321403224032340324403254032640327403284032940330403314033240333403344033540336403374033840339403404034140342403434034440345403464034740348403494035040351403524035340354403554035640357403584035940360403614036240363403644036540366403674036840369403704037140372403734037440375403764037740378403794038040381403824038340384403854038640387403884038940390403914039240393403944039540396403974039840399404004040140402404034040440405404064040740408404094041040411404124041340414404154041640417404184041940420404214042240423404244042540426404274042840429404304043140432404334043440435404364043740438404394044040441404424044340444404454044640447404484044940450404514045240453404544045540456404574045840459404604046140462404634046440465404664046740468404694047040471404724047340474404754047640477404784047940480404814048240483404844048540486404874048840489404904049140492404934049440495404964049740498404994050040501405024050340504405054050640507405084050940510405114051240513405144051540516405174051840519405204052140522405234052440525405264052740528405294053040531405324053340534405354053640537405384053940540405414054240543405444054540546405474054840549405504055140552405534055440555405564055740558405594056040561405624056340564405654056640567405684056940570405714057240573405744057540576405774057840579405804058140582405834058440585405864058740588405894059040591405924059340594405954059640597405984059940600406014060240603406044060540606406074060840609406104061140612406134061440615406164061740618406194062040621406224062340624406254062640627406284062940630406314063240633406344063540636406374063840639406404064140642406434064440645406464064740648406494065040651406524065340654406554065640657406584065940660406614066240663406644066540666406674066840669406704067140672406734067440675406764067740678406794068040681406824068340684406854068640687406884068940690406914069240693406944069540696406974069840699407004070140702407034070440705407064070740708407094071040711407124071340714407154071640717407184071940720407214072240723407244072540726407274072840729407304073140732407334073440735407364073740738407394074040741407424074340744407454074640747407484074940750407514075240753407544075540756407574075840759407604076140762407634076440765407664076740768407694077040771407724077340774407754077640777407784077940780407814078240783407844078540786407874078840789407904079140792407934079440795407964079740798407994080040801408024080340804408054080640807408084080940810408114081240813408144081540816408174081840819408204082140822408234082440825408264082740828408294083040831408324083340834408354083640837408384083940840408414084240843408444084540846408474084840849408504085140852408534085440855408564085740858408594086040861408624086340864408654086640867408684086940870408714087240873408744087540876408774087840879408804088140882408834088440885408864088740888408894089040891408924089340894408954089640897408984089940900409014090240903409044090540906409074090840909409104091140912409134091440915409164091740918409194092040921409224092340924409254092640927409284092940930409314093240933409344093540936409374093840939409404094140942409434094440945409464094740948409494095040951409524095340954409554095640957409584095940960409614096240963409644096540966409674096840969409704097140972409734097440975409764097740978409794098040981409824098340984409854098640987409884098940990409914099240993409944099540996409974099840999410004100141002410034100441005410064100741008410094101041011410124101341014410154101641017410184101941020410214102241023410244102541026410274102841029410304103141032410334103441035410364103741038410394104041041410424104341044410454104641047410484104941050410514105241053410544105541056410574105841059410604106141062410634106441065410664106741068410694107041071410724107341074410754107641077410784107941080410814108241083410844108541086410874108841089410904109141092410934109441095410964109741098410994110041101411024110341104411054110641107411084110941110411114111241113411144111541116411174111841119411204112141122411234112441125411264112741128411294113041131411324113341134411354113641137411384113941140411414114241143411444114541146411474114841149411504115141152411534115441155411564115741158411594116041161411624116341164411654116641167411684116941170411714117241173411744117541176411774117841179411804118141182411834118441185411864118741188411894119041191411924119341194411954119641197411984119941200412014120241203412044120541206412074120841209412104121141212412134121441215412164121741218412194122041221412224122341224412254122641227412284122941230412314123241233412344123541236412374123841239412404124141242412434124441245412464124741248412494125041251412524125341254412554125641257412584125941260412614126241263412644126541266412674126841269412704127141272412734127441275412764127741278412794128041281412824128341284412854128641287412884128941290412914129241293412944129541296412974129841299413004130141302413034130441305413064130741308413094131041311413124131341314413154131641317413184131941320413214132241323413244132541326413274132841329413304133141332413334133441335413364133741338413394134041341413424134341344413454134641347413484134941350413514135241353413544135541356413574135841359413604136141362413634136441365413664136741368413694137041371413724137341374413754137641377413784137941380413814138241383413844138541386413874138841389413904139141392413934139441395413964139741398413994140041401414024140341404414054140641407414084140941410414114141241413414144141541416414174141841419414204142141422414234142441425414264142741428414294143041431414324143341434414354143641437414384143941440414414144241443414444144541446414474144841449414504145141452414534145441455414564145741458414594146041461414624146341464414654146641467414684146941470414714147241473414744147541476414774147841479414804148141482414834148441485414864148741488414894149041491414924149341494414954149641497414984149941500415014150241503415044150541506415074150841509415104151141512415134151441515415164151741518415194152041521415224152341524415254152641527415284152941530415314153241533415344153541536415374153841539415404154141542415434154441545415464154741548415494155041551415524155341554415554155641557415584155941560415614156241563415644156541566415674156841569415704157141572415734157441575415764157741578415794158041581415824158341584415854158641587415884158941590415914159241593415944159541596415974159841599416004160141602416034160441605416064160741608416094161041611416124161341614416154161641617416184161941620416214162241623416244162541626416274162841629416304163141632416334163441635416364163741638416394164041641416424164341644416454164641647416484164941650416514165241653416544165541656416574165841659416604166141662416634166441665416664166741668416694167041671416724167341674416754167641677416784167941680416814168241683416844168541686416874168841689416904169141692416934169441695416964169741698416994170041701417024170341704417054170641707417084170941710417114171241713417144171541716417174171841719417204172141722417234172441725417264172741728417294173041731417324173341734417354173641737417384173941740417414174241743417444174541746417474174841749417504175141752417534175441755417564175741758417594176041761417624176341764417654176641767417684176941770417714177241773417744177541776417774177841779417804178141782417834178441785417864178741788417894179041791417924179341794417954179641797417984179941800418014180241803418044180541806418074180841809418104181141812418134181441815418164181741818418194182041821418224182341824418254182641827418284182941830418314183241833418344183541836418374183841839418404184141842418434184441845418464184741848418494185041851418524185341854418554185641857418584185941860418614186241863418644186541866418674186841869418704187141872418734187441875418764187741878418794188041881418824188341884418854188641887418884188941890418914189241893418944189541896418974189841899419004190141902419034190441905419064190741908419094191041911419124191341914419154191641917419184191941920419214192241923419244192541926419274192841929419304193141932419334193441935419364193741938419394194041941419424194341944419454194641947419484194941950419514195241953419544195541956419574195841959419604196141962419634196441965419664196741968419694197041971419724197341974419754197641977419784197941980419814198241983419844198541986419874198841989419904199141992419934199441995419964199741998419994200042001420024200342004420054200642007420084200942010420114201242013420144201542016420174201842019420204202142022420234202442025420264202742028420294203042031420324203342034420354203642037420384203942040420414204242043420444204542046420474204842049420504205142052420534205442055420564205742058420594206042061420624206342064420654206642067420684206942070420714207242073420744207542076420774207842079420804208142082420834208442085420864208742088420894209042091420924209342094420954209642097420984209942100421014210242103421044210542106421074210842109421104211142112421134211442115421164211742118421194212042121421224212342124421254212642127421284212942130421314213242133421344213542136421374213842139421404214142142421434214442145421464214742148421494215042151421524215342154421554215642157421584215942160421614216242163421644216542166421674216842169421704217142172421734217442175421764217742178421794218042181421824218342184421854218642187421884218942190421914219242193421944219542196421974219842199422004220142202422034220442205422064220742208422094221042211422124221342214422154221642217422184221942220422214222242223422244222542226422274222842229422304223142232422334223442235422364223742238422394224042241422424224342244422454224642247422484224942250422514225242253422544225542256422574225842259422604226142262422634226442265422664226742268422694227042271422724227342274422754227642277422784227942280422814228242283422844228542286422874228842289422904229142292422934229442295422964229742298422994230042301423024230342304423054230642307423084230942310423114231242313423144231542316423174231842319423204232142322423234232442325423264232742328423294233042331423324233342334423354233642337423384233942340423414234242343423444234542346423474234842349423504235142352423534235442355423564235742358423594236042361423624236342364423654236642367423684236942370423714237242373423744237542376423774237842379423804238142382423834238442385423864238742388423894239042391423924239342394423954239642397423984239942400424014240242403424044240542406424074240842409424104241142412424134241442415424164241742418424194242042421424224242342424424254242642427424284242942430424314243242433424344243542436424374243842439424404244142442424434244442445424464244742448424494245042451424524245342454424554245642457424584245942460424614246242463424644246542466424674246842469424704247142472424734247442475424764247742478424794248042481424824248342484424854248642487424884248942490424914249242493424944249542496424974249842499425004250142502425034250442505425064250742508425094251042511425124251342514425154251642517425184251942520425214252242523425244252542526425274252842529425304253142532425334253442535425364253742538425394254042541425424254342544425454254642547425484254942550425514255242553425544255542556425574255842559425604256142562425634256442565425664256742568425694257042571425724257342574425754257642577425784257942580425814258242583425844258542586425874258842589425904259142592425934259442595425964259742598425994260042601426024260342604426054260642607426084260942610426114261242613426144261542616426174261842619426204262142622426234262442625426264262742628426294263042631426324263342634426354263642637426384263942640426414264242643426444264542646426474264842649426504265142652426534265442655426564265742658426594266042661426624266342664426654266642667426684266942670426714267242673426744267542676426774267842679426804268142682426834268442685426864268742688426894269042691426924269342694426954269642697426984269942700427014270242703427044270542706427074270842709427104271142712427134271442715427164271742718427194272042721427224272342724427254272642727427284272942730427314273242733427344273542736427374273842739427404274142742427434274442745427464274742748427494275042751427524275342754427554275642757427584275942760427614276242763427644276542766427674276842769427704277142772427734277442775427764277742778427794278042781427824278342784427854278642787427884278942790427914279242793427944279542796427974279842799428004280142802428034280442805428064280742808428094281042811428124281342814428154281642817428184281942820428214282242823428244282542826428274282842829428304283142832428334283442835428364283742838428394284042841428424284342844428454284642847428484284942850428514285242853428544285542856428574285842859428604286142862428634286442865428664286742868428694287042871428724287342874428754287642877428784287942880428814288242883428844288542886428874288842889428904289142892428934289442895428964289742898428994290042901429024290342904429054290642907429084290942910429114291242913429144291542916429174291842919429204292142922429234292442925429264292742928429294293042931429324293342934429354293642937429384293942940429414294242943429444294542946429474294842949429504295142952429534295442955429564295742958429594296042961429624296342964429654296642967429684296942970429714297242973429744297542976429774297842979429804298142982429834298442985429864298742988429894299042991429924299342994429954299642997429984299943000430014300243003430044300543006430074300843009430104301143012430134301443015430164301743018430194302043021430224302343024430254302643027430284302943030430314303243033430344303543036430374303843039430404304143042430434304443045430464304743048430494305043051430524305343054430554305643057430584305943060430614306243063430644306543066430674306843069430704307143072430734307443075430764307743078430794308043081430824308343084430854308643087430884308943090430914309243093430944309543096430974309843099431004310143102431034310443105431064310743108431094311043111431124311343114431154311643117431184311943120431214312243123431244312543126431274312843129431304313143132431334313443135431364313743138431394314043141431424314343144431454314643147431484314943150431514315243153431544315543156431574315843159431604316143162431634316443165431664316743168431694317043171431724317343174431754317643177431784317943180431814318243183431844318543186431874318843189431904319143192431934319443195431964319743198431994320043201432024320343204432054320643207432084320943210432114321243213432144321543216432174321843219432204322143222432234322443225432264322743228432294323043231432324323343234432354323643237432384323943240432414324243243432444324543246432474324843249432504325143252432534325443255432564325743258432594326043261432624326343264432654326643267432684326943270432714327243273432744327543276432774327843279432804328143282432834328443285432864328743288432894329043291432924329343294432954329643297432984329943300433014330243303433044330543306433074330843309433104331143312433134331443315433164331743318433194332043321433224332343324433254332643327433284332943330433314333243333433344333543336433374333843339433404334143342433434334443345433464334743348433494335043351433524335343354433554335643357433584335943360433614336243363433644336543366433674336843369433704337143372433734337443375433764337743378433794338043381433824338343384433854338643387433884338943390433914339243393433944339543396433974339843399434004340143402434034340443405434064340743408434094341043411434124341343414434154341643417434184341943420434214342243423434244342543426434274342843429434304343143432434334343443435434364343743438434394344043441434424344343444434454344643447434484344943450434514345243453434544345543456434574345843459434604346143462434634346443465434664346743468434694347043471434724347343474434754347643477434784347943480434814348243483434844348543486434874348843489434904349143492434934349443495434964349743498434994350043501435024350343504435054350643507435084350943510435114351243513435144351543516435174351843519435204352143522435234352443525435264352743528435294353043531435324353343534435354353643537435384353943540435414354243543435444354543546435474354843549435504355143552435534355443555435564355743558435594356043561435624356343564435654356643567435684356943570435714357243573435744357543576435774357843579435804358143582435834358443585435864358743588435894359043591435924359343594435954359643597435984359943600436014360243603436044360543606436074360843609436104361143612436134361443615436164361743618436194362043621436224362343624436254362643627436284362943630436314363243633436344363543636436374363843639436404364143642436434364443645436464364743648436494365043651436524365343654436554365643657436584365943660436614366243663436644366543666436674366843669436704367143672436734367443675436764367743678436794368043681436824368343684436854368643687436884368943690436914369243693436944369543696436974369843699437004370143702437034370443705437064370743708437094371043711437124371343714437154371643717437184371943720437214372243723437244372543726437274372843729437304373143732437334373443735437364373743738437394374043741437424374343744437454374643747437484374943750437514375243753437544375543756437574375843759437604376143762437634376443765437664376743768437694377043771437724377343774437754377643777437784377943780437814378243783437844378543786437874378843789437904379143792437934379443795437964379743798437994380043801438024380343804438054380643807438084380943810438114381243813438144381543816438174381843819438204382143822438234382443825438264382743828438294383043831438324383343834438354383643837438384383943840438414384243843438444384543846438474384843849438504385143852438534385443855438564385743858438594386043861438624386343864438654386643867438684386943870438714387243873438744387543876438774387843879438804388143882438834388443885438864388743888438894389043891438924389343894438954389643897438984389943900439014390243903439044390543906439074390843909439104391143912439134391443915439164391743918439194392043921439224392343924439254392643927439284392943930439314393243933439344393543936439374393843939439404394143942439434394443945439464394743948439494395043951439524395343954439554395643957439584395943960439614396243963439644396543966439674396843969439704397143972439734397443975439764397743978439794398043981439824398343984439854398643987439884398943990439914399243993439944399543996439974399843999440004400144002440034400444005440064400744008440094401044011440124401344014440154401644017440184401944020440214402244023440244402544026440274402844029440304403144032440334403444035440364403744038440394404044041440424404344044440454404644047440484404944050440514405244053440544405544056440574405844059440604406144062440634406444065440664406744068440694407044071440724407344074440754407644077440784407944080440814408244083440844408544086440874408844089440904409144092440934409444095440964409744098440994410044101441024410344104441054410644107441084410944110441114411244113441144411544116441174411844119441204412144122441234412444125441264412744128441294413044131441324413344134441354413644137441384413944140441414414244143441444414544146441474414844149441504415144152441534415444155441564415744158441594416044161441624416344164441654416644167441684416944170441714417244173441744417544176441774417844179441804418144182441834418444185441864418744188441894419044191441924419344194441954419644197441984419944200442014420244203442044420544206442074420844209442104421144212442134421444215442164421744218442194422044221442224422344224442254422644227442284422944230442314423244233442344423544236442374423844239442404424144242442434424444245442464424744248442494425044251442524425344254442554425644257442584425944260442614426244263442644426544266442674426844269442704427144272442734427444275442764427744278442794428044281442824428344284442854428644287442884428944290442914429244293442944429544296442974429844299443004430144302443034430444305443064430744308443094431044311443124431344314443154431644317443184431944320443214432244323443244432544326443274432844329443304433144332443334433444335443364433744338443394434044341443424434344344443454434644347443484434944350443514435244353443544435544356443574435844359443604436144362443634436444365443664436744368443694437044371443724437344374443754437644377443784437944380443814438244383443844438544386443874438844389443904439144392443934439444395443964439744398443994440044401444024440344404444054440644407444084440944410444114441244413444144441544416444174441844419444204442144422444234442444425444264442744428444294443044431444324443344434444354443644437444384443944440444414444244443444444444544446444474444844449444504445144452444534445444455444564445744458444594446044461444624446344464444654446644467444684446944470444714447244473444744447544476444774447844479444804448144482444834448444485444864448744488444894449044491444924449344494444954449644497444984449944500445014450244503445044450544506445074450844509445104451144512445134451444515445164451744518445194452044521445224452344524445254452644527445284452944530445314453244533445344453544536445374453844539445404454144542445434454444545445464454744548445494455044551445524455344554445554455644557445584455944560445614456244563445644456544566445674456844569445704457144572445734457444575445764457744578445794458044581445824458344584445854458644587445884458944590445914459244593445944459544596445974459844599446004460144602446034460444605446064460744608446094461044611446124461344614446154461644617446184461944620446214462244623446244462544626446274462844629446304463144632446334463444635446364463744638446394464044641446424464344644446454464644647446484464944650446514465244653446544465544656446574465844659446604466144662446634466444665446664466744668446694467044671446724467344674446754467644677446784467944680446814468244683446844468544686446874468844689446904469144692446934469444695446964469744698446994470044701447024470344704447054470644707447084470944710447114471244713447144471544716447174471844719447204472144722447234472444725447264472744728447294473044731447324473344734447354473644737447384473944740447414474244743447444474544746447474474844749447504475144752447534475444755447564475744758447594476044761447624476344764447654476644767447684476944770447714477244773447744477544776447774477844779447804478144782447834478444785447864478744788447894479044791447924479344794447954479644797447984479944800448014480244803448044480544806448074480844809448104481144812448134481444815448164481744818448194482044821448224482344824448254482644827448284482944830448314483244833448344483544836448374483844839448404484144842448434484444845448464484744848448494485044851448524485344854448554485644857448584485944860448614486244863448644486544866448674486844869448704487144872448734487444875448764487744878448794488044881448824488344884448854488644887448884488944890448914489244893448944489544896448974489844899449004490144902449034490444905449064490744908449094491044911449124491344914449154491644917449184491944920449214492244923449244492544926449274492844929449304493144932449334493444935449364493744938449394494044941449424494344944449454494644947449484494944950449514495244953449544495544956449574495844959449604496144962449634496444965449664496744968449694497044971449724497344974449754497644977449784497944980449814498244983449844498544986449874498844989449904499144992449934499444995449964499744998449994500045001450024500345004450054500645007450084500945010450114501245013450144501545016450174501845019450204502145022450234502445025450264502745028450294503045031450324503345034450354503645037450384503945040450414504245043450444504545046450474504845049450504505145052450534505445055450564505745058450594506045061450624506345064450654506645067450684506945070450714507245073450744507545076450774507845079450804508145082450834508445085450864508745088450894509045091450924509345094450954509645097450984509945100451014510245103451044510545106451074510845109451104511145112451134511445115451164511745118451194512045121451224512345124451254512645127451284512945130451314513245133451344513545136451374513845139451404514145142451434514445145451464514745148451494515045151451524515345154451554515645157451584515945160451614516245163451644516545166451674516845169451704517145172451734517445175451764517745178451794518045181451824518345184451854518645187451884518945190451914519245193451944519545196451974519845199452004520145202452034520445205452064520745208452094521045211452124521345214452154521645217452184521945220452214522245223452244522545226452274522845229452304523145232452334523445235452364523745238452394524045241452424524345244452454524645247452484524945250452514525245253452544525545256452574525845259452604526145262452634526445265452664526745268452694527045271452724527345274452754527645277452784527945280452814528245283452844528545286452874528845289452904529145292452934529445295452964529745298452994530045301453024530345304453054530645307453084530945310453114531245313453144531545316453174531845319453204532145322453234532445325453264532745328453294533045331453324533345334453354533645337453384533945340453414534245343453444534545346453474534845349453504535145352453534535445355453564535745358453594536045361453624536345364453654536645367453684536945370453714537245373453744537545376453774537845379453804538145382453834538445385453864538745388453894539045391453924539345394453954539645397453984539945400454014540245403454044540545406454074540845409454104541145412454134541445415454164541745418454194542045421454224542345424454254542645427454284542945430454314543245433454344543545436454374543845439454404544145442454434544445445454464544745448454494545045451454524545345454454554545645457454584545945460454614546245463454644546545466454674546845469454704547145472454734547445475454764547745478454794548045481454824548345484454854548645487454884548945490454914549245493454944549545496454974549845499455004550145502455034550445505455064550745508455094551045511455124551345514455154551645517455184551945520455214552245523455244552545526455274552845529455304553145532455334553445535455364553745538455394554045541455424554345544455454554645547455484554945550455514555245553455544555545556455574555845559455604556145562455634556445565455664556745568455694557045571
  1. /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
  3. /* Copyright 2012 Mozilla Foundation
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. /*jshint globalstrict: false */
  18. /* globals PDFJS */
  19. // Initializing PDFJS global object (if still undefined)
  20. if (typeof PDFJS === 'undefined') {
  21. (typeof window !== 'undefined' ? window : this).PDFJS = {};
  22. }
  23. PDFJS.version = '1.1.20';
  24. PDFJS.build = '3a8d4a7';
  25. (function pdfjsWrapper() {
  26. // Use strict in our context only - users might not want it
  27. 'use strict';
  28. /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  29. /* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
  30. /* Copyright 2012 Mozilla Foundation
  31. *
  32. * Licensed under the Apache License, Version 2.0 (the "License");
  33. * you may not use this file except in compliance with the License.
  34. * You may obtain a copy of the License at
  35. *
  36. * http://www.apache.org/licenses/LICENSE-2.0
  37. *
  38. * Unless required by applicable law or agreed to in writing, software
  39. * distributed under the License is distributed on an "AS IS" BASIS,
  40. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  41. * See the License for the specific language governing permissions and
  42. * limitations under the License.
  43. */
  44. /* globals Cmd, ColorSpace, Dict, MozBlobBuilder, Name, PDFJS, Ref, URL,
  45. Promise */
  46. 'use strict';
  47. var globalScope = (typeof window === 'undefined') ? this : window;
  48. var isWorker = (typeof window === 'undefined');
  49. var FONT_IDENTITY_MATRIX = [0.001, 0, 0, 0.001, 0, 0];
  50. var TextRenderingMode = {
  51. FILL: 0,
  52. STROKE: 1,
  53. FILL_STROKE: 2,
  54. INVISIBLE: 3,
  55. FILL_ADD_TO_PATH: 4,
  56. STROKE_ADD_TO_PATH: 5,
  57. FILL_STROKE_ADD_TO_PATH: 6,
  58. ADD_TO_PATH: 7,
  59. FILL_STROKE_MASK: 3,
  60. ADD_TO_PATH_FLAG: 4
  61. };
  62. var ImageKind = {
  63. GRAYSCALE_1BPP: 1,
  64. RGB_24BPP: 2,
  65. RGBA_32BPP: 3
  66. };
  67. var AnnotationType = {
  68. WIDGET: 1,
  69. TEXT: 2,
  70. LINK: 3
  71. };
  72. var StreamType = {
  73. UNKNOWN: 0,
  74. FLATE: 1,
  75. LZW: 2,
  76. DCT: 3,
  77. JPX: 4,
  78. JBIG: 5,
  79. A85: 6,
  80. AHX: 7,
  81. CCF: 8,
  82. RL: 9
  83. };
  84. var FontType = {
  85. UNKNOWN: 0,
  86. TYPE1: 1,
  87. TYPE1C: 2,
  88. CIDFONTTYPE0: 3,
  89. CIDFONTTYPE0C: 4,
  90. TRUETYPE: 5,
  91. CIDFONTTYPE2: 6,
  92. TYPE3: 7,
  93. OPENTYPE: 8,
  94. TYPE0: 9,
  95. MMTYPE1: 10
  96. };
  97. // The global PDFJS object exposes the API
  98. // In production, it will be declared outside a global wrapper
  99. // In development, it will be declared here
  100. if (!globalScope.PDFJS) {
  101. globalScope.PDFJS = {};
  102. }
  103. globalScope.PDFJS.pdfBug = false;
  104. PDFJS.VERBOSITY_LEVELS = {
  105. errors: 0,
  106. warnings: 1,
  107. infos: 5
  108. };
  109. // All the possible operations for an operator list.
  110. var OPS = PDFJS.OPS = {
  111. // Intentionally start from 1 so it is easy to spot bad operators that will be
  112. // 0's.
  113. dependency: 1,
  114. setLineWidth: 2,
  115. setLineCap: 3,
  116. setLineJoin: 4,
  117. setMiterLimit: 5,
  118. setDash: 6,
  119. setRenderingIntent: 7,
  120. setFlatness: 8,
  121. setGState: 9,
  122. save: 10,
  123. restore: 11,
  124. transform: 12,
  125. moveTo: 13,
  126. lineTo: 14,
  127. curveTo: 15,
  128. curveTo2: 16,
  129. curveTo3: 17,
  130. closePath: 18,
  131. rectangle: 19,
  132. stroke: 20,
  133. closeStroke: 21,
  134. fill: 22,
  135. eoFill: 23,
  136. fillStroke: 24,
  137. eoFillStroke: 25,
  138. closeFillStroke: 26,
  139. closeEOFillStroke: 27,
  140. endPath: 28,
  141. clip: 29,
  142. eoClip: 30,
  143. beginText: 31,
  144. endText: 32,
  145. setCharSpacing: 33,
  146. setWordSpacing: 34,
  147. setHScale: 35,
  148. setLeading: 36,
  149. setFont: 37,
  150. setTextRenderingMode: 38,
  151. setTextRise: 39,
  152. moveText: 40,
  153. setLeadingMoveText: 41,
  154. setTextMatrix: 42,
  155. nextLine: 43,
  156. showText: 44,
  157. showSpacedText: 45,
  158. nextLineShowText: 46,
  159. nextLineSetSpacingShowText: 47,
  160. setCharWidth: 48,
  161. setCharWidthAndBounds: 49,
  162. setStrokeColorSpace: 50,
  163. setFillColorSpace: 51,
  164. setStrokeColor: 52,
  165. setStrokeColorN: 53,
  166. setFillColor: 54,
  167. setFillColorN: 55,
  168. setStrokeGray: 56,
  169. setFillGray: 57,
  170. setStrokeRGBColor: 58,
  171. setFillRGBColor: 59,
  172. setStrokeCMYKColor: 60,
  173. setFillCMYKColor: 61,
  174. shadingFill: 62,
  175. beginInlineImage: 63,
  176. beginImageData: 64,
  177. endInlineImage: 65,
  178. paintXObject: 66,
  179. markPoint: 67,
  180. markPointProps: 68,
  181. beginMarkedContent: 69,
  182. beginMarkedContentProps: 70,
  183. endMarkedContent: 71,
  184. beginCompat: 72,
  185. endCompat: 73,
  186. paintFormXObjectBegin: 74,
  187. paintFormXObjectEnd: 75,
  188. beginGroup: 76,
  189. endGroup: 77,
  190. beginAnnotations: 78,
  191. endAnnotations: 79,
  192. beginAnnotation: 80,
  193. endAnnotation: 81,
  194. paintJpegXObject: 82,
  195. paintImageMaskXObject: 83,
  196. paintImageMaskXObjectGroup: 84,
  197. paintImageXObject: 85,
  198. paintInlineImageXObject: 86,
  199. paintInlineImageXObjectGroup: 87,
  200. paintImageXObjectRepeat: 88,
  201. paintImageMaskXObjectRepeat: 89,
  202. paintSolidColorImageMask: 90,
  203. constructPath: 91
  204. };
  205. // A notice for devs. These are good for things that are helpful to devs, such
  206. // as warning that Workers were disabled, which is important to devs but not
  207. // end users.
  208. function info(msg) {
  209. if (PDFJS.verbosity >= PDFJS.VERBOSITY_LEVELS.infos) {
  210. console.log('Info: ' + msg);
  211. }
  212. }
  213. // Non-fatal warnings.
  214. function warn(msg) {
  215. if (PDFJS.verbosity >= PDFJS.VERBOSITY_LEVELS.warnings) {
  216. console.log('Warning: ' + msg);
  217. }
  218. }
  219. // Fatal errors that should trigger the fallback UI and halt execution by
  220. // throwing an exception.
  221. function error(msg) {
  222. // If multiple arguments were passed, pass them all to the log function.
  223. if (arguments.length > 1) {
  224. var logArguments = ['Error:'];
  225. logArguments.push.apply(logArguments, arguments);
  226. console.log.apply(console, logArguments);
  227. // Join the arguments into a single string for the lines below.
  228. msg = [].join.call(arguments, ' ');
  229. } else {
  230. console.log('Error: ' + msg);
  231. }
  232. console.log(backtrace());
  233. UnsupportedManager.notify(UNSUPPORTED_FEATURES.unknown);
  234. throw new Error(msg);
  235. }
  236. function backtrace() {
  237. try {
  238. throw new Error();
  239. } catch (e) {
  240. return e.stack ? e.stack.split('\n').slice(2).join('\n') : '';
  241. }
  242. }
  243. function assert(cond, msg) {
  244. if (!cond) {
  245. error(msg);
  246. }
  247. }
  248. var UNSUPPORTED_FEATURES = PDFJS.UNSUPPORTED_FEATURES = {
  249. unknown: 'unknown',
  250. forms: 'forms',
  251. javaScript: 'javaScript',
  252. smask: 'smask',
  253. shadingPattern: 'shadingPattern',
  254. font: 'font'
  255. };
  256. var UnsupportedManager = PDFJS.UnsupportedManager =
  257. (function UnsupportedManagerClosure() {
  258. var listeners = [];
  259. return {
  260. listen: function (cb) {
  261. listeners.push(cb);
  262. },
  263. notify: function (featureId) {
  264. warn('Unsupported feature "' + featureId + '"');
  265. for (var i = 0, ii = listeners.length; i < ii; i++) {
  266. listeners[i](featureId);
  267. }
  268. }
  269. };
  270. })();
  271. // Combines two URLs. The baseUrl shall be absolute URL. If the url is an
  272. // absolute URL, it will be returned as is.
  273. function combineUrl(baseUrl, url) {
  274. if (!url) {
  275. return baseUrl;
  276. }
  277. if (/^[a-z][a-z0-9+\-.]*:/i.test(url)) {
  278. return url;
  279. }
  280. var i;
  281. if (url.charAt(0) === '/') {
  282. // absolute path
  283. i = baseUrl.indexOf('://');
  284. if (url.charAt(1) === '/') {
  285. ++i;
  286. } else {
  287. i = baseUrl.indexOf('/', i + 3);
  288. }
  289. return baseUrl.substring(0, i) + url;
  290. } else {
  291. // relative path
  292. var pathLength = baseUrl.length;
  293. i = baseUrl.lastIndexOf('#');
  294. pathLength = i >= 0 ? i : pathLength;
  295. i = baseUrl.lastIndexOf('?', pathLength);
  296. pathLength = i >= 0 ? i : pathLength;
  297. var prefixLength = baseUrl.lastIndexOf('/', pathLength);
  298. return baseUrl.substring(0, prefixLength + 1) + url;
  299. }
  300. }
  301. // Validates if URL is safe and allowed, e.g. to avoid XSS.
  302. function isValidUrl(url, allowRelative) {
  303. if (!url) {
  304. return false;
  305. }
  306. // RFC 3986 (http://tools.ietf.org/html/rfc3986#section-3.1)
  307. // scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
  308. var protocol = /^[a-z][a-z0-9+\-.]*(?=:)/i.exec(url);
  309. if (!protocol) {
  310. return allowRelative;
  311. }
  312. protocol = protocol[0].toLowerCase();
  313. switch (protocol) {
  314. case 'http':
  315. case 'https':
  316. case 'ftp':
  317. case 'mailto':
  318. case 'tel':
  319. return true;
  320. default:
  321. return false;
  322. }
  323. }
  324. PDFJS.isValidUrl = isValidUrl;
  325. function shadow(obj, prop, value) {
  326. Object.defineProperty(obj, prop, { value: value,
  327. enumerable: true,
  328. configurable: true,
  329. writable: false });
  330. return value;
  331. }
  332. PDFJS.shadow = shadow;
  333. var PasswordResponses = PDFJS.PasswordResponses = {
  334. NEED_PASSWORD: 1,
  335. INCORRECT_PASSWORD: 2
  336. };
  337. var PasswordException = (function PasswordExceptionClosure() {
  338. function PasswordException(msg, code) {
  339. this.name = 'PasswordException';
  340. this.message = msg;
  341. this.code = code;
  342. }
  343. PasswordException.prototype = new Error();
  344. PasswordException.constructor = PasswordException;
  345. return PasswordException;
  346. })();
  347. PDFJS.PasswordException = PasswordException;
  348. var UnknownErrorException = (function UnknownErrorExceptionClosure() {
  349. function UnknownErrorException(msg, details) {
  350. this.name = 'UnknownErrorException';
  351. this.message = msg;
  352. this.details = details;
  353. }
  354. UnknownErrorException.prototype = new Error();
  355. UnknownErrorException.constructor = UnknownErrorException;
  356. return UnknownErrorException;
  357. })();
  358. PDFJS.UnknownErrorException = UnknownErrorException;
  359. var InvalidPDFException = (function InvalidPDFExceptionClosure() {
  360. function InvalidPDFException(msg) {
  361. this.name = 'InvalidPDFException';
  362. this.message = msg;
  363. }
  364. InvalidPDFException.prototype = new Error();
  365. InvalidPDFException.constructor = InvalidPDFException;
  366. return InvalidPDFException;
  367. })();
  368. PDFJS.InvalidPDFException = InvalidPDFException;
  369. var MissingPDFException = (function MissingPDFExceptionClosure() {
  370. function MissingPDFException(msg) {
  371. this.name = 'MissingPDFException';
  372. this.message = msg;
  373. }
  374. MissingPDFException.prototype = new Error();
  375. MissingPDFException.constructor = MissingPDFException;
  376. return MissingPDFException;
  377. })();
  378. PDFJS.MissingPDFException = MissingPDFException;
  379. var UnexpectedResponseException =
  380. (function UnexpectedResponseExceptionClosure() {
  381. function UnexpectedResponseException(msg, status) {
  382. this.name = 'UnexpectedResponseException';
  383. this.message = msg;
  384. this.status = status;
  385. }
  386. UnexpectedResponseException.prototype = new Error();
  387. UnexpectedResponseException.constructor = UnexpectedResponseException;
  388. return UnexpectedResponseException;
  389. })();
  390. PDFJS.UnexpectedResponseException = UnexpectedResponseException;
  391. var NotImplementedException = (function NotImplementedExceptionClosure() {
  392. function NotImplementedException(msg) {
  393. this.message = msg;
  394. }
  395. NotImplementedException.prototype = new Error();
  396. NotImplementedException.prototype.name = 'NotImplementedException';
  397. NotImplementedException.constructor = NotImplementedException;
  398. return NotImplementedException;
  399. })();
  400. var MissingDataException = (function MissingDataExceptionClosure() {
  401. function MissingDataException(begin, end) {
  402. this.begin = begin;
  403. this.end = end;
  404. this.message = 'Missing data [' + begin + ', ' + end + ')';
  405. }
  406. MissingDataException.prototype = new Error();
  407. MissingDataException.prototype.name = 'MissingDataException';
  408. MissingDataException.constructor = MissingDataException;
  409. return MissingDataException;
  410. })();
  411. var XRefParseException = (function XRefParseExceptionClosure() {
  412. function XRefParseException(msg) {
  413. this.message = msg;
  414. }
  415. XRefParseException.prototype = new Error();
  416. XRefParseException.prototype.name = 'XRefParseException';
  417. XRefParseException.constructor = XRefParseException;
  418. return XRefParseException;
  419. })();
  420. function bytesToString(bytes) {
  421. assert(bytes !== null && typeof bytes === 'object' &&
  422. bytes.length !== undefined, 'Invalid argument for bytesToString');
  423. var length = bytes.length;
  424. var MAX_ARGUMENT_COUNT = 8192;
  425. if (length < MAX_ARGUMENT_COUNT) {
  426. return String.fromCharCode.apply(null, bytes);
  427. }
  428. var strBuf = [];
  429. for (var i = 0; i < length; i += MAX_ARGUMENT_COUNT) {
  430. var chunkEnd = Math.min(i + MAX_ARGUMENT_COUNT, length);
  431. var chunk = bytes.subarray(i, chunkEnd);
  432. strBuf.push(String.fromCharCode.apply(null, chunk));
  433. }
  434. return strBuf.join('');
  435. }
  436. function stringToBytes(str) {
  437. assert(typeof str === 'string', 'Invalid argument for stringToBytes');
  438. var length = str.length;
  439. var bytes = new Uint8Array(length);
  440. for (var i = 0; i < length; ++i) {
  441. bytes[i] = str.charCodeAt(i) & 0xFF;
  442. }
  443. return bytes;
  444. }
  445. function string32(value) {
  446. return String.fromCharCode((value >> 24) & 0xff, (value >> 16) & 0xff,
  447. (value >> 8) & 0xff, value & 0xff);
  448. }
  449. function log2(x) {
  450. var n = 1, i = 0;
  451. while (x > n) {
  452. n <<= 1;
  453. i++;
  454. }
  455. return i;
  456. }
  457. function readInt8(data, start) {
  458. return (data[start] << 24) >> 24;
  459. }
  460. function readUint16(data, offset) {
  461. return (data[offset] << 8) | data[offset + 1];
  462. }
  463. function readUint32(data, offset) {
  464. return ((data[offset] << 24) | (data[offset + 1] << 16) |
  465. (data[offset + 2] << 8) | data[offset + 3]) >>> 0;
  466. }
  467. // Lazy test the endianness of the platform
  468. // NOTE: This will be 'true' for simulated TypedArrays
  469. function isLittleEndian() {
  470. var buffer8 = new Uint8Array(2);
  471. buffer8[0] = 1;
  472. var buffer16 = new Uint16Array(buffer8.buffer);
  473. return (buffer16[0] === 1);
  474. }
  475. Object.defineProperty(PDFJS, 'isLittleEndian', {
  476. configurable: true,
  477. get: function PDFJS_isLittleEndian() {
  478. return shadow(PDFJS, 'isLittleEndian', isLittleEndian());
  479. }
  480. });
  481. // Lazy test if the userAgant support CanvasTypedArrays
  482. function hasCanvasTypedArrays() {
  483. var canvas = document.createElement('canvas');
  484. canvas.width = canvas.height = 1;
  485. var ctx = canvas.getContext('2d');
  486. var imageData = ctx.createImageData(1, 1);
  487. return (typeof imageData.data.buffer !== 'undefined');
  488. }
  489. Object.defineProperty(PDFJS, 'hasCanvasTypedArrays', {
  490. configurable: true,
  491. get: function PDFJS_hasCanvasTypedArrays() {
  492. return shadow(PDFJS, 'hasCanvasTypedArrays', hasCanvasTypedArrays());
  493. }
  494. });
  495. var Uint32ArrayView = (function Uint32ArrayViewClosure() {
  496. function Uint32ArrayView(buffer, length) {
  497. this.buffer = buffer;
  498. this.byteLength = buffer.length;
  499. this.length = length === undefined ? (this.byteLength >> 2) : length;
  500. ensureUint32ArrayViewProps(this.length);
  501. }
  502. Uint32ArrayView.prototype = Object.create(null);
  503. var uint32ArrayViewSetters = 0;
  504. function createUint32ArrayProp(index) {
  505. return {
  506. get: function () {
  507. var buffer = this.buffer, offset = index << 2;
  508. return (buffer[offset] | (buffer[offset + 1] << 8) |
  509. (buffer[offset + 2] << 16) | (buffer[offset + 3] << 24)) >>> 0;
  510. },
  511. set: function (value) {
  512. var buffer = this.buffer, offset = index << 2;
  513. buffer[offset] = value & 255;
  514. buffer[offset + 1] = (value >> 8) & 255;
  515. buffer[offset + 2] = (value >> 16) & 255;
  516. buffer[offset + 3] = (value >>> 24) & 255;
  517. }
  518. };
  519. }
  520. function ensureUint32ArrayViewProps(length) {
  521. while (uint32ArrayViewSetters < length) {
  522. Object.defineProperty(Uint32ArrayView.prototype,
  523. uint32ArrayViewSetters,
  524. createUint32ArrayProp(uint32ArrayViewSetters));
  525. uint32ArrayViewSetters++;
  526. }
  527. }
  528. return Uint32ArrayView;
  529. })();
  530. var IDENTITY_MATRIX = [1, 0, 0, 1, 0, 0];
  531. var Util = PDFJS.Util = (function UtilClosure() {
  532. function Util() {}
  533. var rgbBuf = ['rgb(', 0, ',', 0, ',', 0, ')'];
  534. // makeCssRgb() can be called thousands of times. Using |rgbBuf| avoids
  535. // creating many intermediate strings.
  536. Util.makeCssRgb = function Util_makeCssRgb(r, g, b) {
  537. rgbBuf[1] = r;
  538. rgbBuf[3] = g;
  539. rgbBuf[5] = b;
  540. return rgbBuf.join('');
  541. };
  542. // Concatenates two transformation matrices together and returns the result.
  543. Util.transform = function Util_transform(m1, m2) {
  544. return [
  545. m1[0] * m2[0] + m1[2] * m2[1],
  546. m1[1] * m2[0] + m1[3] * m2[1],
  547. m1[0] * m2[2] + m1[2] * m2[3],
  548. m1[1] * m2[2] + m1[3] * m2[3],
  549. m1[0] * m2[4] + m1[2] * m2[5] + m1[4],
  550. m1[1] * m2[4] + m1[3] * m2[5] + m1[5]
  551. ];
  552. };
  553. // For 2d affine transforms
  554. Util.applyTransform = function Util_applyTransform(p, m) {
  555. var xt = p[0] * m[0] + p[1] * m[2] + m[4];
  556. var yt = p[0] * m[1] + p[1] * m[3] + m[5];
  557. return [xt, yt];
  558. };
  559. Util.applyInverseTransform = function Util_applyInverseTransform(p, m) {
  560. var d = m[0] * m[3] - m[1] * m[2];
  561. var xt = (p[0] * m[3] - p[1] * m[2] + m[2] * m[5] - m[4] * m[3]) / d;
  562. var yt = (-p[0] * m[1] + p[1] * m[0] + m[4] * m[1] - m[5] * m[0]) / d;
  563. return [xt, yt];
  564. };
  565. // Applies the transform to the rectangle and finds the minimum axially
  566. // aligned bounding box.
  567. Util.getAxialAlignedBoundingBox =
  568. function Util_getAxialAlignedBoundingBox(r, m) {
  569. var p1 = Util.applyTransform(r, m);
  570. var p2 = Util.applyTransform(r.slice(2, 4), m);
  571. var p3 = Util.applyTransform([r[0], r[3]], m);
  572. var p4 = Util.applyTransform([r[2], r[1]], m);
  573. return [
  574. Math.min(p1[0], p2[0], p3[0], p4[0]),
  575. Math.min(p1[1], p2[1], p3[1], p4[1]),
  576. Math.max(p1[0], p2[0], p3[0], p4[0]),
  577. Math.max(p1[1], p2[1], p3[1], p4[1])
  578. ];
  579. };
  580. Util.inverseTransform = function Util_inverseTransform(m) {
  581. var d = m[0] * m[3] - m[1] * m[2];
  582. return [m[3] / d, -m[1] / d, -m[2] / d, m[0] / d,
  583. (m[2] * m[5] - m[4] * m[3]) / d, (m[4] * m[1] - m[5] * m[0]) / d];
  584. };
  585. // Apply a generic 3d matrix M on a 3-vector v:
  586. // | a b c | | X |
  587. // | d e f | x | Y |
  588. // | g h i | | Z |
  589. // M is assumed to be serialized as [a,b,c,d,e,f,g,h,i],
  590. // with v as [X,Y,Z]
  591. Util.apply3dTransform = function Util_apply3dTransform(m, v) {
  592. return [
  593. m[0] * v[0] + m[1] * v[1] + m[2] * v[2],
  594. m[3] * v[0] + m[4] * v[1] + m[5] * v[2],
  595. m[6] * v[0] + m[7] * v[1] + m[8] * v[2]
  596. ];
  597. };
  598. // This calculation uses Singular Value Decomposition.
  599. // The SVD can be represented with formula A = USV. We are interested in the
  600. // matrix S here because it represents the scale values.
  601. Util.singularValueDecompose2dScale =
  602. function Util_singularValueDecompose2dScale(m) {
  603. var transpose = [m[0], m[2], m[1], m[3]];
  604. // Multiply matrix m with its transpose.
  605. var a = m[0] * transpose[0] + m[1] * transpose[2];
  606. var b = m[0] * transpose[1] + m[1] * transpose[3];
  607. var c = m[2] * transpose[0] + m[3] * transpose[2];
  608. var d = m[2] * transpose[1] + m[3] * transpose[3];
  609. // Solve the second degree polynomial to get roots.
  610. var first = (a + d) / 2;
  611. var second = Math.sqrt((a + d) * (a + d) - 4 * (a * d - c * b)) / 2;
  612. var sx = first + second || 1;
  613. var sy = first - second || 1;
  614. // Scale values are the square roots of the eigenvalues.
  615. return [Math.sqrt(sx), Math.sqrt(sy)];
  616. };
  617. // Normalize rectangle rect=[x1, y1, x2, y2] so that (x1,y1) < (x2,y2)
  618. // For coordinate systems whose origin lies in the bottom-left, this
  619. // means normalization to (BL,TR) ordering. For systems with origin in the
  620. // top-left, this means (TL,BR) ordering.
  621. Util.normalizeRect = function Util_normalizeRect(rect) {
  622. var r = rect.slice(0); // clone rect
  623. if (rect[0] > rect[2]) {
  624. r[0] = rect[2];
  625. r[2] = rect[0];
  626. }
  627. if (rect[1] > rect[3]) {
  628. r[1] = rect[3];
  629. r[3] = rect[1];
  630. }
  631. return r;
  632. };
  633. // Returns a rectangle [x1, y1, x2, y2] corresponding to the
  634. // intersection of rect1 and rect2. If no intersection, returns 'false'
  635. // The rectangle coordinates of rect1, rect2 should be [x1, y1, x2, y2]
  636. Util.intersect = function Util_intersect(rect1, rect2) {
  637. function compare(a, b) {
  638. return a - b;
  639. }
  640. // Order points along the axes
  641. var orderedX = [rect1[0], rect1[2], rect2[0], rect2[2]].sort(compare),
  642. orderedY = [rect1[1], rect1[3], rect2[1], rect2[3]].sort(compare),
  643. result = [];
  644. rect1 = Util.normalizeRect(rect1);
  645. rect2 = Util.normalizeRect(rect2);
  646. // X: first and second points belong to different rectangles?
  647. if ((orderedX[0] === rect1[0] && orderedX[1] === rect2[0]) ||
  648. (orderedX[0] === rect2[0] && orderedX[1] === rect1[0])) {
  649. // Intersection must be between second and third points
  650. result[0] = orderedX[1];
  651. result[2] = orderedX[2];
  652. } else {
  653. return false;
  654. }
  655. // Y: first and second points belong to different rectangles?
  656. if ((orderedY[0] === rect1[1] && orderedY[1] === rect2[1]) ||
  657. (orderedY[0] === rect2[1] && orderedY[1] === rect1[1])) {
  658. // Intersection must be between second and third points
  659. result[1] = orderedY[1];
  660. result[3] = orderedY[2];
  661. } else {
  662. return false;
  663. }
  664. return result;
  665. };
  666. Util.sign = function Util_sign(num) {
  667. return num < 0 ? -1 : 1;
  668. };
  669. Util.appendToArray = function Util_appendToArray(arr1, arr2) {
  670. Array.prototype.push.apply(arr1, arr2);
  671. };
  672. Util.prependToArray = function Util_prependToArray(arr1, arr2) {
  673. Array.prototype.unshift.apply(arr1, arr2);
  674. };
  675. Util.extendObj = function extendObj(obj1, obj2) {
  676. for (var key in obj2) {
  677. obj1[key] = obj2[key];
  678. }
  679. };
  680. Util.getInheritableProperty = function Util_getInheritableProperty(dict,
  681. name) {
  682. while (dict && !dict.has(name)) {
  683. dict = dict.get('Parent');
  684. }
  685. if (!dict) {
  686. return null;
  687. }
  688. return dict.get(name);
  689. };
  690. Util.inherit = function Util_inherit(sub, base, prototype) {
  691. sub.prototype = Object.create(base.prototype);
  692. sub.prototype.constructor = sub;
  693. for (var prop in prototype) {
  694. sub.prototype[prop] = prototype[prop];
  695. }
  696. };
  697. Util.loadScript = function Util_loadScript(src, callback) {
  698. var script = document.createElement('script');
  699. var loaded = false;
  700. script.setAttribute('src', src);
  701. if (callback) {
  702. script.onload = function() {
  703. if (!loaded) {
  704. callback();
  705. }
  706. loaded = true;
  707. };
  708. }
  709. document.getElementsByTagName('head')[0].appendChild(script);
  710. };
  711. return Util;
  712. })();
  713. /**
  714. * PDF page viewport created based on scale, rotation and offset.
  715. * @class
  716. * @alias PDFJS.PageViewport
  717. */
  718. var PageViewport = PDFJS.PageViewport = (function PageViewportClosure() {
  719. /**
  720. * @constructor
  721. * @private
  722. * @param viewBox {Array} xMin, yMin, xMax and yMax coordinates.
  723. * @param scale {number} scale of the viewport.
  724. * @param rotation {number} rotations of the viewport in degrees.
  725. * @param offsetX {number} offset X
  726. * @param offsetY {number} offset Y
  727. * @param dontFlip {boolean} if true, axis Y will not be flipped.
  728. */
  729. function PageViewport(viewBox, scale, rotation, offsetX, offsetY, dontFlip) {
  730. this.viewBox = viewBox;
  731. this.scale = scale;
  732. this.rotation = rotation;
  733. this.offsetX = offsetX;
  734. this.offsetY = offsetY;
  735. // creating transform to convert pdf coordinate system to the normal
  736. // canvas like coordinates taking in account scale and rotation
  737. var centerX = (viewBox[2] + viewBox[0]) / 2;
  738. var centerY = (viewBox[3] + viewBox[1]) / 2;
  739. var rotateA, rotateB, rotateC, rotateD;
  740. rotation = rotation % 360;
  741. rotation = rotation < 0 ? rotation + 360 : rotation;
  742. switch (rotation) {
  743. case 180:
  744. rotateA = -1; rotateB = 0; rotateC = 0; rotateD = 1;
  745. break;
  746. case 90:
  747. rotateA = 0; rotateB = 1; rotateC = 1; rotateD = 0;
  748. break;
  749. case 270:
  750. rotateA = 0; rotateB = -1; rotateC = -1; rotateD = 0;
  751. break;
  752. //case 0:
  753. default:
  754. rotateA = 1; rotateB = 0; rotateC = 0; rotateD = -1;
  755. break;
  756. }
  757. if (dontFlip) {
  758. rotateC = -rotateC; rotateD = -rotateD;
  759. }
  760. var offsetCanvasX, offsetCanvasY;
  761. var width, height;
  762. if (rotateA === 0) {
  763. offsetCanvasX = Math.abs(centerY - viewBox[1]) * scale + offsetX;
  764. offsetCanvasY = Math.abs(centerX - viewBox[0]) * scale + offsetY;
  765. width = Math.abs(viewBox[3] - viewBox[1]) * scale;
  766. height = Math.abs(viewBox[2] - viewBox[0]) * scale;
  767. } else {
  768. offsetCanvasX = Math.abs(centerX - viewBox[0]) * scale + offsetX;
  769. offsetCanvasY = Math.abs(centerY - viewBox[1]) * scale + offsetY;
  770. width = Math.abs(viewBox[2] - viewBox[0]) * scale;
  771. height = Math.abs(viewBox[3] - viewBox[1]) * scale;
  772. }
  773. // creating transform for the following operations:
  774. // translate(-centerX, -centerY), rotate and flip vertically,
  775. // scale, and translate(offsetCanvasX, offsetCanvasY)
  776. this.transform = [
  777. rotateA * scale,
  778. rotateB * scale,
  779. rotateC * scale,
  780. rotateD * scale,
  781. offsetCanvasX - rotateA * scale * centerX - rotateC * scale * centerY,
  782. offsetCanvasY - rotateB * scale * centerX - rotateD * scale * centerY
  783. ];
  784. this.width = width;
  785. this.height = height;
  786. this.fontScale = scale;
  787. }
  788. PageViewport.prototype = /** @lends PDFJS.PageViewport.prototype */ {
  789. /**
  790. * Clones viewport with additional properties.
  791. * @param args {Object} (optional) If specified, may contain the 'scale' or
  792. * 'rotation' properties to override the corresponding properties in
  793. * the cloned viewport.
  794. * @returns {PDFJS.PageViewport} Cloned viewport.
  795. */
  796. clone: function PageViewPort_clone(args) {
  797. args = args || {};
  798. var scale = 'scale' in args ? args.scale : this.scale;
  799. var rotation = 'rotation' in args ? args.rotation : this.rotation;
  800. return new PageViewport(this.viewBox.slice(), scale, rotation,
  801. this.offsetX, this.offsetY, args.dontFlip);
  802. },
  803. /**
  804. * Converts PDF point to the viewport coordinates. For examples, useful for
  805. * converting PDF location into canvas pixel coordinates.
  806. * @param x {number} X coordinate.
  807. * @param y {number} Y coordinate.
  808. * @returns {Object} Object that contains 'x' and 'y' properties of the
  809. * point in the viewport coordinate space.
  810. * @see {@link convertToPdfPoint}
  811. * @see {@link convertToViewportRectangle}
  812. */
  813. convertToViewportPoint: function PageViewport_convertToViewportPoint(x, y) {
  814. return Util.applyTransform([x, y], this.transform);
  815. },
  816. /**
  817. * Converts PDF rectangle to the viewport coordinates.
  818. * @param rect {Array} xMin, yMin, xMax and yMax coordinates.
  819. * @returns {Array} Contains corresponding coordinates of the rectangle
  820. * in the viewport coordinate space.
  821. * @see {@link convertToViewportPoint}
  822. */
  823. convertToViewportRectangle:
  824. function PageViewport_convertToViewportRectangle(rect) {
  825. var tl = Util.applyTransform([rect[0], rect[1]], this.transform);
  826. var br = Util.applyTransform([rect[2], rect[3]], this.transform);
  827. return [tl[0], tl[1], br[0], br[1]];
  828. },
  829. /**
  830. * Converts viewport coordinates to the PDF location. For examples, useful
  831. * for converting canvas pixel location into PDF one.
  832. * @param x {number} X coordinate.
  833. * @param y {number} Y coordinate.
  834. * @returns {Object} Object that contains 'x' and 'y' properties of the
  835. * point in the PDF coordinate space.
  836. * @see {@link convertToViewportPoint}
  837. */
  838. convertToPdfPoint: function PageViewport_convertToPdfPoint(x, y) {
  839. return Util.applyInverseTransform([x, y], this.transform);
  840. }
  841. };
  842. return PageViewport;
  843. })();
  844. var PDFStringTranslateTable = [
  845. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  846. 0x2D8, 0x2C7, 0x2C6, 0x2D9, 0x2DD, 0x2DB, 0x2DA, 0x2DC, 0, 0, 0, 0, 0, 0, 0,
  847. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  848. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  849. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  850. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x2022, 0x2020, 0x2021, 0x2026, 0x2014,
  851. 0x2013, 0x192, 0x2044, 0x2039, 0x203A, 0x2212, 0x2030, 0x201E, 0x201C,
  852. 0x201D, 0x2018, 0x2019, 0x201A, 0x2122, 0xFB01, 0xFB02, 0x141, 0x152, 0x160,
  853. 0x178, 0x17D, 0x131, 0x142, 0x153, 0x161, 0x17E, 0, 0x20AC
  854. ];
  855. function stringToPDFString(str) {
  856. var i, n = str.length, strBuf = [];
  857. if (str[0] === '\xFE' && str[1] === '\xFF') {
  858. // UTF16BE BOM
  859. for (i = 2; i < n; i += 2) {
  860. strBuf.push(String.fromCharCode(
  861. (str.charCodeAt(i) << 8) | str.charCodeAt(i + 1)));
  862. }
  863. } else {
  864. for (i = 0; i < n; ++i) {
  865. var code = PDFStringTranslateTable[str.charCodeAt(i)];
  866. strBuf.push(code ? String.fromCharCode(code) : str.charAt(i));
  867. }
  868. }
  869. return strBuf.join('');
  870. }
  871. function stringToUTF8String(str) {
  872. return decodeURIComponent(escape(str));
  873. }
  874. function isEmptyObj(obj) {
  875. for (var key in obj) {
  876. return false;
  877. }
  878. return true;
  879. }
  880. function isBool(v) {
  881. return typeof v === 'boolean';
  882. }
  883. function isInt(v) {
  884. return typeof v === 'number' && ((v | 0) === v);
  885. }
  886. function isNum(v) {
  887. return typeof v === 'number';
  888. }
  889. function isString(v) {
  890. return typeof v === 'string';
  891. }
  892. function isName(v) {
  893. return v instanceof Name;
  894. }
  895. function isCmd(v, cmd) {
  896. return v instanceof Cmd && (cmd === undefined || v.cmd === cmd);
  897. }
  898. function isDict(v, type) {
  899. if (!(v instanceof Dict)) {
  900. return false;
  901. }
  902. if (!type) {
  903. return true;
  904. }
  905. var dictType = v.get('Type');
  906. return isName(dictType) && dictType.name === type;
  907. }
  908. function isArray(v) {
  909. return v instanceof Array;
  910. }
  911. function isStream(v) {
  912. return typeof v === 'object' && v !== null && v.getBytes !== undefined;
  913. }
  914. function isArrayBuffer(v) {
  915. return typeof v === 'object' && v !== null && v.byteLength !== undefined;
  916. }
  917. function isRef(v) {
  918. return v instanceof Ref;
  919. }
  920. /**
  921. * Promise Capability object.
  922. *
  923. * @typedef {Object} PromiseCapability
  924. * @property {Promise} promise - A promise object.
  925. * @property {function} resolve - Fullfills the promise.
  926. * @property {function} reject - Rejects the promise.
  927. */
  928. /**
  929. * Creates a promise capability object.
  930. * @alias PDFJS.createPromiseCapability
  931. *
  932. * @return {PromiseCapability} A capability object contains:
  933. * - a Promise, resolve and reject methods.
  934. */
  935. function createPromiseCapability() {
  936. var capability = {};
  937. capability.promise = new Promise(function (resolve, reject) {
  938. capability.resolve = resolve;
  939. capability.reject = reject;
  940. });
  941. return capability;
  942. }
  943. PDFJS.createPromiseCapability = createPromiseCapability;
  944. /**
  945. * Polyfill for Promises:
  946. * The following promise implementation tries to generally implement the
  947. * Promise/A+ spec. Some notable differences from other promise libaries are:
  948. * - There currently isn't a seperate deferred and promise object.
  949. * - Unhandled rejections eventually show an error if they aren't handled.
  950. *
  951. * Based off of the work in:
  952. * https://bugzilla.mozilla.org/show_bug.cgi?id=810490
  953. */
  954. (function PromiseClosure() {
  955. if (globalScope.Promise) {
  956. // Promises existing in the DOM/Worker, checking presence of all/resolve
  957. if (typeof globalScope.Promise.all !== 'function') {
  958. globalScope.Promise.all = function (iterable) {
  959. var count = 0, results = [], resolve, reject;
  960. var promise = new globalScope.Promise(function (resolve_, reject_) {
  961. resolve = resolve_;
  962. reject = reject_;
  963. });
  964. iterable.forEach(function (p, i) {
  965. count++;
  966. p.then(function (result) {
  967. results[i] = result;
  968. count--;
  969. if (count === 0) {
  970. resolve(results);
  971. }
  972. }, reject);
  973. });
  974. if (count === 0) {
  975. resolve(results);
  976. }
  977. return promise;
  978. };
  979. }
  980. if (typeof globalScope.Promise.resolve !== 'function') {
  981. globalScope.Promise.resolve = function (value) {
  982. return new globalScope.Promise(function (resolve) { resolve(value); });
  983. };
  984. }
  985. if (typeof globalScope.Promise.reject !== 'function') {
  986. globalScope.Promise.reject = function (reason) {
  987. return new globalScope.Promise(function (resolve, reject) {
  988. reject(reason);
  989. });
  990. };
  991. }
  992. if (typeof globalScope.Promise.prototype.catch !== 'function') {
  993. globalScope.Promise.prototype.catch = function (onReject) {
  994. return globalScope.Promise.prototype.then(undefined, onReject);
  995. };
  996. }
  997. return;
  998. }
  999. var STATUS_PENDING = 0;
  1000. var STATUS_RESOLVED = 1;
  1001. var STATUS_REJECTED = 2;
  1002. // In an attempt to avoid silent exceptions, unhandled rejections are
  1003. // tracked and if they aren't handled in a certain amount of time an
  1004. // error is logged.
  1005. var REJECTION_TIMEOUT = 500;
  1006. var HandlerManager = {
  1007. handlers: [],
  1008. running: false,
  1009. unhandledRejections: [],
  1010. pendingRejectionCheck: false,
  1011. scheduleHandlers: function scheduleHandlers(promise) {
  1012. if (promise._status === STATUS_PENDING) {
  1013. return;
  1014. }
  1015. this.handlers = this.handlers.concat(promise._handlers);
  1016. promise._handlers = [];
  1017. if (this.running) {
  1018. return;
  1019. }
  1020. this.running = true;
  1021. setTimeout(this.runHandlers.bind(this), 0);
  1022. },
  1023. runHandlers: function runHandlers() {
  1024. var RUN_TIMEOUT = 1; // ms
  1025. var timeoutAt = Date.now() + RUN_TIMEOUT;
  1026. while (this.handlers.length > 0) {
  1027. var handler = this.handlers.shift();
  1028. var nextStatus = handler.thisPromise._status;
  1029. var nextValue = handler.thisPromise._value;
  1030. try {
  1031. if (nextStatus === STATUS_RESOLVED) {
  1032. if (typeof handler.onResolve === 'function') {
  1033. nextValue = handler.onResolve(nextValue);
  1034. }
  1035. } else if (typeof handler.onReject === 'function') {
  1036. nextValue = handler.onReject(nextValue);
  1037. nextStatus = STATUS_RESOLVED;
  1038. if (handler.thisPromise._unhandledRejection) {
  1039. this.removeUnhandeledRejection(handler.thisPromise);
  1040. }
  1041. }
  1042. } catch (ex) {
  1043. nextStatus = STATUS_REJECTED;
  1044. nextValue = ex;
  1045. }
  1046. handler.nextPromise._updateStatus(nextStatus, nextValue);
  1047. if (Date.now() >= timeoutAt) {
  1048. break;
  1049. }
  1050. }
  1051. if (this.handlers.length > 0) {
  1052. setTimeout(this.runHandlers.bind(this), 0);
  1053. return;
  1054. }
  1055. this.running = false;
  1056. },
  1057. addUnhandledRejection: function addUnhandledRejection(promise) {
  1058. this.unhandledRejections.push({
  1059. promise: promise,
  1060. time: Date.now()
  1061. });
  1062. this.scheduleRejectionCheck();
  1063. },
  1064. removeUnhandeledRejection: function removeUnhandeledRejection(promise) {
  1065. promise._unhandledRejection = false;
  1066. for (var i = 0; i < this.unhandledRejections.length; i++) {
  1067. if (this.unhandledRejections[i].promise === promise) {
  1068. this.unhandledRejections.splice(i);
  1069. i--;
  1070. }
  1071. }
  1072. },
  1073. scheduleRejectionCheck: function scheduleRejectionCheck() {
  1074. if (this.pendingRejectionCheck) {
  1075. return;
  1076. }
  1077. this.pendingRejectionCheck = true;
  1078. setTimeout(function rejectionCheck() {
  1079. this.pendingRejectionCheck = false;
  1080. var now = Date.now();
  1081. for (var i = 0; i < this.unhandledRejections.length; i++) {
  1082. if (now - this.unhandledRejections[i].time > REJECTION_TIMEOUT) {
  1083. var unhandled = this.unhandledRejections[i].promise._value;
  1084. var msg = 'Unhandled rejection: ' + unhandled;
  1085. if (unhandled.stack) {
  1086. msg += '\n' + unhandled.stack;
  1087. }
  1088. warn(msg);
  1089. this.unhandledRejections.splice(i);
  1090. i--;
  1091. }
  1092. }
  1093. if (this.unhandledRejections.length) {
  1094. this.scheduleRejectionCheck();
  1095. }
  1096. }.bind(this), REJECTION_TIMEOUT);
  1097. }
  1098. };
  1099. function Promise(resolver) {
  1100. this._status = STATUS_PENDING;
  1101. this._handlers = [];
  1102. try {
  1103. resolver.call(this, this._resolve.bind(this), this._reject.bind(this));
  1104. } catch (e) {
  1105. this._reject(e);
  1106. }
  1107. }
  1108. /**
  1109. * Builds a promise that is resolved when all the passed in promises are
  1110. * resolved.
  1111. * @param {array} array of data and/or promises to wait for.
  1112. * @return {Promise} New dependant promise.
  1113. */
  1114. Promise.all = function Promise_all(promises) {
  1115. var resolveAll, rejectAll;
  1116. var deferred = new Promise(function (resolve, reject) {
  1117. resolveAll = resolve;
  1118. rejectAll = reject;
  1119. });
  1120. var unresolved = promises.length;
  1121. var results = [];
  1122. if (unresolved === 0) {
  1123. resolveAll(results);
  1124. return deferred;
  1125. }
  1126. function reject(reason) {
  1127. if (deferred._status === STATUS_REJECTED) {
  1128. return;
  1129. }
  1130. results = [];
  1131. rejectAll(reason);
  1132. }
  1133. for (var i = 0, ii = promises.length; i < ii; ++i) {
  1134. var promise = promises[i];
  1135. var resolve = (function(i) {
  1136. return function(value) {
  1137. if (deferred._status === STATUS_REJECTED) {
  1138. return;
  1139. }
  1140. results[i] = value;
  1141. unresolved--;
  1142. if (unresolved === 0) {
  1143. resolveAll(results);
  1144. }
  1145. };
  1146. })(i);
  1147. if (Promise.isPromise(promise)) {
  1148. promise.then(resolve, reject);
  1149. } else {
  1150. resolve(promise);
  1151. }
  1152. }
  1153. return deferred;
  1154. };
  1155. /**
  1156. * Checks if the value is likely a promise (has a 'then' function).
  1157. * @return {boolean} true if value is thenable
  1158. */
  1159. Promise.isPromise = function Promise_isPromise(value) {
  1160. return value && typeof value.then === 'function';
  1161. };
  1162. /**
  1163. * Creates resolved promise
  1164. * @param value resolve value
  1165. * @returns {Promise}
  1166. */
  1167. Promise.resolve = function Promise_resolve(value) {
  1168. return new Promise(function (resolve) { resolve(value); });
  1169. };
  1170. /**
  1171. * Creates rejected promise
  1172. * @param reason rejection value
  1173. * @returns {Promise}
  1174. */
  1175. Promise.reject = function Promise_reject(reason) {
  1176. return new Promise(function (resolve, reject) { reject(reason); });
  1177. };
  1178. Promise.prototype = {
  1179. _status: null,
  1180. _value: null,
  1181. _handlers: null,
  1182. _unhandledRejection: null,
  1183. _updateStatus: function Promise__updateStatus(status, value) {
  1184. if (this._status === STATUS_RESOLVED ||
  1185. this._status === STATUS_REJECTED) {
  1186. return;
  1187. }
  1188. if (status === STATUS_RESOLVED &&
  1189. Promise.isPromise(value)) {
  1190. value.then(this._updateStatus.bind(this, STATUS_RESOLVED),
  1191. this._updateStatus.bind(this, STATUS_REJECTED));
  1192. return;
  1193. }
  1194. this._status = status;
  1195. this._value = value;
  1196. if (status === STATUS_REJECTED && this._handlers.length === 0) {
  1197. this._unhandledRejection = true;
  1198. HandlerManager.addUnhandledRejection(this);
  1199. }
  1200. HandlerManager.scheduleHandlers(this);
  1201. },
  1202. _resolve: function Promise_resolve(value) {
  1203. this._updateStatus(STATUS_RESOLVED, value);
  1204. },
  1205. _reject: function Promise_reject(reason) {
  1206. this._updateStatus(STATUS_REJECTED, reason);
  1207. },
  1208. then: function Promise_then(onResolve, onReject) {
  1209. var nextPromise = new Promise(function (resolve, reject) {
  1210. this.resolve = resolve;
  1211. this.reject = reject;
  1212. });
  1213. this._handlers.push({
  1214. thisPromise: this,
  1215. onResolve: onResolve,
  1216. onReject: onReject,
  1217. nextPromise: nextPromise
  1218. });
  1219. HandlerManager.scheduleHandlers(this);
  1220. return nextPromise;
  1221. },
  1222. catch: function Promise_catch(onReject) {
  1223. return this.then(undefined, onReject);
  1224. }
  1225. };
  1226. globalScope.Promise = Promise;
  1227. })();
  1228. var StatTimer = (function StatTimerClosure() {
  1229. function rpad(str, pad, length) {
  1230. while (str.length < length) {
  1231. str += pad;
  1232. }
  1233. return str;
  1234. }
  1235. function StatTimer() {
  1236. this.started = {};
  1237. this.times = [];
  1238. this.enabled = true;
  1239. }
  1240. StatTimer.prototype = {
  1241. time: function StatTimer_time(name) {
  1242. if (!this.enabled) {
  1243. return;
  1244. }
  1245. if (name in this.started) {
  1246. warn('Timer is already running for ' + name);
  1247. }
  1248. this.started[name] = Date.now();
  1249. },
  1250. timeEnd: function StatTimer_timeEnd(name) {
  1251. if (!this.enabled) {
  1252. return;
  1253. }
  1254. if (!(name in this.started)) {
  1255. warn('Timer has not been started for ' + name);
  1256. }
  1257. this.times.push({
  1258. 'name': name,
  1259. 'start': this.started[name],
  1260. 'end': Date.now()
  1261. });
  1262. // Remove timer from started so it can be called again.
  1263. delete this.started[name];
  1264. },
  1265. toString: function StatTimer_toString() {
  1266. var i, ii;
  1267. var times = this.times;
  1268. var out = '';
  1269. // Find the longest name for padding purposes.
  1270. var longest = 0;
  1271. for (i = 0, ii = times.length; i < ii; ++i) {
  1272. var name = times[i]['name'];
  1273. if (name.length > longest) {
  1274. longest = name.length;
  1275. }
  1276. }
  1277. for (i = 0, ii = times.length; i < ii; ++i) {
  1278. var span = times[i];
  1279. var duration = span.end - span.start;
  1280. out += rpad(span['name'], ' ', longest) + ' ' + duration + 'ms\n';
  1281. }
  1282. return out;
  1283. }
  1284. };
  1285. return StatTimer;
  1286. })();
  1287. PDFJS.createBlob = function createBlob(data, contentType) {
  1288. if (typeof Blob !== 'undefined') {
  1289. return new Blob([data], { type: contentType });
  1290. }
  1291. // Blob builder is deprecated in FF14 and removed in FF18.
  1292. var bb = new MozBlobBuilder();
  1293. bb.append(data);
  1294. return bb.getBlob(contentType);
  1295. };
  1296. PDFJS.createObjectURL = (function createObjectURLClosure() {
  1297. // Blob/createObjectURL is not available, falling back to data schema.
  1298. var digits =
  1299. 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
  1300. return function createObjectURL(data, contentType) {
  1301. if (!PDFJS.disableCreateObjectURL &&
  1302. typeof URL !== 'undefined' && URL.createObjectURL) {
  1303. var blob = PDFJS.createBlob(data, contentType);
  1304. return URL.createObjectURL(blob);
  1305. }
  1306. var buffer = 'data:' + contentType + ';base64,';
  1307. for (var i = 0, ii = data.length; i < ii; i += 3) {
  1308. var b1 = data[i] & 0xFF;
  1309. var b2 = data[i + 1] & 0xFF;
  1310. var b3 = data[i + 2] & 0xFF;
  1311. var d1 = b1 >> 2, d2 = ((b1 & 3) << 4) | (b2 >> 4);
  1312. var d3 = i + 1 < ii ? ((b2 & 0xF) << 2) | (b3 >> 6) : 64;
  1313. var d4 = i + 2 < ii ? (b3 & 0x3F) : 64;
  1314. buffer += digits[d1] + digits[d2] + digits[d3] + digits[d4];
  1315. }
  1316. return buffer;
  1317. };
  1318. })();
  1319. function MessageHandler(name, comObj) {
  1320. this.name = name;
  1321. this.comObj = comObj;
  1322. this.callbackIndex = 1;
  1323. this.postMessageTransfers = true;
  1324. var callbacksCapabilities = this.callbacksCapabilities = {};
  1325. var ah = this.actionHandler = {};
  1326. ah['console_log'] = [function ahConsoleLog(data) {
  1327. console.log.apply(console, data);
  1328. }];
  1329. ah['console_error'] = [function ahConsoleError(data) {
  1330. console.error.apply(console, data);
  1331. }];
  1332. ah['_unsupported_feature'] = [function ah_unsupportedFeature(data) {
  1333. UnsupportedManager.notify(data);
  1334. }];
  1335. comObj.onmessage = function messageHandlerComObjOnMessage(event) {
  1336. var data = event.data;
  1337. if (data.isReply) {
  1338. var callbackId = data.callbackId;
  1339. if (data.callbackId in callbacksCapabilities) {
  1340. var callback = callbacksCapabilities[callbackId];
  1341. delete callbacksCapabilities[callbackId];
  1342. if ('error' in data) {
  1343. callback.reject(data.error);
  1344. } else {
  1345. callback.resolve(data.data);
  1346. }
  1347. } else {
  1348. error('Cannot resolve callback ' + callbackId);
  1349. }
  1350. } else if (data.action in ah) {
  1351. var action = ah[data.action];
  1352. if (data.callbackId) {
  1353. Promise.resolve().then(function () {
  1354. return action[0].call(action[1], data.data);
  1355. }).then(function (result) {
  1356. comObj.postMessage({
  1357. isReply: true,
  1358. callbackId: data.callbackId,
  1359. data: result
  1360. });
  1361. }, function (reason) {
  1362. comObj.postMessage({
  1363. isReply: true,
  1364. callbackId: data.callbackId,
  1365. error: reason
  1366. });
  1367. });
  1368. } else {
  1369. action[0].call(action[1], data.data);
  1370. }
  1371. } else {
  1372. error('Unknown action from worker: ' + data.action);
  1373. }
  1374. };
  1375. }
  1376. MessageHandler.prototype = {
  1377. on: function messageHandlerOn(actionName, handler, scope) {
  1378. var ah = this.actionHandler;
  1379. if (ah[actionName]) {
  1380. error('There is already an actionName called "' + actionName + '"');
  1381. }
  1382. ah[actionName] = [handler, scope];
  1383. },
  1384. /**
  1385. * Sends a message to the comObj to invoke the action with the supplied data.
  1386. * @param {String} actionName Action to call.
  1387. * @param {JSON} data JSON data to send.
  1388. * @param {Array} [transfers] Optional list of transfers/ArrayBuffers
  1389. */
  1390. send: function messageHandlerSend(actionName, data, transfers) {
  1391. var message = {
  1392. action: actionName,
  1393. data: data
  1394. };
  1395. this.postMessage(message, transfers);
  1396. },
  1397. /**
  1398. * Sends a message to the comObj to invoke the action with the supplied data.
  1399. * Expects that other side will callback with the response.
  1400. * @param {String} actionName Action to call.
  1401. * @param {JSON} data JSON data to send.
  1402. * @param {Array} [transfers] Optional list of transfers/ArrayBuffers.
  1403. * @returns {Promise} Promise to be resolved with response data.
  1404. */
  1405. sendWithPromise:
  1406. function messageHandlerSendWithPromise(actionName, data, transfers) {
  1407. var callbackId = this.callbackIndex++;
  1408. var message = {
  1409. action: actionName,
  1410. data: data,
  1411. callbackId: callbackId
  1412. };
  1413. var capability = createPromiseCapability();
  1414. this.callbacksCapabilities[callbackId] = capability;
  1415. try {
  1416. this.postMessage(message, transfers);
  1417. } catch (e) {
  1418. capability.reject(e);
  1419. }
  1420. return capability.promise;
  1421. },
  1422. /**
  1423. * Sends raw message to the comObj.
  1424. * @private
  1425. * @param message {Object} Raw message.
  1426. * @param transfers List of transfers/ArrayBuffers, or undefined.
  1427. */
  1428. postMessage: function (message, transfers) {
  1429. if (transfers && this.postMessageTransfers) {
  1430. this.comObj.postMessage(message, transfers);
  1431. } else {
  1432. this.comObj.postMessage(message);
  1433. }
  1434. }
  1435. };
  1436. function loadJpegStream(id, imageUrl, objs) {
  1437. var img = new Image();
  1438. img.onload = (function loadJpegStream_onloadClosure() {
  1439. objs.resolve(id, img);
  1440. });
  1441. img.onerror = (function loadJpegStream_onerrorClosure() {
  1442. objs.resolve(id, null);
  1443. warn('Error during JPEG image loading');
  1444. });
  1445. img.src = imageUrl;
  1446. }
  1447. /**
  1448. * The maximum allowed image size in total pixels e.g. width * height. Images
  1449. * above this value will not be drawn. Use -1 for no limit.
  1450. * @var {number}
  1451. */
  1452. PDFJS.maxImageSize = (PDFJS.maxImageSize === undefined ?
  1453. -1 : PDFJS.maxImageSize);
  1454. /**
  1455. * The url of where the predefined Adobe CMaps are located. Include trailing
  1456. * slash.
  1457. * @var {string}
  1458. */
  1459. PDFJS.cMapUrl = (PDFJS.cMapUrl === undefined ? null : PDFJS.cMapUrl);
  1460. /**
  1461. * Specifies if CMaps are binary packed.
  1462. * @var {boolean}
  1463. */
  1464. PDFJS.cMapPacked = PDFJS.cMapPacked === undefined ? false : PDFJS.cMapPacked;
  1465. /**
  1466. * By default fonts are converted to OpenType fonts and loaded via font face
  1467. * rules. If disabled, the font will be rendered using a built in font renderer
  1468. * that constructs the glyphs with primitive path commands.
  1469. * @var {boolean}
  1470. */
  1471. PDFJS.disableFontFace = (PDFJS.disableFontFace === undefined ?
  1472. false : PDFJS.disableFontFace);
  1473. /**
  1474. * Path for image resources, mainly for annotation icons. Include trailing
  1475. * slash.
  1476. * @var {string}
  1477. */
  1478. PDFJS.imageResourcesPath = (PDFJS.imageResourcesPath === undefined ?
  1479. '' : PDFJS.imageResourcesPath);
  1480. /**
  1481. * Disable the web worker and run all code on the main thread. This will happen
  1482. * automatically if the browser doesn't support workers or sending typed arrays
  1483. * to workers.
  1484. * @var {boolean}
  1485. */
  1486. PDFJS.disableWorker = (PDFJS.disableWorker === undefined ?
  1487. false : PDFJS.disableWorker);
  1488. /**
  1489. * Path and filename of the worker file. Required when the worker is enabled in
  1490. * development mode. If unspecified in the production build, the worker will be
  1491. * loaded based on the location of the pdf.js file.
  1492. * @var {string}
  1493. */
  1494. PDFJS.workerSrc = (PDFJS.workerSrc === undefined ? null : PDFJS.workerSrc);
  1495. /**
  1496. * Disable range request loading of PDF files. When enabled and if the server
  1497. * supports partial content requests then the PDF will be fetched in chunks.
  1498. * Enabled (false) by default.
  1499. * @var {boolean}
  1500. */
  1501. PDFJS.disableRange = (PDFJS.disableRange === undefined ?
  1502. false : PDFJS.disableRange);
  1503. /**
  1504. * Disable streaming of PDF file data. By default PDF.js attempts to load PDF
  1505. * in chunks. This default behavior can be disabled.
  1506. * @var {boolean}
  1507. */
  1508. PDFJS.disableStream = (PDFJS.disableStream === undefined ?
  1509. false : PDFJS.disableStream);
  1510. /**
  1511. * Disable pre-fetching of PDF file data. When range requests are enabled PDF.js
  1512. * will automatically keep fetching more data even if it isn't needed to display
  1513. * the current page. This default behavior can be disabled.
  1514. *
  1515. * NOTE: It is also necessary to disable streaming, see above,
  1516. * in order for disabling of pre-fetching to work correctly.
  1517. * @var {boolean}
  1518. */
  1519. PDFJS.disableAutoFetch = (PDFJS.disableAutoFetch === undefined ?
  1520. false : PDFJS.disableAutoFetch);
  1521. /**
  1522. * Enables special hooks for debugging PDF.js.
  1523. * @var {boolean}
  1524. */
  1525. PDFJS.pdfBug = (PDFJS.pdfBug === undefined ? false : PDFJS.pdfBug);
  1526. /**
  1527. * Enables transfer usage in postMessage for ArrayBuffers.
  1528. * @var {boolean}
  1529. */
  1530. PDFJS.postMessageTransfers = (PDFJS.postMessageTransfers === undefined ?
  1531. true : PDFJS.postMessageTransfers);
  1532. /**
  1533. * Disables URL.createObjectURL usage.
  1534. * @var {boolean}
  1535. */
  1536. PDFJS.disableCreateObjectURL = (PDFJS.disableCreateObjectURL === undefined ?
  1537. false : PDFJS.disableCreateObjectURL);
  1538. /**
  1539. * Disables WebGL usage.
  1540. * @var {boolean}
  1541. */
  1542. PDFJS.disableWebGL = (PDFJS.disableWebGL === undefined ?
  1543. true : PDFJS.disableWebGL);
  1544. /**
  1545. * Disables fullscreen support, and by extension Presentation Mode,
  1546. * in browsers which support the fullscreen API.
  1547. * @var {boolean}
  1548. */
  1549. PDFJS.disableFullscreen = (PDFJS.disableFullscreen === undefined ?
  1550. false : PDFJS.disableFullscreen);
  1551. /**
  1552. * Enables CSS only zooming.
  1553. * @var {boolean}
  1554. */
  1555. PDFJS.useOnlyCssZoom = (PDFJS.useOnlyCssZoom === undefined ?
  1556. false : PDFJS.useOnlyCssZoom);
  1557. /**
  1558. * Controls the logging level.
  1559. * The constants from PDFJS.VERBOSITY_LEVELS should be used:
  1560. * - errors
  1561. * - warnings [default]
  1562. * - infos
  1563. * @var {number}
  1564. */
  1565. PDFJS.verbosity = (PDFJS.verbosity === undefined ?
  1566. PDFJS.VERBOSITY_LEVELS.warnings : PDFJS.verbosity);
  1567. /**
  1568. * The maximum supported canvas size in total pixels e.g. width * height.
  1569. * The default value is 4096 * 4096. Use -1 for no limit.
  1570. * @var {number}
  1571. */
  1572. PDFJS.maxCanvasPixels = (PDFJS.maxCanvasPixels === undefined ?
  1573. 16777216 : PDFJS.maxCanvasPixels);
  1574. /**
  1575. * Opens external links in a new window if enabled. The default behavior opens
  1576. * external links in the PDF.js window.
  1577. * @var {boolean}
  1578. */
  1579. PDFJS.openExternalLinksInNewWindow = (
  1580. PDFJS.openExternalLinksInNewWindow === undefined ?
  1581. false : PDFJS.openExternalLinksInNewWindow);
  1582. /**
  1583. * Document initialization / loading parameters object.
  1584. *
  1585. * @typedef {Object} DocumentInitParameters
  1586. * @property {string} url - The URL of the PDF.
  1587. * @property {TypedArray|Array|string} data - Binary PDF data. Use typed arrays
  1588. * (Uint8Array) to improve the memory usage. If PDF data is BASE64-encoded,
  1589. * use atob() to convert it to a binary string first.
  1590. * @property {Object} httpHeaders - Basic authentication headers.
  1591. * @property {boolean} withCredentials - Indicates whether or not cross-site
  1592. * Access-Control requests should be made using credentials such as cookies
  1593. * or authorization headers. The default is false.
  1594. * @property {string} password - For decrypting password-protected PDFs.
  1595. * @property {TypedArray} initialData - A typed array with the first portion or
  1596. * all of the pdf data. Used by the extension since some data is already
  1597. * loaded before the switch to range requests.
  1598. * @property {number} length - The PDF file length. It's used for progress
  1599. * reports and range requests operations.
  1600. * @property {PDFDataRangeTransport} range
  1601. */
  1602. /**
  1603. * @typedef {Object} PDFDocumentStats
  1604. * @property {Array} streamTypes - Used stream types in the document (an item
  1605. * is set to true if specific stream ID was used in the document).
  1606. * @property {Array} fontTypes - Used font type in the document (an item is set
  1607. * to true if specific font ID was used in the document).
  1608. */
  1609. /**
  1610. * This is the main entry point for loading a PDF and interacting with it.
  1611. * NOTE: If a URL is used to fetch the PDF data a standard XMLHttpRequest(XHR)
  1612. * is used, which means it must follow the same origin rules that any XHR does
  1613. * e.g. No cross domain requests without CORS.
  1614. *
  1615. * @param {string|TypedArray|DocumentInitParameters|PDFDataRangeTransport} src
  1616. * Can be a url to where a PDF is located, a typed array (Uint8Array)
  1617. * already populated with data or parameter object.
  1618. *
  1619. * @param {PDFDataRangeTransport} pdfDataRangeTransport (deprecated) It is used
  1620. * if you want to manually serve range requests for data in the PDF.
  1621. *
  1622. * @param {function} passwordCallback (deprecated) It is used to request a
  1623. * password if wrong or no password was provided. The callback receives two
  1624. * parameters: function that needs to be called with new password and reason
  1625. * (see {PasswordResponses}).
  1626. *
  1627. * @param {function} progressCallback (deprecated) It is used to be able to
  1628. * monitor the loading progress of the PDF file (necessary to implement e.g.
  1629. * a loading bar). The callback receives an {Object} with the properties:
  1630. * {number} loaded and {number} total.
  1631. *
  1632. * @return {PDFDocumentLoadingTask}
  1633. */
  1634. PDFJS.getDocument = function getDocument(src,
  1635. pdfDataRangeTransport,
  1636. passwordCallback,
  1637. progressCallback) {
  1638. var task = new PDFDocumentLoadingTask();
  1639. // Support of the obsolete arguments (for compatibility with API v1.0)
  1640. if (pdfDataRangeTransport) {
  1641. if (!(pdfDataRangeTransport instanceof PDFDataRangeTransport)) {
  1642. // Not a PDFDataRangeTransport instance, trying to add missing properties.
  1643. pdfDataRangeTransport = Object.create(pdfDataRangeTransport);
  1644. pdfDataRangeTransport.length = src.length;
  1645. pdfDataRangeTransport.initialData = src.initialData;
  1646. }
  1647. src = Object.create(src);
  1648. src.range = pdfDataRangeTransport;
  1649. }
  1650. task.onPassword = passwordCallback || null;
  1651. task.onProgress = progressCallback || null;
  1652. var workerInitializedCapability, transport;
  1653. var source;
  1654. if (typeof src === 'string') {
  1655. source = { url: src };
  1656. } else if (isArrayBuffer(src)) {
  1657. source = { data: src };
  1658. } else if (src instanceof PDFDataRangeTransport) {
  1659. source = { range: src };
  1660. } else {
  1661. if (typeof src !== 'object') {
  1662. error('Invalid parameter in getDocument, need either Uint8Array, ' +
  1663. 'string or a parameter object');
  1664. }
  1665. if (!src.url && !src.data && !src.range) {
  1666. error('Invalid parameter object: need either .data, .range or .url');
  1667. }
  1668. source = src;
  1669. }
  1670. var params = {};
  1671. for (var key in source) {
  1672. if (key === 'url' && typeof window !== 'undefined') {
  1673. // The full path is required in the 'url' field.
  1674. params[key] = combineUrl(window.location.href, source[key]);
  1675. continue;
  1676. } else if (key === 'range') {
  1677. continue;
  1678. } else if (key === 'data' && !(source[key] instanceof Uint8Array)) {
  1679. // Converting string or array-like data to Uint8Array.
  1680. var pdfBytes = source[key];
  1681. if (typeof pdfBytes === 'string') {
  1682. params[key] = stringToBytes(pdfBytes);
  1683. } else if (typeof pdfBytes === 'object' && pdfBytes !== null &&
  1684. !isNaN(pdfBytes.length)) {
  1685. params[key] = new Uint8Array(pdfBytes);
  1686. } else {
  1687. error('Invalid PDF binary data: either typed array, string or ' +
  1688. 'array-like object is expected in the data property.');
  1689. }
  1690. continue;
  1691. }
  1692. params[key] = source[key];
  1693. }
  1694. workerInitializedCapability = createPromiseCapability();
  1695. transport = new WorkerTransport(workerInitializedCapability, source.range);
  1696. workerInitializedCapability.promise.then(function transportInitialized() {
  1697. transport.fetchDocument(task, params);
  1698. });
  1699. return task;
  1700. };
  1701. /**
  1702. * PDF document loading operation.
  1703. * @class
  1704. */
  1705. var PDFDocumentLoadingTask = (function PDFDocumentLoadingTaskClosure() {
  1706. /** @constructs PDFDocumentLoadingTask */
  1707. function PDFDocumentLoadingTask() {
  1708. this._capability = createPromiseCapability();
  1709. /**
  1710. * Callback to request a password if wrong or no password was provided.
  1711. * The callback receives two parameters: function that needs to be called
  1712. * with new password and reason (see {PasswordResponses}).
  1713. */
  1714. this.onPassword = null;
  1715. /**
  1716. * Callback to be able to monitor the loading progress of the PDF file
  1717. * (necessary to implement e.g. a loading bar). The callback receives
  1718. * an {Object} with the properties: {number} loaded and {number} total.
  1719. */
  1720. this.onProgress = null;
  1721. }
  1722. PDFDocumentLoadingTask.prototype =
  1723. /** @lends PDFDocumentLoadingTask.prototype */ {
  1724. /**
  1725. * @return {Promise}
  1726. */
  1727. get promise() {
  1728. return this._capability.promise;
  1729. },
  1730. // TODO add cancel or abort method
  1731. /**
  1732. * Registers callbacks to indicate the document loading completion.
  1733. *
  1734. * @param {function} onFulfilled The callback for the loading completion.
  1735. * @param {function} onRejected The callback for the loading failure.
  1736. * @return {Promise} A promise that is resolved after the onFulfilled or
  1737. * onRejected callback.
  1738. */
  1739. then: function PDFDocumentLoadingTask_then(onFulfilled, onRejected) {
  1740. return this.promise.then.apply(this.promise, arguments);
  1741. }
  1742. };
  1743. return PDFDocumentLoadingTask;
  1744. })();
  1745. /**
  1746. * Abstract class to support range requests file loading.
  1747. * @class
  1748. */
  1749. var PDFDataRangeTransport = (function pdfDataRangeTransportClosure() {
  1750. /**
  1751. * @constructs PDFDataRangeTransport
  1752. * @param {number} length
  1753. * @param {Uint8Array} initialData
  1754. */
  1755. function PDFDataRangeTransport(length, initialData) {
  1756. this.length = length;
  1757. this.initialData = initialData;
  1758. this._rangeListeners = [];
  1759. this._progressListeners = [];
  1760. this._progressiveReadListeners = [];
  1761. this._readyCapability = createPromiseCapability();
  1762. }
  1763. PDFDataRangeTransport.prototype =
  1764. /** @lends PDFDataRangeTransport.prototype */ {
  1765. addRangeListener:
  1766. function PDFDataRangeTransport_addRangeListener(listener) {
  1767. this._rangeListeners.push(listener);
  1768. },
  1769. addProgressListener:
  1770. function PDFDataRangeTransport_addProgressListener(listener) {
  1771. this._progressListeners.push(listener);
  1772. },
  1773. addProgressiveReadListener:
  1774. function PDFDataRangeTransport_addProgressiveReadListener(listener) {
  1775. this._progressiveReadListeners.push(listener);
  1776. },
  1777. onDataRange: function PDFDataRangeTransport_onDataRange(begin, chunk) {
  1778. var listeners = this._rangeListeners;
  1779. for (var i = 0, n = listeners.length; i < n; ++i) {
  1780. listeners[i](begin, chunk);
  1781. }
  1782. },
  1783. onDataProgress: function PDFDataRangeTransport_onDataProgress(loaded) {
  1784. this._readyCapability.promise.then(function () {
  1785. var listeners = this._progressListeners;
  1786. for (var i = 0, n = listeners.length; i < n; ++i) {
  1787. listeners[i](loaded);
  1788. }
  1789. }.bind(this));
  1790. },
  1791. onDataProgressiveRead:
  1792. function PDFDataRangeTransport_onDataProgress(chunk) {
  1793. this._readyCapability.promise.then(function () {
  1794. var listeners = this._progressiveReadListeners;
  1795. for (var i = 0, n = listeners.length; i < n; ++i) {
  1796. listeners[i](chunk);
  1797. }
  1798. }.bind(this));
  1799. },
  1800. transportReady: function PDFDataRangeTransport_transportReady() {
  1801. this._readyCapability.resolve();
  1802. },
  1803. requestDataRange:
  1804. function PDFDataRangeTransport_requestDataRange(begin, end) {
  1805. throw new Error('Abstract method PDFDataRangeTransport.requestDataRange');
  1806. }
  1807. };
  1808. return PDFDataRangeTransport;
  1809. })();
  1810. PDFJS.PDFDataRangeTransport = PDFDataRangeTransport;
  1811. /**
  1812. * Proxy to a PDFDocument in the worker thread. Also, contains commonly used
  1813. * properties that can be read synchronously.
  1814. * @class
  1815. */
  1816. var PDFDocumentProxy = (function PDFDocumentProxyClosure() {
  1817. function PDFDocumentProxy(pdfInfo, transport) {
  1818. this.pdfInfo = pdfInfo;
  1819. this.transport = transport;
  1820. }
  1821. PDFDocumentProxy.prototype = /** @lends PDFDocumentProxy.prototype */ {
  1822. /**
  1823. * @return {number} Total number of pages the PDF contains.
  1824. */
  1825. get numPages() {
  1826. return this.pdfInfo.numPages;
  1827. },
  1828. /**
  1829. * @return {string} A unique ID to identify a PDF. Not guaranteed to be
  1830. * unique.
  1831. */
  1832. get fingerprint() {
  1833. return this.pdfInfo.fingerprint;
  1834. },
  1835. /**
  1836. * @param {number} pageNumber The page number to get. The first page is 1.
  1837. * @return {Promise} A promise that is resolved with a {@link PDFPageProxy}
  1838. * object.
  1839. */
  1840. getPage: function PDFDocumentProxy_getPage(pageNumber) {
  1841. return this.transport.getPage(pageNumber);
  1842. },
  1843. /**
  1844. * @param {{num: number, gen: number}} ref The page reference. Must have
  1845. * the 'num' and 'gen' properties.
  1846. * @return {Promise} A promise that is resolved with the page index that is
  1847. * associated with the reference.
  1848. */
  1849. getPageIndex: function PDFDocumentProxy_getPageIndex(ref) {
  1850. return this.transport.getPageIndex(ref);
  1851. },
  1852. /**
  1853. * @return {Promise} A promise that is resolved with a lookup table for
  1854. * mapping named destinations to reference numbers.
  1855. *
  1856. * This can be slow for large documents: use getDestination instead
  1857. */
  1858. getDestinations: function PDFDocumentProxy_getDestinations() {
  1859. return this.transport.getDestinations();
  1860. },
  1861. /**
  1862. * @param {string} id The named destination to get.
  1863. * @return {Promise} A promise that is resolved with all information
  1864. * of the given named destination.
  1865. */
  1866. getDestination: function PDFDocumentProxy_getDestination(id) {
  1867. return this.transport.getDestination(id);
  1868. },
  1869. /**
  1870. * @return {Promise} A promise that is resolved with a lookup table for
  1871. * mapping named attachments to their content.
  1872. */
  1873. getAttachments: function PDFDocumentProxy_getAttachments() {
  1874. return this.transport.getAttachments();
  1875. },
  1876. /**
  1877. * @return {Promise} A promise that is resolved with an array of all the
  1878. * JavaScript strings in the name tree.
  1879. */
  1880. getJavaScript: function PDFDocumentProxy_getJavaScript() {
  1881. return this.transport.getJavaScript();
  1882. },
  1883. /**
  1884. * @return {Promise} A promise that is resolved with an {Array} that is a
  1885. * tree outline (if it has one) of the PDF. The tree is in the format of:
  1886. * [
  1887. * {
  1888. * title: string,
  1889. * bold: boolean,
  1890. * italic: boolean,
  1891. * color: rgb array,
  1892. * dest: dest obj,
  1893. * items: array of more items like this
  1894. * },
  1895. * ...
  1896. * ].
  1897. */
  1898. getOutline: function PDFDocumentProxy_getOutline() {
  1899. return this.transport.getOutline();
  1900. },
  1901. /**
  1902. * @return {Promise} A promise that is resolved with an {Object} that has
  1903. * info and metadata properties. Info is an {Object} filled with anything
  1904. * available in the information dictionary and similarly metadata is a
  1905. * {Metadata} object with information from the metadata section of the PDF.
  1906. */
  1907. getMetadata: function PDFDocumentProxy_getMetadata() {
  1908. return this.transport.getMetadata();
  1909. },
  1910. /**
  1911. * @return {Promise} A promise that is resolved with a TypedArray that has
  1912. * the raw data from the PDF.
  1913. */
  1914. getData: function PDFDocumentProxy_getData() {
  1915. return this.transport.getData();
  1916. },
  1917. /**
  1918. * @return {Promise} A promise that is resolved when the document's data
  1919. * is loaded. It is resolved with an {Object} that contains the length
  1920. * property that indicates size of the PDF data in bytes.
  1921. */
  1922. getDownloadInfo: function PDFDocumentProxy_getDownloadInfo() {
  1923. return this.transport.downloadInfoCapability.promise;
  1924. },
  1925. /**
  1926. * @return {Promise} A promise this is resolved with current stats about
  1927. * document structures (see {@link PDFDocumentStats}).
  1928. */
  1929. getStats: function PDFDocumentProxy_getStats() {
  1930. return this.transport.getStats();
  1931. },
  1932. /**
  1933. * Cleans up resources allocated by the document, e.g. created @font-face.
  1934. */
  1935. cleanup: function PDFDocumentProxy_cleanup() {
  1936. this.transport.startCleanup();
  1937. },
  1938. /**
  1939. * Destroys current document instance and terminates worker.
  1940. */
  1941. destroy: function PDFDocumentProxy_destroy() {
  1942. this.transport.destroy();
  1943. }
  1944. };
  1945. return PDFDocumentProxy;
  1946. })();
  1947. /**
  1948. * Page text content.
  1949. *
  1950. * @typedef {Object} TextContent
  1951. * @property {array} items - array of {@link TextItem}
  1952. * @property {Object} styles - {@link TextStyles} objects, indexed by font
  1953. * name.
  1954. */
  1955. /**
  1956. * Page text content part.
  1957. *
  1958. * @typedef {Object} TextItem
  1959. * @property {string} str - text content.
  1960. * @property {string} dir - text direction: 'ttb', 'ltr' or 'rtl'.
  1961. * @property {array} transform - transformation matrix.
  1962. * @property {number} width - width in device space.
  1963. * @property {number} height - height in device space.
  1964. * @property {string} fontName - font name used by pdf.js for converted font.
  1965. */
  1966. /**
  1967. * Text style.
  1968. *
  1969. * @typedef {Object} TextStyle
  1970. * @property {number} ascent - font ascent.
  1971. * @property {number} descent - font descent.
  1972. * @property {boolean} vertical - text is in vertical mode.
  1973. * @property {string} fontFamily - possible font family
  1974. */
  1975. /**
  1976. * Page render parameters.
  1977. *
  1978. * @typedef {Object} RenderParameters
  1979. * @property {Object} canvasContext - A 2D context of a DOM Canvas object.
  1980. * @property {PDFJS.PageViewport} viewport - Rendering viewport obtained by
  1981. * calling of PDFPage.getViewport method.
  1982. * @property {string} intent - Rendering intent, can be 'display' or 'print'
  1983. * (default value is 'display').
  1984. * @property {Object} imageLayer - (optional) An object that has beginLayout,
  1985. * endLayout and appendImage functions.
  1986. * @property {function} continueCallback - (deprecated) A function that will be
  1987. * called each time the rendering is paused. To continue
  1988. * rendering call the function that is the first argument
  1989. * to the callback.
  1990. */
  1991. /**
  1992. * PDF page operator list.
  1993. *
  1994. * @typedef {Object} PDFOperatorList
  1995. * @property {Array} fnArray - Array containing the operator functions.
  1996. * @property {Array} argsArray - Array containing the arguments of the
  1997. * functions.
  1998. */
  1999. /**
  2000. * Proxy to a PDFPage in the worker thread.
  2001. * @class
  2002. */
  2003. var PDFPageProxy = (function PDFPageProxyClosure() {
  2004. function PDFPageProxy(pageIndex, pageInfo, transport) {
  2005. this.pageIndex = pageIndex;
  2006. this.pageInfo = pageInfo;
  2007. this.transport = transport;
  2008. this.stats = new StatTimer();
  2009. this.stats.enabled = !!globalScope.PDFJS.enableStats;
  2010. this.commonObjs = transport.commonObjs;
  2011. this.objs = new PDFObjects();
  2012. this.cleanupAfterRender = false;
  2013. this.pendingDestroy = false;
  2014. this.intentStates = {};
  2015. }
  2016. PDFPageProxy.prototype = /** @lends PDFPageProxy.prototype */ {
  2017. /**
  2018. * @return {number} Page number of the page. First page is 1.
  2019. */
  2020. get pageNumber() {
  2021. return this.pageIndex + 1;
  2022. },
  2023. /**
  2024. * @return {number} The number of degrees the page is rotated clockwise.
  2025. */
  2026. get rotate() {
  2027. return this.pageInfo.rotate;
  2028. },
  2029. /**
  2030. * @return {Object} The reference that points to this page. It has 'num' and
  2031. * 'gen' properties.
  2032. */
  2033. get ref() {
  2034. return this.pageInfo.ref;
  2035. },
  2036. /**
  2037. * @return {Array} An array of the visible portion of the PDF page in the
  2038. * user space units - [x1, y1, x2, y2].
  2039. */
  2040. get view() {
  2041. return this.pageInfo.view;
  2042. },
  2043. /**
  2044. * @param {number} scale The desired scale of the viewport.
  2045. * @param {number} rotate Degrees to rotate the viewport. If omitted this
  2046. * defaults to the page rotation.
  2047. * @return {PDFJS.PageViewport} Contains 'width' and 'height' properties
  2048. * along with transforms required for rendering.
  2049. */
  2050. getViewport: function PDFPageProxy_getViewport(scale, rotate) {
  2051. if (arguments.length < 2) {
  2052. rotate = this.rotate;
  2053. }
  2054. return new PDFJS.PageViewport(this.view, scale, rotate, 0, 0);
  2055. },
  2056. /**
  2057. * @return {Promise} A promise that is resolved with an {Array} of the
  2058. * annotation objects.
  2059. */
  2060. getAnnotations: function PDFPageProxy_getAnnotations() {
  2061. if (this.annotationsPromise) {
  2062. return this.annotationsPromise;
  2063. }
  2064. var promise = this.transport.getAnnotations(this.pageIndex);
  2065. this.annotationsPromise = promise;
  2066. return promise;
  2067. },
  2068. /**
  2069. * Begins the process of rendering a page to the desired context.
  2070. * @param {RenderParameters} params Page render parameters.
  2071. * @return {RenderTask} An object that contains the promise, which
  2072. * is resolved when the page finishes rendering.
  2073. */
  2074. render: function PDFPageProxy_render(params) {
  2075. var stats = this.stats;
  2076. stats.time('Overall');
  2077. // If there was a pending destroy cancel it so no cleanup happens during
  2078. // this call to render.
  2079. this.pendingDestroy = false;
  2080. var renderingIntent = (params.intent === 'print' ? 'print' : 'display');
  2081. if (!this.intentStates[renderingIntent]) {
  2082. this.intentStates[renderingIntent] = {};
  2083. }
  2084. var intentState = this.intentStates[renderingIntent];
  2085. // If there's no displayReadyCapability yet, then the operatorList
  2086. // was never requested before. Make the request and create the promise.
  2087. if (!intentState.displayReadyCapability) {
  2088. intentState.receivingOperatorList = true;
  2089. intentState.displayReadyCapability = createPromiseCapability();
  2090. intentState.operatorList = {
  2091. fnArray: [],
  2092. argsArray: [],
  2093. lastChunk: false
  2094. };
  2095. this.stats.time('Page Request');
  2096. this.transport.messageHandler.send('RenderPageRequest', {
  2097. pageIndex: this.pageNumber - 1,
  2098. intent: renderingIntent
  2099. });
  2100. }
  2101. var internalRenderTask = new InternalRenderTask(complete, params,
  2102. this.objs,
  2103. this.commonObjs,
  2104. intentState.operatorList,
  2105. this.pageNumber);
  2106. if (!intentState.renderTasks) {
  2107. intentState.renderTasks = [];
  2108. }
  2109. intentState.renderTasks.push(internalRenderTask);
  2110. var renderTask = internalRenderTask.task;
  2111. // Obsolete parameter support
  2112. if (params.continueCallback) {
  2113. renderTask.onContinue = params.continueCallback;
  2114. }
  2115. var self = this;
  2116. intentState.displayReadyCapability.promise.then(
  2117. function pageDisplayReadyPromise(transparency) {
  2118. if (self.pendingDestroy) {
  2119. complete();
  2120. return;
  2121. }
  2122. stats.time('Rendering');
  2123. internalRenderTask.initalizeGraphics(transparency);
  2124. internalRenderTask.operatorListChanged();
  2125. },
  2126. function pageDisplayReadPromiseError(reason) {
  2127. complete(reason);
  2128. }
  2129. );
  2130. function complete(error) {
  2131. var i = intentState.renderTasks.indexOf(internalRenderTask);
  2132. if (i >= 0) {
  2133. intentState.renderTasks.splice(i, 1);
  2134. }
  2135. if (self.cleanupAfterRender) {
  2136. self.pendingDestroy = true;
  2137. }
  2138. self._tryDestroy();
  2139. if (error) {
  2140. internalRenderTask.capability.reject(error);
  2141. } else {
  2142. internalRenderTask.capability.resolve();
  2143. }
  2144. stats.timeEnd('Rendering');
  2145. stats.timeEnd('Overall');
  2146. }
  2147. return renderTask;
  2148. },
  2149. /**
  2150. * @return {Promise} A promise resolved with an {@link PDFOperatorList}
  2151. * object that represents page's operator list.
  2152. */
  2153. getOperatorList: function PDFPageProxy_getOperatorList() {
  2154. function operatorListChanged() {
  2155. if (intentState.operatorList.lastChunk) {
  2156. intentState.opListReadCapability.resolve(intentState.operatorList);
  2157. }
  2158. }
  2159. var renderingIntent = 'oplist';
  2160. if (!this.intentStates[renderingIntent]) {
  2161. this.intentStates[renderingIntent] = {};
  2162. }
  2163. var intentState = this.intentStates[renderingIntent];
  2164. if (!intentState.opListReadCapability) {
  2165. var opListTask = {};
  2166. opListTask.operatorListChanged = operatorListChanged;
  2167. intentState.receivingOperatorList = true;
  2168. intentState.opListReadCapability = createPromiseCapability();
  2169. intentState.renderTasks = [];
  2170. intentState.renderTasks.push(opListTask);
  2171. intentState.operatorList = {
  2172. fnArray: [],
  2173. argsArray: [],
  2174. lastChunk: false
  2175. };
  2176. this.transport.messageHandler.send('RenderPageRequest', {
  2177. pageIndex: this.pageIndex,
  2178. intent: renderingIntent
  2179. });
  2180. }
  2181. return intentState.opListReadCapability.promise;
  2182. },
  2183. /**
  2184. * @return {Promise} That is resolved a {@link TextContent}
  2185. * object that represent the page text content.
  2186. */
  2187. getTextContent: function PDFPageProxy_getTextContent() {
  2188. return this.transport.messageHandler.sendWithPromise('GetTextContent', {
  2189. pageIndex: this.pageNumber - 1
  2190. });
  2191. },
  2192. /**
  2193. * Destroys resources allocated by the page.
  2194. */
  2195. destroy: function PDFPageProxy_destroy() {
  2196. this.pendingDestroy = true;
  2197. this._tryDestroy();
  2198. },
  2199. /**
  2200. * For internal use only. Attempts to clean up if rendering is in a state
  2201. * where that's possible.
  2202. * @ignore
  2203. */
  2204. _tryDestroy: function PDFPageProxy__destroy() {
  2205. if (!this.pendingDestroy ||
  2206. Object.keys(this.intentStates).some(function(intent) {
  2207. var intentState = this.intentStates[intent];
  2208. return (intentState.renderTasks.length !== 0 ||
  2209. intentState.receivingOperatorList);
  2210. }, this)) {
  2211. return;
  2212. }
  2213. Object.keys(this.intentStates).forEach(function(intent) {
  2214. delete this.intentStates[intent];
  2215. }, this);
  2216. this.objs.clear();
  2217. this.annotationsPromise = null;
  2218. this.pendingDestroy = false;
  2219. },
  2220. /**
  2221. * For internal use only.
  2222. * @ignore
  2223. */
  2224. _startRenderPage: function PDFPageProxy_startRenderPage(transparency,
  2225. intent) {
  2226. var intentState = this.intentStates[intent];
  2227. // TODO Refactor RenderPageRequest to separate rendering
  2228. // and operator list logic
  2229. if (intentState.displayReadyCapability) {
  2230. intentState.displayReadyCapability.resolve(transparency);
  2231. }
  2232. },
  2233. /**
  2234. * For internal use only.
  2235. * @ignore
  2236. */
  2237. _renderPageChunk: function PDFPageProxy_renderPageChunk(operatorListChunk,
  2238. intent) {
  2239. var intentState = this.intentStates[intent];
  2240. var i, ii;
  2241. // Add the new chunk to the current operator list.
  2242. for (i = 0, ii = operatorListChunk.length; i < ii; i++) {
  2243. intentState.operatorList.fnArray.push(operatorListChunk.fnArray[i]);
  2244. intentState.operatorList.argsArray.push(
  2245. operatorListChunk.argsArray[i]);
  2246. }
  2247. intentState.operatorList.lastChunk = operatorListChunk.lastChunk;
  2248. // Notify all the rendering tasks there are more operators to be consumed.
  2249. for (i = 0; i < intentState.renderTasks.length; i++) {
  2250. intentState.renderTasks[i].operatorListChanged();
  2251. }
  2252. if (operatorListChunk.lastChunk) {
  2253. intentState.receivingOperatorList = false;
  2254. this._tryDestroy();
  2255. }
  2256. }
  2257. };
  2258. return PDFPageProxy;
  2259. })();
  2260. /**
  2261. * For internal use only.
  2262. * @ignore
  2263. */
  2264. var WorkerTransport = (function WorkerTransportClosure() {
  2265. function WorkerTransport(workerInitializedCapability, pdfDataRangeTransport) {
  2266. this.pdfDataRangeTransport = pdfDataRangeTransport;
  2267. this.workerInitializedCapability = workerInitializedCapability;
  2268. this.commonObjs = new PDFObjects();
  2269. this.loadingTask = null;
  2270. this.pageCache = [];
  2271. this.pagePromises = [];
  2272. this.downloadInfoCapability = createPromiseCapability();
  2273. // If worker support isn't disabled explicit and the browser has worker
  2274. // support, create a new web worker and test if it/the browser fullfills
  2275. // all requirements to run parts of pdf.js in a web worker.
  2276. // Right now, the requirement is, that an Uint8Array is still an Uint8Array
  2277. // as it arrives on the worker. Chrome added this with version 15.
  2278. // Either workers are disabled, not supported or have thrown an exception.
  2279. // Thus, we fallback to a faked worker.
  2280. this.setupFakeWorker();
  2281. }
  2282. WorkerTransport.prototype = {
  2283. destroy: function WorkerTransport_destroy() {
  2284. this.pageCache = [];
  2285. this.pagePromises = [];
  2286. var self = this;
  2287. this.messageHandler.sendWithPromise('Terminate', null).then(function () {
  2288. FontLoader.clear();
  2289. if (self.worker) {
  2290. self.worker.terminate();
  2291. }
  2292. });
  2293. },
  2294. setupFakeWorker: function WorkerTransport_setupFakeWorker() {
  2295. globalScope.PDFJS.disableWorker = true;
  2296. if (!PDFJS.fakeWorkerFilesLoadedCapability) {
  2297. PDFJS.fakeWorkerFilesLoadedCapability = createPromiseCapability();
  2298. // In the developer build load worker_loader which in turn loads all the
  2299. // other files and resolves the promise. In production only the
  2300. // pdf.worker.js file is needed.
  2301. PDFJS.fakeWorkerFilesLoadedCapability.resolve();
  2302. }
  2303. PDFJS.fakeWorkerFilesLoadedCapability.promise.then(function () {
  2304. warn('Setting up fake worker.');
  2305. // If we don't use a worker, just post/sendMessage to the main thread.
  2306. var fakeWorker = {
  2307. postMessage: function WorkerTransport_postMessage(obj) {
  2308. fakeWorker.onmessage({data: obj});
  2309. },
  2310. terminate: function WorkerTransport_terminate() {}
  2311. };
  2312. var messageHandler = new MessageHandler('main', fakeWorker);
  2313. this.setupMessageHandler(messageHandler);
  2314. // If the main thread is our worker, setup the handling for the messages
  2315. // the main thread sends to it self.
  2316. PDFJS.WorkerMessageHandler.setup(messageHandler);
  2317. this.workerInitializedCapability.resolve();
  2318. }.bind(this));
  2319. },
  2320. setupMessageHandler:
  2321. function WorkerTransport_setupMessageHandler(messageHandler) {
  2322. this.messageHandler = messageHandler;
  2323. function updatePassword(password) {
  2324. messageHandler.send('UpdatePassword', password);
  2325. }
  2326. var pdfDataRangeTransport = this.pdfDataRangeTransport;
  2327. if (pdfDataRangeTransport) {
  2328. pdfDataRangeTransport.addRangeListener(function(begin, chunk) {
  2329. messageHandler.send('OnDataRange', {
  2330. begin: begin,
  2331. chunk: chunk
  2332. });
  2333. });
  2334. pdfDataRangeTransport.addProgressListener(function(loaded) {
  2335. messageHandler.send('OnDataProgress', {
  2336. loaded: loaded
  2337. });
  2338. });
  2339. pdfDataRangeTransport.addProgressiveReadListener(function(chunk) {
  2340. messageHandler.send('OnDataRange', {
  2341. chunk: chunk
  2342. });
  2343. });
  2344. messageHandler.on('RequestDataRange',
  2345. function transportDataRange(data) {
  2346. pdfDataRangeTransport.requestDataRange(data.begin, data.end);
  2347. }, this);
  2348. }
  2349. messageHandler.on('GetDoc', function transportDoc(data) {
  2350. var pdfInfo = data.pdfInfo;
  2351. this.numPages = data.pdfInfo.numPages;
  2352. var pdfDocument = new PDFDocumentProxy(pdfInfo, this);
  2353. this.pdfDocument = pdfDocument;
  2354. this.loadingTask._capability.resolve(pdfDocument);
  2355. }, this);
  2356. messageHandler.on('NeedPassword',
  2357. function transportNeedPassword(exception) {
  2358. var loadingTask = this.loadingTask;
  2359. if (loadingTask.onPassword) {
  2360. return loadingTask.onPassword(updatePassword,
  2361. PasswordResponses.NEED_PASSWORD);
  2362. }
  2363. loadingTask._capability.reject(
  2364. new PasswordException(exception.message, exception.code));
  2365. }, this);
  2366. messageHandler.on('IncorrectPassword',
  2367. function transportIncorrectPassword(exception) {
  2368. var loadingTask = this.loadingTask;
  2369. if (loadingTask.onPassword) {
  2370. return loadingTask.onPassword(updatePassword,
  2371. PasswordResponses.INCORRECT_PASSWORD);
  2372. }
  2373. loadingTask._capability.reject(
  2374. new PasswordException(exception.message, exception.code));
  2375. }, this);
  2376. messageHandler.on('InvalidPDF', function transportInvalidPDF(exception) {
  2377. this.loadingTask._capability.reject(
  2378. new InvalidPDFException(exception.message));
  2379. }, this);
  2380. messageHandler.on('MissingPDF', function transportMissingPDF(exception) {
  2381. this.loadingTask._capability.reject(
  2382. new MissingPDFException(exception.message));
  2383. }, this);
  2384. messageHandler.on('UnexpectedResponse',
  2385. function transportUnexpectedResponse(exception) {
  2386. this.loadingTask._capability.reject(
  2387. new UnexpectedResponseException(exception.message, exception.status));
  2388. }, this);
  2389. messageHandler.on('UnknownError',
  2390. function transportUnknownError(exception) {
  2391. this.loadingTask._capability.reject(
  2392. new UnknownErrorException(exception.message, exception.details));
  2393. }, this);
  2394. messageHandler.on('DataLoaded', function transportPage(data) {
  2395. this.downloadInfoCapability.resolve(data);
  2396. }, this);
  2397. messageHandler.on('PDFManagerReady', function transportPage(data) {
  2398. if (this.pdfDataRangeTransport) {
  2399. this.pdfDataRangeTransport.transportReady();
  2400. }
  2401. }, this);
  2402. messageHandler.on('StartRenderPage', function transportRender(data) {
  2403. var page = this.pageCache[data.pageIndex];
  2404. page.stats.timeEnd('Page Request');
  2405. page._startRenderPage(data.transparency, data.intent);
  2406. }, this);
  2407. messageHandler.on('RenderPageChunk', function transportRender(data) {
  2408. var page = this.pageCache[data.pageIndex];
  2409. page._renderPageChunk(data.operatorList, data.intent);
  2410. }, this);
  2411. messageHandler.on('commonobj', function transportObj(data) {
  2412. var id = data[0];
  2413. var type = data[1];
  2414. if (this.commonObjs.hasData(id)) {
  2415. return;
  2416. }
  2417. switch (type) {
  2418. case 'Font':
  2419. var exportedData = data[2];
  2420. var font;
  2421. if ('error' in exportedData) {
  2422. var error = exportedData.error;
  2423. warn('Error during font loading: ' + error);
  2424. this.commonObjs.resolve(id, error);
  2425. break;
  2426. } else {
  2427. font = new FontFaceObject(exportedData);
  2428. }
  2429. FontLoader.bind(
  2430. [font],
  2431. function fontReady(fontObjs) {
  2432. this.commonObjs.resolve(id, font);
  2433. }.bind(this)
  2434. );
  2435. break;
  2436. case 'FontPath':
  2437. this.commonObjs.resolve(id, data[2]);
  2438. break;
  2439. default:
  2440. error('Got unknown common object type ' + type);
  2441. }
  2442. }, this);
  2443. messageHandler.on('obj', function transportObj(data) {
  2444. var id = data[0];
  2445. var pageIndex = data[1];
  2446. var type = data[2];
  2447. var pageProxy = this.pageCache[pageIndex];
  2448. var imageData;
  2449. if (pageProxy.objs.hasData(id)) {
  2450. return;
  2451. }
  2452. switch (type) {
  2453. case 'JpegStream':
  2454. imageData = data[3];
  2455. loadJpegStream(id, imageData, pageProxy.objs);
  2456. break;
  2457. case 'Image':
  2458. imageData = data[3];
  2459. pageProxy.objs.resolve(id, imageData);
  2460. // heuristics that will allow not to store large data
  2461. var MAX_IMAGE_SIZE_TO_STORE = 8000000;
  2462. if (imageData && 'data' in imageData &&
  2463. imageData.data.length > MAX_IMAGE_SIZE_TO_STORE) {
  2464. pageProxy.cleanupAfterRender = true;
  2465. }
  2466. break;
  2467. default:
  2468. error('Got unknown object type ' + type);
  2469. }
  2470. }, this);
  2471. messageHandler.on('DocProgress', function transportDocProgress(data) {
  2472. var loadingTask = this.loadingTask;
  2473. if (loadingTask.onProgress) {
  2474. loadingTask.onProgress({
  2475. loaded: data.loaded,
  2476. total: data.total
  2477. });
  2478. }
  2479. }, this);
  2480. messageHandler.on('PageError', function transportError(data) {
  2481. var page = this.pageCache[data.pageNum - 1];
  2482. var intentState = page.intentStates[data.intent];
  2483. if (intentState.displayReadyCapability) {
  2484. intentState.displayReadyCapability.reject(data.error);
  2485. } else {
  2486. error(data.error);
  2487. }
  2488. }, this);
  2489. messageHandler.on('JpegDecode', function(data) {
  2490. var imageUrl = data[0];
  2491. var components = data[1];
  2492. if (components !== 3 && components !== 1) {
  2493. return Promise.reject(
  2494. new Error('Only 3 components or 1 component can be returned'));
  2495. }
  2496. return new Promise(function (resolve, reject) {
  2497. var img = new Image();
  2498. img.onload = function () {
  2499. var width = img.width;
  2500. var height = img.height;
  2501. var size = width * height;
  2502. var rgbaLength = size * 4;
  2503. var buf = new Uint8Array(size * components);
  2504. var tmpCanvas = createScratchCanvas(width, height);
  2505. var tmpCtx = tmpCanvas.getContext('2d');
  2506. tmpCtx.drawImage(img, 0, 0);
  2507. var data = tmpCtx.getImageData(0, 0, width, height).data;
  2508. var i, j;
  2509. if (components === 3) {
  2510. for (i = 0, j = 0; i < rgbaLength; i += 4, j += 3) {
  2511. buf[j] = data[i];
  2512. buf[j + 1] = data[i + 1];
  2513. buf[j + 2] = data[i + 2];
  2514. }
  2515. } else if (components === 1) {
  2516. for (i = 0, j = 0; i < rgbaLength; i += 4, j++) {
  2517. buf[j] = data[i];
  2518. }
  2519. }
  2520. resolve({ data: buf, width: width, height: height});
  2521. };
  2522. img.onerror = function () {
  2523. reject(new Error('JpegDecode failed to load image'));
  2524. };
  2525. img.src = imageUrl;
  2526. });
  2527. });
  2528. },
  2529. fetchDocument: function WorkerTransport_fetchDocument(loadingTask, source) {
  2530. this.loadingTask = loadingTask;
  2531. source.disableAutoFetch = PDFJS.disableAutoFetch;
  2532. source.disableStream = PDFJS.disableStream;
  2533. source.chunkedViewerLoading = !!this.pdfDataRangeTransport;
  2534. if (this.pdfDataRangeTransport) {
  2535. source.length = this.pdfDataRangeTransport.length;
  2536. source.initialData = this.pdfDataRangeTransport.initialData;
  2537. }
  2538. this.messageHandler.send('GetDocRequest', {
  2539. source: source,
  2540. disableRange: PDFJS.disableRange,
  2541. maxImageSize: PDFJS.maxImageSize,
  2542. cMapUrl: PDFJS.cMapUrl,
  2543. cMapPacked: PDFJS.cMapPacked,
  2544. disableFontFace: PDFJS.disableFontFace,
  2545. disableCreateObjectURL: PDFJS.disableCreateObjectURL,
  2546. verbosity: PDFJS.verbosity
  2547. });
  2548. },
  2549. getData: function WorkerTransport_getData() {
  2550. return this.messageHandler.sendWithPromise('GetData', null);
  2551. },
  2552. getPage: function WorkerTransport_getPage(pageNumber, capability) {
  2553. if (pageNumber <= 0 || pageNumber > this.numPages ||
  2554. (pageNumber|0) !== pageNumber) {
  2555. return Promise.reject(new Error('Invalid page request'));
  2556. }
  2557. var pageIndex = pageNumber - 1;
  2558. if (pageIndex in this.pagePromises) {
  2559. return this.pagePromises[pageIndex];
  2560. }
  2561. var promise = this.messageHandler.sendWithPromise('GetPage', {
  2562. pageIndex: pageIndex
  2563. }).then(function (pageInfo) {
  2564. var page = new PDFPageProxy(pageIndex, pageInfo, this);
  2565. this.pageCache[pageIndex] = page;
  2566. return page;
  2567. }.bind(this));
  2568. this.pagePromises[pageIndex] = promise;
  2569. return promise;
  2570. },
  2571. getPageIndex: function WorkerTransport_getPageIndexByRef(ref) {
  2572. return this.messageHandler.sendWithPromise('GetPageIndex', { ref: ref });
  2573. },
  2574. getAnnotations: function WorkerTransport_getAnnotations(pageIndex) {
  2575. return this.messageHandler.sendWithPromise('GetAnnotations',
  2576. { pageIndex: pageIndex });
  2577. },
  2578. getDestinations: function WorkerTransport_getDestinations() {
  2579. return this.messageHandler.sendWithPromise('GetDestinations', null);
  2580. },
  2581. getDestination: function WorkerTransport_getDestination(id) {
  2582. return this.messageHandler.sendWithPromise('GetDestination', { id: id } );
  2583. },
  2584. getAttachments: function WorkerTransport_getAttachments() {
  2585. return this.messageHandler.sendWithPromise('GetAttachments', null);
  2586. },
  2587. getJavaScript: function WorkerTransport_getJavaScript() {
  2588. return this.messageHandler.sendWithPromise('GetJavaScript', null);
  2589. },
  2590. getOutline: function WorkerTransport_getOutline() {
  2591. return this.messageHandler.sendWithPromise('GetOutline', null);
  2592. },
  2593. getMetadata: function WorkerTransport_getMetadata() {
  2594. return this.messageHandler.sendWithPromise('GetMetadata', null).
  2595. then(function transportMetadata(results) {
  2596. return {
  2597. info: results[0],
  2598. metadata: (results[1] ? new PDFJS.Metadata(results[1]) : null)
  2599. };
  2600. });
  2601. },
  2602. getStats: function WorkerTransport_getStats() {
  2603. return this.messageHandler.sendWithPromise('GetStats', null);
  2604. },
  2605. startCleanup: function WorkerTransport_startCleanup() {
  2606. this.messageHandler.sendWithPromise('Cleanup', null).
  2607. then(function endCleanup() {
  2608. for (var i = 0, ii = this.pageCache.length; i < ii; i++) {
  2609. var page = this.pageCache[i];
  2610. if (page) {
  2611. page.destroy();
  2612. }
  2613. }
  2614. this.commonObjs.clear();
  2615. FontLoader.clear();
  2616. }.bind(this));
  2617. }
  2618. };
  2619. return WorkerTransport;
  2620. })();
  2621. /**
  2622. * A PDF document and page is built of many objects. E.g. there are objects
  2623. * for fonts, images, rendering code and such. These objects might get processed
  2624. * inside of a worker. The `PDFObjects` implements some basic functions to
  2625. * manage these objects.
  2626. * @ignore
  2627. */
  2628. var PDFObjects = (function PDFObjectsClosure() {
  2629. function PDFObjects() {
  2630. this.objs = {};
  2631. }
  2632. PDFObjects.prototype = {
  2633. /**
  2634. * Internal function.
  2635. * Ensures there is an object defined for `objId`.
  2636. */
  2637. ensureObj: function PDFObjects_ensureObj(objId) {
  2638. if (this.objs[objId]) {
  2639. return this.objs[objId];
  2640. }
  2641. var obj = {
  2642. capability: createPromiseCapability(),
  2643. data: null,
  2644. resolved: false
  2645. };
  2646. this.objs[objId] = obj;
  2647. return obj;
  2648. },
  2649. /**
  2650. * If called *without* callback, this returns the data of `objId` but the
  2651. * object needs to be resolved. If it isn't, this function throws.
  2652. *
  2653. * If called *with* a callback, the callback is called with the data of the
  2654. * object once the object is resolved. That means, if you call this
  2655. * function and the object is already resolved, the callback gets called
  2656. * right away.
  2657. */
  2658. get: function PDFObjects_get(objId, callback) {
  2659. // If there is a callback, then the get can be async and the object is
  2660. // not required to be resolved right now
  2661. if (callback) {
  2662. this.ensureObj(objId).capability.promise.then(callback);
  2663. return null;
  2664. }
  2665. // If there isn't a callback, the user expects to get the resolved data
  2666. // directly.
  2667. var obj = this.objs[objId];
  2668. // If there isn't an object yet or the object isn't resolved, then the
  2669. // data isn't ready yet!
  2670. if (!obj || !obj.resolved) {
  2671. error('Requesting object that isn\'t resolved yet ' + objId);
  2672. }
  2673. return obj.data;
  2674. },
  2675. /**
  2676. * Resolves the object `objId` with optional `data`.
  2677. */
  2678. resolve: function PDFObjects_resolve(objId, data) {
  2679. var obj = this.ensureObj(objId);
  2680. obj.resolved = true;
  2681. obj.data = data;
  2682. obj.capability.resolve(data);
  2683. },
  2684. isResolved: function PDFObjects_isResolved(objId) {
  2685. var objs = this.objs;
  2686. if (!objs[objId]) {
  2687. return false;
  2688. } else {
  2689. return objs[objId].resolved;
  2690. }
  2691. },
  2692. hasData: function PDFObjects_hasData(objId) {
  2693. return this.isResolved(objId);
  2694. },
  2695. /**
  2696. * Returns the data of `objId` if object exists, null otherwise.
  2697. */
  2698. getData: function PDFObjects_getData(objId) {
  2699. var objs = this.objs;
  2700. if (!objs[objId] || !objs[objId].resolved) {
  2701. return null;
  2702. } else {
  2703. return objs[objId].data;
  2704. }
  2705. },
  2706. clear: function PDFObjects_clear() {
  2707. this.objs = {};
  2708. }
  2709. };
  2710. return PDFObjects;
  2711. })();
  2712. /**
  2713. * Allows controlling of the rendering tasks.
  2714. * @class
  2715. */
  2716. var RenderTask = (function RenderTaskClosure() {
  2717. function RenderTask(internalRenderTask) {
  2718. this._internalRenderTask = internalRenderTask;
  2719. /**
  2720. * Callback for incremental rendering -- a function that will be called
  2721. * each time the rendering is paused. To continue rendering call the
  2722. * function that is the first argument to the callback.
  2723. * @type {function}
  2724. */
  2725. this.onContinue = null;
  2726. }
  2727. RenderTask.prototype = /** @lends RenderTask.prototype */ {
  2728. /**
  2729. * Promise for rendering task completion.
  2730. * @return {Promise}
  2731. */
  2732. get promise() {
  2733. return this._internalRenderTask.capability.promise;
  2734. },
  2735. /**
  2736. * Cancels the rendering task. If the task is currently rendering it will
  2737. * not be cancelled until graphics pauses with a timeout. The promise that
  2738. * this object extends will resolved when cancelled.
  2739. */
  2740. cancel: function RenderTask_cancel() {
  2741. this._internalRenderTask.cancel();
  2742. },
  2743. /**
  2744. * Registers callbacks to indicate the rendering task completion.
  2745. *
  2746. * @param {function} onFulfilled The callback for the rendering completion.
  2747. * @param {function} onRejected The callback for the rendering failure.
  2748. * @return {Promise} A promise that is resolved after the onFulfilled or
  2749. * onRejected callback.
  2750. */
  2751. then: function RenderTask_then(onFulfilled, onRejected) {
  2752. return this.promise.then.apply(this.promise, arguments);
  2753. }
  2754. };
  2755. return RenderTask;
  2756. })();
  2757. /**
  2758. * For internal use only.
  2759. * @ignore
  2760. */
  2761. var InternalRenderTask = (function InternalRenderTaskClosure() {
  2762. function InternalRenderTask(callback, params, objs, commonObjs, operatorList,
  2763. pageNumber) {
  2764. this.callback = callback;
  2765. this.params = params;
  2766. this.objs = objs;
  2767. this.commonObjs = commonObjs;
  2768. this.operatorListIdx = null;
  2769. this.operatorList = operatorList;
  2770. this.pageNumber = pageNumber;
  2771. this.running = false;
  2772. this.graphicsReadyCallback = null;
  2773. this.graphicsReady = false;
  2774. this.cancelled = false;
  2775. this.capability = createPromiseCapability();
  2776. this.task = new RenderTask(this);
  2777. // caching this-bound methods
  2778. this._continueBound = this._continue.bind(this);
  2779. this._scheduleNextBound = this._scheduleNext.bind(this);
  2780. this._nextBound = this._next.bind(this);
  2781. }
  2782. InternalRenderTask.prototype = {
  2783. initalizeGraphics:
  2784. function InternalRenderTask_initalizeGraphics(transparency) {
  2785. if (this.cancelled) {
  2786. return;
  2787. }
  2788. if (PDFJS.pdfBug && 'StepperManager' in globalScope &&
  2789. globalScope.StepperManager.enabled) {
  2790. this.stepper = globalScope.StepperManager.create(this.pageNumber - 1);
  2791. this.stepper.init(this.operatorList);
  2792. this.stepper.nextBreakPoint = this.stepper.getNextBreakPoint();
  2793. }
  2794. var params = this.params;
  2795. this.gfx = new CanvasGraphics(params.canvasContext, this.commonObjs,
  2796. this.objs, params.imageLayer);
  2797. this.gfx.beginDrawing(params.viewport, transparency);
  2798. this.operatorListIdx = 0;
  2799. this.graphicsReady = true;
  2800. if (this.graphicsReadyCallback) {
  2801. this.graphicsReadyCallback();
  2802. }
  2803. },
  2804. cancel: function InternalRenderTask_cancel() {
  2805. this.running = false;
  2806. this.cancelled = true;
  2807. this.callback('cancelled');
  2808. },
  2809. operatorListChanged: function InternalRenderTask_operatorListChanged() {
  2810. if (!this.graphicsReady) {
  2811. if (!this.graphicsReadyCallback) {
  2812. this.graphicsReadyCallback = this._continueBound;
  2813. }
  2814. return;
  2815. }
  2816. if (this.stepper) {
  2817. this.stepper.updateOperatorList(this.operatorList);
  2818. }
  2819. if (this.running) {
  2820. return;
  2821. }
  2822. this._continue();
  2823. },
  2824. _continue: function InternalRenderTask__continue() {
  2825. this.running = true;
  2826. if (this.cancelled) {
  2827. return;
  2828. }
  2829. if (this.task.onContinue) {
  2830. this.task.onContinue.call(this.task, this._scheduleNextBound);
  2831. } else {
  2832. this._scheduleNext();
  2833. }
  2834. },
  2835. _scheduleNext: function InternalRenderTask__scheduleNext() {
  2836. window.requestAnimationFrame(this._nextBound);
  2837. },
  2838. _next: function InternalRenderTask__next() {
  2839. if (this.cancelled) {
  2840. return;
  2841. }
  2842. this.operatorListIdx = this.gfx.executeOperatorList(this.operatorList,
  2843. this.operatorListIdx,
  2844. this._continueBound,
  2845. this.stepper);
  2846. if (this.operatorListIdx === this.operatorList.argsArray.length) {
  2847. this.running = false;
  2848. if (this.operatorList.lastChunk) {
  2849. this.gfx.endDrawing();
  2850. this.callback();
  2851. }
  2852. }
  2853. }
  2854. };
  2855. return InternalRenderTask;
  2856. })();
  2857. var Metadata = PDFJS.Metadata = (function MetadataClosure() {
  2858. function fixMetadata(meta) {
  2859. return meta.replace(/>\\376\\377([^<]+)/g, function(all, codes) {
  2860. var bytes = codes.replace(/\\([0-3])([0-7])([0-7])/g,
  2861. function(code, d1, d2, d3) {
  2862. return String.fromCharCode(d1 * 64 + d2 * 8 + d3 * 1);
  2863. });
  2864. var chars = '';
  2865. for (var i = 0; i < bytes.length; i += 2) {
  2866. var code = bytes.charCodeAt(i) * 256 + bytes.charCodeAt(i + 1);
  2867. chars += code >= 32 && code < 127 && code !== 60 && code !== 62 &&
  2868. code !== 38 && false ? String.fromCharCode(code) :
  2869. '&#x' + (0x10000 + code).toString(16).substring(1) + ';';
  2870. }
  2871. return '>' + chars;
  2872. });
  2873. }
  2874. function Metadata(meta) {
  2875. if (typeof meta === 'string') {
  2876. // Ghostscript produces invalid metadata
  2877. meta = fixMetadata(meta);
  2878. var parser = new DOMParser();
  2879. meta = parser.parseFromString(meta, 'application/xml');
  2880. } else if (!(meta instanceof Document)) {
  2881. error('Metadata: Invalid metadata object');
  2882. }
  2883. this.metaDocument = meta;
  2884. this.metadata = {};
  2885. this.parse();
  2886. }
  2887. Metadata.prototype = {
  2888. parse: function Metadata_parse() {
  2889. var doc = this.metaDocument;
  2890. var rdf = doc.documentElement;
  2891. if (rdf.nodeName.toLowerCase() !== 'rdf:rdf') { // Wrapped in <xmpmeta>
  2892. rdf = rdf.firstChild;
  2893. while (rdf && rdf.nodeName.toLowerCase() !== 'rdf:rdf') {
  2894. rdf = rdf.nextSibling;
  2895. }
  2896. }
  2897. var nodeName = (rdf) ? rdf.nodeName.toLowerCase() : null;
  2898. if (!rdf || nodeName !== 'rdf:rdf' || !rdf.hasChildNodes()) {
  2899. return;
  2900. }
  2901. var children = rdf.childNodes, desc, entry, name, i, ii, length, iLength;
  2902. for (i = 0, length = children.length; i < length; i++) {
  2903. desc = children[i];
  2904. if (desc.nodeName.toLowerCase() !== 'rdf:description') {
  2905. continue;
  2906. }
  2907. for (ii = 0, iLength = desc.childNodes.length; ii < iLength; ii++) {
  2908. if (desc.childNodes[ii].nodeName.toLowerCase() !== '#text') {
  2909. entry = desc.childNodes[ii];
  2910. name = entry.nodeName.toLowerCase();
  2911. this.metadata[name] = entry.textContent.trim();
  2912. }
  2913. }
  2914. }
  2915. },
  2916. get: function Metadata_get(name) {
  2917. return this.metadata[name] || null;
  2918. },
  2919. has: function Metadata_has(name) {
  2920. return typeof this.metadata[name] !== 'undefined';
  2921. }
  2922. };
  2923. return Metadata;
  2924. })();
  2925. // <canvas> contexts store most of the state we need natively.
  2926. // However, PDF needs a bit more state, which we store here.
  2927. // Minimal font size that would be used during canvas fillText operations.
  2928. var MIN_FONT_SIZE = 16;
  2929. // Maximum font size that would be used during canvas fillText operations.
  2930. var MAX_FONT_SIZE = 100;
  2931. var MAX_GROUP_SIZE = 4096;
  2932. // Heuristic value used when enforcing minimum line widths.
  2933. var MIN_WIDTH_FACTOR = 0.65;
  2934. var COMPILE_TYPE3_GLYPHS = true;
  2935. var MAX_SIZE_TO_COMPILE = 1000;
  2936. var FULL_CHUNK_HEIGHT = 16;
  2937. function createScratchCanvas(width, height) {
  2938. var canvas = document.createElement('canvas');
  2939. canvas.width = width;
  2940. canvas.height = height;
  2941. return canvas;
  2942. }
  2943. function addContextCurrentTransform(ctx) {
  2944. // If the context doesn't expose a `mozCurrentTransform`, add a JS based on.
  2945. if (!ctx.mozCurrentTransform) {
  2946. // Store the original context
  2947. ctx._scaleX = ctx._scaleX || 1.0;
  2948. ctx._scaleY = ctx._scaleY || 1.0;
  2949. ctx._originalSave = ctx.save;
  2950. ctx._originalRestore = ctx.restore;
  2951. ctx._originalRotate = ctx.rotate;
  2952. ctx._originalScale = ctx.scale;
  2953. ctx._originalTranslate = ctx.translate;
  2954. ctx._originalTransform = ctx.transform;
  2955. ctx._originalSetTransform = ctx.setTransform;
  2956. ctx._transformMatrix = [ctx._scaleX, 0, 0, ctx._scaleY, 0, 0];
  2957. ctx._transformStack = [];
  2958. Object.defineProperty(ctx, 'mozCurrentTransform', {
  2959. get: function getCurrentTransform() {
  2960. return this._transformMatrix;
  2961. }
  2962. });
  2963. Object.defineProperty(ctx, 'mozCurrentTransformInverse', {
  2964. get: function getCurrentTransformInverse() {
  2965. // Calculation done using WolframAlpha:
  2966. // http://www.wolframalpha.com/input/?
  2967. // i=Inverse+{{a%2C+c%2C+e}%2C+{b%2C+d%2C+f}%2C+{0%2C+0%2C+1}}
  2968. var m = this._transformMatrix;
  2969. var a = m[0], b = m[1], c = m[2], d = m[3], e = m[4], f = m[5];
  2970. var ad_bc = a * d - b * c;
  2971. var bc_ad = b * c - a * d;
  2972. return [
  2973. d / ad_bc,
  2974. b / bc_ad,
  2975. c / bc_ad,
  2976. a / ad_bc,
  2977. (d * e - c * f) / bc_ad,
  2978. (b * e - a * f) / ad_bc
  2979. ];
  2980. }
  2981. });
  2982. ctx.save = function ctxSave() {
  2983. var old = this._transformMatrix;
  2984. this._transformStack.push(old);
  2985. this._transformMatrix = old.slice(0, 6);
  2986. this._originalSave();
  2987. };
  2988. ctx.restore = function ctxRestore() {
  2989. var prev = this._transformStack.pop();
  2990. if (prev) {
  2991. this._transformMatrix = prev;
  2992. this._originalRestore();
  2993. }
  2994. };
  2995. ctx.translate = function ctxTranslate(x, y) {
  2996. var m = this._transformMatrix;
  2997. m[4] = m[0] * x + m[2] * y + m[4];
  2998. m[5] = m[1] * x + m[3] * y + m[5];
  2999. this._originalTranslate(x, y);
  3000. };
  3001. ctx.scale = function ctxScale(x, y) {
  3002. var m = this._transformMatrix;
  3003. m[0] = m[0] * x;
  3004. m[1] = m[1] * x;
  3005. m[2] = m[2] * y;
  3006. m[3] = m[3] * y;
  3007. this._originalScale(x, y);
  3008. };
  3009. ctx.transform = function ctxTransform(a, b, c, d, e, f) {
  3010. var m = this._transformMatrix;
  3011. this._transformMatrix = [
  3012. m[0] * a + m[2] * b,
  3013. m[1] * a + m[3] * b,
  3014. m[0] * c + m[2] * d,
  3015. m[1] * c + m[3] * d,
  3016. m[0] * e + m[2] * f + m[4],
  3017. m[1] * e + m[3] * f + m[5]
  3018. ];
  3019. ctx._originalTransform(a, b, c, d, e, f);
  3020. };
  3021. ctx.setTransform = function ctxSetTransform(a, b, c, d, e, f) {
  3022. this._transformMatrix = [a, b, c, d, e, f];
  3023. ctx._originalSetTransform(a, b, c, d, e, f);
  3024. };
  3025. ctx.rotate = function ctxRotate(angle) {
  3026. var cosValue = Math.cos(angle);
  3027. var sinValue = Math.sin(angle);
  3028. var m = this._transformMatrix;
  3029. this._transformMatrix = [
  3030. m[0] * cosValue + m[2] * sinValue,
  3031. m[1] * cosValue + m[3] * sinValue,
  3032. m[0] * (-sinValue) + m[2] * cosValue,
  3033. m[1] * (-sinValue) + m[3] * cosValue,
  3034. m[4],
  3035. m[5]
  3036. ];
  3037. this._originalRotate(angle);
  3038. };
  3039. }
  3040. }
  3041. var CachedCanvases = (function CachedCanvasesClosure() {
  3042. var cache = {};
  3043. return {
  3044. getCanvas: function CachedCanvases_getCanvas(id, width, height,
  3045. trackTransform) {
  3046. var canvasEntry;
  3047. if (cache[id] !== undefined) {
  3048. canvasEntry = cache[id];
  3049. canvasEntry.canvas.width = width;
  3050. canvasEntry.canvas.height = height;
  3051. // reset canvas transform for emulated mozCurrentTransform, if needed
  3052. canvasEntry.context.setTransform(1, 0, 0, 1, 0, 0);
  3053. } else {
  3054. var canvas = createScratchCanvas(width, height);
  3055. var ctx = canvas.getContext('2d');
  3056. if (trackTransform) {
  3057. addContextCurrentTransform(ctx);
  3058. }
  3059. cache[id] = canvasEntry = {canvas: canvas, context: ctx};
  3060. }
  3061. return canvasEntry;
  3062. },
  3063. clear: function () {
  3064. for (var id in cache) {
  3065. var canvasEntry = cache[id];
  3066. // Zeroing the width and height causes Firefox to release graphics
  3067. // resources immediately, which can greatly reduce memory consumption.
  3068. canvasEntry.canvas.width = 0;
  3069. canvasEntry.canvas.height = 0;
  3070. delete cache[id];
  3071. }
  3072. }
  3073. };
  3074. })();
  3075. function compileType3Glyph(imgData) {
  3076. var POINT_TO_PROCESS_LIMIT = 1000;
  3077. var width = imgData.width, height = imgData.height;
  3078. var i, j, j0, width1 = width + 1;
  3079. var points = new Uint8Array(width1 * (height + 1));
  3080. var POINT_TYPES =
  3081. new Uint8Array([0, 2, 4, 0, 1, 0, 5, 4, 8, 10, 0, 8, 0, 2, 1, 0]);
  3082. // decodes bit-packed mask data
  3083. var lineSize = (width + 7) & ~7, data0 = imgData.data;
  3084. var data = new Uint8Array(lineSize * height), pos = 0, ii;
  3085. for (i = 0, ii = data0.length; i < ii; i++) {
  3086. var mask = 128, elem = data0[i];
  3087. while (mask > 0) {
  3088. data[pos++] = (elem & mask) ? 0 : 255;
  3089. mask >>= 1;
  3090. }
  3091. }
  3092. // finding iteresting points: every point is located between mask pixels,
  3093. // so there will be points of the (width + 1)x(height + 1) grid. Every point
  3094. // will have flags assigned based on neighboring mask pixels:
  3095. // 4 | 8
  3096. // --P--
  3097. // 2 | 1
  3098. // We are interested only in points with the flags:
  3099. // - outside corners: 1, 2, 4, 8;
  3100. // - inside corners: 7, 11, 13, 14;
  3101. // - and, intersections: 5, 10.
  3102. var count = 0;
  3103. pos = 0;
  3104. if (data[pos] !== 0) {
  3105. points[0] = 1;
  3106. ++count;
  3107. }
  3108. for (j = 1; j < width; j++) {
  3109. if (data[pos] !== data[pos + 1]) {
  3110. points[j] = data[pos] ? 2 : 1;
  3111. ++count;
  3112. }
  3113. pos++;
  3114. }
  3115. if (data[pos] !== 0) {
  3116. points[j] = 2;
  3117. ++count;
  3118. }
  3119. for (i = 1; i < height; i++) {
  3120. pos = i * lineSize;
  3121. j0 = i * width1;
  3122. if (data[pos - lineSize] !== data[pos]) {
  3123. points[j0] = data[pos] ? 1 : 8;
  3124. ++count;
  3125. }
  3126. // 'sum' is the position of the current pixel configuration in the 'TYPES'
  3127. // array (in order 8-1-2-4, so we can use '>>2' to shift the column).
  3128. var sum = (data[pos] ? 4 : 0) + (data[pos - lineSize] ? 8 : 0);
  3129. for (j = 1; j < width; j++) {
  3130. sum = (sum >> 2) + (data[pos + 1] ? 4 : 0) +
  3131. (data[pos - lineSize + 1] ? 8 : 0);
  3132. if (POINT_TYPES[sum]) {
  3133. points[j0 + j] = POINT_TYPES[sum];
  3134. ++count;
  3135. }
  3136. pos++;
  3137. }
  3138. if (data[pos - lineSize] !== data[pos]) {
  3139. points[j0 + j] = data[pos] ? 2 : 4;
  3140. ++count;
  3141. }
  3142. if (count > POINT_TO_PROCESS_LIMIT) {
  3143. return null;
  3144. }
  3145. }
  3146. pos = lineSize * (height - 1);
  3147. j0 = i * width1;
  3148. if (data[pos] !== 0) {
  3149. points[j0] = 8;
  3150. ++count;
  3151. }
  3152. for (j = 1; j < width; j++) {
  3153. if (data[pos] !== data[pos + 1]) {
  3154. points[j0 + j] = data[pos] ? 4 : 8;
  3155. ++count;
  3156. }
  3157. pos++;
  3158. }
  3159. if (data[pos] !== 0) {
  3160. points[j0 + j] = 4;
  3161. ++count;
  3162. }
  3163. if (count > POINT_TO_PROCESS_LIMIT) {
  3164. return null;
  3165. }
  3166. // building outlines
  3167. var steps = new Int32Array([0, width1, -1, 0, -width1, 0, 0, 0, 1]);
  3168. var outlines = [];
  3169. for (i = 0; count && i <= height; i++) {
  3170. var p = i * width1;
  3171. var end = p + width;
  3172. while (p < end && !points[p]) {
  3173. p++;
  3174. }
  3175. if (p === end) {
  3176. continue;
  3177. }
  3178. var coords = [p % width1, i];
  3179. var type = points[p], p0 = p, pp;
  3180. do {
  3181. var step = steps[type];
  3182. do {
  3183. p += step;
  3184. } while (!points[p]);
  3185. pp = points[p];
  3186. if (pp !== 5 && pp !== 10) {
  3187. // set new direction
  3188. type = pp;
  3189. // delete mark
  3190. points[p] = 0;
  3191. } else { // type is 5 or 10, ie, a crossing
  3192. // set new direction
  3193. type = pp & ((0x33 * type) >> 4);
  3194. // set new type for "future hit"
  3195. points[p] &= (type >> 2 | type << 2);
  3196. }
  3197. coords.push(p % width1);
  3198. coords.push((p / width1) | 0);
  3199. --count;
  3200. } while (p0 !== p);
  3201. outlines.push(coords);
  3202. --i;
  3203. }
  3204. var drawOutline = function(c) {
  3205. c.save();
  3206. // the path shall be painted in [0..1]x[0..1] space
  3207. c.scale(1 / width, -1 / height);
  3208. c.translate(0, -height);
  3209. c.beginPath();
  3210. for (var i = 0, ii = outlines.length; i < ii; i++) {
  3211. var o = outlines[i];
  3212. c.moveTo(o[0], o[1]);
  3213. for (var j = 2, jj = o.length; j < jj; j += 2) {
  3214. c.lineTo(o[j], o[j+1]);
  3215. }
  3216. }
  3217. c.fill();
  3218. c.beginPath();
  3219. c.restore();
  3220. };
  3221. return drawOutline;
  3222. }
  3223. var CanvasExtraState = (function CanvasExtraStateClosure() {
  3224. function CanvasExtraState(old) {
  3225. // Are soft masks and alpha values shapes or opacities?
  3226. this.alphaIsShape = false;
  3227. this.fontSize = 0;
  3228. this.fontSizeScale = 1;
  3229. this.textMatrix = IDENTITY_MATRIX;
  3230. this.textMatrixScale = 1;
  3231. this.fontMatrix = FONT_IDENTITY_MATRIX;
  3232. this.leading = 0;
  3233. // Current point (in user coordinates)
  3234. this.x = 0;
  3235. this.y = 0;
  3236. // Start of text line (in text coordinates)
  3237. this.lineX = 0;
  3238. this.lineY = 0;
  3239. // Character and word spacing
  3240. this.charSpacing = 0;
  3241. this.wordSpacing = 0;
  3242. this.textHScale = 1;
  3243. this.textRenderingMode = TextRenderingMode.FILL;
  3244. this.textRise = 0;
  3245. // Default fore and background colors
  3246. this.fillColor = '#000000';
  3247. this.strokeColor = '#000000';
  3248. this.patternFill = false;
  3249. // Note: fill alpha applies to all non-stroking operations
  3250. this.fillAlpha = 1;
  3251. this.strokeAlpha = 1;
  3252. this.lineWidth = 1;
  3253. this.activeSMask = null; // nonclonable field (see the save method below)
  3254. this.old = old;
  3255. }
  3256. CanvasExtraState.prototype = {
  3257. clone: function CanvasExtraState_clone() {
  3258. return Object.create(this);
  3259. },
  3260. setCurrentPoint: function CanvasExtraState_setCurrentPoint(x, y) {
  3261. this.x = x;
  3262. this.y = y;
  3263. }
  3264. };
  3265. return CanvasExtraState;
  3266. })();
  3267. var CanvasGraphics = (function CanvasGraphicsClosure() {
  3268. // Defines the time the executeOperatorList is going to be executing
  3269. // before it stops and shedules a continue of execution.
  3270. var EXECUTION_TIME = 15;
  3271. // Defines the number of steps before checking the execution time
  3272. var EXECUTION_STEPS = 10;
  3273. function CanvasGraphics(canvasCtx, commonObjs, objs, imageLayer) {
  3274. this.ctx = canvasCtx;
  3275. this.current = new CanvasExtraState();
  3276. this.stateStack = [];
  3277. this.pendingClip = null;
  3278. this.pendingEOFill = false;
  3279. this.res = null;
  3280. this.xobjs = null;
  3281. this.commonObjs = commonObjs;
  3282. this.objs = objs;
  3283. this.imageLayer = imageLayer;
  3284. this.groupStack = [];
  3285. this.processingType3 = null;
  3286. // Patterns are painted relative to the initial page/form transform, see pdf
  3287. // spec 8.7.2 NOTE 1.
  3288. this.baseTransform = null;
  3289. this.baseTransformStack = [];
  3290. this.groupLevel = 0;
  3291. this.smaskStack = [];
  3292. this.smaskCounter = 0;
  3293. this.tempSMask = null;
  3294. if (canvasCtx) {
  3295. addContextCurrentTransform(canvasCtx);
  3296. }
  3297. this.cachedGetSinglePixelWidth = null;
  3298. }
  3299. function putBinaryImageData(ctx, imgData) {
  3300. if (typeof ImageData !== 'undefined' && imgData instanceof ImageData) {
  3301. ctx.putImageData(imgData, 0, 0);
  3302. return;
  3303. }
  3304. // Put the image data to the canvas in chunks, rather than putting the
  3305. // whole image at once. This saves JS memory, because the ImageData object
  3306. // is smaller. It also possibly saves C++ memory within the implementation
  3307. // of putImageData(). (E.g. in Firefox we make two short-lived copies of
  3308. // the data passed to putImageData()). |n| shouldn't be too small, however,
  3309. // because too many putImageData() calls will slow things down.
  3310. //
  3311. // Note: as written, if the last chunk is partial, the putImageData() call
  3312. // will (conceptually) put pixels past the bounds of the canvas. But
  3313. // that's ok; any such pixels are ignored.
  3314. var height = imgData.height, width = imgData.width;
  3315. var partialChunkHeight = height % FULL_CHUNK_HEIGHT;
  3316. var fullChunks = (height - partialChunkHeight) / FULL_CHUNK_HEIGHT;
  3317. var totalChunks = partialChunkHeight === 0 ? fullChunks : fullChunks + 1;
  3318. var chunkImgData = ctx.createImageData(width, FULL_CHUNK_HEIGHT);
  3319. var srcPos = 0, destPos;
  3320. var src = imgData.data;
  3321. var dest = chunkImgData.data;
  3322. var i, j, thisChunkHeight, elemsInThisChunk;
  3323. // There are multiple forms in which the pixel data can be passed, and
  3324. // imgData.kind tells us which one this is.
  3325. if (imgData.kind === ImageKind.GRAYSCALE_1BPP) {
  3326. // Grayscale, 1 bit per pixel (i.e. black-and-white).
  3327. var srcLength = src.byteLength;
  3328. var dest32 = PDFJS.hasCanvasTypedArrays ? new Uint32Array(dest.buffer) :
  3329. new Uint32ArrayView(dest);
  3330. var dest32DataLength = dest32.length;
  3331. var fullSrcDiff = (width + 7) >> 3;
  3332. var white = 0xFFFFFFFF;
  3333. var black = (PDFJS.isLittleEndian || !PDFJS.hasCanvasTypedArrays) ?
  3334. 0xFF000000 : 0x000000FF;
  3335. for (i = 0; i < totalChunks; i++) {
  3336. thisChunkHeight =
  3337. (i < fullChunks) ? FULL_CHUNK_HEIGHT : partialChunkHeight;
  3338. destPos = 0;
  3339. for (j = 0; j < thisChunkHeight; j++) {
  3340. var srcDiff = srcLength - srcPos;
  3341. var k = 0;
  3342. var kEnd = (srcDiff > fullSrcDiff) ? width : srcDiff * 8 - 7;
  3343. var kEndUnrolled = kEnd & ~7;
  3344. var mask = 0;
  3345. var srcByte = 0;
  3346. for (; k < kEndUnrolled; k += 8) {
  3347. srcByte = src[srcPos++];
  3348. dest32[destPos++] = (srcByte & 128) ? white : black;
  3349. dest32[destPos++] = (srcByte & 64) ? white : black;
  3350. dest32[destPos++] = (srcByte & 32) ? white : black;
  3351. dest32[destPos++] = (srcByte & 16) ? white : black;
  3352. dest32[destPos++] = (srcByte & 8) ? white : black;
  3353. dest32[destPos++] = (srcByte & 4) ? white : black;
  3354. dest32[destPos++] = (srcByte & 2) ? white : black;
  3355. dest32[destPos++] = (srcByte & 1) ? white : black;
  3356. }
  3357. for (; k < kEnd; k++) {
  3358. if (mask === 0) {
  3359. srcByte = src[srcPos++];
  3360. mask = 128;
  3361. }
  3362. dest32[destPos++] = (srcByte & mask) ? white : black;
  3363. mask >>= 1;
  3364. }
  3365. }
  3366. // We ran out of input. Make all remaining pixels transparent.
  3367. while (destPos < dest32DataLength) {
  3368. dest32[destPos++] = 0;
  3369. }
  3370. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  3371. }
  3372. } else if (imgData.kind === ImageKind.RGBA_32BPP) {
  3373. // RGBA, 32-bits per pixel.
  3374. j = 0;
  3375. elemsInThisChunk = width * FULL_CHUNK_HEIGHT * 4;
  3376. for (i = 0; i < fullChunks; i++) {
  3377. dest.set(src.subarray(srcPos, srcPos + elemsInThisChunk));
  3378. srcPos += elemsInThisChunk;
  3379. ctx.putImageData(chunkImgData, 0, j);
  3380. j += FULL_CHUNK_HEIGHT;
  3381. }
  3382. if (i < totalChunks) {
  3383. elemsInThisChunk = width * partialChunkHeight * 4;
  3384. dest.set(src.subarray(srcPos, srcPos + elemsInThisChunk));
  3385. ctx.putImageData(chunkImgData, 0, j);
  3386. }
  3387. } else if (imgData.kind === ImageKind.RGB_24BPP) {
  3388. // RGB, 24-bits per pixel.
  3389. thisChunkHeight = FULL_CHUNK_HEIGHT;
  3390. elemsInThisChunk = width * thisChunkHeight;
  3391. for (i = 0; i < totalChunks; i++) {
  3392. if (i >= fullChunks) {
  3393. thisChunkHeight = partialChunkHeight;
  3394. elemsInThisChunk = width * thisChunkHeight;
  3395. }
  3396. destPos = 0;
  3397. for (j = elemsInThisChunk; j--;) {
  3398. dest[destPos++] = src[srcPos++];
  3399. dest[destPos++] = src[srcPos++];
  3400. dest[destPos++] = src[srcPos++];
  3401. dest[destPos++] = 255;
  3402. }
  3403. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  3404. }
  3405. } else {
  3406. error('bad image kind: ' + imgData.kind);
  3407. }
  3408. }
  3409. function putBinaryImageMask(ctx, imgData) {
  3410. var height = imgData.height, width = imgData.width;
  3411. var partialChunkHeight = height % FULL_CHUNK_HEIGHT;
  3412. var fullChunks = (height - partialChunkHeight) / FULL_CHUNK_HEIGHT;
  3413. var totalChunks = partialChunkHeight === 0 ? fullChunks : fullChunks + 1;
  3414. var chunkImgData = ctx.createImageData(width, FULL_CHUNK_HEIGHT);
  3415. var srcPos = 0;
  3416. var src = imgData.data;
  3417. var dest = chunkImgData.data;
  3418. for (var i = 0; i < totalChunks; i++) {
  3419. var thisChunkHeight =
  3420. (i < fullChunks) ? FULL_CHUNK_HEIGHT : partialChunkHeight;
  3421. // Expand the mask so it can be used by the canvas. Any required
  3422. // inversion has already been handled.
  3423. var destPos = 3; // alpha component offset
  3424. for (var j = 0; j < thisChunkHeight; j++) {
  3425. var mask = 0;
  3426. for (var k = 0; k < width; k++) {
  3427. if (!mask) {
  3428. var elem = src[srcPos++];
  3429. mask = 128;
  3430. }
  3431. dest[destPos] = (elem & mask) ? 0 : 255;
  3432. destPos += 4;
  3433. mask >>= 1;
  3434. }
  3435. }
  3436. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  3437. }
  3438. }
  3439. function copyCtxState(sourceCtx, destCtx) {
  3440. var properties = ['strokeStyle', 'fillStyle', 'fillRule', 'globalAlpha',
  3441. 'lineWidth', 'lineCap', 'lineJoin', 'miterLimit',
  3442. 'globalCompositeOperation', 'font'];
  3443. for (var i = 0, ii = properties.length; i < ii; i++) {
  3444. var property = properties[i];
  3445. if (sourceCtx[property] !== undefined) {
  3446. destCtx[property] = sourceCtx[property];
  3447. }
  3448. }
  3449. if (sourceCtx.setLineDash !== undefined) {
  3450. destCtx.setLineDash(sourceCtx.getLineDash());
  3451. destCtx.lineDashOffset = sourceCtx.lineDashOffset;
  3452. } else if (sourceCtx.mozDashOffset !== undefined) {
  3453. destCtx.mozDash = sourceCtx.mozDash;
  3454. destCtx.mozDashOffset = sourceCtx.mozDashOffset;
  3455. }
  3456. }
  3457. function composeSMaskBackdrop(bytes, r0, g0, b0) {
  3458. var length = bytes.length;
  3459. for (var i = 3; i < length; i += 4) {
  3460. var alpha = bytes[i];
  3461. if (alpha === 0) {
  3462. bytes[i - 3] = r0;
  3463. bytes[i - 2] = g0;
  3464. bytes[i - 1] = b0;
  3465. } else if (alpha < 255) {
  3466. var alpha_ = 255 - alpha;
  3467. bytes[i - 3] = (bytes[i - 3] * alpha + r0 * alpha_) >> 8;
  3468. bytes[i - 2] = (bytes[i - 2] * alpha + g0 * alpha_) >> 8;
  3469. bytes[i - 1] = (bytes[i - 1] * alpha + b0 * alpha_) >> 8;
  3470. }
  3471. }
  3472. }
  3473. function composeSMaskAlpha(maskData, layerData) {
  3474. var length = maskData.length;
  3475. var scale = 1 / 255;
  3476. for (var i = 3; i < length; i += 4) {
  3477. var alpha = maskData[i];
  3478. layerData[i] = (layerData[i] * alpha * scale) | 0;
  3479. }
  3480. }
  3481. function composeSMaskLuminosity(maskData, layerData) {
  3482. var length = maskData.length;
  3483. for (var i = 3; i < length; i += 4) {
  3484. var y = (maskData[i - 3] * 77) + // * 0.3 / 255 * 0x10000
  3485. (maskData[i - 2] * 152) + // * 0.59 ....
  3486. (maskData[i - 1] * 28); // * 0.11 ....
  3487. layerData[i] = (layerData[i] * y) >> 16;
  3488. }
  3489. }
  3490. function genericComposeSMask(maskCtx, layerCtx, width, height,
  3491. subtype, backdrop) {
  3492. var hasBackdrop = !!backdrop;
  3493. var r0 = hasBackdrop ? backdrop[0] : 0;
  3494. var g0 = hasBackdrop ? backdrop[1] : 0;
  3495. var b0 = hasBackdrop ? backdrop[2] : 0;
  3496. var composeFn;
  3497. if (subtype === 'Luminosity') {
  3498. composeFn = composeSMaskLuminosity;
  3499. } else {
  3500. composeFn = composeSMaskAlpha;
  3501. }
  3502. // processing image in chunks to save memory
  3503. var PIXELS_TO_PROCESS = 1048576;
  3504. var chunkSize = Math.min(height, Math.ceil(PIXELS_TO_PROCESS / width));
  3505. for (var row = 0; row < height; row += chunkSize) {
  3506. var chunkHeight = Math.min(chunkSize, height - row);
  3507. var maskData = maskCtx.getImageData(0, row, width, chunkHeight);
  3508. var layerData = layerCtx.getImageData(0, row, width, chunkHeight);
  3509. if (hasBackdrop) {
  3510. composeSMaskBackdrop(maskData.data, r0, g0, b0);
  3511. }
  3512. composeFn(maskData.data, layerData.data);
  3513. maskCtx.putImageData(layerData, 0, row);
  3514. }
  3515. }
  3516. function composeSMask(ctx, smask, layerCtx) {
  3517. var mask = smask.canvas;
  3518. var maskCtx = smask.context;
  3519. ctx.setTransform(smask.scaleX, 0, 0, smask.scaleY,
  3520. smask.offsetX, smask.offsetY);
  3521. var backdrop = smask.backdrop || null;
  3522. if (WebGLUtils.isEnabled) {
  3523. var composed = WebGLUtils.composeSMask(layerCtx.canvas, mask,
  3524. {subtype: smask.subtype, backdrop: backdrop});
  3525. ctx.setTransform(1, 0, 0, 1, 0, 0);
  3526. ctx.drawImage(composed, smask.offsetX, smask.offsetY);
  3527. return;
  3528. }
  3529. genericComposeSMask(maskCtx, layerCtx, mask.width, mask.height,
  3530. smask.subtype, backdrop);
  3531. ctx.drawImage(mask, 0, 0);
  3532. }
  3533. var LINE_CAP_STYLES = ['butt', 'round', 'square'];
  3534. var LINE_JOIN_STYLES = ['miter', 'round', 'bevel'];
  3535. var NORMAL_CLIP = {};
  3536. var EO_CLIP = {};
  3537. CanvasGraphics.prototype = {
  3538. beginDrawing: function CanvasGraphics_beginDrawing(viewport, transparency) {
  3539. // For pdfs that use blend modes we have to clear the canvas else certain
  3540. // blend modes can look wrong since we'd be blending with a white
  3541. // backdrop. The problem with a transparent backdrop though is we then
  3542. // don't get sub pixel anti aliasing on text, so we fill with white if
  3543. // we can.
  3544. var width = this.ctx.canvas.width;
  3545. var height = this.ctx.canvas.height;
  3546. if (transparency) {
  3547. this.ctx.clearRect(0, 0, width, height);
  3548. } else {
  3549. this.ctx.mozOpaque = true;
  3550. this.ctx.save();
  3551. this.ctx.fillStyle = 'rgb(255, 255, 255)';
  3552. this.ctx.fillRect(0, 0, width, height);
  3553. this.ctx.restore();
  3554. }
  3555. var transform = viewport.transform;
  3556. this.ctx.save();
  3557. this.ctx.transform.apply(this.ctx, transform);
  3558. this.baseTransform = this.ctx.mozCurrentTransform.slice();
  3559. if (this.imageLayer) {
  3560. this.imageLayer.beginLayout();
  3561. }
  3562. },
  3563. executeOperatorList: function CanvasGraphics_executeOperatorList(
  3564. operatorList,
  3565. executionStartIdx, continueCallback,
  3566. stepper) {
  3567. var argsArray = operatorList.argsArray;
  3568. var fnArray = operatorList.fnArray;
  3569. var i = executionStartIdx || 0;
  3570. var argsArrayLen = argsArray.length;
  3571. // Sometimes the OperatorList to execute is empty.
  3572. if (argsArrayLen === i) {
  3573. return i;
  3574. }
  3575. var chunkOperations = (argsArrayLen - i > EXECUTION_STEPS &&
  3576. typeof continueCallback === 'function');
  3577. var endTime = chunkOperations ? Date.now() + EXECUTION_TIME : 0;
  3578. var steps = 0;
  3579. var commonObjs = this.commonObjs;
  3580. var objs = this.objs;
  3581. var fnId;
  3582. while (true) {
  3583. if (stepper !== undefined && i === stepper.nextBreakPoint) {
  3584. stepper.breakIt(i, continueCallback);
  3585. return i;
  3586. }
  3587. fnId = fnArray[i];
  3588. if (fnId !== OPS.dependency) {
  3589. this[fnId].apply(this, argsArray[i]);
  3590. } else {
  3591. var deps = argsArray[i];
  3592. for (var n = 0, nn = deps.length; n < nn; n++) {
  3593. var depObjId = deps[n];
  3594. var common = depObjId[0] === 'g' && depObjId[1] === '_';
  3595. var objsPool = common ? commonObjs : objs;
  3596. // If the promise isn't resolved yet, add the continueCallback
  3597. // to the promise and bail out.
  3598. if (!objsPool.isResolved(depObjId)) {
  3599. objsPool.get(depObjId, continueCallback);
  3600. return i;
  3601. }
  3602. }
  3603. }
  3604. i++;
  3605. // If the entire operatorList was executed, stop as were done.
  3606. if (i === argsArrayLen) {
  3607. return i;
  3608. }
  3609. // If the execution took longer then a certain amount of time and
  3610. // `continueCallback` is specified, interrupt the execution.
  3611. if (chunkOperations && ++steps > EXECUTION_STEPS) {
  3612. if (Date.now() > endTime) {
  3613. continueCallback();
  3614. return i;
  3615. }
  3616. steps = 0;
  3617. }
  3618. // If the operatorList isn't executed completely yet OR the execution
  3619. // time was short enough, do another execution round.
  3620. }
  3621. },
  3622. endDrawing: function CanvasGraphics_endDrawing() {
  3623. this.ctx.restore();
  3624. CachedCanvases.clear();
  3625. WebGLUtils.clear();
  3626. if (this.imageLayer) {
  3627. this.imageLayer.endLayout();
  3628. }
  3629. },
  3630. // Graphics state
  3631. setLineWidth: function CanvasGraphics_setLineWidth(width) {
  3632. this.current.lineWidth = width;
  3633. this.ctx.lineWidth = width;
  3634. },
  3635. setLineCap: function CanvasGraphics_setLineCap(style) {
  3636. this.ctx.lineCap = LINE_CAP_STYLES[style];
  3637. },
  3638. setLineJoin: function CanvasGraphics_setLineJoin(style) {
  3639. this.ctx.lineJoin = LINE_JOIN_STYLES[style];
  3640. },
  3641. setMiterLimit: function CanvasGraphics_setMiterLimit(limit) {
  3642. this.ctx.miterLimit = limit;
  3643. },
  3644. setDash: function CanvasGraphics_setDash(dashArray, dashPhase) {
  3645. var ctx = this.ctx;
  3646. if (ctx.setLineDash !== undefined) {
  3647. ctx.setLineDash(dashArray);
  3648. ctx.lineDashOffset = dashPhase;
  3649. } else {
  3650. ctx.mozDash = dashArray;
  3651. ctx.mozDashOffset = dashPhase;
  3652. }
  3653. },
  3654. setRenderingIntent: function CanvasGraphics_setRenderingIntent(intent) {
  3655. // Maybe if we one day fully support color spaces this will be important
  3656. // for now we can ignore.
  3657. // TODO set rendering intent?
  3658. },
  3659. setFlatness: function CanvasGraphics_setFlatness(flatness) {
  3660. // There's no way to control this with canvas, but we can safely ignore.
  3661. // TODO set flatness?
  3662. },
  3663. setGState: function CanvasGraphics_setGState(states) {
  3664. for (var i = 0, ii = states.length; i < ii; i++) {
  3665. var state = states[i];
  3666. var key = state[0];
  3667. var value = state[1];
  3668. switch (key) {
  3669. case 'LW':
  3670. this.setLineWidth(value);
  3671. break;
  3672. case 'LC':
  3673. this.setLineCap(value);
  3674. break;
  3675. case 'LJ':
  3676. this.setLineJoin(value);
  3677. break;
  3678. case 'ML':
  3679. this.setMiterLimit(value);
  3680. break;
  3681. case 'D':
  3682. this.setDash(value[0], value[1]);
  3683. break;
  3684. case 'RI':
  3685. this.setRenderingIntent(value);
  3686. break;
  3687. case 'FL':
  3688. this.setFlatness(value);
  3689. break;
  3690. case 'Font':
  3691. this.setFont(value[0], value[1]);
  3692. break;
  3693. case 'CA':
  3694. this.current.strokeAlpha = state[1];
  3695. break;
  3696. case 'ca':
  3697. this.current.fillAlpha = state[1];
  3698. this.ctx.globalAlpha = state[1];
  3699. break;
  3700. case 'BM':
  3701. if (value && value.name && (value.name !== 'Normal')) {
  3702. var mode = value.name.replace(/([A-Z])/g,
  3703. function(c) {
  3704. return '-' + c.toLowerCase();
  3705. }
  3706. ).substring(1);
  3707. this.ctx.globalCompositeOperation = mode;
  3708. if (this.ctx.globalCompositeOperation !== mode) {
  3709. warn('globalCompositeOperation "' + mode +
  3710. '" is not supported');
  3711. }
  3712. } else {
  3713. this.ctx.globalCompositeOperation = 'source-over';
  3714. }
  3715. break;
  3716. case 'SMask':
  3717. if (this.current.activeSMask) {
  3718. this.endSMaskGroup();
  3719. }
  3720. this.current.activeSMask = value ? this.tempSMask : null;
  3721. if (this.current.activeSMask) {
  3722. this.beginSMaskGroup();
  3723. }
  3724. this.tempSMask = null;
  3725. break;
  3726. }
  3727. }
  3728. },
  3729. beginSMaskGroup: function CanvasGraphics_beginSMaskGroup() {
  3730. var activeSMask = this.current.activeSMask;
  3731. var drawnWidth = activeSMask.canvas.width;
  3732. var drawnHeight = activeSMask.canvas.height;
  3733. var cacheId = 'smaskGroupAt' + this.groupLevel;
  3734. var scratchCanvas = CachedCanvases.getCanvas(
  3735. cacheId, drawnWidth, drawnHeight, true);
  3736. var currentCtx = this.ctx;
  3737. var currentTransform = currentCtx.mozCurrentTransform;
  3738. this.ctx.save();
  3739. var groupCtx = scratchCanvas.context;
  3740. groupCtx.scale(1 / activeSMask.scaleX, 1 / activeSMask.scaleY);
  3741. groupCtx.translate(-activeSMask.offsetX, -activeSMask.offsetY);
  3742. groupCtx.transform.apply(groupCtx, currentTransform);
  3743. copyCtxState(currentCtx, groupCtx);
  3744. this.ctx = groupCtx;
  3745. this.setGState([
  3746. ['BM', 'Normal'],
  3747. ['ca', 1],
  3748. ['CA', 1]
  3749. ]);
  3750. this.groupStack.push(currentCtx);
  3751. this.groupLevel++;
  3752. },
  3753. endSMaskGroup: function CanvasGraphics_endSMaskGroup() {
  3754. var groupCtx = this.ctx;
  3755. this.groupLevel--;
  3756. this.ctx = this.groupStack.pop();
  3757. composeSMask(this.ctx, this.current.activeSMask, groupCtx);
  3758. this.ctx.restore();
  3759. },
  3760. save: function CanvasGraphics_save() {
  3761. this.ctx.save();
  3762. var old = this.current;
  3763. this.stateStack.push(old);
  3764. this.current = old.clone();
  3765. this.current.activeSMask = null;
  3766. },
  3767. restore: function CanvasGraphics_restore() {
  3768. if (this.stateStack.length !== 0) {
  3769. if (this.current.activeSMask !== null) {
  3770. this.endSMaskGroup();
  3771. }
  3772. this.current = this.stateStack.pop();
  3773. this.ctx.restore();
  3774. this.cachedGetSinglePixelWidth = null;
  3775. }
  3776. },
  3777. transform: function CanvasGraphics_transform(a, b, c, d, e, f) {
  3778. this.ctx.transform(a, b, c, d, e, f);
  3779. this.cachedGetSinglePixelWidth = null;
  3780. },
  3781. // Path
  3782. constructPath: function CanvasGraphics_constructPath(ops, args) {
  3783. var ctx = this.ctx;
  3784. var current = this.current;
  3785. var x = current.x, y = current.y;
  3786. for (var i = 0, j = 0, ii = ops.length; i < ii; i++) {
  3787. switch (ops[i] | 0) {
  3788. case OPS.rectangle:
  3789. x = args[j++];
  3790. y = args[j++];
  3791. var width = args[j++];
  3792. var height = args[j++];
  3793. if (width === 0) {
  3794. width = this.getSinglePixelWidth();
  3795. }
  3796. if (height === 0) {
  3797. height = this.getSinglePixelWidth();
  3798. }
  3799. var xw = x + width;
  3800. var yh = y + height;
  3801. this.ctx.moveTo(x, y);
  3802. this.ctx.lineTo(xw, y);
  3803. this.ctx.lineTo(xw, yh);
  3804. this.ctx.lineTo(x, yh);
  3805. this.ctx.lineTo(x, y);
  3806. this.ctx.closePath();
  3807. break;
  3808. case OPS.moveTo:
  3809. x = args[j++];
  3810. y = args[j++];
  3811. ctx.moveTo(x, y);
  3812. break;
  3813. case OPS.lineTo:
  3814. x = args[j++];
  3815. y = args[j++];
  3816. ctx.lineTo(x, y);
  3817. break;
  3818. case OPS.curveTo:
  3819. x = args[j + 4];
  3820. y = args[j + 5];
  3821. ctx.bezierCurveTo(args[j], args[j + 1], args[j + 2], args[j + 3],
  3822. x, y);
  3823. j += 6;
  3824. break;
  3825. case OPS.curveTo2:
  3826. ctx.bezierCurveTo(x, y, args[j], args[j + 1],
  3827. args[j + 2], args[j + 3]);
  3828. x = args[j + 2];
  3829. y = args[j + 3];
  3830. j += 4;
  3831. break;
  3832. case OPS.curveTo3:
  3833. x = args[j + 2];
  3834. y = args[j + 3];
  3835. ctx.bezierCurveTo(args[j], args[j + 1], x, y, x, y);
  3836. j += 4;
  3837. break;
  3838. case OPS.closePath:
  3839. ctx.closePath();
  3840. break;
  3841. }
  3842. }
  3843. current.setCurrentPoint(x, y);
  3844. },
  3845. closePath: function CanvasGraphics_closePath() {
  3846. this.ctx.closePath();
  3847. },
  3848. stroke: function CanvasGraphics_stroke(consumePath) {
  3849. consumePath = typeof consumePath !== 'undefined' ? consumePath : true;
  3850. var ctx = this.ctx;
  3851. var strokeColor = this.current.strokeColor;
  3852. // Prevent drawing too thin lines by enforcing a minimum line width.
  3853. ctx.lineWidth = Math.max(this.getSinglePixelWidth() * MIN_WIDTH_FACTOR,
  3854. this.current.lineWidth);
  3855. // For stroke we want to temporarily change the global alpha to the
  3856. // stroking alpha.
  3857. ctx.globalAlpha = this.current.strokeAlpha;
  3858. if (strokeColor && strokeColor.hasOwnProperty('type') &&
  3859. strokeColor.type === 'Pattern') {
  3860. // for patterns, we transform to pattern space, calculate
  3861. // the pattern, call stroke, and restore to user space
  3862. ctx.save();
  3863. ctx.strokeStyle = strokeColor.getPattern(ctx, this);
  3864. ctx.stroke();
  3865. ctx.restore();
  3866. } else {
  3867. ctx.stroke();
  3868. }
  3869. if (consumePath) {
  3870. this.consumePath();
  3871. }
  3872. // Restore the global alpha to the fill alpha
  3873. ctx.globalAlpha = this.current.fillAlpha;
  3874. },
  3875. closeStroke: function CanvasGraphics_closeStroke() {
  3876. this.closePath();
  3877. this.stroke();
  3878. },
  3879. fill: function CanvasGraphics_fill(consumePath) {
  3880. consumePath = typeof consumePath !== 'undefined' ? consumePath : true;
  3881. var ctx = this.ctx;
  3882. var fillColor = this.current.fillColor;
  3883. var isPatternFill = this.current.patternFill;
  3884. var needRestore = false;
  3885. if (isPatternFill) {
  3886. ctx.save();
  3887. ctx.fillStyle = fillColor.getPattern(ctx, this);
  3888. needRestore = true;
  3889. }
  3890. if (this.pendingEOFill) {
  3891. if (ctx.mozFillRule !== undefined) {
  3892. ctx.mozFillRule = 'evenodd';
  3893. ctx.fill();
  3894. ctx.mozFillRule = 'nonzero';
  3895. } else {
  3896. try {
  3897. ctx.fill('evenodd');
  3898. } catch (ex) {
  3899. // shouldn't really happen, but browsers might think differently
  3900. ctx.fill();
  3901. }
  3902. }
  3903. this.pendingEOFill = false;
  3904. } else {
  3905. ctx.fill();
  3906. }
  3907. if (needRestore) {
  3908. ctx.restore();
  3909. }
  3910. if (consumePath) {
  3911. this.consumePath();
  3912. }
  3913. },
  3914. eoFill: function CanvasGraphics_eoFill() {
  3915. this.pendingEOFill = true;
  3916. this.fill();
  3917. },
  3918. fillStroke: function CanvasGraphics_fillStroke() {
  3919. this.fill(false);
  3920. this.stroke(false);
  3921. this.consumePath();
  3922. },
  3923. eoFillStroke: function CanvasGraphics_eoFillStroke() {
  3924. this.pendingEOFill = true;
  3925. this.fillStroke();
  3926. },
  3927. closeFillStroke: function CanvasGraphics_closeFillStroke() {
  3928. this.closePath();
  3929. this.fillStroke();
  3930. },
  3931. closeEOFillStroke: function CanvasGraphics_closeEOFillStroke() {
  3932. this.pendingEOFill = true;
  3933. this.closePath();
  3934. this.fillStroke();
  3935. },
  3936. endPath: function CanvasGraphics_endPath() {
  3937. this.consumePath();
  3938. },
  3939. // Clipping
  3940. clip: function CanvasGraphics_clip() {
  3941. this.pendingClip = NORMAL_CLIP;
  3942. },
  3943. eoClip: function CanvasGraphics_eoClip() {
  3944. this.pendingClip = EO_CLIP;
  3945. },
  3946. // Text
  3947. beginText: function CanvasGraphics_beginText() {
  3948. this.current.textMatrix = IDENTITY_MATRIX;
  3949. this.current.textMatrixScale = 1;
  3950. this.current.x = this.current.lineX = 0;
  3951. this.current.y = this.current.lineY = 0;
  3952. },
  3953. endText: function CanvasGraphics_endText() {
  3954. var paths = this.pendingTextPaths;
  3955. var ctx = this.ctx;
  3956. if (paths === undefined) {
  3957. ctx.beginPath();
  3958. return;
  3959. }
  3960. ctx.save();
  3961. ctx.beginPath();
  3962. for (var i = 0; i < paths.length; i++) {
  3963. var path = paths[i];
  3964. ctx.setTransform.apply(ctx, path.transform);
  3965. ctx.translate(path.x, path.y);
  3966. path.addToPath(ctx, path.fontSize);
  3967. }
  3968. ctx.restore();
  3969. ctx.clip();
  3970. ctx.beginPath();
  3971. delete this.pendingTextPaths;
  3972. },
  3973. setCharSpacing: function CanvasGraphics_setCharSpacing(spacing) {
  3974. this.current.charSpacing = spacing;
  3975. },
  3976. setWordSpacing: function CanvasGraphics_setWordSpacing(spacing) {
  3977. this.current.wordSpacing = spacing;
  3978. },
  3979. setHScale: function CanvasGraphics_setHScale(scale) {
  3980. this.current.textHScale = scale / 100;
  3981. },
  3982. setLeading: function CanvasGraphics_setLeading(leading) {
  3983. this.current.leading = -leading;
  3984. },
  3985. setFont: function CanvasGraphics_setFont(fontRefName, size) {
  3986. var fontObj = this.commonObjs.get(fontRefName);
  3987. var current = this.current;
  3988. if (!fontObj) {
  3989. error('Can\'t find font for ' + fontRefName);
  3990. }
  3991. current.fontMatrix = (fontObj.fontMatrix ?
  3992. fontObj.fontMatrix : FONT_IDENTITY_MATRIX);
  3993. // A valid matrix needs all main diagonal elements to be non-zero
  3994. // This also ensures we bypass FF bugzilla bug #719844.
  3995. if (current.fontMatrix[0] === 0 ||
  3996. current.fontMatrix[3] === 0) {
  3997. warn('Invalid font matrix for font ' + fontRefName);
  3998. }
  3999. // The spec for Tf (setFont) says that 'size' specifies the font 'scale',
  4000. // and in some docs this can be negative (inverted x-y axes).
  4001. if (size < 0) {
  4002. size = -size;
  4003. current.fontDirection = -1;
  4004. } else {
  4005. current.fontDirection = 1;
  4006. }
  4007. this.current.font = fontObj;
  4008. this.current.fontSize = size;
  4009. if (fontObj.isType3Font) {
  4010. return; // we don't need ctx.font for Type3 fonts
  4011. }
  4012. var name = fontObj.loadedName || 'sans-serif';
  4013. var bold = fontObj.black ? (fontObj.bold ? 'bolder' : 'bold') :
  4014. (fontObj.bold ? 'bold' : 'normal');
  4015. var italic = fontObj.italic ? 'italic' : 'normal';
  4016. var typeface = '"' + name + '", ' + fontObj.fallbackName;
  4017. // Some font backends cannot handle fonts below certain size.
  4018. // Keeping the font at minimal size and using the fontSizeScale to change
  4019. // the current transformation matrix before the fillText/strokeText.
  4020. // See https://bugzilla.mozilla.org/show_bug.cgi?id=726227
  4021. var browserFontSize = size < MIN_FONT_SIZE ? MIN_FONT_SIZE :
  4022. size > MAX_FONT_SIZE ? MAX_FONT_SIZE : size;
  4023. this.current.fontSizeScale = size / browserFontSize;
  4024. var rule = italic + ' ' + bold + ' ' + browserFontSize + 'px ' + typeface;
  4025. this.ctx.font = rule;
  4026. },
  4027. setTextRenderingMode: function CanvasGraphics_setTextRenderingMode(mode) {
  4028. this.current.textRenderingMode = mode;
  4029. },
  4030. setTextRise: function CanvasGraphics_setTextRise(rise) {
  4031. this.current.textRise = rise;
  4032. },
  4033. moveText: function CanvasGraphics_moveText(x, y) {
  4034. this.current.x = this.current.lineX += x;
  4035. this.current.y = this.current.lineY += y;
  4036. },
  4037. setLeadingMoveText: function CanvasGraphics_setLeadingMoveText(x, y) {
  4038. this.setLeading(-y);
  4039. this.moveText(x, y);
  4040. },
  4041. setTextMatrix: function CanvasGraphics_setTextMatrix(a, b, c, d, e, f) {
  4042. this.current.textMatrix = [a, b, c, d, e, f];
  4043. this.current.textMatrixScale = Math.sqrt(a * a + b * b);
  4044. this.current.x = this.current.lineX = 0;
  4045. this.current.y = this.current.lineY = 0;
  4046. },
  4047. nextLine: function CanvasGraphics_nextLine() {
  4048. this.moveText(0, this.current.leading);
  4049. },
  4050. paintChar: function CanvasGraphics_paintChar(character, x, y) {
  4051. var ctx = this.ctx;
  4052. var current = this.current;
  4053. var font = current.font;
  4054. var textRenderingMode = current.textRenderingMode;
  4055. var fontSize = current.fontSize / current.fontSizeScale;
  4056. var fillStrokeMode = textRenderingMode &
  4057. TextRenderingMode.FILL_STROKE_MASK;
  4058. var isAddToPathSet = !!(textRenderingMode &
  4059. TextRenderingMode.ADD_TO_PATH_FLAG);
  4060. var addToPath;
  4061. if (font.disableFontFace || isAddToPathSet) {
  4062. addToPath = font.getPathGenerator(this.commonObjs, character);
  4063. }
  4064. if (font.disableFontFace) {
  4065. ctx.save();
  4066. ctx.translate(x, y);
  4067. ctx.beginPath();
  4068. addToPath(ctx, fontSize);
  4069. if (fillStrokeMode === TextRenderingMode.FILL ||
  4070. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  4071. ctx.fill();
  4072. }
  4073. if (fillStrokeMode === TextRenderingMode.STROKE ||
  4074. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  4075. ctx.stroke();
  4076. }
  4077. ctx.restore();
  4078. } else {
  4079. if (fillStrokeMode === TextRenderingMode.FILL ||
  4080. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  4081. ctx.fillText(character, x, y);
  4082. }
  4083. if (fillStrokeMode === TextRenderingMode.STROKE ||
  4084. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  4085. ctx.strokeText(character, x, y);
  4086. }
  4087. }
  4088. if (isAddToPathSet) {
  4089. var paths = this.pendingTextPaths || (this.pendingTextPaths = []);
  4090. paths.push({
  4091. transform: ctx.mozCurrentTransform,
  4092. x: x,
  4093. y: y,
  4094. fontSize: fontSize,
  4095. addToPath: addToPath
  4096. });
  4097. }
  4098. },
  4099. get isFontSubpixelAAEnabled() {
  4100. // Checks if anti-aliasing is enabled when scaled text is painted.
  4101. // On Windows GDI scaled fonts looks bad.
  4102. var ctx = document.createElement('canvas').getContext('2d');
  4103. ctx.scale(1.5, 1);
  4104. ctx.fillText('I', 0, 10);
  4105. var data = ctx.getImageData(0, 0, 10, 10).data;
  4106. var enabled = false;
  4107. for (var i = 3; i < data.length; i += 4) {
  4108. if (data[i] > 0 && data[i] < 255) {
  4109. enabled = true;
  4110. break;
  4111. }
  4112. }
  4113. return shadow(this, 'isFontSubpixelAAEnabled', enabled);
  4114. },
  4115. showText: function CanvasGraphics_showText(glyphs) {
  4116. var current = this.current;
  4117. var font = current.font;
  4118. if (font.isType3Font) {
  4119. return this.showType3Text(glyphs);
  4120. }
  4121. var fontSize = current.fontSize;
  4122. if (fontSize === 0) {
  4123. return;
  4124. }
  4125. var ctx = this.ctx;
  4126. var fontSizeScale = current.fontSizeScale;
  4127. var charSpacing = current.charSpacing;
  4128. var wordSpacing = current.wordSpacing;
  4129. var fontDirection = current.fontDirection;
  4130. var textHScale = current.textHScale * fontDirection;
  4131. var glyphsLength = glyphs.length;
  4132. var vertical = font.vertical;
  4133. var defaultVMetrics = font.defaultVMetrics;
  4134. var widthAdvanceScale = fontSize * current.fontMatrix[0];
  4135. var simpleFillText =
  4136. current.textRenderingMode === TextRenderingMode.FILL &&
  4137. !font.disableFontFace;
  4138. ctx.save();
  4139. ctx.transform.apply(ctx, current.textMatrix);
  4140. ctx.translate(current.x, current.y + current.textRise);
  4141. if (fontDirection > 0) {
  4142. ctx.scale(textHScale, -1);
  4143. } else {
  4144. ctx.scale(textHScale, 1);
  4145. }
  4146. var lineWidth = current.lineWidth;
  4147. var scale = current.textMatrixScale;
  4148. if (scale === 0 || lineWidth === 0) {
  4149. var fillStrokeMode = current.textRenderingMode &
  4150. TextRenderingMode.FILL_STROKE_MASK;
  4151. if (fillStrokeMode === TextRenderingMode.STROKE ||
  4152. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  4153. this.cachedGetSinglePixelWidth = null;
  4154. lineWidth = this.getSinglePixelWidth() * MIN_WIDTH_FACTOR;
  4155. }
  4156. } else {
  4157. lineWidth /= scale;
  4158. }
  4159. if (fontSizeScale !== 1.0) {
  4160. ctx.scale(fontSizeScale, fontSizeScale);
  4161. lineWidth /= fontSizeScale;
  4162. }
  4163. ctx.lineWidth = lineWidth;
  4164. var x = 0, i;
  4165. for (i = 0; i < glyphsLength; ++i) {
  4166. var glyph = glyphs[i];
  4167. if (glyph === null) {
  4168. // word break
  4169. x += fontDirection * wordSpacing;
  4170. continue;
  4171. } else if (isNum(glyph)) {
  4172. x += -glyph * fontSize * 0.001;
  4173. continue;
  4174. }
  4175. var restoreNeeded = false;
  4176. var character = glyph.fontChar;
  4177. var accent = glyph.accent;
  4178. var scaledX, scaledY, scaledAccentX, scaledAccentY;
  4179. var width = glyph.width;
  4180. if (vertical) {
  4181. var vmetric, vx, vy;
  4182. vmetric = glyph.vmetric || defaultVMetrics;
  4183. vx = glyph.vmetric ? vmetric[1] : width * 0.5;
  4184. vx = -vx * widthAdvanceScale;
  4185. vy = vmetric[2] * widthAdvanceScale;
  4186. width = vmetric ? -vmetric[0] : width;
  4187. scaledX = vx / fontSizeScale;
  4188. scaledY = (x + vy) / fontSizeScale;
  4189. } else {
  4190. scaledX = x / fontSizeScale;
  4191. scaledY = 0;
  4192. }
  4193. if (font.remeasure && width > 0 && this.isFontSubpixelAAEnabled) {
  4194. // some standard fonts may not have the exact width, trying to
  4195. // rescale per character
  4196. var measuredWidth = ctx.measureText(character).width * 1000 /
  4197. fontSize * fontSizeScale;
  4198. var characterScaleX = width / measuredWidth;
  4199. restoreNeeded = true;
  4200. ctx.save();
  4201. ctx.scale(characterScaleX, 1);
  4202. scaledX /= characterScaleX;
  4203. }
  4204. if (simpleFillText && !accent) {
  4205. // common case
  4206. ctx.fillText(character, scaledX, scaledY);
  4207. } else {
  4208. this.paintChar(character, scaledX, scaledY);
  4209. if (accent) {
  4210. scaledAccentX = scaledX + accent.offset.x / fontSizeScale;
  4211. scaledAccentY = scaledY - accent.offset.y / fontSizeScale;
  4212. this.paintChar(accent.fontChar, scaledAccentX, scaledAccentY);
  4213. }
  4214. }
  4215. var charWidth = width * widthAdvanceScale + charSpacing * fontDirection;
  4216. x += charWidth;
  4217. if (restoreNeeded) {
  4218. ctx.restore();
  4219. }
  4220. }
  4221. if (vertical) {
  4222. current.y -= x * textHScale;
  4223. } else {
  4224. current.x += x * textHScale;
  4225. }
  4226. ctx.restore();
  4227. },
  4228. showType3Text: function CanvasGraphics_showType3Text(glyphs) {
  4229. // Type3 fonts - each glyph is a "mini-PDF"
  4230. var ctx = this.ctx;
  4231. var current = this.current;
  4232. var font = current.font;
  4233. var fontSize = current.fontSize;
  4234. var fontDirection = current.fontDirection;
  4235. var charSpacing = current.charSpacing;
  4236. var wordSpacing = current.wordSpacing;
  4237. var textHScale = current.textHScale * fontDirection;
  4238. var fontMatrix = current.fontMatrix || FONT_IDENTITY_MATRIX;
  4239. var glyphsLength = glyphs.length;
  4240. var isTextInvisible =
  4241. current.textRenderingMode === TextRenderingMode.INVISIBLE;
  4242. var i, glyph, width;
  4243. if (isTextInvisible || fontSize === 0) {
  4244. return;
  4245. }
  4246. ctx.save();
  4247. ctx.transform.apply(ctx, current.textMatrix);
  4248. ctx.translate(current.x, current.y);
  4249. ctx.scale(textHScale, fontDirection);
  4250. for (i = 0; i < glyphsLength; ++i) {
  4251. glyph = glyphs[i];
  4252. if (glyph === null) {
  4253. // word break
  4254. this.ctx.translate(wordSpacing, 0);
  4255. current.x += wordSpacing * textHScale;
  4256. continue;
  4257. } else if (isNum(glyph)) {
  4258. var spacingLength = -glyph * 0.001 * fontSize;
  4259. this.ctx.translate(spacingLength, 0);
  4260. current.x += spacingLength * textHScale;
  4261. continue;
  4262. }
  4263. var operatorList = font.charProcOperatorList[glyph.operatorListId];
  4264. if (!operatorList) {
  4265. warn('Type3 character \"' + glyph.operatorListId +
  4266. '\" is not available');
  4267. continue;
  4268. }
  4269. this.processingType3 = glyph;
  4270. this.save();
  4271. ctx.scale(fontSize, fontSize);
  4272. ctx.transform.apply(ctx, fontMatrix);
  4273. this.executeOperatorList(operatorList);
  4274. this.restore();
  4275. var transformed = Util.applyTransform([glyph.width, 0], fontMatrix);
  4276. width = transformed[0] * fontSize + charSpacing;
  4277. ctx.translate(width, 0);
  4278. current.x += width * textHScale;
  4279. }
  4280. ctx.restore();
  4281. this.processingType3 = null;
  4282. },
  4283. // Type3 fonts
  4284. setCharWidth: function CanvasGraphics_setCharWidth(xWidth, yWidth) {
  4285. // We can safely ignore this since the width should be the same
  4286. // as the width in the Widths array.
  4287. },
  4288. setCharWidthAndBounds: function CanvasGraphics_setCharWidthAndBounds(xWidth,
  4289. yWidth,
  4290. llx,
  4291. lly,
  4292. urx,
  4293. ury) {
  4294. // TODO According to the spec we're also suppose to ignore any operators
  4295. // that set color or include images while processing this type3 font.
  4296. this.ctx.rect(llx, lly, urx - llx, ury - lly);
  4297. this.clip();
  4298. this.endPath();
  4299. },
  4300. // Color
  4301. getColorN_Pattern: function CanvasGraphics_getColorN_Pattern(IR) {
  4302. var pattern;
  4303. if (IR[0] === 'TilingPattern') {
  4304. var color = IR[1];
  4305. pattern = new TilingPattern(IR, color, this.ctx, this.objs,
  4306. this.commonObjs, this.baseTransform);
  4307. } else {
  4308. pattern = getShadingPatternFromIR(IR);
  4309. }
  4310. return pattern;
  4311. },
  4312. setStrokeColorN: function CanvasGraphics_setStrokeColorN(/*...*/) {
  4313. this.current.strokeColor = this.getColorN_Pattern(arguments);
  4314. },
  4315. setFillColorN: function CanvasGraphics_setFillColorN(/*...*/) {
  4316. this.current.fillColor = this.getColorN_Pattern(arguments);
  4317. this.current.patternFill = true;
  4318. },
  4319. setStrokeRGBColor: function CanvasGraphics_setStrokeRGBColor(r, g, b) {
  4320. var color = Util.makeCssRgb(r, g, b);
  4321. this.ctx.strokeStyle = color;
  4322. this.current.strokeColor = color;
  4323. },
  4324. setFillRGBColor: function CanvasGraphics_setFillRGBColor(r, g, b) {
  4325. var color = Util.makeCssRgb(r, g, b);
  4326. this.ctx.fillStyle = color;
  4327. this.current.fillColor = color;
  4328. this.current.patternFill = false;
  4329. },
  4330. shadingFill: function CanvasGraphics_shadingFill(patternIR) {
  4331. var ctx = this.ctx;
  4332. this.save();
  4333. var pattern = getShadingPatternFromIR(patternIR);
  4334. ctx.fillStyle = pattern.getPattern(ctx, this, true);
  4335. var inv = ctx.mozCurrentTransformInverse;
  4336. if (inv) {
  4337. var canvas = ctx.canvas;
  4338. var width = canvas.width;
  4339. var height = canvas.height;
  4340. var bl = Util.applyTransform([0, 0], inv);
  4341. var br = Util.applyTransform([0, height], inv);
  4342. var ul = Util.applyTransform([width, 0], inv);
  4343. var ur = Util.applyTransform([width, height], inv);
  4344. var x0 = Math.min(bl[0], br[0], ul[0], ur[0]);
  4345. var y0 = Math.min(bl[1], br[1], ul[1], ur[1]);
  4346. var x1 = Math.max(bl[0], br[0], ul[0], ur[0]);
  4347. var y1 = Math.max(bl[1], br[1], ul[1], ur[1]);
  4348. this.ctx.fillRect(x0, y0, x1 - x0, y1 - y0);
  4349. } else {
  4350. // HACK to draw the gradient onto an infinite rectangle.
  4351. // PDF gradients are drawn across the entire image while
  4352. // Canvas only allows gradients to be drawn in a rectangle
  4353. // The following bug should allow us to remove this.
  4354. // https://bugzilla.mozilla.org/show_bug.cgi?id=664884
  4355. this.ctx.fillRect(-1e10, -1e10, 2e10, 2e10);
  4356. }
  4357. this.restore();
  4358. },
  4359. // Images
  4360. beginInlineImage: function CanvasGraphics_beginInlineImage() {
  4361. error('Should not call beginInlineImage');
  4362. },
  4363. beginImageData: function CanvasGraphics_beginImageData() {
  4364. error('Should not call beginImageData');
  4365. },
  4366. paintFormXObjectBegin: function CanvasGraphics_paintFormXObjectBegin(matrix,
  4367. bbox) {
  4368. this.save();
  4369. this.baseTransformStack.push(this.baseTransform);
  4370. if (isArray(matrix) && 6 === matrix.length) {
  4371. this.transform.apply(this, matrix);
  4372. }
  4373. this.baseTransform = this.ctx.mozCurrentTransform;
  4374. if (isArray(bbox) && 4 === bbox.length) {
  4375. var width = bbox[2] - bbox[0];
  4376. var height = bbox[3] - bbox[1];
  4377. this.ctx.rect(bbox[0], bbox[1], width, height);
  4378. this.clip();
  4379. this.endPath();
  4380. }
  4381. },
  4382. paintFormXObjectEnd: function CanvasGraphics_paintFormXObjectEnd() {
  4383. this.restore();
  4384. this.baseTransform = this.baseTransformStack.pop();
  4385. },
  4386. beginGroup: function CanvasGraphics_beginGroup(group) {
  4387. this.save();
  4388. var currentCtx = this.ctx;
  4389. // TODO non-isolated groups - according to Rik at adobe non-isolated
  4390. // group results aren't usually that different and they even have tools
  4391. // that ignore this setting. Notes from Rik on implmenting:
  4392. // - When you encounter an transparency group, create a new canvas with
  4393. // the dimensions of the bbox
  4394. // - copy the content from the previous canvas to the new canvas
  4395. // - draw as usual
  4396. // - remove the backdrop alpha:
  4397. // alphaNew = 1 - (1 - alpha)/(1 - alphaBackdrop) with 'alpha' the alpha
  4398. // value of your transparency group and 'alphaBackdrop' the alpha of the
  4399. // backdrop
  4400. // - remove background color:
  4401. // colorNew = color - alphaNew *colorBackdrop /(1 - alphaNew)
  4402. if (!group.isolated) {
  4403. info('TODO: Support non-isolated groups.');
  4404. }
  4405. // TODO knockout - supposedly possible with the clever use of compositing
  4406. // modes.
  4407. if (group.knockout) {
  4408. warn('Knockout groups not supported.');
  4409. }
  4410. var currentTransform = currentCtx.mozCurrentTransform;
  4411. if (group.matrix) {
  4412. currentCtx.transform.apply(currentCtx, group.matrix);
  4413. }
  4414. assert(group.bbox, 'Bounding box is required.');
  4415. // Based on the current transform figure out how big the bounding box
  4416. // will actually be.
  4417. var bounds = Util.getAxialAlignedBoundingBox(
  4418. group.bbox,
  4419. currentCtx.mozCurrentTransform);
  4420. // Clip the bounding box to the current canvas.
  4421. var canvasBounds = [0,
  4422. 0,
  4423. currentCtx.canvas.width,
  4424. currentCtx.canvas.height];
  4425. bounds = Util.intersect(bounds, canvasBounds) || [0, 0, 0, 0];
  4426. // Use ceil in case we're between sizes so we don't create canvas that is
  4427. // too small and make the canvas at least 1x1 pixels.
  4428. var offsetX = Math.floor(bounds[0]);
  4429. var offsetY = Math.floor(bounds[1]);
  4430. var drawnWidth = Math.max(Math.ceil(bounds[2]) - offsetX, 1);
  4431. var drawnHeight = Math.max(Math.ceil(bounds[3]) - offsetY, 1);
  4432. var scaleX = 1, scaleY = 1;
  4433. if (drawnWidth > MAX_GROUP_SIZE) {
  4434. scaleX = drawnWidth / MAX_GROUP_SIZE;
  4435. drawnWidth = MAX_GROUP_SIZE;
  4436. }
  4437. if (drawnHeight > MAX_GROUP_SIZE) {
  4438. scaleY = drawnHeight / MAX_GROUP_SIZE;
  4439. drawnHeight = MAX_GROUP_SIZE;
  4440. }
  4441. var cacheId = 'groupAt' + this.groupLevel;
  4442. if (group.smask) {
  4443. // Using two cache entries is case if masks are used one after another.
  4444. cacheId += '_smask_' + ((this.smaskCounter++) % 2);
  4445. }
  4446. var scratchCanvas = CachedCanvases.getCanvas(
  4447. cacheId, drawnWidth, drawnHeight, true);
  4448. var groupCtx = scratchCanvas.context;
  4449. // Since we created a new canvas that is just the size of the bounding box
  4450. // we have to translate the group ctx.
  4451. groupCtx.scale(1 / scaleX, 1 / scaleY);
  4452. groupCtx.translate(-offsetX, -offsetY);
  4453. groupCtx.transform.apply(groupCtx, currentTransform);
  4454. if (group.smask) {
  4455. // Saving state and cached mask to be used in setGState.
  4456. this.smaskStack.push({
  4457. canvas: scratchCanvas.canvas,
  4458. context: groupCtx,
  4459. offsetX: offsetX,
  4460. offsetY: offsetY,
  4461. scaleX: scaleX,
  4462. scaleY: scaleY,
  4463. subtype: group.smask.subtype,
  4464. backdrop: group.smask.backdrop
  4465. });
  4466. } else {
  4467. // Setup the current ctx so when the group is popped we draw it at the
  4468. // right location.
  4469. currentCtx.setTransform(1, 0, 0, 1, 0, 0);
  4470. currentCtx.translate(offsetX, offsetY);
  4471. currentCtx.scale(scaleX, scaleY);
  4472. }
  4473. // The transparency group inherits all off the current graphics state
  4474. // except the blend mode, soft mask, and alpha constants.
  4475. copyCtxState(currentCtx, groupCtx);
  4476. this.ctx = groupCtx;
  4477. this.setGState([
  4478. ['BM', 'Normal'],
  4479. ['ca', 1],
  4480. ['CA', 1]
  4481. ]);
  4482. this.groupStack.push(currentCtx);
  4483. this.groupLevel++;
  4484. },
  4485. endGroup: function CanvasGraphics_endGroup(group) {
  4486. this.groupLevel--;
  4487. var groupCtx = this.ctx;
  4488. this.ctx = this.groupStack.pop();
  4489. // Turn off image smoothing to avoid sub pixel interpolation which can
  4490. // look kind of blurry for some pdfs.
  4491. if (this.ctx.imageSmoothingEnabled !== undefined) {
  4492. this.ctx.imageSmoothingEnabled = false;
  4493. } else {
  4494. this.ctx.mozImageSmoothingEnabled = false;
  4495. }
  4496. if (group.smask) {
  4497. this.tempSMask = this.smaskStack.pop();
  4498. } else {
  4499. this.ctx.drawImage(groupCtx.canvas, 0, 0);
  4500. }
  4501. this.restore();
  4502. },
  4503. beginAnnotations: function CanvasGraphics_beginAnnotations() {
  4504. this.save();
  4505. this.current = new CanvasExtraState();
  4506. },
  4507. endAnnotations: function CanvasGraphics_endAnnotations() {
  4508. this.restore();
  4509. },
  4510. beginAnnotation: function CanvasGraphics_beginAnnotation(rect, transform,
  4511. matrix) {
  4512. this.save();
  4513. if (isArray(rect) && 4 === rect.length) {
  4514. var width = rect[2] - rect[0];
  4515. var height = rect[3] - rect[1];
  4516. this.ctx.rect(rect[0], rect[1], width, height);
  4517. this.clip();
  4518. this.endPath();
  4519. }
  4520. this.transform.apply(this, transform);
  4521. this.transform.apply(this, matrix);
  4522. },
  4523. endAnnotation: function CanvasGraphics_endAnnotation() {
  4524. this.restore();
  4525. },
  4526. paintJpegXObject: function CanvasGraphics_paintJpegXObject(objId, w, h) {
  4527. var domImage = this.objs.get(objId);
  4528. if (!domImage) {
  4529. warn('Dependent image isn\'t ready yet');
  4530. return;
  4531. }
  4532. this.save();
  4533. var ctx = this.ctx;
  4534. // scale the image to the unit square
  4535. ctx.scale(1 / w, -1 / h);
  4536. ctx.drawImage(domImage, 0, 0, domImage.width, domImage.height,
  4537. 0, -h, w, h);
  4538. if (this.imageLayer) {
  4539. var currentTransform = ctx.mozCurrentTransformInverse;
  4540. var position = this.getCanvasPosition(0, 0);
  4541. this.imageLayer.appendImage({
  4542. objId: objId,
  4543. left: position[0],
  4544. top: position[1],
  4545. width: w / currentTransform[0],
  4546. height: h / currentTransform[3]
  4547. });
  4548. }
  4549. this.restore();
  4550. },
  4551. paintImageMaskXObject: function CanvasGraphics_paintImageMaskXObject(img) {
  4552. var ctx = this.ctx;
  4553. var width = img.width, height = img.height;
  4554. var fillColor = this.current.fillColor;
  4555. var isPatternFill = this.current.patternFill;
  4556. var glyph = this.processingType3;
  4557. if (COMPILE_TYPE3_GLYPHS && glyph && glyph.compiled === undefined) {
  4558. if (width <= MAX_SIZE_TO_COMPILE && height <= MAX_SIZE_TO_COMPILE) {
  4559. glyph.compiled =
  4560. compileType3Glyph({data: img.data, width: width, height: height});
  4561. } else {
  4562. glyph.compiled = null;
  4563. }
  4564. }
  4565. if (glyph && glyph.compiled) {
  4566. glyph.compiled(ctx);
  4567. return;
  4568. }
  4569. var maskCanvas = CachedCanvases.getCanvas('maskCanvas', width, height);
  4570. var maskCtx = maskCanvas.context;
  4571. maskCtx.save();
  4572. putBinaryImageMask(maskCtx, img);
  4573. maskCtx.globalCompositeOperation = 'source-in';
  4574. maskCtx.fillStyle = isPatternFill ?
  4575. fillColor.getPattern(maskCtx, this) : fillColor;
  4576. maskCtx.fillRect(0, 0, width, height);
  4577. maskCtx.restore();
  4578. this.paintInlineImageXObject(maskCanvas.canvas);
  4579. },
  4580. paintImageMaskXObjectRepeat:
  4581. function CanvasGraphics_paintImageMaskXObjectRepeat(imgData, scaleX,
  4582. scaleY, positions) {
  4583. var width = imgData.width;
  4584. var height = imgData.height;
  4585. var fillColor = this.current.fillColor;
  4586. var isPatternFill = this.current.patternFill;
  4587. var maskCanvas = CachedCanvases.getCanvas('maskCanvas', width, height);
  4588. var maskCtx = maskCanvas.context;
  4589. maskCtx.save();
  4590. putBinaryImageMask(maskCtx, imgData);
  4591. maskCtx.globalCompositeOperation = 'source-in';
  4592. maskCtx.fillStyle = isPatternFill ?
  4593. fillColor.getPattern(maskCtx, this) : fillColor;
  4594. maskCtx.fillRect(0, 0, width, height);
  4595. maskCtx.restore();
  4596. var ctx = this.ctx;
  4597. for (var i = 0, ii = positions.length; i < ii; i += 2) {
  4598. ctx.save();
  4599. ctx.transform(scaleX, 0, 0, scaleY, positions[i], positions[i + 1]);
  4600. ctx.scale(1, -1);
  4601. ctx.drawImage(maskCanvas.canvas, 0, 0, width, height,
  4602. 0, -1, 1, 1);
  4603. ctx.restore();
  4604. }
  4605. },
  4606. paintImageMaskXObjectGroup:
  4607. function CanvasGraphics_paintImageMaskXObjectGroup(images) {
  4608. var ctx = this.ctx;
  4609. var fillColor = this.current.fillColor;
  4610. var isPatternFill = this.current.patternFill;
  4611. for (var i = 0, ii = images.length; i < ii; i++) {
  4612. var image = images[i];
  4613. var width = image.width, height = image.height;
  4614. var maskCanvas = CachedCanvases.getCanvas('maskCanvas', width, height);
  4615. var maskCtx = maskCanvas.context;
  4616. maskCtx.save();
  4617. putBinaryImageMask(maskCtx, image);
  4618. maskCtx.globalCompositeOperation = 'source-in';
  4619. maskCtx.fillStyle = isPatternFill ?
  4620. fillColor.getPattern(maskCtx, this) : fillColor;
  4621. maskCtx.fillRect(0, 0, width, height);
  4622. maskCtx.restore();
  4623. ctx.save();
  4624. ctx.transform.apply(ctx, image.transform);
  4625. ctx.scale(1, -1);
  4626. ctx.drawImage(maskCanvas.canvas, 0, 0, width, height,
  4627. 0, -1, 1, 1);
  4628. ctx.restore();
  4629. }
  4630. },
  4631. paintImageXObject: function CanvasGraphics_paintImageXObject(objId) {
  4632. var imgData = this.objs.get(objId);
  4633. if (!imgData) {
  4634. warn('Dependent image isn\'t ready yet');
  4635. return;
  4636. }
  4637. this.paintInlineImageXObject(imgData);
  4638. },
  4639. paintImageXObjectRepeat:
  4640. function CanvasGraphics_paintImageXObjectRepeat(objId, scaleX, scaleY,
  4641. positions) {
  4642. var imgData = this.objs.get(objId);
  4643. if (!imgData) {
  4644. warn('Dependent image isn\'t ready yet');
  4645. return;
  4646. }
  4647. var width = imgData.width;
  4648. var height = imgData.height;
  4649. var map = [];
  4650. for (var i = 0, ii = positions.length; i < ii; i += 2) {
  4651. map.push({transform: [scaleX, 0, 0, scaleY, positions[i],
  4652. positions[i + 1]], x: 0, y: 0, w: width, h: height});
  4653. }
  4654. this.paintInlineImageXObjectGroup(imgData, map);
  4655. },
  4656. paintInlineImageXObject:
  4657. function CanvasGraphics_paintInlineImageXObject(imgData) {
  4658. var width = imgData.width;
  4659. var height = imgData.height;
  4660. var ctx = this.ctx;
  4661. this.save();
  4662. // scale the image to the unit square
  4663. ctx.scale(1 / width, -1 / height);
  4664. var currentTransform = ctx.mozCurrentTransformInverse;
  4665. var a = currentTransform[0], b = currentTransform[1];
  4666. var widthScale = Math.max(Math.sqrt(a * a + b * b), 1);
  4667. var c = currentTransform[2], d = currentTransform[3];
  4668. var heightScale = Math.max(Math.sqrt(c * c + d * d), 1);
  4669. var imgToPaint, tmpCanvas;
  4670. // instanceof HTMLElement does not work in jsdom node.js module
  4671. if (imgData instanceof HTMLElement || !imgData.data) {
  4672. imgToPaint = imgData;
  4673. } else {
  4674. tmpCanvas = CachedCanvases.getCanvas('inlineImage', width, height);
  4675. var tmpCtx = tmpCanvas.context;
  4676. putBinaryImageData(tmpCtx, imgData);
  4677. imgToPaint = tmpCanvas.canvas;
  4678. }
  4679. var paintWidth = width, paintHeight = height;
  4680. var tmpCanvasId = 'prescale1';
  4681. // Vertial or horizontal scaling shall not be more than 2 to not loose the
  4682. // pixels during drawImage operation, painting on the temporary canvas(es)
  4683. // that are twice smaller in size
  4684. while ((widthScale > 2 && paintWidth > 1) ||
  4685. (heightScale > 2 && paintHeight > 1)) {
  4686. var newWidth = paintWidth, newHeight = paintHeight;
  4687. if (widthScale > 2 && paintWidth > 1) {
  4688. newWidth = Math.ceil(paintWidth / 2);
  4689. widthScale /= paintWidth / newWidth;
  4690. }
  4691. if (heightScale > 2 && paintHeight > 1) {
  4692. newHeight = Math.ceil(paintHeight / 2);
  4693. heightScale /= paintHeight / newHeight;
  4694. }
  4695. tmpCanvas = CachedCanvases.getCanvas(tmpCanvasId, newWidth, newHeight);
  4696. tmpCtx = tmpCanvas.context;
  4697. tmpCtx.clearRect(0, 0, newWidth, newHeight);
  4698. tmpCtx.drawImage(imgToPaint, 0, 0, paintWidth, paintHeight,
  4699. 0, 0, newWidth, newHeight);
  4700. imgToPaint = tmpCanvas.canvas;
  4701. paintWidth = newWidth;
  4702. paintHeight = newHeight;
  4703. tmpCanvasId = tmpCanvasId === 'prescale1' ? 'prescale2' : 'prescale1';
  4704. }
  4705. ctx.drawImage(imgToPaint, 0, 0, paintWidth, paintHeight,
  4706. 0, -height, width, height);
  4707. if (this.imageLayer) {
  4708. var position = this.getCanvasPosition(0, -height);
  4709. this.imageLayer.appendImage({
  4710. imgData: imgData,
  4711. left: position[0],
  4712. top: position[1],
  4713. width: width / currentTransform[0],
  4714. height: height / currentTransform[3]
  4715. });
  4716. }
  4717. this.restore();
  4718. },
  4719. paintInlineImageXObjectGroup:
  4720. function CanvasGraphics_paintInlineImageXObjectGroup(imgData, map) {
  4721. var ctx = this.ctx;
  4722. var w = imgData.width;
  4723. var h = imgData.height;
  4724. var tmpCanvas = CachedCanvases.getCanvas('inlineImage', w, h);
  4725. var tmpCtx = tmpCanvas.context;
  4726. putBinaryImageData(tmpCtx, imgData);
  4727. for (var i = 0, ii = map.length; i < ii; i++) {
  4728. var entry = map[i];
  4729. ctx.save();
  4730. ctx.transform.apply(ctx, entry.transform);
  4731. ctx.scale(1, -1);
  4732. ctx.drawImage(tmpCanvas.canvas, entry.x, entry.y, entry.w, entry.h,
  4733. 0, -1, 1, 1);
  4734. if (this.imageLayer) {
  4735. var position = this.getCanvasPosition(entry.x, entry.y);
  4736. this.imageLayer.appendImage({
  4737. imgData: imgData,
  4738. left: position[0],
  4739. top: position[1],
  4740. width: w,
  4741. height: h
  4742. });
  4743. }
  4744. ctx.restore();
  4745. }
  4746. },
  4747. paintSolidColorImageMask:
  4748. function CanvasGraphics_paintSolidColorImageMask() {
  4749. this.ctx.fillRect(0, 0, 1, 1);
  4750. },
  4751. // Marked content
  4752. markPoint: function CanvasGraphics_markPoint(tag) {
  4753. // TODO Marked content.
  4754. },
  4755. markPointProps: function CanvasGraphics_markPointProps(tag, properties) {
  4756. // TODO Marked content.
  4757. },
  4758. beginMarkedContent: function CanvasGraphics_beginMarkedContent(tag) {
  4759. // TODO Marked content.
  4760. },
  4761. beginMarkedContentProps: function CanvasGraphics_beginMarkedContentProps(
  4762. tag, properties) {
  4763. // TODO Marked content.
  4764. },
  4765. endMarkedContent: function CanvasGraphics_endMarkedContent() {
  4766. // TODO Marked content.
  4767. },
  4768. // Compatibility
  4769. beginCompat: function CanvasGraphics_beginCompat() {
  4770. // TODO ignore undefined operators (should we do that anyway?)
  4771. },
  4772. endCompat: function CanvasGraphics_endCompat() {
  4773. // TODO stop ignoring undefined operators
  4774. },
  4775. // Helper functions
  4776. consumePath: function CanvasGraphics_consumePath() {
  4777. var ctx = this.ctx;
  4778. if (this.pendingClip) {
  4779. if (this.pendingClip === EO_CLIP) {
  4780. if (ctx.mozFillRule !== undefined) {
  4781. ctx.mozFillRule = 'evenodd';
  4782. ctx.clip();
  4783. ctx.mozFillRule = 'nonzero';
  4784. } else {
  4785. try {
  4786. ctx.clip('evenodd');
  4787. } catch (ex) {
  4788. // shouldn't really happen, but browsers might think differently
  4789. ctx.clip();
  4790. }
  4791. }
  4792. } else {
  4793. ctx.clip();
  4794. }
  4795. this.pendingClip = null;
  4796. }
  4797. ctx.beginPath();
  4798. },
  4799. getSinglePixelWidth: function CanvasGraphics_getSinglePixelWidth(scale) {
  4800. if (this.cachedGetSinglePixelWidth === null) {
  4801. var inverse = this.ctx.mozCurrentTransformInverse;
  4802. // max of the current horizontal and vertical scale
  4803. this.cachedGetSinglePixelWidth = Math.sqrt(Math.max(
  4804. (inverse[0] * inverse[0] + inverse[1] * inverse[1]),
  4805. (inverse[2] * inverse[2] + inverse[3] * inverse[3])));
  4806. }
  4807. return this.cachedGetSinglePixelWidth;
  4808. },
  4809. getCanvasPosition: function CanvasGraphics_getCanvasPosition(x, y) {
  4810. var transform = this.ctx.mozCurrentTransform;
  4811. return [
  4812. transform[0] * x + transform[2] * y + transform[4],
  4813. transform[1] * x + transform[3] * y + transform[5]
  4814. ];
  4815. }
  4816. };
  4817. for (var op in OPS) {
  4818. CanvasGraphics.prototype[OPS[op]] = CanvasGraphics.prototype[op];
  4819. }
  4820. return CanvasGraphics;
  4821. })();
  4822. var WebGLUtils = (function WebGLUtilsClosure() {
  4823. function loadShader(gl, code, shaderType) {
  4824. var shader = gl.createShader(shaderType);
  4825. gl.shaderSource(shader, code);
  4826. gl.compileShader(shader);
  4827. var compiled = gl.getShaderParameter(shader, gl.COMPILE_STATUS);
  4828. if (!compiled) {
  4829. var errorMsg = gl.getShaderInfoLog(shader);
  4830. throw new Error('Error during shader compilation: ' + errorMsg);
  4831. }
  4832. return shader;
  4833. }
  4834. function createVertexShader(gl, code) {
  4835. return loadShader(gl, code, gl.VERTEX_SHADER);
  4836. }
  4837. function createFragmentShader(gl, code) {
  4838. return loadShader(gl, code, gl.FRAGMENT_SHADER);
  4839. }
  4840. function createProgram(gl, shaders) {
  4841. var program = gl.createProgram();
  4842. for (var i = 0, ii = shaders.length; i < ii; ++i) {
  4843. gl.attachShader(program, shaders[i]);
  4844. }
  4845. gl.linkProgram(program);
  4846. var linked = gl.getProgramParameter(program, gl.LINK_STATUS);
  4847. if (!linked) {
  4848. var errorMsg = gl.getProgramInfoLog(program);
  4849. throw new Error('Error during program linking: ' + errorMsg);
  4850. }
  4851. return program;
  4852. }
  4853. function createTexture(gl, image, textureId) {
  4854. gl.activeTexture(textureId);
  4855. var texture = gl.createTexture();
  4856. gl.bindTexture(gl.TEXTURE_2D, texture);
  4857. // Set the parameters so we can render any size image.
  4858. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
  4859. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
  4860. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
  4861. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
  4862. // Upload the image into the texture.
  4863. gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image);
  4864. return texture;
  4865. }
  4866. var currentGL, currentCanvas;
  4867. function generateGL() {
  4868. if (currentGL) {
  4869. return;
  4870. }
  4871. currentCanvas = document.createElement('canvas');
  4872. currentGL = currentCanvas.getContext('webgl',
  4873. { premultipliedalpha: false });
  4874. }
  4875. var smaskVertexShaderCode = '\
  4876. attribute vec2 a_position; \
  4877. attribute vec2 a_texCoord; \
  4878. \
  4879. uniform vec2 u_resolution; \
  4880. \
  4881. varying vec2 v_texCoord; \
  4882. \
  4883. void main() { \
  4884. vec2 clipSpace = (a_position / u_resolution) * 2.0 - 1.0; \
  4885. gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1); \
  4886. \
  4887. v_texCoord = a_texCoord; \
  4888. } ';
  4889. var smaskFragmentShaderCode = '\
  4890. precision mediump float; \
  4891. \
  4892. uniform vec4 u_backdrop; \
  4893. uniform int u_subtype; \
  4894. uniform sampler2D u_image; \
  4895. uniform sampler2D u_mask; \
  4896. \
  4897. varying vec2 v_texCoord; \
  4898. \
  4899. void main() { \
  4900. vec4 imageColor = texture2D(u_image, v_texCoord); \
  4901. vec4 maskColor = texture2D(u_mask, v_texCoord); \
  4902. if (u_backdrop.a > 0.0) { \
  4903. maskColor.rgb = maskColor.rgb * maskColor.a + \
  4904. u_backdrop.rgb * (1.0 - maskColor.a); \
  4905. } \
  4906. float lum; \
  4907. if (u_subtype == 0) { \
  4908. lum = maskColor.a; \
  4909. } else { \
  4910. lum = maskColor.r * 0.3 + maskColor.g * 0.59 + \
  4911. maskColor.b * 0.11; \
  4912. } \
  4913. imageColor.a *= lum; \
  4914. imageColor.rgb *= imageColor.a; \
  4915. gl_FragColor = imageColor; \
  4916. } ';
  4917. var smaskCache = null;
  4918. function initSmaskGL() {
  4919. var canvas, gl;
  4920. generateGL();
  4921. canvas = currentCanvas;
  4922. currentCanvas = null;
  4923. gl = currentGL;
  4924. currentGL = null;
  4925. // setup a GLSL program
  4926. var vertexShader = createVertexShader(gl, smaskVertexShaderCode);
  4927. var fragmentShader = createFragmentShader(gl, smaskFragmentShaderCode);
  4928. var program = createProgram(gl, [vertexShader, fragmentShader]);
  4929. gl.useProgram(program);
  4930. var cache = {};
  4931. cache.gl = gl;
  4932. cache.canvas = canvas;
  4933. cache.resolutionLocation = gl.getUniformLocation(program, 'u_resolution');
  4934. cache.positionLocation = gl.getAttribLocation(program, 'a_position');
  4935. cache.backdropLocation = gl.getUniformLocation(program, 'u_backdrop');
  4936. cache.subtypeLocation = gl.getUniformLocation(program, 'u_subtype');
  4937. var texCoordLocation = gl.getAttribLocation(program, 'a_texCoord');
  4938. var texLayerLocation = gl.getUniformLocation(program, 'u_image');
  4939. var texMaskLocation = gl.getUniformLocation(program, 'u_mask');
  4940. // provide texture coordinates for the rectangle.
  4941. var texCoordBuffer = gl.createBuffer();
  4942. gl.bindBuffer(gl.ARRAY_BUFFER, texCoordBuffer);
  4943. gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
  4944. 0.0, 0.0,
  4945. 1.0, 0.0,
  4946. 0.0, 1.0,
  4947. 0.0, 1.0,
  4948. 1.0, 0.0,
  4949. 1.0, 1.0]), gl.STATIC_DRAW);
  4950. gl.enableVertexAttribArray(texCoordLocation);
  4951. gl.vertexAttribPointer(texCoordLocation, 2, gl.FLOAT, false, 0, 0);
  4952. gl.uniform1i(texLayerLocation, 0);
  4953. gl.uniform1i(texMaskLocation, 1);
  4954. smaskCache = cache;
  4955. }
  4956. function composeSMask(layer, mask, properties) {
  4957. var width = layer.width, height = layer.height;
  4958. if (!smaskCache) {
  4959. initSmaskGL();
  4960. }
  4961. var cache = smaskCache,canvas = cache.canvas, gl = cache.gl;
  4962. canvas.width = width;
  4963. canvas.height = height;
  4964. gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
  4965. gl.uniform2f(cache.resolutionLocation, width, height);
  4966. if (properties.backdrop) {
  4967. gl.uniform4f(cache.resolutionLocation, properties.backdrop[0],
  4968. properties.backdrop[1], properties.backdrop[2], 1);
  4969. } else {
  4970. gl.uniform4f(cache.resolutionLocation, 0, 0, 0, 0);
  4971. }
  4972. gl.uniform1i(cache.subtypeLocation,
  4973. properties.subtype === 'Luminosity' ? 1 : 0);
  4974. // Create a textures
  4975. var texture = createTexture(gl, layer, gl.TEXTURE0);
  4976. var maskTexture = createTexture(gl, mask, gl.TEXTURE1);
  4977. // Create a buffer and put a single clipspace rectangle in
  4978. // it (2 triangles)
  4979. var buffer = gl.createBuffer();
  4980. gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
  4981. gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
  4982. 0, 0,
  4983. width, 0,
  4984. 0, height,
  4985. 0, height,
  4986. width, 0,
  4987. width, height]), gl.STATIC_DRAW);
  4988. gl.enableVertexAttribArray(cache.positionLocation);
  4989. gl.vertexAttribPointer(cache.positionLocation, 2, gl.FLOAT, false, 0, 0);
  4990. // draw
  4991. gl.clearColor(0, 0, 0, 0);
  4992. gl.enable(gl.BLEND);
  4993. gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
  4994. gl.clear(gl.COLOR_BUFFER_BIT);
  4995. gl.drawArrays(gl.TRIANGLES, 0, 6);
  4996. gl.flush();
  4997. gl.deleteTexture(texture);
  4998. gl.deleteTexture(maskTexture);
  4999. gl.deleteBuffer(buffer);
  5000. return canvas;
  5001. }
  5002. var figuresVertexShaderCode = '\
  5003. attribute vec2 a_position; \
  5004. attribute vec3 a_color; \
  5005. \
  5006. uniform vec2 u_resolution; \
  5007. uniform vec2 u_scale; \
  5008. uniform vec2 u_offset; \
  5009. \
  5010. varying vec4 v_color; \
  5011. \
  5012. void main() { \
  5013. vec2 position = (a_position + u_offset) * u_scale; \
  5014. vec2 clipSpace = (position / u_resolution) * 2.0 - 1.0; \
  5015. gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1); \
  5016. \
  5017. v_color = vec4(a_color / 255.0, 1.0); \
  5018. } ';
  5019. var figuresFragmentShaderCode = '\
  5020. precision mediump float; \
  5021. \
  5022. varying vec4 v_color; \
  5023. \
  5024. void main() { \
  5025. gl_FragColor = v_color; \
  5026. } ';
  5027. var figuresCache = null;
  5028. function initFiguresGL() {
  5029. var canvas, gl;
  5030. generateGL();
  5031. canvas = currentCanvas;
  5032. currentCanvas = null;
  5033. gl = currentGL;
  5034. currentGL = null;
  5035. // setup a GLSL program
  5036. var vertexShader = createVertexShader(gl, figuresVertexShaderCode);
  5037. var fragmentShader = createFragmentShader(gl, figuresFragmentShaderCode);
  5038. var program = createProgram(gl, [vertexShader, fragmentShader]);
  5039. gl.useProgram(program);
  5040. var cache = {};
  5041. cache.gl = gl;
  5042. cache.canvas = canvas;
  5043. cache.resolutionLocation = gl.getUniformLocation(program, 'u_resolution');
  5044. cache.scaleLocation = gl.getUniformLocation(program, 'u_scale');
  5045. cache.offsetLocation = gl.getUniformLocation(program, 'u_offset');
  5046. cache.positionLocation = gl.getAttribLocation(program, 'a_position');
  5047. cache.colorLocation = gl.getAttribLocation(program, 'a_color');
  5048. figuresCache = cache;
  5049. }
  5050. function drawFigures(width, height, backgroundColor, figures, context) {
  5051. if (!figuresCache) {
  5052. initFiguresGL();
  5053. }
  5054. var cache = figuresCache, canvas = cache.canvas, gl = cache.gl;
  5055. canvas.width = width;
  5056. canvas.height = height;
  5057. gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
  5058. gl.uniform2f(cache.resolutionLocation, width, height);
  5059. // count triangle points
  5060. var count = 0;
  5061. var i, ii, rows;
  5062. for (i = 0, ii = figures.length; i < ii; i++) {
  5063. switch (figures[i].type) {
  5064. case 'lattice':
  5065. rows = (figures[i].coords.length / figures[i].verticesPerRow) | 0;
  5066. count += (rows - 1) * (figures[i].verticesPerRow - 1) * 6;
  5067. break;
  5068. case 'triangles':
  5069. count += figures[i].coords.length;
  5070. break;
  5071. }
  5072. }
  5073. // transfer data
  5074. var coords = new Float32Array(count * 2);
  5075. var colors = new Uint8Array(count * 3);
  5076. var coordsMap = context.coords, colorsMap = context.colors;
  5077. var pIndex = 0, cIndex = 0;
  5078. for (i = 0, ii = figures.length; i < ii; i++) {
  5079. var figure = figures[i], ps = figure.coords, cs = figure.colors;
  5080. switch (figure.type) {
  5081. case 'lattice':
  5082. var cols = figure.verticesPerRow;
  5083. rows = (ps.length / cols) | 0;
  5084. for (var row = 1; row < rows; row++) {
  5085. var offset = row * cols + 1;
  5086. for (var col = 1; col < cols; col++, offset++) {
  5087. coords[pIndex] = coordsMap[ps[offset - cols - 1]];
  5088. coords[pIndex + 1] = coordsMap[ps[offset - cols - 1] + 1];
  5089. coords[pIndex + 2] = coordsMap[ps[offset - cols]];
  5090. coords[pIndex + 3] = coordsMap[ps[offset - cols] + 1];
  5091. coords[pIndex + 4] = coordsMap[ps[offset - 1]];
  5092. coords[pIndex + 5] = coordsMap[ps[offset - 1] + 1];
  5093. colors[cIndex] = colorsMap[cs[offset - cols - 1]];
  5094. colors[cIndex + 1] = colorsMap[cs[offset - cols - 1] + 1];
  5095. colors[cIndex + 2] = colorsMap[cs[offset - cols - 1] + 2];
  5096. colors[cIndex + 3] = colorsMap[cs[offset - cols]];
  5097. colors[cIndex + 4] = colorsMap[cs[offset - cols] + 1];
  5098. colors[cIndex + 5] = colorsMap[cs[offset - cols] + 2];
  5099. colors[cIndex + 6] = colorsMap[cs[offset - 1]];
  5100. colors[cIndex + 7] = colorsMap[cs[offset - 1] + 1];
  5101. colors[cIndex + 8] = colorsMap[cs[offset - 1] + 2];
  5102. coords[pIndex + 6] = coords[pIndex + 2];
  5103. coords[pIndex + 7] = coords[pIndex + 3];
  5104. coords[pIndex + 8] = coords[pIndex + 4];
  5105. coords[pIndex + 9] = coords[pIndex + 5];
  5106. coords[pIndex + 10] = coordsMap[ps[offset]];
  5107. coords[pIndex + 11] = coordsMap[ps[offset] + 1];
  5108. colors[cIndex + 9] = colors[cIndex + 3];
  5109. colors[cIndex + 10] = colors[cIndex + 4];
  5110. colors[cIndex + 11] = colors[cIndex + 5];
  5111. colors[cIndex + 12] = colors[cIndex + 6];
  5112. colors[cIndex + 13] = colors[cIndex + 7];
  5113. colors[cIndex + 14] = colors[cIndex + 8];
  5114. colors[cIndex + 15] = colorsMap[cs[offset]];
  5115. colors[cIndex + 16] = colorsMap[cs[offset] + 1];
  5116. colors[cIndex + 17] = colorsMap[cs[offset] + 2];
  5117. pIndex += 12;
  5118. cIndex += 18;
  5119. }
  5120. }
  5121. break;
  5122. case 'triangles':
  5123. for (var j = 0, jj = ps.length; j < jj; j++) {
  5124. coords[pIndex] = coordsMap[ps[j]];
  5125. coords[pIndex + 1] = coordsMap[ps[j] + 1];
  5126. colors[cIndex] = colorsMap[cs[i]];
  5127. colors[cIndex + 1] = colorsMap[cs[j] + 1];
  5128. colors[cIndex + 2] = colorsMap[cs[j] + 2];
  5129. pIndex += 2;
  5130. cIndex += 3;
  5131. }
  5132. break;
  5133. }
  5134. }
  5135. // draw
  5136. if (backgroundColor) {
  5137. gl.clearColor(backgroundColor[0] / 255, backgroundColor[1] / 255,
  5138. backgroundColor[2] / 255, 1.0);
  5139. } else {
  5140. gl.clearColor(0, 0, 0, 0);
  5141. }
  5142. gl.clear(gl.COLOR_BUFFER_BIT);
  5143. var coordsBuffer = gl.createBuffer();
  5144. gl.bindBuffer(gl.ARRAY_BUFFER, coordsBuffer);
  5145. gl.bufferData(gl.ARRAY_BUFFER, coords, gl.STATIC_DRAW);
  5146. gl.enableVertexAttribArray(cache.positionLocation);
  5147. gl.vertexAttribPointer(cache.positionLocation, 2, gl.FLOAT, false, 0, 0);
  5148. var colorsBuffer = gl.createBuffer();
  5149. gl.bindBuffer(gl.ARRAY_BUFFER, colorsBuffer);
  5150. gl.bufferData(gl.ARRAY_BUFFER, colors, gl.STATIC_DRAW);
  5151. gl.enableVertexAttribArray(cache.colorLocation);
  5152. gl.vertexAttribPointer(cache.colorLocation, 3, gl.UNSIGNED_BYTE, false,
  5153. 0, 0);
  5154. gl.uniform2f(cache.scaleLocation, context.scaleX, context.scaleY);
  5155. gl.uniform2f(cache.offsetLocation, context.offsetX, context.offsetY);
  5156. gl.drawArrays(gl.TRIANGLES, 0, count);
  5157. gl.flush();
  5158. gl.deleteBuffer(coordsBuffer);
  5159. gl.deleteBuffer(colorsBuffer);
  5160. return canvas;
  5161. }
  5162. function cleanup() {
  5163. if (smaskCache && smaskCache.canvas) {
  5164. smaskCache.canvas.width = 0;
  5165. smaskCache.canvas.height = 0;
  5166. }
  5167. if (figuresCache && figuresCache.canvas) {
  5168. figuresCache.canvas.width = 0;
  5169. figuresCache.canvas.height = 0;
  5170. }
  5171. smaskCache = null;
  5172. figuresCache = null;
  5173. }
  5174. return {
  5175. get isEnabled() {
  5176. if (PDFJS.disableWebGL) {
  5177. return false;
  5178. }
  5179. var enabled = false;
  5180. try {
  5181. generateGL();
  5182. enabled = !!currentGL;
  5183. } catch (e) { }
  5184. return shadow(this, 'isEnabled', enabled);
  5185. },
  5186. composeSMask: composeSMask,
  5187. drawFigures: drawFigures,
  5188. clear: cleanup
  5189. };
  5190. })();
  5191. var ShadingIRs = {};
  5192. ShadingIRs.RadialAxial = {
  5193. fromIR: function RadialAxial_fromIR(raw) {
  5194. var type = raw[1];
  5195. var colorStops = raw[2];
  5196. var p0 = raw[3];
  5197. var p1 = raw[4];
  5198. var r0 = raw[5];
  5199. var r1 = raw[6];
  5200. return {
  5201. type: 'Pattern',
  5202. getPattern: function RadialAxial_getPattern(ctx) {
  5203. var grad;
  5204. if (type === 'axial') {
  5205. grad = ctx.createLinearGradient(p0[0], p0[1], p1[0], p1[1]);
  5206. } else if (type === 'radial') {
  5207. grad = ctx.createRadialGradient(p0[0], p0[1], r0, p1[0], p1[1], r1);
  5208. }
  5209. for (var i = 0, ii = colorStops.length; i < ii; ++i) {
  5210. var c = colorStops[i];
  5211. grad.addColorStop(c[0], c[1]);
  5212. }
  5213. return grad;
  5214. }
  5215. };
  5216. }
  5217. };
  5218. var createMeshCanvas = (function createMeshCanvasClosure() {
  5219. function drawTriangle(data, context, p1, p2, p3, c1, c2, c3) {
  5220. // Very basic Gouraud-shaded triangle rasterization algorithm.
  5221. var coords = context.coords, colors = context.colors;
  5222. var bytes = data.data, rowSize = data.width * 4;
  5223. var tmp;
  5224. if (coords[p1 + 1] > coords[p2 + 1]) {
  5225. tmp = p1; p1 = p2; p2 = tmp; tmp = c1; c1 = c2; c2 = tmp;
  5226. }
  5227. if (coords[p2 + 1] > coords[p3 + 1]) {
  5228. tmp = p2; p2 = p3; p3 = tmp; tmp = c2; c2 = c3; c3 = tmp;
  5229. }
  5230. if (coords[p1 + 1] > coords[p2 + 1]) {
  5231. tmp = p1; p1 = p2; p2 = tmp; tmp = c1; c1 = c2; c2 = tmp;
  5232. }
  5233. var x1 = (coords[p1] + context.offsetX) * context.scaleX;
  5234. var y1 = (coords[p1 + 1] + context.offsetY) * context.scaleY;
  5235. var x2 = (coords[p2] + context.offsetX) * context.scaleX;
  5236. var y2 = (coords[p2 + 1] + context.offsetY) * context.scaleY;
  5237. var x3 = (coords[p3] + context.offsetX) * context.scaleX;
  5238. var y3 = (coords[p3 + 1] + context.offsetY) * context.scaleY;
  5239. if (y1 >= y3) {
  5240. return;
  5241. }
  5242. var c1r = colors[c1], c1g = colors[c1 + 1], c1b = colors[c1 + 2];
  5243. var c2r = colors[c2], c2g = colors[c2 + 1], c2b = colors[c2 + 2];
  5244. var c3r = colors[c3], c3g = colors[c3 + 1], c3b = colors[c3 + 2];
  5245. var minY = Math.round(y1), maxY = Math.round(y3);
  5246. var xa, car, cag, cab;
  5247. var xb, cbr, cbg, cbb;
  5248. var k;
  5249. for (var y = minY; y <= maxY; y++) {
  5250. if (y < y2) {
  5251. k = y < y1 ? 0 : y1 === y2 ? 1 : (y1 - y) / (y1 - y2);
  5252. xa = x1 - (x1 - x2) * k;
  5253. car = c1r - (c1r - c2r) * k;
  5254. cag = c1g - (c1g - c2g) * k;
  5255. cab = c1b - (c1b - c2b) * k;
  5256. } else {
  5257. k = y > y3 ? 1 : y2 === y3 ? 0 : (y2 - y) / (y2 - y3);
  5258. xa = x2 - (x2 - x3) * k;
  5259. car = c2r - (c2r - c3r) * k;
  5260. cag = c2g - (c2g - c3g) * k;
  5261. cab = c2b - (c2b - c3b) * k;
  5262. }
  5263. k = y < y1 ? 0 : y > y3 ? 1 : (y1 - y) / (y1 - y3);
  5264. xb = x1 - (x1 - x3) * k;
  5265. cbr = c1r - (c1r - c3r) * k;
  5266. cbg = c1g - (c1g - c3g) * k;
  5267. cbb = c1b - (c1b - c3b) * k;
  5268. var x1_ = Math.round(Math.min(xa, xb));
  5269. var x2_ = Math.round(Math.max(xa, xb));
  5270. var j = rowSize * y + x1_ * 4;
  5271. for (var x = x1_; x <= x2_; x++) {
  5272. k = (xa - x) / (xa - xb);
  5273. k = k < 0 ? 0 : k > 1 ? 1 : k;
  5274. bytes[j++] = (car - (car - cbr) * k) | 0;
  5275. bytes[j++] = (cag - (cag - cbg) * k) | 0;
  5276. bytes[j++] = (cab - (cab - cbb) * k) | 0;
  5277. bytes[j++] = 255;
  5278. }
  5279. }
  5280. }
  5281. function drawFigure(data, figure, context) {
  5282. var ps = figure.coords;
  5283. var cs = figure.colors;
  5284. var i, ii;
  5285. switch (figure.type) {
  5286. case 'lattice':
  5287. var verticesPerRow = figure.verticesPerRow;
  5288. var rows = Math.floor(ps.length / verticesPerRow) - 1;
  5289. var cols = verticesPerRow - 1;
  5290. for (i = 0; i < rows; i++) {
  5291. var q = i * verticesPerRow;
  5292. for (var j = 0; j < cols; j++, q++) {
  5293. drawTriangle(data, context,
  5294. ps[q], ps[q + 1], ps[q + verticesPerRow],
  5295. cs[q], cs[q + 1], cs[q + verticesPerRow]);
  5296. drawTriangle(data, context,
  5297. ps[q + verticesPerRow + 1], ps[q + 1], ps[q + verticesPerRow],
  5298. cs[q + verticesPerRow + 1], cs[q + 1], cs[q + verticesPerRow]);
  5299. }
  5300. }
  5301. break;
  5302. case 'triangles':
  5303. for (i = 0, ii = ps.length; i < ii; i += 3) {
  5304. drawTriangle(data, context,
  5305. ps[i], ps[i + 1], ps[i + 2],
  5306. cs[i], cs[i + 1], cs[i + 2]);
  5307. }
  5308. break;
  5309. default:
  5310. error('illigal figure');
  5311. break;
  5312. }
  5313. }
  5314. function createMeshCanvas(bounds, combinesScale, coords, colors, figures,
  5315. backgroundColor) {
  5316. // we will increase scale on some weird factor to let antialiasing take
  5317. // care of "rough" edges
  5318. var EXPECTED_SCALE = 1.1;
  5319. // MAX_PATTERN_SIZE is used to avoid OOM situation.
  5320. var MAX_PATTERN_SIZE = 3000; // 10in @ 300dpi shall be enough
  5321. var offsetX = Math.floor(bounds[0]);
  5322. var offsetY = Math.floor(bounds[1]);
  5323. var boundsWidth = Math.ceil(bounds[2]) - offsetX;
  5324. var boundsHeight = Math.ceil(bounds[3]) - offsetY;
  5325. var width = Math.min(Math.ceil(Math.abs(boundsWidth * combinesScale[0] *
  5326. EXPECTED_SCALE)), MAX_PATTERN_SIZE);
  5327. var height = Math.min(Math.ceil(Math.abs(boundsHeight * combinesScale[1] *
  5328. EXPECTED_SCALE)), MAX_PATTERN_SIZE);
  5329. var scaleX = boundsWidth / width;
  5330. var scaleY = boundsHeight / height;
  5331. var context = {
  5332. coords: coords,
  5333. colors: colors,
  5334. offsetX: -offsetX,
  5335. offsetY: -offsetY,
  5336. scaleX: 1 / scaleX,
  5337. scaleY: 1 / scaleY
  5338. };
  5339. var canvas, tmpCanvas, i, ii;
  5340. if (WebGLUtils.isEnabled) {
  5341. canvas = WebGLUtils.drawFigures(width, height, backgroundColor,
  5342. figures, context);
  5343. // https://bugzilla.mozilla.org/show_bug.cgi?id=972126
  5344. tmpCanvas = CachedCanvases.getCanvas('mesh', width, height, false);
  5345. tmpCanvas.context.drawImage(canvas, 0, 0);
  5346. canvas = tmpCanvas.canvas;
  5347. } else {
  5348. tmpCanvas = CachedCanvases.getCanvas('mesh', width, height, false);
  5349. var tmpCtx = tmpCanvas.context;
  5350. var data = tmpCtx.createImageData(width, height);
  5351. if (backgroundColor) {
  5352. var bytes = data.data;
  5353. for (i = 0, ii = bytes.length; i < ii; i += 4) {
  5354. bytes[i] = backgroundColor[0];
  5355. bytes[i + 1] = backgroundColor[1];
  5356. bytes[i + 2] = backgroundColor[2];
  5357. bytes[i + 3] = 255;
  5358. }
  5359. }
  5360. for (i = 0; i < figures.length; i++) {
  5361. drawFigure(data, figures[i], context);
  5362. }
  5363. tmpCtx.putImageData(data, 0, 0);
  5364. canvas = tmpCanvas.canvas;
  5365. }
  5366. return {canvas: canvas, offsetX: offsetX, offsetY: offsetY,
  5367. scaleX: scaleX, scaleY: scaleY};
  5368. }
  5369. return createMeshCanvas;
  5370. })();
  5371. ShadingIRs.Mesh = {
  5372. fromIR: function Mesh_fromIR(raw) {
  5373. //var type = raw[1];
  5374. var coords = raw[2];
  5375. var colors = raw[3];
  5376. var figures = raw[4];
  5377. var bounds = raw[5];
  5378. var matrix = raw[6];
  5379. //var bbox = raw[7];
  5380. var background = raw[8];
  5381. return {
  5382. type: 'Pattern',
  5383. getPattern: function Mesh_getPattern(ctx, owner, shadingFill) {
  5384. var scale;
  5385. if (shadingFill) {
  5386. scale = Util.singularValueDecompose2dScale(ctx.mozCurrentTransform);
  5387. } else {
  5388. // Obtain scale from matrix and current transformation matrix.
  5389. scale = Util.singularValueDecompose2dScale(owner.baseTransform);
  5390. if (matrix) {
  5391. var matrixScale = Util.singularValueDecompose2dScale(matrix);
  5392. scale = [scale[0] * matrixScale[0],
  5393. scale[1] * matrixScale[1]];
  5394. }
  5395. }
  5396. // Rasterizing on the main thread since sending/queue large canvases
  5397. // might cause OOM.
  5398. var temporaryPatternCanvas = createMeshCanvas(bounds, scale, coords,
  5399. colors, figures, shadingFill ? null : background);
  5400. if (!shadingFill) {
  5401. ctx.setTransform.apply(ctx, owner.baseTransform);
  5402. if (matrix) {
  5403. ctx.transform.apply(ctx, matrix);
  5404. }
  5405. }
  5406. ctx.translate(temporaryPatternCanvas.offsetX,
  5407. temporaryPatternCanvas.offsetY);
  5408. ctx.scale(temporaryPatternCanvas.scaleX,
  5409. temporaryPatternCanvas.scaleY);
  5410. return ctx.createPattern(temporaryPatternCanvas.canvas, 'no-repeat');
  5411. }
  5412. };
  5413. }
  5414. };
  5415. ShadingIRs.Dummy = {
  5416. fromIR: function Dummy_fromIR() {
  5417. return {
  5418. type: 'Pattern',
  5419. getPattern: function Dummy_fromIR_getPattern() {
  5420. return 'hotpink';
  5421. }
  5422. };
  5423. }
  5424. };
  5425. function getShadingPatternFromIR(raw) {
  5426. var shadingIR = ShadingIRs[raw[0]];
  5427. if (!shadingIR) {
  5428. error('Unknown IR type: ' + raw[0]);
  5429. }
  5430. return shadingIR.fromIR(raw);
  5431. }
  5432. var TilingPattern = (function TilingPatternClosure() {
  5433. var PaintType = {
  5434. COLORED: 1,
  5435. UNCOLORED: 2
  5436. };
  5437. var MAX_PATTERN_SIZE = 3000; // 10in @ 300dpi shall be enough
  5438. function TilingPattern(IR, color, ctx, objs, commonObjs, baseTransform) {
  5439. this.operatorList = IR[2];
  5440. this.matrix = IR[3] || [1, 0, 0, 1, 0, 0];
  5441. this.bbox = IR[4];
  5442. this.xstep = IR[5];
  5443. this.ystep = IR[6];
  5444. this.paintType = IR[7];
  5445. this.tilingType = IR[8];
  5446. this.color = color;
  5447. this.objs = objs;
  5448. this.commonObjs = commonObjs;
  5449. this.baseTransform = baseTransform;
  5450. this.type = 'Pattern';
  5451. this.ctx = ctx;
  5452. }
  5453. TilingPattern.prototype = {
  5454. createPatternCanvas: function TilinPattern_createPatternCanvas(owner) {
  5455. var operatorList = this.operatorList;
  5456. var bbox = this.bbox;
  5457. var xstep = this.xstep;
  5458. var ystep = this.ystep;
  5459. var paintType = this.paintType;
  5460. var tilingType = this.tilingType;
  5461. var color = this.color;
  5462. var objs = this.objs;
  5463. var commonObjs = this.commonObjs;
  5464. info('TilingType: ' + tilingType);
  5465. var x0 = bbox[0], y0 = bbox[1], x1 = bbox[2], y1 = bbox[3];
  5466. var topLeft = [x0, y0];
  5467. // we want the canvas to be as large as the step size
  5468. var botRight = [x0 + xstep, y0 + ystep];
  5469. var width = botRight[0] - topLeft[0];
  5470. var height = botRight[1] - topLeft[1];
  5471. // Obtain scale from matrix and current transformation matrix.
  5472. var matrixScale = Util.singularValueDecompose2dScale(this.matrix);
  5473. var curMatrixScale = Util.singularValueDecompose2dScale(
  5474. this.baseTransform);
  5475. var combinedScale = [matrixScale[0] * curMatrixScale[0],
  5476. matrixScale[1] * curMatrixScale[1]];
  5477. // MAX_PATTERN_SIZE is used to avoid OOM situation.
  5478. // Use width and height values that are as close as possible to the end
  5479. // result when the pattern is used. Too low value makes the pattern look
  5480. // blurry. Too large value makes it look too crispy.
  5481. width = Math.min(Math.ceil(Math.abs(width * combinedScale[0])),
  5482. MAX_PATTERN_SIZE);
  5483. height = Math.min(Math.ceil(Math.abs(height * combinedScale[1])),
  5484. MAX_PATTERN_SIZE);
  5485. var tmpCanvas = CachedCanvases.getCanvas('pattern', width, height, true);
  5486. var tmpCtx = tmpCanvas.context;
  5487. var graphics = new CanvasGraphics(tmpCtx, commonObjs, objs);
  5488. graphics.groupLevel = owner.groupLevel;
  5489. this.setFillAndStrokeStyleToContext(tmpCtx, paintType, color);
  5490. this.setScale(width, height, xstep, ystep);
  5491. this.transformToScale(graphics);
  5492. // transform coordinates to pattern space
  5493. var tmpTranslate = [1, 0, 0, 1, -topLeft[0], -topLeft[1]];
  5494. graphics.transform.apply(graphics, tmpTranslate);
  5495. this.clipBbox(graphics, bbox, x0, y0, x1, y1);
  5496. graphics.executeOperatorList(operatorList);
  5497. return tmpCanvas.canvas;
  5498. },
  5499. setScale: function TilingPattern_setScale(width, height, xstep, ystep) {
  5500. this.scale = [width / xstep, height / ystep];
  5501. },
  5502. transformToScale: function TilingPattern_transformToScale(graphics) {
  5503. var scale = this.scale;
  5504. var tmpScale = [scale[0], 0, 0, scale[1], 0, 0];
  5505. graphics.transform.apply(graphics, tmpScale);
  5506. },
  5507. scaleToContext: function TilingPattern_scaleToContext() {
  5508. var scale = this.scale;
  5509. this.ctx.scale(1 / scale[0], 1 / scale[1]);
  5510. },
  5511. clipBbox: function clipBbox(graphics, bbox, x0, y0, x1, y1) {
  5512. if (bbox && isArray(bbox) && bbox.length === 4) {
  5513. var bboxWidth = x1 - x0;
  5514. var bboxHeight = y1 - y0;
  5515. graphics.ctx.rect(x0, y0, bboxWidth, bboxHeight);
  5516. graphics.clip();
  5517. graphics.endPath();
  5518. }
  5519. },
  5520. setFillAndStrokeStyleToContext:
  5521. function setFillAndStrokeStyleToContext(context, paintType, color) {
  5522. switch (paintType) {
  5523. case PaintType.COLORED:
  5524. var ctx = this.ctx;
  5525. context.fillStyle = ctx.fillStyle;
  5526. context.strokeStyle = ctx.strokeStyle;
  5527. break;
  5528. case PaintType.UNCOLORED:
  5529. var cssColor = Util.makeCssRgb(color[0], color[1], color[2]);
  5530. context.fillStyle = cssColor;
  5531. context.strokeStyle = cssColor;
  5532. break;
  5533. default:
  5534. error('Unsupported paint type: ' + paintType);
  5535. }
  5536. },
  5537. getPattern: function TilingPattern_getPattern(ctx, owner) {
  5538. var temporaryPatternCanvas = this.createPatternCanvas(owner);
  5539. ctx = this.ctx;
  5540. ctx.setTransform.apply(ctx, this.baseTransform);
  5541. ctx.transform.apply(ctx, this.matrix);
  5542. this.scaleToContext();
  5543. return ctx.createPattern(temporaryPatternCanvas, 'repeat');
  5544. }
  5545. };
  5546. return TilingPattern;
  5547. })();
  5548. PDFJS.disableFontFace = false;
  5549. var FontLoader = {
  5550. insertRule: function fontLoaderInsertRule(rule) {
  5551. var styleElement = document.getElementById('PDFJS_FONT_STYLE_TAG');
  5552. if (!styleElement) {
  5553. styleElement = document.createElement('style');
  5554. styleElement.id = 'PDFJS_FONT_STYLE_TAG';
  5555. document.documentElement.getElementsByTagName('head')[0].appendChild(
  5556. styleElement);
  5557. }
  5558. var styleSheet = styleElement.sheet;
  5559. styleSheet.insertRule(rule, styleSheet.cssRules.length);
  5560. },
  5561. clear: function fontLoaderClear() {
  5562. var styleElement = document.getElementById('PDFJS_FONT_STYLE_TAG');
  5563. if (styleElement) {
  5564. styleElement.parentNode.removeChild(styleElement);
  5565. }
  5566. this.nativeFontFaces.forEach(function(nativeFontFace) {
  5567. document.fonts.delete(nativeFontFace);
  5568. });
  5569. this.nativeFontFaces.length = 0;
  5570. },
  5571. get loadTestFont() {
  5572. // This is a CFF font with 1 glyph for '.' that fills its entire width and
  5573. // height.
  5574. return shadow(this, 'loadTestFont', atob(
  5575. 'T1RUTwALAIAAAwAwQ0ZGIDHtZg4AAAOYAAAAgUZGVE1lkzZwAAAEHAAAABxHREVGABQAFQ' +
  5576. 'AABDgAAAAeT1MvMlYNYwkAAAEgAAAAYGNtYXABDQLUAAACNAAAAUJoZWFk/xVFDQAAALwA' +
  5577. 'AAA2aGhlYQdkA+oAAAD0AAAAJGhtdHgD6AAAAAAEWAAAAAZtYXhwAAJQAAAAARgAAAAGbm' +
  5578. 'FtZVjmdH4AAAGAAAAAsXBvc3T/hgAzAAADeAAAACAAAQAAAAEAALZRFsRfDzz1AAsD6AAA' +
  5579. 'AADOBOTLAAAAAM4KHDwAAAAAA+gDIQAAAAgAAgAAAAAAAAABAAADIQAAAFoD6AAAAAAD6A' +
  5580. 'ABAAAAAAAAAAAAAAAAAAAAAQAAUAAAAgAAAAQD6AH0AAUAAAKKArwAAACMAooCvAAAAeAA' +
  5581. 'MQECAAACAAYJAAAAAAAAAAAAAQAAAAAAAAAAAAAAAFBmRWQAwAAuAC4DIP84AFoDIQAAAA' +
  5582. 'AAAQAAAAAAAAAAACAAIAABAAAADgCuAAEAAAAAAAAAAQAAAAEAAAAAAAEAAQAAAAEAAAAA' +
  5583. 'AAIAAQAAAAEAAAAAAAMAAQAAAAEAAAAAAAQAAQAAAAEAAAAAAAUAAQAAAAEAAAAAAAYAAQ' +
  5584. 'AAAAMAAQQJAAAAAgABAAMAAQQJAAEAAgABAAMAAQQJAAIAAgABAAMAAQQJAAMAAgABAAMA' +
  5585. 'AQQJAAQAAgABAAMAAQQJAAUAAgABAAMAAQQJAAYAAgABWABYAAAAAAAAAwAAAAMAAAAcAA' +
  5586. 'EAAAAAADwAAwABAAAAHAAEACAAAAAEAAQAAQAAAC7//wAAAC7////TAAEAAAAAAAABBgAA' +
  5587. 'AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAA' +
  5588. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' +
  5589. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' +
  5590. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' +
  5591. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMAAA' +
  5592. 'AAAAD/gwAyAAAAAQAAAAAAAAAAAAAAAAAAAAABAAQEAAEBAQJYAAEBASH4DwD4GwHEAvgc' +
  5593. 'A/gXBIwMAYuL+nz5tQXkD5j3CBLnEQACAQEBIVhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWF' +
  5594. 'hYWFhYWFhYAAABAQAADwACAQEEE/t3Dov6fAH6fAT+fPp8+nwHDosMCvm1Cvm1DAz6fBQA' +
  5595. 'AAAAAAABAAAAAMmJbzEAAAAAzgTjFQAAAADOBOQpAAEAAAAAAAAADAAUAAQAAAABAAAAAg' +
  5596. 'ABAAAAAAAAAAAD6AAAAAAAAA=='
  5597. ));
  5598. },
  5599. loadTestFontId: 0,
  5600. loadingContext: {
  5601. requests: [],
  5602. nextRequestId: 0
  5603. },
  5604. isSyncFontLoadingSupported: (function detectSyncFontLoadingSupport() {
  5605. if (isWorker) {
  5606. return false;
  5607. }
  5608. // User agent string sniffing is bad, but there is no reliable way to tell
  5609. // if font is fully loaded and ready to be used with canvas.
  5610. var userAgent = window.navigator.userAgent;
  5611. var m = /Mozilla\/5.0.*?rv:(\d+).*? Gecko/.exec(userAgent);
  5612. if (m && m[1] >= 14) {
  5613. return true;
  5614. }
  5615. // TODO other browsers
  5616. if (userAgent === 'node') {
  5617. return true;
  5618. }
  5619. return false;
  5620. })(),
  5621. nativeFontFaces: [],
  5622. isFontLoadingAPISupported: (!isWorker && typeof document !== 'undefined' &&
  5623. !!document.fonts),
  5624. addNativeFontFace: function fontLoader_addNativeFontFace(nativeFontFace) {
  5625. this.nativeFontFaces.push(nativeFontFace);
  5626. document.fonts.add(nativeFontFace);
  5627. },
  5628. bind: function fontLoaderBind(fonts, callback) {
  5629. assert(!isWorker, 'bind() shall be called from main thread');
  5630. var rules = [];
  5631. var fontsToLoad = [];
  5632. var fontLoadPromises = [];
  5633. for (var i = 0, ii = fonts.length; i < ii; i++) {
  5634. var font = fonts[i];
  5635. // Add the font to the DOM only once or skip if the font
  5636. // is already loaded.
  5637. if (font.attached || font.loading === false) {
  5638. continue;
  5639. }
  5640. font.attached = true;
  5641. if (this.isFontLoadingAPISupported) {
  5642. var nativeFontFace = font.createNativeFontFace();
  5643. if (nativeFontFace) {
  5644. fontLoadPromises.push(nativeFontFace.loaded);
  5645. }
  5646. } else {
  5647. var rule = font.bindDOM();
  5648. if (rule) {
  5649. rules.push(rule);
  5650. fontsToLoad.push(font);
  5651. }
  5652. }
  5653. }
  5654. var request = FontLoader.queueLoadingCallback(callback);
  5655. if (this.isFontLoadingAPISupported) {
  5656. Promise.all(fontsToLoad).then(function() {
  5657. request.complete();
  5658. });
  5659. } else if (rules.length > 0 && !this.isSyncFontLoadingSupported) {
  5660. FontLoader.prepareFontLoadEvent(rules, fontsToLoad, request);
  5661. } else {
  5662. request.complete();
  5663. }
  5664. },
  5665. queueLoadingCallback: function FontLoader_queueLoadingCallback(callback) {
  5666. function LoadLoader_completeRequest() {
  5667. assert(!request.end, 'completeRequest() cannot be called twice');
  5668. request.end = Date.now();
  5669. // sending all completed requests in order how they were queued
  5670. while (context.requests.length > 0 && context.requests[0].end) {
  5671. var otherRequest = context.requests.shift();
  5672. setTimeout(otherRequest.callback, 0);
  5673. }
  5674. }
  5675. var context = FontLoader.loadingContext;
  5676. var requestId = 'pdfjs-font-loading-' + (context.nextRequestId++);
  5677. var request = {
  5678. id: requestId,
  5679. complete: LoadLoader_completeRequest,
  5680. callback: callback,
  5681. started: Date.now()
  5682. };
  5683. context.requests.push(request);
  5684. return request;
  5685. },
  5686. prepareFontLoadEvent: function fontLoaderPrepareFontLoadEvent(rules,
  5687. fonts,
  5688. request) {
  5689. /** Hack begin */
  5690. // There's currently no event when a font has finished downloading so the
  5691. // following code is a dirty hack to 'guess' when a font is
  5692. // ready. It's assumed fonts are loaded in order, so add a known test
  5693. // font after the desired fonts and then test for the loading of that
  5694. // test font.
  5695. function int32(data, offset) {
  5696. return (data.charCodeAt(offset) << 24) |
  5697. (data.charCodeAt(offset + 1) << 16) |
  5698. (data.charCodeAt(offset + 2) << 8) |
  5699. (data.charCodeAt(offset + 3) & 0xff);
  5700. }
  5701. function spliceString(s, offset, remove, insert) {
  5702. var chunk1 = s.substr(0, offset);
  5703. var chunk2 = s.substr(offset + remove);
  5704. return chunk1 + insert + chunk2;
  5705. }
  5706. var i, ii;
  5707. var canvas = document.createElement('canvas');
  5708. canvas.width = 1;
  5709. canvas.height = 1;
  5710. var ctx = canvas.getContext('2d');
  5711. var called = 0;
  5712. function isFontReady(name, callback) {
  5713. called++;
  5714. // With setTimeout clamping this gives the font ~100ms to load.
  5715. if(called > 30) {
  5716. warn('Load test font never loaded.');
  5717. callback();
  5718. return;
  5719. }
  5720. ctx.font = '30px ' + name;
  5721. ctx.fillText('.', 0, 20);
  5722. var imageData = ctx.getImageData(0, 0, 1, 1);
  5723. if (imageData.data[3] > 0) {
  5724. callback();
  5725. return;
  5726. }
  5727. setTimeout(isFontReady.bind(null, name, callback));
  5728. }
  5729. var loadTestFontId = 'lt' + Date.now() + this.loadTestFontId++;
  5730. // Chromium seems to cache fonts based on a hash of the actual font data,
  5731. // so the font must be modified for each load test else it will appear to
  5732. // be loaded already.
  5733. // TODO: This could maybe be made faster by avoiding the btoa of the full
  5734. // font by splitting it in chunks before hand and padding the font id.
  5735. var data = this.loadTestFont;
  5736. var COMMENT_OFFSET = 976; // has to be on 4 byte boundary (for checksum)
  5737. data = spliceString(data, COMMENT_OFFSET, loadTestFontId.length,
  5738. loadTestFontId);
  5739. // CFF checksum is important for IE, adjusting it
  5740. var CFF_CHECKSUM_OFFSET = 16;
  5741. var XXXX_VALUE = 0x58585858; // the "comment" filled with 'X'
  5742. var checksum = int32(data, CFF_CHECKSUM_OFFSET);
  5743. for (i = 0, ii = loadTestFontId.length - 3; i < ii; i += 4) {
  5744. checksum = (checksum - XXXX_VALUE + int32(loadTestFontId, i)) | 0;
  5745. }
  5746. if (i < loadTestFontId.length) { // align to 4 bytes boundary
  5747. checksum = (checksum - XXXX_VALUE +
  5748. int32(loadTestFontId + 'XXX', i)) | 0;
  5749. }
  5750. data = spliceString(data, CFF_CHECKSUM_OFFSET, 4, string32(checksum));
  5751. var url = 'url(data:font/opentype;base64,' + btoa(data) + ');';
  5752. var rule = '@font-face { font-family:"' + loadTestFontId + '";src:' +
  5753. url + '}';
  5754. FontLoader.insertRule(rule);
  5755. var names = [];
  5756. for (i = 0, ii = fonts.length; i < ii; i++) {
  5757. names.push(fonts[i].loadedName);
  5758. }
  5759. names.push(loadTestFontId);
  5760. var div = document.createElement('div');
  5761. div.setAttribute('style',
  5762. 'visibility: hidden;' +
  5763. 'width: 10px; height: 10px;' +
  5764. 'position: absolute; top: 0px; left: 0px;');
  5765. for (i = 0, ii = names.length; i < ii; ++i) {
  5766. var span = document.createElement('span');
  5767. span.textContent = 'Hi';
  5768. span.style.fontFamily = names[i];
  5769. div.appendChild(span);
  5770. }
  5771. document.body.appendChild(div);
  5772. isFontReady(loadTestFontId, function() {
  5773. document.body.removeChild(div);
  5774. request.complete();
  5775. });
  5776. /** Hack end */
  5777. }
  5778. };
  5779. var FontFaceObject = (function FontFaceObjectClosure() {
  5780. function FontFaceObject(name, file, properties) {
  5781. this.compiledGlyphs = {};
  5782. if (arguments.length === 1) {
  5783. // importing translated data
  5784. var data = arguments[0];
  5785. for (var i in data) {
  5786. this[i] = data[i];
  5787. }
  5788. return;
  5789. }
  5790. }
  5791. FontFaceObject.prototype = {
  5792. createNativeFontFace: function FontFaceObject_createNativeFontFace() {
  5793. if (!this.data) {
  5794. return null;
  5795. }
  5796. if (PDFJS.disableFontFace) {
  5797. this.disableFontFace = true;
  5798. return null;
  5799. }
  5800. var nativeFontFace = new FontFace(this.loadedName, this.data, {});
  5801. FontLoader.addNativeFontFace(nativeFontFace);
  5802. if (PDFJS.pdfBug && 'FontInspector' in globalScope &&
  5803. globalScope['FontInspector'].enabled) {
  5804. globalScope['FontInspector'].fontAdded(this);
  5805. }
  5806. return nativeFontFace;
  5807. },
  5808. bindDOM: function FontFaceObject_bindDOM() {
  5809. if (!this.data) {
  5810. return null;
  5811. }
  5812. if (PDFJS.disableFontFace) {
  5813. this.disableFontFace = true;
  5814. return null;
  5815. }
  5816. var data = bytesToString(new Uint8Array(this.data));
  5817. var fontName = this.loadedName;
  5818. // Add the font-face rule to the document
  5819. var url = ('url(data:' + this.mimetype + ';base64,' +
  5820. window.btoa(data) + ');');
  5821. var rule = '@font-face { font-family:"' + fontName + '";src:' + url + '}';
  5822. FontLoader.insertRule(rule);
  5823. if (PDFJS.pdfBug && 'FontInspector' in globalScope &&
  5824. globalScope['FontInspector'].enabled) {
  5825. globalScope['FontInspector'].fontAdded(this, url);
  5826. }
  5827. return rule;
  5828. },
  5829. getPathGenerator: function FontLoader_getPathGenerator(objs, character) {
  5830. if (!(character in this.compiledGlyphs)) {
  5831. var js = objs.get(this.loadedName + '_path_' + character);
  5832. /*jshint -W054 */
  5833. this.compiledGlyphs[character] = new Function('c', 'size', js);
  5834. }
  5835. return this.compiledGlyphs[character];
  5836. }
  5837. };
  5838. return FontFaceObject;
  5839. })();
  5840. var ANNOT_MIN_SIZE = 10; // px
  5841. var AnnotationUtils = (function AnnotationUtilsClosure() {
  5842. // TODO(mack): This dupes some of the logic in CanvasGraphics.setFont()
  5843. function setTextStyles(element, item, fontObj) {
  5844. var style = element.style;
  5845. style.fontSize = item.fontSize + 'px';
  5846. style.direction = item.fontDirection < 0 ? 'rtl': 'ltr';
  5847. if (!fontObj) {
  5848. return;
  5849. }
  5850. style.fontWeight = fontObj.black ?
  5851. (fontObj.bold ? 'bolder' : 'bold') :
  5852. (fontObj.bold ? 'bold' : 'normal');
  5853. style.fontStyle = fontObj.italic ? 'italic' : 'normal';
  5854. var fontName = fontObj.loadedName;
  5855. var fontFamily = fontName ? '"' + fontName + '", ' : '';
  5856. // Use a reasonable default font if the font doesn't specify a fallback
  5857. var fallbackName = fontObj.fallbackName || 'Helvetica, sans-serif';
  5858. style.fontFamily = fontFamily + fallbackName;
  5859. }
  5860. function initContainer(item, drawBorder) {
  5861. var container = document.createElement('section');
  5862. var cstyle = container.style;
  5863. var width = item.rect[2] - item.rect[0];
  5864. var height = item.rect[3] - item.rect[1];
  5865. var bWidth = item.borderWidth || 0;
  5866. if (bWidth) {
  5867. width = width - 2 * bWidth;
  5868. height = height - 2 * bWidth;
  5869. cstyle.borderWidth = bWidth + 'px';
  5870. var color = item.color;
  5871. if (drawBorder && color) {
  5872. cstyle.borderStyle = 'solid';
  5873. cstyle.borderColor = Util.makeCssRgb(Math.round(color[0] * 255),
  5874. Math.round(color[1] * 255),
  5875. Math.round(color[2] * 255));
  5876. }
  5877. }
  5878. cstyle.width = width + 'px';
  5879. cstyle.height = height + 'px';
  5880. return container;
  5881. }
  5882. function getHtmlElementForTextWidgetAnnotation(item, commonObjs) {
  5883. var element = document.createElement('div');
  5884. var width = item.rect[2] - item.rect[0];
  5885. var height = item.rect[3] - item.rect[1];
  5886. element.style.width = width + 'px';
  5887. element.style.height = height + 'px';
  5888. element.style.display = 'table';
  5889. var content = document.createElement('div');
  5890. content.textContent = item.fieldValue;
  5891. var textAlignment = item.textAlignment;
  5892. content.style.textAlign = ['left', 'center', 'right'][textAlignment];
  5893. content.style.verticalAlign = 'middle';
  5894. content.style.display = 'table-cell';
  5895. var fontObj = item.fontRefName ?
  5896. commonObjs.getData(item.fontRefName) : null;
  5897. setTextStyles(content, item, fontObj);
  5898. element.appendChild(content);
  5899. return element;
  5900. }
  5901. function getHtmlElementForTextAnnotation(item) {
  5902. var rect = item.rect;
  5903. // sanity check because of OOo-generated PDFs
  5904. if ((rect[3] - rect[1]) < ANNOT_MIN_SIZE) {
  5905. rect[3] = rect[1] + ANNOT_MIN_SIZE;
  5906. }
  5907. if ((rect[2] - rect[0]) < ANNOT_MIN_SIZE) {
  5908. rect[2] = rect[0] + (rect[3] - rect[1]); // make it square
  5909. }
  5910. var container = initContainer(item, false);
  5911. container.className = 'annotText';
  5912. var image = document.createElement('img');
  5913. image.style.height = container.style.height;
  5914. image.style.width = container.style.width;
  5915. var iconName = item.name;
  5916. image.src = PDFJS.imageResourcesPath + 'annotation-' +
  5917. iconName.toLowerCase() + '.svg';
  5918. image.alt = '[{{type}} Annotation]';
  5919. image.dataset.l10nId = 'text_annotation_type';
  5920. image.dataset.l10nArgs = JSON.stringify({type: iconName});
  5921. var contentWrapper = document.createElement('div');
  5922. contentWrapper.className = 'annotTextContentWrapper';
  5923. contentWrapper.style.left = Math.floor(rect[2] - rect[0] + 5) + 'px';
  5924. contentWrapper.style.top = '-10px';
  5925. var content = document.createElement('div');
  5926. content.className = 'annotTextContent';
  5927. content.setAttribute('hidden', true);
  5928. var i, ii;
  5929. if (item.hasBgColor) {
  5930. var color = item.color;
  5931. // Enlighten the color (70%)
  5932. var BACKGROUND_ENLIGHT = 0.7;
  5933. var r = BACKGROUND_ENLIGHT * (1.0 - color[0]) + color[0];
  5934. var g = BACKGROUND_ENLIGHT * (1.0 - color[1]) + color[1];
  5935. var b = BACKGROUND_ENLIGHT * (1.0 - color[2]) + color[2];
  5936. content.style.backgroundColor = Util.makeCssRgb((r * 255) | 0,
  5937. (g * 255) | 0,
  5938. (b * 255) | 0);
  5939. }
  5940. var title = document.createElement('h1');
  5941. var text = document.createElement('p');
  5942. title.textContent = item.title;
  5943. if (!item.content && !item.title) {
  5944. content.setAttribute('hidden', true);
  5945. } else {
  5946. var e = document.createElement('span');
  5947. var lines = item.content.split(/(?:\r\n?|\n)/);
  5948. for (i = 0, ii = lines.length; i < ii; ++i) {
  5949. var line = lines[i];
  5950. e.appendChild(document.createTextNode(line));
  5951. if (i < (ii - 1)) {
  5952. e.appendChild(document.createElement('br'));
  5953. }
  5954. }
  5955. text.appendChild(e);
  5956. var pinned = false;
  5957. var showAnnotation = function showAnnotation(pin) {
  5958. if (pin) {
  5959. pinned = true;
  5960. }
  5961. if (content.hasAttribute('hidden')) {
  5962. container.style.zIndex += 1;
  5963. content.removeAttribute('hidden');
  5964. }
  5965. };
  5966. var hideAnnotation = function hideAnnotation(unpin) {
  5967. if (unpin) {
  5968. pinned = false;
  5969. }
  5970. if (!content.hasAttribute('hidden') && !pinned) {
  5971. container.style.zIndex -= 1;
  5972. content.setAttribute('hidden', true);
  5973. }
  5974. };
  5975. var toggleAnnotation = function toggleAnnotation() {
  5976. if (pinned) {
  5977. hideAnnotation(true);
  5978. } else {
  5979. showAnnotation(true);
  5980. }
  5981. };
  5982. image.addEventListener('click', function image_clickHandler() {
  5983. toggleAnnotation();
  5984. }, false);
  5985. image.addEventListener('mouseover', function image_mouseOverHandler() {
  5986. showAnnotation();
  5987. }, false);
  5988. image.addEventListener('mouseout', function image_mouseOutHandler() {
  5989. hideAnnotation();
  5990. }, false);
  5991. content.addEventListener('click', function content_clickHandler() {
  5992. hideAnnotation(true);
  5993. }, false);
  5994. }
  5995. content.appendChild(title);
  5996. content.appendChild(text);
  5997. contentWrapper.appendChild(content);
  5998. container.appendChild(image);
  5999. container.appendChild(contentWrapper);
  6000. return container;
  6001. }
  6002. function getHtmlElementForLinkAnnotation(item) {
  6003. var container = initContainer(item, true);
  6004. container.className = 'annotLink';
  6005. var link = document.createElement('a');
  6006. link.href = link.title = item.url || '';
  6007. if (item.url && PDFJS.openExternalLinksInNewWindow) {
  6008. link.target = '_blank';
  6009. }
  6010. container.appendChild(link);
  6011. return container;
  6012. }
  6013. function getHtmlElement(data, objs) {
  6014. switch (data.annotationType) {
  6015. case AnnotationType.WIDGET:
  6016. return getHtmlElementForTextWidgetAnnotation(data, objs);
  6017. case AnnotationType.TEXT:
  6018. return getHtmlElementForTextAnnotation(data);
  6019. case AnnotationType.LINK:
  6020. return getHtmlElementForLinkAnnotation(data);
  6021. default:
  6022. throw new Error('Unsupported annotationType: ' + data.annotationType);
  6023. }
  6024. }
  6025. return {
  6026. getHtmlElement: getHtmlElement
  6027. };
  6028. })();
  6029. PDFJS.AnnotationUtils = AnnotationUtils;
  6030. var SVG_DEFAULTS = {
  6031. fontStyle: 'normal',
  6032. fontWeight: 'normal',
  6033. fillColor: '#000000'
  6034. };
  6035. var convertImgDataToPng = (function convertImgDataToPngClosure() {
  6036. var PNG_HEADER =
  6037. new Uint8Array([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);
  6038. var CHUNK_WRAPPER_SIZE = 12;
  6039. var crcTable = new Int32Array(256);
  6040. for (var i = 0; i < 256; i++) {
  6041. var c = i;
  6042. for (var h = 0; h < 8; h++) {
  6043. if (c & 1) {
  6044. c = 0xedB88320 ^ ((c >> 1) & 0x7fffffff);
  6045. } else {
  6046. c = (c >> 1) & 0x7fffffff;
  6047. }
  6048. }
  6049. crcTable[i] = c;
  6050. }
  6051. function crc32(data, start, end) {
  6052. var crc = -1;
  6053. for (var i = start; i < end; i++) {
  6054. var a = (crc ^ data[i]) & 0xff;
  6055. var b = crcTable[a];
  6056. crc = (crc >>> 8) ^ b;
  6057. }
  6058. return crc ^ -1;
  6059. }
  6060. function writePngChunk(type, body, data, offset) {
  6061. var p = offset;
  6062. var len = body.length;
  6063. data[p] = len >> 24 & 0xff;
  6064. data[p + 1] = len >> 16 & 0xff;
  6065. data[p + 2] = len >> 8 & 0xff;
  6066. data[p + 3] = len & 0xff;
  6067. p += 4;
  6068. data[p] = type.charCodeAt(0) & 0xff;
  6069. data[p + 1] = type.charCodeAt(1) & 0xff;
  6070. data[p + 2] = type.charCodeAt(2) & 0xff;
  6071. data[p + 3] = type.charCodeAt(3) & 0xff;
  6072. p += 4;
  6073. data.set(body, p);
  6074. p += body.length;
  6075. var crc = crc32(data, offset + 4, p);
  6076. data[p] = crc >> 24 & 0xff;
  6077. data[p + 1] = crc >> 16 & 0xff;
  6078. data[p + 2] = crc >> 8 & 0xff;
  6079. data[p + 3] = crc & 0xff;
  6080. }
  6081. function adler32(data, start, end) {
  6082. var a = 1;
  6083. var b = 0;
  6084. for (var i = start; i < end; ++i) {
  6085. a = (a + (data[i] & 0xff)) % 65521;
  6086. b = (b + a) % 65521;
  6087. }
  6088. return (b << 16) | a;
  6089. }
  6090. function encode(imgData, kind) {
  6091. var width = imgData.width;
  6092. var height = imgData.height;
  6093. var bitDepth, colorType, lineSize;
  6094. var bytes = imgData.data;
  6095. switch (kind) {
  6096. case ImageKind.GRAYSCALE_1BPP:
  6097. colorType = 0;
  6098. bitDepth = 1;
  6099. lineSize = (width + 7) >> 3;
  6100. break;
  6101. case ImageKind.RGB_24BPP:
  6102. colorType = 2;
  6103. bitDepth = 8;
  6104. lineSize = width * 3;
  6105. break;
  6106. case ImageKind.RGBA_32BPP:
  6107. colorType = 6;
  6108. bitDepth = 8;
  6109. lineSize = width * 4;
  6110. break;
  6111. default:
  6112. throw new Error('invalid format');
  6113. }
  6114. // prefix every row with predictor 0
  6115. var literals = new Uint8Array((1 + lineSize) * height);
  6116. var offsetLiterals = 0, offsetBytes = 0;
  6117. var y, i;
  6118. for (y = 0; y < height; ++y) {
  6119. literals[offsetLiterals++] = 0; // no prediction
  6120. literals.set(bytes.subarray(offsetBytes, offsetBytes + lineSize),
  6121. offsetLiterals);
  6122. offsetBytes += lineSize;
  6123. offsetLiterals += lineSize;
  6124. }
  6125. if (kind === ImageKind.GRAYSCALE_1BPP) {
  6126. // inverting for B/W
  6127. offsetLiterals = 0;
  6128. for (y = 0; y < height; y++) {
  6129. offsetLiterals++; // skipping predictor
  6130. for (i = 0; i < lineSize; i++) {
  6131. literals[offsetLiterals++] ^= 0xFF;
  6132. }
  6133. }
  6134. }
  6135. var ihdr = new Uint8Array([
  6136. width >> 24 & 0xff,
  6137. width >> 16 & 0xff,
  6138. width >> 8 & 0xff,
  6139. width & 0xff,
  6140. height >> 24 & 0xff,
  6141. height >> 16 & 0xff,
  6142. height >> 8 & 0xff,
  6143. height & 0xff,
  6144. bitDepth, // bit depth
  6145. colorType, // color type
  6146. 0x00, // compression method
  6147. 0x00, // filter method
  6148. 0x00 // interlace method
  6149. ]);
  6150. var len = literals.length;
  6151. var maxBlockLength = 0xFFFF;
  6152. var deflateBlocks = Math.ceil(len / maxBlockLength);
  6153. var idat = new Uint8Array(2 + len + deflateBlocks * 5 + 4);
  6154. var pi = 0;
  6155. idat[pi++] = 0x78; // compression method and flags
  6156. idat[pi++] = 0x9c; // flags
  6157. var pos = 0;
  6158. while (len > maxBlockLength) {
  6159. // writing non-final DEFLATE blocks type 0 and length of 65535
  6160. idat[pi++] = 0x00;
  6161. idat[pi++] = 0xff;
  6162. idat[pi++] = 0xff;
  6163. idat[pi++] = 0x00;
  6164. idat[pi++] = 0x00;
  6165. idat.set(literals.subarray(pos, pos + maxBlockLength), pi);
  6166. pi += maxBlockLength;
  6167. pos += maxBlockLength;
  6168. len -= maxBlockLength;
  6169. }
  6170. // writing non-final DEFLATE blocks type 0
  6171. idat[pi++] = 0x01;
  6172. idat[pi++] = len & 0xff;
  6173. idat[pi++] = len >> 8 & 0xff;
  6174. idat[pi++] = (~len & 0xffff) & 0xff;
  6175. idat[pi++] = (~len & 0xffff) >> 8 & 0xff;
  6176. idat.set(literals.subarray(pos), pi);
  6177. pi += literals.length - pos;
  6178. var adler = adler32(literals, 0, literals.length); // checksum
  6179. idat[pi++] = adler >> 24 & 0xff;
  6180. idat[pi++] = adler >> 16 & 0xff;
  6181. idat[pi++] = adler >> 8 & 0xff;
  6182. idat[pi++] = adler & 0xff;
  6183. // PNG will consists: header, IHDR+data, IDAT+data, and IEND.
  6184. var pngLength = PNG_HEADER.length + (CHUNK_WRAPPER_SIZE * 3) +
  6185. ihdr.length + idat.length;
  6186. var data = new Uint8Array(pngLength);
  6187. var offset = 0;
  6188. data.set(PNG_HEADER, offset);
  6189. offset += PNG_HEADER.length;
  6190. writePngChunk('IHDR', ihdr, data, offset);
  6191. offset += CHUNK_WRAPPER_SIZE + ihdr.length;
  6192. writePngChunk('IDATA', idat, data, offset);
  6193. offset += CHUNK_WRAPPER_SIZE + idat.length;
  6194. writePngChunk('IEND', new Uint8Array(0), data, offset);
  6195. return PDFJS.createObjectURL(data, 'image/png');
  6196. }
  6197. return function convertImgDataToPng(imgData) {
  6198. var kind = (imgData.kind === undefined ?
  6199. ImageKind.GRAYSCALE_1BPP : imgData.kind);
  6200. return encode(imgData, kind);
  6201. };
  6202. })();
  6203. var SVGExtraState = (function SVGExtraStateClosure() {
  6204. function SVGExtraState() {
  6205. this.fontSizeScale = 1;
  6206. this.fontWeight = SVG_DEFAULTS.fontWeight;
  6207. this.fontSize = 0;
  6208. this.textMatrix = IDENTITY_MATRIX;
  6209. this.fontMatrix = FONT_IDENTITY_MATRIX;
  6210. this.leading = 0;
  6211. // Current point (in user coordinates)
  6212. this.x = 0;
  6213. this.y = 0;
  6214. // Start of text line (in text coordinates)
  6215. this.lineX = 0;
  6216. this.lineY = 0;
  6217. // Character and word spacing
  6218. this.charSpacing = 0;
  6219. this.wordSpacing = 0;
  6220. this.textHScale = 1;
  6221. this.textRise = 0;
  6222. // Default foreground and background colors
  6223. this.fillColor = SVG_DEFAULTS.fillColor;
  6224. this.strokeColor = '#000000';
  6225. this.fillAlpha = 1;
  6226. this.strokeAlpha = 1;
  6227. this.lineWidth = 1;
  6228. this.lineJoin = '';
  6229. this.lineCap = '';
  6230. this.miterLimit = 0;
  6231. this.dashArray = [];
  6232. this.dashPhase = 0;
  6233. this.dependencies = [];
  6234. // Clipping
  6235. this.clipId = '';
  6236. this.pendingClip = false;
  6237. this.maskId = '';
  6238. }
  6239. SVGExtraState.prototype = {
  6240. clone: function SVGExtraState_clone() {
  6241. return Object.create(this);
  6242. },
  6243. setCurrentPoint: function SVGExtraState_setCurrentPoint(x, y) {
  6244. this.x = x;
  6245. this.y = y;
  6246. }
  6247. };
  6248. return SVGExtraState;
  6249. })();
  6250. var SVGGraphics = (function SVGGraphicsClosure() {
  6251. function createScratchSVG(width, height) {
  6252. var NS = 'http://www.w3.org/2000/svg';
  6253. var svg = document.createElementNS(NS, 'svg:svg');
  6254. svg.setAttributeNS(null, 'version', '1.1');
  6255. svg.setAttributeNS(null, 'width', width + 'px');
  6256. svg.setAttributeNS(null, 'height', height + 'px');
  6257. svg.setAttributeNS(null, 'viewBox', '0 0 ' + width + ' ' + height);
  6258. return svg;
  6259. }
  6260. function opListToTree(opList) {
  6261. var opTree = [];
  6262. var tmp = [];
  6263. var opListLen = opList.length;
  6264. for (var x = 0; x < opListLen; x++) {
  6265. if (opList[x].fn === 'save') {
  6266. opTree.push({'fnId': 92, 'fn': 'group', 'items': []});
  6267. tmp.push(opTree);
  6268. opTree = opTree[opTree.length - 1].items;
  6269. continue;
  6270. }
  6271. if(opList[x].fn === 'restore') {
  6272. opTree = tmp.pop();
  6273. } else {
  6274. opTree.push(opList[x]);
  6275. }
  6276. }
  6277. return opTree;
  6278. }
  6279. /**
  6280. * Formats float number.
  6281. * @param value {number} number to format.
  6282. * @returns {string}
  6283. */
  6284. function pf(value) {
  6285. if (value === (value | 0)) { // integer number
  6286. return value.toString();
  6287. }
  6288. var s = value.toFixed(10);
  6289. var i = s.length - 1;
  6290. if (s[i] !== '0') {
  6291. return s;
  6292. }
  6293. // removing trailing zeros
  6294. do {
  6295. i--;
  6296. } while (s[i] === '0');
  6297. return s.substr(0, s[i] === '.' ? i : i + 1);
  6298. }
  6299. /**
  6300. * Formats transform matrix. The standard rotation, scale and translate
  6301. * matrices are replaced by their shorter forms, and for identity matrix
  6302. * returns empty string to save the memory.
  6303. * @param m {Array} matrix to format.
  6304. * @returns {string}
  6305. */
  6306. function pm(m) {
  6307. if (m[4] === 0 && m[5] === 0) {
  6308. if (m[1] === 0 && m[2] === 0) {
  6309. if (m[0] === 1 && m[3] === 1) {
  6310. return '';
  6311. }
  6312. return 'scale(' + pf(m[0]) + ' ' + pf(m[3]) + ')';
  6313. }
  6314. if (m[0] === m[3] && m[1] === -m[2]) {
  6315. var a = Math.acos(m[0]) * 180 / Math.PI;
  6316. return 'rotate(' + pf(a) + ')';
  6317. }
  6318. } else {
  6319. if (m[0] === 1 && m[1] === 0 && m[2] === 0 && m[3] === 1) {
  6320. return 'translate(' + pf(m[4]) + ' ' + pf(m[5]) + ')';
  6321. }
  6322. }
  6323. return 'matrix(' + pf(m[0]) + ' ' + pf(m[1]) + ' ' + pf(m[2]) + ' ' +
  6324. pf(m[3]) + ' ' + pf(m[4]) + ' ' + pf(m[5]) + ')';
  6325. }
  6326. function SVGGraphics(commonObjs, objs) {
  6327. this.current = new SVGExtraState();
  6328. this.transformMatrix = IDENTITY_MATRIX; // Graphics state matrix
  6329. this.transformStack = [];
  6330. this.extraStack = [];
  6331. this.commonObjs = commonObjs;
  6332. this.objs = objs;
  6333. this.pendingEOFill = false;
  6334. this.embedFonts = false;
  6335. this.embeddedFonts = {};
  6336. this.cssStyle = null;
  6337. }
  6338. var NS = 'http://www.w3.org/2000/svg';
  6339. var XML_NS = 'http://www.w3.org/XML/1998/namespace';
  6340. var XLINK_NS = 'http://www.w3.org/1999/xlink';
  6341. var LINE_CAP_STYLES = ['butt', 'round', 'square'];
  6342. var LINE_JOIN_STYLES = ['miter', 'round', 'bevel'];
  6343. var clipCount = 0;
  6344. var maskCount = 0;
  6345. SVGGraphics.prototype = {
  6346. save: function SVGGraphics_save() {
  6347. this.transformStack.push(this.transformMatrix);
  6348. var old = this.current;
  6349. this.extraStack.push(old);
  6350. this.current = old.clone();
  6351. },
  6352. restore: function SVGGraphics_restore() {
  6353. this.transformMatrix = this.transformStack.pop();
  6354. this.current = this.extraStack.pop();
  6355. this.tgrp = document.createElementNS(NS, 'svg:g');
  6356. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  6357. this.pgrp.appendChild(this.tgrp);
  6358. },
  6359. group: function SVGGraphics_group(items) {
  6360. this.save();
  6361. this.executeOpTree(items);
  6362. this.restore();
  6363. },
  6364. loadDependencies: function SVGGraphics_loadDependencies(operatorList) {
  6365. var fnArray = operatorList.fnArray;
  6366. var fnArrayLen = fnArray.length;
  6367. var argsArray = operatorList.argsArray;
  6368. var self = this;
  6369. for (var i = 0; i < fnArrayLen; i++) {
  6370. if (OPS.dependency === fnArray[i]) {
  6371. var deps = argsArray[i];
  6372. for (var n = 0, nn = deps.length; n < nn; n++) {
  6373. var obj = deps[n];
  6374. var common = obj.substring(0, 2) === 'g_';
  6375. var promise;
  6376. if (common) {
  6377. promise = new Promise(function(resolve) {
  6378. self.commonObjs.get(obj, resolve);
  6379. });
  6380. } else {
  6381. promise = new Promise(function(resolve) {
  6382. self.objs.get(obj, resolve);
  6383. });
  6384. }
  6385. this.current.dependencies.push(promise);
  6386. }
  6387. }
  6388. }
  6389. return Promise.all(this.current.dependencies);
  6390. },
  6391. transform: function SVGGraphics_transform(a, b, c, d, e, f) {
  6392. var transformMatrix = [a, b, c, d, e, f];
  6393. this.transformMatrix = PDFJS.Util.transform(this.transformMatrix,
  6394. transformMatrix);
  6395. this.tgrp = document.createElementNS(NS, 'svg:g');
  6396. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  6397. },
  6398. getSVG: function SVGGraphics_getSVG(operatorList, viewport) {
  6399. this.svg = createScratchSVG(viewport.width, viewport.height);
  6400. this.viewport = viewport;
  6401. return this.loadDependencies(operatorList).then(function () {
  6402. this.transformMatrix = IDENTITY_MATRIX;
  6403. this.pgrp = document.createElementNS(NS, 'svg:g'); // Parent group
  6404. this.pgrp.setAttributeNS(null, 'transform', pm(viewport.transform));
  6405. this.tgrp = document.createElementNS(NS, 'svg:g'); // Transform group
  6406. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  6407. this.defs = document.createElementNS(NS, 'svg:defs');
  6408. this.pgrp.appendChild(this.defs);
  6409. this.pgrp.appendChild(this.tgrp);
  6410. this.svg.appendChild(this.pgrp);
  6411. var opTree = this.convertOpList(operatorList);
  6412. this.executeOpTree(opTree);
  6413. return this.svg;
  6414. }.bind(this));
  6415. },
  6416. convertOpList: function SVGGraphics_convertOpList(operatorList) {
  6417. var argsArray = operatorList.argsArray;
  6418. var fnArray = operatorList.fnArray;
  6419. var fnArrayLen = fnArray.length;
  6420. var REVOPS = [];
  6421. var opList = [];
  6422. for (var op in OPS) {
  6423. REVOPS[OPS[op]] = op;
  6424. }
  6425. for (var x = 0; x < fnArrayLen; x++) {
  6426. var fnId = fnArray[x];
  6427. opList.push({'fnId' : fnId, 'fn': REVOPS[fnId], 'args': argsArray[x]});
  6428. }
  6429. return opListToTree(opList);
  6430. },
  6431. executeOpTree: function SVGGraphics_executeOpTree(opTree) {
  6432. var opTreeLen = opTree.length;
  6433. for(var x = 0; x < opTreeLen; x++) {
  6434. var fn = opTree[x].fn;
  6435. var fnId = opTree[x].fnId;
  6436. var args = opTree[x].args;
  6437. switch (fnId | 0) {
  6438. case OPS.beginText:
  6439. this.beginText();
  6440. break;
  6441. case OPS.setLeading:
  6442. this.setLeading(args);
  6443. break;
  6444. case OPS.setLeadingMoveText:
  6445. this.setLeadingMoveText(args[0], args[1]);
  6446. break;
  6447. case OPS.setFont:
  6448. this.setFont(args);
  6449. break;
  6450. case OPS.showText:
  6451. this.showText(args[0]);
  6452. break;
  6453. case OPS.showSpacedText:
  6454. this.showText(args[0]);
  6455. break;
  6456. case OPS.endText:
  6457. this.endText();
  6458. break;
  6459. case OPS.moveText:
  6460. this.moveText(args[0], args[1]);
  6461. break;
  6462. case OPS.setCharSpacing:
  6463. this.setCharSpacing(args[0]);
  6464. break;
  6465. case OPS.setWordSpacing:
  6466. this.setWordSpacing(args[0]);
  6467. break;
  6468. case OPS.setHScale:
  6469. this.setHScale(args[0]);
  6470. break;
  6471. case OPS.setTextMatrix:
  6472. this.setTextMatrix(args[0], args[1], args[2],
  6473. args[3], args[4], args[5]);
  6474. break;
  6475. case OPS.setLineWidth:
  6476. this.setLineWidth(args[0]);
  6477. break;
  6478. case OPS.setLineJoin:
  6479. this.setLineJoin(args[0]);
  6480. break;
  6481. case OPS.setLineCap:
  6482. this.setLineCap(args[0]);
  6483. break;
  6484. case OPS.setMiterLimit:
  6485. this.setMiterLimit(args[0]);
  6486. break;
  6487. case OPS.setFillRGBColor:
  6488. this.setFillRGBColor(args[0], args[1], args[2]);
  6489. break;
  6490. case OPS.setStrokeRGBColor:
  6491. this.setStrokeRGBColor(args[0], args[1], args[2]);
  6492. break;
  6493. case OPS.setDash:
  6494. this.setDash(args[0], args[1]);
  6495. break;
  6496. case OPS.setGState:
  6497. this.setGState(args[0]);
  6498. break;
  6499. case OPS.fill:
  6500. this.fill();
  6501. break;
  6502. case OPS.eoFill:
  6503. this.eoFill();
  6504. break;
  6505. case OPS.stroke:
  6506. this.stroke();
  6507. break;
  6508. case OPS.fillStroke:
  6509. this.fillStroke();
  6510. break;
  6511. case OPS.eoFillStroke:
  6512. this.eoFillStroke();
  6513. break;
  6514. case OPS.clip:
  6515. this.clip('nonzero');
  6516. break;
  6517. case OPS.eoClip:
  6518. this.clip('evenodd');
  6519. break;
  6520. case OPS.paintSolidColorImageMask:
  6521. this.paintSolidColorImageMask();
  6522. break;
  6523. case OPS.paintJpegXObject:
  6524. this.paintJpegXObject(args[0], args[1], args[2]);
  6525. break;
  6526. case OPS.paintImageXObject:
  6527. this.paintImageXObject(args[0]);
  6528. break;
  6529. case OPS.paintInlineImageXObject:
  6530. this.paintInlineImageXObject(args[0]);
  6531. break;
  6532. case OPS.paintImageMaskXObject:
  6533. this.paintImageMaskXObject(args[0]);
  6534. break;
  6535. case OPS.paintFormXObjectBegin:
  6536. this.paintFormXObjectBegin(args[0], args[1]);
  6537. break;
  6538. case OPS.paintFormXObjectEnd:
  6539. this.paintFormXObjectEnd();
  6540. break;
  6541. case OPS.closePath:
  6542. this.closePath();
  6543. break;
  6544. case OPS.closeStroke:
  6545. this.closeStroke();
  6546. break;
  6547. case OPS.closeFillStroke:
  6548. this.closeFillStroke();
  6549. break;
  6550. case OPS.nextLine:
  6551. this.nextLine();
  6552. break;
  6553. case OPS.transform:
  6554. this.transform(args[0], args[1], args[2], args[3],
  6555. args[4], args[5]);
  6556. break;
  6557. case OPS.constructPath:
  6558. this.constructPath(args[0], args[1]);
  6559. break;
  6560. case OPS.endPath:
  6561. this.endPath();
  6562. break;
  6563. case 92:
  6564. this.group(opTree[x].items);
  6565. break;
  6566. default:
  6567. warn('Unimplemented method '+ fn);
  6568. break;
  6569. }
  6570. }
  6571. },
  6572. setWordSpacing: function SVGGraphics_setWordSpacing(wordSpacing) {
  6573. this.current.wordSpacing = wordSpacing;
  6574. },
  6575. setCharSpacing: function SVGGraphics_setCharSpacing(charSpacing) {
  6576. this.current.charSpacing = charSpacing;
  6577. },
  6578. nextLine: function SVGGraphics_nextLine() {
  6579. this.moveText(0, this.current.leading);
  6580. },
  6581. setTextMatrix: function SVGGraphics_setTextMatrix(a, b, c, d, e, f) {
  6582. var current = this.current;
  6583. this.current.textMatrix = this.current.lineMatrix = [a, b, c, d, e, f];
  6584. this.current.x = this.current.lineX = 0;
  6585. this.current.y = this.current.lineY = 0;
  6586. current.xcoords = [];
  6587. current.tspan = document.createElementNS(NS, 'svg:tspan');
  6588. current.tspan.setAttributeNS(null, 'font-family', current.fontFamily);
  6589. current.tspan.setAttributeNS(null, 'font-size',
  6590. pf(current.fontSize) + 'px');
  6591. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  6592. current.txtElement = document.createElementNS(NS, 'svg:text');
  6593. current.txtElement.appendChild(current.tspan);
  6594. },
  6595. beginText: function SVGGraphics_beginText() {
  6596. this.current.x = this.current.lineX = 0;
  6597. this.current.y = this.current.lineY = 0;
  6598. this.current.textMatrix = IDENTITY_MATRIX;
  6599. this.current.lineMatrix = IDENTITY_MATRIX;
  6600. this.current.tspan = document.createElementNS(NS, 'svg:tspan');
  6601. this.current.txtElement = document.createElementNS(NS, 'svg:text');
  6602. this.current.txtgrp = document.createElementNS(NS, 'svg:g');
  6603. this.current.xcoords = [];
  6604. },
  6605. moveText: function SVGGraphics_moveText(x, y) {
  6606. var current = this.current;
  6607. this.current.x = this.current.lineX += x;
  6608. this.current.y = this.current.lineY += y;
  6609. current.xcoords = [];
  6610. current.tspan = document.createElementNS(NS, 'svg:tspan');
  6611. current.tspan.setAttributeNS(null, 'font-family', current.fontFamily);
  6612. current.tspan.setAttributeNS(null, 'font-size',
  6613. pf(current.fontSize) + 'px');
  6614. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  6615. },
  6616. showText: function SVGGraphics_showText(glyphs) {
  6617. var current = this.current;
  6618. var font = current.font;
  6619. var fontSize = current.fontSize;
  6620. if (fontSize === 0) {
  6621. return;
  6622. }
  6623. var charSpacing = current.charSpacing;
  6624. var wordSpacing = current.wordSpacing;
  6625. var fontDirection = current.fontDirection;
  6626. var textHScale = current.textHScale * fontDirection;
  6627. var glyphsLength = glyphs.length;
  6628. var vertical = font.vertical;
  6629. var widthAdvanceScale = fontSize * current.fontMatrix[0];
  6630. var x = 0, i;
  6631. for (i = 0; i < glyphsLength; ++i) {
  6632. var glyph = glyphs[i];
  6633. if (glyph === null) {
  6634. // word break
  6635. x += fontDirection * wordSpacing;
  6636. continue;
  6637. } else if (isNum(glyph)) {
  6638. x += -glyph * fontSize * 0.001;
  6639. continue;
  6640. }
  6641. current.xcoords.push(current.x + x * textHScale);
  6642. var width = glyph.width;
  6643. var character = glyph.fontChar;
  6644. var charWidth = width * widthAdvanceScale + charSpacing * fontDirection;
  6645. x += charWidth;
  6646. current.tspan.textContent += character;
  6647. }
  6648. if (vertical) {
  6649. current.y -= x * textHScale;
  6650. } else {
  6651. current.x += x * textHScale;
  6652. }
  6653. current.tspan.setAttributeNS(null, 'x',
  6654. current.xcoords.map(pf).join(' '));
  6655. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  6656. current.tspan.setAttributeNS(null, 'font-family', current.fontFamily);
  6657. current.tspan.setAttributeNS(null, 'font-size',
  6658. pf(current.fontSize) + 'px');
  6659. if (current.fontStyle !== SVG_DEFAULTS.fontStyle) {
  6660. current.tspan.setAttributeNS(null, 'font-style', current.fontStyle);
  6661. }
  6662. if (current.fontWeight !== SVG_DEFAULTS.fontWeight) {
  6663. current.tspan.setAttributeNS(null, 'font-weight', current.fontWeight);
  6664. }
  6665. if (current.fillColor !== SVG_DEFAULTS.fillColor) {
  6666. current.tspan.setAttributeNS(null, 'fill', current.fillColor);
  6667. }
  6668. current.txtElement.setAttributeNS(null, 'transform',
  6669. pm(current.textMatrix) +
  6670. ' scale(1, -1)' );
  6671. current.txtElement.setAttributeNS(XML_NS, 'xml:space', 'preserve');
  6672. current.txtElement.appendChild(current.tspan);
  6673. current.txtgrp.appendChild(current.txtElement);
  6674. this.tgrp.appendChild(current.txtElement);
  6675. },
  6676. setLeadingMoveText: function SVGGraphics_setLeadingMoveText(x, y) {
  6677. this.setLeading(-y);
  6678. this.moveText(x, y);
  6679. },
  6680. addFontStyle: function SVGGraphics_addFontStyle(fontObj) {
  6681. if (!this.cssStyle) {
  6682. this.cssStyle = document.createElementNS(NS, 'svg:style');
  6683. this.cssStyle.setAttributeNS(null, 'type', 'text/css');
  6684. this.defs.appendChild(this.cssStyle);
  6685. }
  6686. var url = PDFJS.createObjectURL(fontObj.data, fontObj.mimetype);
  6687. this.cssStyle.textContent +=
  6688. '@font-face { font-family: "' + fontObj.loadedName + '";' +
  6689. ' src: url(' + url + '); }\n';
  6690. },
  6691. setFont: function SVGGraphics_setFont(details) {
  6692. var current = this.current;
  6693. var fontObj = this.commonObjs.get(details[0]);
  6694. var size = details[1];
  6695. this.current.font = fontObj;
  6696. if (this.embedFonts && fontObj.data &&
  6697. !this.embeddedFonts[fontObj.loadedName]) {
  6698. this.addFontStyle(fontObj);
  6699. this.embeddedFonts[fontObj.loadedName] = fontObj;
  6700. }
  6701. current.fontMatrix = (fontObj.fontMatrix ?
  6702. fontObj.fontMatrix : FONT_IDENTITY_MATRIX);
  6703. var bold = fontObj.black ? (fontObj.bold ? 'bolder' : 'bold') :
  6704. (fontObj.bold ? 'bold' : 'normal');
  6705. var italic = fontObj.italic ? 'italic' : 'normal';
  6706. if (size < 0) {
  6707. size = -size;
  6708. current.fontDirection = -1;
  6709. } else {
  6710. current.fontDirection = 1;
  6711. }
  6712. current.fontSize = size;
  6713. current.fontFamily = fontObj.loadedName;
  6714. current.fontWeight = bold;
  6715. current.fontStyle = italic;
  6716. current.tspan = document.createElementNS(NS, 'svg:tspan');
  6717. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  6718. current.xcoords = [];
  6719. },
  6720. endText: function SVGGraphics_endText() {
  6721. if (this.current.pendingClip) {
  6722. this.cgrp.appendChild(this.tgrp);
  6723. this.pgrp.appendChild(this.cgrp);
  6724. } else {
  6725. this.pgrp.appendChild(this.tgrp);
  6726. }
  6727. this.tgrp = document.createElementNS(NS, 'svg:g');
  6728. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  6729. },
  6730. // Path properties
  6731. setLineWidth: function SVGGraphics_setLineWidth(width) {
  6732. this.current.lineWidth = width;
  6733. },
  6734. setLineCap: function SVGGraphics_setLineCap(style) {
  6735. this.current.lineCap = LINE_CAP_STYLES[style];
  6736. },
  6737. setLineJoin: function SVGGraphics_setLineJoin(style) {
  6738. this.current.lineJoin = LINE_JOIN_STYLES[style];
  6739. },
  6740. setMiterLimit: function SVGGraphics_setMiterLimit(limit) {
  6741. this.current.miterLimit = limit;
  6742. },
  6743. setStrokeRGBColor: function SVGGraphics_setStrokeRGBColor(r, g, b) {
  6744. var color = Util.makeCssRgb(r, g, b);
  6745. this.current.strokeColor = color;
  6746. },
  6747. setFillRGBColor: function SVGGraphics_setFillRGBColor(r, g, b) {
  6748. var color = Util.makeCssRgb(r, g, b);
  6749. this.current.fillColor = color;
  6750. this.current.tspan = document.createElementNS(NS, 'svg:tspan');
  6751. this.current.xcoords = [];
  6752. },
  6753. setDash: function SVGGraphics_setDash(dashArray, dashPhase) {
  6754. this.current.dashArray = dashArray;
  6755. this.current.dashPhase = dashPhase;
  6756. },
  6757. constructPath: function SVGGraphics_constructPath(ops, args) {
  6758. var current = this.current;
  6759. var x = current.x, y = current.y;
  6760. current.path = document.createElementNS(NS, 'svg:path');
  6761. var d = [];
  6762. var opLength = ops.length;
  6763. for (var i = 0, j = 0; i < opLength; i++) {
  6764. switch (ops[i] | 0) {
  6765. case OPS.rectangle:
  6766. x = args[j++];
  6767. y = args[j++];
  6768. var width = args[j++];
  6769. var height = args[j++];
  6770. var xw = x + width;
  6771. var yh = y + height;
  6772. d.push('M', pf(x), pf(y), 'L', pf(xw) , pf(y), 'L', pf(xw), pf(yh),
  6773. 'L', pf(x), pf(yh), 'Z');
  6774. break;
  6775. case OPS.moveTo:
  6776. x = args[j++];
  6777. y = args[j++];
  6778. d.push('M', pf(x), pf(y));
  6779. break;
  6780. case OPS.lineTo:
  6781. x = args[j++];
  6782. y = args[j++];
  6783. d.push('L', pf(x) , pf(y));
  6784. break;
  6785. case OPS.curveTo:
  6786. x = args[j + 4];
  6787. y = args[j + 5];
  6788. d.push('C', pf(args[j]), pf(args[j + 1]), pf(args[j + 2]),
  6789. pf(args[j + 3]), pf(x), pf(y));
  6790. j += 6;
  6791. break;
  6792. case OPS.curveTo2:
  6793. x = args[j + 2];
  6794. y = args[j + 3];
  6795. d.push('C', pf(x), pf(y), pf(args[j]), pf(args[j + 1]),
  6796. pf(args[j + 2]), pf(args[j + 3]));
  6797. j += 4;
  6798. break;
  6799. case OPS.curveTo3:
  6800. x = args[j + 2];
  6801. y = args[j + 3];
  6802. d.push('C', pf(args[j]), pf(args[j + 1]), pf(x), pf(y),
  6803. pf(x), pf(y));
  6804. j += 4;
  6805. break;
  6806. case OPS.closePath:
  6807. d.push('Z');
  6808. break;
  6809. }
  6810. }
  6811. current.path.setAttributeNS(null, 'd', d.join(' '));
  6812. current.path.setAttributeNS(null, 'stroke-miterlimit',
  6813. pf(current.miterLimit));
  6814. current.path.setAttributeNS(null, 'stroke-linecap', current.lineCap);
  6815. current.path.setAttributeNS(null, 'stroke-linejoin', current.lineJoin);
  6816. current.path.setAttributeNS(null, 'stroke-width',
  6817. pf(current.lineWidth) + 'px');
  6818. current.path.setAttributeNS(null, 'stroke-dasharray',
  6819. current.dashArray.map(pf).join(' '));
  6820. current.path.setAttributeNS(null, 'stroke-dashoffset',
  6821. pf(current.dashPhase) + 'px');
  6822. current.path.setAttributeNS(null, 'fill', 'none');
  6823. this.tgrp.appendChild(current.path);
  6824. if (current.pendingClip) {
  6825. this.cgrp.appendChild(this.tgrp);
  6826. this.pgrp.appendChild(this.cgrp);
  6827. } else {
  6828. this.pgrp.appendChild(this.tgrp);
  6829. }
  6830. // Saving a reference in current.element so that it can be addressed
  6831. // in 'fill' and 'stroke'
  6832. current.element = current.path;
  6833. current.setCurrentPoint(x, y);
  6834. },
  6835. endPath: function SVGGraphics_endPath() {
  6836. var current = this.current;
  6837. if (current.pendingClip) {
  6838. this.cgrp.appendChild(this.tgrp);
  6839. this.pgrp.appendChild(this.cgrp);
  6840. } else {
  6841. this.pgrp.appendChild(this.tgrp);
  6842. }
  6843. this.tgrp = document.createElementNS(NS, 'svg:g');
  6844. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  6845. },
  6846. clip: function SVGGraphics_clip(type) {
  6847. var current = this.current;
  6848. // Add current path to clipping path
  6849. current.clipId = 'clippath' + clipCount;
  6850. clipCount++;
  6851. this.clippath = document.createElementNS(NS, 'svg:clipPath');
  6852. this.clippath.setAttributeNS(null, 'id', current.clipId);
  6853. var clipElement = current.element.cloneNode();
  6854. if (type === 'evenodd') {
  6855. clipElement.setAttributeNS(null, 'clip-rule', 'evenodd');
  6856. } else {
  6857. clipElement.setAttributeNS(null, 'clip-rule', 'nonzero');
  6858. }
  6859. this.clippath.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  6860. this.clippath.appendChild(clipElement);
  6861. this.defs.appendChild(this.clippath);
  6862. // Create a new group with that attribute
  6863. current.pendingClip = true;
  6864. this.cgrp = document.createElementNS(NS, 'svg:g');
  6865. this.cgrp.setAttributeNS(null, 'clip-path',
  6866. 'url(#' + current.clipId + ')');
  6867. this.pgrp.appendChild(this.cgrp);
  6868. },
  6869. closePath: function SVGGraphics_closePath() {
  6870. var current = this.current;
  6871. var d = current.path.getAttributeNS(null, 'd');
  6872. d += 'Z';
  6873. current.path.setAttributeNS(null, 'd', d);
  6874. },
  6875. setLeading: function SVGGraphics_setLeading(leading) {
  6876. this.current.leading = -leading;
  6877. },
  6878. setTextRise: function SVGGraphics_setTextRise(textRise) {
  6879. this.current.textRise = textRise;
  6880. },
  6881. setHScale: function SVGGraphics_setHScale(scale) {
  6882. this.current.textHScale = scale / 100;
  6883. },
  6884. setGState: function SVGGraphics_setGState(states) {
  6885. for (var i = 0, ii = states.length; i < ii; i++) {
  6886. var state = states[i];
  6887. var key = state[0];
  6888. var value = state[1];
  6889. switch (key) {
  6890. case 'LW':
  6891. this.setLineWidth(value);
  6892. break;
  6893. case 'LC':
  6894. this.setLineCap(value);
  6895. break;
  6896. case 'LJ':
  6897. this.setLineJoin(value);
  6898. break;
  6899. case 'ML':
  6900. this.setMiterLimit(value);
  6901. break;
  6902. case 'D':
  6903. this.setDash(value[0], value[1]);
  6904. break;
  6905. case 'RI':
  6906. break;
  6907. case 'FL':
  6908. break;
  6909. case 'Font':
  6910. this.setFont(value);
  6911. break;
  6912. case 'CA':
  6913. break;
  6914. case 'ca':
  6915. break;
  6916. case 'BM':
  6917. break;
  6918. case 'SMask':
  6919. break;
  6920. }
  6921. }
  6922. },
  6923. fill: function SVGGraphics_fill() {
  6924. var current = this.current;
  6925. current.element.setAttributeNS(null, 'fill', current.fillColor);
  6926. },
  6927. stroke: function SVGGraphics_stroke() {
  6928. var current = this.current;
  6929. current.element.setAttributeNS(null, 'stroke', current.strokeColor);
  6930. current.element.setAttributeNS(null, 'fill', 'none');
  6931. },
  6932. eoFill: function SVGGraphics_eoFill() {
  6933. var current = this.current;
  6934. current.element.setAttributeNS(null, 'fill', current.fillColor);
  6935. current.element.setAttributeNS(null, 'fill-rule', 'evenodd');
  6936. },
  6937. fillStroke: function SVGGraphics_fillStroke() {
  6938. // Order is important since stroke wants fill to be none.
  6939. // First stroke, then if fill needed, it will be overwritten.
  6940. this.stroke();
  6941. this.fill();
  6942. },
  6943. eoFillStroke: function SVGGraphics_eoFillStroke() {
  6944. this.current.element.setAttributeNS(null, 'fill-rule', 'evenodd');
  6945. this.fillStroke();
  6946. },
  6947. closeStroke: function SVGGraphics_closeStroke() {
  6948. this.closePath();
  6949. this.stroke();
  6950. },
  6951. closeFillStroke: function SVGGraphics_closeFillStroke() {
  6952. this.closePath();
  6953. this.fillStroke();
  6954. },
  6955. paintSolidColorImageMask:
  6956. function SVGGraphics_paintSolidColorImageMask() {
  6957. var current = this.current;
  6958. var rect = document.createElementNS(NS, 'svg:rect');
  6959. rect.setAttributeNS(null, 'x', '0');
  6960. rect.setAttributeNS(null, 'y', '0');
  6961. rect.setAttributeNS(null, 'width', '1px');
  6962. rect.setAttributeNS(null, 'height', '1px');
  6963. rect.setAttributeNS(null, 'fill', current.fillColor);
  6964. this.tgrp.appendChild(rect);
  6965. },
  6966. paintJpegXObject: function SVGGraphics_paintJpegXObject(objId, w, h) {
  6967. var current = this.current;
  6968. var imgObj = this.objs.get(objId);
  6969. var imgEl = document.createElementNS(NS, 'svg:image');
  6970. imgEl.setAttributeNS(XLINK_NS, 'xlink:href', imgObj.src);
  6971. imgEl.setAttributeNS(null, 'width', imgObj.width + 'px');
  6972. imgEl.setAttributeNS(null, 'height', imgObj.height + 'px');
  6973. imgEl.setAttributeNS(null, 'x', '0');
  6974. imgEl.setAttributeNS(null, 'y', pf(-h));
  6975. imgEl.setAttributeNS(null, 'transform',
  6976. 'scale(' + pf(1 / w) + ' ' + pf(-1 / h) + ')');
  6977. this.tgrp.appendChild(imgEl);
  6978. if (current.pendingClip) {
  6979. this.cgrp.appendChild(this.tgrp);
  6980. this.pgrp.appendChild(this.cgrp);
  6981. } else {
  6982. this.pgrp.appendChild(this.tgrp);
  6983. }
  6984. },
  6985. paintImageXObject: function SVGGraphics_paintImageXObject(objId) {
  6986. var imgData = this.objs.get(objId);
  6987. if (!imgData) {
  6988. warn('Dependent image isn\'t ready yet');
  6989. return;
  6990. }
  6991. this.paintInlineImageXObject(imgData);
  6992. },
  6993. paintInlineImageXObject:
  6994. function SVGGraphics_paintInlineImageXObject(imgData, mask) {
  6995. var current = this.current;
  6996. var width = imgData.width;
  6997. var height = imgData.height;
  6998. var imgSrc = convertImgDataToPng(imgData);
  6999. var cliprect = document.createElementNS(NS, 'svg:rect');
  7000. cliprect.setAttributeNS(null, 'x', '0');
  7001. cliprect.setAttributeNS(null, 'y', '0');
  7002. cliprect.setAttributeNS(null, 'width', pf(width));
  7003. cliprect.setAttributeNS(null, 'height', pf(height));
  7004. current.element = cliprect;
  7005. this.clip('nonzero');
  7006. var imgEl = document.createElementNS(NS, 'svg:image');
  7007. imgEl.setAttributeNS(XLINK_NS, 'xlink:href', imgSrc);
  7008. imgEl.setAttributeNS(null, 'x', '0');
  7009. imgEl.setAttributeNS(null, 'y', pf(-height));
  7010. imgEl.setAttributeNS(null, 'width', pf(width) + 'px');
  7011. imgEl.setAttributeNS(null, 'height', pf(height) + 'px');
  7012. imgEl.setAttributeNS(null, 'transform',
  7013. 'scale(' + pf(1 / width) + ' ' +
  7014. pf(-1 / height) + ')');
  7015. if (mask) {
  7016. mask.appendChild(imgEl);
  7017. } else {
  7018. this.tgrp.appendChild(imgEl);
  7019. }
  7020. if (current.pendingClip) {
  7021. this.cgrp.appendChild(this.tgrp);
  7022. this.pgrp.appendChild(this.cgrp);
  7023. } else {
  7024. this.pgrp.appendChild(this.tgrp);
  7025. }
  7026. },
  7027. paintImageMaskXObject:
  7028. function SVGGraphics_paintImageMaskXObject(imgData) {
  7029. var current = this.current;
  7030. var width = imgData.width;
  7031. var height = imgData.height;
  7032. var fillColor = current.fillColor;
  7033. current.maskId = 'mask' + maskCount++;
  7034. var mask = document.createElementNS(NS, 'svg:mask');
  7035. mask.setAttributeNS(null, 'id', current.maskId);
  7036. var rect = document.createElementNS(NS, 'svg:rect');
  7037. rect.setAttributeNS(null, 'x', '0');
  7038. rect.setAttributeNS(null, 'y', '0');
  7039. rect.setAttributeNS(null, 'width', pf(width));
  7040. rect.setAttributeNS(null, 'height', pf(height));
  7041. rect.setAttributeNS(null, 'fill', fillColor);
  7042. rect.setAttributeNS(null, 'mask', 'url(#' + current.maskId +')');
  7043. this.defs.appendChild(mask);
  7044. this.tgrp.appendChild(rect);
  7045. this.paintInlineImageXObject(imgData, mask);
  7046. },
  7047. paintFormXObjectBegin:
  7048. function SVGGraphics_paintFormXObjectBegin(matrix, bbox) {
  7049. this.save();
  7050. if (isArray(matrix) && matrix.length === 6) {
  7051. this.transform(matrix[0], matrix[1], matrix[2],
  7052. matrix[3], matrix[4], matrix[5]);
  7053. }
  7054. if (isArray(bbox) && bbox.length === 4) {
  7055. var width = bbox[2] - bbox[0];
  7056. var height = bbox[3] - bbox[1];
  7057. var cliprect = document.createElementNS(NS, 'svg:rect');
  7058. cliprect.setAttributeNS(null, 'x', bbox[0]);
  7059. cliprect.setAttributeNS(null, 'y', bbox[1]);
  7060. cliprect.setAttributeNS(null, 'width', pf(width));
  7061. cliprect.setAttributeNS(null, 'height', pf(height));
  7062. this.current.element = cliprect;
  7063. this.clip('nonzero');
  7064. this.endPath();
  7065. }
  7066. },
  7067. paintFormXObjectEnd:
  7068. function SVGGraphics_paintFormXObjectEnd() {
  7069. this.restore();
  7070. }
  7071. };
  7072. return SVGGraphics;
  7073. })();
  7074. PDFJS.SVGGraphics = SVGGraphics;
  7075. var NetworkManager = (function NetworkManagerClosure() {
  7076. var OK_RESPONSE = 200;
  7077. var PARTIAL_CONTENT_RESPONSE = 206;
  7078. function NetworkManager(url, args) {
  7079. this.url = url;
  7080. args = args || {};
  7081. this.isHttp = /^https?:/i.test(url);
  7082. this.httpHeaders = (this.isHttp && args.httpHeaders) || {};
  7083. this.withCredentials = args.withCredentials || false;
  7084. this.getXhr = args.getXhr ||
  7085. function NetworkManager_getXhr() {
  7086. return new XMLHttpRequest();
  7087. };
  7088. this.currXhrId = 0;
  7089. this.pendingRequests = {};
  7090. this.loadedRequests = {};
  7091. }
  7092. function getArrayBuffer(xhr) {
  7093. var data = xhr.response;
  7094. if (typeof data !== 'string') {
  7095. return data;
  7096. }
  7097. var length = data.length;
  7098. var array = new Uint8Array(length);
  7099. for (var i = 0; i < length; i++) {
  7100. array[i] = data.charCodeAt(i) & 0xFF;
  7101. }
  7102. return array.buffer;
  7103. }
  7104. NetworkManager.prototype = {
  7105. requestRange: function NetworkManager_requestRange(begin, end, listeners) {
  7106. var args = {
  7107. begin: begin,
  7108. end: end
  7109. };
  7110. for (var prop in listeners) {
  7111. args[prop] = listeners[prop];
  7112. }
  7113. return this.request(args);
  7114. },
  7115. requestFull: function NetworkManager_requestFull(listeners) {
  7116. return this.request(listeners);
  7117. },
  7118. request: function NetworkManager_request(args) {
  7119. var xhr = this.getXhr();
  7120. var xhrId = this.currXhrId++;
  7121. var pendingRequest = this.pendingRequests[xhrId] = {
  7122. xhr: xhr
  7123. };
  7124. xhr.open('GET', this.url);
  7125. xhr.withCredentials = this.withCredentials;
  7126. for (var property in this.httpHeaders) {
  7127. var value = this.httpHeaders[property];
  7128. if (typeof value === 'undefined') {
  7129. continue;
  7130. }
  7131. xhr.setRequestHeader(property, value);
  7132. }
  7133. if (this.isHttp && 'begin' in args && 'end' in args) {
  7134. var rangeStr = args.begin + '-' + (args.end - 1);
  7135. xhr.setRequestHeader('Range', 'bytes=' + rangeStr);
  7136. pendingRequest.expectedStatus = 206;
  7137. } else {
  7138. pendingRequest.expectedStatus = 200;
  7139. }
  7140. if (args.onProgressiveData) {
  7141. // Some legacy browsers might throw an exception.
  7142. try {
  7143. xhr.responseType = 'moz-chunked-arraybuffer';
  7144. } catch(e) {}
  7145. if (xhr.responseType === 'moz-chunked-arraybuffer') {
  7146. pendingRequest.onProgressiveData = args.onProgressiveData;
  7147. pendingRequest.mozChunked = true;
  7148. } else {
  7149. xhr.responseType = 'arraybuffer';
  7150. }
  7151. } else {
  7152. xhr.responseType = 'arraybuffer';
  7153. }
  7154. if (args.onError) {
  7155. xhr.onerror = function(evt) {
  7156. args.onError(xhr.status);
  7157. };
  7158. }
  7159. xhr.onreadystatechange = this.onStateChange.bind(this, xhrId);
  7160. xhr.onprogress = this.onProgress.bind(this, xhrId);
  7161. pendingRequest.onHeadersReceived = args.onHeadersReceived;
  7162. pendingRequest.onDone = args.onDone;
  7163. pendingRequest.onError = args.onError;
  7164. pendingRequest.onProgress = args.onProgress;
  7165. xhr.send(null);
  7166. return xhrId;
  7167. },
  7168. onProgress: function NetworkManager_onProgress(xhrId, evt) {
  7169. var pendingRequest = this.pendingRequests[xhrId];
  7170. if (!pendingRequest) {
  7171. // Maybe abortRequest was called...
  7172. return;
  7173. }
  7174. if (pendingRequest.mozChunked) {
  7175. var chunk = getArrayBuffer(pendingRequest.xhr);
  7176. pendingRequest.onProgressiveData(chunk);
  7177. }
  7178. var onProgress = pendingRequest.onProgress;
  7179. if (onProgress) {
  7180. onProgress(evt);
  7181. }
  7182. },
  7183. onStateChange: function NetworkManager_onStateChange(xhrId, evt) {
  7184. var pendingRequest = this.pendingRequests[xhrId];
  7185. if (!pendingRequest) {
  7186. // Maybe abortRequest was called...
  7187. return;
  7188. }
  7189. var xhr = pendingRequest.xhr;
  7190. if (xhr.readyState >= 2 && pendingRequest.onHeadersReceived) {
  7191. pendingRequest.onHeadersReceived();
  7192. delete pendingRequest.onHeadersReceived;
  7193. }
  7194. if (xhr.readyState !== 4) {
  7195. return;
  7196. }
  7197. if (!(xhrId in this.pendingRequests)) {
  7198. // The XHR request might have been aborted in onHeadersReceived()
  7199. // callback, in which case we should abort request
  7200. return;
  7201. }
  7202. delete this.pendingRequests[xhrId];
  7203. // success status == 0 can be on ftp, file and other protocols
  7204. if (xhr.status === 0 && this.isHttp) {
  7205. if (pendingRequest.onError) {
  7206. pendingRequest.onError(xhr.status);
  7207. }
  7208. return;
  7209. }
  7210. var xhrStatus = xhr.status || OK_RESPONSE;
  7211. // From http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35.2:
  7212. // "A server MAY ignore the Range header". This means it's possible to
  7213. // get a 200 rather than a 206 response from a range request.
  7214. var ok_response_on_range_request =
  7215. xhrStatus === OK_RESPONSE &&
  7216. pendingRequest.expectedStatus === PARTIAL_CONTENT_RESPONSE;
  7217. if (!ok_response_on_range_request &&
  7218. xhrStatus !== pendingRequest.expectedStatus) {
  7219. if (pendingRequest.onError) {
  7220. pendingRequest.onError(xhr.status);
  7221. }
  7222. return;
  7223. }
  7224. this.loadedRequests[xhrId] = true;
  7225. var chunk = getArrayBuffer(xhr);
  7226. if (xhrStatus === PARTIAL_CONTENT_RESPONSE) {
  7227. var rangeHeader = xhr.getResponseHeader('Content-Range');
  7228. var matches = /bytes (\d+)-(\d+)\/(\d+)/.exec(rangeHeader);
  7229. var begin = parseInt(matches[1], 10);
  7230. pendingRequest.onDone({
  7231. begin: begin,
  7232. chunk: chunk
  7233. });
  7234. } else if (pendingRequest.onProgressiveData) {
  7235. pendingRequest.onDone(null);
  7236. } else {
  7237. pendingRequest.onDone({
  7238. begin: 0,
  7239. chunk: chunk
  7240. });
  7241. }
  7242. },
  7243. hasPendingRequests: function NetworkManager_hasPendingRequests() {
  7244. for (var xhrId in this.pendingRequests) {
  7245. return true;
  7246. }
  7247. return false;
  7248. },
  7249. getRequestXhr: function NetworkManager_getXhr(xhrId) {
  7250. return this.pendingRequests[xhrId].xhr;
  7251. },
  7252. isStreamingRequest: function NetworkManager_isStreamingRequest(xhrId) {
  7253. return !!(this.pendingRequests[xhrId].onProgressiveData);
  7254. },
  7255. isPendingRequest: function NetworkManager_isPendingRequest(xhrId) {
  7256. return xhrId in this.pendingRequests;
  7257. },
  7258. isLoadedRequest: function NetworkManager_isLoadedRequest(xhrId) {
  7259. return xhrId in this.loadedRequests;
  7260. },
  7261. abortAllRequests: function NetworkManager_abortAllRequests() {
  7262. for (var xhrId in this.pendingRequests) {
  7263. this.abortRequest(xhrId | 0);
  7264. }
  7265. },
  7266. abortRequest: function NetworkManager_abortRequest(xhrId) {
  7267. var xhr = this.pendingRequests[xhrId].xhr;
  7268. delete this.pendingRequests[xhrId];
  7269. xhr.abort();
  7270. }
  7271. };
  7272. return NetworkManager;
  7273. })();
  7274. var ChunkedStream = (function ChunkedStreamClosure() {
  7275. function ChunkedStream(length, chunkSize, manager) {
  7276. this.bytes = new Uint8Array(length);
  7277. this.start = 0;
  7278. this.pos = 0;
  7279. this.end = length;
  7280. this.chunkSize = chunkSize;
  7281. this.loadedChunks = [];
  7282. this.numChunksLoaded = 0;
  7283. this.numChunks = Math.ceil(length / chunkSize);
  7284. this.manager = manager;
  7285. this.progressiveDataLength = 0;
  7286. this.lastSuccessfulEnsureByteChunk = -1; // a single-entry cache
  7287. }
  7288. // required methods for a stream. if a particular stream does not
  7289. // implement these, an error should be thrown
  7290. ChunkedStream.prototype = {
  7291. getMissingChunks: function ChunkedStream_getMissingChunks() {
  7292. var chunks = [];
  7293. for (var chunk = 0, n = this.numChunks; chunk < n; ++chunk) {
  7294. if (!this.loadedChunks[chunk]) {
  7295. chunks.push(chunk);
  7296. }
  7297. }
  7298. return chunks;
  7299. },
  7300. getBaseStreams: function ChunkedStream_getBaseStreams() {
  7301. return [this];
  7302. },
  7303. allChunksLoaded: function ChunkedStream_allChunksLoaded() {
  7304. return this.numChunksLoaded === this.numChunks;
  7305. },
  7306. onReceiveData: function ChunkedStream_onReceiveData(begin, chunk) {
  7307. var end = begin + chunk.byteLength;
  7308. assert(begin % this.chunkSize === 0, 'Bad begin offset: ' + begin);
  7309. // Using this.length is inaccurate here since this.start can be moved
  7310. // See ChunkedStream.moveStart()
  7311. var length = this.bytes.length;
  7312. assert(end % this.chunkSize === 0 || end === length,
  7313. 'Bad end offset: ' + end);
  7314. this.bytes.set(new Uint8Array(chunk), begin);
  7315. var chunkSize = this.chunkSize;
  7316. var beginChunk = Math.floor(begin / chunkSize);
  7317. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  7318. var curChunk;
  7319. for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  7320. if (!this.loadedChunks[curChunk]) {
  7321. this.loadedChunks[curChunk] = true;
  7322. ++this.numChunksLoaded;
  7323. }
  7324. }
  7325. },
  7326. onReceiveProgressiveData:
  7327. function ChunkedStream_onReceiveProgressiveData(data) {
  7328. var position = this.progressiveDataLength;
  7329. var beginChunk = Math.floor(position / this.chunkSize);
  7330. this.bytes.set(new Uint8Array(data), position);
  7331. position += data.byteLength;
  7332. this.progressiveDataLength = position;
  7333. var endChunk = position >= this.end ? this.numChunks :
  7334. Math.floor(position / this.chunkSize);
  7335. var curChunk;
  7336. for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  7337. if (!this.loadedChunks[curChunk]) {
  7338. this.loadedChunks[curChunk] = true;
  7339. ++this.numChunksLoaded;
  7340. }
  7341. }
  7342. },
  7343. ensureByte: function ChunkedStream_ensureByte(pos) {
  7344. var chunk = Math.floor(pos / this.chunkSize);
  7345. if (chunk === this.lastSuccessfulEnsureByteChunk) {
  7346. return;
  7347. }
  7348. if (!this.loadedChunks[chunk]) {
  7349. throw new MissingDataException(pos, pos + 1);
  7350. }
  7351. this.lastSuccessfulEnsureByteChunk = chunk;
  7352. },
  7353. ensureRange: function ChunkedStream_ensureRange(begin, end) {
  7354. if (begin >= end) {
  7355. return;
  7356. }
  7357. if (end <= this.progressiveDataLength) {
  7358. return;
  7359. }
  7360. var chunkSize = this.chunkSize;
  7361. var beginChunk = Math.floor(begin / chunkSize);
  7362. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  7363. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  7364. if (!this.loadedChunks[chunk]) {
  7365. throw new MissingDataException(begin, end);
  7366. }
  7367. }
  7368. },
  7369. nextEmptyChunk: function ChunkedStream_nextEmptyChunk(beginChunk) {
  7370. var chunk, n;
  7371. for (chunk = beginChunk, n = this.numChunks; chunk < n; ++chunk) {
  7372. if (!this.loadedChunks[chunk]) {
  7373. return chunk;
  7374. }
  7375. }
  7376. // Wrap around to beginning
  7377. for (chunk = 0; chunk < beginChunk; ++chunk) {
  7378. if (!this.loadedChunks[chunk]) {
  7379. return chunk;
  7380. }
  7381. }
  7382. return null;
  7383. },
  7384. hasChunk: function ChunkedStream_hasChunk(chunk) {
  7385. return !!this.loadedChunks[chunk];
  7386. },
  7387. get length() {
  7388. return this.end - this.start;
  7389. },
  7390. get isEmpty() {
  7391. return this.length === 0;
  7392. },
  7393. getByte: function ChunkedStream_getByte() {
  7394. var pos = this.pos;
  7395. if (pos >= this.end) {
  7396. return -1;
  7397. }
  7398. this.ensureByte(pos);
  7399. return this.bytes[this.pos++];
  7400. },
  7401. getUint16: function ChunkedStream_getUint16() {
  7402. var b0 = this.getByte();
  7403. var b1 = this.getByte();
  7404. if (b0 === -1 || b1 === -1) {
  7405. return -1;
  7406. }
  7407. return (b0 << 8) + b1;
  7408. },
  7409. getInt32: function ChunkedStream_getInt32() {
  7410. var b0 = this.getByte();
  7411. var b1 = this.getByte();
  7412. var b2 = this.getByte();
  7413. var b3 = this.getByte();
  7414. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  7415. },
  7416. // returns subarray of original buffer
  7417. // should only be read
  7418. getBytes: function ChunkedStream_getBytes(length) {
  7419. var bytes = this.bytes;
  7420. var pos = this.pos;
  7421. var strEnd = this.end;
  7422. if (!length) {
  7423. this.ensureRange(pos, strEnd);
  7424. return bytes.subarray(pos, strEnd);
  7425. }
  7426. var end = pos + length;
  7427. if (end > strEnd) {
  7428. end = strEnd;
  7429. }
  7430. this.ensureRange(pos, end);
  7431. this.pos = end;
  7432. return bytes.subarray(pos, end);
  7433. },
  7434. peekByte: function ChunkedStream_peekByte() {
  7435. var peekedByte = this.getByte();
  7436. this.pos--;
  7437. return peekedByte;
  7438. },
  7439. peekBytes: function ChunkedStream_peekBytes(length) {
  7440. var bytes = this.getBytes(length);
  7441. this.pos -= bytes.length;
  7442. return bytes;
  7443. },
  7444. getByteRange: function ChunkedStream_getBytes(begin, end) {
  7445. this.ensureRange(begin, end);
  7446. return this.bytes.subarray(begin, end);
  7447. },
  7448. skip: function ChunkedStream_skip(n) {
  7449. if (!n) {
  7450. n = 1;
  7451. }
  7452. this.pos += n;
  7453. },
  7454. reset: function ChunkedStream_reset() {
  7455. this.pos = this.start;
  7456. },
  7457. moveStart: function ChunkedStream_moveStart() {
  7458. this.start = this.pos;
  7459. },
  7460. makeSubStream: function ChunkedStream_makeSubStream(start, length, dict) {
  7461. this.ensureRange(start, start + length);
  7462. function ChunkedStreamSubstream() {}
  7463. ChunkedStreamSubstream.prototype = Object.create(this);
  7464. ChunkedStreamSubstream.prototype.getMissingChunks = function() {
  7465. var chunkSize = this.chunkSize;
  7466. var beginChunk = Math.floor(this.start / chunkSize);
  7467. var endChunk = Math.floor((this.end - 1) / chunkSize) + 1;
  7468. var missingChunks = [];
  7469. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  7470. if (!this.loadedChunks[chunk]) {
  7471. missingChunks.push(chunk);
  7472. }
  7473. }
  7474. return missingChunks;
  7475. };
  7476. var subStream = new ChunkedStreamSubstream();
  7477. subStream.pos = subStream.start = start;
  7478. subStream.end = start + length || this.end;
  7479. subStream.dict = dict;
  7480. return subStream;
  7481. },
  7482. isStream: true
  7483. };
  7484. return ChunkedStream;
  7485. })();
  7486. var ChunkedStreamManager = (function ChunkedStreamManagerClosure() {
  7487. function ChunkedStreamManager(length, chunkSize, url, args) {
  7488. this.stream = new ChunkedStream(length, chunkSize, this);
  7489. this.length = length;
  7490. this.chunkSize = chunkSize;
  7491. this.url = url;
  7492. this.disableAutoFetch = args.disableAutoFetch;
  7493. var msgHandler = this.msgHandler = args.msgHandler;
  7494. if (args.chunkedViewerLoading) {
  7495. msgHandler.on('OnDataRange', this.onReceiveData.bind(this));
  7496. msgHandler.on('OnDataProgress', this.onProgress.bind(this));
  7497. this.sendRequest = function ChunkedStreamManager_sendRequest(begin, end) {
  7498. msgHandler.send('RequestDataRange', { begin: begin, end: end });
  7499. };
  7500. } else {
  7501. var getXhr = function getXhr() {
  7502. return new XMLHttpRequest();
  7503. };
  7504. this.networkManager = new NetworkManager(this.url, {
  7505. getXhr: getXhr,
  7506. httpHeaders: args.httpHeaders,
  7507. withCredentials: args.withCredentials
  7508. });
  7509. this.sendRequest = function ChunkedStreamManager_sendRequest(begin, end) {
  7510. this.networkManager.requestRange(begin, end, {
  7511. onDone: this.onReceiveData.bind(this),
  7512. onProgress: this.onProgress.bind(this)
  7513. });
  7514. };
  7515. }
  7516. this.currRequestId = 0;
  7517. this.chunksNeededByRequest = {};
  7518. this.requestsByChunk = {};
  7519. this.callbacksByRequest = {};
  7520. this.progressiveDataLength = 0;
  7521. this._loadedStreamCapability = createPromiseCapability();
  7522. if (args.initialData) {
  7523. this.onReceiveData({chunk: args.initialData});
  7524. }
  7525. }
  7526. ChunkedStreamManager.prototype = {
  7527. onLoadedStream: function ChunkedStreamManager_getLoadedStream() {
  7528. return this._loadedStreamCapability.promise;
  7529. },
  7530. // Get all the chunks that are not yet loaded and groups them into
  7531. // contiguous ranges to load in as few requests as possible
  7532. requestAllChunks: function ChunkedStreamManager_requestAllChunks() {
  7533. var missingChunks = this.stream.getMissingChunks();
  7534. this.requestChunks(missingChunks);
  7535. return this._loadedStreamCapability.promise;
  7536. },
  7537. requestChunks: function ChunkedStreamManager_requestChunks(chunks,
  7538. callback) {
  7539. var requestId = this.currRequestId++;
  7540. var chunksNeeded;
  7541. var i, ii;
  7542. this.chunksNeededByRequest[requestId] = chunksNeeded = {};
  7543. for (i = 0, ii = chunks.length; i < ii; i++) {
  7544. if (!this.stream.hasChunk(chunks[i])) {
  7545. chunksNeeded[chunks[i]] = true;
  7546. }
  7547. }
  7548. if (isEmptyObj(chunksNeeded)) {
  7549. if (callback) {
  7550. callback();
  7551. }
  7552. return;
  7553. }
  7554. this.callbacksByRequest[requestId] = callback;
  7555. var chunksToRequest = [];
  7556. for (var chunk in chunksNeeded) {
  7557. chunk = chunk | 0;
  7558. if (!(chunk in this.requestsByChunk)) {
  7559. this.requestsByChunk[chunk] = [];
  7560. chunksToRequest.push(chunk);
  7561. }
  7562. this.requestsByChunk[chunk].push(requestId);
  7563. }
  7564. if (!chunksToRequest.length) {
  7565. return;
  7566. }
  7567. var groupedChunksToRequest = this.groupChunks(chunksToRequest);
  7568. for (i = 0; i < groupedChunksToRequest.length; ++i) {
  7569. var groupedChunk = groupedChunksToRequest[i];
  7570. var begin = groupedChunk.beginChunk * this.chunkSize;
  7571. var end = Math.min(groupedChunk.endChunk * this.chunkSize, this.length);
  7572. this.sendRequest(begin, end);
  7573. }
  7574. },
  7575. getStream: function ChunkedStreamManager_getStream() {
  7576. return this.stream;
  7577. },
  7578. // Loads any chunks in the requested range that are not yet loaded
  7579. requestRange: function ChunkedStreamManager_requestRange(
  7580. begin, end, callback) {
  7581. end = Math.min(end, this.length);
  7582. var beginChunk = this.getBeginChunk(begin);
  7583. var endChunk = this.getEndChunk(end);
  7584. var chunks = [];
  7585. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  7586. chunks.push(chunk);
  7587. }
  7588. this.requestChunks(chunks, callback);
  7589. },
  7590. requestRanges: function ChunkedStreamManager_requestRanges(ranges,
  7591. callback) {
  7592. ranges = ranges || [];
  7593. var chunksToRequest = [];
  7594. for (var i = 0; i < ranges.length; i++) {
  7595. var beginChunk = this.getBeginChunk(ranges[i].begin);
  7596. var endChunk = this.getEndChunk(ranges[i].end);
  7597. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  7598. if (chunksToRequest.indexOf(chunk) < 0) {
  7599. chunksToRequest.push(chunk);
  7600. }
  7601. }
  7602. }
  7603. chunksToRequest.sort(function(a, b) { return a - b; });
  7604. this.requestChunks(chunksToRequest, callback);
  7605. },
  7606. // Groups a sorted array of chunks into as few continguous larger
  7607. // chunks as possible
  7608. groupChunks: function ChunkedStreamManager_groupChunks(chunks) {
  7609. var groupedChunks = [];
  7610. var beginChunk = -1;
  7611. var prevChunk = -1;
  7612. for (var i = 0; i < chunks.length; ++i) {
  7613. var chunk = chunks[i];
  7614. if (beginChunk < 0) {
  7615. beginChunk = chunk;
  7616. }
  7617. if (prevChunk >= 0 && prevChunk + 1 !== chunk) {
  7618. groupedChunks.push({ beginChunk: beginChunk,
  7619. endChunk: prevChunk + 1 });
  7620. beginChunk = chunk;
  7621. }
  7622. if (i + 1 === chunks.length) {
  7623. groupedChunks.push({ beginChunk: beginChunk,
  7624. endChunk: chunk + 1 });
  7625. }
  7626. prevChunk = chunk;
  7627. }
  7628. return groupedChunks;
  7629. },
  7630. onProgress: function ChunkedStreamManager_onProgress(args) {
  7631. var bytesLoaded = (this.stream.numChunksLoaded * this.chunkSize +
  7632. args.loaded);
  7633. this.msgHandler.send('DocProgress', {
  7634. loaded: bytesLoaded,
  7635. total: this.length
  7636. });
  7637. },
  7638. onReceiveData: function ChunkedStreamManager_onReceiveData(args) {
  7639. var chunk = args.chunk;
  7640. var isProgressive = args.begin === undefined;
  7641. var begin = isProgressive ? this.progressiveDataLength : args.begin;
  7642. var end = begin + chunk.byteLength;
  7643. var beginChunk = Math.floor(begin / this.chunkSize);
  7644. var endChunk = end < this.length ? Math.floor(end / this.chunkSize) :
  7645. Math.ceil(end / this.chunkSize);
  7646. if (isProgressive) {
  7647. this.stream.onReceiveProgressiveData(chunk);
  7648. this.progressiveDataLength = end;
  7649. } else {
  7650. this.stream.onReceiveData(begin, chunk);
  7651. }
  7652. if (this.stream.allChunksLoaded()) {
  7653. this._loadedStreamCapability.resolve(this.stream);
  7654. }
  7655. var loadedRequests = [];
  7656. var i, requestId;
  7657. for (chunk = beginChunk; chunk < endChunk; ++chunk) {
  7658. // The server might return more chunks than requested
  7659. var requestIds = this.requestsByChunk[chunk] || [];
  7660. delete this.requestsByChunk[chunk];
  7661. for (i = 0; i < requestIds.length; ++i) {
  7662. requestId = requestIds[i];
  7663. var chunksNeeded = this.chunksNeededByRequest[requestId];
  7664. if (chunk in chunksNeeded) {
  7665. delete chunksNeeded[chunk];
  7666. }
  7667. if (!isEmptyObj(chunksNeeded)) {
  7668. continue;
  7669. }
  7670. loadedRequests.push(requestId);
  7671. }
  7672. }
  7673. // If there are no pending requests, automatically fetch the next
  7674. // unfetched chunk of the PDF
  7675. if (!this.disableAutoFetch && isEmptyObj(this.requestsByChunk)) {
  7676. var nextEmptyChunk;
  7677. if (this.stream.numChunksLoaded === 1) {
  7678. // This is a special optimization so that after fetching the first
  7679. // chunk, rather than fetching the second chunk, we fetch the last
  7680. // chunk.
  7681. var lastChunk = this.stream.numChunks - 1;
  7682. if (!this.stream.hasChunk(lastChunk)) {
  7683. nextEmptyChunk = lastChunk;
  7684. }
  7685. } else {
  7686. nextEmptyChunk = this.stream.nextEmptyChunk(endChunk);
  7687. }
  7688. if (isInt(nextEmptyChunk)) {
  7689. this.requestChunks([nextEmptyChunk]);
  7690. }
  7691. }
  7692. for (i = 0; i < loadedRequests.length; ++i) {
  7693. requestId = loadedRequests[i];
  7694. var callback = this.callbacksByRequest[requestId];
  7695. delete this.callbacksByRequest[requestId];
  7696. if (callback) {
  7697. callback();
  7698. }
  7699. }
  7700. this.msgHandler.send('DocProgress', {
  7701. loaded: this.stream.numChunksLoaded * this.chunkSize,
  7702. total: this.length
  7703. });
  7704. },
  7705. onError: function ChunkedStreamManager_onError(err) {
  7706. this._loadedStreamCapability.reject(err);
  7707. },
  7708. getBeginChunk: function ChunkedStreamManager_getBeginChunk(begin) {
  7709. var chunk = Math.floor(begin / this.chunkSize);
  7710. return chunk;
  7711. },
  7712. getEndChunk: function ChunkedStreamManager_getEndChunk(end) {
  7713. if (end % this.chunkSize === 0) {
  7714. return end / this.chunkSize;
  7715. }
  7716. // 0 -> 0
  7717. // 1 -> 1
  7718. // 99 -> 1
  7719. // 100 -> 1
  7720. // 101 -> 2
  7721. var chunk = Math.floor((end - 1) / this.chunkSize) + 1;
  7722. return chunk;
  7723. }
  7724. };
  7725. return ChunkedStreamManager;
  7726. })();
  7727. // The maximum number of bytes fetched per range request
  7728. var RANGE_CHUNK_SIZE = 65536;
  7729. // TODO(mack): Make use of PDFJS.Util.inherit() when it becomes available
  7730. var BasePdfManager = (function BasePdfManagerClosure() {
  7731. function BasePdfManager() {
  7732. throw new Error('Cannot initialize BaseManagerManager');
  7733. }
  7734. BasePdfManager.prototype = {
  7735. onLoadedStream: function BasePdfManager_onLoadedStream() {
  7736. throw new NotImplementedException();
  7737. },
  7738. ensureDoc: function BasePdfManager_ensureDoc(prop, args) {
  7739. return this.ensure(this.pdfDocument, prop, args);
  7740. },
  7741. ensureXRef: function BasePdfManager_ensureXRef(prop, args) {
  7742. return this.ensure(this.pdfDocument.xref, prop, args);
  7743. },
  7744. ensureCatalog: function BasePdfManager_ensureCatalog(prop, args) {
  7745. return this.ensure(this.pdfDocument.catalog, prop, args);
  7746. },
  7747. getPage: function BasePdfManager_pagePage(pageIndex) {
  7748. return this.pdfDocument.getPage(pageIndex);
  7749. },
  7750. cleanup: function BasePdfManager_cleanup() {
  7751. return this.pdfDocument.cleanup();
  7752. },
  7753. ensure: function BasePdfManager_ensure(obj, prop, args) {
  7754. return new NotImplementedException();
  7755. },
  7756. requestRange: function BasePdfManager_ensure(begin, end) {
  7757. return new NotImplementedException();
  7758. },
  7759. requestLoadedStream: function BasePdfManager_requestLoadedStream() {
  7760. return new NotImplementedException();
  7761. },
  7762. sendProgressiveData: function BasePdfManager_sendProgressiveData(chunk) {
  7763. return new NotImplementedException();
  7764. },
  7765. updatePassword: function BasePdfManager_updatePassword(password) {
  7766. this.pdfDocument.xref.password = this.password = password;
  7767. if (this._passwordChangedCapability) {
  7768. this._passwordChangedCapability.resolve();
  7769. }
  7770. },
  7771. passwordChanged: function BasePdfManager_passwordChanged() {
  7772. this._passwordChangedCapability = createPromiseCapability();
  7773. return this._passwordChangedCapability.promise;
  7774. },
  7775. terminate: function BasePdfManager_terminate() {
  7776. return new NotImplementedException();
  7777. }
  7778. };
  7779. return BasePdfManager;
  7780. })();
  7781. var LocalPdfManager = (function LocalPdfManagerClosure() {
  7782. function LocalPdfManager(data, password) {
  7783. var stream = new Stream(data);
  7784. this.pdfDocument = new PDFDocument(this, stream, password);
  7785. this._loadedStreamCapability = createPromiseCapability();
  7786. this._loadedStreamCapability.resolve(stream);
  7787. }
  7788. LocalPdfManager.prototype = Object.create(BasePdfManager.prototype);
  7789. LocalPdfManager.prototype.constructor = LocalPdfManager;
  7790. LocalPdfManager.prototype.ensure =
  7791. function LocalPdfManager_ensure(obj, prop, args) {
  7792. return new Promise(function (resolve, reject) {
  7793. try {
  7794. var value = obj[prop];
  7795. var result;
  7796. if (typeof value === 'function') {
  7797. result = value.apply(obj, args);
  7798. } else {
  7799. result = value;
  7800. }
  7801. resolve(result);
  7802. } catch (e) {
  7803. reject(e);
  7804. }
  7805. });
  7806. };
  7807. LocalPdfManager.prototype.requestRange =
  7808. function LocalPdfManager_requestRange(begin, end) {
  7809. return Promise.resolve();
  7810. };
  7811. LocalPdfManager.prototype.requestLoadedStream =
  7812. function LocalPdfManager_requestLoadedStream() {
  7813. };
  7814. LocalPdfManager.prototype.onLoadedStream =
  7815. function LocalPdfManager_getLoadedStream() {
  7816. return this._loadedStreamCapability.promise;
  7817. };
  7818. LocalPdfManager.prototype.terminate =
  7819. function LocalPdfManager_terminate() {
  7820. return;
  7821. };
  7822. return LocalPdfManager;
  7823. })();
  7824. var NetworkPdfManager = (function NetworkPdfManagerClosure() {
  7825. function NetworkPdfManager(args, msgHandler) {
  7826. this.msgHandler = msgHandler;
  7827. var params = {
  7828. msgHandler: msgHandler,
  7829. httpHeaders: args.httpHeaders,
  7830. withCredentials: args.withCredentials,
  7831. chunkedViewerLoading: args.chunkedViewerLoading,
  7832. disableAutoFetch: args.disableAutoFetch,
  7833. initialData: args.initialData
  7834. };
  7835. this.streamManager = new ChunkedStreamManager(args.length, RANGE_CHUNK_SIZE,
  7836. args.url, params);
  7837. this.pdfDocument = new PDFDocument(this, this.streamManager.getStream(),
  7838. args.password);
  7839. }
  7840. NetworkPdfManager.prototype = Object.create(BasePdfManager.prototype);
  7841. NetworkPdfManager.prototype.constructor = NetworkPdfManager;
  7842. NetworkPdfManager.prototype.ensure =
  7843. function NetworkPdfManager_ensure(obj, prop, args) {
  7844. var pdfManager = this;
  7845. return new Promise(function (resolve, reject) {
  7846. function ensureHelper() {
  7847. try {
  7848. var result;
  7849. var value = obj[prop];
  7850. if (typeof value === 'function') {
  7851. result = value.apply(obj, args);
  7852. } else {
  7853. result = value;
  7854. }
  7855. resolve(result);
  7856. } catch(e) {
  7857. if (!(e instanceof MissingDataException)) {
  7858. reject(e);
  7859. return;
  7860. }
  7861. pdfManager.streamManager.requestRange(e.begin, e.end, ensureHelper);
  7862. }
  7863. }
  7864. ensureHelper();
  7865. });
  7866. };
  7867. NetworkPdfManager.prototype.requestRange =
  7868. function NetworkPdfManager_requestRange(begin, end) {
  7869. return new Promise(function (resolve) {
  7870. this.streamManager.requestRange(begin, end, function() {
  7871. resolve();
  7872. });
  7873. }.bind(this));
  7874. };
  7875. NetworkPdfManager.prototype.requestLoadedStream =
  7876. function NetworkPdfManager_requestLoadedStream() {
  7877. this.streamManager.requestAllChunks();
  7878. };
  7879. NetworkPdfManager.prototype.sendProgressiveData =
  7880. function NetworkPdfManager_sendProgressiveData(chunk) {
  7881. this.streamManager.onReceiveData({ chunk: chunk });
  7882. };
  7883. NetworkPdfManager.prototype.onLoadedStream =
  7884. function NetworkPdfManager_getLoadedStream() {
  7885. return this.streamManager.onLoadedStream();
  7886. };
  7887. NetworkPdfManager.prototype.terminate =
  7888. function NetworkPdfManager_terminate() {
  7889. this.streamManager.networkManager.abortAllRequests();
  7890. };
  7891. return NetworkPdfManager;
  7892. })();
  7893. var Page = (function PageClosure() {
  7894. var LETTER_SIZE_MEDIABOX = [0, 0, 612, 792];
  7895. function Page(pdfManager, xref, pageIndex, pageDict, ref, fontCache) {
  7896. this.pdfManager = pdfManager;
  7897. this.pageIndex = pageIndex;
  7898. this.pageDict = pageDict;
  7899. this.xref = xref;
  7900. this.ref = ref;
  7901. this.fontCache = fontCache;
  7902. this.idCounters = {
  7903. obj: 0
  7904. };
  7905. this.resourcesPromise = null;
  7906. }
  7907. Page.prototype = {
  7908. getPageProp: function Page_getPageProp(key) {
  7909. return this.pageDict.get(key);
  7910. },
  7911. getInheritedPageProp: function Page_inheritPageProp(key) {
  7912. var dict = this.pageDict;
  7913. var value = dict.get(key);
  7914. while (value === undefined) {
  7915. dict = dict.get('Parent');
  7916. if (!dict) {
  7917. break;
  7918. }
  7919. value = dict.get(key);
  7920. }
  7921. return value;
  7922. },
  7923. get content() {
  7924. return this.getPageProp('Contents');
  7925. },
  7926. get resources() {
  7927. var value = this.getInheritedPageProp('Resources');
  7928. // For robustness: The spec states that a \Resources entry has to be
  7929. // present, but can be empty. Some document omit it still. In this case
  7930. // return an empty dictionary:
  7931. if (value === undefined) {
  7932. value = Dict.empty;
  7933. }
  7934. return shadow(this, 'resources', value);
  7935. },
  7936. get mediaBox() {
  7937. var obj = this.getInheritedPageProp('MediaBox');
  7938. // Reset invalid media box to letter size.
  7939. if (!isArray(obj) || obj.length !== 4) {
  7940. obj = LETTER_SIZE_MEDIABOX;
  7941. }
  7942. return shadow(this, 'mediaBox', obj);
  7943. },
  7944. get view() {
  7945. var mediaBox = this.mediaBox;
  7946. var cropBox = this.getInheritedPageProp('CropBox');
  7947. if (!isArray(cropBox) || cropBox.length !== 4) {
  7948. return shadow(this, 'view', mediaBox);
  7949. }
  7950. // From the spec, 6th ed., p.963:
  7951. // "The crop, bleed, trim, and art boxes should not ordinarily
  7952. // extend beyond the boundaries of the media box. If they do, they are
  7953. // effectively reduced to their intersection with the media box."
  7954. cropBox = Util.intersect(cropBox, mediaBox);
  7955. if (!cropBox) {
  7956. return shadow(this, 'view', mediaBox);
  7957. }
  7958. return shadow(this, 'view', cropBox);
  7959. },
  7960. get annotationRefs() {
  7961. return shadow(this, 'annotationRefs',
  7962. this.getInheritedPageProp('Annots'));
  7963. },
  7964. get rotate() {
  7965. var rotate = this.getInheritedPageProp('Rotate') || 0;
  7966. // Normalize rotation so it's a multiple of 90 and between 0 and 270
  7967. if (rotate % 90 !== 0) {
  7968. rotate = 0;
  7969. } else if (rotate >= 360) {
  7970. rotate = rotate % 360;
  7971. } else if (rotate < 0) {
  7972. // The spec doesn't cover negatives, assume its counterclockwise
  7973. // rotation. The following is the other implementation of modulo.
  7974. rotate = ((rotate % 360) + 360) % 360;
  7975. }
  7976. return shadow(this, 'rotate', rotate);
  7977. },
  7978. getContentStream: function Page_getContentStream() {
  7979. var content = this.content;
  7980. var stream;
  7981. if (isArray(content)) {
  7982. // fetching items
  7983. var xref = this.xref;
  7984. var i, n = content.length;
  7985. var streams = [];
  7986. for (i = 0; i < n; ++i) {
  7987. streams.push(xref.fetchIfRef(content[i]));
  7988. }
  7989. stream = new StreamsSequenceStream(streams);
  7990. } else if (isStream(content)) {
  7991. stream = content;
  7992. } else {
  7993. // replacing non-existent page content with empty one
  7994. stream = new NullStream();
  7995. }
  7996. return stream;
  7997. },
  7998. loadResources: function Page_loadResources(keys) {
  7999. if (!this.resourcesPromise) {
  8000. // TODO: add async getInheritedPageProp and remove this.
  8001. this.resourcesPromise = this.pdfManager.ensure(this, 'resources');
  8002. }
  8003. return this.resourcesPromise.then(function resourceSuccess() {
  8004. var objectLoader = new ObjectLoader(this.resources.map,
  8005. keys,
  8006. this.xref);
  8007. return objectLoader.load();
  8008. }.bind(this));
  8009. },
  8010. getOperatorList: function Page_getOperatorList(handler, intent) {
  8011. var self = this;
  8012. var pdfManager = this.pdfManager;
  8013. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
  8014. []);
  8015. var resourcesPromise = this.loadResources([
  8016. 'ExtGState',
  8017. 'ColorSpace',
  8018. 'Pattern',
  8019. 'Shading',
  8020. 'XObject',
  8021. 'Font'
  8022. // ProcSet
  8023. // Properties
  8024. ]);
  8025. var partialEvaluator = new PartialEvaluator(pdfManager, this.xref,
  8026. handler, this.pageIndex,
  8027. 'p' + this.pageIndex + '_',
  8028. this.idCounters,
  8029. this.fontCache);
  8030. var dataPromises = Promise.all([contentStreamPromise, resourcesPromise]);
  8031. var pageListPromise = dataPromises.then(function(data) {
  8032. var contentStream = data[0];
  8033. var opList = new OperatorList(intent, handler, self.pageIndex);
  8034. handler.send('StartRenderPage', {
  8035. transparency: partialEvaluator.hasBlendModes(self.resources),
  8036. pageIndex: self.pageIndex,
  8037. intent: intent
  8038. });
  8039. return partialEvaluator.getOperatorList(contentStream, self.resources,
  8040. opList).then(function () {
  8041. return opList;
  8042. });
  8043. });
  8044. var annotationsPromise = pdfManager.ensure(this, 'annotations');
  8045. return Promise.all([pageListPromise, annotationsPromise]).then(
  8046. function(datas) {
  8047. var pageOpList = datas[0];
  8048. var annotations = datas[1];
  8049. if (annotations.length === 0) {
  8050. pageOpList.flush(true);
  8051. return pageOpList;
  8052. }
  8053. var annotationsReadyPromise = Annotation.appendToOperatorList(
  8054. annotations, pageOpList, pdfManager, partialEvaluator, intent);
  8055. return annotationsReadyPromise.then(function () {
  8056. pageOpList.flush(true);
  8057. return pageOpList;
  8058. });
  8059. });
  8060. },
  8061. extractTextContent: function Page_extractTextContent() {
  8062. var handler = {
  8063. on: function nullHandlerOn() {},
  8064. send: function nullHandlerSend() {}
  8065. };
  8066. var self = this;
  8067. var pdfManager = this.pdfManager;
  8068. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
  8069. []);
  8070. var resourcesPromise = this.loadResources([
  8071. 'ExtGState',
  8072. 'XObject',
  8073. 'Font'
  8074. ]);
  8075. var dataPromises = Promise.all([contentStreamPromise,
  8076. resourcesPromise]);
  8077. return dataPromises.then(function(data) {
  8078. var contentStream = data[0];
  8079. var partialEvaluator = new PartialEvaluator(pdfManager, self.xref,
  8080. handler, self.pageIndex,
  8081. 'p' + self.pageIndex + '_',
  8082. self.idCounters,
  8083. self.fontCache);
  8084. return partialEvaluator.getTextContent(contentStream,
  8085. self.resources);
  8086. });
  8087. },
  8088. getAnnotationsData: function Page_getAnnotationsData() {
  8089. var annotations = this.annotations;
  8090. var annotationsData = [];
  8091. for (var i = 0, n = annotations.length; i < n; ++i) {
  8092. annotationsData.push(annotations[i].getData());
  8093. }
  8094. return annotationsData;
  8095. },
  8096. get annotations() {
  8097. var annotations = [];
  8098. var annotationRefs = (this.annotationRefs || []);
  8099. for (var i = 0, n = annotationRefs.length; i < n; ++i) {
  8100. var annotationRef = annotationRefs[i];
  8101. var annotation = Annotation.fromRef(this.xref, annotationRef);
  8102. if (annotation) {
  8103. annotations.push(annotation);
  8104. }
  8105. }
  8106. return shadow(this, 'annotations', annotations);
  8107. }
  8108. };
  8109. return Page;
  8110. })();
  8111. /**
  8112. * The `PDFDocument` holds all the data of the PDF file. Compared to the
  8113. * `PDFDoc`, this one doesn't have any job management code.
  8114. * Right now there exists one PDFDocument on the main thread + one object
  8115. * for each worker. If there is no worker support enabled, there are two
  8116. * `PDFDocument` objects on the main thread created.
  8117. */
  8118. var PDFDocument = (function PDFDocumentClosure() {
  8119. var FINGERPRINT_FIRST_BYTES = 1024;
  8120. var EMPTY_FINGERPRINT = '\x00\x00\x00\x00\x00\x00\x00' +
  8121. '\x00\x00\x00\x00\x00\x00\x00\x00\x00';
  8122. function PDFDocument(pdfManager, arg, password) {
  8123. if (isStream(arg)) {
  8124. init.call(this, pdfManager, arg, password);
  8125. } else if (isArrayBuffer(arg)) {
  8126. init.call(this, pdfManager, new Stream(arg), password);
  8127. } else {
  8128. error('PDFDocument: Unknown argument type');
  8129. }
  8130. }
  8131. function init(pdfManager, stream, password) {
  8132. assert(stream.length > 0, 'stream must have data');
  8133. this.pdfManager = pdfManager;
  8134. this.stream = stream;
  8135. var xref = new XRef(this.stream, password, pdfManager);
  8136. this.xref = xref;
  8137. }
  8138. function find(stream, needle, limit, backwards) {
  8139. var pos = stream.pos;
  8140. var end = stream.end;
  8141. var strBuf = [];
  8142. if (pos + limit > end) {
  8143. limit = end - pos;
  8144. }
  8145. for (var n = 0; n < limit; ++n) {
  8146. strBuf.push(String.fromCharCode(stream.getByte()));
  8147. }
  8148. var str = strBuf.join('');
  8149. stream.pos = pos;
  8150. var index = backwards ? str.lastIndexOf(needle) : str.indexOf(needle);
  8151. if (index === -1) {
  8152. return false; /* not found */
  8153. }
  8154. stream.pos += index;
  8155. return true; /* found */
  8156. }
  8157. var DocumentInfoValidators = {
  8158. get entries() {
  8159. // Lazily build this since all the validation functions below are not
  8160. // defined until after this file loads.
  8161. return shadow(this, 'entries', {
  8162. Title: isString,
  8163. Author: isString,
  8164. Subject: isString,
  8165. Keywords: isString,
  8166. Creator: isString,
  8167. Producer: isString,
  8168. CreationDate: isString,
  8169. ModDate: isString,
  8170. Trapped: isName
  8171. });
  8172. }
  8173. };
  8174. PDFDocument.prototype = {
  8175. parse: function PDFDocument_parse(recoveryMode) {
  8176. this.setup(recoveryMode);
  8177. try {
  8178. // checking if AcroForm is present
  8179. this.acroForm = this.catalog.catDict.get('AcroForm');
  8180. if (this.acroForm) {
  8181. this.xfa = this.acroForm.get('XFA');
  8182. var fields = this.acroForm.get('Fields');
  8183. if ((!fields || !isArray(fields) || fields.length === 0) &&
  8184. !this.xfa) {
  8185. // no fields and no XFA -- not a form (?)
  8186. this.acroForm = null;
  8187. }
  8188. }
  8189. } catch (ex) {
  8190. info('Something wrong with AcroForm entry');
  8191. this.acroForm = null;
  8192. }
  8193. },
  8194. get linearization() {
  8195. var linearization = null;
  8196. if (this.stream.length) {
  8197. try {
  8198. linearization = Linearization.create(this.stream);
  8199. } catch (err) {
  8200. if (err instanceof MissingDataException) {
  8201. throw err;
  8202. }
  8203. info(err);
  8204. }
  8205. }
  8206. // shadow the prototype getter with a data property
  8207. return shadow(this, 'linearization', linearization);
  8208. },
  8209. get startXRef() {
  8210. var stream = this.stream;
  8211. var startXRef = 0;
  8212. var linearization = this.linearization;
  8213. if (linearization) {
  8214. // Find end of first obj.
  8215. stream.reset();
  8216. if (find(stream, 'endobj', 1024)) {
  8217. startXRef = stream.pos + 6;
  8218. }
  8219. } else {
  8220. // Find startxref by jumping backward from the end of the file.
  8221. var step = 1024;
  8222. var found = false, pos = stream.end;
  8223. while (!found && pos > 0) {
  8224. pos -= step - 'startxref'.length;
  8225. if (pos < 0) {
  8226. pos = 0;
  8227. }
  8228. stream.pos = pos;
  8229. found = find(stream, 'startxref', step, true);
  8230. }
  8231. if (found) {
  8232. stream.skip(9);
  8233. var ch;
  8234. do {
  8235. ch = stream.getByte();
  8236. } while (Lexer.isSpace(ch));
  8237. var str = '';
  8238. while (ch >= 0x20 && ch <= 0x39) { // < '9'
  8239. str += String.fromCharCode(ch);
  8240. ch = stream.getByte();
  8241. }
  8242. startXRef = parseInt(str, 10);
  8243. if (isNaN(startXRef)) {
  8244. startXRef = 0;
  8245. }
  8246. }
  8247. }
  8248. // shadow the prototype getter with a data property
  8249. return shadow(this, 'startXRef', startXRef);
  8250. },
  8251. get mainXRefEntriesOffset() {
  8252. var mainXRefEntriesOffset = 0;
  8253. var linearization = this.linearization;
  8254. if (linearization) {
  8255. mainXRefEntriesOffset = linearization.mainXRefEntriesOffset;
  8256. }
  8257. // shadow the prototype getter with a data property
  8258. return shadow(this, 'mainXRefEntriesOffset', mainXRefEntriesOffset);
  8259. },
  8260. // Find the header, remove leading garbage and setup the stream
  8261. // starting from the header.
  8262. checkHeader: function PDFDocument_checkHeader() {
  8263. var stream = this.stream;
  8264. stream.reset();
  8265. if (find(stream, '%PDF-', 1024)) {
  8266. // Found the header, trim off any garbage before it.
  8267. stream.moveStart();
  8268. // Reading file format version
  8269. var MAX_VERSION_LENGTH = 12;
  8270. var version = '', ch;
  8271. while ((ch = stream.getByte()) > 0x20) { // SPACE
  8272. if (version.length >= MAX_VERSION_LENGTH) {
  8273. break;
  8274. }
  8275. version += String.fromCharCode(ch);
  8276. }
  8277. // removing "%PDF-"-prefix
  8278. this.pdfFormatVersion = version.substring(5);
  8279. return;
  8280. }
  8281. // May not be a PDF file, continue anyway.
  8282. },
  8283. parseStartXRef: function PDFDocument_parseStartXRef() {
  8284. var startXRef = this.startXRef;
  8285. this.xref.setStartXRef(startXRef);
  8286. },
  8287. setup: function PDFDocument_setup(recoveryMode) {
  8288. this.xref.parse(recoveryMode);
  8289. this.catalog = new Catalog(this.pdfManager, this.xref);
  8290. },
  8291. get numPages() {
  8292. var linearization = this.linearization;
  8293. var num = linearization ? linearization.numPages : this.catalog.numPages;
  8294. // shadow the prototype getter
  8295. return shadow(this, 'numPages', num);
  8296. },
  8297. get documentInfo() {
  8298. var docInfo = {
  8299. PDFFormatVersion: this.pdfFormatVersion,
  8300. IsAcroFormPresent: !!this.acroForm,
  8301. IsXFAPresent: !!this.xfa
  8302. };
  8303. var infoDict;
  8304. try {
  8305. infoDict = this.xref.trailer.get('Info');
  8306. } catch (err) {
  8307. info('The document information dictionary is invalid.');
  8308. }
  8309. if (infoDict) {
  8310. var validEntries = DocumentInfoValidators.entries;
  8311. // Only fill the document info with valid entries from the spec.
  8312. for (var key in validEntries) {
  8313. if (infoDict.has(key)) {
  8314. var value = infoDict.get(key);
  8315. // Make sure the value conforms to the spec.
  8316. if (validEntries[key](value)) {
  8317. docInfo[key] = (typeof value !== 'string' ?
  8318. value : stringToPDFString(value));
  8319. } else {
  8320. info('Bad value in document info for "' + key + '"');
  8321. }
  8322. }
  8323. }
  8324. }
  8325. return shadow(this, 'documentInfo', docInfo);
  8326. },
  8327. get fingerprint() {
  8328. var xref = this.xref, idArray, hash, fileID = '';
  8329. if (xref.trailer.has('ID')) {
  8330. idArray = xref.trailer.get('ID');
  8331. }
  8332. if (idArray && isArray(idArray) && idArray[0] !== EMPTY_FINGERPRINT) {
  8333. hash = stringToBytes(idArray[0]);
  8334. } else {
  8335. if (this.stream.ensureRange) {
  8336. this.stream.ensureRange(0,
  8337. Math.min(FINGERPRINT_FIRST_BYTES, this.stream.end));
  8338. }
  8339. hash = calculateMD5(this.stream.bytes.subarray(0,
  8340. FINGERPRINT_FIRST_BYTES), 0, FINGERPRINT_FIRST_BYTES);
  8341. }
  8342. for (var i = 0, n = hash.length; i < n; i++) {
  8343. var hex = hash[i].toString(16);
  8344. fileID += hex.length === 1 ? '0' + hex : hex;
  8345. }
  8346. return shadow(this, 'fingerprint', fileID);
  8347. },
  8348. getPage: function PDFDocument_getPage(pageIndex) {
  8349. return this.catalog.getPage(pageIndex);
  8350. },
  8351. cleanup: function PDFDocument_cleanup() {
  8352. return this.catalog.cleanup();
  8353. }
  8354. };
  8355. return PDFDocument;
  8356. })();
  8357. var Name = (function NameClosure() {
  8358. function Name(name) {
  8359. this.name = name;
  8360. }
  8361. Name.prototype = {};
  8362. var nameCache = {};
  8363. Name.get = function Name_get(name) {
  8364. var nameValue = nameCache[name];
  8365. return (nameValue ? nameValue : (nameCache[name] = new Name(name)));
  8366. };
  8367. return Name;
  8368. })();
  8369. var Cmd = (function CmdClosure() {
  8370. function Cmd(cmd) {
  8371. this.cmd = cmd;
  8372. }
  8373. Cmd.prototype = {};
  8374. var cmdCache = {};
  8375. Cmd.get = function Cmd_get(cmd) {
  8376. var cmdValue = cmdCache[cmd];
  8377. return (cmdValue ? cmdValue : (cmdCache[cmd] = new Cmd(cmd)));
  8378. };
  8379. return Cmd;
  8380. })();
  8381. var Dict = (function DictClosure() {
  8382. var nonSerializable = function nonSerializableClosure() {
  8383. return nonSerializable; // creating closure on some variable
  8384. };
  8385. var GETALL_DICTIONARY_TYPES_WHITELIST = {
  8386. 'Background': true,
  8387. 'ExtGState': true,
  8388. 'Halftone': true,
  8389. 'Layout': true,
  8390. 'Mask': true,
  8391. 'Pagination': true,
  8392. 'Printing': true
  8393. };
  8394. function isRecursionAllowedFor(dict) {
  8395. if (!isName(dict.Type)) {
  8396. return true;
  8397. }
  8398. var dictType = dict.Type.name;
  8399. return GETALL_DICTIONARY_TYPES_WHITELIST[dictType] === true;
  8400. }
  8401. // xref is optional
  8402. function Dict(xref) {
  8403. // Map should only be used internally, use functions below to access.
  8404. this.map = Object.create(null);
  8405. this.xref = xref;
  8406. this.objId = null;
  8407. this.__nonSerializable__ = nonSerializable; // disable cloning of the Dict
  8408. }
  8409. Dict.prototype = {
  8410. assignXref: function Dict_assignXref(newXref) {
  8411. this.xref = newXref;
  8412. },
  8413. // automatically dereferences Ref objects
  8414. get: function Dict_get(key1, key2, key3) {
  8415. var value;
  8416. var xref = this.xref;
  8417. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
  8418. typeof key2 === 'undefined') {
  8419. return xref ? xref.fetchIfRef(value) : value;
  8420. }
  8421. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
  8422. typeof key3 === 'undefined') {
  8423. return xref ? xref.fetchIfRef(value) : value;
  8424. }
  8425. value = this.map[key3] || null;
  8426. return xref ? xref.fetchIfRef(value) : value;
  8427. },
  8428. // Same as get(), but returns a promise and uses fetchIfRefAsync().
  8429. getAsync: function Dict_getAsync(key1, key2, key3) {
  8430. var value;
  8431. var xref = this.xref;
  8432. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
  8433. typeof key2 === 'undefined') {
  8434. if (xref) {
  8435. return xref.fetchIfRefAsync(value);
  8436. }
  8437. return Promise.resolve(value);
  8438. }
  8439. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
  8440. typeof key3 === 'undefined') {
  8441. if (xref) {
  8442. return xref.fetchIfRefAsync(value);
  8443. }
  8444. return Promise.resolve(value);
  8445. }
  8446. value = this.map[key3] || null;
  8447. if (xref) {
  8448. return xref.fetchIfRefAsync(value);
  8449. }
  8450. return Promise.resolve(value);
  8451. },
  8452. // no dereferencing
  8453. getRaw: function Dict_getRaw(key) {
  8454. return this.map[key];
  8455. },
  8456. // creates new map and dereferences all Refs
  8457. getAll: function Dict_getAll() {
  8458. var all = Object.create(null);
  8459. var queue = null;
  8460. var key, obj;
  8461. for (key in this.map) {
  8462. obj = this.get(key);
  8463. if (obj instanceof Dict) {
  8464. if (isRecursionAllowedFor(obj)) {
  8465. (queue || (queue = [])).push({target: all, key: key, obj: obj});
  8466. } else {
  8467. all[key] = this.getRaw(key);
  8468. }
  8469. } else {
  8470. all[key] = obj;
  8471. }
  8472. }
  8473. if (!queue) {
  8474. return all;
  8475. }
  8476. // trying to take cyclic references into the account
  8477. var processed = Object.create(null);
  8478. while (queue.length > 0) {
  8479. var item = queue.shift();
  8480. var itemObj = item.obj;
  8481. var objId = itemObj.objId;
  8482. if (objId && objId in processed) {
  8483. item.target[item.key] = processed[objId];
  8484. continue;
  8485. }
  8486. var dereferenced = Object.create(null);
  8487. for (key in itemObj.map) {
  8488. obj = itemObj.get(key);
  8489. if (obj instanceof Dict) {
  8490. if (isRecursionAllowedFor(obj)) {
  8491. queue.push({target: dereferenced, key: key, obj: obj});
  8492. } else {
  8493. dereferenced[key] = itemObj.getRaw(key);
  8494. }
  8495. } else {
  8496. dereferenced[key] = obj;
  8497. }
  8498. }
  8499. if (objId) {
  8500. processed[objId] = dereferenced;
  8501. }
  8502. item.target[item.key] = dereferenced;
  8503. }
  8504. return all;
  8505. },
  8506. set: function Dict_set(key, value) {
  8507. this.map[key] = value;
  8508. },
  8509. has: function Dict_has(key) {
  8510. return key in this.map;
  8511. },
  8512. forEach: function Dict_forEach(callback) {
  8513. for (var key in this.map) {
  8514. callback(key, this.get(key));
  8515. }
  8516. }
  8517. };
  8518. Dict.empty = new Dict(null);
  8519. return Dict;
  8520. })();
  8521. var Ref = (function RefClosure() {
  8522. function Ref(num, gen) {
  8523. this.num = num;
  8524. this.gen = gen;
  8525. }
  8526. Ref.prototype = {
  8527. toString: function Ref_toString() {
  8528. // This function is hot, so we make the string as compact as possible.
  8529. // |this.gen| is almost always zero, so we treat that case specially.
  8530. var str = this.num + 'R';
  8531. if (this.gen !== 0) {
  8532. str += this.gen;
  8533. }
  8534. return str;
  8535. }
  8536. };
  8537. return Ref;
  8538. })();
  8539. // The reference is identified by number and generation.
  8540. // This structure stores only one instance of the reference.
  8541. var RefSet = (function RefSetClosure() {
  8542. function RefSet() {
  8543. this.dict = {};
  8544. }
  8545. RefSet.prototype = {
  8546. has: function RefSet_has(ref) {
  8547. return ref.toString() in this.dict;
  8548. },
  8549. put: function RefSet_put(ref) {
  8550. this.dict[ref.toString()] = true;
  8551. },
  8552. remove: function RefSet_remove(ref) {
  8553. delete this.dict[ref.toString()];
  8554. }
  8555. };
  8556. return RefSet;
  8557. })();
  8558. var RefSetCache = (function RefSetCacheClosure() {
  8559. function RefSetCache() {
  8560. this.dict = Object.create(null);
  8561. }
  8562. RefSetCache.prototype = {
  8563. get: function RefSetCache_get(ref) {
  8564. return this.dict[ref.toString()];
  8565. },
  8566. has: function RefSetCache_has(ref) {
  8567. return ref.toString() in this.dict;
  8568. },
  8569. put: function RefSetCache_put(ref, obj) {
  8570. this.dict[ref.toString()] = obj;
  8571. },
  8572. putAlias: function RefSetCache_putAlias(ref, aliasRef) {
  8573. this.dict[ref.toString()] = this.get(aliasRef);
  8574. },
  8575. forEach: function RefSetCache_forEach(fn, thisArg) {
  8576. for (var i in this.dict) {
  8577. fn.call(thisArg, this.dict[i]);
  8578. }
  8579. },
  8580. clear: function RefSetCache_clear() {
  8581. this.dict = Object.create(null);
  8582. }
  8583. };
  8584. return RefSetCache;
  8585. })();
  8586. var Catalog = (function CatalogClosure() {
  8587. function Catalog(pdfManager, xref) {
  8588. this.pdfManager = pdfManager;
  8589. this.xref = xref;
  8590. this.catDict = xref.getCatalogObj();
  8591. this.fontCache = new RefSetCache();
  8592. assert(isDict(this.catDict),
  8593. 'catalog object is not a dictionary');
  8594. this.pagePromises = [];
  8595. }
  8596. Catalog.prototype = {
  8597. get metadata() {
  8598. var streamRef = this.catDict.getRaw('Metadata');
  8599. if (!isRef(streamRef)) {
  8600. return shadow(this, 'metadata', null);
  8601. }
  8602. var encryptMetadata = (!this.xref.encrypt ? false :
  8603. this.xref.encrypt.encryptMetadata);
  8604. var stream = this.xref.fetch(streamRef, !encryptMetadata);
  8605. var metadata;
  8606. if (stream && isDict(stream.dict)) {
  8607. var type = stream.dict.get('Type');
  8608. var subtype = stream.dict.get('Subtype');
  8609. if (isName(type) && isName(subtype) &&
  8610. type.name === 'Metadata' && subtype.name === 'XML') {
  8611. // XXX: This should examine the charset the XML document defines,
  8612. // however since there are currently no real means to decode
  8613. // arbitrary charsets, let's just hope that the author of the PDF
  8614. // was reasonable enough to stick with the XML default charset,
  8615. // which is UTF-8.
  8616. try {
  8617. metadata = stringToUTF8String(bytesToString(stream.getBytes()));
  8618. } catch (e) {
  8619. info('Skipping invalid metadata.');
  8620. }
  8621. }
  8622. }
  8623. return shadow(this, 'metadata', metadata);
  8624. },
  8625. get toplevelPagesDict() {
  8626. var pagesObj = this.catDict.get('Pages');
  8627. assert(isDict(pagesObj), 'invalid top-level pages dictionary');
  8628. // shadow the prototype getter
  8629. return shadow(this, 'toplevelPagesDict', pagesObj);
  8630. },
  8631. get documentOutline() {
  8632. var obj = null;
  8633. try {
  8634. obj = this.readDocumentOutline();
  8635. } catch (ex) {
  8636. if (ex instanceof MissingDataException) {
  8637. throw ex;
  8638. }
  8639. warn('Unable to read document outline');
  8640. }
  8641. return shadow(this, 'documentOutline', obj);
  8642. },
  8643. readDocumentOutline: function Catalog_readDocumentOutline() {
  8644. var xref = this.xref;
  8645. var obj = this.catDict.get('Outlines');
  8646. var root = { items: [] };
  8647. if (isDict(obj)) {
  8648. obj = obj.getRaw('First');
  8649. var processed = new RefSet();
  8650. if (isRef(obj)) {
  8651. var queue = [{obj: obj, parent: root}];
  8652. // to avoid recursion keeping track of the items
  8653. // in the processed dictionary
  8654. processed.put(obj);
  8655. while (queue.length > 0) {
  8656. var i = queue.shift();
  8657. var outlineDict = xref.fetchIfRef(i.obj);
  8658. if (outlineDict === null) {
  8659. continue;
  8660. }
  8661. if (!outlineDict.has('Title')) {
  8662. error('Invalid outline item');
  8663. }
  8664. var dest = outlineDict.get('A');
  8665. if (dest) {
  8666. dest = dest.get('D');
  8667. } else if (outlineDict.has('Dest')) {
  8668. dest = outlineDict.getRaw('Dest');
  8669. if (isName(dest)) {
  8670. dest = dest.name;
  8671. }
  8672. }
  8673. var title = outlineDict.get('Title');
  8674. var outlineItem = {
  8675. dest: dest,
  8676. title: stringToPDFString(title),
  8677. color: outlineDict.get('C') || [0, 0, 0],
  8678. count: outlineDict.get('Count'),
  8679. bold: !!(outlineDict.get('F') & 2),
  8680. italic: !!(outlineDict.get('F') & 1),
  8681. items: []
  8682. };
  8683. i.parent.items.push(outlineItem);
  8684. obj = outlineDict.getRaw('First');
  8685. if (isRef(obj) && !processed.has(obj)) {
  8686. queue.push({obj: obj, parent: outlineItem});
  8687. processed.put(obj);
  8688. }
  8689. obj = outlineDict.getRaw('Next');
  8690. if (isRef(obj) && !processed.has(obj)) {
  8691. queue.push({obj: obj, parent: i.parent});
  8692. processed.put(obj);
  8693. }
  8694. }
  8695. }
  8696. }
  8697. return (root.items.length > 0 ? root.items : null);
  8698. },
  8699. get numPages() {
  8700. var obj = this.toplevelPagesDict.get('Count');
  8701. assert(
  8702. isInt(obj),
  8703. 'page count in top level pages object is not an integer'
  8704. );
  8705. // shadow the prototype getter
  8706. return shadow(this, 'num', obj);
  8707. },
  8708. get destinations() {
  8709. function fetchDestination(dest) {
  8710. return isDict(dest) ? dest.get('D') : dest;
  8711. }
  8712. var xref = this.xref;
  8713. var dests = {}, nameTreeRef, nameDictionaryRef;
  8714. var obj = this.catDict.get('Names');
  8715. if (obj && obj.has('Dests')) {
  8716. nameTreeRef = obj.getRaw('Dests');
  8717. } else if (this.catDict.has('Dests')) {
  8718. nameDictionaryRef = this.catDict.get('Dests');
  8719. }
  8720. if (nameDictionaryRef) {
  8721. // reading simple destination dictionary
  8722. obj = nameDictionaryRef;
  8723. obj.forEach(function catalogForEach(key, value) {
  8724. if (!value) {
  8725. return;
  8726. }
  8727. dests[key] = fetchDestination(value);
  8728. });
  8729. }
  8730. if (nameTreeRef) {
  8731. var nameTree = new NameTree(nameTreeRef, xref);
  8732. var names = nameTree.getAll();
  8733. for (var name in names) {
  8734. if (!names.hasOwnProperty(name)) {
  8735. continue;
  8736. }
  8737. dests[name] = fetchDestination(names[name]);
  8738. }
  8739. }
  8740. return shadow(this, 'destinations', dests);
  8741. },
  8742. getDestination: function Catalog_getDestination(destinationId) {
  8743. function fetchDestination(dest) {
  8744. return isDict(dest) ? dest.get('D') : dest;
  8745. }
  8746. var xref = this.xref;
  8747. var dest, nameTreeRef, nameDictionaryRef;
  8748. var obj = this.catDict.get('Names');
  8749. if (obj && obj.has('Dests')) {
  8750. nameTreeRef = obj.getRaw('Dests');
  8751. } else if (this.catDict.has('Dests')) {
  8752. nameDictionaryRef = this.catDict.get('Dests');
  8753. }
  8754. if (nameDictionaryRef) {
  8755. // reading simple destination dictionary
  8756. obj = nameDictionaryRef;
  8757. obj.forEach(function catalogForEach(key, value) {
  8758. if (!value) {
  8759. return;
  8760. }
  8761. if (key === destinationId) {
  8762. dest = fetchDestination(value);
  8763. }
  8764. });
  8765. }
  8766. if (nameTreeRef) {
  8767. var nameTree = new NameTree(nameTreeRef, xref);
  8768. dest = fetchDestination(nameTree.get(destinationId));
  8769. }
  8770. return dest;
  8771. },
  8772. get attachments() {
  8773. var xref = this.xref;
  8774. var attachments = null, nameTreeRef;
  8775. var obj = this.catDict.get('Names');
  8776. if (obj) {
  8777. nameTreeRef = obj.getRaw('EmbeddedFiles');
  8778. }
  8779. if (nameTreeRef) {
  8780. var nameTree = new NameTree(nameTreeRef, xref);
  8781. var names = nameTree.getAll();
  8782. for (var name in names) {
  8783. if (!names.hasOwnProperty(name)) {
  8784. continue;
  8785. }
  8786. var fs = new FileSpec(names[name], xref);
  8787. if (!attachments) {
  8788. attachments = {};
  8789. }
  8790. attachments[stringToPDFString(name)] = fs.serializable;
  8791. }
  8792. }
  8793. return shadow(this, 'attachments', attachments);
  8794. },
  8795. get javaScript() {
  8796. var xref = this.xref;
  8797. var obj = this.catDict.get('Names');
  8798. var javaScript = [];
  8799. if (obj && obj.has('JavaScript')) {
  8800. var nameTree = new NameTree(obj.getRaw('JavaScript'), xref);
  8801. var names = nameTree.getAll();
  8802. for (var name in names) {
  8803. if (!names.hasOwnProperty(name)) {
  8804. continue;
  8805. }
  8806. // We don't really use the JavaScript right now. This code is
  8807. // defensive so we don't cause errors on document load.
  8808. var jsDict = names[name];
  8809. if (!isDict(jsDict)) {
  8810. continue;
  8811. }
  8812. var type = jsDict.get('S');
  8813. if (!isName(type) || type.name !== 'JavaScript') {
  8814. continue;
  8815. }
  8816. var js = jsDict.get('JS');
  8817. if (!isString(js) && !isStream(js)) {
  8818. continue;
  8819. }
  8820. if (isStream(js)) {
  8821. js = bytesToString(js.getBytes());
  8822. }
  8823. javaScript.push(stringToPDFString(js));
  8824. }
  8825. }
  8826. // Append OpenAction actions to javaScript array
  8827. var openactionDict = this.catDict.get('OpenAction');
  8828. if (isDict(openactionDict)) {
  8829. var objType = openactionDict.get('Type');
  8830. var actionType = openactionDict.get('S');
  8831. var action = openactionDict.get('N');
  8832. var isPrintAction = (isName(objType) && objType.name === 'Action' &&
  8833. isName(actionType) && actionType.name === 'Named' &&
  8834. isName(action) && action.name === 'Print');
  8835. if (isPrintAction) {
  8836. javaScript.push('print(true);');
  8837. }
  8838. }
  8839. return shadow(this, 'javaScript', javaScript);
  8840. },
  8841. cleanup: function Catalog_cleanup() {
  8842. var promises = [];
  8843. this.fontCache.forEach(function (promise) {
  8844. promises.push(promise);
  8845. });
  8846. return Promise.all(promises).then(function (translatedFonts) {
  8847. for (var i = 0, ii = translatedFonts.length; i < ii; i++) {
  8848. var font = translatedFonts[i].dict;
  8849. delete font.translated;
  8850. }
  8851. this.fontCache.clear();
  8852. }.bind(this));
  8853. },
  8854. getPage: function Catalog_getPage(pageIndex) {
  8855. if (!(pageIndex in this.pagePromises)) {
  8856. this.pagePromises[pageIndex] = this.getPageDict(pageIndex).then(
  8857. function (a) {
  8858. var dict = a[0];
  8859. var ref = a[1];
  8860. return new Page(this.pdfManager, this.xref, pageIndex, dict, ref,
  8861. this.fontCache);
  8862. }.bind(this)
  8863. );
  8864. }
  8865. return this.pagePromises[pageIndex];
  8866. },
  8867. getPageDict: function Catalog_getPageDict(pageIndex) {
  8868. var capability = createPromiseCapability();
  8869. var nodesToVisit = [this.catDict.getRaw('Pages')];
  8870. var currentPageIndex = 0;
  8871. var xref = this.xref;
  8872. function next() {
  8873. while (nodesToVisit.length) {
  8874. var currentNode = nodesToVisit.pop();
  8875. if (isRef(currentNode)) {
  8876. xref.fetchAsync(currentNode).then(function (obj) {
  8877. if ((isDict(obj, 'Page') || (isDict(obj) && !obj.has('Kids')))) {
  8878. if (pageIndex === currentPageIndex) {
  8879. capability.resolve([obj, currentNode]);
  8880. } else {
  8881. currentPageIndex++;
  8882. next();
  8883. }
  8884. return;
  8885. }
  8886. nodesToVisit.push(obj);
  8887. next();
  8888. }, capability.reject);
  8889. return;
  8890. }
  8891. // must be a child page dictionary
  8892. assert(
  8893. isDict(currentNode),
  8894. 'page dictionary kid reference points to wrong type of object'
  8895. );
  8896. var count = currentNode.get('Count');
  8897. // Skip nodes where the page can't be.
  8898. if (currentPageIndex + count <= pageIndex) {
  8899. currentPageIndex += count;
  8900. continue;
  8901. }
  8902. var kids = currentNode.get('Kids');
  8903. assert(isArray(kids), 'page dictionary kids object is not an array');
  8904. if (count === kids.length) {
  8905. // Nodes that don't have the page have been skipped and this is the
  8906. // bottom of the tree which means the page requested must be a
  8907. // descendant of this pages node. Ideally we would just resolve the
  8908. // promise with the page ref here, but there is the case where more
  8909. // pages nodes could link to single a page (see issue 3666 pdf). To
  8910. // handle this push it back on the queue so if it is a pages node it
  8911. // will be descended into.
  8912. nodesToVisit = [kids[pageIndex - currentPageIndex]];
  8913. currentPageIndex = pageIndex;
  8914. continue;
  8915. } else {
  8916. for (var last = kids.length - 1; last >= 0; last--) {
  8917. nodesToVisit.push(kids[last]);
  8918. }
  8919. }
  8920. }
  8921. capability.reject('Page index ' + pageIndex + ' not found.');
  8922. }
  8923. next();
  8924. return capability.promise;
  8925. },
  8926. getPageIndex: function Catalog_getPageIndex(ref) {
  8927. // The page tree nodes have the count of all the leaves below them. To get
  8928. // how many pages are before we just have to walk up the tree and keep
  8929. // adding the count of siblings to the left of the node.
  8930. var xref = this.xref;
  8931. function pagesBeforeRef(kidRef) {
  8932. var total = 0;
  8933. var parentRef;
  8934. return xref.fetchAsync(kidRef).then(function (node) {
  8935. if (!node) {
  8936. return null;
  8937. }
  8938. parentRef = node.getRaw('Parent');
  8939. return node.getAsync('Parent');
  8940. }).then(function (parent) {
  8941. if (!parent) {
  8942. return null;
  8943. }
  8944. return parent.getAsync('Kids');
  8945. }).then(function (kids) {
  8946. if (!kids) {
  8947. return null;
  8948. }
  8949. var kidPromises = [];
  8950. var found = false;
  8951. for (var i = 0; i < kids.length; i++) {
  8952. var kid = kids[i];
  8953. assert(isRef(kid), 'kids must be a ref');
  8954. if (kid.num === kidRef.num) {
  8955. found = true;
  8956. break;
  8957. }
  8958. kidPromises.push(xref.fetchAsync(kid).then(function (kid) {
  8959. if (kid.has('Count')) {
  8960. var count = kid.get('Count');
  8961. total += count;
  8962. } else { // page leaf node
  8963. total++;
  8964. }
  8965. }));
  8966. }
  8967. if (!found) {
  8968. error('kid ref not found in parents kids');
  8969. }
  8970. return Promise.all(kidPromises).then(function () {
  8971. return [total, parentRef];
  8972. });
  8973. });
  8974. }
  8975. var total = 0;
  8976. function next(ref) {
  8977. return pagesBeforeRef(ref).then(function (args) {
  8978. if (!args) {
  8979. return total;
  8980. }
  8981. var count = args[0];
  8982. var parentRef = args[1];
  8983. total += count;
  8984. return next(parentRef);
  8985. });
  8986. }
  8987. return next(ref);
  8988. }
  8989. };
  8990. return Catalog;
  8991. })();
  8992. var XRef = (function XRefClosure() {
  8993. function XRef(stream, password) {
  8994. this.stream = stream;
  8995. this.entries = [];
  8996. this.xrefstms = {};
  8997. // prepare the XRef cache
  8998. this.cache = [];
  8999. this.password = password;
  9000. this.stats = {
  9001. streamTypes: [],
  9002. fontTypes: []
  9003. };
  9004. }
  9005. XRef.prototype = {
  9006. setStartXRef: function XRef_setStartXRef(startXRef) {
  9007. // Store the starting positions of xref tables as we process them
  9008. // so we can recover from missing data errors
  9009. this.startXRefQueue = [startXRef];
  9010. },
  9011. parse: function XRef_parse(recoveryMode) {
  9012. var trailerDict;
  9013. if (!recoveryMode) {
  9014. trailerDict = this.readXRef();
  9015. } else {
  9016. warn('Indexing all PDF objects');
  9017. trailerDict = this.indexObjects();
  9018. }
  9019. trailerDict.assignXref(this);
  9020. this.trailer = trailerDict;
  9021. var encrypt = trailerDict.get('Encrypt');
  9022. if (encrypt) {
  9023. var ids = trailerDict.get('ID');
  9024. var fileId = (ids && ids.length) ? ids[0] : '';
  9025. this.encrypt = new CipherTransformFactory(encrypt, fileId,
  9026. this.password);
  9027. }
  9028. // get the root dictionary (catalog) object
  9029. if (!(this.root = trailerDict.get('Root'))) {
  9030. error('Invalid root reference');
  9031. }
  9032. },
  9033. processXRefTable: function XRef_processXRefTable(parser) {
  9034. if (!('tableState' in this)) {
  9035. // Stores state of the table as we process it so we can resume
  9036. // from middle of table in case of missing data error
  9037. this.tableState = {
  9038. entryNum: 0,
  9039. streamPos: parser.lexer.stream.pos,
  9040. parserBuf1: parser.buf1,
  9041. parserBuf2: parser.buf2
  9042. };
  9043. }
  9044. var obj = this.readXRefTable(parser);
  9045. // Sanity check
  9046. if (!isCmd(obj, 'trailer')) {
  9047. error('Invalid XRef table: could not find trailer dictionary');
  9048. }
  9049. // Read trailer dictionary, e.g.
  9050. // trailer
  9051. // << /Size 22
  9052. // /Root 20R
  9053. // /Info 10R
  9054. // /ID [ <81b14aafa313db63dbd6f981e49f94f4> ]
  9055. // >>
  9056. // The parser goes through the entire stream << ... >> and provides
  9057. // a getter interface for the key-value table
  9058. var dict = parser.getObj();
  9059. // The pdflib PDF generator can generate a nested trailer dictionary
  9060. if (!isDict(dict) && dict.dict) {
  9061. dict = dict.dict;
  9062. }
  9063. if (!isDict(dict)) {
  9064. error('Invalid XRef table: could not parse trailer dictionary');
  9065. }
  9066. delete this.tableState;
  9067. return dict;
  9068. },
  9069. readXRefTable: function XRef_readXRefTable(parser) {
  9070. // Example of cross-reference table:
  9071. // xref
  9072. // 0 1 <-- subsection header (first obj #, obj count)
  9073. // 0000000000 65535 f <-- actual object (offset, generation #, f/n)
  9074. // 23 2 <-- subsection header ... and so on ...
  9075. // 0000025518 00002 n
  9076. // 0000025635 00000 n
  9077. // trailer
  9078. // ...
  9079. var stream = parser.lexer.stream;
  9080. var tableState = this.tableState;
  9081. stream.pos = tableState.streamPos;
  9082. parser.buf1 = tableState.parserBuf1;
  9083. parser.buf2 = tableState.parserBuf2;
  9084. // Outer loop is over subsection headers
  9085. var obj;
  9086. while (true) {
  9087. if (!('firstEntryNum' in tableState) || !('entryCount' in tableState)) {
  9088. if (isCmd(obj = parser.getObj(), 'trailer')) {
  9089. break;
  9090. }
  9091. tableState.firstEntryNum = obj;
  9092. tableState.entryCount = parser.getObj();
  9093. }
  9094. var first = tableState.firstEntryNum;
  9095. var count = tableState.entryCount;
  9096. if (!isInt(first) || !isInt(count)) {
  9097. error('Invalid XRef table: wrong types in subsection header');
  9098. }
  9099. // Inner loop is over objects themselves
  9100. for (var i = tableState.entryNum; i < count; i++) {
  9101. tableState.streamPos = stream.pos;
  9102. tableState.entryNum = i;
  9103. tableState.parserBuf1 = parser.buf1;
  9104. tableState.parserBuf2 = parser.buf2;
  9105. var entry = {};
  9106. entry.offset = parser.getObj();
  9107. entry.gen = parser.getObj();
  9108. var type = parser.getObj();
  9109. if (isCmd(type, 'f')) {
  9110. entry.free = true;
  9111. } else if (isCmd(type, 'n')) {
  9112. entry.uncompressed = true;
  9113. }
  9114. // Validate entry obj
  9115. if (!isInt(entry.offset) || !isInt(entry.gen) ||
  9116. !(entry.free || entry.uncompressed)) {
  9117. error('Invalid entry in XRef subsection: ' + first + ', ' + count);
  9118. }
  9119. if (!this.entries[i + first]) {
  9120. this.entries[i + first] = entry;
  9121. }
  9122. }
  9123. tableState.entryNum = 0;
  9124. tableState.streamPos = stream.pos;
  9125. tableState.parserBuf1 = parser.buf1;
  9126. tableState.parserBuf2 = parser.buf2;
  9127. delete tableState.firstEntryNum;
  9128. delete tableState.entryCount;
  9129. }
  9130. // Per issue 3248: hp scanners generate bad XRef
  9131. if (first === 1 && this.entries[1] && this.entries[1].free) {
  9132. // shifting the entries
  9133. this.entries.shift();
  9134. }
  9135. // Sanity check: as per spec, first object must be free
  9136. if (this.entries[0] && !this.entries[0].free) {
  9137. error('Invalid XRef table: unexpected first object');
  9138. }
  9139. return obj;
  9140. },
  9141. processXRefStream: function XRef_processXRefStream(stream) {
  9142. if (!('streamState' in this)) {
  9143. // Stores state of the stream as we process it so we can resume
  9144. // from middle of stream in case of missing data error
  9145. var streamParameters = stream.dict;
  9146. var byteWidths = streamParameters.get('W');
  9147. var range = streamParameters.get('Index');
  9148. if (!range) {
  9149. range = [0, streamParameters.get('Size')];
  9150. }
  9151. this.streamState = {
  9152. entryRanges: range,
  9153. byteWidths: byteWidths,
  9154. entryNum: 0,
  9155. streamPos: stream.pos
  9156. };
  9157. }
  9158. this.readXRefStream(stream);
  9159. delete this.streamState;
  9160. return stream.dict;
  9161. },
  9162. readXRefStream: function XRef_readXRefStream(stream) {
  9163. var i, j;
  9164. var streamState = this.streamState;
  9165. stream.pos = streamState.streamPos;
  9166. var byteWidths = streamState.byteWidths;
  9167. var typeFieldWidth = byteWidths[0];
  9168. var offsetFieldWidth = byteWidths[1];
  9169. var generationFieldWidth = byteWidths[2];
  9170. var entryRanges = streamState.entryRanges;
  9171. while (entryRanges.length > 0) {
  9172. var first = entryRanges[0];
  9173. var n = entryRanges[1];
  9174. if (!isInt(first) || !isInt(n)) {
  9175. error('Invalid XRef range fields: ' + first + ', ' + n);
  9176. }
  9177. if (!isInt(typeFieldWidth) || !isInt(offsetFieldWidth) ||
  9178. !isInt(generationFieldWidth)) {
  9179. error('Invalid XRef entry fields length: ' + first + ', ' + n);
  9180. }
  9181. for (i = streamState.entryNum; i < n; ++i) {
  9182. streamState.entryNum = i;
  9183. streamState.streamPos = stream.pos;
  9184. var type = 0, offset = 0, generation = 0;
  9185. for (j = 0; j < typeFieldWidth; ++j) {
  9186. type = (type << 8) | stream.getByte();
  9187. }
  9188. // if type field is absent, its default value is 1
  9189. if (typeFieldWidth === 0) {
  9190. type = 1;
  9191. }
  9192. for (j = 0; j < offsetFieldWidth; ++j) {
  9193. offset = (offset << 8) | stream.getByte();
  9194. }
  9195. for (j = 0; j < generationFieldWidth; ++j) {
  9196. generation = (generation << 8) | stream.getByte();
  9197. }
  9198. var entry = {};
  9199. entry.offset = offset;
  9200. entry.gen = generation;
  9201. switch (type) {
  9202. case 0:
  9203. entry.free = true;
  9204. break;
  9205. case 1:
  9206. entry.uncompressed = true;
  9207. break;
  9208. case 2:
  9209. break;
  9210. default:
  9211. error('Invalid XRef entry type: ' + type);
  9212. }
  9213. if (!this.entries[first + i]) {
  9214. this.entries[first + i] = entry;
  9215. }
  9216. }
  9217. streamState.entryNum = 0;
  9218. streamState.streamPos = stream.pos;
  9219. entryRanges.splice(0, 2);
  9220. }
  9221. },
  9222. indexObjects: function XRef_indexObjects() {
  9223. // Simple scan through the PDF content to find objects,
  9224. // trailers and XRef streams.
  9225. function readToken(data, offset) {
  9226. var token = '', ch = data[offset];
  9227. while (ch !== 13 && ch !== 10) {
  9228. if (++offset >= data.length) {
  9229. break;
  9230. }
  9231. token += String.fromCharCode(ch);
  9232. ch = data[offset];
  9233. }
  9234. return token;
  9235. }
  9236. function skipUntil(data, offset, what) {
  9237. var length = what.length, dataLength = data.length;
  9238. var skipped = 0;
  9239. // finding byte sequence
  9240. while (offset < dataLength) {
  9241. var i = 0;
  9242. while (i < length && data[offset + i] === what[i]) {
  9243. ++i;
  9244. }
  9245. if (i >= length) {
  9246. break; // sequence found
  9247. }
  9248. offset++;
  9249. skipped++;
  9250. }
  9251. return skipped;
  9252. }
  9253. var trailerBytes = new Uint8Array([116, 114, 97, 105, 108, 101, 114]);
  9254. var startxrefBytes = new Uint8Array([115, 116, 97, 114, 116, 120, 114,
  9255. 101, 102]);
  9256. var endobjBytes = new Uint8Array([101, 110, 100, 111, 98, 106]);
  9257. var xrefBytes = new Uint8Array([47, 88, 82, 101, 102]);
  9258. var stream = this.stream;
  9259. stream.pos = 0;
  9260. var buffer = stream.getBytes();
  9261. var position = stream.start, length = buffer.length;
  9262. var trailers = [], xrefStms = [];
  9263. while (position < length) {
  9264. var ch = buffer[position];
  9265. if (ch === 32 || ch === 9 || ch === 13 || ch === 10) {
  9266. ++position;
  9267. continue;
  9268. }
  9269. if (ch === 37) { // %-comment
  9270. do {
  9271. ++position;
  9272. if (position >= length) {
  9273. break;
  9274. }
  9275. ch = buffer[position];
  9276. } while (ch !== 13 && ch !== 10);
  9277. continue;
  9278. }
  9279. var token = readToken(buffer, position);
  9280. var m;
  9281. if (token === 'xref') {
  9282. position += skipUntil(buffer, position, trailerBytes);
  9283. trailers.push(position);
  9284. position += skipUntil(buffer, position, startxrefBytes);
  9285. } else if ((m = /^(\d+)\s+(\d+)\s+obj\b/.exec(token))) {
  9286. this.entries[m[1]] = {
  9287. offset: position,
  9288. gen: m[2] | 0,
  9289. uncompressed: true
  9290. };
  9291. var contentLength = skipUntil(buffer, position, endobjBytes) + 7;
  9292. var content = buffer.subarray(position, position + contentLength);
  9293. // checking XRef stream suspect
  9294. // (it shall have '/XRef' and next char is not a letter)
  9295. var xrefTagOffset = skipUntil(content, 0, xrefBytes);
  9296. if (xrefTagOffset < contentLength &&
  9297. content[xrefTagOffset + 5] < 64) {
  9298. xrefStms.push(position);
  9299. this.xrefstms[position] = 1; // don't read it recursively
  9300. }
  9301. position += contentLength;
  9302. } else {
  9303. position += token.length + 1;
  9304. }
  9305. }
  9306. // reading XRef streams
  9307. var i, ii;
  9308. for (i = 0, ii = xrefStms.length; i < ii; ++i) {
  9309. this.startXRefQueue.push(xrefStms[i]);
  9310. this.readXRef(/* recoveryMode */ true);
  9311. }
  9312. // finding main trailer
  9313. var dict;
  9314. for (i = 0, ii = trailers.length; i < ii; ++i) {
  9315. stream.pos = trailers[i];
  9316. var parser = new Parser(new Lexer(stream), true, this);
  9317. var obj = parser.getObj();
  9318. if (!isCmd(obj, 'trailer')) {
  9319. continue;
  9320. }
  9321. // read the trailer dictionary
  9322. if (!isDict(dict = parser.getObj())) {
  9323. continue;
  9324. }
  9325. // taking the first one with 'ID'
  9326. if (dict.has('ID')) {
  9327. return dict;
  9328. }
  9329. }
  9330. // no tailer with 'ID', taking last one (if exists)
  9331. if (dict) {
  9332. return dict;
  9333. }
  9334. // nothing helps
  9335. // calling error() would reject worker with an UnknownErrorException.
  9336. throw new InvalidPDFException('Invalid PDF structure');
  9337. },
  9338. readXRef: function XRef_readXRef(recoveryMode) {
  9339. var stream = this.stream;
  9340. try {
  9341. while (this.startXRefQueue.length) {
  9342. var startXRef = this.startXRefQueue[0];
  9343. stream.pos = startXRef + stream.start;
  9344. var parser = new Parser(new Lexer(stream), true, this);
  9345. var obj = parser.getObj();
  9346. var dict;
  9347. // Get dictionary
  9348. if (isCmd(obj, 'xref')) {
  9349. // Parse end-of-file XRef
  9350. dict = this.processXRefTable(parser);
  9351. if (!this.topDict) {
  9352. this.topDict = dict;
  9353. }
  9354. // Recursively get other XRefs 'XRefStm', if any
  9355. obj = dict.get('XRefStm');
  9356. if (isInt(obj)) {
  9357. var pos = obj;
  9358. // ignore previously loaded xref streams
  9359. // (possible infinite recursion)
  9360. if (!(pos in this.xrefstms)) {
  9361. this.xrefstms[pos] = 1;
  9362. this.startXRefQueue.push(pos);
  9363. }
  9364. }
  9365. } else if (isInt(obj)) {
  9366. // Parse in-stream XRef
  9367. if (!isInt(parser.getObj()) ||
  9368. !isCmd(parser.getObj(), 'obj') ||
  9369. !isStream(obj = parser.getObj())) {
  9370. error('Invalid XRef stream');
  9371. }
  9372. dict = this.processXRefStream(obj);
  9373. if (!this.topDict) {
  9374. this.topDict = dict;
  9375. }
  9376. if (!dict) {
  9377. error('Failed to read XRef stream');
  9378. }
  9379. } else {
  9380. error('Invalid XRef stream header');
  9381. }
  9382. // Recursively get previous dictionary, if any
  9383. obj = dict.get('Prev');
  9384. if (isInt(obj)) {
  9385. this.startXRefQueue.push(obj);
  9386. } else if (isRef(obj)) {
  9387. // The spec says Prev must not be a reference, i.e. "/Prev NNN"
  9388. // This is a fallback for non-compliant PDFs, i.e. "/Prev NNN 0 R"
  9389. this.startXRefQueue.push(obj.num);
  9390. }
  9391. this.startXRefQueue.shift();
  9392. }
  9393. return this.topDict;
  9394. } catch (e) {
  9395. if (e instanceof MissingDataException) {
  9396. throw e;
  9397. }
  9398. info('(while reading XRef): ' + e);
  9399. }
  9400. if (recoveryMode) {
  9401. return;
  9402. }
  9403. throw new XRefParseException();
  9404. },
  9405. getEntry: function XRef_getEntry(i) {
  9406. var xrefEntry = this.entries[i];
  9407. if (xrefEntry && !xrefEntry.free && xrefEntry.offset) {
  9408. return xrefEntry;
  9409. }
  9410. return null;
  9411. },
  9412. fetchIfRef: function XRef_fetchIfRef(obj) {
  9413. if (!isRef(obj)) {
  9414. return obj;
  9415. }
  9416. return this.fetch(obj);
  9417. },
  9418. fetch: function XRef_fetch(ref, suppressEncryption) {
  9419. assert(isRef(ref), 'ref object is not a reference');
  9420. var num = ref.num;
  9421. if (num in this.cache) {
  9422. var cacheEntry = this.cache[num];
  9423. return cacheEntry;
  9424. }
  9425. var xrefEntry = this.getEntry(num);
  9426. // the referenced entry can be free
  9427. if (xrefEntry === null) {
  9428. return (this.cache[num] = null);
  9429. }
  9430. if (xrefEntry.uncompressed) {
  9431. xrefEntry = this.fetchUncompressed(ref, xrefEntry, suppressEncryption);
  9432. } else {
  9433. xrefEntry = this.fetchCompressed(xrefEntry, suppressEncryption);
  9434. }
  9435. if (isDict(xrefEntry)){
  9436. xrefEntry.objId = ref.toString();
  9437. } else if (isStream(xrefEntry)) {
  9438. xrefEntry.dict.objId = ref.toString();
  9439. }
  9440. return xrefEntry;
  9441. },
  9442. fetchUncompressed: function XRef_fetchUncompressed(ref, xrefEntry,
  9443. suppressEncryption) {
  9444. var gen = ref.gen;
  9445. var num = ref.num;
  9446. if (xrefEntry.gen !== gen) {
  9447. error('inconsistent generation in XRef');
  9448. }
  9449. var stream = this.stream.makeSubStream(xrefEntry.offset +
  9450. this.stream.start);
  9451. var parser = new Parser(new Lexer(stream), true, this);
  9452. var obj1 = parser.getObj();
  9453. var obj2 = parser.getObj();
  9454. var obj3 = parser.getObj();
  9455. if (!isInt(obj1) || parseInt(obj1, 10) !== num ||
  9456. !isInt(obj2) || parseInt(obj2, 10) !== gen ||
  9457. !isCmd(obj3)) {
  9458. error('bad XRef entry');
  9459. }
  9460. if (!isCmd(obj3, 'obj')) {
  9461. // some bad PDFs use "obj1234" and really mean 1234
  9462. if (obj3.cmd.indexOf('obj') === 0) {
  9463. num = parseInt(obj3.cmd.substring(3), 10);
  9464. if (!isNaN(num)) {
  9465. return num;
  9466. }
  9467. }
  9468. error('bad XRef entry');
  9469. }
  9470. if (this.encrypt && !suppressEncryption) {
  9471. xrefEntry = parser.getObj(this.encrypt.createCipherTransform(num, gen));
  9472. } else {
  9473. xrefEntry = parser.getObj();
  9474. }
  9475. if (!isStream(xrefEntry)) {
  9476. this.cache[num] = xrefEntry;
  9477. }
  9478. return xrefEntry;
  9479. },
  9480. fetchCompressed: function XRef_fetchCompressed(xrefEntry,
  9481. suppressEncryption) {
  9482. var tableOffset = xrefEntry.offset;
  9483. var stream = this.fetch(new Ref(tableOffset, 0));
  9484. if (!isStream(stream)) {
  9485. error('bad ObjStm stream');
  9486. }
  9487. var first = stream.dict.get('First');
  9488. var n = stream.dict.get('N');
  9489. if (!isInt(first) || !isInt(n)) {
  9490. error('invalid first and n parameters for ObjStm stream');
  9491. }
  9492. var parser = new Parser(new Lexer(stream), false, this);
  9493. parser.allowStreams = true;
  9494. var i, entries = [], num, nums = [];
  9495. // read the object numbers to populate cache
  9496. for (i = 0; i < n; ++i) {
  9497. num = parser.getObj();
  9498. if (!isInt(num)) {
  9499. error('invalid object number in the ObjStm stream: ' + num);
  9500. }
  9501. nums.push(num);
  9502. var offset = parser.getObj();
  9503. if (!isInt(offset)) {
  9504. error('invalid object offset in the ObjStm stream: ' + offset);
  9505. }
  9506. }
  9507. // read stream objects for cache
  9508. for (i = 0; i < n; ++i) {
  9509. entries.push(parser.getObj());
  9510. num = nums[i];
  9511. var entry = this.entries[num];
  9512. if (entry && entry.offset === tableOffset && entry.gen === i) {
  9513. this.cache[num] = entries[i];
  9514. }
  9515. }
  9516. xrefEntry = entries[xrefEntry.gen];
  9517. if (xrefEntry === undefined) {
  9518. error('bad XRef entry for compressed object');
  9519. }
  9520. return xrefEntry;
  9521. },
  9522. fetchIfRefAsync: function XRef_fetchIfRefAsync(obj) {
  9523. if (!isRef(obj)) {
  9524. return Promise.resolve(obj);
  9525. }
  9526. return this.fetchAsync(obj);
  9527. },
  9528. fetchAsync: function XRef_fetchAsync(ref, suppressEncryption) {
  9529. var streamManager = this.stream.manager;
  9530. var xref = this;
  9531. return new Promise(function tryFetch(resolve, reject) {
  9532. try {
  9533. resolve(xref.fetch(ref, suppressEncryption));
  9534. } catch (e) {
  9535. if (e instanceof MissingDataException) {
  9536. streamManager.requestRange(e.begin, e.end, function () {
  9537. tryFetch(resolve, reject);
  9538. });
  9539. return;
  9540. }
  9541. reject(e);
  9542. }
  9543. });
  9544. },
  9545. getCatalogObj: function XRef_getCatalogObj() {
  9546. return this.root;
  9547. }
  9548. };
  9549. return XRef;
  9550. })();
  9551. /**
  9552. * A NameTree is like a Dict but has some advantageous properties, see the
  9553. * spec (7.9.6) for more details.
  9554. * TODO: implement all the Dict functions and make this more efficent.
  9555. */
  9556. var NameTree = (function NameTreeClosure() {
  9557. function NameTree(root, xref) {
  9558. this.root = root;
  9559. this.xref = xref;
  9560. }
  9561. NameTree.prototype = {
  9562. getAll: function NameTree_getAll() {
  9563. var dict = {};
  9564. if (!this.root) {
  9565. return dict;
  9566. }
  9567. var xref = this.xref;
  9568. // reading name tree
  9569. var processed = new RefSet();
  9570. processed.put(this.root);
  9571. var queue = [this.root];
  9572. while (queue.length > 0) {
  9573. var i, n;
  9574. var obj = xref.fetchIfRef(queue.shift());
  9575. if (!isDict(obj)) {
  9576. continue;
  9577. }
  9578. if (obj.has('Kids')) {
  9579. var kids = obj.get('Kids');
  9580. for (i = 0, n = kids.length; i < n; i++) {
  9581. var kid = kids[i];
  9582. if (processed.has(kid)) {
  9583. error('invalid destinations');
  9584. }
  9585. queue.push(kid);
  9586. processed.put(kid);
  9587. }
  9588. continue;
  9589. }
  9590. var names = obj.get('Names');
  9591. if (names) {
  9592. for (i = 0, n = names.length; i < n; i += 2) {
  9593. dict[names[i]] = xref.fetchIfRef(names[i + 1]);
  9594. }
  9595. }
  9596. }
  9597. return dict;
  9598. },
  9599. get: function NameTree_get(destinationId) {
  9600. if (!this.root) {
  9601. return null;
  9602. }
  9603. var xref = this.xref;
  9604. var kidsOrNames = xref.fetchIfRef(this.root);
  9605. var loopCount = 0;
  9606. var MAX_NAMES_LEVELS = 10;
  9607. var l, r, m;
  9608. // Perform a binary search to quickly find the entry that
  9609. // contains the named destination we are looking for.
  9610. while (kidsOrNames.has('Kids')) {
  9611. loopCount++;
  9612. if (loopCount > MAX_NAMES_LEVELS) {
  9613. warn('Search depth limit for named destionations has been reached.');
  9614. return null;
  9615. }
  9616. var kids = kidsOrNames.get('Kids');
  9617. if (!isArray(kids)) {
  9618. return null;
  9619. }
  9620. l = 0;
  9621. r = kids.length - 1;
  9622. while (l <= r) {
  9623. m = (l + r) >> 1;
  9624. var kid = xref.fetchIfRef(kids[m]);
  9625. var limits = kid.get('Limits');
  9626. if (destinationId < limits[0]) {
  9627. r = m - 1;
  9628. } else if (destinationId > limits[1]) {
  9629. l = m + 1;
  9630. } else {
  9631. kidsOrNames = xref.fetchIfRef(kids[m]);
  9632. break;
  9633. }
  9634. }
  9635. if (l > r) {
  9636. return null;
  9637. }
  9638. }
  9639. // If we get here, then we have found the right entry. Now
  9640. // go through the named destinations in the Named dictionary
  9641. // until we find the exact destination we're looking for.
  9642. var names = kidsOrNames.get('Names');
  9643. if (isArray(names)) {
  9644. // Perform a binary search to reduce the lookup time.
  9645. l = 0;
  9646. r = names.length - 2;
  9647. while (l <= r) {
  9648. // Check only even indices (0, 2, 4, ...) because the
  9649. // odd indices contain the actual D array.
  9650. m = (l + r) & ~1;
  9651. if (destinationId < names[m]) {
  9652. r = m - 2;
  9653. } else if (destinationId > names[m]) {
  9654. l = m + 2;
  9655. } else {
  9656. return xref.fetchIfRef(names[m + 1]);
  9657. }
  9658. }
  9659. }
  9660. return null;
  9661. }
  9662. };
  9663. return NameTree;
  9664. })();
  9665. /**
  9666. * "A PDF file can refer to the contents of another file by using a File
  9667. * Specification (PDF 1.1)", see the spec (7.11) for more details.
  9668. * NOTE: Only embedded files are supported (as part of the attachments support)
  9669. * TODO: support the 'URL' file system (with caching if !/V), portable
  9670. * collections attributes and related files (/RF)
  9671. */
  9672. var FileSpec = (function FileSpecClosure() {
  9673. function FileSpec(root, xref) {
  9674. if (!root || !isDict(root)) {
  9675. return;
  9676. }
  9677. this.xref = xref;
  9678. this.root = root;
  9679. if (root.has('FS')) {
  9680. this.fs = root.get('FS');
  9681. }
  9682. this.description = root.has('Desc') ?
  9683. stringToPDFString(root.get('Desc')) :
  9684. '';
  9685. if (root.has('RF')) {
  9686. warn('Related file specifications are not supported');
  9687. }
  9688. this.contentAvailable = true;
  9689. if (!root.has('EF')) {
  9690. this.contentAvailable = false;
  9691. warn('Non-embedded file specifications are not supported');
  9692. }
  9693. }
  9694. function pickPlatformItem(dict) {
  9695. // Look for the filename in this order:
  9696. // UF, F, Unix, Mac, DOS
  9697. if (dict.has('UF')) {
  9698. return dict.get('UF');
  9699. } else if (dict.has('F')) {
  9700. return dict.get('F');
  9701. } else if (dict.has('Unix')) {
  9702. return dict.get('Unix');
  9703. } else if (dict.has('Mac')) {
  9704. return dict.get('Mac');
  9705. } else if (dict.has('DOS')) {
  9706. return dict.get('DOS');
  9707. } else {
  9708. return null;
  9709. }
  9710. }
  9711. FileSpec.prototype = {
  9712. get filename() {
  9713. if (!this._filename && this.root) {
  9714. var filename = pickPlatformItem(this.root) || 'unnamed';
  9715. this._filename = stringToPDFString(filename).
  9716. replace(/\\\\/g, '\\').
  9717. replace(/\\\//g, '/').
  9718. replace(/\\/g, '/');
  9719. }
  9720. return this._filename;
  9721. },
  9722. get content() {
  9723. if (!this.contentAvailable) {
  9724. return null;
  9725. }
  9726. if (!this.contentRef && this.root) {
  9727. this.contentRef = pickPlatformItem(this.root.get('EF'));
  9728. }
  9729. var content = null;
  9730. if (this.contentRef) {
  9731. var xref = this.xref;
  9732. var fileObj = xref.fetchIfRef(this.contentRef);
  9733. if (fileObj && isStream(fileObj)) {
  9734. content = fileObj.getBytes();
  9735. } else {
  9736. warn('Embedded file specification points to non-existing/invalid ' +
  9737. 'content');
  9738. }
  9739. } else {
  9740. warn('Embedded file specification does not have a content');
  9741. }
  9742. return content;
  9743. },
  9744. get serializable() {
  9745. return {
  9746. filename: this.filename,
  9747. content: this.content
  9748. };
  9749. }
  9750. };
  9751. return FileSpec;
  9752. })();
  9753. /**
  9754. * A helper for loading missing data in object graphs. It traverses the graph
  9755. * depth first and queues up any objects that have missing data. Once it has
  9756. * has traversed as many objects that are available it attempts to bundle the
  9757. * missing data requests and then resume from the nodes that weren't ready.
  9758. *
  9759. * NOTE: It provides protection from circular references by keeping track of
  9760. * of loaded references. However, you must be careful not to load any graphs
  9761. * that have references to the catalog or other pages since that will cause the
  9762. * entire PDF document object graph to be traversed.
  9763. */
  9764. var ObjectLoader = (function() {
  9765. function mayHaveChildren(value) {
  9766. return isRef(value) || isDict(value) || isArray(value) || isStream(value);
  9767. }
  9768. function addChildren(node, nodesToVisit) {
  9769. var value;
  9770. if (isDict(node) || isStream(node)) {
  9771. var map;
  9772. if (isDict(node)) {
  9773. map = node.map;
  9774. } else {
  9775. map = node.dict.map;
  9776. }
  9777. for (var key in map) {
  9778. value = map[key];
  9779. if (mayHaveChildren(value)) {
  9780. nodesToVisit.push(value);
  9781. }
  9782. }
  9783. } else if (isArray(node)) {
  9784. for (var i = 0, ii = node.length; i < ii; i++) {
  9785. value = node[i];
  9786. if (mayHaveChildren(value)) {
  9787. nodesToVisit.push(value);
  9788. }
  9789. }
  9790. }
  9791. }
  9792. function ObjectLoader(obj, keys, xref) {
  9793. this.obj = obj;
  9794. this.keys = keys;
  9795. this.xref = xref;
  9796. this.refSet = null;
  9797. }
  9798. ObjectLoader.prototype = {
  9799. load: function ObjectLoader_load() {
  9800. var keys = this.keys;
  9801. this.capability = createPromiseCapability();
  9802. // Don't walk the graph if all the data is already loaded.
  9803. if (!(this.xref.stream instanceof ChunkedStream) ||
  9804. this.xref.stream.getMissingChunks().length === 0) {
  9805. this.capability.resolve();
  9806. return this.capability.promise;
  9807. }
  9808. this.refSet = new RefSet();
  9809. // Setup the initial nodes to visit.
  9810. var nodesToVisit = [];
  9811. for (var i = 0; i < keys.length; i++) {
  9812. nodesToVisit.push(this.obj[keys[i]]);
  9813. }
  9814. this.walk(nodesToVisit);
  9815. return this.capability.promise;
  9816. },
  9817. walk: function ObjectLoader_walk(nodesToVisit) {
  9818. var nodesToRevisit = [];
  9819. var pendingRequests = [];
  9820. // DFS walk of the object graph.
  9821. while (nodesToVisit.length) {
  9822. var currentNode = nodesToVisit.pop();
  9823. // Only references or chunked streams can cause missing data exceptions.
  9824. if (isRef(currentNode)) {
  9825. // Skip nodes that have already been visited.
  9826. if (this.refSet.has(currentNode)) {
  9827. continue;
  9828. }
  9829. try {
  9830. var ref = currentNode;
  9831. this.refSet.put(ref);
  9832. currentNode = this.xref.fetch(currentNode);
  9833. } catch (e) {
  9834. if (!(e instanceof MissingDataException)) {
  9835. throw e;
  9836. }
  9837. nodesToRevisit.push(currentNode);
  9838. pendingRequests.push({ begin: e.begin, end: e.end });
  9839. }
  9840. }
  9841. if (currentNode && currentNode.getBaseStreams) {
  9842. var baseStreams = currentNode.getBaseStreams();
  9843. var foundMissingData = false;
  9844. for (var i = 0; i < baseStreams.length; i++) {
  9845. var stream = baseStreams[i];
  9846. if (stream.getMissingChunks && stream.getMissingChunks().length) {
  9847. foundMissingData = true;
  9848. pendingRequests.push({
  9849. begin: stream.start,
  9850. end: stream.end
  9851. });
  9852. }
  9853. }
  9854. if (foundMissingData) {
  9855. nodesToRevisit.push(currentNode);
  9856. }
  9857. }
  9858. addChildren(currentNode, nodesToVisit);
  9859. }
  9860. if (pendingRequests.length) {
  9861. this.xref.stream.manager.requestRanges(pendingRequests,
  9862. function pendingRequestCallback() {
  9863. nodesToVisit = nodesToRevisit;
  9864. for (var i = 0; i < nodesToRevisit.length; i++) {
  9865. var node = nodesToRevisit[i];
  9866. // Remove any reference nodes from the currrent refset so they
  9867. // aren't skipped when we revist them.
  9868. if (isRef(node)) {
  9869. this.refSet.remove(node);
  9870. }
  9871. }
  9872. this.walk(nodesToVisit);
  9873. }.bind(this));
  9874. return;
  9875. }
  9876. // Everything is loaded.
  9877. this.refSet = null;
  9878. this.capability.resolve();
  9879. }
  9880. };
  9881. return ObjectLoader;
  9882. })();
  9883. var ISOAdobeCharset = [
  9884. '.notdef', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar',
  9885. 'percent', 'ampersand', 'quoteright', 'parenleft', 'parenright',
  9886. 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash', 'zero',
  9887. 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',
  9888. 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater', 'question',
  9889. 'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
  9890. 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
  9891. 'bracketleft', 'backslash', 'bracketright', 'asciicircum', 'underscore',
  9892. 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
  9893. 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
  9894. 'braceleft', 'bar', 'braceright', 'asciitilde', 'exclamdown', 'cent',
  9895. 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  9896. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  9897. 'guilsinglright', 'fi', 'fl', 'endash', 'dagger', 'daggerdbl',
  9898. 'periodcentered', 'paragraph', 'bullet', 'quotesinglbase',
  9899. 'quotedblbase', 'quotedblright', 'guillemotright', 'ellipsis',
  9900. 'perthousand', 'questiondown', 'grave', 'acute', 'circumflex', 'tilde',
  9901. 'macron', 'breve', 'dotaccent', 'dieresis', 'ring', 'cedilla',
  9902. 'hungarumlaut', 'ogonek', 'caron', 'emdash', 'AE', 'ordfeminine',
  9903. 'Lslash', 'Oslash', 'OE', 'ordmasculine', 'ae', 'dotlessi', 'lslash',
  9904. 'oslash', 'oe', 'germandbls', 'onesuperior', 'logicalnot', 'mu',
  9905. 'trademark', 'Eth', 'onehalf', 'plusminus', 'Thorn', 'onequarter',
  9906. 'divide', 'brokenbar', 'degree', 'thorn', 'threequarters', 'twosuperior',
  9907. 'registered', 'minus', 'eth', 'multiply', 'threesuperior', 'copyright',
  9908. 'Aacute', 'Acircumflex', 'Adieresis', 'Agrave', 'Aring', 'Atilde',
  9909. 'Ccedilla', 'Eacute', 'Ecircumflex', 'Edieresis', 'Egrave', 'Iacute',
  9910. 'Icircumflex', 'Idieresis', 'Igrave', 'Ntilde', 'Oacute', 'Ocircumflex',
  9911. 'Odieresis', 'Ograve', 'Otilde', 'Scaron', 'Uacute', 'Ucircumflex',
  9912. 'Udieresis', 'Ugrave', 'Yacute', 'Ydieresis', 'Zcaron', 'aacute',
  9913. 'acircumflex', 'adieresis', 'agrave', 'aring', 'atilde', 'ccedilla',
  9914. 'eacute', 'ecircumflex', 'edieresis', 'egrave', 'iacute', 'icircumflex',
  9915. 'idieresis', 'igrave', 'ntilde', 'oacute', 'ocircumflex', 'odieresis',
  9916. 'ograve', 'otilde', 'scaron', 'uacute', 'ucircumflex', 'udieresis',
  9917. 'ugrave', 'yacute', 'ydieresis', 'zcaron'
  9918. ];
  9919. var ExpertCharset = [
  9920. '.notdef', 'space', 'exclamsmall', 'Hungarumlautsmall', 'dollaroldstyle',
  9921. 'dollarsuperior', 'ampersandsmall', 'Acutesmall', 'parenleftsuperior',
  9922. 'parenrightsuperior', 'twodotenleader', 'onedotenleader', 'comma',
  9923. 'hyphen', 'period', 'fraction', 'zerooldstyle', 'oneoldstyle',
  9924. 'twooldstyle', 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle',
  9925. 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle',
  9926. 'colon', 'semicolon', 'commasuperior', 'threequartersemdash',
  9927. 'periodsuperior', 'questionsmall', 'asuperior', 'bsuperior',
  9928. 'centsuperior', 'dsuperior', 'esuperior', 'isuperior', 'lsuperior',
  9929. 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  9930. 'tsuperior', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior',
  9931. 'parenrightinferior', 'Circumflexsmall', 'hyphensuperior', 'Gravesmall',
  9932. 'Asmall', 'Bsmall', 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall',
  9933. 'Hsmall', 'Ismall', 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall',
  9934. 'Osmall', 'Psmall', 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall',
  9935. 'Vsmall', 'Wsmall', 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary',
  9936. 'onefitted', 'rupiah', 'Tildesmall', 'exclamdownsmall', 'centoldstyle',
  9937. 'Lslashsmall', 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall',
  9938. 'Brevesmall', 'Caronsmall', 'Dotaccentsmall', 'Macronsmall',
  9939. 'figuredash', 'hypheninferior', 'Ogoneksmall', 'Ringsmall',
  9940. 'Cedillasmall', 'onequarter', 'onehalf', 'threequarters',
  9941. 'questiondownsmall', 'oneeighth', 'threeeighths', 'fiveeighths',
  9942. 'seveneighths', 'onethird', 'twothirds', 'zerosuperior', 'onesuperior',
  9943. 'twosuperior', 'threesuperior', 'foursuperior', 'fivesuperior',
  9944. 'sixsuperior', 'sevensuperior', 'eightsuperior', 'ninesuperior',
  9945. 'zeroinferior', 'oneinferior', 'twoinferior', 'threeinferior',
  9946. 'fourinferior', 'fiveinferior', 'sixinferior', 'seveninferior',
  9947. 'eightinferior', 'nineinferior', 'centinferior', 'dollarinferior',
  9948. 'periodinferior', 'commainferior', 'Agravesmall', 'Aacutesmall',
  9949. 'Acircumflexsmall', 'Atildesmall', 'Adieresissmall', 'Aringsmall',
  9950. 'AEsmall', 'Ccedillasmall', 'Egravesmall', 'Eacutesmall',
  9951. 'Ecircumflexsmall', 'Edieresissmall', 'Igravesmall', 'Iacutesmall',
  9952. 'Icircumflexsmall', 'Idieresissmall', 'Ethsmall', 'Ntildesmall',
  9953. 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall', 'Otildesmall',
  9954. 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall', 'Uacutesmall',
  9955. 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall', 'Thornsmall',
  9956. 'Ydieresissmall'
  9957. ];
  9958. var ExpertSubsetCharset = [
  9959. '.notdef', 'space', 'dollaroldstyle', 'dollarsuperior',
  9960. 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  9961. 'onedotenleader', 'comma', 'hyphen', 'period', 'fraction',
  9962. 'zerooldstyle', 'oneoldstyle', 'twooldstyle', 'threeoldstyle',
  9963. 'fouroldstyle', 'fiveoldstyle', 'sixoldstyle', 'sevenoldstyle',
  9964. 'eightoldstyle', 'nineoldstyle', 'colon', 'semicolon', 'commasuperior',
  9965. 'threequartersemdash', 'periodsuperior', 'asuperior', 'bsuperior',
  9966. 'centsuperior', 'dsuperior', 'esuperior', 'isuperior', 'lsuperior',
  9967. 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  9968. 'tsuperior', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior',
  9969. 'parenrightinferior', 'hyphensuperior', 'colonmonetary', 'onefitted',
  9970. 'rupiah', 'centoldstyle', 'figuredash', 'hypheninferior', 'onequarter',
  9971. 'onehalf', 'threequarters', 'oneeighth', 'threeeighths', 'fiveeighths',
  9972. 'seveneighths', 'onethird', 'twothirds', 'zerosuperior', 'onesuperior',
  9973. 'twosuperior', 'threesuperior', 'foursuperior', 'fivesuperior',
  9974. 'sixsuperior', 'sevensuperior', 'eightsuperior', 'ninesuperior',
  9975. 'zeroinferior', 'oneinferior', 'twoinferior', 'threeinferior',
  9976. 'fourinferior', 'fiveinferior', 'sixinferior', 'seveninferior',
  9977. 'eightinferior', 'nineinferior', 'centinferior', 'dollarinferior',
  9978. 'periodinferior', 'commainferior'
  9979. ];
  9980. var DEFAULT_ICON_SIZE = 22; // px
  9981. var SUPPORTED_TYPES = ['Link', 'Text', 'Widget'];
  9982. var Annotation = (function AnnotationClosure() {
  9983. // 12.5.5: Algorithm: Appearance streams
  9984. function getTransformMatrix(rect, bbox, matrix) {
  9985. var bounds = Util.getAxialAlignedBoundingBox(bbox, matrix);
  9986. var minX = bounds[0];
  9987. var minY = bounds[1];
  9988. var maxX = bounds[2];
  9989. var maxY = bounds[3];
  9990. if (minX === maxX || minY === maxY) {
  9991. // From real-life file, bbox was [0, 0, 0, 0]. In this case,
  9992. // just apply the transform for rect
  9993. return [1, 0, 0, 1, rect[0], rect[1]];
  9994. }
  9995. var xRatio = (rect[2] - rect[0]) / (maxX - minX);
  9996. var yRatio = (rect[3] - rect[1]) / (maxY - minY);
  9997. return [
  9998. xRatio,
  9999. 0,
  10000. 0,
  10001. yRatio,
  10002. rect[0] - minX * xRatio,
  10003. rect[1] - minY * yRatio
  10004. ];
  10005. }
  10006. function getDefaultAppearance(dict) {
  10007. var appearanceState = dict.get('AP');
  10008. if (!isDict(appearanceState)) {
  10009. return;
  10010. }
  10011. var appearance;
  10012. var appearances = appearanceState.get('N');
  10013. if (isDict(appearances)) {
  10014. var as = dict.get('AS');
  10015. if (as && appearances.has(as.name)) {
  10016. appearance = appearances.get(as.name);
  10017. }
  10018. } else {
  10019. appearance = appearances;
  10020. }
  10021. return appearance;
  10022. }
  10023. function Annotation(params) {
  10024. var dict = params.dict;
  10025. var data = this.data = {};
  10026. data.subtype = dict.get('Subtype').name;
  10027. var rect = dict.get('Rect') || [0, 0, 0, 0];
  10028. data.rect = Util.normalizeRect(rect);
  10029. data.annotationFlags = dict.get('F');
  10030. var color = dict.get('C');
  10031. if (!color) {
  10032. // The PDF spec does not mention how a missing color array is interpreted.
  10033. // Adobe Reader seems to default to black in this case.
  10034. data.color = [0, 0, 0];
  10035. } else if (isArray(color)) {
  10036. switch (color.length) {
  10037. case 0:
  10038. // Empty array denotes transparent border.
  10039. data.color = null;
  10040. break;
  10041. case 1:
  10042. // TODO: implement DeviceGray
  10043. break;
  10044. case 3:
  10045. data.color = color;
  10046. break;
  10047. case 4:
  10048. // TODO: implement DeviceCMYK
  10049. break;
  10050. }
  10051. }
  10052. // Some types of annotations have border style dict which has more
  10053. // info than the border array
  10054. if (dict.has('BS')) {
  10055. var borderStyle = dict.get('BS');
  10056. data.borderWidth = borderStyle.has('W') ? borderStyle.get('W') : 1;
  10057. } else {
  10058. var borderArray = dict.get('Border') || [0, 0, 1];
  10059. data.borderWidth = borderArray[2] || 0;
  10060. // TODO: implement proper support for annotations with line dash patterns.
  10061. var dashArray = borderArray[3];
  10062. if (data.borderWidth > 0 && dashArray) {
  10063. if (!isArray(dashArray)) {
  10064. // Ignore the border if dashArray is not actually an array,
  10065. // this is consistent with the behaviour in Adobe Reader.
  10066. data.borderWidth = 0;
  10067. } else {
  10068. var dashArrayLength = dashArray.length;
  10069. if (dashArrayLength > 0) {
  10070. // According to the PDF specification: the elements in a dashArray
  10071. // shall be numbers that are nonnegative and not all equal to zero.
  10072. var isInvalid = false;
  10073. var numPositive = 0;
  10074. for (var i = 0; i < dashArrayLength; i++) {
  10075. var validNumber = (+dashArray[i] >= 0);
  10076. if (!validNumber) {
  10077. isInvalid = true;
  10078. break;
  10079. } else if (dashArray[i] > 0) {
  10080. numPositive++;
  10081. }
  10082. }
  10083. if (isInvalid || numPositive === 0) {
  10084. data.borderWidth = 0;
  10085. }
  10086. }
  10087. }
  10088. }
  10089. }
  10090. this.appearance = getDefaultAppearance(dict);
  10091. data.hasAppearance = !!this.appearance;
  10092. data.id = params.ref.num;
  10093. }
  10094. Annotation.prototype = {
  10095. getData: function Annotation_getData() {
  10096. return this.data;
  10097. },
  10098. isInvisible: function Annotation_isInvisible() {
  10099. var data = this.data;
  10100. if (data && SUPPORTED_TYPES.indexOf(data.subtype) !== -1) {
  10101. return false;
  10102. } else {
  10103. return !!(data &&
  10104. data.annotationFlags && // Default: not invisible
  10105. data.annotationFlags & 0x1); // Invisible
  10106. }
  10107. },
  10108. isViewable: function Annotation_isViewable() {
  10109. var data = this.data;
  10110. return !!(!this.isInvisible() &&
  10111. data &&
  10112. (!data.annotationFlags ||
  10113. !(data.annotationFlags & 0x22)) && // Hidden or NoView
  10114. data.rect); // rectangle is necessary
  10115. },
  10116. isPrintable: function Annotation_isPrintable() {
  10117. var data = this.data;
  10118. return !!(!this.isInvisible() &&
  10119. data &&
  10120. data.annotationFlags && // Default: not printable
  10121. data.annotationFlags & 0x4 && // Print
  10122. !(data.annotationFlags & 0x2) && // Hidden
  10123. data.rect); // rectangle is necessary
  10124. },
  10125. loadResources: function Annotation_loadResources(keys) {
  10126. return new Promise(function (resolve, reject) {
  10127. this.appearance.dict.getAsync('Resources').then(function (resources) {
  10128. if (!resources) {
  10129. resolve();
  10130. return;
  10131. }
  10132. var objectLoader = new ObjectLoader(resources.map,
  10133. keys,
  10134. resources.xref);
  10135. objectLoader.load().then(function() {
  10136. resolve(resources);
  10137. }, reject);
  10138. }, reject);
  10139. }.bind(this));
  10140. },
  10141. getOperatorList: function Annotation_getOperatorList(evaluator) {
  10142. if (!this.appearance) {
  10143. return Promise.resolve(new OperatorList());
  10144. }
  10145. var data = this.data;
  10146. var appearanceDict = this.appearance.dict;
  10147. var resourcesPromise = this.loadResources([
  10148. 'ExtGState',
  10149. 'ColorSpace',
  10150. 'Pattern',
  10151. 'Shading',
  10152. 'XObject',
  10153. 'Font'
  10154. // ProcSet
  10155. // Properties
  10156. ]);
  10157. var bbox = appearanceDict.get('BBox') || [0, 0, 1, 1];
  10158. var matrix = appearanceDict.get('Matrix') || [1, 0, 0, 1, 0 ,0];
  10159. var transform = getTransformMatrix(data.rect, bbox, matrix);
  10160. var self = this;
  10161. return resourcesPromise.then(function(resources) {
  10162. var opList = new OperatorList();
  10163. opList.addOp(OPS.beginAnnotation, [data.rect, transform, matrix]);
  10164. return evaluator.getOperatorList(self.appearance, resources, opList).
  10165. then(function () {
  10166. opList.addOp(OPS.endAnnotation, []);
  10167. self.appearance.reset();
  10168. return opList;
  10169. });
  10170. });
  10171. }
  10172. };
  10173. Annotation.getConstructor =
  10174. function Annotation_getConstructor(subtype, fieldType) {
  10175. if (!subtype) {
  10176. return;
  10177. }
  10178. // TODO(mack): Implement FreeText annotations
  10179. if (subtype === 'Link') {
  10180. return LinkAnnotation;
  10181. } else if (subtype === 'Text') {
  10182. return TextAnnotation;
  10183. } else if (subtype === 'Widget') {
  10184. if (!fieldType) {
  10185. return;
  10186. }
  10187. if (fieldType === 'Tx') {
  10188. return TextWidgetAnnotation;
  10189. } else {
  10190. return WidgetAnnotation;
  10191. }
  10192. } else {
  10193. return Annotation;
  10194. }
  10195. };
  10196. Annotation.fromRef = function Annotation_fromRef(xref, ref) {
  10197. var dict = xref.fetchIfRef(ref);
  10198. if (!isDict(dict)) {
  10199. return;
  10200. }
  10201. var subtype = dict.get('Subtype');
  10202. subtype = isName(subtype) ? subtype.name : '';
  10203. if (!subtype) {
  10204. return;
  10205. }
  10206. var fieldType = Util.getInheritableProperty(dict, 'FT');
  10207. fieldType = isName(fieldType) ? fieldType.name : '';
  10208. var Constructor = Annotation.getConstructor(subtype, fieldType);
  10209. if (!Constructor) {
  10210. return;
  10211. }
  10212. var params = {
  10213. dict: dict,
  10214. ref: ref,
  10215. };
  10216. var annotation = new Constructor(params);
  10217. if (annotation.isViewable() || annotation.isPrintable()) {
  10218. return annotation;
  10219. } else {
  10220. if (SUPPORTED_TYPES.indexOf(subtype) === -1) {
  10221. warn('unimplemented annotation type: ' + subtype);
  10222. }
  10223. }
  10224. };
  10225. Annotation.appendToOperatorList = function Annotation_appendToOperatorList(
  10226. annotations, opList, pdfManager, partialEvaluator, intent) {
  10227. function reject(e) {
  10228. annotationsReadyCapability.reject(e);
  10229. }
  10230. var annotationsReadyCapability = createPromiseCapability();
  10231. var annotationPromises = [];
  10232. for (var i = 0, n = annotations.length; i < n; ++i) {
  10233. if (intent === 'display' && annotations[i].isViewable() ||
  10234. intent === 'print' && annotations[i].isPrintable()) {
  10235. annotationPromises.push(
  10236. annotations[i].getOperatorList(partialEvaluator));
  10237. }
  10238. }
  10239. Promise.all(annotationPromises).then(function(datas) {
  10240. opList.addOp(OPS.beginAnnotations, []);
  10241. for (var i = 0, n = datas.length; i < n; ++i) {
  10242. var annotOpList = datas[i];
  10243. opList.addOpList(annotOpList);
  10244. }
  10245. opList.addOp(OPS.endAnnotations, []);
  10246. annotationsReadyCapability.resolve();
  10247. }, reject);
  10248. return annotationsReadyCapability.promise;
  10249. };
  10250. return Annotation;
  10251. })();
  10252. var WidgetAnnotation = (function WidgetAnnotationClosure() {
  10253. function WidgetAnnotation(params) {
  10254. Annotation.call(this, params);
  10255. var dict = params.dict;
  10256. var data = this.data;
  10257. data.fieldValue = stringToPDFString(
  10258. Util.getInheritableProperty(dict, 'V') || '');
  10259. data.alternativeText = stringToPDFString(dict.get('TU') || '');
  10260. data.defaultAppearance = Util.getInheritableProperty(dict, 'DA') || '';
  10261. var fieldType = Util.getInheritableProperty(dict, 'FT');
  10262. data.fieldType = isName(fieldType) ? fieldType.name : '';
  10263. data.fieldFlags = Util.getInheritableProperty(dict, 'Ff') || 0;
  10264. this.fieldResources = Util.getInheritableProperty(dict, 'DR') || Dict.empty;
  10265. // Building the full field name by collecting the field and
  10266. // its ancestors 'T' data and joining them using '.'.
  10267. var fieldName = [];
  10268. var namedItem = dict;
  10269. var ref = params.ref;
  10270. while (namedItem) {
  10271. var parent = namedItem.get('Parent');
  10272. var parentRef = namedItem.getRaw('Parent');
  10273. var name = namedItem.get('T');
  10274. if (name) {
  10275. fieldName.unshift(stringToPDFString(name));
  10276. } else if (parent && ref) {
  10277. // The field name is absent, that means more than one field
  10278. // with the same name may exist. Replacing the empty name
  10279. // with the '`' plus index in the parent's 'Kids' array.
  10280. // This is not in the PDF spec but necessary to id the
  10281. // the input controls.
  10282. var kids = parent.get('Kids');
  10283. var j, jj;
  10284. for (j = 0, jj = kids.length; j < jj; j++) {
  10285. var kidRef = kids[j];
  10286. if (kidRef.num === ref.num && kidRef.gen === ref.gen) {
  10287. break;
  10288. }
  10289. }
  10290. fieldName.unshift('`' + j);
  10291. }
  10292. namedItem = parent;
  10293. ref = parentRef;
  10294. }
  10295. data.fullName = fieldName.join('.');
  10296. }
  10297. var parent = Annotation.prototype;
  10298. Util.inherit(WidgetAnnotation, Annotation, {
  10299. isViewable: function WidgetAnnotation_isViewable() {
  10300. if (this.data.fieldType === 'Sig') {
  10301. warn('unimplemented annotation type: Widget signature');
  10302. return false;
  10303. }
  10304. return parent.isViewable.call(this);
  10305. }
  10306. });
  10307. return WidgetAnnotation;
  10308. })();
  10309. var TextWidgetAnnotation = (function TextWidgetAnnotationClosure() {
  10310. function TextWidgetAnnotation(params) {
  10311. WidgetAnnotation.call(this, params);
  10312. this.data.textAlignment = Util.getInheritableProperty(params.dict, 'Q');
  10313. this.data.annotationType = AnnotationType.WIDGET;
  10314. this.data.hasHtml = !this.data.hasAppearance && !!this.data.fieldValue;
  10315. }
  10316. Util.inherit(TextWidgetAnnotation, WidgetAnnotation, {
  10317. getOperatorList: function TextWidgetAnnotation_getOperatorList(evaluator) {
  10318. if (this.appearance) {
  10319. return Annotation.prototype.getOperatorList.call(this, evaluator);
  10320. }
  10321. var opList = new OperatorList();
  10322. var data = this.data;
  10323. // Even if there is an appearance stream, ignore it. This is the
  10324. // behaviour used by Adobe Reader.
  10325. if (!data.defaultAppearance) {
  10326. return Promise.resolve(opList);
  10327. }
  10328. var stream = new Stream(stringToBytes(data.defaultAppearance));
  10329. return evaluator.getOperatorList(stream, this.fieldResources, opList).
  10330. then(function () {
  10331. return opList;
  10332. });
  10333. }
  10334. });
  10335. return TextWidgetAnnotation;
  10336. })();
  10337. var InteractiveAnnotation = (function InteractiveAnnotationClosure() {
  10338. function InteractiveAnnotation(params) {
  10339. Annotation.call(this, params);
  10340. this.data.hasHtml = true;
  10341. }
  10342. Util.inherit(InteractiveAnnotation, Annotation, { });
  10343. return InteractiveAnnotation;
  10344. })();
  10345. var TextAnnotation = (function TextAnnotationClosure() {
  10346. function TextAnnotation(params) {
  10347. InteractiveAnnotation.call(this, params);
  10348. var dict = params.dict;
  10349. var data = this.data;
  10350. var content = dict.get('Contents');
  10351. var title = dict.get('T');
  10352. data.annotationType = AnnotationType.TEXT;
  10353. data.content = stringToPDFString(content || '');
  10354. data.title = stringToPDFString(title || '');
  10355. if (data.hasAppearance) {
  10356. data.name = 'NoIcon';
  10357. } else {
  10358. data.rect[1] = data.rect[3] - DEFAULT_ICON_SIZE;
  10359. data.rect[2] = data.rect[0] + DEFAULT_ICON_SIZE;
  10360. data.name = dict.has('Name') ? dict.get('Name').name : 'Note';
  10361. }
  10362. if (dict.has('C')) {
  10363. data.hasBgColor = true;
  10364. }
  10365. }
  10366. Util.inherit(TextAnnotation, InteractiveAnnotation, { });
  10367. return TextAnnotation;
  10368. })();
  10369. var LinkAnnotation = (function LinkAnnotationClosure() {
  10370. function LinkAnnotation(params) {
  10371. InteractiveAnnotation.call(this, params);
  10372. var dict = params.dict;
  10373. var data = this.data;
  10374. data.annotationType = AnnotationType.LINK;
  10375. var action = dict.get('A');
  10376. if (action && isDict(action)) {
  10377. var linkType = action.get('S').name;
  10378. if (linkType === 'URI') {
  10379. var url = action.get('URI');
  10380. if (isName(url)) {
  10381. // Some bad PDFs do not put parentheses around relative URLs.
  10382. url = '/' + url.name;
  10383. } else if (url) {
  10384. url = addDefaultProtocolToUrl(url);
  10385. }
  10386. // TODO: pdf spec mentions urls can be relative to a Base
  10387. // entry in the dictionary.
  10388. if (!isValidUrl(url, false)) {
  10389. url = '';
  10390. }
  10391. data.url = url;
  10392. } else if (linkType === 'GoTo') {
  10393. data.dest = action.get('D');
  10394. } else if (linkType === 'GoToR') {
  10395. var urlDict = action.get('F');
  10396. if (isDict(urlDict)) {
  10397. // We assume that the 'url' is a Filspec dictionary
  10398. // and fetch the url without checking any further
  10399. url = urlDict.get('F') || '';
  10400. }
  10401. // TODO: pdf reference says that GoToR
  10402. // can also have 'NewWindow' attribute
  10403. if (!isValidUrl(url, false)) {
  10404. url = '';
  10405. }
  10406. data.url = url;
  10407. data.dest = action.get('D');
  10408. } else if (linkType === 'Named') {
  10409. data.action = action.get('N').name;
  10410. } else {
  10411. warn('unrecognized link type: ' + linkType);
  10412. }
  10413. } else if (dict.has('Dest')) {
  10414. // simple destination link
  10415. var dest = dict.get('Dest');
  10416. data.dest = isName(dest) ? dest.name : dest;
  10417. }
  10418. }
  10419. // Lets URLs beginning with 'www.' default to using the 'http://' protocol.
  10420. function addDefaultProtocolToUrl(url) {
  10421. if (url && url.indexOf('www.') === 0) {
  10422. return ('http://' + url);
  10423. }
  10424. return url;
  10425. }
  10426. Util.inherit(LinkAnnotation, InteractiveAnnotation, { });
  10427. return LinkAnnotation;
  10428. })();
  10429. var PDFFunction = (function PDFFunctionClosure() {
  10430. var CONSTRUCT_SAMPLED = 0;
  10431. var CONSTRUCT_INTERPOLATED = 2;
  10432. var CONSTRUCT_STICHED = 3;
  10433. var CONSTRUCT_POSTSCRIPT = 4;
  10434. return {
  10435. getSampleArray: function PDFFunction_getSampleArray(size, outputSize, bps,
  10436. str) {
  10437. var i, ii;
  10438. var length = 1;
  10439. for (i = 0, ii = size.length; i < ii; i++) {
  10440. length *= size[i];
  10441. }
  10442. length *= outputSize;
  10443. var array = new Array(length);
  10444. var codeSize = 0;
  10445. var codeBuf = 0;
  10446. // 32 is a valid bps so shifting won't work
  10447. var sampleMul = 1.0 / (Math.pow(2.0, bps) - 1);
  10448. var strBytes = str.getBytes((length * bps + 7) / 8);
  10449. var strIdx = 0;
  10450. for (i = 0; i < length; i++) {
  10451. while (codeSize < bps) {
  10452. codeBuf <<= 8;
  10453. codeBuf |= strBytes[strIdx++];
  10454. codeSize += 8;
  10455. }
  10456. codeSize -= bps;
  10457. array[i] = (codeBuf >> codeSize) * sampleMul;
  10458. codeBuf &= (1 << codeSize) - 1;
  10459. }
  10460. return array;
  10461. },
  10462. getIR: function PDFFunction_getIR(xref, fn) {
  10463. var dict = fn.dict;
  10464. if (!dict) {
  10465. dict = fn;
  10466. }
  10467. var types = [this.constructSampled,
  10468. null,
  10469. this.constructInterpolated,
  10470. this.constructStiched,
  10471. this.constructPostScript];
  10472. var typeNum = dict.get('FunctionType');
  10473. var typeFn = types[typeNum];
  10474. if (!typeFn) {
  10475. error('Unknown type of function');
  10476. }
  10477. return typeFn.call(this, fn, dict, xref);
  10478. },
  10479. fromIR: function PDFFunction_fromIR(IR) {
  10480. var type = IR[0];
  10481. switch (type) {
  10482. case CONSTRUCT_SAMPLED:
  10483. return this.constructSampledFromIR(IR);
  10484. case CONSTRUCT_INTERPOLATED:
  10485. return this.constructInterpolatedFromIR(IR);
  10486. case CONSTRUCT_STICHED:
  10487. return this.constructStichedFromIR(IR);
  10488. //case CONSTRUCT_POSTSCRIPT:
  10489. default:
  10490. return this.constructPostScriptFromIR(IR);
  10491. }
  10492. },
  10493. parse: function PDFFunction_parse(xref, fn) {
  10494. var IR = this.getIR(xref, fn);
  10495. return this.fromIR(IR);
  10496. },
  10497. parseArray: function PDFFunction_parseArray(xref, fnObj) {
  10498. if (!isArray(fnObj)) {
  10499. // not an array -- parsing as regular function
  10500. return this.parse(xref, fnObj);
  10501. }
  10502. var fnArray = [];
  10503. for (var j = 0, jj = fnObj.length; j < jj; j++) {
  10504. var obj = xref.fetchIfRef(fnObj[j]);
  10505. fnArray.push(PDFFunction.parse(xref, obj));
  10506. }
  10507. return function (src, srcOffset, dest, destOffset) {
  10508. for (var i = 0, ii = fnArray.length; i < ii; i++) {
  10509. fnArray[i](src, srcOffset, dest, destOffset + i);
  10510. }
  10511. };
  10512. },
  10513. constructSampled: function PDFFunction_constructSampled(str, dict) {
  10514. function toMultiArray(arr) {
  10515. var inputLength = arr.length;
  10516. var out = [];
  10517. var index = 0;
  10518. for (var i = 0; i < inputLength; i += 2) {
  10519. out[index] = [arr[i], arr[i + 1]];
  10520. ++index;
  10521. }
  10522. return out;
  10523. }
  10524. var domain = dict.get('Domain');
  10525. var range = dict.get('Range');
  10526. if (!domain || !range) {
  10527. error('No domain or range');
  10528. }
  10529. var inputSize = domain.length / 2;
  10530. var outputSize = range.length / 2;
  10531. domain = toMultiArray(domain);
  10532. range = toMultiArray(range);
  10533. var size = dict.get('Size');
  10534. var bps = dict.get('BitsPerSample');
  10535. var order = dict.get('Order') || 1;
  10536. if (order !== 1) {
  10537. // No description how cubic spline interpolation works in PDF32000:2008
  10538. // As in poppler, ignoring order, linear interpolation may work as good
  10539. info('No support for cubic spline interpolation: ' + order);
  10540. }
  10541. var encode = dict.get('Encode');
  10542. if (!encode) {
  10543. encode = [];
  10544. for (var i = 0; i < inputSize; ++i) {
  10545. encode.push(0);
  10546. encode.push(size[i] - 1);
  10547. }
  10548. }
  10549. encode = toMultiArray(encode);
  10550. var decode = dict.get('Decode');
  10551. if (!decode) {
  10552. decode = range;
  10553. } else {
  10554. decode = toMultiArray(decode);
  10555. }
  10556. var samples = this.getSampleArray(size, outputSize, bps, str);
  10557. return [
  10558. CONSTRUCT_SAMPLED, inputSize, domain, encode, decode, samples, size,
  10559. outputSize, Math.pow(2, bps) - 1, range
  10560. ];
  10561. },
  10562. constructSampledFromIR: function PDFFunction_constructSampledFromIR(IR) {
  10563. // See chapter 3, page 109 of the PDF reference
  10564. function interpolate(x, xmin, xmax, ymin, ymax) {
  10565. return ymin + ((x - xmin) * ((ymax - ymin) / (xmax - xmin)));
  10566. }
  10567. return function constructSampledFromIRResult(src, srcOffset,
  10568. dest, destOffset) {
  10569. // See chapter 3, page 110 of the PDF reference.
  10570. var m = IR[1];
  10571. var domain = IR[2];
  10572. var encode = IR[3];
  10573. var decode = IR[4];
  10574. var samples = IR[5];
  10575. var size = IR[6];
  10576. var n = IR[7];
  10577. //var mask = IR[8];
  10578. var range = IR[9];
  10579. // Building the cube vertices: its part and sample index
  10580. // http://rjwagner49.com/Mathematics/Interpolation.pdf
  10581. var cubeVertices = 1 << m;
  10582. var cubeN = new Float64Array(cubeVertices);
  10583. var cubeVertex = new Uint32Array(cubeVertices);
  10584. var i, j;
  10585. for (j = 0; j < cubeVertices; j++) {
  10586. cubeN[j] = 1;
  10587. }
  10588. var k = n, pos = 1;
  10589. // Map x_i to y_j for 0 <= i < m using the sampled function.
  10590. for (i = 0; i < m; ++i) {
  10591. // x_i' = min(max(x_i, Domain_2i), Domain_2i+1)
  10592. var domain_2i = domain[i][0];
  10593. var domain_2i_1 = domain[i][1];
  10594. var xi = Math.min(Math.max(src[srcOffset +i], domain_2i),
  10595. domain_2i_1);
  10596. // e_i = Interpolate(x_i', Domain_2i, Domain_2i+1,
  10597. // Encode_2i, Encode_2i+1)
  10598. var e = interpolate(xi, domain_2i, domain_2i_1,
  10599. encode[i][0], encode[i][1]);
  10600. // e_i' = min(max(e_i, 0), Size_i - 1)
  10601. var size_i = size[i];
  10602. e = Math.min(Math.max(e, 0), size_i - 1);
  10603. // Adjusting the cube: N and vertex sample index
  10604. var e0 = e < size_i - 1 ? Math.floor(e) : e - 1; // e1 = e0 + 1;
  10605. var n0 = e0 + 1 - e; // (e1 - e) / (e1 - e0);
  10606. var n1 = e - e0; // (e - e0) / (e1 - e0);
  10607. var offset0 = e0 * k;
  10608. var offset1 = offset0 + k; // e1 * k
  10609. for (j = 0; j < cubeVertices; j++) {
  10610. if (j & pos) {
  10611. cubeN[j] *= n1;
  10612. cubeVertex[j] += offset1;
  10613. } else {
  10614. cubeN[j] *= n0;
  10615. cubeVertex[j] += offset0;
  10616. }
  10617. }
  10618. k *= size_i;
  10619. pos <<= 1;
  10620. }
  10621. for (j = 0; j < n; ++j) {
  10622. // Sum all cube vertices' samples portions
  10623. var rj = 0;
  10624. for (i = 0; i < cubeVertices; i++) {
  10625. rj += samples[cubeVertex[i] + j] * cubeN[i];
  10626. }
  10627. // r_j' = Interpolate(r_j, 0, 2^BitsPerSample - 1,
  10628. // Decode_2j, Decode_2j+1)
  10629. rj = interpolate(rj, 0, 1, decode[j][0], decode[j][1]);
  10630. // y_j = min(max(r_j, range_2j), range_2j+1)
  10631. dest[destOffset + j] = Math.min(Math.max(rj, range[j][0]),
  10632. range[j][1]);
  10633. }
  10634. };
  10635. },
  10636. constructInterpolated: function PDFFunction_constructInterpolated(str,
  10637. dict) {
  10638. var c0 = dict.get('C0') || [0];
  10639. var c1 = dict.get('C1') || [1];
  10640. var n = dict.get('N');
  10641. if (!isArray(c0) || !isArray(c1)) {
  10642. error('Illegal dictionary for interpolated function');
  10643. }
  10644. var length = c0.length;
  10645. var diff = [];
  10646. for (var i = 0; i < length; ++i) {
  10647. diff.push(c1[i] - c0[i]);
  10648. }
  10649. return [CONSTRUCT_INTERPOLATED, c0, diff, n];
  10650. },
  10651. constructInterpolatedFromIR:
  10652. function PDFFunction_constructInterpolatedFromIR(IR) {
  10653. var c0 = IR[1];
  10654. var diff = IR[2];
  10655. var n = IR[3];
  10656. var length = diff.length;
  10657. return function constructInterpolatedFromIRResult(src, srcOffset,
  10658. dest, destOffset) {
  10659. var x = n === 1 ? src[srcOffset] : Math.pow(src[srcOffset], n);
  10660. for (var j = 0; j < length; ++j) {
  10661. dest[destOffset + j] = c0[j] + (x * diff[j]);
  10662. }
  10663. };
  10664. },
  10665. constructStiched: function PDFFunction_constructStiched(fn, dict, xref) {
  10666. var domain = dict.get('Domain');
  10667. if (!domain) {
  10668. error('No domain');
  10669. }
  10670. var inputSize = domain.length / 2;
  10671. if (inputSize !== 1) {
  10672. error('Bad domain for stiched function');
  10673. }
  10674. var fnRefs = dict.get('Functions');
  10675. var fns = [];
  10676. for (var i = 0, ii = fnRefs.length; i < ii; ++i) {
  10677. fns.push(PDFFunction.getIR(xref, xref.fetchIfRef(fnRefs[i])));
  10678. }
  10679. var bounds = dict.get('Bounds');
  10680. var encode = dict.get('Encode');
  10681. return [CONSTRUCT_STICHED, domain, bounds, encode, fns];
  10682. },
  10683. constructStichedFromIR: function PDFFunction_constructStichedFromIR(IR) {
  10684. var domain = IR[1];
  10685. var bounds = IR[2];
  10686. var encode = IR[3];
  10687. var fnsIR = IR[4];
  10688. var fns = [];
  10689. var tmpBuf = new Float32Array(1);
  10690. for (var i = 0, ii = fnsIR.length; i < ii; i++) {
  10691. fns.push(PDFFunction.fromIR(fnsIR[i]));
  10692. }
  10693. return function constructStichedFromIRResult(src, srcOffset,
  10694. dest, destOffset) {
  10695. var clip = function constructStichedFromIRClip(v, min, max) {
  10696. if (v > max) {
  10697. v = max;
  10698. } else if (v < min) {
  10699. v = min;
  10700. }
  10701. return v;
  10702. };
  10703. // clip to domain
  10704. var v = clip(src[srcOffset], domain[0], domain[1]);
  10705. // calulate which bound the value is in
  10706. for (var i = 0, ii = bounds.length; i < ii; ++i) {
  10707. if (v < bounds[i]) {
  10708. break;
  10709. }
  10710. }
  10711. // encode value into domain of function
  10712. var dmin = domain[0];
  10713. if (i > 0) {
  10714. dmin = bounds[i - 1];
  10715. }
  10716. var dmax = domain[1];
  10717. if (i < bounds.length) {
  10718. dmax = bounds[i];
  10719. }
  10720. var rmin = encode[2 * i];
  10721. var rmax = encode[2 * i + 1];
  10722. tmpBuf[0] = rmin + (v - dmin) * (rmax - rmin) / (dmax - dmin);
  10723. // call the appropriate function
  10724. fns[i](tmpBuf, 0, dest, destOffset);
  10725. };
  10726. },
  10727. constructPostScript: function PDFFunction_constructPostScript(fn, dict,
  10728. xref) {
  10729. var domain = dict.get('Domain');
  10730. var range = dict.get('Range');
  10731. if (!domain) {
  10732. error('No domain.');
  10733. }
  10734. if (!range) {
  10735. error('No range.');
  10736. }
  10737. var lexer = new PostScriptLexer(fn);
  10738. var parser = new PostScriptParser(lexer);
  10739. var code = parser.parse();
  10740. return [CONSTRUCT_POSTSCRIPT, domain, range, code];
  10741. },
  10742. constructPostScriptFromIR: function PDFFunction_constructPostScriptFromIR(
  10743. IR) {
  10744. var domain = IR[1];
  10745. var range = IR[2];
  10746. var code = IR[3];
  10747. var compiled = (new PostScriptCompiler()).compile(code, domain, range);
  10748. if (compiled) {
  10749. // Compiled function consists of simple expressions such as addition,
  10750. // subtraction, Math.max, and also contains 'var' and 'return'
  10751. // statements. See the generation in the PostScriptCompiler below.
  10752. /*jshint -W054 */
  10753. return new Function('src', 'srcOffset', 'dest', 'destOffset', compiled);
  10754. }
  10755. info('Unable to compile PS function');
  10756. var numOutputs = range.length >> 1;
  10757. var numInputs = domain.length >> 1;
  10758. var evaluator = new PostScriptEvaluator(code);
  10759. // Cache the values for a big speed up, the cache size is limited though
  10760. // since the number of possible values can be huge from a PS function.
  10761. var cache = {};
  10762. // The MAX_CACHE_SIZE is set to ~4x the maximum number of distinct values
  10763. // seen in our tests.
  10764. var MAX_CACHE_SIZE = 2048 * 4;
  10765. var cache_available = MAX_CACHE_SIZE;
  10766. var tmpBuf = new Float32Array(numInputs);
  10767. return function constructPostScriptFromIRResult(src, srcOffset,
  10768. dest, destOffset) {
  10769. var i, value;
  10770. var key = '';
  10771. var input = tmpBuf;
  10772. for (i = 0; i < numInputs; i++) {
  10773. value = src[srcOffset + i];
  10774. input[i] = value;
  10775. key += value + '_';
  10776. }
  10777. var cachedValue = cache[key];
  10778. if (cachedValue !== undefined) {
  10779. dest.set(cachedValue, destOffset);
  10780. return;
  10781. }
  10782. var output = new Float32Array(numOutputs);
  10783. var stack = evaluator.execute(input);
  10784. var stackIndex = stack.length - numOutputs;
  10785. for (i = 0; i < numOutputs; i++) {
  10786. value = stack[stackIndex + i];
  10787. var bound = range[i * 2];
  10788. if (value < bound) {
  10789. value = bound;
  10790. } else {
  10791. bound = range[i * 2 +1];
  10792. if (value > bound) {
  10793. value = bound;
  10794. }
  10795. }
  10796. output[i] = value;
  10797. }
  10798. if (cache_available > 0) {
  10799. cache_available--;
  10800. cache[key] = output;
  10801. }
  10802. dest.set(output, destOffset);
  10803. };
  10804. }
  10805. };
  10806. })();
  10807. function isPDFFunction(v) {
  10808. var fnDict;
  10809. if (typeof v !== 'object') {
  10810. return false;
  10811. } else if (isDict(v)) {
  10812. fnDict = v;
  10813. } else if (isStream(v)) {
  10814. fnDict = v.dict;
  10815. } else {
  10816. return false;
  10817. }
  10818. return fnDict.has('FunctionType');
  10819. }
  10820. var PostScriptStack = (function PostScriptStackClosure() {
  10821. var MAX_STACK_SIZE = 100;
  10822. function PostScriptStack(initialStack) {
  10823. this.stack = !initialStack ? [] :
  10824. Array.prototype.slice.call(initialStack, 0);
  10825. }
  10826. PostScriptStack.prototype = {
  10827. push: function PostScriptStack_push(value) {
  10828. if (this.stack.length >= MAX_STACK_SIZE) {
  10829. error('PostScript function stack overflow.');
  10830. }
  10831. this.stack.push(value);
  10832. },
  10833. pop: function PostScriptStack_pop() {
  10834. if (this.stack.length <= 0) {
  10835. error('PostScript function stack underflow.');
  10836. }
  10837. return this.stack.pop();
  10838. },
  10839. copy: function PostScriptStack_copy(n) {
  10840. if (this.stack.length + n >= MAX_STACK_SIZE) {
  10841. error('PostScript function stack overflow.');
  10842. }
  10843. var stack = this.stack;
  10844. for (var i = stack.length - n, j = n - 1; j >= 0; j--, i++) {
  10845. stack.push(stack[i]);
  10846. }
  10847. },
  10848. index: function PostScriptStack_index(n) {
  10849. this.push(this.stack[this.stack.length - n - 1]);
  10850. },
  10851. // rotate the last n stack elements p times
  10852. roll: function PostScriptStack_roll(n, p) {
  10853. var stack = this.stack;
  10854. var l = stack.length - n;
  10855. var r = stack.length - 1, c = l + (p - Math.floor(p / n) * n), i, j, t;
  10856. for (i = l, j = r; i < j; i++, j--) {
  10857. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  10858. }
  10859. for (i = l, j = c - 1; i < j; i++, j--) {
  10860. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  10861. }
  10862. for (i = c, j = r; i < j; i++, j--) {
  10863. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  10864. }
  10865. }
  10866. };
  10867. return PostScriptStack;
  10868. })();
  10869. var PostScriptEvaluator = (function PostScriptEvaluatorClosure() {
  10870. function PostScriptEvaluator(operators) {
  10871. this.operators = operators;
  10872. }
  10873. PostScriptEvaluator.prototype = {
  10874. execute: function PostScriptEvaluator_execute(initialStack) {
  10875. var stack = new PostScriptStack(initialStack);
  10876. var counter = 0;
  10877. var operators = this.operators;
  10878. var length = operators.length;
  10879. var operator, a, b;
  10880. while (counter < length) {
  10881. operator = operators[counter++];
  10882. if (typeof operator === 'number') {
  10883. // Operator is really an operand and should be pushed to the stack.
  10884. stack.push(operator);
  10885. continue;
  10886. }
  10887. switch (operator) {
  10888. // non standard ps operators
  10889. case 'jz': // jump if false
  10890. b = stack.pop();
  10891. a = stack.pop();
  10892. if (!a) {
  10893. counter = b;
  10894. }
  10895. break;
  10896. case 'j': // jump
  10897. a = stack.pop();
  10898. counter = a;
  10899. break;
  10900. // all ps operators in alphabetical order (excluding if/ifelse)
  10901. case 'abs':
  10902. a = stack.pop();
  10903. stack.push(Math.abs(a));
  10904. break;
  10905. case 'add':
  10906. b = stack.pop();
  10907. a = stack.pop();
  10908. stack.push(a + b);
  10909. break;
  10910. case 'and':
  10911. b = stack.pop();
  10912. a = stack.pop();
  10913. if (isBool(a) && isBool(b)) {
  10914. stack.push(a && b);
  10915. } else {
  10916. stack.push(a & b);
  10917. }
  10918. break;
  10919. case 'atan':
  10920. a = stack.pop();
  10921. stack.push(Math.atan(a));
  10922. break;
  10923. case 'bitshift':
  10924. b = stack.pop();
  10925. a = stack.pop();
  10926. if (a > 0) {
  10927. stack.push(a << b);
  10928. } else {
  10929. stack.push(a >> b);
  10930. }
  10931. break;
  10932. case 'ceiling':
  10933. a = stack.pop();
  10934. stack.push(Math.ceil(a));
  10935. break;
  10936. case 'copy':
  10937. a = stack.pop();
  10938. stack.copy(a);
  10939. break;
  10940. case 'cos':
  10941. a = stack.pop();
  10942. stack.push(Math.cos(a));
  10943. break;
  10944. case 'cvi':
  10945. a = stack.pop() | 0;
  10946. stack.push(a);
  10947. break;
  10948. case 'cvr':
  10949. // noop
  10950. break;
  10951. case 'div':
  10952. b = stack.pop();
  10953. a = stack.pop();
  10954. stack.push(a / b);
  10955. break;
  10956. case 'dup':
  10957. stack.copy(1);
  10958. break;
  10959. case 'eq':
  10960. b = stack.pop();
  10961. a = stack.pop();
  10962. stack.push(a === b);
  10963. break;
  10964. case 'exch':
  10965. stack.roll(2, 1);
  10966. break;
  10967. case 'exp':
  10968. b = stack.pop();
  10969. a = stack.pop();
  10970. stack.push(Math.pow(a, b));
  10971. break;
  10972. case 'false':
  10973. stack.push(false);
  10974. break;
  10975. case 'floor':
  10976. a = stack.pop();
  10977. stack.push(Math.floor(a));
  10978. break;
  10979. case 'ge':
  10980. b = stack.pop();
  10981. a = stack.pop();
  10982. stack.push(a >= b);
  10983. break;
  10984. case 'gt':
  10985. b = stack.pop();
  10986. a = stack.pop();
  10987. stack.push(a > b);
  10988. break;
  10989. case 'idiv':
  10990. b = stack.pop();
  10991. a = stack.pop();
  10992. stack.push((a / b) | 0);
  10993. break;
  10994. case 'index':
  10995. a = stack.pop();
  10996. stack.index(a);
  10997. break;
  10998. case 'le':
  10999. b = stack.pop();
  11000. a = stack.pop();
  11001. stack.push(a <= b);
  11002. break;
  11003. case 'ln':
  11004. a = stack.pop();
  11005. stack.push(Math.log(a));
  11006. break;
  11007. case 'log':
  11008. a = stack.pop();
  11009. stack.push(Math.log(a) / Math.LN10);
  11010. break;
  11011. case 'lt':
  11012. b = stack.pop();
  11013. a = stack.pop();
  11014. stack.push(a < b);
  11015. break;
  11016. case 'mod':
  11017. b = stack.pop();
  11018. a = stack.pop();
  11019. stack.push(a % b);
  11020. break;
  11021. case 'mul':
  11022. b = stack.pop();
  11023. a = stack.pop();
  11024. stack.push(a * b);
  11025. break;
  11026. case 'ne':
  11027. b = stack.pop();
  11028. a = stack.pop();
  11029. stack.push(a !== b);
  11030. break;
  11031. case 'neg':
  11032. a = stack.pop();
  11033. stack.push(-a);
  11034. break;
  11035. case 'not':
  11036. a = stack.pop();
  11037. if (isBool(a)) {
  11038. stack.push(!a);
  11039. } else {
  11040. stack.push(~a);
  11041. }
  11042. break;
  11043. case 'or':
  11044. b = stack.pop();
  11045. a = stack.pop();
  11046. if (isBool(a) && isBool(b)) {
  11047. stack.push(a || b);
  11048. } else {
  11049. stack.push(a | b);
  11050. }
  11051. break;
  11052. case 'pop':
  11053. stack.pop();
  11054. break;
  11055. case 'roll':
  11056. b = stack.pop();
  11057. a = stack.pop();
  11058. stack.roll(a, b);
  11059. break;
  11060. case 'round':
  11061. a = stack.pop();
  11062. stack.push(Math.round(a));
  11063. break;
  11064. case 'sin':
  11065. a = stack.pop();
  11066. stack.push(Math.sin(a));
  11067. break;
  11068. case 'sqrt':
  11069. a = stack.pop();
  11070. stack.push(Math.sqrt(a));
  11071. break;
  11072. case 'sub':
  11073. b = stack.pop();
  11074. a = stack.pop();
  11075. stack.push(a - b);
  11076. break;
  11077. case 'true':
  11078. stack.push(true);
  11079. break;
  11080. case 'truncate':
  11081. a = stack.pop();
  11082. a = a < 0 ? Math.ceil(a) : Math.floor(a);
  11083. stack.push(a);
  11084. break;
  11085. case 'xor':
  11086. b = stack.pop();
  11087. a = stack.pop();
  11088. if (isBool(a) && isBool(b)) {
  11089. stack.push(a !== b);
  11090. } else {
  11091. stack.push(a ^ b);
  11092. }
  11093. break;
  11094. default:
  11095. error('Unknown operator ' + operator);
  11096. break;
  11097. }
  11098. }
  11099. return stack.stack;
  11100. }
  11101. };
  11102. return PostScriptEvaluator;
  11103. })();
  11104. // Most of the PDFs functions consist of simple operations such as:
  11105. // roll, exch, sub, cvr, pop, index, dup, mul, if, gt, add.
  11106. //
  11107. // We can compile most of such programs, and at the same moment, we can
  11108. // optimize some expressions using basic math properties. Keeping track of
  11109. // min/max values will allow us to avoid extra Math.min/Math.max calls.
  11110. var PostScriptCompiler = (function PostScriptCompilerClosure() {
  11111. function AstNode(type) {
  11112. this.type = type;
  11113. }
  11114. AstNode.prototype.visit = function (visitor) {
  11115. throw new Error('abstract method');
  11116. };
  11117. function AstArgument(index, min, max) {
  11118. AstNode.call(this, 'args');
  11119. this.index = index;
  11120. this.min = min;
  11121. this.max = max;
  11122. }
  11123. AstArgument.prototype = Object.create(AstNode.prototype);
  11124. AstArgument.prototype.visit = function (visitor) {
  11125. visitor.visitArgument(this);
  11126. };
  11127. function AstLiteral(number) {
  11128. AstNode.call(this, 'literal');
  11129. this.number = number;
  11130. this.min = number;
  11131. this.max = number;
  11132. }
  11133. AstLiteral.prototype = Object.create(AstNode.prototype);
  11134. AstLiteral.prototype.visit = function (visitor) {
  11135. visitor.visitLiteral(this);
  11136. };
  11137. function AstBinaryOperation(op, arg1, arg2, min, max) {
  11138. AstNode.call(this, 'binary');
  11139. this.op = op;
  11140. this.arg1 = arg1;
  11141. this.arg2 = arg2;
  11142. this.min = min;
  11143. this.max = max;
  11144. }
  11145. AstBinaryOperation.prototype = Object.create(AstNode.prototype);
  11146. AstBinaryOperation.prototype.visit = function (visitor) {
  11147. visitor.visitBinaryOperation(this);
  11148. };
  11149. function AstMin(arg, max) {
  11150. AstNode.call(this, 'max');
  11151. this.arg = arg;
  11152. this.min = arg.min;
  11153. this.max = max;
  11154. }
  11155. AstMin.prototype = Object.create(AstNode.prototype);
  11156. AstMin.prototype.visit = function (visitor) {
  11157. visitor.visitMin(this);
  11158. };
  11159. function AstVariable(index, min, max) {
  11160. AstNode.call(this, 'var');
  11161. this.index = index;
  11162. this.min = min;
  11163. this.max = max;
  11164. }
  11165. AstVariable.prototype = Object.create(AstNode.prototype);
  11166. AstVariable.prototype.visit = function (visitor) {
  11167. visitor.visitVariable(this);
  11168. };
  11169. function AstVariableDefinition(variable, arg) {
  11170. AstNode.call(this, 'definition');
  11171. this.variable = variable;
  11172. this.arg = arg;
  11173. }
  11174. AstVariableDefinition.prototype = Object.create(AstNode.prototype);
  11175. AstVariableDefinition.prototype.visit = function (visitor) {
  11176. visitor.visitVariableDefinition(this);
  11177. };
  11178. function ExpressionBuilderVisitor() {
  11179. this.parts = [];
  11180. }
  11181. ExpressionBuilderVisitor.prototype = {
  11182. visitArgument: function (arg) {
  11183. this.parts.push('Math.max(', arg.min, ', Math.min(',
  11184. arg.max, ', src[srcOffset + ', arg.index, ']))');
  11185. },
  11186. visitVariable: function (variable) {
  11187. this.parts.push('v', variable.index);
  11188. },
  11189. visitLiteral: function (literal) {
  11190. this.parts.push(literal.number);
  11191. },
  11192. visitBinaryOperation: function (operation) {
  11193. this.parts.push('(');
  11194. operation.arg1.visit(this);
  11195. this.parts.push(' ', operation.op, ' ');
  11196. operation.arg2.visit(this);
  11197. this.parts.push(')');
  11198. },
  11199. visitVariableDefinition: function (definition) {
  11200. this.parts.push('var ');
  11201. definition.variable.visit(this);
  11202. this.parts.push(' = ');
  11203. definition.arg.visit(this);
  11204. this.parts.push(';');
  11205. },
  11206. visitMin: function (max) {
  11207. this.parts.push('Math.min(');
  11208. max.arg.visit(this);
  11209. this.parts.push(', ', max.max, ')');
  11210. },
  11211. toString: function () {
  11212. return this.parts.join('');
  11213. }
  11214. };
  11215. function buildAddOperation(num1, num2) {
  11216. if (num2.type === 'literal' && num2.number === 0) {
  11217. // optimization: second operand is 0
  11218. return num1;
  11219. }
  11220. if (num1.type === 'literal' && num1.number === 0) {
  11221. // optimization: first operand is 0
  11222. return num2;
  11223. }
  11224. if (num2.type === 'literal' && num1.type === 'literal') {
  11225. // optimization: operands operand are literals
  11226. return new AstLiteral(num1.number + num2.number);
  11227. }
  11228. return new AstBinaryOperation('+', num1, num2,
  11229. num1.min + num2.min, num1.max + num2.max);
  11230. }
  11231. function buildMulOperation(num1, num2) {
  11232. if (num2.type === 'literal') {
  11233. // optimization: second operands is a literal...
  11234. if (num2.number === 0) {
  11235. return new AstLiteral(0); // and it's 0
  11236. } else if (num2.number === 1) {
  11237. return num1; // and it's 1
  11238. } else if (num1.type === 'literal') {
  11239. // ... and first operands is a literal too
  11240. return new AstLiteral(num1.number * num2.number);
  11241. }
  11242. }
  11243. if (num1.type === 'literal') {
  11244. // optimization: first operands is a literal...
  11245. if (num1.number === 0) {
  11246. return new AstLiteral(0); // and it's 0
  11247. } else if (num1.number === 1) {
  11248. return num2; // and it's 1
  11249. }
  11250. }
  11251. var min = Math.min(num1.min * num2.min, num1.min * num2.max,
  11252. num1.max * num2.min, num1.max * num2.max);
  11253. var max = Math.max(num1.min * num2.min, num1.min * num2.max,
  11254. num1.max * num2.min, num1.max * num2.max);
  11255. return new AstBinaryOperation('*', num1, num2, min, max);
  11256. }
  11257. function buildSubOperation(num1, num2) {
  11258. if (num2.type === 'literal') {
  11259. // optimization: second operands is a literal...
  11260. if (num2.number === 0) {
  11261. return num1; // ... and it's 0
  11262. } else if (num1.type === 'literal') {
  11263. // ... and first operands is a literal too
  11264. return new AstLiteral(num1.number - num2.number);
  11265. }
  11266. }
  11267. if (num2.type === 'binary' && num2.op === '-' &&
  11268. num1.type === 'literal' && num1.number === 1 &&
  11269. num2.arg1.type === 'literal' && num2.arg1.number === 1) {
  11270. // optimization for case: 1 - (1 - x)
  11271. return num2.arg2;
  11272. }
  11273. return new AstBinaryOperation('-', num1, num2,
  11274. num1.min - num2.max, num1.max - num2.min);
  11275. }
  11276. function buildMinOperation(num1, max) {
  11277. if (num1.min >= max) {
  11278. // optimization: num1 min value is not less than required max
  11279. return new AstLiteral(max); // just returning max
  11280. } else if (num1.max <= max) {
  11281. // optimization: num1 max value is not greater than required max
  11282. return num1; // just returning an argument
  11283. }
  11284. return new AstMin(num1, max);
  11285. }
  11286. function PostScriptCompiler() {}
  11287. PostScriptCompiler.prototype = {
  11288. compile: function PostScriptCompiler_compile(code, domain, range) {
  11289. var stack = [];
  11290. var i, ii;
  11291. var instructions = [];
  11292. var inputSize = domain.length >> 1, outputSize = range.length >> 1;
  11293. var lastRegister = 0;
  11294. var n, j, min, max;
  11295. var num1, num2, ast1, ast2, tmpVar, item;
  11296. for (i = 0; i < inputSize; i++) {
  11297. stack.push(new AstArgument(i, domain[i * 2], domain[i * 2 + 1]));
  11298. }
  11299. for (i = 0, ii = code.length; i < ii; i++) {
  11300. item = code[i];
  11301. if (typeof item === 'number') {
  11302. stack.push(new AstLiteral(item));
  11303. continue;
  11304. }
  11305. switch (item) {
  11306. case 'add':
  11307. if (stack.length < 2) {
  11308. return null;
  11309. }
  11310. num2 = stack.pop();
  11311. num1 = stack.pop();
  11312. stack.push(buildAddOperation(num1, num2));
  11313. break;
  11314. case 'cvr':
  11315. if (stack.length < 1) {
  11316. return null;
  11317. }
  11318. break;
  11319. case 'mul':
  11320. if (stack.length < 2) {
  11321. return null;
  11322. }
  11323. num2 = stack.pop();
  11324. num1 = stack.pop();
  11325. stack.push(buildMulOperation(num1, num2));
  11326. break;
  11327. case 'sub':
  11328. if (stack.length < 2) {
  11329. return null;
  11330. }
  11331. num2 = stack.pop();
  11332. num1 = stack.pop();
  11333. stack.push(buildSubOperation(num1, num2));
  11334. break;
  11335. case 'exch':
  11336. if (stack.length < 2) {
  11337. return null;
  11338. }
  11339. ast1 = stack.pop(); ast2 = stack.pop();
  11340. stack.push(ast1, ast2);
  11341. break;
  11342. case 'pop':
  11343. if (stack.length < 1) {
  11344. return null;
  11345. }
  11346. stack.pop();
  11347. break;
  11348. case 'index':
  11349. if (stack.length < 1) {
  11350. return null;
  11351. }
  11352. num1 = stack.pop();
  11353. if (num1.type !== 'literal') {
  11354. return null;
  11355. }
  11356. n = num1.number;
  11357. if (n < 0 || (n|0) !== n || stack.length < n) {
  11358. return null;
  11359. }
  11360. ast1 = stack[stack.length - n - 1];
  11361. if (ast1.type === 'literal' || ast1.type === 'var') {
  11362. stack.push(ast1);
  11363. break;
  11364. }
  11365. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  11366. stack[stack.length - n - 1] = tmpVar;
  11367. stack.push(tmpVar);
  11368. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  11369. break;
  11370. case 'dup':
  11371. if (stack.length < 1) {
  11372. return null;
  11373. }
  11374. if (typeof code[i + 1] === 'number' && code[i + 2] === 'gt' &&
  11375. code[i + 3] === i + 7 && code[i + 4] === 'jz' &&
  11376. code[i + 5] === 'pop' && code[i + 6] === code[i + 1]) {
  11377. // special case of the commands sequence for the min operation
  11378. num1 = stack.pop();
  11379. stack.push(buildMinOperation(num1, code[i + 1]));
  11380. i += 6;
  11381. break;
  11382. }
  11383. ast1 = stack[stack.length - 1];
  11384. if (ast1.type === 'literal' || ast1.type === 'var') {
  11385. // we don't have to save into intermediate variable a literal or
  11386. // variable.
  11387. stack.push(ast1);
  11388. break;
  11389. }
  11390. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  11391. stack[stack.length - 1] = tmpVar;
  11392. stack.push(tmpVar);
  11393. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  11394. break;
  11395. case 'roll':
  11396. if (stack.length < 2) {
  11397. return null;
  11398. }
  11399. num2 = stack.pop();
  11400. num1 = stack.pop();
  11401. if (num2.type !== 'literal' || num1.type !== 'literal') {
  11402. // both roll operands must be numbers
  11403. return null;
  11404. }
  11405. j = num2.number;
  11406. n = num1.number;
  11407. if (n <= 0 || (n|0) !== n || (j|0) !== j || stack.length < n) {
  11408. // ... and integers
  11409. return null;
  11410. }
  11411. j = ((j % n) + n) % n;
  11412. if (j === 0) {
  11413. break; // just skipping -- there are nothing to rotate
  11414. }
  11415. Array.prototype.push.apply(stack,
  11416. stack.splice(stack.length - n, n - j));
  11417. break;
  11418. default:
  11419. return null; // unsupported operator
  11420. }
  11421. }
  11422. if (stack.length !== outputSize) {
  11423. return null;
  11424. }
  11425. var result = [];
  11426. instructions.forEach(function (instruction) {
  11427. var statementBuilder = new ExpressionBuilderVisitor();
  11428. instruction.visit(statementBuilder);
  11429. result.push(statementBuilder.toString());
  11430. });
  11431. stack.forEach(function (expr, i) {
  11432. var statementBuilder = new ExpressionBuilderVisitor();
  11433. expr.visit(statementBuilder);
  11434. var min = range[i * 2], max = range[i * 2 + 1];
  11435. var out = [statementBuilder.toString()];
  11436. if (min > expr.min) {
  11437. out.unshift('Math.max(', min, ', ');
  11438. out.push(')');
  11439. }
  11440. if (max < expr.max) {
  11441. out.unshift('Math.min(', max, ', ');
  11442. out.push(')');
  11443. }
  11444. out.unshift('dest[destOffset + ', i, '] = ');
  11445. out.push(';');
  11446. result.push(out.join(''));
  11447. });
  11448. return result.join('\n');
  11449. }
  11450. };
  11451. return PostScriptCompiler;
  11452. })();
  11453. var ColorSpace = (function ColorSpaceClosure() {
  11454. // Constructor should define this.numComps, this.defaultColor, this.name
  11455. function ColorSpace() {
  11456. error('should not call ColorSpace constructor');
  11457. }
  11458. ColorSpace.prototype = {
  11459. /**
  11460. * Converts the color value to the RGB color. The color components are
  11461. * located in the src array starting from the srcOffset. Returns the array
  11462. * of the rgb components, each value ranging from [0,255].
  11463. */
  11464. getRgb: function ColorSpace_getRgb(src, srcOffset) {
  11465. var rgb = new Uint8Array(3);
  11466. this.getRgbItem(src, srcOffset, rgb, 0);
  11467. return rgb;
  11468. },
  11469. /**
  11470. * Converts the color value to the RGB color, similar to the getRgb method.
  11471. * The result placed into the dest array starting from the destOffset.
  11472. */
  11473. getRgbItem: function ColorSpace_getRgbItem(src, srcOffset,
  11474. dest, destOffset) {
  11475. error('Should not call ColorSpace.getRgbItem');
  11476. },
  11477. /**
  11478. * Converts the specified number of the color values to the RGB colors.
  11479. * The colors are located in the src array starting from the srcOffset.
  11480. * The result is placed into the dest array starting from the destOffset.
  11481. * The src array items shall be in [0,2^bits) range, the dest array items
  11482. * will be in [0,255] range. alpha01 indicates how many alpha components
  11483. * there are in the dest array; it will be either 0 (RGB array) or 1 (RGBA
  11484. * array).
  11485. */
  11486. getRgbBuffer: function ColorSpace_getRgbBuffer(src, srcOffset, count,
  11487. dest, destOffset, bits,
  11488. alpha01) {
  11489. error('Should not call ColorSpace.getRgbBuffer');
  11490. },
  11491. /**
  11492. * Determines the number of bytes required to store the result of the
  11493. * conversion done by the getRgbBuffer method. As in getRgbBuffer,
  11494. * |alpha01| is either 0 (RGB output) or 1 (RGBA output).
  11495. */
  11496. getOutputLength: function ColorSpace_getOutputLength(inputLength,
  11497. alpha01) {
  11498. error('Should not call ColorSpace.getOutputLength');
  11499. },
  11500. /**
  11501. * Returns true if source data will be equal the result/output data.
  11502. */
  11503. isPassthrough: function ColorSpace_isPassthrough(bits) {
  11504. return false;
  11505. },
  11506. /**
  11507. * Fills in the RGB colors in the destination buffer. alpha01 indicates
  11508. * how many alpha components there are in the dest array; it will be either
  11509. * 0 (RGB array) or 1 (RGBA array).
  11510. */
  11511. fillRgb: function ColorSpace_fillRgb(dest, originalWidth,
  11512. originalHeight, width, height,
  11513. actualHeight, bpc, comps, alpha01) {
  11514. var count = originalWidth * originalHeight;
  11515. var rgbBuf = null;
  11516. var numComponentColors = 1 << bpc;
  11517. var needsResizing = originalHeight !== height || originalWidth !== width;
  11518. var i, ii;
  11519. if (this.isPassthrough(bpc)) {
  11520. rgbBuf = comps;
  11521. } else if (this.numComps === 1 && count > numComponentColors &&
  11522. this.name !== 'DeviceGray' && this.name !== 'DeviceRGB') {
  11523. // Optimization: create a color map when there is just one component and
  11524. // we are converting more colors than the size of the color map. We
  11525. // don't build the map if the colorspace is gray or rgb since those
  11526. // methods are faster than building a map. This mainly offers big speed
  11527. // ups for indexed and alternate colorspaces.
  11528. //
  11529. // TODO it may be worth while to cache the color map. While running
  11530. // testing I never hit a cache so I will leave that out for now (perhaps
  11531. // we are reparsing colorspaces too much?).
  11532. var allColors = bpc <= 8 ? new Uint8Array(numComponentColors) :
  11533. new Uint16Array(numComponentColors);
  11534. var key;
  11535. for (i = 0; i < numComponentColors; i++) {
  11536. allColors[i] = i;
  11537. }
  11538. var colorMap = new Uint8Array(numComponentColors * 3);
  11539. this.getRgbBuffer(allColors, 0, numComponentColors, colorMap, 0, bpc,
  11540. /* alpha01 = */ 0);
  11541. var destPos, rgbPos;
  11542. if (!needsResizing) {
  11543. // Fill in the RGB values directly into |dest|.
  11544. destPos = 0;
  11545. for (i = 0; i < count; ++i) {
  11546. key = comps[i] * 3;
  11547. dest[destPos++] = colorMap[key];
  11548. dest[destPos++] = colorMap[key + 1];
  11549. dest[destPos++] = colorMap[key + 2];
  11550. destPos += alpha01;
  11551. }
  11552. } else {
  11553. rgbBuf = new Uint8Array(count * 3);
  11554. rgbPos = 0;
  11555. for (i = 0; i < count; ++i) {
  11556. key = comps[i] * 3;
  11557. rgbBuf[rgbPos++] = colorMap[key];
  11558. rgbBuf[rgbPos++] = colorMap[key + 1];
  11559. rgbBuf[rgbPos++] = colorMap[key + 2];
  11560. }
  11561. }
  11562. } else {
  11563. if (!needsResizing) {
  11564. // Fill in the RGB values directly into |dest|.
  11565. this.getRgbBuffer(comps, 0, width * actualHeight, dest, 0, bpc,
  11566. alpha01);
  11567. } else {
  11568. rgbBuf = new Uint8Array(count * 3);
  11569. this.getRgbBuffer(comps, 0, count, rgbBuf, 0, bpc,
  11570. /* alpha01 = */ 0);
  11571. }
  11572. }
  11573. if (rgbBuf) {
  11574. if (needsResizing) {
  11575. PDFImage.resize(rgbBuf, bpc, 3, originalWidth, originalHeight, width,
  11576. height, dest, alpha01);
  11577. } else {
  11578. rgbPos = 0;
  11579. destPos = 0;
  11580. for (i = 0, ii = width * actualHeight; i < ii; i++) {
  11581. dest[destPos++] = rgbBuf[rgbPos++];
  11582. dest[destPos++] = rgbBuf[rgbPos++];
  11583. dest[destPos++] = rgbBuf[rgbPos++];
  11584. destPos += alpha01;
  11585. }
  11586. }
  11587. }
  11588. },
  11589. /**
  11590. * True if the colorspace has components in the default range of [0, 1].
  11591. * This should be true for all colorspaces except for lab color spaces
  11592. * which are [0,100], [-128, 127], [-128, 127].
  11593. */
  11594. usesZeroToOneRange: true
  11595. };
  11596. ColorSpace.parse = function ColorSpace_parse(cs, xref, res) {
  11597. var IR = ColorSpace.parseToIR(cs, xref, res);
  11598. if (IR instanceof AlternateCS) {
  11599. return IR;
  11600. }
  11601. return ColorSpace.fromIR(IR);
  11602. };
  11603. ColorSpace.fromIR = function ColorSpace_fromIR(IR) {
  11604. var name = isArray(IR) ? IR[0] : IR;
  11605. var whitePoint, blackPoint, gamma;
  11606. switch (name) {
  11607. case 'DeviceGrayCS':
  11608. return this.singletons.gray;
  11609. case 'DeviceRgbCS':
  11610. return this.singletons.rgb;
  11611. case 'DeviceCmykCS':
  11612. return this.singletons.cmyk;
  11613. case 'CalGrayCS':
  11614. whitePoint = IR[1].WhitePoint;
  11615. blackPoint = IR[1].BlackPoint;
  11616. gamma = IR[1].Gamma;
  11617. return new CalGrayCS(whitePoint, blackPoint, gamma);
  11618. case 'CalRGBCS':
  11619. whitePoint = IR[1].WhitePoint;
  11620. blackPoint = IR[1].BlackPoint;
  11621. gamma = IR[1].Gamma;
  11622. var matrix = IR[1].Matrix;
  11623. return new CalRGBCS(whitePoint, blackPoint, gamma, matrix);
  11624. case 'PatternCS':
  11625. var basePatternCS = IR[1];
  11626. if (basePatternCS) {
  11627. basePatternCS = ColorSpace.fromIR(basePatternCS);
  11628. }
  11629. return new PatternCS(basePatternCS);
  11630. case 'IndexedCS':
  11631. var baseIndexedCS = IR[1];
  11632. var hiVal = IR[2];
  11633. var lookup = IR[3];
  11634. return new IndexedCS(ColorSpace.fromIR(baseIndexedCS), hiVal, lookup);
  11635. case 'AlternateCS':
  11636. var numComps = IR[1];
  11637. var alt = IR[2];
  11638. var tintFnIR = IR[3];
  11639. return new AlternateCS(numComps, ColorSpace.fromIR(alt),
  11640. PDFFunction.fromIR(tintFnIR));
  11641. case 'LabCS':
  11642. whitePoint = IR[1].WhitePoint;
  11643. blackPoint = IR[1].BlackPoint;
  11644. var range = IR[1].Range;
  11645. return new LabCS(whitePoint, blackPoint, range);
  11646. default:
  11647. error('Unknown name ' + name);
  11648. }
  11649. return null;
  11650. };
  11651. ColorSpace.parseToIR = function ColorSpace_parseToIR(cs, xref, res) {
  11652. if (isName(cs)) {
  11653. var colorSpaces = res.get('ColorSpace');
  11654. if (isDict(colorSpaces)) {
  11655. var refcs = colorSpaces.get(cs.name);
  11656. if (refcs) {
  11657. cs = refcs;
  11658. }
  11659. }
  11660. }
  11661. cs = xref.fetchIfRef(cs);
  11662. var mode;
  11663. if (isName(cs)) {
  11664. mode = cs.name;
  11665. this.mode = mode;
  11666. switch (mode) {
  11667. case 'DeviceGray':
  11668. case 'G':
  11669. return 'DeviceGrayCS';
  11670. case 'DeviceRGB':
  11671. case 'RGB':
  11672. return 'DeviceRgbCS';
  11673. case 'DeviceCMYK':
  11674. case 'CMYK':
  11675. return 'DeviceCmykCS';
  11676. case 'Pattern':
  11677. return ['PatternCS', null];
  11678. default:
  11679. error('unrecognized colorspace ' + mode);
  11680. }
  11681. } else if (isArray(cs)) {
  11682. mode = cs[0].name;
  11683. this.mode = mode;
  11684. var numComps, params;
  11685. switch (mode) {
  11686. case 'DeviceGray':
  11687. case 'G':
  11688. return 'DeviceGrayCS';
  11689. case 'DeviceRGB':
  11690. case 'RGB':
  11691. return 'DeviceRgbCS';
  11692. case 'DeviceCMYK':
  11693. case 'CMYK':
  11694. return 'DeviceCmykCS';
  11695. case 'CalGray':
  11696. params = xref.fetchIfRef(cs[1]).getAll();
  11697. return ['CalGrayCS', params];
  11698. case 'CalRGB':
  11699. params = xref.fetchIfRef(cs[1]).getAll();
  11700. return ['CalRGBCS', params];
  11701. case 'ICCBased':
  11702. var stream = xref.fetchIfRef(cs[1]);
  11703. var dict = stream.dict;
  11704. numComps = dict.get('N');
  11705. if (numComps === 1) {
  11706. return 'DeviceGrayCS';
  11707. } else if (numComps === 3) {
  11708. return 'DeviceRgbCS';
  11709. } else if (numComps === 4) {
  11710. return 'DeviceCmykCS';
  11711. }
  11712. break;
  11713. case 'Pattern':
  11714. var basePatternCS = cs[1];
  11715. if (basePatternCS) {
  11716. basePatternCS = ColorSpace.parseToIR(basePatternCS, xref, res);
  11717. }
  11718. return ['PatternCS', basePatternCS];
  11719. case 'Indexed':
  11720. case 'I':
  11721. var baseIndexedCS = ColorSpace.parseToIR(cs[1], xref, res);
  11722. var hiVal = cs[2] + 1;
  11723. var lookup = xref.fetchIfRef(cs[3]);
  11724. if (isStream(lookup)) {
  11725. lookup = lookup.getBytes();
  11726. }
  11727. return ['IndexedCS', baseIndexedCS, hiVal, lookup];
  11728. case 'Separation':
  11729. case 'DeviceN':
  11730. var name = cs[1];
  11731. numComps = 1;
  11732. if (isName(name)) {
  11733. numComps = 1;
  11734. } else if (isArray(name)) {
  11735. numComps = name.length;
  11736. }
  11737. var alt = ColorSpace.parseToIR(cs[2], xref, res);
  11738. var tintFnIR = PDFFunction.getIR(xref, xref.fetchIfRef(cs[3]));
  11739. return ['AlternateCS', numComps, alt, tintFnIR];
  11740. case 'Lab':
  11741. params = cs[1].getAll();
  11742. return ['LabCS', params];
  11743. default:
  11744. error('unimplemented color space object "' + mode + '"');
  11745. }
  11746. } else {
  11747. error('unrecognized color space object: "' + cs + '"');
  11748. }
  11749. return null;
  11750. };
  11751. /**
  11752. * Checks if a decode map matches the default decode map for a color space.
  11753. * This handles the general decode maps where there are two values per
  11754. * component. e.g. [0, 1, 0, 1, 0, 1] for a RGB color.
  11755. * This does not handle Lab, Indexed, or Pattern decode maps since they are
  11756. * slightly different.
  11757. * @param {Array} decode Decode map (usually from an image).
  11758. * @param {Number} n Number of components the color space has.
  11759. */
  11760. ColorSpace.isDefaultDecode = function ColorSpace_isDefaultDecode(decode, n) {
  11761. if (!decode) {
  11762. return true;
  11763. }
  11764. if (n * 2 !== decode.length) {
  11765. warn('The decode map is not the correct length');
  11766. return true;
  11767. }
  11768. for (var i = 0, ii = decode.length; i < ii; i += 2) {
  11769. if (decode[i] !== 0 || decode[i + 1] !== 1) {
  11770. return false;
  11771. }
  11772. }
  11773. return true;
  11774. };
  11775. ColorSpace.singletons = {
  11776. get gray() {
  11777. return shadow(this, 'gray', new DeviceGrayCS());
  11778. },
  11779. get rgb() {
  11780. return shadow(this, 'rgb', new DeviceRgbCS());
  11781. },
  11782. get cmyk() {
  11783. return shadow(this, 'cmyk', new DeviceCmykCS());
  11784. }
  11785. };
  11786. return ColorSpace;
  11787. })();
  11788. /**
  11789. * Alternate color space handles both Separation and DeviceN color spaces. A
  11790. * Separation color space is actually just a DeviceN with one color component.
  11791. * Both color spaces use a tinting function to convert colors to a base color
  11792. * space.
  11793. */
  11794. var AlternateCS = (function AlternateCSClosure() {
  11795. function AlternateCS(numComps, base, tintFn) {
  11796. this.name = 'Alternate';
  11797. this.numComps = numComps;
  11798. this.defaultColor = new Float32Array(numComps);
  11799. for (var i = 0; i < numComps; ++i) {
  11800. this.defaultColor[i] = 1;
  11801. }
  11802. this.base = base;
  11803. this.tintFn = tintFn;
  11804. this.tmpBuf = new Float32Array(base.numComps);
  11805. }
  11806. AlternateCS.prototype = {
  11807. getRgb: ColorSpace.prototype.getRgb,
  11808. getRgbItem: function AlternateCS_getRgbItem(src, srcOffset,
  11809. dest, destOffset) {
  11810. var tmpBuf = this.tmpBuf;
  11811. this.tintFn(src, srcOffset, tmpBuf, 0);
  11812. this.base.getRgbItem(tmpBuf, 0, dest, destOffset);
  11813. },
  11814. getRgbBuffer: function AlternateCS_getRgbBuffer(src, srcOffset, count,
  11815. dest, destOffset, bits,
  11816. alpha01) {
  11817. var tintFn = this.tintFn;
  11818. var base = this.base;
  11819. var scale = 1 / ((1 << bits) - 1);
  11820. var baseNumComps = base.numComps;
  11821. var usesZeroToOneRange = base.usesZeroToOneRange;
  11822. var isPassthrough = (base.isPassthrough(8) || !usesZeroToOneRange) &&
  11823. alpha01 === 0;
  11824. var pos = isPassthrough ? destOffset : 0;
  11825. var baseBuf = isPassthrough ? dest : new Uint8Array(baseNumComps * count);
  11826. var numComps = this.numComps;
  11827. var scaled = new Float32Array(numComps);
  11828. var tinted = new Float32Array(baseNumComps);
  11829. var i, j;
  11830. if (usesZeroToOneRange) {
  11831. for (i = 0; i < count; i++) {
  11832. for (j = 0; j < numComps; j++) {
  11833. scaled[j] = src[srcOffset++] * scale;
  11834. }
  11835. tintFn(scaled, 0, tinted, 0);
  11836. for (j = 0; j < baseNumComps; j++) {
  11837. baseBuf[pos++] = tinted[j] * 255;
  11838. }
  11839. }
  11840. } else {
  11841. for (i = 0; i < count; i++) {
  11842. for (j = 0; j < numComps; j++) {
  11843. scaled[j] = src[srcOffset++] * scale;
  11844. }
  11845. tintFn(scaled, 0, tinted, 0);
  11846. base.getRgbItem(tinted, 0, baseBuf, pos);
  11847. pos += baseNumComps;
  11848. }
  11849. }
  11850. if (!isPassthrough) {
  11851. base.getRgbBuffer(baseBuf, 0, count, dest, destOffset, 8, alpha01);
  11852. }
  11853. },
  11854. getOutputLength: function AlternateCS_getOutputLength(inputLength,
  11855. alpha01) {
  11856. return this.base.getOutputLength(inputLength *
  11857. this.base.numComps / this.numComps,
  11858. alpha01);
  11859. },
  11860. isPassthrough: ColorSpace.prototype.isPassthrough,
  11861. fillRgb: ColorSpace.prototype.fillRgb,
  11862. isDefaultDecode: function AlternateCS_isDefaultDecode(decodeMap) {
  11863. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  11864. },
  11865. usesZeroToOneRange: true
  11866. };
  11867. return AlternateCS;
  11868. })();
  11869. var PatternCS = (function PatternCSClosure() {
  11870. function PatternCS(baseCS) {
  11871. this.name = 'Pattern';
  11872. this.base = baseCS;
  11873. }
  11874. PatternCS.prototype = {};
  11875. return PatternCS;
  11876. })();
  11877. var IndexedCS = (function IndexedCSClosure() {
  11878. function IndexedCS(base, highVal, lookup) {
  11879. this.name = 'Indexed';
  11880. this.numComps = 1;
  11881. this.defaultColor = new Uint8Array([0]);
  11882. this.base = base;
  11883. this.highVal = highVal;
  11884. var baseNumComps = base.numComps;
  11885. var length = baseNumComps * highVal;
  11886. var lookupArray;
  11887. if (isStream(lookup)) {
  11888. lookupArray = new Uint8Array(length);
  11889. var bytes = lookup.getBytes(length);
  11890. lookupArray.set(bytes);
  11891. } else if (isString(lookup)) {
  11892. lookupArray = new Uint8Array(length);
  11893. for (var i = 0; i < length; ++i) {
  11894. lookupArray[i] = lookup.charCodeAt(i);
  11895. }
  11896. } else if (lookup instanceof Uint8Array || lookup instanceof Array) {
  11897. lookupArray = lookup;
  11898. } else {
  11899. error('Unrecognized lookup table: ' + lookup);
  11900. }
  11901. this.lookup = lookupArray;
  11902. }
  11903. IndexedCS.prototype = {
  11904. getRgb: ColorSpace.prototype.getRgb,
  11905. getRgbItem: function IndexedCS_getRgbItem(src, srcOffset,
  11906. dest, destOffset) {
  11907. var numComps = this.base.numComps;
  11908. var start = src[srcOffset] * numComps;
  11909. this.base.getRgbItem(this.lookup, start, dest, destOffset);
  11910. },
  11911. getRgbBuffer: function IndexedCS_getRgbBuffer(src, srcOffset, count,
  11912. dest, destOffset, bits,
  11913. alpha01) {
  11914. var base = this.base;
  11915. var numComps = base.numComps;
  11916. var outputDelta = base.getOutputLength(numComps, alpha01);
  11917. var lookup = this.lookup;
  11918. for (var i = 0; i < count; ++i) {
  11919. var lookupPos = src[srcOffset++] * numComps;
  11920. base.getRgbBuffer(lookup, lookupPos, 1, dest, destOffset, 8, alpha01);
  11921. destOffset += outputDelta;
  11922. }
  11923. },
  11924. getOutputLength: function IndexedCS_getOutputLength(inputLength, alpha01) {
  11925. return this.base.getOutputLength(inputLength * this.base.numComps,
  11926. alpha01);
  11927. },
  11928. isPassthrough: ColorSpace.prototype.isPassthrough,
  11929. fillRgb: ColorSpace.prototype.fillRgb,
  11930. isDefaultDecode: function IndexedCS_isDefaultDecode(decodeMap) {
  11931. // indexed color maps shouldn't be changed
  11932. return true;
  11933. },
  11934. usesZeroToOneRange: true
  11935. };
  11936. return IndexedCS;
  11937. })();
  11938. var DeviceGrayCS = (function DeviceGrayCSClosure() {
  11939. function DeviceGrayCS() {
  11940. this.name = 'DeviceGray';
  11941. this.numComps = 1;
  11942. this.defaultColor = new Float32Array([0]);
  11943. }
  11944. DeviceGrayCS.prototype = {
  11945. getRgb: ColorSpace.prototype.getRgb,
  11946. getRgbItem: function DeviceGrayCS_getRgbItem(src, srcOffset,
  11947. dest, destOffset) {
  11948. var c = (src[srcOffset] * 255) | 0;
  11949. c = c < 0 ? 0 : c > 255 ? 255 : c;
  11950. dest[destOffset] = dest[destOffset + 1] = dest[destOffset + 2] = c;
  11951. },
  11952. getRgbBuffer: function DeviceGrayCS_getRgbBuffer(src, srcOffset, count,
  11953. dest, destOffset, bits,
  11954. alpha01) {
  11955. var scale = 255 / ((1 << bits) - 1);
  11956. var j = srcOffset, q = destOffset;
  11957. for (var i = 0; i < count; ++i) {
  11958. var c = (scale * src[j++]) | 0;
  11959. dest[q++] = c;
  11960. dest[q++] = c;
  11961. dest[q++] = c;
  11962. q += alpha01;
  11963. }
  11964. },
  11965. getOutputLength: function DeviceGrayCS_getOutputLength(inputLength,
  11966. alpha01) {
  11967. return inputLength * (3 + alpha01);
  11968. },
  11969. isPassthrough: ColorSpace.prototype.isPassthrough,
  11970. fillRgb: ColorSpace.prototype.fillRgb,
  11971. isDefaultDecode: function DeviceGrayCS_isDefaultDecode(decodeMap) {
  11972. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  11973. },
  11974. usesZeroToOneRange: true
  11975. };
  11976. return DeviceGrayCS;
  11977. })();
  11978. var DeviceRgbCS = (function DeviceRgbCSClosure() {
  11979. function DeviceRgbCS() {
  11980. this.name = 'DeviceRGB';
  11981. this.numComps = 3;
  11982. this.defaultColor = new Float32Array([0, 0, 0]);
  11983. }
  11984. DeviceRgbCS.prototype = {
  11985. getRgb: ColorSpace.prototype.getRgb,
  11986. getRgbItem: function DeviceRgbCS_getRgbItem(src, srcOffset,
  11987. dest, destOffset) {
  11988. var r = (src[srcOffset] * 255) | 0;
  11989. var g = (src[srcOffset + 1] * 255) | 0;
  11990. var b = (src[srcOffset + 2] * 255) | 0;
  11991. dest[destOffset] = r < 0 ? 0 : r > 255 ? 255 : r;
  11992. dest[destOffset + 1] = g < 0 ? 0 : g > 255 ? 255 : g;
  11993. dest[destOffset + 2] = b < 0 ? 0 : b > 255 ? 255 : b;
  11994. },
  11995. getRgbBuffer: function DeviceRgbCS_getRgbBuffer(src, srcOffset, count,
  11996. dest, destOffset, bits,
  11997. alpha01) {
  11998. if (bits === 8 && alpha01 === 0) {
  11999. dest.set(src.subarray(srcOffset, srcOffset + count * 3), destOffset);
  12000. return;
  12001. }
  12002. var scale = 255 / ((1 << bits) - 1);
  12003. var j = srcOffset, q = destOffset;
  12004. for (var i = 0; i < count; ++i) {
  12005. dest[q++] = (scale * src[j++]) | 0;
  12006. dest[q++] = (scale * src[j++]) | 0;
  12007. dest[q++] = (scale * src[j++]) | 0;
  12008. q += alpha01;
  12009. }
  12010. },
  12011. getOutputLength: function DeviceRgbCS_getOutputLength(inputLength,
  12012. alpha01) {
  12013. return (inputLength * (3 + alpha01) / 3) | 0;
  12014. },
  12015. isPassthrough: function DeviceRgbCS_isPassthrough(bits) {
  12016. return bits === 8;
  12017. },
  12018. fillRgb: ColorSpace.prototype.fillRgb,
  12019. isDefaultDecode: function DeviceRgbCS_isDefaultDecode(decodeMap) {
  12020. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  12021. },
  12022. usesZeroToOneRange: true
  12023. };
  12024. return DeviceRgbCS;
  12025. })();
  12026. var DeviceCmykCS = (function DeviceCmykCSClosure() {
  12027. // The coefficients below was found using numerical analysis: the method of
  12028. // steepest descent for the sum((f_i - color_value_i)^2) for r/g/b colors,
  12029. // where color_value is the tabular value from the table of sampled RGB colors
  12030. // from CMYK US Web Coated (SWOP) colorspace, and f_i is the corresponding
  12031. // CMYK color conversion using the estimation below:
  12032. // f(A, B,.. N) = Acc+Bcm+Ccy+Dck+c+Fmm+Gmy+Hmk+Im+Jyy+Kyk+Ly+Mkk+Nk+255
  12033. function convertToRgb(src, srcOffset, srcScale, dest, destOffset) {
  12034. var c = src[srcOffset + 0] * srcScale;
  12035. var m = src[srcOffset + 1] * srcScale;
  12036. var y = src[srcOffset + 2] * srcScale;
  12037. var k = src[srcOffset + 3] * srcScale;
  12038. var r =
  12039. (c * (-4.387332384609988 * c + 54.48615194189176 * m +
  12040. 18.82290502165302 * y + 212.25662451639585 * k +
  12041. -285.2331026137004) +
  12042. m * (1.7149763477362134 * m - 5.6096736904047315 * y +
  12043. -17.873870861415444 * k - 5.497006427196366) +
  12044. y * (-2.5217340131683033 * y - 21.248923337353073 * k +
  12045. 17.5119270841813) +
  12046. k * (-21.86122147463605 * k - 189.48180835922747) + 255) | 0;
  12047. var g =
  12048. (c * (8.841041422036149 * c + 60.118027045597366 * m +
  12049. 6.871425592049007 * y + 31.159100130055922 * k +
  12050. -79.2970844816548) +
  12051. m * (-15.310361306967817 * m + 17.575251261109482 * y +
  12052. 131.35250912493976 * k - 190.9453302588951) +
  12053. y * (4.444339102852739 * y + 9.8632861493405 * k - 24.86741582555878) +
  12054. k * (-20.737325471181034 * k - 187.80453709719578) + 255) | 0;
  12055. var b =
  12056. (c * (0.8842522430003296 * c + 8.078677503112928 * m +
  12057. 30.89978309703729 * y - 0.23883238689178934 * k +
  12058. -14.183576799673286) +
  12059. m * (10.49593273432072 * m + 63.02378494754052 * y +
  12060. 50.606957656360734 * k - 112.23884253719248) +
  12061. y * (0.03296041114873217 * y + 115.60384449646641 * k +
  12062. -193.58209356861505) +
  12063. k * (-22.33816807309886 * k - 180.12613974708367) + 255) | 0;
  12064. dest[destOffset] = r > 255 ? 255 : r < 0 ? 0 : r;
  12065. dest[destOffset + 1] = g > 255 ? 255 : g < 0 ? 0 : g;
  12066. dest[destOffset + 2] = b > 255 ? 255 : b < 0 ? 0 : b;
  12067. }
  12068. function DeviceCmykCS() {
  12069. this.name = 'DeviceCMYK';
  12070. this.numComps = 4;
  12071. this.defaultColor = new Float32Array([0, 0, 0, 1]);
  12072. }
  12073. DeviceCmykCS.prototype = {
  12074. getRgb: ColorSpace.prototype.getRgb,
  12075. getRgbItem: function DeviceCmykCS_getRgbItem(src, srcOffset,
  12076. dest, destOffset) {
  12077. convertToRgb(src, srcOffset, 1, dest, destOffset);
  12078. },
  12079. getRgbBuffer: function DeviceCmykCS_getRgbBuffer(src, srcOffset, count,
  12080. dest, destOffset, bits,
  12081. alpha01) {
  12082. var scale = 1 / ((1 << bits) - 1);
  12083. for (var i = 0; i < count; i++) {
  12084. convertToRgb(src, srcOffset, scale, dest, destOffset);
  12085. srcOffset += 4;
  12086. destOffset += 3 + alpha01;
  12087. }
  12088. },
  12089. getOutputLength: function DeviceCmykCS_getOutputLength(inputLength,
  12090. alpha01) {
  12091. return (inputLength / 4 * (3 + alpha01)) | 0;
  12092. },
  12093. isPassthrough: ColorSpace.prototype.isPassthrough,
  12094. fillRgb: ColorSpace.prototype.fillRgb,
  12095. isDefaultDecode: function DeviceCmykCS_isDefaultDecode(decodeMap) {
  12096. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  12097. },
  12098. usesZeroToOneRange: true
  12099. };
  12100. return DeviceCmykCS;
  12101. })();
  12102. //
  12103. // CalGrayCS: Based on "PDF Reference, Sixth Ed", p.245
  12104. //
  12105. var CalGrayCS = (function CalGrayCSClosure() {
  12106. function CalGrayCS(whitePoint, blackPoint, gamma) {
  12107. this.name = 'CalGray';
  12108. this.numComps = 1;
  12109. this.defaultColor = new Float32Array([0]);
  12110. if (!whitePoint) {
  12111. error('WhitePoint missing - required for color space CalGray');
  12112. }
  12113. blackPoint = blackPoint || [0, 0, 0];
  12114. gamma = gamma || 1;
  12115. // Translate arguments to spec variables.
  12116. this.XW = whitePoint[0];
  12117. this.YW = whitePoint[1];
  12118. this.ZW = whitePoint[2];
  12119. this.XB = blackPoint[0];
  12120. this.YB = blackPoint[1];
  12121. this.ZB = blackPoint[2];
  12122. this.G = gamma;
  12123. // Validate variables as per spec.
  12124. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  12125. error('Invalid WhitePoint components for ' + this.name +
  12126. ', no fallback available');
  12127. }
  12128. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  12129. info('Invalid BlackPoint for ' + this.name + ', falling back to default');
  12130. this.XB = this.YB = this.ZB = 0;
  12131. }
  12132. if (this.XB !== 0 || this.YB !== 0 || this.ZB !== 0) {
  12133. warn(this.name + ', BlackPoint: XB: ' + this.XB + ', YB: ' + this.YB +
  12134. ', ZB: ' + this.ZB + ', only default values are supported.');
  12135. }
  12136. if (this.G < 1) {
  12137. info('Invalid Gamma: ' + this.G + ' for ' + this.name +
  12138. ', falling back to default');
  12139. this.G = 1;
  12140. }
  12141. }
  12142. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  12143. // A represents a gray component of a calibrated gray space.
  12144. // A <---> AG in the spec
  12145. var A = src[srcOffset] * scale;
  12146. var AG = Math.pow(A, cs.G);
  12147. // Computes L as per spec. ( = cs.YW * AG )
  12148. // Except if other than default BlackPoint values are used.
  12149. var L = cs.YW * AG;
  12150. // http://www.poynton.com/notes/colour_and_gamma/ColorFAQ.html, Ch 4.
  12151. // Convert values to rgb range [0, 255].
  12152. var val = Math.max(295.8 * Math.pow(L, 0.333333333333333333) - 40.8, 0) | 0;
  12153. dest[destOffset] = val;
  12154. dest[destOffset + 1] = val;
  12155. dest[destOffset + 2] = val;
  12156. }
  12157. CalGrayCS.prototype = {
  12158. getRgb: ColorSpace.prototype.getRgb,
  12159. getRgbItem: function CalGrayCS_getRgbItem(src, srcOffset,
  12160. dest, destOffset) {
  12161. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  12162. },
  12163. getRgbBuffer: function CalGrayCS_getRgbBuffer(src, srcOffset, count,
  12164. dest, destOffset, bits,
  12165. alpha01) {
  12166. var scale = 1 / ((1 << bits) - 1);
  12167. for (var i = 0; i < count; ++i) {
  12168. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  12169. srcOffset += 1;
  12170. destOffset += 3 + alpha01;
  12171. }
  12172. },
  12173. getOutputLength: function CalGrayCS_getOutputLength(inputLength, alpha01) {
  12174. return inputLength * (3 + alpha01);
  12175. },
  12176. isPassthrough: ColorSpace.prototype.isPassthrough,
  12177. fillRgb: ColorSpace.prototype.fillRgb,
  12178. isDefaultDecode: function CalGrayCS_isDefaultDecode(decodeMap) {
  12179. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  12180. },
  12181. usesZeroToOneRange: true
  12182. };
  12183. return CalGrayCS;
  12184. })();
  12185. //
  12186. // CalRGBCS: Based on "PDF Reference, Sixth Ed", p.247
  12187. //
  12188. var CalRGBCS = (function CalRGBCSClosure() {
  12189. // See http://www.brucelindbloom.com/index.html?Eqn_ChromAdapt.html for these
  12190. // matrices.
  12191. var BRADFORD_SCALE_MATRIX = new Float32Array([
  12192. 0.8951, 0.2664, -0.1614,
  12193. -0.7502, 1.7135, 0.0367,
  12194. 0.0389, -0.0685, 1.0296]);
  12195. var BRADFORD_SCALE_INVERSE_MATRIX = new Float32Array([
  12196. 0.9869929, -0.1470543, 0.1599627,
  12197. 0.4323053, 0.5183603, 0.0492912,
  12198. -0.0085287, 0.0400428, 0.9684867]);
  12199. // See http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html.
  12200. var SRGB_D65_XYZ_TO_RGB_MATRIX = new Float32Array([
  12201. 3.2404542, -1.5371385, -0.4985314,
  12202. -0.9692660, 1.8760108, 0.0415560,
  12203. 0.0556434, -0.2040259, 1.0572252]);
  12204. var FLAT_WHITEPOINT_MATRIX = new Float32Array([1, 1, 1]);
  12205. var tempNormalizeMatrix = new Float32Array(3);
  12206. var tempConvertMatrix1 = new Float32Array(3);
  12207. var tempConvertMatrix2 = new Float32Array(3);
  12208. var DECODE_L_CONSTANT = Math.pow(((8 + 16) / 116), 3) / 8.0;
  12209. function CalRGBCS(whitePoint, blackPoint, gamma, matrix) {
  12210. this.name = 'CalRGB';
  12211. this.numComps = 3;
  12212. this.defaultColor = new Float32Array(3);
  12213. if (!whitePoint) {
  12214. error('WhitePoint missing - required for color space CalRGB');
  12215. }
  12216. blackPoint = blackPoint || new Float32Array(3);
  12217. gamma = gamma || new Float32Array([1, 1, 1]);
  12218. matrix = matrix || new Float32Array([1, 0, 0, 0, 1, 0, 0, 0, 1]);
  12219. // Translate arguments to spec variables.
  12220. var XW = whitePoint[0];
  12221. var YW = whitePoint[1];
  12222. var ZW = whitePoint[2];
  12223. this.whitePoint = whitePoint;
  12224. var XB = blackPoint[0];
  12225. var YB = blackPoint[1];
  12226. var ZB = blackPoint[2];
  12227. this.blackPoint = blackPoint;
  12228. this.GR = gamma[0];
  12229. this.GG = gamma[1];
  12230. this.GB = gamma[2];
  12231. this.MXA = matrix[0];
  12232. this.MYA = matrix[1];
  12233. this.MZA = matrix[2];
  12234. this.MXB = matrix[3];
  12235. this.MYB = matrix[4];
  12236. this.MZB = matrix[5];
  12237. this.MXC = matrix[6];
  12238. this.MYC = matrix[7];
  12239. this.MZC = matrix[8];
  12240. // Validate variables as per spec.
  12241. if (XW < 0 || ZW < 0 || YW !== 1) {
  12242. error('Invalid WhitePoint components for ' + this.name +
  12243. ', no fallback available');
  12244. }
  12245. if (XB < 0 || YB < 0 || ZB < 0) {
  12246. info('Invalid BlackPoint for ' + this.name + ' [' + XB + ', ' + YB +
  12247. ', ' + ZB + '], falling back to default');
  12248. this.blackPoint = new Float32Array(3);
  12249. }
  12250. if (this.GR < 0 || this.GG < 0 || this.GB < 0) {
  12251. info('Invalid Gamma [' + this.GR + ', ' + this.GG + ', ' + this.GB +
  12252. '] for ' + this.name + ', falling back to default');
  12253. this.GR = this.GG = this.GB = 1;
  12254. }
  12255. if (this.MXA < 0 || this.MYA < 0 || this.MZA < 0 ||
  12256. this.MXB < 0 || this.MYB < 0 || this.MZB < 0 ||
  12257. this.MXC < 0 || this.MYC < 0 || this.MZC < 0) {
  12258. info('Invalid Matrix for ' + this.name + ' [' +
  12259. this.MXA + ', ' + this.MYA + ', ' + this.MZA +
  12260. this.MXB + ', ' + this.MYB + ', ' + this.MZB +
  12261. this.MXC + ', ' + this.MYC + ', ' + this.MZC +
  12262. '], falling back to default');
  12263. this.MXA = this.MYB = this.MZC = 1;
  12264. this.MXB = this.MYA = this.MZA = this.MXC = this.MYC = this.MZB = 0;
  12265. }
  12266. }
  12267. function matrixProduct(a, b, result) {
  12268. result[0] = a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
  12269. result[1] = a[3] * b[0] + a[4] * b[1] + a[5] * b[2];
  12270. result[2] = a[6] * b[0] + a[7] * b[1] + a[8] * b[2];
  12271. }
  12272. function convertToFlat(sourceWhitePoint, LMS, result) {
  12273. result[0] = LMS[0] * 1 / sourceWhitePoint[0];
  12274. result[1] = LMS[1] * 1 / sourceWhitePoint[1];
  12275. result[2] = LMS[2] * 1 / sourceWhitePoint[2];
  12276. }
  12277. function convertToD65(sourceWhitePoint, LMS, result) {
  12278. var D65X = 0.95047;
  12279. var D65Y = 1;
  12280. var D65Z = 1.08883;
  12281. result[0] = LMS[0] * D65X / sourceWhitePoint[0];
  12282. result[1] = LMS[1] * D65Y / sourceWhitePoint[1];
  12283. result[2] = LMS[2] * D65Z / sourceWhitePoint[2];
  12284. }
  12285. function sRGBTransferFunction(color) {
  12286. // See http://en.wikipedia.org/wiki/SRGB.
  12287. if (color <= 0.0031308){
  12288. return adjustToRange(0, 1, 12.92 * color);
  12289. }
  12290. return adjustToRange(0, 1, (1 + 0.055) * Math.pow(color, 1 / 2.4) - 0.055);
  12291. }
  12292. function adjustToRange(min, max, value) {
  12293. return Math.max(min, Math.min(max, value));
  12294. }
  12295. function decodeL(L) {
  12296. if (L < 0) {
  12297. return -decodeL(-L);
  12298. }
  12299. if (L > 8.0) {
  12300. return Math.pow(((L + 16) / 116), 3);
  12301. }
  12302. return L * DECODE_L_CONSTANT;
  12303. }
  12304. function compensateBlackPoint(sourceBlackPoint, XYZ_Flat, result) {
  12305. // In case the blackPoint is already the default blackPoint then there is
  12306. // no need to do compensation.
  12307. if (sourceBlackPoint[0] === 0 &&
  12308. sourceBlackPoint[1] === 0 &&
  12309. sourceBlackPoint[2] === 0) {
  12310. result[0] = XYZ_Flat[0];
  12311. result[1] = XYZ_Flat[1];
  12312. result[2] = XYZ_Flat[2];
  12313. return;
  12314. }
  12315. // For the blackPoint calculation details, please see
  12316. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  12317. // AdobeBPC.pdf.
  12318. // The destination blackPoint is the default blackPoint [0, 0, 0].
  12319. var zeroDecodeL = decodeL(0);
  12320. var X_DST = zeroDecodeL;
  12321. var X_SRC = decodeL(sourceBlackPoint[0]);
  12322. var Y_DST = zeroDecodeL;
  12323. var Y_SRC = decodeL(sourceBlackPoint[1]);
  12324. var Z_DST = zeroDecodeL;
  12325. var Z_SRC = decodeL(sourceBlackPoint[2]);
  12326. var X_Scale = (1 - X_DST) / (1 - X_SRC);
  12327. var X_Offset = 1 - X_Scale;
  12328. var Y_Scale = (1 - Y_DST) / (1 - Y_SRC);
  12329. var Y_Offset = 1 - Y_Scale;
  12330. var Z_Scale = (1 - Z_DST) / (1 - Z_SRC);
  12331. var Z_Offset = 1 - Z_Scale;
  12332. result[0] = XYZ_Flat[0] * X_Scale + X_Offset;
  12333. result[1] = XYZ_Flat[1] * Y_Scale + Y_Offset;
  12334. result[2] = XYZ_Flat[2] * Z_Scale + Z_Offset;
  12335. }
  12336. function normalizeWhitePointToFlat(sourceWhitePoint, XYZ_In, result) {
  12337. // In case the whitePoint is already flat then there is no need to do
  12338. // normalization.
  12339. if (sourceWhitePoint[0] === 1 && sourceWhitePoint[2] === 1) {
  12340. result[0] = XYZ_In[0];
  12341. result[1] = XYZ_In[1];
  12342. result[2] = XYZ_In[2];
  12343. return;
  12344. }
  12345. var LMS = result;
  12346. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  12347. var LMS_Flat = tempNormalizeMatrix;
  12348. convertToFlat(sourceWhitePoint, LMS, LMS_Flat);
  12349. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_Flat, result);
  12350. }
  12351. function normalizeWhitePointToD65(sourceWhitePoint, XYZ_In, result) {
  12352. var LMS = result;
  12353. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  12354. var LMS_D65 = tempNormalizeMatrix;
  12355. convertToD65(sourceWhitePoint, LMS, LMS_D65);
  12356. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_D65, result);
  12357. }
  12358. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  12359. // A, B and C represent a red, green and blue components of a calibrated
  12360. // rgb space.
  12361. var A = adjustToRange(0, 1, src[srcOffset] * scale);
  12362. var B = adjustToRange(0, 1, src[srcOffset + 1] * scale);
  12363. var C = adjustToRange(0, 1, src[srcOffset + 2] * scale);
  12364. // A <---> AGR in the spec
  12365. // B <---> BGG in the spec
  12366. // C <---> CGB in the spec
  12367. var AGR = Math.pow(A, cs.GR);
  12368. var BGG = Math.pow(B, cs.GG);
  12369. var CGB = Math.pow(C, cs.GB);
  12370. // Computes intermediate variables L, M, N as per spec.
  12371. // To decode X, Y, Z values map L, M, N directly to them.
  12372. var X = cs.MXA * AGR + cs.MXB * BGG + cs.MXC * CGB;
  12373. var Y = cs.MYA * AGR + cs.MYB * BGG + cs.MYC * CGB;
  12374. var Z = cs.MZA * AGR + cs.MZB * BGG + cs.MZC * CGB;
  12375. // The following calculations are based on this document:
  12376. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  12377. // AdobeBPC.pdf.
  12378. var XYZ = tempConvertMatrix1;
  12379. XYZ[0] = X;
  12380. XYZ[1] = Y;
  12381. XYZ[2] = Z;
  12382. var XYZ_Flat = tempConvertMatrix2;
  12383. normalizeWhitePointToFlat(cs.whitePoint, XYZ, XYZ_Flat);
  12384. var XYZ_Black = tempConvertMatrix1;
  12385. compensateBlackPoint(cs.blackPoint, XYZ_Flat, XYZ_Black);
  12386. var XYZ_D65 = tempConvertMatrix2;
  12387. normalizeWhitePointToD65(FLAT_WHITEPOINT_MATRIX, XYZ_Black, XYZ_D65);
  12388. var SRGB = tempConvertMatrix1;
  12389. matrixProduct(SRGB_D65_XYZ_TO_RGB_MATRIX, XYZ_D65, SRGB);
  12390. var sR = sRGBTransferFunction(SRGB[0]);
  12391. var sG = sRGBTransferFunction(SRGB[1]);
  12392. var sB = sRGBTransferFunction(SRGB[2]);
  12393. // Convert the values to rgb range [0, 255].
  12394. dest[destOffset] = Math.round(sR * 255);
  12395. dest[destOffset + 1] = Math.round(sG * 255);
  12396. dest[destOffset + 2] = Math.round(sB * 255);
  12397. }
  12398. CalRGBCS.prototype = {
  12399. getRgb: function CalRGBCS_getRgb(src, srcOffset) {
  12400. var rgb = new Uint8Array(3);
  12401. this.getRgbItem(src, srcOffset, rgb, 0);
  12402. return rgb;
  12403. },
  12404. getRgbItem: function CalRGBCS_getRgbItem(src, srcOffset,
  12405. dest, destOffset) {
  12406. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  12407. },
  12408. getRgbBuffer: function CalRGBCS_getRgbBuffer(src, srcOffset, count,
  12409. dest, destOffset, bits,
  12410. alpha01) {
  12411. var scale = 1 / ((1 << bits) - 1);
  12412. for (var i = 0; i < count; ++i) {
  12413. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  12414. srcOffset += 3;
  12415. destOffset += 3 + alpha01;
  12416. }
  12417. },
  12418. getOutputLength: function CalRGBCS_getOutputLength(inputLength, alpha01) {
  12419. return (inputLength * (3 + alpha01) / 3) | 0;
  12420. },
  12421. isPassthrough: ColorSpace.prototype.isPassthrough,
  12422. fillRgb: ColorSpace.prototype.fillRgb,
  12423. isDefaultDecode: function CalRGBCS_isDefaultDecode(decodeMap) {
  12424. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  12425. },
  12426. usesZeroToOneRange: true
  12427. };
  12428. return CalRGBCS;
  12429. })();
  12430. //
  12431. // LabCS: Based on "PDF Reference, Sixth Ed", p.250
  12432. //
  12433. var LabCS = (function LabCSClosure() {
  12434. function LabCS(whitePoint, blackPoint, range) {
  12435. this.name = 'Lab';
  12436. this.numComps = 3;
  12437. this.defaultColor = new Float32Array([0, 0, 0]);
  12438. if (!whitePoint) {
  12439. error('WhitePoint missing - required for color space Lab');
  12440. }
  12441. blackPoint = blackPoint || [0, 0, 0];
  12442. range = range || [-100, 100, -100, 100];
  12443. // Translate args to spec variables
  12444. this.XW = whitePoint[0];
  12445. this.YW = whitePoint[1];
  12446. this.ZW = whitePoint[2];
  12447. this.amin = range[0];
  12448. this.amax = range[1];
  12449. this.bmin = range[2];
  12450. this.bmax = range[3];
  12451. // These are here just for completeness - the spec doesn't offer any
  12452. // formulas that use BlackPoint in Lab
  12453. this.XB = blackPoint[0];
  12454. this.YB = blackPoint[1];
  12455. this.ZB = blackPoint[2];
  12456. // Validate vars as per spec
  12457. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  12458. error('Invalid WhitePoint components, no fallback available');
  12459. }
  12460. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  12461. info('Invalid BlackPoint, falling back to default');
  12462. this.XB = this.YB = this.ZB = 0;
  12463. }
  12464. if (this.amin > this.amax || this.bmin > this.bmax) {
  12465. info('Invalid Range, falling back to defaults');
  12466. this.amin = -100;
  12467. this.amax = 100;
  12468. this.bmin = -100;
  12469. this.bmax = 100;
  12470. }
  12471. }
  12472. // Function g(x) from spec
  12473. function fn_g(x) {
  12474. if (x >= 6 / 29) {
  12475. return x * x * x;
  12476. } else {
  12477. return (108 / 841) * (x - 4 / 29);
  12478. }
  12479. }
  12480. function decode(value, high1, low2, high2) {
  12481. return low2 + (value) * (high2 - low2) / (high1);
  12482. }
  12483. // If decoding is needed maxVal should be 2^bits per component - 1.
  12484. function convertToRgb(cs, src, srcOffset, maxVal, dest, destOffset) {
  12485. // XXX: Lab input is in the range of [0, 100], [amin, amax], [bmin, bmax]
  12486. // not the usual [0, 1]. If a command like setFillColor is used the src
  12487. // values will already be within the correct range. However, if we are
  12488. // converting an image we have to map the values to the correct range given
  12489. // above.
  12490. // Ls,as,bs <---> L*,a*,b* in the spec
  12491. var Ls = src[srcOffset];
  12492. var as = src[srcOffset + 1];
  12493. var bs = src[srcOffset + 2];
  12494. if (maxVal !== false) {
  12495. Ls = decode(Ls, maxVal, 0, 100);
  12496. as = decode(as, maxVal, cs.amin, cs.amax);
  12497. bs = decode(bs, maxVal, cs.bmin, cs.bmax);
  12498. }
  12499. // Adjust limits of 'as' and 'bs'
  12500. as = as > cs.amax ? cs.amax : as < cs.amin ? cs.amin : as;
  12501. bs = bs > cs.bmax ? cs.bmax : bs < cs.bmin ? cs.bmin : bs;
  12502. // Computes intermediate variables X,Y,Z as per spec
  12503. var M = (Ls + 16) / 116;
  12504. var L = M + (as / 500);
  12505. var N = M - (bs / 200);
  12506. var X = cs.XW * fn_g(L);
  12507. var Y = cs.YW * fn_g(M);
  12508. var Z = cs.ZW * fn_g(N);
  12509. var r, g, b;
  12510. // Using different conversions for D50 and D65 white points,
  12511. // per http://www.color.org/srgb.pdf
  12512. if (cs.ZW < 1) {
  12513. // Assuming D50 (X=0.9642, Y=1.00, Z=0.8249)
  12514. r = X * 3.1339 + Y * -1.6170 + Z * -0.4906;
  12515. g = X * -0.9785 + Y * 1.9160 + Z * 0.0333;
  12516. b = X * 0.0720 + Y * -0.2290 + Z * 1.4057;
  12517. } else {
  12518. // Assuming D65 (X=0.9505, Y=1.00, Z=1.0888)
  12519. r = X * 3.2406 + Y * -1.5372 + Z * -0.4986;
  12520. g = X * -0.9689 + Y * 1.8758 + Z * 0.0415;
  12521. b = X * 0.0557 + Y * -0.2040 + Z * 1.0570;
  12522. }
  12523. // clamp color values to [0,1] range then convert to [0,255] range.
  12524. dest[destOffset] = r <= 0 ? 0 : r >= 1 ? 255 : Math.sqrt(r) * 255 | 0;
  12525. dest[destOffset + 1] = g <= 0 ? 0 : g >= 1 ? 255 : Math.sqrt(g) * 255 | 0;
  12526. dest[destOffset + 2] = b <= 0 ? 0 : b >= 1 ? 255 : Math.sqrt(b) * 255 | 0;
  12527. }
  12528. LabCS.prototype = {
  12529. getRgb: ColorSpace.prototype.getRgb,
  12530. getRgbItem: function LabCS_getRgbItem(src, srcOffset, dest, destOffset) {
  12531. convertToRgb(this, src, srcOffset, false, dest, destOffset);
  12532. },
  12533. getRgbBuffer: function LabCS_getRgbBuffer(src, srcOffset, count,
  12534. dest, destOffset, bits,
  12535. alpha01) {
  12536. var maxVal = (1 << bits) - 1;
  12537. for (var i = 0; i < count; i++) {
  12538. convertToRgb(this, src, srcOffset, maxVal, dest, destOffset);
  12539. srcOffset += 3;
  12540. destOffset += 3 + alpha01;
  12541. }
  12542. },
  12543. getOutputLength: function LabCS_getOutputLength(inputLength, alpha01) {
  12544. return (inputLength * (3 + alpha01) / 3) | 0;
  12545. },
  12546. isPassthrough: ColorSpace.prototype.isPassthrough,
  12547. fillRgb: ColorSpace.prototype.fillRgb,
  12548. isDefaultDecode: function LabCS_isDefaultDecode(decodeMap) {
  12549. // XXX: Decoding is handled with the lab conversion because of the strange
  12550. // ranges that are used.
  12551. return true;
  12552. },
  12553. usesZeroToOneRange: false
  12554. };
  12555. return LabCS;
  12556. })();
  12557. var ARCFourCipher = (function ARCFourCipherClosure() {
  12558. function ARCFourCipher(key) {
  12559. this.a = 0;
  12560. this.b = 0;
  12561. var s = new Uint8Array(256);
  12562. var i, j = 0, tmp, keyLength = key.length;
  12563. for (i = 0; i < 256; ++i) {
  12564. s[i] = i;
  12565. }
  12566. for (i = 0; i < 256; ++i) {
  12567. tmp = s[i];
  12568. j = (j + tmp + key[i % keyLength]) & 0xFF;
  12569. s[i] = s[j];
  12570. s[j] = tmp;
  12571. }
  12572. this.s = s;
  12573. }
  12574. ARCFourCipher.prototype = {
  12575. encryptBlock: function ARCFourCipher_encryptBlock(data) {
  12576. var i, n = data.length, tmp, tmp2;
  12577. var a = this.a, b = this.b, s = this.s;
  12578. var output = new Uint8Array(n);
  12579. for (i = 0; i < n; ++i) {
  12580. a = (a + 1) & 0xFF;
  12581. tmp = s[a];
  12582. b = (b + tmp) & 0xFF;
  12583. tmp2 = s[b];
  12584. s[a] = tmp2;
  12585. s[b] = tmp;
  12586. output[i] = data[i] ^ s[(tmp + tmp2) & 0xFF];
  12587. }
  12588. this.a = a;
  12589. this.b = b;
  12590. return output;
  12591. }
  12592. };
  12593. ARCFourCipher.prototype.decryptBlock = ARCFourCipher.prototype.encryptBlock;
  12594. return ARCFourCipher;
  12595. })();
  12596. var calculateMD5 = (function calculateMD5Closure() {
  12597. var r = new Uint8Array([
  12598. 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22,
  12599. 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20,
  12600. 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23,
  12601. 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21]);
  12602. var k = new Int32Array([
  12603. -680876936, -389564586, 606105819, -1044525330, -176418897, 1200080426,
  12604. -1473231341, -45705983, 1770035416, -1958414417, -42063, -1990404162,
  12605. 1804603682, -40341101, -1502002290, 1236535329, -165796510, -1069501632,
  12606. 643717713, -373897302, -701558691, 38016083, -660478335, -405537848,
  12607. 568446438, -1019803690, -187363961, 1163531501, -1444681467, -51403784,
  12608. 1735328473, -1926607734, -378558, -2022574463, 1839030562, -35309556,
  12609. -1530992060, 1272893353, -155497632, -1094730640, 681279174, -358537222,
  12610. -722521979, 76029189, -640364487, -421815835, 530742520, -995338651,
  12611. -198630844, 1126891415, -1416354905, -57434055, 1700485571, -1894986606,
  12612. -1051523, -2054922799, 1873313359, -30611744, -1560198380, 1309151649,
  12613. -145523070, -1120210379, 718787259, -343485551]);
  12614. function hash(data, offset, length) {
  12615. var h0 = 1732584193, h1 = -271733879, h2 = -1732584194, h3 = 271733878;
  12616. // pre-processing
  12617. var paddedLength = (length + 72) & ~63; // data + 9 extra bytes
  12618. var padded = new Uint8Array(paddedLength);
  12619. var i, j, n;
  12620. for (i = 0; i < length; ++i) {
  12621. padded[i] = data[offset++];
  12622. }
  12623. padded[i++] = 0x80;
  12624. n = paddedLength - 8;
  12625. while (i < n) {
  12626. padded[i++] = 0;
  12627. }
  12628. padded[i++] = (length << 3) & 0xFF;
  12629. padded[i++] = (length >> 5) & 0xFF;
  12630. padded[i++] = (length >> 13) & 0xFF;
  12631. padded[i++] = (length >> 21) & 0xFF;
  12632. padded[i++] = (length >>> 29) & 0xFF;
  12633. padded[i++] = 0;
  12634. padded[i++] = 0;
  12635. padded[i++] = 0;
  12636. var w = new Int32Array(16);
  12637. for (i = 0; i < paddedLength;) {
  12638. for (j = 0; j < 16; ++j, i += 4) {
  12639. w[j] = (padded[i] | (padded[i + 1] << 8) |
  12640. (padded[i + 2] << 16) | (padded[i + 3] << 24));
  12641. }
  12642. var a = h0, b = h1, c = h2, d = h3, f, g;
  12643. for (j = 0; j < 64; ++j) {
  12644. if (j < 16) {
  12645. f = (b & c) | ((~b) & d);
  12646. g = j;
  12647. } else if (j < 32) {
  12648. f = (d & b) | ((~d) & c);
  12649. g = (5 * j + 1) & 15;
  12650. } else if (j < 48) {
  12651. f = b ^ c ^ d;
  12652. g = (3 * j + 5) & 15;
  12653. } else {
  12654. f = c ^ (b | (~d));
  12655. g = (7 * j) & 15;
  12656. }
  12657. var tmp = d, rotateArg = (a + f + k[j] + w[g]) | 0, rotate = r[j];
  12658. d = c;
  12659. c = b;
  12660. b = (b + ((rotateArg << rotate) | (rotateArg >>> (32 - rotate)))) | 0;
  12661. a = tmp;
  12662. }
  12663. h0 = (h0 + a) | 0;
  12664. h1 = (h1 + b) | 0;
  12665. h2 = (h2 + c) | 0;
  12666. h3 = (h3 + d) | 0;
  12667. }
  12668. return new Uint8Array([
  12669. h0 & 0xFF, (h0 >> 8) & 0xFF, (h0 >> 16) & 0xFF, (h0 >>> 24) & 0xFF,
  12670. h1 & 0xFF, (h1 >> 8) & 0xFF, (h1 >> 16) & 0xFF, (h1 >>> 24) & 0xFF,
  12671. h2 & 0xFF, (h2 >> 8) & 0xFF, (h2 >> 16) & 0xFF, (h2 >>> 24) & 0xFF,
  12672. h3 & 0xFF, (h3 >> 8) & 0xFF, (h3 >> 16) & 0xFF, (h3 >>> 24) & 0xFF
  12673. ]);
  12674. }
  12675. return hash;
  12676. })();
  12677. var Word64 = (function Word64Closure() {
  12678. function Word64(highInteger, lowInteger) {
  12679. this.high = highInteger | 0;
  12680. this.low = lowInteger | 0;
  12681. }
  12682. Word64.prototype = {
  12683. and: function Word64_and(word) {
  12684. this.high &= word.high;
  12685. this.low &= word.low;
  12686. },
  12687. xor: function Word64_xor(word) {
  12688. this.high ^= word.high;
  12689. this.low ^= word.low;
  12690. },
  12691. or: function Word64_or(word) {
  12692. this.high |= word.high;
  12693. this.low |= word.low;
  12694. },
  12695. shiftRight: function Word64_shiftRight(places) {
  12696. if (places >= 32) {
  12697. this.low = (this.high >>> (places - 32)) | 0;
  12698. this.high = 0;
  12699. } else {
  12700. this.low = (this.low >>> places) | (this.high << (32 - places));
  12701. this.high = (this.high >>> places) | 0;
  12702. }
  12703. },
  12704. shiftLeft: function Word64_shiftLeft(places) {
  12705. if (places >= 32) {
  12706. this.high = this.low << (places - 32);
  12707. this.low = 0;
  12708. } else {
  12709. this.high = (this.high << places) | (this.low >>> (32 - places));
  12710. this.low = this.low << places;
  12711. }
  12712. },
  12713. rotateRight: function Word64_rotateRight(places) {
  12714. var low, high;
  12715. if (places & 32) {
  12716. high = this.low;
  12717. low = this.high;
  12718. } else {
  12719. low = this.low;
  12720. high = this.high;
  12721. }
  12722. places &= 31;
  12723. this.low = (low >>> places) | (high << (32 - places));
  12724. this.high = (high >>> places) | (low << (32 - places));
  12725. },
  12726. not: function Word64_not() {
  12727. this.high = ~this.high;
  12728. this.low = ~this.low;
  12729. },
  12730. add: function Word64_add(word) {
  12731. var lowAdd = (this.low >>> 0) + (word.low >>> 0);
  12732. var highAdd = (this.high >>> 0) + (word.high >>> 0);
  12733. if (lowAdd > 0xFFFFFFFF) {
  12734. highAdd += 1;
  12735. }
  12736. this.low = lowAdd | 0;
  12737. this.high = highAdd | 0;
  12738. },
  12739. copyTo: function Word64_copyTo(bytes, offset) {
  12740. bytes[offset] = (this.high >>> 24) & 0xFF;
  12741. bytes[offset + 1] = (this.high >> 16) & 0xFF;
  12742. bytes[offset + 2] = (this.high >> 8) & 0xFF;
  12743. bytes[offset + 3] = this.high & 0xFF;
  12744. bytes[offset + 4] = (this.low >>> 24) & 0xFF;
  12745. bytes[offset + 5] = (this.low >> 16) & 0xFF;
  12746. bytes[offset + 6] = (this.low >> 8) & 0xFF;
  12747. bytes[offset + 7] = this.low & 0xFF;
  12748. },
  12749. assign: function Word64_assign(word) {
  12750. this.high = word.high;
  12751. this.low = word.low;
  12752. }
  12753. };
  12754. return Word64;
  12755. })();
  12756. var calculateSHA256 = (function calculateSHA256Closure() {
  12757. function rotr(x, n) {
  12758. return (x >>> n) | (x << 32 - n);
  12759. }
  12760. function ch(x, y, z) {
  12761. return (x & y) ^ (~x & z);
  12762. }
  12763. function maj(x, y, z) {
  12764. return (x & y) ^ (x & z) ^ (y & z);
  12765. }
  12766. function sigma(x) {
  12767. return rotr(x, 2) ^ rotr(x, 13) ^ rotr(x, 22);
  12768. }
  12769. function sigmaPrime(x) {
  12770. return rotr(x, 6) ^ rotr(x, 11) ^ rotr(x, 25);
  12771. }
  12772. function littleSigma(x) {
  12773. return rotr(x, 7) ^ rotr(x, 18) ^ x >>> 3;
  12774. }
  12775. function littleSigmaPrime(x) {
  12776. return rotr(x, 17) ^ rotr(x, 19) ^ x >>> 10;
  12777. }
  12778. var k = [0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
  12779. 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
  12780. 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
  12781. 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
  12782. 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
  12783. 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
  12784. 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
  12785. 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
  12786. 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
  12787. 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
  12788. 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
  12789. 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
  12790. 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
  12791. 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
  12792. 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
  12793. 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2];
  12794. function hash(data, offset, length) {
  12795. // initial hash values
  12796. var h0 = 0x6a09e667, h1 = 0xbb67ae85, h2 = 0x3c6ef372,
  12797. h3 = 0xa54ff53a, h4 = 0x510e527f, h5 = 0x9b05688c,
  12798. h6 = 0x1f83d9ab, h7 = 0x5be0cd19;
  12799. // pre-processing
  12800. var paddedLength = Math.ceil((length + 9) / 64) * 64;
  12801. var padded = new Uint8Array(paddedLength);
  12802. var i, j, n;
  12803. for (i = 0; i < length; ++i) {
  12804. padded[i] = data[offset++];
  12805. }
  12806. padded[i++] = 0x80;
  12807. n = paddedLength - 8;
  12808. while (i < n) {
  12809. padded[i++] = 0;
  12810. }
  12811. padded[i++] = 0;
  12812. padded[i++] = 0;
  12813. padded[i++] = 0;
  12814. padded[i++] = (length >>> 29) & 0xFF;
  12815. padded[i++] = (length >> 21) & 0xFF;
  12816. padded[i++] = (length >> 13) & 0xFF;
  12817. padded[i++] = (length >> 5) & 0xFF;
  12818. padded[i++] = (length << 3) & 0xFF;
  12819. var w = new Uint32Array(64);
  12820. // for each 512 bit block
  12821. for (i = 0; i < paddedLength;) {
  12822. for (j = 0; j < 16; ++j) {
  12823. w[j] = (padded[i] << 24 | (padded[i + 1] << 16) |
  12824. (padded[i + 2] << 8) | (padded[i + 3]));
  12825. i += 4;
  12826. }
  12827. for (j = 16; j < 64; ++j) {
  12828. w[j] = littleSigmaPrime(w[j - 2]) + w[j - 7] +
  12829. littleSigma(w[j - 15]) + w[j - 16] | 0;
  12830. }
  12831. var a = h0, b = h1, c = h2, d = h3, e = h4,
  12832. f = h5, g = h6, h = h7, t1, t2;
  12833. for (j = 0; j < 64; ++j) {
  12834. t1 = h + sigmaPrime(e) + ch(e, f, g) + k[j] + w[j];
  12835. t2 = sigma(a) + maj(a, b, c);
  12836. h = g;
  12837. g = f;
  12838. f = e;
  12839. e = (d + t1) | 0;
  12840. d = c;
  12841. c = b;
  12842. b = a;
  12843. a = (t1 + t2) | 0;
  12844. }
  12845. h0 = (h0 + a) | 0;
  12846. h1 = (h1 + b) | 0;
  12847. h2 = (h2 + c) | 0;
  12848. h3 = (h3 + d) | 0;
  12849. h4 = (h4 + e) | 0;
  12850. h5 = (h5 + f) | 0;
  12851. h6 = (h6 + g) | 0;
  12852. h7 = (h7 + h) | 0;
  12853. }
  12854. return new Uint8Array([
  12855. (h0 >> 24) & 0xFF, (h0 >> 16) & 0xFF, (h0 >> 8) & 0xFF, (h0) & 0xFF,
  12856. (h1 >> 24) & 0xFF, (h1 >> 16) & 0xFF, (h1 >> 8) & 0xFF, (h1) & 0xFF,
  12857. (h2 >> 24) & 0xFF, (h2 >> 16) & 0xFF, (h2 >> 8) & 0xFF, (h2) & 0xFF,
  12858. (h3 >> 24) & 0xFF, (h3 >> 16) & 0xFF, (h3 >> 8) & 0xFF, (h3) & 0xFF,
  12859. (h4 >> 24) & 0xFF, (h4 >> 16) & 0xFF, (h4 >> 8) & 0xFF, (h4) & 0xFF,
  12860. (h5 >> 24) & 0xFF, (h5 >> 16) & 0xFF, (h5 >> 8) & 0xFF, (h5) & 0xFF,
  12861. (h6 >> 24) & 0xFF, (h6 >> 16) & 0xFF, (h6 >> 8) & 0xFF, (h6) & 0xFF,
  12862. (h7 >> 24) & 0xFF, (h7 >> 16) & 0xFF, (h7 >> 8) & 0xFF, (h7) & 0xFF
  12863. ]);
  12864. }
  12865. return hash;
  12866. })();
  12867. var calculateSHA512 = (function calculateSHA512Closure() {
  12868. function ch(result, x, y, z, tmp) {
  12869. result.assign(x);
  12870. result.and(y);
  12871. tmp.assign(x);
  12872. tmp.not();
  12873. tmp.and(z);
  12874. result.xor(tmp);
  12875. }
  12876. function maj(result, x, y, z, tmp) {
  12877. result.assign(x);
  12878. result.and(y);
  12879. tmp.assign(x);
  12880. tmp.and(z);
  12881. result.xor(tmp);
  12882. tmp.assign(y);
  12883. tmp.and(z);
  12884. result.xor(tmp);
  12885. }
  12886. function sigma(result, x, tmp) {
  12887. result.assign(x);
  12888. result.rotateRight(28);
  12889. tmp.assign(x);
  12890. tmp.rotateRight(34);
  12891. result.xor(tmp);
  12892. tmp.assign(x);
  12893. tmp.rotateRight(39);
  12894. result.xor(tmp);
  12895. }
  12896. function sigmaPrime(result, x, tmp) {
  12897. result.assign(x);
  12898. result.rotateRight(14);
  12899. tmp.assign(x);
  12900. tmp.rotateRight(18);
  12901. result.xor(tmp);
  12902. tmp.assign(x);
  12903. tmp.rotateRight(41);
  12904. result.xor(tmp);
  12905. }
  12906. function littleSigma(result, x, tmp) {
  12907. result.assign(x);
  12908. result.rotateRight(1);
  12909. tmp.assign(x);
  12910. tmp.rotateRight(8);
  12911. result.xor(tmp);
  12912. tmp.assign(x);
  12913. tmp.shiftRight(7);
  12914. result.xor(tmp);
  12915. }
  12916. function littleSigmaPrime(result, x, tmp) {
  12917. result.assign(x);
  12918. result.rotateRight(19);
  12919. tmp.assign(x);
  12920. tmp.rotateRight(61);
  12921. result.xor(tmp);
  12922. tmp.assign(x);
  12923. tmp.shiftRight(6);
  12924. result.xor(tmp);
  12925. }
  12926. var k = [
  12927. new Word64(0x428a2f98, 0xd728ae22), new Word64(0x71374491, 0x23ef65cd),
  12928. new Word64(0xb5c0fbcf, 0xec4d3b2f), new Word64(0xe9b5dba5, 0x8189dbbc),
  12929. new Word64(0x3956c25b, 0xf348b538), new Word64(0x59f111f1, 0xb605d019),
  12930. new Word64(0x923f82a4, 0xaf194f9b), new Word64(0xab1c5ed5, 0xda6d8118),
  12931. new Word64(0xd807aa98, 0xa3030242), new Word64(0x12835b01, 0x45706fbe),
  12932. new Word64(0x243185be, 0x4ee4b28c), new Word64(0x550c7dc3, 0xd5ffb4e2),
  12933. new Word64(0x72be5d74, 0xf27b896f), new Word64(0x80deb1fe, 0x3b1696b1),
  12934. new Word64(0x9bdc06a7, 0x25c71235), new Word64(0xc19bf174, 0xcf692694),
  12935. new Word64(0xe49b69c1, 0x9ef14ad2), new Word64(0xefbe4786, 0x384f25e3),
  12936. new Word64(0x0fc19dc6, 0x8b8cd5b5), new Word64(0x240ca1cc, 0x77ac9c65),
  12937. new Word64(0x2de92c6f, 0x592b0275), new Word64(0x4a7484aa, 0x6ea6e483),
  12938. new Word64(0x5cb0a9dc, 0xbd41fbd4), new Word64(0x76f988da, 0x831153b5),
  12939. new Word64(0x983e5152, 0xee66dfab), new Word64(0xa831c66d, 0x2db43210),
  12940. new Word64(0xb00327c8, 0x98fb213f), new Word64(0xbf597fc7, 0xbeef0ee4),
  12941. new Word64(0xc6e00bf3, 0x3da88fc2), new Word64(0xd5a79147, 0x930aa725),
  12942. new Word64(0x06ca6351, 0xe003826f), new Word64(0x14292967, 0x0a0e6e70),
  12943. new Word64(0x27b70a85, 0x46d22ffc), new Word64(0x2e1b2138, 0x5c26c926),
  12944. new Word64(0x4d2c6dfc, 0x5ac42aed), new Word64(0x53380d13, 0x9d95b3df),
  12945. new Word64(0x650a7354, 0x8baf63de), new Word64(0x766a0abb, 0x3c77b2a8),
  12946. new Word64(0x81c2c92e, 0x47edaee6), new Word64(0x92722c85, 0x1482353b),
  12947. new Word64(0xa2bfe8a1, 0x4cf10364), new Word64(0xa81a664b, 0xbc423001),
  12948. new Word64(0xc24b8b70, 0xd0f89791), new Word64(0xc76c51a3, 0x0654be30),
  12949. new Word64(0xd192e819, 0xd6ef5218), new Word64(0xd6990624, 0x5565a910),
  12950. new Word64(0xf40e3585, 0x5771202a), new Word64(0x106aa070, 0x32bbd1b8),
  12951. new Word64(0x19a4c116, 0xb8d2d0c8), new Word64(0x1e376c08, 0x5141ab53),
  12952. new Word64(0x2748774c, 0xdf8eeb99), new Word64(0x34b0bcb5, 0xe19b48a8),
  12953. new Word64(0x391c0cb3, 0xc5c95a63), new Word64(0x4ed8aa4a, 0xe3418acb),
  12954. new Word64(0x5b9cca4f, 0x7763e373), new Word64(0x682e6ff3, 0xd6b2b8a3),
  12955. new Word64(0x748f82ee, 0x5defb2fc), new Word64(0x78a5636f, 0x43172f60),
  12956. new Word64(0x84c87814, 0xa1f0ab72), new Word64(0x8cc70208, 0x1a6439ec),
  12957. new Word64(0x90befffa, 0x23631e28), new Word64(0xa4506ceb, 0xde82bde9),
  12958. new Word64(0xbef9a3f7, 0xb2c67915), new Word64(0xc67178f2, 0xe372532b),
  12959. new Word64(0xca273ece, 0xea26619c), new Word64(0xd186b8c7, 0x21c0c207),
  12960. new Word64(0xeada7dd6, 0xcde0eb1e), new Word64(0xf57d4f7f, 0xee6ed178),
  12961. new Word64(0x06f067aa, 0x72176fba), new Word64(0x0a637dc5, 0xa2c898a6),
  12962. new Word64(0x113f9804, 0xbef90dae), new Word64(0x1b710b35, 0x131c471b),
  12963. new Word64(0x28db77f5, 0x23047d84), new Word64(0x32caab7b, 0x40c72493),
  12964. new Word64(0x3c9ebe0a, 0x15c9bebc), new Word64(0x431d67c4, 0x9c100d4c),
  12965. new Word64(0x4cc5d4be, 0xcb3e42b6), new Word64(0x597f299c, 0xfc657e2a),
  12966. new Word64(0x5fcb6fab, 0x3ad6faec), new Word64(0x6c44198c, 0x4a475817)];
  12967. function hash(data, offset, length, mode384) {
  12968. mode384 = !!mode384;
  12969. // initial hash values
  12970. var h0, h1, h2, h3, h4, h5, h6, h7;
  12971. if (!mode384) {
  12972. h0 = new Word64(0x6a09e667, 0xf3bcc908);
  12973. h1 = new Word64(0xbb67ae85, 0x84caa73b);
  12974. h2 = new Word64(0x3c6ef372, 0xfe94f82b);
  12975. h3 = new Word64(0xa54ff53a, 0x5f1d36f1);
  12976. h4 = new Word64(0x510e527f, 0xade682d1);
  12977. h5 = new Word64(0x9b05688c, 0x2b3e6c1f);
  12978. h6 = new Word64(0x1f83d9ab, 0xfb41bd6b);
  12979. h7 = new Word64(0x5be0cd19, 0x137e2179);
  12980. }
  12981. else {
  12982. // SHA384 is exactly the same
  12983. // except with different starting values and a trimmed result
  12984. h0 = new Word64(0xcbbb9d5d, 0xc1059ed8);
  12985. h1 = new Word64(0x629a292a, 0x367cd507);
  12986. h2 = new Word64(0x9159015a, 0x3070dd17);
  12987. h3 = new Word64(0x152fecd8, 0xf70e5939);
  12988. h4 = new Word64(0x67332667, 0xffc00b31);
  12989. h5 = new Word64(0x8eb44a87, 0x68581511);
  12990. h6 = new Word64(0xdb0c2e0d, 0x64f98fa7);
  12991. h7 = new Word64(0x47b5481d, 0xbefa4fa4);
  12992. }
  12993. // pre-processing
  12994. var paddedLength = Math.ceil((length + 17) / 128) * 128;
  12995. var padded = new Uint8Array(paddedLength);
  12996. var i, j, n;
  12997. for (i = 0; i < length; ++i) {
  12998. padded[i] = data[offset++];
  12999. }
  13000. padded[i++] = 0x80;
  13001. n = paddedLength - 16;
  13002. while (i < n) {
  13003. padded[i++] = 0;
  13004. }
  13005. padded[i++] = 0;
  13006. padded[i++] = 0;
  13007. padded[i++] = 0;
  13008. padded[i++] = 0;
  13009. padded[i++] = 0;
  13010. padded[i++] = 0;
  13011. padded[i++] = 0;
  13012. padded[i++] = 0;
  13013. padded[i++] = 0;
  13014. padded[i++] = 0;
  13015. padded[i++] = 0;
  13016. padded[i++] = (length >>> 29) & 0xFF;
  13017. padded[i++] = (length >> 21) & 0xFF;
  13018. padded[i++] = (length >> 13) & 0xFF;
  13019. padded[i++] = (length >> 5) & 0xFF;
  13020. padded[i++] = (length << 3) & 0xFF;
  13021. var w = new Array(80);
  13022. for (i = 0; i < 80; i++) {
  13023. w[i] = new Word64(0, 0);
  13024. }
  13025. var a = new Word64(0, 0), b = new Word64(0, 0), c = new Word64(0, 0);
  13026. var d = new Word64(0, 0), e = new Word64(0, 0), f = new Word64(0, 0);
  13027. var g = new Word64(0, 0), h = new Word64(0, 0);
  13028. var t1 = new Word64(0, 0), t2 = new Word64(0, 0);
  13029. var tmp1 = new Word64(0, 0), tmp2 = new Word64(0, 0), tmp3;
  13030. // for each 1024 bit block
  13031. for (i = 0; i < paddedLength;) {
  13032. for (j = 0; j < 16; ++j) {
  13033. w[j].high = (padded[i] << 24) | (padded[i + 1] << 16) |
  13034. (padded[i + 2] << 8) | (padded[i + 3]);
  13035. w[j].low = (padded[i + 4]) << 24 | (padded[i + 5]) << 16 |
  13036. (padded[i + 6]) << 8 | (padded[i + 7]);
  13037. i += 8;
  13038. }
  13039. for (j = 16; j < 80; ++j) {
  13040. tmp3 = w[j];
  13041. littleSigmaPrime(tmp3, w[j - 2], tmp2);
  13042. tmp3.add(w[j - 7]);
  13043. littleSigma(tmp1, w[j - 15], tmp2);
  13044. tmp3.add(tmp1);
  13045. tmp3.add(w[j - 16]);
  13046. }
  13047. a.assign(h0); b.assign(h1); c.assign(h2); d.assign(h3);
  13048. e.assign(h4); f.assign(h5); g.assign(h6); h.assign(h7);
  13049. for (j = 0; j < 80; ++j) {
  13050. t1.assign(h);
  13051. sigmaPrime(tmp1, e, tmp2);
  13052. t1.add(tmp1);
  13053. ch(tmp1, e, f, g, tmp2);
  13054. t1.add(tmp1);
  13055. t1.add(k[j]);
  13056. t1.add(w[j]);
  13057. sigma(t2, a, tmp2);
  13058. maj(tmp1, a, b, c, tmp2);
  13059. t2.add(tmp1);
  13060. tmp3 = h;
  13061. h = g;
  13062. g = f;
  13063. f = e;
  13064. d.add(t1);
  13065. e = d;
  13066. d = c;
  13067. c = b;
  13068. b = a;
  13069. tmp3.assign(t1);
  13070. tmp3.add(t2);
  13071. a = tmp3;
  13072. }
  13073. h0.add(a);
  13074. h1.add(b);
  13075. h2.add(c);
  13076. h3.add(d);
  13077. h4.add(e);
  13078. h5.add(f);
  13079. h6.add(g);
  13080. h7.add(h);
  13081. }
  13082. var result;
  13083. if (!mode384) {
  13084. result = new Uint8Array(64);
  13085. h0.copyTo(result,0);
  13086. h1.copyTo(result,8);
  13087. h2.copyTo(result,16);
  13088. h3.copyTo(result,24);
  13089. h4.copyTo(result,32);
  13090. h5.copyTo(result,40);
  13091. h6.copyTo(result,48);
  13092. h7.copyTo(result,56);
  13093. }
  13094. else {
  13095. result = new Uint8Array(48);
  13096. h0.copyTo(result,0);
  13097. h1.copyTo(result,8);
  13098. h2.copyTo(result,16);
  13099. h3.copyTo(result,24);
  13100. h4.copyTo(result,32);
  13101. h5.copyTo(result,40);
  13102. }
  13103. return result;
  13104. }
  13105. return hash;
  13106. })();
  13107. var calculateSHA384 = (function calculateSHA384Closure() {
  13108. function hash(data, offset, length) {
  13109. return calculateSHA512(data, offset, length, true);
  13110. }
  13111. return hash;
  13112. })();
  13113. var NullCipher = (function NullCipherClosure() {
  13114. function NullCipher() {
  13115. }
  13116. NullCipher.prototype = {
  13117. decryptBlock: function NullCipher_decryptBlock(data) {
  13118. return data;
  13119. }
  13120. };
  13121. return NullCipher;
  13122. })();
  13123. var AES128Cipher = (function AES128CipherClosure() {
  13124. var rcon = new Uint8Array([
  13125. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  13126. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  13127. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  13128. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  13129. 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  13130. 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
  13131. 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
  13132. 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
  13133. 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
  13134. 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
  13135. 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
  13136. 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
  13137. 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
  13138. 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
  13139. 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
  13140. 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
  13141. 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
  13142. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  13143. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  13144. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  13145. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  13146. 0x74, 0xe8, 0xcb, 0x8d]);
  13147. var s = new Uint8Array([
  13148. 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
  13149. 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
  13150. 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
  13151. 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
  13152. 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
  13153. 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
  13154. 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
  13155. 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
  13156. 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
  13157. 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
  13158. 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
  13159. 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
  13160. 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
  13161. 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
  13162. 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
  13163. 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
  13164. 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
  13165. 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
  13166. 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
  13167. 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
  13168. 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
  13169. 0xb0, 0x54, 0xbb, 0x16]);
  13170. var inv_s = new Uint8Array([
  13171. 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
  13172. 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
  13173. 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
  13174. 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
  13175. 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
  13176. 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
  13177. 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
  13178. 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
  13179. 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
  13180. 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
  13181. 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
  13182. 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
  13183. 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
  13184. 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
  13185. 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
  13186. 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
  13187. 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
  13188. 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
  13189. 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
  13190. 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
  13191. 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
  13192. 0x55, 0x21, 0x0c, 0x7d]);
  13193. var mixCol = new Uint8Array(256);
  13194. for (var i = 0; i < 256; i++) {
  13195. if (i < 128) {
  13196. mixCol[i] = i << 1;
  13197. } else {
  13198. mixCol[i] = (i << 1) ^ 0x1b;
  13199. }
  13200. }
  13201. var mix = new Uint32Array([
  13202. 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
  13203. 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
  13204. 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
  13205. 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
  13206. 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
  13207. 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
  13208. 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
  13209. 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
  13210. 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
  13211. 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
  13212. 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
  13213. 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
  13214. 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
  13215. 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
  13216. 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
  13217. 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
  13218. 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
  13219. 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
  13220. 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
  13221. 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
  13222. 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
  13223. 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
  13224. 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
  13225. 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
  13226. 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
  13227. 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
  13228. 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
  13229. 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
  13230. 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
  13231. 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
  13232. 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
  13233. 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
  13234. 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
  13235. 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
  13236. 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
  13237. 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
  13238. 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
  13239. 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
  13240. 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
  13241. 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
  13242. 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
  13243. 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
  13244. 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
  13245. function expandKey128(cipherKey) {
  13246. var b = 176, result = new Uint8Array(b);
  13247. result.set(cipherKey);
  13248. for (var j = 16, i = 1; j < b; ++i) {
  13249. // RotWord
  13250. var t1 = result[j - 3], t2 = result[j - 2],
  13251. t3 = result[j - 1], t4 = result[j - 4];
  13252. // SubWord
  13253. t1 = s[t1];
  13254. t2 = s[t2];
  13255. t3 = s[t3];
  13256. t4 = s[t4];
  13257. // Rcon
  13258. t1 = t1 ^ rcon[i];
  13259. for (var n = 0; n < 4; ++n) {
  13260. result[j] = (t1 ^= result[j - 16]);
  13261. j++;
  13262. result[j] = (t2 ^= result[j - 16]);
  13263. j++;
  13264. result[j] = (t3 ^= result[j - 16]);
  13265. j++;
  13266. result[j] = (t4 ^= result[j - 16]);
  13267. j++;
  13268. }
  13269. }
  13270. return result;
  13271. }
  13272. function decrypt128(input, key) {
  13273. var state = new Uint8Array(16);
  13274. state.set(input);
  13275. var i, j, k;
  13276. var t, u, v;
  13277. // AddRoundKey
  13278. for (j = 0, k = 160; j < 16; ++j, ++k) {
  13279. state[j] ^= key[k];
  13280. }
  13281. for (i = 9; i >= 1; --i) {
  13282. // InvShiftRows
  13283. t = state[13];
  13284. state[13] = state[9];
  13285. state[9] = state[5];
  13286. state[5] = state[1];
  13287. state[1] = t;
  13288. t = state[14];
  13289. u = state[10];
  13290. state[14] = state[6];
  13291. state[10] = state[2];
  13292. state[6] = t;
  13293. state[2] = u;
  13294. t = state[15];
  13295. u = state[11];
  13296. v = state[7];
  13297. state[15] = state[3];
  13298. state[11] = t;
  13299. state[7] = u;
  13300. state[3] = v;
  13301. // InvSubBytes
  13302. for (j = 0; j < 16; ++j) {
  13303. state[j] = inv_s[state[j]];
  13304. }
  13305. // AddRoundKey
  13306. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  13307. state[j] ^= key[k];
  13308. }
  13309. // InvMixColumns
  13310. for (j = 0; j < 16; j += 4) {
  13311. var s0 = mix[state[j]], s1 = mix[state[j + 1]],
  13312. s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  13313. t = (s0 ^ (s1 >>> 8) ^ (s1 << 24) ^ (s2 >>> 16) ^ (s2 << 16) ^
  13314. (s3 >>> 24) ^ (s3 << 8));
  13315. state[j] = (t >>> 24) & 0xFF;
  13316. state[j + 1] = (t >> 16) & 0xFF;
  13317. state[j + 2] = (t >> 8) & 0xFF;
  13318. state[j + 3] = t & 0xFF;
  13319. }
  13320. }
  13321. // InvShiftRows
  13322. t = state[13];
  13323. state[13] = state[9];
  13324. state[9] = state[5];
  13325. state[5] = state[1];
  13326. state[1] = t;
  13327. t = state[14];
  13328. u = state[10];
  13329. state[14] = state[6];
  13330. state[10] = state[2];
  13331. state[6] = t;
  13332. state[2] = u;
  13333. t = state[15];
  13334. u = state[11];
  13335. v = state[7];
  13336. state[15] = state[3];
  13337. state[11] = t;
  13338. state[7] = u;
  13339. state[3] = v;
  13340. for (j = 0; j < 16; ++j) {
  13341. // InvSubBytes
  13342. state[j] = inv_s[state[j]];
  13343. // AddRoundKey
  13344. state[j] ^= key[j];
  13345. }
  13346. return state;
  13347. }
  13348. function encrypt128(input, key) {
  13349. var t, u, v, k;
  13350. var state = new Uint8Array(16);
  13351. state.set(input);
  13352. for (j = 0; j < 16; ++j) {
  13353. // AddRoundKey
  13354. state[j] ^= key[j];
  13355. }
  13356. for (i = 1; i < 10; i++) {
  13357. //SubBytes
  13358. for (j = 0; j < 16; ++j) {
  13359. state[j] = s[state[j]];
  13360. }
  13361. //ShiftRows
  13362. v = state[1];
  13363. state[1] = state[5];
  13364. state[5] = state[9];
  13365. state[9] = state[13];
  13366. state[13] = v;
  13367. v = state[2];
  13368. u = state[6];
  13369. state[2] = state[10];
  13370. state[6] = state[14];
  13371. state[10] = v;
  13372. state[14] = u;
  13373. v = state[3];
  13374. u = state[7];
  13375. t = state[11];
  13376. state[3] = state[15];
  13377. state[7] = v;
  13378. state[11] = u;
  13379. state[15] = t;
  13380. //MixColumns
  13381. for (var j = 0; j < 16; j += 4) {
  13382. var s0 = state[j + 0], s1 = state[j + 1];
  13383. var s2 = state[j + 2], s3 = state[j + 3];
  13384. t = s0 ^ s1 ^ s2 ^ s3;
  13385. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  13386. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  13387. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  13388. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  13389. }
  13390. //AddRoundKey
  13391. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  13392. state[j] ^= key[k];
  13393. }
  13394. }
  13395. //SubBytes
  13396. for (j = 0; j < 16; ++j) {
  13397. state[j] = s[state[j]];
  13398. }
  13399. //ShiftRows
  13400. v = state[1];
  13401. state[1] = state[5];
  13402. state[5] = state[9];
  13403. state[9] = state[13];
  13404. state[13] = v;
  13405. v = state[2];
  13406. u = state[6];
  13407. state[2] = state[10];
  13408. state[6] = state[14];
  13409. state[10] = v;
  13410. state[14] = u;
  13411. v = state[3];
  13412. u = state[7];
  13413. t = state[11];
  13414. state[3] = state[15];
  13415. state[7] = v;
  13416. state[11] = u;
  13417. state[15] = t;
  13418. //AddRoundKey
  13419. for (j = 0, k = 160; j < 16; ++j, ++k) {
  13420. state[j] ^= key[k];
  13421. }
  13422. return state;
  13423. }
  13424. function AES128Cipher(key) {
  13425. this.key = expandKey128(key);
  13426. this.buffer = new Uint8Array(16);
  13427. this.bufferPosition = 0;
  13428. }
  13429. function decryptBlock2(data, finalize) {
  13430. var i, j, ii, sourceLength = data.length,
  13431. buffer = this.buffer, bufferLength = this.bufferPosition,
  13432. result = [], iv = this.iv;
  13433. for (i = 0; i < sourceLength; ++i) {
  13434. buffer[bufferLength] = data[i];
  13435. ++bufferLength;
  13436. if (bufferLength < 16) {
  13437. continue;
  13438. }
  13439. // buffer is full, decrypting
  13440. var plain = decrypt128(buffer, this.key);
  13441. // xor-ing the IV vector to get plain text
  13442. for (j = 0; j < 16; ++j) {
  13443. plain[j] ^= iv[j];
  13444. }
  13445. iv = buffer;
  13446. result.push(plain);
  13447. buffer = new Uint8Array(16);
  13448. bufferLength = 0;
  13449. }
  13450. // saving incomplete buffer
  13451. this.buffer = buffer;
  13452. this.bufferLength = bufferLength;
  13453. this.iv = iv;
  13454. if (result.length === 0) {
  13455. return new Uint8Array([]);
  13456. }
  13457. // combining plain text blocks into one
  13458. var outputLength = 16 * result.length;
  13459. if (finalize) {
  13460. // undo a padding that is described in RFC 2898
  13461. var lastBlock = result[result.length - 1];
  13462. var psLen = lastBlock[15];
  13463. if (psLen <= 16) {
  13464. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  13465. if (lastBlock[i] !== psLen) {
  13466. // Invalid padding, assume that the block has no padding.
  13467. psLen = 0;
  13468. break;
  13469. }
  13470. }
  13471. outputLength -= psLen;
  13472. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  13473. }
  13474. }
  13475. var output = new Uint8Array(outputLength);
  13476. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  13477. output.set(result[i], j);
  13478. }
  13479. return output;
  13480. }
  13481. AES128Cipher.prototype = {
  13482. decryptBlock: function AES128Cipher_decryptBlock(data, finalize) {
  13483. var i, sourceLength = data.length;
  13484. var buffer = this.buffer, bufferLength = this.bufferPosition;
  13485. // waiting for IV values -- they are at the start of the stream
  13486. for (i = 0; bufferLength < 16 && i < sourceLength; ++i, ++bufferLength) {
  13487. buffer[bufferLength] = data[i];
  13488. }
  13489. if (bufferLength < 16) {
  13490. // need more data
  13491. this.bufferLength = bufferLength;
  13492. return new Uint8Array([]);
  13493. }
  13494. this.iv = buffer;
  13495. this.buffer = new Uint8Array(16);
  13496. this.bufferLength = 0;
  13497. // starting decryption
  13498. this.decryptBlock = decryptBlock2;
  13499. return this.decryptBlock(data.subarray(16), finalize);
  13500. },
  13501. encrypt: function AES128Cipher_encrypt(data, iv) {
  13502. var i, j, ii, sourceLength = data.length,
  13503. buffer = this.buffer, bufferLength = this.bufferPosition,
  13504. result = [];
  13505. if (!iv) {
  13506. iv = new Uint8Array(16);
  13507. }
  13508. for (i = 0; i < sourceLength; ++i) {
  13509. buffer[bufferLength] = data[i];
  13510. ++bufferLength;
  13511. if (bufferLength < 16) {
  13512. continue;
  13513. }
  13514. for (j = 0; j < 16; ++j) {
  13515. buffer[j] ^= iv[j];
  13516. }
  13517. // buffer is full, encrypting
  13518. var cipher = encrypt128(buffer, this.key);
  13519. iv = cipher;
  13520. result.push(cipher);
  13521. buffer = new Uint8Array(16);
  13522. bufferLength = 0;
  13523. }
  13524. // saving incomplete buffer
  13525. this.buffer = buffer;
  13526. this.bufferLength = bufferLength;
  13527. this.iv = iv;
  13528. if (result.length === 0) {
  13529. return new Uint8Array([]);
  13530. }
  13531. // combining plain text blocks into one
  13532. var outputLength = 16 * result.length;
  13533. var output = new Uint8Array(outputLength);
  13534. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  13535. output.set(result[i], j);
  13536. }
  13537. return output;
  13538. }
  13539. };
  13540. return AES128Cipher;
  13541. })();
  13542. var AES256Cipher = (function AES256CipherClosure() {
  13543. var rcon = new Uint8Array([
  13544. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  13545. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  13546. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  13547. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  13548. 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  13549. 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
  13550. 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
  13551. 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
  13552. 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
  13553. 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
  13554. 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
  13555. 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
  13556. 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
  13557. 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
  13558. 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
  13559. 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
  13560. 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
  13561. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  13562. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  13563. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  13564. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  13565. 0x74, 0xe8, 0xcb, 0x8d]);
  13566. var s = new Uint8Array([
  13567. 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
  13568. 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
  13569. 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
  13570. 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
  13571. 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
  13572. 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
  13573. 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
  13574. 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
  13575. 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
  13576. 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
  13577. 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
  13578. 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
  13579. 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
  13580. 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
  13581. 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
  13582. 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
  13583. 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
  13584. 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
  13585. 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
  13586. 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
  13587. 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
  13588. 0xb0, 0x54, 0xbb, 0x16]);
  13589. var inv_s = new Uint8Array([
  13590. 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
  13591. 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
  13592. 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
  13593. 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
  13594. 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
  13595. 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
  13596. 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
  13597. 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
  13598. 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
  13599. 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
  13600. 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
  13601. 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
  13602. 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
  13603. 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
  13604. 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
  13605. 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
  13606. 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
  13607. 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
  13608. 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
  13609. 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
  13610. 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
  13611. 0x55, 0x21, 0x0c, 0x7d]);
  13612. var mixCol = new Uint8Array(256);
  13613. for (var i = 0; i < 256; i++) {
  13614. if (i < 128) {
  13615. mixCol[i] = i << 1;
  13616. } else {
  13617. mixCol[i] = (i << 1) ^ 0x1b;
  13618. }
  13619. }
  13620. var mix = new Uint32Array([
  13621. 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
  13622. 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
  13623. 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
  13624. 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
  13625. 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
  13626. 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
  13627. 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
  13628. 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
  13629. 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
  13630. 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
  13631. 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
  13632. 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
  13633. 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
  13634. 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
  13635. 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
  13636. 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
  13637. 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
  13638. 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
  13639. 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
  13640. 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
  13641. 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
  13642. 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
  13643. 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
  13644. 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
  13645. 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
  13646. 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
  13647. 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
  13648. 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
  13649. 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
  13650. 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
  13651. 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
  13652. 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
  13653. 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
  13654. 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
  13655. 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
  13656. 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
  13657. 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
  13658. 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
  13659. 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
  13660. 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
  13661. 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
  13662. 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
  13663. 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
  13664. function expandKey256(cipherKey) {
  13665. var b = 240, result = new Uint8Array(b);
  13666. var r = 1;
  13667. result.set(cipherKey);
  13668. for (var j = 32, i = 1; j < b; ++i) {
  13669. if (j % 32 === 16) {
  13670. t1 = s[t1];
  13671. t2 = s[t2];
  13672. t3 = s[t3];
  13673. t4 = s[t4];
  13674. } else if (j % 32 === 0) {
  13675. // RotWord
  13676. var t1 = result[j - 3], t2 = result[j - 2],
  13677. t3 = result[j - 1], t4 = result[j - 4];
  13678. // SubWord
  13679. t1 = s[t1];
  13680. t2 = s[t2];
  13681. t3 = s[t3];
  13682. t4 = s[t4];
  13683. // Rcon
  13684. t1 = t1 ^ r;
  13685. if ((r <<= 1) >= 256) {
  13686. r = (r ^ 0x1b) & 0xFF;
  13687. }
  13688. }
  13689. for (var n = 0; n < 4; ++n) {
  13690. result[j] = (t1 ^= result[j - 32]);
  13691. j++;
  13692. result[j] = (t2 ^= result[j - 32]);
  13693. j++;
  13694. result[j] = (t3 ^= result[j - 32]);
  13695. j++;
  13696. result[j] = (t4 ^= result[j - 32]);
  13697. j++;
  13698. }
  13699. }
  13700. return result;
  13701. }
  13702. function decrypt256(input, key) {
  13703. var state = new Uint8Array(16);
  13704. state.set(input);
  13705. var i, j, k;
  13706. var t, u, v;
  13707. // AddRoundKey
  13708. for (j = 0, k = 224; j < 16; ++j, ++k) {
  13709. state[j] ^= key[k];
  13710. }
  13711. for (i = 13; i >= 1; --i) {
  13712. // InvShiftRows
  13713. t = state[13];
  13714. state[13] = state[9];
  13715. state[9] = state[5];
  13716. state[5] = state[1];
  13717. state[1] = t;
  13718. t = state[14];
  13719. u = state[10];
  13720. state[14] = state[6];
  13721. state[10] = state[2];
  13722. state[6] = t;
  13723. state[2] = u;
  13724. t = state[15];
  13725. u = state[11];
  13726. v = state[7];
  13727. state[15] = state[3];
  13728. state[11] = t;
  13729. state[7] = u;
  13730. state[3] = v;
  13731. // InvSubBytes
  13732. for (j = 0; j < 16; ++j) {
  13733. state[j] = inv_s[state[j]];
  13734. }
  13735. // AddRoundKey
  13736. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  13737. state[j] ^= key[k];
  13738. }
  13739. // InvMixColumns
  13740. for (j = 0; j < 16; j += 4) {
  13741. var s0 = mix[state[j]], s1 = mix[state[j + 1]],
  13742. s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  13743. t = (s0 ^ (s1 >>> 8) ^ (s1 << 24) ^ (s2 >>> 16) ^ (s2 << 16) ^
  13744. (s3 >>> 24) ^ (s3 << 8));
  13745. state[j] = (t >>> 24) & 0xFF;
  13746. state[j + 1] = (t >> 16) & 0xFF;
  13747. state[j + 2] = (t >> 8) & 0xFF;
  13748. state[j + 3] = t & 0xFF;
  13749. }
  13750. }
  13751. // InvShiftRows
  13752. t = state[13];
  13753. state[13] = state[9];
  13754. state[9] = state[5];
  13755. state[5] = state[1];
  13756. state[1] = t;
  13757. t = state[14];
  13758. u = state[10];
  13759. state[14] = state[6];
  13760. state[10] = state[2];
  13761. state[6] = t;
  13762. state[2] = u;
  13763. t = state[15];
  13764. u = state[11];
  13765. v = state[7];
  13766. state[15] = state[3];
  13767. state[11] = t;
  13768. state[7] = u;
  13769. state[3] = v;
  13770. for (j = 0; j < 16; ++j) {
  13771. // InvSubBytes
  13772. state[j] = inv_s[state[j]];
  13773. // AddRoundKey
  13774. state[j] ^= key[j];
  13775. }
  13776. return state;
  13777. }
  13778. function encrypt256(input, key) {
  13779. var t, u, v, k;
  13780. var state = new Uint8Array(16);
  13781. state.set(input);
  13782. for (j = 0; j < 16; ++j) {
  13783. // AddRoundKey
  13784. state[j] ^= key[j];
  13785. }
  13786. for (i = 1; i < 14; i++) {
  13787. //SubBytes
  13788. for (j = 0; j < 16; ++j) {
  13789. state[j] = s[state[j]];
  13790. }
  13791. //ShiftRows
  13792. v = state[1];
  13793. state[1] = state[5];
  13794. state[5] = state[9];
  13795. state[9] = state[13];
  13796. state[13] = v;
  13797. v = state[2];
  13798. u = state[6];
  13799. state[2] = state[10];
  13800. state[6] = state[14];
  13801. state[10] = v;
  13802. state[14] = u;
  13803. v = state[3];
  13804. u = state[7];
  13805. t = state[11];
  13806. state[3] = state[15];
  13807. state[7] = v;
  13808. state[11] = u;
  13809. state[15] = t;
  13810. //MixColumns
  13811. for (var j = 0; j < 16; j += 4) {
  13812. var s0 = state[j + 0], s1 = state[j + 1];
  13813. var s2 = state[j + 2], s3 = state[j + 3];
  13814. t = s0 ^ s1 ^ s2 ^ s3;
  13815. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  13816. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  13817. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  13818. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  13819. }
  13820. //AddRoundKey
  13821. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  13822. state[j] ^= key[k];
  13823. }
  13824. }
  13825. //SubBytes
  13826. for (j = 0; j < 16; ++j) {
  13827. state[j] = s[state[j]];
  13828. }
  13829. //ShiftRows
  13830. v = state[1];
  13831. state[1] = state[5];
  13832. state[5] = state[9];
  13833. state[9] = state[13];
  13834. state[13] = v;
  13835. v = state[2];
  13836. u = state[6];
  13837. state[2] = state[10];
  13838. state[6] = state[14];
  13839. state[10] = v;
  13840. state[14] = u;
  13841. v = state[3];
  13842. u = state[7];
  13843. t = state[11];
  13844. state[3] = state[15];
  13845. state[7] = v;
  13846. state[11] = u;
  13847. state[15] = t;
  13848. //AddRoundKey
  13849. for (j = 0, k = 224; j < 16; ++j, ++k) {
  13850. state[j] ^= key[k];
  13851. }
  13852. return state;
  13853. }
  13854. function AES256Cipher(key) {
  13855. this.key = expandKey256(key);
  13856. this.buffer = new Uint8Array(16);
  13857. this.bufferPosition = 0;
  13858. }
  13859. function decryptBlock2(data, finalize) {
  13860. var i, j, ii, sourceLength = data.length,
  13861. buffer = this.buffer, bufferLength = this.bufferPosition,
  13862. result = [], iv = this.iv;
  13863. for (i = 0; i < sourceLength; ++i) {
  13864. buffer[bufferLength] = data[i];
  13865. ++bufferLength;
  13866. if (bufferLength < 16) {
  13867. continue;
  13868. }
  13869. // buffer is full, decrypting
  13870. var plain = decrypt256(buffer, this.key);
  13871. // xor-ing the IV vector to get plain text
  13872. for (j = 0; j < 16; ++j) {
  13873. plain[j] ^= iv[j];
  13874. }
  13875. iv = buffer;
  13876. result.push(plain);
  13877. buffer = new Uint8Array(16);
  13878. bufferLength = 0;
  13879. }
  13880. // saving incomplete buffer
  13881. this.buffer = buffer;
  13882. this.bufferLength = bufferLength;
  13883. this.iv = iv;
  13884. if (result.length === 0) {
  13885. return new Uint8Array([]);
  13886. }
  13887. // combining plain text blocks into one
  13888. var outputLength = 16 * result.length;
  13889. if (finalize) {
  13890. // undo a padding that is described in RFC 2898
  13891. var lastBlock = result[result.length - 1];
  13892. var psLen = lastBlock[15];
  13893. if (psLen <= 16) {
  13894. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  13895. if (lastBlock[i] !== psLen) {
  13896. // Invalid padding, assume that the block has no padding.
  13897. psLen = 0;
  13898. break;
  13899. }
  13900. }
  13901. outputLength -= psLen;
  13902. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  13903. }
  13904. }
  13905. var output = new Uint8Array(outputLength);
  13906. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  13907. output.set(result[i], j);
  13908. }
  13909. return output;
  13910. }
  13911. AES256Cipher.prototype = {
  13912. decryptBlock: function AES256Cipher_decryptBlock(data, finalize, iv) {
  13913. var i, sourceLength = data.length;
  13914. var buffer = this.buffer, bufferLength = this.bufferPosition;
  13915. // if not supplied an IV wait for IV values
  13916. // they are at the start of the stream
  13917. if (iv) {
  13918. this.iv = iv;
  13919. } else {
  13920. for (i = 0; bufferLength < 16 &&
  13921. i < sourceLength; ++i, ++bufferLength) {
  13922. buffer[bufferLength] = data[i];
  13923. }
  13924. if (bufferLength < 16) {
  13925. //need more data
  13926. this.bufferLength = bufferLength;
  13927. return new Uint8Array([]);
  13928. }
  13929. this.iv = buffer;
  13930. data = data.subarray(16);
  13931. }
  13932. this.buffer = new Uint8Array(16);
  13933. this.bufferLength = 0;
  13934. // starting decryption
  13935. this.decryptBlock = decryptBlock2;
  13936. return this.decryptBlock(data, finalize);
  13937. },
  13938. encrypt: function AES256Cipher_encrypt(data, iv) {
  13939. var i, j, ii, sourceLength = data.length,
  13940. buffer = this.buffer, bufferLength = this.bufferPosition,
  13941. result = [];
  13942. if (!iv) {
  13943. iv = new Uint8Array(16);
  13944. }
  13945. for (i = 0; i < sourceLength; ++i) {
  13946. buffer[bufferLength] = data[i];
  13947. ++bufferLength;
  13948. if (bufferLength < 16) {
  13949. continue;
  13950. }
  13951. for (j = 0; j < 16; ++j) {
  13952. buffer[j] ^= iv[j];
  13953. }
  13954. // buffer is full, encrypting
  13955. var cipher = encrypt256(buffer, this.key);
  13956. this.iv = cipher;
  13957. result.push(cipher);
  13958. buffer = new Uint8Array(16);
  13959. bufferLength = 0;
  13960. }
  13961. // saving incomplete buffer
  13962. this.buffer = buffer;
  13963. this.bufferLength = bufferLength;
  13964. this.iv = iv;
  13965. if (result.length === 0) {
  13966. return new Uint8Array([]);
  13967. }
  13968. // combining plain text blocks into one
  13969. var outputLength = 16 * result.length;
  13970. var output = new Uint8Array(outputLength);
  13971. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  13972. output.set(result[i], j);
  13973. }
  13974. return output;
  13975. }
  13976. };
  13977. return AES256Cipher;
  13978. })();
  13979. var PDF17 = (function PDF17Closure() {
  13980. function compareByteArrays(array1, array2) {
  13981. if (array1.length !== array2.length) {
  13982. return false;
  13983. }
  13984. for (var i = 0; i < array1.length; i++) {
  13985. if (array1[i] !== array2[i]) {
  13986. return false;
  13987. }
  13988. }
  13989. return true;
  13990. }
  13991. function PDF17() {
  13992. }
  13993. PDF17.prototype = {
  13994. checkOwnerPassword: function PDF17_checkOwnerPassword(password,
  13995. ownerValidationSalt,
  13996. userBytes,
  13997. ownerPassword) {
  13998. var hashData = new Uint8Array(password.length + 56);
  13999. hashData.set(password, 0);
  14000. hashData.set(ownerValidationSalt, password.length);
  14001. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  14002. var result = calculateSHA256(hashData, 0, hashData.length);
  14003. return compareByteArrays(result, ownerPassword);
  14004. },
  14005. checkUserPassword: function PDF17_checkUserPassword(password,
  14006. userValidationSalt,
  14007. userPassword) {
  14008. var hashData = new Uint8Array(password.length + 8);
  14009. hashData.set(password, 0);
  14010. hashData.set(userValidationSalt, password.length);
  14011. var result = calculateSHA256(hashData, 0, hashData.length);
  14012. return compareByteArrays(result, userPassword);
  14013. },
  14014. getOwnerKey: function PDF17_getOwnerKey(password, ownerKeySalt, userBytes,
  14015. ownerEncryption) {
  14016. var hashData = new Uint8Array(password.length + 56);
  14017. hashData.set(password, 0);
  14018. hashData.set(ownerKeySalt, password.length);
  14019. hashData.set(userBytes, password.length + ownerKeySalt.length);
  14020. var key = calculateSHA256(hashData, 0, hashData.length);
  14021. var cipher = new AES256Cipher(key);
  14022. return cipher.decryptBlock(ownerEncryption,
  14023. false,
  14024. new Uint8Array(16));
  14025. },
  14026. getUserKey: function PDF17_getUserKey(password, userKeySalt,
  14027. userEncryption) {
  14028. var hashData = new Uint8Array(password.length + 8);
  14029. hashData.set(password, 0);
  14030. hashData.set(userKeySalt, password.length);
  14031. //key is the decryption key for the UE string
  14032. var key = calculateSHA256(hashData, 0, hashData.length);
  14033. var cipher = new AES256Cipher(key);
  14034. return cipher.decryptBlock(userEncryption,
  14035. false,
  14036. new Uint8Array(16));
  14037. }
  14038. };
  14039. return PDF17;
  14040. })();
  14041. var PDF20 = (function PDF20Closure() {
  14042. function concatArrays(array1, array2) {
  14043. var t = new Uint8Array(array1.length + array2.length);
  14044. t.set(array1, 0);
  14045. t.set(array2, array1.length);
  14046. return t;
  14047. }
  14048. function calculatePDF20Hash(password, input, userBytes) {
  14049. //This refers to Algorithm 2.B as defined in ISO 32000-2
  14050. var k = calculateSHA256(input, 0, input.length).subarray(0, 32);
  14051. var e = [0];
  14052. var i = 0;
  14053. while (i < 64 || e[e.length - 1] > i - 32) {
  14054. var arrayLength = password.length + k.length + userBytes.length;
  14055. var k1 = new Uint8Array(arrayLength * 64);
  14056. var array = concatArrays(password, k);
  14057. array = concatArrays(array, userBytes);
  14058. for (var j = 0, pos = 0; j < 64; j++, pos += arrayLength) {
  14059. k1.set(array, pos);
  14060. }
  14061. //AES128 CBC NO PADDING with
  14062. //first 16 bytes of k as the key and the second 16 as the iv.
  14063. var cipher = new AES128Cipher(k.subarray(0, 16));
  14064. e = cipher.encrypt(k1, k.subarray(16, 32));
  14065. //Now we have to take the first 16 bytes of an unsigned
  14066. //big endian integer... and compute the remainder
  14067. //modulo 3.... That is a fairly large number and
  14068. //JavaScript isn't going to handle that well...
  14069. //So we're using a trick that allows us to perform
  14070. //modulo math byte by byte
  14071. var remainder = 0;
  14072. for (var z = 0; z < 16; z++) {
  14073. remainder *= (256 % 3);
  14074. remainder %= 3;
  14075. remainder += ((e[z] >>> 0) % 3);
  14076. remainder %= 3;
  14077. }
  14078. if (remainder === 0) {
  14079. k = calculateSHA256(e, 0, e.length);
  14080. }
  14081. else if (remainder === 1) {
  14082. k = calculateSHA384(e, 0, e.length);
  14083. }
  14084. else if (remainder === 2) {
  14085. k = calculateSHA512(e, 0, e.length);
  14086. }
  14087. i++;
  14088. }
  14089. return k.subarray(0, 32);
  14090. }
  14091. function PDF20() {
  14092. }
  14093. function compareByteArrays(array1, array2) {
  14094. if (array1.length !== array2.length) {
  14095. return false;
  14096. }
  14097. for (var i = 0; i < array1.length; i++) {
  14098. if (array1[i] !== array2[i]) {
  14099. return false;
  14100. }
  14101. }
  14102. return true;
  14103. }
  14104. PDF20.prototype = {
  14105. hash: function PDF20_hash(password, concatBytes, userBytes) {
  14106. return calculatePDF20Hash(password, concatBytes, userBytes);
  14107. },
  14108. checkOwnerPassword: function PDF20_checkOwnerPassword(password,
  14109. ownerValidationSalt,
  14110. userBytes,
  14111. ownerPassword) {
  14112. var hashData = new Uint8Array(password.length + 56);
  14113. hashData.set(password, 0);
  14114. hashData.set(ownerValidationSalt, password.length);
  14115. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  14116. var result = calculatePDF20Hash(password, hashData, userBytes);
  14117. return compareByteArrays(result, ownerPassword);
  14118. },
  14119. checkUserPassword: function PDF20_checkUserPassword(password,
  14120. userValidationSalt,
  14121. userPassword) {
  14122. var hashData = new Uint8Array(password.length + 8);
  14123. hashData.set(password, 0);
  14124. hashData.set(userValidationSalt, password.length);
  14125. var result = calculatePDF20Hash(password, hashData, []);
  14126. return compareByteArrays(result, userPassword);
  14127. },
  14128. getOwnerKey: function PDF20_getOwnerKey(password, ownerKeySalt, userBytes,
  14129. ownerEncryption) {
  14130. var hashData = new Uint8Array(password.length + 56);
  14131. hashData.set(password, 0);
  14132. hashData.set(ownerKeySalt, password.length);
  14133. hashData.set(userBytes, password.length + ownerKeySalt.length);
  14134. var key = calculatePDF20Hash(password, hashData, userBytes);
  14135. var cipher = new AES256Cipher(key);
  14136. return cipher.decryptBlock(ownerEncryption,
  14137. false,
  14138. new Uint8Array(16));
  14139. },
  14140. getUserKey: function PDF20_getUserKey(password, userKeySalt,
  14141. userEncryption) {
  14142. var hashData = new Uint8Array(password.length + 8);
  14143. hashData.set(password, 0);
  14144. hashData.set(userKeySalt, password.length);
  14145. //key is the decryption key for the UE string
  14146. var key = calculatePDF20Hash(password, hashData, []);
  14147. var cipher = new AES256Cipher(key);
  14148. return cipher.decryptBlock(userEncryption,
  14149. false,
  14150. new Uint8Array(16));
  14151. }
  14152. };
  14153. return PDF20;
  14154. })();
  14155. var CipherTransform = (function CipherTransformClosure() {
  14156. function CipherTransform(stringCipherConstructor, streamCipherConstructor) {
  14157. this.stringCipherConstructor = stringCipherConstructor;
  14158. this.streamCipherConstructor = streamCipherConstructor;
  14159. }
  14160. CipherTransform.prototype = {
  14161. createStream: function CipherTransform_createStream(stream, length) {
  14162. var cipher = new this.streamCipherConstructor();
  14163. return new DecryptStream(stream, length,
  14164. function cipherTransformDecryptStream(data, finalize) {
  14165. return cipher.decryptBlock(data, finalize);
  14166. }
  14167. );
  14168. },
  14169. decryptString: function CipherTransform_decryptString(s) {
  14170. var cipher = new this.stringCipherConstructor();
  14171. var data = stringToBytes(s);
  14172. data = cipher.decryptBlock(data, true);
  14173. return bytesToString(data);
  14174. }
  14175. };
  14176. return CipherTransform;
  14177. })();
  14178. var CipherTransformFactory = (function CipherTransformFactoryClosure() {
  14179. var defaultPasswordBytes = new Uint8Array([
  14180. 0x28, 0xBF, 0x4E, 0x5E, 0x4E, 0x75, 0x8A, 0x41,
  14181. 0x64, 0x00, 0x4E, 0x56, 0xFF, 0xFA, 0x01, 0x08,
  14182. 0x2E, 0x2E, 0x00, 0xB6, 0xD0, 0x68, 0x3E, 0x80,
  14183. 0x2F, 0x0C, 0xA9, 0xFE, 0x64, 0x53, 0x69, 0x7A]);
  14184. function createEncryptionKey20(revision, password, ownerPassword,
  14185. ownerValidationSalt, ownerKeySalt, uBytes,
  14186. userPassword, userValidationSalt, userKeySalt,
  14187. ownerEncryption, userEncryption, perms) {
  14188. if (password) {
  14189. var passwordLength = Math.min(127, password.length);
  14190. password = password.subarray(0, passwordLength);
  14191. } else {
  14192. password = [];
  14193. }
  14194. var pdfAlgorithm;
  14195. if (revision === 6) {
  14196. pdfAlgorithm = new PDF20();
  14197. } else {
  14198. pdfAlgorithm = new PDF17();
  14199. }
  14200. if (pdfAlgorithm) {
  14201. if (pdfAlgorithm.checkUserPassword(password, userValidationSalt,
  14202. userPassword)) {
  14203. return pdfAlgorithm.getUserKey(password, userKeySalt, userEncryption);
  14204. } else if (pdfAlgorithm.checkOwnerPassword(password, ownerValidationSalt,
  14205. uBytes,
  14206. ownerPassword)) {
  14207. return pdfAlgorithm.getOwnerKey(password, ownerKeySalt, uBytes,
  14208. ownerEncryption);
  14209. }
  14210. }
  14211. return null;
  14212. }
  14213. function prepareKeyData(fileId, password, ownerPassword, userPassword,
  14214. flags, revision, keyLength, encryptMetadata) {
  14215. var hashDataSize = 40 + ownerPassword.length + fileId.length;
  14216. var hashData = new Uint8Array(hashDataSize), i = 0, j, n;
  14217. if (password) {
  14218. n = Math.min(32, password.length);
  14219. for (; i < n; ++i) {
  14220. hashData[i] = password[i];
  14221. }
  14222. }
  14223. j = 0;
  14224. while (i < 32) {
  14225. hashData[i++] = defaultPasswordBytes[j++];
  14226. }
  14227. // as now the padded password in the hashData[0..i]
  14228. for (j = 0, n = ownerPassword.length; j < n; ++j) {
  14229. hashData[i++] = ownerPassword[j];
  14230. }
  14231. hashData[i++] = flags & 0xFF;
  14232. hashData[i++] = (flags >> 8) & 0xFF;
  14233. hashData[i++] = (flags >> 16) & 0xFF;
  14234. hashData[i++] = (flags >>> 24) & 0xFF;
  14235. for (j = 0, n = fileId.length; j < n; ++j) {
  14236. hashData[i++] = fileId[j];
  14237. }
  14238. if (revision >= 4 && !encryptMetadata) {
  14239. hashData[i++] = 0xFF;
  14240. hashData[i++] = 0xFF;
  14241. hashData[i++] = 0xFF;
  14242. hashData[i++] = 0xFF;
  14243. }
  14244. var hash = calculateMD5(hashData, 0, i);
  14245. var keyLengthInBytes = keyLength >> 3;
  14246. if (revision >= 3) {
  14247. for (j = 0; j < 50; ++j) {
  14248. hash = calculateMD5(hash, 0, keyLengthInBytes);
  14249. }
  14250. }
  14251. var encryptionKey = hash.subarray(0, keyLengthInBytes);
  14252. var cipher, checkData;
  14253. if (revision >= 3) {
  14254. for (i = 0; i < 32; ++i) {
  14255. hashData[i] = defaultPasswordBytes[i];
  14256. }
  14257. for (j = 0, n = fileId.length; j < n; ++j) {
  14258. hashData[i++] = fileId[j];
  14259. }
  14260. cipher = new ARCFourCipher(encryptionKey);
  14261. checkData = cipher.encryptBlock(calculateMD5(hashData, 0, i));
  14262. n = encryptionKey.length;
  14263. var derivedKey = new Uint8Array(n), k;
  14264. for (j = 1; j <= 19; ++j) {
  14265. for (k = 0; k < n; ++k) {
  14266. derivedKey[k] = encryptionKey[k] ^ j;
  14267. }
  14268. cipher = new ARCFourCipher(derivedKey);
  14269. checkData = cipher.encryptBlock(checkData);
  14270. }
  14271. for (j = 0, n = checkData.length; j < n; ++j) {
  14272. if (userPassword[j] !== checkData[j]) {
  14273. return null;
  14274. }
  14275. }
  14276. } else {
  14277. cipher = new ARCFourCipher(encryptionKey);
  14278. checkData = cipher.encryptBlock(defaultPasswordBytes);
  14279. for (j = 0, n = checkData.length; j < n; ++j) {
  14280. if (userPassword[j] !== checkData[j]) {
  14281. return null;
  14282. }
  14283. }
  14284. }
  14285. return encryptionKey;
  14286. }
  14287. function decodeUserPassword(password, ownerPassword, revision, keyLength) {
  14288. var hashData = new Uint8Array(32), i = 0, j, n;
  14289. n = Math.min(32, password.length);
  14290. for (; i < n; ++i) {
  14291. hashData[i] = password[i];
  14292. }
  14293. j = 0;
  14294. while (i < 32) {
  14295. hashData[i++] = defaultPasswordBytes[j++];
  14296. }
  14297. var hash = calculateMD5(hashData, 0, i);
  14298. var keyLengthInBytes = keyLength >> 3;
  14299. if (revision >= 3) {
  14300. for (j = 0; j < 50; ++j) {
  14301. hash = calculateMD5(hash, 0, hash.length);
  14302. }
  14303. }
  14304. var cipher, userPassword;
  14305. if (revision >= 3) {
  14306. userPassword = ownerPassword;
  14307. var derivedKey = new Uint8Array(keyLengthInBytes), k;
  14308. for (j = 19; j >= 0; j--) {
  14309. for (k = 0; k < keyLengthInBytes; ++k) {
  14310. derivedKey[k] = hash[k] ^ j;
  14311. }
  14312. cipher = new ARCFourCipher(derivedKey);
  14313. userPassword = cipher.encryptBlock(userPassword);
  14314. }
  14315. } else {
  14316. cipher = new ARCFourCipher(hash.subarray(0, keyLengthInBytes));
  14317. userPassword = cipher.encryptBlock(ownerPassword);
  14318. }
  14319. return userPassword;
  14320. }
  14321. var identityName = Name.get('Identity');
  14322. function CipherTransformFactory(dict, fileId, password) {
  14323. var filter = dict.get('Filter');
  14324. if (!isName(filter) || filter.name !== 'Standard') {
  14325. error('unknown encryption method');
  14326. }
  14327. this.dict = dict;
  14328. var algorithm = dict.get('V');
  14329. if (!isInt(algorithm) ||
  14330. (algorithm !== 1 && algorithm !== 2 && algorithm !== 4 &&
  14331. algorithm !== 5)) {
  14332. error('unsupported encryption algorithm');
  14333. }
  14334. this.algorithm = algorithm;
  14335. var keyLength = dict.get('Length') || 40;
  14336. if (!isInt(keyLength) ||
  14337. keyLength < 40 || (keyLength % 8) !== 0) {
  14338. error('invalid key length');
  14339. }
  14340. // prepare keys
  14341. var ownerPassword = stringToBytes(dict.get('O')).subarray(0, 32);
  14342. var userPassword = stringToBytes(dict.get('U')).subarray(0, 32);
  14343. var flags = dict.get('P');
  14344. var revision = dict.get('R');
  14345. // meaningful when V is 4 or 5
  14346. var encryptMetadata = ((algorithm === 4 || algorithm === 5) &&
  14347. dict.get('EncryptMetadata') !== false);
  14348. this.encryptMetadata = encryptMetadata;
  14349. var fileIdBytes = stringToBytes(fileId);
  14350. var passwordBytes;
  14351. if (password) {
  14352. passwordBytes = stringToBytes(password);
  14353. }
  14354. var encryptionKey;
  14355. if (algorithm !== 5) {
  14356. encryptionKey = prepareKeyData(fileIdBytes, passwordBytes,
  14357. ownerPassword, userPassword, flags,
  14358. revision, keyLength, encryptMetadata);
  14359. }
  14360. else {
  14361. var ownerValidationSalt = stringToBytes(dict.get('O')).subarray(32, 40);
  14362. var ownerKeySalt = stringToBytes(dict.get('O')).subarray(40, 48);
  14363. var uBytes = stringToBytes(dict.get('U')).subarray(0, 48);
  14364. var userValidationSalt = stringToBytes(dict.get('U')).subarray(32, 40);
  14365. var userKeySalt = stringToBytes(dict.get('U')).subarray(40, 48);
  14366. var ownerEncryption = stringToBytes(dict.get('OE'));
  14367. var userEncryption = stringToBytes(dict.get('UE'));
  14368. var perms = stringToBytes(dict.get('Perms'));
  14369. encryptionKey =
  14370. createEncryptionKey20(revision, passwordBytes,
  14371. ownerPassword, ownerValidationSalt,
  14372. ownerKeySalt, uBytes,
  14373. userPassword, userValidationSalt,
  14374. userKeySalt, ownerEncryption,
  14375. userEncryption, perms);
  14376. }
  14377. if (!encryptionKey && !password) {
  14378. throw new PasswordException('No password given',
  14379. PasswordResponses.NEED_PASSWORD);
  14380. } else if (!encryptionKey && password) {
  14381. // Attempting use the password as an owner password
  14382. var decodedPassword = decodeUserPassword(passwordBytes, ownerPassword,
  14383. revision, keyLength);
  14384. encryptionKey = prepareKeyData(fileIdBytes, decodedPassword,
  14385. ownerPassword, userPassword, flags,
  14386. revision, keyLength, encryptMetadata);
  14387. }
  14388. if (!encryptionKey) {
  14389. throw new PasswordException('Incorrect Password',
  14390. PasswordResponses.INCORRECT_PASSWORD);
  14391. }
  14392. this.encryptionKey = encryptionKey;
  14393. if (algorithm >= 4) {
  14394. this.cf = dict.get('CF');
  14395. this.stmf = dict.get('StmF') || identityName;
  14396. this.strf = dict.get('StrF') || identityName;
  14397. this.eff = dict.get('EFF') || this.strf;
  14398. }
  14399. }
  14400. function buildObjectKey(num, gen, encryptionKey, isAes) {
  14401. var key = new Uint8Array(encryptionKey.length + 9), i, n;
  14402. for (i = 0, n = encryptionKey.length; i < n; ++i) {
  14403. key[i] = encryptionKey[i];
  14404. }
  14405. key[i++] = num & 0xFF;
  14406. key[i++] = (num >> 8) & 0xFF;
  14407. key[i++] = (num >> 16) & 0xFF;
  14408. key[i++] = gen & 0xFF;
  14409. key[i++] = (gen >> 8) & 0xFF;
  14410. if (isAes) {
  14411. key[i++] = 0x73;
  14412. key[i++] = 0x41;
  14413. key[i++] = 0x6C;
  14414. key[i++] = 0x54;
  14415. }
  14416. var hash = calculateMD5(key, 0, i);
  14417. return hash.subarray(0, Math.min(encryptionKey.length + 5, 16));
  14418. }
  14419. function buildCipherConstructor(cf, name, num, gen, key) {
  14420. var cryptFilter = cf.get(name.name);
  14421. var cfm;
  14422. if (cryptFilter !== null && cryptFilter !== undefined) {
  14423. cfm = cryptFilter.get('CFM');
  14424. }
  14425. if (!cfm || cfm.name === 'None') {
  14426. return function cipherTransformFactoryBuildCipherConstructorNone() {
  14427. return new NullCipher();
  14428. };
  14429. }
  14430. if ('V2' === cfm.name) {
  14431. return function cipherTransformFactoryBuildCipherConstructorV2() {
  14432. return new ARCFourCipher(buildObjectKey(num, gen, key, false));
  14433. };
  14434. }
  14435. if ('AESV2' === cfm.name) {
  14436. return function cipherTransformFactoryBuildCipherConstructorAESV2() {
  14437. return new AES128Cipher(buildObjectKey(num, gen, key, true));
  14438. };
  14439. }
  14440. if ('AESV3' === cfm.name) {
  14441. return function cipherTransformFactoryBuildCipherConstructorAESV3() {
  14442. return new AES256Cipher(key);
  14443. };
  14444. }
  14445. error('Unknown crypto method');
  14446. }
  14447. CipherTransformFactory.prototype = {
  14448. createCipherTransform:
  14449. function CipherTransformFactory_createCipherTransform(num, gen) {
  14450. if (this.algorithm === 4 || this.algorithm === 5) {
  14451. return new CipherTransform(
  14452. buildCipherConstructor(this.cf, this.stmf,
  14453. num, gen, this.encryptionKey),
  14454. buildCipherConstructor(this.cf, this.strf,
  14455. num, gen, this.encryptionKey));
  14456. }
  14457. // algorithms 1 and 2
  14458. var key = buildObjectKey(num, gen, this.encryptionKey, false);
  14459. var cipherConstructor = function buildCipherCipherConstructor() {
  14460. return new ARCFourCipher(key);
  14461. };
  14462. return new CipherTransform(cipherConstructor, cipherConstructor);
  14463. }
  14464. };
  14465. return CipherTransformFactory;
  14466. })();
  14467. var PatternType = {
  14468. FUNCTION_BASED: 1,
  14469. AXIAL: 2,
  14470. RADIAL: 3,
  14471. FREE_FORM_MESH: 4,
  14472. LATTICE_FORM_MESH: 5,
  14473. COONS_PATCH_MESH: 6,
  14474. TENSOR_PATCH_MESH: 7
  14475. };
  14476. var Pattern = (function PatternClosure() {
  14477. // Constructor should define this.getPattern
  14478. function Pattern() {
  14479. error('should not call Pattern constructor');
  14480. }
  14481. Pattern.prototype = {
  14482. // Input: current Canvas context
  14483. // Output: the appropriate fillStyle or strokeStyle
  14484. getPattern: function Pattern_getPattern(ctx) {
  14485. error('Should not call Pattern.getStyle: ' + ctx);
  14486. }
  14487. };
  14488. Pattern.parseShading = function Pattern_parseShading(shading, matrix, xref,
  14489. res) {
  14490. var dict = isStream(shading) ? shading.dict : shading;
  14491. var type = dict.get('ShadingType');
  14492. try {
  14493. switch (type) {
  14494. case PatternType.AXIAL:
  14495. case PatternType.RADIAL:
  14496. // Both radial and axial shadings are handled by RadialAxial shading.
  14497. return new Shadings.RadialAxial(dict, matrix, xref, res);
  14498. case PatternType.FREE_FORM_MESH:
  14499. case PatternType.LATTICE_FORM_MESH:
  14500. case PatternType.COONS_PATCH_MESH:
  14501. case PatternType.TENSOR_PATCH_MESH:
  14502. return new Shadings.Mesh(shading, matrix, xref, res);
  14503. default:
  14504. throw new Error('Unknown PatternType: ' + type);
  14505. }
  14506. } catch (ex) {
  14507. if (ex instanceof MissingDataException) {
  14508. throw ex;
  14509. }
  14510. UnsupportedManager.notify(UNSUPPORTED_FEATURES.shadingPattern);
  14511. warn(ex);
  14512. return new Shadings.Dummy();
  14513. }
  14514. };
  14515. return Pattern;
  14516. })();
  14517. var Shadings = {};
  14518. // A small number to offset the first/last color stops so we can insert ones to
  14519. // support extend. Number.MIN_VALUE appears to be too small and breaks the
  14520. // extend. 1e-7 works in FF but chrome seems to use an even smaller sized number
  14521. // internally so we have to go bigger.
  14522. Shadings.SMALL_NUMBER = 1e-2;
  14523. // Radial and axial shading have very similar implementations
  14524. // If needed, the implementations can be broken into two classes
  14525. Shadings.RadialAxial = (function RadialAxialClosure() {
  14526. function RadialAxial(dict, matrix, xref, res) {
  14527. this.matrix = matrix;
  14528. this.coordsArr = dict.get('Coords');
  14529. this.shadingType = dict.get('ShadingType');
  14530. this.type = 'Pattern';
  14531. var cs = dict.get('ColorSpace', 'CS');
  14532. cs = ColorSpace.parse(cs, xref, res);
  14533. this.cs = cs;
  14534. var t0 = 0.0, t1 = 1.0;
  14535. if (dict.has('Domain')) {
  14536. var domainArr = dict.get('Domain');
  14537. t0 = domainArr[0];
  14538. t1 = domainArr[1];
  14539. }
  14540. var extendStart = false, extendEnd = false;
  14541. if (dict.has('Extend')) {
  14542. var extendArr = dict.get('Extend');
  14543. extendStart = extendArr[0];
  14544. extendEnd = extendArr[1];
  14545. }
  14546. if (this.shadingType === PatternType.RADIAL &&
  14547. (!extendStart || !extendEnd)) {
  14548. // Radial gradient only currently works if either circle is fully within
  14549. // the other circle.
  14550. var x1 = this.coordsArr[0];
  14551. var y1 = this.coordsArr[1];
  14552. var r1 = this.coordsArr[2];
  14553. var x2 = this.coordsArr[3];
  14554. var y2 = this.coordsArr[4];
  14555. var r2 = this.coordsArr[5];
  14556. var distance = Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
  14557. if (r1 <= r2 + distance &&
  14558. r2 <= r1 + distance) {
  14559. warn('Unsupported radial gradient.');
  14560. }
  14561. }
  14562. this.extendStart = extendStart;
  14563. this.extendEnd = extendEnd;
  14564. var fnObj = dict.get('Function');
  14565. var fn = PDFFunction.parseArray(xref, fnObj);
  14566. // 10 samples seems good enough for now, but probably won't work
  14567. // if there are sharp color changes. Ideally, we would implement
  14568. // the spec faithfully and add lossless optimizations.
  14569. var diff = t1 - t0;
  14570. var step = diff / 10;
  14571. var colorStops = this.colorStops = [];
  14572. // Protect against bad domains so we don't end up in an infinte loop below.
  14573. if (t0 >= t1 || step <= 0) {
  14574. // Acrobat doesn't seem to handle these cases so we'll ignore for
  14575. // now.
  14576. info('Bad shading domain.');
  14577. return;
  14578. }
  14579. var color = new Float32Array(cs.numComps), ratio = new Float32Array(1);
  14580. var rgbColor;
  14581. for (var i = t0; i <= t1; i += step) {
  14582. ratio[0] = i;
  14583. fn(ratio, 0, color, 0);
  14584. rgbColor = cs.getRgb(color, 0);
  14585. var cssColor = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
  14586. colorStops.push([(i - t0) / diff, cssColor]);
  14587. }
  14588. var background = 'transparent';
  14589. if (dict.has('Background')) {
  14590. rgbColor = cs.getRgb(dict.get('Background'), 0);
  14591. background = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
  14592. }
  14593. if (!extendStart) {
  14594. // Insert a color stop at the front and offset the first real color stop
  14595. // so it doesn't conflict with the one we insert.
  14596. colorStops.unshift([0, background]);
  14597. colorStops[1][0] += Shadings.SMALL_NUMBER;
  14598. }
  14599. if (!extendEnd) {
  14600. // Same idea as above in extendStart but for the end.
  14601. colorStops[colorStops.length - 1][0] -= Shadings.SMALL_NUMBER;
  14602. colorStops.push([1, background]);
  14603. }
  14604. this.colorStops = colorStops;
  14605. }
  14606. RadialAxial.prototype = {
  14607. getIR: function RadialAxial_getIR() {
  14608. var coordsArr = this.coordsArr;
  14609. var shadingType = this.shadingType;
  14610. var type, p0, p1, r0, r1;
  14611. if (shadingType === PatternType.AXIAL) {
  14612. p0 = [coordsArr[0], coordsArr[1]];
  14613. p1 = [coordsArr[2], coordsArr[3]];
  14614. r0 = null;
  14615. r1 = null;
  14616. type = 'axial';
  14617. } else if (shadingType === PatternType.RADIAL) {
  14618. p0 = [coordsArr[0], coordsArr[1]];
  14619. p1 = [coordsArr[3], coordsArr[4]];
  14620. r0 = coordsArr[2];
  14621. r1 = coordsArr[5];
  14622. type = 'radial';
  14623. } else {
  14624. error('getPattern type unknown: ' + shadingType);
  14625. }
  14626. var matrix = this.matrix;
  14627. if (matrix) {
  14628. p0 = Util.applyTransform(p0, matrix);
  14629. p1 = Util.applyTransform(p1, matrix);
  14630. }
  14631. return ['RadialAxial', type, this.colorStops, p0, p1, r0, r1];
  14632. }
  14633. };
  14634. return RadialAxial;
  14635. })();
  14636. // All mesh shading. For now, they will be presented as set of the triangles
  14637. // to be drawn on the canvas and rgb color for each vertex.
  14638. Shadings.Mesh = (function MeshClosure() {
  14639. function MeshStreamReader(stream, context) {
  14640. this.stream = stream;
  14641. this.context = context;
  14642. this.buffer = 0;
  14643. this.bufferLength = 0;
  14644. var numComps = context.numComps;
  14645. this.tmpCompsBuf = new Float32Array(numComps);
  14646. var csNumComps = context.colorSpace;
  14647. this.tmpCsCompsBuf = context.colorFn ? new Float32Array(csNumComps) :
  14648. this.tmpCompsBuf;
  14649. }
  14650. MeshStreamReader.prototype = {
  14651. get hasData() {
  14652. if (this.stream.end) {
  14653. return this.stream.pos < this.stream.end;
  14654. }
  14655. if (this.bufferLength > 0) {
  14656. return true;
  14657. }
  14658. var nextByte = this.stream.getByte();
  14659. if (nextByte < 0) {
  14660. return false;
  14661. }
  14662. this.buffer = nextByte;
  14663. this.bufferLength = 8;
  14664. return true;
  14665. },
  14666. readBits: function MeshStreamReader_readBits(n) {
  14667. var buffer = this.buffer;
  14668. var bufferLength = this.bufferLength;
  14669. if (n === 32) {
  14670. if (bufferLength === 0) {
  14671. return ((this.stream.getByte() << 24) |
  14672. (this.stream.getByte() << 16) | (this.stream.getByte() << 8) |
  14673. this.stream.getByte()) >>> 0;
  14674. }
  14675. buffer = (buffer << 24) | (this.stream.getByte() << 16) |
  14676. (this.stream.getByte() << 8) | this.stream.getByte();
  14677. var nextByte = this.stream.getByte();
  14678. this.buffer = nextByte & ((1 << bufferLength) - 1);
  14679. return ((buffer << (8 - bufferLength)) |
  14680. ((nextByte & 0xFF) >> bufferLength)) >>> 0;
  14681. }
  14682. if (n === 8 && bufferLength === 0) {
  14683. return this.stream.getByte();
  14684. }
  14685. while (bufferLength < n) {
  14686. buffer = (buffer << 8) | this.stream.getByte();
  14687. bufferLength += 8;
  14688. }
  14689. bufferLength -= n;
  14690. this.bufferLength = bufferLength;
  14691. this.buffer = buffer & ((1 << bufferLength) - 1);
  14692. return buffer >> bufferLength;
  14693. },
  14694. align: function MeshStreamReader_align() {
  14695. this.buffer = 0;
  14696. this.bufferLength = 0;
  14697. },
  14698. readFlag: function MeshStreamReader_readFlag() {
  14699. return this.readBits(this.context.bitsPerFlag);
  14700. },
  14701. readCoordinate: function MeshStreamReader_readCoordinate() {
  14702. var bitsPerCoordinate = this.context.bitsPerCoordinate;
  14703. var xi = this.readBits(bitsPerCoordinate);
  14704. var yi = this.readBits(bitsPerCoordinate);
  14705. var decode = this.context.decode;
  14706. var scale = bitsPerCoordinate < 32 ? 1 / ((1 << bitsPerCoordinate) - 1) :
  14707. 2.3283064365386963e-10; // 2 ^ -32
  14708. return [
  14709. xi * scale * (decode[1] - decode[0]) + decode[0],
  14710. yi * scale * (decode[3] - decode[2]) + decode[2]
  14711. ];
  14712. },
  14713. readComponents: function MeshStreamReader_readComponents() {
  14714. var numComps = this.context.numComps;
  14715. var bitsPerComponent = this.context.bitsPerComponent;
  14716. var scale = bitsPerComponent < 32 ? 1 / ((1 << bitsPerComponent) - 1) :
  14717. 2.3283064365386963e-10; // 2 ^ -32
  14718. var decode = this.context.decode;
  14719. var components = this.tmpCompsBuf;
  14720. for (var i = 0, j = 4; i < numComps; i++, j += 2) {
  14721. var ci = this.readBits(bitsPerComponent);
  14722. components[i] = ci * scale * (decode[j + 1] - decode[j]) + decode[j];
  14723. }
  14724. var color = this.tmpCsCompsBuf;
  14725. if (this.context.colorFn) {
  14726. this.context.colorFn(components, 0, color, 0);
  14727. }
  14728. return this.context.colorSpace.getRgb(color, 0);
  14729. }
  14730. };
  14731. function decodeType4Shading(mesh, reader) {
  14732. var coords = mesh.coords;
  14733. var colors = mesh.colors;
  14734. var operators = [];
  14735. var ps = []; // not maintaining cs since that will match ps
  14736. var verticesLeft = 0; // assuming we have all data to start a new triangle
  14737. while (reader.hasData) {
  14738. var f = reader.readFlag();
  14739. var coord = reader.readCoordinate();
  14740. var color = reader.readComponents();
  14741. if (verticesLeft === 0) { // ignoring flags if we started a triangle
  14742. assert(0 <= f && f <= 2, 'Unknown type4 flag');
  14743. switch (f) {
  14744. case 0:
  14745. verticesLeft = 3;
  14746. break;
  14747. case 1:
  14748. ps.push(ps[ps.length - 2], ps[ps.length - 1]);
  14749. verticesLeft = 1;
  14750. break;
  14751. case 2:
  14752. ps.push(ps[ps.length - 3], ps[ps.length - 1]);
  14753. verticesLeft = 1;
  14754. break;
  14755. }
  14756. operators.push(f);
  14757. }
  14758. ps.push(coords.length);
  14759. coords.push(coord);
  14760. colors.push(color);
  14761. verticesLeft--;
  14762. reader.align();
  14763. }
  14764. var psPacked = new Int32Array(ps);
  14765. mesh.figures.push({
  14766. type: 'triangles',
  14767. coords: psPacked,
  14768. colors: psPacked
  14769. });
  14770. }
  14771. function decodeType5Shading(mesh, reader, verticesPerRow) {
  14772. var coords = mesh.coords;
  14773. var colors = mesh.colors;
  14774. var ps = []; // not maintaining cs since that will match ps
  14775. while (reader.hasData) {
  14776. var coord = reader.readCoordinate();
  14777. var color = reader.readComponents();
  14778. ps.push(coords.length);
  14779. coords.push(coord);
  14780. colors.push(color);
  14781. }
  14782. var psPacked = new Int32Array(ps);
  14783. mesh.figures.push({
  14784. type: 'lattice',
  14785. coords: psPacked,
  14786. colors: psPacked,
  14787. verticesPerRow: verticesPerRow
  14788. });
  14789. }
  14790. var MIN_SPLIT_PATCH_CHUNKS_AMOUNT = 3;
  14791. var MAX_SPLIT_PATCH_CHUNKS_AMOUNT = 20;
  14792. var TRIANGLE_DENSITY = 20; // count of triangles per entire mesh bounds
  14793. var getB = (function getBClosure() {
  14794. function buildB(count) {
  14795. var lut = [];
  14796. for (var i = 0; i <= count; i++) {
  14797. var t = i / count, t_ = 1 - t;
  14798. lut.push(new Float32Array([t_ * t_ * t_, 3 * t * t_ * t_,
  14799. 3 * t * t * t_, t * t * t]));
  14800. }
  14801. return lut;
  14802. }
  14803. var cache = [];
  14804. return function getB(count) {
  14805. if (!cache[count]) {
  14806. cache[count] = buildB(count);
  14807. }
  14808. return cache[count];
  14809. };
  14810. })();
  14811. function buildFigureFromPatch(mesh, index) {
  14812. var figure = mesh.figures[index];
  14813. assert(figure.type === 'patch', 'Unexpected patch mesh figure');
  14814. var coords = mesh.coords, colors = mesh.colors;
  14815. var pi = figure.coords;
  14816. var ci = figure.colors;
  14817. var figureMinX = Math.min(coords[pi[0]][0], coords[pi[3]][0],
  14818. coords[pi[12]][0], coords[pi[15]][0]);
  14819. var figureMinY = Math.min(coords[pi[0]][1], coords[pi[3]][1],
  14820. coords[pi[12]][1], coords[pi[15]][1]);
  14821. var figureMaxX = Math.max(coords[pi[0]][0], coords[pi[3]][0],
  14822. coords[pi[12]][0], coords[pi[15]][0]);
  14823. var figureMaxY = Math.max(coords[pi[0]][1], coords[pi[3]][1],
  14824. coords[pi[12]][1], coords[pi[15]][1]);
  14825. var splitXBy = Math.ceil((figureMaxX - figureMinX) * TRIANGLE_DENSITY /
  14826. (mesh.bounds[2] - mesh.bounds[0]));
  14827. splitXBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
  14828. Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitXBy));
  14829. var splitYBy = Math.ceil((figureMaxY - figureMinY) * TRIANGLE_DENSITY /
  14830. (mesh.bounds[3] - mesh.bounds[1]));
  14831. splitYBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
  14832. Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitYBy));
  14833. var verticesPerRow = splitXBy + 1;
  14834. var figureCoords = new Int32Array((splitYBy + 1) * verticesPerRow);
  14835. var figureColors = new Int32Array((splitYBy + 1) * verticesPerRow);
  14836. var k = 0;
  14837. var cl = new Uint8Array(3), cr = new Uint8Array(3);
  14838. var c0 = colors[ci[0]], c1 = colors[ci[1]],
  14839. c2 = colors[ci[2]], c3 = colors[ci[3]];
  14840. var bRow = getB(splitYBy), bCol = getB(splitXBy);
  14841. for (var row = 0; row <= splitYBy; row++) {
  14842. cl[0] = ((c0[0] * (splitYBy - row) + c2[0] * row) / splitYBy) | 0;
  14843. cl[1] = ((c0[1] * (splitYBy - row) + c2[1] * row) / splitYBy) | 0;
  14844. cl[2] = ((c0[2] * (splitYBy - row) + c2[2] * row) / splitYBy) | 0;
  14845. cr[0] = ((c1[0] * (splitYBy - row) + c3[0] * row) / splitYBy) | 0;
  14846. cr[1] = ((c1[1] * (splitYBy - row) + c3[1] * row) / splitYBy) | 0;
  14847. cr[2] = ((c1[2] * (splitYBy - row) + c3[2] * row) / splitYBy) | 0;
  14848. for (var col = 0; col <= splitXBy; col++, k++) {
  14849. if ((row === 0 || row === splitYBy) &&
  14850. (col === 0 || col === splitXBy)) {
  14851. continue;
  14852. }
  14853. var x = 0, y = 0;
  14854. var q = 0;
  14855. for (var i = 0; i <= 3; i++) {
  14856. for (var j = 0; j <= 3; j++, q++) {
  14857. var m = bRow[row][i] * bCol[col][j];
  14858. x += coords[pi[q]][0] * m;
  14859. y += coords[pi[q]][1] * m;
  14860. }
  14861. }
  14862. figureCoords[k] = coords.length;
  14863. coords.push([x, y]);
  14864. figureColors[k] = colors.length;
  14865. var newColor = new Uint8Array(3);
  14866. newColor[0] = ((cl[0] * (splitXBy - col) + cr[0] * col) / splitXBy) | 0;
  14867. newColor[1] = ((cl[1] * (splitXBy - col) + cr[1] * col) / splitXBy) | 0;
  14868. newColor[2] = ((cl[2] * (splitXBy - col) + cr[2] * col) / splitXBy) | 0;
  14869. colors.push(newColor);
  14870. }
  14871. }
  14872. figureCoords[0] = pi[0];
  14873. figureColors[0] = ci[0];
  14874. figureCoords[splitXBy] = pi[3];
  14875. figureColors[splitXBy] = ci[1];
  14876. figureCoords[verticesPerRow * splitYBy] = pi[12];
  14877. figureColors[verticesPerRow * splitYBy] = ci[2];
  14878. figureCoords[verticesPerRow * splitYBy + splitXBy] = pi[15];
  14879. figureColors[verticesPerRow * splitYBy + splitXBy] = ci[3];
  14880. mesh.figures[index] = {
  14881. type: 'lattice',
  14882. coords: figureCoords,
  14883. colors: figureColors,
  14884. verticesPerRow: verticesPerRow
  14885. };
  14886. }
  14887. function decodeType6Shading(mesh, reader) {
  14888. // A special case of Type 7. The p11, p12, p21, p22 automatically filled
  14889. var coords = mesh.coords;
  14890. var colors = mesh.colors;
  14891. var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
  14892. var cs = new Int32Array(4); // c00, c30, c03, c33
  14893. while (reader.hasData) {
  14894. var f = reader.readFlag();
  14895. assert(0 <= f && f <= 3, 'Unknown type6 flag');
  14896. var i, ii;
  14897. var pi = coords.length;
  14898. for (i = 0, ii = (f !== 0 ? 8 : 12); i < ii; i++) {
  14899. coords.push(reader.readCoordinate());
  14900. }
  14901. var ci = colors.length;
  14902. for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
  14903. colors.push(reader.readComponents());
  14904. }
  14905. var tmp1, tmp2, tmp3, tmp4;
  14906. switch (f) {
  14907. case 0:
  14908. ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
  14909. ps[ 8] = pi + 2; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 7;
  14910. ps[ 4] = pi + 1; /* calculated below */ ps[ 7] = pi + 8;
  14911. ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
  14912. cs[2] = ci + 1; cs[3] = ci + 2;
  14913. cs[0] = ci; cs[1] = ci + 3;
  14914. break;
  14915. case 1:
  14916. tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
  14917. ps[12] = pi + 5; ps[13] = pi + 4; ps[14] = pi + 3; ps[15] = pi + 2;
  14918. ps[ 8] = pi + 6; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 1;
  14919. ps[ 4] = pi + 7; /* calculated below */ ps[ 7] = pi;
  14920. ps[ 0] = tmp1; ps[ 1] = tmp2; ps[ 2] = tmp3; ps[ 3] = tmp4;
  14921. tmp1 = cs[2]; tmp2 = cs[3];
  14922. cs[2] = ci + 1; cs[3] = ci;
  14923. cs[0] = tmp1; cs[1] = tmp2;
  14924. break;
  14925. case 2:
  14926. ps[12] = ps[15]; ps[13] = pi + 7; ps[14] = pi + 6; ps[15] = pi + 5;
  14927. ps[ 8] = ps[11]; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 4;
  14928. ps[ 4] = ps[7]; /* calculated below */ ps[ 7] = pi + 3;
  14929. ps[ 0] = ps[3]; ps[ 1] = pi; ps[ 2] = pi + 1; ps[ 3] = pi + 2;
  14930. cs[2] = cs[3]; cs[3] = ci + 1;
  14931. cs[0] = cs[1]; cs[1] = ci;
  14932. break;
  14933. case 3:
  14934. ps[12] = ps[0]; ps[13] = ps[1]; ps[14] = ps[2]; ps[15] = ps[3];
  14935. ps[ 8] = pi; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 7;
  14936. ps[ 4] = pi + 1; /* calculated below */ ps[ 7] = pi + 6;
  14937. ps[ 0] = pi + 2; ps[ 1] = pi + 3; ps[ 2] = pi + 4; ps[ 3] = pi + 5;
  14938. cs[2] = cs[0]; cs[3] = cs[1];
  14939. cs[0] = ci; cs[1] = ci + 1;
  14940. break;
  14941. }
  14942. // set p11, p12, p21, p22
  14943. ps[5] = coords.length;
  14944. coords.push([
  14945. (-4 * coords[ps[0]][0] - coords[ps[15]][0] +
  14946. 6 * (coords[ps[4]][0] + coords[ps[1]][0]) -
  14947. 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
  14948. 3 * (coords[ps[13]][0] + coords[ps[7]][0])) / 9,
  14949. (-4 * coords[ps[0]][1] - coords[ps[15]][1] +
  14950. 6 * (coords[ps[4]][1] + coords[ps[1]][1]) -
  14951. 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
  14952. 3 * (coords[ps[13]][1] + coords[ps[7]][1])) / 9
  14953. ]);
  14954. ps[6] = coords.length;
  14955. coords.push([
  14956. (-4 * coords[ps[3]][0] - coords[ps[12]][0] +
  14957. 6 * (coords[ps[2]][0] + coords[ps[7]][0]) -
  14958. 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
  14959. 3 * (coords[ps[4]][0] + coords[ps[14]][0])) / 9,
  14960. (-4 * coords[ps[3]][1] - coords[ps[12]][1] +
  14961. 6 * (coords[ps[2]][1] + coords[ps[7]][1]) -
  14962. 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
  14963. 3 * (coords[ps[4]][1] + coords[ps[14]][1])) / 9
  14964. ]);
  14965. ps[9] = coords.length;
  14966. coords.push([
  14967. (-4 * coords[ps[12]][0] - coords[ps[3]][0] +
  14968. 6 * (coords[ps[8]][0] + coords[ps[13]][0]) -
  14969. 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
  14970. 3 * (coords[ps[11]][0] + coords[ps[1]][0])) / 9,
  14971. (-4 * coords[ps[12]][1] - coords[ps[3]][1] +
  14972. 6 * (coords[ps[8]][1] + coords[ps[13]][1]) -
  14973. 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
  14974. 3 * (coords[ps[11]][1] + coords[ps[1]][1])) / 9
  14975. ]);
  14976. ps[10] = coords.length;
  14977. coords.push([
  14978. (-4 * coords[ps[15]][0] - coords[ps[0]][0] +
  14979. 6 * (coords[ps[11]][0] + coords[ps[14]][0]) -
  14980. 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
  14981. 3 * (coords[ps[2]][0] + coords[ps[8]][0])) / 9,
  14982. (-4 * coords[ps[15]][1] - coords[ps[0]][1] +
  14983. 6 * (coords[ps[11]][1] + coords[ps[14]][1]) -
  14984. 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
  14985. 3 * (coords[ps[2]][1] + coords[ps[8]][1])) / 9
  14986. ]);
  14987. mesh.figures.push({
  14988. type: 'patch',
  14989. coords: new Int32Array(ps), // making copies of ps and cs
  14990. colors: new Int32Array(cs)
  14991. });
  14992. }
  14993. }
  14994. function decodeType7Shading(mesh, reader) {
  14995. var coords = mesh.coords;
  14996. var colors = mesh.colors;
  14997. var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
  14998. var cs = new Int32Array(4); // c00, c30, c03, c33
  14999. while (reader.hasData) {
  15000. var f = reader.readFlag();
  15001. assert(0 <= f && f <= 3, 'Unknown type7 flag');
  15002. var i, ii;
  15003. var pi = coords.length;
  15004. for (i = 0, ii = (f !== 0 ? 12 : 16); i < ii; i++) {
  15005. coords.push(reader.readCoordinate());
  15006. }
  15007. var ci = colors.length;
  15008. for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
  15009. colors.push(reader.readComponents());
  15010. }
  15011. var tmp1, tmp2, tmp3, tmp4;
  15012. switch (f) {
  15013. case 0:
  15014. ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
  15015. ps[ 8] = pi + 2; ps[ 9] = pi + 13; ps[10] = pi + 14; ps[11] = pi + 7;
  15016. ps[ 4] = pi + 1; ps[ 5] = pi + 12; ps[ 6] = pi + 15; ps[ 7] = pi + 8;
  15017. ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
  15018. cs[2] = ci + 1; cs[3] = ci + 2;
  15019. cs[0] = ci; cs[1] = ci + 3;
  15020. break;
  15021. case 1:
  15022. tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
  15023. ps[12] = pi + 5; ps[13] = pi + 4; ps[14] = pi + 3; ps[15] = pi + 2;
  15024. ps[ 8] = pi + 6; ps[ 9] = pi + 11; ps[10] = pi + 10; ps[11] = pi + 1;
  15025. ps[ 4] = pi + 7; ps[ 5] = pi + 8; ps[ 6] = pi + 9; ps[ 7] = pi;
  15026. ps[ 0] = tmp1; ps[ 1] = tmp2; ps[ 2] = tmp3; ps[ 3] = tmp4;
  15027. tmp1 = cs[2]; tmp2 = cs[3];
  15028. cs[2] = ci + 1; cs[3] = ci;
  15029. cs[0] = tmp1; cs[1] = tmp2;
  15030. break;
  15031. case 2:
  15032. ps[12] = ps[15]; ps[13] = pi + 7; ps[14] = pi + 6; ps[15] = pi + 5;
  15033. ps[ 8] = ps[11]; ps[ 9] = pi + 8; ps[10] = pi + 11; ps[11] = pi + 4;
  15034. ps[ 4] = ps[7]; ps[ 5] = pi + 9; ps[ 6] = pi + 10; ps[ 7] = pi + 3;
  15035. ps[ 0] = ps[3]; ps[ 1] = pi; ps[ 2] = pi + 1; ps[ 3] = pi + 2;
  15036. cs[2] = cs[3]; cs[3] = ci + 1;
  15037. cs[0] = cs[1]; cs[1] = ci;
  15038. break;
  15039. case 3:
  15040. ps[12] = ps[0]; ps[13] = ps[1]; ps[14] = ps[2]; ps[15] = ps[3];
  15041. ps[ 8] = pi; ps[ 9] = pi + 9; ps[10] = pi + 8; ps[11] = pi + 7;
  15042. ps[ 4] = pi + 1; ps[ 5] = pi + 10; ps[ 6] = pi + 11; ps[ 7] = pi + 6;
  15043. ps[ 0] = pi + 2; ps[ 1] = pi + 3; ps[ 2] = pi + 4; ps[ 3] = pi + 5;
  15044. cs[2] = cs[0]; cs[3] = cs[1];
  15045. cs[0] = ci; cs[1] = ci + 1;
  15046. break;
  15047. }
  15048. mesh.figures.push({
  15049. type: 'patch',
  15050. coords: new Int32Array(ps), // making copies of ps and cs
  15051. colors: new Int32Array(cs)
  15052. });
  15053. }
  15054. }
  15055. function updateBounds(mesh) {
  15056. var minX = mesh.coords[0][0], minY = mesh.coords[0][1],
  15057. maxX = minX, maxY = minY;
  15058. for (var i = 1, ii = mesh.coords.length; i < ii; i++) {
  15059. var x = mesh.coords[i][0], y = mesh.coords[i][1];
  15060. minX = minX > x ? x : minX;
  15061. minY = minY > y ? y : minY;
  15062. maxX = maxX < x ? x : maxX;
  15063. maxY = maxY < y ? y : maxY;
  15064. }
  15065. mesh.bounds = [minX, minY, maxX, maxY];
  15066. }
  15067. function packData(mesh) {
  15068. var i, ii, j, jj;
  15069. var coords = mesh.coords;
  15070. var coordsPacked = new Float32Array(coords.length * 2);
  15071. for (i = 0, j = 0, ii = coords.length; i < ii; i++) {
  15072. var xy = coords[i];
  15073. coordsPacked[j++] = xy[0];
  15074. coordsPacked[j++] = xy[1];
  15075. }
  15076. mesh.coords = coordsPacked;
  15077. var colors = mesh.colors;
  15078. var colorsPacked = new Uint8Array(colors.length * 3);
  15079. for (i = 0, j = 0, ii = colors.length; i < ii; i++) {
  15080. var c = colors[i];
  15081. colorsPacked[j++] = c[0];
  15082. colorsPacked[j++] = c[1];
  15083. colorsPacked[j++] = c[2];
  15084. }
  15085. mesh.colors = colorsPacked;
  15086. var figures = mesh.figures;
  15087. for (i = 0, ii = figures.length; i < ii; i++) {
  15088. var figure = figures[i], ps = figure.coords, cs = figure.colors;
  15089. for (j = 0, jj = ps.length; j < jj; j++) {
  15090. ps[j] *= 2;
  15091. cs[j] *= 3;
  15092. }
  15093. }
  15094. }
  15095. function Mesh(stream, matrix, xref, res) {
  15096. assert(isStream(stream), 'Mesh data is not a stream');
  15097. var dict = stream.dict;
  15098. this.matrix = matrix;
  15099. this.shadingType = dict.get('ShadingType');
  15100. this.type = 'Pattern';
  15101. this.bbox = dict.get('BBox');
  15102. var cs = dict.get('ColorSpace', 'CS');
  15103. cs = ColorSpace.parse(cs, xref, res);
  15104. this.cs = cs;
  15105. this.background = dict.has('Background') ?
  15106. cs.getRgb(dict.get('Background'), 0) : null;
  15107. var fnObj = dict.get('Function');
  15108. var fn = fnObj ? PDFFunction.parseArray(xref, fnObj) : null;
  15109. this.coords = [];
  15110. this.colors = [];
  15111. this.figures = [];
  15112. var decodeContext = {
  15113. bitsPerCoordinate: dict.get('BitsPerCoordinate'),
  15114. bitsPerComponent: dict.get('BitsPerComponent'),
  15115. bitsPerFlag: dict.get('BitsPerFlag'),
  15116. decode: dict.get('Decode'),
  15117. colorFn: fn,
  15118. colorSpace: cs,
  15119. numComps: fn ? 1 : cs.numComps
  15120. };
  15121. var reader = new MeshStreamReader(stream, decodeContext);
  15122. var patchMesh = false;
  15123. switch (this.shadingType) {
  15124. case PatternType.FREE_FORM_MESH:
  15125. decodeType4Shading(this, reader);
  15126. break;
  15127. case PatternType.LATTICE_FORM_MESH:
  15128. var verticesPerRow = dict.get('VerticesPerRow') | 0;
  15129. assert(verticesPerRow >= 2, 'Invalid VerticesPerRow');
  15130. decodeType5Shading(this, reader, verticesPerRow);
  15131. break;
  15132. case PatternType.COONS_PATCH_MESH:
  15133. decodeType6Shading(this, reader);
  15134. patchMesh = true;
  15135. break;
  15136. case PatternType.TENSOR_PATCH_MESH:
  15137. decodeType7Shading(this, reader);
  15138. patchMesh = true;
  15139. break;
  15140. default:
  15141. error('Unsupported mesh type.');
  15142. break;
  15143. }
  15144. if (patchMesh) {
  15145. // dirty bounds calculation for determining, how dense shall be triangles
  15146. updateBounds(this);
  15147. for (var i = 0, ii = this.figures.length; i < ii; i++) {
  15148. buildFigureFromPatch(this, i);
  15149. }
  15150. }
  15151. // calculate bounds
  15152. updateBounds(this);
  15153. packData(this);
  15154. }
  15155. Mesh.prototype = {
  15156. getIR: function Mesh_getIR() {
  15157. return ['Mesh', this.shadingType, this.coords, this.colors, this.figures,
  15158. this.bounds, this.matrix, this.bbox, this.background];
  15159. }
  15160. };
  15161. return Mesh;
  15162. })();
  15163. Shadings.Dummy = (function DummyClosure() {
  15164. function Dummy() {
  15165. this.type = 'Pattern';
  15166. }
  15167. Dummy.prototype = {
  15168. getIR: function Dummy_getIR() {
  15169. return ['Dummy'];
  15170. }
  15171. };
  15172. return Dummy;
  15173. })();
  15174. function getTilingPatternIR(operatorList, dict, args) {
  15175. var matrix = dict.get('Matrix');
  15176. var bbox = dict.get('BBox');
  15177. var xstep = dict.get('XStep');
  15178. var ystep = dict.get('YStep');
  15179. var paintType = dict.get('PaintType');
  15180. var tilingType = dict.get('TilingType');
  15181. return [
  15182. 'TilingPattern', args, operatorList, matrix, bbox, xstep, ystep,
  15183. paintType, tilingType
  15184. ];
  15185. }
  15186. var PartialEvaluator = (function PartialEvaluatorClosure() {
  15187. function PartialEvaluator(pdfManager, xref, handler, pageIndex,
  15188. uniquePrefix, idCounters, fontCache) {
  15189. this.pdfManager = pdfManager;
  15190. this.xref = xref;
  15191. this.handler = handler;
  15192. this.pageIndex = pageIndex;
  15193. this.uniquePrefix = uniquePrefix;
  15194. this.idCounters = idCounters;
  15195. this.fontCache = fontCache;
  15196. }
  15197. // Trying to minimize Date.now() usage and check every 100 time
  15198. var TIME_SLOT_DURATION_MS = 20;
  15199. var CHECK_TIME_EVERY = 100;
  15200. function TimeSlotManager() {
  15201. this.reset();
  15202. }
  15203. TimeSlotManager.prototype = {
  15204. check: function TimeSlotManager_check() {
  15205. if (++this.checked < CHECK_TIME_EVERY) {
  15206. return false;
  15207. }
  15208. this.checked = 0;
  15209. return this.endTime <= Date.now();
  15210. },
  15211. reset: function TimeSlotManager_reset() {
  15212. this.endTime = Date.now() + TIME_SLOT_DURATION_MS;
  15213. this.checked = 0;
  15214. }
  15215. };
  15216. var deferred = Promise.resolve();
  15217. var TILING_PATTERN = 1, SHADING_PATTERN = 2;
  15218. PartialEvaluator.prototype = {
  15219. hasBlendModes: function PartialEvaluator_hasBlendModes(resources) {
  15220. if (!isDict(resources)) {
  15221. return false;
  15222. }
  15223. var processed = Object.create(null);
  15224. if (resources.objId) {
  15225. processed[resources.objId] = true;
  15226. }
  15227. var nodes = [resources];
  15228. while (nodes.length) {
  15229. var key;
  15230. var node = nodes.shift();
  15231. // First check the current resources for blend modes.
  15232. var graphicStates = node.get('ExtGState');
  15233. if (isDict(graphicStates)) {
  15234. graphicStates = graphicStates.getAll();
  15235. for (key in graphicStates) {
  15236. var graphicState = graphicStates[key];
  15237. var bm = graphicState['BM'];
  15238. if (isName(bm) && bm.name !== 'Normal') {
  15239. return true;
  15240. }
  15241. }
  15242. }
  15243. // Descend into the XObjects to look for more resources and blend modes.
  15244. var xObjects = node.get('XObject');
  15245. if (!isDict(xObjects)) {
  15246. continue;
  15247. }
  15248. xObjects = xObjects.getAll();
  15249. for (key in xObjects) {
  15250. var xObject = xObjects[key];
  15251. if (!isStream(xObject)) {
  15252. continue;
  15253. }
  15254. if (xObject.dict.objId) {
  15255. if (processed[xObject.dict.objId]) {
  15256. // stream has objId and is processed already
  15257. continue;
  15258. }
  15259. processed[xObject.dict.objId] = true;
  15260. }
  15261. var xResources = xObject.dict.get('Resources');
  15262. // Checking objId to detect an infinite loop.
  15263. if (isDict(xResources) &&
  15264. (!xResources.objId || !processed[xResources.objId])) {
  15265. nodes.push(xResources);
  15266. if (xResources.objId) {
  15267. processed[xResources.objId] = true;
  15268. }
  15269. }
  15270. }
  15271. }
  15272. return false;
  15273. },
  15274. buildFormXObject: function PartialEvaluator_buildFormXObject(resources,
  15275. xobj, smask,
  15276. operatorList,
  15277. initialState) {
  15278. var matrix = xobj.dict.get('Matrix');
  15279. var bbox = xobj.dict.get('BBox');
  15280. var group = xobj.dict.get('Group');
  15281. if (group) {
  15282. var groupOptions = {
  15283. matrix: matrix,
  15284. bbox: bbox,
  15285. smask: smask,
  15286. isolated: false,
  15287. knockout: false
  15288. };
  15289. var groupSubtype = group.get('S');
  15290. var colorSpace;
  15291. if (isName(groupSubtype) && groupSubtype.name === 'Transparency') {
  15292. groupOptions.isolated = (group.get('I') || false);
  15293. groupOptions.knockout = (group.get('K') || false);
  15294. colorSpace = (group.has('CS') ?
  15295. ColorSpace.parse(group.get('CS'), this.xref, resources) : null);
  15296. }
  15297. if (smask && smask.backdrop) {
  15298. colorSpace = colorSpace || ColorSpace.singletons.rgb;
  15299. smask.backdrop = colorSpace.getRgb(smask.backdrop, 0);
  15300. }
  15301. operatorList.addOp(OPS.beginGroup, [groupOptions]);
  15302. }
  15303. operatorList.addOp(OPS.paintFormXObjectBegin, [matrix, bbox]);
  15304. return this.getOperatorList(xobj,
  15305. (xobj.dict.get('Resources') || resources), operatorList, initialState).
  15306. then(function () {
  15307. operatorList.addOp(OPS.paintFormXObjectEnd, []);
  15308. if (group) {
  15309. operatorList.addOp(OPS.endGroup, [groupOptions]);
  15310. }
  15311. });
  15312. },
  15313. buildPaintImageXObject:
  15314. function PartialEvaluator_buildPaintImageXObject(resources, image,
  15315. inline, operatorList,
  15316. cacheKey, imageCache) {
  15317. var self = this;
  15318. var dict = image.dict;
  15319. var w = dict.get('Width', 'W');
  15320. var h = dict.get('Height', 'H');
  15321. if (!(w && isNum(w)) || !(h && isNum(h))) {
  15322. warn('Image dimensions are missing, or not numbers.');
  15323. return;
  15324. }
  15325. if (PDFJS.maxImageSize !== -1 && w * h > PDFJS.maxImageSize) {
  15326. warn('Image exceeded maximum allowed size and was removed.');
  15327. return;
  15328. }
  15329. var imageMask = (dict.get('ImageMask', 'IM') || false);
  15330. var imgData, args;
  15331. if (imageMask) {
  15332. // This depends on a tmpCanvas being filled with the
  15333. // current fillStyle, such that processing the pixel
  15334. // data can't be done here. Instead of creating a
  15335. // complete PDFImage, only read the information needed
  15336. // for later.
  15337. var width = dict.get('Width', 'W');
  15338. var height = dict.get('Height', 'H');
  15339. var bitStrideLength = (width + 7) >> 3;
  15340. var imgArray = image.getBytes(bitStrideLength * height);
  15341. var decode = dict.get('Decode', 'D');
  15342. var inverseDecode = (!!decode && decode[0] > 0);
  15343. imgData = PDFImage.createMask(imgArray, width, height,
  15344. image instanceof DecodeStream,
  15345. inverseDecode);
  15346. imgData.cached = true;
  15347. args = [imgData];
  15348. operatorList.addOp(OPS.paintImageMaskXObject, args);
  15349. if (cacheKey) {
  15350. imageCache[cacheKey] = {
  15351. fn: OPS.paintImageMaskXObject,
  15352. args: args
  15353. };
  15354. }
  15355. return;
  15356. }
  15357. var softMask = (dict.get('SMask', 'SM') || false);
  15358. var mask = (dict.get('Mask') || false);
  15359. var SMALL_IMAGE_DIMENSIONS = 200;
  15360. // Inlining small images into the queue as RGB data
  15361. if (inline && !softMask && !mask && !(image instanceof JpegStream) &&
  15362. (w + h) < SMALL_IMAGE_DIMENSIONS) {
  15363. var imageObj = new PDFImage(this.xref, resources, image,
  15364. inline, null, null);
  15365. // We force the use of RGBA_32BPP images here, because we can't handle
  15366. // any other kind.
  15367. imgData = imageObj.createImageData(/* forceRGBA = */ true);
  15368. operatorList.addOp(OPS.paintInlineImageXObject, [imgData]);
  15369. return;
  15370. }
  15371. // If there is no imageMask, create the PDFImage and a lot
  15372. // of image processing can be done here.
  15373. var uniquePrefix = (this.uniquePrefix || '');
  15374. var objId = 'img_' + uniquePrefix + (++this.idCounters.obj);
  15375. operatorList.addDependency(objId);
  15376. args = [objId, w, h];
  15377. if (!softMask && !mask && image instanceof JpegStream &&
  15378. image.isNativelySupported(this.xref, resources)) {
  15379. // These JPEGs don't need any more processing so we can just send it.
  15380. operatorList.addOp(OPS.paintJpegXObject, args);
  15381. this.handler.send('obj',
  15382. [objId, this.pageIndex, 'JpegStream', image.getIR()]);
  15383. return;
  15384. }
  15385. PDFImage.buildImage(self.handler, self.xref, resources, image, inline).
  15386. then(function(imageObj) {
  15387. var imgData = imageObj.createImageData(/* forceRGBA = */ false);
  15388. self.handler.send('obj', [objId, self.pageIndex, 'Image', imgData],
  15389. [imgData.data.buffer]);
  15390. }).then(undefined, function (reason) {
  15391. warn('Unable to decode image: ' + reason);
  15392. self.handler.send('obj', [objId, self.pageIndex, 'Image', null]);
  15393. });
  15394. operatorList.addOp(OPS.paintImageXObject, args);
  15395. if (cacheKey) {
  15396. imageCache[cacheKey] = {
  15397. fn: OPS.paintImageXObject,
  15398. args: args
  15399. };
  15400. }
  15401. },
  15402. handleSMask: function PartialEvaluator_handleSmask(smask, resources,
  15403. operatorList,
  15404. stateManager) {
  15405. var smaskContent = smask.get('G');
  15406. var smaskOptions = {
  15407. subtype: smask.get('S').name,
  15408. backdrop: smask.get('BC')
  15409. };
  15410. return this.buildFormXObject(resources, smaskContent, smaskOptions,
  15411. operatorList, stateManager.state.clone());
  15412. },
  15413. handleTilingType:
  15414. function PartialEvaluator_handleTilingType(fn, args, resources,
  15415. pattern, patternDict,
  15416. operatorList) {
  15417. // Create an IR of the pattern code.
  15418. var tilingOpList = new OperatorList();
  15419. return this.getOperatorList(pattern,
  15420. (patternDict.get('Resources') || resources), tilingOpList).
  15421. then(function () {
  15422. // Add the dependencies to the parent operator list so they are
  15423. // resolved before sub operator list is executed synchronously.
  15424. operatorList.addDependencies(tilingOpList.dependencies);
  15425. operatorList.addOp(fn, getTilingPatternIR({
  15426. fnArray: tilingOpList.fnArray,
  15427. argsArray: tilingOpList.argsArray
  15428. }, patternDict, args));
  15429. });
  15430. },
  15431. handleSetFont:
  15432. function PartialEvaluator_handleSetFont(resources, fontArgs, fontRef,
  15433. operatorList, state) {
  15434. // TODO(mack): Not needed?
  15435. var fontName;
  15436. if (fontArgs) {
  15437. fontArgs = fontArgs.slice();
  15438. fontName = fontArgs[0].name;
  15439. }
  15440. var self = this;
  15441. return this.loadFont(fontName, fontRef, this.xref, resources).then(
  15442. function (translated) {
  15443. if (!translated.font.isType3Font) {
  15444. return translated;
  15445. }
  15446. return translated.loadType3Data(self, resources, operatorList).then(
  15447. function () {
  15448. return translated;
  15449. });
  15450. }).then(function (translated) {
  15451. state.font = translated.font;
  15452. translated.send(self.handler);
  15453. return translated.loadedName;
  15454. });
  15455. },
  15456. handleText: function PartialEvaluator_handleText(chars, state) {
  15457. var font = state.font;
  15458. var glyphs = font.charsToGlyphs(chars);
  15459. var isAddToPathSet = !!(state.textRenderingMode &
  15460. TextRenderingMode.ADD_TO_PATH_FLAG);
  15461. if (font.data && (isAddToPathSet || PDFJS.disableFontFace)) {
  15462. var buildPath = function (fontChar) {
  15463. if (!font.renderer.hasBuiltPath(fontChar)) {
  15464. var path = font.renderer.getPathJs(fontChar);
  15465. this.handler.send('commonobj', [
  15466. font.loadedName + '_path_' + fontChar,
  15467. 'FontPath',
  15468. path
  15469. ]);
  15470. }
  15471. }.bind(this);
  15472. for (var i = 0, ii = glyphs.length; i < ii; i++) {
  15473. var glyph = glyphs[i];
  15474. if (glyph === null) {
  15475. continue;
  15476. }
  15477. buildPath(glyph.fontChar);
  15478. // If the glyph has an accent we need to build a path for its
  15479. // fontChar too, otherwise CanvasGraphics_paintChar will fail.
  15480. var accent = glyph.accent;
  15481. if (accent && accent.fontChar) {
  15482. buildPath(accent.fontChar);
  15483. }
  15484. }
  15485. }
  15486. return glyphs;
  15487. },
  15488. setGState: function PartialEvaluator_setGState(resources, gState,
  15489. operatorList, xref,
  15490. stateManager) {
  15491. // This array holds the converted/processed state data.
  15492. var gStateObj = [];
  15493. var gStateMap = gState.map;
  15494. var self = this;
  15495. var promise = Promise.resolve();
  15496. for (var key in gStateMap) {
  15497. var value = gStateMap[key];
  15498. switch (key) {
  15499. case 'Type':
  15500. break;
  15501. case 'LW':
  15502. case 'LC':
  15503. case 'LJ':
  15504. case 'ML':
  15505. case 'D':
  15506. case 'RI':
  15507. case 'FL':
  15508. case 'CA':
  15509. case 'ca':
  15510. gStateObj.push([key, value]);
  15511. break;
  15512. case 'Font':
  15513. promise = promise.then(function () {
  15514. return self.handleSetFont(resources, null, value[0],
  15515. operatorList, stateManager.state).
  15516. then(function (loadedName) {
  15517. operatorList.addDependency(loadedName);
  15518. gStateObj.push([key, [loadedName, value[1]]]);
  15519. });
  15520. });
  15521. break;
  15522. case 'BM':
  15523. gStateObj.push([key, value]);
  15524. break;
  15525. case 'SMask':
  15526. if (isName(value) && value.name === 'None') {
  15527. gStateObj.push([key, false]);
  15528. break;
  15529. }
  15530. var dict = xref.fetchIfRef(value);
  15531. if (isDict(dict)) {
  15532. promise = promise.then(function () {
  15533. return self.handleSMask(dict, resources, operatorList,
  15534. stateManager);
  15535. });
  15536. gStateObj.push([key, true]);
  15537. } else {
  15538. warn('Unsupported SMask type');
  15539. }
  15540. break;
  15541. // Only generate info log messages for the following since
  15542. // they are unlikely to have a big impact on the rendering.
  15543. case 'OP':
  15544. case 'op':
  15545. case 'OPM':
  15546. case 'BG':
  15547. case 'BG2':
  15548. case 'UCR':
  15549. case 'UCR2':
  15550. case 'TR':
  15551. case 'TR2':
  15552. case 'HT':
  15553. case 'SM':
  15554. case 'SA':
  15555. case 'AIS':
  15556. case 'TK':
  15557. // TODO implement these operators.
  15558. info('graphic state operator ' + key);
  15559. break;
  15560. default:
  15561. info('Unknown graphic state operator ' + key);
  15562. break;
  15563. }
  15564. }
  15565. return promise.then(function () {
  15566. if (gStateObj.length >= 0) {
  15567. operatorList.addOp(OPS.setGState, [gStateObj]);
  15568. }
  15569. });
  15570. },
  15571. loadFont: function PartialEvaluator_loadFont(fontName, font, xref,
  15572. resources) {
  15573. function errorFont() {
  15574. return Promise.resolve(new TranslatedFont('g_font_error',
  15575. new ErrorFont('Font ' + fontName + ' is not available'), font));
  15576. }
  15577. var fontRef;
  15578. if (font) { // Loading by ref.
  15579. assert(isRef(font));
  15580. fontRef = font;
  15581. } else { // Loading by name.
  15582. var fontRes = resources.get('Font');
  15583. if (fontRes) {
  15584. fontRef = fontRes.getRaw(fontName);
  15585. } else {
  15586. warn('fontRes not available');
  15587. return errorFont();
  15588. }
  15589. }
  15590. if (!fontRef) {
  15591. warn('fontRef not available');
  15592. return errorFont();
  15593. }
  15594. if (this.fontCache.has(fontRef)) {
  15595. return this.fontCache.get(fontRef);
  15596. }
  15597. font = xref.fetchIfRef(fontRef);
  15598. if (!isDict(font)) {
  15599. return errorFont();
  15600. }
  15601. // We are holding font.translated references just for fontRef that are not
  15602. // dictionaries (Dict). See explanation below.
  15603. if (font.translated) {
  15604. return font.translated;
  15605. }
  15606. var fontCapability = createPromiseCapability();
  15607. var preEvaluatedFont = this.preEvaluateFont(font, xref);
  15608. var descriptor = preEvaluatedFont.descriptor;
  15609. var fontID = fontRef.num + '_' + fontRef.gen;
  15610. if (isDict(descriptor)) {
  15611. if (!descriptor.fontAliases) {
  15612. descriptor.fontAliases = Object.create(null);
  15613. }
  15614. var fontAliases = descriptor.fontAliases;
  15615. var hash = preEvaluatedFont.hash;
  15616. if (fontAliases[hash]) {
  15617. var aliasFontRef = fontAliases[hash].aliasRef;
  15618. if (aliasFontRef && this.fontCache.has(aliasFontRef)) {
  15619. this.fontCache.putAlias(fontRef, aliasFontRef);
  15620. return this.fontCache.get(fontRef);
  15621. }
  15622. }
  15623. if (!fontAliases[hash]) {
  15624. fontAliases[hash] = {
  15625. fontID: Font.getFontID()
  15626. };
  15627. }
  15628. fontAliases[hash].aliasRef = fontRef;
  15629. fontID = fontAliases[hash].fontID;
  15630. }
  15631. // Workaround for bad PDF generators that don't reference fonts
  15632. // properly, i.e. by not using an object identifier.
  15633. // Check if the fontRef is a Dict (as opposed to a standard object),
  15634. // in which case we don't cache the font and instead reference it by
  15635. // fontName in font.loadedName below.
  15636. var fontRefIsDict = isDict(fontRef);
  15637. if (!fontRefIsDict) {
  15638. this.fontCache.put(fontRef, fontCapability.promise);
  15639. }
  15640. // Keep track of each font we translated so the caller can
  15641. // load them asynchronously before calling display on a page.
  15642. font.loadedName = 'g_font_' + (fontRefIsDict ?
  15643. fontName.replace(/\W/g, '') : fontID);
  15644. font.translated = fontCapability.promise;
  15645. // TODO move promises into translate font
  15646. var translatedPromise;
  15647. try {
  15648. translatedPromise = Promise.resolve(
  15649. this.translateFont(preEvaluatedFont, xref));
  15650. } catch (e) {
  15651. translatedPromise = Promise.reject(e);
  15652. }
  15653. translatedPromise.then(function (translatedFont) {
  15654. if (translatedFont.fontType !== undefined) {
  15655. var xrefFontStats = xref.stats.fontTypes;
  15656. xrefFontStats[translatedFont.fontType] = true;
  15657. }
  15658. fontCapability.resolve(new TranslatedFont(font.loadedName,
  15659. translatedFont, font));
  15660. }, function (reason) {
  15661. // TODO fontCapability.reject?
  15662. UnsupportedManager.notify(UNSUPPORTED_FEATURES.font);
  15663. try {
  15664. // error, but it's still nice to have font type reported
  15665. var descriptor = preEvaluatedFont.descriptor;
  15666. var fontFile3 = descriptor && descriptor.get('FontFile3');
  15667. var subtype = fontFile3 && fontFile3.get('Subtype');
  15668. var fontType = getFontType(preEvaluatedFont.type,
  15669. subtype && subtype.name);
  15670. var xrefFontStats = xref.stats.fontTypes;
  15671. xrefFontStats[fontType] = true;
  15672. } catch (ex) { }
  15673. fontCapability.resolve(new TranslatedFont(font.loadedName,
  15674. new ErrorFont(reason instanceof Error ? reason.message : reason),
  15675. font));
  15676. });
  15677. return fontCapability.promise;
  15678. },
  15679. buildPath: function PartialEvaluator_buildPath(operatorList, fn, args) {
  15680. var lastIndex = operatorList.length - 1;
  15681. if (!args) {
  15682. args = [];
  15683. }
  15684. if (lastIndex < 0 ||
  15685. operatorList.fnArray[lastIndex] !== OPS.constructPath) {
  15686. operatorList.addOp(OPS.constructPath, [[fn], args]);
  15687. } else {
  15688. var opArgs = operatorList.argsArray[lastIndex];
  15689. opArgs[0].push(fn);
  15690. Array.prototype.push.apply(opArgs[1], args);
  15691. }
  15692. },
  15693. handleColorN: function PartialEvaluator_handleColorN(operatorList, fn, args,
  15694. cs, patterns, resources, xref) {
  15695. // compile tiling patterns
  15696. var patternName = args[args.length - 1];
  15697. // SCN/scn applies patterns along with normal colors
  15698. var pattern;
  15699. if (isName(patternName) &&
  15700. (pattern = patterns.get(patternName.name))) {
  15701. var dict = (isStream(pattern) ? pattern.dict : pattern);
  15702. var typeNum = dict.get('PatternType');
  15703. if (typeNum === TILING_PATTERN) {
  15704. var color = cs.base ? cs.base.getRgb(args, 0) : null;
  15705. return this.handleTilingType(fn, color, resources, pattern,
  15706. dict, operatorList);
  15707. } else if (typeNum === SHADING_PATTERN) {
  15708. var shading = dict.get('Shading');
  15709. var matrix = dict.get('Matrix');
  15710. pattern = Pattern.parseShading(shading, matrix, xref, resources);
  15711. operatorList.addOp(fn, pattern.getIR());
  15712. return Promise.resolve();
  15713. } else {
  15714. return Promise.reject('Unknown PatternType: ' + typeNum);
  15715. }
  15716. }
  15717. // TODO shall we fail here?
  15718. operatorList.addOp(fn, args);
  15719. return Promise.resolve();
  15720. },
  15721. getOperatorList: function PartialEvaluator_getOperatorList(stream,
  15722. resources,
  15723. operatorList,
  15724. initialState) {
  15725. var self = this;
  15726. var xref = this.xref;
  15727. var imageCache = {};
  15728. assert(operatorList);
  15729. resources = (resources || Dict.empty);
  15730. var xobjs = (resources.get('XObject') || Dict.empty);
  15731. var patterns = (resources.get('Pattern') || Dict.empty);
  15732. var stateManager = new StateManager(initialState || new EvalState());
  15733. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  15734. var timeSlotManager = new TimeSlotManager();
  15735. return new Promise(function next(resolve, reject) {
  15736. timeSlotManager.reset();
  15737. var stop, operation = {}, i, ii, cs;
  15738. while (!(stop = timeSlotManager.check())) {
  15739. // The arguments parsed by read() are used beyond this loop, so we
  15740. // cannot reuse the same array on each iteration. Therefore we pass
  15741. // in |null| as the initial value (see the comment on
  15742. // EvaluatorPreprocessor_read() for why).
  15743. operation.args = null;
  15744. if (!(preprocessor.read(operation))) {
  15745. break;
  15746. }
  15747. var args = operation.args;
  15748. var fn = operation.fn;
  15749. switch (fn | 0) {
  15750. case OPS.paintXObject:
  15751. if (args[0].code) {
  15752. break;
  15753. }
  15754. // eagerly compile XForm objects
  15755. var name = args[0].name;
  15756. if (imageCache[name] !== undefined) {
  15757. operatorList.addOp(imageCache[name].fn, imageCache[name].args);
  15758. args = null;
  15759. continue;
  15760. }
  15761. var xobj = xobjs.get(name);
  15762. if (xobj) {
  15763. assert(isStream(xobj), 'XObject should be a stream');
  15764. var type = xobj.dict.get('Subtype');
  15765. assert(isName(type),
  15766. 'XObject should have a Name subtype');
  15767. if (type.name === 'Form') {
  15768. stateManager.save();
  15769. return self.buildFormXObject(resources, xobj, null,
  15770. operatorList,
  15771. stateManager.state.clone()).
  15772. then(function () {
  15773. stateManager.restore();
  15774. next(resolve, reject);
  15775. }, reject);
  15776. } else if (type.name === 'Image') {
  15777. self.buildPaintImageXObject(resources, xobj, false,
  15778. operatorList, name, imageCache);
  15779. args = null;
  15780. continue;
  15781. } else if (type.name === 'PS') {
  15782. // PostScript XObjects are unused when viewing documents.
  15783. // See section 4.7.1 of Adobe's PDF reference.
  15784. info('Ignored XObject subtype PS');
  15785. continue;
  15786. } else {
  15787. error('Unhandled XObject subtype ' + type.name);
  15788. }
  15789. }
  15790. break;
  15791. case OPS.setFont:
  15792. var fontSize = args[1];
  15793. // eagerly collect all fonts
  15794. return self.handleSetFont(resources, args, null,
  15795. operatorList, stateManager.state).
  15796. then(function (loadedName) {
  15797. operatorList.addDependency(loadedName);
  15798. operatorList.addOp(OPS.setFont, [loadedName, fontSize]);
  15799. next(resolve, reject);
  15800. }, reject);
  15801. case OPS.endInlineImage:
  15802. var cacheKey = args[0].cacheKey;
  15803. if (cacheKey) {
  15804. var cacheEntry = imageCache[cacheKey];
  15805. if (cacheEntry !== undefined) {
  15806. operatorList.addOp(cacheEntry.fn, cacheEntry.args);
  15807. args = null;
  15808. continue;
  15809. }
  15810. }
  15811. self.buildPaintImageXObject(resources, args[0], true,
  15812. operatorList, cacheKey, imageCache);
  15813. args = null;
  15814. continue;
  15815. case OPS.showText:
  15816. args[0] = self.handleText(args[0], stateManager.state);
  15817. break;
  15818. case OPS.showSpacedText:
  15819. var arr = args[0];
  15820. var combinedGlyphs = [];
  15821. var arrLength = arr.length;
  15822. for (i = 0; i < arrLength; ++i) {
  15823. var arrItem = arr[i];
  15824. if (isString(arrItem)) {
  15825. Array.prototype.push.apply(combinedGlyphs,
  15826. self.handleText(arrItem, stateManager.state));
  15827. } else if (isNum(arrItem)) {
  15828. combinedGlyphs.push(arrItem);
  15829. }
  15830. }
  15831. args[0] = combinedGlyphs;
  15832. fn = OPS.showText;
  15833. break;
  15834. case OPS.nextLineShowText:
  15835. operatorList.addOp(OPS.nextLine);
  15836. args[0] = self.handleText(args[0], stateManager.state);
  15837. fn = OPS.showText;
  15838. break;
  15839. case OPS.nextLineSetSpacingShowText:
  15840. operatorList.addOp(OPS.nextLine);
  15841. operatorList.addOp(OPS.setWordSpacing, [args.shift()]);
  15842. operatorList.addOp(OPS.setCharSpacing, [args.shift()]);
  15843. args[0] = self.handleText(args[0], stateManager.state);
  15844. fn = OPS.showText;
  15845. break;
  15846. case OPS.setTextRenderingMode:
  15847. stateManager.state.textRenderingMode = args[0];
  15848. break;
  15849. case OPS.setFillColorSpace:
  15850. stateManager.state.fillColorSpace =
  15851. ColorSpace.parse(args[0], xref, resources);
  15852. continue;
  15853. case OPS.setStrokeColorSpace:
  15854. stateManager.state.strokeColorSpace =
  15855. ColorSpace.parse(args[0], xref, resources);
  15856. continue;
  15857. case OPS.setFillColor:
  15858. cs = stateManager.state.fillColorSpace;
  15859. args = cs.getRgb(args, 0);
  15860. fn = OPS.setFillRGBColor;
  15861. break;
  15862. case OPS.setStrokeColor:
  15863. cs = stateManager.state.strokeColorSpace;
  15864. args = cs.getRgb(args, 0);
  15865. fn = OPS.setStrokeRGBColor;
  15866. break;
  15867. case OPS.setFillGray:
  15868. stateManager.state.fillColorSpace = ColorSpace.singletons.gray;
  15869. args = ColorSpace.singletons.gray.getRgb(args, 0);
  15870. fn = OPS.setFillRGBColor;
  15871. break;
  15872. case OPS.setStrokeGray:
  15873. stateManager.state.strokeColorSpace = ColorSpace.singletons.gray;
  15874. args = ColorSpace.singletons.gray.getRgb(args, 0);
  15875. fn = OPS.setStrokeRGBColor;
  15876. break;
  15877. case OPS.setFillCMYKColor:
  15878. stateManager.state.fillColorSpace = ColorSpace.singletons.cmyk;
  15879. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  15880. fn = OPS.setFillRGBColor;
  15881. break;
  15882. case OPS.setStrokeCMYKColor:
  15883. stateManager.state.strokeColorSpace = ColorSpace.singletons.cmyk;
  15884. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  15885. fn = OPS.setStrokeRGBColor;
  15886. break;
  15887. case OPS.setFillRGBColor:
  15888. stateManager.state.fillColorSpace = ColorSpace.singletons.rgb;
  15889. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  15890. break;
  15891. case OPS.setStrokeRGBColor:
  15892. stateManager.state.strokeColorSpace = ColorSpace.singletons.rgb;
  15893. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  15894. break;
  15895. case OPS.setFillColorN:
  15896. cs = stateManager.state.fillColorSpace;
  15897. if (cs.name === 'Pattern') {
  15898. return self.handleColorN(operatorList, OPS.setFillColorN,
  15899. args, cs, patterns, resources, xref).then(function() {
  15900. next(resolve, reject);
  15901. }, reject);
  15902. }
  15903. args = cs.getRgb(args, 0);
  15904. fn = OPS.setFillRGBColor;
  15905. break;
  15906. case OPS.setStrokeColorN:
  15907. cs = stateManager.state.strokeColorSpace;
  15908. if (cs.name === 'Pattern') {
  15909. return self.handleColorN(operatorList, OPS.setStrokeColorN,
  15910. args, cs, patterns, resources, xref).then(function() {
  15911. next(resolve, reject);
  15912. }, reject);
  15913. }
  15914. args = cs.getRgb(args, 0);
  15915. fn = OPS.setStrokeRGBColor;
  15916. break;
  15917. case OPS.shadingFill:
  15918. var shadingRes = resources.get('Shading');
  15919. if (!shadingRes) {
  15920. error('No shading resource found');
  15921. }
  15922. var shading = shadingRes.get(args[0].name);
  15923. if (!shading) {
  15924. error('No shading object found');
  15925. }
  15926. var shadingFill = Pattern.parseShading(shading, null, xref,
  15927. resources);
  15928. var patternIR = shadingFill.getIR();
  15929. args = [patternIR];
  15930. fn = OPS.shadingFill;
  15931. break;
  15932. case OPS.setGState:
  15933. var dictName = args[0];
  15934. var extGState = resources.get('ExtGState');
  15935. if (!isDict(extGState) || !extGState.has(dictName.name)) {
  15936. break;
  15937. }
  15938. var gState = extGState.get(dictName.name);
  15939. return self.setGState(resources, gState, operatorList, xref,
  15940. stateManager).then(function() {
  15941. next(resolve, reject);
  15942. }, reject);
  15943. case OPS.moveTo:
  15944. case OPS.lineTo:
  15945. case OPS.curveTo:
  15946. case OPS.curveTo2:
  15947. case OPS.curveTo3:
  15948. case OPS.closePath:
  15949. self.buildPath(operatorList, fn, args);
  15950. continue;
  15951. case OPS.rectangle:
  15952. self.buildPath(operatorList, fn, args);
  15953. continue;
  15954. }
  15955. operatorList.addOp(fn, args);
  15956. }
  15957. if (stop) {
  15958. deferred.then(function () {
  15959. next(resolve, reject);
  15960. });
  15961. return;
  15962. }
  15963. // Some PDFs don't close all restores inside object/form.
  15964. // Closing those for them.
  15965. for (i = 0, ii = preprocessor.savedStatesDepth; i < ii; i++) {
  15966. operatorList.addOp(OPS.restore, []);
  15967. }
  15968. resolve();
  15969. });
  15970. },
  15971. getTextContent: function PartialEvaluator_getTextContent(stream, resources,
  15972. stateManager) {
  15973. stateManager = (stateManager || new StateManager(new TextState()));
  15974. var textContent = {
  15975. items: [],
  15976. styles: Object.create(null)
  15977. };
  15978. var bidiTexts = textContent.items;
  15979. var SPACE_FACTOR = 0.3;
  15980. var MULTI_SPACE_FACTOR = 1.5;
  15981. var self = this;
  15982. var xref = this.xref;
  15983. resources = (xref.fetchIfRef(resources) || Dict.empty);
  15984. // The xobj is parsed iff it's needed, e.g. if there is a `DO` cmd.
  15985. var xobjs = null;
  15986. var xobjsCache = {};
  15987. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  15988. var textState;
  15989. function newTextChunk() {
  15990. var font = textState.font;
  15991. if (!(font.loadedName in textContent.styles)) {
  15992. textContent.styles[font.loadedName] = {
  15993. fontFamily: font.fallbackName,
  15994. ascent: font.ascent,
  15995. descent: font.descent,
  15996. vertical: font.vertical
  15997. };
  15998. }
  15999. return {
  16000. // |str| is initially an array which we push individual chars to, and
  16001. // then runBidi() overwrites it with the final string.
  16002. str: [],
  16003. dir: null,
  16004. width: 0,
  16005. height: 0,
  16006. transform: null,
  16007. fontName: font.loadedName
  16008. };
  16009. }
  16010. function runBidi(textChunk) {
  16011. var str = textChunk.str.join('');
  16012. var bidiResult = PDFJS.bidi(str, -1, textState.font.vertical);
  16013. textChunk.str = bidiResult.str;
  16014. textChunk.dir = bidiResult.dir;
  16015. return textChunk;
  16016. }
  16017. function handleSetFont(fontName, fontRef) {
  16018. return self.loadFont(fontName, fontRef, xref, resources).
  16019. then(function (translated) {
  16020. textState.font = translated.font;
  16021. textState.fontMatrix = translated.font.fontMatrix ||
  16022. FONT_IDENTITY_MATRIX;
  16023. });
  16024. }
  16025. function buildTextGeometry(chars, textChunk) {
  16026. var font = textState.font;
  16027. textChunk = textChunk || newTextChunk();
  16028. if (!textChunk.transform) {
  16029. // 9.4.4 Text Space Details
  16030. var tsm = [textState.fontSize * textState.textHScale, 0,
  16031. 0, textState.fontSize,
  16032. 0, textState.textRise];
  16033. var trm = textChunk.transform = Util.transform(textState.ctm,
  16034. Util.transform(textState.textMatrix, tsm));
  16035. if (!font.vertical) {
  16036. textChunk.height = Math.sqrt(trm[2] * trm[2] + trm[3] * trm[3]);
  16037. } else {
  16038. textChunk.width = Math.sqrt(trm[0] * trm[0] + trm[1] * trm[1]);
  16039. }
  16040. }
  16041. var width = 0;
  16042. var height = 0;
  16043. var glyphs = font.charsToGlyphs(chars);
  16044. var defaultVMetrics = font.defaultVMetrics;
  16045. for (var i = 0; i < glyphs.length; i++) {
  16046. var glyph = glyphs[i];
  16047. if (!glyph) { // Previous glyph was a space.
  16048. width += textState.wordSpacing * textState.textHScale;
  16049. continue;
  16050. }
  16051. var vMetricX = null;
  16052. var vMetricY = null;
  16053. var glyphWidth = null;
  16054. if (font.vertical) {
  16055. if (glyph.vmetric) {
  16056. glyphWidth = glyph.vmetric[0];
  16057. vMetricX = glyph.vmetric[1];
  16058. vMetricY = glyph.vmetric[2];
  16059. } else {
  16060. glyphWidth = glyph.width;
  16061. vMetricX = glyph.width * 0.5;
  16062. vMetricY = defaultVMetrics[2];
  16063. }
  16064. } else {
  16065. glyphWidth = glyph.width;
  16066. }
  16067. var glyphUnicode = glyph.unicode;
  16068. if (NormalizedUnicodes[glyphUnicode] !== undefined) {
  16069. glyphUnicode = NormalizedUnicodes[glyphUnicode];
  16070. }
  16071. glyphUnicode = reverseIfRtl(glyphUnicode);
  16072. // The following will calculate the x and y of the individual glyphs.
  16073. // if (font.vertical) {
  16074. // tsm[4] -= vMetricX * Math.abs(textState.fontSize) *
  16075. // textState.fontMatrix[0];
  16076. // tsm[5] -= vMetricY * textState.fontSize *
  16077. // textState.fontMatrix[0];
  16078. // }
  16079. // var trm = Util.transform(textState.textMatrix, tsm);
  16080. // var pt = Util.applyTransform([trm[4], trm[5]], textState.ctm);
  16081. // var x = pt[0];
  16082. // var y = pt[1];
  16083. var tx = 0;
  16084. var ty = 0;
  16085. if (!font.vertical) {
  16086. var w0 = glyphWidth * textState.fontMatrix[0];
  16087. tx = (w0 * textState.fontSize + textState.charSpacing) *
  16088. textState.textHScale;
  16089. width += tx;
  16090. } else {
  16091. var w1 = glyphWidth * textState.fontMatrix[0];
  16092. ty = w1 * textState.fontSize + textState.charSpacing;
  16093. height += ty;
  16094. }
  16095. textState.translateTextMatrix(tx, ty);
  16096. textChunk.str.push(glyphUnicode);
  16097. }
  16098. var a = textState.textLineMatrix[0];
  16099. var b = textState.textLineMatrix[1];
  16100. var scaleLineX = Math.sqrt(a * a + b * b);
  16101. a = textState.ctm[0];
  16102. b = textState.ctm[1];
  16103. var scaleCtmX = Math.sqrt(a * a + b * b);
  16104. if (!font.vertical) {
  16105. textChunk.width += width * scaleCtmX * scaleLineX;
  16106. } else {
  16107. textChunk.height += Math.abs(height * scaleCtmX * scaleLineX);
  16108. }
  16109. return textChunk;
  16110. }
  16111. var timeSlotManager = new TimeSlotManager();
  16112. return new Promise(function next(resolve, reject) {
  16113. timeSlotManager.reset();
  16114. var stop, operation = {}, args = [];
  16115. while (!(stop = timeSlotManager.check())) {
  16116. // The arguments parsed by read() are not used beyond this loop, so
  16117. // we can reuse the same array on every iteration, thus avoiding
  16118. // unnecessary allocations.
  16119. args.length = 0;
  16120. operation.args = args;
  16121. if (!(preprocessor.read(operation))) {
  16122. break;
  16123. }
  16124. textState = stateManager.state;
  16125. var fn = operation.fn;
  16126. args = operation.args;
  16127. switch (fn | 0) {
  16128. case OPS.setFont:
  16129. textState.fontSize = args[1];
  16130. return handleSetFont(args[0].name).then(function() {
  16131. next(resolve, reject);
  16132. }, reject);
  16133. case OPS.setTextRise:
  16134. textState.textRise = args[0];
  16135. break;
  16136. case OPS.setHScale:
  16137. textState.textHScale = args[0] / 100;
  16138. break;
  16139. case OPS.setLeading:
  16140. textState.leading = args[0];
  16141. break;
  16142. case OPS.moveText:
  16143. textState.translateTextLineMatrix(args[0], args[1]);
  16144. textState.textMatrix = textState.textLineMatrix.slice();
  16145. break;
  16146. case OPS.setLeadingMoveText:
  16147. textState.leading = -args[1];
  16148. textState.translateTextLineMatrix(args[0], args[1]);
  16149. textState.textMatrix = textState.textLineMatrix.slice();
  16150. break;
  16151. case OPS.nextLine:
  16152. textState.carriageReturn();
  16153. break;
  16154. case OPS.setTextMatrix:
  16155. textState.setTextMatrix(args[0], args[1], args[2], args[3],
  16156. args[4], args[5]);
  16157. textState.setTextLineMatrix(args[0], args[1], args[2], args[3],
  16158. args[4], args[5]);
  16159. break;
  16160. case OPS.setCharSpacing:
  16161. textState.charSpacing = args[0];
  16162. break;
  16163. case OPS.setWordSpacing:
  16164. textState.wordSpacing = args[0];
  16165. break;
  16166. case OPS.beginText:
  16167. textState.textMatrix = IDENTITY_MATRIX.slice();
  16168. textState.textLineMatrix = IDENTITY_MATRIX.slice();
  16169. break;
  16170. case OPS.showSpacedText:
  16171. var items = args[0];
  16172. var textChunk = newTextChunk();
  16173. var offset;
  16174. for (var j = 0, jj = items.length; j < jj; j++) {
  16175. if (typeof items[j] === 'string') {
  16176. buildTextGeometry(items[j], textChunk);
  16177. } else {
  16178. var val = items[j] / 1000;
  16179. if (!textState.font.vertical) {
  16180. offset = -val * textState.fontSize * textState.textHScale *
  16181. textState.textMatrix[0];
  16182. textState.translateTextMatrix(offset, 0);
  16183. textChunk.width += offset;
  16184. } else {
  16185. offset = -val * textState.fontSize *
  16186. textState.textMatrix[3];
  16187. textState.translateTextMatrix(0, offset);
  16188. textChunk.height += offset;
  16189. }
  16190. if (items[j] < 0 && textState.font.spaceWidth > 0) {
  16191. var fakeSpaces = -items[j] / textState.font.spaceWidth;
  16192. if (fakeSpaces > MULTI_SPACE_FACTOR) {
  16193. fakeSpaces = Math.round(fakeSpaces);
  16194. while (fakeSpaces--) {
  16195. textChunk.str.push(' ');
  16196. }
  16197. } else if (fakeSpaces > SPACE_FACTOR) {
  16198. textChunk.str.push(' ');
  16199. }
  16200. }
  16201. }
  16202. }
  16203. bidiTexts.push(runBidi(textChunk));
  16204. break;
  16205. case OPS.showText:
  16206. bidiTexts.push(runBidi(buildTextGeometry(args[0])));
  16207. break;
  16208. case OPS.nextLineShowText:
  16209. textState.carriageReturn();
  16210. bidiTexts.push(runBidi(buildTextGeometry(args[0])));
  16211. break;
  16212. case OPS.nextLineSetSpacingShowText:
  16213. textState.wordSpacing = args[0];
  16214. textState.charSpacing = args[1];
  16215. textState.carriageReturn();
  16216. bidiTexts.push(runBidi(buildTextGeometry(args[2])));
  16217. break;
  16218. case OPS.paintXObject:
  16219. if (args[0].code) {
  16220. break;
  16221. }
  16222. if (!xobjs) {
  16223. xobjs = (resources.get('XObject') || Dict.empty);
  16224. }
  16225. var name = args[0].name;
  16226. if (xobjsCache.key === name) {
  16227. if (xobjsCache.texts) {
  16228. Util.appendToArray(bidiTexts, xobjsCache.texts.items);
  16229. Util.extendObj(textContent.styles, xobjsCache.texts.styles);
  16230. }
  16231. break;
  16232. }
  16233. var xobj = xobjs.get(name);
  16234. if (!xobj) {
  16235. break;
  16236. }
  16237. assert(isStream(xobj), 'XObject should be a stream');
  16238. var type = xobj.dict.get('Subtype');
  16239. assert(isName(type),
  16240. 'XObject should have a Name subtype');
  16241. if ('Form' !== type.name) {
  16242. xobjsCache.key = name;
  16243. xobjsCache.texts = null;
  16244. break;
  16245. }
  16246. stateManager.save();
  16247. var matrix = xobj.dict.get('Matrix');
  16248. if (isArray(matrix) && matrix.length === 6) {
  16249. stateManager.transform(matrix);
  16250. }
  16251. return self.getTextContent(xobj,
  16252. xobj.dict.get('Resources') || resources, stateManager).
  16253. then(function (formTextContent) {
  16254. Util.appendToArray(bidiTexts, formTextContent.items);
  16255. Util.extendObj(textContent.styles, formTextContent.styles);
  16256. stateManager.restore();
  16257. xobjsCache.key = name;
  16258. xobjsCache.texts = formTextContent;
  16259. next(resolve, reject);
  16260. }, reject);
  16261. case OPS.setGState:
  16262. var dictName = args[0];
  16263. var extGState = resources.get('ExtGState');
  16264. if (!isDict(extGState) || !extGState.has(dictName.name)) {
  16265. break;
  16266. }
  16267. var gsStateMap = extGState.get(dictName.name);
  16268. var gsStateFont = null;
  16269. for (var key in gsStateMap) {
  16270. if (key === 'Font') {
  16271. assert(!gsStateFont);
  16272. gsStateFont = gsStateMap[key];
  16273. }
  16274. }
  16275. if (gsStateFont) {
  16276. textState.fontSize = gsStateFont[1];
  16277. return handleSetFont(gsStateFont[0]).then(function() {
  16278. next(resolve, reject);
  16279. }, reject);
  16280. }
  16281. break;
  16282. } // switch
  16283. } // while
  16284. if (stop) {
  16285. deferred.then(function () {
  16286. next(resolve, reject);
  16287. });
  16288. return;
  16289. }
  16290. resolve(textContent);
  16291. });
  16292. },
  16293. extractDataStructures: function
  16294. partialEvaluatorExtractDataStructures(dict, baseDict,
  16295. xref, properties) {
  16296. // 9.10.2
  16297. var toUnicode = (dict.get('ToUnicode') || baseDict.get('ToUnicode'));
  16298. if (toUnicode) {
  16299. properties.toUnicode = this.readToUnicode(toUnicode);
  16300. }
  16301. if (properties.composite) {
  16302. // CIDSystemInfo helps to match CID to glyphs
  16303. var cidSystemInfo = dict.get('CIDSystemInfo');
  16304. if (isDict(cidSystemInfo)) {
  16305. properties.cidSystemInfo = {
  16306. registry: cidSystemInfo.get('Registry'),
  16307. ordering: cidSystemInfo.get('Ordering'),
  16308. supplement: cidSystemInfo.get('Supplement')
  16309. };
  16310. }
  16311. var cidToGidMap = dict.get('CIDToGIDMap');
  16312. if (isStream(cidToGidMap)) {
  16313. properties.cidToGidMap = this.readCidToGidMap(cidToGidMap);
  16314. }
  16315. }
  16316. // Based on 9.6.6 of the spec the encoding can come from multiple places
  16317. // and depends on the font type. The base encoding and differences are
  16318. // read here, but the encoding that is actually used is chosen during
  16319. // glyph mapping in the font.
  16320. // TODO: Loading the built in encoding in the font would allow the
  16321. // differences to be merged in here not require us to hold on to it.
  16322. var differences = [];
  16323. var baseEncodingName = null;
  16324. var encoding;
  16325. if (dict.has('Encoding')) {
  16326. encoding = dict.get('Encoding');
  16327. if (isDict(encoding)) {
  16328. baseEncodingName = encoding.get('BaseEncoding');
  16329. baseEncodingName = (isName(baseEncodingName) ?
  16330. baseEncodingName.name : null);
  16331. // Load the differences between the base and original
  16332. if (encoding.has('Differences')) {
  16333. var diffEncoding = encoding.get('Differences');
  16334. var index = 0;
  16335. for (var j = 0, jj = diffEncoding.length; j < jj; j++) {
  16336. var data = diffEncoding[j];
  16337. if (isNum(data)) {
  16338. index = data;
  16339. } else {
  16340. differences[index++] = data.name;
  16341. }
  16342. }
  16343. }
  16344. } else if (isName(encoding)) {
  16345. baseEncodingName = encoding.name;
  16346. } else {
  16347. error('Encoding is not a Name nor a Dict');
  16348. }
  16349. // According to table 114 if the encoding is a named encoding it must be
  16350. // one of these predefined encodings.
  16351. if ((baseEncodingName !== 'MacRomanEncoding' &&
  16352. baseEncodingName !== 'MacExpertEncoding' &&
  16353. baseEncodingName !== 'WinAnsiEncoding')) {
  16354. baseEncodingName = null;
  16355. }
  16356. }
  16357. if (baseEncodingName) {
  16358. properties.defaultEncoding = Encodings[baseEncodingName].slice();
  16359. } else {
  16360. encoding = (properties.type === 'TrueType' ?
  16361. Encodings.WinAnsiEncoding : Encodings.StandardEncoding);
  16362. // The Symbolic attribute can be misused for regular fonts
  16363. // Heuristic: we have to check if the font is a standard one also
  16364. if (!!(properties.flags & FontFlags.Symbolic)) {
  16365. encoding = Encodings.MacRomanEncoding;
  16366. if (!properties.file) {
  16367. if (/Symbol/i.test(properties.name)) {
  16368. encoding = Encodings.SymbolSetEncoding;
  16369. } else if (/Dingbats/i.test(properties.name)) {
  16370. encoding = Encodings.ZapfDingbatsEncoding;
  16371. }
  16372. }
  16373. }
  16374. properties.defaultEncoding = encoding;
  16375. }
  16376. properties.differences = differences;
  16377. properties.baseEncodingName = baseEncodingName;
  16378. properties.dict = dict;
  16379. },
  16380. readToUnicode: function PartialEvaluator_readToUnicode(toUnicode) {
  16381. var cmap, cmapObj = toUnicode;
  16382. if (isName(cmapObj)) {
  16383. cmap = CMapFactory.create(cmapObj,
  16384. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  16385. if (cmap instanceof IdentityCMap) {
  16386. return new IdentityToUnicodeMap(0, 0xFFFF);
  16387. }
  16388. return new ToUnicodeMap(cmap.getMap());
  16389. } else if (isStream(cmapObj)) {
  16390. cmap = CMapFactory.create(cmapObj,
  16391. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null).getMap();
  16392. // Convert UTF-16BE
  16393. // NOTE: cmap can be a sparse array, so use forEach instead of for(;;)
  16394. // to iterate over all keys.
  16395. cmap.forEach(function(token, i) {
  16396. var str = [];
  16397. for (var k = 0; k < token.length; k += 2) {
  16398. var w1 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
  16399. if ((w1 & 0xF800) !== 0xD800) { // w1 < 0xD800 || w1 > 0xDFFF
  16400. str.push(w1);
  16401. continue;
  16402. }
  16403. k += 2;
  16404. var w2 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
  16405. str.push(((w1 & 0x3ff) << 10) + (w2 & 0x3ff) + 0x10000);
  16406. }
  16407. cmap[i] = String.fromCharCode.apply(String, str);
  16408. });
  16409. return new ToUnicodeMap(cmap);
  16410. }
  16411. return null;
  16412. },
  16413. readCidToGidMap: function PartialEvaluator_readCidToGidMap(cidToGidStream) {
  16414. // Extract the encoding from the CIDToGIDMap
  16415. var glyphsData = cidToGidStream.getBytes();
  16416. // Set encoding 0 to later verify the font has an encoding
  16417. var result = [];
  16418. for (var j = 0, jj = glyphsData.length; j < jj; j++) {
  16419. var glyphID = (glyphsData[j++] << 8) | glyphsData[j];
  16420. if (glyphID === 0) {
  16421. continue;
  16422. }
  16423. var code = j >> 1;
  16424. result[code] = glyphID;
  16425. }
  16426. return result;
  16427. },
  16428. extractWidths: function PartialEvaluator_extractWidths(dict, xref,
  16429. descriptor,
  16430. properties) {
  16431. var glyphsWidths = [];
  16432. var defaultWidth = 0;
  16433. var glyphsVMetrics = [];
  16434. var defaultVMetrics;
  16435. var i, ii, j, jj, start, code, widths;
  16436. if (properties.composite) {
  16437. defaultWidth = dict.get('DW') || 1000;
  16438. widths = dict.get('W');
  16439. if (widths) {
  16440. for (i = 0, ii = widths.length; i < ii; i++) {
  16441. start = widths[i++];
  16442. code = xref.fetchIfRef(widths[i]);
  16443. if (isArray(code)) {
  16444. for (j = 0, jj = code.length; j < jj; j++) {
  16445. glyphsWidths[start++] = code[j];
  16446. }
  16447. } else {
  16448. var width = widths[++i];
  16449. for (j = start; j <= code; j++) {
  16450. glyphsWidths[j] = width;
  16451. }
  16452. }
  16453. }
  16454. }
  16455. if (properties.vertical) {
  16456. var vmetrics = (dict.get('DW2') || [880, -1000]);
  16457. defaultVMetrics = [vmetrics[1], defaultWidth * 0.5, vmetrics[0]];
  16458. vmetrics = dict.get('W2');
  16459. if (vmetrics) {
  16460. for (i = 0, ii = vmetrics.length; i < ii; i++) {
  16461. start = vmetrics[i++];
  16462. code = xref.fetchIfRef(vmetrics[i]);
  16463. if (isArray(code)) {
  16464. for (j = 0, jj = code.length; j < jj; j++) {
  16465. glyphsVMetrics[start++] = [code[j++], code[j++], code[j]];
  16466. }
  16467. } else {
  16468. var vmetric = [vmetrics[++i], vmetrics[++i], vmetrics[++i]];
  16469. for (j = start; j <= code; j++) {
  16470. glyphsVMetrics[j] = vmetric;
  16471. }
  16472. }
  16473. }
  16474. }
  16475. }
  16476. } else {
  16477. var firstChar = properties.firstChar;
  16478. widths = dict.get('Widths');
  16479. if (widths) {
  16480. j = firstChar;
  16481. for (i = 0, ii = widths.length; i < ii; i++) {
  16482. glyphsWidths[j++] = widths[i];
  16483. }
  16484. defaultWidth = (parseFloat(descriptor.get('MissingWidth')) || 0);
  16485. } else {
  16486. // Trying get the BaseFont metrics (see comment above).
  16487. var baseFontName = dict.get('BaseFont');
  16488. if (isName(baseFontName)) {
  16489. var metrics = this.getBaseFontMetrics(baseFontName.name);
  16490. glyphsWidths = this.buildCharCodeToWidth(metrics.widths,
  16491. properties);
  16492. defaultWidth = metrics.defaultWidth;
  16493. }
  16494. }
  16495. }
  16496. // Heuristic: detection of monospace font by checking all non-zero widths
  16497. var isMonospace = true;
  16498. var firstWidth = defaultWidth;
  16499. for (var glyph in glyphsWidths) {
  16500. var glyphWidth = glyphsWidths[glyph];
  16501. if (!glyphWidth) {
  16502. continue;
  16503. }
  16504. if (!firstWidth) {
  16505. firstWidth = glyphWidth;
  16506. continue;
  16507. }
  16508. if (firstWidth !== glyphWidth) {
  16509. isMonospace = false;
  16510. break;
  16511. }
  16512. }
  16513. if (isMonospace) {
  16514. properties.flags |= FontFlags.FixedPitch;
  16515. }
  16516. properties.defaultWidth = defaultWidth;
  16517. properties.widths = glyphsWidths;
  16518. properties.defaultVMetrics = defaultVMetrics;
  16519. properties.vmetrics = glyphsVMetrics;
  16520. },
  16521. isSerifFont: function PartialEvaluator_isSerifFont(baseFontName) {
  16522. // Simulating descriptor flags attribute
  16523. var fontNameWoStyle = baseFontName.split('-')[0];
  16524. return (fontNameWoStyle in serifFonts) ||
  16525. (fontNameWoStyle.search(/serif/gi) !== -1);
  16526. },
  16527. getBaseFontMetrics: function PartialEvaluator_getBaseFontMetrics(name) {
  16528. var defaultWidth = 0;
  16529. var widths = [];
  16530. var monospace = false;
  16531. var lookupName = (stdFontMap[name] || name);
  16532. if (!(lookupName in Metrics)) {
  16533. // Use default fonts for looking up font metrics if the passed
  16534. // font is not a base font
  16535. if (this.isSerifFont(name)) {
  16536. lookupName = 'Times-Roman';
  16537. } else {
  16538. lookupName = 'Helvetica';
  16539. }
  16540. }
  16541. var glyphWidths = Metrics[lookupName];
  16542. if (isNum(glyphWidths)) {
  16543. defaultWidth = glyphWidths;
  16544. monospace = true;
  16545. } else {
  16546. widths = glyphWidths;
  16547. }
  16548. return {
  16549. defaultWidth: defaultWidth,
  16550. monospace: monospace,
  16551. widths: widths
  16552. };
  16553. },
  16554. buildCharCodeToWidth:
  16555. function PartialEvaluator_bulildCharCodeToWidth(widthsByGlyphName,
  16556. properties) {
  16557. var widths = Object.create(null);
  16558. var differences = properties.differences;
  16559. var encoding = properties.defaultEncoding;
  16560. for (var charCode = 0; charCode < 256; charCode++) {
  16561. if (charCode in differences &&
  16562. widthsByGlyphName[differences[charCode]]) {
  16563. widths[charCode] = widthsByGlyphName[differences[charCode]];
  16564. continue;
  16565. }
  16566. if (charCode in encoding && widthsByGlyphName[encoding[charCode]]) {
  16567. widths[charCode] = widthsByGlyphName[encoding[charCode]];
  16568. continue;
  16569. }
  16570. }
  16571. return widths;
  16572. },
  16573. preEvaluateFont: function PartialEvaluator_preEvaluateFont(dict, xref) {
  16574. var baseDict = dict;
  16575. var type = dict.get('Subtype');
  16576. assert(isName(type), 'invalid font Subtype');
  16577. var composite = false;
  16578. var uint8array;
  16579. if (type.name === 'Type0') {
  16580. // If font is a composite
  16581. // - get the descendant font
  16582. // - set the type according to the descendant font
  16583. // - get the FontDescriptor from the descendant font
  16584. var df = dict.get('DescendantFonts');
  16585. if (!df) {
  16586. error('Descendant fonts are not specified');
  16587. }
  16588. dict = (isArray(df) ? xref.fetchIfRef(df[0]) : df);
  16589. type = dict.get('Subtype');
  16590. assert(isName(type), 'invalid font Subtype');
  16591. composite = true;
  16592. }
  16593. var descriptor = dict.get('FontDescriptor');
  16594. if (descriptor) {
  16595. var hash = new MurmurHash3_64();
  16596. var encoding = baseDict.getRaw('Encoding');
  16597. if (isName(encoding)) {
  16598. hash.update(encoding.name);
  16599. } else if (isRef(encoding)) {
  16600. hash.update(encoding.num + '_' + encoding.gen);
  16601. }
  16602. var toUnicode = dict.get('ToUnicode') || baseDict.get('ToUnicode');
  16603. if (isStream(toUnicode)) {
  16604. var stream = toUnicode.str || toUnicode;
  16605. uint8array = stream.buffer ?
  16606. new Uint8Array(stream.buffer.buffer, 0, stream.bufferLength) :
  16607. new Uint8Array(stream.bytes.buffer,
  16608. stream.start, stream.end - stream.start);
  16609. hash.update(uint8array);
  16610. } else if (isName(toUnicode)) {
  16611. hash.update(toUnicode.name);
  16612. }
  16613. var widths = dict.get('Widths') || baseDict.get('Widths');
  16614. if (widths) {
  16615. uint8array = new Uint8Array(new Uint32Array(widths).buffer);
  16616. hash.update(uint8array);
  16617. }
  16618. }
  16619. return {
  16620. descriptor: descriptor,
  16621. dict: dict,
  16622. baseDict: baseDict,
  16623. composite: composite,
  16624. type: type.name,
  16625. hash: hash ? hash.hexdigest() : ''
  16626. };
  16627. },
  16628. translateFont: function PartialEvaluator_translateFont(preEvaluatedFont,
  16629. xref) {
  16630. var baseDict = preEvaluatedFont.baseDict;
  16631. var dict = preEvaluatedFont.dict;
  16632. var composite = preEvaluatedFont.composite;
  16633. var descriptor = preEvaluatedFont.descriptor;
  16634. var type = preEvaluatedFont.type;
  16635. var maxCharIndex = (composite ? 0xFFFF : 0xFF);
  16636. var properties;
  16637. if (!descriptor) {
  16638. if (type === 'Type3') {
  16639. // FontDescriptor is only required for Type3 fonts when the document
  16640. // is a tagged pdf. Create a barbebones one to get by.
  16641. descriptor = new Dict(null);
  16642. descriptor.set('FontName', Name.get(type));
  16643. } else {
  16644. // Before PDF 1.5 if the font was one of the base 14 fonts, having a
  16645. // FontDescriptor was not required.
  16646. // This case is here for compatibility.
  16647. var baseFontName = dict.get('BaseFont');
  16648. if (!isName(baseFontName)) {
  16649. error('Base font is not specified');
  16650. }
  16651. // Using base font name as a font name.
  16652. baseFontName = baseFontName.name.replace(/[,_]/g, '-');
  16653. var metrics = this.getBaseFontMetrics(baseFontName);
  16654. // Simulating descriptor flags attribute
  16655. var fontNameWoStyle = baseFontName.split('-')[0];
  16656. var flags =
  16657. (this.isSerifFont(fontNameWoStyle) ? FontFlags.Serif : 0) |
  16658. (metrics.monospace ? FontFlags.FixedPitch : 0) |
  16659. (symbolsFonts[fontNameWoStyle] ? FontFlags.Symbolic :
  16660. FontFlags.Nonsymbolic);
  16661. properties = {
  16662. type: type,
  16663. name: baseFontName,
  16664. widths: metrics.widths,
  16665. defaultWidth: metrics.defaultWidth,
  16666. flags: flags,
  16667. firstChar: 0,
  16668. lastChar: maxCharIndex
  16669. };
  16670. this.extractDataStructures(dict, dict, xref, properties);
  16671. properties.widths = this.buildCharCodeToWidth(metrics.widths,
  16672. properties);
  16673. return new Font(baseFontName, null, properties);
  16674. }
  16675. }
  16676. // According to the spec if 'FontDescriptor' is declared, 'FirstChar',
  16677. // 'LastChar' and 'Widths' should exist too, but some PDF encoders seem
  16678. // to ignore this rule when a variant of a standart font is used.
  16679. // TODO Fill the width array depending on which of the base font this is
  16680. // a variant.
  16681. var firstChar = (dict.get('FirstChar') || 0);
  16682. var lastChar = (dict.get('LastChar') || maxCharIndex);
  16683. var fontName = descriptor.get('FontName');
  16684. var baseFont = dict.get('BaseFont');
  16685. // Some bad PDFs have a string as the font name.
  16686. if (isString(fontName)) {
  16687. fontName = Name.get(fontName);
  16688. }
  16689. if (isString(baseFont)) {
  16690. baseFont = Name.get(baseFont);
  16691. }
  16692. if (type !== 'Type3') {
  16693. var fontNameStr = fontName && fontName.name;
  16694. var baseFontStr = baseFont && baseFont.name;
  16695. if (fontNameStr !== baseFontStr) {
  16696. info('The FontDescriptor\'s FontName is "' + fontNameStr +
  16697. '" but should be the same as the Font\'s BaseFont "' +
  16698. baseFontStr + '"');
  16699. // Workaround for cases where e.g. fontNameStr = 'Arial' and
  16700. // baseFontStr = 'Arial,Bold' (needed when no font file is embedded).
  16701. if (fontNameStr && baseFontStr &&
  16702. baseFontStr.indexOf(fontNameStr) === 0) {
  16703. fontName = baseFont;
  16704. }
  16705. }
  16706. }
  16707. fontName = (fontName || baseFont);
  16708. assert(isName(fontName), 'invalid font name');
  16709. var fontFile = descriptor.get('FontFile', 'FontFile2', 'FontFile3');
  16710. if (fontFile) {
  16711. if (fontFile.dict) {
  16712. var subtype = fontFile.dict.get('Subtype');
  16713. if (subtype) {
  16714. subtype = subtype.name;
  16715. }
  16716. var length1 = fontFile.dict.get('Length1');
  16717. var length2 = fontFile.dict.get('Length2');
  16718. }
  16719. }
  16720. properties = {
  16721. type: type,
  16722. name: fontName.name,
  16723. subtype: subtype,
  16724. file: fontFile,
  16725. length1: length1,
  16726. length2: length2,
  16727. loadedName: baseDict.loadedName,
  16728. composite: composite,
  16729. wideChars: composite,
  16730. fixedPitch: false,
  16731. fontMatrix: (dict.get('FontMatrix') || FONT_IDENTITY_MATRIX),
  16732. firstChar: firstChar || 0,
  16733. lastChar: (lastChar || maxCharIndex),
  16734. bbox: descriptor.get('FontBBox'),
  16735. ascent: descriptor.get('Ascent'),
  16736. descent: descriptor.get('Descent'),
  16737. xHeight: descriptor.get('XHeight'),
  16738. capHeight: descriptor.get('CapHeight'),
  16739. flags: descriptor.get('Flags'),
  16740. italicAngle: descriptor.get('ItalicAngle'),
  16741. coded: false
  16742. };
  16743. if (composite) {
  16744. var cidEncoding = baseDict.get('Encoding');
  16745. if (isName(cidEncoding)) {
  16746. properties.cidEncoding = cidEncoding.name;
  16747. }
  16748. properties.cMap = CMapFactory.create(cidEncoding,
  16749. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  16750. properties.vertical = properties.cMap.vertical;
  16751. }
  16752. this.extractDataStructures(dict, baseDict, xref, properties);
  16753. this.extractWidths(dict, xref, descriptor, properties);
  16754. if (type === 'Type3') {
  16755. properties.isType3Font = true;
  16756. }
  16757. return new Font(fontName.name, fontFile, properties);
  16758. }
  16759. };
  16760. return PartialEvaluator;
  16761. })();
  16762. var TranslatedFont = (function TranslatedFontClosure() {
  16763. function TranslatedFont(loadedName, font, dict) {
  16764. this.loadedName = loadedName;
  16765. this.font = font;
  16766. this.dict = dict;
  16767. this.type3Loaded = null;
  16768. this.sent = false;
  16769. }
  16770. TranslatedFont.prototype = {
  16771. send: function (handler) {
  16772. if (this.sent) {
  16773. return;
  16774. }
  16775. var fontData = this.font.exportData();
  16776. handler.send('commonobj', [
  16777. this.loadedName,
  16778. 'Font',
  16779. fontData
  16780. ]);
  16781. this.sent = true;
  16782. },
  16783. loadType3Data: function (evaluator, resources, parentOperatorList) {
  16784. assert(this.font.isType3Font);
  16785. if (this.type3Loaded) {
  16786. return this.type3Loaded;
  16787. }
  16788. var translatedFont = this.font;
  16789. var loadCharProcsPromise = Promise.resolve();
  16790. var charProcs = this.dict.get('CharProcs').getAll();
  16791. var fontResources = this.dict.get('Resources') || resources;
  16792. var charProcKeys = Object.keys(charProcs);
  16793. var charProcOperatorList = {};
  16794. for (var i = 0, n = charProcKeys.length; i < n; ++i) {
  16795. loadCharProcsPromise = loadCharProcsPromise.then(function (key) {
  16796. var glyphStream = charProcs[key];
  16797. var operatorList = new OperatorList();
  16798. return evaluator.getOperatorList(glyphStream, fontResources,
  16799. operatorList).then(function () {
  16800. charProcOperatorList[key] = operatorList.getIR();
  16801. // Add the dependencies to the parent operator list so they are
  16802. // resolved before sub operator list is executed synchronously.
  16803. parentOperatorList.addDependencies(operatorList.dependencies);
  16804. }, function (reason) {
  16805. warn('Type3 font resource \"' + key + '\" is not available');
  16806. var operatorList = new OperatorList();
  16807. charProcOperatorList[key] = operatorList.getIR();
  16808. });
  16809. }.bind(this, charProcKeys[i]));
  16810. }
  16811. this.type3Loaded = loadCharProcsPromise.then(function () {
  16812. translatedFont.charProcOperatorList = charProcOperatorList;
  16813. });
  16814. return this.type3Loaded;
  16815. }
  16816. };
  16817. return TranslatedFont;
  16818. })();
  16819. var OperatorList = (function OperatorListClosure() {
  16820. var CHUNK_SIZE = 1000;
  16821. var CHUNK_SIZE_ABOUT = CHUNK_SIZE - 5; // close to chunk size
  16822. function getTransfers(queue) {
  16823. var transfers = [];
  16824. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  16825. for (var i = 0, ii = queue.length; i < ii; i++) {
  16826. switch (fnArray[i]) {
  16827. case OPS.paintInlineImageXObject:
  16828. case OPS.paintInlineImageXObjectGroup:
  16829. case OPS.paintImageMaskXObject:
  16830. var arg = argsArray[i][0]; // first param in imgData
  16831. if (!arg.cached) {
  16832. transfers.push(arg.data.buffer);
  16833. }
  16834. break;
  16835. }
  16836. }
  16837. return transfers;
  16838. }
  16839. function OperatorList(intent, messageHandler, pageIndex) {
  16840. this.messageHandler = messageHandler;
  16841. this.fnArray = [];
  16842. this.argsArray = [];
  16843. this.dependencies = {};
  16844. this.pageIndex = pageIndex;
  16845. this.intent = intent;
  16846. }
  16847. OperatorList.prototype = {
  16848. get length() {
  16849. return this.argsArray.length;
  16850. },
  16851. addOp: function(fn, args) {
  16852. this.fnArray.push(fn);
  16853. this.argsArray.push(args);
  16854. if (this.messageHandler) {
  16855. if (this.fnArray.length >= CHUNK_SIZE) {
  16856. this.flush();
  16857. } else if (this.fnArray.length >= CHUNK_SIZE_ABOUT &&
  16858. (fn === OPS.restore || fn === OPS.endText)) {
  16859. // heuristic to flush on boundary of restore or endText
  16860. this.flush();
  16861. }
  16862. }
  16863. },
  16864. addDependency: function(dependency) {
  16865. if (dependency in this.dependencies) {
  16866. return;
  16867. }
  16868. this.dependencies[dependency] = true;
  16869. this.addOp(OPS.dependency, [dependency]);
  16870. },
  16871. addDependencies: function(dependencies) {
  16872. for (var key in dependencies) {
  16873. this.addDependency(key);
  16874. }
  16875. },
  16876. addOpList: function(opList) {
  16877. Util.extendObj(this.dependencies, opList.dependencies);
  16878. for (var i = 0, ii = opList.length; i < ii; i++) {
  16879. this.addOp(opList.fnArray[i], opList.argsArray[i]);
  16880. }
  16881. },
  16882. getIR: function() {
  16883. return {
  16884. fnArray: this.fnArray,
  16885. argsArray: this.argsArray,
  16886. length: this.length
  16887. };
  16888. },
  16889. flush: function(lastChunk) {
  16890. if (this.intent !== 'oplist') {
  16891. new QueueOptimizer().optimize(this);
  16892. }
  16893. var transfers = getTransfers(this);
  16894. this.messageHandler.send('RenderPageChunk', {
  16895. operatorList: {
  16896. fnArray: this.fnArray,
  16897. argsArray: this.argsArray,
  16898. lastChunk: lastChunk,
  16899. length: this.length
  16900. },
  16901. pageIndex: this.pageIndex,
  16902. intent: this.intent
  16903. }, transfers);
  16904. this.dependencies = {};
  16905. this.fnArray.length = 0;
  16906. this.argsArray.length = 0;
  16907. }
  16908. };
  16909. return OperatorList;
  16910. })();
  16911. var StateManager = (function StateManagerClosure() {
  16912. function StateManager(initialState) {
  16913. this.state = initialState;
  16914. this.stateStack = [];
  16915. }
  16916. StateManager.prototype = {
  16917. save: function () {
  16918. var old = this.state;
  16919. this.stateStack.push(this.state);
  16920. this.state = old.clone();
  16921. },
  16922. restore: function () {
  16923. var prev = this.stateStack.pop();
  16924. if (prev) {
  16925. this.state = prev;
  16926. }
  16927. },
  16928. transform: function (args) {
  16929. this.state.ctm = Util.transform(this.state.ctm, args);
  16930. }
  16931. };
  16932. return StateManager;
  16933. })();
  16934. var TextState = (function TextStateClosure() {
  16935. function TextState() {
  16936. this.ctm = new Float32Array(IDENTITY_MATRIX);
  16937. this.fontSize = 0;
  16938. this.font = null;
  16939. this.fontMatrix = FONT_IDENTITY_MATRIX;
  16940. this.textMatrix = IDENTITY_MATRIX.slice();
  16941. this.textLineMatrix = IDENTITY_MATRIX.slice();
  16942. this.charSpacing = 0;
  16943. this.wordSpacing = 0;
  16944. this.leading = 0;
  16945. this.textHScale = 1;
  16946. this.textRise = 0;
  16947. }
  16948. TextState.prototype = {
  16949. setTextMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  16950. var m = this.textMatrix;
  16951. m[0] = a; m[1] = b; m[2] = c; m[3] = d; m[4] = e; m[5] = f;
  16952. },
  16953. setTextLineMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  16954. var m = this.textLineMatrix;
  16955. m[0] = a; m[1] = b; m[2] = c; m[3] = d; m[4] = e; m[5] = f;
  16956. },
  16957. translateTextMatrix: function TextState_translateTextMatrix(x, y) {
  16958. var m = this.textMatrix;
  16959. m[4] = m[0] * x + m[2] * y + m[4];
  16960. m[5] = m[1] * x + m[3] * y + m[5];
  16961. },
  16962. translateTextLineMatrix: function TextState_translateTextMatrix(x, y) {
  16963. var m = this.textLineMatrix;
  16964. m[4] = m[0] * x + m[2] * y + m[4];
  16965. m[5] = m[1] * x + m[3] * y + m[5];
  16966. },
  16967. calcRenderMatrix: function TextState_calcRendeMatrix(ctm) {
  16968. // 9.4.4 Text Space Details
  16969. var tsm = [this.fontSize * this.textHScale, 0,
  16970. 0, this.fontSize,
  16971. 0, this.textRise];
  16972. return Util.transform(ctm, Util.transform(this.textMatrix, tsm));
  16973. },
  16974. carriageReturn: function TextState_carriageReturn() {
  16975. this.translateTextLineMatrix(0, -this.leading);
  16976. this.textMatrix = this.textLineMatrix.slice();
  16977. },
  16978. clone: function TextState_clone() {
  16979. var clone = Object.create(this);
  16980. clone.textMatrix = this.textMatrix.slice();
  16981. clone.textLineMatrix = this.textLineMatrix.slice();
  16982. clone.fontMatrix = this.fontMatrix.slice();
  16983. return clone;
  16984. }
  16985. };
  16986. return TextState;
  16987. })();
  16988. var EvalState = (function EvalStateClosure() {
  16989. function EvalState() {
  16990. this.ctm = new Float32Array(IDENTITY_MATRIX);
  16991. this.font = null;
  16992. this.textRenderingMode = TextRenderingMode.FILL;
  16993. this.fillColorSpace = ColorSpace.singletons.gray;
  16994. this.strokeColorSpace = ColorSpace.singletons.gray;
  16995. }
  16996. EvalState.prototype = {
  16997. clone: function CanvasExtraState_clone() {
  16998. return Object.create(this);
  16999. },
  17000. };
  17001. return EvalState;
  17002. })();
  17003. var EvaluatorPreprocessor = (function EvaluatorPreprocessorClosure() {
  17004. // Specifies properties for each command
  17005. //
  17006. // If variableArgs === true: [0, `numArgs`] expected
  17007. // If variableArgs === false: exactly `numArgs` expected
  17008. var OP_MAP = {
  17009. // Graphic state
  17010. w: { id: OPS.setLineWidth, numArgs: 1, variableArgs: false },
  17011. J: { id: OPS.setLineCap, numArgs: 1, variableArgs: false },
  17012. j: { id: OPS.setLineJoin, numArgs: 1, variableArgs: false },
  17013. M: { id: OPS.setMiterLimit, numArgs: 1, variableArgs: false },
  17014. d: { id: OPS.setDash, numArgs: 2, variableArgs: false },
  17015. ri: { id: OPS.setRenderingIntent, numArgs: 1, variableArgs: false },
  17016. i: { id: OPS.setFlatness, numArgs: 1, variableArgs: false },
  17017. gs: { id: OPS.setGState, numArgs: 1, variableArgs: false },
  17018. q: { id: OPS.save, numArgs: 0, variableArgs: false },
  17019. Q: { id: OPS.restore, numArgs: 0, variableArgs: false },
  17020. cm: { id: OPS.transform, numArgs: 6, variableArgs: false },
  17021. // Path
  17022. m: { id: OPS.moveTo, numArgs: 2, variableArgs: false },
  17023. l: { id: OPS.lineTo, numArgs: 2, variableArgs: false },
  17024. c: { id: OPS.curveTo, numArgs: 6, variableArgs: false },
  17025. v: { id: OPS.curveTo2, numArgs: 4, variableArgs: false },
  17026. y: { id: OPS.curveTo3, numArgs: 4, variableArgs: false },
  17027. h: { id: OPS.closePath, numArgs: 0, variableArgs: false },
  17028. re: { id: OPS.rectangle, numArgs: 4, variableArgs: false },
  17029. S: { id: OPS.stroke, numArgs: 0, variableArgs: false },
  17030. s: { id: OPS.closeStroke, numArgs: 0, variableArgs: false },
  17031. f: { id: OPS.fill, numArgs: 0, variableArgs: false },
  17032. F: { id: OPS.fill, numArgs: 0, variableArgs: false },
  17033. 'f*': { id: OPS.eoFill, numArgs: 0, variableArgs: false },
  17034. B: { id: OPS.fillStroke, numArgs: 0, variableArgs: false },
  17035. 'B*': { id: OPS.eoFillStroke, numArgs: 0, variableArgs: false },
  17036. b: { id: OPS.closeFillStroke, numArgs: 0, variableArgs: false },
  17037. 'b*': { id: OPS.closeEOFillStroke, numArgs: 0, variableArgs: false },
  17038. n: { id: OPS.endPath, numArgs: 0, variableArgs: false },
  17039. // Clipping
  17040. W: { id: OPS.clip, numArgs: 0, variableArgs: false },
  17041. 'W*': { id: OPS.eoClip, numArgs: 0, variableArgs: false },
  17042. // Text
  17043. BT: { id: OPS.beginText, numArgs: 0, variableArgs: false },
  17044. ET: { id: OPS.endText, numArgs: 0, variableArgs: false },
  17045. Tc: { id: OPS.setCharSpacing, numArgs: 1, variableArgs: false },
  17046. Tw: { id: OPS.setWordSpacing, numArgs: 1, variableArgs: false },
  17047. Tz: { id: OPS.setHScale, numArgs: 1, variableArgs: false },
  17048. TL: { id: OPS.setLeading, numArgs: 1, variableArgs: false },
  17049. Tf: { id: OPS.setFont, numArgs: 2, variableArgs: false },
  17050. Tr: { id: OPS.setTextRenderingMode, numArgs: 1, variableArgs: false },
  17051. Ts: { id: OPS.setTextRise, numArgs: 1, variableArgs: false },
  17052. Td: { id: OPS.moveText, numArgs: 2, variableArgs: false },
  17053. TD: { id: OPS.setLeadingMoveText, numArgs: 2, variableArgs: false },
  17054. Tm: { id: OPS.setTextMatrix, numArgs: 6, variableArgs: false },
  17055. 'T*': { id: OPS.nextLine, numArgs: 0, variableArgs: false },
  17056. Tj: { id: OPS.showText, numArgs: 1, variableArgs: false },
  17057. TJ: { id: OPS.showSpacedText, numArgs: 1, variableArgs: false },
  17058. '\'': { id: OPS.nextLineShowText, numArgs: 1, variableArgs: false },
  17059. '"': { id: OPS.nextLineSetSpacingShowText, numArgs: 3,
  17060. variableArgs: false },
  17061. // Type3 fonts
  17062. d0: { id: OPS.setCharWidth, numArgs: 2, variableArgs: false },
  17063. d1: { id: OPS.setCharWidthAndBounds, numArgs: 6, variableArgs: false },
  17064. // Color
  17065. CS: { id: OPS.setStrokeColorSpace, numArgs: 1, variableArgs: false },
  17066. cs: { id: OPS.setFillColorSpace, numArgs: 1, variableArgs: false },
  17067. SC: { id: OPS.setStrokeColor, numArgs: 4, variableArgs: true },
  17068. SCN: { id: OPS.setStrokeColorN, numArgs: 33, variableArgs: true },
  17069. sc: { id: OPS.setFillColor, numArgs: 4, variableArgs: true },
  17070. scn: { id: OPS.setFillColorN, numArgs: 33, variableArgs: true },
  17071. G: { id: OPS.setStrokeGray, numArgs: 1, variableArgs: false },
  17072. g: { id: OPS.setFillGray, numArgs: 1, variableArgs: false },
  17073. RG: { id: OPS.setStrokeRGBColor, numArgs: 3, variableArgs: false },
  17074. rg: { id: OPS.setFillRGBColor, numArgs: 3, variableArgs: false },
  17075. K: { id: OPS.setStrokeCMYKColor, numArgs: 4, variableArgs: false },
  17076. k: { id: OPS.setFillCMYKColor, numArgs: 4, variableArgs: false },
  17077. // Shading
  17078. sh: { id: OPS.shadingFill, numArgs: 1, variableArgs: false },
  17079. // Images
  17080. BI: { id: OPS.beginInlineImage, numArgs: 0, variableArgs: false },
  17081. ID: { id: OPS.beginImageData, numArgs: 0, variableArgs: false },
  17082. EI: { id: OPS.endInlineImage, numArgs: 1, variableArgs: false },
  17083. // XObjects
  17084. Do: { id: OPS.paintXObject, numArgs: 1, variableArgs: false },
  17085. MP: { id: OPS.markPoint, numArgs: 1, variableArgs: false },
  17086. DP: { id: OPS.markPointProps, numArgs: 2, variableArgs: false },
  17087. BMC: { id: OPS.beginMarkedContent, numArgs: 1, variableArgs: false },
  17088. BDC: { id: OPS.beginMarkedContentProps, numArgs: 2,
  17089. variableArgs: false },
  17090. EMC: { id: OPS.endMarkedContent, numArgs: 0, variableArgs: false },
  17091. // Compatibility
  17092. BX: { id: OPS.beginCompat, numArgs: 0, variableArgs: false },
  17093. EX: { id: OPS.endCompat, numArgs: 0, variableArgs: false },
  17094. // (reserved partial commands for the lexer)
  17095. BM: null,
  17096. BD: null,
  17097. 'true': null,
  17098. fa: null,
  17099. fal: null,
  17100. fals: null,
  17101. 'false': null,
  17102. nu: null,
  17103. nul: null,
  17104. 'null': null
  17105. };
  17106. function EvaluatorPreprocessor(stream, xref, stateManager) {
  17107. // TODO(mduan): pass array of knownCommands rather than OP_MAP
  17108. // dictionary
  17109. this.parser = new Parser(new Lexer(stream, OP_MAP), false, xref);
  17110. this.stateManager = stateManager;
  17111. this.nonProcessedArgs = [];
  17112. }
  17113. EvaluatorPreprocessor.prototype = {
  17114. get savedStatesDepth() {
  17115. return this.stateManager.stateStack.length;
  17116. },
  17117. // |operation| is an object with two fields:
  17118. //
  17119. // - |fn| is an out param.
  17120. //
  17121. // - |args| is an inout param. On entry, it should have one of two values.
  17122. //
  17123. // - An empty array. This indicates that the caller is providing the
  17124. // array in which the args will be stored in. The caller should use
  17125. // this value if it can reuse a single array for each call to read().
  17126. //
  17127. // - |null|. This indicates that the caller needs this function to create
  17128. // the array in which any args are stored in. If there are zero args,
  17129. // this function will leave |operation.args| as |null| (thus avoiding
  17130. // allocations that would occur if we used an empty array to represent
  17131. // zero arguments). Otherwise, it will replace |null| with a new array
  17132. // containing the arguments. The caller should use this value if it
  17133. // cannot reuse an array for each call to read().
  17134. //
  17135. // These two modes are present because this function is very hot and so
  17136. // avoiding allocations where possible is worthwhile.
  17137. //
  17138. read: function EvaluatorPreprocessor_read(operation) {
  17139. var args = operation.args;
  17140. while (true) {
  17141. var obj = this.parser.getObj();
  17142. if (isCmd(obj)) {
  17143. var cmd = obj.cmd;
  17144. // Check that the command is valid
  17145. var opSpec = OP_MAP[cmd];
  17146. if (!opSpec) {
  17147. warn('Unknown command "' + cmd + '"');
  17148. continue;
  17149. }
  17150. var fn = opSpec.id;
  17151. var numArgs = opSpec.numArgs;
  17152. var argsLength = args !== null ? args.length : 0;
  17153. if (!opSpec.variableArgs) {
  17154. // Postscript commands can be nested, e.g. /F2 /GS2 gs 5.711 Tf
  17155. if (argsLength !== numArgs) {
  17156. var nonProcessedArgs = this.nonProcessedArgs;
  17157. while (argsLength > numArgs) {
  17158. nonProcessedArgs.push(args.shift());
  17159. argsLength--;
  17160. }
  17161. while (argsLength < numArgs && nonProcessedArgs.length !== 0) {
  17162. if (!args) {
  17163. args = [];
  17164. }
  17165. args.unshift(nonProcessedArgs.pop());
  17166. argsLength++;
  17167. }
  17168. }
  17169. if (argsLength < numArgs) {
  17170. // If we receive too few args, it's not possible to possible
  17171. // to execute the command, so skip the command
  17172. info('Command ' + fn + ': because expected ' +
  17173. numArgs + ' args, but received ' + argsLength +
  17174. ' args; skipping');
  17175. args = null;
  17176. continue;
  17177. }
  17178. } else if (argsLength > numArgs) {
  17179. info('Command ' + fn + ': expected [0,' + numArgs +
  17180. '] args, but received ' + argsLength + ' args');
  17181. }
  17182. // TODO figure out how to type-check vararg functions
  17183. this.preprocessCommand(fn, args);
  17184. operation.fn = fn;
  17185. operation.args = args;
  17186. return true;
  17187. } else {
  17188. if (isEOF(obj)) {
  17189. return false; // no more commands
  17190. }
  17191. // argument
  17192. if (obj !== null) {
  17193. if (!args) {
  17194. args = [];
  17195. }
  17196. args.push((obj instanceof Dict ? obj.getAll() : obj));
  17197. assert(args.length <= 33, 'Too many arguments');
  17198. }
  17199. }
  17200. }
  17201. },
  17202. preprocessCommand:
  17203. function EvaluatorPreprocessor_preprocessCommand(fn, args) {
  17204. switch (fn | 0) {
  17205. case OPS.save:
  17206. this.stateManager.save();
  17207. break;
  17208. case OPS.restore:
  17209. this.stateManager.restore();
  17210. break;
  17211. case OPS.transform:
  17212. this.stateManager.transform(args);
  17213. break;
  17214. }
  17215. }
  17216. };
  17217. return EvaluatorPreprocessor;
  17218. })();
  17219. var QueueOptimizer = (function QueueOptimizerClosure() {
  17220. function addState(parentState, pattern, fn) {
  17221. var state = parentState;
  17222. for (var i = 0, ii = pattern.length - 1; i < ii; i++) {
  17223. var item = pattern[i];
  17224. state = (state[item] || (state[item] = []));
  17225. }
  17226. state[pattern[pattern.length - 1]] = fn;
  17227. }
  17228. function handlePaintSolidColorImageMask(iFirstSave, count, fnArray,
  17229. argsArray) {
  17230. // Handles special case of mainly LaTeX documents which use image masks to
  17231. // draw lines with the current fill style.
  17232. // 'count' groups of (save, transform, paintImageMaskXObject, restore)+
  17233. // have been found at iFirstSave.
  17234. var iFirstPIMXO = iFirstSave + 2;
  17235. for (var i = 0; i < count; i++) {
  17236. var arg = argsArray[iFirstPIMXO + 4 * i];
  17237. var imageMask = arg.length === 1 && arg[0];
  17238. if (imageMask && imageMask.width === 1 && imageMask.height === 1 &&
  17239. (!imageMask.data.length ||
  17240. (imageMask.data.length === 1 && imageMask.data[0] === 0))) {
  17241. fnArray[iFirstPIMXO + 4 * i] = OPS.paintSolidColorImageMask;
  17242. continue;
  17243. }
  17244. break;
  17245. }
  17246. return count - i;
  17247. }
  17248. var InitialState = [];
  17249. // This replaces (save, transform, paintInlineImageXObject, restore)+
  17250. // sequences with one |paintInlineImageXObjectGroup| operation.
  17251. addState(InitialState,
  17252. [OPS.save, OPS.transform, OPS.paintInlineImageXObject, OPS.restore],
  17253. function foundInlineImageGroup(context) {
  17254. var MIN_IMAGES_IN_INLINE_IMAGES_BLOCK = 10;
  17255. var MAX_IMAGES_IN_INLINE_IMAGES_BLOCK = 200;
  17256. var MAX_WIDTH = 1000;
  17257. var IMAGE_PADDING = 1;
  17258. var fnArray = context.fnArray, argsArray = context.argsArray;
  17259. var curr = context.iCurr;
  17260. var iFirstSave = curr - 3;
  17261. var iFirstTransform = curr - 2;
  17262. var iFirstPIIXO = curr - 1;
  17263. // Look for the quartets.
  17264. var i = iFirstSave + 4;
  17265. var ii = fnArray.length;
  17266. while (i + 3 < ii) {
  17267. if (fnArray[i] !== OPS.save ||
  17268. fnArray[i + 1] !== OPS.transform ||
  17269. fnArray[i + 2] !== OPS.paintInlineImageXObject ||
  17270. fnArray[i + 3] !== OPS.restore) {
  17271. break; // ops don't match
  17272. }
  17273. i += 4;
  17274. }
  17275. // At this point, i is the index of the first op past the last valid
  17276. // quartet.
  17277. var count = Math.min((i - iFirstSave) / 4,
  17278. MAX_IMAGES_IN_INLINE_IMAGES_BLOCK);
  17279. if (count < MIN_IMAGES_IN_INLINE_IMAGES_BLOCK) {
  17280. return i;
  17281. }
  17282. // assuming that heights of those image is too small (~1 pixel)
  17283. // packing as much as possible by lines
  17284. var maxX = 0;
  17285. var map = [], maxLineHeight = 0;
  17286. var currentX = IMAGE_PADDING, currentY = IMAGE_PADDING;
  17287. var q;
  17288. for (q = 0; q < count; q++) {
  17289. var transform = argsArray[iFirstTransform + (q << 2)];
  17290. var img = argsArray[iFirstPIIXO + (q << 2)][0];
  17291. if (currentX + img.width > MAX_WIDTH) {
  17292. // starting new line
  17293. maxX = Math.max(maxX, currentX);
  17294. currentY += maxLineHeight + 2 * IMAGE_PADDING;
  17295. currentX = 0;
  17296. maxLineHeight = 0;
  17297. }
  17298. map.push({
  17299. transform: transform,
  17300. x: currentX, y: currentY,
  17301. w: img.width, h: img.height
  17302. });
  17303. currentX += img.width + 2 * IMAGE_PADDING;
  17304. maxLineHeight = Math.max(maxLineHeight, img.height);
  17305. }
  17306. var imgWidth = Math.max(maxX, currentX) + IMAGE_PADDING;
  17307. var imgHeight = currentY + maxLineHeight + IMAGE_PADDING;
  17308. var imgData = new Uint8Array(imgWidth * imgHeight * 4);
  17309. var imgRowSize = imgWidth << 2;
  17310. for (q = 0; q < count; q++) {
  17311. var data = argsArray[iFirstPIIXO + (q << 2)][0].data;
  17312. // Copy image by lines and extends pixels into padding.
  17313. var rowSize = map[q].w << 2;
  17314. var dataOffset = 0;
  17315. var offset = (map[q].x + map[q].y * imgWidth) << 2;
  17316. imgData.set(data.subarray(0, rowSize), offset - imgRowSize);
  17317. for (var k = 0, kk = map[q].h; k < kk; k++) {
  17318. imgData.set(data.subarray(dataOffset, dataOffset + rowSize), offset);
  17319. dataOffset += rowSize;
  17320. offset += imgRowSize;
  17321. }
  17322. imgData.set(data.subarray(dataOffset - rowSize, dataOffset), offset);
  17323. while (offset >= 0) {
  17324. data[offset - 4] = data[offset];
  17325. data[offset - 3] = data[offset + 1];
  17326. data[offset - 2] = data[offset + 2];
  17327. data[offset - 1] = data[offset + 3];
  17328. data[offset + rowSize] = data[offset + rowSize - 4];
  17329. data[offset + rowSize + 1] = data[offset + rowSize - 3];
  17330. data[offset + rowSize + 2] = data[offset + rowSize - 2];
  17331. data[offset + rowSize + 3] = data[offset + rowSize - 1];
  17332. offset -= imgRowSize;
  17333. }
  17334. }
  17335. // Replace queue items.
  17336. fnArray.splice(iFirstSave, count * 4, OPS.paintInlineImageXObjectGroup);
  17337. argsArray.splice(iFirstSave, count * 4,
  17338. [{ width: imgWidth, height: imgHeight, kind: ImageKind.RGBA_32BPP,
  17339. data: imgData }, map]);
  17340. return iFirstSave + 1;
  17341. });
  17342. // This replaces (save, transform, paintImageMaskXObject, restore)+
  17343. // sequences with one |paintImageMaskXObjectGroup| or one
  17344. // |paintImageMaskXObjectRepeat| operation.
  17345. addState(InitialState,
  17346. [OPS.save, OPS.transform, OPS.paintImageMaskXObject, OPS.restore],
  17347. function foundImageMaskGroup(context) {
  17348. var MIN_IMAGES_IN_MASKS_BLOCK = 10;
  17349. var MAX_IMAGES_IN_MASKS_BLOCK = 100;
  17350. var MAX_SAME_IMAGES_IN_MASKS_BLOCK = 1000;
  17351. var fnArray = context.fnArray, argsArray = context.argsArray;
  17352. var curr = context.iCurr;
  17353. var iFirstSave = curr - 3;
  17354. var iFirstTransform = curr - 2;
  17355. var iFirstPIMXO = curr - 1;
  17356. // Look for the quartets.
  17357. var i = iFirstSave + 4;
  17358. var ii = fnArray.length;
  17359. while (i + 3 < ii) {
  17360. if (fnArray[i] !== OPS.save ||
  17361. fnArray[i + 1] !== OPS.transform ||
  17362. fnArray[i + 2] !== OPS.paintImageMaskXObject ||
  17363. fnArray[i + 3] !== OPS.restore) {
  17364. break; // ops don't match
  17365. }
  17366. i += 4;
  17367. }
  17368. // At this point, i is the index of the first op past the last valid
  17369. // quartet.
  17370. var count = (i - iFirstSave) / 4;
  17371. count = handlePaintSolidColorImageMask(iFirstSave, count, fnArray,
  17372. argsArray);
  17373. if (count < MIN_IMAGES_IN_MASKS_BLOCK) {
  17374. return i;
  17375. }
  17376. var q;
  17377. var isSameImage = false;
  17378. var iTransform, transformArgs;
  17379. var firstPIMXOArg0 = argsArray[iFirstPIMXO][0];
  17380. if (argsArray[iFirstTransform][1] === 0 &&
  17381. argsArray[iFirstTransform][2] === 0) {
  17382. isSameImage = true;
  17383. var firstTransformArg0 = argsArray[iFirstTransform][0];
  17384. var firstTransformArg3 = argsArray[iFirstTransform][3];
  17385. iTransform = iFirstTransform + 4;
  17386. var iPIMXO = iFirstPIMXO + 4;
  17387. for (q = 1; q < count; q++, iTransform += 4, iPIMXO += 4) {
  17388. transformArgs = argsArray[iTransform];
  17389. if (argsArray[iPIMXO][0] !== firstPIMXOArg0 ||
  17390. transformArgs[0] !== firstTransformArg0 ||
  17391. transformArgs[1] !== 0 ||
  17392. transformArgs[2] !== 0 ||
  17393. transformArgs[3] !== firstTransformArg3) {
  17394. if (q < MIN_IMAGES_IN_MASKS_BLOCK) {
  17395. isSameImage = false;
  17396. } else {
  17397. count = q;
  17398. }
  17399. break; // different image or transform
  17400. }
  17401. }
  17402. }
  17403. if (isSameImage) {
  17404. count = Math.min(count, MAX_SAME_IMAGES_IN_MASKS_BLOCK);
  17405. var positions = new Float32Array(count * 2);
  17406. iTransform = iFirstTransform;
  17407. for (q = 0; q < count; q++, iTransform += 4) {
  17408. transformArgs = argsArray[iTransform];
  17409. positions[(q << 1)] = transformArgs[4];
  17410. positions[(q << 1) + 1] = transformArgs[5];
  17411. }
  17412. // Replace queue items.
  17413. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectRepeat);
  17414. argsArray.splice(iFirstSave, count * 4,
  17415. [firstPIMXOArg0, firstTransformArg0, firstTransformArg3, positions]);
  17416. } else {
  17417. count = Math.min(count, MAX_IMAGES_IN_MASKS_BLOCK);
  17418. var images = [];
  17419. for (q = 0; q < count; q++) {
  17420. transformArgs = argsArray[iFirstTransform + (q << 2)];
  17421. var maskParams = argsArray[iFirstPIMXO + (q << 2)][0];
  17422. images.push({ data: maskParams.data, width: maskParams.width,
  17423. height: maskParams.height,
  17424. transform: transformArgs });
  17425. }
  17426. // Replace queue items.
  17427. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectGroup);
  17428. argsArray.splice(iFirstSave, count * 4, [images]);
  17429. }
  17430. return iFirstSave + 1;
  17431. });
  17432. // This replaces (save, transform, paintImageXObject, restore)+ sequences
  17433. // with one paintImageXObjectRepeat operation, if the |transform| and
  17434. // |paintImageXObjectRepeat| ops are appropriate.
  17435. addState(InitialState,
  17436. [OPS.save, OPS.transform, OPS.paintImageXObject, OPS.restore],
  17437. function (context) {
  17438. var MIN_IMAGES_IN_BLOCK = 3;
  17439. var MAX_IMAGES_IN_BLOCK = 1000;
  17440. var fnArray = context.fnArray, argsArray = context.argsArray;
  17441. var curr = context.iCurr;
  17442. var iFirstSave = curr - 3;
  17443. var iFirstTransform = curr - 2;
  17444. var iFirstPIXO = curr - 1;
  17445. var iFirstRestore = curr;
  17446. if (argsArray[iFirstTransform][1] !== 0 ||
  17447. argsArray[iFirstTransform][2] !== 0) {
  17448. return iFirstRestore + 1; // transform has the wrong form
  17449. }
  17450. // Look for the quartets.
  17451. var firstPIXOArg0 = argsArray[iFirstPIXO][0];
  17452. var firstTransformArg0 = argsArray[iFirstTransform][0];
  17453. var firstTransformArg3 = argsArray[iFirstTransform][3];
  17454. var i = iFirstSave + 4;
  17455. var ii = fnArray.length;
  17456. while (i + 3 < ii) {
  17457. if (fnArray[i] !== OPS.save ||
  17458. fnArray[i + 1] !== OPS.transform ||
  17459. fnArray[i + 2] !== OPS.paintImageXObject ||
  17460. fnArray[i + 3] !== OPS.restore) {
  17461. break; // ops don't match
  17462. }
  17463. if (argsArray[i + 1][0] !== firstTransformArg0 ||
  17464. argsArray[i + 1][1] !== 0 ||
  17465. argsArray[i + 1][2] !== 0 ||
  17466. argsArray[i + 1][3] !== firstTransformArg3) {
  17467. break; // transforms don't match
  17468. }
  17469. if (argsArray[i + 2][0] !== firstPIXOArg0) {
  17470. break; // images don't match
  17471. }
  17472. i += 4;
  17473. }
  17474. // At this point, i is the index of the first op past the last valid
  17475. // quartet.
  17476. var count = Math.min((i - iFirstSave) / 4, MAX_IMAGES_IN_BLOCK);
  17477. if (count < MIN_IMAGES_IN_BLOCK) {
  17478. return i;
  17479. }
  17480. // Extract the (x,y) positions from all of the matching transforms.
  17481. var positions = new Float32Array(count * 2);
  17482. var iTransform = iFirstTransform;
  17483. for (var q = 0; q < count; q++, iTransform += 4) {
  17484. var transformArgs = argsArray[iTransform];
  17485. positions[(q << 1)] = transformArgs[4];
  17486. positions[(q << 1) + 1] = transformArgs[5];
  17487. }
  17488. // Replace queue items.
  17489. var args = [firstPIXOArg0, firstTransformArg0, firstTransformArg3,
  17490. positions];
  17491. fnArray.splice(iFirstSave, count * 4, OPS.paintImageXObjectRepeat);
  17492. argsArray.splice(iFirstSave, count * 4, args);
  17493. return iFirstSave + 1;
  17494. });
  17495. // This replaces (beginText, setFont, setTextMatrix, showText, endText)+
  17496. // sequences with (beginText, setFont, (setTextMatrix, showText)+, endText)+
  17497. // sequences, if the font for each one is the same.
  17498. addState(InitialState,
  17499. [OPS.beginText, OPS.setFont, OPS.setTextMatrix, OPS.showText, OPS.endText],
  17500. function (context) {
  17501. var MIN_CHARS_IN_BLOCK = 3;
  17502. var MAX_CHARS_IN_BLOCK = 1000;
  17503. var fnArray = context.fnArray, argsArray = context.argsArray;
  17504. var curr = context.iCurr;
  17505. var iFirstBeginText = curr - 4;
  17506. var iFirstSetFont = curr - 3;
  17507. var iFirstSetTextMatrix = curr - 2;
  17508. var iFirstShowText = curr - 1;
  17509. var iFirstEndText = curr;
  17510. // Look for the quintets.
  17511. var firstSetFontArg0 = argsArray[iFirstSetFont][0];
  17512. var firstSetFontArg1 = argsArray[iFirstSetFont][1];
  17513. var i = iFirstBeginText + 5;
  17514. var ii = fnArray.length;
  17515. while (i + 4 < ii) {
  17516. if (fnArray[i] !== OPS.beginText ||
  17517. fnArray[i + 1] !== OPS.setFont ||
  17518. fnArray[i + 2] !== OPS.setTextMatrix ||
  17519. fnArray[i + 3] !== OPS.showText ||
  17520. fnArray[i + 4] !== OPS.endText) {
  17521. break; // ops don't match
  17522. }
  17523. if (argsArray[i + 1][0] !== firstSetFontArg0 ||
  17524. argsArray[i + 1][1] !== firstSetFontArg1) {
  17525. break; // fonts don't match
  17526. }
  17527. i += 5;
  17528. }
  17529. // At this point, i is the index of the first op past the last valid
  17530. // quintet.
  17531. var count = Math.min(((i - iFirstBeginText) / 5), MAX_CHARS_IN_BLOCK);
  17532. if (count < MIN_CHARS_IN_BLOCK) {
  17533. return i;
  17534. }
  17535. // If the preceding quintet is (<something>, setFont, setTextMatrix,
  17536. // showText, endText), include that as well. (E.g. <something> might be
  17537. // |dependency|.)
  17538. var iFirst = iFirstBeginText;
  17539. if (iFirstBeginText >= 4 &&
  17540. fnArray[iFirstBeginText - 4] === fnArray[iFirstSetFont] &&
  17541. fnArray[iFirstBeginText - 3] === fnArray[iFirstSetTextMatrix] &&
  17542. fnArray[iFirstBeginText - 2] === fnArray[iFirstShowText] &&
  17543. fnArray[iFirstBeginText - 1] === fnArray[iFirstEndText] &&
  17544. argsArray[iFirstBeginText - 4][0] === firstSetFontArg0 &&
  17545. argsArray[iFirstBeginText - 4][1] === firstSetFontArg1) {
  17546. count++;
  17547. iFirst -= 5;
  17548. }
  17549. // Remove (endText, beginText, setFont) trios.
  17550. var iEndText = iFirst + 4;
  17551. for (var q = 1; q < count; q++) {
  17552. fnArray.splice(iEndText, 3);
  17553. argsArray.splice(iEndText, 3);
  17554. iEndText += 2;
  17555. }
  17556. return iEndText + 1;
  17557. });
  17558. function QueueOptimizer() {}
  17559. QueueOptimizer.prototype = {
  17560. optimize: function QueueOptimizer_optimize(queue) {
  17561. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  17562. var context = {
  17563. iCurr: 0,
  17564. fnArray: fnArray,
  17565. argsArray: argsArray
  17566. };
  17567. var state;
  17568. var i = 0, ii = fnArray.length;
  17569. while (i < ii) {
  17570. state = (state || InitialState)[fnArray[i]];
  17571. if (typeof state === 'function') { // we found some handler
  17572. context.iCurr = i;
  17573. // state() returns the index of the first non-matching op (if we
  17574. // didn't match) or the first op past the modified ops (if we did
  17575. // match and replace).
  17576. i = state(context);
  17577. state = undefined; // reset the state machine
  17578. ii = context.fnArray.length;
  17579. } else {
  17580. i++;
  17581. }
  17582. }
  17583. }
  17584. };
  17585. return QueueOptimizer;
  17586. })();
  17587. var BUILT_IN_CMAPS = [
  17588. // << Start unicode maps.
  17589. 'Adobe-GB1-UCS2',
  17590. 'Adobe-CNS1-UCS2',
  17591. 'Adobe-Japan1-UCS2',
  17592. 'Adobe-Korea1-UCS2',
  17593. // >> End unicode maps.
  17594. '78-EUC-H',
  17595. '78-EUC-V',
  17596. '78-H',
  17597. '78-RKSJ-H',
  17598. '78-RKSJ-V',
  17599. '78-V',
  17600. '78ms-RKSJ-H',
  17601. '78ms-RKSJ-V',
  17602. '83pv-RKSJ-H',
  17603. '90ms-RKSJ-H',
  17604. '90ms-RKSJ-V',
  17605. '90msp-RKSJ-H',
  17606. '90msp-RKSJ-V',
  17607. '90pv-RKSJ-H',
  17608. '90pv-RKSJ-V',
  17609. 'Add-H',
  17610. 'Add-RKSJ-H',
  17611. 'Add-RKSJ-V',
  17612. 'Add-V',
  17613. 'Adobe-CNS1-0',
  17614. 'Adobe-CNS1-1',
  17615. 'Adobe-CNS1-2',
  17616. 'Adobe-CNS1-3',
  17617. 'Adobe-CNS1-4',
  17618. 'Adobe-CNS1-5',
  17619. 'Adobe-CNS1-6',
  17620. 'Adobe-GB1-0',
  17621. 'Adobe-GB1-1',
  17622. 'Adobe-GB1-2',
  17623. 'Adobe-GB1-3',
  17624. 'Adobe-GB1-4',
  17625. 'Adobe-GB1-5',
  17626. 'Adobe-Japan1-0',
  17627. 'Adobe-Japan1-1',
  17628. 'Adobe-Japan1-2',
  17629. 'Adobe-Japan1-3',
  17630. 'Adobe-Japan1-4',
  17631. 'Adobe-Japan1-5',
  17632. 'Adobe-Japan1-6',
  17633. 'Adobe-Korea1-0',
  17634. 'Adobe-Korea1-1',
  17635. 'Adobe-Korea1-2',
  17636. 'B5-H',
  17637. 'B5-V',
  17638. 'B5pc-H',
  17639. 'B5pc-V',
  17640. 'CNS-EUC-H',
  17641. 'CNS-EUC-V',
  17642. 'CNS1-H',
  17643. 'CNS1-V',
  17644. 'CNS2-H',
  17645. 'CNS2-V',
  17646. 'ETHK-B5-H',
  17647. 'ETHK-B5-V',
  17648. 'ETen-B5-H',
  17649. 'ETen-B5-V',
  17650. 'ETenms-B5-H',
  17651. 'ETenms-B5-V',
  17652. 'EUC-H',
  17653. 'EUC-V',
  17654. 'Ext-H',
  17655. 'Ext-RKSJ-H',
  17656. 'Ext-RKSJ-V',
  17657. 'Ext-V',
  17658. 'GB-EUC-H',
  17659. 'GB-EUC-V',
  17660. 'GB-H',
  17661. 'GB-V',
  17662. 'GBK-EUC-H',
  17663. 'GBK-EUC-V',
  17664. 'GBK2K-H',
  17665. 'GBK2K-V',
  17666. 'GBKp-EUC-H',
  17667. 'GBKp-EUC-V',
  17668. 'GBT-EUC-H',
  17669. 'GBT-EUC-V',
  17670. 'GBT-H',
  17671. 'GBT-V',
  17672. 'GBTpc-EUC-H',
  17673. 'GBTpc-EUC-V',
  17674. 'GBpc-EUC-H',
  17675. 'GBpc-EUC-V',
  17676. 'H',
  17677. 'HKdla-B5-H',
  17678. 'HKdla-B5-V',
  17679. 'HKdlb-B5-H',
  17680. 'HKdlb-B5-V',
  17681. 'HKgccs-B5-H',
  17682. 'HKgccs-B5-V',
  17683. 'HKm314-B5-H',
  17684. 'HKm314-B5-V',
  17685. 'HKm471-B5-H',
  17686. 'HKm471-B5-V',
  17687. 'HKscs-B5-H',
  17688. 'HKscs-B5-V',
  17689. 'Hankaku',
  17690. 'Hiragana',
  17691. 'KSC-EUC-H',
  17692. 'KSC-EUC-V',
  17693. 'KSC-H',
  17694. 'KSC-Johab-H',
  17695. 'KSC-Johab-V',
  17696. 'KSC-V',
  17697. 'KSCms-UHC-H',
  17698. 'KSCms-UHC-HW-H',
  17699. 'KSCms-UHC-HW-V',
  17700. 'KSCms-UHC-V',
  17701. 'KSCpc-EUC-H',
  17702. 'KSCpc-EUC-V',
  17703. 'Katakana',
  17704. 'NWP-H',
  17705. 'NWP-V',
  17706. 'RKSJ-H',
  17707. 'RKSJ-V',
  17708. 'Roman',
  17709. 'UniCNS-UCS2-H',
  17710. 'UniCNS-UCS2-V',
  17711. 'UniCNS-UTF16-H',
  17712. 'UniCNS-UTF16-V',
  17713. 'UniCNS-UTF32-H',
  17714. 'UniCNS-UTF32-V',
  17715. 'UniCNS-UTF8-H',
  17716. 'UniCNS-UTF8-V',
  17717. 'UniGB-UCS2-H',
  17718. 'UniGB-UCS2-V',
  17719. 'UniGB-UTF16-H',
  17720. 'UniGB-UTF16-V',
  17721. 'UniGB-UTF32-H',
  17722. 'UniGB-UTF32-V',
  17723. 'UniGB-UTF8-H',
  17724. 'UniGB-UTF8-V',
  17725. 'UniJIS-UCS2-H',
  17726. 'UniJIS-UCS2-HW-H',
  17727. 'UniJIS-UCS2-HW-V',
  17728. 'UniJIS-UCS2-V',
  17729. 'UniJIS-UTF16-H',
  17730. 'UniJIS-UTF16-V',
  17731. 'UniJIS-UTF32-H',
  17732. 'UniJIS-UTF32-V',
  17733. 'UniJIS-UTF8-H',
  17734. 'UniJIS-UTF8-V',
  17735. 'UniJIS2004-UTF16-H',
  17736. 'UniJIS2004-UTF16-V',
  17737. 'UniJIS2004-UTF32-H',
  17738. 'UniJIS2004-UTF32-V',
  17739. 'UniJIS2004-UTF8-H',
  17740. 'UniJIS2004-UTF8-V',
  17741. 'UniJISPro-UCS2-HW-V',
  17742. 'UniJISPro-UCS2-V',
  17743. 'UniJISPro-UTF8-V',
  17744. 'UniJISX0213-UTF32-H',
  17745. 'UniJISX0213-UTF32-V',
  17746. 'UniJISX02132004-UTF32-H',
  17747. 'UniJISX02132004-UTF32-V',
  17748. 'UniKS-UCS2-H',
  17749. 'UniKS-UCS2-V',
  17750. 'UniKS-UTF16-H',
  17751. 'UniKS-UTF16-V',
  17752. 'UniKS-UTF32-H',
  17753. 'UniKS-UTF32-V',
  17754. 'UniKS-UTF8-H',
  17755. 'UniKS-UTF8-V',
  17756. 'V',
  17757. 'WP-Symbol'];
  17758. // CMap, not to be confused with TrueType's cmap.
  17759. var CMap = (function CMapClosure() {
  17760. function CMap(builtInCMap) {
  17761. // Codespace ranges are stored as follows:
  17762. // [[1BytePairs], [2BytePairs], [3BytePairs], [4BytePairs]]
  17763. // where nBytePairs are ranges e.g. [low1, high1, low2, high2, ...]
  17764. this.codespaceRanges = [[], [], [], []];
  17765. this.numCodespaceRanges = 0;
  17766. // Map entries have one of two forms.
  17767. // - cid chars are 16-bit unsigned integers, stored as integers.
  17768. // - bf chars are variable-length byte sequences, stored as strings, with
  17769. // one byte per character.
  17770. this._map = [];
  17771. this.vertical = false;
  17772. this.useCMap = null;
  17773. this.builtInCMap = builtInCMap;
  17774. }
  17775. CMap.prototype = {
  17776. addCodespaceRange: function(n, low, high) {
  17777. this.codespaceRanges[n - 1].push(low, high);
  17778. this.numCodespaceRanges++;
  17779. },
  17780. mapCidRange: function(low, high, dstLow) {
  17781. while (low <= high) {
  17782. this._map[low++] = dstLow++;
  17783. }
  17784. },
  17785. mapBfRange: function(low, high, dstLow) {
  17786. var lastByte = dstLow.length - 1;
  17787. while (low <= high) {
  17788. this._map[low++] = dstLow;
  17789. // Only the last byte has to be incremented.
  17790. dstLow = dstLow.substr(0, lastByte) +
  17791. String.fromCharCode(dstLow.charCodeAt(lastByte) + 1);
  17792. }
  17793. },
  17794. mapBfRangeToArray: function(low, high, array) {
  17795. var i = 0, ii = array.length;
  17796. while (low <= high && i < ii) {
  17797. this._map[low] = array[i++];
  17798. ++low;
  17799. }
  17800. },
  17801. // This is used for both bf and cid chars.
  17802. mapOne: function(src, dst) {
  17803. this._map[src] = dst;
  17804. },
  17805. lookup: function(code) {
  17806. return this._map[code];
  17807. },
  17808. contains: function(code) {
  17809. return this._map[code] !== undefined;
  17810. },
  17811. forEach: function(callback) {
  17812. // Most maps have fewer than 65536 entries, and for those we use normal
  17813. // array iteration. But really sparse tables are possible -- e.g. with
  17814. // indices in the *billions*. For such tables we use for..in, which isn't
  17815. // ideal because it stringifies the indices for all present elements, but
  17816. // it does avoid iterating over every undefined entry.
  17817. var map = this._map;
  17818. var length = map.length;
  17819. var i;
  17820. if (length <= 0x10000) {
  17821. for (i = 0; i < length; i++) {
  17822. if (map[i] !== undefined) {
  17823. callback(i, map[i]);
  17824. }
  17825. }
  17826. } else {
  17827. for (i in this._map) {
  17828. callback(i, map[i]);
  17829. }
  17830. }
  17831. },
  17832. charCodeOf: function(value) {
  17833. return this._map.indexOf(value);
  17834. },
  17835. getMap: function() {
  17836. return this._map;
  17837. },
  17838. readCharCode: function(str, offset, out) {
  17839. var c = 0;
  17840. var codespaceRanges = this.codespaceRanges;
  17841. var codespaceRangesLen = this.codespaceRanges.length;
  17842. // 9.7.6.2 CMap Mapping
  17843. // The code length is at most 4.
  17844. for (var n = 0; n < codespaceRangesLen; n++) {
  17845. c = ((c << 8) | str.charCodeAt(offset + n)) >>> 0;
  17846. // Check each codespace range to see if it falls within.
  17847. var codespaceRange = codespaceRanges[n];
  17848. for (var k = 0, kk = codespaceRange.length; k < kk;) {
  17849. var low = codespaceRange[k++];
  17850. var high = codespaceRange[k++];
  17851. if (c >= low && c <= high) {
  17852. out.charcode = c;
  17853. out.length = n + 1;
  17854. return;
  17855. }
  17856. }
  17857. }
  17858. out.charcode = 0;
  17859. out.length = 1;
  17860. }
  17861. };
  17862. return CMap;
  17863. })();
  17864. // A special case of CMap, where the _map array implicitly has a length of
  17865. // 65535 and each element is equal to its index.
  17866. var IdentityCMap = (function IdentityCMapClosure() {
  17867. function IdentityCMap(vertical, n) {
  17868. CMap.call(this);
  17869. this.vertical = vertical;
  17870. this.addCodespaceRange(n, 0, 0xffff);
  17871. }
  17872. Util.inherit(IdentityCMap, CMap, {});
  17873. IdentityCMap.prototype = {
  17874. addCodespaceRange: CMap.prototype.addCodespaceRange,
  17875. mapCidRange: function(low, high, dstLow) {
  17876. error('should not call mapCidRange');
  17877. },
  17878. mapBfRange: function(low, high, dstLow) {
  17879. error('should not call mapBfRange');
  17880. },
  17881. mapBfRangeToArray: function(low, high, array) {
  17882. error('should not call mapBfRangeToArray');
  17883. },
  17884. mapOne: function(src, dst) {
  17885. error('should not call mapCidOne');
  17886. },
  17887. lookup: function(code) {
  17888. return (isInt(code) && code <= 0xffff) ? code : undefined;
  17889. },
  17890. contains: function(code) {
  17891. return isInt(code) && code <= 0xffff;
  17892. },
  17893. forEach: function(callback) {
  17894. for (var i = 0; i <= 0xffff; i++) {
  17895. callback(i, i);
  17896. }
  17897. },
  17898. charCodeOf: function(value) {
  17899. return (isInt(value) && value <= 0xffff) ? value : -1;
  17900. },
  17901. getMap: function() {
  17902. // Sometimes identity maps must be instantiated, but it's rare.
  17903. var map = new Array(0x10000);
  17904. for (var i = 0; i <= 0xffff; i++) {
  17905. map[i] = i;
  17906. }
  17907. return map;
  17908. },
  17909. readCharCode: CMap.prototype.readCharCode
  17910. };
  17911. return IdentityCMap;
  17912. })();
  17913. var BinaryCMapReader = (function BinaryCMapReaderClosure() {
  17914. function fetchBinaryData(url) {
  17915. var nonBinaryRequest = PDFJS.disableWorker;
  17916. var request = new XMLHttpRequest();
  17917. request.open('GET', url, false);
  17918. if (!nonBinaryRequest) {
  17919. try {
  17920. request.responseType = 'arraybuffer';
  17921. nonBinaryRequest = request.responseType !== 'arraybuffer';
  17922. } catch (e) {
  17923. nonBinaryRequest = true;
  17924. }
  17925. }
  17926. if (nonBinaryRequest && request.overrideMimeType) {
  17927. request.overrideMimeType('text/plain; charset=x-user-defined');
  17928. }
  17929. request.send(null);
  17930. if (nonBinaryRequest ? !request.responseText : !request.response) {
  17931. error('Unable to get binary cMap at: ' + url);
  17932. }
  17933. if (nonBinaryRequest) {
  17934. var data = Array.prototype.map.call(request.responseText, function (ch) {
  17935. return ch.charCodeAt(0) & 255;
  17936. });
  17937. return new Uint8Array(data);
  17938. }
  17939. return new Uint8Array(request.response);
  17940. }
  17941. function hexToInt(a, size) {
  17942. var n = 0;
  17943. for (var i = 0; i <= size; i++) {
  17944. n = (n << 8) | a[i];
  17945. }
  17946. return n >>> 0;
  17947. }
  17948. function hexToStr(a, size) {
  17949. // This code is hot. Special-case some common values to avoid creating an
  17950. // object with subarray().
  17951. if (size === 1) {
  17952. return String.fromCharCode(a[0], a[1]);
  17953. }
  17954. if (size === 3) {
  17955. return String.fromCharCode(a[0], a[1], a[2], a[3]);
  17956. }
  17957. return String.fromCharCode.apply(null, a.subarray(0, size + 1));
  17958. }
  17959. function addHex(a, b, size) {
  17960. var c = 0;
  17961. for (var i = size; i >= 0; i--) {
  17962. c += a[i] + b[i];
  17963. a[i] = c & 255;
  17964. c >>= 8;
  17965. }
  17966. }
  17967. function incHex(a, size) {
  17968. var c = 1;
  17969. for (var i = size; i >= 0 && c > 0; i--) {
  17970. c += a[i];
  17971. a[i] = c & 255;
  17972. c >>= 8;
  17973. }
  17974. }
  17975. var MAX_NUM_SIZE = 16;
  17976. var MAX_ENCODED_NUM_SIZE = 19; // ceil(MAX_NUM_SIZE * 7 / 8)
  17977. function BinaryCMapStream(data) {
  17978. this.buffer = data;
  17979. this.pos = 0;
  17980. this.end = data.length;
  17981. this.tmpBuf = new Uint8Array(MAX_ENCODED_NUM_SIZE);
  17982. }
  17983. BinaryCMapStream.prototype = {
  17984. readByte: function () {
  17985. if (this.pos >= this.end) {
  17986. return -1;
  17987. }
  17988. return this.buffer[this.pos++];
  17989. },
  17990. readNumber: function () {
  17991. var n = 0;
  17992. var last;
  17993. do {
  17994. var b = this.readByte();
  17995. if (b < 0) {
  17996. error('unexpected EOF in bcmap');
  17997. }
  17998. last = !(b & 0x80);
  17999. n = (n << 7) | (b & 0x7F);
  18000. } while (!last);
  18001. return n;
  18002. },
  18003. readSigned: function () {
  18004. var n = this.readNumber();
  18005. return (n & 1) ? ~(n >>> 1) : n >>> 1;
  18006. },
  18007. readHex: function (num, size) {
  18008. num.set(this.buffer.subarray(this.pos,
  18009. this.pos + size + 1));
  18010. this.pos += size + 1;
  18011. },
  18012. readHexNumber: function (num, size) {
  18013. var last;
  18014. var stack = this.tmpBuf, sp = 0;
  18015. do {
  18016. var b = this.readByte();
  18017. if (b < 0) {
  18018. error('unexpected EOF in bcmap');
  18019. }
  18020. last = !(b & 0x80);
  18021. stack[sp++] = b & 0x7F;
  18022. } while (!last);
  18023. var i = size, buffer = 0, bufferSize = 0;
  18024. while (i >= 0) {
  18025. while (bufferSize < 8 && stack.length > 0) {
  18026. buffer = (stack[--sp] << bufferSize) | buffer;
  18027. bufferSize += 7;
  18028. }
  18029. num[i] = buffer & 255;
  18030. i--;
  18031. buffer >>= 8;
  18032. bufferSize -= 8;
  18033. }
  18034. },
  18035. readHexSigned: function (num, size) {
  18036. this.readHexNumber(num, size);
  18037. var sign = num[size] & 1 ? 255 : 0;
  18038. var c = 0;
  18039. for (var i = 0; i <= size; i++) {
  18040. c = ((c & 1) << 8) | num[i];
  18041. num[i] = (c >> 1) ^ sign;
  18042. }
  18043. },
  18044. readString: function () {
  18045. var len = this.readNumber();
  18046. var s = '';
  18047. for (var i = 0; i < len; i++) {
  18048. s += String.fromCharCode(this.readNumber());
  18049. }
  18050. return s;
  18051. }
  18052. };
  18053. function processBinaryCMap(url, cMap, extend) {
  18054. var data = fetchBinaryData(url);
  18055. var stream = new BinaryCMapStream(data);
  18056. var header = stream.readByte();
  18057. cMap.vertical = !!(header & 1);
  18058. var useCMap = null;
  18059. var start = new Uint8Array(MAX_NUM_SIZE);
  18060. var end = new Uint8Array(MAX_NUM_SIZE);
  18061. var char = new Uint8Array(MAX_NUM_SIZE);
  18062. var charCode = new Uint8Array(MAX_NUM_SIZE);
  18063. var tmp = new Uint8Array(MAX_NUM_SIZE);
  18064. var code;
  18065. var b;
  18066. while ((b = stream.readByte()) >= 0) {
  18067. var type = b >> 5;
  18068. if (type === 7) { // metadata, e.g. comment or usecmap
  18069. switch (b & 0x1F) {
  18070. case 0:
  18071. stream.readString(); // skipping comment
  18072. break;
  18073. case 1:
  18074. useCMap = stream.readString();
  18075. break;
  18076. }
  18077. continue;
  18078. }
  18079. var sequence = !!(b & 0x10);
  18080. var dataSize = b & 15;
  18081. assert(dataSize + 1 <= MAX_NUM_SIZE);
  18082. var ucs2DataSize = 1;
  18083. var subitemsCount = stream.readNumber();
  18084. var i;
  18085. switch (type) {
  18086. case 0: // codespacerange
  18087. stream.readHex(start, dataSize);
  18088. stream.readHexNumber(end, dataSize);
  18089. addHex(end, start, dataSize);
  18090. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
  18091. hexToInt(end, dataSize));
  18092. for (i = 1; i < subitemsCount; i++) {
  18093. incHex(end, dataSize);
  18094. stream.readHexNumber(start, dataSize);
  18095. addHex(start, end, dataSize);
  18096. stream.readHexNumber(end, dataSize);
  18097. addHex(end, start, dataSize);
  18098. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
  18099. hexToInt(end, dataSize));
  18100. }
  18101. break;
  18102. case 1: // notdefrange
  18103. stream.readHex(start, dataSize);
  18104. stream.readHexNumber(end, dataSize);
  18105. addHex(end, start, dataSize);
  18106. code = stream.readNumber();
  18107. // undefined range, skipping
  18108. for (i = 1; i < subitemsCount; i++) {
  18109. incHex(end, dataSize);
  18110. stream.readHexNumber(start, dataSize);
  18111. addHex(start, end, dataSize);
  18112. stream.readHexNumber(end, dataSize);
  18113. addHex(end, start, dataSize);
  18114. code = stream.readNumber();
  18115. // nop
  18116. }
  18117. break;
  18118. case 2: // cidchar
  18119. stream.readHex(char, dataSize);
  18120. code = stream.readNumber();
  18121. cMap.mapOne(hexToInt(char, dataSize), code);
  18122. for (i = 1; i < subitemsCount; i++) {
  18123. incHex(char, dataSize);
  18124. if (!sequence) {
  18125. stream.readHexNumber(tmp, dataSize);
  18126. addHex(char, tmp, dataSize);
  18127. }
  18128. code = stream.readSigned() + (code + 1);
  18129. cMap.mapOne(hexToInt(char, dataSize), code);
  18130. }
  18131. break;
  18132. case 3: // cidrange
  18133. stream.readHex(start, dataSize);
  18134. stream.readHexNumber(end, dataSize);
  18135. addHex(end, start, dataSize);
  18136. code = stream.readNumber();
  18137. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize),
  18138. code);
  18139. for (i = 1; i < subitemsCount; i++) {
  18140. incHex(end, dataSize);
  18141. if (!sequence) {
  18142. stream.readHexNumber(start, dataSize);
  18143. addHex(start, end, dataSize);
  18144. } else {
  18145. start.set(end);
  18146. }
  18147. stream.readHexNumber(end, dataSize);
  18148. addHex(end, start, dataSize);
  18149. code = stream.readNumber();
  18150. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize),
  18151. code);
  18152. }
  18153. break;
  18154. case 4: // bfchar
  18155. stream.readHex(char, ucs2DataSize);
  18156. stream.readHex(charCode, dataSize);
  18157. cMap.mapOne(hexToInt(char, ucs2DataSize),
  18158. hexToStr(charCode, dataSize));
  18159. for (i = 1; i < subitemsCount; i++) {
  18160. incHex(char, ucs2DataSize);
  18161. if (!sequence) {
  18162. stream.readHexNumber(tmp, ucs2DataSize);
  18163. addHex(char, tmp, ucs2DataSize);
  18164. }
  18165. incHex(charCode, dataSize);
  18166. stream.readHexSigned(tmp, dataSize);
  18167. addHex(charCode, tmp, dataSize);
  18168. cMap.mapOne(hexToInt(char, ucs2DataSize),
  18169. hexToStr(charCode, dataSize));
  18170. }
  18171. break;
  18172. case 5: // bfrange
  18173. stream.readHex(start, ucs2DataSize);
  18174. stream.readHexNumber(end, ucs2DataSize);
  18175. addHex(end, start, ucs2DataSize);
  18176. stream.readHex(charCode, dataSize);
  18177. cMap.mapBfRange(hexToInt(start, ucs2DataSize),
  18178. hexToInt(end, ucs2DataSize),
  18179. hexToStr(charCode, dataSize));
  18180. for (i = 1; i < subitemsCount; i++) {
  18181. incHex(end, ucs2DataSize);
  18182. if (!sequence) {
  18183. stream.readHexNumber(start, ucs2DataSize);
  18184. addHex(start, end, ucs2DataSize);
  18185. } else {
  18186. start.set(end);
  18187. }
  18188. stream.readHexNumber(end, ucs2DataSize);
  18189. addHex(end, start, ucs2DataSize);
  18190. stream.readHex(charCode, dataSize);
  18191. cMap.mapBfRange(hexToInt(start, ucs2DataSize),
  18192. hexToInt(end, ucs2DataSize),
  18193. hexToStr(charCode, dataSize));
  18194. }
  18195. break;
  18196. default:
  18197. error('Unknown type: ' + type);
  18198. break;
  18199. }
  18200. }
  18201. if (useCMap) {
  18202. extend(useCMap);
  18203. }
  18204. return cMap;
  18205. }
  18206. function BinaryCMapReader() {}
  18207. BinaryCMapReader.prototype = {
  18208. read: processBinaryCMap
  18209. };
  18210. return BinaryCMapReader;
  18211. })();
  18212. var CMapFactory = (function CMapFactoryClosure() {
  18213. function strToInt(str) {
  18214. var a = 0;
  18215. for (var i = 0; i < str.length; i++) {
  18216. a = (a << 8) | str.charCodeAt(i);
  18217. }
  18218. return a >>> 0;
  18219. }
  18220. function expectString(obj) {
  18221. if (!isString(obj)) {
  18222. error('Malformed CMap: expected string.');
  18223. }
  18224. }
  18225. function expectInt(obj) {
  18226. if (!isInt(obj)) {
  18227. error('Malformed CMap: expected int.');
  18228. }
  18229. }
  18230. function parseBfChar(cMap, lexer) {
  18231. while (true) {
  18232. var obj = lexer.getObj();
  18233. if (isEOF(obj)) {
  18234. break;
  18235. }
  18236. if (isCmd(obj, 'endbfchar')) {
  18237. return;
  18238. }
  18239. expectString(obj);
  18240. var src = strToInt(obj);
  18241. obj = lexer.getObj();
  18242. // TODO are /dstName used?
  18243. expectString(obj);
  18244. var dst = obj;
  18245. cMap.mapOne(src, dst);
  18246. }
  18247. }
  18248. function parseBfRange(cMap, lexer) {
  18249. while (true) {
  18250. var obj = lexer.getObj();
  18251. if (isEOF(obj)) {
  18252. break;
  18253. }
  18254. if (isCmd(obj, 'endbfrange')) {
  18255. return;
  18256. }
  18257. expectString(obj);
  18258. var low = strToInt(obj);
  18259. obj = lexer.getObj();
  18260. expectString(obj);
  18261. var high = strToInt(obj);
  18262. obj = lexer.getObj();
  18263. if (isInt(obj) || isString(obj)) {
  18264. var dstLow = isInt(obj) ? String.fromCharCode(obj) : obj;
  18265. cMap.mapBfRange(low, high, dstLow);
  18266. } else if (isCmd(obj, '[')) {
  18267. obj = lexer.getObj();
  18268. var array = [];
  18269. while (!isCmd(obj, ']') && !isEOF(obj)) {
  18270. array.push(obj);
  18271. obj = lexer.getObj();
  18272. }
  18273. cMap.mapBfRangeToArray(low, high, array);
  18274. } else {
  18275. break;
  18276. }
  18277. }
  18278. error('Invalid bf range.');
  18279. }
  18280. function parseCidChar(cMap, lexer) {
  18281. while (true) {
  18282. var obj = lexer.getObj();
  18283. if (isEOF(obj)) {
  18284. break;
  18285. }
  18286. if (isCmd(obj, 'endcidchar')) {
  18287. return;
  18288. }
  18289. expectString(obj);
  18290. var src = strToInt(obj);
  18291. obj = lexer.getObj();
  18292. expectInt(obj);
  18293. var dst = obj;
  18294. cMap.mapOne(src, dst);
  18295. }
  18296. }
  18297. function parseCidRange(cMap, lexer) {
  18298. while (true) {
  18299. var obj = lexer.getObj();
  18300. if (isEOF(obj)) {
  18301. break;
  18302. }
  18303. if (isCmd(obj, 'endcidrange')) {
  18304. return;
  18305. }
  18306. expectString(obj);
  18307. var low = strToInt(obj);
  18308. obj = lexer.getObj();
  18309. expectString(obj);
  18310. var high = strToInt(obj);
  18311. obj = lexer.getObj();
  18312. expectInt(obj);
  18313. var dstLow = obj;
  18314. cMap.mapCidRange(low, high, dstLow);
  18315. }
  18316. }
  18317. function parseCodespaceRange(cMap, lexer) {
  18318. while (true) {
  18319. var obj = lexer.getObj();
  18320. if (isEOF(obj)) {
  18321. break;
  18322. }
  18323. if (isCmd(obj, 'endcodespacerange')) {
  18324. return;
  18325. }
  18326. if (!isString(obj)) {
  18327. break;
  18328. }
  18329. var low = strToInt(obj);
  18330. obj = lexer.getObj();
  18331. if (!isString(obj)) {
  18332. break;
  18333. }
  18334. var high = strToInt(obj);
  18335. cMap.addCodespaceRange(obj.length, low, high);
  18336. }
  18337. error('Invalid codespace range.');
  18338. }
  18339. function parseWMode(cMap, lexer) {
  18340. var obj = lexer.getObj();
  18341. if (isInt(obj)) {
  18342. cMap.vertical = !!obj;
  18343. }
  18344. }
  18345. function parseCMap(cMap, lexer, builtInCMapParams, useCMap) {
  18346. var previous;
  18347. var embededUseCMap;
  18348. objLoop: while (true) {
  18349. var obj = lexer.getObj();
  18350. if (isEOF(obj)) {
  18351. break;
  18352. } else if (isName(obj)) {
  18353. if (obj.name === 'WMode') {
  18354. parseWMode(cMap, lexer);
  18355. }
  18356. previous = obj;
  18357. } else if (isCmd(obj)) {
  18358. switch (obj.cmd) {
  18359. case 'endcmap':
  18360. break objLoop;
  18361. case 'usecmap':
  18362. if (isName(previous)) {
  18363. embededUseCMap = previous.name;
  18364. }
  18365. break;
  18366. case 'begincodespacerange':
  18367. parseCodespaceRange(cMap, lexer);
  18368. break;
  18369. case 'beginbfchar':
  18370. parseBfChar(cMap, lexer);
  18371. break;
  18372. case 'begincidchar':
  18373. parseCidChar(cMap, lexer);
  18374. break;
  18375. case 'beginbfrange':
  18376. parseBfRange(cMap, lexer);
  18377. break;
  18378. case 'begincidrange':
  18379. parseCidRange(cMap, lexer);
  18380. break;
  18381. }
  18382. }
  18383. }
  18384. if (!useCMap && embededUseCMap) {
  18385. // Load the usecmap definition from the file only if there wasn't one
  18386. // specified.
  18387. useCMap = embededUseCMap;
  18388. }
  18389. if (useCMap) {
  18390. extendCMap(cMap, builtInCMapParams, useCMap);
  18391. }
  18392. }
  18393. function extendCMap(cMap, builtInCMapParams, useCMap) {
  18394. cMap.useCMap = createBuiltInCMap(useCMap, builtInCMapParams);
  18395. // If there aren't any code space ranges defined clone all the parent ones
  18396. // into this cMap.
  18397. if (cMap.numCodespaceRanges === 0) {
  18398. var useCodespaceRanges = cMap.useCMap.codespaceRanges;
  18399. for (var i = 0; i < useCodespaceRanges.length; i++) {
  18400. cMap.codespaceRanges[i] = useCodespaceRanges[i].slice();
  18401. }
  18402. cMap.numCodespaceRanges = cMap.useCMap.numCodespaceRanges;
  18403. }
  18404. // Merge the map into the current one, making sure not to override
  18405. // any previously defined entries.
  18406. cMap.useCMap.forEach(function(key, value) {
  18407. if (!cMap.contains(key)) {
  18408. cMap.mapOne(key, cMap.useCMap.lookup(key));
  18409. }
  18410. });
  18411. }
  18412. function parseBinaryCMap(name, builtInCMapParams) {
  18413. var url = builtInCMapParams.url + name + '.bcmap';
  18414. var cMap = new CMap(true);
  18415. new BinaryCMapReader().read(url, cMap, function (useCMap) {
  18416. extendCMap(cMap, builtInCMapParams, useCMap);
  18417. });
  18418. return cMap;
  18419. }
  18420. function createBuiltInCMap(name, builtInCMapParams) {
  18421. if (name === 'Identity-H') {
  18422. return new IdentityCMap(false, 2);
  18423. } else if (name === 'Identity-V') {
  18424. return new IdentityCMap(true, 2);
  18425. }
  18426. if (BUILT_IN_CMAPS.indexOf(name) === -1) {
  18427. error('Unknown cMap name: ' + name);
  18428. }
  18429. assert(builtInCMapParams, 'built-in cMap parameters are not provided');
  18430. if (builtInCMapParams.packed) {
  18431. return parseBinaryCMap(name, builtInCMapParams);
  18432. }
  18433. var request = new XMLHttpRequest();
  18434. var url = builtInCMapParams.url + name;
  18435. request.open('GET', url, false);
  18436. request.send(null);
  18437. if (!request.responseText) {
  18438. error('Unable to get cMap at: ' + url);
  18439. }
  18440. var cMap = new CMap(true);
  18441. var lexer = new Lexer(new StringStream(request.responseText));
  18442. parseCMap(cMap, lexer, builtInCMapParams, null);
  18443. return cMap;
  18444. }
  18445. return {
  18446. create: function (encoding, builtInCMapParams, useCMap) {
  18447. if (isName(encoding)) {
  18448. return createBuiltInCMap(encoding.name, builtInCMapParams);
  18449. } else if (isStream(encoding)) {
  18450. var cMap = new CMap();
  18451. var lexer = new Lexer(encoding);
  18452. try {
  18453. parseCMap(cMap, lexer, builtInCMapParams, useCMap);
  18454. } catch (e) {
  18455. warn('Invalid CMap data. ' + e);
  18456. }
  18457. return cMap;
  18458. }
  18459. error('Encoding required.');
  18460. }
  18461. };
  18462. })();
  18463. // Unicode Private Use Area
  18464. var PRIVATE_USE_OFFSET_START = 0xE000;
  18465. var PRIVATE_USE_OFFSET_END = 0xF8FF;
  18466. var SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = false;
  18467. // PDF Glyph Space Units are one Thousandth of a TextSpace Unit
  18468. // except for Type 3 fonts
  18469. var PDF_GLYPH_SPACE_UNITS = 1000;
  18470. // Hinting is currently disabled due to unknown problems on windows
  18471. // in tracemonkey and various other pdfs with type1 fonts.
  18472. var HINTING_ENABLED = false;
  18473. // Accented charactars are not displayed properly on windows, using this flag
  18474. // to control analysis of seac charstrings.
  18475. var SEAC_ANALYSIS_ENABLED = false;
  18476. var FontFlags = {
  18477. FixedPitch: 1,
  18478. Serif: 2,
  18479. Symbolic: 4,
  18480. Script: 8,
  18481. Nonsymbolic: 32,
  18482. Italic: 64,
  18483. AllCap: 65536,
  18484. SmallCap: 131072,
  18485. ForceBold: 262144
  18486. };
  18487. var Encodings = {
  18488. ExpertEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18489. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18490. 'space', 'exclamsmall', 'Hungarumlautsmall', '', 'dollaroldstyle',
  18491. 'dollarsuperior', 'ampersandsmall', 'Acutesmall', 'parenleftsuperior',
  18492. 'parenrightsuperior', 'twodotenleader', 'onedotenleader', 'comma',
  18493. 'hyphen', 'period', 'fraction', 'zerooldstyle', 'oneoldstyle',
  18494. 'twooldstyle', 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle',
  18495. 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle', 'colon',
  18496. 'semicolon', 'commasuperior', 'threequartersemdash', 'periodsuperior',
  18497. 'questionsmall', '', 'asuperior', 'bsuperior', 'centsuperior', 'dsuperior',
  18498. 'esuperior', '', '', 'isuperior', '', '', 'lsuperior', 'msuperior',
  18499. 'nsuperior', 'osuperior', '', '', 'rsuperior', 'ssuperior', 'tsuperior',
  18500. '', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior', '',
  18501. 'parenrightinferior', 'Circumflexsmall', 'hyphensuperior', 'Gravesmall',
  18502. 'Asmall', 'Bsmall', 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall',
  18503. 'Hsmall', 'Ismall', 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall',
  18504. 'Osmall', 'Psmall', 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall',
  18505. 'Vsmall', 'Wsmall', 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary',
  18506. 'onefitted', 'rupiah', 'Tildesmall', '', '', '', '', '', '', '', '', '',
  18507. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18508. '', '', '', '', '', '', 'exclamdownsmall', 'centoldstyle', 'Lslashsmall',
  18509. '', '', 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall', 'Brevesmall',
  18510. 'Caronsmall', '', 'Dotaccentsmall', '', '', 'Macronsmall', '', '',
  18511. 'figuredash', 'hypheninferior', '', '', 'Ogoneksmall', 'Ringsmall',
  18512. 'Cedillasmall', '', '', '', 'onequarter', 'onehalf', 'threequarters',
  18513. 'questiondownsmall', 'oneeighth', 'threeeighths', 'fiveeighths',
  18514. 'seveneighths', 'onethird', 'twothirds', '', '', 'zerosuperior',
  18515. 'onesuperior', 'twosuperior', 'threesuperior', 'foursuperior',
  18516. 'fivesuperior', 'sixsuperior', 'sevensuperior', 'eightsuperior',
  18517. 'ninesuperior', 'zeroinferior', 'oneinferior', 'twoinferior',
  18518. 'threeinferior', 'fourinferior', 'fiveinferior', 'sixinferior',
  18519. 'seveninferior', 'eightinferior', 'nineinferior', 'centinferior',
  18520. 'dollarinferior', 'periodinferior', 'commainferior', 'Agravesmall',
  18521. 'Aacutesmall', 'Acircumflexsmall', 'Atildesmall', 'Adieresissmall',
  18522. 'Aringsmall', 'AEsmall', 'Ccedillasmall', 'Egravesmall', 'Eacutesmall',
  18523. 'Ecircumflexsmall', 'Edieresissmall', 'Igravesmall', 'Iacutesmall',
  18524. 'Icircumflexsmall', 'Idieresissmall', 'Ethsmall', 'Ntildesmall',
  18525. 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall', 'Otildesmall',
  18526. 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall', 'Uacutesmall',
  18527. 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall', 'Thornsmall',
  18528. 'Ydieresissmall'],
  18529. MacExpertEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18530. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18531. 'space', 'exclamsmall', 'Hungarumlautsmall', 'centoldstyle',
  18532. 'dollaroldstyle', 'dollarsuperior', 'ampersandsmall', 'Acutesmall',
  18533. 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  18534. 'onedotenleader', 'comma', 'hyphen', 'period', 'fraction', 'zerooldstyle',
  18535. 'oneoldstyle', 'twooldstyle', 'threeoldstyle', 'fouroldstyle',
  18536. 'fiveoldstyle', 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle',
  18537. 'nineoldstyle', 'colon', 'semicolon', '', 'threequartersemdash', '',
  18538. 'questionsmall', '', '', '', '', 'Ethsmall', '', '', 'onequarter',
  18539. 'onehalf', 'threequarters', 'oneeighth', 'threeeighths', 'fiveeighths',
  18540. 'seveneighths', 'onethird', 'twothirds', '', '', '', '', '', '', 'ff',
  18541. 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior', '', 'parenrightinferior',
  18542. 'Circumflexsmall', 'hypheninferior', 'Gravesmall', 'Asmall', 'Bsmall',
  18543. 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall', 'Hsmall', 'Ismall',
  18544. 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall', 'Osmall', 'Psmall',
  18545. 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall', 'Vsmall', 'Wsmall',
  18546. 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary', 'onefitted', 'rupiah',
  18547. 'Tildesmall', '', '', 'asuperior', 'centsuperior', '', '', '', '',
  18548. 'Aacutesmall', 'Agravesmall', 'Acircumflexsmall', 'Adieresissmall',
  18549. 'Atildesmall', 'Aringsmall', 'Ccedillasmall', 'Eacutesmall', 'Egravesmall',
  18550. 'Ecircumflexsmall', 'Edieresissmall', 'Iacutesmall', 'Igravesmall',
  18551. 'Icircumflexsmall', 'Idieresissmall', 'Ntildesmall', 'Oacutesmall',
  18552. 'Ogravesmall', 'Ocircumflexsmall', 'Odieresissmall', 'Otildesmall',
  18553. 'Uacutesmall', 'Ugravesmall', 'Ucircumflexsmall', 'Udieresissmall', '',
  18554. 'eightsuperior', 'fourinferior', 'threeinferior', 'sixinferior',
  18555. 'eightinferior', 'seveninferior', 'Scaronsmall', '', 'centinferior',
  18556. 'twoinferior', '', 'Dieresissmall', '', 'Caronsmall', 'osuperior',
  18557. 'fiveinferior', '', 'commainferior', 'periodinferior', 'Yacutesmall', '',
  18558. 'dollarinferior', '', 'Thornsmall', '', 'nineinferior', 'zeroinferior',
  18559. 'Zcaronsmall', 'AEsmall', 'Oslashsmall', 'questiondownsmall',
  18560. 'oneinferior', 'Lslashsmall', '', '', '', '', '', '', 'Cedillasmall', '',
  18561. '', '', '', '', 'OEsmall', 'figuredash', 'hyphensuperior', '', '', '', '',
  18562. 'exclamdownsmall', '', 'Ydieresissmall', '', 'onesuperior', 'twosuperior',
  18563. 'threesuperior', 'foursuperior', 'fivesuperior', 'sixsuperior',
  18564. 'sevensuperior', 'ninesuperior', 'zerosuperior', '', 'esuperior',
  18565. 'rsuperior', 'tsuperior', '', '', 'isuperior', 'ssuperior', 'dsuperior',
  18566. '', '', '', '', '', 'lsuperior', 'Ogoneksmall', 'Brevesmall',
  18567. 'Macronsmall', 'bsuperior', 'nsuperior', 'msuperior', 'commasuperior',
  18568. 'periodsuperior', 'Dotaccentsmall', 'Ringsmall'],
  18569. MacRomanEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18570. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18571. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  18572. 'ampersand', 'quotesingle', 'parenleft', 'parenright', 'asterisk', 'plus',
  18573. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  18574. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  18575. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  18576. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  18577. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  18578. 'asciicircum', 'underscore', 'grave', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
  18579. 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
  18580. 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde', '',
  18581. 'Adieresis', 'Aring', 'Ccedilla', 'Eacute', 'Ntilde', 'Odieresis',
  18582. 'Udieresis', 'aacute', 'agrave', 'acircumflex', 'adieresis', 'atilde',
  18583. 'aring', 'ccedilla', 'eacute', 'egrave', 'ecircumflex', 'edieresis',
  18584. 'iacute', 'igrave', 'icircumflex', 'idieresis', 'ntilde', 'oacute',
  18585. 'ograve', 'ocircumflex', 'odieresis', 'otilde', 'uacute', 'ugrave',
  18586. 'ucircumflex', 'udieresis', 'dagger', 'degree', 'cent', 'sterling',
  18587. 'section', 'bullet', 'paragraph', 'germandbls', 'registered', 'copyright',
  18588. 'trademark', 'acute', 'dieresis', 'notequal', 'AE', 'Oslash', 'infinity',
  18589. 'plusminus', 'lessequal', 'greaterequal', 'yen', 'mu', 'partialdiff',
  18590. 'summation', 'product', 'pi', 'integral', 'ordfeminine', 'ordmasculine',
  18591. 'Omega', 'ae', 'oslash', 'questiondown', 'exclamdown', 'logicalnot',
  18592. 'radical', 'florin', 'approxequal', 'Delta', 'guillemotleft',
  18593. 'guillemotright', 'ellipsis', 'space', 'Agrave', 'Atilde', 'Otilde', 'OE',
  18594. 'oe', 'endash', 'emdash', 'quotedblleft', 'quotedblright', 'quoteleft',
  18595. 'quoteright', 'divide', 'lozenge', 'ydieresis', 'Ydieresis', 'fraction',
  18596. 'currency', 'guilsinglleft', 'guilsinglright', 'fi', 'fl', 'daggerdbl',
  18597. 'periodcentered', 'quotesinglbase', 'quotedblbase', 'perthousand',
  18598. 'Acircumflex', 'Ecircumflex', 'Aacute', 'Edieresis', 'Egrave', 'Iacute',
  18599. 'Icircumflex', 'Idieresis', 'Igrave', 'Oacute', 'Ocircumflex', 'apple',
  18600. 'Ograve', 'Uacute', 'Ucircumflex', 'Ugrave', 'dotlessi', 'circumflex',
  18601. 'tilde', 'macron', 'breve', 'dotaccent', 'ring', 'cedilla', 'hungarumlaut',
  18602. 'ogonek', 'caron'],
  18603. StandardEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18604. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18605. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  18606. 'ampersand', 'quoteright', 'parenleft', 'parenright', 'asterisk', 'plus',
  18607. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  18608. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  18609. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  18610. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  18611. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  18612. 'asciicircum', 'underscore', 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f',
  18613. 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u',
  18614. 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde',
  18615. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18616. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', 'exclamdown',
  18617. 'cent', 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  18618. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  18619. 'guilsinglright', 'fi', 'fl', '', 'endash', 'dagger', 'daggerdbl',
  18620. 'periodcentered', '', 'paragraph', 'bullet', 'quotesinglbase',
  18621. 'quotedblbase', 'quotedblright', 'guillemotright', 'ellipsis',
  18622. 'perthousand', '', 'questiondown', '', 'grave', 'acute', 'circumflex',
  18623. 'tilde', 'macron', 'breve', 'dotaccent', 'dieresis', '', 'ring', 'cedilla',
  18624. '', 'hungarumlaut', 'ogonek', 'caron', 'emdash', '', '', '', '', '', '',
  18625. '', '', '', '', '', '', '', '', '', '', 'AE', '', 'ordfeminine', '', '',
  18626. '', '', 'Lslash', 'Oslash', 'OE', 'ordmasculine', '', '', '', '', '', 'ae',
  18627. '', '', '', 'dotlessi', '', '', 'lslash', 'oslash', 'oe', 'germandbls'],
  18628. WinAnsiEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18629. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18630. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  18631. 'ampersand', 'quotesingle', 'parenleft', 'parenright', 'asterisk', 'plus',
  18632. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  18633. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  18634. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  18635. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  18636. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  18637. 'asciicircum', 'underscore', 'grave', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
  18638. 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
  18639. 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde',
  18640. 'bullet', 'Euro', 'bullet', 'quotesinglbase', 'florin', 'quotedblbase',
  18641. 'ellipsis', 'dagger', 'daggerdbl', 'circumflex', 'perthousand', 'Scaron',
  18642. 'guilsinglleft', 'OE', 'bullet', 'Zcaron', 'bullet', 'bullet', 'quoteleft',
  18643. 'quoteright', 'quotedblleft', 'quotedblright', 'bullet', 'endash',
  18644. 'emdash', 'tilde', 'trademark', 'scaron', 'guilsinglright', 'oe', 'bullet',
  18645. 'zcaron', 'Ydieresis', 'space', 'exclamdown', 'cent', 'sterling',
  18646. 'currency', 'yen', 'brokenbar', 'section', 'dieresis', 'copyright',
  18647. 'ordfeminine', 'guillemotleft', 'logicalnot', 'hyphen', 'registered',
  18648. 'macron', 'degree', 'plusminus', 'twosuperior', 'threesuperior', 'acute',
  18649. 'mu', 'paragraph', 'periodcentered', 'cedilla', 'onesuperior',
  18650. 'ordmasculine', 'guillemotright', 'onequarter', 'onehalf', 'threequarters',
  18651. 'questiondown', 'Agrave', 'Aacute', 'Acircumflex', 'Atilde', 'Adieresis',
  18652. 'Aring', 'AE', 'Ccedilla', 'Egrave', 'Eacute', 'Ecircumflex', 'Edieresis',
  18653. 'Igrave', 'Iacute', 'Icircumflex', 'Idieresis', 'Eth', 'Ntilde', 'Ograve',
  18654. 'Oacute', 'Ocircumflex', 'Otilde', 'Odieresis', 'multiply', 'Oslash',
  18655. 'Ugrave', 'Uacute', 'Ucircumflex', 'Udieresis', 'Yacute', 'Thorn',
  18656. 'germandbls', 'agrave', 'aacute', 'acircumflex', 'atilde', 'adieresis',
  18657. 'aring', 'ae', 'ccedilla', 'egrave', 'eacute', 'ecircumflex', 'edieresis',
  18658. 'igrave', 'iacute', 'icircumflex', 'idieresis', 'eth', 'ntilde', 'ograve',
  18659. 'oacute', 'ocircumflex', 'otilde', 'odieresis', 'divide', 'oslash',
  18660. 'ugrave', 'uacute', 'ucircumflex', 'udieresis', 'yacute', 'thorn',
  18661. 'ydieresis'],
  18662. SymbolSetEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18663. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18664. 'space', 'exclam', 'universal', 'numbersign', 'existential', 'percent',
  18665. 'ampersand', 'suchthat', 'parenleft', 'parenright', 'asteriskmath', 'plus',
  18666. 'comma', 'minus', 'period', 'slash', 'zero', 'one', 'two', 'three', 'four',
  18667. 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon', 'less',
  18668. 'equal', 'greater', 'question', 'congruent', 'Alpha', 'Beta', 'Chi',
  18669. 'Delta', 'Epsilon', 'Phi', 'Gamma', 'Eta', 'Iota', 'theta1', 'Kappa',
  18670. 'Lambda', 'Mu', 'Nu', 'Omicron', 'Pi', 'Theta', 'Rho', 'Sigma', 'Tau',
  18671. 'Upsilon', 'sigma1', 'Omega', 'Xi', 'Psi', 'Zeta', 'bracketleft',
  18672. 'therefore', 'bracketright', 'perpendicular', 'underscore', 'radicalex',
  18673. 'alpha', 'beta', 'chi', 'delta', 'epsilon', 'phi', 'gamma', 'eta', 'iota',
  18674. 'phi1', 'kappa', 'lambda', 'mu', 'nu', 'omicron', 'pi', 'theta', 'rho',
  18675. 'sigma', 'tau', 'upsilon', 'omega1', 'omega', 'xi', 'psi', 'zeta',
  18676. 'braceleft', 'bar', 'braceright', 'similar', '', '', '', '', '', '', '',
  18677. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18678. '', '', '', '', '', '', '', 'Euro', 'Upsilon1', 'minute', 'lessequal',
  18679. 'fraction', 'infinity', 'florin', 'club', 'diamond', 'heart', 'spade',
  18680. 'arrowboth', 'arrowleft', 'arrowup', 'arrowright', 'arrowdown', 'degree',
  18681. 'plusminus', 'second', 'greaterequal', 'multiply', 'proportional',
  18682. 'partialdiff', 'bullet', 'divide', 'notequal', 'equivalence',
  18683. 'approxequal', 'ellipsis', 'arrowvertex', 'arrowhorizex', 'carriagereturn',
  18684. 'aleph', 'Ifraktur', 'Rfraktur', 'weierstrass', 'circlemultiply',
  18685. 'circleplus', 'emptyset', 'intersection', 'union', 'propersuperset',
  18686. 'reflexsuperset', 'notsubset', 'propersubset', 'reflexsubset', 'element',
  18687. 'notelement', 'angle', 'gradient', 'registerserif', 'copyrightserif',
  18688. 'trademarkserif', 'product', 'radical', 'dotmath', 'logicalnot',
  18689. 'logicaland', 'logicalor', 'arrowdblboth', 'arrowdblleft', 'arrowdblup',
  18690. 'arrowdblright', 'arrowdbldown', 'lozenge', 'angleleft', 'registersans',
  18691. 'copyrightsans', 'trademarksans', 'summation', 'parenlefttp',
  18692. 'parenleftex', 'parenleftbt', 'bracketlefttp', 'bracketleftex',
  18693. 'bracketleftbt', 'bracelefttp', 'braceleftmid', 'braceleftbt', 'braceex',
  18694. '', 'angleright', 'integral', 'integraltp', 'integralex', 'integralbt',
  18695. 'parenrighttp', 'parenrightex', 'parenrightbt', 'bracketrighttp',
  18696. 'bracketrightex', 'bracketrightbt', 'bracerighttp', 'bracerightmid',
  18697. 'bracerightbt'],
  18698. ZapfDingbatsEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18699. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18700. 'space', 'a1', 'a2', 'a202', 'a3', 'a4', 'a5', 'a119', 'a118', 'a117',
  18701. 'a11', 'a12', 'a13', 'a14', 'a15', 'a16', 'a105', 'a17', 'a18', 'a19',
  18702. 'a20', 'a21', 'a22', 'a23', 'a24', 'a25', 'a26', 'a27', 'a28', 'a6', 'a7',
  18703. 'a8', 'a9', 'a10', 'a29', 'a30', 'a31', 'a32', 'a33', 'a34', 'a35', 'a36',
  18704. 'a37', 'a38', 'a39', 'a40', 'a41', 'a42', 'a43', 'a44', 'a45', 'a46',
  18705. 'a47', 'a48', 'a49', 'a50', 'a51', 'a52', 'a53', 'a54', 'a55', 'a56',
  18706. 'a57', 'a58', 'a59', 'a60', 'a61', 'a62', 'a63', 'a64', 'a65', 'a66',
  18707. 'a67', 'a68', 'a69', 'a70', 'a71', 'a72', 'a73', 'a74', 'a203', 'a75',
  18708. 'a204', 'a76', 'a77', 'a78', 'a79', 'a81', 'a82', 'a83', 'a84', 'a97',
  18709. 'a98', 'a99', 'a100', '', 'a89', 'a90', 'a93', 'a94', 'a91', 'a92', 'a205',
  18710. 'a85', 'a206', 'a86', 'a87', 'a88', 'a95', 'a96', '', '', '', '', '', '',
  18711. '', '', '', '', '', '', '', '', '', '', '', '', '', 'a101', 'a102', 'a103',
  18712. 'a104', 'a106', 'a107', 'a108', 'a112', 'a111', 'a110', 'a109', 'a120',
  18713. 'a121', 'a122', 'a123', 'a124', 'a125', 'a126', 'a127', 'a128', 'a129',
  18714. 'a130', 'a131', 'a132', 'a133', 'a134', 'a135', 'a136', 'a137', 'a138',
  18715. 'a139', 'a140', 'a141', 'a142', 'a143', 'a144', 'a145', 'a146', 'a147',
  18716. 'a148', 'a149', 'a150', 'a151', 'a152', 'a153', 'a154', 'a155', 'a156',
  18717. 'a157', 'a158', 'a159', 'a160', 'a161', 'a163', 'a164', 'a196', 'a165',
  18718. 'a192', 'a166', 'a167', 'a168', 'a169', 'a170', 'a171', 'a172', 'a173',
  18719. 'a162', 'a174', 'a175', 'a176', 'a177', 'a178', 'a179', 'a193', 'a180',
  18720. 'a199', 'a181', 'a200', 'a182', '', 'a201', 'a183', 'a184', 'a197', 'a185',
  18721. 'a194', 'a198', 'a186', 'a195', 'a187', 'a188', 'a189', 'a190', 'a191']
  18722. };
  18723. /**
  18724. * Hold a map of decoded fonts and of the standard fourteen Type1
  18725. * fonts and their acronyms.
  18726. */
  18727. var stdFontMap = {
  18728. 'ArialNarrow': 'Helvetica',
  18729. 'ArialNarrow-Bold': 'Helvetica-Bold',
  18730. 'ArialNarrow-BoldItalic': 'Helvetica-BoldOblique',
  18731. 'ArialNarrow-Italic': 'Helvetica-Oblique',
  18732. 'ArialBlack': 'Helvetica',
  18733. 'ArialBlack-Bold': 'Helvetica-Bold',
  18734. 'ArialBlack-BoldItalic': 'Helvetica-BoldOblique',
  18735. 'ArialBlack-Italic': 'Helvetica-Oblique',
  18736. 'Arial': 'Helvetica',
  18737. 'Arial-Bold': 'Helvetica-Bold',
  18738. 'Arial-BoldItalic': 'Helvetica-BoldOblique',
  18739. 'Arial-Italic': 'Helvetica-Oblique',
  18740. 'Arial-BoldItalicMT': 'Helvetica-BoldOblique',
  18741. 'Arial-BoldMT': 'Helvetica-Bold',
  18742. 'Arial-ItalicMT': 'Helvetica-Oblique',
  18743. 'ArialMT': 'Helvetica',
  18744. 'Courier-Bold': 'Courier-Bold',
  18745. 'Courier-BoldItalic': 'Courier-BoldOblique',
  18746. 'Courier-Italic': 'Courier-Oblique',
  18747. 'CourierNew': 'Courier',
  18748. 'CourierNew-Bold': 'Courier-Bold',
  18749. 'CourierNew-BoldItalic': 'Courier-BoldOblique',
  18750. 'CourierNew-Italic': 'Courier-Oblique',
  18751. 'CourierNewPS-BoldItalicMT': 'Courier-BoldOblique',
  18752. 'CourierNewPS-BoldMT': 'Courier-Bold',
  18753. 'CourierNewPS-ItalicMT': 'Courier-Oblique',
  18754. 'CourierNewPSMT': 'Courier',
  18755. 'Helvetica': 'Helvetica',
  18756. 'Helvetica-Bold': 'Helvetica-Bold',
  18757. 'Helvetica-BoldItalic': 'Helvetica-BoldOblique',
  18758. 'Helvetica-BoldOblique': 'Helvetica-BoldOblique',
  18759. 'Helvetica-Italic': 'Helvetica-Oblique',
  18760. 'Helvetica-Oblique':'Helvetica-Oblique',
  18761. 'Symbol-Bold': 'Symbol',
  18762. 'Symbol-BoldItalic': 'Symbol',
  18763. 'Symbol-Italic': 'Symbol',
  18764. 'TimesNewRoman': 'Times-Roman',
  18765. 'TimesNewRoman-Bold': 'Times-Bold',
  18766. 'TimesNewRoman-BoldItalic': 'Times-BoldItalic',
  18767. 'TimesNewRoman-Italic': 'Times-Italic',
  18768. 'TimesNewRomanPS': 'Times-Roman',
  18769. 'TimesNewRomanPS-Bold': 'Times-Bold',
  18770. 'TimesNewRomanPS-BoldItalic': 'Times-BoldItalic',
  18771. 'TimesNewRomanPS-BoldItalicMT': 'Times-BoldItalic',
  18772. 'TimesNewRomanPS-BoldMT': 'Times-Bold',
  18773. 'TimesNewRomanPS-Italic': 'Times-Italic',
  18774. 'TimesNewRomanPS-ItalicMT': 'Times-Italic',
  18775. 'TimesNewRomanPSMT': 'Times-Roman',
  18776. 'TimesNewRomanPSMT-Bold': 'Times-Bold',
  18777. 'TimesNewRomanPSMT-BoldItalic': 'Times-BoldItalic',
  18778. 'TimesNewRomanPSMT-Italic': 'Times-Italic'
  18779. };
  18780. /**
  18781. * Holds the map of the non-standard fonts that might be included as a standard
  18782. * fonts without glyph data.
  18783. */
  18784. var nonStdFontMap = {
  18785. 'CenturyGothic': 'Helvetica',
  18786. 'CenturyGothic-Bold': 'Helvetica-Bold',
  18787. 'CenturyGothic-BoldItalic': 'Helvetica-BoldOblique',
  18788. 'CenturyGothic-Italic': 'Helvetica-Oblique',
  18789. 'ComicSansMS': 'Comic Sans MS',
  18790. 'ComicSansMS-Bold': 'Comic Sans MS-Bold',
  18791. 'ComicSansMS-BoldItalic': 'Comic Sans MS-BoldItalic',
  18792. 'ComicSansMS-Italic': 'Comic Sans MS-Italic',
  18793. 'LucidaConsole': 'Courier',
  18794. 'LucidaConsole-Bold': 'Courier-Bold',
  18795. 'LucidaConsole-BoldItalic': 'Courier-BoldOblique',
  18796. 'LucidaConsole-Italic': 'Courier-Oblique',
  18797. 'MS-Gothic': 'MS Gothic',
  18798. 'MS-Gothic-Bold': 'MS Gothic-Bold',
  18799. 'MS-Gothic-BoldItalic': 'MS Gothic-BoldItalic',
  18800. 'MS-Gothic-Italic': 'MS Gothic-Italic',
  18801. 'MS-Mincho': 'MS Mincho',
  18802. 'MS-Mincho-Bold': 'MS Mincho-Bold',
  18803. 'MS-Mincho-BoldItalic': 'MS Mincho-BoldItalic',
  18804. 'MS-Mincho-Italic': 'MS Mincho-Italic',
  18805. 'MS-PGothic': 'MS PGothic',
  18806. 'MS-PGothic-Bold': 'MS PGothic-Bold',
  18807. 'MS-PGothic-BoldItalic': 'MS PGothic-BoldItalic',
  18808. 'MS-PGothic-Italic': 'MS PGothic-Italic',
  18809. 'MS-PMincho': 'MS PMincho',
  18810. 'MS-PMincho-Bold': 'MS PMincho-Bold',
  18811. 'MS-PMincho-BoldItalic': 'MS PMincho-BoldItalic',
  18812. 'MS-PMincho-Italic': 'MS PMincho-Italic',
  18813. 'Wingdings': 'ZapfDingbats'
  18814. };
  18815. var serifFonts = {
  18816. 'Adobe Jenson': true, 'Adobe Text': true, 'Albertus': true,
  18817. 'Aldus': true, 'Alexandria': true, 'Algerian': true,
  18818. 'American Typewriter': true, 'Antiqua': true, 'Apex': true,
  18819. 'Arno': true, 'Aster': true, 'Aurora': true,
  18820. 'Baskerville': true, 'Bell': true, 'Bembo': true,
  18821. 'Bembo Schoolbook': true, 'Benguiat': true, 'Berkeley Old Style': true,
  18822. 'Bernhard Modern': true, 'Berthold City': true, 'Bodoni': true,
  18823. 'Bauer Bodoni': true, 'Book Antiqua': true, 'Bookman': true,
  18824. 'Bordeaux Roman': true, 'Californian FB': true, 'Calisto': true,
  18825. 'Calvert': true, 'Capitals': true, 'Cambria': true,
  18826. 'Cartier': true, 'Caslon': true, 'Catull': true,
  18827. 'Centaur': true, 'Century Old Style': true, 'Century Schoolbook': true,
  18828. 'Chaparral': true, 'Charis SIL': true, 'Cheltenham': true,
  18829. 'Cholla Slab': true, 'Clarendon': true, 'Clearface': true,
  18830. 'Cochin': true, 'Colonna': true, 'Computer Modern': true,
  18831. 'Concrete Roman': true, 'Constantia': true, 'Cooper Black': true,
  18832. 'Corona': true, 'Ecotype': true, 'Egyptienne': true,
  18833. 'Elephant': true, 'Excelsior': true, 'Fairfield': true,
  18834. 'FF Scala': true, 'Folkard': true, 'Footlight': true,
  18835. 'FreeSerif': true, 'Friz Quadrata': true, 'Garamond': true,
  18836. 'Gentium': true, 'Georgia': true, 'Gloucester': true,
  18837. 'Goudy Old Style': true, 'Goudy Schoolbook': true, 'Goudy Pro Font': true,
  18838. 'Granjon': true, 'Guardian Egyptian': true, 'Heather': true,
  18839. 'Hercules': true, 'High Tower Text': true, 'Hiroshige': true,
  18840. 'Hoefler Text': true, 'Humana Serif': true, 'Imprint': true,
  18841. 'Ionic No. 5': true, 'Janson': true, 'Joanna': true,
  18842. 'Korinna': true, 'Lexicon': true, 'Liberation Serif': true,
  18843. 'Linux Libertine': true, 'Literaturnaya': true, 'Lucida': true,
  18844. 'Lucida Bright': true, 'Melior': true, 'Memphis': true,
  18845. 'Miller': true, 'Minion': true, 'Modern': true,
  18846. 'Mona Lisa': true, 'Mrs Eaves': true, 'MS Serif': true,
  18847. 'Museo Slab': true, 'New York': true, 'Nimbus Roman': true,
  18848. 'NPS Rawlinson Roadway': true, 'Palatino': true, 'Perpetua': true,
  18849. 'Plantin': true, 'Plantin Schoolbook': true, 'Playbill': true,
  18850. 'Poor Richard': true, 'Rawlinson Roadway': true, 'Renault': true,
  18851. 'Requiem': true, 'Rockwell': true, 'Roman': true,
  18852. 'Rotis Serif': true, 'Sabon': true, 'Scala': true,
  18853. 'Seagull': true, 'Sistina': true, 'Souvenir': true,
  18854. 'STIX': true, 'Stone Informal': true, 'Stone Serif': true,
  18855. 'Sylfaen': true, 'Times': true, 'Trajan': true,
  18856. 'Trinité': true, 'Trump Mediaeval': true, 'Utopia': true,
  18857. 'Vale Type': true, 'Bitstream Vera': true, 'Vera Serif': true,
  18858. 'Versailles': true, 'Wanted': true, 'Weiss': true,
  18859. 'Wide Latin': true, 'Windsor': true, 'XITS': true
  18860. };
  18861. var symbolsFonts = {
  18862. 'Dingbats': true, 'Symbol': true, 'ZapfDingbats': true
  18863. };
  18864. // Glyph map for well-known standard fonts. Sometimes Ghostscript uses CID fonts
  18865. // but does not embed the CID to GID mapping. The mapping is incomplete for all
  18866. // glyphs, but common for some set of the standard fonts.
  18867. var GlyphMapForStandardFonts = {
  18868. '2': 10, '3': 32, '4': 33, '5': 34, '6': 35, '7': 36, '8': 37, '9': 38,
  18869. '10': 39, '11': 40, '12': 41, '13': 42, '14': 43, '15': 44, '16': 45,
  18870. '17': 46, '18': 47, '19': 48, '20': 49, '21': 50, '22': 51, '23': 52,
  18871. '24': 53, '25': 54, '26': 55, '27': 56, '28': 57, '29': 58, '30': 894,
  18872. '31': 60, '32': 61, '33': 62, '34': 63, '35': 64, '36': 65, '37': 66,
  18873. '38': 67, '39': 68, '40': 69, '41': 70, '42': 71, '43': 72, '44': 73,
  18874. '45': 74, '46': 75, '47': 76, '48': 77, '49': 78, '50': 79, '51': 80,
  18875. '52': 81, '53': 82, '54': 83, '55': 84, '56': 85, '57': 86, '58': 87,
  18876. '59': 88, '60': 89, '61': 90, '62': 91, '63': 92, '64': 93, '65': 94,
  18877. '66': 95, '67': 96, '68': 97, '69': 98, '70': 99, '71': 100, '72': 101,
  18878. '73': 102, '74': 103, '75': 104, '76': 105, '77': 106, '78': 107, '79': 108,
  18879. '80': 109, '81': 110, '82': 111, '83': 112, '84': 113, '85': 114, '86': 115,
  18880. '87': 116, '88': 117, '89': 118, '90': 119, '91': 120, '92': 121, '93': 122,
  18881. '94': 123, '95': 124, '96': 125, '97': 126, '98': 196, '99': 197, '100': 199,
  18882. '101': 201, '102': 209, '103': 214, '104': 220, '105': 225, '106': 224,
  18883. '107': 226, '108': 228, '109': 227, '110': 229, '111': 231, '112': 233,
  18884. '113': 232, '114': 234, '115': 235, '116': 237, '117': 236, '118': 238,
  18885. '119': 239, '120': 241, '121': 243, '122': 242, '123': 244, '124': 246,
  18886. '125': 245, '126': 250, '127': 249, '128': 251, '129': 252, '130': 8224,
  18887. '131': 176, '132': 162, '133': 163, '134': 167, '135': 8226, '136': 182,
  18888. '137': 223, '138': 174, '139': 169, '140': 8482, '141': 180, '142': 168,
  18889. '143': 8800, '144': 198, '145': 216, '146': 8734, '147': 177, '148': 8804,
  18890. '149': 8805, '150': 165, '151': 181, '152': 8706, '153': 8721, '154': 8719,
  18891. '156': 8747, '157': 170, '158': 186, '159': 8486, '160': 230, '161': 248,
  18892. '162': 191, '163': 161, '164': 172, '165': 8730, '166': 402, '167': 8776,
  18893. '168': 8710, '169': 171, '170': 187, '171': 8230, '210': 218, '223': 711,
  18894. '224': 321, '225': 322, '227': 353, '229': 382, '234': 253, '252': 263,
  18895. '253': 268, '254': 269, '258': 258, '260': 260, '261': 261, '265': 280,
  18896. '266': 281, '268': 283, '269': 313, '275': 323, '276': 324, '278': 328,
  18897. '284': 345, '285': 346, '286': 347, '292': 367, '295': 377, '296': 378,
  18898. '298': 380, '305': 963,
  18899. '306': 964, '307': 966, '308': 8215, '309': 8252, '310': 8319, '311': 8359,
  18900. '312': 8592, '313': 8593, '337': 9552, '493': 1039, '494': 1040, '705': 1524,
  18901. '706': 8362, '710': 64288, '711': 64298, '759': 1617, '761': 1776,
  18902. '763': 1778, '775': 1652, '777': 1764, '778': 1780, '779': 1781, '780': 1782,
  18903. '782': 771, '783': 64726, '786': 8363, '788': 8532, '790': 768, '791': 769,
  18904. '792': 768, '795': 803, '797': 64336, '798': 64337, '799': 64342,
  18905. '800': 64343, '801': 64344, '802': 64345, '803': 64362, '804': 64363,
  18906. '805': 64364, '2424': 7821, '2425': 7822, '2426': 7823, '2427': 7824,
  18907. '2428': 7825, '2429': 7826, '2430': 7827, '2433': 7682, '2678': 8045,
  18908. '2679': 8046, '2830': 1552, '2838': 686, '2840': 751, '2842': 753,
  18909. '2843': 754, '2844': 755, '2846': 757, '2856': 767, '2857': 848, '2858': 849,
  18910. '2862': 853, '2863': 854, '2864': 855, '2865': 861, '2866': 862, '2906': 7460,
  18911. '2908': 7462, '2909': 7463, '2910': 7464, '2912': 7466, '2913': 7467,
  18912. '2914': 7468, '2916': 7470, '2917': 7471, '2918': 7472, '2920': 7474,
  18913. '2921': 7475, '2922': 7476, '2924': 7478, '2925': 7479, '2926': 7480,
  18914. '2928': 7482, '2929': 7483, '2930': 7484, '2932': 7486, '2933': 7487,
  18915. '2934': 7488, '2936': 7490, '2937': 7491, '2938': 7492, '2940': 7494,
  18916. '2941': 7495, '2942': 7496, '2944': 7498, '2946': 7500, '2948': 7502,
  18917. '2950': 7504, '2951': 7505, '2952': 7506, '2954': 7508, '2955': 7509,
  18918. '2956': 7510, '2958': 7512, '2959': 7513, '2960': 7514, '2962': 7516,
  18919. '2963': 7517, '2964': 7518, '2966': 7520, '2967': 7521, '2968': 7522,
  18920. '2970': 7524, '2971': 7525, '2972': 7526, '2974': 7528, '2975': 7529,
  18921. '2976': 7530, '2978': 1537, '2979': 1538, '2980': 1539, '2982': 1549,
  18922. '2983': 1551, '2984': 1552, '2986': 1554, '2987': 1555, '2988': 1556,
  18923. '2990': 1623, '2991': 1624, '2995': 1775, '2999': 1791, '3002': 64290,
  18924. '3003': 64291, '3004': 64292, '3006': 64294, '3007': 64295, '3008': 64296,
  18925. '3011': 1900, '3014': 8223, '3015': 8244, '3017': 7532, '3018': 7533,
  18926. '3019': 7534, '3075': 7590, '3076': 7591, '3079': 7594, '3080': 7595,
  18927. '3083': 7598, '3084': 7599, '3087': 7602, '3088': 7603, '3091': 7606,
  18928. '3092': 7607, '3095': 7610, '3096': 7611, '3099': 7614, '3100': 7615,
  18929. '3103': 7618, '3104': 7619, '3107': 8337, '3108': 8338, '3116': 1884,
  18930. '3119': 1885, '3120': 1885, '3123': 1886, '3124': 1886, '3127': 1887,
  18931. '3128': 1887, '3131': 1888, '3132': 1888, '3135': 1889, '3136': 1889,
  18932. '3139': 1890, '3140': 1890, '3143': 1891, '3144': 1891, '3147': 1892,
  18933. '3148': 1892, '3153': 580, '3154': 581, '3157': 584, '3158': 585, '3161': 588,
  18934. '3162': 589, '3165': 891, '3166': 892, '3169': 1274, '3170': 1275,
  18935. '3173': 1278, '3174': 1279, '3181': 7622, '3182': 7623, '3282': 11799,
  18936. '3316': 578, '3379': 42785, '3393': 1159, '3416': 8377
  18937. };
  18938. // Some characters, e.g. copyrightserif, are mapped to the private use area and
  18939. // might not be displayed using standard fonts. Mapping/hacking well-known chars
  18940. // to the similar equivalents in the normal characters range.
  18941. var SpecialPUASymbols = {
  18942. '63721': 0x00A9, // copyrightsans (0xF8E9) => copyright
  18943. '63193': 0x00A9, // copyrightserif (0xF6D9) => copyright
  18944. '63720': 0x00AE, // registersans (0xF8E8) => registered
  18945. '63194': 0x00AE, // registerserif (0xF6DA) => registered
  18946. '63722': 0x2122, // trademarksans (0xF8EA) => trademark
  18947. '63195': 0x2122, // trademarkserif (0xF6DB) => trademark
  18948. '63729': 0x23A7, // bracelefttp (0xF8F1)
  18949. '63730': 0x23A8, // braceleftmid (0xF8F2)
  18950. '63731': 0x23A9, // braceleftbt (0xF8F3)
  18951. '63740': 0x23AB, // bracerighttp (0xF8FC)
  18952. '63741': 0x23AC, // bracerightmid (0xF8FD)
  18953. '63742': 0x23AD, // bracerightbt (0xF8FE)
  18954. '63726': 0x23A1, // bracketlefttp (0xF8EE)
  18955. '63727': 0x23A2, // bracketleftex (0xF8EF)
  18956. '63728': 0x23A3, // bracketleftbt (0xF8F0)
  18957. '63737': 0x23A4, // bracketrighttp (0xF8F9)
  18958. '63738': 0x23A5, // bracketrightex (0xF8FA)
  18959. '63739': 0x23A6, // bracketrightbt (0xF8FB)
  18960. '63723': 0x239B, // parenlefttp (0xF8EB)
  18961. '63724': 0x239C, // parenleftex (0xF8EC)
  18962. '63725': 0x239D, // parenleftbt (0xF8ED)
  18963. '63734': 0x239E, // parenrighttp (0xF8F6)
  18964. '63735': 0x239F, // parenrightex (0xF8F7)
  18965. '63736': 0x23A0, // parenrightbt (0xF8F8)
  18966. };
  18967. function mapSpecialUnicodeValues(code) {
  18968. if (code >= 0xFFF0 && code <= 0xFFFF) { // Specials unicode block.
  18969. return 0;
  18970. } else if (code >= 0xF600 && code <= 0xF8FF) {
  18971. return (SpecialPUASymbols[code] || code);
  18972. }
  18973. return code;
  18974. }
  18975. var UnicodeRanges = [
  18976. { 'begin': 0x0000, 'end': 0x007F }, // Basic Latin
  18977. { 'begin': 0x0080, 'end': 0x00FF }, // Latin-1 Supplement
  18978. { 'begin': 0x0100, 'end': 0x017F }, // Latin Extended-A
  18979. { 'begin': 0x0180, 'end': 0x024F }, // Latin Extended-B
  18980. { 'begin': 0x0250, 'end': 0x02AF }, // IPA Extensions
  18981. { 'begin': 0x02B0, 'end': 0x02FF }, // Spacing Modifier Letters
  18982. { 'begin': 0x0300, 'end': 0x036F }, // Combining Diacritical Marks
  18983. { 'begin': 0x0370, 'end': 0x03FF }, // Greek and Coptic
  18984. { 'begin': 0x2C80, 'end': 0x2CFF }, // Coptic
  18985. { 'begin': 0x0400, 'end': 0x04FF }, // Cyrillic
  18986. { 'begin': 0x0530, 'end': 0x058F }, // Armenian
  18987. { 'begin': 0x0590, 'end': 0x05FF }, // Hebrew
  18988. { 'begin': 0xA500, 'end': 0xA63F }, // Vai
  18989. { 'begin': 0x0600, 'end': 0x06FF }, // Arabic
  18990. { 'begin': 0x07C0, 'end': 0x07FF }, // NKo
  18991. { 'begin': 0x0900, 'end': 0x097F }, // Devanagari
  18992. { 'begin': 0x0980, 'end': 0x09FF }, // Bengali
  18993. { 'begin': 0x0A00, 'end': 0x0A7F }, // Gurmukhi
  18994. { 'begin': 0x0A80, 'end': 0x0AFF }, // Gujarati
  18995. { 'begin': 0x0B00, 'end': 0x0B7F }, // Oriya
  18996. { 'begin': 0x0B80, 'end': 0x0BFF }, // Tamil
  18997. { 'begin': 0x0C00, 'end': 0x0C7F }, // Telugu
  18998. { 'begin': 0x0C80, 'end': 0x0CFF }, // Kannada
  18999. { 'begin': 0x0D00, 'end': 0x0D7F }, // Malayalam
  19000. { 'begin': 0x0E00, 'end': 0x0E7F }, // Thai
  19001. { 'begin': 0x0E80, 'end': 0x0EFF }, // Lao
  19002. { 'begin': 0x10A0, 'end': 0x10FF }, // Georgian
  19003. { 'begin': 0x1B00, 'end': 0x1B7F }, // Balinese
  19004. { 'begin': 0x1100, 'end': 0x11FF }, // Hangul Jamo
  19005. { 'begin': 0x1E00, 'end': 0x1EFF }, // Latin Extended Additional
  19006. { 'begin': 0x1F00, 'end': 0x1FFF }, // Greek Extended
  19007. { 'begin': 0x2000, 'end': 0x206F }, // General Punctuation
  19008. { 'begin': 0x2070, 'end': 0x209F }, // Superscripts And Subscripts
  19009. { 'begin': 0x20A0, 'end': 0x20CF }, // Currency Symbol
  19010. { 'begin': 0x20D0, 'end': 0x20FF }, // Combining Diacritical Marks For Symbols
  19011. { 'begin': 0x2100, 'end': 0x214F }, // Letterlike Symbols
  19012. { 'begin': 0x2150, 'end': 0x218F }, // Number Forms
  19013. { 'begin': 0x2190, 'end': 0x21FF }, // Arrows
  19014. { 'begin': 0x2200, 'end': 0x22FF }, // Mathematical Operators
  19015. { 'begin': 0x2300, 'end': 0x23FF }, // Miscellaneous Technical
  19016. { 'begin': 0x2400, 'end': 0x243F }, // Control Pictures
  19017. { 'begin': 0x2440, 'end': 0x245F }, // Optical Character Recognition
  19018. { 'begin': 0x2460, 'end': 0x24FF }, // Enclosed Alphanumerics
  19019. { 'begin': 0x2500, 'end': 0x257F }, // Box Drawing
  19020. { 'begin': 0x2580, 'end': 0x259F }, // Block Elements
  19021. { 'begin': 0x25A0, 'end': 0x25FF }, // Geometric Shapes
  19022. { 'begin': 0x2600, 'end': 0x26FF }, // Miscellaneous Symbols
  19023. { 'begin': 0x2700, 'end': 0x27BF }, // Dingbats
  19024. { 'begin': 0x3000, 'end': 0x303F }, // CJK Symbols And Punctuation
  19025. { 'begin': 0x3040, 'end': 0x309F }, // Hiragana
  19026. { 'begin': 0x30A0, 'end': 0x30FF }, // Katakana
  19027. { 'begin': 0x3100, 'end': 0x312F }, // Bopomofo
  19028. { 'begin': 0x3130, 'end': 0x318F }, // Hangul Compatibility Jamo
  19029. { 'begin': 0xA840, 'end': 0xA87F }, // Phags-pa
  19030. { 'begin': 0x3200, 'end': 0x32FF }, // Enclosed CJK Letters And Months
  19031. { 'begin': 0x3300, 'end': 0x33FF }, // CJK Compatibility
  19032. { 'begin': 0xAC00, 'end': 0xD7AF }, // Hangul Syllables
  19033. { 'begin': 0xD800, 'end': 0xDFFF }, // Non-Plane 0 *
  19034. { 'begin': 0x10900, 'end': 0x1091F }, // Phoenicia
  19035. { 'begin': 0x4E00, 'end': 0x9FFF }, // CJK Unified Ideographs
  19036. { 'begin': 0xE000, 'end': 0xF8FF }, // Private Use Area (plane 0)
  19037. { 'begin': 0x31C0, 'end': 0x31EF }, // CJK Strokes
  19038. { 'begin': 0xFB00, 'end': 0xFB4F }, // Alphabetic Presentation Forms
  19039. { 'begin': 0xFB50, 'end': 0xFDFF }, // Arabic Presentation Forms-A
  19040. { 'begin': 0xFE20, 'end': 0xFE2F }, // Combining Half Marks
  19041. { 'begin': 0xFE10, 'end': 0xFE1F }, // Vertical Forms
  19042. { 'begin': 0xFE50, 'end': 0xFE6F }, // Small Form Variants
  19043. { 'begin': 0xFE70, 'end': 0xFEFF }, // Arabic Presentation Forms-B
  19044. { 'begin': 0xFF00, 'end': 0xFFEF }, // Halfwidth And Fullwidth Forms
  19045. { 'begin': 0xFFF0, 'end': 0xFFFF }, // Specials
  19046. { 'begin': 0x0F00, 'end': 0x0FFF }, // Tibetan
  19047. { 'begin': 0x0700, 'end': 0x074F }, // Syriac
  19048. { 'begin': 0x0780, 'end': 0x07BF }, // Thaana
  19049. { 'begin': 0x0D80, 'end': 0x0DFF }, // Sinhala
  19050. { 'begin': 0x1000, 'end': 0x109F }, // Myanmar
  19051. { 'begin': 0x1200, 'end': 0x137F }, // Ethiopic
  19052. { 'begin': 0x13A0, 'end': 0x13FF }, // Cherokee
  19053. { 'begin': 0x1400, 'end': 0x167F }, // Unified Canadian Aboriginal Syllabics
  19054. { 'begin': 0x1680, 'end': 0x169F }, // Ogham
  19055. { 'begin': 0x16A0, 'end': 0x16FF }, // Runic
  19056. { 'begin': 0x1780, 'end': 0x17FF }, // Khmer
  19057. { 'begin': 0x1800, 'end': 0x18AF }, // Mongolian
  19058. { 'begin': 0x2800, 'end': 0x28FF }, // Braille Patterns
  19059. { 'begin': 0xA000, 'end': 0xA48F }, // Yi Syllables
  19060. { 'begin': 0x1700, 'end': 0x171F }, // Tagalog
  19061. { 'begin': 0x10300, 'end': 0x1032F }, // Old Italic
  19062. { 'begin': 0x10330, 'end': 0x1034F }, // Gothic
  19063. { 'begin': 0x10400, 'end': 0x1044F }, // Deseret
  19064. { 'begin': 0x1D000, 'end': 0x1D0FF }, // Byzantine Musical Symbols
  19065. { 'begin': 0x1D400, 'end': 0x1D7FF }, // Mathematical Alphanumeric Symbols
  19066. { 'begin': 0xFF000, 'end': 0xFFFFD }, // Private Use (plane 15)
  19067. { 'begin': 0xFE00, 'end': 0xFE0F }, // Variation Selectors
  19068. { 'begin': 0xE0000, 'end': 0xE007F }, // Tags
  19069. { 'begin': 0x1900, 'end': 0x194F }, // Limbu
  19070. { 'begin': 0x1950, 'end': 0x197F }, // Tai Le
  19071. { 'begin': 0x1980, 'end': 0x19DF }, // New Tai Lue
  19072. { 'begin': 0x1A00, 'end': 0x1A1F }, // Buginese
  19073. { 'begin': 0x2C00, 'end': 0x2C5F }, // Glagolitic
  19074. { 'begin': 0x2D30, 'end': 0x2D7F }, // Tifinagh
  19075. { 'begin': 0x4DC0, 'end': 0x4DFF }, // Yijing Hexagram Symbols
  19076. { 'begin': 0xA800, 'end': 0xA82F }, // Syloti Nagri
  19077. { 'begin': 0x10000, 'end': 0x1007F }, // Linear B Syllabary
  19078. { 'begin': 0x10140, 'end': 0x1018F }, // Ancient Greek Numbers
  19079. { 'begin': 0x10380, 'end': 0x1039F }, // Ugaritic
  19080. { 'begin': 0x103A0, 'end': 0x103DF }, // Old Persian
  19081. { 'begin': 0x10450, 'end': 0x1047F }, // Shavian
  19082. { 'begin': 0x10480, 'end': 0x104AF }, // Osmanya
  19083. { 'begin': 0x10800, 'end': 0x1083F }, // Cypriot Syllabary
  19084. { 'begin': 0x10A00, 'end': 0x10A5F }, // Kharoshthi
  19085. { 'begin': 0x1D300, 'end': 0x1D35F }, // Tai Xuan Jing Symbols
  19086. { 'begin': 0x12000, 'end': 0x123FF }, // Cuneiform
  19087. { 'begin': 0x1D360, 'end': 0x1D37F }, // Counting Rod Numerals
  19088. { 'begin': 0x1B80, 'end': 0x1BBF }, // Sundanese
  19089. { 'begin': 0x1C00, 'end': 0x1C4F }, // Lepcha
  19090. { 'begin': 0x1C50, 'end': 0x1C7F }, // Ol Chiki
  19091. { 'begin': 0xA880, 'end': 0xA8DF }, // Saurashtra
  19092. { 'begin': 0xA900, 'end': 0xA92F }, // Kayah Li
  19093. { 'begin': 0xA930, 'end': 0xA95F }, // Rejang
  19094. { 'begin': 0xAA00, 'end': 0xAA5F }, // Cham
  19095. { 'begin': 0x10190, 'end': 0x101CF }, // Ancient Symbols
  19096. { 'begin': 0x101D0, 'end': 0x101FF }, // Phaistos Disc
  19097. { 'begin': 0x102A0, 'end': 0x102DF }, // Carian
  19098. { 'begin': 0x1F030, 'end': 0x1F09F } // Domino Tiles
  19099. ];
  19100. var MacStandardGlyphOrdering = [
  19101. '.notdef', '.null', 'nonmarkingreturn', 'space', 'exclam', 'quotedbl',
  19102. 'numbersign', 'dollar', 'percent', 'ampersand', 'quotesingle', 'parenleft',
  19103. 'parenright', 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash',
  19104. 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',
  19105. 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater', 'question', 'at',
  19106. 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
  19107. 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'bracketleft',
  19108. 'backslash', 'bracketright', 'asciicircum', 'underscore', 'grave', 'a', 'b',
  19109. 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q',
  19110. 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright',
  19111. 'asciitilde', 'Adieresis', 'Aring', 'Ccedilla', 'Eacute', 'Ntilde',
  19112. 'Odieresis', 'Udieresis', 'aacute', 'agrave', 'acircumflex', 'adieresis',
  19113. 'atilde', 'aring', 'ccedilla', 'eacute', 'egrave', 'ecircumflex', 'edieresis',
  19114. 'iacute', 'igrave', 'icircumflex', 'idieresis', 'ntilde', 'oacute', 'ograve',
  19115. 'ocircumflex', 'odieresis', 'otilde', 'uacute', 'ugrave', 'ucircumflex',
  19116. 'udieresis', 'dagger', 'degree', 'cent', 'sterling', 'section', 'bullet',
  19117. 'paragraph', 'germandbls', 'registered', 'copyright', 'trademark', 'acute',
  19118. 'dieresis', 'notequal', 'AE', 'Oslash', 'infinity', 'plusminus', 'lessequal',
  19119. 'greaterequal', 'yen', 'mu', 'partialdiff', 'summation', 'product', 'pi',
  19120. 'integral', 'ordfeminine', 'ordmasculine', 'Omega', 'ae', 'oslash',
  19121. 'questiondown', 'exclamdown', 'logicalnot', 'radical', 'florin',
  19122. 'approxequal', 'Delta', 'guillemotleft', 'guillemotright', 'ellipsis',
  19123. 'nonbreakingspace', 'Agrave', 'Atilde', 'Otilde', 'OE', 'oe', 'endash',
  19124. 'emdash', 'quotedblleft', 'quotedblright', 'quoteleft', 'quoteright',
  19125. 'divide', 'lozenge', 'ydieresis', 'Ydieresis', 'fraction', 'currency',
  19126. 'guilsinglleft', 'guilsinglright', 'fi', 'fl', 'daggerdbl', 'periodcentered',
  19127. 'quotesinglbase', 'quotedblbase', 'perthousand', 'Acircumflex',
  19128. 'Ecircumflex', 'Aacute', 'Edieresis', 'Egrave', 'Iacute', 'Icircumflex',
  19129. 'Idieresis', 'Igrave', 'Oacute', 'Ocircumflex', 'apple', 'Ograve', 'Uacute',
  19130. 'Ucircumflex', 'Ugrave', 'dotlessi', 'circumflex', 'tilde', 'macron',
  19131. 'breve', 'dotaccent', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron',
  19132. 'Lslash', 'lslash', 'Scaron', 'scaron', 'Zcaron', 'zcaron', 'brokenbar',
  19133. 'Eth', 'eth', 'Yacute', 'yacute', 'Thorn', 'thorn', 'minus', 'multiply',
  19134. 'onesuperior', 'twosuperior', 'threesuperior', 'onehalf', 'onequarter',
  19135. 'threequarters', 'franc', 'Gbreve', 'gbreve', 'Idotaccent', 'Scedilla',
  19136. 'scedilla', 'Cacute', 'cacute', 'Ccaron', 'ccaron', 'dcroat'];
  19137. function getUnicodeRangeFor(value) {
  19138. for (var i = 0, ii = UnicodeRanges.length; i < ii; i++) {
  19139. var range = UnicodeRanges[i];
  19140. if (value >= range.begin && value < range.end) {
  19141. return i;
  19142. }
  19143. }
  19144. return -1;
  19145. }
  19146. function isRTLRangeFor(value) {
  19147. var range = UnicodeRanges[13];
  19148. if (value >= range.begin && value < range.end) {
  19149. return true;
  19150. }
  19151. range = UnicodeRanges[11];
  19152. if (value >= range.begin && value < range.end) {
  19153. return true;
  19154. }
  19155. return false;
  19156. }
  19157. // The normalization table is obtained by filtering the Unicode characters
  19158. // database with <compat> entries.
  19159. var NormalizedUnicodes = {
  19160. '\u00A8': '\u0020\u0308',
  19161. '\u00AF': '\u0020\u0304',
  19162. '\u00B4': '\u0020\u0301',
  19163. '\u00B5': '\u03BC',
  19164. '\u00B8': '\u0020\u0327',
  19165. '\u0132': '\u0049\u004A',
  19166. '\u0133': '\u0069\u006A',
  19167. '\u013F': '\u004C\u00B7',
  19168. '\u0140': '\u006C\u00B7',
  19169. '\u0149': '\u02BC\u006E',
  19170. '\u017F': '\u0073',
  19171. '\u01C4': '\u0044\u017D',
  19172. '\u01C5': '\u0044\u017E',
  19173. '\u01C6': '\u0064\u017E',
  19174. '\u01C7': '\u004C\u004A',
  19175. '\u01C8': '\u004C\u006A',
  19176. '\u01C9': '\u006C\u006A',
  19177. '\u01CA': '\u004E\u004A',
  19178. '\u01CB': '\u004E\u006A',
  19179. '\u01CC': '\u006E\u006A',
  19180. '\u01F1': '\u0044\u005A',
  19181. '\u01F2': '\u0044\u007A',
  19182. '\u01F3': '\u0064\u007A',
  19183. '\u02D8': '\u0020\u0306',
  19184. '\u02D9': '\u0020\u0307',
  19185. '\u02DA': '\u0020\u030A',
  19186. '\u02DB': '\u0020\u0328',
  19187. '\u02DC': '\u0020\u0303',
  19188. '\u02DD': '\u0020\u030B',
  19189. '\u037A': '\u0020\u0345',
  19190. '\u0384': '\u0020\u0301',
  19191. '\u03D0': '\u03B2',
  19192. '\u03D1': '\u03B8',
  19193. '\u03D2': '\u03A5',
  19194. '\u03D5': '\u03C6',
  19195. '\u03D6': '\u03C0',
  19196. '\u03F0': '\u03BA',
  19197. '\u03F1': '\u03C1',
  19198. '\u03F2': '\u03C2',
  19199. '\u03F4': '\u0398',
  19200. '\u03F5': '\u03B5',
  19201. '\u03F9': '\u03A3',
  19202. '\u0587': '\u0565\u0582',
  19203. '\u0675': '\u0627\u0674',
  19204. '\u0676': '\u0648\u0674',
  19205. '\u0677': '\u06C7\u0674',
  19206. '\u0678': '\u064A\u0674',
  19207. '\u0E33': '\u0E4D\u0E32',
  19208. '\u0EB3': '\u0ECD\u0EB2',
  19209. '\u0EDC': '\u0EAB\u0E99',
  19210. '\u0EDD': '\u0EAB\u0EA1',
  19211. '\u0F77': '\u0FB2\u0F81',
  19212. '\u0F79': '\u0FB3\u0F81',
  19213. '\u1E9A': '\u0061\u02BE',
  19214. '\u1FBD': '\u0020\u0313',
  19215. '\u1FBF': '\u0020\u0313',
  19216. '\u1FC0': '\u0020\u0342',
  19217. '\u1FFE': '\u0020\u0314',
  19218. '\u2002': '\u0020',
  19219. '\u2003': '\u0020',
  19220. '\u2004': '\u0020',
  19221. '\u2005': '\u0020',
  19222. '\u2006': '\u0020',
  19223. '\u2008': '\u0020',
  19224. '\u2009': '\u0020',
  19225. '\u200A': '\u0020',
  19226. '\u2017': '\u0020\u0333',
  19227. '\u2024': '\u002E',
  19228. '\u2025': '\u002E\u002E',
  19229. '\u2026': '\u002E\u002E\u002E',
  19230. '\u2033': '\u2032\u2032',
  19231. '\u2034': '\u2032\u2032\u2032',
  19232. '\u2036': '\u2035\u2035',
  19233. '\u2037': '\u2035\u2035\u2035',
  19234. '\u203C': '\u0021\u0021',
  19235. '\u203E': '\u0020\u0305',
  19236. '\u2047': '\u003F\u003F',
  19237. '\u2048': '\u003F\u0021',
  19238. '\u2049': '\u0021\u003F',
  19239. '\u2057': '\u2032\u2032\u2032\u2032',
  19240. '\u205F': '\u0020',
  19241. '\u20A8': '\u0052\u0073',
  19242. '\u2100': '\u0061\u002F\u0063',
  19243. '\u2101': '\u0061\u002F\u0073',
  19244. '\u2103': '\u00B0\u0043',
  19245. '\u2105': '\u0063\u002F\u006F',
  19246. '\u2106': '\u0063\u002F\u0075',
  19247. '\u2107': '\u0190',
  19248. '\u2109': '\u00B0\u0046',
  19249. '\u2116': '\u004E\u006F',
  19250. '\u2121': '\u0054\u0045\u004C',
  19251. '\u2135': '\u05D0',
  19252. '\u2136': '\u05D1',
  19253. '\u2137': '\u05D2',
  19254. '\u2138': '\u05D3',
  19255. '\u213B': '\u0046\u0041\u0058',
  19256. '\u2160': '\u0049',
  19257. '\u2161': '\u0049\u0049',
  19258. '\u2162': '\u0049\u0049\u0049',
  19259. '\u2163': '\u0049\u0056',
  19260. '\u2164': '\u0056',
  19261. '\u2165': '\u0056\u0049',
  19262. '\u2166': '\u0056\u0049\u0049',
  19263. '\u2167': '\u0056\u0049\u0049\u0049',
  19264. '\u2168': '\u0049\u0058',
  19265. '\u2169': '\u0058',
  19266. '\u216A': '\u0058\u0049',
  19267. '\u216B': '\u0058\u0049\u0049',
  19268. '\u216C': '\u004C',
  19269. '\u216D': '\u0043',
  19270. '\u216E': '\u0044',
  19271. '\u216F': '\u004D',
  19272. '\u2170': '\u0069',
  19273. '\u2171': '\u0069\u0069',
  19274. '\u2172': '\u0069\u0069\u0069',
  19275. '\u2173': '\u0069\u0076',
  19276. '\u2174': '\u0076',
  19277. '\u2175': '\u0076\u0069',
  19278. '\u2176': '\u0076\u0069\u0069',
  19279. '\u2177': '\u0076\u0069\u0069\u0069',
  19280. '\u2178': '\u0069\u0078',
  19281. '\u2179': '\u0078',
  19282. '\u217A': '\u0078\u0069',
  19283. '\u217B': '\u0078\u0069\u0069',
  19284. '\u217C': '\u006C',
  19285. '\u217D': '\u0063',
  19286. '\u217E': '\u0064',
  19287. '\u217F': '\u006D',
  19288. '\u222C': '\u222B\u222B',
  19289. '\u222D': '\u222B\u222B\u222B',
  19290. '\u222F': '\u222E\u222E',
  19291. '\u2230': '\u222E\u222E\u222E',
  19292. '\u2474': '\u0028\u0031\u0029',
  19293. '\u2475': '\u0028\u0032\u0029',
  19294. '\u2476': '\u0028\u0033\u0029',
  19295. '\u2477': '\u0028\u0034\u0029',
  19296. '\u2478': '\u0028\u0035\u0029',
  19297. '\u2479': '\u0028\u0036\u0029',
  19298. '\u247A': '\u0028\u0037\u0029',
  19299. '\u247B': '\u0028\u0038\u0029',
  19300. '\u247C': '\u0028\u0039\u0029',
  19301. '\u247D': '\u0028\u0031\u0030\u0029',
  19302. '\u247E': '\u0028\u0031\u0031\u0029',
  19303. '\u247F': '\u0028\u0031\u0032\u0029',
  19304. '\u2480': '\u0028\u0031\u0033\u0029',
  19305. '\u2481': '\u0028\u0031\u0034\u0029',
  19306. '\u2482': '\u0028\u0031\u0035\u0029',
  19307. '\u2483': '\u0028\u0031\u0036\u0029',
  19308. '\u2484': '\u0028\u0031\u0037\u0029',
  19309. '\u2485': '\u0028\u0031\u0038\u0029',
  19310. '\u2486': '\u0028\u0031\u0039\u0029',
  19311. '\u2487': '\u0028\u0032\u0030\u0029',
  19312. '\u2488': '\u0031\u002E',
  19313. '\u2489': '\u0032\u002E',
  19314. '\u248A': '\u0033\u002E',
  19315. '\u248B': '\u0034\u002E',
  19316. '\u248C': '\u0035\u002E',
  19317. '\u248D': '\u0036\u002E',
  19318. '\u248E': '\u0037\u002E',
  19319. '\u248F': '\u0038\u002E',
  19320. '\u2490': '\u0039\u002E',
  19321. '\u2491': '\u0031\u0030\u002E',
  19322. '\u2492': '\u0031\u0031\u002E',
  19323. '\u2493': '\u0031\u0032\u002E',
  19324. '\u2494': '\u0031\u0033\u002E',
  19325. '\u2495': '\u0031\u0034\u002E',
  19326. '\u2496': '\u0031\u0035\u002E',
  19327. '\u2497': '\u0031\u0036\u002E',
  19328. '\u2498': '\u0031\u0037\u002E',
  19329. '\u2499': '\u0031\u0038\u002E',
  19330. '\u249A': '\u0031\u0039\u002E',
  19331. '\u249B': '\u0032\u0030\u002E',
  19332. '\u249C': '\u0028\u0061\u0029',
  19333. '\u249D': '\u0028\u0062\u0029',
  19334. '\u249E': '\u0028\u0063\u0029',
  19335. '\u249F': '\u0028\u0064\u0029',
  19336. '\u24A0': '\u0028\u0065\u0029',
  19337. '\u24A1': '\u0028\u0066\u0029',
  19338. '\u24A2': '\u0028\u0067\u0029',
  19339. '\u24A3': '\u0028\u0068\u0029',
  19340. '\u24A4': '\u0028\u0069\u0029',
  19341. '\u24A5': '\u0028\u006A\u0029',
  19342. '\u24A6': '\u0028\u006B\u0029',
  19343. '\u24A7': '\u0028\u006C\u0029',
  19344. '\u24A8': '\u0028\u006D\u0029',
  19345. '\u24A9': '\u0028\u006E\u0029',
  19346. '\u24AA': '\u0028\u006F\u0029',
  19347. '\u24AB': '\u0028\u0070\u0029',
  19348. '\u24AC': '\u0028\u0071\u0029',
  19349. '\u24AD': '\u0028\u0072\u0029',
  19350. '\u24AE': '\u0028\u0073\u0029',
  19351. '\u24AF': '\u0028\u0074\u0029',
  19352. '\u24B0': '\u0028\u0075\u0029',
  19353. '\u24B1': '\u0028\u0076\u0029',
  19354. '\u24B2': '\u0028\u0077\u0029',
  19355. '\u24B3': '\u0028\u0078\u0029',
  19356. '\u24B4': '\u0028\u0079\u0029',
  19357. '\u24B5': '\u0028\u007A\u0029',
  19358. '\u2A0C': '\u222B\u222B\u222B\u222B',
  19359. '\u2A74': '\u003A\u003A\u003D',
  19360. '\u2A75': '\u003D\u003D',
  19361. '\u2A76': '\u003D\u003D\u003D',
  19362. '\u2E9F': '\u6BCD',
  19363. '\u2EF3': '\u9F9F',
  19364. '\u2F00': '\u4E00',
  19365. '\u2F01': '\u4E28',
  19366. '\u2F02': '\u4E36',
  19367. '\u2F03': '\u4E3F',
  19368. '\u2F04': '\u4E59',
  19369. '\u2F05': '\u4E85',
  19370. '\u2F06': '\u4E8C',
  19371. '\u2F07': '\u4EA0',
  19372. '\u2F08': '\u4EBA',
  19373. '\u2F09': '\u513F',
  19374. '\u2F0A': '\u5165',
  19375. '\u2F0B': '\u516B',
  19376. '\u2F0C': '\u5182',
  19377. '\u2F0D': '\u5196',
  19378. '\u2F0E': '\u51AB',
  19379. '\u2F0F': '\u51E0',
  19380. '\u2F10': '\u51F5',
  19381. '\u2F11': '\u5200',
  19382. '\u2F12': '\u529B',
  19383. '\u2F13': '\u52F9',
  19384. '\u2F14': '\u5315',
  19385. '\u2F15': '\u531A',
  19386. '\u2F16': '\u5338',
  19387. '\u2F17': '\u5341',
  19388. '\u2F18': '\u535C',
  19389. '\u2F19': '\u5369',
  19390. '\u2F1A': '\u5382',
  19391. '\u2F1B': '\u53B6',
  19392. '\u2F1C': '\u53C8',
  19393. '\u2F1D': '\u53E3',
  19394. '\u2F1E': '\u56D7',
  19395. '\u2F1F': '\u571F',
  19396. '\u2F20': '\u58EB',
  19397. '\u2F21': '\u5902',
  19398. '\u2F22': '\u590A',
  19399. '\u2F23': '\u5915',
  19400. '\u2F24': '\u5927',
  19401. '\u2F25': '\u5973',
  19402. '\u2F26': '\u5B50',
  19403. '\u2F27': '\u5B80',
  19404. '\u2F28': '\u5BF8',
  19405. '\u2F29': '\u5C0F',
  19406. '\u2F2A': '\u5C22',
  19407. '\u2F2B': '\u5C38',
  19408. '\u2F2C': '\u5C6E',
  19409. '\u2F2D': '\u5C71',
  19410. '\u2F2E': '\u5DDB',
  19411. '\u2F2F': '\u5DE5',
  19412. '\u2F30': '\u5DF1',
  19413. '\u2F31': '\u5DFE',
  19414. '\u2F32': '\u5E72',
  19415. '\u2F33': '\u5E7A',
  19416. '\u2F34': '\u5E7F',
  19417. '\u2F35': '\u5EF4',
  19418. '\u2F36': '\u5EFE',
  19419. '\u2F37': '\u5F0B',
  19420. '\u2F38': '\u5F13',
  19421. '\u2F39': '\u5F50',
  19422. '\u2F3A': '\u5F61',
  19423. '\u2F3B': '\u5F73',
  19424. '\u2F3C': '\u5FC3',
  19425. '\u2F3D': '\u6208',
  19426. '\u2F3E': '\u6236',
  19427. '\u2F3F': '\u624B',
  19428. '\u2F40': '\u652F',
  19429. '\u2F41': '\u6534',
  19430. '\u2F42': '\u6587',
  19431. '\u2F43': '\u6597',
  19432. '\u2F44': '\u65A4',
  19433. '\u2F45': '\u65B9',
  19434. '\u2F46': '\u65E0',
  19435. '\u2F47': '\u65E5',
  19436. '\u2F48': '\u66F0',
  19437. '\u2F49': '\u6708',
  19438. '\u2F4A': '\u6728',
  19439. '\u2F4B': '\u6B20',
  19440. '\u2F4C': '\u6B62',
  19441. '\u2F4D': '\u6B79',
  19442. '\u2F4E': '\u6BB3',
  19443. '\u2F4F': '\u6BCB',
  19444. '\u2F50': '\u6BD4',
  19445. '\u2F51': '\u6BDB',
  19446. '\u2F52': '\u6C0F',
  19447. '\u2F53': '\u6C14',
  19448. '\u2F54': '\u6C34',
  19449. '\u2F55': '\u706B',
  19450. '\u2F56': '\u722A',
  19451. '\u2F57': '\u7236',
  19452. '\u2F58': '\u723B',
  19453. '\u2F59': '\u723F',
  19454. '\u2F5A': '\u7247',
  19455. '\u2F5B': '\u7259',
  19456. '\u2F5C': '\u725B',
  19457. '\u2F5D': '\u72AC',
  19458. '\u2F5E': '\u7384',
  19459. '\u2F5F': '\u7389',
  19460. '\u2F60': '\u74DC',
  19461. '\u2F61': '\u74E6',
  19462. '\u2F62': '\u7518',
  19463. '\u2F63': '\u751F',
  19464. '\u2F64': '\u7528',
  19465. '\u2F65': '\u7530',
  19466. '\u2F66': '\u758B',
  19467. '\u2F67': '\u7592',
  19468. '\u2F68': '\u7676',
  19469. '\u2F69': '\u767D',
  19470. '\u2F6A': '\u76AE',
  19471. '\u2F6B': '\u76BF',
  19472. '\u2F6C': '\u76EE',
  19473. '\u2F6D': '\u77DB',
  19474. '\u2F6E': '\u77E2',
  19475. '\u2F6F': '\u77F3',
  19476. '\u2F70': '\u793A',
  19477. '\u2F71': '\u79B8',
  19478. '\u2F72': '\u79BE',
  19479. '\u2F73': '\u7A74',
  19480. '\u2F74': '\u7ACB',
  19481. '\u2F75': '\u7AF9',
  19482. '\u2F76': '\u7C73',
  19483. '\u2F77': '\u7CF8',
  19484. '\u2F78': '\u7F36',
  19485. '\u2F79': '\u7F51',
  19486. '\u2F7A': '\u7F8A',
  19487. '\u2F7B': '\u7FBD',
  19488. '\u2F7C': '\u8001',
  19489. '\u2F7D': '\u800C',
  19490. '\u2F7E': '\u8012',
  19491. '\u2F7F': '\u8033',
  19492. '\u2F80': '\u807F',
  19493. '\u2F81': '\u8089',
  19494. '\u2F82': '\u81E3',
  19495. '\u2F83': '\u81EA',
  19496. '\u2F84': '\u81F3',
  19497. '\u2F85': '\u81FC',
  19498. '\u2F86': '\u820C',
  19499. '\u2F87': '\u821B',
  19500. '\u2F88': '\u821F',
  19501. '\u2F89': '\u826E',
  19502. '\u2F8A': '\u8272',
  19503. '\u2F8B': '\u8278',
  19504. '\u2F8C': '\u864D',
  19505. '\u2F8D': '\u866B',
  19506. '\u2F8E': '\u8840',
  19507. '\u2F8F': '\u884C',
  19508. '\u2F90': '\u8863',
  19509. '\u2F91': '\u897E',
  19510. '\u2F92': '\u898B',
  19511. '\u2F93': '\u89D2',
  19512. '\u2F94': '\u8A00',
  19513. '\u2F95': '\u8C37',
  19514. '\u2F96': '\u8C46',
  19515. '\u2F97': '\u8C55',
  19516. '\u2F98': '\u8C78',
  19517. '\u2F99': '\u8C9D',
  19518. '\u2F9A': '\u8D64',
  19519. '\u2F9B': '\u8D70',
  19520. '\u2F9C': '\u8DB3',
  19521. '\u2F9D': '\u8EAB',
  19522. '\u2F9E': '\u8ECA',
  19523. '\u2F9F': '\u8F9B',
  19524. '\u2FA0': '\u8FB0',
  19525. '\u2FA1': '\u8FB5',
  19526. '\u2FA2': '\u9091',
  19527. '\u2FA3': '\u9149',
  19528. '\u2FA4': '\u91C6',
  19529. '\u2FA5': '\u91CC',
  19530. '\u2FA6': '\u91D1',
  19531. '\u2FA7': '\u9577',
  19532. '\u2FA8': '\u9580',
  19533. '\u2FA9': '\u961C',
  19534. '\u2FAA': '\u96B6',
  19535. '\u2FAB': '\u96B9',
  19536. '\u2FAC': '\u96E8',
  19537. '\u2FAD': '\u9751',
  19538. '\u2FAE': '\u975E',
  19539. '\u2FAF': '\u9762',
  19540. '\u2FB0': '\u9769',
  19541. '\u2FB1': '\u97CB',
  19542. '\u2FB2': '\u97ED',
  19543. '\u2FB3': '\u97F3',
  19544. '\u2FB4': '\u9801',
  19545. '\u2FB5': '\u98A8',
  19546. '\u2FB6': '\u98DB',
  19547. '\u2FB7': '\u98DF',
  19548. '\u2FB8': '\u9996',
  19549. '\u2FB9': '\u9999',
  19550. '\u2FBA': '\u99AC',
  19551. '\u2FBB': '\u9AA8',
  19552. '\u2FBC': '\u9AD8',
  19553. '\u2FBD': '\u9ADF',
  19554. '\u2FBE': '\u9B25',
  19555. '\u2FBF': '\u9B2F',
  19556. '\u2FC0': '\u9B32',
  19557. '\u2FC1': '\u9B3C',
  19558. '\u2FC2': '\u9B5A',
  19559. '\u2FC3': '\u9CE5',
  19560. '\u2FC4': '\u9E75',
  19561. '\u2FC5': '\u9E7F',
  19562. '\u2FC6': '\u9EA5',
  19563. '\u2FC7': '\u9EBB',
  19564. '\u2FC8': '\u9EC3',
  19565. '\u2FC9': '\u9ECD',
  19566. '\u2FCA': '\u9ED1',
  19567. '\u2FCB': '\u9EF9',
  19568. '\u2FCC': '\u9EFD',
  19569. '\u2FCD': '\u9F0E',
  19570. '\u2FCE': '\u9F13',
  19571. '\u2FCF': '\u9F20',
  19572. '\u2FD0': '\u9F3B',
  19573. '\u2FD1': '\u9F4A',
  19574. '\u2FD2': '\u9F52',
  19575. '\u2FD3': '\u9F8D',
  19576. '\u2FD4': '\u9F9C',
  19577. '\u2FD5': '\u9FA0',
  19578. '\u3036': '\u3012',
  19579. '\u3038': '\u5341',
  19580. '\u3039': '\u5344',
  19581. '\u303A': '\u5345',
  19582. '\u309B': '\u0020\u3099',
  19583. '\u309C': '\u0020\u309A',
  19584. '\u3131': '\u1100',
  19585. '\u3132': '\u1101',
  19586. '\u3133': '\u11AA',
  19587. '\u3134': '\u1102',
  19588. '\u3135': '\u11AC',
  19589. '\u3136': '\u11AD',
  19590. '\u3137': '\u1103',
  19591. '\u3138': '\u1104',
  19592. '\u3139': '\u1105',
  19593. '\u313A': '\u11B0',
  19594. '\u313B': '\u11B1',
  19595. '\u313C': '\u11B2',
  19596. '\u313D': '\u11B3',
  19597. '\u313E': '\u11B4',
  19598. '\u313F': '\u11B5',
  19599. '\u3140': '\u111A',
  19600. '\u3141': '\u1106',
  19601. '\u3142': '\u1107',
  19602. '\u3143': '\u1108',
  19603. '\u3144': '\u1121',
  19604. '\u3145': '\u1109',
  19605. '\u3146': '\u110A',
  19606. '\u3147': '\u110B',
  19607. '\u3148': '\u110C',
  19608. '\u3149': '\u110D',
  19609. '\u314A': '\u110E',
  19610. '\u314B': '\u110F',
  19611. '\u314C': '\u1110',
  19612. '\u314D': '\u1111',
  19613. '\u314E': '\u1112',
  19614. '\u314F': '\u1161',
  19615. '\u3150': '\u1162',
  19616. '\u3151': '\u1163',
  19617. '\u3152': '\u1164',
  19618. '\u3153': '\u1165',
  19619. '\u3154': '\u1166',
  19620. '\u3155': '\u1167',
  19621. '\u3156': '\u1168',
  19622. '\u3157': '\u1169',
  19623. '\u3158': '\u116A',
  19624. '\u3159': '\u116B',
  19625. '\u315A': '\u116C',
  19626. '\u315B': '\u116D',
  19627. '\u315C': '\u116E',
  19628. '\u315D': '\u116F',
  19629. '\u315E': '\u1170',
  19630. '\u315F': '\u1171',
  19631. '\u3160': '\u1172',
  19632. '\u3161': '\u1173',
  19633. '\u3162': '\u1174',
  19634. '\u3163': '\u1175',
  19635. '\u3164': '\u1160',
  19636. '\u3165': '\u1114',
  19637. '\u3166': '\u1115',
  19638. '\u3167': '\u11C7',
  19639. '\u3168': '\u11C8',
  19640. '\u3169': '\u11CC',
  19641. '\u316A': '\u11CE',
  19642. '\u316B': '\u11D3',
  19643. '\u316C': '\u11D7',
  19644. '\u316D': '\u11D9',
  19645. '\u316E': '\u111C',
  19646. '\u316F': '\u11DD',
  19647. '\u3170': '\u11DF',
  19648. '\u3171': '\u111D',
  19649. '\u3172': '\u111E',
  19650. '\u3173': '\u1120',
  19651. '\u3174': '\u1122',
  19652. '\u3175': '\u1123',
  19653. '\u3176': '\u1127',
  19654. '\u3177': '\u1129',
  19655. '\u3178': '\u112B',
  19656. '\u3179': '\u112C',
  19657. '\u317A': '\u112D',
  19658. '\u317B': '\u112E',
  19659. '\u317C': '\u112F',
  19660. '\u317D': '\u1132',
  19661. '\u317E': '\u1136',
  19662. '\u317F': '\u1140',
  19663. '\u3180': '\u1147',
  19664. '\u3181': '\u114C',
  19665. '\u3182': '\u11F1',
  19666. '\u3183': '\u11F2',
  19667. '\u3184': '\u1157',
  19668. '\u3185': '\u1158',
  19669. '\u3186': '\u1159',
  19670. '\u3187': '\u1184',
  19671. '\u3188': '\u1185',
  19672. '\u3189': '\u1188',
  19673. '\u318A': '\u1191',
  19674. '\u318B': '\u1192',
  19675. '\u318C': '\u1194',
  19676. '\u318D': '\u119E',
  19677. '\u318E': '\u11A1',
  19678. '\u3200': '\u0028\u1100\u0029',
  19679. '\u3201': '\u0028\u1102\u0029',
  19680. '\u3202': '\u0028\u1103\u0029',
  19681. '\u3203': '\u0028\u1105\u0029',
  19682. '\u3204': '\u0028\u1106\u0029',
  19683. '\u3205': '\u0028\u1107\u0029',
  19684. '\u3206': '\u0028\u1109\u0029',
  19685. '\u3207': '\u0028\u110B\u0029',
  19686. '\u3208': '\u0028\u110C\u0029',
  19687. '\u3209': '\u0028\u110E\u0029',
  19688. '\u320A': '\u0028\u110F\u0029',
  19689. '\u320B': '\u0028\u1110\u0029',
  19690. '\u320C': '\u0028\u1111\u0029',
  19691. '\u320D': '\u0028\u1112\u0029',
  19692. '\u320E': '\u0028\u1100\u1161\u0029',
  19693. '\u320F': '\u0028\u1102\u1161\u0029',
  19694. '\u3210': '\u0028\u1103\u1161\u0029',
  19695. '\u3211': '\u0028\u1105\u1161\u0029',
  19696. '\u3212': '\u0028\u1106\u1161\u0029',
  19697. '\u3213': '\u0028\u1107\u1161\u0029',
  19698. '\u3214': '\u0028\u1109\u1161\u0029',
  19699. '\u3215': '\u0028\u110B\u1161\u0029',
  19700. '\u3216': '\u0028\u110C\u1161\u0029',
  19701. '\u3217': '\u0028\u110E\u1161\u0029',
  19702. '\u3218': '\u0028\u110F\u1161\u0029',
  19703. '\u3219': '\u0028\u1110\u1161\u0029',
  19704. '\u321A': '\u0028\u1111\u1161\u0029',
  19705. '\u321B': '\u0028\u1112\u1161\u0029',
  19706. '\u321C': '\u0028\u110C\u116E\u0029',
  19707. '\u321D': '\u0028\u110B\u1169\u110C\u1165\u11AB\u0029',
  19708. '\u321E': '\u0028\u110B\u1169\u1112\u116E\u0029',
  19709. '\u3220': '\u0028\u4E00\u0029',
  19710. '\u3221': '\u0028\u4E8C\u0029',
  19711. '\u3222': '\u0028\u4E09\u0029',
  19712. '\u3223': '\u0028\u56DB\u0029',
  19713. '\u3224': '\u0028\u4E94\u0029',
  19714. '\u3225': '\u0028\u516D\u0029',
  19715. '\u3226': '\u0028\u4E03\u0029',
  19716. '\u3227': '\u0028\u516B\u0029',
  19717. '\u3228': '\u0028\u4E5D\u0029',
  19718. '\u3229': '\u0028\u5341\u0029',
  19719. '\u322A': '\u0028\u6708\u0029',
  19720. '\u322B': '\u0028\u706B\u0029',
  19721. '\u322C': '\u0028\u6C34\u0029',
  19722. '\u322D': '\u0028\u6728\u0029',
  19723. '\u322E': '\u0028\u91D1\u0029',
  19724. '\u322F': '\u0028\u571F\u0029',
  19725. '\u3230': '\u0028\u65E5\u0029',
  19726. '\u3231': '\u0028\u682A\u0029',
  19727. '\u3232': '\u0028\u6709\u0029',
  19728. '\u3233': '\u0028\u793E\u0029',
  19729. '\u3234': '\u0028\u540D\u0029',
  19730. '\u3235': '\u0028\u7279\u0029',
  19731. '\u3236': '\u0028\u8CA1\u0029',
  19732. '\u3237': '\u0028\u795D\u0029',
  19733. '\u3238': '\u0028\u52B4\u0029',
  19734. '\u3239': '\u0028\u4EE3\u0029',
  19735. '\u323A': '\u0028\u547C\u0029',
  19736. '\u323B': '\u0028\u5B66\u0029',
  19737. '\u323C': '\u0028\u76E3\u0029',
  19738. '\u323D': '\u0028\u4F01\u0029',
  19739. '\u323E': '\u0028\u8CC7\u0029',
  19740. '\u323F': '\u0028\u5354\u0029',
  19741. '\u3240': '\u0028\u796D\u0029',
  19742. '\u3241': '\u0028\u4F11\u0029',
  19743. '\u3242': '\u0028\u81EA\u0029',
  19744. '\u3243': '\u0028\u81F3\u0029',
  19745. '\u32C0': '\u0031\u6708',
  19746. '\u32C1': '\u0032\u6708',
  19747. '\u32C2': '\u0033\u6708',
  19748. '\u32C3': '\u0034\u6708',
  19749. '\u32C4': '\u0035\u6708',
  19750. '\u32C5': '\u0036\u6708',
  19751. '\u32C6': '\u0037\u6708',
  19752. '\u32C7': '\u0038\u6708',
  19753. '\u32C8': '\u0039\u6708',
  19754. '\u32C9': '\u0031\u0030\u6708',
  19755. '\u32CA': '\u0031\u0031\u6708',
  19756. '\u32CB': '\u0031\u0032\u6708',
  19757. '\u3358': '\u0030\u70B9',
  19758. '\u3359': '\u0031\u70B9',
  19759. '\u335A': '\u0032\u70B9',
  19760. '\u335B': '\u0033\u70B9',
  19761. '\u335C': '\u0034\u70B9',
  19762. '\u335D': '\u0035\u70B9',
  19763. '\u335E': '\u0036\u70B9',
  19764. '\u335F': '\u0037\u70B9',
  19765. '\u3360': '\u0038\u70B9',
  19766. '\u3361': '\u0039\u70B9',
  19767. '\u3362': '\u0031\u0030\u70B9',
  19768. '\u3363': '\u0031\u0031\u70B9',
  19769. '\u3364': '\u0031\u0032\u70B9',
  19770. '\u3365': '\u0031\u0033\u70B9',
  19771. '\u3366': '\u0031\u0034\u70B9',
  19772. '\u3367': '\u0031\u0035\u70B9',
  19773. '\u3368': '\u0031\u0036\u70B9',
  19774. '\u3369': '\u0031\u0037\u70B9',
  19775. '\u336A': '\u0031\u0038\u70B9',
  19776. '\u336B': '\u0031\u0039\u70B9',
  19777. '\u336C': '\u0032\u0030\u70B9',
  19778. '\u336D': '\u0032\u0031\u70B9',
  19779. '\u336E': '\u0032\u0032\u70B9',
  19780. '\u336F': '\u0032\u0033\u70B9',
  19781. '\u3370': '\u0032\u0034\u70B9',
  19782. '\u33E0': '\u0031\u65E5',
  19783. '\u33E1': '\u0032\u65E5',
  19784. '\u33E2': '\u0033\u65E5',
  19785. '\u33E3': '\u0034\u65E5',
  19786. '\u33E4': '\u0035\u65E5',
  19787. '\u33E5': '\u0036\u65E5',
  19788. '\u33E6': '\u0037\u65E5',
  19789. '\u33E7': '\u0038\u65E5',
  19790. '\u33E8': '\u0039\u65E5',
  19791. '\u33E9': '\u0031\u0030\u65E5',
  19792. '\u33EA': '\u0031\u0031\u65E5',
  19793. '\u33EB': '\u0031\u0032\u65E5',
  19794. '\u33EC': '\u0031\u0033\u65E5',
  19795. '\u33ED': '\u0031\u0034\u65E5',
  19796. '\u33EE': '\u0031\u0035\u65E5',
  19797. '\u33EF': '\u0031\u0036\u65E5',
  19798. '\u33F0': '\u0031\u0037\u65E5',
  19799. '\u33F1': '\u0031\u0038\u65E5',
  19800. '\u33F2': '\u0031\u0039\u65E5',
  19801. '\u33F3': '\u0032\u0030\u65E5',
  19802. '\u33F4': '\u0032\u0031\u65E5',
  19803. '\u33F5': '\u0032\u0032\u65E5',
  19804. '\u33F6': '\u0032\u0033\u65E5',
  19805. '\u33F7': '\u0032\u0034\u65E5',
  19806. '\u33F8': '\u0032\u0035\u65E5',
  19807. '\u33F9': '\u0032\u0036\u65E5',
  19808. '\u33FA': '\u0032\u0037\u65E5',
  19809. '\u33FB': '\u0032\u0038\u65E5',
  19810. '\u33FC': '\u0032\u0039\u65E5',
  19811. '\u33FD': '\u0033\u0030\u65E5',
  19812. '\u33FE': '\u0033\u0031\u65E5',
  19813. '\uFB00': '\u0066\u0066',
  19814. '\uFB01': '\u0066\u0069',
  19815. '\uFB02': '\u0066\u006C',
  19816. '\uFB03': '\u0066\u0066\u0069',
  19817. '\uFB04': '\u0066\u0066\u006C',
  19818. '\uFB05': '\u017F\u0074',
  19819. '\uFB06': '\u0073\u0074',
  19820. '\uFB13': '\u0574\u0576',
  19821. '\uFB14': '\u0574\u0565',
  19822. '\uFB15': '\u0574\u056B',
  19823. '\uFB16': '\u057E\u0576',
  19824. '\uFB17': '\u0574\u056D',
  19825. '\uFB4F': '\u05D0\u05DC',
  19826. '\uFB50': '\u0671',
  19827. '\uFB51': '\u0671',
  19828. '\uFB52': '\u067B',
  19829. '\uFB53': '\u067B',
  19830. '\uFB54': '\u067B',
  19831. '\uFB55': '\u067B',
  19832. '\uFB56': '\u067E',
  19833. '\uFB57': '\u067E',
  19834. '\uFB58': '\u067E',
  19835. '\uFB59': '\u067E',
  19836. '\uFB5A': '\u0680',
  19837. '\uFB5B': '\u0680',
  19838. '\uFB5C': '\u0680',
  19839. '\uFB5D': '\u0680',
  19840. '\uFB5E': '\u067A',
  19841. '\uFB5F': '\u067A',
  19842. '\uFB60': '\u067A',
  19843. '\uFB61': '\u067A',
  19844. '\uFB62': '\u067F',
  19845. '\uFB63': '\u067F',
  19846. '\uFB64': '\u067F',
  19847. '\uFB65': '\u067F',
  19848. '\uFB66': '\u0679',
  19849. '\uFB67': '\u0679',
  19850. '\uFB68': '\u0679',
  19851. '\uFB69': '\u0679',
  19852. '\uFB6A': '\u06A4',
  19853. '\uFB6B': '\u06A4',
  19854. '\uFB6C': '\u06A4',
  19855. '\uFB6D': '\u06A4',
  19856. '\uFB6E': '\u06A6',
  19857. '\uFB6F': '\u06A6',
  19858. '\uFB70': '\u06A6',
  19859. '\uFB71': '\u06A6',
  19860. '\uFB72': '\u0684',
  19861. '\uFB73': '\u0684',
  19862. '\uFB74': '\u0684',
  19863. '\uFB75': '\u0684',
  19864. '\uFB76': '\u0683',
  19865. '\uFB77': '\u0683',
  19866. '\uFB78': '\u0683',
  19867. '\uFB79': '\u0683',
  19868. '\uFB7A': '\u0686',
  19869. '\uFB7B': '\u0686',
  19870. '\uFB7C': '\u0686',
  19871. '\uFB7D': '\u0686',
  19872. '\uFB7E': '\u0687',
  19873. '\uFB7F': '\u0687',
  19874. '\uFB80': '\u0687',
  19875. '\uFB81': '\u0687',
  19876. '\uFB82': '\u068D',
  19877. '\uFB83': '\u068D',
  19878. '\uFB84': '\u068C',
  19879. '\uFB85': '\u068C',
  19880. '\uFB86': '\u068E',
  19881. '\uFB87': '\u068E',
  19882. '\uFB88': '\u0688',
  19883. '\uFB89': '\u0688',
  19884. '\uFB8A': '\u0698',
  19885. '\uFB8B': '\u0698',
  19886. '\uFB8C': '\u0691',
  19887. '\uFB8D': '\u0691',
  19888. '\uFB8E': '\u06A9',
  19889. '\uFB8F': '\u06A9',
  19890. '\uFB90': '\u06A9',
  19891. '\uFB91': '\u06A9',
  19892. '\uFB92': '\u06AF',
  19893. '\uFB93': '\u06AF',
  19894. '\uFB94': '\u06AF',
  19895. '\uFB95': '\u06AF',
  19896. '\uFB96': '\u06B3',
  19897. '\uFB97': '\u06B3',
  19898. '\uFB98': '\u06B3',
  19899. '\uFB99': '\u06B3',
  19900. '\uFB9A': '\u06B1',
  19901. '\uFB9B': '\u06B1',
  19902. '\uFB9C': '\u06B1',
  19903. '\uFB9D': '\u06B1',
  19904. '\uFB9E': '\u06BA',
  19905. '\uFB9F': '\u06BA',
  19906. '\uFBA0': '\u06BB',
  19907. '\uFBA1': '\u06BB',
  19908. '\uFBA2': '\u06BB',
  19909. '\uFBA3': '\u06BB',
  19910. '\uFBA4': '\u06C0',
  19911. '\uFBA5': '\u06C0',
  19912. '\uFBA6': '\u06C1',
  19913. '\uFBA7': '\u06C1',
  19914. '\uFBA8': '\u06C1',
  19915. '\uFBA9': '\u06C1',
  19916. '\uFBAA': '\u06BE',
  19917. '\uFBAB': '\u06BE',
  19918. '\uFBAC': '\u06BE',
  19919. '\uFBAD': '\u06BE',
  19920. '\uFBAE': '\u06D2',
  19921. '\uFBAF': '\u06D2',
  19922. '\uFBB0': '\u06D3',
  19923. '\uFBB1': '\u06D3',
  19924. '\uFBD3': '\u06AD',
  19925. '\uFBD4': '\u06AD',
  19926. '\uFBD5': '\u06AD',
  19927. '\uFBD6': '\u06AD',
  19928. '\uFBD7': '\u06C7',
  19929. '\uFBD8': '\u06C7',
  19930. '\uFBD9': '\u06C6',
  19931. '\uFBDA': '\u06C6',
  19932. '\uFBDB': '\u06C8',
  19933. '\uFBDC': '\u06C8',
  19934. '\uFBDD': '\u0677',
  19935. '\uFBDE': '\u06CB',
  19936. '\uFBDF': '\u06CB',
  19937. '\uFBE0': '\u06C5',
  19938. '\uFBE1': '\u06C5',
  19939. '\uFBE2': '\u06C9',
  19940. '\uFBE3': '\u06C9',
  19941. '\uFBE4': '\u06D0',
  19942. '\uFBE5': '\u06D0',
  19943. '\uFBE6': '\u06D0',
  19944. '\uFBE7': '\u06D0',
  19945. '\uFBE8': '\u0649',
  19946. '\uFBE9': '\u0649',
  19947. '\uFBEA': '\u0626\u0627',
  19948. '\uFBEB': '\u0626\u0627',
  19949. '\uFBEC': '\u0626\u06D5',
  19950. '\uFBED': '\u0626\u06D5',
  19951. '\uFBEE': '\u0626\u0648',
  19952. '\uFBEF': '\u0626\u0648',
  19953. '\uFBF0': '\u0626\u06C7',
  19954. '\uFBF1': '\u0626\u06C7',
  19955. '\uFBF2': '\u0626\u06C6',
  19956. '\uFBF3': '\u0626\u06C6',
  19957. '\uFBF4': '\u0626\u06C8',
  19958. '\uFBF5': '\u0626\u06C8',
  19959. '\uFBF6': '\u0626\u06D0',
  19960. '\uFBF7': '\u0626\u06D0',
  19961. '\uFBF8': '\u0626\u06D0',
  19962. '\uFBF9': '\u0626\u0649',
  19963. '\uFBFA': '\u0626\u0649',
  19964. '\uFBFB': '\u0626\u0649',
  19965. '\uFBFC': '\u06CC',
  19966. '\uFBFD': '\u06CC',
  19967. '\uFBFE': '\u06CC',
  19968. '\uFBFF': '\u06CC',
  19969. '\uFC00': '\u0626\u062C',
  19970. '\uFC01': '\u0626\u062D',
  19971. '\uFC02': '\u0626\u0645',
  19972. '\uFC03': '\u0626\u0649',
  19973. '\uFC04': '\u0626\u064A',
  19974. '\uFC05': '\u0628\u062C',
  19975. '\uFC06': '\u0628\u062D',
  19976. '\uFC07': '\u0628\u062E',
  19977. '\uFC08': '\u0628\u0645',
  19978. '\uFC09': '\u0628\u0649',
  19979. '\uFC0A': '\u0628\u064A',
  19980. '\uFC0B': '\u062A\u062C',
  19981. '\uFC0C': '\u062A\u062D',
  19982. '\uFC0D': '\u062A\u062E',
  19983. '\uFC0E': '\u062A\u0645',
  19984. '\uFC0F': '\u062A\u0649',
  19985. '\uFC10': '\u062A\u064A',
  19986. '\uFC11': '\u062B\u062C',
  19987. '\uFC12': '\u062B\u0645',
  19988. '\uFC13': '\u062B\u0649',
  19989. '\uFC14': '\u062B\u064A',
  19990. '\uFC15': '\u062C\u062D',
  19991. '\uFC16': '\u062C\u0645',
  19992. '\uFC17': '\u062D\u062C',
  19993. '\uFC18': '\u062D\u0645',
  19994. '\uFC19': '\u062E\u062C',
  19995. '\uFC1A': '\u062E\u062D',
  19996. '\uFC1B': '\u062E\u0645',
  19997. '\uFC1C': '\u0633\u062C',
  19998. '\uFC1D': '\u0633\u062D',
  19999. '\uFC1E': '\u0633\u062E',
  20000. '\uFC1F': '\u0633\u0645',
  20001. '\uFC20': '\u0635\u062D',
  20002. '\uFC21': '\u0635\u0645',
  20003. '\uFC22': '\u0636\u062C',
  20004. '\uFC23': '\u0636\u062D',
  20005. '\uFC24': '\u0636\u062E',
  20006. '\uFC25': '\u0636\u0645',
  20007. '\uFC26': '\u0637\u062D',
  20008. '\uFC27': '\u0637\u0645',
  20009. '\uFC28': '\u0638\u0645',
  20010. '\uFC29': '\u0639\u062C',
  20011. '\uFC2A': '\u0639\u0645',
  20012. '\uFC2B': '\u063A\u062C',
  20013. '\uFC2C': '\u063A\u0645',
  20014. '\uFC2D': '\u0641\u062C',
  20015. '\uFC2E': '\u0641\u062D',
  20016. '\uFC2F': '\u0641\u062E',
  20017. '\uFC30': '\u0641\u0645',
  20018. '\uFC31': '\u0641\u0649',
  20019. '\uFC32': '\u0641\u064A',
  20020. '\uFC33': '\u0642\u062D',
  20021. '\uFC34': '\u0642\u0645',
  20022. '\uFC35': '\u0642\u0649',
  20023. '\uFC36': '\u0642\u064A',
  20024. '\uFC37': '\u0643\u0627',
  20025. '\uFC38': '\u0643\u062C',
  20026. '\uFC39': '\u0643\u062D',
  20027. '\uFC3A': '\u0643\u062E',
  20028. '\uFC3B': '\u0643\u0644',
  20029. '\uFC3C': '\u0643\u0645',
  20030. '\uFC3D': '\u0643\u0649',
  20031. '\uFC3E': '\u0643\u064A',
  20032. '\uFC3F': '\u0644\u062C',
  20033. '\uFC40': '\u0644\u062D',
  20034. '\uFC41': '\u0644\u062E',
  20035. '\uFC42': '\u0644\u0645',
  20036. '\uFC43': '\u0644\u0649',
  20037. '\uFC44': '\u0644\u064A',
  20038. '\uFC45': '\u0645\u062C',
  20039. '\uFC46': '\u0645\u062D',
  20040. '\uFC47': '\u0645\u062E',
  20041. '\uFC48': '\u0645\u0645',
  20042. '\uFC49': '\u0645\u0649',
  20043. '\uFC4A': '\u0645\u064A',
  20044. '\uFC4B': '\u0646\u062C',
  20045. '\uFC4C': '\u0646\u062D',
  20046. '\uFC4D': '\u0646\u062E',
  20047. '\uFC4E': '\u0646\u0645',
  20048. '\uFC4F': '\u0646\u0649',
  20049. '\uFC50': '\u0646\u064A',
  20050. '\uFC51': '\u0647\u062C',
  20051. '\uFC52': '\u0647\u0645',
  20052. '\uFC53': '\u0647\u0649',
  20053. '\uFC54': '\u0647\u064A',
  20054. '\uFC55': '\u064A\u062C',
  20055. '\uFC56': '\u064A\u062D',
  20056. '\uFC57': '\u064A\u062E',
  20057. '\uFC58': '\u064A\u0645',
  20058. '\uFC59': '\u064A\u0649',
  20059. '\uFC5A': '\u064A\u064A',
  20060. '\uFC5B': '\u0630\u0670',
  20061. '\uFC5C': '\u0631\u0670',
  20062. '\uFC5D': '\u0649\u0670',
  20063. '\uFC5E': '\u0020\u064C\u0651',
  20064. '\uFC5F': '\u0020\u064D\u0651',
  20065. '\uFC60': '\u0020\u064E\u0651',
  20066. '\uFC61': '\u0020\u064F\u0651',
  20067. '\uFC62': '\u0020\u0650\u0651',
  20068. '\uFC63': '\u0020\u0651\u0670',
  20069. '\uFC64': '\u0626\u0631',
  20070. '\uFC65': '\u0626\u0632',
  20071. '\uFC66': '\u0626\u0645',
  20072. '\uFC67': '\u0626\u0646',
  20073. '\uFC68': '\u0626\u0649',
  20074. '\uFC69': '\u0626\u064A',
  20075. '\uFC6A': '\u0628\u0631',
  20076. '\uFC6B': '\u0628\u0632',
  20077. '\uFC6C': '\u0628\u0645',
  20078. '\uFC6D': '\u0628\u0646',
  20079. '\uFC6E': '\u0628\u0649',
  20080. '\uFC6F': '\u0628\u064A',
  20081. '\uFC70': '\u062A\u0631',
  20082. '\uFC71': '\u062A\u0632',
  20083. '\uFC72': '\u062A\u0645',
  20084. '\uFC73': '\u062A\u0646',
  20085. '\uFC74': '\u062A\u0649',
  20086. '\uFC75': '\u062A\u064A',
  20087. '\uFC76': '\u062B\u0631',
  20088. '\uFC77': '\u062B\u0632',
  20089. '\uFC78': '\u062B\u0645',
  20090. '\uFC79': '\u062B\u0646',
  20091. '\uFC7A': '\u062B\u0649',
  20092. '\uFC7B': '\u062B\u064A',
  20093. '\uFC7C': '\u0641\u0649',
  20094. '\uFC7D': '\u0641\u064A',
  20095. '\uFC7E': '\u0642\u0649',
  20096. '\uFC7F': '\u0642\u064A',
  20097. '\uFC80': '\u0643\u0627',
  20098. '\uFC81': '\u0643\u0644',
  20099. '\uFC82': '\u0643\u0645',
  20100. '\uFC83': '\u0643\u0649',
  20101. '\uFC84': '\u0643\u064A',
  20102. '\uFC85': '\u0644\u0645',
  20103. '\uFC86': '\u0644\u0649',
  20104. '\uFC87': '\u0644\u064A',
  20105. '\uFC88': '\u0645\u0627',
  20106. '\uFC89': '\u0645\u0645',
  20107. '\uFC8A': '\u0646\u0631',
  20108. '\uFC8B': '\u0646\u0632',
  20109. '\uFC8C': '\u0646\u0645',
  20110. '\uFC8D': '\u0646\u0646',
  20111. '\uFC8E': '\u0646\u0649',
  20112. '\uFC8F': '\u0646\u064A',
  20113. '\uFC90': '\u0649\u0670',
  20114. '\uFC91': '\u064A\u0631',
  20115. '\uFC92': '\u064A\u0632',
  20116. '\uFC93': '\u064A\u0645',
  20117. '\uFC94': '\u064A\u0646',
  20118. '\uFC95': '\u064A\u0649',
  20119. '\uFC96': '\u064A\u064A',
  20120. '\uFC97': '\u0626\u062C',
  20121. '\uFC98': '\u0626\u062D',
  20122. '\uFC99': '\u0626\u062E',
  20123. '\uFC9A': '\u0626\u0645',
  20124. '\uFC9B': '\u0626\u0647',
  20125. '\uFC9C': '\u0628\u062C',
  20126. '\uFC9D': '\u0628\u062D',
  20127. '\uFC9E': '\u0628\u062E',
  20128. '\uFC9F': '\u0628\u0645',
  20129. '\uFCA0': '\u0628\u0647',
  20130. '\uFCA1': '\u062A\u062C',
  20131. '\uFCA2': '\u062A\u062D',
  20132. '\uFCA3': '\u062A\u062E',
  20133. '\uFCA4': '\u062A\u0645',
  20134. '\uFCA5': '\u062A\u0647',
  20135. '\uFCA6': '\u062B\u0645',
  20136. '\uFCA7': '\u062C\u062D',
  20137. '\uFCA8': '\u062C\u0645',
  20138. '\uFCA9': '\u062D\u062C',
  20139. '\uFCAA': '\u062D\u0645',
  20140. '\uFCAB': '\u062E\u062C',
  20141. '\uFCAC': '\u062E\u0645',
  20142. '\uFCAD': '\u0633\u062C',
  20143. '\uFCAE': '\u0633\u062D',
  20144. '\uFCAF': '\u0633\u062E',
  20145. '\uFCB0': '\u0633\u0645',
  20146. '\uFCB1': '\u0635\u062D',
  20147. '\uFCB2': '\u0635\u062E',
  20148. '\uFCB3': '\u0635\u0645',
  20149. '\uFCB4': '\u0636\u062C',
  20150. '\uFCB5': '\u0636\u062D',
  20151. '\uFCB6': '\u0636\u062E',
  20152. '\uFCB7': '\u0636\u0645',
  20153. '\uFCB8': '\u0637\u062D',
  20154. '\uFCB9': '\u0638\u0645',
  20155. '\uFCBA': '\u0639\u062C',
  20156. '\uFCBB': '\u0639\u0645',
  20157. '\uFCBC': '\u063A\u062C',
  20158. '\uFCBD': '\u063A\u0645',
  20159. '\uFCBE': '\u0641\u062C',
  20160. '\uFCBF': '\u0641\u062D',
  20161. '\uFCC0': '\u0641\u062E',
  20162. '\uFCC1': '\u0641\u0645',
  20163. '\uFCC2': '\u0642\u062D',
  20164. '\uFCC3': '\u0642\u0645',
  20165. '\uFCC4': '\u0643\u062C',
  20166. '\uFCC5': '\u0643\u062D',
  20167. '\uFCC6': '\u0643\u062E',
  20168. '\uFCC7': '\u0643\u0644',
  20169. '\uFCC8': '\u0643\u0645',
  20170. '\uFCC9': '\u0644\u062C',
  20171. '\uFCCA': '\u0644\u062D',
  20172. '\uFCCB': '\u0644\u062E',
  20173. '\uFCCC': '\u0644\u0645',
  20174. '\uFCCD': '\u0644\u0647',
  20175. '\uFCCE': '\u0645\u062C',
  20176. '\uFCCF': '\u0645\u062D',
  20177. '\uFCD0': '\u0645\u062E',
  20178. '\uFCD1': '\u0645\u0645',
  20179. '\uFCD2': '\u0646\u062C',
  20180. '\uFCD3': '\u0646\u062D',
  20181. '\uFCD4': '\u0646\u062E',
  20182. '\uFCD5': '\u0646\u0645',
  20183. '\uFCD6': '\u0646\u0647',
  20184. '\uFCD7': '\u0647\u062C',
  20185. '\uFCD8': '\u0647\u0645',
  20186. '\uFCD9': '\u0647\u0670',
  20187. '\uFCDA': '\u064A\u062C',
  20188. '\uFCDB': '\u064A\u062D',
  20189. '\uFCDC': '\u064A\u062E',
  20190. '\uFCDD': '\u064A\u0645',
  20191. '\uFCDE': '\u064A\u0647',
  20192. '\uFCDF': '\u0626\u0645',
  20193. '\uFCE0': '\u0626\u0647',
  20194. '\uFCE1': '\u0628\u0645',
  20195. '\uFCE2': '\u0628\u0647',
  20196. '\uFCE3': '\u062A\u0645',
  20197. '\uFCE4': '\u062A\u0647',
  20198. '\uFCE5': '\u062B\u0645',
  20199. '\uFCE6': '\u062B\u0647',
  20200. '\uFCE7': '\u0633\u0645',
  20201. '\uFCE8': '\u0633\u0647',
  20202. '\uFCE9': '\u0634\u0645',
  20203. '\uFCEA': '\u0634\u0647',
  20204. '\uFCEB': '\u0643\u0644',
  20205. '\uFCEC': '\u0643\u0645',
  20206. '\uFCED': '\u0644\u0645',
  20207. '\uFCEE': '\u0646\u0645',
  20208. '\uFCEF': '\u0646\u0647',
  20209. '\uFCF0': '\u064A\u0645',
  20210. '\uFCF1': '\u064A\u0647',
  20211. '\uFCF2': '\u0640\u064E\u0651',
  20212. '\uFCF3': '\u0640\u064F\u0651',
  20213. '\uFCF4': '\u0640\u0650\u0651',
  20214. '\uFCF5': '\u0637\u0649',
  20215. '\uFCF6': '\u0637\u064A',
  20216. '\uFCF7': '\u0639\u0649',
  20217. '\uFCF8': '\u0639\u064A',
  20218. '\uFCF9': '\u063A\u0649',
  20219. '\uFCFA': '\u063A\u064A',
  20220. '\uFCFB': '\u0633\u0649',
  20221. '\uFCFC': '\u0633\u064A',
  20222. '\uFCFD': '\u0634\u0649',
  20223. '\uFCFE': '\u0634\u064A',
  20224. '\uFCFF': '\u062D\u0649',
  20225. '\uFD00': '\u062D\u064A',
  20226. '\uFD01': '\u062C\u0649',
  20227. '\uFD02': '\u062C\u064A',
  20228. '\uFD03': '\u062E\u0649',
  20229. '\uFD04': '\u062E\u064A',
  20230. '\uFD05': '\u0635\u0649',
  20231. '\uFD06': '\u0635\u064A',
  20232. '\uFD07': '\u0636\u0649',
  20233. '\uFD08': '\u0636\u064A',
  20234. '\uFD09': '\u0634\u062C',
  20235. '\uFD0A': '\u0634\u062D',
  20236. '\uFD0B': '\u0634\u062E',
  20237. '\uFD0C': '\u0634\u0645',
  20238. '\uFD0D': '\u0634\u0631',
  20239. '\uFD0E': '\u0633\u0631',
  20240. '\uFD0F': '\u0635\u0631',
  20241. '\uFD10': '\u0636\u0631',
  20242. '\uFD11': '\u0637\u0649',
  20243. '\uFD12': '\u0637\u064A',
  20244. '\uFD13': '\u0639\u0649',
  20245. '\uFD14': '\u0639\u064A',
  20246. '\uFD15': '\u063A\u0649',
  20247. '\uFD16': '\u063A\u064A',
  20248. '\uFD17': '\u0633\u0649',
  20249. '\uFD18': '\u0633\u064A',
  20250. '\uFD19': '\u0634\u0649',
  20251. '\uFD1A': '\u0634\u064A',
  20252. '\uFD1B': '\u062D\u0649',
  20253. '\uFD1C': '\u062D\u064A',
  20254. '\uFD1D': '\u062C\u0649',
  20255. '\uFD1E': '\u062C\u064A',
  20256. '\uFD1F': '\u062E\u0649',
  20257. '\uFD20': '\u062E\u064A',
  20258. '\uFD21': '\u0635\u0649',
  20259. '\uFD22': '\u0635\u064A',
  20260. '\uFD23': '\u0636\u0649',
  20261. '\uFD24': '\u0636\u064A',
  20262. '\uFD25': '\u0634\u062C',
  20263. '\uFD26': '\u0634\u062D',
  20264. '\uFD27': '\u0634\u062E',
  20265. '\uFD28': '\u0634\u0645',
  20266. '\uFD29': '\u0634\u0631',
  20267. '\uFD2A': '\u0633\u0631',
  20268. '\uFD2B': '\u0635\u0631',
  20269. '\uFD2C': '\u0636\u0631',
  20270. '\uFD2D': '\u0634\u062C',
  20271. '\uFD2E': '\u0634\u062D',
  20272. '\uFD2F': '\u0634\u062E',
  20273. '\uFD30': '\u0634\u0645',
  20274. '\uFD31': '\u0633\u0647',
  20275. '\uFD32': '\u0634\u0647',
  20276. '\uFD33': '\u0637\u0645',
  20277. '\uFD34': '\u0633\u062C',
  20278. '\uFD35': '\u0633\u062D',
  20279. '\uFD36': '\u0633\u062E',
  20280. '\uFD37': '\u0634\u062C',
  20281. '\uFD38': '\u0634\u062D',
  20282. '\uFD39': '\u0634\u062E',
  20283. '\uFD3A': '\u0637\u0645',
  20284. '\uFD3B': '\u0638\u0645',
  20285. '\uFD3C': '\u0627\u064B',
  20286. '\uFD3D': '\u0627\u064B',
  20287. '\uFD50': '\u062A\u062C\u0645',
  20288. '\uFD51': '\u062A\u062D\u062C',
  20289. '\uFD52': '\u062A\u062D\u062C',
  20290. '\uFD53': '\u062A\u062D\u0645',
  20291. '\uFD54': '\u062A\u062E\u0645',
  20292. '\uFD55': '\u062A\u0645\u062C',
  20293. '\uFD56': '\u062A\u0645\u062D',
  20294. '\uFD57': '\u062A\u0645\u062E',
  20295. '\uFD58': '\u062C\u0645\u062D',
  20296. '\uFD59': '\u062C\u0645\u062D',
  20297. '\uFD5A': '\u062D\u0645\u064A',
  20298. '\uFD5B': '\u062D\u0645\u0649',
  20299. '\uFD5C': '\u0633\u062D\u062C',
  20300. '\uFD5D': '\u0633\u062C\u062D',
  20301. '\uFD5E': '\u0633\u062C\u0649',
  20302. '\uFD5F': '\u0633\u0645\u062D',
  20303. '\uFD60': '\u0633\u0645\u062D',
  20304. '\uFD61': '\u0633\u0645\u062C',
  20305. '\uFD62': '\u0633\u0645\u0645',
  20306. '\uFD63': '\u0633\u0645\u0645',
  20307. '\uFD64': '\u0635\u062D\u062D',
  20308. '\uFD65': '\u0635\u062D\u062D',
  20309. '\uFD66': '\u0635\u0645\u0645',
  20310. '\uFD67': '\u0634\u062D\u0645',
  20311. '\uFD68': '\u0634\u062D\u0645',
  20312. '\uFD69': '\u0634\u062C\u064A',
  20313. '\uFD6A': '\u0634\u0645\u062E',
  20314. '\uFD6B': '\u0634\u0645\u062E',
  20315. '\uFD6C': '\u0634\u0645\u0645',
  20316. '\uFD6D': '\u0634\u0645\u0645',
  20317. '\uFD6E': '\u0636\u062D\u0649',
  20318. '\uFD6F': '\u0636\u062E\u0645',
  20319. '\uFD70': '\u0636\u062E\u0645',
  20320. '\uFD71': '\u0637\u0645\u062D',
  20321. '\uFD72': '\u0637\u0645\u062D',
  20322. '\uFD73': '\u0637\u0645\u0645',
  20323. '\uFD74': '\u0637\u0645\u064A',
  20324. '\uFD75': '\u0639\u062C\u0645',
  20325. '\uFD76': '\u0639\u0645\u0645',
  20326. '\uFD77': '\u0639\u0645\u0645',
  20327. '\uFD78': '\u0639\u0645\u0649',
  20328. '\uFD79': '\u063A\u0645\u0645',
  20329. '\uFD7A': '\u063A\u0645\u064A',
  20330. '\uFD7B': '\u063A\u0645\u0649',
  20331. '\uFD7C': '\u0641\u062E\u0645',
  20332. '\uFD7D': '\u0641\u062E\u0645',
  20333. '\uFD7E': '\u0642\u0645\u062D',
  20334. '\uFD7F': '\u0642\u0645\u0645',
  20335. '\uFD80': '\u0644\u062D\u0645',
  20336. '\uFD81': '\u0644\u062D\u064A',
  20337. '\uFD82': '\u0644\u062D\u0649',
  20338. '\uFD83': '\u0644\u062C\u062C',
  20339. '\uFD84': '\u0644\u062C\u062C',
  20340. '\uFD85': '\u0644\u062E\u0645',
  20341. '\uFD86': '\u0644\u062E\u0645',
  20342. '\uFD87': '\u0644\u0645\u062D',
  20343. '\uFD88': '\u0644\u0645\u062D',
  20344. '\uFD89': '\u0645\u062D\u062C',
  20345. '\uFD8A': '\u0645\u062D\u0645',
  20346. '\uFD8B': '\u0645\u062D\u064A',
  20347. '\uFD8C': '\u0645\u062C\u062D',
  20348. '\uFD8D': '\u0645\u062C\u0645',
  20349. '\uFD8E': '\u0645\u062E\u062C',
  20350. '\uFD8F': '\u0645\u062E\u0645',
  20351. '\uFD92': '\u0645\u062C\u062E',
  20352. '\uFD93': '\u0647\u0645\u062C',
  20353. '\uFD94': '\u0647\u0645\u0645',
  20354. '\uFD95': '\u0646\u062D\u0645',
  20355. '\uFD96': '\u0646\u062D\u0649',
  20356. '\uFD97': '\u0646\u062C\u0645',
  20357. '\uFD98': '\u0646\u062C\u0645',
  20358. '\uFD99': '\u0646\u062C\u0649',
  20359. '\uFD9A': '\u0646\u0645\u064A',
  20360. '\uFD9B': '\u0646\u0645\u0649',
  20361. '\uFD9C': '\u064A\u0645\u0645',
  20362. '\uFD9D': '\u064A\u0645\u0645',
  20363. '\uFD9E': '\u0628\u062E\u064A',
  20364. '\uFD9F': '\u062A\u062C\u064A',
  20365. '\uFDA0': '\u062A\u062C\u0649',
  20366. '\uFDA1': '\u062A\u062E\u064A',
  20367. '\uFDA2': '\u062A\u062E\u0649',
  20368. '\uFDA3': '\u062A\u0645\u064A',
  20369. '\uFDA4': '\u062A\u0645\u0649',
  20370. '\uFDA5': '\u062C\u0645\u064A',
  20371. '\uFDA6': '\u062C\u062D\u0649',
  20372. '\uFDA7': '\u062C\u0645\u0649',
  20373. '\uFDA8': '\u0633\u062E\u0649',
  20374. '\uFDA9': '\u0635\u062D\u064A',
  20375. '\uFDAA': '\u0634\u062D\u064A',
  20376. '\uFDAB': '\u0636\u062D\u064A',
  20377. '\uFDAC': '\u0644\u062C\u064A',
  20378. '\uFDAD': '\u0644\u0645\u064A',
  20379. '\uFDAE': '\u064A\u062D\u064A',
  20380. '\uFDAF': '\u064A\u062C\u064A',
  20381. '\uFDB0': '\u064A\u0645\u064A',
  20382. '\uFDB1': '\u0645\u0645\u064A',
  20383. '\uFDB2': '\u0642\u0645\u064A',
  20384. '\uFDB3': '\u0646\u062D\u064A',
  20385. '\uFDB4': '\u0642\u0645\u062D',
  20386. '\uFDB5': '\u0644\u062D\u0645',
  20387. '\uFDB6': '\u0639\u0645\u064A',
  20388. '\uFDB7': '\u0643\u0645\u064A',
  20389. '\uFDB8': '\u0646\u062C\u062D',
  20390. '\uFDB9': '\u0645\u062E\u064A',
  20391. '\uFDBA': '\u0644\u062C\u0645',
  20392. '\uFDBB': '\u0643\u0645\u0645',
  20393. '\uFDBC': '\u0644\u062C\u0645',
  20394. '\uFDBD': '\u0646\u062C\u062D',
  20395. '\uFDBE': '\u062C\u062D\u064A',
  20396. '\uFDBF': '\u062D\u062C\u064A',
  20397. '\uFDC0': '\u0645\u062C\u064A',
  20398. '\uFDC1': '\u0641\u0645\u064A',
  20399. '\uFDC2': '\u0628\u062D\u064A',
  20400. '\uFDC3': '\u0643\u0645\u0645',
  20401. '\uFDC4': '\u0639\u062C\u0645',
  20402. '\uFDC5': '\u0635\u0645\u0645',
  20403. '\uFDC6': '\u0633\u062E\u064A',
  20404. '\uFDC7': '\u0646\u062C\u064A',
  20405. '\uFE49': '\u203E',
  20406. '\uFE4A': '\u203E',
  20407. '\uFE4B': '\u203E',
  20408. '\uFE4C': '\u203E',
  20409. '\uFE4D': '\u005F',
  20410. '\uFE4E': '\u005F',
  20411. '\uFE4F': '\u005F',
  20412. '\uFE80': '\u0621',
  20413. '\uFE81': '\u0622',
  20414. '\uFE82': '\u0622',
  20415. '\uFE83': '\u0623',
  20416. '\uFE84': '\u0623',
  20417. '\uFE85': '\u0624',
  20418. '\uFE86': '\u0624',
  20419. '\uFE87': '\u0625',
  20420. '\uFE88': '\u0625',
  20421. '\uFE89': '\u0626',
  20422. '\uFE8A': '\u0626',
  20423. '\uFE8B': '\u0626',
  20424. '\uFE8C': '\u0626',
  20425. '\uFE8D': '\u0627',
  20426. '\uFE8E': '\u0627',
  20427. '\uFE8F': '\u0628',
  20428. '\uFE90': '\u0628',
  20429. '\uFE91': '\u0628',
  20430. '\uFE92': '\u0628',
  20431. '\uFE93': '\u0629',
  20432. '\uFE94': '\u0629',
  20433. '\uFE95': '\u062A',
  20434. '\uFE96': '\u062A',
  20435. '\uFE97': '\u062A',
  20436. '\uFE98': '\u062A',
  20437. '\uFE99': '\u062B',
  20438. '\uFE9A': '\u062B',
  20439. '\uFE9B': '\u062B',
  20440. '\uFE9C': '\u062B',
  20441. '\uFE9D': '\u062C',
  20442. '\uFE9E': '\u062C',
  20443. '\uFE9F': '\u062C',
  20444. '\uFEA0': '\u062C',
  20445. '\uFEA1': '\u062D',
  20446. '\uFEA2': '\u062D',
  20447. '\uFEA3': '\u062D',
  20448. '\uFEA4': '\u062D',
  20449. '\uFEA5': '\u062E',
  20450. '\uFEA6': '\u062E',
  20451. '\uFEA7': '\u062E',
  20452. '\uFEA8': '\u062E',
  20453. '\uFEA9': '\u062F',
  20454. '\uFEAA': '\u062F',
  20455. '\uFEAB': '\u0630',
  20456. '\uFEAC': '\u0630',
  20457. '\uFEAD': '\u0631',
  20458. '\uFEAE': '\u0631',
  20459. '\uFEAF': '\u0632',
  20460. '\uFEB0': '\u0632',
  20461. '\uFEB1': '\u0633',
  20462. '\uFEB2': '\u0633',
  20463. '\uFEB3': '\u0633',
  20464. '\uFEB4': '\u0633',
  20465. '\uFEB5': '\u0634',
  20466. '\uFEB6': '\u0634',
  20467. '\uFEB7': '\u0634',
  20468. '\uFEB8': '\u0634',
  20469. '\uFEB9': '\u0635',
  20470. '\uFEBA': '\u0635',
  20471. '\uFEBB': '\u0635',
  20472. '\uFEBC': '\u0635',
  20473. '\uFEBD': '\u0636',
  20474. '\uFEBE': '\u0636',
  20475. '\uFEBF': '\u0636',
  20476. '\uFEC0': '\u0636',
  20477. '\uFEC1': '\u0637',
  20478. '\uFEC2': '\u0637',
  20479. '\uFEC3': '\u0637',
  20480. '\uFEC4': '\u0637',
  20481. '\uFEC5': '\u0638',
  20482. '\uFEC6': '\u0638',
  20483. '\uFEC7': '\u0638',
  20484. '\uFEC8': '\u0638',
  20485. '\uFEC9': '\u0639',
  20486. '\uFECA': '\u0639',
  20487. '\uFECB': '\u0639',
  20488. '\uFECC': '\u0639',
  20489. '\uFECD': '\u063A',
  20490. '\uFECE': '\u063A',
  20491. '\uFECF': '\u063A',
  20492. '\uFED0': '\u063A',
  20493. '\uFED1': '\u0641',
  20494. '\uFED2': '\u0641',
  20495. '\uFED3': '\u0641',
  20496. '\uFED4': '\u0641',
  20497. '\uFED5': '\u0642',
  20498. '\uFED6': '\u0642',
  20499. '\uFED7': '\u0642',
  20500. '\uFED8': '\u0642',
  20501. '\uFED9': '\u0643',
  20502. '\uFEDA': '\u0643',
  20503. '\uFEDB': '\u0643',
  20504. '\uFEDC': '\u0643',
  20505. '\uFEDD': '\u0644',
  20506. '\uFEDE': '\u0644',
  20507. '\uFEDF': '\u0644',
  20508. '\uFEE0': '\u0644',
  20509. '\uFEE1': '\u0645',
  20510. '\uFEE2': '\u0645',
  20511. '\uFEE3': '\u0645',
  20512. '\uFEE4': '\u0645',
  20513. '\uFEE5': '\u0646',
  20514. '\uFEE6': '\u0646',
  20515. '\uFEE7': '\u0646',
  20516. '\uFEE8': '\u0646',
  20517. '\uFEE9': '\u0647',
  20518. '\uFEEA': '\u0647',
  20519. '\uFEEB': '\u0647',
  20520. '\uFEEC': '\u0647',
  20521. '\uFEED': '\u0648',
  20522. '\uFEEE': '\u0648',
  20523. '\uFEEF': '\u0649',
  20524. '\uFEF0': '\u0649',
  20525. '\uFEF1': '\u064A',
  20526. '\uFEF2': '\u064A',
  20527. '\uFEF3': '\u064A',
  20528. '\uFEF4': '\u064A',
  20529. '\uFEF5': '\u0644\u0622',
  20530. '\uFEF6': '\u0644\u0622',
  20531. '\uFEF7': '\u0644\u0623',
  20532. '\uFEF8': '\u0644\u0623',
  20533. '\uFEF9': '\u0644\u0625',
  20534. '\uFEFA': '\u0644\u0625',
  20535. '\uFEFB': '\u0644\u0627',
  20536. '\uFEFC': '\u0644\u0627'
  20537. };
  20538. function reverseIfRtl(chars) {
  20539. var charsLength = chars.length;
  20540. //reverse an arabic ligature
  20541. if (charsLength <= 1 || !isRTLRangeFor(chars.charCodeAt(0))) {
  20542. return chars;
  20543. }
  20544. var s = '';
  20545. for (var ii = charsLength - 1; ii >= 0; ii--) {
  20546. s += chars[ii];
  20547. }
  20548. return s;
  20549. }
  20550. function adjustWidths(properties) {
  20551. if (properties.fontMatrix[0] === FONT_IDENTITY_MATRIX[0]) {
  20552. return;
  20553. }
  20554. // adjusting width to fontMatrix scale
  20555. var scale = 0.001 / properties.fontMatrix[0];
  20556. var glyphsWidths = properties.widths;
  20557. for (var glyph in glyphsWidths) {
  20558. glyphsWidths[glyph] *= scale;
  20559. }
  20560. properties.defaultWidth *= scale;
  20561. }
  20562. function getFontType(type, subtype) {
  20563. switch (type) {
  20564. case 'Type1':
  20565. return subtype === 'Type1C' ? FontType.TYPE1C : FontType.TYPE1;
  20566. case 'CIDFontType0':
  20567. return subtype === 'CIDFontType0C' ? FontType.CIDFONTTYPE0C :
  20568. FontType.CIDFONTTYPE0;
  20569. case 'OpenType':
  20570. return FontType.OPENTYPE;
  20571. case 'TrueType':
  20572. return FontType.TRUETYPE;
  20573. case 'CIDFontType2':
  20574. return FontType.CIDFONTTYPE2;
  20575. case 'MMType1':
  20576. return FontType.MMTYPE1;
  20577. case 'Type0':
  20578. return FontType.TYPE0;
  20579. default:
  20580. return FontType.UNKNOWN;
  20581. }
  20582. }
  20583. var Glyph = (function GlyphClosure() {
  20584. function Glyph(fontChar, unicode, accent, width, vmetric, operatorListId) {
  20585. this.fontChar = fontChar;
  20586. this.unicode = unicode;
  20587. this.accent = accent;
  20588. this.width = width;
  20589. this.vmetric = vmetric;
  20590. this.operatorListId = operatorListId;
  20591. }
  20592. Glyph.prototype.matchesForCache =
  20593. function(fontChar, unicode, accent, width, vmetric, operatorListId) {
  20594. return this.fontChar === fontChar &&
  20595. this.unicode === unicode &&
  20596. this.accent === accent &&
  20597. this.width === width &&
  20598. this.vmetric === vmetric &&
  20599. this.operatorListId === operatorListId;
  20600. };
  20601. return Glyph;
  20602. })();
  20603. var ToUnicodeMap = (function ToUnicodeMapClosure() {
  20604. function ToUnicodeMap(cmap) {
  20605. // The elements of this._map can be integers or strings, depending on how
  20606. // |cmap| was created.
  20607. this._map = cmap;
  20608. }
  20609. ToUnicodeMap.prototype = {
  20610. get length() {
  20611. return this._map.length;
  20612. },
  20613. forEach: function(callback) {
  20614. for (var charCode in this._map) {
  20615. callback(charCode, this._map[charCode].charCodeAt(0));
  20616. }
  20617. },
  20618. has: function(i) {
  20619. return this._map[i] !== undefined;
  20620. },
  20621. get: function(i) {
  20622. return this._map[i];
  20623. },
  20624. charCodeOf: function(v) {
  20625. return this._map.indexOf(v);
  20626. }
  20627. };
  20628. return ToUnicodeMap;
  20629. })();
  20630. var IdentityToUnicodeMap = (function IdentityToUnicodeMapClosure() {
  20631. function IdentityToUnicodeMap(firstChar, lastChar) {
  20632. this.firstChar = firstChar;
  20633. this.lastChar = lastChar;
  20634. }
  20635. IdentityToUnicodeMap.prototype = {
  20636. get length() {
  20637. return (this.lastChar + 1) - this.firstChar;
  20638. },
  20639. forEach: function (callback) {
  20640. for (var i = this.firstChar, ii = this.lastChar; i <= ii; i++) {
  20641. callback(i, i);
  20642. }
  20643. },
  20644. has: function (i) {
  20645. return this.firstChar <= i && i <= this.lastChar;
  20646. },
  20647. get: function (i) {
  20648. if (this.firstChar <= i && i <= this.lastChar) {
  20649. return String.fromCharCode(i);
  20650. }
  20651. return undefined;
  20652. },
  20653. charCodeOf: function (v) {
  20654. error('should not call .charCodeOf');
  20655. }
  20656. };
  20657. return IdentityToUnicodeMap;
  20658. })();
  20659. var OpenTypeFileBuilder = (function OpenTypeFileBuilderClosure() {
  20660. function writeInt16(dest, offset, num) {
  20661. dest[offset] = (num >> 8) & 0xFF;
  20662. dest[offset + 1] = num & 0xFF;
  20663. }
  20664. function writeInt32(dest, offset, num) {
  20665. dest[offset] = (num >> 24) & 0xFF;
  20666. dest[offset + 1] = (num >> 16) & 0xFF;
  20667. dest[offset + 2] = (num >> 8) & 0xFF;
  20668. dest[offset + 3] = num & 0xFF;
  20669. }
  20670. function writeData(dest, offset, data) {
  20671. var i, ii;
  20672. if (data instanceof Uint8Array) {
  20673. dest.set(data, offset);
  20674. } else if (typeof data === 'string') {
  20675. for (i = 0, ii = data.length; i < ii; i++) {
  20676. dest[offset++] = data.charCodeAt(i) & 0xFF;
  20677. }
  20678. } else {
  20679. // treating everything else as array
  20680. for (i = 0, ii = data.length; i < ii; i++) {
  20681. dest[offset++] = data[i] & 0xFF;
  20682. }
  20683. }
  20684. }
  20685. function OpenTypeFileBuilder(sfnt) {
  20686. this.sfnt = sfnt;
  20687. this.tables = Object.create(null);
  20688. }
  20689. OpenTypeFileBuilder.getSearchParams =
  20690. function OpenTypeFileBuilder_getSearchParams(entriesCount, entrySize) {
  20691. var maxPower2 = 1, log2 = 0;
  20692. while ((maxPower2 ^ entriesCount) > maxPower2) {
  20693. maxPower2 <<= 1;
  20694. log2++;
  20695. }
  20696. var searchRange = maxPower2 * entrySize;
  20697. return {
  20698. range: searchRange,
  20699. entry: log2,
  20700. rangeShift: entrySize * entriesCount - searchRange
  20701. };
  20702. };
  20703. var OTF_HEADER_SIZE = 12;
  20704. var OTF_TABLE_ENTRY_SIZE = 16;
  20705. OpenTypeFileBuilder.prototype = {
  20706. toArray: function OpenTypeFileBuilder_toArray() {
  20707. var sfnt = this.sfnt;
  20708. // Tables needs to be written by ascendant alphabetic order
  20709. var tables = this.tables;
  20710. var tablesNames = Object.keys(tables);
  20711. tablesNames.sort();
  20712. var numTables = tablesNames.length;
  20713. var i, j, jj, table, tableName;
  20714. // layout the tables data
  20715. var offset = OTF_HEADER_SIZE + numTables * OTF_TABLE_ENTRY_SIZE;
  20716. var tableOffsets = [offset];
  20717. for (i = 0; i < numTables; i++) {
  20718. table = tables[tablesNames[i]];
  20719. var paddedLength = ((table.length + 3) & ~3) >>> 0;
  20720. offset += paddedLength;
  20721. tableOffsets.push(offset);
  20722. }
  20723. var file = new Uint8Array(offset);
  20724. // write the table data first (mostly for checksum)
  20725. for (i = 0; i < numTables; i++) {
  20726. table = tables[tablesNames[i]];
  20727. writeData(file, tableOffsets[i], table);
  20728. }
  20729. // sfnt version (4 bytes)
  20730. if (sfnt === 'true') {
  20731. // Windows hates the Mac TrueType sfnt version number
  20732. sfnt = string32(0x00010000);
  20733. }
  20734. file[0] = sfnt.charCodeAt(0) & 0xFF;
  20735. file[1] = sfnt.charCodeAt(1) & 0xFF;
  20736. file[2] = sfnt.charCodeAt(2) & 0xFF;
  20737. file[3] = sfnt.charCodeAt(3) & 0xFF;
  20738. // numTables (2 bytes)
  20739. writeInt16(file, 4, numTables);
  20740. var searchParams = OpenTypeFileBuilder.getSearchParams(numTables, 16);
  20741. // searchRange (2 bytes)
  20742. writeInt16(file, 6, searchParams.range);
  20743. // entrySelector (2 bytes)
  20744. writeInt16(file, 8, searchParams.entry);
  20745. // rangeShift (2 bytes)
  20746. writeInt16(file, 10, searchParams.rangeShift);
  20747. offset = OTF_HEADER_SIZE;
  20748. // writing table entries
  20749. for (i = 0; i < numTables; i++) {
  20750. tableName = tablesNames[i];
  20751. file[offset] = tableName.charCodeAt(0) & 0xFF;
  20752. file[offset + 1] = tableName.charCodeAt(1) & 0xFF;
  20753. file[offset + 2] = tableName.charCodeAt(2) & 0xFF;
  20754. file[offset + 3] = tableName.charCodeAt(3) & 0xFF;
  20755. // checksum
  20756. var checksum = 0;
  20757. for (j = tableOffsets[i], jj = tableOffsets[i + 1]; j < jj; j += 4) {
  20758. var quad = (file[j] << 24) + (file[j + 1] << 16) +
  20759. (file[j + 2] << 8) + file[j + 3];
  20760. checksum = (checksum + quad) | 0;
  20761. }
  20762. writeInt32(file, offset + 4, checksum);
  20763. // offset
  20764. writeInt32(file, offset + 8, tableOffsets[i]);
  20765. // length
  20766. writeInt32(file, offset + 12, tables[tableName].length);
  20767. offset += OTF_TABLE_ENTRY_SIZE;
  20768. }
  20769. return file;
  20770. },
  20771. addTable: function OpenTypeFileBuilder_addTable(tag, data) {
  20772. if (tag in this.tables) {
  20773. throw new Error('Table ' + tag + ' already exists');
  20774. }
  20775. this.tables[tag] = data;
  20776. }
  20777. };
  20778. return OpenTypeFileBuilder;
  20779. })();
  20780. /**
  20781. * 'Font' is the class the outside world should use, it encapsulate all the font
  20782. * decoding logics whatever type it is (assuming the font type is supported).
  20783. *
  20784. * For example to read a Type1 font and to attach it to the document:
  20785. * var type1Font = new Font("MyFontName", binaryFile, propertiesObject);
  20786. * type1Font.bind();
  20787. */
  20788. var Font = (function FontClosure() {
  20789. function Font(name, file, properties) {
  20790. var charCode, glyphName, fontChar;
  20791. this.name = name;
  20792. this.loadedName = properties.loadedName;
  20793. this.isType3Font = properties.isType3Font;
  20794. this.sizes = [];
  20795. this.glyphCache = {};
  20796. var names = name.split('+');
  20797. names = names.length > 1 ? names[1] : names[0];
  20798. names = names.split(/[-,_]/g)[0];
  20799. this.isSerifFont = !!(properties.flags & FontFlags.Serif);
  20800. this.isSymbolicFont = !!(properties.flags & FontFlags.Symbolic);
  20801. this.isMonospace = !!(properties.flags & FontFlags.FixedPitch);
  20802. var type = properties.type;
  20803. var subtype = properties.subtype;
  20804. this.type = type;
  20805. this.fallbackName = (this.isMonospace ? 'monospace' :
  20806. (this.isSerifFont ? 'serif' : 'sans-serif'));
  20807. this.differences = properties.differences;
  20808. this.widths = properties.widths;
  20809. this.defaultWidth = properties.defaultWidth;
  20810. this.composite = properties.composite;
  20811. this.wideChars = properties.wideChars;
  20812. this.cMap = properties.cMap;
  20813. this.ascent = properties.ascent / PDF_GLYPH_SPACE_UNITS;
  20814. this.descent = properties.descent / PDF_GLYPH_SPACE_UNITS;
  20815. this.fontMatrix = properties.fontMatrix;
  20816. this.toUnicode = properties.toUnicode = this.buildToUnicode(properties);
  20817. this.toFontChar = [];
  20818. if (properties.type === 'Type3') {
  20819. for (charCode = 0; charCode < 256; charCode++) {
  20820. this.toFontChar[charCode] = (this.differences[charCode] ||
  20821. properties.defaultEncoding[charCode]);
  20822. }
  20823. this.fontType = FontType.TYPE3;
  20824. return;
  20825. }
  20826. this.cidEncoding = properties.cidEncoding;
  20827. this.vertical = properties.vertical;
  20828. if (this.vertical) {
  20829. this.vmetrics = properties.vmetrics;
  20830. this.defaultVMetrics = properties.defaultVMetrics;
  20831. }
  20832. if (!file || file.isEmpty) {
  20833. if (file) {
  20834. // Some bad PDF generators will include empty font files,
  20835. // attempting to recover by assuming that no file exists.
  20836. warn('Font file is empty in "' + name + '" (' + this.loadedName + ')');
  20837. }
  20838. this.missingFile = true;
  20839. // The file data is not specified. Trying to fix the font name
  20840. // to be used with the canvas.font.
  20841. var fontName = name.replace(/[,_]/g, '-');
  20842. var isStandardFont = !!stdFontMap[fontName] ||
  20843. !!(nonStdFontMap[fontName] && stdFontMap[nonStdFontMap[fontName]]);
  20844. fontName = stdFontMap[fontName] || nonStdFontMap[fontName] || fontName;
  20845. this.bold = (fontName.search(/bold/gi) !== -1);
  20846. this.italic = ((fontName.search(/oblique/gi) !== -1) ||
  20847. (fontName.search(/italic/gi) !== -1));
  20848. // Use 'name' instead of 'fontName' here because the original
  20849. // name ArialBlack for example will be replaced by Helvetica.
  20850. this.black = (name.search(/Black/g) !== -1);
  20851. // if at least one width is present, remeasure all chars when exists
  20852. this.remeasure = Object.keys(this.widths).length > 0;
  20853. if (isStandardFont && type === 'CIDFontType2' &&
  20854. properties.cidEncoding.indexOf('Identity-') === 0) {
  20855. // Standard fonts might be embedded as CID font without glyph mapping.
  20856. // Building one based on GlyphMapForStandardFonts.
  20857. var map = [];
  20858. for (var code in GlyphMapForStandardFonts) {
  20859. map[+code] = GlyphMapForStandardFonts[code];
  20860. }
  20861. var isIdentityUnicode = this.toUnicode instanceof IdentityToUnicodeMap;
  20862. if (!isIdentityUnicode) {
  20863. this.toUnicode.forEach(function(charCode, unicodeCharCode) {
  20864. map[+charCode] = unicodeCharCode;
  20865. });
  20866. }
  20867. this.toFontChar = map;
  20868. this.toUnicode = new ToUnicodeMap(map);
  20869. } else if (/Symbol/i.test(fontName)) {
  20870. var symbols = Encodings.SymbolSetEncoding;
  20871. for (charCode in symbols) {
  20872. fontChar = GlyphsUnicode[symbols[charCode]];
  20873. if (!fontChar) {
  20874. continue;
  20875. }
  20876. this.toFontChar[charCode] = fontChar;
  20877. }
  20878. for (charCode in properties.differences) {
  20879. fontChar = GlyphsUnicode[properties.differences[charCode]];
  20880. if (!fontChar) {
  20881. continue;
  20882. }
  20883. this.toFontChar[charCode] = fontChar;
  20884. }
  20885. } else if (/Dingbats/i.test(fontName)) {
  20886. if (/Wingdings/i.test(name)) {
  20887. warn('Wingdings font without embedded font file, ' +
  20888. 'falling back to the ZapfDingbats encoding.');
  20889. }
  20890. var dingbats = Encodings.ZapfDingbatsEncoding;
  20891. for (charCode in dingbats) {
  20892. fontChar = DingbatsGlyphsUnicode[dingbats[charCode]];
  20893. if (!fontChar) {
  20894. continue;
  20895. }
  20896. this.toFontChar[charCode] = fontChar;
  20897. }
  20898. for (charCode in properties.differences) {
  20899. fontChar = DingbatsGlyphsUnicode[properties.differences[charCode]];
  20900. if (!fontChar) {
  20901. continue;
  20902. }
  20903. this.toFontChar[charCode] = fontChar;
  20904. }
  20905. } else if (isStandardFont) {
  20906. this.toFontChar = [];
  20907. for (charCode in properties.defaultEncoding) {
  20908. glyphName = (properties.differences[charCode] ||
  20909. properties.defaultEncoding[charCode]);
  20910. this.toFontChar[charCode] = GlyphsUnicode[glyphName];
  20911. }
  20912. } else {
  20913. var unicodeCharCode, notCidFont = (type.indexOf('CIDFontType') === -1);
  20914. this.toUnicode.forEach(function(charCode, unicodeCharCode) {
  20915. if (notCidFont) {
  20916. glyphName = (properties.differences[charCode] ||
  20917. properties.defaultEncoding[charCode]);
  20918. unicodeCharCode = (GlyphsUnicode[glyphName] || unicodeCharCode);
  20919. }
  20920. this.toFontChar[charCode] = unicodeCharCode;
  20921. }.bind(this));
  20922. }
  20923. this.loadedName = fontName.split('-')[0];
  20924. this.loading = false;
  20925. this.fontType = getFontType(type, subtype);
  20926. return;
  20927. }
  20928. // Some fonts might use wrong font types for Type1C or CIDFontType0C
  20929. if (subtype === 'Type1C' && (type !== 'Type1' && type !== 'MMType1')) {
  20930. // Some TrueType fonts by mistake claim Type1C
  20931. if (isTrueTypeFile(file)) {
  20932. subtype = 'TrueType';
  20933. } else {
  20934. type = 'Type1';
  20935. }
  20936. }
  20937. if (subtype === 'CIDFontType0C' && type !== 'CIDFontType0') {
  20938. type = 'CIDFontType0';
  20939. }
  20940. if (subtype === 'OpenType') {
  20941. type = 'OpenType';
  20942. }
  20943. var data;
  20944. switch (type) {
  20945. case 'MMType1':
  20946. info('MMType1 font (' + name + '), falling back to Type1.');
  20947. /* falls through */
  20948. case 'Type1':
  20949. case 'CIDFontType0':
  20950. this.mimetype = 'font/opentype';
  20951. var cff = (subtype === 'Type1C' || subtype === 'CIDFontType0C') ?
  20952. new CFFFont(file, properties) : new Type1Font(name, file, properties);
  20953. adjustWidths(properties);
  20954. // Wrap the CFF data inside an OTF font file
  20955. data = this.convert(name, cff, properties);
  20956. break;
  20957. case 'OpenType':
  20958. case 'TrueType':
  20959. case 'CIDFontType2':
  20960. this.mimetype = 'font/opentype';
  20961. // Repair the TrueType file. It is can be damaged in the point of
  20962. // view of the sanitizer
  20963. data = this.checkAndRepair(name, file, properties);
  20964. if (this.isOpenType) {
  20965. type = 'OpenType';
  20966. }
  20967. break;
  20968. default:
  20969. error('Font ' + type + ' is not supported');
  20970. break;
  20971. }
  20972. this.data = data;
  20973. this.fontType = getFontType(type, subtype);
  20974. // Transfer some properties again that could change during font conversion
  20975. this.fontMatrix = properties.fontMatrix;
  20976. this.widths = properties.widths;
  20977. this.defaultWidth = properties.defaultWidth;
  20978. this.encoding = properties.baseEncoding;
  20979. this.seacMap = properties.seacMap;
  20980. this.loading = true;
  20981. }
  20982. Font.getFontID = (function () {
  20983. var ID = 1;
  20984. return function Font_getFontID() {
  20985. return String(ID++);
  20986. };
  20987. })();
  20988. function int16(b0, b1) {
  20989. return (b0 << 8) + b1;
  20990. }
  20991. function int32(b0, b1, b2, b3) {
  20992. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  20993. }
  20994. function string16(value) {
  20995. return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
  20996. }
  20997. function safeString16(value) {
  20998. // clamp value to the 16-bit int range
  20999. value = (value > 0x7FFF ? 0x7FFF : (value < -0x8000 ? -0x8000 : value));
  21000. return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
  21001. }
  21002. function isTrueTypeFile(file) {
  21003. var header = file.peekBytes(4);
  21004. return readUint32(header, 0) === 0x00010000;
  21005. }
  21006. /**
  21007. * Rebuilds the char code to glyph ID map by trying to replace the char codes
  21008. * with their unicode value. It also moves char codes that are in known
  21009. * problematic locations.
  21010. * @return {Object} Two properties:
  21011. * 'toFontChar' - maps original char codes(the value that will be read
  21012. * from commands such as show text) to the char codes that will be used in the
  21013. * font that we build
  21014. * 'charCodeToGlyphId' - maps the new font char codes to glyph ids
  21015. */
  21016. function adjustMapping(charCodeToGlyphId, properties) {
  21017. var toUnicode = properties.toUnicode;
  21018. var isSymbolic = !!(properties.flags & FontFlags.Symbolic);
  21019. var isIdentityUnicode =
  21020. properties.toUnicode instanceof IdentityToUnicodeMap;
  21021. var newMap = Object.create(null);
  21022. var toFontChar = [];
  21023. var usedFontCharCodes = [];
  21024. var nextAvailableFontCharCode = PRIVATE_USE_OFFSET_START;
  21025. for (var originalCharCode in charCodeToGlyphId) {
  21026. originalCharCode |= 0;
  21027. var glyphId = charCodeToGlyphId[originalCharCode];
  21028. var fontCharCode = originalCharCode;
  21029. // First try to map the value to a unicode position if a non identity map
  21030. // was created.
  21031. if (!isIdentityUnicode && toUnicode.has(originalCharCode)) {
  21032. var unicode = toUnicode.get(fontCharCode);
  21033. // TODO: Try to map ligatures to the correct spot.
  21034. if (unicode.length === 1) {
  21035. fontCharCode = unicode.charCodeAt(0);
  21036. }
  21037. }
  21038. // Try to move control characters, special characters and already mapped
  21039. // characters to the private use area since they will not be drawn by
  21040. // canvas if left in their current position. Also, move characters if the
  21041. // font was symbolic and there is only an identity unicode map since the
  21042. // characters probably aren't in the correct position (fixes an issue
  21043. // with firefox and thuluthfont).
  21044. if ((usedFontCharCodes[fontCharCode] !== undefined ||
  21045. fontCharCode <= 0x1f || // Control chars
  21046. fontCharCode === 0x7F || // Control char
  21047. fontCharCode === 0xAD || // Soft hyphen
  21048. fontCharCode === 0xA0 || // Non breaking space
  21049. fontCharCode === 0x25CC || // Dotted circle (combining mark)
  21050. (fontCharCode >= 0x80 && fontCharCode <= 0x9F) || // Control chars
  21051. // Prevent drawing characters in the specials unicode block.
  21052. (fontCharCode >= 0xFFF0 && fontCharCode <= 0xFFFF) ||
  21053. (isSymbolic && isIdentityUnicode)) &&
  21054. nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END) { // Room left.
  21055. // Loop to try and find a free spot in the private use area.
  21056. do {
  21057. fontCharCode = nextAvailableFontCharCode++;
  21058. if (SKIP_PRIVATE_USE_RANGE_F000_TO_F01F && fontCharCode === 0xF000) {
  21059. fontCharCode = 0xF020;
  21060. nextAvailableFontCharCode = fontCharCode + 1;
  21061. }
  21062. } while (usedFontCharCodes[fontCharCode] !== undefined &&
  21063. nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END);
  21064. }
  21065. newMap[fontCharCode] = glyphId;
  21066. toFontChar[originalCharCode] = fontCharCode;
  21067. usedFontCharCodes[fontCharCode] = true;
  21068. }
  21069. return {
  21070. toFontChar: toFontChar,
  21071. charCodeToGlyphId: newMap,
  21072. nextAvailableFontCharCode: nextAvailableFontCharCode
  21073. };
  21074. }
  21075. function getRanges(glyphs) {
  21076. // Array.sort() sorts by characters, not numerically, so convert to an
  21077. // array of characters.
  21078. var codes = [];
  21079. for (var charCode in glyphs) {
  21080. codes.push({ fontCharCode: charCode | 0, glyphId: glyphs[charCode] });
  21081. }
  21082. codes.sort(function fontGetRangesSort(a, b) {
  21083. return a.fontCharCode - b.fontCharCode;
  21084. });
  21085. // Split the sorted codes into ranges.
  21086. var ranges = [];
  21087. var length = codes.length;
  21088. for (var n = 0; n < length; ) {
  21089. var start = codes[n].fontCharCode;
  21090. var codeIndices = [codes[n].glyphId];
  21091. ++n;
  21092. var end = start;
  21093. while (n < length && end + 1 === codes[n].fontCharCode) {
  21094. codeIndices.push(codes[n].glyphId);
  21095. ++end;
  21096. ++n;
  21097. if (end === 0xFFFF) {
  21098. break;
  21099. }
  21100. }
  21101. ranges.push([start, end, codeIndices]);
  21102. }
  21103. return ranges;
  21104. }
  21105. function createCmapTable(glyphs) {
  21106. var ranges = getRanges(glyphs);
  21107. var numTables = ranges[ranges.length - 1][1] > 0xFFFF ? 2 : 1;
  21108. var cmap = '\x00\x00' + // version
  21109. string16(numTables) + // numTables
  21110. '\x00\x03' + // platformID
  21111. '\x00\x01' + // encodingID
  21112. string32(4 + numTables * 8); // start of the table record
  21113. var i, ii, j, jj;
  21114. for (i = ranges.length - 1; i >= 0; --i) {
  21115. if (ranges[i][0] <= 0xFFFF) { break; }
  21116. }
  21117. var bmpLength = i + 1;
  21118. if (ranges[i][0] < 0xFFFF && ranges[i][1] === 0xFFFF) {
  21119. ranges[i][1] = 0xFFFE;
  21120. }
  21121. var trailingRangesCount = ranges[i][1] < 0xFFFF ? 1 : 0;
  21122. var segCount = bmpLength + trailingRangesCount;
  21123. var searchParams = OpenTypeFileBuilder.getSearchParams(segCount, 2);
  21124. // Fill up the 4 parallel arrays describing the segments.
  21125. var startCount = '';
  21126. var endCount = '';
  21127. var idDeltas = '';
  21128. var idRangeOffsets = '';
  21129. var glyphsIds = '';
  21130. var bias = 0;
  21131. var range, start, end, codes;
  21132. for (i = 0, ii = bmpLength; i < ii; i++) {
  21133. range = ranges[i];
  21134. start = range[0];
  21135. end = range[1];
  21136. startCount += string16(start);
  21137. endCount += string16(end);
  21138. codes = range[2];
  21139. var contiguous = true;
  21140. for (j = 1, jj = codes.length; j < jj; ++j) {
  21141. if (codes[j] !== codes[j - 1] + 1) {
  21142. contiguous = false;
  21143. break;
  21144. }
  21145. }
  21146. if (!contiguous) {
  21147. var offset = (segCount - i) * 2 + bias * 2;
  21148. bias += (end - start + 1);
  21149. idDeltas += string16(0);
  21150. idRangeOffsets += string16(offset);
  21151. for (j = 0, jj = codes.length; j < jj; ++j) {
  21152. glyphsIds += string16(codes[j]);
  21153. }
  21154. } else {
  21155. var startCode = codes[0];
  21156. idDeltas += string16((startCode - start) & 0xFFFF);
  21157. idRangeOffsets += string16(0);
  21158. }
  21159. }
  21160. if (trailingRangesCount > 0) {
  21161. endCount += '\xFF\xFF';
  21162. startCount += '\xFF\xFF';
  21163. idDeltas += '\x00\x01';
  21164. idRangeOffsets += '\x00\x00';
  21165. }
  21166. var format314 = '\x00\x00' + // language
  21167. string16(2 * segCount) +
  21168. string16(searchParams.range) +
  21169. string16(searchParams.entry) +
  21170. string16(searchParams.rangeShift) +
  21171. endCount + '\x00\x00' + startCount +
  21172. idDeltas + idRangeOffsets + glyphsIds;
  21173. var format31012 = '';
  21174. var header31012 = '';
  21175. if (numTables > 1) {
  21176. cmap += '\x00\x03' + // platformID
  21177. '\x00\x0A' + // encodingID
  21178. string32(4 + numTables * 8 +
  21179. 4 + format314.length); // start of the table record
  21180. format31012 = '';
  21181. for (i = 0, ii = ranges.length; i < ii; i++) {
  21182. range = ranges[i];
  21183. start = range[0];
  21184. codes = range[2];
  21185. var code = codes[0];
  21186. for (j = 1, jj = codes.length; j < jj; ++j) {
  21187. if (codes[j] !== codes[j - 1] + 1) {
  21188. end = range[0] + j - 1;
  21189. format31012 += string32(start) + // startCharCode
  21190. string32(end) + // endCharCode
  21191. string32(code); // startGlyphID
  21192. start = end + 1;
  21193. code = codes[j];
  21194. }
  21195. }
  21196. format31012 += string32(start) + // startCharCode
  21197. string32(range[1]) + // endCharCode
  21198. string32(code); // startGlyphID
  21199. }
  21200. header31012 = '\x00\x0C' + // format
  21201. '\x00\x00' + // reserved
  21202. string32(format31012.length + 16) + // length
  21203. '\x00\x00\x00\x00' + // language
  21204. string32(format31012.length / 12); // nGroups
  21205. }
  21206. return cmap + '\x00\x04' + // format
  21207. string16(format314.length + 4) + // length
  21208. format314 + header31012 + format31012;
  21209. }
  21210. function validateOS2Table(os2) {
  21211. var stream = new Stream(os2.data);
  21212. var version = stream.getUint16();
  21213. // TODO verify all OS/2 tables fields, but currently we validate only those
  21214. // that give us issues
  21215. stream.getBytes(60); // skipping type, misc sizes, panose, unicode ranges
  21216. var selection = stream.getUint16();
  21217. if (version < 4 && (selection & 0x0300)) {
  21218. return false;
  21219. }
  21220. var firstChar = stream.getUint16();
  21221. var lastChar = stream.getUint16();
  21222. if (firstChar > lastChar) {
  21223. return false;
  21224. }
  21225. stream.getBytes(6); // skipping sTypoAscender/Descender/LineGap
  21226. var usWinAscent = stream.getUint16();
  21227. if (usWinAscent === 0) { // makes font unreadable by windows
  21228. return false;
  21229. }
  21230. // OS/2 appears to be valid, resetting some fields
  21231. os2.data[8] = os2.data[9] = 0; // IE rejects fonts if fsType != 0
  21232. return true;
  21233. }
  21234. function createOS2Table(properties, charstrings, override) {
  21235. override = override || {
  21236. unitsPerEm: 0,
  21237. yMax: 0,
  21238. yMin: 0,
  21239. ascent: 0,
  21240. descent: 0
  21241. };
  21242. var ulUnicodeRange1 = 0;
  21243. var ulUnicodeRange2 = 0;
  21244. var ulUnicodeRange3 = 0;
  21245. var ulUnicodeRange4 = 0;
  21246. var firstCharIndex = null;
  21247. var lastCharIndex = 0;
  21248. if (charstrings) {
  21249. for (var code in charstrings) {
  21250. code |= 0;
  21251. if (firstCharIndex > code || !firstCharIndex) {
  21252. firstCharIndex = code;
  21253. }
  21254. if (lastCharIndex < code) {
  21255. lastCharIndex = code;
  21256. }
  21257. var position = getUnicodeRangeFor(code);
  21258. if (position < 32) {
  21259. ulUnicodeRange1 |= 1 << position;
  21260. } else if (position < 64) {
  21261. ulUnicodeRange2 |= 1 << position - 32;
  21262. } else if (position < 96) {
  21263. ulUnicodeRange3 |= 1 << position - 64;
  21264. } else if (position < 123) {
  21265. ulUnicodeRange4 |= 1 << position - 96;
  21266. } else {
  21267. error('Unicode ranges Bits > 123 are reserved for internal usage');
  21268. }
  21269. }
  21270. } else {
  21271. // TODO
  21272. firstCharIndex = 0;
  21273. lastCharIndex = 255;
  21274. }
  21275. var bbox = properties.bbox || [0, 0, 0, 0];
  21276. var unitsPerEm = (override.unitsPerEm ||
  21277. 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0]);
  21278. // if the font units differ to the PDF glyph space units
  21279. // then scale up the values
  21280. var scale = (properties.ascentScaled ? 1.0 :
  21281. unitsPerEm / PDF_GLYPH_SPACE_UNITS);
  21282. var typoAscent = (override.ascent ||
  21283. Math.round(scale * (properties.ascent || bbox[3])));
  21284. var typoDescent = (override.descent ||
  21285. Math.round(scale * (properties.descent || bbox[1])));
  21286. if (typoDescent > 0 && properties.descent > 0 && bbox[1] < 0) {
  21287. typoDescent = -typoDescent; // fixing incorrect descent
  21288. }
  21289. var winAscent = override.yMax || typoAscent;
  21290. var winDescent = -override.yMin || -typoDescent;
  21291. return '\x00\x03' + // version
  21292. '\x02\x24' + // xAvgCharWidth
  21293. '\x01\xF4' + // usWeightClass
  21294. '\x00\x05' + // usWidthClass
  21295. '\x00\x00' + // fstype (0 to let the font loads via font-face on IE)
  21296. '\x02\x8A' + // ySubscriptXSize
  21297. '\x02\xBB' + // ySubscriptYSize
  21298. '\x00\x00' + // ySubscriptXOffset
  21299. '\x00\x8C' + // ySubscriptYOffset
  21300. '\x02\x8A' + // ySuperScriptXSize
  21301. '\x02\xBB' + // ySuperScriptYSize
  21302. '\x00\x00' + // ySuperScriptXOffset
  21303. '\x01\xDF' + // ySuperScriptYOffset
  21304. '\x00\x31' + // yStrikeOutSize
  21305. '\x01\x02' + // yStrikeOutPosition
  21306. '\x00\x00' + // sFamilyClass
  21307. '\x00\x00\x06' +
  21308. String.fromCharCode(properties.fixedPitch ? 0x09 : 0x00) +
  21309. '\x00\x00\x00\x00\x00\x00' + // Panose
  21310. string32(ulUnicodeRange1) + // ulUnicodeRange1 (Bits 0-31)
  21311. string32(ulUnicodeRange2) + // ulUnicodeRange2 (Bits 32-63)
  21312. string32(ulUnicodeRange3) + // ulUnicodeRange3 (Bits 64-95)
  21313. string32(ulUnicodeRange4) + // ulUnicodeRange4 (Bits 96-127)
  21314. '\x2A\x32\x31\x2A' + // achVendID
  21315. string16(properties.italicAngle ? 1 : 0) + // fsSelection
  21316. string16(firstCharIndex ||
  21317. properties.firstChar) + // usFirstCharIndex
  21318. string16(lastCharIndex || properties.lastChar) + // usLastCharIndex
  21319. string16(typoAscent) + // sTypoAscender
  21320. string16(typoDescent) + // sTypoDescender
  21321. '\x00\x64' + // sTypoLineGap (7%-10% of the unitsPerEM value)
  21322. string16(winAscent) + // usWinAscent
  21323. string16(winDescent) + // usWinDescent
  21324. '\x00\x00\x00\x00' + // ulCodePageRange1 (Bits 0-31)
  21325. '\x00\x00\x00\x00' + // ulCodePageRange2 (Bits 32-63)
  21326. string16(properties.xHeight) + // sxHeight
  21327. string16(properties.capHeight) + // sCapHeight
  21328. string16(0) + // usDefaultChar
  21329. string16(firstCharIndex || properties.firstChar) + // usBreakChar
  21330. '\x00\x03'; // usMaxContext
  21331. }
  21332. function createPostTable(properties) {
  21333. var angle = Math.floor(properties.italicAngle * (Math.pow(2, 16)));
  21334. return ('\x00\x03\x00\x00' + // Version number
  21335. string32(angle) + // italicAngle
  21336. '\x00\x00' + // underlinePosition
  21337. '\x00\x00' + // underlineThickness
  21338. string32(properties.fixedPitch) + // isFixedPitch
  21339. '\x00\x00\x00\x00' + // minMemType42
  21340. '\x00\x00\x00\x00' + // maxMemType42
  21341. '\x00\x00\x00\x00' + // minMemType1
  21342. '\x00\x00\x00\x00'); // maxMemType1
  21343. }
  21344. function createNameTable(name, proto) {
  21345. if (!proto) {
  21346. proto = [[], []]; // no strings and unicode strings
  21347. }
  21348. var strings = [
  21349. proto[0][0] || 'Original licence', // 0.Copyright
  21350. proto[0][1] || name, // 1.Font family
  21351. proto[0][2] || 'Unknown', // 2.Font subfamily (font weight)
  21352. proto[0][3] || 'uniqueID', // 3.Unique ID
  21353. proto[0][4] || name, // 4.Full font name
  21354. proto[0][5] || 'Version 0.11', // 5.Version
  21355. proto[0][6] || '', // 6.Postscript name
  21356. proto[0][7] || 'Unknown', // 7.Trademark
  21357. proto[0][8] || 'Unknown', // 8.Manufacturer
  21358. proto[0][9] || 'Unknown' // 9.Designer
  21359. ];
  21360. // Mac want 1-byte per character strings while Windows want
  21361. // 2-bytes per character, so duplicate the names table
  21362. var stringsUnicode = [];
  21363. var i, ii, j, jj, str;
  21364. for (i = 0, ii = strings.length; i < ii; i++) {
  21365. str = proto[1][i] || strings[i];
  21366. var strBufUnicode = [];
  21367. for (j = 0, jj = str.length; j < jj; j++) {
  21368. strBufUnicode.push(string16(str.charCodeAt(j)));
  21369. }
  21370. stringsUnicode.push(strBufUnicode.join(''));
  21371. }
  21372. var names = [strings, stringsUnicode];
  21373. var platforms = ['\x00\x01', '\x00\x03'];
  21374. var encodings = ['\x00\x00', '\x00\x01'];
  21375. var languages = ['\x00\x00', '\x04\x09'];
  21376. var namesRecordCount = strings.length * platforms.length;
  21377. var nameTable =
  21378. '\x00\x00' + // format
  21379. string16(namesRecordCount) + // Number of names Record
  21380. string16(namesRecordCount * 12 + 6); // Storage
  21381. // Build the name records field
  21382. var strOffset = 0;
  21383. for (i = 0, ii = platforms.length; i < ii; i++) {
  21384. var strs = names[i];
  21385. for (j = 0, jj = strs.length; j < jj; j++) {
  21386. str = strs[j];
  21387. var nameRecord =
  21388. platforms[i] + // platform ID
  21389. encodings[i] + // encoding ID
  21390. languages[i] + // language ID
  21391. string16(j) + // name ID
  21392. string16(str.length) +
  21393. string16(strOffset);
  21394. nameTable += nameRecord;
  21395. strOffset += str.length;
  21396. }
  21397. }
  21398. nameTable += strings.join('') + stringsUnicode.join('');
  21399. return nameTable;
  21400. }
  21401. Font.prototype = {
  21402. name: null,
  21403. font: null,
  21404. mimetype: null,
  21405. encoding: null,
  21406. get renderer() {
  21407. var renderer = FontRendererFactory.create(this);
  21408. return shadow(this, 'renderer', renderer);
  21409. },
  21410. exportData: function Font_exportData() {
  21411. var data = {};
  21412. for (var i in this) {
  21413. if (this.hasOwnProperty(i)) {
  21414. data[i] = this[i];
  21415. }
  21416. }
  21417. return data;
  21418. },
  21419. checkAndRepair: function Font_checkAndRepair(name, font, properties) {
  21420. function readTableEntry(file) {
  21421. var tag = bytesToString(file.getBytes(4));
  21422. var checksum = file.getInt32();
  21423. var offset = file.getInt32() >>> 0;
  21424. var length = file.getInt32() >>> 0;
  21425. // Read the table associated data
  21426. var previousPosition = file.pos;
  21427. file.pos = file.start ? file.start : 0;
  21428. file.skip(offset);
  21429. var data = file.getBytes(length);
  21430. file.pos = previousPosition;
  21431. if (tag === 'head') {
  21432. // clearing checksum adjustment
  21433. data[8] = data[9] = data[10] = data[11] = 0;
  21434. data[17] |= 0x20; //Set font optimized for cleartype flag
  21435. }
  21436. return {
  21437. tag: tag,
  21438. checksum: checksum,
  21439. length: length,
  21440. offset: offset,
  21441. data: data
  21442. };
  21443. }
  21444. function readOpenTypeHeader(ttf) {
  21445. return {
  21446. version: bytesToString(ttf.getBytes(4)),
  21447. numTables: ttf.getUint16(),
  21448. searchRange: ttf.getUint16(),
  21449. entrySelector: ttf.getUint16(),
  21450. rangeShift: ttf.getUint16()
  21451. };
  21452. }
  21453. /**
  21454. * Read the appropriate subtable from the cmap according to 9.6.6.4 from
  21455. * PDF spec
  21456. */
  21457. function readCmapTable(cmap, font, isSymbolicFont) {
  21458. var segment;
  21459. var start = (font.start ? font.start : 0) + cmap.offset;
  21460. font.pos = start;
  21461. var version = font.getUint16();
  21462. var numTables = font.getUint16();
  21463. var potentialTable;
  21464. var canBreak = false;
  21465. // There's an order of preference in terms of which cmap subtable to
  21466. // use:
  21467. // - non-symbolic fonts the preference is a 3,1 table then a 1,0 table
  21468. // - symbolic fonts the preference is a 3,0 table then a 1,0 table
  21469. // The following takes advantage of the fact that the tables are sorted
  21470. // to work.
  21471. for (var i = 0; i < numTables; i++) {
  21472. var platformId = font.getUint16();
  21473. var encodingId = font.getUint16();
  21474. var offset = font.getInt32() >>> 0;
  21475. var useTable = false;
  21476. if (platformId === 0 && encodingId === 0) {
  21477. useTable = true;
  21478. // Continue the loop since there still may be a higher priority
  21479. // table.
  21480. } else if (platformId === 1 && encodingId === 0) {
  21481. useTable = true;
  21482. // Continue the loop since there still may be a higher priority
  21483. // table.
  21484. } else if (platformId === 3 && encodingId === 1 &&
  21485. (!isSymbolicFont || !potentialTable)) {
  21486. useTable = true;
  21487. if (!isSymbolicFont) {
  21488. canBreak = true;
  21489. }
  21490. } else if (isSymbolicFont && platformId === 3 && encodingId === 0) {
  21491. useTable = true;
  21492. canBreak = true;
  21493. }
  21494. if (useTable) {
  21495. potentialTable = {
  21496. platformId: platformId,
  21497. encodingId: encodingId,
  21498. offset: offset
  21499. };
  21500. }
  21501. if (canBreak) {
  21502. break;
  21503. }
  21504. }
  21505. if (!potentialTable) {
  21506. warn('Could not find a preferred cmap table.');
  21507. return {
  21508. platformId: -1,
  21509. encodingId: -1,
  21510. mappings: [],
  21511. hasShortCmap: false
  21512. };
  21513. }
  21514. font.pos = start + potentialTable.offset;
  21515. var format = font.getUint16();
  21516. var length = font.getUint16();
  21517. var language = font.getUint16();
  21518. var hasShortCmap = false;
  21519. var mappings = [];
  21520. var j, glyphId;
  21521. // TODO(mack): refactor this cmap subtable reading logic out
  21522. if (format === 0) {
  21523. for (j = 0; j < 256; j++) {
  21524. var index = font.getByte();
  21525. if (!index) {
  21526. continue;
  21527. }
  21528. mappings.push({
  21529. charCode: j,
  21530. glyphId: index
  21531. });
  21532. }
  21533. hasShortCmap = true;
  21534. } else if (format === 4) {
  21535. // re-creating the table in format 4 since the encoding
  21536. // might be changed
  21537. var segCount = (font.getUint16() >> 1);
  21538. font.getBytes(6); // skipping range fields
  21539. var segIndex, segments = [];
  21540. for (segIndex = 0; segIndex < segCount; segIndex++) {
  21541. segments.push({ end: font.getUint16() });
  21542. }
  21543. font.getUint16();
  21544. for (segIndex = 0; segIndex < segCount; segIndex++) {
  21545. segments[segIndex].start = font.getUint16();
  21546. }
  21547. for (segIndex = 0; segIndex < segCount; segIndex++) {
  21548. segments[segIndex].delta = font.getUint16();
  21549. }
  21550. var offsetsCount = 0;
  21551. for (segIndex = 0; segIndex < segCount; segIndex++) {
  21552. segment = segments[segIndex];
  21553. var rangeOffset = font.getUint16();
  21554. if (!rangeOffset) {
  21555. segment.offsetIndex = -1;
  21556. continue;
  21557. }
  21558. var offsetIndex = (rangeOffset >> 1) - (segCount - segIndex);
  21559. segment.offsetIndex = offsetIndex;
  21560. offsetsCount = Math.max(offsetsCount, offsetIndex +
  21561. segment.end - segment.start + 1);
  21562. }
  21563. var offsets = [];
  21564. for (j = 0; j < offsetsCount; j++) {
  21565. offsets.push(font.getUint16());
  21566. }
  21567. for (segIndex = 0; segIndex < segCount; segIndex++) {
  21568. segment = segments[segIndex];
  21569. start = segment.start;
  21570. var end = segment.end;
  21571. var delta = segment.delta;
  21572. offsetIndex = segment.offsetIndex;
  21573. for (j = start; j <= end; j++) {
  21574. if (j === 0xFFFF) {
  21575. continue;
  21576. }
  21577. glyphId = (offsetIndex < 0 ?
  21578. j : offsets[offsetIndex + j - start]);
  21579. glyphId = (glyphId + delta) & 0xFFFF;
  21580. if (glyphId === 0) {
  21581. continue;
  21582. }
  21583. mappings.push({
  21584. charCode: j,
  21585. glyphId: glyphId
  21586. });
  21587. }
  21588. }
  21589. } else if (format === 6) {
  21590. // Format 6 is a 2-bytes dense mapping, which means the font data
  21591. // lives glue together even if they are pretty far in the unicode
  21592. // table. (This looks weird, so I can have missed something), this
  21593. // works on Linux but seems to fails on Mac so let's rewrite the
  21594. // cmap table to a 3-1-4 style
  21595. var firstCode = font.getUint16();
  21596. var entryCount = font.getUint16();
  21597. for (j = 0; j < entryCount; j++) {
  21598. glyphId = font.getUint16();
  21599. var charCode = firstCode + j;
  21600. mappings.push({
  21601. charCode: charCode,
  21602. glyphId: glyphId
  21603. });
  21604. }
  21605. } else {
  21606. error('cmap table has unsupported format: ' + format);
  21607. }
  21608. // removing duplicate entries
  21609. mappings.sort(function (a, b) {
  21610. return a.charCode - b.charCode;
  21611. });
  21612. for (i = 1; i < mappings.length; i++) {
  21613. if (mappings[i - 1].charCode === mappings[i].charCode) {
  21614. mappings.splice(i, 1);
  21615. i--;
  21616. }
  21617. }
  21618. return {
  21619. platformId: potentialTable.platformId,
  21620. encodingId: potentialTable.encodingId,
  21621. mappings: mappings,
  21622. hasShortCmap: hasShortCmap
  21623. };
  21624. }
  21625. function sanitizeMetrics(font, header, metrics, numGlyphs) {
  21626. if (!header) {
  21627. if (metrics) {
  21628. metrics.data = null;
  21629. }
  21630. return;
  21631. }
  21632. font.pos = (font.start ? font.start : 0) + header.offset;
  21633. font.pos += header.length - 2;
  21634. var numOfMetrics = font.getUint16();
  21635. if (numOfMetrics > numGlyphs) {
  21636. info('The numOfMetrics (' + numOfMetrics + ') should not be ' +
  21637. 'greater than the numGlyphs (' + numGlyphs + ')');
  21638. // Reduce numOfMetrics if it is greater than numGlyphs
  21639. numOfMetrics = numGlyphs;
  21640. header.data[34] = (numOfMetrics & 0xff00) >> 8;
  21641. header.data[35] = numOfMetrics & 0x00ff;
  21642. }
  21643. var numOfSidebearings = numGlyphs - numOfMetrics;
  21644. var numMissing = numOfSidebearings -
  21645. ((metrics.length - numOfMetrics * 4) >> 1);
  21646. if (numMissing > 0) {
  21647. // For each missing glyph, we set both the width and lsb to 0 (zero).
  21648. // Since we need to add two properties for each glyph, this explains
  21649. // the use of |numMissing * 2| when initializing the typed array.
  21650. var entries = new Uint8Array(metrics.length + numMissing * 2);
  21651. entries.set(metrics.data);
  21652. metrics.data = entries;
  21653. }
  21654. }
  21655. function sanitizeGlyph(source, sourceStart, sourceEnd, dest, destStart,
  21656. hintsValid) {
  21657. if (sourceEnd - sourceStart <= 12) {
  21658. // glyph with data less than 12 is invalid one
  21659. return 0;
  21660. }
  21661. var glyf = source.subarray(sourceStart, sourceEnd);
  21662. var contoursCount = (glyf[0] << 8) | glyf[1];
  21663. if (contoursCount & 0x8000) {
  21664. // complex glyph, writing as is
  21665. dest.set(glyf, destStart);
  21666. return glyf.length;
  21667. }
  21668. var i, j = 10, flagsCount = 0;
  21669. for (i = 0; i < contoursCount; i++) {
  21670. var endPoint = (glyf[j] << 8) | glyf[j + 1];
  21671. flagsCount = endPoint + 1;
  21672. j += 2;
  21673. }
  21674. // skipping instructions
  21675. var instructionsStart = j;
  21676. var instructionsLength = (glyf[j] << 8) | glyf[j + 1];
  21677. j += 2 + instructionsLength;
  21678. var instructionsEnd = j;
  21679. // validating flags
  21680. var coordinatesLength = 0;
  21681. for (i = 0; i < flagsCount; i++) {
  21682. var flag = glyf[j++];
  21683. if (flag & 0xC0) {
  21684. // reserved flags must be zero, cleaning up
  21685. glyf[j - 1] = flag & 0x3F;
  21686. }
  21687. var xyLength = ((flag & 2) ? 1 : (flag & 16) ? 0 : 2) +
  21688. ((flag & 4) ? 1 : (flag & 32) ? 0 : 2);
  21689. coordinatesLength += xyLength;
  21690. if (flag & 8) {
  21691. var repeat = glyf[j++];
  21692. i += repeat;
  21693. coordinatesLength += repeat * xyLength;
  21694. }
  21695. }
  21696. // glyph without coordinates will be rejected
  21697. if (coordinatesLength === 0) {
  21698. return 0;
  21699. }
  21700. var glyphDataLength = j + coordinatesLength;
  21701. if (glyphDataLength > glyf.length) {
  21702. // not enough data for coordinates
  21703. return 0;
  21704. }
  21705. if (!hintsValid && instructionsLength > 0) {
  21706. dest.set(glyf.subarray(0, instructionsStart), destStart);
  21707. dest.set([0, 0], destStart + instructionsStart);
  21708. dest.set(glyf.subarray(instructionsEnd, glyphDataLength),
  21709. destStart + instructionsStart + 2);
  21710. glyphDataLength -= instructionsLength;
  21711. if (glyf.length - glyphDataLength > 3) {
  21712. glyphDataLength = (glyphDataLength + 3) & ~3;
  21713. }
  21714. return glyphDataLength;
  21715. }
  21716. if (glyf.length - glyphDataLength > 3) {
  21717. // truncating and aligning to 4 bytes the long glyph data
  21718. glyphDataLength = (glyphDataLength + 3) & ~3;
  21719. dest.set(glyf.subarray(0, glyphDataLength), destStart);
  21720. return glyphDataLength;
  21721. }
  21722. // glyph data is fine
  21723. dest.set(glyf, destStart);
  21724. return glyf.length;
  21725. }
  21726. function sanitizeHead(head, numGlyphs, locaLength) {
  21727. var data = head.data;
  21728. // Validate version:
  21729. // Should always be 0x00010000
  21730. var version = int32(data[0], data[1], data[2], data[3]);
  21731. if (version >> 16 !== 1) {
  21732. info('Attempting to fix invalid version in head table: ' + version);
  21733. data[0] = 0;
  21734. data[1] = 1;
  21735. data[2] = 0;
  21736. data[3] = 0;
  21737. }
  21738. var indexToLocFormat = int16(data[50], data[51]);
  21739. if (indexToLocFormat < 0 || indexToLocFormat > 1) {
  21740. info('Attempting to fix invalid indexToLocFormat in head table: ' +
  21741. indexToLocFormat);
  21742. // The value of indexToLocFormat should be 0 if the loca table
  21743. // consists of short offsets, and should be 1 if the loca table
  21744. // consists of long offsets.
  21745. //
  21746. // The number of entries in the loca table should be numGlyphs + 1.
  21747. //
  21748. // Using this information, we can work backwards to deduce if the
  21749. // size of each offset in the loca table, and thus figure out the
  21750. // appropriate value for indexToLocFormat.
  21751. var numGlyphsPlusOne = numGlyphs + 1;
  21752. if (locaLength === numGlyphsPlusOne << 1) {
  21753. // 0x0000 indicates the loca table consists of short offsets
  21754. data[50] = 0;
  21755. data[51] = 0;
  21756. } else if (locaLength === numGlyphsPlusOne << 2) {
  21757. // 0x0001 indicates the loca table consists of long offsets
  21758. data[50] = 0;
  21759. data[51] = 1;
  21760. } else {
  21761. warn('Could not fix indexToLocFormat: ' + indexToLocFormat);
  21762. }
  21763. }
  21764. }
  21765. function sanitizeGlyphLocations(loca, glyf, numGlyphs,
  21766. isGlyphLocationsLong, hintsValid,
  21767. dupFirstEntry) {
  21768. var itemSize, itemDecode, itemEncode;
  21769. if (isGlyphLocationsLong) {
  21770. itemSize = 4;
  21771. itemDecode = function fontItemDecodeLong(data, offset) {
  21772. return (data[offset] << 24) | (data[offset + 1] << 16) |
  21773. (data[offset + 2] << 8) | data[offset + 3];
  21774. };
  21775. itemEncode = function fontItemEncodeLong(data, offset, value) {
  21776. data[offset] = (value >>> 24) & 0xFF;
  21777. data[offset + 1] = (value >> 16) & 0xFF;
  21778. data[offset + 2] = (value >> 8) & 0xFF;
  21779. data[offset + 3] = value & 0xFF;
  21780. };
  21781. } else {
  21782. itemSize = 2;
  21783. itemDecode = function fontItemDecode(data, offset) {
  21784. return (data[offset] << 9) | (data[offset + 1] << 1);
  21785. };
  21786. itemEncode = function fontItemEncode(data, offset, value) {
  21787. data[offset] = (value >> 9) & 0xFF;
  21788. data[offset + 1] = (value >> 1) & 0xFF;
  21789. };
  21790. }
  21791. var locaData = loca.data;
  21792. var locaDataSize = itemSize * (1 + numGlyphs);
  21793. // is loca.data too short or long?
  21794. if (locaData.length !== locaDataSize) {
  21795. locaData = new Uint8Array(locaDataSize);
  21796. locaData.set(loca.data.subarray(0, locaDataSize));
  21797. loca.data = locaData;
  21798. }
  21799. // removing the invalid glyphs
  21800. var oldGlyfData = glyf.data;
  21801. var oldGlyfDataLength = oldGlyfData.length;
  21802. var newGlyfData = new Uint8Array(oldGlyfDataLength);
  21803. var startOffset = itemDecode(locaData, 0);
  21804. var writeOffset = 0;
  21805. var missingGlyphData = {};
  21806. itemEncode(locaData, 0, writeOffset);
  21807. var i, j;
  21808. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  21809. var endOffset = itemDecode(locaData, j);
  21810. if (endOffset > oldGlyfDataLength &&
  21811. ((oldGlyfDataLength + 3) & ~3) === endOffset) {
  21812. // Aspose breaks fonts by aligning the glyphs to the qword, but not
  21813. // the glyf table size, which makes last glyph out of range.
  21814. endOffset = oldGlyfDataLength;
  21815. }
  21816. if (endOffset > oldGlyfDataLength) {
  21817. // glyph end offset points outside glyf data, rejecting the glyph
  21818. itemEncode(locaData, j, writeOffset);
  21819. startOffset = endOffset;
  21820. continue;
  21821. }
  21822. if (startOffset === endOffset) {
  21823. missingGlyphData[i] = true;
  21824. }
  21825. var newLength = sanitizeGlyph(oldGlyfData, startOffset, endOffset,
  21826. newGlyfData, writeOffset, hintsValid);
  21827. writeOffset += newLength;
  21828. itemEncode(locaData, j, writeOffset);
  21829. startOffset = endOffset;
  21830. }
  21831. if (writeOffset === 0) {
  21832. // glyf table cannot be empty -- redoing the glyf and loca tables
  21833. // to have single glyph with one point
  21834. var simpleGlyph = new Uint8Array(
  21835. [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 49, 0]);
  21836. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  21837. itemEncode(locaData, j, simpleGlyph.length);
  21838. }
  21839. glyf.data = simpleGlyph;
  21840. return missingGlyphData;
  21841. }
  21842. if (dupFirstEntry) {
  21843. var firstEntryLength = itemDecode(locaData, itemSize);
  21844. if (newGlyfData.length > firstEntryLength + writeOffset) {
  21845. glyf.data = newGlyfData.subarray(0, firstEntryLength + writeOffset);
  21846. } else {
  21847. glyf.data = new Uint8Array(firstEntryLength + writeOffset);
  21848. glyf.data.set(newGlyfData.subarray(0, writeOffset));
  21849. }
  21850. glyf.data.set(newGlyfData.subarray(0, firstEntryLength), writeOffset);
  21851. itemEncode(loca.data, locaData.length - itemSize,
  21852. writeOffset + firstEntryLength);
  21853. } else {
  21854. glyf.data = newGlyfData.subarray(0, writeOffset);
  21855. }
  21856. return missingGlyphData;
  21857. }
  21858. function readPostScriptTable(post, properties, maxpNumGlyphs) {
  21859. var start = (font.start ? font.start : 0) + post.offset;
  21860. font.pos = start;
  21861. var length = post.length, end = start + length;
  21862. var version = font.getInt32();
  21863. // skip rest to the tables
  21864. font.getBytes(28);
  21865. var glyphNames;
  21866. var valid = true;
  21867. var i;
  21868. switch (version) {
  21869. case 0x00010000:
  21870. glyphNames = MacStandardGlyphOrdering;
  21871. break;
  21872. case 0x00020000:
  21873. var numGlyphs = font.getUint16();
  21874. if (numGlyphs !== maxpNumGlyphs) {
  21875. valid = false;
  21876. break;
  21877. }
  21878. var glyphNameIndexes = [];
  21879. for (i = 0; i < numGlyphs; ++i) {
  21880. var index = font.getUint16();
  21881. if (index >= 32768) {
  21882. valid = false;
  21883. break;
  21884. }
  21885. glyphNameIndexes.push(index);
  21886. }
  21887. if (!valid) {
  21888. break;
  21889. }
  21890. var customNames = [];
  21891. var strBuf = [];
  21892. while (font.pos < end) {
  21893. var stringLength = font.getByte();
  21894. strBuf.length = stringLength;
  21895. for (i = 0; i < stringLength; ++i) {
  21896. strBuf[i] = String.fromCharCode(font.getByte());
  21897. }
  21898. customNames.push(strBuf.join(''));
  21899. }
  21900. glyphNames = [];
  21901. for (i = 0; i < numGlyphs; ++i) {
  21902. var j = glyphNameIndexes[i];
  21903. if (j < 258) {
  21904. glyphNames.push(MacStandardGlyphOrdering[j]);
  21905. continue;
  21906. }
  21907. glyphNames.push(customNames[j - 258]);
  21908. }
  21909. break;
  21910. case 0x00030000:
  21911. break;
  21912. default:
  21913. warn('Unknown/unsupported post table version ' + version);
  21914. valid = false;
  21915. break;
  21916. }
  21917. properties.glyphNames = glyphNames;
  21918. return valid;
  21919. }
  21920. function readNameTable(nameTable) {
  21921. var start = (font.start ? font.start : 0) + nameTable.offset;
  21922. font.pos = start;
  21923. var names = [[], []];
  21924. var length = nameTable.length, end = start + length;
  21925. var format = font.getUint16();
  21926. var FORMAT_0_HEADER_LENGTH = 6;
  21927. if (format !== 0 || length < FORMAT_0_HEADER_LENGTH) {
  21928. // unsupported name table format or table "too" small
  21929. return names;
  21930. }
  21931. var numRecords = font.getUint16();
  21932. var stringsStart = font.getUint16();
  21933. var records = [];
  21934. var NAME_RECORD_LENGTH = 12;
  21935. var i, ii;
  21936. for (i = 0; i < numRecords &&
  21937. font.pos + NAME_RECORD_LENGTH <= end; i++) {
  21938. var r = {
  21939. platform: font.getUint16(),
  21940. encoding: font.getUint16(),
  21941. language: font.getUint16(),
  21942. name: font.getUint16(),
  21943. length: font.getUint16(),
  21944. offset: font.getUint16()
  21945. };
  21946. // using only Macintosh and Windows platform/encoding names
  21947. if ((r.platform === 1 && r.encoding === 0 && r.language === 0) ||
  21948. (r.platform === 3 && r.encoding === 1 && r.language === 0x409)) {
  21949. records.push(r);
  21950. }
  21951. }
  21952. for (i = 0, ii = records.length; i < ii; i++) {
  21953. var record = records[i];
  21954. var pos = start + stringsStart + record.offset;
  21955. if (pos + record.length > end) {
  21956. continue; // outside of name table, ignoring
  21957. }
  21958. font.pos = pos;
  21959. var nameIndex = record.name;
  21960. if (record.encoding) {
  21961. // unicode
  21962. var str = '';
  21963. for (var j = 0, jj = record.length; j < jj; j += 2) {
  21964. str += String.fromCharCode(font.getUint16());
  21965. }
  21966. names[1][nameIndex] = str;
  21967. } else {
  21968. names[0][nameIndex] = bytesToString(font.getBytes(record.length));
  21969. }
  21970. }
  21971. return names;
  21972. }
  21973. var TTOpsStackDeltas = [
  21974. 0, 0, 0, 0, 0, 0, 0, 0, -2, -2, -2, -2, 0, 0, -2, -5,
  21975. -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, -1, -1,
  21976. 1, -1, -999, 0, 1, 0, -1, -2, 0, -1, -2, -1, -1, 0, -1, -1,
  21977. 0, 0, -999, -999, -1, -1, -1, -1, -2, -999, -2, -2, -999, 0, -2, -2,
  21978. 0, 0, -2, 0, -2, 0, 0, 0, -2, -1, -1, 1, 1, 0, 0, -1,
  21979. -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, 0, -999, -1, -1,
  21980. -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  21981. -2, -999, -999, -999, -999, -999, -1, -1, -2, -2, 0, 0, 0, 0, -1, -1,
  21982. -999, -2, -2, 0, 0, -1, -2, -2, 0, 0, 0, -1, -1, -1, -2];
  21983. // 0xC0-DF == -1 and 0xE0-FF == -2
  21984. function sanitizeTTProgram(table, ttContext) {
  21985. var data = table.data;
  21986. var i = 0, j, n, b, funcId, pc, lastEndf = 0, lastDeff = 0;
  21987. var stack = [];
  21988. var callstack = [];
  21989. var functionsCalled = [];
  21990. var tooComplexToFollowFunctions =
  21991. ttContext.tooComplexToFollowFunctions;
  21992. var inFDEF = false, ifLevel = 0, inELSE = 0;
  21993. for (var ii = data.length; i < ii;) {
  21994. var op = data[i++];
  21995. // The TrueType instruction set docs can be found at
  21996. // https://developer.apple.com/fonts/TTRefMan/RM05/Chap5.html
  21997. if (op === 0x40) { // NPUSHB - pushes n bytes
  21998. n = data[i++];
  21999. if (inFDEF || inELSE) {
  22000. i += n;
  22001. } else {
  22002. for (j = 0; j < n; j++) {
  22003. stack.push(data[i++]);
  22004. }
  22005. }
  22006. } else if (op === 0x41) { // NPUSHW - pushes n words
  22007. n = data[i++];
  22008. if (inFDEF || inELSE) {
  22009. i += n * 2;
  22010. } else {
  22011. for (j = 0; j < n; j++) {
  22012. b = data[i++];
  22013. stack.push((b << 8) | data[i++]);
  22014. }
  22015. }
  22016. } else if ((op & 0xF8) === 0xB0) { // PUSHB - pushes bytes
  22017. n = op - 0xB0 + 1;
  22018. if (inFDEF || inELSE) {
  22019. i += n;
  22020. } else {
  22021. for (j = 0; j < n; j++) {
  22022. stack.push(data[i++]);
  22023. }
  22024. }
  22025. } else if ((op & 0xF8) === 0xB8) { // PUSHW - pushes words
  22026. n = op - 0xB8 + 1;
  22027. if (inFDEF || inELSE) {
  22028. i += n * 2;
  22029. } else {
  22030. for (j = 0; j < n; j++) {
  22031. b = data[i++];
  22032. stack.push((b << 8) | data[i++]);
  22033. }
  22034. }
  22035. } else if (op === 0x2B && !tooComplexToFollowFunctions) { // CALL
  22036. if (!inFDEF && !inELSE) {
  22037. // collecting inforamtion about which functions are used
  22038. funcId = stack[stack.length - 1];
  22039. ttContext.functionsUsed[funcId] = true;
  22040. if (funcId in ttContext.functionsStackDeltas) {
  22041. stack.length += ttContext.functionsStackDeltas[funcId];
  22042. } else if (funcId in ttContext.functionsDefined &&
  22043. functionsCalled.indexOf(funcId) < 0) {
  22044. callstack.push({data: data, i: i, stackTop: stack.length - 1});
  22045. functionsCalled.push(funcId);
  22046. pc = ttContext.functionsDefined[funcId];
  22047. if (!pc) {
  22048. warn('TT: CALL non-existent function');
  22049. ttContext.hintsValid = false;
  22050. return;
  22051. }
  22052. data = pc.data;
  22053. i = pc.i;
  22054. }
  22055. }
  22056. } else if (op === 0x2C && !tooComplexToFollowFunctions) { // FDEF
  22057. if (inFDEF || inELSE) {
  22058. warn('TT: nested FDEFs not allowed');
  22059. tooComplexToFollowFunctions = true;
  22060. }
  22061. inFDEF = true;
  22062. // collecting inforamtion about which functions are defined
  22063. lastDeff = i;
  22064. funcId = stack.pop();
  22065. ttContext.functionsDefined[funcId] = {data: data, i: i};
  22066. } else if (op === 0x2D) { // ENDF - end of function
  22067. if (inFDEF) {
  22068. inFDEF = false;
  22069. lastEndf = i;
  22070. } else {
  22071. pc = callstack.pop();
  22072. if (!pc) {
  22073. warn('TT: ENDF bad stack');
  22074. ttContext.hintsValid = false;
  22075. return;
  22076. }
  22077. funcId = functionsCalled.pop();
  22078. data = pc.data;
  22079. i = pc.i;
  22080. ttContext.functionsStackDeltas[funcId] =
  22081. stack.length - pc.stackTop;
  22082. }
  22083. } else if (op === 0x89) { // IDEF - instruction definition
  22084. if (inFDEF || inELSE) {
  22085. warn('TT: nested IDEFs not allowed');
  22086. tooComplexToFollowFunctions = true;
  22087. }
  22088. inFDEF = true;
  22089. // recording it as a function to track ENDF
  22090. lastDeff = i;
  22091. } else if (op === 0x58) { // IF
  22092. ++ifLevel;
  22093. } else if (op === 0x1B) { // ELSE
  22094. inELSE = ifLevel;
  22095. } else if (op === 0x59) { // EIF
  22096. if (inELSE === ifLevel) {
  22097. inELSE = 0;
  22098. }
  22099. --ifLevel;
  22100. } else if (op === 0x1C) { // JMPR
  22101. if (!inFDEF && !inELSE) {
  22102. var offset = stack[stack.length - 1];
  22103. // only jumping forward to prevent infinite loop
  22104. if (offset > 0) {
  22105. i += offset - 1;
  22106. }
  22107. }
  22108. }
  22109. // Adjusting stack not extactly, but just enough to get function id
  22110. if (!inFDEF && !inELSE) {
  22111. var stackDelta = op <= 0x8E ? TTOpsStackDeltas[op] :
  22112. op >= 0xC0 && op <= 0xDF ? -1 : op >= 0xE0 ? -2 : 0;
  22113. if (op >= 0x71 && op <= 0x75) {
  22114. n = stack.pop();
  22115. if (n === n) {
  22116. stackDelta = -n * 2;
  22117. }
  22118. }
  22119. while (stackDelta < 0 && stack.length > 0) {
  22120. stack.pop();
  22121. stackDelta++;
  22122. }
  22123. while (stackDelta > 0) {
  22124. stack.push(NaN); // pushing any number into stack
  22125. stackDelta--;
  22126. }
  22127. }
  22128. }
  22129. ttContext.tooComplexToFollowFunctions = tooComplexToFollowFunctions;
  22130. var content = [data];
  22131. if (i > data.length) {
  22132. content.push(new Uint8Array(i - data.length));
  22133. }
  22134. if (lastDeff > lastEndf) {
  22135. warn('TT: complementing a missing function tail');
  22136. // new function definition started, but not finished
  22137. // complete function by [CLEAR, ENDF]
  22138. content.push(new Uint8Array([0x22, 0x2D]));
  22139. }
  22140. foldTTTable(table, content);
  22141. }
  22142. function checkInvalidFunctions(ttContext, maxFunctionDefs) {
  22143. if (ttContext.tooComplexToFollowFunctions) {
  22144. return;
  22145. }
  22146. if (ttContext.functionsDefined.length > maxFunctionDefs) {
  22147. warn('TT: more functions defined than expected');
  22148. ttContext.hintsValid = false;
  22149. return;
  22150. }
  22151. for (var j = 0, jj = ttContext.functionsUsed.length; j < jj; j++) {
  22152. if (j > maxFunctionDefs) {
  22153. warn('TT: invalid function id: ' + j);
  22154. ttContext.hintsValid = false;
  22155. return;
  22156. }
  22157. if (ttContext.functionsUsed[j] && !ttContext.functionsDefined[j]) {
  22158. warn('TT: undefined function: ' + j);
  22159. ttContext.hintsValid = false;
  22160. return;
  22161. }
  22162. }
  22163. }
  22164. function foldTTTable(table, content) {
  22165. if (content.length > 1) {
  22166. // concatenating the content items
  22167. var newLength = 0;
  22168. var j, jj;
  22169. for (j = 0, jj = content.length; j < jj; j++) {
  22170. newLength += content[j].length;
  22171. }
  22172. newLength = (newLength + 3) & ~3;
  22173. var result = new Uint8Array(newLength);
  22174. var pos = 0;
  22175. for (j = 0, jj = content.length; j < jj; j++) {
  22176. result.set(content[j], pos);
  22177. pos += content[j].length;
  22178. }
  22179. table.data = result;
  22180. table.length = newLength;
  22181. }
  22182. }
  22183. function sanitizeTTPrograms(fpgm, prep, cvt) {
  22184. var ttContext = {
  22185. functionsDefined: [],
  22186. functionsUsed: [],
  22187. functionsStackDeltas: [],
  22188. tooComplexToFollowFunctions: false,
  22189. hintsValid: true
  22190. };
  22191. if (fpgm) {
  22192. sanitizeTTProgram(fpgm, ttContext);
  22193. }
  22194. if (prep) {
  22195. sanitizeTTProgram(prep, ttContext);
  22196. }
  22197. if (fpgm) {
  22198. checkInvalidFunctions(ttContext, maxFunctionDefs);
  22199. }
  22200. if (cvt && (cvt.length & 1)) {
  22201. var cvtData = new Uint8Array(cvt.length + 1);
  22202. cvtData.set(cvt.data);
  22203. cvt.data = cvtData;
  22204. }
  22205. return ttContext.hintsValid;
  22206. }
  22207. // The following steps modify the original font data, making copy
  22208. font = new Stream(new Uint8Array(font.getBytes()));
  22209. var VALID_TABLES = ['OS/2', 'cmap', 'head', 'hhea', 'hmtx', 'maxp',
  22210. 'name', 'post', 'loca', 'glyf', 'fpgm', 'prep', 'cvt ', 'CFF '];
  22211. var header = readOpenTypeHeader(font);
  22212. var numTables = header.numTables;
  22213. var cff, cffFile;
  22214. var tables = { 'OS/2': null, cmap: null, head: null, hhea: null,
  22215. hmtx: null, maxp: null, name: null, post: null };
  22216. var table;
  22217. for (var i = 0; i < numTables; i++) {
  22218. table = readTableEntry(font);
  22219. if (VALID_TABLES.indexOf(table.tag) < 0) {
  22220. continue; // skipping table if it's not a required or optional table
  22221. }
  22222. if (table.length === 0) {
  22223. continue; // skipping empty tables
  22224. }
  22225. tables[table.tag] = table;
  22226. }
  22227. var isTrueType = !tables['CFF '];
  22228. if (!isTrueType) {
  22229. // OpenType font
  22230. if (header.version === 'OTTO' ||
  22231. !tables.head || !tables.hhea || !tables.maxp || !tables.post) {
  22232. // no major tables: throwing everything at CFFFont
  22233. cffFile = new Stream(tables['CFF '].data);
  22234. cff = new CFFFont(cffFile, properties);
  22235. return this.convert(name, cff, properties);
  22236. }
  22237. delete tables.glyf;
  22238. delete tables.loca;
  22239. delete tables.fpgm;
  22240. delete tables.prep;
  22241. delete tables['cvt '];
  22242. this.isOpenType = true;
  22243. } else {
  22244. if (!tables.glyf || !tables.loca) {
  22245. error('Required "glyf" or "loca" tables are not found');
  22246. }
  22247. this.isOpenType = false;
  22248. }
  22249. if (!tables.maxp) {
  22250. error('Required "maxp" table is not found');
  22251. }
  22252. font.pos = (font.start || 0) + tables.maxp.offset;
  22253. var version = font.getInt32();
  22254. var numGlyphs = font.getUint16();
  22255. var maxFunctionDefs = 0;
  22256. if (version >= 0x00010000 && tables.maxp.length >= 22) {
  22257. // maxZones can be invalid
  22258. font.pos += 8;
  22259. var maxZones = font.getUint16();
  22260. if (maxZones > 2) { // reset to 2 if font has invalid maxZones
  22261. tables.maxp.data[14] = 0;
  22262. tables.maxp.data[15] = 2;
  22263. }
  22264. font.pos += 4;
  22265. maxFunctionDefs = font.getUint16();
  22266. }
  22267. var dupFirstEntry = false;
  22268. if (properties.type === 'CIDFontType2' && properties.toUnicode &&
  22269. properties.toUnicode.get(0) > '\u0000') {
  22270. // oracle's defect (see 3427), duplicating first entry
  22271. dupFirstEntry = true;
  22272. numGlyphs++;
  22273. tables.maxp.data[4] = numGlyphs >> 8;
  22274. tables.maxp.data[5] = numGlyphs & 255;
  22275. }
  22276. var hintsValid = sanitizeTTPrograms(tables.fpgm, tables.prep,
  22277. tables['cvt '], maxFunctionDefs);
  22278. if (!hintsValid) {
  22279. delete tables.fpgm;
  22280. delete tables.prep;
  22281. delete tables['cvt '];
  22282. }
  22283. // Ensure the hmtx table contains the advance width and
  22284. // sidebearings information for numGlyphs in the maxp table
  22285. sanitizeMetrics(font, tables.hhea, tables.hmtx, numGlyphs);
  22286. if (!tables.head) {
  22287. error('Required "head" table is not found');
  22288. }
  22289. sanitizeHead(tables.head, numGlyphs, isTrueType ? tables.loca.length : 0);
  22290. var missingGlyphs = {};
  22291. if (isTrueType) {
  22292. var isGlyphLocationsLong = int16(tables.head.data[50],
  22293. tables.head.data[51]);
  22294. missingGlyphs = sanitizeGlyphLocations(tables.loca, tables.glyf,
  22295. numGlyphs, isGlyphLocationsLong,
  22296. hintsValid, dupFirstEntry);
  22297. }
  22298. if (!tables.hhea) {
  22299. error('Required "hhea" table is not found');
  22300. }
  22301. // Sanitizer reduces the glyph advanceWidth to the maxAdvanceWidth
  22302. // Sometimes it's 0. That needs to be fixed
  22303. if (tables.hhea.data[10] === 0 && tables.hhea.data[11] === 0) {
  22304. tables.hhea.data[10] = 0xFF;
  22305. tables.hhea.data[11] = 0xFF;
  22306. }
  22307. // The 'post' table has glyphs names.
  22308. if (tables.post) {
  22309. var valid = readPostScriptTable(tables.post, properties, numGlyphs);
  22310. if (!valid) {
  22311. tables.post = null;
  22312. }
  22313. }
  22314. var charCodeToGlyphId = [], charCode, toUnicode = properties.toUnicode;
  22315. function hasGlyph(glyphId, charCode) {
  22316. if (!missingGlyphs[glyphId]) {
  22317. return true;
  22318. }
  22319. if (charCode >= 0 && toUnicode.has(charCode)) {
  22320. return true;
  22321. }
  22322. return false;
  22323. }
  22324. if (properties.type === 'CIDFontType2') {
  22325. var cidToGidMap = properties.cidToGidMap || [];
  22326. var isCidToGidMapEmpty = cidToGidMap.length === 0;
  22327. properties.cMap.forEach(function(charCode, cid) {
  22328. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  22329. var glyphId = -1;
  22330. if (isCidToGidMapEmpty) {
  22331. glyphId = charCode;
  22332. } else if (cidToGidMap[cid] !== undefined) {
  22333. glyphId = cidToGidMap[cid];
  22334. }
  22335. if (glyphId >= 0 && glyphId < numGlyphs &&
  22336. hasGlyph(glyphId, charCode)) {
  22337. charCodeToGlyphId[charCode] = glyphId;
  22338. }
  22339. });
  22340. if (dupFirstEntry) {
  22341. charCodeToGlyphId[0] = numGlyphs - 1;
  22342. }
  22343. } else {
  22344. // Most of the following logic in this code branch is based on the
  22345. // 9.6.6.4 of the PDF spec.
  22346. var cmapTable = readCmapTable(tables.cmap, font, this.isSymbolicFont);
  22347. var cmapPlatformId = cmapTable.platformId;
  22348. var cmapEncodingId = cmapTable.encodingId;
  22349. var cmapMappings = cmapTable.mappings;
  22350. var cmapMappingsLength = cmapMappings.length;
  22351. var hasEncoding = properties.differences.length ||
  22352. !!properties.baseEncodingName;
  22353. // The spec seems to imply that if the font is symbolic the encoding
  22354. // should be ignored, this doesn't appear to work for 'preistabelle.pdf'
  22355. // where the the font is symbolic and it has an encoding.
  22356. if (hasEncoding &&
  22357. (cmapPlatformId === 3 && cmapEncodingId === 1 ||
  22358. cmapPlatformId === 1 && cmapEncodingId === 0) ||
  22359. (cmapPlatformId === -1 && cmapEncodingId === -1 && // Temporary hack
  22360. !!Encodings[properties.baseEncodingName])) { // Temporary hack
  22361. // When no preferred cmap table was found and |baseEncodingName| is
  22362. // one of the predefined encodings, we seem to obtain a better
  22363. // |charCodeToGlyphId| map from the code below (fixes bug 1057544).
  22364. // TODO: Note that this is a hack which should be removed as soon as
  22365. // we have proper support for more exotic cmap tables.
  22366. var baseEncoding = [];
  22367. if (properties.baseEncodingName === 'MacRomanEncoding' ||
  22368. properties.baseEncodingName === 'WinAnsiEncoding') {
  22369. baseEncoding = Encodings[properties.baseEncodingName];
  22370. }
  22371. for (charCode = 0; charCode < 256; charCode++) {
  22372. var glyphName;
  22373. if (this.differences && charCode in this.differences) {
  22374. glyphName = this.differences[charCode];
  22375. } else if (charCode in baseEncoding &&
  22376. baseEncoding[charCode] !== '') {
  22377. glyphName = baseEncoding[charCode];
  22378. } else {
  22379. glyphName = Encodings.StandardEncoding[charCode];
  22380. }
  22381. if (!glyphName) {
  22382. continue;
  22383. }
  22384. var unicodeOrCharCode;
  22385. if (cmapPlatformId === 3 && cmapEncodingId === 1) {
  22386. unicodeOrCharCode = GlyphsUnicode[glyphName];
  22387. } else if (cmapPlatformId === 1 && cmapEncodingId === 0) {
  22388. // TODO: the encoding needs to be updated with mac os table.
  22389. unicodeOrCharCode = Encodings.MacRomanEncoding.indexOf(glyphName);
  22390. }
  22391. var found = false;
  22392. for (i = 0; i < cmapMappingsLength; ++i) {
  22393. if (cmapMappings[i].charCode === unicodeOrCharCode &&
  22394. hasGlyph(cmapMappings[i].glyphId, unicodeOrCharCode)) {
  22395. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  22396. found = true;
  22397. break;
  22398. }
  22399. }
  22400. if (!found && properties.glyphNames) {
  22401. // Try to map using the post table. There are currently no known
  22402. // pdfs that this fixes.
  22403. var glyphId = properties.glyphNames.indexOf(glyphName);
  22404. if (glyphId > 0 && hasGlyph(glyphId, -1)) {
  22405. charCodeToGlyphId[charCode] = glyphId;
  22406. }
  22407. }
  22408. }
  22409. } else if (cmapPlatformId === 0 && cmapEncodingId === 0) {
  22410. // Default Unicode semantics, use the charcodes as is.
  22411. for (i = 0; i < cmapMappingsLength; ++i) {
  22412. charCodeToGlyphId[cmapMappings[i].charCode] =
  22413. cmapMappings[i].glyphId;
  22414. }
  22415. } else {
  22416. // For (3, 0) cmap tables:
  22417. // The charcode key being stored in charCodeToGlyphId is the lower
  22418. // byte of the two-byte charcodes of the cmap table since according to
  22419. // the spec: 'each byte from the string shall be prepended with the
  22420. // high byte of the range [of charcodes in the cmap table], to form
  22421. // a two-byte character, which shall be used to select the
  22422. // associated glyph description from the subtable'.
  22423. //
  22424. // For (1, 0) cmap tables:
  22425. // 'single bytes from the string shall be used to look up the
  22426. // associated glyph descriptions from the subtable'. This means
  22427. // charcodes in the cmap will be single bytes, so no-op since
  22428. // glyph.charCode & 0xFF === glyph.charCode
  22429. for (i = 0; i < cmapMappingsLength; ++i) {
  22430. charCode = cmapMappings[i].charCode & 0xFF;
  22431. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  22432. }
  22433. }
  22434. }
  22435. if (charCodeToGlyphId.length === 0) {
  22436. // defines at least one glyph
  22437. charCodeToGlyphId[0] = 0;
  22438. }
  22439. // Converting glyphs and ids into font's cmap table
  22440. var newMapping = adjustMapping(charCodeToGlyphId, properties);
  22441. this.toFontChar = newMapping.toFontChar;
  22442. tables.cmap = {
  22443. tag: 'cmap',
  22444. data: createCmapTable(newMapping.charCodeToGlyphId)
  22445. };
  22446. if (!tables['OS/2'] || !validateOS2Table(tables['OS/2'])) {
  22447. // extract some more font properties from the OpenType head and
  22448. // hhea tables; yMin and descent value are always negative
  22449. var override = {
  22450. unitsPerEm: int16(tables.head.data[18], tables.head.data[19]),
  22451. yMax: int16(tables.head.data[42], tables.head.data[43]),
  22452. yMin: int16(tables.head.data[38], tables.head.data[39]) - 0x10000,
  22453. ascent: int16(tables.hhea.data[4], tables.hhea.data[5]),
  22454. descent: int16(tables.hhea.data[6], tables.hhea.data[7]) - 0x10000
  22455. };
  22456. tables['OS/2'] = {
  22457. tag: 'OS/2',
  22458. data: createOS2Table(properties, newMapping.charCodeToGlyphId,
  22459. override)
  22460. };
  22461. }
  22462. // Rewrite the 'post' table if needed
  22463. if (!tables.post) {
  22464. tables.post = {
  22465. tag: 'post',
  22466. data: createPostTable(properties)
  22467. };
  22468. }
  22469. if (!isTrueType) {
  22470. try {
  22471. // Trying to repair CFF file
  22472. cffFile = new Stream(tables['CFF '].data);
  22473. var parser = new CFFParser(cffFile, properties);
  22474. cff = parser.parse();
  22475. var compiler = new CFFCompiler(cff);
  22476. tables['CFF '].data = compiler.compile();
  22477. } catch (e) {
  22478. warn('Failed to compile font ' + properties.loadedName);
  22479. }
  22480. }
  22481. // Re-creating 'name' table
  22482. if (!tables.name) {
  22483. tables.name = {
  22484. tag: 'name',
  22485. data: createNameTable(this.name)
  22486. };
  22487. } else {
  22488. // ... using existing 'name' table as prototype
  22489. var namePrototype = readNameTable(tables.name);
  22490. tables.name.data = createNameTable(name, namePrototype);
  22491. }
  22492. var builder = new OpenTypeFileBuilder(header.version);
  22493. for (var tableTag in tables) {
  22494. builder.addTable(tableTag, tables[tableTag].data);
  22495. }
  22496. return builder.toArray();
  22497. },
  22498. convert: function Font_convert(fontName, font, properties) {
  22499. // TODO: Check the charstring widths to determine this.
  22500. properties.fixedPitch = false;
  22501. var mapping = font.getGlyphMapping(properties);
  22502. var newMapping = adjustMapping(mapping, properties);
  22503. this.toFontChar = newMapping.toFontChar;
  22504. var numGlyphs = font.numGlyphs;
  22505. function getCharCodes(charCodeToGlyphId, glyphId) {
  22506. var charCodes = null;
  22507. for (var charCode in charCodeToGlyphId) {
  22508. if (glyphId === charCodeToGlyphId[charCode]) {
  22509. if (!charCodes) {
  22510. charCodes = [];
  22511. }
  22512. charCodes.push(charCode | 0);
  22513. }
  22514. }
  22515. return charCodes;
  22516. }
  22517. function createCharCode(charCodeToGlyphId, glyphId) {
  22518. for (var charCode in charCodeToGlyphId) {
  22519. if (glyphId === charCodeToGlyphId[charCode]) {
  22520. return charCode | 0;
  22521. }
  22522. }
  22523. newMapping.charCodeToGlyphId[newMapping.nextAvailableFontCharCode] =
  22524. glyphId;
  22525. return newMapping.nextAvailableFontCharCode++;
  22526. }
  22527. var seacs = font.seacs;
  22528. if (SEAC_ANALYSIS_ENABLED && seacs && seacs.length) {
  22529. var matrix = properties.fontMatrix || FONT_IDENTITY_MATRIX;
  22530. var charset = font.getCharset();
  22531. var seacMap = Object.create(null);
  22532. for (var glyphId in seacs) {
  22533. glyphId |= 0;
  22534. var seac = seacs[glyphId];
  22535. var baseGlyphName = Encodings.StandardEncoding[seac[2]];
  22536. var accentGlyphName = Encodings.StandardEncoding[seac[3]];
  22537. var baseGlyphId = charset.indexOf(baseGlyphName);
  22538. var accentGlyphId = charset.indexOf(accentGlyphName);
  22539. if (baseGlyphId < 0 || accentGlyphId < 0) {
  22540. continue;
  22541. }
  22542. var accentOffset = {
  22543. x: seac[0] * matrix[0] + seac[1] * matrix[2] + matrix[4],
  22544. y: seac[0] * matrix[1] + seac[1] * matrix[3] + matrix[5]
  22545. };
  22546. var charCodes = getCharCodes(mapping, glyphId);
  22547. if (!charCodes) {
  22548. // There's no point in mapping it if the char code was never mapped
  22549. // to begin with.
  22550. continue;
  22551. }
  22552. for (var i = 0, ii = charCodes.length; i < ii; i++) {
  22553. var charCode = charCodes[i];
  22554. // Find a fontCharCode that maps to the base and accent glyphs.
  22555. // If one doesn't exists, create it.
  22556. var charCodeToGlyphId = newMapping.charCodeToGlyphId;
  22557. var baseFontCharCode = createCharCode(charCodeToGlyphId,
  22558. baseGlyphId);
  22559. var accentFontCharCode = createCharCode(charCodeToGlyphId,
  22560. accentGlyphId);
  22561. seacMap[charCode] = {
  22562. baseFontCharCode: baseFontCharCode,
  22563. accentFontCharCode: accentFontCharCode,
  22564. accentOffset: accentOffset
  22565. };
  22566. }
  22567. }
  22568. properties.seacMap = seacMap;
  22569. }
  22570. var unitsPerEm = 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0];
  22571. var builder = new OpenTypeFileBuilder('\x4F\x54\x54\x4F');
  22572. // PostScript Font Program
  22573. builder.addTable('CFF ', font.data);
  22574. // OS/2 and Windows Specific metrics
  22575. builder.addTable('OS/2', createOS2Table(properties,
  22576. newMapping.charCodeToGlyphId));
  22577. // Character to glyphs mapping
  22578. builder.addTable('cmap', createCmapTable(newMapping.charCodeToGlyphId));
  22579. // Font header
  22580. builder.addTable('head',
  22581. '\x00\x01\x00\x00' + // Version number
  22582. '\x00\x00\x10\x00' + // fontRevision
  22583. '\x00\x00\x00\x00' + // checksumAdjustement
  22584. '\x5F\x0F\x3C\xF5' + // magicNumber
  22585. '\x00\x00' + // Flags
  22586. safeString16(unitsPerEm) + // unitsPerEM
  22587. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // creation date
  22588. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // modifification date
  22589. '\x00\x00' + // xMin
  22590. safeString16(properties.descent) + // yMin
  22591. '\x0F\xFF' + // xMax
  22592. safeString16(properties.ascent) + // yMax
  22593. string16(properties.italicAngle ? 2 : 0) + // macStyle
  22594. '\x00\x11' + // lowestRecPPEM
  22595. '\x00\x00' + // fontDirectionHint
  22596. '\x00\x00' + // indexToLocFormat
  22597. '\x00\x00'); // glyphDataFormat
  22598. // Horizontal header
  22599. builder.addTable('hhea',
  22600. '\x00\x01\x00\x00' + // Version number
  22601. safeString16(properties.ascent) + // Typographic Ascent
  22602. safeString16(properties.descent) + // Typographic Descent
  22603. '\x00\x00' + // Line Gap
  22604. '\xFF\xFF' + // advanceWidthMax
  22605. '\x00\x00' + // minLeftSidebearing
  22606. '\x00\x00' + // minRightSidebearing
  22607. '\x00\x00' + // xMaxExtent
  22608. safeString16(properties.capHeight) + // caretSlopeRise
  22609. safeString16(Math.tan(properties.italicAngle) *
  22610. properties.xHeight) + // caretSlopeRun
  22611. '\x00\x00' + // caretOffset
  22612. '\x00\x00' + // -reserved-
  22613. '\x00\x00' + // -reserved-
  22614. '\x00\x00' + // -reserved-
  22615. '\x00\x00' + // -reserved-
  22616. '\x00\x00' + // metricDataFormat
  22617. string16(numGlyphs)); // Number of HMetrics
  22618. // Horizontal metrics
  22619. builder.addTable('hmtx', (function fontFieldsHmtx() {
  22620. var charstrings = font.charstrings;
  22621. var cffWidths = font.cff ? font.cff.widths : null;
  22622. var hmtx = '\x00\x00\x00\x00'; // Fake .notdef
  22623. for (var i = 1, ii = numGlyphs; i < ii; i++) {
  22624. var width = 0;
  22625. if (charstrings) {
  22626. var charstring = charstrings[i - 1];
  22627. width = 'width' in charstring ? charstring.width : 0;
  22628. } else if (cffWidths) {
  22629. width = Math.ceil(cffWidths[i] || 0);
  22630. }
  22631. hmtx += string16(width) + string16(0);
  22632. }
  22633. return hmtx;
  22634. })());
  22635. // Maximum profile
  22636. builder.addTable('maxp',
  22637. '\x00\x00\x50\x00' + // Version number
  22638. string16(numGlyphs)); // Num of glyphs
  22639. // Naming tables
  22640. builder.addTable('name', createNameTable(fontName));
  22641. // PostScript informations
  22642. builder.addTable('post', createPostTable(properties));
  22643. return builder.toArray();
  22644. },
  22645. /**
  22646. * Builds a char code to unicode map based on section 9.10 of the spec.
  22647. * @param {Object} properties Font properties object.
  22648. * @return {Object} A ToUnicodeMap object.
  22649. */
  22650. buildToUnicode: function Font_buildToUnicode(properties) {
  22651. // Section 9.10.2 Mapping Character Codes to Unicode Values
  22652. if (properties.toUnicode && properties.toUnicode.length !== 0) {
  22653. return properties.toUnicode;
  22654. }
  22655. // According to the spec if the font is a simple font we should only map
  22656. // to unicode if the base encoding is MacRoman, MacExpert, or WinAnsi or
  22657. // the differences array only contains adobe standard or symbol set names,
  22658. // in pratice it seems better to always try to create a toUnicode
  22659. // map based of the default encoding.
  22660. var toUnicode, charcode;
  22661. if (!properties.composite /* is simple font */) {
  22662. toUnicode = [];
  22663. var encoding = properties.defaultEncoding.slice();
  22664. var baseEncodingName = properties.baseEncodingName;
  22665. // Merge in the differences array.
  22666. var differences = properties.differences;
  22667. for (charcode in differences) {
  22668. encoding[charcode] = differences[charcode];
  22669. }
  22670. for (charcode in encoding) {
  22671. // a) Map the character code to a character name.
  22672. var glyphName = encoding[charcode];
  22673. // b) Look up the character name in the Adobe Glyph List (see the
  22674. // Bibliography) to obtain the corresponding Unicode value.
  22675. if (glyphName === '') {
  22676. continue;
  22677. } else if (GlyphsUnicode[glyphName] === undefined) {
  22678. // (undocumented) c) Few heuristics to recognize unknown glyphs
  22679. // NOTE: Adobe Reader does not do this step, but OSX Preview does
  22680. var code = 0;
  22681. switch (glyphName[0]) {
  22682. case 'G': // Gxx glyph
  22683. if (glyphName.length === 3) {
  22684. code = parseInt(glyphName.substr(1), 16);
  22685. }
  22686. break;
  22687. case 'g': // g00xx glyph
  22688. if (glyphName.length === 5) {
  22689. code = parseInt(glyphName.substr(1), 16);
  22690. }
  22691. break;
  22692. case 'C': // Cddd glyph
  22693. case 'c': // cddd glyph
  22694. if (glyphName.length >= 3) {
  22695. code = +glyphName.substr(1);
  22696. }
  22697. break;
  22698. }
  22699. if (code) {
  22700. // If |baseEncodingName| is one the predefined encodings,
  22701. // and |code| equals |charcode|, using the glyph defined in the
  22702. // baseEncoding seems to yield a better |toUnicode| mapping
  22703. // (fixes issue 5070).
  22704. if (baseEncodingName && code === +charcode) {
  22705. var baseEncoding = Encodings[baseEncodingName];
  22706. if (baseEncoding && (glyphName = baseEncoding[charcode])) {
  22707. toUnicode[charcode] =
  22708. String.fromCharCode(GlyphsUnicode[glyphName]);
  22709. continue;
  22710. }
  22711. }
  22712. toUnicode[charcode] = String.fromCharCode(code);
  22713. }
  22714. continue;
  22715. }
  22716. toUnicode[charcode] = String.fromCharCode(GlyphsUnicode[glyphName]);
  22717. }
  22718. return new ToUnicodeMap(toUnicode);
  22719. }
  22720. // If the font is a composite font that uses one of the predefined CMaps
  22721. // listed in Table 118 (except Identity–H and Identity–V) or whose
  22722. // descendant CIDFont uses the Adobe-GB1, Adobe-CNS1, Adobe-Japan1, or
  22723. // Adobe-Korea1 character collection:
  22724. if (properties.composite && (
  22725. (properties.cMap.builtInCMap &&
  22726. !(properties.cMap instanceof IdentityCMap)) ||
  22727. (properties.cidSystemInfo.registry === 'Adobe' &&
  22728. (properties.cidSystemInfo.ordering === 'GB1' ||
  22729. properties.cidSystemInfo.ordering === 'CNS1' ||
  22730. properties.cidSystemInfo.ordering === 'Japan1' ||
  22731. properties.cidSystemInfo.ordering === 'Korea1')))) {
  22732. // Then:
  22733. // a) Map the character code to a character identifier (CID) according
  22734. // to the font’s CMap.
  22735. // b) Obtain the registry and ordering of the character collection used
  22736. // by the font’s CMap (for example, Adobe and Japan1) from its
  22737. // CIDSystemInfo dictionary.
  22738. var registry = properties.cidSystemInfo.registry;
  22739. var ordering = properties.cidSystemInfo.ordering;
  22740. // c) Construct a second CMap name by concatenating the registry and
  22741. // ordering obtained in step (b) in the format registry–ordering–UCS2
  22742. // (for example, Adobe–Japan1–UCS2).
  22743. var ucs2CMapName = new Name(registry + '-' + ordering + '-UCS2');
  22744. // d) Obtain the CMap with the name constructed in step (c) (available
  22745. // from the ASN Web site; see the Bibliography).
  22746. var ucs2CMap = CMapFactory.create(ucs2CMapName,
  22747. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  22748. var cMap = properties.cMap;
  22749. toUnicode = [];
  22750. cMap.forEach(function(charcode, cid) {
  22751. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  22752. // e) Map the CID obtained in step (a) according to the CMap obtained
  22753. // in step (d), producing a Unicode value.
  22754. var ucs2 = ucs2CMap.lookup(cid);
  22755. if (ucs2) {
  22756. toUnicode[charcode] =
  22757. String.fromCharCode((ucs2.charCodeAt(0) << 8) +
  22758. ucs2.charCodeAt(1));
  22759. }
  22760. });
  22761. return new ToUnicodeMap(toUnicode);
  22762. }
  22763. // The viewer's choice, just use an identity map.
  22764. return new IdentityToUnicodeMap(properties.firstChar,
  22765. properties.lastChar);
  22766. },
  22767. get spaceWidth() {
  22768. if ('_shadowWidth' in this) {
  22769. return this._shadowWidth;
  22770. }
  22771. // trying to estimate space character width
  22772. var possibleSpaceReplacements = ['space', 'minus', 'one', 'i'];
  22773. var width;
  22774. for (var i = 0, ii = possibleSpaceReplacements.length; i < ii; i++) {
  22775. var glyphName = possibleSpaceReplacements[i];
  22776. // if possible, getting width by glyph name
  22777. if (glyphName in this.widths) {
  22778. width = this.widths[glyphName];
  22779. break;
  22780. }
  22781. var glyphUnicode = GlyphsUnicode[glyphName];
  22782. // finding the charcode via unicodeToCID map
  22783. var charcode = 0;
  22784. if (this.composite) {
  22785. if (this.cMap.contains(glyphUnicode)) {
  22786. charcode = this.cMap.lookup(glyphUnicode);
  22787. }
  22788. }
  22789. // ... via toUnicode map
  22790. if (!charcode && 'toUnicode' in this) {
  22791. charcode = this.toUnicode.charCodeOf(glyphUnicode);
  22792. }
  22793. // setting it to unicode if negative or undefined
  22794. if (charcode <= 0) {
  22795. charcode = glyphUnicode;
  22796. }
  22797. // trying to get width via charcode
  22798. width = this.widths[charcode];
  22799. if (width) {
  22800. break; // the non-zero width found
  22801. }
  22802. }
  22803. width = width || this.defaultWidth;
  22804. // Do not shadow the property here. See discussion:
  22805. // https://github.com/mozilla/pdf.js/pull/2127#discussion_r1662280
  22806. this._shadowWidth = width;
  22807. return width;
  22808. },
  22809. charToGlyph: function Font_charToGlyph(charcode) {
  22810. var fontCharCode, width, operatorListId;
  22811. var widthCode = charcode;
  22812. if (this.cMap && this.cMap.contains(charcode)) {
  22813. widthCode = this.cMap.lookup(charcode);
  22814. }
  22815. width = this.widths[widthCode];
  22816. width = isNum(width) ? width : this.defaultWidth;
  22817. var vmetric = this.vmetrics && this.vmetrics[widthCode];
  22818. var unicode = this.toUnicode.get(charcode) || charcode;
  22819. if (typeof unicode === 'number') {
  22820. unicode = String.fromCharCode(unicode);
  22821. }
  22822. // First try the toFontChar map, if it's not there then try falling
  22823. // back to the char code.
  22824. fontCharCode = this.toFontChar[charcode] || charcode;
  22825. if (this.missingFile) {
  22826. fontCharCode = mapSpecialUnicodeValues(fontCharCode);
  22827. }
  22828. if (this.isType3Font) {
  22829. // Font char code in this case is actually a glyph name.
  22830. operatorListId = fontCharCode;
  22831. }
  22832. var accent = null;
  22833. if (this.seacMap && this.seacMap[charcode]) {
  22834. var seac = this.seacMap[charcode];
  22835. fontCharCode = seac.baseFontCharCode;
  22836. accent = {
  22837. fontChar: String.fromCharCode(seac.accentFontCharCode),
  22838. offset: seac.accentOffset
  22839. };
  22840. }
  22841. var fontChar = String.fromCharCode(fontCharCode);
  22842. var glyph = this.glyphCache[charcode];
  22843. if (!glyph ||
  22844. !glyph.matchesForCache(fontChar, unicode, accent, width, vmetric,
  22845. operatorListId)) {
  22846. glyph = new Glyph(fontChar, unicode, accent, width, vmetric,
  22847. operatorListId);
  22848. this.glyphCache[charcode] = glyph;
  22849. }
  22850. return glyph;
  22851. },
  22852. charsToGlyphs: function Font_charsToGlyphs(chars) {
  22853. var charsCache = this.charsCache;
  22854. var glyphs, glyph, charcode;
  22855. // if we translated this string before, just grab it from the cache
  22856. if (charsCache) {
  22857. glyphs = charsCache[chars];
  22858. if (glyphs) {
  22859. return glyphs;
  22860. }
  22861. }
  22862. // lazily create the translation cache
  22863. if (!charsCache) {
  22864. charsCache = this.charsCache = Object.create(null);
  22865. }
  22866. glyphs = [];
  22867. var charsCacheKey = chars;
  22868. var i = 0, ii;
  22869. if (this.cMap) {
  22870. // composite fonts have multi-byte strings convert the string from
  22871. // single-byte to multi-byte
  22872. var c = {};
  22873. while (i < chars.length) {
  22874. this.cMap.readCharCode(chars, i, c);
  22875. charcode = c.charcode;
  22876. var length = c.length;
  22877. i += length;
  22878. glyph = this.charToGlyph(charcode);
  22879. glyphs.push(glyph);
  22880. // placing null after each word break charcode (ASCII SPACE)
  22881. // Ignore occurences of 0x20 in multiple-byte codes.
  22882. if (length === 1 && chars.charCodeAt(i - 1) === 0x20) {
  22883. glyphs.push(null);
  22884. }
  22885. }
  22886. } else {
  22887. for (i = 0, ii = chars.length; i < ii; ++i) {
  22888. charcode = chars.charCodeAt(i);
  22889. glyph = this.charToGlyph(charcode);
  22890. glyphs.push(glyph);
  22891. if (charcode === 0x20) {
  22892. glyphs.push(null);
  22893. }
  22894. }
  22895. }
  22896. // Enter the translated string into the cache
  22897. return (charsCache[charsCacheKey] = glyphs);
  22898. }
  22899. };
  22900. return Font;
  22901. })();
  22902. var ErrorFont = (function ErrorFontClosure() {
  22903. function ErrorFont(error) {
  22904. this.error = error;
  22905. this.loadedName = 'g_font_error';
  22906. this.loading = false;
  22907. }
  22908. ErrorFont.prototype = {
  22909. charsToGlyphs: function ErrorFont_charsToGlyphs() {
  22910. return [];
  22911. },
  22912. exportData: function ErrorFont_exportData() {
  22913. return {error: this.error};
  22914. }
  22915. };
  22916. return ErrorFont;
  22917. })();
  22918. /**
  22919. * Shared logic for building a char code to glyph id mapping for Type1 and
  22920. * simple CFF fonts. See section 9.6.6.2 of the spec.
  22921. * @param {Object} properties Font properties object.
  22922. * @param {Object} builtInEncoding The encoding contained within the actual font
  22923. * data.
  22924. * @param {Array} Array of glyph names where the index is the glyph ID.
  22925. * @returns {Object} A char code to glyph ID map.
  22926. */
  22927. function type1FontGlyphMapping(properties, builtInEncoding, glyphNames) {
  22928. var charCodeToGlyphId = Object.create(null);
  22929. var glyphId, charCode, baseEncoding;
  22930. if (properties.baseEncodingName) {
  22931. // If a valid base encoding name was used, the mapping is initialized with
  22932. // that.
  22933. baseEncoding = Encodings[properties.baseEncodingName];
  22934. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  22935. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  22936. if (glyphId >= 0) {
  22937. charCodeToGlyphId[charCode] = glyphId;
  22938. } else {
  22939. charCodeToGlyphId[charCode] = 0; // notdef
  22940. }
  22941. }
  22942. } else if (!!(properties.flags & FontFlags.Symbolic)) {
  22943. // For a symbolic font the encoding should be the fonts built-in
  22944. // encoding.
  22945. for (charCode in builtInEncoding) {
  22946. charCodeToGlyphId[charCode] = builtInEncoding[charCode];
  22947. }
  22948. } else {
  22949. // For non-symbolic fonts that don't have a base encoding the standard
  22950. // encoding should be used.
  22951. baseEncoding = Encodings.StandardEncoding;
  22952. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  22953. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  22954. if (glyphId >= 0) {
  22955. charCodeToGlyphId[charCode] = glyphId;
  22956. } else {
  22957. charCodeToGlyphId[charCode] = 0; // notdef
  22958. }
  22959. }
  22960. }
  22961. // Lastly, merge in the differences.
  22962. var differences = properties.differences;
  22963. if (differences) {
  22964. for (charCode in differences) {
  22965. var glyphName = differences[charCode];
  22966. glyphId = glyphNames.indexOf(glyphName);
  22967. if (glyphId >= 0) {
  22968. charCodeToGlyphId[charCode] = glyphId;
  22969. } else {
  22970. charCodeToGlyphId[charCode] = 0; // notdef
  22971. }
  22972. }
  22973. }
  22974. return charCodeToGlyphId;
  22975. }
  22976. /*
  22977. * CharStrings are encoded following the the CharString Encoding sequence
  22978. * describe in Chapter 6 of the "Adobe Type1 Font Format" specification.
  22979. * The value in a byte indicates a command, a number, or subsequent bytes
  22980. * that are to be interpreted in a special way.
  22981. *
  22982. * CharString Number Encoding:
  22983. * A CharString byte containing the values from 32 through 255 inclusive
  22984. * indicate an integer. These values are decoded in four ranges.
  22985. *
  22986. * 1. A CharString byte containing a value, v, between 32 and 246 inclusive,
  22987. * indicate the integer v - 139. Thus, the integer values from -107 through
  22988. * 107 inclusive may be encoded in single byte.
  22989. *
  22990. * 2. A CharString byte containing a value, v, between 247 and 250 inclusive,
  22991. * indicates an integer involving the next byte, w, according to the formula:
  22992. * [(v - 247) x 256] + w + 108
  22993. *
  22994. * 3. A CharString byte containing a value, v, between 251 and 254 inclusive,
  22995. * indicates an integer involving the next byte, w, according to the formula:
  22996. * -[(v - 251) * 256] - w - 108
  22997. *
  22998. * 4. A CharString containing the value 255 indicates that the next 4 bytes
  22999. * are a two complement signed integer. The first of these bytes contains the
  23000. * highest order bits, the second byte contains the next higher order bits
  23001. * and the fourth byte contain the lowest order bits.
  23002. *
  23003. *
  23004. * CharString Command Encoding:
  23005. * CharStrings commands are encoded in 1 or 2 bytes.
  23006. *
  23007. * Single byte commands are encoded in 1 byte that contains a value between
  23008. * 0 and 31 inclusive.
  23009. * If a command byte contains the value 12, then the value in the next byte
  23010. * indicates a command. This "escape" mechanism allows many extra commands
  23011. * to be encoded and this encoding technique helps to minimize the length of
  23012. * the charStrings.
  23013. */
  23014. var Type1CharString = (function Type1CharStringClosure() {
  23015. var COMMAND_MAP = {
  23016. 'hstem': [1],
  23017. 'vstem': [3],
  23018. 'vmoveto': [4],
  23019. 'rlineto': [5],
  23020. 'hlineto': [6],
  23021. 'vlineto': [7],
  23022. 'rrcurveto': [8],
  23023. 'callsubr': [10],
  23024. 'flex': [12, 35],
  23025. 'drop' : [12, 18],
  23026. 'endchar': [14],
  23027. 'rmoveto': [21],
  23028. 'hmoveto': [22],
  23029. 'vhcurveto': [30],
  23030. 'hvcurveto': [31]
  23031. };
  23032. function Type1CharString() {
  23033. this.width = 0;
  23034. this.lsb = 0;
  23035. this.flexing = false;
  23036. this.output = [];
  23037. this.stack = [];
  23038. }
  23039. Type1CharString.prototype = {
  23040. convert: function Type1CharString_convert(encoded, subrs) {
  23041. var count = encoded.length;
  23042. var error = false;
  23043. var wx, sbx, subrNumber;
  23044. for (var i = 0; i < count; i++) {
  23045. var value = encoded[i];
  23046. if (value < 32) {
  23047. if (value === 12) {
  23048. value = (value << 8) + encoded[++i];
  23049. }
  23050. switch (value) {
  23051. case 1: // hstem
  23052. if (!HINTING_ENABLED) {
  23053. this.stack = [];
  23054. break;
  23055. }
  23056. error = this.executeCommand(2, COMMAND_MAP.hstem);
  23057. break;
  23058. case 3: // vstem
  23059. if (!HINTING_ENABLED) {
  23060. this.stack = [];
  23061. break;
  23062. }
  23063. error = this.executeCommand(2, COMMAND_MAP.vstem);
  23064. break;
  23065. case 4: // vmoveto
  23066. if (this.flexing) {
  23067. if (this.stack.length < 1) {
  23068. error = true;
  23069. break;
  23070. }
  23071. // Add the dx for flex and but also swap the values so they are
  23072. // the right order.
  23073. var dy = this.stack.pop();
  23074. this.stack.push(0, dy);
  23075. break;
  23076. }
  23077. error = this.executeCommand(1, COMMAND_MAP.vmoveto);
  23078. break;
  23079. case 5: // rlineto
  23080. error = this.executeCommand(2, COMMAND_MAP.rlineto);
  23081. break;
  23082. case 6: // hlineto
  23083. error = this.executeCommand(1, COMMAND_MAP.hlineto);
  23084. break;
  23085. case 7: // vlineto
  23086. error = this.executeCommand(1, COMMAND_MAP.vlineto);
  23087. break;
  23088. case 8: // rrcurveto
  23089. error = this.executeCommand(6, COMMAND_MAP.rrcurveto);
  23090. break;
  23091. case 9: // closepath
  23092. // closepath is a Type1 command that does not take argument and is
  23093. // useless in Type2 and it can simply be ignored.
  23094. this.stack = [];
  23095. break;
  23096. case 10: // callsubr
  23097. if (this.stack.length < 1) {
  23098. error = true;
  23099. break;
  23100. }
  23101. subrNumber = this.stack.pop();
  23102. error = this.convert(subrs[subrNumber], subrs);
  23103. break;
  23104. case 11: // return
  23105. return error;
  23106. case 13: // hsbw
  23107. if (this.stack.length < 2) {
  23108. error = true;
  23109. break;
  23110. }
  23111. // To convert to type2 we have to move the width value to the
  23112. // first part of the charstring and then use hmoveto with lsb.
  23113. wx = this.stack.pop();
  23114. sbx = this.stack.pop();
  23115. this.lsb = sbx;
  23116. this.width = wx;
  23117. this.stack.push(wx, sbx);
  23118. error = this.executeCommand(2, COMMAND_MAP.hmoveto);
  23119. break;
  23120. case 14: // endchar
  23121. this.output.push(COMMAND_MAP.endchar[0]);
  23122. break;
  23123. case 21: // rmoveto
  23124. if (this.flexing) {
  23125. break;
  23126. }
  23127. error = this.executeCommand(2, COMMAND_MAP.rmoveto);
  23128. break;
  23129. case 22: // hmoveto
  23130. if (this.flexing) {
  23131. // Add the dy for flex.
  23132. this.stack.push(0);
  23133. break;
  23134. }
  23135. error = this.executeCommand(1, COMMAND_MAP.hmoveto);
  23136. break;
  23137. case 30: // vhcurveto
  23138. error = this.executeCommand(4, COMMAND_MAP.vhcurveto);
  23139. break;
  23140. case 31: // hvcurveto
  23141. error = this.executeCommand(4, COMMAND_MAP.hvcurveto);
  23142. break;
  23143. case (12 << 8) + 0: // dotsection
  23144. // dotsection is a Type1 command to specify some hinting feature
  23145. // for dots that do not take a parameter and it can safely be
  23146. // ignored for Type2.
  23147. this.stack = [];
  23148. break;
  23149. case (12 << 8) + 1: // vstem3
  23150. if (!HINTING_ENABLED) {
  23151. this.stack = [];
  23152. break;
  23153. }
  23154. // [vh]stem3 are Type1 only and Type2 supports [vh]stem with
  23155. // multiple parameters, so instead of returning [vh]stem3 take a
  23156. // shortcut and return [vhstem] instead.
  23157. error = this.executeCommand(2, COMMAND_MAP.vstem);
  23158. break;
  23159. case (12 << 8) + 2: // hstem3
  23160. if (!HINTING_ENABLED) {
  23161. this.stack = [];
  23162. break;
  23163. }
  23164. // See vstem3.
  23165. error = this.executeCommand(2, COMMAND_MAP.hstem);
  23166. break;
  23167. case (12 << 8) + 6: // seac
  23168. // seac is like type 2's special endchar but it doesn't use the
  23169. // first argument asb, so remove it.
  23170. if (SEAC_ANALYSIS_ENABLED) {
  23171. this.seac = this.stack.splice(-4, 4);
  23172. error = this.executeCommand(0, COMMAND_MAP.endchar);
  23173. } else {
  23174. error = this.executeCommand(4, COMMAND_MAP.endchar);
  23175. }
  23176. break;
  23177. case (12 << 8) + 7: // sbw
  23178. if (this.stack.length < 4) {
  23179. error = true;
  23180. break;
  23181. }
  23182. // To convert to type2 we have to move the width value to the
  23183. // first part of the charstring and then use rmoveto with
  23184. // (dx, dy). The height argument will not be used for vmtx and
  23185. // vhea tables reconstruction -- ignoring it.
  23186. var wy = this.stack.pop();
  23187. wx = this.stack.pop();
  23188. var sby = this.stack.pop();
  23189. sbx = this.stack.pop();
  23190. this.lsb = sbx;
  23191. this.width = wx;
  23192. this.stack.push(wx, sbx, sby);
  23193. error = this.executeCommand(3, COMMAND_MAP.rmoveto);
  23194. break;
  23195. case (12 << 8) + 12: // div
  23196. if (this.stack.length < 2) {
  23197. error = true;
  23198. break;
  23199. }
  23200. var num2 = this.stack.pop();
  23201. var num1 = this.stack.pop();
  23202. this.stack.push(num1 / num2);
  23203. break;
  23204. case (12 << 8) + 16: // callothersubr
  23205. if (this.stack.length < 2) {
  23206. error = true;
  23207. break;
  23208. }
  23209. subrNumber = this.stack.pop();
  23210. var numArgs = this.stack.pop();
  23211. if (subrNumber === 0 && numArgs === 3) {
  23212. var flexArgs = this.stack.splice(this.stack.length - 17, 17);
  23213. this.stack.push(
  23214. flexArgs[2] + flexArgs[0], // bcp1x + rpx
  23215. flexArgs[3] + flexArgs[1], // bcp1y + rpy
  23216. flexArgs[4], // bcp2x
  23217. flexArgs[5], // bcp2y
  23218. flexArgs[6], // p2x
  23219. flexArgs[7], // p2y
  23220. flexArgs[8], // bcp3x
  23221. flexArgs[9], // bcp3y
  23222. flexArgs[10], // bcp4x
  23223. flexArgs[11], // bcp4y
  23224. flexArgs[12], // p3x
  23225. flexArgs[13], // p3y
  23226. flexArgs[14] // flexDepth
  23227. // 15 = finalx unused by flex
  23228. // 16 = finaly unused by flex
  23229. );
  23230. error = this.executeCommand(13, COMMAND_MAP.flex, true);
  23231. this.flexing = false;
  23232. this.stack.push(flexArgs[15], flexArgs[16]);
  23233. } else if (subrNumber === 1 && numArgs === 0) {
  23234. this.flexing = true;
  23235. }
  23236. break;
  23237. case (12 << 8) + 17: // pop
  23238. // Ignore this since it is only used with othersubr.
  23239. break;
  23240. case (12 << 8) + 33: // setcurrentpoint
  23241. // Ignore for now.
  23242. this.stack = [];
  23243. break;
  23244. default:
  23245. warn('Unknown type 1 charstring command of "' + value + '"');
  23246. break;
  23247. }
  23248. if (error) {
  23249. break;
  23250. }
  23251. continue;
  23252. } else if (value <= 246) {
  23253. value = value - 139;
  23254. } else if (value <= 250) {
  23255. value = ((value - 247) * 256) + encoded[++i] + 108;
  23256. } else if (value <= 254) {
  23257. value = -((value - 251) * 256) - encoded[++i] - 108;
  23258. } else {
  23259. value = (encoded[++i] & 0xff) << 24 | (encoded[++i] & 0xff) << 16 |
  23260. (encoded[++i] & 0xff) << 8 | (encoded[++i] & 0xff) << 0;
  23261. }
  23262. this.stack.push(value);
  23263. }
  23264. return error;
  23265. },
  23266. executeCommand: function(howManyArgs, command, keepStack) {
  23267. var stackLength = this.stack.length;
  23268. if (howManyArgs > stackLength) {
  23269. return true;
  23270. }
  23271. var start = stackLength - howManyArgs;
  23272. for (var i = start; i < stackLength; i++) {
  23273. var value = this.stack[i];
  23274. if (value === (value | 0)) { // int
  23275. this.output.push(28, (value >> 8) & 0xff, value & 0xff);
  23276. } else { // fixed point
  23277. value = (65536 * value) | 0;
  23278. this.output.push(255,
  23279. (value >> 24) & 0xFF,
  23280. (value >> 16) & 0xFF,
  23281. (value >> 8) & 0xFF,
  23282. value & 0xFF);
  23283. }
  23284. }
  23285. this.output.push.apply(this.output, command);
  23286. if (keepStack) {
  23287. this.stack.splice(start, howManyArgs);
  23288. } else {
  23289. this.stack.length = 0;
  23290. }
  23291. return false;
  23292. }
  23293. };
  23294. return Type1CharString;
  23295. })();
  23296. /*
  23297. * Type1Parser encapsulate the needed code for parsing a Type1 font
  23298. * program. Some of its logic depends on the Type2 charstrings
  23299. * structure.
  23300. * Note: this doesn't really parse the font since that would require evaluation
  23301. * of PostScript, but it is possible in most cases to extract what we need
  23302. * without a full parse.
  23303. */
  23304. var Type1Parser = (function Type1ParserClosure() {
  23305. /*
  23306. * Decrypt a Sequence of Ciphertext Bytes to Produce the Original Sequence
  23307. * of Plaintext Bytes. The function took a key as a parameter which can be
  23308. * for decrypting the eexec block of for decoding charStrings.
  23309. */
  23310. var EEXEC_ENCRYPT_KEY = 55665;
  23311. var CHAR_STRS_ENCRYPT_KEY = 4330;
  23312. function isHexDigit(code) {
  23313. return code >= 48 && code <= 57 || // '0'-'9'
  23314. code >= 65 && code <= 70 || // 'A'-'F'
  23315. code >= 97 && code <= 102; // 'a'-'f'
  23316. }
  23317. function decrypt(data, key, discardNumber) {
  23318. var r = key | 0, c1 = 52845, c2 = 22719;
  23319. var count = data.length;
  23320. var decrypted = new Uint8Array(count);
  23321. for (var i = 0; i < count; i++) {
  23322. var value = data[i];
  23323. decrypted[i] = value ^ (r >> 8);
  23324. r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
  23325. }
  23326. return Array.prototype.slice.call(decrypted, discardNumber);
  23327. }
  23328. function decryptAscii(data, key, discardNumber) {
  23329. var r = key | 0, c1 = 52845, c2 = 22719;
  23330. var count = data.length, maybeLength = count >>> 1;
  23331. var decrypted = new Uint8Array(maybeLength);
  23332. var i, j;
  23333. for (i = 0, j = 0; i < count; i++) {
  23334. var digit1 = data[i];
  23335. if (!isHexDigit(digit1)) {
  23336. continue;
  23337. }
  23338. i++;
  23339. var digit2;
  23340. while (i < count && !isHexDigit(digit2 = data[i])) {
  23341. i++;
  23342. }
  23343. if (i < count) {
  23344. var value = parseInt(String.fromCharCode(digit1, digit2), 16);
  23345. decrypted[j++] = value ^ (r >> 8);
  23346. r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
  23347. }
  23348. }
  23349. return Array.prototype.slice.call(decrypted, discardNumber, j);
  23350. }
  23351. function isSpecial(c) {
  23352. return c === 0x2F || // '/'
  23353. c === 0x5B || c === 0x5D || // '[', ']'
  23354. c === 0x7B || c === 0x7D || // '{', '}'
  23355. c === 0x28 || c === 0x29; // '(', ')'
  23356. }
  23357. function Type1Parser(stream, encrypted) {
  23358. if (encrypted) {
  23359. var data = stream.getBytes();
  23360. var isBinary = !(isHexDigit(data[0]) && isHexDigit(data[1]) &&
  23361. isHexDigit(data[2]) && isHexDigit(data[3]));
  23362. stream = new Stream(isBinary ? decrypt(data, EEXEC_ENCRYPT_KEY, 4) :
  23363. decryptAscii(data, EEXEC_ENCRYPT_KEY, 4));
  23364. }
  23365. this.stream = stream;
  23366. this.nextChar();
  23367. }
  23368. Type1Parser.prototype = {
  23369. readNumberArray: function Type1Parser_readNumberArray() {
  23370. this.getToken(); // read '[' or '{' (arrays can start with either)
  23371. var array = [];
  23372. while (true) {
  23373. var token = this.getToken();
  23374. if (token === null || token === ']' || token === '}') {
  23375. break;
  23376. }
  23377. array.push(parseFloat(token || 0));
  23378. }
  23379. return array;
  23380. },
  23381. readNumber: function Type1Parser_readNumber() {
  23382. var token = this.getToken();
  23383. return parseFloat(token || 0);
  23384. },
  23385. readInt: function Type1Parser_readInt() {
  23386. // Use '| 0' to prevent setting a double into length such as the double
  23387. // does not flow into the loop variable.
  23388. var token = this.getToken();
  23389. return parseInt(token || 0, 10) | 0;
  23390. },
  23391. readBoolean: function Type1Parser_readBoolean() {
  23392. var token = this.getToken();
  23393. // Use 1 and 0 since that's what type2 charstrings use.
  23394. return token === 'true' ? 1 : 0;
  23395. },
  23396. nextChar : function Type1_nextChar() {
  23397. return (this.currentChar = this.stream.getByte());
  23398. },
  23399. getToken: function Type1Parser_getToken() {
  23400. // Eat whitespace and comments.
  23401. var comment = false;
  23402. var ch = this.currentChar;
  23403. while (true) {
  23404. if (ch === -1) {
  23405. return null;
  23406. }
  23407. if (comment) {
  23408. if (ch === 0x0A || ch === 0x0D) {
  23409. comment = false;
  23410. }
  23411. } else if (ch === 0x25) { // '%'
  23412. comment = true;
  23413. } else if (!Lexer.isSpace(ch)) {
  23414. break;
  23415. }
  23416. ch = this.nextChar();
  23417. }
  23418. if (isSpecial(ch)) {
  23419. this.nextChar();
  23420. return String.fromCharCode(ch);
  23421. }
  23422. var token = '';
  23423. do {
  23424. token += String.fromCharCode(ch);
  23425. ch = this.nextChar();
  23426. } while (ch >= 0 && !Lexer.isSpace(ch) && !isSpecial(ch));
  23427. return token;
  23428. },
  23429. /*
  23430. * Returns an object containing a Subrs array and a CharStrings
  23431. * array extracted from and eexec encrypted block of data
  23432. */
  23433. extractFontProgram: function Type1Parser_extractFontProgram() {
  23434. var stream = this.stream;
  23435. var subrs = [], charstrings = [];
  23436. var program = {
  23437. subrs: [],
  23438. charstrings: [],
  23439. properties: {
  23440. 'privateData': {
  23441. 'lenIV': 4
  23442. }
  23443. }
  23444. };
  23445. var token, length, data, lenIV, encoded;
  23446. while ((token = this.getToken()) !== null) {
  23447. if (token !== '/') {
  23448. continue;
  23449. }
  23450. token = this.getToken();
  23451. switch (token) {
  23452. case 'CharStrings':
  23453. // The number immediately following CharStrings must be greater or
  23454. // equal to the number of CharStrings.
  23455. this.getToken();
  23456. this.getToken(); // read in 'dict'
  23457. this.getToken(); // read in 'dup'
  23458. this.getToken(); // read in 'begin'
  23459. while(true) {
  23460. token = this.getToken();
  23461. if (token === null || token === 'end') {
  23462. break;
  23463. }
  23464. if (token !== '/') {
  23465. continue;
  23466. }
  23467. var glyph = this.getToken();
  23468. length = this.readInt();
  23469. this.getToken(); // read in 'RD' or '-|'
  23470. data = stream.makeSubStream(stream.pos, length);
  23471. lenIV = program.properties.privateData['lenIV'];
  23472. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  23473. // Skip past the required space and binary data.
  23474. stream.skip(length);
  23475. this.nextChar();
  23476. token = this.getToken(); // read in 'ND' or '|-'
  23477. if (token === 'noaccess') {
  23478. this.getToken(); // read in 'def'
  23479. }
  23480. charstrings.push({
  23481. glyph: glyph,
  23482. encoded: encoded
  23483. });
  23484. }
  23485. break;
  23486. case 'Subrs':
  23487. var num = this.readInt();
  23488. this.getToken(); // read in 'array'
  23489. while ((token = this.getToken()) === 'dup') {
  23490. var index = this.readInt();
  23491. length = this.readInt();
  23492. this.getToken(); // read in 'RD' or '-|'
  23493. data = stream.makeSubStream(stream.pos, length);
  23494. lenIV = program.properties.privateData['lenIV'];
  23495. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  23496. // Skip past the required space and binary data.
  23497. stream.skip(length);
  23498. this.nextChar();
  23499. token = this.getToken(); // read in 'NP' or '|'
  23500. if (token === 'noaccess') {
  23501. this.getToken(); // read in 'put'
  23502. }
  23503. subrs[index] = encoded;
  23504. }
  23505. break;
  23506. case 'BlueValues':
  23507. case 'OtherBlues':
  23508. case 'FamilyBlues':
  23509. case 'FamilyOtherBlues':
  23510. var blueArray = this.readNumberArray();
  23511. // *Blue* values may contain invalid data: disables reading of
  23512. // those values when hinting is disabled.
  23513. if (blueArray.length > 0 && (blueArray.length % 2) === 0 &&
  23514. HINTING_ENABLED) {
  23515. program.properties.privateData[token] = blueArray;
  23516. }
  23517. break;
  23518. case 'StemSnapH':
  23519. case 'StemSnapV':
  23520. program.properties.privateData[token] = this.readNumberArray();
  23521. break;
  23522. case 'StdHW':
  23523. case 'StdVW':
  23524. program.properties.privateData[token] =
  23525. this.readNumberArray()[0];
  23526. break;
  23527. case 'BlueShift':
  23528. case 'lenIV':
  23529. case 'BlueFuzz':
  23530. case 'BlueScale':
  23531. case 'LanguageGroup':
  23532. case 'ExpansionFactor':
  23533. program.properties.privateData[token] = this.readNumber();
  23534. break;
  23535. case 'ForceBold':
  23536. program.properties.privateData[token] = this.readBoolean();
  23537. break;
  23538. }
  23539. }
  23540. for (var i = 0; i < charstrings.length; i++) {
  23541. glyph = charstrings[i].glyph;
  23542. encoded = charstrings[i].encoded;
  23543. var charString = new Type1CharString();
  23544. var error = charString.convert(encoded, subrs);
  23545. var output = charString.output;
  23546. if (error) {
  23547. // It seems when FreeType encounters an error while evaluating a glyph
  23548. // that it completely ignores the glyph so we'll mimic that behaviour
  23549. // here and put an endchar to make the validator happy.
  23550. output = [14];
  23551. }
  23552. program.charstrings.push({
  23553. glyphName: glyph,
  23554. charstring: output,
  23555. width: charString.width,
  23556. lsb: charString.lsb,
  23557. seac: charString.seac
  23558. });
  23559. }
  23560. return program;
  23561. },
  23562. extractFontHeader: function Type1Parser_extractFontHeader(properties) {
  23563. var token;
  23564. while ((token = this.getToken()) !== null) {
  23565. if (token !== '/') {
  23566. continue;
  23567. }
  23568. token = this.getToken();
  23569. switch (token) {
  23570. case 'FontMatrix':
  23571. var matrix = this.readNumberArray();
  23572. properties.fontMatrix = matrix;
  23573. break;
  23574. case 'Encoding':
  23575. var encodingArg = this.getToken();
  23576. var encoding;
  23577. if (!/^\d+$/.test(encodingArg)) {
  23578. // encoding name is specified
  23579. encoding = Encodings[encodingArg];
  23580. } else {
  23581. encoding = [];
  23582. var size = parseInt(encodingArg, 10) | 0;
  23583. this.getToken(); // read in 'array'
  23584. for (var j = 0; j < size; j++) {
  23585. token = this.getToken();
  23586. // skipping till first dup or def (e.g. ignoring for statement)
  23587. while (token !== 'dup' && token !== 'def') {
  23588. token = this.getToken();
  23589. if (token === null) {
  23590. return; // invalid header
  23591. }
  23592. }
  23593. if (token === 'def') {
  23594. break; // read all array data
  23595. }
  23596. var index = this.readInt();
  23597. this.getToken(); // read in '/'
  23598. var glyph = this.getToken();
  23599. encoding[index] = glyph;
  23600. this.getToken(); // read the in 'put'
  23601. }
  23602. }
  23603. properties.builtInEncoding = encoding;
  23604. break;
  23605. case 'FontBBox':
  23606. var fontBBox = this.readNumberArray();
  23607. // adjusting ascent/descent
  23608. properties.ascent = fontBBox[3];
  23609. properties.descent = fontBBox[1];
  23610. properties.ascentScaled = true;
  23611. break;
  23612. }
  23613. }
  23614. }
  23615. };
  23616. return Type1Parser;
  23617. })();
  23618. /**
  23619. * The CFF class takes a Type1 file and wrap it into a
  23620. * 'Compact Font Format' which itself embed Type2 charstrings.
  23621. */
  23622. var CFFStandardStrings = [
  23623. '.notdef', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  23624. 'ampersand', 'quoteright', 'parenleft', 'parenright', 'asterisk', 'plus',
  23625. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three', 'four',
  23626. 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon', 'less',
  23627. 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
  23628. 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
  23629. 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright', 'asciicircum',
  23630. 'underscore', 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
  23631. 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y',
  23632. 'z', 'braceleft', 'bar', 'braceright', 'asciitilde', 'exclamdown', 'cent',
  23633. 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  23634. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  23635. 'guilsinglright', 'fi', 'fl', 'endash', 'dagger', 'daggerdbl',
  23636. 'periodcentered', 'paragraph', 'bullet', 'quotesinglbase', 'quotedblbase',
  23637. 'quotedblright', 'guillemotright', 'ellipsis', 'perthousand', 'questiondown',
  23638. 'grave', 'acute', 'circumflex', 'tilde', 'macron', 'breve', 'dotaccent',
  23639. 'dieresis', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron', 'emdash',
  23640. 'AE', 'ordfeminine', 'Lslash', 'Oslash', 'OE', 'ordmasculine', 'ae',
  23641. 'dotlessi', 'lslash', 'oslash', 'oe', 'germandbls', 'onesuperior',
  23642. 'logicalnot', 'mu', 'trademark', 'Eth', 'onehalf', 'plusminus', 'Thorn',
  23643. 'onequarter', 'divide', 'brokenbar', 'degree', 'thorn', 'threequarters',
  23644. 'twosuperior', 'registered', 'minus', 'eth', 'multiply', 'threesuperior',
  23645. 'copyright', 'Aacute', 'Acircumflex', 'Adieresis', 'Agrave', 'Aring',
  23646. 'Atilde', 'Ccedilla', 'Eacute', 'Ecircumflex', 'Edieresis', 'Egrave',
  23647. 'Iacute', 'Icircumflex', 'Idieresis', 'Igrave', 'Ntilde', 'Oacute',
  23648. 'Ocircumflex', 'Odieresis', 'Ograve', 'Otilde', 'Scaron', 'Uacute',
  23649. 'Ucircumflex', 'Udieresis', 'Ugrave', 'Yacute', 'Ydieresis', 'Zcaron',
  23650. 'aacute', 'acircumflex', 'adieresis', 'agrave', 'aring', 'atilde',
  23651. 'ccedilla', 'eacute', 'ecircumflex', 'edieresis', 'egrave', 'iacute',
  23652. 'icircumflex', 'idieresis', 'igrave', 'ntilde', 'oacute', 'ocircumflex',
  23653. 'odieresis', 'ograve', 'otilde', 'scaron', 'uacute', 'ucircumflex',
  23654. 'udieresis', 'ugrave', 'yacute', 'ydieresis', 'zcaron', 'exclamsmall',
  23655. 'Hungarumlautsmall', 'dollaroldstyle', 'dollarsuperior', 'ampersandsmall',
  23656. 'Acutesmall', 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  23657. 'onedotenleader', 'zerooldstyle', 'oneoldstyle', 'twooldstyle',
  23658. 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle', 'sixoldstyle',
  23659. 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle', 'commasuperior',
  23660. 'threequartersemdash', 'periodsuperior', 'questionsmall', 'asuperior',
  23661. 'bsuperior', 'centsuperior', 'dsuperior', 'esuperior', 'isuperior',
  23662. 'lsuperior', 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  23663. 'tsuperior', 'ff', 'ffi', 'ffl', 'parenleftinferior', 'parenrightinferior',
  23664. 'Circumflexsmall', 'hyphensuperior', 'Gravesmall', 'Asmall', 'Bsmall',
  23665. 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall', 'Hsmall', 'Ismall',
  23666. 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall', 'Osmall', 'Psmall',
  23667. 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall', 'Vsmall', 'Wsmall',
  23668. 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary', 'onefitted', 'rupiah',
  23669. 'Tildesmall', 'exclamdownsmall', 'centoldstyle', 'Lslashsmall',
  23670. 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall', 'Brevesmall', 'Caronsmall',
  23671. 'Dotaccentsmall', 'Macronsmall', 'figuredash', 'hypheninferior',
  23672. 'Ogoneksmall', 'Ringsmall', 'Cedillasmall', 'questiondownsmall', 'oneeighth',
  23673. 'threeeighths', 'fiveeighths', 'seveneighths', 'onethird', 'twothirds',
  23674. 'zerosuperior', 'foursuperior', 'fivesuperior', 'sixsuperior',
  23675. 'sevensuperior', 'eightsuperior', 'ninesuperior', 'zeroinferior',
  23676. 'oneinferior', 'twoinferior', 'threeinferior', 'fourinferior',
  23677. 'fiveinferior', 'sixinferior', 'seveninferior', 'eightinferior',
  23678. 'nineinferior', 'centinferior', 'dollarinferior', 'periodinferior',
  23679. 'commainferior', 'Agravesmall', 'Aacutesmall', 'Acircumflexsmall',
  23680. 'Atildesmall', 'Adieresissmall', 'Aringsmall', 'AEsmall', 'Ccedillasmall',
  23681. 'Egravesmall', 'Eacutesmall', 'Ecircumflexsmall', 'Edieresissmall',
  23682. 'Igravesmall', 'Iacutesmall', 'Icircumflexsmall', 'Idieresissmall',
  23683. 'Ethsmall', 'Ntildesmall', 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall',
  23684. 'Otildesmall', 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall',
  23685. 'Uacutesmall', 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall',
  23686. 'Thornsmall', 'Ydieresissmall', '001.000', '001.001', '001.002', '001.003',
  23687. 'Black', 'Bold', 'Book', 'Light', 'Medium', 'Regular', 'Roman', 'Semibold'
  23688. ];
  23689. // Type1Font is also a CIDFontType0.
  23690. var Type1Font = function Type1Font(name, file, properties) {
  23691. // Some bad generators embed pfb file as is, we have to strip 6-byte headers.
  23692. // Also, length1 and length2 might be off by 6 bytes as well.
  23693. // http://www.math.ubc.ca/~cass/piscript/type1.pdf
  23694. var PFB_HEADER_SIZE = 6;
  23695. var headerBlockLength = properties.length1;
  23696. var eexecBlockLength = properties.length2;
  23697. var pfbHeader = file.peekBytes(PFB_HEADER_SIZE);
  23698. var pfbHeaderPresent = pfbHeader[0] === 0x80 && pfbHeader[1] === 0x01;
  23699. if (pfbHeaderPresent) {
  23700. file.skip(PFB_HEADER_SIZE);
  23701. headerBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
  23702. (pfbHeader[3] << 8) | pfbHeader[2];
  23703. }
  23704. // Get the data block containing glyphs and subrs informations
  23705. var headerBlock = new Stream(file.getBytes(headerBlockLength));
  23706. var headerBlockParser = new Type1Parser(headerBlock);
  23707. headerBlockParser.extractFontHeader(properties);
  23708. if (pfbHeaderPresent) {
  23709. pfbHeader = file.getBytes(PFB_HEADER_SIZE);
  23710. eexecBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
  23711. (pfbHeader[3] << 8) | pfbHeader[2];
  23712. }
  23713. // Decrypt the data blocks and retrieve it's content
  23714. var eexecBlock = new Stream(file.getBytes(eexecBlockLength));
  23715. var eexecBlockParser = new Type1Parser(eexecBlock, true);
  23716. var data = eexecBlockParser.extractFontProgram();
  23717. for (var info in data.properties) {
  23718. properties[info] = data.properties[info];
  23719. }
  23720. var charstrings = data.charstrings;
  23721. var type2Charstrings = this.getType2Charstrings(charstrings);
  23722. var subrs = this.getType2Subrs(data.subrs);
  23723. this.charstrings = charstrings;
  23724. this.data = this.wrap(name, type2Charstrings, this.charstrings,
  23725. subrs, properties);
  23726. this.seacs = this.getSeacs(data.charstrings);
  23727. };
  23728. Type1Font.prototype = {
  23729. get numGlyphs() {
  23730. return this.charstrings.length + 1;
  23731. },
  23732. getCharset: function Type1Font_getCharset() {
  23733. var charset = ['.notdef'];
  23734. var charstrings = this.charstrings;
  23735. for (var glyphId = 0; glyphId < charstrings.length; glyphId++) {
  23736. charset.push(charstrings[glyphId].glyphName);
  23737. }
  23738. return charset;
  23739. },
  23740. getGlyphMapping: function Type1Font_getGlyphMapping(properties) {
  23741. var charstrings = this.charstrings;
  23742. var glyphNames = ['.notdef'], glyphId;
  23743. for (glyphId = 0; glyphId < charstrings.length; glyphId++) {
  23744. glyphNames.push(charstrings[glyphId].glyphName);
  23745. }
  23746. var encoding = properties.builtInEncoding;
  23747. if (encoding) {
  23748. var builtInEncoding = {};
  23749. for (var charCode in encoding) {
  23750. glyphId = glyphNames.indexOf(encoding[charCode]);
  23751. if (glyphId >= 0) {
  23752. builtInEncoding[charCode] = glyphId;
  23753. }
  23754. }
  23755. }
  23756. return type1FontGlyphMapping(properties, builtInEncoding, glyphNames);
  23757. },
  23758. getSeacs: function Type1Font_getSeacs(charstrings) {
  23759. var i, ii;
  23760. var seacMap = [];
  23761. for (i = 0, ii = charstrings.length; i < ii; i++) {
  23762. var charstring = charstrings[i];
  23763. if (charstring.seac) {
  23764. // Offset by 1 for .notdef
  23765. seacMap[i + 1] = charstring.seac;
  23766. }
  23767. }
  23768. return seacMap;
  23769. },
  23770. getType2Charstrings: function Type1Font_getType2Charstrings(
  23771. type1Charstrings) {
  23772. var type2Charstrings = [];
  23773. for (var i = 0, ii = type1Charstrings.length; i < ii; i++) {
  23774. type2Charstrings.push(type1Charstrings[i].charstring);
  23775. }
  23776. return type2Charstrings;
  23777. },
  23778. getType2Subrs: function Type1Font_getType2Subrs(type1Subrs) {
  23779. var bias = 0;
  23780. var count = type1Subrs.length;
  23781. if (count < 1133) {
  23782. bias = 107;
  23783. } else if (count < 33769) {
  23784. bias = 1131;
  23785. } else {
  23786. bias = 32768;
  23787. }
  23788. // Add a bunch of empty subrs to deal with the Type2 bias
  23789. var type2Subrs = [];
  23790. var i;
  23791. for (i = 0; i < bias; i++) {
  23792. type2Subrs.push([0x0B]);
  23793. }
  23794. for (i = 0; i < count; i++) {
  23795. type2Subrs.push(type1Subrs[i]);
  23796. }
  23797. return type2Subrs;
  23798. },
  23799. wrap: function Type1Font_wrap(name, glyphs, charstrings, subrs, properties) {
  23800. var cff = new CFF();
  23801. cff.header = new CFFHeader(1, 0, 4, 4);
  23802. cff.names = [name];
  23803. var topDict = new CFFTopDict();
  23804. // CFF strings IDs 0...390 are predefined names, so refering
  23805. // to entries in our own String INDEX starts at SID 391.
  23806. topDict.setByName('version', 391);
  23807. topDict.setByName('Notice', 392);
  23808. topDict.setByName('FullName', 393);
  23809. topDict.setByName('FamilyName', 394);
  23810. topDict.setByName('Weight', 395);
  23811. topDict.setByName('Encoding', null); // placeholder
  23812. topDict.setByName('FontMatrix', properties.fontMatrix);
  23813. topDict.setByName('FontBBox', properties.bbox);
  23814. topDict.setByName('charset', null); // placeholder
  23815. topDict.setByName('CharStrings', null); // placeholder
  23816. topDict.setByName('Private', null); // placeholder
  23817. cff.topDict = topDict;
  23818. var strings = new CFFStrings();
  23819. strings.add('Version 0.11'); // Version
  23820. strings.add('See original notice'); // Notice
  23821. strings.add(name); // FullName
  23822. strings.add(name); // FamilyName
  23823. strings.add('Medium'); // Weight
  23824. cff.strings = strings;
  23825. cff.globalSubrIndex = new CFFIndex();
  23826. var count = glyphs.length;
  23827. var charsetArray = [0];
  23828. var i, ii;
  23829. for (i = 0; i < count; i++) {
  23830. var index = CFFStandardStrings.indexOf(charstrings[i].glyphName);
  23831. // TODO: Insert the string and correctly map it. Previously it was
  23832. // thought mapping names that aren't in the standard strings to .notdef
  23833. // was fine, however in issue818 when mapping them all to .notdef the
  23834. // adieresis glyph no longer worked.
  23835. if (index === -1) {
  23836. index = 0;
  23837. }
  23838. charsetArray.push((index >> 8) & 0xff, index & 0xff);
  23839. }
  23840. cff.charset = new CFFCharset(false, 0, [], charsetArray);
  23841. var charStringsIndex = new CFFIndex();
  23842. charStringsIndex.add([0x8B, 0x0E]); // .notdef
  23843. for (i = 0; i < count; i++) {
  23844. charStringsIndex.add(glyphs[i]);
  23845. }
  23846. cff.charStrings = charStringsIndex;
  23847. var privateDict = new CFFPrivateDict();
  23848. privateDict.setByName('Subrs', null); // placeholder
  23849. var fields = [
  23850. 'BlueValues',
  23851. 'OtherBlues',
  23852. 'FamilyBlues',
  23853. 'FamilyOtherBlues',
  23854. 'StemSnapH',
  23855. 'StemSnapV',
  23856. 'BlueShift',
  23857. 'BlueFuzz',
  23858. 'BlueScale',
  23859. 'LanguageGroup',
  23860. 'ExpansionFactor',
  23861. 'ForceBold',
  23862. 'StdHW',
  23863. 'StdVW'
  23864. ];
  23865. for (i = 0, ii = fields.length; i < ii; i++) {
  23866. var field = fields[i];
  23867. if (!properties.privateData.hasOwnProperty(field)) {
  23868. continue;
  23869. }
  23870. var value = properties.privateData[field];
  23871. if (isArray(value)) {
  23872. // All of the private dictionary array data in CFF must be stored as
  23873. // "delta-encoded" numbers.
  23874. for (var j = value.length - 1; j > 0; j--) {
  23875. value[j] -= value[j - 1]; // ... difference from previous value
  23876. }
  23877. }
  23878. privateDict.setByName(field, value);
  23879. }
  23880. cff.topDict.privateDict = privateDict;
  23881. var subrIndex = new CFFIndex();
  23882. for (i = 0, ii = subrs.length; i < ii; i++) {
  23883. subrIndex.add(subrs[i]);
  23884. }
  23885. privateDict.subrsIndex = subrIndex;
  23886. var compiler = new CFFCompiler(cff);
  23887. return compiler.compile();
  23888. }
  23889. };
  23890. var CFFFont = (function CFFFontClosure() {
  23891. function CFFFont(file, properties) {
  23892. this.properties = properties;
  23893. var parser = new CFFParser(file, properties);
  23894. this.cff = parser.parse();
  23895. var compiler = new CFFCompiler(this.cff);
  23896. this.seacs = this.cff.seacs;
  23897. try {
  23898. this.data = compiler.compile();
  23899. } catch (e) {
  23900. warn('Failed to compile font ' + properties.loadedName);
  23901. // There may have just been an issue with the compiler, set the data
  23902. // anyway and hope the font loaded.
  23903. this.data = file;
  23904. }
  23905. }
  23906. CFFFont.prototype = {
  23907. get numGlyphs() {
  23908. return this.cff.charStrings.count;
  23909. },
  23910. getCharset: function CFFFont_getCharset() {
  23911. return this.cff.charset.charset;
  23912. },
  23913. getGlyphMapping: function CFFFont_getGlyphMapping() {
  23914. var cff = this.cff;
  23915. var properties = this.properties;
  23916. var charsets = cff.charset.charset;
  23917. var charCodeToGlyphId;
  23918. var glyphId;
  23919. if (properties.composite) {
  23920. charCodeToGlyphId = Object.create(null);
  23921. if (cff.isCIDFont) {
  23922. // If the font is actually a CID font then we should use the charset
  23923. // to map CIDs to GIDs.
  23924. for (glyphId = 0; glyphId < charsets.length; glyphId++) {
  23925. var cid = charsets[glyphId];
  23926. var charCode = properties.cMap.charCodeOf(cid);
  23927. charCodeToGlyphId[charCode] = glyphId;
  23928. }
  23929. } else {
  23930. // If it is NOT actually a CID font then CIDs should be mapped
  23931. // directly to GIDs.
  23932. for (glyphId = 0; glyphId < cff.charStrings.count; glyphId++) {
  23933. charCodeToGlyphId[glyphId] = glyphId;
  23934. }
  23935. }
  23936. return charCodeToGlyphId;
  23937. }
  23938. var encoding = cff.encoding ? cff.encoding.encoding : null;
  23939. charCodeToGlyphId = type1FontGlyphMapping(properties, encoding, charsets);
  23940. return charCodeToGlyphId;
  23941. }
  23942. };
  23943. return CFFFont;
  23944. })();
  23945. var CFFParser = (function CFFParserClosure() {
  23946. var CharstringValidationData = [
  23947. null,
  23948. { id: 'hstem', min: 2, stackClearing: true, stem: true },
  23949. null,
  23950. { id: 'vstem', min: 2, stackClearing: true, stem: true },
  23951. { id: 'vmoveto', min: 1, stackClearing: true },
  23952. { id: 'rlineto', min: 2, resetStack: true },
  23953. { id: 'hlineto', min: 1, resetStack: true },
  23954. { id: 'vlineto', min: 1, resetStack: true },
  23955. { id: 'rrcurveto', min: 6, resetStack: true },
  23956. null,
  23957. { id: 'callsubr', min: 1, undefStack: true },
  23958. { id: 'return', min: 0, undefStack: true },
  23959. null, // 12
  23960. null,
  23961. { id: 'endchar', min: 0, stackClearing: true },
  23962. null,
  23963. null,
  23964. null,
  23965. { id: 'hstemhm', min: 2, stackClearing: true, stem: true },
  23966. { id: 'hintmask', min: 0, stackClearing: true },
  23967. { id: 'cntrmask', min: 0, stackClearing: true },
  23968. { id: 'rmoveto', min: 2, stackClearing: true },
  23969. { id: 'hmoveto', min: 1, stackClearing: true },
  23970. { id: 'vstemhm', min: 2, stackClearing: true, stem: true },
  23971. { id: 'rcurveline', min: 8, resetStack: true },
  23972. { id: 'rlinecurve', min: 8, resetStack: true },
  23973. { id: 'vvcurveto', min: 4, resetStack: true },
  23974. { id: 'hhcurveto', min: 4, resetStack: true },
  23975. null, // shortint
  23976. { id: 'callgsubr', min: 1, undefStack: true },
  23977. { id: 'vhcurveto', min: 4, resetStack: true },
  23978. { id: 'hvcurveto', min: 4, resetStack: true }
  23979. ];
  23980. var CharstringValidationData12 = [
  23981. null,
  23982. null,
  23983. null,
  23984. { id: 'and', min: 2, stackDelta: -1 },
  23985. { id: 'or', min: 2, stackDelta: -1 },
  23986. { id: 'not', min: 1, stackDelta: 0 },
  23987. null,
  23988. null,
  23989. null,
  23990. { id: 'abs', min: 1, stackDelta: 0 },
  23991. { id: 'add', min: 2, stackDelta: -1,
  23992. stackFn: function stack_div(stack, index) {
  23993. stack[index - 2] = stack[index - 2] + stack[index - 1];
  23994. }
  23995. },
  23996. { id: 'sub', min: 2, stackDelta: -1,
  23997. stackFn: function stack_div(stack, index) {
  23998. stack[index - 2] = stack[index - 2] - stack[index - 1];
  23999. }
  24000. },
  24001. { id: 'div', min: 2, stackDelta: -1,
  24002. stackFn: function stack_div(stack, index) {
  24003. stack[index - 2] = stack[index - 2] / stack[index - 1];
  24004. }
  24005. },
  24006. null,
  24007. { id: 'neg', min: 1, stackDelta: 0,
  24008. stackFn: function stack_div(stack, index) {
  24009. stack[index - 1] = -stack[index - 1];
  24010. }
  24011. },
  24012. { id: 'eq', min: 2, stackDelta: -1 },
  24013. null,
  24014. null,
  24015. { id: 'drop', min: 1, stackDelta: -1 },
  24016. null,
  24017. { id: 'put', min: 2, stackDelta: -2 },
  24018. { id: 'get', min: 1, stackDelta: 0 },
  24019. { id: 'ifelse', min: 4, stackDelta: -3 },
  24020. { id: 'random', min: 0, stackDelta: 1 },
  24021. { id: 'mul', min: 2, stackDelta: -1,
  24022. stackFn: function stack_div(stack, index) {
  24023. stack[index - 2] = stack[index - 2] * stack[index - 1];
  24024. }
  24025. },
  24026. null,
  24027. { id: 'sqrt', min: 1, stackDelta: 0 },
  24028. { id: 'dup', min: 1, stackDelta: 1 },
  24029. { id: 'exch', min: 2, stackDelta: 0 },
  24030. { id: 'index', min: 2, stackDelta: 0 },
  24031. { id: 'roll', min: 3, stackDelta: -2 },
  24032. null,
  24033. null,
  24034. null,
  24035. { id: 'hflex', min: 7, resetStack: true },
  24036. { id: 'flex', min: 13, resetStack: true },
  24037. { id: 'hflex1', min: 9, resetStack: true },
  24038. { id: 'flex1', min: 11, resetStack: true }
  24039. ];
  24040. function CFFParser(file, properties) {
  24041. this.bytes = file.getBytes();
  24042. this.properties = properties;
  24043. }
  24044. CFFParser.prototype = {
  24045. parse: function CFFParser_parse() {
  24046. var properties = this.properties;
  24047. var cff = new CFF();
  24048. this.cff = cff;
  24049. // The first five sections must be in order, all the others are reached
  24050. // via offsets contained in one of the below.
  24051. var header = this.parseHeader();
  24052. var nameIndex = this.parseIndex(header.endPos);
  24053. var topDictIndex = this.parseIndex(nameIndex.endPos);
  24054. var stringIndex = this.parseIndex(topDictIndex.endPos);
  24055. var globalSubrIndex = this.parseIndex(stringIndex.endPos);
  24056. var topDictParsed = this.parseDict(topDictIndex.obj.get(0));
  24057. var topDict = this.createDict(CFFTopDict, topDictParsed, cff.strings);
  24058. cff.header = header.obj;
  24059. cff.names = this.parseNameIndex(nameIndex.obj);
  24060. cff.strings = this.parseStringIndex(stringIndex.obj);
  24061. cff.topDict = topDict;
  24062. cff.globalSubrIndex = globalSubrIndex.obj;
  24063. this.parsePrivateDict(cff.topDict);
  24064. cff.isCIDFont = topDict.hasName('ROS');
  24065. var charStringOffset = topDict.getByName('CharStrings');
  24066. var charStringsAndSeacs = this.parseCharStrings(charStringOffset);
  24067. cff.charStrings = charStringsAndSeacs.charStrings;
  24068. cff.seacs = charStringsAndSeacs.seacs;
  24069. cff.widths = charStringsAndSeacs.widths;
  24070. var fontMatrix = topDict.getByName('FontMatrix');
  24071. if (fontMatrix) {
  24072. properties.fontMatrix = fontMatrix;
  24073. }
  24074. var fontBBox = topDict.getByName('FontBBox');
  24075. if (fontBBox) {
  24076. // adjusting ascent/descent
  24077. properties.ascent = fontBBox[3];
  24078. properties.descent = fontBBox[1];
  24079. properties.ascentScaled = true;
  24080. }
  24081. var charset, encoding;
  24082. if (cff.isCIDFont) {
  24083. var fdArrayIndex = this.parseIndex(topDict.getByName('FDArray')).obj;
  24084. for (var i = 0, ii = fdArrayIndex.count; i < ii; ++i) {
  24085. var dictRaw = fdArrayIndex.get(i);
  24086. var fontDict = this.createDict(CFFTopDict, this.parseDict(dictRaw),
  24087. cff.strings);
  24088. this.parsePrivateDict(fontDict);
  24089. cff.fdArray.push(fontDict);
  24090. }
  24091. // cid fonts don't have an encoding
  24092. encoding = null;
  24093. charset = this.parseCharsets(topDict.getByName('charset'),
  24094. cff.charStrings.count, cff.strings, true);
  24095. cff.fdSelect = this.parseFDSelect(topDict.getByName('FDSelect'),
  24096. cff.charStrings.count);
  24097. } else {
  24098. charset = this.parseCharsets(topDict.getByName('charset'),
  24099. cff.charStrings.count, cff.strings, false);
  24100. encoding = this.parseEncoding(topDict.getByName('Encoding'),
  24101. properties,
  24102. cff.strings, charset.charset);
  24103. }
  24104. cff.charset = charset;
  24105. cff.encoding = encoding;
  24106. return cff;
  24107. },
  24108. parseHeader: function CFFParser_parseHeader() {
  24109. var bytes = this.bytes;
  24110. var bytesLength = bytes.length;
  24111. var offset = 0;
  24112. // Prevent an infinite loop, by checking that the offset is within the
  24113. // bounds of the bytes array. Necessary in empty, or invalid, font files.
  24114. while (offset < bytesLength && bytes[offset] !== 1) {
  24115. ++offset;
  24116. }
  24117. if (offset >= bytesLength) {
  24118. error('Invalid CFF header');
  24119. } else if (offset !== 0) {
  24120. info('cff data is shifted');
  24121. bytes = bytes.subarray(offset);
  24122. this.bytes = bytes;
  24123. }
  24124. var major = bytes[0];
  24125. var minor = bytes[1];
  24126. var hdrSize = bytes[2];
  24127. var offSize = bytes[3];
  24128. var header = new CFFHeader(major, minor, hdrSize, offSize);
  24129. return { obj: header, endPos: hdrSize };
  24130. },
  24131. parseDict: function CFFParser_parseDict(dict) {
  24132. var pos = 0;
  24133. function parseOperand() {
  24134. var value = dict[pos++];
  24135. if (value === 30) {
  24136. return parseFloatOperand(pos);
  24137. } else if (value === 28) {
  24138. value = dict[pos++];
  24139. value = ((value << 24) | (dict[pos++] << 16)) >> 16;
  24140. return value;
  24141. } else if (value === 29) {
  24142. value = dict[pos++];
  24143. value = (value << 8) | dict[pos++];
  24144. value = (value << 8) | dict[pos++];
  24145. value = (value << 8) | dict[pos++];
  24146. return value;
  24147. } else if (value >= 32 && value <= 246) {
  24148. return value - 139;
  24149. } else if (value >= 247 && value <= 250) {
  24150. return ((value - 247) * 256) + dict[pos++] + 108;
  24151. } else if (value >= 251 && value <= 254) {
  24152. return -((value - 251) * 256) - dict[pos++] - 108;
  24153. } else {
  24154. error('255 is not a valid DICT command');
  24155. }
  24156. return -1;
  24157. }
  24158. function parseFloatOperand() {
  24159. var str = '';
  24160. var eof = 15;
  24161. var lookup = ['0', '1', '2', '3', '4', '5', '6', '7', '8',
  24162. '9', '.', 'E', 'E-', null, '-'];
  24163. var length = dict.length;
  24164. while (pos < length) {
  24165. var b = dict[pos++];
  24166. var b1 = b >> 4;
  24167. var b2 = b & 15;
  24168. if (b1 === eof) {
  24169. break;
  24170. }
  24171. str += lookup[b1];
  24172. if (b2 === eof) {
  24173. break;
  24174. }
  24175. str += lookup[b2];
  24176. }
  24177. return parseFloat(str);
  24178. }
  24179. var operands = [];
  24180. var entries = [];
  24181. pos = 0;
  24182. var end = dict.length;
  24183. while (pos < end) {
  24184. var b = dict[pos];
  24185. if (b <= 21) {
  24186. if (b === 12) {
  24187. b = (b << 8) | dict[++pos];
  24188. }
  24189. entries.push([b, operands]);
  24190. operands = [];
  24191. ++pos;
  24192. } else {
  24193. operands.push(parseOperand());
  24194. }
  24195. }
  24196. return entries;
  24197. },
  24198. parseIndex: function CFFParser_parseIndex(pos) {
  24199. var cffIndex = new CFFIndex();
  24200. var bytes = this.bytes;
  24201. var count = (bytes[pos++] << 8) | bytes[pos++];
  24202. var offsets = [];
  24203. var end = pos;
  24204. var i, ii;
  24205. if (count !== 0) {
  24206. var offsetSize = bytes[pos++];
  24207. // add 1 for offset to determine size of last object
  24208. var startPos = pos + ((count + 1) * offsetSize) - 1;
  24209. for (i = 0, ii = count + 1; i < ii; ++i) {
  24210. var offset = 0;
  24211. for (var j = 0; j < offsetSize; ++j) {
  24212. offset <<= 8;
  24213. offset += bytes[pos++];
  24214. }
  24215. offsets.push(startPos + offset);
  24216. }
  24217. end = offsets[count];
  24218. }
  24219. for (i = 0, ii = offsets.length - 1; i < ii; ++i) {
  24220. var offsetStart = offsets[i];
  24221. var offsetEnd = offsets[i + 1];
  24222. cffIndex.add(bytes.subarray(offsetStart, offsetEnd));
  24223. }
  24224. return {obj: cffIndex, endPos: end};
  24225. },
  24226. parseNameIndex: function CFFParser_parseNameIndex(index) {
  24227. var names = [];
  24228. for (var i = 0, ii = index.count; i < ii; ++i) {
  24229. var name = index.get(i);
  24230. // OTS doesn't allow names to be over 127 characters.
  24231. var length = Math.min(name.length, 127);
  24232. var data = [];
  24233. // OTS also only permits certain characters in the name.
  24234. for (var j = 0; j < length; ++j) {
  24235. var c = name[j];
  24236. if (j === 0 && c === 0) {
  24237. data[j] = c;
  24238. continue;
  24239. }
  24240. if ((c < 33 || c > 126) || c === 91 /* [ */ || c === 93 /* ] */ ||
  24241. c === 40 /* ( */ || c === 41 /* ) */ || c === 123 /* { */ ||
  24242. c === 125 /* } */ || c === 60 /* < */ || c === 62 /* > */ ||
  24243. c === 47 /* / */ || c === 37 /* % */ || c === 35 /* # */) {
  24244. data[j] = 95;
  24245. continue;
  24246. }
  24247. data[j] = c;
  24248. }
  24249. names.push(bytesToString(data));
  24250. }
  24251. return names;
  24252. },
  24253. parseStringIndex: function CFFParser_parseStringIndex(index) {
  24254. var strings = new CFFStrings();
  24255. for (var i = 0, ii = index.count; i < ii; ++i) {
  24256. var data = index.get(i);
  24257. strings.add(bytesToString(data));
  24258. }
  24259. return strings;
  24260. },
  24261. createDict: function CFFParser_createDict(Type, dict, strings) {
  24262. var cffDict = new Type(strings);
  24263. for (var i = 0, ii = dict.length; i < ii; ++i) {
  24264. var pair = dict[i];
  24265. var key = pair[0];
  24266. var value = pair[1];
  24267. cffDict.setByKey(key, value);
  24268. }
  24269. return cffDict;
  24270. },
  24271. parseCharStrings: function CFFParser_parseCharStrings(charStringOffset) {
  24272. var charStrings = this.parseIndex(charStringOffset).obj;
  24273. var seacs = [];
  24274. var widths = [];
  24275. var count = charStrings.count;
  24276. for (var i = 0; i < count; i++) {
  24277. var charstring = charStrings.get(i);
  24278. var stackSize = 0;
  24279. var stack = [];
  24280. var undefStack = true;
  24281. var hints = 0;
  24282. var valid = true;
  24283. var data = charstring;
  24284. var length = data.length;
  24285. var firstStackClearing = true;
  24286. for (var j = 0; j < length;) {
  24287. var value = data[j++];
  24288. var validationCommand = null;
  24289. if (value === 12) {
  24290. var q = data[j++];
  24291. if (q === 0) {
  24292. // The CFF specification state that the 'dotsection' command
  24293. // (12, 0) is deprecated and treated as a no-op, but all Type2
  24294. // charstrings processors should support them. Unfortunately
  24295. // the font sanitizer don't. As a workaround the sequence (12, 0)
  24296. // is replaced by a useless (0, hmoveto).
  24297. data[j - 2] = 139;
  24298. data[j - 1] = 22;
  24299. stackSize = 0;
  24300. } else {
  24301. validationCommand = CharstringValidationData12[q];
  24302. }
  24303. } else if (value === 28) { // number (16 bit)
  24304. stack[stackSize] = ((data[j] << 24) | (data[j + 1] << 16)) >> 16;
  24305. j += 2;
  24306. stackSize++;
  24307. } else if (value === 14) {
  24308. if (stackSize >= 4) {
  24309. stackSize -= 4;
  24310. if (SEAC_ANALYSIS_ENABLED) {
  24311. seacs[i] = stack.slice(stackSize, stackSize + 4);
  24312. valid = false;
  24313. }
  24314. }
  24315. validationCommand = CharstringValidationData[value];
  24316. } else if (value >= 32 && value <= 246) { // number
  24317. stack[stackSize] = value - 139;
  24318. stackSize++;
  24319. } else if (value >= 247 && value <= 254) { // number (+1 bytes)
  24320. stack[stackSize] = (value < 251 ?
  24321. ((value - 247) << 8) + data[j] + 108 :
  24322. -((value - 251) << 8) - data[j] - 108);
  24323. j++;
  24324. stackSize++;
  24325. } else if (value === 255) { // number (32 bit)
  24326. stack[stackSize] = ((data[j] << 24) | (data[j + 1] << 16) |
  24327. (data[j + 2] << 8) | data[j + 3]) / 65536;
  24328. j += 4;
  24329. stackSize++;
  24330. } else if (value === 19 || value === 20) {
  24331. hints += stackSize >> 1;
  24332. j += (hints + 7) >> 3; // skipping right amount of hints flag data
  24333. stackSize %= 2;
  24334. validationCommand = CharstringValidationData[value];
  24335. } else {
  24336. validationCommand = CharstringValidationData[value];
  24337. }
  24338. if (validationCommand) {
  24339. if (validationCommand.stem) {
  24340. hints += stackSize >> 1;
  24341. }
  24342. if ('min' in validationCommand) {
  24343. if (!undefStack && stackSize < validationCommand.min) {
  24344. warn('Not enough parameters for ' + validationCommand.id +
  24345. '; actual: ' + stackSize +
  24346. ', expected: ' + validationCommand.min);
  24347. valid = false;
  24348. break;
  24349. }
  24350. }
  24351. if (firstStackClearing && validationCommand.stackClearing) {
  24352. firstStackClearing = false;
  24353. // the optional character width can be found before the first
  24354. // stack-clearing command arguments
  24355. stackSize -= validationCommand.min;
  24356. if (stackSize >= 2 && validationCommand.stem) {
  24357. // there are even amount of arguments for stem commands
  24358. stackSize %= 2;
  24359. } else if (stackSize > 1) {
  24360. warn('Found too many parameters for stack-clearing command');
  24361. }
  24362. if (stackSize > 0 && stack[stackSize - 1] >= 0) {
  24363. widths[i] = stack[stackSize - 1];
  24364. }
  24365. }
  24366. if ('stackDelta' in validationCommand) {
  24367. if ('stackFn' in validationCommand) {
  24368. validationCommand.stackFn(stack, stackSize);
  24369. }
  24370. stackSize += validationCommand.stackDelta;
  24371. } else if (validationCommand.stackClearing) {
  24372. stackSize = 0;
  24373. } else if (validationCommand.resetStack) {
  24374. stackSize = 0;
  24375. undefStack = false;
  24376. } else if (validationCommand.undefStack) {
  24377. stackSize = 0;
  24378. undefStack = true;
  24379. firstStackClearing = false;
  24380. }
  24381. }
  24382. }
  24383. if (!valid) {
  24384. // resetting invalid charstring to single 'endchar'
  24385. charStrings.set(i, new Uint8Array([14]));
  24386. }
  24387. }
  24388. return { charStrings: charStrings, seacs: seacs, widths: widths };
  24389. },
  24390. emptyPrivateDictionary:
  24391. function CFFParser_emptyPrivateDictionary(parentDict) {
  24392. var privateDict = this.createDict(CFFPrivateDict, [],
  24393. parentDict.strings);
  24394. parentDict.setByKey(18, [0, 0]);
  24395. parentDict.privateDict = privateDict;
  24396. },
  24397. parsePrivateDict: function CFFParser_parsePrivateDict(parentDict) {
  24398. // no private dict, do nothing
  24399. if (!parentDict.hasName('Private')) {
  24400. this.emptyPrivateDictionary(parentDict);
  24401. return;
  24402. }
  24403. var privateOffset = parentDict.getByName('Private');
  24404. // make sure the params are formatted correctly
  24405. if (!isArray(privateOffset) || privateOffset.length !== 2) {
  24406. parentDict.removeByName('Private');
  24407. return;
  24408. }
  24409. var size = privateOffset[0];
  24410. var offset = privateOffset[1];
  24411. // remove empty dicts or ones that refer to invalid location
  24412. if (size === 0 || offset >= this.bytes.length) {
  24413. this.emptyPrivateDictionary(parentDict);
  24414. return;
  24415. }
  24416. var privateDictEnd = offset + size;
  24417. var dictData = this.bytes.subarray(offset, privateDictEnd);
  24418. var dict = this.parseDict(dictData);
  24419. var privateDict = this.createDict(CFFPrivateDict, dict,
  24420. parentDict.strings);
  24421. parentDict.privateDict = privateDict;
  24422. // Parse the Subrs index also since it's relative to the private dict.
  24423. if (!privateDict.getByName('Subrs')) {
  24424. return;
  24425. }
  24426. var subrsOffset = privateDict.getByName('Subrs');
  24427. var relativeOffset = offset + subrsOffset;
  24428. // Validate the offset.
  24429. if (subrsOffset === 0 || relativeOffset >= this.bytes.length) {
  24430. this.emptyPrivateDictionary(parentDict);
  24431. return;
  24432. }
  24433. var subrsIndex = this.parseIndex(relativeOffset);
  24434. privateDict.subrsIndex = subrsIndex.obj;
  24435. },
  24436. parseCharsets: function CFFParser_parseCharsets(pos, length, strings, cid) {
  24437. if (pos === 0) {
  24438. return new CFFCharset(true, CFFCharsetPredefinedTypes.ISO_ADOBE,
  24439. ISOAdobeCharset);
  24440. } else if (pos === 1) {
  24441. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT,
  24442. ExpertCharset);
  24443. } else if (pos === 2) {
  24444. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT_SUBSET,
  24445. ExpertSubsetCharset);
  24446. }
  24447. var bytes = this.bytes;
  24448. var start = pos;
  24449. var format = bytes[pos++];
  24450. var charset = ['.notdef'];
  24451. var id, count, i;
  24452. // subtract 1 for the .notdef glyph
  24453. length -= 1;
  24454. switch (format) {
  24455. case 0:
  24456. for (i = 0; i < length; i++) {
  24457. id = (bytes[pos++] << 8) | bytes[pos++];
  24458. charset.push(cid ? id : strings.get(id));
  24459. }
  24460. break;
  24461. case 1:
  24462. while (charset.length <= length) {
  24463. id = (bytes[pos++] << 8) | bytes[pos++];
  24464. count = bytes[pos++];
  24465. for (i = 0; i <= count; i++) {
  24466. charset.push(cid ? id++ : strings.get(id++));
  24467. }
  24468. }
  24469. break;
  24470. case 2:
  24471. while (charset.length <= length) {
  24472. id = (bytes[pos++] << 8) | bytes[pos++];
  24473. count = (bytes[pos++] << 8) | bytes[pos++];
  24474. for (i = 0; i <= count; i++) {
  24475. charset.push(cid ? id++ : strings.get(id++));
  24476. }
  24477. }
  24478. break;
  24479. default:
  24480. error('Unknown charset format');
  24481. }
  24482. // Raw won't be needed if we actually compile the charset.
  24483. var end = pos;
  24484. var raw = bytes.subarray(start, end);
  24485. return new CFFCharset(false, format, charset, raw);
  24486. },
  24487. parseEncoding: function CFFParser_parseEncoding(pos,
  24488. properties,
  24489. strings,
  24490. charset) {
  24491. var encoding = {};
  24492. var bytes = this.bytes;
  24493. var predefined = false;
  24494. var hasSupplement = false;
  24495. var format, i, ii;
  24496. var raw = null;
  24497. function readSupplement() {
  24498. var supplementsCount = bytes[pos++];
  24499. for (i = 0; i < supplementsCount; i++) {
  24500. var code = bytes[pos++];
  24501. var sid = (bytes[pos++] << 8) + (bytes[pos++] & 0xff);
  24502. encoding[code] = charset.indexOf(strings.get(sid));
  24503. }
  24504. }
  24505. if (pos === 0 || pos === 1) {
  24506. predefined = true;
  24507. format = pos;
  24508. var baseEncoding = pos ? Encodings.ExpertEncoding :
  24509. Encodings.StandardEncoding;
  24510. for (i = 0, ii = charset.length; i < ii; i++) {
  24511. var index = baseEncoding.indexOf(charset[i]);
  24512. if (index !== -1) {
  24513. encoding[index] = i;
  24514. }
  24515. }
  24516. } else {
  24517. var dataStart = pos;
  24518. format = bytes[pos++];
  24519. switch (format & 0x7f) {
  24520. case 0:
  24521. var glyphsCount = bytes[pos++];
  24522. for (i = 1; i <= glyphsCount; i++) {
  24523. encoding[bytes[pos++]] = i;
  24524. }
  24525. break;
  24526. case 1:
  24527. var rangesCount = bytes[pos++];
  24528. var gid = 1;
  24529. for (i = 0; i < rangesCount; i++) {
  24530. var start = bytes[pos++];
  24531. var left = bytes[pos++];
  24532. for (var j = start; j <= start + left; j++) {
  24533. encoding[j] = gid++;
  24534. }
  24535. }
  24536. break;
  24537. default:
  24538. error('Unknow encoding format: ' + format + ' in CFF');
  24539. break;
  24540. }
  24541. var dataEnd = pos;
  24542. if (format & 0x80) {
  24543. // The font sanitizer does not support CFF encoding with a
  24544. // supplement, since the encoding is not really used to map
  24545. // between gid to glyph, let's overwrite what is declared in
  24546. // the top dictionary to let the sanitizer think the font use
  24547. // StandardEncoding, that's a lie but that's ok.
  24548. bytes[dataStart] &= 0x7f;
  24549. readSupplement();
  24550. hasSupplement = true;
  24551. }
  24552. raw = bytes.subarray(dataStart, dataEnd);
  24553. }
  24554. format = format & 0x7f;
  24555. return new CFFEncoding(predefined, format, encoding, raw);
  24556. },
  24557. parseFDSelect: function CFFParser_parseFDSelect(pos, length) {
  24558. var start = pos;
  24559. var bytes = this.bytes;
  24560. var format = bytes[pos++];
  24561. var fdSelect = [];
  24562. var i;
  24563. switch (format) {
  24564. case 0:
  24565. for (i = 0; i < length; ++i) {
  24566. var id = bytes[pos++];
  24567. fdSelect.push(id);
  24568. }
  24569. break;
  24570. case 3:
  24571. var rangesCount = (bytes[pos++] << 8) | bytes[pos++];
  24572. for (i = 0; i < rangesCount; ++i) {
  24573. var first = (bytes[pos++] << 8) | bytes[pos++];
  24574. var fdIndex = bytes[pos++];
  24575. var next = (bytes[pos] << 8) | bytes[pos + 1];
  24576. for (var j = first; j < next; ++j) {
  24577. fdSelect.push(fdIndex);
  24578. }
  24579. }
  24580. // Advance past the sentinel(next).
  24581. pos += 2;
  24582. break;
  24583. default:
  24584. error('Unknown fdselect format ' + format);
  24585. break;
  24586. }
  24587. var end = pos;
  24588. return new CFFFDSelect(fdSelect, bytes.subarray(start, end));
  24589. }
  24590. };
  24591. return CFFParser;
  24592. })();
  24593. // Compact Font Format
  24594. var CFF = (function CFFClosure() {
  24595. function CFF() {
  24596. this.header = null;
  24597. this.names = [];
  24598. this.topDict = null;
  24599. this.strings = new CFFStrings();
  24600. this.globalSubrIndex = null;
  24601. // The following could really be per font, but since we only have one font
  24602. // store them here.
  24603. this.encoding = null;
  24604. this.charset = null;
  24605. this.charStrings = null;
  24606. this.fdArray = [];
  24607. this.fdSelect = null;
  24608. this.isCIDFont = false;
  24609. }
  24610. return CFF;
  24611. })();
  24612. var CFFHeader = (function CFFHeaderClosure() {
  24613. function CFFHeader(major, minor, hdrSize, offSize) {
  24614. this.major = major;
  24615. this.minor = minor;
  24616. this.hdrSize = hdrSize;
  24617. this.offSize = offSize;
  24618. }
  24619. return CFFHeader;
  24620. })();
  24621. var CFFStrings = (function CFFStringsClosure() {
  24622. function CFFStrings() {
  24623. this.strings = [];
  24624. }
  24625. CFFStrings.prototype = {
  24626. get: function CFFStrings_get(index) {
  24627. if (index >= 0 && index <= 390) {
  24628. return CFFStandardStrings[index];
  24629. }
  24630. if (index - 391 <= this.strings.length) {
  24631. return this.strings[index - 391];
  24632. }
  24633. return CFFStandardStrings[0];
  24634. },
  24635. add: function CFFStrings_add(value) {
  24636. this.strings.push(value);
  24637. },
  24638. get count() {
  24639. return this.strings.length;
  24640. }
  24641. };
  24642. return CFFStrings;
  24643. })();
  24644. var CFFIndex = (function CFFIndexClosure() {
  24645. function CFFIndex() {
  24646. this.objects = [];
  24647. this.length = 0;
  24648. }
  24649. CFFIndex.prototype = {
  24650. add: function CFFIndex_add(data) {
  24651. this.length += data.length;
  24652. this.objects.push(data);
  24653. },
  24654. set: function CFFIndex_set(index, data) {
  24655. this.length += data.length - this.objects[index].length;
  24656. this.objects[index] = data;
  24657. },
  24658. get: function CFFIndex_get(index) {
  24659. return this.objects[index];
  24660. },
  24661. get count() {
  24662. return this.objects.length;
  24663. }
  24664. };
  24665. return CFFIndex;
  24666. })();
  24667. var CFFDict = (function CFFDictClosure() {
  24668. function CFFDict(tables, strings) {
  24669. this.keyToNameMap = tables.keyToNameMap;
  24670. this.nameToKeyMap = tables.nameToKeyMap;
  24671. this.defaults = tables.defaults;
  24672. this.types = tables.types;
  24673. this.opcodes = tables.opcodes;
  24674. this.order = tables.order;
  24675. this.strings = strings;
  24676. this.values = {};
  24677. }
  24678. CFFDict.prototype = {
  24679. // value should always be an array
  24680. setByKey: function CFFDict_setByKey(key, value) {
  24681. if (!(key in this.keyToNameMap)) {
  24682. return false;
  24683. }
  24684. // ignore empty values
  24685. if (value.length === 0) {
  24686. return true;
  24687. }
  24688. var type = this.types[key];
  24689. // remove the array wrapping these types of values
  24690. if (type === 'num' || type === 'sid' || type === 'offset') {
  24691. value = value[0];
  24692. }
  24693. this.values[key] = value;
  24694. return true;
  24695. },
  24696. setByName: function CFFDict_setByName(name, value) {
  24697. if (!(name in this.nameToKeyMap)) {
  24698. error('Invalid dictionary name "' + name + '"');
  24699. }
  24700. this.values[this.nameToKeyMap[name]] = value;
  24701. },
  24702. hasName: function CFFDict_hasName(name) {
  24703. return this.nameToKeyMap[name] in this.values;
  24704. },
  24705. getByName: function CFFDict_getByName(name) {
  24706. if (!(name in this.nameToKeyMap)) {
  24707. error('Invalid dictionary name "' + name + '"');
  24708. }
  24709. var key = this.nameToKeyMap[name];
  24710. if (!(key in this.values)) {
  24711. return this.defaults[key];
  24712. }
  24713. return this.values[key];
  24714. },
  24715. removeByName: function CFFDict_removeByName(name) {
  24716. delete this.values[this.nameToKeyMap[name]];
  24717. }
  24718. };
  24719. CFFDict.createTables = function CFFDict_createTables(layout) {
  24720. var tables = {
  24721. keyToNameMap: {},
  24722. nameToKeyMap: {},
  24723. defaults: {},
  24724. types: {},
  24725. opcodes: {},
  24726. order: []
  24727. };
  24728. for (var i = 0, ii = layout.length; i < ii; ++i) {
  24729. var entry = layout[i];
  24730. var key = isArray(entry[0]) ? (entry[0][0] << 8) + entry[0][1] : entry[0];
  24731. tables.keyToNameMap[key] = entry[1];
  24732. tables.nameToKeyMap[entry[1]] = key;
  24733. tables.types[key] = entry[2];
  24734. tables.defaults[key] = entry[3];
  24735. tables.opcodes[key] = isArray(entry[0]) ? entry[0] : [entry[0]];
  24736. tables.order.push(key);
  24737. }
  24738. return tables;
  24739. };
  24740. return CFFDict;
  24741. })();
  24742. var CFFTopDict = (function CFFTopDictClosure() {
  24743. var layout = [
  24744. [[12, 30], 'ROS', ['sid', 'sid', 'num'], null],
  24745. [[12, 20], 'SyntheticBase', 'num', null],
  24746. [0, 'version', 'sid', null],
  24747. [1, 'Notice', 'sid', null],
  24748. [[12, 0], 'Copyright', 'sid', null],
  24749. [2, 'FullName', 'sid', null],
  24750. [3, 'FamilyName', 'sid', null],
  24751. [4, 'Weight', 'sid', null],
  24752. [[12, 1], 'isFixedPitch', 'num', 0],
  24753. [[12, 2], 'ItalicAngle', 'num', 0],
  24754. [[12, 3], 'UnderlinePosition', 'num', -100],
  24755. [[12, 4], 'UnderlineThickness', 'num', 50],
  24756. [[12, 5], 'PaintType', 'num', 0],
  24757. [[12, 6], 'CharstringType', 'num', 2],
  24758. [[12, 7], 'FontMatrix', ['num', 'num', 'num', 'num', 'num', 'num'],
  24759. [0.001, 0, 0, 0.001, 0, 0]],
  24760. [13, 'UniqueID', 'num', null],
  24761. [5, 'FontBBox', ['num', 'num', 'num', 'num'], [0, 0, 0, 0]],
  24762. [[12, 8], 'StrokeWidth', 'num', 0],
  24763. [14, 'XUID', 'array', null],
  24764. [15, 'charset', 'offset', 0],
  24765. [16, 'Encoding', 'offset', 0],
  24766. [17, 'CharStrings', 'offset', 0],
  24767. [18, 'Private', ['offset', 'offset'], null],
  24768. [[12, 21], 'PostScript', 'sid', null],
  24769. [[12, 22], 'BaseFontName', 'sid', null],
  24770. [[12, 23], 'BaseFontBlend', 'delta', null],
  24771. [[12, 31], 'CIDFontVersion', 'num', 0],
  24772. [[12, 32], 'CIDFontRevision', 'num', 0],
  24773. [[12, 33], 'CIDFontType', 'num', 0],
  24774. [[12, 34], 'CIDCount', 'num', 8720],
  24775. [[12, 35], 'UIDBase', 'num', null],
  24776. // XXX: CID Fonts on DirectWrite 6.1 only seem to work if FDSelect comes
  24777. // before FDArray.
  24778. [[12, 37], 'FDSelect', 'offset', null],
  24779. [[12, 36], 'FDArray', 'offset', null],
  24780. [[12, 38], 'FontName', 'sid', null]
  24781. ];
  24782. var tables = null;
  24783. function CFFTopDict(strings) {
  24784. if (tables === null) {
  24785. tables = CFFDict.createTables(layout);
  24786. }
  24787. CFFDict.call(this, tables, strings);
  24788. this.privateDict = null;
  24789. }
  24790. CFFTopDict.prototype = Object.create(CFFDict.prototype);
  24791. return CFFTopDict;
  24792. })();
  24793. var CFFPrivateDict = (function CFFPrivateDictClosure() {
  24794. var layout = [
  24795. [6, 'BlueValues', 'delta', null],
  24796. [7, 'OtherBlues', 'delta', null],
  24797. [8, 'FamilyBlues', 'delta', null],
  24798. [9, 'FamilyOtherBlues', 'delta', null],
  24799. [[12, 9], 'BlueScale', 'num', 0.039625],
  24800. [[12, 10], 'BlueShift', 'num', 7],
  24801. [[12, 11], 'BlueFuzz', 'num', 1],
  24802. [10, 'StdHW', 'num', null],
  24803. [11, 'StdVW', 'num', null],
  24804. [[12, 12], 'StemSnapH', 'delta', null],
  24805. [[12, 13], 'StemSnapV', 'delta', null],
  24806. [[12, 14], 'ForceBold', 'num', 0],
  24807. [[12, 17], 'LanguageGroup', 'num', 0],
  24808. [[12, 18], 'ExpansionFactor', 'num', 0.06],
  24809. [[12, 19], 'initialRandomSeed', 'num', 0],
  24810. [20, 'defaultWidthX', 'num', 0],
  24811. [21, 'nominalWidthX', 'num', 0],
  24812. [19, 'Subrs', 'offset', null]
  24813. ];
  24814. var tables = null;
  24815. function CFFPrivateDict(strings) {
  24816. if (tables === null) {
  24817. tables = CFFDict.createTables(layout);
  24818. }
  24819. CFFDict.call(this, tables, strings);
  24820. this.subrsIndex = null;
  24821. }
  24822. CFFPrivateDict.prototype = Object.create(CFFDict.prototype);
  24823. return CFFPrivateDict;
  24824. })();
  24825. var CFFCharsetPredefinedTypes = {
  24826. ISO_ADOBE: 0,
  24827. EXPERT: 1,
  24828. EXPERT_SUBSET: 2
  24829. };
  24830. var CFFCharset = (function CFFCharsetClosure() {
  24831. function CFFCharset(predefined, format, charset, raw) {
  24832. this.predefined = predefined;
  24833. this.format = format;
  24834. this.charset = charset;
  24835. this.raw = raw;
  24836. }
  24837. return CFFCharset;
  24838. })();
  24839. var CFFEncoding = (function CFFEncodingClosure() {
  24840. function CFFEncoding(predefined, format, encoding, raw) {
  24841. this.predefined = predefined;
  24842. this.format = format;
  24843. this.encoding = encoding;
  24844. this.raw = raw;
  24845. }
  24846. return CFFEncoding;
  24847. })();
  24848. var CFFFDSelect = (function CFFFDSelectClosure() {
  24849. function CFFFDSelect(fdSelect, raw) {
  24850. this.fdSelect = fdSelect;
  24851. this.raw = raw;
  24852. }
  24853. return CFFFDSelect;
  24854. })();
  24855. // Helper class to keep track of where an offset is within the data and helps
  24856. // filling in that offset once it's known.
  24857. var CFFOffsetTracker = (function CFFOffsetTrackerClosure() {
  24858. function CFFOffsetTracker() {
  24859. this.offsets = {};
  24860. }
  24861. CFFOffsetTracker.prototype = {
  24862. isTracking: function CFFOffsetTracker_isTracking(key) {
  24863. return key in this.offsets;
  24864. },
  24865. track: function CFFOffsetTracker_track(key, location) {
  24866. if (key in this.offsets) {
  24867. error('Already tracking location of ' + key);
  24868. }
  24869. this.offsets[key] = location;
  24870. },
  24871. offset: function CFFOffsetTracker_offset(value) {
  24872. for (var key in this.offsets) {
  24873. this.offsets[key] += value;
  24874. }
  24875. },
  24876. setEntryLocation: function CFFOffsetTracker_setEntryLocation(key,
  24877. values,
  24878. output) {
  24879. if (!(key in this.offsets)) {
  24880. error('Not tracking location of ' + key);
  24881. }
  24882. var data = output.data;
  24883. var dataOffset = this.offsets[key];
  24884. var size = 5;
  24885. for (var i = 0, ii = values.length; i < ii; ++i) {
  24886. var offset0 = i * size + dataOffset;
  24887. var offset1 = offset0 + 1;
  24888. var offset2 = offset0 + 2;
  24889. var offset3 = offset0 + 3;
  24890. var offset4 = offset0 + 4;
  24891. // It's easy to screw up offsets so perform this sanity check.
  24892. if (data[offset0] !== 0x1d || data[offset1] !== 0 ||
  24893. data[offset2] !== 0 || data[offset3] !== 0 || data[offset4] !== 0) {
  24894. error('writing to an offset that is not empty');
  24895. }
  24896. var value = values[i];
  24897. data[offset0] = 0x1d;
  24898. data[offset1] = (value >> 24) & 0xFF;
  24899. data[offset2] = (value >> 16) & 0xFF;
  24900. data[offset3] = (value >> 8) & 0xFF;
  24901. data[offset4] = value & 0xFF;
  24902. }
  24903. }
  24904. };
  24905. return CFFOffsetTracker;
  24906. })();
  24907. // Takes a CFF and converts it to the binary representation.
  24908. var CFFCompiler = (function CFFCompilerClosure() {
  24909. function CFFCompiler(cff) {
  24910. this.cff = cff;
  24911. }
  24912. CFFCompiler.prototype = {
  24913. compile: function CFFCompiler_compile() {
  24914. var cff = this.cff;
  24915. var output = {
  24916. data: [],
  24917. length: 0,
  24918. add: function CFFCompiler_add(data) {
  24919. this.data = this.data.concat(data);
  24920. this.length = this.data.length;
  24921. }
  24922. };
  24923. // Compile the five entries that must be in order.
  24924. var header = this.compileHeader(cff.header);
  24925. output.add(header);
  24926. var nameIndex = this.compileNameIndex(cff.names);
  24927. output.add(nameIndex);
  24928. if (cff.isCIDFont) {
  24929. // The spec is unclear on how font matrices should relate to each other
  24930. // when there is one in the main top dict and the sub top dicts.
  24931. // Windows handles this differently than linux and osx so we have to
  24932. // normalize to work on all.
  24933. // Rules based off of some mailing list discussions:
  24934. // - If main font has a matrix and subfont doesn't, use the main matrix.
  24935. // - If no main font matrix and there is a subfont matrix, use the
  24936. // subfont matrix.
  24937. // - If both have matrices, concat together.
  24938. // - If neither have matrices, use default.
  24939. // To make this work on all platforms we move the top matrix into each
  24940. // sub top dict and concat if necessary.
  24941. if (cff.topDict.hasName('FontMatrix')) {
  24942. var base = cff.topDict.getByName('FontMatrix');
  24943. cff.topDict.removeByName('FontMatrix');
  24944. for (var i = 0, ii = cff.fdArray.length; i < ii; i++) {
  24945. var subDict = cff.fdArray[i];
  24946. var matrix = base.slice(0);
  24947. if (subDict.hasName('FontMatrix')) {
  24948. matrix = Util.transform(matrix, subDict.getByName('FontMatrix'));
  24949. }
  24950. subDict.setByName('FontMatrix', matrix);
  24951. }
  24952. }
  24953. }
  24954. var compiled = this.compileTopDicts([cff.topDict],
  24955. output.length,
  24956. cff.isCIDFont);
  24957. output.add(compiled.output);
  24958. var topDictTracker = compiled.trackers[0];
  24959. var stringIndex = this.compileStringIndex(cff.strings.strings);
  24960. output.add(stringIndex);
  24961. var globalSubrIndex = this.compileIndex(cff.globalSubrIndex);
  24962. output.add(globalSubrIndex);
  24963. // Now start on the other entries that have no specfic order.
  24964. if (cff.encoding && cff.topDict.hasName('Encoding')) {
  24965. if (cff.encoding.predefined) {
  24966. topDictTracker.setEntryLocation('Encoding', [cff.encoding.format],
  24967. output);
  24968. } else {
  24969. var encoding = this.compileEncoding(cff.encoding);
  24970. topDictTracker.setEntryLocation('Encoding', [output.length], output);
  24971. output.add(encoding);
  24972. }
  24973. }
  24974. if (cff.charset && cff.topDict.hasName('charset')) {
  24975. if (cff.charset.predefined) {
  24976. topDictTracker.setEntryLocation('charset', [cff.charset.format],
  24977. output);
  24978. } else {
  24979. var charset = this.compileCharset(cff.charset);
  24980. topDictTracker.setEntryLocation('charset', [output.length], output);
  24981. output.add(charset);
  24982. }
  24983. }
  24984. var charStrings = this.compileCharStrings(cff.charStrings);
  24985. topDictTracker.setEntryLocation('CharStrings', [output.length], output);
  24986. output.add(charStrings);
  24987. if (cff.isCIDFont) {
  24988. // For some reason FDSelect must be in front of FDArray on windows. OSX
  24989. // and linux don't seem to care.
  24990. topDictTracker.setEntryLocation('FDSelect', [output.length], output);
  24991. var fdSelect = this.compileFDSelect(cff.fdSelect.raw);
  24992. output.add(fdSelect);
  24993. // It is unclear if the sub font dictionary can have CID related
  24994. // dictionary keys, but the sanitizer doesn't like them so remove them.
  24995. compiled = this.compileTopDicts(cff.fdArray, output.length, true);
  24996. topDictTracker.setEntryLocation('FDArray', [output.length], output);
  24997. output.add(compiled.output);
  24998. var fontDictTrackers = compiled.trackers;
  24999. this.compilePrivateDicts(cff.fdArray, fontDictTrackers, output);
  25000. }
  25001. this.compilePrivateDicts([cff.topDict], [topDictTracker], output);
  25002. // If the font data ends with INDEX whose object data is zero-length,
  25003. // the sanitizer will bail out. Add a dummy byte to avoid that.
  25004. output.add([0]);
  25005. return output.data;
  25006. },
  25007. encodeNumber: function CFFCompiler_encodeNumber(value) {
  25008. if (parseFloat(value) === parseInt(value, 10) && !isNaN(value)) { // isInt
  25009. return this.encodeInteger(value);
  25010. } else {
  25011. return this.encodeFloat(value);
  25012. }
  25013. },
  25014. encodeFloat: function CFFCompiler_encodeFloat(num) {
  25015. var value = num.toString();
  25016. // rounding inaccurate doubles
  25017. var m = /\.(\d*?)(?:9{5,20}|0{5,20})\d{0,2}(?:e(.+)|$)/.exec(value);
  25018. if (m) {
  25019. var epsilon = parseFloat('1e' + ((m[2] ? +m[2] : 0) + m[1].length));
  25020. value = (Math.round(num * epsilon) / epsilon).toString();
  25021. }
  25022. var nibbles = '';
  25023. var i, ii;
  25024. for (i = 0, ii = value.length; i < ii; ++i) {
  25025. var a = value[i];
  25026. if (a === 'e') {
  25027. nibbles += value[++i] === '-' ? 'c' : 'b';
  25028. } else if (a === '.') {
  25029. nibbles += 'a';
  25030. } else if (a === '-') {
  25031. nibbles += 'e';
  25032. } else {
  25033. nibbles += a;
  25034. }
  25035. }
  25036. nibbles += (nibbles.length & 1) ? 'f' : 'ff';
  25037. var out = [30];
  25038. for (i = 0, ii = nibbles.length; i < ii; i += 2) {
  25039. out.push(parseInt(nibbles.substr(i, 2), 16));
  25040. }
  25041. return out;
  25042. },
  25043. encodeInteger: function CFFCompiler_encodeInteger(value) {
  25044. var code;
  25045. if (value >= -107 && value <= 107) {
  25046. code = [value + 139];
  25047. } else if (value >= 108 && value <= 1131) {
  25048. value = [value - 108];
  25049. code = [(value >> 8) + 247, value & 0xFF];
  25050. } else if (value >= -1131 && value <= -108) {
  25051. value = -value - 108;
  25052. code = [(value >> 8) + 251, value & 0xFF];
  25053. } else if (value >= -32768 && value <= 32767) {
  25054. code = [0x1c, (value >> 8) & 0xFF, value & 0xFF];
  25055. } else {
  25056. code = [0x1d,
  25057. (value >> 24) & 0xFF,
  25058. (value >> 16) & 0xFF,
  25059. (value >> 8) & 0xFF,
  25060. value & 0xFF];
  25061. }
  25062. return code;
  25063. },
  25064. compileHeader: function CFFCompiler_compileHeader(header) {
  25065. return [
  25066. header.major,
  25067. header.minor,
  25068. header.hdrSize,
  25069. header.offSize
  25070. ];
  25071. },
  25072. compileNameIndex: function CFFCompiler_compileNameIndex(names) {
  25073. var nameIndex = new CFFIndex();
  25074. for (var i = 0, ii = names.length; i < ii; ++i) {
  25075. nameIndex.add(stringToBytes(names[i]));
  25076. }
  25077. return this.compileIndex(nameIndex);
  25078. },
  25079. compileTopDicts: function CFFCompiler_compileTopDicts(dicts,
  25080. length,
  25081. removeCidKeys) {
  25082. var fontDictTrackers = [];
  25083. var fdArrayIndex = new CFFIndex();
  25084. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  25085. var fontDict = dicts[i];
  25086. if (removeCidKeys) {
  25087. fontDict.removeByName('CIDFontVersion');
  25088. fontDict.removeByName('CIDFontRevision');
  25089. fontDict.removeByName('CIDFontType');
  25090. fontDict.removeByName('CIDCount');
  25091. fontDict.removeByName('UIDBase');
  25092. }
  25093. var fontDictTracker = new CFFOffsetTracker();
  25094. var fontDictData = this.compileDict(fontDict, fontDictTracker);
  25095. fontDictTrackers.push(fontDictTracker);
  25096. fdArrayIndex.add(fontDictData);
  25097. fontDictTracker.offset(length);
  25098. }
  25099. fdArrayIndex = this.compileIndex(fdArrayIndex, fontDictTrackers);
  25100. return {
  25101. trackers: fontDictTrackers,
  25102. output: fdArrayIndex
  25103. };
  25104. },
  25105. compilePrivateDicts: function CFFCompiler_compilePrivateDicts(dicts,
  25106. trackers,
  25107. output) {
  25108. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  25109. var fontDict = dicts[i];
  25110. assert(fontDict.privateDict && fontDict.hasName('Private'),
  25111. 'There must be an private dictionary.');
  25112. var privateDict = fontDict.privateDict;
  25113. var privateDictTracker = new CFFOffsetTracker();
  25114. var privateDictData = this.compileDict(privateDict, privateDictTracker);
  25115. var outputLength = output.length;
  25116. privateDictTracker.offset(outputLength);
  25117. if (!privateDictData.length) {
  25118. // The private dictionary was empty, set the output length to zero to
  25119. // ensure the offset length isn't out of bounds in the eyes of the
  25120. // sanitizer.
  25121. outputLength = 0;
  25122. }
  25123. trackers[i].setEntryLocation('Private',
  25124. [privateDictData.length, outputLength],
  25125. output);
  25126. output.add(privateDictData);
  25127. if (privateDict.subrsIndex && privateDict.hasName('Subrs')) {
  25128. var subrs = this.compileIndex(privateDict.subrsIndex);
  25129. privateDictTracker.setEntryLocation('Subrs', [privateDictData.length],
  25130. output);
  25131. output.add(subrs);
  25132. }
  25133. }
  25134. },
  25135. compileDict: function CFFCompiler_compileDict(dict, offsetTracker) {
  25136. var out = [];
  25137. // The dictionary keys must be in a certain order.
  25138. var order = dict.order;
  25139. for (var i = 0; i < order.length; ++i) {
  25140. var key = order[i];
  25141. if (!(key in dict.values)) {
  25142. continue;
  25143. }
  25144. var values = dict.values[key];
  25145. var types = dict.types[key];
  25146. if (!isArray(types)) {
  25147. types = [types];
  25148. }
  25149. if (!isArray(values)) {
  25150. values = [values];
  25151. }
  25152. // Remove any empty dict values.
  25153. if (values.length === 0) {
  25154. continue;
  25155. }
  25156. for (var j = 0, jj = types.length; j < jj; ++j) {
  25157. var type = types[j];
  25158. var value = values[j];
  25159. switch (type) {
  25160. case 'num':
  25161. case 'sid':
  25162. out = out.concat(this.encodeNumber(value));
  25163. break;
  25164. case 'offset':
  25165. // For offsets we just insert a 32bit integer so we don't have to
  25166. // deal with figuring out the length of the offset when it gets
  25167. // replaced later on by the compiler.
  25168. var name = dict.keyToNameMap[key];
  25169. // Some offsets have the offset and the length, so just record the
  25170. // position of the first one.
  25171. if (!offsetTracker.isTracking(name)) {
  25172. offsetTracker.track(name, out.length);
  25173. }
  25174. out = out.concat([0x1d, 0, 0, 0, 0]);
  25175. break;
  25176. case 'array':
  25177. case 'delta':
  25178. out = out.concat(this.encodeNumber(value));
  25179. for (var k = 1, kk = values.length; k < kk; ++k) {
  25180. out = out.concat(this.encodeNumber(values[k]));
  25181. }
  25182. break;
  25183. default:
  25184. error('Unknown data type of ' + type);
  25185. break;
  25186. }
  25187. }
  25188. out = out.concat(dict.opcodes[key]);
  25189. }
  25190. return out;
  25191. },
  25192. compileStringIndex: function CFFCompiler_compileStringIndex(strings) {
  25193. var stringIndex = new CFFIndex();
  25194. for (var i = 0, ii = strings.length; i < ii; ++i) {
  25195. stringIndex.add(stringToBytes(strings[i]));
  25196. }
  25197. return this.compileIndex(stringIndex);
  25198. },
  25199. compileGlobalSubrIndex: function CFFCompiler_compileGlobalSubrIndex() {
  25200. var globalSubrIndex = this.cff.globalSubrIndex;
  25201. this.out.writeByteArray(this.compileIndex(globalSubrIndex));
  25202. },
  25203. compileCharStrings: function CFFCompiler_compileCharStrings(charStrings) {
  25204. return this.compileIndex(charStrings);
  25205. },
  25206. compileCharset: function CFFCompiler_compileCharset(charset) {
  25207. return this.compileTypedArray(charset.raw);
  25208. },
  25209. compileEncoding: function CFFCompiler_compileEncoding(encoding) {
  25210. return this.compileTypedArray(encoding.raw);
  25211. },
  25212. compileFDSelect: function CFFCompiler_compileFDSelect(fdSelect) {
  25213. return this.compileTypedArray(fdSelect);
  25214. },
  25215. compileTypedArray: function CFFCompiler_compileTypedArray(data) {
  25216. var out = [];
  25217. for (var i = 0, ii = data.length; i < ii; ++i) {
  25218. out[i] = data[i];
  25219. }
  25220. return out;
  25221. },
  25222. compileIndex: function CFFCompiler_compileIndex(index, trackers) {
  25223. trackers = trackers || [];
  25224. var objects = index.objects;
  25225. // First 2 bytes contains the number of objects contained into this index
  25226. var count = objects.length;
  25227. // If there is no object, just create an index. This technically
  25228. // should just be [0, 0] but OTS has an issue with that.
  25229. if (count === 0) {
  25230. return [0, 0, 0];
  25231. }
  25232. var data = [(count >> 8) & 0xFF, count & 0xff];
  25233. var lastOffset = 1, i;
  25234. for (i = 0; i < count; ++i) {
  25235. lastOffset += objects[i].length;
  25236. }
  25237. var offsetSize;
  25238. if (lastOffset < 0x100) {
  25239. offsetSize = 1;
  25240. } else if (lastOffset < 0x10000) {
  25241. offsetSize = 2;
  25242. } else if (lastOffset < 0x1000000) {
  25243. offsetSize = 3;
  25244. } else {
  25245. offsetSize = 4;
  25246. }
  25247. // Next byte contains the offset size use to reference object in the file
  25248. data.push(offsetSize);
  25249. // Add another offset after this one because we need a new offset
  25250. var relativeOffset = 1;
  25251. for (i = 0; i < count + 1; i++) {
  25252. if (offsetSize === 1) {
  25253. data.push(relativeOffset & 0xFF);
  25254. } else if (offsetSize === 2) {
  25255. data.push((relativeOffset >> 8) & 0xFF,
  25256. relativeOffset & 0xFF);
  25257. } else if (offsetSize === 3) {
  25258. data.push((relativeOffset >> 16) & 0xFF,
  25259. (relativeOffset >> 8) & 0xFF,
  25260. relativeOffset & 0xFF);
  25261. } else {
  25262. data.push((relativeOffset >>> 24) & 0xFF,
  25263. (relativeOffset >> 16) & 0xFF,
  25264. (relativeOffset >> 8) & 0xFF,
  25265. relativeOffset & 0xFF);
  25266. }
  25267. if (objects[i]) {
  25268. relativeOffset += objects[i].length;
  25269. }
  25270. }
  25271. for (i = 0; i < count; i++) {
  25272. // Notify the tracker where the object will be offset in the data.
  25273. if (trackers[i]) {
  25274. trackers[i].offset(data.length);
  25275. }
  25276. for (var j = 0, jj = objects[i].length; j < jj; j++) {
  25277. data.push(objects[i][j]);
  25278. }
  25279. }
  25280. return data;
  25281. }
  25282. };
  25283. return CFFCompiler;
  25284. })();
  25285. // Workaround for seac on Windows.
  25286. (function checkSeacSupport() {
  25287. if (/Windows/.test(navigator.userAgent)) {
  25288. SEAC_ANALYSIS_ENABLED = true;
  25289. }
  25290. })();
  25291. // Workaround for Private Use Area characters in Chrome on Windows
  25292. // http://code.google.com/p/chromium/issues/detail?id=122465
  25293. // https://github.com/mozilla/pdf.js/issues/1689
  25294. (function checkChromeWindows() {
  25295. if (/Windows.*Chrome/.test(navigator.userAgent)) {
  25296. SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = true;
  25297. }
  25298. })();
  25299. var FontRendererFactory = (function FontRendererFactoryClosure() {
  25300. function getLong(data, offset) {
  25301. return (data[offset] << 24) | (data[offset + 1] << 16) |
  25302. (data[offset + 2] << 8) | data[offset + 3];
  25303. }
  25304. function getUshort(data, offset) {
  25305. return (data[offset] << 8) | data[offset + 1];
  25306. }
  25307. function parseCmap(data, start, end) {
  25308. var offset = (getUshort(data, start + 2) === 1 ?
  25309. getLong(data, start + 8) : getLong(data, start + 16));
  25310. var format = getUshort(data, start + offset);
  25311. var length, ranges, p, i;
  25312. if (format === 4) {
  25313. length = getUshort(data, start + offset + 2);
  25314. var segCount = getUshort(data, start + offset + 6) >> 1;
  25315. p = start + offset + 14;
  25316. ranges = [];
  25317. for (i = 0; i < segCount; i++, p += 2) {
  25318. ranges[i] = {end: getUshort(data, p)};
  25319. }
  25320. p += 2;
  25321. for (i = 0; i < segCount; i++, p += 2) {
  25322. ranges[i].start = getUshort(data, p);
  25323. }
  25324. for (i = 0; i < segCount; i++, p += 2) {
  25325. ranges[i].idDelta = getUshort(data, p);
  25326. }
  25327. for (i = 0; i < segCount; i++, p += 2) {
  25328. var idOffset = getUshort(data, p);
  25329. if (idOffset === 0) {
  25330. continue;
  25331. }
  25332. ranges[i].ids = [];
  25333. for (var j = 0, jj = ranges[i].end - ranges[i].start + 1; j < jj; j++) {
  25334. ranges[i].ids[j] = getUshort(data, p + idOffset);
  25335. idOffset += 2;
  25336. }
  25337. }
  25338. return ranges;
  25339. } else if (format === 12) {
  25340. length = getLong(data, start + offset + 4);
  25341. var groups = getLong(data, start + offset + 12);
  25342. p = start + offset + 16;
  25343. ranges = [];
  25344. for (i = 0; i < groups; i++) {
  25345. ranges.push({
  25346. start: getLong(data, p),
  25347. end: getLong(data, p + 4),
  25348. idDelta: getLong(data, p + 8) - getLong(data, p)
  25349. });
  25350. p += 12;
  25351. }
  25352. return ranges;
  25353. }
  25354. error('not supported cmap: ' + format);
  25355. }
  25356. function parseCff(data, start, end) {
  25357. var properties = {};
  25358. var parser = new CFFParser(new Stream(data, start, end - start),
  25359. properties);
  25360. var cff = parser.parse();
  25361. return {
  25362. glyphs: cff.charStrings.objects,
  25363. subrs: (cff.topDict.privateDict && cff.topDict.privateDict.subrsIndex &&
  25364. cff.topDict.privateDict.subrsIndex.objects),
  25365. gsubrs: cff.globalSubrIndex && cff.globalSubrIndex.objects
  25366. };
  25367. }
  25368. function parseGlyfTable(glyf, loca, isGlyphLocationsLong) {
  25369. var itemSize, itemDecode;
  25370. if (isGlyphLocationsLong) {
  25371. itemSize = 4;
  25372. itemDecode = function fontItemDecodeLong(data, offset) {
  25373. return (data[offset] << 24) | (data[offset + 1] << 16) |
  25374. (data[offset + 2] << 8) | data[offset + 3];
  25375. };
  25376. } else {
  25377. itemSize = 2;
  25378. itemDecode = function fontItemDecode(data, offset) {
  25379. return (data[offset] << 9) | (data[offset + 1] << 1);
  25380. };
  25381. }
  25382. var glyphs = [];
  25383. var startOffset = itemDecode(loca, 0);
  25384. for (var j = itemSize; j < loca.length; j += itemSize) {
  25385. var endOffset = itemDecode(loca, j);
  25386. glyphs.push(glyf.subarray(startOffset, endOffset));
  25387. startOffset = endOffset;
  25388. }
  25389. return glyphs;
  25390. }
  25391. function lookupCmap(ranges, unicode) {
  25392. var code = unicode.charCodeAt(0);
  25393. var l = 0, r = ranges.length - 1;
  25394. while (l < r) {
  25395. var c = (l + r + 1) >> 1;
  25396. if (code < ranges[c].start) {
  25397. r = c - 1;
  25398. } else {
  25399. l = c;
  25400. }
  25401. }
  25402. if (ranges[l].start <= code && code <= ranges[l].end) {
  25403. return (ranges[l].idDelta + (ranges[l].ids ?
  25404. ranges[l].ids[code - ranges[l].start] : code)) & 0xFFFF;
  25405. }
  25406. return 0;
  25407. }
  25408. function compileGlyf(code, js, font) {
  25409. function moveTo(x, y) {
  25410. js.push('c.moveTo(' + x + ',' + y + ');');
  25411. }
  25412. function lineTo(x, y) {
  25413. js.push('c.lineTo(' + x + ',' + y + ');');
  25414. }
  25415. function quadraticCurveTo(xa, ya, x, y) {
  25416. js.push('c.quadraticCurveTo(' + xa + ',' + ya + ',' +
  25417. x + ',' + y + ');');
  25418. }
  25419. var i = 0;
  25420. var numberOfContours = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  25421. var flags;
  25422. var x = 0, y = 0;
  25423. i += 10;
  25424. if (numberOfContours < 0) {
  25425. // composite glyph
  25426. do {
  25427. flags = (code[i] << 8) | code[i + 1];
  25428. var glyphIndex = (code[i + 2] << 8) | code[i + 3];
  25429. i += 4;
  25430. var arg1, arg2;
  25431. if ((flags & 0x01)) {
  25432. arg1 = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  25433. arg2 = ((code[i + 2] << 24) | (code[i + 3] << 16)) >> 16;
  25434. i += 4;
  25435. } else {
  25436. arg1 = code[i++]; arg2 = code[i++];
  25437. }
  25438. if ((flags & 0x02)) {
  25439. x = arg1;
  25440. y = arg2;
  25441. } else {
  25442. x = 0; y = 0; // TODO "they are points" ?
  25443. }
  25444. var scaleX = 1, scaleY = 1, scale01 = 0, scale10 = 0;
  25445. if ((flags & 0x08)) {
  25446. scaleX =
  25447. scaleY = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  25448. i += 2;
  25449. } else if ((flags & 0x40)) {
  25450. scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  25451. scaleY = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
  25452. i += 4;
  25453. } else if ((flags & 0x80)) {
  25454. scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  25455. scale01 = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
  25456. scale10 = ((code[i + 4] << 24) | (code[i + 5] << 16)) / 1073741824;
  25457. scaleY = ((code[i + 6] << 24) | (code[i + 7] << 16)) / 1073741824;
  25458. i += 8;
  25459. }
  25460. var subglyph = font.glyphs[glyphIndex];
  25461. if (subglyph) {
  25462. js.push('c.save();');
  25463. js.push('c.transform(' + scaleX + ',' + scale01 + ',' +
  25464. scale10 + ',' + scaleY + ',' + x + ',' + y + ');');
  25465. compileGlyf(subglyph, js, font);
  25466. js.push('c.restore();');
  25467. }
  25468. } while ((flags & 0x20));
  25469. } else {
  25470. // simple glyph
  25471. var endPtsOfContours = [];
  25472. var j, jj;
  25473. for (j = 0; j < numberOfContours; j++) {
  25474. endPtsOfContours.push((code[i] << 8) | code[i + 1]);
  25475. i += 2;
  25476. }
  25477. var instructionLength = (code[i] << 8) | code[i + 1];
  25478. i += 2 + instructionLength; // skipping the instructions
  25479. var numberOfPoints = endPtsOfContours[endPtsOfContours.length - 1] + 1;
  25480. var points = [];
  25481. while (points.length < numberOfPoints) {
  25482. flags = code[i++];
  25483. var repeat = 1;
  25484. if ((flags & 0x08)) {
  25485. repeat += code[i++];
  25486. }
  25487. while (repeat-- > 0) {
  25488. points.push({flags: flags});
  25489. }
  25490. }
  25491. for (j = 0; j < numberOfPoints; j++) {
  25492. switch (points[j].flags & 0x12) {
  25493. case 0x00:
  25494. x += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  25495. i += 2;
  25496. break;
  25497. case 0x02:
  25498. x -= code[i++];
  25499. break;
  25500. case 0x12:
  25501. x += code[i++];
  25502. break;
  25503. }
  25504. points[j].x = x;
  25505. }
  25506. for (j = 0; j < numberOfPoints; j++) {
  25507. switch (points[j].flags & 0x24) {
  25508. case 0x00:
  25509. y += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  25510. i += 2;
  25511. break;
  25512. case 0x04:
  25513. y -= code[i++];
  25514. break;
  25515. case 0x24:
  25516. y += code[i++];
  25517. break;
  25518. }
  25519. points[j].y = y;
  25520. }
  25521. var startPoint = 0;
  25522. for (i = 0; i < numberOfContours; i++) {
  25523. var endPoint = endPtsOfContours[i];
  25524. // contours might have implicit points, which is located in the middle
  25525. // between two neighboring off-curve points
  25526. var contour = points.slice(startPoint, endPoint + 1);
  25527. if ((contour[0].flags & 1)) {
  25528. contour.push(contour[0]); // using start point at the contour end
  25529. } else if ((contour[contour.length - 1].flags & 1)) {
  25530. // first is off-curve point, trying to use one from the end
  25531. contour.unshift(contour[contour.length - 1]);
  25532. } else {
  25533. // start and end are off-curve points, creating implicit one
  25534. var p = {
  25535. flags: 1,
  25536. x: (contour[0].x + contour[contour.length - 1].x) / 2,
  25537. y: (contour[0].y + contour[contour.length - 1].y) / 2
  25538. };
  25539. contour.unshift(p);
  25540. contour.push(p);
  25541. }
  25542. moveTo(contour[0].x, contour[0].y);
  25543. for (j = 1, jj = contour.length; j < jj; j++) {
  25544. if ((contour[j].flags & 1)) {
  25545. lineTo(contour[j].x, contour[j].y);
  25546. } else if ((contour[j + 1].flags & 1)){
  25547. quadraticCurveTo(contour[j].x, contour[j].y,
  25548. contour[j + 1].x, contour[j + 1].y);
  25549. j++;
  25550. } else {
  25551. quadraticCurveTo(contour[j].x, contour[j].y,
  25552. (contour[j].x + contour[j + 1].x) / 2,
  25553. (contour[j].y + contour[j + 1].y) / 2);
  25554. }
  25555. }
  25556. startPoint = endPoint + 1;
  25557. }
  25558. }
  25559. }
  25560. function compileCharString(code, js, font) {
  25561. var stack = [];
  25562. var x = 0, y = 0;
  25563. var stems = 0;
  25564. function moveTo(x, y) {
  25565. js.push('c.moveTo(' + x + ',' + y + ');');
  25566. }
  25567. function lineTo(x, y) {
  25568. js.push('c.lineTo(' + x + ',' + y + ');');
  25569. }
  25570. function bezierCurveTo(x1, y1, x2, y2, x, y) {
  25571. js.push('c.bezierCurveTo(' + x1 + ',' + y1 + ',' + x2 + ',' + y2 + ',' +
  25572. x + ',' + y + ');');
  25573. }
  25574. function parse(code) {
  25575. var i = 0;
  25576. while (i < code.length) {
  25577. var stackClean = false;
  25578. var v = code[i++];
  25579. var xa, xb, ya, yb, y1, y2, y3, n, subrCode;
  25580. switch (v) {
  25581. case 1: // hstem
  25582. stems += stack.length >> 1;
  25583. stackClean = true;
  25584. break;
  25585. case 3: // vstem
  25586. stems += stack.length >> 1;
  25587. stackClean = true;
  25588. break;
  25589. case 4: // vmoveto
  25590. y += stack.pop();
  25591. moveTo(x, y);
  25592. stackClean = true;
  25593. break;
  25594. case 5: // rlineto
  25595. while (stack.length > 0) {
  25596. x += stack.shift();
  25597. y += stack.shift();
  25598. lineTo(x, y);
  25599. }
  25600. break;
  25601. case 6: // hlineto
  25602. while (stack.length > 0) {
  25603. x += stack.shift();
  25604. lineTo(x, y);
  25605. if (stack.length === 0) {
  25606. break;
  25607. }
  25608. y += stack.shift();
  25609. lineTo(x, y);
  25610. }
  25611. break;
  25612. case 7: // vlineto
  25613. while (stack.length > 0) {
  25614. y += stack.shift();
  25615. lineTo(x, y);
  25616. if (stack.length === 0) {
  25617. break;
  25618. }
  25619. x += stack.shift();
  25620. lineTo(x, y);
  25621. }
  25622. break;
  25623. case 8: // rrcurveto
  25624. while (stack.length > 0) {
  25625. xa = x + stack.shift(); ya = y + stack.shift();
  25626. xb = xa + stack.shift(); yb = ya + stack.shift();
  25627. x = xb + stack.shift(); y = yb + stack.shift();
  25628. bezierCurveTo(xa, ya, xb, yb, x, y);
  25629. }
  25630. break;
  25631. case 10: // callsubr
  25632. n = stack.pop() + font.subrsBias;
  25633. subrCode = font.subrs[n];
  25634. if (subrCode) {
  25635. parse(subrCode);
  25636. }
  25637. break;
  25638. case 11: // return
  25639. return;
  25640. case 12:
  25641. v = code[i++];
  25642. switch (v) {
  25643. case 34: // flex
  25644. xa = x + stack.shift();
  25645. xb = xa + stack.shift(); y1 = y + stack.shift();
  25646. x = xb + stack.shift();
  25647. bezierCurveTo(xa, y, xb, y1, x, y1);
  25648. xa = x + stack.shift();
  25649. xb = xa + stack.shift();
  25650. x = xb + stack.shift();
  25651. bezierCurveTo(xa, y1, xb, y, x, y);
  25652. break;
  25653. case 35: // flex
  25654. xa = x + stack.shift(); ya = y + stack.shift();
  25655. xb = xa + stack.shift(); yb = ya + stack.shift();
  25656. x = xb + stack.shift(); y = yb + stack.shift();
  25657. bezierCurveTo(xa, ya, xb, yb, x, y);
  25658. xa = x + stack.shift(); ya = y + stack.shift();
  25659. xb = xa + stack.shift(); yb = ya + stack.shift();
  25660. x = xb + stack.shift(); y = yb + stack.shift();
  25661. bezierCurveTo(xa, ya, xb, yb, x, y);
  25662. stack.pop(); // fd
  25663. break;
  25664. case 36: // hflex1
  25665. xa = x + stack.shift(); y1 = y + stack.shift();
  25666. xb = xa + stack.shift(); y2 = y1 + stack.shift();
  25667. x = xb + stack.shift();
  25668. bezierCurveTo(xa, y1, xb, y2, x, y2);
  25669. xa = x + stack.shift();
  25670. xb = xa + stack.shift(); y3 = y2 + stack.shift();
  25671. x = xb + stack.shift();
  25672. bezierCurveTo(xa, y2, xb, y3, x, y);
  25673. break;
  25674. case 37: // flex1
  25675. var x0 = x, y0 = y;
  25676. xa = x + stack.shift(); ya = y + stack.shift();
  25677. xb = xa + stack.shift(); yb = ya + stack.shift();
  25678. x = xb + stack.shift(); y = yb + stack.shift();
  25679. bezierCurveTo(xa, ya, xb, yb, x, y);
  25680. xa = x + stack.shift(); ya = y + stack.shift();
  25681. xb = xa + stack.shift(); yb = ya + stack.shift();
  25682. x = xb; y = yb;
  25683. if (Math.abs(x - x0) > Math.abs(y - y0)) {
  25684. x += stack.shift();
  25685. } else {
  25686. y += stack.shift();
  25687. }
  25688. bezierCurveTo(xa, ya, xb, yb, x, y);
  25689. break;
  25690. default:
  25691. error('unknown operator: 12 ' + v);
  25692. }
  25693. break;
  25694. case 14: // endchar
  25695. if (stack.length >= 4) {
  25696. var achar = stack.pop();
  25697. var bchar = stack.pop();
  25698. y = stack.pop();
  25699. x = stack.pop();
  25700. js.push('c.save();');
  25701. js.push('c.translate('+ x + ',' + y + ');');
  25702. var gid = lookupCmap(font.cmap, String.fromCharCode(
  25703. font.glyphNameMap[Encodings.StandardEncoding[achar]]));
  25704. compileCharString(font.glyphs[gid], js, font);
  25705. js.push('c.restore();');
  25706. gid = lookupCmap(font.cmap, String.fromCharCode(
  25707. font.glyphNameMap[Encodings.StandardEncoding[bchar]]));
  25708. compileCharString(font.glyphs[gid], js, font);
  25709. }
  25710. return;
  25711. case 18: // hstemhm
  25712. stems += stack.length >> 1;
  25713. stackClean = true;
  25714. break;
  25715. case 19: // hintmask
  25716. stems += stack.length >> 1;
  25717. i += (stems + 7) >> 3;
  25718. stackClean = true;
  25719. break;
  25720. case 20: // cntrmask
  25721. stems += stack.length >> 1;
  25722. i += (stems + 7) >> 3;
  25723. stackClean = true;
  25724. break;
  25725. case 21: // rmoveto
  25726. y += stack.pop();
  25727. x += stack.pop();
  25728. moveTo(x, y);
  25729. stackClean = true;
  25730. break;
  25731. case 22: // hmoveto
  25732. x += stack.pop();
  25733. moveTo(x, y);
  25734. stackClean = true;
  25735. break;
  25736. case 23: // vstemhm
  25737. stems += stack.length >> 1;
  25738. stackClean = true;
  25739. break;
  25740. case 24: // rcurveline
  25741. while (stack.length > 2) {
  25742. xa = x + stack.shift(); ya = y + stack.shift();
  25743. xb = xa + stack.shift(); yb = ya + stack.shift();
  25744. x = xb + stack.shift(); y = yb + stack.shift();
  25745. bezierCurveTo(xa, ya, xb, yb, x, y);
  25746. }
  25747. x += stack.shift();
  25748. y += stack.shift();
  25749. lineTo(x, y);
  25750. break;
  25751. case 25: // rlinecurve
  25752. while (stack.length > 6) {
  25753. x += stack.shift();
  25754. y += stack.shift();
  25755. lineTo(x, y);
  25756. }
  25757. xa = x + stack.shift(); ya = y + stack.shift();
  25758. xb = xa + stack.shift(); yb = ya + stack.shift();
  25759. x = xb + stack.shift(); y = yb + stack.shift();
  25760. bezierCurveTo(xa, ya, xb, yb, x, y);
  25761. break;
  25762. case 26: // vvcurveto
  25763. if (stack.length % 2) {
  25764. x += stack.shift();
  25765. }
  25766. while (stack.length > 0) {
  25767. xa = x; ya = y + stack.shift();
  25768. xb = xa + stack.shift(); yb = ya + stack.shift();
  25769. x = xb; y = yb + stack.shift();
  25770. bezierCurveTo(xa, ya, xb, yb, x, y);
  25771. }
  25772. break;
  25773. case 27: // hhcurveto
  25774. if (stack.length % 2) {
  25775. y += stack.shift();
  25776. }
  25777. while (stack.length > 0) {
  25778. xa = x + stack.shift(); ya = y;
  25779. xb = xa + stack.shift(); yb = ya + stack.shift();
  25780. x = xb + stack.shift(); y = yb;
  25781. bezierCurveTo(xa, ya, xb, yb, x, y);
  25782. }
  25783. break;
  25784. case 28:
  25785. stack.push(((code[i] << 24) | (code[i + 1] << 16)) >> 16);
  25786. i += 2;
  25787. break;
  25788. case 29: // callgsubr
  25789. n = stack.pop() + font.gsubrsBias;
  25790. subrCode = font.gsubrs[n];
  25791. if (subrCode) {
  25792. parse(subrCode);
  25793. }
  25794. break;
  25795. case 30: // vhcurveto
  25796. while (stack.length > 0) {
  25797. xa = x; ya = y + stack.shift();
  25798. xb = xa + stack.shift(); yb = ya + stack.shift();
  25799. x = xb + stack.shift();
  25800. y = yb + (stack.length === 1 ? stack.shift() : 0);
  25801. bezierCurveTo(xa, ya, xb, yb, x, y);
  25802. if (stack.length === 0) {
  25803. break;
  25804. }
  25805. xa = x + stack.shift(); ya = y;
  25806. xb = xa + stack.shift(); yb = ya + stack.shift();
  25807. y = yb + stack.shift();
  25808. x = xb + (stack.length === 1 ? stack.shift() : 0);
  25809. bezierCurveTo(xa, ya, xb, yb, x, y);
  25810. }
  25811. break;
  25812. case 31: // hvcurveto
  25813. while (stack.length > 0) {
  25814. xa = x + stack.shift(); ya = y;
  25815. xb = xa + stack.shift(); yb = ya + stack.shift();
  25816. y = yb + stack.shift();
  25817. x = xb + (stack.length === 1 ? stack.shift() : 0);
  25818. bezierCurveTo(xa, ya, xb, yb, x, y);
  25819. if (stack.length === 0) {
  25820. break;
  25821. }
  25822. xa = x; ya = y + stack.shift();
  25823. xb = xa + stack.shift(); yb = ya + stack.shift();
  25824. x = xb + stack.shift();
  25825. y = yb + (stack.length === 1 ? stack.shift() : 0);
  25826. bezierCurveTo(xa, ya, xb, yb, x, y);
  25827. }
  25828. break;
  25829. default:
  25830. if (v < 32) {
  25831. error('unknown operator: ' + v);
  25832. }
  25833. if (v < 247) {
  25834. stack.push(v - 139);
  25835. } else if (v < 251) {
  25836. stack.push((v - 247) * 256 + code[i++] + 108);
  25837. } else if (v < 255) {
  25838. stack.push(-(v - 251) * 256 - code[i++] - 108);
  25839. } else {
  25840. stack.push(((code[i] << 24) | (code[i + 1] << 16) |
  25841. (code[i + 2] << 8) | code[i + 3]) / 65536);
  25842. i += 4;
  25843. }
  25844. break;
  25845. }
  25846. if (stackClean) {
  25847. stack.length = 0;
  25848. }
  25849. }
  25850. }
  25851. parse(code);
  25852. }
  25853. var noop = '';
  25854. function CompiledFont(fontMatrix) {
  25855. this.compiledGlyphs = {};
  25856. this.fontMatrix = fontMatrix;
  25857. }
  25858. CompiledFont.prototype = {
  25859. getPathJs: function (unicode) {
  25860. var gid = lookupCmap(this.cmap, unicode);
  25861. var fn = this.compiledGlyphs[gid];
  25862. if (!fn) {
  25863. this.compiledGlyphs[gid] = fn = this.compileGlyph(this.glyphs[gid]);
  25864. }
  25865. return fn;
  25866. },
  25867. compileGlyph: function (code) {
  25868. if (!code || code.length === 0 || code[0] === 14) {
  25869. return noop;
  25870. }
  25871. var js = [];
  25872. js.push('c.save();');
  25873. js.push('c.transform(' + this.fontMatrix.join(',') + ');');
  25874. js.push('c.scale(size, -size);');
  25875. this.compileGlyphImpl(code, js);
  25876. js.push('c.restore();');
  25877. return js.join('\n');
  25878. },
  25879. compileGlyphImpl: function () {
  25880. error('Children classes should implement this.');
  25881. },
  25882. hasBuiltPath: function (unicode) {
  25883. var gid = lookupCmap(this.cmap, unicode);
  25884. return gid in this.compiledGlyphs;
  25885. }
  25886. };
  25887. function TrueTypeCompiled(glyphs, cmap, fontMatrix) {
  25888. fontMatrix = fontMatrix || [0.000488, 0, 0, 0.000488, 0, 0];
  25889. CompiledFont.call(this, fontMatrix);
  25890. this.glyphs = glyphs;
  25891. this.cmap = cmap;
  25892. this.compiledGlyphs = [];
  25893. }
  25894. Util.inherit(TrueTypeCompiled, CompiledFont, {
  25895. compileGlyphImpl: function (code, js) {
  25896. compileGlyf(code, js, this);
  25897. }
  25898. });
  25899. function Type2Compiled(cffInfo, cmap, fontMatrix, glyphNameMap) {
  25900. fontMatrix = fontMatrix || [0.001, 0, 0, 0.001, 0, 0];
  25901. CompiledFont.call(this, fontMatrix);
  25902. this.glyphs = cffInfo.glyphs;
  25903. this.gsubrs = cffInfo.gsubrs || [];
  25904. this.subrs = cffInfo.subrs || [];
  25905. this.cmap = cmap;
  25906. this.glyphNameMap = glyphNameMap || GlyphsUnicode;
  25907. this.compiledGlyphs = [];
  25908. this.gsubrsBias = (this.gsubrs.length < 1240 ?
  25909. 107 : (this.gsubrs.length < 33900 ? 1131 : 32768));
  25910. this.subrsBias = (this.subrs.length < 1240 ?
  25911. 107 : (this.subrs.length < 33900 ? 1131 : 32768));
  25912. }
  25913. Util.inherit(Type2Compiled, CompiledFont, {
  25914. compileGlyphImpl: function (code, js) {
  25915. compileCharString(code, js, this);
  25916. }
  25917. });
  25918. return {
  25919. create: function FontRendererFactory_create(font) {
  25920. var data = new Uint8Array(font.data);
  25921. var cmap, glyf, loca, cff, indexToLocFormat, unitsPerEm;
  25922. var numTables = getUshort(data, 4);
  25923. for (var i = 0, p = 12; i < numTables; i++, p += 16) {
  25924. var tag = bytesToString(data.subarray(p, p + 4));
  25925. var offset = getLong(data, p + 8);
  25926. var length = getLong(data, p + 12);
  25927. switch (tag) {
  25928. case 'cmap':
  25929. cmap = parseCmap(data, offset, offset + length);
  25930. break;
  25931. case 'glyf':
  25932. glyf = data.subarray(offset, offset + length);
  25933. break;
  25934. case 'loca':
  25935. loca = data.subarray(offset, offset + length);
  25936. break;
  25937. case 'head':
  25938. unitsPerEm = getUshort(data, offset + 18);
  25939. indexToLocFormat = getUshort(data, offset + 50);
  25940. break;
  25941. case 'CFF ':
  25942. cff = parseCff(data, offset, offset + length);
  25943. break;
  25944. }
  25945. }
  25946. if (glyf) {
  25947. var fontMatrix = (!unitsPerEm ? font.fontMatrix :
  25948. [1 / unitsPerEm, 0, 0, 1 / unitsPerEm, 0, 0]);
  25949. return new TrueTypeCompiled(
  25950. parseGlyfTable(glyf, loca, indexToLocFormat), cmap, fontMatrix);
  25951. } else {
  25952. return new Type2Compiled(cff, cmap, font.fontMatrix, font.glyphNameMap);
  25953. }
  25954. }
  25955. };
  25956. })();
  25957. var GlyphsUnicode = {
  25958. A: 0x0041,
  25959. AE: 0x00C6,
  25960. AEacute: 0x01FC,
  25961. AEmacron: 0x01E2,
  25962. AEsmall: 0xF7E6,
  25963. Aacute: 0x00C1,
  25964. Aacutesmall: 0xF7E1,
  25965. Abreve: 0x0102,
  25966. Abreveacute: 0x1EAE,
  25967. Abrevecyrillic: 0x04D0,
  25968. Abrevedotbelow: 0x1EB6,
  25969. Abrevegrave: 0x1EB0,
  25970. Abrevehookabove: 0x1EB2,
  25971. Abrevetilde: 0x1EB4,
  25972. Acaron: 0x01CD,
  25973. Acircle: 0x24B6,
  25974. Acircumflex: 0x00C2,
  25975. Acircumflexacute: 0x1EA4,
  25976. Acircumflexdotbelow: 0x1EAC,
  25977. Acircumflexgrave: 0x1EA6,
  25978. Acircumflexhookabove: 0x1EA8,
  25979. Acircumflexsmall: 0xF7E2,
  25980. Acircumflextilde: 0x1EAA,
  25981. Acute: 0xF6C9,
  25982. Acutesmall: 0xF7B4,
  25983. Acyrillic: 0x0410,
  25984. Adblgrave: 0x0200,
  25985. Adieresis: 0x00C4,
  25986. Adieresiscyrillic: 0x04D2,
  25987. Adieresismacron: 0x01DE,
  25988. Adieresissmall: 0xF7E4,
  25989. Adotbelow: 0x1EA0,
  25990. Adotmacron: 0x01E0,
  25991. Agrave: 0x00C0,
  25992. Agravesmall: 0xF7E0,
  25993. Ahookabove: 0x1EA2,
  25994. Aiecyrillic: 0x04D4,
  25995. Ainvertedbreve: 0x0202,
  25996. Alpha: 0x0391,
  25997. Alphatonos: 0x0386,
  25998. Amacron: 0x0100,
  25999. Amonospace: 0xFF21,
  26000. Aogonek: 0x0104,
  26001. Aring: 0x00C5,
  26002. Aringacute: 0x01FA,
  26003. Aringbelow: 0x1E00,
  26004. Aringsmall: 0xF7E5,
  26005. Asmall: 0xF761,
  26006. Atilde: 0x00C3,
  26007. Atildesmall: 0xF7E3,
  26008. Aybarmenian: 0x0531,
  26009. B: 0x0042,
  26010. Bcircle: 0x24B7,
  26011. Bdotaccent: 0x1E02,
  26012. Bdotbelow: 0x1E04,
  26013. Becyrillic: 0x0411,
  26014. Benarmenian: 0x0532,
  26015. Beta: 0x0392,
  26016. Bhook: 0x0181,
  26017. Blinebelow: 0x1E06,
  26018. Bmonospace: 0xFF22,
  26019. Brevesmall: 0xF6F4,
  26020. Bsmall: 0xF762,
  26021. Btopbar: 0x0182,
  26022. C: 0x0043,
  26023. Caarmenian: 0x053E,
  26024. Cacute: 0x0106,
  26025. Caron: 0xF6CA,
  26026. Caronsmall: 0xF6F5,
  26027. Ccaron: 0x010C,
  26028. Ccedilla: 0x00C7,
  26029. Ccedillaacute: 0x1E08,
  26030. Ccedillasmall: 0xF7E7,
  26031. Ccircle: 0x24B8,
  26032. Ccircumflex: 0x0108,
  26033. Cdot: 0x010A,
  26034. Cdotaccent: 0x010A,
  26035. Cedillasmall: 0xF7B8,
  26036. Chaarmenian: 0x0549,
  26037. Cheabkhasiancyrillic: 0x04BC,
  26038. Checyrillic: 0x0427,
  26039. Chedescenderabkhasiancyrillic: 0x04BE,
  26040. Chedescendercyrillic: 0x04B6,
  26041. Chedieresiscyrillic: 0x04F4,
  26042. Cheharmenian: 0x0543,
  26043. Chekhakassiancyrillic: 0x04CB,
  26044. Cheverticalstrokecyrillic: 0x04B8,
  26045. Chi: 0x03A7,
  26046. Chook: 0x0187,
  26047. Circumflexsmall: 0xF6F6,
  26048. Cmonospace: 0xFF23,
  26049. Coarmenian: 0x0551,
  26050. Csmall: 0xF763,
  26051. D: 0x0044,
  26052. DZ: 0x01F1,
  26053. DZcaron: 0x01C4,
  26054. Daarmenian: 0x0534,
  26055. Dafrican: 0x0189,
  26056. Dcaron: 0x010E,
  26057. Dcedilla: 0x1E10,
  26058. Dcircle: 0x24B9,
  26059. Dcircumflexbelow: 0x1E12,
  26060. Dcroat: 0x0110,
  26061. Ddotaccent: 0x1E0A,
  26062. Ddotbelow: 0x1E0C,
  26063. Decyrillic: 0x0414,
  26064. Deicoptic: 0x03EE,
  26065. Delta: 0x2206,
  26066. Deltagreek: 0x0394,
  26067. Dhook: 0x018A,
  26068. Dieresis: 0xF6CB,
  26069. DieresisAcute: 0xF6CC,
  26070. DieresisGrave: 0xF6CD,
  26071. Dieresissmall: 0xF7A8,
  26072. Digammagreek: 0x03DC,
  26073. Djecyrillic: 0x0402,
  26074. Dlinebelow: 0x1E0E,
  26075. Dmonospace: 0xFF24,
  26076. Dotaccentsmall: 0xF6F7,
  26077. Dslash: 0x0110,
  26078. Dsmall: 0xF764,
  26079. Dtopbar: 0x018B,
  26080. Dz: 0x01F2,
  26081. Dzcaron: 0x01C5,
  26082. Dzeabkhasiancyrillic: 0x04E0,
  26083. Dzecyrillic: 0x0405,
  26084. Dzhecyrillic: 0x040F,
  26085. E: 0x0045,
  26086. Eacute: 0x00C9,
  26087. Eacutesmall: 0xF7E9,
  26088. Ebreve: 0x0114,
  26089. Ecaron: 0x011A,
  26090. Ecedillabreve: 0x1E1C,
  26091. Echarmenian: 0x0535,
  26092. Ecircle: 0x24BA,
  26093. Ecircumflex: 0x00CA,
  26094. Ecircumflexacute: 0x1EBE,
  26095. Ecircumflexbelow: 0x1E18,
  26096. Ecircumflexdotbelow: 0x1EC6,
  26097. Ecircumflexgrave: 0x1EC0,
  26098. Ecircumflexhookabove: 0x1EC2,
  26099. Ecircumflexsmall: 0xF7EA,
  26100. Ecircumflextilde: 0x1EC4,
  26101. Ecyrillic: 0x0404,
  26102. Edblgrave: 0x0204,
  26103. Edieresis: 0x00CB,
  26104. Edieresissmall: 0xF7EB,
  26105. Edot: 0x0116,
  26106. Edotaccent: 0x0116,
  26107. Edotbelow: 0x1EB8,
  26108. Efcyrillic: 0x0424,
  26109. Egrave: 0x00C8,
  26110. Egravesmall: 0xF7E8,
  26111. Eharmenian: 0x0537,
  26112. Ehookabove: 0x1EBA,
  26113. Eightroman: 0x2167,
  26114. Einvertedbreve: 0x0206,
  26115. Eiotifiedcyrillic: 0x0464,
  26116. Elcyrillic: 0x041B,
  26117. Elevenroman: 0x216A,
  26118. Emacron: 0x0112,
  26119. Emacronacute: 0x1E16,
  26120. Emacrongrave: 0x1E14,
  26121. Emcyrillic: 0x041C,
  26122. Emonospace: 0xFF25,
  26123. Encyrillic: 0x041D,
  26124. Endescendercyrillic: 0x04A2,
  26125. Eng: 0x014A,
  26126. Enghecyrillic: 0x04A4,
  26127. Enhookcyrillic: 0x04C7,
  26128. Eogonek: 0x0118,
  26129. Eopen: 0x0190,
  26130. Epsilon: 0x0395,
  26131. Epsilontonos: 0x0388,
  26132. Ercyrillic: 0x0420,
  26133. Ereversed: 0x018E,
  26134. Ereversedcyrillic: 0x042D,
  26135. Escyrillic: 0x0421,
  26136. Esdescendercyrillic: 0x04AA,
  26137. Esh: 0x01A9,
  26138. Esmall: 0xF765,
  26139. Eta: 0x0397,
  26140. Etarmenian: 0x0538,
  26141. Etatonos: 0x0389,
  26142. Eth: 0x00D0,
  26143. Ethsmall: 0xF7F0,
  26144. Etilde: 0x1EBC,
  26145. Etildebelow: 0x1E1A,
  26146. Euro: 0x20AC,
  26147. Ezh: 0x01B7,
  26148. Ezhcaron: 0x01EE,
  26149. Ezhreversed: 0x01B8,
  26150. F: 0x0046,
  26151. Fcircle: 0x24BB,
  26152. Fdotaccent: 0x1E1E,
  26153. Feharmenian: 0x0556,
  26154. Feicoptic: 0x03E4,
  26155. Fhook: 0x0191,
  26156. Fitacyrillic: 0x0472,
  26157. Fiveroman: 0x2164,
  26158. Fmonospace: 0xFF26,
  26159. Fourroman: 0x2163,
  26160. Fsmall: 0xF766,
  26161. G: 0x0047,
  26162. GBsquare: 0x3387,
  26163. Gacute: 0x01F4,
  26164. Gamma: 0x0393,
  26165. Gammaafrican: 0x0194,
  26166. Gangiacoptic: 0x03EA,
  26167. Gbreve: 0x011E,
  26168. Gcaron: 0x01E6,
  26169. Gcedilla: 0x0122,
  26170. Gcircle: 0x24BC,
  26171. Gcircumflex: 0x011C,
  26172. Gcommaaccent: 0x0122,
  26173. Gdot: 0x0120,
  26174. Gdotaccent: 0x0120,
  26175. Gecyrillic: 0x0413,
  26176. Ghadarmenian: 0x0542,
  26177. Ghemiddlehookcyrillic: 0x0494,
  26178. Ghestrokecyrillic: 0x0492,
  26179. Gheupturncyrillic: 0x0490,
  26180. Ghook: 0x0193,
  26181. Gimarmenian: 0x0533,
  26182. Gjecyrillic: 0x0403,
  26183. Gmacron: 0x1E20,
  26184. Gmonospace: 0xFF27,
  26185. Grave: 0xF6CE,
  26186. Gravesmall: 0xF760,
  26187. Gsmall: 0xF767,
  26188. Gsmallhook: 0x029B,
  26189. Gstroke: 0x01E4,
  26190. H: 0x0048,
  26191. H18533: 0x25CF,
  26192. H18543: 0x25AA,
  26193. H18551: 0x25AB,
  26194. H22073: 0x25A1,
  26195. HPsquare: 0x33CB,
  26196. Haabkhasiancyrillic: 0x04A8,
  26197. Hadescendercyrillic: 0x04B2,
  26198. Hardsigncyrillic: 0x042A,
  26199. Hbar: 0x0126,
  26200. Hbrevebelow: 0x1E2A,
  26201. Hcedilla: 0x1E28,
  26202. Hcircle: 0x24BD,
  26203. Hcircumflex: 0x0124,
  26204. Hdieresis: 0x1E26,
  26205. Hdotaccent: 0x1E22,
  26206. Hdotbelow: 0x1E24,
  26207. Hmonospace: 0xFF28,
  26208. Hoarmenian: 0x0540,
  26209. Horicoptic: 0x03E8,
  26210. Hsmall: 0xF768,
  26211. Hungarumlaut: 0xF6CF,
  26212. Hungarumlautsmall: 0xF6F8,
  26213. Hzsquare: 0x3390,
  26214. I: 0x0049,
  26215. IAcyrillic: 0x042F,
  26216. IJ: 0x0132,
  26217. IUcyrillic: 0x042E,
  26218. Iacute: 0x00CD,
  26219. Iacutesmall: 0xF7ED,
  26220. Ibreve: 0x012C,
  26221. Icaron: 0x01CF,
  26222. Icircle: 0x24BE,
  26223. Icircumflex: 0x00CE,
  26224. Icircumflexsmall: 0xF7EE,
  26225. Icyrillic: 0x0406,
  26226. Idblgrave: 0x0208,
  26227. Idieresis: 0x00CF,
  26228. Idieresisacute: 0x1E2E,
  26229. Idieresiscyrillic: 0x04E4,
  26230. Idieresissmall: 0xF7EF,
  26231. Idot: 0x0130,
  26232. Idotaccent: 0x0130,
  26233. Idotbelow: 0x1ECA,
  26234. Iebrevecyrillic: 0x04D6,
  26235. Iecyrillic: 0x0415,
  26236. Ifraktur: 0x2111,
  26237. Igrave: 0x00CC,
  26238. Igravesmall: 0xF7EC,
  26239. Ihookabove: 0x1EC8,
  26240. Iicyrillic: 0x0418,
  26241. Iinvertedbreve: 0x020A,
  26242. Iishortcyrillic: 0x0419,
  26243. Imacron: 0x012A,
  26244. Imacroncyrillic: 0x04E2,
  26245. Imonospace: 0xFF29,
  26246. Iniarmenian: 0x053B,
  26247. Iocyrillic: 0x0401,
  26248. Iogonek: 0x012E,
  26249. Iota: 0x0399,
  26250. Iotaafrican: 0x0196,
  26251. Iotadieresis: 0x03AA,
  26252. Iotatonos: 0x038A,
  26253. Ismall: 0xF769,
  26254. Istroke: 0x0197,
  26255. Itilde: 0x0128,
  26256. Itildebelow: 0x1E2C,
  26257. Izhitsacyrillic: 0x0474,
  26258. Izhitsadblgravecyrillic: 0x0476,
  26259. J: 0x004A,
  26260. Jaarmenian: 0x0541,
  26261. Jcircle: 0x24BF,
  26262. Jcircumflex: 0x0134,
  26263. Jecyrillic: 0x0408,
  26264. Jheharmenian: 0x054B,
  26265. Jmonospace: 0xFF2A,
  26266. Jsmall: 0xF76A,
  26267. K: 0x004B,
  26268. KBsquare: 0x3385,
  26269. KKsquare: 0x33CD,
  26270. Kabashkircyrillic: 0x04A0,
  26271. Kacute: 0x1E30,
  26272. Kacyrillic: 0x041A,
  26273. Kadescendercyrillic: 0x049A,
  26274. Kahookcyrillic: 0x04C3,
  26275. Kappa: 0x039A,
  26276. Kastrokecyrillic: 0x049E,
  26277. Kaverticalstrokecyrillic: 0x049C,
  26278. Kcaron: 0x01E8,
  26279. Kcedilla: 0x0136,
  26280. Kcircle: 0x24C0,
  26281. Kcommaaccent: 0x0136,
  26282. Kdotbelow: 0x1E32,
  26283. Keharmenian: 0x0554,
  26284. Kenarmenian: 0x053F,
  26285. Khacyrillic: 0x0425,
  26286. Kheicoptic: 0x03E6,
  26287. Khook: 0x0198,
  26288. Kjecyrillic: 0x040C,
  26289. Klinebelow: 0x1E34,
  26290. Kmonospace: 0xFF2B,
  26291. Koppacyrillic: 0x0480,
  26292. Koppagreek: 0x03DE,
  26293. Ksicyrillic: 0x046E,
  26294. Ksmall: 0xF76B,
  26295. L: 0x004C,
  26296. LJ: 0x01C7,
  26297. LL: 0xF6BF,
  26298. Lacute: 0x0139,
  26299. Lambda: 0x039B,
  26300. Lcaron: 0x013D,
  26301. Lcedilla: 0x013B,
  26302. Lcircle: 0x24C1,
  26303. Lcircumflexbelow: 0x1E3C,
  26304. Lcommaaccent: 0x013B,
  26305. Ldot: 0x013F,
  26306. Ldotaccent: 0x013F,
  26307. Ldotbelow: 0x1E36,
  26308. Ldotbelowmacron: 0x1E38,
  26309. Liwnarmenian: 0x053C,
  26310. Lj: 0x01C8,
  26311. Ljecyrillic: 0x0409,
  26312. Llinebelow: 0x1E3A,
  26313. Lmonospace: 0xFF2C,
  26314. Lslash: 0x0141,
  26315. Lslashsmall: 0xF6F9,
  26316. Lsmall: 0xF76C,
  26317. M: 0x004D,
  26318. MBsquare: 0x3386,
  26319. Macron: 0xF6D0,
  26320. Macronsmall: 0xF7AF,
  26321. Macute: 0x1E3E,
  26322. Mcircle: 0x24C2,
  26323. Mdotaccent: 0x1E40,
  26324. Mdotbelow: 0x1E42,
  26325. Menarmenian: 0x0544,
  26326. Mmonospace: 0xFF2D,
  26327. Msmall: 0xF76D,
  26328. Mturned: 0x019C,
  26329. Mu: 0x039C,
  26330. N: 0x004E,
  26331. NJ: 0x01CA,
  26332. Nacute: 0x0143,
  26333. Ncaron: 0x0147,
  26334. Ncedilla: 0x0145,
  26335. Ncircle: 0x24C3,
  26336. Ncircumflexbelow: 0x1E4A,
  26337. Ncommaaccent: 0x0145,
  26338. Ndotaccent: 0x1E44,
  26339. Ndotbelow: 0x1E46,
  26340. Nhookleft: 0x019D,
  26341. Nineroman: 0x2168,
  26342. Nj: 0x01CB,
  26343. Njecyrillic: 0x040A,
  26344. Nlinebelow: 0x1E48,
  26345. Nmonospace: 0xFF2E,
  26346. Nowarmenian: 0x0546,
  26347. Nsmall: 0xF76E,
  26348. Ntilde: 0x00D1,
  26349. Ntildesmall: 0xF7F1,
  26350. Nu: 0x039D,
  26351. O: 0x004F,
  26352. OE: 0x0152,
  26353. OEsmall: 0xF6FA,
  26354. Oacute: 0x00D3,
  26355. Oacutesmall: 0xF7F3,
  26356. Obarredcyrillic: 0x04E8,
  26357. Obarreddieresiscyrillic: 0x04EA,
  26358. Obreve: 0x014E,
  26359. Ocaron: 0x01D1,
  26360. Ocenteredtilde: 0x019F,
  26361. Ocircle: 0x24C4,
  26362. Ocircumflex: 0x00D4,
  26363. Ocircumflexacute: 0x1ED0,
  26364. Ocircumflexdotbelow: 0x1ED8,
  26365. Ocircumflexgrave: 0x1ED2,
  26366. Ocircumflexhookabove: 0x1ED4,
  26367. Ocircumflexsmall: 0xF7F4,
  26368. Ocircumflextilde: 0x1ED6,
  26369. Ocyrillic: 0x041E,
  26370. Odblacute: 0x0150,
  26371. Odblgrave: 0x020C,
  26372. Odieresis: 0x00D6,
  26373. Odieresiscyrillic: 0x04E6,
  26374. Odieresissmall: 0xF7F6,
  26375. Odotbelow: 0x1ECC,
  26376. Ogoneksmall: 0xF6FB,
  26377. Ograve: 0x00D2,
  26378. Ogravesmall: 0xF7F2,
  26379. Oharmenian: 0x0555,
  26380. Ohm: 0x2126,
  26381. Ohookabove: 0x1ECE,
  26382. Ohorn: 0x01A0,
  26383. Ohornacute: 0x1EDA,
  26384. Ohorndotbelow: 0x1EE2,
  26385. Ohorngrave: 0x1EDC,
  26386. Ohornhookabove: 0x1EDE,
  26387. Ohorntilde: 0x1EE0,
  26388. Ohungarumlaut: 0x0150,
  26389. Oi: 0x01A2,
  26390. Oinvertedbreve: 0x020E,
  26391. Omacron: 0x014C,
  26392. Omacronacute: 0x1E52,
  26393. Omacrongrave: 0x1E50,
  26394. Omega: 0x2126,
  26395. Omegacyrillic: 0x0460,
  26396. Omegagreek: 0x03A9,
  26397. Omegaroundcyrillic: 0x047A,
  26398. Omegatitlocyrillic: 0x047C,
  26399. Omegatonos: 0x038F,
  26400. Omicron: 0x039F,
  26401. Omicrontonos: 0x038C,
  26402. Omonospace: 0xFF2F,
  26403. Oneroman: 0x2160,
  26404. Oogonek: 0x01EA,
  26405. Oogonekmacron: 0x01EC,
  26406. Oopen: 0x0186,
  26407. Oslash: 0x00D8,
  26408. Oslashacute: 0x01FE,
  26409. Oslashsmall: 0xF7F8,
  26410. Osmall: 0xF76F,
  26411. Ostrokeacute: 0x01FE,
  26412. Otcyrillic: 0x047E,
  26413. Otilde: 0x00D5,
  26414. Otildeacute: 0x1E4C,
  26415. Otildedieresis: 0x1E4E,
  26416. Otildesmall: 0xF7F5,
  26417. P: 0x0050,
  26418. Pacute: 0x1E54,
  26419. Pcircle: 0x24C5,
  26420. Pdotaccent: 0x1E56,
  26421. Pecyrillic: 0x041F,
  26422. Peharmenian: 0x054A,
  26423. Pemiddlehookcyrillic: 0x04A6,
  26424. Phi: 0x03A6,
  26425. Phook: 0x01A4,
  26426. Pi: 0x03A0,
  26427. Piwrarmenian: 0x0553,
  26428. Pmonospace: 0xFF30,
  26429. Psi: 0x03A8,
  26430. Psicyrillic: 0x0470,
  26431. Psmall: 0xF770,
  26432. Q: 0x0051,
  26433. Qcircle: 0x24C6,
  26434. Qmonospace: 0xFF31,
  26435. Qsmall: 0xF771,
  26436. R: 0x0052,
  26437. Raarmenian: 0x054C,
  26438. Racute: 0x0154,
  26439. Rcaron: 0x0158,
  26440. Rcedilla: 0x0156,
  26441. Rcircle: 0x24C7,
  26442. Rcommaaccent: 0x0156,
  26443. Rdblgrave: 0x0210,
  26444. Rdotaccent: 0x1E58,
  26445. Rdotbelow: 0x1E5A,
  26446. Rdotbelowmacron: 0x1E5C,
  26447. Reharmenian: 0x0550,
  26448. Rfraktur: 0x211C,
  26449. Rho: 0x03A1,
  26450. Ringsmall: 0xF6FC,
  26451. Rinvertedbreve: 0x0212,
  26452. Rlinebelow: 0x1E5E,
  26453. Rmonospace: 0xFF32,
  26454. Rsmall: 0xF772,
  26455. Rsmallinverted: 0x0281,
  26456. Rsmallinvertedsuperior: 0x02B6,
  26457. S: 0x0053,
  26458. SF010000: 0x250C,
  26459. SF020000: 0x2514,
  26460. SF030000: 0x2510,
  26461. SF040000: 0x2518,
  26462. SF050000: 0x253C,
  26463. SF060000: 0x252C,
  26464. SF070000: 0x2534,
  26465. SF080000: 0x251C,
  26466. SF090000: 0x2524,
  26467. SF100000: 0x2500,
  26468. SF110000: 0x2502,
  26469. SF190000: 0x2561,
  26470. SF200000: 0x2562,
  26471. SF210000: 0x2556,
  26472. SF220000: 0x2555,
  26473. SF230000: 0x2563,
  26474. SF240000: 0x2551,
  26475. SF250000: 0x2557,
  26476. SF260000: 0x255D,
  26477. SF270000: 0x255C,
  26478. SF280000: 0x255B,
  26479. SF360000: 0x255E,
  26480. SF370000: 0x255F,
  26481. SF380000: 0x255A,
  26482. SF390000: 0x2554,
  26483. SF400000: 0x2569,
  26484. SF410000: 0x2566,
  26485. SF420000: 0x2560,
  26486. SF430000: 0x2550,
  26487. SF440000: 0x256C,
  26488. SF450000: 0x2567,
  26489. SF460000: 0x2568,
  26490. SF470000: 0x2564,
  26491. SF480000: 0x2565,
  26492. SF490000: 0x2559,
  26493. SF500000: 0x2558,
  26494. SF510000: 0x2552,
  26495. SF520000: 0x2553,
  26496. SF530000: 0x256B,
  26497. SF540000: 0x256A,
  26498. Sacute: 0x015A,
  26499. Sacutedotaccent: 0x1E64,
  26500. Sampigreek: 0x03E0,
  26501. Scaron: 0x0160,
  26502. Scarondotaccent: 0x1E66,
  26503. Scaronsmall: 0xF6FD,
  26504. Scedilla: 0x015E,
  26505. Schwa: 0x018F,
  26506. Schwacyrillic: 0x04D8,
  26507. Schwadieresiscyrillic: 0x04DA,
  26508. Scircle: 0x24C8,
  26509. Scircumflex: 0x015C,
  26510. Scommaaccent: 0x0218,
  26511. Sdotaccent: 0x1E60,
  26512. Sdotbelow: 0x1E62,
  26513. Sdotbelowdotaccent: 0x1E68,
  26514. Seharmenian: 0x054D,
  26515. Sevenroman: 0x2166,
  26516. Shaarmenian: 0x0547,
  26517. Shacyrillic: 0x0428,
  26518. Shchacyrillic: 0x0429,
  26519. Sheicoptic: 0x03E2,
  26520. Shhacyrillic: 0x04BA,
  26521. Shimacoptic: 0x03EC,
  26522. Sigma: 0x03A3,
  26523. Sixroman: 0x2165,
  26524. Smonospace: 0xFF33,
  26525. Softsigncyrillic: 0x042C,
  26526. Ssmall: 0xF773,
  26527. Stigmagreek: 0x03DA,
  26528. T: 0x0054,
  26529. Tau: 0x03A4,
  26530. Tbar: 0x0166,
  26531. Tcaron: 0x0164,
  26532. Tcedilla: 0x0162,
  26533. Tcircle: 0x24C9,
  26534. Tcircumflexbelow: 0x1E70,
  26535. Tcommaaccent: 0x0162,
  26536. Tdotaccent: 0x1E6A,
  26537. Tdotbelow: 0x1E6C,
  26538. Tecyrillic: 0x0422,
  26539. Tedescendercyrillic: 0x04AC,
  26540. Tenroman: 0x2169,
  26541. Tetsecyrillic: 0x04B4,
  26542. Theta: 0x0398,
  26543. Thook: 0x01AC,
  26544. Thorn: 0x00DE,
  26545. Thornsmall: 0xF7FE,
  26546. Threeroman: 0x2162,
  26547. Tildesmall: 0xF6FE,
  26548. Tiwnarmenian: 0x054F,
  26549. Tlinebelow: 0x1E6E,
  26550. Tmonospace: 0xFF34,
  26551. Toarmenian: 0x0539,
  26552. Tonefive: 0x01BC,
  26553. Tonesix: 0x0184,
  26554. Tonetwo: 0x01A7,
  26555. Tretroflexhook: 0x01AE,
  26556. Tsecyrillic: 0x0426,
  26557. Tshecyrillic: 0x040B,
  26558. Tsmall: 0xF774,
  26559. Twelveroman: 0x216B,
  26560. Tworoman: 0x2161,
  26561. U: 0x0055,
  26562. Uacute: 0x00DA,
  26563. Uacutesmall: 0xF7FA,
  26564. Ubreve: 0x016C,
  26565. Ucaron: 0x01D3,
  26566. Ucircle: 0x24CA,
  26567. Ucircumflex: 0x00DB,
  26568. Ucircumflexbelow: 0x1E76,
  26569. Ucircumflexsmall: 0xF7FB,
  26570. Ucyrillic: 0x0423,
  26571. Udblacute: 0x0170,
  26572. Udblgrave: 0x0214,
  26573. Udieresis: 0x00DC,
  26574. Udieresisacute: 0x01D7,
  26575. Udieresisbelow: 0x1E72,
  26576. Udieresiscaron: 0x01D9,
  26577. Udieresiscyrillic: 0x04F0,
  26578. Udieresisgrave: 0x01DB,
  26579. Udieresismacron: 0x01D5,
  26580. Udieresissmall: 0xF7FC,
  26581. Udotbelow: 0x1EE4,
  26582. Ugrave: 0x00D9,
  26583. Ugravesmall: 0xF7F9,
  26584. Uhookabove: 0x1EE6,
  26585. Uhorn: 0x01AF,
  26586. Uhornacute: 0x1EE8,
  26587. Uhorndotbelow: 0x1EF0,
  26588. Uhorngrave: 0x1EEA,
  26589. Uhornhookabove: 0x1EEC,
  26590. Uhorntilde: 0x1EEE,
  26591. Uhungarumlaut: 0x0170,
  26592. Uhungarumlautcyrillic: 0x04F2,
  26593. Uinvertedbreve: 0x0216,
  26594. Ukcyrillic: 0x0478,
  26595. Umacron: 0x016A,
  26596. Umacroncyrillic: 0x04EE,
  26597. Umacrondieresis: 0x1E7A,
  26598. Umonospace: 0xFF35,
  26599. Uogonek: 0x0172,
  26600. Upsilon: 0x03A5,
  26601. Upsilon1: 0x03D2,
  26602. Upsilonacutehooksymbolgreek: 0x03D3,
  26603. Upsilonafrican: 0x01B1,
  26604. Upsilondieresis: 0x03AB,
  26605. Upsilondieresishooksymbolgreek: 0x03D4,
  26606. Upsilonhooksymbol: 0x03D2,
  26607. Upsilontonos: 0x038E,
  26608. Uring: 0x016E,
  26609. Ushortcyrillic: 0x040E,
  26610. Usmall: 0xF775,
  26611. Ustraightcyrillic: 0x04AE,
  26612. Ustraightstrokecyrillic: 0x04B0,
  26613. Utilde: 0x0168,
  26614. Utildeacute: 0x1E78,
  26615. Utildebelow: 0x1E74,
  26616. V: 0x0056,
  26617. Vcircle: 0x24CB,
  26618. Vdotbelow: 0x1E7E,
  26619. Vecyrillic: 0x0412,
  26620. Vewarmenian: 0x054E,
  26621. Vhook: 0x01B2,
  26622. Vmonospace: 0xFF36,
  26623. Voarmenian: 0x0548,
  26624. Vsmall: 0xF776,
  26625. Vtilde: 0x1E7C,
  26626. W: 0x0057,
  26627. Wacute: 0x1E82,
  26628. Wcircle: 0x24CC,
  26629. Wcircumflex: 0x0174,
  26630. Wdieresis: 0x1E84,
  26631. Wdotaccent: 0x1E86,
  26632. Wdotbelow: 0x1E88,
  26633. Wgrave: 0x1E80,
  26634. Wmonospace: 0xFF37,
  26635. Wsmall: 0xF777,
  26636. X: 0x0058,
  26637. Xcircle: 0x24CD,
  26638. Xdieresis: 0x1E8C,
  26639. Xdotaccent: 0x1E8A,
  26640. Xeharmenian: 0x053D,
  26641. Xi: 0x039E,
  26642. Xmonospace: 0xFF38,
  26643. Xsmall: 0xF778,
  26644. Y: 0x0059,
  26645. Yacute: 0x00DD,
  26646. Yacutesmall: 0xF7FD,
  26647. Yatcyrillic: 0x0462,
  26648. Ycircle: 0x24CE,
  26649. Ycircumflex: 0x0176,
  26650. Ydieresis: 0x0178,
  26651. Ydieresissmall: 0xF7FF,
  26652. Ydotaccent: 0x1E8E,
  26653. Ydotbelow: 0x1EF4,
  26654. Yericyrillic: 0x042B,
  26655. Yerudieresiscyrillic: 0x04F8,
  26656. Ygrave: 0x1EF2,
  26657. Yhook: 0x01B3,
  26658. Yhookabove: 0x1EF6,
  26659. Yiarmenian: 0x0545,
  26660. Yicyrillic: 0x0407,
  26661. Yiwnarmenian: 0x0552,
  26662. Ymonospace: 0xFF39,
  26663. Ysmall: 0xF779,
  26664. Ytilde: 0x1EF8,
  26665. Yusbigcyrillic: 0x046A,
  26666. Yusbigiotifiedcyrillic: 0x046C,
  26667. Yuslittlecyrillic: 0x0466,
  26668. Yuslittleiotifiedcyrillic: 0x0468,
  26669. Z: 0x005A,
  26670. Zaarmenian: 0x0536,
  26671. Zacute: 0x0179,
  26672. Zcaron: 0x017D,
  26673. Zcaronsmall: 0xF6FF,
  26674. Zcircle: 0x24CF,
  26675. Zcircumflex: 0x1E90,
  26676. Zdot: 0x017B,
  26677. Zdotaccent: 0x017B,
  26678. Zdotbelow: 0x1E92,
  26679. Zecyrillic: 0x0417,
  26680. Zedescendercyrillic: 0x0498,
  26681. Zedieresiscyrillic: 0x04DE,
  26682. Zeta: 0x0396,
  26683. Zhearmenian: 0x053A,
  26684. Zhebrevecyrillic: 0x04C1,
  26685. Zhecyrillic: 0x0416,
  26686. Zhedescendercyrillic: 0x0496,
  26687. Zhedieresiscyrillic: 0x04DC,
  26688. Zlinebelow: 0x1E94,
  26689. Zmonospace: 0xFF3A,
  26690. Zsmall: 0xF77A,
  26691. Zstroke: 0x01B5,
  26692. a: 0x0061,
  26693. aabengali: 0x0986,
  26694. aacute: 0x00E1,
  26695. aadeva: 0x0906,
  26696. aagujarati: 0x0A86,
  26697. aagurmukhi: 0x0A06,
  26698. aamatragurmukhi: 0x0A3E,
  26699. aarusquare: 0x3303,
  26700. aavowelsignbengali: 0x09BE,
  26701. aavowelsigndeva: 0x093E,
  26702. aavowelsigngujarati: 0x0ABE,
  26703. abbreviationmarkarmenian: 0x055F,
  26704. abbreviationsigndeva: 0x0970,
  26705. abengali: 0x0985,
  26706. abopomofo: 0x311A,
  26707. abreve: 0x0103,
  26708. abreveacute: 0x1EAF,
  26709. abrevecyrillic: 0x04D1,
  26710. abrevedotbelow: 0x1EB7,
  26711. abrevegrave: 0x1EB1,
  26712. abrevehookabove: 0x1EB3,
  26713. abrevetilde: 0x1EB5,
  26714. acaron: 0x01CE,
  26715. acircle: 0x24D0,
  26716. acircumflex: 0x00E2,
  26717. acircumflexacute: 0x1EA5,
  26718. acircumflexdotbelow: 0x1EAD,
  26719. acircumflexgrave: 0x1EA7,
  26720. acircumflexhookabove: 0x1EA9,
  26721. acircumflextilde: 0x1EAB,
  26722. acute: 0x00B4,
  26723. acutebelowcmb: 0x0317,
  26724. acutecmb: 0x0301,
  26725. acutecomb: 0x0301,
  26726. acutedeva: 0x0954,
  26727. acutelowmod: 0x02CF,
  26728. acutetonecmb: 0x0341,
  26729. acyrillic: 0x0430,
  26730. adblgrave: 0x0201,
  26731. addakgurmukhi: 0x0A71,
  26732. adeva: 0x0905,
  26733. adieresis: 0x00E4,
  26734. adieresiscyrillic: 0x04D3,
  26735. adieresismacron: 0x01DF,
  26736. adotbelow: 0x1EA1,
  26737. adotmacron: 0x01E1,
  26738. ae: 0x00E6,
  26739. aeacute: 0x01FD,
  26740. aekorean: 0x3150,
  26741. aemacron: 0x01E3,
  26742. afii00208: 0x2015,
  26743. afii08941: 0x20A4,
  26744. afii10017: 0x0410,
  26745. afii10018: 0x0411,
  26746. afii10019: 0x0412,
  26747. afii10020: 0x0413,
  26748. afii10021: 0x0414,
  26749. afii10022: 0x0415,
  26750. afii10023: 0x0401,
  26751. afii10024: 0x0416,
  26752. afii10025: 0x0417,
  26753. afii10026: 0x0418,
  26754. afii10027: 0x0419,
  26755. afii10028: 0x041A,
  26756. afii10029: 0x041B,
  26757. afii10030: 0x041C,
  26758. afii10031: 0x041D,
  26759. afii10032: 0x041E,
  26760. afii10033: 0x041F,
  26761. afii10034: 0x0420,
  26762. afii10035: 0x0421,
  26763. afii10036: 0x0422,
  26764. afii10037: 0x0423,
  26765. afii10038: 0x0424,
  26766. afii10039: 0x0425,
  26767. afii10040: 0x0426,
  26768. afii10041: 0x0427,
  26769. afii10042: 0x0428,
  26770. afii10043: 0x0429,
  26771. afii10044: 0x042A,
  26772. afii10045: 0x042B,
  26773. afii10046: 0x042C,
  26774. afii10047: 0x042D,
  26775. afii10048: 0x042E,
  26776. afii10049: 0x042F,
  26777. afii10050: 0x0490,
  26778. afii10051: 0x0402,
  26779. afii10052: 0x0403,
  26780. afii10053: 0x0404,
  26781. afii10054: 0x0405,
  26782. afii10055: 0x0406,
  26783. afii10056: 0x0407,
  26784. afii10057: 0x0408,
  26785. afii10058: 0x0409,
  26786. afii10059: 0x040A,
  26787. afii10060: 0x040B,
  26788. afii10061: 0x040C,
  26789. afii10062: 0x040E,
  26790. afii10063: 0xF6C4,
  26791. afii10064: 0xF6C5,
  26792. afii10065: 0x0430,
  26793. afii10066: 0x0431,
  26794. afii10067: 0x0432,
  26795. afii10068: 0x0433,
  26796. afii10069: 0x0434,
  26797. afii10070: 0x0435,
  26798. afii10071: 0x0451,
  26799. afii10072: 0x0436,
  26800. afii10073: 0x0437,
  26801. afii10074: 0x0438,
  26802. afii10075: 0x0439,
  26803. afii10076: 0x043A,
  26804. afii10077: 0x043B,
  26805. afii10078: 0x043C,
  26806. afii10079: 0x043D,
  26807. afii10080: 0x043E,
  26808. afii10081: 0x043F,
  26809. afii10082: 0x0440,
  26810. afii10083: 0x0441,
  26811. afii10084: 0x0442,
  26812. afii10085: 0x0443,
  26813. afii10086: 0x0444,
  26814. afii10087: 0x0445,
  26815. afii10088: 0x0446,
  26816. afii10089: 0x0447,
  26817. afii10090: 0x0448,
  26818. afii10091: 0x0449,
  26819. afii10092: 0x044A,
  26820. afii10093: 0x044B,
  26821. afii10094: 0x044C,
  26822. afii10095: 0x044D,
  26823. afii10096: 0x044E,
  26824. afii10097: 0x044F,
  26825. afii10098: 0x0491,
  26826. afii10099: 0x0452,
  26827. afii10100: 0x0453,
  26828. afii10101: 0x0454,
  26829. afii10102: 0x0455,
  26830. afii10103: 0x0456,
  26831. afii10104: 0x0457,
  26832. afii10105: 0x0458,
  26833. afii10106: 0x0459,
  26834. afii10107: 0x045A,
  26835. afii10108: 0x045B,
  26836. afii10109: 0x045C,
  26837. afii10110: 0x045E,
  26838. afii10145: 0x040F,
  26839. afii10146: 0x0462,
  26840. afii10147: 0x0472,
  26841. afii10148: 0x0474,
  26842. afii10192: 0xF6C6,
  26843. afii10193: 0x045F,
  26844. afii10194: 0x0463,
  26845. afii10195: 0x0473,
  26846. afii10196: 0x0475,
  26847. afii10831: 0xF6C7,
  26848. afii10832: 0xF6C8,
  26849. afii10846: 0x04D9,
  26850. afii299: 0x200E,
  26851. afii300: 0x200F,
  26852. afii301: 0x200D,
  26853. afii57381: 0x066A,
  26854. afii57388: 0x060C,
  26855. afii57392: 0x0660,
  26856. afii57393: 0x0661,
  26857. afii57394: 0x0662,
  26858. afii57395: 0x0663,
  26859. afii57396: 0x0664,
  26860. afii57397: 0x0665,
  26861. afii57398: 0x0666,
  26862. afii57399: 0x0667,
  26863. afii57400: 0x0668,
  26864. afii57401: 0x0669,
  26865. afii57403: 0x061B,
  26866. afii57407: 0x061F,
  26867. afii57409: 0x0621,
  26868. afii57410: 0x0622,
  26869. afii57411: 0x0623,
  26870. afii57412: 0x0624,
  26871. afii57413: 0x0625,
  26872. afii57414: 0x0626,
  26873. afii57415: 0x0627,
  26874. afii57416: 0x0628,
  26875. afii57417: 0x0629,
  26876. afii57418: 0x062A,
  26877. afii57419: 0x062B,
  26878. afii57420: 0x062C,
  26879. afii57421: 0x062D,
  26880. afii57422: 0x062E,
  26881. afii57423: 0x062F,
  26882. afii57424: 0x0630,
  26883. afii57425: 0x0631,
  26884. afii57426: 0x0632,
  26885. afii57427: 0x0633,
  26886. afii57428: 0x0634,
  26887. afii57429: 0x0635,
  26888. afii57430: 0x0636,
  26889. afii57431: 0x0637,
  26890. afii57432: 0x0638,
  26891. afii57433: 0x0639,
  26892. afii57434: 0x063A,
  26893. afii57440: 0x0640,
  26894. afii57441: 0x0641,
  26895. afii57442: 0x0642,
  26896. afii57443: 0x0643,
  26897. afii57444: 0x0644,
  26898. afii57445: 0x0645,
  26899. afii57446: 0x0646,
  26900. afii57448: 0x0648,
  26901. afii57449: 0x0649,
  26902. afii57450: 0x064A,
  26903. afii57451: 0x064B,
  26904. afii57452: 0x064C,
  26905. afii57453: 0x064D,
  26906. afii57454: 0x064E,
  26907. afii57455: 0x064F,
  26908. afii57456: 0x0650,
  26909. afii57457: 0x0651,
  26910. afii57458: 0x0652,
  26911. afii57470: 0x0647,
  26912. afii57505: 0x06A4,
  26913. afii57506: 0x067E,
  26914. afii57507: 0x0686,
  26915. afii57508: 0x0698,
  26916. afii57509: 0x06AF,
  26917. afii57511: 0x0679,
  26918. afii57512: 0x0688,
  26919. afii57513: 0x0691,
  26920. afii57514: 0x06BA,
  26921. afii57519: 0x06D2,
  26922. afii57534: 0x06D5,
  26923. afii57636: 0x20AA,
  26924. afii57645: 0x05BE,
  26925. afii57658: 0x05C3,
  26926. afii57664: 0x05D0,
  26927. afii57665: 0x05D1,
  26928. afii57666: 0x05D2,
  26929. afii57667: 0x05D3,
  26930. afii57668: 0x05D4,
  26931. afii57669: 0x05D5,
  26932. afii57670: 0x05D6,
  26933. afii57671: 0x05D7,
  26934. afii57672: 0x05D8,
  26935. afii57673: 0x05D9,
  26936. afii57674: 0x05DA,
  26937. afii57675: 0x05DB,
  26938. afii57676: 0x05DC,
  26939. afii57677: 0x05DD,
  26940. afii57678: 0x05DE,
  26941. afii57679: 0x05DF,
  26942. afii57680: 0x05E0,
  26943. afii57681: 0x05E1,
  26944. afii57682: 0x05E2,
  26945. afii57683: 0x05E3,
  26946. afii57684: 0x05E4,
  26947. afii57685: 0x05E5,
  26948. afii57686: 0x05E6,
  26949. afii57687: 0x05E7,
  26950. afii57688: 0x05E8,
  26951. afii57689: 0x05E9,
  26952. afii57690: 0x05EA,
  26953. afii57694: 0xFB2A,
  26954. afii57695: 0xFB2B,
  26955. afii57700: 0xFB4B,
  26956. afii57705: 0xFB1F,
  26957. afii57716: 0x05F0,
  26958. afii57717: 0x05F1,
  26959. afii57718: 0x05F2,
  26960. afii57723: 0xFB35,
  26961. afii57793: 0x05B4,
  26962. afii57794: 0x05B5,
  26963. afii57795: 0x05B6,
  26964. afii57796: 0x05BB,
  26965. afii57797: 0x05B8,
  26966. afii57798: 0x05B7,
  26967. afii57799: 0x05B0,
  26968. afii57800: 0x05B2,
  26969. afii57801: 0x05B1,
  26970. afii57802: 0x05B3,
  26971. afii57803: 0x05C2,
  26972. afii57804: 0x05C1,
  26973. afii57806: 0x05B9,
  26974. afii57807: 0x05BC,
  26975. afii57839: 0x05BD,
  26976. afii57841: 0x05BF,
  26977. afii57842: 0x05C0,
  26978. afii57929: 0x02BC,
  26979. afii61248: 0x2105,
  26980. afii61289: 0x2113,
  26981. afii61352: 0x2116,
  26982. afii61573: 0x202C,
  26983. afii61574: 0x202D,
  26984. afii61575: 0x202E,
  26985. afii61664: 0x200C,
  26986. afii63167: 0x066D,
  26987. afii64937: 0x02BD,
  26988. agrave: 0x00E0,
  26989. agujarati: 0x0A85,
  26990. agurmukhi: 0x0A05,
  26991. ahiragana: 0x3042,
  26992. ahookabove: 0x1EA3,
  26993. aibengali: 0x0990,
  26994. aibopomofo: 0x311E,
  26995. aideva: 0x0910,
  26996. aiecyrillic: 0x04D5,
  26997. aigujarati: 0x0A90,
  26998. aigurmukhi: 0x0A10,
  26999. aimatragurmukhi: 0x0A48,
  27000. ainarabic: 0x0639,
  27001. ainfinalarabic: 0xFECA,
  27002. aininitialarabic: 0xFECB,
  27003. ainmedialarabic: 0xFECC,
  27004. ainvertedbreve: 0x0203,
  27005. aivowelsignbengali: 0x09C8,
  27006. aivowelsigndeva: 0x0948,
  27007. aivowelsigngujarati: 0x0AC8,
  27008. akatakana: 0x30A2,
  27009. akatakanahalfwidth: 0xFF71,
  27010. akorean: 0x314F,
  27011. alef: 0x05D0,
  27012. alefarabic: 0x0627,
  27013. alefdageshhebrew: 0xFB30,
  27014. aleffinalarabic: 0xFE8E,
  27015. alefhamzaabovearabic: 0x0623,
  27016. alefhamzaabovefinalarabic: 0xFE84,
  27017. alefhamzabelowarabic: 0x0625,
  27018. alefhamzabelowfinalarabic: 0xFE88,
  27019. alefhebrew: 0x05D0,
  27020. aleflamedhebrew: 0xFB4F,
  27021. alefmaddaabovearabic: 0x0622,
  27022. alefmaddaabovefinalarabic: 0xFE82,
  27023. alefmaksuraarabic: 0x0649,
  27024. alefmaksurafinalarabic: 0xFEF0,
  27025. alefmaksurainitialarabic: 0xFEF3,
  27026. alefmaksuramedialarabic: 0xFEF4,
  27027. alefpatahhebrew: 0xFB2E,
  27028. alefqamatshebrew: 0xFB2F,
  27029. aleph: 0x2135,
  27030. allequal: 0x224C,
  27031. alpha: 0x03B1,
  27032. alphatonos: 0x03AC,
  27033. amacron: 0x0101,
  27034. amonospace: 0xFF41,
  27035. ampersand: 0x0026,
  27036. ampersandmonospace: 0xFF06,
  27037. ampersandsmall: 0xF726,
  27038. amsquare: 0x33C2,
  27039. anbopomofo: 0x3122,
  27040. angbopomofo: 0x3124,
  27041. angbracketleft: 0x3008, // This glyph is missing from Adobe's original list.
  27042. angbracketright: 0x3009, // This glyph is missing from Adobe's original list.
  27043. angkhankhuthai: 0x0E5A,
  27044. angle: 0x2220,
  27045. anglebracketleft: 0x3008,
  27046. anglebracketleftvertical: 0xFE3F,
  27047. anglebracketright: 0x3009,
  27048. anglebracketrightvertical: 0xFE40,
  27049. angleleft: 0x2329,
  27050. angleright: 0x232A,
  27051. angstrom: 0x212B,
  27052. anoteleia: 0x0387,
  27053. anudattadeva: 0x0952,
  27054. anusvarabengali: 0x0982,
  27055. anusvaradeva: 0x0902,
  27056. anusvaragujarati: 0x0A82,
  27057. aogonek: 0x0105,
  27058. apaatosquare: 0x3300,
  27059. aparen: 0x249C,
  27060. apostrophearmenian: 0x055A,
  27061. apostrophemod: 0x02BC,
  27062. apple: 0xF8FF,
  27063. approaches: 0x2250,
  27064. approxequal: 0x2248,
  27065. approxequalorimage: 0x2252,
  27066. approximatelyequal: 0x2245,
  27067. araeaekorean: 0x318E,
  27068. araeakorean: 0x318D,
  27069. arc: 0x2312,
  27070. arighthalfring: 0x1E9A,
  27071. aring: 0x00E5,
  27072. aringacute: 0x01FB,
  27073. aringbelow: 0x1E01,
  27074. arrowboth: 0x2194,
  27075. arrowdashdown: 0x21E3,
  27076. arrowdashleft: 0x21E0,
  27077. arrowdashright: 0x21E2,
  27078. arrowdashup: 0x21E1,
  27079. arrowdblboth: 0x21D4,
  27080. arrowdbldown: 0x21D3,
  27081. arrowdblleft: 0x21D0,
  27082. arrowdblright: 0x21D2,
  27083. arrowdblup: 0x21D1,
  27084. arrowdown: 0x2193,
  27085. arrowdownleft: 0x2199,
  27086. arrowdownright: 0x2198,
  27087. arrowdownwhite: 0x21E9,
  27088. arrowheaddownmod: 0x02C5,
  27089. arrowheadleftmod: 0x02C2,
  27090. arrowheadrightmod: 0x02C3,
  27091. arrowheadupmod: 0x02C4,
  27092. arrowhorizex: 0xF8E7,
  27093. arrowleft: 0x2190,
  27094. arrowleftdbl: 0x21D0,
  27095. arrowleftdblstroke: 0x21CD,
  27096. arrowleftoverright: 0x21C6,
  27097. arrowleftwhite: 0x21E6,
  27098. arrowright: 0x2192,
  27099. arrowrightdblstroke: 0x21CF,
  27100. arrowrightheavy: 0x279E,
  27101. arrowrightoverleft: 0x21C4,
  27102. arrowrightwhite: 0x21E8,
  27103. arrowtableft: 0x21E4,
  27104. arrowtabright: 0x21E5,
  27105. arrowup: 0x2191,
  27106. arrowupdn: 0x2195,
  27107. arrowupdnbse: 0x21A8,
  27108. arrowupdownbase: 0x21A8,
  27109. arrowupleft: 0x2196,
  27110. arrowupleftofdown: 0x21C5,
  27111. arrowupright: 0x2197,
  27112. arrowupwhite: 0x21E7,
  27113. arrowvertex: 0xF8E6,
  27114. asciicircum: 0x005E,
  27115. asciicircummonospace: 0xFF3E,
  27116. asciitilde: 0x007E,
  27117. asciitildemonospace: 0xFF5E,
  27118. ascript: 0x0251,
  27119. ascriptturned: 0x0252,
  27120. asmallhiragana: 0x3041,
  27121. asmallkatakana: 0x30A1,
  27122. asmallkatakanahalfwidth: 0xFF67,
  27123. asterisk: 0x002A,
  27124. asteriskaltonearabic: 0x066D,
  27125. asteriskarabic: 0x066D,
  27126. asteriskmath: 0x2217,
  27127. asteriskmonospace: 0xFF0A,
  27128. asterisksmall: 0xFE61,
  27129. asterism: 0x2042,
  27130. asuperior: 0xF6E9,
  27131. asymptoticallyequal: 0x2243,
  27132. at: 0x0040,
  27133. atilde: 0x00E3,
  27134. atmonospace: 0xFF20,
  27135. atsmall: 0xFE6B,
  27136. aturned: 0x0250,
  27137. aubengali: 0x0994,
  27138. aubopomofo: 0x3120,
  27139. audeva: 0x0914,
  27140. augujarati: 0x0A94,
  27141. augurmukhi: 0x0A14,
  27142. aulengthmarkbengali: 0x09D7,
  27143. aumatragurmukhi: 0x0A4C,
  27144. auvowelsignbengali: 0x09CC,
  27145. auvowelsigndeva: 0x094C,
  27146. auvowelsigngujarati: 0x0ACC,
  27147. avagrahadeva: 0x093D,
  27148. aybarmenian: 0x0561,
  27149. ayin: 0x05E2,
  27150. ayinaltonehebrew: 0xFB20,
  27151. ayinhebrew: 0x05E2,
  27152. b: 0x0062,
  27153. babengali: 0x09AC,
  27154. backslash: 0x005C,
  27155. backslashmonospace: 0xFF3C,
  27156. badeva: 0x092C,
  27157. bagujarati: 0x0AAC,
  27158. bagurmukhi: 0x0A2C,
  27159. bahiragana: 0x3070,
  27160. bahtthai: 0x0E3F,
  27161. bakatakana: 0x30D0,
  27162. bar: 0x007C,
  27163. barmonospace: 0xFF5C,
  27164. bbopomofo: 0x3105,
  27165. bcircle: 0x24D1,
  27166. bdotaccent: 0x1E03,
  27167. bdotbelow: 0x1E05,
  27168. beamedsixteenthnotes: 0x266C,
  27169. because: 0x2235,
  27170. becyrillic: 0x0431,
  27171. beharabic: 0x0628,
  27172. behfinalarabic: 0xFE90,
  27173. behinitialarabic: 0xFE91,
  27174. behiragana: 0x3079,
  27175. behmedialarabic: 0xFE92,
  27176. behmeeminitialarabic: 0xFC9F,
  27177. behmeemisolatedarabic: 0xFC08,
  27178. behnoonfinalarabic: 0xFC6D,
  27179. bekatakana: 0x30D9,
  27180. benarmenian: 0x0562,
  27181. bet: 0x05D1,
  27182. beta: 0x03B2,
  27183. betasymbolgreek: 0x03D0,
  27184. betdagesh: 0xFB31,
  27185. betdageshhebrew: 0xFB31,
  27186. bethebrew: 0x05D1,
  27187. betrafehebrew: 0xFB4C,
  27188. bhabengali: 0x09AD,
  27189. bhadeva: 0x092D,
  27190. bhagujarati: 0x0AAD,
  27191. bhagurmukhi: 0x0A2D,
  27192. bhook: 0x0253,
  27193. bihiragana: 0x3073,
  27194. bikatakana: 0x30D3,
  27195. bilabialclick: 0x0298,
  27196. bindigurmukhi: 0x0A02,
  27197. birusquare: 0x3331,
  27198. blackcircle: 0x25CF,
  27199. blackdiamond: 0x25C6,
  27200. blackdownpointingtriangle: 0x25BC,
  27201. blackleftpointingpointer: 0x25C4,
  27202. blackleftpointingtriangle: 0x25C0,
  27203. blacklenticularbracketleft: 0x3010,
  27204. blacklenticularbracketleftvertical: 0xFE3B,
  27205. blacklenticularbracketright: 0x3011,
  27206. blacklenticularbracketrightvertical: 0xFE3C,
  27207. blacklowerlefttriangle: 0x25E3,
  27208. blacklowerrighttriangle: 0x25E2,
  27209. blackrectangle: 0x25AC,
  27210. blackrightpointingpointer: 0x25BA,
  27211. blackrightpointingtriangle: 0x25B6,
  27212. blacksmallsquare: 0x25AA,
  27213. blacksmilingface: 0x263B,
  27214. blacksquare: 0x25A0,
  27215. blackstar: 0x2605,
  27216. blackupperlefttriangle: 0x25E4,
  27217. blackupperrighttriangle: 0x25E5,
  27218. blackuppointingsmalltriangle: 0x25B4,
  27219. blackuppointingtriangle: 0x25B2,
  27220. blank: 0x2423,
  27221. blinebelow: 0x1E07,
  27222. block: 0x2588,
  27223. bmonospace: 0xFF42,
  27224. bobaimaithai: 0x0E1A,
  27225. bohiragana: 0x307C,
  27226. bokatakana: 0x30DC,
  27227. bparen: 0x249D,
  27228. bqsquare: 0x33C3,
  27229. braceex: 0xF8F4,
  27230. braceleft: 0x007B,
  27231. braceleftbt: 0xF8F3,
  27232. braceleftmid: 0xF8F2,
  27233. braceleftmonospace: 0xFF5B,
  27234. braceleftsmall: 0xFE5B,
  27235. bracelefttp: 0xF8F1,
  27236. braceleftvertical: 0xFE37,
  27237. braceright: 0x007D,
  27238. bracerightbt: 0xF8FE,
  27239. bracerightmid: 0xF8FD,
  27240. bracerightmonospace: 0xFF5D,
  27241. bracerightsmall: 0xFE5C,
  27242. bracerighttp: 0xF8FC,
  27243. bracerightvertical: 0xFE38,
  27244. bracketleft: 0x005B,
  27245. bracketleftbt: 0xF8F0,
  27246. bracketleftex: 0xF8EF,
  27247. bracketleftmonospace: 0xFF3B,
  27248. bracketlefttp: 0xF8EE,
  27249. bracketright: 0x005D,
  27250. bracketrightbt: 0xF8FB,
  27251. bracketrightex: 0xF8FA,
  27252. bracketrightmonospace: 0xFF3D,
  27253. bracketrighttp: 0xF8F9,
  27254. breve: 0x02D8,
  27255. brevebelowcmb: 0x032E,
  27256. brevecmb: 0x0306,
  27257. breveinvertedbelowcmb: 0x032F,
  27258. breveinvertedcmb: 0x0311,
  27259. breveinverteddoublecmb: 0x0361,
  27260. bridgebelowcmb: 0x032A,
  27261. bridgeinvertedbelowcmb: 0x033A,
  27262. brokenbar: 0x00A6,
  27263. bstroke: 0x0180,
  27264. bsuperior: 0xF6EA,
  27265. btopbar: 0x0183,
  27266. buhiragana: 0x3076,
  27267. bukatakana: 0x30D6,
  27268. bullet: 0x2022,
  27269. bulletinverse: 0x25D8,
  27270. bulletoperator: 0x2219,
  27271. bullseye: 0x25CE,
  27272. c: 0x0063,
  27273. caarmenian: 0x056E,
  27274. cabengali: 0x099A,
  27275. cacute: 0x0107,
  27276. cadeva: 0x091A,
  27277. cagujarati: 0x0A9A,
  27278. cagurmukhi: 0x0A1A,
  27279. calsquare: 0x3388,
  27280. candrabindubengali: 0x0981,
  27281. candrabinducmb: 0x0310,
  27282. candrabindudeva: 0x0901,
  27283. candrabindugujarati: 0x0A81,
  27284. capslock: 0x21EA,
  27285. careof: 0x2105,
  27286. caron: 0x02C7,
  27287. caronbelowcmb: 0x032C,
  27288. caroncmb: 0x030C,
  27289. carriagereturn: 0x21B5,
  27290. cbopomofo: 0x3118,
  27291. ccaron: 0x010D,
  27292. ccedilla: 0x00E7,
  27293. ccedillaacute: 0x1E09,
  27294. ccircle: 0x24D2,
  27295. ccircumflex: 0x0109,
  27296. ccurl: 0x0255,
  27297. cdot: 0x010B,
  27298. cdotaccent: 0x010B,
  27299. cdsquare: 0x33C5,
  27300. cedilla: 0x00B8,
  27301. cedillacmb: 0x0327,
  27302. cent: 0x00A2,
  27303. centigrade: 0x2103,
  27304. centinferior: 0xF6DF,
  27305. centmonospace: 0xFFE0,
  27306. centoldstyle: 0xF7A2,
  27307. centsuperior: 0xF6E0,
  27308. chaarmenian: 0x0579,
  27309. chabengali: 0x099B,
  27310. chadeva: 0x091B,
  27311. chagujarati: 0x0A9B,
  27312. chagurmukhi: 0x0A1B,
  27313. chbopomofo: 0x3114,
  27314. cheabkhasiancyrillic: 0x04BD,
  27315. checkmark: 0x2713,
  27316. checyrillic: 0x0447,
  27317. chedescenderabkhasiancyrillic: 0x04BF,
  27318. chedescendercyrillic: 0x04B7,
  27319. chedieresiscyrillic: 0x04F5,
  27320. cheharmenian: 0x0573,
  27321. chekhakassiancyrillic: 0x04CC,
  27322. cheverticalstrokecyrillic: 0x04B9,
  27323. chi: 0x03C7,
  27324. chieuchacirclekorean: 0x3277,
  27325. chieuchaparenkorean: 0x3217,
  27326. chieuchcirclekorean: 0x3269,
  27327. chieuchkorean: 0x314A,
  27328. chieuchparenkorean: 0x3209,
  27329. chochangthai: 0x0E0A,
  27330. chochanthai: 0x0E08,
  27331. chochingthai: 0x0E09,
  27332. chochoethai: 0x0E0C,
  27333. chook: 0x0188,
  27334. cieucacirclekorean: 0x3276,
  27335. cieucaparenkorean: 0x3216,
  27336. cieuccirclekorean: 0x3268,
  27337. cieuckorean: 0x3148,
  27338. cieucparenkorean: 0x3208,
  27339. cieucuparenkorean: 0x321C,
  27340. circle: 0x25CB,
  27341. circlecopyrt: 0x00A9, // This glyph is missing from Adobe's original list.
  27342. circlemultiply: 0x2297,
  27343. circleot: 0x2299,
  27344. circleplus: 0x2295,
  27345. circlepostalmark: 0x3036,
  27346. circlewithlefthalfblack: 0x25D0,
  27347. circlewithrighthalfblack: 0x25D1,
  27348. circumflex: 0x02C6,
  27349. circumflexbelowcmb: 0x032D,
  27350. circumflexcmb: 0x0302,
  27351. clear: 0x2327,
  27352. clickalveolar: 0x01C2,
  27353. clickdental: 0x01C0,
  27354. clicklateral: 0x01C1,
  27355. clickretroflex: 0x01C3,
  27356. club: 0x2663,
  27357. clubsuitblack: 0x2663,
  27358. clubsuitwhite: 0x2667,
  27359. cmcubedsquare: 0x33A4,
  27360. cmonospace: 0xFF43,
  27361. cmsquaredsquare: 0x33A0,
  27362. coarmenian: 0x0581,
  27363. colon: 0x003A,
  27364. colonmonetary: 0x20A1,
  27365. colonmonospace: 0xFF1A,
  27366. colonsign: 0x20A1,
  27367. colonsmall: 0xFE55,
  27368. colontriangularhalfmod: 0x02D1,
  27369. colontriangularmod: 0x02D0,
  27370. comma: 0x002C,
  27371. commaabovecmb: 0x0313,
  27372. commaaboverightcmb: 0x0315,
  27373. commaaccent: 0xF6C3,
  27374. commaarabic: 0x060C,
  27375. commaarmenian: 0x055D,
  27376. commainferior: 0xF6E1,
  27377. commamonospace: 0xFF0C,
  27378. commareversedabovecmb: 0x0314,
  27379. commareversedmod: 0x02BD,
  27380. commasmall: 0xFE50,
  27381. commasuperior: 0xF6E2,
  27382. commaturnedabovecmb: 0x0312,
  27383. commaturnedmod: 0x02BB,
  27384. compass: 0x263C,
  27385. congruent: 0x2245,
  27386. contourintegral: 0x222E,
  27387. control: 0x2303,
  27388. controlACK: 0x0006,
  27389. controlBEL: 0x0007,
  27390. controlBS: 0x0008,
  27391. controlCAN: 0x0018,
  27392. controlCR: 0x000D,
  27393. controlDC1: 0x0011,
  27394. controlDC2: 0x0012,
  27395. controlDC3: 0x0013,
  27396. controlDC4: 0x0014,
  27397. controlDEL: 0x007F,
  27398. controlDLE: 0x0010,
  27399. controlEM: 0x0019,
  27400. controlENQ: 0x0005,
  27401. controlEOT: 0x0004,
  27402. controlESC: 0x001B,
  27403. controlETB: 0x0017,
  27404. controlETX: 0x0003,
  27405. controlFF: 0x000C,
  27406. controlFS: 0x001C,
  27407. controlGS: 0x001D,
  27408. controlHT: 0x0009,
  27409. controlLF: 0x000A,
  27410. controlNAK: 0x0015,
  27411. controlRS: 0x001E,
  27412. controlSI: 0x000F,
  27413. controlSO: 0x000E,
  27414. controlSOT: 0x0002,
  27415. controlSTX: 0x0001,
  27416. controlSUB: 0x001A,
  27417. controlSYN: 0x0016,
  27418. controlUS: 0x001F,
  27419. controlVT: 0x000B,
  27420. copyright: 0x00A9,
  27421. copyrightsans: 0xF8E9,
  27422. copyrightserif: 0xF6D9,
  27423. cornerbracketleft: 0x300C,
  27424. cornerbracketlefthalfwidth: 0xFF62,
  27425. cornerbracketleftvertical: 0xFE41,
  27426. cornerbracketright: 0x300D,
  27427. cornerbracketrighthalfwidth: 0xFF63,
  27428. cornerbracketrightvertical: 0xFE42,
  27429. corporationsquare: 0x337F,
  27430. cosquare: 0x33C7,
  27431. coverkgsquare: 0x33C6,
  27432. cparen: 0x249E,
  27433. cruzeiro: 0x20A2,
  27434. cstretched: 0x0297,
  27435. curlyand: 0x22CF,
  27436. curlyor: 0x22CE,
  27437. currency: 0x00A4,
  27438. cyrBreve: 0xF6D1,
  27439. cyrFlex: 0xF6D2,
  27440. cyrbreve: 0xF6D4,
  27441. cyrflex: 0xF6D5,
  27442. d: 0x0064,
  27443. daarmenian: 0x0564,
  27444. dabengali: 0x09A6,
  27445. dadarabic: 0x0636,
  27446. dadeva: 0x0926,
  27447. dadfinalarabic: 0xFEBE,
  27448. dadinitialarabic: 0xFEBF,
  27449. dadmedialarabic: 0xFEC0,
  27450. dagesh: 0x05BC,
  27451. dageshhebrew: 0x05BC,
  27452. dagger: 0x2020,
  27453. daggerdbl: 0x2021,
  27454. dagujarati: 0x0AA6,
  27455. dagurmukhi: 0x0A26,
  27456. dahiragana: 0x3060,
  27457. dakatakana: 0x30C0,
  27458. dalarabic: 0x062F,
  27459. dalet: 0x05D3,
  27460. daletdagesh: 0xFB33,
  27461. daletdageshhebrew: 0xFB33,
  27462. dalethebrew: 0x05D3,
  27463. dalfinalarabic: 0xFEAA,
  27464. dammaarabic: 0x064F,
  27465. dammalowarabic: 0x064F,
  27466. dammatanaltonearabic: 0x064C,
  27467. dammatanarabic: 0x064C,
  27468. danda: 0x0964,
  27469. dargahebrew: 0x05A7,
  27470. dargalefthebrew: 0x05A7,
  27471. dasiapneumatacyrilliccmb: 0x0485,
  27472. dblGrave: 0xF6D3,
  27473. dblanglebracketleft: 0x300A,
  27474. dblanglebracketleftvertical: 0xFE3D,
  27475. dblanglebracketright: 0x300B,
  27476. dblanglebracketrightvertical: 0xFE3E,
  27477. dblarchinvertedbelowcmb: 0x032B,
  27478. dblarrowleft: 0x21D4,
  27479. dblarrowright: 0x21D2,
  27480. dbldanda: 0x0965,
  27481. dblgrave: 0xF6D6,
  27482. dblgravecmb: 0x030F,
  27483. dblintegral: 0x222C,
  27484. dbllowline: 0x2017,
  27485. dbllowlinecmb: 0x0333,
  27486. dbloverlinecmb: 0x033F,
  27487. dblprimemod: 0x02BA,
  27488. dblverticalbar: 0x2016,
  27489. dblverticallineabovecmb: 0x030E,
  27490. dbopomofo: 0x3109,
  27491. dbsquare: 0x33C8,
  27492. dcaron: 0x010F,
  27493. dcedilla: 0x1E11,
  27494. dcircle: 0x24D3,
  27495. dcircumflexbelow: 0x1E13,
  27496. dcroat: 0x0111,
  27497. ddabengali: 0x09A1,
  27498. ddadeva: 0x0921,
  27499. ddagujarati: 0x0AA1,
  27500. ddagurmukhi: 0x0A21,
  27501. ddalarabic: 0x0688,
  27502. ddalfinalarabic: 0xFB89,
  27503. dddhadeva: 0x095C,
  27504. ddhabengali: 0x09A2,
  27505. ddhadeva: 0x0922,
  27506. ddhagujarati: 0x0AA2,
  27507. ddhagurmukhi: 0x0A22,
  27508. ddotaccent: 0x1E0B,
  27509. ddotbelow: 0x1E0D,
  27510. decimalseparatorarabic: 0x066B,
  27511. decimalseparatorpersian: 0x066B,
  27512. decyrillic: 0x0434,
  27513. degree: 0x00B0,
  27514. dehihebrew: 0x05AD,
  27515. dehiragana: 0x3067,
  27516. deicoptic: 0x03EF,
  27517. dekatakana: 0x30C7,
  27518. deleteleft: 0x232B,
  27519. deleteright: 0x2326,
  27520. delta: 0x03B4,
  27521. deltaturned: 0x018D,
  27522. denominatorminusonenumeratorbengali: 0x09F8,
  27523. dezh: 0x02A4,
  27524. dhabengali: 0x09A7,
  27525. dhadeva: 0x0927,
  27526. dhagujarati: 0x0AA7,
  27527. dhagurmukhi: 0x0A27,
  27528. dhook: 0x0257,
  27529. dialytikatonos: 0x0385,
  27530. dialytikatonoscmb: 0x0344,
  27531. diamond: 0x2666,
  27532. diamondsuitwhite: 0x2662,
  27533. dieresis: 0x00A8,
  27534. dieresisacute: 0xF6D7,
  27535. dieresisbelowcmb: 0x0324,
  27536. dieresiscmb: 0x0308,
  27537. dieresisgrave: 0xF6D8,
  27538. dieresistonos: 0x0385,
  27539. dihiragana: 0x3062,
  27540. dikatakana: 0x30C2,
  27541. dittomark: 0x3003,
  27542. divide: 0x00F7,
  27543. divides: 0x2223,
  27544. divisionslash: 0x2215,
  27545. djecyrillic: 0x0452,
  27546. dkshade: 0x2593,
  27547. dlinebelow: 0x1E0F,
  27548. dlsquare: 0x3397,
  27549. dmacron: 0x0111,
  27550. dmonospace: 0xFF44,
  27551. dnblock: 0x2584,
  27552. dochadathai: 0x0E0E,
  27553. dodekthai: 0x0E14,
  27554. dohiragana: 0x3069,
  27555. dokatakana: 0x30C9,
  27556. dollar: 0x0024,
  27557. dollarinferior: 0xF6E3,
  27558. dollarmonospace: 0xFF04,
  27559. dollaroldstyle: 0xF724,
  27560. dollarsmall: 0xFE69,
  27561. dollarsuperior: 0xF6E4,
  27562. dong: 0x20AB,
  27563. dorusquare: 0x3326,
  27564. dotaccent: 0x02D9,
  27565. dotaccentcmb: 0x0307,
  27566. dotbelowcmb: 0x0323,
  27567. dotbelowcomb: 0x0323,
  27568. dotkatakana: 0x30FB,
  27569. dotlessi: 0x0131,
  27570. dotlessj: 0xF6BE,
  27571. dotlessjstrokehook: 0x0284,
  27572. dotmath: 0x22C5,
  27573. dottedcircle: 0x25CC,
  27574. doubleyodpatah: 0xFB1F,
  27575. doubleyodpatahhebrew: 0xFB1F,
  27576. downtackbelowcmb: 0x031E,
  27577. downtackmod: 0x02D5,
  27578. dparen: 0x249F,
  27579. dsuperior: 0xF6EB,
  27580. dtail: 0x0256,
  27581. dtopbar: 0x018C,
  27582. duhiragana: 0x3065,
  27583. dukatakana: 0x30C5,
  27584. dz: 0x01F3,
  27585. dzaltone: 0x02A3,
  27586. dzcaron: 0x01C6,
  27587. dzcurl: 0x02A5,
  27588. dzeabkhasiancyrillic: 0x04E1,
  27589. dzecyrillic: 0x0455,
  27590. dzhecyrillic: 0x045F,
  27591. e: 0x0065,
  27592. eacute: 0x00E9,
  27593. earth: 0x2641,
  27594. ebengali: 0x098F,
  27595. ebopomofo: 0x311C,
  27596. ebreve: 0x0115,
  27597. ecandradeva: 0x090D,
  27598. ecandragujarati: 0x0A8D,
  27599. ecandravowelsigndeva: 0x0945,
  27600. ecandravowelsigngujarati: 0x0AC5,
  27601. ecaron: 0x011B,
  27602. ecedillabreve: 0x1E1D,
  27603. echarmenian: 0x0565,
  27604. echyiwnarmenian: 0x0587,
  27605. ecircle: 0x24D4,
  27606. ecircumflex: 0x00EA,
  27607. ecircumflexacute: 0x1EBF,
  27608. ecircumflexbelow: 0x1E19,
  27609. ecircumflexdotbelow: 0x1EC7,
  27610. ecircumflexgrave: 0x1EC1,
  27611. ecircumflexhookabove: 0x1EC3,
  27612. ecircumflextilde: 0x1EC5,
  27613. ecyrillic: 0x0454,
  27614. edblgrave: 0x0205,
  27615. edeva: 0x090F,
  27616. edieresis: 0x00EB,
  27617. edot: 0x0117,
  27618. edotaccent: 0x0117,
  27619. edotbelow: 0x1EB9,
  27620. eegurmukhi: 0x0A0F,
  27621. eematragurmukhi: 0x0A47,
  27622. efcyrillic: 0x0444,
  27623. egrave: 0x00E8,
  27624. egujarati: 0x0A8F,
  27625. eharmenian: 0x0567,
  27626. ehbopomofo: 0x311D,
  27627. ehiragana: 0x3048,
  27628. ehookabove: 0x1EBB,
  27629. eibopomofo: 0x311F,
  27630. eight: 0x0038,
  27631. eightarabic: 0x0668,
  27632. eightbengali: 0x09EE,
  27633. eightcircle: 0x2467,
  27634. eightcircleinversesansserif: 0x2791,
  27635. eightdeva: 0x096E,
  27636. eighteencircle: 0x2471,
  27637. eighteenparen: 0x2485,
  27638. eighteenperiod: 0x2499,
  27639. eightgujarati: 0x0AEE,
  27640. eightgurmukhi: 0x0A6E,
  27641. eighthackarabic: 0x0668,
  27642. eighthangzhou: 0x3028,
  27643. eighthnotebeamed: 0x266B,
  27644. eightideographicparen: 0x3227,
  27645. eightinferior: 0x2088,
  27646. eightmonospace: 0xFF18,
  27647. eightoldstyle: 0xF738,
  27648. eightparen: 0x247B,
  27649. eightperiod: 0x248F,
  27650. eightpersian: 0x06F8,
  27651. eightroman: 0x2177,
  27652. eightsuperior: 0x2078,
  27653. eightthai: 0x0E58,
  27654. einvertedbreve: 0x0207,
  27655. eiotifiedcyrillic: 0x0465,
  27656. ekatakana: 0x30A8,
  27657. ekatakanahalfwidth: 0xFF74,
  27658. ekonkargurmukhi: 0x0A74,
  27659. ekorean: 0x3154,
  27660. elcyrillic: 0x043B,
  27661. element: 0x2208,
  27662. elevencircle: 0x246A,
  27663. elevenparen: 0x247E,
  27664. elevenperiod: 0x2492,
  27665. elevenroman: 0x217A,
  27666. ellipsis: 0x2026,
  27667. ellipsisvertical: 0x22EE,
  27668. emacron: 0x0113,
  27669. emacronacute: 0x1E17,
  27670. emacrongrave: 0x1E15,
  27671. emcyrillic: 0x043C,
  27672. emdash: 0x2014,
  27673. emdashvertical: 0xFE31,
  27674. emonospace: 0xFF45,
  27675. emphasismarkarmenian: 0x055B,
  27676. emptyset: 0x2205,
  27677. enbopomofo: 0x3123,
  27678. encyrillic: 0x043D,
  27679. endash: 0x2013,
  27680. endashvertical: 0xFE32,
  27681. endescendercyrillic: 0x04A3,
  27682. eng: 0x014B,
  27683. engbopomofo: 0x3125,
  27684. enghecyrillic: 0x04A5,
  27685. enhookcyrillic: 0x04C8,
  27686. enspace: 0x2002,
  27687. eogonek: 0x0119,
  27688. eokorean: 0x3153,
  27689. eopen: 0x025B,
  27690. eopenclosed: 0x029A,
  27691. eopenreversed: 0x025C,
  27692. eopenreversedclosed: 0x025E,
  27693. eopenreversedhook: 0x025D,
  27694. eparen: 0x24A0,
  27695. epsilon: 0x03B5,
  27696. epsilontonos: 0x03AD,
  27697. equal: 0x003D,
  27698. equalmonospace: 0xFF1D,
  27699. equalsmall: 0xFE66,
  27700. equalsuperior: 0x207C,
  27701. equivalence: 0x2261,
  27702. erbopomofo: 0x3126,
  27703. ercyrillic: 0x0440,
  27704. ereversed: 0x0258,
  27705. ereversedcyrillic: 0x044D,
  27706. escyrillic: 0x0441,
  27707. esdescendercyrillic: 0x04AB,
  27708. esh: 0x0283,
  27709. eshcurl: 0x0286,
  27710. eshortdeva: 0x090E,
  27711. eshortvowelsigndeva: 0x0946,
  27712. eshreversedloop: 0x01AA,
  27713. eshsquatreversed: 0x0285,
  27714. esmallhiragana: 0x3047,
  27715. esmallkatakana: 0x30A7,
  27716. esmallkatakanahalfwidth: 0xFF6A,
  27717. estimated: 0x212E,
  27718. esuperior: 0xF6EC,
  27719. eta: 0x03B7,
  27720. etarmenian: 0x0568,
  27721. etatonos: 0x03AE,
  27722. eth: 0x00F0,
  27723. etilde: 0x1EBD,
  27724. etildebelow: 0x1E1B,
  27725. etnahtafoukhhebrew: 0x0591,
  27726. etnahtafoukhlefthebrew: 0x0591,
  27727. etnahtahebrew: 0x0591,
  27728. etnahtalefthebrew: 0x0591,
  27729. eturned: 0x01DD,
  27730. eukorean: 0x3161,
  27731. euro: 0x20AC,
  27732. evowelsignbengali: 0x09C7,
  27733. evowelsigndeva: 0x0947,
  27734. evowelsigngujarati: 0x0AC7,
  27735. exclam: 0x0021,
  27736. exclamarmenian: 0x055C,
  27737. exclamdbl: 0x203C,
  27738. exclamdown: 0x00A1,
  27739. exclamdownsmall: 0xF7A1,
  27740. exclammonospace: 0xFF01,
  27741. exclamsmall: 0xF721,
  27742. existential: 0x2203,
  27743. ezh: 0x0292,
  27744. ezhcaron: 0x01EF,
  27745. ezhcurl: 0x0293,
  27746. ezhreversed: 0x01B9,
  27747. ezhtail: 0x01BA,
  27748. f: 0x0066,
  27749. fadeva: 0x095E,
  27750. fagurmukhi: 0x0A5E,
  27751. fahrenheit: 0x2109,
  27752. fathaarabic: 0x064E,
  27753. fathalowarabic: 0x064E,
  27754. fathatanarabic: 0x064B,
  27755. fbopomofo: 0x3108,
  27756. fcircle: 0x24D5,
  27757. fdotaccent: 0x1E1F,
  27758. feharabic: 0x0641,
  27759. feharmenian: 0x0586,
  27760. fehfinalarabic: 0xFED2,
  27761. fehinitialarabic: 0xFED3,
  27762. fehmedialarabic: 0xFED4,
  27763. feicoptic: 0x03E5,
  27764. female: 0x2640,
  27765. ff: 0xFB00,
  27766. ffi: 0xFB03,
  27767. ffl: 0xFB04,
  27768. fi: 0xFB01,
  27769. fifteencircle: 0x246E,
  27770. fifteenparen: 0x2482,
  27771. fifteenperiod: 0x2496,
  27772. figuredash: 0x2012,
  27773. filledbox: 0x25A0,
  27774. filledrect: 0x25AC,
  27775. finalkaf: 0x05DA,
  27776. finalkafdagesh: 0xFB3A,
  27777. finalkafdageshhebrew: 0xFB3A,
  27778. finalkafhebrew: 0x05DA,
  27779. finalmem: 0x05DD,
  27780. finalmemhebrew: 0x05DD,
  27781. finalnun: 0x05DF,
  27782. finalnunhebrew: 0x05DF,
  27783. finalpe: 0x05E3,
  27784. finalpehebrew: 0x05E3,
  27785. finaltsadi: 0x05E5,
  27786. finaltsadihebrew: 0x05E5,
  27787. firsttonechinese: 0x02C9,
  27788. fisheye: 0x25C9,
  27789. fitacyrillic: 0x0473,
  27790. five: 0x0035,
  27791. fivearabic: 0x0665,
  27792. fivebengali: 0x09EB,
  27793. fivecircle: 0x2464,
  27794. fivecircleinversesansserif: 0x278E,
  27795. fivedeva: 0x096B,
  27796. fiveeighths: 0x215D,
  27797. fivegujarati: 0x0AEB,
  27798. fivegurmukhi: 0x0A6B,
  27799. fivehackarabic: 0x0665,
  27800. fivehangzhou: 0x3025,
  27801. fiveideographicparen: 0x3224,
  27802. fiveinferior: 0x2085,
  27803. fivemonospace: 0xFF15,
  27804. fiveoldstyle: 0xF735,
  27805. fiveparen: 0x2478,
  27806. fiveperiod: 0x248C,
  27807. fivepersian: 0x06F5,
  27808. fiveroman: 0x2174,
  27809. fivesuperior: 0x2075,
  27810. fivethai: 0x0E55,
  27811. fl: 0xFB02,
  27812. florin: 0x0192,
  27813. fmonospace: 0xFF46,
  27814. fmsquare: 0x3399,
  27815. fofanthai: 0x0E1F,
  27816. fofathai: 0x0E1D,
  27817. fongmanthai: 0x0E4F,
  27818. forall: 0x2200,
  27819. four: 0x0034,
  27820. fourarabic: 0x0664,
  27821. fourbengali: 0x09EA,
  27822. fourcircle: 0x2463,
  27823. fourcircleinversesansserif: 0x278D,
  27824. fourdeva: 0x096A,
  27825. fourgujarati: 0x0AEA,
  27826. fourgurmukhi: 0x0A6A,
  27827. fourhackarabic: 0x0664,
  27828. fourhangzhou: 0x3024,
  27829. fourideographicparen: 0x3223,
  27830. fourinferior: 0x2084,
  27831. fourmonospace: 0xFF14,
  27832. fournumeratorbengali: 0x09F7,
  27833. fouroldstyle: 0xF734,
  27834. fourparen: 0x2477,
  27835. fourperiod: 0x248B,
  27836. fourpersian: 0x06F4,
  27837. fourroman: 0x2173,
  27838. foursuperior: 0x2074,
  27839. fourteencircle: 0x246D,
  27840. fourteenparen: 0x2481,
  27841. fourteenperiod: 0x2495,
  27842. fourthai: 0x0E54,
  27843. fourthtonechinese: 0x02CB,
  27844. fparen: 0x24A1,
  27845. fraction: 0x2044,
  27846. franc: 0x20A3,
  27847. g: 0x0067,
  27848. gabengali: 0x0997,
  27849. gacute: 0x01F5,
  27850. gadeva: 0x0917,
  27851. gafarabic: 0x06AF,
  27852. gaffinalarabic: 0xFB93,
  27853. gafinitialarabic: 0xFB94,
  27854. gafmedialarabic: 0xFB95,
  27855. gagujarati: 0x0A97,
  27856. gagurmukhi: 0x0A17,
  27857. gahiragana: 0x304C,
  27858. gakatakana: 0x30AC,
  27859. gamma: 0x03B3,
  27860. gammalatinsmall: 0x0263,
  27861. gammasuperior: 0x02E0,
  27862. gangiacoptic: 0x03EB,
  27863. gbopomofo: 0x310D,
  27864. gbreve: 0x011F,
  27865. gcaron: 0x01E7,
  27866. gcedilla: 0x0123,
  27867. gcircle: 0x24D6,
  27868. gcircumflex: 0x011D,
  27869. gcommaaccent: 0x0123,
  27870. gdot: 0x0121,
  27871. gdotaccent: 0x0121,
  27872. gecyrillic: 0x0433,
  27873. gehiragana: 0x3052,
  27874. gekatakana: 0x30B2,
  27875. geometricallyequal: 0x2251,
  27876. gereshaccenthebrew: 0x059C,
  27877. gereshhebrew: 0x05F3,
  27878. gereshmuqdamhebrew: 0x059D,
  27879. germandbls: 0x00DF,
  27880. gershayimaccenthebrew: 0x059E,
  27881. gershayimhebrew: 0x05F4,
  27882. getamark: 0x3013,
  27883. ghabengali: 0x0998,
  27884. ghadarmenian: 0x0572,
  27885. ghadeva: 0x0918,
  27886. ghagujarati: 0x0A98,
  27887. ghagurmukhi: 0x0A18,
  27888. ghainarabic: 0x063A,
  27889. ghainfinalarabic: 0xFECE,
  27890. ghaininitialarabic: 0xFECF,
  27891. ghainmedialarabic: 0xFED0,
  27892. ghemiddlehookcyrillic: 0x0495,
  27893. ghestrokecyrillic: 0x0493,
  27894. gheupturncyrillic: 0x0491,
  27895. ghhadeva: 0x095A,
  27896. ghhagurmukhi: 0x0A5A,
  27897. ghook: 0x0260,
  27898. ghzsquare: 0x3393,
  27899. gihiragana: 0x304E,
  27900. gikatakana: 0x30AE,
  27901. gimarmenian: 0x0563,
  27902. gimel: 0x05D2,
  27903. gimeldagesh: 0xFB32,
  27904. gimeldageshhebrew: 0xFB32,
  27905. gimelhebrew: 0x05D2,
  27906. gjecyrillic: 0x0453,
  27907. glottalinvertedstroke: 0x01BE,
  27908. glottalstop: 0x0294,
  27909. glottalstopinverted: 0x0296,
  27910. glottalstopmod: 0x02C0,
  27911. glottalstopreversed: 0x0295,
  27912. glottalstopreversedmod: 0x02C1,
  27913. glottalstopreversedsuperior: 0x02E4,
  27914. glottalstopstroke: 0x02A1,
  27915. glottalstopstrokereversed: 0x02A2,
  27916. gmacron: 0x1E21,
  27917. gmonospace: 0xFF47,
  27918. gohiragana: 0x3054,
  27919. gokatakana: 0x30B4,
  27920. gparen: 0x24A2,
  27921. gpasquare: 0x33AC,
  27922. gradient: 0x2207,
  27923. grave: 0x0060,
  27924. gravebelowcmb: 0x0316,
  27925. gravecmb: 0x0300,
  27926. gravecomb: 0x0300,
  27927. gravedeva: 0x0953,
  27928. gravelowmod: 0x02CE,
  27929. gravemonospace: 0xFF40,
  27930. gravetonecmb: 0x0340,
  27931. greater: 0x003E,
  27932. greaterequal: 0x2265,
  27933. greaterequalorless: 0x22DB,
  27934. greatermonospace: 0xFF1E,
  27935. greaterorequivalent: 0x2273,
  27936. greaterorless: 0x2277,
  27937. greateroverequal: 0x2267,
  27938. greatersmall: 0xFE65,
  27939. gscript: 0x0261,
  27940. gstroke: 0x01E5,
  27941. guhiragana: 0x3050,
  27942. guillemotleft: 0x00AB,
  27943. guillemotright: 0x00BB,
  27944. guilsinglleft: 0x2039,
  27945. guilsinglright: 0x203A,
  27946. gukatakana: 0x30B0,
  27947. guramusquare: 0x3318,
  27948. gysquare: 0x33C9,
  27949. h: 0x0068,
  27950. haabkhasiancyrillic: 0x04A9,
  27951. haaltonearabic: 0x06C1,
  27952. habengali: 0x09B9,
  27953. hadescendercyrillic: 0x04B3,
  27954. hadeva: 0x0939,
  27955. hagujarati: 0x0AB9,
  27956. hagurmukhi: 0x0A39,
  27957. haharabic: 0x062D,
  27958. hahfinalarabic: 0xFEA2,
  27959. hahinitialarabic: 0xFEA3,
  27960. hahiragana: 0x306F,
  27961. hahmedialarabic: 0xFEA4,
  27962. haitusquare: 0x332A,
  27963. hakatakana: 0x30CF,
  27964. hakatakanahalfwidth: 0xFF8A,
  27965. halantgurmukhi: 0x0A4D,
  27966. hamzaarabic: 0x0621,
  27967. hamzalowarabic: 0x0621,
  27968. hangulfiller: 0x3164,
  27969. hardsigncyrillic: 0x044A,
  27970. harpoonleftbarbup: 0x21BC,
  27971. harpoonrightbarbup: 0x21C0,
  27972. hasquare: 0x33CA,
  27973. hatafpatah: 0x05B2,
  27974. hatafpatah16: 0x05B2,
  27975. hatafpatah23: 0x05B2,
  27976. hatafpatah2f: 0x05B2,
  27977. hatafpatahhebrew: 0x05B2,
  27978. hatafpatahnarrowhebrew: 0x05B2,
  27979. hatafpatahquarterhebrew: 0x05B2,
  27980. hatafpatahwidehebrew: 0x05B2,
  27981. hatafqamats: 0x05B3,
  27982. hatafqamats1b: 0x05B3,
  27983. hatafqamats28: 0x05B3,
  27984. hatafqamats34: 0x05B3,
  27985. hatafqamatshebrew: 0x05B3,
  27986. hatafqamatsnarrowhebrew: 0x05B3,
  27987. hatafqamatsquarterhebrew: 0x05B3,
  27988. hatafqamatswidehebrew: 0x05B3,
  27989. hatafsegol: 0x05B1,
  27990. hatafsegol17: 0x05B1,
  27991. hatafsegol24: 0x05B1,
  27992. hatafsegol30: 0x05B1,
  27993. hatafsegolhebrew: 0x05B1,
  27994. hatafsegolnarrowhebrew: 0x05B1,
  27995. hatafsegolquarterhebrew: 0x05B1,
  27996. hatafsegolwidehebrew: 0x05B1,
  27997. hbar: 0x0127,
  27998. hbopomofo: 0x310F,
  27999. hbrevebelow: 0x1E2B,
  28000. hcedilla: 0x1E29,
  28001. hcircle: 0x24D7,
  28002. hcircumflex: 0x0125,
  28003. hdieresis: 0x1E27,
  28004. hdotaccent: 0x1E23,
  28005. hdotbelow: 0x1E25,
  28006. he: 0x05D4,
  28007. heart: 0x2665,
  28008. heartsuitblack: 0x2665,
  28009. heartsuitwhite: 0x2661,
  28010. hedagesh: 0xFB34,
  28011. hedageshhebrew: 0xFB34,
  28012. hehaltonearabic: 0x06C1,
  28013. heharabic: 0x0647,
  28014. hehebrew: 0x05D4,
  28015. hehfinalaltonearabic: 0xFBA7,
  28016. hehfinalalttwoarabic: 0xFEEA,
  28017. hehfinalarabic: 0xFEEA,
  28018. hehhamzaabovefinalarabic: 0xFBA5,
  28019. hehhamzaaboveisolatedarabic: 0xFBA4,
  28020. hehinitialaltonearabic: 0xFBA8,
  28021. hehinitialarabic: 0xFEEB,
  28022. hehiragana: 0x3078,
  28023. hehmedialaltonearabic: 0xFBA9,
  28024. hehmedialarabic: 0xFEEC,
  28025. heiseierasquare: 0x337B,
  28026. hekatakana: 0x30D8,
  28027. hekatakanahalfwidth: 0xFF8D,
  28028. hekutaarusquare: 0x3336,
  28029. henghook: 0x0267,
  28030. herutusquare: 0x3339,
  28031. het: 0x05D7,
  28032. hethebrew: 0x05D7,
  28033. hhook: 0x0266,
  28034. hhooksuperior: 0x02B1,
  28035. hieuhacirclekorean: 0x327B,
  28036. hieuhaparenkorean: 0x321B,
  28037. hieuhcirclekorean: 0x326D,
  28038. hieuhkorean: 0x314E,
  28039. hieuhparenkorean: 0x320D,
  28040. hihiragana: 0x3072,
  28041. hikatakana: 0x30D2,
  28042. hikatakanahalfwidth: 0xFF8B,
  28043. hiriq: 0x05B4,
  28044. hiriq14: 0x05B4,
  28045. hiriq21: 0x05B4,
  28046. hiriq2d: 0x05B4,
  28047. hiriqhebrew: 0x05B4,
  28048. hiriqnarrowhebrew: 0x05B4,
  28049. hiriqquarterhebrew: 0x05B4,
  28050. hiriqwidehebrew: 0x05B4,
  28051. hlinebelow: 0x1E96,
  28052. hmonospace: 0xFF48,
  28053. hoarmenian: 0x0570,
  28054. hohipthai: 0x0E2B,
  28055. hohiragana: 0x307B,
  28056. hokatakana: 0x30DB,
  28057. hokatakanahalfwidth: 0xFF8E,
  28058. holam: 0x05B9,
  28059. holam19: 0x05B9,
  28060. holam26: 0x05B9,
  28061. holam32: 0x05B9,
  28062. holamhebrew: 0x05B9,
  28063. holamnarrowhebrew: 0x05B9,
  28064. holamquarterhebrew: 0x05B9,
  28065. holamwidehebrew: 0x05B9,
  28066. honokhukthai: 0x0E2E,
  28067. hookabovecomb: 0x0309,
  28068. hookcmb: 0x0309,
  28069. hookpalatalizedbelowcmb: 0x0321,
  28070. hookretroflexbelowcmb: 0x0322,
  28071. hoonsquare: 0x3342,
  28072. horicoptic: 0x03E9,
  28073. horizontalbar: 0x2015,
  28074. horncmb: 0x031B,
  28075. hotsprings: 0x2668,
  28076. house: 0x2302,
  28077. hparen: 0x24A3,
  28078. hsuperior: 0x02B0,
  28079. hturned: 0x0265,
  28080. huhiragana: 0x3075,
  28081. huiitosquare: 0x3333,
  28082. hukatakana: 0x30D5,
  28083. hukatakanahalfwidth: 0xFF8C,
  28084. hungarumlaut: 0x02DD,
  28085. hungarumlautcmb: 0x030B,
  28086. hv: 0x0195,
  28087. hyphen: 0x002D,
  28088. hypheninferior: 0xF6E5,
  28089. hyphenmonospace: 0xFF0D,
  28090. hyphensmall: 0xFE63,
  28091. hyphensuperior: 0xF6E6,
  28092. hyphentwo: 0x2010,
  28093. i: 0x0069,
  28094. iacute: 0x00ED,
  28095. iacyrillic: 0x044F,
  28096. ibengali: 0x0987,
  28097. ibopomofo: 0x3127,
  28098. ibreve: 0x012D,
  28099. icaron: 0x01D0,
  28100. icircle: 0x24D8,
  28101. icircumflex: 0x00EE,
  28102. icyrillic: 0x0456,
  28103. idblgrave: 0x0209,
  28104. ideographearthcircle: 0x328F,
  28105. ideographfirecircle: 0x328B,
  28106. ideographicallianceparen: 0x323F,
  28107. ideographiccallparen: 0x323A,
  28108. ideographiccentrecircle: 0x32A5,
  28109. ideographicclose: 0x3006,
  28110. ideographiccomma: 0x3001,
  28111. ideographiccommaleft: 0xFF64,
  28112. ideographiccongratulationparen: 0x3237,
  28113. ideographiccorrectcircle: 0x32A3,
  28114. ideographicearthparen: 0x322F,
  28115. ideographicenterpriseparen: 0x323D,
  28116. ideographicexcellentcircle: 0x329D,
  28117. ideographicfestivalparen: 0x3240,
  28118. ideographicfinancialcircle: 0x3296,
  28119. ideographicfinancialparen: 0x3236,
  28120. ideographicfireparen: 0x322B,
  28121. ideographichaveparen: 0x3232,
  28122. ideographichighcircle: 0x32A4,
  28123. ideographiciterationmark: 0x3005,
  28124. ideographiclaborcircle: 0x3298,
  28125. ideographiclaborparen: 0x3238,
  28126. ideographicleftcircle: 0x32A7,
  28127. ideographiclowcircle: 0x32A6,
  28128. ideographicmedicinecircle: 0x32A9,
  28129. ideographicmetalparen: 0x322E,
  28130. ideographicmoonparen: 0x322A,
  28131. ideographicnameparen: 0x3234,
  28132. ideographicperiod: 0x3002,
  28133. ideographicprintcircle: 0x329E,
  28134. ideographicreachparen: 0x3243,
  28135. ideographicrepresentparen: 0x3239,
  28136. ideographicresourceparen: 0x323E,
  28137. ideographicrightcircle: 0x32A8,
  28138. ideographicsecretcircle: 0x3299,
  28139. ideographicselfparen: 0x3242,
  28140. ideographicsocietyparen: 0x3233,
  28141. ideographicspace: 0x3000,
  28142. ideographicspecialparen: 0x3235,
  28143. ideographicstockparen: 0x3231,
  28144. ideographicstudyparen: 0x323B,
  28145. ideographicsunparen: 0x3230,
  28146. ideographicsuperviseparen: 0x323C,
  28147. ideographicwaterparen: 0x322C,
  28148. ideographicwoodparen: 0x322D,
  28149. ideographiczero: 0x3007,
  28150. ideographmetalcircle: 0x328E,
  28151. ideographmooncircle: 0x328A,
  28152. ideographnamecircle: 0x3294,
  28153. ideographsuncircle: 0x3290,
  28154. ideographwatercircle: 0x328C,
  28155. ideographwoodcircle: 0x328D,
  28156. ideva: 0x0907,
  28157. idieresis: 0x00EF,
  28158. idieresisacute: 0x1E2F,
  28159. idieresiscyrillic: 0x04E5,
  28160. idotbelow: 0x1ECB,
  28161. iebrevecyrillic: 0x04D7,
  28162. iecyrillic: 0x0435,
  28163. ieungacirclekorean: 0x3275,
  28164. ieungaparenkorean: 0x3215,
  28165. ieungcirclekorean: 0x3267,
  28166. ieungkorean: 0x3147,
  28167. ieungparenkorean: 0x3207,
  28168. igrave: 0x00EC,
  28169. igujarati: 0x0A87,
  28170. igurmukhi: 0x0A07,
  28171. ihiragana: 0x3044,
  28172. ihookabove: 0x1EC9,
  28173. iibengali: 0x0988,
  28174. iicyrillic: 0x0438,
  28175. iideva: 0x0908,
  28176. iigujarati: 0x0A88,
  28177. iigurmukhi: 0x0A08,
  28178. iimatragurmukhi: 0x0A40,
  28179. iinvertedbreve: 0x020B,
  28180. iishortcyrillic: 0x0439,
  28181. iivowelsignbengali: 0x09C0,
  28182. iivowelsigndeva: 0x0940,
  28183. iivowelsigngujarati: 0x0AC0,
  28184. ij: 0x0133,
  28185. ikatakana: 0x30A4,
  28186. ikatakanahalfwidth: 0xFF72,
  28187. ikorean: 0x3163,
  28188. ilde: 0x02DC,
  28189. iluyhebrew: 0x05AC,
  28190. imacron: 0x012B,
  28191. imacroncyrillic: 0x04E3,
  28192. imageorapproximatelyequal: 0x2253,
  28193. imatragurmukhi: 0x0A3F,
  28194. imonospace: 0xFF49,
  28195. increment: 0x2206,
  28196. infinity: 0x221E,
  28197. iniarmenian: 0x056B,
  28198. integral: 0x222B,
  28199. integralbottom: 0x2321,
  28200. integralbt: 0x2321,
  28201. integralex: 0xF8F5,
  28202. integraltop: 0x2320,
  28203. integraltp: 0x2320,
  28204. intersection: 0x2229,
  28205. intisquare: 0x3305,
  28206. invbullet: 0x25D8,
  28207. invcircle: 0x25D9,
  28208. invsmileface: 0x263B,
  28209. iocyrillic: 0x0451,
  28210. iogonek: 0x012F,
  28211. iota: 0x03B9,
  28212. iotadieresis: 0x03CA,
  28213. iotadieresistonos: 0x0390,
  28214. iotalatin: 0x0269,
  28215. iotatonos: 0x03AF,
  28216. iparen: 0x24A4,
  28217. irigurmukhi: 0x0A72,
  28218. ismallhiragana: 0x3043,
  28219. ismallkatakana: 0x30A3,
  28220. ismallkatakanahalfwidth: 0xFF68,
  28221. issharbengali: 0x09FA,
  28222. istroke: 0x0268,
  28223. isuperior: 0xF6ED,
  28224. iterationhiragana: 0x309D,
  28225. iterationkatakana: 0x30FD,
  28226. itilde: 0x0129,
  28227. itildebelow: 0x1E2D,
  28228. iubopomofo: 0x3129,
  28229. iucyrillic: 0x044E,
  28230. ivowelsignbengali: 0x09BF,
  28231. ivowelsigndeva: 0x093F,
  28232. ivowelsigngujarati: 0x0ABF,
  28233. izhitsacyrillic: 0x0475,
  28234. izhitsadblgravecyrillic: 0x0477,
  28235. j: 0x006A,
  28236. jaarmenian: 0x0571,
  28237. jabengali: 0x099C,
  28238. jadeva: 0x091C,
  28239. jagujarati: 0x0A9C,
  28240. jagurmukhi: 0x0A1C,
  28241. jbopomofo: 0x3110,
  28242. jcaron: 0x01F0,
  28243. jcircle: 0x24D9,
  28244. jcircumflex: 0x0135,
  28245. jcrossedtail: 0x029D,
  28246. jdotlessstroke: 0x025F,
  28247. jecyrillic: 0x0458,
  28248. jeemarabic: 0x062C,
  28249. jeemfinalarabic: 0xFE9E,
  28250. jeeminitialarabic: 0xFE9F,
  28251. jeemmedialarabic: 0xFEA0,
  28252. jeharabic: 0x0698,
  28253. jehfinalarabic: 0xFB8B,
  28254. jhabengali: 0x099D,
  28255. jhadeva: 0x091D,
  28256. jhagujarati: 0x0A9D,
  28257. jhagurmukhi: 0x0A1D,
  28258. jheharmenian: 0x057B,
  28259. jis: 0x3004,
  28260. jmonospace: 0xFF4A,
  28261. jparen: 0x24A5,
  28262. jsuperior: 0x02B2,
  28263. k: 0x006B,
  28264. kabashkircyrillic: 0x04A1,
  28265. kabengali: 0x0995,
  28266. kacute: 0x1E31,
  28267. kacyrillic: 0x043A,
  28268. kadescendercyrillic: 0x049B,
  28269. kadeva: 0x0915,
  28270. kaf: 0x05DB,
  28271. kafarabic: 0x0643,
  28272. kafdagesh: 0xFB3B,
  28273. kafdageshhebrew: 0xFB3B,
  28274. kaffinalarabic: 0xFEDA,
  28275. kafhebrew: 0x05DB,
  28276. kafinitialarabic: 0xFEDB,
  28277. kafmedialarabic: 0xFEDC,
  28278. kafrafehebrew: 0xFB4D,
  28279. kagujarati: 0x0A95,
  28280. kagurmukhi: 0x0A15,
  28281. kahiragana: 0x304B,
  28282. kahookcyrillic: 0x04C4,
  28283. kakatakana: 0x30AB,
  28284. kakatakanahalfwidth: 0xFF76,
  28285. kappa: 0x03BA,
  28286. kappasymbolgreek: 0x03F0,
  28287. kapyeounmieumkorean: 0x3171,
  28288. kapyeounphieuphkorean: 0x3184,
  28289. kapyeounpieupkorean: 0x3178,
  28290. kapyeounssangpieupkorean: 0x3179,
  28291. karoriisquare: 0x330D,
  28292. kashidaautoarabic: 0x0640,
  28293. kashidaautonosidebearingarabic: 0x0640,
  28294. kasmallkatakana: 0x30F5,
  28295. kasquare: 0x3384,
  28296. kasraarabic: 0x0650,
  28297. kasratanarabic: 0x064D,
  28298. kastrokecyrillic: 0x049F,
  28299. katahiraprolongmarkhalfwidth: 0xFF70,
  28300. kaverticalstrokecyrillic: 0x049D,
  28301. kbopomofo: 0x310E,
  28302. kcalsquare: 0x3389,
  28303. kcaron: 0x01E9,
  28304. kcedilla: 0x0137,
  28305. kcircle: 0x24DA,
  28306. kcommaaccent: 0x0137,
  28307. kdotbelow: 0x1E33,
  28308. keharmenian: 0x0584,
  28309. kehiragana: 0x3051,
  28310. kekatakana: 0x30B1,
  28311. kekatakanahalfwidth: 0xFF79,
  28312. kenarmenian: 0x056F,
  28313. kesmallkatakana: 0x30F6,
  28314. kgreenlandic: 0x0138,
  28315. khabengali: 0x0996,
  28316. khacyrillic: 0x0445,
  28317. khadeva: 0x0916,
  28318. khagujarati: 0x0A96,
  28319. khagurmukhi: 0x0A16,
  28320. khaharabic: 0x062E,
  28321. khahfinalarabic: 0xFEA6,
  28322. khahinitialarabic: 0xFEA7,
  28323. khahmedialarabic: 0xFEA8,
  28324. kheicoptic: 0x03E7,
  28325. khhadeva: 0x0959,
  28326. khhagurmukhi: 0x0A59,
  28327. khieukhacirclekorean: 0x3278,
  28328. khieukhaparenkorean: 0x3218,
  28329. khieukhcirclekorean: 0x326A,
  28330. khieukhkorean: 0x314B,
  28331. khieukhparenkorean: 0x320A,
  28332. khokhaithai: 0x0E02,
  28333. khokhonthai: 0x0E05,
  28334. khokhuatthai: 0x0E03,
  28335. khokhwaithai: 0x0E04,
  28336. khomutthai: 0x0E5B,
  28337. khook: 0x0199,
  28338. khorakhangthai: 0x0E06,
  28339. khzsquare: 0x3391,
  28340. kihiragana: 0x304D,
  28341. kikatakana: 0x30AD,
  28342. kikatakanahalfwidth: 0xFF77,
  28343. kiroguramusquare: 0x3315,
  28344. kiromeetorusquare: 0x3316,
  28345. kirosquare: 0x3314,
  28346. kiyeokacirclekorean: 0x326E,
  28347. kiyeokaparenkorean: 0x320E,
  28348. kiyeokcirclekorean: 0x3260,
  28349. kiyeokkorean: 0x3131,
  28350. kiyeokparenkorean: 0x3200,
  28351. kiyeoksioskorean: 0x3133,
  28352. kjecyrillic: 0x045C,
  28353. klinebelow: 0x1E35,
  28354. klsquare: 0x3398,
  28355. kmcubedsquare: 0x33A6,
  28356. kmonospace: 0xFF4B,
  28357. kmsquaredsquare: 0x33A2,
  28358. kohiragana: 0x3053,
  28359. kohmsquare: 0x33C0,
  28360. kokaithai: 0x0E01,
  28361. kokatakana: 0x30B3,
  28362. kokatakanahalfwidth: 0xFF7A,
  28363. kooposquare: 0x331E,
  28364. koppacyrillic: 0x0481,
  28365. koreanstandardsymbol: 0x327F,
  28366. koroniscmb: 0x0343,
  28367. kparen: 0x24A6,
  28368. kpasquare: 0x33AA,
  28369. ksicyrillic: 0x046F,
  28370. ktsquare: 0x33CF,
  28371. kturned: 0x029E,
  28372. kuhiragana: 0x304F,
  28373. kukatakana: 0x30AF,
  28374. kukatakanahalfwidth: 0xFF78,
  28375. kvsquare: 0x33B8,
  28376. kwsquare: 0x33BE,
  28377. l: 0x006C,
  28378. labengali: 0x09B2,
  28379. lacute: 0x013A,
  28380. ladeva: 0x0932,
  28381. lagujarati: 0x0AB2,
  28382. lagurmukhi: 0x0A32,
  28383. lakkhangyaothai: 0x0E45,
  28384. lamaleffinalarabic: 0xFEFC,
  28385. lamalefhamzaabovefinalarabic: 0xFEF8,
  28386. lamalefhamzaaboveisolatedarabic: 0xFEF7,
  28387. lamalefhamzabelowfinalarabic: 0xFEFA,
  28388. lamalefhamzabelowisolatedarabic: 0xFEF9,
  28389. lamalefisolatedarabic: 0xFEFB,
  28390. lamalefmaddaabovefinalarabic: 0xFEF6,
  28391. lamalefmaddaaboveisolatedarabic: 0xFEF5,
  28392. lamarabic: 0x0644,
  28393. lambda: 0x03BB,
  28394. lambdastroke: 0x019B,
  28395. lamed: 0x05DC,
  28396. lameddagesh: 0xFB3C,
  28397. lameddageshhebrew: 0xFB3C,
  28398. lamedhebrew: 0x05DC,
  28399. lamfinalarabic: 0xFEDE,
  28400. lamhahinitialarabic: 0xFCCA,
  28401. laminitialarabic: 0xFEDF,
  28402. lamjeeminitialarabic: 0xFCC9,
  28403. lamkhahinitialarabic: 0xFCCB,
  28404. lamlamhehisolatedarabic: 0xFDF2,
  28405. lammedialarabic: 0xFEE0,
  28406. lammeemhahinitialarabic: 0xFD88,
  28407. lammeeminitialarabic: 0xFCCC,
  28408. largecircle: 0x25EF,
  28409. lbar: 0x019A,
  28410. lbelt: 0x026C,
  28411. lbopomofo: 0x310C,
  28412. lcaron: 0x013E,
  28413. lcedilla: 0x013C,
  28414. lcircle: 0x24DB,
  28415. lcircumflexbelow: 0x1E3D,
  28416. lcommaaccent: 0x013C,
  28417. ldot: 0x0140,
  28418. ldotaccent: 0x0140,
  28419. ldotbelow: 0x1E37,
  28420. ldotbelowmacron: 0x1E39,
  28421. leftangleabovecmb: 0x031A,
  28422. lefttackbelowcmb: 0x0318,
  28423. less: 0x003C,
  28424. lessequal: 0x2264,
  28425. lessequalorgreater: 0x22DA,
  28426. lessmonospace: 0xFF1C,
  28427. lessorequivalent: 0x2272,
  28428. lessorgreater: 0x2276,
  28429. lessoverequal: 0x2266,
  28430. lesssmall: 0xFE64,
  28431. lezh: 0x026E,
  28432. lfblock: 0x258C,
  28433. lhookretroflex: 0x026D,
  28434. lira: 0x20A4,
  28435. liwnarmenian: 0x056C,
  28436. lj: 0x01C9,
  28437. ljecyrillic: 0x0459,
  28438. ll: 0xF6C0,
  28439. lladeva: 0x0933,
  28440. llagujarati: 0x0AB3,
  28441. llinebelow: 0x1E3B,
  28442. llladeva: 0x0934,
  28443. llvocalicbengali: 0x09E1,
  28444. llvocalicdeva: 0x0961,
  28445. llvocalicvowelsignbengali: 0x09E3,
  28446. llvocalicvowelsigndeva: 0x0963,
  28447. lmiddletilde: 0x026B,
  28448. lmonospace: 0xFF4C,
  28449. lmsquare: 0x33D0,
  28450. lochulathai: 0x0E2C,
  28451. logicaland: 0x2227,
  28452. logicalnot: 0x00AC,
  28453. logicalnotreversed: 0x2310,
  28454. logicalor: 0x2228,
  28455. lolingthai: 0x0E25,
  28456. longs: 0x017F,
  28457. lowlinecenterline: 0xFE4E,
  28458. lowlinecmb: 0x0332,
  28459. lowlinedashed: 0xFE4D,
  28460. lozenge: 0x25CA,
  28461. lparen: 0x24A7,
  28462. lslash: 0x0142,
  28463. lsquare: 0x2113,
  28464. lsuperior: 0xF6EE,
  28465. ltshade: 0x2591,
  28466. luthai: 0x0E26,
  28467. lvocalicbengali: 0x098C,
  28468. lvocalicdeva: 0x090C,
  28469. lvocalicvowelsignbengali: 0x09E2,
  28470. lvocalicvowelsigndeva: 0x0962,
  28471. lxsquare: 0x33D3,
  28472. m: 0x006D,
  28473. mabengali: 0x09AE,
  28474. macron: 0x00AF,
  28475. macronbelowcmb: 0x0331,
  28476. macroncmb: 0x0304,
  28477. macronlowmod: 0x02CD,
  28478. macronmonospace: 0xFFE3,
  28479. macute: 0x1E3F,
  28480. madeva: 0x092E,
  28481. magujarati: 0x0AAE,
  28482. magurmukhi: 0x0A2E,
  28483. mahapakhhebrew: 0x05A4,
  28484. mahapakhlefthebrew: 0x05A4,
  28485. mahiragana: 0x307E,
  28486. maichattawalowleftthai: 0xF895,
  28487. maichattawalowrightthai: 0xF894,
  28488. maichattawathai: 0x0E4B,
  28489. maichattawaupperleftthai: 0xF893,
  28490. maieklowleftthai: 0xF88C,
  28491. maieklowrightthai: 0xF88B,
  28492. maiekthai: 0x0E48,
  28493. maiekupperleftthai: 0xF88A,
  28494. maihanakatleftthai: 0xF884,
  28495. maihanakatthai: 0x0E31,
  28496. maitaikhuleftthai: 0xF889,
  28497. maitaikhuthai: 0x0E47,
  28498. maitholowleftthai: 0xF88F,
  28499. maitholowrightthai: 0xF88E,
  28500. maithothai: 0x0E49,
  28501. maithoupperleftthai: 0xF88D,
  28502. maitrilowleftthai: 0xF892,
  28503. maitrilowrightthai: 0xF891,
  28504. maitrithai: 0x0E4A,
  28505. maitriupperleftthai: 0xF890,
  28506. maiyamokthai: 0x0E46,
  28507. makatakana: 0x30DE,
  28508. makatakanahalfwidth: 0xFF8F,
  28509. male: 0x2642,
  28510. mansyonsquare: 0x3347,
  28511. maqafhebrew: 0x05BE,
  28512. mars: 0x2642,
  28513. masoracirclehebrew: 0x05AF,
  28514. masquare: 0x3383,
  28515. mbopomofo: 0x3107,
  28516. mbsquare: 0x33D4,
  28517. mcircle: 0x24DC,
  28518. mcubedsquare: 0x33A5,
  28519. mdotaccent: 0x1E41,
  28520. mdotbelow: 0x1E43,
  28521. meemarabic: 0x0645,
  28522. meemfinalarabic: 0xFEE2,
  28523. meeminitialarabic: 0xFEE3,
  28524. meemmedialarabic: 0xFEE4,
  28525. meemmeeminitialarabic: 0xFCD1,
  28526. meemmeemisolatedarabic: 0xFC48,
  28527. meetorusquare: 0x334D,
  28528. mehiragana: 0x3081,
  28529. meizierasquare: 0x337E,
  28530. mekatakana: 0x30E1,
  28531. mekatakanahalfwidth: 0xFF92,
  28532. mem: 0x05DE,
  28533. memdagesh: 0xFB3E,
  28534. memdageshhebrew: 0xFB3E,
  28535. memhebrew: 0x05DE,
  28536. menarmenian: 0x0574,
  28537. merkhahebrew: 0x05A5,
  28538. merkhakefulahebrew: 0x05A6,
  28539. merkhakefulalefthebrew: 0x05A6,
  28540. merkhalefthebrew: 0x05A5,
  28541. mhook: 0x0271,
  28542. mhzsquare: 0x3392,
  28543. middledotkatakanahalfwidth: 0xFF65,
  28544. middot: 0x00B7,
  28545. mieumacirclekorean: 0x3272,
  28546. mieumaparenkorean: 0x3212,
  28547. mieumcirclekorean: 0x3264,
  28548. mieumkorean: 0x3141,
  28549. mieumpansioskorean: 0x3170,
  28550. mieumparenkorean: 0x3204,
  28551. mieumpieupkorean: 0x316E,
  28552. mieumsioskorean: 0x316F,
  28553. mihiragana: 0x307F,
  28554. mikatakana: 0x30DF,
  28555. mikatakanahalfwidth: 0xFF90,
  28556. minus: 0x2212,
  28557. minusbelowcmb: 0x0320,
  28558. minuscircle: 0x2296,
  28559. minusmod: 0x02D7,
  28560. minusplus: 0x2213,
  28561. minute: 0x2032,
  28562. miribaarusquare: 0x334A,
  28563. mirisquare: 0x3349,
  28564. mlonglegturned: 0x0270,
  28565. mlsquare: 0x3396,
  28566. mmcubedsquare: 0x33A3,
  28567. mmonospace: 0xFF4D,
  28568. mmsquaredsquare: 0x339F,
  28569. mohiragana: 0x3082,
  28570. mohmsquare: 0x33C1,
  28571. mokatakana: 0x30E2,
  28572. mokatakanahalfwidth: 0xFF93,
  28573. molsquare: 0x33D6,
  28574. momathai: 0x0E21,
  28575. moverssquare: 0x33A7,
  28576. moverssquaredsquare: 0x33A8,
  28577. mparen: 0x24A8,
  28578. mpasquare: 0x33AB,
  28579. mssquare: 0x33B3,
  28580. msuperior: 0xF6EF,
  28581. mturned: 0x026F,
  28582. mu: 0x00B5,
  28583. mu1: 0x00B5,
  28584. muasquare: 0x3382,
  28585. muchgreater: 0x226B,
  28586. muchless: 0x226A,
  28587. mufsquare: 0x338C,
  28588. mugreek: 0x03BC,
  28589. mugsquare: 0x338D,
  28590. muhiragana: 0x3080,
  28591. mukatakana: 0x30E0,
  28592. mukatakanahalfwidth: 0xFF91,
  28593. mulsquare: 0x3395,
  28594. multiply: 0x00D7,
  28595. mumsquare: 0x339B,
  28596. munahhebrew: 0x05A3,
  28597. munahlefthebrew: 0x05A3,
  28598. musicalnote: 0x266A,
  28599. musicalnotedbl: 0x266B,
  28600. musicflatsign: 0x266D,
  28601. musicsharpsign: 0x266F,
  28602. mussquare: 0x33B2,
  28603. muvsquare: 0x33B6,
  28604. muwsquare: 0x33BC,
  28605. mvmegasquare: 0x33B9,
  28606. mvsquare: 0x33B7,
  28607. mwmegasquare: 0x33BF,
  28608. mwsquare: 0x33BD,
  28609. n: 0x006E,
  28610. nabengali: 0x09A8,
  28611. nabla: 0x2207,
  28612. nacute: 0x0144,
  28613. nadeva: 0x0928,
  28614. nagujarati: 0x0AA8,
  28615. nagurmukhi: 0x0A28,
  28616. nahiragana: 0x306A,
  28617. nakatakana: 0x30CA,
  28618. nakatakanahalfwidth: 0xFF85,
  28619. napostrophe: 0x0149,
  28620. nasquare: 0x3381,
  28621. nbopomofo: 0x310B,
  28622. nbspace: 0x00A0,
  28623. ncaron: 0x0148,
  28624. ncedilla: 0x0146,
  28625. ncircle: 0x24DD,
  28626. ncircumflexbelow: 0x1E4B,
  28627. ncommaaccent: 0x0146,
  28628. ndotaccent: 0x1E45,
  28629. ndotbelow: 0x1E47,
  28630. nehiragana: 0x306D,
  28631. nekatakana: 0x30CD,
  28632. nekatakanahalfwidth: 0xFF88,
  28633. newsheqelsign: 0x20AA,
  28634. nfsquare: 0x338B,
  28635. ngabengali: 0x0999,
  28636. ngadeva: 0x0919,
  28637. ngagujarati: 0x0A99,
  28638. ngagurmukhi: 0x0A19,
  28639. ngonguthai: 0x0E07,
  28640. nhiragana: 0x3093,
  28641. nhookleft: 0x0272,
  28642. nhookretroflex: 0x0273,
  28643. nieunacirclekorean: 0x326F,
  28644. nieunaparenkorean: 0x320F,
  28645. nieuncieuckorean: 0x3135,
  28646. nieuncirclekorean: 0x3261,
  28647. nieunhieuhkorean: 0x3136,
  28648. nieunkorean: 0x3134,
  28649. nieunpansioskorean: 0x3168,
  28650. nieunparenkorean: 0x3201,
  28651. nieunsioskorean: 0x3167,
  28652. nieuntikeutkorean: 0x3166,
  28653. nihiragana: 0x306B,
  28654. nikatakana: 0x30CB,
  28655. nikatakanahalfwidth: 0xFF86,
  28656. nikhahitleftthai: 0xF899,
  28657. nikhahitthai: 0x0E4D,
  28658. nine: 0x0039,
  28659. ninearabic: 0x0669,
  28660. ninebengali: 0x09EF,
  28661. ninecircle: 0x2468,
  28662. ninecircleinversesansserif: 0x2792,
  28663. ninedeva: 0x096F,
  28664. ninegujarati: 0x0AEF,
  28665. ninegurmukhi: 0x0A6F,
  28666. ninehackarabic: 0x0669,
  28667. ninehangzhou: 0x3029,
  28668. nineideographicparen: 0x3228,
  28669. nineinferior: 0x2089,
  28670. ninemonospace: 0xFF19,
  28671. nineoldstyle: 0xF739,
  28672. nineparen: 0x247C,
  28673. nineperiod: 0x2490,
  28674. ninepersian: 0x06F9,
  28675. nineroman: 0x2178,
  28676. ninesuperior: 0x2079,
  28677. nineteencircle: 0x2472,
  28678. nineteenparen: 0x2486,
  28679. nineteenperiod: 0x249A,
  28680. ninethai: 0x0E59,
  28681. nj: 0x01CC,
  28682. njecyrillic: 0x045A,
  28683. nkatakana: 0x30F3,
  28684. nkatakanahalfwidth: 0xFF9D,
  28685. nlegrightlong: 0x019E,
  28686. nlinebelow: 0x1E49,
  28687. nmonospace: 0xFF4E,
  28688. nmsquare: 0x339A,
  28689. nnabengali: 0x09A3,
  28690. nnadeva: 0x0923,
  28691. nnagujarati: 0x0AA3,
  28692. nnagurmukhi: 0x0A23,
  28693. nnnadeva: 0x0929,
  28694. nohiragana: 0x306E,
  28695. nokatakana: 0x30CE,
  28696. nokatakanahalfwidth: 0xFF89,
  28697. nonbreakingspace: 0x00A0,
  28698. nonenthai: 0x0E13,
  28699. nonuthai: 0x0E19,
  28700. noonarabic: 0x0646,
  28701. noonfinalarabic: 0xFEE6,
  28702. noonghunnaarabic: 0x06BA,
  28703. noonghunnafinalarabic: 0xFB9F,
  28704. nooninitialarabic: 0xFEE7,
  28705. noonjeeminitialarabic: 0xFCD2,
  28706. noonjeemisolatedarabic: 0xFC4B,
  28707. noonmedialarabic: 0xFEE8,
  28708. noonmeeminitialarabic: 0xFCD5,
  28709. noonmeemisolatedarabic: 0xFC4E,
  28710. noonnoonfinalarabic: 0xFC8D,
  28711. notcontains: 0x220C,
  28712. notelement: 0x2209,
  28713. notelementof: 0x2209,
  28714. notequal: 0x2260,
  28715. notgreater: 0x226F,
  28716. notgreaternorequal: 0x2271,
  28717. notgreaternorless: 0x2279,
  28718. notidentical: 0x2262,
  28719. notless: 0x226E,
  28720. notlessnorequal: 0x2270,
  28721. notparallel: 0x2226,
  28722. notprecedes: 0x2280,
  28723. notsubset: 0x2284,
  28724. notsucceeds: 0x2281,
  28725. notsuperset: 0x2285,
  28726. nowarmenian: 0x0576,
  28727. nparen: 0x24A9,
  28728. nssquare: 0x33B1,
  28729. nsuperior: 0x207F,
  28730. ntilde: 0x00F1,
  28731. nu: 0x03BD,
  28732. nuhiragana: 0x306C,
  28733. nukatakana: 0x30CC,
  28734. nukatakanahalfwidth: 0xFF87,
  28735. nuktabengali: 0x09BC,
  28736. nuktadeva: 0x093C,
  28737. nuktagujarati: 0x0ABC,
  28738. nuktagurmukhi: 0x0A3C,
  28739. numbersign: 0x0023,
  28740. numbersignmonospace: 0xFF03,
  28741. numbersignsmall: 0xFE5F,
  28742. numeralsigngreek: 0x0374,
  28743. numeralsignlowergreek: 0x0375,
  28744. numero: 0x2116,
  28745. nun: 0x05E0,
  28746. nundagesh: 0xFB40,
  28747. nundageshhebrew: 0xFB40,
  28748. nunhebrew: 0x05E0,
  28749. nvsquare: 0x33B5,
  28750. nwsquare: 0x33BB,
  28751. nyabengali: 0x099E,
  28752. nyadeva: 0x091E,
  28753. nyagujarati: 0x0A9E,
  28754. nyagurmukhi: 0x0A1E,
  28755. o: 0x006F,
  28756. oacute: 0x00F3,
  28757. oangthai: 0x0E2D,
  28758. obarred: 0x0275,
  28759. obarredcyrillic: 0x04E9,
  28760. obarreddieresiscyrillic: 0x04EB,
  28761. obengali: 0x0993,
  28762. obopomofo: 0x311B,
  28763. obreve: 0x014F,
  28764. ocandradeva: 0x0911,
  28765. ocandragujarati: 0x0A91,
  28766. ocandravowelsigndeva: 0x0949,
  28767. ocandravowelsigngujarati: 0x0AC9,
  28768. ocaron: 0x01D2,
  28769. ocircle: 0x24DE,
  28770. ocircumflex: 0x00F4,
  28771. ocircumflexacute: 0x1ED1,
  28772. ocircumflexdotbelow: 0x1ED9,
  28773. ocircumflexgrave: 0x1ED3,
  28774. ocircumflexhookabove: 0x1ED5,
  28775. ocircumflextilde: 0x1ED7,
  28776. ocyrillic: 0x043E,
  28777. odblacute: 0x0151,
  28778. odblgrave: 0x020D,
  28779. odeva: 0x0913,
  28780. odieresis: 0x00F6,
  28781. odieresiscyrillic: 0x04E7,
  28782. odotbelow: 0x1ECD,
  28783. oe: 0x0153,
  28784. oekorean: 0x315A,
  28785. ogonek: 0x02DB,
  28786. ogonekcmb: 0x0328,
  28787. ograve: 0x00F2,
  28788. ogujarati: 0x0A93,
  28789. oharmenian: 0x0585,
  28790. ohiragana: 0x304A,
  28791. ohookabove: 0x1ECF,
  28792. ohorn: 0x01A1,
  28793. ohornacute: 0x1EDB,
  28794. ohorndotbelow: 0x1EE3,
  28795. ohorngrave: 0x1EDD,
  28796. ohornhookabove: 0x1EDF,
  28797. ohorntilde: 0x1EE1,
  28798. ohungarumlaut: 0x0151,
  28799. oi: 0x01A3,
  28800. oinvertedbreve: 0x020F,
  28801. okatakana: 0x30AA,
  28802. okatakanahalfwidth: 0xFF75,
  28803. okorean: 0x3157,
  28804. olehebrew: 0x05AB,
  28805. omacron: 0x014D,
  28806. omacronacute: 0x1E53,
  28807. omacrongrave: 0x1E51,
  28808. omdeva: 0x0950,
  28809. omega: 0x03C9,
  28810. omega1: 0x03D6,
  28811. omegacyrillic: 0x0461,
  28812. omegalatinclosed: 0x0277,
  28813. omegaroundcyrillic: 0x047B,
  28814. omegatitlocyrillic: 0x047D,
  28815. omegatonos: 0x03CE,
  28816. omgujarati: 0x0AD0,
  28817. omicron: 0x03BF,
  28818. omicrontonos: 0x03CC,
  28819. omonospace: 0xFF4F,
  28820. one: 0x0031,
  28821. onearabic: 0x0661,
  28822. onebengali: 0x09E7,
  28823. onecircle: 0x2460,
  28824. onecircleinversesansserif: 0x278A,
  28825. onedeva: 0x0967,
  28826. onedotenleader: 0x2024,
  28827. oneeighth: 0x215B,
  28828. onefitted: 0xF6DC,
  28829. onegujarati: 0x0AE7,
  28830. onegurmukhi: 0x0A67,
  28831. onehackarabic: 0x0661,
  28832. onehalf: 0x00BD,
  28833. onehangzhou: 0x3021,
  28834. oneideographicparen: 0x3220,
  28835. oneinferior: 0x2081,
  28836. onemonospace: 0xFF11,
  28837. onenumeratorbengali: 0x09F4,
  28838. oneoldstyle: 0xF731,
  28839. oneparen: 0x2474,
  28840. oneperiod: 0x2488,
  28841. onepersian: 0x06F1,
  28842. onequarter: 0x00BC,
  28843. oneroman: 0x2170,
  28844. onesuperior: 0x00B9,
  28845. onethai: 0x0E51,
  28846. onethird: 0x2153,
  28847. oogonek: 0x01EB,
  28848. oogonekmacron: 0x01ED,
  28849. oogurmukhi: 0x0A13,
  28850. oomatragurmukhi: 0x0A4B,
  28851. oopen: 0x0254,
  28852. oparen: 0x24AA,
  28853. openbullet: 0x25E6,
  28854. option: 0x2325,
  28855. ordfeminine: 0x00AA,
  28856. ordmasculine: 0x00BA,
  28857. orthogonal: 0x221F,
  28858. oshortdeva: 0x0912,
  28859. oshortvowelsigndeva: 0x094A,
  28860. oslash: 0x00F8,
  28861. oslashacute: 0x01FF,
  28862. osmallhiragana: 0x3049,
  28863. osmallkatakana: 0x30A9,
  28864. osmallkatakanahalfwidth: 0xFF6B,
  28865. ostrokeacute: 0x01FF,
  28866. osuperior: 0xF6F0,
  28867. otcyrillic: 0x047F,
  28868. otilde: 0x00F5,
  28869. otildeacute: 0x1E4D,
  28870. otildedieresis: 0x1E4F,
  28871. oubopomofo: 0x3121,
  28872. overline: 0x203E,
  28873. overlinecenterline: 0xFE4A,
  28874. overlinecmb: 0x0305,
  28875. overlinedashed: 0xFE49,
  28876. overlinedblwavy: 0xFE4C,
  28877. overlinewavy: 0xFE4B,
  28878. overscore: 0x00AF,
  28879. ovowelsignbengali: 0x09CB,
  28880. ovowelsigndeva: 0x094B,
  28881. ovowelsigngujarati: 0x0ACB,
  28882. p: 0x0070,
  28883. paampssquare: 0x3380,
  28884. paasentosquare: 0x332B,
  28885. pabengali: 0x09AA,
  28886. pacute: 0x1E55,
  28887. padeva: 0x092A,
  28888. pagedown: 0x21DF,
  28889. pageup: 0x21DE,
  28890. pagujarati: 0x0AAA,
  28891. pagurmukhi: 0x0A2A,
  28892. pahiragana: 0x3071,
  28893. paiyannoithai: 0x0E2F,
  28894. pakatakana: 0x30D1,
  28895. palatalizationcyrilliccmb: 0x0484,
  28896. palochkacyrillic: 0x04C0,
  28897. pansioskorean: 0x317F,
  28898. paragraph: 0x00B6,
  28899. parallel: 0x2225,
  28900. parenleft: 0x0028,
  28901. parenleftaltonearabic: 0xFD3E,
  28902. parenleftbt: 0xF8ED,
  28903. parenleftex: 0xF8EC,
  28904. parenleftinferior: 0x208D,
  28905. parenleftmonospace: 0xFF08,
  28906. parenleftsmall: 0xFE59,
  28907. parenleftsuperior: 0x207D,
  28908. parenlefttp: 0xF8EB,
  28909. parenleftvertical: 0xFE35,
  28910. parenright: 0x0029,
  28911. parenrightaltonearabic: 0xFD3F,
  28912. parenrightbt: 0xF8F8,
  28913. parenrightex: 0xF8F7,
  28914. parenrightinferior: 0x208E,
  28915. parenrightmonospace: 0xFF09,
  28916. parenrightsmall: 0xFE5A,
  28917. parenrightsuperior: 0x207E,
  28918. parenrighttp: 0xF8F6,
  28919. parenrightvertical: 0xFE36,
  28920. partialdiff: 0x2202,
  28921. paseqhebrew: 0x05C0,
  28922. pashtahebrew: 0x0599,
  28923. pasquare: 0x33A9,
  28924. patah: 0x05B7,
  28925. patah11: 0x05B7,
  28926. patah1d: 0x05B7,
  28927. patah2a: 0x05B7,
  28928. patahhebrew: 0x05B7,
  28929. patahnarrowhebrew: 0x05B7,
  28930. patahquarterhebrew: 0x05B7,
  28931. patahwidehebrew: 0x05B7,
  28932. pazerhebrew: 0x05A1,
  28933. pbopomofo: 0x3106,
  28934. pcircle: 0x24DF,
  28935. pdotaccent: 0x1E57,
  28936. pe: 0x05E4,
  28937. pecyrillic: 0x043F,
  28938. pedagesh: 0xFB44,
  28939. pedageshhebrew: 0xFB44,
  28940. peezisquare: 0x333B,
  28941. pefinaldageshhebrew: 0xFB43,
  28942. peharabic: 0x067E,
  28943. peharmenian: 0x057A,
  28944. pehebrew: 0x05E4,
  28945. pehfinalarabic: 0xFB57,
  28946. pehinitialarabic: 0xFB58,
  28947. pehiragana: 0x307A,
  28948. pehmedialarabic: 0xFB59,
  28949. pekatakana: 0x30DA,
  28950. pemiddlehookcyrillic: 0x04A7,
  28951. perafehebrew: 0xFB4E,
  28952. percent: 0x0025,
  28953. percentarabic: 0x066A,
  28954. percentmonospace: 0xFF05,
  28955. percentsmall: 0xFE6A,
  28956. period: 0x002E,
  28957. periodarmenian: 0x0589,
  28958. periodcentered: 0x00B7,
  28959. periodhalfwidth: 0xFF61,
  28960. periodinferior: 0xF6E7,
  28961. periodmonospace: 0xFF0E,
  28962. periodsmall: 0xFE52,
  28963. periodsuperior: 0xF6E8,
  28964. perispomenigreekcmb: 0x0342,
  28965. perpendicular: 0x22A5,
  28966. perthousand: 0x2030,
  28967. peseta: 0x20A7,
  28968. pfsquare: 0x338A,
  28969. phabengali: 0x09AB,
  28970. phadeva: 0x092B,
  28971. phagujarati: 0x0AAB,
  28972. phagurmukhi: 0x0A2B,
  28973. phi: 0x03C6,
  28974. phi1: 0x03D5,
  28975. phieuphacirclekorean: 0x327A,
  28976. phieuphaparenkorean: 0x321A,
  28977. phieuphcirclekorean: 0x326C,
  28978. phieuphkorean: 0x314D,
  28979. phieuphparenkorean: 0x320C,
  28980. philatin: 0x0278,
  28981. phinthuthai: 0x0E3A,
  28982. phisymbolgreek: 0x03D5,
  28983. phook: 0x01A5,
  28984. phophanthai: 0x0E1E,
  28985. phophungthai: 0x0E1C,
  28986. phosamphaothai: 0x0E20,
  28987. pi: 0x03C0,
  28988. pieupacirclekorean: 0x3273,
  28989. pieupaparenkorean: 0x3213,
  28990. pieupcieuckorean: 0x3176,
  28991. pieupcirclekorean: 0x3265,
  28992. pieupkiyeokkorean: 0x3172,
  28993. pieupkorean: 0x3142,
  28994. pieupparenkorean: 0x3205,
  28995. pieupsioskiyeokkorean: 0x3174,
  28996. pieupsioskorean: 0x3144,
  28997. pieupsiostikeutkorean: 0x3175,
  28998. pieupthieuthkorean: 0x3177,
  28999. pieuptikeutkorean: 0x3173,
  29000. pihiragana: 0x3074,
  29001. pikatakana: 0x30D4,
  29002. pisymbolgreek: 0x03D6,
  29003. piwrarmenian: 0x0583,
  29004. plus: 0x002B,
  29005. plusbelowcmb: 0x031F,
  29006. pluscircle: 0x2295,
  29007. plusminus: 0x00B1,
  29008. plusmod: 0x02D6,
  29009. plusmonospace: 0xFF0B,
  29010. plussmall: 0xFE62,
  29011. plussuperior: 0x207A,
  29012. pmonospace: 0xFF50,
  29013. pmsquare: 0x33D8,
  29014. pohiragana: 0x307D,
  29015. pointingindexdownwhite: 0x261F,
  29016. pointingindexleftwhite: 0x261C,
  29017. pointingindexrightwhite: 0x261E,
  29018. pointingindexupwhite: 0x261D,
  29019. pokatakana: 0x30DD,
  29020. poplathai: 0x0E1B,
  29021. postalmark: 0x3012,
  29022. postalmarkface: 0x3020,
  29023. pparen: 0x24AB,
  29024. precedes: 0x227A,
  29025. prescription: 0x211E,
  29026. primemod: 0x02B9,
  29027. primereversed: 0x2035,
  29028. product: 0x220F,
  29029. projective: 0x2305,
  29030. prolongedkana: 0x30FC,
  29031. propellor: 0x2318,
  29032. propersubset: 0x2282,
  29033. propersuperset: 0x2283,
  29034. proportion: 0x2237,
  29035. proportional: 0x221D,
  29036. psi: 0x03C8,
  29037. psicyrillic: 0x0471,
  29038. psilipneumatacyrilliccmb: 0x0486,
  29039. pssquare: 0x33B0,
  29040. puhiragana: 0x3077,
  29041. pukatakana: 0x30D7,
  29042. pvsquare: 0x33B4,
  29043. pwsquare: 0x33BA,
  29044. q: 0x0071,
  29045. qadeva: 0x0958,
  29046. qadmahebrew: 0x05A8,
  29047. qafarabic: 0x0642,
  29048. qaffinalarabic: 0xFED6,
  29049. qafinitialarabic: 0xFED7,
  29050. qafmedialarabic: 0xFED8,
  29051. qamats: 0x05B8,
  29052. qamats10: 0x05B8,
  29053. qamats1a: 0x05B8,
  29054. qamats1c: 0x05B8,
  29055. qamats27: 0x05B8,
  29056. qamats29: 0x05B8,
  29057. qamats33: 0x05B8,
  29058. qamatsde: 0x05B8,
  29059. qamatshebrew: 0x05B8,
  29060. qamatsnarrowhebrew: 0x05B8,
  29061. qamatsqatanhebrew: 0x05B8,
  29062. qamatsqatannarrowhebrew: 0x05B8,
  29063. qamatsqatanquarterhebrew: 0x05B8,
  29064. qamatsqatanwidehebrew: 0x05B8,
  29065. qamatsquarterhebrew: 0x05B8,
  29066. qamatswidehebrew: 0x05B8,
  29067. qarneyparahebrew: 0x059F,
  29068. qbopomofo: 0x3111,
  29069. qcircle: 0x24E0,
  29070. qhook: 0x02A0,
  29071. qmonospace: 0xFF51,
  29072. qof: 0x05E7,
  29073. qofdagesh: 0xFB47,
  29074. qofdageshhebrew: 0xFB47,
  29075. qofhebrew: 0x05E7,
  29076. qparen: 0x24AC,
  29077. quarternote: 0x2669,
  29078. qubuts: 0x05BB,
  29079. qubuts18: 0x05BB,
  29080. qubuts25: 0x05BB,
  29081. qubuts31: 0x05BB,
  29082. qubutshebrew: 0x05BB,
  29083. qubutsnarrowhebrew: 0x05BB,
  29084. qubutsquarterhebrew: 0x05BB,
  29085. qubutswidehebrew: 0x05BB,
  29086. question: 0x003F,
  29087. questionarabic: 0x061F,
  29088. questionarmenian: 0x055E,
  29089. questiondown: 0x00BF,
  29090. questiondownsmall: 0xF7BF,
  29091. questiongreek: 0x037E,
  29092. questionmonospace: 0xFF1F,
  29093. questionsmall: 0xF73F,
  29094. quotedbl: 0x0022,
  29095. quotedblbase: 0x201E,
  29096. quotedblleft: 0x201C,
  29097. quotedblmonospace: 0xFF02,
  29098. quotedblprime: 0x301E,
  29099. quotedblprimereversed: 0x301D,
  29100. quotedblright: 0x201D,
  29101. quoteleft: 0x2018,
  29102. quoteleftreversed: 0x201B,
  29103. quotereversed: 0x201B,
  29104. quoteright: 0x2019,
  29105. quoterightn: 0x0149,
  29106. quotesinglbase: 0x201A,
  29107. quotesingle: 0x0027,
  29108. quotesinglemonospace: 0xFF07,
  29109. r: 0x0072,
  29110. raarmenian: 0x057C,
  29111. rabengali: 0x09B0,
  29112. racute: 0x0155,
  29113. radeva: 0x0930,
  29114. radical: 0x221A,
  29115. radicalex: 0xF8E5,
  29116. radoverssquare: 0x33AE,
  29117. radoverssquaredsquare: 0x33AF,
  29118. radsquare: 0x33AD,
  29119. rafe: 0x05BF,
  29120. rafehebrew: 0x05BF,
  29121. ragujarati: 0x0AB0,
  29122. ragurmukhi: 0x0A30,
  29123. rahiragana: 0x3089,
  29124. rakatakana: 0x30E9,
  29125. rakatakanahalfwidth: 0xFF97,
  29126. ralowerdiagonalbengali: 0x09F1,
  29127. ramiddlediagonalbengali: 0x09F0,
  29128. ramshorn: 0x0264,
  29129. ratio: 0x2236,
  29130. rbopomofo: 0x3116,
  29131. rcaron: 0x0159,
  29132. rcedilla: 0x0157,
  29133. rcircle: 0x24E1,
  29134. rcommaaccent: 0x0157,
  29135. rdblgrave: 0x0211,
  29136. rdotaccent: 0x1E59,
  29137. rdotbelow: 0x1E5B,
  29138. rdotbelowmacron: 0x1E5D,
  29139. referencemark: 0x203B,
  29140. reflexsubset: 0x2286,
  29141. reflexsuperset: 0x2287,
  29142. registered: 0x00AE,
  29143. registersans: 0xF8E8,
  29144. registerserif: 0xF6DA,
  29145. reharabic: 0x0631,
  29146. reharmenian: 0x0580,
  29147. rehfinalarabic: 0xFEAE,
  29148. rehiragana: 0x308C,
  29149. rekatakana: 0x30EC,
  29150. rekatakanahalfwidth: 0xFF9A,
  29151. resh: 0x05E8,
  29152. reshdageshhebrew: 0xFB48,
  29153. reshhebrew: 0x05E8,
  29154. reversedtilde: 0x223D,
  29155. reviahebrew: 0x0597,
  29156. reviamugrashhebrew: 0x0597,
  29157. revlogicalnot: 0x2310,
  29158. rfishhook: 0x027E,
  29159. rfishhookreversed: 0x027F,
  29160. rhabengali: 0x09DD,
  29161. rhadeva: 0x095D,
  29162. rho: 0x03C1,
  29163. rhook: 0x027D,
  29164. rhookturned: 0x027B,
  29165. rhookturnedsuperior: 0x02B5,
  29166. rhosymbolgreek: 0x03F1,
  29167. rhotichookmod: 0x02DE,
  29168. rieulacirclekorean: 0x3271,
  29169. rieulaparenkorean: 0x3211,
  29170. rieulcirclekorean: 0x3263,
  29171. rieulhieuhkorean: 0x3140,
  29172. rieulkiyeokkorean: 0x313A,
  29173. rieulkiyeoksioskorean: 0x3169,
  29174. rieulkorean: 0x3139,
  29175. rieulmieumkorean: 0x313B,
  29176. rieulpansioskorean: 0x316C,
  29177. rieulparenkorean: 0x3203,
  29178. rieulphieuphkorean: 0x313F,
  29179. rieulpieupkorean: 0x313C,
  29180. rieulpieupsioskorean: 0x316B,
  29181. rieulsioskorean: 0x313D,
  29182. rieulthieuthkorean: 0x313E,
  29183. rieultikeutkorean: 0x316A,
  29184. rieulyeorinhieuhkorean: 0x316D,
  29185. rightangle: 0x221F,
  29186. righttackbelowcmb: 0x0319,
  29187. righttriangle: 0x22BF,
  29188. rihiragana: 0x308A,
  29189. rikatakana: 0x30EA,
  29190. rikatakanahalfwidth: 0xFF98,
  29191. ring: 0x02DA,
  29192. ringbelowcmb: 0x0325,
  29193. ringcmb: 0x030A,
  29194. ringhalfleft: 0x02BF,
  29195. ringhalfleftarmenian: 0x0559,
  29196. ringhalfleftbelowcmb: 0x031C,
  29197. ringhalfleftcentered: 0x02D3,
  29198. ringhalfright: 0x02BE,
  29199. ringhalfrightbelowcmb: 0x0339,
  29200. ringhalfrightcentered: 0x02D2,
  29201. rinvertedbreve: 0x0213,
  29202. rittorusquare: 0x3351,
  29203. rlinebelow: 0x1E5F,
  29204. rlongleg: 0x027C,
  29205. rlonglegturned: 0x027A,
  29206. rmonospace: 0xFF52,
  29207. rohiragana: 0x308D,
  29208. rokatakana: 0x30ED,
  29209. rokatakanahalfwidth: 0xFF9B,
  29210. roruathai: 0x0E23,
  29211. rparen: 0x24AD,
  29212. rrabengali: 0x09DC,
  29213. rradeva: 0x0931,
  29214. rragurmukhi: 0x0A5C,
  29215. rreharabic: 0x0691,
  29216. rrehfinalarabic: 0xFB8D,
  29217. rrvocalicbengali: 0x09E0,
  29218. rrvocalicdeva: 0x0960,
  29219. rrvocalicgujarati: 0x0AE0,
  29220. rrvocalicvowelsignbengali: 0x09C4,
  29221. rrvocalicvowelsigndeva: 0x0944,
  29222. rrvocalicvowelsigngujarati: 0x0AC4,
  29223. rsuperior: 0xF6F1,
  29224. rtblock: 0x2590,
  29225. rturned: 0x0279,
  29226. rturnedsuperior: 0x02B4,
  29227. ruhiragana: 0x308B,
  29228. rukatakana: 0x30EB,
  29229. rukatakanahalfwidth: 0xFF99,
  29230. rupeemarkbengali: 0x09F2,
  29231. rupeesignbengali: 0x09F3,
  29232. rupiah: 0xF6DD,
  29233. ruthai: 0x0E24,
  29234. rvocalicbengali: 0x098B,
  29235. rvocalicdeva: 0x090B,
  29236. rvocalicgujarati: 0x0A8B,
  29237. rvocalicvowelsignbengali: 0x09C3,
  29238. rvocalicvowelsigndeva: 0x0943,
  29239. rvocalicvowelsigngujarati: 0x0AC3,
  29240. s: 0x0073,
  29241. sabengali: 0x09B8,
  29242. sacute: 0x015B,
  29243. sacutedotaccent: 0x1E65,
  29244. sadarabic: 0x0635,
  29245. sadeva: 0x0938,
  29246. sadfinalarabic: 0xFEBA,
  29247. sadinitialarabic: 0xFEBB,
  29248. sadmedialarabic: 0xFEBC,
  29249. sagujarati: 0x0AB8,
  29250. sagurmukhi: 0x0A38,
  29251. sahiragana: 0x3055,
  29252. sakatakana: 0x30B5,
  29253. sakatakanahalfwidth: 0xFF7B,
  29254. sallallahoualayhewasallamarabic: 0xFDFA,
  29255. samekh: 0x05E1,
  29256. samekhdagesh: 0xFB41,
  29257. samekhdageshhebrew: 0xFB41,
  29258. samekhhebrew: 0x05E1,
  29259. saraaathai: 0x0E32,
  29260. saraaethai: 0x0E41,
  29261. saraaimaimalaithai: 0x0E44,
  29262. saraaimaimuanthai: 0x0E43,
  29263. saraamthai: 0x0E33,
  29264. saraathai: 0x0E30,
  29265. saraethai: 0x0E40,
  29266. saraiileftthai: 0xF886,
  29267. saraiithai: 0x0E35,
  29268. saraileftthai: 0xF885,
  29269. saraithai: 0x0E34,
  29270. saraothai: 0x0E42,
  29271. saraueeleftthai: 0xF888,
  29272. saraueethai: 0x0E37,
  29273. saraueleftthai: 0xF887,
  29274. sarauethai: 0x0E36,
  29275. sarauthai: 0x0E38,
  29276. sarauuthai: 0x0E39,
  29277. sbopomofo: 0x3119,
  29278. scaron: 0x0161,
  29279. scarondotaccent: 0x1E67,
  29280. scedilla: 0x015F,
  29281. schwa: 0x0259,
  29282. schwacyrillic: 0x04D9,
  29283. schwadieresiscyrillic: 0x04DB,
  29284. schwahook: 0x025A,
  29285. scircle: 0x24E2,
  29286. scircumflex: 0x015D,
  29287. scommaaccent: 0x0219,
  29288. sdotaccent: 0x1E61,
  29289. sdotbelow: 0x1E63,
  29290. sdotbelowdotaccent: 0x1E69,
  29291. seagullbelowcmb: 0x033C,
  29292. second: 0x2033,
  29293. secondtonechinese: 0x02CA,
  29294. section: 0x00A7,
  29295. seenarabic: 0x0633,
  29296. seenfinalarabic: 0xFEB2,
  29297. seeninitialarabic: 0xFEB3,
  29298. seenmedialarabic: 0xFEB4,
  29299. segol: 0x05B6,
  29300. segol13: 0x05B6,
  29301. segol1f: 0x05B6,
  29302. segol2c: 0x05B6,
  29303. segolhebrew: 0x05B6,
  29304. segolnarrowhebrew: 0x05B6,
  29305. segolquarterhebrew: 0x05B6,
  29306. segoltahebrew: 0x0592,
  29307. segolwidehebrew: 0x05B6,
  29308. seharmenian: 0x057D,
  29309. sehiragana: 0x305B,
  29310. sekatakana: 0x30BB,
  29311. sekatakanahalfwidth: 0xFF7E,
  29312. semicolon: 0x003B,
  29313. semicolonarabic: 0x061B,
  29314. semicolonmonospace: 0xFF1B,
  29315. semicolonsmall: 0xFE54,
  29316. semivoicedmarkkana: 0x309C,
  29317. semivoicedmarkkanahalfwidth: 0xFF9F,
  29318. sentisquare: 0x3322,
  29319. sentosquare: 0x3323,
  29320. seven: 0x0037,
  29321. sevenarabic: 0x0667,
  29322. sevenbengali: 0x09ED,
  29323. sevencircle: 0x2466,
  29324. sevencircleinversesansserif: 0x2790,
  29325. sevendeva: 0x096D,
  29326. seveneighths: 0x215E,
  29327. sevengujarati: 0x0AED,
  29328. sevengurmukhi: 0x0A6D,
  29329. sevenhackarabic: 0x0667,
  29330. sevenhangzhou: 0x3027,
  29331. sevenideographicparen: 0x3226,
  29332. seveninferior: 0x2087,
  29333. sevenmonospace: 0xFF17,
  29334. sevenoldstyle: 0xF737,
  29335. sevenparen: 0x247A,
  29336. sevenperiod: 0x248E,
  29337. sevenpersian: 0x06F7,
  29338. sevenroman: 0x2176,
  29339. sevensuperior: 0x2077,
  29340. seventeencircle: 0x2470,
  29341. seventeenparen: 0x2484,
  29342. seventeenperiod: 0x2498,
  29343. seventhai: 0x0E57,
  29344. sfthyphen: 0x00AD,
  29345. shaarmenian: 0x0577,
  29346. shabengali: 0x09B6,
  29347. shacyrillic: 0x0448,
  29348. shaddaarabic: 0x0651,
  29349. shaddadammaarabic: 0xFC61,
  29350. shaddadammatanarabic: 0xFC5E,
  29351. shaddafathaarabic: 0xFC60,
  29352. shaddakasraarabic: 0xFC62,
  29353. shaddakasratanarabic: 0xFC5F,
  29354. shade: 0x2592,
  29355. shadedark: 0x2593,
  29356. shadelight: 0x2591,
  29357. shademedium: 0x2592,
  29358. shadeva: 0x0936,
  29359. shagujarati: 0x0AB6,
  29360. shagurmukhi: 0x0A36,
  29361. shalshelethebrew: 0x0593,
  29362. shbopomofo: 0x3115,
  29363. shchacyrillic: 0x0449,
  29364. sheenarabic: 0x0634,
  29365. sheenfinalarabic: 0xFEB6,
  29366. sheeninitialarabic: 0xFEB7,
  29367. sheenmedialarabic: 0xFEB8,
  29368. sheicoptic: 0x03E3,
  29369. sheqel: 0x20AA,
  29370. sheqelhebrew: 0x20AA,
  29371. sheva: 0x05B0,
  29372. sheva115: 0x05B0,
  29373. sheva15: 0x05B0,
  29374. sheva22: 0x05B0,
  29375. sheva2e: 0x05B0,
  29376. shevahebrew: 0x05B0,
  29377. shevanarrowhebrew: 0x05B0,
  29378. shevaquarterhebrew: 0x05B0,
  29379. shevawidehebrew: 0x05B0,
  29380. shhacyrillic: 0x04BB,
  29381. shimacoptic: 0x03ED,
  29382. shin: 0x05E9,
  29383. shindagesh: 0xFB49,
  29384. shindageshhebrew: 0xFB49,
  29385. shindageshshindot: 0xFB2C,
  29386. shindageshshindothebrew: 0xFB2C,
  29387. shindageshsindot: 0xFB2D,
  29388. shindageshsindothebrew: 0xFB2D,
  29389. shindothebrew: 0x05C1,
  29390. shinhebrew: 0x05E9,
  29391. shinshindot: 0xFB2A,
  29392. shinshindothebrew: 0xFB2A,
  29393. shinsindot: 0xFB2B,
  29394. shinsindothebrew: 0xFB2B,
  29395. shook: 0x0282,
  29396. sigma: 0x03C3,
  29397. sigma1: 0x03C2,
  29398. sigmafinal: 0x03C2,
  29399. sigmalunatesymbolgreek: 0x03F2,
  29400. sihiragana: 0x3057,
  29401. sikatakana: 0x30B7,
  29402. sikatakanahalfwidth: 0xFF7C,
  29403. siluqhebrew: 0x05BD,
  29404. siluqlefthebrew: 0x05BD,
  29405. similar: 0x223C,
  29406. sindothebrew: 0x05C2,
  29407. siosacirclekorean: 0x3274,
  29408. siosaparenkorean: 0x3214,
  29409. sioscieuckorean: 0x317E,
  29410. sioscirclekorean: 0x3266,
  29411. sioskiyeokkorean: 0x317A,
  29412. sioskorean: 0x3145,
  29413. siosnieunkorean: 0x317B,
  29414. siosparenkorean: 0x3206,
  29415. siospieupkorean: 0x317D,
  29416. siostikeutkorean: 0x317C,
  29417. six: 0x0036,
  29418. sixarabic: 0x0666,
  29419. sixbengali: 0x09EC,
  29420. sixcircle: 0x2465,
  29421. sixcircleinversesansserif: 0x278F,
  29422. sixdeva: 0x096C,
  29423. sixgujarati: 0x0AEC,
  29424. sixgurmukhi: 0x0A6C,
  29425. sixhackarabic: 0x0666,
  29426. sixhangzhou: 0x3026,
  29427. sixideographicparen: 0x3225,
  29428. sixinferior: 0x2086,
  29429. sixmonospace: 0xFF16,
  29430. sixoldstyle: 0xF736,
  29431. sixparen: 0x2479,
  29432. sixperiod: 0x248D,
  29433. sixpersian: 0x06F6,
  29434. sixroman: 0x2175,
  29435. sixsuperior: 0x2076,
  29436. sixteencircle: 0x246F,
  29437. sixteencurrencydenominatorbengali: 0x09F9,
  29438. sixteenparen: 0x2483,
  29439. sixteenperiod: 0x2497,
  29440. sixthai: 0x0E56,
  29441. slash: 0x002F,
  29442. slashmonospace: 0xFF0F,
  29443. slong: 0x017F,
  29444. slongdotaccent: 0x1E9B,
  29445. smileface: 0x263A,
  29446. smonospace: 0xFF53,
  29447. sofpasuqhebrew: 0x05C3,
  29448. softhyphen: 0x00AD,
  29449. softsigncyrillic: 0x044C,
  29450. sohiragana: 0x305D,
  29451. sokatakana: 0x30BD,
  29452. sokatakanahalfwidth: 0xFF7F,
  29453. soliduslongoverlaycmb: 0x0338,
  29454. solidusshortoverlaycmb: 0x0337,
  29455. sorusithai: 0x0E29,
  29456. sosalathai: 0x0E28,
  29457. sosothai: 0x0E0B,
  29458. sosuathai: 0x0E2A,
  29459. space: 0x0020,
  29460. spacehackarabic: 0x0020,
  29461. spade: 0x2660,
  29462. spadesuitblack: 0x2660,
  29463. spadesuitwhite: 0x2664,
  29464. sparen: 0x24AE,
  29465. squarebelowcmb: 0x033B,
  29466. squarecc: 0x33C4,
  29467. squarecm: 0x339D,
  29468. squarediagonalcrosshatchfill: 0x25A9,
  29469. squarehorizontalfill: 0x25A4,
  29470. squarekg: 0x338F,
  29471. squarekm: 0x339E,
  29472. squarekmcapital: 0x33CE,
  29473. squareln: 0x33D1,
  29474. squarelog: 0x33D2,
  29475. squaremg: 0x338E,
  29476. squaremil: 0x33D5,
  29477. squaremm: 0x339C,
  29478. squaremsquared: 0x33A1,
  29479. squareorthogonalcrosshatchfill: 0x25A6,
  29480. squareupperlefttolowerrightfill: 0x25A7,
  29481. squareupperrighttolowerleftfill: 0x25A8,
  29482. squareverticalfill: 0x25A5,
  29483. squarewhitewithsmallblack: 0x25A3,
  29484. srsquare: 0x33DB,
  29485. ssabengali: 0x09B7,
  29486. ssadeva: 0x0937,
  29487. ssagujarati: 0x0AB7,
  29488. ssangcieuckorean: 0x3149,
  29489. ssanghieuhkorean: 0x3185,
  29490. ssangieungkorean: 0x3180,
  29491. ssangkiyeokkorean: 0x3132,
  29492. ssangnieunkorean: 0x3165,
  29493. ssangpieupkorean: 0x3143,
  29494. ssangsioskorean: 0x3146,
  29495. ssangtikeutkorean: 0x3138,
  29496. ssuperior: 0xF6F2,
  29497. sterling: 0x00A3,
  29498. sterlingmonospace: 0xFFE1,
  29499. strokelongoverlaycmb: 0x0336,
  29500. strokeshortoverlaycmb: 0x0335,
  29501. subset: 0x2282,
  29502. subsetnotequal: 0x228A,
  29503. subsetorequal: 0x2286,
  29504. succeeds: 0x227B,
  29505. suchthat: 0x220B,
  29506. suhiragana: 0x3059,
  29507. sukatakana: 0x30B9,
  29508. sukatakanahalfwidth: 0xFF7D,
  29509. sukunarabic: 0x0652,
  29510. summation: 0x2211,
  29511. sun: 0x263C,
  29512. superset: 0x2283,
  29513. supersetnotequal: 0x228B,
  29514. supersetorequal: 0x2287,
  29515. svsquare: 0x33DC,
  29516. syouwaerasquare: 0x337C,
  29517. t: 0x0074,
  29518. tabengali: 0x09A4,
  29519. tackdown: 0x22A4,
  29520. tackleft: 0x22A3,
  29521. tadeva: 0x0924,
  29522. tagujarati: 0x0AA4,
  29523. tagurmukhi: 0x0A24,
  29524. taharabic: 0x0637,
  29525. tahfinalarabic: 0xFEC2,
  29526. tahinitialarabic: 0xFEC3,
  29527. tahiragana: 0x305F,
  29528. tahmedialarabic: 0xFEC4,
  29529. taisyouerasquare: 0x337D,
  29530. takatakana: 0x30BF,
  29531. takatakanahalfwidth: 0xFF80,
  29532. tatweelarabic: 0x0640,
  29533. tau: 0x03C4,
  29534. tav: 0x05EA,
  29535. tavdages: 0xFB4A,
  29536. tavdagesh: 0xFB4A,
  29537. tavdageshhebrew: 0xFB4A,
  29538. tavhebrew: 0x05EA,
  29539. tbar: 0x0167,
  29540. tbopomofo: 0x310A,
  29541. tcaron: 0x0165,
  29542. tccurl: 0x02A8,
  29543. tcedilla: 0x0163,
  29544. tcheharabic: 0x0686,
  29545. tchehfinalarabic: 0xFB7B,
  29546. tchehinitialarabic: 0xFB7C,
  29547. tchehmedialarabic: 0xFB7D,
  29548. tcircle: 0x24E3,
  29549. tcircumflexbelow: 0x1E71,
  29550. tcommaaccent: 0x0163,
  29551. tdieresis: 0x1E97,
  29552. tdotaccent: 0x1E6B,
  29553. tdotbelow: 0x1E6D,
  29554. tecyrillic: 0x0442,
  29555. tedescendercyrillic: 0x04AD,
  29556. teharabic: 0x062A,
  29557. tehfinalarabic: 0xFE96,
  29558. tehhahinitialarabic: 0xFCA2,
  29559. tehhahisolatedarabic: 0xFC0C,
  29560. tehinitialarabic: 0xFE97,
  29561. tehiragana: 0x3066,
  29562. tehjeeminitialarabic: 0xFCA1,
  29563. tehjeemisolatedarabic: 0xFC0B,
  29564. tehmarbutaarabic: 0x0629,
  29565. tehmarbutafinalarabic: 0xFE94,
  29566. tehmedialarabic: 0xFE98,
  29567. tehmeeminitialarabic: 0xFCA4,
  29568. tehmeemisolatedarabic: 0xFC0E,
  29569. tehnoonfinalarabic: 0xFC73,
  29570. tekatakana: 0x30C6,
  29571. tekatakanahalfwidth: 0xFF83,
  29572. telephone: 0x2121,
  29573. telephoneblack: 0x260E,
  29574. telishagedolahebrew: 0x05A0,
  29575. telishaqetanahebrew: 0x05A9,
  29576. tencircle: 0x2469,
  29577. tenideographicparen: 0x3229,
  29578. tenparen: 0x247D,
  29579. tenperiod: 0x2491,
  29580. tenroman: 0x2179,
  29581. tesh: 0x02A7,
  29582. tet: 0x05D8,
  29583. tetdagesh: 0xFB38,
  29584. tetdageshhebrew: 0xFB38,
  29585. tethebrew: 0x05D8,
  29586. tetsecyrillic: 0x04B5,
  29587. tevirhebrew: 0x059B,
  29588. tevirlefthebrew: 0x059B,
  29589. thabengali: 0x09A5,
  29590. thadeva: 0x0925,
  29591. thagujarati: 0x0AA5,
  29592. thagurmukhi: 0x0A25,
  29593. thalarabic: 0x0630,
  29594. thalfinalarabic: 0xFEAC,
  29595. thanthakhatlowleftthai: 0xF898,
  29596. thanthakhatlowrightthai: 0xF897,
  29597. thanthakhatthai: 0x0E4C,
  29598. thanthakhatupperleftthai: 0xF896,
  29599. theharabic: 0x062B,
  29600. thehfinalarabic: 0xFE9A,
  29601. thehinitialarabic: 0xFE9B,
  29602. thehmedialarabic: 0xFE9C,
  29603. thereexists: 0x2203,
  29604. therefore: 0x2234,
  29605. theta: 0x03B8,
  29606. theta1: 0x03D1,
  29607. thetasymbolgreek: 0x03D1,
  29608. thieuthacirclekorean: 0x3279,
  29609. thieuthaparenkorean: 0x3219,
  29610. thieuthcirclekorean: 0x326B,
  29611. thieuthkorean: 0x314C,
  29612. thieuthparenkorean: 0x320B,
  29613. thirteencircle: 0x246C,
  29614. thirteenparen: 0x2480,
  29615. thirteenperiod: 0x2494,
  29616. thonangmonthothai: 0x0E11,
  29617. thook: 0x01AD,
  29618. thophuthaothai: 0x0E12,
  29619. thorn: 0x00FE,
  29620. thothahanthai: 0x0E17,
  29621. thothanthai: 0x0E10,
  29622. thothongthai: 0x0E18,
  29623. thothungthai: 0x0E16,
  29624. thousandcyrillic: 0x0482,
  29625. thousandsseparatorarabic: 0x066C,
  29626. thousandsseparatorpersian: 0x066C,
  29627. three: 0x0033,
  29628. threearabic: 0x0663,
  29629. threebengali: 0x09E9,
  29630. threecircle: 0x2462,
  29631. threecircleinversesansserif: 0x278C,
  29632. threedeva: 0x0969,
  29633. threeeighths: 0x215C,
  29634. threegujarati: 0x0AE9,
  29635. threegurmukhi: 0x0A69,
  29636. threehackarabic: 0x0663,
  29637. threehangzhou: 0x3023,
  29638. threeideographicparen: 0x3222,
  29639. threeinferior: 0x2083,
  29640. threemonospace: 0xFF13,
  29641. threenumeratorbengali: 0x09F6,
  29642. threeoldstyle: 0xF733,
  29643. threeparen: 0x2476,
  29644. threeperiod: 0x248A,
  29645. threepersian: 0x06F3,
  29646. threequarters: 0x00BE,
  29647. threequartersemdash: 0xF6DE,
  29648. threeroman: 0x2172,
  29649. threesuperior: 0x00B3,
  29650. threethai: 0x0E53,
  29651. thzsquare: 0x3394,
  29652. tihiragana: 0x3061,
  29653. tikatakana: 0x30C1,
  29654. tikatakanahalfwidth: 0xFF81,
  29655. tikeutacirclekorean: 0x3270,
  29656. tikeutaparenkorean: 0x3210,
  29657. tikeutcirclekorean: 0x3262,
  29658. tikeutkorean: 0x3137,
  29659. tikeutparenkorean: 0x3202,
  29660. tilde: 0x02DC,
  29661. tildebelowcmb: 0x0330,
  29662. tildecmb: 0x0303,
  29663. tildecomb: 0x0303,
  29664. tildedoublecmb: 0x0360,
  29665. tildeoperator: 0x223C,
  29666. tildeoverlaycmb: 0x0334,
  29667. tildeverticalcmb: 0x033E,
  29668. timescircle: 0x2297,
  29669. tipehahebrew: 0x0596,
  29670. tipehalefthebrew: 0x0596,
  29671. tippigurmukhi: 0x0A70,
  29672. titlocyrilliccmb: 0x0483,
  29673. tiwnarmenian: 0x057F,
  29674. tlinebelow: 0x1E6F,
  29675. tmonospace: 0xFF54,
  29676. toarmenian: 0x0569,
  29677. tohiragana: 0x3068,
  29678. tokatakana: 0x30C8,
  29679. tokatakanahalfwidth: 0xFF84,
  29680. tonebarextrahighmod: 0x02E5,
  29681. tonebarextralowmod: 0x02E9,
  29682. tonebarhighmod: 0x02E6,
  29683. tonebarlowmod: 0x02E8,
  29684. tonebarmidmod: 0x02E7,
  29685. tonefive: 0x01BD,
  29686. tonesix: 0x0185,
  29687. tonetwo: 0x01A8,
  29688. tonos: 0x0384,
  29689. tonsquare: 0x3327,
  29690. topatakthai: 0x0E0F,
  29691. tortoiseshellbracketleft: 0x3014,
  29692. tortoiseshellbracketleftsmall: 0xFE5D,
  29693. tortoiseshellbracketleftvertical: 0xFE39,
  29694. tortoiseshellbracketright: 0x3015,
  29695. tortoiseshellbracketrightsmall: 0xFE5E,
  29696. tortoiseshellbracketrightvertical: 0xFE3A,
  29697. totaothai: 0x0E15,
  29698. tpalatalhook: 0x01AB,
  29699. tparen: 0x24AF,
  29700. trademark: 0x2122,
  29701. trademarksans: 0xF8EA,
  29702. trademarkserif: 0xF6DB,
  29703. tretroflexhook: 0x0288,
  29704. triagdn: 0x25BC,
  29705. triaglf: 0x25C4,
  29706. triagrt: 0x25BA,
  29707. triagup: 0x25B2,
  29708. ts: 0x02A6,
  29709. tsadi: 0x05E6,
  29710. tsadidagesh: 0xFB46,
  29711. tsadidageshhebrew: 0xFB46,
  29712. tsadihebrew: 0x05E6,
  29713. tsecyrillic: 0x0446,
  29714. tsere: 0x05B5,
  29715. tsere12: 0x05B5,
  29716. tsere1e: 0x05B5,
  29717. tsere2b: 0x05B5,
  29718. tserehebrew: 0x05B5,
  29719. tserenarrowhebrew: 0x05B5,
  29720. tserequarterhebrew: 0x05B5,
  29721. tserewidehebrew: 0x05B5,
  29722. tshecyrillic: 0x045B,
  29723. tsuperior: 0xF6F3,
  29724. ttabengali: 0x099F,
  29725. ttadeva: 0x091F,
  29726. ttagujarati: 0x0A9F,
  29727. ttagurmukhi: 0x0A1F,
  29728. tteharabic: 0x0679,
  29729. ttehfinalarabic: 0xFB67,
  29730. ttehinitialarabic: 0xFB68,
  29731. ttehmedialarabic: 0xFB69,
  29732. tthabengali: 0x09A0,
  29733. tthadeva: 0x0920,
  29734. tthagujarati: 0x0AA0,
  29735. tthagurmukhi: 0x0A20,
  29736. tturned: 0x0287,
  29737. tuhiragana: 0x3064,
  29738. tukatakana: 0x30C4,
  29739. tukatakanahalfwidth: 0xFF82,
  29740. tusmallhiragana: 0x3063,
  29741. tusmallkatakana: 0x30C3,
  29742. tusmallkatakanahalfwidth: 0xFF6F,
  29743. twelvecircle: 0x246B,
  29744. twelveparen: 0x247F,
  29745. twelveperiod: 0x2493,
  29746. twelveroman: 0x217B,
  29747. twentycircle: 0x2473,
  29748. twentyhangzhou: 0x5344,
  29749. twentyparen: 0x2487,
  29750. twentyperiod: 0x249B,
  29751. two: 0x0032,
  29752. twoarabic: 0x0662,
  29753. twobengali: 0x09E8,
  29754. twocircle: 0x2461,
  29755. twocircleinversesansserif: 0x278B,
  29756. twodeva: 0x0968,
  29757. twodotenleader: 0x2025,
  29758. twodotleader: 0x2025,
  29759. twodotleadervertical: 0xFE30,
  29760. twogujarati: 0x0AE8,
  29761. twogurmukhi: 0x0A68,
  29762. twohackarabic: 0x0662,
  29763. twohangzhou: 0x3022,
  29764. twoideographicparen: 0x3221,
  29765. twoinferior: 0x2082,
  29766. twomonospace: 0xFF12,
  29767. twonumeratorbengali: 0x09F5,
  29768. twooldstyle: 0xF732,
  29769. twoparen: 0x2475,
  29770. twoperiod: 0x2489,
  29771. twopersian: 0x06F2,
  29772. tworoman: 0x2171,
  29773. twostroke: 0x01BB,
  29774. twosuperior: 0x00B2,
  29775. twothai: 0x0E52,
  29776. twothirds: 0x2154,
  29777. u: 0x0075,
  29778. uacute: 0x00FA,
  29779. ubar: 0x0289,
  29780. ubengali: 0x0989,
  29781. ubopomofo: 0x3128,
  29782. ubreve: 0x016D,
  29783. ucaron: 0x01D4,
  29784. ucircle: 0x24E4,
  29785. ucircumflex: 0x00FB,
  29786. ucircumflexbelow: 0x1E77,
  29787. ucyrillic: 0x0443,
  29788. udattadeva: 0x0951,
  29789. udblacute: 0x0171,
  29790. udblgrave: 0x0215,
  29791. udeva: 0x0909,
  29792. udieresis: 0x00FC,
  29793. udieresisacute: 0x01D8,
  29794. udieresisbelow: 0x1E73,
  29795. udieresiscaron: 0x01DA,
  29796. udieresiscyrillic: 0x04F1,
  29797. udieresisgrave: 0x01DC,
  29798. udieresismacron: 0x01D6,
  29799. udotbelow: 0x1EE5,
  29800. ugrave: 0x00F9,
  29801. ugujarati: 0x0A89,
  29802. ugurmukhi: 0x0A09,
  29803. uhiragana: 0x3046,
  29804. uhookabove: 0x1EE7,
  29805. uhorn: 0x01B0,
  29806. uhornacute: 0x1EE9,
  29807. uhorndotbelow: 0x1EF1,
  29808. uhorngrave: 0x1EEB,
  29809. uhornhookabove: 0x1EED,
  29810. uhorntilde: 0x1EEF,
  29811. uhungarumlaut: 0x0171,
  29812. uhungarumlautcyrillic: 0x04F3,
  29813. uinvertedbreve: 0x0217,
  29814. ukatakana: 0x30A6,
  29815. ukatakanahalfwidth: 0xFF73,
  29816. ukcyrillic: 0x0479,
  29817. ukorean: 0x315C,
  29818. umacron: 0x016B,
  29819. umacroncyrillic: 0x04EF,
  29820. umacrondieresis: 0x1E7B,
  29821. umatragurmukhi: 0x0A41,
  29822. umonospace: 0xFF55,
  29823. underscore: 0x005F,
  29824. underscoredbl: 0x2017,
  29825. underscoremonospace: 0xFF3F,
  29826. underscorevertical: 0xFE33,
  29827. underscorewavy: 0xFE4F,
  29828. union: 0x222A,
  29829. universal: 0x2200,
  29830. uogonek: 0x0173,
  29831. uparen: 0x24B0,
  29832. upblock: 0x2580,
  29833. upperdothebrew: 0x05C4,
  29834. upsilon: 0x03C5,
  29835. upsilondieresis: 0x03CB,
  29836. upsilondieresistonos: 0x03B0,
  29837. upsilonlatin: 0x028A,
  29838. upsilontonos: 0x03CD,
  29839. uptackbelowcmb: 0x031D,
  29840. uptackmod: 0x02D4,
  29841. uragurmukhi: 0x0A73,
  29842. uring: 0x016F,
  29843. ushortcyrillic: 0x045E,
  29844. usmallhiragana: 0x3045,
  29845. usmallkatakana: 0x30A5,
  29846. usmallkatakanahalfwidth: 0xFF69,
  29847. ustraightcyrillic: 0x04AF,
  29848. ustraightstrokecyrillic: 0x04B1,
  29849. utilde: 0x0169,
  29850. utildeacute: 0x1E79,
  29851. utildebelow: 0x1E75,
  29852. uubengali: 0x098A,
  29853. uudeva: 0x090A,
  29854. uugujarati: 0x0A8A,
  29855. uugurmukhi: 0x0A0A,
  29856. uumatragurmukhi: 0x0A42,
  29857. uuvowelsignbengali: 0x09C2,
  29858. uuvowelsigndeva: 0x0942,
  29859. uuvowelsigngujarati: 0x0AC2,
  29860. uvowelsignbengali: 0x09C1,
  29861. uvowelsigndeva: 0x0941,
  29862. uvowelsigngujarati: 0x0AC1,
  29863. v: 0x0076,
  29864. vadeva: 0x0935,
  29865. vagujarati: 0x0AB5,
  29866. vagurmukhi: 0x0A35,
  29867. vakatakana: 0x30F7,
  29868. vav: 0x05D5,
  29869. vavdagesh: 0xFB35,
  29870. vavdagesh65: 0xFB35,
  29871. vavdageshhebrew: 0xFB35,
  29872. vavhebrew: 0x05D5,
  29873. vavholam: 0xFB4B,
  29874. vavholamhebrew: 0xFB4B,
  29875. vavvavhebrew: 0x05F0,
  29876. vavyodhebrew: 0x05F1,
  29877. vcircle: 0x24E5,
  29878. vdotbelow: 0x1E7F,
  29879. vecyrillic: 0x0432,
  29880. veharabic: 0x06A4,
  29881. vehfinalarabic: 0xFB6B,
  29882. vehinitialarabic: 0xFB6C,
  29883. vehmedialarabic: 0xFB6D,
  29884. vekatakana: 0x30F9,
  29885. venus: 0x2640,
  29886. verticalbar: 0x007C,
  29887. verticallineabovecmb: 0x030D,
  29888. verticallinebelowcmb: 0x0329,
  29889. verticallinelowmod: 0x02CC,
  29890. verticallinemod: 0x02C8,
  29891. vewarmenian: 0x057E,
  29892. vhook: 0x028B,
  29893. vikatakana: 0x30F8,
  29894. viramabengali: 0x09CD,
  29895. viramadeva: 0x094D,
  29896. viramagujarati: 0x0ACD,
  29897. visargabengali: 0x0983,
  29898. visargadeva: 0x0903,
  29899. visargagujarati: 0x0A83,
  29900. vmonospace: 0xFF56,
  29901. voarmenian: 0x0578,
  29902. voicediterationhiragana: 0x309E,
  29903. voicediterationkatakana: 0x30FE,
  29904. voicedmarkkana: 0x309B,
  29905. voicedmarkkanahalfwidth: 0xFF9E,
  29906. vokatakana: 0x30FA,
  29907. vparen: 0x24B1,
  29908. vtilde: 0x1E7D,
  29909. vturned: 0x028C,
  29910. vuhiragana: 0x3094,
  29911. vukatakana: 0x30F4,
  29912. w: 0x0077,
  29913. wacute: 0x1E83,
  29914. waekorean: 0x3159,
  29915. wahiragana: 0x308F,
  29916. wakatakana: 0x30EF,
  29917. wakatakanahalfwidth: 0xFF9C,
  29918. wakorean: 0x3158,
  29919. wasmallhiragana: 0x308E,
  29920. wasmallkatakana: 0x30EE,
  29921. wattosquare: 0x3357,
  29922. wavedash: 0x301C,
  29923. wavyunderscorevertical: 0xFE34,
  29924. wawarabic: 0x0648,
  29925. wawfinalarabic: 0xFEEE,
  29926. wawhamzaabovearabic: 0x0624,
  29927. wawhamzaabovefinalarabic: 0xFE86,
  29928. wbsquare: 0x33DD,
  29929. wcircle: 0x24E6,
  29930. wcircumflex: 0x0175,
  29931. wdieresis: 0x1E85,
  29932. wdotaccent: 0x1E87,
  29933. wdotbelow: 0x1E89,
  29934. wehiragana: 0x3091,
  29935. weierstrass: 0x2118,
  29936. wekatakana: 0x30F1,
  29937. wekorean: 0x315E,
  29938. weokorean: 0x315D,
  29939. wgrave: 0x1E81,
  29940. whitebullet: 0x25E6,
  29941. whitecircle: 0x25CB,
  29942. whitecircleinverse: 0x25D9,
  29943. whitecornerbracketleft: 0x300E,
  29944. whitecornerbracketleftvertical: 0xFE43,
  29945. whitecornerbracketright: 0x300F,
  29946. whitecornerbracketrightvertical: 0xFE44,
  29947. whitediamond: 0x25C7,
  29948. whitediamondcontainingblacksmalldiamond: 0x25C8,
  29949. whitedownpointingsmalltriangle: 0x25BF,
  29950. whitedownpointingtriangle: 0x25BD,
  29951. whiteleftpointingsmalltriangle: 0x25C3,
  29952. whiteleftpointingtriangle: 0x25C1,
  29953. whitelenticularbracketleft: 0x3016,
  29954. whitelenticularbracketright: 0x3017,
  29955. whiterightpointingsmalltriangle: 0x25B9,
  29956. whiterightpointingtriangle: 0x25B7,
  29957. whitesmallsquare: 0x25AB,
  29958. whitesmilingface: 0x263A,
  29959. whitesquare: 0x25A1,
  29960. whitestar: 0x2606,
  29961. whitetelephone: 0x260F,
  29962. whitetortoiseshellbracketleft: 0x3018,
  29963. whitetortoiseshellbracketright: 0x3019,
  29964. whiteuppointingsmalltriangle: 0x25B5,
  29965. whiteuppointingtriangle: 0x25B3,
  29966. wihiragana: 0x3090,
  29967. wikatakana: 0x30F0,
  29968. wikorean: 0x315F,
  29969. wmonospace: 0xFF57,
  29970. wohiragana: 0x3092,
  29971. wokatakana: 0x30F2,
  29972. wokatakanahalfwidth: 0xFF66,
  29973. won: 0x20A9,
  29974. wonmonospace: 0xFFE6,
  29975. wowaenthai: 0x0E27,
  29976. wparen: 0x24B2,
  29977. wring: 0x1E98,
  29978. wsuperior: 0x02B7,
  29979. wturned: 0x028D,
  29980. wynn: 0x01BF,
  29981. x: 0x0078,
  29982. xabovecmb: 0x033D,
  29983. xbopomofo: 0x3112,
  29984. xcircle: 0x24E7,
  29985. xdieresis: 0x1E8D,
  29986. xdotaccent: 0x1E8B,
  29987. xeharmenian: 0x056D,
  29988. xi: 0x03BE,
  29989. xmonospace: 0xFF58,
  29990. xparen: 0x24B3,
  29991. xsuperior: 0x02E3,
  29992. y: 0x0079,
  29993. yaadosquare: 0x334E,
  29994. yabengali: 0x09AF,
  29995. yacute: 0x00FD,
  29996. yadeva: 0x092F,
  29997. yaekorean: 0x3152,
  29998. yagujarati: 0x0AAF,
  29999. yagurmukhi: 0x0A2F,
  30000. yahiragana: 0x3084,
  30001. yakatakana: 0x30E4,
  30002. yakatakanahalfwidth: 0xFF94,
  30003. yakorean: 0x3151,
  30004. yamakkanthai: 0x0E4E,
  30005. yasmallhiragana: 0x3083,
  30006. yasmallkatakana: 0x30E3,
  30007. yasmallkatakanahalfwidth: 0xFF6C,
  30008. yatcyrillic: 0x0463,
  30009. ycircle: 0x24E8,
  30010. ycircumflex: 0x0177,
  30011. ydieresis: 0x00FF,
  30012. ydotaccent: 0x1E8F,
  30013. ydotbelow: 0x1EF5,
  30014. yeharabic: 0x064A,
  30015. yehbarreearabic: 0x06D2,
  30016. yehbarreefinalarabic: 0xFBAF,
  30017. yehfinalarabic: 0xFEF2,
  30018. yehhamzaabovearabic: 0x0626,
  30019. yehhamzaabovefinalarabic: 0xFE8A,
  30020. yehhamzaaboveinitialarabic: 0xFE8B,
  30021. yehhamzaabovemedialarabic: 0xFE8C,
  30022. yehinitialarabic: 0xFEF3,
  30023. yehmedialarabic: 0xFEF4,
  30024. yehmeeminitialarabic: 0xFCDD,
  30025. yehmeemisolatedarabic: 0xFC58,
  30026. yehnoonfinalarabic: 0xFC94,
  30027. yehthreedotsbelowarabic: 0x06D1,
  30028. yekorean: 0x3156,
  30029. yen: 0x00A5,
  30030. yenmonospace: 0xFFE5,
  30031. yeokorean: 0x3155,
  30032. yeorinhieuhkorean: 0x3186,
  30033. yerahbenyomohebrew: 0x05AA,
  30034. yerahbenyomolefthebrew: 0x05AA,
  30035. yericyrillic: 0x044B,
  30036. yerudieresiscyrillic: 0x04F9,
  30037. yesieungkorean: 0x3181,
  30038. yesieungpansioskorean: 0x3183,
  30039. yesieungsioskorean: 0x3182,
  30040. yetivhebrew: 0x059A,
  30041. ygrave: 0x1EF3,
  30042. yhook: 0x01B4,
  30043. yhookabove: 0x1EF7,
  30044. yiarmenian: 0x0575,
  30045. yicyrillic: 0x0457,
  30046. yikorean: 0x3162,
  30047. yinyang: 0x262F,
  30048. yiwnarmenian: 0x0582,
  30049. ymonospace: 0xFF59,
  30050. yod: 0x05D9,
  30051. yoddagesh: 0xFB39,
  30052. yoddageshhebrew: 0xFB39,
  30053. yodhebrew: 0x05D9,
  30054. yodyodhebrew: 0x05F2,
  30055. yodyodpatahhebrew: 0xFB1F,
  30056. yohiragana: 0x3088,
  30057. yoikorean: 0x3189,
  30058. yokatakana: 0x30E8,
  30059. yokatakanahalfwidth: 0xFF96,
  30060. yokorean: 0x315B,
  30061. yosmallhiragana: 0x3087,
  30062. yosmallkatakana: 0x30E7,
  30063. yosmallkatakanahalfwidth: 0xFF6E,
  30064. yotgreek: 0x03F3,
  30065. yoyaekorean: 0x3188,
  30066. yoyakorean: 0x3187,
  30067. yoyakthai: 0x0E22,
  30068. yoyingthai: 0x0E0D,
  30069. yparen: 0x24B4,
  30070. ypogegrammeni: 0x037A,
  30071. ypogegrammenigreekcmb: 0x0345,
  30072. yr: 0x01A6,
  30073. yring: 0x1E99,
  30074. ysuperior: 0x02B8,
  30075. ytilde: 0x1EF9,
  30076. yturned: 0x028E,
  30077. yuhiragana: 0x3086,
  30078. yuikorean: 0x318C,
  30079. yukatakana: 0x30E6,
  30080. yukatakanahalfwidth: 0xFF95,
  30081. yukorean: 0x3160,
  30082. yusbigcyrillic: 0x046B,
  30083. yusbigiotifiedcyrillic: 0x046D,
  30084. yuslittlecyrillic: 0x0467,
  30085. yuslittleiotifiedcyrillic: 0x0469,
  30086. yusmallhiragana: 0x3085,
  30087. yusmallkatakana: 0x30E5,
  30088. yusmallkatakanahalfwidth: 0xFF6D,
  30089. yuyekorean: 0x318B,
  30090. yuyeokorean: 0x318A,
  30091. yyabengali: 0x09DF,
  30092. yyadeva: 0x095F,
  30093. z: 0x007A,
  30094. zaarmenian: 0x0566,
  30095. zacute: 0x017A,
  30096. zadeva: 0x095B,
  30097. zagurmukhi: 0x0A5B,
  30098. zaharabic: 0x0638,
  30099. zahfinalarabic: 0xFEC6,
  30100. zahinitialarabic: 0xFEC7,
  30101. zahiragana: 0x3056,
  30102. zahmedialarabic: 0xFEC8,
  30103. zainarabic: 0x0632,
  30104. zainfinalarabic: 0xFEB0,
  30105. zakatakana: 0x30B6,
  30106. zaqefgadolhebrew: 0x0595,
  30107. zaqefqatanhebrew: 0x0594,
  30108. zarqahebrew: 0x0598,
  30109. zayin: 0x05D6,
  30110. zayindagesh: 0xFB36,
  30111. zayindageshhebrew: 0xFB36,
  30112. zayinhebrew: 0x05D6,
  30113. zbopomofo: 0x3117,
  30114. zcaron: 0x017E,
  30115. zcircle: 0x24E9,
  30116. zcircumflex: 0x1E91,
  30117. zcurl: 0x0291,
  30118. zdot: 0x017C,
  30119. zdotaccent: 0x017C,
  30120. zdotbelow: 0x1E93,
  30121. zecyrillic: 0x0437,
  30122. zedescendercyrillic: 0x0499,
  30123. zedieresiscyrillic: 0x04DF,
  30124. zehiragana: 0x305C,
  30125. zekatakana: 0x30BC,
  30126. zero: 0x0030,
  30127. zeroarabic: 0x0660,
  30128. zerobengali: 0x09E6,
  30129. zerodeva: 0x0966,
  30130. zerogujarati: 0x0AE6,
  30131. zerogurmukhi: 0x0A66,
  30132. zerohackarabic: 0x0660,
  30133. zeroinferior: 0x2080,
  30134. zeromonospace: 0xFF10,
  30135. zerooldstyle: 0xF730,
  30136. zeropersian: 0x06F0,
  30137. zerosuperior: 0x2070,
  30138. zerothai: 0x0E50,
  30139. zerowidthjoiner: 0xFEFF,
  30140. zerowidthnonjoiner: 0x200C,
  30141. zerowidthspace: 0x200B,
  30142. zeta: 0x03B6,
  30143. zhbopomofo: 0x3113,
  30144. zhearmenian: 0x056A,
  30145. zhebrevecyrillic: 0x04C2,
  30146. zhecyrillic: 0x0436,
  30147. zhedescendercyrillic: 0x0497,
  30148. zhedieresiscyrillic: 0x04DD,
  30149. zihiragana: 0x3058,
  30150. zikatakana: 0x30B8,
  30151. zinorhebrew: 0x05AE,
  30152. zlinebelow: 0x1E95,
  30153. zmonospace: 0xFF5A,
  30154. zohiragana: 0x305E,
  30155. zokatakana: 0x30BE,
  30156. zparen: 0x24B5,
  30157. zretroflexhook: 0x0290,
  30158. zstroke: 0x01B6,
  30159. zuhiragana: 0x305A,
  30160. zukatakana: 0x30BA,
  30161. '.notdef': 0x0000
  30162. };
  30163. var DingbatsGlyphsUnicode = {
  30164. space: 0x0020,
  30165. a1: 0x2701,
  30166. a2: 0x2702,
  30167. a202: 0x2703,
  30168. a3: 0x2704,
  30169. a4: 0x260E,
  30170. a5: 0x2706,
  30171. a119: 0x2707,
  30172. a118: 0x2708,
  30173. a117: 0x2709,
  30174. a11: 0x261B,
  30175. a12: 0x261E,
  30176. a13: 0x270C,
  30177. a14: 0x270D,
  30178. a15: 0x270E,
  30179. a16: 0x270F,
  30180. a105: 0x2710,
  30181. a17: 0x2711,
  30182. a18: 0x2712,
  30183. a19: 0x2713,
  30184. a20: 0x2714,
  30185. a21: 0x2715,
  30186. a22: 0x2716,
  30187. a23: 0x2717,
  30188. a24: 0x2718,
  30189. a25: 0x2719,
  30190. a26: 0x271A,
  30191. a27: 0x271B,
  30192. a28: 0x271C,
  30193. a6: 0x271D,
  30194. a7: 0x271E,
  30195. a8: 0x271F,
  30196. a9: 0x2720,
  30197. a10: 0x2721,
  30198. a29: 0x2722,
  30199. a30: 0x2723,
  30200. a31: 0x2724,
  30201. a32: 0x2725,
  30202. a33: 0x2726,
  30203. a34: 0x2727,
  30204. a35: 0x2605,
  30205. a36: 0x2729,
  30206. a37: 0x272A,
  30207. a38: 0x272B,
  30208. a39: 0x272C,
  30209. a40: 0x272D,
  30210. a41: 0x272E,
  30211. a42: 0x272F,
  30212. a43: 0x2730,
  30213. a44: 0x2731,
  30214. a45: 0x2732,
  30215. a46: 0x2733,
  30216. a47: 0x2734,
  30217. a48: 0x2735,
  30218. a49: 0x2736,
  30219. a50: 0x2737,
  30220. a51: 0x2738,
  30221. a52: 0x2739,
  30222. a53: 0x273A,
  30223. a54: 0x273B,
  30224. a55: 0x273C,
  30225. a56: 0x273D,
  30226. a57: 0x273E,
  30227. a58: 0x273F,
  30228. a59: 0x2740,
  30229. a60: 0x2741,
  30230. a61: 0x2742,
  30231. a62: 0x2743,
  30232. a63: 0x2744,
  30233. a64: 0x2745,
  30234. a65: 0x2746,
  30235. a66: 0x2747,
  30236. a67: 0x2748,
  30237. a68: 0x2749,
  30238. a69: 0x274A,
  30239. a70: 0x274B,
  30240. a71: 0x25CF,
  30241. a72: 0x274D,
  30242. a73: 0x25A0,
  30243. a74: 0x274F,
  30244. a203: 0x2750,
  30245. a75: 0x2751,
  30246. a204: 0x2752,
  30247. a76: 0x25B2,
  30248. a77: 0x25BC,
  30249. a78: 0x25C6,
  30250. a79: 0x2756,
  30251. a81: 0x25D7,
  30252. a82: 0x2758,
  30253. a83: 0x2759,
  30254. a84: 0x275A,
  30255. a97: 0x275B,
  30256. a98: 0x275C,
  30257. a99: 0x275D,
  30258. a100: 0x275E,
  30259. a101: 0x2761,
  30260. a102: 0x2762,
  30261. a103: 0x2763,
  30262. a104: 0x2764,
  30263. a106: 0x2765,
  30264. a107: 0x2766,
  30265. a108: 0x2767,
  30266. a112: 0x2663,
  30267. a111: 0x2666,
  30268. a110: 0x2665,
  30269. a109: 0x2660,
  30270. a120: 0x2460,
  30271. a121: 0x2461,
  30272. a122: 0x2462,
  30273. a123: 0x2463,
  30274. a124: 0x2464,
  30275. a125: 0x2465,
  30276. a126: 0x2466,
  30277. a127: 0x2467,
  30278. a128: 0x2468,
  30279. a129: 0x2469,
  30280. a130: 0x2776,
  30281. a131: 0x2777,
  30282. a132: 0x2778,
  30283. a133: 0x2779,
  30284. a134: 0x277A,
  30285. a135: 0x277B,
  30286. a136: 0x277C,
  30287. a137: 0x277D,
  30288. a138: 0x277E,
  30289. a139: 0x277F,
  30290. a140: 0x2780,
  30291. a141: 0x2781,
  30292. a142: 0x2782,
  30293. a143: 0x2783,
  30294. a144: 0x2784,
  30295. a145: 0x2785,
  30296. a146: 0x2786,
  30297. a147: 0x2787,
  30298. a148: 0x2788,
  30299. a149: 0x2789,
  30300. a150: 0x278A,
  30301. a151: 0x278B,
  30302. a152: 0x278C,
  30303. a153: 0x278D,
  30304. a154: 0x278E,
  30305. a155: 0x278F,
  30306. a156: 0x2790,
  30307. a157: 0x2791,
  30308. a158: 0x2792,
  30309. a159: 0x2793,
  30310. a160: 0x2794,
  30311. a161: 0x2192,
  30312. a163: 0x2194,
  30313. a164: 0x2195,
  30314. a196: 0x2798,
  30315. a165: 0x2799,
  30316. a192: 0x279A,
  30317. a166: 0x279B,
  30318. a167: 0x279C,
  30319. a168: 0x279D,
  30320. a169: 0x279E,
  30321. a170: 0x279F,
  30322. a171: 0x27A0,
  30323. a172: 0x27A1,
  30324. a173: 0x27A2,
  30325. a162: 0x27A3,
  30326. a174: 0x27A4,
  30327. a175: 0x27A5,
  30328. a176: 0x27A6,
  30329. a177: 0x27A7,
  30330. a178: 0x27A8,
  30331. a179: 0x27A9,
  30332. a193: 0x27AA,
  30333. a180: 0x27AB,
  30334. a199: 0x27AC,
  30335. a181: 0x27AD,
  30336. a200: 0x27AE,
  30337. a182: 0x27AF,
  30338. a201: 0x27B1,
  30339. a183: 0x27B2,
  30340. a184: 0x27B3,
  30341. a197: 0x27B4,
  30342. a185: 0x27B5,
  30343. a194: 0x27B6,
  30344. a198: 0x27B7,
  30345. a186: 0x27B8,
  30346. a195: 0x27B9,
  30347. a187: 0x27BA,
  30348. a188: 0x27BB,
  30349. a189: 0x27BC,
  30350. a190: 0x27BD,
  30351. a191: 0x27BE,
  30352. a89: 0x2768, // 0xF8D7
  30353. a90: 0x2769, // 0xF8D8
  30354. a93: 0x276A, // 0xF8D9
  30355. a94: 0x276B, // 0xF8DA
  30356. a91: 0x276C, // 0xF8DB
  30357. a92: 0x276D, // 0xF8DC
  30358. a205: 0x276E, // 0xF8DD
  30359. a85: 0x276F, // 0xF8DE
  30360. a206: 0x2770, // 0xF8DF
  30361. a86: 0x2771, // 0xF8E0
  30362. a87: 0x2772, // 0xF8E1
  30363. a88: 0x2773, // 0xF8E2
  30364. a95: 0x2774, // 0xF8E3
  30365. a96: 0x2775, // 0xF8E4
  30366. '.notdef': 0x0000
  30367. };
  30368. var PDFImage = (function PDFImageClosure() {
  30369. /**
  30370. * Decode the image in the main thread if it supported. Resovles the promise
  30371. * when the image data is ready.
  30372. */
  30373. function handleImageData(handler, xref, res, image) {
  30374. if (image instanceof JpegStream && image.isNativelyDecodable(xref, res)) {
  30375. // For natively supported jpegs send them to the main thread for decoding.
  30376. var dict = image.dict;
  30377. var colorSpace = dict.get('ColorSpace', 'CS');
  30378. colorSpace = ColorSpace.parse(colorSpace, xref, res);
  30379. var numComps = colorSpace.numComps;
  30380. var decodePromise = handler.sendWithPromise('JpegDecode',
  30381. [image.getIR(), numComps]);
  30382. return decodePromise.then(function (message) {
  30383. var data = message.data;
  30384. return new Stream(data, 0, data.length, image.dict);
  30385. });
  30386. } else {
  30387. return Promise.resolve(image);
  30388. }
  30389. }
  30390. /**
  30391. * Decode and clamp a value. The formula is different from the spec because we
  30392. * don't decode to float range [0,1], we decode it in the [0,max] range.
  30393. */
  30394. function decodeAndClamp(value, addend, coefficient, max) {
  30395. value = addend + value * coefficient;
  30396. // Clamp the value to the range
  30397. return (value < 0 ? 0 : (value > max ? max : value));
  30398. }
  30399. function PDFImage(xref, res, image, inline, smask, mask, isMask) {
  30400. this.image = image;
  30401. var dict = image.dict;
  30402. if (dict.has('Filter')) {
  30403. var filter = dict.get('Filter').name;
  30404. if (filter === 'JPXDecode') {
  30405. var jpxImage = new JpxImage();
  30406. jpxImage.parseImageProperties(image.stream);
  30407. image.stream.reset();
  30408. image.bitsPerComponent = jpxImage.bitsPerComponent;
  30409. image.numComps = jpxImage.componentsCount;
  30410. } else if (filter === 'JBIG2Decode') {
  30411. image.bitsPerComponent = 1;
  30412. image.numComps = 1;
  30413. }
  30414. }
  30415. // TODO cache rendered images?
  30416. this.width = dict.get('Width', 'W');
  30417. this.height = dict.get('Height', 'H');
  30418. if (this.width < 1 || this.height < 1) {
  30419. error('Invalid image width: ' + this.width + ' or height: ' +
  30420. this.height);
  30421. }
  30422. this.interpolate = dict.get('Interpolate', 'I') || false;
  30423. this.imageMask = dict.get('ImageMask', 'IM') || false;
  30424. this.matte = dict.get('Matte') || false;
  30425. var bitsPerComponent = image.bitsPerComponent;
  30426. if (!bitsPerComponent) {
  30427. bitsPerComponent = dict.get('BitsPerComponent', 'BPC');
  30428. if (!bitsPerComponent) {
  30429. if (this.imageMask) {
  30430. bitsPerComponent = 1;
  30431. } else {
  30432. error('Bits per component missing in image: ' + this.imageMask);
  30433. }
  30434. }
  30435. }
  30436. this.bpc = bitsPerComponent;
  30437. if (!this.imageMask) {
  30438. var colorSpace = dict.get('ColorSpace', 'CS');
  30439. if (!colorSpace) {
  30440. info('JPX images (which do not require color spaces)');
  30441. switch (image.numComps) {
  30442. case 1:
  30443. colorSpace = Name.get('DeviceGray');
  30444. break;
  30445. case 3:
  30446. colorSpace = Name.get('DeviceRGB');
  30447. break;
  30448. case 4:
  30449. colorSpace = Name.get('DeviceCMYK');
  30450. break;
  30451. default:
  30452. error('JPX images with ' + this.numComps +
  30453. ' color components not supported.');
  30454. }
  30455. }
  30456. this.colorSpace = ColorSpace.parse(colorSpace, xref, res);
  30457. this.numComps = this.colorSpace.numComps;
  30458. }
  30459. this.decode = dict.get('Decode', 'D');
  30460. this.needsDecode = false;
  30461. if (this.decode &&
  30462. ((this.colorSpace && !this.colorSpace.isDefaultDecode(this.decode)) ||
  30463. (isMask && !ColorSpace.isDefaultDecode(this.decode, 1)))) {
  30464. this.needsDecode = true;
  30465. // Do some preprocessing to avoid more math.
  30466. var max = (1 << bitsPerComponent) - 1;
  30467. this.decodeCoefficients = [];
  30468. this.decodeAddends = [];
  30469. for (var i = 0, j = 0; i < this.decode.length; i += 2, ++j) {
  30470. var dmin = this.decode[i];
  30471. var dmax = this.decode[i + 1];
  30472. this.decodeCoefficients[j] = dmax - dmin;
  30473. this.decodeAddends[j] = max * dmin;
  30474. }
  30475. }
  30476. if (smask) {
  30477. this.smask = new PDFImage(xref, res, smask, false);
  30478. } else if (mask) {
  30479. if (isStream(mask)) {
  30480. this.mask = new PDFImage(xref, res, mask, false, null, null, true);
  30481. } else {
  30482. // Color key mask (just an array).
  30483. this.mask = mask;
  30484. }
  30485. }
  30486. }
  30487. /**
  30488. * Handles processing of image data and returns the Promise that is resolved
  30489. * with a PDFImage when the image is ready to be used.
  30490. */
  30491. PDFImage.buildImage = function PDFImage_buildImage(handler, xref,
  30492. res, image, inline) {
  30493. var imagePromise = handleImageData(handler, xref, res, image);
  30494. var smaskPromise;
  30495. var maskPromise;
  30496. var smask = image.dict.get('SMask');
  30497. var mask = image.dict.get('Mask');
  30498. if (smask) {
  30499. smaskPromise = handleImageData(handler, xref, res, smask);
  30500. maskPromise = Promise.resolve(null);
  30501. } else {
  30502. smaskPromise = Promise.resolve(null);
  30503. if (mask) {
  30504. if (isStream(mask)) {
  30505. maskPromise = handleImageData(handler, xref, res, mask);
  30506. } else if (isArray(mask)) {
  30507. maskPromise = Promise.resolve(mask);
  30508. } else {
  30509. warn('Unsupported mask format.');
  30510. maskPromise = Promise.resolve(null);
  30511. }
  30512. } else {
  30513. maskPromise = Promise.resolve(null);
  30514. }
  30515. }
  30516. return Promise.all([imagePromise, smaskPromise, maskPromise]).then(
  30517. function(results) {
  30518. var imageData = results[0];
  30519. var smaskData = results[1];
  30520. var maskData = results[2];
  30521. return new PDFImage(xref, res, imageData, inline, smaskData, maskData);
  30522. });
  30523. };
  30524. /**
  30525. * Resize an image using the nearest neighbor algorithm. Currently only
  30526. * supports one and three component images.
  30527. * @param {TypedArray} pixels The original image with one component.
  30528. * @param {Number} bpc Number of bits per component.
  30529. * @param {Number} components Number of color components, 1 or 3 is supported.
  30530. * @param {Number} w1 Original width.
  30531. * @param {Number} h1 Original height.
  30532. * @param {Number} w2 New width.
  30533. * @param {Number} h2 New height.
  30534. * @param {TypedArray} dest (Optional) The destination buffer.
  30535. * @param {Number} alpha01 (Optional) Size reserved for the alpha channel.
  30536. * @return {TypedArray} Resized image data.
  30537. */
  30538. PDFImage.resize = function PDFImage_resize(pixels, bpc, components,
  30539. w1, h1, w2, h2, dest, alpha01) {
  30540. if (components !== 1 && components !== 3) {
  30541. error('Unsupported component count for resizing.');
  30542. }
  30543. var length = w2 * h2 * components;
  30544. var temp = dest ? dest : (bpc <= 8 ? new Uint8Array(length) :
  30545. (bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length)));
  30546. var xRatio = w1 / w2;
  30547. var yRatio = h1 / h2;
  30548. var i, j, py, newIndex = 0, oldIndex;
  30549. var xScaled = new Uint16Array(w2);
  30550. var w1Scanline = w1 * components;
  30551. if (alpha01 !== 1) {
  30552. alpha01 = 0;
  30553. }
  30554. for (j = 0; j < w2; j++) {
  30555. xScaled[j] = Math.floor(j * xRatio) * components;
  30556. }
  30557. if (components === 1) {
  30558. for (i = 0; i < h2; i++) {
  30559. py = Math.floor(i * yRatio) * w1Scanline;
  30560. for (j = 0; j < w2; j++) {
  30561. oldIndex = py + xScaled[j];
  30562. temp[newIndex++] = pixels[oldIndex];
  30563. }
  30564. }
  30565. } else if (components === 3) {
  30566. for (i = 0; i < h2; i++) {
  30567. py = Math.floor(i * yRatio) * w1Scanline;
  30568. for (j = 0; j < w2; j++) {
  30569. oldIndex = py + xScaled[j];
  30570. temp[newIndex++] = pixels[oldIndex++];
  30571. temp[newIndex++] = pixels[oldIndex++];
  30572. temp[newIndex++] = pixels[oldIndex++];
  30573. newIndex += alpha01;
  30574. }
  30575. }
  30576. }
  30577. return temp;
  30578. };
  30579. PDFImage.createMask =
  30580. function PDFImage_createMask(imgArray, width, height,
  30581. imageIsFromDecodeStream, inverseDecode) {
  30582. // |imgArray| might not contain full data for every pixel of the mask, so
  30583. // we need to distinguish between |computedLength| and |actualLength|.
  30584. // In particular, if inverseDecode is true, then the array we return must
  30585. // have a length of |computedLength|.
  30586. var computedLength = ((width + 7) >> 3) * height;
  30587. var actualLength = imgArray.byteLength;
  30588. var haveFullData = computedLength === actualLength;
  30589. var data, i;
  30590. if (imageIsFromDecodeStream && (!inverseDecode || haveFullData)) {
  30591. // imgArray came from a DecodeStream and its data is in an appropriate
  30592. // form, so we can just transfer it.
  30593. data = imgArray;
  30594. } else if (!inverseDecode) {
  30595. data = new Uint8Array(actualLength);
  30596. data.set(imgArray);
  30597. } else {
  30598. data = new Uint8Array(computedLength);
  30599. data.set(imgArray);
  30600. for (i = actualLength; i < computedLength; i++) {
  30601. data[i] = 0xff;
  30602. }
  30603. }
  30604. // If necessary, invert the original mask data (but not any extra we might
  30605. // have added above). It's safe to modify the array -- whether it's the
  30606. // original or a copy, we're about to transfer it anyway, so nothing else
  30607. // in this thread can be relying on its contents.
  30608. if (inverseDecode) {
  30609. for (i = 0; i < actualLength; i++) {
  30610. data[i] = ~data[i];
  30611. }
  30612. }
  30613. return {data: data, width: width, height: height};
  30614. };
  30615. PDFImage.prototype = {
  30616. get drawWidth() {
  30617. return Math.max(this.width,
  30618. this.smask && this.smask.width || 0,
  30619. this.mask && this.mask.width || 0);
  30620. },
  30621. get drawHeight() {
  30622. return Math.max(this.height,
  30623. this.smask && this.smask.height || 0,
  30624. this.mask && this.mask.height || 0);
  30625. },
  30626. decodeBuffer: function PDFImage_decodeBuffer(buffer) {
  30627. var bpc = this.bpc;
  30628. var numComps = this.numComps;
  30629. var decodeAddends = this.decodeAddends;
  30630. var decodeCoefficients = this.decodeCoefficients;
  30631. var max = (1 << bpc) - 1;
  30632. var i, ii;
  30633. if (bpc === 1) {
  30634. // If the buffer needed decode that means it just needs to be inverted.
  30635. for (i = 0, ii = buffer.length; i < ii; i++) {
  30636. buffer[i] = +!(buffer[i]);
  30637. }
  30638. return;
  30639. }
  30640. var index = 0;
  30641. for (i = 0, ii = this.width * this.height; i < ii; i++) {
  30642. for (var j = 0; j < numComps; j++) {
  30643. buffer[index] = decodeAndClamp(buffer[index], decodeAddends[j],
  30644. decodeCoefficients[j], max);
  30645. index++;
  30646. }
  30647. }
  30648. },
  30649. getComponents: function PDFImage_getComponents(buffer) {
  30650. var bpc = this.bpc;
  30651. // This image doesn't require any extra work.
  30652. if (bpc === 8) {
  30653. return buffer;
  30654. }
  30655. var width = this.width;
  30656. var height = this.height;
  30657. var numComps = this.numComps;
  30658. var length = width * height * numComps;
  30659. var bufferPos = 0;
  30660. var output = (bpc <= 8 ? new Uint8Array(length) :
  30661. (bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length)));
  30662. var rowComps = width * numComps;
  30663. var max = (1 << bpc) - 1;
  30664. var i = 0, ii, buf;
  30665. if (bpc === 1) {
  30666. // Optimization for reading 1 bpc images.
  30667. var mask, loop1End, loop2End;
  30668. for (var j = 0; j < height; j++) {
  30669. loop1End = i + (rowComps & ~7);
  30670. loop2End = i + rowComps;
  30671. // unroll loop for all full bytes
  30672. while (i < loop1End) {
  30673. buf = buffer[bufferPos++];
  30674. output[i] = (buf >> 7) & 1;
  30675. output[i + 1] = (buf >> 6) & 1;
  30676. output[i + 2] = (buf >> 5) & 1;
  30677. output[i + 3] = (buf >> 4) & 1;
  30678. output[i + 4] = (buf >> 3) & 1;
  30679. output[i + 5] = (buf >> 2) & 1;
  30680. output[i + 6] = (buf >> 1) & 1;
  30681. output[i + 7] = buf & 1;
  30682. i += 8;
  30683. }
  30684. // handle remaing bits
  30685. if (i < loop2End) {
  30686. buf = buffer[bufferPos++];
  30687. mask = 128;
  30688. while (i < loop2End) {
  30689. output[i++] = +!!(buf & mask);
  30690. mask >>= 1;
  30691. }
  30692. }
  30693. }
  30694. } else {
  30695. // The general case that handles all other bpc values.
  30696. var bits = 0;
  30697. buf = 0;
  30698. for (i = 0, ii = length; i < ii; ++i) {
  30699. if (i % rowComps === 0) {
  30700. buf = 0;
  30701. bits = 0;
  30702. }
  30703. while (bits < bpc) {
  30704. buf = (buf << 8) | buffer[bufferPos++];
  30705. bits += 8;
  30706. }
  30707. var remainingBits = bits - bpc;
  30708. var value = buf >> remainingBits;
  30709. output[i] = (value < 0 ? 0 : (value > max ? max : value));
  30710. buf = buf & ((1 << remainingBits) - 1);
  30711. bits = remainingBits;
  30712. }
  30713. }
  30714. return output;
  30715. },
  30716. fillOpacity: function PDFImage_fillOpacity(rgbaBuf, width, height,
  30717. actualHeight, image) {
  30718. var smask = this.smask;
  30719. var mask = this.mask;
  30720. var alphaBuf, sw, sh, i, ii, j;
  30721. if (smask) {
  30722. sw = smask.width;
  30723. sh = smask.height;
  30724. alphaBuf = new Uint8Array(sw * sh);
  30725. smask.fillGrayBuffer(alphaBuf);
  30726. if (sw !== width || sh !== height) {
  30727. alphaBuf = PDFImage.resize(alphaBuf, smask.bpc, 1, sw, sh, width,
  30728. height);
  30729. }
  30730. } else if (mask) {
  30731. if (mask instanceof PDFImage) {
  30732. sw = mask.width;
  30733. sh = mask.height;
  30734. alphaBuf = new Uint8Array(sw * sh);
  30735. mask.numComps = 1;
  30736. mask.fillGrayBuffer(alphaBuf);
  30737. // Need to invert values in rgbaBuf
  30738. for (i = 0, ii = sw * sh; i < ii; ++i) {
  30739. alphaBuf[i] = 255 - alphaBuf[i];
  30740. }
  30741. if (sw !== width || sh !== height) {
  30742. alphaBuf = PDFImage.resize(alphaBuf, mask.bpc, 1, sw, sh, width,
  30743. height);
  30744. }
  30745. } else if (isArray(mask)) {
  30746. // Color key mask: if any of the compontents are outside the range
  30747. // then they should be painted.
  30748. alphaBuf = new Uint8Array(width * height);
  30749. var numComps = this.numComps;
  30750. for (i = 0, ii = width * height; i < ii; ++i) {
  30751. var opacity = 0;
  30752. var imageOffset = i * numComps;
  30753. for (j = 0; j < numComps; ++j) {
  30754. var color = image[imageOffset + j];
  30755. var maskOffset = j * 2;
  30756. if (color < mask[maskOffset] || color > mask[maskOffset + 1]) {
  30757. opacity = 255;
  30758. break;
  30759. }
  30760. }
  30761. alphaBuf[i] = opacity;
  30762. }
  30763. } else {
  30764. error('Unknown mask format.');
  30765. }
  30766. }
  30767. if (alphaBuf) {
  30768. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  30769. rgbaBuf[j] = alphaBuf[i];
  30770. }
  30771. } else {
  30772. // No mask.
  30773. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  30774. rgbaBuf[j] = 255;
  30775. }
  30776. }
  30777. },
  30778. undoPreblend: function PDFImage_undoPreblend(buffer, width, height) {
  30779. var matte = this.smask && this.smask.matte;
  30780. if (!matte) {
  30781. return;
  30782. }
  30783. var matteRgb = this.colorSpace.getRgb(matte, 0);
  30784. var matteR = matteRgb[0];
  30785. var matteG = matteRgb[1];
  30786. var matteB = matteRgb[2];
  30787. var length = width * height * 4;
  30788. var r, g, b;
  30789. for (var i = 0; i < length; i += 4) {
  30790. var alpha = buffer[i + 3];
  30791. if (alpha === 0) {
  30792. // according formula we have to get Infinity in all components
  30793. // making it white (typical paper color) should be okay
  30794. buffer[i] = 255;
  30795. buffer[i + 1] = 255;
  30796. buffer[i + 2] = 255;
  30797. continue;
  30798. }
  30799. var k = 255 / alpha;
  30800. r = (buffer[i] - matteR) * k + matteR;
  30801. g = (buffer[i + 1] - matteG) * k + matteG;
  30802. b = (buffer[i + 2] - matteB) * k + matteB;
  30803. buffer[i] = r <= 0 ? 0 : r >= 255 ? 255 : r | 0;
  30804. buffer[i + 1] = g <= 0 ? 0 : g >= 255 ? 255 : g | 0;
  30805. buffer[i + 2] = b <= 0 ? 0 : b >= 255 ? 255 : b | 0;
  30806. }
  30807. },
  30808. createImageData: function PDFImage_createImageData(forceRGBA) {
  30809. var drawWidth = this.drawWidth;
  30810. var drawHeight = this.drawHeight;
  30811. var imgData = { // other fields are filled in below
  30812. width: drawWidth,
  30813. height: drawHeight
  30814. };
  30815. var numComps = this.numComps;
  30816. var originalWidth = this.width;
  30817. var originalHeight = this.height;
  30818. var bpc = this.bpc;
  30819. // Rows start at byte boundary.
  30820. var rowBytes = (originalWidth * numComps * bpc + 7) >> 3;
  30821. var imgArray;
  30822. if (!forceRGBA) {
  30823. // If it is a 1-bit-per-pixel grayscale (i.e. black-and-white) image
  30824. // without any complications, we pass a same-sized copy to the main
  30825. // thread rather than expanding by 32x to RGBA form. This saves *lots*
  30826. // of memory for many scanned documents. It's also much faster.
  30827. //
  30828. // Similarly, if it is a 24-bit-per pixel RGB image without any
  30829. // complications, we avoid expanding by 1.333x to RGBA form.
  30830. var kind;
  30831. if (this.colorSpace.name === 'DeviceGray' && bpc === 1) {
  30832. kind = ImageKind.GRAYSCALE_1BPP;
  30833. } else if (this.colorSpace.name === 'DeviceRGB' && bpc === 8 &&
  30834. !this.needsDecode) {
  30835. kind = ImageKind.RGB_24BPP;
  30836. }
  30837. if (kind && !this.smask && !this.mask &&
  30838. drawWidth === originalWidth && drawHeight === originalHeight) {
  30839. imgData.kind = kind;
  30840. imgArray = this.getImageBytes(originalHeight * rowBytes);
  30841. // If imgArray came from a DecodeStream, we're safe to transfer it
  30842. // (and thus neuter it) because it will constitute the entire
  30843. // DecodeStream's data. But if it came from a Stream, we need to
  30844. // copy it because it'll only be a portion of the Stream's data, and
  30845. // the rest will be read later on.
  30846. if (this.image instanceof DecodeStream) {
  30847. imgData.data = imgArray;
  30848. } else {
  30849. var newArray = new Uint8Array(imgArray.length);
  30850. newArray.set(imgArray);
  30851. imgData.data = newArray;
  30852. }
  30853. if (this.needsDecode) {
  30854. // Invert the buffer (which must be grayscale if we reached here).
  30855. assert(kind === ImageKind.GRAYSCALE_1BPP);
  30856. var buffer = imgData.data;
  30857. for (var i = 0, ii = buffer.length; i < ii; i++) {
  30858. buffer[i] ^= 0xff;
  30859. }
  30860. }
  30861. return imgData;
  30862. }
  30863. if (this.image instanceof JpegStream && !this.smask && !this.mask) {
  30864. imgData.kind = ImageKind.RGB_24BPP;
  30865. imgData.data = this.getImageBytes(originalHeight * rowBytes,
  30866. drawWidth, drawHeight, true);
  30867. return imgData;
  30868. }
  30869. }
  30870. imgArray = this.getImageBytes(originalHeight * rowBytes);
  30871. // imgArray can be incomplete (e.g. after CCITT fax encoding).
  30872. var actualHeight = 0 | (imgArray.length / rowBytes *
  30873. drawHeight / originalHeight);
  30874. var comps = this.getComponents(imgArray);
  30875. // If opacity data is present, use RGBA_32BPP form. Otherwise, use the
  30876. // more compact RGB_24BPP form if allowable.
  30877. var alpha01, maybeUndoPreblend;
  30878. if (!forceRGBA && !this.smask && !this.mask) {
  30879. imgData.kind = ImageKind.RGB_24BPP;
  30880. imgData.data = new Uint8Array(drawWidth * drawHeight * 3);
  30881. alpha01 = 0;
  30882. maybeUndoPreblend = false;
  30883. } else {
  30884. imgData.kind = ImageKind.RGBA_32BPP;
  30885. imgData.data = new Uint8Array(drawWidth * drawHeight * 4);
  30886. alpha01 = 1;
  30887. maybeUndoPreblend = true;
  30888. // Color key masking (opacity) must be performed before decoding.
  30889. this.fillOpacity(imgData.data, drawWidth, drawHeight, actualHeight,
  30890. comps);
  30891. }
  30892. if (this.needsDecode) {
  30893. this.decodeBuffer(comps);
  30894. }
  30895. this.colorSpace.fillRgb(imgData.data, originalWidth, originalHeight,
  30896. drawWidth, drawHeight, actualHeight, bpc, comps,
  30897. alpha01);
  30898. if (maybeUndoPreblend) {
  30899. this.undoPreblend(imgData.data, drawWidth, actualHeight);
  30900. }
  30901. return imgData;
  30902. },
  30903. fillGrayBuffer: function PDFImage_fillGrayBuffer(buffer) {
  30904. var numComps = this.numComps;
  30905. if (numComps !== 1) {
  30906. error('Reading gray scale from a color image: ' + numComps);
  30907. }
  30908. var width = this.width;
  30909. var height = this.height;
  30910. var bpc = this.bpc;
  30911. // rows start at byte boundary
  30912. var rowBytes = (width * numComps * bpc + 7) >> 3;
  30913. var imgArray = this.getImageBytes(height * rowBytes);
  30914. var comps = this.getComponents(imgArray);
  30915. var i, length;
  30916. if (bpc === 1) {
  30917. // inline decoding (= inversion) for 1 bpc images
  30918. length = width * height;
  30919. if (this.needsDecode) {
  30920. // invert and scale to {0, 255}
  30921. for (i = 0; i < length; ++i) {
  30922. buffer[i] = (comps[i] - 1) & 255;
  30923. }
  30924. } else {
  30925. // scale to {0, 255}
  30926. for (i = 0; i < length; ++i) {
  30927. buffer[i] = (-comps[i]) & 255;
  30928. }
  30929. }
  30930. return;
  30931. }
  30932. if (this.needsDecode) {
  30933. this.decodeBuffer(comps);
  30934. }
  30935. length = width * height;
  30936. // we aren't using a colorspace so we need to scale the value
  30937. var scale = 255 / ((1 << bpc) - 1);
  30938. for (i = 0; i < length; ++i) {
  30939. buffer[i] = (scale * comps[i]) | 0;
  30940. }
  30941. },
  30942. getImageBytes: function PDFImage_getImageBytes(length,
  30943. drawWidth, drawHeight,
  30944. forceRGB) {
  30945. this.image.reset();
  30946. this.image.drawWidth = drawWidth || this.width;
  30947. this.image.drawHeight = drawHeight || this.height;
  30948. this.image.forceRGB = !!forceRGB;
  30949. return this.image.getBytes(length);
  30950. }
  30951. };
  30952. return PDFImage;
  30953. })();
  30954. // The Metrics object contains glyph widths (in glyph space units).
  30955. // As per PDF spec, for most fonts (Type 3 being an exception) a glyph
  30956. // space unit corresponds to 1/1000th of text space unit.
  30957. var Metrics = {
  30958. 'Courier': 600,
  30959. 'Courier-Bold': 600,
  30960. 'Courier-BoldOblique': 600,
  30961. 'Courier-Oblique': 600,
  30962. 'Helvetica' : {
  30963. 'space': 278,
  30964. 'exclam': 278,
  30965. 'quotedbl': 355,
  30966. 'numbersign': 556,
  30967. 'dollar': 556,
  30968. 'percent': 889,
  30969. 'ampersand': 667,
  30970. 'quoteright': 222,
  30971. 'parenleft': 333,
  30972. 'parenright': 333,
  30973. 'asterisk': 389,
  30974. 'plus': 584,
  30975. 'comma': 278,
  30976. 'hyphen': 333,
  30977. 'period': 278,
  30978. 'slash': 278,
  30979. 'zero': 556,
  30980. 'one': 556,
  30981. 'two': 556,
  30982. 'three': 556,
  30983. 'four': 556,
  30984. 'five': 556,
  30985. 'six': 556,
  30986. 'seven': 556,
  30987. 'eight': 556,
  30988. 'nine': 556,
  30989. 'colon': 278,
  30990. 'semicolon': 278,
  30991. 'less': 584,
  30992. 'equal': 584,
  30993. 'greater': 584,
  30994. 'question': 556,
  30995. 'at': 1015,
  30996. 'A': 667,
  30997. 'B': 667,
  30998. 'C': 722,
  30999. 'D': 722,
  31000. 'E': 667,
  31001. 'F': 611,
  31002. 'G': 778,
  31003. 'H': 722,
  31004. 'I': 278,
  31005. 'J': 500,
  31006. 'K': 667,
  31007. 'L': 556,
  31008. 'M': 833,
  31009. 'N': 722,
  31010. 'O': 778,
  31011. 'P': 667,
  31012. 'Q': 778,
  31013. 'R': 722,
  31014. 'S': 667,
  31015. 'T': 611,
  31016. 'U': 722,
  31017. 'V': 667,
  31018. 'W': 944,
  31019. 'X': 667,
  31020. 'Y': 667,
  31021. 'Z': 611,
  31022. 'bracketleft': 278,
  31023. 'backslash': 278,
  31024. 'bracketright': 278,
  31025. 'asciicircum': 469,
  31026. 'underscore': 556,
  31027. 'quoteleft': 222,
  31028. 'a': 556,
  31029. 'b': 556,
  31030. 'c': 500,
  31031. 'd': 556,
  31032. 'e': 556,
  31033. 'f': 278,
  31034. 'g': 556,
  31035. 'h': 556,
  31036. 'i': 222,
  31037. 'j': 222,
  31038. 'k': 500,
  31039. 'l': 222,
  31040. 'm': 833,
  31041. 'n': 556,
  31042. 'o': 556,
  31043. 'p': 556,
  31044. 'q': 556,
  31045. 'r': 333,
  31046. 's': 500,
  31047. 't': 278,
  31048. 'u': 556,
  31049. 'v': 500,
  31050. 'w': 722,
  31051. 'x': 500,
  31052. 'y': 500,
  31053. 'z': 500,
  31054. 'braceleft': 334,
  31055. 'bar': 260,
  31056. 'braceright': 334,
  31057. 'asciitilde': 584,
  31058. 'exclamdown': 333,
  31059. 'cent': 556,
  31060. 'sterling': 556,
  31061. 'fraction': 167,
  31062. 'yen': 556,
  31063. 'florin': 556,
  31064. 'section': 556,
  31065. 'currency': 556,
  31066. 'quotesingle': 191,
  31067. 'quotedblleft': 333,
  31068. 'guillemotleft': 556,
  31069. 'guilsinglleft': 333,
  31070. 'guilsinglright': 333,
  31071. 'fi': 500,
  31072. 'fl': 500,
  31073. 'endash': 556,
  31074. 'dagger': 556,
  31075. 'daggerdbl': 556,
  31076. 'periodcentered': 278,
  31077. 'paragraph': 537,
  31078. 'bullet': 350,
  31079. 'quotesinglbase': 222,
  31080. 'quotedblbase': 333,
  31081. 'quotedblright': 333,
  31082. 'guillemotright': 556,
  31083. 'ellipsis': 1000,
  31084. 'perthousand': 1000,
  31085. 'questiondown': 611,
  31086. 'grave': 333,
  31087. 'acute': 333,
  31088. 'circumflex': 333,
  31089. 'tilde': 333,
  31090. 'macron': 333,
  31091. 'breve': 333,
  31092. 'dotaccent': 333,
  31093. 'dieresis': 333,
  31094. 'ring': 333,
  31095. 'cedilla': 333,
  31096. 'hungarumlaut': 333,
  31097. 'ogonek': 333,
  31098. 'caron': 333,
  31099. 'emdash': 1000,
  31100. 'AE': 1000,
  31101. 'ordfeminine': 370,
  31102. 'Lslash': 556,
  31103. 'Oslash': 778,
  31104. 'OE': 1000,
  31105. 'ordmasculine': 365,
  31106. 'ae': 889,
  31107. 'dotlessi': 278,
  31108. 'lslash': 222,
  31109. 'oslash': 611,
  31110. 'oe': 944,
  31111. 'germandbls': 611,
  31112. 'Idieresis': 278,
  31113. 'eacute': 556,
  31114. 'abreve': 556,
  31115. 'uhungarumlaut': 556,
  31116. 'ecaron': 556,
  31117. 'Ydieresis': 667,
  31118. 'divide': 584,
  31119. 'Yacute': 667,
  31120. 'Acircumflex': 667,
  31121. 'aacute': 556,
  31122. 'Ucircumflex': 722,
  31123. 'yacute': 500,
  31124. 'scommaaccent': 500,
  31125. 'ecircumflex': 556,
  31126. 'Uring': 722,
  31127. 'Udieresis': 722,
  31128. 'aogonek': 556,
  31129. 'Uacute': 722,
  31130. 'uogonek': 556,
  31131. 'Edieresis': 667,
  31132. 'Dcroat': 722,
  31133. 'commaaccent': 250,
  31134. 'copyright': 737,
  31135. 'Emacron': 667,
  31136. 'ccaron': 500,
  31137. 'aring': 556,
  31138. 'Ncommaaccent': 722,
  31139. 'lacute': 222,
  31140. 'agrave': 556,
  31141. 'Tcommaaccent': 611,
  31142. 'Cacute': 722,
  31143. 'atilde': 556,
  31144. 'Edotaccent': 667,
  31145. 'scaron': 500,
  31146. 'scedilla': 500,
  31147. 'iacute': 278,
  31148. 'lozenge': 471,
  31149. 'Rcaron': 722,
  31150. 'Gcommaaccent': 778,
  31151. 'ucircumflex': 556,
  31152. 'acircumflex': 556,
  31153. 'Amacron': 667,
  31154. 'rcaron': 333,
  31155. 'ccedilla': 500,
  31156. 'Zdotaccent': 611,
  31157. 'Thorn': 667,
  31158. 'Omacron': 778,
  31159. 'Racute': 722,
  31160. 'Sacute': 667,
  31161. 'dcaron': 643,
  31162. 'Umacron': 722,
  31163. 'uring': 556,
  31164. 'threesuperior': 333,
  31165. 'Ograve': 778,
  31166. 'Agrave': 667,
  31167. 'Abreve': 667,
  31168. 'multiply': 584,
  31169. 'uacute': 556,
  31170. 'Tcaron': 611,
  31171. 'partialdiff': 476,
  31172. 'ydieresis': 500,
  31173. 'Nacute': 722,
  31174. 'icircumflex': 278,
  31175. 'Ecircumflex': 667,
  31176. 'adieresis': 556,
  31177. 'edieresis': 556,
  31178. 'cacute': 500,
  31179. 'nacute': 556,
  31180. 'umacron': 556,
  31181. 'Ncaron': 722,
  31182. 'Iacute': 278,
  31183. 'plusminus': 584,
  31184. 'brokenbar': 260,
  31185. 'registered': 737,
  31186. 'Gbreve': 778,
  31187. 'Idotaccent': 278,
  31188. 'summation': 600,
  31189. 'Egrave': 667,
  31190. 'racute': 333,
  31191. 'omacron': 556,
  31192. 'Zacute': 611,
  31193. 'Zcaron': 611,
  31194. 'greaterequal': 549,
  31195. 'Eth': 722,
  31196. 'Ccedilla': 722,
  31197. 'lcommaaccent': 222,
  31198. 'tcaron': 317,
  31199. 'eogonek': 556,
  31200. 'Uogonek': 722,
  31201. 'Aacute': 667,
  31202. 'Adieresis': 667,
  31203. 'egrave': 556,
  31204. 'zacute': 500,
  31205. 'iogonek': 222,
  31206. 'Oacute': 778,
  31207. 'oacute': 556,
  31208. 'amacron': 556,
  31209. 'sacute': 500,
  31210. 'idieresis': 278,
  31211. 'Ocircumflex': 778,
  31212. 'Ugrave': 722,
  31213. 'Delta': 612,
  31214. 'thorn': 556,
  31215. 'twosuperior': 333,
  31216. 'Odieresis': 778,
  31217. 'mu': 556,
  31218. 'igrave': 278,
  31219. 'ohungarumlaut': 556,
  31220. 'Eogonek': 667,
  31221. 'dcroat': 556,
  31222. 'threequarters': 834,
  31223. 'Scedilla': 667,
  31224. 'lcaron': 299,
  31225. 'Kcommaaccent': 667,
  31226. 'Lacute': 556,
  31227. 'trademark': 1000,
  31228. 'edotaccent': 556,
  31229. 'Igrave': 278,
  31230. 'Imacron': 278,
  31231. 'Lcaron': 556,
  31232. 'onehalf': 834,
  31233. 'lessequal': 549,
  31234. 'ocircumflex': 556,
  31235. 'ntilde': 556,
  31236. 'Uhungarumlaut': 722,
  31237. 'Eacute': 667,
  31238. 'emacron': 556,
  31239. 'gbreve': 556,
  31240. 'onequarter': 834,
  31241. 'Scaron': 667,
  31242. 'Scommaaccent': 667,
  31243. 'Ohungarumlaut': 778,
  31244. 'degree': 400,
  31245. 'ograve': 556,
  31246. 'Ccaron': 722,
  31247. 'ugrave': 556,
  31248. 'radical': 453,
  31249. 'Dcaron': 722,
  31250. 'rcommaaccent': 333,
  31251. 'Ntilde': 722,
  31252. 'otilde': 556,
  31253. 'Rcommaaccent': 722,
  31254. 'Lcommaaccent': 556,
  31255. 'Atilde': 667,
  31256. 'Aogonek': 667,
  31257. 'Aring': 667,
  31258. 'Otilde': 778,
  31259. 'zdotaccent': 500,
  31260. 'Ecaron': 667,
  31261. 'Iogonek': 278,
  31262. 'kcommaaccent': 500,
  31263. 'minus': 584,
  31264. 'Icircumflex': 278,
  31265. 'ncaron': 556,
  31266. 'tcommaaccent': 278,
  31267. 'logicalnot': 584,
  31268. 'odieresis': 556,
  31269. 'udieresis': 556,
  31270. 'notequal': 549,
  31271. 'gcommaaccent': 556,
  31272. 'eth': 556,
  31273. 'zcaron': 500,
  31274. 'ncommaaccent': 556,
  31275. 'onesuperior': 333,
  31276. 'imacron': 278,
  31277. 'Euro': 556
  31278. },
  31279. 'Helvetica-Bold': {
  31280. 'space': 278,
  31281. 'exclam': 333,
  31282. 'quotedbl': 474,
  31283. 'numbersign': 556,
  31284. 'dollar': 556,
  31285. 'percent': 889,
  31286. 'ampersand': 722,
  31287. 'quoteright': 278,
  31288. 'parenleft': 333,
  31289. 'parenright': 333,
  31290. 'asterisk': 389,
  31291. 'plus': 584,
  31292. 'comma': 278,
  31293. 'hyphen': 333,
  31294. 'period': 278,
  31295. 'slash': 278,
  31296. 'zero': 556,
  31297. 'one': 556,
  31298. 'two': 556,
  31299. 'three': 556,
  31300. 'four': 556,
  31301. 'five': 556,
  31302. 'six': 556,
  31303. 'seven': 556,
  31304. 'eight': 556,
  31305. 'nine': 556,
  31306. 'colon': 333,
  31307. 'semicolon': 333,
  31308. 'less': 584,
  31309. 'equal': 584,
  31310. 'greater': 584,
  31311. 'question': 611,
  31312. 'at': 975,
  31313. 'A': 722,
  31314. 'B': 722,
  31315. 'C': 722,
  31316. 'D': 722,
  31317. 'E': 667,
  31318. 'F': 611,
  31319. 'G': 778,
  31320. 'H': 722,
  31321. 'I': 278,
  31322. 'J': 556,
  31323. 'K': 722,
  31324. 'L': 611,
  31325. 'M': 833,
  31326. 'N': 722,
  31327. 'O': 778,
  31328. 'P': 667,
  31329. 'Q': 778,
  31330. 'R': 722,
  31331. 'S': 667,
  31332. 'T': 611,
  31333. 'U': 722,
  31334. 'V': 667,
  31335. 'W': 944,
  31336. 'X': 667,
  31337. 'Y': 667,
  31338. 'Z': 611,
  31339. 'bracketleft': 333,
  31340. 'backslash': 278,
  31341. 'bracketright': 333,
  31342. 'asciicircum': 584,
  31343. 'underscore': 556,
  31344. 'quoteleft': 278,
  31345. 'a': 556,
  31346. 'b': 611,
  31347. 'c': 556,
  31348. 'd': 611,
  31349. 'e': 556,
  31350. 'f': 333,
  31351. 'g': 611,
  31352. 'h': 611,
  31353. 'i': 278,
  31354. 'j': 278,
  31355. 'k': 556,
  31356. 'l': 278,
  31357. 'm': 889,
  31358. 'n': 611,
  31359. 'o': 611,
  31360. 'p': 611,
  31361. 'q': 611,
  31362. 'r': 389,
  31363. 's': 556,
  31364. 't': 333,
  31365. 'u': 611,
  31366. 'v': 556,
  31367. 'w': 778,
  31368. 'x': 556,
  31369. 'y': 556,
  31370. 'z': 500,
  31371. 'braceleft': 389,
  31372. 'bar': 280,
  31373. 'braceright': 389,
  31374. 'asciitilde': 584,
  31375. 'exclamdown': 333,
  31376. 'cent': 556,
  31377. 'sterling': 556,
  31378. 'fraction': 167,
  31379. 'yen': 556,
  31380. 'florin': 556,
  31381. 'section': 556,
  31382. 'currency': 556,
  31383. 'quotesingle': 238,
  31384. 'quotedblleft': 500,
  31385. 'guillemotleft': 556,
  31386. 'guilsinglleft': 333,
  31387. 'guilsinglright': 333,
  31388. 'fi': 611,
  31389. 'fl': 611,
  31390. 'endash': 556,
  31391. 'dagger': 556,
  31392. 'daggerdbl': 556,
  31393. 'periodcentered': 278,
  31394. 'paragraph': 556,
  31395. 'bullet': 350,
  31396. 'quotesinglbase': 278,
  31397. 'quotedblbase': 500,
  31398. 'quotedblright': 500,
  31399. 'guillemotright': 556,
  31400. 'ellipsis': 1000,
  31401. 'perthousand': 1000,
  31402. 'questiondown': 611,
  31403. 'grave': 333,
  31404. 'acute': 333,
  31405. 'circumflex': 333,
  31406. 'tilde': 333,
  31407. 'macron': 333,
  31408. 'breve': 333,
  31409. 'dotaccent': 333,
  31410. 'dieresis': 333,
  31411. 'ring': 333,
  31412. 'cedilla': 333,
  31413. 'hungarumlaut': 333,
  31414. 'ogonek': 333,
  31415. 'caron': 333,
  31416. 'emdash': 1000,
  31417. 'AE': 1000,
  31418. 'ordfeminine': 370,
  31419. 'Lslash': 611,
  31420. 'Oslash': 778,
  31421. 'OE': 1000,
  31422. 'ordmasculine': 365,
  31423. 'ae': 889,
  31424. 'dotlessi': 278,
  31425. 'lslash': 278,
  31426. 'oslash': 611,
  31427. 'oe': 944,
  31428. 'germandbls': 611,
  31429. 'Idieresis': 278,
  31430. 'eacute': 556,
  31431. 'abreve': 556,
  31432. 'uhungarumlaut': 611,
  31433. 'ecaron': 556,
  31434. 'Ydieresis': 667,
  31435. 'divide': 584,
  31436. 'Yacute': 667,
  31437. 'Acircumflex': 722,
  31438. 'aacute': 556,
  31439. 'Ucircumflex': 722,
  31440. 'yacute': 556,
  31441. 'scommaaccent': 556,
  31442. 'ecircumflex': 556,
  31443. 'Uring': 722,
  31444. 'Udieresis': 722,
  31445. 'aogonek': 556,
  31446. 'Uacute': 722,
  31447. 'uogonek': 611,
  31448. 'Edieresis': 667,
  31449. 'Dcroat': 722,
  31450. 'commaaccent': 250,
  31451. 'copyright': 737,
  31452. 'Emacron': 667,
  31453. 'ccaron': 556,
  31454. 'aring': 556,
  31455. 'Ncommaaccent': 722,
  31456. 'lacute': 278,
  31457. 'agrave': 556,
  31458. 'Tcommaaccent': 611,
  31459. 'Cacute': 722,
  31460. 'atilde': 556,
  31461. 'Edotaccent': 667,
  31462. 'scaron': 556,
  31463. 'scedilla': 556,
  31464. 'iacute': 278,
  31465. 'lozenge': 494,
  31466. 'Rcaron': 722,
  31467. 'Gcommaaccent': 778,
  31468. 'ucircumflex': 611,
  31469. 'acircumflex': 556,
  31470. 'Amacron': 722,
  31471. 'rcaron': 389,
  31472. 'ccedilla': 556,
  31473. 'Zdotaccent': 611,
  31474. 'Thorn': 667,
  31475. 'Omacron': 778,
  31476. 'Racute': 722,
  31477. 'Sacute': 667,
  31478. 'dcaron': 743,
  31479. 'Umacron': 722,
  31480. 'uring': 611,
  31481. 'threesuperior': 333,
  31482. 'Ograve': 778,
  31483. 'Agrave': 722,
  31484. 'Abreve': 722,
  31485. 'multiply': 584,
  31486. 'uacute': 611,
  31487. 'Tcaron': 611,
  31488. 'partialdiff': 494,
  31489. 'ydieresis': 556,
  31490. 'Nacute': 722,
  31491. 'icircumflex': 278,
  31492. 'Ecircumflex': 667,
  31493. 'adieresis': 556,
  31494. 'edieresis': 556,
  31495. 'cacute': 556,
  31496. 'nacute': 611,
  31497. 'umacron': 611,
  31498. 'Ncaron': 722,
  31499. 'Iacute': 278,
  31500. 'plusminus': 584,
  31501. 'brokenbar': 280,
  31502. 'registered': 737,
  31503. 'Gbreve': 778,
  31504. 'Idotaccent': 278,
  31505. 'summation': 600,
  31506. 'Egrave': 667,
  31507. 'racute': 389,
  31508. 'omacron': 611,
  31509. 'Zacute': 611,
  31510. 'Zcaron': 611,
  31511. 'greaterequal': 549,
  31512. 'Eth': 722,
  31513. 'Ccedilla': 722,
  31514. 'lcommaaccent': 278,
  31515. 'tcaron': 389,
  31516. 'eogonek': 556,
  31517. 'Uogonek': 722,
  31518. 'Aacute': 722,
  31519. 'Adieresis': 722,
  31520. 'egrave': 556,
  31521. 'zacute': 500,
  31522. 'iogonek': 278,
  31523. 'Oacute': 778,
  31524. 'oacute': 611,
  31525. 'amacron': 556,
  31526. 'sacute': 556,
  31527. 'idieresis': 278,
  31528. 'Ocircumflex': 778,
  31529. 'Ugrave': 722,
  31530. 'Delta': 612,
  31531. 'thorn': 611,
  31532. 'twosuperior': 333,
  31533. 'Odieresis': 778,
  31534. 'mu': 611,
  31535. 'igrave': 278,
  31536. 'ohungarumlaut': 611,
  31537. 'Eogonek': 667,
  31538. 'dcroat': 611,
  31539. 'threequarters': 834,
  31540. 'Scedilla': 667,
  31541. 'lcaron': 400,
  31542. 'Kcommaaccent': 722,
  31543. 'Lacute': 611,
  31544. 'trademark': 1000,
  31545. 'edotaccent': 556,
  31546. 'Igrave': 278,
  31547. 'Imacron': 278,
  31548. 'Lcaron': 611,
  31549. 'onehalf': 834,
  31550. 'lessequal': 549,
  31551. 'ocircumflex': 611,
  31552. 'ntilde': 611,
  31553. 'Uhungarumlaut': 722,
  31554. 'Eacute': 667,
  31555. 'emacron': 556,
  31556. 'gbreve': 611,
  31557. 'onequarter': 834,
  31558. 'Scaron': 667,
  31559. 'Scommaaccent': 667,
  31560. 'Ohungarumlaut': 778,
  31561. 'degree': 400,
  31562. 'ograve': 611,
  31563. 'Ccaron': 722,
  31564. 'ugrave': 611,
  31565. 'radical': 549,
  31566. 'Dcaron': 722,
  31567. 'rcommaaccent': 389,
  31568. 'Ntilde': 722,
  31569. 'otilde': 611,
  31570. 'Rcommaaccent': 722,
  31571. 'Lcommaaccent': 611,
  31572. 'Atilde': 722,
  31573. 'Aogonek': 722,
  31574. 'Aring': 722,
  31575. 'Otilde': 778,
  31576. 'zdotaccent': 500,
  31577. 'Ecaron': 667,
  31578. 'Iogonek': 278,
  31579. 'kcommaaccent': 556,
  31580. 'minus': 584,
  31581. 'Icircumflex': 278,
  31582. 'ncaron': 611,
  31583. 'tcommaaccent': 333,
  31584. 'logicalnot': 584,
  31585. 'odieresis': 611,
  31586. 'udieresis': 611,
  31587. 'notequal': 549,
  31588. 'gcommaaccent': 611,
  31589. 'eth': 611,
  31590. 'zcaron': 500,
  31591. 'ncommaaccent': 611,
  31592. 'onesuperior': 333,
  31593. 'imacron': 278,
  31594. 'Euro': 556
  31595. },
  31596. 'Helvetica-BoldOblique': {
  31597. 'space': 278,
  31598. 'exclam': 333,
  31599. 'quotedbl': 474,
  31600. 'numbersign': 556,
  31601. 'dollar': 556,
  31602. 'percent': 889,
  31603. 'ampersand': 722,
  31604. 'quoteright': 278,
  31605. 'parenleft': 333,
  31606. 'parenright': 333,
  31607. 'asterisk': 389,
  31608. 'plus': 584,
  31609. 'comma': 278,
  31610. 'hyphen': 333,
  31611. 'period': 278,
  31612. 'slash': 278,
  31613. 'zero': 556,
  31614. 'one': 556,
  31615. 'two': 556,
  31616. 'three': 556,
  31617. 'four': 556,
  31618. 'five': 556,
  31619. 'six': 556,
  31620. 'seven': 556,
  31621. 'eight': 556,
  31622. 'nine': 556,
  31623. 'colon': 333,
  31624. 'semicolon': 333,
  31625. 'less': 584,
  31626. 'equal': 584,
  31627. 'greater': 584,
  31628. 'question': 611,
  31629. 'at': 975,
  31630. 'A': 722,
  31631. 'B': 722,
  31632. 'C': 722,
  31633. 'D': 722,
  31634. 'E': 667,
  31635. 'F': 611,
  31636. 'G': 778,
  31637. 'H': 722,
  31638. 'I': 278,
  31639. 'J': 556,
  31640. 'K': 722,
  31641. 'L': 611,
  31642. 'M': 833,
  31643. 'N': 722,
  31644. 'O': 778,
  31645. 'P': 667,
  31646. 'Q': 778,
  31647. 'R': 722,
  31648. 'S': 667,
  31649. 'T': 611,
  31650. 'U': 722,
  31651. 'V': 667,
  31652. 'W': 944,
  31653. 'X': 667,
  31654. 'Y': 667,
  31655. 'Z': 611,
  31656. 'bracketleft': 333,
  31657. 'backslash': 278,
  31658. 'bracketright': 333,
  31659. 'asciicircum': 584,
  31660. 'underscore': 556,
  31661. 'quoteleft': 278,
  31662. 'a': 556,
  31663. 'b': 611,
  31664. 'c': 556,
  31665. 'd': 611,
  31666. 'e': 556,
  31667. 'f': 333,
  31668. 'g': 611,
  31669. 'h': 611,
  31670. 'i': 278,
  31671. 'j': 278,
  31672. 'k': 556,
  31673. 'l': 278,
  31674. 'm': 889,
  31675. 'n': 611,
  31676. 'o': 611,
  31677. 'p': 611,
  31678. 'q': 611,
  31679. 'r': 389,
  31680. 's': 556,
  31681. 't': 333,
  31682. 'u': 611,
  31683. 'v': 556,
  31684. 'w': 778,
  31685. 'x': 556,
  31686. 'y': 556,
  31687. 'z': 500,
  31688. 'braceleft': 389,
  31689. 'bar': 280,
  31690. 'braceright': 389,
  31691. 'asciitilde': 584,
  31692. 'exclamdown': 333,
  31693. 'cent': 556,
  31694. 'sterling': 556,
  31695. 'fraction': 167,
  31696. 'yen': 556,
  31697. 'florin': 556,
  31698. 'section': 556,
  31699. 'currency': 556,
  31700. 'quotesingle': 238,
  31701. 'quotedblleft': 500,
  31702. 'guillemotleft': 556,
  31703. 'guilsinglleft': 333,
  31704. 'guilsinglright': 333,
  31705. 'fi': 611,
  31706. 'fl': 611,
  31707. 'endash': 556,
  31708. 'dagger': 556,
  31709. 'daggerdbl': 556,
  31710. 'periodcentered': 278,
  31711. 'paragraph': 556,
  31712. 'bullet': 350,
  31713. 'quotesinglbase': 278,
  31714. 'quotedblbase': 500,
  31715. 'quotedblright': 500,
  31716. 'guillemotright': 556,
  31717. 'ellipsis': 1000,
  31718. 'perthousand': 1000,
  31719. 'questiondown': 611,
  31720. 'grave': 333,
  31721. 'acute': 333,
  31722. 'circumflex': 333,
  31723. 'tilde': 333,
  31724. 'macron': 333,
  31725. 'breve': 333,
  31726. 'dotaccent': 333,
  31727. 'dieresis': 333,
  31728. 'ring': 333,
  31729. 'cedilla': 333,
  31730. 'hungarumlaut': 333,
  31731. 'ogonek': 333,
  31732. 'caron': 333,
  31733. 'emdash': 1000,
  31734. 'AE': 1000,
  31735. 'ordfeminine': 370,
  31736. 'Lslash': 611,
  31737. 'Oslash': 778,
  31738. 'OE': 1000,
  31739. 'ordmasculine': 365,
  31740. 'ae': 889,
  31741. 'dotlessi': 278,
  31742. 'lslash': 278,
  31743. 'oslash': 611,
  31744. 'oe': 944,
  31745. 'germandbls': 611,
  31746. 'Idieresis': 278,
  31747. 'eacute': 556,
  31748. 'abreve': 556,
  31749. 'uhungarumlaut': 611,
  31750. 'ecaron': 556,
  31751. 'Ydieresis': 667,
  31752. 'divide': 584,
  31753. 'Yacute': 667,
  31754. 'Acircumflex': 722,
  31755. 'aacute': 556,
  31756. 'Ucircumflex': 722,
  31757. 'yacute': 556,
  31758. 'scommaaccent': 556,
  31759. 'ecircumflex': 556,
  31760. 'Uring': 722,
  31761. 'Udieresis': 722,
  31762. 'aogonek': 556,
  31763. 'Uacute': 722,
  31764. 'uogonek': 611,
  31765. 'Edieresis': 667,
  31766. 'Dcroat': 722,
  31767. 'commaaccent': 250,
  31768. 'copyright': 737,
  31769. 'Emacron': 667,
  31770. 'ccaron': 556,
  31771. 'aring': 556,
  31772. 'Ncommaaccent': 722,
  31773. 'lacute': 278,
  31774. 'agrave': 556,
  31775. 'Tcommaaccent': 611,
  31776. 'Cacute': 722,
  31777. 'atilde': 556,
  31778. 'Edotaccent': 667,
  31779. 'scaron': 556,
  31780. 'scedilla': 556,
  31781. 'iacute': 278,
  31782. 'lozenge': 494,
  31783. 'Rcaron': 722,
  31784. 'Gcommaaccent': 778,
  31785. 'ucircumflex': 611,
  31786. 'acircumflex': 556,
  31787. 'Amacron': 722,
  31788. 'rcaron': 389,
  31789. 'ccedilla': 556,
  31790. 'Zdotaccent': 611,
  31791. 'Thorn': 667,
  31792. 'Omacron': 778,
  31793. 'Racute': 722,
  31794. 'Sacute': 667,
  31795. 'dcaron': 743,
  31796. 'Umacron': 722,
  31797. 'uring': 611,
  31798. 'threesuperior': 333,
  31799. 'Ograve': 778,
  31800. 'Agrave': 722,
  31801. 'Abreve': 722,
  31802. 'multiply': 584,
  31803. 'uacute': 611,
  31804. 'Tcaron': 611,
  31805. 'partialdiff': 494,
  31806. 'ydieresis': 556,
  31807. 'Nacute': 722,
  31808. 'icircumflex': 278,
  31809. 'Ecircumflex': 667,
  31810. 'adieresis': 556,
  31811. 'edieresis': 556,
  31812. 'cacute': 556,
  31813. 'nacute': 611,
  31814. 'umacron': 611,
  31815. 'Ncaron': 722,
  31816. 'Iacute': 278,
  31817. 'plusminus': 584,
  31818. 'brokenbar': 280,
  31819. 'registered': 737,
  31820. 'Gbreve': 778,
  31821. 'Idotaccent': 278,
  31822. 'summation': 600,
  31823. 'Egrave': 667,
  31824. 'racute': 389,
  31825. 'omacron': 611,
  31826. 'Zacute': 611,
  31827. 'Zcaron': 611,
  31828. 'greaterequal': 549,
  31829. 'Eth': 722,
  31830. 'Ccedilla': 722,
  31831. 'lcommaaccent': 278,
  31832. 'tcaron': 389,
  31833. 'eogonek': 556,
  31834. 'Uogonek': 722,
  31835. 'Aacute': 722,
  31836. 'Adieresis': 722,
  31837. 'egrave': 556,
  31838. 'zacute': 500,
  31839. 'iogonek': 278,
  31840. 'Oacute': 778,
  31841. 'oacute': 611,
  31842. 'amacron': 556,
  31843. 'sacute': 556,
  31844. 'idieresis': 278,
  31845. 'Ocircumflex': 778,
  31846. 'Ugrave': 722,
  31847. 'Delta': 612,
  31848. 'thorn': 611,
  31849. 'twosuperior': 333,
  31850. 'Odieresis': 778,
  31851. 'mu': 611,
  31852. 'igrave': 278,
  31853. 'ohungarumlaut': 611,
  31854. 'Eogonek': 667,
  31855. 'dcroat': 611,
  31856. 'threequarters': 834,
  31857. 'Scedilla': 667,
  31858. 'lcaron': 400,
  31859. 'Kcommaaccent': 722,
  31860. 'Lacute': 611,
  31861. 'trademark': 1000,
  31862. 'edotaccent': 556,
  31863. 'Igrave': 278,
  31864. 'Imacron': 278,
  31865. 'Lcaron': 611,
  31866. 'onehalf': 834,
  31867. 'lessequal': 549,
  31868. 'ocircumflex': 611,
  31869. 'ntilde': 611,
  31870. 'Uhungarumlaut': 722,
  31871. 'Eacute': 667,
  31872. 'emacron': 556,
  31873. 'gbreve': 611,
  31874. 'onequarter': 834,
  31875. 'Scaron': 667,
  31876. 'Scommaaccent': 667,
  31877. 'Ohungarumlaut': 778,
  31878. 'degree': 400,
  31879. 'ograve': 611,
  31880. 'Ccaron': 722,
  31881. 'ugrave': 611,
  31882. 'radical': 549,
  31883. 'Dcaron': 722,
  31884. 'rcommaaccent': 389,
  31885. 'Ntilde': 722,
  31886. 'otilde': 611,
  31887. 'Rcommaaccent': 722,
  31888. 'Lcommaaccent': 611,
  31889. 'Atilde': 722,
  31890. 'Aogonek': 722,
  31891. 'Aring': 722,
  31892. 'Otilde': 778,
  31893. 'zdotaccent': 500,
  31894. 'Ecaron': 667,
  31895. 'Iogonek': 278,
  31896. 'kcommaaccent': 556,
  31897. 'minus': 584,
  31898. 'Icircumflex': 278,
  31899. 'ncaron': 611,
  31900. 'tcommaaccent': 333,
  31901. 'logicalnot': 584,
  31902. 'odieresis': 611,
  31903. 'udieresis': 611,
  31904. 'notequal': 549,
  31905. 'gcommaaccent': 611,
  31906. 'eth': 611,
  31907. 'zcaron': 500,
  31908. 'ncommaaccent': 611,
  31909. 'onesuperior': 333,
  31910. 'imacron': 278,
  31911. 'Euro': 556
  31912. },
  31913. 'Helvetica-Oblique' : {
  31914. 'space': 278,
  31915. 'exclam': 278,
  31916. 'quotedbl': 355,
  31917. 'numbersign': 556,
  31918. 'dollar': 556,
  31919. 'percent': 889,
  31920. 'ampersand': 667,
  31921. 'quoteright': 222,
  31922. 'parenleft': 333,
  31923. 'parenright': 333,
  31924. 'asterisk': 389,
  31925. 'plus': 584,
  31926. 'comma': 278,
  31927. 'hyphen': 333,
  31928. 'period': 278,
  31929. 'slash': 278,
  31930. 'zero': 556,
  31931. 'one': 556,
  31932. 'two': 556,
  31933. 'three': 556,
  31934. 'four': 556,
  31935. 'five': 556,
  31936. 'six': 556,
  31937. 'seven': 556,
  31938. 'eight': 556,
  31939. 'nine': 556,
  31940. 'colon': 278,
  31941. 'semicolon': 278,
  31942. 'less': 584,
  31943. 'equal': 584,
  31944. 'greater': 584,
  31945. 'question': 556,
  31946. 'at': 1015,
  31947. 'A': 667,
  31948. 'B': 667,
  31949. 'C': 722,
  31950. 'D': 722,
  31951. 'E': 667,
  31952. 'F': 611,
  31953. 'G': 778,
  31954. 'H': 722,
  31955. 'I': 278,
  31956. 'J': 500,
  31957. 'K': 667,
  31958. 'L': 556,
  31959. 'M': 833,
  31960. 'N': 722,
  31961. 'O': 778,
  31962. 'P': 667,
  31963. 'Q': 778,
  31964. 'R': 722,
  31965. 'S': 667,
  31966. 'T': 611,
  31967. 'U': 722,
  31968. 'V': 667,
  31969. 'W': 944,
  31970. 'X': 667,
  31971. 'Y': 667,
  31972. 'Z': 611,
  31973. 'bracketleft': 278,
  31974. 'backslash': 278,
  31975. 'bracketright': 278,
  31976. 'asciicircum': 469,
  31977. 'underscore': 556,
  31978. 'quoteleft': 222,
  31979. 'a': 556,
  31980. 'b': 556,
  31981. 'c': 500,
  31982. 'd': 556,
  31983. 'e': 556,
  31984. 'f': 278,
  31985. 'g': 556,
  31986. 'h': 556,
  31987. 'i': 222,
  31988. 'j': 222,
  31989. 'k': 500,
  31990. 'l': 222,
  31991. 'm': 833,
  31992. 'n': 556,
  31993. 'o': 556,
  31994. 'p': 556,
  31995. 'q': 556,
  31996. 'r': 333,
  31997. 's': 500,
  31998. 't': 278,
  31999. 'u': 556,
  32000. 'v': 500,
  32001. 'w': 722,
  32002. 'x': 500,
  32003. 'y': 500,
  32004. 'z': 500,
  32005. 'braceleft': 334,
  32006. 'bar': 260,
  32007. 'braceright': 334,
  32008. 'asciitilde': 584,
  32009. 'exclamdown': 333,
  32010. 'cent': 556,
  32011. 'sterling': 556,
  32012. 'fraction': 167,
  32013. 'yen': 556,
  32014. 'florin': 556,
  32015. 'section': 556,
  32016. 'currency': 556,
  32017. 'quotesingle': 191,
  32018. 'quotedblleft': 333,
  32019. 'guillemotleft': 556,
  32020. 'guilsinglleft': 333,
  32021. 'guilsinglright': 333,
  32022. 'fi': 500,
  32023. 'fl': 500,
  32024. 'endash': 556,
  32025. 'dagger': 556,
  32026. 'daggerdbl': 556,
  32027. 'periodcentered': 278,
  32028. 'paragraph': 537,
  32029. 'bullet': 350,
  32030. 'quotesinglbase': 222,
  32031. 'quotedblbase': 333,
  32032. 'quotedblright': 333,
  32033. 'guillemotright': 556,
  32034. 'ellipsis': 1000,
  32035. 'perthousand': 1000,
  32036. 'questiondown': 611,
  32037. 'grave': 333,
  32038. 'acute': 333,
  32039. 'circumflex': 333,
  32040. 'tilde': 333,
  32041. 'macron': 333,
  32042. 'breve': 333,
  32043. 'dotaccent': 333,
  32044. 'dieresis': 333,
  32045. 'ring': 333,
  32046. 'cedilla': 333,
  32047. 'hungarumlaut': 333,
  32048. 'ogonek': 333,
  32049. 'caron': 333,
  32050. 'emdash': 1000,
  32051. 'AE': 1000,
  32052. 'ordfeminine': 370,
  32053. 'Lslash': 556,
  32054. 'Oslash': 778,
  32055. 'OE': 1000,
  32056. 'ordmasculine': 365,
  32057. 'ae': 889,
  32058. 'dotlessi': 278,
  32059. 'lslash': 222,
  32060. 'oslash': 611,
  32061. 'oe': 944,
  32062. 'germandbls': 611,
  32063. 'Idieresis': 278,
  32064. 'eacute': 556,
  32065. 'abreve': 556,
  32066. 'uhungarumlaut': 556,
  32067. 'ecaron': 556,
  32068. 'Ydieresis': 667,
  32069. 'divide': 584,
  32070. 'Yacute': 667,
  32071. 'Acircumflex': 667,
  32072. 'aacute': 556,
  32073. 'Ucircumflex': 722,
  32074. 'yacute': 500,
  32075. 'scommaaccent': 500,
  32076. 'ecircumflex': 556,
  32077. 'Uring': 722,
  32078. 'Udieresis': 722,
  32079. 'aogonek': 556,
  32080. 'Uacute': 722,
  32081. 'uogonek': 556,
  32082. 'Edieresis': 667,
  32083. 'Dcroat': 722,
  32084. 'commaaccent': 250,
  32085. 'copyright': 737,
  32086. 'Emacron': 667,
  32087. 'ccaron': 500,
  32088. 'aring': 556,
  32089. 'Ncommaaccent': 722,
  32090. 'lacute': 222,
  32091. 'agrave': 556,
  32092. 'Tcommaaccent': 611,
  32093. 'Cacute': 722,
  32094. 'atilde': 556,
  32095. 'Edotaccent': 667,
  32096. 'scaron': 500,
  32097. 'scedilla': 500,
  32098. 'iacute': 278,
  32099. 'lozenge': 471,
  32100. 'Rcaron': 722,
  32101. 'Gcommaaccent': 778,
  32102. 'ucircumflex': 556,
  32103. 'acircumflex': 556,
  32104. 'Amacron': 667,
  32105. 'rcaron': 333,
  32106. 'ccedilla': 500,
  32107. 'Zdotaccent': 611,
  32108. 'Thorn': 667,
  32109. 'Omacron': 778,
  32110. 'Racute': 722,
  32111. 'Sacute': 667,
  32112. 'dcaron': 643,
  32113. 'Umacron': 722,
  32114. 'uring': 556,
  32115. 'threesuperior': 333,
  32116. 'Ograve': 778,
  32117. 'Agrave': 667,
  32118. 'Abreve': 667,
  32119. 'multiply': 584,
  32120. 'uacute': 556,
  32121. 'Tcaron': 611,
  32122. 'partialdiff': 476,
  32123. 'ydieresis': 500,
  32124. 'Nacute': 722,
  32125. 'icircumflex': 278,
  32126. 'Ecircumflex': 667,
  32127. 'adieresis': 556,
  32128. 'edieresis': 556,
  32129. 'cacute': 500,
  32130. 'nacute': 556,
  32131. 'umacron': 556,
  32132. 'Ncaron': 722,
  32133. 'Iacute': 278,
  32134. 'plusminus': 584,
  32135. 'brokenbar': 260,
  32136. 'registered': 737,
  32137. 'Gbreve': 778,
  32138. 'Idotaccent': 278,
  32139. 'summation': 600,
  32140. 'Egrave': 667,
  32141. 'racute': 333,
  32142. 'omacron': 556,
  32143. 'Zacute': 611,
  32144. 'Zcaron': 611,
  32145. 'greaterequal': 549,
  32146. 'Eth': 722,
  32147. 'Ccedilla': 722,
  32148. 'lcommaaccent': 222,
  32149. 'tcaron': 317,
  32150. 'eogonek': 556,
  32151. 'Uogonek': 722,
  32152. 'Aacute': 667,
  32153. 'Adieresis': 667,
  32154. 'egrave': 556,
  32155. 'zacute': 500,
  32156. 'iogonek': 222,
  32157. 'Oacute': 778,
  32158. 'oacute': 556,
  32159. 'amacron': 556,
  32160. 'sacute': 500,
  32161. 'idieresis': 278,
  32162. 'Ocircumflex': 778,
  32163. 'Ugrave': 722,
  32164. 'Delta': 612,
  32165. 'thorn': 556,
  32166. 'twosuperior': 333,
  32167. 'Odieresis': 778,
  32168. 'mu': 556,
  32169. 'igrave': 278,
  32170. 'ohungarumlaut': 556,
  32171. 'Eogonek': 667,
  32172. 'dcroat': 556,
  32173. 'threequarters': 834,
  32174. 'Scedilla': 667,
  32175. 'lcaron': 299,
  32176. 'Kcommaaccent': 667,
  32177. 'Lacute': 556,
  32178. 'trademark': 1000,
  32179. 'edotaccent': 556,
  32180. 'Igrave': 278,
  32181. 'Imacron': 278,
  32182. 'Lcaron': 556,
  32183. 'onehalf': 834,
  32184. 'lessequal': 549,
  32185. 'ocircumflex': 556,
  32186. 'ntilde': 556,
  32187. 'Uhungarumlaut': 722,
  32188. 'Eacute': 667,
  32189. 'emacron': 556,
  32190. 'gbreve': 556,
  32191. 'onequarter': 834,
  32192. 'Scaron': 667,
  32193. 'Scommaaccent': 667,
  32194. 'Ohungarumlaut': 778,
  32195. 'degree': 400,
  32196. 'ograve': 556,
  32197. 'Ccaron': 722,
  32198. 'ugrave': 556,
  32199. 'radical': 453,
  32200. 'Dcaron': 722,
  32201. 'rcommaaccent': 333,
  32202. 'Ntilde': 722,
  32203. 'otilde': 556,
  32204. 'Rcommaaccent': 722,
  32205. 'Lcommaaccent': 556,
  32206. 'Atilde': 667,
  32207. 'Aogonek': 667,
  32208. 'Aring': 667,
  32209. 'Otilde': 778,
  32210. 'zdotaccent': 500,
  32211. 'Ecaron': 667,
  32212. 'Iogonek': 278,
  32213. 'kcommaaccent': 500,
  32214. 'minus': 584,
  32215. 'Icircumflex': 278,
  32216. 'ncaron': 556,
  32217. 'tcommaaccent': 278,
  32218. 'logicalnot': 584,
  32219. 'odieresis': 556,
  32220. 'udieresis': 556,
  32221. 'notequal': 549,
  32222. 'gcommaaccent': 556,
  32223. 'eth': 556,
  32224. 'zcaron': 500,
  32225. 'ncommaaccent': 556,
  32226. 'onesuperior': 333,
  32227. 'imacron': 278,
  32228. 'Euro': 556
  32229. },
  32230. 'Symbol': {
  32231. 'space': 250,
  32232. 'exclam': 333,
  32233. 'universal': 713,
  32234. 'numbersign': 500,
  32235. 'existential': 549,
  32236. 'percent': 833,
  32237. 'ampersand': 778,
  32238. 'suchthat': 439,
  32239. 'parenleft': 333,
  32240. 'parenright': 333,
  32241. 'asteriskmath': 500,
  32242. 'plus': 549,
  32243. 'comma': 250,
  32244. 'minus': 549,
  32245. 'period': 250,
  32246. 'slash': 278,
  32247. 'zero': 500,
  32248. 'one': 500,
  32249. 'two': 500,
  32250. 'three': 500,
  32251. 'four': 500,
  32252. 'five': 500,
  32253. 'six': 500,
  32254. 'seven': 500,
  32255. 'eight': 500,
  32256. 'nine': 500,
  32257. 'colon': 278,
  32258. 'semicolon': 278,
  32259. 'less': 549,
  32260. 'equal': 549,
  32261. 'greater': 549,
  32262. 'question': 444,
  32263. 'congruent': 549,
  32264. 'Alpha': 722,
  32265. 'Beta': 667,
  32266. 'Chi': 722,
  32267. 'Delta': 612,
  32268. 'Epsilon': 611,
  32269. 'Phi': 763,
  32270. 'Gamma': 603,
  32271. 'Eta': 722,
  32272. 'Iota': 333,
  32273. 'theta1': 631,
  32274. 'Kappa': 722,
  32275. 'Lambda': 686,
  32276. 'Mu': 889,
  32277. 'Nu': 722,
  32278. 'Omicron': 722,
  32279. 'Pi': 768,
  32280. 'Theta': 741,
  32281. 'Rho': 556,
  32282. 'Sigma': 592,
  32283. 'Tau': 611,
  32284. 'Upsilon': 690,
  32285. 'sigma1': 439,
  32286. 'Omega': 768,
  32287. 'Xi': 645,
  32288. 'Psi': 795,
  32289. 'Zeta': 611,
  32290. 'bracketleft': 333,
  32291. 'therefore': 863,
  32292. 'bracketright': 333,
  32293. 'perpendicular': 658,
  32294. 'underscore': 500,
  32295. 'radicalex': 500,
  32296. 'alpha': 631,
  32297. 'beta': 549,
  32298. 'chi': 549,
  32299. 'delta': 494,
  32300. 'epsilon': 439,
  32301. 'phi': 521,
  32302. 'gamma': 411,
  32303. 'eta': 603,
  32304. 'iota': 329,
  32305. 'phi1': 603,
  32306. 'kappa': 549,
  32307. 'lambda': 549,
  32308. 'mu': 576,
  32309. 'nu': 521,
  32310. 'omicron': 549,
  32311. 'pi': 549,
  32312. 'theta': 521,
  32313. 'rho': 549,
  32314. 'sigma': 603,
  32315. 'tau': 439,
  32316. 'upsilon': 576,
  32317. 'omega1': 713,
  32318. 'omega': 686,
  32319. 'xi': 493,
  32320. 'psi': 686,
  32321. 'zeta': 494,
  32322. 'braceleft': 480,
  32323. 'bar': 200,
  32324. 'braceright': 480,
  32325. 'similar': 549,
  32326. 'Euro': 750,
  32327. 'Upsilon1': 620,
  32328. 'minute': 247,
  32329. 'lessequal': 549,
  32330. 'fraction': 167,
  32331. 'infinity': 713,
  32332. 'florin': 500,
  32333. 'club': 753,
  32334. 'diamond': 753,
  32335. 'heart': 753,
  32336. 'spade': 753,
  32337. 'arrowboth': 1042,
  32338. 'arrowleft': 987,
  32339. 'arrowup': 603,
  32340. 'arrowright': 987,
  32341. 'arrowdown': 603,
  32342. 'degree': 400,
  32343. 'plusminus': 549,
  32344. 'second': 411,
  32345. 'greaterequal': 549,
  32346. 'multiply': 549,
  32347. 'proportional': 713,
  32348. 'partialdiff': 494,
  32349. 'bullet': 460,
  32350. 'divide': 549,
  32351. 'notequal': 549,
  32352. 'equivalence': 549,
  32353. 'approxequal': 549,
  32354. 'ellipsis': 1000,
  32355. 'arrowvertex': 603,
  32356. 'arrowhorizex': 1000,
  32357. 'carriagereturn': 658,
  32358. 'aleph': 823,
  32359. 'Ifraktur': 686,
  32360. 'Rfraktur': 795,
  32361. 'weierstrass': 987,
  32362. 'circlemultiply': 768,
  32363. 'circleplus': 768,
  32364. 'emptyset': 823,
  32365. 'intersection': 768,
  32366. 'union': 768,
  32367. 'propersuperset': 713,
  32368. 'reflexsuperset': 713,
  32369. 'notsubset': 713,
  32370. 'propersubset': 713,
  32371. 'reflexsubset': 713,
  32372. 'element': 713,
  32373. 'notelement': 713,
  32374. 'angle': 768,
  32375. 'gradient': 713,
  32376. 'registerserif': 790,
  32377. 'copyrightserif': 790,
  32378. 'trademarkserif': 890,
  32379. 'product': 823,
  32380. 'radical': 549,
  32381. 'dotmath': 250,
  32382. 'logicalnot': 713,
  32383. 'logicaland': 603,
  32384. 'logicalor': 603,
  32385. 'arrowdblboth': 1042,
  32386. 'arrowdblleft': 987,
  32387. 'arrowdblup': 603,
  32388. 'arrowdblright': 987,
  32389. 'arrowdbldown': 603,
  32390. 'lozenge': 494,
  32391. 'angleleft': 329,
  32392. 'registersans': 790,
  32393. 'copyrightsans': 790,
  32394. 'trademarksans': 786,
  32395. 'summation': 713,
  32396. 'parenlefttp': 384,
  32397. 'parenleftex': 384,
  32398. 'parenleftbt': 384,
  32399. 'bracketlefttp': 384,
  32400. 'bracketleftex': 384,
  32401. 'bracketleftbt': 384,
  32402. 'bracelefttp': 494,
  32403. 'braceleftmid': 494,
  32404. 'braceleftbt': 494,
  32405. 'braceex': 494,
  32406. 'angleright': 329,
  32407. 'integral': 274,
  32408. 'integraltp': 686,
  32409. 'integralex': 686,
  32410. 'integralbt': 686,
  32411. 'parenrighttp': 384,
  32412. 'parenrightex': 384,
  32413. 'parenrightbt': 384,
  32414. 'bracketrighttp': 384,
  32415. 'bracketrightex': 384,
  32416. 'bracketrightbt': 384,
  32417. 'bracerighttp': 494,
  32418. 'bracerightmid': 494,
  32419. 'bracerightbt': 494,
  32420. 'apple': 790
  32421. },
  32422. 'Times-Roman': {
  32423. 'space': 250,
  32424. 'exclam': 333,
  32425. 'quotedbl': 408,
  32426. 'numbersign': 500,
  32427. 'dollar': 500,
  32428. 'percent': 833,
  32429. 'ampersand': 778,
  32430. 'quoteright': 333,
  32431. 'parenleft': 333,
  32432. 'parenright': 333,
  32433. 'asterisk': 500,
  32434. 'plus': 564,
  32435. 'comma': 250,
  32436. 'hyphen': 333,
  32437. 'period': 250,
  32438. 'slash': 278,
  32439. 'zero': 500,
  32440. 'one': 500,
  32441. 'two': 500,
  32442. 'three': 500,
  32443. 'four': 500,
  32444. 'five': 500,
  32445. 'six': 500,
  32446. 'seven': 500,
  32447. 'eight': 500,
  32448. 'nine': 500,
  32449. 'colon': 278,
  32450. 'semicolon': 278,
  32451. 'less': 564,
  32452. 'equal': 564,
  32453. 'greater': 564,
  32454. 'question': 444,
  32455. 'at': 921,
  32456. 'A': 722,
  32457. 'B': 667,
  32458. 'C': 667,
  32459. 'D': 722,
  32460. 'E': 611,
  32461. 'F': 556,
  32462. 'G': 722,
  32463. 'H': 722,
  32464. 'I': 333,
  32465. 'J': 389,
  32466. 'K': 722,
  32467. 'L': 611,
  32468. 'M': 889,
  32469. 'N': 722,
  32470. 'O': 722,
  32471. 'P': 556,
  32472. 'Q': 722,
  32473. 'R': 667,
  32474. 'S': 556,
  32475. 'T': 611,
  32476. 'U': 722,
  32477. 'V': 722,
  32478. 'W': 944,
  32479. 'X': 722,
  32480. 'Y': 722,
  32481. 'Z': 611,
  32482. 'bracketleft': 333,
  32483. 'backslash': 278,
  32484. 'bracketright': 333,
  32485. 'asciicircum': 469,
  32486. 'underscore': 500,
  32487. 'quoteleft': 333,
  32488. 'a': 444,
  32489. 'b': 500,
  32490. 'c': 444,
  32491. 'd': 500,
  32492. 'e': 444,
  32493. 'f': 333,
  32494. 'g': 500,
  32495. 'h': 500,
  32496. 'i': 278,
  32497. 'j': 278,
  32498. 'k': 500,
  32499. 'l': 278,
  32500. 'm': 778,
  32501. 'n': 500,
  32502. 'o': 500,
  32503. 'p': 500,
  32504. 'q': 500,
  32505. 'r': 333,
  32506. 's': 389,
  32507. 't': 278,
  32508. 'u': 500,
  32509. 'v': 500,
  32510. 'w': 722,
  32511. 'x': 500,
  32512. 'y': 500,
  32513. 'z': 444,
  32514. 'braceleft': 480,
  32515. 'bar': 200,
  32516. 'braceright': 480,
  32517. 'asciitilde': 541,
  32518. 'exclamdown': 333,
  32519. 'cent': 500,
  32520. 'sterling': 500,
  32521. 'fraction': 167,
  32522. 'yen': 500,
  32523. 'florin': 500,
  32524. 'section': 500,
  32525. 'currency': 500,
  32526. 'quotesingle': 180,
  32527. 'quotedblleft': 444,
  32528. 'guillemotleft': 500,
  32529. 'guilsinglleft': 333,
  32530. 'guilsinglright': 333,
  32531. 'fi': 556,
  32532. 'fl': 556,
  32533. 'endash': 500,
  32534. 'dagger': 500,
  32535. 'daggerdbl': 500,
  32536. 'periodcentered': 250,
  32537. 'paragraph': 453,
  32538. 'bullet': 350,
  32539. 'quotesinglbase': 333,
  32540. 'quotedblbase': 444,
  32541. 'quotedblright': 444,
  32542. 'guillemotright': 500,
  32543. 'ellipsis': 1000,
  32544. 'perthousand': 1000,
  32545. 'questiondown': 444,
  32546. 'grave': 333,
  32547. 'acute': 333,
  32548. 'circumflex': 333,
  32549. 'tilde': 333,
  32550. 'macron': 333,
  32551. 'breve': 333,
  32552. 'dotaccent': 333,
  32553. 'dieresis': 333,
  32554. 'ring': 333,
  32555. 'cedilla': 333,
  32556. 'hungarumlaut': 333,
  32557. 'ogonek': 333,
  32558. 'caron': 333,
  32559. 'emdash': 1000,
  32560. 'AE': 889,
  32561. 'ordfeminine': 276,
  32562. 'Lslash': 611,
  32563. 'Oslash': 722,
  32564. 'OE': 889,
  32565. 'ordmasculine': 310,
  32566. 'ae': 667,
  32567. 'dotlessi': 278,
  32568. 'lslash': 278,
  32569. 'oslash': 500,
  32570. 'oe': 722,
  32571. 'germandbls': 500,
  32572. 'Idieresis': 333,
  32573. 'eacute': 444,
  32574. 'abreve': 444,
  32575. 'uhungarumlaut': 500,
  32576. 'ecaron': 444,
  32577. 'Ydieresis': 722,
  32578. 'divide': 564,
  32579. 'Yacute': 722,
  32580. 'Acircumflex': 722,
  32581. 'aacute': 444,
  32582. 'Ucircumflex': 722,
  32583. 'yacute': 500,
  32584. 'scommaaccent': 389,
  32585. 'ecircumflex': 444,
  32586. 'Uring': 722,
  32587. 'Udieresis': 722,
  32588. 'aogonek': 444,
  32589. 'Uacute': 722,
  32590. 'uogonek': 500,
  32591. 'Edieresis': 611,
  32592. 'Dcroat': 722,
  32593. 'commaaccent': 250,
  32594. 'copyright': 760,
  32595. 'Emacron': 611,
  32596. 'ccaron': 444,
  32597. 'aring': 444,
  32598. 'Ncommaaccent': 722,
  32599. 'lacute': 278,
  32600. 'agrave': 444,
  32601. 'Tcommaaccent': 611,
  32602. 'Cacute': 667,
  32603. 'atilde': 444,
  32604. 'Edotaccent': 611,
  32605. 'scaron': 389,
  32606. 'scedilla': 389,
  32607. 'iacute': 278,
  32608. 'lozenge': 471,
  32609. 'Rcaron': 667,
  32610. 'Gcommaaccent': 722,
  32611. 'ucircumflex': 500,
  32612. 'acircumflex': 444,
  32613. 'Amacron': 722,
  32614. 'rcaron': 333,
  32615. 'ccedilla': 444,
  32616. 'Zdotaccent': 611,
  32617. 'Thorn': 556,
  32618. 'Omacron': 722,
  32619. 'Racute': 667,
  32620. 'Sacute': 556,
  32621. 'dcaron': 588,
  32622. 'Umacron': 722,
  32623. 'uring': 500,
  32624. 'threesuperior': 300,
  32625. 'Ograve': 722,
  32626. 'Agrave': 722,
  32627. 'Abreve': 722,
  32628. 'multiply': 564,
  32629. 'uacute': 500,
  32630. 'Tcaron': 611,
  32631. 'partialdiff': 476,
  32632. 'ydieresis': 500,
  32633. 'Nacute': 722,
  32634. 'icircumflex': 278,
  32635. 'Ecircumflex': 611,
  32636. 'adieresis': 444,
  32637. 'edieresis': 444,
  32638. 'cacute': 444,
  32639. 'nacute': 500,
  32640. 'umacron': 500,
  32641. 'Ncaron': 722,
  32642. 'Iacute': 333,
  32643. 'plusminus': 564,
  32644. 'brokenbar': 200,
  32645. 'registered': 760,
  32646. 'Gbreve': 722,
  32647. 'Idotaccent': 333,
  32648. 'summation': 600,
  32649. 'Egrave': 611,
  32650. 'racute': 333,
  32651. 'omacron': 500,
  32652. 'Zacute': 611,
  32653. 'Zcaron': 611,
  32654. 'greaterequal': 549,
  32655. 'Eth': 722,
  32656. 'Ccedilla': 667,
  32657. 'lcommaaccent': 278,
  32658. 'tcaron': 326,
  32659. 'eogonek': 444,
  32660. 'Uogonek': 722,
  32661. 'Aacute': 722,
  32662. 'Adieresis': 722,
  32663. 'egrave': 444,
  32664. 'zacute': 444,
  32665. 'iogonek': 278,
  32666. 'Oacute': 722,
  32667. 'oacute': 500,
  32668. 'amacron': 444,
  32669. 'sacute': 389,
  32670. 'idieresis': 278,
  32671. 'Ocircumflex': 722,
  32672. 'Ugrave': 722,
  32673. 'Delta': 612,
  32674. 'thorn': 500,
  32675. 'twosuperior': 300,
  32676. 'Odieresis': 722,
  32677. 'mu': 500,
  32678. 'igrave': 278,
  32679. 'ohungarumlaut': 500,
  32680. 'Eogonek': 611,
  32681. 'dcroat': 500,
  32682. 'threequarters': 750,
  32683. 'Scedilla': 556,
  32684. 'lcaron': 344,
  32685. 'Kcommaaccent': 722,
  32686. 'Lacute': 611,
  32687. 'trademark': 980,
  32688. 'edotaccent': 444,
  32689. 'Igrave': 333,
  32690. 'Imacron': 333,
  32691. 'Lcaron': 611,
  32692. 'onehalf': 750,
  32693. 'lessequal': 549,
  32694. 'ocircumflex': 500,
  32695. 'ntilde': 500,
  32696. 'Uhungarumlaut': 722,
  32697. 'Eacute': 611,
  32698. 'emacron': 444,
  32699. 'gbreve': 500,
  32700. 'onequarter': 750,
  32701. 'Scaron': 556,
  32702. 'Scommaaccent': 556,
  32703. 'Ohungarumlaut': 722,
  32704. 'degree': 400,
  32705. 'ograve': 500,
  32706. 'Ccaron': 667,
  32707. 'ugrave': 500,
  32708. 'radical': 453,
  32709. 'Dcaron': 722,
  32710. 'rcommaaccent': 333,
  32711. 'Ntilde': 722,
  32712. 'otilde': 500,
  32713. 'Rcommaaccent': 667,
  32714. 'Lcommaaccent': 611,
  32715. 'Atilde': 722,
  32716. 'Aogonek': 722,
  32717. 'Aring': 722,
  32718. 'Otilde': 722,
  32719. 'zdotaccent': 444,
  32720. 'Ecaron': 611,
  32721. 'Iogonek': 333,
  32722. 'kcommaaccent': 500,
  32723. 'minus': 564,
  32724. 'Icircumflex': 333,
  32725. 'ncaron': 500,
  32726. 'tcommaaccent': 278,
  32727. 'logicalnot': 564,
  32728. 'odieresis': 500,
  32729. 'udieresis': 500,
  32730. 'notequal': 549,
  32731. 'gcommaaccent': 500,
  32732. 'eth': 500,
  32733. 'zcaron': 444,
  32734. 'ncommaaccent': 500,
  32735. 'onesuperior': 300,
  32736. 'imacron': 278,
  32737. 'Euro': 500
  32738. },
  32739. 'Times-Bold': {
  32740. 'space': 250,
  32741. 'exclam': 333,
  32742. 'quotedbl': 555,
  32743. 'numbersign': 500,
  32744. 'dollar': 500,
  32745. 'percent': 1000,
  32746. 'ampersand': 833,
  32747. 'quoteright': 333,
  32748. 'parenleft': 333,
  32749. 'parenright': 333,
  32750. 'asterisk': 500,
  32751. 'plus': 570,
  32752. 'comma': 250,
  32753. 'hyphen': 333,
  32754. 'period': 250,
  32755. 'slash': 278,
  32756. 'zero': 500,
  32757. 'one': 500,
  32758. 'two': 500,
  32759. 'three': 500,
  32760. 'four': 500,
  32761. 'five': 500,
  32762. 'six': 500,
  32763. 'seven': 500,
  32764. 'eight': 500,
  32765. 'nine': 500,
  32766. 'colon': 333,
  32767. 'semicolon': 333,
  32768. 'less': 570,
  32769. 'equal': 570,
  32770. 'greater': 570,
  32771. 'question': 500,
  32772. 'at': 930,
  32773. 'A': 722,
  32774. 'B': 667,
  32775. 'C': 722,
  32776. 'D': 722,
  32777. 'E': 667,
  32778. 'F': 611,
  32779. 'G': 778,
  32780. 'H': 778,
  32781. 'I': 389,
  32782. 'J': 500,
  32783. 'K': 778,
  32784. 'L': 667,
  32785. 'M': 944,
  32786. 'N': 722,
  32787. 'O': 778,
  32788. 'P': 611,
  32789. 'Q': 778,
  32790. 'R': 722,
  32791. 'S': 556,
  32792. 'T': 667,
  32793. 'U': 722,
  32794. 'V': 722,
  32795. 'W': 1000,
  32796. 'X': 722,
  32797. 'Y': 722,
  32798. 'Z': 667,
  32799. 'bracketleft': 333,
  32800. 'backslash': 278,
  32801. 'bracketright': 333,
  32802. 'asciicircum': 581,
  32803. 'underscore': 500,
  32804. 'quoteleft': 333,
  32805. 'a': 500,
  32806. 'b': 556,
  32807. 'c': 444,
  32808. 'd': 556,
  32809. 'e': 444,
  32810. 'f': 333,
  32811. 'g': 500,
  32812. 'h': 556,
  32813. 'i': 278,
  32814. 'j': 333,
  32815. 'k': 556,
  32816. 'l': 278,
  32817. 'm': 833,
  32818. 'n': 556,
  32819. 'o': 500,
  32820. 'p': 556,
  32821. 'q': 556,
  32822. 'r': 444,
  32823. 's': 389,
  32824. 't': 333,
  32825. 'u': 556,
  32826. 'v': 500,
  32827. 'w': 722,
  32828. 'x': 500,
  32829. 'y': 500,
  32830. 'z': 444,
  32831. 'braceleft': 394,
  32832. 'bar': 220,
  32833. 'braceright': 394,
  32834. 'asciitilde': 520,
  32835. 'exclamdown': 333,
  32836. 'cent': 500,
  32837. 'sterling': 500,
  32838. 'fraction': 167,
  32839. 'yen': 500,
  32840. 'florin': 500,
  32841. 'section': 500,
  32842. 'currency': 500,
  32843. 'quotesingle': 278,
  32844. 'quotedblleft': 500,
  32845. 'guillemotleft': 500,
  32846. 'guilsinglleft': 333,
  32847. 'guilsinglright': 333,
  32848. 'fi': 556,
  32849. 'fl': 556,
  32850. 'endash': 500,
  32851. 'dagger': 500,
  32852. 'daggerdbl': 500,
  32853. 'periodcentered': 250,
  32854. 'paragraph': 540,
  32855. 'bullet': 350,
  32856. 'quotesinglbase': 333,
  32857. 'quotedblbase': 500,
  32858. 'quotedblright': 500,
  32859. 'guillemotright': 500,
  32860. 'ellipsis': 1000,
  32861. 'perthousand': 1000,
  32862. 'questiondown': 500,
  32863. 'grave': 333,
  32864. 'acute': 333,
  32865. 'circumflex': 333,
  32866. 'tilde': 333,
  32867. 'macron': 333,
  32868. 'breve': 333,
  32869. 'dotaccent': 333,
  32870. 'dieresis': 333,
  32871. 'ring': 333,
  32872. 'cedilla': 333,
  32873. 'hungarumlaut': 333,
  32874. 'ogonek': 333,
  32875. 'caron': 333,
  32876. 'emdash': 1000,
  32877. 'AE': 1000,
  32878. 'ordfeminine': 300,
  32879. 'Lslash': 667,
  32880. 'Oslash': 778,
  32881. 'OE': 1000,
  32882. 'ordmasculine': 330,
  32883. 'ae': 722,
  32884. 'dotlessi': 278,
  32885. 'lslash': 278,
  32886. 'oslash': 500,
  32887. 'oe': 722,
  32888. 'germandbls': 556,
  32889. 'Idieresis': 389,
  32890. 'eacute': 444,
  32891. 'abreve': 500,
  32892. 'uhungarumlaut': 556,
  32893. 'ecaron': 444,
  32894. 'Ydieresis': 722,
  32895. 'divide': 570,
  32896. 'Yacute': 722,
  32897. 'Acircumflex': 722,
  32898. 'aacute': 500,
  32899. 'Ucircumflex': 722,
  32900. 'yacute': 500,
  32901. 'scommaaccent': 389,
  32902. 'ecircumflex': 444,
  32903. 'Uring': 722,
  32904. 'Udieresis': 722,
  32905. 'aogonek': 500,
  32906. 'Uacute': 722,
  32907. 'uogonek': 556,
  32908. 'Edieresis': 667,
  32909. 'Dcroat': 722,
  32910. 'commaaccent': 250,
  32911. 'copyright': 747,
  32912. 'Emacron': 667,
  32913. 'ccaron': 444,
  32914. 'aring': 500,
  32915. 'Ncommaaccent': 722,
  32916. 'lacute': 278,
  32917. 'agrave': 500,
  32918. 'Tcommaaccent': 667,
  32919. 'Cacute': 722,
  32920. 'atilde': 500,
  32921. 'Edotaccent': 667,
  32922. 'scaron': 389,
  32923. 'scedilla': 389,
  32924. 'iacute': 278,
  32925. 'lozenge': 494,
  32926. 'Rcaron': 722,
  32927. 'Gcommaaccent': 778,
  32928. 'ucircumflex': 556,
  32929. 'acircumflex': 500,
  32930. 'Amacron': 722,
  32931. 'rcaron': 444,
  32932. 'ccedilla': 444,
  32933. 'Zdotaccent': 667,
  32934. 'Thorn': 611,
  32935. 'Omacron': 778,
  32936. 'Racute': 722,
  32937. 'Sacute': 556,
  32938. 'dcaron': 672,
  32939. 'Umacron': 722,
  32940. 'uring': 556,
  32941. 'threesuperior': 300,
  32942. 'Ograve': 778,
  32943. 'Agrave': 722,
  32944. 'Abreve': 722,
  32945. 'multiply': 570,
  32946. 'uacute': 556,
  32947. 'Tcaron': 667,
  32948. 'partialdiff': 494,
  32949. 'ydieresis': 500,
  32950. 'Nacute': 722,
  32951. 'icircumflex': 278,
  32952. 'Ecircumflex': 667,
  32953. 'adieresis': 500,
  32954. 'edieresis': 444,
  32955. 'cacute': 444,
  32956. 'nacute': 556,
  32957. 'umacron': 556,
  32958. 'Ncaron': 722,
  32959. 'Iacute': 389,
  32960. 'plusminus': 570,
  32961. 'brokenbar': 220,
  32962. 'registered': 747,
  32963. 'Gbreve': 778,
  32964. 'Idotaccent': 389,
  32965. 'summation': 600,
  32966. 'Egrave': 667,
  32967. 'racute': 444,
  32968. 'omacron': 500,
  32969. 'Zacute': 667,
  32970. 'Zcaron': 667,
  32971. 'greaterequal': 549,
  32972. 'Eth': 722,
  32973. 'Ccedilla': 722,
  32974. 'lcommaaccent': 278,
  32975. 'tcaron': 416,
  32976. 'eogonek': 444,
  32977. 'Uogonek': 722,
  32978. 'Aacute': 722,
  32979. 'Adieresis': 722,
  32980. 'egrave': 444,
  32981. 'zacute': 444,
  32982. 'iogonek': 278,
  32983. 'Oacute': 778,
  32984. 'oacute': 500,
  32985. 'amacron': 500,
  32986. 'sacute': 389,
  32987. 'idieresis': 278,
  32988. 'Ocircumflex': 778,
  32989. 'Ugrave': 722,
  32990. 'Delta': 612,
  32991. 'thorn': 556,
  32992. 'twosuperior': 300,
  32993. 'Odieresis': 778,
  32994. 'mu': 556,
  32995. 'igrave': 278,
  32996. 'ohungarumlaut': 500,
  32997. 'Eogonek': 667,
  32998. 'dcroat': 556,
  32999. 'threequarters': 750,
  33000. 'Scedilla': 556,
  33001. 'lcaron': 394,
  33002. 'Kcommaaccent': 778,
  33003. 'Lacute': 667,
  33004. 'trademark': 1000,
  33005. 'edotaccent': 444,
  33006. 'Igrave': 389,
  33007. 'Imacron': 389,
  33008. 'Lcaron': 667,
  33009. 'onehalf': 750,
  33010. 'lessequal': 549,
  33011. 'ocircumflex': 500,
  33012. 'ntilde': 556,
  33013. 'Uhungarumlaut': 722,
  33014. 'Eacute': 667,
  33015. 'emacron': 444,
  33016. 'gbreve': 500,
  33017. 'onequarter': 750,
  33018. 'Scaron': 556,
  33019. 'Scommaaccent': 556,
  33020. 'Ohungarumlaut': 778,
  33021. 'degree': 400,
  33022. 'ograve': 500,
  33023. 'Ccaron': 722,
  33024. 'ugrave': 556,
  33025. 'radical': 549,
  33026. 'Dcaron': 722,
  33027. 'rcommaaccent': 444,
  33028. 'Ntilde': 722,
  33029. 'otilde': 500,
  33030. 'Rcommaaccent': 722,
  33031. 'Lcommaaccent': 667,
  33032. 'Atilde': 722,
  33033. 'Aogonek': 722,
  33034. 'Aring': 722,
  33035. 'Otilde': 778,
  33036. 'zdotaccent': 444,
  33037. 'Ecaron': 667,
  33038. 'Iogonek': 389,
  33039. 'kcommaaccent': 556,
  33040. 'minus': 570,
  33041. 'Icircumflex': 389,
  33042. 'ncaron': 556,
  33043. 'tcommaaccent': 333,
  33044. 'logicalnot': 570,
  33045. 'odieresis': 500,
  33046. 'udieresis': 556,
  33047. 'notequal': 549,
  33048. 'gcommaaccent': 500,
  33049. 'eth': 500,
  33050. 'zcaron': 444,
  33051. 'ncommaaccent': 556,
  33052. 'onesuperior': 300,
  33053. 'imacron': 278,
  33054. 'Euro': 500
  33055. },
  33056. 'Times-BoldItalic': {
  33057. 'space': 250,
  33058. 'exclam': 389,
  33059. 'quotedbl': 555,
  33060. 'numbersign': 500,
  33061. 'dollar': 500,
  33062. 'percent': 833,
  33063. 'ampersand': 778,
  33064. 'quoteright': 333,
  33065. 'parenleft': 333,
  33066. 'parenright': 333,
  33067. 'asterisk': 500,
  33068. 'plus': 570,
  33069. 'comma': 250,
  33070. 'hyphen': 333,
  33071. 'period': 250,
  33072. 'slash': 278,
  33073. 'zero': 500,
  33074. 'one': 500,
  33075. 'two': 500,
  33076. 'three': 500,
  33077. 'four': 500,
  33078. 'five': 500,
  33079. 'six': 500,
  33080. 'seven': 500,
  33081. 'eight': 500,
  33082. 'nine': 500,
  33083. 'colon': 333,
  33084. 'semicolon': 333,
  33085. 'less': 570,
  33086. 'equal': 570,
  33087. 'greater': 570,
  33088. 'question': 500,
  33089. 'at': 832,
  33090. 'A': 667,
  33091. 'B': 667,
  33092. 'C': 667,
  33093. 'D': 722,
  33094. 'E': 667,
  33095. 'F': 667,
  33096. 'G': 722,
  33097. 'H': 778,
  33098. 'I': 389,
  33099. 'J': 500,
  33100. 'K': 667,
  33101. 'L': 611,
  33102. 'M': 889,
  33103. 'N': 722,
  33104. 'O': 722,
  33105. 'P': 611,
  33106. 'Q': 722,
  33107. 'R': 667,
  33108. 'S': 556,
  33109. 'T': 611,
  33110. 'U': 722,
  33111. 'V': 667,
  33112. 'W': 889,
  33113. 'X': 667,
  33114. 'Y': 611,
  33115. 'Z': 611,
  33116. 'bracketleft': 333,
  33117. 'backslash': 278,
  33118. 'bracketright': 333,
  33119. 'asciicircum': 570,
  33120. 'underscore': 500,
  33121. 'quoteleft': 333,
  33122. 'a': 500,
  33123. 'b': 500,
  33124. 'c': 444,
  33125. 'd': 500,
  33126. 'e': 444,
  33127. 'f': 333,
  33128. 'g': 500,
  33129. 'h': 556,
  33130. 'i': 278,
  33131. 'j': 278,
  33132. 'k': 500,
  33133. 'l': 278,
  33134. 'm': 778,
  33135. 'n': 556,
  33136. 'o': 500,
  33137. 'p': 500,
  33138. 'q': 500,
  33139. 'r': 389,
  33140. 's': 389,
  33141. 't': 278,
  33142. 'u': 556,
  33143. 'v': 444,
  33144. 'w': 667,
  33145. 'x': 500,
  33146. 'y': 444,
  33147. 'z': 389,
  33148. 'braceleft': 348,
  33149. 'bar': 220,
  33150. 'braceright': 348,
  33151. 'asciitilde': 570,
  33152. 'exclamdown': 389,
  33153. 'cent': 500,
  33154. 'sterling': 500,
  33155. 'fraction': 167,
  33156. 'yen': 500,
  33157. 'florin': 500,
  33158. 'section': 500,
  33159. 'currency': 500,
  33160. 'quotesingle': 278,
  33161. 'quotedblleft': 500,
  33162. 'guillemotleft': 500,
  33163. 'guilsinglleft': 333,
  33164. 'guilsinglright': 333,
  33165. 'fi': 556,
  33166. 'fl': 556,
  33167. 'endash': 500,
  33168. 'dagger': 500,
  33169. 'daggerdbl': 500,
  33170. 'periodcentered': 250,
  33171. 'paragraph': 500,
  33172. 'bullet': 350,
  33173. 'quotesinglbase': 333,
  33174. 'quotedblbase': 500,
  33175. 'quotedblright': 500,
  33176. 'guillemotright': 500,
  33177. 'ellipsis': 1000,
  33178. 'perthousand': 1000,
  33179. 'questiondown': 500,
  33180. 'grave': 333,
  33181. 'acute': 333,
  33182. 'circumflex': 333,
  33183. 'tilde': 333,
  33184. 'macron': 333,
  33185. 'breve': 333,
  33186. 'dotaccent': 333,
  33187. 'dieresis': 333,
  33188. 'ring': 333,
  33189. 'cedilla': 333,
  33190. 'hungarumlaut': 333,
  33191. 'ogonek': 333,
  33192. 'caron': 333,
  33193. 'emdash': 1000,
  33194. 'AE': 944,
  33195. 'ordfeminine': 266,
  33196. 'Lslash': 611,
  33197. 'Oslash': 722,
  33198. 'OE': 944,
  33199. 'ordmasculine': 300,
  33200. 'ae': 722,
  33201. 'dotlessi': 278,
  33202. 'lslash': 278,
  33203. 'oslash': 500,
  33204. 'oe': 722,
  33205. 'germandbls': 500,
  33206. 'Idieresis': 389,
  33207. 'eacute': 444,
  33208. 'abreve': 500,
  33209. 'uhungarumlaut': 556,
  33210. 'ecaron': 444,
  33211. 'Ydieresis': 611,
  33212. 'divide': 570,
  33213. 'Yacute': 611,
  33214. 'Acircumflex': 667,
  33215. 'aacute': 500,
  33216. 'Ucircumflex': 722,
  33217. 'yacute': 444,
  33218. 'scommaaccent': 389,
  33219. 'ecircumflex': 444,
  33220. 'Uring': 722,
  33221. 'Udieresis': 722,
  33222. 'aogonek': 500,
  33223. 'Uacute': 722,
  33224. 'uogonek': 556,
  33225. 'Edieresis': 667,
  33226. 'Dcroat': 722,
  33227. 'commaaccent': 250,
  33228. 'copyright': 747,
  33229. 'Emacron': 667,
  33230. 'ccaron': 444,
  33231. 'aring': 500,
  33232. 'Ncommaaccent': 722,
  33233. 'lacute': 278,
  33234. 'agrave': 500,
  33235. 'Tcommaaccent': 611,
  33236. 'Cacute': 667,
  33237. 'atilde': 500,
  33238. 'Edotaccent': 667,
  33239. 'scaron': 389,
  33240. 'scedilla': 389,
  33241. 'iacute': 278,
  33242. 'lozenge': 494,
  33243. 'Rcaron': 667,
  33244. 'Gcommaaccent': 722,
  33245. 'ucircumflex': 556,
  33246. 'acircumflex': 500,
  33247. 'Amacron': 667,
  33248. 'rcaron': 389,
  33249. 'ccedilla': 444,
  33250. 'Zdotaccent': 611,
  33251. 'Thorn': 611,
  33252. 'Omacron': 722,
  33253. 'Racute': 667,
  33254. 'Sacute': 556,
  33255. 'dcaron': 608,
  33256. 'Umacron': 722,
  33257. 'uring': 556,
  33258. 'threesuperior': 300,
  33259. 'Ograve': 722,
  33260. 'Agrave': 667,
  33261. 'Abreve': 667,
  33262. 'multiply': 570,
  33263. 'uacute': 556,
  33264. 'Tcaron': 611,
  33265. 'partialdiff': 494,
  33266. 'ydieresis': 444,
  33267. 'Nacute': 722,
  33268. 'icircumflex': 278,
  33269. 'Ecircumflex': 667,
  33270. 'adieresis': 500,
  33271. 'edieresis': 444,
  33272. 'cacute': 444,
  33273. 'nacute': 556,
  33274. 'umacron': 556,
  33275. 'Ncaron': 722,
  33276. 'Iacute': 389,
  33277. 'plusminus': 570,
  33278. 'brokenbar': 220,
  33279. 'registered': 747,
  33280. 'Gbreve': 722,
  33281. 'Idotaccent': 389,
  33282. 'summation': 600,
  33283. 'Egrave': 667,
  33284. 'racute': 389,
  33285. 'omacron': 500,
  33286. 'Zacute': 611,
  33287. 'Zcaron': 611,
  33288. 'greaterequal': 549,
  33289. 'Eth': 722,
  33290. 'Ccedilla': 667,
  33291. 'lcommaaccent': 278,
  33292. 'tcaron': 366,
  33293. 'eogonek': 444,
  33294. 'Uogonek': 722,
  33295. 'Aacute': 667,
  33296. 'Adieresis': 667,
  33297. 'egrave': 444,
  33298. 'zacute': 389,
  33299. 'iogonek': 278,
  33300. 'Oacute': 722,
  33301. 'oacute': 500,
  33302. 'amacron': 500,
  33303. 'sacute': 389,
  33304. 'idieresis': 278,
  33305. 'Ocircumflex': 722,
  33306. 'Ugrave': 722,
  33307. 'Delta': 612,
  33308. 'thorn': 500,
  33309. 'twosuperior': 300,
  33310. 'Odieresis': 722,
  33311. 'mu': 576,
  33312. 'igrave': 278,
  33313. 'ohungarumlaut': 500,
  33314. 'Eogonek': 667,
  33315. 'dcroat': 500,
  33316. 'threequarters': 750,
  33317. 'Scedilla': 556,
  33318. 'lcaron': 382,
  33319. 'Kcommaaccent': 667,
  33320. 'Lacute': 611,
  33321. 'trademark': 1000,
  33322. 'edotaccent': 444,
  33323. 'Igrave': 389,
  33324. 'Imacron': 389,
  33325. 'Lcaron': 611,
  33326. 'onehalf': 750,
  33327. 'lessequal': 549,
  33328. 'ocircumflex': 500,
  33329. 'ntilde': 556,
  33330. 'Uhungarumlaut': 722,
  33331. 'Eacute': 667,
  33332. 'emacron': 444,
  33333. 'gbreve': 500,
  33334. 'onequarter': 750,
  33335. 'Scaron': 556,
  33336. 'Scommaaccent': 556,
  33337. 'Ohungarumlaut': 722,
  33338. 'degree': 400,
  33339. 'ograve': 500,
  33340. 'Ccaron': 667,
  33341. 'ugrave': 556,
  33342. 'radical': 549,
  33343. 'Dcaron': 722,
  33344. 'rcommaaccent': 389,
  33345. 'Ntilde': 722,
  33346. 'otilde': 500,
  33347. 'Rcommaaccent': 667,
  33348. 'Lcommaaccent': 611,
  33349. 'Atilde': 667,
  33350. 'Aogonek': 667,
  33351. 'Aring': 667,
  33352. 'Otilde': 722,
  33353. 'zdotaccent': 389,
  33354. 'Ecaron': 667,
  33355. 'Iogonek': 389,
  33356. 'kcommaaccent': 500,
  33357. 'minus': 606,
  33358. 'Icircumflex': 389,
  33359. 'ncaron': 556,
  33360. 'tcommaaccent': 278,
  33361. 'logicalnot': 606,
  33362. 'odieresis': 500,
  33363. 'udieresis': 556,
  33364. 'notequal': 549,
  33365. 'gcommaaccent': 500,
  33366. 'eth': 500,
  33367. 'zcaron': 389,
  33368. 'ncommaaccent': 556,
  33369. 'onesuperior': 300,
  33370. 'imacron': 278,
  33371. 'Euro': 500
  33372. },
  33373. 'Times-Italic': {
  33374. 'space': 250,
  33375. 'exclam': 333,
  33376. 'quotedbl': 420,
  33377. 'numbersign': 500,
  33378. 'dollar': 500,
  33379. 'percent': 833,
  33380. 'ampersand': 778,
  33381. 'quoteright': 333,
  33382. 'parenleft': 333,
  33383. 'parenright': 333,
  33384. 'asterisk': 500,
  33385. 'plus': 675,
  33386. 'comma': 250,
  33387. 'hyphen': 333,
  33388. 'period': 250,
  33389. 'slash': 278,
  33390. 'zero': 500,
  33391. 'one': 500,
  33392. 'two': 500,
  33393. 'three': 500,
  33394. 'four': 500,
  33395. 'five': 500,
  33396. 'six': 500,
  33397. 'seven': 500,
  33398. 'eight': 500,
  33399. 'nine': 500,
  33400. 'colon': 333,
  33401. 'semicolon': 333,
  33402. 'less': 675,
  33403. 'equal': 675,
  33404. 'greater': 675,
  33405. 'question': 500,
  33406. 'at': 920,
  33407. 'A': 611,
  33408. 'B': 611,
  33409. 'C': 667,
  33410. 'D': 722,
  33411. 'E': 611,
  33412. 'F': 611,
  33413. 'G': 722,
  33414. 'H': 722,
  33415. 'I': 333,
  33416. 'J': 444,
  33417. 'K': 667,
  33418. 'L': 556,
  33419. 'M': 833,
  33420. 'N': 667,
  33421. 'O': 722,
  33422. 'P': 611,
  33423. 'Q': 722,
  33424. 'R': 611,
  33425. 'S': 500,
  33426. 'T': 556,
  33427. 'U': 722,
  33428. 'V': 611,
  33429. 'W': 833,
  33430. 'X': 611,
  33431. 'Y': 556,
  33432. 'Z': 556,
  33433. 'bracketleft': 389,
  33434. 'backslash': 278,
  33435. 'bracketright': 389,
  33436. 'asciicircum': 422,
  33437. 'underscore': 500,
  33438. 'quoteleft': 333,
  33439. 'a': 500,
  33440. 'b': 500,
  33441. 'c': 444,
  33442. 'd': 500,
  33443. 'e': 444,
  33444. 'f': 278,
  33445. 'g': 500,
  33446. 'h': 500,
  33447. 'i': 278,
  33448. 'j': 278,
  33449. 'k': 444,
  33450. 'l': 278,
  33451. 'm': 722,
  33452. 'n': 500,
  33453. 'o': 500,
  33454. 'p': 500,
  33455. 'q': 500,
  33456. 'r': 389,
  33457. 's': 389,
  33458. 't': 278,
  33459. 'u': 500,
  33460. 'v': 444,
  33461. 'w': 667,
  33462. 'x': 444,
  33463. 'y': 444,
  33464. 'z': 389,
  33465. 'braceleft': 400,
  33466. 'bar': 275,
  33467. 'braceright': 400,
  33468. 'asciitilde': 541,
  33469. 'exclamdown': 389,
  33470. 'cent': 500,
  33471. 'sterling': 500,
  33472. 'fraction': 167,
  33473. 'yen': 500,
  33474. 'florin': 500,
  33475. 'section': 500,
  33476. 'currency': 500,
  33477. 'quotesingle': 214,
  33478. 'quotedblleft': 556,
  33479. 'guillemotleft': 500,
  33480. 'guilsinglleft': 333,
  33481. 'guilsinglright': 333,
  33482. 'fi': 500,
  33483. 'fl': 500,
  33484. 'endash': 500,
  33485. 'dagger': 500,
  33486. 'daggerdbl': 500,
  33487. 'periodcentered': 250,
  33488. 'paragraph': 523,
  33489. 'bullet': 350,
  33490. 'quotesinglbase': 333,
  33491. 'quotedblbase': 556,
  33492. 'quotedblright': 556,
  33493. 'guillemotright': 500,
  33494. 'ellipsis': 889,
  33495. 'perthousand': 1000,
  33496. 'questiondown': 500,
  33497. 'grave': 333,
  33498. 'acute': 333,
  33499. 'circumflex': 333,
  33500. 'tilde': 333,
  33501. 'macron': 333,
  33502. 'breve': 333,
  33503. 'dotaccent': 333,
  33504. 'dieresis': 333,
  33505. 'ring': 333,
  33506. 'cedilla': 333,
  33507. 'hungarumlaut': 333,
  33508. 'ogonek': 333,
  33509. 'caron': 333,
  33510. 'emdash': 889,
  33511. 'AE': 889,
  33512. 'ordfeminine': 276,
  33513. 'Lslash': 556,
  33514. 'Oslash': 722,
  33515. 'OE': 944,
  33516. 'ordmasculine': 310,
  33517. 'ae': 667,
  33518. 'dotlessi': 278,
  33519. 'lslash': 278,
  33520. 'oslash': 500,
  33521. 'oe': 667,
  33522. 'germandbls': 500,
  33523. 'Idieresis': 333,
  33524. 'eacute': 444,
  33525. 'abreve': 500,
  33526. 'uhungarumlaut': 500,
  33527. 'ecaron': 444,
  33528. 'Ydieresis': 556,
  33529. 'divide': 675,
  33530. 'Yacute': 556,
  33531. 'Acircumflex': 611,
  33532. 'aacute': 500,
  33533. 'Ucircumflex': 722,
  33534. 'yacute': 444,
  33535. 'scommaaccent': 389,
  33536. 'ecircumflex': 444,
  33537. 'Uring': 722,
  33538. 'Udieresis': 722,
  33539. 'aogonek': 500,
  33540. 'Uacute': 722,
  33541. 'uogonek': 500,
  33542. 'Edieresis': 611,
  33543. 'Dcroat': 722,
  33544. 'commaaccent': 250,
  33545. 'copyright': 760,
  33546. 'Emacron': 611,
  33547. 'ccaron': 444,
  33548. 'aring': 500,
  33549. 'Ncommaaccent': 667,
  33550. 'lacute': 278,
  33551. 'agrave': 500,
  33552. 'Tcommaaccent': 556,
  33553. 'Cacute': 667,
  33554. 'atilde': 500,
  33555. 'Edotaccent': 611,
  33556. 'scaron': 389,
  33557. 'scedilla': 389,
  33558. 'iacute': 278,
  33559. 'lozenge': 471,
  33560. 'Rcaron': 611,
  33561. 'Gcommaaccent': 722,
  33562. 'ucircumflex': 500,
  33563. 'acircumflex': 500,
  33564. 'Amacron': 611,
  33565. 'rcaron': 389,
  33566. 'ccedilla': 444,
  33567. 'Zdotaccent': 556,
  33568. 'Thorn': 611,
  33569. 'Omacron': 722,
  33570. 'Racute': 611,
  33571. 'Sacute': 500,
  33572. 'dcaron': 544,
  33573. 'Umacron': 722,
  33574. 'uring': 500,
  33575. 'threesuperior': 300,
  33576. 'Ograve': 722,
  33577. 'Agrave': 611,
  33578. 'Abreve': 611,
  33579. 'multiply': 675,
  33580. 'uacute': 500,
  33581. 'Tcaron': 556,
  33582. 'partialdiff': 476,
  33583. 'ydieresis': 444,
  33584. 'Nacute': 667,
  33585. 'icircumflex': 278,
  33586. 'Ecircumflex': 611,
  33587. 'adieresis': 500,
  33588. 'edieresis': 444,
  33589. 'cacute': 444,
  33590. 'nacute': 500,
  33591. 'umacron': 500,
  33592. 'Ncaron': 667,
  33593. 'Iacute': 333,
  33594. 'plusminus': 675,
  33595. 'brokenbar': 275,
  33596. 'registered': 760,
  33597. 'Gbreve': 722,
  33598. 'Idotaccent': 333,
  33599. 'summation': 600,
  33600. 'Egrave': 611,
  33601. 'racute': 389,
  33602. 'omacron': 500,
  33603. 'Zacute': 556,
  33604. 'Zcaron': 556,
  33605. 'greaterequal': 549,
  33606. 'Eth': 722,
  33607. 'Ccedilla': 667,
  33608. 'lcommaaccent': 278,
  33609. 'tcaron': 300,
  33610. 'eogonek': 444,
  33611. 'Uogonek': 722,
  33612. 'Aacute': 611,
  33613. 'Adieresis': 611,
  33614. 'egrave': 444,
  33615. 'zacute': 389,
  33616. 'iogonek': 278,
  33617. 'Oacute': 722,
  33618. 'oacute': 500,
  33619. 'amacron': 500,
  33620. 'sacute': 389,
  33621. 'idieresis': 278,
  33622. 'Ocircumflex': 722,
  33623. 'Ugrave': 722,
  33624. 'Delta': 612,
  33625. 'thorn': 500,
  33626. 'twosuperior': 300,
  33627. 'Odieresis': 722,
  33628. 'mu': 500,
  33629. 'igrave': 278,
  33630. 'ohungarumlaut': 500,
  33631. 'Eogonek': 611,
  33632. 'dcroat': 500,
  33633. 'threequarters': 750,
  33634. 'Scedilla': 500,
  33635. 'lcaron': 300,
  33636. 'Kcommaaccent': 667,
  33637. 'Lacute': 556,
  33638. 'trademark': 980,
  33639. 'edotaccent': 444,
  33640. 'Igrave': 333,
  33641. 'Imacron': 333,
  33642. 'Lcaron': 611,
  33643. 'onehalf': 750,
  33644. 'lessequal': 549,
  33645. 'ocircumflex': 500,
  33646. 'ntilde': 500,
  33647. 'Uhungarumlaut': 722,
  33648. 'Eacute': 611,
  33649. 'emacron': 444,
  33650. 'gbreve': 500,
  33651. 'onequarter': 750,
  33652. 'Scaron': 500,
  33653. 'Scommaaccent': 500,
  33654. 'Ohungarumlaut': 722,
  33655. 'degree': 400,
  33656. 'ograve': 500,
  33657. 'Ccaron': 667,
  33658. 'ugrave': 500,
  33659. 'radical': 453,
  33660. 'Dcaron': 722,
  33661. 'rcommaaccent': 389,
  33662. 'Ntilde': 667,
  33663. 'otilde': 500,
  33664. 'Rcommaaccent': 611,
  33665. 'Lcommaaccent': 556,
  33666. 'Atilde': 611,
  33667. 'Aogonek': 611,
  33668. 'Aring': 611,
  33669. 'Otilde': 722,
  33670. 'zdotaccent': 389,
  33671. 'Ecaron': 611,
  33672. 'Iogonek': 333,
  33673. 'kcommaaccent': 444,
  33674. 'minus': 675,
  33675. 'Icircumflex': 333,
  33676. 'ncaron': 500,
  33677. 'tcommaaccent': 278,
  33678. 'logicalnot': 675,
  33679. 'odieresis': 500,
  33680. 'udieresis': 500,
  33681. 'notequal': 549,
  33682. 'gcommaaccent': 500,
  33683. 'eth': 500,
  33684. 'zcaron': 389,
  33685. 'ncommaaccent': 500,
  33686. 'onesuperior': 300,
  33687. 'imacron': 278,
  33688. 'Euro': 500
  33689. },
  33690. 'ZapfDingbats': {
  33691. 'space': 278,
  33692. 'a1': 974,
  33693. 'a2': 961,
  33694. 'a202': 974,
  33695. 'a3': 980,
  33696. 'a4': 719,
  33697. 'a5': 789,
  33698. 'a119': 790,
  33699. 'a118': 791,
  33700. 'a117': 690,
  33701. 'a11': 960,
  33702. 'a12': 939,
  33703. 'a13': 549,
  33704. 'a14': 855,
  33705. 'a15': 911,
  33706. 'a16': 933,
  33707. 'a105': 911,
  33708. 'a17': 945,
  33709. 'a18': 974,
  33710. 'a19': 755,
  33711. 'a20': 846,
  33712. 'a21': 762,
  33713. 'a22': 761,
  33714. 'a23': 571,
  33715. 'a24': 677,
  33716. 'a25': 763,
  33717. 'a26': 760,
  33718. 'a27': 759,
  33719. 'a28': 754,
  33720. 'a6': 494,
  33721. 'a7': 552,
  33722. 'a8': 537,
  33723. 'a9': 577,
  33724. 'a10': 692,
  33725. 'a29': 786,
  33726. 'a30': 788,
  33727. 'a31': 788,
  33728. 'a32': 790,
  33729. 'a33': 793,
  33730. 'a34': 794,
  33731. 'a35': 816,
  33732. 'a36': 823,
  33733. 'a37': 789,
  33734. 'a38': 841,
  33735. 'a39': 823,
  33736. 'a40': 833,
  33737. 'a41': 816,
  33738. 'a42': 831,
  33739. 'a43': 923,
  33740. 'a44': 744,
  33741. 'a45': 723,
  33742. 'a46': 749,
  33743. 'a47': 790,
  33744. 'a48': 792,
  33745. 'a49': 695,
  33746. 'a50': 776,
  33747. 'a51': 768,
  33748. 'a52': 792,
  33749. 'a53': 759,
  33750. 'a54': 707,
  33751. 'a55': 708,
  33752. 'a56': 682,
  33753. 'a57': 701,
  33754. 'a58': 826,
  33755. 'a59': 815,
  33756. 'a60': 789,
  33757. 'a61': 789,
  33758. 'a62': 707,
  33759. 'a63': 687,
  33760. 'a64': 696,
  33761. 'a65': 689,
  33762. 'a66': 786,
  33763. 'a67': 787,
  33764. 'a68': 713,
  33765. 'a69': 791,
  33766. 'a70': 785,
  33767. 'a71': 791,
  33768. 'a72': 873,
  33769. 'a73': 761,
  33770. 'a74': 762,
  33771. 'a203': 762,
  33772. 'a75': 759,
  33773. 'a204': 759,
  33774. 'a76': 892,
  33775. 'a77': 892,
  33776. 'a78': 788,
  33777. 'a79': 784,
  33778. 'a81': 438,
  33779. 'a82': 138,
  33780. 'a83': 277,
  33781. 'a84': 415,
  33782. 'a97': 392,
  33783. 'a98': 392,
  33784. 'a99': 668,
  33785. 'a100': 668,
  33786. 'a89': 390,
  33787. 'a90': 390,
  33788. 'a93': 317,
  33789. 'a94': 317,
  33790. 'a91': 276,
  33791. 'a92': 276,
  33792. 'a205': 509,
  33793. 'a85': 509,
  33794. 'a206': 410,
  33795. 'a86': 410,
  33796. 'a87': 234,
  33797. 'a88': 234,
  33798. 'a95': 334,
  33799. 'a96': 334,
  33800. 'a101': 732,
  33801. 'a102': 544,
  33802. 'a103': 544,
  33803. 'a104': 910,
  33804. 'a106': 667,
  33805. 'a107': 760,
  33806. 'a108': 760,
  33807. 'a112': 776,
  33808. 'a111': 595,
  33809. 'a110': 694,
  33810. 'a109': 626,
  33811. 'a120': 788,
  33812. 'a121': 788,
  33813. 'a122': 788,
  33814. 'a123': 788,
  33815. 'a124': 788,
  33816. 'a125': 788,
  33817. 'a126': 788,
  33818. 'a127': 788,
  33819. 'a128': 788,
  33820. 'a129': 788,
  33821. 'a130': 788,
  33822. 'a131': 788,
  33823. 'a132': 788,
  33824. 'a133': 788,
  33825. 'a134': 788,
  33826. 'a135': 788,
  33827. 'a136': 788,
  33828. 'a137': 788,
  33829. 'a138': 788,
  33830. 'a139': 788,
  33831. 'a140': 788,
  33832. 'a141': 788,
  33833. 'a142': 788,
  33834. 'a143': 788,
  33835. 'a144': 788,
  33836. 'a145': 788,
  33837. 'a146': 788,
  33838. 'a147': 788,
  33839. 'a148': 788,
  33840. 'a149': 788,
  33841. 'a150': 788,
  33842. 'a151': 788,
  33843. 'a152': 788,
  33844. 'a153': 788,
  33845. 'a154': 788,
  33846. 'a155': 788,
  33847. 'a156': 788,
  33848. 'a157': 788,
  33849. 'a158': 788,
  33850. 'a159': 788,
  33851. 'a160': 894,
  33852. 'a161': 838,
  33853. 'a163': 1016,
  33854. 'a164': 458,
  33855. 'a196': 748,
  33856. 'a165': 924,
  33857. 'a192': 748,
  33858. 'a166': 918,
  33859. 'a167': 927,
  33860. 'a168': 928,
  33861. 'a169': 928,
  33862. 'a170': 834,
  33863. 'a171': 873,
  33864. 'a172': 828,
  33865. 'a173': 924,
  33866. 'a162': 924,
  33867. 'a174': 917,
  33868. 'a175': 930,
  33869. 'a176': 931,
  33870. 'a177': 463,
  33871. 'a178': 883,
  33872. 'a179': 836,
  33873. 'a193': 836,
  33874. 'a180': 867,
  33875. 'a199': 867,
  33876. 'a181': 696,
  33877. 'a200': 696,
  33878. 'a182': 874,
  33879. 'a201': 874,
  33880. 'a183': 760,
  33881. 'a184': 946,
  33882. 'a197': 771,
  33883. 'a185': 865,
  33884. 'a194': 771,
  33885. 'a198': 888,
  33886. 'a186': 967,
  33887. 'a195': 888,
  33888. 'a187': 831,
  33889. 'a188': 873,
  33890. 'a189': 927,
  33891. 'a190': 970,
  33892. 'a191': 918
  33893. }
  33894. };
  33895. var EOF = {};
  33896. function isEOF(v) {
  33897. return (v === EOF);
  33898. }
  33899. var MAX_LENGTH_TO_CACHE = 1000;
  33900. var Parser = (function ParserClosure() {
  33901. function Parser(lexer, allowStreams, xref) {
  33902. this.lexer = lexer;
  33903. this.allowStreams = allowStreams;
  33904. this.xref = xref;
  33905. this.imageCache = {};
  33906. this.refill();
  33907. }
  33908. Parser.prototype = {
  33909. refill: function Parser_refill() {
  33910. this.buf1 = this.lexer.getObj();
  33911. this.buf2 = this.lexer.getObj();
  33912. },
  33913. shift: function Parser_shift() {
  33914. if (isCmd(this.buf2, 'ID')) {
  33915. this.buf1 = this.buf2;
  33916. this.buf2 = null;
  33917. } else {
  33918. this.buf1 = this.buf2;
  33919. this.buf2 = this.lexer.getObj();
  33920. }
  33921. },
  33922. getObj: function Parser_getObj(cipherTransform) {
  33923. var buf1 = this.buf1;
  33924. this.shift();
  33925. if (buf1 instanceof Cmd) {
  33926. switch (buf1.cmd) {
  33927. case 'BI': // inline image
  33928. return this.makeInlineImage(cipherTransform);
  33929. case '[': // array
  33930. var array = [];
  33931. while (!isCmd(this.buf1, ']') && !isEOF(this.buf1)) {
  33932. array.push(this.getObj(cipherTransform));
  33933. }
  33934. if (isEOF(this.buf1)) {
  33935. error('End of file inside array');
  33936. }
  33937. this.shift();
  33938. return array;
  33939. case '<<': // dictionary or stream
  33940. var dict = new Dict(this.xref);
  33941. while (!isCmd(this.buf1, '>>') && !isEOF(this.buf1)) {
  33942. if (!isName(this.buf1)) {
  33943. info('Malformed dictionary: key must be a name object');
  33944. this.shift();
  33945. continue;
  33946. }
  33947. var key = this.buf1.name;
  33948. this.shift();
  33949. if (isEOF(this.buf1)) {
  33950. break;
  33951. }
  33952. dict.set(key, this.getObj(cipherTransform));
  33953. }
  33954. if (isEOF(this.buf1)) {
  33955. error('End of file inside dictionary');
  33956. }
  33957. // Stream objects are not allowed inside content streams or
  33958. // object streams.
  33959. if (isCmd(this.buf2, 'stream')) {
  33960. return (this.allowStreams ?
  33961. this.makeStream(dict, cipherTransform) : dict);
  33962. }
  33963. this.shift();
  33964. return dict;
  33965. default: // simple object
  33966. return buf1;
  33967. }
  33968. }
  33969. if (isInt(buf1)) { // indirect reference or integer
  33970. var num = buf1;
  33971. if (isInt(this.buf1) && isCmd(this.buf2, 'R')) {
  33972. var ref = new Ref(num, this.buf1);
  33973. this.shift();
  33974. this.shift();
  33975. return ref;
  33976. }
  33977. return num;
  33978. }
  33979. if (isString(buf1)) { // string
  33980. var str = buf1;
  33981. if (cipherTransform) {
  33982. str = cipherTransform.decryptString(str);
  33983. }
  33984. return str;
  33985. }
  33986. // simple object
  33987. return buf1;
  33988. },
  33989. /**
  33990. * Find the end of the stream by searching for the /EI\s/.
  33991. * @returns {number} The inline stream length.
  33992. */
  33993. findDefaultInlineStreamEnd:
  33994. function Parser_findDefaultInlineStreamEnd(stream) {
  33995. var E = 0x45, I = 0x49, SPACE = 0x20, LF = 0xA, CR = 0xD;
  33996. var startPos = stream.pos, state = 0, ch, i, n, followingBytes;
  33997. while ((ch = stream.getByte()) !== -1) {
  33998. if (state === 0) {
  33999. state = (ch === E) ? 1 : 0;
  34000. } else if (state === 1) {
  34001. state = (ch === I) ? 2 : 0;
  34002. } else {
  34003. assert(state === 2);
  34004. if (ch === SPACE || ch === LF || ch === CR) {
  34005. // Let's check the next five bytes are ASCII... just be sure.
  34006. n = 5;
  34007. followingBytes = stream.peekBytes(n);
  34008. for (i = 0; i < n; i++) {
  34009. ch = followingBytes[i];
  34010. if (ch !== LF && ch !== CR && (ch < SPACE || ch > 0x7F)) {
  34011. // Not a LF, CR, SPACE or any visible ASCII character, i.e.
  34012. // it's binary stuff. Resetting the state.
  34013. state = 0;
  34014. break;
  34015. }
  34016. }
  34017. if (state === 2) {
  34018. break; // Finished!
  34019. }
  34020. } else {
  34021. state = 0;
  34022. }
  34023. }
  34024. }
  34025. return ((stream.pos - 4) - startPos);
  34026. },
  34027. /**
  34028. * Find the EOI (end-of-image) marker 0xFFD9 of the stream.
  34029. * @returns {number} The inline stream length.
  34030. */
  34031. findDCTDecodeInlineStreamEnd:
  34032. function Parser_findDCTDecodeInlineStreamEnd(stream) {
  34033. var startPos = stream.pos, foundEOI = false, b, markerLength, length;
  34034. while ((b = stream.getByte()) !== -1) {
  34035. if (b !== 0xFF) { // Not a valid marker.
  34036. continue;
  34037. }
  34038. switch (stream.getByte()) {
  34039. case 0x00: // Byte stuffing.
  34040. // 0xFF00 appears to be a very common byte sequence in JPEG images.
  34041. break;
  34042. case 0xFF: // Fill byte.
  34043. // Avoid skipping a valid marker, resetting the stream position.
  34044. stream.skip(-1);
  34045. break;
  34046. case 0xD9: // EOI
  34047. foundEOI = true;
  34048. break;
  34049. case 0xC0: // SOF0
  34050. case 0xC1: // SOF1
  34051. case 0xC2: // SOF2
  34052. case 0xC3: // SOF3
  34053. case 0xC5: // SOF5
  34054. case 0xC6: // SOF6
  34055. case 0xC7: // SOF7
  34056. case 0xC9: // SOF9
  34057. case 0xCA: // SOF10
  34058. case 0xCB: // SOF11
  34059. case 0xCD: // SOF13
  34060. case 0xCE: // SOF14
  34061. case 0xCF: // SOF15
  34062. case 0xC4: // DHT
  34063. case 0xCC: // DAC
  34064. case 0xDA: // SOS
  34065. case 0xDB: // DQT
  34066. case 0xDC: // DNL
  34067. case 0xDD: // DRI
  34068. case 0xDE: // DHP
  34069. case 0xDF: // EXP
  34070. case 0xE0: // APP0
  34071. case 0xE1: // APP1
  34072. case 0xE2: // APP2
  34073. case 0xE3: // APP3
  34074. case 0xE4: // APP4
  34075. case 0xE5: // APP5
  34076. case 0xE6: // APP6
  34077. case 0xE7: // APP7
  34078. case 0xE8: // APP8
  34079. case 0xE9: // APP9
  34080. case 0xEA: // APP10
  34081. case 0xEB: // APP11
  34082. case 0xEC: // APP12
  34083. case 0xED: // APP13
  34084. case 0xEE: // APP14
  34085. case 0xEF: // APP15
  34086. case 0xFE: // COM
  34087. // The marker should be followed by the length of the segment.
  34088. markerLength = stream.getUint16();
  34089. if (markerLength > 2) {
  34090. // |markerLength| contains the byte length of the marker segment,
  34091. // including its own length (2 bytes) and excluding the marker.
  34092. stream.skip(markerLength - 2); // Jump to the next marker.
  34093. } else {
  34094. // The marker length is invalid, resetting the stream position.
  34095. stream.skip(-2);
  34096. }
  34097. break;
  34098. }
  34099. if (foundEOI) {
  34100. break;
  34101. }
  34102. }
  34103. length = stream.pos - startPos;
  34104. if (b === -1) {
  34105. warn('Inline DCTDecode image stream: ' +
  34106. 'EOI marker not found, searching for /EI/ instead.');
  34107. stream.skip(-length); // Reset the stream position.
  34108. return this.findDefaultInlineStreamEnd(stream);
  34109. }
  34110. this.inlineStreamSkipEI(stream);
  34111. return length;
  34112. },
  34113. /**
  34114. * Find the EOD (end-of-data) marker '~>' (i.e. TILDE + GT) of the stream.
  34115. * @returns {number} The inline stream length.
  34116. */
  34117. findASCII85DecodeInlineStreamEnd:
  34118. function Parser_findASCII85DecodeInlineStreamEnd(stream) {
  34119. var TILDE = 0x7E, GT = 0x3E;
  34120. var startPos = stream.pos, ch, length;
  34121. while ((ch = stream.getByte()) !== -1) {
  34122. if (ch === TILDE && stream.peekByte() === GT) {
  34123. stream.skip();
  34124. break;
  34125. }
  34126. }
  34127. length = stream.pos - startPos;
  34128. if (ch === -1) {
  34129. warn('Inline ASCII85Decode image stream: ' +
  34130. 'EOD marker not found, searching for /EI/ instead.');
  34131. stream.skip(-length); // Reset the stream position.
  34132. return this.findDefaultInlineStreamEnd(stream);
  34133. }
  34134. this.inlineStreamSkipEI(stream);
  34135. return length;
  34136. },
  34137. /**
  34138. * Find the EOD (end-of-data) marker '>' (i.e. GT) of the stream.
  34139. * @returns {number} The inline stream length.
  34140. */
  34141. findASCIIHexDecodeInlineStreamEnd:
  34142. function Parser_findASCIIHexDecodeInlineStreamEnd(stream) {
  34143. var GT = 0x3E;
  34144. var startPos = stream.pos, ch, length;
  34145. while ((ch = stream.getByte()) !== -1) {
  34146. if (ch === GT) {
  34147. break;
  34148. }
  34149. }
  34150. length = stream.pos - startPos;
  34151. if (ch === -1) {
  34152. warn('Inline ASCIIHexDecode image stream: ' +
  34153. 'EOD marker not found, searching for /EI/ instead.');
  34154. stream.skip(-length); // Reset the stream position.
  34155. return this.findDefaultInlineStreamEnd(stream);
  34156. }
  34157. this.inlineStreamSkipEI(stream);
  34158. return length;
  34159. },
  34160. /**
  34161. * Skip over the /EI/ for streams where we search for an EOD marker.
  34162. */
  34163. inlineStreamSkipEI: function Parser_inlineStreamSkipEI(stream) {
  34164. var E = 0x45, I = 0x49;
  34165. var state = 0, ch;
  34166. while ((ch = stream.getByte()) !== -1) {
  34167. if (state === 0) {
  34168. state = (ch === E) ? 1 : 0;
  34169. } else if (state === 1) {
  34170. state = (ch === I) ? 2 : 0;
  34171. } else if (state === 2) {
  34172. break;
  34173. }
  34174. }
  34175. },
  34176. makeInlineImage: function Parser_makeInlineImage(cipherTransform) {
  34177. var lexer = this.lexer;
  34178. var stream = lexer.stream;
  34179. // Parse dictionary.
  34180. var dict = new Dict(null);
  34181. while (!isCmd(this.buf1, 'ID') && !isEOF(this.buf1)) {
  34182. if (!isName(this.buf1)) {
  34183. error('Dictionary key must be a name object');
  34184. }
  34185. var key = this.buf1.name;
  34186. this.shift();
  34187. if (isEOF(this.buf1)) {
  34188. break;
  34189. }
  34190. dict.set(key, this.getObj(cipherTransform));
  34191. }
  34192. // Extract the name of the first (i.e. the current) image filter.
  34193. var filter = this.fetchIfRef(dict.get('Filter', 'F')), filterName;
  34194. if (isName(filter)) {
  34195. filterName = filter.name;
  34196. } else if (isArray(filter) && isName(filter[0])) {
  34197. filterName = filter[0].name;
  34198. }
  34199. // Parse image stream.
  34200. var startPos = stream.pos, length, i, ii;
  34201. if (filterName === 'DCTDecode' || filterName === 'DCT') {
  34202. length = this.findDCTDecodeInlineStreamEnd(stream);
  34203. } else if (filterName === 'ASCII85Decide' || filterName === 'A85') {
  34204. length = this.findASCII85DecodeInlineStreamEnd(stream);
  34205. } else if (filterName === 'ASCIIHexDecode' || filterName === 'AHx') {
  34206. length = this.findASCIIHexDecodeInlineStreamEnd(stream);
  34207. } else {
  34208. length = this.findDefaultInlineStreamEnd(stream);
  34209. }
  34210. var imageStream = stream.makeSubStream(startPos, length, dict);
  34211. // Cache all images below the MAX_LENGTH_TO_CACHE threshold by their
  34212. // adler32 checksum.
  34213. var adler32;
  34214. if (length < MAX_LENGTH_TO_CACHE) {
  34215. var imageBytes = imageStream.getBytes();
  34216. imageStream.reset();
  34217. var a = 1;
  34218. var b = 0;
  34219. for (i = 0, ii = imageBytes.length; i < ii; ++i) {
  34220. // No modulo required in the loop if imageBytes.length < 5552.
  34221. a += imageBytes[i] & 0xff;
  34222. b += a;
  34223. }
  34224. adler32 = ((b % 65521) << 16) | (a % 65521);
  34225. if (this.imageCache.adler32 === adler32) {
  34226. this.buf2 = Cmd.get('EI');
  34227. this.shift();
  34228. this.imageCache[adler32].reset();
  34229. return this.imageCache[adler32];
  34230. }
  34231. }
  34232. if (cipherTransform) {
  34233. imageStream = cipherTransform.createStream(imageStream, length);
  34234. }
  34235. imageStream = this.filter(imageStream, dict, length);
  34236. imageStream.dict = dict;
  34237. if (adler32 !== undefined) {
  34238. imageStream.cacheKey = 'inline_' + length + '_' + adler32;
  34239. this.imageCache[adler32] = imageStream;
  34240. }
  34241. this.buf2 = Cmd.get('EI');
  34242. this.shift();
  34243. return imageStream;
  34244. },
  34245. fetchIfRef: function Parser_fetchIfRef(obj) {
  34246. // not relying on the xref.fetchIfRef -- xref might not be set
  34247. return (isRef(obj) ? this.xref.fetch(obj) : obj);
  34248. },
  34249. makeStream: function Parser_makeStream(dict, cipherTransform) {
  34250. var lexer = this.lexer;
  34251. var stream = lexer.stream;
  34252. // get stream start position
  34253. lexer.skipToNextLine();
  34254. var pos = stream.pos - 1;
  34255. // get length
  34256. var length = this.fetchIfRef(dict.get('Length'));
  34257. if (!isInt(length)) {
  34258. info('Bad ' + length + ' attribute in stream');
  34259. length = 0;
  34260. }
  34261. // skip over the stream data
  34262. stream.pos = pos + length;
  34263. lexer.nextChar();
  34264. this.shift(); // '>>'
  34265. this.shift(); // 'stream'
  34266. if (!isCmd(this.buf1, 'endstream')) {
  34267. // bad stream length, scanning for endstream
  34268. stream.pos = pos;
  34269. var SCAN_BLOCK_SIZE = 2048;
  34270. var ENDSTREAM_SIGNATURE_LENGTH = 9;
  34271. var ENDSTREAM_SIGNATURE = [0x65, 0x6E, 0x64, 0x73, 0x74, 0x72, 0x65,
  34272. 0x61, 0x6D];
  34273. var skipped = 0, found = false, i, j;
  34274. while (stream.pos < stream.end) {
  34275. var scanBytes = stream.peekBytes(SCAN_BLOCK_SIZE);
  34276. var scanLength = scanBytes.length - ENDSTREAM_SIGNATURE_LENGTH;
  34277. if (scanLength <= 0) {
  34278. break;
  34279. }
  34280. found = false;
  34281. for (i = 0, j = 0; i < scanLength; i++) {
  34282. var b = scanBytes[i];
  34283. if (b !== ENDSTREAM_SIGNATURE[j]) {
  34284. i -= j;
  34285. j = 0;
  34286. } else {
  34287. j++;
  34288. if (j >= ENDSTREAM_SIGNATURE_LENGTH) {
  34289. i++;
  34290. found = true;
  34291. break;
  34292. }
  34293. }
  34294. }
  34295. if (found) {
  34296. skipped += i - ENDSTREAM_SIGNATURE_LENGTH;
  34297. stream.pos += i - ENDSTREAM_SIGNATURE_LENGTH;
  34298. break;
  34299. }
  34300. skipped += scanLength;
  34301. stream.pos += scanLength;
  34302. }
  34303. if (!found) {
  34304. error('Missing endstream');
  34305. }
  34306. length = skipped;
  34307. lexer.nextChar();
  34308. this.shift();
  34309. this.shift();
  34310. }
  34311. this.shift(); // 'endstream'
  34312. stream = stream.makeSubStream(pos, length, dict);
  34313. if (cipherTransform) {
  34314. stream = cipherTransform.createStream(stream, length);
  34315. }
  34316. stream = this.filter(stream, dict, length);
  34317. stream.dict = dict;
  34318. return stream;
  34319. },
  34320. filter: function Parser_filter(stream, dict, length) {
  34321. var filter = this.fetchIfRef(dict.get('Filter', 'F'));
  34322. var params = this.fetchIfRef(dict.get('DecodeParms', 'DP'));
  34323. if (isName(filter)) {
  34324. return this.makeFilter(stream, filter.name, length, params);
  34325. }
  34326. var maybeLength = length;
  34327. if (isArray(filter)) {
  34328. var filterArray = filter;
  34329. var paramsArray = params;
  34330. for (var i = 0, ii = filterArray.length; i < ii; ++i) {
  34331. filter = filterArray[i];
  34332. if (!isName(filter)) {
  34333. error('Bad filter name: ' + filter);
  34334. }
  34335. params = null;
  34336. if (isArray(paramsArray) && (i in paramsArray)) {
  34337. params = paramsArray[i];
  34338. }
  34339. stream = this.makeFilter(stream, filter.name, maybeLength, params);
  34340. // after the first stream the length variable is invalid
  34341. maybeLength = null;
  34342. }
  34343. }
  34344. return stream;
  34345. },
  34346. makeFilter: function Parser_makeFilter(stream, name, maybeLength, params) {
  34347. if (stream.dict.get('Length') === 0) {
  34348. return new NullStream(stream);
  34349. }
  34350. try {
  34351. if (params) {
  34352. params = this.fetchIfRef(params);
  34353. }
  34354. var xrefStreamStats = this.xref.stats.streamTypes;
  34355. if (name === 'FlateDecode' || name === 'Fl') {
  34356. xrefStreamStats[StreamType.FLATE] = true;
  34357. if (params) {
  34358. return new PredictorStream(new FlateStream(stream, maybeLength),
  34359. maybeLength, params);
  34360. }
  34361. return new FlateStream(stream, maybeLength);
  34362. }
  34363. if (name === 'LZWDecode' || name === 'LZW') {
  34364. xrefStreamStats[StreamType.LZW] = true;
  34365. var earlyChange = 1;
  34366. if (params) {
  34367. if (params.has('EarlyChange')) {
  34368. earlyChange = params.get('EarlyChange');
  34369. }
  34370. return new PredictorStream(
  34371. new LZWStream(stream, maybeLength, earlyChange),
  34372. maybeLength, params);
  34373. }
  34374. return new LZWStream(stream, maybeLength, earlyChange);
  34375. }
  34376. if (name === 'DCTDecode' || name === 'DCT') {
  34377. xrefStreamStats[StreamType.DCT] = true;
  34378. return new JpegStream(stream, maybeLength, stream.dict, this.xref);
  34379. }
  34380. if (name === 'JPXDecode' || name === 'JPX') {
  34381. xrefStreamStats[StreamType.JPX] = true;
  34382. return new JpxStream(stream, maybeLength, stream.dict);
  34383. }
  34384. if (name === 'ASCII85Decode' || name === 'A85') {
  34385. xrefStreamStats[StreamType.A85] = true;
  34386. return new Ascii85Stream(stream, maybeLength);
  34387. }
  34388. if (name === 'ASCIIHexDecode' || name === 'AHx') {
  34389. xrefStreamStats[StreamType.AHX] = true;
  34390. return new AsciiHexStream(stream, maybeLength);
  34391. }
  34392. if (name === 'CCITTFaxDecode' || name === 'CCF') {
  34393. xrefStreamStats[StreamType.CCF] = true;
  34394. return new CCITTFaxStream(stream, maybeLength, params);
  34395. }
  34396. if (name === 'RunLengthDecode' || name === 'RL') {
  34397. xrefStreamStats[StreamType.RL] = true;
  34398. return new RunLengthStream(stream, maybeLength);
  34399. }
  34400. if (name === 'JBIG2Decode') {
  34401. xrefStreamStats[StreamType.JBIG] = true;
  34402. return new Jbig2Stream(stream, maybeLength, stream.dict);
  34403. }
  34404. warn('filter "' + name + '" not supported yet');
  34405. return stream;
  34406. } catch (ex) {
  34407. if (ex instanceof MissingDataException) {
  34408. throw ex;
  34409. }
  34410. warn('Invalid stream: \"' + ex + '\"');
  34411. return new NullStream(stream);
  34412. }
  34413. }
  34414. };
  34415. return Parser;
  34416. })();
  34417. var Lexer = (function LexerClosure() {
  34418. function Lexer(stream, knownCommands) {
  34419. this.stream = stream;
  34420. this.nextChar();
  34421. // While lexing, we build up many strings one char at a time. Using += for
  34422. // this can result in lots of garbage strings. It's better to build an
  34423. // array of single-char strings and then join() them together at the end.
  34424. // And reusing a single array (i.e. |this.strBuf|) over and over for this
  34425. // purpose uses less memory than using a new array for each string.
  34426. this.strBuf = [];
  34427. // The PDFs might have "glued" commands with other commands, operands or
  34428. // literals, e.g. "q1". The knownCommands is a dictionary of the valid
  34429. // commands and their prefixes. The prefixes are built the following way:
  34430. // if there a command that is a prefix of the other valid command or
  34431. // literal (e.g. 'f' and 'false') the following prefixes must be included,
  34432. // 'fa', 'fal', 'fals'. The prefixes are not needed, if the command has no
  34433. // other commands or literals as a prefix. The knowCommands is optional.
  34434. this.knownCommands = knownCommands;
  34435. }
  34436. Lexer.isSpace = function Lexer_isSpace(ch) {
  34437. // Space is one of the following characters: SPACE, TAB, CR or LF.
  34438. return (ch === 0x20 || ch === 0x09 || ch === 0x0D || ch === 0x0A);
  34439. };
  34440. // A '1' in this array means the character is white space. A '1' or
  34441. // '2' means the character ends a name or command.
  34442. var specialChars = [
  34443. 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, // 0x
  34444. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 1x
  34445. 1, 0, 0, 0, 0, 2, 0, 0, 2, 2, 0, 0, 0, 0, 0, 2, // 2x
  34446. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, // 3x
  34447. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 4x
  34448. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 5x
  34449. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 6x
  34450. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 7x
  34451. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 8x
  34452. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 9x
  34453. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ax
  34454. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // bx
  34455. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // cx
  34456. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // dx
  34457. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ex
  34458. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 // fx
  34459. ];
  34460. function toHexDigit(ch) {
  34461. if (ch >= 0x30 && ch <= 0x39) { // '0'-'9'
  34462. return ch & 0x0F;
  34463. }
  34464. if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
  34465. // 'A'-'F', 'a'-'f'
  34466. return (ch & 0x0F) + 9;
  34467. }
  34468. return -1;
  34469. }
  34470. Lexer.prototype = {
  34471. nextChar: function Lexer_nextChar() {
  34472. return (this.currentChar = this.stream.getByte());
  34473. },
  34474. peekChar: function Lexer_peekChar() {
  34475. return this.stream.peekByte();
  34476. },
  34477. getNumber: function Lexer_getNumber() {
  34478. var ch = this.currentChar;
  34479. var eNotation = false;
  34480. var divideBy = 0; // different from 0 if it's a floating point value
  34481. var sign = 1;
  34482. if (ch === 0x2D) { // '-'
  34483. sign = -1;
  34484. ch = this.nextChar();
  34485. } else if (ch === 0x2B) { // '+'
  34486. ch = this.nextChar();
  34487. }
  34488. if (ch === 0x2E) { // '.'
  34489. divideBy = 10;
  34490. ch = this.nextChar();
  34491. }
  34492. if (ch < 0x30 || ch > 0x39) { // '0' - '9'
  34493. error('Invalid number: ' + String.fromCharCode(ch));
  34494. return 0;
  34495. }
  34496. var baseValue = ch - 0x30; // '0'
  34497. var powerValue = 0;
  34498. var powerValueSign = 1;
  34499. while ((ch = this.nextChar()) >= 0) {
  34500. if (0x30 <= ch && ch <= 0x39) { // '0' - '9'
  34501. var currentDigit = ch - 0x30; // '0'
  34502. if (eNotation) { // We are after an 'e' or 'E'
  34503. powerValue = powerValue * 10 + currentDigit;
  34504. } else {
  34505. if (divideBy !== 0) { // We are after a point
  34506. divideBy *= 10;
  34507. }
  34508. baseValue = baseValue * 10 + currentDigit;
  34509. }
  34510. } else if (ch === 0x2E) { // '.'
  34511. if (divideBy === 0) {
  34512. divideBy = 1;
  34513. } else {
  34514. // A number can have only one '.'
  34515. break;
  34516. }
  34517. } else if (ch === 0x2D) { // '-'
  34518. // ignore minus signs in the middle of numbers to match
  34519. // Adobe's behavior
  34520. warn('Badly formated number');
  34521. } else if (ch === 0x45 || ch === 0x65) { // 'E', 'e'
  34522. // 'E' can be either a scientific notation or the beginning of a new
  34523. // operator
  34524. ch = this.peekChar();
  34525. if (ch === 0x2B || ch === 0x2D) { // '+', '-'
  34526. powerValueSign = (ch === 0x2D) ? -1 : 1;
  34527. this.nextChar(); // Consume the sign character
  34528. } else if (ch < 0x30 || ch > 0x39) { // '0' - '9'
  34529. // The 'E' must be the beginning of a new operator
  34530. break;
  34531. }
  34532. eNotation = true;
  34533. } else {
  34534. // the last character doesn't belong to us
  34535. break;
  34536. }
  34537. }
  34538. if (divideBy !== 0) {
  34539. baseValue /= divideBy;
  34540. }
  34541. if (eNotation) {
  34542. baseValue *= Math.pow(10, powerValueSign * powerValue);
  34543. }
  34544. return sign * baseValue;
  34545. },
  34546. getString: function Lexer_getString() {
  34547. var numParen = 1;
  34548. var done = false;
  34549. var strBuf = this.strBuf;
  34550. strBuf.length = 0;
  34551. var ch = this.nextChar();
  34552. while (true) {
  34553. var charBuffered = false;
  34554. switch (ch | 0) {
  34555. case -1:
  34556. warn('Unterminated string');
  34557. done = true;
  34558. break;
  34559. case 0x28: // '('
  34560. ++numParen;
  34561. strBuf.push('(');
  34562. break;
  34563. case 0x29: // ')'
  34564. if (--numParen === 0) {
  34565. this.nextChar(); // consume strings ')'
  34566. done = true;
  34567. } else {
  34568. strBuf.push(')');
  34569. }
  34570. break;
  34571. case 0x5C: // '\\'
  34572. ch = this.nextChar();
  34573. switch (ch) {
  34574. case -1:
  34575. warn('Unterminated string');
  34576. done = true;
  34577. break;
  34578. case 0x6E: // 'n'
  34579. strBuf.push('\n');
  34580. break;
  34581. case 0x72: // 'r'
  34582. strBuf.push('\r');
  34583. break;
  34584. case 0x74: // 't'
  34585. strBuf.push('\t');
  34586. break;
  34587. case 0x62: // 'b'
  34588. strBuf.push('\b');
  34589. break;
  34590. case 0x66: // 'f'
  34591. strBuf.push('\f');
  34592. break;
  34593. case 0x5C: // '\'
  34594. case 0x28: // '('
  34595. case 0x29: // ')'
  34596. strBuf.push(String.fromCharCode(ch));
  34597. break;
  34598. case 0x30: case 0x31: case 0x32: case 0x33: // '0'-'3'
  34599. case 0x34: case 0x35: case 0x36: case 0x37: // '4'-'7'
  34600. var x = ch & 0x0F;
  34601. ch = this.nextChar();
  34602. charBuffered = true;
  34603. if (ch >= 0x30 && ch <= 0x37) { // '0'-'7'
  34604. x = (x << 3) + (ch & 0x0F);
  34605. ch = this.nextChar();
  34606. if (ch >= 0x30 && ch <= 0x37) { // '0'-'7'
  34607. charBuffered = false;
  34608. x = (x << 3) + (ch & 0x0F);
  34609. }
  34610. }
  34611. strBuf.push(String.fromCharCode(x));
  34612. break;
  34613. case 0x0D: // CR
  34614. if (this.peekChar() === 0x0A) { // LF
  34615. this.nextChar();
  34616. }
  34617. break;
  34618. case 0x0A: // LF
  34619. break;
  34620. default:
  34621. strBuf.push(String.fromCharCode(ch));
  34622. break;
  34623. }
  34624. break;
  34625. default:
  34626. strBuf.push(String.fromCharCode(ch));
  34627. break;
  34628. }
  34629. if (done) {
  34630. break;
  34631. }
  34632. if (!charBuffered) {
  34633. ch = this.nextChar();
  34634. }
  34635. }
  34636. return strBuf.join('');
  34637. },
  34638. getName: function Lexer_getName() {
  34639. var ch;
  34640. var strBuf = this.strBuf;
  34641. strBuf.length = 0;
  34642. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  34643. if (ch === 0x23) { // '#'
  34644. ch = this.nextChar();
  34645. var x = toHexDigit(ch);
  34646. if (x !== -1) {
  34647. var x2 = toHexDigit(this.nextChar());
  34648. if (x2 === -1) {
  34649. error('Illegal digit in hex char in name: ' + x2);
  34650. }
  34651. strBuf.push(String.fromCharCode((x << 4) | x2));
  34652. } else {
  34653. strBuf.push('#', String.fromCharCode(ch));
  34654. }
  34655. } else {
  34656. strBuf.push(String.fromCharCode(ch));
  34657. }
  34658. }
  34659. if (strBuf.length > 128) {
  34660. error('Warning: name token is longer than allowed by the spec: ' +
  34661. strBuf.length);
  34662. }
  34663. return Name.get(strBuf.join(''));
  34664. },
  34665. getHexString: function Lexer_getHexString() {
  34666. var strBuf = this.strBuf;
  34667. strBuf.length = 0;
  34668. var ch = this.currentChar;
  34669. var isFirstHex = true;
  34670. var firstDigit;
  34671. var secondDigit;
  34672. while (true) {
  34673. if (ch < 0) {
  34674. warn('Unterminated hex string');
  34675. break;
  34676. } else if (ch === 0x3E) { // '>'
  34677. this.nextChar();
  34678. break;
  34679. } else if (specialChars[ch] === 1) {
  34680. ch = this.nextChar();
  34681. continue;
  34682. } else {
  34683. if (isFirstHex) {
  34684. firstDigit = toHexDigit(ch);
  34685. if (firstDigit === -1) {
  34686. warn('Ignoring invalid character "' + ch + '" in hex string');
  34687. ch = this.nextChar();
  34688. continue;
  34689. }
  34690. } else {
  34691. secondDigit = toHexDigit(ch);
  34692. if (secondDigit === -1) {
  34693. warn('Ignoring invalid character "' + ch + '" in hex string');
  34694. ch = this.nextChar();
  34695. continue;
  34696. }
  34697. strBuf.push(String.fromCharCode((firstDigit << 4) | secondDigit));
  34698. }
  34699. isFirstHex = !isFirstHex;
  34700. ch = this.nextChar();
  34701. }
  34702. }
  34703. return strBuf.join('');
  34704. },
  34705. getObj: function Lexer_getObj() {
  34706. // skip whitespace and comments
  34707. var comment = false;
  34708. var ch = this.currentChar;
  34709. while (true) {
  34710. if (ch < 0) {
  34711. return EOF;
  34712. }
  34713. if (comment) {
  34714. if (ch === 0x0A || ch === 0x0D) { // LF, CR
  34715. comment = false;
  34716. }
  34717. } else if (ch === 0x25) { // '%'
  34718. comment = true;
  34719. } else if (specialChars[ch] !== 1) {
  34720. break;
  34721. }
  34722. ch = this.nextChar();
  34723. }
  34724. // start reading token
  34725. switch (ch | 0) {
  34726. case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: // '0'-'4'
  34727. case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: // '5'-'9'
  34728. case 0x2B: case 0x2D: case 0x2E: // '+', '-', '.'
  34729. return this.getNumber();
  34730. case 0x28: // '('
  34731. return this.getString();
  34732. case 0x2F: // '/'
  34733. return this.getName();
  34734. // array punctuation
  34735. case 0x5B: // '['
  34736. this.nextChar();
  34737. return Cmd.get('[');
  34738. case 0x5D: // ']'
  34739. this.nextChar();
  34740. return Cmd.get(']');
  34741. // hex string or dict punctuation
  34742. case 0x3C: // '<'
  34743. ch = this.nextChar();
  34744. if (ch === 0x3C) {
  34745. // dict punctuation
  34746. this.nextChar();
  34747. return Cmd.get('<<');
  34748. }
  34749. return this.getHexString();
  34750. // dict punctuation
  34751. case 0x3E: // '>'
  34752. ch = this.nextChar();
  34753. if (ch === 0x3E) {
  34754. this.nextChar();
  34755. return Cmd.get('>>');
  34756. }
  34757. return Cmd.get('>');
  34758. case 0x7B: // '{'
  34759. this.nextChar();
  34760. return Cmd.get('{');
  34761. case 0x7D: // '}'
  34762. this.nextChar();
  34763. return Cmd.get('}');
  34764. case 0x29: // ')'
  34765. error('Illegal character: ' + ch);
  34766. break;
  34767. }
  34768. // command
  34769. var str = String.fromCharCode(ch);
  34770. var knownCommands = this.knownCommands;
  34771. var knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  34772. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  34773. // stop if known command is found and next character does not make
  34774. // the str a command
  34775. var possibleCommand = str + String.fromCharCode(ch);
  34776. if (knownCommandFound && knownCommands[possibleCommand] === undefined) {
  34777. break;
  34778. }
  34779. if (str.length === 128) {
  34780. error('Command token too long: ' + str.length);
  34781. }
  34782. str = possibleCommand;
  34783. knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  34784. }
  34785. if (str === 'true') {
  34786. return true;
  34787. }
  34788. if (str === 'false') {
  34789. return false;
  34790. }
  34791. if (str === 'null') {
  34792. return null;
  34793. }
  34794. return Cmd.get(str);
  34795. },
  34796. skipToNextLine: function Lexer_skipToNextLine() {
  34797. var ch = this.currentChar;
  34798. while (ch >= 0) {
  34799. if (ch === 0x0D) { // CR
  34800. ch = this.nextChar();
  34801. if (ch === 0x0A) { // LF
  34802. this.nextChar();
  34803. }
  34804. break;
  34805. } else if (ch === 0x0A) { // LF
  34806. this.nextChar();
  34807. break;
  34808. }
  34809. ch = this.nextChar();
  34810. }
  34811. }
  34812. };
  34813. return Lexer;
  34814. })();
  34815. var Linearization = {
  34816. create: function LinearizationCreate(stream) {
  34817. function getInt(name, allowZeroValue) {
  34818. var obj = linDict.get(name);
  34819. if (isInt(obj) && (allowZeroValue ? obj >= 0 : obj > 0)) {
  34820. return obj;
  34821. }
  34822. throw new Error('The "' + name + '" parameter in the linearization ' +
  34823. 'dictionary is invalid.');
  34824. }
  34825. function getHints() {
  34826. var hints = linDict.get('H'), hintsLength, item;
  34827. if (isArray(hints) &&
  34828. ((hintsLength = hints.length) === 2 || hintsLength === 4)) {
  34829. for (var index = 0; index < hintsLength; index++) {
  34830. if (!(isInt(item = hints[index]) && item > 0)) {
  34831. throw new Error('Hint (' + index +
  34832. ') in the linearization dictionary is invalid.');
  34833. }
  34834. }
  34835. return hints;
  34836. }
  34837. throw new Error('Hint array in the linearization dictionary is invalid.');
  34838. }
  34839. var parser = new Parser(new Lexer(stream), false, null);
  34840. var obj1 = parser.getObj();
  34841. var obj2 = parser.getObj();
  34842. var obj3 = parser.getObj();
  34843. var linDict = parser.getObj();
  34844. var obj, length;
  34845. if (!(isInt(obj1) && isInt(obj2) && isCmd(obj3, 'obj') && isDict(linDict) &&
  34846. isNum(obj = linDict.get('Linearized')) && obj > 0)) {
  34847. return null; // No valid linearization dictionary found.
  34848. } else if ((length = getInt('L')) !== stream.length) {
  34849. throw new Error('The "L" parameter in the linearization dictionary ' +
  34850. 'does not equal the stream length.');
  34851. }
  34852. return {
  34853. length: length,
  34854. hints: getHints(),
  34855. objectNumberFirst: getInt('O'),
  34856. endFirst: getInt('E'),
  34857. numPages: getInt('N'),
  34858. mainXRefEntriesOffset: getInt('T'),
  34859. pageFirst: (linDict.has('P') ? getInt('P', true) : 0)
  34860. };
  34861. }
  34862. };
  34863. var PostScriptParser = (function PostScriptParserClosure() {
  34864. function PostScriptParser(lexer) {
  34865. this.lexer = lexer;
  34866. this.operators = [];
  34867. this.token = null;
  34868. this.prev = null;
  34869. }
  34870. PostScriptParser.prototype = {
  34871. nextToken: function PostScriptParser_nextToken() {
  34872. this.prev = this.token;
  34873. this.token = this.lexer.getToken();
  34874. },
  34875. accept: function PostScriptParser_accept(type) {
  34876. if (this.token.type === type) {
  34877. this.nextToken();
  34878. return true;
  34879. }
  34880. return false;
  34881. },
  34882. expect: function PostScriptParser_expect(type) {
  34883. if (this.accept(type)) {
  34884. return true;
  34885. }
  34886. error('Unexpected symbol: found ' + this.token.type + ' expected ' +
  34887. type + '.');
  34888. },
  34889. parse: function PostScriptParser_parse() {
  34890. this.nextToken();
  34891. this.expect(PostScriptTokenTypes.LBRACE);
  34892. this.parseBlock();
  34893. this.expect(PostScriptTokenTypes.RBRACE);
  34894. return this.operators;
  34895. },
  34896. parseBlock: function PostScriptParser_parseBlock() {
  34897. while (true) {
  34898. if (this.accept(PostScriptTokenTypes.NUMBER)) {
  34899. this.operators.push(this.prev.value);
  34900. } else if (this.accept(PostScriptTokenTypes.OPERATOR)) {
  34901. this.operators.push(this.prev.value);
  34902. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  34903. this.parseCondition();
  34904. } else {
  34905. return;
  34906. }
  34907. }
  34908. },
  34909. parseCondition: function PostScriptParser_parseCondition() {
  34910. // Add two place holders that will be updated later
  34911. var conditionLocation = this.operators.length;
  34912. this.operators.push(null, null);
  34913. this.parseBlock();
  34914. this.expect(PostScriptTokenTypes.RBRACE);
  34915. if (this.accept(PostScriptTokenTypes.IF)) {
  34916. // The true block is right after the 'if' so it just falls through on
  34917. // true else it jumps and skips the true block.
  34918. this.operators[conditionLocation] = this.operators.length;
  34919. this.operators[conditionLocation + 1] = 'jz';
  34920. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  34921. var jumpLocation = this.operators.length;
  34922. this.operators.push(null, null);
  34923. var endOfTrue = this.operators.length;
  34924. this.parseBlock();
  34925. this.expect(PostScriptTokenTypes.RBRACE);
  34926. this.expect(PostScriptTokenTypes.IFELSE);
  34927. // The jump is added at the end of the true block to skip the false
  34928. // block.
  34929. this.operators[jumpLocation] = this.operators.length;
  34930. this.operators[jumpLocation + 1] = 'j';
  34931. this.operators[conditionLocation] = endOfTrue;
  34932. this.operators[conditionLocation + 1] = 'jz';
  34933. } else {
  34934. error('PS Function: error parsing conditional.');
  34935. }
  34936. }
  34937. };
  34938. return PostScriptParser;
  34939. })();
  34940. var PostScriptTokenTypes = {
  34941. LBRACE: 0,
  34942. RBRACE: 1,
  34943. NUMBER: 2,
  34944. OPERATOR: 3,
  34945. IF: 4,
  34946. IFELSE: 5
  34947. };
  34948. var PostScriptToken = (function PostScriptTokenClosure() {
  34949. function PostScriptToken(type, value) {
  34950. this.type = type;
  34951. this.value = value;
  34952. }
  34953. var opCache = {};
  34954. PostScriptToken.getOperator = function PostScriptToken_getOperator(op) {
  34955. var opValue = opCache[op];
  34956. if (opValue) {
  34957. return opValue;
  34958. }
  34959. return opCache[op] = new PostScriptToken(PostScriptTokenTypes.OPERATOR, op);
  34960. };
  34961. PostScriptToken.LBRACE = new PostScriptToken(PostScriptTokenTypes.LBRACE,
  34962. '{');
  34963. PostScriptToken.RBRACE = new PostScriptToken(PostScriptTokenTypes.RBRACE,
  34964. '}');
  34965. PostScriptToken.IF = new PostScriptToken(PostScriptTokenTypes.IF, 'IF');
  34966. PostScriptToken.IFELSE = new PostScriptToken(PostScriptTokenTypes.IFELSE,
  34967. 'IFELSE');
  34968. return PostScriptToken;
  34969. })();
  34970. var PostScriptLexer = (function PostScriptLexerClosure() {
  34971. function PostScriptLexer(stream) {
  34972. this.stream = stream;
  34973. this.nextChar();
  34974. this.strBuf = [];
  34975. }
  34976. PostScriptLexer.prototype = {
  34977. nextChar: function PostScriptLexer_nextChar() {
  34978. return (this.currentChar = this.stream.getByte());
  34979. },
  34980. getToken: function PostScriptLexer_getToken() {
  34981. var comment = false;
  34982. var ch = this.currentChar;
  34983. // skip comments
  34984. while (true) {
  34985. if (ch < 0) {
  34986. return EOF;
  34987. }
  34988. if (comment) {
  34989. if (ch === 0x0A || ch === 0x0D) {
  34990. comment = false;
  34991. }
  34992. } else if (ch === 0x25) { // '%'
  34993. comment = true;
  34994. } else if (!Lexer.isSpace(ch)) {
  34995. break;
  34996. }
  34997. ch = this.nextChar();
  34998. }
  34999. switch (ch | 0) {
  35000. case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: // '0'-'4'
  35001. case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: // '5'-'9'
  35002. case 0x2B: case 0x2D: case 0x2E: // '+', '-', '.'
  35003. return new PostScriptToken(PostScriptTokenTypes.NUMBER,
  35004. this.getNumber());
  35005. case 0x7B: // '{'
  35006. this.nextChar();
  35007. return PostScriptToken.LBRACE;
  35008. case 0x7D: // '}'
  35009. this.nextChar();
  35010. return PostScriptToken.RBRACE;
  35011. }
  35012. // operator
  35013. var strBuf = this.strBuf;
  35014. strBuf.length = 0;
  35015. strBuf[0] = String.fromCharCode(ch);
  35016. while ((ch = this.nextChar()) >= 0 && // and 'A'-'Z', 'a'-'z'
  35017. ((ch >= 0x41 && ch <= 0x5A) || (ch >= 0x61 && ch <= 0x7A))) {
  35018. strBuf.push(String.fromCharCode(ch));
  35019. }
  35020. var str = strBuf.join('');
  35021. switch (str.toLowerCase()) {
  35022. case 'if':
  35023. return PostScriptToken.IF;
  35024. case 'ifelse':
  35025. return PostScriptToken.IFELSE;
  35026. default:
  35027. return PostScriptToken.getOperator(str);
  35028. }
  35029. },
  35030. getNumber: function PostScriptLexer_getNumber() {
  35031. var ch = this.currentChar;
  35032. var strBuf = this.strBuf;
  35033. strBuf.length = 0;
  35034. strBuf[0] = String.fromCharCode(ch);
  35035. while ((ch = this.nextChar()) >= 0) {
  35036. if ((ch >= 0x30 && ch <= 0x39) || // '0'-'9'
  35037. ch === 0x2D || ch === 0x2E) { // '-', '.'
  35038. strBuf.push(String.fromCharCode(ch));
  35039. } else {
  35040. break;
  35041. }
  35042. }
  35043. var value = parseFloat(strBuf.join(''));
  35044. if (isNaN(value)) {
  35045. error('Invalid floating point number: ' + value);
  35046. }
  35047. return value;
  35048. }
  35049. };
  35050. return PostScriptLexer;
  35051. })();
  35052. var Stream = (function StreamClosure() {
  35053. function Stream(arrayBuffer, start, length, dict) {
  35054. this.bytes = (arrayBuffer instanceof Uint8Array ?
  35055. arrayBuffer : new Uint8Array(arrayBuffer));
  35056. this.start = start || 0;
  35057. this.pos = this.start;
  35058. this.end = (start + length) || this.bytes.length;
  35059. this.dict = dict;
  35060. }
  35061. // required methods for a stream. if a particular stream does not
  35062. // implement these, an error should be thrown
  35063. Stream.prototype = {
  35064. get length() {
  35065. return this.end - this.start;
  35066. },
  35067. get isEmpty() {
  35068. return this.length === 0;
  35069. },
  35070. getByte: function Stream_getByte() {
  35071. if (this.pos >= this.end) {
  35072. return -1;
  35073. }
  35074. return this.bytes[this.pos++];
  35075. },
  35076. getUint16: function Stream_getUint16() {
  35077. var b0 = this.getByte();
  35078. var b1 = this.getByte();
  35079. if (b0 === -1 || b1 === -1) {
  35080. return -1;
  35081. }
  35082. return (b0 << 8) + b1;
  35083. },
  35084. getInt32: function Stream_getInt32() {
  35085. var b0 = this.getByte();
  35086. var b1 = this.getByte();
  35087. var b2 = this.getByte();
  35088. var b3 = this.getByte();
  35089. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  35090. },
  35091. // returns subarray of original buffer
  35092. // should only be read
  35093. getBytes: function Stream_getBytes(length) {
  35094. var bytes = this.bytes;
  35095. var pos = this.pos;
  35096. var strEnd = this.end;
  35097. if (!length) {
  35098. return bytes.subarray(pos, strEnd);
  35099. }
  35100. var end = pos + length;
  35101. if (end > strEnd) {
  35102. end = strEnd;
  35103. }
  35104. this.pos = end;
  35105. return bytes.subarray(pos, end);
  35106. },
  35107. peekByte: function Stream_peekByte() {
  35108. var peekedByte = this.getByte();
  35109. this.pos--;
  35110. return peekedByte;
  35111. },
  35112. peekBytes: function Stream_peekBytes(length) {
  35113. var bytes = this.getBytes(length);
  35114. this.pos -= bytes.length;
  35115. return bytes;
  35116. },
  35117. skip: function Stream_skip(n) {
  35118. if (!n) {
  35119. n = 1;
  35120. }
  35121. this.pos += n;
  35122. },
  35123. reset: function Stream_reset() {
  35124. this.pos = this.start;
  35125. },
  35126. moveStart: function Stream_moveStart() {
  35127. this.start = this.pos;
  35128. },
  35129. makeSubStream: function Stream_makeSubStream(start, length, dict) {
  35130. return new Stream(this.bytes.buffer, start, length, dict);
  35131. },
  35132. isStream: true
  35133. };
  35134. return Stream;
  35135. })();
  35136. var StringStream = (function StringStreamClosure() {
  35137. function StringStream(str) {
  35138. var length = str.length;
  35139. var bytes = new Uint8Array(length);
  35140. for (var n = 0; n < length; ++n) {
  35141. bytes[n] = str.charCodeAt(n);
  35142. }
  35143. Stream.call(this, bytes);
  35144. }
  35145. StringStream.prototype = Stream.prototype;
  35146. return StringStream;
  35147. })();
  35148. // super class for the decoding streams
  35149. var DecodeStream = (function DecodeStreamClosure() {
  35150. // Lots of DecodeStreams are created whose buffers are never used. For these
  35151. // we share a single empty buffer. This is (a) space-efficient and (b) avoids
  35152. // having special cases that would be required if we used |null| for an empty
  35153. // buffer.
  35154. var emptyBuffer = new Uint8Array(0);
  35155. function DecodeStream(maybeMinBufferLength) {
  35156. this.pos = 0;
  35157. this.bufferLength = 0;
  35158. this.eof = false;
  35159. this.buffer = emptyBuffer;
  35160. this.minBufferLength = 512;
  35161. if (maybeMinBufferLength) {
  35162. // Compute the first power of two that is as big as maybeMinBufferLength.
  35163. while (this.minBufferLength < maybeMinBufferLength) {
  35164. this.minBufferLength *= 2;
  35165. }
  35166. }
  35167. }
  35168. DecodeStream.prototype = {
  35169. get isEmpty() {
  35170. while (!this.eof && this.bufferLength === 0) {
  35171. this.readBlock();
  35172. }
  35173. return this.bufferLength === 0;
  35174. },
  35175. ensureBuffer: function DecodeStream_ensureBuffer(requested) {
  35176. var buffer = this.buffer;
  35177. if (requested <= buffer.byteLength) {
  35178. return buffer;
  35179. }
  35180. var size = this.minBufferLength;
  35181. while (size < requested) {
  35182. size *= 2;
  35183. }
  35184. var buffer2 = new Uint8Array(size);
  35185. buffer2.set(buffer);
  35186. return (this.buffer = buffer2);
  35187. },
  35188. getByte: function DecodeStream_getByte() {
  35189. var pos = this.pos;
  35190. while (this.bufferLength <= pos) {
  35191. if (this.eof) {
  35192. return -1;
  35193. }
  35194. this.readBlock();
  35195. }
  35196. return this.buffer[this.pos++];
  35197. },
  35198. getUint16: function DecodeStream_getUint16() {
  35199. var b0 = this.getByte();
  35200. var b1 = this.getByte();
  35201. if (b0 === -1 || b1 === -1) {
  35202. return -1;
  35203. }
  35204. return (b0 << 8) + b1;
  35205. },
  35206. getInt32: function DecodeStream_getInt32() {
  35207. var b0 = this.getByte();
  35208. var b1 = this.getByte();
  35209. var b2 = this.getByte();
  35210. var b3 = this.getByte();
  35211. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  35212. },
  35213. getBytes: function DecodeStream_getBytes(length) {
  35214. var end, pos = this.pos;
  35215. if (length) {
  35216. this.ensureBuffer(pos + length);
  35217. end = pos + length;
  35218. while (!this.eof && this.bufferLength < end) {
  35219. this.readBlock();
  35220. }
  35221. var bufEnd = this.bufferLength;
  35222. if (end > bufEnd) {
  35223. end = bufEnd;
  35224. }
  35225. } else {
  35226. while (!this.eof) {
  35227. this.readBlock();
  35228. }
  35229. end = this.bufferLength;
  35230. }
  35231. this.pos = end;
  35232. return this.buffer.subarray(pos, end);
  35233. },
  35234. peekByte: function DecodeStream_peekByte() {
  35235. var peekedByte = this.getByte();
  35236. this.pos--;
  35237. return peekedByte;
  35238. },
  35239. peekBytes: function DecodeStream_peekBytes(length) {
  35240. var bytes = this.getBytes(length);
  35241. this.pos -= bytes.length;
  35242. return bytes;
  35243. },
  35244. makeSubStream: function DecodeStream_makeSubStream(start, length, dict) {
  35245. var end = start + length;
  35246. while (this.bufferLength <= end && !this.eof) {
  35247. this.readBlock();
  35248. }
  35249. return new Stream(this.buffer, start, length, dict);
  35250. },
  35251. skip: function DecodeStream_skip(n) {
  35252. if (!n) {
  35253. n = 1;
  35254. }
  35255. this.pos += n;
  35256. },
  35257. reset: function DecodeStream_reset() {
  35258. this.pos = 0;
  35259. },
  35260. getBaseStreams: function DecodeStream_getBaseStreams() {
  35261. if (this.str && this.str.getBaseStreams) {
  35262. return this.str.getBaseStreams();
  35263. }
  35264. return [];
  35265. }
  35266. };
  35267. return DecodeStream;
  35268. })();
  35269. var StreamsSequenceStream = (function StreamsSequenceStreamClosure() {
  35270. function StreamsSequenceStream(streams) {
  35271. this.streams = streams;
  35272. DecodeStream.call(this, /* maybeLength = */ null);
  35273. }
  35274. StreamsSequenceStream.prototype = Object.create(DecodeStream.prototype);
  35275. StreamsSequenceStream.prototype.readBlock =
  35276. function streamSequenceStreamReadBlock() {
  35277. var streams = this.streams;
  35278. if (streams.length === 0) {
  35279. this.eof = true;
  35280. return;
  35281. }
  35282. var stream = streams.shift();
  35283. var chunk = stream.getBytes();
  35284. var bufferLength = this.bufferLength;
  35285. var newLength = bufferLength + chunk.length;
  35286. var buffer = this.ensureBuffer(newLength);
  35287. buffer.set(chunk, bufferLength);
  35288. this.bufferLength = newLength;
  35289. };
  35290. StreamsSequenceStream.prototype.getBaseStreams =
  35291. function StreamsSequenceStream_getBaseStreams() {
  35292. var baseStreams = [];
  35293. for (var i = 0, ii = this.streams.length; i < ii; i++) {
  35294. var stream = this.streams[i];
  35295. if (stream.getBaseStreams) {
  35296. Util.appendToArray(baseStreams, stream.getBaseStreams());
  35297. }
  35298. }
  35299. return baseStreams;
  35300. };
  35301. return StreamsSequenceStream;
  35302. })();
  35303. var FlateStream = (function FlateStreamClosure() {
  35304. var codeLenCodeMap = new Uint32Array([
  35305. 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15
  35306. ]);
  35307. var lengthDecode = new Uint32Array([
  35308. 0x00003, 0x00004, 0x00005, 0x00006, 0x00007, 0x00008, 0x00009, 0x0000a,
  35309. 0x1000b, 0x1000d, 0x1000f, 0x10011, 0x20013, 0x20017, 0x2001b, 0x2001f,
  35310. 0x30023, 0x3002b, 0x30033, 0x3003b, 0x40043, 0x40053, 0x40063, 0x40073,
  35311. 0x50083, 0x500a3, 0x500c3, 0x500e3, 0x00102, 0x00102, 0x00102
  35312. ]);
  35313. var distDecode = new Uint32Array([
  35314. 0x00001, 0x00002, 0x00003, 0x00004, 0x10005, 0x10007, 0x20009, 0x2000d,
  35315. 0x30011, 0x30019, 0x40021, 0x40031, 0x50041, 0x50061, 0x60081, 0x600c1,
  35316. 0x70101, 0x70181, 0x80201, 0x80301, 0x90401, 0x90601, 0xa0801, 0xa0c01,
  35317. 0xb1001, 0xb1801, 0xc2001, 0xc3001, 0xd4001, 0xd6001
  35318. ]);
  35319. var fixedLitCodeTab = [new Uint32Array([
  35320. 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c0,
  35321. 0x70108, 0x80060, 0x80020, 0x900a0, 0x80000, 0x80080, 0x80040, 0x900e0,
  35322. 0x70104, 0x80058, 0x80018, 0x90090, 0x70114, 0x80078, 0x80038, 0x900d0,
  35323. 0x7010c, 0x80068, 0x80028, 0x900b0, 0x80008, 0x80088, 0x80048, 0x900f0,
  35324. 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c8,
  35325. 0x7010a, 0x80064, 0x80024, 0x900a8, 0x80004, 0x80084, 0x80044, 0x900e8,
  35326. 0x70106, 0x8005c, 0x8001c, 0x90098, 0x70116, 0x8007c, 0x8003c, 0x900d8,
  35327. 0x7010e, 0x8006c, 0x8002c, 0x900b8, 0x8000c, 0x8008c, 0x8004c, 0x900f8,
  35328. 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c4,
  35329. 0x70109, 0x80062, 0x80022, 0x900a4, 0x80002, 0x80082, 0x80042, 0x900e4,
  35330. 0x70105, 0x8005a, 0x8001a, 0x90094, 0x70115, 0x8007a, 0x8003a, 0x900d4,
  35331. 0x7010d, 0x8006a, 0x8002a, 0x900b4, 0x8000a, 0x8008a, 0x8004a, 0x900f4,
  35332. 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cc,
  35333. 0x7010b, 0x80066, 0x80026, 0x900ac, 0x80006, 0x80086, 0x80046, 0x900ec,
  35334. 0x70107, 0x8005e, 0x8001e, 0x9009c, 0x70117, 0x8007e, 0x8003e, 0x900dc,
  35335. 0x7010f, 0x8006e, 0x8002e, 0x900bc, 0x8000e, 0x8008e, 0x8004e, 0x900fc,
  35336. 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c2,
  35337. 0x70108, 0x80061, 0x80021, 0x900a2, 0x80001, 0x80081, 0x80041, 0x900e2,
  35338. 0x70104, 0x80059, 0x80019, 0x90092, 0x70114, 0x80079, 0x80039, 0x900d2,
  35339. 0x7010c, 0x80069, 0x80029, 0x900b2, 0x80009, 0x80089, 0x80049, 0x900f2,
  35340. 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900ca,
  35341. 0x7010a, 0x80065, 0x80025, 0x900aa, 0x80005, 0x80085, 0x80045, 0x900ea,
  35342. 0x70106, 0x8005d, 0x8001d, 0x9009a, 0x70116, 0x8007d, 0x8003d, 0x900da,
  35343. 0x7010e, 0x8006d, 0x8002d, 0x900ba, 0x8000d, 0x8008d, 0x8004d, 0x900fa,
  35344. 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c6,
  35345. 0x70109, 0x80063, 0x80023, 0x900a6, 0x80003, 0x80083, 0x80043, 0x900e6,
  35346. 0x70105, 0x8005b, 0x8001b, 0x90096, 0x70115, 0x8007b, 0x8003b, 0x900d6,
  35347. 0x7010d, 0x8006b, 0x8002b, 0x900b6, 0x8000b, 0x8008b, 0x8004b, 0x900f6,
  35348. 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900ce,
  35349. 0x7010b, 0x80067, 0x80027, 0x900ae, 0x80007, 0x80087, 0x80047, 0x900ee,
  35350. 0x70107, 0x8005f, 0x8001f, 0x9009e, 0x70117, 0x8007f, 0x8003f, 0x900de,
  35351. 0x7010f, 0x8006f, 0x8002f, 0x900be, 0x8000f, 0x8008f, 0x8004f, 0x900fe,
  35352. 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c1,
  35353. 0x70108, 0x80060, 0x80020, 0x900a1, 0x80000, 0x80080, 0x80040, 0x900e1,
  35354. 0x70104, 0x80058, 0x80018, 0x90091, 0x70114, 0x80078, 0x80038, 0x900d1,
  35355. 0x7010c, 0x80068, 0x80028, 0x900b1, 0x80008, 0x80088, 0x80048, 0x900f1,
  35356. 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c9,
  35357. 0x7010a, 0x80064, 0x80024, 0x900a9, 0x80004, 0x80084, 0x80044, 0x900e9,
  35358. 0x70106, 0x8005c, 0x8001c, 0x90099, 0x70116, 0x8007c, 0x8003c, 0x900d9,
  35359. 0x7010e, 0x8006c, 0x8002c, 0x900b9, 0x8000c, 0x8008c, 0x8004c, 0x900f9,
  35360. 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c5,
  35361. 0x70109, 0x80062, 0x80022, 0x900a5, 0x80002, 0x80082, 0x80042, 0x900e5,
  35362. 0x70105, 0x8005a, 0x8001a, 0x90095, 0x70115, 0x8007a, 0x8003a, 0x900d5,
  35363. 0x7010d, 0x8006a, 0x8002a, 0x900b5, 0x8000a, 0x8008a, 0x8004a, 0x900f5,
  35364. 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cd,
  35365. 0x7010b, 0x80066, 0x80026, 0x900ad, 0x80006, 0x80086, 0x80046, 0x900ed,
  35366. 0x70107, 0x8005e, 0x8001e, 0x9009d, 0x70117, 0x8007e, 0x8003e, 0x900dd,
  35367. 0x7010f, 0x8006e, 0x8002e, 0x900bd, 0x8000e, 0x8008e, 0x8004e, 0x900fd,
  35368. 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c3,
  35369. 0x70108, 0x80061, 0x80021, 0x900a3, 0x80001, 0x80081, 0x80041, 0x900e3,
  35370. 0x70104, 0x80059, 0x80019, 0x90093, 0x70114, 0x80079, 0x80039, 0x900d3,
  35371. 0x7010c, 0x80069, 0x80029, 0x900b3, 0x80009, 0x80089, 0x80049, 0x900f3,
  35372. 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900cb,
  35373. 0x7010a, 0x80065, 0x80025, 0x900ab, 0x80005, 0x80085, 0x80045, 0x900eb,
  35374. 0x70106, 0x8005d, 0x8001d, 0x9009b, 0x70116, 0x8007d, 0x8003d, 0x900db,
  35375. 0x7010e, 0x8006d, 0x8002d, 0x900bb, 0x8000d, 0x8008d, 0x8004d, 0x900fb,
  35376. 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c7,
  35377. 0x70109, 0x80063, 0x80023, 0x900a7, 0x80003, 0x80083, 0x80043, 0x900e7,
  35378. 0x70105, 0x8005b, 0x8001b, 0x90097, 0x70115, 0x8007b, 0x8003b, 0x900d7,
  35379. 0x7010d, 0x8006b, 0x8002b, 0x900b7, 0x8000b, 0x8008b, 0x8004b, 0x900f7,
  35380. 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900cf,
  35381. 0x7010b, 0x80067, 0x80027, 0x900af, 0x80007, 0x80087, 0x80047, 0x900ef,
  35382. 0x70107, 0x8005f, 0x8001f, 0x9009f, 0x70117, 0x8007f, 0x8003f, 0x900df,
  35383. 0x7010f, 0x8006f, 0x8002f, 0x900bf, 0x8000f, 0x8008f, 0x8004f, 0x900ff
  35384. ]), 9];
  35385. var fixedDistCodeTab = [new Uint32Array([
  35386. 0x50000, 0x50010, 0x50008, 0x50018, 0x50004, 0x50014, 0x5000c, 0x5001c,
  35387. 0x50002, 0x50012, 0x5000a, 0x5001a, 0x50006, 0x50016, 0x5000e, 0x00000,
  35388. 0x50001, 0x50011, 0x50009, 0x50019, 0x50005, 0x50015, 0x5000d, 0x5001d,
  35389. 0x50003, 0x50013, 0x5000b, 0x5001b, 0x50007, 0x50017, 0x5000f, 0x00000
  35390. ]), 5];
  35391. function FlateStream(str, maybeLength) {
  35392. this.str = str;
  35393. this.dict = str.dict;
  35394. var cmf = str.getByte();
  35395. var flg = str.getByte();
  35396. if (cmf === -1 || flg === -1) {
  35397. error('Invalid header in flate stream: ' + cmf + ', ' + flg);
  35398. }
  35399. if ((cmf & 0x0f) !== 0x08) {
  35400. error('Unknown compression method in flate stream: ' + cmf + ', ' + flg);
  35401. }
  35402. if ((((cmf << 8) + flg) % 31) !== 0) {
  35403. error('Bad FCHECK in flate stream: ' + cmf + ', ' + flg);
  35404. }
  35405. if (flg & 0x20) {
  35406. error('FDICT bit set in flate stream: ' + cmf + ', ' + flg);
  35407. }
  35408. this.codeSize = 0;
  35409. this.codeBuf = 0;
  35410. DecodeStream.call(this, maybeLength);
  35411. }
  35412. FlateStream.prototype = Object.create(DecodeStream.prototype);
  35413. FlateStream.prototype.getBits = function FlateStream_getBits(bits) {
  35414. var str = this.str;
  35415. var codeSize = this.codeSize;
  35416. var codeBuf = this.codeBuf;
  35417. var b;
  35418. while (codeSize < bits) {
  35419. if ((b = str.getByte()) === -1) {
  35420. error('Bad encoding in flate stream');
  35421. }
  35422. codeBuf |= b << codeSize;
  35423. codeSize += 8;
  35424. }
  35425. b = codeBuf & ((1 << bits) - 1);
  35426. this.codeBuf = codeBuf >> bits;
  35427. this.codeSize = codeSize -= bits;
  35428. return b;
  35429. };
  35430. FlateStream.prototype.getCode = function FlateStream_getCode(table) {
  35431. var str = this.str;
  35432. var codes = table[0];
  35433. var maxLen = table[1];
  35434. var codeSize = this.codeSize;
  35435. var codeBuf = this.codeBuf;
  35436. var b;
  35437. while (codeSize < maxLen) {
  35438. if ((b = str.getByte()) === -1) {
  35439. // premature end of stream. code might however still be valid.
  35440. // codeSize < codeLen check below guards against incomplete codeVal.
  35441. break;
  35442. }
  35443. codeBuf |= (b << codeSize);
  35444. codeSize += 8;
  35445. }
  35446. var code = codes[codeBuf & ((1 << maxLen) - 1)];
  35447. var codeLen = code >> 16;
  35448. var codeVal = code & 0xffff;
  35449. if (codeLen < 1 || codeSize < codeLen) {
  35450. error('Bad encoding in flate stream');
  35451. }
  35452. this.codeBuf = (codeBuf >> codeLen);
  35453. this.codeSize = (codeSize - codeLen);
  35454. return codeVal;
  35455. };
  35456. FlateStream.prototype.generateHuffmanTable =
  35457. function flateStreamGenerateHuffmanTable(lengths) {
  35458. var n = lengths.length;
  35459. // find max code length
  35460. var maxLen = 0;
  35461. var i;
  35462. for (i = 0; i < n; ++i) {
  35463. if (lengths[i] > maxLen) {
  35464. maxLen = lengths[i];
  35465. }
  35466. }
  35467. // build the table
  35468. var size = 1 << maxLen;
  35469. var codes = new Uint32Array(size);
  35470. for (var len = 1, code = 0, skip = 2;
  35471. len <= maxLen;
  35472. ++len, code <<= 1, skip <<= 1) {
  35473. for (var val = 0; val < n; ++val) {
  35474. if (lengths[val] === len) {
  35475. // bit-reverse the code
  35476. var code2 = 0;
  35477. var t = code;
  35478. for (i = 0; i < len; ++i) {
  35479. code2 = (code2 << 1) | (t & 1);
  35480. t >>= 1;
  35481. }
  35482. // fill the table entries
  35483. for (i = code2; i < size; i += skip) {
  35484. codes[i] = (len << 16) | val;
  35485. }
  35486. ++code;
  35487. }
  35488. }
  35489. }
  35490. return [codes, maxLen];
  35491. };
  35492. FlateStream.prototype.readBlock = function FlateStream_readBlock() {
  35493. var buffer, len;
  35494. var str = this.str;
  35495. // read block header
  35496. var hdr = this.getBits(3);
  35497. if (hdr & 1) {
  35498. this.eof = true;
  35499. }
  35500. hdr >>= 1;
  35501. if (hdr === 0) { // uncompressed block
  35502. var b;
  35503. if ((b = str.getByte()) === -1) {
  35504. error('Bad block header in flate stream');
  35505. }
  35506. var blockLen = b;
  35507. if ((b = str.getByte()) === -1) {
  35508. error('Bad block header in flate stream');
  35509. }
  35510. blockLen |= (b << 8);
  35511. if ((b = str.getByte()) === -1) {
  35512. error('Bad block header in flate stream');
  35513. }
  35514. var check = b;
  35515. if ((b = str.getByte()) === -1) {
  35516. error('Bad block header in flate stream');
  35517. }
  35518. check |= (b << 8);
  35519. if (check !== (~blockLen & 0xffff) &&
  35520. (blockLen !== 0 || check !== 0)) {
  35521. // Ignoring error for bad "empty" block (see issue 1277)
  35522. error('Bad uncompressed block length in flate stream');
  35523. }
  35524. this.codeBuf = 0;
  35525. this.codeSize = 0;
  35526. var bufferLength = this.bufferLength;
  35527. buffer = this.ensureBuffer(bufferLength + blockLen);
  35528. var end = bufferLength + blockLen;
  35529. this.bufferLength = end;
  35530. if (blockLen === 0) {
  35531. if (str.peekByte() === -1) {
  35532. this.eof = true;
  35533. }
  35534. } else {
  35535. for (var n = bufferLength; n < end; ++n) {
  35536. if ((b = str.getByte()) === -1) {
  35537. this.eof = true;
  35538. break;
  35539. }
  35540. buffer[n] = b;
  35541. }
  35542. }
  35543. return;
  35544. }
  35545. var litCodeTable;
  35546. var distCodeTable;
  35547. if (hdr === 1) { // compressed block, fixed codes
  35548. litCodeTable = fixedLitCodeTab;
  35549. distCodeTable = fixedDistCodeTab;
  35550. } else if (hdr === 2) { // compressed block, dynamic codes
  35551. var numLitCodes = this.getBits(5) + 257;
  35552. var numDistCodes = this.getBits(5) + 1;
  35553. var numCodeLenCodes = this.getBits(4) + 4;
  35554. // build the code lengths code table
  35555. var codeLenCodeLengths = new Uint8Array(codeLenCodeMap.length);
  35556. var i;
  35557. for (i = 0; i < numCodeLenCodes; ++i) {
  35558. codeLenCodeLengths[codeLenCodeMap[i]] = this.getBits(3);
  35559. }
  35560. var codeLenCodeTab = this.generateHuffmanTable(codeLenCodeLengths);
  35561. // build the literal and distance code tables
  35562. len = 0;
  35563. i = 0;
  35564. var codes = numLitCodes + numDistCodes;
  35565. var codeLengths = new Uint8Array(codes);
  35566. var bitsLength, bitsOffset, what;
  35567. while (i < codes) {
  35568. var code = this.getCode(codeLenCodeTab);
  35569. if (code === 16) {
  35570. bitsLength = 2; bitsOffset = 3; what = len;
  35571. } else if (code === 17) {
  35572. bitsLength = 3; bitsOffset = 3; what = (len = 0);
  35573. } else if (code === 18) {
  35574. bitsLength = 7; bitsOffset = 11; what = (len = 0);
  35575. } else {
  35576. codeLengths[i++] = len = code;
  35577. continue;
  35578. }
  35579. var repeatLength = this.getBits(bitsLength) + bitsOffset;
  35580. while (repeatLength-- > 0) {
  35581. codeLengths[i++] = what;
  35582. }
  35583. }
  35584. litCodeTable =
  35585. this.generateHuffmanTable(codeLengths.subarray(0, numLitCodes));
  35586. distCodeTable =
  35587. this.generateHuffmanTable(codeLengths.subarray(numLitCodes, codes));
  35588. } else {
  35589. error('Unknown block type in flate stream');
  35590. }
  35591. buffer = this.buffer;
  35592. var limit = buffer ? buffer.length : 0;
  35593. var pos = this.bufferLength;
  35594. while (true) {
  35595. var code1 = this.getCode(litCodeTable);
  35596. if (code1 < 256) {
  35597. if (pos + 1 >= limit) {
  35598. buffer = this.ensureBuffer(pos + 1);
  35599. limit = buffer.length;
  35600. }
  35601. buffer[pos++] = code1;
  35602. continue;
  35603. }
  35604. if (code1 === 256) {
  35605. this.bufferLength = pos;
  35606. return;
  35607. }
  35608. code1 -= 257;
  35609. code1 = lengthDecode[code1];
  35610. var code2 = code1 >> 16;
  35611. if (code2 > 0) {
  35612. code2 = this.getBits(code2);
  35613. }
  35614. len = (code1 & 0xffff) + code2;
  35615. code1 = this.getCode(distCodeTable);
  35616. code1 = distDecode[code1];
  35617. code2 = code1 >> 16;
  35618. if (code2 > 0) {
  35619. code2 = this.getBits(code2);
  35620. }
  35621. var dist = (code1 & 0xffff) + code2;
  35622. if (pos + len >= limit) {
  35623. buffer = this.ensureBuffer(pos + len);
  35624. limit = buffer.length;
  35625. }
  35626. for (var k = 0; k < len; ++k, ++pos) {
  35627. buffer[pos] = buffer[pos - dist];
  35628. }
  35629. }
  35630. };
  35631. return FlateStream;
  35632. })();
  35633. var PredictorStream = (function PredictorStreamClosure() {
  35634. function PredictorStream(str, maybeLength, params) {
  35635. var predictor = this.predictor = params.get('Predictor') || 1;
  35636. if (predictor <= 1) {
  35637. return str; // no prediction
  35638. }
  35639. if (predictor !== 2 && (predictor < 10 || predictor > 15)) {
  35640. error('Unsupported predictor: ' + predictor);
  35641. }
  35642. if (predictor === 2) {
  35643. this.readBlock = this.readBlockTiff;
  35644. } else {
  35645. this.readBlock = this.readBlockPng;
  35646. }
  35647. this.str = str;
  35648. this.dict = str.dict;
  35649. var colors = this.colors = params.get('Colors') || 1;
  35650. var bits = this.bits = params.get('BitsPerComponent') || 8;
  35651. var columns = this.columns = params.get('Columns') || 1;
  35652. this.pixBytes = (colors * bits + 7) >> 3;
  35653. this.rowBytes = (columns * colors * bits + 7) >> 3;
  35654. DecodeStream.call(this, maybeLength);
  35655. return this;
  35656. }
  35657. PredictorStream.prototype = Object.create(DecodeStream.prototype);
  35658. PredictorStream.prototype.readBlockTiff =
  35659. function predictorStreamReadBlockTiff() {
  35660. var rowBytes = this.rowBytes;
  35661. var bufferLength = this.bufferLength;
  35662. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  35663. var bits = this.bits;
  35664. var colors = this.colors;
  35665. var rawBytes = this.str.getBytes(rowBytes);
  35666. this.eof = !rawBytes.length;
  35667. if (this.eof) {
  35668. return;
  35669. }
  35670. var inbuf = 0, outbuf = 0;
  35671. var inbits = 0, outbits = 0;
  35672. var pos = bufferLength;
  35673. var i;
  35674. if (bits === 1) {
  35675. for (i = 0; i < rowBytes; ++i) {
  35676. var c = rawBytes[i];
  35677. inbuf = (inbuf << 8) | c;
  35678. // bitwise addition is exclusive or
  35679. // first shift inbuf and then add
  35680. buffer[pos++] = (c ^ (inbuf >> colors)) & 0xFF;
  35681. // truncate inbuf (assumes colors < 16)
  35682. inbuf &= 0xFFFF;
  35683. }
  35684. } else if (bits === 8) {
  35685. for (i = 0; i < colors; ++i) {
  35686. buffer[pos++] = rawBytes[i];
  35687. }
  35688. for (; i < rowBytes; ++i) {
  35689. buffer[pos] = buffer[pos - colors] + rawBytes[i];
  35690. pos++;
  35691. }
  35692. } else {
  35693. var compArray = new Uint8Array(colors + 1);
  35694. var bitMask = (1 << bits) - 1;
  35695. var j = 0, k = bufferLength;
  35696. var columns = this.columns;
  35697. for (i = 0; i < columns; ++i) {
  35698. for (var kk = 0; kk < colors; ++kk) {
  35699. if (inbits < bits) {
  35700. inbuf = (inbuf << 8) | (rawBytes[j++] & 0xFF);
  35701. inbits += 8;
  35702. }
  35703. compArray[kk] = (compArray[kk] +
  35704. (inbuf >> (inbits - bits))) & bitMask;
  35705. inbits -= bits;
  35706. outbuf = (outbuf << bits) | compArray[kk];
  35707. outbits += bits;
  35708. if (outbits >= 8) {
  35709. buffer[k++] = (outbuf >> (outbits - 8)) & 0xFF;
  35710. outbits -= 8;
  35711. }
  35712. }
  35713. }
  35714. if (outbits > 0) {
  35715. buffer[k++] = (outbuf << (8 - outbits)) +
  35716. (inbuf & ((1 << (8 - outbits)) - 1));
  35717. }
  35718. }
  35719. this.bufferLength += rowBytes;
  35720. };
  35721. PredictorStream.prototype.readBlockPng =
  35722. function predictorStreamReadBlockPng() {
  35723. var rowBytes = this.rowBytes;
  35724. var pixBytes = this.pixBytes;
  35725. var predictor = this.str.getByte();
  35726. var rawBytes = this.str.getBytes(rowBytes);
  35727. this.eof = !rawBytes.length;
  35728. if (this.eof) {
  35729. return;
  35730. }
  35731. var bufferLength = this.bufferLength;
  35732. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  35733. var prevRow = buffer.subarray(bufferLength - rowBytes, bufferLength);
  35734. if (prevRow.length === 0) {
  35735. prevRow = new Uint8Array(rowBytes);
  35736. }
  35737. var i, j = bufferLength, up, c;
  35738. switch (predictor) {
  35739. case 0:
  35740. for (i = 0; i < rowBytes; ++i) {
  35741. buffer[j++] = rawBytes[i];
  35742. }
  35743. break;
  35744. case 1:
  35745. for (i = 0; i < pixBytes; ++i) {
  35746. buffer[j++] = rawBytes[i];
  35747. }
  35748. for (; i < rowBytes; ++i) {
  35749. buffer[j] = (buffer[j - pixBytes] + rawBytes[i]) & 0xFF;
  35750. j++;
  35751. }
  35752. break;
  35753. case 2:
  35754. for (i = 0; i < rowBytes; ++i) {
  35755. buffer[j++] = (prevRow[i] + rawBytes[i]) & 0xFF;
  35756. }
  35757. break;
  35758. case 3:
  35759. for (i = 0; i < pixBytes; ++i) {
  35760. buffer[j++] = (prevRow[i] >> 1) + rawBytes[i];
  35761. }
  35762. for (; i < rowBytes; ++i) {
  35763. buffer[j] = (((prevRow[i] + buffer[j - pixBytes]) >> 1) +
  35764. rawBytes[i]) & 0xFF;
  35765. j++;
  35766. }
  35767. break;
  35768. case 4:
  35769. // we need to save the up left pixels values. the simplest way
  35770. // is to create a new buffer
  35771. for (i = 0; i < pixBytes; ++i) {
  35772. up = prevRow[i];
  35773. c = rawBytes[i];
  35774. buffer[j++] = up + c;
  35775. }
  35776. for (; i < rowBytes; ++i) {
  35777. up = prevRow[i];
  35778. var upLeft = prevRow[i - pixBytes];
  35779. var left = buffer[j - pixBytes];
  35780. var p = left + up - upLeft;
  35781. var pa = p - left;
  35782. if (pa < 0) {
  35783. pa = -pa;
  35784. }
  35785. var pb = p - up;
  35786. if (pb < 0) {
  35787. pb = -pb;
  35788. }
  35789. var pc = p - upLeft;
  35790. if (pc < 0) {
  35791. pc = -pc;
  35792. }
  35793. c = rawBytes[i];
  35794. if (pa <= pb && pa <= pc) {
  35795. buffer[j++] = left + c;
  35796. } else if (pb <= pc) {
  35797. buffer[j++] = up + c;
  35798. } else {
  35799. buffer[j++] = upLeft + c;
  35800. }
  35801. }
  35802. break;
  35803. default:
  35804. error('Unsupported predictor: ' + predictor);
  35805. }
  35806. this.bufferLength += rowBytes;
  35807. };
  35808. return PredictorStream;
  35809. })();
  35810. /**
  35811. * Depending on the type of JPEG a JpegStream is handled in different ways. For
  35812. * JPEG's that are supported natively such as DeviceGray and DeviceRGB the image
  35813. * data is stored and then loaded by the browser. For unsupported JPEG's we use
  35814. * a library to decode these images and the stream behaves like all the other
  35815. * DecodeStreams.
  35816. */
  35817. var JpegStream = (function JpegStreamClosure() {
  35818. function JpegStream(stream, maybeLength, dict, xref) {
  35819. // Some images may contain 'junk' before the SOI (start-of-image) marker.
  35820. // Note: this seems to mainly affect inline images.
  35821. var ch;
  35822. while ((ch = stream.getByte()) !== -1) {
  35823. if (ch === 0xFF) { // Find the first byte of the SOI marker (0xFFD8).
  35824. stream.skip(-1); // Reset the stream position to the SOI.
  35825. break;
  35826. }
  35827. }
  35828. this.stream = stream;
  35829. this.maybeLength = maybeLength;
  35830. this.dict = dict;
  35831. DecodeStream.call(this, maybeLength);
  35832. }
  35833. JpegStream.prototype = Object.create(DecodeStream.prototype);
  35834. Object.defineProperty(JpegStream.prototype, 'bytes', {
  35835. get: function JpegStream_bytes() {
  35836. // If this.maybeLength is null, we'll get the entire stream.
  35837. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  35838. },
  35839. configurable: true
  35840. });
  35841. JpegStream.prototype.ensureBuffer = function JpegStream_ensureBuffer(req) {
  35842. if (this.bufferLength) {
  35843. return;
  35844. }
  35845. try {
  35846. var jpegImage = new JpegImage();
  35847. // checking if values needs to be transformed before conversion
  35848. if (this.forceRGB && this.dict && isArray(this.dict.get('Decode'))) {
  35849. var decodeArr = this.dict.get('Decode');
  35850. var bitsPerComponent = this.dict.get('BitsPerComponent') || 8;
  35851. var decodeArrLength = decodeArr.length;
  35852. var transform = new Int32Array(decodeArrLength);
  35853. var transformNeeded = false;
  35854. var maxValue = (1 << bitsPerComponent) - 1;
  35855. for (var i = 0; i < decodeArrLength; i += 2) {
  35856. transform[i] = ((decodeArr[i + 1] - decodeArr[i]) * 256) | 0;
  35857. transform[i + 1] = (decodeArr[i] * maxValue) | 0;
  35858. if (transform[i] !== 256 || transform[i + 1] !== 0) {
  35859. transformNeeded = true;
  35860. }
  35861. }
  35862. if (transformNeeded) {
  35863. jpegImage.decodeTransform = transform;
  35864. }
  35865. }
  35866. jpegImage.parse(this.bytes);
  35867. var data = jpegImage.getData(this.drawWidth, this.drawHeight,
  35868. this.forceRGB);
  35869. this.buffer = data;
  35870. this.bufferLength = data.length;
  35871. this.eof = true;
  35872. } catch (e) {
  35873. error('JPEG error: ' + e);
  35874. }
  35875. };
  35876. JpegStream.prototype.getBytes = function JpegStream_getBytes(length) {
  35877. this.ensureBuffer();
  35878. return this.buffer;
  35879. };
  35880. JpegStream.prototype.getIR = function JpegStream_getIR() {
  35881. return PDFJS.createObjectURL(this.bytes, 'image/jpeg');
  35882. };
  35883. /**
  35884. * Checks if the image can be decoded and displayed by the browser without any
  35885. * further processing such as color space conversions.
  35886. */
  35887. JpegStream.prototype.isNativelySupported =
  35888. function JpegStream_isNativelySupported(xref, res) {
  35889. var cs = ColorSpace.parse(this.dict.get('ColorSpace', 'CS'), xref, res);
  35890. return cs.name === 'DeviceGray' || cs.name === 'DeviceRGB';
  35891. };
  35892. /**
  35893. * Checks if the image can be decoded by the browser.
  35894. */
  35895. JpegStream.prototype.isNativelyDecodable =
  35896. function JpegStream_isNativelyDecodable(xref, res) {
  35897. var cs = ColorSpace.parse(this.dict.get('ColorSpace', 'CS'), xref, res);
  35898. var numComps = cs.numComps;
  35899. return numComps === 1 || numComps === 3;
  35900. };
  35901. return JpegStream;
  35902. })();
  35903. /**
  35904. * For JPEG 2000's we use a library to decode these images and
  35905. * the stream behaves like all the other DecodeStreams.
  35906. */
  35907. var JpxStream = (function JpxStreamClosure() {
  35908. function JpxStream(stream, maybeLength, dict) {
  35909. this.stream = stream;
  35910. this.maybeLength = maybeLength;
  35911. this.dict = dict;
  35912. DecodeStream.call(this, maybeLength);
  35913. }
  35914. JpxStream.prototype = Object.create(DecodeStream.prototype);
  35915. Object.defineProperty(JpxStream.prototype, 'bytes', {
  35916. get: function JpxStream_bytes() {
  35917. // If this.maybeLength is null, we'll get the entire stream.
  35918. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  35919. },
  35920. configurable: true
  35921. });
  35922. JpxStream.prototype.ensureBuffer = function JpxStream_ensureBuffer(req) {
  35923. if (this.bufferLength) {
  35924. return;
  35925. }
  35926. var jpxImage = new JpxImage();
  35927. jpxImage.parse(this.bytes);
  35928. var width = jpxImage.width;
  35929. var height = jpxImage.height;
  35930. var componentsCount = jpxImage.componentsCount;
  35931. var tileCount = jpxImage.tiles.length;
  35932. if (tileCount === 1) {
  35933. this.buffer = jpxImage.tiles[0].items;
  35934. } else {
  35935. var data = new Uint8Array(width * height * componentsCount);
  35936. for (var k = 0; k < tileCount; k++) {
  35937. var tileComponents = jpxImage.tiles[k];
  35938. var tileWidth = tileComponents.width;
  35939. var tileHeight = tileComponents.height;
  35940. var tileLeft = tileComponents.left;
  35941. var tileTop = tileComponents.top;
  35942. var src = tileComponents.items;
  35943. var srcPosition = 0;
  35944. var dataPosition = (width * tileTop + tileLeft) * componentsCount;
  35945. var imgRowSize = width * componentsCount;
  35946. var tileRowSize = tileWidth * componentsCount;
  35947. for (var j = 0; j < tileHeight; j++) {
  35948. var rowBytes = src.subarray(srcPosition, srcPosition + tileRowSize);
  35949. data.set(rowBytes, dataPosition);
  35950. srcPosition += tileRowSize;
  35951. dataPosition += imgRowSize;
  35952. }
  35953. }
  35954. this.buffer = data;
  35955. }
  35956. this.bufferLength = this.buffer.length;
  35957. this.eof = true;
  35958. };
  35959. return JpxStream;
  35960. })();
  35961. /**
  35962. * For JBIG2's we use a library to decode these images and
  35963. * the stream behaves like all the other DecodeStreams.
  35964. */
  35965. var Jbig2Stream = (function Jbig2StreamClosure() {
  35966. function Jbig2Stream(stream, maybeLength, dict) {
  35967. this.stream = stream;
  35968. this.maybeLength = maybeLength;
  35969. this.dict = dict;
  35970. DecodeStream.call(this, maybeLength);
  35971. }
  35972. Jbig2Stream.prototype = Object.create(DecodeStream.prototype);
  35973. Object.defineProperty(Jbig2Stream.prototype, 'bytes', {
  35974. get: function Jbig2Stream_bytes() {
  35975. // If this.maybeLength is null, we'll get the entire stream.
  35976. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  35977. },
  35978. configurable: true
  35979. });
  35980. Jbig2Stream.prototype.ensureBuffer = function Jbig2Stream_ensureBuffer(req) {
  35981. if (this.bufferLength) {
  35982. return;
  35983. }
  35984. var jbig2Image = new Jbig2Image();
  35985. var chunks = [], xref = this.dict.xref;
  35986. var decodeParams = xref.fetchIfRef(this.dict.get('DecodeParms'));
  35987. // According to the PDF specification, DecodeParms can be either
  35988. // a dictionary, or an array whose elements are dictionaries.
  35989. if (isArray(decodeParams)) {
  35990. if (decodeParams.length > 1) {
  35991. warn('JBIG2 - \'DecodeParms\' array with multiple elements ' +
  35992. 'not supported.');
  35993. }
  35994. decodeParams = xref.fetchIfRef(decodeParams[0]);
  35995. }
  35996. if (decodeParams && decodeParams.has('JBIG2Globals')) {
  35997. var globalsStream = decodeParams.get('JBIG2Globals');
  35998. var globals = globalsStream.getBytes();
  35999. chunks.push({data: globals, start: 0, end: globals.length});
  36000. }
  36001. chunks.push({data: this.bytes, start: 0, end: this.bytes.length});
  36002. var data = jbig2Image.parseChunks(chunks);
  36003. var dataLength = data.length;
  36004. // JBIG2 had black as 1 and white as 0, inverting the colors
  36005. for (var i = 0; i < dataLength; i++) {
  36006. data[i] ^= 0xFF;
  36007. }
  36008. this.buffer = data;
  36009. this.bufferLength = dataLength;
  36010. this.eof = true;
  36011. };
  36012. return Jbig2Stream;
  36013. })();
  36014. var DecryptStream = (function DecryptStreamClosure() {
  36015. function DecryptStream(str, maybeLength, decrypt) {
  36016. this.str = str;
  36017. this.dict = str.dict;
  36018. this.decrypt = decrypt;
  36019. this.nextChunk = null;
  36020. this.initialized = false;
  36021. DecodeStream.call(this, maybeLength);
  36022. }
  36023. var chunkSize = 512;
  36024. DecryptStream.prototype = Object.create(DecodeStream.prototype);
  36025. DecryptStream.prototype.readBlock = function DecryptStream_readBlock() {
  36026. var chunk;
  36027. if (this.initialized) {
  36028. chunk = this.nextChunk;
  36029. } else {
  36030. chunk = this.str.getBytes(chunkSize);
  36031. this.initialized = true;
  36032. }
  36033. if (!chunk || chunk.length === 0) {
  36034. this.eof = true;
  36035. return;
  36036. }
  36037. this.nextChunk = this.str.getBytes(chunkSize);
  36038. var hasMoreData = this.nextChunk && this.nextChunk.length > 0;
  36039. var decrypt = this.decrypt;
  36040. chunk = decrypt(chunk, !hasMoreData);
  36041. var bufferLength = this.bufferLength;
  36042. var i, n = chunk.length;
  36043. var buffer = this.ensureBuffer(bufferLength + n);
  36044. for (i = 0; i < n; i++) {
  36045. buffer[bufferLength++] = chunk[i];
  36046. }
  36047. this.bufferLength = bufferLength;
  36048. };
  36049. return DecryptStream;
  36050. })();
  36051. var Ascii85Stream = (function Ascii85StreamClosure() {
  36052. function Ascii85Stream(str, maybeLength) {
  36053. this.str = str;
  36054. this.dict = str.dict;
  36055. this.input = new Uint8Array(5);
  36056. // Most streams increase in size when decoded, but Ascii85 streams
  36057. // typically shrink by ~20%.
  36058. if (maybeLength) {
  36059. maybeLength = 0.8 * maybeLength;
  36060. }
  36061. DecodeStream.call(this, maybeLength);
  36062. }
  36063. Ascii85Stream.prototype = Object.create(DecodeStream.prototype);
  36064. Ascii85Stream.prototype.readBlock = function Ascii85Stream_readBlock() {
  36065. var TILDA_CHAR = 0x7E; // '~'
  36066. var Z_LOWER_CHAR = 0x7A; // 'z'
  36067. var EOF = -1;
  36068. var str = this.str;
  36069. var c = str.getByte();
  36070. while (Lexer.isSpace(c)) {
  36071. c = str.getByte();
  36072. }
  36073. if (c === EOF || c === TILDA_CHAR) {
  36074. this.eof = true;
  36075. return;
  36076. }
  36077. var bufferLength = this.bufferLength, buffer;
  36078. var i;
  36079. // special code for z
  36080. if (c === Z_LOWER_CHAR) {
  36081. buffer = this.ensureBuffer(bufferLength + 4);
  36082. for (i = 0; i < 4; ++i) {
  36083. buffer[bufferLength + i] = 0;
  36084. }
  36085. this.bufferLength += 4;
  36086. } else {
  36087. var input = this.input;
  36088. input[0] = c;
  36089. for (i = 1; i < 5; ++i) {
  36090. c = str.getByte();
  36091. while (Lexer.isSpace(c)) {
  36092. c = str.getByte();
  36093. }
  36094. input[i] = c;
  36095. if (c === EOF || c === TILDA_CHAR) {
  36096. break;
  36097. }
  36098. }
  36099. buffer = this.ensureBuffer(bufferLength + i - 1);
  36100. this.bufferLength += i - 1;
  36101. // partial ending;
  36102. if (i < 5) {
  36103. for (; i < 5; ++i) {
  36104. input[i] = 0x21 + 84;
  36105. }
  36106. this.eof = true;
  36107. }
  36108. var t = 0;
  36109. for (i = 0; i < 5; ++i) {
  36110. t = t * 85 + (input[i] - 0x21);
  36111. }
  36112. for (i = 3; i >= 0; --i) {
  36113. buffer[bufferLength + i] = t & 0xFF;
  36114. t >>= 8;
  36115. }
  36116. }
  36117. };
  36118. return Ascii85Stream;
  36119. })();
  36120. var AsciiHexStream = (function AsciiHexStreamClosure() {
  36121. function AsciiHexStream(str, maybeLength) {
  36122. this.str = str;
  36123. this.dict = str.dict;
  36124. this.firstDigit = -1;
  36125. // Most streams increase in size when decoded, but AsciiHex streams shrink
  36126. // by 50%.
  36127. if (maybeLength) {
  36128. maybeLength = 0.5 * maybeLength;
  36129. }
  36130. DecodeStream.call(this, maybeLength);
  36131. }
  36132. AsciiHexStream.prototype = Object.create(DecodeStream.prototype);
  36133. AsciiHexStream.prototype.readBlock = function AsciiHexStream_readBlock() {
  36134. var UPSTREAM_BLOCK_SIZE = 8000;
  36135. var bytes = this.str.getBytes(UPSTREAM_BLOCK_SIZE);
  36136. if (!bytes.length) {
  36137. this.eof = true;
  36138. return;
  36139. }
  36140. var maxDecodeLength = (bytes.length + 1) >> 1;
  36141. var buffer = this.ensureBuffer(this.bufferLength + maxDecodeLength);
  36142. var bufferLength = this.bufferLength;
  36143. var firstDigit = this.firstDigit;
  36144. for (var i = 0, ii = bytes.length; i < ii; i++) {
  36145. var ch = bytes[i], digit;
  36146. if (ch >= 0x30 && ch <= 0x39) { // '0'-'9'
  36147. digit = ch & 0x0F;
  36148. } else if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
  36149. // 'A'-'Z', 'a'-'z'
  36150. digit = (ch & 0x0F) + 9;
  36151. } else if (ch === 0x3E) { // '>'
  36152. this.eof = true;
  36153. break;
  36154. } else { // probably whitespace
  36155. continue; // ignoring
  36156. }
  36157. if (firstDigit < 0) {
  36158. firstDigit = digit;
  36159. } else {
  36160. buffer[bufferLength++] = (firstDigit << 4) | digit;
  36161. firstDigit = -1;
  36162. }
  36163. }
  36164. if (firstDigit >= 0 && this.eof) {
  36165. // incomplete byte
  36166. buffer[bufferLength++] = (firstDigit << 4);
  36167. firstDigit = -1;
  36168. }
  36169. this.firstDigit = firstDigit;
  36170. this.bufferLength = bufferLength;
  36171. };
  36172. return AsciiHexStream;
  36173. })();
  36174. var RunLengthStream = (function RunLengthStreamClosure() {
  36175. function RunLengthStream(str, maybeLength) {
  36176. this.str = str;
  36177. this.dict = str.dict;
  36178. DecodeStream.call(this, maybeLength);
  36179. }
  36180. RunLengthStream.prototype = Object.create(DecodeStream.prototype);
  36181. RunLengthStream.prototype.readBlock = function RunLengthStream_readBlock() {
  36182. // The repeatHeader has following format. The first byte defines type of run
  36183. // and amount of bytes to repeat/copy: n = 0 through 127 - copy next n bytes
  36184. // (in addition to the second byte from the header), n = 129 through 255 -
  36185. // duplicate the second byte from the header (257 - n) times, n = 128 - end.
  36186. var repeatHeader = this.str.getBytes(2);
  36187. if (!repeatHeader || repeatHeader.length < 2 || repeatHeader[0] === 128) {
  36188. this.eof = true;
  36189. return;
  36190. }
  36191. var buffer;
  36192. var bufferLength = this.bufferLength;
  36193. var n = repeatHeader[0];
  36194. if (n < 128) {
  36195. // copy n bytes
  36196. buffer = this.ensureBuffer(bufferLength + n + 1);
  36197. buffer[bufferLength++] = repeatHeader[1];
  36198. if (n > 0) {
  36199. var source = this.str.getBytes(n);
  36200. buffer.set(source, bufferLength);
  36201. bufferLength += n;
  36202. }
  36203. } else {
  36204. n = 257 - n;
  36205. var b = repeatHeader[1];
  36206. buffer = this.ensureBuffer(bufferLength + n + 1);
  36207. for (var i = 0; i < n; i++) {
  36208. buffer[bufferLength++] = b;
  36209. }
  36210. }
  36211. this.bufferLength = bufferLength;
  36212. };
  36213. return RunLengthStream;
  36214. })();
  36215. var CCITTFaxStream = (function CCITTFaxStreamClosure() {
  36216. var ccittEOL = -2;
  36217. var twoDimPass = 0;
  36218. var twoDimHoriz = 1;
  36219. var twoDimVert0 = 2;
  36220. var twoDimVertR1 = 3;
  36221. var twoDimVertL1 = 4;
  36222. var twoDimVertR2 = 5;
  36223. var twoDimVertL2 = 6;
  36224. var twoDimVertR3 = 7;
  36225. var twoDimVertL3 = 8;
  36226. var twoDimTable = [
  36227. [-1, -1], [-1, -1], // 000000x
  36228. [7, twoDimVertL3], // 0000010
  36229. [7, twoDimVertR3], // 0000011
  36230. [6, twoDimVertL2], [6, twoDimVertL2], // 000010x
  36231. [6, twoDimVertR2], [6, twoDimVertR2], // 000011x
  36232. [4, twoDimPass], [4, twoDimPass], // 0001xxx
  36233. [4, twoDimPass], [4, twoDimPass],
  36234. [4, twoDimPass], [4, twoDimPass],
  36235. [4, twoDimPass], [4, twoDimPass],
  36236. [3, twoDimHoriz], [3, twoDimHoriz], // 001xxxx
  36237. [3, twoDimHoriz], [3, twoDimHoriz],
  36238. [3, twoDimHoriz], [3, twoDimHoriz],
  36239. [3, twoDimHoriz], [3, twoDimHoriz],
  36240. [3, twoDimHoriz], [3, twoDimHoriz],
  36241. [3, twoDimHoriz], [3, twoDimHoriz],
  36242. [3, twoDimHoriz], [3, twoDimHoriz],
  36243. [3, twoDimHoriz], [3, twoDimHoriz],
  36244. [3, twoDimVertL1], [3, twoDimVertL1], // 010xxxx
  36245. [3, twoDimVertL1], [3, twoDimVertL1],
  36246. [3, twoDimVertL1], [3, twoDimVertL1],
  36247. [3, twoDimVertL1], [3, twoDimVertL1],
  36248. [3, twoDimVertL1], [3, twoDimVertL1],
  36249. [3, twoDimVertL1], [3, twoDimVertL1],
  36250. [3, twoDimVertL1], [3, twoDimVertL1],
  36251. [3, twoDimVertL1], [3, twoDimVertL1],
  36252. [3, twoDimVertR1], [3, twoDimVertR1], // 011xxxx
  36253. [3, twoDimVertR1], [3, twoDimVertR1],
  36254. [3, twoDimVertR1], [3, twoDimVertR1],
  36255. [3, twoDimVertR1], [3, twoDimVertR1],
  36256. [3, twoDimVertR1], [3, twoDimVertR1],
  36257. [3, twoDimVertR1], [3, twoDimVertR1],
  36258. [3, twoDimVertR1], [3, twoDimVertR1],
  36259. [3, twoDimVertR1], [3, twoDimVertR1],
  36260. [1, twoDimVert0], [1, twoDimVert0], // 1xxxxxx
  36261. [1, twoDimVert0], [1, twoDimVert0],
  36262. [1, twoDimVert0], [1, twoDimVert0],
  36263. [1, twoDimVert0], [1, twoDimVert0],
  36264. [1, twoDimVert0], [1, twoDimVert0],
  36265. [1, twoDimVert0], [1, twoDimVert0],
  36266. [1, twoDimVert0], [1, twoDimVert0],
  36267. [1, twoDimVert0], [1, twoDimVert0],
  36268. [1, twoDimVert0], [1, twoDimVert0],
  36269. [1, twoDimVert0], [1, twoDimVert0],
  36270. [1, twoDimVert0], [1, twoDimVert0],
  36271. [1, twoDimVert0], [1, twoDimVert0],
  36272. [1, twoDimVert0], [1, twoDimVert0],
  36273. [1, twoDimVert0], [1, twoDimVert0],
  36274. [1, twoDimVert0], [1, twoDimVert0],
  36275. [1, twoDimVert0], [1, twoDimVert0],
  36276. [1, twoDimVert0], [1, twoDimVert0],
  36277. [1, twoDimVert0], [1, twoDimVert0],
  36278. [1, twoDimVert0], [1, twoDimVert0],
  36279. [1, twoDimVert0], [1, twoDimVert0],
  36280. [1, twoDimVert0], [1, twoDimVert0],
  36281. [1, twoDimVert0], [1, twoDimVert0],
  36282. [1, twoDimVert0], [1, twoDimVert0],
  36283. [1, twoDimVert0], [1, twoDimVert0],
  36284. [1, twoDimVert0], [1, twoDimVert0],
  36285. [1, twoDimVert0], [1, twoDimVert0],
  36286. [1, twoDimVert0], [1, twoDimVert0],
  36287. [1, twoDimVert0], [1, twoDimVert0],
  36288. [1, twoDimVert0], [1, twoDimVert0],
  36289. [1, twoDimVert0], [1, twoDimVert0],
  36290. [1, twoDimVert0], [1, twoDimVert0],
  36291. [1, twoDimVert0], [1, twoDimVert0]
  36292. ];
  36293. var whiteTable1 = [
  36294. [-1, -1], // 00000
  36295. [12, ccittEOL], // 00001
  36296. [-1, -1], [-1, -1], // 0001x
  36297. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 001xx
  36298. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 010xx
  36299. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 011xx
  36300. [11, 1792], [11, 1792], // 1000x
  36301. [12, 1984], // 10010
  36302. [12, 2048], // 10011
  36303. [12, 2112], // 10100
  36304. [12, 2176], // 10101
  36305. [12, 2240], // 10110
  36306. [12, 2304], // 10111
  36307. [11, 1856], [11, 1856], // 1100x
  36308. [11, 1920], [11, 1920], // 1101x
  36309. [12, 2368], // 11100
  36310. [12, 2432], // 11101
  36311. [12, 2496], // 11110
  36312. [12, 2560] // 11111
  36313. ];
  36314. var whiteTable2 = [
  36315. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000000xx
  36316. [8, 29], [8, 29], // 00000010x
  36317. [8, 30], [8, 30], // 00000011x
  36318. [8, 45], [8, 45], // 00000100x
  36319. [8, 46], [8, 46], // 00000101x
  36320. [7, 22], [7, 22], [7, 22], [7, 22], // 0000011xx
  36321. [7, 23], [7, 23], [7, 23], [7, 23], // 0000100xx
  36322. [8, 47], [8, 47], // 00001010x
  36323. [8, 48], [8, 48], // 00001011x
  36324. [6, 13], [6, 13], [6, 13], [6, 13], // 000011xxx
  36325. [6, 13], [6, 13], [6, 13], [6, 13],
  36326. [7, 20], [7, 20], [7, 20], [7, 20], // 0001000xx
  36327. [8, 33], [8, 33], // 00010010x
  36328. [8, 34], [8, 34], // 00010011x
  36329. [8, 35], [8, 35], // 00010100x
  36330. [8, 36], [8, 36], // 00010101x
  36331. [8, 37], [8, 37], // 00010110x
  36332. [8, 38], [8, 38], // 00010111x
  36333. [7, 19], [7, 19], [7, 19], [7, 19], // 0001100xx
  36334. [8, 31], [8, 31], // 00011010x
  36335. [8, 32], [8, 32], // 00011011x
  36336. [6, 1], [6, 1], [6, 1], [6, 1], // 000111xxx
  36337. [6, 1], [6, 1], [6, 1], [6, 1],
  36338. [6, 12], [6, 12], [6, 12], [6, 12], // 001000xxx
  36339. [6, 12], [6, 12], [6, 12], [6, 12],
  36340. [8, 53], [8, 53], // 00100100x
  36341. [8, 54], [8, 54], // 00100101x
  36342. [7, 26], [7, 26], [7, 26], [7, 26], // 0010011xx
  36343. [8, 39], [8, 39], // 00101000x
  36344. [8, 40], [8, 40], // 00101001x
  36345. [8, 41], [8, 41], // 00101010x
  36346. [8, 42], [8, 42], // 00101011x
  36347. [8, 43], [8, 43], // 00101100x
  36348. [8, 44], [8, 44], // 00101101x
  36349. [7, 21], [7, 21], [7, 21], [7, 21], // 0010111xx
  36350. [7, 28], [7, 28], [7, 28], [7, 28], // 0011000xx
  36351. [8, 61], [8, 61], // 00110010x
  36352. [8, 62], [8, 62], // 00110011x
  36353. [8, 63], [8, 63], // 00110100x
  36354. [8, 0], [8, 0], // 00110101x
  36355. [8, 320], [8, 320], // 00110110x
  36356. [8, 384], [8, 384], // 00110111x
  36357. [5, 10], [5, 10], [5, 10], [5, 10], // 00111xxxx
  36358. [5, 10], [5, 10], [5, 10], [5, 10],
  36359. [5, 10], [5, 10], [5, 10], [5, 10],
  36360. [5, 10], [5, 10], [5, 10], [5, 10],
  36361. [5, 11], [5, 11], [5, 11], [5, 11], // 01000xxxx
  36362. [5, 11], [5, 11], [5, 11], [5, 11],
  36363. [5, 11], [5, 11], [5, 11], [5, 11],
  36364. [5, 11], [5, 11], [5, 11], [5, 11],
  36365. [7, 27], [7, 27], [7, 27], [7, 27], // 0100100xx
  36366. [8, 59], [8, 59], // 01001010x
  36367. [8, 60], [8, 60], // 01001011x
  36368. [9, 1472], // 010011000
  36369. [9, 1536], // 010011001
  36370. [9, 1600], // 010011010
  36371. [9, 1728], // 010011011
  36372. [7, 18], [7, 18], [7, 18], [7, 18], // 0100111xx
  36373. [7, 24], [7, 24], [7, 24], [7, 24], // 0101000xx
  36374. [8, 49], [8, 49], // 01010010x
  36375. [8, 50], [8, 50], // 01010011x
  36376. [8, 51], [8, 51], // 01010100x
  36377. [8, 52], [8, 52], // 01010101x
  36378. [7, 25], [7, 25], [7, 25], [7, 25], // 0101011xx
  36379. [8, 55], [8, 55], // 01011000x
  36380. [8, 56], [8, 56], // 01011001x
  36381. [8, 57], [8, 57], // 01011010x
  36382. [8, 58], [8, 58], // 01011011x
  36383. [6, 192], [6, 192], [6, 192], [6, 192], // 010111xxx
  36384. [6, 192], [6, 192], [6, 192], [6, 192],
  36385. [6, 1664], [6, 1664], [6, 1664], [6, 1664], // 011000xxx
  36386. [6, 1664], [6, 1664], [6, 1664], [6, 1664],
  36387. [8, 448], [8, 448], // 01100100x
  36388. [8, 512], [8, 512], // 01100101x
  36389. [9, 704], // 011001100
  36390. [9, 768], // 011001101
  36391. [8, 640], [8, 640], // 01100111x
  36392. [8, 576], [8, 576], // 01101000x
  36393. [9, 832], // 011010010
  36394. [9, 896], // 011010011
  36395. [9, 960], // 011010100
  36396. [9, 1024], // 011010101
  36397. [9, 1088], // 011010110
  36398. [9, 1152], // 011010111
  36399. [9, 1216], // 011011000
  36400. [9, 1280], // 011011001
  36401. [9, 1344], // 011011010
  36402. [9, 1408], // 011011011
  36403. [7, 256], [7, 256], [7, 256], [7, 256], // 0110111xx
  36404. [4, 2], [4, 2], [4, 2], [4, 2], // 0111xxxxx
  36405. [4, 2], [4, 2], [4, 2], [4, 2],
  36406. [4, 2], [4, 2], [4, 2], [4, 2],
  36407. [4, 2], [4, 2], [4, 2], [4, 2],
  36408. [4, 2], [4, 2], [4, 2], [4, 2],
  36409. [4, 2], [4, 2], [4, 2], [4, 2],
  36410. [4, 2], [4, 2], [4, 2], [4, 2],
  36411. [4, 2], [4, 2], [4, 2], [4, 2],
  36412. [4, 3], [4, 3], [4, 3], [4, 3], // 1000xxxxx
  36413. [4, 3], [4, 3], [4, 3], [4, 3],
  36414. [4, 3], [4, 3], [4, 3], [4, 3],
  36415. [4, 3], [4, 3], [4, 3], [4, 3],
  36416. [4, 3], [4, 3], [4, 3], [4, 3],
  36417. [4, 3], [4, 3], [4, 3], [4, 3],
  36418. [4, 3], [4, 3], [4, 3], [4, 3],
  36419. [4, 3], [4, 3], [4, 3], [4, 3],
  36420. [5, 128], [5, 128], [5, 128], [5, 128], // 10010xxxx
  36421. [5, 128], [5, 128], [5, 128], [5, 128],
  36422. [5, 128], [5, 128], [5, 128], [5, 128],
  36423. [5, 128], [5, 128], [5, 128], [5, 128],
  36424. [5, 8], [5, 8], [5, 8], [5, 8], // 10011xxxx
  36425. [5, 8], [5, 8], [5, 8], [5, 8],
  36426. [5, 8], [5, 8], [5, 8], [5, 8],
  36427. [5, 8], [5, 8], [5, 8], [5, 8],
  36428. [5, 9], [5, 9], [5, 9], [5, 9], // 10100xxxx
  36429. [5, 9], [5, 9], [5, 9], [5, 9],
  36430. [5, 9], [5, 9], [5, 9], [5, 9],
  36431. [5, 9], [5, 9], [5, 9], [5, 9],
  36432. [6, 16], [6, 16], [6, 16], [6, 16], // 101010xxx
  36433. [6, 16], [6, 16], [6, 16], [6, 16],
  36434. [6, 17], [6, 17], [6, 17], [6, 17], // 101011xxx
  36435. [6, 17], [6, 17], [6, 17], [6, 17],
  36436. [4, 4], [4, 4], [4, 4], [4, 4], // 1011xxxxx
  36437. [4, 4], [4, 4], [4, 4], [4, 4],
  36438. [4, 4], [4, 4], [4, 4], [4, 4],
  36439. [4, 4], [4, 4], [4, 4], [4, 4],
  36440. [4, 4], [4, 4], [4, 4], [4, 4],
  36441. [4, 4], [4, 4], [4, 4], [4, 4],
  36442. [4, 4], [4, 4], [4, 4], [4, 4],
  36443. [4, 4], [4, 4], [4, 4], [4, 4],
  36444. [4, 5], [4, 5], [4, 5], [4, 5], // 1100xxxxx
  36445. [4, 5], [4, 5], [4, 5], [4, 5],
  36446. [4, 5], [4, 5], [4, 5], [4, 5],
  36447. [4, 5], [4, 5], [4, 5], [4, 5],
  36448. [4, 5], [4, 5], [4, 5], [4, 5],
  36449. [4, 5], [4, 5], [4, 5], [4, 5],
  36450. [4, 5], [4, 5], [4, 5], [4, 5],
  36451. [4, 5], [4, 5], [4, 5], [4, 5],
  36452. [6, 14], [6, 14], [6, 14], [6, 14], // 110100xxx
  36453. [6, 14], [6, 14], [6, 14], [6, 14],
  36454. [6, 15], [6, 15], [6, 15], [6, 15], // 110101xxx
  36455. [6, 15], [6, 15], [6, 15], [6, 15],
  36456. [5, 64], [5, 64], [5, 64], [5, 64], // 11011xxxx
  36457. [5, 64], [5, 64], [5, 64], [5, 64],
  36458. [5, 64], [5, 64], [5, 64], [5, 64],
  36459. [5, 64], [5, 64], [5, 64], [5, 64],
  36460. [4, 6], [4, 6], [4, 6], [4, 6], // 1110xxxxx
  36461. [4, 6], [4, 6], [4, 6], [4, 6],
  36462. [4, 6], [4, 6], [4, 6], [4, 6],
  36463. [4, 6], [4, 6], [4, 6], [4, 6],
  36464. [4, 6], [4, 6], [4, 6], [4, 6],
  36465. [4, 6], [4, 6], [4, 6], [4, 6],
  36466. [4, 6], [4, 6], [4, 6], [4, 6],
  36467. [4, 6], [4, 6], [4, 6], [4, 6],
  36468. [4, 7], [4, 7], [4, 7], [4, 7], // 1111xxxxx
  36469. [4, 7], [4, 7], [4, 7], [4, 7],
  36470. [4, 7], [4, 7], [4, 7], [4, 7],
  36471. [4, 7], [4, 7], [4, 7], [4, 7],
  36472. [4, 7], [4, 7], [4, 7], [4, 7],
  36473. [4, 7], [4, 7], [4, 7], [4, 7],
  36474. [4, 7], [4, 7], [4, 7], [4, 7],
  36475. [4, 7], [4, 7], [4, 7], [4, 7]
  36476. ];
  36477. var blackTable1 = [
  36478. [-1, -1], [-1, -1], // 000000000000x
  36479. [12, ccittEOL], [12, ccittEOL], // 000000000001x
  36480. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000001xx
  36481. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000010xx
  36482. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000011xx
  36483. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000100xx
  36484. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000101xx
  36485. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000110xx
  36486. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000111xx
  36487. [11, 1792], [11, 1792], [11, 1792], [11, 1792], // 00000001000xx
  36488. [12, 1984], [12, 1984], // 000000010010x
  36489. [12, 2048], [12, 2048], // 000000010011x
  36490. [12, 2112], [12, 2112], // 000000010100x
  36491. [12, 2176], [12, 2176], // 000000010101x
  36492. [12, 2240], [12, 2240], // 000000010110x
  36493. [12, 2304], [12, 2304], // 000000010111x
  36494. [11, 1856], [11, 1856], [11, 1856], [11, 1856], // 00000001100xx
  36495. [11, 1920], [11, 1920], [11, 1920], [11, 1920], // 00000001101xx
  36496. [12, 2368], [12, 2368], // 000000011100x
  36497. [12, 2432], [12, 2432], // 000000011101x
  36498. [12, 2496], [12, 2496], // 000000011110x
  36499. [12, 2560], [12, 2560], // 000000011111x
  36500. [10, 18], [10, 18], [10, 18], [10, 18], // 0000001000xxx
  36501. [10, 18], [10, 18], [10, 18], [10, 18],
  36502. [12, 52], [12, 52], // 000000100100x
  36503. [13, 640], // 0000001001010
  36504. [13, 704], // 0000001001011
  36505. [13, 768], // 0000001001100
  36506. [13, 832], // 0000001001101
  36507. [12, 55], [12, 55], // 000000100111x
  36508. [12, 56], [12, 56], // 000000101000x
  36509. [13, 1280], // 0000001010010
  36510. [13, 1344], // 0000001010011
  36511. [13, 1408], // 0000001010100
  36512. [13, 1472], // 0000001010101
  36513. [12, 59], [12, 59], // 000000101011x
  36514. [12, 60], [12, 60], // 000000101100x
  36515. [13, 1536], // 0000001011010
  36516. [13, 1600], // 0000001011011
  36517. [11, 24], [11, 24], [11, 24], [11, 24], // 00000010111xx
  36518. [11, 25], [11, 25], [11, 25], [11, 25], // 00000011000xx
  36519. [13, 1664], // 0000001100100
  36520. [13, 1728], // 0000001100101
  36521. [12, 320], [12, 320], // 000000110011x
  36522. [12, 384], [12, 384], // 000000110100x
  36523. [12, 448], [12, 448], // 000000110101x
  36524. [13, 512], // 0000001101100
  36525. [13, 576], // 0000001101101
  36526. [12, 53], [12, 53], // 000000110111x
  36527. [12, 54], [12, 54], // 000000111000x
  36528. [13, 896], // 0000001110010
  36529. [13, 960], // 0000001110011
  36530. [13, 1024], // 0000001110100
  36531. [13, 1088], // 0000001110101
  36532. [13, 1152], // 0000001110110
  36533. [13, 1216], // 0000001110111
  36534. [10, 64], [10, 64], [10, 64], [10, 64], // 0000001111xxx
  36535. [10, 64], [10, 64], [10, 64], [10, 64]
  36536. ];
  36537. var blackTable2 = [
  36538. [8, 13], [8, 13], [8, 13], [8, 13], // 00000100xxxx
  36539. [8, 13], [8, 13], [8, 13], [8, 13],
  36540. [8, 13], [8, 13], [8, 13], [8, 13],
  36541. [8, 13], [8, 13], [8, 13], [8, 13],
  36542. [11, 23], [11, 23], // 00000101000x
  36543. [12, 50], // 000001010010
  36544. [12, 51], // 000001010011
  36545. [12, 44], // 000001010100
  36546. [12, 45], // 000001010101
  36547. [12, 46], // 000001010110
  36548. [12, 47], // 000001010111
  36549. [12, 57], // 000001011000
  36550. [12, 58], // 000001011001
  36551. [12, 61], // 000001011010
  36552. [12, 256], // 000001011011
  36553. [10, 16], [10, 16], [10, 16], [10, 16], // 0000010111xx
  36554. [10, 17], [10, 17], [10, 17], [10, 17], // 0000011000xx
  36555. [12, 48], // 000001100100
  36556. [12, 49], // 000001100101
  36557. [12, 62], // 000001100110
  36558. [12, 63], // 000001100111
  36559. [12, 30], // 000001101000
  36560. [12, 31], // 000001101001
  36561. [12, 32], // 000001101010
  36562. [12, 33], // 000001101011
  36563. [12, 40], // 000001101100
  36564. [12, 41], // 000001101101
  36565. [11, 22], [11, 22], // 00000110111x
  36566. [8, 14], [8, 14], [8, 14], [8, 14], // 00000111xxxx
  36567. [8, 14], [8, 14], [8, 14], [8, 14],
  36568. [8, 14], [8, 14], [8, 14], [8, 14],
  36569. [8, 14], [8, 14], [8, 14], [8, 14],
  36570. [7, 10], [7, 10], [7, 10], [7, 10], // 0000100xxxxx
  36571. [7, 10], [7, 10], [7, 10], [7, 10],
  36572. [7, 10], [7, 10], [7, 10], [7, 10],
  36573. [7, 10], [7, 10], [7, 10], [7, 10],
  36574. [7, 10], [7, 10], [7, 10], [7, 10],
  36575. [7, 10], [7, 10], [7, 10], [7, 10],
  36576. [7, 10], [7, 10], [7, 10], [7, 10],
  36577. [7, 10], [7, 10], [7, 10], [7, 10],
  36578. [7, 11], [7, 11], [7, 11], [7, 11], // 0000101xxxxx
  36579. [7, 11], [7, 11], [7, 11], [7, 11],
  36580. [7, 11], [7, 11], [7, 11], [7, 11],
  36581. [7, 11], [7, 11], [7, 11], [7, 11],
  36582. [7, 11], [7, 11], [7, 11], [7, 11],
  36583. [7, 11], [7, 11], [7, 11], [7, 11],
  36584. [7, 11], [7, 11], [7, 11], [7, 11],
  36585. [7, 11], [7, 11], [7, 11], [7, 11],
  36586. [9, 15], [9, 15], [9, 15], [9, 15], // 000011000xxx
  36587. [9, 15], [9, 15], [9, 15], [9, 15],
  36588. [12, 128], // 000011001000
  36589. [12, 192], // 000011001001
  36590. [12, 26], // 000011001010
  36591. [12, 27], // 000011001011
  36592. [12, 28], // 000011001100
  36593. [12, 29], // 000011001101
  36594. [11, 19], [11, 19], // 00001100111x
  36595. [11, 20], [11, 20], // 00001101000x
  36596. [12, 34], // 000011010010
  36597. [12, 35], // 000011010011
  36598. [12, 36], // 000011010100
  36599. [12, 37], // 000011010101
  36600. [12, 38], // 000011010110
  36601. [12, 39], // 000011010111
  36602. [11, 21], [11, 21], // 00001101100x
  36603. [12, 42], // 000011011010
  36604. [12, 43], // 000011011011
  36605. [10, 0], [10, 0], [10, 0], [10, 0], // 0000110111xx
  36606. [7, 12], [7, 12], [7, 12], [7, 12], // 0000111xxxxx
  36607. [7, 12], [7, 12], [7, 12], [7, 12],
  36608. [7, 12], [7, 12], [7, 12], [7, 12],
  36609. [7, 12], [7, 12], [7, 12], [7, 12],
  36610. [7, 12], [7, 12], [7, 12], [7, 12],
  36611. [7, 12], [7, 12], [7, 12], [7, 12],
  36612. [7, 12], [7, 12], [7, 12], [7, 12],
  36613. [7, 12], [7, 12], [7, 12], [7, 12]
  36614. ];
  36615. var blackTable3 = [
  36616. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000xx
  36617. [6, 9], // 000100
  36618. [6, 8], // 000101
  36619. [5, 7], [5, 7], // 00011x
  36620. [4, 6], [4, 6], [4, 6], [4, 6], // 0010xx
  36621. [4, 5], [4, 5], [4, 5], [4, 5], // 0011xx
  36622. [3, 1], [3, 1], [3, 1], [3, 1], // 010xxx
  36623. [3, 1], [3, 1], [3, 1], [3, 1],
  36624. [3, 4], [3, 4], [3, 4], [3, 4], // 011xxx
  36625. [3, 4], [3, 4], [3, 4], [3, 4],
  36626. [2, 3], [2, 3], [2, 3], [2, 3], // 10xxxx
  36627. [2, 3], [2, 3], [2, 3], [2, 3],
  36628. [2, 3], [2, 3], [2, 3], [2, 3],
  36629. [2, 3], [2, 3], [2, 3], [2, 3],
  36630. [2, 2], [2, 2], [2, 2], [2, 2], // 11xxxx
  36631. [2, 2], [2, 2], [2, 2], [2, 2],
  36632. [2, 2], [2, 2], [2, 2], [2, 2],
  36633. [2, 2], [2, 2], [2, 2], [2, 2]
  36634. ];
  36635. function CCITTFaxStream(str, maybeLength, params) {
  36636. this.str = str;
  36637. this.dict = str.dict;
  36638. params = params || Dict.empty;
  36639. this.encoding = params.get('K') || 0;
  36640. this.eoline = params.get('EndOfLine') || false;
  36641. this.byteAlign = params.get('EncodedByteAlign') || false;
  36642. this.columns = params.get('Columns') || 1728;
  36643. this.rows = params.get('Rows') || 0;
  36644. var eoblock = params.get('EndOfBlock');
  36645. if (eoblock === null || eoblock === undefined) {
  36646. eoblock = true;
  36647. }
  36648. this.eoblock = eoblock;
  36649. this.black = params.get('BlackIs1') || false;
  36650. this.codingLine = new Uint32Array(this.columns + 1);
  36651. this.refLine = new Uint32Array(this.columns + 2);
  36652. this.codingLine[0] = this.columns;
  36653. this.codingPos = 0;
  36654. this.row = 0;
  36655. this.nextLine2D = this.encoding < 0;
  36656. this.inputBits = 0;
  36657. this.inputBuf = 0;
  36658. this.outputBits = 0;
  36659. var code1;
  36660. while ((code1 = this.lookBits(12)) === 0) {
  36661. this.eatBits(1);
  36662. }
  36663. if (code1 === 1) {
  36664. this.eatBits(12);
  36665. }
  36666. if (this.encoding > 0) {
  36667. this.nextLine2D = !this.lookBits(1);
  36668. this.eatBits(1);
  36669. }
  36670. DecodeStream.call(this, maybeLength);
  36671. }
  36672. CCITTFaxStream.prototype = Object.create(DecodeStream.prototype);
  36673. CCITTFaxStream.prototype.readBlock = function CCITTFaxStream_readBlock() {
  36674. while (!this.eof) {
  36675. var c = this.lookChar();
  36676. this.ensureBuffer(this.bufferLength + 1);
  36677. this.buffer[this.bufferLength++] = c;
  36678. }
  36679. };
  36680. CCITTFaxStream.prototype.addPixels =
  36681. function ccittFaxStreamAddPixels(a1, blackPixels) {
  36682. var codingLine = this.codingLine;
  36683. var codingPos = this.codingPos;
  36684. if (a1 > codingLine[codingPos]) {
  36685. if (a1 > this.columns) {
  36686. info('row is wrong length');
  36687. this.err = true;
  36688. a1 = this.columns;
  36689. }
  36690. if ((codingPos & 1) ^ blackPixels) {
  36691. ++codingPos;
  36692. }
  36693. codingLine[codingPos] = a1;
  36694. }
  36695. this.codingPos = codingPos;
  36696. };
  36697. CCITTFaxStream.prototype.addPixelsNeg =
  36698. function ccittFaxStreamAddPixelsNeg(a1, blackPixels) {
  36699. var codingLine = this.codingLine;
  36700. var codingPos = this.codingPos;
  36701. if (a1 > codingLine[codingPos]) {
  36702. if (a1 > this.columns) {
  36703. info('row is wrong length');
  36704. this.err = true;
  36705. a1 = this.columns;
  36706. }
  36707. if ((codingPos & 1) ^ blackPixels) {
  36708. ++codingPos;
  36709. }
  36710. codingLine[codingPos] = a1;
  36711. } else if (a1 < codingLine[codingPos]) {
  36712. if (a1 < 0) {
  36713. info('invalid code');
  36714. this.err = true;
  36715. a1 = 0;
  36716. }
  36717. while (codingPos > 0 && a1 < codingLine[codingPos - 1]) {
  36718. --codingPos;
  36719. }
  36720. codingLine[codingPos] = a1;
  36721. }
  36722. this.codingPos = codingPos;
  36723. };
  36724. CCITTFaxStream.prototype.lookChar = function CCITTFaxStream_lookChar() {
  36725. var refLine = this.refLine;
  36726. var codingLine = this.codingLine;
  36727. var columns = this.columns;
  36728. var refPos, blackPixels, bits, i;
  36729. if (this.outputBits === 0) {
  36730. if (this.eof) {
  36731. return null;
  36732. }
  36733. this.err = false;
  36734. var code1, code2, code3;
  36735. if (this.nextLine2D) {
  36736. for (i = 0; codingLine[i] < columns; ++i) {
  36737. refLine[i] = codingLine[i];
  36738. }
  36739. refLine[i++] = columns;
  36740. refLine[i] = columns;
  36741. codingLine[0] = 0;
  36742. this.codingPos = 0;
  36743. refPos = 0;
  36744. blackPixels = 0;
  36745. while (codingLine[this.codingPos] < columns) {
  36746. code1 = this.getTwoDimCode();
  36747. switch (code1) {
  36748. case twoDimPass:
  36749. this.addPixels(refLine[refPos + 1], blackPixels);
  36750. if (refLine[refPos + 1] < columns) {
  36751. refPos += 2;
  36752. }
  36753. break;
  36754. case twoDimHoriz:
  36755. code1 = code2 = 0;
  36756. if (blackPixels) {
  36757. do {
  36758. code1 += (code3 = this.getBlackCode());
  36759. } while (code3 >= 64);
  36760. do {
  36761. code2 += (code3 = this.getWhiteCode());
  36762. } while (code3 >= 64);
  36763. } else {
  36764. do {
  36765. code1 += (code3 = this.getWhiteCode());
  36766. } while (code3 >= 64);
  36767. do {
  36768. code2 += (code3 = this.getBlackCode());
  36769. } while (code3 >= 64);
  36770. }
  36771. this.addPixels(codingLine[this.codingPos] +
  36772. code1, blackPixels);
  36773. if (codingLine[this.codingPos] < columns) {
  36774. this.addPixels(codingLine[this.codingPos] + code2,
  36775. blackPixels ^ 1);
  36776. }
  36777. while (refLine[refPos] <= codingLine[this.codingPos] &&
  36778. refLine[refPos] < columns) {
  36779. refPos += 2;
  36780. }
  36781. break;
  36782. case twoDimVertR3:
  36783. this.addPixels(refLine[refPos] + 3, blackPixels);
  36784. blackPixels ^= 1;
  36785. if (codingLine[this.codingPos] < columns) {
  36786. ++refPos;
  36787. while (refLine[refPos] <= codingLine[this.codingPos] &&
  36788. refLine[refPos] < columns) {
  36789. refPos += 2;
  36790. }
  36791. }
  36792. break;
  36793. case twoDimVertR2:
  36794. this.addPixels(refLine[refPos] + 2, blackPixels);
  36795. blackPixels ^= 1;
  36796. if (codingLine[this.codingPos] < columns) {
  36797. ++refPos;
  36798. while (refLine[refPos] <= codingLine[this.codingPos] &&
  36799. refLine[refPos] < columns) {
  36800. refPos += 2;
  36801. }
  36802. }
  36803. break;
  36804. case twoDimVertR1:
  36805. this.addPixels(refLine[refPos] + 1, blackPixels);
  36806. blackPixels ^= 1;
  36807. if (codingLine[this.codingPos] < columns) {
  36808. ++refPos;
  36809. while (refLine[refPos] <= codingLine[this.codingPos] &&
  36810. refLine[refPos] < columns) {
  36811. refPos += 2;
  36812. }
  36813. }
  36814. break;
  36815. case twoDimVert0:
  36816. this.addPixels(refLine[refPos], blackPixels);
  36817. blackPixels ^= 1;
  36818. if (codingLine[this.codingPos] < columns) {
  36819. ++refPos;
  36820. while (refLine[refPos] <= codingLine[this.codingPos] &&
  36821. refLine[refPos] < columns) {
  36822. refPos += 2;
  36823. }
  36824. }
  36825. break;
  36826. case twoDimVertL3:
  36827. this.addPixelsNeg(refLine[refPos] - 3, blackPixels);
  36828. blackPixels ^= 1;
  36829. if (codingLine[this.codingPos] < columns) {
  36830. if (refPos > 0) {
  36831. --refPos;
  36832. } else {
  36833. ++refPos;
  36834. }
  36835. while (refLine[refPos] <= codingLine[this.codingPos] &&
  36836. refLine[refPos] < columns) {
  36837. refPos += 2;
  36838. }
  36839. }
  36840. break;
  36841. case twoDimVertL2:
  36842. this.addPixelsNeg(refLine[refPos] - 2, blackPixels);
  36843. blackPixels ^= 1;
  36844. if (codingLine[this.codingPos] < columns) {
  36845. if (refPos > 0) {
  36846. --refPos;
  36847. } else {
  36848. ++refPos;
  36849. }
  36850. while (refLine[refPos] <= codingLine[this.codingPos] &&
  36851. refLine[refPos] < columns) {
  36852. refPos += 2;
  36853. }
  36854. }
  36855. break;
  36856. case twoDimVertL1:
  36857. this.addPixelsNeg(refLine[refPos] - 1, blackPixels);
  36858. blackPixels ^= 1;
  36859. if (codingLine[this.codingPos] < columns) {
  36860. if (refPos > 0) {
  36861. --refPos;
  36862. } else {
  36863. ++refPos;
  36864. }
  36865. while (refLine[refPos] <= codingLine[this.codingPos] &&
  36866. refLine[refPos] < columns) {
  36867. refPos += 2;
  36868. }
  36869. }
  36870. break;
  36871. case EOF:
  36872. this.addPixels(columns, 0);
  36873. this.eof = true;
  36874. break;
  36875. default:
  36876. info('bad 2d code');
  36877. this.addPixels(columns, 0);
  36878. this.err = true;
  36879. }
  36880. }
  36881. } else {
  36882. codingLine[0] = 0;
  36883. this.codingPos = 0;
  36884. blackPixels = 0;
  36885. while (codingLine[this.codingPos] < columns) {
  36886. code1 = 0;
  36887. if (blackPixels) {
  36888. do {
  36889. code1 += (code3 = this.getBlackCode());
  36890. } while (code3 >= 64);
  36891. } else {
  36892. do {
  36893. code1 += (code3 = this.getWhiteCode());
  36894. } while (code3 >= 64);
  36895. }
  36896. this.addPixels(codingLine[this.codingPos] + code1, blackPixels);
  36897. blackPixels ^= 1;
  36898. }
  36899. }
  36900. var gotEOL = false;
  36901. if (this.byteAlign) {
  36902. this.inputBits &= ~7;
  36903. }
  36904. if (!this.eoblock && this.row === this.rows - 1) {
  36905. this.eof = true;
  36906. } else {
  36907. code1 = this.lookBits(12);
  36908. if (this.eoline) {
  36909. while (code1 !== EOF && code1 !== 1) {
  36910. this.eatBits(1);
  36911. code1 = this.lookBits(12);
  36912. }
  36913. } else {
  36914. while (code1 === 0) {
  36915. this.eatBits(1);
  36916. code1 = this.lookBits(12);
  36917. }
  36918. }
  36919. if (code1 === 1) {
  36920. this.eatBits(12);
  36921. gotEOL = true;
  36922. } else if (code1 === EOF) {
  36923. this.eof = true;
  36924. }
  36925. }
  36926. if (!this.eof && this.encoding > 0) {
  36927. this.nextLine2D = !this.lookBits(1);
  36928. this.eatBits(1);
  36929. }
  36930. if (this.eoblock && gotEOL && this.byteAlign) {
  36931. code1 = this.lookBits(12);
  36932. if (code1 === 1) {
  36933. this.eatBits(12);
  36934. if (this.encoding > 0) {
  36935. this.lookBits(1);
  36936. this.eatBits(1);
  36937. }
  36938. if (this.encoding >= 0) {
  36939. for (i = 0; i < 4; ++i) {
  36940. code1 = this.lookBits(12);
  36941. if (code1 !== 1) {
  36942. info('bad rtc code: ' + code1);
  36943. }
  36944. this.eatBits(12);
  36945. if (this.encoding > 0) {
  36946. this.lookBits(1);
  36947. this.eatBits(1);
  36948. }
  36949. }
  36950. }
  36951. this.eof = true;
  36952. }
  36953. } else if (this.err && this.eoline) {
  36954. while (true) {
  36955. code1 = this.lookBits(13);
  36956. if (code1 === EOF) {
  36957. this.eof = true;
  36958. return null;
  36959. }
  36960. if ((code1 >> 1) === 1) {
  36961. break;
  36962. }
  36963. this.eatBits(1);
  36964. }
  36965. this.eatBits(12);
  36966. if (this.encoding > 0) {
  36967. this.eatBits(1);
  36968. this.nextLine2D = !(code1 & 1);
  36969. }
  36970. }
  36971. if (codingLine[0] > 0) {
  36972. this.outputBits = codingLine[this.codingPos = 0];
  36973. } else {
  36974. this.outputBits = codingLine[this.codingPos = 1];
  36975. }
  36976. this.row++;
  36977. }
  36978. var c;
  36979. if (this.outputBits >= 8) {
  36980. c = (this.codingPos & 1) ? 0 : 0xFF;
  36981. this.outputBits -= 8;
  36982. if (this.outputBits === 0 && codingLine[this.codingPos] < columns) {
  36983. this.codingPos++;
  36984. this.outputBits = (codingLine[this.codingPos] -
  36985. codingLine[this.codingPos - 1]);
  36986. }
  36987. } else {
  36988. bits = 8;
  36989. c = 0;
  36990. do {
  36991. if (this.outputBits > bits) {
  36992. c <<= bits;
  36993. if (!(this.codingPos & 1)) {
  36994. c |= 0xFF >> (8 - bits);
  36995. }
  36996. this.outputBits -= bits;
  36997. bits = 0;
  36998. } else {
  36999. c <<= this.outputBits;
  37000. if (!(this.codingPos & 1)) {
  37001. c |= 0xFF >> (8 - this.outputBits);
  37002. }
  37003. bits -= this.outputBits;
  37004. this.outputBits = 0;
  37005. if (codingLine[this.codingPos] < columns) {
  37006. this.codingPos++;
  37007. this.outputBits = (codingLine[this.codingPos] -
  37008. codingLine[this.codingPos - 1]);
  37009. } else if (bits > 0) {
  37010. c <<= bits;
  37011. bits = 0;
  37012. }
  37013. }
  37014. } while (bits);
  37015. }
  37016. if (this.black) {
  37017. c ^= 0xFF;
  37018. }
  37019. return c;
  37020. };
  37021. // This functions returns the code found from the table.
  37022. // The start and end parameters set the boundaries for searching the table.
  37023. // The limit parameter is optional. Function returns an array with three
  37024. // values. The first array element indicates whether a valid code is being
  37025. // returned. The second array element is the actual code. The third array
  37026. // element indicates whether EOF was reached.
  37027. CCITTFaxStream.prototype.findTableCode =
  37028. function ccittFaxStreamFindTableCode(start, end, table, limit) {
  37029. var limitValue = limit || 0;
  37030. for (var i = start; i <= end; ++i) {
  37031. var code = this.lookBits(i);
  37032. if (code === EOF) {
  37033. return [true, 1, false];
  37034. }
  37035. if (i < end) {
  37036. code <<= end - i;
  37037. }
  37038. if (!limitValue || code >= limitValue) {
  37039. var p = table[code - limitValue];
  37040. if (p[0] === i) {
  37041. this.eatBits(i);
  37042. return [true, p[1], true];
  37043. }
  37044. }
  37045. }
  37046. return [false, 0, false];
  37047. };
  37048. CCITTFaxStream.prototype.getTwoDimCode =
  37049. function ccittFaxStreamGetTwoDimCode() {
  37050. var code = 0;
  37051. var p;
  37052. if (this.eoblock) {
  37053. code = this.lookBits(7);
  37054. p = twoDimTable[code];
  37055. if (p && p[0] > 0) {
  37056. this.eatBits(p[0]);
  37057. return p[1];
  37058. }
  37059. } else {
  37060. var result = this.findTableCode(1, 7, twoDimTable);
  37061. if (result[0] && result[2]) {
  37062. return result[1];
  37063. }
  37064. }
  37065. info('Bad two dim code');
  37066. return EOF;
  37067. };
  37068. CCITTFaxStream.prototype.getWhiteCode =
  37069. function ccittFaxStreamGetWhiteCode() {
  37070. var code = 0;
  37071. var p;
  37072. if (this.eoblock) {
  37073. code = this.lookBits(12);
  37074. if (code === EOF) {
  37075. return 1;
  37076. }
  37077. if ((code >> 5) === 0) {
  37078. p = whiteTable1[code];
  37079. } else {
  37080. p = whiteTable2[code >> 3];
  37081. }
  37082. if (p[0] > 0) {
  37083. this.eatBits(p[0]);
  37084. return p[1];
  37085. }
  37086. } else {
  37087. var result = this.findTableCode(1, 9, whiteTable2);
  37088. if (result[0]) {
  37089. return result[1];
  37090. }
  37091. result = this.findTableCode(11, 12, whiteTable1);
  37092. if (result[0]) {
  37093. return result[1];
  37094. }
  37095. }
  37096. info('bad white code');
  37097. this.eatBits(1);
  37098. return 1;
  37099. };
  37100. CCITTFaxStream.prototype.getBlackCode =
  37101. function ccittFaxStreamGetBlackCode() {
  37102. var code, p;
  37103. if (this.eoblock) {
  37104. code = this.lookBits(13);
  37105. if (code === EOF) {
  37106. return 1;
  37107. }
  37108. if ((code >> 7) === 0) {
  37109. p = blackTable1[code];
  37110. } else if ((code >> 9) === 0 && (code >> 7) !== 0) {
  37111. p = blackTable2[(code >> 1) - 64];
  37112. } else {
  37113. p = blackTable3[code >> 7];
  37114. }
  37115. if (p[0] > 0) {
  37116. this.eatBits(p[0]);
  37117. return p[1];
  37118. }
  37119. } else {
  37120. var result = this.findTableCode(2, 6, blackTable3);
  37121. if (result[0]) {
  37122. return result[1];
  37123. }
  37124. result = this.findTableCode(7, 12, blackTable2, 64);
  37125. if (result[0]) {
  37126. return result[1];
  37127. }
  37128. result = this.findTableCode(10, 13, blackTable1);
  37129. if (result[0]) {
  37130. return result[1];
  37131. }
  37132. }
  37133. info('bad black code');
  37134. this.eatBits(1);
  37135. return 1;
  37136. };
  37137. CCITTFaxStream.prototype.lookBits = function CCITTFaxStream_lookBits(n) {
  37138. var c;
  37139. while (this.inputBits < n) {
  37140. if ((c = this.str.getByte()) === -1) {
  37141. if (this.inputBits === 0) {
  37142. return EOF;
  37143. }
  37144. return ((this.inputBuf << (n - this.inputBits)) &
  37145. (0xFFFF >> (16 - n)));
  37146. }
  37147. this.inputBuf = (this.inputBuf << 8) + c;
  37148. this.inputBits += 8;
  37149. }
  37150. return (this.inputBuf >> (this.inputBits - n)) & (0xFFFF >> (16 - n));
  37151. };
  37152. CCITTFaxStream.prototype.eatBits = function CCITTFaxStream_eatBits(n) {
  37153. if ((this.inputBits -= n) < 0) {
  37154. this.inputBits = 0;
  37155. }
  37156. };
  37157. return CCITTFaxStream;
  37158. })();
  37159. var LZWStream = (function LZWStreamClosure() {
  37160. function LZWStream(str, maybeLength, earlyChange) {
  37161. this.str = str;
  37162. this.dict = str.dict;
  37163. this.cachedData = 0;
  37164. this.bitsCached = 0;
  37165. var maxLzwDictionarySize = 4096;
  37166. var lzwState = {
  37167. earlyChange: earlyChange,
  37168. codeLength: 9,
  37169. nextCode: 258,
  37170. dictionaryValues: new Uint8Array(maxLzwDictionarySize),
  37171. dictionaryLengths: new Uint16Array(maxLzwDictionarySize),
  37172. dictionaryPrevCodes: new Uint16Array(maxLzwDictionarySize),
  37173. currentSequence: new Uint8Array(maxLzwDictionarySize),
  37174. currentSequenceLength: 0
  37175. };
  37176. for (var i = 0; i < 256; ++i) {
  37177. lzwState.dictionaryValues[i] = i;
  37178. lzwState.dictionaryLengths[i] = 1;
  37179. }
  37180. this.lzwState = lzwState;
  37181. DecodeStream.call(this, maybeLength);
  37182. }
  37183. LZWStream.prototype = Object.create(DecodeStream.prototype);
  37184. LZWStream.prototype.readBits = function LZWStream_readBits(n) {
  37185. var bitsCached = this.bitsCached;
  37186. var cachedData = this.cachedData;
  37187. while (bitsCached < n) {
  37188. var c = this.str.getByte();
  37189. if (c === -1) {
  37190. this.eof = true;
  37191. return null;
  37192. }
  37193. cachedData = (cachedData << 8) | c;
  37194. bitsCached += 8;
  37195. }
  37196. this.bitsCached = (bitsCached -= n);
  37197. this.cachedData = cachedData;
  37198. this.lastCode = null;
  37199. return (cachedData >>> bitsCached) & ((1 << n) - 1);
  37200. };
  37201. LZWStream.prototype.readBlock = function LZWStream_readBlock() {
  37202. var blockSize = 512;
  37203. var estimatedDecodedSize = blockSize * 2, decodedSizeDelta = blockSize;
  37204. var i, j, q;
  37205. var lzwState = this.lzwState;
  37206. if (!lzwState) {
  37207. return; // eof was found
  37208. }
  37209. var earlyChange = lzwState.earlyChange;
  37210. var nextCode = lzwState.nextCode;
  37211. var dictionaryValues = lzwState.dictionaryValues;
  37212. var dictionaryLengths = lzwState.dictionaryLengths;
  37213. var dictionaryPrevCodes = lzwState.dictionaryPrevCodes;
  37214. var codeLength = lzwState.codeLength;
  37215. var prevCode = lzwState.prevCode;
  37216. var currentSequence = lzwState.currentSequence;
  37217. var currentSequenceLength = lzwState.currentSequenceLength;
  37218. var decodedLength = 0;
  37219. var currentBufferLength = this.bufferLength;
  37220. var buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  37221. for (i = 0; i < blockSize; i++) {
  37222. var code = this.readBits(codeLength);
  37223. var hasPrev = currentSequenceLength > 0;
  37224. if (code < 256) {
  37225. currentSequence[0] = code;
  37226. currentSequenceLength = 1;
  37227. } else if (code >= 258) {
  37228. if (code < nextCode) {
  37229. currentSequenceLength = dictionaryLengths[code];
  37230. for (j = currentSequenceLength - 1, q = code; j >= 0; j--) {
  37231. currentSequence[j] = dictionaryValues[q];
  37232. q = dictionaryPrevCodes[q];
  37233. }
  37234. } else {
  37235. currentSequence[currentSequenceLength++] = currentSequence[0];
  37236. }
  37237. } else if (code === 256) {
  37238. codeLength = 9;
  37239. nextCode = 258;
  37240. currentSequenceLength = 0;
  37241. continue;
  37242. } else {
  37243. this.eof = true;
  37244. delete this.lzwState;
  37245. break;
  37246. }
  37247. if (hasPrev) {
  37248. dictionaryPrevCodes[nextCode] = prevCode;
  37249. dictionaryLengths[nextCode] = dictionaryLengths[prevCode] + 1;
  37250. dictionaryValues[nextCode] = currentSequence[0];
  37251. nextCode++;
  37252. codeLength = (nextCode + earlyChange) & (nextCode + earlyChange - 1) ?
  37253. codeLength : Math.min(Math.log(nextCode + earlyChange) /
  37254. 0.6931471805599453 + 1, 12) | 0;
  37255. }
  37256. prevCode = code;
  37257. decodedLength += currentSequenceLength;
  37258. if (estimatedDecodedSize < decodedLength) {
  37259. do {
  37260. estimatedDecodedSize += decodedSizeDelta;
  37261. } while (estimatedDecodedSize < decodedLength);
  37262. buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  37263. }
  37264. for (j = 0; j < currentSequenceLength; j++) {
  37265. buffer[currentBufferLength++] = currentSequence[j];
  37266. }
  37267. }
  37268. lzwState.nextCode = nextCode;
  37269. lzwState.codeLength = codeLength;
  37270. lzwState.prevCode = prevCode;
  37271. lzwState.currentSequenceLength = currentSequenceLength;
  37272. this.bufferLength = currentBufferLength;
  37273. };
  37274. return LZWStream;
  37275. })();
  37276. var NullStream = (function NullStreamClosure() {
  37277. function NullStream() {
  37278. Stream.call(this, new Uint8Array(0));
  37279. }
  37280. NullStream.prototype = Stream.prototype;
  37281. return NullStream;
  37282. })();
  37283. var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
  37284. setup: function wphSetup(handler) {
  37285. var pdfManager;
  37286. function loadDocument(recoveryMode) {
  37287. var loadDocumentCapability = createPromiseCapability();
  37288. var parseSuccess = function parseSuccess() {
  37289. var numPagesPromise = pdfManager.ensureDoc('numPages');
  37290. var fingerprintPromise = pdfManager.ensureDoc('fingerprint');
  37291. var encryptedPromise = pdfManager.ensureXRef('encrypt');
  37292. Promise.all([numPagesPromise, fingerprintPromise,
  37293. encryptedPromise]).then(function onDocReady(results) {
  37294. var doc = {
  37295. numPages: results[0],
  37296. fingerprint: results[1],
  37297. encrypted: !!results[2],
  37298. };
  37299. loadDocumentCapability.resolve(doc);
  37300. },
  37301. parseFailure);
  37302. };
  37303. var parseFailure = function parseFailure(e) {
  37304. loadDocumentCapability.reject(e);
  37305. };
  37306. pdfManager.ensureDoc('checkHeader', []).then(function() {
  37307. pdfManager.ensureDoc('parseStartXRef', []).then(function() {
  37308. pdfManager.ensureDoc('parse', [recoveryMode]).then(
  37309. parseSuccess, parseFailure);
  37310. }, parseFailure);
  37311. }, parseFailure);
  37312. return loadDocumentCapability.promise;
  37313. }
  37314. function getPdfManager(data) {
  37315. var pdfManagerCapability = createPromiseCapability();
  37316. var source = data.source;
  37317. var disableRange = data.disableRange;
  37318. if (source.data) {
  37319. try {
  37320. pdfManager = new LocalPdfManager(source.data, source.password);
  37321. pdfManagerCapability.resolve();
  37322. } catch (ex) {
  37323. pdfManagerCapability.reject(ex);
  37324. }
  37325. return pdfManagerCapability.promise;
  37326. } else if (source.chunkedViewerLoading) {
  37327. try {
  37328. pdfManager = new NetworkPdfManager(source, handler);
  37329. pdfManagerCapability.resolve();
  37330. } catch (ex) {
  37331. pdfManagerCapability.reject(ex);
  37332. }
  37333. return pdfManagerCapability.promise;
  37334. }
  37335. var networkManager = new NetworkManager(source.url, {
  37336. httpHeaders: source.httpHeaders,
  37337. withCredentials: source.withCredentials
  37338. });
  37339. var cachedChunks = [];
  37340. var fullRequestXhrId = networkManager.requestFull({
  37341. onHeadersReceived: function onHeadersReceived() {
  37342. if (disableRange) {
  37343. return;
  37344. }
  37345. var fullRequestXhr = networkManager.getRequestXhr(fullRequestXhrId);
  37346. if (fullRequestXhr.getResponseHeader('Accept-Ranges') !== 'bytes') {
  37347. return;
  37348. }
  37349. var contentEncoding =
  37350. fullRequestXhr.getResponseHeader('Content-Encoding') || 'identity';
  37351. if (contentEncoding !== 'identity') {
  37352. return;
  37353. }
  37354. var length = fullRequestXhr.getResponseHeader('Content-Length');
  37355. length = parseInt(length, 10);
  37356. if (!isInt(length)) {
  37357. return;
  37358. }
  37359. source.length = length;
  37360. if (length <= 2 * RANGE_CHUNK_SIZE) {
  37361. // The file size is smaller than the size of two chunks, so it does
  37362. // not make any sense to abort the request and retry with a range
  37363. // request.
  37364. return;
  37365. }
  37366. if (networkManager.isStreamingRequest(fullRequestXhrId)) {
  37367. // We can continue fetching when progressive loading is enabled,
  37368. // and we don't need the autoFetch feature.
  37369. source.disableAutoFetch = true;
  37370. } else {
  37371. // NOTE: by cancelling the full request, and then issuing range
  37372. // requests, there will be an issue for sites where you can only
  37373. // request the pdf once. However, if this is the case, then the
  37374. // server should not be returning that it can support range
  37375. // requests.
  37376. networkManager.abortRequest(fullRequestXhrId);
  37377. }
  37378. try {
  37379. pdfManager = new NetworkPdfManager(source, handler);
  37380. pdfManagerCapability.resolve(pdfManager);
  37381. } catch (ex) {
  37382. pdfManagerCapability.reject(ex);
  37383. }
  37384. },
  37385. onProgressiveData: source.disableStream ? null :
  37386. function onProgressiveData(chunk) {
  37387. if (!pdfManager) {
  37388. cachedChunks.push(chunk);
  37389. return;
  37390. }
  37391. pdfManager.sendProgressiveData(chunk);
  37392. },
  37393. onDone: function onDone(args) {
  37394. if (pdfManager) {
  37395. return; // already processed
  37396. }
  37397. var pdfFile;
  37398. if (args === null) {
  37399. // TODO add some streaming manager, e.g. for unknown length files.
  37400. // The data was returned in the onProgressiveData, combining...
  37401. var pdfFileLength = 0, pos = 0;
  37402. cachedChunks.forEach(function (chunk) {
  37403. pdfFileLength += chunk.byteLength;
  37404. });
  37405. if (source.length && pdfFileLength !== source.length) {
  37406. warn('reported HTTP length is different from actual');
  37407. }
  37408. var pdfFileArray = new Uint8Array(pdfFileLength);
  37409. cachedChunks.forEach(function (chunk) {
  37410. pdfFileArray.set(new Uint8Array(chunk), pos);
  37411. pos += chunk.byteLength;
  37412. });
  37413. pdfFile = pdfFileArray.buffer;
  37414. } else {
  37415. pdfFile = args.chunk;
  37416. }
  37417. // the data is array, instantiating directly from it
  37418. try {
  37419. pdfManager = new LocalPdfManager(pdfFile, source.password);
  37420. pdfManagerCapability.resolve();
  37421. } catch (ex) {
  37422. pdfManagerCapability.reject(ex);
  37423. }
  37424. },
  37425. onError: function onError(status) {
  37426. var exception;
  37427. if (status === 404) {
  37428. exception = new MissingPDFException('Missing PDF "' +
  37429. source.url + '".');
  37430. handler.send('MissingPDF', exception);
  37431. } else {
  37432. exception = new UnexpectedResponseException(
  37433. 'Unexpected server response (' + status +
  37434. ') while retrieving PDF "' + source.url + '".', status);
  37435. handler.send('UnexpectedResponse', exception);
  37436. }
  37437. },
  37438. onProgress: function onProgress(evt) {
  37439. handler.send('DocProgress', {
  37440. loaded: evt.loaded,
  37441. total: evt.lengthComputable ? evt.total : source.length
  37442. });
  37443. }
  37444. });
  37445. return pdfManagerCapability.promise;
  37446. }
  37447. handler.on('test', function wphSetupTest(data) {
  37448. // check if Uint8Array can be sent to worker
  37449. if (!(data instanceof Uint8Array)) {
  37450. handler.send('test', false);
  37451. return;
  37452. }
  37453. // making sure postMessage transfers are working
  37454. var supportTransfers = data[0] === 255;
  37455. handler.postMessageTransfers = supportTransfers;
  37456. // check if the response property is supported by xhr
  37457. var xhr = new XMLHttpRequest();
  37458. var responseExists = 'response' in xhr;
  37459. // check if the property is actually implemented
  37460. try {
  37461. var dummy = xhr.responseType;
  37462. } catch (e) {
  37463. responseExists = false;
  37464. }
  37465. if (!responseExists) {
  37466. handler.send('test', false);
  37467. return;
  37468. }
  37469. handler.send('test', {
  37470. supportTypedArray: true,
  37471. supportTransfers: supportTransfers
  37472. });
  37473. });
  37474. handler.on('GetDocRequest', function wphSetupDoc(data) {
  37475. var onSuccess = function(doc) {
  37476. handler.send('GetDoc', { pdfInfo: doc });
  37477. };
  37478. var onFailure = function(e) {
  37479. if (e instanceof PasswordException) {
  37480. if (e.code === PasswordResponses.NEED_PASSWORD) {
  37481. handler.send('NeedPassword', e);
  37482. } else if (e.code === PasswordResponses.INCORRECT_PASSWORD) {
  37483. handler.send('IncorrectPassword', e);
  37484. }
  37485. } else if (e instanceof InvalidPDFException) {
  37486. handler.send('InvalidPDF', e);
  37487. } else if (e instanceof MissingPDFException) {
  37488. handler.send('MissingPDF', e);
  37489. } else if (e instanceof UnexpectedResponseException) {
  37490. handler.send('UnexpectedResponse', e);
  37491. } else {
  37492. handler.send('UnknownError',
  37493. new UnknownErrorException(e.message, e.toString()));
  37494. }
  37495. };
  37496. PDFJS.maxImageSize = data.maxImageSize === undefined ?
  37497. -1 : data.maxImageSize;
  37498. PDFJS.disableFontFace = data.disableFontFace;
  37499. PDFJS.disableCreateObjectURL = data.disableCreateObjectURL;
  37500. PDFJS.verbosity = data.verbosity;
  37501. PDFJS.cMapUrl = data.cMapUrl === undefined ?
  37502. null : data.cMapUrl;
  37503. PDFJS.cMapPacked = data.cMapPacked === true;
  37504. getPdfManager(data).then(function () {
  37505. handler.send('PDFManagerReady', null);
  37506. pdfManager.onLoadedStream().then(function(stream) {
  37507. handler.send('DataLoaded', { length: stream.bytes.byteLength });
  37508. });
  37509. }).then(function pdfManagerReady() {
  37510. loadDocument(false).then(onSuccess, function loadFailure(ex) {
  37511. // Try again with recoveryMode == true
  37512. if (!(ex instanceof XRefParseException)) {
  37513. if (ex instanceof PasswordException) {
  37514. // after password exception prepare to receive a new password
  37515. // to repeat loading
  37516. pdfManager.passwordChanged().then(pdfManagerReady);
  37517. }
  37518. onFailure(ex);
  37519. return;
  37520. }
  37521. pdfManager.requestLoadedStream();
  37522. pdfManager.onLoadedStream().then(function() {
  37523. loadDocument(true).then(onSuccess, onFailure);
  37524. });
  37525. }, onFailure);
  37526. }, onFailure);
  37527. });
  37528. handler.on('GetPage', function wphSetupGetPage(data) {
  37529. return pdfManager.getPage(data.pageIndex).then(function(page) {
  37530. var rotatePromise = pdfManager.ensure(page, 'rotate');
  37531. var refPromise = pdfManager.ensure(page, 'ref');
  37532. var viewPromise = pdfManager.ensure(page, 'view');
  37533. return Promise.all([rotatePromise, refPromise, viewPromise]).then(
  37534. function(results) {
  37535. return {
  37536. rotate: results[0],
  37537. ref: results[1],
  37538. view: results[2]
  37539. };
  37540. });
  37541. });
  37542. });
  37543. handler.on('GetPageIndex', function wphSetupGetPageIndex(data) {
  37544. var ref = new Ref(data.ref.num, data.ref.gen);
  37545. var catalog = pdfManager.pdfDocument.catalog;
  37546. return catalog.getPageIndex(ref);
  37547. });
  37548. handler.on('GetDestinations',
  37549. function wphSetupGetDestinations(data) {
  37550. return pdfManager.ensureCatalog('destinations');
  37551. }
  37552. );
  37553. handler.on('GetDestination',
  37554. function wphSetupGetDestination(data) {
  37555. return pdfManager.ensureCatalog('getDestination', [ data.id ]);
  37556. }
  37557. );
  37558. handler.on('GetAttachments',
  37559. function wphSetupGetAttachments(data) {
  37560. return pdfManager.ensureCatalog('attachments');
  37561. }
  37562. );
  37563. handler.on('GetJavaScript',
  37564. function wphSetupGetJavaScript(data) {
  37565. return pdfManager.ensureCatalog('javaScript');
  37566. }
  37567. );
  37568. handler.on('GetOutline',
  37569. function wphSetupGetOutline(data) {
  37570. return pdfManager.ensureCatalog('documentOutline');
  37571. }
  37572. );
  37573. handler.on('GetMetadata',
  37574. function wphSetupGetMetadata(data) {
  37575. return Promise.all([pdfManager.ensureDoc('documentInfo'),
  37576. pdfManager.ensureCatalog('metadata')]);
  37577. }
  37578. );
  37579. handler.on('GetData', function wphSetupGetData(data) {
  37580. pdfManager.requestLoadedStream();
  37581. return pdfManager.onLoadedStream().then(function(stream) {
  37582. return stream.bytes;
  37583. });
  37584. });
  37585. handler.on('GetStats',
  37586. function wphSetupGetStats(data) {
  37587. return pdfManager.pdfDocument.xref.stats;
  37588. }
  37589. );
  37590. handler.on('UpdatePassword', function wphSetupUpdatePassword(data) {
  37591. pdfManager.updatePassword(data);
  37592. });
  37593. handler.on('GetAnnotations', function wphSetupGetAnnotations(data) {
  37594. return pdfManager.getPage(data.pageIndex).then(function(page) {
  37595. return pdfManager.ensure(page, 'getAnnotationsData', []);
  37596. });
  37597. });
  37598. handler.on('RenderPageRequest', function wphSetupRenderPage(data) {
  37599. pdfManager.getPage(data.pageIndex).then(function(page) {
  37600. var pageNum = data.pageIndex + 1;
  37601. var start = Date.now();
  37602. // Pre compile the pdf page and fetch the fonts/images.
  37603. page.getOperatorList(handler, data.intent).then(function(operatorList) {
  37604. info('page=' + pageNum + ' - getOperatorList: time=' +
  37605. (Date.now() - start) + 'ms, len=' + operatorList.fnArray.length);
  37606. }, function(e) {
  37607. var minimumStackMessage =
  37608. 'worker.js: while trying to getPage() and getOperatorList()';
  37609. var wrappedException;
  37610. // Turn the error into an obj that can be serialized
  37611. if (typeof e === 'string') {
  37612. wrappedException = {
  37613. message: e,
  37614. stack: minimumStackMessage
  37615. };
  37616. } else if (typeof e === 'object') {
  37617. wrappedException = {
  37618. message: e.message || e.toString(),
  37619. stack: e.stack || minimumStackMessage
  37620. };
  37621. } else {
  37622. wrappedException = {
  37623. message: 'Unknown exception type: ' + (typeof e),
  37624. stack: minimumStackMessage
  37625. };
  37626. }
  37627. handler.send('PageError', {
  37628. pageNum: pageNum,
  37629. error: wrappedException,
  37630. intent: data.intent
  37631. });
  37632. });
  37633. });
  37634. }, this);
  37635. handler.on('GetTextContent', function wphExtractText(data) {
  37636. return pdfManager.getPage(data.pageIndex).then(function(page) {
  37637. var pageNum = data.pageIndex + 1;
  37638. var start = Date.now();
  37639. return page.extractTextContent().then(function(textContent) {
  37640. info('text indexing: page=' + pageNum + ' - time=' +
  37641. (Date.now() - start) + 'ms');
  37642. return textContent;
  37643. });
  37644. });
  37645. });
  37646. handler.on('Cleanup', function wphCleanup(data) {
  37647. return pdfManager.cleanup();
  37648. });
  37649. handler.on('Terminate', function wphTerminate(data) {
  37650. pdfManager.terminate();
  37651. });
  37652. }
  37653. };
  37654. var consoleTimer = {};
  37655. var workerConsole = {
  37656. log: function log() {
  37657. var args = Array.prototype.slice.call(arguments);
  37658. globalScope.postMessage({
  37659. action: 'console_log',
  37660. data: args
  37661. });
  37662. },
  37663. error: function error() {
  37664. var args = Array.prototype.slice.call(arguments);
  37665. globalScope.postMessage({
  37666. action: 'console_error',
  37667. data: args
  37668. });
  37669. throw 'pdf.js execution error';
  37670. },
  37671. time: function time(name) {
  37672. consoleTimer[name] = Date.now();
  37673. },
  37674. timeEnd: function timeEnd(name) {
  37675. var time = consoleTimer[name];
  37676. if (!time) {
  37677. error('Unknown timer name ' + name);
  37678. }
  37679. this.log('Timer:', name, Date.now() - time);
  37680. }
  37681. };
  37682. // Worker thread?
  37683. if (typeof window === 'undefined') {
  37684. if (!('console' in globalScope)) {
  37685. globalScope.console = workerConsole;
  37686. }
  37687. // Listen for unsupported features so we can pass them on to the main thread.
  37688. PDFJS.UnsupportedManager.listen(function (msg) {
  37689. globalScope.postMessage({
  37690. action: '_unsupported_feature',
  37691. data: msg
  37692. });
  37693. });
  37694. var handler = new MessageHandler('worker_processor', this);
  37695. WorkerMessageHandler.setup(handler);
  37696. }
  37697. /* This class implements the QM Coder decoding as defined in
  37698. * JPEG 2000 Part I Final Committee Draft Version 1.0
  37699. * Annex C.3 Arithmetic decoding procedure
  37700. * available at http://www.jpeg.org/public/fcd15444-1.pdf
  37701. *
  37702. * The arithmetic decoder is used in conjunction with context models to decode
  37703. * JPEG2000 and JBIG2 streams.
  37704. */
  37705. var ArithmeticDecoder = (function ArithmeticDecoderClosure() {
  37706. // Table C-2
  37707. var QeTable = [
  37708. {qe: 0x5601, nmps: 1, nlps: 1, switchFlag: 1},
  37709. {qe: 0x3401, nmps: 2, nlps: 6, switchFlag: 0},
  37710. {qe: 0x1801, nmps: 3, nlps: 9, switchFlag: 0},
  37711. {qe: 0x0AC1, nmps: 4, nlps: 12, switchFlag: 0},
  37712. {qe: 0x0521, nmps: 5, nlps: 29, switchFlag: 0},
  37713. {qe: 0x0221, nmps: 38, nlps: 33, switchFlag: 0},
  37714. {qe: 0x5601, nmps: 7, nlps: 6, switchFlag: 1},
  37715. {qe: 0x5401, nmps: 8, nlps: 14, switchFlag: 0},
  37716. {qe: 0x4801, nmps: 9, nlps: 14, switchFlag: 0},
  37717. {qe: 0x3801, nmps: 10, nlps: 14, switchFlag: 0},
  37718. {qe: 0x3001, nmps: 11, nlps: 17, switchFlag: 0},
  37719. {qe: 0x2401, nmps: 12, nlps: 18, switchFlag: 0},
  37720. {qe: 0x1C01, nmps: 13, nlps: 20, switchFlag: 0},
  37721. {qe: 0x1601, nmps: 29, nlps: 21, switchFlag: 0},
  37722. {qe: 0x5601, nmps: 15, nlps: 14, switchFlag: 1},
  37723. {qe: 0x5401, nmps: 16, nlps: 14, switchFlag: 0},
  37724. {qe: 0x5101, nmps: 17, nlps: 15, switchFlag: 0},
  37725. {qe: 0x4801, nmps: 18, nlps: 16, switchFlag: 0},
  37726. {qe: 0x3801, nmps: 19, nlps: 17, switchFlag: 0},
  37727. {qe: 0x3401, nmps: 20, nlps: 18, switchFlag: 0},
  37728. {qe: 0x3001, nmps: 21, nlps: 19, switchFlag: 0},
  37729. {qe: 0x2801, nmps: 22, nlps: 19, switchFlag: 0},
  37730. {qe: 0x2401, nmps: 23, nlps: 20, switchFlag: 0},
  37731. {qe: 0x2201, nmps: 24, nlps: 21, switchFlag: 0},
  37732. {qe: 0x1C01, nmps: 25, nlps: 22, switchFlag: 0},
  37733. {qe: 0x1801, nmps: 26, nlps: 23, switchFlag: 0},
  37734. {qe: 0x1601, nmps: 27, nlps: 24, switchFlag: 0},
  37735. {qe: 0x1401, nmps: 28, nlps: 25, switchFlag: 0},
  37736. {qe: 0x1201, nmps: 29, nlps: 26, switchFlag: 0},
  37737. {qe: 0x1101, nmps: 30, nlps: 27, switchFlag: 0},
  37738. {qe: 0x0AC1, nmps: 31, nlps: 28, switchFlag: 0},
  37739. {qe: 0x09C1, nmps: 32, nlps: 29, switchFlag: 0},
  37740. {qe: 0x08A1, nmps: 33, nlps: 30, switchFlag: 0},
  37741. {qe: 0x0521, nmps: 34, nlps: 31, switchFlag: 0},
  37742. {qe: 0x0441, nmps: 35, nlps: 32, switchFlag: 0},
  37743. {qe: 0x02A1, nmps: 36, nlps: 33, switchFlag: 0},
  37744. {qe: 0x0221, nmps: 37, nlps: 34, switchFlag: 0},
  37745. {qe: 0x0141, nmps: 38, nlps: 35, switchFlag: 0},
  37746. {qe: 0x0111, nmps: 39, nlps: 36, switchFlag: 0},
  37747. {qe: 0x0085, nmps: 40, nlps: 37, switchFlag: 0},
  37748. {qe: 0x0049, nmps: 41, nlps: 38, switchFlag: 0},
  37749. {qe: 0x0025, nmps: 42, nlps: 39, switchFlag: 0},
  37750. {qe: 0x0015, nmps: 43, nlps: 40, switchFlag: 0},
  37751. {qe: 0x0009, nmps: 44, nlps: 41, switchFlag: 0},
  37752. {qe: 0x0005, nmps: 45, nlps: 42, switchFlag: 0},
  37753. {qe: 0x0001, nmps: 45, nlps: 43, switchFlag: 0},
  37754. {qe: 0x5601, nmps: 46, nlps: 46, switchFlag: 0}
  37755. ];
  37756. // C.3.5 Initialisation of the decoder (INITDEC)
  37757. function ArithmeticDecoder(data, start, end) {
  37758. this.data = data;
  37759. this.bp = start;
  37760. this.dataEnd = end;
  37761. this.chigh = data[start];
  37762. this.clow = 0;
  37763. this.byteIn();
  37764. this.chigh = ((this.chigh << 7) & 0xFFFF) | ((this.clow >> 9) & 0x7F);
  37765. this.clow = (this.clow << 7) & 0xFFFF;
  37766. this.ct -= 7;
  37767. this.a = 0x8000;
  37768. }
  37769. ArithmeticDecoder.prototype = {
  37770. // C.3.4 Compressed data input (BYTEIN)
  37771. byteIn: function ArithmeticDecoder_byteIn() {
  37772. var data = this.data;
  37773. var bp = this.bp;
  37774. if (data[bp] === 0xFF) {
  37775. var b1 = data[bp + 1];
  37776. if (b1 > 0x8F) {
  37777. this.clow += 0xFF00;
  37778. this.ct = 8;
  37779. } else {
  37780. bp++;
  37781. this.clow += (data[bp] << 9);
  37782. this.ct = 7;
  37783. this.bp = bp;
  37784. }
  37785. } else {
  37786. bp++;
  37787. this.clow += bp < this.dataEnd ? (data[bp] << 8) : 0xFF00;
  37788. this.ct = 8;
  37789. this.bp = bp;
  37790. }
  37791. if (this.clow > 0xFFFF) {
  37792. this.chigh += (this.clow >> 16);
  37793. this.clow &= 0xFFFF;
  37794. }
  37795. },
  37796. // C.3.2 Decoding a decision (DECODE)
  37797. readBit: function ArithmeticDecoder_readBit(contexts, pos) {
  37798. // contexts are packed into 1 byte:
  37799. // highest 7 bits carry cx.index, lowest bit carries cx.mps
  37800. var cx_index = contexts[pos] >> 1, cx_mps = contexts[pos] & 1;
  37801. var qeTableIcx = QeTable[cx_index];
  37802. var qeIcx = qeTableIcx.qe;
  37803. var d;
  37804. var a = this.a - qeIcx;
  37805. if (this.chigh < qeIcx) {
  37806. // exchangeLps
  37807. if (a < qeIcx) {
  37808. a = qeIcx;
  37809. d = cx_mps;
  37810. cx_index = qeTableIcx.nmps;
  37811. } else {
  37812. a = qeIcx;
  37813. d = 1 ^ cx_mps;
  37814. if (qeTableIcx.switchFlag === 1) {
  37815. cx_mps = d;
  37816. }
  37817. cx_index = qeTableIcx.nlps;
  37818. }
  37819. } else {
  37820. this.chigh -= qeIcx;
  37821. if ((a & 0x8000) !== 0) {
  37822. this.a = a;
  37823. return cx_mps;
  37824. }
  37825. // exchangeMps
  37826. if (a < qeIcx) {
  37827. d = 1 ^ cx_mps;
  37828. if (qeTableIcx.switchFlag === 1) {
  37829. cx_mps = d;
  37830. }
  37831. cx_index = qeTableIcx.nlps;
  37832. } else {
  37833. d = cx_mps;
  37834. cx_index = qeTableIcx.nmps;
  37835. }
  37836. }
  37837. // C.3.3 renormD;
  37838. do {
  37839. if (this.ct === 0) {
  37840. this.byteIn();
  37841. }
  37842. a <<= 1;
  37843. this.chigh = ((this.chigh << 1) & 0xFFFF) | ((this.clow >> 15) & 1);
  37844. this.clow = (this.clow << 1) & 0xFFFF;
  37845. this.ct--;
  37846. } while ((a & 0x8000) === 0);
  37847. this.a = a;
  37848. contexts[pos] = cx_index << 1 | cx_mps;
  37849. return d;
  37850. }
  37851. };
  37852. return ArithmeticDecoder;
  37853. })();
  37854. var JpegImage = (function jpegImage() {
  37855. var dctZigZag = new Uint8Array([
  37856. 0,
  37857. 1, 8,
  37858. 16, 9, 2,
  37859. 3, 10, 17, 24,
  37860. 32, 25, 18, 11, 4,
  37861. 5, 12, 19, 26, 33, 40,
  37862. 48, 41, 34, 27, 20, 13, 6,
  37863. 7, 14, 21, 28, 35, 42, 49, 56,
  37864. 57, 50, 43, 36, 29, 22, 15,
  37865. 23, 30, 37, 44, 51, 58,
  37866. 59, 52, 45, 38, 31,
  37867. 39, 46, 53, 60,
  37868. 61, 54, 47,
  37869. 55, 62,
  37870. 63
  37871. ]);
  37872. var dctCos1 = 4017; // cos(pi/16)
  37873. var dctSin1 = 799; // sin(pi/16)
  37874. var dctCos3 = 3406; // cos(3*pi/16)
  37875. var dctSin3 = 2276; // sin(3*pi/16)
  37876. var dctCos6 = 1567; // cos(6*pi/16)
  37877. var dctSin6 = 3784; // sin(6*pi/16)
  37878. var dctSqrt2 = 5793; // sqrt(2)
  37879. var dctSqrt1d2 = 2896; // sqrt(2) / 2
  37880. function constructor() {
  37881. }
  37882. function buildHuffmanTable(codeLengths, values) {
  37883. var k = 0, code = [], i, j, length = 16;
  37884. while (length > 0 && !codeLengths[length - 1]) {
  37885. length--;
  37886. }
  37887. code.push({children: [], index: 0});
  37888. var p = code[0], q;
  37889. for (i = 0; i < length; i++) {
  37890. for (j = 0; j < codeLengths[i]; j++) {
  37891. p = code.pop();
  37892. p.children[p.index] = values[k];
  37893. while (p.index > 0) {
  37894. p = code.pop();
  37895. }
  37896. p.index++;
  37897. code.push(p);
  37898. while (code.length <= i) {
  37899. code.push(q = {children: [], index: 0});
  37900. p.children[p.index] = q.children;
  37901. p = q;
  37902. }
  37903. k++;
  37904. }
  37905. if (i + 1 < length) {
  37906. // p here points to last code
  37907. code.push(q = {children: [], index: 0});
  37908. p.children[p.index] = q.children;
  37909. p = q;
  37910. }
  37911. }
  37912. return code[0].children;
  37913. }
  37914. function getBlockBufferOffset(component, row, col) {
  37915. return 64 * ((component.blocksPerLine + 1) * row + col);
  37916. }
  37917. function decodeScan(data, offset, frame, components, resetInterval,
  37918. spectralStart, spectralEnd, successivePrev, successive) {
  37919. var precision = frame.precision;
  37920. var samplesPerLine = frame.samplesPerLine;
  37921. var scanLines = frame.scanLines;
  37922. var mcusPerLine = frame.mcusPerLine;
  37923. var progressive = frame.progressive;
  37924. var maxH = frame.maxH, maxV = frame.maxV;
  37925. var startOffset = offset, bitsData = 0, bitsCount = 0;
  37926. function readBit() {
  37927. if (bitsCount > 0) {
  37928. bitsCount--;
  37929. return (bitsData >> bitsCount) & 1;
  37930. }
  37931. bitsData = data[offset++];
  37932. if (bitsData === 0xFF) {
  37933. var nextByte = data[offset++];
  37934. if (nextByte) {
  37935. throw 'unexpected marker: ' +
  37936. ((bitsData << 8) | nextByte).toString(16);
  37937. }
  37938. // unstuff 0
  37939. }
  37940. bitsCount = 7;
  37941. return bitsData >>> 7;
  37942. }
  37943. function decodeHuffman(tree) {
  37944. var node = tree;
  37945. while (true) {
  37946. node = node[readBit()];
  37947. if (typeof node === 'number') {
  37948. return node;
  37949. }
  37950. if (typeof node !== 'object') {
  37951. throw 'invalid huffman sequence';
  37952. }
  37953. }
  37954. }
  37955. function receive(length) {
  37956. var n = 0;
  37957. while (length > 0) {
  37958. n = (n << 1) | readBit();
  37959. length--;
  37960. }
  37961. return n;
  37962. }
  37963. function receiveAndExtend(length) {
  37964. if (length === 1) {
  37965. return readBit() === 1 ? 1 : -1;
  37966. }
  37967. var n = receive(length);
  37968. if (n >= 1 << (length - 1)) {
  37969. return n;
  37970. }
  37971. return n + (-1 << length) + 1;
  37972. }
  37973. function decodeBaseline(component, offset) {
  37974. var t = decodeHuffman(component.huffmanTableDC);
  37975. var diff = t === 0 ? 0 : receiveAndExtend(t);
  37976. component.blockData[offset] = (component.pred += diff);
  37977. var k = 1;
  37978. while (k < 64) {
  37979. var rs = decodeHuffman(component.huffmanTableAC);
  37980. var s = rs & 15, r = rs >> 4;
  37981. if (s === 0) {
  37982. if (r < 15) {
  37983. break;
  37984. }
  37985. k += 16;
  37986. continue;
  37987. }
  37988. k += r;
  37989. var z = dctZigZag[k];
  37990. component.blockData[offset + z] = receiveAndExtend(s);
  37991. k++;
  37992. }
  37993. }
  37994. function decodeDCFirst(component, offset) {
  37995. var t = decodeHuffman(component.huffmanTableDC);
  37996. var diff = t === 0 ? 0 : (receiveAndExtend(t) << successive);
  37997. component.blockData[offset] = (component.pred += diff);
  37998. }
  37999. function decodeDCSuccessive(component, offset) {
  38000. component.blockData[offset] |= readBit() << successive;
  38001. }
  38002. var eobrun = 0;
  38003. function decodeACFirst(component, offset) {
  38004. if (eobrun > 0) {
  38005. eobrun--;
  38006. return;
  38007. }
  38008. var k = spectralStart, e = spectralEnd;
  38009. while (k <= e) {
  38010. var rs = decodeHuffman(component.huffmanTableAC);
  38011. var s = rs & 15, r = rs >> 4;
  38012. if (s === 0) {
  38013. if (r < 15) {
  38014. eobrun = receive(r) + (1 << r) - 1;
  38015. break;
  38016. }
  38017. k += 16;
  38018. continue;
  38019. }
  38020. k += r;
  38021. var z = dctZigZag[k];
  38022. component.blockData[offset + z] =
  38023. receiveAndExtend(s) * (1 << successive);
  38024. k++;
  38025. }
  38026. }
  38027. var successiveACState = 0, successiveACNextValue;
  38028. function decodeACSuccessive(component, offset) {
  38029. var k = spectralStart;
  38030. var e = spectralEnd;
  38031. var r = 0;
  38032. var s;
  38033. var rs;
  38034. while (k <= e) {
  38035. var z = dctZigZag[k];
  38036. switch (successiveACState) {
  38037. case 0: // initial state
  38038. rs = decodeHuffman(component.huffmanTableAC);
  38039. s = rs & 15;
  38040. r = rs >> 4;
  38041. if (s === 0) {
  38042. if (r < 15) {
  38043. eobrun = receive(r) + (1 << r);
  38044. successiveACState = 4;
  38045. } else {
  38046. r = 16;
  38047. successiveACState = 1;
  38048. }
  38049. } else {
  38050. if (s !== 1) {
  38051. throw 'invalid ACn encoding';
  38052. }
  38053. successiveACNextValue = receiveAndExtend(s);
  38054. successiveACState = r ? 2 : 3;
  38055. }
  38056. continue;
  38057. case 1: // skipping r zero items
  38058. case 2:
  38059. if (component.blockData[offset + z]) {
  38060. component.blockData[offset + z] += (readBit() << successive);
  38061. } else {
  38062. r--;
  38063. if (r === 0) {
  38064. successiveACState = successiveACState === 2 ? 3 : 0;
  38065. }
  38066. }
  38067. break;
  38068. case 3: // set value for a zero item
  38069. if (component.blockData[offset + z]) {
  38070. component.blockData[offset + z] += (readBit() << successive);
  38071. } else {
  38072. component.blockData[offset + z] =
  38073. successiveACNextValue << successive;
  38074. successiveACState = 0;
  38075. }
  38076. break;
  38077. case 4: // eob
  38078. if (component.blockData[offset + z]) {
  38079. component.blockData[offset + z] += (readBit() << successive);
  38080. }
  38081. break;
  38082. }
  38083. k++;
  38084. }
  38085. if (successiveACState === 4) {
  38086. eobrun--;
  38087. if (eobrun === 0) {
  38088. successiveACState = 0;
  38089. }
  38090. }
  38091. }
  38092. function decodeMcu(component, decode, mcu, row, col) {
  38093. var mcuRow = (mcu / mcusPerLine) | 0;
  38094. var mcuCol = mcu % mcusPerLine;
  38095. var blockRow = mcuRow * component.v + row;
  38096. var blockCol = mcuCol * component.h + col;
  38097. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  38098. decode(component, offset);
  38099. }
  38100. function decodeBlock(component, decode, mcu) {
  38101. var blockRow = (mcu / component.blocksPerLine) | 0;
  38102. var blockCol = mcu % component.blocksPerLine;
  38103. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  38104. decode(component, offset);
  38105. }
  38106. var componentsLength = components.length;
  38107. var component, i, j, k, n;
  38108. var decodeFn;
  38109. if (progressive) {
  38110. if (spectralStart === 0) {
  38111. decodeFn = successivePrev === 0 ? decodeDCFirst : decodeDCSuccessive;
  38112. } else {
  38113. decodeFn = successivePrev === 0 ? decodeACFirst : decodeACSuccessive;
  38114. }
  38115. } else {
  38116. decodeFn = decodeBaseline;
  38117. }
  38118. var mcu = 0, marker;
  38119. var mcuExpected;
  38120. if (componentsLength === 1) {
  38121. mcuExpected = components[0].blocksPerLine * components[0].blocksPerColumn;
  38122. } else {
  38123. mcuExpected = mcusPerLine * frame.mcusPerColumn;
  38124. }
  38125. if (!resetInterval) {
  38126. resetInterval = mcuExpected;
  38127. }
  38128. var h, v;
  38129. while (mcu < mcuExpected) {
  38130. // reset interval stuff
  38131. for (i = 0; i < componentsLength; i++) {
  38132. components[i].pred = 0;
  38133. }
  38134. eobrun = 0;
  38135. if (componentsLength === 1) {
  38136. component = components[0];
  38137. for (n = 0; n < resetInterval; n++) {
  38138. decodeBlock(component, decodeFn, mcu);
  38139. mcu++;
  38140. }
  38141. } else {
  38142. for (n = 0; n < resetInterval; n++) {
  38143. for (i = 0; i < componentsLength; i++) {
  38144. component = components[i];
  38145. h = component.h;
  38146. v = component.v;
  38147. for (j = 0; j < v; j++) {
  38148. for (k = 0; k < h; k++) {
  38149. decodeMcu(component, decodeFn, mcu, j, k);
  38150. }
  38151. }
  38152. }
  38153. mcu++;
  38154. }
  38155. }
  38156. // find marker
  38157. bitsCount = 0;
  38158. marker = (data[offset] << 8) | data[offset + 1];
  38159. if (marker <= 0xFF00) {
  38160. throw 'marker was not found';
  38161. }
  38162. if (marker >= 0xFFD0 && marker <= 0xFFD7) { // RSTx
  38163. offset += 2;
  38164. } else {
  38165. break;
  38166. }
  38167. }
  38168. return offset - startOffset;
  38169. }
  38170. // A port of poppler's IDCT method which in turn is taken from:
  38171. // Christoph Loeffler, Adriaan Ligtenberg, George S. Moschytz,
  38172. // 'Practical Fast 1-D DCT Algorithms with 11 Multiplications',
  38173. // IEEE Intl. Conf. on Acoustics, Speech & Signal Processing, 1989,
  38174. // 988-991.
  38175. function quantizeAndInverse(component, blockBufferOffset, p) {
  38176. var qt = component.quantizationTable, blockData = component.blockData;
  38177. var v0, v1, v2, v3, v4, v5, v6, v7;
  38178. var p0, p1, p2, p3, p4, p5, p6, p7;
  38179. var t;
  38180. // inverse DCT on rows
  38181. for (var row = 0; row < 64; row += 8) {
  38182. // gather block data
  38183. p0 = blockData[blockBufferOffset + row];
  38184. p1 = blockData[blockBufferOffset + row + 1];
  38185. p2 = blockData[blockBufferOffset + row + 2];
  38186. p3 = blockData[blockBufferOffset + row + 3];
  38187. p4 = blockData[blockBufferOffset + row + 4];
  38188. p5 = blockData[blockBufferOffset + row + 5];
  38189. p6 = blockData[blockBufferOffset + row + 6];
  38190. p7 = blockData[blockBufferOffset + row + 7];
  38191. // dequant p0
  38192. p0 *= qt[row];
  38193. // check for all-zero AC coefficients
  38194. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  38195. t = (dctSqrt2 * p0 + 512) >> 10;
  38196. p[row] = t;
  38197. p[row + 1] = t;
  38198. p[row + 2] = t;
  38199. p[row + 3] = t;
  38200. p[row + 4] = t;
  38201. p[row + 5] = t;
  38202. p[row + 6] = t;
  38203. p[row + 7] = t;
  38204. continue;
  38205. }
  38206. // dequant p1 ... p7
  38207. p1 *= qt[row + 1];
  38208. p2 *= qt[row + 2];
  38209. p3 *= qt[row + 3];
  38210. p4 *= qt[row + 4];
  38211. p5 *= qt[row + 5];
  38212. p6 *= qt[row + 6];
  38213. p7 *= qt[row + 7];
  38214. // stage 4
  38215. v0 = (dctSqrt2 * p0 + 128) >> 8;
  38216. v1 = (dctSqrt2 * p4 + 128) >> 8;
  38217. v2 = p2;
  38218. v3 = p6;
  38219. v4 = (dctSqrt1d2 * (p1 - p7) + 128) >> 8;
  38220. v7 = (dctSqrt1d2 * (p1 + p7) + 128) >> 8;
  38221. v5 = p3 << 4;
  38222. v6 = p5 << 4;
  38223. // stage 3
  38224. v0 = (v0 + v1 + 1) >> 1;
  38225. v1 = v0 - v1;
  38226. t = (v2 * dctSin6 + v3 * dctCos6 + 128) >> 8;
  38227. v2 = (v2 * dctCos6 - v3 * dctSin6 + 128) >> 8;
  38228. v3 = t;
  38229. v4 = (v4 + v6 + 1) >> 1;
  38230. v6 = v4 - v6;
  38231. v7 = (v7 + v5 + 1) >> 1;
  38232. v5 = v7 - v5;
  38233. // stage 2
  38234. v0 = (v0 + v3 + 1) >> 1;
  38235. v3 = v0 - v3;
  38236. v1 = (v1 + v2 + 1) >> 1;
  38237. v2 = v1 - v2;
  38238. t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12;
  38239. v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12;
  38240. v7 = t;
  38241. t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12;
  38242. v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12;
  38243. v6 = t;
  38244. // stage 1
  38245. p[row] = v0 + v7;
  38246. p[row + 7] = v0 - v7;
  38247. p[row + 1] = v1 + v6;
  38248. p[row + 6] = v1 - v6;
  38249. p[row + 2] = v2 + v5;
  38250. p[row + 5] = v2 - v5;
  38251. p[row + 3] = v3 + v4;
  38252. p[row + 4] = v3 - v4;
  38253. }
  38254. // inverse DCT on columns
  38255. for (var col = 0; col < 8; ++col) {
  38256. p0 = p[col];
  38257. p1 = p[col + 8];
  38258. p2 = p[col + 16];
  38259. p3 = p[col + 24];
  38260. p4 = p[col + 32];
  38261. p5 = p[col + 40];
  38262. p6 = p[col + 48];
  38263. p7 = p[col + 56];
  38264. // check for all-zero AC coefficients
  38265. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  38266. t = (dctSqrt2 * p0 + 8192) >> 14;
  38267. // convert to 8 bit
  38268. t = (t < -2040) ? 0 : (t >= 2024) ? 255 : (t + 2056) >> 4;
  38269. blockData[blockBufferOffset + col] = t;
  38270. blockData[blockBufferOffset + col + 8] = t;
  38271. blockData[blockBufferOffset + col + 16] = t;
  38272. blockData[blockBufferOffset + col + 24] = t;
  38273. blockData[blockBufferOffset + col + 32] = t;
  38274. blockData[blockBufferOffset + col + 40] = t;
  38275. blockData[blockBufferOffset + col + 48] = t;
  38276. blockData[blockBufferOffset + col + 56] = t;
  38277. continue;
  38278. }
  38279. // stage 4
  38280. v0 = (dctSqrt2 * p0 + 2048) >> 12;
  38281. v1 = (dctSqrt2 * p4 + 2048) >> 12;
  38282. v2 = p2;
  38283. v3 = p6;
  38284. v4 = (dctSqrt1d2 * (p1 - p7) + 2048) >> 12;
  38285. v7 = (dctSqrt1d2 * (p1 + p7) + 2048) >> 12;
  38286. v5 = p3;
  38287. v6 = p5;
  38288. // stage 3
  38289. // Shift v0 by 128.5 << 5 here, so we don't need to shift p0...p7 when
  38290. // converting to UInt8 range later.
  38291. v0 = ((v0 + v1 + 1) >> 1) + 4112;
  38292. v1 = v0 - v1;
  38293. t = (v2 * dctSin6 + v3 * dctCos6 + 2048) >> 12;
  38294. v2 = (v2 * dctCos6 - v3 * dctSin6 + 2048) >> 12;
  38295. v3 = t;
  38296. v4 = (v4 + v6 + 1) >> 1;
  38297. v6 = v4 - v6;
  38298. v7 = (v7 + v5 + 1) >> 1;
  38299. v5 = v7 - v5;
  38300. // stage 2
  38301. v0 = (v0 + v3 + 1) >> 1;
  38302. v3 = v0 - v3;
  38303. v1 = (v1 + v2 + 1) >> 1;
  38304. v2 = v1 - v2;
  38305. t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12;
  38306. v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12;
  38307. v7 = t;
  38308. t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12;
  38309. v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12;
  38310. v6 = t;
  38311. // stage 1
  38312. p0 = v0 + v7;
  38313. p7 = v0 - v7;
  38314. p1 = v1 + v6;
  38315. p6 = v1 - v6;
  38316. p2 = v2 + v5;
  38317. p5 = v2 - v5;
  38318. p3 = v3 + v4;
  38319. p4 = v3 - v4;
  38320. // convert to 8-bit integers
  38321. p0 = (p0 < 16) ? 0 : (p0 >= 4080) ? 255 : p0 >> 4;
  38322. p1 = (p1 < 16) ? 0 : (p1 >= 4080) ? 255 : p1 >> 4;
  38323. p2 = (p2 < 16) ? 0 : (p2 >= 4080) ? 255 : p2 >> 4;
  38324. p3 = (p3 < 16) ? 0 : (p3 >= 4080) ? 255 : p3 >> 4;
  38325. p4 = (p4 < 16) ? 0 : (p4 >= 4080) ? 255 : p4 >> 4;
  38326. p5 = (p5 < 16) ? 0 : (p5 >= 4080) ? 255 : p5 >> 4;
  38327. p6 = (p6 < 16) ? 0 : (p6 >= 4080) ? 255 : p6 >> 4;
  38328. p7 = (p7 < 16) ? 0 : (p7 >= 4080) ? 255 : p7 >> 4;
  38329. // store block data
  38330. blockData[blockBufferOffset + col] = p0;
  38331. blockData[blockBufferOffset + col + 8] = p1;
  38332. blockData[blockBufferOffset + col + 16] = p2;
  38333. blockData[blockBufferOffset + col + 24] = p3;
  38334. blockData[blockBufferOffset + col + 32] = p4;
  38335. blockData[blockBufferOffset + col + 40] = p5;
  38336. blockData[blockBufferOffset + col + 48] = p6;
  38337. blockData[blockBufferOffset + col + 56] = p7;
  38338. }
  38339. }
  38340. function buildComponentData(frame, component) {
  38341. var blocksPerLine = component.blocksPerLine;
  38342. var blocksPerColumn = component.blocksPerColumn;
  38343. var computationBuffer = new Int16Array(64);
  38344. for (var blockRow = 0; blockRow < blocksPerColumn; blockRow++) {
  38345. for (var blockCol = 0; blockCol < blocksPerLine; blockCol++) {
  38346. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  38347. quantizeAndInverse(component, offset, computationBuffer);
  38348. }
  38349. }
  38350. return component.blockData;
  38351. }
  38352. function clamp0to255(a) {
  38353. return a <= 0 ? 0 : a >= 255 ? 255 : a;
  38354. }
  38355. constructor.prototype = {
  38356. parse: function parse(data) {
  38357. function readUint16() {
  38358. var value = (data[offset] << 8) | data[offset + 1];
  38359. offset += 2;
  38360. return value;
  38361. }
  38362. function readDataBlock() {
  38363. var length = readUint16();
  38364. var array = data.subarray(offset, offset + length - 2);
  38365. offset += array.length;
  38366. return array;
  38367. }
  38368. function prepareComponents(frame) {
  38369. var mcusPerLine = Math.ceil(frame.samplesPerLine / 8 / frame.maxH);
  38370. var mcusPerColumn = Math.ceil(frame.scanLines / 8 / frame.maxV);
  38371. for (var i = 0; i < frame.components.length; i++) {
  38372. component = frame.components[i];
  38373. var blocksPerLine = Math.ceil(Math.ceil(frame.samplesPerLine / 8) *
  38374. component.h / frame.maxH);
  38375. var blocksPerColumn = Math.ceil(Math.ceil(frame.scanLines / 8) *
  38376. component.v / frame.maxV);
  38377. var blocksPerLineForMcu = mcusPerLine * component.h;
  38378. var blocksPerColumnForMcu = mcusPerColumn * component.v;
  38379. var blocksBufferSize = 64 * blocksPerColumnForMcu *
  38380. (blocksPerLineForMcu + 1);
  38381. component.blockData = new Int16Array(blocksBufferSize);
  38382. component.blocksPerLine = blocksPerLine;
  38383. component.blocksPerColumn = blocksPerColumn;
  38384. }
  38385. frame.mcusPerLine = mcusPerLine;
  38386. frame.mcusPerColumn = mcusPerColumn;
  38387. }
  38388. var offset = 0, length = data.length;
  38389. var jfif = null;
  38390. var adobe = null;
  38391. var pixels = null;
  38392. var frame, resetInterval;
  38393. var quantizationTables = [];
  38394. var huffmanTablesAC = [], huffmanTablesDC = [];
  38395. var fileMarker = readUint16();
  38396. if (fileMarker !== 0xFFD8) { // SOI (Start of Image)
  38397. throw 'SOI not found';
  38398. }
  38399. fileMarker = readUint16();
  38400. while (fileMarker !== 0xFFD9) { // EOI (End of image)
  38401. var i, j, l;
  38402. switch(fileMarker) {
  38403. case 0xFFE0: // APP0 (Application Specific)
  38404. case 0xFFE1: // APP1
  38405. case 0xFFE2: // APP2
  38406. case 0xFFE3: // APP3
  38407. case 0xFFE4: // APP4
  38408. case 0xFFE5: // APP5
  38409. case 0xFFE6: // APP6
  38410. case 0xFFE7: // APP7
  38411. case 0xFFE8: // APP8
  38412. case 0xFFE9: // APP9
  38413. case 0xFFEA: // APP10
  38414. case 0xFFEB: // APP11
  38415. case 0xFFEC: // APP12
  38416. case 0xFFED: // APP13
  38417. case 0xFFEE: // APP14
  38418. case 0xFFEF: // APP15
  38419. case 0xFFFE: // COM (Comment)
  38420. var appData = readDataBlock();
  38421. if (fileMarker === 0xFFE0) {
  38422. if (appData[0] === 0x4A && appData[1] === 0x46 &&
  38423. appData[2] === 0x49 && appData[3] === 0x46 &&
  38424. appData[4] === 0) { // 'JFIF\x00'
  38425. jfif = {
  38426. version: { major: appData[5], minor: appData[6] },
  38427. densityUnits: appData[7],
  38428. xDensity: (appData[8] << 8) | appData[9],
  38429. yDensity: (appData[10] << 8) | appData[11],
  38430. thumbWidth: appData[12],
  38431. thumbHeight: appData[13],
  38432. thumbData: appData.subarray(14, 14 +
  38433. 3 * appData[12] * appData[13])
  38434. };
  38435. }
  38436. }
  38437. // TODO APP1 - Exif
  38438. if (fileMarker === 0xFFEE) {
  38439. if (appData[0] === 0x41 && appData[1] === 0x64 &&
  38440. appData[2] === 0x6F && appData[3] === 0x62 &&
  38441. appData[4] === 0x65) { // 'Adobe'
  38442. adobe = {
  38443. version: (appData[5] << 8) | appData[6],
  38444. flags0: (appData[7] << 8) | appData[8],
  38445. flags1: (appData[9] << 8) | appData[10],
  38446. transformCode: appData[11]
  38447. };
  38448. }
  38449. }
  38450. break;
  38451. case 0xFFDB: // DQT (Define Quantization Tables)
  38452. var quantizationTablesLength = readUint16();
  38453. var quantizationTablesEnd = quantizationTablesLength + offset - 2;
  38454. var z;
  38455. while (offset < quantizationTablesEnd) {
  38456. var quantizationTableSpec = data[offset++];
  38457. var tableData = new Uint16Array(64);
  38458. if ((quantizationTableSpec >> 4) === 0) { // 8 bit values
  38459. for (j = 0; j < 64; j++) {
  38460. z = dctZigZag[j];
  38461. tableData[z] = data[offset++];
  38462. }
  38463. } else if ((quantizationTableSpec >> 4) === 1) { //16 bit
  38464. for (j = 0; j < 64; j++) {
  38465. z = dctZigZag[j];
  38466. tableData[z] = readUint16();
  38467. }
  38468. } else {
  38469. throw 'DQT: invalid table spec';
  38470. }
  38471. quantizationTables[quantizationTableSpec & 15] = tableData;
  38472. }
  38473. break;
  38474. case 0xFFC0: // SOF0 (Start of Frame, Baseline DCT)
  38475. case 0xFFC1: // SOF1 (Start of Frame, Extended DCT)
  38476. case 0xFFC2: // SOF2 (Start of Frame, Progressive DCT)
  38477. if (frame) {
  38478. throw 'Only single frame JPEGs supported';
  38479. }
  38480. readUint16(); // skip data length
  38481. frame = {};
  38482. frame.extended = (fileMarker === 0xFFC1);
  38483. frame.progressive = (fileMarker === 0xFFC2);
  38484. frame.precision = data[offset++];
  38485. frame.scanLines = readUint16();
  38486. frame.samplesPerLine = readUint16();
  38487. frame.components = [];
  38488. frame.componentIds = {};
  38489. var componentsCount = data[offset++], componentId;
  38490. var maxH = 0, maxV = 0;
  38491. for (i = 0; i < componentsCount; i++) {
  38492. componentId = data[offset];
  38493. var h = data[offset + 1] >> 4;
  38494. var v = data[offset + 1] & 15;
  38495. if (maxH < h) {
  38496. maxH = h;
  38497. }
  38498. if (maxV < v) {
  38499. maxV = v;
  38500. }
  38501. var qId = data[offset + 2];
  38502. l = frame.components.push({
  38503. h: h,
  38504. v: v,
  38505. quantizationTable: quantizationTables[qId]
  38506. });
  38507. frame.componentIds[componentId] = l - 1;
  38508. offset += 3;
  38509. }
  38510. frame.maxH = maxH;
  38511. frame.maxV = maxV;
  38512. prepareComponents(frame);
  38513. break;
  38514. case 0xFFC4: // DHT (Define Huffman Tables)
  38515. var huffmanLength = readUint16();
  38516. for (i = 2; i < huffmanLength;) {
  38517. var huffmanTableSpec = data[offset++];
  38518. var codeLengths = new Uint8Array(16);
  38519. var codeLengthSum = 0;
  38520. for (j = 0; j < 16; j++, offset++) {
  38521. codeLengthSum += (codeLengths[j] = data[offset]);
  38522. }
  38523. var huffmanValues = new Uint8Array(codeLengthSum);
  38524. for (j = 0; j < codeLengthSum; j++, offset++) {
  38525. huffmanValues[j] = data[offset];
  38526. }
  38527. i += 17 + codeLengthSum;
  38528. ((huffmanTableSpec >> 4) === 0 ?
  38529. huffmanTablesDC : huffmanTablesAC)[huffmanTableSpec & 15] =
  38530. buildHuffmanTable(codeLengths, huffmanValues);
  38531. }
  38532. break;
  38533. case 0xFFDD: // DRI (Define Restart Interval)
  38534. readUint16(); // skip data length
  38535. resetInterval = readUint16();
  38536. break;
  38537. case 0xFFDA: // SOS (Start of Scan)
  38538. var scanLength = readUint16();
  38539. var selectorsCount = data[offset++];
  38540. var components = [], component;
  38541. for (i = 0; i < selectorsCount; i++) {
  38542. var componentIndex = frame.componentIds[data[offset++]];
  38543. component = frame.components[componentIndex];
  38544. var tableSpec = data[offset++];
  38545. component.huffmanTableDC = huffmanTablesDC[tableSpec >> 4];
  38546. component.huffmanTableAC = huffmanTablesAC[tableSpec & 15];
  38547. components.push(component);
  38548. }
  38549. var spectralStart = data[offset++];
  38550. var spectralEnd = data[offset++];
  38551. var successiveApproximation = data[offset++];
  38552. var processed = decodeScan(data, offset,
  38553. frame, components, resetInterval,
  38554. spectralStart, spectralEnd,
  38555. successiveApproximation >> 4, successiveApproximation & 15);
  38556. offset += processed;
  38557. break;
  38558. case 0xFFFF: // Fill bytes
  38559. if (data[offset] !== 0xFF) { // Avoid skipping a valid marker.
  38560. offset--;
  38561. }
  38562. break;
  38563. default:
  38564. if (data[offset - 3] === 0xFF &&
  38565. data[offset - 2] >= 0xC0 && data[offset - 2] <= 0xFE) {
  38566. // could be incorrect encoding -- last 0xFF byte of the previous
  38567. // block was eaten by the encoder
  38568. offset -= 3;
  38569. break;
  38570. }
  38571. throw 'unknown JPEG marker ' + fileMarker.toString(16);
  38572. }
  38573. fileMarker = readUint16();
  38574. }
  38575. this.width = frame.samplesPerLine;
  38576. this.height = frame.scanLines;
  38577. this.jfif = jfif;
  38578. this.adobe = adobe;
  38579. this.components = [];
  38580. for (i = 0; i < frame.components.length; i++) {
  38581. component = frame.components[i];
  38582. this.components.push({
  38583. output: buildComponentData(frame, component),
  38584. scaleX: component.h / frame.maxH,
  38585. scaleY: component.v / frame.maxV,
  38586. blocksPerLine: component.blocksPerLine,
  38587. blocksPerColumn: component.blocksPerColumn
  38588. });
  38589. }
  38590. this.numComponents = this.components.length;
  38591. },
  38592. _getLinearizedBlockData: function getLinearizedBlockData(width, height) {
  38593. var scaleX = this.width / width, scaleY = this.height / height;
  38594. var component, componentScaleX, componentScaleY, blocksPerScanline;
  38595. var x, y, i, j, k;
  38596. var index;
  38597. var offset = 0;
  38598. var output;
  38599. var numComponents = this.components.length;
  38600. var dataLength = width * height * numComponents;
  38601. var data = new Uint8Array(dataLength);
  38602. var xScaleBlockOffset = new Uint32Array(width);
  38603. var mask3LSB = 0xfffffff8; // used to clear the 3 LSBs
  38604. for (i = 0; i < numComponents; i++) {
  38605. component = this.components[i];
  38606. componentScaleX = component.scaleX * scaleX;
  38607. componentScaleY = component.scaleY * scaleY;
  38608. offset = i;
  38609. output = component.output;
  38610. blocksPerScanline = (component.blocksPerLine + 1) << 3;
  38611. // precalculate the xScaleBlockOffset
  38612. for (x = 0; x < width; x++) {
  38613. j = 0 | (x * componentScaleX);
  38614. xScaleBlockOffset[x] = ((j & mask3LSB) << 3) | (j & 7);
  38615. }
  38616. // linearize the blocks of the component
  38617. for (y = 0; y < height; y++) {
  38618. j = 0 | (y * componentScaleY);
  38619. index = blocksPerScanline * (j & mask3LSB) | ((j & 7) << 3);
  38620. for (x = 0; x < width; x++) {
  38621. data[offset] = output[index + xScaleBlockOffset[x]];
  38622. offset += numComponents;
  38623. }
  38624. }
  38625. }
  38626. // decodeTransform contains pairs of multiplier (-256..256) and additive
  38627. var transform = this.decodeTransform;
  38628. if (transform) {
  38629. for (i = 0; i < dataLength;) {
  38630. for (j = 0, k = 0; j < numComponents; j++, i++, k += 2) {
  38631. data[i] = ((data[i] * transform[k]) >> 8) + transform[k + 1];
  38632. }
  38633. }
  38634. }
  38635. return data;
  38636. },
  38637. _isColorConversionNeeded: function isColorConversionNeeded() {
  38638. if (this.adobe && this.adobe.transformCode) {
  38639. // The adobe transform marker overrides any previous setting
  38640. return true;
  38641. } else if (this.numComponents === 3) {
  38642. return true;
  38643. } else {
  38644. return false;
  38645. }
  38646. },
  38647. _convertYccToRgb: function convertYccToRgb(data) {
  38648. var Y, Cb, Cr;
  38649. for (var i = 0, length = data.length; i < length; i += 3) {
  38650. Y = data[i ];
  38651. Cb = data[i + 1];
  38652. Cr = data[i + 2];
  38653. data[i ] = clamp0to255(Y - 179.456 + 1.402 * Cr);
  38654. data[i + 1] = clamp0to255(Y + 135.459 - 0.344 * Cb - 0.714 * Cr);
  38655. data[i + 2] = clamp0to255(Y - 226.816 + 1.772 * Cb);
  38656. }
  38657. return data;
  38658. },
  38659. _convertYcckToRgb: function convertYcckToRgb(data) {
  38660. var Y, Cb, Cr, k;
  38661. var offset = 0;
  38662. for (var i = 0, length = data.length; i < length; i += 4) {
  38663. Y = data[i];
  38664. Cb = data[i + 1];
  38665. Cr = data[i + 2];
  38666. k = data[i + 3];
  38667. var r = -122.67195406894 +
  38668. Cb * (-6.60635669420364e-5 * Cb + 0.000437130475926232 * Cr -
  38669. 5.4080610064599e-5 * Y + 0.00048449797120281 * k -
  38670. 0.154362151871126) +
  38671. Cr * (-0.000957964378445773 * Cr + 0.000817076911346625 * Y -
  38672. 0.00477271405408747 * k + 1.53380253221734) +
  38673. Y * (0.000961250184130688 * Y - 0.00266257332283933 * k +
  38674. 0.48357088451265) +
  38675. k * (-0.000336197177618394 * k + 0.484791561490776);
  38676. var g = 107.268039397724 +
  38677. Cb * (2.19927104525741e-5 * Cb - 0.000640992018297945 * Cr +
  38678. 0.000659397001245577 * Y + 0.000426105652938837 * k -
  38679. 0.176491792462875) +
  38680. Cr * (-0.000778269941513683 * Cr + 0.00130872261408275 * Y +
  38681. 0.000770482631801132 * k - 0.151051492775562) +
  38682. Y * (0.00126935368114843 * Y - 0.00265090189010898 * k +
  38683. 0.25802910206845) +
  38684. k * (-0.000318913117588328 * k - 0.213742400323665);
  38685. var b = -20.810012546947 +
  38686. Cb * (-0.000570115196973677 * Cb - 2.63409051004589e-5 * Cr +
  38687. 0.0020741088115012 * Y - 0.00288260236853442 * k +
  38688. 0.814272968359295) +
  38689. Cr * (-1.53496057440975e-5 * Cr - 0.000132689043961446 * Y +
  38690. 0.000560833691242812 * k - 0.195152027534049) +
  38691. Y * (0.00174418132927582 * Y - 0.00255243321439347 * k +
  38692. 0.116935020465145) +
  38693. k * (-0.000343531996510555 * k + 0.24165260232407);
  38694. data[offset++] = clamp0to255(r);
  38695. data[offset++] = clamp0to255(g);
  38696. data[offset++] = clamp0to255(b);
  38697. }
  38698. return data;
  38699. },
  38700. _convertYcckToCmyk: function convertYcckToCmyk(data) {
  38701. var Y, Cb, Cr;
  38702. for (var i = 0, length = data.length; i < length; i += 4) {
  38703. Y = data[i];
  38704. Cb = data[i + 1];
  38705. Cr = data[i + 2];
  38706. data[i ] = clamp0to255(434.456 - Y - 1.402 * Cr);
  38707. data[i + 1] = clamp0to255(119.541 - Y + 0.344 * Cb + 0.714 * Cr);
  38708. data[i + 2] = clamp0to255(481.816 - Y - 1.772 * Cb);
  38709. // K in data[i + 3] is unchanged
  38710. }
  38711. return data;
  38712. },
  38713. _convertCmykToRgb: function convertCmykToRgb(data) {
  38714. var c, m, y, k;
  38715. var offset = 0;
  38716. var min = -255 * 255 * 255;
  38717. var scale = 1 / 255 / 255;
  38718. for (var i = 0, length = data.length; i < length; i += 4) {
  38719. c = data[i];
  38720. m = data[i + 1];
  38721. y = data[i + 2];
  38722. k = data[i + 3];
  38723. var r =
  38724. c * (-4.387332384609988 * c + 54.48615194189176 * m +
  38725. 18.82290502165302 * y + 212.25662451639585 * k -
  38726. 72734.4411664936) +
  38727. m * (1.7149763477362134 * m - 5.6096736904047315 * y -
  38728. 17.873870861415444 * k - 1401.7366389350734) +
  38729. y * (-2.5217340131683033 * y - 21.248923337353073 * k +
  38730. 4465.541406466231) -
  38731. k * (21.86122147463605 * k + 48317.86113160301);
  38732. var g =
  38733. c * (8.841041422036149 * c + 60.118027045597366 * m +
  38734. 6.871425592049007 * y + 31.159100130055922 * k -
  38735. 20220.756542821975) +
  38736. m * (-15.310361306967817 * m + 17.575251261109482 * y +
  38737. 131.35250912493976 * k - 48691.05921601825) +
  38738. y * (4.444339102852739 * y + 9.8632861493405 * k -
  38739. 6341.191035517494) -
  38740. k * (20.737325471181034 * k + 47890.15695978492);
  38741. var b =
  38742. c * (0.8842522430003296 * c + 8.078677503112928 * m +
  38743. 30.89978309703729 * y - 0.23883238689178934 * k -
  38744. 3616.812083916688) +
  38745. m * (10.49593273432072 * m + 63.02378494754052 * y +
  38746. 50.606957656360734 * k - 28620.90484698408) +
  38747. y * (0.03296041114873217 * y + 115.60384449646641 * k -
  38748. 49363.43385999684) -
  38749. k * (22.33816807309886 * k + 45932.16563550634);
  38750. data[offset++] = r >= 0 ? 255 : r <= min ? 0 : 255 + r * scale | 0;
  38751. data[offset++] = g >= 0 ? 255 : g <= min ? 0 : 255 + g * scale | 0;
  38752. data[offset++] = b >= 0 ? 255 : b <= min ? 0 : 255 + b * scale | 0;
  38753. }
  38754. return data;
  38755. },
  38756. getData: function getData(width, height, forceRGBoutput) {
  38757. if (this.numComponents > 4) {
  38758. throw 'Unsupported color mode';
  38759. }
  38760. // type of data: Uint8Array(width * height * numComponents)
  38761. var data = this._getLinearizedBlockData(width, height);
  38762. if (this.numComponents === 3) {
  38763. return this._convertYccToRgb(data);
  38764. } else if (this.numComponents === 4) {
  38765. if (this._isColorConversionNeeded()) {
  38766. if (forceRGBoutput) {
  38767. return this._convertYcckToRgb(data);
  38768. } else {
  38769. return this._convertYcckToCmyk(data);
  38770. }
  38771. } else if (forceRGBoutput) {
  38772. return this._convertCmykToRgb(data);
  38773. }
  38774. }
  38775. return data;
  38776. }
  38777. };
  38778. return constructor;
  38779. })();
  38780. var JpxImage = (function JpxImageClosure() {
  38781. // Table E.1
  38782. var SubbandsGainLog2 = {
  38783. 'LL': 0,
  38784. 'LH': 1,
  38785. 'HL': 1,
  38786. 'HH': 2
  38787. };
  38788. function JpxImage() {
  38789. this.failOnCorruptedImage = false;
  38790. }
  38791. JpxImage.prototype = {
  38792. parse: function JpxImage_parse(data) {
  38793. var head = readUint16(data, 0);
  38794. // No box header, immediate start of codestream (SOC)
  38795. if (head === 0xFF4F) {
  38796. this.parseCodestream(data, 0, data.length);
  38797. return;
  38798. }
  38799. var position = 0, length = data.length;
  38800. while (position < length) {
  38801. var headerSize = 8;
  38802. var lbox = readUint32(data, position);
  38803. var tbox = readUint32(data, position + 4);
  38804. position += headerSize;
  38805. if (lbox === 1) {
  38806. // XLBox: read UInt64 according to spec.
  38807. // JavaScript's int precision of 53 bit should be sufficient here.
  38808. lbox = readUint32(data, position) * 4294967296 +
  38809. readUint32(data, position + 4);
  38810. position += 8;
  38811. headerSize += 8;
  38812. }
  38813. if (lbox === 0) {
  38814. lbox = length - position + headerSize;
  38815. }
  38816. if (lbox < headerSize) {
  38817. throw new Error('JPX Error: Invalid box field size');
  38818. }
  38819. var dataLength = lbox - headerSize;
  38820. var jumpDataLength = true;
  38821. switch (tbox) {
  38822. case 0x6A703268: // 'jp2h'
  38823. jumpDataLength = false; // parsing child boxes
  38824. break;
  38825. case 0x636F6C72: // 'colr'
  38826. // Colorspaces are not used, the CS from the PDF is used.
  38827. var method = data[position];
  38828. var precedence = data[position + 1];
  38829. var approximation = data[position + 2];
  38830. if (method === 1) {
  38831. // enumerated colorspace
  38832. var colorspace = readUint32(data, position + 3);
  38833. switch (colorspace) {
  38834. case 16: // this indicates a sRGB colorspace
  38835. case 17: // this indicates a grayscale colorspace
  38836. case 18: // this indicates a YUV colorspace
  38837. break;
  38838. default:
  38839. warn('Unknown colorspace ' + colorspace);
  38840. break;
  38841. }
  38842. } else if (method === 2) {
  38843. info('ICC profile not supported');
  38844. }
  38845. break;
  38846. case 0x6A703263: // 'jp2c'
  38847. this.parseCodestream(data, position, position + dataLength);
  38848. break;
  38849. case 0x6A502020: // 'jP\024\024'
  38850. if (0x0d0a870a !== readUint32(data, position)) {
  38851. warn('Invalid JP2 signature');
  38852. }
  38853. break;
  38854. // The following header types are valid but currently not used:
  38855. case 0x6A501A1A: // 'jP\032\032'
  38856. case 0x66747970: // 'ftyp'
  38857. case 0x72726571: // 'rreq'
  38858. case 0x72657320: // 'res '
  38859. case 0x69686472: // 'ihdr'
  38860. break;
  38861. default:
  38862. var headerType = String.fromCharCode((tbox >> 24) & 0xFF,
  38863. (tbox >> 16) & 0xFF,
  38864. (tbox >> 8) & 0xFF,
  38865. tbox & 0xFF);
  38866. warn('Unsupported header type ' + tbox + ' (' + headerType + ')');
  38867. break;
  38868. }
  38869. if (jumpDataLength) {
  38870. position += dataLength;
  38871. }
  38872. }
  38873. },
  38874. parseImageProperties: function JpxImage_parseImageProperties(stream) {
  38875. var newByte = stream.getByte();
  38876. while (newByte >= 0) {
  38877. var oldByte = newByte;
  38878. newByte = stream.getByte();
  38879. var code = (oldByte << 8) | newByte;
  38880. // Image and tile size (SIZ)
  38881. if (code === 0xFF51) {
  38882. stream.skip(4);
  38883. var Xsiz = stream.getInt32() >>> 0; // Byte 4
  38884. var Ysiz = stream.getInt32() >>> 0; // Byte 8
  38885. var XOsiz = stream.getInt32() >>> 0; // Byte 12
  38886. var YOsiz = stream.getInt32() >>> 0; // Byte 16
  38887. stream.skip(16);
  38888. var Csiz = stream.getUint16(); // Byte 36
  38889. this.width = Xsiz - XOsiz;
  38890. this.height = Ysiz - YOsiz;
  38891. this.componentsCount = Csiz;
  38892. // Results are always returned as Uint8Arrays
  38893. this.bitsPerComponent = 8;
  38894. return;
  38895. }
  38896. }
  38897. throw new Error('JPX Error: No size marker found in JPX stream');
  38898. },
  38899. parseCodestream: function JpxImage_parseCodestream(data, start, end) {
  38900. var context = {};
  38901. try {
  38902. var doNotRecover = false;
  38903. var position = start;
  38904. while (position + 1 < end) {
  38905. var code = readUint16(data, position);
  38906. position += 2;
  38907. var length = 0, j, sqcd, spqcds, spqcdSize, scalarExpounded, tile;
  38908. switch (code) {
  38909. case 0xFF4F: // Start of codestream (SOC)
  38910. context.mainHeader = true;
  38911. break;
  38912. case 0xFFD9: // End of codestream (EOC)
  38913. break;
  38914. case 0xFF51: // Image and tile size (SIZ)
  38915. length = readUint16(data, position);
  38916. var siz = {};
  38917. siz.Xsiz = readUint32(data, position + 4);
  38918. siz.Ysiz = readUint32(data, position + 8);
  38919. siz.XOsiz = readUint32(data, position + 12);
  38920. siz.YOsiz = readUint32(data, position + 16);
  38921. siz.XTsiz = readUint32(data, position + 20);
  38922. siz.YTsiz = readUint32(data, position + 24);
  38923. siz.XTOsiz = readUint32(data, position + 28);
  38924. siz.YTOsiz = readUint32(data, position + 32);
  38925. var componentsCount = readUint16(data, position + 36);
  38926. siz.Csiz = componentsCount;
  38927. var components = [];
  38928. j = position + 38;
  38929. for (var i = 0; i < componentsCount; i++) {
  38930. var component = {
  38931. precision: (data[j] & 0x7F) + 1,
  38932. isSigned: !!(data[j] & 0x80),
  38933. XRsiz: data[j + 1],
  38934. YRsiz: data[j + 1]
  38935. };
  38936. calculateComponentDimensions(component, siz);
  38937. components.push(component);
  38938. }
  38939. context.SIZ = siz;
  38940. context.components = components;
  38941. calculateTileGrids(context, components);
  38942. context.QCC = [];
  38943. context.COC = [];
  38944. break;
  38945. case 0xFF5C: // Quantization default (QCD)
  38946. length = readUint16(data, position);
  38947. var qcd = {};
  38948. j = position + 2;
  38949. sqcd = data[j++];
  38950. switch (sqcd & 0x1F) {
  38951. case 0:
  38952. spqcdSize = 8;
  38953. scalarExpounded = true;
  38954. break;
  38955. case 1:
  38956. spqcdSize = 16;
  38957. scalarExpounded = false;
  38958. break;
  38959. case 2:
  38960. spqcdSize = 16;
  38961. scalarExpounded = true;
  38962. break;
  38963. default:
  38964. throw new Error('JPX Error: Invalid SQcd value ' + sqcd);
  38965. }
  38966. qcd.noQuantization = (spqcdSize === 8);
  38967. qcd.scalarExpounded = scalarExpounded;
  38968. qcd.guardBits = sqcd >> 5;
  38969. spqcds = [];
  38970. while (j < length + position) {
  38971. var spqcd = {};
  38972. if (spqcdSize === 8) {
  38973. spqcd.epsilon = data[j++] >> 3;
  38974. spqcd.mu = 0;
  38975. } else {
  38976. spqcd.epsilon = data[j] >> 3;
  38977. spqcd.mu = ((data[j] & 0x7) << 8) | data[j + 1];
  38978. j += 2;
  38979. }
  38980. spqcds.push(spqcd);
  38981. }
  38982. qcd.SPqcds = spqcds;
  38983. if (context.mainHeader) {
  38984. context.QCD = qcd;
  38985. } else {
  38986. context.currentTile.QCD = qcd;
  38987. context.currentTile.QCC = [];
  38988. }
  38989. break;
  38990. case 0xFF5D: // Quantization component (QCC)
  38991. length = readUint16(data, position);
  38992. var qcc = {};
  38993. j = position + 2;
  38994. var cqcc;
  38995. if (context.SIZ.Csiz < 257) {
  38996. cqcc = data[j++];
  38997. } else {
  38998. cqcc = readUint16(data, j);
  38999. j += 2;
  39000. }
  39001. sqcd = data[j++];
  39002. switch (sqcd & 0x1F) {
  39003. case 0:
  39004. spqcdSize = 8;
  39005. scalarExpounded = true;
  39006. break;
  39007. case 1:
  39008. spqcdSize = 16;
  39009. scalarExpounded = false;
  39010. break;
  39011. case 2:
  39012. spqcdSize = 16;
  39013. scalarExpounded = true;
  39014. break;
  39015. default:
  39016. throw new Error('JPX Error: Invalid SQcd value ' + sqcd);
  39017. }
  39018. qcc.noQuantization = (spqcdSize === 8);
  39019. qcc.scalarExpounded = scalarExpounded;
  39020. qcc.guardBits = sqcd >> 5;
  39021. spqcds = [];
  39022. while (j < (length + position)) {
  39023. spqcd = {};
  39024. if (spqcdSize === 8) {
  39025. spqcd.epsilon = data[j++] >> 3;
  39026. spqcd.mu = 0;
  39027. } else {
  39028. spqcd.epsilon = data[j] >> 3;
  39029. spqcd.mu = ((data[j] & 0x7) << 8) | data[j + 1];
  39030. j += 2;
  39031. }
  39032. spqcds.push(spqcd);
  39033. }
  39034. qcc.SPqcds = spqcds;
  39035. if (context.mainHeader) {
  39036. context.QCC[cqcc] = qcc;
  39037. } else {
  39038. context.currentTile.QCC[cqcc] = qcc;
  39039. }
  39040. break;
  39041. case 0xFF52: // Coding style default (COD)
  39042. length = readUint16(data, position);
  39043. var cod = {};
  39044. j = position + 2;
  39045. var scod = data[j++];
  39046. cod.entropyCoderWithCustomPrecincts = !!(scod & 1);
  39047. cod.sopMarkerUsed = !!(scod & 2);
  39048. cod.ephMarkerUsed = !!(scod & 4);
  39049. cod.progressionOrder = data[j++];
  39050. cod.layersCount = readUint16(data, j);
  39051. j += 2;
  39052. cod.multipleComponentTransform = data[j++];
  39053. cod.decompositionLevelsCount = data[j++];
  39054. cod.xcb = (data[j++] & 0xF) + 2;
  39055. cod.ycb = (data[j++] & 0xF) + 2;
  39056. var blockStyle = data[j++];
  39057. cod.selectiveArithmeticCodingBypass = !!(blockStyle & 1);
  39058. cod.resetContextProbabilities = !!(blockStyle & 2);
  39059. cod.terminationOnEachCodingPass = !!(blockStyle & 4);
  39060. cod.verticalyStripe = !!(blockStyle & 8);
  39061. cod.predictableTermination = !!(blockStyle & 16);
  39062. cod.segmentationSymbolUsed = !!(blockStyle & 32);
  39063. cod.reversibleTransformation = data[j++];
  39064. if (cod.entropyCoderWithCustomPrecincts) {
  39065. var precinctsSizes = [];
  39066. while (j < length + position) {
  39067. var precinctsSize = data[j++];
  39068. precinctsSizes.push({
  39069. PPx: precinctsSize & 0xF,
  39070. PPy: precinctsSize >> 4
  39071. });
  39072. }
  39073. cod.precinctsSizes = precinctsSizes;
  39074. }
  39075. var unsupported = [];
  39076. if (cod.selectiveArithmeticCodingBypass) {
  39077. unsupported.push('selectiveArithmeticCodingBypass');
  39078. }
  39079. if (cod.resetContextProbabilities) {
  39080. unsupported.push('resetContextProbabilities');
  39081. }
  39082. if (cod.terminationOnEachCodingPass) {
  39083. unsupported.push('terminationOnEachCodingPass');
  39084. }
  39085. if (cod.verticalyStripe) {
  39086. unsupported.push('verticalyStripe');
  39087. }
  39088. if (cod.predictableTermination) {
  39089. unsupported.push('predictableTermination');
  39090. }
  39091. if (unsupported.length > 0) {
  39092. doNotRecover = true;
  39093. throw new Error('JPX Error: Unsupported COD options (' +
  39094. unsupported.join(', ') + ')');
  39095. }
  39096. if (context.mainHeader) {
  39097. context.COD = cod;
  39098. } else {
  39099. context.currentTile.COD = cod;
  39100. context.currentTile.COC = [];
  39101. }
  39102. break;
  39103. case 0xFF90: // Start of tile-part (SOT)
  39104. length = readUint16(data, position);
  39105. tile = {};
  39106. tile.index = readUint16(data, position + 2);
  39107. tile.length = readUint32(data, position + 4);
  39108. tile.dataEnd = tile.length + position - 2;
  39109. tile.partIndex = data[position + 8];
  39110. tile.partsCount = data[position + 9];
  39111. context.mainHeader = false;
  39112. if (tile.partIndex === 0) {
  39113. // reset component specific settings
  39114. tile.COD = context.COD;
  39115. tile.COC = context.COC.slice(0); // clone of the global COC
  39116. tile.QCD = context.QCD;
  39117. tile.QCC = context.QCC.slice(0); // clone of the global COC
  39118. }
  39119. context.currentTile = tile;
  39120. break;
  39121. case 0xFF93: // Start of data (SOD)
  39122. tile = context.currentTile;
  39123. if (tile.partIndex === 0) {
  39124. initializeTile(context, tile.index);
  39125. buildPackets(context);
  39126. }
  39127. // moving to the end of the data
  39128. length = tile.dataEnd - position;
  39129. parseTilePackets(context, data, position, length);
  39130. break;
  39131. case 0xFF55: // Tile-part lengths, main header (TLM)
  39132. case 0xFF57: // Packet length, main header (PLM)
  39133. case 0xFF58: // Packet length, tile-part header (PLT)
  39134. case 0xFF64: // Comment (COM)
  39135. length = readUint16(data, position);
  39136. // skipping content
  39137. break;
  39138. case 0xFF53: // Coding style component (COC)
  39139. throw new Error('JPX Error: Codestream code 0xFF53 (COC) is ' +
  39140. 'not implemented');
  39141. default:
  39142. throw new Error('JPX Error: Unknown codestream code: ' +
  39143. code.toString(16));
  39144. }
  39145. position += length;
  39146. }
  39147. } catch (e) {
  39148. if (doNotRecover || this.failOnCorruptedImage) {
  39149. throw e;
  39150. } else {
  39151. warn('Trying to recover from ' + e.message);
  39152. }
  39153. }
  39154. this.tiles = transformComponents(context);
  39155. this.width = context.SIZ.Xsiz - context.SIZ.XOsiz;
  39156. this.height = context.SIZ.Ysiz - context.SIZ.YOsiz;
  39157. this.componentsCount = context.SIZ.Csiz;
  39158. }
  39159. };
  39160. function calculateComponentDimensions(component, siz) {
  39161. // Section B.2 Component mapping
  39162. component.x0 = Math.ceil(siz.XOsiz / component.XRsiz);
  39163. component.x1 = Math.ceil(siz.Xsiz / component.XRsiz);
  39164. component.y0 = Math.ceil(siz.YOsiz / component.YRsiz);
  39165. component.y1 = Math.ceil(siz.Ysiz / component.YRsiz);
  39166. component.width = component.x1 - component.x0;
  39167. component.height = component.y1 - component.y0;
  39168. }
  39169. function calculateTileGrids(context, components) {
  39170. var siz = context.SIZ;
  39171. // Section B.3 Division into tile and tile-components
  39172. var tile, tiles = [];
  39173. var numXtiles = Math.ceil((siz.Xsiz - siz.XTOsiz) / siz.XTsiz);
  39174. var numYtiles = Math.ceil((siz.Ysiz - siz.YTOsiz) / siz.YTsiz);
  39175. for (var q = 0; q < numYtiles; q++) {
  39176. for (var p = 0; p < numXtiles; p++) {
  39177. tile = {};
  39178. tile.tx0 = Math.max(siz.XTOsiz + p * siz.XTsiz, siz.XOsiz);
  39179. tile.ty0 = Math.max(siz.YTOsiz + q * siz.YTsiz, siz.YOsiz);
  39180. tile.tx1 = Math.min(siz.XTOsiz + (p + 1) * siz.XTsiz, siz.Xsiz);
  39181. tile.ty1 = Math.min(siz.YTOsiz + (q + 1) * siz.YTsiz, siz.Ysiz);
  39182. tile.width = tile.tx1 - tile.tx0;
  39183. tile.height = tile.ty1 - tile.ty0;
  39184. tile.components = [];
  39185. tiles.push(tile);
  39186. }
  39187. }
  39188. context.tiles = tiles;
  39189. var componentsCount = siz.Csiz;
  39190. for (var i = 0, ii = componentsCount; i < ii; i++) {
  39191. var component = components[i];
  39192. for (var j = 0, jj = tiles.length; j < jj; j++) {
  39193. var tileComponent = {};
  39194. tile = tiles[j];
  39195. tileComponent.tcx0 = Math.ceil(tile.tx0 / component.XRsiz);
  39196. tileComponent.tcy0 = Math.ceil(tile.ty0 / component.YRsiz);
  39197. tileComponent.tcx1 = Math.ceil(tile.tx1 / component.XRsiz);
  39198. tileComponent.tcy1 = Math.ceil(tile.ty1 / component.YRsiz);
  39199. tileComponent.width = tileComponent.tcx1 - tileComponent.tcx0;
  39200. tileComponent.height = tileComponent.tcy1 - tileComponent.tcy0;
  39201. tile.components[i] = tileComponent;
  39202. }
  39203. }
  39204. }
  39205. function getBlocksDimensions(context, component, r) {
  39206. var codOrCoc = component.codingStyleParameters;
  39207. var result = {};
  39208. if (!codOrCoc.entropyCoderWithCustomPrecincts) {
  39209. result.PPx = 15;
  39210. result.PPy = 15;
  39211. } else {
  39212. result.PPx = codOrCoc.precinctsSizes[r].PPx;
  39213. result.PPy = codOrCoc.precinctsSizes[r].PPy;
  39214. }
  39215. // calculate codeblock size as described in section B.7
  39216. result.xcb_ = (r > 0 ? Math.min(codOrCoc.xcb, result.PPx - 1) :
  39217. Math.min(codOrCoc.xcb, result.PPx));
  39218. result.ycb_ = (r > 0 ? Math.min(codOrCoc.ycb, result.PPy - 1) :
  39219. Math.min(codOrCoc.ycb, result.PPy));
  39220. return result;
  39221. }
  39222. function buildPrecincts(context, resolution, dimensions) {
  39223. // Section B.6 Division resolution to precincts
  39224. var precinctWidth = 1 << dimensions.PPx;
  39225. var precinctHeight = 1 << dimensions.PPy;
  39226. // Jasper introduces codeblock groups for mapping each subband codeblocks
  39227. // to precincts. Precinct partition divides a resolution according to width
  39228. // and height parameters. The subband that belongs to the resolution level
  39229. // has a different size than the level, unless it is the zero resolution.
  39230. // From Jasper documentation: jpeg2000.pdf, section K: Tier-2 coding:
  39231. // The precinct partitioning for a particular subband is derived from a
  39232. // partitioning of its parent LL band (i.e., the LL band at the next higher
  39233. // resolution level)... The LL band associated with each resolution level is
  39234. // divided into precincts... Each of the resulting precinct regions is then
  39235. // mapped into its child subbands (if any) at the next lower resolution
  39236. // level. This is accomplished by using the coordinate transformation
  39237. // (u, v) = (ceil(x/2), ceil(y/2)) where (x, y) and (u, v) are the
  39238. // coordinates of a point in the LL band and child subband, respectively.
  39239. var isZeroRes = resolution.resLevel === 0;
  39240. var precinctWidthInSubband = 1 << (dimensions.PPx + (isZeroRes ? 0 : -1));
  39241. var precinctHeightInSubband = 1 << (dimensions.PPy + (isZeroRes ? 0 : -1));
  39242. var numprecinctswide = (resolution.trx1 > resolution.trx0 ?
  39243. Math.ceil(resolution.trx1 / precinctWidth) -
  39244. Math.floor(resolution.trx0 / precinctWidth) : 0);
  39245. var numprecinctshigh = (resolution.try1 > resolution.try0 ?
  39246. Math.ceil(resolution.try1 / precinctHeight) -
  39247. Math.floor(resolution.try0 / precinctHeight) : 0);
  39248. var numprecincts = numprecinctswide * numprecinctshigh;
  39249. resolution.precinctParameters = {
  39250. precinctWidth: precinctWidth,
  39251. precinctHeight: precinctHeight,
  39252. numprecinctswide: numprecinctswide,
  39253. numprecinctshigh: numprecinctshigh,
  39254. numprecincts: numprecincts,
  39255. precinctWidthInSubband: precinctWidthInSubband,
  39256. precinctHeightInSubband: precinctHeightInSubband
  39257. };
  39258. }
  39259. function buildCodeblocks(context, subband, dimensions) {
  39260. // Section B.7 Division sub-band into code-blocks
  39261. var xcb_ = dimensions.xcb_;
  39262. var ycb_ = dimensions.ycb_;
  39263. var codeblockWidth = 1 << xcb_;
  39264. var codeblockHeight = 1 << ycb_;
  39265. var cbx0 = subband.tbx0 >> xcb_;
  39266. var cby0 = subband.tby0 >> ycb_;
  39267. var cbx1 = (subband.tbx1 + codeblockWidth - 1) >> xcb_;
  39268. var cby1 = (subband.tby1 + codeblockHeight - 1) >> ycb_;
  39269. var precinctParameters = subband.resolution.precinctParameters;
  39270. var codeblocks = [];
  39271. var precincts = [];
  39272. var i, j, codeblock, precinctNumber;
  39273. for (j = cby0; j < cby1; j++) {
  39274. for (i = cbx0; i < cbx1; i++) {
  39275. codeblock = {
  39276. cbx: i,
  39277. cby: j,
  39278. tbx0: codeblockWidth * i,
  39279. tby0: codeblockHeight * j,
  39280. tbx1: codeblockWidth * (i + 1),
  39281. tby1: codeblockHeight * (j + 1)
  39282. };
  39283. codeblock.tbx0_ = Math.max(subband.tbx0, codeblock.tbx0);
  39284. codeblock.tby0_ = Math.max(subband.tby0, codeblock.tby0);
  39285. codeblock.tbx1_ = Math.min(subband.tbx1, codeblock.tbx1);
  39286. codeblock.tby1_ = Math.min(subband.tby1, codeblock.tby1);
  39287. // Calculate precinct number for this codeblock, codeblock position
  39288. // should be relative to its subband, use actual dimension and position
  39289. // See comment about codeblock group width and height
  39290. var pi = Math.floor((codeblock.tbx0_ - subband.tbx0) /
  39291. precinctParameters.precinctWidthInSubband);
  39292. var pj = Math.floor((codeblock.tby0_ - subband.tby0) /
  39293. precinctParameters.precinctHeightInSubband);
  39294. precinctNumber = pi + (pj * precinctParameters.numprecinctswide);
  39295. codeblock.precinctNumber = precinctNumber;
  39296. codeblock.subbandType = subband.type;
  39297. codeblock.Lblock = 3;
  39298. if (codeblock.tbx1_ <= codeblock.tbx0_ ||
  39299. codeblock.tby1_ <= codeblock.tby0_) {
  39300. continue;
  39301. }
  39302. codeblocks.push(codeblock);
  39303. // building precinct for the sub-band
  39304. var precinct = precincts[precinctNumber];
  39305. if (precinct !== undefined) {
  39306. if (i < precinct.cbxMin) {
  39307. precinct.cbxMin = i;
  39308. } else if (i > precinct.cbxMax) {
  39309. precinct.cbxMax = i;
  39310. }
  39311. if (j < precinct.cbyMin) {
  39312. precinct.cbxMin = j;
  39313. } else if (j > precinct.cbyMax) {
  39314. precinct.cbyMax = j;
  39315. }
  39316. } else {
  39317. precincts[precinctNumber] = precinct = {
  39318. cbxMin: i,
  39319. cbyMin: j,
  39320. cbxMax: i,
  39321. cbyMax: j
  39322. };
  39323. }
  39324. codeblock.precinct = precinct;
  39325. }
  39326. }
  39327. subband.codeblockParameters = {
  39328. codeblockWidth: xcb_,
  39329. codeblockHeight: ycb_,
  39330. numcodeblockwide: cbx1 - cbx0 + 1,
  39331. numcodeblockhigh: cby1 - cby0 + 1
  39332. };
  39333. subband.codeblocks = codeblocks;
  39334. subband.precincts = precincts;
  39335. }
  39336. function createPacket(resolution, precinctNumber, layerNumber) {
  39337. var precinctCodeblocks = [];
  39338. // Section B.10.8 Order of info in packet
  39339. var subbands = resolution.subbands;
  39340. // sub-bands already ordered in 'LL', 'HL', 'LH', and 'HH' sequence
  39341. for (var i = 0, ii = subbands.length; i < ii; i++) {
  39342. var subband = subbands[i];
  39343. var codeblocks = subband.codeblocks;
  39344. for (var j = 0, jj = codeblocks.length; j < jj; j++) {
  39345. var codeblock = codeblocks[j];
  39346. if (codeblock.precinctNumber !== precinctNumber) {
  39347. continue;
  39348. }
  39349. precinctCodeblocks.push(codeblock);
  39350. }
  39351. }
  39352. return {
  39353. layerNumber: layerNumber,
  39354. codeblocks: precinctCodeblocks
  39355. };
  39356. }
  39357. function LayerResolutionComponentPositionIterator(context) {
  39358. var siz = context.SIZ;
  39359. var tileIndex = context.currentTile.index;
  39360. var tile = context.tiles[tileIndex];
  39361. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  39362. var componentsCount = siz.Csiz;
  39363. var maxDecompositionLevelsCount = 0;
  39364. for (var q = 0; q < componentsCount; q++) {
  39365. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  39366. tile.components[q].codingStyleParameters.decompositionLevelsCount);
  39367. }
  39368. var l = 0, r = 0, i = 0, k = 0;
  39369. this.nextPacket = function JpxImage_nextPacket() {
  39370. // Section B.12.1.1 Layer-resolution-component-position
  39371. for (; l < layersCount; l++) {
  39372. for (; r <= maxDecompositionLevelsCount; r++) {
  39373. for (; i < componentsCount; i++) {
  39374. var component = tile.components[i];
  39375. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  39376. continue;
  39377. }
  39378. var resolution = component.resolutions[r];
  39379. var numprecincts = resolution.precinctParameters.numprecincts;
  39380. for (; k < numprecincts;) {
  39381. var packet = createPacket(resolution, k, l);
  39382. k++;
  39383. return packet;
  39384. }
  39385. k = 0;
  39386. }
  39387. i = 0;
  39388. }
  39389. r = 0;
  39390. }
  39391. throw new Error('JPX Error: Out of packets');
  39392. };
  39393. }
  39394. function ResolutionLayerComponentPositionIterator(context) {
  39395. var siz = context.SIZ;
  39396. var tileIndex = context.currentTile.index;
  39397. var tile = context.tiles[tileIndex];
  39398. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  39399. var componentsCount = siz.Csiz;
  39400. var maxDecompositionLevelsCount = 0;
  39401. for (var q = 0; q < componentsCount; q++) {
  39402. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  39403. tile.components[q].codingStyleParameters.decompositionLevelsCount);
  39404. }
  39405. var r = 0, l = 0, i = 0, k = 0;
  39406. this.nextPacket = function JpxImage_nextPacket() {
  39407. // Section B.12.1.2 Resolution-layer-component-position
  39408. for (; r <= maxDecompositionLevelsCount; r++) {
  39409. for (; l < layersCount; l++) {
  39410. for (; i < componentsCount; i++) {
  39411. var component = tile.components[i];
  39412. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  39413. continue;
  39414. }
  39415. var resolution = component.resolutions[r];
  39416. var numprecincts = resolution.precinctParameters.numprecincts;
  39417. for (; k < numprecincts;) {
  39418. var packet = createPacket(resolution, k, l);
  39419. k++;
  39420. return packet;
  39421. }
  39422. k = 0;
  39423. }
  39424. i = 0;
  39425. }
  39426. l = 0;
  39427. }
  39428. throw new Error('JPX Error: Out of packets');
  39429. };
  39430. }
  39431. function ResolutionPositionComponentLayerIterator(context) {
  39432. var siz = context.SIZ;
  39433. var tileIndex = context.currentTile.index;
  39434. var tile = context.tiles[tileIndex];
  39435. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  39436. var componentsCount = siz.Csiz;
  39437. var l, r, c, p;
  39438. var maxDecompositionLevelsCount = 0;
  39439. for (c = 0; c < componentsCount; c++) {
  39440. var component = tile.components[c];
  39441. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  39442. component.codingStyleParameters.decompositionLevelsCount);
  39443. }
  39444. var maxNumPrecinctsInLevel = new Int32Array(
  39445. maxDecompositionLevelsCount + 1);
  39446. for (r = 0; r <= maxDecompositionLevelsCount; ++r) {
  39447. var maxNumPrecincts = 0;
  39448. for (c = 0; c < componentsCount; ++c) {
  39449. var resolutions = tile.components[c].resolutions;
  39450. if (r < resolutions.length) {
  39451. maxNumPrecincts = Math.max(maxNumPrecincts,
  39452. resolutions[r].precinctParameters.numprecincts);
  39453. }
  39454. }
  39455. maxNumPrecinctsInLevel[r] = maxNumPrecincts;
  39456. }
  39457. l = 0;
  39458. r = 0;
  39459. c = 0;
  39460. p = 0;
  39461. this.nextPacket = function JpxImage_nextPacket() {
  39462. // Section B.12.1.3 Resolution-position-component-layer
  39463. for (; r <= maxDecompositionLevelsCount; r++) {
  39464. for (; p < maxNumPrecinctsInLevel[r]; p++) {
  39465. for (; c < componentsCount; c++) {
  39466. var component = tile.components[c];
  39467. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  39468. continue;
  39469. }
  39470. var resolution = component.resolutions[r];
  39471. var numprecincts = resolution.precinctParameters.numprecincts;
  39472. if (p >= numprecincts) {
  39473. continue;
  39474. }
  39475. for (; l < layersCount;) {
  39476. var packet = createPacket(resolution, p, l);
  39477. l++;
  39478. return packet;
  39479. }
  39480. l = 0;
  39481. }
  39482. c = 0;
  39483. }
  39484. p = 0;
  39485. }
  39486. throw new Error('JPX Error: Out of packets');
  39487. };
  39488. }
  39489. function PositionComponentResolutionLayerIterator(context) {
  39490. var siz = context.SIZ;
  39491. var tileIndex = context.currentTile.index;
  39492. var tile = context.tiles[tileIndex];
  39493. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  39494. var componentsCount = siz.Csiz;
  39495. var precinctsSizes = getPrecinctSizesInImageScale(tile);
  39496. var precinctsIterationSizes = precinctsSizes;
  39497. var l = 0, r = 0, c = 0, px = 0, py = 0;
  39498. this.nextPacket = function JpxImage_nextPacket() {
  39499. // Section B.12.1.4 Position-component-resolution-layer
  39500. for (; py < precinctsIterationSizes.maxNumHigh; py++) {
  39501. for (; px < precinctsIterationSizes.maxNumWide; px++) {
  39502. for (; c < componentsCount; c++) {
  39503. var component = tile.components[c];
  39504. var decompositionLevelsCount =
  39505. component.codingStyleParameters.decompositionLevelsCount;
  39506. for (; r <= decompositionLevelsCount; r++) {
  39507. var resolution = component.resolutions[r];
  39508. var sizeInImageScale =
  39509. precinctsSizes.components[c].resolutions[r];
  39510. var k = getPrecinctIndexIfExist(
  39511. px,
  39512. py,
  39513. sizeInImageScale,
  39514. precinctsIterationSizes,
  39515. resolution);
  39516. if (k === null) {
  39517. continue;
  39518. }
  39519. for (; l < layersCount;) {
  39520. var packet = createPacket(resolution, k, l);
  39521. l++;
  39522. return packet;
  39523. }
  39524. l = 0;
  39525. }
  39526. r = 0;
  39527. }
  39528. c = 0;
  39529. }
  39530. px = 0;
  39531. }
  39532. throw new Error('JPX Error: Out of packets');
  39533. };
  39534. }
  39535. function ComponentPositionResolutionLayerIterator(context) {
  39536. var siz = context.SIZ;
  39537. var tileIndex = context.currentTile.index;
  39538. var tile = context.tiles[tileIndex];
  39539. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  39540. var componentsCount = siz.Csiz;
  39541. var precinctsSizes = getPrecinctSizesInImageScale(tile);
  39542. var l = 0, r = 0, c = 0, px = 0, py = 0;
  39543. this.nextPacket = function JpxImage_nextPacket() {
  39544. // Section B.12.1.5 Component-position-resolution-layer
  39545. for (; c < componentsCount; ++c) {
  39546. var component = tile.components[c];
  39547. var precinctsIterationSizes = precinctsSizes.components[c];
  39548. var decompositionLevelsCount =
  39549. component.codingStyleParameters.decompositionLevelsCount;
  39550. for (; py < precinctsIterationSizes.maxNumHigh; py++) {
  39551. for (; px < precinctsIterationSizes.maxNumWide; px++) {
  39552. for (; r <= decompositionLevelsCount; r++) {
  39553. var resolution = component.resolutions[r];
  39554. var sizeInImageScale = precinctsIterationSizes.resolutions[r];
  39555. var k = getPrecinctIndexIfExist(
  39556. px,
  39557. py,
  39558. sizeInImageScale,
  39559. precinctsIterationSizes,
  39560. resolution);
  39561. if (k === null) {
  39562. continue;
  39563. }
  39564. for (; l < layersCount;) {
  39565. var packet = createPacket(resolution, k, l);
  39566. l++;
  39567. return packet;
  39568. }
  39569. l = 0;
  39570. }
  39571. r = 0;
  39572. }
  39573. px = 0;
  39574. }
  39575. py = 0;
  39576. }
  39577. throw new Error('JPX Error: Out of packets');
  39578. };
  39579. }
  39580. function getPrecinctIndexIfExist(
  39581. pxIndex, pyIndex, sizeInImageScale, precinctIterationSizes, resolution) {
  39582. var posX = pxIndex * precinctIterationSizes.minWidth;
  39583. var posY = pyIndex * precinctIterationSizes.minHeight;
  39584. if (posX % sizeInImageScale.width !== 0 ||
  39585. posY % sizeInImageScale.height !== 0) {
  39586. return null;
  39587. }
  39588. var startPrecinctRowIndex =
  39589. (posY / sizeInImageScale.width) *
  39590. resolution.precinctParameters.numprecinctswide;
  39591. return (posX / sizeInImageScale.height) + startPrecinctRowIndex;
  39592. }
  39593. function getPrecinctSizesInImageScale(tile) {
  39594. var componentsCount = tile.components.length;
  39595. var minWidth = Number.MAX_VALUE;
  39596. var minHeight = Number.MAX_VALUE;
  39597. var maxNumWide = 0;
  39598. var maxNumHigh = 0;
  39599. var sizePerComponent = new Array(componentsCount);
  39600. for (var c = 0; c < componentsCount; c++) {
  39601. var component = tile.components[c];
  39602. var decompositionLevelsCount =
  39603. component.codingStyleParameters.decompositionLevelsCount;
  39604. var sizePerResolution = new Array(decompositionLevelsCount + 1);
  39605. var minWidthCurrentComponent = Number.MAX_VALUE;
  39606. var minHeightCurrentComponent = Number.MAX_VALUE;
  39607. var maxNumWideCurrentComponent = 0;
  39608. var maxNumHighCurrentComponent = 0;
  39609. var scale = 1;
  39610. for (var r = decompositionLevelsCount; r >= 0; --r) {
  39611. var resolution = component.resolutions[r];
  39612. var widthCurrentResolution =
  39613. scale * resolution.precinctParameters.precinctWidth;
  39614. var heightCurrentResolution =
  39615. scale * resolution.precinctParameters.precinctHeight;
  39616. minWidthCurrentComponent = Math.min(
  39617. minWidthCurrentComponent,
  39618. widthCurrentResolution);
  39619. minHeightCurrentComponent = Math.min(
  39620. minHeightCurrentComponent,
  39621. heightCurrentResolution);
  39622. maxNumWideCurrentComponent = Math.max(maxNumWideCurrentComponent,
  39623. resolution.precinctParameters.numprecinctswide);
  39624. maxNumHighCurrentComponent = Math.max(maxNumHighCurrentComponent,
  39625. resolution.precinctParameters.numprecinctshigh);
  39626. sizePerResolution[r] = {
  39627. width: widthCurrentResolution,
  39628. height: heightCurrentResolution
  39629. };
  39630. scale <<= 1;
  39631. }
  39632. minWidth = Math.min(minWidth, minWidthCurrentComponent);
  39633. minHeight = Math.min(minHeight, minHeightCurrentComponent);
  39634. maxNumWide = Math.max(maxNumWide, maxNumWideCurrentComponent);
  39635. maxNumHigh = Math.max(maxNumHigh, maxNumHighCurrentComponent);
  39636. sizePerComponent[c] = {
  39637. resolutions: sizePerResolution,
  39638. minWidth: minWidthCurrentComponent,
  39639. minHeight: minHeightCurrentComponent,
  39640. maxNumWide: maxNumWideCurrentComponent,
  39641. maxNumHigh: maxNumHighCurrentComponent
  39642. };
  39643. }
  39644. return {
  39645. components: sizePerComponent,
  39646. minWidth: minWidth,
  39647. minHeight: minHeight,
  39648. maxNumWide: maxNumWide,
  39649. maxNumHigh: maxNumHigh
  39650. };
  39651. }
  39652. function buildPackets(context) {
  39653. var siz = context.SIZ;
  39654. var tileIndex = context.currentTile.index;
  39655. var tile = context.tiles[tileIndex];
  39656. var componentsCount = siz.Csiz;
  39657. // Creating resolutions and sub-bands for each component
  39658. for (var c = 0; c < componentsCount; c++) {
  39659. var component = tile.components[c];
  39660. var decompositionLevelsCount =
  39661. component.codingStyleParameters.decompositionLevelsCount;
  39662. // Section B.5 Resolution levels and sub-bands
  39663. var resolutions = [];
  39664. var subbands = [];
  39665. for (var r = 0; r <= decompositionLevelsCount; r++) {
  39666. var blocksDimensions = getBlocksDimensions(context, component, r);
  39667. var resolution = {};
  39668. var scale = 1 << (decompositionLevelsCount - r);
  39669. resolution.trx0 = Math.ceil(component.tcx0 / scale);
  39670. resolution.try0 = Math.ceil(component.tcy0 / scale);
  39671. resolution.trx1 = Math.ceil(component.tcx1 / scale);
  39672. resolution.try1 = Math.ceil(component.tcy1 / scale);
  39673. resolution.resLevel = r;
  39674. buildPrecincts(context, resolution, blocksDimensions);
  39675. resolutions.push(resolution);
  39676. var subband;
  39677. if (r === 0) {
  39678. // one sub-band (LL) with last decomposition
  39679. subband = {};
  39680. subband.type = 'LL';
  39681. subband.tbx0 = Math.ceil(component.tcx0 / scale);
  39682. subband.tby0 = Math.ceil(component.tcy0 / scale);
  39683. subband.tbx1 = Math.ceil(component.tcx1 / scale);
  39684. subband.tby1 = Math.ceil(component.tcy1 / scale);
  39685. subband.resolution = resolution;
  39686. buildCodeblocks(context, subband, blocksDimensions);
  39687. subbands.push(subband);
  39688. resolution.subbands = [subband];
  39689. } else {
  39690. var bscale = 1 << (decompositionLevelsCount - r + 1);
  39691. var resolutionSubbands = [];
  39692. // three sub-bands (HL, LH and HH) with rest of decompositions
  39693. subband = {};
  39694. subband.type = 'HL';
  39695. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  39696. subband.tby0 = Math.ceil(component.tcy0 / bscale);
  39697. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  39698. subband.tby1 = Math.ceil(component.tcy1 / bscale);
  39699. subband.resolution = resolution;
  39700. buildCodeblocks(context, subband, blocksDimensions);
  39701. subbands.push(subband);
  39702. resolutionSubbands.push(subband);
  39703. subband = {};
  39704. subband.type = 'LH';
  39705. subband.tbx0 = Math.ceil(component.tcx0 / bscale);
  39706. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  39707. subband.tbx1 = Math.ceil(component.tcx1 / bscale);
  39708. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  39709. subband.resolution = resolution;
  39710. buildCodeblocks(context, subband, blocksDimensions);
  39711. subbands.push(subband);
  39712. resolutionSubbands.push(subband);
  39713. subband = {};
  39714. subband.type = 'HH';
  39715. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  39716. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  39717. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  39718. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  39719. subband.resolution = resolution;
  39720. buildCodeblocks(context, subband, blocksDimensions);
  39721. subbands.push(subband);
  39722. resolutionSubbands.push(subband);
  39723. resolution.subbands = resolutionSubbands;
  39724. }
  39725. }
  39726. component.resolutions = resolutions;
  39727. component.subbands = subbands;
  39728. }
  39729. // Generate the packets sequence
  39730. var progressionOrder = tile.codingStyleDefaultParameters.progressionOrder;
  39731. switch (progressionOrder) {
  39732. case 0:
  39733. tile.packetsIterator =
  39734. new LayerResolutionComponentPositionIterator(context);
  39735. break;
  39736. case 1:
  39737. tile.packetsIterator =
  39738. new ResolutionLayerComponentPositionIterator(context);
  39739. break;
  39740. case 2:
  39741. tile.packetsIterator =
  39742. new ResolutionPositionComponentLayerIterator(context);
  39743. break;
  39744. case 3:
  39745. tile.packetsIterator =
  39746. new PositionComponentResolutionLayerIterator(context);
  39747. break;
  39748. case 4:
  39749. tile.packetsIterator =
  39750. new ComponentPositionResolutionLayerIterator(context);
  39751. break;
  39752. default:
  39753. throw new Error('JPX Error: Unsupported progression order ' +
  39754. progressionOrder);
  39755. }
  39756. }
  39757. function parseTilePackets(context, data, offset, dataLength) {
  39758. var position = 0;
  39759. var buffer, bufferSize = 0, skipNextBit = false;
  39760. function readBits(count) {
  39761. while (bufferSize < count) {
  39762. var b = data[offset + position];
  39763. position++;
  39764. if (skipNextBit) {
  39765. buffer = (buffer << 7) | b;
  39766. bufferSize += 7;
  39767. skipNextBit = false;
  39768. } else {
  39769. buffer = (buffer << 8) | b;
  39770. bufferSize += 8;
  39771. }
  39772. if (b === 0xFF) {
  39773. skipNextBit = true;
  39774. }
  39775. }
  39776. bufferSize -= count;
  39777. return (buffer >>> bufferSize) & ((1 << count) - 1);
  39778. }
  39779. function skipMarkerIfEqual(value) {
  39780. if (data[offset + position - 1] === 0xFF &&
  39781. data[offset + position] === value) {
  39782. skipBytes(1);
  39783. return true;
  39784. } else if (data[offset + position] === 0xFF &&
  39785. data[offset + position + 1] === value) {
  39786. skipBytes(2);
  39787. return true;
  39788. }
  39789. return false;
  39790. }
  39791. function skipBytes(count) {
  39792. position += count;
  39793. }
  39794. function alignToByte() {
  39795. bufferSize = 0;
  39796. if (skipNextBit) {
  39797. position++;
  39798. skipNextBit = false;
  39799. }
  39800. }
  39801. function readCodingpasses() {
  39802. if (readBits(1) === 0) {
  39803. return 1;
  39804. }
  39805. if (readBits(1) === 0) {
  39806. return 2;
  39807. }
  39808. var value = readBits(2);
  39809. if (value < 3) {
  39810. return value + 3;
  39811. }
  39812. value = readBits(5);
  39813. if (value < 31) {
  39814. return value + 6;
  39815. }
  39816. value = readBits(7);
  39817. return value + 37;
  39818. }
  39819. var tileIndex = context.currentTile.index;
  39820. var tile = context.tiles[tileIndex];
  39821. var sopMarkerUsed = context.COD.sopMarkerUsed;
  39822. var ephMarkerUsed = context.COD.ephMarkerUsed;
  39823. var packetsIterator = tile.packetsIterator;
  39824. while (position < dataLength) {
  39825. alignToByte();
  39826. if (sopMarkerUsed && skipMarkerIfEqual(0x91)) {
  39827. // Skip also marker segment length and packet sequence ID
  39828. skipBytes(4);
  39829. }
  39830. var packet = packetsIterator.nextPacket();
  39831. if (!readBits(1)) {
  39832. continue;
  39833. }
  39834. var layerNumber = packet.layerNumber;
  39835. var queue = [], codeblock;
  39836. for (var i = 0, ii = packet.codeblocks.length; i < ii; i++) {
  39837. codeblock = packet.codeblocks[i];
  39838. var precinct = codeblock.precinct;
  39839. var codeblockColumn = codeblock.cbx - precinct.cbxMin;
  39840. var codeblockRow = codeblock.cby - precinct.cbyMin;
  39841. var codeblockIncluded = false;
  39842. var firstTimeInclusion = false;
  39843. var valueReady;
  39844. if (codeblock['included'] !== undefined) {
  39845. codeblockIncluded = !!readBits(1);
  39846. } else {
  39847. // reading inclusion tree
  39848. precinct = codeblock.precinct;
  39849. var inclusionTree, zeroBitPlanesTree;
  39850. if (precinct['inclusionTree'] !== undefined) {
  39851. inclusionTree = precinct.inclusionTree;
  39852. } else {
  39853. // building inclusion and zero bit-planes trees
  39854. var width = precinct.cbxMax - precinct.cbxMin + 1;
  39855. var height = precinct.cbyMax - precinct.cbyMin + 1;
  39856. inclusionTree = new InclusionTree(width, height, layerNumber);
  39857. zeroBitPlanesTree = new TagTree(width, height);
  39858. precinct.inclusionTree = inclusionTree;
  39859. precinct.zeroBitPlanesTree = zeroBitPlanesTree;
  39860. }
  39861. if (inclusionTree.reset(codeblockColumn, codeblockRow, layerNumber)) {
  39862. while (true) {
  39863. if (readBits(1)) {
  39864. valueReady = !inclusionTree.nextLevel();
  39865. if (valueReady) {
  39866. codeblock.included = true;
  39867. codeblockIncluded = firstTimeInclusion = true;
  39868. break;
  39869. }
  39870. } else {
  39871. inclusionTree.incrementValue(layerNumber);
  39872. break;
  39873. }
  39874. }
  39875. }
  39876. }
  39877. if (!codeblockIncluded) {
  39878. continue;
  39879. }
  39880. if (firstTimeInclusion) {
  39881. zeroBitPlanesTree = precinct.zeroBitPlanesTree;
  39882. zeroBitPlanesTree.reset(codeblockColumn, codeblockRow);
  39883. while (true) {
  39884. if (readBits(1)) {
  39885. valueReady = !zeroBitPlanesTree.nextLevel();
  39886. if (valueReady) {
  39887. break;
  39888. }
  39889. } else {
  39890. zeroBitPlanesTree.incrementValue();
  39891. }
  39892. }
  39893. codeblock.zeroBitPlanes = zeroBitPlanesTree.value;
  39894. }
  39895. var codingpasses = readCodingpasses();
  39896. while (readBits(1)) {
  39897. codeblock.Lblock++;
  39898. }
  39899. var codingpassesLog2 = log2(codingpasses);
  39900. // rounding down log2
  39901. var bits = ((codingpasses < (1 << codingpassesLog2)) ?
  39902. codingpassesLog2 - 1 : codingpassesLog2) + codeblock.Lblock;
  39903. var codedDataLength = readBits(bits);
  39904. queue.push({
  39905. codeblock: codeblock,
  39906. codingpasses: codingpasses,
  39907. dataLength: codedDataLength
  39908. });
  39909. }
  39910. alignToByte();
  39911. if (ephMarkerUsed) {
  39912. skipMarkerIfEqual(0x92);
  39913. }
  39914. while (queue.length > 0) {
  39915. var packetItem = queue.shift();
  39916. codeblock = packetItem.codeblock;
  39917. if (codeblock['data'] === undefined) {
  39918. codeblock.data = [];
  39919. }
  39920. codeblock.data.push({
  39921. data: data,
  39922. start: offset + position,
  39923. end: offset + position + packetItem.dataLength,
  39924. codingpasses: packetItem.codingpasses
  39925. });
  39926. position += packetItem.dataLength;
  39927. }
  39928. }
  39929. return position;
  39930. }
  39931. function copyCoefficients(coefficients, levelWidth, levelHeight, subband,
  39932. delta, mb, reversible, segmentationSymbolUsed) {
  39933. var x0 = subband.tbx0;
  39934. var y0 = subband.tby0;
  39935. var width = subband.tbx1 - subband.tbx0;
  39936. var codeblocks = subband.codeblocks;
  39937. var right = subband.type.charAt(0) === 'H' ? 1 : 0;
  39938. var bottom = subband.type.charAt(1) === 'H' ? levelWidth : 0;
  39939. for (var i = 0, ii = codeblocks.length; i < ii; ++i) {
  39940. var codeblock = codeblocks[i];
  39941. var blockWidth = codeblock.tbx1_ - codeblock.tbx0_;
  39942. var blockHeight = codeblock.tby1_ - codeblock.tby0_;
  39943. if (blockWidth === 0 || blockHeight === 0) {
  39944. continue;
  39945. }
  39946. if (codeblock['data'] === undefined) {
  39947. continue;
  39948. }
  39949. var bitModel, currentCodingpassType;
  39950. bitModel = new BitModel(blockWidth, blockHeight, codeblock.subbandType,
  39951. codeblock.zeroBitPlanes, mb);
  39952. currentCodingpassType = 2; // first bit plane starts from cleanup
  39953. // collect data
  39954. var data = codeblock.data, totalLength = 0, codingpasses = 0;
  39955. var j, jj, dataItem;
  39956. for (j = 0, jj = data.length; j < jj; j++) {
  39957. dataItem = data[j];
  39958. totalLength += dataItem.end - dataItem.start;
  39959. codingpasses += dataItem.codingpasses;
  39960. }
  39961. var encodedData = new Uint8Array(totalLength);
  39962. var position = 0;
  39963. for (j = 0, jj = data.length; j < jj; j++) {
  39964. dataItem = data[j];
  39965. var chunk = dataItem.data.subarray(dataItem.start, dataItem.end);
  39966. encodedData.set(chunk, position);
  39967. position += chunk.length;
  39968. }
  39969. // decoding the item
  39970. var decoder = new ArithmeticDecoder(encodedData, 0, totalLength);
  39971. bitModel.setDecoder(decoder);
  39972. for (j = 0; j < codingpasses; j++) {
  39973. switch (currentCodingpassType) {
  39974. case 0:
  39975. bitModel.runSignificancePropogationPass();
  39976. break;
  39977. case 1:
  39978. bitModel.runMagnitudeRefinementPass();
  39979. break;
  39980. case 2:
  39981. bitModel.runCleanupPass();
  39982. if (segmentationSymbolUsed) {
  39983. bitModel.checkSegmentationSymbol();
  39984. }
  39985. break;
  39986. }
  39987. currentCodingpassType = (currentCodingpassType + 1) % 3;
  39988. }
  39989. var offset = (codeblock.tbx0_ - x0) + (codeblock.tby0_ - y0) * width;
  39990. var sign = bitModel.coefficentsSign;
  39991. var magnitude = bitModel.coefficentsMagnitude;
  39992. var bitsDecoded = bitModel.bitsDecoded;
  39993. var magnitudeCorrection = reversible ? 0 : 0.5;
  39994. var k, n, nb;
  39995. position = 0;
  39996. // Do the interleaving of Section F.3.3 here, so we do not need
  39997. // to copy later. LL level is not interleaved, just copied.
  39998. var interleave = (subband.type !== 'LL');
  39999. for (j = 0; j < blockHeight; j++) {
  40000. var row = (offset / width) | 0; // row in the non-interleaved subband
  40001. var levelOffset = 2 * row * (levelWidth - width) + right + bottom;
  40002. for (k = 0; k < blockWidth; k++) {
  40003. n = magnitude[position];
  40004. if (n !== 0) {
  40005. n = (n + magnitudeCorrection) * delta;
  40006. if (sign[position] !== 0) {
  40007. n = -n;
  40008. }
  40009. nb = bitsDecoded[position];
  40010. var pos = interleave ? (levelOffset + (offset << 1)) : offset;
  40011. if (reversible && (nb >= mb)) {
  40012. coefficients[pos] = n;
  40013. } else {
  40014. coefficients[pos] = n * (1 << (mb - nb));
  40015. }
  40016. }
  40017. offset++;
  40018. position++;
  40019. }
  40020. offset += width - blockWidth;
  40021. }
  40022. }
  40023. }
  40024. function transformTile(context, tile, c) {
  40025. var component = tile.components[c];
  40026. var codingStyleParameters = component.codingStyleParameters;
  40027. var quantizationParameters = component.quantizationParameters;
  40028. var decompositionLevelsCount =
  40029. codingStyleParameters.decompositionLevelsCount;
  40030. var spqcds = quantizationParameters.SPqcds;
  40031. var scalarExpounded = quantizationParameters.scalarExpounded;
  40032. var guardBits = quantizationParameters.guardBits;
  40033. var segmentationSymbolUsed = codingStyleParameters.segmentationSymbolUsed;
  40034. var precision = context.components[c].precision;
  40035. var reversible = codingStyleParameters.reversibleTransformation;
  40036. var transform = (reversible ? new ReversibleTransform() :
  40037. new IrreversibleTransform());
  40038. var subbandCoefficients = [];
  40039. var b = 0;
  40040. for (var i = 0; i <= decompositionLevelsCount; i++) {
  40041. var resolution = component.resolutions[i];
  40042. var width = resolution.trx1 - resolution.trx0;
  40043. var height = resolution.try1 - resolution.try0;
  40044. // Allocate space for the whole sublevel.
  40045. var coefficients = new Float32Array(width * height);
  40046. for (var j = 0, jj = resolution.subbands.length; j < jj; j++) {
  40047. var mu, epsilon;
  40048. if (!scalarExpounded) {
  40049. // formula E-5
  40050. mu = spqcds[0].mu;
  40051. epsilon = spqcds[0].epsilon + (i > 0 ? 1 - i : 0);
  40052. } else {
  40053. mu = spqcds[b].mu;
  40054. epsilon = spqcds[b].epsilon;
  40055. b++;
  40056. }
  40057. var subband = resolution.subbands[j];
  40058. var gainLog2 = SubbandsGainLog2[subband.type];
  40059. // calulate quantization coefficient (Section E.1.1.1)
  40060. var delta = (reversible ? 1 :
  40061. Math.pow(2, precision + gainLog2 - epsilon) * (1 + mu / 2048));
  40062. var mb = (guardBits + epsilon - 1);
  40063. // In the first resolution level, copyCoefficients will fill the
  40064. // whole array with coefficients. In the succeding passes,
  40065. // copyCoefficients will consecutively fill in the values that belong
  40066. // to the interleaved positions of the HL, LH, and HH coefficients.
  40067. // The LL coefficients will then be interleaved in Transform.iterate().
  40068. copyCoefficients(coefficients, width, height, subband, delta, mb,
  40069. reversible, segmentationSymbolUsed);
  40070. }
  40071. subbandCoefficients.push({
  40072. width: width,
  40073. height: height,
  40074. items: coefficients
  40075. });
  40076. }
  40077. var result = transform.calculate(subbandCoefficients,
  40078. component.tcx0, component.tcy0);
  40079. return {
  40080. left: component.tcx0,
  40081. top: component.tcy0,
  40082. width: result.width,
  40083. height: result.height,
  40084. items: result.items
  40085. };
  40086. }
  40087. function transformComponents(context) {
  40088. var siz = context.SIZ;
  40089. var components = context.components;
  40090. var componentsCount = siz.Csiz;
  40091. var resultImages = [];
  40092. for (var i = 0, ii = context.tiles.length; i < ii; i++) {
  40093. var tile = context.tiles[i];
  40094. var transformedTiles = [];
  40095. var c;
  40096. for (c = 0; c < componentsCount; c++) {
  40097. transformedTiles[c] = transformTile(context, tile, c);
  40098. }
  40099. var tile0 = transformedTiles[0];
  40100. var out = new Uint8Array(tile0.items.length * componentsCount);
  40101. var result = {
  40102. left: tile0.left,
  40103. top: tile0.top,
  40104. width: tile0.width,
  40105. height: tile0.height,
  40106. items: out
  40107. };
  40108. // Section G.2.2 Inverse multi component transform
  40109. var shift, offset, max, min, maxK;
  40110. var pos = 0, j, jj, y0, y1, y2, r, g, b, k, val;
  40111. if (tile.codingStyleDefaultParameters.multipleComponentTransform) {
  40112. var fourComponents = componentsCount === 4;
  40113. var y0items = transformedTiles[0].items;
  40114. var y1items = transformedTiles[1].items;
  40115. var y2items = transformedTiles[2].items;
  40116. var y3items = fourComponents ? transformedTiles[3].items : null;
  40117. // HACK: The multiple component transform formulas below assume that
  40118. // all components have the same precision. With this in mind, we
  40119. // compute shift and offset only once.
  40120. shift = components[0].precision - 8;
  40121. offset = (128 << shift) + 0.5;
  40122. max = 255 * (1 << shift);
  40123. maxK = max * 0.5;
  40124. min = -maxK;
  40125. var component0 = tile.components[0];
  40126. var alpha01 = componentsCount - 3;
  40127. jj = y0items.length;
  40128. if (!component0.codingStyleParameters.reversibleTransformation) {
  40129. // inverse irreversible multiple component transform
  40130. for (j = 0; j < jj; j++, pos += alpha01) {
  40131. y0 = y0items[j] + offset;
  40132. y1 = y1items[j];
  40133. y2 = y2items[j];
  40134. r = y0 + 1.402 * y2;
  40135. g = y0 - 0.34413 * y1 - 0.71414 * y2;
  40136. b = y0 + 1.772 * y1;
  40137. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  40138. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  40139. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  40140. }
  40141. } else {
  40142. // inverse reversible multiple component transform
  40143. for (j = 0; j < jj; j++, pos += alpha01) {
  40144. y0 = y0items[j] + offset;
  40145. y1 = y1items[j];
  40146. y2 = y2items[j];
  40147. g = y0 - ((y2 + y1) >> 2);
  40148. r = g + y2;
  40149. b = g + y1;
  40150. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  40151. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  40152. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  40153. }
  40154. }
  40155. if (fourComponents) {
  40156. for (j = 0, pos = 3; j < jj; j++, pos += 4) {
  40157. k = y3items[j];
  40158. out[pos] = k <= min ? 0 : k >= maxK ? 255 : (k + offset) >> shift;
  40159. }
  40160. }
  40161. } else { // no multi-component transform
  40162. for (c = 0; c < componentsCount; c++) {
  40163. var items = transformedTiles[c].items;
  40164. shift = components[c].precision - 8;
  40165. offset = (128 << shift) + 0.5;
  40166. max = (127.5 * (1 << shift));
  40167. min = -max;
  40168. for (pos = c, j = 0, jj = items.length; j < jj; j++) {
  40169. val = items[j];
  40170. out[pos] = val <= min ? 0 :
  40171. val >= max ? 255 : (val + offset) >> shift;
  40172. pos += componentsCount;
  40173. }
  40174. }
  40175. }
  40176. resultImages.push(result);
  40177. }
  40178. return resultImages;
  40179. }
  40180. function initializeTile(context, tileIndex) {
  40181. var siz = context.SIZ;
  40182. var componentsCount = siz.Csiz;
  40183. var tile = context.tiles[tileIndex];
  40184. for (var c = 0; c < componentsCount; c++) {
  40185. var component = tile.components[c];
  40186. var qcdOrQcc = (context.currentTile.QCC[c] !== undefined ?
  40187. context.currentTile.QCC[c] : context.currentTile.QCD);
  40188. component.quantizationParameters = qcdOrQcc;
  40189. var codOrCoc = (context.currentTile.COC[c] !== undefined ?
  40190. context.currentTile.COC[c] : context.currentTile.COD);
  40191. component.codingStyleParameters = codOrCoc;
  40192. }
  40193. tile.codingStyleDefaultParameters = context.currentTile.COD;
  40194. }
  40195. // Section B.10.2 Tag trees
  40196. var TagTree = (function TagTreeClosure() {
  40197. function TagTree(width, height) {
  40198. var levelsLength = log2(Math.max(width, height)) + 1;
  40199. this.levels = [];
  40200. for (var i = 0; i < levelsLength; i++) {
  40201. var level = {
  40202. width: width,
  40203. height: height,
  40204. items: []
  40205. };
  40206. this.levels.push(level);
  40207. width = Math.ceil(width / 2);
  40208. height = Math.ceil(height / 2);
  40209. }
  40210. }
  40211. TagTree.prototype = {
  40212. reset: function TagTree_reset(i, j) {
  40213. var currentLevel = 0, value = 0, level;
  40214. while (currentLevel < this.levels.length) {
  40215. level = this.levels[currentLevel];
  40216. var index = i + j * level.width;
  40217. if (level.items[index] !== undefined) {
  40218. value = level.items[index];
  40219. break;
  40220. }
  40221. level.index = index;
  40222. i >>= 1;
  40223. j >>= 1;
  40224. currentLevel++;
  40225. }
  40226. currentLevel--;
  40227. level = this.levels[currentLevel];
  40228. level.items[level.index] = value;
  40229. this.currentLevel = currentLevel;
  40230. delete this.value;
  40231. },
  40232. incrementValue: function TagTree_incrementValue() {
  40233. var level = this.levels[this.currentLevel];
  40234. level.items[level.index]++;
  40235. },
  40236. nextLevel: function TagTree_nextLevel() {
  40237. var currentLevel = this.currentLevel;
  40238. var level = this.levels[currentLevel];
  40239. var value = level.items[level.index];
  40240. currentLevel--;
  40241. if (currentLevel < 0) {
  40242. this.value = value;
  40243. return false;
  40244. }
  40245. this.currentLevel = currentLevel;
  40246. level = this.levels[currentLevel];
  40247. level.items[level.index] = value;
  40248. return true;
  40249. }
  40250. };
  40251. return TagTree;
  40252. })();
  40253. var InclusionTree = (function InclusionTreeClosure() {
  40254. function InclusionTree(width, height, defaultValue) {
  40255. var levelsLength = log2(Math.max(width, height)) + 1;
  40256. this.levels = [];
  40257. for (var i = 0; i < levelsLength; i++) {
  40258. var items = new Uint8Array(width * height);
  40259. for (var j = 0, jj = items.length; j < jj; j++) {
  40260. items[j] = defaultValue;
  40261. }
  40262. var level = {
  40263. width: width,
  40264. height: height,
  40265. items: items
  40266. };
  40267. this.levels.push(level);
  40268. width = Math.ceil(width / 2);
  40269. height = Math.ceil(height / 2);
  40270. }
  40271. }
  40272. InclusionTree.prototype = {
  40273. reset: function InclusionTree_reset(i, j, stopValue) {
  40274. var currentLevel = 0;
  40275. while (currentLevel < this.levels.length) {
  40276. var level = this.levels[currentLevel];
  40277. var index = i + j * level.width;
  40278. level.index = index;
  40279. var value = level.items[index];
  40280. if (value === 0xFF) {
  40281. break;
  40282. }
  40283. if (value > stopValue) {
  40284. this.currentLevel = currentLevel;
  40285. // already know about this one, propagating the value to top levels
  40286. this.propagateValues();
  40287. return false;
  40288. }
  40289. i >>= 1;
  40290. j >>= 1;
  40291. currentLevel++;
  40292. }
  40293. this.currentLevel = currentLevel - 1;
  40294. return true;
  40295. },
  40296. incrementValue: function InclusionTree_incrementValue(stopValue) {
  40297. var level = this.levels[this.currentLevel];
  40298. level.items[level.index] = stopValue + 1;
  40299. this.propagateValues();
  40300. },
  40301. propagateValues: function InclusionTree_propagateValues() {
  40302. var levelIndex = this.currentLevel;
  40303. var level = this.levels[levelIndex];
  40304. var currentValue = level.items[level.index];
  40305. while (--levelIndex >= 0) {
  40306. level = this.levels[levelIndex];
  40307. level.items[level.index] = currentValue;
  40308. }
  40309. },
  40310. nextLevel: function InclusionTree_nextLevel() {
  40311. var currentLevel = this.currentLevel;
  40312. var level = this.levels[currentLevel];
  40313. var value = level.items[level.index];
  40314. level.items[level.index] = 0xFF;
  40315. currentLevel--;
  40316. if (currentLevel < 0) {
  40317. return false;
  40318. }
  40319. this.currentLevel = currentLevel;
  40320. level = this.levels[currentLevel];
  40321. level.items[level.index] = value;
  40322. return true;
  40323. }
  40324. };
  40325. return InclusionTree;
  40326. })();
  40327. // Section D. Coefficient bit modeling
  40328. var BitModel = (function BitModelClosure() {
  40329. var UNIFORM_CONTEXT = 17;
  40330. var RUNLENGTH_CONTEXT = 18;
  40331. // Table D-1
  40332. // The index is binary presentation: 0dddvvhh, ddd - sum of Di (0..4),
  40333. // vv - sum of Vi (0..2), and hh - sum of Hi (0..2)
  40334. var LLAndLHContextsLabel = new Uint8Array([
  40335. 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,
  40336. 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,
  40337. 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
  40338. ]);
  40339. var HLContextLabel = new Uint8Array([
  40340. 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,
  40341. 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,
  40342. 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
  40343. ]);
  40344. var HHContextLabel = new Uint8Array([
  40345. 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,
  40346. 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,
  40347. 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
  40348. ]);
  40349. function BitModel(width, height, subband, zeroBitPlanes, mb) {
  40350. this.width = width;
  40351. this.height = height;
  40352. this.contextLabelTable = (subband === 'HH' ? HHContextLabel :
  40353. (subband === 'HL' ? HLContextLabel : LLAndLHContextsLabel));
  40354. var coefficientCount = width * height;
  40355. // coefficients outside the encoding region treated as insignificant
  40356. // add border state cells for significanceState
  40357. this.neighborsSignificance = new Uint8Array(coefficientCount);
  40358. this.coefficentsSign = new Uint8Array(coefficientCount);
  40359. this.coefficentsMagnitude = mb > 14 ? new Uint32Array(coefficientCount) :
  40360. mb > 6 ? new Uint16Array(coefficientCount) :
  40361. new Uint8Array(coefficientCount);
  40362. this.processingFlags = new Uint8Array(coefficientCount);
  40363. var bitsDecoded = new Uint8Array(coefficientCount);
  40364. if (zeroBitPlanes !== 0) {
  40365. for (var i = 0; i < coefficientCount; i++) {
  40366. bitsDecoded[i] = zeroBitPlanes;
  40367. }
  40368. }
  40369. this.bitsDecoded = bitsDecoded;
  40370. this.reset();
  40371. }
  40372. BitModel.prototype = {
  40373. setDecoder: function BitModel_setDecoder(decoder) {
  40374. this.decoder = decoder;
  40375. },
  40376. reset: function BitModel_reset() {
  40377. // We have 17 contexts that are accessed via context labels,
  40378. // plus the uniform and runlength context.
  40379. this.contexts = new Int8Array(19);
  40380. // Contexts are packed into 1 byte:
  40381. // highest 7 bits carry the index, lowest bit carries mps
  40382. this.contexts[0] = (4 << 1) | 0;
  40383. this.contexts[UNIFORM_CONTEXT] = (46 << 1) | 0;
  40384. this.contexts[RUNLENGTH_CONTEXT] = (3 << 1) | 0;
  40385. },
  40386. setNeighborsSignificance:
  40387. function BitModel_setNeighborsSignificance(row, column, index) {
  40388. var neighborsSignificance = this.neighborsSignificance;
  40389. var width = this.width, height = this.height;
  40390. var left = (column > 0);
  40391. var right = (column + 1 < width);
  40392. var i;
  40393. if (row > 0) {
  40394. i = index - width;
  40395. if (left) {
  40396. neighborsSignificance[i - 1] += 0x10;
  40397. }
  40398. if (right) {
  40399. neighborsSignificance[i + 1] += 0x10;
  40400. }
  40401. neighborsSignificance[i] += 0x04;
  40402. }
  40403. if (row + 1 < height) {
  40404. i = index + width;
  40405. if (left) {
  40406. neighborsSignificance[i - 1] += 0x10;
  40407. }
  40408. if (right) {
  40409. neighborsSignificance[i + 1] += 0x10;
  40410. }
  40411. neighborsSignificance[i] += 0x04;
  40412. }
  40413. if (left) {
  40414. neighborsSignificance[index - 1] += 0x01;
  40415. }
  40416. if (right) {
  40417. neighborsSignificance[index + 1] += 0x01;
  40418. }
  40419. neighborsSignificance[index] |= 0x80;
  40420. },
  40421. runSignificancePropogationPass:
  40422. function BitModel_runSignificancePropogationPass() {
  40423. var decoder = this.decoder;
  40424. var width = this.width, height = this.height;
  40425. var coefficentsMagnitude = this.coefficentsMagnitude;
  40426. var coefficentsSign = this.coefficentsSign;
  40427. var neighborsSignificance = this.neighborsSignificance;
  40428. var processingFlags = this.processingFlags;
  40429. var contexts = this.contexts;
  40430. var labels = this.contextLabelTable;
  40431. var bitsDecoded = this.bitsDecoded;
  40432. var processedInverseMask = ~1;
  40433. var processedMask = 1;
  40434. var firstMagnitudeBitMask = 2;
  40435. for (var i0 = 0; i0 < height; i0 += 4) {
  40436. for (var j = 0; j < width; j++) {
  40437. var index = i0 * width + j;
  40438. for (var i1 = 0; i1 < 4; i1++, index += width) {
  40439. var i = i0 + i1;
  40440. if (i >= height) {
  40441. break;
  40442. }
  40443. // clear processed flag first
  40444. processingFlags[index] &= processedInverseMask;
  40445. if (coefficentsMagnitude[index] ||
  40446. !neighborsSignificance[index]) {
  40447. continue;
  40448. }
  40449. var contextLabel = labels[neighborsSignificance[index]];
  40450. var decision = decoder.readBit(contexts, contextLabel);
  40451. if (decision) {
  40452. var sign = this.decodeSignBit(i, j, index);
  40453. coefficentsSign[index] = sign;
  40454. coefficentsMagnitude[index] = 1;
  40455. this.setNeighborsSignificance(i, j, index);
  40456. processingFlags[index] |= firstMagnitudeBitMask;
  40457. }
  40458. bitsDecoded[index]++;
  40459. processingFlags[index] |= processedMask;
  40460. }
  40461. }
  40462. }
  40463. },
  40464. decodeSignBit: function BitModel_decodeSignBit(row, column, index) {
  40465. var width = this.width, height = this.height;
  40466. var coefficentsMagnitude = this.coefficentsMagnitude;
  40467. var coefficentsSign = this.coefficentsSign;
  40468. var contribution, sign0, sign1, significance1;
  40469. var contextLabel, decoded;
  40470. // calculate horizontal contribution
  40471. significance1 = (column > 0 && coefficentsMagnitude[index - 1] !== 0);
  40472. if (column + 1 < width && coefficentsMagnitude[index + 1] !== 0) {
  40473. sign1 = coefficentsSign[index + 1];
  40474. if (significance1) {
  40475. sign0 = coefficentsSign[index - 1];
  40476. contribution = 1 - sign1 - sign0;
  40477. } else {
  40478. contribution = 1 - sign1 - sign1;
  40479. }
  40480. } else if (significance1) {
  40481. sign0 = coefficentsSign[index - 1];
  40482. contribution = 1 - sign0 - sign0;
  40483. } else {
  40484. contribution = 0;
  40485. }
  40486. var horizontalContribution = 3 * contribution;
  40487. // calculate vertical contribution and combine with the horizontal
  40488. significance1 = (row > 0 && coefficentsMagnitude[index - width] !== 0);
  40489. if (row + 1 < height && coefficentsMagnitude[index + width] !== 0) {
  40490. sign1 = coefficentsSign[index + width];
  40491. if (significance1) {
  40492. sign0 = coefficentsSign[index - width];
  40493. contribution = 1 - sign1 - sign0 + horizontalContribution;
  40494. } else {
  40495. contribution = 1 - sign1 - sign1 + horizontalContribution;
  40496. }
  40497. } else if (significance1) {
  40498. sign0 = coefficentsSign[index - width];
  40499. contribution = 1 - sign0 - sign0 + horizontalContribution;
  40500. } else {
  40501. contribution = horizontalContribution;
  40502. }
  40503. if (contribution >= 0) {
  40504. contextLabel = 9 + contribution;
  40505. decoded = this.decoder.readBit(this.contexts, contextLabel);
  40506. } else {
  40507. contextLabel = 9 - contribution;
  40508. decoded = this.decoder.readBit(this.contexts, contextLabel) ^ 1;
  40509. }
  40510. return decoded;
  40511. },
  40512. runMagnitudeRefinementPass:
  40513. function BitModel_runMagnitudeRefinementPass() {
  40514. var decoder = this.decoder;
  40515. var width = this.width, height = this.height;
  40516. var coefficentsMagnitude = this.coefficentsMagnitude;
  40517. var neighborsSignificance = this.neighborsSignificance;
  40518. var contexts = this.contexts;
  40519. var bitsDecoded = this.bitsDecoded;
  40520. var processingFlags = this.processingFlags;
  40521. var processedMask = 1;
  40522. var firstMagnitudeBitMask = 2;
  40523. var length = width * height;
  40524. var width4 = width * 4;
  40525. for (var index0 = 0, indexNext; index0 < length; index0 = indexNext) {
  40526. indexNext = Math.min(length, index0 + width4);
  40527. for (var j = 0; j < width; j++) {
  40528. for (var index = index0 + j; index < indexNext; index += width) {
  40529. // significant but not those that have just become
  40530. if (!coefficentsMagnitude[index] ||
  40531. (processingFlags[index] & processedMask) !== 0) {
  40532. continue;
  40533. }
  40534. var contextLabel = 16;
  40535. if ((processingFlags[index] & firstMagnitudeBitMask) !== 0) {
  40536. processingFlags[index] ^= firstMagnitudeBitMask;
  40537. // first refinement
  40538. var significance = neighborsSignificance[index] & 127;
  40539. contextLabel = significance === 0 ? 15 : 14;
  40540. }
  40541. var bit = decoder.readBit(contexts, contextLabel);
  40542. coefficentsMagnitude[index] =
  40543. (coefficentsMagnitude[index] << 1) | bit;
  40544. bitsDecoded[index]++;
  40545. processingFlags[index] |= processedMask;
  40546. }
  40547. }
  40548. }
  40549. },
  40550. runCleanupPass: function BitModel_runCleanupPass() {
  40551. var decoder = this.decoder;
  40552. var width = this.width, height = this.height;
  40553. var neighborsSignificance = this.neighborsSignificance;
  40554. var coefficentsMagnitude = this.coefficentsMagnitude;
  40555. var coefficentsSign = this.coefficentsSign;
  40556. var contexts = this.contexts;
  40557. var labels = this.contextLabelTable;
  40558. var bitsDecoded = this.bitsDecoded;
  40559. var processingFlags = this.processingFlags;
  40560. var processedMask = 1;
  40561. var firstMagnitudeBitMask = 2;
  40562. var oneRowDown = width;
  40563. var twoRowsDown = width * 2;
  40564. var threeRowsDown = width * 3;
  40565. var iNext;
  40566. for (var i0 = 0; i0 < height; i0 = iNext) {
  40567. iNext = Math.min(i0 + 4, height);
  40568. var indexBase = i0 * width;
  40569. var checkAllEmpty = i0 + 3 < height;
  40570. for (var j = 0; j < width; j++) {
  40571. var index0 = indexBase + j;
  40572. // using the property: labels[neighborsSignificance[index]] === 0
  40573. // when neighborsSignificance[index] === 0
  40574. var allEmpty = (checkAllEmpty &&
  40575. processingFlags[index0] === 0 &&
  40576. processingFlags[index0 + oneRowDown] === 0 &&
  40577. processingFlags[index0 + twoRowsDown] === 0 &&
  40578. processingFlags[index0 + threeRowsDown] === 0 &&
  40579. neighborsSignificance[index0] === 0 &&
  40580. neighborsSignificance[index0 + oneRowDown] === 0 &&
  40581. neighborsSignificance[index0 + twoRowsDown] === 0 &&
  40582. neighborsSignificance[index0 + threeRowsDown] === 0);
  40583. var i1 = 0, index = index0;
  40584. var i = i0, sign;
  40585. if (allEmpty) {
  40586. var hasSignificantCoefficent =
  40587. decoder.readBit(contexts, RUNLENGTH_CONTEXT);
  40588. if (!hasSignificantCoefficent) {
  40589. bitsDecoded[index0]++;
  40590. bitsDecoded[index0 + oneRowDown]++;
  40591. bitsDecoded[index0 + twoRowsDown]++;
  40592. bitsDecoded[index0 + threeRowsDown]++;
  40593. continue; // next column
  40594. }
  40595. i1 = (decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
  40596. decoder.readBit(contexts, UNIFORM_CONTEXT);
  40597. if (i1 !== 0) {
  40598. i = i0 + i1;
  40599. index += i1 * width;
  40600. }
  40601. sign = this.decodeSignBit(i, j, index);
  40602. coefficentsSign[index] = sign;
  40603. coefficentsMagnitude[index] = 1;
  40604. this.setNeighborsSignificance(i, j, index);
  40605. processingFlags[index] |= firstMagnitudeBitMask;
  40606. index = index0;
  40607. for (var i2 = i0; i2 <= i; i2++, index += width) {
  40608. bitsDecoded[index]++;
  40609. }
  40610. i1++;
  40611. }
  40612. for (i = i0 + i1; i < iNext; i++, index += width) {
  40613. if (coefficentsMagnitude[index] ||
  40614. (processingFlags[index] & processedMask) !== 0) {
  40615. continue;
  40616. }
  40617. var contextLabel = labels[neighborsSignificance[index]];
  40618. var decision = decoder.readBit(contexts, contextLabel);
  40619. if (decision === 1) {
  40620. sign = this.decodeSignBit(i, j, index);
  40621. coefficentsSign[index] = sign;
  40622. coefficentsMagnitude[index] = 1;
  40623. this.setNeighborsSignificance(i, j, index);
  40624. processingFlags[index] |= firstMagnitudeBitMask;
  40625. }
  40626. bitsDecoded[index]++;
  40627. }
  40628. }
  40629. }
  40630. },
  40631. checkSegmentationSymbol: function BitModel_checkSegmentationSymbol() {
  40632. var decoder = this.decoder;
  40633. var contexts = this.contexts;
  40634. var symbol = (decoder.readBit(contexts, UNIFORM_CONTEXT) << 3) |
  40635. (decoder.readBit(contexts, UNIFORM_CONTEXT) << 2) |
  40636. (decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
  40637. decoder.readBit(contexts, UNIFORM_CONTEXT);
  40638. if (symbol !== 0xA) {
  40639. throw new Error('JPX Error: Invalid segmentation symbol');
  40640. }
  40641. }
  40642. };
  40643. return BitModel;
  40644. })();
  40645. // Section F, Discrete wavelet transformation
  40646. var Transform = (function TransformClosure() {
  40647. function Transform() {}
  40648. Transform.prototype.calculate =
  40649. function transformCalculate(subbands, u0, v0) {
  40650. var ll = subbands[0];
  40651. for (var i = 1, ii = subbands.length; i < ii; i++) {
  40652. ll = this.iterate(ll, subbands[i], u0, v0);
  40653. }
  40654. return ll;
  40655. };
  40656. Transform.prototype.extend = function extend(buffer, offset, size) {
  40657. // Section F.3.7 extending... using max extension of 4
  40658. var i1 = offset - 1, j1 = offset + 1;
  40659. var i2 = offset + size - 2, j2 = offset + size;
  40660. buffer[i1--] = buffer[j1++];
  40661. buffer[j2++] = buffer[i2--];
  40662. buffer[i1--] = buffer[j1++];
  40663. buffer[j2++] = buffer[i2--];
  40664. buffer[i1--] = buffer[j1++];
  40665. buffer[j2++] = buffer[i2--];
  40666. buffer[i1] = buffer[j1];
  40667. buffer[j2] = buffer[i2];
  40668. };
  40669. Transform.prototype.iterate = function Transform_iterate(ll, hl_lh_hh,
  40670. u0, v0) {
  40671. var llWidth = ll.width, llHeight = ll.height, llItems = ll.items;
  40672. var width = hl_lh_hh.width;
  40673. var height = hl_lh_hh.height;
  40674. var items = hl_lh_hh.items;
  40675. var i, j, k, l, u, v;
  40676. // Interleave LL according to Section F.3.3
  40677. for (k = 0, i = 0; i < llHeight; i++) {
  40678. l = i * 2 * width;
  40679. for (j = 0; j < llWidth; j++, k++, l += 2) {
  40680. items[l] = llItems[k];
  40681. }
  40682. }
  40683. // The LL band is not needed anymore.
  40684. llItems = ll.items = null;
  40685. var bufferPadding = 4;
  40686. var rowBuffer = new Float32Array(width + 2 * bufferPadding);
  40687. // Section F.3.4 HOR_SR
  40688. if (width === 1) {
  40689. // if width = 1, when u0 even keep items as is, when odd divide by 2
  40690. if ((u0 & 1) !== 0) {
  40691. for (v = 0, k = 0; v < height; v++, k += width) {
  40692. items[k] *= 0.5;
  40693. }
  40694. }
  40695. } else {
  40696. for (v = 0, k = 0; v < height; v++, k += width) {
  40697. rowBuffer.set(items.subarray(k, k + width), bufferPadding);
  40698. this.extend(rowBuffer, bufferPadding, width);
  40699. this.filter(rowBuffer, bufferPadding, width);
  40700. items.set(
  40701. rowBuffer.subarray(bufferPadding, bufferPadding + width),
  40702. k);
  40703. }
  40704. }
  40705. // Accesses to the items array can take long, because it may not fit into
  40706. // CPU cache and has to be fetched from main memory. Since subsequent
  40707. // accesses to the items array are not local when reading columns, we
  40708. // have a cache miss every time. To reduce cache misses, get up to
  40709. // 'numBuffers' items at a time and store them into the individual
  40710. // buffers. The colBuffers should be small enough to fit into CPU cache.
  40711. var numBuffers = 16;
  40712. var colBuffers = [];
  40713. for (i = 0; i < numBuffers; i++) {
  40714. colBuffers.push(new Float32Array(height + 2 * bufferPadding));
  40715. }
  40716. var b, currentBuffer = 0;
  40717. ll = bufferPadding + height;
  40718. // Section F.3.5 VER_SR
  40719. if (height === 1) {
  40720. // if height = 1, when v0 even keep items as is, when odd divide by 2
  40721. if ((v0 & 1) !== 0) {
  40722. for (u = 0; u < width; u++) {
  40723. items[u] *= 0.5;
  40724. }
  40725. }
  40726. } else {
  40727. for (u = 0; u < width; u++) {
  40728. // if we ran out of buffers, copy several image columns at once
  40729. if (currentBuffer === 0) {
  40730. numBuffers = Math.min(width - u, numBuffers);
  40731. for (k = u, l = bufferPadding; l < ll; k += width, l++) {
  40732. for (b = 0; b < numBuffers; b++) {
  40733. colBuffers[b][l] = items[k + b];
  40734. }
  40735. }
  40736. currentBuffer = numBuffers;
  40737. }
  40738. currentBuffer--;
  40739. var buffer = colBuffers[currentBuffer];
  40740. this.extend(buffer, bufferPadding, height);
  40741. this.filter(buffer, bufferPadding, height);
  40742. // If this is last buffer in this group of buffers, flush all buffers.
  40743. if (currentBuffer === 0) {
  40744. k = u - numBuffers + 1;
  40745. for (l = bufferPadding; l < ll; k += width, l++) {
  40746. for (b = 0; b < numBuffers; b++) {
  40747. items[k + b] = colBuffers[b][l];
  40748. }
  40749. }
  40750. }
  40751. }
  40752. }
  40753. return {
  40754. width: width,
  40755. height: height,
  40756. items: items
  40757. };
  40758. };
  40759. return Transform;
  40760. })();
  40761. // Section 3.8.2 Irreversible 9-7 filter
  40762. var IrreversibleTransform = (function IrreversibleTransformClosure() {
  40763. function IrreversibleTransform() {
  40764. Transform.call(this);
  40765. }
  40766. IrreversibleTransform.prototype = Object.create(Transform.prototype);
  40767. IrreversibleTransform.prototype.filter =
  40768. function irreversibleTransformFilter(x, offset, length) {
  40769. var len = length >> 1;
  40770. offset = offset | 0;
  40771. var j, n, current, next;
  40772. var alpha = -1.586134342059924;
  40773. var beta = -0.052980118572961;
  40774. var gamma = 0.882911075530934;
  40775. var delta = 0.443506852043971;
  40776. var K = 1.230174104914001;
  40777. var K_ = 1 / K;
  40778. // step 1 is combined with step 3
  40779. // step 2
  40780. j = offset - 3;
  40781. for (n = len + 4; n--; j += 2) {
  40782. x[j] *= K_;
  40783. }
  40784. // step 1 & 3
  40785. j = offset - 2;
  40786. current = delta * x[j -1];
  40787. for (n = len + 3; n--; j += 2) {
  40788. next = delta * x[j + 1];
  40789. x[j] = K * x[j] - current - next;
  40790. if (n--) {
  40791. j += 2;
  40792. current = delta * x[j + 1];
  40793. x[j] = K * x[j] - current - next;
  40794. } else {
  40795. break;
  40796. }
  40797. }
  40798. // step 4
  40799. j = offset - 1;
  40800. current = gamma * x[j - 1];
  40801. for (n = len + 2; n--; j += 2) {
  40802. next = gamma * x[j + 1];
  40803. x[j] -= current + next;
  40804. if (n--) {
  40805. j += 2;
  40806. current = gamma * x[j + 1];
  40807. x[j] -= current + next;
  40808. } else {
  40809. break;
  40810. }
  40811. }
  40812. // step 5
  40813. j = offset;
  40814. current = beta * x[j - 1];
  40815. for (n = len + 1; n--; j += 2) {
  40816. next = beta * x[j + 1];
  40817. x[j] -= current + next;
  40818. if (n--) {
  40819. j += 2;
  40820. current = beta * x[j + 1];
  40821. x[j] -= current + next;
  40822. } else {
  40823. break;
  40824. }
  40825. }
  40826. // step 6
  40827. if (len !== 0) {
  40828. j = offset + 1;
  40829. current = alpha * x[j - 1];
  40830. for (n = len; n--; j += 2) {
  40831. next = alpha * x[j + 1];
  40832. x[j] -= current + next;
  40833. if (n--) {
  40834. j += 2;
  40835. current = alpha * x[j + 1];
  40836. x[j] -= current + next;
  40837. } else {
  40838. break;
  40839. }
  40840. }
  40841. }
  40842. };
  40843. return IrreversibleTransform;
  40844. })();
  40845. // Section 3.8.1 Reversible 5-3 filter
  40846. var ReversibleTransform = (function ReversibleTransformClosure() {
  40847. function ReversibleTransform() {
  40848. Transform.call(this);
  40849. }
  40850. ReversibleTransform.prototype = Object.create(Transform.prototype);
  40851. ReversibleTransform.prototype.filter =
  40852. function reversibleTransformFilter(x, offset, length) {
  40853. var len = length >> 1;
  40854. offset = offset | 0;
  40855. var j, n;
  40856. for (j = offset, n = len + 1; n--; j += 2) {
  40857. x[j] -= (x[j - 1] + x[j + 1] + 2) >> 2;
  40858. }
  40859. for (j = offset + 1, n = len; n--; j += 2) {
  40860. x[j] += (x[j - 1] + x[j + 1]) >> 1;
  40861. }
  40862. };
  40863. return ReversibleTransform;
  40864. })();
  40865. return JpxImage;
  40866. })();
  40867. var Jbig2Image = (function Jbig2ImageClosure() {
  40868. // Utility data structures
  40869. function ContextCache() {}
  40870. ContextCache.prototype = {
  40871. getContexts: function(id) {
  40872. if (id in this) {
  40873. return this[id];
  40874. }
  40875. return (this[id] = new Int8Array(1 << 16));
  40876. }
  40877. };
  40878. function DecodingContext(data, start, end) {
  40879. this.data = data;
  40880. this.start = start;
  40881. this.end = end;
  40882. }
  40883. DecodingContext.prototype = {
  40884. get decoder() {
  40885. var decoder = new ArithmeticDecoder(this.data, this.start, this.end);
  40886. return shadow(this, 'decoder', decoder);
  40887. },
  40888. get contextCache() {
  40889. var cache = new ContextCache();
  40890. return shadow(this, 'contextCache', cache);
  40891. }
  40892. };
  40893. // Annex A. Arithmetic Integer Decoding Procedure
  40894. // A.2 Procedure for decoding values
  40895. function decodeInteger(contextCache, procedure, decoder) {
  40896. var contexts = contextCache.getContexts(procedure);
  40897. var prev = 1;
  40898. function readBits(length) {
  40899. var v = 0;
  40900. for (var i = 0; i < length; i++) {
  40901. var bit = decoder.readBit(contexts, prev);
  40902. prev = (prev < 256 ? (prev << 1) | bit :
  40903. (((prev << 1) | bit) & 511) | 256);
  40904. v = (v << 1) | bit;
  40905. }
  40906. return v >>> 0;
  40907. }
  40908. var sign = readBits(1);
  40909. var value = readBits(1) ?
  40910. (readBits(1) ?
  40911. (readBits(1) ?
  40912. (readBits(1) ?
  40913. (readBits(1) ?
  40914. (readBits(32) + 4436) :
  40915. readBits(12) + 340) :
  40916. readBits(8) + 84) :
  40917. readBits(6) + 20) :
  40918. readBits(4) + 4) :
  40919. readBits(2);
  40920. return (sign === 0 ? value : (value > 0 ? -value : null));
  40921. }
  40922. // A.3 The IAID decoding procedure
  40923. function decodeIAID(contextCache, decoder, codeLength) {
  40924. var contexts = contextCache.getContexts('IAID');
  40925. var prev = 1;
  40926. for (var i = 0; i < codeLength; i++) {
  40927. var bit = decoder.readBit(contexts, prev);
  40928. prev = (prev << 1) | bit;
  40929. }
  40930. if (codeLength < 31) {
  40931. return prev & ((1 << codeLength) - 1);
  40932. }
  40933. return prev & 0x7FFFFFFF;
  40934. }
  40935. // 7.3 Segment types
  40936. var SegmentTypes = [
  40937. 'SymbolDictionary', null, null, null, 'IntermediateTextRegion', null,
  40938. 'ImmediateTextRegion', 'ImmediateLosslessTextRegion', null, null, null,
  40939. null, null, null, null, null, 'patternDictionary', null, null, null,
  40940. 'IntermediateHalftoneRegion', null, 'ImmediateHalftoneRegion',
  40941. 'ImmediateLosslessHalftoneRegion', null, null, null, null, null, null, null,
  40942. null, null, null, null, null, 'IntermediateGenericRegion', null,
  40943. 'ImmediateGenericRegion', 'ImmediateLosslessGenericRegion',
  40944. 'IntermediateGenericRefinementRegion', null,
  40945. 'ImmediateGenericRefinementRegion',
  40946. 'ImmediateLosslessGenericRefinementRegion', null, null, null, null,
  40947. 'PageInformation', 'EndOfPage', 'EndOfStripe', 'EndOfFile', 'Profiles',
  40948. 'Tables', null, null, null, null, null, null, null, null,
  40949. 'Extension'
  40950. ];
  40951. var CodingTemplates = [
  40952. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: -2, y: -1},
  40953. {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: 2, y: -1},
  40954. {x: -4, y: 0}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}],
  40955. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: 2, y: -2},
  40956. {x: -2, y: -1}, {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1},
  40957. {x: 2, y: -1}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}],
  40958. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: -2, y: -1},
  40959. {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: -2, y: 0},
  40960. {x: -1, y: 0}],
  40961. [{x: -3, y: -1}, {x: -2, y: -1}, {x: -1, y: -1}, {x: 0, y: -1},
  40962. {x: 1, y: -1}, {x: -4, y: 0}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}]
  40963. ];
  40964. var RefinementTemplates = [
  40965. {
  40966. coding: [{x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}],
  40967. reference: [{x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}, {x: 0, y: 0},
  40968. {x: 1, y: 0}, {x: -1, y: 1}, {x: 0, y: 1}, {x: 1, y: 1}]
  40969. },
  40970. {
  40971. coding: [{x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}],
  40972. reference: [{x: 0, y: -1}, {x: -1, y: 0}, {x: 0, y: 0}, {x: 1, y: 0},
  40973. {x: 0, y: 1}, {x: 1, y: 1}]
  40974. }
  40975. ];
  40976. // See 6.2.5.7 Decoding the bitmap.
  40977. var ReusedContexts = [
  40978. 0x9B25, // 10011 0110010 0101
  40979. 0x0795, // 0011 110010 101
  40980. 0x00E5, // 001 11001 01
  40981. 0x0195 // 011001 0101
  40982. ];
  40983. var RefinementReusedContexts = [
  40984. 0x0020, // '000' + '0' (coding) + '00010000' + '0' (reference)
  40985. 0x0008 // '0000' + '001000'
  40986. ];
  40987. function decodeBitmapTemplate0(width, height, decodingContext) {
  40988. var decoder = decodingContext.decoder;
  40989. var contexts = decodingContext.contextCache.getContexts('GB');
  40990. var contextLabel, i, j, pixel, row, row1, row2, bitmap = [];
  40991. // ...ooooo....
  40992. // ..ooooooo... Context template for current pixel (X)
  40993. // .ooooX...... (concatenate values of 'o'-pixels to get contextLabel)
  40994. var OLD_PIXEL_MASK = 0x7BF7; // 01111 0111111 0111
  40995. for (i = 0; i < height; i++) {
  40996. row = bitmap[i] = new Uint8Array(width);
  40997. row1 = (i < 1) ? row : bitmap[i - 1];
  40998. row2 = (i < 2) ? row : bitmap[i - 2];
  40999. // At the beginning of each row:
  41000. // Fill contextLabel with pixels that are above/right of (X)
  41001. contextLabel = (row2[0] << 13) | (row2[1] << 12) | (row2[2] << 11) |
  41002. (row1[0] << 7) | (row1[1] << 6) | (row1[2] << 5) |
  41003. (row1[3] << 4);
  41004. for (j = 0; j < width; j++) {
  41005. row[j] = pixel = decoder.readBit(contexts, contextLabel);
  41006. // At each pixel: Clear contextLabel pixels that are shifted
  41007. // out of the context, then add new ones.
  41008. contextLabel = ((contextLabel & OLD_PIXEL_MASK) << 1) |
  41009. (j + 3 < width ? row2[j + 3] << 11 : 0) |
  41010. (j + 4 < width ? row1[j + 4] << 4 : 0) | pixel;
  41011. }
  41012. }
  41013. return bitmap;
  41014. }
  41015. // 6.2 Generic Region Decoding Procedure
  41016. function decodeBitmap(mmr, width, height, templateIndex, prediction, skip, at,
  41017. decodingContext) {
  41018. if (mmr) {
  41019. error('JBIG2 error: MMR encoding is not supported');
  41020. }
  41021. // Use optimized version for the most common case
  41022. if (templateIndex === 0 && !skip && !prediction && at.length === 4 &&
  41023. at[0].x === 3 && at[0].y === -1 && at[1].x === -3 && at[1].y === -1 &&
  41024. at[2].x === 2 && at[2].y === -2 && at[3].x === -2 && at[3].y === -2) {
  41025. return decodeBitmapTemplate0(width, height, decodingContext);
  41026. }
  41027. var useskip = !!skip;
  41028. var template = CodingTemplates[templateIndex].concat(at);
  41029. // Sorting is non-standard, and it is not required. But sorting increases
  41030. // the number of template bits that can be reused from the previous
  41031. // contextLabel in the main loop.
  41032. template.sort(function (a, b) {
  41033. return (a.y - b.y) || (a.x - b.x);
  41034. });
  41035. var templateLength = template.length;
  41036. var templateX = new Int8Array(templateLength);
  41037. var templateY = new Int8Array(templateLength);
  41038. var changingTemplateEntries = [];
  41039. var reuseMask = 0, minX = 0, maxX = 0, minY = 0;
  41040. var c, k;
  41041. for (k = 0; k < templateLength; k++) {
  41042. templateX[k] = template[k].x;
  41043. templateY[k] = template[k].y;
  41044. minX = Math.min(minX, template[k].x);
  41045. maxX = Math.max(maxX, template[k].x);
  41046. minY = Math.min(minY, template[k].y);
  41047. // Check if the template pixel appears in two consecutive context labels,
  41048. // so it can be reused. Otherwise, we add it to the list of changing
  41049. // template entries.
  41050. if (k < templateLength - 1 &&
  41051. template[k].y === template[k + 1].y &&
  41052. template[k].x === template[k + 1].x - 1) {
  41053. reuseMask |= 1 << (templateLength - 1 - k);
  41054. } else {
  41055. changingTemplateEntries.push(k);
  41056. }
  41057. }
  41058. var changingEntriesLength = changingTemplateEntries.length;
  41059. var changingTemplateX = new Int8Array(changingEntriesLength);
  41060. var changingTemplateY = new Int8Array(changingEntriesLength);
  41061. var changingTemplateBit = new Uint16Array(changingEntriesLength);
  41062. for (c = 0; c < changingEntriesLength; c++) {
  41063. k = changingTemplateEntries[c];
  41064. changingTemplateX[c] = template[k].x;
  41065. changingTemplateY[c] = template[k].y;
  41066. changingTemplateBit[c] = 1 << (templateLength - 1 - k);
  41067. }
  41068. // Get the safe bounding box edges from the width, height, minX, maxX, minY
  41069. var sbb_left = -minX;
  41070. var sbb_top = -minY;
  41071. var sbb_right = width - maxX;
  41072. var pseudoPixelContext = ReusedContexts[templateIndex];
  41073. var row = new Uint8Array(width);
  41074. var bitmap = [];
  41075. var decoder = decodingContext.decoder;
  41076. var contexts = decodingContext.contextCache.getContexts('GB');
  41077. var ltp = 0, j, i0, j0, contextLabel = 0, bit, shift;
  41078. for (var i = 0; i < height; i++) {
  41079. if (prediction) {
  41080. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  41081. ltp ^= sltp;
  41082. if (ltp) {
  41083. bitmap.push(row); // duplicate previous row
  41084. continue;
  41085. }
  41086. }
  41087. row = new Uint8Array(row);
  41088. bitmap.push(row);
  41089. for (j = 0; j < width; j++) {
  41090. if (useskip && skip[i][j]) {
  41091. row[j] = 0;
  41092. continue;
  41093. }
  41094. // Are we in the middle of a scanline, so we can reuse contextLabel
  41095. // bits?
  41096. if (j >= sbb_left && j < sbb_right && i >= sbb_top) {
  41097. // If yes, we can just shift the bits that are reusable and only
  41098. // fetch the remaining ones.
  41099. contextLabel = (contextLabel << 1) & reuseMask;
  41100. for (k = 0; k < changingEntriesLength; k++) {
  41101. i0 = i + changingTemplateY[k];
  41102. j0 = j + changingTemplateX[k];
  41103. bit = bitmap[i0][j0];
  41104. if (bit) {
  41105. bit = changingTemplateBit[k];
  41106. contextLabel |= bit;
  41107. }
  41108. }
  41109. } else {
  41110. // compute the contextLabel from scratch
  41111. contextLabel = 0;
  41112. shift = templateLength - 1;
  41113. for (k = 0; k < templateLength; k++, shift--) {
  41114. j0 = j + templateX[k];
  41115. if (j0 >= 0 && j0 < width) {
  41116. i0 = i + templateY[k];
  41117. if (i0 >= 0) {
  41118. bit = bitmap[i0][j0];
  41119. if (bit) {
  41120. contextLabel |= bit << shift;
  41121. }
  41122. }
  41123. }
  41124. }
  41125. }
  41126. var pixel = decoder.readBit(contexts, contextLabel);
  41127. row[j] = pixel;
  41128. }
  41129. }
  41130. return bitmap;
  41131. }
  41132. // 6.3.2 Generic Refinement Region Decoding Procedure
  41133. function decodeRefinement(width, height, templateIndex, referenceBitmap,
  41134. offsetX, offsetY, prediction, at,
  41135. decodingContext) {
  41136. var codingTemplate = RefinementTemplates[templateIndex].coding;
  41137. if (templateIndex === 0) {
  41138. codingTemplate = codingTemplate.concat([at[0]]);
  41139. }
  41140. var codingTemplateLength = codingTemplate.length;
  41141. var codingTemplateX = new Int32Array(codingTemplateLength);
  41142. var codingTemplateY = new Int32Array(codingTemplateLength);
  41143. var k;
  41144. for (k = 0; k < codingTemplateLength; k++) {
  41145. codingTemplateX[k] = codingTemplate[k].x;
  41146. codingTemplateY[k] = codingTemplate[k].y;
  41147. }
  41148. var referenceTemplate = RefinementTemplates[templateIndex].reference;
  41149. if (templateIndex === 0) {
  41150. referenceTemplate = referenceTemplate.concat([at[1]]);
  41151. }
  41152. var referenceTemplateLength = referenceTemplate.length;
  41153. var referenceTemplateX = new Int32Array(referenceTemplateLength);
  41154. var referenceTemplateY = new Int32Array(referenceTemplateLength);
  41155. for (k = 0; k < referenceTemplateLength; k++) {
  41156. referenceTemplateX[k] = referenceTemplate[k].x;
  41157. referenceTemplateY[k] = referenceTemplate[k].y;
  41158. }
  41159. var referenceWidth = referenceBitmap[0].length;
  41160. var referenceHeight = referenceBitmap.length;
  41161. var pseudoPixelContext = RefinementReusedContexts[templateIndex];
  41162. var bitmap = [];
  41163. var decoder = decodingContext.decoder;
  41164. var contexts = decodingContext.contextCache.getContexts('GR');
  41165. var ltp = 0;
  41166. for (var i = 0; i < height; i++) {
  41167. if (prediction) {
  41168. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  41169. ltp ^= sltp;
  41170. if (ltp) {
  41171. error('JBIG2 error: prediction is not supported');
  41172. }
  41173. }
  41174. var row = new Uint8Array(width);
  41175. bitmap.push(row);
  41176. for (var j = 0; j < width; j++) {
  41177. var i0, j0;
  41178. var contextLabel = 0;
  41179. for (k = 0; k < codingTemplateLength; k++) {
  41180. i0 = i + codingTemplateY[k];
  41181. j0 = j + codingTemplateX[k];
  41182. if (i0 < 0 || j0 < 0 || j0 >= width) {
  41183. contextLabel <<= 1; // out of bound pixel
  41184. } else {
  41185. contextLabel = (contextLabel << 1) | bitmap[i0][j0];
  41186. }
  41187. }
  41188. for (k = 0; k < referenceTemplateLength; k++) {
  41189. i0 = i + referenceTemplateY[k] + offsetY;
  41190. j0 = j + referenceTemplateX[k] + offsetX;
  41191. if (i0 < 0 || i0 >= referenceHeight || j0 < 0 ||
  41192. j0 >= referenceWidth) {
  41193. contextLabel <<= 1; // out of bound pixel
  41194. } else {
  41195. contextLabel = (contextLabel << 1) | referenceBitmap[i0][j0];
  41196. }
  41197. }
  41198. var pixel = decoder.readBit(contexts, contextLabel);
  41199. row[j] = pixel;
  41200. }
  41201. }
  41202. return bitmap;
  41203. }
  41204. // 6.5.5 Decoding the symbol dictionary
  41205. function decodeSymbolDictionary(huffman, refinement, symbols,
  41206. numberOfNewSymbols, numberOfExportedSymbols,
  41207. huffmanTables, templateIndex, at,
  41208. refinementTemplateIndex, refinementAt,
  41209. decodingContext) {
  41210. if (huffman) {
  41211. error('JBIG2 error: huffman is not supported');
  41212. }
  41213. var newSymbols = [];
  41214. var currentHeight = 0;
  41215. var symbolCodeLength = log2(symbols.length + numberOfNewSymbols);
  41216. var decoder = decodingContext.decoder;
  41217. var contextCache = decodingContext.contextCache;
  41218. while (newSymbols.length < numberOfNewSymbols) {
  41219. var deltaHeight = decodeInteger(contextCache, 'IADH', decoder); // 6.5.6
  41220. currentHeight += deltaHeight;
  41221. var currentWidth = 0;
  41222. var totalWidth = 0;
  41223. while (true) {
  41224. var deltaWidth = decodeInteger(contextCache, 'IADW', decoder); // 6.5.7
  41225. if (deltaWidth === null) {
  41226. break; // OOB
  41227. }
  41228. currentWidth += deltaWidth;
  41229. totalWidth += currentWidth;
  41230. var bitmap;
  41231. if (refinement) {
  41232. // 6.5.8.2 Refinement/aggregate-coded symbol bitmap
  41233. var numberOfInstances = decodeInteger(contextCache, 'IAAI', decoder);
  41234. if (numberOfInstances > 1) {
  41235. bitmap = decodeTextRegion(huffman, refinement,
  41236. currentWidth, currentHeight, 0,
  41237. numberOfInstances, 1, //strip size
  41238. symbols.concat(newSymbols),
  41239. symbolCodeLength,
  41240. 0, //transposed
  41241. 0, //ds offset
  41242. 1, //top left 7.4.3.1.1
  41243. 0, //OR operator
  41244. huffmanTables,
  41245. refinementTemplateIndex, refinementAt,
  41246. decodingContext);
  41247. } else {
  41248. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  41249. var rdx = decodeInteger(contextCache, 'IARDX', decoder); // 6.4.11.3
  41250. var rdy = decodeInteger(contextCache, 'IARDY', decoder); // 6.4.11.4
  41251. var symbol = (symbolId < symbols.length ? symbols[symbolId] :
  41252. newSymbols[symbolId - symbols.length]);
  41253. bitmap = decodeRefinement(currentWidth, currentHeight,
  41254. refinementTemplateIndex, symbol, rdx, rdy, false, refinementAt,
  41255. decodingContext);
  41256. }
  41257. } else {
  41258. // 6.5.8.1 Direct-coded symbol bitmap
  41259. bitmap = decodeBitmap(false, currentWidth, currentHeight,
  41260. templateIndex, false, null, at, decodingContext);
  41261. }
  41262. newSymbols.push(bitmap);
  41263. }
  41264. }
  41265. // 6.5.10 Exported symbols
  41266. var exportedSymbols = [];
  41267. var flags = [], currentFlag = false;
  41268. var totalSymbolsLength = symbols.length + numberOfNewSymbols;
  41269. while (flags.length < totalSymbolsLength) {
  41270. var runLength = decodeInteger(contextCache, 'IAEX', decoder);
  41271. while (runLength--) {
  41272. flags.push(currentFlag);
  41273. }
  41274. currentFlag = !currentFlag;
  41275. }
  41276. for (var i = 0, ii = symbols.length; i < ii; i++) {
  41277. if (flags[i]) {
  41278. exportedSymbols.push(symbols[i]);
  41279. }
  41280. }
  41281. for (var j = 0; j < numberOfNewSymbols; i++, j++) {
  41282. if (flags[i]) {
  41283. exportedSymbols.push(newSymbols[j]);
  41284. }
  41285. }
  41286. return exportedSymbols;
  41287. }
  41288. function decodeTextRegion(huffman, refinement, width, height,
  41289. defaultPixelValue, numberOfSymbolInstances,
  41290. stripSize, inputSymbols, symbolCodeLength,
  41291. transposed, dsOffset, referenceCorner,
  41292. combinationOperator, huffmanTables,
  41293. refinementTemplateIndex, refinementAt,
  41294. decodingContext) {
  41295. if (huffman) {
  41296. error('JBIG2 error: huffman is not supported');
  41297. }
  41298. // Prepare bitmap
  41299. var bitmap = [];
  41300. var i, row;
  41301. for (i = 0; i < height; i++) {
  41302. row = new Uint8Array(width);
  41303. if (defaultPixelValue) {
  41304. for (var j = 0; j < width; j++) {
  41305. row[j] = defaultPixelValue;
  41306. }
  41307. }
  41308. bitmap.push(row);
  41309. }
  41310. var decoder = decodingContext.decoder;
  41311. var contextCache = decodingContext.contextCache;
  41312. var stripT = -decodeInteger(contextCache, 'IADT', decoder); // 6.4.6
  41313. var firstS = 0;
  41314. i = 0;
  41315. while (i < numberOfSymbolInstances) {
  41316. var deltaT = decodeInteger(contextCache, 'IADT', decoder); // 6.4.6
  41317. stripT += deltaT;
  41318. var deltaFirstS = decodeInteger(contextCache, 'IAFS', decoder); // 6.4.7
  41319. firstS += deltaFirstS;
  41320. var currentS = firstS;
  41321. do {
  41322. var currentT = (stripSize === 1 ? 0 :
  41323. decodeInteger(contextCache, 'IAIT', decoder)); // 6.4.9
  41324. var t = stripSize * stripT + currentT;
  41325. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  41326. var applyRefinement = (refinement &&
  41327. decodeInteger(contextCache, 'IARI', decoder));
  41328. var symbolBitmap = inputSymbols[symbolId];
  41329. var symbolWidth = symbolBitmap[0].length;
  41330. var symbolHeight = symbolBitmap.length;
  41331. if (applyRefinement) {
  41332. var rdw = decodeInteger(contextCache, 'IARDW', decoder); // 6.4.11.1
  41333. var rdh = decodeInteger(contextCache, 'IARDH', decoder); // 6.4.11.2
  41334. var rdx = decodeInteger(contextCache, 'IARDX', decoder); // 6.4.11.3
  41335. var rdy = decodeInteger(contextCache, 'IARDY', decoder); // 6.4.11.4
  41336. symbolWidth += rdw;
  41337. symbolHeight += rdh;
  41338. symbolBitmap = decodeRefinement(symbolWidth, symbolHeight,
  41339. refinementTemplateIndex, symbolBitmap, (rdw >> 1) + rdx,
  41340. (rdh >> 1) + rdy, false, refinementAt,
  41341. decodingContext);
  41342. }
  41343. var offsetT = t - ((referenceCorner & 1) ? 0 : symbolHeight);
  41344. var offsetS = currentS - ((referenceCorner & 2) ? symbolWidth : 0);
  41345. var s2, t2, symbolRow;
  41346. if (transposed) {
  41347. // Place Symbol Bitmap from T1,S1
  41348. for (s2 = 0; s2 < symbolHeight; s2++) {
  41349. row = bitmap[offsetS + s2];
  41350. if (!row) {
  41351. continue;
  41352. }
  41353. symbolRow = symbolBitmap[s2];
  41354. // To ignore Parts of Symbol bitmap which goes
  41355. // outside bitmap region
  41356. var maxWidth = Math.min(width - offsetT, symbolWidth);
  41357. switch (combinationOperator) {
  41358. case 0: // OR
  41359. for (t2 = 0; t2 < maxWidth; t2++) {
  41360. row[offsetT + t2] |= symbolRow[t2];
  41361. }
  41362. break;
  41363. case 2: // XOR
  41364. for (t2 = 0; t2 < maxWidth; t2++) {
  41365. row[offsetT + t2] ^= symbolRow[t2];
  41366. }
  41367. break;
  41368. default:
  41369. error('JBIG2 error: operator ' + combinationOperator +
  41370. ' is not supported');
  41371. }
  41372. }
  41373. currentS += symbolHeight - 1;
  41374. } else {
  41375. for (t2 = 0; t2 < symbolHeight; t2++) {
  41376. row = bitmap[offsetT + t2];
  41377. if (!row) {
  41378. continue;
  41379. }
  41380. symbolRow = symbolBitmap[t2];
  41381. switch (combinationOperator) {
  41382. case 0: // OR
  41383. for (s2 = 0; s2 < symbolWidth; s2++) {
  41384. row[offsetS + s2] |= symbolRow[s2];
  41385. }
  41386. break;
  41387. case 2: // XOR
  41388. for (s2 = 0; s2 < symbolWidth; s2++) {
  41389. row[offsetS + s2] ^= symbolRow[s2];
  41390. }
  41391. break;
  41392. default:
  41393. error('JBIG2 error: operator ' + combinationOperator +
  41394. ' is not supported');
  41395. }
  41396. }
  41397. currentS += symbolWidth - 1;
  41398. }
  41399. i++;
  41400. var deltaS = decodeInteger(contextCache, 'IADS', decoder); // 6.4.8
  41401. if (deltaS === null) {
  41402. break; // OOB
  41403. }
  41404. currentS += deltaS + dsOffset;
  41405. } while (true);
  41406. }
  41407. return bitmap;
  41408. }
  41409. function readSegmentHeader(data, start) {
  41410. var segmentHeader = {};
  41411. segmentHeader.number = readUint32(data, start);
  41412. var flags = data[start + 4];
  41413. var segmentType = flags & 0x3F;
  41414. if (!SegmentTypes[segmentType]) {
  41415. error('JBIG2 error: invalid segment type: ' + segmentType);
  41416. }
  41417. segmentHeader.type = segmentType;
  41418. segmentHeader.typeName = SegmentTypes[segmentType];
  41419. segmentHeader.deferredNonRetain = !!(flags & 0x80);
  41420. var pageAssociationFieldSize = !!(flags & 0x40);
  41421. var referredFlags = data[start + 5];
  41422. var referredToCount = (referredFlags >> 5) & 7;
  41423. var retainBits = [referredFlags & 31];
  41424. var position = start + 6;
  41425. if (referredFlags === 7) {
  41426. referredToCount = readUint32(data, position - 1) & 0x1FFFFFFF;
  41427. position += 3;
  41428. var bytes = (referredToCount + 7) >> 3;
  41429. retainBits[0] = data[position++];
  41430. while (--bytes > 0) {
  41431. retainBits.push(data[position++]);
  41432. }
  41433. } else if (referredFlags === 5 || referredFlags === 6) {
  41434. error('JBIG2 error: invalid referred-to flags');
  41435. }
  41436. segmentHeader.retainBits = retainBits;
  41437. var referredToSegmentNumberSize = (segmentHeader.number <= 256 ? 1 :
  41438. (segmentHeader.number <= 65536 ? 2 : 4));
  41439. var referredTo = [];
  41440. var i, ii;
  41441. for (i = 0; i < referredToCount; i++) {
  41442. var number = (referredToSegmentNumberSize === 1 ? data[position] :
  41443. (referredToSegmentNumberSize === 2 ? readUint16(data, position) :
  41444. readUint32(data, position)));
  41445. referredTo.push(number);
  41446. position += referredToSegmentNumberSize;
  41447. }
  41448. segmentHeader.referredTo = referredTo;
  41449. if (!pageAssociationFieldSize) {
  41450. segmentHeader.pageAssociation = data[position++];
  41451. } else {
  41452. segmentHeader.pageAssociation = readUint32(data, position);
  41453. position += 4;
  41454. }
  41455. segmentHeader.length = readUint32(data, position);
  41456. position += 4;
  41457. if (segmentHeader.length === 0xFFFFFFFF) {
  41458. // 7.2.7 Segment data length, unknown segment length
  41459. if (segmentType === 38) { // ImmediateGenericRegion
  41460. var genericRegionInfo = readRegionSegmentInformation(data, position);
  41461. var genericRegionSegmentFlags = data[position +
  41462. RegionSegmentInformationFieldLength];
  41463. var genericRegionMmr = !!(genericRegionSegmentFlags & 1);
  41464. // searching for the segment end
  41465. var searchPatternLength = 6;
  41466. var searchPattern = new Uint8Array(searchPatternLength);
  41467. if (!genericRegionMmr) {
  41468. searchPattern[0] = 0xFF;
  41469. searchPattern[1] = 0xAC;
  41470. }
  41471. searchPattern[2] = (genericRegionInfo.height >>> 24) & 0xFF;
  41472. searchPattern[3] = (genericRegionInfo.height >> 16) & 0xFF;
  41473. searchPattern[4] = (genericRegionInfo.height >> 8) & 0xFF;
  41474. searchPattern[5] = genericRegionInfo.height & 0xFF;
  41475. for (i = position, ii = data.length; i < ii; i++) {
  41476. var j = 0;
  41477. while (j < searchPatternLength && searchPattern[j] === data[i + j]) {
  41478. j++;
  41479. }
  41480. if (j === searchPatternLength) {
  41481. segmentHeader.length = i + searchPatternLength;
  41482. break;
  41483. }
  41484. }
  41485. if (segmentHeader.length === 0xFFFFFFFF) {
  41486. error('JBIG2 error: segment end was not found');
  41487. }
  41488. } else {
  41489. error('JBIG2 error: invalid unknown segment length');
  41490. }
  41491. }
  41492. segmentHeader.headerEnd = position;
  41493. return segmentHeader;
  41494. }
  41495. function readSegments(header, data, start, end) {
  41496. var segments = [];
  41497. var position = start;
  41498. while (position < end) {
  41499. var segmentHeader = readSegmentHeader(data, position);
  41500. position = segmentHeader.headerEnd;
  41501. var segment = {
  41502. header: segmentHeader,
  41503. data: data
  41504. };
  41505. if (!header.randomAccess) {
  41506. segment.start = position;
  41507. position += segmentHeader.length;
  41508. segment.end = position;
  41509. }
  41510. segments.push(segment);
  41511. if (segmentHeader.type === 51) {
  41512. break; // end of file is found
  41513. }
  41514. }
  41515. if (header.randomAccess) {
  41516. for (var i = 0, ii = segments.length; i < ii; i++) {
  41517. segments[i].start = position;
  41518. position += segments[i].header.length;
  41519. segments[i].end = position;
  41520. }
  41521. }
  41522. return segments;
  41523. }
  41524. // 7.4.1 Region segment information field
  41525. function readRegionSegmentInformation(data, start) {
  41526. return {
  41527. width: readUint32(data, start),
  41528. height: readUint32(data, start + 4),
  41529. x: readUint32(data, start + 8),
  41530. y: readUint32(data, start + 12),
  41531. combinationOperator: data[start + 16] & 7
  41532. };
  41533. }
  41534. var RegionSegmentInformationFieldLength = 17;
  41535. function processSegment(segment, visitor) {
  41536. var header = segment.header;
  41537. var data = segment.data, position = segment.start, end = segment.end;
  41538. var args, at, i, atLength;
  41539. switch (header.type) {
  41540. case 0: // SymbolDictionary
  41541. // 7.4.2 Symbol dictionary segment syntax
  41542. var dictionary = {};
  41543. var dictionaryFlags = readUint16(data, position); // 7.4.2.1.1
  41544. dictionary.huffman = !!(dictionaryFlags & 1);
  41545. dictionary.refinement = !!(dictionaryFlags & 2);
  41546. dictionary.huffmanDHSelector = (dictionaryFlags >> 2) & 3;
  41547. dictionary.huffmanDWSelector = (dictionaryFlags >> 4) & 3;
  41548. dictionary.bitmapSizeSelector = (dictionaryFlags >> 6) & 1;
  41549. dictionary.aggregationInstancesSelector = (dictionaryFlags >> 7) & 1;
  41550. dictionary.bitmapCodingContextUsed = !!(dictionaryFlags & 256);
  41551. dictionary.bitmapCodingContextRetained = !!(dictionaryFlags & 512);
  41552. dictionary.template = (dictionaryFlags >> 10) & 3;
  41553. dictionary.refinementTemplate = (dictionaryFlags >> 12) & 1;
  41554. position += 2;
  41555. if (!dictionary.huffman) {
  41556. atLength = dictionary.template === 0 ? 4 : 1;
  41557. at = [];
  41558. for (i = 0; i < atLength; i++) {
  41559. at.push({
  41560. x: readInt8(data, position),
  41561. y: readInt8(data, position + 1)
  41562. });
  41563. position += 2;
  41564. }
  41565. dictionary.at = at;
  41566. }
  41567. if (dictionary.refinement && !dictionary.refinementTemplate) {
  41568. at = [];
  41569. for (i = 0; i < 2; i++) {
  41570. at.push({
  41571. x: readInt8(data, position),
  41572. y: readInt8(data, position + 1)
  41573. });
  41574. position += 2;
  41575. }
  41576. dictionary.refinementAt = at;
  41577. }
  41578. dictionary.numberOfExportedSymbols = readUint32(data, position);
  41579. position += 4;
  41580. dictionary.numberOfNewSymbols = readUint32(data, position);
  41581. position += 4;
  41582. args = [dictionary, header.number, header.referredTo,
  41583. data, position, end];
  41584. break;
  41585. case 6: // ImmediateTextRegion
  41586. case 7: // ImmediateLosslessTextRegion
  41587. var textRegion = {};
  41588. textRegion.info = readRegionSegmentInformation(data, position);
  41589. position += RegionSegmentInformationFieldLength;
  41590. var textRegionSegmentFlags = readUint16(data, position);
  41591. position += 2;
  41592. textRegion.huffman = !!(textRegionSegmentFlags & 1);
  41593. textRegion.refinement = !!(textRegionSegmentFlags & 2);
  41594. textRegion.stripSize = 1 << ((textRegionSegmentFlags >> 2) & 3);
  41595. textRegion.referenceCorner = (textRegionSegmentFlags >> 4) & 3;
  41596. textRegion.transposed = !!(textRegionSegmentFlags & 64);
  41597. textRegion.combinationOperator = (textRegionSegmentFlags >> 7) & 3;
  41598. textRegion.defaultPixelValue = (textRegionSegmentFlags >> 9) & 1;
  41599. textRegion.dsOffset = (textRegionSegmentFlags << 17) >> 27;
  41600. textRegion.refinementTemplate = (textRegionSegmentFlags >> 15) & 1;
  41601. if (textRegion.huffman) {
  41602. var textRegionHuffmanFlags = readUint16(data, position);
  41603. position += 2;
  41604. textRegion.huffmanFS = (textRegionHuffmanFlags) & 3;
  41605. textRegion.huffmanDS = (textRegionHuffmanFlags >> 2) & 3;
  41606. textRegion.huffmanDT = (textRegionHuffmanFlags >> 4) & 3;
  41607. textRegion.huffmanRefinementDW = (textRegionHuffmanFlags >> 6) & 3;
  41608. textRegion.huffmanRefinementDH = (textRegionHuffmanFlags >> 8) & 3;
  41609. textRegion.huffmanRefinementDX = (textRegionHuffmanFlags >> 10) & 3;
  41610. textRegion.huffmanRefinementDY = (textRegionHuffmanFlags >> 12) & 3;
  41611. textRegion.huffmanRefinementSizeSelector =
  41612. !!(textRegionHuffmanFlags & 14);
  41613. }
  41614. if (textRegion.refinement && !textRegion.refinementTemplate) {
  41615. at = [];
  41616. for (i = 0; i < 2; i++) {
  41617. at.push({
  41618. x: readInt8(data, position),
  41619. y: readInt8(data, position + 1)
  41620. });
  41621. position += 2;
  41622. }
  41623. textRegion.refinementAt = at;
  41624. }
  41625. textRegion.numberOfSymbolInstances = readUint32(data, position);
  41626. position += 4;
  41627. // TODO 7.4.3.1.7 Symbol ID Huffman table decoding
  41628. if (textRegion.huffman) {
  41629. error('JBIG2 error: huffman is not supported');
  41630. }
  41631. args = [textRegion, header.referredTo, data, position, end];
  41632. break;
  41633. case 38: // ImmediateGenericRegion
  41634. case 39: // ImmediateLosslessGenericRegion
  41635. var genericRegion = {};
  41636. genericRegion.info = readRegionSegmentInformation(data, position);
  41637. position += RegionSegmentInformationFieldLength;
  41638. var genericRegionSegmentFlags = data[position++];
  41639. genericRegion.mmr = !!(genericRegionSegmentFlags & 1);
  41640. genericRegion.template = (genericRegionSegmentFlags >> 1) & 3;
  41641. genericRegion.prediction = !!(genericRegionSegmentFlags & 8);
  41642. if (!genericRegion.mmr) {
  41643. atLength = genericRegion.template === 0 ? 4 : 1;
  41644. at = [];
  41645. for (i = 0; i < atLength; i++) {
  41646. at.push({
  41647. x: readInt8(data, position),
  41648. y: readInt8(data, position + 1)
  41649. });
  41650. position += 2;
  41651. }
  41652. genericRegion.at = at;
  41653. }
  41654. args = [genericRegion, data, position, end];
  41655. break;
  41656. case 48: // PageInformation
  41657. var pageInfo = {
  41658. width: readUint32(data, position),
  41659. height: readUint32(data, position + 4),
  41660. resolutionX: readUint32(data, position + 8),
  41661. resolutionY: readUint32(data, position + 12)
  41662. };
  41663. if (pageInfo.height === 0xFFFFFFFF) {
  41664. delete pageInfo.height;
  41665. }
  41666. var pageSegmentFlags = data[position + 16];
  41667. var pageStripingInformatiom = readUint16(data, position + 17);
  41668. pageInfo.lossless = !!(pageSegmentFlags & 1);
  41669. pageInfo.refinement = !!(pageSegmentFlags & 2);
  41670. pageInfo.defaultPixelValue = (pageSegmentFlags >> 2) & 1;
  41671. pageInfo.combinationOperator = (pageSegmentFlags >> 3) & 3;
  41672. pageInfo.requiresBuffer = !!(pageSegmentFlags & 32);
  41673. pageInfo.combinationOperatorOverride = !!(pageSegmentFlags & 64);
  41674. args = [pageInfo];
  41675. break;
  41676. case 49: // EndOfPage
  41677. break;
  41678. case 50: // EndOfStripe
  41679. break;
  41680. case 51: // EndOfFile
  41681. break;
  41682. case 62: // 7.4.15 defines 2 extension types which
  41683. // are comments and can be ignored.
  41684. break;
  41685. default:
  41686. error('JBIG2 error: segment type ' + header.typeName + '(' +
  41687. header.type + ') is not implemented');
  41688. }
  41689. var callbackName = 'on' + header.typeName;
  41690. if (callbackName in visitor) {
  41691. visitor[callbackName].apply(visitor, args);
  41692. }
  41693. }
  41694. function processSegments(segments, visitor) {
  41695. for (var i = 0, ii = segments.length; i < ii; i++) {
  41696. processSegment(segments[i], visitor);
  41697. }
  41698. }
  41699. function parseJbig2(data, start, end) {
  41700. var position = start;
  41701. if (data[position] !== 0x97 || data[position + 1] !== 0x4A ||
  41702. data[position + 2] !== 0x42 || data[position + 3] !== 0x32 ||
  41703. data[position + 4] !== 0x0D || data[position + 5] !== 0x0A ||
  41704. data[position + 6] !== 0x1A || data[position + 7] !== 0x0A) {
  41705. error('JBIG2 error: invalid header');
  41706. }
  41707. var header = {};
  41708. position += 8;
  41709. var flags = data[position++];
  41710. header.randomAccess = !(flags & 1);
  41711. if (!(flags & 2)) {
  41712. header.numberOfPages = readUint32(data, position);
  41713. position += 4;
  41714. }
  41715. var segments = readSegments(header, data, position, end);
  41716. error('Not implemented');
  41717. // processSegments(segments, new SimpleSegmentVisitor());
  41718. }
  41719. function parseJbig2Chunks(chunks) {
  41720. var visitor = new SimpleSegmentVisitor();
  41721. for (var i = 0, ii = chunks.length; i < ii; i++) {
  41722. var chunk = chunks[i];
  41723. var segments = readSegments({}, chunk.data, chunk.start, chunk.end);
  41724. processSegments(segments, visitor);
  41725. }
  41726. return visitor.buffer;
  41727. }
  41728. function SimpleSegmentVisitor() {}
  41729. SimpleSegmentVisitor.prototype = {
  41730. onPageInformation: function SimpleSegmentVisitor_onPageInformation(info) {
  41731. this.currentPageInfo = info;
  41732. var rowSize = (info.width + 7) >> 3;
  41733. var buffer = new Uint8Array(rowSize * info.height);
  41734. // The contents of ArrayBuffers are initialized to 0.
  41735. // Fill the buffer with 0xFF only if info.defaultPixelValue is set
  41736. if (info.defaultPixelValue) {
  41737. for (var i = 0, ii = buffer.length; i < ii; i++) {
  41738. buffer[i] = 0xFF;
  41739. }
  41740. }
  41741. this.buffer = buffer;
  41742. },
  41743. drawBitmap: function SimpleSegmentVisitor_drawBitmap(regionInfo, bitmap) {
  41744. var pageInfo = this.currentPageInfo;
  41745. var width = regionInfo.width, height = regionInfo.height;
  41746. var rowSize = (pageInfo.width + 7) >> 3;
  41747. var combinationOperator = pageInfo.combinationOperatorOverride ?
  41748. regionInfo.combinationOperator : pageInfo.combinationOperator;
  41749. var buffer = this.buffer;
  41750. var mask0 = 128 >> (regionInfo.x & 7);
  41751. var offset0 = regionInfo.y * rowSize + (regionInfo.x >> 3);
  41752. var i, j, mask, offset;
  41753. switch (combinationOperator) {
  41754. case 0: // OR
  41755. for (i = 0; i < height; i++) {
  41756. mask = mask0;
  41757. offset = offset0;
  41758. for (j = 0; j < width; j++) {
  41759. if (bitmap[i][j]) {
  41760. buffer[offset] |= mask;
  41761. }
  41762. mask >>= 1;
  41763. if (!mask) {
  41764. mask = 128;
  41765. offset++;
  41766. }
  41767. }
  41768. offset0 += rowSize;
  41769. }
  41770. break;
  41771. case 2: // XOR
  41772. for (i = 0; i < height; i++) {
  41773. mask = mask0;
  41774. offset = offset0;
  41775. for (j = 0; j < width; j++) {
  41776. if (bitmap[i][j]) {
  41777. buffer[offset] ^= mask;
  41778. }
  41779. mask >>= 1;
  41780. if (!mask) {
  41781. mask = 128;
  41782. offset++;
  41783. }
  41784. }
  41785. offset0 += rowSize;
  41786. }
  41787. break;
  41788. default:
  41789. error('JBIG2 error: operator ' + combinationOperator +
  41790. ' is not supported');
  41791. }
  41792. },
  41793. onImmediateGenericRegion:
  41794. function SimpleSegmentVisitor_onImmediateGenericRegion(region, data,
  41795. start, end) {
  41796. var regionInfo = region.info;
  41797. var decodingContext = new DecodingContext(data, start, end);
  41798. var bitmap = decodeBitmap(region.mmr, regionInfo.width, regionInfo.height,
  41799. region.template, region.prediction, null,
  41800. region.at, decodingContext);
  41801. this.drawBitmap(regionInfo, bitmap);
  41802. },
  41803. onImmediateLosslessGenericRegion:
  41804. function SimpleSegmentVisitor_onImmediateLosslessGenericRegion() {
  41805. this.onImmediateGenericRegion.apply(this, arguments);
  41806. },
  41807. onSymbolDictionary:
  41808. function SimpleSegmentVisitor_onSymbolDictionary(dictionary,
  41809. currentSegment,
  41810. referredSegments,
  41811. data, start, end) {
  41812. var huffmanTables;
  41813. if (dictionary.huffman) {
  41814. error('JBIG2 error: huffman is not supported');
  41815. }
  41816. // Combines exported symbols from all referred segments
  41817. var symbols = this.symbols;
  41818. if (!symbols) {
  41819. this.symbols = symbols = {};
  41820. }
  41821. var inputSymbols = [];
  41822. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  41823. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  41824. }
  41825. var decodingContext = new DecodingContext(data, start, end);
  41826. symbols[currentSegment] = decodeSymbolDictionary(dictionary.huffman,
  41827. dictionary.refinement, inputSymbols, dictionary.numberOfNewSymbols,
  41828. dictionary.numberOfExportedSymbols, huffmanTables,
  41829. dictionary.template, dictionary.at,
  41830. dictionary.refinementTemplate, dictionary.refinementAt,
  41831. decodingContext);
  41832. },
  41833. onImmediateTextRegion:
  41834. function SimpleSegmentVisitor_onImmediateTextRegion(region,
  41835. referredSegments,
  41836. data, start, end) {
  41837. var regionInfo = region.info;
  41838. var huffmanTables;
  41839. // Combines exported symbols from all referred segments
  41840. var symbols = this.symbols;
  41841. var inputSymbols = [];
  41842. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  41843. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  41844. }
  41845. var symbolCodeLength = log2(inputSymbols.length);
  41846. var decodingContext = new DecodingContext(data, start, end);
  41847. var bitmap = decodeTextRegion(region.huffman, region.refinement,
  41848. regionInfo.width, regionInfo.height, region.defaultPixelValue,
  41849. region.numberOfSymbolInstances, region.stripSize, inputSymbols,
  41850. symbolCodeLength, region.transposed, region.dsOffset,
  41851. region.referenceCorner, region.combinationOperator, huffmanTables,
  41852. region.refinementTemplate, region.refinementAt, decodingContext);
  41853. this.drawBitmap(regionInfo, bitmap);
  41854. },
  41855. onImmediateLosslessTextRegion:
  41856. function SimpleSegmentVisitor_onImmediateLosslessTextRegion() {
  41857. this.onImmediateTextRegion.apply(this, arguments);
  41858. }
  41859. };
  41860. function Jbig2Image() {}
  41861. Jbig2Image.prototype = {
  41862. parseChunks: function Jbig2Image_parseChunks(chunks) {
  41863. return parseJbig2Chunks(chunks);
  41864. }
  41865. };
  41866. return Jbig2Image;
  41867. })();
  41868. var bidi = PDFJS.bidi = (function bidiClosure() {
  41869. // Character types for symbols from 0000 to 00FF.
  41870. var baseTypes = [
  41871. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'S', 'B', 'S', 'WS',
  41872. 'B', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  41873. 'BN', 'BN', 'B', 'B', 'B', 'S', 'WS', 'ON', 'ON', 'ET', 'ET', 'ET', 'ON',
  41874. 'ON', 'ON', 'ON', 'ON', 'ON', 'CS', 'ON', 'CS', 'ON', 'EN', 'EN', 'EN',
  41875. 'EN', 'EN', 'EN', 'EN', 'EN', 'EN', 'EN', 'ON', 'ON', 'ON', 'ON', 'ON',
  41876. 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  41877. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'ON', 'ON',
  41878. 'ON', 'ON', 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  41879. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  41880. 'L', 'ON', 'ON', 'ON', 'ON', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'B', 'BN',
  41881. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  41882. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  41883. 'BN', 'CS', 'ON', 'ET', 'ET', 'ET', 'ET', 'ON', 'ON', 'ON', 'ON', 'L', 'ON',
  41884. 'ON', 'ON', 'ON', 'ON', 'ET', 'ET', 'EN', 'EN', 'ON', 'L', 'ON', 'ON', 'ON',
  41885. 'EN', 'L', 'ON', 'ON', 'ON', 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  41886. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  41887. 'L', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  41888. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  41889. 'L', 'L', 'L', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L'
  41890. ];
  41891. // Character types for symbols from 0600 to 06FF
  41892. var arabicTypes = [
  41893. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  41894. 'CS', 'AL', 'ON', 'ON', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'AL',
  41895. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  41896. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  41897. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  41898. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  41899. 'AL', 'AL', 'AL', 'AL', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM',
  41900. 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'AL', 'AL', 'AL', 'AL',
  41901. 'AL', 'AL', 'AL', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN',
  41902. 'AN', 'ET', 'AN', 'AN', 'AL', 'AL', 'AL', 'NSM', 'AL', 'AL', 'AL', 'AL',
  41903. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  41904. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  41905. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  41906. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  41907. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  41908. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  41909. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  41910. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  41911. 'AL', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM',
  41912. 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'ON', 'NSM',
  41913. 'NSM', 'NSM', 'NSM', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  41914. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL'
  41915. ];
  41916. function isOdd(i) {
  41917. return (i & 1) !== 0;
  41918. }
  41919. function isEven(i) {
  41920. return (i & 1) === 0;
  41921. }
  41922. function findUnequal(arr, start, value) {
  41923. for (var j = start, jj = arr.length; j < jj; ++j) {
  41924. if (arr[j] !== value) {
  41925. return j;
  41926. }
  41927. }
  41928. return j;
  41929. }
  41930. function setValues(arr, start, end, value) {
  41931. for (var j = start; j < end; ++j) {
  41932. arr[j] = value;
  41933. }
  41934. }
  41935. function reverseValues(arr, start, end) {
  41936. for (var i = start, j = end - 1; i < j; ++i, --j) {
  41937. var temp = arr[i];
  41938. arr[i] = arr[j];
  41939. arr[j] = temp;
  41940. }
  41941. }
  41942. function createBidiText(str, isLTR, vertical) {
  41943. return {
  41944. str: str,
  41945. dir: (vertical ? 'ttb' : (isLTR ? 'ltr' : 'rtl'))
  41946. };
  41947. }
  41948. // These are used in bidi(), which is called frequently. We re-use them on
  41949. // each call to avoid unnecessary allocations.
  41950. var chars = [];
  41951. var types = [];
  41952. function bidi(str, startLevel, vertical) {
  41953. var isLTR = true;
  41954. var strLength = str.length;
  41955. if (strLength === 0 || vertical) {
  41956. return createBidiText(str, isLTR, vertical);
  41957. }
  41958. // Get types and fill arrays
  41959. chars.length = strLength;
  41960. types.length = strLength;
  41961. var numBidi = 0;
  41962. var i, ii;
  41963. for (i = 0; i < strLength; ++i) {
  41964. chars[i] = str.charAt(i);
  41965. var charCode = str.charCodeAt(i);
  41966. var charType = 'L';
  41967. if (charCode <= 0x00ff) {
  41968. charType = baseTypes[charCode];
  41969. } else if (0x0590 <= charCode && charCode <= 0x05f4) {
  41970. charType = 'R';
  41971. } else if (0x0600 <= charCode && charCode <= 0x06ff) {
  41972. charType = arabicTypes[charCode & 0xff];
  41973. } else if (0x0700 <= charCode && charCode <= 0x08AC) {
  41974. charType = 'AL';
  41975. }
  41976. if (charType === 'R' || charType === 'AL' || charType === 'AN') {
  41977. numBidi++;
  41978. }
  41979. types[i] = charType;
  41980. }
  41981. // Detect the bidi method
  41982. // - If there are no rtl characters then no bidi needed
  41983. // - If less than 30% chars are rtl then string is primarily ltr
  41984. // - If more than 30% chars are rtl then string is primarily rtl
  41985. if (numBidi === 0) {
  41986. isLTR = true;
  41987. return createBidiText(str, isLTR);
  41988. }
  41989. if (startLevel === -1) {
  41990. if ((strLength / numBidi) < 0.3) {
  41991. isLTR = true;
  41992. startLevel = 0;
  41993. } else {
  41994. isLTR = false;
  41995. startLevel = 1;
  41996. }
  41997. }
  41998. var levels = [];
  41999. for (i = 0; i < strLength; ++i) {
  42000. levels[i] = startLevel;
  42001. }
  42002. /*
  42003. X1-X10: skip most of this, since we are NOT doing the embeddings.
  42004. */
  42005. var e = (isOdd(startLevel) ? 'R' : 'L');
  42006. var sor = e;
  42007. var eor = sor;
  42008. /*
  42009. W1. Examine each non-spacing mark (NSM) in the level run, and change the
  42010. type of the NSM to the type of the previous character. If the NSM is at the
  42011. start of the level run, it will get the type of sor.
  42012. */
  42013. var lastType = sor;
  42014. for (i = 0; i < strLength; ++i) {
  42015. if (types[i] === 'NSM') {
  42016. types[i] = lastType;
  42017. } else {
  42018. lastType = types[i];
  42019. }
  42020. }
  42021. /*
  42022. W2. Search backwards from each instance of a European number until the
  42023. first strong type (R, L, AL, or sor) is found. If an AL is found, change
  42024. the type of the European number to Arabic number.
  42025. */
  42026. lastType = sor;
  42027. var t;
  42028. for (i = 0; i < strLength; ++i) {
  42029. t = types[i];
  42030. if (t === 'EN') {
  42031. types[i] = (lastType === 'AL') ? 'AN' : 'EN';
  42032. } else if (t === 'R' || t === 'L' || t === 'AL') {
  42033. lastType = t;
  42034. }
  42035. }
  42036. /*
  42037. W3. Change all ALs to R.
  42038. */
  42039. for (i = 0; i < strLength; ++i) {
  42040. t = types[i];
  42041. if (t === 'AL') {
  42042. types[i] = 'R';
  42043. }
  42044. }
  42045. /*
  42046. W4. A single European separator between two European numbers changes to a
  42047. European number. A single common separator between two numbers of the same
  42048. type changes to that type:
  42049. */
  42050. for (i = 1; i < strLength - 1; ++i) {
  42051. if (types[i] === 'ES' && types[i - 1] === 'EN' && types[i + 1] === 'EN') {
  42052. types[i] = 'EN';
  42053. }
  42054. if (types[i] === 'CS' &&
  42055. (types[i - 1] === 'EN' || types[i - 1] === 'AN') &&
  42056. types[i + 1] === types[i - 1]) {
  42057. types[i] = types[i - 1];
  42058. }
  42059. }
  42060. /*
  42061. W5. A sequence of European terminators adjacent to European numbers changes
  42062. to all European numbers:
  42063. */
  42064. for (i = 0; i < strLength; ++i) {
  42065. if (types[i] === 'EN') {
  42066. // do before
  42067. var j;
  42068. for (j = i - 1; j >= 0; --j) {
  42069. if (types[j] !== 'ET') {
  42070. break;
  42071. }
  42072. types[j] = 'EN';
  42073. }
  42074. // do after
  42075. for (j = i + 1; j < strLength; --j) {
  42076. if (types[j] !== 'ET') {
  42077. break;
  42078. }
  42079. types[j] = 'EN';
  42080. }
  42081. }
  42082. }
  42083. /*
  42084. W6. Otherwise, separators and terminators change to Other Neutral:
  42085. */
  42086. for (i = 0; i < strLength; ++i) {
  42087. t = types[i];
  42088. if (t === 'WS' || t === 'ES' || t === 'ET' || t === 'CS') {
  42089. types[i] = 'ON';
  42090. }
  42091. }
  42092. /*
  42093. W7. Search backwards from each instance of a European number until the
  42094. first strong type (R, L, or sor) is found. If an L is found, then change
  42095. the type of the European number to L.
  42096. */
  42097. lastType = sor;
  42098. for (i = 0; i < strLength; ++i) {
  42099. t = types[i];
  42100. if (t === 'EN') {
  42101. types[i] = ((lastType === 'L') ? 'L' : 'EN');
  42102. } else if (t === 'R' || t === 'L') {
  42103. lastType = t;
  42104. }
  42105. }
  42106. /*
  42107. N1. A sequence of neutrals takes the direction of the surrounding strong
  42108. text if the text on both sides has the same direction. European and Arabic
  42109. numbers are treated as though they were R. Start-of-level-run (sor) and
  42110. end-of-level-run (eor) are used at level run boundaries.
  42111. */
  42112. for (i = 0; i < strLength; ++i) {
  42113. if (types[i] === 'ON') {
  42114. var end = findUnequal(types, i + 1, 'ON');
  42115. var before = sor;
  42116. if (i > 0) {
  42117. before = types[i - 1];
  42118. }
  42119. var after = eor;
  42120. if (end + 1 < strLength) {
  42121. after = types[end + 1];
  42122. }
  42123. if (before !== 'L') {
  42124. before = 'R';
  42125. }
  42126. if (after !== 'L') {
  42127. after = 'R';
  42128. }
  42129. if (before === after) {
  42130. setValues(types, i, end, before);
  42131. }
  42132. i = end - 1; // reset to end (-1 so next iteration is ok)
  42133. }
  42134. }
  42135. /*
  42136. N2. Any remaining neutrals take the embedding direction.
  42137. */
  42138. for (i = 0; i < strLength; ++i) {
  42139. if (types[i] === 'ON') {
  42140. types[i] = e;
  42141. }
  42142. }
  42143. /*
  42144. I1. For all characters with an even (left-to-right) embedding direction,
  42145. those of type R go up one level and those of type AN or EN go up two
  42146. levels.
  42147. I2. For all characters with an odd (right-to-left) embedding direction,
  42148. those of type L, EN or AN go up one level.
  42149. */
  42150. for (i = 0; i < strLength; ++i) {
  42151. t = types[i];
  42152. if (isEven(levels[i])) {
  42153. if (t === 'R') {
  42154. levels[i] += 1;
  42155. } else if (t === 'AN' || t === 'EN') {
  42156. levels[i] += 2;
  42157. }
  42158. } else { // isOdd
  42159. if (t === 'L' || t === 'AN' || t === 'EN') {
  42160. levels[i] += 1;
  42161. }
  42162. }
  42163. }
  42164. /*
  42165. L1. On each line, reset the embedding level of the following characters to
  42166. the paragraph embedding level:
  42167. segment separators,
  42168. paragraph separators,
  42169. any sequence of whitespace characters preceding a segment separator or
  42170. paragraph separator, and any sequence of white space characters at the end
  42171. of the line.
  42172. */
  42173. // don't bother as text is only single line
  42174. /*
  42175. L2. From the highest level found in the text to the lowest odd level on
  42176. each line, reverse any contiguous sequence of characters that are at that
  42177. level or higher.
  42178. */
  42179. // find highest level & lowest odd level
  42180. var highestLevel = -1;
  42181. var lowestOddLevel = 99;
  42182. var level;
  42183. for (i = 0, ii = levels.length; i < ii; ++i) {
  42184. level = levels[i];
  42185. if (highestLevel < level) {
  42186. highestLevel = level;
  42187. }
  42188. if (lowestOddLevel > level && isOdd(level)) {
  42189. lowestOddLevel = level;
  42190. }
  42191. }
  42192. // now reverse between those limits
  42193. for (level = highestLevel; level >= lowestOddLevel; --level) {
  42194. // find segments to reverse
  42195. var start = -1;
  42196. for (i = 0, ii = levels.length; i < ii; ++i) {
  42197. if (levels[i] < level) {
  42198. if (start >= 0) {
  42199. reverseValues(chars, start, i);
  42200. start = -1;
  42201. }
  42202. } else if (start < 0) {
  42203. start = i;
  42204. }
  42205. }
  42206. if (start >= 0) {
  42207. reverseValues(chars, start, levels.length);
  42208. }
  42209. }
  42210. /*
  42211. L3. Combining marks applied to a right-to-left base character will at this
  42212. point precede their base character. If the rendering engine expects them to
  42213. follow the base characters in the final display process, then the ordering
  42214. of the marks and the base character must be reversed.
  42215. */
  42216. // don't bother for now
  42217. /*
  42218. L4. A character that possesses the mirrored property as specified by
  42219. Section 4.7, Mirrored, must be depicted by a mirrored glyph if the resolved
  42220. directionality of that character is R.
  42221. */
  42222. // don't mirror as characters are already mirrored in the pdf
  42223. // Finally, return string
  42224. var result = '';
  42225. for (i = 0, ii = chars.length; i < ii; ++i) {
  42226. var ch = chars[i];
  42227. if (ch !== '<' && ch !== '>') {
  42228. result += ch;
  42229. }
  42230. }
  42231. return createBidiText(result, isLTR);
  42232. }
  42233. return bidi;
  42234. })();
  42235. /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  42236. /* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
  42237. /* Copyright 2014 Opera Software ASA
  42238. *
  42239. * Licensed under the Apache License, Version 2.0 (the "License");
  42240. * you may not use this file except in compliance with the License.
  42241. * You may obtain a copy of the License at
  42242. *
  42243. * http://www.apache.org/licenses/LICENSE-2.0
  42244. *
  42245. * Unless required by applicable law or agreed to in writing, software
  42246. * distributed under the License is distributed on an "AS IS" BASIS,
  42247. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  42248. * See the License for the specific language governing permissions and
  42249. * limitations under the License.
  42250. *
  42251. *
  42252. * Based on https://code.google.com/p/smhasher/wiki/MurmurHash3.
  42253. * Hashes roughly 100 KB per millisecond on i7 3.4 GHz.
  42254. */
  42255. /* globals Uint32ArrayView */
  42256. 'use strict';
  42257. var MurmurHash3_64 = (function MurmurHash3_64Closure (seed) {
  42258. // Workaround for missing math precison in JS.
  42259. var MASK_HIGH = 0xffff0000;
  42260. var MASK_LOW = 0xffff;
  42261. function MurmurHash3_64 (seed) {
  42262. var SEED = 0xc3d2e1f0;
  42263. this.h1 = seed ? seed & 0xffffffff : SEED;
  42264. this.h2 = seed ? seed & 0xffffffff : SEED;
  42265. }
  42266. var alwaysUseUint32ArrayView = false;
  42267. // old webkits have issues with non-aligned arrays
  42268. try {
  42269. new Uint32Array(new Uint8Array(5).buffer, 0, 1);
  42270. } catch (e) {
  42271. alwaysUseUint32ArrayView = true;
  42272. }
  42273. MurmurHash3_64.prototype = {
  42274. update: function MurmurHash3_64_update(input) {
  42275. var useUint32ArrayView = alwaysUseUint32ArrayView;
  42276. var i;
  42277. if (typeof input === 'string') {
  42278. var data = new Uint8Array(input.length * 2);
  42279. var length = 0;
  42280. for (i = 0; i < input.length; i++) {
  42281. var code = input.charCodeAt(i);
  42282. if (code <= 0xff) {
  42283. data[length++] = code;
  42284. }
  42285. else {
  42286. data[length++] = code >>> 8;
  42287. data[length++] = code & 0xff;
  42288. }
  42289. }
  42290. } else if (input instanceof Uint8Array) {
  42291. data = input;
  42292. length = data.length;
  42293. } else if (typeof input === 'object' && ('length' in input)) {
  42294. // processing regular arrays as well, e.g. for IE9
  42295. data = input;
  42296. length = data.length;
  42297. useUint32ArrayView = true;
  42298. } else {
  42299. throw new Error('Wrong data format in MurmurHash3_64_update. ' +
  42300. 'Input must be a string or array.');
  42301. }
  42302. var blockCounts = length >> 2;
  42303. var tailLength = length - blockCounts * 4;
  42304. // we don't care about endianness here
  42305. var dataUint32 = useUint32ArrayView ?
  42306. new Uint32ArrayView(data, blockCounts) :
  42307. new Uint32Array(data.buffer, 0, blockCounts);
  42308. var k1 = 0;
  42309. var k2 = 0;
  42310. var h1 = this.h1;
  42311. var h2 = this.h2;
  42312. var C1 = 0xcc9e2d51;
  42313. var C2 = 0x1b873593;
  42314. var C1_LOW = C1 & MASK_LOW;
  42315. var C2_LOW = C2 & MASK_LOW;
  42316. for (i = 0; i < blockCounts; i++) {
  42317. if (i & 1) {
  42318. k1 = dataUint32[i];
  42319. k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);
  42320. k1 = k1 << 15 | k1 >>> 17;
  42321. k1 = (k1 * C2 & MASK_HIGH) | (k1 * C2_LOW & MASK_LOW);
  42322. h1 ^= k1;
  42323. h1 = h1 << 13 | h1 >>> 19;
  42324. h1 = h1 * 5 + 0xe6546b64;
  42325. } else {
  42326. k2 = dataUint32[i];
  42327. k2 = (k2 * C1 & MASK_HIGH) | (k2 * C1_LOW & MASK_LOW);
  42328. k2 = k2 << 15 | k2 >>> 17;
  42329. k2 = (k2 * C2 & MASK_HIGH) | (k2 * C2_LOW & MASK_LOW);
  42330. h2 ^= k2;
  42331. h2 = h2 << 13 | h2 >>> 19;
  42332. h2 = h2 * 5 + 0xe6546b64;
  42333. }
  42334. }
  42335. k1 = 0;
  42336. switch (tailLength) {
  42337. case 3:
  42338. k1 ^= data[blockCounts * 4 + 2] << 16;
  42339. /* falls through */
  42340. case 2:
  42341. k1 ^= data[blockCounts * 4 + 1] << 8;
  42342. /* falls through */
  42343. case 1:
  42344. k1 ^= data[blockCounts * 4];
  42345. /* falls through */
  42346. k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);
  42347. k1 = k1 << 15 | k1 >>> 17;
  42348. k1 = (k1 * C2 & MASK_HIGH) | (k1 * C2_LOW & MASK_LOW);
  42349. if (blockCounts & 1) {
  42350. h1 ^= k1;
  42351. } else {
  42352. h2 ^= k1;
  42353. }
  42354. }
  42355. this.h1 = h1;
  42356. this.h2 = h2;
  42357. return this;
  42358. },
  42359. hexdigest: function MurmurHash3_64_hexdigest () {
  42360. var h1 = this.h1;
  42361. var h2 = this.h2;
  42362. h1 ^= h2 >>> 1;
  42363. h1 = (h1 * 0xed558ccd & MASK_HIGH) | (h1 * 0x8ccd & MASK_LOW);
  42364. h2 = (h2 * 0xff51afd7 & MASK_HIGH) |
  42365. (((h2 << 16 | h1 >>> 16) * 0xafd7ed55 & MASK_HIGH) >>> 16);
  42366. h1 ^= h2 >>> 1;
  42367. h1 = (h1 * 0x1a85ec53 & MASK_HIGH) | (h1 * 0xec53 & MASK_LOW);
  42368. h2 = (h2 * 0xc4ceb9fe & MASK_HIGH) |
  42369. (((h2 << 16 | h1 >>> 16) * 0xb9fe1a85 & MASK_HIGH) >>> 16);
  42370. h1 ^= h2 >>> 1;
  42371. for (var i = 0, arr = [h1, h2], str = ''; i < arr.length; i++) {
  42372. var hex = (arr[i] >>> 0).toString(16);
  42373. while (hex.length < 8) {
  42374. hex = '0' + hex;
  42375. }
  42376. str += hex;
  42377. }
  42378. return str;
  42379. }
  42380. };
  42381. return MurmurHash3_64;
  42382. })();
  42383. }).call((typeof window === 'undefined') ? this : window);
  42384. if (!PDFJS.workerSrc && typeof document !== 'undefined') {
  42385. // workerSrc is not set -- using last script url to define default location
  42386. PDFJS.workerSrc = (function () {
  42387. 'use strict';
  42388. var scriptTagContainer = document.body ||
  42389. document.getElementsByTagName('head')[0];
  42390. var pdfjsSrc = scriptTagContainer.lastChild.src;
  42391. return pdfjsSrc && pdfjsSrc.replace(/\.js$/i, '.worker.js');
  42392. })();
  42393. }