pdf.combined.js 1.3 MB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079280802808128082280832808428085280862808728088280892809028091280922809328094280952809628097280982809928100281012810228103281042810528106281072810828109281102811128112281132811428115281162811728118281192812028121281222812328124281252812628127281282812928130281312813228133281342813528136281372813828139281402814128142281432814428145281462814728148281492815028151281522815328154281552815628157281582815928160281612816228163281642816528166281672816828169281702817128172281732817428175281762817728178281792818028181281822818328184281852818628187281882818928190281912819228193281942819528196281972819828199282002820128202282032820428205282062820728208282092821028211282122821328214282152821628217282182821928220282212822228223282242822528226282272822828229282302823128232282332823428235282362823728238282392824028241282422824328244282452824628247282482824928250282512825228253282542825528256282572825828259282602826128262282632826428265282662826728268282692827028271282722827328274282752827628277282782827928280282812828228283282842828528286282872828828289282902829128292282932829428295282962829728298282992830028301283022830328304283052830628307283082830928310283112831228313283142831528316283172831828319283202832128322283232832428325283262832728328283292833028331283322833328334283352833628337283382833928340283412834228343283442834528346283472834828349283502835128352283532835428355283562835728358283592836028361283622836328364283652836628367283682836928370283712837228373283742837528376283772837828379283802838128382283832838428385283862838728388283892839028391283922839328394283952839628397283982839928400284012840228403284042840528406284072840828409284102841128412284132841428415284162841728418284192842028421284222842328424284252842628427284282842928430284312843228433284342843528436284372843828439284402844128442284432844428445284462844728448284492845028451284522845328454284552845628457284582845928460284612846228463284642846528466284672846828469284702847128472284732847428475284762847728478284792848028481284822848328484284852848628487284882848928490284912849228493284942849528496284972849828499285002850128502285032850428505285062850728508285092851028511285122851328514285152851628517285182851928520285212852228523285242852528526285272852828529285302853128532285332853428535285362853728538285392854028541285422854328544285452854628547285482854928550285512855228553285542855528556285572855828559285602856128562285632856428565285662856728568285692857028571285722857328574285752857628577285782857928580285812858228583285842858528586285872858828589285902859128592285932859428595285962859728598285992860028601286022860328604286052860628607286082860928610286112861228613286142861528616286172861828619286202862128622286232862428625286262862728628286292863028631286322863328634286352863628637286382863928640286412864228643286442864528646286472864828649286502865128652286532865428655286562865728658286592866028661286622866328664286652866628667286682866928670286712867228673286742867528676286772867828679286802868128682286832868428685286862868728688286892869028691286922869328694286952869628697286982869928700287012870228703287042870528706287072870828709287102871128712287132871428715287162871728718287192872028721287222872328724287252872628727287282872928730287312873228733287342873528736287372873828739287402874128742287432874428745287462874728748287492875028751287522875328754287552875628757287582875928760287612876228763287642876528766287672876828769287702877128772287732877428775287762877728778287792878028781287822878328784287852878628787287882878928790287912879228793287942879528796287972879828799288002880128802288032880428805288062880728808288092881028811288122881328814288152881628817288182881928820288212882228823288242882528826288272882828829288302883128832288332883428835288362883728838288392884028841288422884328844288452884628847288482884928850288512885228853288542885528856288572885828859288602886128862288632886428865288662886728868288692887028871288722887328874288752887628877288782887928880288812888228883288842888528886288872888828889288902889128892288932889428895288962889728898288992890028901289022890328904289052890628907289082890928910289112891228913289142891528916289172891828919289202892128922289232892428925289262892728928289292893028931289322893328934289352893628937289382893928940289412894228943289442894528946289472894828949289502895128952289532895428955289562895728958289592896028961289622896328964289652896628967289682896928970289712897228973289742897528976289772897828979289802898128982289832898428985289862898728988289892899028991289922899328994289952899628997289982899929000290012900229003290042900529006290072900829009290102901129012290132901429015290162901729018290192902029021290222902329024290252902629027290282902929030290312903229033290342903529036290372903829039290402904129042290432904429045290462904729048290492905029051290522905329054290552905629057290582905929060290612906229063290642906529066290672906829069290702907129072290732907429075290762907729078290792908029081290822908329084290852908629087290882908929090290912909229093290942909529096290972909829099291002910129102291032910429105291062910729108291092911029111291122911329114291152911629117291182911929120291212912229123291242912529126291272912829129291302913129132291332913429135291362913729138291392914029141291422914329144291452914629147291482914929150291512915229153291542915529156291572915829159291602916129162291632916429165291662916729168291692917029171291722917329174291752917629177291782917929180291812918229183291842918529186291872918829189291902919129192291932919429195291962919729198291992920029201292022920329204292052920629207292082920929210292112921229213292142921529216292172921829219292202922129222292232922429225292262922729228292292923029231292322923329234292352923629237292382923929240292412924229243292442924529246292472924829249292502925129252292532925429255292562925729258292592926029261292622926329264292652926629267292682926929270292712927229273292742927529276292772927829279292802928129282292832928429285292862928729288292892929029291292922929329294292952929629297292982929929300293012930229303293042930529306293072930829309293102931129312293132931429315293162931729318293192932029321293222932329324293252932629327293282932929330293312933229333293342933529336293372933829339293402934129342293432934429345293462934729348293492935029351293522935329354293552935629357293582935929360293612936229363293642936529366293672936829369293702937129372293732937429375293762937729378293792938029381293822938329384293852938629387293882938929390293912939229393293942939529396293972939829399294002940129402294032940429405294062940729408294092941029411294122941329414294152941629417294182941929420294212942229423294242942529426294272942829429294302943129432294332943429435294362943729438294392944029441294422944329444294452944629447294482944929450294512945229453294542945529456294572945829459294602946129462294632946429465294662946729468294692947029471294722947329474294752947629477294782947929480294812948229483294842948529486294872948829489294902949129492294932949429495294962949729498294992950029501295022950329504295052950629507295082950929510295112951229513295142951529516295172951829519295202952129522295232952429525295262952729528295292953029531295322953329534295352953629537295382953929540295412954229543295442954529546295472954829549295502955129552295532955429555295562955729558295592956029561295622956329564295652956629567295682956929570295712957229573295742957529576295772957829579295802958129582295832958429585295862958729588295892959029591295922959329594295952959629597295982959929600296012960229603296042960529606296072960829609296102961129612296132961429615296162961729618296192962029621296222962329624296252962629627296282962929630296312963229633296342963529636296372963829639296402964129642296432964429645296462964729648296492965029651296522965329654296552965629657296582965929660296612966229663296642966529666296672966829669296702967129672296732967429675296762967729678296792968029681296822968329684296852968629687296882968929690296912969229693296942969529696296972969829699297002970129702297032970429705297062970729708297092971029711297122971329714297152971629717297182971929720297212972229723297242972529726297272972829729297302973129732297332973429735297362973729738297392974029741297422974329744297452974629747297482974929750297512975229753297542975529756297572975829759297602976129762297632976429765297662976729768297692977029771297722977329774297752977629777297782977929780297812978229783297842978529786297872978829789297902979129792297932979429795297962979729798297992980029801298022980329804298052980629807298082980929810298112981229813298142981529816298172981829819298202982129822298232982429825298262982729828298292983029831298322983329834298352983629837298382983929840298412984229843298442984529846298472984829849298502985129852298532985429855298562985729858298592986029861298622986329864298652986629867298682986929870298712987229873298742987529876298772987829879298802988129882298832988429885298862988729888298892989029891298922989329894298952989629897298982989929900299012990229903299042990529906299072990829909299102991129912299132991429915299162991729918299192992029921299222992329924299252992629927299282992929930299312993229933299342993529936299372993829939299402994129942299432994429945299462994729948299492995029951299522995329954299552995629957299582995929960299612996229963299642996529966299672996829969299702997129972299732997429975299762997729978299792998029981299822998329984299852998629987299882998929990299912999229993299942999529996299972999829999300003000130002300033000430005300063000730008300093001030011300123001330014300153001630017300183001930020300213002230023300243002530026300273002830029300303003130032300333003430035300363003730038300393004030041300423004330044300453004630047300483004930050300513005230053300543005530056300573005830059300603006130062300633006430065300663006730068300693007030071300723007330074300753007630077300783007930080300813008230083300843008530086300873008830089300903009130092300933009430095300963009730098300993010030101301023010330104301053010630107301083010930110301113011230113301143011530116301173011830119301203012130122301233012430125301263012730128301293013030131301323013330134301353013630137301383013930140301413014230143301443014530146301473014830149301503015130152301533015430155301563015730158301593016030161301623016330164301653016630167301683016930170301713017230173301743017530176301773017830179301803018130182301833018430185301863018730188301893019030191301923019330194301953019630197301983019930200302013020230203302043020530206302073020830209302103021130212302133021430215302163021730218302193022030221302223022330224302253022630227302283022930230302313023230233302343023530236302373023830239302403024130242302433024430245302463024730248302493025030251302523025330254302553025630257302583025930260302613026230263302643026530266302673026830269302703027130272302733027430275302763027730278302793028030281302823028330284302853028630287302883028930290302913029230293302943029530296302973029830299303003030130302303033030430305303063030730308303093031030311303123031330314303153031630317303183031930320303213032230323303243032530326303273032830329303303033130332303333033430335303363033730338303393034030341303423034330344303453034630347303483034930350303513035230353303543035530356303573035830359303603036130362303633036430365303663036730368303693037030371303723037330374303753037630377303783037930380303813038230383303843038530386303873038830389303903039130392303933039430395303963039730398303993040030401304023040330404304053040630407304083040930410304113041230413304143041530416304173041830419304203042130422304233042430425304263042730428304293043030431304323043330434304353043630437304383043930440304413044230443304443044530446304473044830449304503045130452304533045430455304563045730458304593046030461304623046330464304653046630467304683046930470304713047230473304743047530476304773047830479304803048130482304833048430485304863048730488304893049030491304923049330494304953049630497304983049930500305013050230503305043050530506305073050830509305103051130512305133051430515305163051730518305193052030521305223052330524305253052630527305283052930530305313053230533305343053530536305373053830539305403054130542305433054430545305463054730548305493055030551305523055330554305553055630557305583055930560305613056230563305643056530566305673056830569305703057130572305733057430575305763057730578305793058030581305823058330584305853058630587305883058930590305913059230593305943059530596305973059830599306003060130602306033060430605306063060730608306093061030611306123061330614306153061630617306183061930620306213062230623306243062530626306273062830629306303063130632306333063430635306363063730638306393064030641306423064330644306453064630647306483064930650306513065230653306543065530656306573065830659306603066130662306633066430665306663066730668306693067030671306723067330674306753067630677306783067930680306813068230683306843068530686306873068830689306903069130692306933069430695306963069730698306993070030701307023070330704307053070630707307083070930710307113071230713307143071530716307173071830719307203072130722307233072430725307263072730728307293073030731307323073330734307353073630737307383073930740307413074230743307443074530746307473074830749307503075130752307533075430755307563075730758307593076030761307623076330764307653076630767307683076930770307713077230773307743077530776307773077830779307803078130782307833078430785307863078730788307893079030791307923079330794307953079630797307983079930800308013080230803308043080530806308073080830809308103081130812308133081430815308163081730818308193082030821308223082330824308253082630827308283082930830308313083230833308343083530836308373083830839308403084130842308433084430845308463084730848308493085030851308523085330854308553085630857308583085930860308613086230863308643086530866308673086830869308703087130872308733087430875308763087730878308793088030881308823088330884308853088630887308883088930890308913089230893308943089530896308973089830899309003090130902309033090430905309063090730908309093091030911309123091330914309153091630917309183091930920309213092230923309243092530926309273092830929309303093130932309333093430935309363093730938309393094030941309423094330944309453094630947309483094930950309513095230953309543095530956309573095830959309603096130962309633096430965309663096730968309693097030971309723097330974309753097630977309783097930980309813098230983309843098530986309873098830989309903099130992309933099430995309963099730998309993100031001310023100331004310053100631007310083100931010310113101231013310143101531016310173101831019310203102131022310233102431025310263102731028310293103031031310323103331034310353103631037310383103931040310413104231043310443104531046310473104831049310503105131052310533105431055310563105731058310593106031061310623106331064310653106631067310683106931070310713107231073310743107531076310773107831079310803108131082310833108431085310863108731088310893109031091310923109331094310953109631097310983109931100311013110231103311043110531106311073110831109311103111131112311133111431115311163111731118311193112031121311223112331124311253112631127311283112931130311313113231133311343113531136311373113831139311403114131142311433114431145311463114731148311493115031151311523115331154311553115631157311583115931160311613116231163311643116531166311673116831169311703117131172311733117431175311763117731178311793118031181311823118331184311853118631187311883118931190311913119231193311943119531196311973119831199312003120131202312033120431205312063120731208312093121031211312123121331214312153121631217312183121931220312213122231223312243122531226312273122831229312303123131232312333123431235312363123731238312393124031241312423124331244312453124631247312483124931250312513125231253312543125531256312573125831259312603126131262312633126431265312663126731268312693127031271312723127331274312753127631277312783127931280312813128231283312843128531286312873128831289312903129131292312933129431295312963129731298312993130031301313023130331304313053130631307313083130931310313113131231313313143131531316313173131831319313203132131322313233132431325313263132731328313293133031331313323133331334313353133631337313383133931340313413134231343313443134531346313473134831349313503135131352313533135431355313563135731358313593136031361313623136331364313653136631367313683136931370313713137231373313743137531376313773137831379313803138131382313833138431385313863138731388313893139031391313923139331394313953139631397313983139931400314013140231403314043140531406314073140831409314103141131412314133141431415314163141731418314193142031421314223142331424314253142631427314283142931430314313143231433314343143531436314373143831439314403144131442314433144431445314463144731448314493145031451314523145331454314553145631457314583145931460314613146231463314643146531466314673146831469314703147131472314733147431475314763147731478314793148031481314823148331484314853148631487314883148931490314913149231493314943149531496314973149831499315003150131502315033150431505315063150731508315093151031511315123151331514315153151631517315183151931520315213152231523315243152531526315273152831529315303153131532315333153431535315363153731538315393154031541315423154331544315453154631547315483154931550315513155231553315543155531556315573155831559315603156131562315633156431565315663156731568315693157031571315723157331574315753157631577315783157931580315813158231583315843158531586315873158831589315903159131592315933159431595315963159731598315993160031601316023160331604316053160631607316083160931610316113161231613316143161531616316173161831619316203162131622316233162431625316263162731628316293163031631316323163331634316353163631637316383163931640316413164231643316443164531646316473164831649316503165131652316533165431655316563165731658316593166031661316623166331664316653166631667316683166931670316713167231673316743167531676316773167831679316803168131682316833168431685316863168731688316893169031691316923169331694316953169631697316983169931700317013170231703317043170531706317073170831709317103171131712317133171431715317163171731718317193172031721317223172331724317253172631727317283172931730317313173231733317343173531736317373173831739317403174131742317433174431745317463174731748317493175031751317523175331754317553175631757317583175931760317613176231763317643176531766317673176831769317703177131772317733177431775317763177731778317793178031781317823178331784317853178631787317883178931790317913179231793317943179531796317973179831799318003180131802318033180431805318063180731808318093181031811318123181331814318153181631817318183181931820318213182231823318243182531826318273182831829318303183131832318333183431835318363183731838318393184031841318423184331844318453184631847318483184931850318513185231853318543185531856318573185831859318603186131862318633186431865318663186731868318693187031871318723187331874318753187631877318783187931880318813188231883318843188531886318873188831889318903189131892318933189431895318963189731898318993190031901319023190331904319053190631907319083190931910319113191231913319143191531916319173191831919319203192131922319233192431925319263192731928319293193031931319323193331934319353193631937319383193931940319413194231943319443194531946319473194831949319503195131952319533195431955319563195731958319593196031961319623196331964319653196631967319683196931970319713197231973319743197531976319773197831979319803198131982319833198431985319863198731988319893199031991319923199331994319953199631997319983199932000320013200232003320043200532006320073200832009320103201132012320133201432015320163201732018320193202032021320223202332024320253202632027320283202932030320313203232033320343203532036320373203832039320403204132042320433204432045320463204732048320493205032051320523205332054320553205632057320583205932060320613206232063320643206532066320673206832069320703207132072320733207432075320763207732078320793208032081320823208332084320853208632087320883208932090320913209232093320943209532096320973209832099321003210132102321033210432105321063210732108321093211032111321123211332114321153211632117321183211932120321213212232123321243212532126321273212832129321303213132132321333213432135321363213732138321393214032141321423214332144321453214632147321483214932150321513215232153321543215532156321573215832159321603216132162321633216432165321663216732168321693217032171321723217332174321753217632177321783217932180321813218232183321843218532186321873218832189321903219132192321933219432195321963219732198321993220032201322023220332204322053220632207322083220932210322113221232213322143221532216322173221832219322203222132222322233222432225322263222732228322293223032231322323223332234322353223632237322383223932240322413224232243322443224532246322473224832249322503225132252322533225432255322563225732258322593226032261322623226332264322653226632267322683226932270322713227232273322743227532276322773227832279322803228132282322833228432285322863228732288322893229032291322923229332294322953229632297322983229932300323013230232303323043230532306323073230832309323103231132312323133231432315323163231732318323193232032321323223232332324323253232632327323283232932330323313233232333323343233532336323373233832339323403234132342323433234432345323463234732348323493235032351323523235332354323553235632357323583235932360323613236232363323643236532366323673236832369323703237132372323733237432375323763237732378323793238032381323823238332384323853238632387323883238932390323913239232393323943239532396323973239832399324003240132402324033240432405324063240732408324093241032411324123241332414324153241632417324183241932420324213242232423324243242532426324273242832429324303243132432324333243432435324363243732438324393244032441324423244332444324453244632447324483244932450324513245232453324543245532456324573245832459324603246132462324633246432465324663246732468324693247032471324723247332474324753247632477324783247932480324813248232483324843248532486324873248832489324903249132492324933249432495324963249732498324993250032501325023250332504325053250632507325083250932510325113251232513325143251532516325173251832519325203252132522325233252432525325263252732528325293253032531325323253332534325353253632537325383253932540325413254232543325443254532546325473254832549325503255132552325533255432555325563255732558325593256032561325623256332564325653256632567325683256932570325713257232573325743257532576325773257832579325803258132582325833258432585325863258732588325893259032591325923259332594325953259632597325983259932600326013260232603326043260532606326073260832609326103261132612326133261432615326163261732618326193262032621326223262332624326253262632627326283262932630326313263232633326343263532636326373263832639326403264132642326433264432645326463264732648326493265032651326523265332654326553265632657326583265932660326613266232663326643266532666326673266832669326703267132672326733267432675326763267732678326793268032681326823268332684326853268632687326883268932690326913269232693326943269532696326973269832699327003270132702327033270432705327063270732708327093271032711327123271332714327153271632717327183271932720327213272232723327243272532726327273272832729327303273132732327333273432735327363273732738327393274032741327423274332744327453274632747327483274932750327513275232753327543275532756327573275832759327603276132762327633276432765327663276732768327693277032771327723277332774327753277632777327783277932780327813278232783327843278532786327873278832789327903279132792327933279432795327963279732798327993280032801328023280332804328053280632807328083280932810328113281232813328143281532816328173281832819328203282132822328233282432825328263282732828328293283032831328323283332834328353283632837328383283932840328413284232843328443284532846328473284832849328503285132852328533285432855328563285732858328593286032861328623286332864328653286632867328683286932870328713287232873328743287532876328773287832879328803288132882328833288432885328863288732888328893289032891328923289332894328953289632897328983289932900329013290232903329043290532906329073290832909329103291132912329133291432915329163291732918329193292032921329223292332924329253292632927329283292932930329313293232933329343293532936329373293832939329403294132942329433294432945329463294732948329493295032951329523295332954329553295632957329583295932960329613296232963329643296532966329673296832969329703297132972329733297432975329763297732978329793298032981329823298332984329853298632987329883298932990329913299232993329943299532996329973299832999330003300133002330033300433005330063300733008330093301033011330123301333014330153301633017330183301933020330213302233023330243302533026330273302833029330303303133032330333303433035330363303733038330393304033041330423304333044330453304633047330483304933050330513305233053330543305533056330573305833059330603306133062330633306433065330663306733068330693307033071330723307333074330753307633077330783307933080330813308233083330843308533086330873308833089330903309133092330933309433095330963309733098330993310033101331023310333104331053310633107331083310933110331113311233113331143311533116331173311833119331203312133122331233312433125331263312733128331293313033131331323313333134331353313633137331383313933140331413314233143331443314533146331473314833149331503315133152331533315433155331563315733158331593316033161331623316333164331653316633167331683316933170331713317233173331743317533176331773317833179331803318133182331833318433185331863318733188331893319033191331923319333194331953319633197331983319933200332013320233203332043320533206332073320833209332103321133212332133321433215332163321733218332193322033221332223322333224332253322633227332283322933230332313323233233332343323533236332373323833239332403324133242332433324433245332463324733248332493325033251332523325333254332553325633257332583325933260332613326233263332643326533266332673326833269332703327133272332733327433275332763327733278332793328033281332823328333284332853328633287332883328933290332913329233293332943329533296332973329833299333003330133302333033330433305333063330733308333093331033311333123331333314333153331633317333183331933320333213332233323333243332533326333273332833329333303333133332333333333433335333363333733338333393334033341333423334333344333453334633347333483334933350333513335233353333543335533356333573335833359333603336133362333633336433365333663336733368333693337033371333723337333374333753337633377333783337933380333813338233383333843338533386333873338833389333903339133392333933339433395333963339733398333993340033401334023340333404334053340633407334083340933410334113341233413334143341533416334173341833419334203342133422334233342433425334263342733428334293343033431334323343333434334353343633437334383343933440334413344233443334443344533446334473344833449334503345133452334533345433455334563345733458334593346033461334623346333464334653346633467334683346933470334713347233473334743347533476334773347833479334803348133482334833348433485334863348733488334893349033491334923349333494334953349633497334983349933500335013350233503335043350533506335073350833509335103351133512335133351433515335163351733518335193352033521335223352333524335253352633527335283352933530335313353233533335343353533536335373353833539335403354133542335433354433545335463354733548335493355033551335523355333554335553355633557335583355933560335613356233563335643356533566335673356833569335703357133572335733357433575335763357733578335793358033581335823358333584335853358633587335883358933590335913359233593335943359533596335973359833599336003360133602336033360433605336063360733608336093361033611336123361333614336153361633617336183361933620336213362233623336243362533626336273362833629336303363133632336333363433635336363363733638336393364033641336423364333644336453364633647336483364933650336513365233653336543365533656336573365833659336603366133662336633366433665336663366733668336693367033671336723367333674336753367633677336783367933680336813368233683336843368533686336873368833689336903369133692336933369433695336963369733698336993370033701337023370333704337053370633707337083370933710337113371233713337143371533716337173371833719337203372133722337233372433725337263372733728337293373033731337323373333734337353373633737337383373933740337413374233743337443374533746337473374833749337503375133752337533375433755337563375733758337593376033761337623376333764337653376633767337683376933770337713377233773337743377533776337773377833779337803378133782337833378433785337863378733788337893379033791337923379333794337953379633797337983379933800338013380233803338043380533806338073380833809338103381133812338133381433815338163381733818338193382033821338223382333824338253382633827338283382933830338313383233833338343383533836338373383833839338403384133842338433384433845338463384733848338493385033851338523385333854338553385633857338583385933860338613386233863338643386533866338673386833869338703387133872338733387433875338763387733878338793388033881338823388333884338853388633887338883388933890338913389233893338943389533896338973389833899339003390133902339033390433905339063390733908339093391033911339123391333914339153391633917339183391933920339213392233923339243392533926339273392833929339303393133932339333393433935339363393733938339393394033941339423394333944339453394633947339483394933950339513395233953339543395533956339573395833959339603396133962339633396433965339663396733968339693397033971339723397333974339753397633977339783397933980339813398233983339843398533986339873398833989339903399133992339933399433995339963399733998339993400034001340023400334004340053400634007340083400934010340113401234013340143401534016340173401834019340203402134022340233402434025340263402734028340293403034031340323403334034340353403634037340383403934040340413404234043340443404534046340473404834049340503405134052340533405434055340563405734058340593406034061340623406334064340653406634067340683406934070340713407234073340743407534076340773407834079340803408134082340833408434085340863408734088340893409034091340923409334094340953409634097340983409934100341013410234103341043410534106341073410834109341103411134112341133411434115341163411734118341193412034121341223412334124341253412634127341283412934130341313413234133341343413534136341373413834139341403414134142341433414434145341463414734148341493415034151341523415334154341553415634157341583415934160341613416234163341643416534166341673416834169341703417134172341733417434175341763417734178341793418034181341823418334184341853418634187341883418934190341913419234193341943419534196341973419834199342003420134202342033420434205342063420734208342093421034211342123421334214342153421634217342183421934220342213422234223342243422534226342273422834229342303423134232342333423434235342363423734238342393424034241342423424334244342453424634247342483424934250342513425234253342543425534256342573425834259342603426134262342633426434265342663426734268342693427034271342723427334274342753427634277342783427934280342813428234283342843428534286342873428834289342903429134292342933429434295342963429734298342993430034301343023430334304343053430634307343083430934310343113431234313343143431534316343173431834319343203432134322343233432434325343263432734328343293433034331343323433334334343353433634337343383433934340343413434234343343443434534346343473434834349343503435134352343533435434355343563435734358343593436034361343623436334364343653436634367343683436934370343713437234373343743437534376343773437834379343803438134382343833438434385343863438734388343893439034391343923439334394343953439634397343983439934400344013440234403344043440534406344073440834409344103441134412344133441434415344163441734418344193442034421344223442334424344253442634427344283442934430344313443234433344343443534436344373443834439344403444134442344433444434445344463444734448344493445034451344523445334454344553445634457344583445934460344613446234463344643446534466344673446834469344703447134472344733447434475344763447734478344793448034481344823448334484344853448634487344883448934490344913449234493344943449534496344973449834499345003450134502345033450434505345063450734508345093451034511345123451334514345153451634517345183451934520345213452234523345243452534526345273452834529345303453134532345333453434535345363453734538345393454034541345423454334544345453454634547345483454934550345513455234553345543455534556345573455834559345603456134562345633456434565345663456734568345693457034571345723457334574345753457634577345783457934580345813458234583345843458534586345873458834589345903459134592345933459434595345963459734598345993460034601346023460334604346053460634607346083460934610346113461234613346143461534616346173461834619346203462134622346233462434625346263462734628346293463034631346323463334634346353463634637346383463934640346413464234643346443464534646346473464834649346503465134652346533465434655346563465734658346593466034661346623466334664346653466634667346683466934670346713467234673346743467534676346773467834679346803468134682346833468434685346863468734688346893469034691346923469334694346953469634697346983469934700347013470234703347043470534706347073470834709347103471134712347133471434715347163471734718347193472034721347223472334724347253472634727347283472934730347313473234733347343473534736347373473834739347403474134742347433474434745347463474734748347493475034751347523475334754347553475634757347583475934760347613476234763347643476534766347673476834769347703477134772347733477434775347763477734778347793478034781347823478334784347853478634787347883478934790347913479234793347943479534796347973479834799348003480134802348033480434805348063480734808348093481034811348123481334814348153481634817348183481934820348213482234823348243482534826348273482834829348303483134832348333483434835348363483734838348393484034841348423484334844348453484634847348483484934850348513485234853348543485534856348573485834859348603486134862348633486434865348663486734868348693487034871348723487334874348753487634877348783487934880348813488234883348843488534886348873488834889348903489134892348933489434895348963489734898348993490034901349023490334904349053490634907349083490934910349113491234913349143491534916349173491834919349203492134922349233492434925349263492734928349293493034931349323493334934349353493634937349383493934940349413494234943349443494534946349473494834949349503495134952349533495434955349563495734958349593496034961349623496334964349653496634967349683496934970349713497234973349743497534976349773497834979349803498134982349833498434985349863498734988349893499034991349923499334994349953499634997349983499935000350013500235003350043500535006350073500835009350103501135012350133501435015350163501735018350193502035021350223502335024350253502635027350283502935030350313503235033350343503535036350373503835039350403504135042350433504435045350463504735048350493505035051350523505335054350553505635057350583505935060350613506235063350643506535066350673506835069350703507135072350733507435075350763507735078350793508035081350823508335084350853508635087350883508935090350913509235093350943509535096350973509835099351003510135102351033510435105351063510735108351093511035111351123511335114351153511635117351183511935120351213512235123351243512535126351273512835129351303513135132351333513435135351363513735138351393514035141351423514335144351453514635147351483514935150351513515235153351543515535156351573515835159351603516135162351633516435165351663516735168351693517035171351723517335174351753517635177351783517935180351813518235183351843518535186351873518835189351903519135192351933519435195351963519735198351993520035201352023520335204352053520635207352083520935210352113521235213352143521535216352173521835219352203522135222352233522435225352263522735228352293523035231352323523335234352353523635237352383523935240352413524235243352443524535246352473524835249352503525135252352533525435255352563525735258352593526035261352623526335264352653526635267352683526935270352713527235273352743527535276352773527835279352803528135282352833528435285352863528735288352893529035291352923529335294352953529635297352983529935300353013530235303353043530535306353073530835309353103531135312353133531435315353163531735318353193532035321353223532335324353253532635327353283532935330353313533235333353343533535336353373533835339353403534135342353433534435345353463534735348353493535035351353523535335354353553535635357353583535935360353613536235363353643536535366353673536835369353703537135372353733537435375353763537735378353793538035381353823538335384353853538635387353883538935390353913539235393353943539535396353973539835399354003540135402354033540435405354063540735408354093541035411354123541335414354153541635417354183541935420354213542235423354243542535426354273542835429354303543135432354333543435435354363543735438354393544035441354423544335444354453544635447354483544935450354513545235453354543545535456354573545835459354603546135462354633546435465354663546735468354693547035471354723547335474354753547635477354783547935480354813548235483354843548535486354873548835489354903549135492354933549435495354963549735498354993550035501355023550335504355053550635507355083550935510355113551235513355143551535516355173551835519355203552135522355233552435525355263552735528355293553035531355323553335534355353553635537355383553935540355413554235543355443554535546355473554835549355503555135552355533555435555355563555735558355593556035561355623556335564355653556635567355683556935570355713557235573355743557535576355773557835579355803558135582355833558435585355863558735588355893559035591355923559335594355953559635597355983559935600356013560235603356043560535606356073560835609356103561135612356133561435615356163561735618356193562035621356223562335624356253562635627356283562935630356313563235633356343563535636356373563835639356403564135642356433564435645356463564735648356493565035651356523565335654356553565635657356583565935660356613566235663356643566535666356673566835669356703567135672356733567435675356763567735678356793568035681356823568335684356853568635687356883568935690356913569235693356943569535696356973569835699357003570135702357033570435705357063570735708357093571035711357123571335714357153571635717357183571935720357213572235723357243572535726357273572835729357303573135732357333573435735357363573735738357393574035741357423574335744357453574635747357483574935750357513575235753357543575535756357573575835759357603576135762357633576435765357663576735768357693577035771357723577335774357753577635777357783577935780357813578235783357843578535786357873578835789357903579135792357933579435795357963579735798357993580035801358023580335804358053580635807358083580935810358113581235813358143581535816358173581835819358203582135822358233582435825358263582735828358293583035831358323583335834358353583635837358383583935840358413584235843358443584535846358473584835849358503585135852358533585435855358563585735858358593586035861358623586335864358653586635867358683586935870358713587235873358743587535876358773587835879358803588135882358833588435885358863588735888358893589035891358923589335894358953589635897358983589935900359013590235903359043590535906359073590835909359103591135912359133591435915359163591735918359193592035921359223592335924359253592635927359283592935930359313593235933359343593535936359373593835939359403594135942359433594435945359463594735948359493595035951359523595335954359553595635957359583595935960359613596235963359643596535966359673596835969359703597135972359733597435975359763597735978359793598035981359823598335984359853598635987359883598935990359913599235993359943599535996359973599835999360003600136002360033600436005360063600736008360093601036011360123601336014360153601636017360183601936020360213602236023360243602536026360273602836029360303603136032360333603436035360363603736038360393604036041360423604336044360453604636047360483604936050360513605236053360543605536056360573605836059360603606136062360633606436065360663606736068360693607036071360723607336074360753607636077360783607936080360813608236083360843608536086360873608836089360903609136092360933609436095360963609736098360993610036101361023610336104361053610636107361083610936110361113611236113361143611536116361173611836119361203612136122361233612436125361263612736128361293613036131361323613336134361353613636137361383613936140361413614236143361443614536146361473614836149361503615136152361533615436155361563615736158361593616036161361623616336164361653616636167361683616936170361713617236173361743617536176361773617836179361803618136182361833618436185361863618736188361893619036191361923619336194361953619636197361983619936200362013620236203362043620536206362073620836209362103621136212362133621436215362163621736218362193622036221362223622336224362253622636227362283622936230362313623236233362343623536236362373623836239362403624136242362433624436245362463624736248362493625036251362523625336254362553625636257362583625936260362613626236263362643626536266362673626836269362703627136272362733627436275362763627736278362793628036281362823628336284362853628636287362883628936290362913629236293362943629536296362973629836299363003630136302363033630436305363063630736308363093631036311363123631336314363153631636317363183631936320363213632236323363243632536326363273632836329363303633136332363333633436335363363633736338363393634036341363423634336344363453634636347363483634936350363513635236353363543635536356363573635836359363603636136362363633636436365363663636736368363693637036371363723637336374363753637636377363783637936380363813638236383363843638536386363873638836389363903639136392363933639436395363963639736398363993640036401364023640336404364053640636407364083640936410364113641236413364143641536416364173641836419364203642136422364233642436425364263642736428364293643036431364323643336434364353643636437364383643936440364413644236443364443644536446364473644836449364503645136452364533645436455364563645736458364593646036461364623646336464364653646636467364683646936470364713647236473364743647536476364773647836479364803648136482364833648436485364863648736488364893649036491364923649336494364953649636497364983649936500365013650236503365043650536506365073650836509365103651136512365133651436515365163651736518365193652036521365223652336524365253652636527365283652936530365313653236533365343653536536365373653836539365403654136542365433654436545365463654736548365493655036551365523655336554365553655636557365583655936560365613656236563365643656536566365673656836569365703657136572365733657436575365763657736578365793658036581365823658336584365853658636587365883658936590365913659236593365943659536596365973659836599366003660136602366033660436605366063660736608366093661036611366123661336614366153661636617366183661936620366213662236623366243662536626366273662836629366303663136632366333663436635366363663736638366393664036641366423664336644366453664636647366483664936650366513665236653366543665536656366573665836659366603666136662366633666436665366663666736668366693667036671366723667336674366753667636677366783667936680366813668236683366843668536686366873668836689366903669136692366933669436695366963669736698366993670036701367023670336704367053670636707367083670936710367113671236713367143671536716367173671836719367203672136722367233672436725367263672736728367293673036731367323673336734367353673636737367383673936740367413674236743367443674536746367473674836749367503675136752367533675436755367563675736758367593676036761367623676336764367653676636767367683676936770367713677236773367743677536776367773677836779367803678136782367833678436785367863678736788367893679036791367923679336794367953679636797367983679936800368013680236803368043680536806368073680836809368103681136812368133681436815368163681736818368193682036821368223682336824368253682636827368283682936830368313683236833368343683536836368373683836839368403684136842368433684436845368463684736848368493685036851368523685336854368553685636857368583685936860368613686236863368643686536866368673686836869368703687136872368733687436875368763687736878368793688036881368823688336884368853688636887368883688936890368913689236893368943689536896368973689836899369003690136902369033690436905369063690736908369093691036911369123691336914369153691636917369183691936920369213692236923369243692536926369273692836929369303693136932369333693436935369363693736938369393694036941369423694336944369453694636947369483694936950369513695236953369543695536956369573695836959369603696136962369633696436965369663696736968369693697036971369723697336974369753697636977369783697936980369813698236983369843698536986369873698836989369903699136992369933699436995369963699736998369993700037001370023700337004370053700637007370083700937010370113701237013370143701537016370173701837019370203702137022370233702437025370263702737028370293703037031370323703337034370353703637037370383703937040370413704237043370443704537046370473704837049370503705137052370533705437055370563705737058370593706037061370623706337064370653706637067370683706937070370713707237073370743707537076370773707837079370803708137082370833708437085370863708737088370893709037091370923709337094370953709637097370983709937100371013710237103371043710537106371073710837109371103711137112371133711437115371163711737118371193712037121371223712337124371253712637127371283712937130371313713237133371343713537136371373713837139371403714137142371433714437145371463714737148371493715037151371523715337154371553715637157371583715937160371613716237163371643716537166371673716837169371703717137172371733717437175371763717737178371793718037181371823718337184371853718637187371883718937190371913719237193371943719537196371973719837199372003720137202372033720437205372063720737208372093721037211372123721337214372153721637217372183721937220372213722237223372243722537226372273722837229372303723137232372333723437235372363723737238372393724037241372423724337244372453724637247372483724937250372513725237253372543725537256372573725837259372603726137262372633726437265372663726737268372693727037271372723727337274372753727637277372783727937280372813728237283372843728537286372873728837289372903729137292372933729437295372963729737298372993730037301373023730337304373053730637307373083730937310373113731237313373143731537316373173731837319373203732137322373233732437325373263732737328373293733037331373323733337334373353733637337373383733937340373413734237343373443734537346373473734837349373503735137352373533735437355373563735737358373593736037361373623736337364373653736637367373683736937370373713737237373373743737537376373773737837379373803738137382373833738437385373863738737388373893739037391373923739337394373953739637397373983739937400374013740237403374043740537406374073740837409374103741137412374133741437415374163741737418374193742037421374223742337424374253742637427374283742937430374313743237433374343743537436374373743837439374403744137442374433744437445374463744737448374493745037451374523745337454374553745637457374583745937460374613746237463374643746537466374673746837469374703747137472374733747437475374763747737478374793748037481374823748337484374853748637487374883748937490374913749237493374943749537496374973749837499375003750137502375033750437505375063750737508375093751037511375123751337514375153751637517375183751937520375213752237523375243752537526375273752837529375303753137532375333753437535375363753737538375393754037541375423754337544375453754637547375483754937550375513755237553375543755537556375573755837559375603756137562375633756437565375663756737568375693757037571375723757337574375753757637577375783757937580375813758237583375843758537586375873758837589375903759137592375933759437595375963759737598375993760037601376023760337604376053760637607376083760937610376113761237613376143761537616376173761837619376203762137622376233762437625376263762737628376293763037631376323763337634376353763637637376383763937640376413764237643376443764537646376473764837649376503765137652376533765437655376563765737658376593766037661376623766337664376653766637667376683766937670376713767237673376743767537676376773767837679376803768137682376833768437685376863768737688376893769037691376923769337694376953769637697376983769937700377013770237703377043770537706377073770837709377103771137712377133771437715377163771737718377193772037721377223772337724377253772637727377283772937730377313773237733377343773537736377373773837739377403774137742377433774437745377463774737748377493775037751377523775337754377553775637757377583775937760377613776237763377643776537766377673776837769377703777137772377733777437775377763777737778377793778037781377823778337784377853778637787377883778937790377913779237793377943779537796377973779837799378003780137802378033780437805378063780737808378093781037811378123781337814378153781637817378183781937820378213782237823378243782537826378273782837829378303783137832378333783437835378363783737838378393784037841378423784337844378453784637847378483784937850378513785237853378543785537856378573785837859378603786137862378633786437865378663786737868378693787037871378723787337874378753787637877378783787937880378813788237883378843788537886378873788837889378903789137892378933789437895378963789737898378993790037901379023790337904379053790637907379083790937910379113791237913379143791537916379173791837919379203792137922379233792437925379263792737928379293793037931379323793337934379353793637937379383793937940379413794237943379443794537946379473794837949379503795137952379533795437955379563795737958379593796037961379623796337964379653796637967379683796937970379713797237973379743797537976379773797837979379803798137982379833798437985379863798737988379893799037991379923799337994379953799637997379983799938000380013800238003380043800538006380073800838009380103801138012380133801438015380163801738018380193802038021380223802338024380253802638027380283802938030380313803238033380343803538036380373803838039380403804138042380433804438045380463804738048380493805038051380523805338054380553805638057380583805938060380613806238063380643806538066380673806838069380703807138072380733807438075380763807738078380793808038081380823808338084380853808638087380883808938090380913809238093380943809538096380973809838099381003810138102381033810438105381063810738108381093811038111381123811338114381153811638117381183811938120381213812238123381243812538126381273812838129381303813138132381333813438135381363813738138381393814038141381423814338144381453814638147381483814938150381513815238153381543815538156381573815838159381603816138162381633816438165381663816738168381693817038171381723817338174381753817638177381783817938180381813818238183381843818538186381873818838189381903819138192381933819438195381963819738198381993820038201382023820338204382053820638207382083820938210382113821238213382143821538216382173821838219382203822138222382233822438225382263822738228382293823038231382323823338234382353823638237382383823938240382413824238243382443824538246382473824838249382503825138252382533825438255382563825738258382593826038261382623826338264382653826638267382683826938270382713827238273382743827538276382773827838279382803828138282382833828438285382863828738288382893829038291382923829338294382953829638297382983829938300383013830238303383043830538306383073830838309383103831138312383133831438315383163831738318383193832038321383223832338324383253832638327383283832938330383313833238333383343833538336383373833838339383403834138342383433834438345383463834738348383493835038351383523835338354383553835638357383583835938360383613836238363383643836538366383673836838369383703837138372383733837438375383763837738378383793838038381383823838338384383853838638387383883838938390383913839238393383943839538396383973839838399384003840138402384033840438405384063840738408384093841038411384123841338414384153841638417384183841938420384213842238423384243842538426384273842838429384303843138432384333843438435384363843738438384393844038441384423844338444384453844638447384483844938450384513845238453384543845538456384573845838459384603846138462384633846438465384663846738468384693847038471384723847338474384753847638477384783847938480384813848238483384843848538486384873848838489384903849138492384933849438495384963849738498384993850038501385023850338504385053850638507385083850938510385113851238513385143851538516385173851838519385203852138522385233852438525385263852738528385293853038531385323853338534385353853638537385383853938540385413854238543385443854538546385473854838549385503855138552385533855438555385563855738558385593856038561385623856338564385653856638567385683856938570385713857238573385743857538576385773857838579385803858138582385833858438585385863858738588385893859038591385923859338594385953859638597385983859938600386013860238603386043860538606386073860838609386103861138612386133861438615386163861738618386193862038621386223862338624386253862638627386283862938630386313863238633386343863538636386373863838639386403864138642386433864438645386463864738648386493865038651386523865338654386553865638657386583865938660386613866238663386643866538666386673866838669386703867138672386733867438675386763867738678386793868038681386823868338684386853868638687386883868938690386913869238693386943869538696386973869838699387003870138702387033870438705387063870738708387093871038711387123871338714387153871638717387183871938720387213872238723387243872538726387273872838729387303873138732387333873438735387363873738738387393874038741387423874338744387453874638747387483874938750387513875238753387543875538756387573875838759387603876138762387633876438765387663876738768387693877038771387723877338774387753877638777387783877938780387813878238783387843878538786387873878838789387903879138792387933879438795387963879738798387993880038801388023880338804388053880638807388083880938810388113881238813388143881538816388173881838819388203882138822388233882438825388263882738828388293883038831388323883338834388353883638837388383883938840388413884238843388443884538846388473884838849388503885138852388533885438855388563885738858388593886038861388623886338864388653886638867388683886938870388713887238873388743887538876388773887838879388803888138882388833888438885388863888738888388893889038891388923889338894388953889638897388983889938900389013890238903389043890538906389073890838909389103891138912389133891438915389163891738918389193892038921389223892338924389253892638927389283892938930389313893238933389343893538936389373893838939389403894138942389433894438945389463894738948389493895038951389523895338954389553895638957389583895938960389613896238963389643896538966389673896838969389703897138972389733897438975389763897738978389793898038981389823898338984389853898638987389883898938990389913899238993389943899538996389973899838999390003900139002390033900439005390063900739008390093901039011390123901339014390153901639017390183901939020390213902239023390243902539026390273902839029390303903139032390333903439035390363903739038390393904039041390423904339044390453904639047390483904939050390513905239053390543905539056390573905839059390603906139062390633906439065390663906739068390693907039071390723907339074390753907639077390783907939080390813908239083390843908539086390873908839089390903909139092390933909439095390963909739098390993910039101391023910339104391053910639107391083910939110391113911239113391143911539116391173911839119391203912139122391233912439125391263912739128391293913039131391323913339134391353913639137391383913939140391413914239143391443914539146391473914839149391503915139152391533915439155391563915739158391593916039161391623916339164391653916639167391683916939170391713917239173391743917539176391773917839179391803918139182391833918439185391863918739188391893919039191391923919339194391953919639197391983919939200392013920239203392043920539206392073920839209392103921139212392133921439215392163921739218392193922039221392223922339224392253922639227392283922939230392313923239233392343923539236392373923839239392403924139242392433924439245392463924739248392493925039251392523925339254392553925639257392583925939260392613926239263392643926539266392673926839269392703927139272392733927439275392763927739278392793928039281392823928339284392853928639287392883928939290392913929239293392943929539296392973929839299393003930139302393033930439305393063930739308393093931039311393123931339314393153931639317393183931939320393213932239323393243932539326393273932839329393303933139332393333933439335393363933739338393393934039341393423934339344393453934639347393483934939350393513935239353393543935539356393573935839359393603936139362393633936439365393663936739368393693937039371393723937339374393753937639377393783937939380393813938239383393843938539386393873938839389393903939139392393933939439395393963939739398393993940039401394023940339404394053940639407394083940939410394113941239413394143941539416394173941839419394203942139422394233942439425394263942739428394293943039431394323943339434394353943639437394383943939440394413944239443394443944539446394473944839449394503945139452394533945439455394563945739458394593946039461394623946339464394653946639467394683946939470394713947239473394743947539476394773947839479394803948139482394833948439485394863948739488394893949039491394923949339494394953949639497394983949939500395013950239503395043950539506395073950839509395103951139512395133951439515395163951739518395193952039521395223952339524395253952639527395283952939530395313953239533395343953539536395373953839539395403954139542395433954439545395463954739548395493955039551395523955339554395553955639557395583955939560395613956239563395643956539566395673956839569395703957139572395733957439575395763957739578395793958039581395823958339584395853958639587395883958939590395913959239593395943959539596395973959839599396003960139602396033960439605396063960739608396093961039611396123961339614396153961639617396183961939620396213962239623396243962539626396273962839629396303963139632396333963439635396363963739638396393964039641396423964339644396453964639647396483964939650396513965239653396543965539656396573965839659396603966139662396633966439665396663966739668396693967039671396723967339674396753967639677396783967939680396813968239683396843968539686396873968839689396903969139692396933969439695396963969739698396993970039701397023970339704397053970639707397083970939710397113971239713397143971539716397173971839719397203972139722397233972439725397263972739728397293973039731397323973339734397353973639737397383973939740397413974239743397443974539746397473974839749397503975139752397533975439755397563975739758397593976039761397623976339764397653976639767397683976939770397713977239773397743977539776397773977839779397803978139782397833978439785397863978739788397893979039791397923979339794397953979639797397983979939800398013980239803398043980539806398073980839809398103981139812398133981439815398163981739818398193982039821398223982339824398253982639827398283982939830398313983239833398343983539836398373983839839398403984139842398433984439845398463984739848398493985039851398523985339854398553985639857398583985939860398613986239863398643986539866398673986839869398703987139872398733987439875398763987739878398793988039881398823988339884398853988639887398883988939890398913989239893398943989539896398973989839899399003990139902399033990439905399063990739908399093991039911399123991339914399153991639917399183991939920399213992239923399243992539926399273992839929399303993139932399333993439935399363993739938399393994039941399423994339944399453994639947399483994939950399513995239953399543995539956399573995839959399603996139962399633996439965399663996739968399693997039971399723997339974399753997639977399783997939980399813998239983399843998539986399873998839989399903999139992399933999439995399963999739998399994000040001400024000340004400054000640007400084000940010400114001240013400144001540016400174001840019400204002140022400234002440025400264002740028400294003040031400324003340034400354003640037400384003940040400414004240043400444004540046400474004840049400504005140052400534005440055400564005740058400594006040061400624006340064400654006640067400684006940070400714007240073400744007540076400774007840079400804008140082400834008440085400864008740088400894009040091400924009340094400954009640097400984009940100401014010240103401044010540106401074010840109401104011140112401134011440115401164011740118401194012040121401224012340124401254012640127401284012940130401314013240133401344013540136401374013840139401404014140142401434014440145401464014740148401494015040151401524015340154401554015640157401584015940160401614016240163401644016540166401674016840169401704017140172401734017440175401764017740178401794018040181401824018340184401854018640187401884018940190401914019240193401944019540196401974019840199402004020140202402034020440205402064020740208402094021040211402124021340214402154021640217402184021940220402214022240223402244022540226402274022840229402304023140232402334023440235402364023740238402394024040241402424024340244402454024640247402484024940250402514025240253402544025540256402574025840259402604026140262402634026440265402664026740268402694027040271402724027340274402754027640277402784027940280402814028240283402844028540286402874028840289402904029140292402934029440295402964029740298402994030040301403024030340304403054030640307403084030940310403114031240313403144031540316403174031840319403204032140322403234032440325403264032740328403294033040331403324033340334403354033640337403384033940340403414034240343403444034540346403474034840349403504035140352403534035440355403564035740358403594036040361403624036340364403654036640367403684036940370403714037240373403744037540376403774037840379403804038140382403834038440385403864038740388403894039040391403924039340394403954039640397403984039940400404014040240403404044040540406404074040840409404104041140412404134041440415404164041740418404194042040421404224042340424404254042640427404284042940430404314043240433404344043540436404374043840439404404044140442404434044440445404464044740448404494045040451404524045340454404554045640457404584045940460404614046240463404644046540466404674046840469404704047140472404734047440475404764047740478404794048040481404824048340484404854048640487404884048940490404914049240493404944049540496404974049840499405004050140502405034050440505405064050740508405094051040511405124051340514405154051640517405184051940520405214052240523405244052540526405274052840529405304053140532405334053440535405364053740538405394054040541405424054340544405454054640547405484054940550405514055240553405544055540556405574055840559405604056140562405634056440565405664056740568405694057040571405724057340574405754057640577405784057940580405814058240583405844058540586405874058840589405904059140592405934059440595405964059740598405994060040601406024060340604406054060640607406084060940610406114061240613406144061540616406174061840619406204062140622406234062440625406264062740628406294063040631406324063340634406354063640637406384063940640406414064240643406444064540646406474064840649406504065140652406534065440655406564065740658406594066040661406624066340664406654066640667406684066940670406714067240673406744067540676406774067840679406804068140682406834068440685406864068740688406894069040691406924069340694406954069640697406984069940700407014070240703407044070540706407074070840709407104071140712407134071440715407164071740718407194072040721407224072340724407254072640727407284072940730407314073240733407344073540736407374073840739407404074140742407434074440745407464074740748407494075040751407524075340754407554075640757407584075940760407614076240763407644076540766407674076840769407704077140772407734077440775407764077740778407794078040781407824078340784407854078640787407884078940790407914079240793407944079540796407974079840799408004080140802408034080440805408064080740808408094081040811408124081340814408154081640817408184081940820408214082240823408244082540826408274082840829408304083140832408334083440835408364083740838408394084040841408424084340844408454084640847408484084940850408514085240853408544085540856408574085840859408604086140862408634086440865408664086740868408694087040871408724087340874408754087640877408784087940880408814088240883408844088540886408874088840889408904089140892408934089440895408964089740898408994090040901409024090340904409054090640907409084090940910409114091240913409144091540916409174091840919409204092140922409234092440925409264092740928409294093040931409324093340934409354093640937409384093940940409414094240943409444094540946409474094840949409504095140952409534095440955409564095740958409594096040961409624096340964409654096640967409684096940970409714097240973409744097540976409774097840979409804098140982409834098440985409864098740988409894099040991409924099340994409954099640997409984099941000410014100241003410044100541006410074100841009410104101141012410134101441015410164101741018410194102041021410224102341024410254102641027410284102941030410314103241033410344103541036410374103841039410404104141042410434104441045410464104741048410494105041051410524105341054410554105641057410584105941060410614106241063410644106541066410674106841069410704107141072410734107441075410764107741078410794108041081410824108341084410854108641087410884108941090410914109241093410944109541096410974109841099411004110141102411034110441105411064110741108411094111041111411124111341114411154111641117411184111941120411214112241123411244112541126411274112841129411304113141132411334113441135411364113741138411394114041141411424114341144411454114641147411484114941150411514115241153411544115541156411574115841159411604116141162411634116441165411664116741168411694117041171411724117341174411754117641177411784117941180411814118241183411844118541186411874118841189411904119141192411934119441195411964119741198411994120041201412024120341204412054120641207412084120941210412114121241213412144121541216412174121841219412204122141222412234122441225412264122741228412294123041231412324123341234412354123641237412384123941240412414124241243412444124541246412474124841249412504125141252412534125441255412564125741258412594126041261412624126341264412654126641267412684126941270412714127241273412744127541276412774127841279412804128141282412834128441285412864128741288412894129041291412924129341294412954129641297412984129941300413014130241303413044130541306413074130841309413104131141312413134131441315413164131741318413194132041321413224132341324413254132641327413284132941330413314133241333413344133541336413374133841339413404134141342413434134441345413464134741348413494135041351413524135341354413554135641357413584135941360413614136241363413644136541366413674136841369413704137141372413734137441375413764137741378413794138041381413824138341384413854138641387413884138941390413914139241393413944139541396413974139841399414004140141402414034140441405414064140741408414094141041411414124141341414414154141641417414184141941420414214142241423414244142541426414274142841429414304143141432414334143441435414364143741438414394144041441414424144341444414454144641447414484144941450414514145241453414544145541456414574145841459414604146141462414634146441465414664146741468414694147041471414724147341474414754147641477414784147941480414814148241483414844148541486414874148841489414904149141492414934149441495414964149741498414994150041501415024150341504415054150641507415084150941510415114151241513415144151541516415174151841519415204152141522415234152441525415264152741528415294153041531415324153341534415354153641537415384153941540415414154241543415444154541546415474154841549415504155141552415534155441555415564155741558415594156041561415624156341564415654156641567415684156941570415714157241573415744157541576415774157841579415804158141582415834158441585415864158741588415894159041591415924159341594415954159641597415984159941600416014160241603416044160541606416074160841609416104161141612416134161441615416164161741618416194162041621416224162341624416254162641627416284162941630416314163241633416344163541636416374163841639416404164141642416434164441645416464164741648416494165041651416524165341654416554165641657416584165941660416614166241663416644166541666416674166841669416704167141672416734167441675416764167741678416794168041681416824168341684416854168641687416884168941690416914169241693416944169541696416974169841699417004170141702417034170441705417064170741708417094171041711417124171341714417154171641717417184171941720417214172241723417244172541726417274172841729417304173141732417334173441735417364173741738417394174041741417424174341744417454174641747417484174941750417514175241753417544175541756417574175841759417604176141762417634176441765417664176741768417694177041771417724177341774417754177641777417784177941780417814178241783417844178541786417874178841789417904179141792417934179441795417964179741798417994180041801418024180341804418054180641807418084180941810418114181241813418144181541816418174181841819418204182141822418234182441825418264182741828418294183041831418324183341834418354183641837418384183941840418414184241843418444184541846418474184841849418504185141852418534185441855418564185741858418594186041861418624186341864418654186641867418684186941870418714187241873418744187541876418774187841879418804188141882418834188441885418864188741888418894189041891418924189341894418954189641897418984189941900419014190241903419044190541906419074190841909419104191141912419134191441915419164191741918419194192041921419224192341924419254192641927419284192941930419314193241933419344193541936419374193841939419404194141942419434194441945419464194741948419494195041951419524195341954419554195641957419584195941960419614196241963419644196541966419674196841969419704197141972419734197441975419764197741978419794198041981419824198341984419854198641987419884198941990419914199241993419944199541996419974199841999420004200142002420034200442005420064200742008420094201042011420124201342014420154201642017420184201942020420214202242023420244202542026420274202842029420304203142032420334203442035420364203742038420394204042041420424204342044420454204642047420484204942050420514205242053420544205542056420574205842059420604206142062420634206442065420664206742068420694207042071420724207342074420754207642077420784207942080420814208242083420844208542086420874208842089420904209142092420934209442095420964209742098420994210042101421024210342104421054210642107421084210942110421114211242113421144211542116421174211842119421204212142122421234212442125421264212742128421294213042131421324213342134421354213642137421384213942140421414214242143421444214542146421474214842149421504215142152421534215442155421564215742158421594216042161421624216342164421654216642167421684216942170421714217242173421744217542176421774217842179421804218142182421834218442185421864218742188421894219042191421924219342194421954219642197421984219942200422014220242203422044220542206422074220842209422104221142212422134221442215422164221742218422194222042221422224222342224422254222642227422284222942230422314223242233422344223542236422374223842239422404224142242422434224442245422464224742248422494225042251422524225342254422554225642257422584225942260422614226242263422644226542266422674226842269422704227142272422734227442275422764227742278422794228042281422824228342284422854228642287422884228942290422914229242293422944229542296422974229842299423004230142302423034230442305423064230742308423094231042311423124231342314423154231642317423184231942320423214232242323423244232542326423274232842329423304233142332423334233442335423364233742338423394234042341423424234342344423454234642347423484234942350423514235242353423544235542356423574235842359423604236142362423634236442365423664236742368423694237042371423724237342374423754237642377423784237942380423814238242383423844238542386423874238842389423904239142392423934239442395423964239742398423994240042401424024240342404424054240642407424084240942410424114241242413424144241542416424174241842419424204242142422424234242442425424264242742428424294243042431424324243342434424354243642437424384243942440424414244242443424444244542446424474244842449424504245142452424534245442455424564245742458424594246042461424624246342464424654246642467424684246942470424714247242473424744247542476424774247842479424804248142482424834248442485424864248742488424894249042491424924249342494424954249642497424984249942500425014250242503425044250542506425074250842509425104251142512425134251442515425164251742518425194252042521425224252342524425254252642527425284252942530425314253242533425344253542536425374253842539425404254142542425434254442545425464254742548425494255042551425524255342554425554255642557425584255942560425614256242563425644256542566425674256842569425704257142572425734257442575425764257742578425794258042581425824258342584425854258642587425884258942590425914259242593425944259542596425974259842599426004260142602426034260442605426064260742608426094261042611426124261342614426154261642617426184261942620
  1. /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
  3. /* Copyright 2012 Mozilla Foundation
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. /*jshint globalstrict: false */
  18. /* globals PDFJS */
  19. // Initializing PDFJS global object (if still undefined)
  20. if (typeof PDFJS === 'undefined') {
  21. (typeof window !== 'undefined' ? window : this).PDFJS = {};
  22. }
  23. PDFJS.version = '1.0.627';
  24. PDFJS.build = '99b08ed';
  25. (function pdfjsWrapper() {
  26. // Use strict in our context only - users might not want it
  27. 'use strict';
  28. /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  29. /* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
  30. /* Copyright 2012 Mozilla Foundation
  31. *
  32. * Licensed under the Apache License, Version 2.0 (the "License");
  33. * you may not use this file except in compliance with the License.
  34. * You may obtain a copy of the License at
  35. *
  36. * http://www.apache.org/licenses/LICENSE-2.0
  37. *
  38. * Unless required by applicable law or agreed to in writing, software
  39. * distributed under the License is distributed on an "AS IS" BASIS,
  40. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  41. * See the License for the specific language governing permissions and
  42. * limitations under the License.
  43. */
  44. /* globals Cmd, ColorSpace, Dict, MozBlobBuilder, Name, PDFJS, Ref, URL,
  45. Promise */
  46. 'use strict';
  47. var globalScope = (typeof window === 'undefined') ? this : window;
  48. var isWorker = (typeof window === 'undefined');
  49. var FONT_IDENTITY_MATRIX = [0.001, 0, 0, 0.001, 0, 0];
  50. var TextRenderingMode = {
  51. FILL: 0,
  52. STROKE: 1,
  53. FILL_STROKE: 2,
  54. INVISIBLE: 3,
  55. FILL_ADD_TO_PATH: 4,
  56. STROKE_ADD_TO_PATH: 5,
  57. FILL_STROKE_ADD_TO_PATH: 6,
  58. ADD_TO_PATH: 7,
  59. FILL_STROKE_MASK: 3,
  60. ADD_TO_PATH_FLAG: 4
  61. };
  62. var ImageKind = {
  63. GRAYSCALE_1BPP: 1,
  64. RGB_24BPP: 2,
  65. RGBA_32BPP: 3
  66. };
  67. var AnnotationType = {
  68. WIDGET: 1,
  69. TEXT: 2,
  70. LINK: 3
  71. };
  72. var StreamType = {
  73. UNKNOWN: 0,
  74. FLATE: 1,
  75. LZW: 2,
  76. DCT: 3,
  77. JPX: 4,
  78. JBIG: 5,
  79. A85: 6,
  80. AHX: 7,
  81. CCF: 8,
  82. RL: 9
  83. };
  84. var FontType = {
  85. UNKNOWN: 0,
  86. TYPE1: 1,
  87. TYPE1C: 2,
  88. CIDFONTTYPE0: 3,
  89. CIDFONTTYPE0C: 4,
  90. TRUETYPE: 5,
  91. CIDFONTTYPE2: 6,
  92. TYPE3: 7,
  93. OPENTYPE: 8,
  94. TYPE0: 9,
  95. MMTYPE1: 10
  96. };
  97. // The global PDFJS object exposes the API
  98. // In production, it will be declared outside a global wrapper
  99. // In development, it will be declared here
  100. if (!globalScope.PDFJS) {
  101. globalScope.PDFJS = {};
  102. }
  103. globalScope.PDFJS.pdfBug = false;
  104. PDFJS.VERBOSITY_LEVELS = {
  105. errors: 0,
  106. warnings: 1,
  107. infos: 5
  108. };
  109. // All the possible operations for an operator list.
  110. var OPS = PDFJS.OPS = {
  111. // Intentionally start from 1 so it is easy to spot bad operators that will be
  112. // 0's.
  113. dependency: 1,
  114. setLineWidth: 2,
  115. setLineCap: 3,
  116. setLineJoin: 4,
  117. setMiterLimit: 5,
  118. setDash: 6,
  119. setRenderingIntent: 7,
  120. setFlatness: 8,
  121. setGState: 9,
  122. save: 10,
  123. restore: 11,
  124. transform: 12,
  125. moveTo: 13,
  126. lineTo: 14,
  127. curveTo: 15,
  128. curveTo2: 16,
  129. curveTo3: 17,
  130. closePath: 18,
  131. rectangle: 19,
  132. stroke: 20,
  133. closeStroke: 21,
  134. fill: 22,
  135. eoFill: 23,
  136. fillStroke: 24,
  137. eoFillStroke: 25,
  138. closeFillStroke: 26,
  139. closeEOFillStroke: 27,
  140. endPath: 28,
  141. clip: 29,
  142. eoClip: 30,
  143. beginText: 31,
  144. endText: 32,
  145. setCharSpacing: 33,
  146. setWordSpacing: 34,
  147. setHScale: 35,
  148. setLeading: 36,
  149. setFont: 37,
  150. setTextRenderingMode: 38,
  151. setTextRise: 39,
  152. moveText: 40,
  153. setLeadingMoveText: 41,
  154. setTextMatrix: 42,
  155. nextLine: 43,
  156. showText: 44,
  157. showSpacedText: 45,
  158. nextLineShowText: 46,
  159. nextLineSetSpacingShowText: 47,
  160. setCharWidth: 48,
  161. setCharWidthAndBounds: 49,
  162. setStrokeColorSpace: 50,
  163. setFillColorSpace: 51,
  164. setStrokeColor: 52,
  165. setStrokeColorN: 53,
  166. setFillColor: 54,
  167. setFillColorN: 55,
  168. setStrokeGray: 56,
  169. setFillGray: 57,
  170. setStrokeRGBColor: 58,
  171. setFillRGBColor: 59,
  172. setStrokeCMYKColor: 60,
  173. setFillCMYKColor: 61,
  174. shadingFill: 62,
  175. beginInlineImage: 63,
  176. beginImageData: 64,
  177. endInlineImage: 65,
  178. paintXObject: 66,
  179. markPoint: 67,
  180. markPointProps: 68,
  181. beginMarkedContent: 69,
  182. beginMarkedContentProps: 70,
  183. endMarkedContent: 71,
  184. beginCompat: 72,
  185. endCompat: 73,
  186. paintFormXObjectBegin: 74,
  187. paintFormXObjectEnd: 75,
  188. beginGroup: 76,
  189. endGroup: 77,
  190. beginAnnotations: 78,
  191. endAnnotations: 79,
  192. beginAnnotation: 80,
  193. endAnnotation: 81,
  194. paintJpegXObject: 82,
  195. paintImageMaskXObject: 83,
  196. paintImageMaskXObjectGroup: 84,
  197. paintImageXObject: 85,
  198. paintInlineImageXObject: 86,
  199. paintInlineImageXObjectGroup: 87,
  200. paintImageXObjectRepeat: 88,
  201. paintImageMaskXObjectRepeat: 89,
  202. paintSolidColorImageMask: 90,
  203. constructPath: 91
  204. };
  205. // A notice for devs. These are good for things that are helpful to devs, such
  206. // as warning that Workers were disabled, which is important to devs but not
  207. // end users.
  208. function info(msg) {
  209. if (PDFJS.verbosity >= PDFJS.VERBOSITY_LEVELS.infos) {
  210. console.log('Info: ' + msg);
  211. }
  212. }
  213. // Non-fatal warnings.
  214. function warn(msg) {
  215. if (PDFJS.verbosity >= PDFJS.VERBOSITY_LEVELS.warnings) {
  216. console.log('Warning: ' + msg);
  217. }
  218. }
  219. // Fatal errors that should trigger the fallback UI and halt execution by
  220. // throwing an exception.
  221. function error(msg) {
  222. // If multiple arguments were passed, pass them all to the log function.
  223. if (arguments.length > 1) {
  224. var logArguments = ['Error:'];
  225. logArguments.push.apply(logArguments, arguments);
  226. console.log.apply(console, logArguments);
  227. // Join the arguments into a single string for the lines below.
  228. msg = [].join.call(arguments, ' ');
  229. } else {
  230. console.log('Error: ' + msg);
  231. }
  232. console.log(backtrace());
  233. UnsupportedManager.notify(UNSUPPORTED_FEATURES.unknown);
  234. throw new Error(msg);
  235. }
  236. function backtrace() {
  237. try {
  238. throw new Error();
  239. } catch (e) {
  240. return e.stack ? e.stack.split('\n').slice(2).join('\n') : '';
  241. }
  242. }
  243. function assert(cond, msg) {
  244. if (!cond) {
  245. error(msg);
  246. }
  247. }
  248. var UNSUPPORTED_FEATURES = PDFJS.UNSUPPORTED_FEATURES = {
  249. unknown: 'unknown',
  250. forms: 'forms',
  251. javaScript: 'javaScript',
  252. smask: 'smask',
  253. shadingPattern: 'shadingPattern',
  254. font: 'font'
  255. };
  256. var UnsupportedManager = PDFJS.UnsupportedManager =
  257. (function UnsupportedManagerClosure() {
  258. var listeners = [];
  259. return {
  260. listen: function (cb) {
  261. listeners.push(cb);
  262. },
  263. notify: function (featureId) {
  264. warn('Unsupported feature "' + featureId + '"');
  265. for (var i = 0, ii = listeners.length; i < ii; i++) {
  266. listeners[i](featureId);
  267. }
  268. }
  269. };
  270. })();
  271. // Combines two URLs. The baseUrl shall be absolute URL. If the url is an
  272. // absolute URL, it will be returned as is.
  273. function combineUrl(baseUrl, url) {
  274. if (!url) {
  275. return baseUrl;
  276. }
  277. if (/^[a-z][a-z0-9+\-.]*:/i.test(url)) {
  278. return url;
  279. }
  280. var i;
  281. if (url.charAt(0) === '/') {
  282. // absolute path
  283. i = baseUrl.indexOf('://');
  284. if (url.charAt(1) === '/') {
  285. ++i;
  286. } else {
  287. i = baseUrl.indexOf('/', i + 3);
  288. }
  289. return baseUrl.substring(0, i) + url;
  290. } else {
  291. // relative path
  292. var pathLength = baseUrl.length;
  293. i = baseUrl.lastIndexOf('#');
  294. pathLength = i >= 0 ? i : pathLength;
  295. i = baseUrl.lastIndexOf('?', pathLength);
  296. pathLength = i >= 0 ? i : pathLength;
  297. var prefixLength = baseUrl.lastIndexOf('/', pathLength);
  298. return baseUrl.substring(0, prefixLength + 1) + url;
  299. }
  300. }
  301. // Validates if URL is safe and allowed, e.g. to avoid XSS.
  302. function isValidUrl(url, allowRelative) {
  303. if (!url) {
  304. return false;
  305. }
  306. // RFC 3986 (http://tools.ietf.org/html/rfc3986#section-3.1)
  307. // scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
  308. var protocol = /^[a-z][a-z0-9+\-.]*(?=:)/i.exec(url);
  309. if (!protocol) {
  310. return allowRelative;
  311. }
  312. protocol = protocol[0].toLowerCase();
  313. switch (protocol) {
  314. case 'http':
  315. case 'https':
  316. case 'ftp':
  317. case 'mailto':
  318. return true;
  319. default:
  320. return false;
  321. }
  322. }
  323. PDFJS.isValidUrl = isValidUrl;
  324. function shadow(obj, prop, value) {
  325. Object.defineProperty(obj, prop, { value: value,
  326. enumerable: true,
  327. configurable: true,
  328. writable: false });
  329. return value;
  330. }
  331. var PasswordResponses = PDFJS.PasswordResponses = {
  332. NEED_PASSWORD: 1,
  333. INCORRECT_PASSWORD: 2
  334. };
  335. var PasswordException = (function PasswordExceptionClosure() {
  336. function PasswordException(msg, code) {
  337. this.name = 'PasswordException';
  338. this.message = msg;
  339. this.code = code;
  340. }
  341. PasswordException.prototype = new Error();
  342. PasswordException.constructor = PasswordException;
  343. return PasswordException;
  344. })();
  345. var UnknownErrorException = (function UnknownErrorExceptionClosure() {
  346. function UnknownErrorException(msg, details) {
  347. this.name = 'UnknownErrorException';
  348. this.message = msg;
  349. this.details = details;
  350. }
  351. UnknownErrorException.prototype = new Error();
  352. UnknownErrorException.constructor = UnknownErrorException;
  353. return UnknownErrorException;
  354. })();
  355. var InvalidPDFException = (function InvalidPDFExceptionClosure() {
  356. function InvalidPDFException(msg) {
  357. this.name = 'InvalidPDFException';
  358. this.message = msg;
  359. }
  360. InvalidPDFException.prototype = new Error();
  361. InvalidPDFException.constructor = InvalidPDFException;
  362. return InvalidPDFException;
  363. })();
  364. var MissingPDFException = (function MissingPDFExceptionClosure() {
  365. function MissingPDFException(msg) {
  366. this.name = 'MissingPDFException';
  367. this.message = msg;
  368. }
  369. MissingPDFException.prototype = new Error();
  370. MissingPDFException.constructor = MissingPDFException;
  371. return MissingPDFException;
  372. })();
  373. var NotImplementedException = (function NotImplementedExceptionClosure() {
  374. function NotImplementedException(msg) {
  375. this.message = msg;
  376. }
  377. NotImplementedException.prototype = new Error();
  378. NotImplementedException.prototype.name = 'NotImplementedException';
  379. NotImplementedException.constructor = NotImplementedException;
  380. return NotImplementedException;
  381. })();
  382. var MissingDataException = (function MissingDataExceptionClosure() {
  383. function MissingDataException(begin, end) {
  384. this.begin = begin;
  385. this.end = end;
  386. this.message = 'Missing data [' + begin + ', ' + end + ')';
  387. }
  388. MissingDataException.prototype = new Error();
  389. MissingDataException.prototype.name = 'MissingDataException';
  390. MissingDataException.constructor = MissingDataException;
  391. return MissingDataException;
  392. })();
  393. var XRefParseException = (function XRefParseExceptionClosure() {
  394. function XRefParseException(msg) {
  395. this.message = msg;
  396. }
  397. XRefParseException.prototype = new Error();
  398. XRefParseException.prototype.name = 'XRefParseException';
  399. XRefParseException.constructor = XRefParseException;
  400. return XRefParseException;
  401. })();
  402. function bytesToString(bytes) {
  403. var length = bytes.length;
  404. var MAX_ARGUMENT_COUNT = 8192;
  405. if (length < MAX_ARGUMENT_COUNT) {
  406. return String.fromCharCode.apply(null, bytes);
  407. }
  408. var strBuf = [];
  409. for (var i = 0; i < length; i += MAX_ARGUMENT_COUNT) {
  410. var chunkEnd = Math.min(i + MAX_ARGUMENT_COUNT, length);
  411. var chunk = bytes.subarray(i, chunkEnd);
  412. strBuf.push(String.fromCharCode.apply(null, chunk));
  413. }
  414. return strBuf.join('');
  415. }
  416. function stringToArray(str) {
  417. var length = str.length;
  418. var array = new Uint16Array(length);
  419. for (var i = 0; i < length; ++i) {
  420. array[i] = str.charCodeAt(i);
  421. }
  422. return array;
  423. }
  424. function stringToBytes(str) {
  425. var length = str.length;
  426. var bytes = new Uint8Array(length);
  427. for (var i = 0; i < length; ++i) {
  428. bytes[i] = str.charCodeAt(i) & 0xFF;
  429. }
  430. return bytes;
  431. }
  432. function string32(value) {
  433. return String.fromCharCode((value >> 24) & 0xff, (value >> 16) & 0xff,
  434. (value >> 8) & 0xff, value & 0xff);
  435. }
  436. function log2(x) {
  437. var n = 1, i = 0;
  438. while (x > n) {
  439. n <<= 1;
  440. i++;
  441. }
  442. return i;
  443. }
  444. function readInt8(data, start) {
  445. return (data[start] << 24) >> 24;
  446. }
  447. function readUint16(data, offset) {
  448. return (data[offset] << 8) | data[offset + 1];
  449. }
  450. function readUint32(data, offset) {
  451. return ((data[offset] << 24) | (data[offset + 1] << 16) |
  452. (data[offset + 2] << 8) | data[offset + 3]) >>> 0;
  453. }
  454. // Lazy test the endianness of the platform
  455. // NOTE: This will be 'true' for simulated TypedArrays
  456. function isLittleEndian() {
  457. var buffer8 = new Uint8Array(2);
  458. buffer8[0] = 1;
  459. var buffer16 = new Uint16Array(buffer8.buffer);
  460. return (buffer16[0] === 1);
  461. }
  462. Object.defineProperty(PDFJS, 'isLittleEndian', {
  463. configurable: true,
  464. get: function PDFJS_isLittleEndian() {
  465. return shadow(PDFJS, 'isLittleEndian', isLittleEndian());
  466. }
  467. });
  468. // Lazy test if the userAgant support CanvasTypedArrays
  469. function hasCanvasTypedArrays() {
  470. var canvas = document.createElement('canvas');
  471. canvas.width = canvas.height = 1;
  472. var ctx = canvas.getContext('2d');
  473. var imageData = ctx.createImageData(1, 1);
  474. return (typeof imageData.data.buffer !== 'undefined');
  475. }
  476. Object.defineProperty(PDFJS, 'hasCanvasTypedArrays', {
  477. configurable: true,
  478. get: function PDFJS_hasCanvasTypedArrays() {
  479. return shadow(PDFJS, 'hasCanvasTypedArrays', hasCanvasTypedArrays());
  480. }
  481. });
  482. var Uint32ArrayView = (function Uint32ArrayViewClosure() {
  483. function Uint32ArrayView(buffer, length) {
  484. this.buffer = buffer;
  485. this.byteLength = buffer.length;
  486. this.length = length === undefined ? (this.byteLength >> 2) : length;
  487. ensureUint32ArrayViewProps(this.length);
  488. }
  489. Uint32ArrayView.prototype = Object.create(null);
  490. var uint32ArrayViewSetters = 0;
  491. function createUint32ArrayProp(index) {
  492. return {
  493. get: function () {
  494. var buffer = this.buffer, offset = index << 2;
  495. return (buffer[offset] | (buffer[offset + 1] << 8) |
  496. (buffer[offset + 2] << 16) | (buffer[offset + 3] << 24)) >>> 0;
  497. },
  498. set: function (value) {
  499. var buffer = this.buffer, offset = index << 2;
  500. buffer[offset] = value & 255;
  501. buffer[offset + 1] = (value >> 8) & 255;
  502. buffer[offset + 2] = (value >> 16) & 255;
  503. buffer[offset + 3] = (value >>> 24) & 255;
  504. }
  505. };
  506. }
  507. function ensureUint32ArrayViewProps(length) {
  508. while (uint32ArrayViewSetters < length) {
  509. Object.defineProperty(Uint32ArrayView.prototype,
  510. uint32ArrayViewSetters,
  511. createUint32ArrayProp(uint32ArrayViewSetters));
  512. uint32ArrayViewSetters++;
  513. }
  514. }
  515. return Uint32ArrayView;
  516. })();
  517. var IDENTITY_MATRIX = [1, 0, 0, 1, 0, 0];
  518. var Util = PDFJS.Util = (function UtilClosure() {
  519. function Util() {}
  520. var rgbBuf = ['rgb(', 0, ',', 0, ',', 0, ')'];
  521. // makeCssRgb() can be called thousands of times. Using |rgbBuf| avoids
  522. // creating many intermediate strings.
  523. Util.makeCssRgb = function Util_makeCssRgb(rgb) {
  524. rgbBuf[1] = rgb[0];
  525. rgbBuf[3] = rgb[1];
  526. rgbBuf[5] = rgb[2];
  527. return rgbBuf.join('');
  528. };
  529. // Concatenates two transformation matrices together and returns the result.
  530. Util.transform = function Util_transform(m1, m2) {
  531. return [
  532. m1[0] * m2[0] + m1[2] * m2[1],
  533. m1[1] * m2[0] + m1[3] * m2[1],
  534. m1[0] * m2[2] + m1[2] * m2[3],
  535. m1[1] * m2[2] + m1[3] * m2[3],
  536. m1[0] * m2[4] + m1[2] * m2[5] + m1[4],
  537. m1[1] * m2[4] + m1[3] * m2[5] + m1[5]
  538. ];
  539. };
  540. // For 2d affine transforms
  541. Util.applyTransform = function Util_applyTransform(p, m) {
  542. var xt = p[0] * m[0] + p[1] * m[2] + m[4];
  543. var yt = p[0] * m[1] + p[1] * m[3] + m[5];
  544. return [xt, yt];
  545. };
  546. Util.applyInverseTransform = function Util_applyInverseTransform(p, m) {
  547. var d = m[0] * m[3] - m[1] * m[2];
  548. var xt = (p[0] * m[3] - p[1] * m[2] + m[2] * m[5] - m[4] * m[3]) / d;
  549. var yt = (-p[0] * m[1] + p[1] * m[0] + m[4] * m[1] - m[5] * m[0]) / d;
  550. return [xt, yt];
  551. };
  552. // Applies the transform to the rectangle and finds the minimum axially
  553. // aligned bounding box.
  554. Util.getAxialAlignedBoundingBox =
  555. function Util_getAxialAlignedBoundingBox(r, m) {
  556. var p1 = Util.applyTransform(r, m);
  557. var p2 = Util.applyTransform(r.slice(2, 4), m);
  558. var p3 = Util.applyTransform([r[0], r[3]], m);
  559. var p4 = Util.applyTransform([r[2], r[1]], m);
  560. return [
  561. Math.min(p1[0], p2[0], p3[0], p4[0]),
  562. Math.min(p1[1], p2[1], p3[1], p4[1]),
  563. Math.max(p1[0], p2[0], p3[0], p4[0]),
  564. Math.max(p1[1], p2[1], p3[1], p4[1])
  565. ];
  566. };
  567. Util.inverseTransform = function Util_inverseTransform(m) {
  568. var d = m[0] * m[3] - m[1] * m[2];
  569. return [m[3] / d, -m[1] / d, -m[2] / d, m[0] / d,
  570. (m[2] * m[5] - m[4] * m[3]) / d, (m[4] * m[1] - m[5] * m[0]) / d];
  571. };
  572. // Apply a generic 3d matrix M on a 3-vector v:
  573. // | a b c | | X |
  574. // | d e f | x | Y |
  575. // | g h i | | Z |
  576. // M is assumed to be serialized as [a,b,c,d,e,f,g,h,i],
  577. // with v as [X,Y,Z]
  578. Util.apply3dTransform = function Util_apply3dTransform(m, v) {
  579. return [
  580. m[0] * v[0] + m[1] * v[1] + m[2] * v[2],
  581. m[3] * v[0] + m[4] * v[1] + m[5] * v[2],
  582. m[6] * v[0] + m[7] * v[1] + m[8] * v[2]
  583. ];
  584. };
  585. // This calculation uses Singular Value Decomposition.
  586. // The SVD can be represented with formula A = USV. We are interested in the
  587. // matrix S here because it represents the scale values.
  588. Util.singularValueDecompose2dScale =
  589. function Util_singularValueDecompose2dScale(m) {
  590. var transpose = [m[0], m[2], m[1], m[3]];
  591. // Multiply matrix m with its transpose.
  592. var a = m[0] * transpose[0] + m[1] * transpose[2];
  593. var b = m[0] * transpose[1] + m[1] * transpose[3];
  594. var c = m[2] * transpose[0] + m[3] * transpose[2];
  595. var d = m[2] * transpose[1] + m[3] * transpose[3];
  596. // Solve the second degree polynomial to get roots.
  597. var first = (a + d) / 2;
  598. var second = Math.sqrt((a + d) * (a + d) - 4 * (a * d - c * b)) / 2;
  599. var sx = first + second || 1;
  600. var sy = first - second || 1;
  601. // Scale values are the square roots of the eigenvalues.
  602. return [Math.sqrt(sx), Math.sqrt(sy)];
  603. };
  604. // Normalize rectangle rect=[x1, y1, x2, y2] so that (x1,y1) < (x2,y2)
  605. // For coordinate systems whose origin lies in the bottom-left, this
  606. // means normalization to (BL,TR) ordering. For systems with origin in the
  607. // top-left, this means (TL,BR) ordering.
  608. Util.normalizeRect = function Util_normalizeRect(rect) {
  609. var r = rect.slice(0); // clone rect
  610. if (rect[0] > rect[2]) {
  611. r[0] = rect[2];
  612. r[2] = rect[0];
  613. }
  614. if (rect[1] > rect[3]) {
  615. r[1] = rect[3];
  616. r[3] = rect[1];
  617. }
  618. return r;
  619. };
  620. // Returns a rectangle [x1, y1, x2, y2] corresponding to the
  621. // intersection of rect1 and rect2. If no intersection, returns 'false'
  622. // The rectangle coordinates of rect1, rect2 should be [x1, y1, x2, y2]
  623. Util.intersect = function Util_intersect(rect1, rect2) {
  624. function compare(a, b) {
  625. return a - b;
  626. }
  627. // Order points along the axes
  628. var orderedX = [rect1[0], rect1[2], rect2[0], rect2[2]].sort(compare),
  629. orderedY = [rect1[1], rect1[3], rect2[1], rect2[3]].sort(compare),
  630. result = [];
  631. rect1 = Util.normalizeRect(rect1);
  632. rect2 = Util.normalizeRect(rect2);
  633. // X: first and second points belong to different rectangles?
  634. if ((orderedX[0] === rect1[0] && orderedX[1] === rect2[0]) ||
  635. (orderedX[0] === rect2[0] && orderedX[1] === rect1[0])) {
  636. // Intersection must be between second and third points
  637. result[0] = orderedX[1];
  638. result[2] = orderedX[2];
  639. } else {
  640. return false;
  641. }
  642. // Y: first and second points belong to different rectangles?
  643. if ((orderedY[0] === rect1[1] && orderedY[1] === rect2[1]) ||
  644. (orderedY[0] === rect2[1] && orderedY[1] === rect1[1])) {
  645. // Intersection must be between second and third points
  646. result[1] = orderedY[1];
  647. result[3] = orderedY[2];
  648. } else {
  649. return false;
  650. }
  651. return result;
  652. };
  653. Util.sign = function Util_sign(num) {
  654. return num < 0 ? -1 : 1;
  655. };
  656. Util.appendToArray = function Util_appendToArray(arr1, arr2) {
  657. Array.prototype.push.apply(arr1, arr2);
  658. };
  659. Util.prependToArray = function Util_prependToArray(arr1, arr2) {
  660. Array.prototype.unshift.apply(arr1, arr2);
  661. };
  662. Util.extendObj = function extendObj(obj1, obj2) {
  663. for (var key in obj2) {
  664. obj1[key] = obj2[key];
  665. }
  666. };
  667. Util.getInheritableProperty = function Util_getInheritableProperty(dict,
  668. name) {
  669. while (dict && !dict.has(name)) {
  670. dict = dict.get('Parent');
  671. }
  672. if (!dict) {
  673. return null;
  674. }
  675. return dict.get(name);
  676. };
  677. Util.inherit = function Util_inherit(sub, base, prototype) {
  678. sub.prototype = Object.create(base.prototype);
  679. sub.prototype.constructor = sub;
  680. for (var prop in prototype) {
  681. sub.prototype[prop] = prototype[prop];
  682. }
  683. };
  684. Util.loadScript = function Util_loadScript(src, callback) {
  685. var script = document.createElement('script');
  686. var loaded = false;
  687. script.setAttribute('src', src);
  688. if (callback) {
  689. script.onload = function() {
  690. if (!loaded) {
  691. callback();
  692. }
  693. loaded = true;
  694. };
  695. }
  696. document.getElementsByTagName('head')[0].appendChild(script);
  697. };
  698. return Util;
  699. })();
  700. /**
  701. * PDF page viewport created based on scale, rotation and offset.
  702. * @class
  703. * @alias PDFJS.PageViewport
  704. */
  705. var PageViewport = PDFJS.PageViewport = (function PageViewportClosure() {
  706. /**
  707. * @constructor
  708. * @private
  709. * @param viewBox {Array} xMin, yMin, xMax and yMax coordinates.
  710. * @param scale {number} scale of the viewport.
  711. * @param rotation {number} rotations of the viewport in degrees.
  712. * @param offsetX {number} offset X
  713. * @param offsetY {number} offset Y
  714. * @param dontFlip {boolean} if true, axis Y will not be flipped.
  715. */
  716. function PageViewport(viewBox, scale, rotation, offsetX, offsetY, dontFlip) {
  717. this.viewBox = viewBox;
  718. this.scale = scale;
  719. this.rotation = rotation;
  720. this.offsetX = offsetX;
  721. this.offsetY = offsetY;
  722. // creating transform to convert pdf coordinate system to the normal
  723. // canvas like coordinates taking in account scale and rotation
  724. var centerX = (viewBox[2] + viewBox[0]) / 2;
  725. var centerY = (viewBox[3] + viewBox[1]) / 2;
  726. var rotateA, rotateB, rotateC, rotateD;
  727. rotation = rotation % 360;
  728. rotation = rotation < 0 ? rotation + 360 : rotation;
  729. switch (rotation) {
  730. case 180:
  731. rotateA = -1; rotateB = 0; rotateC = 0; rotateD = 1;
  732. break;
  733. case 90:
  734. rotateA = 0; rotateB = 1; rotateC = 1; rotateD = 0;
  735. break;
  736. case 270:
  737. rotateA = 0; rotateB = -1; rotateC = -1; rotateD = 0;
  738. break;
  739. //case 0:
  740. default:
  741. rotateA = 1; rotateB = 0; rotateC = 0; rotateD = -1;
  742. break;
  743. }
  744. if (dontFlip) {
  745. rotateC = -rotateC; rotateD = -rotateD;
  746. }
  747. var offsetCanvasX, offsetCanvasY;
  748. var width, height;
  749. if (rotateA === 0) {
  750. offsetCanvasX = Math.abs(centerY - viewBox[1]) * scale + offsetX;
  751. offsetCanvasY = Math.abs(centerX - viewBox[0]) * scale + offsetY;
  752. width = Math.abs(viewBox[3] - viewBox[1]) * scale;
  753. height = Math.abs(viewBox[2] - viewBox[0]) * scale;
  754. } else {
  755. offsetCanvasX = Math.abs(centerX - viewBox[0]) * scale + offsetX;
  756. offsetCanvasY = Math.abs(centerY - viewBox[1]) * scale + offsetY;
  757. width = Math.abs(viewBox[2] - viewBox[0]) * scale;
  758. height = Math.abs(viewBox[3] - viewBox[1]) * scale;
  759. }
  760. // creating transform for the following operations:
  761. // translate(-centerX, -centerY), rotate and flip vertically,
  762. // scale, and translate(offsetCanvasX, offsetCanvasY)
  763. this.transform = [
  764. rotateA * scale,
  765. rotateB * scale,
  766. rotateC * scale,
  767. rotateD * scale,
  768. offsetCanvasX - rotateA * scale * centerX - rotateC * scale * centerY,
  769. offsetCanvasY - rotateB * scale * centerX - rotateD * scale * centerY
  770. ];
  771. this.width = width;
  772. this.height = height;
  773. this.fontScale = scale;
  774. }
  775. PageViewport.prototype = /** @lends PDFJS.PageViewport.prototype */ {
  776. /**
  777. * Clones viewport with additional properties.
  778. * @param args {Object} (optional) If specified, may contain the 'scale' or
  779. * 'rotation' properties to override the corresponding properties in
  780. * the cloned viewport.
  781. * @returns {PDFJS.PageViewport} Cloned viewport.
  782. */
  783. clone: function PageViewPort_clone(args) {
  784. args = args || {};
  785. var scale = 'scale' in args ? args.scale : this.scale;
  786. var rotation = 'rotation' in args ? args.rotation : this.rotation;
  787. return new PageViewport(this.viewBox.slice(), scale, rotation,
  788. this.offsetX, this.offsetY, args.dontFlip);
  789. },
  790. /**
  791. * Converts PDF point to the viewport coordinates. For examples, useful for
  792. * converting PDF location into canvas pixel coordinates.
  793. * @param x {number} X coordinate.
  794. * @param y {number} Y coordinate.
  795. * @returns {Object} Object that contains 'x' and 'y' properties of the
  796. * point in the viewport coordinate space.
  797. * @see {@link convertToPdfPoint}
  798. * @see {@link convertToViewportRectangle}
  799. */
  800. convertToViewportPoint: function PageViewport_convertToViewportPoint(x, y) {
  801. return Util.applyTransform([x, y], this.transform);
  802. },
  803. /**
  804. * Converts PDF rectangle to the viewport coordinates.
  805. * @param rect {Array} xMin, yMin, xMax and yMax coordinates.
  806. * @returns {Array} Contains corresponding coordinates of the rectangle
  807. * in the viewport coordinate space.
  808. * @see {@link convertToViewportPoint}
  809. */
  810. convertToViewportRectangle:
  811. function PageViewport_convertToViewportRectangle(rect) {
  812. var tl = Util.applyTransform([rect[0], rect[1]], this.transform);
  813. var br = Util.applyTransform([rect[2], rect[3]], this.transform);
  814. return [tl[0], tl[1], br[0], br[1]];
  815. },
  816. /**
  817. * Converts viewport coordinates to the PDF location. For examples, useful
  818. * for converting canvas pixel location into PDF one.
  819. * @param x {number} X coordinate.
  820. * @param y {number} Y coordinate.
  821. * @returns {Object} Object that contains 'x' and 'y' properties of the
  822. * point in the PDF coordinate space.
  823. * @see {@link convertToViewportPoint}
  824. */
  825. convertToPdfPoint: function PageViewport_convertToPdfPoint(x, y) {
  826. return Util.applyInverseTransform([x, y], this.transform);
  827. }
  828. };
  829. return PageViewport;
  830. })();
  831. var PDFStringTranslateTable = [
  832. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  833. 0x2D8, 0x2C7, 0x2C6, 0x2D9, 0x2DD, 0x2DB, 0x2DA, 0x2DC, 0, 0, 0, 0, 0, 0, 0,
  834. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  835. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  836. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  837. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x2022, 0x2020, 0x2021, 0x2026, 0x2014,
  838. 0x2013, 0x192, 0x2044, 0x2039, 0x203A, 0x2212, 0x2030, 0x201E, 0x201C,
  839. 0x201D, 0x2018, 0x2019, 0x201A, 0x2122, 0xFB01, 0xFB02, 0x141, 0x152, 0x160,
  840. 0x178, 0x17D, 0x131, 0x142, 0x153, 0x161, 0x17E, 0, 0x20AC
  841. ];
  842. function stringToPDFString(str) {
  843. var i, n = str.length, strBuf = [];
  844. if (str[0] === '\xFE' && str[1] === '\xFF') {
  845. // UTF16BE BOM
  846. for (i = 2; i < n; i += 2) {
  847. strBuf.push(String.fromCharCode(
  848. (str.charCodeAt(i) << 8) | str.charCodeAt(i + 1)));
  849. }
  850. } else {
  851. for (i = 0; i < n; ++i) {
  852. var code = PDFStringTranslateTable[str.charCodeAt(i)];
  853. strBuf.push(code ? String.fromCharCode(code) : str.charAt(i));
  854. }
  855. }
  856. return strBuf.join('');
  857. }
  858. function stringToUTF8String(str) {
  859. return decodeURIComponent(escape(str));
  860. }
  861. function isEmptyObj(obj) {
  862. for (var key in obj) {
  863. return false;
  864. }
  865. return true;
  866. }
  867. function isBool(v) {
  868. return typeof v === 'boolean';
  869. }
  870. function isInt(v) {
  871. return typeof v === 'number' && ((v | 0) === v);
  872. }
  873. function isNum(v) {
  874. return typeof v === 'number';
  875. }
  876. function isString(v) {
  877. return typeof v === 'string';
  878. }
  879. function isNull(v) {
  880. return v === null;
  881. }
  882. function isName(v) {
  883. return v instanceof Name;
  884. }
  885. function isCmd(v, cmd) {
  886. return v instanceof Cmd && (cmd === undefined || v.cmd === cmd);
  887. }
  888. function isDict(v, type) {
  889. if (!(v instanceof Dict)) {
  890. return false;
  891. }
  892. if (!type) {
  893. return true;
  894. }
  895. var dictType = v.get('Type');
  896. return isName(dictType) && dictType.name === type;
  897. }
  898. function isArray(v) {
  899. return v instanceof Array;
  900. }
  901. function isStream(v) {
  902. return typeof v === 'object' && v !== null && v.getBytes !== undefined;
  903. }
  904. function isArrayBuffer(v) {
  905. return typeof v === 'object' && v !== null && v.byteLength !== undefined;
  906. }
  907. function isRef(v) {
  908. return v instanceof Ref;
  909. }
  910. /**
  911. * Promise Capability object.
  912. *
  913. * @typedef {Object} PromiseCapability
  914. * @property {Promise} promise - A promise object.
  915. * @property {function} resolve - Fullfills the promise.
  916. * @property {function} reject - Rejects the promise.
  917. */
  918. /**
  919. * Creates a promise capability object.
  920. * @alias PDFJS.createPromiseCapability
  921. *
  922. * @return {PromiseCapability} A capability object contains:
  923. * - a Promise, resolve and reject methods.
  924. */
  925. function createPromiseCapability() {
  926. var capability = {};
  927. capability.promise = new Promise(function (resolve, reject) {
  928. capability.resolve = resolve;
  929. capability.reject = reject;
  930. });
  931. return capability;
  932. }
  933. PDFJS.createPromiseCapability = createPromiseCapability;
  934. /**
  935. * Polyfill for Promises:
  936. * The following promise implementation tries to generally implement the
  937. * Promise/A+ spec. Some notable differences from other promise libaries are:
  938. * - There currently isn't a seperate deferred and promise object.
  939. * - Unhandled rejections eventually show an error if they aren't handled.
  940. *
  941. * Based off of the work in:
  942. * https://bugzilla.mozilla.org/show_bug.cgi?id=810490
  943. */
  944. (function PromiseClosure() {
  945. if (globalScope.Promise) {
  946. // Promises existing in the DOM/Worker, checking presence of all/resolve
  947. if (typeof globalScope.Promise.all !== 'function') {
  948. globalScope.Promise.all = function (iterable) {
  949. var count = 0, results = [], resolve, reject;
  950. var promise = new globalScope.Promise(function (resolve_, reject_) {
  951. resolve = resolve_;
  952. reject = reject_;
  953. });
  954. iterable.forEach(function (p, i) {
  955. count++;
  956. p.then(function (result) {
  957. results[i] = result;
  958. count--;
  959. if (count === 0) {
  960. resolve(results);
  961. }
  962. }, reject);
  963. });
  964. if (count === 0) {
  965. resolve(results);
  966. }
  967. return promise;
  968. };
  969. }
  970. if (typeof globalScope.Promise.resolve !== 'function') {
  971. globalScope.Promise.resolve = function (value) {
  972. return new globalScope.Promise(function (resolve) { resolve(value); });
  973. };
  974. }
  975. if (typeof globalScope.Promise.reject !== 'function') {
  976. globalScope.Promise.reject = function (reason) {
  977. return new globalScope.Promise(function (resolve, reject) {
  978. reject(reason);
  979. });
  980. };
  981. }
  982. if (typeof globalScope.Promise.prototype.catch !== 'function') {
  983. globalScope.Promise.prototype.catch = function (onReject) {
  984. return globalScope.Promise.prototype.then(undefined, onReject);
  985. };
  986. }
  987. return;
  988. }
  989. var STATUS_PENDING = 0;
  990. var STATUS_RESOLVED = 1;
  991. var STATUS_REJECTED = 2;
  992. // In an attempt to avoid silent exceptions, unhandled rejections are
  993. // tracked and if they aren't handled in a certain amount of time an
  994. // error is logged.
  995. var REJECTION_TIMEOUT = 500;
  996. var HandlerManager = {
  997. handlers: [],
  998. running: false,
  999. unhandledRejections: [],
  1000. pendingRejectionCheck: false,
  1001. scheduleHandlers: function scheduleHandlers(promise) {
  1002. if (promise._status === STATUS_PENDING) {
  1003. return;
  1004. }
  1005. this.handlers = this.handlers.concat(promise._handlers);
  1006. promise._handlers = [];
  1007. if (this.running) {
  1008. return;
  1009. }
  1010. this.running = true;
  1011. setTimeout(this.runHandlers.bind(this), 0);
  1012. },
  1013. runHandlers: function runHandlers() {
  1014. var RUN_TIMEOUT = 1; // ms
  1015. var timeoutAt = Date.now() + RUN_TIMEOUT;
  1016. while (this.handlers.length > 0) {
  1017. var handler = this.handlers.shift();
  1018. var nextStatus = handler.thisPromise._status;
  1019. var nextValue = handler.thisPromise._value;
  1020. try {
  1021. if (nextStatus === STATUS_RESOLVED) {
  1022. if (typeof handler.onResolve === 'function') {
  1023. nextValue = handler.onResolve(nextValue);
  1024. }
  1025. } else if (typeof handler.onReject === 'function') {
  1026. nextValue = handler.onReject(nextValue);
  1027. nextStatus = STATUS_RESOLVED;
  1028. if (handler.thisPromise._unhandledRejection) {
  1029. this.removeUnhandeledRejection(handler.thisPromise);
  1030. }
  1031. }
  1032. } catch (ex) {
  1033. nextStatus = STATUS_REJECTED;
  1034. nextValue = ex;
  1035. }
  1036. handler.nextPromise._updateStatus(nextStatus, nextValue);
  1037. if (Date.now() >= timeoutAt) {
  1038. break;
  1039. }
  1040. }
  1041. if (this.handlers.length > 0) {
  1042. setTimeout(this.runHandlers.bind(this), 0);
  1043. return;
  1044. }
  1045. this.running = false;
  1046. },
  1047. addUnhandledRejection: function addUnhandledRejection(promise) {
  1048. this.unhandledRejections.push({
  1049. promise: promise,
  1050. time: Date.now()
  1051. });
  1052. this.scheduleRejectionCheck();
  1053. },
  1054. removeUnhandeledRejection: function removeUnhandeledRejection(promise) {
  1055. promise._unhandledRejection = false;
  1056. for (var i = 0; i < this.unhandledRejections.length; i++) {
  1057. if (this.unhandledRejections[i].promise === promise) {
  1058. this.unhandledRejections.splice(i);
  1059. i--;
  1060. }
  1061. }
  1062. },
  1063. scheduleRejectionCheck: function scheduleRejectionCheck() {
  1064. if (this.pendingRejectionCheck) {
  1065. return;
  1066. }
  1067. this.pendingRejectionCheck = true;
  1068. setTimeout(function rejectionCheck() {
  1069. this.pendingRejectionCheck = false;
  1070. var now = Date.now();
  1071. for (var i = 0; i < this.unhandledRejections.length; i++) {
  1072. if (now - this.unhandledRejections[i].time > REJECTION_TIMEOUT) {
  1073. var unhandled = this.unhandledRejections[i].promise._value;
  1074. var msg = 'Unhandled rejection: ' + unhandled;
  1075. if (unhandled.stack) {
  1076. msg += '\n' + unhandled.stack;
  1077. }
  1078. warn(msg);
  1079. this.unhandledRejections.splice(i);
  1080. i--;
  1081. }
  1082. }
  1083. if (this.unhandledRejections.length) {
  1084. this.scheduleRejectionCheck();
  1085. }
  1086. }.bind(this), REJECTION_TIMEOUT);
  1087. }
  1088. };
  1089. function Promise(resolver) {
  1090. this._status = STATUS_PENDING;
  1091. this._handlers = [];
  1092. try {
  1093. resolver.call(this, this._resolve.bind(this), this._reject.bind(this));
  1094. } catch (e) {
  1095. this._reject(e);
  1096. }
  1097. }
  1098. /**
  1099. * Builds a promise that is resolved when all the passed in promises are
  1100. * resolved.
  1101. * @param {array} array of data and/or promises to wait for.
  1102. * @return {Promise} New dependant promise.
  1103. */
  1104. Promise.all = function Promise_all(promises) {
  1105. var resolveAll, rejectAll;
  1106. var deferred = new Promise(function (resolve, reject) {
  1107. resolveAll = resolve;
  1108. rejectAll = reject;
  1109. });
  1110. var unresolved = promises.length;
  1111. var results = [];
  1112. if (unresolved === 0) {
  1113. resolveAll(results);
  1114. return deferred;
  1115. }
  1116. function reject(reason) {
  1117. if (deferred._status === STATUS_REJECTED) {
  1118. return;
  1119. }
  1120. results = [];
  1121. rejectAll(reason);
  1122. }
  1123. for (var i = 0, ii = promises.length; i < ii; ++i) {
  1124. var promise = promises[i];
  1125. var resolve = (function(i) {
  1126. return function(value) {
  1127. if (deferred._status === STATUS_REJECTED) {
  1128. return;
  1129. }
  1130. results[i] = value;
  1131. unresolved--;
  1132. if (unresolved === 0) {
  1133. resolveAll(results);
  1134. }
  1135. };
  1136. })(i);
  1137. if (Promise.isPromise(promise)) {
  1138. promise.then(resolve, reject);
  1139. } else {
  1140. resolve(promise);
  1141. }
  1142. }
  1143. return deferred;
  1144. };
  1145. /**
  1146. * Checks if the value is likely a promise (has a 'then' function).
  1147. * @return {boolean} true if value is thenable
  1148. */
  1149. Promise.isPromise = function Promise_isPromise(value) {
  1150. return value && typeof value.then === 'function';
  1151. };
  1152. /**
  1153. * Creates resolved promise
  1154. * @param value resolve value
  1155. * @returns {Promise}
  1156. */
  1157. Promise.resolve = function Promise_resolve(value) {
  1158. return new Promise(function (resolve) { resolve(value); });
  1159. };
  1160. /**
  1161. * Creates rejected promise
  1162. * @param reason rejection value
  1163. * @returns {Promise}
  1164. */
  1165. Promise.reject = function Promise_reject(reason) {
  1166. return new Promise(function (resolve, reject) { reject(reason); });
  1167. };
  1168. Promise.prototype = {
  1169. _status: null,
  1170. _value: null,
  1171. _handlers: null,
  1172. _unhandledRejection: null,
  1173. _updateStatus: function Promise__updateStatus(status, value) {
  1174. if (this._status === STATUS_RESOLVED ||
  1175. this._status === STATUS_REJECTED) {
  1176. return;
  1177. }
  1178. if (status === STATUS_RESOLVED &&
  1179. Promise.isPromise(value)) {
  1180. value.then(this._updateStatus.bind(this, STATUS_RESOLVED),
  1181. this._updateStatus.bind(this, STATUS_REJECTED));
  1182. return;
  1183. }
  1184. this._status = status;
  1185. this._value = value;
  1186. if (status === STATUS_REJECTED && this._handlers.length === 0) {
  1187. this._unhandledRejection = true;
  1188. HandlerManager.addUnhandledRejection(this);
  1189. }
  1190. HandlerManager.scheduleHandlers(this);
  1191. },
  1192. _resolve: function Promise_resolve(value) {
  1193. this._updateStatus(STATUS_RESOLVED, value);
  1194. },
  1195. _reject: function Promise_reject(reason) {
  1196. this._updateStatus(STATUS_REJECTED, reason);
  1197. },
  1198. then: function Promise_then(onResolve, onReject) {
  1199. var nextPromise = new Promise(function (resolve, reject) {
  1200. this.resolve = resolve;
  1201. this.reject = reject;
  1202. });
  1203. this._handlers.push({
  1204. thisPromise: this,
  1205. onResolve: onResolve,
  1206. onReject: onReject,
  1207. nextPromise: nextPromise
  1208. });
  1209. HandlerManager.scheduleHandlers(this);
  1210. return nextPromise;
  1211. },
  1212. catch: function Promise_catch(onReject) {
  1213. return this.then(undefined, onReject);
  1214. }
  1215. };
  1216. globalScope.Promise = Promise;
  1217. })();
  1218. var StatTimer = (function StatTimerClosure() {
  1219. function rpad(str, pad, length) {
  1220. while (str.length < length) {
  1221. str += pad;
  1222. }
  1223. return str;
  1224. }
  1225. function StatTimer() {
  1226. this.started = {};
  1227. this.times = [];
  1228. this.enabled = true;
  1229. }
  1230. StatTimer.prototype = {
  1231. time: function StatTimer_time(name) {
  1232. if (!this.enabled) {
  1233. return;
  1234. }
  1235. if (name in this.started) {
  1236. warn('Timer is already running for ' + name);
  1237. }
  1238. this.started[name] = Date.now();
  1239. },
  1240. timeEnd: function StatTimer_timeEnd(name) {
  1241. if (!this.enabled) {
  1242. return;
  1243. }
  1244. if (!(name in this.started)) {
  1245. warn('Timer has not been started for ' + name);
  1246. }
  1247. this.times.push({
  1248. 'name': name,
  1249. 'start': this.started[name],
  1250. 'end': Date.now()
  1251. });
  1252. // Remove timer from started so it can be called again.
  1253. delete this.started[name];
  1254. },
  1255. toString: function StatTimer_toString() {
  1256. var i, ii;
  1257. var times = this.times;
  1258. var out = '';
  1259. // Find the longest name for padding purposes.
  1260. var longest = 0;
  1261. for (i = 0, ii = times.length; i < ii; ++i) {
  1262. var name = times[i]['name'];
  1263. if (name.length > longest) {
  1264. longest = name.length;
  1265. }
  1266. }
  1267. for (i = 0, ii = times.length; i < ii; ++i) {
  1268. var span = times[i];
  1269. var duration = span.end - span.start;
  1270. out += rpad(span['name'], ' ', longest) + ' ' + duration + 'ms\n';
  1271. }
  1272. return out;
  1273. }
  1274. };
  1275. return StatTimer;
  1276. })();
  1277. PDFJS.createBlob = function createBlob(data, contentType) {
  1278. if (typeof Blob !== 'undefined') {
  1279. return new Blob([data], { type: contentType });
  1280. }
  1281. // Blob builder is deprecated in FF14 and removed in FF18.
  1282. var bb = new MozBlobBuilder();
  1283. bb.append(data);
  1284. return bb.getBlob(contentType);
  1285. };
  1286. PDFJS.createObjectURL = (function createObjectURLClosure() {
  1287. // Blob/createObjectURL is not available, falling back to data schema.
  1288. var digits =
  1289. 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
  1290. return function createObjectURL(data, contentType) {
  1291. if (!PDFJS.disableCreateObjectURL &&
  1292. typeof URL !== 'undefined' && URL.createObjectURL) {
  1293. var blob = PDFJS.createBlob(data, contentType);
  1294. return URL.createObjectURL(blob);
  1295. }
  1296. var buffer = 'data:' + contentType + ';base64,';
  1297. for (var i = 0, ii = data.length; i < ii; i += 3) {
  1298. var b1 = data[i] & 0xFF;
  1299. var b2 = data[i + 1] & 0xFF;
  1300. var b3 = data[i + 2] & 0xFF;
  1301. var d1 = b1 >> 2, d2 = ((b1 & 3) << 4) | (b2 >> 4);
  1302. var d3 = i + 1 < ii ? ((b2 & 0xF) << 2) | (b3 >> 6) : 64;
  1303. var d4 = i + 2 < ii ? (b3 & 0x3F) : 64;
  1304. buffer += digits[d1] + digits[d2] + digits[d3] + digits[d4];
  1305. }
  1306. return buffer;
  1307. };
  1308. })();
  1309. function MessageHandler(name, comObj) {
  1310. this.name = name;
  1311. this.comObj = comObj;
  1312. this.callbackIndex = 1;
  1313. this.postMessageTransfers = true;
  1314. var callbacksCapabilities = this.callbacksCapabilities = {};
  1315. var ah = this.actionHandler = {};
  1316. ah['console_log'] = [function ahConsoleLog(data) {
  1317. console.log.apply(console, data);
  1318. }];
  1319. ah['console_error'] = [function ahConsoleError(data) {
  1320. console.error.apply(console, data);
  1321. }];
  1322. ah['_unsupported_feature'] = [function ah_unsupportedFeature(data) {
  1323. UnsupportedManager.notify(data);
  1324. }];
  1325. comObj.onmessage = function messageHandlerComObjOnMessage(event) {
  1326. var data = event.data;
  1327. if (data.isReply) {
  1328. var callbackId = data.callbackId;
  1329. if (data.callbackId in callbacksCapabilities) {
  1330. var callback = callbacksCapabilities[callbackId];
  1331. delete callbacksCapabilities[callbackId];
  1332. if ('error' in data) {
  1333. callback.reject(data.error);
  1334. } else {
  1335. callback.resolve(data.data);
  1336. }
  1337. } else {
  1338. error('Cannot resolve callback ' + callbackId);
  1339. }
  1340. } else if (data.action in ah) {
  1341. var action = ah[data.action];
  1342. if (data.callbackId) {
  1343. Promise.resolve().then(function () {
  1344. return action[0].call(action[1], data.data);
  1345. }).then(function (result) {
  1346. comObj.postMessage({
  1347. isReply: true,
  1348. callbackId: data.callbackId,
  1349. data: result
  1350. });
  1351. }, function (reason) {
  1352. comObj.postMessage({
  1353. isReply: true,
  1354. callbackId: data.callbackId,
  1355. error: reason
  1356. });
  1357. });
  1358. } else {
  1359. action[0].call(action[1], data.data);
  1360. }
  1361. } else {
  1362. error('Unknown action from worker: ' + data.action);
  1363. }
  1364. };
  1365. }
  1366. MessageHandler.prototype = {
  1367. on: function messageHandlerOn(actionName, handler, scope) {
  1368. var ah = this.actionHandler;
  1369. if (ah[actionName]) {
  1370. error('There is already an actionName called "' + actionName + '"');
  1371. }
  1372. ah[actionName] = [handler, scope];
  1373. },
  1374. /**
  1375. * Sends a message to the comObj to invoke the action with the supplied data.
  1376. * @param {String} actionName Action to call.
  1377. * @param {JSON} data JSON data to send.
  1378. * @param {Array} [transfers] Optional list of transfers/ArrayBuffers
  1379. */
  1380. send: function messageHandlerSend(actionName, data, transfers) {
  1381. var message = {
  1382. action: actionName,
  1383. data: data
  1384. };
  1385. this.postMessage(message, transfers);
  1386. },
  1387. /**
  1388. * Sends a message to the comObj to invoke the action with the supplied data.
  1389. * Expects that other side will callback with the response.
  1390. * @param {String} actionName Action to call.
  1391. * @param {JSON} data JSON data to send.
  1392. * @param {Array} [transfers] Optional list of transfers/ArrayBuffers.
  1393. * @returns {Promise} Promise to be resolved with response data.
  1394. */
  1395. sendWithPromise:
  1396. function messageHandlerSendWithPromise(actionName, data, transfers) {
  1397. var callbackId = this.callbackIndex++;
  1398. var message = {
  1399. action: actionName,
  1400. data: data,
  1401. callbackId: callbackId
  1402. };
  1403. var capability = createPromiseCapability();
  1404. this.callbacksCapabilities[callbackId] = capability;
  1405. try {
  1406. this.postMessage(message, transfers);
  1407. } catch (e) {
  1408. capability.reject(e);
  1409. }
  1410. return capability.promise;
  1411. },
  1412. /**
  1413. * Sends raw message to the comObj.
  1414. * @private
  1415. * @param message {Object} Raw message.
  1416. * @param transfers List of transfers/ArrayBuffers, or undefined.
  1417. */
  1418. postMessage: function (message, transfers) {
  1419. if (transfers && this.postMessageTransfers) {
  1420. this.comObj.postMessage(message, transfers);
  1421. } else {
  1422. this.comObj.postMessage(message);
  1423. }
  1424. }
  1425. };
  1426. function loadJpegStream(id, imageUrl, objs) {
  1427. var img = new Image();
  1428. img.onload = (function loadJpegStream_onloadClosure() {
  1429. objs.resolve(id, img);
  1430. });
  1431. img.onerror = (function loadJpegStream_onerrorClosure() {
  1432. objs.resolve(id, null);
  1433. warn('Error during JPEG image loading');
  1434. });
  1435. img.src = imageUrl;
  1436. }
  1437. /**
  1438. * The maximum allowed image size in total pixels e.g. width * height. Images
  1439. * above this value will not be drawn. Use -1 for no limit.
  1440. * @var {number}
  1441. */
  1442. PDFJS.maxImageSize = (PDFJS.maxImageSize === undefined ?
  1443. -1 : PDFJS.maxImageSize);
  1444. /**
  1445. * The url of where the predefined Adobe CMaps are located. Include trailing
  1446. * slash.
  1447. * @var {string}
  1448. */
  1449. PDFJS.cMapUrl = (PDFJS.cMapUrl === undefined ? null : PDFJS.cMapUrl);
  1450. /**
  1451. * Specifies if CMaps are binary packed.
  1452. * @var {boolean}
  1453. */
  1454. PDFJS.cMapPacked = PDFJS.cMapPacked === undefined ? false : PDFJS.cMapPacked;
  1455. /*
  1456. * By default fonts are converted to OpenType fonts and loaded via font face
  1457. * rules. If disabled, the font will be rendered using a built in font renderer
  1458. * that constructs the glyphs with primitive path commands.
  1459. * @var {boolean}
  1460. */
  1461. PDFJS.disableFontFace = (PDFJS.disableFontFace === undefined ?
  1462. false : PDFJS.disableFontFace);
  1463. /**
  1464. * Path for image resources, mainly for annotation icons. Include trailing
  1465. * slash.
  1466. * @var {string}
  1467. */
  1468. PDFJS.imageResourcesPath = (PDFJS.imageResourcesPath === undefined ?
  1469. '' : PDFJS.imageResourcesPath);
  1470. /**
  1471. * Disable the web worker and run all code on the main thread. This will happen
  1472. * automatically if the browser doesn't support workers or sending typed arrays
  1473. * to workers.
  1474. * @var {boolean}
  1475. */
  1476. PDFJS.disableWorker = (PDFJS.disableWorker === undefined ?
  1477. false : PDFJS.disableWorker);
  1478. /**
  1479. * Path and filename of the worker file. Required when the worker is enabled in
  1480. * development mode. If unspecified in the production build, the worker will be
  1481. * loaded based on the location of the pdf.js file.
  1482. * @var {string}
  1483. */
  1484. PDFJS.workerSrc = (PDFJS.workerSrc === undefined ? null : PDFJS.workerSrc);
  1485. /**
  1486. * Disable range request loading of PDF files. When enabled and if the server
  1487. * supports partial content requests then the PDF will be fetched in chunks.
  1488. * Enabled (false) by default.
  1489. * @var {boolean}
  1490. */
  1491. PDFJS.disableRange = (PDFJS.disableRange === undefined ?
  1492. false : PDFJS.disableRange);
  1493. /**
  1494. * Disable pre-fetching of PDF file data. When range requests are enabled PDF.js
  1495. * will automatically keep fetching more data even if it isn't needed to display
  1496. * the current page. This default behavior can be disabled.
  1497. * @var {boolean}
  1498. */
  1499. PDFJS.disableAutoFetch = (PDFJS.disableAutoFetch === undefined ?
  1500. false : PDFJS.disableAutoFetch);
  1501. /**
  1502. * Enables special hooks for debugging PDF.js.
  1503. * @var {boolean}
  1504. */
  1505. PDFJS.pdfBug = (PDFJS.pdfBug === undefined ? false : PDFJS.pdfBug);
  1506. /**
  1507. * Enables transfer usage in postMessage for ArrayBuffers.
  1508. * @var {boolean}
  1509. */
  1510. PDFJS.postMessageTransfers = (PDFJS.postMessageTransfers === undefined ?
  1511. true : PDFJS.postMessageTransfers);
  1512. /**
  1513. * Disables URL.createObjectURL usage.
  1514. * @var {boolean}
  1515. */
  1516. PDFJS.disableCreateObjectURL = (PDFJS.disableCreateObjectURL === undefined ?
  1517. false : PDFJS.disableCreateObjectURL);
  1518. /**
  1519. * Disables WebGL usage.
  1520. * @var {boolean}
  1521. */
  1522. PDFJS.disableWebGL = (PDFJS.disableWebGL === undefined ?
  1523. true : PDFJS.disableWebGL);
  1524. /**
  1525. * Enables CSS only zooming.
  1526. * @var {boolean}
  1527. */
  1528. PDFJS.useOnlyCssZoom = (PDFJS.useOnlyCssZoom === undefined ?
  1529. false : PDFJS.useOnlyCssZoom);
  1530. /**
  1531. * Controls the logging level.
  1532. * The constants from PDFJS.VERBOSITY_LEVELS should be used:
  1533. * - errors
  1534. * - warnings [default]
  1535. * - infos
  1536. * @var {number}
  1537. */
  1538. PDFJS.verbosity = (PDFJS.verbosity === undefined ?
  1539. PDFJS.VERBOSITY_LEVELS.warnings : PDFJS.verbosity);
  1540. /**
  1541. * The maximum supported canvas size in total pixels e.g. width * height.
  1542. * The default value is 4096 * 4096. Use -1 for no limit.
  1543. * @var {number}
  1544. */
  1545. PDFJS.maxCanvasPixels = (PDFJS.maxCanvasPixels === undefined ?
  1546. 16777216 : PDFJS.maxCanvasPixels);
  1547. /**
  1548. * Document initialization / loading parameters object.
  1549. *
  1550. * @typedef {Object} DocumentInitParameters
  1551. * @property {string} url - The URL of the PDF.
  1552. * @property {TypedArray} data - A typed array with PDF data.
  1553. * @property {Object} httpHeaders - Basic authentication headers.
  1554. * @property {boolean} withCredentials - Indicates whether or not cross-site
  1555. * Access-Control requests should be made using credentials such as cookies
  1556. * or authorization headers. The default is false.
  1557. * @property {string} password - For decrypting password-protected PDFs.
  1558. * @property {TypedArray} initialData - A typed array with the first portion or
  1559. * all of the pdf data. Used by the extension since some data is already
  1560. * loaded before the switch to range requests.
  1561. */
  1562. /**
  1563. * @typedef {Object} PDFDocumentStats
  1564. * @property {Array} streamTypes - Used stream types in the document (an item
  1565. * is set to true if specific stream ID was used in the document).
  1566. * @property {Array} fontTypes - Used font type in the document (an item is set
  1567. * to true if specific font ID was used in the document).
  1568. */
  1569. /**
  1570. * This is the main entry point for loading a PDF and interacting with it.
  1571. * NOTE: If a URL is used to fetch the PDF data a standard XMLHttpRequest(XHR)
  1572. * is used, which means it must follow the same origin rules that any XHR does
  1573. * e.g. No cross domain requests without CORS.
  1574. *
  1575. * @param {string|TypedArray|DocumentInitParameters} source Can be a url to
  1576. * where a PDF is located, a typed array (Uint8Array) already populated with
  1577. * data or parameter object.
  1578. *
  1579. * @param {Object} pdfDataRangeTransport is optional. It is used if you want
  1580. * to manually serve range requests for data in the PDF. See viewer.js for
  1581. * an example of pdfDataRangeTransport's interface.
  1582. *
  1583. * @param {function} passwordCallback is optional. It is used to request a
  1584. * password if wrong or no password was provided. The callback receives two
  1585. * parameters: function that needs to be called with new password and reason
  1586. * (see {PasswordResponses}).
  1587. *
  1588. * @return {Promise} A promise that is resolved with {@link PDFDocumentProxy}
  1589. * object.
  1590. */
  1591. PDFJS.getDocument = function getDocument(source,
  1592. pdfDataRangeTransport,
  1593. passwordCallback,
  1594. progressCallback) {
  1595. var workerInitializedCapability, workerReadyCapability, transport;
  1596. if (typeof source === 'string') {
  1597. source = { url: source };
  1598. } else if (isArrayBuffer(source)) {
  1599. source = { data: source };
  1600. } else if (typeof source !== 'object') {
  1601. error('Invalid parameter in getDocument, need either Uint8Array, ' +
  1602. 'string or a parameter object');
  1603. }
  1604. if (!source.url && !source.data) {
  1605. error('Invalid parameter array, need either .data or .url');
  1606. }
  1607. // copy/use all keys as is except 'url' -- full path is required
  1608. var params = {};
  1609. for (var key in source) {
  1610. if (key === 'url' && typeof window !== 'undefined') {
  1611. params[key] = combineUrl(window.location.href, source[key]);
  1612. continue;
  1613. }
  1614. params[key] = source[key];
  1615. }
  1616. workerInitializedCapability = createPromiseCapability();
  1617. workerReadyCapability = createPromiseCapability();
  1618. transport = new WorkerTransport(workerInitializedCapability,
  1619. workerReadyCapability, pdfDataRangeTransport,
  1620. progressCallback);
  1621. workerInitializedCapability.promise.then(function transportInitialized() {
  1622. transport.passwordCallback = passwordCallback;
  1623. transport.fetchDocument(params);
  1624. });
  1625. return workerReadyCapability.promise;
  1626. };
  1627. /**
  1628. * Proxy to a PDFDocument in the worker thread. Also, contains commonly used
  1629. * properties that can be read synchronously.
  1630. * @class
  1631. */
  1632. var PDFDocumentProxy = (function PDFDocumentProxyClosure() {
  1633. function PDFDocumentProxy(pdfInfo, transport) {
  1634. this.pdfInfo = pdfInfo;
  1635. this.transport = transport;
  1636. }
  1637. PDFDocumentProxy.prototype = /** @lends PDFDocumentProxy.prototype */ {
  1638. /**
  1639. * @return {number} Total number of pages the PDF contains.
  1640. */
  1641. get numPages() {
  1642. return this.pdfInfo.numPages;
  1643. },
  1644. /**
  1645. * @return {string} A unique ID to identify a PDF. Not guaranteed to be
  1646. * unique.
  1647. */
  1648. get fingerprint() {
  1649. return this.pdfInfo.fingerprint;
  1650. },
  1651. /**
  1652. * @param {number} pageNumber The page number to get. The first page is 1.
  1653. * @return {Promise} A promise that is resolved with a {@link PDFPageProxy}
  1654. * object.
  1655. */
  1656. getPage: function PDFDocumentProxy_getPage(pageNumber) {
  1657. return this.transport.getPage(pageNumber);
  1658. },
  1659. /**
  1660. * @param {{num: number, gen: number}} ref The page reference. Must have
  1661. * the 'num' and 'gen' properties.
  1662. * @return {Promise} A promise that is resolved with the page index that is
  1663. * associated with the reference.
  1664. */
  1665. getPageIndex: function PDFDocumentProxy_getPageIndex(ref) {
  1666. return this.transport.getPageIndex(ref);
  1667. },
  1668. /**
  1669. * @return {Promise} A promise that is resolved with a lookup table for
  1670. * mapping named destinations to reference numbers.
  1671. */
  1672. getDestinations: function PDFDocumentProxy_getDestinations() {
  1673. return this.transport.getDestinations();
  1674. },
  1675. /**
  1676. * @return {Promise} A promise that is resolved with a lookup table for
  1677. * mapping named attachments to their content.
  1678. */
  1679. getAttachments: function PDFDocumentProxy_getAttachments() {
  1680. return this.transport.getAttachments();
  1681. },
  1682. /**
  1683. * @return {Promise} A promise that is resolved with an array of all the
  1684. * JavaScript strings in the name tree.
  1685. */
  1686. getJavaScript: function PDFDocumentProxy_getJavaScript() {
  1687. return this.transport.getJavaScript();
  1688. },
  1689. /**
  1690. * @return {Promise} A promise that is resolved with an {Array} that is a
  1691. * tree outline (if it has one) of the PDF. The tree is in the format of:
  1692. * [
  1693. * {
  1694. * title: string,
  1695. * bold: boolean,
  1696. * italic: boolean,
  1697. * color: rgb array,
  1698. * dest: dest obj,
  1699. * items: array of more items like this
  1700. * },
  1701. * ...
  1702. * ].
  1703. */
  1704. getOutline: function PDFDocumentProxy_getOutline() {
  1705. return this.transport.getOutline();
  1706. },
  1707. /**
  1708. * @return {Promise} A promise that is resolved with an {Object} that has
  1709. * info and metadata properties. Info is an {Object} filled with anything
  1710. * available in the information dictionary and similarly metadata is a
  1711. * {Metadata} object with information from the metadata section of the PDF.
  1712. */
  1713. getMetadata: function PDFDocumentProxy_getMetadata() {
  1714. return this.transport.getMetadata();
  1715. },
  1716. /**
  1717. * @return {Promise} A promise that is resolved with a TypedArray that has
  1718. * the raw data from the PDF.
  1719. */
  1720. getData: function PDFDocumentProxy_getData() {
  1721. return this.transport.getData();
  1722. },
  1723. /**
  1724. * @return {Promise} A promise that is resolved when the document's data
  1725. * is loaded. It is resolved with an {Object} that contains the length
  1726. * property that indicates size of the PDF data in bytes.
  1727. */
  1728. getDownloadInfo: function PDFDocumentProxy_getDownloadInfo() {
  1729. return this.transport.downloadInfoCapability.promise;
  1730. },
  1731. /**
  1732. * @returns {Promise} A promise this is resolved with current stats about
  1733. * document structures (see {@link PDFDocumentStats}).
  1734. */
  1735. getStats: function PDFDocumentProxy_getStats() {
  1736. return this.transport.getStats();
  1737. },
  1738. /**
  1739. * Cleans up resources allocated by the document, e.g. created @font-face.
  1740. */
  1741. cleanup: function PDFDocumentProxy_cleanup() {
  1742. this.transport.startCleanup();
  1743. },
  1744. /**
  1745. * Destroys current document instance and terminates worker.
  1746. */
  1747. destroy: function PDFDocumentProxy_destroy() {
  1748. this.transport.destroy();
  1749. }
  1750. };
  1751. return PDFDocumentProxy;
  1752. })();
  1753. /**
  1754. * Page text content.
  1755. *
  1756. * @typedef {Object} TextContent
  1757. * @property {array} items - array of {@link TextItem}
  1758. * @property {Object} styles - {@link TextStyles} objects, indexed by font
  1759. * name.
  1760. */
  1761. /**
  1762. * Page text content part.
  1763. *
  1764. * @typedef {Object} TextItem
  1765. * @property {string} str - text content.
  1766. * @property {string} dir - text direction: 'ttb', 'ltr' or 'rtl'.
  1767. * @property {array} transform - transformation matrix.
  1768. * @property {number} width - width in device space.
  1769. * @property {number} height - height in device space.
  1770. * @property {string} fontName - font name used by pdf.js for converted font.
  1771. */
  1772. /**
  1773. * Text style.
  1774. *
  1775. * @typedef {Object} TextStyle
  1776. * @property {number} ascent - font ascent.
  1777. * @property {number} descent - font descent.
  1778. * @property {boolean} vertical - text is in vertical mode.
  1779. * @property {string} fontFamily - possible font family
  1780. */
  1781. /**
  1782. * Page render parameters.
  1783. *
  1784. * @typedef {Object} RenderParameters
  1785. * @property {Object} canvasContext - A 2D context of a DOM Canvas object.
  1786. * @property {PDFJS.PageViewport} viewport - Rendering viewport obtained by
  1787. * calling of PDFPage.getViewport method.
  1788. * @property {string} intent - Rendering intent, can be 'display' or 'print'
  1789. * (default value is 'display').
  1790. * @property {Object} imageLayer - (optional) An object that has beginLayout,
  1791. * endLayout and appendImage functions.
  1792. * @property {function} continueCallback - (optional) A function that will be
  1793. * called each time the rendering is paused. To continue
  1794. * rendering call the function that is the first argument
  1795. * to the callback.
  1796. */
  1797. /**
  1798. * PDF page operator list.
  1799. *
  1800. * @typedef {Object} PDFOperatorList
  1801. * @property {Array} fnArray - Array containing the operator functions.
  1802. * @property {Array} argsArray - Array containing the arguments of the
  1803. * functions.
  1804. */
  1805. /**
  1806. * Proxy to a PDFPage in the worker thread.
  1807. * @class
  1808. */
  1809. var PDFPageProxy = (function PDFPageProxyClosure() {
  1810. function PDFPageProxy(pageIndex, pageInfo, transport) {
  1811. this.pageIndex = pageIndex;
  1812. this.pageInfo = pageInfo;
  1813. this.transport = transport;
  1814. this.stats = new StatTimer();
  1815. this.stats.enabled = !!globalScope.PDFJS.enableStats;
  1816. this.commonObjs = transport.commonObjs;
  1817. this.objs = new PDFObjects();
  1818. this.cleanupAfterRender = false;
  1819. this.pendingDestroy = false;
  1820. this.intentStates = {};
  1821. }
  1822. PDFPageProxy.prototype = /** @lends PDFPageProxy.prototype */ {
  1823. /**
  1824. * @return {number} Page number of the page. First page is 1.
  1825. */
  1826. get pageNumber() {
  1827. return this.pageIndex + 1;
  1828. },
  1829. /**
  1830. * @return {number} The number of degrees the page is rotated clockwise.
  1831. */
  1832. get rotate() {
  1833. return this.pageInfo.rotate;
  1834. },
  1835. /**
  1836. * @return {Object} The reference that points to this page. It has 'num' and
  1837. * 'gen' properties.
  1838. */
  1839. get ref() {
  1840. return this.pageInfo.ref;
  1841. },
  1842. /**
  1843. * @return {Array} An array of the visible portion of the PDF page in the
  1844. * user space units - [x1, y1, x2, y2].
  1845. */
  1846. get view() {
  1847. return this.pageInfo.view;
  1848. },
  1849. /**
  1850. * @param {number} scale The desired scale of the viewport.
  1851. * @param {number} rotate Degrees to rotate the viewport. If omitted this
  1852. * defaults to the page rotation.
  1853. * @return {PDFJS.PageViewport} Contains 'width' and 'height' properties
  1854. * along with transforms required for rendering.
  1855. */
  1856. getViewport: function PDFPageProxy_getViewport(scale, rotate) {
  1857. if (arguments.length < 2) {
  1858. rotate = this.rotate;
  1859. }
  1860. return new PDFJS.PageViewport(this.view, scale, rotate, 0, 0);
  1861. },
  1862. /**
  1863. * @return {Promise} A promise that is resolved with an {Array} of the
  1864. * annotation objects.
  1865. */
  1866. getAnnotations: function PDFPageProxy_getAnnotations() {
  1867. if (this.annotationsPromise) {
  1868. return this.annotationsPromise;
  1869. }
  1870. var promise = this.transport.getAnnotations(this.pageIndex);
  1871. this.annotationsPromise = promise;
  1872. return promise;
  1873. },
  1874. /**
  1875. * Begins the process of rendering a page to the desired context.
  1876. * @param {RenderParameters} params Page render parameters.
  1877. * @return {RenderTask} An object that contains the promise, which
  1878. * is resolved when the page finishes rendering.
  1879. */
  1880. render: function PDFPageProxy_render(params) {
  1881. var stats = this.stats;
  1882. stats.time('Overall');
  1883. // If there was a pending destroy cancel it so no cleanup happens during
  1884. // this call to render.
  1885. this.pendingDestroy = false;
  1886. var renderingIntent = (params.intent === 'print' ? 'print' : 'display');
  1887. if (!this.intentStates[renderingIntent]) {
  1888. this.intentStates[renderingIntent] = {};
  1889. }
  1890. var intentState = this.intentStates[renderingIntent];
  1891. // If there's no displayReadyCapability yet, then the operatorList
  1892. // was never requested before. Make the request and create the promise.
  1893. if (!intentState.displayReadyCapability) {
  1894. intentState.receivingOperatorList = true;
  1895. intentState.displayReadyCapability = createPromiseCapability();
  1896. intentState.operatorList = {
  1897. fnArray: [],
  1898. argsArray: [],
  1899. lastChunk: false
  1900. };
  1901. this.stats.time('Page Request');
  1902. this.transport.messageHandler.send('RenderPageRequest', {
  1903. pageIndex: this.pageNumber - 1,
  1904. intent: renderingIntent
  1905. });
  1906. }
  1907. var internalRenderTask = new InternalRenderTask(complete, params,
  1908. this.objs,
  1909. this.commonObjs,
  1910. intentState.operatorList,
  1911. this.pageNumber);
  1912. if (!intentState.renderTasks) {
  1913. intentState.renderTasks = [];
  1914. }
  1915. intentState.renderTasks.push(internalRenderTask);
  1916. var renderTask = new RenderTask(internalRenderTask);
  1917. var self = this;
  1918. intentState.displayReadyCapability.promise.then(
  1919. function pageDisplayReadyPromise(transparency) {
  1920. if (self.pendingDestroy) {
  1921. complete();
  1922. return;
  1923. }
  1924. stats.time('Rendering');
  1925. internalRenderTask.initalizeGraphics(transparency);
  1926. internalRenderTask.operatorListChanged();
  1927. },
  1928. function pageDisplayReadPromiseError(reason) {
  1929. complete(reason);
  1930. }
  1931. );
  1932. function complete(error) {
  1933. var i = intentState.renderTasks.indexOf(internalRenderTask);
  1934. if (i >= 0) {
  1935. intentState.renderTasks.splice(i, 1);
  1936. }
  1937. if (self.cleanupAfterRender) {
  1938. self.pendingDestroy = true;
  1939. }
  1940. self._tryDestroy();
  1941. if (error) {
  1942. internalRenderTask.capability.reject(error);
  1943. } else {
  1944. internalRenderTask.capability.resolve();
  1945. }
  1946. stats.timeEnd('Rendering');
  1947. stats.timeEnd('Overall');
  1948. }
  1949. return renderTask;
  1950. },
  1951. /**
  1952. * @return {Promise} A promise resolved with an {@link PDFOperatorList}
  1953. * object that represents page's operator list.
  1954. */
  1955. getOperatorList: function PDFPageProxy_getOperatorList() {
  1956. function operatorListChanged() {
  1957. if (intentState.operatorList.lastChunk) {
  1958. intentState.opListReadCapability.resolve(intentState.operatorList);
  1959. }
  1960. }
  1961. var renderingIntent = 'oplist';
  1962. if (!this.intentStates[renderingIntent]) {
  1963. this.intentStates[renderingIntent] = {};
  1964. }
  1965. var intentState = this.intentStates[renderingIntent];
  1966. if (!intentState.opListReadCapability) {
  1967. var opListTask = {};
  1968. opListTask.operatorListChanged = operatorListChanged;
  1969. intentState.receivingOperatorList = true;
  1970. intentState.opListReadCapability = createPromiseCapability();
  1971. intentState.renderTasks = [];
  1972. intentState.renderTasks.push(opListTask);
  1973. intentState.operatorList = {
  1974. fnArray: [],
  1975. argsArray: [],
  1976. lastChunk: false
  1977. };
  1978. this.transport.messageHandler.send('RenderPageRequest', {
  1979. pageIndex: this.pageIndex,
  1980. intent: renderingIntent
  1981. });
  1982. }
  1983. return intentState.opListReadCapability.promise;
  1984. },
  1985. /**
  1986. * @return {Promise} That is resolved a {@link TextContent}
  1987. * object that represent the page text content.
  1988. */
  1989. getTextContent: function PDFPageProxy_getTextContent() {
  1990. return this.transport.messageHandler.sendWithPromise('GetTextContent', {
  1991. pageIndex: this.pageNumber - 1
  1992. });
  1993. },
  1994. /**
  1995. * Destroys resources allocated by the page.
  1996. */
  1997. destroy: function PDFPageProxy_destroy() {
  1998. this.pendingDestroy = true;
  1999. this._tryDestroy();
  2000. },
  2001. /**
  2002. * For internal use only. Attempts to clean up if rendering is in a state
  2003. * where that's possible.
  2004. * @ignore
  2005. */
  2006. _tryDestroy: function PDFPageProxy__destroy() {
  2007. if (!this.pendingDestroy ||
  2008. Object.keys(this.intentStates).some(function(intent) {
  2009. var intentState = this.intentStates[intent];
  2010. return (intentState.renderTasks.length !== 0 ||
  2011. intentState.receivingOperatorList);
  2012. }, this)) {
  2013. return;
  2014. }
  2015. Object.keys(this.intentStates).forEach(function(intent) {
  2016. delete this.intentStates[intent];
  2017. }, this);
  2018. this.objs.clear();
  2019. this.annotationsPromise = null;
  2020. this.pendingDestroy = false;
  2021. },
  2022. /**
  2023. * For internal use only.
  2024. * @ignore
  2025. */
  2026. _startRenderPage: function PDFPageProxy_startRenderPage(transparency,
  2027. intent) {
  2028. var intentState = this.intentStates[intent];
  2029. // TODO Refactor RenderPageRequest to separate rendering
  2030. // and operator list logic
  2031. if (intentState.displayReadyCapability) {
  2032. intentState.displayReadyCapability.resolve(transparency);
  2033. }
  2034. },
  2035. /**
  2036. * For internal use only.
  2037. * @ignore
  2038. */
  2039. _renderPageChunk: function PDFPageProxy_renderPageChunk(operatorListChunk,
  2040. intent) {
  2041. var intentState = this.intentStates[intent];
  2042. var i, ii;
  2043. // Add the new chunk to the current operator list.
  2044. for (i = 0, ii = operatorListChunk.length; i < ii; i++) {
  2045. intentState.operatorList.fnArray.push(operatorListChunk.fnArray[i]);
  2046. intentState.operatorList.argsArray.push(
  2047. operatorListChunk.argsArray[i]);
  2048. }
  2049. intentState.operatorList.lastChunk = operatorListChunk.lastChunk;
  2050. // Notify all the rendering tasks there are more operators to be consumed.
  2051. for (i = 0; i < intentState.renderTasks.length; i++) {
  2052. intentState.renderTasks[i].operatorListChanged();
  2053. }
  2054. if (operatorListChunk.lastChunk) {
  2055. intentState.receivingOperatorList = false;
  2056. this._tryDestroy();
  2057. }
  2058. }
  2059. };
  2060. return PDFPageProxy;
  2061. })();
  2062. /**
  2063. * For internal use only.
  2064. * @ignore
  2065. */
  2066. var WorkerTransport = (function WorkerTransportClosure() {
  2067. function WorkerTransport(workerInitializedCapability, workerReadyCapability,
  2068. pdfDataRangeTransport, progressCallback) {
  2069. this.pdfDataRangeTransport = pdfDataRangeTransport;
  2070. this.workerInitializedCapability = workerInitializedCapability;
  2071. this.workerReadyCapability = workerReadyCapability;
  2072. this.progressCallback = progressCallback;
  2073. this.commonObjs = new PDFObjects();
  2074. this.pageCache = [];
  2075. this.pagePromises = [];
  2076. this.downloadInfoCapability = createPromiseCapability();
  2077. this.passwordCallback = null;
  2078. // If worker support isn't disabled explicit and the browser has worker
  2079. // support, create a new web worker and test if it/the browser fullfills
  2080. // all requirements to run parts of pdf.js in a web worker.
  2081. // Right now, the requirement is, that an Uint8Array is still an Uint8Array
  2082. // as it arrives on the worker. Chrome added this with version 15.
  2083. // Either workers are disabled, not supported or have thrown an exception.
  2084. // Thus, we fallback to a faked worker.
  2085. this.setupFakeWorker();
  2086. }
  2087. WorkerTransport.prototype = {
  2088. destroy: function WorkerTransport_destroy() {
  2089. this.pageCache = [];
  2090. this.pagePromises = [];
  2091. var self = this;
  2092. this.messageHandler.sendWithPromise('Terminate', null).then(function () {
  2093. FontLoader.clear();
  2094. if (self.worker) {
  2095. self.worker.terminate();
  2096. }
  2097. });
  2098. },
  2099. setupFakeWorker: function WorkerTransport_setupFakeWorker() {
  2100. globalScope.PDFJS.disableWorker = true;
  2101. if (!PDFJS.fakeWorkerFilesLoadedCapability) {
  2102. PDFJS.fakeWorkerFilesLoadedCapability = createPromiseCapability();
  2103. // In the developer build load worker_loader which in turn loads all the
  2104. // other files and resolves the promise. In production only the
  2105. // pdf.worker.js file is needed.
  2106. PDFJS.fakeWorkerFilesLoadedCapability.resolve();
  2107. }
  2108. PDFJS.fakeWorkerFilesLoadedCapability.promise.then(function () {
  2109. warn('Setting up fake worker.');
  2110. // If we don't use a worker, just post/sendMessage to the main thread.
  2111. var fakeWorker = {
  2112. postMessage: function WorkerTransport_postMessage(obj) {
  2113. fakeWorker.onmessage({data: obj});
  2114. },
  2115. terminate: function WorkerTransport_terminate() {}
  2116. };
  2117. var messageHandler = new MessageHandler('main', fakeWorker);
  2118. this.setupMessageHandler(messageHandler);
  2119. // If the main thread is our worker, setup the handling for the messages
  2120. // the main thread sends to it self.
  2121. PDFJS.WorkerMessageHandler.setup(messageHandler);
  2122. this.workerInitializedCapability.resolve();
  2123. }.bind(this));
  2124. },
  2125. setupMessageHandler:
  2126. function WorkerTransport_setupMessageHandler(messageHandler) {
  2127. this.messageHandler = messageHandler;
  2128. function updatePassword(password) {
  2129. messageHandler.send('UpdatePassword', password);
  2130. }
  2131. var pdfDataRangeTransport = this.pdfDataRangeTransport;
  2132. if (pdfDataRangeTransport) {
  2133. pdfDataRangeTransport.addRangeListener(function(begin, chunk) {
  2134. messageHandler.send('OnDataRange', {
  2135. begin: begin,
  2136. chunk: chunk
  2137. });
  2138. });
  2139. pdfDataRangeTransport.addProgressListener(function(loaded) {
  2140. messageHandler.send('OnDataProgress', {
  2141. loaded: loaded
  2142. });
  2143. });
  2144. messageHandler.on('RequestDataRange',
  2145. function transportDataRange(data) {
  2146. pdfDataRangeTransport.requestDataRange(data.begin, data.end);
  2147. }, this);
  2148. }
  2149. messageHandler.on('GetDoc', function transportDoc(data) {
  2150. var pdfInfo = data.pdfInfo;
  2151. this.numPages = data.pdfInfo.numPages;
  2152. var pdfDocument = new PDFDocumentProxy(pdfInfo, this);
  2153. this.pdfDocument = pdfDocument;
  2154. this.workerReadyCapability.resolve(pdfDocument);
  2155. }, this);
  2156. messageHandler.on('NeedPassword', function transportPassword(data) {
  2157. if (this.passwordCallback) {
  2158. return this.passwordCallback(updatePassword,
  2159. PasswordResponses.NEED_PASSWORD);
  2160. }
  2161. this.workerReadyCapability.reject(data.exception.message,
  2162. data.exception);
  2163. }, this);
  2164. messageHandler.on('IncorrectPassword', function transportBadPass(data) {
  2165. if (this.passwordCallback) {
  2166. return this.passwordCallback(updatePassword,
  2167. PasswordResponses.INCORRECT_PASSWORD);
  2168. }
  2169. this.workerReadyCapability.reject(data.exception.message,
  2170. data.exception);
  2171. }, this);
  2172. messageHandler.on('InvalidPDF', function transportInvalidPDF(data) {
  2173. this.workerReadyCapability.reject(data.exception.name, data.exception);
  2174. }, this);
  2175. messageHandler.on('MissingPDF', function transportMissingPDF(data) {
  2176. this.workerReadyCapability.reject(data.exception.message,
  2177. data.exception);
  2178. }, this);
  2179. messageHandler.on('UnknownError', function transportUnknownError(data) {
  2180. this.workerReadyCapability.reject(data.exception.message,
  2181. data.exception);
  2182. }, this);
  2183. messageHandler.on('DataLoaded', function transportPage(data) {
  2184. this.downloadInfoCapability.resolve(data);
  2185. }, this);
  2186. messageHandler.on('StartRenderPage', function transportRender(data) {
  2187. var page = this.pageCache[data.pageIndex];
  2188. page.stats.timeEnd('Page Request');
  2189. page._startRenderPage(data.transparency, data.intent);
  2190. }, this);
  2191. messageHandler.on('RenderPageChunk', function transportRender(data) {
  2192. var page = this.pageCache[data.pageIndex];
  2193. page._renderPageChunk(data.operatorList, data.intent);
  2194. }, this);
  2195. messageHandler.on('commonobj', function transportObj(data) {
  2196. var id = data[0];
  2197. var type = data[1];
  2198. if (this.commonObjs.hasData(id)) {
  2199. return;
  2200. }
  2201. switch (type) {
  2202. case 'Font':
  2203. var exportedData = data[2];
  2204. var font;
  2205. if ('error' in exportedData) {
  2206. var error = exportedData.error;
  2207. warn('Error during font loading: ' + error);
  2208. this.commonObjs.resolve(id, error);
  2209. break;
  2210. } else {
  2211. font = new FontFace(exportedData);
  2212. }
  2213. FontLoader.bind(
  2214. [font],
  2215. function fontReady(fontObjs) {
  2216. this.commonObjs.resolve(id, font);
  2217. }.bind(this)
  2218. );
  2219. break;
  2220. case 'FontPath':
  2221. this.commonObjs.resolve(id, data[2]);
  2222. break;
  2223. default:
  2224. error('Got unknown common object type ' + type);
  2225. }
  2226. }, this);
  2227. messageHandler.on('obj', function transportObj(data) {
  2228. var id = data[0];
  2229. var pageIndex = data[1];
  2230. var type = data[2];
  2231. var pageProxy = this.pageCache[pageIndex];
  2232. var imageData;
  2233. if (pageProxy.objs.hasData(id)) {
  2234. return;
  2235. }
  2236. switch (type) {
  2237. case 'JpegStream':
  2238. imageData = data[3];
  2239. loadJpegStream(id, imageData, pageProxy.objs);
  2240. break;
  2241. case 'Image':
  2242. imageData = data[3];
  2243. pageProxy.objs.resolve(id, imageData);
  2244. // heuristics that will allow not to store large data
  2245. var MAX_IMAGE_SIZE_TO_STORE = 8000000;
  2246. if (imageData && 'data' in imageData &&
  2247. imageData.data.length > MAX_IMAGE_SIZE_TO_STORE) {
  2248. pageProxy.cleanupAfterRender = true;
  2249. }
  2250. break;
  2251. default:
  2252. error('Got unknown object type ' + type);
  2253. }
  2254. }, this);
  2255. messageHandler.on('DocProgress', function transportDocProgress(data) {
  2256. if (this.progressCallback) {
  2257. this.progressCallback({
  2258. loaded: data.loaded,
  2259. total: data.total
  2260. });
  2261. }
  2262. }, this);
  2263. messageHandler.on('DocError', function transportDocError(data) {
  2264. this.workerReadyCapability.reject(data);
  2265. }, this);
  2266. messageHandler.on('PageError', function transportError(data) {
  2267. var page = this.pageCache[data.pageNum - 1];
  2268. var intentState = page.intentStates[data.intent];
  2269. if (intentState.displayReadyCapability.promise) {
  2270. intentState.displayReadyCapability.reject(data.error);
  2271. } else {
  2272. error(data.error);
  2273. }
  2274. }, this);
  2275. messageHandler.on('JpegDecode', function(data) {
  2276. var imageUrl = data[0];
  2277. var components = data[1];
  2278. if (components !== 3 && components !== 1) {
  2279. return Promise.reject(
  2280. new Error('Only 3 components or 1 component can be returned'));
  2281. }
  2282. return new Promise(function (resolve, reject) {
  2283. var img = new Image();
  2284. img.onload = function () {
  2285. var width = img.width;
  2286. var height = img.height;
  2287. var size = width * height;
  2288. var rgbaLength = size * 4;
  2289. var buf = new Uint8Array(size * components);
  2290. var tmpCanvas = createScratchCanvas(width, height);
  2291. var tmpCtx = tmpCanvas.getContext('2d');
  2292. tmpCtx.drawImage(img, 0, 0);
  2293. var data = tmpCtx.getImageData(0, 0, width, height).data;
  2294. var i, j;
  2295. if (components === 3) {
  2296. for (i = 0, j = 0; i < rgbaLength; i += 4, j += 3) {
  2297. buf[j] = data[i];
  2298. buf[j + 1] = data[i + 1];
  2299. buf[j + 2] = data[i + 2];
  2300. }
  2301. } else if (components === 1) {
  2302. for (i = 0, j = 0; i < rgbaLength; i += 4, j++) {
  2303. buf[j] = data[i];
  2304. }
  2305. }
  2306. resolve({ data: buf, width: width, height: height});
  2307. };
  2308. img.onerror = function () {
  2309. reject(new Error('JpegDecode failed to load image'));
  2310. };
  2311. img.src = imageUrl;
  2312. });
  2313. });
  2314. },
  2315. fetchDocument: function WorkerTransport_fetchDocument(source) {
  2316. source.disableAutoFetch = PDFJS.disableAutoFetch;
  2317. source.chunkedViewerLoading = !!this.pdfDataRangeTransport;
  2318. this.messageHandler.send('GetDocRequest', {
  2319. source: source,
  2320. disableRange: PDFJS.disableRange,
  2321. maxImageSize: PDFJS.maxImageSize,
  2322. cMapUrl: PDFJS.cMapUrl,
  2323. cMapPacked: PDFJS.cMapPacked,
  2324. disableFontFace: PDFJS.disableFontFace,
  2325. disableCreateObjectURL: PDFJS.disableCreateObjectURL,
  2326. verbosity: PDFJS.verbosity
  2327. });
  2328. },
  2329. getData: function WorkerTransport_getData() {
  2330. return this.messageHandler.sendWithPromise('GetData', null);
  2331. },
  2332. getPage: function WorkerTransport_getPage(pageNumber, capability) {
  2333. if (pageNumber <= 0 || pageNumber > this.numPages ||
  2334. (pageNumber|0) !== pageNumber) {
  2335. return Promise.reject(new Error('Invalid page request'));
  2336. }
  2337. var pageIndex = pageNumber - 1;
  2338. if (pageIndex in this.pagePromises) {
  2339. return this.pagePromises[pageIndex];
  2340. }
  2341. var promise = this.messageHandler.sendWithPromise('GetPage', {
  2342. pageIndex: pageIndex
  2343. }).then(function (pageInfo) {
  2344. var page = new PDFPageProxy(pageIndex, pageInfo, this);
  2345. this.pageCache[pageIndex] = page;
  2346. return page;
  2347. }.bind(this));
  2348. this.pagePromises[pageIndex] = promise;
  2349. return promise;
  2350. },
  2351. getPageIndex: function WorkerTransport_getPageIndexByRef(ref) {
  2352. return this.messageHandler.sendWithPromise('GetPageIndex', { ref: ref });
  2353. },
  2354. getAnnotations: function WorkerTransport_getAnnotations(pageIndex) {
  2355. return this.messageHandler.sendWithPromise('GetAnnotations',
  2356. { pageIndex: pageIndex });
  2357. },
  2358. getDestinations: function WorkerTransport_getDestinations() {
  2359. return this.messageHandler.sendWithPromise('GetDestinations', null);
  2360. },
  2361. getAttachments: function WorkerTransport_getAttachments() {
  2362. return this.messageHandler.sendWithPromise('GetAttachments', null);
  2363. },
  2364. getJavaScript: function WorkerTransport_getJavaScript() {
  2365. return this.messageHandler.sendWithPromise('GetJavaScript', null);
  2366. },
  2367. getOutline: function WorkerTransport_getOutline() {
  2368. return this.messageHandler.sendWithPromise('GetOutline', null);
  2369. },
  2370. getMetadata: function WorkerTransport_getMetadata() {
  2371. return this.messageHandler.sendWithPromise('GetMetadata', null).
  2372. then(function transportMetadata(results) {
  2373. return {
  2374. info: results[0],
  2375. metadata: (results[1] ? new PDFJS.Metadata(results[1]) : null)
  2376. };
  2377. });
  2378. },
  2379. getStats: function WorkerTransport_getStats() {
  2380. return this.messageHandler.sendWithPromise('GetStats', null);
  2381. },
  2382. startCleanup: function WorkerTransport_startCleanup() {
  2383. this.messageHandler.sendWithPromise('Cleanup', null).
  2384. then(function endCleanup() {
  2385. for (var i = 0, ii = this.pageCache.length; i < ii; i++) {
  2386. var page = this.pageCache[i];
  2387. if (page) {
  2388. page.destroy();
  2389. }
  2390. }
  2391. this.commonObjs.clear();
  2392. FontLoader.clear();
  2393. }.bind(this));
  2394. }
  2395. };
  2396. return WorkerTransport;
  2397. })();
  2398. /**
  2399. * A PDF document and page is built of many objects. E.g. there are objects
  2400. * for fonts, images, rendering code and such. These objects might get processed
  2401. * inside of a worker. The `PDFObjects` implements some basic functions to
  2402. * manage these objects.
  2403. * @ignore
  2404. */
  2405. var PDFObjects = (function PDFObjectsClosure() {
  2406. function PDFObjects() {
  2407. this.objs = {};
  2408. }
  2409. PDFObjects.prototype = {
  2410. /**
  2411. * Internal function.
  2412. * Ensures there is an object defined for `objId`.
  2413. */
  2414. ensureObj: function PDFObjects_ensureObj(objId) {
  2415. if (this.objs[objId]) {
  2416. return this.objs[objId];
  2417. }
  2418. var obj = {
  2419. capability: createPromiseCapability(),
  2420. data: null,
  2421. resolved: false
  2422. };
  2423. this.objs[objId] = obj;
  2424. return obj;
  2425. },
  2426. /**
  2427. * If called *without* callback, this returns the data of `objId` but the
  2428. * object needs to be resolved. If it isn't, this function throws.
  2429. *
  2430. * If called *with* a callback, the callback is called with the data of the
  2431. * object once the object is resolved. That means, if you call this
  2432. * function and the object is already resolved, the callback gets called
  2433. * right away.
  2434. */
  2435. get: function PDFObjects_get(objId, callback) {
  2436. // If there is a callback, then the get can be async and the object is
  2437. // not required to be resolved right now
  2438. if (callback) {
  2439. this.ensureObj(objId).capability.promise.then(callback);
  2440. return null;
  2441. }
  2442. // If there isn't a callback, the user expects to get the resolved data
  2443. // directly.
  2444. var obj = this.objs[objId];
  2445. // If there isn't an object yet or the object isn't resolved, then the
  2446. // data isn't ready yet!
  2447. if (!obj || !obj.resolved) {
  2448. error('Requesting object that isn\'t resolved yet ' + objId);
  2449. }
  2450. return obj.data;
  2451. },
  2452. /**
  2453. * Resolves the object `objId` with optional `data`.
  2454. */
  2455. resolve: function PDFObjects_resolve(objId, data) {
  2456. var obj = this.ensureObj(objId);
  2457. obj.resolved = true;
  2458. obj.data = data;
  2459. obj.capability.resolve(data);
  2460. },
  2461. isResolved: function PDFObjects_isResolved(objId) {
  2462. var objs = this.objs;
  2463. if (!objs[objId]) {
  2464. return false;
  2465. } else {
  2466. return objs[objId].resolved;
  2467. }
  2468. },
  2469. hasData: function PDFObjects_hasData(objId) {
  2470. return this.isResolved(objId);
  2471. },
  2472. /**
  2473. * Returns the data of `objId` if object exists, null otherwise.
  2474. */
  2475. getData: function PDFObjects_getData(objId) {
  2476. var objs = this.objs;
  2477. if (!objs[objId] || !objs[objId].resolved) {
  2478. return null;
  2479. } else {
  2480. return objs[objId].data;
  2481. }
  2482. },
  2483. clear: function PDFObjects_clear() {
  2484. this.objs = {};
  2485. }
  2486. };
  2487. return PDFObjects;
  2488. })();
  2489. /**
  2490. * Allows controlling of the rendering tasks.
  2491. * @class
  2492. */
  2493. var RenderTask = (function RenderTaskClosure() {
  2494. function RenderTask(internalRenderTask) {
  2495. this.internalRenderTask = internalRenderTask;
  2496. /**
  2497. * Promise for rendering task completion.
  2498. * @type {Promise}
  2499. */
  2500. this.promise = this.internalRenderTask.capability.promise;
  2501. }
  2502. RenderTask.prototype = /** @lends RenderTask.prototype */ {
  2503. /**
  2504. * Cancels the rendering task. If the task is currently rendering it will
  2505. * not be cancelled until graphics pauses with a timeout. The promise that
  2506. * this object extends will resolved when cancelled.
  2507. */
  2508. cancel: function RenderTask_cancel() {
  2509. this.internalRenderTask.cancel();
  2510. },
  2511. /**
  2512. * Registers callback to indicate the rendering task completion.
  2513. *
  2514. * @param {function} onFulfilled The callback for the rendering completion.
  2515. * @param {function} onRejected The callback for the rendering failure.
  2516. * @return {Promise} A promise that is resolved after the onFulfilled or
  2517. * onRejected callback.
  2518. */
  2519. then: function RenderTask_then(onFulfilled, onRejected) {
  2520. return this.promise.then(onFulfilled, onRejected);
  2521. }
  2522. };
  2523. return RenderTask;
  2524. })();
  2525. /**
  2526. * For internal use only.
  2527. * @ignore
  2528. */
  2529. var InternalRenderTask = (function InternalRenderTaskClosure() {
  2530. function InternalRenderTask(callback, params, objs, commonObjs, operatorList,
  2531. pageNumber) {
  2532. this.callback = callback;
  2533. this.params = params;
  2534. this.objs = objs;
  2535. this.commonObjs = commonObjs;
  2536. this.operatorListIdx = null;
  2537. this.operatorList = operatorList;
  2538. this.pageNumber = pageNumber;
  2539. this.running = false;
  2540. this.graphicsReadyCallback = null;
  2541. this.graphicsReady = false;
  2542. this.cancelled = false;
  2543. this.capability = createPromiseCapability();
  2544. // caching this-bound methods
  2545. this._continueBound = this._continue.bind(this);
  2546. this._scheduleNextBound = this._scheduleNext.bind(this);
  2547. this._nextBound = this._next.bind(this);
  2548. }
  2549. InternalRenderTask.prototype = {
  2550. initalizeGraphics:
  2551. function InternalRenderTask_initalizeGraphics(transparency) {
  2552. if (this.cancelled) {
  2553. return;
  2554. }
  2555. if (PDFJS.pdfBug && 'StepperManager' in globalScope &&
  2556. globalScope.StepperManager.enabled) {
  2557. this.stepper = globalScope.StepperManager.create(this.pageNumber - 1);
  2558. this.stepper.init(this.operatorList);
  2559. this.stepper.nextBreakPoint = this.stepper.getNextBreakPoint();
  2560. }
  2561. var params = this.params;
  2562. this.gfx = new CanvasGraphics(params.canvasContext, this.commonObjs,
  2563. this.objs, params.imageLayer);
  2564. this.gfx.beginDrawing(params.viewport, transparency);
  2565. this.operatorListIdx = 0;
  2566. this.graphicsReady = true;
  2567. if (this.graphicsReadyCallback) {
  2568. this.graphicsReadyCallback();
  2569. }
  2570. },
  2571. cancel: function InternalRenderTask_cancel() {
  2572. this.running = false;
  2573. this.cancelled = true;
  2574. this.callback('cancelled');
  2575. },
  2576. operatorListChanged: function InternalRenderTask_operatorListChanged() {
  2577. if (!this.graphicsReady) {
  2578. if (!this.graphicsReadyCallback) {
  2579. this.graphicsReadyCallback = this._continueBound;
  2580. }
  2581. return;
  2582. }
  2583. if (this.stepper) {
  2584. this.stepper.updateOperatorList(this.operatorList);
  2585. }
  2586. if (this.running) {
  2587. return;
  2588. }
  2589. this._continue();
  2590. },
  2591. _continue: function InternalRenderTask__continue() {
  2592. this.running = true;
  2593. if (this.cancelled) {
  2594. return;
  2595. }
  2596. if (this.params.continueCallback) {
  2597. this.params.continueCallback(this._scheduleNextBound);
  2598. } else {
  2599. this._scheduleNext();
  2600. }
  2601. },
  2602. _scheduleNext: function InternalRenderTask__scheduleNext() {
  2603. window.requestAnimationFrame(this._nextBound);
  2604. },
  2605. _next: function InternalRenderTask__next() {
  2606. if (this.cancelled) {
  2607. return;
  2608. }
  2609. this.operatorListIdx = this.gfx.executeOperatorList(this.operatorList,
  2610. this.operatorListIdx,
  2611. this._continueBound,
  2612. this.stepper);
  2613. if (this.operatorListIdx === this.operatorList.argsArray.length) {
  2614. this.running = false;
  2615. if (this.operatorList.lastChunk) {
  2616. this.gfx.endDrawing();
  2617. this.callback();
  2618. }
  2619. }
  2620. }
  2621. };
  2622. return InternalRenderTask;
  2623. })();
  2624. var Metadata = PDFJS.Metadata = (function MetadataClosure() {
  2625. function fixMetadata(meta) {
  2626. return meta.replace(/>\\376\\377([^<]+)/g, function(all, codes) {
  2627. var bytes = codes.replace(/\\([0-3])([0-7])([0-7])/g,
  2628. function(code, d1, d2, d3) {
  2629. return String.fromCharCode(d1 * 64 + d2 * 8 + d3 * 1);
  2630. });
  2631. var chars = '';
  2632. for (var i = 0; i < bytes.length; i += 2) {
  2633. var code = bytes.charCodeAt(i) * 256 + bytes.charCodeAt(i + 1);
  2634. chars += code >= 32 && code < 127 && code !== 60 && code !== 62 &&
  2635. code !== 38 && false ? String.fromCharCode(code) :
  2636. '&#x' + (0x10000 + code).toString(16).substring(1) + ';';
  2637. }
  2638. return '>' + chars;
  2639. });
  2640. }
  2641. function Metadata(meta) {
  2642. if (typeof meta === 'string') {
  2643. // Ghostscript produces invalid metadata
  2644. meta = fixMetadata(meta);
  2645. var parser = new DOMParser();
  2646. meta = parser.parseFromString(meta, 'application/xml');
  2647. } else if (!(meta instanceof Document)) {
  2648. error('Metadata: Invalid metadata object');
  2649. }
  2650. this.metaDocument = meta;
  2651. this.metadata = {};
  2652. this.parse();
  2653. }
  2654. Metadata.prototype = {
  2655. parse: function Metadata_parse() {
  2656. var doc = this.metaDocument;
  2657. var rdf = doc.documentElement;
  2658. if (rdf.nodeName.toLowerCase() !== 'rdf:rdf') { // Wrapped in <xmpmeta>
  2659. rdf = rdf.firstChild;
  2660. while (rdf && rdf.nodeName.toLowerCase() !== 'rdf:rdf') {
  2661. rdf = rdf.nextSibling;
  2662. }
  2663. }
  2664. var nodeName = (rdf) ? rdf.nodeName.toLowerCase() : null;
  2665. if (!rdf || nodeName !== 'rdf:rdf' || !rdf.hasChildNodes()) {
  2666. return;
  2667. }
  2668. var children = rdf.childNodes, desc, entry, name, i, ii, length, iLength;
  2669. for (i = 0, length = children.length; i < length; i++) {
  2670. desc = children[i];
  2671. if (desc.nodeName.toLowerCase() !== 'rdf:description') {
  2672. continue;
  2673. }
  2674. for (ii = 0, iLength = desc.childNodes.length; ii < iLength; ii++) {
  2675. if (desc.childNodes[ii].nodeName.toLowerCase() !== '#text') {
  2676. entry = desc.childNodes[ii];
  2677. name = entry.nodeName.toLowerCase();
  2678. this.metadata[name] = entry.textContent.trim();
  2679. }
  2680. }
  2681. }
  2682. },
  2683. get: function Metadata_get(name) {
  2684. return this.metadata[name] || null;
  2685. },
  2686. has: function Metadata_has(name) {
  2687. return typeof this.metadata[name] !== 'undefined';
  2688. }
  2689. };
  2690. return Metadata;
  2691. })();
  2692. // <canvas> contexts store most of the state we need natively.
  2693. // However, PDF needs a bit more state, which we store here.
  2694. // Minimal font size that would be used during canvas fillText operations.
  2695. var MIN_FONT_SIZE = 16;
  2696. var MAX_GROUP_SIZE = 4096;
  2697. var COMPILE_TYPE3_GLYPHS = true;
  2698. function createScratchCanvas(width, height) {
  2699. var canvas = document.createElement('canvas');
  2700. canvas.width = width;
  2701. canvas.height = height;
  2702. return canvas;
  2703. }
  2704. function addContextCurrentTransform(ctx) {
  2705. // If the context doesn't expose a `mozCurrentTransform`, add a JS based on.
  2706. if (!ctx.mozCurrentTransform) {
  2707. // Store the original context
  2708. ctx._scaleX = ctx._scaleX || 1.0;
  2709. ctx._scaleY = ctx._scaleY || 1.0;
  2710. ctx._originalSave = ctx.save;
  2711. ctx._originalRestore = ctx.restore;
  2712. ctx._originalRotate = ctx.rotate;
  2713. ctx._originalScale = ctx.scale;
  2714. ctx._originalTranslate = ctx.translate;
  2715. ctx._originalTransform = ctx.transform;
  2716. ctx._originalSetTransform = ctx.setTransform;
  2717. ctx._transformMatrix = [ctx._scaleX, 0, 0, ctx._scaleY, 0, 0];
  2718. ctx._transformStack = [];
  2719. Object.defineProperty(ctx, 'mozCurrentTransform', {
  2720. get: function getCurrentTransform() {
  2721. return this._transformMatrix;
  2722. }
  2723. });
  2724. Object.defineProperty(ctx, 'mozCurrentTransformInverse', {
  2725. get: function getCurrentTransformInverse() {
  2726. // Calculation done using WolframAlpha:
  2727. // http://www.wolframalpha.com/input/?
  2728. // i=Inverse+{{a%2C+c%2C+e}%2C+{b%2C+d%2C+f}%2C+{0%2C+0%2C+1}}
  2729. var m = this._transformMatrix;
  2730. var a = m[0], b = m[1], c = m[2], d = m[3], e = m[4], f = m[5];
  2731. var ad_bc = a * d - b * c;
  2732. var bc_ad = b * c - a * d;
  2733. return [
  2734. d / ad_bc,
  2735. b / bc_ad,
  2736. c / bc_ad,
  2737. a / ad_bc,
  2738. (d * e - c * f) / bc_ad,
  2739. (b * e - a * f) / ad_bc
  2740. ];
  2741. }
  2742. });
  2743. ctx.save = function ctxSave() {
  2744. var old = this._transformMatrix;
  2745. this._transformStack.push(old);
  2746. this._transformMatrix = old.slice(0, 6);
  2747. this._originalSave();
  2748. };
  2749. ctx.restore = function ctxRestore() {
  2750. var prev = this._transformStack.pop();
  2751. if (prev) {
  2752. this._transformMatrix = prev;
  2753. this._originalRestore();
  2754. }
  2755. };
  2756. ctx.translate = function ctxTranslate(x, y) {
  2757. var m = this._transformMatrix;
  2758. m[4] = m[0] * x + m[2] * y + m[4];
  2759. m[5] = m[1] * x + m[3] * y + m[5];
  2760. this._originalTranslate(x, y);
  2761. };
  2762. ctx.scale = function ctxScale(x, y) {
  2763. var m = this._transformMatrix;
  2764. m[0] = m[0] * x;
  2765. m[1] = m[1] * x;
  2766. m[2] = m[2] * y;
  2767. m[3] = m[3] * y;
  2768. this._originalScale(x, y);
  2769. };
  2770. ctx.transform = function ctxTransform(a, b, c, d, e, f) {
  2771. var m = this._transformMatrix;
  2772. this._transformMatrix = [
  2773. m[0] * a + m[2] * b,
  2774. m[1] * a + m[3] * b,
  2775. m[0] * c + m[2] * d,
  2776. m[1] * c + m[3] * d,
  2777. m[0] * e + m[2] * f + m[4],
  2778. m[1] * e + m[3] * f + m[5]
  2779. ];
  2780. ctx._originalTransform(a, b, c, d, e, f);
  2781. };
  2782. ctx.setTransform = function ctxSetTransform(a, b, c, d, e, f) {
  2783. this._transformMatrix = [a, b, c, d, e, f];
  2784. ctx._originalSetTransform(a, b, c, d, e, f);
  2785. };
  2786. ctx.rotate = function ctxRotate(angle) {
  2787. var cosValue = Math.cos(angle);
  2788. var sinValue = Math.sin(angle);
  2789. var m = this._transformMatrix;
  2790. this._transformMatrix = [
  2791. m[0] * cosValue + m[2] * sinValue,
  2792. m[1] * cosValue + m[3] * sinValue,
  2793. m[0] * (-sinValue) + m[2] * cosValue,
  2794. m[1] * (-sinValue) + m[3] * cosValue,
  2795. m[4],
  2796. m[5]
  2797. ];
  2798. this._originalRotate(angle);
  2799. };
  2800. }
  2801. }
  2802. var CachedCanvases = (function CachedCanvasesClosure() {
  2803. var cache = {};
  2804. return {
  2805. getCanvas: function CachedCanvases_getCanvas(id, width, height,
  2806. trackTransform) {
  2807. var canvasEntry;
  2808. if (id in cache) {
  2809. canvasEntry = cache[id];
  2810. canvasEntry.canvas.width = width;
  2811. canvasEntry.canvas.height = height;
  2812. // reset canvas transform for emulated mozCurrentTransform, if needed
  2813. canvasEntry.context.setTransform(1, 0, 0, 1, 0, 0);
  2814. } else {
  2815. var canvas = createScratchCanvas(width, height);
  2816. var ctx = canvas.getContext('2d');
  2817. if (trackTransform) {
  2818. addContextCurrentTransform(ctx);
  2819. }
  2820. cache[id] = canvasEntry = {canvas: canvas, context: ctx};
  2821. }
  2822. return canvasEntry;
  2823. },
  2824. clear: function () {
  2825. for (var id in cache) {
  2826. var canvasEntry = cache[id];
  2827. // Zeroing the width and height causes Firefox to release graphics
  2828. // resources immediately, which can greatly reduce memory consumption.
  2829. canvasEntry.canvas.width = 0;
  2830. canvasEntry.canvas.height = 0;
  2831. delete cache[id];
  2832. }
  2833. }
  2834. };
  2835. })();
  2836. function compileType3Glyph(imgData) {
  2837. var POINT_TO_PROCESS_LIMIT = 1000;
  2838. var width = imgData.width, height = imgData.height;
  2839. var i, j, j0, width1 = width + 1;
  2840. var points = new Uint8Array(width1 * (height + 1));
  2841. var POINT_TYPES =
  2842. new Uint8Array([0, 2, 4, 0, 1, 0, 5, 4, 8, 10, 0, 8, 0, 2, 1, 0]);
  2843. // decodes bit-packed mask data
  2844. var lineSize = (width + 7) & ~7, data0 = imgData.data;
  2845. var data = new Uint8Array(lineSize * height), pos = 0, ii;
  2846. for (i = 0, ii = data0.length; i < ii; i++) {
  2847. var mask = 128, elem = data0[i];
  2848. while (mask > 0) {
  2849. data[pos++] = (elem & mask) ? 0 : 255;
  2850. mask >>= 1;
  2851. }
  2852. }
  2853. // finding iteresting points: every point is located between mask pixels,
  2854. // so there will be points of the (width + 1)x(height + 1) grid. Every point
  2855. // will have flags assigned based on neighboring mask pixels:
  2856. // 4 | 8
  2857. // --P--
  2858. // 2 | 1
  2859. // We are interested only in points with the flags:
  2860. // - outside corners: 1, 2, 4, 8;
  2861. // - inside corners: 7, 11, 13, 14;
  2862. // - and, intersections: 5, 10.
  2863. var count = 0;
  2864. pos = 0;
  2865. if (data[pos] !== 0) {
  2866. points[0] = 1;
  2867. ++count;
  2868. }
  2869. for (j = 1; j < width; j++) {
  2870. if (data[pos] !== data[pos + 1]) {
  2871. points[j] = data[pos] ? 2 : 1;
  2872. ++count;
  2873. }
  2874. pos++;
  2875. }
  2876. if (data[pos] !== 0) {
  2877. points[j] = 2;
  2878. ++count;
  2879. }
  2880. for (i = 1; i < height; i++) {
  2881. pos = i * lineSize;
  2882. j0 = i * width1;
  2883. if (data[pos - lineSize] !== data[pos]) {
  2884. points[j0] = data[pos] ? 1 : 8;
  2885. ++count;
  2886. }
  2887. // 'sum' is the position of the current pixel configuration in the 'TYPES'
  2888. // array (in order 8-1-2-4, so we can use '>>2' to shift the column).
  2889. var sum = (data[pos] ? 4 : 0) + (data[pos - lineSize] ? 8 : 0);
  2890. for (j = 1; j < width; j++) {
  2891. sum = (sum >> 2) + (data[pos + 1] ? 4 : 0) +
  2892. (data[pos - lineSize + 1] ? 8 : 0);
  2893. if (POINT_TYPES[sum]) {
  2894. points[j0 + j] = POINT_TYPES[sum];
  2895. ++count;
  2896. }
  2897. pos++;
  2898. }
  2899. if (data[pos - lineSize] !== data[pos]) {
  2900. points[j0 + j] = data[pos] ? 2 : 4;
  2901. ++count;
  2902. }
  2903. if (count > POINT_TO_PROCESS_LIMIT) {
  2904. return null;
  2905. }
  2906. }
  2907. pos = lineSize * (height - 1);
  2908. j0 = i * width1;
  2909. if (data[pos] !== 0) {
  2910. points[j0] = 8;
  2911. ++count;
  2912. }
  2913. for (j = 1; j < width; j++) {
  2914. if (data[pos] !== data[pos + 1]) {
  2915. points[j0 + j] = data[pos] ? 4 : 8;
  2916. ++count;
  2917. }
  2918. pos++;
  2919. }
  2920. if (data[pos] !== 0) {
  2921. points[j0 + j] = 4;
  2922. ++count;
  2923. }
  2924. if (count > POINT_TO_PROCESS_LIMIT) {
  2925. return null;
  2926. }
  2927. // building outlines
  2928. var steps = new Int32Array([0, width1, -1, 0, -width1, 0, 0, 0, 1]);
  2929. var outlines = [];
  2930. for (i = 0; count && i <= height; i++) {
  2931. var p = i * width1;
  2932. var end = p + width;
  2933. while (p < end && !points[p]) {
  2934. p++;
  2935. }
  2936. if (p === end) {
  2937. continue;
  2938. }
  2939. var coords = [p % width1, i];
  2940. var type = points[p], p0 = p, pp;
  2941. do {
  2942. var step = steps[type];
  2943. do {
  2944. p += step;
  2945. } while (!points[p]);
  2946. pp = points[p];
  2947. if (pp !== 5 && pp !== 10) {
  2948. // set new direction
  2949. type = pp;
  2950. // delete mark
  2951. points[p] = 0;
  2952. } else { // type is 5 or 10, ie, a crossing
  2953. // set new direction
  2954. type = pp & ((0x33 * type) >> 4);
  2955. // set new type for "future hit"
  2956. points[p] &= (type >> 2 | type << 2);
  2957. }
  2958. coords.push(p % width1);
  2959. coords.push((p / width1) | 0);
  2960. --count;
  2961. } while (p0 !== p);
  2962. outlines.push(coords);
  2963. --i;
  2964. }
  2965. var drawOutline = function(c) {
  2966. c.save();
  2967. // the path shall be painted in [0..1]x[0..1] space
  2968. c.scale(1 / width, -1 / height);
  2969. c.translate(0, -height);
  2970. c.beginPath();
  2971. for (var i = 0, ii = outlines.length; i < ii; i++) {
  2972. var o = outlines[i];
  2973. c.moveTo(o[0], o[1]);
  2974. for (var j = 2, jj = o.length; j < jj; j += 2) {
  2975. c.lineTo(o[j], o[j+1]);
  2976. }
  2977. }
  2978. c.fill();
  2979. c.beginPath();
  2980. c.restore();
  2981. };
  2982. return drawOutline;
  2983. }
  2984. var CanvasExtraState = (function CanvasExtraStateClosure() {
  2985. function CanvasExtraState(old) {
  2986. // Are soft masks and alpha values shapes or opacities?
  2987. this.alphaIsShape = false;
  2988. this.fontSize = 0;
  2989. this.fontSizeScale = 1;
  2990. this.textMatrix = IDENTITY_MATRIX;
  2991. this.textMatrixScale = 1;
  2992. this.fontMatrix = FONT_IDENTITY_MATRIX;
  2993. this.leading = 0;
  2994. // Current point (in user coordinates)
  2995. this.x = 0;
  2996. this.y = 0;
  2997. // Start of text line (in text coordinates)
  2998. this.lineX = 0;
  2999. this.lineY = 0;
  3000. // Character and word spacing
  3001. this.charSpacing = 0;
  3002. this.wordSpacing = 0;
  3003. this.textHScale = 1;
  3004. this.textRenderingMode = TextRenderingMode.FILL;
  3005. this.textRise = 0;
  3006. // Default fore and background colors
  3007. this.fillColor = '#000000';
  3008. this.strokeColor = '#000000';
  3009. // Note: fill alpha applies to all non-stroking operations
  3010. this.fillAlpha = 1;
  3011. this.strokeAlpha = 1;
  3012. this.lineWidth = 1;
  3013. this.activeSMask = null; // nonclonable field (see the save method below)
  3014. this.old = old;
  3015. }
  3016. CanvasExtraState.prototype = {
  3017. clone: function CanvasExtraState_clone() {
  3018. return Object.create(this);
  3019. },
  3020. setCurrentPoint: function CanvasExtraState_setCurrentPoint(x, y) {
  3021. this.x = x;
  3022. this.y = y;
  3023. }
  3024. };
  3025. return CanvasExtraState;
  3026. })();
  3027. var CanvasGraphics = (function CanvasGraphicsClosure() {
  3028. // Defines the time the executeOperatorList is going to be executing
  3029. // before it stops and shedules a continue of execution.
  3030. var EXECUTION_TIME = 15;
  3031. // Defines the number of steps before checking the execution time
  3032. var EXECUTION_STEPS = 10;
  3033. function CanvasGraphics(canvasCtx, commonObjs, objs, imageLayer) {
  3034. this.ctx = canvasCtx;
  3035. this.current = new CanvasExtraState();
  3036. this.stateStack = [];
  3037. this.pendingClip = null;
  3038. this.pendingEOFill = false;
  3039. this.res = null;
  3040. this.xobjs = null;
  3041. this.commonObjs = commonObjs;
  3042. this.objs = objs;
  3043. this.imageLayer = imageLayer;
  3044. this.groupStack = [];
  3045. this.processingType3 = null;
  3046. // Patterns are painted relative to the initial page/form transform, see pdf
  3047. // spec 8.7.2 NOTE 1.
  3048. this.baseTransform = null;
  3049. this.baseTransformStack = [];
  3050. this.groupLevel = 0;
  3051. this.smaskStack = [];
  3052. this.smaskCounter = 0;
  3053. this.tempSMask = null;
  3054. if (canvasCtx) {
  3055. addContextCurrentTransform(canvasCtx);
  3056. }
  3057. }
  3058. function putBinaryImageData(ctx, imgData) {
  3059. if (typeof ImageData !== 'undefined' && imgData instanceof ImageData) {
  3060. ctx.putImageData(imgData, 0, 0);
  3061. return;
  3062. }
  3063. // Put the image data to the canvas in chunks, rather than putting the
  3064. // whole image at once. This saves JS memory, because the ImageData object
  3065. // is smaller. It also possibly saves C++ memory within the implementation
  3066. // of putImageData(). (E.g. in Firefox we make two short-lived copies of
  3067. // the data passed to putImageData()). |n| shouldn't be too small, however,
  3068. // because too many putImageData() calls will slow things down.
  3069. //
  3070. // Note: as written, if the last chunk is partial, the putImageData() call
  3071. // will (conceptually) put pixels past the bounds of the canvas. But
  3072. // that's ok; any such pixels are ignored.
  3073. var height = imgData.height, width = imgData.width;
  3074. var fullChunkHeight = 16;
  3075. var fracChunks = height / fullChunkHeight;
  3076. var fullChunks = Math.floor(fracChunks);
  3077. var totalChunks = Math.ceil(fracChunks);
  3078. var partialChunkHeight = height - fullChunks * fullChunkHeight;
  3079. var chunkImgData = ctx.createImageData(width, fullChunkHeight);
  3080. var srcPos = 0, destPos;
  3081. var src = imgData.data;
  3082. var dest = chunkImgData.data;
  3083. var i, j, thisChunkHeight, elemsInThisChunk;
  3084. // There are multiple forms in which the pixel data can be passed, and
  3085. // imgData.kind tells us which one this is.
  3086. if (imgData.kind === ImageKind.GRAYSCALE_1BPP) {
  3087. // Grayscale, 1 bit per pixel (i.e. black-and-white).
  3088. var srcLength = src.byteLength;
  3089. var dest32 = PDFJS.hasCanvasTypedArrays ? new Uint32Array(dest.buffer) :
  3090. new Uint32ArrayView(dest);
  3091. var dest32DataLength = dest32.length;
  3092. var fullSrcDiff = (width + 7) >> 3;
  3093. var white = 0xFFFFFFFF;
  3094. var black = (PDFJS.isLittleEndian || !PDFJS.hasCanvasTypedArrays) ?
  3095. 0xFF000000 : 0x000000FF;
  3096. for (i = 0; i < totalChunks; i++) {
  3097. thisChunkHeight =
  3098. (i < fullChunks) ? fullChunkHeight : partialChunkHeight;
  3099. destPos = 0;
  3100. for (j = 0; j < thisChunkHeight; j++) {
  3101. var srcDiff = srcLength - srcPos;
  3102. var k = 0;
  3103. var kEnd = (srcDiff > fullSrcDiff) ? width : srcDiff * 8 - 7;
  3104. var kEndUnrolled = kEnd & ~7;
  3105. var mask = 0;
  3106. var srcByte = 0;
  3107. for (; k < kEndUnrolled; k += 8) {
  3108. srcByte = src[srcPos++];
  3109. dest32[destPos++] = (srcByte & 128) ? white : black;
  3110. dest32[destPos++] = (srcByte & 64) ? white : black;
  3111. dest32[destPos++] = (srcByte & 32) ? white : black;
  3112. dest32[destPos++] = (srcByte & 16) ? white : black;
  3113. dest32[destPos++] = (srcByte & 8) ? white : black;
  3114. dest32[destPos++] = (srcByte & 4) ? white : black;
  3115. dest32[destPos++] = (srcByte & 2) ? white : black;
  3116. dest32[destPos++] = (srcByte & 1) ? white : black;
  3117. }
  3118. for (; k < kEnd; k++) {
  3119. if (mask === 0) {
  3120. srcByte = src[srcPos++];
  3121. mask = 128;
  3122. }
  3123. dest32[destPos++] = (srcByte & mask) ? white : black;
  3124. mask >>= 1;
  3125. }
  3126. }
  3127. // We ran out of input. Make all remaining pixels transparent.
  3128. while (destPos < dest32DataLength) {
  3129. dest32[destPos++] = 0;
  3130. }
  3131. ctx.putImageData(chunkImgData, 0, i * fullChunkHeight);
  3132. }
  3133. } else if (imgData.kind === ImageKind.RGBA_32BPP) {
  3134. // RGBA, 32-bits per pixel.
  3135. j = 0;
  3136. elemsInThisChunk = width * fullChunkHeight * 4;
  3137. for (i = 0; i < fullChunks; i++) {
  3138. dest.set(src.subarray(srcPos, srcPos + elemsInThisChunk));
  3139. srcPos += elemsInThisChunk;
  3140. ctx.putImageData(chunkImgData, 0, j);
  3141. j += fullChunkHeight;
  3142. }
  3143. if (i < totalChunks) {
  3144. elemsInThisChunk = width * partialChunkHeight * 4;
  3145. dest.set(src.subarray(srcPos, srcPos + elemsInThisChunk));
  3146. ctx.putImageData(chunkImgData, 0, j);
  3147. }
  3148. } else if (imgData.kind === ImageKind.RGB_24BPP) {
  3149. // RGB, 24-bits per pixel.
  3150. thisChunkHeight = fullChunkHeight;
  3151. elemsInThisChunk = width * thisChunkHeight;
  3152. for (i = 0; i < totalChunks; i++) {
  3153. if (i >= fullChunks) {
  3154. thisChunkHeight =partialChunkHeight;
  3155. elemsInThisChunk = width * thisChunkHeight;
  3156. }
  3157. destPos = 0;
  3158. for (j = elemsInThisChunk; j--;) {
  3159. dest[destPos++] = src[srcPos++];
  3160. dest[destPos++] = src[srcPos++];
  3161. dest[destPos++] = src[srcPos++];
  3162. dest[destPos++] = 255;
  3163. }
  3164. ctx.putImageData(chunkImgData, 0, i * fullChunkHeight);
  3165. }
  3166. } else {
  3167. error('bad image kind: ' + imgData.kind);
  3168. }
  3169. }
  3170. function putBinaryImageMask(ctx, imgData) {
  3171. var height = imgData.height, width = imgData.width;
  3172. var fullChunkHeight = 16;
  3173. var fracChunks = height / fullChunkHeight;
  3174. var fullChunks = Math.floor(fracChunks);
  3175. var totalChunks = Math.ceil(fracChunks);
  3176. var partialChunkHeight = height - fullChunks * fullChunkHeight;
  3177. var chunkImgData = ctx.createImageData(width, fullChunkHeight);
  3178. var srcPos = 0;
  3179. var src = imgData.data;
  3180. var dest = chunkImgData.data;
  3181. for (var i = 0; i < totalChunks; i++) {
  3182. var thisChunkHeight =
  3183. (i < fullChunks) ? fullChunkHeight : partialChunkHeight;
  3184. // Expand the mask so it can be used by the canvas. Any required
  3185. // inversion has already been handled.
  3186. var destPos = 3; // alpha component offset
  3187. for (var j = 0; j < thisChunkHeight; j++) {
  3188. var mask = 0;
  3189. for (var k = 0; k < width; k++) {
  3190. if (!mask) {
  3191. var elem = src[srcPos++];
  3192. mask = 128;
  3193. }
  3194. dest[destPos] = (elem & mask) ? 0 : 255;
  3195. destPos += 4;
  3196. mask >>= 1;
  3197. }
  3198. }
  3199. ctx.putImageData(chunkImgData, 0, i * fullChunkHeight);
  3200. }
  3201. }
  3202. function copyCtxState(sourceCtx, destCtx) {
  3203. var properties = ['strokeStyle', 'fillStyle', 'fillRule', 'globalAlpha',
  3204. 'lineWidth', 'lineCap', 'lineJoin', 'miterLimit',
  3205. 'globalCompositeOperation', 'font'];
  3206. for (var i = 0, ii = properties.length; i < ii; i++) {
  3207. var property = properties[i];
  3208. if (property in sourceCtx) {
  3209. destCtx[property] = sourceCtx[property];
  3210. }
  3211. }
  3212. if ('setLineDash' in sourceCtx) {
  3213. destCtx.setLineDash(sourceCtx.getLineDash());
  3214. destCtx.lineDashOffset = sourceCtx.lineDashOffset;
  3215. } else if ('mozDash' in sourceCtx) {
  3216. destCtx.mozDash = sourceCtx.mozDash;
  3217. destCtx.mozDashOffset = sourceCtx.mozDashOffset;
  3218. }
  3219. }
  3220. function composeSMaskBackdrop(bytes, r0, g0, b0) {
  3221. var length = bytes.length;
  3222. for (var i = 3; i < length; i += 4) {
  3223. var alpha = bytes[i];
  3224. if (alpha === 0) {
  3225. bytes[i - 3] = r0;
  3226. bytes[i - 2] = g0;
  3227. bytes[i - 1] = b0;
  3228. } else if (alpha < 255) {
  3229. var alpha_ = 255 - alpha;
  3230. bytes[i - 3] = (bytes[i - 3] * alpha + r0 * alpha_) >> 8;
  3231. bytes[i - 2] = (bytes[i - 2] * alpha + g0 * alpha_) >> 8;
  3232. bytes[i - 1] = (bytes[i - 1] * alpha + b0 * alpha_) >> 8;
  3233. }
  3234. }
  3235. }
  3236. function composeSMaskAlpha(maskData, layerData) {
  3237. var length = maskData.length;
  3238. var scale = 1 / 255;
  3239. for (var i = 3; i < length; i += 4) {
  3240. var alpha = maskData[i];
  3241. layerData[i] = (layerData[i] * alpha * scale) | 0;
  3242. }
  3243. }
  3244. function composeSMaskLuminosity(maskData, layerData) {
  3245. var length = maskData.length;
  3246. for (var i = 3; i < length; i += 4) {
  3247. var y = ((maskData[i - 3] * 77) + // * 0.3 / 255 * 0x10000
  3248. (maskData[i - 2] * 152) + // * 0.59 ....
  3249. (maskData[i - 1] * 28)) | 0; // * 0.11 ....
  3250. layerData[i] = (layerData[i] * y) >> 16;
  3251. }
  3252. }
  3253. function genericComposeSMask(maskCtx, layerCtx, width, height,
  3254. subtype, backdrop) {
  3255. var hasBackdrop = !!backdrop;
  3256. var r0 = hasBackdrop ? backdrop[0] : 0;
  3257. var g0 = hasBackdrop ? backdrop[1] : 0;
  3258. var b0 = hasBackdrop ? backdrop[2] : 0;
  3259. var composeFn;
  3260. if (subtype === 'Luminosity') {
  3261. composeFn = composeSMaskLuminosity;
  3262. } else {
  3263. composeFn = composeSMaskAlpha;
  3264. }
  3265. // processing image in chunks to save memory
  3266. var PIXELS_TO_PROCESS = 65536;
  3267. var chunkSize = Math.min(height, Math.ceil(PIXELS_TO_PROCESS / width));
  3268. for (var row = 0; row < height; row += chunkSize) {
  3269. var chunkHeight = Math.min(chunkSize, height - row);
  3270. var maskData = maskCtx.getImageData(0, row, width, chunkHeight);
  3271. var layerData = layerCtx.getImageData(0, row, width, chunkHeight);
  3272. if (hasBackdrop) {
  3273. composeSMaskBackdrop(maskData.data, r0, g0, b0);
  3274. }
  3275. composeFn(maskData.data, layerData.data);
  3276. maskCtx.putImageData(layerData, 0, row);
  3277. }
  3278. }
  3279. function composeSMask(ctx, smask, layerCtx) {
  3280. var mask = smask.canvas;
  3281. var maskCtx = smask.context;
  3282. ctx.setTransform(smask.scaleX, 0, 0, smask.scaleY,
  3283. smask.offsetX, smask.offsetY);
  3284. var backdrop = smask.backdrop || null;
  3285. if (WebGLUtils.isEnabled) {
  3286. var composed = WebGLUtils.composeSMask(layerCtx.canvas, mask,
  3287. {subtype: smask.subtype, backdrop: backdrop});
  3288. ctx.setTransform(1, 0, 0, 1, 0, 0);
  3289. ctx.drawImage(composed, smask.offsetX, smask.offsetY);
  3290. return;
  3291. }
  3292. genericComposeSMask(maskCtx, layerCtx, mask.width, mask.height,
  3293. smask.subtype, backdrop);
  3294. ctx.drawImage(mask, 0, 0);
  3295. }
  3296. var LINE_CAP_STYLES = ['butt', 'round', 'square'];
  3297. var LINE_JOIN_STYLES = ['miter', 'round', 'bevel'];
  3298. var NORMAL_CLIP = {};
  3299. var EO_CLIP = {};
  3300. CanvasGraphics.prototype = {
  3301. beginDrawing: function CanvasGraphics_beginDrawing(viewport, transparency) {
  3302. // For pdfs that use blend modes we have to clear the canvas else certain
  3303. // blend modes can look wrong since we'd be blending with a white
  3304. // backdrop. The problem with a transparent backdrop though is we then
  3305. // don't get sub pixel anti aliasing on text, so we fill with white if
  3306. // we can.
  3307. var width = this.ctx.canvas.width;
  3308. var height = this.ctx.canvas.height;
  3309. if (transparency) {
  3310. this.ctx.clearRect(0, 0, width, height);
  3311. } else {
  3312. this.ctx.mozOpaque = true;
  3313. this.ctx.save();
  3314. this.ctx.fillStyle = 'rgb(255, 255, 255)';
  3315. this.ctx.fillRect(0, 0, width, height);
  3316. this.ctx.restore();
  3317. }
  3318. var transform = viewport.transform;
  3319. this.ctx.save();
  3320. this.ctx.transform.apply(this.ctx, transform);
  3321. this.baseTransform = this.ctx.mozCurrentTransform.slice();
  3322. if (this.imageLayer) {
  3323. this.imageLayer.beginLayout();
  3324. }
  3325. },
  3326. executeOperatorList: function CanvasGraphics_executeOperatorList(
  3327. operatorList,
  3328. executionStartIdx, continueCallback,
  3329. stepper) {
  3330. var argsArray = operatorList.argsArray;
  3331. var fnArray = operatorList.fnArray;
  3332. var i = executionStartIdx || 0;
  3333. var argsArrayLen = argsArray.length;
  3334. // Sometimes the OperatorList to execute is empty.
  3335. if (argsArrayLen === i) {
  3336. return i;
  3337. }
  3338. var chunkOperations = (argsArrayLen - i > EXECUTION_STEPS &&
  3339. typeof continueCallback === 'function');
  3340. var endTime = chunkOperations ? Date.now() + EXECUTION_TIME : 0;
  3341. var steps = 0;
  3342. var commonObjs = this.commonObjs;
  3343. var objs = this.objs;
  3344. var fnId;
  3345. while (true) {
  3346. if (stepper !== undefined && i === stepper.nextBreakPoint) {
  3347. stepper.breakIt(i, continueCallback);
  3348. return i;
  3349. }
  3350. fnId = fnArray[i];
  3351. if (fnId !== OPS.dependency) {
  3352. this[fnId].apply(this, argsArray[i]);
  3353. } else {
  3354. var deps = argsArray[i];
  3355. for (var n = 0, nn = deps.length; n < nn; n++) {
  3356. var depObjId = deps[n];
  3357. var common = depObjId[0] === 'g' && depObjId[1] === '_';
  3358. var objsPool = common ? commonObjs : objs;
  3359. // If the promise isn't resolved yet, add the continueCallback
  3360. // to the promise and bail out.
  3361. if (!objsPool.isResolved(depObjId)) {
  3362. objsPool.get(depObjId, continueCallback);
  3363. return i;
  3364. }
  3365. }
  3366. }
  3367. i++;
  3368. // If the entire operatorList was executed, stop as were done.
  3369. if (i === argsArrayLen) {
  3370. return i;
  3371. }
  3372. // If the execution took longer then a certain amount of time and
  3373. // `continueCallback` is specified, interrupt the execution.
  3374. if (chunkOperations && ++steps > EXECUTION_STEPS) {
  3375. if (Date.now() > endTime) {
  3376. continueCallback();
  3377. return i;
  3378. }
  3379. steps = 0;
  3380. }
  3381. // If the operatorList isn't executed completely yet OR the execution
  3382. // time was short enough, do another execution round.
  3383. }
  3384. },
  3385. endDrawing: function CanvasGraphics_endDrawing() {
  3386. this.ctx.restore();
  3387. CachedCanvases.clear();
  3388. WebGLUtils.clear();
  3389. if (this.imageLayer) {
  3390. this.imageLayer.endLayout();
  3391. }
  3392. },
  3393. // Graphics state
  3394. setLineWidth: function CanvasGraphics_setLineWidth(width) {
  3395. this.current.lineWidth = width;
  3396. this.ctx.lineWidth = width;
  3397. },
  3398. setLineCap: function CanvasGraphics_setLineCap(style) {
  3399. this.ctx.lineCap = LINE_CAP_STYLES[style];
  3400. },
  3401. setLineJoin: function CanvasGraphics_setLineJoin(style) {
  3402. this.ctx.lineJoin = LINE_JOIN_STYLES[style];
  3403. },
  3404. setMiterLimit: function CanvasGraphics_setMiterLimit(limit) {
  3405. this.ctx.miterLimit = limit;
  3406. },
  3407. setDash: function CanvasGraphics_setDash(dashArray, dashPhase) {
  3408. var ctx = this.ctx;
  3409. if ('setLineDash' in ctx) {
  3410. ctx.setLineDash(dashArray);
  3411. ctx.lineDashOffset = dashPhase;
  3412. } else {
  3413. ctx.mozDash = dashArray;
  3414. ctx.mozDashOffset = dashPhase;
  3415. }
  3416. },
  3417. setRenderingIntent: function CanvasGraphics_setRenderingIntent(intent) {
  3418. // Maybe if we one day fully support color spaces this will be important
  3419. // for now we can ignore.
  3420. // TODO set rendering intent?
  3421. },
  3422. setFlatness: function CanvasGraphics_setFlatness(flatness) {
  3423. // There's no way to control this with canvas, but we can safely ignore.
  3424. // TODO set flatness?
  3425. },
  3426. setGState: function CanvasGraphics_setGState(states) {
  3427. for (var i = 0, ii = states.length; i < ii; i++) {
  3428. var state = states[i];
  3429. var key = state[0];
  3430. var value = state[1];
  3431. switch (key) {
  3432. case 'LW':
  3433. this.setLineWidth(value);
  3434. break;
  3435. case 'LC':
  3436. this.setLineCap(value);
  3437. break;
  3438. case 'LJ':
  3439. this.setLineJoin(value);
  3440. break;
  3441. case 'ML':
  3442. this.setMiterLimit(value);
  3443. break;
  3444. case 'D':
  3445. this.setDash(value[0], value[1]);
  3446. break;
  3447. case 'RI':
  3448. this.setRenderingIntent(value);
  3449. break;
  3450. case 'FL':
  3451. this.setFlatness(value);
  3452. break;
  3453. case 'Font':
  3454. this.setFont(value[0], value[1]);
  3455. break;
  3456. case 'CA':
  3457. this.current.strokeAlpha = state[1];
  3458. break;
  3459. case 'ca':
  3460. this.current.fillAlpha = state[1];
  3461. this.ctx.globalAlpha = state[1];
  3462. break;
  3463. case 'BM':
  3464. if (value && value.name && (value.name !== 'Normal')) {
  3465. var mode = value.name.replace(/([A-Z])/g,
  3466. function(c) {
  3467. return '-' + c.toLowerCase();
  3468. }
  3469. ).substring(1);
  3470. this.ctx.globalCompositeOperation = mode;
  3471. if (this.ctx.globalCompositeOperation !== mode) {
  3472. warn('globalCompositeOperation "' + mode +
  3473. '" is not supported');
  3474. }
  3475. } else {
  3476. this.ctx.globalCompositeOperation = 'source-over';
  3477. }
  3478. break;
  3479. case 'SMask':
  3480. if (this.current.activeSMask) {
  3481. this.endSMaskGroup();
  3482. }
  3483. this.current.activeSMask = value ? this.tempSMask : null;
  3484. if (this.current.activeSMask) {
  3485. this.beginSMaskGroup();
  3486. }
  3487. this.tempSMask = null;
  3488. break;
  3489. }
  3490. }
  3491. },
  3492. beginSMaskGroup: function CanvasGraphics_beginSMaskGroup() {
  3493. var activeSMask = this.current.activeSMask;
  3494. var drawnWidth = activeSMask.canvas.width;
  3495. var drawnHeight = activeSMask.canvas.height;
  3496. var cacheId = 'smaskGroupAt' + this.groupLevel;
  3497. var scratchCanvas = CachedCanvases.getCanvas(
  3498. cacheId, drawnWidth, drawnHeight, true);
  3499. var currentCtx = this.ctx;
  3500. var currentTransform = currentCtx.mozCurrentTransform;
  3501. this.ctx.save();
  3502. var groupCtx = scratchCanvas.context;
  3503. groupCtx.scale(1 / activeSMask.scaleX, 1 / activeSMask.scaleY);
  3504. groupCtx.translate(-activeSMask.offsetX, -activeSMask.offsetY);
  3505. groupCtx.transform.apply(groupCtx, currentTransform);
  3506. copyCtxState(currentCtx, groupCtx);
  3507. this.ctx = groupCtx;
  3508. this.setGState([
  3509. ['BM', 'Normal'],
  3510. ['ca', 1],
  3511. ['CA', 1]
  3512. ]);
  3513. this.groupStack.push(currentCtx);
  3514. this.groupLevel++;
  3515. },
  3516. endSMaskGroup: function CanvasGraphics_endSMaskGroup() {
  3517. var groupCtx = this.ctx;
  3518. this.groupLevel--;
  3519. this.ctx = this.groupStack.pop();
  3520. composeSMask(this.ctx, this.current.activeSMask, groupCtx);
  3521. this.ctx.restore();
  3522. },
  3523. save: function CanvasGraphics_save() {
  3524. this.ctx.save();
  3525. var old = this.current;
  3526. this.stateStack.push(old);
  3527. this.current = old.clone();
  3528. this.current.activeSMask = null;
  3529. },
  3530. restore: function CanvasGraphics_restore() {
  3531. if (this.stateStack.length !== 0) {
  3532. if (this.current.activeSMask !== null) {
  3533. this.endSMaskGroup();
  3534. }
  3535. this.current = this.stateStack.pop();
  3536. this.ctx.restore();
  3537. }
  3538. },
  3539. transform: function CanvasGraphics_transform(a, b, c, d, e, f) {
  3540. this.ctx.transform(a, b, c, d, e, f);
  3541. },
  3542. // Path
  3543. constructPath: function CanvasGraphics_constructPath(ops, args) {
  3544. var ctx = this.ctx;
  3545. var current = this.current;
  3546. var x = current.x, y = current.y;
  3547. for (var i = 0, j = 0, ii = ops.length; i < ii; i++) {
  3548. switch (ops[i] | 0) {
  3549. case OPS.rectangle:
  3550. x = args[j++];
  3551. y = args[j++];
  3552. var width = args[j++];
  3553. var height = args[j++];
  3554. if (width === 0) {
  3555. width = this.getSinglePixelWidth();
  3556. }
  3557. if (height === 0) {
  3558. height = this.getSinglePixelWidth();
  3559. }
  3560. var xw = x + width;
  3561. var yh = y + height;
  3562. this.ctx.moveTo(x, y);
  3563. this.ctx.lineTo(xw, y);
  3564. this.ctx.lineTo(xw, yh);
  3565. this.ctx.lineTo(x, yh);
  3566. this.ctx.lineTo(x, y);
  3567. this.ctx.closePath();
  3568. break;
  3569. case OPS.moveTo:
  3570. x = args[j++];
  3571. y = args[j++];
  3572. ctx.moveTo(x, y);
  3573. break;
  3574. case OPS.lineTo:
  3575. x = args[j++];
  3576. y = args[j++];
  3577. ctx.lineTo(x, y);
  3578. break;
  3579. case OPS.curveTo:
  3580. x = args[j + 4];
  3581. y = args[j + 5];
  3582. ctx.bezierCurveTo(args[j], args[j + 1], args[j + 2], args[j + 3],
  3583. x, y);
  3584. j += 6;
  3585. break;
  3586. case OPS.curveTo2:
  3587. ctx.bezierCurveTo(x, y, args[j], args[j + 1],
  3588. args[j + 2], args[j + 3]);
  3589. x = args[j + 2];
  3590. y = args[j + 3];
  3591. j += 4;
  3592. break;
  3593. case OPS.curveTo3:
  3594. x = args[j + 2];
  3595. y = args[j + 3];
  3596. ctx.bezierCurveTo(args[j], args[j + 1], x, y, x, y);
  3597. j += 4;
  3598. break;
  3599. case OPS.closePath:
  3600. ctx.closePath();
  3601. break;
  3602. }
  3603. }
  3604. current.setCurrentPoint(x, y);
  3605. },
  3606. closePath: function CanvasGraphics_closePath() {
  3607. this.ctx.closePath();
  3608. },
  3609. stroke: function CanvasGraphics_stroke(consumePath) {
  3610. consumePath = typeof consumePath !== 'undefined' ? consumePath : true;
  3611. var ctx = this.ctx;
  3612. var strokeColor = this.current.strokeColor;
  3613. if (this.current.lineWidth === 0) {
  3614. ctx.lineWidth = this.getSinglePixelWidth();
  3615. }
  3616. // For stroke we want to temporarily change the global alpha to the
  3617. // stroking alpha.
  3618. ctx.globalAlpha = this.current.strokeAlpha;
  3619. if (strokeColor && strokeColor.hasOwnProperty('type') &&
  3620. strokeColor.type === 'Pattern') {
  3621. // for patterns, we transform to pattern space, calculate
  3622. // the pattern, call stroke, and restore to user space
  3623. ctx.save();
  3624. ctx.strokeStyle = strokeColor.getPattern(ctx, this);
  3625. ctx.stroke();
  3626. ctx.restore();
  3627. } else {
  3628. ctx.stroke();
  3629. }
  3630. if (consumePath) {
  3631. this.consumePath();
  3632. }
  3633. // Restore the global alpha to the fill alpha
  3634. ctx.globalAlpha = this.current.fillAlpha;
  3635. },
  3636. closeStroke: function CanvasGraphics_closeStroke() {
  3637. this.closePath();
  3638. this.stroke();
  3639. },
  3640. fill: function CanvasGraphics_fill(consumePath) {
  3641. consumePath = typeof consumePath !== 'undefined' ? consumePath : true;
  3642. var ctx = this.ctx;
  3643. var fillColor = this.current.fillColor;
  3644. var needRestore = false;
  3645. if (fillColor && fillColor.hasOwnProperty('type') &&
  3646. fillColor.type === 'Pattern') {
  3647. ctx.save();
  3648. ctx.fillStyle = fillColor.getPattern(ctx, this);
  3649. needRestore = true;
  3650. }
  3651. if (this.pendingEOFill) {
  3652. if (ctx.mozFillRule !== undefined) {
  3653. ctx.mozFillRule = 'evenodd';
  3654. ctx.fill();
  3655. ctx.mozFillRule = 'nonzero';
  3656. } else {
  3657. try {
  3658. ctx.fill('evenodd');
  3659. } catch (ex) {
  3660. // shouldn't really happen, but browsers might think differently
  3661. ctx.fill();
  3662. }
  3663. }
  3664. this.pendingEOFill = false;
  3665. } else {
  3666. ctx.fill();
  3667. }
  3668. if (needRestore) {
  3669. ctx.restore();
  3670. }
  3671. if (consumePath) {
  3672. this.consumePath();
  3673. }
  3674. },
  3675. eoFill: function CanvasGraphics_eoFill() {
  3676. this.pendingEOFill = true;
  3677. this.fill();
  3678. },
  3679. fillStroke: function CanvasGraphics_fillStroke() {
  3680. this.fill(false);
  3681. this.stroke(false);
  3682. this.consumePath();
  3683. },
  3684. eoFillStroke: function CanvasGraphics_eoFillStroke() {
  3685. this.pendingEOFill = true;
  3686. this.fillStroke();
  3687. },
  3688. closeFillStroke: function CanvasGraphics_closeFillStroke() {
  3689. this.closePath();
  3690. this.fillStroke();
  3691. },
  3692. closeEOFillStroke: function CanvasGraphics_closeEOFillStroke() {
  3693. this.pendingEOFill = true;
  3694. this.closePath();
  3695. this.fillStroke();
  3696. },
  3697. endPath: function CanvasGraphics_endPath() {
  3698. this.consumePath();
  3699. },
  3700. // Clipping
  3701. clip: function CanvasGraphics_clip() {
  3702. this.pendingClip = NORMAL_CLIP;
  3703. },
  3704. eoClip: function CanvasGraphics_eoClip() {
  3705. this.pendingClip = EO_CLIP;
  3706. },
  3707. // Text
  3708. beginText: function CanvasGraphics_beginText() {
  3709. this.current.textMatrix = IDENTITY_MATRIX;
  3710. this.current.textMatrixScale = 1;
  3711. this.current.x = this.current.lineX = 0;
  3712. this.current.y = this.current.lineY = 0;
  3713. },
  3714. endText: function CanvasGraphics_endText() {
  3715. var paths = this.pendingTextPaths;
  3716. var ctx = this.ctx;
  3717. if (paths === undefined) {
  3718. ctx.beginPath();
  3719. return;
  3720. }
  3721. ctx.save();
  3722. ctx.beginPath();
  3723. for (var i = 0; i < paths.length; i++) {
  3724. var path = paths[i];
  3725. ctx.setTransform.apply(ctx, path.transform);
  3726. ctx.translate(path.x, path.y);
  3727. path.addToPath(ctx, path.fontSize);
  3728. }
  3729. ctx.restore();
  3730. ctx.clip();
  3731. ctx.beginPath();
  3732. delete this.pendingTextPaths;
  3733. },
  3734. setCharSpacing: function CanvasGraphics_setCharSpacing(spacing) {
  3735. this.current.charSpacing = spacing;
  3736. },
  3737. setWordSpacing: function CanvasGraphics_setWordSpacing(spacing) {
  3738. this.current.wordSpacing = spacing;
  3739. },
  3740. setHScale: function CanvasGraphics_setHScale(scale) {
  3741. this.current.textHScale = scale / 100;
  3742. },
  3743. setLeading: function CanvasGraphics_setLeading(leading) {
  3744. this.current.leading = -leading;
  3745. },
  3746. setFont: function CanvasGraphics_setFont(fontRefName, size) {
  3747. var fontObj = this.commonObjs.get(fontRefName);
  3748. var current = this.current;
  3749. if (!fontObj) {
  3750. error('Can\'t find font for ' + fontRefName);
  3751. }
  3752. current.fontMatrix = (fontObj.fontMatrix ?
  3753. fontObj.fontMatrix : FONT_IDENTITY_MATRIX);
  3754. // A valid matrix needs all main diagonal elements to be non-zero
  3755. // This also ensures we bypass FF bugzilla bug #719844.
  3756. if (current.fontMatrix[0] === 0 ||
  3757. current.fontMatrix[3] === 0) {
  3758. warn('Invalid font matrix for font ' + fontRefName);
  3759. }
  3760. // The spec for Tf (setFont) says that 'size' specifies the font 'scale',
  3761. // and in some docs this can be negative (inverted x-y axes).
  3762. if (size < 0) {
  3763. size = -size;
  3764. current.fontDirection = -1;
  3765. } else {
  3766. current.fontDirection = 1;
  3767. }
  3768. this.current.font = fontObj;
  3769. this.current.fontSize = size;
  3770. if (fontObj.isType3Font) {
  3771. return; // we don't need ctx.font for Type3 fonts
  3772. }
  3773. var name = fontObj.loadedName || 'sans-serif';
  3774. var bold = fontObj.black ? (fontObj.bold ? 'bolder' : 'bold') :
  3775. (fontObj.bold ? 'bold' : 'normal');
  3776. var italic = fontObj.italic ? 'italic' : 'normal';
  3777. var typeface = '"' + name + '", ' + fontObj.fallbackName;
  3778. // Some font backends cannot handle fonts below certain size.
  3779. // Keeping the font at minimal size and using the fontSizeScale to change
  3780. // the current transformation matrix before the fillText/strokeText.
  3781. // See https://bugzilla.mozilla.org/show_bug.cgi?id=726227
  3782. var browserFontSize = size >= MIN_FONT_SIZE ? size : MIN_FONT_SIZE;
  3783. this.current.fontSizeScale = browserFontSize !== MIN_FONT_SIZE ? 1.0 :
  3784. size / MIN_FONT_SIZE;
  3785. var rule = italic + ' ' + bold + ' ' + browserFontSize + 'px ' + typeface;
  3786. this.ctx.font = rule;
  3787. },
  3788. setTextRenderingMode: function CanvasGraphics_setTextRenderingMode(mode) {
  3789. this.current.textRenderingMode = mode;
  3790. },
  3791. setTextRise: function CanvasGraphics_setTextRise(rise) {
  3792. this.current.textRise = rise;
  3793. },
  3794. moveText: function CanvasGraphics_moveText(x, y) {
  3795. this.current.x = this.current.lineX += x;
  3796. this.current.y = this.current.lineY += y;
  3797. },
  3798. setLeadingMoveText: function CanvasGraphics_setLeadingMoveText(x, y) {
  3799. this.setLeading(-y);
  3800. this.moveText(x, y);
  3801. },
  3802. setTextMatrix: function CanvasGraphics_setTextMatrix(a, b, c, d, e, f) {
  3803. this.current.textMatrix = [a, b, c, d, e, f];
  3804. this.current.textMatrixScale = Math.sqrt(a * a + b * b);
  3805. this.current.x = this.current.lineX = 0;
  3806. this.current.y = this.current.lineY = 0;
  3807. },
  3808. nextLine: function CanvasGraphics_nextLine() {
  3809. this.moveText(0, this.current.leading);
  3810. },
  3811. paintChar: function CanvasGraphics_paintChar(character, x, y) {
  3812. var ctx = this.ctx;
  3813. var current = this.current;
  3814. var font = current.font;
  3815. var textRenderingMode = current.textRenderingMode;
  3816. var fontSize = current.fontSize / current.fontSizeScale;
  3817. var fillStrokeMode = textRenderingMode &
  3818. TextRenderingMode.FILL_STROKE_MASK;
  3819. var isAddToPathSet = !!(textRenderingMode &
  3820. TextRenderingMode.ADD_TO_PATH_FLAG);
  3821. var addToPath;
  3822. if (font.disableFontFace || isAddToPathSet) {
  3823. addToPath = font.getPathGenerator(this.commonObjs, character);
  3824. }
  3825. if (font.disableFontFace) {
  3826. ctx.save();
  3827. ctx.translate(x, y);
  3828. ctx.beginPath();
  3829. addToPath(ctx, fontSize);
  3830. if (fillStrokeMode === TextRenderingMode.FILL ||
  3831. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  3832. ctx.fill();
  3833. }
  3834. if (fillStrokeMode === TextRenderingMode.STROKE ||
  3835. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  3836. ctx.stroke();
  3837. }
  3838. ctx.restore();
  3839. } else {
  3840. if (fillStrokeMode === TextRenderingMode.FILL ||
  3841. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  3842. ctx.fillText(character, x, y);
  3843. }
  3844. if (fillStrokeMode === TextRenderingMode.STROKE ||
  3845. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  3846. ctx.strokeText(character, x, y);
  3847. }
  3848. }
  3849. if (isAddToPathSet) {
  3850. var paths = this.pendingTextPaths || (this.pendingTextPaths = []);
  3851. paths.push({
  3852. transform: ctx.mozCurrentTransform,
  3853. x: x,
  3854. y: y,
  3855. fontSize: fontSize,
  3856. addToPath: addToPath
  3857. });
  3858. }
  3859. },
  3860. get isFontSubpixelAAEnabled() {
  3861. // Checks if anti-aliasing is enabled when scaled text is painted.
  3862. // On Windows GDI scaled fonts looks bad.
  3863. var ctx = document.createElement('canvas').getContext('2d');
  3864. ctx.scale(1.5, 1);
  3865. ctx.fillText('I', 0, 10);
  3866. var data = ctx.getImageData(0, 0, 10, 10).data;
  3867. var enabled = false;
  3868. for (var i = 3; i < data.length; i += 4) {
  3869. if (data[i] > 0 && data[i] < 255) {
  3870. enabled = true;
  3871. break;
  3872. }
  3873. }
  3874. return shadow(this, 'isFontSubpixelAAEnabled', enabled);
  3875. },
  3876. showText: function CanvasGraphics_showText(glyphs) {
  3877. var current = this.current;
  3878. var font = current.font;
  3879. if (font.isType3Font) {
  3880. return this.showType3Text(glyphs);
  3881. }
  3882. var fontSize = current.fontSize;
  3883. if (fontSize === 0) {
  3884. return;
  3885. }
  3886. var ctx = this.ctx;
  3887. var fontSizeScale = current.fontSizeScale;
  3888. var charSpacing = current.charSpacing;
  3889. var wordSpacing = current.wordSpacing;
  3890. var fontDirection = current.fontDirection;
  3891. var textHScale = current.textHScale * fontDirection;
  3892. var glyphsLength = glyphs.length;
  3893. var vertical = font.vertical;
  3894. var defaultVMetrics = font.defaultVMetrics;
  3895. var widthAdvanceScale = fontSize * current.fontMatrix[0];
  3896. var simpleFillText =
  3897. current.textRenderingMode === TextRenderingMode.FILL &&
  3898. !font.disableFontFace;
  3899. ctx.save();
  3900. ctx.transform.apply(ctx, current.textMatrix);
  3901. ctx.translate(current.x, current.y + current.textRise);
  3902. if (fontDirection > 0) {
  3903. ctx.scale(textHScale, -1);
  3904. } else {
  3905. ctx.scale(textHScale, 1);
  3906. }
  3907. var lineWidth = current.lineWidth;
  3908. var scale = current.textMatrixScale;
  3909. if (scale === 0 || lineWidth === 0) {
  3910. lineWidth = this.getSinglePixelWidth();
  3911. } else {
  3912. lineWidth /= scale;
  3913. }
  3914. if (fontSizeScale !== 1.0) {
  3915. ctx.scale(fontSizeScale, fontSizeScale);
  3916. lineWidth /= fontSizeScale;
  3917. }
  3918. ctx.lineWidth = lineWidth;
  3919. var x = 0, i;
  3920. for (i = 0; i < glyphsLength; ++i) {
  3921. var glyph = glyphs[i];
  3922. if (glyph === null) {
  3923. // word break
  3924. x += fontDirection * wordSpacing;
  3925. continue;
  3926. } else if (isNum(glyph)) {
  3927. x += -glyph * fontSize * 0.001;
  3928. continue;
  3929. }
  3930. var restoreNeeded = false;
  3931. var character = glyph.fontChar;
  3932. var accent = glyph.accent;
  3933. var scaledX, scaledY, scaledAccentX, scaledAccentY;
  3934. var width = glyph.width;
  3935. if (vertical) {
  3936. var vmetric, vx, vy;
  3937. vmetric = glyph.vmetric || defaultVMetrics;
  3938. vx = glyph.vmetric ? vmetric[1] : width * 0.5;
  3939. vx = -vx * widthAdvanceScale;
  3940. vy = vmetric[2] * widthAdvanceScale;
  3941. width = vmetric ? -vmetric[0] : width;
  3942. scaledX = vx / fontSizeScale;
  3943. scaledY = (x + vy) / fontSizeScale;
  3944. } else {
  3945. scaledX = x / fontSizeScale;
  3946. scaledY = 0;
  3947. }
  3948. if (font.remeasure && width > 0 && this.isFontSubpixelAAEnabled) {
  3949. // some standard fonts may not have the exact width, trying to
  3950. // rescale per character
  3951. var measuredWidth = ctx.measureText(character).width * 1000 /
  3952. fontSize * fontSizeScale;
  3953. var characterScaleX = width / measuredWidth;
  3954. restoreNeeded = true;
  3955. ctx.save();
  3956. ctx.scale(characterScaleX, 1);
  3957. scaledX /= characterScaleX;
  3958. }
  3959. if (simpleFillText && !accent) {
  3960. // common case
  3961. ctx.fillText(character, scaledX, scaledY);
  3962. } else {
  3963. this.paintChar(character, scaledX, scaledY);
  3964. if (accent) {
  3965. scaledAccentX = scaledX + accent.offset.x / fontSizeScale;
  3966. scaledAccentY = scaledY - accent.offset.y / fontSizeScale;
  3967. this.paintChar(accent.fontChar, scaledAccentX, scaledAccentY);
  3968. }
  3969. }
  3970. var charWidth = width * widthAdvanceScale + charSpacing * fontDirection;
  3971. x += charWidth;
  3972. if (restoreNeeded) {
  3973. ctx.restore();
  3974. }
  3975. }
  3976. if (vertical) {
  3977. current.y -= x * textHScale;
  3978. } else {
  3979. current.x += x * textHScale;
  3980. }
  3981. ctx.restore();
  3982. },
  3983. showType3Text: function CanvasGraphics_showType3Text(glyphs) {
  3984. // Type3 fonts - each glyph is a "mini-PDF"
  3985. var ctx = this.ctx;
  3986. var current = this.current;
  3987. var font = current.font;
  3988. var fontSize = current.fontSize;
  3989. var fontDirection = current.fontDirection;
  3990. var charSpacing = current.charSpacing;
  3991. var wordSpacing = current.wordSpacing;
  3992. var textHScale = current.textHScale * fontDirection;
  3993. var fontMatrix = current.fontMatrix || FONT_IDENTITY_MATRIX;
  3994. var glyphsLength = glyphs.length;
  3995. var i, glyph, width;
  3996. if (fontSize === 0) {
  3997. return;
  3998. }
  3999. ctx.save();
  4000. ctx.transform.apply(ctx, current.textMatrix);
  4001. ctx.translate(current.x, current.y);
  4002. ctx.scale(textHScale, 1);
  4003. for (i = 0; i < glyphsLength; ++i) {
  4004. glyph = glyphs[i];
  4005. if (glyph === null) {
  4006. // word break
  4007. this.ctx.translate(wordSpacing, 0);
  4008. current.x += wordSpacing * textHScale;
  4009. continue;
  4010. } else if (isNum(glyph)) {
  4011. var spacingLength = -glyph * 0.001 * fontSize;
  4012. this.ctx.translate(spacingLength, 0);
  4013. current.x += spacingLength * textHScale;
  4014. continue;
  4015. }
  4016. var operatorList = font.charProcOperatorList[glyph.operatorListId];
  4017. if (!operatorList) {
  4018. warn('Type3 character \"' + glyph.operatorListId +
  4019. '\" is not available');
  4020. continue;
  4021. }
  4022. this.processingType3 = glyph;
  4023. this.save();
  4024. ctx.scale(fontSize, fontSize);
  4025. ctx.transform.apply(ctx, fontMatrix);
  4026. this.executeOperatorList(operatorList);
  4027. this.restore();
  4028. var transformed = Util.applyTransform([glyph.width, 0], fontMatrix);
  4029. width = ((transformed[0] * fontSize + charSpacing) * fontDirection);
  4030. ctx.translate(width, 0);
  4031. current.x += width * textHScale;
  4032. }
  4033. ctx.restore();
  4034. this.processingType3 = null;
  4035. },
  4036. // Type3 fonts
  4037. setCharWidth: function CanvasGraphics_setCharWidth(xWidth, yWidth) {
  4038. // We can safely ignore this since the width should be the same
  4039. // as the width in the Widths array.
  4040. },
  4041. setCharWidthAndBounds: function CanvasGraphics_setCharWidthAndBounds(xWidth,
  4042. yWidth,
  4043. llx,
  4044. lly,
  4045. urx,
  4046. ury) {
  4047. // TODO According to the spec we're also suppose to ignore any operators
  4048. // that set color or include images while processing this type3 font.
  4049. this.ctx.rect(llx, lly, urx - llx, ury - lly);
  4050. this.clip();
  4051. this.endPath();
  4052. },
  4053. // Color
  4054. getColorN_Pattern: function CanvasGraphics_getColorN_Pattern(IR) {
  4055. var pattern;
  4056. if (IR[0] === 'TilingPattern') {
  4057. var color = IR[1];
  4058. pattern = new TilingPattern(IR, color, this.ctx, this.objs,
  4059. this.commonObjs, this.baseTransform);
  4060. } else {
  4061. pattern = getShadingPatternFromIR(IR);
  4062. }
  4063. return pattern;
  4064. },
  4065. setStrokeColorN: function CanvasGraphics_setStrokeColorN(/*...*/) {
  4066. this.current.strokeColor = this.getColorN_Pattern(arguments);
  4067. },
  4068. setFillColorN: function CanvasGraphics_setFillColorN(/*...*/) {
  4069. this.current.fillColor = this.getColorN_Pattern(arguments);
  4070. },
  4071. setStrokeRGBColor: function CanvasGraphics_setStrokeRGBColor(r, g, b) {
  4072. var color = Util.makeCssRgb(arguments);
  4073. this.ctx.strokeStyle = color;
  4074. this.current.strokeColor = color;
  4075. },
  4076. setFillRGBColor: function CanvasGraphics_setFillRGBColor(r, g, b) {
  4077. var color = Util.makeCssRgb(arguments);
  4078. this.ctx.fillStyle = color;
  4079. this.current.fillColor = color;
  4080. },
  4081. shadingFill: function CanvasGraphics_shadingFill(patternIR) {
  4082. var ctx = this.ctx;
  4083. this.save();
  4084. var pattern = getShadingPatternFromIR(patternIR);
  4085. ctx.fillStyle = pattern.getPattern(ctx, this, true);
  4086. var inv = ctx.mozCurrentTransformInverse;
  4087. if (inv) {
  4088. var canvas = ctx.canvas;
  4089. var width = canvas.width;
  4090. var height = canvas.height;
  4091. var bl = Util.applyTransform([0, 0], inv);
  4092. var br = Util.applyTransform([0, height], inv);
  4093. var ul = Util.applyTransform([width, 0], inv);
  4094. var ur = Util.applyTransform([width, height], inv);
  4095. var x0 = Math.min(bl[0], br[0], ul[0], ur[0]);
  4096. var y0 = Math.min(bl[1], br[1], ul[1], ur[1]);
  4097. var x1 = Math.max(bl[0], br[0], ul[0], ur[0]);
  4098. var y1 = Math.max(bl[1], br[1], ul[1], ur[1]);
  4099. this.ctx.fillRect(x0, y0, x1 - x0, y1 - y0);
  4100. } else {
  4101. // HACK to draw the gradient onto an infinite rectangle.
  4102. // PDF gradients are drawn across the entire image while
  4103. // Canvas only allows gradients to be drawn in a rectangle
  4104. // The following bug should allow us to remove this.
  4105. // https://bugzilla.mozilla.org/show_bug.cgi?id=664884
  4106. this.ctx.fillRect(-1e10, -1e10, 2e10, 2e10);
  4107. }
  4108. this.restore();
  4109. },
  4110. // Images
  4111. beginInlineImage: function CanvasGraphics_beginInlineImage() {
  4112. error('Should not call beginInlineImage');
  4113. },
  4114. beginImageData: function CanvasGraphics_beginImageData() {
  4115. error('Should not call beginImageData');
  4116. },
  4117. paintFormXObjectBegin: function CanvasGraphics_paintFormXObjectBegin(matrix,
  4118. bbox) {
  4119. this.save();
  4120. this.baseTransformStack.push(this.baseTransform);
  4121. if (isArray(matrix) && 6 === matrix.length) {
  4122. this.transform.apply(this, matrix);
  4123. }
  4124. this.baseTransform = this.ctx.mozCurrentTransform;
  4125. if (isArray(bbox) && 4 === bbox.length) {
  4126. var width = bbox[2] - bbox[0];
  4127. var height = bbox[3] - bbox[1];
  4128. this.ctx.rect(bbox[0], bbox[1], width, height);
  4129. this.clip();
  4130. this.endPath();
  4131. }
  4132. },
  4133. paintFormXObjectEnd: function CanvasGraphics_paintFormXObjectEnd() {
  4134. this.restore();
  4135. this.baseTransform = this.baseTransformStack.pop();
  4136. },
  4137. beginGroup: function CanvasGraphics_beginGroup(group) {
  4138. this.save();
  4139. var currentCtx = this.ctx;
  4140. // TODO non-isolated groups - according to Rik at adobe non-isolated
  4141. // group results aren't usually that different and they even have tools
  4142. // that ignore this setting. Notes from Rik on implmenting:
  4143. // - When you encounter an transparency group, create a new canvas with
  4144. // the dimensions of the bbox
  4145. // - copy the content from the previous canvas to the new canvas
  4146. // - draw as usual
  4147. // - remove the backdrop alpha:
  4148. // alphaNew = 1 - (1 - alpha)/(1 - alphaBackdrop) with 'alpha' the alpha
  4149. // value of your transparency group and 'alphaBackdrop' the alpha of the
  4150. // backdrop
  4151. // - remove background color:
  4152. // colorNew = color - alphaNew *colorBackdrop /(1 - alphaNew)
  4153. if (!group.isolated) {
  4154. info('TODO: Support non-isolated groups.');
  4155. }
  4156. // TODO knockout - supposedly possible with the clever use of compositing
  4157. // modes.
  4158. if (group.knockout) {
  4159. warn('Knockout groups not supported.');
  4160. }
  4161. var currentTransform = currentCtx.mozCurrentTransform;
  4162. if (group.matrix) {
  4163. currentCtx.transform.apply(currentCtx, group.matrix);
  4164. }
  4165. assert(group.bbox, 'Bounding box is required.');
  4166. // Based on the current transform figure out how big the bounding box
  4167. // will actually be.
  4168. var bounds = Util.getAxialAlignedBoundingBox(
  4169. group.bbox,
  4170. currentCtx.mozCurrentTransform);
  4171. // Clip the bounding box to the current canvas.
  4172. var canvasBounds = [0,
  4173. 0,
  4174. currentCtx.canvas.width,
  4175. currentCtx.canvas.height];
  4176. bounds = Util.intersect(bounds, canvasBounds) || [0, 0, 0, 0];
  4177. // Use ceil in case we're between sizes so we don't create canvas that is
  4178. // too small and make the canvas at least 1x1 pixels.
  4179. var offsetX = Math.floor(bounds[0]);
  4180. var offsetY = Math.floor(bounds[1]);
  4181. var drawnWidth = Math.max(Math.ceil(bounds[2]) - offsetX, 1);
  4182. var drawnHeight = Math.max(Math.ceil(bounds[3]) - offsetY, 1);
  4183. var scaleX = 1, scaleY = 1;
  4184. if (drawnWidth > MAX_GROUP_SIZE) {
  4185. scaleX = drawnWidth / MAX_GROUP_SIZE;
  4186. drawnWidth = MAX_GROUP_SIZE;
  4187. }
  4188. if (drawnHeight > MAX_GROUP_SIZE) {
  4189. scaleY = drawnHeight / MAX_GROUP_SIZE;
  4190. drawnHeight = MAX_GROUP_SIZE;
  4191. }
  4192. var cacheId = 'groupAt' + this.groupLevel;
  4193. if (group.smask) {
  4194. // Using two cache entries is case if masks are used one after another.
  4195. cacheId += '_smask_' + ((this.smaskCounter++) % 2);
  4196. }
  4197. var scratchCanvas = CachedCanvases.getCanvas(
  4198. cacheId, drawnWidth, drawnHeight, true);
  4199. var groupCtx = scratchCanvas.context;
  4200. // Since we created a new canvas that is just the size of the bounding box
  4201. // we have to translate the group ctx.
  4202. groupCtx.scale(1 / scaleX, 1 / scaleY);
  4203. groupCtx.translate(-offsetX, -offsetY);
  4204. groupCtx.transform.apply(groupCtx, currentTransform);
  4205. if (group.smask) {
  4206. // Saving state and cached mask to be used in setGState.
  4207. this.smaskStack.push({
  4208. canvas: scratchCanvas.canvas,
  4209. context: groupCtx,
  4210. offsetX: offsetX,
  4211. offsetY: offsetY,
  4212. scaleX: scaleX,
  4213. scaleY: scaleY,
  4214. subtype: group.smask.subtype,
  4215. backdrop: group.smask.backdrop
  4216. });
  4217. } else {
  4218. // Setup the current ctx so when the group is popped we draw it at the
  4219. // right location.
  4220. currentCtx.setTransform(1, 0, 0, 1, 0, 0);
  4221. currentCtx.translate(offsetX, offsetY);
  4222. currentCtx.scale(scaleX, scaleY);
  4223. }
  4224. // The transparency group inherits all off the current graphics state
  4225. // except the blend mode, soft mask, and alpha constants.
  4226. copyCtxState(currentCtx, groupCtx);
  4227. this.ctx = groupCtx;
  4228. this.setGState([
  4229. ['BM', 'Normal'],
  4230. ['ca', 1],
  4231. ['CA', 1]
  4232. ]);
  4233. this.groupStack.push(currentCtx);
  4234. this.groupLevel++;
  4235. },
  4236. endGroup: function CanvasGraphics_endGroup(group) {
  4237. this.groupLevel--;
  4238. var groupCtx = this.ctx;
  4239. this.ctx = this.groupStack.pop();
  4240. // Turn off image smoothing to avoid sub pixel interpolation which can
  4241. // look kind of blurry for some pdfs.
  4242. if (this.ctx.imageSmoothingEnabled !== undefined) {
  4243. this.ctx.imageSmoothingEnabled = false;
  4244. } else {
  4245. this.ctx.mozImageSmoothingEnabled = false;
  4246. }
  4247. if (group.smask) {
  4248. this.tempSMask = this.smaskStack.pop();
  4249. } else {
  4250. this.ctx.drawImage(groupCtx.canvas, 0, 0);
  4251. }
  4252. this.restore();
  4253. },
  4254. beginAnnotations: function CanvasGraphics_beginAnnotations() {
  4255. this.save();
  4256. this.current = new CanvasExtraState();
  4257. },
  4258. endAnnotations: function CanvasGraphics_endAnnotations() {
  4259. this.restore();
  4260. },
  4261. beginAnnotation: function CanvasGraphics_beginAnnotation(rect, transform,
  4262. matrix) {
  4263. this.save();
  4264. if (isArray(rect) && 4 === rect.length) {
  4265. var width = rect[2] - rect[0];
  4266. var height = rect[3] - rect[1];
  4267. this.ctx.rect(rect[0], rect[1], width, height);
  4268. this.clip();
  4269. this.endPath();
  4270. }
  4271. this.transform.apply(this, transform);
  4272. this.transform.apply(this, matrix);
  4273. },
  4274. endAnnotation: function CanvasGraphics_endAnnotation() {
  4275. this.restore();
  4276. },
  4277. paintJpegXObject: function CanvasGraphics_paintJpegXObject(objId, w, h) {
  4278. var domImage = this.objs.get(objId);
  4279. if (!domImage) {
  4280. warn('Dependent image isn\'t ready yet');
  4281. return;
  4282. }
  4283. this.save();
  4284. var ctx = this.ctx;
  4285. // scale the image to the unit square
  4286. ctx.scale(1 / w, -1 / h);
  4287. ctx.drawImage(domImage, 0, 0, domImage.width, domImage.height,
  4288. 0, -h, w, h);
  4289. if (this.imageLayer) {
  4290. var currentTransform = ctx.mozCurrentTransformInverse;
  4291. var position = this.getCanvasPosition(0, 0);
  4292. this.imageLayer.appendImage({
  4293. objId: objId,
  4294. left: position[0],
  4295. top: position[1],
  4296. width: w / currentTransform[0],
  4297. height: h / currentTransform[3]
  4298. });
  4299. }
  4300. this.restore();
  4301. },
  4302. paintImageMaskXObject: function CanvasGraphics_paintImageMaskXObject(img) {
  4303. var ctx = this.ctx;
  4304. var width = img.width, height = img.height;
  4305. var glyph = this.processingType3;
  4306. if (COMPILE_TYPE3_GLYPHS && glyph && !('compiled' in glyph)) {
  4307. var MAX_SIZE_TO_COMPILE = 1000;
  4308. if (width <= MAX_SIZE_TO_COMPILE && height <= MAX_SIZE_TO_COMPILE) {
  4309. glyph.compiled =
  4310. compileType3Glyph({data: img.data, width: width, height: height});
  4311. } else {
  4312. glyph.compiled = null;
  4313. }
  4314. }
  4315. if (glyph && glyph.compiled) {
  4316. glyph.compiled(ctx);
  4317. return;
  4318. }
  4319. var maskCanvas = CachedCanvases.getCanvas('maskCanvas', width, height);
  4320. var maskCtx = maskCanvas.context;
  4321. maskCtx.save();
  4322. putBinaryImageMask(maskCtx, img);
  4323. maskCtx.globalCompositeOperation = 'source-in';
  4324. var fillColor = this.current.fillColor;
  4325. maskCtx.fillStyle = (fillColor && fillColor.hasOwnProperty('type') &&
  4326. fillColor.type === 'Pattern') ?
  4327. fillColor.getPattern(maskCtx, this) : fillColor;
  4328. maskCtx.fillRect(0, 0, width, height);
  4329. maskCtx.restore();
  4330. this.paintInlineImageXObject(maskCanvas.canvas);
  4331. },
  4332. paintImageMaskXObjectRepeat:
  4333. function CanvasGraphics_paintImageMaskXObjectRepeat(imgData, scaleX,
  4334. scaleY, positions) {
  4335. var width = imgData.width;
  4336. var height = imgData.height;
  4337. var ctx = this.ctx;
  4338. var maskCanvas = CachedCanvases.getCanvas('maskCanvas', width, height);
  4339. var maskCtx = maskCanvas.context;
  4340. maskCtx.save();
  4341. putBinaryImageMask(maskCtx, imgData);
  4342. maskCtx.globalCompositeOperation = 'source-in';
  4343. var fillColor = this.current.fillColor;
  4344. maskCtx.fillStyle = (fillColor && fillColor.hasOwnProperty('type') &&
  4345. fillColor.type === 'Pattern') ?
  4346. fillColor.getPattern(maskCtx, this) : fillColor;
  4347. maskCtx.fillRect(0, 0, width, height);
  4348. maskCtx.restore();
  4349. for (var i = 0, ii = positions.length; i < ii; i += 2) {
  4350. ctx.save();
  4351. ctx.transform(scaleX, 0, 0, scaleY, positions[i], positions[i + 1]);
  4352. ctx.scale(1, -1);
  4353. ctx.drawImage(maskCanvas.canvas, 0, 0, width, height,
  4354. 0, -1, 1, 1);
  4355. ctx.restore();
  4356. }
  4357. },
  4358. paintImageMaskXObjectGroup:
  4359. function CanvasGraphics_paintImageMaskXObjectGroup(images) {
  4360. var ctx = this.ctx;
  4361. for (var i = 0, ii = images.length; i < ii; i++) {
  4362. var image = images[i];
  4363. var width = image.width, height = image.height;
  4364. var maskCanvas = CachedCanvases.getCanvas('maskCanvas', width, height);
  4365. var maskCtx = maskCanvas.context;
  4366. maskCtx.save();
  4367. putBinaryImageMask(maskCtx, image);
  4368. maskCtx.globalCompositeOperation = 'source-in';
  4369. var fillColor = this.current.fillColor;
  4370. maskCtx.fillStyle = (fillColor && fillColor.hasOwnProperty('type') &&
  4371. fillColor.type === 'Pattern') ?
  4372. fillColor.getPattern(maskCtx, this) : fillColor;
  4373. maskCtx.fillRect(0, 0, width, height);
  4374. maskCtx.restore();
  4375. ctx.save();
  4376. ctx.transform.apply(ctx, image.transform);
  4377. ctx.scale(1, -1);
  4378. ctx.drawImage(maskCanvas.canvas, 0, 0, width, height,
  4379. 0, -1, 1, 1);
  4380. ctx.restore();
  4381. }
  4382. },
  4383. paintImageXObject: function CanvasGraphics_paintImageXObject(objId) {
  4384. var imgData = this.objs.get(objId);
  4385. if (!imgData) {
  4386. warn('Dependent image isn\'t ready yet');
  4387. return;
  4388. }
  4389. this.paintInlineImageXObject(imgData);
  4390. },
  4391. paintImageXObjectRepeat:
  4392. function CanvasGraphics_paintImageXObjectRepeat(objId, scaleX, scaleY,
  4393. positions) {
  4394. var imgData = this.objs.get(objId);
  4395. if (!imgData) {
  4396. warn('Dependent image isn\'t ready yet');
  4397. return;
  4398. }
  4399. var width = imgData.width;
  4400. var height = imgData.height;
  4401. var map = [];
  4402. for (var i = 0, ii = positions.length; i < ii; i += 2) {
  4403. map.push({transform: [scaleX, 0, 0, scaleY, positions[i],
  4404. positions[i + 1]], x: 0, y: 0, w: width, h: height});
  4405. }
  4406. this.paintInlineImageXObjectGroup(imgData, map);
  4407. },
  4408. paintInlineImageXObject:
  4409. function CanvasGraphics_paintInlineImageXObject(imgData) {
  4410. var width = imgData.width;
  4411. var height = imgData.height;
  4412. var ctx = this.ctx;
  4413. this.save();
  4414. // scale the image to the unit square
  4415. ctx.scale(1 / width, -1 / height);
  4416. var currentTransform = ctx.mozCurrentTransformInverse;
  4417. var a = currentTransform[0], b = currentTransform[1];
  4418. var widthScale = Math.max(Math.sqrt(a * a + b * b), 1);
  4419. var c = currentTransform[2], d = currentTransform[3];
  4420. var heightScale = Math.max(Math.sqrt(c * c + d * d), 1);
  4421. var imgToPaint, tmpCanvas;
  4422. // instanceof HTMLElement does not work in jsdom node.js module
  4423. if (imgData instanceof HTMLElement || !imgData.data) {
  4424. imgToPaint = imgData;
  4425. } else {
  4426. tmpCanvas = CachedCanvases.getCanvas('inlineImage', width, height);
  4427. var tmpCtx = tmpCanvas.context;
  4428. putBinaryImageData(tmpCtx, imgData);
  4429. imgToPaint = tmpCanvas.canvas;
  4430. }
  4431. var paintWidth = width, paintHeight = height;
  4432. var tmpCanvasId = 'prescale1';
  4433. // Vertial or horizontal scaling shall not be more than 2 to not loose the
  4434. // pixels during drawImage operation, painting on the temporary canvas(es)
  4435. // that are twice smaller in size
  4436. while ((widthScale > 2 && paintWidth > 1) ||
  4437. (heightScale > 2 && paintHeight > 1)) {
  4438. var newWidth = paintWidth, newHeight = paintHeight;
  4439. if (widthScale > 2 && paintWidth > 1) {
  4440. newWidth = Math.ceil(paintWidth / 2);
  4441. widthScale /= paintWidth / newWidth;
  4442. }
  4443. if (heightScale > 2 && paintHeight > 1) {
  4444. newHeight = Math.ceil(paintHeight / 2);
  4445. heightScale /= paintHeight / newHeight;
  4446. }
  4447. tmpCanvas = CachedCanvases.getCanvas(tmpCanvasId, newWidth, newHeight);
  4448. tmpCtx = tmpCanvas.context;
  4449. tmpCtx.clearRect(0, 0, newWidth, newHeight);
  4450. tmpCtx.drawImage(imgToPaint, 0, 0, paintWidth, paintHeight,
  4451. 0, 0, newWidth, newHeight);
  4452. imgToPaint = tmpCanvas.canvas;
  4453. paintWidth = newWidth;
  4454. paintHeight = newHeight;
  4455. tmpCanvasId = tmpCanvasId === 'prescale1' ? 'prescale2' : 'prescale1';
  4456. }
  4457. ctx.drawImage(imgToPaint, 0, 0, paintWidth, paintHeight,
  4458. 0, -height, width, height);
  4459. if (this.imageLayer) {
  4460. var position = this.getCanvasPosition(0, -height);
  4461. this.imageLayer.appendImage({
  4462. imgData: imgData,
  4463. left: position[0],
  4464. top: position[1],
  4465. width: width / currentTransform[0],
  4466. height: height / currentTransform[3]
  4467. });
  4468. }
  4469. this.restore();
  4470. },
  4471. paintInlineImageXObjectGroup:
  4472. function CanvasGraphics_paintInlineImageXObjectGroup(imgData, map) {
  4473. var ctx = this.ctx;
  4474. var w = imgData.width;
  4475. var h = imgData.height;
  4476. var tmpCanvas = CachedCanvases.getCanvas('inlineImage', w, h);
  4477. var tmpCtx = tmpCanvas.context;
  4478. putBinaryImageData(tmpCtx, imgData);
  4479. for (var i = 0, ii = map.length; i < ii; i++) {
  4480. var entry = map[i];
  4481. ctx.save();
  4482. ctx.transform.apply(ctx, entry.transform);
  4483. ctx.scale(1, -1);
  4484. ctx.drawImage(tmpCanvas.canvas, entry.x, entry.y, entry.w, entry.h,
  4485. 0, -1, 1, 1);
  4486. if (this.imageLayer) {
  4487. var position = this.getCanvasPosition(entry.x, entry.y);
  4488. this.imageLayer.appendImage({
  4489. imgData: imgData,
  4490. left: position[0],
  4491. top: position[1],
  4492. width: w,
  4493. height: h
  4494. });
  4495. }
  4496. ctx.restore();
  4497. }
  4498. },
  4499. paintSolidColorImageMask:
  4500. function CanvasGraphics_paintSolidColorImageMask() {
  4501. this.ctx.fillRect(0, 0, 1, 1);
  4502. },
  4503. // Marked content
  4504. markPoint: function CanvasGraphics_markPoint(tag) {
  4505. // TODO Marked content.
  4506. },
  4507. markPointProps: function CanvasGraphics_markPointProps(tag, properties) {
  4508. // TODO Marked content.
  4509. },
  4510. beginMarkedContent: function CanvasGraphics_beginMarkedContent(tag) {
  4511. // TODO Marked content.
  4512. },
  4513. beginMarkedContentProps: function CanvasGraphics_beginMarkedContentProps(
  4514. tag, properties) {
  4515. // TODO Marked content.
  4516. },
  4517. endMarkedContent: function CanvasGraphics_endMarkedContent() {
  4518. // TODO Marked content.
  4519. },
  4520. // Compatibility
  4521. beginCompat: function CanvasGraphics_beginCompat() {
  4522. // TODO ignore undefined operators (should we do that anyway?)
  4523. },
  4524. endCompat: function CanvasGraphics_endCompat() {
  4525. // TODO stop ignoring undefined operators
  4526. },
  4527. // Helper functions
  4528. consumePath: function CanvasGraphics_consumePath() {
  4529. var ctx = this.ctx;
  4530. if (this.pendingClip) {
  4531. if (this.pendingClip === EO_CLIP) {
  4532. if (ctx.mozFillRule !== undefined) {
  4533. ctx.mozFillRule = 'evenodd';
  4534. ctx.clip();
  4535. ctx.mozFillRule = 'nonzero';
  4536. } else {
  4537. try {
  4538. ctx.clip('evenodd');
  4539. } catch (ex) {
  4540. // shouldn't really happen, but browsers might think differently
  4541. ctx.clip();
  4542. }
  4543. }
  4544. } else {
  4545. ctx.clip();
  4546. }
  4547. this.pendingClip = null;
  4548. }
  4549. ctx.beginPath();
  4550. },
  4551. getSinglePixelWidth: function CanvasGraphics_getSinglePixelWidth(scale) {
  4552. var inverse = this.ctx.mozCurrentTransformInverse;
  4553. // max of the current horizontal and vertical scale
  4554. return Math.sqrt(Math.max(
  4555. (inverse[0] * inverse[0] + inverse[1] * inverse[1]),
  4556. (inverse[2] * inverse[2] + inverse[3] * inverse[3])));
  4557. },
  4558. getCanvasPosition: function CanvasGraphics_getCanvasPosition(x, y) {
  4559. var transform = this.ctx.mozCurrentTransform;
  4560. return [
  4561. transform[0] * x + transform[2] * y + transform[4],
  4562. transform[1] * x + transform[3] * y + transform[5]
  4563. ];
  4564. }
  4565. };
  4566. for (var op in OPS) {
  4567. CanvasGraphics.prototype[OPS[op]] = CanvasGraphics.prototype[op];
  4568. }
  4569. return CanvasGraphics;
  4570. })();
  4571. var WebGLUtils = (function WebGLUtilsClosure() {
  4572. function loadShader(gl, code, shaderType) {
  4573. var shader = gl.createShader(shaderType);
  4574. gl.shaderSource(shader, code);
  4575. gl.compileShader(shader);
  4576. var compiled = gl.getShaderParameter(shader, gl.COMPILE_STATUS);
  4577. if (!compiled) {
  4578. var errorMsg = gl.getShaderInfoLog(shader);
  4579. throw new Error('Error during shader compilation: ' + errorMsg);
  4580. }
  4581. return shader;
  4582. }
  4583. function createVertexShader(gl, code) {
  4584. return loadShader(gl, code, gl.VERTEX_SHADER);
  4585. }
  4586. function createFragmentShader(gl, code) {
  4587. return loadShader(gl, code, gl.FRAGMENT_SHADER);
  4588. }
  4589. function createProgram(gl, shaders) {
  4590. var program = gl.createProgram();
  4591. for (var i = 0, ii = shaders.length; i < ii; ++i) {
  4592. gl.attachShader(program, shaders[i]);
  4593. }
  4594. gl.linkProgram(program);
  4595. var linked = gl.getProgramParameter(program, gl.LINK_STATUS);
  4596. if (!linked) {
  4597. var errorMsg = gl.getProgramInfoLog(program);
  4598. throw new Error('Error during program linking: ' + errorMsg);
  4599. }
  4600. return program;
  4601. }
  4602. function createTexture(gl, image, textureId) {
  4603. gl.activeTexture(textureId);
  4604. var texture = gl.createTexture();
  4605. gl.bindTexture(gl.TEXTURE_2D, texture);
  4606. // Set the parameters so we can render any size image.
  4607. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
  4608. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
  4609. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
  4610. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
  4611. // Upload the image into the texture.
  4612. gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image);
  4613. return texture;
  4614. }
  4615. var currentGL, currentCanvas;
  4616. function generageGL() {
  4617. if (currentGL) {
  4618. return;
  4619. }
  4620. currentCanvas = document.createElement('canvas');
  4621. currentGL = currentCanvas.getContext('webgl',
  4622. { premultipliedalpha: false });
  4623. }
  4624. var smaskVertexShaderCode = '\
  4625. attribute vec2 a_position; \
  4626. attribute vec2 a_texCoord; \
  4627. \
  4628. uniform vec2 u_resolution; \
  4629. \
  4630. varying vec2 v_texCoord; \
  4631. \
  4632. void main() { \
  4633. vec2 clipSpace = (a_position / u_resolution) * 2.0 - 1.0; \
  4634. gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1); \
  4635. \
  4636. v_texCoord = a_texCoord; \
  4637. } ';
  4638. var smaskFragmentShaderCode = '\
  4639. precision mediump float; \
  4640. \
  4641. uniform vec4 u_backdrop; \
  4642. uniform int u_subtype; \
  4643. uniform sampler2D u_image; \
  4644. uniform sampler2D u_mask; \
  4645. \
  4646. varying vec2 v_texCoord; \
  4647. \
  4648. void main() { \
  4649. vec4 imageColor = texture2D(u_image, v_texCoord); \
  4650. vec4 maskColor = texture2D(u_mask, v_texCoord); \
  4651. if (u_backdrop.a > 0.0) { \
  4652. maskColor.rgb = maskColor.rgb * maskColor.a + \
  4653. u_backdrop.rgb * (1.0 - maskColor.a); \
  4654. } \
  4655. float lum; \
  4656. if (u_subtype == 0) { \
  4657. lum = maskColor.a; \
  4658. } else { \
  4659. lum = maskColor.r * 0.3 + maskColor.g * 0.59 + \
  4660. maskColor.b * 0.11; \
  4661. } \
  4662. imageColor.a *= lum; \
  4663. imageColor.rgb *= imageColor.a; \
  4664. gl_FragColor = imageColor; \
  4665. } ';
  4666. var smaskCache = null;
  4667. function initSmaskGL() {
  4668. var canvas, gl;
  4669. generageGL();
  4670. canvas = currentCanvas;
  4671. currentCanvas = null;
  4672. gl = currentGL;
  4673. currentGL = null;
  4674. // setup a GLSL program
  4675. var vertexShader = createVertexShader(gl, smaskVertexShaderCode);
  4676. var fragmentShader = createFragmentShader(gl, smaskFragmentShaderCode);
  4677. var program = createProgram(gl, [vertexShader, fragmentShader]);
  4678. gl.useProgram(program);
  4679. var cache = {};
  4680. cache.gl = gl;
  4681. cache.canvas = canvas;
  4682. cache.resolutionLocation = gl.getUniformLocation(program, 'u_resolution');
  4683. cache.positionLocation = gl.getAttribLocation(program, 'a_position');
  4684. cache.backdropLocation = gl.getUniformLocation(program, 'u_backdrop');
  4685. cache.subtypeLocation = gl.getUniformLocation(program, 'u_subtype');
  4686. var texCoordLocation = gl.getAttribLocation(program, 'a_texCoord');
  4687. var texLayerLocation = gl.getUniformLocation(program, 'u_image');
  4688. var texMaskLocation = gl.getUniformLocation(program, 'u_mask');
  4689. // provide texture coordinates for the rectangle.
  4690. var texCoordBuffer = gl.createBuffer();
  4691. gl.bindBuffer(gl.ARRAY_BUFFER, texCoordBuffer);
  4692. gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
  4693. 0.0, 0.0,
  4694. 1.0, 0.0,
  4695. 0.0, 1.0,
  4696. 0.0, 1.0,
  4697. 1.0, 0.0,
  4698. 1.0, 1.0]), gl.STATIC_DRAW);
  4699. gl.enableVertexAttribArray(texCoordLocation);
  4700. gl.vertexAttribPointer(texCoordLocation, 2, gl.FLOAT, false, 0, 0);
  4701. gl.uniform1i(texLayerLocation, 0);
  4702. gl.uniform1i(texMaskLocation, 1);
  4703. smaskCache = cache;
  4704. }
  4705. function composeSMask(layer, mask, properties) {
  4706. var width = layer.width, height = layer.height;
  4707. if (!smaskCache) {
  4708. initSmaskGL();
  4709. }
  4710. var cache = smaskCache,canvas = cache.canvas, gl = cache.gl;
  4711. canvas.width = width;
  4712. canvas.height = height;
  4713. gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
  4714. gl.uniform2f(cache.resolutionLocation, width, height);
  4715. if (properties.backdrop) {
  4716. gl.uniform4f(cache.resolutionLocation, properties.backdrop[0],
  4717. properties.backdrop[1], properties.backdrop[2], 1);
  4718. } else {
  4719. gl.uniform4f(cache.resolutionLocation, 0, 0, 0, 0);
  4720. }
  4721. gl.uniform1i(cache.subtypeLocation,
  4722. properties.subtype === 'Luminosity' ? 1 : 0);
  4723. // Create a textures
  4724. var texture = createTexture(gl, layer, gl.TEXTURE0);
  4725. var maskTexture = createTexture(gl, mask, gl.TEXTURE1);
  4726. // Create a buffer and put a single clipspace rectangle in
  4727. // it (2 triangles)
  4728. var buffer = gl.createBuffer();
  4729. gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
  4730. gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
  4731. 0, 0,
  4732. width, 0,
  4733. 0, height,
  4734. 0, height,
  4735. width, 0,
  4736. width, height]), gl.STATIC_DRAW);
  4737. gl.enableVertexAttribArray(cache.positionLocation);
  4738. gl.vertexAttribPointer(cache.positionLocation, 2, gl.FLOAT, false, 0, 0);
  4739. // draw
  4740. gl.clearColor(0, 0, 0, 0);
  4741. gl.enable(gl.BLEND);
  4742. gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
  4743. gl.clear(gl.COLOR_BUFFER_BIT);
  4744. gl.drawArrays(gl.TRIANGLES, 0, 6);
  4745. gl.flush();
  4746. gl.deleteTexture(texture);
  4747. gl.deleteTexture(maskTexture);
  4748. gl.deleteBuffer(buffer);
  4749. return canvas;
  4750. }
  4751. var figuresVertexShaderCode = '\
  4752. attribute vec2 a_position; \
  4753. attribute vec3 a_color; \
  4754. \
  4755. uniform vec2 u_resolution; \
  4756. uniform vec2 u_scale; \
  4757. uniform vec2 u_offset; \
  4758. \
  4759. varying vec4 v_color; \
  4760. \
  4761. void main() { \
  4762. vec2 position = (a_position + u_offset) * u_scale; \
  4763. vec2 clipSpace = (position / u_resolution) * 2.0 - 1.0; \
  4764. gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1); \
  4765. \
  4766. v_color = vec4(a_color / 255.0, 1.0); \
  4767. } ';
  4768. var figuresFragmentShaderCode = '\
  4769. precision mediump float; \
  4770. \
  4771. varying vec4 v_color; \
  4772. \
  4773. void main() { \
  4774. gl_FragColor = v_color; \
  4775. } ';
  4776. var figuresCache = null;
  4777. function initFiguresGL() {
  4778. var canvas, gl;
  4779. generageGL();
  4780. canvas = currentCanvas;
  4781. currentCanvas = null;
  4782. gl = currentGL;
  4783. currentGL = null;
  4784. // setup a GLSL program
  4785. var vertexShader = createVertexShader(gl, figuresVertexShaderCode);
  4786. var fragmentShader = createFragmentShader(gl, figuresFragmentShaderCode);
  4787. var program = createProgram(gl, [vertexShader, fragmentShader]);
  4788. gl.useProgram(program);
  4789. var cache = {};
  4790. cache.gl = gl;
  4791. cache.canvas = canvas;
  4792. cache.resolutionLocation = gl.getUniformLocation(program, 'u_resolution');
  4793. cache.scaleLocation = gl.getUniformLocation(program, 'u_scale');
  4794. cache.offsetLocation = gl.getUniformLocation(program, 'u_offset');
  4795. cache.positionLocation = gl.getAttribLocation(program, 'a_position');
  4796. cache.colorLocation = gl.getAttribLocation(program, 'a_color');
  4797. figuresCache = cache;
  4798. }
  4799. function drawFigures(width, height, backgroundColor, figures, context) {
  4800. if (!figuresCache) {
  4801. initFiguresGL();
  4802. }
  4803. var cache = figuresCache, canvas = cache.canvas, gl = cache.gl;
  4804. canvas.width = width;
  4805. canvas.height = height;
  4806. gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
  4807. gl.uniform2f(cache.resolutionLocation, width, height);
  4808. // count triangle points
  4809. var count = 0;
  4810. var i, ii, rows;
  4811. for (i = 0, ii = figures.length; i < ii; i++) {
  4812. switch (figures[i].type) {
  4813. case 'lattice':
  4814. rows = (figures[i].coords.length / figures[i].verticesPerRow) | 0;
  4815. count += (rows - 1) * (figures[i].verticesPerRow - 1) * 6;
  4816. break;
  4817. case 'triangles':
  4818. count += figures[i].coords.length;
  4819. break;
  4820. }
  4821. }
  4822. // transfer data
  4823. var coords = new Float32Array(count * 2);
  4824. var colors = new Uint8Array(count * 3);
  4825. var coordsMap = context.coords, colorsMap = context.colors;
  4826. var pIndex = 0, cIndex = 0;
  4827. for (i = 0, ii = figures.length; i < ii; i++) {
  4828. var figure = figures[i], ps = figure.coords, cs = figure.colors;
  4829. switch (figure.type) {
  4830. case 'lattice':
  4831. var cols = figure.verticesPerRow;
  4832. rows = (ps.length / cols) | 0;
  4833. for (var row = 1; row < rows; row++) {
  4834. var offset = row * cols + 1;
  4835. for (var col = 1; col < cols; col++, offset++) {
  4836. coords[pIndex] = coordsMap[ps[offset - cols - 1]];
  4837. coords[pIndex + 1] = coordsMap[ps[offset - cols - 1] + 1];
  4838. coords[pIndex + 2] = coordsMap[ps[offset - cols]];
  4839. coords[pIndex + 3] = coordsMap[ps[offset - cols] + 1];
  4840. coords[pIndex + 4] = coordsMap[ps[offset - 1]];
  4841. coords[pIndex + 5] = coordsMap[ps[offset - 1] + 1];
  4842. colors[cIndex] = colorsMap[cs[offset - cols - 1]];
  4843. colors[cIndex + 1] = colorsMap[cs[offset - cols - 1] + 1];
  4844. colors[cIndex + 2] = colorsMap[cs[offset - cols - 1] + 2];
  4845. colors[cIndex + 3] = colorsMap[cs[offset - cols]];
  4846. colors[cIndex + 4] = colorsMap[cs[offset - cols] + 1];
  4847. colors[cIndex + 5] = colorsMap[cs[offset - cols] + 2];
  4848. colors[cIndex + 6] = colorsMap[cs[offset - 1]];
  4849. colors[cIndex + 7] = colorsMap[cs[offset - 1] + 1];
  4850. colors[cIndex + 8] = colorsMap[cs[offset - 1] + 2];
  4851. coords[pIndex + 6] = coords[pIndex + 2];
  4852. coords[pIndex + 7] = coords[pIndex + 3];
  4853. coords[pIndex + 8] = coords[pIndex + 4];
  4854. coords[pIndex + 9] = coords[pIndex + 5];
  4855. coords[pIndex + 10] = coordsMap[ps[offset]];
  4856. coords[pIndex + 11] = coordsMap[ps[offset] + 1];
  4857. colors[cIndex + 9] = colors[cIndex + 3];
  4858. colors[cIndex + 10] = colors[cIndex + 4];
  4859. colors[cIndex + 11] = colors[cIndex + 5];
  4860. colors[cIndex + 12] = colors[cIndex + 6];
  4861. colors[cIndex + 13] = colors[cIndex + 7];
  4862. colors[cIndex + 14] = colors[cIndex + 8];
  4863. colors[cIndex + 15] = colorsMap[cs[offset]];
  4864. colors[cIndex + 16] = colorsMap[cs[offset] + 1];
  4865. colors[cIndex + 17] = colorsMap[cs[offset] + 2];
  4866. pIndex += 12;
  4867. cIndex += 18;
  4868. }
  4869. }
  4870. break;
  4871. case 'triangles':
  4872. for (var j = 0, jj = ps.length; j < jj; j++) {
  4873. coords[pIndex] = coordsMap[ps[j]];
  4874. coords[pIndex + 1] = coordsMap[ps[j] + 1];
  4875. colors[cIndex] = colorsMap[cs[i]];
  4876. colors[cIndex + 1] = colorsMap[cs[j] + 1];
  4877. colors[cIndex + 2] = colorsMap[cs[j] + 2];
  4878. pIndex += 2;
  4879. cIndex += 3;
  4880. }
  4881. break;
  4882. }
  4883. }
  4884. // draw
  4885. if (backgroundColor) {
  4886. gl.clearColor(backgroundColor[0] / 255, backgroundColor[1] / 255,
  4887. backgroundColor[2] / 255, 1.0);
  4888. } else {
  4889. gl.clearColor(0, 0, 0, 0);
  4890. }
  4891. gl.clear(gl.COLOR_BUFFER_BIT);
  4892. var coordsBuffer = gl.createBuffer();
  4893. gl.bindBuffer(gl.ARRAY_BUFFER, coordsBuffer);
  4894. gl.bufferData(gl.ARRAY_BUFFER, coords, gl.STATIC_DRAW);
  4895. gl.enableVertexAttribArray(cache.positionLocation);
  4896. gl.vertexAttribPointer(cache.positionLocation, 2, gl.FLOAT, false, 0, 0);
  4897. var colorsBuffer = gl.createBuffer();
  4898. gl.bindBuffer(gl.ARRAY_BUFFER, colorsBuffer);
  4899. gl.bufferData(gl.ARRAY_BUFFER, colors, gl.STATIC_DRAW);
  4900. gl.enableVertexAttribArray(cache.colorLocation);
  4901. gl.vertexAttribPointer(cache.colorLocation, 3, gl.UNSIGNED_BYTE, false,
  4902. 0, 0);
  4903. gl.uniform2f(cache.scaleLocation, context.scaleX, context.scaleY);
  4904. gl.uniform2f(cache.offsetLocation, context.offsetX, context.offsetY);
  4905. gl.drawArrays(gl.TRIANGLES, 0, count);
  4906. gl.flush();
  4907. gl.deleteBuffer(coordsBuffer);
  4908. gl.deleteBuffer(colorsBuffer);
  4909. return canvas;
  4910. }
  4911. function cleanup() {
  4912. if (smaskCache && smaskCache.canvas) {
  4913. smaskCache.canvas.width = 0;
  4914. smaskCache.canvas.height = 0;
  4915. }
  4916. if (figuresCache && figuresCache.canvas) {
  4917. figuresCache.canvas.width = 0;
  4918. figuresCache.canvas.height = 0;
  4919. }
  4920. smaskCache = null;
  4921. figuresCache = null;
  4922. }
  4923. return {
  4924. get isEnabled() {
  4925. if (PDFJS.disableWebGL) {
  4926. return false;
  4927. }
  4928. var enabled = false;
  4929. try {
  4930. generageGL();
  4931. enabled = !!currentGL;
  4932. } catch (e) { }
  4933. return shadow(this, 'isEnabled', enabled);
  4934. },
  4935. composeSMask: composeSMask,
  4936. drawFigures: drawFigures,
  4937. clear: cleanup
  4938. };
  4939. })();
  4940. var ShadingIRs = {};
  4941. ShadingIRs.RadialAxial = {
  4942. fromIR: function RadialAxial_fromIR(raw) {
  4943. var type = raw[1];
  4944. var colorStops = raw[2];
  4945. var p0 = raw[3];
  4946. var p1 = raw[4];
  4947. var r0 = raw[5];
  4948. var r1 = raw[6];
  4949. return {
  4950. type: 'Pattern',
  4951. getPattern: function RadialAxial_getPattern(ctx) {
  4952. var grad;
  4953. if (type === 'axial') {
  4954. grad = ctx.createLinearGradient(p0[0], p0[1], p1[0], p1[1]);
  4955. } else if (type === 'radial') {
  4956. grad = ctx.createRadialGradient(p0[0], p0[1], r0, p1[0], p1[1], r1);
  4957. }
  4958. for (var i = 0, ii = colorStops.length; i < ii; ++i) {
  4959. var c = colorStops[i];
  4960. grad.addColorStop(c[0], c[1]);
  4961. }
  4962. return grad;
  4963. }
  4964. };
  4965. }
  4966. };
  4967. var createMeshCanvas = (function createMeshCanvasClosure() {
  4968. function drawTriangle(data, context, p1, p2, p3, c1, c2, c3) {
  4969. // Very basic Gouraud-shaded triangle rasterization algorithm.
  4970. var coords = context.coords, colors = context.colors;
  4971. var bytes = data.data, rowSize = data.width * 4;
  4972. var tmp;
  4973. if (coords[p1 + 1] > coords[p2 + 1]) {
  4974. tmp = p1; p1 = p2; p2 = tmp; tmp = c1; c1 = c2; c2 = tmp;
  4975. }
  4976. if (coords[p2 + 1] > coords[p3 + 1]) {
  4977. tmp = p2; p2 = p3; p3 = tmp; tmp = c2; c2 = c3; c3 = tmp;
  4978. }
  4979. if (coords[p1 + 1] > coords[p2 + 1]) {
  4980. tmp = p1; p1 = p2; p2 = tmp; tmp = c1; c1 = c2; c2 = tmp;
  4981. }
  4982. var x1 = (coords[p1] + context.offsetX) * context.scaleX;
  4983. var y1 = (coords[p1 + 1] + context.offsetY) * context.scaleY;
  4984. var x2 = (coords[p2] + context.offsetX) * context.scaleX;
  4985. var y2 = (coords[p2 + 1] + context.offsetY) * context.scaleY;
  4986. var x3 = (coords[p3] + context.offsetX) * context.scaleX;
  4987. var y3 = (coords[p3 + 1] + context.offsetY) * context.scaleY;
  4988. if (y1 >= y3) {
  4989. return;
  4990. }
  4991. var c1r = colors[c1], c1g = colors[c1 + 1], c1b = colors[c1 + 2];
  4992. var c2r = colors[c2], c2g = colors[c2 + 1], c2b = colors[c2 + 2];
  4993. var c3r = colors[c3], c3g = colors[c3 + 1], c3b = colors[c3 + 2];
  4994. var minY = Math.round(y1), maxY = Math.round(y3);
  4995. var xa, car, cag, cab;
  4996. var xb, cbr, cbg, cbb;
  4997. var k;
  4998. for (var y = minY; y <= maxY; y++) {
  4999. if (y < y2) {
  5000. k = y < y1 ? 0 : y1 === y2 ? 1 : (y1 - y) / (y1 - y2);
  5001. xa = x1 - (x1 - x2) * k;
  5002. car = c1r - (c1r - c2r) * k;
  5003. cag = c1g - (c1g - c2g) * k;
  5004. cab = c1b - (c1b - c2b) * k;
  5005. } else {
  5006. k = y > y3 ? 1 : y2 === y3 ? 0 : (y2 - y) / (y2 - y3);
  5007. xa = x2 - (x2 - x3) * k;
  5008. car = c2r - (c2r - c3r) * k;
  5009. cag = c2g - (c2g - c3g) * k;
  5010. cab = c2b - (c2b - c3b) * k;
  5011. }
  5012. k = y < y1 ? 0 : y > y3 ? 1 : (y1 - y) / (y1 - y3);
  5013. xb = x1 - (x1 - x3) * k;
  5014. cbr = c1r - (c1r - c3r) * k;
  5015. cbg = c1g - (c1g - c3g) * k;
  5016. cbb = c1b - (c1b - c3b) * k;
  5017. var x1_ = Math.round(Math.min(xa, xb));
  5018. var x2_ = Math.round(Math.max(xa, xb));
  5019. var j = rowSize * y + x1_ * 4;
  5020. for (var x = x1_; x <= x2_; x++) {
  5021. k = (xa - x) / (xa - xb);
  5022. k = k < 0 ? 0 : k > 1 ? 1 : k;
  5023. bytes[j++] = (car - (car - cbr) * k) | 0;
  5024. bytes[j++] = (cag - (cag - cbg) * k) | 0;
  5025. bytes[j++] = (cab - (cab - cbb) * k) | 0;
  5026. bytes[j++] = 255;
  5027. }
  5028. }
  5029. }
  5030. function drawFigure(data, figure, context) {
  5031. var ps = figure.coords;
  5032. var cs = figure.colors;
  5033. var i, ii;
  5034. switch (figure.type) {
  5035. case 'lattice':
  5036. var verticesPerRow = figure.verticesPerRow;
  5037. var rows = Math.floor(ps.length / verticesPerRow) - 1;
  5038. var cols = verticesPerRow - 1;
  5039. for (i = 0; i < rows; i++) {
  5040. var q = i * verticesPerRow;
  5041. for (var j = 0; j < cols; j++, q++) {
  5042. drawTriangle(data, context,
  5043. ps[q], ps[q + 1], ps[q + verticesPerRow],
  5044. cs[q], cs[q + 1], cs[q + verticesPerRow]);
  5045. drawTriangle(data, context,
  5046. ps[q + verticesPerRow + 1], ps[q + 1], ps[q + verticesPerRow],
  5047. cs[q + verticesPerRow + 1], cs[q + 1], cs[q + verticesPerRow]);
  5048. }
  5049. }
  5050. break;
  5051. case 'triangles':
  5052. for (i = 0, ii = ps.length; i < ii; i += 3) {
  5053. drawTriangle(data, context,
  5054. ps[i], ps[i + 1], ps[i + 2],
  5055. cs[i], cs[i + 1], cs[i + 2]);
  5056. }
  5057. break;
  5058. default:
  5059. error('illigal figure');
  5060. break;
  5061. }
  5062. }
  5063. function createMeshCanvas(bounds, combinesScale, coords, colors, figures,
  5064. backgroundColor) {
  5065. // we will increase scale on some weird factor to let antialiasing take
  5066. // care of "rough" edges
  5067. var EXPECTED_SCALE = 1.1;
  5068. // MAX_PATTERN_SIZE is used to avoid OOM situation.
  5069. var MAX_PATTERN_SIZE = 3000; // 10in @ 300dpi shall be enough
  5070. var offsetX = Math.floor(bounds[0]);
  5071. var offsetY = Math.floor(bounds[1]);
  5072. var boundsWidth = Math.ceil(bounds[2]) - offsetX;
  5073. var boundsHeight = Math.ceil(bounds[3]) - offsetY;
  5074. var width = Math.min(Math.ceil(Math.abs(boundsWidth * combinesScale[0] *
  5075. EXPECTED_SCALE)), MAX_PATTERN_SIZE);
  5076. var height = Math.min(Math.ceil(Math.abs(boundsHeight * combinesScale[1] *
  5077. EXPECTED_SCALE)), MAX_PATTERN_SIZE);
  5078. var scaleX = boundsWidth / width;
  5079. var scaleY = boundsHeight / height;
  5080. var context = {
  5081. coords: coords,
  5082. colors: colors,
  5083. offsetX: -offsetX,
  5084. offsetY: -offsetY,
  5085. scaleX: 1 / scaleX,
  5086. scaleY: 1 / scaleY
  5087. };
  5088. var canvas, tmpCanvas, i, ii;
  5089. if (WebGLUtils.isEnabled) {
  5090. canvas = WebGLUtils.drawFigures(width, height, backgroundColor,
  5091. figures, context);
  5092. // https://bugzilla.mozilla.org/show_bug.cgi?id=972126
  5093. tmpCanvas = CachedCanvases.getCanvas('mesh', width, height, false);
  5094. tmpCanvas.context.drawImage(canvas, 0, 0);
  5095. canvas = tmpCanvas.canvas;
  5096. } else {
  5097. tmpCanvas = CachedCanvases.getCanvas('mesh', width, height, false);
  5098. var tmpCtx = tmpCanvas.context;
  5099. var data = tmpCtx.createImageData(width, height);
  5100. if (backgroundColor) {
  5101. var bytes = data.data;
  5102. for (i = 0, ii = bytes.length; i < ii; i += 4) {
  5103. bytes[i] = backgroundColor[0];
  5104. bytes[i + 1] = backgroundColor[1];
  5105. bytes[i + 2] = backgroundColor[2];
  5106. bytes[i + 3] = 255;
  5107. }
  5108. }
  5109. for (i = 0; i < figures.length; i++) {
  5110. drawFigure(data, figures[i], context);
  5111. }
  5112. tmpCtx.putImageData(data, 0, 0);
  5113. canvas = tmpCanvas.canvas;
  5114. }
  5115. return {canvas: canvas, offsetX: offsetX, offsetY: offsetY,
  5116. scaleX: scaleX, scaleY: scaleY};
  5117. }
  5118. return createMeshCanvas;
  5119. })();
  5120. ShadingIRs.Mesh = {
  5121. fromIR: function Mesh_fromIR(raw) {
  5122. //var type = raw[1];
  5123. var coords = raw[2];
  5124. var colors = raw[3];
  5125. var figures = raw[4];
  5126. var bounds = raw[5];
  5127. var matrix = raw[6];
  5128. //var bbox = raw[7];
  5129. var background = raw[8];
  5130. return {
  5131. type: 'Pattern',
  5132. getPattern: function Mesh_getPattern(ctx, owner, shadingFill) {
  5133. var scale;
  5134. if (shadingFill) {
  5135. scale = Util.singularValueDecompose2dScale(ctx.mozCurrentTransform);
  5136. } else {
  5137. // Obtain scale from matrix and current transformation matrix.
  5138. scale = Util.singularValueDecompose2dScale(owner.baseTransform);
  5139. if (matrix) {
  5140. var matrixScale = Util.singularValueDecompose2dScale(matrix);
  5141. scale = [scale[0] * matrixScale[0],
  5142. scale[1] * matrixScale[1]];
  5143. }
  5144. }
  5145. // Rasterizing on the main thread since sending/queue large canvases
  5146. // might cause OOM.
  5147. var temporaryPatternCanvas = createMeshCanvas(bounds, scale, coords,
  5148. colors, figures, shadingFill ? null : background);
  5149. if (!shadingFill) {
  5150. ctx.setTransform.apply(ctx, owner.baseTransform);
  5151. if (matrix) {
  5152. ctx.transform.apply(ctx, matrix);
  5153. }
  5154. }
  5155. ctx.translate(temporaryPatternCanvas.offsetX,
  5156. temporaryPatternCanvas.offsetY);
  5157. ctx.scale(temporaryPatternCanvas.scaleX,
  5158. temporaryPatternCanvas.scaleY);
  5159. return ctx.createPattern(temporaryPatternCanvas.canvas, 'no-repeat');
  5160. }
  5161. };
  5162. }
  5163. };
  5164. ShadingIRs.Dummy = {
  5165. fromIR: function Dummy_fromIR() {
  5166. return {
  5167. type: 'Pattern',
  5168. getPattern: function Dummy_fromIR_getPattern() {
  5169. return 'hotpink';
  5170. }
  5171. };
  5172. }
  5173. };
  5174. function getShadingPatternFromIR(raw) {
  5175. var shadingIR = ShadingIRs[raw[0]];
  5176. if (!shadingIR) {
  5177. error('Unknown IR type: ' + raw[0]);
  5178. }
  5179. return shadingIR.fromIR(raw);
  5180. }
  5181. var TilingPattern = (function TilingPatternClosure() {
  5182. var PaintType = {
  5183. COLORED: 1,
  5184. UNCOLORED: 2
  5185. };
  5186. var MAX_PATTERN_SIZE = 3000; // 10in @ 300dpi shall be enough
  5187. function TilingPattern(IR, color, ctx, objs, commonObjs, baseTransform) {
  5188. this.operatorList = IR[2];
  5189. this.matrix = IR[3] || [1, 0, 0, 1, 0, 0];
  5190. this.bbox = IR[4];
  5191. this.xstep = IR[5];
  5192. this.ystep = IR[6];
  5193. this.paintType = IR[7];
  5194. this.tilingType = IR[8];
  5195. this.color = color;
  5196. this.objs = objs;
  5197. this.commonObjs = commonObjs;
  5198. this.baseTransform = baseTransform;
  5199. this.type = 'Pattern';
  5200. this.ctx = ctx;
  5201. }
  5202. TilingPattern.prototype = {
  5203. createPatternCanvas: function TilinPattern_createPatternCanvas(owner) {
  5204. var operatorList = this.operatorList;
  5205. var bbox = this.bbox;
  5206. var xstep = this.xstep;
  5207. var ystep = this.ystep;
  5208. var paintType = this.paintType;
  5209. var tilingType = this.tilingType;
  5210. var color = this.color;
  5211. var objs = this.objs;
  5212. var commonObjs = this.commonObjs;
  5213. info('TilingType: ' + tilingType);
  5214. var x0 = bbox[0], y0 = bbox[1], x1 = bbox[2], y1 = bbox[3];
  5215. var topLeft = [x0, y0];
  5216. // we want the canvas to be as large as the step size
  5217. var botRight = [x0 + xstep, y0 + ystep];
  5218. var width = botRight[0] - topLeft[0];
  5219. var height = botRight[1] - topLeft[1];
  5220. // Obtain scale from matrix and current transformation matrix.
  5221. var matrixScale = Util.singularValueDecompose2dScale(this.matrix);
  5222. var curMatrixScale = Util.singularValueDecompose2dScale(
  5223. this.baseTransform);
  5224. var combinedScale = [matrixScale[0] * curMatrixScale[0],
  5225. matrixScale[1] * curMatrixScale[1]];
  5226. // MAX_PATTERN_SIZE is used to avoid OOM situation.
  5227. // Use width and height values that are as close as possible to the end
  5228. // result when the pattern is used. Too low value makes the pattern look
  5229. // blurry. Too large value makes it look too crispy.
  5230. width = Math.min(Math.ceil(Math.abs(width * combinedScale[0])),
  5231. MAX_PATTERN_SIZE);
  5232. height = Math.min(Math.ceil(Math.abs(height * combinedScale[1])),
  5233. MAX_PATTERN_SIZE);
  5234. var tmpCanvas = CachedCanvases.getCanvas('pattern', width, height, true);
  5235. var tmpCtx = tmpCanvas.context;
  5236. var graphics = new CanvasGraphics(tmpCtx, commonObjs, objs);
  5237. graphics.groupLevel = owner.groupLevel;
  5238. this.setFillAndStrokeStyleToContext(tmpCtx, paintType, color);
  5239. this.setScale(width, height, xstep, ystep);
  5240. this.transformToScale(graphics);
  5241. // transform coordinates to pattern space
  5242. var tmpTranslate = [1, 0, 0, 1, -topLeft[0], -topLeft[1]];
  5243. graphics.transform.apply(graphics, tmpTranslate);
  5244. this.clipBbox(graphics, bbox, x0, y0, x1, y1);
  5245. graphics.executeOperatorList(operatorList);
  5246. return tmpCanvas.canvas;
  5247. },
  5248. setScale: function TilingPattern_setScale(width, height, xstep, ystep) {
  5249. this.scale = [width / xstep, height / ystep];
  5250. },
  5251. transformToScale: function TilingPattern_transformToScale(graphics) {
  5252. var scale = this.scale;
  5253. var tmpScale = [scale[0], 0, 0, scale[1], 0, 0];
  5254. graphics.transform.apply(graphics, tmpScale);
  5255. },
  5256. scaleToContext: function TilingPattern_scaleToContext() {
  5257. var scale = this.scale;
  5258. this.ctx.scale(1 / scale[0], 1 / scale[1]);
  5259. },
  5260. clipBbox: function clipBbox(graphics, bbox, x0, y0, x1, y1) {
  5261. if (bbox && isArray(bbox) && bbox.length === 4) {
  5262. var bboxWidth = x1 - x0;
  5263. var bboxHeight = y1 - y0;
  5264. graphics.ctx.rect(x0, y0, bboxWidth, bboxHeight);
  5265. graphics.clip();
  5266. graphics.endPath();
  5267. }
  5268. },
  5269. setFillAndStrokeStyleToContext:
  5270. function setFillAndStrokeStyleToContext(context, paintType, color) {
  5271. switch (paintType) {
  5272. case PaintType.COLORED:
  5273. var ctx = this.ctx;
  5274. context.fillStyle = ctx.fillStyle;
  5275. context.strokeStyle = ctx.strokeStyle;
  5276. break;
  5277. case PaintType.UNCOLORED:
  5278. var cssColor = Util.makeCssRgb(color);
  5279. context.fillStyle = cssColor;
  5280. context.strokeStyle = cssColor;
  5281. break;
  5282. default:
  5283. error('Unsupported paint type: ' + paintType);
  5284. }
  5285. },
  5286. getPattern: function TilingPattern_getPattern(ctx, owner) {
  5287. var temporaryPatternCanvas = this.createPatternCanvas(owner);
  5288. ctx = this.ctx;
  5289. ctx.setTransform.apply(ctx, this.baseTransform);
  5290. ctx.transform.apply(ctx, this.matrix);
  5291. this.scaleToContext();
  5292. return ctx.createPattern(temporaryPatternCanvas, 'repeat');
  5293. }
  5294. };
  5295. return TilingPattern;
  5296. })();
  5297. PDFJS.disableFontFace = false;
  5298. var FontLoader = {
  5299. insertRule: function fontLoaderInsertRule(rule) {
  5300. var styleElement = document.getElementById('PDFJS_FONT_STYLE_TAG');
  5301. if (!styleElement) {
  5302. styleElement = document.createElement('style');
  5303. styleElement.id = 'PDFJS_FONT_STYLE_TAG';
  5304. document.documentElement.getElementsByTagName('head')[0].appendChild(
  5305. styleElement);
  5306. }
  5307. var styleSheet = styleElement.sheet;
  5308. styleSheet.insertRule(rule, styleSheet.cssRules.length);
  5309. },
  5310. clear: function fontLoaderClear() {
  5311. var styleElement = document.getElementById('PDFJS_FONT_STYLE_TAG');
  5312. if (styleElement) {
  5313. styleElement.parentNode.removeChild(styleElement);
  5314. }
  5315. },
  5316. get loadTestFont() {
  5317. // This is a CFF font with 1 glyph for '.' that fills its entire width and
  5318. // height.
  5319. return shadow(this, 'loadTestFont', atob(
  5320. 'T1RUTwALAIAAAwAwQ0ZGIDHtZg4AAAOYAAAAgUZGVE1lkzZwAAAEHAAAABxHREVGABQAFQ' +
  5321. 'AABDgAAAAeT1MvMlYNYwkAAAEgAAAAYGNtYXABDQLUAAACNAAAAUJoZWFk/xVFDQAAALwA' +
  5322. 'AAA2aGhlYQdkA+oAAAD0AAAAJGhtdHgD6AAAAAAEWAAAAAZtYXhwAAJQAAAAARgAAAAGbm' +
  5323. 'FtZVjmdH4AAAGAAAAAsXBvc3T/hgAzAAADeAAAACAAAQAAAAEAALZRFsRfDzz1AAsD6AAA' +
  5324. 'AADOBOTLAAAAAM4KHDwAAAAAA+gDIQAAAAgAAgAAAAAAAAABAAADIQAAAFoD6AAAAAAD6A' +
  5325. 'ABAAAAAAAAAAAAAAAAAAAAAQAAUAAAAgAAAAQD6AH0AAUAAAKKArwAAACMAooCvAAAAeAA' +
  5326. 'MQECAAACAAYJAAAAAAAAAAAAAQAAAAAAAAAAAAAAAFBmRWQAwAAuAC4DIP84AFoDIQAAAA' +
  5327. 'AAAQAAAAAAAAAAACAAIAABAAAADgCuAAEAAAAAAAAAAQAAAAEAAAAAAAEAAQAAAAEAAAAA' +
  5328. 'AAIAAQAAAAEAAAAAAAMAAQAAAAEAAAAAAAQAAQAAAAEAAAAAAAUAAQAAAAEAAAAAAAYAAQ' +
  5329. 'AAAAMAAQQJAAAAAgABAAMAAQQJAAEAAgABAAMAAQQJAAIAAgABAAMAAQQJAAMAAgABAAMA' +
  5330. 'AQQJAAQAAgABAAMAAQQJAAUAAgABAAMAAQQJAAYAAgABWABYAAAAAAAAAwAAAAMAAAAcAA' +
  5331. 'EAAAAAADwAAwABAAAAHAAEACAAAAAEAAQAAQAAAC7//wAAAC7////TAAEAAAAAAAABBgAA' +
  5332. 'AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAA' +
  5333. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' +
  5334. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' +
  5335. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' +
  5336. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMAAA' +
  5337. 'AAAAD/gwAyAAAAAQAAAAAAAAAAAAAAAAAAAAABAAQEAAEBAQJYAAEBASH4DwD4GwHEAvgc' +
  5338. 'A/gXBIwMAYuL+nz5tQXkD5j3CBLnEQACAQEBIVhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWF' +
  5339. 'hYWFhYWFhYAAABAQAADwACAQEEE/t3Dov6fAH6fAT+fPp8+nwHDosMCvm1Cvm1DAz6fBQA' +
  5340. 'AAAAAAABAAAAAMmJbzEAAAAAzgTjFQAAAADOBOQpAAEAAAAAAAAADAAUAAQAAAABAAAAAg' +
  5341. 'ABAAAAAAAAAAAD6AAAAAAAAA=='
  5342. ));
  5343. },
  5344. loadTestFontId: 0,
  5345. loadingContext: {
  5346. requests: [],
  5347. nextRequestId: 0
  5348. },
  5349. isSyncFontLoadingSupported: (function detectSyncFontLoadingSupport() {
  5350. if (isWorker) {
  5351. return false;
  5352. }
  5353. // User agent string sniffing is bad, but there is no reliable way to tell
  5354. // if font is fully loaded and ready to be used with canvas.
  5355. var userAgent = window.navigator.userAgent;
  5356. var m = /Mozilla\/5.0.*?rv:(\d+).*? Gecko/.exec(userAgent);
  5357. if (m && m[1] >= 14) {
  5358. return true;
  5359. }
  5360. // TODO other browsers
  5361. return false;
  5362. })(),
  5363. bind: function fontLoaderBind(fonts, callback) {
  5364. assert(!isWorker, 'bind() shall be called from main thread');
  5365. var rules = [], fontsToLoad = [];
  5366. for (var i = 0, ii = fonts.length; i < ii; i++) {
  5367. var font = fonts[i];
  5368. // Add the font to the DOM only once or skip if the font
  5369. // is already loaded.
  5370. if (font.attached || font.loading === false) {
  5371. continue;
  5372. }
  5373. font.attached = true;
  5374. var rule = font.bindDOM();
  5375. if (rule) {
  5376. rules.push(rule);
  5377. fontsToLoad.push(font);
  5378. }
  5379. }
  5380. var request = FontLoader.queueLoadingCallback(callback);
  5381. if (rules.length > 0 && !this.isSyncFontLoadingSupported) {
  5382. FontLoader.prepareFontLoadEvent(rules, fontsToLoad, request);
  5383. } else {
  5384. request.complete();
  5385. }
  5386. },
  5387. queueLoadingCallback: function FontLoader_queueLoadingCallback(callback) {
  5388. function LoadLoader_completeRequest() {
  5389. assert(!request.end, 'completeRequest() cannot be called twice');
  5390. request.end = Date.now();
  5391. // sending all completed requests in order how they were queued
  5392. while (context.requests.length > 0 && context.requests[0].end) {
  5393. var otherRequest = context.requests.shift();
  5394. setTimeout(otherRequest.callback, 0);
  5395. }
  5396. }
  5397. var context = FontLoader.loadingContext;
  5398. var requestId = 'pdfjs-font-loading-' + (context.nextRequestId++);
  5399. var request = {
  5400. id: requestId,
  5401. complete: LoadLoader_completeRequest,
  5402. callback: callback,
  5403. started: Date.now()
  5404. };
  5405. context.requests.push(request);
  5406. return request;
  5407. },
  5408. prepareFontLoadEvent: function fontLoaderPrepareFontLoadEvent(rules,
  5409. fonts,
  5410. request) {
  5411. /** Hack begin */
  5412. // There's currently no event when a font has finished downloading so the
  5413. // following code is a dirty hack to 'guess' when a font is
  5414. // ready. It's assumed fonts are loaded in order, so add a known test
  5415. // font after the desired fonts and then test for the loading of that
  5416. // test font.
  5417. function int32(data, offset) {
  5418. return (data.charCodeAt(offset) << 24) |
  5419. (data.charCodeAt(offset + 1) << 16) |
  5420. (data.charCodeAt(offset + 2) << 8) |
  5421. (data.charCodeAt(offset + 3) & 0xff);
  5422. }
  5423. function spliceString(s, offset, remove, insert) {
  5424. var chunk1 = s.substr(0, offset);
  5425. var chunk2 = s.substr(offset + remove);
  5426. return chunk1 + insert + chunk2;
  5427. }
  5428. var i, ii;
  5429. var canvas = document.createElement('canvas');
  5430. canvas.width = 1;
  5431. canvas.height = 1;
  5432. var ctx = canvas.getContext('2d');
  5433. var called = 0;
  5434. function isFontReady(name, callback) {
  5435. called++;
  5436. // With setTimeout clamping this gives the font ~100ms to load.
  5437. if(called > 30) {
  5438. warn('Load test font never loaded.');
  5439. callback();
  5440. return;
  5441. }
  5442. ctx.font = '30px ' + name;
  5443. ctx.fillText('.', 0, 20);
  5444. var imageData = ctx.getImageData(0, 0, 1, 1);
  5445. if (imageData.data[3] > 0) {
  5446. callback();
  5447. return;
  5448. }
  5449. setTimeout(isFontReady.bind(null, name, callback));
  5450. }
  5451. var loadTestFontId = 'lt' + Date.now() + this.loadTestFontId++;
  5452. // Chromium seems to cache fonts based on a hash of the actual font data,
  5453. // so the font must be modified for each load test else it will appear to
  5454. // be loaded already.
  5455. // TODO: This could maybe be made faster by avoiding the btoa of the full
  5456. // font by splitting it in chunks before hand and padding the font id.
  5457. var data = this.loadTestFont;
  5458. var COMMENT_OFFSET = 976; // has to be on 4 byte boundary (for checksum)
  5459. data = spliceString(data, COMMENT_OFFSET, loadTestFontId.length,
  5460. loadTestFontId);
  5461. // CFF checksum is important for IE, adjusting it
  5462. var CFF_CHECKSUM_OFFSET = 16;
  5463. var XXXX_VALUE = 0x58585858; // the "comment" filled with 'X'
  5464. var checksum = int32(data, CFF_CHECKSUM_OFFSET);
  5465. for (i = 0, ii = loadTestFontId.length - 3; i < ii; i += 4) {
  5466. checksum = (checksum - XXXX_VALUE + int32(loadTestFontId, i)) | 0;
  5467. }
  5468. if (i < loadTestFontId.length) { // align to 4 bytes boundary
  5469. checksum = (checksum - XXXX_VALUE +
  5470. int32(loadTestFontId + 'XXX', i)) | 0;
  5471. }
  5472. data = spliceString(data, CFF_CHECKSUM_OFFSET, 4, string32(checksum));
  5473. var url = 'url(data:font/opentype;base64,' + btoa(data) + ');';
  5474. var rule = '@font-face { font-family:"' + loadTestFontId + '";src:' +
  5475. url + '}';
  5476. FontLoader.insertRule(rule);
  5477. var names = [];
  5478. for (i = 0, ii = fonts.length; i < ii; i++) {
  5479. names.push(fonts[i].loadedName);
  5480. }
  5481. names.push(loadTestFontId);
  5482. var div = document.createElement('div');
  5483. div.setAttribute('style',
  5484. 'visibility: hidden;' +
  5485. 'width: 10px; height: 10px;' +
  5486. 'position: absolute; top: 0px; left: 0px;');
  5487. for (i = 0, ii = names.length; i < ii; ++i) {
  5488. var span = document.createElement('span');
  5489. span.textContent = 'Hi';
  5490. span.style.fontFamily = names[i];
  5491. div.appendChild(span);
  5492. }
  5493. document.body.appendChild(div);
  5494. isFontReady(loadTestFontId, function() {
  5495. document.body.removeChild(div);
  5496. request.complete();
  5497. });
  5498. /** Hack end */
  5499. }
  5500. };
  5501. var FontFace = (function FontFaceClosure() {
  5502. function FontFace(name, file, properties) {
  5503. this.compiledGlyphs = {};
  5504. if (arguments.length === 1) {
  5505. // importing translated data
  5506. var data = arguments[0];
  5507. for (var i in data) {
  5508. this[i] = data[i];
  5509. }
  5510. return;
  5511. }
  5512. }
  5513. FontFace.prototype = {
  5514. bindDOM: function FontFace_bindDOM() {
  5515. if (!this.data) {
  5516. return null;
  5517. }
  5518. if (PDFJS.disableFontFace) {
  5519. this.disableFontFace = true;
  5520. return null;
  5521. }
  5522. var data = bytesToString(new Uint8Array(this.data));
  5523. var fontName = this.loadedName;
  5524. // Add the font-face rule to the document
  5525. var url = ('url(data:' + this.mimetype + ';base64,' +
  5526. window.btoa(data) + ');');
  5527. var rule = '@font-face { font-family:"' + fontName + '";src:' + url + '}';
  5528. FontLoader.insertRule(rule);
  5529. if (PDFJS.pdfBug && 'FontInspector' in globalScope &&
  5530. globalScope['FontInspector'].enabled) {
  5531. globalScope['FontInspector'].fontAdded(this, url);
  5532. }
  5533. return rule;
  5534. },
  5535. getPathGenerator: function (objs, character) {
  5536. if (!(character in this.compiledGlyphs)) {
  5537. var js = objs.get(this.loadedName + '_path_' + character);
  5538. /*jshint -W054 */
  5539. this.compiledGlyphs[character] = new Function('c', 'size', js);
  5540. }
  5541. return this.compiledGlyphs[character];
  5542. }
  5543. };
  5544. return FontFace;
  5545. })();
  5546. var HIGHLIGHT_OFFSET = 4; // px
  5547. var ANNOT_MIN_SIZE = 10; // px
  5548. var AnnotationUtils = (function AnnotationUtilsClosure() {
  5549. // TODO(mack): This dupes some of the logic in CanvasGraphics.setFont()
  5550. function setTextStyles(element, item, fontObj) {
  5551. var style = element.style;
  5552. style.fontSize = item.fontSize + 'px';
  5553. style.direction = item.fontDirection < 0 ? 'rtl': 'ltr';
  5554. if (!fontObj) {
  5555. return;
  5556. }
  5557. style.fontWeight = fontObj.black ?
  5558. (fontObj.bold ? 'bolder' : 'bold') :
  5559. (fontObj.bold ? 'bold' : 'normal');
  5560. style.fontStyle = fontObj.italic ? 'italic' : 'normal';
  5561. var fontName = fontObj.loadedName;
  5562. var fontFamily = fontName ? '"' + fontName + '", ' : '';
  5563. // Use a reasonable default font if the font doesn't specify a fallback
  5564. var fallbackName = fontObj.fallbackName || 'Helvetica, sans-serif';
  5565. style.fontFamily = fontFamily + fallbackName;
  5566. }
  5567. // TODO(mack): Remove this, it's not really that helpful.
  5568. function getEmptyContainer(tagName, rect, borderWidth) {
  5569. var bWidth = borderWidth || 0;
  5570. var element = document.createElement(tagName);
  5571. element.style.borderWidth = bWidth + 'px';
  5572. var width = rect[2] - rect[0] - 2 * bWidth;
  5573. var height = rect[3] - rect[1] - 2 * bWidth;
  5574. element.style.width = width + 'px';
  5575. element.style.height = height + 'px';
  5576. return element;
  5577. }
  5578. function initContainer(item) {
  5579. var container = getEmptyContainer('section', item.rect, item.borderWidth);
  5580. container.style.backgroundColor = item.color;
  5581. var color = item.color;
  5582. var rgb = [];
  5583. for (var i = 0; i < 3; ++i) {
  5584. rgb[i] = Math.round(color[i] * 255);
  5585. }
  5586. item.colorCssRgb = Util.makeCssRgb(rgb);
  5587. var highlight = document.createElement('div');
  5588. highlight.className = 'annotationHighlight';
  5589. highlight.style.left = highlight.style.top = -HIGHLIGHT_OFFSET + 'px';
  5590. highlight.style.right = highlight.style.bottom = -HIGHLIGHT_OFFSET + 'px';
  5591. highlight.setAttribute('hidden', true);
  5592. item.highlightElement = highlight;
  5593. container.appendChild(item.highlightElement);
  5594. return container;
  5595. }
  5596. function getHtmlElementForTextWidgetAnnotation(item, commonObjs) {
  5597. var element = getEmptyContainer('div', item.rect, 0);
  5598. element.style.display = 'table';
  5599. var content = document.createElement('div');
  5600. content.textContent = item.fieldValue;
  5601. var textAlignment = item.textAlignment;
  5602. content.style.textAlign = ['left', 'center', 'right'][textAlignment];
  5603. content.style.verticalAlign = 'middle';
  5604. content.style.display = 'table-cell';
  5605. var fontObj = item.fontRefName ?
  5606. commonObjs.getData(item.fontRefName) : null;
  5607. setTextStyles(content, item, fontObj);
  5608. element.appendChild(content);
  5609. return element;
  5610. }
  5611. function getHtmlElementForTextAnnotation(item) {
  5612. var rect = item.rect;
  5613. // sanity check because of OOo-generated PDFs
  5614. if ((rect[3] - rect[1]) < ANNOT_MIN_SIZE) {
  5615. rect[3] = rect[1] + ANNOT_MIN_SIZE;
  5616. }
  5617. if ((rect[2] - rect[0]) < ANNOT_MIN_SIZE) {
  5618. rect[2] = rect[0] + (rect[3] - rect[1]); // make it square
  5619. }
  5620. var container = initContainer(item);
  5621. container.className = 'annotText';
  5622. var image = document.createElement('img');
  5623. image.style.height = container.style.height;
  5624. image.style.width = container.style.width;
  5625. var iconName = item.name;
  5626. image.src = PDFJS.imageResourcesPath + 'annotation-' +
  5627. iconName.toLowerCase() + '.svg';
  5628. image.alt = '[{{type}} Annotation]';
  5629. image.dataset.l10nId = 'text_annotation_type';
  5630. image.dataset.l10nArgs = JSON.stringify({type: iconName});
  5631. var contentWrapper = document.createElement('div');
  5632. contentWrapper.className = 'annotTextContentWrapper';
  5633. contentWrapper.style.left = Math.floor(rect[2] - rect[0] + 5) + 'px';
  5634. contentWrapper.style.top = '-10px';
  5635. var content = document.createElement('div');
  5636. content.className = 'annotTextContent';
  5637. content.setAttribute('hidden', true);
  5638. var i, ii;
  5639. if (item.hasBgColor) {
  5640. var color = item.color;
  5641. var rgb = [];
  5642. for (i = 0; i < 3; ++i) {
  5643. // Enlighten the color (70%)
  5644. var c = Math.round(color[i] * 255);
  5645. rgb[i] = Math.round((255 - c) * 0.7) + c;
  5646. }
  5647. content.style.backgroundColor = Util.makeCssRgb(rgb);
  5648. }
  5649. var title = document.createElement('h1');
  5650. var text = document.createElement('p');
  5651. title.textContent = item.title;
  5652. if (!item.content && !item.title) {
  5653. content.setAttribute('hidden', true);
  5654. } else {
  5655. var e = document.createElement('span');
  5656. var lines = item.content.split(/(?:\r\n?|\n)/);
  5657. for (i = 0, ii = lines.length; i < ii; ++i) {
  5658. var line = lines[i];
  5659. e.appendChild(document.createTextNode(line));
  5660. if (i < (ii - 1)) {
  5661. e.appendChild(document.createElement('br'));
  5662. }
  5663. }
  5664. text.appendChild(e);
  5665. var pinned = false;
  5666. var showAnnotation = function showAnnotation(pin) {
  5667. if (pin) {
  5668. pinned = true;
  5669. }
  5670. if (content.hasAttribute('hidden')) {
  5671. container.style.zIndex += 1;
  5672. content.removeAttribute('hidden');
  5673. }
  5674. };
  5675. var hideAnnotation = function hideAnnotation(unpin) {
  5676. if (unpin) {
  5677. pinned = false;
  5678. }
  5679. if (!content.hasAttribute('hidden') && !pinned) {
  5680. container.style.zIndex -= 1;
  5681. content.setAttribute('hidden', true);
  5682. }
  5683. };
  5684. var toggleAnnotation = function toggleAnnotation() {
  5685. if (pinned) {
  5686. hideAnnotation(true);
  5687. } else {
  5688. showAnnotation(true);
  5689. }
  5690. };
  5691. image.addEventListener('click', function image_clickHandler() {
  5692. toggleAnnotation();
  5693. }, false);
  5694. image.addEventListener('mouseover', function image_mouseOverHandler() {
  5695. showAnnotation();
  5696. }, false);
  5697. image.addEventListener('mouseout', function image_mouseOutHandler() {
  5698. hideAnnotation();
  5699. }, false);
  5700. content.addEventListener('click', function content_clickHandler() {
  5701. hideAnnotation(true);
  5702. }, false);
  5703. }
  5704. content.appendChild(title);
  5705. content.appendChild(text);
  5706. contentWrapper.appendChild(content);
  5707. container.appendChild(image);
  5708. container.appendChild(contentWrapper);
  5709. return container;
  5710. }
  5711. function getHtmlElementForLinkAnnotation(item) {
  5712. var container = initContainer(item);
  5713. container.className = 'annotLink';
  5714. container.style.borderColor = item.colorCssRgb;
  5715. container.style.borderStyle = 'solid';
  5716. var link = document.createElement('a');
  5717. link.href = link.title = item.url || '';
  5718. container.appendChild(link);
  5719. return container;
  5720. }
  5721. function getHtmlElement(data, objs) {
  5722. switch (data.annotationType) {
  5723. case AnnotationType.WIDGET:
  5724. return getHtmlElementForTextWidgetAnnotation(data, objs);
  5725. case AnnotationType.TEXT:
  5726. return getHtmlElementForTextAnnotation(data);
  5727. case AnnotationType.LINK:
  5728. return getHtmlElementForLinkAnnotation(data);
  5729. default:
  5730. throw new Error('Unsupported annotationType: ' + data.annotationType);
  5731. }
  5732. }
  5733. return {
  5734. getHtmlElement: getHtmlElement
  5735. };
  5736. })();
  5737. PDFJS.AnnotationUtils = AnnotationUtils;
  5738. var NetworkManager = (function NetworkManagerClosure() {
  5739. var OK_RESPONSE = 200;
  5740. var PARTIAL_CONTENT_RESPONSE = 206;
  5741. function NetworkManager(url, args) {
  5742. this.url = url;
  5743. args = args || {};
  5744. this.isHttp = /^https?:/i.test(url);
  5745. this.httpHeaders = (this.isHttp && args.httpHeaders) || {};
  5746. this.withCredentials = args.withCredentials || false;
  5747. this.getXhr = args.getXhr ||
  5748. function NetworkManager_getXhr() {
  5749. return new XMLHttpRequest();
  5750. };
  5751. this.currXhrId = 0;
  5752. this.pendingRequests = {};
  5753. this.loadedRequests = {};
  5754. }
  5755. function getArrayBuffer(xhr) {
  5756. var data = xhr.response;
  5757. if (typeof data !== 'string') {
  5758. return data;
  5759. }
  5760. var length = data.length;
  5761. var buffer = new Uint8Array(length);
  5762. for (var i = 0; i < length; i++) {
  5763. buffer[i] = data.charCodeAt(i) & 0xFF;
  5764. }
  5765. return buffer;
  5766. }
  5767. NetworkManager.prototype = {
  5768. requestRange: function NetworkManager_requestRange(begin, end, listeners) {
  5769. var args = {
  5770. begin: begin,
  5771. end: end
  5772. };
  5773. for (var prop in listeners) {
  5774. args[prop] = listeners[prop];
  5775. }
  5776. return this.request(args);
  5777. },
  5778. requestFull: function NetworkManager_requestRange(listeners) {
  5779. return this.request(listeners);
  5780. },
  5781. request: function NetworkManager_requestRange(args) {
  5782. var xhr = this.getXhr();
  5783. var xhrId = this.currXhrId++;
  5784. var pendingRequest = this.pendingRequests[xhrId] = {
  5785. xhr: xhr
  5786. };
  5787. xhr.open('GET', this.url);
  5788. xhr.withCredentials = this.withCredentials;
  5789. for (var property in this.httpHeaders) {
  5790. var value = this.httpHeaders[property];
  5791. if (typeof value === 'undefined') {
  5792. continue;
  5793. }
  5794. xhr.setRequestHeader(property, value);
  5795. }
  5796. if (this.isHttp && 'begin' in args && 'end' in args) {
  5797. var rangeStr = args.begin + '-' + (args.end - 1);
  5798. xhr.setRequestHeader('Range', 'bytes=' + rangeStr);
  5799. pendingRequest.expectedStatus = 206;
  5800. } else {
  5801. pendingRequest.expectedStatus = 200;
  5802. }
  5803. xhr.responseType = 'arraybuffer';
  5804. if (args.onProgress) {
  5805. xhr.onprogress = args.onProgress;
  5806. }
  5807. if (args.onError) {
  5808. xhr.onerror = function(evt) {
  5809. args.onError(xhr.status);
  5810. };
  5811. }
  5812. xhr.onreadystatechange = this.onStateChange.bind(this, xhrId);
  5813. pendingRequest.onHeadersReceived = args.onHeadersReceived;
  5814. pendingRequest.onDone = args.onDone;
  5815. pendingRequest.onError = args.onError;
  5816. xhr.send(null);
  5817. return xhrId;
  5818. },
  5819. onStateChange: function NetworkManager_onStateChange(xhrId, evt) {
  5820. var pendingRequest = this.pendingRequests[xhrId];
  5821. if (!pendingRequest) {
  5822. // Maybe abortRequest was called...
  5823. return;
  5824. }
  5825. var xhr = pendingRequest.xhr;
  5826. if (xhr.readyState >= 2 && pendingRequest.onHeadersReceived) {
  5827. pendingRequest.onHeadersReceived();
  5828. delete pendingRequest.onHeadersReceived;
  5829. }
  5830. if (xhr.readyState !== 4) {
  5831. return;
  5832. }
  5833. if (!(xhrId in this.pendingRequests)) {
  5834. // The XHR request might have been aborted in onHeadersReceived()
  5835. // callback, in which case we should abort request
  5836. return;
  5837. }
  5838. delete this.pendingRequests[xhrId];
  5839. // success status == 0 can be on ftp, file and other protocols
  5840. if (xhr.status === 0 && this.isHttp) {
  5841. if (pendingRequest.onError) {
  5842. pendingRequest.onError(xhr.status);
  5843. }
  5844. return;
  5845. }
  5846. var xhrStatus = xhr.status || OK_RESPONSE;
  5847. // From http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35.2:
  5848. // "A server MAY ignore the Range header". This means it's possible to
  5849. // get a 200 rather than a 206 response from a range request.
  5850. var ok_response_on_range_request =
  5851. xhrStatus === OK_RESPONSE &&
  5852. pendingRequest.expectedStatus === PARTIAL_CONTENT_RESPONSE;
  5853. if (!ok_response_on_range_request &&
  5854. xhrStatus !== pendingRequest.expectedStatus) {
  5855. if (pendingRequest.onError) {
  5856. pendingRequest.onError(xhr.status);
  5857. }
  5858. return;
  5859. }
  5860. this.loadedRequests[xhrId] = true;
  5861. var chunk = getArrayBuffer(xhr);
  5862. if (xhrStatus === PARTIAL_CONTENT_RESPONSE) {
  5863. var rangeHeader = xhr.getResponseHeader('Content-Range');
  5864. var matches = /bytes (\d+)-(\d+)\/(\d+)/.exec(rangeHeader);
  5865. var begin = parseInt(matches[1], 10);
  5866. pendingRequest.onDone({
  5867. begin: begin,
  5868. chunk: chunk
  5869. });
  5870. } else {
  5871. pendingRequest.onDone({
  5872. begin: 0,
  5873. chunk: chunk
  5874. });
  5875. }
  5876. },
  5877. hasPendingRequests: function NetworkManager_hasPendingRequests() {
  5878. for (var xhrId in this.pendingRequests) {
  5879. return true;
  5880. }
  5881. return false;
  5882. },
  5883. getRequestXhr: function NetworkManager_getXhr(xhrId) {
  5884. return this.pendingRequests[xhrId].xhr;
  5885. },
  5886. isPendingRequest: function NetworkManager_isPendingRequest(xhrId) {
  5887. return xhrId in this.pendingRequests;
  5888. },
  5889. isLoadedRequest: function NetworkManager_isLoadedRequest(xhrId) {
  5890. return xhrId in this.loadedRequests;
  5891. },
  5892. abortAllRequests: function NetworkManager_abortAllRequests() {
  5893. for (var xhrId in this.pendingRequests) {
  5894. this.abortRequest(xhrId | 0);
  5895. }
  5896. },
  5897. abortRequest: function NetworkManager_abortRequest(xhrId) {
  5898. var xhr = this.pendingRequests[xhrId].xhr;
  5899. delete this.pendingRequests[xhrId];
  5900. xhr.abort();
  5901. }
  5902. };
  5903. return NetworkManager;
  5904. })();
  5905. var ChunkedStream = (function ChunkedStreamClosure() {
  5906. function ChunkedStream(length, chunkSize, manager) {
  5907. this.bytes = new Uint8Array(length);
  5908. this.start = 0;
  5909. this.pos = 0;
  5910. this.end = length;
  5911. this.chunkSize = chunkSize;
  5912. this.loadedChunks = [];
  5913. this.numChunksLoaded = 0;
  5914. this.numChunks = Math.ceil(length / chunkSize);
  5915. this.manager = manager;
  5916. this.initialDataLength = 0;
  5917. this.lastSuccessfulEnsureByteChunk = -1; // a single-entry cache
  5918. }
  5919. // required methods for a stream. if a particular stream does not
  5920. // implement these, an error should be thrown
  5921. ChunkedStream.prototype = {
  5922. getMissingChunks: function ChunkedStream_getMissingChunks() {
  5923. var chunks = [];
  5924. for (var chunk = 0, n = this.numChunks; chunk < n; ++chunk) {
  5925. if (!(chunk in this.loadedChunks)) {
  5926. chunks.push(chunk);
  5927. }
  5928. }
  5929. return chunks;
  5930. },
  5931. getBaseStreams: function ChunkedStream_getBaseStreams() {
  5932. return [this];
  5933. },
  5934. allChunksLoaded: function ChunkedStream_allChunksLoaded() {
  5935. return this.numChunksLoaded === this.numChunks;
  5936. },
  5937. onReceiveData: function ChunkedStream_onReceiveData(begin, chunk) {
  5938. var end = begin + chunk.byteLength;
  5939. assert(begin % this.chunkSize === 0, 'Bad begin offset: ' + begin);
  5940. // Using this.length is inaccurate here since this.start can be moved
  5941. // See ChunkedStream.moveStart()
  5942. var length = this.bytes.length;
  5943. assert(end % this.chunkSize === 0 || end === length,
  5944. 'Bad end offset: ' + end);
  5945. this.bytes.set(new Uint8Array(chunk), begin);
  5946. var chunkSize = this.chunkSize;
  5947. var beginChunk = Math.floor(begin / chunkSize);
  5948. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  5949. var curChunk;
  5950. for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  5951. if (!(curChunk in this.loadedChunks)) {
  5952. this.loadedChunks[curChunk] = true;
  5953. ++this.numChunksLoaded;
  5954. }
  5955. }
  5956. },
  5957. onReceiveInitialData: function ChunkedStream_onReceiveInitialData(data) {
  5958. this.bytes.set(data);
  5959. this.initialDataLength = data.length;
  5960. var endChunk = (this.end === data.length ?
  5961. this.numChunks : Math.floor(data.length / this.chunkSize));
  5962. for (var i = 0; i < endChunk; i++) {
  5963. this.loadedChunks[i] = true;
  5964. ++this.numChunksLoaded;
  5965. }
  5966. },
  5967. ensureByte: function ChunkedStream_ensureRange(pos) {
  5968. var chunk = Math.floor(pos / this.chunkSize);
  5969. if (chunk === this.lastSuccessfulEnsureByteChunk) {
  5970. return;
  5971. }
  5972. if (!(chunk in this.loadedChunks)) {
  5973. throw new MissingDataException(pos, pos + 1);
  5974. }
  5975. this.lastSuccessfulEnsureByteChunk = chunk;
  5976. },
  5977. ensureRange: function ChunkedStream_ensureRange(begin, end) {
  5978. if (begin >= end) {
  5979. return;
  5980. }
  5981. if (end <= this.initialDataLength) {
  5982. return;
  5983. }
  5984. var chunkSize = this.chunkSize;
  5985. var beginChunk = Math.floor(begin / chunkSize);
  5986. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  5987. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  5988. if (!(chunk in this.loadedChunks)) {
  5989. throw new MissingDataException(begin, end);
  5990. }
  5991. }
  5992. },
  5993. nextEmptyChunk: function ChunkedStream_nextEmptyChunk(beginChunk) {
  5994. var chunk, n;
  5995. for (chunk = beginChunk, n = this.numChunks; chunk < n; ++chunk) {
  5996. if (!(chunk in this.loadedChunks)) {
  5997. return chunk;
  5998. }
  5999. }
  6000. // Wrap around to beginning
  6001. for (chunk = 0; chunk < beginChunk; ++chunk) {
  6002. if (!(chunk in this.loadedChunks)) {
  6003. return chunk;
  6004. }
  6005. }
  6006. return null;
  6007. },
  6008. hasChunk: function ChunkedStream_hasChunk(chunk) {
  6009. return chunk in this.loadedChunks;
  6010. },
  6011. get length() {
  6012. return this.end - this.start;
  6013. },
  6014. get isEmpty() {
  6015. return this.length === 0;
  6016. },
  6017. getByte: function ChunkedStream_getByte() {
  6018. var pos = this.pos;
  6019. if (pos >= this.end) {
  6020. return -1;
  6021. }
  6022. this.ensureByte(pos);
  6023. return this.bytes[this.pos++];
  6024. },
  6025. getUint16: function ChunkedStream_getUint16() {
  6026. var b0 = this.getByte();
  6027. var b1 = this.getByte();
  6028. return (b0 << 8) + b1;
  6029. },
  6030. getInt32: function ChunkedStream_getInt32() {
  6031. var b0 = this.getByte();
  6032. var b1 = this.getByte();
  6033. var b2 = this.getByte();
  6034. var b3 = this.getByte();
  6035. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  6036. },
  6037. // returns subarray of original buffer
  6038. // should only be read
  6039. getBytes: function ChunkedStream_getBytes(length) {
  6040. var bytes = this.bytes;
  6041. var pos = this.pos;
  6042. var strEnd = this.end;
  6043. if (!length) {
  6044. this.ensureRange(pos, strEnd);
  6045. return bytes.subarray(pos, strEnd);
  6046. }
  6047. var end = pos + length;
  6048. if (end > strEnd) {
  6049. end = strEnd;
  6050. }
  6051. this.ensureRange(pos, end);
  6052. this.pos = end;
  6053. return bytes.subarray(pos, end);
  6054. },
  6055. peekBytes: function ChunkedStream_peekBytes(length) {
  6056. var bytes = this.getBytes(length);
  6057. this.pos -= bytes.length;
  6058. return bytes;
  6059. },
  6060. getByteRange: function ChunkedStream_getBytes(begin, end) {
  6061. this.ensureRange(begin, end);
  6062. return this.bytes.subarray(begin, end);
  6063. },
  6064. skip: function ChunkedStream_skip(n) {
  6065. if (!n) {
  6066. n = 1;
  6067. }
  6068. this.pos += n;
  6069. },
  6070. reset: function ChunkedStream_reset() {
  6071. this.pos = this.start;
  6072. },
  6073. moveStart: function ChunkedStream_moveStart() {
  6074. this.start = this.pos;
  6075. },
  6076. makeSubStream: function ChunkedStream_makeSubStream(start, length, dict) {
  6077. this.ensureRange(start, start + length);
  6078. function ChunkedStreamSubstream() {}
  6079. ChunkedStreamSubstream.prototype = Object.create(this);
  6080. ChunkedStreamSubstream.prototype.getMissingChunks = function() {
  6081. var chunkSize = this.chunkSize;
  6082. var beginChunk = Math.floor(this.start / chunkSize);
  6083. var endChunk = Math.floor((this.end - 1) / chunkSize) + 1;
  6084. var missingChunks = [];
  6085. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  6086. if (!(chunk in this.loadedChunks)) {
  6087. missingChunks.push(chunk);
  6088. }
  6089. }
  6090. return missingChunks;
  6091. };
  6092. var subStream = new ChunkedStreamSubstream();
  6093. subStream.pos = subStream.start = start;
  6094. subStream.end = start + length || this.end;
  6095. subStream.dict = dict;
  6096. return subStream;
  6097. },
  6098. isStream: true
  6099. };
  6100. return ChunkedStream;
  6101. })();
  6102. var ChunkedStreamManager = (function ChunkedStreamManagerClosure() {
  6103. function ChunkedStreamManager(length, chunkSize, url, args) {
  6104. this.stream = new ChunkedStream(length, chunkSize, this);
  6105. this.length = length;
  6106. this.chunkSize = chunkSize;
  6107. this.url = url;
  6108. this.disableAutoFetch = args.disableAutoFetch;
  6109. var msgHandler = this.msgHandler = args.msgHandler;
  6110. if (args.chunkedViewerLoading) {
  6111. msgHandler.on('OnDataRange', this.onReceiveData.bind(this));
  6112. msgHandler.on('OnDataProgress', this.onProgress.bind(this));
  6113. this.sendRequest = function ChunkedStreamManager_sendRequest(begin, end) {
  6114. msgHandler.send('RequestDataRange', { begin: begin, end: end });
  6115. };
  6116. } else {
  6117. var getXhr = function getXhr() {
  6118. return new XMLHttpRequest();
  6119. };
  6120. this.networkManager = new NetworkManager(this.url, {
  6121. getXhr: getXhr,
  6122. httpHeaders: args.httpHeaders,
  6123. withCredentials: args.withCredentials
  6124. });
  6125. this.sendRequest = function ChunkedStreamManager_sendRequest(begin, end) {
  6126. this.networkManager.requestRange(begin, end, {
  6127. onDone: this.onReceiveData.bind(this),
  6128. onProgress: this.onProgress.bind(this)
  6129. });
  6130. };
  6131. }
  6132. this.currRequestId = 0;
  6133. this.chunksNeededByRequest = {};
  6134. this.requestsByChunk = {};
  6135. this.callbacksByRequest = {};
  6136. this._loadedStreamCapability = createPromiseCapability();
  6137. if (args.initialData) {
  6138. this.setInitialData(args.initialData);
  6139. }
  6140. }
  6141. ChunkedStreamManager.prototype = {
  6142. setInitialData: function ChunkedStreamManager_setInitialData(data) {
  6143. this.stream.onReceiveInitialData(data);
  6144. if (this.stream.allChunksLoaded()) {
  6145. this._loadedStreamCapability.resolve(this.stream);
  6146. } else if (this.msgHandler) {
  6147. this.msgHandler.send('DocProgress', {
  6148. loaded: data.length,
  6149. total: this.length
  6150. });
  6151. }
  6152. },
  6153. onLoadedStream: function ChunkedStreamManager_getLoadedStream() {
  6154. return this._loadedStreamCapability.promise;
  6155. },
  6156. // Get all the chunks that are not yet loaded and groups them into
  6157. // contiguous ranges to load in as few requests as possible
  6158. requestAllChunks: function ChunkedStreamManager_requestAllChunks() {
  6159. var missingChunks = this.stream.getMissingChunks();
  6160. this.requestChunks(missingChunks);
  6161. return this._loadedStreamCapability.promise;
  6162. },
  6163. requestChunks: function ChunkedStreamManager_requestChunks(chunks,
  6164. callback) {
  6165. var requestId = this.currRequestId++;
  6166. var chunksNeeded;
  6167. var i, ii;
  6168. this.chunksNeededByRequest[requestId] = chunksNeeded = {};
  6169. for (i = 0, ii = chunks.length; i < ii; i++) {
  6170. if (!this.stream.hasChunk(chunks[i])) {
  6171. chunksNeeded[chunks[i]] = true;
  6172. }
  6173. }
  6174. if (isEmptyObj(chunksNeeded)) {
  6175. if (callback) {
  6176. callback();
  6177. }
  6178. return;
  6179. }
  6180. this.callbacksByRequest[requestId] = callback;
  6181. var chunksToRequest = [];
  6182. for (var chunk in chunksNeeded) {
  6183. chunk = chunk | 0;
  6184. if (!(chunk in this.requestsByChunk)) {
  6185. this.requestsByChunk[chunk] = [];
  6186. chunksToRequest.push(chunk);
  6187. }
  6188. this.requestsByChunk[chunk].push(requestId);
  6189. }
  6190. if (!chunksToRequest.length) {
  6191. return;
  6192. }
  6193. var groupedChunksToRequest = this.groupChunks(chunksToRequest);
  6194. for (i = 0; i < groupedChunksToRequest.length; ++i) {
  6195. var groupedChunk = groupedChunksToRequest[i];
  6196. var begin = groupedChunk.beginChunk * this.chunkSize;
  6197. var end = Math.min(groupedChunk.endChunk * this.chunkSize, this.length);
  6198. this.sendRequest(begin, end);
  6199. }
  6200. },
  6201. getStream: function ChunkedStreamManager_getStream() {
  6202. return this.stream;
  6203. },
  6204. // Loads any chunks in the requested range that are not yet loaded
  6205. requestRange: function ChunkedStreamManager_requestRange(
  6206. begin, end, callback) {
  6207. end = Math.min(end, this.length);
  6208. var beginChunk = this.getBeginChunk(begin);
  6209. var endChunk = this.getEndChunk(end);
  6210. var chunks = [];
  6211. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  6212. chunks.push(chunk);
  6213. }
  6214. this.requestChunks(chunks, callback);
  6215. },
  6216. requestRanges: function ChunkedStreamManager_requestRanges(ranges,
  6217. callback) {
  6218. ranges = ranges || [];
  6219. var chunksToRequest = [];
  6220. for (var i = 0; i < ranges.length; i++) {
  6221. var beginChunk = this.getBeginChunk(ranges[i].begin);
  6222. var endChunk = this.getEndChunk(ranges[i].end);
  6223. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  6224. if (chunksToRequest.indexOf(chunk) < 0) {
  6225. chunksToRequest.push(chunk);
  6226. }
  6227. }
  6228. }
  6229. chunksToRequest.sort(function(a, b) { return a - b; });
  6230. this.requestChunks(chunksToRequest, callback);
  6231. },
  6232. // Groups a sorted array of chunks into as few continguous larger
  6233. // chunks as possible
  6234. groupChunks: function ChunkedStreamManager_groupChunks(chunks) {
  6235. var groupedChunks = [];
  6236. var beginChunk = -1;
  6237. var prevChunk = -1;
  6238. for (var i = 0; i < chunks.length; ++i) {
  6239. var chunk = chunks[i];
  6240. if (beginChunk < 0) {
  6241. beginChunk = chunk;
  6242. }
  6243. if (prevChunk >= 0 && prevChunk + 1 !== chunk) {
  6244. groupedChunks.push({ beginChunk: beginChunk,
  6245. endChunk: prevChunk + 1 });
  6246. beginChunk = chunk;
  6247. }
  6248. if (i + 1 === chunks.length) {
  6249. groupedChunks.push({ beginChunk: beginChunk,
  6250. endChunk: chunk + 1 });
  6251. }
  6252. prevChunk = chunk;
  6253. }
  6254. return groupedChunks;
  6255. },
  6256. onProgress: function ChunkedStreamManager_onProgress(args) {
  6257. var bytesLoaded = (this.stream.numChunksLoaded * this.chunkSize +
  6258. args.loaded);
  6259. this.msgHandler.send('DocProgress', {
  6260. loaded: bytesLoaded,
  6261. total: this.length
  6262. });
  6263. },
  6264. onReceiveData: function ChunkedStreamManager_onReceiveData(args) {
  6265. var chunk = args.chunk;
  6266. var begin = args.begin;
  6267. var end = begin + chunk.byteLength;
  6268. var beginChunk = this.getBeginChunk(begin);
  6269. var endChunk = this.getEndChunk(end);
  6270. this.stream.onReceiveData(begin, chunk);
  6271. if (this.stream.allChunksLoaded()) {
  6272. this._loadedStreamCapability.resolve(this.stream);
  6273. }
  6274. var loadedRequests = [];
  6275. var i, requestId;
  6276. for (chunk = beginChunk; chunk < endChunk; ++chunk) {
  6277. // The server might return more chunks than requested
  6278. var requestIds = this.requestsByChunk[chunk] || [];
  6279. delete this.requestsByChunk[chunk];
  6280. for (i = 0; i < requestIds.length; ++i) {
  6281. requestId = requestIds[i];
  6282. var chunksNeeded = this.chunksNeededByRequest[requestId];
  6283. if (chunk in chunksNeeded) {
  6284. delete chunksNeeded[chunk];
  6285. }
  6286. if (!isEmptyObj(chunksNeeded)) {
  6287. continue;
  6288. }
  6289. loadedRequests.push(requestId);
  6290. }
  6291. }
  6292. // If there are no pending requests, automatically fetch the next
  6293. // unfetched chunk of the PDF
  6294. if (!this.disableAutoFetch && isEmptyObj(this.requestsByChunk)) {
  6295. var nextEmptyChunk;
  6296. if (this.stream.numChunksLoaded === 1) {
  6297. // This is a special optimization so that after fetching the first
  6298. // chunk, rather than fetching the second chunk, we fetch the last
  6299. // chunk.
  6300. var lastChunk = this.stream.numChunks - 1;
  6301. if (!this.stream.hasChunk(lastChunk)) {
  6302. nextEmptyChunk = lastChunk;
  6303. }
  6304. } else {
  6305. nextEmptyChunk = this.stream.nextEmptyChunk(endChunk);
  6306. }
  6307. if (isInt(nextEmptyChunk)) {
  6308. this.requestChunks([nextEmptyChunk]);
  6309. }
  6310. }
  6311. for (i = 0; i < loadedRequests.length; ++i) {
  6312. requestId = loadedRequests[i];
  6313. var callback = this.callbacksByRequest[requestId];
  6314. delete this.callbacksByRequest[requestId];
  6315. if (callback) {
  6316. callback();
  6317. }
  6318. }
  6319. this.msgHandler.send('DocProgress', {
  6320. loaded: this.stream.numChunksLoaded * this.chunkSize,
  6321. total: this.length
  6322. });
  6323. },
  6324. onError: function ChunkedStreamManager_onError(err) {
  6325. this._loadedStreamCapability.reject(err);
  6326. },
  6327. getBeginChunk: function ChunkedStreamManager_getBeginChunk(begin) {
  6328. var chunk = Math.floor(begin / this.chunkSize);
  6329. return chunk;
  6330. },
  6331. getEndChunk: function ChunkedStreamManager_getEndChunk(end) {
  6332. if (end % this.chunkSize === 0) {
  6333. return end / this.chunkSize;
  6334. }
  6335. // 0 -> 0
  6336. // 1 -> 1
  6337. // 99 -> 1
  6338. // 100 -> 1
  6339. // 101 -> 2
  6340. var chunk = Math.floor((end - 1) / this.chunkSize) + 1;
  6341. return chunk;
  6342. }
  6343. };
  6344. return ChunkedStreamManager;
  6345. })();
  6346. // The maximum number of bytes fetched per range request
  6347. var RANGE_CHUNK_SIZE = 65536;
  6348. // TODO(mack): Make use of PDFJS.Util.inherit() when it becomes available
  6349. var BasePdfManager = (function BasePdfManagerClosure() {
  6350. function BasePdfManager() {
  6351. throw new Error('Cannot initialize BaseManagerManager');
  6352. }
  6353. BasePdfManager.prototype = {
  6354. onLoadedStream: function BasePdfManager_onLoadedStream() {
  6355. throw new NotImplementedException();
  6356. },
  6357. ensureDoc: function BasePdfManager_ensureDoc(prop, args) {
  6358. return this.ensure(this.pdfDocument, prop, args);
  6359. },
  6360. ensureXRef: function BasePdfManager_ensureXRef(prop, args) {
  6361. return this.ensure(this.pdfDocument.xref, prop, args);
  6362. },
  6363. ensureCatalog: function BasePdfManager_ensureCatalog(prop, args) {
  6364. return this.ensure(this.pdfDocument.catalog, prop, args);
  6365. },
  6366. getPage: function BasePdfManager_pagePage(pageIndex) {
  6367. return this.pdfDocument.getPage(pageIndex);
  6368. },
  6369. cleanup: function BasePdfManager_cleanup() {
  6370. return this.pdfDocument.cleanup();
  6371. },
  6372. ensure: function BasePdfManager_ensure(obj, prop, args) {
  6373. return new NotImplementedException();
  6374. },
  6375. requestRange: function BasePdfManager_ensure(begin, end) {
  6376. return new NotImplementedException();
  6377. },
  6378. requestLoadedStream: function BasePdfManager_requestLoadedStream() {
  6379. return new NotImplementedException();
  6380. },
  6381. updatePassword: function BasePdfManager_updatePassword(password) {
  6382. this.pdfDocument.xref.password = this.password = password;
  6383. if (this._passwordChangedCapability) {
  6384. this._passwordChangedCapability.resolve();
  6385. }
  6386. },
  6387. passwordChanged: function BasePdfManager_passwordChanged() {
  6388. this._passwordChangedCapability = createPromiseCapability();
  6389. return this._passwordChangedCapability.promise;
  6390. },
  6391. terminate: function BasePdfManager_terminate() {
  6392. return new NotImplementedException();
  6393. }
  6394. };
  6395. return BasePdfManager;
  6396. })();
  6397. var LocalPdfManager = (function LocalPdfManagerClosure() {
  6398. function LocalPdfManager(data, password) {
  6399. var stream = new Stream(data);
  6400. this.pdfDocument = new PDFDocument(this, stream, password);
  6401. this._loadedStreamCapability = createPromiseCapability();
  6402. this._loadedStreamCapability.resolve(stream);
  6403. }
  6404. LocalPdfManager.prototype = Object.create(BasePdfManager.prototype);
  6405. LocalPdfManager.prototype.constructor = LocalPdfManager;
  6406. LocalPdfManager.prototype.ensure =
  6407. function LocalPdfManager_ensure(obj, prop, args) {
  6408. return new Promise(function (resolve, reject) {
  6409. try {
  6410. var value = obj[prop];
  6411. var result;
  6412. if (typeof value === 'function') {
  6413. result = value.apply(obj, args);
  6414. } else {
  6415. result = value;
  6416. }
  6417. resolve(result);
  6418. } catch (e) {
  6419. reject(e);
  6420. }
  6421. });
  6422. };
  6423. LocalPdfManager.prototype.requestRange =
  6424. function LocalPdfManager_requestRange(begin, end) {
  6425. return Promise.resolve();
  6426. };
  6427. LocalPdfManager.prototype.requestLoadedStream =
  6428. function LocalPdfManager_requestLoadedStream() {
  6429. };
  6430. LocalPdfManager.prototype.onLoadedStream =
  6431. function LocalPdfManager_getLoadedStream() {
  6432. return this._loadedStreamCapability.promise;
  6433. };
  6434. LocalPdfManager.prototype.terminate =
  6435. function LocalPdfManager_terminate() {
  6436. return;
  6437. };
  6438. return LocalPdfManager;
  6439. })();
  6440. var NetworkPdfManager = (function NetworkPdfManagerClosure() {
  6441. function NetworkPdfManager(args, msgHandler) {
  6442. this.msgHandler = msgHandler;
  6443. var params = {
  6444. msgHandler: msgHandler,
  6445. httpHeaders: args.httpHeaders,
  6446. withCredentials: args.withCredentials,
  6447. chunkedViewerLoading: args.chunkedViewerLoading,
  6448. disableAutoFetch: args.disableAutoFetch,
  6449. initialData: args.initialData
  6450. };
  6451. this.streamManager = new ChunkedStreamManager(args.length, RANGE_CHUNK_SIZE,
  6452. args.url, params);
  6453. this.pdfDocument = new PDFDocument(this, this.streamManager.getStream(),
  6454. args.password);
  6455. }
  6456. NetworkPdfManager.prototype = Object.create(BasePdfManager.prototype);
  6457. NetworkPdfManager.prototype.constructor = NetworkPdfManager;
  6458. NetworkPdfManager.prototype.ensure =
  6459. function NetworkPdfManager_ensure(obj, prop, args) {
  6460. var pdfManager = this;
  6461. return new Promise(function (resolve, reject) {
  6462. function ensureHelper() {
  6463. try {
  6464. var result;
  6465. var value = obj[prop];
  6466. if (typeof value === 'function') {
  6467. result = value.apply(obj, args);
  6468. } else {
  6469. result = value;
  6470. }
  6471. resolve(result);
  6472. } catch(e) {
  6473. if (!(e instanceof MissingDataException)) {
  6474. reject(e);
  6475. return;
  6476. }
  6477. pdfManager.streamManager.requestRange(e.begin, e.end, ensureHelper);
  6478. }
  6479. }
  6480. ensureHelper();
  6481. });
  6482. };
  6483. NetworkPdfManager.prototype.requestRange =
  6484. function NetworkPdfManager_requestRange(begin, end) {
  6485. return new Promise(function (resolve) {
  6486. this.streamManager.requestRange(begin, end, function() {
  6487. resolve();
  6488. });
  6489. }.bind(this));
  6490. };
  6491. NetworkPdfManager.prototype.requestLoadedStream =
  6492. function NetworkPdfManager_requestLoadedStream() {
  6493. this.streamManager.requestAllChunks();
  6494. };
  6495. NetworkPdfManager.prototype.onLoadedStream =
  6496. function NetworkPdfManager_getLoadedStream() {
  6497. return this.streamManager.onLoadedStream();
  6498. };
  6499. NetworkPdfManager.prototype.terminate =
  6500. function NetworkPdfManager_terminate() {
  6501. this.streamManager.networkManager.abortAllRequests();
  6502. };
  6503. return NetworkPdfManager;
  6504. })();
  6505. var Page = (function PageClosure() {
  6506. var LETTER_SIZE_MEDIABOX = [0, 0, 612, 792];
  6507. function Page(pdfManager, xref, pageIndex, pageDict, ref, fontCache) {
  6508. this.pdfManager = pdfManager;
  6509. this.pageIndex = pageIndex;
  6510. this.pageDict = pageDict;
  6511. this.xref = xref;
  6512. this.ref = ref;
  6513. this.fontCache = fontCache;
  6514. this.idCounters = {
  6515. obj: 0
  6516. };
  6517. this.resourcesPromise = null;
  6518. }
  6519. Page.prototype = {
  6520. getPageProp: function Page_getPageProp(key) {
  6521. return this.pageDict.get(key);
  6522. },
  6523. getInheritedPageProp: function Page_inheritPageProp(key) {
  6524. var dict = this.pageDict;
  6525. var value = dict.get(key);
  6526. while (value === undefined) {
  6527. dict = dict.get('Parent');
  6528. if (!dict) {
  6529. break;
  6530. }
  6531. value = dict.get(key);
  6532. }
  6533. return value;
  6534. },
  6535. get content() {
  6536. return this.getPageProp('Contents');
  6537. },
  6538. get resources() {
  6539. var value = this.getInheritedPageProp('Resources');
  6540. // For robustness: The spec states that a \Resources entry has to be
  6541. // present, but can be empty. Some document omit it still. In this case
  6542. // return an empty dictionary:
  6543. if (value === undefined) {
  6544. value = Dict.empty;
  6545. }
  6546. return shadow(this, 'resources', value);
  6547. },
  6548. get mediaBox() {
  6549. var obj = this.getInheritedPageProp('MediaBox');
  6550. // Reset invalid media box to letter size.
  6551. if (!isArray(obj) || obj.length !== 4) {
  6552. obj = LETTER_SIZE_MEDIABOX;
  6553. }
  6554. return shadow(this, 'mediaBox', obj);
  6555. },
  6556. get view() {
  6557. var mediaBox = this.mediaBox;
  6558. var cropBox = this.getInheritedPageProp('CropBox');
  6559. if (!isArray(cropBox) || cropBox.length !== 4) {
  6560. return shadow(this, 'view', mediaBox);
  6561. }
  6562. // From the spec, 6th ed., p.963:
  6563. // "The crop, bleed, trim, and art boxes should not ordinarily
  6564. // extend beyond the boundaries of the media box. If they do, they are
  6565. // effectively reduced to their intersection with the media box."
  6566. cropBox = Util.intersect(cropBox, mediaBox);
  6567. if (!cropBox) {
  6568. return shadow(this, 'view', mediaBox);
  6569. }
  6570. return shadow(this, 'view', cropBox);
  6571. },
  6572. get annotationRefs() {
  6573. return shadow(this, 'annotationRefs',
  6574. this.getInheritedPageProp('Annots'));
  6575. },
  6576. get rotate() {
  6577. var rotate = this.getInheritedPageProp('Rotate') || 0;
  6578. // Normalize rotation so it's a multiple of 90 and between 0 and 270
  6579. if (rotate % 90 !== 0) {
  6580. rotate = 0;
  6581. } else if (rotate >= 360) {
  6582. rotate = rotate % 360;
  6583. } else if (rotate < 0) {
  6584. // The spec doesn't cover negatives, assume its counterclockwise
  6585. // rotation. The following is the other implementation of modulo.
  6586. rotate = ((rotate % 360) + 360) % 360;
  6587. }
  6588. return shadow(this, 'rotate', rotate);
  6589. },
  6590. getContentStream: function Page_getContentStream() {
  6591. var content = this.content;
  6592. var stream;
  6593. if (isArray(content)) {
  6594. // fetching items
  6595. var xref = this.xref;
  6596. var i, n = content.length;
  6597. var streams = [];
  6598. for (i = 0; i < n; ++i) {
  6599. streams.push(xref.fetchIfRef(content[i]));
  6600. }
  6601. stream = new StreamsSequenceStream(streams);
  6602. } else if (isStream(content)) {
  6603. stream = content;
  6604. } else {
  6605. // replacing non-existent page content with empty one
  6606. stream = new NullStream();
  6607. }
  6608. return stream;
  6609. },
  6610. loadResources: function Page_loadResources(keys) {
  6611. if (!this.resourcesPromise) {
  6612. // TODO: add async getInheritedPageProp and remove this.
  6613. this.resourcesPromise = this.pdfManager.ensure(this, 'resources');
  6614. }
  6615. return this.resourcesPromise.then(function resourceSuccess() {
  6616. var objectLoader = new ObjectLoader(this.resources.map,
  6617. keys,
  6618. this.xref);
  6619. return objectLoader.load();
  6620. }.bind(this));
  6621. },
  6622. getOperatorList: function Page_getOperatorList(handler, intent) {
  6623. var self = this;
  6624. var pdfManager = this.pdfManager;
  6625. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
  6626. []);
  6627. var resourcesPromise = this.loadResources([
  6628. 'ExtGState',
  6629. 'ColorSpace',
  6630. 'Pattern',
  6631. 'Shading',
  6632. 'XObject',
  6633. 'Font'
  6634. // ProcSet
  6635. // Properties
  6636. ]);
  6637. var partialEvaluator = new PartialEvaluator(pdfManager, this.xref,
  6638. handler, this.pageIndex,
  6639. 'p' + this.pageIndex + '_',
  6640. this.idCounters,
  6641. this.fontCache);
  6642. var dataPromises = Promise.all([contentStreamPromise, resourcesPromise]);
  6643. var pageListPromise = dataPromises.then(function(data) {
  6644. var contentStream = data[0];
  6645. var opList = new OperatorList(intent, handler, self.pageIndex);
  6646. handler.send('StartRenderPage', {
  6647. transparency: partialEvaluator.hasBlendModes(self.resources),
  6648. pageIndex: self.pageIndex,
  6649. intent: intent
  6650. });
  6651. return partialEvaluator.getOperatorList(contentStream, self.resources,
  6652. opList).then(function () {
  6653. return opList;
  6654. });
  6655. });
  6656. var annotationsPromise = pdfManager.ensure(this, 'annotations');
  6657. return Promise.all([pageListPromise, annotationsPromise]).then(
  6658. function(datas) {
  6659. var pageOpList = datas[0];
  6660. var annotations = datas[1];
  6661. if (annotations.length === 0) {
  6662. pageOpList.flush(true);
  6663. return pageOpList;
  6664. }
  6665. var annotationsReadyPromise = Annotation.appendToOperatorList(
  6666. annotations, pageOpList, pdfManager, partialEvaluator, intent);
  6667. return annotationsReadyPromise.then(function () {
  6668. pageOpList.flush(true);
  6669. return pageOpList;
  6670. });
  6671. });
  6672. },
  6673. extractTextContent: function Page_extractTextContent() {
  6674. var handler = {
  6675. on: function nullHandlerOn() {},
  6676. send: function nullHandlerSend() {}
  6677. };
  6678. var self = this;
  6679. var pdfManager = this.pdfManager;
  6680. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
  6681. []);
  6682. var resourcesPromise = this.loadResources([
  6683. 'ExtGState',
  6684. 'XObject',
  6685. 'Font'
  6686. ]);
  6687. var dataPromises = Promise.all([contentStreamPromise,
  6688. resourcesPromise]);
  6689. return dataPromises.then(function(data) {
  6690. var contentStream = data[0];
  6691. var partialEvaluator = new PartialEvaluator(pdfManager, self.xref,
  6692. handler, self.pageIndex,
  6693. 'p' + self.pageIndex + '_',
  6694. self.idCounters,
  6695. self.fontCache);
  6696. return partialEvaluator.getTextContent(contentStream,
  6697. self.resources);
  6698. });
  6699. },
  6700. getAnnotationsData: function Page_getAnnotationsData() {
  6701. var annotations = this.annotations;
  6702. var annotationsData = [];
  6703. for (var i = 0, n = annotations.length; i < n; ++i) {
  6704. annotationsData.push(annotations[i].getData());
  6705. }
  6706. return annotationsData;
  6707. },
  6708. get annotations() {
  6709. var annotations = [];
  6710. var annotationRefs = (this.annotationRefs || []);
  6711. for (var i = 0, n = annotationRefs.length; i < n; ++i) {
  6712. var annotationRef = annotationRefs[i];
  6713. var annotation = Annotation.fromRef(this.xref, annotationRef);
  6714. if (annotation) {
  6715. annotations.push(annotation);
  6716. }
  6717. }
  6718. return shadow(this, 'annotations', annotations);
  6719. }
  6720. };
  6721. return Page;
  6722. })();
  6723. /**
  6724. * The `PDFDocument` holds all the data of the PDF file. Compared to the
  6725. * `PDFDoc`, this one doesn't have any job management code.
  6726. * Right now there exists one PDFDocument on the main thread + one object
  6727. * for each worker. If there is no worker support enabled, there are two
  6728. * `PDFDocument` objects on the main thread created.
  6729. */
  6730. var PDFDocument = (function PDFDocumentClosure() {
  6731. function PDFDocument(pdfManager, arg, password) {
  6732. if (isStream(arg)) {
  6733. init.call(this, pdfManager, arg, password);
  6734. } else if (isArrayBuffer(arg)) {
  6735. init.call(this, pdfManager, new Stream(arg), password);
  6736. } else {
  6737. error('PDFDocument: Unknown argument type');
  6738. }
  6739. }
  6740. function init(pdfManager, stream, password) {
  6741. assert(stream.length > 0, 'stream must have data');
  6742. this.pdfManager = pdfManager;
  6743. this.stream = stream;
  6744. var xref = new XRef(this.stream, password, pdfManager);
  6745. this.xref = xref;
  6746. }
  6747. function find(stream, needle, limit, backwards) {
  6748. var pos = stream.pos;
  6749. var end = stream.end;
  6750. var strBuf = [];
  6751. if (pos + limit > end) {
  6752. limit = end - pos;
  6753. }
  6754. for (var n = 0; n < limit; ++n) {
  6755. strBuf.push(String.fromCharCode(stream.getByte()));
  6756. }
  6757. var str = strBuf.join('');
  6758. stream.pos = pos;
  6759. var index = backwards ? str.lastIndexOf(needle) : str.indexOf(needle);
  6760. if (index === -1) {
  6761. return false; /* not found */
  6762. }
  6763. stream.pos += index;
  6764. return true; /* found */
  6765. }
  6766. var DocumentInfoValidators = {
  6767. get entries() {
  6768. // Lazily build this since all the validation functions below are not
  6769. // defined until after this file loads.
  6770. return shadow(this, 'entries', {
  6771. Title: isString,
  6772. Author: isString,
  6773. Subject: isString,
  6774. Keywords: isString,
  6775. Creator: isString,
  6776. Producer: isString,
  6777. CreationDate: isString,
  6778. ModDate: isString,
  6779. Trapped: isName
  6780. });
  6781. }
  6782. };
  6783. PDFDocument.prototype = {
  6784. parse: function PDFDocument_parse(recoveryMode) {
  6785. this.setup(recoveryMode);
  6786. try {
  6787. // checking if AcroForm is present
  6788. this.acroForm = this.catalog.catDict.get('AcroForm');
  6789. if (this.acroForm) {
  6790. this.xfa = this.acroForm.get('XFA');
  6791. var fields = this.acroForm.get('Fields');
  6792. if ((!fields || !isArray(fields) || fields.length === 0) &&
  6793. !this.xfa) {
  6794. // no fields and no XFA -- not a form (?)
  6795. this.acroForm = null;
  6796. }
  6797. }
  6798. } catch (ex) {
  6799. info('Something wrong with AcroForm entry');
  6800. this.acroForm = null;
  6801. }
  6802. },
  6803. get linearization() {
  6804. var linearization = null;
  6805. if (this.stream.length) {
  6806. try {
  6807. linearization = Linearization.create(this.stream);
  6808. } catch (err) {
  6809. if (err instanceof MissingDataException) {
  6810. throw err;
  6811. }
  6812. info(err);
  6813. }
  6814. }
  6815. // shadow the prototype getter with a data property
  6816. return shadow(this, 'linearization', linearization);
  6817. },
  6818. get startXRef() {
  6819. var stream = this.stream;
  6820. var startXRef = 0;
  6821. var linearization = this.linearization;
  6822. if (linearization) {
  6823. // Find end of first obj.
  6824. stream.reset();
  6825. if (find(stream, 'endobj', 1024)) {
  6826. startXRef = stream.pos + 6;
  6827. }
  6828. } else {
  6829. // Find startxref by jumping backward from the end of the file.
  6830. var step = 1024;
  6831. var found = false, pos = stream.end;
  6832. while (!found && pos > 0) {
  6833. pos -= step - 'startxref'.length;
  6834. if (pos < 0) {
  6835. pos = 0;
  6836. }
  6837. stream.pos = pos;
  6838. found = find(stream, 'startxref', step, true);
  6839. }
  6840. if (found) {
  6841. stream.skip(9);
  6842. var ch;
  6843. do {
  6844. ch = stream.getByte();
  6845. } while (Lexer.isSpace(ch));
  6846. var str = '';
  6847. while (ch >= 0x20 && ch <= 0x39) { // < '9'
  6848. str += String.fromCharCode(ch);
  6849. ch = stream.getByte();
  6850. }
  6851. startXRef = parseInt(str, 10);
  6852. if (isNaN(startXRef)) {
  6853. startXRef = 0;
  6854. }
  6855. }
  6856. }
  6857. // shadow the prototype getter with a data property
  6858. return shadow(this, 'startXRef', startXRef);
  6859. },
  6860. get mainXRefEntriesOffset() {
  6861. var mainXRefEntriesOffset = 0;
  6862. var linearization = this.linearization;
  6863. if (linearization) {
  6864. mainXRefEntriesOffset = linearization.mainXRefEntriesOffset;
  6865. }
  6866. // shadow the prototype getter with a data property
  6867. return shadow(this, 'mainXRefEntriesOffset', mainXRefEntriesOffset);
  6868. },
  6869. // Find the header, remove leading garbage and setup the stream
  6870. // starting from the header.
  6871. checkHeader: function PDFDocument_checkHeader() {
  6872. var stream = this.stream;
  6873. stream.reset();
  6874. if (find(stream, '%PDF-', 1024)) {
  6875. // Found the header, trim off any garbage before it.
  6876. stream.moveStart();
  6877. // Reading file format version
  6878. var MAX_VERSION_LENGTH = 12;
  6879. var version = '', ch;
  6880. while ((ch = stream.getByte()) > 0x20) { // SPACE
  6881. if (version.length >= MAX_VERSION_LENGTH) {
  6882. break;
  6883. }
  6884. version += String.fromCharCode(ch);
  6885. }
  6886. // removing "%PDF-"-prefix
  6887. this.pdfFormatVersion = version.substring(5);
  6888. return;
  6889. }
  6890. // May not be a PDF file, continue anyway.
  6891. },
  6892. parseStartXRef: function PDFDocument_parseStartXRef() {
  6893. var startXRef = this.startXRef;
  6894. this.xref.setStartXRef(startXRef);
  6895. },
  6896. setup: function PDFDocument_setup(recoveryMode) {
  6897. this.xref.parse(recoveryMode);
  6898. this.catalog = new Catalog(this.pdfManager, this.xref);
  6899. },
  6900. get numPages() {
  6901. var linearization = this.linearization;
  6902. var num = linearization ? linearization.numPages : this.catalog.numPages;
  6903. // shadow the prototype getter
  6904. return shadow(this, 'numPages', num);
  6905. },
  6906. get documentInfo() {
  6907. var docInfo = {
  6908. PDFFormatVersion: this.pdfFormatVersion,
  6909. IsAcroFormPresent: !!this.acroForm,
  6910. IsXFAPresent: !!this.xfa
  6911. };
  6912. var infoDict;
  6913. try {
  6914. infoDict = this.xref.trailer.get('Info');
  6915. } catch (err) {
  6916. info('The document information dictionary is invalid.');
  6917. }
  6918. if (infoDict) {
  6919. var validEntries = DocumentInfoValidators.entries;
  6920. // Only fill the document info with valid entries from the spec.
  6921. for (var key in validEntries) {
  6922. if (infoDict.has(key)) {
  6923. var value = infoDict.get(key);
  6924. // Make sure the value conforms to the spec.
  6925. if (validEntries[key](value)) {
  6926. docInfo[key] = (typeof value !== 'string' ?
  6927. value : stringToPDFString(value));
  6928. } else {
  6929. info('Bad value in document info for "' + key + '"');
  6930. }
  6931. }
  6932. }
  6933. }
  6934. return shadow(this, 'documentInfo', docInfo);
  6935. },
  6936. get fingerprint() {
  6937. var xref = this.xref, hash, fileID = '';
  6938. if (xref.trailer.has('ID')) {
  6939. hash = stringToBytes(xref.trailer.get('ID')[0]);
  6940. } else {
  6941. hash = calculateMD5(this.stream.bytes.subarray(0, 100), 0, 100);
  6942. }
  6943. for (var i = 0, n = hash.length; i < n; i++) {
  6944. fileID += hash[i].toString(16);
  6945. }
  6946. return shadow(this, 'fingerprint', fileID);
  6947. },
  6948. getPage: function PDFDocument_getPage(pageIndex) {
  6949. return this.catalog.getPage(pageIndex);
  6950. },
  6951. cleanup: function PDFDocument_cleanup() {
  6952. return this.catalog.cleanup();
  6953. }
  6954. };
  6955. return PDFDocument;
  6956. })();
  6957. var Name = (function NameClosure() {
  6958. function Name(name) {
  6959. this.name = name;
  6960. }
  6961. Name.prototype = {};
  6962. var nameCache = {};
  6963. Name.get = function Name_get(name) {
  6964. var nameValue = nameCache[name];
  6965. return (nameValue ? nameValue : (nameCache[name] = new Name(name)));
  6966. };
  6967. return Name;
  6968. })();
  6969. var Cmd = (function CmdClosure() {
  6970. function Cmd(cmd) {
  6971. this.cmd = cmd;
  6972. }
  6973. Cmd.prototype = {};
  6974. var cmdCache = {};
  6975. Cmd.get = function Cmd_get(cmd) {
  6976. var cmdValue = cmdCache[cmd];
  6977. return (cmdValue ? cmdValue : (cmdCache[cmd] = new Cmd(cmd)));
  6978. };
  6979. return Cmd;
  6980. })();
  6981. var Dict = (function DictClosure() {
  6982. var nonSerializable = function nonSerializableClosure() {
  6983. return nonSerializable; // creating closure on some variable
  6984. };
  6985. var GETALL_DICTIONARY_TYPES_WHITELIST = {
  6986. 'Background': true,
  6987. 'ExtGState': true,
  6988. 'Halftone': true,
  6989. 'Layout': true,
  6990. 'Mask': true,
  6991. 'Pagination': true,
  6992. 'Printing': true
  6993. };
  6994. function isRecursionAllowedFor(dict) {
  6995. if (!isName(dict.Type)) {
  6996. return true;
  6997. }
  6998. var dictType = dict.Type.name;
  6999. return GETALL_DICTIONARY_TYPES_WHITELIST[dictType] === true;
  7000. }
  7001. // xref is optional
  7002. function Dict(xref) {
  7003. // Map should only be used internally, use functions below to access.
  7004. this.map = Object.create(null);
  7005. this.xref = xref;
  7006. this.objId = null;
  7007. this.__nonSerializable__ = nonSerializable; // disable cloning of the Dict
  7008. }
  7009. Dict.prototype = {
  7010. assignXref: function Dict_assignXref(newXref) {
  7011. this.xref = newXref;
  7012. },
  7013. // automatically dereferences Ref objects
  7014. get: function Dict_get(key1, key2, key3) {
  7015. var value;
  7016. var xref = this.xref;
  7017. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
  7018. typeof key2 === 'undefined') {
  7019. return xref ? xref.fetchIfRef(value) : value;
  7020. }
  7021. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
  7022. typeof key3 === 'undefined') {
  7023. return xref ? xref.fetchIfRef(value) : value;
  7024. }
  7025. value = this.map[key3] || null;
  7026. return xref ? xref.fetchIfRef(value) : value;
  7027. },
  7028. // Same as get(), but returns a promise and uses fetchIfRefAsync().
  7029. getAsync: function Dict_getAsync(key1, key2, key3) {
  7030. var value;
  7031. var xref = this.xref;
  7032. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
  7033. typeof key2 === 'undefined') {
  7034. if (xref) {
  7035. return xref.fetchIfRefAsync(value);
  7036. }
  7037. return Promise.resolve(value);
  7038. }
  7039. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
  7040. typeof key3 === 'undefined') {
  7041. if (xref) {
  7042. return xref.fetchIfRefAsync(value);
  7043. }
  7044. return Promise.resolve(value);
  7045. }
  7046. value = this.map[key3] || null;
  7047. if (xref) {
  7048. return xref.fetchIfRefAsync(value);
  7049. }
  7050. return Promise.resolve(value);
  7051. },
  7052. // no dereferencing
  7053. getRaw: function Dict_getRaw(key) {
  7054. return this.map[key];
  7055. },
  7056. // creates new map and dereferences all Refs
  7057. getAll: function Dict_getAll() {
  7058. var all = Object.create(null);
  7059. var queue = null;
  7060. var key, obj;
  7061. for (key in this.map) {
  7062. obj = this.get(key);
  7063. if (obj instanceof Dict) {
  7064. if (isRecursionAllowedFor(obj)) {
  7065. (queue || (queue = [])).push({target: all, key: key, obj: obj});
  7066. } else {
  7067. all[key] = this.getRaw(key);
  7068. }
  7069. } else {
  7070. all[key] = obj;
  7071. }
  7072. }
  7073. if (!queue) {
  7074. return all;
  7075. }
  7076. // trying to take cyclic references into the account
  7077. var processed = Object.create(null);
  7078. while (queue.length > 0) {
  7079. var item = queue.shift();
  7080. var itemObj = item.obj;
  7081. var objId = itemObj.objId;
  7082. if (objId && objId in processed) {
  7083. item.target[item.key] = processed[objId];
  7084. continue;
  7085. }
  7086. var dereferenced = Object.create(null);
  7087. for (key in itemObj.map) {
  7088. obj = itemObj.get(key);
  7089. if (obj instanceof Dict) {
  7090. if (isRecursionAllowedFor(obj)) {
  7091. queue.push({target: dereferenced, key: key, obj: obj});
  7092. } else {
  7093. dereferenced[key] = itemObj.getRaw(key);
  7094. }
  7095. } else {
  7096. dereferenced[key] = obj;
  7097. }
  7098. }
  7099. if (objId) {
  7100. processed[objId] = dereferenced;
  7101. }
  7102. item.target[item.key] = dereferenced;
  7103. }
  7104. return all;
  7105. },
  7106. set: function Dict_set(key, value) {
  7107. this.map[key] = value;
  7108. },
  7109. has: function Dict_has(key) {
  7110. return key in this.map;
  7111. },
  7112. forEach: function Dict_forEach(callback) {
  7113. for (var key in this.map) {
  7114. callback(key, this.get(key));
  7115. }
  7116. }
  7117. };
  7118. Dict.empty = new Dict(null);
  7119. return Dict;
  7120. })();
  7121. var Ref = (function RefClosure() {
  7122. function Ref(num, gen) {
  7123. this.num = num;
  7124. this.gen = gen;
  7125. }
  7126. Ref.prototype = {
  7127. toString: function Ref_toString() {
  7128. // This function is hot, so we make the string as compact as possible.
  7129. // |this.gen| is almost always zero, so we treat that case specially.
  7130. var str = this.num + 'R';
  7131. if (this.gen !== 0) {
  7132. str += this.gen;
  7133. }
  7134. return str;
  7135. }
  7136. };
  7137. return Ref;
  7138. })();
  7139. // The reference is identified by number and generation.
  7140. // This structure stores only one instance of the reference.
  7141. var RefSet = (function RefSetClosure() {
  7142. function RefSet() {
  7143. this.dict = {};
  7144. }
  7145. RefSet.prototype = {
  7146. has: function RefSet_has(ref) {
  7147. return ref.toString() in this.dict;
  7148. },
  7149. put: function RefSet_put(ref) {
  7150. this.dict[ref.toString()] = true;
  7151. },
  7152. remove: function RefSet_remove(ref) {
  7153. delete this.dict[ref.toString()];
  7154. }
  7155. };
  7156. return RefSet;
  7157. })();
  7158. var RefSetCache = (function RefSetCacheClosure() {
  7159. function RefSetCache() {
  7160. this.dict = Object.create(null);
  7161. }
  7162. RefSetCache.prototype = {
  7163. get: function RefSetCache_get(ref) {
  7164. return this.dict[ref.toString()];
  7165. },
  7166. has: function RefSetCache_has(ref) {
  7167. return ref.toString() in this.dict;
  7168. },
  7169. put: function RefSetCache_put(ref, obj) {
  7170. this.dict[ref.toString()] = obj;
  7171. },
  7172. putAlias: function RefSetCache_putAlias(ref, aliasRef) {
  7173. this.dict[ref.toString()] = this.get(aliasRef);
  7174. },
  7175. forEach: function RefSetCache_forEach(fn, thisArg) {
  7176. for (var i in this.dict) {
  7177. fn.call(thisArg, this.dict[i]);
  7178. }
  7179. },
  7180. clear: function RefSetCache_clear() {
  7181. this.dict = Object.create(null);
  7182. }
  7183. };
  7184. return RefSetCache;
  7185. })();
  7186. var Catalog = (function CatalogClosure() {
  7187. function Catalog(pdfManager, xref) {
  7188. this.pdfManager = pdfManager;
  7189. this.xref = xref;
  7190. this.catDict = xref.getCatalogObj();
  7191. this.fontCache = new RefSetCache();
  7192. assert(isDict(this.catDict),
  7193. 'catalog object is not a dictionary');
  7194. this.pagePromises = [];
  7195. }
  7196. Catalog.prototype = {
  7197. get metadata() {
  7198. var streamRef = this.catDict.getRaw('Metadata');
  7199. if (!isRef(streamRef)) {
  7200. return shadow(this, 'metadata', null);
  7201. }
  7202. var encryptMetadata = (!this.xref.encrypt ? false :
  7203. this.xref.encrypt.encryptMetadata);
  7204. var stream = this.xref.fetch(streamRef, !encryptMetadata);
  7205. var metadata;
  7206. if (stream && isDict(stream.dict)) {
  7207. var type = stream.dict.get('Type');
  7208. var subtype = stream.dict.get('Subtype');
  7209. if (isName(type) && isName(subtype) &&
  7210. type.name === 'Metadata' && subtype.name === 'XML') {
  7211. // XXX: This should examine the charset the XML document defines,
  7212. // however since there are currently no real means to decode
  7213. // arbitrary charsets, let's just hope that the author of the PDF
  7214. // was reasonable enough to stick with the XML default charset,
  7215. // which is UTF-8.
  7216. try {
  7217. metadata = stringToUTF8String(bytesToString(stream.getBytes()));
  7218. } catch (e) {
  7219. info('Skipping invalid metadata.');
  7220. }
  7221. }
  7222. }
  7223. return shadow(this, 'metadata', metadata);
  7224. },
  7225. get toplevelPagesDict() {
  7226. var pagesObj = this.catDict.get('Pages');
  7227. assert(isDict(pagesObj), 'invalid top-level pages dictionary');
  7228. // shadow the prototype getter
  7229. return shadow(this, 'toplevelPagesDict', pagesObj);
  7230. },
  7231. get documentOutline() {
  7232. var obj = null;
  7233. try {
  7234. obj = this.readDocumentOutline();
  7235. } catch (ex) {
  7236. if (ex instanceof MissingDataException) {
  7237. throw ex;
  7238. }
  7239. warn('Unable to read document outline');
  7240. }
  7241. return shadow(this, 'documentOutline', obj);
  7242. },
  7243. readDocumentOutline: function Catalog_readDocumentOutline() {
  7244. var xref = this.xref;
  7245. var obj = this.catDict.get('Outlines');
  7246. var root = { items: [] };
  7247. if (isDict(obj)) {
  7248. obj = obj.getRaw('First');
  7249. var processed = new RefSet();
  7250. if (isRef(obj)) {
  7251. var queue = [{obj: obj, parent: root}];
  7252. // to avoid recursion keeping track of the items
  7253. // in the processed dictionary
  7254. processed.put(obj);
  7255. while (queue.length > 0) {
  7256. var i = queue.shift();
  7257. var outlineDict = xref.fetchIfRef(i.obj);
  7258. if (outlineDict === null) {
  7259. continue;
  7260. }
  7261. if (!outlineDict.has('Title')) {
  7262. error('Invalid outline item');
  7263. }
  7264. var dest = outlineDict.get('A');
  7265. if (dest) {
  7266. dest = dest.get('D');
  7267. } else if (outlineDict.has('Dest')) {
  7268. dest = outlineDict.getRaw('Dest');
  7269. if (isName(dest)) {
  7270. dest = dest.name;
  7271. }
  7272. }
  7273. var title = outlineDict.get('Title');
  7274. var outlineItem = {
  7275. dest: dest,
  7276. title: stringToPDFString(title),
  7277. color: outlineDict.get('C') || [0, 0, 0],
  7278. count: outlineDict.get('Count'),
  7279. bold: !!(outlineDict.get('F') & 2),
  7280. italic: !!(outlineDict.get('F') & 1),
  7281. items: []
  7282. };
  7283. i.parent.items.push(outlineItem);
  7284. obj = outlineDict.getRaw('First');
  7285. if (isRef(obj) && !processed.has(obj)) {
  7286. queue.push({obj: obj, parent: outlineItem});
  7287. processed.put(obj);
  7288. }
  7289. obj = outlineDict.getRaw('Next');
  7290. if (isRef(obj) && !processed.has(obj)) {
  7291. queue.push({obj: obj, parent: i.parent});
  7292. processed.put(obj);
  7293. }
  7294. }
  7295. }
  7296. }
  7297. return (root.items.length > 0 ? root.items : null);
  7298. },
  7299. get numPages() {
  7300. var obj = this.toplevelPagesDict.get('Count');
  7301. assert(
  7302. isInt(obj),
  7303. 'page count in top level pages object is not an integer'
  7304. );
  7305. // shadow the prototype getter
  7306. return shadow(this, 'num', obj);
  7307. },
  7308. get destinations() {
  7309. function fetchDestination(dest) {
  7310. return isDict(dest) ? dest.get('D') : dest;
  7311. }
  7312. var xref = this.xref;
  7313. var dests = {}, nameTreeRef, nameDictionaryRef;
  7314. var obj = this.catDict.get('Names');
  7315. if (obj && obj.has('Dests')) {
  7316. nameTreeRef = obj.getRaw('Dests');
  7317. } else if (this.catDict.has('Dests')) {
  7318. nameDictionaryRef = this.catDict.get('Dests');
  7319. }
  7320. if (nameDictionaryRef) {
  7321. // reading simple destination dictionary
  7322. obj = nameDictionaryRef;
  7323. obj.forEach(function catalogForEach(key, value) {
  7324. if (!value) {
  7325. return;
  7326. }
  7327. dests[key] = fetchDestination(value);
  7328. });
  7329. }
  7330. if (nameTreeRef) {
  7331. var nameTree = new NameTree(nameTreeRef, xref);
  7332. var names = nameTree.getAll();
  7333. for (var name in names) {
  7334. if (!names.hasOwnProperty(name)) {
  7335. continue;
  7336. }
  7337. dests[name] = fetchDestination(names[name]);
  7338. }
  7339. }
  7340. return shadow(this, 'destinations', dests);
  7341. },
  7342. get attachments() {
  7343. var xref = this.xref;
  7344. var attachments = null, nameTreeRef;
  7345. var obj = this.catDict.get('Names');
  7346. if (obj) {
  7347. nameTreeRef = obj.getRaw('EmbeddedFiles');
  7348. }
  7349. if (nameTreeRef) {
  7350. var nameTree = new NameTree(nameTreeRef, xref);
  7351. var names = nameTree.getAll();
  7352. for (var name in names) {
  7353. if (!names.hasOwnProperty(name)) {
  7354. continue;
  7355. }
  7356. var fs = new FileSpec(names[name], xref);
  7357. if (!attachments) {
  7358. attachments = {};
  7359. }
  7360. attachments[stringToPDFString(name)] = fs.serializable;
  7361. }
  7362. }
  7363. return shadow(this, 'attachments', attachments);
  7364. },
  7365. get javaScript() {
  7366. var xref = this.xref;
  7367. var obj = this.catDict.get('Names');
  7368. var javaScript = [];
  7369. if (obj && obj.has('JavaScript')) {
  7370. var nameTree = new NameTree(obj.getRaw('JavaScript'), xref);
  7371. var names = nameTree.getAll();
  7372. for (var name in names) {
  7373. if (!names.hasOwnProperty(name)) {
  7374. continue;
  7375. }
  7376. // We don't really use the JavaScript right now. This code is
  7377. // defensive so we don't cause errors on document load.
  7378. var jsDict = names[name];
  7379. if (!isDict(jsDict)) {
  7380. continue;
  7381. }
  7382. var type = jsDict.get('S');
  7383. if (!isName(type) || type.name !== 'JavaScript') {
  7384. continue;
  7385. }
  7386. var js = jsDict.get('JS');
  7387. if (!isString(js) && !isStream(js)) {
  7388. continue;
  7389. }
  7390. if (isStream(js)) {
  7391. js = bytesToString(js.getBytes());
  7392. }
  7393. javaScript.push(stringToPDFString(js));
  7394. }
  7395. }
  7396. // Append OpenAction actions to javaScript array
  7397. var openactionDict = this.catDict.get('OpenAction');
  7398. if (isDict(openactionDict)) {
  7399. var objType = openactionDict.get('Type');
  7400. var actionType = openactionDict.get('S');
  7401. var action = openactionDict.get('N');
  7402. var isPrintAction = (isName(objType) && objType.name === 'Action' &&
  7403. isName(actionType) && actionType.name === 'Named' &&
  7404. isName(action) && action.name === 'Print');
  7405. if (isPrintAction) {
  7406. javaScript.push('print(true);');
  7407. }
  7408. }
  7409. return shadow(this, 'javaScript', javaScript);
  7410. },
  7411. cleanup: function Catalog_cleanup() {
  7412. var promises = [];
  7413. this.fontCache.forEach(function (promise) {
  7414. promises.push(promise);
  7415. });
  7416. return Promise.all(promises).then(function (translatedFonts) {
  7417. for (var i = 0, ii = translatedFonts.length; i < ii; i++) {
  7418. var font = translatedFonts[i].dict;
  7419. delete font.translated;
  7420. }
  7421. this.fontCache.clear();
  7422. }.bind(this));
  7423. },
  7424. getPage: function Catalog_getPage(pageIndex) {
  7425. if (!(pageIndex in this.pagePromises)) {
  7426. this.pagePromises[pageIndex] = this.getPageDict(pageIndex).then(
  7427. function (a) {
  7428. var dict = a[0];
  7429. var ref = a[1];
  7430. return new Page(this.pdfManager, this.xref, pageIndex, dict, ref,
  7431. this.fontCache);
  7432. }.bind(this)
  7433. );
  7434. }
  7435. return this.pagePromises[pageIndex];
  7436. },
  7437. getPageDict: function Catalog_getPageDict(pageIndex) {
  7438. var capability = createPromiseCapability();
  7439. var nodesToVisit = [this.catDict.getRaw('Pages')];
  7440. var currentPageIndex = 0;
  7441. var xref = this.xref;
  7442. function next() {
  7443. while (nodesToVisit.length) {
  7444. var currentNode = nodesToVisit.pop();
  7445. if (isRef(currentNode)) {
  7446. xref.fetchAsync(currentNode).then(function (obj) {
  7447. if ((isDict(obj, 'Page') || (isDict(obj) && !obj.has('Kids')))) {
  7448. if (pageIndex === currentPageIndex) {
  7449. capability.resolve([obj, currentNode]);
  7450. } else {
  7451. currentPageIndex++;
  7452. next();
  7453. }
  7454. return;
  7455. }
  7456. nodesToVisit.push(obj);
  7457. next();
  7458. }, capability.reject);
  7459. return;
  7460. }
  7461. // must be a child page dictionary
  7462. assert(
  7463. isDict(currentNode),
  7464. 'page dictionary kid reference points to wrong type of object'
  7465. );
  7466. var count = currentNode.get('Count');
  7467. // Skip nodes where the page can't be.
  7468. if (currentPageIndex + count <= pageIndex) {
  7469. currentPageIndex += count;
  7470. continue;
  7471. }
  7472. var kids = currentNode.get('Kids');
  7473. assert(isArray(kids), 'page dictionary kids object is not an array');
  7474. if (count === kids.length) {
  7475. // Nodes that don't have the page have been skipped and this is the
  7476. // bottom of the tree which means the page requested must be a
  7477. // descendant of this pages node. Ideally we would just resolve the
  7478. // promise with the page ref here, but there is the case where more
  7479. // pages nodes could link to single a page (see issue 3666 pdf). To
  7480. // handle this push it back on the queue so if it is a pages node it
  7481. // will be descended into.
  7482. nodesToVisit = [kids[pageIndex - currentPageIndex]];
  7483. currentPageIndex = pageIndex;
  7484. continue;
  7485. } else {
  7486. for (var last = kids.length - 1; last >= 0; last--) {
  7487. nodesToVisit.push(kids[last]);
  7488. }
  7489. }
  7490. }
  7491. capability.reject('Page index ' + pageIndex + ' not found.');
  7492. }
  7493. next();
  7494. return capability.promise;
  7495. },
  7496. getPageIndex: function Catalog_getPageIndex(ref) {
  7497. // The page tree nodes have the count of all the leaves below them. To get
  7498. // how many pages are before we just have to walk up the tree and keep
  7499. // adding the count of siblings to the left of the node.
  7500. var xref = this.xref;
  7501. function pagesBeforeRef(kidRef) {
  7502. var total = 0;
  7503. var parentRef;
  7504. return xref.fetchAsync(kidRef).then(function (node) {
  7505. if (!node) {
  7506. return null;
  7507. }
  7508. parentRef = node.getRaw('Parent');
  7509. return node.getAsync('Parent');
  7510. }).then(function (parent) {
  7511. if (!parent) {
  7512. return null;
  7513. }
  7514. return parent.getAsync('Kids');
  7515. }).then(function (kids) {
  7516. if (!kids) {
  7517. return null;
  7518. }
  7519. var kidPromises = [];
  7520. var found = false;
  7521. for (var i = 0; i < kids.length; i++) {
  7522. var kid = kids[i];
  7523. assert(isRef(kid), 'kids must be a ref');
  7524. if (kid.num === kidRef.num) {
  7525. found = true;
  7526. break;
  7527. }
  7528. kidPromises.push(xref.fetchAsync(kid).then(function (kid) {
  7529. if (kid.has('Count')) {
  7530. var count = kid.get('Count');
  7531. total += count;
  7532. } else { // page leaf node
  7533. total++;
  7534. }
  7535. }));
  7536. }
  7537. if (!found) {
  7538. error('kid ref not found in parents kids');
  7539. }
  7540. return Promise.all(kidPromises).then(function () {
  7541. return [total, parentRef];
  7542. });
  7543. });
  7544. }
  7545. var total = 0;
  7546. function next(ref) {
  7547. return pagesBeforeRef(ref).then(function (args) {
  7548. if (!args) {
  7549. return total;
  7550. }
  7551. var count = args[0];
  7552. var parentRef = args[1];
  7553. total += count;
  7554. return next(parentRef);
  7555. });
  7556. }
  7557. return next(ref);
  7558. }
  7559. };
  7560. return Catalog;
  7561. })();
  7562. var XRef = (function XRefClosure() {
  7563. function XRef(stream, password) {
  7564. this.stream = stream;
  7565. this.entries = [];
  7566. this.xrefstms = {};
  7567. // prepare the XRef cache
  7568. this.cache = [];
  7569. this.password = password;
  7570. this.stats = {
  7571. streamTypes: [],
  7572. fontTypes: []
  7573. };
  7574. }
  7575. XRef.prototype = {
  7576. setStartXRef: function XRef_setStartXRef(startXRef) {
  7577. // Store the starting positions of xref tables as we process them
  7578. // so we can recover from missing data errors
  7579. this.startXRefQueue = [startXRef];
  7580. },
  7581. parse: function XRef_parse(recoveryMode) {
  7582. var trailerDict;
  7583. if (!recoveryMode) {
  7584. trailerDict = this.readXRef();
  7585. } else {
  7586. warn('Indexing all PDF objects');
  7587. trailerDict = this.indexObjects();
  7588. }
  7589. trailerDict.assignXref(this);
  7590. this.trailer = trailerDict;
  7591. var encrypt = trailerDict.get('Encrypt');
  7592. if (encrypt) {
  7593. var ids = trailerDict.get('ID');
  7594. var fileId = (ids && ids.length) ? ids[0] : '';
  7595. this.encrypt = new CipherTransformFactory(encrypt, fileId,
  7596. this.password);
  7597. }
  7598. // get the root dictionary (catalog) object
  7599. if (!(this.root = trailerDict.get('Root'))) {
  7600. error('Invalid root reference');
  7601. }
  7602. },
  7603. processXRefTable: function XRef_processXRefTable(parser) {
  7604. if (!('tableState' in this)) {
  7605. // Stores state of the table as we process it so we can resume
  7606. // from middle of table in case of missing data error
  7607. this.tableState = {
  7608. entryNum: 0,
  7609. streamPos: parser.lexer.stream.pos,
  7610. parserBuf1: parser.buf1,
  7611. parserBuf2: parser.buf2
  7612. };
  7613. }
  7614. var obj = this.readXRefTable(parser);
  7615. // Sanity check
  7616. if (!isCmd(obj, 'trailer')) {
  7617. error('Invalid XRef table: could not find trailer dictionary');
  7618. }
  7619. // Read trailer dictionary, e.g.
  7620. // trailer
  7621. // << /Size 22
  7622. // /Root 20R
  7623. // /Info 10R
  7624. // /ID [ <81b14aafa313db63dbd6f981e49f94f4> ]
  7625. // >>
  7626. // The parser goes through the entire stream << ... >> and provides
  7627. // a getter interface for the key-value table
  7628. var dict = parser.getObj();
  7629. // The pdflib PDF generator can generate a nested trailer dictionary
  7630. if (!isDict(dict) && dict.dict) {
  7631. dict = dict.dict;
  7632. }
  7633. if (!isDict(dict)) {
  7634. error('Invalid XRef table: could not parse trailer dictionary');
  7635. }
  7636. delete this.tableState;
  7637. return dict;
  7638. },
  7639. readXRefTable: function XRef_readXRefTable(parser) {
  7640. // Example of cross-reference table:
  7641. // xref
  7642. // 0 1 <-- subsection header (first obj #, obj count)
  7643. // 0000000000 65535 f <-- actual object (offset, generation #, f/n)
  7644. // 23 2 <-- subsection header ... and so on ...
  7645. // 0000025518 00002 n
  7646. // 0000025635 00000 n
  7647. // trailer
  7648. // ...
  7649. var stream = parser.lexer.stream;
  7650. var tableState = this.tableState;
  7651. stream.pos = tableState.streamPos;
  7652. parser.buf1 = tableState.parserBuf1;
  7653. parser.buf2 = tableState.parserBuf2;
  7654. // Outer loop is over subsection headers
  7655. var obj;
  7656. while (true) {
  7657. if (!('firstEntryNum' in tableState) || !('entryCount' in tableState)) {
  7658. if (isCmd(obj = parser.getObj(), 'trailer')) {
  7659. break;
  7660. }
  7661. tableState.firstEntryNum = obj;
  7662. tableState.entryCount = parser.getObj();
  7663. }
  7664. var first = tableState.firstEntryNum;
  7665. var count = tableState.entryCount;
  7666. if (!isInt(first) || !isInt(count)) {
  7667. error('Invalid XRef table: wrong types in subsection header');
  7668. }
  7669. // Inner loop is over objects themselves
  7670. for (var i = tableState.entryNum; i < count; i++) {
  7671. tableState.streamPos = stream.pos;
  7672. tableState.entryNum = i;
  7673. tableState.parserBuf1 = parser.buf1;
  7674. tableState.parserBuf2 = parser.buf2;
  7675. var entry = {};
  7676. entry.offset = parser.getObj();
  7677. entry.gen = parser.getObj();
  7678. var type = parser.getObj();
  7679. if (isCmd(type, 'f')) {
  7680. entry.free = true;
  7681. } else if (isCmd(type, 'n')) {
  7682. entry.uncompressed = true;
  7683. }
  7684. // Validate entry obj
  7685. if (!isInt(entry.offset) || !isInt(entry.gen) ||
  7686. !(entry.free || entry.uncompressed)) {
  7687. console.log(entry.offset, entry.gen, entry.free,
  7688. entry.uncompressed);
  7689. error('Invalid entry in XRef subsection: ' + first + ', ' + count);
  7690. }
  7691. if (!this.entries[i + first]) {
  7692. this.entries[i + first] = entry;
  7693. }
  7694. }
  7695. tableState.entryNum = 0;
  7696. tableState.streamPos = stream.pos;
  7697. tableState.parserBuf1 = parser.buf1;
  7698. tableState.parserBuf2 = parser.buf2;
  7699. delete tableState.firstEntryNum;
  7700. delete tableState.entryCount;
  7701. }
  7702. // Per issue 3248: hp scanners generate bad XRef
  7703. if (first === 1 && this.entries[1] && this.entries[1].free) {
  7704. // shifting the entries
  7705. this.entries.shift();
  7706. }
  7707. // Sanity check: as per spec, first object must be free
  7708. if (this.entries[0] && !this.entries[0].free) {
  7709. error('Invalid XRef table: unexpected first object');
  7710. }
  7711. return obj;
  7712. },
  7713. processXRefStream: function XRef_processXRefStream(stream) {
  7714. if (!('streamState' in this)) {
  7715. // Stores state of the stream as we process it so we can resume
  7716. // from middle of stream in case of missing data error
  7717. var streamParameters = stream.dict;
  7718. var byteWidths = streamParameters.get('W');
  7719. var range = streamParameters.get('Index');
  7720. if (!range) {
  7721. range = [0, streamParameters.get('Size')];
  7722. }
  7723. this.streamState = {
  7724. entryRanges: range,
  7725. byteWidths: byteWidths,
  7726. entryNum: 0,
  7727. streamPos: stream.pos
  7728. };
  7729. }
  7730. this.readXRefStream(stream);
  7731. delete this.streamState;
  7732. return stream.dict;
  7733. },
  7734. readXRefStream: function XRef_readXRefStream(stream) {
  7735. var i, j;
  7736. var streamState = this.streamState;
  7737. stream.pos = streamState.streamPos;
  7738. var byteWidths = streamState.byteWidths;
  7739. var typeFieldWidth = byteWidths[0];
  7740. var offsetFieldWidth = byteWidths[1];
  7741. var generationFieldWidth = byteWidths[2];
  7742. var entryRanges = streamState.entryRanges;
  7743. while (entryRanges.length > 0) {
  7744. var first = entryRanges[0];
  7745. var n = entryRanges[1];
  7746. if (!isInt(first) || !isInt(n)) {
  7747. error('Invalid XRef range fields: ' + first + ', ' + n);
  7748. }
  7749. if (!isInt(typeFieldWidth) || !isInt(offsetFieldWidth) ||
  7750. !isInt(generationFieldWidth)) {
  7751. error('Invalid XRef entry fields length: ' + first + ', ' + n);
  7752. }
  7753. for (i = streamState.entryNum; i < n; ++i) {
  7754. streamState.entryNum = i;
  7755. streamState.streamPos = stream.pos;
  7756. var type = 0, offset = 0, generation = 0;
  7757. for (j = 0; j < typeFieldWidth; ++j) {
  7758. type = (type << 8) | stream.getByte();
  7759. }
  7760. // if type field is absent, its default value is 1
  7761. if (typeFieldWidth === 0) {
  7762. type = 1;
  7763. }
  7764. for (j = 0; j < offsetFieldWidth; ++j) {
  7765. offset = (offset << 8) | stream.getByte();
  7766. }
  7767. for (j = 0; j < generationFieldWidth; ++j) {
  7768. generation = (generation << 8) | stream.getByte();
  7769. }
  7770. var entry = {};
  7771. entry.offset = offset;
  7772. entry.gen = generation;
  7773. switch (type) {
  7774. case 0:
  7775. entry.free = true;
  7776. break;
  7777. case 1:
  7778. entry.uncompressed = true;
  7779. break;
  7780. case 2:
  7781. break;
  7782. default:
  7783. error('Invalid XRef entry type: ' + type);
  7784. }
  7785. if (!this.entries[first + i]) {
  7786. this.entries[first + i] = entry;
  7787. }
  7788. }
  7789. streamState.entryNum = 0;
  7790. streamState.streamPos = stream.pos;
  7791. entryRanges.splice(0, 2);
  7792. }
  7793. },
  7794. indexObjects: function XRef_indexObjects() {
  7795. // Simple scan through the PDF content to find objects,
  7796. // trailers and XRef streams.
  7797. function readToken(data, offset) {
  7798. var token = '', ch = data[offset];
  7799. while (ch !== 13 && ch !== 10) {
  7800. if (++offset >= data.length) {
  7801. break;
  7802. }
  7803. token += String.fromCharCode(ch);
  7804. ch = data[offset];
  7805. }
  7806. return token;
  7807. }
  7808. function skipUntil(data, offset, what) {
  7809. var length = what.length, dataLength = data.length;
  7810. var skipped = 0;
  7811. // finding byte sequence
  7812. while (offset < dataLength) {
  7813. var i = 0;
  7814. while (i < length && data[offset + i] === what[i]) {
  7815. ++i;
  7816. }
  7817. if (i >= length) {
  7818. break; // sequence found
  7819. }
  7820. offset++;
  7821. skipped++;
  7822. }
  7823. return skipped;
  7824. }
  7825. var trailerBytes = new Uint8Array([116, 114, 97, 105, 108, 101, 114]);
  7826. var startxrefBytes = new Uint8Array([115, 116, 97, 114, 116, 120, 114,
  7827. 101, 102]);
  7828. var endobjBytes = new Uint8Array([101, 110, 100, 111, 98, 106]);
  7829. var xrefBytes = new Uint8Array([47, 88, 82, 101, 102]);
  7830. var stream = this.stream;
  7831. stream.pos = 0;
  7832. var buffer = stream.getBytes();
  7833. var position = stream.start, length = buffer.length;
  7834. var trailers = [], xrefStms = [];
  7835. while (position < length) {
  7836. var ch = buffer[position];
  7837. if (ch === 32 || ch === 9 || ch === 13 || ch === 10) {
  7838. ++position;
  7839. continue;
  7840. }
  7841. if (ch === 37) { // %-comment
  7842. do {
  7843. ++position;
  7844. if (position >= length) {
  7845. break;
  7846. }
  7847. ch = buffer[position];
  7848. } while (ch !== 13 && ch !== 10);
  7849. continue;
  7850. }
  7851. var token = readToken(buffer, position);
  7852. var m;
  7853. if (token === 'xref') {
  7854. position += skipUntil(buffer, position, trailerBytes);
  7855. trailers.push(position);
  7856. position += skipUntil(buffer, position, startxrefBytes);
  7857. } else if ((m = /^(\d+)\s+(\d+)\s+obj\b/.exec(token))) {
  7858. this.entries[m[1]] = {
  7859. offset: position,
  7860. gen: m[2] | 0,
  7861. uncompressed: true
  7862. };
  7863. var contentLength = skipUntil(buffer, position, endobjBytes) + 7;
  7864. var content = buffer.subarray(position, position + contentLength);
  7865. // checking XRef stream suspect
  7866. // (it shall have '/XRef' and next char is not a letter)
  7867. var xrefTagOffset = skipUntil(content, 0, xrefBytes);
  7868. if (xrefTagOffset < contentLength &&
  7869. content[xrefTagOffset + 5] < 64) {
  7870. xrefStms.push(position);
  7871. this.xrefstms[position] = 1; // don't read it recursively
  7872. }
  7873. position += contentLength;
  7874. } else {
  7875. position += token.length + 1;
  7876. }
  7877. }
  7878. // reading XRef streams
  7879. var i, ii;
  7880. for (i = 0, ii = xrefStms.length; i < ii; ++i) {
  7881. this.startXRefQueue.push(xrefStms[i]);
  7882. this.readXRef(/* recoveryMode */ true);
  7883. }
  7884. // finding main trailer
  7885. var dict;
  7886. for (i = 0, ii = trailers.length; i < ii; ++i) {
  7887. stream.pos = trailers[i];
  7888. var parser = new Parser(new Lexer(stream), true, this);
  7889. var obj = parser.getObj();
  7890. if (!isCmd(obj, 'trailer')) {
  7891. continue;
  7892. }
  7893. // read the trailer dictionary
  7894. if (!isDict(dict = parser.getObj())) {
  7895. continue;
  7896. }
  7897. // taking the first one with 'ID'
  7898. if (dict.has('ID')) {
  7899. return dict;
  7900. }
  7901. }
  7902. // no tailer with 'ID', taking last one (if exists)
  7903. if (dict) {
  7904. return dict;
  7905. }
  7906. // nothing helps
  7907. // calling error() would reject worker with an UnknownErrorException.
  7908. throw new InvalidPDFException('Invalid PDF structure');
  7909. },
  7910. readXRef: function XRef_readXRef(recoveryMode) {
  7911. var stream = this.stream;
  7912. try {
  7913. while (this.startXRefQueue.length) {
  7914. var startXRef = this.startXRefQueue[0];
  7915. stream.pos = startXRef + stream.start;
  7916. var parser = new Parser(new Lexer(stream), true, this);
  7917. var obj = parser.getObj();
  7918. var dict;
  7919. // Get dictionary
  7920. if (isCmd(obj, 'xref')) {
  7921. // Parse end-of-file XRef
  7922. dict = this.processXRefTable(parser);
  7923. if (!this.topDict) {
  7924. this.topDict = dict;
  7925. }
  7926. // Recursively get other XRefs 'XRefStm', if any
  7927. obj = dict.get('XRefStm');
  7928. if (isInt(obj)) {
  7929. var pos = obj;
  7930. // ignore previously loaded xref streams
  7931. // (possible infinite recursion)
  7932. if (!(pos in this.xrefstms)) {
  7933. this.xrefstms[pos] = 1;
  7934. this.startXRefQueue.push(pos);
  7935. }
  7936. }
  7937. } else if (isInt(obj)) {
  7938. // Parse in-stream XRef
  7939. if (!isInt(parser.getObj()) ||
  7940. !isCmd(parser.getObj(), 'obj') ||
  7941. !isStream(obj = parser.getObj())) {
  7942. error('Invalid XRef stream');
  7943. }
  7944. dict = this.processXRefStream(obj);
  7945. if (!this.topDict) {
  7946. this.topDict = dict;
  7947. }
  7948. if (!dict) {
  7949. error('Failed to read XRef stream');
  7950. }
  7951. } else {
  7952. error('Invalid XRef stream header');
  7953. }
  7954. // Recursively get previous dictionary, if any
  7955. obj = dict.get('Prev');
  7956. if (isInt(obj)) {
  7957. this.startXRefQueue.push(obj);
  7958. } else if (isRef(obj)) {
  7959. // The spec says Prev must not be a reference, i.e. "/Prev NNN"
  7960. // This is a fallback for non-compliant PDFs, i.e. "/Prev NNN 0 R"
  7961. this.startXRefQueue.push(obj.num);
  7962. }
  7963. this.startXRefQueue.shift();
  7964. }
  7965. return this.topDict;
  7966. } catch (e) {
  7967. if (e instanceof MissingDataException) {
  7968. throw e;
  7969. }
  7970. info('(while reading XRef): ' + e);
  7971. }
  7972. if (recoveryMode) {
  7973. return;
  7974. }
  7975. throw new XRefParseException();
  7976. },
  7977. getEntry: function XRef_getEntry(i) {
  7978. var xrefEntry = this.entries[i];
  7979. if (xrefEntry && !xrefEntry.free && xrefEntry.offset) {
  7980. return xrefEntry;
  7981. }
  7982. return null;
  7983. },
  7984. fetchIfRef: function XRef_fetchIfRef(obj) {
  7985. if (!isRef(obj)) {
  7986. return obj;
  7987. }
  7988. return this.fetch(obj);
  7989. },
  7990. fetch: function XRef_fetch(ref, suppressEncryption) {
  7991. assert(isRef(ref), 'ref object is not a reference');
  7992. var num = ref.num;
  7993. if (num in this.cache) {
  7994. var cacheEntry = this.cache[num];
  7995. return cacheEntry;
  7996. }
  7997. var xrefEntry = this.getEntry(num);
  7998. // the referenced entry can be free
  7999. if (xrefEntry === null) {
  8000. return (this.cache[num] = null);
  8001. }
  8002. if (xrefEntry.uncompressed) {
  8003. xrefEntry = this.fetchUncompressed(ref, xrefEntry, suppressEncryption);
  8004. } else {
  8005. xrefEntry = this.fetchCompressed(xrefEntry, suppressEncryption);
  8006. }
  8007. if (isDict(xrefEntry)){
  8008. xrefEntry.objId = ref.toString();
  8009. } else if (isStream(xrefEntry)) {
  8010. xrefEntry.dict.objId = ref.toString();
  8011. }
  8012. return xrefEntry;
  8013. },
  8014. fetchUncompressed: function XRef_fetchUncompressed(ref, xrefEntry,
  8015. suppressEncryption) {
  8016. var gen = ref.gen;
  8017. var num = ref.num;
  8018. if (xrefEntry.gen !== gen) {
  8019. error('inconsistent generation in XRef');
  8020. }
  8021. var stream = this.stream.makeSubStream(xrefEntry.offset +
  8022. this.stream.start);
  8023. var parser = new Parser(new Lexer(stream), true, this);
  8024. var obj1 = parser.getObj();
  8025. var obj2 = parser.getObj();
  8026. var obj3 = parser.getObj();
  8027. if (!isInt(obj1) || parseInt(obj1, 10) !== num ||
  8028. !isInt(obj2) || parseInt(obj2, 10) !== gen ||
  8029. !isCmd(obj3)) {
  8030. error('bad XRef entry');
  8031. }
  8032. if (!isCmd(obj3, 'obj')) {
  8033. // some bad PDFs use "obj1234" and really mean 1234
  8034. if (obj3.cmd.indexOf('obj') === 0) {
  8035. num = parseInt(obj3.cmd.substring(3), 10);
  8036. if (!isNaN(num)) {
  8037. return num;
  8038. }
  8039. }
  8040. error('bad XRef entry');
  8041. }
  8042. if (this.encrypt && !suppressEncryption) {
  8043. xrefEntry = parser.getObj(this.encrypt.createCipherTransform(num, gen));
  8044. } else {
  8045. xrefEntry = parser.getObj();
  8046. }
  8047. if (!isStream(xrefEntry)) {
  8048. this.cache[num] = xrefEntry;
  8049. }
  8050. return xrefEntry;
  8051. },
  8052. fetchCompressed: function XRef_fetchCompressed(xrefEntry,
  8053. suppressEncryption) {
  8054. var tableOffset = xrefEntry.offset;
  8055. var stream = this.fetch(new Ref(tableOffset, 0));
  8056. if (!isStream(stream)) {
  8057. error('bad ObjStm stream');
  8058. }
  8059. var first = stream.dict.get('First');
  8060. var n = stream.dict.get('N');
  8061. if (!isInt(first) || !isInt(n)) {
  8062. error('invalid first and n parameters for ObjStm stream');
  8063. }
  8064. var parser = new Parser(new Lexer(stream), false, this);
  8065. parser.allowStreams = true;
  8066. var i, entries = [], num, nums = [];
  8067. // read the object numbers to populate cache
  8068. for (i = 0; i < n; ++i) {
  8069. num = parser.getObj();
  8070. if (!isInt(num)) {
  8071. error('invalid object number in the ObjStm stream: ' + num);
  8072. }
  8073. nums.push(num);
  8074. var offset = parser.getObj();
  8075. if (!isInt(offset)) {
  8076. error('invalid object offset in the ObjStm stream: ' + offset);
  8077. }
  8078. }
  8079. // read stream objects for cache
  8080. for (i = 0; i < n; ++i) {
  8081. entries.push(parser.getObj());
  8082. num = nums[i];
  8083. var entry = this.entries[num];
  8084. if (entry && entry.offset === tableOffset && entry.gen === i) {
  8085. this.cache[num] = entries[i];
  8086. }
  8087. }
  8088. xrefEntry = entries[xrefEntry.gen];
  8089. if (xrefEntry === undefined) {
  8090. error('bad XRef entry for compressed object');
  8091. }
  8092. return xrefEntry;
  8093. },
  8094. fetchIfRefAsync: function XRef_fetchIfRefAsync(obj) {
  8095. if (!isRef(obj)) {
  8096. return Promise.resolve(obj);
  8097. }
  8098. return this.fetchAsync(obj);
  8099. },
  8100. fetchAsync: function XRef_fetchAsync(ref, suppressEncryption) {
  8101. var streamManager = this.stream.manager;
  8102. var xref = this;
  8103. return new Promise(function tryFetch(resolve, reject) {
  8104. try {
  8105. resolve(xref.fetch(ref, suppressEncryption));
  8106. } catch (e) {
  8107. if (e instanceof MissingDataException) {
  8108. streamManager.requestRange(e.begin, e.end, function () {
  8109. tryFetch(resolve, reject);
  8110. });
  8111. return;
  8112. }
  8113. reject(e);
  8114. }
  8115. });
  8116. },
  8117. getCatalogObj: function XRef_getCatalogObj() {
  8118. return this.root;
  8119. }
  8120. };
  8121. return XRef;
  8122. })();
  8123. /**
  8124. * A NameTree is like a Dict but has some advantageous properties, see the
  8125. * spec (7.9.6) for more details.
  8126. * TODO: implement all the Dict functions and make this more efficent.
  8127. */
  8128. var NameTree = (function NameTreeClosure() {
  8129. function NameTree(root, xref) {
  8130. this.root = root;
  8131. this.xref = xref;
  8132. }
  8133. NameTree.prototype = {
  8134. getAll: function NameTree_getAll() {
  8135. var dict = {};
  8136. if (!this.root) {
  8137. return dict;
  8138. }
  8139. var xref = this.xref;
  8140. // reading name tree
  8141. var processed = new RefSet();
  8142. processed.put(this.root);
  8143. var queue = [this.root];
  8144. while (queue.length > 0) {
  8145. var i, n;
  8146. var obj = xref.fetchIfRef(queue.shift());
  8147. if (!isDict(obj)) {
  8148. continue;
  8149. }
  8150. if (obj.has('Kids')) {
  8151. var kids = obj.get('Kids');
  8152. for (i = 0, n = kids.length; i < n; i++) {
  8153. var kid = kids[i];
  8154. if (processed.has(kid)) {
  8155. error('invalid destinations');
  8156. }
  8157. queue.push(kid);
  8158. processed.put(kid);
  8159. }
  8160. continue;
  8161. }
  8162. var names = obj.get('Names');
  8163. if (names) {
  8164. for (i = 0, n = names.length; i < n; i += 2) {
  8165. dict[names[i]] = xref.fetchIfRef(names[i + 1]);
  8166. }
  8167. }
  8168. }
  8169. return dict;
  8170. }
  8171. };
  8172. return NameTree;
  8173. })();
  8174. /**
  8175. * "A PDF file can refer to the contents of another file by using a File
  8176. * Specification (PDF 1.1)", see the spec (7.11) for more details.
  8177. * NOTE: Only embedded files are supported (as part of the attachments support)
  8178. * TODO: support the 'URL' file system (with caching if !/V), portable
  8179. * collections attributes and related files (/RF)
  8180. */
  8181. var FileSpec = (function FileSpecClosure() {
  8182. function FileSpec(root, xref) {
  8183. if (!root || !isDict(root)) {
  8184. return;
  8185. }
  8186. this.xref = xref;
  8187. this.root = root;
  8188. if (root.has('FS')) {
  8189. this.fs = root.get('FS');
  8190. }
  8191. this.description = root.has('Desc') ?
  8192. stringToPDFString(root.get('Desc')) :
  8193. '';
  8194. if (root.has('RF')) {
  8195. warn('Related file specifications are not supported');
  8196. }
  8197. this.contentAvailable = true;
  8198. if (!root.has('EF')) {
  8199. this.contentAvailable = false;
  8200. warn('Non-embedded file specifications are not supported');
  8201. }
  8202. }
  8203. function pickPlatformItem(dict) {
  8204. // Look for the filename in this order:
  8205. // UF, F, Unix, Mac, DOS
  8206. if (dict.has('UF')) {
  8207. return dict.get('UF');
  8208. } else if (dict.has('F')) {
  8209. return dict.get('F');
  8210. } else if (dict.has('Unix')) {
  8211. return dict.get('Unix');
  8212. } else if (dict.has('Mac')) {
  8213. return dict.get('Mac');
  8214. } else if (dict.has('DOS')) {
  8215. return dict.get('DOS');
  8216. } else {
  8217. return null;
  8218. }
  8219. }
  8220. FileSpec.prototype = {
  8221. get filename() {
  8222. if (!this._filename && this.root) {
  8223. var filename = pickPlatformItem(this.root) || 'unnamed';
  8224. this._filename = stringToPDFString(filename).
  8225. replace(/\\\\/g, '\\').
  8226. replace(/\\\//g, '/').
  8227. replace(/\\/g, '/');
  8228. }
  8229. return this._filename;
  8230. },
  8231. get content() {
  8232. if (!this.contentAvailable) {
  8233. return null;
  8234. }
  8235. if (!this.contentRef && this.root) {
  8236. this.contentRef = pickPlatformItem(this.root.get('EF'));
  8237. }
  8238. var content = null;
  8239. if (this.contentRef) {
  8240. var xref = this.xref;
  8241. var fileObj = xref.fetchIfRef(this.contentRef);
  8242. if (fileObj && isStream(fileObj)) {
  8243. content = fileObj.getBytes();
  8244. } else {
  8245. warn('Embedded file specification points to non-existing/invalid ' +
  8246. 'content');
  8247. }
  8248. } else {
  8249. warn('Embedded file specification does not have a content');
  8250. }
  8251. return content;
  8252. },
  8253. get serializable() {
  8254. return {
  8255. filename: this.filename,
  8256. content: this.content
  8257. };
  8258. }
  8259. };
  8260. return FileSpec;
  8261. })();
  8262. /**
  8263. * A helper for loading missing data in object graphs. It traverses the graph
  8264. * depth first and queues up any objects that have missing data. Once it has
  8265. * has traversed as many objects that are available it attempts to bundle the
  8266. * missing data requests and then resume from the nodes that weren't ready.
  8267. *
  8268. * NOTE: It provides protection from circular references by keeping track of
  8269. * of loaded references. However, you must be careful not to load any graphs
  8270. * that have references to the catalog or other pages since that will cause the
  8271. * entire PDF document object graph to be traversed.
  8272. */
  8273. var ObjectLoader = (function() {
  8274. function mayHaveChildren(value) {
  8275. return isRef(value) || isDict(value) || isArray(value) || isStream(value);
  8276. }
  8277. function addChildren(node, nodesToVisit) {
  8278. var value;
  8279. if (isDict(node) || isStream(node)) {
  8280. var map;
  8281. if (isDict(node)) {
  8282. map = node.map;
  8283. } else {
  8284. map = node.dict.map;
  8285. }
  8286. for (var key in map) {
  8287. value = map[key];
  8288. if (mayHaveChildren(value)) {
  8289. nodesToVisit.push(value);
  8290. }
  8291. }
  8292. } else if (isArray(node)) {
  8293. for (var i = 0, ii = node.length; i < ii; i++) {
  8294. value = node[i];
  8295. if (mayHaveChildren(value)) {
  8296. nodesToVisit.push(value);
  8297. }
  8298. }
  8299. }
  8300. }
  8301. function ObjectLoader(obj, keys, xref) {
  8302. this.obj = obj;
  8303. this.keys = keys;
  8304. this.xref = xref;
  8305. this.refSet = null;
  8306. }
  8307. ObjectLoader.prototype = {
  8308. load: function ObjectLoader_load() {
  8309. var keys = this.keys;
  8310. this.capability = createPromiseCapability();
  8311. // Don't walk the graph if all the data is already loaded.
  8312. if (!(this.xref.stream instanceof ChunkedStream) ||
  8313. this.xref.stream.getMissingChunks().length === 0) {
  8314. this.capability.resolve();
  8315. return this.capability.promise;
  8316. }
  8317. this.refSet = new RefSet();
  8318. // Setup the initial nodes to visit.
  8319. var nodesToVisit = [];
  8320. for (var i = 0; i < keys.length; i++) {
  8321. nodesToVisit.push(this.obj[keys[i]]);
  8322. }
  8323. this.walk(nodesToVisit);
  8324. return this.capability.promise;
  8325. },
  8326. walk: function ObjectLoader_walk(nodesToVisit) {
  8327. var nodesToRevisit = [];
  8328. var pendingRequests = [];
  8329. // DFS walk of the object graph.
  8330. while (nodesToVisit.length) {
  8331. var currentNode = nodesToVisit.pop();
  8332. // Only references or chunked streams can cause missing data exceptions.
  8333. if (isRef(currentNode)) {
  8334. // Skip nodes that have already been visited.
  8335. if (this.refSet.has(currentNode)) {
  8336. continue;
  8337. }
  8338. try {
  8339. var ref = currentNode;
  8340. this.refSet.put(ref);
  8341. currentNode = this.xref.fetch(currentNode);
  8342. } catch (e) {
  8343. if (!(e instanceof MissingDataException)) {
  8344. throw e;
  8345. }
  8346. nodesToRevisit.push(currentNode);
  8347. pendingRequests.push({ begin: e.begin, end: e.end });
  8348. }
  8349. }
  8350. if (currentNode && currentNode.getBaseStreams) {
  8351. var baseStreams = currentNode.getBaseStreams();
  8352. var foundMissingData = false;
  8353. for (var i = 0; i < baseStreams.length; i++) {
  8354. var stream = baseStreams[i];
  8355. if (stream.getMissingChunks && stream.getMissingChunks().length) {
  8356. foundMissingData = true;
  8357. pendingRequests.push({
  8358. begin: stream.start,
  8359. end: stream.end
  8360. });
  8361. }
  8362. }
  8363. if (foundMissingData) {
  8364. nodesToRevisit.push(currentNode);
  8365. }
  8366. }
  8367. addChildren(currentNode, nodesToVisit);
  8368. }
  8369. if (pendingRequests.length) {
  8370. this.xref.stream.manager.requestRanges(pendingRequests,
  8371. function pendingRequestCallback() {
  8372. nodesToVisit = nodesToRevisit;
  8373. for (var i = 0; i < nodesToRevisit.length; i++) {
  8374. var node = nodesToRevisit[i];
  8375. // Remove any reference nodes from the currrent refset so they
  8376. // aren't skipped when we revist them.
  8377. if (isRef(node)) {
  8378. this.refSet.remove(node);
  8379. }
  8380. }
  8381. this.walk(nodesToVisit);
  8382. }.bind(this));
  8383. return;
  8384. }
  8385. // Everything is loaded.
  8386. this.refSet = null;
  8387. this.capability.resolve();
  8388. }
  8389. };
  8390. return ObjectLoader;
  8391. })();
  8392. var ISOAdobeCharset = [
  8393. '.notdef', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar',
  8394. 'percent', 'ampersand', 'quoteright', 'parenleft', 'parenright',
  8395. 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash', 'zero',
  8396. 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',
  8397. 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater', 'question',
  8398. 'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
  8399. 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
  8400. 'bracketleft', 'backslash', 'bracketright', 'asciicircum', 'underscore',
  8401. 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
  8402. 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
  8403. 'braceleft', 'bar', 'braceright', 'asciitilde', 'exclamdown', 'cent',
  8404. 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  8405. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  8406. 'guilsinglright', 'fi', 'fl', 'endash', 'dagger', 'daggerdbl',
  8407. 'periodcentered', 'paragraph', 'bullet', 'quotesinglbase',
  8408. 'quotedblbase', 'quotedblright', 'guillemotright', 'ellipsis',
  8409. 'perthousand', 'questiondown', 'grave', 'acute', 'circumflex', 'tilde',
  8410. 'macron', 'breve', 'dotaccent', 'dieresis', 'ring', 'cedilla',
  8411. 'hungarumlaut', 'ogonek', 'caron', 'emdash', 'AE', 'ordfeminine',
  8412. 'Lslash', 'Oslash', 'OE', 'ordmasculine', 'ae', 'dotlessi', 'lslash',
  8413. 'oslash', 'oe', 'germandbls', 'onesuperior', 'logicalnot', 'mu',
  8414. 'trademark', 'Eth', 'onehalf', 'plusminus', 'Thorn', 'onequarter',
  8415. 'divide', 'brokenbar', 'degree', 'thorn', 'threequarters', 'twosuperior',
  8416. 'registered', 'minus', 'eth', 'multiply', 'threesuperior', 'copyright',
  8417. 'Aacute', 'Acircumflex', 'Adieresis', 'Agrave', 'Aring', 'Atilde',
  8418. 'Ccedilla', 'Eacute', 'Ecircumflex', 'Edieresis', 'Egrave', 'Iacute',
  8419. 'Icircumflex', 'Idieresis', 'Igrave', 'Ntilde', 'Oacute', 'Ocircumflex',
  8420. 'Odieresis', 'Ograve', 'Otilde', 'Scaron', 'Uacute', 'Ucircumflex',
  8421. 'Udieresis', 'Ugrave', 'Yacute', 'Ydieresis', 'Zcaron', 'aacute',
  8422. 'acircumflex', 'adieresis', 'agrave', 'aring', 'atilde', 'ccedilla',
  8423. 'eacute', 'ecircumflex', 'edieresis', 'egrave', 'iacute', 'icircumflex',
  8424. 'idieresis', 'igrave', 'ntilde', 'oacute', 'ocircumflex', 'odieresis',
  8425. 'ograve', 'otilde', 'scaron', 'uacute', 'ucircumflex', 'udieresis',
  8426. 'ugrave', 'yacute', 'ydieresis', 'zcaron'
  8427. ];
  8428. var ExpertCharset = [
  8429. '.notdef', 'space', 'exclamsmall', 'Hungarumlautsmall', 'dollaroldstyle',
  8430. 'dollarsuperior', 'ampersandsmall', 'Acutesmall', 'parenleftsuperior',
  8431. 'parenrightsuperior', 'twodotenleader', 'onedotenleader', 'comma',
  8432. 'hyphen', 'period', 'fraction', 'zerooldstyle', 'oneoldstyle',
  8433. 'twooldstyle', 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle',
  8434. 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle',
  8435. 'colon', 'semicolon', 'commasuperior', 'threequartersemdash',
  8436. 'periodsuperior', 'questionsmall', 'asuperior', 'bsuperior',
  8437. 'centsuperior', 'dsuperior', 'esuperior', 'isuperior', 'lsuperior',
  8438. 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  8439. 'tsuperior', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior',
  8440. 'parenrightinferior', 'Circumflexsmall', 'hyphensuperior', 'Gravesmall',
  8441. 'Asmall', 'Bsmall', 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall',
  8442. 'Hsmall', 'Ismall', 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall',
  8443. 'Osmall', 'Psmall', 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall',
  8444. 'Vsmall', 'Wsmall', 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary',
  8445. 'onefitted', 'rupiah', 'Tildesmall', 'exclamdownsmall', 'centoldstyle',
  8446. 'Lslashsmall', 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall',
  8447. 'Brevesmall', 'Caronsmall', 'Dotaccentsmall', 'Macronsmall',
  8448. 'figuredash', 'hypheninferior', 'Ogoneksmall', 'Ringsmall',
  8449. 'Cedillasmall', 'onequarter', 'onehalf', 'threequarters',
  8450. 'questiondownsmall', 'oneeighth', 'threeeighths', 'fiveeighths',
  8451. 'seveneighths', 'onethird', 'twothirds', 'zerosuperior', 'onesuperior',
  8452. 'twosuperior', 'threesuperior', 'foursuperior', 'fivesuperior',
  8453. 'sixsuperior', 'sevensuperior', 'eightsuperior', 'ninesuperior',
  8454. 'zeroinferior', 'oneinferior', 'twoinferior', 'threeinferior',
  8455. 'fourinferior', 'fiveinferior', 'sixinferior', 'seveninferior',
  8456. 'eightinferior', 'nineinferior', 'centinferior', 'dollarinferior',
  8457. 'periodinferior', 'commainferior', 'Agravesmall', 'Aacutesmall',
  8458. 'Acircumflexsmall', 'Atildesmall', 'Adieresissmall', 'Aringsmall',
  8459. 'AEsmall', 'Ccedillasmall', 'Egravesmall', 'Eacutesmall',
  8460. 'Ecircumflexsmall', 'Edieresissmall', 'Igravesmall', 'Iacutesmall',
  8461. 'Icircumflexsmall', 'Idieresissmall', 'Ethsmall', 'Ntildesmall',
  8462. 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall', 'Otildesmall',
  8463. 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall', 'Uacutesmall',
  8464. 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall', 'Thornsmall',
  8465. 'Ydieresissmall'
  8466. ];
  8467. var ExpertSubsetCharset = [
  8468. '.notdef', 'space', 'dollaroldstyle', 'dollarsuperior',
  8469. 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  8470. 'onedotenleader', 'comma', 'hyphen', 'period', 'fraction',
  8471. 'zerooldstyle', 'oneoldstyle', 'twooldstyle', 'threeoldstyle',
  8472. 'fouroldstyle', 'fiveoldstyle', 'sixoldstyle', 'sevenoldstyle',
  8473. 'eightoldstyle', 'nineoldstyle', 'colon', 'semicolon', 'commasuperior',
  8474. 'threequartersemdash', 'periodsuperior', 'asuperior', 'bsuperior',
  8475. 'centsuperior', 'dsuperior', 'esuperior', 'isuperior', 'lsuperior',
  8476. 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  8477. 'tsuperior', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior',
  8478. 'parenrightinferior', 'hyphensuperior', 'colonmonetary', 'onefitted',
  8479. 'rupiah', 'centoldstyle', 'figuredash', 'hypheninferior', 'onequarter',
  8480. 'onehalf', 'threequarters', 'oneeighth', 'threeeighths', 'fiveeighths',
  8481. 'seveneighths', 'onethird', 'twothirds', 'zerosuperior', 'onesuperior',
  8482. 'twosuperior', 'threesuperior', 'foursuperior', 'fivesuperior',
  8483. 'sixsuperior', 'sevensuperior', 'eightsuperior', 'ninesuperior',
  8484. 'zeroinferior', 'oneinferior', 'twoinferior', 'threeinferior',
  8485. 'fourinferior', 'fiveinferior', 'sixinferior', 'seveninferior',
  8486. 'eightinferior', 'nineinferior', 'centinferior', 'dollarinferior',
  8487. 'periodinferior', 'commainferior'
  8488. ];
  8489. var DEFAULT_ICON_SIZE = 22; // px
  8490. var SUPPORTED_TYPES = ['Link', 'Text', 'Widget'];
  8491. var Annotation = (function AnnotationClosure() {
  8492. // 12.5.5: Algorithm: Appearance streams
  8493. function getTransformMatrix(rect, bbox, matrix) {
  8494. var bounds = Util.getAxialAlignedBoundingBox(bbox, matrix);
  8495. var minX = bounds[0];
  8496. var minY = bounds[1];
  8497. var maxX = bounds[2];
  8498. var maxY = bounds[3];
  8499. if (minX === maxX || minY === maxY) {
  8500. // From real-life file, bbox was [0, 0, 0, 0]. In this case,
  8501. // just apply the transform for rect
  8502. return [1, 0, 0, 1, rect[0], rect[1]];
  8503. }
  8504. var xRatio = (rect[2] - rect[0]) / (maxX - minX);
  8505. var yRatio = (rect[3] - rect[1]) / (maxY - minY);
  8506. return [
  8507. xRatio,
  8508. 0,
  8509. 0,
  8510. yRatio,
  8511. rect[0] - minX * xRatio,
  8512. rect[1] - minY * yRatio
  8513. ];
  8514. }
  8515. function getDefaultAppearance(dict) {
  8516. var appearanceState = dict.get('AP');
  8517. if (!isDict(appearanceState)) {
  8518. return;
  8519. }
  8520. var appearance;
  8521. var appearances = appearanceState.get('N');
  8522. if (isDict(appearances)) {
  8523. var as = dict.get('AS');
  8524. if (as && appearances.has(as.name)) {
  8525. appearance = appearances.get(as.name);
  8526. }
  8527. } else {
  8528. appearance = appearances;
  8529. }
  8530. return appearance;
  8531. }
  8532. function Annotation(params) {
  8533. var dict = params.dict;
  8534. var data = this.data = {};
  8535. data.subtype = dict.get('Subtype').name;
  8536. var rect = dict.get('Rect') || [0, 0, 0, 0];
  8537. data.rect = Util.normalizeRect(rect);
  8538. data.annotationFlags = dict.get('F');
  8539. var color = dict.get('C');
  8540. if (isArray(color) && color.length === 3) {
  8541. // TODO(mack): currently only supporting rgb; need support different
  8542. // colorspaces
  8543. data.color = color;
  8544. } else {
  8545. data.color = [0, 0, 0];
  8546. }
  8547. // Some types of annotations have border style dict which has more
  8548. // info than the border array
  8549. if (dict.has('BS')) {
  8550. var borderStyle = dict.get('BS');
  8551. data.borderWidth = borderStyle.has('W') ? borderStyle.get('W') : 1;
  8552. } else {
  8553. var borderArray = dict.get('Border') || [0, 0, 1];
  8554. data.borderWidth = borderArray[2] || 0;
  8555. // TODO: implement proper support for annotations with line dash patterns.
  8556. var dashArray = borderArray[3];
  8557. if (data.borderWidth > 0 && dashArray) {
  8558. if (!isArray(dashArray)) {
  8559. // Ignore the border if dashArray is not actually an array,
  8560. // this is consistent with the behaviour in Adobe Reader.
  8561. data.borderWidth = 0;
  8562. } else {
  8563. var dashArrayLength = dashArray.length;
  8564. if (dashArrayLength > 0) {
  8565. // According to the PDF specification: the elements in a dashArray
  8566. // shall be numbers that are nonnegative and not all equal to zero.
  8567. var isInvalid = false;
  8568. var numPositive = 0;
  8569. for (var i = 0; i < dashArrayLength; i++) {
  8570. var validNumber = (+dashArray[i] >= 0);
  8571. if (!validNumber) {
  8572. isInvalid = true;
  8573. break;
  8574. } else if (dashArray[i] > 0) {
  8575. numPositive++;
  8576. }
  8577. }
  8578. if (isInvalid || numPositive === 0) {
  8579. data.borderWidth = 0;
  8580. }
  8581. }
  8582. }
  8583. }
  8584. }
  8585. this.appearance = getDefaultAppearance(dict);
  8586. data.hasAppearance = !!this.appearance;
  8587. data.id = params.ref.num;
  8588. }
  8589. Annotation.prototype = {
  8590. getData: function Annotation_getData() {
  8591. return this.data;
  8592. },
  8593. isInvisible: function Annotation_isInvisible() {
  8594. var data = this.data;
  8595. if (data && SUPPORTED_TYPES.indexOf(data.subtype) !== -1) {
  8596. return false;
  8597. } else {
  8598. return !!(data &&
  8599. data.annotationFlags && // Default: not invisible
  8600. data.annotationFlags & 0x1); // Invisible
  8601. }
  8602. },
  8603. isViewable: function Annotation_isViewable() {
  8604. var data = this.data;
  8605. return !!(!this.isInvisible() &&
  8606. data &&
  8607. (!data.annotationFlags ||
  8608. !(data.annotationFlags & 0x22)) && // Hidden or NoView
  8609. data.rect); // rectangle is necessary
  8610. },
  8611. isPrintable: function Annotation_isPrintable() {
  8612. var data = this.data;
  8613. return !!(!this.isInvisible() &&
  8614. data &&
  8615. data.annotationFlags && // Default: not printable
  8616. data.annotationFlags & 0x4 && // Print
  8617. !(data.annotationFlags & 0x2) && // Hidden
  8618. data.rect); // rectangle is necessary
  8619. },
  8620. loadResources: function Annotation_loadResources(keys) {
  8621. return new Promise(function (resolve, reject) {
  8622. this.appearance.dict.getAsync('Resources').then(function (resources) {
  8623. if (!resources) {
  8624. resolve();
  8625. return;
  8626. }
  8627. var objectLoader = new ObjectLoader(resources.map,
  8628. keys,
  8629. resources.xref);
  8630. objectLoader.load().then(function() {
  8631. resolve(resources);
  8632. }, reject);
  8633. }, reject);
  8634. }.bind(this));
  8635. },
  8636. getOperatorList: function Annotation_getOperatorList(evaluator) {
  8637. if (!this.appearance) {
  8638. return Promise.resolve(new OperatorList());
  8639. }
  8640. var data = this.data;
  8641. var appearanceDict = this.appearance.dict;
  8642. var resourcesPromise = this.loadResources([
  8643. 'ExtGState',
  8644. 'ColorSpace',
  8645. 'Pattern',
  8646. 'Shading',
  8647. 'XObject',
  8648. 'Font'
  8649. // ProcSet
  8650. // Properties
  8651. ]);
  8652. var bbox = appearanceDict.get('BBox') || [0, 0, 1, 1];
  8653. var matrix = appearanceDict.get('Matrix') || [1, 0, 0, 1, 0 ,0];
  8654. var transform = getTransformMatrix(data.rect, bbox, matrix);
  8655. var self = this;
  8656. return resourcesPromise.then(function(resources) {
  8657. var opList = new OperatorList();
  8658. opList.addOp(OPS.beginAnnotation, [data.rect, transform, matrix]);
  8659. return evaluator.getOperatorList(self.appearance, resources, opList).
  8660. then(function () {
  8661. opList.addOp(OPS.endAnnotation, []);
  8662. self.appearance.reset();
  8663. return opList;
  8664. });
  8665. });
  8666. }
  8667. };
  8668. Annotation.getConstructor =
  8669. function Annotation_getConstructor(subtype, fieldType) {
  8670. if (!subtype) {
  8671. return;
  8672. }
  8673. // TODO(mack): Implement FreeText annotations
  8674. if (subtype === 'Link') {
  8675. return LinkAnnotation;
  8676. } else if (subtype === 'Text') {
  8677. return TextAnnotation;
  8678. } else if (subtype === 'Widget') {
  8679. if (!fieldType) {
  8680. return;
  8681. }
  8682. if (fieldType === 'Tx') {
  8683. return TextWidgetAnnotation;
  8684. } else {
  8685. return WidgetAnnotation;
  8686. }
  8687. } else {
  8688. return Annotation;
  8689. }
  8690. };
  8691. Annotation.fromRef = function Annotation_fromRef(xref, ref) {
  8692. var dict = xref.fetchIfRef(ref);
  8693. if (!isDict(dict)) {
  8694. return;
  8695. }
  8696. var subtype = dict.get('Subtype');
  8697. subtype = isName(subtype) ? subtype.name : '';
  8698. if (!subtype) {
  8699. return;
  8700. }
  8701. var fieldType = Util.getInheritableProperty(dict, 'FT');
  8702. fieldType = isName(fieldType) ? fieldType.name : '';
  8703. var Constructor = Annotation.getConstructor(subtype, fieldType);
  8704. if (!Constructor) {
  8705. return;
  8706. }
  8707. var params = {
  8708. dict: dict,
  8709. ref: ref,
  8710. };
  8711. var annotation = new Constructor(params);
  8712. if (annotation.isViewable() || annotation.isPrintable()) {
  8713. return annotation;
  8714. } else {
  8715. if (SUPPORTED_TYPES.indexOf(subtype) === -1) {
  8716. warn('unimplemented annotation type: ' + subtype);
  8717. }
  8718. }
  8719. };
  8720. Annotation.appendToOperatorList = function Annotation_appendToOperatorList(
  8721. annotations, opList, pdfManager, partialEvaluator, intent) {
  8722. function reject(e) {
  8723. annotationsReadyCapability.reject(e);
  8724. }
  8725. var annotationsReadyCapability = createPromiseCapability();
  8726. var annotationPromises = [];
  8727. for (var i = 0, n = annotations.length; i < n; ++i) {
  8728. if (intent === 'display' && annotations[i].isViewable() ||
  8729. intent === 'print' && annotations[i].isPrintable()) {
  8730. annotationPromises.push(
  8731. annotations[i].getOperatorList(partialEvaluator));
  8732. }
  8733. }
  8734. Promise.all(annotationPromises).then(function(datas) {
  8735. opList.addOp(OPS.beginAnnotations, []);
  8736. for (var i = 0, n = datas.length; i < n; ++i) {
  8737. var annotOpList = datas[i];
  8738. opList.addOpList(annotOpList);
  8739. }
  8740. opList.addOp(OPS.endAnnotations, []);
  8741. annotationsReadyCapability.resolve();
  8742. }, reject);
  8743. return annotationsReadyCapability.promise;
  8744. };
  8745. return Annotation;
  8746. })();
  8747. var WidgetAnnotation = (function WidgetAnnotationClosure() {
  8748. function WidgetAnnotation(params) {
  8749. Annotation.call(this, params);
  8750. var dict = params.dict;
  8751. var data = this.data;
  8752. data.fieldValue = stringToPDFString(
  8753. Util.getInheritableProperty(dict, 'V') || '');
  8754. data.alternativeText = stringToPDFString(dict.get('TU') || '');
  8755. data.defaultAppearance = Util.getInheritableProperty(dict, 'DA') || '';
  8756. var fieldType = Util.getInheritableProperty(dict, 'FT');
  8757. data.fieldType = isName(fieldType) ? fieldType.name : '';
  8758. data.fieldFlags = Util.getInheritableProperty(dict, 'Ff') || 0;
  8759. this.fieldResources = Util.getInheritableProperty(dict, 'DR') || Dict.empty;
  8760. // Building the full field name by collecting the field and
  8761. // its ancestors 'T' data and joining them using '.'.
  8762. var fieldName = [];
  8763. var namedItem = dict;
  8764. var ref = params.ref;
  8765. while (namedItem) {
  8766. var parent = namedItem.get('Parent');
  8767. var parentRef = namedItem.getRaw('Parent');
  8768. var name = namedItem.get('T');
  8769. if (name) {
  8770. fieldName.unshift(stringToPDFString(name));
  8771. } else {
  8772. // The field name is absent, that means more than one field
  8773. // with the same name may exist. Replacing the empty name
  8774. // with the '`' plus index in the parent's 'Kids' array.
  8775. // This is not in the PDF spec but necessary to id the
  8776. // the input controls.
  8777. var kids = parent.get('Kids');
  8778. var j, jj;
  8779. for (j = 0, jj = kids.length; j < jj; j++) {
  8780. var kidRef = kids[j];
  8781. if (kidRef.num === ref.num && kidRef.gen === ref.gen) {
  8782. break;
  8783. }
  8784. }
  8785. fieldName.unshift('`' + j);
  8786. }
  8787. namedItem = parent;
  8788. ref = parentRef;
  8789. }
  8790. data.fullName = fieldName.join('.');
  8791. }
  8792. var parent = Annotation.prototype;
  8793. Util.inherit(WidgetAnnotation, Annotation, {
  8794. isViewable: function WidgetAnnotation_isViewable() {
  8795. if (this.data.fieldType === 'Sig') {
  8796. warn('unimplemented annotation type: Widget signature');
  8797. return false;
  8798. }
  8799. return parent.isViewable.call(this);
  8800. }
  8801. });
  8802. return WidgetAnnotation;
  8803. })();
  8804. var TextWidgetAnnotation = (function TextWidgetAnnotationClosure() {
  8805. function TextWidgetAnnotation(params) {
  8806. WidgetAnnotation.call(this, params);
  8807. this.data.textAlignment = Util.getInheritableProperty(params.dict, 'Q');
  8808. this.data.annotationType = AnnotationType.WIDGET;
  8809. this.data.hasHtml = !this.data.hasAppearance && !!this.data.fieldValue;
  8810. }
  8811. Util.inherit(TextWidgetAnnotation, WidgetAnnotation, {
  8812. getOperatorList: function TextWidgetAnnotation_getOperatorList(evaluator) {
  8813. if (this.appearance) {
  8814. return Annotation.prototype.getOperatorList.call(this, evaluator);
  8815. }
  8816. var opList = new OperatorList();
  8817. var data = this.data;
  8818. // Even if there is an appearance stream, ignore it. This is the
  8819. // behaviour used by Adobe Reader.
  8820. if (!data.defaultAppearance) {
  8821. return Promise.resolve(opList);
  8822. }
  8823. var stream = new Stream(stringToBytes(data.defaultAppearance));
  8824. return evaluator.getOperatorList(stream, this.fieldResources, opList).
  8825. then(function () {
  8826. return opList;
  8827. });
  8828. }
  8829. });
  8830. return TextWidgetAnnotation;
  8831. })();
  8832. var InteractiveAnnotation = (function InteractiveAnnotationClosure() {
  8833. function InteractiveAnnotation(params) {
  8834. Annotation.call(this, params);
  8835. this.data.hasHtml = true;
  8836. }
  8837. Util.inherit(InteractiveAnnotation, Annotation, { });
  8838. return InteractiveAnnotation;
  8839. })();
  8840. var TextAnnotation = (function TextAnnotationClosure() {
  8841. function TextAnnotation(params) {
  8842. InteractiveAnnotation.call(this, params);
  8843. var dict = params.dict;
  8844. var data = this.data;
  8845. var content = dict.get('Contents');
  8846. var title = dict.get('T');
  8847. data.annotationType = AnnotationType.TEXT;
  8848. data.content = stringToPDFString(content || '');
  8849. data.title = stringToPDFString(title || '');
  8850. if (data.hasAppearance) {
  8851. data.name = 'NoIcon';
  8852. } else {
  8853. data.rect[1] = data.rect[3] - DEFAULT_ICON_SIZE;
  8854. data.rect[2] = data.rect[0] + DEFAULT_ICON_SIZE;
  8855. data.name = dict.has('Name') ? dict.get('Name').name : 'Note';
  8856. }
  8857. if (dict.has('C')) {
  8858. data.hasBgColor = true;
  8859. }
  8860. }
  8861. Util.inherit(TextAnnotation, InteractiveAnnotation, { });
  8862. return TextAnnotation;
  8863. })();
  8864. var LinkAnnotation = (function LinkAnnotationClosure() {
  8865. function LinkAnnotation(params) {
  8866. InteractiveAnnotation.call(this, params);
  8867. var dict = params.dict;
  8868. var data = this.data;
  8869. data.annotationType = AnnotationType.LINK;
  8870. var action = dict.get('A');
  8871. if (action) {
  8872. var linkType = action.get('S').name;
  8873. if (linkType === 'URI') {
  8874. var url = action.get('URI');
  8875. if (isName(url)) {
  8876. // Some bad PDFs do not put parentheses around relative URLs.
  8877. url = '/' + url.name;
  8878. } else if (url) {
  8879. url = addDefaultProtocolToUrl(url);
  8880. }
  8881. // TODO: pdf spec mentions urls can be relative to a Base
  8882. // entry in the dictionary.
  8883. if (!isValidUrl(url, false)) {
  8884. url = '';
  8885. }
  8886. data.url = url;
  8887. } else if (linkType === 'GoTo') {
  8888. data.dest = action.get('D');
  8889. } else if (linkType === 'GoToR') {
  8890. var urlDict = action.get('F');
  8891. if (isDict(urlDict)) {
  8892. // We assume that the 'url' is a Filspec dictionary
  8893. // and fetch the url without checking any further
  8894. url = urlDict.get('F') || '';
  8895. }
  8896. // TODO: pdf reference says that GoToR
  8897. // can also have 'NewWindow' attribute
  8898. if (!isValidUrl(url, false)) {
  8899. url = '';
  8900. }
  8901. data.url = url;
  8902. data.dest = action.get('D');
  8903. } else if (linkType === 'Named') {
  8904. data.action = action.get('N').name;
  8905. } else {
  8906. warn('unrecognized link type: ' + linkType);
  8907. }
  8908. } else if (dict.has('Dest')) {
  8909. // simple destination link
  8910. var dest = dict.get('Dest');
  8911. data.dest = isName(dest) ? dest.name : dest;
  8912. }
  8913. }
  8914. // Lets URLs beginning with 'www.' default to using the 'http://' protocol.
  8915. function addDefaultProtocolToUrl(url) {
  8916. if (url && url.indexOf('www.') === 0) {
  8917. return ('http://' + url);
  8918. }
  8919. return url;
  8920. }
  8921. Util.inherit(LinkAnnotation, InteractiveAnnotation, {
  8922. hasOperatorList: function LinkAnnotation_hasOperatorList() {
  8923. return false;
  8924. }
  8925. });
  8926. return LinkAnnotation;
  8927. })();
  8928. var PDFFunction = (function PDFFunctionClosure() {
  8929. var CONSTRUCT_SAMPLED = 0;
  8930. var CONSTRUCT_INTERPOLATED = 2;
  8931. var CONSTRUCT_STICHED = 3;
  8932. var CONSTRUCT_POSTSCRIPT = 4;
  8933. return {
  8934. getSampleArray: function PDFFunction_getSampleArray(size, outputSize, bps,
  8935. str) {
  8936. var i, ii;
  8937. var length = 1;
  8938. for (i = 0, ii = size.length; i < ii; i++) {
  8939. length *= size[i];
  8940. }
  8941. length *= outputSize;
  8942. var array = [];
  8943. var codeSize = 0;
  8944. var codeBuf = 0;
  8945. // 32 is a valid bps so shifting won't work
  8946. var sampleMul = 1.0 / (Math.pow(2.0, bps) - 1);
  8947. var strBytes = str.getBytes((length * bps + 7) / 8);
  8948. var strIdx = 0;
  8949. for (i = 0; i < length; i++) {
  8950. while (codeSize < bps) {
  8951. codeBuf <<= 8;
  8952. codeBuf |= strBytes[strIdx++];
  8953. codeSize += 8;
  8954. }
  8955. codeSize -= bps;
  8956. array.push((codeBuf >> codeSize) * sampleMul);
  8957. codeBuf &= (1 << codeSize) - 1;
  8958. }
  8959. return array;
  8960. },
  8961. getIR: function PDFFunction_getIR(xref, fn) {
  8962. var dict = fn.dict;
  8963. if (!dict) {
  8964. dict = fn;
  8965. }
  8966. var types = [this.constructSampled,
  8967. null,
  8968. this.constructInterpolated,
  8969. this.constructStiched,
  8970. this.constructPostScript];
  8971. var typeNum = dict.get('FunctionType');
  8972. var typeFn = types[typeNum];
  8973. if (!typeFn) {
  8974. error('Unknown type of function');
  8975. }
  8976. return typeFn.call(this, fn, dict, xref);
  8977. },
  8978. fromIR: function PDFFunction_fromIR(IR) {
  8979. var type = IR[0];
  8980. switch (type) {
  8981. case CONSTRUCT_SAMPLED:
  8982. return this.constructSampledFromIR(IR);
  8983. case CONSTRUCT_INTERPOLATED:
  8984. return this.constructInterpolatedFromIR(IR);
  8985. case CONSTRUCT_STICHED:
  8986. return this.constructStichedFromIR(IR);
  8987. //case CONSTRUCT_POSTSCRIPT:
  8988. default:
  8989. return this.constructPostScriptFromIR(IR);
  8990. }
  8991. },
  8992. parse: function PDFFunction_parse(xref, fn) {
  8993. var IR = this.getIR(xref, fn);
  8994. return this.fromIR(IR);
  8995. },
  8996. parseArray: function PDFFunction_parseArray(xref, fnObj) {
  8997. if (!isArray(fnObj)) {
  8998. // not an array -- parsing as regular function
  8999. return this.parse(xref, fnObj);
  9000. }
  9001. var fnArray = [];
  9002. for (var j = 0, jj = fnObj.length; j < jj; j++) {
  9003. var obj = xref.fetchIfRef(fnObj[j]);
  9004. fnArray.push(PDFFunction.parse(xref, obj));
  9005. }
  9006. return function (src, srcOffset, dest, destOffset) {
  9007. for (var i = 0, ii = fnArray.length; i < ii; i++) {
  9008. fnArray[i](src, srcOffset, dest, destOffset + i);
  9009. }
  9010. };
  9011. },
  9012. constructSampled: function PDFFunction_constructSampled(str, dict) {
  9013. function toMultiArray(arr) {
  9014. var inputLength = arr.length;
  9015. var out = [];
  9016. var index = 0;
  9017. for (var i = 0; i < inputLength; i += 2) {
  9018. out[index] = [arr[i], arr[i + 1]];
  9019. ++index;
  9020. }
  9021. return out;
  9022. }
  9023. var domain = dict.get('Domain');
  9024. var range = dict.get('Range');
  9025. if (!domain || !range) {
  9026. error('No domain or range');
  9027. }
  9028. var inputSize = domain.length / 2;
  9029. var outputSize = range.length / 2;
  9030. domain = toMultiArray(domain);
  9031. range = toMultiArray(range);
  9032. var size = dict.get('Size');
  9033. var bps = dict.get('BitsPerSample');
  9034. var order = dict.get('Order') || 1;
  9035. if (order !== 1) {
  9036. // No description how cubic spline interpolation works in PDF32000:2008
  9037. // As in poppler, ignoring order, linear interpolation may work as good
  9038. info('No support for cubic spline interpolation: ' + order);
  9039. }
  9040. var encode = dict.get('Encode');
  9041. if (!encode) {
  9042. encode = [];
  9043. for (var i = 0; i < inputSize; ++i) {
  9044. encode.push(0);
  9045. encode.push(size[i] - 1);
  9046. }
  9047. }
  9048. encode = toMultiArray(encode);
  9049. var decode = dict.get('Decode');
  9050. if (!decode) {
  9051. decode = range;
  9052. } else {
  9053. decode = toMultiArray(decode);
  9054. }
  9055. var samples = this.getSampleArray(size, outputSize, bps, str);
  9056. return [
  9057. CONSTRUCT_SAMPLED, inputSize, domain, encode, decode, samples, size,
  9058. outputSize, Math.pow(2, bps) - 1, range
  9059. ];
  9060. },
  9061. constructSampledFromIR: function PDFFunction_constructSampledFromIR(IR) {
  9062. // See chapter 3, page 109 of the PDF reference
  9063. function interpolate(x, xmin, xmax, ymin, ymax) {
  9064. return ymin + ((x - xmin) * ((ymax - ymin) / (xmax - xmin)));
  9065. }
  9066. return function constructSampledFromIRResult(src, srcOffset,
  9067. dest, destOffset) {
  9068. // See chapter 3, page 110 of the PDF reference.
  9069. var m = IR[1];
  9070. var domain = IR[2];
  9071. var encode = IR[3];
  9072. var decode = IR[4];
  9073. var samples = IR[5];
  9074. var size = IR[6];
  9075. var n = IR[7];
  9076. //var mask = IR[8];
  9077. var range = IR[9];
  9078. // Building the cube vertices: its part and sample index
  9079. // http://rjwagner49.com/Mathematics/Interpolation.pdf
  9080. var cubeVertices = 1 << m;
  9081. var cubeN = new Float64Array(cubeVertices);
  9082. var cubeVertex = new Uint32Array(cubeVertices);
  9083. var i, j;
  9084. for (j = 0; j < cubeVertices; j++) {
  9085. cubeN[j] = 1;
  9086. }
  9087. var k = n, pos = 1;
  9088. // Map x_i to y_j for 0 <= i < m using the sampled function.
  9089. for (i = 0; i < m; ++i) {
  9090. // x_i' = min(max(x_i, Domain_2i), Domain_2i+1)
  9091. var domain_2i = domain[i][0];
  9092. var domain_2i_1 = domain[i][1];
  9093. var xi = Math.min(Math.max(src[srcOffset +i], domain_2i),
  9094. domain_2i_1);
  9095. // e_i = Interpolate(x_i', Domain_2i, Domain_2i+1,
  9096. // Encode_2i, Encode_2i+1)
  9097. var e = interpolate(xi, domain_2i, domain_2i_1,
  9098. encode[i][0], encode[i][1]);
  9099. // e_i' = min(max(e_i, 0), Size_i - 1)
  9100. var size_i = size[i];
  9101. e = Math.min(Math.max(e, 0), size_i - 1);
  9102. // Adjusting the cube: N and vertex sample index
  9103. var e0 = e < size_i - 1 ? Math.floor(e) : e - 1; // e1 = e0 + 1;
  9104. var n0 = e0 + 1 - e; // (e1 - e) / (e1 - e0);
  9105. var n1 = e - e0; // (e - e0) / (e1 - e0);
  9106. var offset0 = e0 * k;
  9107. var offset1 = offset0 + k; // e1 * k
  9108. for (j = 0; j < cubeVertices; j++) {
  9109. if (j & pos) {
  9110. cubeN[j] *= n1;
  9111. cubeVertex[j] += offset1;
  9112. } else {
  9113. cubeN[j] *= n0;
  9114. cubeVertex[j] += offset0;
  9115. }
  9116. }
  9117. k *= size_i;
  9118. pos <<= 1;
  9119. }
  9120. for (j = 0; j < n; ++j) {
  9121. // Sum all cube vertices' samples portions
  9122. var rj = 0;
  9123. for (i = 0; i < cubeVertices; i++) {
  9124. rj += samples[cubeVertex[i] + j] * cubeN[i];
  9125. }
  9126. // r_j' = Interpolate(r_j, 0, 2^BitsPerSample - 1,
  9127. // Decode_2j, Decode_2j+1)
  9128. rj = interpolate(rj, 0, 1, decode[j][0], decode[j][1]);
  9129. // y_j = min(max(r_j, range_2j), range_2j+1)
  9130. dest[destOffset + j] = Math.min(Math.max(rj, range[j][0]),
  9131. range[j][1]);
  9132. }
  9133. };
  9134. },
  9135. constructInterpolated: function PDFFunction_constructInterpolated(str,
  9136. dict) {
  9137. var c0 = dict.get('C0') || [0];
  9138. var c1 = dict.get('C1') || [1];
  9139. var n = dict.get('N');
  9140. if (!isArray(c0) || !isArray(c1)) {
  9141. error('Illegal dictionary for interpolated function');
  9142. }
  9143. var length = c0.length;
  9144. var diff = [];
  9145. for (var i = 0; i < length; ++i) {
  9146. diff.push(c1[i] - c0[i]);
  9147. }
  9148. return [CONSTRUCT_INTERPOLATED, c0, diff, n];
  9149. },
  9150. constructInterpolatedFromIR:
  9151. function PDFFunction_constructInterpolatedFromIR(IR) {
  9152. var c0 = IR[1];
  9153. var diff = IR[2];
  9154. var n = IR[3];
  9155. var length = diff.length;
  9156. return function constructInterpolatedFromIRResult(src, srcOffset,
  9157. dest, destOffset) {
  9158. var x = n === 1 ? src[srcOffset] : Math.pow(src[srcOffset], n);
  9159. for (var j = 0; j < length; ++j) {
  9160. dest[destOffset + j] = c0[j] + (x * diff[j]);
  9161. }
  9162. };
  9163. },
  9164. constructStiched: function PDFFunction_constructStiched(fn, dict, xref) {
  9165. var domain = dict.get('Domain');
  9166. if (!domain) {
  9167. error('No domain');
  9168. }
  9169. var inputSize = domain.length / 2;
  9170. if (inputSize !== 1) {
  9171. error('Bad domain for stiched function');
  9172. }
  9173. var fnRefs = dict.get('Functions');
  9174. var fns = [];
  9175. for (var i = 0, ii = fnRefs.length; i < ii; ++i) {
  9176. fns.push(PDFFunction.getIR(xref, xref.fetchIfRef(fnRefs[i])));
  9177. }
  9178. var bounds = dict.get('Bounds');
  9179. var encode = dict.get('Encode');
  9180. return [CONSTRUCT_STICHED, domain, bounds, encode, fns];
  9181. },
  9182. constructStichedFromIR: function PDFFunction_constructStichedFromIR(IR) {
  9183. var domain = IR[1];
  9184. var bounds = IR[2];
  9185. var encode = IR[3];
  9186. var fnsIR = IR[4];
  9187. var fns = [];
  9188. var tmpBuf = new Float32Array(1);
  9189. for (var i = 0, ii = fnsIR.length; i < ii; i++) {
  9190. fns.push(PDFFunction.fromIR(fnsIR[i]));
  9191. }
  9192. return function constructStichedFromIRResult(src, srcOffset,
  9193. dest, destOffset) {
  9194. var clip = function constructStichedFromIRClip(v, min, max) {
  9195. if (v > max) {
  9196. v = max;
  9197. } else if (v < min) {
  9198. v = min;
  9199. }
  9200. return v;
  9201. };
  9202. // clip to domain
  9203. var v = clip(src[srcOffset], domain[0], domain[1]);
  9204. // calulate which bound the value is in
  9205. for (var i = 0, ii = bounds.length; i < ii; ++i) {
  9206. if (v < bounds[i]) {
  9207. break;
  9208. }
  9209. }
  9210. // encode value into domain of function
  9211. var dmin = domain[0];
  9212. if (i > 0) {
  9213. dmin = bounds[i - 1];
  9214. }
  9215. var dmax = domain[1];
  9216. if (i < bounds.length) {
  9217. dmax = bounds[i];
  9218. }
  9219. var rmin = encode[2 * i];
  9220. var rmax = encode[2 * i + 1];
  9221. tmpBuf[0] = rmin + (v - dmin) * (rmax - rmin) / (dmax - dmin);
  9222. // call the appropriate function
  9223. fns[i](tmpBuf, 0, dest, destOffset);
  9224. };
  9225. },
  9226. constructPostScript: function PDFFunction_constructPostScript(fn, dict,
  9227. xref) {
  9228. var domain = dict.get('Domain');
  9229. var range = dict.get('Range');
  9230. if (!domain) {
  9231. error('No domain.');
  9232. }
  9233. if (!range) {
  9234. error('No range.');
  9235. }
  9236. var lexer = new PostScriptLexer(fn);
  9237. var parser = new PostScriptParser(lexer);
  9238. var code = parser.parse();
  9239. return [CONSTRUCT_POSTSCRIPT, domain, range, code];
  9240. },
  9241. constructPostScriptFromIR: function PDFFunction_constructPostScriptFromIR(
  9242. IR) {
  9243. var domain = IR[1];
  9244. var range = IR[2];
  9245. var code = IR[3];
  9246. var compiled = (new PostScriptCompiler()).compile(code, domain, range);
  9247. if (compiled) {
  9248. // Compiled function consists of simple expressions such as addition,
  9249. // subtraction, Math.max, and also contains 'var' and 'return'
  9250. // statements. See the generation in the PostScriptCompiler below.
  9251. /*jshint -W054 */
  9252. return new Function('src', 'srcOffset', 'dest', 'destOffset', compiled);
  9253. }
  9254. info('Unable to compile PS function');
  9255. var numOutputs = range.length >> 1;
  9256. var numInputs = domain.length >> 1;
  9257. var evaluator = new PostScriptEvaluator(code);
  9258. // Cache the values for a big speed up, the cache size is limited though
  9259. // since the number of possible values can be huge from a PS function.
  9260. var cache = {};
  9261. // The MAX_CACHE_SIZE is set to ~4x the maximum number of distinct values
  9262. // seen in our tests.
  9263. var MAX_CACHE_SIZE = 2048 * 4;
  9264. var cache_available = MAX_CACHE_SIZE;
  9265. var tmpBuf = new Float32Array(numInputs);
  9266. return function constructPostScriptFromIRResult(src, srcOffset,
  9267. dest, destOffset) {
  9268. var i, value;
  9269. var key = '';
  9270. var input = tmpBuf;
  9271. for (i = 0; i < numInputs; i++) {
  9272. value = src[srcOffset + i];
  9273. input[i] = value;
  9274. key += value + '_';
  9275. }
  9276. var cachedValue = cache[key];
  9277. if (cachedValue !== undefined) {
  9278. cachedValue.set(dest, destOffset);
  9279. return;
  9280. }
  9281. var output = new Float32Array(numOutputs);
  9282. var stack = evaluator.execute(input);
  9283. var stackIndex = stack.length - numOutputs;
  9284. for (i = 0; i < numOutputs; i++) {
  9285. value = stack[stackIndex + i];
  9286. var bound = range[i * 2];
  9287. if (value < bound) {
  9288. value = bound;
  9289. } else {
  9290. bound = range[i * 2 +1];
  9291. if (value > bound) {
  9292. value = bound;
  9293. }
  9294. }
  9295. output[i] = value;
  9296. }
  9297. if (cache_available > 0) {
  9298. cache_available--;
  9299. cache[key] = output;
  9300. }
  9301. output.set(dest, destOffset);
  9302. };
  9303. }
  9304. };
  9305. })();
  9306. function isPDFFunction(v) {
  9307. var fnDict;
  9308. if (typeof v !== 'object') {
  9309. return false;
  9310. } else if (isDict(v)) {
  9311. fnDict = v;
  9312. } else if (isStream(v)) {
  9313. fnDict = v.dict;
  9314. } else {
  9315. return false;
  9316. }
  9317. return fnDict.has('FunctionType');
  9318. }
  9319. var PostScriptStack = (function PostScriptStackClosure() {
  9320. var MAX_STACK_SIZE = 100;
  9321. function PostScriptStack(initialStack) {
  9322. this.stack = !initialStack ? [] :
  9323. Array.prototype.slice.call(initialStack, 0);
  9324. }
  9325. PostScriptStack.prototype = {
  9326. push: function PostScriptStack_push(value) {
  9327. if (this.stack.length >= MAX_STACK_SIZE) {
  9328. error('PostScript function stack overflow.');
  9329. }
  9330. this.stack.push(value);
  9331. },
  9332. pop: function PostScriptStack_pop() {
  9333. if (this.stack.length <= 0) {
  9334. error('PostScript function stack underflow.');
  9335. }
  9336. return this.stack.pop();
  9337. },
  9338. copy: function PostScriptStack_copy(n) {
  9339. if (this.stack.length + n >= MAX_STACK_SIZE) {
  9340. error('PostScript function stack overflow.');
  9341. }
  9342. var stack = this.stack;
  9343. for (var i = stack.length - n, j = n - 1; j >= 0; j--, i++) {
  9344. stack.push(stack[i]);
  9345. }
  9346. },
  9347. index: function PostScriptStack_index(n) {
  9348. this.push(this.stack[this.stack.length - n - 1]);
  9349. },
  9350. // rotate the last n stack elements p times
  9351. roll: function PostScriptStack_roll(n, p) {
  9352. var stack = this.stack;
  9353. var l = stack.length - n;
  9354. var r = stack.length - 1, c = l + (p - Math.floor(p / n) * n), i, j, t;
  9355. for (i = l, j = r; i < j; i++, j--) {
  9356. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  9357. }
  9358. for (i = l, j = c - 1; i < j; i++, j--) {
  9359. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  9360. }
  9361. for (i = c, j = r; i < j; i++, j--) {
  9362. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  9363. }
  9364. }
  9365. };
  9366. return PostScriptStack;
  9367. })();
  9368. var PostScriptEvaluator = (function PostScriptEvaluatorClosure() {
  9369. function PostScriptEvaluator(operators) {
  9370. this.operators = operators;
  9371. }
  9372. PostScriptEvaluator.prototype = {
  9373. execute: function PostScriptEvaluator_execute(initialStack) {
  9374. var stack = new PostScriptStack(initialStack);
  9375. var counter = 0;
  9376. var operators = this.operators;
  9377. var length = operators.length;
  9378. var operator, a, b;
  9379. while (counter < length) {
  9380. operator = operators[counter++];
  9381. if (typeof operator === 'number') {
  9382. // Operator is really an operand and should be pushed to the stack.
  9383. stack.push(operator);
  9384. continue;
  9385. }
  9386. switch (operator) {
  9387. // non standard ps operators
  9388. case 'jz': // jump if false
  9389. b = stack.pop();
  9390. a = stack.pop();
  9391. if (!a) {
  9392. counter = b;
  9393. }
  9394. break;
  9395. case 'j': // jump
  9396. a = stack.pop();
  9397. counter = a;
  9398. break;
  9399. // all ps operators in alphabetical order (excluding if/ifelse)
  9400. case 'abs':
  9401. a = stack.pop();
  9402. stack.push(Math.abs(a));
  9403. break;
  9404. case 'add':
  9405. b = stack.pop();
  9406. a = stack.pop();
  9407. stack.push(a + b);
  9408. break;
  9409. case 'and':
  9410. b = stack.pop();
  9411. a = stack.pop();
  9412. if (isBool(a) && isBool(b)) {
  9413. stack.push(a && b);
  9414. } else {
  9415. stack.push(a & b);
  9416. }
  9417. break;
  9418. case 'atan':
  9419. a = stack.pop();
  9420. stack.push(Math.atan(a));
  9421. break;
  9422. case 'bitshift':
  9423. b = stack.pop();
  9424. a = stack.pop();
  9425. if (a > 0) {
  9426. stack.push(a << b);
  9427. } else {
  9428. stack.push(a >> b);
  9429. }
  9430. break;
  9431. case 'ceiling':
  9432. a = stack.pop();
  9433. stack.push(Math.ceil(a));
  9434. break;
  9435. case 'copy':
  9436. a = stack.pop();
  9437. stack.copy(a);
  9438. break;
  9439. case 'cos':
  9440. a = stack.pop();
  9441. stack.push(Math.cos(a));
  9442. break;
  9443. case 'cvi':
  9444. a = stack.pop() | 0;
  9445. stack.push(a);
  9446. break;
  9447. case 'cvr':
  9448. // noop
  9449. break;
  9450. case 'div':
  9451. b = stack.pop();
  9452. a = stack.pop();
  9453. stack.push(a / b);
  9454. break;
  9455. case 'dup':
  9456. stack.copy(1);
  9457. break;
  9458. case 'eq':
  9459. b = stack.pop();
  9460. a = stack.pop();
  9461. stack.push(a === b);
  9462. break;
  9463. case 'exch':
  9464. stack.roll(2, 1);
  9465. break;
  9466. case 'exp':
  9467. b = stack.pop();
  9468. a = stack.pop();
  9469. stack.push(Math.pow(a, b));
  9470. break;
  9471. case 'false':
  9472. stack.push(false);
  9473. break;
  9474. case 'floor':
  9475. a = stack.pop();
  9476. stack.push(Math.floor(a));
  9477. break;
  9478. case 'ge':
  9479. b = stack.pop();
  9480. a = stack.pop();
  9481. stack.push(a >= b);
  9482. break;
  9483. case 'gt':
  9484. b = stack.pop();
  9485. a = stack.pop();
  9486. stack.push(a > b);
  9487. break;
  9488. case 'idiv':
  9489. b = stack.pop();
  9490. a = stack.pop();
  9491. stack.push((a / b) | 0);
  9492. break;
  9493. case 'index':
  9494. a = stack.pop();
  9495. stack.index(a);
  9496. break;
  9497. case 'le':
  9498. b = stack.pop();
  9499. a = stack.pop();
  9500. stack.push(a <= b);
  9501. break;
  9502. case 'ln':
  9503. a = stack.pop();
  9504. stack.push(Math.log(a));
  9505. break;
  9506. case 'log':
  9507. a = stack.pop();
  9508. stack.push(Math.log(a) / Math.LN10);
  9509. break;
  9510. case 'lt':
  9511. b = stack.pop();
  9512. a = stack.pop();
  9513. stack.push(a < b);
  9514. break;
  9515. case 'mod':
  9516. b = stack.pop();
  9517. a = stack.pop();
  9518. stack.push(a % b);
  9519. break;
  9520. case 'mul':
  9521. b = stack.pop();
  9522. a = stack.pop();
  9523. stack.push(a * b);
  9524. break;
  9525. case 'ne':
  9526. b = stack.pop();
  9527. a = stack.pop();
  9528. stack.push(a !== b);
  9529. break;
  9530. case 'neg':
  9531. a = stack.pop();
  9532. stack.push(-a);
  9533. break;
  9534. case 'not':
  9535. a = stack.pop();
  9536. if (isBool(a)) {
  9537. stack.push(!a);
  9538. } else {
  9539. stack.push(~a);
  9540. }
  9541. break;
  9542. case 'or':
  9543. b = stack.pop();
  9544. a = stack.pop();
  9545. if (isBool(a) && isBool(b)) {
  9546. stack.push(a || b);
  9547. } else {
  9548. stack.push(a | b);
  9549. }
  9550. break;
  9551. case 'pop':
  9552. stack.pop();
  9553. break;
  9554. case 'roll':
  9555. b = stack.pop();
  9556. a = stack.pop();
  9557. stack.roll(a, b);
  9558. break;
  9559. case 'round':
  9560. a = stack.pop();
  9561. stack.push(Math.round(a));
  9562. break;
  9563. case 'sin':
  9564. a = stack.pop();
  9565. stack.push(Math.sin(a));
  9566. break;
  9567. case 'sqrt':
  9568. a = stack.pop();
  9569. stack.push(Math.sqrt(a));
  9570. break;
  9571. case 'sub':
  9572. b = stack.pop();
  9573. a = stack.pop();
  9574. stack.push(a - b);
  9575. break;
  9576. case 'true':
  9577. stack.push(true);
  9578. break;
  9579. case 'truncate':
  9580. a = stack.pop();
  9581. a = a < 0 ? Math.ceil(a) : Math.floor(a);
  9582. stack.push(a);
  9583. break;
  9584. case 'xor':
  9585. b = stack.pop();
  9586. a = stack.pop();
  9587. if (isBool(a) && isBool(b)) {
  9588. stack.push(a !== b);
  9589. } else {
  9590. stack.push(a ^ b);
  9591. }
  9592. break;
  9593. default:
  9594. error('Unknown operator ' + operator);
  9595. break;
  9596. }
  9597. }
  9598. return stack.stack;
  9599. }
  9600. };
  9601. return PostScriptEvaluator;
  9602. })();
  9603. // Most of the PDFs functions consist of simple operations such as:
  9604. // roll, exch, sub, cvr, pop, index, dup, mul, if, gt, add.
  9605. //
  9606. // We can compile most of such programs, and at the same moment, we can
  9607. // optimize some expressions using basic math properties. Keeping track of
  9608. // min/max values will allow us to avoid extra Math.min/Math.max calls.
  9609. var PostScriptCompiler = (function PostScriptCompilerClosure() {
  9610. function AstNode(type) {
  9611. this.type = type;
  9612. }
  9613. AstNode.prototype.visit = function (visitor) {
  9614. throw new Error('abstract method');
  9615. };
  9616. function AstArgument(index, min, max) {
  9617. AstNode.call(this, 'args');
  9618. this.index = index;
  9619. this.min = min;
  9620. this.max = max;
  9621. }
  9622. AstArgument.prototype = Object.create(AstNode.prototype);
  9623. AstArgument.prototype.visit = function (visitor) {
  9624. visitor.visitArgument(this);
  9625. };
  9626. function AstLiteral(number) {
  9627. AstNode.call(this, 'literal');
  9628. this.number = number;
  9629. this.min = number;
  9630. this.max = number;
  9631. }
  9632. AstLiteral.prototype = Object.create(AstNode.prototype);
  9633. AstLiteral.prototype.visit = function (visitor) {
  9634. visitor.visitLiteral(this);
  9635. };
  9636. function AstBinaryOperation(op, arg1, arg2, min, max) {
  9637. AstNode.call(this, 'binary');
  9638. this.op = op;
  9639. this.arg1 = arg1;
  9640. this.arg2 = arg2;
  9641. this.min = min;
  9642. this.max = max;
  9643. }
  9644. AstBinaryOperation.prototype = Object.create(AstNode.prototype);
  9645. AstBinaryOperation.prototype.visit = function (visitor) {
  9646. visitor.visitBinaryOperation(this);
  9647. };
  9648. function AstMin(arg, max) {
  9649. AstNode.call(this, 'max');
  9650. this.arg = arg;
  9651. this.min = arg.min;
  9652. this.max = max;
  9653. }
  9654. AstMin.prototype = Object.create(AstNode.prototype);
  9655. AstMin.prototype.visit = function (visitor) {
  9656. visitor.visitMin(this);
  9657. };
  9658. function AstVariable(index, min, max) {
  9659. AstNode.call(this, 'var');
  9660. this.index = index;
  9661. this.min = min;
  9662. this.max = max;
  9663. }
  9664. AstVariable.prototype = Object.create(AstNode.prototype);
  9665. AstVariable.prototype.visit = function (visitor) {
  9666. visitor.visitVariable(this);
  9667. };
  9668. function AstVariableDefinition(variable, arg) {
  9669. AstNode.call(this, 'definition');
  9670. this.variable = variable;
  9671. this.arg = arg;
  9672. }
  9673. AstVariableDefinition.prototype = Object.create(AstNode.prototype);
  9674. AstVariableDefinition.prototype.visit = function (visitor) {
  9675. visitor.visitVariableDefinition(this);
  9676. };
  9677. function ExpressionBuilderVisitor() {
  9678. this.parts = [];
  9679. }
  9680. ExpressionBuilderVisitor.prototype = {
  9681. visitArgument: function (arg) {
  9682. this.parts.push('Math.max(', arg.min, ', Math.min(',
  9683. arg.max, ', src[srcOffset + ', arg.index, ']))');
  9684. },
  9685. visitVariable: function (variable) {
  9686. this.parts.push('v', variable.index);
  9687. },
  9688. visitLiteral: function (literal) {
  9689. this.parts.push(literal.number);
  9690. },
  9691. visitBinaryOperation: function (operation) {
  9692. this.parts.push('(');
  9693. operation.arg1.visit(this);
  9694. this.parts.push(' ', operation.op, ' ');
  9695. operation.arg2.visit(this);
  9696. this.parts.push(')');
  9697. },
  9698. visitVariableDefinition: function (definition) {
  9699. this.parts.push('var ');
  9700. definition.variable.visit(this);
  9701. this.parts.push(' = ');
  9702. definition.arg.visit(this);
  9703. this.parts.push(';');
  9704. },
  9705. visitMin: function (max) {
  9706. this.parts.push('Math.min(');
  9707. max.arg.visit(this);
  9708. this.parts.push(', ', max.max, ')');
  9709. },
  9710. toString: function () {
  9711. return this.parts.join('');
  9712. }
  9713. };
  9714. function buildAddOperation(num1, num2) {
  9715. if (num2.type === 'literal' && num2.number === 0) {
  9716. // optimization: second operand is 0
  9717. return num1;
  9718. }
  9719. if (num1.type === 'literal' && num1.number === 0) {
  9720. // optimization: first operand is 0
  9721. return num2;
  9722. }
  9723. if (num2.type === 'literal' && num1.type === 'literal') {
  9724. // optimization: operands operand are literals
  9725. return new AstLiteral(num1.number + num2.number);
  9726. }
  9727. return new AstBinaryOperation('+', num1, num2,
  9728. num1.min + num2.min, num1.max + num2.max);
  9729. }
  9730. function buildMulOperation(num1, num2) {
  9731. if (num2.type === 'literal') {
  9732. // optimization: second operands is a literal...
  9733. if (num2.number === 0) {
  9734. return new AstLiteral(0); // and it's 0
  9735. } else if (num2.number === 1) {
  9736. return num1; // and it's 1
  9737. } else if (num1.type === 'literal') {
  9738. // ... and first operands is a literal too
  9739. return new AstLiteral(num1.number * num2.number);
  9740. }
  9741. }
  9742. if (num1.type === 'literal') {
  9743. // optimization: first operands is a literal...
  9744. if (num1.number === 0) {
  9745. return new AstLiteral(0); // and it's 0
  9746. } else if (num1.number === 1) {
  9747. return num2; // and it's 1
  9748. }
  9749. }
  9750. var min = Math.min(num1.min * num2.min, num1.min * num2.max,
  9751. num1.max * num2.min, num1.max * num2.max);
  9752. var max = Math.max(num1.min * num2.min, num1.min * num2.max,
  9753. num1.max * num2.min, num1.max * num2.max);
  9754. return new AstBinaryOperation('*', num1, num2, min, max);
  9755. }
  9756. function buildSubOperation(num1, num2) {
  9757. if (num2.type === 'literal') {
  9758. // optimization: second operands is a literal...
  9759. if (num2.number === 0) {
  9760. return num1; // ... and it's 0
  9761. } else if (num1.type === 'literal') {
  9762. // ... and first operands is a literal too
  9763. return new AstLiteral(num1.number - num2.number);
  9764. }
  9765. }
  9766. if (num2.type === 'binary' && num2.op === '-' &&
  9767. num1.type === 'literal' && num1.number === 1 &&
  9768. num2.arg1.type === 'literal' && num2.arg1.number === 1) {
  9769. // optimization for case: 1 - (1 - x)
  9770. return num2.arg2;
  9771. }
  9772. return new AstBinaryOperation('-', num1, num2,
  9773. num1.min - num2.max, num1.max - num2.min);
  9774. }
  9775. function buildMinOperation(num1, max) {
  9776. if (num1.min >= max) {
  9777. // optimization: num1 min value is not less than required max
  9778. return new AstLiteral(max); // just returning max
  9779. } else if (num1.max <= max) {
  9780. // optimization: num1 max value is not greater than required max
  9781. return num1; // just returning an argument
  9782. }
  9783. return new AstMin(num1, max);
  9784. }
  9785. function PostScriptCompiler() {}
  9786. PostScriptCompiler.prototype = {
  9787. compile: function PostScriptCompiler_compile(code, domain, range) {
  9788. var stack = [];
  9789. var i, ii;
  9790. var instructions = [];
  9791. var inputSize = domain.length >> 1, outputSize = range.length >> 1;
  9792. var lastRegister = 0;
  9793. var n, j, min, max;
  9794. var num1, num2, ast1, ast2, tmpVar, item;
  9795. for (i = 0; i < inputSize; i++) {
  9796. stack.push(new AstArgument(i, domain[i * 2], domain[i * 2 + 1]));
  9797. }
  9798. for (i = 0, ii = code.length; i < ii; i++) {
  9799. item = code[i];
  9800. if (typeof item === 'number') {
  9801. stack.push(new AstLiteral(item));
  9802. continue;
  9803. }
  9804. switch (item) {
  9805. case 'add':
  9806. if (stack.length < 2) {
  9807. return null;
  9808. }
  9809. num2 = stack.pop();
  9810. num1 = stack.pop();
  9811. stack.push(buildAddOperation(num1, num2));
  9812. break;
  9813. case 'cvr':
  9814. if (stack.length < 1) {
  9815. return null;
  9816. }
  9817. break;
  9818. case 'mul':
  9819. if (stack.length < 2) {
  9820. return null;
  9821. }
  9822. num2 = stack.pop();
  9823. num1 = stack.pop();
  9824. stack.push(buildMulOperation(num1, num2));
  9825. break;
  9826. case 'sub':
  9827. if (stack.length < 2) {
  9828. return null;
  9829. }
  9830. num2 = stack.pop();
  9831. num1 = stack.pop();
  9832. stack.push(buildSubOperation(num1, num2));
  9833. break;
  9834. case 'exch':
  9835. if (stack.length < 2) {
  9836. return null;
  9837. }
  9838. ast1 = stack.pop(); ast2 = stack.pop();
  9839. stack.push(ast1, ast2);
  9840. break;
  9841. case 'pop':
  9842. if (stack.length < 1) {
  9843. return null;
  9844. }
  9845. stack.pop();
  9846. break;
  9847. case 'index':
  9848. if (stack.length < 1) {
  9849. return null;
  9850. }
  9851. num1 = stack.pop();
  9852. if (num1.type !== 'literal') {
  9853. return null;
  9854. }
  9855. n = num1.number;
  9856. if (n < 0 || (n|0) !== n || stack.length < n) {
  9857. return null;
  9858. }
  9859. ast1 = stack[stack.length - n - 1];
  9860. if (ast1.type === 'literal' || ast1.type === 'var') {
  9861. stack.push(ast1);
  9862. break;
  9863. }
  9864. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  9865. stack[stack.length - n - 1] = tmpVar;
  9866. stack.push(tmpVar);
  9867. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  9868. break;
  9869. case 'dup':
  9870. if (stack.length < 1) {
  9871. return null;
  9872. }
  9873. if (typeof code[i + 1] === 'number' && code[i + 2] === 'gt' &&
  9874. code[i + 3] === i + 7 && code[i + 4] === 'jz' &&
  9875. code[i + 5] === 'pop' && code[i + 6] === code[i + 1]) {
  9876. // special case of the commands sequence for the min operation
  9877. num1 = stack.pop();
  9878. stack.push(buildMinOperation(num1, code[i + 1]));
  9879. i += 6;
  9880. break;
  9881. }
  9882. ast1 = stack[stack.length - 1];
  9883. if (ast1.type === 'literal' || ast1.type === 'var') {
  9884. // we don't have to save into intermediate variable a literal or
  9885. // variable.
  9886. stack.push(ast1);
  9887. break;
  9888. }
  9889. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  9890. stack[stack.length - 1] = tmpVar;
  9891. stack.push(tmpVar);
  9892. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  9893. break;
  9894. case 'roll':
  9895. if (stack.length < 2) {
  9896. return null;
  9897. }
  9898. num2 = stack.pop();
  9899. num1 = stack.pop();
  9900. if (num2.type !== 'literal' || num1.type !== 'literal') {
  9901. // both roll operands must be numbers
  9902. return null;
  9903. }
  9904. j = num2.number;
  9905. n = num1.number;
  9906. if (n <= 0 || (n|0) !== n || (j|0) !== j || stack.length < n) {
  9907. // ... and integers
  9908. return null;
  9909. }
  9910. j = ((j % n) + n) % n;
  9911. if (j === 0) {
  9912. break; // just skipping -- there are nothing to rotate
  9913. }
  9914. Array.prototype.push.apply(stack,
  9915. stack.splice(stack.length - n, n - j));
  9916. break;
  9917. default:
  9918. return null; // unsupported operator
  9919. }
  9920. }
  9921. if (stack.length !== outputSize) {
  9922. return null;
  9923. }
  9924. var result = [];
  9925. instructions.forEach(function (instruction) {
  9926. var statementBuilder = new ExpressionBuilderVisitor();
  9927. instruction.visit(statementBuilder);
  9928. result.push(statementBuilder.toString());
  9929. });
  9930. stack.forEach(function (expr, i) {
  9931. var statementBuilder = new ExpressionBuilderVisitor();
  9932. expr.visit(statementBuilder);
  9933. var min = range[i * 2], max = range[i * 2 + 1];
  9934. var out = [statementBuilder.toString()];
  9935. if (min > expr.min) {
  9936. out.unshift('Math.max(', min, ', ');
  9937. out.push(')');
  9938. }
  9939. if (max < expr.max) {
  9940. out.unshift('Math.min(', max, ', ');
  9941. out.push(')');
  9942. }
  9943. out.unshift('dest[destOffset + ', i, '] = ');
  9944. out.push(';');
  9945. result.push(out.join(''));
  9946. });
  9947. return result.join('\n');
  9948. }
  9949. };
  9950. return PostScriptCompiler;
  9951. })();
  9952. var ColorSpace = (function ColorSpaceClosure() {
  9953. // Constructor should define this.numComps, this.defaultColor, this.name
  9954. function ColorSpace() {
  9955. error('should not call ColorSpace constructor');
  9956. }
  9957. ColorSpace.prototype = {
  9958. /**
  9959. * Converts the color value to the RGB color. The color components are
  9960. * located in the src array starting from the srcOffset. Returns the array
  9961. * of the rgb components, each value ranging from [0,255].
  9962. */
  9963. getRgb: function ColorSpace_getRgb(src, srcOffset) {
  9964. var rgb = new Uint8Array(3);
  9965. this.getRgbItem(src, srcOffset, rgb, 0);
  9966. return rgb;
  9967. },
  9968. /**
  9969. * Converts the color value to the RGB color, similar to the getRgb method.
  9970. * The result placed into the dest array starting from the destOffset.
  9971. */
  9972. getRgbItem: function ColorSpace_getRgbItem(src, srcOffset,
  9973. dest, destOffset) {
  9974. error('Should not call ColorSpace.getRgbItem');
  9975. },
  9976. /**
  9977. * Converts the specified number of the color values to the RGB colors.
  9978. * The colors are located in the src array starting from the srcOffset.
  9979. * The result is placed into the dest array starting from the destOffset.
  9980. * The src array items shall be in [0,2^bits) range, the dest array items
  9981. * will be in [0,255] range. alpha01 indicates how many alpha components
  9982. * there are in the dest array; it will be either 0 (RGB array) or 1 (RGBA
  9983. * array).
  9984. */
  9985. getRgbBuffer: function ColorSpace_getRgbBuffer(src, srcOffset, count,
  9986. dest, destOffset, bits,
  9987. alpha01) {
  9988. error('Should not call ColorSpace.getRgbBuffer');
  9989. },
  9990. /**
  9991. * Determines the number of bytes required to store the result of the
  9992. * conversion done by the getRgbBuffer method. As in getRgbBuffer,
  9993. * |alpha01| is either 0 (RGB output) or 1 (RGBA output).
  9994. */
  9995. getOutputLength: function ColorSpace_getOutputLength(inputLength,
  9996. alpha01) {
  9997. error('Should not call ColorSpace.getOutputLength');
  9998. },
  9999. /**
  10000. * Returns true if source data will be equal the result/output data.
  10001. */
  10002. isPassthrough: function ColorSpace_isPassthrough(bits) {
  10003. return false;
  10004. },
  10005. /**
  10006. * Fills in the RGB colors in the destination buffer. alpha01 indicates
  10007. * how many alpha components there are in the dest array; it will be either
  10008. * 0 (RGB array) or 1 (RGBA array).
  10009. */
  10010. fillRgb: function ColorSpace_fillRgb(dest, originalWidth,
  10011. originalHeight, width, height,
  10012. actualHeight, bpc, comps, alpha01) {
  10013. var count = originalWidth * originalHeight;
  10014. var rgbBuf = null;
  10015. var numComponentColors = 1 << bpc;
  10016. var needsResizing = originalHeight !== height || originalWidth !== width;
  10017. var i, ii;
  10018. if (this.isPassthrough(bpc)) {
  10019. rgbBuf = comps;
  10020. } else if (this.numComps === 1 && count > numComponentColors &&
  10021. this.name !== 'DeviceGray' && this.name !== 'DeviceRGB') {
  10022. // Optimization: create a color map when there is just one component and
  10023. // we are converting more colors than the size of the color map. We
  10024. // don't build the map if the colorspace is gray or rgb since those
  10025. // methods are faster than building a map. This mainly offers big speed
  10026. // ups for indexed and alternate colorspaces.
  10027. //
  10028. // TODO it may be worth while to cache the color map. While running
  10029. // testing I never hit a cache so I will leave that out for now (perhaps
  10030. // we are reparsing colorspaces too much?).
  10031. var allColors = bpc <= 8 ? new Uint8Array(numComponentColors) :
  10032. new Uint16Array(numComponentColors);
  10033. var key;
  10034. for (i = 0; i < numComponentColors; i++) {
  10035. allColors[i] = i;
  10036. }
  10037. var colorMap = new Uint8Array(numComponentColors * 3);
  10038. this.getRgbBuffer(allColors, 0, numComponentColors, colorMap, 0, bpc,
  10039. /* alpha01 = */ 0);
  10040. var destPos, rgbPos;
  10041. if (!needsResizing) {
  10042. // Fill in the RGB values directly into |dest|.
  10043. destPos = 0;
  10044. for (i = 0; i < count; ++i) {
  10045. key = comps[i] * 3;
  10046. dest[destPos++] = colorMap[key];
  10047. dest[destPos++] = colorMap[key + 1];
  10048. dest[destPos++] = colorMap[key + 2];
  10049. destPos += alpha01;
  10050. }
  10051. } else {
  10052. rgbBuf = new Uint8Array(count * 3);
  10053. rgbPos = 0;
  10054. for (i = 0; i < count; ++i) {
  10055. key = comps[i] * 3;
  10056. rgbBuf[rgbPos++] = colorMap[key];
  10057. rgbBuf[rgbPos++] = colorMap[key + 1];
  10058. rgbBuf[rgbPos++] = colorMap[key + 2];
  10059. }
  10060. }
  10061. } else {
  10062. if (!needsResizing) {
  10063. // Fill in the RGB values directly into |dest|.
  10064. this.getRgbBuffer(comps, 0, width * actualHeight, dest, 0, bpc,
  10065. alpha01);
  10066. } else {
  10067. rgbBuf = new Uint8Array(count * 3);
  10068. this.getRgbBuffer(comps, 0, count, rgbBuf, 0, bpc,
  10069. /* alpha01 = */ 0);
  10070. }
  10071. }
  10072. if (rgbBuf) {
  10073. if (needsResizing) {
  10074. PDFImage.resize(rgbBuf, bpc, 3, originalWidth, originalHeight, width,
  10075. height, dest, alpha01);
  10076. } else {
  10077. rgbPos = 0;
  10078. destPos = 0;
  10079. for (i = 0, ii = width * actualHeight; i < ii; i++) {
  10080. dest[destPos++] = rgbBuf[rgbPos++];
  10081. dest[destPos++] = rgbBuf[rgbPos++];
  10082. dest[destPos++] = rgbBuf[rgbPos++];
  10083. destPos += alpha01;
  10084. }
  10085. }
  10086. }
  10087. },
  10088. /**
  10089. * True if the colorspace has components in the default range of [0, 1].
  10090. * This should be true for all colorspaces except for lab color spaces
  10091. * which are [0,100], [-128, 127], [-128, 127].
  10092. */
  10093. usesZeroToOneRange: true
  10094. };
  10095. ColorSpace.parse = function ColorSpace_parse(cs, xref, res) {
  10096. var IR = ColorSpace.parseToIR(cs, xref, res);
  10097. if (IR instanceof AlternateCS) {
  10098. return IR;
  10099. }
  10100. return ColorSpace.fromIR(IR);
  10101. };
  10102. ColorSpace.fromIR = function ColorSpace_fromIR(IR) {
  10103. var name = isArray(IR) ? IR[0] : IR;
  10104. var whitePoint, blackPoint;
  10105. switch (name) {
  10106. case 'DeviceGrayCS':
  10107. return this.singletons.gray;
  10108. case 'DeviceRgbCS':
  10109. return this.singletons.rgb;
  10110. case 'DeviceCmykCS':
  10111. return this.singletons.cmyk;
  10112. case 'CalGrayCS':
  10113. whitePoint = IR[1].WhitePoint;
  10114. blackPoint = IR[1].BlackPoint;
  10115. var gamma = IR[1].Gamma;
  10116. return new CalGrayCS(whitePoint, blackPoint, gamma);
  10117. case 'PatternCS':
  10118. var basePatternCS = IR[1];
  10119. if (basePatternCS) {
  10120. basePatternCS = ColorSpace.fromIR(basePatternCS);
  10121. }
  10122. return new PatternCS(basePatternCS);
  10123. case 'IndexedCS':
  10124. var baseIndexedCS = IR[1];
  10125. var hiVal = IR[2];
  10126. var lookup = IR[3];
  10127. return new IndexedCS(ColorSpace.fromIR(baseIndexedCS), hiVal, lookup);
  10128. case 'AlternateCS':
  10129. var numComps = IR[1];
  10130. var alt = IR[2];
  10131. var tintFnIR = IR[3];
  10132. return new AlternateCS(numComps, ColorSpace.fromIR(alt),
  10133. PDFFunction.fromIR(tintFnIR));
  10134. case 'LabCS':
  10135. whitePoint = IR[1].WhitePoint;
  10136. blackPoint = IR[1].BlackPoint;
  10137. var range = IR[1].Range;
  10138. return new LabCS(whitePoint, blackPoint, range);
  10139. default:
  10140. error('Unkown name ' + name);
  10141. }
  10142. return null;
  10143. };
  10144. ColorSpace.parseToIR = function ColorSpace_parseToIR(cs, xref, res) {
  10145. if (isName(cs)) {
  10146. var colorSpaces = res.get('ColorSpace');
  10147. if (isDict(colorSpaces)) {
  10148. var refcs = colorSpaces.get(cs.name);
  10149. if (refcs) {
  10150. cs = refcs;
  10151. }
  10152. }
  10153. }
  10154. cs = xref.fetchIfRef(cs);
  10155. var mode;
  10156. if (isName(cs)) {
  10157. mode = cs.name;
  10158. this.mode = mode;
  10159. switch (mode) {
  10160. case 'DeviceGray':
  10161. case 'G':
  10162. return 'DeviceGrayCS';
  10163. case 'DeviceRGB':
  10164. case 'RGB':
  10165. return 'DeviceRgbCS';
  10166. case 'DeviceCMYK':
  10167. case 'CMYK':
  10168. return 'DeviceCmykCS';
  10169. case 'Pattern':
  10170. return ['PatternCS', null];
  10171. default:
  10172. error('unrecognized colorspace ' + mode);
  10173. }
  10174. } else if (isArray(cs)) {
  10175. mode = cs[0].name;
  10176. this.mode = mode;
  10177. var numComps, params;
  10178. switch (mode) {
  10179. case 'DeviceGray':
  10180. case 'G':
  10181. return 'DeviceGrayCS';
  10182. case 'DeviceRGB':
  10183. case 'RGB':
  10184. return 'DeviceRgbCS';
  10185. case 'DeviceCMYK':
  10186. case 'CMYK':
  10187. return 'DeviceCmykCS';
  10188. case 'CalGray':
  10189. params = cs[1].getAll();
  10190. return ['CalGrayCS', params];
  10191. case 'CalRGB':
  10192. return 'DeviceRgbCS';
  10193. case 'ICCBased':
  10194. var stream = xref.fetchIfRef(cs[1]);
  10195. var dict = stream.dict;
  10196. numComps = dict.get('N');
  10197. if (numComps === 1) {
  10198. return 'DeviceGrayCS';
  10199. } else if (numComps === 3) {
  10200. return 'DeviceRgbCS';
  10201. } else if (numComps === 4) {
  10202. return 'DeviceCmykCS';
  10203. }
  10204. break;
  10205. case 'Pattern':
  10206. var basePatternCS = cs[1];
  10207. if (basePatternCS) {
  10208. basePatternCS = ColorSpace.parseToIR(basePatternCS, xref, res);
  10209. }
  10210. return ['PatternCS', basePatternCS];
  10211. case 'Indexed':
  10212. case 'I':
  10213. var baseIndexedCS = ColorSpace.parseToIR(cs[1], xref, res);
  10214. var hiVal = cs[2] + 1;
  10215. var lookup = xref.fetchIfRef(cs[3]);
  10216. if (isStream(lookup)) {
  10217. lookup = lookup.getBytes();
  10218. }
  10219. return ['IndexedCS', baseIndexedCS, hiVal, lookup];
  10220. case 'Separation':
  10221. case 'DeviceN':
  10222. var name = cs[1];
  10223. numComps = 1;
  10224. if (isName(name)) {
  10225. numComps = 1;
  10226. } else if (isArray(name)) {
  10227. numComps = name.length;
  10228. }
  10229. var alt = ColorSpace.parseToIR(cs[2], xref, res);
  10230. var tintFnIR = PDFFunction.getIR(xref, xref.fetchIfRef(cs[3]));
  10231. return ['AlternateCS', numComps, alt, tintFnIR];
  10232. case 'Lab':
  10233. params = cs[1].getAll();
  10234. return ['LabCS', params];
  10235. default:
  10236. error('unimplemented color space object "' + mode + '"');
  10237. }
  10238. } else {
  10239. error('unrecognized color space object: "' + cs + '"');
  10240. }
  10241. return null;
  10242. };
  10243. /**
  10244. * Checks if a decode map matches the default decode map for a color space.
  10245. * This handles the general decode maps where there are two values per
  10246. * component. e.g. [0, 1, 0, 1, 0, 1] for a RGB color.
  10247. * This does not handle Lab, Indexed, or Pattern decode maps since they are
  10248. * slightly different.
  10249. * @param {Array} decode Decode map (usually from an image).
  10250. * @param {Number} n Number of components the color space has.
  10251. */
  10252. ColorSpace.isDefaultDecode = function ColorSpace_isDefaultDecode(decode, n) {
  10253. if (!decode) {
  10254. return true;
  10255. }
  10256. if (n * 2 !== decode.length) {
  10257. warn('The decode map is not the correct length');
  10258. return true;
  10259. }
  10260. for (var i = 0, ii = decode.length; i < ii; i += 2) {
  10261. if (decode[i] !== 0 || decode[i + 1] !== 1) {
  10262. return false;
  10263. }
  10264. }
  10265. return true;
  10266. };
  10267. ColorSpace.singletons = {
  10268. get gray() {
  10269. return shadow(this, 'gray', new DeviceGrayCS());
  10270. },
  10271. get rgb() {
  10272. return shadow(this, 'rgb', new DeviceRgbCS());
  10273. },
  10274. get cmyk() {
  10275. return shadow(this, 'cmyk', new DeviceCmykCS());
  10276. }
  10277. };
  10278. return ColorSpace;
  10279. })();
  10280. /**
  10281. * Alternate color space handles both Separation and DeviceN color spaces. A
  10282. * Separation color space is actually just a DeviceN with one color component.
  10283. * Both color spaces use a tinting function to convert colors to a base color
  10284. * space.
  10285. */
  10286. var AlternateCS = (function AlternateCSClosure() {
  10287. function AlternateCS(numComps, base, tintFn) {
  10288. this.name = 'Alternate';
  10289. this.numComps = numComps;
  10290. this.defaultColor = new Float32Array(numComps);
  10291. for (var i = 0; i < numComps; ++i) {
  10292. this.defaultColor[i] = 1;
  10293. }
  10294. this.base = base;
  10295. this.tintFn = tintFn;
  10296. this.tmpBuf = new Float32Array(base.numComps);
  10297. }
  10298. AlternateCS.prototype = {
  10299. getRgb: ColorSpace.prototype.getRgb,
  10300. getRgbItem: function AlternateCS_getRgbItem(src, srcOffset,
  10301. dest, destOffset) {
  10302. var tmpBuf = this.tmpBuf;
  10303. this.tintFn(src, srcOffset, tmpBuf, 0);
  10304. this.base.getRgbItem(tmpBuf, 0, dest, destOffset);
  10305. },
  10306. getRgbBuffer: function AlternateCS_getRgbBuffer(src, srcOffset, count,
  10307. dest, destOffset, bits,
  10308. alpha01) {
  10309. var tintFn = this.tintFn;
  10310. var base = this.base;
  10311. var scale = 1 / ((1 << bits) - 1);
  10312. var baseNumComps = base.numComps;
  10313. var usesZeroToOneRange = base.usesZeroToOneRange;
  10314. var isPassthrough = (base.isPassthrough(8) || !usesZeroToOneRange) &&
  10315. alpha01 === 0;
  10316. var pos = isPassthrough ? destOffset : 0;
  10317. var baseBuf = isPassthrough ? dest : new Uint8Array(baseNumComps * count);
  10318. var numComps = this.numComps;
  10319. var scaled = new Float32Array(numComps);
  10320. var tinted = new Float32Array(baseNumComps);
  10321. var i, j;
  10322. if (usesZeroToOneRange) {
  10323. for (i = 0; i < count; i++) {
  10324. for (j = 0; j < numComps; j++) {
  10325. scaled[j] = src[srcOffset++] * scale;
  10326. }
  10327. tintFn(scaled, 0, tinted, 0);
  10328. for (j = 0; j < baseNumComps; j++) {
  10329. baseBuf[pos++] = tinted[j] * 255;
  10330. }
  10331. }
  10332. } else {
  10333. for (i = 0; i < count; i++) {
  10334. for (j = 0; j < numComps; j++) {
  10335. scaled[j] = src[srcOffset++] * scale;
  10336. }
  10337. tintFn(scaled, 0, tinted, 0);
  10338. base.getRgbItem(tinted, 0, baseBuf, pos);
  10339. pos += baseNumComps;
  10340. }
  10341. }
  10342. if (!isPassthrough) {
  10343. base.getRgbBuffer(baseBuf, 0, count, dest, destOffset, 8, alpha01);
  10344. }
  10345. },
  10346. getOutputLength: function AlternateCS_getOutputLength(inputLength,
  10347. alpha01) {
  10348. return this.base.getOutputLength(inputLength *
  10349. this.base.numComps / this.numComps,
  10350. alpha01);
  10351. },
  10352. isPassthrough: ColorSpace.prototype.isPassthrough,
  10353. fillRgb: ColorSpace.prototype.fillRgb,
  10354. isDefaultDecode: function AlternateCS_isDefaultDecode(decodeMap) {
  10355. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  10356. },
  10357. usesZeroToOneRange: true
  10358. };
  10359. return AlternateCS;
  10360. })();
  10361. var PatternCS = (function PatternCSClosure() {
  10362. function PatternCS(baseCS) {
  10363. this.name = 'Pattern';
  10364. this.base = baseCS;
  10365. }
  10366. PatternCS.prototype = {};
  10367. return PatternCS;
  10368. })();
  10369. var IndexedCS = (function IndexedCSClosure() {
  10370. function IndexedCS(base, highVal, lookup) {
  10371. this.name = 'Indexed';
  10372. this.numComps = 1;
  10373. this.defaultColor = new Uint8Array([0]);
  10374. this.base = base;
  10375. this.highVal = highVal;
  10376. var baseNumComps = base.numComps;
  10377. var length = baseNumComps * highVal;
  10378. var lookupArray;
  10379. if (isStream(lookup)) {
  10380. lookupArray = new Uint8Array(length);
  10381. var bytes = lookup.getBytes(length);
  10382. lookupArray.set(bytes);
  10383. } else if (isString(lookup)) {
  10384. lookupArray = new Uint8Array(length);
  10385. for (var i = 0; i < length; ++i) {
  10386. lookupArray[i] = lookup.charCodeAt(i);
  10387. }
  10388. } else if (lookup instanceof Uint8Array || lookup instanceof Array) {
  10389. lookupArray = lookup;
  10390. } else {
  10391. error('Unrecognized lookup table: ' + lookup);
  10392. }
  10393. this.lookup = lookupArray;
  10394. }
  10395. IndexedCS.prototype = {
  10396. getRgb: ColorSpace.prototype.getRgb,
  10397. getRgbItem: function IndexedCS_getRgbItem(src, srcOffset,
  10398. dest, destOffset) {
  10399. var numComps = this.base.numComps;
  10400. var start = src[srcOffset] * numComps;
  10401. this.base.getRgbItem(this.lookup, start, dest, destOffset);
  10402. },
  10403. getRgbBuffer: function IndexedCS_getRgbBuffer(src, srcOffset, count,
  10404. dest, destOffset, bits,
  10405. alpha01) {
  10406. var base = this.base;
  10407. var numComps = base.numComps;
  10408. var outputDelta = base.getOutputLength(numComps, alpha01);
  10409. var lookup = this.lookup;
  10410. for (var i = 0; i < count; ++i) {
  10411. var lookupPos = src[srcOffset++] * numComps;
  10412. base.getRgbBuffer(lookup, lookupPos, 1, dest, destOffset, 8, alpha01);
  10413. destOffset += outputDelta;
  10414. }
  10415. },
  10416. getOutputLength: function IndexedCS_getOutputLength(inputLength, alpha01) {
  10417. return this.base.getOutputLength(inputLength * this.base.numComps,
  10418. alpha01);
  10419. },
  10420. isPassthrough: ColorSpace.prototype.isPassthrough,
  10421. fillRgb: ColorSpace.prototype.fillRgb,
  10422. isDefaultDecode: function IndexedCS_isDefaultDecode(decodeMap) {
  10423. // indexed color maps shouldn't be changed
  10424. return true;
  10425. },
  10426. usesZeroToOneRange: true
  10427. };
  10428. return IndexedCS;
  10429. })();
  10430. var DeviceGrayCS = (function DeviceGrayCSClosure() {
  10431. function DeviceGrayCS() {
  10432. this.name = 'DeviceGray';
  10433. this.numComps = 1;
  10434. this.defaultColor = new Float32Array([0]);
  10435. }
  10436. DeviceGrayCS.prototype = {
  10437. getRgb: ColorSpace.prototype.getRgb,
  10438. getRgbItem: function DeviceGrayCS_getRgbItem(src, srcOffset,
  10439. dest, destOffset) {
  10440. var c = (src[srcOffset] * 255) | 0;
  10441. c = c < 0 ? 0 : c > 255 ? 255 : c;
  10442. dest[destOffset] = dest[destOffset + 1] = dest[destOffset + 2] = c;
  10443. },
  10444. getRgbBuffer: function DeviceGrayCS_getRgbBuffer(src, srcOffset, count,
  10445. dest, destOffset, bits,
  10446. alpha01) {
  10447. var scale = 255 / ((1 << bits) - 1);
  10448. var j = srcOffset, q = destOffset;
  10449. for (var i = 0; i < count; ++i) {
  10450. var c = (scale * src[j++]) | 0;
  10451. dest[q++] = c;
  10452. dest[q++] = c;
  10453. dest[q++] = c;
  10454. q += alpha01;
  10455. }
  10456. },
  10457. getOutputLength: function DeviceGrayCS_getOutputLength(inputLength,
  10458. alpha01) {
  10459. return inputLength * (3 + alpha01);
  10460. },
  10461. isPassthrough: ColorSpace.prototype.isPassthrough,
  10462. fillRgb: ColorSpace.prototype.fillRgb,
  10463. isDefaultDecode: function DeviceGrayCS_isDefaultDecode(decodeMap) {
  10464. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  10465. },
  10466. usesZeroToOneRange: true
  10467. };
  10468. return DeviceGrayCS;
  10469. })();
  10470. var DeviceRgbCS = (function DeviceRgbCSClosure() {
  10471. function DeviceRgbCS() {
  10472. this.name = 'DeviceRGB';
  10473. this.numComps = 3;
  10474. this.defaultColor = new Float32Array([0, 0, 0]);
  10475. }
  10476. DeviceRgbCS.prototype = {
  10477. getRgb: ColorSpace.prototype.getRgb,
  10478. getRgbItem: function DeviceRgbCS_getRgbItem(src, srcOffset,
  10479. dest, destOffset) {
  10480. var r = (src[srcOffset] * 255) | 0;
  10481. var g = (src[srcOffset + 1] * 255) | 0;
  10482. var b = (src[srcOffset + 2] * 255) | 0;
  10483. dest[destOffset] = r < 0 ? 0 : r > 255 ? 255 : r;
  10484. dest[destOffset + 1] = g < 0 ? 0 : g > 255 ? 255 : g;
  10485. dest[destOffset + 2] = b < 0 ? 0 : b > 255 ? 255 : b;
  10486. },
  10487. getRgbBuffer: function DeviceRgbCS_getRgbBuffer(src, srcOffset, count,
  10488. dest, destOffset, bits,
  10489. alpha01) {
  10490. if (bits === 8 && alpha01 === 0) {
  10491. dest.set(src.subarray(srcOffset, srcOffset + count * 3), destOffset);
  10492. return;
  10493. }
  10494. var scale = 255 / ((1 << bits) - 1);
  10495. var j = srcOffset, q = destOffset;
  10496. for (var i = 0; i < count; ++i) {
  10497. dest[q++] = (scale * src[j++]) | 0;
  10498. dest[q++] = (scale * src[j++]) | 0;
  10499. dest[q++] = (scale * src[j++]) | 0;
  10500. q += alpha01;
  10501. }
  10502. },
  10503. getOutputLength: function DeviceRgbCS_getOutputLength(inputLength,
  10504. alpha01) {
  10505. return (inputLength * (3 + alpha01) / 3) | 0;
  10506. },
  10507. isPassthrough: function DeviceRgbCS_isPassthrough(bits) {
  10508. return bits === 8;
  10509. },
  10510. fillRgb: ColorSpace.prototype.fillRgb,
  10511. isDefaultDecode: function DeviceRgbCS_isDefaultDecode(decodeMap) {
  10512. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  10513. },
  10514. usesZeroToOneRange: true
  10515. };
  10516. return DeviceRgbCS;
  10517. })();
  10518. var DeviceCmykCS = (function DeviceCmykCSClosure() {
  10519. // The coefficients below was found using numerical analysis: the method of
  10520. // steepest descent for the sum((f_i - color_value_i)^2) for r/g/b colors,
  10521. // where color_value is the tabular value from the table of sampled RGB colors
  10522. // from CMYK US Web Coated (SWOP) colorspace, and f_i is the corresponding
  10523. // CMYK color conversion using the estimation below:
  10524. // f(A, B,.. N) = Acc+Bcm+Ccy+Dck+c+Fmm+Gmy+Hmk+Im+Jyy+Kyk+Ly+Mkk+Nk+255
  10525. function convertToRgb(src, srcOffset, srcScale, dest, destOffset) {
  10526. var c = src[srcOffset + 0] * srcScale;
  10527. var m = src[srcOffset + 1] * srcScale;
  10528. var y = src[srcOffset + 2] * srcScale;
  10529. var k = src[srcOffset + 3] * srcScale;
  10530. var r =
  10531. (c * (-4.387332384609988 * c + 54.48615194189176 * m +
  10532. 18.82290502165302 * y + 212.25662451639585 * k +
  10533. -285.2331026137004) +
  10534. m * (1.7149763477362134 * m - 5.6096736904047315 * y +
  10535. -17.873870861415444 * k - 5.497006427196366) +
  10536. y * (-2.5217340131683033 * y - 21.248923337353073 * k +
  10537. 17.5119270841813) +
  10538. k * (-21.86122147463605 * k - 189.48180835922747) + 255) | 0;
  10539. var g =
  10540. (c * (8.841041422036149 * c + 60.118027045597366 * m +
  10541. 6.871425592049007 * y + 31.159100130055922 * k +
  10542. -79.2970844816548) +
  10543. m * (-15.310361306967817 * m + 17.575251261109482 * y +
  10544. 131.35250912493976 * k - 190.9453302588951) +
  10545. y * (4.444339102852739 * y + 9.8632861493405 * k - 24.86741582555878) +
  10546. k * (-20.737325471181034 * k - 187.80453709719578) + 255) | 0;
  10547. var b =
  10548. (c * (0.8842522430003296 * c + 8.078677503112928 * m +
  10549. 30.89978309703729 * y - 0.23883238689178934 * k +
  10550. -14.183576799673286) +
  10551. m * (10.49593273432072 * m + 63.02378494754052 * y +
  10552. 50.606957656360734 * k - 112.23884253719248) +
  10553. y * (0.03296041114873217 * y + 115.60384449646641 * k +
  10554. -193.58209356861505) +
  10555. k * (-22.33816807309886 * k - 180.12613974708367) + 255) | 0;
  10556. dest[destOffset] = r > 255 ? 255 : r < 0 ? 0 : r;
  10557. dest[destOffset + 1] = g > 255 ? 255 : g < 0 ? 0 : g;
  10558. dest[destOffset + 2] = b > 255 ? 255 : b < 0 ? 0 : b;
  10559. }
  10560. function DeviceCmykCS() {
  10561. this.name = 'DeviceCMYK';
  10562. this.numComps = 4;
  10563. this.defaultColor = new Float32Array([0, 0, 0, 1]);
  10564. }
  10565. DeviceCmykCS.prototype = {
  10566. getRgb: ColorSpace.prototype.getRgb,
  10567. getRgbItem: function DeviceCmykCS_getRgbItem(src, srcOffset,
  10568. dest, destOffset) {
  10569. convertToRgb(src, srcOffset, 1, dest, destOffset);
  10570. },
  10571. getRgbBuffer: function DeviceCmykCS_getRgbBuffer(src, srcOffset, count,
  10572. dest, destOffset, bits,
  10573. alpha01) {
  10574. var scale = 1 / ((1 << bits) - 1);
  10575. for (var i = 0; i < count; i++) {
  10576. convertToRgb(src, srcOffset, scale, dest, destOffset);
  10577. srcOffset += 4;
  10578. destOffset += 3 + alpha01;
  10579. }
  10580. },
  10581. getOutputLength: function DeviceCmykCS_getOutputLength(inputLength,
  10582. alpha01) {
  10583. return (inputLength / 4 * (3 + alpha01)) | 0;
  10584. },
  10585. isPassthrough: ColorSpace.prototype.isPassthrough,
  10586. fillRgb: ColorSpace.prototype.fillRgb,
  10587. isDefaultDecode: function DeviceCmykCS_isDefaultDecode(decodeMap) {
  10588. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  10589. },
  10590. usesZeroToOneRange: true
  10591. };
  10592. return DeviceCmykCS;
  10593. })();
  10594. //
  10595. // CalGrayCS: Based on "PDF Reference, Sixth Ed", p.245
  10596. //
  10597. var CalGrayCS = (function CalGrayCSClosure() {
  10598. function CalGrayCS(whitePoint, blackPoint, gamma) {
  10599. this.name = 'CalGray';
  10600. this.numComps = 1;
  10601. this.defaultColor = new Float32Array([0]);
  10602. if (!whitePoint) {
  10603. error('WhitePoint missing - required for color space CalGray');
  10604. }
  10605. blackPoint = blackPoint || [0, 0, 0];
  10606. gamma = gamma || 1;
  10607. // Translate arguments to spec variables.
  10608. this.XW = whitePoint[0];
  10609. this.YW = whitePoint[1];
  10610. this.ZW = whitePoint[2];
  10611. this.XB = blackPoint[0];
  10612. this.YB = blackPoint[1];
  10613. this.ZB = blackPoint[2];
  10614. this.G = gamma;
  10615. // Validate variables as per spec.
  10616. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  10617. error('Invalid WhitePoint components for ' + this.name +
  10618. ', no fallback available');
  10619. }
  10620. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  10621. info('Invalid BlackPoint for ' + this.name + ', falling back to default');
  10622. this.XB = this.YB = this.ZB = 0;
  10623. }
  10624. if (this.XB !== 0 || this.YB !== 0 || this.ZB !== 0) {
  10625. warn(this.name + ', BlackPoint: XB: ' + this.XB + ', YB: ' + this.YB +
  10626. ', ZB: ' + this.ZB + ', only default values are supported.');
  10627. }
  10628. if (this.G < 1) {
  10629. info('Invalid Gamma: ' + this.G + ' for ' + this.name +
  10630. ', falling back to default');
  10631. this.G = 1;
  10632. }
  10633. }
  10634. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  10635. // A represents a gray component of a calibrated gray space.
  10636. // A <---> AG in the spec
  10637. var A = src[srcOffset] * scale;
  10638. var AG = Math.pow(A, cs.G);
  10639. // Computes L as per spec. ( = cs.YW * AG )
  10640. // Except if other than default BlackPoint values are used.
  10641. var L = cs.YW * AG;
  10642. // http://www.poynton.com/notes/colour_and_gamma/ColorFAQ.html, Ch 4.
  10643. // Convert values to rgb range [0, 255].
  10644. var val = Math.max(295.8 * Math.pow(L, 0.333333333333333333) - 40.8, 0) | 0;
  10645. dest[destOffset] = val;
  10646. dest[destOffset + 1] = val;
  10647. dest[destOffset + 2] = val;
  10648. }
  10649. CalGrayCS.prototype = {
  10650. getRgb: ColorSpace.prototype.getRgb,
  10651. getRgbItem: function CalGrayCS_getRgbItem(src, srcOffset,
  10652. dest, destOffset) {
  10653. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  10654. },
  10655. getRgbBuffer: function CalGrayCS_getRgbBuffer(src, srcOffset, count,
  10656. dest, destOffset, bits,
  10657. alpha01) {
  10658. var scale = 1 / ((1 << bits) - 1);
  10659. for (var i = 0; i < count; ++i) {
  10660. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  10661. srcOffset += 1;
  10662. destOffset += 3 + alpha01;
  10663. }
  10664. },
  10665. getOutputLength: function CalGrayCS_getOutputLength(inputLength, alpha01) {
  10666. return inputLength * (3 + alpha01);
  10667. },
  10668. isPassthrough: ColorSpace.prototype.isPassthrough,
  10669. fillRgb: ColorSpace.prototype.fillRgb,
  10670. isDefaultDecode: function CalGrayCS_isDefaultDecode(decodeMap) {
  10671. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  10672. },
  10673. usesZeroToOneRange: true
  10674. };
  10675. return CalGrayCS;
  10676. })();
  10677. //
  10678. // LabCS: Based on "PDF Reference, Sixth Ed", p.250
  10679. //
  10680. var LabCS = (function LabCSClosure() {
  10681. function LabCS(whitePoint, blackPoint, range) {
  10682. this.name = 'Lab';
  10683. this.numComps = 3;
  10684. this.defaultColor = new Float32Array([0, 0, 0]);
  10685. if (!whitePoint) {
  10686. error('WhitePoint missing - required for color space Lab');
  10687. }
  10688. blackPoint = blackPoint || [0, 0, 0];
  10689. range = range || [-100, 100, -100, 100];
  10690. // Translate args to spec variables
  10691. this.XW = whitePoint[0];
  10692. this.YW = whitePoint[1];
  10693. this.ZW = whitePoint[2];
  10694. this.amin = range[0];
  10695. this.amax = range[1];
  10696. this.bmin = range[2];
  10697. this.bmax = range[3];
  10698. // These are here just for completeness - the spec doesn't offer any
  10699. // formulas that use BlackPoint in Lab
  10700. this.XB = blackPoint[0];
  10701. this.YB = blackPoint[1];
  10702. this.ZB = blackPoint[2];
  10703. // Validate vars as per spec
  10704. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  10705. error('Invalid WhitePoint components, no fallback available');
  10706. }
  10707. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  10708. info('Invalid BlackPoint, falling back to default');
  10709. this.XB = this.YB = this.ZB = 0;
  10710. }
  10711. if (this.amin > this.amax || this.bmin > this.bmax) {
  10712. info('Invalid Range, falling back to defaults');
  10713. this.amin = -100;
  10714. this.amax = 100;
  10715. this.bmin = -100;
  10716. this.bmax = 100;
  10717. }
  10718. }
  10719. // Function g(x) from spec
  10720. function fn_g(x) {
  10721. if (x >= 6 / 29) {
  10722. return x * x * x;
  10723. } else {
  10724. return (108 / 841) * (x - 4 / 29);
  10725. }
  10726. }
  10727. function decode(value, high1, low2, high2) {
  10728. return low2 + (value) * (high2 - low2) / (high1);
  10729. }
  10730. // If decoding is needed maxVal should be 2^bits per component - 1.
  10731. function convertToRgb(cs, src, srcOffset, maxVal, dest, destOffset) {
  10732. // XXX: Lab input is in the range of [0, 100], [amin, amax], [bmin, bmax]
  10733. // not the usual [0, 1]. If a command like setFillColor is used the src
  10734. // values will already be within the correct range. However, if we are
  10735. // converting an image we have to map the values to the correct range given
  10736. // above.
  10737. // Ls,as,bs <---> L*,a*,b* in the spec
  10738. var Ls = src[srcOffset];
  10739. var as = src[srcOffset + 1];
  10740. var bs = src[srcOffset + 2];
  10741. if (maxVal !== false) {
  10742. Ls = decode(Ls, maxVal, 0, 100);
  10743. as = decode(as, maxVal, cs.amin, cs.amax);
  10744. bs = decode(bs, maxVal, cs.bmin, cs.bmax);
  10745. }
  10746. // Adjust limits of 'as' and 'bs'
  10747. as = as > cs.amax ? cs.amax : as < cs.amin ? cs.amin : as;
  10748. bs = bs > cs.bmax ? cs.bmax : bs < cs.bmin ? cs.bmin : bs;
  10749. // Computes intermediate variables X,Y,Z as per spec
  10750. var M = (Ls + 16) / 116;
  10751. var L = M + (as / 500);
  10752. var N = M - (bs / 200);
  10753. var X = cs.XW * fn_g(L);
  10754. var Y = cs.YW * fn_g(M);
  10755. var Z = cs.ZW * fn_g(N);
  10756. var r, g, b;
  10757. // Using different conversions for D50 and D65 white points,
  10758. // per http://www.color.org/srgb.pdf
  10759. if (cs.ZW < 1) {
  10760. // Assuming D50 (X=0.9642, Y=1.00, Z=0.8249)
  10761. r = X * 3.1339 + Y * -1.6170 + Z * -0.4906;
  10762. g = X * -0.9785 + Y * 1.9160 + Z * 0.0333;
  10763. b = X * 0.0720 + Y * -0.2290 + Z * 1.4057;
  10764. } else {
  10765. // Assuming D65 (X=0.9505, Y=1.00, Z=1.0888)
  10766. r = X * 3.2406 + Y * -1.5372 + Z * -0.4986;
  10767. g = X * -0.9689 + Y * 1.8758 + Z * 0.0415;
  10768. b = X * 0.0557 + Y * -0.2040 + Z * 1.0570;
  10769. }
  10770. // clamp color values to [0,1] range then convert to [0,255] range.
  10771. dest[destOffset] = r <= 0 ? 0 : r >= 1 ? 255 : Math.sqrt(r) * 255 | 0;
  10772. dest[destOffset + 1] = g <= 0 ? 0 : g >= 1 ? 255 : Math.sqrt(g) * 255 | 0;
  10773. dest[destOffset + 2] = b <= 0 ? 0 : b >= 1 ? 255 : Math.sqrt(b) * 255 | 0;
  10774. }
  10775. LabCS.prototype = {
  10776. getRgb: ColorSpace.prototype.getRgb,
  10777. getRgbItem: function LabCS_getRgbItem(src, srcOffset, dest, destOffset) {
  10778. convertToRgb(this, src, srcOffset, false, dest, destOffset);
  10779. },
  10780. getRgbBuffer: function LabCS_getRgbBuffer(src, srcOffset, count,
  10781. dest, destOffset, bits,
  10782. alpha01) {
  10783. var maxVal = (1 << bits) - 1;
  10784. for (var i = 0; i < count; i++) {
  10785. convertToRgb(this, src, srcOffset, maxVal, dest, destOffset);
  10786. srcOffset += 3;
  10787. destOffset += 3 + alpha01;
  10788. }
  10789. },
  10790. getOutputLength: function LabCS_getOutputLength(inputLength, alpha01) {
  10791. return (inputLength * (3 + alpha01) / 3) | 0;
  10792. },
  10793. isPassthrough: ColorSpace.prototype.isPassthrough,
  10794. fillRgb: ColorSpace.prototype.fillRgb,
  10795. isDefaultDecode: function LabCS_isDefaultDecode(decodeMap) {
  10796. // XXX: Decoding is handled with the lab conversion because of the strange
  10797. // ranges that are used.
  10798. return true;
  10799. },
  10800. usesZeroToOneRange: false
  10801. };
  10802. return LabCS;
  10803. })();
  10804. var ARCFourCipher = (function ARCFourCipherClosure() {
  10805. function ARCFourCipher(key) {
  10806. this.a = 0;
  10807. this.b = 0;
  10808. var s = new Uint8Array(256);
  10809. var i, j = 0, tmp, keyLength = key.length;
  10810. for (i = 0; i < 256; ++i) {
  10811. s[i] = i;
  10812. }
  10813. for (i = 0; i < 256; ++i) {
  10814. tmp = s[i];
  10815. j = (j + tmp + key[i % keyLength]) & 0xFF;
  10816. s[i] = s[j];
  10817. s[j] = tmp;
  10818. }
  10819. this.s = s;
  10820. }
  10821. ARCFourCipher.prototype = {
  10822. encryptBlock: function ARCFourCipher_encryptBlock(data) {
  10823. var i, n = data.length, tmp, tmp2;
  10824. var a = this.a, b = this.b, s = this.s;
  10825. var output = new Uint8Array(n);
  10826. for (i = 0; i < n; ++i) {
  10827. a = (a + 1) & 0xFF;
  10828. tmp = s[a];
  10829. b = (b + tmp) & 0xFF;
  10830. tmp2 = s[b];
  10831. s[a] = tmp2;
  10832. s[b] = tmp;
  10833. output[i] = data[i] ^ s[(tmp + tmp2) & 0xFF];
  10834. }
  10835. this.a = a;
  10836. this.b = b;
  10837. return output;
  10838. }
  10839. };
  10840. ARCFourCipher.prototype.decryptBlock = ARCFourCipher.prototype.encryptBlock;
  10841. return ARCFourCipher;
  10842. })();
  10843. var calculateMD5 = (function calculateMD5Closure() {
  10844. var r = new Uint8Array([
  10845. 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22,
  10846. 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20,
  10847. 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23,
  10848. 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21]);
  10849. var k = new Int32Array([
  10850. -680876936, -389564586, 606105819, -1044525330, -176418897, 1200080426,
  10851. -1473231341, -45705983, 1770035416, -1958414417, -42063, -1990404162,
  10852. 1804603682, -40341101, -1502002290, 1236535329, -165796510, -1069501632,
  10853. 643717713, -373897302, -701558691, 38016083, -660478335, -405537848,
  10854. 568446438, -1019803690, -187363961, 1163531501, -1444681467, -51403784,
  10855. 1735328473, -1926607734, -378558, -2022574463, 1839030562, -35309556,
  10856. -1530992060, 1272893353, -155497632, -1094730640, 681279174, -358537222,
  10857. -722521979, 76029189, -640364487, -421815835, 530742520, -995338651,
  10858. -198630844, 1126891415, -1416354905, -57434055, 1700485571, -1894986606,
  10859. -1051523, -2054922799, 1873313359, -30611744, -1560198380, 1309151649,
  10860. -145523070, -1120210379, 718787259, -343485551]);
  10861. function hash(data, offset, length) {
  10862. var h0 = 1732584193, h1 = -271733879, h2 = -1732584194, h3 = 271733878;
  10863. // pre-processing
  10864. var paddedLength = (length + 72) & ~63; // data + 9 extra bytes
  10865. var padded = new Uint8Array(paddedLength);
  10866. var i, j, n;
  10867. for (i = 0; i < length; ++i) {
  10868. padded[i] = data[offset++];
  10869. }
  10870. padded[i++] = 0x80;
  10871. n = paddedLength - 8;
  10872. while (i < n) {
  10873. padded[i++] = 0;
  10874. }
  10875. padded[i++] = (length << 3) & 0xFF;
  10876. padded[i++] = (length >> 5) & 0xFF;
  10877. padded[i++] = (length >> 13) & 0xFF;
  10878. padded[i++] = (length >> 21) & 0xFF;
  10879. padded[i++] = (length >>> 29) & 0xFF;
  10880. padded[i++] = 0;
  10881. padded[i++] = 0;
  10882. padded[i++] = 0;
  10883. var w = new Int32Array(16);
  10884. for (i = 0; i < paddedLength;) {
  10885. for (j = 0; j < 16; ++j, i += 4) {
  10886. w[j] = (padded[i] | (padded[i + 1] << 8) |
  10887. (padded[i + 2] << 16) | (padded[i + 3] << 24));
  10888. }
  10889. var a = h0, b = h1, c = h2, d = h3, f, g;
  10890. for (j = 0; j < 64; ++j) {
  10891. if (j < 16) {
  10892. f = (b & c) | ((~b) & d);
  10893. g = j;
  10894. } else if (j < 32) {
  10895. f = (d & b) | ((~d) & c);
  10896. g = (5 * j + 1) & 15;
  10897. } else if (j < 48) {
  10898. f = b ^ c ^ d;
  10899. g = (3 * j + 5) & 15;
  10900. } else {
  10901. f = c ^ (b | (~d));
  10902. g = (7 * j) & 15;
  10903. }
  10904. var tmp = d, rotateArg = (a + f + k[j] + w[g]) | 0, rotate = r[j];
  10905. d = c;
  10906. c = b;
  10907. b = (b + ((rotateArg << rotate) | (rotateArg >>> (32 - rotate)))) | 0;
  10908. a = tmp;
  10909. }
  10910. h0 = (h0 + a) | 0;
  10911. h1 = (h1 + b) | 0;
  10912. h2 = (h2 + c) | 0;
  10913. h3 = (h3 + d) | 0;
  10914. }
  10915. return new Uint8Array([
  10916. h0 & 0xFF, (h0 >> 8) & 0xFF, (h0 >> 16) & 0xFF, (h0 >>> 24) & 0xFF,
  10917. h1 & 0xFF, (h1 >> 8) & 0xFF, (h1 >> 16) & 0xFF, (h1 >>> 24) & 0xFF,
  10918. h2 & 0xFF, (h2 >> 8) & 0xFF, (h2 >> 16) & 0xFF, (h2 >>> 24) & 0xFF,
  10919. h3 & 0xFF, (h3 >> 8) & 0xFF, (h3 >> 16) & 0xFF, (h3 >>> 24) & 0xFF
  10920. ]);
  10921. }
  10922. return hash;
  10923. })();
  10924. var Word64 = (function Word64Closure() {
  10925. function Word64(highInteger, lowInteger) {
  10926. this.high = highInteger | 0;
  10927. this.low = lowInteger | 0;
  10928. }
  10929. Word64.prototype = {
  10930. and: function Word64_and(word) {
  10931. this.high &= word.high;
  10932. this.low &= word.low;
  10933. },
  10934. xor: function Word64_xor(word) {
  10935. this.high ^= word.high;
  10936. this.low ^= word.low;
  10937. },
  10938. or: function Word64_or(word) {
  10939. this.high |= word.high;
  10940. this.low |= word.low;
  10941. },
  10942. shiftRight: function Word64_shiftRight(places) {
  10943. if (places >= 32) {
  10944. this.low = (this.high >>> (places - 32)) | 0;
  10945. this.high = 0;
  10946. } else {
  10947. this.low = (this.low >>> places) | (this.high << (32 - places));
  10948. this.high = (this.high >>> places) | 0;
  10949. }
  10950. },
  10951. shiftLeft: function Word64_shiftLeft(places) {
  10952. if (places >= 32) {
  10953. this.high = this.low << (places - 32);
  10954. this.low = 0;
  10955. } else {
  10956. this.high = (this.high << places) | (this.low >>> (32 - places));
  10957. this.low = this.low << places;
  10958. }
  10959. },
  10960. rotateRight: function Word64_rotateRight(places) {
  10961. var low, high;
  10962. if (places & 32) {
  10963. high = this.low;
  10964. low = this.high;
  10965. } else {
  10966. low = this.low;
  10967. high = this.high;
  10968. }
  10969. places &= 31;
  10970. this.low = (low >>> places) | (high << (32 - places));
  10971. this.high = (high >>> places) | (low << (32 - places));
  10972. },
  10973. not: function Word64_not() {
  10974. this.high = ~this.high;
  10975. this.low = ~this.low;
  10976. },
  10977. add: function Word64_add(word) {
  10978. var lowAdd = (this.low >>> 0) + (word.low >>> 0);
  10979. var highAdd = (this.high >>> 0) + (word.high >>> 0);
  10980. if (lowAdd > 0xFFFFFFFF) {
  10981. highAdd += 1;
  10982. }
  10983. this.low = lowAdd | 0;
  10984. this.high = highAdd | 0;
  10985. },
  10986. copyTo: function Word64_copyTo(bytes, offset) {
  10987. bytes[offset] = (this.high >>> 24) & 0xFF;
  10988. bytes[offset + 1] = (this.high >> 16) & 0xFF;
  10989. bytes[offset + 2] = (this.high >> 8) & 0xFF;
  10990. bytes[offset + 3] = this.high & 0xFF;
  10991. bytes[offset + 4] = (this.low >>> 24) & 0xFF;
  10992. bytes[offset + 5] = (this.low >> 16) & 0xFF;
  10993. bytes[offset + 6] = (this.low >> 8) & 0xFF;
  10994. bytes[offset + 7] = this.low & 0xFF;
  10995. },
  10996. assign: function Word64_assign(word) {
  10997. this.high = word.high;
  10998. this.low = word.low;
  10999. }
  11000. };
  11001. return Word64;
  11002. })();
  11003. var calculateSHA256 = (function calculateSHA256Closure() {
  11004. function rotr(x, n) {
  11005. return (x >>> n) | (x << 32 - n);
  11006. }
  11007. function ch(x, y, z) {
  11008. return (x & y) ^ (~x & z);
  11009. }
  11010. function maj(x, y, z) {
  11011. return (x & y) ^ (x & z) ^ (y & z);
  11012. }
  11013. function sigma(x) {
  11014. return rotr(x, 2) ^ rotr(x, 13) ^ rotr(x, 22);
  11015. }
  11016. function sigmaPrime(x) {
  11017. return rotr(x, 6) ^ rotr(x, 11) ^ rotr(x, 25);
  11018. }
  11019. function littleSigma(x) {
  11020. return rotr(x, 7) ^ rotr(x, 18) ^ x >>> 3;
  11021. }
  11022. function littleSigmaPrime(x) {
  11023. return rotr(x, 17) ^ rotr(x, 19) ^ x >>> 10;
  11024. }
  11025. var k = [0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
  11026. 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
  11027. 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
  11028. 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
  11029. 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
  11030. 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
  11031. 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
  11032. 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
  11033. 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
  11034. 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
  11035. 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
  11036. 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
  11037. 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
  11038. 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
  11039. 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
  11040. 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2];
  11041. function hash(data, offset, length) {
  11042. // initial hash values
  11043. var h0 = 0x6a09e667, h1 = 0xbb67ae85, h2 = 0x3c6ef372,
  11044. h3 = 0xa54ff53a, h4 = 0x510e527f, h5 = 0x9b05688c,
  11045. h6 = 0x1f83d9ab, h7 = 0x5be0cd19;
  11046. // pre-processing
  11047. var paddedLength = Math.ceil((length + 9) / 64) * 64;
  11048. var padded = new Uint8Array(paddedLength);
  11049. var i, j, n;
  11050. for (i = 0; i < length; ++i) {
  11051. padded[i] = data[offset++];
  11052. }
  11053. padded[i++] = 0x80;
  11054. n = paddedLength - 8;
  11055. while (i < n) {
  11056. padded[i++] = 0;
  11057. }
  11058. padded[i++] = 0;
  11059. padded[i++] = 0;
  11060. padded[i++] = 0;
  11061. padded[i++] = (length >>> 29) & 0xFF;
  11062. padded[i++] = (length >> 21) & 0xFF;
  11063. padded[i++] = (length >> 13) & 0xFF;
  11064. padded[i++] = (length >> 5) & 0xFF;
  11065. padded[i++] = (length << 3) & 0xFF;
  11066. var w = new Uint32Array(64);
  11067. // for each 512 bit block
  11068. for (i = 0; i < paddedLength;) {
  11069. for (j = 0; j < 16; ++j) {
  11070. w[j] = (padded[i] << 24 | (padded[i + 1] << 16) |
  11071. (padded[i + 2] << 8) | (padded[i + 3]));
  11072. i += 4;
  11073. }
  11074. for (j = 16; j < 64; ++j) {
  11075. w[j] = littleSigmaPrime(w[j - 2]) + w[j - 7] +
  11076. littleSigma(w[j - 15]) + w[j - 16] | 0;
  11077. }
  11078. var a = h0, b = h1, c = h2, d = h3, e = h4,
  11079. f = h5, g = h6, h = h7, t1, t2;
  11080. for (j = 0; j < 64; ++j) {
  11081. t1 = h + sigmaPrime(e) + ch(e, f, g) + k[j] + w[j];
  11082. t2 = sigma(a) + maj(a, b, c);
  11083. h = g;
  11084. g = f;
  11085. f = e;
  11086. e = (d + t1) | 0;
  11087. d = c;
  11088. c = b;
  11089. b = a;
  11090. a = (t1 + t2) | 0;
  11091. }
  11092. h0 = (h0 + a) | 0;
  11093. h1 = (h1 + b) | 0;
  11094. h2 = (h2 + c) | 0;
  11095. h3 = (h3 + d) | 0;
  11096. h4 = (h4 + e) | 0;
  11097. h5 = (h5 + f) | 0;
  11098. h6 = (h6 + g) | 0;
  11099. h7 = (h7 + h) | 0;
  11100. }
  11101. return new Uint8Array([
  11102. (h0 >> 24) & 0xFF, (h0 >> 16) & 0xFF, (h0 >> 8) & 0xFF, (h0) & 0xFF,
  11103. (h1 >> 24) & 0xFF, (h1 >> 16) & 0xFF, (h1 >> 8) & 0xFF, (h1) & 0xFF,
  11104. (h2 >> 24) & 0xFF, (h2 >> 16) & 0xFF, (h2 >> 8) & 0xFF, (h2) & 0xFF,
  11105. (h3 >> 24) & 0xFF, (h3 >> 16) & 0xFF, (h3 >> 8) & 0xFF, (h3) & 0xFF,
  11106. (h4 >> 24) & 0xFF, (h4 >> 16) & 0xFF, (h4 >> 8) & 0xFF, (h4) & 0xFF,
  11107. (h5 >> 24) & 0xFF, (h5 >> 16) & 0xFF, (h5 >> 8) & 0xFF, (h5) & 0xFF,
  11108. (h6 >> 24) & 0xFF, (h6 >> 16) & 0xFF, (h6 >> 8) & 0xFF, (h6) & 0xFF,
  11109. (h7 >> 24) & 0xFF, (h7 >> 16) & 0xFF, (h7 >> 8) & 0xFF, (h7) & 0xFF
  11110. ]);
  11111. }
  11112. return hash;
  11113. })();
  11114. var calculateSHA512 = (function calculateSHA512Closure() {
  11115. function ch(result, x, y, z, tmp) {
  11116. result.assign(x);
  11117. result.and(y);
  11118. tmp.assign(x);
  11119. tmp.not();
  11120. tmp.and(z);
  11121. result.xor(tmp);
  11122. }
  11123. function maj(result, x, y, z, tmp) {
  11124. result.assign(x);
  11125. result.and(y);
  11126. tmp.assign(x);
  11127. tmp.and(z);
  11128. result.xor(tmp);
  11129. tmp.assign(y);
  11130. tmp.and(z);
  11131. result.xor(tmp);
  11132. }
  11133. function sigma(result, x, tmp) {
  11134. result.assign(x);
  11135. result.rotateRight(28);
  11136. tmp.assign(x);
  11137. tmp.rotateRight(34);
  11138. result.xor(tmp);
  11139. tmp.assign(x);
  11140. tmp.rotateRight(39);
  11141. result.xor(tmp);
  11142. }
  11143. function sigmaPrime(result, x, tmp) {
  11144. result.assign(x);
  11145. result.rotateRight(14);
  11146. tmp.assign(x);
  11147. tmp.rotateRight(18);
  11148. result.xor(tmp);
  11149. tmp.assign(x);
  11150. tmp.rotateRight(41);
  11151. result.xor(tmp);
  11152. }
  11153. function littleSigma(result, x, tmp) {
  11154. result.assign(x);
  11155. result.rotateRight(1);
  11156. tmp.assign(x);
  11157. tmp.rotateRight(8);
  11158. result.xor(tmp);
  11159. tmp.assign(x);
  11160. tmp.shiftRight(7);
  11161. result.xor(tmp);
  11162. }
  11163. function littleSigmaPrime(result, x, tmp) {
  11164. result.assign(x);
  11165. result.rotateRight(19);
  11166. tmp.assign(x);
  11167. tmp.rotateRight(61);
  11168. result.xor(tmp);
  11169. tmp.assign(x);
  11170. tmp.shiftRight(6);
  11171. result.xor(tmp);
  11172. }
  11173. var k = [
  11174. new Word64(0x428a2f98, 0xd728ae22), new Word64(0x71374491, 0x23ef65cd),
  11175. new Word64(0xb5c0fbcf, 0xec4d3b2f), new Word64(0xe9b5dba5, 0x8189dbbc),
  11176. new Word64(0x3956c25b, 0xf348b538), new Word64(0x59f111f1, 0xb605d019),
  11177. new Word64(0x923f82a4, 0xaf194f9b), new Word64(0xab1c5ed5, 0xda6d8118),
  11178. new Word64(0xd807aa98, 0xa3030242), new Word64(0x12835b01, 0x45706fbe),
  11179. new Word64(0x243185be, 0x4ee4b28c), new Word64(0x550c7dc3, 0xd5ffb4e2),
  11180. new Word64(0x72be5d74, 0xf27b896f), new Word64(0x80deb1fe, 0x3b1696b1),
  11181. new Word64(0x9bdc06a7, 0x25c71235), new Word64(0xc19bf174, 0xcf692694),
  11182. new Word64(0xe49b69c1, 0x9ef14ad2), new Word64(0xefbe4786, 0x384f25e3),
  11183. new Word64(0x0fc19dc6, 0x8b8cd5b5), new Word64(0x240ca1cc, 0x77ac9c65),
  11184. new Word64(0x2de92c6f, 0x592b0275), new Word64(0x4a7484aa, 0x6ea6e483),
  11185. new Word64(0x5cb0a9dc, 0xbd41fbd4), new Word64(0x76f988da, 0x831153b5),
  11186. new Word64(0x983e5152, 0xee66dfab), new Word64(0xa831c66d, 0x2db43210),
  11187. new Word64(0xb00327c8, 0x98fb213f), new Word64(0xbf597fc7, 0xbeef0ee4),
  11188. new Word64(0xc6e00bf3, 0x3da88fc2), new Word64(0xd5a79147, 0x930aa725),
  11189. new Word64(0x06ca6351, 0xe003826f), new Word64(0x14292967, 0x0a0e6e70),
  11190. new Word64(0x27b70a85, 0x46d22ffc), new Word64(0x2e1b2138, 0x5c26c926),
  11191. new Word64(0x4d2c6dfc, 0x5ac42aed), new Word64(0x53380d13, 0x9d95b3df),
  11192. new Word64(0x650a7354, 0x8baf63de), new Word64(0x766a0abb, 0x3c77b2a8),
  11193. new Word64(0x81c2c92e, 0x47edaee6), new Word64(0x92722c85, 0x1482353b),
  11194. new Word64(0xa2bfe8a1, 0x4cf10364), new Word64(0xa81a664b, 0xbc423001),
  11195. new Word64(0xc24b8b70, 0xd0f89791), new Word64(0xc76c51a3, 0x0654be30),
  11196. new Word64(0xd192e819, 0xd6ef5218), new Word64(0xd6990624, 0x5565a910),
  11197. new Word64(0xf40e3585, 0x5771202a), new Word64(0x106aa070, 0x32bbd1b8),
  11198. new Word64(0x19a4c116, 0xb8d2d0c8), new Word64(0x1e376c08, 0x5141ab53),
  11199. new Word64(0x2748774c, 0xdf8eeb99), new Word64(0x34b0bcb5, 0xe19b48a8),
  11200. new Word64(0x391c0cb3, 0xc5c95a63), new Word64(0x4ed8aa4a, 0xe3418acb),
  11201. new Word64(0x5b9cca4f, 0x7763e373), new Word64(0x682e6ff3, 0xd6b2b8a3),
  11202. new Word64(0x748f82ee, 0x5defb2fc), new Word64(0x78a5636f, 0x43172f60),
  11203. new Word64(0x84c87814, 0xa1f0ab72), new Word64(0x8cc70208, 0x1a6439ec),
  11204. new Word64(0x90befffa, 0x23631e28), new Word64(0xa4506ceb, 0xde82bde9),
  11205. new Word64(0xbef9a3f7, 0xb2c67915), new Word64(0xc67178f2, 0xe372532b),
  11206. new Word64(0xca273ece, 0xea26619c), new Word64(0xd186b8c7, 0x21c0c207),
  11207. new Word64(0xeada7dd6, 0xcde0eb1e), new Word64(0xf57d4f7f, 0xee6ed178),
  11208. new Word64(0x06f067aa, 0x72176fba), new Word64(0x0a637dc5, 0xa2c898a6),
  11209. new Word64(0x113f9804, 0xbef90dae), new Word64(0x1b710b35, 0x131c471b),
  11210. new Word64(0x28db77f5, 0x23047d84), new Word64(0x32caab7b, 0x40c72493),
  11211. new Word64(0x3c9ebe0a, 0x15c9bebc), new Word64(0x431d67c4, 0x9c100d4c),
  11212. new Word64(0x4cc5d4be, 0xcb3e42b6), new Word64(0x597f299c, 0xfc657e2a),
  11213. new Word64(0x5fcb6fab, 0x3ad6faec), new Word64(0x6c44198c, 0x4a475817)];
  11214. function hash(data, offset, length, mode384) {
  11215. mode384 = !!mode384;
  11216. // initial hash values
  11217. var h0, h1, h2, h3, h4, h5, h6, h7;
  11218. if (!mode384) {
  11219. h0 = new Word64(0x6a09e667, 0xf3bcc908);
  11220. h1 = new Word64(0xbb67ae85, 0x84caa73b);
  11221. h2 = new Word64(0x3c6ef372, 0xfe94f82b);
  11222. h3 = new Word64(0xa54ff53a, 0x5f1d36f1);
  11223. h4 = new Word64(0x510e527f, 0xade682d1);
  11224. h5 = new Word64(0x9b05688c, 0x2b3e6c1f);
  11225. h6 = new Word64(0x1f83d9ab, 0xfb41bd6b);
  11226. h7 = new Word64(0x5be0cd19, 0x137e2179);
  11227. }
  11228. else {
  11229. // SHA384 is exactly the same
  11230. // except with different starting values and a trimmed result
  11231. h0 = new Word64(0xcbbb9d5d, 0xc1059ed8);
  11232. h1 = new Word64(0x629a292a, 0x367cd507);
  11233. h2 = new Word64(0x9159015a, 0x3070dd17);
  11234. h3 = new Word64(0x152fecd8, 0xf70e5939);
  11235. h4 = new Word64(0x67332667, 0xffc00b31);
  11236. h5 = new Word64(0x8eb44a87, 0x68581511);
  11237. h6 = new Word64(0xdb0c2e0d, 0x64f98fa7);
  11238. h7 = new Word64(0x47b5481d, 0xbefa4fa4);
  11239. }
  11240. // pre-processing
  11241. var paddedLength = Math.ceil((length + 17) / 128) * 128;
  11242. var padded = new Uint8Array(paddedLength);
  11243. var i, j, n;
  11244. for (i = 0; i < length; ++i) {
  11245. padded[i] = data[offset++];
  11246. }
  11247. padded[i++] = 0x80;
  11248. n = paddedLength - 16;
  11249. while (i < n) {
  11250. padded[i++] = 0;
  11251. }
  11252. padded[i++] = 0;
  11253. padded[i++] = 0;
  11254. padded[i++] = 0;
  11255. padded[i++] = 0;
  11256. padded[i++] = 0;
  11257. padded[i++] = 0;
  11258. padded[i++] = 0;
  11259. padded[i++] = 0;
  11260. padded[i++] = 0;
  11261. padded[i++] = 0;
  11262. padded[i++] = 0;
  11263. padded[i++] = (length >>> 29) & 0xFF;
  11264. padded[i++] = (length >> 21) & 0xFF;
  11265. padded[i++] = (length >> 13) & 0xFF;
  11266. padded[i++] = (length >> 5) & 0xFF;
  11267. padded[i++] = (length << 3) & 0xFF;
  11268. var w = new Array(80);
  11269. for (i = 0; i < 80; i++) {
  11270. w[i] = new Word64(0, 0);
  11271. }
  11272. var a = new Word64(0, 0), b = new Word64(0, 0), c = new Word64(0, 0);
  11273. var d = new Word64(0, 0), e = new Word64(0, 0), f = new Word64(0, 0);
  11274. var g = new Word64(0, 0), h = new Word64(0, 0);
  11275. var t1 = new Word64(0, 0), t2 = new Word64(0, 0);
  11276. var tmp1 = new Word64(0, 0), tmp2 = new Word64(0, 0), tmp3;
  11277. // for each 1024 bit block
  11278. for (i = 0; i < paddedLength;) {
  11279. for (j = 0; j < 16; ++j) {
  11280. w[j].high = (padded[i] << 24) | (padded[i + 1] << 16) |
  11281. (padded[i + 2] << 8) | (padded[i + 3]);
  11282. w[j].low = (padded[i + 4]) << 24 | (padded[i + 5]) << 16 |
  11283. (padded[i + 6]) << 8 | (padded[i + 7]);
  11284. i += 8;
  11285. }
  11286. for (j = 16; j < 80; ++j) {
  11287. tmp3 = w[j];
  11288. littleSigmaPrime(tmp3, w[j - 2], tmp2);
  11289. tmp3.add(w[j - 7]);
  11290. littleSigma(tmp1, w[j - 15], tmp2);
  11291. tmp3.add(tmp1);
  11292. tmp3.add(w[j - 16]);
  11293. }
  11294. a.assign(h0); b.assign(h1); c.assign(h2); d.assign(h3);
  11295. e.assign(h4); f.assign(h5); g.assign(h6); h.assign(h7);
  11296. for (j = 0; j < 80; ++j) {
  11297. t1.assign(h);
  11298. sigmaPrime(tmp1, e, tmp2);
  11299. t1.add(tmp1);
  11300. ch(tmp1, e, f, g, tmp2);
  11301. t1.add(tmp1);
  11302. t1.add(k[j]);
  11303. t1.add(w[j]);
  11304. sigma(t2, a, tmp2);
  11305. maj(tmp1, a, b, c, tmp2);
  11306. t2.add(tmp1);
  11307. tmp3 = h;
  11308. h = g;
  11309. g = f;
  11310. f = e;
  11311. d.add(t1);
  11312. e = d;
  11313. d = c;
  11314. c = b;
  11315. b = a;
  11316. tmp3.assign(t1);
  11317. tmp3.add(t2);
  11318. a = tmp3;
  11319. }
  11320. h0.add(a);
  11321. h1.add(b);
  11322. h2.add(c);
  11323. h3.add(d);
  11324. h4.add(e);
  11325. h5.add(f);
  11326. h6.add(g);
  11327. h7.add(h);
  11328. }
  11329. var result;
  11330. if (!mode384) {
  11331. result = new Uint8Array(64);
  11332. h0.copyTo(result,0);
  11333. h1.copyTo(result,8);
  11334. h2.copyTo(result,16);
  11335. h3.copyTo(result,24);
  11336. h4.copyTo(result,32);
  11337. h5.copyTo(result,40);
  11338. h6.copyTo(result,48);
  11339. h7.copyTo(result,56);
  11340. }
  11341. else {
  11342. result = new Uint8Array(48);
  11343. h0.copyTo(result,0);
  11344. h1.copyTo(result,8);
  11345. h2.copyTo(result,16);
  11346. h3.copyTo(result,24);
  11347. h4.copyTo(result,32);
  11348. h5.copyTo(result,40);
  11349. }
  11350. return result;
  11351. }
  11352. return hash;
  11353. })();
  11354. var calculateSHA384 = (function calculateSHA384Closure() {
  11355. function hash(data, offset, length) {
  11356. return calculateSHA512(data, offset, length, true);
  11357. }
  11358. return hash;
  11359. })();
  11360. var NullCipher = (function NullCipherClosure() {
  11361. function NullCipher() {
  11362. }
  11363. NullCipher.prototype = {
  11364. decryptBlock: function NullCipher_decryptBlock(data) {
  11365. return data;
  11366. }
  11367. };
  11368. return NullCipher;
  11369. })();
  11370. var AES128Cipher = (function AES128CipherClosure() {
  11371. var rcon = new Uint8Array([
  11372. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  11373. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  11374. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  11375. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  11376. 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  11377. 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
  11378. 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
  11379. 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
  11380. 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
  11381. 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
  11382. 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
  11383. 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
  11384. 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
  11385. 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
  11386. 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
  11387. 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
  11388. 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
  11389. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  11390. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  11391. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  11392. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  11393. 0x74, 0xe8, 0xcb, 0x8d]);
  11394. var s = new Uint8Array([
  11395. 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
  11396. 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
  11397. 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
  11398. 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
  11399. 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
  11400. 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
  11401. 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
  11402. 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
  11403. 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
  11404. 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
  11405. 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
  11406. 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
  11407. 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
  11408. 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
  11409. 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
  11410. 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
  11411. 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
  11412. 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
  11413. 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
  11414. 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
  11415. 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
  11416. 0xb0, 0x54, 0xbb, 0x16]);
  11417. var inv_s = new Uint8Array([
  11418. 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
  11419. 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
  11420. 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
  11421. 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
  11422. 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
  11423. 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
  11424. 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
  11425. 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
  11426. 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
  11427. 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
  11428. 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
  11429. 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
  11430. 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
  11431. 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
  11432. 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
  11433. 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
  11434. 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
  11435. 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
  11436. 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
  11437. 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
  11438. 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
  11439. 0x55, 0x21, 0x0c, 0x7d]);
  11440. var mixCol = new Uint8Array(256);
  11441. for (var i = 0; i < 256; i++) {
  11442. if (i < 128) {
  11443. mixCol[i] = i << 1;
  11444. } else {
  11445. mixCol[i] = (i << 1) ^ 0x1b;
  11446. }
  11447. }
  11448. var mix = new Uint32Array([
  11449. 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
  11450. 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
  11451. 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
  11452. 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
  11453. 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
  11454. 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
  11455. 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
  11456. 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
  11457. 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
  11458. 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
  11459. 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
  11460. 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
  11461. 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
  11462. 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
  11463. 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
  11464. 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
  11465. 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
  11466. 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
  11467. 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
  11468. 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
  11469. 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
  11470. 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
  11471. 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
  11472. 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
  11473. 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
  11474. 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
  11475. 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
  11476. 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
  11477. 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
  11478. 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
  11479. 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
  11480. 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
  11481. 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
  11482. 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
  11483. 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
  11484. 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
  11485. 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
  11486. 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
  11487. 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
  11488. 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
  11489. 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
  11490. 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
  11491. 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
  11492. function expandKey128(cipherKey) {
  11493. var b = 176, result = new Uint8Array(b);
  11494. result.set(cipherKey);
  11495. for (var j = 16, i = 1; j < b; ++i) {
  11496. // RotWord
  11497. var t1 = result[j - 3], t2 = result[j - 2],
  11498. t3 = result[j - 1], t4 = result[j - 4];
  11499. // SubWord
  11500. t1 = s[t1];
  11501. t2 = s[t2];
  11502. t3 = s[t3];
  11503. t4 = s[t4];
  11504. // Rcon
  11505. t1 = t1 ^ rcon[i];
  11506. for (var n = 0; n < 4; ++n) {
  11507. result[j] = (t1 ^= result[j - 16]);
  11508. j++;
  11509. result[j] = (t2 ^= result[j - 16]);
  11510. j++;
  11511. result[j] = (t3 ^= result[j - 16]);
  11512. j++;
  11513. result[j] = (t4 ^= result[j - 16]);
  11514. j++;
  11515. }
  11516. }
  11517. return result;
  11518. }
  11519. function decrypt128(input, key) {
  11520. var state = new Uint8Array(16);
  11521. state.set(input);
  11522. var i, j, k;
  11523. var t, u, v;
  11524. // AddRoundKey
  11525. for (j = 0, k = 160; j < 16; ++j, ++k) {
  11526. state[j] ^= key[k];
  11527. }
  11528. for (i = 9; i >= 1; --i) {
  11529. // InvShiftRows
  11530. t = state[13];
  11531. state[13] = state[9];
  11532. state[9] = state[5];
  11533. state[5] = state[1];
  11534. state[1] = t;
  11535. t = state[14];
  11536. u = state[10];
  11537. state[14] = state[6];
  11538. state[10] = state[2];
  11539. state[6] = t;
  11540. state[2] = u;
  11541. t = state[15];
  11542. u = state[11];
  11543. v = state[7];
  11544. state[15] = state[3];
  11545. state[11] = t;
  11546. state[7] = u;
  11547. state[3] = v;
  11548. // InvSubBytes
  11549. for (j = 0; j < 16; ++j) {
  11550. state[j] = inv_s[state[j]];
  11551. }
  11552. // AddRoundKey
  11553. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  11554. state[j] ^= key[k];
  11555. }
  11556. // InvMixColumns
  11557. for (j = 0; j < 16; j += 4) {
  11558. var s0 = mix[state[j]], s1 = mix[state[j + 1]],
  11559. s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  11560. t = (s0 ^ (s1 >>> 8) ^ (s1 << 24) ^ (s2 >>> 16) ^ (s2 << 16) ^
  11561. (s3 >>> 24) ^ (s3 << 8));
  11562. state[j] = (t >>> 24) & 0xFF;
  11563. state[j + 1] = (t >> 16) & 0xFF;
  11564. state[j + 2] = (t >> 8) & 0xFF;
  11565. state[j + 3] = t & 0xFF;
  11566. }
  11567. }
  11568. // InvShiftRows
  11569. t = state[13];
  11570. state[13] = state[9];
  11571. state[9] = state[5];
  11572. state[5] = state[1];
  11573. state[1] = t;
  11574. t = state[14];
  11575. u = state[10];
  11576. state[14] = state[6];
  11577. state[10] = state[2];
  11578. state[6] = t;
  11579. state[2] = u;
  11580. t = state[15];
  11581. u = state[11];
  11582. v = state[7];
  11583. state[15] = state[3];
  11584. state[11] = t;
  11585. state[7] = u;
  11586. state[3] = v;
  11587. for (j = 0; j < 16; ++j) {
  11588. // InvSubBytes
  11589. state[j] = inv_s[state[j]];
  11590. // AddRoundKey
  11591. state[j] ^= key[j];
  11592. }
  11593. return state;
  11594. }
  11595. function encrypt128(input, key) {
  11596. var t, u, v, k;
  11597. var state = new Uint8Array(16);
  11598. state.set(input);
  11599. for (j = 0; j < 16; ++j) {
  11600. // AddRoundKey
  11601. state[j] ^= key[j];
  11602. }
  11603. for (i = 1; i < 10; i++) {
  11604. //SubBytes
  11605. for (j = 0; j < 16; ++j) {
  11606. state[j] = s[state[j]];
  11607. }
  11608. //ShiftRows
  11609. v = state[1];
  11610. state[1] = state[5];
  11611. state[5] = state[9];
  11612. state[9] = state[13];
  11613. state[13] = v;
  11614. v = state[2];
  11615. u = state[6];
  11616. state[2] = state[10];
  11617. state[6] = state[14];
  11618. state[10] = v;
  11619. state[14] = u;
  11620. v = state[3];
  11621. u = state[7];
  11622. t = state[11];
  11623. state[3] = state[15];
  11624. state[7] = v;
  11625. state[11] = u;
  11626. state[15] = t;
  11627. //MixColumns
  11628. for (var j = 0; j < 16; j += 4) {
  11629. var s0 = state[j + 0], s1 = state[j + 1];
  11630. var s2 = state[j + 2], s3 = state[j + 3];
  11631. t = s0 ^ s1 ^ s2 ^ s3;
  11632. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  11633. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  11634. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  11635. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  11636. }
  11637. //AddRoundKey
  11638. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  11639. state[j] ^= key[k];
  11640. }
  11641. }
  11642. //SubBytes
  11643. for (j = 0; j < 16; ++j) {
  11644. state[j] = s[state[j]];
  11645. }
  11646. //ShiftRows
  11647. v = state[1];
  11648. state[1] = state[5];
  11649. state[5] = state[9];
  11650. state[9] = state[13];
  11651. state[13] = v;
  11652. v = state[2];
  11653. u = state[6];
  11654. state[2] = state[10];
  11655. state[6] = state[14];
  11656. state[10] = v;
  11657. state[14] = u;
  11658. v = state[3];
  11659. u = state[7];
  11660. t = state[11];
  11661. state[3] = state[15];
  11662. state[7] = v;
  11663. state[11] = u;
  11664. state[15] = t;
  11665. //AddRoundKey
  11666. for (j = 0, k = 160; j < 16; ++j, ++k) {
  11667. state[j] ^= key[k];
  11668. }
  11669. return state;
  11670. }
  11671. function AES128Cipher(key) {
  11672. this.key = expandKey128(key);
  11673. this.buffer = new Uint8Array(16);
  11674. this.bufferPosition = 0;
  11675. }
  11676. function decryptBlock2(data, finalize) {
  11677. var i, j, ii, sourceLength = data.length,
  11678. buffer = this.buffer, bufferLength = this.bufferPosition,
  11679. result = [], iv = this.iv;
  11680. for (i = 0; i < sourceLength; ++i) {
  11681. buffer[bufferLength] = data[i];
  11682. ++bufferLength;
  11683. if (bufferLength < 16) {
  11684. continue;
  11685. }
  11686. // buffer is full, decrypting
  11687. var plain = decrypt128(buffer, this.key);
  11688. // xor-ing the IV vector to get plain text
  11689. for (j = 0; j < 16; ++j) {
  11690. plain[j] ^= iv[j];
  11691. }
  11692. iv = buffer;
  11693. result.push(plain);
  11694. buffer = new Uint8Array(16);
  11695. bufferLength = 0;
  11696. }
  11697. // saving incomplete buffer
  11698. this.buffer = buffer;
  11699. this.bufferLength = bufferLength;
  11700. this.iv = iv;
  11701. if (result.length === 0) {
  11702. return new Uint8Array([]);
  11703. }
  11704. // combining plain text blocks into one
  11705. var outputLength = 16 * result.length;
  11706. if (finalize) {
  11707. // undo a padding that is described in RFC 2898
  11708. var lastBlock = result[result.length - 1];
  11709. var psLen = lastBlock[15];
  11710. if (psLen <= 16) {
  11711. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  11712. if (lastBlock[i] !== psLen) {
  11713. // Invalid padding, assume that the block has no padding.
  11714. psLen = 0;
  11715. break;
  11716. }
  11717. }
  11718. outputLength -= psLen;
  11719. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  11720. }
  11721. }
  11722. var output = new Uint8Array(outputLength);
  11723. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  11724. output.set(result[i], j);
  11725. }
  11726. return output;
  11727. }
  11728. AES128Cipher.prototype = {
  11729. decryptBlock: function AES128Cipher_decryptBlock(data, finalize) {
  11730. var i, sourceLength = data.length;
  11731. var buffer = this.buffer, bufferLength = this.bufferPosition;
  11732. // waiting for IV values -- they are at the start of the stream
  11733. for (i = 0; bufferLength < 16 && i < sourceLength; ++i, ++bufferLength) {
  11734. buffer[bufferLength] = data[i];
  11735. }
  11736. if (bufferLength < 16) {
  11737. // need more data
  11738. this.bufferLength = bufferLength;
  11739. return new Uint8Array([]);
  11740. }
  11741. this.iv = buffer;
  11742. this.buffer = new Uint8Array(16);
  11743. this.bufferLength = 0;
  11744. // starting decryption
  11745. this.decryptBlock = decryptBlock2;
  11746. return this.decryptBlock(data.subarray(16), finalize);
  11747. },
  11748. encrypt: function AES128Cipher_encrypt(data, iv) {
  11749. var i, j, ii, sourceLength = data.length,
  11750. buffer = this.buffer, bufferLength = this.bufferPosition,
  11751. result = [];
  11752. if (!iv) {
  11753. iv = new Uint8Array(16);
  11754. }
  11755. for (i = 0; i < sourceLength; ++i) {
  11756. buffer[bufferLength] = data[i];
  11757. ++bufferLength;
  11758. if (bufferLength < 16) {
  11759. continue;
  11760. }
  11761. for (j = 0; j < 16; ++j) {
  11762. buffer[j] ^= iv[j];
  11763. }
  11764. // buffer is full, encrypting
  11765. var cipher = encrypt128(buffer, this.key);
  11766. iv = cipher;
  11767. result.push(cipher);
  11768. buffer = new Uint8Array(16);
  11769. bufferLength = 0;
  11770. }
  11771. // saving incomplete buffer
  11772. this.buffer = buffer;
  11773. this.bufferLength = bufferLength;
  11774. this.iv = iv;
  11775. if (result.length === 0) {
  11776. return new Uint8Array([]);
  11777. }
  11778. // combining plain text blocks into one
  11779. var outputLength = 16 * result.length;
  11780. var output = new Uint8Array(outputLength);
  11781. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  11782. output.set(result[i], j);
  11783. }
  11784. return output;
  11785. }
  11786. };
  11787. return AES128Cipher;
  11788. })();
  11789. var AES256Cipher = (function AES256CipherClosure() {
  11790. var rcon = new Uint8Array([
  11791. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  11792. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  11793. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  11794. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  11795. 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  11796. 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
  11797. 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
  11798. 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
  11799. 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
  11800. 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
  11801. 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
  11802. 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
  11803. 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
  11804. 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
  11805. 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
  11806. 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
  11807. 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
  11808. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  11809. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  11810. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  11811. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  11812. 0x74, 0xe8, 0xcb, 0x8d]);
  11813. var s = new Uint8Array([
  11814. 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
  11815. 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
  11816. 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
  11817. 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
  11818. 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
  11819. 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
  11820. 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
  11821. 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
  11822. 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
  11823. 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
  11824. 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
  11825. 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
  11826. 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
  11827. 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
  11828. 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
  11829. 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
  11830. 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
  11831. 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
  11832. 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
  11833. 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
  11834. 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
  11835. 0xb0, 0x54, 0xbb, 0x16]);
  11836. var inv_s = new Uint8Array([
  11837. 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
  11838. 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
  11839. 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
  11840. 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
  11841. 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
  11842. 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
  11843. 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
  11844. 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
  11845. 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
  11846. 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
  11847. 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
  11848. 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
  11849. 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
  11850. 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
  11851. 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
  11852. 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
  11853. 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
  11854. 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
  11855. 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
  11856. 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
  11857. 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
  11858. 0x55, 0x21, 0x0c, 0x7d]);
  11859. var mixCol = new Uint8Array(256);
  11860. for (var i = 0; i < 256; i++) {
  11861. if (i < 128) {
  11862. mixCol[i] = i << 1;
  11863. } else {
  11864. mixCol[i] = (i << 1) ^ 0x1b;
  11865. }
  11866. }
  11867. var mix = new Uint32Array([
  11868. 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
  11869. 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
  11870. 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
  11871. 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
  11872. 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
  11873. 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
  11874. 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
  11875. 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
  11876. 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
  11877. 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
  11878. 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
  11879. 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
  11880. 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
  11881. 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
  11882. 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
  11883. 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
  11884. 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
  11885. 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
  11886. 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
  11887. 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
  11888. 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
  11889. 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
  11890. 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
  11891. 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
  11892. 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
  11893. 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
  11894. 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
  11895. 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
  11896. 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
  11897. 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
  11898. 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
  11899. 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
  11900. 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
  11901. 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
  11902. 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
  11903. 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
  11904. 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
  11905. 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
  11906. 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
  11907. 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
  11908. 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
  11909. 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
  11910. 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
  11911. function expandKey256(cipherKey) {
  11912. var b = 240, result = new Uint8Array(b);
  11913. var r = 1;
  11914. result.set(cipherKey);
  11915. for (var j = 32, i = 1; j < b; ++i) {
  11916. if (j % 32 === 16) {
  11917. t1 = s[t1];
  11918. t2 = s[t2];
  11919. t3 = s[t3];
  11920. t4 = s[t4];
  11921. } else if (j % 32 === 0) {
  11922. // RotWord
  11923. var t1 = result[j - 3], t2 = result[j - 2],
  11924. t3 = result[j - 1], t4 = result[j - 4];
  11925. // SubWord
  11926. t1 = s[t1];
  11927. t2 = s[t2];
  11928. t3 = s[t3];
  11929. t4 = s[t4];
  11930. // Rcon
  11931. t1 = t1 ^ r;
  11932. if ((r <<= 1) >= 256) {
  11933. r = (r ^ 0x1b) & 0xFF;
  11934. }
  11935. }
  11936. for (var n = 0; n < 4; ++n) {
  11937. result[j] = (t1 ^= result[j - 32]);
  11938. j++;
  11939. result[j] = (t2 ^= result[j - 32]);
  11940. j++;
  11941. result[j] = (t3 ^= result[j - 32]);
  11942. j++;
  11943. result[j] = (t4 ^= result[j - 32]);
  11944. j++;
  11945. }
  11946. }
  11947. return result;
  11948. }
  11949. function decrypt256(input, key) {
  11950. var state = new Uint8Array(16);
  11951. state.set(input);
  11952. var i, j, k;
  11953. var t, u, v;
  11954. // AddRoundKey
  11955. for (j = 0, k = 224; j < 16; ++j, ++k) {
  11956. state[j] ^= key[k];
  11957. }
  11958. for (i = 13; i >= 1; --i) {
  11959. // InvShiftRows
  11960. t = state[13];
  11961. state[13] = state[9];
  11962. state[9] = state[5];
  11963. state[5] = state[1];
  11964. state[1] = t;
  11965. t = state[14];
  11966. u = state[10];
  11967. state[14] = state[6];
  11968. state[10] = state[2];
  11969. state[6] = t;
  11970. state[2] = u;
  11971. t = state[15];
  11972. u = state[11];
  11973. v = state[7];
  11974. state[15] = state[3];
  11975. state[11] = t;
  11976. state[7] = u;
  11977. state[3] = v;
  11978. // InvSubBytes
  11979. for (j = 0; j < 16; ++j) {
  11980. state[j] = inv_s[state[j]];
  11981. }
  11982. // AddRoundKey
  11983. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  11984. state[j] ^= key[k];
  11985. }
  11986. // InvMixColumns
  11987. for (j = 0; j < 16; j += 4) {
  11988. var s0 = mix[state[j]], s1 = mix[state[j + 1]],
  11989. s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  11990. t = (s0 ^ (s1 >>> 8) ^ (s1 << 24) ^ (s2 >>> 16) ^ (s2 << 16) ^
  11991. (s3 >>> 24) ^ (s3 << 8));
  11992. state[j] = (t >>> 24) & 0xFF;
  11993. state[j + 1] = (t >> 16) & 0xFF;
  11994. state[j + 2] = (t >> 8) & 0xFF;
  11995. state[j + 3] = t & 0xFF;
  11996. }
  11997. }
  11998. // InvShiftRows
  11999. t = state[13];
  12000. state[13] = state[9];
  12001. state[9] = state[5];
  12002. state[5] = state[1];
  12003. state[1] = t;
  12004. t = state[14];
  12005. u = state[10];
  12006. state[14] = state[6];
  12007. state[10] = state[2];
  12008. state[6] = t;
  12009. state[2] = u;
  12010. t = state[15];
  12011. u = state[11];
  12012. v = state[7];
  12013. state[15] = state[3];
  12014. state[11] = t;
  12015. state[7] = u;
  12016. state[3] = v;
  12017. for (j = 0; j < 16; ++j) {
  12018. // InvSubBytes
  12019. state[j] = inv_s[state[j]];
  12020. // AddRoundKey
  12021. state[j] ^= key[j];
  12022. }
  12023. return state;
  12024. }
  12025. function encrypt256(input, key) {
  12026. var t, u, v, k;
  12027. var state = new Uint8Array(16);
  12028. state.set(input);
  12029. for (j = 0; j < 16; ++j) {
  12030. // AddRoundKey
  12031. state[j] ^= key[j];
  12032. }
  12033. for (i = 1; i < 14; i++) {
  12034. //SubBytes
  12035. for (j = 0; j < 16; ++j) {
  12036. state[j] = s[state[j]];
  12037. }
  12038. //ShiftRows
  12039. v = state[1];
  12040. state[1] = state[5];
  12041. state[5] = state[9];
  12042. state[9] = state[13];
  12043. state[13] = v;
  12044. v = state[2];
  12045. u = state[6];
  12046. state[2] = state[10];
  12047. state[6] = state[14];
  12048. state[10] = v;
  12049. state[14] = u;
  12050. v = state[3];
  12051. u = state[7];
  12052. t = state[11];
  12053. state[3] = state[15];
  12054. state[7] = v;
  12055. state[11] = u;
  12056. state[15] = t;
  12057. //MixColumns
  12058. for (var j = 0; j < 16; j += 4) {
  12059. var s0 = state[j + 0], s1 = state[j + 1];
  12060. var s2 = state[j + 2], s3 = state[j + 3];
  12061. t = s0 ^ s1 ^ s2 ^ s3;
  12062. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  12063. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  12064. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  12065. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  12066. }
  12067. //AddRoundKey
  12068. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  12069. state[j] ^= key[k];
  12070. }
  12071. }
  12072. //SubBytes
  12073. for (j = 0; j < 16; ++j) {
  12074. state[j] = s[state[j]];
  12075. }
  12076. //ShiftRows
  12077. v = state[1];
  12078. state[1] = state[5];
  12079. state[5] = state[9];
  12080. state[9] = state[13];
  12081. state[13] = v;
  12082. v = state[2];
  12083. u = state[6];
  12084. state[2] = state[10];
  12085. state[6] = state[14];
  12086. state[10] = v;
  12087. state[14] = u;
  12088. v = state[3];
  12089. u = state[7];
  12090. t = state[11];
  12091. state[3] = state[15];
  12092. state[7] = v;
  12093. state[11] = u;
  12094. state[15] = t;
  12095. //AddRoundKey
  12096. for (j = 0, k = 224; j < 16; ++j, ++k) {
  12097. state[j] ^= key[k];
  12098. }
  12099. return state;
  12100. }
  12101. function AES256Cipher(key) {
  12102. this.key = expandKey256(key);
  12103. this.buffer = new Uint8Array(16);
  12104. this.bufferPosition = 0;
  12105. }
  12106. function decryptBlock2(data, finalize) {
  12107. var i, j, ii, sourceLength = data.length,
  12108. buffer = this.buffer, bufferLength = this.bufferPosition,
  12109. result = [], iv = this.iv;
  12110. for (i = 0; i < sourceLength; ++i) {
  12111. buffer[bufferLength] = data[i];
  12112. ++bufferLength;
  12113. if (bufferLength < 16) {
  12114. continue;
  12115. }
  12116. // buffer is full, decrypting
  12117. var plain = decrypt256(buffer, this.key);
  12118. // xor-ing the IV vector to get plain text
  12119. for (j = 0; j < 16; ++j) {
  12120. plain[j] ^= iv[j];
  12121. }
  12122. iv = buffer;
  12123. result.push(plain);
  12124. buffer = new Uint8Array(16);
  12125. bufferLength = 0;
  12126. }
  12127. // saving incomplete buffer
  12128. this.buffer = buffer;
  12129. this.bufferLength = bufferLength;
  12130. this.iv = iv;
  12131. if (result.length === 0) {
  12132. return new Uint8Array([]);
  12133. }
  12134. // combining plain text blocks into one
  12135. var outputLength = 16 * result.length;
  12136. if (finalize) {
  12137. // undo a padding that is described in RFC 2898
  12138. var lastBlock = result[result.length - 1];
  12139. var psLen = lastBlock[15];
  12140. if (psLen <= 16) {
  12141. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  12142. if (lastBlock[i] !== psLen) {
  12143. // Invalid padding, assume that the block has no padding.
  12144. psLen = 0;
  12145. break;
  12146. }
  12147. }
  12148. outputLength -= psLen;
  12149. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  12150. }
  12151. }
  12152. var output = new Uint8Array(outputLength);
  12153. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  12154. output.set(result[i], j);
  12155. }
  12156. return output;
  12157. }
  12158. AES256Cipher.prototype = {
  12159. decryptBlock: function AES256Cipher_decryptBlock(data, finalize, iv) {
  12160. var i, sourceLength = data.length;
  12161. var buffer = this.buffer, bufferLength = this.bufferPosition;
  12162. // if not supplied an IV wait for IV values
  12163. // they are at the start of the stream
  12164. if (iv) {
  12165. this.iv = iv;
  12166. } else {
  12167. for (i = 0; bufferLength < 16 &&
  12168. i < sourceLength; ++i, ++bufferLength) {
  12169. buffer[bufferLength] = data[i];
  12170. }
  12171. if (bufferLength < 16) {
  12172. //need more data
  12173. this.bufferLength = bufferLength;
  12174. return new Uint8Array([]);
  12175. }
  12176. this.iv = buffer;
  12177. data = data.subarray(16);
  12178. }
  12179. this.buffer = new Uint8Array(16);
  12180. this.bufferLength = 0;
  12181. // starting decryption
  12182. this.decryptBlock = decryptBlock2;
  12183. return this.decryptBlock(data, finalize);
  12184. },
  12185. encrypt: function AES256Cipher_encrypt(data, iv) {
  12186. var i, j, ii, sourceLength = data.length,
  12187. buffer = this.buffer, bufferLength = this.bufferPosition,
  12188. result = [];
  12189. if (!iv) {
  12190. iv = new Uint8Array(16);
  12191. }
  12192. for (i = 0; i < sourceLength; ++i) {
  12193. buffer[bufferLength] = data[i];
  12194. ++bufferLength;
  12195. if (bufferLength < 16) {
  12196. continue;
  12197. }
  12198. for (j = 0; j < 16; ++j) {
  12199. buffer[j] ^= iv[j];
  12200. }
  12201. // buffer is full, encrypting
  12202. var cipher = encrypt256(buffer, this.key);
  12203. this.iv = cipher;
  12204. result.push(cipher);
  12205. buffer = new Uint8Array(16);
  12206. bufferLength = 0;
  12207. }
  12208. // saving incomplete buffer
  12209. this.buffer = buffer;
  12210. this.bufferLength = bufferLength;
  12211. this.iv = iv;
  12212. if (result.length === 0) {
  12213. return new Uint8Array([]);
  12214. }
  12215. // combining plain text blocks into one
  12216. var outputLength = 16 * result.length;
  12217. var output = new Uint8Array(outputLength);
  12218. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  12219. output.set(result[i], j);
  12220. }
  12221. return output;
  12222. }
  12223. };
  12224. return AES256Cipher;
  12225. })();
  12226. var PDF17 = (function PDF17Closure() {
  12227. function compareByteArrays(array1, array2) {
  12228. if (array1.length !== array2.length) {
  12229. return false;
  12230. }
  12231. for (var i = 0; i < array1.length; i++) {
  12232. if (array1[i] !== array2[i]) {
  12233. return false;
  12234. }
  12235. }
  12236. return true;
  12237. }
  12238. function PDF17() {
  12239. }
  12240. PDF17.prototype = {
  12241. checkOwnerPassword: function PDF17_checkOwnerPassword(password,
  12242. ownerValidationSalt,
  12243. userBytes,
  12244. ownerPassword) {
  12245. var hashData = new Uint8Array(password.length + 56);
  12246. hashData.set(password, 0);
  12247. hashData.set(ownerValidationSalt, password.length);
  12248. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  12249. var result = calculateSHA256(hashData, 0, hashData.length);
  12250. return compareByteArrays(result, ownerPassword);
  12251. },
  12252. checkUserPassword: function PDF17_checkUserPassword(password,
  12253. userValidationSalt,
  12254. userPassword) {
  12255. var hashData = new Uint8Array(password.length + 8);
  12256. hashData.set(password, 0);
  12257. hashData.set(userValidationSalt, password.length);
  12258. var result = calculateSHA256(hashData, 0, hashData.length);
  12259. return compareByteArrays(result, userPassword);
  12260. },
  12261. getOwnerKey: function PDF17_getOwnerKey(password, ownerKeySalt, userBytes,
  12262. ownerEncryption) {
  12263. var hashData = new Uint8Array(password.length + 56);
  12264. hashData.set(password, 0);
  12265. hashData.set(ownerKeySalt, password.length);
  12266. hashData.set(userBytes, password.length + ownerKeySalt.length);
  12267. var key = calculateSHA256(hashData, 0, hashData.length);
  12268. var cipher = new AES256Cipher(key);
  12269. return cipher.decryptBlock(ownerEncryption,
  12270. false,
  12271. new Uint8Array(16));
  12272. },
  12273. getUserKey: function PDF17_getUserKey(password, userKeySalt,
  12274. userEncryption) {
  12275. var hashData = new Uint8Array(password.length + 8);
  12276. hashData.set(password, 0);
  12277. hashData.set(userKeySalt, password.length);
  12278. //key is the decryption key for the UE string
  12279. var key = calculateSHA256(hashData, 0, hashData.length);
  12280. var cipher = new AES256Cipher(key);
  12281. return cipher.decryptBlock(userEncryption,
  12282. false,
  12283. new Uint8Array(16));
  12284. }
  12285. };
  12286. return PDF17;
  12287. })();
  12288. var PDF20 = (function PDF20Closure() {
  12289. function concatArrays(array1, array2) {
  12290. var t = new Uint8Array(array1.length + array2.length);
  12291. t.set(array1, 0);
  12292. t.set(array2, array1.length);
  12293. return t;
  12294. }
  12295. function calculatePDF20Hash(password, input, userBytes) {
  12296. //This refers to Algorithm 2.B as defined in ISO 32000-2
  12297. var k = calculateSHA256(input, 0, input.length).subarray(0, 32);
  12298. var e = [0];
  12299. var i = 0;
  12300. while (i < 64 || e[e.length - 1] > i - 32) {
  12301. var arrayLength = password.length + k.length + userBytes.length;
  12302. var k1 = new Uint8Array(arrayLength * 64);
  12303. var array = concatArrays(password, k);
  12304. array = concatArrays(array, userBytes);
  12305. for (var j = 0, pos = 0; j < 64; j++, pos += arrayLength) {
  12306. k1.set(array, pos);
  12307. }
  12308. //AES128 CBC NO PADDING with
  12309. //first 16 bytes of k as the key and the second 16 as the iv.
  12310. var cipher = new AES128Cipher(k.subarray(0, 16));
  12311. e = cipher.encrypt(k1, k.subarray(16, 32));
  12312. //Now we have to take the first 16 bytes of an unsigned
  12313. //big endian integer... and compute the remainder
  12314. //modulo 3.... That is a fairly large number and
  12315. //JavaScript isn't going to handle that well...
  12316. //So we're using a trick that allows us to perform
  12317. //modulo math byte by byte
  12318. var remainder = 0;
  12319. for (var z = 0; z < 16; z++) {
  12320. remainder *= (256 % 3);
  12321. remainder %= 3;
  12322. remainder += ((e[z] >>> 0) % 3);
  12323. remainder %= 3;
  12324. }
  12325. if (remainder === 0) {
  12326. k = calculateSHA256(e, 0, e.length);
  12327. }
  12328. else if (remainder === 1) {
  12329. k = calculateSHA384(e, 0, e.length);
  12330. }
  12331. else if (remainder === 2) {
  12332. k = calculateSHA512(e, 0, e.length);
  12333. }
  12334. i++;
  12335. }
  12336. return k.subarray(0, 32);
  12337. }
  12338. function PDF20() {
  12339. }
  12340. function compareByteArrays(array1, array2) {
  12341. if (array1.length !== array2.length) {
  12342. return false;
  12343. }
  12344. for (var i = 0; i < array1.length; i++) {
  12345. if (array1[i] !== array2[i]) {
  12346. return false;
  12347. }
  12348. }
  12349. return true;
  12350. }
  12351. PDF20.prototype = {
  12352. hash: function PDF20_hash(password, concatBytes, userBytes) {
  12353. return calculatePDF20Hash(password, concatBytes, userBytes);
  12354. },
  12355. checkOwnerPassword: function PDF20_checkOwnerPassword(password,
  12356. ownerValidationSalt,
  12357. userBytes,
  12358. ownerPassword) {
  12359. var hashData = new Uint8Array(password.length + 56);
  12360. hashData.set(password, 0);
  12361. hashData.set(ownerValidationSalt, password.length);
  12362. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  12363. var result = calculatePDF20Hash(password, hashData, userBytes);
  12364. return compareByteArrays(result, ownerPassword);
  12365. },
  12366. checkUserPassword: function PDF20_checkUserPassword(password,
  12367. userValidationSalt,
  12368. userPassword) {
  12369. var hashData = new Uint8Array(password.length + 8);
  12370. hashData.set(password, 0);
  12371. hashData.set(userValidationSalt, password.length);
  12372. var result = calculatePDF20Hash(password, hashData, []);
  12373. return compareByteArrays(result, userPassword);
  12374. },
  12375. getOwnerKey: function PDF20_getOwnerKey(password, ownerKeySalt, userBytes,
  12376. ownerEncryption) {
  12377. var hashData = new Uint8Array(password.length + 56);
  12378. hashData.set(password, 0);
  12379. hashData.set(ownerKeySalt, password.length);
  12380. hashData.set(userBytes, password.length + ownerKeySalt.length);
  12381. var key = calculatePDF20Hash(password, hashData, userBytes);
  12382. var cipher = new AES256Cipher(key);
  12383. return cipher.decryptBlock(ownerEncryption,
  12384. false,
  12385. new Uint8Array(16));
  12386. },
  12387. getUserKey: function PDF20_getUserKey(password, userKeySalt,
  12388. userEncryption) {
  12389. var hashData = new Uint8Array(password.length + 8);
  12390. hashData.set(password, 0);
  12391. hashData.set(userKeySalt, password.length);
  12392. //key is the decryption key for the UE string
  12393. var key = calculatePDF20Hash(password, hashData, []);
  12394. var cipher = new AES256Cipher(key);
  12395. return cipher.decryptBlock(userEncryption,
  12396. false,
  12397. new Uint8Array(16));
  12398. }
  12399. };
  12400. return PDF20;
  12401. })();
  12402. var CipherTransform = (function CipherTransformClosure() {
  12403. function CipherTransform(stringCipherConstructor, streamCipherConstructor) {
  12404. this.stringCipherConstructor = stringCipherConstructor;
  12405. this.streamCipherConstructor = streamCipherConstructor;
  12406. }
  12407. CipherTransform.prototype = {
  12408. createStream: function CipherTransform_createStream(stream, length) {
  12409. var cipher = new this.streamCipherConstructor();
  12410. return new DecryptStream(stream, length,
  12411. function cipherTransformDecryptStream(data, finalize) {
  12412. return cipher.decryptBlock(data, finalize);
  12413. }
  12414. );
  12415. },
  12416. decryptString: function CipherTransform_decryptString(s) {
  12417. var cipher = new this.stringCipherConstructor();
  12418. var data = stringToBytes(s);
  12419. data = cipher.decryptBlock(data, true);
  12420. return bytesToString(data);
  12421. }
  12422. };
  12423. return CipherTransform;
  12424. })();
  12425. var CipherTransformFactory = (function CipherTransformFactoryClosure() {
  12426. var defaultPasswordBytes = new Uint8Array([
  12427. 0x28, 0xBF, 0x4E, 0x5E, 0x4E, 0x75, 0x8A, 0x41,
  12428. 0x64, 0x00, 0x4E, 0x56, 0xFF, 0xFA, 0x01, 0x08,
  12429. 0x2E, 0x2E, 0x00, 0xB6, 0xD0, 0x68, 0x3E, 0x80,
  12430. 0x2F, 0x0C, 0xA9, 0xFE, 0x64, 0x53, 0x69, 0x7A]);
  12431. function createEncryptionKey20(revision, password, ownerPassword,
  12432. ownerValidationSalt, ownerKeySalt, uBytes,
  12433. userPassword, userValidationSalt, userKeySalt,
  12434. ownerEncryption, userEncryption, perms) {
  12435. if (password) {
  12436. var passwordLength = Math.min(127, password.length);
  12437. password = password.subarray(0, passwordLength);
  12438. } else {
  12439. password = [];
  12440. }
  12441. var pdfAlgorithm;
  12442. if (revision === 6) {
  12443. pdfAlgorithm = new PDF20();
  12444. } else {
  12445. pdfAlgorithm = new PDF17();
  12446. }
  12447. if (pdfAlgorithm) {
  12448. if (pdfAlgorithm.checkUserPassword(password, userValidationSalt,
  12449. userPassword)) {
  12450. return pdfAlgorithm.getUserKey(password, userKeySalt, userEncryption);
  12451. } else if (pdfAlgorithm.checkOwnerPassword(password, ownerValidationSalt,
  12452. uBytes,
  12453. ownerPassword)) {
  12454. return pdfAlgorithm.getOwnerKey(password, ownerKeySalt, uBytes,
  12455. ownerEncryption);
  12456. }
  12457. }
  12458. return null;
  12459. }
  12460. function prepareKeyData(fileId, password, ownerPassword, userPassword,
  12461. flags, revision, keyLength, encryptMetadata) {
  12462. var hashDataSize = 40 + ownerPassword.length + fileId.length;
  12463. var hashData = new Uint8Array(hashDataSize), i = 0, j, n;
  12464. if (password) {
  12465. n = Math.min(32, password.length);
  12466. for (; i < n; ++i) {
  12467. hashData[i] = password[i];
  12468. }
  12469. }
  12470. j = 0;
  12471. while (i < 32) {
  12472. hashData[i++] = defaultPasswordBytes[j++];
  12473. }
  12474. // as now the padded password in the hashData[0..i]
  12475. for (j = 0, n = ownerPassword.length; j < n; ++j) {
  12476. hashData[i++] = ownerPassword[j];
  12477. }
  12478. hashData[i++] = flags & 0xFF;
  12479. hashData[i++] = (flags >> 8) & 0xFF;
  12480. hashData[i++] = (flags >> 16) & 0xFF;
  12481. hashData[i++] = (flags >>> 24) & 0xFF;
  12482. for (j = 0, n = fileId.length; j < n; ++j) {
  12483. hashData[i++] = fileId[j];
  12484. }
  12485. if (revision >= 4 && !encryptMetadata) {
  12486. hashData[i++] = 0xFF;
  12487. hashData[i++] = 0xFF;
  12488. hashData[i++] = 0xFF;
  12489. hashData[i++] = 0xFF;
  12490. }
  12491. var hash = calculateMD5(hashData, 0, i);
  12492. var keyLengthInBytes = keyLength >> 3;
  12493. if (revision >= 3) {
  12494. for (j = 0; j < 50; ++j) {
  12495. hash = calculateMD5(hash, 0, keyLengthInBytes);
  12496. }
  12497. }
  12498. var encryptionKey = hash.subarray(0, keyLengthInBytes);
  12499. var cipher, checkData;
  12500. if (revision >= 3) {
  12501. for (i = 0; i < 32; ++i) {
  12502. hashData[i] = defaultPasswordBytes[i];
  12503. }
  12504. for (j = 0, n = fileId.length; j < n; ++j) {
  12505. hashData[i++] = fileId[j];
  12506. }
  12507. cipher = new ARCFourCipher(encryptionKey);
  12508. checkData = cipher.encryptBlock(calculateMD5(hashData, 0, i));
  12509. n = encryptionKey.length;
  12510. var derivedKey = new Uint8Array(n), k;
  12511. for (j = 1; j <= 19; ++j) {
  12512. for (k = 0; k < n; ++k) {
  12513. derivedKey[k] = encryptionKey[k] ^ j;
  12514. }
  12515. cipher = new ARCFourCipher(derivedKey);
  12516. checkData = cipher.encryptBlock(checkData);
  12517. }
  12518. for (j = 0, n = checkData.length; j < n; ++j) {
  12519. if (userPassword[j] !== checkData[j]) {
  12520. return null;
  12521. }
  12522. }
  12523. } else {
  12524. cipher = new ARCFourCipher(encryptionKey);
  12525. checkData = cipher.encryptBlock(defaultPasswordBytes);
  12526. for (j = 0, n = checkData.length; j < n; ++j) {
  12527. if (userPassword[j] !== checkData[j]) {
  12528. return null;
  12529. }
  12530. }
  12531. }
  12532. return encryptionKey;
  12533. }
  12534. function decodeUserPassword(password, ownerPassword, revision, keyLength) {
  12535. var hashData = new Uint8Array(32), i = 0, j, n;
  12536. n = Math.min(32, password.length);
  12537. for (; i < n; ++i) {
  12538. hashData[i] = password[i];
  12539. }
  12540. j = 0;
  12541. while (i < 32) {
  12542. hashData[i++] = defaultPasswordBytes[j++];
  12543. }
  12544. var hash = calculateMD5(hashData, 0, i);
  12545. var keyLengthInBytes = keyLength >> 3;
  12546. if (revision >= 3) {
  12547. for (j = 0; j < 50; ++j) {
  12548. hash = calculateMD5(hash, 0, hash.length);
  12549. }
  12550. }
  12551. var cipher, userPassword;
  12552. if (revision >= 3) {
  12553. userPassword = ownerPassword;
  12554. var derivedKey = new Uint8Array(keyLengthInBytes), k;
  12555. for (j = 19; j >= 0; j--) {
  12556. for (k = 0; k < keyLengthInBytes; ++k) {
  12557. derivedKey[k] = hash[k] ^ j;
  12558. }
  12559. cipher = new ARCFourCipher(derivedKey);
  12560. userPassword = cipher.encryptBlock(userPassword);
  12561. }
  12562. } else {
  12563. cipher = new ARCFourCipher(hash.subarray(0, keyLengthInBytes));
  12564. userPassword = cipher.encryptBlock(ownerPassword);
  12565. }
  12566. return userPassword;
  12567. }
  12568. var identityName = Name.get('Identity');
  12569. function CipherTransformFactory(dict, fileId, password) {
  12570. var filter = dict.get('Filter');
  12571. if (!isName(filter) || filter.name !== 'Standard') {
  12572. error('unknown encryption method');
  12573. }
  12574. this.dict = dict;
  12575. var algorithm = dict.get('V');
  12576. if (!isInt(algorithm) ||
  12577. (algorithm !== 1 && algorithm !== 2 && algorithm !== 4 &&
  12578. algorithm !== 5)) {
  12579. error('unsupported encryption algorithm');
  12580. }
  12581. this.algorithm = algorithm;
  12582. var keyLength = dict.get('Length') || 40;
  12583. if (!isInt(keyLength) ||
  12584. keyLength < 40 || (keyLength % 8) !== 0) {
  12585. error('invalid key length');
  12586. }
  12587. // prepare keys
  12588. var ownerPassword = stringToBytes(dict.get('O')).subarray(0, 32);
  12589. var userPassword = stringToBytes(dict.get('U')).subarray(0, 32);
  12590. var flags = dict.get('P');
  12591. var revision = dict.get('R');
  12592. // meaningful when V is 4 or 5
  12593. var encryptMetadata = ((algorithm === 4 || algorithm === 5) &&
  12594. dict.get('EncryptMetadata') !== false);
  12595. this.encryptMetadata = encryptMetadata;
  12596. var fileIdBytes = stringToBytes(fileId);
  12597. var passwordBytes;
  12598. if (password) {
  12599. passwordBytes = stringToBytes(password);
  12600. }
  12601. var encryptionKey;
  12602. if (algorithm !== 5) {
  12603. encryptionKey = prepareKeyData(fileIdBytes, passwordBytes,
  12604. ownerPassword, userPassword, flags,
  12605. revision, keyLength, encryptMetadata);
  12606. }
  12607. else {
  12608. var ownerValidationSalt = stringToBytes(dict.get('O')).subarray(32, 40);
  12609. var ownerKeySalt = stringToBytes(dict.get('O')).subarray(40, 48);
  12610. var uBytes = stringToBytes(dict.get('U')).subarray(0, 48);
  12611. var userValidationSalt = stringToBytes(dict.get('U')).subarray(32, 40);
  12612. var userKeySalt = stringToBytes(dict.get('U')).subarray(40, 48);
  12613. var ownerEncryption = stringToBytes(dict.get('OE'));
  12614. var userEncryption = stringToBytes(dict.get('UE'));
  12615. var perms = stringToBytes(dict.get('Perms'));
  12616. encryptionKey =
  12617. createEncryptionKey20(revision, passwordBytes,
  12618. ownerPassword, ownerValidationSalt,
  12619. ownerKeySalt, uBytes,
  12620. userPassword, userValidationSalt,
  12621. userKeySalt, ownerEncryption,
  12622. userEncryption, perms);
  12623. }
  12624. if (!encryptionKey && !password) {
  12625. throw new PasswordException('No password given',
  12626. PasswordResponses.NEED_PASSWORD);
  12627. } else if (!encryptionKey && password) {
  12628. // Attempting use the password as an owner password
  12629. var decodedPassword = decodeUserPassword(passwordBytes, ownerPassword,
  12630. revision, keyLength);
  12631. encryptionKey = prepareKeyData(fileIdBytes, decodedPassword,
  12632. ownerPassword, userPassword, flags,
  12633. revision, keyLength, encryptMetadata);
  12634. }
  12635. if (!encryptionKey) {
  12636. throw new PasswordException('Incorrect Password',
  12637. PasswordResponses.INCORRECT_PASSWORD);
  12638. }
  12639. this.encryptionKey = encryptionKey;
  12640. if (algorithm >= 4) {
  12641. this.cf = dict.get('CF');
  12642. this.stmf = dict.get('StmF') || identityName;
  12643. this.strf = dict.get('StrF') || identityName;
  12644. this.eff = dict.get('EFF') || this.strf;
  12645. }
  12646. }
  12647. function buildObjectKey(num, gen, encryptionKey, isAes) {
  12648. var key = new Uint8Array(encryptionKey.length + 9), i, n;
  12649. for (i = 0, n = encryptionKey.length; i < n; ++i) {
  12650. key[i] = encryptionKey[i];
  12651. }
  12652. key[i++] = num & 0xFF;
  12653. key[i++] = (num >> 8) & 0xFF;
  12654. key[i++] = (num >> 16) & 0xFF;
  12655. key[i++] = gen & 0xFF;
  12656. key[i++] = (gen >> 8) & 0xFF;
  12657. if (isAes) {
  12658. key[i++] = 0x73;
  12659. key[i++] = 0x41;
  12660. key[i++] = 0x6C;
  12661. key[i++] = 0x54;
  12662. }
  12663. var hash = calculateMD5(key, 0, i);
  12664. return hash.subarray(0, Math.min(encryptionKey.length + 5, 16));
  12665. }
  12666. function buildCipherConstructor(cf, name, num, gen, key) {
  12667. var cryptFilter = cf.get(name.name);
  12668. var cfm;
  12669. if (cryptFilter !== null && cryptFilter !== undefined) {
  12670. cfm = cryptFilter.get('CFM');
  12671. }
  12672. if (!cfm || cfm.name === 'None') {
  12673. return function cipherTransformFactoryBuildCipherConstructorNone() {
  12674. return new NullCipher();
  12675. };
  12676. }
  12677. if ('V2' === cfm.name) {
  12678. return function cipherTransformFactoryBuildCipherConstructorV2() {
  12679. return new ARCFourCipher(buildObjectKey(num, gen, key, false));
  12680. };
  12681. }
  12682. if ('AESV2' === cfm.name) {
  12683. return function cipherTransformFactoryBuildCipherConstructorAESV2() {
  12684. return new AES128Cipher(buildObjectKey(num, gen, key, true));
  12685. };
  12686. }
  12687. if ('AESV3' === cfm.name) {
  12688. return function cipherTransformFactoryBuildCipherConstructorAESV3() {
  12689. return new AES256Cipher(key);
  12690. };
  12691. }
  12692. error('Unknown crypto method');
  12693. }
  12694. CipherTransformFactory.prototype = {
  12695. createCipherTransform:
  12696. function CipherTransformFactory_createCipherTransform(num, gen) {
  12697. if (this.algorithm === 4 || this.algorithm === 5) {
  12698. return new CipherTransform(
  12699. buildCipherConstructor(this.cf, this.stmf,
  12700. num, gen, this.encryptionKey),
  12701. buildCipherConstructor(this.cf, this.strf,
  12702. num, gen, this.encryptionKey));
  12703. }
  12704. // algorithms 1 and 2
  12705. var key = buildObjectKey(num, gen, this.encryptionKey, false);
  12706. var cipherConstructor = function buildCipherCipherConstructor() {
  12707. return new ARCFourCipher(key);
  12708. };
  12709. return new CipherTransform(cipherConstructor, cipherConstructor);
  12710. }
  12711. };
  12712. return CipherTransformFactory;
  12713. })();
  12714. var PatternType = {
  12715. FUNCTION_BASED: 1,
  12716. AXIAL: 2,
  12717. RADIAL: 3,
  12718. FREE_FORM_MESH: 4,
  12719. LATTICE_FORM_MESH: 5,
  12720. COONS_PATCH_MESH: 6,
  12721. TENSOR_PATCH_MESH: 7
  12722. };
  12723. var Pattern = (function PatternClosure() {
  12724. // Constructor should define this.getPattern
  12725. function Pattern() {
  12726. error('should not call Pattern constructor');
  12727. }
  12728. Pattern.prototype = {
  12729. // Input: current Canvas context
  12730. // Output: the appropriate fillStyle or strokeStyle
  12731. getPattern: function Pattern_getPattern(ctx) {
  12732. error('Should not call Pattern.getStyle: ' + ctx);
  12733. }
  12734. };
  12735. Pattern.parseShading = function Pattern_parseShading(shading, matrix, xref,
  12736. res) {
  12737. var dict = isStream(shading) ? shading.dict : shading;
  12738. var type = dict.get('ShadingType');
  12739. switch (type) {
  12740. case PatternType.AXIAL:
  12741. case PatternType.RADIAL:
  12742. // Both radial and axial shadings are handled by RadialAxial shading.
  12743. return new Shadings.RadialAxial(dict, matrix, xref, res);
  12744. case PatternType.FREE_FORM_MESH:
  12745. case PatternType.LATTICE_FORM_MESH:
  12746. case PatternType.COONS_PATCH_MESH:
  12747. case PatternType.TENSOR_PATCH_MESH:
  12748. return new Shadings.Mesh(shading, matrix, xref, res);
  12749. default:
  12750. UnsupportedManager.notify(UNSUPPORTED_FEATURES.shadingPattern);
  12751. return new Shadings.Dummy();
  12752. }
  12753. };
  12754. return Pattern;
  12755. })();
  12756. var Shadings = {};
  12757. // A small number to offset the first/last color stops so we can insert ones to
  12758. // support extend. Number.MIN_VALUE appears to be too small and breaks the
  12759. // extend. 1e-7 works in FF but chrome seems to use an even smaller sized number
  12760. // internally so we have to go bigger.
  12761. Shadings.SMALL_NUMBER = 1e-2;
  12762. // Radial and axial shading have very similar implementations
  12763. // If needed, the implementations can be broken into two classes
  12764. Shadings.RadialAxial = (function RadialAxialClosure() {
  12765. function RadialAxial(dict, matrix, xref, res) {
  12766. this.matrix = matrix;
  12767. this.coordsArr = dict.get('Coords');
  12768. this.shadingType = dict.get('ShadingType');
  12769. this.type = 'Pattern';
  12770. var cs = dict.get('ColorSpace', 'CS');
  12771. cs = ColorSpace.parse(cs, xref, res);
  12772. this.cs = cs;
  12773. var t0 = 0.0, t1 = 1.0;
  12774. if (dict.has('Domain')) {
  12775. var domainArr = dict.get('Domain');
  12776. t0 = domainArr[0];
  12777. t1 = domainArr[1];
  12778. }
  12779. var extendStart = false, extendEnd = false;
  12780. if (dict.has('Extend')) {
  12781. var extendArr = dict.get('Extend');
  12782. extendStart = extendArr[0];
  12783. extendEnd = extendArr[1];
  12784. }
  12785. if (this.shadingType === PatternType.RADIAL &&
  12786. (!extendStart || !extendEnd)) {
  12787. // Radial gradient only currently works if either circle is fully within
  12788. // the other circle.
  12789. var x1 = this.coordsArr[0];
  12790. var y1 = this.coordsArr[1];
  12791. var r1 = this.coordsArr[2];
  12792. var x2 = this.coordsArr[3];
  12793. var y2 = this.coordsArr[4];
  12794. var r2 = this.coordsArr[5];
  12795. var distance = Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
  12796. if (r1 <= r2 + distance &&
  12797. r2 <= r1 + distance) {
  12798. warn('Unsupported radial gradient.');
  12799. }
  12800. }
  12801. this.extendStart = extendStart;
  12802. this.extendEnd = extendEnd;
  12803. var fnObj = dict.get('Function');
  12804. var fn = PDFFunction.parseArray(xref, fnObj);
  12805. // 10 samples seems good enough for now, but probably won't work
  12806. // if there are sharp color changes. Ideally, we would implement
  12807. // the spec faithfully and add lossless optimizations.
  12808. var diff = t1 - t0;
  12809. var step = diff / 10;
  12810. var colorStops = this.colorStops = [];
  12811. // Protect against bad domains so we don't end up in an infinte loop below.
  12812. if (t0 >= t1 || step <= 0) {
  12813. // Acrobat doesn't seem to handle these cases so we'll ignore for
  12814. // now.
  12815. info('Bad shading domain.');
  12816. return;
  12817. }
  12818. var color = new Float32Array(cs.numComps), ratio = new Float32Array(1);
  12819. var rgbColor;
  12820. for (var i = t0; i <= t1; i += step) {
  12821. ratio[0] = i;
  12822. fn(ratio, 0, color, 0);
  12823. rgbColor = cs.getRgb(color, 0);
  12824. var cssColor = Util.makeCssRgb(rgbColor);
  12825. colorStops.push([(i - t0) / diff, cssColor]);
  12826. }
  12827. var background = 'transparent';
  12828. if (dict.has('Background')) {
  12829. rgbColor = cs.getRgb(dict.get('Background'), 0);
  12830. background = Util.makeCssRgb(rgbColor);
  12831. }
  12832. if (!extendStart) {
  12833. // Insert a color stop at the front and offset the first real color stop
  12834. // so it doesn't conflict with the one we insert.
  12835. colorStops.unshift([0, background]);
  12836. colorStops[1][0] += Shadings.SMALL_NUMBER;
  12837. }
  12838. if (!extendEnd) {
  12839. // Same idea as above in extendStart but for the end.
  12840. colorStops[colorStops.length - 1][0] -= Shadings.SMALL_NUMBER;
  12841. colorStops.push([1, background]);
  12842. }
  12843. this.colorStops = colorStops;
  12844. }
  12845. RadialAxial.prototype = {
  12846. getIR: function RadialAxial_getIR() {
  12847. var coordsArr = this.coordsArr;
  12848. var shadingType = this.shadingType;
  12849. var type, p0, p1, r0, r1;
  12850. if (shadingType === PatternType.AXIAL) {
  12851. p0 = [coordsArr[0], coordsArr[1]];
  12852. p1 = [coordsArr[2], coordsArr[3]];
  12853. r0 = null;
  12854. r1 = null;
  12855. type = 'axial';
  12856. } else if (shadingType === PatternType.RADIAL) {
  12857. p0 = [coordsArr[0], coordsArr[1]];
  12858. p1 = [coordsArr[3], coordsArr[4]];
  12859. r0 = coordsArr[2];
  12860. r1 = coordsArr[5];
  12861. type = 'radial';
  12862. } else {
  12863. error('getPattern type unknown: ' + shadingType);
  12864. }
  12865. var matrix = this.matrix;
  12866. if (matrix) {
  12867. p0 = Util.applyTransform(p0, matrix);
  12868. p1 = Util.applyTransform(p1, matrix);
  12869. }
  12870. return ['RadialAxial', type, this.colorStops, p0, p1, r0, r1];
  12871. }
  12872. };
  12873. return RadialAxial;
  12874. })();
  12875. // All mesh shading. For now, they will be presented as set of the triangles
  12876. // to be drawn on the canvas and rgb color for each vertex.
  12877. Shadings.Mesh = (function MeshClosure() {
  12878. function MeshStreamReader(stream, context) {
  12879. this.stream = stream;
  12880. this.context = context;
  12881. this.buffer = 0;
  12882. this.bufferLength = 0;
  12883. var numComps = context.numComps;
  12884. this.tmpCompsBuf = new Float32Array(numComps);
  12885. var csNumComps = context.colorSpace;
  12886. this.tmpCsCompsBuf = context.colorFn ? new Float32Array(csNumComps) :
  12887. this.tmpCompsBuf;
  12888. }
  12889. MeshStreamReader.prototype = {
  12890. get hasData() {
  12891. if (this.stream.end) {
  12892. return this.stream.pos < this.stream.end;
  12893. }
  12894. if (this.bufferLength > 0) {
  12895. return true;
  12896. }
  12897. var nextByte = this.stream.getByte();
  12898. if (nextByte < 0) {
  12899. return false;
  12900. }
  12901. this.buffer = nextByte;
  12902. this.bufferLength = 8;
  12903. return true;
  12904. },
  12905. readBits: function MeshStreamReader_readBits(n) {
  12906. var buffer = this.buffer;
  12907. var bufferLength = this.bufferLength;
  12908. if (n === 32) {
  12909. if (bufferLength === 0) {
  12910. return ((this.stream.getByte() << 24) |
  12911. (this.stream.getByte() << 16) | (this.stream.getByte() << 8) |
  12912. this.stream.getByte()) >>> 0;
  12913. }
  12914. buffer = (buffer << 24) | (this.stream.getByte() << 16) |
  12915. (this.stream.getByte() << 8) | this.stream.getByte();
  12916. var nextByte = this.stream.getByte();
  12917. this.buffer = nextByte & ((1 << bufferLength) - 1);
  12918. return ((buffer << (8 - bufferLength)) |
  12919. ((nextByte & 0xFF) >> bufferLength)) >>> 0;
  12920. }
  12921. if (n === 8 && bufferLength === 0) {
  12922. return this.stream.getByte();
  12923. }
  12924. while (bufferLength < n) {
  12925. buffer = (buffer << 8) | this.stream.getByte();
  12926. bufferLength += 8;
  12927. }
  12928. bufferLength -= n;
  12929. this.bufferLength = bufferLength;
  12930. this.buffer = buffer & ((1 << bufferLength) - 1);
  12931. return buffer >> bufferLength;
  12932. },
  12933. align: function MeshStreamReader_align() {
  12934. this.buffer = 0;
  12935. this.bufferLength = 0;
  12936. },
  12937. readFlag: function MeshStreamReader_readFlag() {
  12938. return this.readBits(this.context.bitsPerFlag);
  12939. },
  12940. readCoordinate: function MeshStreamReader_readCoordinate() {
  12941. var bitsPerCoordinate = this.context.bitsPerCoordinate;
  12942. var xi = this.readBits(bitsPerCoordinate);
  12943. var yi = this.readBits(bitsPerCoordinate);
  12944. var decode = this.context.decode;
  12945. var scale = bitsPerCoordinate < 32 ? 1 / ((1 << bitsPerCoordinate) - 1) :
  12946. 2.3283064365386963e-10; // 2 ^ -32
  12947. return [
  12948. xi * scale * (decode[1] - decode[0]) + decode[0],
  12949. yi * scale * (decode[3] - decode[2]) + decode[2]
  12950. ];
  12951. },
  12952. readComponents: function MeshStreamReader_readComponents() {
  12953. var numComps = this.context.numComps;
  12954. var bitsPerComponent = this.context.bitsPerComponent;
  12955. var scale = bitsPerComponent < 32 ? 1 / ((1 << bitsPerComponent) - 1) :
  12956. 2.3283064365386963e-10; // 2 ^ -32
  12957. var decode = this.context.decode;
  12958. var components = this.tmpCompsBuf;
  12959. for (var i = 0, j = 4; i < numComps; i++, j += 2) {
  12960. var ci = this.readBits(bitsPerComponent);
  12961. components[i] = ci * scale * (decode[j + 1] - decode[j]) + decode[j];
  12962. }
  12963. var color = this.tmpCsCompsBuf;
  12964. if (this.context.colorFn) {
  12965. this.context.colorFn(components, 0, color, 0);
  12966. }
  12967. return this.context.colorSpace.getRgb(color, 0);
  12968. }
  12969. };
  12970. function decodeType4Shading(mesh, reader) {
  12971. var coords = mesh.coords;
  12972. var colors = mesh.colors;
  12973. var operators = [];
  12974. var ps = []; // not maintaining cs since that will match ps
  12975. var verticesLeft = 0; // assuming we have all data to start a new triangle
  12976. while (reader.hasData) {
  12977. var f = reader.readFlag();
  12978. var coord = reader.readCoordinate();
  12979. var color = reader.readComponents();
  12980. if (verticesLeft === 0) { // ignoring flags if we started a triangle
  12981. assert(0 <= f && f <= 2, 'Unknown type4 flag');
  12982. switch (f) {
  12983. case 0:
  12984. verticesLeft = 3;
  12985. break;
  12986. case 1:
  12987. ps.push(ps[ps.length - 2], ps[ps.length - 1]);
  12988. verticesLeft = 1;
  12989. break;
  12990. case 2:
  12991. ps.push(ps[ps.length - 3], ps[ps.length - 1]);
  12992. verticesLeft = 1;
  12993. break;
  12994. }
  12995. operators.push(f);
  12996. }
  12997. ps.push(coords.length);
  12998. coords.push(coord);
  12999. colors.push(color);
  13000. verticesLeft--;
  13001. reader.align();
  13002. }
  13003. var psPacked = new Int32Array(ps);
  13004. mesh.figures.push({
  13005. type: 'triangles',
  13006. coords: psPacked,
  13007. colors: psPacked
  13008. });
  13009. }
  13010. function decodeType5Shading(mesh, reader, verticesPerRow) {
  13011. var coords = mesh.coords;
  13012. var colors = mesh.colors;
  13013. var ps = []; // not maintaining cs since that will match ps
  13014. while (reader.hasData) {
  13015. var coord = reader.readCoordinate();
  13016. var color = reader.readComponents();
  13017. ps.push(coords.length);
  13018. coords.push(coord);
  13019. colors.push(color);
  13020. }
  13021. var psPacked = new Int32Array(ps);
  13022. mesh.figures.push({
  13023. type: 'lattice',
  13024. coords: psPacked,
  13025. colors: psPacked,
  13026. verticesPerRow: verticesPerRow
  13027. });
  13028. }
  13029. var MIN_SPLIT_PATCH_CHUNKS_AMOUNT = 3;
  13030. var MAX_SPLIT_PATCH_CHUNKS_AMOUNT = 20;
  13031. var TRIANGLE_DENSITY = 20; // count of triangles per entire mesh bounds
  13032. var getB = (function getBClosure() {
  13033. function buildB(count) {
  13034. var lut = [];
  13035. for (var i = 0; i <= count; i++) {
  13036. var t = i / count, t_ = 1 - t;
  13037. lut.push(new Float32Array([t_ * t_ * t_, 3 * t * t_ * t_,
  13038. 3 * t * t * t_, t * t * t]));
  13039. }
  13040. return lut;
  13041. }
  13042. var cache = [];
  13043. return function getB(count) {
  13044. if (!cache[count]) {
  13045. cache[count] = buildB(count);
  13046. }
  13047. return cache[count];
  13048. };
  13049. })();
  13050. function buildFigureFromPatch(mesh, index) {
  13051. var figure = mesh.figures[index];
  13052. assert(figure.type === 'patch', 'Unexpected patch mesh figure');
  13053. var coords = mesh.coords, colors = mesh.colors;
  13054. var pi = figure.coords;
  13055. var ci = figure.colors;
  13056. var figureMinX = Math.min(coords[pi[0]][0], coords[pi[3]][0],
  13057. coords[pi[12]][0], coords[pi[15]][0]);
  13058. var figureMinY = Math.min(coords[pi[0]][1], coords[pi[3]][1],
  13059. coords[pi[12]][1], coords[pi[15]][1]);
  13060. var figureMaxX = Math.max(coords[pi[0]][0], coords[pi[3]][0],
  13061. coords[pi[12]][0], coords[pi[15]][0]);
  13062. var figureMaxY = Math.max(coords[pi[0]][1], coords[pi[3]][1],
  13063. coords[pi[12]][1], coords[pi[15]][1]);
  13064. var splitXBy = Math.ceil((figureMaxX - figureMinX) * TRIANGLE_DENSITY /
  13065. (mesh.bounds[2] - mesh.bounds[0]));
  13066. splitXBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
  13067. Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitXBy));
  13068. var splitYBy = Math.ceil((figureMaxY - figureMinY) * TRIANGLE_DENSITY /
  13069. (mesh.bounds[3] - mesh.bounds[1]));
  13070. splitYBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
  13071. Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitYBy));
  13072. var verticesPerRow = splitXBy + 1;
  13073. var figureCoords = new Int32Array((splitYBy + 1) * verticesPerRow);
  13074. var figureColors = new Int32Array((splitYBy + 1) * verticesPerRow);
  13075. var k = 0;
  13076. var cl = new Uint8Array(3), cr = new Uint8Array(3);
  13077. var c0 = colors[ci[0]], c1 = colors[ci[1]],
  13078. c2 = colors[ci[2]], c3 = colors[ci[3]];
  13079. var bRow = getB(splitYBy), bCol = getB(splitXBy);
  13080. for (var row = 0; row <= splitYBy; row++) {
  13081. cl[0] = ((c0[0] * (splitYBy - row) + c2[0] * row) / splitYBy) | 0;
  13082. cl[1] = ((c0[1] * (splitYBy - row) + c2[1] * row) / splitYBy) | 0;
  13083. cl[2] = ((c0[2] * (splitYBy - row) + c2[2] * row) / splitYBy) | 0;
  13084. cr[0] = ((c1[0] * (splitYBy - row) + c3[0] * row) / splitYBy) | 0;
  13085. cr[1] = ((c1[1] * (splitYBy - row) + c3[1] * row) / splitYBy) | 0;
  13086. cr[2] = ((c1[2] * (splitYBy - row) + c3[2] * row) / splitYBy) | 0;
  13087. for (var col = 0; col <= splitXBy; col++, k++) {
  13088. if ((row === 0 || row === splitYBy) &&
  13089. (col === 0 || col === splitXBy)) {
  13090. continue;
  13091. }
  13092. var x = 0, y = 0;
  13093. var q = 0;
  13094. for (var i = 0; i <= 3; i++) {
  13095. for (var j = 0; j <= 3; j++, q++) {
  13096. var m = bRow[row][i] * bCol[col][j];
  13097. x += coords[pi[q]][0] * m;
  13098. y += coords[pi[q]][1] * m;
  13099. }
  13100. }
  13101. figureCoords[k] = coords.length;
  13102. coords.push([x, y]);
  13103. figureColors[k] = colors.length;
  13104. var newColor = new Uint8Array(3);
  13105. newColor[0] = ((cl[0] * (splitXBy - col) + cr[0] * col) / splitXBy) | 0;
  13106. newColor[1] = ((cl[1] * (splitXBy - col) + cr[1] * col) / splitXBy) | 0;
  13107. newColor[2] = ((cl[2] * (splitXBy - col) + cr[2] * col) / splitXBy) | 0;
  13108. colors.push(newColor);
  13109. }
  13110. }
  13111. figureCoords[0] = pi[0];
  13112. figureColors[0] = ci[0];
  13113. figureCoords[splitXBy] = pi[3];
  13114. figureColors[splitXBy] = ci[1];
  13115. figureCoords[verticesPerRow * splitYBy] = pi[12];
  13116. figureColors[verticesPerRow * splitYBy] = ci[2];
  13117. figureCoords[verticesPerRow * splitYBy + splitXBy] = pi[15];
  13118. figureColors[verticesPerRow * splitYBy + splitXBy] = ci[3];
  13119. mesh.figures[index] = {
  13120. type: 'lattice',
  13121. coords: figureCoords,
  13122. colors: figureColors,
  13123. verticesPerRow: verticesPerRow
  13124. };
  13125. }
  13126. function decodeType6Shading(mesh, reader) {
  13127. // A special case of Type 7. The p11, p12, p21, p22 automatically filled
  13128. var coords = mesh.coords;
  13129. var colors = mesh.colors;
  13130. var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
  13131. var cs = new Int32Array(4); // c00, c30, c03, c33
  13132. while (reader.hasData) {
  13133. var f = reader.readFlag();
  13134. assert(0 <= f && f <= 3, 'Unknown type6 flag');
  13135. var i, ii;
  13136. var pi = coords.length;
  13137. for (i = 0, ii = (f !== 0 ? 8 : 12); i < ii; i++) {
  13138. coords.push(reader.readCoordinate());
  13139. }
  13140. var ci = colors.length;
  13141. for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
  13142. colors.push(reader.readComponents());
  13143. }
  13144. var tmp1, tmp2, tmp3, tmp4;
  13145. switch (f) {
  13146. case 0:
  13147. ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
  13148. ps[ 8] = pi + 2; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 7;
  13149. ps[ 4] = pi + 1; /* calculated below */ ps[ 7] = pi + 8;
  13150. ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
  13151. cs[2] = ci + 1; cs[3] = ci + 2;
  13152. cs[0] = ci; cs[1] = ci + 3;
  13153. break;
  13154. case 1:
  13155. tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
  13156. ps[12] = pi + 5; ps[13] = pi + 4; ps[14] = pi + 3; ps[15] = pi + 2;
  13157. ps[ 8] = pi + 6; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 1;
  13158. ps[ 4] = pi + 7; /* calculated below */ ps[ 7] = pi;
  13159. ps[ 0] = tmp1; ps[ 1] = tmp2; ps[ 2] = tmp3; ps[ 3] = tmp4;
  13160. tmp1 = cs[2]; tmp2 = cs[3];
  13161. cs[2] = ci + 1; cs[3] = ci;
  13162. cs[0] = tmp1; cs[1] = tmp2;
  13163. break;
  13164. case 2:
  13165. ps[12] = ps[15]; ps[13] = pi + 7; ps[14] = pi + 6; ps[15] = pi + 5;
  13166. ps[ 8] = ps[11]; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 4;
  13167. ps[ 4] = ps[7]; /* calculated below */ ps[ 7] = pi + 3;
  13168. ps[ 0] = ps[3]; ps[ 1] = pi; ps[ 2] = pi + 1; ps[ 3] = pi + 2;
  13169. cs[2] = cs[3]; cs[3] = ci + 1;
  13170. cs[0] = cs[1]; cs[1] = ci;
  13171. break;
  13172. case 3:
  13173. ps[12] = ps[0]; ps[13] = ps[1]; ps[14] = ps[2]; ps[15] = ps[3];
  13174. ps[ 8] = pi; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 7;
  13175. ps[ 4] = pi + 1; /* calculated below */ ps[ 7] = pi + 6;
  13176. ps[ 0] = pi + 2; ps[ 1] = pi + 3; ps[ 2] = pi + 4; ps[ 3] = pi + 5;
  13177. cs[2] = cs[0]; cs[3] = cs[1];
  13178. cs[0] = ci; cs[1] = ci + 1;
  13179. break;
  13180. }
  13181. // set p11, p12, p21, p22
  13182. ps[5] = coords.length;
  13183. coords.push([
  13184. (-4 * coords[ps[0]][0] - coords[ps[15]][0] +
  13185. 6 * (coords[ps[4]][0] + coords[ps[1]][0]) -
  13186. 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
  13187. 3 * (coords[ps[13]][0] + coords[ps[7]][0])) / 9,
  13188. (-4 * coords[ps[0]][1] - coords[ps[15]][1] +
  13189. 6 * (coords[ps[4]][1] + coords[ps[1]][1]) -
  13190. 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
  13191. 3 * (coords[ps[13]][1] + coords[ps[7]][1])) / 9
  13192. ]);
  13193. ps[6] = coords.length;
  13194. coords.push([
  13195. (-4 * coords[ps[3]][0] - coords[ps[12]][0] +
  13196. 6 * (coords[ps[2]][0] + coords[ps[7]][0]) -
  13197. 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
  13198. 3 * (coords[ps[4]][0] + coords[ps[14]][0])) / 9,
  13199. (-4 * coords[ps[3]][1] - coords[ps[12]][1] +
  13200. 6 * (coords[ps[2]][1] + coords[ps[7]][1]) -
  13201. 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
  13202. 3 * (coords[ps[4]][1] + coords[ps[14]][1])) / 9
  13203. ]);
  13204. ps[9] = coords.length;
  13205. coords.push([
  13206. (-4 * coords[ps[12]][0] - coords[ps[3]][0] +
  13207. 6 * (coords[ps[8]][0] + coords[ps[13]][0]) -
  13208. 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
  13209. 3 * (coords[ps[11]][0] + coords[ps[1]][0])) / 9,
  13210. (-4 * coords[ps[12]][1] - coords[ps[3]][1] +
  13211. 6 * (coords[ps[8]][1] + coords[ps[13]][1]) -
  13212. 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
  13213. 3 * (coords[ps[11]][1] + coords[ps[1]][1])) / 9
  13214. ]);
  13215. ps[10] = coords.length;
  13216. coords.push([
  13217. (-4 * coords[ps[15]][0] - coords[ps[0]][0] +
  13218. 6 * (coords[ps[11]][0] + coords[ps[14]][0]) -
  13219. 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
  13220. 3 * (coords[ps[2]][0] + coords[ps[8]][0])) / 9,
  13221. (-4 * coords[ps[15]][1] - coords[ps[0]][1] +
  13222. 6 * (coords[ps[11]][1] + coords[ps[14]][1]) -
  13223. 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
  13224. 3 * (coords[ps[2]][1] + coords[ps[8]][1])) / 9
  13225. ]);
  13226. mesh.figures.push({
  13227. type: 'patch',
  13228. coords: new Int32Array(ps), // making copies of ps and cs
  13229. colors: new Int32Array(cs)
  13230. });
  13231. }
  13232. }
  13233. function decodeType7Shading(mesh, reader) {
  13234. var coords = mesh.coords;
  13235. var colors = mesh.colors;
  13236. var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
  13237. var cs = new Int32Array(4); // c00, c30, c03, c33
  13238. while (reader.hasData) {
  13239. var f = reader.readFlag();
  13240. assert(0 <= f && f <= 3, 'Unknown type7 flag');
  13241. var i, ii;
  13242. var pi = coords.length;
  13243. for (i = 0, ii = (f !== 0 ? 12 : 16); i < ii; i++) {
  13244. coords.push(reader.readCoordinate());
  13245. }
  13246. var ci = colors.length;
  13247. for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
  13248. colors.push(reader.readComponents());
  13249. }
  13250. var tmp1, tmp2, tmp3, tmp4;
  13251. switch (f) {
  13252. case 0:
  13253. ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
  13254. ps[ 8] = pi + 2; ps[ 9] = pi + 13; ps[10] = pi + 14; ps[11] = pi + 7;
  13255. ps[ 4] = pi + 1; ps[ 5] = pi + 12; ps[ 6] = pi + 15; ps[ 7] = pi + 8;
  13256. ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
  13257. cs[2] = ci + 1; cs[3] = ci + 2;
  13258. cs[0] = ci; cs[1] = ci + 3;
  13259. break;
  13260. case 1:
  13261. tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
  13262. ps[12] = pi + 5; ps[13] = pi + 4; ps[14] = pi + 3; ps[15] = pi + 2;
  13263. ps[ 8] = pi + 6; ps[ 9] = pi + 11; ps[10] = pi + 10; ps[11] = pi + 1;
  13264. ps[ 4] = pi + 7; ps[ 5] = pi + 8; ps[ 6] = pi + 9; ps[ 7] = pi;
  13265. ps[ 0] = tmp1; ps[ 1] = tmp2; ps[ 2] = tmp3; ps[ 3] = tmp4;
  13266. tmp1 = cs[2]; tmp2 = cs[3];
  13267. cs[2] = ci + 1; cs[3] = ci;
  13268. cs[0] = tmp1; cs[1] = tmp2;
  13269. break;
  13270. case 2:
  13271. ps[12] = ps[15]; ps[13] = pi + 7; ps[14] = pi + 6; ps[15] = pi + 5;
  13272. ps[ 8] = ps[11]; ps[ 9] = pi + 8; ps[10] = pi + 11; ps[11] = pi + 4;
  13273. ps[ 4] = ps[7]; ps[ 5] = pi + 9; ps[ 6] = pi + 10; ps[ 7] = pi + 3;
  13274. ps[ 0] = ps[3]; ps[ 1] = pi; ps[ 2] = pi + 1; ps[ 3] = pi + 2;
  13275. cs[2] = cs[3]; cs[3] = ci + 1;
  13276. cs[0] = cs[1]; cs[1] = ci;
  13277. break;
  13278. case 3:
  13279. ps[12] = ps[0]; ps[13] = ps[1]; ps[14] = ps[2]; ps[15] = ps[3];
  13280. ps[ 8] = pi; ps[ 9] = pi + 9; ps[10] = pi + 8; ps[11] = pi + 7;
  13281. ps[ 4] = pi + 1; ps[ 5] = pi + 10; ps[ 6] = pi + 11; ps[ 7] = pi + 6;
  13282. ps[ 0] = pi + 2; ps[ 1] = pi + 3; ps[ 2] = pi + 4; ps[ 3] = pi + 5;
  13283. cs[2] = cs[0]; cs[3] = cs[1];
  13284. cs[0] = ci; cs[1] = ci + 1;
  13285. break;
  13286. }
  13287. mesh.figures.push({
  13288. type: 'patch',
  13289. coords: new Int32Array(ps), // making copies of ps and cs
  13290. colors: new Int32Array(cs)
  13291. });
  13292. }
  13293. }
  13294. function updateBounds(mesh) {
  13295. var minX = mesh.coords[0][0], minY = mesh.coords[0][1],
  13296. maxX = minX, maxY = minY;
  13297. for (var i = 1, ii = mesh.coords.length; i < ii; i++) {
  13298. var x = mesh.coords[i][0], y = mesh.coords[i][1];
  13299. minX = minX > x ? x : minX;
  13300. minY = minY > y ? y : minY;
  13301. maxX = maxX < x ? x : maxX;
  13302. maxY = maxY < y ? y : maxY;
  13303. }
  13304. mesh.bounds = [minX, minY, maxX, maxY];
  13305. }
  13306. function packData(mesh) {
  13307. var i, ii, j, jj;
  13308. var coords = mesh.coords;
  13309. var coordsPacked = new Float32Array(coords.length * 2);
  13310. for (i = 0, j = 0, ii = coords.length; i < ii; i++) {
  13311. var xy = coords[i];
  13312. coordsPacked[j++] = xy[0];
  13313. coordsPacked[j++] = xy[1];
  13314. }
  13315. mesh.coords = coordsPacked;
  13316. var colors = mesh.colors;
  13317. var colorsPacked = new Uint8Array(colors.length * 3);
  13318. for (i = 0, j = 0, ii = colors.length; i < ii; i++) {
  13319. var c = colors[i];
  13320. colorsPacked[j++] = c[0];
  13321. colorsPacked[j++] = c[1];
  13322. colorsPacked[j++] = c[2];
  13323. }
  13324. mesh.colors = colorsPacked;
  13325. var figures = mesh.figures;
  13326. for (i = 0, ii = figures.length; i < ii; i++) {
  13327. var figure = figures[i], ps = figure.coords, cs = figure.colors;
  13328. for (j = 0, jj = ps.length; j < jj; j++) {
  13329. ps[j] *= 2;
  13330. cs[j] *= 3;
  13331. }
  13332. }
  13333. }
  13334. function Mesh(stream, matrix, xref, res) {
  13335. assert(isStream(stream), 'Mesh data is not a stream');
  13336. var dict = stream.dict;
  13337. this.matrix = matrix;
  13338. this.shadingType = dict.get('ShadingType');
  13339. this.type = 'Pattern';
  13340. this.bbox = dict.get('BBox');
  13341. var cs = dict.get('ColorSpace', 'CS');
  13342. cs = ColorSpace.parse(cs, xref, res);
  13343. this.cs = cs;
  13344. this.background = dict.has('Background') ?
  13345. cs.getRgb(dict.get('Background'), 0) : null;
  13346. var fnObj = dict.get('Function');
  13347. var fn = fnObj ? PDFFunction.parseArray(xref, fnObj) : null;
  13348. this.coords = [];
  13349. this.colors = [];
  13350. this.figures = [];
  13351. var decodeContext = {
  13352. bitsPerCoordinate: dict.get('BitsPerCoordinate'),
  13353. bitsPerComponent: dict.get('BitsPerComponent'),
  13354. bitsPerFlag: dict.get('BitsPerFlag'),
  13355. decode: dict.get('Decode'),
  13356. colorFn: fn,
  13357. colorSpace: cs,
  13358. numComps: fn ? 1 : cs.numComps
  13359. };
  13360. var reader = new MeshStreamReader(stream, decodeContext);
  13361. var patchMesh = false;
  13362. switch (this.shadingType) {
  13363. case PatternType.FREE_FORM_MESH:
  13364. decodeType4Shading(this, reader);
  13365. break;
  13366. case PatternType.LATTICE_FORM_MESH:
  13367. var verticesPerRow = dict.get('VerticesPerRow') | 0;
  13368. assert(verticesPerRow >= 2, 'Invalid VerticesPerRow');
  13369. decodeType5Shading(this, reader, verticesPerRow);
  13370. break;
  13371. case PatternType.COONS_PATCH_MESH:
  13372. decodeType6Shading(this, reader);
  13373. patchMesh = true;
  13374. break;
  13375. case PatternType.TENSOR_PATCH_MESH:
  13376. decodeType7Shading(this, reader);
  13377. patchMesh = true;
  13378. break;
  13379. default:
  13380. error('Unsupported mesh type.');
  13381. break;
  13382. }
  13383. if (patchMesh) {
  13384. // dirty bounds calculation for determining, how dense shall be triangles
  13385. updateBounds(this);
  13386. for (var i = 0, ii = this.figures.length; i < ii; i++) {
  13387. buildFigureFromPatch(this, i);
  13388. }
  13389. }
  13390. // calculate bounds
  13391. updateBounds(this);
  13392. packData(this);
  13393. }
  13394. Mesh.prototype = {
  13395. getIR: function Mesh_getIR() {
  13396. return ['Mesh', this.shadingType, this.coords, this.colors, this.figures,
  13397. this.bounds, this.matrix, this.bbox, this.background];
  13398. }
  13399. };
  13400. return Mesh;
  13401. })();
  13402. Shadings.Dummy = (function DummyClosure() {
  13403. function Dummy() {
  13404. this.type = 'Pattern';
  13405. }
  13406. Dummy.prototype = {
  13407. getIR: function Dummy_getIR() {
  13408. return ['Dummy'];
  13409. }
  13410. };
  13411. return Dummy;
  13412. })();
  13413. function getTilingPatternIR(operatorList, dict, args) {
  13414. var matrix = dict.get('Matrix');
  13415. var bbox = dict.get('BBox');
  13416. var xstep = dict.get('XStep');
  13417. var ystep = dict.get('YStep');
  13418. var paintType = dict.get('PaintType');
  13419. var tilingType = dict.get('TilingType');
  13420. return [
  13421. 'TilingPattern', args, operatorList, matrix, bbox, xstep, ystep,
  13422. paintType, tilingType
  13423. ];
  13424. }
  13425. var PartialEvaluator = (function PartialEvaluatorClosure() {
  13426. function PartialEvaluator(pdfManager, xref, handler, pageIndex,
  13427. uniquePrefix, idCounters, fontCache) {
  13428. this.pdfManager = pdfManager;
  13429. this.xref = xref;
  13430. this.handler = handler;
  13431. this.pageIndex = pageIndex;
  13432. this.uniquePrefix = uniquePrefix;
  13433. this.idCounters = idCounters;
  13434. this.fontCache = fontCache;
  13435. }
  13436. // Trying to minimize Date.now() usage and check every 100 time
  13437. var TIME_SLOT_DURATION_MS = 20;
  13438. var CHECK_TIME_EVERY = 100;
  13439. function TimeSlotManager() {
  13440. this.reset();
  13441. }
  13442. TimeSlotManager.prototype = {
  13443. check: function TimeSlotManager_check() {
  13444. if (++this.checked < CHECK_TIME_EVERY) {
  13445. return false;
  13446. }
  13447. this.checked = 0;
  13448. return this.endTime <= Date.now();
  13449. },
  13450. reset: function TimeSlotManager_reset() {
  13451. this.endTime = Date.now() + TIME_SLOT_DURATION_MS;
  13452. this.checked = 0;
  13453. }
  13454. };
  13455. var deferred = Promise.resolve();
  13456. var TILING_PATTERN = 1, SHADING_PATTERN = 2;
  13457. PartialEvaluator.prototype = {
  13458. hasBlendModes: function PartialEvaluator_hasBlendModes(resources) {
  13459. if (!isDict(resources)) {
  13460. return false;
  13461. }
  13462. var processed = Object.create(null);
  13463. if (resources.objId) {
  13464. processed[resources.objId] = true;
  13465. }
  13466. var nodes = [resources];
  13467. while (nodes.length) {
  13468. var key;
  13469. var node = nodes.shift();
  13470. // First check the current resources for blend modes.
  13471. var graphicStates = node.get('ExtGState');
  13472. if (isDict(graphicStates)) {
  13473. graphicStates = graphicStates.getAll();
  13474. for (key in graphicStates) {
  13475. var graphicState = graphicStates[key];
  13476. var bm = graphicState['BM'];
  13477. if (isName(bm) && bm.name !== 'Normal') {
  13478. return true;
  13479. }
  13480. }
  13481. }
  13482. // Descend into the XObjects to look for more resources and blend modes.
  13483. var xObjects = node.get('XObject');
  13484. if (!isDict(xObjects)) {
  13485. continue;
  13486. }
  13487. xObjects = xObjects.getAll();
  13488. for (key in xObjects) {
  13489. var xObject = xObjects[key];
  13490. if (!isStream(xObject)) {
  13491. continue;
  13492. }
  13493. if (xObject.dict.objId) {
  13494. if (processed[xObject.dict.objId]) {
  13495. // stream has objId and is processed already
  13496. continue;
  13497. }
  13498. processed[xObject.dict.objId] = true;
  13499. }
  13500. var xResources = xObject.dict.get('Resources');
  13501. // Checking objId to detect an infinite loop.
  13502. if (isDict(xResources) &&
  13503. (!xResources.objId || !processed[xResources.objId])) {
  13504. nodes.push(xResources);
  13505. if (xResources.objId) {
  13506. processed[xResources.objId] = true;
  13507. }
  13508. }
  13509. }
  13510. }
  13511. return false;
  13512. },
  13513. buildFormXObject: function PartialEvaluator_buildFormXObject(resources,
  13514. xobj, smask,
  13515. operatorList,
  13516. initialState) {
  13517. var matrix = xobj.dict.get('Matrix');
  13518. var bbox = xobj.dict.get('BBox');
  13519. var group = xobj.dict.get('Group');
  13520. if (group) {
  13521. var groupOptions = {
  13522. matrix: matrix,
  13523. bbox: bbox,
  13524. smask: smask,
  13525. isolated: false,
  13526. knockout: false
  13527. };
  13528. var groupSubtype = group.get('S');
  13529. var colorSpace;
  13530. if (isName(groupSubtype) && groupSubtype.name === 'Transparency') {
  13531. groupOptions.isolated = (group.get('I') || false);
  13532. groupOptions.knockout = (group.get('K') || false);
  13533. colorSpace = (group.has('CS') ?
  13534. ColorSpace.parse(group.get('CS'), this.xref, resources) : null);
  13535. }
  13536. if (smask && smask.backdrop) {
  13537. colorSpace = colorSpace || ColorSpace.singletons.rgb;
  13538. smask.backdrop = colorSpace.getRgb(smask.backdrop, 0);
  13539. }
  13540. operatorList.addOp(OPS.beginGroup, [groupOptions]);
  13541. }
  13542. operatorList.addOp(OPS.paintFormXObjectBegin, [matrix, bbox]);
  13543. return this.getOperatorList(xobj,
  13544. (xobj.dict.get('Resources') || resources), operatorList, initialState).
  13545. then(function () {
  13546. operatorList.addOp(OPS.paintFormXObjectEnd, []);
  13547. if (group) {
  13548. operatorList.addOp(OPS.endGroup, [groupOptions]);
  13549. }
  13550. });
  13551. },
  13552. buildPaintImageXObject:
  13553. function PartialEvaluator_buildPaintImageXObject(resources, image,
  13554. inline, operatorList,
  13555. cacheKey, cache) {
  13556. var self = this;
  13557. var dict = image.dict;
  13558. var w = dict.get('Width', 'W');
  13559. var h = dict.get('Height', 'H');
  13560. if (!(w && isNum(w)) || !(h && isNum(h))) {
  13561. warn('Image dimensions are missing, or not numbers.');
  13562. return;
  13563. }
  13564. if (PDFJS.maxImageSize !== -1 && w * h > PDFJS.maxImageSize) {
  13565. warn('Image exceeded maximum allowed size and was removed.');
  13566. return;
  13567. }
  13568. var imageMask = (dict.get('ImageMask', 'IM') || false);
  13569. var imgData, args;
  13570. if (imageMask) {
  13571. // This depends on a tmpCanvas being filled with the
  13572. // current fillStyle, such that processing the pixel
  13573. // data can't be done here. Instead of creating a
  13574. // complete PDFImage, only read the information needed
  13575. // for later.
  13576. var width = dict.get('Width', 'W');
  13577. var height = dict.get('Height', 'H');
  13578. var bitStrideLength = (width + 7) >> 3;
  13579. var imgArray = image.getBytes(bitStrideLength * height);
  13580. var decode = dict.get('Decode', 'D');
  13581. var inverseDecode = (!!decode && decode[0] > 0);
  13582. imgData = PDFImage.createMask(imgArray, width, height,
  13583. image instanceof DecodeStream,
  13584. inverseDecode);
  13585. imgData.cached = true;
  13586. args = [imgData];
  13587. operatorList.addOp(OPS.paintImageMaskXObject, args);
  13588. if (cacheKey) {
  13589. cache.key = cacheKey;
  13590. cache.fn = OPS.paintImageMaskXObject;
  13591. cache.args = args;
  13592. }
  13593. return;
  13594. }
  13595. var softMask = (dict.get('SMask', 'SM') || false);
  13596. var mask = (dict.get('Mask') || false);
  13597. var SMALL_IMAGE_DIMENSIONS = 200;
  13598. // Inlining small images into the queue as RGB data
  13599. if (inline && !softMask && !mask && !(image instanceof JpegStream) &&
  13600. (w + h) < SMALL_IMAGE_DIMENSIONS) {
  13601. var imageObj = new PDFImage(this.xref, resources, image,
  13602. inline, null, null);
  13603. // We force the use of RGBA_32BPP images here, because we can't handle
  13604. // any other kind.
  13605. imgData = imageObj.createImageData(/* forceRGBA = */ true);
  13606. operatorList.addOp(OPS.paintInlineImageXObject, [imgData]);
  13607. return;
  13608. }
  13609. // If there is no imageMask, create the PDFImage and a lot
  13610. // of image processing can be done here.
  13611. var uniquePrefix = (this.uniquePrefix || '');
  13612. var objId = 'img_' + uniquePrefix + (++this.idCounters.obj);
  13613. operatorList.addDependency(objId);
  13614. args = [objId, w, h];
  13615. if (!softMask && !mask && image instanceof JpegStream &&
  13616. image.isNativelySupported(this.xref, resources)) {
  13617. // These JPEGs don't need any more processing so we can just send it.
  13618. operatorList.addOp(OPS.paintJpegXObject, args);
  13619. this.handler.send('obj',
  13620. [objId, this.pageIndex, 'JpegStream', image.getIR()]);
  13621. return;
  13622. }
  13623. PDFImage.buildImage(self.handler, self.xref, resources, image, inline).
  13624. then(function(imageObj) {
  13625. var imgData = imageObj.createImageData(/* forceRGBA = */ false);
  13626. self.handler.send('obj', [objId, self.pageIndex, 'Image', imgData],
  13627. [imgData.data.buffer]);
  13628. }).then(null, function (reason) {
  13629. warn('Unable to decode image: ' + reason);
  13630. self.handler.send('obj', [objId, self.pageIndex, 'Image', null]);
  13631. });
  13632. operatorList.addOp(OPS.paintImageXObject, args);
  13633. if (cacheKey) {
  13634. cache.key = cacheKey;
  13635. cache.fn = OPS.paintImageXObject;
  13636. cache.args = args;
  13637. }
  13638. },
  13639. handleSMask: function PartialEvaluator_handleSmask(smask, resources,
  13640. operatorList,
  13641. stateManager) {
  13642. var smaskContent = smask.get('G');
  13643. var smaskOptions = {
  13644. subtype: smask.get('S').name,
  13645. backdrop: smask.get('BC')
  13646. };
  13647. return this.buildFormXObject(resources, smaskContent, smaskOptions,
  13648. operatorList, stateManager.state.clone());
  13649. },
  13650. handleTilingType:
  13651. function PartialEvaluator_handleTilingType(fn, args, resources,
  13652. pattern, patternDict,
  13653. operatorList) {
  13654. // Create an IR of the pattern code.
  13655. var tilingOpList = new OperatorList();
  13656. return this.getOperatorList(pattern,
  13657. (patternDict.get('Resources') || resources), tilingOpList).
  13658. then(function () {
  13659. // Add the dependencies to the parent operator list so they are
  13660. // resolved before sub operator list is executed synchronously.
  13661. operatorList.addDependencies(tilingOpList.dependencies);
  13662. operatorList.addOp(fn, getTilingPatternIR({
  13663. fnArray: tilingOpList.fnArray,
  13664. argsArray: tilingOpList.argsArray
  13665. }, patternDict, args));
  13666. });
  13667. },
  13668. handleSetFont:
  13669. function PartialEvaluator_handleSetFont(resources, fontArgs, fontRef,
  13670. operatorList, state) {
  13671. // TODO(mack): Not needed?
  13672. var fontName;
  13673. if (fontArgs) {
  13674. fontArgs = fontArgs.slice();
  13675. fontName = fontArgs[0].name;
  13676. }
  13677. var self = this;
  13678. return this.loadFont(fontName, fontRef, this.xref, resources).then(
  13679. function (translated) {
  13680. if (!translated.font.isType3Font) {
  13681. return translated;
  13682. }
  13683. return translated.loadType3Data(self, resources, operatorList).then(
  13684. function () {
  13685. return translated;
  13686. });
  13687. }).then(function (translated) {
  13688. state.font = translated.font;
  13689. translated.send(self.handler);
  13690. return translated.loadedName;
  13691. });
  13692. },
  13693. handleText: function PartialEvaluator_handleText(chars, state) {
  13694. var font = state.font;
  13695. var glyphs = font.charsToGlyphs(chars);
  13696. var isAddToPathSet = !!(state.textRenderingMode &
  13697. TextRenderingMode.ADD_TO_PATH_FLAG);
  13698. if (font.data && (isAddToPathSet || PDFJS.disableFontFace)) {
  13699. var buildPath = function (fontChar) {
  13700. if (!font.renderer.hasBuiltPath(fontChar)) {
  13701. var path = font.renderer.getPathJs(fontChar);
  13702. this.handler.send('commonobj', [
  13703. font.loadedName + '_path_' + fontChar,
  13704. 'FontPath',
  13705. path
  13706. ]);
  13707. }
  13708. }.bind(this);
  13709. for (var i = 0, ii = glyphs.length; i < ii; i++) {
  13710. var glyph = glyphs[i];
  13711. if (glyph === null) {
  13712. continue;
  13713. }
  13714. buildPath(glyph.fontChar);
  13715. // If the glyph has an accent we need to build a path for its
  13716. // fontChar too, otherwise CanvasGraphics_paintChar will fail.
  13717. var accent = glyph.accent;
  13718. if (accent && accent.fontChar) {
  13719. buildPath(accent.fontChar);
  13720. }
  13721. }
  13722. }
  13723. return glyphs;
  13724. },
  13725. setGState: function PartialEvaluator_setGState(resources, gState,
  13726. operatorList, xref,
  13727. stateManager) {
  13728. // TODO(mack): This should be rewritten so that this function returns
  13729. // what should be added to the queue during each iteration
  13730. function setGStateForKey(gStateObj, key, value) {
  13731. switch (key) {
  13732. case 'Type':
  13733. break;
  13734. case 'LW':
  13735. case 'LC':
  13736. case 'LJ':
  13737. case 'ML':
  13738. case 'D':
  13739. case 'RI':
  13740. case 'FL':
  13741. case 'CA':
  13742. case 'ca':
  13743. gStateObj.push([key, value]);
  13744. break;
  13745. case 'Font':
  13746. promise = promise.then(function () {
  13747. return self.handleSetFont(resources, null, value[0],
  13748. operatorList, stateManager.state).
  13749. then(function (loadedName) {
  13750. operatorList.addDependency(loadedName);
  13751. gStateObj.push([key, [loadedName, value[1]]]);
  13752. });
  13753. });
  13754. break;
  13755. case 'BM':
  13756. gStateObj.push([key, value]);
  13757. break;
  13758. case 'SMask':
  13759. if (isName(value) && value.name === 'None') {
  13760. gStateObj.push([key, false]);
  13761. break;
  13762. }
  13763. var dict = xref.fetchIfRef(value);
  13764. if (isDict(dict)) {
  13765. promise = promise.then(function () {
  13766. return self.handleSMask(dict, resources, operatorList,
  13767. stateManager);
  13768. });
  13769. gStateObj.push([key, true]);
  13770. } else {
  13771. warn('Unsupported SMask type');
  13772. }
  13773. break;
  13774. // Only generate info log messages for the following since
  13775. // they are unlikey to have a big impact on the rendering.
  13776. case 'OP':
  13777. case 'op':
  13778. case 'OPM':
  13779. case 'BG':
  13780. case 'BG2':
  13781. case 'UCR':
  13782. case 'UCR2':
  13783. case 'TR':
  13784. case 'TR2':
  13785. case 'HT':
  13786. case 'SM':
  13787. case 'SA':
  13788. case 'AIS':
  13789. case 'TK':
  13790. // TODO implement these operators.
  13791. info('graphic state operator ' + key);
  13792. break;
  13793. default:
  13794. info('Unknown graphic state operator ' + key);
  13795. break;
  13796. }
  13797. }
  13798. // This array holds the converted/processed state data.
  13799. var gStateObj = [];
  13800. var gStateMap = gState.map;
  13801. var self = this;
  13802. var promise = Promise.resolve();
  13803. for (var key in gStateMap) {
  13804. var value = gStateMap[key];
  13805. setGStateForKey(gStateObj, key, value);
  13806. }
  13807. return promise.then(function () {
  13808. operatorList.addOp(OPS.setGState, [gStateObj]);
  13809. });
  13810. },
  13811. loadFont: function PartialEvaluator_loadFont(fontName, font, xref,
  13812. resources) {
  13813. function errorFont() {
  13814. return Promise.resolve(new TranslatedFont('g_font_error',
  13815. new ErrorFont('Font ' + fontName + ' is not available'), font));
  13816. }
  13817. var fontRef;
  13818. if (font) { // Loading by ref.
  13819. assert(isRef(font));
  13820. fontRef = font;
  13821. } else { // Loading by name.
  13822. var fontRes = resources.get('Font');
  13823. if (fontRes) {
  13824. fontRef = fontRes.getRaw(fontName);
  13825. } else {
  13826. warn('fontRes not available');
  13827. return errorFont();
  13828. }
  13829. }
  13830. if (!fontRef) {
  13831. warn('fontRef not available');
  13832. return errorFont();
  13833. }
  13834. if (this.fontCache.has(fontRef)) {
  13835. return this.fontCache.get(fontRef);
  13836. }
  13837. font = xref.fetchIfRef(fontRef);
  13838. if (!isDict(font)) {
  13839. return errorFont();
  13840. }
  13841. // We are holding font.translated references just for fontRef that are not
  13842. // dictionaries (Dict). See explanation below.
  13843. if (font.translated) {
  13844. return font.translated;
  13845. }
  13846. var fontCapability = createPromiseCapability();
  13847. var preEvaluatedFont = this.preEvaluateFont(font, xref);
  13848. var descriptor = preEvaluatedFont.descriptor;
  13849. var fontID = fontRef.num + '_' + fontRef.gen;
  13850. if (isDict(descriptor)) {
  13851. if (!descriptor.fontAliases) {
  13852. descriptor.fontAliases = Object.create(null);
  13853. }
  13854. var fontAliases = descriptor.fontAliases;
  13855. var hash = preEvaluatedFont.hash;
  13856. if (fontAliases[hash]) {
  13857. var aliasFontRef = fontAliases[hash].aliasRef;
  13858. if (aliasFontRef && this.fontCache.has(aliasFontRef)) {
  13859. this.fontCache.putAlias(fontRef, aliasFontRef);
  13860. return this.fontCache.get(fontRef);
  13861. }
  13862. }
  13863. if (!fontAliases[hash]) {
  13864. fontAliases[hash] = {
  13865. fontID: Font.getFontID()
  13866. };
  13867. }
  13868. fontAliases[hash].aliasRef = fontRef;
  13869. fontID = fontAliases[hash].fontID;
  13870. }
  13871. // Workaround for bad PDF generators that don't reference fonts
  13872. // properly, i.e. by not using an object identifier.
  13873. // Check if the fontRef is a Dict (as opposed to a standard object),
  13874. // in which case we don't cache the font and instead reference it by
  13875. // fontName in font.loadedName below.
  13876. var fontRefIsDict = isDict(fontRef);
  13877. if (!fontRefIsDict) {
  13878. this.fontCache.put(fontRef, fontCapability.promise);
  13879. }
  13880. // Keep track of each font we translated so the caller can
  13881. // load them asynchronously before calling display on a page.
  13882. font.loadedName = 'g_font_' + (fontRefIsDict ?
  13883. fontName.replace(/\W/g, '') : fontID);
  13884. font.translated = fontCapability.promise;
  13885. // TODO move promises into translate font
  13886. var translatedPromise;
  13887. try {
  13888. translatedPromise = Promise.resolve(
  13889. this.translateFont(preEvaluatedFont, xref));
  13890. } catch (e) {
  13891. translatedPromise = Promise.reject(e);
  13892. }
  13893. translatedPromise.then(function (translatedFont) {
  13894. if (translatedFont.fontType !== undefined) {
  13895. var xrefFontStats = xref.stats.fontTypes;
  13896. xrefFontStats[translatedFont.fontType] = true;
  13897. }
  13898. fontCapability.resolve(new TranslatedFont(font.loadedName,
  13899. translatedFont, font));
  13900. }, function (reason) {
  13901. // TODO fontCapability.reject?
  13902. UnsupportedManager.notify(UNSUPPORTED_FEATURES.font);
  13903. try {
  13904. // error, but it's still nice to have font type reported
  13905. var descriptor = preEvaluatedFont.descriptor;
  13906. var fontFile3 = descriptor && descriptor.get('FontFile3');
  13907. var subtype = fontFile3 && fontFile3.get('Subtype');
  13908. var fontType = getFontType(preEvaluatedFont.type,
  13909. subtype && subtype.name);
  13910. var xrefFontStats = xref.stats.fontTypes;
  13911. xrefFontStats[fontType] = true;
  13912. } catch (ex) { }
  13913. fontCapability.resolve(new TranslatedFont(font.loadedName,
  13914. new ErrorFont(reason instanceof Error ? reason.message : reason),
  13915. font));
  13916. });
  13917. return fontCapability.promise;
  13918. },
  13919. buildPath: function PartialEvaluator_buildPath(operatorList, fn, args) {
  13920. var lastIndex = operatorList.length - 1;
  13921. if (!args) {
  13922. args = [];
  13923. }
  13924. if (lastIndex < 0 ||
  13925. operatorList.fnArray[lastIndex] !== OPS.constructPath) {
  13926. operatorList.addOp(OPS.constructPath, [[fn], args]);
  13927. } else {
  13928. var opArgs = operatorList.argsArray[lastIndex];
  13929. opArgs[0].push(fn);
  13930. Array.prototype.push.apply(opArgs[1], args);
  13931. }
  13932. },
  13933. handleColorN: function PartialEvaluator_handleColorN(operatorList, fn, args,
  13934. cs, patterns, resources, xref) {
  13935. // compile tiling patterns
  13936. var patternName = args[args.length - 1];
  13937. // SCN/scn applies patterns along with normal colors
  13938. var pattern;
  13939. if (isName(patternName) &&
  13940. (pattern = patterns.get(patternName.name))) {
  13941. var dict = (isStream(pattern) ? pattern.dict : pattern);
  13942. var typeNum = dict.get('PatternType');
  13943. if (typeNum === TILING_PATTERN) {
  13944. var color = cs.base ? cs.base.getRgb(args, 0) : null;
  13945. return this.handleTilingType(fn, color, resources, pattern,
  13946. dict, operatorList);
  13947. } else if (typeNum === SHADING_PATTERN) {
  13948. var shading = dict.get('Shading');
  13949. var matrix = dict.get('Matrix');
  13950. pattern = Pattern.parseShading(shading, matrix, xref, resources);
  13951. operatorList.addOp(fn, pattern.getIR());
  13952. return Promise.resolve();
  13953. } else {
  13954. return Promise.reject('Unknown PatternType: ' + typeNum);
  13955. }
  13956. }
  13957. // TODO shall we fail here?
  13958. operatorList.addOp(fn, args);
  13959. return Promise.resolve();
  13960. },
  13961. getOperatorList: function PartialEvaluator_getOperatorList(stream,
  13962. resources,
  13963. operatorList,
  13964. initialState) {
  13965. var self = this;
  13966. var xref = this.xref;
  13967. var imageCache = {};
  13968. assert(operatorList);
  13969. resources = (resources || Dict.empty);
  13970. var xobjs = (resources.get('XObject') || Dict.empty);
  13971. var patterns = (resources.get('Pattern') || Dict.empty);
  13972. var stateManager = new StateManager(initialState || new EvalState());
  13973. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  13974. var timeSlotManager = new TimeSlotManager();
  13975. return new Promise(function next(resolve, reject) {
  13976. timeSlotManager.reset();
  13977. var stop, operation = {}, i, ii, cs;
  13978. while (!(stop = timeSlotManager.check()) &&
  13979. preprocessor.read(operation)) {
  13980. var args = operation.args;
  13981. var fn = operation.fn;
  13982. switch (fn | 0) {
  13983. case OPS.paintXObject:
  13984. if (args[0].code) {
  13985. break;
  13986. }
  13987. // eagerly compile XForm objects
  13988. var name = args[0].name;
  13989. if (imageCache.key === name) {
  13990. operatorList.addOp(imageCache.fn, imageCache.args);
  13991. args = null;
  13992. continue;
  13993. }
  13994. var xobj = xobjs.get(name);
  13995. if (xobj) {
  13996. assert(isStream(xobj), 'XObject should be a stream');
  13997. var type = xobj.dict.get('Subtype');
  13998. assert(isName(type),
  13999. 'XObject should have a Name subtype');
  14000. if (type.name === 'Form') {
  14001. stateManager.save();
  14002. return self.buildFormXObject(resources, xobj, null,
  14003. operatorList,
  14004. stateManager.state.clone()).
  14005. then(function () {
  14006. stateManager.restore();
  14007. next(resolve, reject);
  14008. }, reject);
  14009. } else if (type.name === 'Image') {
  14010. self.buildPaintImageXObject(resources, xobj, false,
  14011. operatorList, name, imageCache);
  14012. args = null;
  14013. continue;
  14014. } else if (type.name === 'PS') {
  14015. // PostScript XObjects are unused when viewing documents.
  14016. // See section 4.7.1 of Adobe's PDF reference.
  14017. info('Ignored XObject subtype PS');
  14018. continue;
  14019. } else {
  14020. error('Unhandled XObject subtype ' + type.name);
  14021. }
  14022. }
  14023. break;
  14024. case OPS.setFont:
  14025. var fontSize = args[1];
  14026. // eagerly collect all fonts
  14027. return self.handleSetFont(resources, args, null,
  14028. operatorList, stateManager.state).
  14029. then(function (loadedName) {
  14030. operatorList.addDependency(loadedName);
  14031. operatorList.addOp(OPS.setFont, [loadedName, fontSize]);
  14032. next(resolve, reject);
  14033. }, reject);
  14034. case OPS.endInlineImage:
  14035. var cacheKey = args[0].cacheKey;
  14036. if (cacheKey && imageCache.key === cacheKey) {
  14037. operatorList.addOp(imageCache.fn, imageCache.args);
  14038. args = null;
  14039. continue;
  14040. }
  14041. self.buildPaintImageXObject(resources, args[0], true,
  14042. operatorList, cacheKey, imageCache);
  14043. args = null;
  14044. continue;
  14045. case OPS.showText:
  14046. args[0] = self.handleText(args[0], stateManager.state);
  14047. break;
  14048. case OPS.showSpacedText:
  14049. var arr = args[0];
  14050. var combinedGlyphs = [];
  14051. var arrLength = arr.length;
  14052. for (i = 0; i < arrLength; ++i) {
  14053. var arrItem = arr[i];
  14054. if (isString(arrItem)) {
  14055. Array.prototype.push.apply(combinedGlyphs,
  14056. self.handleText(arrItem, stateManager.state));
  14057. } else if (isNum(arrItem)) {
  14058. combinedGlyphs.push(arrItem);
  14059. }
  14060. }
  14061. args[0] = combinedGlyphs;
  14062. fn = OPS.showText;
  14063. break;
  14064. case OPS.nextLineShowText:
  14065. operatorList.addOp(OPS.nextLine);
  14066. args[0] = self.handleText(args[0], stateManager.state);
  14067. fn = OPS.showText;
  14068. break;
  14069. case OPS.nextLineSetSpacingShowText:
  14070. operatorList.addOp(OPS.nextLine);
  14071. operatorList.addOp(OPS.setWordSpacing, [args.shift()]);
  14072. operatorList.addOp(OPS.setCharSpacing, [args.shift()]);
  14073. args[0] = self.handleText(args[0], stateManager.state);
  14074. fn = OPS.showText;
  14075. break;
  14076. case OPS.setTextRenderingMode:
  14077. stateManager.state.textRenderingMode = args[0];
  14078. break;
  14079. case OPS.setFillColorSpace:
  14080. stateManager.state.fillColorSpace =
  14081. ColorSpace.parse(args[0], xref, resources);
  14082. continue;
  14083. case OPS.setStrokeColorSpace:
  14084. stateManager.state.strokeColorSpace =
  14085. ColorSpace.parse(args[0], xref, resources);
  14086. continue;
  14087. case OPS.setFillColor:
  14088. cs = stateManager.state.fillColorSpace;
  14089. args = cs.getRgb(args, 0);
  14090. fn = OPS.setFillRGBColor;
  14091. break;
  14092. case OPS.setStrokeColor:
  14093. cs = stateManager.state.strokeColorSpace;
  14094. args = cs.getRgb(args, 0);
  14095. fn = OPS.setStrokeRGBColor;
  14096. break;
  14097. case OPS.setFillGray:
  14098. stateManager.state.fillColorSpace = ColorSpace.singletons.gray;
  14099. args = ColorSpace.singletons.gray.getRgb(args, 0);
  14100. fn = OPS.setFillRGBColor;
  14101. break;
  14102. case OPS.setStrokeGray:
  14103. stateManager.state.strokeColorSpace = ColorSpace.singletons.gray;
  14104. args = ColorSpace.singletons.gray.getRgb(args, 0);
  14105. fn = OPS.setStrokeRGBColor;
  14106. break;
  14107. case OPS.setFillCMYKColor:
  14108. stateManager.state.fillColorSpace = ColorSpace.singletons.cmyk;
  14109. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  14110. fn = OPS.setFillRGBColor;
  14111. break;
  14112. case OPS.setStrokeCMYKColor:
  14113. stateManager.state.strokeColorSpace = ColorSpace.singletons.cmyk;
  14114. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  14115. fn = OPS.setStrokeRGBColor;
  14116. break;
  14117. case OPS.setFillRGBColor:
  14118. stateManager.state.fillColorSpace = ColorSpace.singletons.rgb;
  14119. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  14120. break;
  14121. case OPS.setStrokeRGBColor:
  14122. stateManager.state.strokeColorSpace = ColorSpace.singletons.rgb;
  14123. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  14124. break;
  14125. case OPS.setFillColorN:
  14126. cs = stateManager.state.fillColorSpace;
  14127. if (cs.name === 'Pattern') {
  14128. return self.handleColorN(operatorList, OPS.setFillColorN,
  14129. args, cs, patterns, resources, xref).then(function() {
  14130. next(resolve, reject);
  14131. }, reject);
  14132. }
  14133. args = cs.getRgb(args, 0);
  14134. fn = OPS.setFillRGBColor;
  14135. break;
  14136. case OPS.setStrokeColorN:
  14137. cs = stateManager.state.strokeColorSpace;
  14138. if (cs.name === 'Pattern') {
  14139. return self.handleColorN(operatorList, OPS.setStrokeColorN,
  14140. args, cs, patterns, resources, xref).then(function() {
  14141. next(resolve, reject);
  14142. }, reject);
  14143. }
  14144. args = cs.getRgb(args, 0);
  14145. fn = OPS.setStrokeRGBColor;
  14146. break;
  14147. case OPS.shadingFill:
  14148. var shadingRes = resources.get('Shading');
  14149. if (!shadingRes) {
  14150. error('No shading resource found');
  14151. }
  14152. var shading = shadingRes.get(args[0].name);
  14153. if (!shading) {
  14154. error('No shading object found');
  14155. }
  14156. var shadingFill = Pattern.parseShading(shading, null, xref,
  14157. resources);
  14158. var patternIR = shadingFill.getIR();
  14159. args = [patternIR];
  14160. fn = OPS.shadingFill;
  14161. break;
  14162. case OPS.setGState:
  14163. var dictName = args[0];
  14164. var extGState = resources.get('ExtGState');
  14165. if (!isDict(extGState) || !extGState.has(dictName.name)) {
  14166. break;
  14167. }
  14168. var gState = extGState.get(dictName.name);
  14169. return self.setGState(resources, gState, operatorList, xref,
  14170. stateManager).then(function() {
  14171. next(resolve, reject);
  14172. }, reject);
  14173. case OPS.moveTo:
  14174. case OPS.lineTo:
  14175. case OPS.curveTo:
  14176. case OPS.curveTo2:
  14177. case OPS.curveTo3:
  14178. case OPS.closePath:
  14179. self.buildPath(operatorList, fn, args);
  14180. continue;
  14181. case OPS.rectangle:
  14182. self.buildPath(operatorList, fn, args);
  14183. continue;
  14184. }
  14185. operatorList.addOp(fn, args);
  14186. }
  14187. if (stop) {
  14188. deferred.then(function () {
  14189. next(resolve, reject);
  14190. });
  14191. return;
  14192. }
  14193. // Some PDFs don't close all restores inside object/form.
  14194. // Closing those for them.
  14195. for (i = 0, ii = preprocessor.savedStatesDepth; i < ii; i++) {
  14196. operatorList.addOp(OPS.restore, []);
  14197. }
  14198. resolve();
  14199. });
  14200. },
  14201. getTextContent: function PartialEvaluator_getTextContent(stream, resources,
  14202. stateManager) {
  14203. stateManager = (stateManager || new StateManager(new TextState()));
  14204. var textContent = {
  14205. items: [],
  14206. styles: Object.create(null)
  14207. };
  14208. var bidiTexts = textContent.items;
  14209. var SPACE_FACTOR = 0.35;
  14210. var MULTI_SPACE_FACTOR = 1.5;
  14211. var self = this;
  14212. var xref = this.xref;
  14213. resources = (xref.fetchIfRef(resources) || Dict.empty);
  14214. // The xobj is parsed iff it's needed, e.g. if there is a `DO` cmd.
  14215. var xobjs = null;
  14216. var xobjsCache = {};
  14217. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  14218. var textState;
  14219. function newTextChunk() {
  14220. var font = textState.font;
  14221. if (!(font.loadedName in textContent.styles)) {
  14222. textContent.styles[font.loadedName] = {
  14223. fontFamily: font.fallbackName,
  14224. ascent: font.ascent,
  14225. descent: font.descent,
  14226. vertical: font.vertical
  14227. };
  14228. }
  14229. return {
  14230. // |str| is initially an array which we push individual chars to, and
  14231. // then runBidi() overwrites it with the final string.
  14232. str: [],
  14233. dir: null,
  14234. width: 0,
  14235. height: 0,
  14236. transform: null,
  14237. fontName: font.loadedName
  14238. };
  14239. }
  14240. function runBidi(textChunk) {
  14241. var str = textChunk.str.join('');
  14242. var bidiResult = PDFJS.bidi(str, -1, textState.font.vertical);
  14243. textChunk.str = bidiResult.str;
  14244. textChunk.dir = bidiResult.dir;
  14245. return textChunk;
  14246. }
  14247. function handleSetFont(fontName, fontRef) {
  14248. return self.loadFont(fontName, fontRef, xref, resources).
  14249. then(function (translated) {
  14250. textState.font = translated.font;
  14251. textState.fontMatrix = translated.font.fontMatrix ||
  14252. FONT_IDENTITY_MATRIX;
  14253. });
  14254. }
  14255. function buildTextGeometry(chars, textChunk) {
  14256. var font = textState.font;
  14257. textChunk = textChunk || newTextChunk();
  14258. if (!textChunk.transform) {
  14259. // 9.4.4 Text Space Details
  14260. var tsm = [textState.fontSize * textState.textHScale, 0,
  14261. 0, textState.fontSize,
  14262. 0, textState.textRise];
  14263. var trm = textChunk.transform = Util.transform(textState.ctm,
  14264. Util.transform(textState.textMatrix, tsm));
  14265. if (!font.vertical) {
  14266. textChunk.height = Math.sqrt(trm[2] * trm[2] + trm[3] * trm[3]);
  14267. } else {
  14268. textChunk.width = Math.sqrt(trm[0] * trm[0] + trm[1] * trm[1]);
  14269. }
  14270. }
  14271. var width = 0;
  14272. var height = 0;
  14273. var glyphs = font.charsToGlyphs(chars);
  14274. var defaultVMetrics = font.defaultVMetrics;
  14275. for (var i = 0; i < glyphs.length; i++) {
  14276. var glyph = glyphs[i];
  14277. if (!glyph) { // Previous glyph was a space.
  14278. width += textState.wordSpacing * textState.textHScale;
  14279. continue;
  14280. }
  14281. var vMetricX = null;
  14282. var vMetricY = null;
  14283. var glyphWidth = null;
  14284. if (font.vertical) {
  14285. if (glyph.vmetric) {
  14286. glyphWidth = glyph.vmetric[0];
  14287. vMetricX = glyph.vmetric[1];
  14288. vMetricY = glyph.vmetric[2];
  14289. } else {
  14290. glyphWidth = glyph.width;
  14291. vMetricX = glyph.width * 0.5;
  14292. vMetricY = defaultVMetrics[2];
  14293. }
  14294. } else {
  14295. glyphWidth = glyph.width;
  14296. }
  14297. var glyphUnicode = glyph.unicode;
  14298. if (NormalizedUnicodes[glyphUnicode] !== undefined) {
  14299. glyphUnicode = NormalizedUnicodes[glyphUnicode];
  14300. }
  14301. glyphUnicode = reverseIfRtl(glyphUnicode);
  14302. // The following will calculate the x and y of the individual glyphs.
  14303. // if (font.vertical) {
  14304. // tsm[4] -= vMetricX * Math.abs(textState.fontSize) *
  14305. // textState.fontMatrix[0];
  14306. // tsm[5] -= vMetricY * textState.fontSize *
  14307. // textState.fontMatrix[0];
  14308. // }
  14309. // var trm = Util.transform(textState.textMatrix, tsm);
  14310. // var pt = Util.applyTransform([trm[4], trm[5]], textState.ctm);
  14311. // var x = pt[0];
  14312. // var y = pt[1];
  14313. var tx = 0;
  14314. var ty = 0;
  14315. if (!font.vertical) {
  14316. var w0 = glyphWidth * textState.fontMatrix[0];
  14317. tx = (w0 * textState.fontSize + textState.charSpacing) *
  14318. textState.textHScale;
  14319. width += tx;
  14320. } else {
  14321. var w1 = glyphWidth * textState.fontMatrix[0];
  14322. ty = w1 * textState.fontSize + textState.charSpacing;
  14323. height += ty;
  14324. }
  14325. textState.translateTextMatrix(tx, ty);
  14326. textChunk.str.push(glyphUnicode);
  14327. }
  14328. var a = textState.textLineMatrix[0];
  14329. var b = textState.textLineMatrix[1];
  14330. var scaleLineX = Math.sqrt(a * a + b * b);
  14331. a = textState.ctm[0];
  14332. b = textState.ctm[1];
  14333. var scaleCtmX = Math.sqrt(a * a + b * b);
  14334. if (!font.vertical) {
  14335. textChunk.width += width * scaleCtmX * scaleLineX;
  14336. } else {
  14337. textChunk.height += Math.abs(height * scaleCtmX * scaleLineX);
  14338. }
  14339. return textChunk;
  14340. }
  14341. var timeSlotManager = new TimeSlotManager();
  14342. return new Promise(function next(resolve, reject) {
  14343. timeSlotManager.reset();
  14344. var stop, operation = {};
  14345. while (!(stop = timeSlotManager.check()) &&
  14346. (preprocessor.read(operation))) {
  14347. textState = stateManager.state;
  14348. var fn = operation.fn;
  14349. var args = operation.args;
  14350. switch (fn | 0) {
  14351. case OPS.setFont:
  14352. textState.fontSize = args[1];
  14353. return handleSetFont(args[0].name).then(function() {
  14354. next(resolve, reject);
  14355. }, reject);
  14356. case OPS.setTextRise:
  14357. textState.textRise = args[0];
  14358. break;
  14359. case OPS.setHScale:
  14360. textState.textHScale = args[0] / 100;
  14361. break;
  14362. case OPS.setLeading:
  14363. textState.leading = args[0];
  14364. break;
  14365. case OPS.moveText:
  14366. textState.translateTextLineMatrix(args[0], args[1]);
  14367. textState.textMatrix = textState.textLineMatrix.slice();
  14368. break;
  14369. case OPS.setLeadingMoveText:
  14370. textState.leading = -args[1];
  14371. textState.translateTextLineMatrix(args[0], args[1]);
  14372. textState.textMatrix = textState.textLineMatrix.slice();
  14373. break;
  14374. case OPS.nextLine:
  14375. textState.carriageReturn();
  14376. break;
  14377. case OPS.setTextMatrix:
  14378. textState.setTextMatrix(args[0], args[1], args[2], args[3],
  14379. args[4], args[5]);
  14380. textState.setTextLineMatrix(args[0], args[1], args[2], args[3],
  14381. args[4], args[5]);
  14382. break;
  14383. case OPS.setCharSpacing:
  14384. textState.charSpacing = args[0];
  14385. break;
  14386. case OPS.setWordSpacing:
  14387. textState.wordSpacing = args[0];
  14388. break;
  14389. case OPS.beginText:
  14390. textState.textMatrix = IDENTITY_MATRIX.slice();
  14391. textState.textLineMatrix = IDENTITY_MATRIX.slice();
  14392. break;
  14393. case OPS.showSpacedText:
  14394. var items = args[0];
  14395. var textChunk = newTextChunk();
  14396. var offset;
  14397. for (var j = 0, jj = items.length; j < jj; j++) {
  14398. if (typeof items[j] === 'string') {
  14399. buildTextGeometry(items[j], textChunk);
  14400. } else {
  14401. var val = items[j] / 1000;
  14402. if (!textState.font.vertical) {
  14403. offset = -val * textState.fontSize * textState.textHScale *
  14404. textState.textMatrix[0];
  14405. textState.translateTextMatrix(offset, 0);
  14406. textChunk.width += offset;
  14407. } else {
  14408. offset = -val * textState.fontSize *
  14409. textState.textMatrix[3];
  14410. textState.translateTextMatrix(0, offset);
  14411. textChunk.height += offset;
  14412. }
  14413. if (items[j] < 0 && textState.font.spaceWidth > 0) {
  14414. var fakeSpaces = -items[j] / textState.font.spaceWidth;
  14415. if (fakeSpaces > MULTI_SPACE_FACTOR) {
  14416. fakeSpaces = Math.round(fakeSpaces);
  14417. while (fakeSpaces--) {
  14418. textChunk.str.push(' ');
  14419. }
  14420. } else if (fakeSpaces > SPACE_FACTOR) {
  14421. textChunk.str.push(' ');
  14422. }
  14423. }
  14424. }
  14425. }
  14426. bidiTexts.push(runBidi(textChunk));
  14427. break;
  14428. case OPS.showText:
  14429. bidiTexts.push(runBidi(buildTextGeometry(args[0])));
  14430. break;
  14431. case OPS.nextLineShowText:
  14432. textState.carriageReturn();
  14433. bidiTexts.push(runBidi(buildTextGeometry(args[0])));
  14434. break;
  14435. case OPS.nextLineSetSpacingShowText:
  14436. textState.wordSpacing = args[0];
  14437. textState.charSpacing = args[1];
  14438. textState.carriageReturn();
  14439. bidiTexts.push(runBidi(buildTextGeometry(args[2])));
  14440. break;
  14441. case OPS.paintXObject:
  14442. if (args[0].code) {
  14443. break;
  14444. }
  14445. if (!xobjs) {
  14446. xobjs = (resources.get('XObject') || Dict.empty);
  14447. }
  14448. var name = args[0].name;
  14449. if (xobjsCache.key === name) {
  14450. if (xobjsCache.texts) {
  14451. Util.appendToArray(bidiTexts, xobjsCache.texts.items);
  14452. Util.extendObj(textContent.styles, xobjsCache.texts.styles);
  14453. }
  14454. break;
  14455. }
  14456. var xobj = xobjs.get(name);
  14457. if (!xobj) {
  14458. break;
  14459. }
  14460. assert(isStream(xobj), 'XObject should be a stream');
  14461. var type = xobj.dict.get('Subtype');
  14462. assert(isName(type),
  14463. 'XObject should have a Name subtype');
  14464. if ('Form' !== type.name) {
  14465. xobjsCache.key = name;
  14466. xobjsCache.texts = null;
  14467. break;
  14468. }
  14469. stateManager.save();
  14470. var matrix = xobj.dict.get('Matrix');
  14471. if (isArray(matrix) && matrix.length === 6) {
  14472. stateManager.transform(matrix);
  14473. }
  14474. return self.getTextContent(xobj,
  14475. xobj.dict.get('Resources') || resources, stateManager).
  14476. then(function (formTextContent) {
  14477. Util.appendToArray(bidiTexts, formTextContent.items);
  14478. Util.extendObj(textContent.styles, formTextContent.styles);
  14479. stateManager.restore();
  14480. xobjsCache.key = name;
  14481. xobjsCache.texts = formTextContent;
  14482. next(resolve, reject);
  14483. }, reject);
  14484. case OPS.setGState:
  14485. var dictName = args[0];
  14486. var extGState = resources.get('ExtGState');
  14487. if (!isDict(extGState) || !extGState.has(dictName.name)) {
  14488. break;
  14489. }
  14490. var gsStateMap = extGState.get(dictName.name);
  14491. var gsStateFont = null;
  14492. for (var key in gsStateMap) {
  14493. if (key === 'Font') {
  14494. assert(!gsStateFont);
  14495. gsStateFont = gsStateMap[key];
  14496. }
  14497. }
  14498. if (gsStateFont) {
  14499. textState.fontSize = gsStateFont[1];
  14500. return handleSetFont(gsStateFont[0]).then(function() {
  14501. next(resolve, reject);
  14502. }, reject);
  14503. }
  14504. break;
  14505. } // switch
  14506. } // while
  14507. if (stop) {
  14508. deferred.then(function () {
  14509. next(resolve, reject);
  14510. });
  14511. return;
  14512. }
  14513. resolve(textContent);
  14514. });
  14515. },
  14516. extractDataStructures: function
  14517. partialEvaluatorExtractDataStructures(dict, baseDict,
  14518. xref, properties) {
  14519. // 9.10.2
  14520. var toUnicode = (dict.get('ToUnicode') || baseDict.get('ToUnicode'));
  14521. if (toUnicode) {
  14522. properties.toUnicode = this.readToUnicode(toUnicode);
  14523. }
  14524. if (properties.composite) {
  14525. // CIDSystemInfo helps to match CID to glyphs
  14526. var cidSystemInfo = dict.get('CIDSystemInfo');
  14527. if (isDict(cidSystemInfo)) {
  14528. properties.cidSystemInfo = {
  14529. registry: cidSystemInfo.get('Registry'),
  14530. ordering: cidSystemInfo.get('Ordering'),
  14531. supplement: cidSystemInfo.get('Supplement')
  14532. };
  14533. }
  14534. var cidToGidMap = dict.get('CIDToGIDMap');
  14535. if (isStream(cidToGidMap)) {
  14536. properties.cidToGidMap = this.readCidToGidMap(cidToGidMap);
  14537. }
  14538. }
  14539. // Based on 9.6.6 of the spec the encoding can come from multiple places
  14540. // and depends on the font type. The base encoding and differences are
  14541. // read here, but the encoding that is actually used is chosen during
  14542. // glyph mapping in the font.
  14543. // TODO: Loading the built in encoding in the font would allow the
  14544. // differences to be merged in here not require us to hold on to it.
  14545. var differences = [];
  14546. var baseEncodingName = null;
  14547. var encoding;
  14548. if (dict.has('Encoding')) {
  14549. encoding = dict.get('Encoding');
  14550. if (isDict(encoding)) {
  14551. baseEncodingName = encoding.get('BaseEncoding');
  14552. baseEncodingName = (isName(baseEncodingName) ?
  14553. baseEncodingName.name : null);
  14554. // Load the differences between the base and original
  14555. if (encoding.has('Differences')) {
  14556. var diffEncoding = encoding.get('Differences');
  14557. var index = 0;
  14558. for (var j = 0, jj = diffEncoding.length; j < jj; j++) {
  14559. var data = diffEncoding[j];
  14560. if (isNum(data)) {
  14561. index = data;
  14562. } else {
  14563. differences[index++] = data.name;
  14564. }
  14565. }
  14566. }
  14567. } else if (isName(encoding)) {
  14568. baseEncodingName = encoding.name;
  14569. } else {
  14570. error('Encoding is not a Name nor a Dict');
  14571. }
  14572. // According to table 114 if the encoding is a named encoding it must be
  14573. // one of these predefined encodings.
  14574. if ((baseEncodingName !== 'MacRomanEncoding' &&
  14575. baseEncodingName !== 'MacExpertEncoding' &&
  14576. baseEncodingName !== 'WinAnsiEncoding')) {
  14577. baseEncodingName = null;
  14578. }
  14579. }
  14580. if (baseEncodingName) {
  14581. properties.defaultEncoding = Encodings[baseEncodingName].slice();
  14582. } else {
  14583. encoding = (properties.type === 'TrueType' ?
  14584. Encodings.WinAnsiEncoding : Encodings.StandardEncoding);
  14585. // The Symbolic attribute can be misused for regular fonts
  14586. // Heuristic: we have to check if the font is a standard one also
  14587. if (!!(properties.flags & FontFlags.Symbolic)) {
  14588. encoding = (!properties.file && /Symbol/i.test(properties.name) ?
  14589. Encodings.SymbolSetEncoding :
  14590. Encodings.MacRomanEncoding);
  14591. }
  14592. properties.defaultEncoding = encoding;
  14593. }
  14594. properties.differences = differences;
  14595. properties.baseEncodingName = baseEncodingName;
  14596. properties.dict = dict;
  14597. },
  14598. readToUnicode: function PartialEvaluator_readToUnicode(toUnicode) {
  14599. var cmapObj = toUnicode;
  14600. if (isName(cmapObj)) {
  14601. return CMapFactory.create(cmapObj,
  14602. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null).getMap();
  14603. } else if (isStream(cmapObj)) {
  14604. var cmap = CMapFactory.create(cmapObj,
  14605. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null).getMap();
  14606. // Convert UTF-16BE
  14607. // NOTE: cmap can be a sparse array, so use forEach instead of for(;;)
  14608. // to iterate over all keys.
  14609. cmap.forEach(function(token, i) {
  14610. var str = [];
  14611. for (var k = 0; k < token.length; k += 2) {
  14612. var w1 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
  14613. if ((w1 & 0xF800) !== 0xD800) { // w1 < 0xD800 || w1 > 0xDFFF
  14614. str.push(w1);
  14615. continue;
  14616. }
  14617. k += 2;
  14618. var w2 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
  14619. str.push(((w1 & 0x3ff) << 10) + (w2 & 0x3ff) + 0x10000);
  14620. }
  14621. cmap[i] = String.fromCharCode.apply(String, str);
  14622. });
  14623. return cmap;
  14624. }
  14625. return null;
  14626. },
  14627. readCidToGidMap: function PartialEvaluator_readCidToGidMap(cidToGidStream) {
  14628. // Extract the encoding from the CIDToGIDMap
  14629. var glyphsData = cidToGidStream.getBytes();
  14630. // Set encoding 0 to later verify the font has an encoding
  14631. var result = [];
  14632. for (var j = 0, jj = glyphsData.length; j < jj; j++) {
  14633. var glyphID = (glyphsData[j++] << 8) | glyphsData[j];
  14634. if (glyphID === 0) {
  14635. continue;
  14636. }
  14637. var code = j >> 1;
  14638. result[code] = glyphID;
  14639. }
  14640. return result;
  14641. },
  14642. extractWidths: function PartialEvaluator_extractWidths(dict, xref,
  14643. descriptor,
  14644. properties) {
  14645. var glyphsWidths = [];
  14646. var defaultWidth = 0;
  14647. var glyphsVMetrics = [];
  14648. var defaultVMetrics;
  14649. var i, ii, j, jj, start, code, widths;
  14650. if (properties.composite) {
  14651. defaultWidth = dict.get('DW') || 1000;
  14652. widths = dict.get('W');
  14653. if (widths) {
  14654. for (i = 0, ii = widths.length; i < ii; i++) {
  14655. start = widths[i++];
  14656. code = xref.fetchIfRef(widths[i]);
  14657. if (isArray(code)) {
  14658. for (j = 0, jj = code.length; j < jj; j++) {
  14659. glyphsWidths[start++] = code[j];
  14660. }
  14661. } else {
  14662. var width = widths[++i];
  14663. for (j = start; j <= code; j++) {
  14664. glyphsWidths[j] = width;
  14665. }
  14666. }
  14667. }
  14668. }
  14669. if (properties.vertical) {
  14670. var vmetrics = (dict.get('DW2') || [880, -1000]);
  14671. defaultVMetrics = [vmetrics[1], defaultWidth * 0.5, vmetrics[0]];
  14672. vmetrics = dict.get('W2');
  14673. if (vmetrics) {
  14674. for (i = 0, ii = vmetrics.length; i < ii; i++) {
  14675. start = vmetrics[i++];
  14676. code = xref.fetchIfRef(vmetrics[i]);
  14677. if (isArray(code)) {
  14678. for (j = 0, jj = code.length; j < jj; j++) {
  14679. glyphsVMetrics[start++] = [code[j++], code[j++], code[j]];
  14680. }
  14681. } else {
  14682. var vmetric = [vmetrics[++i], vmetrics[++i], vmetrics[++i]];
  14683. for (j = start; j <= code; j++) {
  14684. glyphsVMetrics[j] = vmetric;
  14685. }
  14686. }
  14687. }
  14688. }
  14689. }
  14690. } else {
  14691. var firstChar = properties.firstChar;
  14692. widths = dict.get('Widths');
  14693. if (widths) {
  14694. j = firstChar;
  14695. for (i = 0, ii = widths.length; i < ii; i++) {
  14696. glyphsWidths[j++] = widths[i];
  14697. }
  14698. defaultWidth = (parseFloat(descriptor.get('MissingWidth')) || 0);
  14699. } else {
  14700. // Trying get the BaseFont metrics (see comment above).
  14701. var baseFontName = dict.get('BaseFont');
  14702. if (isName(baseFontName)) {
  14703. var metrics = this.getBaseFontMetrics(baseFontName.name);
  14704. glyphsWidths = this.buildCharCodeToWidth(metrics.widths,
  14705. properties);
  14706. defaultWidth = metrics.defaultWidth;
  14707. }
  14708. }
  14709. }
  14710. // Heuristic: detection of monospace font by checking all non-zero widths
  14711. var isMonospace = true;
  14712. var firstWidth = defaultWidth;
  14713. for (var glyph in glyphsWidths) {
  14714. var glyphWidth = glyphsWidths[glyph];
  14715. if (!glyphWidth) {
  14716. continue;
  14717. }
  14718. if (!firstWidth) {
  14719. firstWidth = glyphWidth;
  14720. continue;
  14721. }
  14722. if (firstWidth !== glyphWidth) {
  14723. isMonospace = false;
  14724. break;
  14725. }
  14726. }
  14727. if (isMonospace) {
  14728. properties.flags |= FontFlags.FixedPitch;
  14729. }
  14730. properties.defaultWidth = defaultWidth;
  14731. properties.widths = glyphsWidths;
  14732. properties.defaultVMetrics = defaultVMetrics;
  14733. properties.vmetrics = glyphsVMetrics;
  14734. },
  14735. isSerifFont: function PartialEvaluator_isSerifFont(baseFontName) {
  14736. // Simulating descriptor flags attribute
  14737. var fontNameWoStyle = baseFontName.split('-')[0];
  14738. return (fontNameWoStyle in serifFonts) ||
  14739. (fontNameWoStyle.search(/serif/gi) !== -1);
  14740. },
  14741. getBaseFontMetrics: function PartialEvaluator_getBaseFontMetrics(name) {
  14742. var defaultWidth = 0;
  14743. var widths = [];
  14744. var monospace = false;
  14745. var lookupName = (stdFontMap[name] || name);
  14746. if (!(lookupName in Metrics)) {
  14747. // Use default fonts for looking up font metrics if the passed
  14748. // font is not a base font
  14749. if (this.isSerifFont(name)) {
  14750. lookupName = 'Times-Roman';
  14751. } else {
  14752. lookupName = 'Helvetica';
  14753. }
  14754. }
  14755. var glyphWidths = Metrics[lookupName];
  14756. if (isNum(glyphWidths)) {
  14757. defaultWidth = glyphWidths;
  14758. monospace = true;
  14759. } else {
  14760. widths = glyphWidths;
  14761. }
  14762. return {
  14763. defaultWidth: defaultWidth,
  14764. monospace: monospace,
  14765. widths: widths
  14766. };
  14767. },
  14768. buildCharCodeToWidth:
  14769. function PartialEvaluator_bulildCharCodeToWidth(widthsByGlyphName,
  14770. properties) {
  14771. var widths = Object.create(null);
  14772. var differences = properties.differences;
  14773. var encoding = properties.defaultEncoding;
  14774. for (var charCode = 0; charCode < 256; charCode++) {
  14775. if (charCode in differences &&
  14776. widthsByGlyphName[differences[charCode]]) {
  14777. widths[charCode] = widthsByGlyphName[differences[charCode]];
  14778. continue;
  14779. }
  14780. if (charCode in encoding && widthsByGlyphName[encoding[charCode]]) {
  14781. widths[charCode] = widthsByGlyphName[encoding[charCode]];
  14782. continue;
  14783. }
  14784. }
  14785. return widths;
  14786. },
  14787. preEvaluateFont: function PartialEvaluator_preEvaluateFont(dict, xref) {
  14788. var baseDict = dict;
  14789. var type = dict.get('Subtype');
  14790. assert(isName(type), 'invalid font Subtype');
  14791. var composite = false;
  14792. var uint8array;
  14793. if (type.name === 'Type0') {
  14794. // If font is a composite
  14795. // - get the descendant font
  14796. // - set the type according to the descendant font
  14797. // - get the FontDescriptor from the descendant font
  14798. var df = dict.get('DescendantFonts');
  14799. if (!df) {
  14800. error('Descendant fonts are not specified');
  14801. }
  14802. dict = (isArray(df) ? xref.fetchIfRef(df[0]) : df);
  14803. type = dict.get('Subtype');
  14804. assert(isName(type), 'invalid font Subtype');
  14805. composite = true;
  14806. }
  14807. var descriptor = dict.get('FontDescriptor');
  14808. if (descriptor) {
  14809. var hash = new MurmurHash3_64();
  14810. var encoding = baseDict.getRaw('Encoding');
  14811. if (isName(encoding)) {
  14812. hash.update(encoding.name);
  14813. } else if (isRef(encoding)) {
  14814. hash.update(encoding.num + '_' + encoding.gen);
  14815. }
  14816. var toUnicode = dict.get('ToUnicode') || baseDict.get('ToUnicode');
  14817. if (isStream(toUnicode)) {
  14818. var stream = toUnicode.str || toUnicode;
  14819. uint8array = stream.buffer ?
  14820. new Uint8Array(stream.buffer.buffer, 0, stream.bufferLength) :
  14821. new Uint8Array(stream.bytes.buffer,
  14822. stream.start, stream.end - stream.start);
  14823. hash.update(uint8array);
  14824. } else if (isName(toUnicode)) {
  14825. hash.update(toUnicode.name);
  14826. }
  14827. var widths = dict.get('Widths') || baseDict.get('Widths');
  14828. if (widths) {
  14829. uint8array = new Uint8Array(new Uint32Array(widths).buffer);
  14830. hash.update(uint8array);
  14831. }
  14832. }
  14833. return {
  14834. descriptor: descriptor,
  14835. dict: dict,
  14836. baseDict: baseDict,
  14837. composite: composite,
  14838. type: type.name,
  14839. hash: hash ? hash.hexdigest() : ''
  14840. };
  14841. },
  14842. translateFont: function PartialEvaluator_translateFont(preEvaluatedFont,
  14843. xref) {
  14844. var baseDict = preEvaluatedFont.baseDict;
  14845. var dict = preEvaluatedFont.dict;
  14846. var composite = preEvaluatedFont.composite;
  14847. var descriptor = preEvaluatedFont.descriptor;
  14848. var type = preEvaluatedFont.type;
  14849. var maxCharIndex = (composite ? 0xFFFF : 0xFF);
  14850. var properties;
  14851. if (!descriptor) {
  14852. if (type === 'Type3') {
  14853. // FontDescriptor is only required for Type3 fonts when the document
  14854. // is a tagged pdf. Create a barbebones one to get by.
  14855. descriptor = new Dict(null);
  14856. descriptor.set('FontName', Name.get(type));
  14857. } else {
  14858. // Before PDF 1.5 if the font was one of the base 14 fonts, having a
  14859. // FontDescriptor was not required.
  14860. // This case is here for compatibility.
  14861. var baseFontName = dict.get('BaseFont');
  14862. if (!isName(baseFontName)) {
  14863. error('Base font is not specified');
  14864. }
  14865. // Using base font name as a font name.
  14866. baseFontName = baseFontName.name.replace(/[,_]/g, '-');
  14867. var metrics = this.getBaseFontMetrics(baseFontName);
  14868. // Simulating descriptor flags attribute
  14869. var fontNameWoStyle = baseFontName.split('-')[0];
  14870. var flags =
  14871. (this.isSerifFont(fontNameWoStyle) ? FontFlags.Serif : 0) |
  14872. (metrics.monospace ? FontFlags.FixedPitch : 0) |
  14873. (symbolsFonts[fontNameWoStyle] ? FontFlags.Symbolic :
  14874. FontFlags.Nonsymbolic);
  14875. properties = {
  14876. type: type,
  14877. name: baseFontName,
  14878. widths: metrics.widths,
  14879. defaultWidth: metrics.defaultWidth,
  14880. flags: flags,
  14881. firstChar: 0,
  14882. lastChar: maxCharIndex
  14883. };
  14884. this.extractDataStructures(dict, dict, xref, properties);
  14885. properties.widths = this.buildCharCodeToWidth(metrics.widths,
  14886. properties);
  14887. return new Font(baseFontName, null, properties);
  14888. }
  14889. }
  14890. // According to the spec if 'FontDescriptor' is declared, 'FirstChar',
  14891. // 'LastChar' and 'Widths' should exist too, but some PDF encoders seem
  14892. // to ignore this rule when a variant of a standart font is used.
  14893. // TODO Fill the width array depending on which of the base font this is
  14894. // a variant.
  14895. var firstChar = (dict.get('FirstChar') || 0);
  14896. var lastChar = (dict.get('LastChar') || maxCharIndex);
  14897. var fontName = descriptor.get('FontName');
  14898. var baseFont = dict.get('BaseFont');
  14899. // Some bad PDFs have a string as the font name.
  14900. if (isString(fontName)) {
  14901. fontName = Name.get(fontName);
  14902. }
  14903. if (isString(baseFont)) {
  14904. baseFont = Name.get(baseFont);
  14905. }
  14906. if (type !== 'Type3') {
  14907. var fontNameStr = fontName && fontName.name;
  14908. var baseFontStr = baseFont && baseFont.name;
  14909. if (fontNameStr !== baseFontStr) {
  14910. info('The FontDescriptor\'s FontName is "' + fontNameStr +
  14911. '" but should be the same as the Font\'s BaseFont "' +
  14912. baseFontStr + '"');
  14913. // Workaround for cases where e.g. fontNameStr = 'Arial' and
  14914. // baseFontStr = 'Arial,Bold' (needed when no font file is embedded).
  14915. if (fontNameStr && baseFontStr &&
  14916. baseFontStr.indexOf(fontNameStr) === 0) {
  14917. fontName = baseFont;
  14918. }
  14919. }
  14920. }
  14921. fontName = (fontName || baseFont);
  14922. assert(isName(fontName), 'invalid font name');
  14923. var fontFile = descriptor.get('FontFile', 'FontFile2', 'FontFile3');
  14924. if (fontFile) {
  14925. if (fontFile.dict) {
  14926. var subtype = fontFile.dict.get('Subtype');
  14927. if (subtype) {
  14928. subtype = subtype.name;
  14929. }
  14930. var length1 = fontFile.dict.get('Length1');
  14931. var length2 = fontFile.dict.get('Length2');
  14932. }
  14933. }
  14934. properties = {
  14935. type: type,
  14936. name: fontName.name,
  14937. subtype: subtype,
  14938. file: fontFile,
  14939. length1: length1,
  14940. length2: length2,
  14941. loadedName: baseDict.loadedName,
  14942. composite: composite,
  14943. wideChars: composite,
  14944. fixedPitch: false,
  14945. fontMatrix: (dict.get('FontMatrix') || FONT_IDENTITY_MATRIX),
  14946. firstChar: firstChar || 0,
  14947. lastChar: (lastChar || maxCharIndex),
  14948. bbox: descriptor.get('FontBBox'),
  14949. ascent: descriptor.get('Ascent'),
  14950. descent: descriptor.get('Descent'),
  14951. xHeight: descriptor.get('XHeight'),
  14952. capHeight: descriptor.get('CapHeight'),
  14953. flags: descriptor.get('Flags'),
  14954. italicAngle: descriptor.get('ItalicAngle'),
  14955. coded: false
  14956. };
  14957. if (composite) {
  14958. var cidEncoding = baseDict.get('Encoding');
  14959. if (isName(cidEncoding)) {
  14960. properties.cidEncoding = cidEncoding.name;
  14961. }
  14962. properties.cMap = CMapFactory.create(cidEncoding,
  14963. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  14964. properties.vertical = properties.cMap.vertical;
  14965. }
  14966. this.extractDataStructures(dict, baseDict, xref, properties);
  14967. this.extractWidths(dict, xref, descriptor, properties);
  14968. if (type === 'Type3') {
  14969. properties.isType3Font = true;
  14970. }
  14971. return new Font(fontName.name, fontFile, properties);
  14972. }
  14973. };
  14974. return PartialEvaluator;
  14975. })();
  14976. var TranslatedFont = (function TranslatedFontClosure() {
  14977. function TranslatedFont(loadedName, font, dict) {
  14978. this.loadedName = loadedName;
  14979. this.font = font;
  14980. this.dict = dict;
  14981. this.type3Loaded = null;
  14982. this.sent = false;
  14983. }
  14984. TranslatedFont.prototype = {
  14985. send: function (handler) {
  14986. if (this.sent) {
  14987. return;
  14988. }
  14989. var fontData = this.font.exportData();
  14990. handler.send('commonobj', [
  14991. this.loadedName,
  14992. 'Font',
  14993. fontData
  14994. ]);
  14995. this.sent = true;
  14996. },
  14997. loadType3Data: function (evaluator, resources, parentOperatorList) {
  14998. assert(this.font.isType3Font);
  14999. if (this.type3Loaded) {
  15000. return this.type3Loaded;
  15001. }
  15002. var translatedFont = this.font;
  15003. var loadCharProcsPromise = Promise.resolve();
  15004. var charProcs = this.dict.get('CharProcs').getAll();
  15005. var fontResources = this.dict.get('Resources') || resources;
  15006. var charProcKeys = Object.keys(charProcs);
  15007. var charProcOperatorList = {};
  15008. for (var i = 0, n = charProcKeys.length; i < n; ++i) {
  15009. loadCharProcsPromise = loadCharProcsPromise.then(function (key) {
  15010. var glyphStream = charProcs[key];
  15011. var operatorList = new OperatorList();
  15012. return evaluator.getOperatorList(glyphStream, fontResources,
  15013. operatorList).then(function () {
  15014. charProcOperatorList[key] = operatorList.getIR();
  15015. // Add the dependencies to the parent operator list so they are
  15016. // resolved before sub operator list is executed synchronously.
  15017. parentOperatorList.addDependencies(operatorList.dependencies);
  15018. }, function (reason) {
  15019. warn('Type3 font resource \"' + key + '\" is not available');
  15020. var operatorList = new OperatorList();
  15021. charProcOperatorList[key] = operatorList.getIR();
  15022. });
  15023. }.bind(this, charProcKeys[i]));
  15024. }
  15025. this.type3Loaded = loadCharProcsPromise.then(function () {
  15026. translatedFont.charProcOperatorList = charProcOperatorList;
  15027. });
  15028. return this.type3Loaded;
  15029. }
  15030. };
  15031. return TranslatedFont;
  15032. })();
  15033. var OperatorList = (function OperatorListClosure() {
  15034. var CHUNK_SIZE = 1000;
  15035. var CHUNK_SIZE_ABOUT = CHUNK_SIZE - 5; // close to chunk size
  15036. function getTransfers(queue) {
  15037. var transfers = [];
  15038. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  15039. for (var i = 0, ii = queue.length; i < ii; i++) {
  15040. switch (fnArray[i]) {
  15041. case OPS.paintInlineImageXObject:
  15042. case OPS.paintInlineImageXObjectGroup:
  15043. case OPS.paintImageMaskXObject:
  15044. var arg = argsArray[i][0]; // first param in imgData
  15045. if (!arg.cached) {
  15046. transfers.push(arg.data.buffer);
  15047. }
  15048. break;
  15049. }
  15050. }
  15051. return transfers;
  15052. }
  15053. function OperatorList(intent, messageHandler, pageIndex) {
  15054. this.messageHandler = messageHandler;
  15055. this.fnArray = [];
  15056. this.argsArray = [];
  15057. this.dependencies = {};
  15058. this.pageIndex = pageIndex;
  15059. this.intent = intent;
  15060. }
  15061. OperatorList.prototype = {
  15062. get length() {
  15063. return this.argsArray.length;
  15064. },
  15065. addOp: function(fn, args) {
  15066. this.fnArray.push(fn);
  15067. this.argsArray.push(args);
  15068. if (this.messageHandler) {
  15069. if (this.fnArray.length >= CHUNK_SIZE) {
  15070. this.flush();
  15071. } else if (this.fnArray.length >= CHUNK_SIZE_ABOUT &&
  15072. (fn === OPS.restore || fn === OPS.endText)) {
  15073. // heuristic to flush on boundary of restore or endText
  15074. this.flush();
  15075. }
  15076. }
  15077. },
  15078. addDependency: function(dependency) {
  15079. if (dependency in this.dependencies) {
  15080. return;
  15081. }
  15082. this.dependencies[dependency] = true;
  15083. this.addOp(OPS.dependency, [dependency]);
  15084. },
  15085. addDependencies: function(dependencies) {
  15086. for (var key in dependencies) {
  15087. this.addDependency(key);
  15088. }
  15089. },
  15090. addOpList: function(opList) {
  15091. Util.extendObj(this.dependencies, opList.dependencies);
  15092. for (var i = 0, ii = opList.length; i < ii; i++) {
  15093. this.addOp(opList.fnArray[i], opList.argsArray[i]);
  15094. }
  15095. },
  15096. getIR: function() {
  15097. return {
  15098. fnArray: this.fnArray,
  15099. argsArray: this.argsArray,
  15100. length: this.length
  15101. };
  15102. },
  15103. flush: function(lastChunk) {
  15104. if (this.intent !== 'oplist') {
  15105. new QueueOptimizer().optimize(this);
  15106. }
  15107. var transfers = getTransfers(this);
  15108. this.messageHandler.send('RenderPageChunk', {
  15109. operatorList: {
  15110. fnArray: this.fnArray,
  15111. argsArray: this.argsArray,
  15112. lastChunk: lastChunk,
  15113. length: this.length
  15114. },
  15115. pageIndex: this.pageIndex,
  15116. intent: this.intent
  15117. }, transfers);
  15118. this.dependencies = {};
  15119. this.fnArray.length = 0;
  15120. this.argsArray.length = 0;
  15121. }
  15122. };
  15123. return OperatorList;
  15124. })();
  15125. var StateManager = (function StateManagerClosure() {
  15126. function StateManager(initialState) {
  15127. this.state = initialState;
  15128. this.stateStack = [];
  15129. }
  15130. StateManager.prototype = {
  15131. save: function () {
  15132. var old = this.state;
  15133. this.stateStack.push(this.state);
  15134. this.state = old.clone();
  15135. },
  15136. restore: function () {
  15137. var prev = this.stateStack.pop();
  15138. if (prev) {
  15139. this.state = prev;
  15140. }
  15141. },
  15142. transform: function (args) {
  15143. this.state.ctm = Util.transform(this.state.ctm, args);
  15144. }
  15145. };
  15146. return StateManager;
  15147. })();
  15148. var TextState = (function TextStateClosure() {
  15149. function TextState() {
  15150. this.ctm = new Float32Array(IDENTITY_MATRIX);
  15151. this.fontSize = 0;
  15152. this.font = null;
  15153. this.fontMatrix = FONT_IDENTITY_MATRIX;
  15154. this.textMatrix = IDENTITY_MATRIX.slice();
  15155. this.textLineMatrix = IDENTITY_MATRIX.slice();
  15156. this.charSpacing = 0;
  15157. this.wordSpacing = 0;
  15158. this.leading = 0;
  15159. this.textHScale = 1;
  15160. this.textRise = 0;
  15161. }
  15162. TextState.prototype = {
  15163. setTextMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  15164. var m = this.textMatrix;
  15165. m[0] = a; m[1] = b; m[2] = c; m[3] = d; m[4] = e; m[5] = f;
  15166. },
  15167. setTextLineMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  15168. var m = this.textLineMatrix;
  15169. m[0] = a; m[1] = b; m[2] = c; m[3] = d; m[4] = e; m[5] = f;
  15170. },
  15171. translateTextMatrix: function TextState_translateTextMatrix(x, y) {
  15172. var m = this.textMatrix;
  15173. m[4] = m[0] * x + m[2] * y + m[4];
  15174. m[5] = m[1] * x + m[3] * y + m[5];
  15175. },
  15176. translateTextLineMatrix: function TextState_translateTextMatrix(x, y) {
  15177. var m = this.textLineMatrix;
  15178. m[4] = m[0] * x + m[2] * y + m[4];
  15179. m[5] = m[1] * x + m[3] * y + m[5];
  15180. },
  15181. calcRenderMatrix: function TextState_calcRendeMatrix(ctm) {
  15182. // 9.4.4 Text Space Details
  15183. var tsm = [this.fontSize * this.textHScale, 0,
  15184. 0, this.fontSize,
  15185. 0, this.textRise];
  15186. return Util.transform(ctm, Util.transform(this.textMatrix, tsm));
  15187. },
  15188. carriageReturn: function TextState_carriageReturn() {
  15189. this.translateTextLineMatrix(0, -this.leading);
  15190. this.textMatrix = this.textLineMatrix.slice();
  15191. },
  15192. clone: function TextState_clone() {
  15193. var clone = Object.create(this);
  15194. clone.textMatrix = this.textMatrix.slice();
  15195. clone.textLineMatrix = this.textLineMatrix.slice();
  15196. clone.fontMatrix = this.fontMatrix.slice();
  15197. return clone;
  15198. }
  15199. };
  15200. return TextState;
  15201. })();
  15202. var EvalState = (function EvalStateClosure() {
  15203. function EvalState() {
  15204. this.ctm = new Float32Array(IDENTITY_MATRIX);
  15205. this.font = null;
  15206. this.textRenderingMode = TextRenderingMode.FILL;
  15207. this.fillColorSpace = ColorSpace.singletons.gray;
  15208. this.strokeColorSpace = ColorSpace.singletons.gray;
  15209. }
  15210. EvalState.prototype = {
  15211. clone: function CanvasExtraState_clone() {
  15212. return Object.create(this);
  15213. },
  15214. };
  15215. return EvalState;
  15216. })();
  15217. var EvaluatorPreprocessor = (function EvaluatorPreprocessorClosure() {
  15218. // Specifies properties for each command
  15219. //
  15220. // If variableArgs === true: [0, `numArgs`] expected
  15221. // If variableArgs === false: exactly `numArgs` expected
  15222. var OP_MAP = {
  15223. // Graphic state
  15224. w: { id: OPS.setLineWidth, numArgs: 1, variableArgs: false },
  15225. J: { id: OPS.setLineCap, numArgs: 1, variableArgs: false },
  15226. j: { id: OPS.setLineJoin, numArgs: 1, variableArgs: false },
  15227. M: { id: OPS.setMiterLimit, numArgs: 1, variableArgs: false },
  15228. d: { id: OPS.setDash, numArgs: 2, variableArgs: false },
  15229. ri: { id: OPS.setRenderingIntent, numArgs: 1, variableArgs: false },
  15230. i: { id: OPS.setFlatness, numArgs: 1, variableArgs: false },
  15231. gs: { id: OPS.setGState, numArgs: 1, variableArgs: false },
  15232. q: { id: OPS.save, numArgs: 0, variableArgs: false },
  15233. Q: { id: OPS.restore, numArgs: 0, variableArgs: false },
  15234. cm: { id: OPS.transform, numArgs: 6, variableArgs: false },
  15235. // Path
  15236. m: { id: OPS.moveTo, numArgs: 2, variableArgs: false },
  15237. l: { id: OPS.lineTo, numArgs: 2, variableArgs: false },
  15238. c: { id: OPS.curveTo, numArgs: 6, variableArgs: false },
  15239. v: { id: OPS.curveTo2, numArgs: 4, variableArgs: false },
  15240. y: { id: OPS.curveTo3, numArgs: 4, variableArgs: false },
  15241. h: { id: OPS.closePath, numArgs: 0, variableArgs: false },
  15242. re: { id: OPS.rectangle, numArgs: 4, variableArgs: false },
  15243. S: { id: OPS.stroke, numArgs: 0, variableArgs: false },
  15244. s: { id: OPS.closeStroke, numArgs: 0, variableArgs: false },
  15245. f: { id: OPS.fill, numArgs: 0, variableArgs: false },
  15246. F: { id: OPS.fill, numArgs: 0, variableArgs: false },
  15247. 'f*': { id: OPS.eoFill, numArgs: 0, variableArgs: false },
  15248. B: { id: OPS.fillStroke, numArgs: 0, variableArgs: false },
  15249. 'B*': { id: OPS.eoFillStroke, numArgs: 0, variableArgs: false },
  15250. b: { id: OPS.closeFillStroke, numArgs: 0, variableArgs: false },
  15251. 'b*': { id: OPS.closeEOFillStroke, numArgs: 0, variableArgs: false },
  15252. n: { id: OPS.endPath, numArgs: 0, variableArgs: false },
  15253. // Clipping
  15254. W: { id: OPS.clip, numArgs: 0, variableArgs: false },
  15255. 'W*': { id: OPS.eoClip, numArgs: 0, variableArgs: false },
  15256. // Text
  15257. BT: { id: OPS.beginText, numArgs: 0, variableArgs: false },
  15258. ET: { id: OPS.endText, numArgs: 0, variableArgs: false },
  15259. Tc: { id: OPS.setCharSpacing, numArgs: 1, variableArgs: false },
  15260. Tw: { id: OPS.setWordSpacing, numArgs: 1, variableArgs: false },
  15261. Tz: { id: OPS.setHScale, numArgs: 1, variableArgs: false },
  15262. TL: { id: OPS.setLeading, numArgs: 1, variableArgs: false },
  15263. Tf: { id: OPS.setFont, numArgs: 2, variableArgs: false },
  15264. Tr: { id: OPS.setTextRenderingMode, numArgs: 1, variableArgs: false },
  15265. Ts: { id: OPS.setTextRise, numArgs: 1, variableArgs: false },
  15266. Td: { id: OPS.moveText, numArgs: 2, variableArgs: false },
  15267. TD: { id: OPS.setLeadingMoveText, numArgs: 2, variableArgs: false },
  15268. Tm: { id: OPS.setTextMatrix, numArgs: 6, variableArgs: false },
  15269. 'T*': { id: OPS.nextLine, numArgs: 0, variableArgs: false },
  15270. Tj: { id: OPS.showText, numArgs: 1, variableArgs: false },
  15271. TJ: { id: OPS.showSpacedText, numArgs: 1, variableArgs: false },
  15272. '\'': { id: OPS.nextLineShowText, numArgs: 1, variableArgs: false },
  15273. '"': { id: OPS.nextLineSetSpacingShowText, numArgs: 3,
  15274. variableArgs: false },
  15275. // Type3 fonts
  15276. d0: { id: OPS.setCharWidth, numArgs: 2, variableArgs: false },
  15277. d1: { id: OPS.setCharWidthAndBounds, numArgs: 6, variableArgs: false },
  15278. // Color
  15279. CS: { id: OPS.setStrokeColorSpace, numArgs: 1, variableArgs: false },
  15280. cs: { id: OPS.setFillColorSpace, numArgs: 1, variableArgs: false },
  15281. SC: { id: OPS.setStrokeColor, numArgs: 4, variableArgs: true },
  15282. SCN: { id: OPS.setStrokeColorN, numArgs: 33, variableArgs: true },
  15283. sc: { id: OPS.setFillColor, numArgs: 4, variableArgs: true },
  15284. scn: { id: OPS.setFillColorN, numArgs: 33, variableArgs: true },
  15285. G: { id: OPS.setStrokeGray, numArgs: 1, variableArgs: false },
  15286. g: { id: OPS.setFillGray, numArgs: 1, variableArgs: false },
  15287. RG: { id: OPS.setStrokeRGBColor, numArgs: 3, variableArgs: false },
  15288. rg: { id: OPS.setFillRGBColor, numArgs: 3, variableArgs: false },
  15289. K: { id: OPS.setStrokeCMYKColor, numArgs: 4, variableArgs: false },
  15290. k: { id: OPS.setFillCMYKColor, numArgs: 4, variableArgs: false },
  15291. // Shading
  15292. sh: { id: OPS.shadingFill, numArgs: 1, variableArgs: false },
  15293. // Images
  15294. BI: { id: OPS.beginInlineImage, numArgs: 0, variableArgs: false },
  15295. ID: { id: OPS.beginImageData, numArgs: 0, variableArgs: false },
  15296. EI: { id: OPS.endInlineImage, numArgs: 1, variableArgs: false },
  15297. // XObjects
  15298. Do: { id: OPS.paintXObject, numArgs: 1, variableArgs: false },
  15299. MP: { id: OPS.markPoint, numArgs: 1, variableArgs: false },
  15300. DP: { id: OPS.markPointProps, numArgs: 2, variableArgs: false },
  15301. BMC: { id: OPS.beginMarkedContent, numArgs: 1, variableArgs: false },
  15302. BDC: { id: OPS.beginMarkedContentProps, numArgs: 2,
  15303. variableArgs: false },
  15304. EMC: { id: OPS.endMarkedContent, numArgs: 0, variableArgs: false },
  15305. // Compatibility
  15306. BX: { id: OPS.beginCompat, numArgs: 0, variableArgs: false },
  15307. EX: { id: OPS.endCompat, numArgs: 0, variableArgs: false },
  15308. // (reserved partial commands for the lexer)
  15309. BM: null,
  15310. BD: null,
  15311. 'true': null,
  15312. fa: null,
  15313. fal: null,
  15314. fals: null,
  15315. 'false': null,
  15316. nu: null,
  15317. nul: null,
  15318. 'null': null
  15319. };
  15320. function EvaluatorPreprocessor(stream, xref, stateManager) {
  15321. // TODO(mduan): pass array of knownCommands rather than OP_MAP
  15322. // dictionary
  15323. this.parser = new Parser(new Lexer(stream, OP_MAP), false, xref);
  15324. this.stateManager = stateManager;
  15325. this.nonProcessedArgs = [];
  15326. }
  15327. EvaluatorPreprocessor.prototype = {
  15328. get savedStatesDepth() {
  15329. return this.stateManager.stateStack.length;
  15330. },
  15331. read: function EvaluatorPreprocessor_read(operation) {
  15332. // We use an array to represent args, except we use |null| to represent
  15333. // no args because it's more compact than an empty array.
  15334. var args = null;
  15335. while (true) {
  15336. var obj = this.parser.getObj();
  15337. if (isCmd(obj)) {
  15338. var cmd = obj.cmd;
  15339. // Check that the command is valid
  15340. var opSpec = OP_MAP[cmd];
  15341. if (!opSpec) {
  15342. warn('Unknown command "' + cmd + '"');
  15343. continue;
  15344. }
  15345. var fn = opSpec.id;
  15346. var numArgs = opSpec.numArgs;
  15347. var argsLength = args !== null ? args.length : 0;
  15348. if (!opSpec.variableArgs) {
  15349. // Postscript commands can be nested, e.g. /F2 /GS2 gs 5.711 Tf
  15350. if (argsLength !== numArgs) {
  15351. var nonProcessedArgs = this.nonProcessedArgs;
  15352. while (argsLength > numArgs) {
  15353. nonProcessedArgs.push(args.shift());
  15354. argsLength--;
  15355. }
  15356. while (argsLength < numArgs && nonProcessedArgs.length !== 0) {
  15357. if (!args) {
  15358. args = [];
  15359. }
  15360. args.unshift(nonProcessedArgs.pop());
  15361. argsLength++;
  15362. }
  15363. }
  15364. if (argsLength < numArgs) {
  15365. // If we receive too few args, it's not possible to possible
  15366. // to execute the command, so skip the command
  15367. info('Command ' + fn + ': because expected ' +
  15368. numArgs + ' args, but received ' + argsLength +
  15369. ' args; skipping');
  15370. args = null;
  15371. continue;
  15372. }
  15373. } else if (argsLength > numArgs) {
  15374. info('Command ' + fn + ': expected [0,' + numArgs +
  15375. '] args, but received ' + argsLength + ' args');
  15376. }
  15377. // TODO figure out how to type-check vararg functions
  15378. this.preprocessCommand(fn, args);
  15379. operation.fn = fn;
  15380. operation.args = args;
  15381. return true;
  15382. } else {
  15383. if (isEOF(obj)) {
  15384. return false; // no more commands
  15385. }
  15386. // argument
  15387. if (obj !== null) {
  15388. if (!args) {
  15389. args = [];
  15390. }
  15391. args.push((obj instanceof Dict ? obj.getAll() : obj));
  15392. assert(args.length <= 33, 'Too many arguments');
  15393. }
  15394. }
  15395. }
  15396. },
  15397. preprocessCommand:
  15398. function EvaluatorPreprocessor_preprocessCommand(fn, args) {
  15399. switch (fn | 0) {
  15400. case OPS.save:
  15401. this.stateManager.save();
  15402. break;
  15403. case OPS.restore:
  15404. this.stateManager.restore();
  15405. break;
  15406. case OPS.transform:
  15407. this.stateManager.transform(args);
  15408. break;
  15409. }
  15410. }
  15411. };
  15412. return EvaluatorPreprocessor;
  15413. })();
  15414. var QueueOptimizer = (function QueueOptimizerClosure() {
  15415. function addState(parentState, pattern, fn) {
  15416. var state = parentState;
  15417. for (var i = 0, ii = pattern.length - 1; i < ii; i++) {
  15418. var item = pattern[i];
  15419. state = (state[item] || (state[item] = []));
  15420. }
  15421. state[pattern[pattern.length - 1]] = fn;
  15422. }
  15423. function handlePaintSolidColorImageMask(iFirstSave, count, fnArray,
  15424. argsArray) {
  15425. // Handles special case of mainly LaTeX documents which use image masks to
  15426. // draw lines with the current fill style.
  15427. // 'count' groups of (save, transform, paintImageMaskXObject, restore)+
  15428. // have been found at iFirstSave.
  15429. var iFirstPIMXO = iFirstSave + 2;
  15430. for (var i = 0; i < count; i++) {
  15431. var arg = argsArray[iFirstPIMXO + 4 * i];
  15432. var imageMask = arg.length === 1 && arg[0];
  15433. if (imageMask && imageMask.width === 1 && imageMask.height === 1 &&
  15434. (!imageMask.data.length ||
  15435. (imageMask.data.length === 1 && imageMask.data[0] === 0))) {
  15436. fnArray[iFirstPIMXO + 4 * i] = OPS.paintSolidColorImageMask;
  15437. continue;
  15438. }
  15439. break;
  15440. }
  15441. return count - i;
  15442. }
  15443. var InitialState = [];
  15444. // This replaces (save, transform, paintInlineImageXObject, restore)+
  15445. // sequences with one |paintInlineImageXObjectGroup| operation.
  15446. addState(InitialState,
  15447. [OPS.save, OPS.transform, OPS.paintInlineImageXObject, OPS.restore],
  15448. function foundInlineImageGroup(context) {
  15449. var MIN_IMAGES_IN_INLINE_IMAGES_BLOCK = 10;
  15450. var MAX_IMAGES_IN_INLINE_IMAGES_BLOCK = 200;
  15451. var MAX_WIDTH = 1000;
  15452. var IMAGE_PADDING = 1;
  15453. var fnArray = context.fnArray, argsArray = context.argsArray;
  15454. var curr = context.iCurr;
  15455. var iFirstSave = curr - 3;
  15456. var iFirstTransform = curr - 2;
  15457. var iFirstPIIXO = curr - 1;
  15458. // Look for the quartets.
  15459. var i = iFirstSave + 4;
  15460. var ii = fnArray.length;
  15461. while (i + 3 < ii) {
  15462. if (fnArray[i] !== OPS.save ||
  15463. fnArray[i + 1] !== OPS.transform ||
  15464. fnArray[i + 2] !== OPS.paintInlineImageXObject ||
  15465. fnArray[i + 3] !== OPS.restore) {
  15466. break; // ops don't match
  15467. }
  15468. i += 4;
  15469. }
  15470. // At this point, i is the index of the first op past the last valid
  15471. // quartet.
  15472. var count = Math.min((i - iFirstSave) / 4,
  15473. MAX_IMAGES_IN_INLINE_IMAGES_BLOCK);
  15474. if (count < MIN_IMAGES_IN_INLINE_IMAGES_BLOCK) {
  15475. return i;
  15476. }
  15477. // assuming that heights of those image is too small (~1 pixel)
  15478. // packing as much as possible by lines
  15479. var maxX = 0;
  15480. var map = [], maxLineHeight = 0;
  15481. var currentX = IMAGE_PADDING, currentY = IMAGE_PADDING;
  15482. var q;
  15483. for (q = 0; q < count; q++) {
  15484. var transform = argsArray[iFirstTransform + (q << 2)];
  15485. var img = argsArray[iFirstPIIXO + (q << 2)][0];
  15486. if (currentX + img.width > MAX_WIDTH) {
  15487. // starting new line
  15488. maxX = Math.max(maxX, currentX);
  15489. currentY += maxLineHeight + 2 * IMAGE_PADDING;
  15490. currentX = 0;
  15491. maxLineHeight = 0;
  15492. }
  15493. map.push({
  15494. transform: transform,
  15495. x: currentX, y: currentY,
  15496. w: img.width, h: img.height
  15497. });
  15498. currentX += img.width + 2 * IMAGE_PADDING;
  15499. maxLineHeight = Math.max(maxLineHeight, img.height);
  15500. }
  15501. var imgWidth = Math.max(maxX, currentX) + IMAGE_PADDING;
  15502. var imgHeight = currentY + maxLineHeight + IMAGE_PADDING;
  15503. var imgData = new Uint8Array(imgWidth * imgHeight * 4);
  15504. var imgRowSize = imgWidth << 2;
  15505. for (q = 0; q < count; q++) {
  15506. var data = argsArray[iFirstPIIXO + (q << 2)][0].data;
  15507. // Copy image by lines and extends pixels into padding.
  15508. var rowSize = map[q].w << 2;
  15509. var dataOffset = 0;
  15510. var offset = (map[q].x + map[q].y * imgWidth) << 2;
  15511. imgData.set(data.subarray(0, rowSize), offset - imgRowSize);
  15512. for (var k = 0, kk = map[q].h; k < kk; k++) {
  15513. imgData.set(data.subarray(dataOffset, dataOffset + rowSize), offset);
  15514. dataOffset += rowSize;
  15515. offset += imgRowSize;
  15516. }
  15517. imgData.set(data.subarray(dataOffset - rowSize, dataOffset), offset);
  15518. while (offset >= 0) {
  15519. data[offset - 4] = data[offset];
  15520. data[offset - 3] = data[offset + 1];
  15521. data[offset - 2] = data[offset + 2];
  15522. data[offset - 1] = data[offset + 3];
  15523. data[offset + rowSize] = data[offset + rowSize - 4];
  15524. data[offset + rowSize + 1] = data[offset + rowSize - 3];
  15525. data[offset + rowSize + 2] = data[offset + rowSize - 2];
  15526. data[offset + rowSize + 3] = data[offset + rowSize - 1];
  15527. offset -= imgRowSize;
  15528. }
  15529. }
  15530. // Replace queue items.
  15531. fnArray.splice(iFirstSave, count * 4, OPS.paintInlineImageXObjectGroup);
  15532. argsArray.splice(iFirstSave, count * 4,
  15533. [{ width: imgWidth, height: imgHeight, kind: ImageKind.RGBA_32BPP,
  15534. data: imgData }, map]);
  15535. return iFirstSave + 1;
  15536. });
  15537. // This replaces (save, transform, paintImageMaskXObject, restore)+
  15538. // sequences with one |paintImageMaskXObjectGroup| or one
  15539. // |paintImageMaskXObjectRepeat| operation.
  15540. addState(InitialState,
  15541. [OPS.save, OPS.transform, OPS.paintImageMaskXObject, OPS.restore],
  15542. function foundImageMaskGroup(context) {
  15543. var MIN_IMAGES_IN_MASKS_BLOCK = 10;
  15544. var MAX_IMAGES_IN_MASKS_BLOCK = 100;
  15545. var MAX_SAME_IMAGES_IN_MASKS_BLOCK = 1000;
  15546. var fnArray = context.fnArray, argsArray = context.argsArray;
  15547. var curr = context.iCurr;
  15548. var iFirstSave = curr - 3;
  15549. var iFirstTransform = curr - 2;
  15550. var iFirstPIMXO = curr - 1;
  15551. // Look for the quartets.
  15552. var i = iFirstSave + 4;
  15553. var ii = fnArray.length;
  15554. while (i + 3 < ii) {
  15555. if (fnArray[i] !== OPS.save ||
  15556. fnArray[i + 1] !== OPS.transform ||
  15557. fnArray[i + 2] !== OPS.paintImageMaskXObject ||
  15558. fnArray[i + 3] !== OPS.restore) {
  15559. break; // ops don't match
  15560. }
  15561. i += 4;
  15562. }
  15563. // At this point, i is the index of the first op past the last valid
  15564. // quartet.
  15565. var count = (i - iFirstSave) / 4;
  15566. count = handlePaintSolidColorImageMask(iFirstSave, count, fnArray,
  15567. argsArray);
  15568. if (count < MIN_IMAGES_IN_MASKS_BLOCK) {
  15569. return i;
  15570. }
  15571. var q;
  15572. var isSameImage = false;
  15573. var iTransform, transformArgs;
  15574. var firstPIMXOArg0 = argsArray[iFirstPIMXO][0];
  15575. if (argsArray[iFirstTransform][1] === 0 &&
  15576. argsArray[iFirstTransform][2] === 0) {
  15577. isSameImage = true;
  15578. var firstTransformArg0 = argsArray[iFirstTransform][0];
  15579. var firstTransformArg3 = argsArray[iFirstTransform][3];
  15580. iTransform = iFirstTransform + 4;
  15581. var iPIMXO = iFirstPIMXO + 4;
  15582. for (q = 1; q < count; q++, iTransform += 4, iPIMXO += 4) {
  15583. transformArgs = argsArray[iTransform];
  15584. if (argsArray[iPIMXO][0] !== firstPIMXOArg0 ||
  15585. transformArgs[0] !== firstTransformArg0 ||
  15586. transformArgs[1] !== 0 ||
  15587. transformArgs[2] !== 0 ||
  15588. transformArgs[3] !== firstTransformArg3) {
  15589. if (q < MIN_IMAGES_IN_MASKS_BLOCK) {
  15590. isSameImage = false;
  15591. } else {
  15592. count = q;
  15593. }
  15594. break; // different image or transform
  15595. }
  15596. }
  15597. }
  15598. if (isSameImage) {
  15599. count = Math.min(count, MAX_SAME_IMAGES_IN_MASKS_BLOCK);
  15600. var positions = new Float32Array(count * 2);
  15601. iTransform = iFirstTransform;
  15602. for (q = 0; q < count; q++, iTransform += 4) {
  15603. transformArgs = argsArray[iTransform];
  15604. positions[(q << 1)] = transformArgs[4];
  15605. positions[(q << 1) + 1] = transformArgs[5];
  15606. }
  15607. // Replace queue items.
  15608. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectRepeat);
  15609. argsArray.splice(iFirstSave, count * 4,
  15610. [firstPIMXOArg0, firstTransformArg0, firstTransformArg3, positions]);
  15611. } else {
  15612. count = Math.min(count, MAX_IMAGES_IN_MASKS_BLOCK);
  15613. var images = [];
  15614. for (q = 0; q < count; q++) {
  15615. transformArgs = argsArray[iFirstTransform + (q << 2)];
  15616. var maskParams = argsArray[iFirstPIMXO + (q << 2)][0];
  15617. images.push({ data: maskParams.data, width: maskParams.width,
  15618. height: maskParams.height,
  15619. transform: transformArgs });
  15620. }
  15621. // Replace queue items.
  15622. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectGroup);
  15623. argsArray.splice(iFirstSave, count * 4, [images]);
  15624. }
  15625. return iFirstSave + 1;
  15626. });
  15627. // This replaces (save, transform, paintImageXObject, restore)+ sequences
  15628. // with one paintImageXObjectRepeat operation, if the |transform| and
  15629. // |paintImageXObjectRepeat| ops are appropriate.
  15630. addState(InitialState,
  15631. [OPS.save, OPS.transform, OPS.paintImageXObject, OPS.restore],
  15632. function (context) {
  15633. var MIN_IMAGES_IN_BLOCK = 3;
  15634. var MAX_IMAGES_IN_BLOCK = 1000;
  15635. var fnArray = context.fnArray, argsArray = context.argsArray;
  15636. var curr = context.iCurr;
  15637. var iFirstSave = curr - 3;
  15638. var iFirstTransform = curr - 2;
  15639. var iFirstPIXO = curr - 1;
  15640. var iFirstRestore = curr;
  15641. if (argsArray[iFirstTransform][1] !== 0 ||
  15642. argsArray[iFirstTransform][2] !== 0) {
  15643. return iFirstRestore + 1; // transform has the wrong form
  15644. }
  15645. // Look for the quartets.
  15646. var firstPIXOArg0 = argsArray[iFirstPIXO][0];
  15647. var firstTransformArg0 = argsArray[iFirstTransform][0];
  15648. var firstTransformArg3 = argsArray[iFirstTransform][3];
  15649. var i = iFirstSave + 4;
  15650. var ii = fnArray.length;
  15651. while (i + 3 < ii) {
  15652. if (fnArray[i] !== OPS.save ||
  15653. fnArray[i + 1] !== OPS.transform ||
  15654. fnArray[i + 2] !== OPS.paintImageXObject ||
  15655. fnArray[i + 3] !== OPS.restore) {
  15656. break; // ops don't match
  15657. }
  15658. if (argsArray[i + 1][0] !== firstTransformArg0 ||
  15659. argsArray[i + 1][1] !== 0 ||
  15660. argsArray[i + 1][2] !== 0 ||
  15661. argsArray[i + 1][3] !== firstTransformArg3) {
  15662. break; // transforms don't match
  15663. }
  15664. if (argsArray[i + 2][0] !== firstPIXOArg0) {
  15665. break; // images don't match
  15666. }
  15667. i += 4;
  15668. }
  15669. // At this point, i is the index of the first op past the last valid
  15670. // quartet.
  15671. var count = Math.min((i - iFirstSave) / 4, MAX_IMAGES_IN_BLOCK);
  15672. if (count < MIN_IMAGES_IN_BLOCK) {
  15673. return i;
  15674. }
  15675. // Extract the (x,y) positions from all of the matching transforms.
  15676. var positions = new Float32Array(count * 2);
  15677. var iTransform = iFirstTransform;
  15678. for (var q = 0; q < count; q++, iTransform += 4) {
  15679. var transformArgs = argsArray[iTransform];
  15680. positions[(q << 1)] = transformArgs[4];
  15681. positions[(q << 1) + 1] = transformArgs[5];
  15682. }
  15683. // Replace queue items.
  15684. var args = [firstPIXOArg0, firstTransformArg0, firstTransformArg3,
  15685. positions];
  15686. fnArray.splice(iFirstSave, count * 4, OPS.paintImageXObjectRepeat);
  15687. argsArray.splice(iFirstSave, count * 4, args);
  15688. return iFirstSave + 1;
  15689. });
  15690. // This replaces (beginText, setFont, setTextMatrix, showText, endText)+
  15691. // sequences with (beginText, setFont, (setTextMatrix, showText)+, endText)+
  15692. // sequences, if the font for each one is the same.
  15693. addState(InitialState,
  15694. [OPS.beginText, OPS.setFont, OPS.setTextMatrix, OPS.showText, OPS.endText],
  15695. function (context) {
  15696. var MIN_CHARS_IN_BLOCK = 3;
  15697. var MAX_CHARS_IN_BLOCK = 1000;
  15698. var fnArray = context.fnArray, argsArray = context.argsArray;
  15699. var curr = context.iCurr;
  15700. var iFirstBeginText = curr - 4;
  15701. var iFirstSetFont = curr - 3;
  15702. var iFirstSetTextMatrix = curr - 2;
  15703. var iFirstShowText = curr - 1;
  15704. var iFirstEndText = curr;
  15705. // Look for the quintets.
  15706. var firstSetFontArg0 = argsArray[iFirstSetFont][0];
  15707. var firstSetFontArg1 = argsArray[iFirstSetFont][1];
  15708. var i = iFirstBeginText + 5;
  15709. var ii = fnArray.length;
  15710. while (i + 4 < ii) {
  15711. if (fnArray[i] !== OPS.beginText ||
  15712. fnArray[i + 1] !== OPS.setFont ||
  15713. fnArray[i + 2] !== OPS.setTextMatrix ||
  15714. fnArray[i + 3] !== OPS.showText ||
  15715. fnArray[i + 4] !== OPS.endText) {
  15716. break; // ops don't match
  15717. }
  15718. if (argsArray[i + 1][0] !== firstSetFontArg0 ||
  15719. argsArray[i + 1][1] !== firstSetFontArg1) {
  15720. break; // fonts don't match
  15721. }
  15722. i += 5;
  15723. }
  15724. // At this point, i is the index of the first op past the last valid
  15725. // quintet.
  15726. var count = Math.min(((i - iFirstBeginText) / 5), MAX_CHARS_IN_BLOCK);
  15727. if (count < MIN_CHARS_IN_BLOCK) {
  15728. return i;
  15729. }
  15730. // If the preceding quintet is (<something>, setFont, setTextMatrix,
  15731. // showText, endText), include that as well. (E.g. <something> might be
  15732. // |dependency|.)
  15733. var iFirst = iFirstBeginText;
  15734. if (iFirstBeginText >= 4 &&
  15735. fnArray[iFirstBeginText - 4] === fnArray[iFirstSetFont] &&
  15736. fnArray[iFirstBeginText - 3] === fnArray[iFirstSetTextMatrix] &&
  15737. fnArray[iFirstBeginText - 2] === fnArray[iFirstShowText] &&
  15738. fnArray[iFirstBeginText - 1] === fnArray[iFirstEndText] &&
  15739. argsArray[iFirstBeginText - 4][0] === firstSetFontArg0 &&
  15740. argsArray[iFirstBeginText - 4][1] === firstSetFontArg1) {
  15741. count++;
  15742. iFirst -= 5;
  15743. }
  15744. // Remove (endText, beginText, setFont) trios.
  15745. var iEndText = iFirst + 4;
  15746. for (var q = 1; q < count; q++) {
  15747. fnArray.splice(iEndText, 3);
  15748. argsArray.splice(iEndText, 3);
  15749. iEndText += 2;
  15750. }
  15751. return iEndText + 1;
  15752. });
  15753. function QueueOptimizer() {}
  15754. QueueOptimizer.prototype = {
  15755. optimize: function QueueOptimizer_optimize(queue) {
  15756. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  15757. var context = {
  15758. iCurr: 0,
  15759. fnArray: fnArray,
  15760. argsArray: argsArray
  15761. };
  15762. var state;
  15763. var i = 0, ii = fnArray.length;
  15764. while (i < ii) {
  15765. state = (state || InitialState)[fnArray[i]];
  15766. if (typeof state === 'function') { // we found some handler
  15767. context.iCurr = i;
  15768. // state() returns the index of the first non-matching op (if we
  15769. // didn't match) or the first op past the modified ops (if we did
  15770. // match and replace).
  15771. i = state(context);
  15772. state = undefined; // reset the state machine
  15773. ii = context.fnArray.length;
  15774. } else {
  15775. i++;
  15776. }
  15777. }
  15778. }
  15779. };
  15780. return QueueOptimizer;
  15781. })();
  15782. var BUILT_IN_CMAPS = [
  15783. // << Start unicode maps.
  15784. 'Adobe-GB1-UCS2',
  15785. 'Adobe-CNS1-UCS2',
  15786. 'Adobe-Japan1-UCS2',
  15787. 'Adobe-Korea1-UCS2',
  15788. // >> End unicode maps.
  15789. '78-EUC-H',
  15790. '78-EUC-V',
  15791. '78-H',
  15792. '78-RKSJ-H',
  15793. '78-RKSJ-V',
  15794. '78-V',
  15795. '78ms-RKSJ-H',
  15796. '78ms-RKSJ-V',
  15797. '83pv-RKSJ-H',
  15798. '90ms-RKSJ-H',
  15799. '90ms-RKSJ-V',
  15800. '90msp-RKSJ-H',
  15801. '90msp-RKSJ-V',
  15802. '90pv-RKSJ-H',
  15803. '90pv-RKSJ-V',
  15804. 'Add-H',
  15805. 'Add-RKSJ-H',
  15806. 'Add-RKSJ-V',
  15807. 'Add-V',
  15808. 'Adobe-CNS1-0',
  15809. 'Adobe-CNS1-1',
  15810. 'Adobe-CNS1-2',
  15811. 'Adobe-CNS1-3',
  15812. 'Adobe-CNS1-4',
  15813. 'Adobe-CNS1-5',
  15814. 'Adobe-CNS1-6',
  15815. 'Adobe-GB1-0',
  15816. 'Adobe-GB1-1',
  15817. 'Adobe-GB1-2',
  15818. 'Adobe-GB1-3',
  15819. 'Adobe-GB1-4',
  15820. 'Adobe-GB1-5',
  15821. 'Adobe-Japan1-0',
  15822. 'Adobe-Japan1-1',
  15823. 'Adobe-Japan1-2',
  15824. 'Adobe-Japan1-3',
  15825. 'Adobe-Japan1-4',
  15826. 'Adobe-Japan1-5',
  15827. 'Adobe-Japan1-6',
  15828. 'Adobe-Korea1-0',
  15829. 'Adobe-Korea1-1',
  15830. 'Adobe-Korea1-2',
  15831. 'B5-H',
  15832. 'B5-V',
  15833. 'B5pc-H',
  15834. 'B5pc-V',
  15835. 'CNS-EUC-H',
  15836. 'CNS-EUC-V',
  15837. 'CNS1-H',
  15838. 'CNS1-V',
  15839. 'CNS2-H',
  15840. 'CNS2-V',
  15841. 'ETHK-B5-H',
  15842. 'ETHK-B5-V',
  15843. 'ETen-B5-H',
  15844. 'ETen-B5-V',
  15845. 'ETenms-B5-H',
  15846. 'ETenms-B5-V',
  15847. 'EUC-H',
  15848. 'EUC-V',
  15849. 'Ext-H',
  15850. 'Ext-RKSJ-H',
  15851. 'Ext-RKSJ-V',
  15852. 'Ext-V',
  15853. 'GB-EUC-H',
  15854. 'GB-EUC-V',
  15855. 'GB-H',
  15856. 'GB-V',
  15857. 'GBK-EUC-H',
  15858. 'GBK-EUC-V',
  15859. 'GBK2K-H',
  15860. 'GBK2K-V',
  15861. 'GBKp-EUC-H',
  15862. 'GBKp-EUC-V',
  15863. 'GBT-EUC-H',
  15864. 'GBT-EUC-V',
  15865. 'GBT-H',
  15866. 'GBT-V',
  15867. 'GBTpc-EUC-H',
  15868. 'GBTpc-EUC-V',
  15869. 'GBpc-EUC-H',
  15870. 'GBpc-EUC-V',
  15871. 'H',
  15872. 'HKdla-B5-H',
  15873. 'HKdla-B5-V',
  15874. 'HKdlb-B5-H',
  15875. 'HKdlb-B5-V',
  15876. 'HKgccs-B5-H',
  15877. 'HKgccs-B5-V',
  15878. 'HKm314-B5-H',
  15879. 'HKm314-B5-V',
  15880. 'HKm471-B5-H',
  15881. 'HKm471-B5-V',
  15882. 'HKscs-B5-H',
  15883. 'HKscs-B5-V',
  15884. 'Hankaku',
  15885. 'Hiragana',
  15886. 'KSC-EUC-H',
  15887. 'KSC-EUC-V',
  15888. 'KSC-H',
  15889. 'KSC-Johab-H',
  15890. 'KSC-Johab-V',
  15891. 'KSC-V',
  15892. 'KSCms-UHC-H',
  15893. 'KSCms-UHC-HW-H',
  15894. 'KSCms-UHC-HW-V',
  15895. 'KSCms-UHC-V',
  15896. 'KSCpc-EUC-H',
  15897. 'KSCpc-EUC-V',
  15898. 'Katakana',
  15899. 'NWP-H',
  15900. 'NWP-V',
  15901. 'RKSJ-H',
  15902. 'RKSJ-V',
  15903. 'Roman',
  15904. 'UniCNS-UCS2-H',
  15905. 'UniCNS-UCS2-V',
  15906. 'UniCNS-UTF16-H',
  15907. 'UniCNS-UTF16-V',
  15908. 'UniCNS-UTF32-H',
  15909. 'UniCNS-UTF32-V',
  15910. 'UniCNS-UTF8-H',
  15911. 'UniCNS-UTF8-V',
  15912. 'UniGB-UCS2-H',
  15913. 'UniGB-UCS2-V',
  15914. 'UniGB-UTF16-H',
  15915. 'UniGB-UTF16-V',
  15916. 'UniGB-UTF32-H',
  15917. 'UniGB-UTF32-V',
  15918. 'UniGB-UTF8-H',
  15919. 'UniGB-UTF8-V',
  15920. 'UniJIS-UCS2-H',
  15921. 'UniJIS-UCS2-HW-H',
  15922. 'UniJIS-UCS2-HW-V',
  15923. 'UniJIS-UCS2-V',
  15924. 'UniJIS-UTF16-H',
  15925. 'UniJIS-UTF16-V',
  15926. 'UniJIS-UTF32-H',
  15927. 'UniJIS-UTF32-V',
  15928. 'UniJIS-UTF8-H',
  15929. 'UniJIS-UTF8-V',
  15930. 'UniJIS2004-UTF16-H',
  15931. 'UniJIS2004-UTF16-V',
  15932. 'UniJIS2004-UTF32-H',
  15933. 'UniJIS2004-UTF32-V',
  15934. 'UniJIS2004-UTF8-H',
  15935. 'UniJIS2004-UTF8-V',
  15936. 'UniJISPro-UCS2-HW-V',
  15937. 'UniJISPro-UCS2-V',
  15938. 'UniJISPro-UTF8-V',
  15939. 'UniJISX0213-UTF32-H',
  15940. 'UniJISX0213-UTF32-V',
  15941. 'UniJISX02132004-UTF32-H',
  15942. 'UniJISX02132004-UTF32-V',
  15943. 'UniKS-UCS2-H',
  15944. 'UniKS-UCS2-V',
  15945. 'UniKS-UTF16-H',
  15946. 'UniKS-UTF16-V',
  15947. 'UniKS-UTF32-H',
  15948. 'UniKS-UTF32-V',
  15949. 'UniKS-UTF8-H',
  15950. 'UniKS-UTF8-V',
  15951. 'V',
  15952. 'WP-Symbol'];
  15953. // CMap, not to be confused with TrueType's cmap.
  15954. var CMap = (function CMapClosure() {
  15955. function CMap(builtInCMap) {
  15956. // Codespace ranges are stored as follows:
  15957. // [[1BytePairs], [2BytePairs], [3BytePairs], [4BytePairs]]
  15958. // where nBytePairs are ranges e.g. [low1, high1, low2, high2, ...]
  15959. this.codespaceRanges = [[], [], [], []];
  15960. this.numCodespaceRanges = 0;
  15961. // Map entries have one of two forms.
  15962. // - cid chars are 16-bit unsigned integers, stored as integers.
  15963. // - bf chars are variable-length byte sequences, stored as strings, with
  15964. // one byte per character.
  15965. this._map = [];
  15966. this.vertical = false;
  15967. this.useCMap = null;
  15968. this.builtInCMap = builtInCMap;
  15969. }
  15970. CMap.prototype = {
  15971. addCodespaceRange: function(n, low, high) {
  15972. this.codespaceRanges[n - 1].push(low, high);
  15973. this.numCodespaceRanges++;
  15974. },
  15975. mapCidRange: function(low, high, dstLow) {
  15976. while (low <= high) {
  15977. this._map[low++] = dstLow++;
  15978. }
  15979. },
  15980. mapBfRange: function(low, high, dstLow) {
  15981. var lastByte = dstLow.length - 1;
  15982. while (low <= high) {
  15983. this._map[low++] = dstLow;
  15984. // Only the last byte has to be incremented.
  15985. dstLow = dstLow.substr(0, lastByte) +
  15986. String.fromCharCode(dstLow.charCodeAt(lastByte) + 1);
  15987. }
  15988. },
  15989. mapBfRangeToArray: function(low, high, array) {
  15990. var i = 0, ii = array.length;
  15991. while (low <= high && i < ii) {
  15992. this._map[low] = array[i++];
  15993. ++low;
  15994. }
  15995. },
  15996. // This is used for both bf and cid chars.
  15997. mapOne: function(src, dst) {
  15998. this._map[src] = dst;
  15999. },
  16000. lookup: function(code) {
  16001. return this._map[code];
  16002. },
  16003. contains: function(code) {
  16004. return this._map[code] !== undefined;
  16005. },
  16006. forEach: function(callback) {
  16007. // Most maps have fewer than 65536 entries, and for those we use normal
  16008. // array iteration. But really sparse tables are possible -- e.g. with
  16009. // indices in the *billions*. For such tables we use for..in, which isn't
  16010. // ideal because it stringifies the indices for all present elements, but
  16011. // it does avoid iterating over every undefined entry.
  16012. var map = this._map;
  16013. var length = map.length;
  16014. var i;
  16015. if (length <= 0x10000) {
  16016. for (i = 0; i < length; i++) {
  16017. if (map[i] !== undefined) {
  16018. callback(i, map[i]);
  16019. }
  16020. }
  16021. } else {
  16022. for (i in this._map) {
  16023. callback(i, map[i]);
  16024. }
  16025. }
  16026. },
  16027. charCodeOf: function(value) {
  16028. return this._map.indexOf(value);
  16029. },
  16030. getMap: function() {
  16031. return this._map;
  16032. },
  16033. readCharCode: function(str, offset) {
  16034. var c = 0;
  16035. var codespaceRanges = this.codespaceRanges;
  16036. var codespaceRangesLen = this.codespaceRanges.length;
  16037. // 9.7.6.2 CMap Mapping
  16038. // The code length is at most 4.
  16039. for (var n = 0; n < codespaceRangesLen; n++) {
  16040. c = ((c << 8) | str.charCodeAt(offset + n)) >>> 0;
  16041. // Check each codespace range to see if it falls within.
  16042. var codespaceRange = codespaceRanges[n];
  16043. for (var k = 0, kk = codespaceRange.length; k < kk;) {
  16044. var low = codespaceRange[k++];
  16045. var high = codespaceRange[k++];
  16046. if (c >= low && c <= high) {
  16047. return [c, n + 1];
  16048. }
  16049. }
  16050. }
  16051. return [0, 1];
  16052. }
  16053. };
  16054. return CMap;
  16055. })();
  16056. // A special case of CMap, where the _map array implicitly has a length of
  16057. // 65535 and each element is equal to its index.
  16058. var IdentityCMap = (function IdentityCMapClosure() {
  16059. function IdentityCMap(vertical, n) {
  16060. CMap.call(this);
  16061. this.vertical = vertical;
  16062. this.addCodespaceRange(n, 0, 0xffff);
  16063. }
  16064. Util.inherit(IdentityCMap, CMap, {});
  16065. IdentityCMap.prototype = {
  16066. addCodespaceRange: CMap.prototype.addCodespaceRange,
  16067. mapCidRange: function(low, high, dstLow) {
  16068. error('should not call mapCidRange');
  16069. },
  16070. mapBfRange: function(low, high, dstLow) {
  16071. error('should not call mapBfRange');
  16072. },
  16073. mapBfRangeToArray: function(low, high, array) {
  16074. error('should not call mapBfRangeToArray');
  16075. },
  16076. mapOne: function(src, dst) {
  16077. error('should not call mapCidOne');
  16078. },
  16079. lookup: function(code) {
  16080. return (isInt(code) && code <= 0xffff) ? code : undefined;
  16081. },
  16082. contains: function(code) {
  16083. return isInt(code) && code <= 0xffff;
  16084. },
  16085. forEach: function(callback) {
  16086. for (var i = 0; i <= 0xffff; i++) {
  16087. callback(i, i);
  16088. }
  16089. },
  16090. charCodeOf: function(value) {
  16091. return (isInt(value) && value <= 0xffff) ? value : -1;
  16092. },
  16093. getMap: function() {
  16094. // Sometimes identity maps must be instantiated, but it's rare.
  16095. var map = new Array(0x10000);
  16096. for (var i = 0; i <= 0xffff; i++) {
  16097. map[i] = i;
  16098. }
  16099. return map;
  16100. },
  16101. readCharCode: CMap.prototype.readCharCode
  16102. };
  16103. return IdentityCMap;
  16104. })();
  16105. var BinaryCMapReader = (function BinaryCMapReaderClosure() {
  16106. function fetchBinaryData(url) {
  16107. var nonBinaryRequest = PDFJS.disableWorker;
  16108. var request = new XMLHttpRequest();
  16109. request.open('GET', url, false);
  16110. if (!nonBinaryRequest) {
  16111. try {
  16112. request.responseType = 'arraybuffer';
  16113. nonBinaryRequest = request.responseType !== 'arraybuffer';
  16114. } catch (e) {
  16115. nonBinaryRequest = true;
  16116. }
  16117. }
  16118. if (nonBinaryRequest && request.overrideMimeType) {
  16119. request.overrideMimeType('text/plain; charset=x-user-defined');
  16120. }
  16121. request.send(null);
  16122. if (request.status === 0 && /^https?:/i.test(url)) {
  16123. error('Unable to get binary cMap at: ' + url);
  16124. }
  16125. if (nonBinaryRequest) {
  16126. var data = Array.prototype.map.call(request.responseText, function (ch) {
  16127. return ch.charCodeAt(0) & 255;
  16128. });
  16129. return new Uint8Array(data);
  16130. }
  16131. return new Uint8Array(request.response);
  16132. }
  16133. function hexToInt(a, size) {
  16134. var n = 0;
  16135. for (var i = 0; i <= size; i++) {
  16136. n = (n << 8) | a[i];
  16137. }
  16138. return n >>> 0;
  16139. }
  16140. function hexToStr(a, size) {
  16141. // This code is hot. Special-case some common values to avoid creating an
  16142. // object with subarray().
  16143. if (size === 1) {
  16144. return String.fromCharCode(a[0], a[1]);
  16145. }
  16146. if (size === 3) {
  16147. return String.fromCharCode(a[0], a[1], a[2], a[3]);
  16148. }
  16149. return String.fromCharCode.apply(null, a.subarray(0, size + 1));
  16150. }
  16151. function addHex(a, b, size) {
  16152. var c = 0;
  16153. for (var i = size; i >= 0; i--) {
  16154. c += a[i] + b[i];
  16155. a[i] = c & 255;
  16156. c >>= 8;
  16157. }
  16158. }
  16159. function incHex(a, size) {
  16160. var c = 1;
  16161. for (var i = size; i >= 0 && c > 0; i--) {
  16162. c += a[i];
  16163. a[i] = c & 255;
  16164. c >>= 8;
  16165. }
  16166. }
  16167. var MAX_NUM_SIZE = 16;
  16168. var MAX_ENCODED_NUM_SIZE = 19; // ceil(MAX_NUM_SIZE * 7 / 8)
  16169. function BinaryCMapStream(data) {
  16170. this.buffer = data;
  16171. this.pos = 0;
  16172. this.end = data.length;
  16173. this.tmpBuf = new Uint8Array(MAX_ENCODED_NUM_SIZE);
  16174. }
  16175. BinaryCMapStream.prototype = {
  16176. readByte: function () {
  16177. if (this.pos >= this.end) {
  16178. return -1;
  16179. }
  16180. return this.buffer[this.pos++];
  16181. },
  16182. readNumber: function () {
  16183. var n = 0;
  16184. var last;
  16185. do {
  16186. var b = this.readByte();
  16187. if (b < 0) {
  16188. error('unexpected EOF in bcmap');
  16189. }
  16190. last = !(b & 0x80);
  16191. n = (n << 7) | (b & 0x7F);
  16192. } while (!last);
  16193. return n;
  16194. },
  16195. readSigned: function () {
  16196. var n = this.readNumber();
  16197. return (n & 1) ? ~(n >>> 1) : n >>> 1;
  16198. },
  16199. readHex: function (num, size) {
  16200. num.set(this.buffer.subarray(this.pos,
  16201. this.pos + size + 1));
  16202. this.pos += size + 1;
  16203. },
  16204. readHexNumber: function (num, size) {
  16205. var last;
  16206. var stack = this.tmpBuf, sp = 0;
  16207. do {
  16208. var b = this.readByte();
  16209. if (b < 0) {
  16210. error('unexpected EOF in bcmap');
  16211. }
  16212. last = !(b & 0x80);
  16213. stack[sp++] = b & 0x7F;
  16214. } while (!last);
  16215. var i = size, buffer = 0, bufferSize = 0;
  16216. while (i >= 0) {
  16217. while (bufferSize < 8 && stack.length > 0) {
  16218. buffer = (stack[--sp] << bufferSize) | buffer;
  16219. bufferSize += 7;
  16220. }
  16221. num[i] = buffer & 255;
  16222. i--;
  16223. buffer >>= 8;
  16224. bufferSize -= 8;
  16225. }
  16226. },
  16227. readHexSigned: function (num, size) {
  16228. this.readHexNumber(num, size);
  16229. var sign = num[size] & 1 ? 255 : 0;
  16230. var c = 0;
  16231. for (var i = 0; i <= size; i++) {
  16232. c = ((c & 1) << 8) | num[i];
  16233. num[i] = (c >> 1) ^ sign;
  16234. }
  16235. },
  16236. readString: function () {
  16237. var len = this.readNumber();
  16238. var s = '';
  16239. for (var i = 0; i < len; i++) {
  16240. s += String.fromCharCode(this.readNumber());
  16241. }
  16242. return s;
  16243. }
  16244. };
  16245. function processBinaryCMap(url, cMap, extend) {
  16246. var data = fetchBinaryData(url);
  16247. var stream = new BinaryCMapStream(data);
  16248. var header = stream.readByte();
  16249. cMap.vertical = !!(header & 1);
  16250. var useCMap = null;
  16251. var start = new Uint8Array(MAX_NUM_SIZE);
  16252. var end = new Uint8Array(MAX_NUM_SIZE);
  16253. var char = new Uint8Array(MAX_NUM_SIZE);
  16254. var charCode = new Uint8Array(MAX_NUM_SIZE);
  16255. var tmp = new Uint8Array(MAX_NUM_SIZE);
  16256. var code;
  16257. var b;
  16258. while ((b = stream.readByte()) >= 0) {
  16259. var type = b >> 5;
  16260. if (type === 7) { // metadata, e.g. comment or usecmap
  16261. switch (b & 0x1F) {
  16262. case 0:
  16263. stream.readString(); // skipping comment
  16264. break;
  16265. case 1:
  16266. useCMap = stream.readString();
  16267. break;
  16268. }
  16269. continue;
  16270. }
  16271. var sequence = !!(b & 0x10);
  16272. var dataSize = b & 15;
  16273. assert(dataSize + 1 <= MAX_NUM_SIZE);
  16274. var ucs2DataSize = 1;
  16275. var subitemsCount = stream.readNumber();
  16276. var i;
  16277. switch (type) {
  16278. case 0: // codespacerange
  16279. stream.readHex(start, dataSize);
  16280. stream.readHexNumber(end, dataSize);
  16281. addHex(end, start, dataSize);
  16282. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
  16283. hexToInt(end, dataSize));
  16284. for (i = 1; i < subitemsCount; i++) {
  16285. incHex(end, dataSize);
  16286. stream.readHexNumber(start, dataSize);
  16287. addHex(start, end, dataSize);
  16288. stream.readHexNumber(end, dataSize);
  16289. addHex(end, start, dataSize);
  16290. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
  16291. hexToInt(end, dataSize));
  16292. }
  16293. break;
  16294. case 1: // notdefrange
  16295. stream.readHex(start, dataSize);
  16296. stream.readHexNumber(end, dataSize);
  16297. addHex(end, start, dataSize);
  16298. code = stream.readNumber();
  16299. // undefined range, skipping
  16300. for (i = 1; i < subitemsCount; i++) {
  16301. incHex(end, dataSize);
  16302. stream.readHexNumber(start, dataSize);
  16303. addHex(start, end, dataSize);
  16304. stream.readHexNumber(end, dataSize);
  16305. addHex(end, start, dataSize);
  16306. code = stream.readNumber();
  16307. // nop
  16308. }
  16309. break;
  16310. case 2: // cidchar
  16311. stream.readHex(char, dataSize);
  16312. code = stream.readNumber();
  16313. cMap.mapOne(hexToInt(char, dataSize), code);
  16314. for (i = 1; i < subitemsCount; i++) {
  16315. incHex(char, dataSize);
  16316. if (!sequence) {
  16317. stream.readHexNumber(tmp, dataSize);
  16318. addHex(char, tmp, dataSize);
  16319. }
  16320. code = stream.readSigned() + (code + 1);
  16321. cMap.mapOne(hexToInt(char, dataSize), code);
  16322. }
  16323. break;
  16324. case 3: // cidrange
  16325. stream.readHex(start, dataSize);
  16326. stream.readHexNumber(end, dataSize);
  16327. addHex(end, start, dataSize);
  16328. code = stream.readNumber();
  16329. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize),
  16330. code);
  16331. for (i = 1; i < subitemsCount; i++) {
  16332. incHex(end, dataSize);
  16333. if (!sequence) {
  16334. stream.readHexNumber(start, dataSize);
  16335. addHex(start, end, dataSize);
  16336. } else {
  16337. start.set(end);
  16338. }
  16339. stream.readHexNumber(end, dataSize);
  16340. addHex(end, start, dataSize);
  16341. code = stream.readNumber();
  16342. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize),
  16343. code);
  16344. }
  16345. break;
  16346. case 4: // bfchar
  16347. stream.readHex(char, ucs2DataSize);
  16348. stream.readHex(charCode, dataSize);
  16349. cMap.mapOne(hexToInt(char, ucs2DataSize),
  16350. hexToStr(charCode, dataSize));
  16351. for (i = 1; i < subitemsCount; i++) {
  16352. incHex(char, ucs2DataSize);
  16353. if (!sequence) {
  16354. stream.readHexNumber(tmp, ucs2DataSize);
  16355. addHex(char, tmp, ucs2DataSize);
  16356. }
  16357. incHex(charCode, dataSize);
  16358. stream.readHexSigned(tmp, dataSize);
  16359. addHex(charCode, tmp, dataSize);
  16360. cMap.mapOne(hexToInt(char, ucs2DataSize),
  16361. hexToStr(charCode, dataSize));
  16362. }
  16363. break;
  16364. case 5: // bfrange
  16365. stream.readHex(start, ucs2DataSize);
  16366. stream.readHexNumber(end, ucs2DataSize);
  16367. addHex(end, start, ucs2DataSize);
  16368. stream.readHex(charCode, dataSize);
  16369. cMap.mapBfRange(hexToInt(start, ucs2DataSize),
  16370. hexToInt(end, ucs2DataSize),
  16371. hexToStr(charCode, dataSize));
  16372. for (i = 1; i < subitemsCount; i++) {
  16373. incHex(end, ucs2DataSize);
  16374. if (!sequence) {
  16375. stream.readHexNumber(start, ucs2DataSize);
  16376. addHex(start, end, ucs2DataSize);
  16377. } else {
  16378. start.set(end);
  16379. }
  16380. stream.readHexNumber(end, ucs2DataSize);
  16381. addHex(end, start, ucs2DataSize);
  16382. stream.readHex(charCode, dataSize);
  16383. cMap.mapBfRange(hexToInt(start, ucs2DataSize),
  16384. hexToInt(end, ucs2DataSize),
  16385. hexToStr(charCode, dataSize));
  16386. }
  16387. break;
  16388. default:
  16389. error('Unknown type: ' + type);
  16390. break;
  16391. }
  16392. }
  16393. if (useCMap) {
  16394. extend(useCMap);
  16395. }
  16396. return cMap;
  16397. }
  16398. function BinaryCMapReader() {}
  16399. BinaryCMapReader.prototype = {
  16400. read: processBinaryCMap
  16401. };
  16402. return BinaryCMapReader;
  16403. })();
  16404. var CMapFactory = (function CMapFactoryClosure() {
  16405. function strToInt(str) {
  16406. var a = 0;
  16407. for (var i = 0; i < str.length; i++) {
  16408. a = (a << 8) | str.charCodeAt(i);
  16409. }
  16410. return a >>> 0;
  16411. }
  16412. function expectString(obj) {
  16413. if (!isString(obj)) {
  16414. error('Malformed CMap: expected string.');
  16415. }
  16416. }
  16417. function expectInt(obj) {
  16418. if (!isInt(obj)) {
  16419. error('Malformed CMap: expected int.');
  16420. }
  16421. }
  16422. function parseBfChar(cMap, lexer) {
  16423. while (true) {
  16424. var obj = lexer.getObj();
  16425. if (isEOF(obj)) {
  16426. break;
  16427. }
  16428. if (isCmd(obj, 'endbfchar')) {
  16429. return;
  16430. }
  16431. expectString(obj);
  16432. var src = strToInt(obj);
  16433. obj = lexer.getObj();
  16434. // TODO are /dstName used?
  16435. expectString(obj);
  16436. var dst = obj;
  16437. cMap.mapOne(src, dst);
  16438. }
  16439. }
  16440. function parseBfRange(cMap, lexer) {
  16441. while (true) {
  16442. var obj = lexer.getObj();
  16443. if (isEOF(obj)) {
  16444. break;
  16445. }
  16446. if (isCmd(obj, 'endbfrange')) {
  16447. return;
  16448. }
  16449. expectString(obj);
  16450. var low = strToInt(obj);
  16451. obj = lexer.getObj();
  16452. expectString(obj);
  16453. var high = strToInt(obj);
  16454. obj = lexer.getObj();
  16455. if (isInt(obj) || isString(obj)) {
  16456. var dstLow = isInt(obj) ? String.fromCharCode(obj) : obj;
  16457. cMap.mapBfRange(low, high, dstLow);
  16458. } else if (isCmd(obj, '[')) {
  16459. obj = lexer.getObj();
  16460. var array = [];
  16461. while (!isCmd(obj, ']') && !isEOF(obj)) {
  16462. array.push(obj);
  16463. obj = lexer.getObj();
  16464. }
  16465. cMap.mapBfRangeToArray(low, high, array);
  16466. } else {
  16467. break;
  16468. }
  16469. }
  16470. error('Invalid bf range.');
  16471. }
  16472. function parseCidChar(cMap, lexer) {
  16473. while (true) {
  16474. var obj = lexer.getObj();
  16475. if (isEOF(obj)) {
  16476. break;
  16477. }
  16478. if (isCmd(obj, 'endcidchar')) {
  16479. return;
  16480. }
  16481. expectString(obj);
  16482. var src = strToInt(obj);
  16483. obj = lexer.getObj();
  16484. expectInt(obj);
  16485. var dst = obj;
  16486. cMap.mapOne(src, dst);
  16487. }
  16488. }
  16489. function parseCidRange(cMap, lexer) {
  16490. while (true) {
  16491. var obj = lexer.getObj();
  16492. if (isEOF(obj)) {
  16493. break;
  16494. }
  16495. if (isCmd(obj, 'endcidrange')) {
  16496. return;
  16497. }
  16498. expectString(obj);
  16499. var low = strToInt(obj);
  16500. obj = lexer.getObj();
  16501. expectString(obj);
  16502. var high = strToInt(obj);
  16503. obj = lexer.getObj();
  16504. expectInt(obj);
  16505. var dstLow = obj;
  16506. cMap.mapCidRange(low, high, dstLow);
  16507. }
  16508. }
  16509. function parseCodespaceRange(cMap, lexer) {
  16510. while (true) {
  16511. var obj = lexer.getObj();
  16512. if (isEOF(obj)) {
  16513. break;
  16514. }
  16515. if (isCmd(obj, 'endcodespacerange')) {
  16516. return;
  16517. }
  16518. if (!isString(obj)) {
  16519. break;
  16520. }
  16521. var low = strToInt(obj);
  16522. obj = lexer.getObj();
  16523. if (!isString(obj)) {
  16524. break;
  16525. }
  16526. var high = strToInt(obj);
  16527. cMap.addCodespaceRange(obj.length, low, high);
  16528. }
  16529. error('Invalid codespace range.');
  16530. }
  16531. function parseWMode(cMap, lexer) {
  16532. var obj = lexer.getObj();
  16533. if (isInt(obj)) {
  16534. cMap.vertical = !!obj;
  16535. }
  16536. }
  16537. function parseCMap(cMap, lexer, builtInCMapParams, useCMap) {
  16538. var previous;
  16539. var embededUseCMap;
  16540. objLoop: while (true) {
  16541. var obj = lexer.getObj();
  16542. if (isEOF(obj)) {
  16543. break;
  16544. } else if (isName(obj)) {
  16545. if (obj.name === 'WMode') {
  16546. parseWMode(cMap, lexer);
  16547. }
  16548. previous = obj;
  16549. } else if (isCmd(obj)) {
  16550. switch (obj.cmd) {
  16551. case 'endcmap':
  16552. break objLoop;
  16553. case 'usecmap':
  16554. if (isName(previous)) {
  16555. embededUseCMap = previous.name;
  16556. }
  16557. break;
  16558. case 'begincodespacerange':
  16559. parseCodespaceRange(cMap, lexer);
  16560. break;
  16561. case 'beginbfchar':
  16562. parseBfChar(cMap, lexer);
  16563. break;
  16564. case 'begincidchar':
  16565. parseCidChar(cMap, lexer);
  16566. break;
  16567. case 'beginbfrange':
  16568. parseBfRange(cMap, lexer);
  16569. break;
  16570. case 'begincidrange':
  16571. parseCidRange(cMap, lexer);
  16572. break;
  16573. }
  16574. }
  16575. }
  16576. if (!useCMap && embededUseCMap) {
  16577. // Load the usecmap definition from the file only if there wasn't one
  16578. // specified.
  16579. useCMap = embededUseCMap;
  16580. }
  16581. if (useCMap) {
  16582. extendCMap(cMap, builtInCMapParams, useCMap);
  16583. }
  16584. }
  16585. function extendCMap(cMap, builtInCMapParams, useCMap) {
  16586. cMap.useCMap = createBuiltInCMap(useCMap, builtInCMapParams);
  16587. // If there aren't any code space ranges defined clone all the parent ones
  16588. // into this cMap.
  16589. if (cMap.numCodespaceRanges === 0) {
  16590. var useCodespaceRanges = cMap.useCMap.codespaceRanges;
  16591. for (var i = 0; i < useCodespaceRanges.length; i++) {
  16592. cMap.codespaceRanges[i] = useCodespaceRanges[i].slice();
  16593. }
  16594. cMap.numCodespaceRanges = cMap.useCMap.numCodespaceRanges;
  16595. }
  16596. // Merge the map into the current one, making sure not to override
  16597. // any previously defined entries.
  16598. cMap.useCMap.forEach(function(key, value) {
  16599. if (!cMap.contains(key)) {
  16600. cMap.mapOne(key, cMap.useCMap.lookup(key));
  16601. }
  16602. });
  16603. }
  16604. function parseBinaryCMap(name, builtInCMapParams) {
  16605. var url = builtInCMapParams.url + name + '.bcmap';
  16606. var cMap = new CMap(true);
  16607. new BinaryCMapReader().read(url, cMap, function (useCMap) {
  16608. extendCMap(cMap, builtInCMapParams, useCMap);
  16609. });
  16610. return cMap;
  16611. }
  16612. function createBuiltInCMap(name, builtInCMapParams) {
  16613. if (name === 'Identity-H') {
  16614. return new IdentityCMap(false, 2);
  16615. } else if (name === 'Identity-V') {
  16616. return new IdentityCMap(true, 2);
  16617. }
  16618. if (BUILT_IN_CMAPS.indexOf(name) === -1) {
  16619. error('Unknown cMap name: ' + name);
  16620. }
  16621. assert(builtInCMapParams, 'built-in cMap parameters are not provided');
  16622. if (builtInCMapParams.packed) {
  16623. return parseBinaryCMap(name, builtInCMapParams);
  16624. }
  16625. var request = new XMLHttpRequest();
  16626. var url = builtInCMapParams.url + name;
  16627. request.open('GET', url, false);
  16628. request.send(null);
  16629. if (request.status === 0 && /^https?:/i.test(url)) {
  16630. error('Unable to get cMap at: ' + url);
  16631. }
  16632. var cMap = new CMap(true);
  16633. var lexer = new Lexer(new StringStream(request.responseText));
  16634. parseCMap(cMap, lexer, builtInCMapParams, null);
  16635. return cMap;
  16636. }
  16637. return {
  16638. create: function (encoding, builtInCMapParams, useCMap) {
  16639. if (isName(encoding)) {
  16640. return createBuiltInCMap(encoding.name, builtInCMapParams);
  16641. } else if (isStream(encoding)) {
  16642. var cMap = new CMap();
  16643. var lexer = new Lexer(encoding);
  16644. try {
  16645. parseCMap(cMap, lexer, builtInCMapParams, useCMap);
  16646. } catch (e) {
  16647. warn('Invalid CMap data. ' + e);
  16648. }
  16649. return cMap;
  16650. }
  16651. error('Encoding required.');
  16652. }
  16653. };
  16654. })();
  16655. // Unicode Private Use Area
  16656. var PRIVATE_USE_OFFSET_START = 0xE000;
  16657. var PRIVATE_USE_OFFSET_END = 0xF8FF;
  16658. var SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = false;
  16659. // PDF Glyph Space Units are one Thousandth of a TextSpace Unit
  16660. // except for Type 3 fonts
  16661. var PDF_GLYPH_SPACE_UNITS = 1000;
  16662. // Hinting is currently disabled due to unknown problems on windows
  16663. // in tracemonkey and various other pdfs with type1 fonts.
  16664. var HINTING_ENABLED = false;
  16665. // Accented charactars are not displayed properly on windows, using this flag
  16666. // to control analysis of seac charstrings.
  16667. var SEAC_ANALYSIS_ENABLED = false;
  16668. var FontFlags = {
  16669. FixedPitch: 1,
  16670. Serif: 2,
  16671. Symbolic: 4,
  16672. Script: 8,
  16673. Nonsymbolic: 32,
  16674. Italic: 64,
  16675. AllCap: 65536,
  16676. SmallCap: 131072,
  16677. ForceBold: 262144
  16678. };
  16679. var Encodings = {
  16680. ExpertEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  16681. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  16682. 'space', 'exclamsmall', 'Hungarumlautsmall', '', 'dollaroldstyle',
  16683. 'dollarsuperior', 'ampersandsmall', 'Acutesmall', 'parenleftsuperior',
  16684. 'parenrightsuperior', 'twodotenleader', 'onedotenleader', 'comma',
  16685. 'hyphen', 'period', 'fraction', 'zerooldstyle', 'oneoldstyle',
  16686. 'twooldstyle', 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle',
  16687. 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle', 'colon',
  16688. 'semicolon', 'commasuperior', 'threequartersemdash', 'periodsuperior',
  16689. 'questionsmall', '', 'asuperior', 'bsuperior', 'centsuperior', 'dsuperior',
  16690. 'esuperior', '', '', 'isuperior', '', '', 'lsuperior', 'msuperior',
  16691. 'nsuperior', 'osuperior', '', '', 'rsuperior', 'ssuperior', 'tsuperior',
  16692. '', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior', '',
  16693. 'parenrightinferior', 'Circumflexsmall', 'hyphensuperior', 'Gravesmall',
  16694. 'Asmall', 'Bsmall', 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall',
  16695. 'Hsmall', 'Ismall', 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall',
  16696. 'Osmall', 'Psmall', 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall',
  16697. 'Vsmall', 'Wsmall', 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary',
  16698. 'onefitted', 'rupiah', 'Tildesmall', '', '', '', '', '', '', '', '', '',
  16699. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  16700. '', '', '', '', '', '', 'exclamdownsmall', 'centoldstyle', 'Lslashsmall',
  16701. '', '', 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall', 'Brevesmall',
  16702. 'Caronsmall', '', 'Dotaccentsmall', '', '', 'Macronsmall', '', '',
  16703. 'figuredash', 'hypheninferior', '', '', 'Ogoneksmall', 'Ringsmall',
  16704. 'Cedillasmall', '', '', '', 'onequarter', 'onehalf', 'threequarters',
  16705. 'questiondownsmall', 'oneeighth', 'threeeighths', 'fiveeighths',
  16706. 'seveneighths', 'onethird', 'twothirds', '', '', 'zerosuperior',
  16707. 'onesuperior', 'twosuperior', 'threesuperior', 'foursuperior',
  16708. 'fivesuperior', 'sixsuperior', 'sevensuperior', 'eightsuperior',
  16709. 'ninesuperior', 'zeroinferior', 'oneinferior', 'twoinferior',
  16710. 'threeinferior', 'fourinferior', 'fiveinferior', 'sixinferior',
  16711. 'seveninferior', 'eightinferior', 'nineinferior', 'centinferior',
  16712. 'dollarinferior', 'periodinferior', 'commainferior', 'Agravesmall',
  16713. 'Aacutesmall', 'Acircumflexsmall', 'Atildesmall', 'Adieresissmall',
  16714. 'Aringsmall', 'AEsmall', 'Ccedillasmall', 'Egravesmall', 'Eacutesmall',
  16715. 'Ecircumflexsmall', 'Edieresissmall', 'Igravesmall', 'Iacutesmall',
  16716. 'Icircumflexsmall', 'Idieresissmall', 'Ethsmall', 'Ntildesmall',
  16717. 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall', 'Otildesmall',
  16718. 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall', 'Uacutesmall',
  16719. 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall', 'Thornsmall',
  16720. 'Ydieresissmall'],
  16721. MacExpertEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  16722. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  16723. 'space', 'exclamsmall', 'Hungarumlautsmall', 'centoldstyle',
  16724. 'dollaroldstyle', 'dollarsuperior', 'ampersandsmall', 'Acutesmall',
  16725. 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  16726. 'onedotenleader', 'comma', 'hyphen', 'period', 'fraction', 'zerooldstyle',
  16727. 'oneoldstyle', 'twooldstyle', 'threeoldstyle', 'fouroldstyle',
  16728. 'fiveoldstyle', 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle',
  16729. 'nineoldstyle', 'colon', 'semicolon', '', 'threequartersemdash', '',
  16730. 'questionsmall', '', '', '', '', 'Ethsmall', '', '', 'onequarter',
  16731. 'onehalf', 'threequarters', 'oneeighth', 'threeeighths', 'fiveeighths',
  16732. 'seveneighths', 'onethird', 'twothirds', '', '', '', '', '', '', 'ff',
  16733. 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior', '', 'parenrightinferior',
  16734. 'Circumflexsmall', 'hypheninferior', 'Gravesmall', 'Asmall', 'Bsmall',
  16735. 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall', 'Hsmall', 'Ismall',
  16736. 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall', 'Osmall', 'Psmall',
  16737. 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall', 'Vsmall', 'Wsmall',
  16738. 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary', 'onefitted', 'rupiah',
  16739. 'Tildesmall', '', '', 'asuperior', 'centsuperior', '', '', '', '',
  16740. 'Aacutesmall', 'Agravesmall', 'Acircumflexsmall', 'Adieresissmall',
  16741. 'Atildesmall', 'Aringsmall', 'Ccedillasmall', 'Eacutesmall', 'Egravesmall',
  16742. 'Ecircumflexsmall', 'Edieresissmall', 'Iacutesmall', 'Igravesmall',
  16743. 'Icircumflexsmall', 'Idieresissmall', 'Ntildesmall', 'Oacutesmall',
  16744. 'Ogravesmall', 'Ocircumflexsmall', 'Odieresissmall', 'Otildesmall',
  16745. 'Uacutesmall', 'Ugravesmall', 'Ucircumflexsmall', 'Udieresissmall', '',
  16746. 'eightsuperior', 'fourinferior', 'threeinferior', 'sixinferior',
  16747. 'eightinferior', 'seveninferior', 'Scaronsmall', '', 'centinferior',
  16748. 'twoinferior', '', 'Dieresissmall', '', 'Caronsmall', 'osuperior',
  16749. 'fiveinferior', '', 'commainferior', 'periodinferior', 'Yacutesmall', '',
  16750. 'dollarinferior', '', 'Thornsmall', '', 'nineinferior', 'zeroinferior',
  16751. 'Zcaronsmall', 'AEsmall', 'Oslashsmall', 'questiondownsmall',
  16752. 'oneinferior', 'Lslashsmall', '', '', '', '', '', '', 'Cedillasmall', '',
  16753. '', '', '', '', 'OEsmall', 'figuredash', 'hyphensuperior', '', '', '', '',
  16754. 'exclamdownsmall', '', 'Ydieresissmall', '', 'onesuperior', 'twosuperior',
  16755. 'threesuperior', 'foursuperior', 'fivesuperior', 'sixsuperior',
  16756. 'sevensuperior', 'ninesuperior', 'zerosuperior', '', 'esuperior',
  16757. 'rsuperior', 'tsuperior', '', '', 'isuperior', 'ssuperior', 'dsuperior',
  16758. '', '', '', '', '', 'lsuperior', 'Ogoneksmall', 'Brevesmall',
  16759. 'Macronsmall', 'bsuperior', 'nsuperior', 'msuperior', 'commasuperior',
  16760. 'periodsuperior', 'Dotaccentsmall', 'Ringsmall'],
  16761. MacRomanEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  16762. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  16763. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  16764. 'ampersand', 'quotesingle', 'parenleft', 'parenright', 'asterisk', 'plus',
  16765. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  16766. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  16767. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  16768. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  16769. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  16770. 'asciicircum', 'underscore', 'grave', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
  16771. 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
  16772. 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde', '',
  16773. 'Adieresis', 'Aring', 'Ccedilla', 'Eacute', 'Ntilde', 'Odieresis',
  16774. 'Udieresis', 'aacute', 'agrave', 'acircumflex', 'adieresis', 'atilde',
  16775. 'aring', 'ccedilla', 'eacute', 'egrave', 'ecircumflex', 'edieresis',
  16776. 'iacute', 'igrave', 'icircumflex', 'idieresis', 'ntilde', 'oacute',
  16777. 'ograve', 'ocircumflex', 'odieresis', 'otilde', 'uacute', 'ugrave',
  16778. 'ucircumflex', 'udieresis', 'dagger', 'degree', 'cent', 'sterling',
  16779. 'section', 'bullet', 'paragraph', 'germandbls', 'registered', 'copyright',
  16780. 'trademark', 'acute', 'dieresis', 'notequal', 'AE', 'Oslash', 'infinity',
  16781. 'plusminus', 'lessequal', 'greaterequal', 'yen', 'mu', 'partialdiff',
  16782. 'summation', 'product', 'pi', 'integral', 'ordfeminine', 'ordmasculine',
  16783. 'Omega', 'ae', 'oslash', 'questiondown', 'exclamdown', 'logicalnot',
  16784. 'radical', 'florin', 'approxequal', 'Delta', 'guillemotleft',
  16785. 'guillemotright', 'ellipsis', 'space', 'Agrave', 'Atilde', 'Otilde', 'OE',
  16786. 'oe', 'endash', 'emdash', 'quotedblleft', 'quotedblright', 'quoteleft',
  16787. 'quoteright', 'divide', 'lozenge', 'ydieresis', 'Ydieresis', 'fraction',
  16788. 'currency', 'guilsinglleft', 'guilsinglright', 'fi', 'fl', 'daggerdbl',
  16789. 'periodcentered', 'quotesinglbase', 'quotedblbase', 'perthousand',
  16790. 'Acircumflex', 'Ecircumflex', 'Aacute', 'Edieresis', 'Egrave', 'Iacute',
  16791. 'Icircumflex', 'Idieresis', 'Igrave', 'Oacute', 'Ocircumflex', 'apple',
  16792. 'Ograve', 'Uacute', 'Ucircumflex', 'Ugrave', 'dotlessi', 'circumflex',
  16793. 'tilde', 'macron', 'breve', 'dotaccent', 'ring', 'cedilla', 'hungarumlaut',
  16794. 'ogonek', 'caron'],
  16795. StandardEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  16796. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  16797. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  16798. 'ampersand', 'quoteright', 'parenleft', 'parenright', 'asterisk', 'plus',
  16799. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  16800. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  16801. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  16802. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  16803. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  16804. 'asciicircum', 'underscore', 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f',
  16805. 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u',
  16806. 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde',
  16807. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  16808. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', 'exclamdown',
  16809. 'cent', 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  16810. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  16811. 'guilsinglright', 'fi', 'fl', '', 'endash', 'dagger', 'daggerdbl',
  16812. 'periodcentered', '', 'paragraph', 'bullet', 'quotesinglbase',
  16813. 'quotedblbase', 'quotedblright', 'guillemotright', 'ellipsis',
  16814. 'perthousand', '', 'questiondown', '', 'grave', 'acute', 'circumflex',
  16815. 'tilde', 'macron', 'breve', 'dotaccent', 'dieresis', '', 'ring', 'cedilla',
  16816. '', 'hungarumlaut', 'ogonek', 'caron', 'emdash', '', '', '', '', '', '',
  16817. '', '', '', '', '', '', '', '', '', '', 'AE', '', 'ordfeminine', '', '',
  16818. '', '', 'Lslash', 'Oslash', 'OE', 'ordmasculine', '', '', '', '', '', 'ae',
  16819. '', '', '', 'dotlessi', '', '', 'lslash', 'oslash', 'oe', 'germandbls'],
  16820. WinAnsiEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  16821. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  16822. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  16823. 'ampersand', 'quotesingle', 'parenleft', 'parenright', 'asterisk', 'plus',
  16824. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  16825. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  16826. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  16827. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  16828. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  16829. 'asciicircum', 'underscore', 'grave', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
  16830. 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
  16831. 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde',
  16832. 'bullet', 'Euro', 'bullet', 'quotesinglbase', 'florin', 'quotedblbase',
  16833. 'ellipsis', 'dagger', 'daggerdbl', 'circumflex', 'perthousand', 'Scaron',
  16834. 'guilsinglleft', 'OE', 'bullet', 'Zcaron', 'bullet', 'bullet', 'quoteleft',
  16835. 'quoteright', 'quotedblleft', 'quotedblright', 'bullet', 'endash',
  16836. 'emdash', 'tilde', 'trademark', 'scaron', 'guilsinglright', 'oe', 'bullet',
  16837. 'zcaron', 'Ydieresis', 'space', 'exclamdown', 'cent', 'sterling',
  16838. 'currency', 'yen', 'brokenbar', 'section', 'dieresis', 'copyright',
  16839. 'ordfeminine', 'guillemotleft', 'logicalnot', 'hyphen', 'registered',
  16840. 'macron', 'degree', 'plusminus', 'twosuperior', 'threesuperior', 'acute',
  16841. 'mu', 'paragraph', 'periodcentered', 'cedilla', 'onesuperior',
  16842. 'ordmasculine', 'guillemotright', 'onequarter', 'onehalf', 'threequarters',
  16843. 'questiondown', 'Agrave', 'Aacute', 'Acircumflex', 'Atilde', 'Adieresis',
  16844. 'Aring', 'AE', 'Ccedilla', 'Egrave', 'Eacute', 'Ecircumflex', 'Edieresis',
  16845. 'Igrave', 'Iacute', 'Icircumflex', 'Idieresis', 'Eth', 'Ntilde', 'Ograve',
  16846. 'Oacute', 'Ocircumflex', 'Otilde', 'Odieresis', 'multiply', 'Oslash',
  16847. 'Ugrave', 'Uacute', 'Ucircumflex', 'Udieresis', 'Yacute', 'Thorn',
  16848. 'germandbls', 'agrave', 'aacute', 'acircumflex', 'atilde', 'adieresis',
  16849. 'aring', 'ae', 'ccedilla', 'egrave', 'eacute', 'ecircumflex', 'edieresis',
  16850. 'igrave', 'iacute', 'icircumflex', 'idieresis', 'eth', 'ntilde', 'ograve',
  16851. 'oacute', 'ocircumflex', 'otilde', 'odieresis', 'divide', 'oslash',
  16852. 'ugrave', 'uacute', 'ucircumflex', 'udieresis', 'yacute', 'thorn',
  16853. 'ydieresis'],
  16854. SymbolSetEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  16855. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  16856. 'space', 'exclam', 'universal', 'numbersign', 'existential', 'percent',
  16857. 'ampersand', 'suchthat', 'parenleft', 'parenright', 'asteriskmath', 'plus',
  16858. 'comma', 'minus', 'period', 'slash', 'zero', 'one', 'two', 'three', 'four',
  16859. 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon', 'less',
  16860. 'equal', 'greater', 'question', 'congruent', 'Alpha', 'Beta', 'Chi',
  16861. 'Delta', 'Epsilon', 'Phi', 'Gamma', 'Eta', 'Iota', 'theta1', 'Kappa',
  16862. 'Lambda', 'Mu', 'Nu', 'Omicron', 'Pi', 'Theta', 'Rho', 'Sigma', 'Tau',
  16863. 'Upsilon', 'sigma1', 'Omega', 'Xi', 'Psi', 'Zeta', 'bracketleft',
  16864. 'therefore', 'bracketright', 'perpendicular', 'underscore', 'radicalex',
  16865. 'alpha', 'beta', 'chi', 'delta', 'epsilon', 'phi', 'gamma', 'eta', 'iota',
  16866. 'phi1', 'kappa', 'lambda', 'mu', 'nu', 'omicron', 'pi', 'theta', 'rho',
  16867. 'sigma', 'tau', 'upsilon', 'omega1', 'omega', 'xi', 'psi', 'zeta',
  16868. 'braceleft', 'bar', 'braceright', 'similar', '', '', '', '', '', '', '',
  16869. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  16870. '', '', '', '', '', '', '', 'Euro', 'Upsilon1', 'minute', 'lessequal',
  16871. 'fraction', 'infinity', 'florin', 'club', 'diamond', 'heart', 'spade',
  16872. 'arrowboth', 'arrowleft', 'arrowup', 'arrowright', 'arrowdown', 'degree',
  16873. 'plusminus', 'second', 'greaterequal', 'multiply', 'proportional',
  16874. 'partialdiff', 'bullet', 'divide', 'notequal', 'equivalence',
  16875. 'approxequal', 'ellipsis', 'arrowvertex', 'arrowhorizex', 'carriagereturn',
  16876. 'aleph', 'Ifraktur', 'Rfraktur', 'weierstrass', 'circlemultiply',
  16877. 'circleplus', 'emptyset', 'intersection', 'union', 'propersuperset',
  16878. 'reflexsuperset', 'notsubset', 'propersubset', 'reflexsubset', 'element',
  16879. 'notelement', 'angle', 'gradient', 'registerserif', 'copyrightserif',
  16880. 'trademarkserif', 'product', 'radical', 'dotmath', 'logicalnot',
  16881. 'logicaland', 'logicalor', 'arrowdblboth', 'arrowdblleft', 'arrowdblup',
  16882. 'arrowdblright', 'arrowdbldown', 'lozenge', 'angleleft', 'registersans',
  16883. 'copyrightsans', 'trademarksans', 'summation', 'parenlefttp',
  16884. 'parenleftex', 'parenleftbt', 'bracketlefttp', 'bracketleftex',
  16885. 'bracketleftbt', 'bracelefttp', 'braceleftmid', 'braceleftbt', 'braceex',
  16886. '', 'angleright', 'integral', 'integraltp', 'integralex', 'integralbt',
  16887. 'parenrighttp', 'parenrightex', 'parenrightbt', 'bracketrighttp',
  16888. 'bracketrightex', 'bracketrightbt', 'bracerighttp', 'bracerightmid',
  16889. 'bracerightbt'],
  16890. zapfDingbatsEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  16891. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  16892. 'space', 'a1', 'a2', 'a202', 'a3', 'a4', 'a5', 'a119', 'a118', 'a117',
  16893. 'a11', 'a12', 'a13', 'a14', 'a15', 'a16', 'a105', 'a17', 'a18', 'a19',
  16894. 'a20', 'a21', 'a22', 'a23', 'a24', 'a25', 'a26', 'a27', 'a28', 'a6', 'a7',
  16895. 'a8', 'a9', 'a10', 'a29', 'a30', 'a31', 'a32', 'a33', 'a34', 'a35', 'a36',
  16896. 'a37', 'a38', 'a39', 'a40', 'a41', 'a42', 'a43', 'a44', 'a45', 'a46',
  16897. 'a47', 'a48', 'a49', 'a50', 'a51', 'a52', 'a53', 'a54', 'a55', 'a56',
  16898. 'a57', 'a58', 'a59', 'a60', 'a61', 'a62', 'a63', 'a64', 'a65', 'a66',
  16899. 'a67', 'a68', 'a69', 'a70', 'a71', 'a72', 'a73', 'a74', 'a203', 'a75',
  16900. 'a204', 'a76', 'a77', 'a78', 'a79', 'a81', 'a82', 'a83', 'a84', 'a97',
  16901. 'a98', 'a99', 'a100', '', '', '', '', '', '', '', '', '', '', '', '', '',
  16902. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  16903. '', '', 'a101', 'a102', 'a103', 'a104', 'a106', 'a107', 'a108', 'a112',
  16904. 'a111', 'a110', 'a109', 'a120', 'a121', 'a122', 'a123', 'a124', 'a125',
  16905. 'a126', 'a127', 'a128', 'a129', 'a130', 'a131', 'a132', 'a133', 'a134',
  16906. 'a135', 'a136', 'a137', 'a138', 'a139', 'a140', 'a141', 'a142', 'a143',
  16907. 'a144', 'a145', 'a146', 'a147', 'a148', 'a149', 'a150', 'a151', 'a152',
  16908. 'a153', 'a154', 'a155', 'a156', 'a157', 'a158', 'a159', 'a160', 'a161',
  16909. 'a163', 'a164', 'a196', 'a165', 'a192', 'a166', 'a167', 'a168', 'a169',
  16910. 'a170', 'a171', 'a172', 'a173', 'a162', 'a174', 'a175', 'a176', 'a177',
  16911. 'a178', 'a179', 'a193', 'a180', 'a199', 'a181', 'a200', 'a182', '', 'a201',
  16912. 'a183', 'a184', 'a197', 'a185', 'a194', 'a198', 'a186', 'a195', 'a187',
  16913. 'a188', 'a189', 'a190', 'a191']
  16914. };
  16915. /**
  16916. * Hold a map of decoded fonts and of the standard fourteen Type1
  16917. * fonts and their acronyms.
  16918. */
  16919. var stdFontMap = {
  16920. 'ArialNarrow': 'Helvetica',
  16921. 'ArialNarrow-Bold': 'Helvetica-Bold',
  16922. 'ArialNarrow-BoldItalic': 'Helvetica-BoldOblique',
  16923. 'ArialNarrow-Italic': 'Helvetica-Oblique',
  16924. 'ArialBlack': 'Helvetica',
  16925. 'ArialBlack-Bold': 'Helvetica-Bold',
  16926. 'ArialBlack-BoldItalic': 'Helvetica-BoldOblique',
  16927. 'ArialBlack-Italic': 'Helvetica-Oblique',
  16928. 'Arial': 'Helvetica',
  16929. 'Arial-Bold': 'Helvetica-Bold',
  16930. 'Arial-BoldItalic': 'Helvetica-BoldOblique',
  16931. 'Arial-Italic': 'Helvetica-Oblique',
  16932. 'Arial-BoldItalicMT': 'Helvetica-BoldOblique',
  16933. 'Arial-BoldMT': 'Helvetica-Bold',
  16934. 'Arial-ItalicMT': 'Helvetica-Oblique',
  16935. 'ArialMT': 'Helvetica',
  16936. 'Courier-Bold': 'Courier-Bold',
  16937. 'Courier-BoldItalic': 'Courier-BoldOblique',
  16938. 'Courier-Italic': 'Courier-Oblique',
  16939. 'CourierNew': 'Courier',
  16940. 'CourierNew-Bold': 'Courier-Bold',
  16941. 'CourierNew-BoldItalic': 'Courier-BoldOblique',
  16942. 'CourierNew-Italic': 'Courier-Oblique',
  16943. 'CourierNewPS-BoldItalicMT': 'Courier-BoldOblique',
  16944. 'CourierNewPS-BoldMT': 'Courier-Bold',
  16945. 'CourierNewPS-ItalicMT': 'Courier-Oblique',
  16946. 'CourierNewPSMT': 'Courier',
  16947. 'Helvetica-Bold': 'Helvetica-Bold',
  16948. 'Helvetica-BoldItalic': 'Helvetica-BoldOblique',
  16949. 'Helvetica-Italic': 'Helvetica-Oblique',
  16950. 'Symbol-Bold': 'Symbol',
  16951. 'Symbol-BoldItalic': 'Symbol',
  16952. 'Symbol-Italic': 'Symbol',
  16953. 'TimesNewRoman': 'Times-Roman',
  16954. 'TimesNewRoman-Bold': 'Times-Bold',
  16955. 'TimesNewRoman-BoldItalic': 'Times-BoldItalic',
  16956. 'TimesNewRoman-Italic': 'Times-Italic',
  16957. 'TimesNewRomanPS': 'Times-Roman',
  16958. 'TimesNewRomanPS-Bold': 'Times-Bold',
  16959. 'TimesNewRomanPS-BoldItalic': 'Times-BoldItalic',
  16960. 'TimesNewRomanPS-BoldItalicMT': 'Times-BoldItalic',
  16961. 'TimesNewRomanPS-BoldMT': 'Times-Bold',
  16962. 'TimesNewRomanPS-Italic': 'Times-Italic',
  16963. 'TimesNewRomanPS-ItalicMT': 'Times-Italic',
  16964. 'TimesNewRomanPSMT': 'Times-Roman',
  16965. 'TimesNewRomanPSMT-Bold': 'Times-Bold',
  16966. 'TimesNewRomanPSMT-BoldItalic': 'Times-BoldItalic',
  16967. 'TimesNewRomanPSMT-Italic': 'Times-Italic'
  16968. };
  16969. /**
  16970. * Holds the map of the non-standard fonts that might be included as a standard
  16971. * fonts without glyph data.
  16972. */
  16973. var nonStdFontMap = {
  16974. 'ComicSansMS': 'Comic Sans MS',
  16975. 'ComicSansMS-Bold': 'Comic Sans MS-Bold',
  16976. 'ComicSansMS-BoldItalic': 'Comic Sans MS-BoldItalic',
  16977. 'ComicSansMS-Italic': 'Comic Sans MS-Italic',
  16978. 'LucidaConsole': 'Courier',
  16979. 'LucidaConsole-Bold': 'Courier-Bold',
  16980. 'LucidaConsole-BoldItalic': 'Courier-BoldOblique',
  16981. 'LucidaConsole-Italic': 'Courier-Oblique',
  16982. 'MS-Gothic': 'MS Gothic',
  16983. 'MS-Gothic-Bold': 'MS Gothic-Bold',
  16984. 'MS-Gothic-BoldItalic': 'MS Gothic-BoldItalic',
  16985. 'MS-Gothic-Italic': 'MS Gothic-Italic',
  16986. 'MS-Mincho': 'MS Mincho',
  16987. 'MS-Mincho-Bold': 'MS Mincho-Bold',
  16988. 'MS-Mincho-BoldItalic': 'MS Mincho-BoldItalic',
  16989. 'MS-Mincho-Italic': 'MS Mincho-Italic',
  16990. 'MS-PGothic': 'MS PGothic',
  16991. 'MS-PGothic-Bold': 'MS PGothic-Bold',
  16992. 'MS-PGothic-BoldItalic': 'MS PGothic-BoldItalic',
  16993. 'MS-PGothic-Italic': 'MS PGothic-Italic',
  16994. 'MS-PMincho': 'MS PMincho',
  16995. 'MS-PMincho-Bold': 'MS PMincho-Bold',
  16996. 'MS-PMincho-BoldItalic': 'MS PMincho-BoldItalic',
  16997. 'MS-PMincho-Italic': 'MS PMincho-Italic'
  16998. };
  16999. var serifFonts = {
  17000. 'Adobe Jenson': true, 'Adobe Text': true, 'Albertus': true,
  17001. 'Aldus': true, 'Alexandria': true, 'Algerian': true,
  17002. 'American Typewriter': true, 'Antiqua': true, 'Apex': true,
  17003. 'Arno': true, 'Aster': true, 'Aurora': true,
  17004. 'Baskerville': true, 'Bell': true, 'Bembo': true,
  17005. 'Bembo Schoolbook': true, 'Benguiat': true, 'Berkeley Old Style': true,
  17006. 'Bernhard Modern': true, 'Berthold City': true, 'Bodoni': true,
  17007. 'Bauer Bodoni': true, 'Book Antiqua': true, 'Bookman': true,
  17008. 'Bordeaux Roman': true, 'Californian FB': true, 'Calisto': true,
  17009. 'Calvert': true, 'Capitals': true, 'Cambria': true,
  17010. 'Cartier': true, 'Caslon': true, 'Catull': true,
  17011. 'Centaur': true, 'Century Old Style': true, 'Century Schoolbook': true,
  17012. 'Chaparral': true, 'Charis SIL': true, 'Cheltenham': true,
  17013. 'Cholla Slab': true, 'Clarendon': true, 'Clearface': true,
  17014. 'Cochin': true, 'Colonna': true, 'Computer Modern': true,
  17015. 'Concrete Roman': true, 'Constantia': true, 'Cooper Black': true,
  17016. 'Corona': true, 'Ecotype': true, 'Egyptienne': true,
  17017. 'Elephant': true, 'Excelsior': true, 'Fairfield': true,
  17018. 'FF Scala': true, 'Folkard': true, 'Footlight': true,
  17019. 'FreeSerif': true, 'Friz Quadrata': true, 'Garamond': true,
  17020. 'Gentium': true, 'Georgia': true, 'Gloucester': true,
  17021. 'Goudy Old Style': true, 'Goudy Schoolbook': true, 'Goudy Pro Font': true,
  17022. 'Granjon': true, 'Guardian Egyptian': true, 'Heather': true,
  17023. 'Hercules': true, 'High Tower Text': true, 'Hiroshige': true,
  17024. 'Hoefler Text': true, 'Humana Serif': true, 'Imprint': true,
  17025. 'Ionic No. 5': true, 'Janson': true, 'Joanna': true,
  17026. 'Korinna': true, 'Lexicon': true, 'Liberation Serif': true,
  17027. 'Linux Libertine': true, 'Literaturnaya': true, 'Lucida': true,
  17028. 'Lucida Bright': true, 'Melior': true, 'Memphis': true,
  17029. 'Miller': true, 'Minion': true, 'Modern': true,
  17030. 'Mona Lisa': true, 'Mrs Eaves': true, 'MS Serif': true,
  17031. 'Museo Slab': true, 'New York': true, 'Nimbus Roman': true,
  17032. 'NPS Rawlinson Roadway': true, 'Palatino': true, 'Perpetua': true,
  17033. 'Plantin': true, 'Plantin Schoolbook': true, 'Playbill': true,
  17034. 'Poor Richard': true, 'Rawlinson Roadway': true, 'Renault': true,
  17035. 'Requiem': true, 'Rockwell': true, 'Roman': true,
  17036. 'Rotis Serif': true, 'Sabon': true, 'Scala': true,
  17037. 'Seagull': true, 'Sistina': true, 'Souvenir': true,
  17038. 'STIX': true, 'Stone Informal': true, 'Stone Serif': true,
  17039. 'Sylfaen': true, 'Times': true, 'Trajan': true,
  17040. 'Trinité': true, 'Trump Mediaeval': true, 'Utopia': true,
  17041. 'Vale Type': true, 'Bitstream Vera': true, 'Vera Serif': true,
  17042. 'Versailles': true, 'Wanted': true, 'Weiss': true,
  17043. 'Wide Latin': true, 'Windsor': true, 'XITS': true
  17044. };
  17045. var symbolsFonts = {
  17046. 'Dingbats': true, 'Symbol': true, 'ZapfDingbats': true
  17047. };
  17048. // Glyph map for well-known standard fonts. Sometimes Ghostscript uses CID fonts
  17049. // but does not embed the CID to GID mapping. The mapping is incomplete for all
  17050. // glyphs, but common for some set of the standard fonts.
  17051. var GlyphMapForStandardFonts = {
  17052. '2': 10, '3': 32, '4': 33, '5': 34, '6': 35, '7': 36, '8': 37, '9': 38,
  17053. '10': 39, '11': 40, '12': 41, '13': 42, '14': 43, '15': 44, '16': 45,
  17054. '17': 46, '18': 47, '19': 48, '20': 49, '21': 50, '22': 51, '23': 52,
  17055. '24': 53, '25': 54, '26': 55, '27': 56, '28': 57, '29': 58, '30': 894,
  17056. '31': 60, '32': 61, '33': 62, '34': 63, '35': 64, '36': 65, '37': 66,
  17057. '38': 67, '39': 68, '40': 69, '41': 70, '42': 71, '43': 72, '44': 73,
  17058. '45': 74, '46': 75, '47': 76, '48': 77, '49': 78, '50': 79, '51': 80,
  17059. '52': 81, '53': 82, '54': 83, '55': 84, '56': 85, '57': 86, '58': 87,
  17060. '59': 88, '60': 89, '61': 90, '62': 91, '63': 92, '64': 93, '65': 94,
  17061. '66': 95, '67': 96, '68': 97, '69': 98, '70': 99, '71': 100, '72': 101,
  17062. '73': 102, '74': 103, '75': 104, '76': 105, '77': 106, '78': 107, '79': 108,
  17063. '80': 109, '81': 110, '82': 111, '83': 112, '84': 113, '85': 114, '86': 115,
  17064. '87': 116, '88': 117, '89': 118, '90': 119, '91': 120, '92': 121, '93': 122,
  17065. '94': 123, '95': 124, '96': 125, '97': 126, '98': 196, '99': 197, '100': 199,
  17066. '101': 201, '102': 209, '103': 214, '104': 220, '105': 225, '106': 224,
  17067. '107': 226, '108': 228, '109': 227, '110': 229, '111': 231, '112': 233,
  17068. '113': 232, '114': 234, '115': 235, '116': 237, '117': 236, '118': 238,
  17069. '119': 239, '120': 241, '121': 243, '122': 242, '123': 244, '124': 246,
  17070. '125': 245, '126': 250, '127': 249, '128': 251, '129': 252, '130': 8224,
  17071. '131': 176, '132': 162, '133': 163, '134': 167, '135': 8226, '136': 182,
  17072. '137': 223, '138': 174, '139': 169, '140': 8482, '141': 180, '142': 168,
  17073. '143': 8800, '144': 198, '145': 216, '146': 8734, '147': 177, '148': 8804,
  17074. '149': 8805, '150': 165, '151': 181, '152': 8706, '153': 8721, '154': 8719,
  17075. '156': 8747, '157': 170, '158': 186, '159': 8486, '160': 230, '161': 248,
  17076. '162': 191, '163': 161, '164': 172, '165': 8730, '166': 402, '167': 8776,
  17077. '168': 8710, '169': 171, '170': 187, '171': 8230, '210': 218, '223': 711,
  17078. '227': 353, '229': 382, '234': 253, '253': 268, '254': 269, '258': 258,
  17079. '268': 283, '269': 313, '278': 328, '284': 345, '292': 367, '305': 963,
  17080. '306': 964, '307': 966, '308': 8215, '309': 8252, '310': 8319, '311': 8359,
  17081. '312': 8592, '313': 8593, '337': 9552, '493': 1039, '494': 1040, '705': 1524,
  17082. '706': 8362, '710': 64288, '711': 64298, '759': 1617, '761': 1776,
  17083. '763': 1778, '775': 1652, '777': 1764, '778': 1780, '779': 1781, '780': 1782,
  17084. '782': 771, '783': 64726, '786': 8363, '788': 8532, '790': 768, '791': 769,
  17085. '792': 768, '795': 803, '797': 64336, '798': 64337, '799': 64342,
  17086. '800': 64343, '801': 64344, '802': 64345, '803': 64362, '804': 64363,
  17087. '805': 64364, '2424': 7821, '2425': 7822, '2426': 7823, '2427': 7824,
  17088. '2428': 7825, '2429': 7826, '2430': 7827, '2433': 7682, '2678': 8045,
  17089. '2679': 8046, '2830': 1552, '2838': 686, '2840': 751, '2842': 753,
  17090. '2843': 754, '2844': 755, '2846': 757, '2856': 767, '2857': 848, '2858': 849,
  17091. '2862': 853, '2863': 854, '2864': 855, '2865': 861, '2866': 862, '2906': 7460,
  17092. '2908': 7462, '2909': 7463, '2910': 7464, '2912': 7466, '2913': 7467,
  17093. '2914': 7468, '2916': 7470, '2917': 7471, '2918': 7472, '2920': 7474,
  17094. '2921': 7475, '2922': 7476, '2924': 7478, '2925': 7479, '2926': 7480,
  17095. '2928': 7482, '2929': 7483, '2930': 7484, '2932': 7486, '2933': 7487,
  17096. '2934': 7488, '2936': 7490, '2937': 7491, '2938': 7492, '2940': 7494,
  17097. '2941': 7495, '2942': 7496, '2944': 7498, '2946': 7500, '2948': 7502,
  17098. '2950': 7504, '2951': 7505, '2952': 7506, '2954': 7508, '2955': 7509,
  17099. '2956': 7510, '2958': 7512, '2959': 7513, '2960': 7514, '2962': 7516,
  17100. '2963': 7517, '2964': 7518, '2966': 7520, '2967': 7521, '2968': 7522,
  17101. '2970': 7524, '2971': 7525, '2972': 7526, '2974': 7528, '2975': 7529,
  17102. '2976': 7530, '2978': 1537, '2979': 1538, '2980': 1539, '2982': 1549,
  17103. '2983': 1551, '2984': 1552, '2986': 1554, '2987': 1555, '2988': 1556,
  17104. '2990': 1623, '2991': 1624, '2995': 1775, '2999': 1791, '3002': 64290,
  17105. '3003': 64291, '3004': 64292, '3006': 64294, '3007': 64295, '3008': 64296,
  17106. '3011': 1900, '3014': 8223, '3015': 8244, '3017': 7532, '3018': 7533,
  17107. '3019': 7534, '3075': 7590, '3076': 7591, '3079': 7594, '3080': 7595,
  17108. '3083': 7598, '3084': 7599, '3087': 7602, '3088': 7603, '3091': 7606,
  17109. '3092': 7607, '3095': 7610, '3096': 7611, '3099': 7614, '3100': 7615,
  17110. '3103': 7618, '3104': 7619, '3107': 8337, '3108': 8338, '3116': 1884,
  17111. '3119': 1885, '3120': 1885, '3123': 1886, '3124': 1886, '3127': 1887,
  17112. '3128': 1887, '3131': 1888, '3132': 1888, '3135': 1889, '3136': 1889,
  17113. '3139': 1890, '3140': 1890, '3143': 1891, '3144': 1891, '3147': 1892,
  17114. '3148': 1892, '3153': 580, '3154': 581, '3157': 584, '3158': 585, '3161': 588,
  17115. '3162': 589, '3165': 891, '3166': 892, '3169': 1274, '3170': 1275,
  17116. '3173': 1278, '3174': 1279, '3181': 7622, '3182': 7623, '3282': 11799,
  17117. '3316': 578, '3379': 42785, '3393': 1159, '3416': 8377
  17118. };
  17119. // Some characters, e.g. copyrightserif, mapped to the private use area and
  17120. // might not be displayed using standard fonts. Mapping/hacking well-known chars
  17121. // to the similar equivalents in the normal characters range.
  17122. function mapSpecialUnicodeValues(code) {
  17123. if (code >= 0xFFF0 && code <= 0xFFFF) { // Specials unicode block.
  17124. return 0;
  17125. }
  17126. switch (code) {
  17127. case 0xF8E9: // copyrightsans
  17128. case 0xF6D9: // copyrightserif
  17129. return 0x00A9; // copyright
  17130. case 0xF8E8: // registersans
  17131. case 0xF6DA: // registerserif
  17132. return 0x00AE; // registered
  17133. case 0xF8EA: // trademarksans
  17134. case 0xF6DB: // trademarkserif
  17135. return 0x2122; // trademark
  17136. default:
  17137. return code;
  17138. }
  17139. }
  17140. var UnicodeRanges = [
  17141. { 'begin': 0x0000, 'end': 0x007F }, // Basic Latin
  17142. { 'begin': 0x0080, 'end': 0x00FF }, // Latin-1 Supplement
  17143. { 'begin': 0x0100, 'end': 0x017F }, // Latin Extended-A
  17144. { 'begin': 0x0180, 'end': 0x024F }, // Latin Extended-B
  17145. { 'begin': 0x0250, 'end': 0x02AF }, // IPA Extensions
  17146. { 'begin': 0x02B0, 'end': 0x02FF }, // Spacing Modifier Letters
  17147. { 'begin': 0x0300, 'end': 0x036F }, // Combining Diacritical Marks
  17148. { 'begin': 0x0370, 'end': 0x03FF }, // Greek and Coptic
  17149. { 'begin': 0x2C80, 'end': 0x2CFF }, // Coptic
  17150. { 'begin': 0x0400, 'end': 0x04FF }, // Cyrillic
  17151. { 'begin': 0x0530, 'end': 0x058F }, // Armenian
  17152. { 'begin': 0x0590, 'end': 0x05FF }, // Hebrew
  17153. { 'begin': 0xA500, 'end': 0xA63F }, // Vai
  17154. { 'begin': 0x0600, 'end': 0x06FF }, // Arabic
  17155. { 'begin': 0x07C0, 'end': 0x07FF }, // NKo
  17156. { 'begin': 0x0900, 'end': 0x097F }, // Devanagari
  17157. { 'begin': 0x0980, 'end': 0x09FF }, // Bengali
  17158. { 'begin': 0x0A00, 'end': 0x0A7F }, // Gurmukhi
  17159. { 'begin': 0x0A80, 'end': 0x0AFF }, // Gujarati
  17160. { 'begin': 0x0B00, 'end': 0x0B7F }, // Oriya
  17161. { 'begin': 0x0B80, 'end': 0x0BFF }, // Tamil
  17162. { 'begin': 0x0C00, 'end': 0x0C7F }, // Telugu
  17163. { 'begin': 0x0C80, 'end': 0x0CFF }, // Kannada
  17164. { 'begin': 0x0D00, 'end': 0x0D7F }, // Malayalam
  17165. { 'begin': 0x0E00, 'end': 0x0E7F }, // Thai
  17166. { 'begin': 0x0E80, 'end': 0x0EFF }, // Lao
  17167. { 'begin': 0x10A0, 'end': 0x10FF }, // Georgian
  17168. { 'begin': 0x1B00, 'end': 0x1B7F }, // Balinese
  17169. { 'begin': 0x1100, 'end': 0x11FF }, // Hangul Jamo
  17170. { 'begin': 0x1E00, 'end': 0x1EFF }, // Latin Extended Additional
  17171. { 'begin': 0x1F00, 'end': 0x1FFF }, // Greek Extended
  17172. { 'begin': 0x2000, 'end': 0x206F }, // General Punctuation
  17173. { 'begin': 0x2070, 'end': 0x209F }, // Superscripts And Subscripts
  17174. { 'begin': 0x20A0, 'end': 0x20CF }, // Currency Symbol
  17175. { 'begin': 0x20D0, 'end': 0x20FF }, // Combining Diacritical Marks For Symbols
  17176. { 'begin': 0x2100, 'end': 0x214F }, // Letterlike Symbols
  17177. { 'begin': 0x2150, 'end': 0x218F }, // Number Forms
  17178. { 'begin': 0x2190, 'end': 0x21FF }, // Arrows
  17179. { 'begin': 0x2200, 'end': 0x22FF }, // Mathematical Operators
  17180. { 'begin': 0x2300, 'end': 0x23FF }, // Miscellaneous Technical
  17181. { 'begin': 0x2400, 'end': 0x243F }, // Control Pictures
  17182. { 'begin': 0x2440, 'end': 0x245F }, // Optical Character Recognition
  17183. { 'begin': 0x2460, 'end': 0x24FF }, // Enclosed Alphanumerics
  17184. { 'begin': 0x2500, 'end': 0x257F }, // Box Drawing
  17185. { 'begin': 0x2580, 'end': 0x259F }, // Block Elements
  17186. { 'begin': 0x25A0, 'end': 0x25FF }, // Geometric Shapes
  17187. { 'begin': 0x2600, 'end': 0x26FF }, // Miscellaneous Symbols
  17188. { 'begin': 0x2700, 'end': 0x27BF }, // Dingbats
  17189. { 'begin': 0x3000, 'end': 0x303F }, // CJK Symbols And Punctuation
  17190. { 'begin': 0x3040, 'end': 0x309F }, // Hiragana
  17191. { 'begin': 0x30A0, 'end': 0x30FF }, // Katakana
  17192. { 'begin': 0x3100, 'end': 0x312F }, // Bopomofo
  17193. { 'begin': 0x3130, 'end': 0x318F }, // Hangul Compatibility Jamo
  17194. { 'begin': 0xA840, 'end': 0xA87F }, // Phags-pa
  17195. { 'begin': 0x3200, 'end': 0x32FF }, // Enclosed CJK Letters And Months
  17196. { 'begin': 0x3300, 'end': 0x33FF }, // CJK Compatibility
  17197. { 'begin': 0xAC00, 'end': 0xD7AF }, // Hangul Syllables
  17198. { 'begin': 0xD800, 'end': 0xDFFF }, // Non-Plane 0 *
  17199. { 'begin': 0x10900, 'end': 0x1091F }, // Phoenicia
  17200. { 'begin': 0x4E00, 'end': 0x9FFF }, // CJK Unified Ideographs
  17201. { 'begin': 0xE000, 'end': 0xF8FF }, // Private Use Area (plane 0)
  17202. { 'begin': 0x31C0, 'end': 0x31EF }, // CJK Strokes
  17203. { 'begin': 0xFB00, 'end': 0xFB4F }, // Alphabetic Presentation Forms
  17204. { 'begin': 0xFB50, 'end': 0xFDFF }, // Arabic Presentation Forms-A
  17205. { 'begin': 0xFE20, 'end': 0xFE2F }, // Combining Half Marks
  17206. { 'begin': 0xFE10, 'end': 0xFE1F }, // Vertical Forms
  17207. { 'begin': 0xFE50, 'end': 0xFE6F }, // Small Form Variants
  17208. { 'begin': 0xFE70, 'end': 0xFEFF }, // Arabic Presentation Forms-B
  17209. { 'begin': 0xFF00, 'end': 0xFFEF }, // Halfwidth And Fullwidth Forms
  17210. { 'begin': 0xFFF0, 'end': 0xFFFF }, // Specials
  17211. { 'begin': 0x0F00, 'end': 0x0FFF }, // Tibetan
  17212. { 'begin': 0x0700, 'end': 0x074F }, // Syriac
  17213. { 'begin': 0x0780, 'end': 0x07BF }, // Thaana
  17214. { 'begin': 0x0D80, 'end': 0x0DFF }, // Sinhala
  17215. { 'begin': 0x1000, 'end': 0x109F }, // Myanmar
  17216. { 'begin': 0x1200, 'end': 0x137F }, // Ethiopic
  17217. { 'begin': 0x13A0, 'end': 0x13FF }, // Cherokee
  17218. { 'begin': 0x1400, 'end': 0x167F }, // Unified Canadian Aboriginal Syllabics
  17219. { 'begin': 0x1680, 'end': 0x169F }, // Ogham
  17220. { 'begin': 0x16A0, 'end': 0x16FF }, // Runic
  17221. { 'begin': 0x1780, 'end': 0x17FF }, // Khmer
  17222. { 'begin': 0x1800, 'end': 0x18AF }, // Mongolian
  17223. { 'begin': 0x2800, 'end': 0x28FF }, // Braille Patterns
  17224. { 'begin': 0xA000, 'end': 0xA48F }, // Yi Syllables
  17225. { 'begin': 0x1700, 'end': 0x171F }, // Tagalog
  17226. { 'begin': 0x10300, 'end': 0x1032F }, // Old Italic
  17227. { 'begin': 0x10330, 'end': 0x1034F }, // Gothic
  17228. { 'begin': 0x10400, 'end': 0x1044F }, // Deseret
  17229. { 'begin': 0x1D000, 'end': 0x1D0FF }, // Byzantine Musical Symbols
  17230. { 'begin': 0x1D400, 'end': 0x1D7FF }, // Mathematical Alphanumeric Symbols
  17231. { 'begin': 0xFF000, 'end': 0xFFFFD }, // Private Use (plane 15)
  17232. { 'begin': 0xFE00, 'end': 0xFE0F }, // Variation Selectors
  17233. { 'begin': 0xE0000, 'end': 0xE007F }, // Tags
  17234. { 'begin': 0x1900, 'end': 0x194F }, // Limbu
  17235. { 'begin': 0x1950, 'end': 0x197F }, // Tai Le
  17236. { 'begin': 0x1980, 'end': 0x19DF }, // New Tai Lue
  17237. { 'begin': 0x1A00, 'end': 0x1A1F }, // Buginese
  17238. { 'begin': 0x2C00, 'end': 0x2C5F }, // Glagolitic
  17239. { 'begin': 0x2D30, 'end': 0x2D7F }, // Tifinagh
  17240. { 'begin': 0x4DC0, 'end': 0x4DFF }, // Yijing Hexagram Symbols
  17241. { 'begin': 0xA800, 'end': 0xA82F }, // Syloti Nagri
  17242. { 'begin': 0x10000, 'end': 0x1007F }, // Linear B Syllabary
  17243. { 'begin': 0x10140, 'end': 0x1018F }, // Ancient Greek Numbers
  17244. { 'begin': 0x10380, 'end': 0x1039F }, // Ugaritic
  17245. { 'begin': 0x103A0, 'end': 0x103DF }, // Old Persian
  17246. { 'begin': 0x10450, 'end': 0x1047F }, // Shavian
  17247. { 'begin': 0x10480, 'end': 0x104AF }, // Osmanya
  17248. { 'begin': 0x10800, 'end': 0x1083F }, // Cypriot Syllabary
  17249. { 'begin': 0x10A00, 'end': 0x10A5F }, // Kharoshthi
  17250. { 'begin': 0x1D300, 'end': 0x1D35F }, // Tai Xuan Jing Symbols
  17251. { 'begin': 0x12000, 'end': 0x123FF }, // Cuneiform
  17252. { 'begin': 0x1D360, 'end': 0x1D37F }, // Counting Rod Numerals
  17253. { 'begin': 0x1B80, 'end': 0x1BBF }, // Sundanese
  17254. { 'begin': 0x1C00, 'end': 0x1C4F }, // Lepcha
  17255. { 'begin': 0x1C50, 'end': 0x1C7F }, // Ol Chiki
  17256. { 'begin': 0xA880, 'end': 0xA8DF }, // Saurashtra
  17257. { 'begin': 0xA900, 'end': 0xA92F }, // Kayah Li
  17258. { 'begin': 0xA930, 'end': 0xA95F }, // Rejang
  17259. { 'begin': 0xAA00, 'end': 0xAA5F }, // Cham
  17260. { 'begin': 0x10190, 'end': 0x101CF }, // Ancient Symbols
  17261. { 'begin': 0x101D0, 'end': 0x101FF }, // Phaistos Disc
  17262. { 'begin': 0x102A0, 'end': 0x102DF }, // Carian
  17263. { 'begin': 0x1F030, 'end': 0x1F09F } // Domino Tiles
  17264. ];
  17265. var MacStandardGlyphOrdering = [
  17266. '.notdef', '.null', 'nonmarkingreturn', 'space', 'exclam', 'quotedbl',
  17267. 'numbersign', 'dollar', 'percent', 'ampersand', 'quotesingle', 'parenleft',
  17268. 'parenright', 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash',
  17269. 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',
  17270. 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater', 'question', 'at',
  17271. 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
  17272. 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'bracketleft',
  17273. 'backslash', 'bracketright', 'asciicircum', 'underscore', 'grave', 'a', 'b',
  17274. 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q',
  17275. 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright',
  17276. 'asciitilde', 'Adieresis', 'Aring', 'Ccedilla', 'Eacute', 'Ntilde',
  17277. 'Odieresis', 'Udieresis', 'aacute', 'agrave', 'acircumflex', 'adieresis',
  17278. 'atilde', 'aring', 'ccedilla', 'eacute', 'egrave', 'ecircumflex', 'edieresis',
  17279. 'iacute', 'igrave', 'icircumflex', 'idieresis', 'ntilde', 'oacute', 'ograve',
  17280. 'ocircumflex', 'odieresis', 'otilde', 'uacute', 'ugrave', 'ucircumflex',
  17281. 'udieresis', 'dagger', 'degree', 'cent', 'sterling', 'section', 'bullet',
  17282. 'paragraph', 'germandbls', 'registered', 'copyright', 'trademark', 'acute',
  17283. 'dieresis', 'notequal', 'AE', 'Oslash', 'infinity', 'plusminus', 'lessequal',
  17284. 'greaterequal', 'yen', 'mu', 'partialdiff', 'summation', 'product', 'pi',
  17285. 'integral', 'ordfeminine', 'ordmasculine', 'Omega', 'ae', 'oslash',
  17286. 'questiondown', 'exclamdown', 'logicalnot', 'radical', 'florin',
  17287. 'approxequal', 'Delta', 'guillemotleft', 'guillemotright', 'ellipsis',
  17288. 'nonbreakingspace', 'Agrave', 'Atilde', 'Otilde', 'OE', 'oe', 'endash',
  17289. 'emdash', 'quotedblleft', 'quotedblright', 'quoteleft', 'quoteright',
  17290. 'divide', 'lozenge', 'ydieresis', 'Ydieresis', 'fraction', 'currency',
  17291. 'guilsinglleft', 'guilsinglright', 'fi', 'fl', 'daggerdbl', 'periodcentered',
  17292. 'quotesinglbase', 'quotedblbase', 'perthousand', 'Acircumflex',
  17293. 'Ecircumflex', 'Aacute', 'Edieresis', 'Egrave', 'Iacute', 'Icircumflex',
  17294. 'Idieresis', 'Igrave', 'Oacute', 'Ocircumflex', 'apple', 'Ograve', 'Uacute',
  17295. 'Ucircumflex', 'Ugrave', 'dotlessi', 'circumflex', 'tilde', 'macron',
  17296. 'breve', 'dotaccent', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron',
  17297. 'Lslash', 'lslash', 'Scaron', 'scaron', 'Zcaron', 'zcaron', 'brokenbar',
  17298. 'Eth', 'eth', 'Yacute', 'yacute', 'Thorn', 'thorn', 'minus', 'multiply',
  17299. 'onesuperior', 'twosuperior', 'threesuperior', 'onehalf', 'onequarter',
  17300. 'threequarters', 'franc', 'Gbreve', 'gbreve', 'Idotaccent', 'Scedilla',
  17301. 'scedilla', 'Cacute', 'cacute', 'Ccaron', 'ccaron', 'dcroat'];
  17302. function getUnicodeRangeFor(value) {
  17303. for (var i = 0, ii = UnicodeRanges.length; i < ii; i++) {
  17304. var range = UnicodeRanges[i];
  17305. if (value >= range.begin && value < range.end) {
  17306. return i;
  17307. }
  17308. }
  17309. return -1;
  17310. }
  17311. function isRTLRangeFor(value) {
  17312. var range = UnicodeRanges[13];
  17313. if (value >= range.begin && value < range.end) {
  17314. return true;
  17315. }
  17316. range = UnicodeRanges[11];
  17317. if (value >= range.begin && value < range.end) {
  17318. return true;
  17319. }
  17320. return false;
  17321. }
  17322. // The normalization table is obtained by filtering the Unicode characters
  17323. // database with <compat> entries.
  17324. var NormalizedUnicodes = {
  17325. '\u00A8': '\u0020\u0308',
  17326. '\u00AF': '\u0020\u0304',
  17327. '\u00B4': '\u0020\u0301',
  17328. '\u00B5': '\u03BC',
  17329. '\u00B8': '\u0020\u0327',
  17330. '\u0132': '\u0049\u004A',
  17331. '\u0133': '\u0069\u006A',
  17332. '\u013F': '\u004C\u00B7',
  17333. '\u0140': '\u006C\u00B7',
  17334. '\u0149': '\u02BC\u006E',
  17335. '\u017F': '\u0073',
  17336. '\u01C4': '\u0044\u017D',
  17337. '\u01C5': '\u0044\u017E',
  17338. '\u01C6': '\u0064\u017E',
  17339. '\u01C7': '\u004C\u004A',
  17340. '\u01C8': '\u004C\u006A',
  17341. '\u01C9': '\u006C\u006A',
  17342. '\u01CA': '\u004E\u004A',
  17343. '\u01CB': '\u004E\u006A',
  17344. '\u01CC': '\u006E\u006A',
  17345. '\u01F1': '\u0044\u005A',
  17346. '\u01F2': '\u0044\u007A',
  17347. '\u01F3': '\u0064\u007A',
  17348. '\u02D8': '\u0020\u0306',
  17349. '\u02D9': '\u0020\u0307',
  17350. '\u02DA': '\u0020\u030A',
  17351. '\u02DB': '\u0020\u0328',
  17352. '\u02DC': '\u0020\u0303',
  17353. '\u02DD': '\u0020\u030B',
  17354. '\u037A': '\u0020\u0345',
  17355. '\u0384': '\u0020\u0301',
  17356. '\u03D0': '\u03B2',
  17357. '\u03D1': '\u03B8',
  17358. '\u03D2': '\u03A5',
  17359. '\u03D5': '\u03C6',
  17360. '\u03D6': '\u03C0',
  17361. '\u03F0': '\u03BA',
  17362. '\u03F1': '\u03C1',
  17363. '\u03F2': '\u03C2',
  17364. '\u03F4': '\u0398',
  17365. '\u03F5': '\u03B5',
  17366. '\u03F9': '\u03A3',
  17367. '\u0587': '\u0565\u0582',
  17368. '\u0675': '\u0627\u0674',
  17369. '\u0676': '\u0648\u0674',
  17370. '\u0677': '\u06C7\u0674',
  17371. '\u0678': '\u064A\u0674',
  17372. '\u0E33': '\u0E4D\u0E32',
  17373. '\u0EB3': '\u0ECD\u0EB2',
  17374. '\u0EDC': '\u0EAB\u0E99',
  17375. '\u0EDD': '\u0EAB\u0EA1',
  17376. '\u0F77': '\u0FB2\u0F81',
  17377. '\u0F79': '\u0FB3\u0F81',
  17378. '\u1E9A': '\u0061\u02BE',
  17379. '\u1FBD': '\u0020\u0313',
  17380. '\u1FBF': '\u0020\u0313',
  17381. '\u1FC0': '\u0020\u0342',
  17382. '\u1FFE': '\u0020\u0314',
  17383. '\u2002': '\u0020',
  17384. '\u2003': '\u0020',
  17385. '\u2004': '\u0020',
  17386. '\u2005': '\u0020',
  17387. '\u2006': '\u0020',
  17388. '\u2008': '\u0020',
  17389. '\u2009': '\u0020',
  17390. '\u200A': '\u0020',
  17391. '\u2017': '\u0020\u0333',
  17392. '\u2024': '\u002E',
  17393. '\u2025': '\u002E\u002E',
  17394. '\u2026': '\u002E\u002E\u002E',
  17395. '\u2033': '\u2032\u2032',
  17396. '\u2034': '\u2032\u2032\u2032',
  17397. '\u2036': '\u2035\u2035',
  17398. '\u2037': '\u2035\u2035\u2035',
  17399. '\u203C': '\u0021\u0021',
  17400. '\u203E': '\u0020\u0305',
  17401. '\u2047': '\u003F\u003F',
  17402. '\u2048': '\u003F\u0021',
  17403. '\u2049': '\u0021\u003F',
  17404. '\u2057': '\u2032\u2032\u2032\u2032',
  17405. '\u205F': '\u0020',
  17406. '\u20A8': '\u0052\u0073',
  17407. '\u2100': '\u0061\u002F\u0063',
  17408. '\u2101': '\u0061\u002F\u0073',
  17409. '\u2103': '\u00B0\u0043',
  17410. '\u2105': '\u0063\u002F\u006F',
  17411. '\u2106': '\u0063\u002F\u0075',
  17412. '\u2107': '\u0190',
  17413. '\u2109': '\u00B0\u0046',
  17414. '\u2116': '\u004E\u006F',
  17415. '\u2121': '\u0054\u0045\u004C',
  17416. '\u2135': '\u05D0',
  17417. '\u2136': '\u05D1',
  17418. '\u2137': '\u05D2',
  17419. '\u2138': '\u05D3',
  17420. '\u213B': '\u0046\u0041\u0058',
  17421. '\u2160': '\u0049',
  17422. '\u2161': '\u0049\u0049',
  17423. '\u2162': '\u0049\u0049\u0049',
  17424. '\u2163': '\u0049\u0056',
  17425. '\u2164': '\u0056',
  17426. '\u2165': '\u0056\u0049',
  17427. '\u2166': '\u0056\u0049\u0049',
  17428. '\u2167': '\u0056\u0049\u0049\u0049',
  17429. '\u2168': '\u0049\u0058',
  17430. '\u2169': '\u0058',
  17431. '\u216A': '\u0058\u0049',
  17432. '\u216B': '\u0058\u0049\u0049',
  17433. '\u216C': '\u004C',
  17434. '\u216D': '\u0043',
  17435. '\u216E': '\u0044',
  17436. '\u216F': '\u004D',
  17437. '\u2170': '\u0069',
  17438. '\u2171': '\u0069\u0069',
  17439. '\u2172': '\u0069\u0069\u0069',
  17440. '\u2173': '\u0069\u0076',
  17441. '\u2174': '\u0076',
  17442. '\u2175': '\u0076\u0069',
  17443. '\u2176': '\u0076\u0069\u0069',
  17444. '\u2177': '\u0076\u0069\u0069\u0069',
  17445. '\u2178': '\u0069\u0078',
  17446. '\u2179': '\u0078',
  17447. '\u217A': '\u0078\u0069',
  17448. '\u217B': '\u0078\u0069\u0069',
  17449. '\u217C': '\u006C',
  17450. '\u217D': '\u0063',
  17451. '\u217E': '\u0064',
  17452. '\u217F': '\u006D',
  17453. '\u222C': '\u222B\u222B',
  17454. '\u222D': '\u222B\u222B\u222B',
  17455. '\u222F': '\u222E\u222E',
  17456. '\u2230': '\u222E\u222E\u222E',
  17457. '\u2474': '\u0028\u0031\u0029',
  17458. '\u2475': '\u0028\u0032\u0029',
  17459. '\u2476': '\u0028\u0033\u0029',
  17460. '\u2477': '\u0028\u0034\u0029',
  17461. '\u2478': '\u0028\u0035\u0029',
  17462. '\u2479': '\u0028\u0036\u0029',
  17463. '\u247A': '\u0028\u0037\u0029',
  17464. '\u247B': '\u0028\u0038\u0029',
  17465. '\u247C': '\u0028\u0039\u0029',
  17466. '\u247D': '\u0028\u0031\u0030\u0029',
  17467. '\u247E': '\u0028\u0031\u0031\u0029',
  17468. '\u247F': '\u0028\u0031\u0032\u0029',
  17469. '\u2480': '\u0028\u0031\u0033\u0029',
  17470. '\u2481': '\u0028\u0031\u0034\u0029',
  17471. '\u2482': '\u0028\u0031\u0035\u0029',
  17472. '\u2483': '\u0028\u0031\u0036\u0029',
  17473. '\u2484': '\u0028\u0031\u0037\u0029',
  17474. '\u2485': '\u0028\u0031\u0038\u0029',
  17475. '\u2486': '\u0028\u0031\u0039\u0029',
  17476. '\u2487': '\u0028\u0032\u0030\u0029',
  17477. '\u2488': '\u0031\u002E',
  17478. '\u2489': '\u0032\u002E',
  17479. '\u248A': '\u0033\u002E',
  17480. '\u248B': '\u0034\u002E',
  17481. '\u248C': '\u0035\u002E',
  17482. '\u248D': '\u0036\u002E',
  17483. '\u248E': '\u0037\u002E',
  17484. '\u248F': '\u0038\u002E',
  17485. '\u2490': '\u0039\u002E',
  17486. '\u2491': '\u0031\u0030\u002E',
  17487. '\u2492': '\u0031\u0031\u002E',
  17488. '\u2493': '\u0031\u0032\u002E',
  17489. '\u2494': '\u0031\u0033\u002E',
  17490. '\u2495': '\u0031\u0034\u002E',
  17491. '\u2496': '\u0031\u0035\u002E',
  17492. '\u2497': '\u0031\u0036\u002E',
  17493. '\u2498': '\u0031\u0037\u002E',
  17494. '\u2499': '\u0031\u0038\u002E',
  17495. '\u249A': '\u0031\u0039\u002E',
  17496. '\u249B': '\u0032\u0030\u002E',
  17497. '\u249C': '\u0028\u0061\u0029',
  17498. '\u249D': '\u0028\u0062\u0029',
  17499. '\u249E': '\u0028\u0063\u0029',
  17500. '\u249F': '\u0028\u0064\u0029',
  17501. '\u24A0': '\u0028\u0065\u0029',
  17502. '\u24A1': '\u0028\u0066\u0029',
  17503. '\u24A2': '\u0028\u0067\u0029',
  17504. '\u24A3': '\u0028\u0068\u0029',
  17505. '\u24A4': '\u0028\u0069\u0029',
  17506. '\u24A5': '\u0028\u006A\u0029',
  17507. '\u24A6': '\u0028\u006B\u0029',
  17508. '\u24A7': '\u0028\u006C\u0029',
  17509. '\u24A8': '\u0028\u006D\u0029',
  17510. '\u24A9': '\u0028\u006E\u0029',
  17511. '\u24AA': '\u0028\u006F\u0029',
  17512. '\u24AB': '\u0028\u0070\u0029',
  17513. '\u24AC': '\u0028\u0071\u0029',
  17514. '\u24AD': '\u0028\u0072\u0029',
  17515. '\u24AE': '\u0028\u0073\u0029',
  17516. '\u24AF': '\u0028\u0074\u0029',
  17517. '\u24B0': '\u0028\u0075\u0029',
  17518. '\u24B1': '\u0028\u0076\u0029',
  17519. '\u24B2': '\u0028\u0077\u0029',
  17520. '\u24B3': '\u0028\u0078\u0029',
  17521. '\u24B4': '\u0028\u0079\u0029',
  17522. '\u24B5': '\u0028\u007A\u0029',
  17523. '\u2A0C': '\u222B\u222B\u222B\u222B',
  17524. '\u2A74': '\u003A\u003A\u003D',
  17525. '\u2A75': '\u003D\u003D',
  17526. '\u2A76': '\u003D\u003D\u003D',
  17527. '\u2E9F': '\u6BCD',
  17528. '\u2EF3': '\u9F9F',
  17529. '\u2F00': '\u4E00',
  17530. '\u2F01': '\u4E28',
  17531. '\u2F02': '\u4E36',
  17532. '\u2F03': '\u4E3F',
  17533. '\u2F04': '\u4E59',
  17534. '\u2F05': '\u4E85',
  17535. '\u2F06': '\u4E8C',
  17536. '\u2F07': '\u4EA0',
  17537. '\u2F08': '\u4EBA',
  17538. '\u2F09': '\u513F',
  17539. '\u2F0A': '\u5165',
  17540. '\u2F0B': '\u516B',
  17541. '\u2F0C': '\u5182',
  17542. '\u2F0D': '\u5196',
  17543. '\u2F0E': '\u51AB',
  17544. '\u2F0F': '\u51E0',
  17545. '\u2F10': '\u51F5',
  17546. '\u2F11': '\u5200',
  17547. '\u2F12': '\u529B',
  17548. '\u2F13': '\u52F9',
  17549. '\u2F14': '\u5315',
  17550. '\u2F15': '\u531A',
  17551. '\u2F16': '\u5338',
  17552. '\u2F17': '\u5341',
  17553. '\u2F18': '\u535C',
  17554. '\u2F19': '\u5369',
  17555. '\u2F1A': '\u5382',
  17556. '\u2F1B': '\u53B6',
  17557. '\u2F1C': '\u53C8',
  17558. '\u2F1D': '\u53E3',
  17559. '\u2F1E': '\u56D7',
  17560. '\u2F1F': '\u571F',
  17561. '\u2F20': '\u58EB',
  17562. '\u2F21': '\u5902',
  17563. '\u2F22': '\u590A',
  17564. '\u2F23': '\u5915',
  17565. '\u2F24': '\u5927',
  17566. '\u2F25': '\u5973',
  17567. '\u2F26': '\u5B50',
  17568. '\u2F27': '\u5B80',
  17569. '\u2F28': '\u5BF8',
  17570. '\u2F29': '\u5C0F',
  17571. '\u2F2A': '\u5C22',
  17572. '\u2F2B': '\u5C38',
  17573. '\u2F2C': '\u5C6E',
  17574. '\u2F2D': '\u5C71',
  17575. '\u2F2E': '\u5DDB',
  17576. '\u2F2F': '\u5DE5',
  17577. '\u2F30': '\u5DF1',
  17578. '\u2F31': '\u5DFE',
  17579. '\u2F32': '\u5E72',
  17580. '\u2F33': '\u5E7A',
  17581. '\u2F34': '\u5E7F',
  17582. '\u2F35': '\u5EF4',
  17583. '\u2F36': '\u5EFE',
  17584. '\u2F37': '\u5F0B',
  17585. '\u2F38': '\u5F13',
  17586. '\u2F39': '\u5F50',
  17587. '\u2F3A': '\u5F61',
  17588. '\u2F3B': '\u5F73',
  17589. '\u2F3C': '\u5FC3',
  17590. '\u2F3D': '\u6208',
  17591. '\u2F3E': '\u6236',
  17592. '\u2F3F': '\u624B',
  17593. '\u2F40': '\u652F',
  17594. '\u2F41': '\u6534',
  17595. '\u2F42': '\u6587',
  17596. '\u2F43': '\u6597',
  17597. '\u2F44': '\u65A4',
  17598. '\u2F45': '\u65B9',
  17599. '\u2F46': '\u65E0',
  17600. '\u2F47': '\u65E5',
  17601. '\u2F48': '\u66F0',
  17602. '\u2F49': '\u6708',
  17603. '\u2F4A': '\u6728',
  17604. '\u2F4B': '\u6B20',
  17605. '\u2F4C': '\u6B62',
  17606. '\u2F4D': '\u6B79',
  17607. '\u2F4E': '\u6BB3',
  17608. '\u2F4F': '\u6BCB',
  17609. '\u2F50': '\u6BD4',
  17610. '\u2F51': '\u6BDB',
  17611. '\u2F52': '\u6C0F',
  17612. '\u2F53': '\u6C14',
  17613. '\u2F54': '\u6C34',
  17614. '\u2F55': '\u706B',
  17615. '\u2F56': '\u722A',
  17616. '\u2F57': '\u7236',
  17617. '\u2F58': '\u723B',
  17618. '\u2F59': '\u723F',
  17619. '\u2F5A': '\u7247',
  17620. '\u2F5B': '\u7259',
  17621. '\u2F5C': '\u725B',
  17622. '\u2F5D': '\u72AC',
  17623. '\u2F5E': '\u7384',
  17624. '\u2F5F': '\u7389',
  17625. '\u2F60': '\u74DC',
  17626. '\u2F61': '\u74E6',
  17627. '\u2F62': '\u7518',
  17628. '\u2F63': '\u751F',
  17629. '\u2F64': '\u7528',
  17630. '\u2F65': '\u7530',
  17631. '\u2F66': '\u758B',
  17632. '\u2F67': '\u7592',
  17633. '\u2F68': '\u7676',
  17634. '\u2F69': '\u767D',
  17635. '\u2F6A': '\u76AE',
  17636. '\u2F6B': '\u76BF',
  17637. '\u2F6C': '\u76EE',
  17638. '\u2F6D': '\u77DB',
  17639. '\u2F6E': '\u77E2',
  17640. '\u2F6F': '\u77F3',
  17641. '\u2F70': '\u793A',
  17642. '\u2F71': '\u79B8',
  17643. '\u2F72': '\u79BE',
  17644. '\u2F73': '\u7A74',
  17645. '\u2F74': '\u7ACB',
  17646. '\u2F75': '\u7AF9',
  17647. '\u2F76': '\u7C73',
  17648. '\u2F77': '\u7CF8',
  17649. '\u2F78': '\u7F36',
  17650. '\u2F79': '\u7F51',
  17651. '\u2F7A': '\u7F8A',
  17652. '\u2F7B': '\u7FBD',
  17653. '\u2F7C': '\u8001',
  17654. '\u2F7D': '\u800C',
  17655. '\u2F7E': '\u8012',
  17656. '\u2F7F': '\u8033',
  17657. '\u2F80': '\u807F',
  17658. '\u2F81': '\u8089',
  17659. '\u2F82': '\u81E3',
  17660. '\u2F83': '\u81EA',
  17661. '\u2F84': '\u81F3',
  17662. '\u2F85': '\u81FC',
  17663. '\u2F86': '\u820C',
  17664. '\u2F87': '\u821B',
  17665. '\u2F88': '\u821F',
  17666. '\u2F89': '\u826E',
  17667. '\u2F8A': '\u8272',
  17668. '\u2F8B': '\u8278',
  17669. '\u2F8C': '\u864D',
  17670. '\u2F8D': '\u866B',
  17671. '\u2F8E': '\u8840',
  17672. '\u2F8F': '\u884C',
  17673. '\u2F90': '\u8863',
  17674. '\u2F91': '\u897E',
  17675. '\u2F92': '\u898B',
  17676. '\u2F93': '\u89D2',
  17677. '\u2F94': '\u8A00',
  17678. '\u2F95': '\u8C37',
  17679. '\u2F96': '\u8C46',
  17680. '\u2F97': '\u8C55',
  17681. '\u2F98': '\u8C78',
  17682. '\u2F99': '\u8C9D',
  17683. '\u2F9A': '\u8D64',
  17684. '\u2F9B': '\u8D70',
  17685. '\u2F9C': '\u8DB3',
  17686. '\u2F9D': '\u8EAB',
  17687. '\u2F9E': '\u8ECA',
  17688. '\u2F9F': '\u8F9B',
  17689. '\u2FA0': '\u8FB0',
  17690. '\u2FA1': '\u8FB5',
  17691. '\u2FA2': '\u9091',
  17692. '\u2FA3': '\u9149',
  17693. '\u2FA4': '\u91C6',
  17694. '\u2FA5': '\u91CC',
  17695. '\u2FA6': '\u91D1',
  17696. '\u2FA7': '\u9577',
  17697. '\u2FA8': '\u9580',
  17698. '\u2FA9': '\u961C',
  17699. '\u2FAA': '\u96B6',
  17700. '\u2FAB': '\u96B9',
  17701. '\u2FAC': '\u96E8',
  17702. '\u2FAD': '\u9751',
  17703. '\u2FAE': '\u975E',
  17704. '\u2FAF': '\u9762',
  17705. '\u2FB0': '\u9769',
  17706. '\u2FB1': '\u97CB',
  17707. '\u2FB2': '\u97ED',
  17708. '\u2FB3': '\u97F3',
  17709. '\u2FB4': '\u9801',
  17710. '\u2FB5': '\u98A8',
  17711. '\u2FB6': '\u98DB',
  17712. '\u2FB7': '\u98DF',
  17713. '\u2FB8': '\u9996',
  17714. '\u2FB9': '\u9999',
  17715. '\u2FBA': '\u99AC',
  17716. '\u2FBB': '\u9AA8',
  17717. '\u2FBC': '\u9AD8',
  17718. '\u2FBD': '\u9ADF',
  17719. '\u2FBE': '\u9B25',
  17720. '\u2FBF': '\u9B2F',
  17721. '\u2FC0': '\u9B32',
  17722. '\u2FC1': '\u9B3C',
  17723. '\u2FC2': '\u9B5A',
  17724. '\u2FC3': '\u9CE5',
  17725. '\u2FC4': '\u9E75',
  17726. '\u2FC5': '\u9E7F',
  17727. '\u2FC6': '\u9EA5',
  17728. '\u2FC7': '\u9EBB',
  17729. '\u2FC8': '\u9EC3',
  17730. '\u2FC9': '\u9ECD',
  17731. '\u2FCA': '\u9ED1',
  17732. '\u2FCB': '\u9EF9',
  17733. '\u2FCC': '\u9EFD',
  17734. '\u2FCD': '\u9F0E',
  17735. '\u2FCE': '\u9F13',
  17736. '\u2FCF': '\u9F20',
  17737. '\u2FD0': '\u9F3B',
  17738. '\u2FD1': '\u9F4A',
  17739. '\u2FD2': '\u9F52',
  17740. '\u2FD3': '\u9F8D',
  17741. '\u2FD4': '\u9F9C',
  17742. '\u2FD5': '\u9FA0',
  17743. '\u3036': '\u3012',
  17744. '\u3038': '\u5341',
  17745. '\u3039': '\u5344',
  17746. '\u303A': '\u5345',
  17747. '\u309B': '\u0020\u3099',
  17748. '\u309C': '\u0020\u309A',
  17749. '\u3131': '\u1100',
  17750. '\u3132': '\u1101',
  17751. '\u3133': '\u11AA',
  17752. '\u3134': '\u1102',
  17753. '\u3135': '\u11AC',
  17754. '\u3136': '\u11AD',
  17755. '\u3137': '\u1103',
  17756. '\u3138': '\u1104',
  17757. '\u3139': '\u1105',
  17758. '\u313A': '\u11B0',
  17759. '\u313B': '\u11B1',
  17760. '\u313C': '\u11B2',
  17761. '\u313D': '\u11B3',
  17762. '\u313E': '\u11B4',
  17763. '\u313F': '\u11B5',
  17764. '\u3140': '\u111A',
  17765. '\u3141': '\u1106',
  17766. '\u3142': '\u1107',
  17767. '\u3143': '\u1108',
  17768. '\u3144': '\u1121',
  17769. '\u3145': '\u1109',
  17770. '\u3146': '\u110A',
  17771. '\u3147': '\u110B',
  17772. '\u3148': '\u110C',
  17773. '\u3149': '\u110D',
  17774. '\u314A': '\u110E',
  17775. '\u314B': '\u110F',
  17776. '\u314C': '\u1110',
  17777. '\u314D': '\u1111',
  17778. '\u314E': '\u1112',
  17779. '\u314F': '\u1161',
  17780. '\u3150': '\u1162',
  17781. '\u3151': '\u1163',
  17782. '\u3152': '\u1164',
  17783. '\u3153': '\u1165',
  17784. '\u3154': '\u1166',
  17785. '\u3155': '\u1167',
  17786. '\u3156': '\u1168',
  17787. '\u3157': '\u1169',
  17788. '\u3158': '\u116A',
  17789. '\u3159': '\u116B',
  17790. '\u315A': '\u116C',
  17791. '\u315B': '\u116D',
  17792. '\u315C': '\u116E',
  17793. '\u315D': '\u116F',
  17794. '\u315E': '\u1170',
  17795. '\u315F': '\u1171',
  17796. '\u3160': '\u1172',
  17797. '\u3161': '\u1173',
  17798. '\u3162': '\u1174',
  17799. '\u3163': '\u1175',
  17800. '\u3164': '\u1160',
  17801. '\u3165': '\u1114',
  17802. '\u3166': '\u1115',
  17803. '\u3167': '\u11C7',
  17804. '\u3168': '\u11C8',
  17805. '\u3169': '\u11CC',
  17806. '\u316A': '\u11CE',
  17807. '\u316B': '\u11D3',
  17808. '\u316C': '\u11D7',
  17809. '\u316D': '\u11D9',
  17810. '\u316E': '\u111C',
  17811. '\u316F': '\u11DD',
  17812. '\u3170': '\u11DF',
  17813. '\u3171': '\u111D',
  17814. '\u3172': '\u111E',
  17815. '\u3173': '\u1120',
  17816. '\u3174': '\u1122',
  17817. '\u3175': '\u1123',
  17818. '\u3176': '\u1127',
  17819. '\u3177': '\u1129',
  17820. '\u3178': '\u112B',
  17821. '\u3179': '\u112C',
  17822. '\u317A': '\u112D',
  17823. '\u317B': '\u112E',
  17824. '\u317C': '\u112F',
  17825. '\u317D': '\u1132',
  17826. '\u317E': '\u1136',
  17827. '\u317F': '\u1140',
  17828. '\u3180': '\u1147',
  17829. '\u3181': '\u114C',
  17830. '\u3182': '\u11F1',
  17831. '\u3183': '\u11F2',
  17832. '\u3184': '\u1157',
  17833. '\u3185': '\u1158',
  17834. '\u3186': '\u1159',
  17835. '\u3187': '\u1184',
  17836. '\u3188': '\u1185',
  17837. '\u3189': '\u1188',
  17838. '\u318A': '\u1191',
  17839. '\u318B': '\u1192',
  17840. '\u318C': '\u1194',
  17841. '\u318D': '\u119E',
  17842. '\u318E': '\u11A1',
  17843. '\u3200': '\u0028\u1100\u0029',
  17844. '\u3201': '\u0028\u1102\u0029',
  17845. '\u3202': '\u0028\u1103\u0029',
  17846. '\u3203': '\u0028\u1105\u0029',
  17847. '\u3204': '\u0028\u1106\u0029',
  17848. '\u3205': '\u0028\u1107\u0029',
  17849. '\u3206': '\u0028\u1109\u0029',
  17850. '\u3207': '\u0028\u110B\u0029',
  17851. '\u3208': '\u0028\u110C\u0029',
  17852. '\u3209': '\u0028\u110E\u0029',
  17853. '\u320A': '\u0028\u110F\u0029',
  17854. '\u320B': '\u0028\u1110\u0029',
  17855. '\u320C': '\u0028\u1111\u0029',
  17856. '\u320D': '\u0028\u1112\u0029',
  17857. '\u320E': '\u0028\u1100\u1161\u0029',
  17858. '\u320F': '\u0028\u1102\u1161\u0029',
  17859. '\u3210': '\u0028\u1103\u1161\u0029',
  17860. '\u3211': '\u0028\u1105\u1161\u0029',
  17861. '\u3212': '\u0028\u1106\u1161\u0029',
  17862. '\u3213': '\u0028\u1107\u1161\u0029',
  17863. '\u3214': '\u0028\u1109\u1161\u0029',
  17864. '\u3215': '\u0028\u110B\u1161\u0029',
  17865. '\u3216': '\u0028\u110C\u1161\u0029',
  17866. '\u3217': '\u0028\u110E\u1161\u0029',
  17867. '\u3218': '\u0028\u110F\u1161\u0029',
  17868. '\u3219': '\u0028\u1110\u1161\u0029',
  17869. '\u321A': '\u0028\u1111\u1161\u0029',
  17870. '\u321B': '\u0028\u1112\u1161\u0029',
  17871. '\u321C': '\u0028\u110C\u116E\u0029',
  17872. '\u321D': '\u0028\u110B\u1169\u110C\u1165\u11AB\u0029',
  17873. '\u321E': '\u0028\u110B\u1169\u1112\u116E\u0029',
  17874. '\u3220': '\u0028\u4E00\u0029',
  17875. '\u3221': '\u0028\u4E8C\u0029',
  17876. '\u3222': '\u0028\u4E09\u0029',
  17877. '\u3223': '\u0028\u56DB\u0029',
  17878. '\u3224': '\u0028\u4E94\u0029',
  17879. '\u3225': '\u0028\u516D\u0029',
  17880. '\u3226': '\u0028\u4E03\u0029',
  17881. '\u3227': '\u0028\u516B\u0029',
  17882. '\u3228': '\u0028\u4E5D\u0029',
  17883. '\u3229': '\u0028\u5341\u0029',
  17884. '\u322A': '\u0028\u6708\u0029',
  17885. '\u322B': '\u0028\u706B\u0029',
  17886. '\u322C': '\u0028\u6C34\u0029',
  17887. '\u322D': '\u0028\u6728\u0029',
  17888. '\u322E': '\u0028\u91D1\u0029',
  17889. '\u322F': '\u0028\u571F\u0029',
  17890. '\u3230': '\u0028\u65E5\u0029',
  17891. '\u3231': '\u0028\u682A\u0029',
  17892. '\u3232': '\u0028\u6709\u0029',
  17893. '\u3233': '\u0028\u793E\u0029',
  17894. '\u3234': '\u0028\u540D\u0029',
  17895. '\u3235': '\u0028\u7279\u0029',
  17896. '\u3236': '\u0028\u8CA1\u0029',
  17897. '\u3237': '\u0028\u795D\u0029',
  17898. '\u3238': '\u0028\u52B4\u0029',
  17899. '\u3239': '\u0028\u4EE3\u0029',
  17900. '\u323A': '\u0028\u547C\u0029',
  17901. '\u323B': '\u0028\u5B66\u0029',
  17902. '\u323C': '\u0028\u76E3\u0029',
  17903. '\u323D': '\u0028\u4F01\u0029',
  17904. '\u323E': '\u0028\u8CC7\u0029',
  17905. '\u323F': '\u0028\u5354\u0029',
  17906. '\u3240': '\u0028\u796D\u0029',
  17907. '\u3241': '\u0028\u4F11\u0029',
  17908. '\u3242': '\u0028\u81EA\u0029',
  17909. '\u3243': '\u0028\u81F3\u0029',
  17910. '\u32C0': '\u0031\u6708',
  17911. '\u32C1': '\u0032\u6708',
  17912. '\u32C2': '\u0033\u6708',
  17913. '\u32C3': '\u0034\u6708',
  17914. '\u32C4': '\u0035\u6708',
  17915. '\u32C5': '\u0036\u6708',
  17916. '\u32C6': '\u0037\u6708',
  17917. '\u32C7': '\u0038\u6708',
  17918. '\u32C8': '\u0039\u6708',
  17919. '\u32C9': '\u0031\u0030\u6708',
  17920. '\u32CA': '\u0031\u0031\u6708',
  17921. '\u32CB': '\u0031\u0032\u6708',
  17922. '\u3358': '\u0030\u70B9',
  17923. '\u3359': '\u0031\u70B9',
  17924. '\u335A': '\u0032\u70B9',
  17925. '\u335B': '\u0033\u70B9',
  17926. '\u335C': '\u0034\u70B9',
  17927. '\u335D': '\u0035\u70B9',
  17928. '\u335E': '\u0036\u70B9',
  17929. '\u335F': '\u0037\u70B9',
  17930. '\u3360': '\u0038\u70B9',
  17931. '\u3361': '\u0039\u70B9',
  17932. '\u3362': '\u0031\u0030\u70B9',
  17933. '\u3363': '\u0031\u0031\u70B9',
  17934. '\u3364': '\u0031\u0032\u70B9',
  17935. '\u3365': '\u0031\u0033\u70B9',
  17936. '\u3366': '\u0031\u0034\u70B9',
  17937. '\u3367': '\u0031\u0035\u70B9',
  17938. '\u3368': '\u0031\u0036\u70B9',
  17939. '\u3369': '\u0031\u0037\u70B9',
  17940. '\u336A': '\u0031\u0038\u70B9',
  17941. '\u336B': '\u0031\u0039\u70B9',
  17942. '\u336C': '\u0032\u0030\u70B9',
  17943. '\u336D': '\u0032\u0031\u70B9',
  17944. '\u336E': '\u0032\u0032\u70B9',
  17945. '\u336F': '\u0032\u0033\u70B9',
  17946. '\u3370': '\u0032\u0034\u70B9',
  17947. '\u33E0': '\u0031\u65E5',
  17948. '\u33E1': '\u0032\u65E5',
  17949. '\u33E2': '\u0033\u65E5',
  17950. '\u33E3': '\u0034\u65E5',
  17951. '\u33E4': '\u0035\u65E5',
  17952. '\u33E5': '\u0036\u65E5',
  17953. '\u33E6': '\u0037\u65E5',
  17954. '\u33E7': '\u0038\u65E5',
  17955. '\u33E8': '\u0039\u65E5',
  17956. '\u33E9': '\u0031\u0030\u65E5',
  17957. '\u33EA': '\u0031\u0031\u65E5',
  17958. '\u33EB': '\u0031\u0032\u65E5',
  17959. '\u33EC': '\u0031\u0033\u65E5',
  17960. '\u33ED': '\u0031\u0034\u65E5',
  17961. '\u33EE': '\u0031\u0035\u65E5',
  17962. '\u33EF': '\u0031\u0036\u65E5',
  17963. '\u33F0': '\u0031\u0037\u65E5',
  17964. '\u33F1': '\u0031\u0038\u65E5',
  17965. '\u33F2': '\u0031\u0039\u65E5',
  17966. '\u33F3': '\u0032\u0030\u65E5',
  17967. '\u33F4': '\u0032\u0031\u65E5',
  17968. '\u33F5': '\u0032\u0032\u65E5',
  17969. '\u33F6': '\u0032\u0033\u65E5',
  17970. '\u33F7': '\u0032\u0034\u65E5',
  17971. '\u33F8': '\u0032\u0035\u65E5',
  17972. '\u33F9': '\u0032\u0036\u65E5',
  17973. '\u33FA': '\u0032\u0037\u65E5',
  17974. '\u33FB': '\u0032\u0038\u65E5',
  17975. '\u33FC': '\u0032\u0039\u65E5',
  17976. '\u33FD': '\u0033\u0030\u65E5',
  17977. '\u33FE': '\u0033\u0031\u65E5',
  17978. '\uFB00': '\u0066\u0066',
  17979. '\uFB01': '\u0066\u0069',
  17980. '\uFB02': '\u0066\u006C',
  17981. '\uFB03': '\u0066\u0066\u0069',
  17982. '\uFB04': '\u0066\u0066\u006C',
  17983. '\uFB05': '\u017F\u0074',
  17984. '\uFB06': '\u0073\u0074',
  17985. '\uFB13': '\u0574\u0576',
  17986. '\uFB14': '\u0574\u0565',
  17987. '\uFB15': '\u0574\u056B',
  17988. '\uFB16': '\u057E\u0576',
  17989. '\uFB17': '\u0574\u056D',
  17990. '\uFB4F': '\u05D0\u05DC',
  17991. '\uFB50': '\u0671',
  17992. '\uFB51': '\u0671',
  17993. '\uFB52': '\u067B',
  17994. '\uFB53': '\u067B',
  17995. '\uFB54': '\u067B',
  17996. '\uFB55': '\u067B',
  17997. '\uFB56': '\u067E',
  17998. '\uFB57': '\u067E',
  17999. '\uFB58': '\u067E',
  18000. '\uFB59': '\u067E',
  18001. '\uFB5A': '\u0680',
  18002. '\uFB5B': '\u0680',
  18003. '\uFB5C': '\u0680',
  18004. '\uFB5D': '\u0680',
  18005. '\uFB5E': '\u067A',
  18006. '\uFB5F': '\u067A',
  18007. '\uFB60': '\u067A',
  18008. '\uFB61': '\u067A',
  18009. '\uFB62': '\u067F',
  18010. '\uFB63': '\u067F',
  18011. '\uFB64': '\u067F',
  18012. '\uFB65': '\u067F',
  18013. '\uFB66': '\u0679',
  18014. '\uFB67': '\u0679',
  18015. '\uFB68': '\u0679',
  18016. '\uFB69': '\u0679',
  18017. '\uFB6A': '\u06A4',
  18018. '\uFB6B': '\u06A4',
  18019. '\uFB6C': '\u06A4',
  18020. '\uFB6D': '\u06A4',
  18021. '\uFB6E': '\u06A6',
  18022. '\uFB6F': '\u06A6',
  18023. '\uFB70': '\u06A6',
  18024. '\uFB71': '\u06A6',
  18025. '\uFB72': '\u0684',
  18026. '\uFB73': '\u0684',
  18027. '\uFB74': '\u0684',
  18028. '\uFB75': '\u0684',
  18029. '\uFB76': '\u0683',
  18030. '\uFB77': '\u0683',
  18031. '\uFB78': '\u0683',
  18032. '\uFB79': '\u0683',
  18033. '\uFB7A': '\u0686',
  18034. '\uFB7B': '\u0686',
  18035. '\uFB7C': '\u0686',
  18036. '\uFB7D': '\u0686',
  18037. '\uFB7E': '\u0687',
  18038. '\uFB7F': '\u0687',
  18039. '\uFB80': '\u0687',
  18040. '\uFB81': '\u0687',
  18041. '\uFB82': '\u068D',
  18042. '\uFB83': '\u068D',
  18043. '\uFB84': '\u068C',
  18044. '\uFB85': '\u068C',
  18045. '\uFB86': '\u068E',
  18046. '\uFB87': '\u068E',
  18047. '\uFB88': '\u0688',
  18048. '\uFB89': '\u0688',
  18049. '\uFB8A': '\u0698',
  18050. '\uFB8B': '\u0698',
  18051. '\uFB8C': '\u0691',
  18052. '\uFB8D': '\u0691',
  18053. '\uFB8E': '\u06A9',
  18054. '\uFB8F': '\u06A9',
  18055. '\uFB90': '\u06A9',
  18056. '\uFB91': '\u06A9',
  18057. '\uFB92': '\u06AF',
  18058. '\uFB93': '\u06AF',
  18059. '\uFB94': '\u06AF',
  18060. '\uFB95': '\u06AF',
  18061. '\uFB96': '\u06B3',
  18062. '\uFB97': '\u06B3',
  18063. '\uFB98': '\u06B3',
  18064. '\uFB99': '\u06B3',
  18065. '\uFB9A': '\u06B1',
  18066. '\uFB9B': '\u06B1',
  18067. '\uFB9C': '\u06B1',
  18068. '\uFB9D': '\u06B1',
  18069. '\uFB9E': '\u06BA',
  18070. '\uFB9F': '\u06BA',
  18071. '\uFBA0': '\u06BB',
  18072. '\uFBA1': '\u06BB',
  18073. '\uFBA2': '\u06BB',
  18074. '\uFBA3': '\u06BB',
  18075. '\uFBA4': '\u06C0',
  18076. '\uFBA5': '\u06C0',
  18077. '\uFBA6': '\u06C1',
  18078. '\uFBA7': '\u06C1',
  18079. '\uFBA8': '\u06C1',
  18080. '\uFBA9': '\u06C1',
  18081. '\uFBAA': '\u06BE',
  18082. '\uFBAB': '\u06BE',
  18083. '\uFBAC': '\u06BE',
  18084. '\uFBAD': '\u06BE',
  18085. '\uFBAE': '\u06D2',
  18086. '\uFBAF': '\u06D2',
  18087. '\uFBB0': '\u06D3',
  18088. '\uFBB1': '\u06D3',
  18089. '\uFBD3': '\u06AD',
  18090. '\uFBD4': '\u06AD',
  18091. '\uFBD5': '\u06AD',
  18092. '\uFBD6': '\u06AD',
  18093. '\uFBD7': '\u06C7',
  18094. '\uFBD8': '\u06C7',
  18095. '\uFBD9': '\u06C6',
  18096. '\uFBDA': '\u06C6',
  18097. '\uFBDB': '\u06C8',
  18098. '\uFBDC': '\u06C8',
  18099. '\uFBDD': '\u0677',
  18100. '\uFBDE': '\u06CB',
  18101. '\uFBDF': '\u06CB',
  18102. '\uFBE0': '\u06C5',
  18103. '\uFBE1': '\u06C5',
  18104. '\uFBE2': '\u06C9',
  18105. '\uFBE3': '\u06C9',
  18106. '\uFBE4': '\u06D0',
  18107. '\uFBE5': '\u06D0',
  18108. '\uFBE6': '\u06D0',
  18109. '\uFBE7': '\u06D0',
  18110. '\uFBE8': '\u0649',
  18111. '\uFBE9': '\u0649',
  18112. '\uFBEA': '\u0626\u0627',
  18113. '\uFBEB': '\u0626\u0627',
  18114. '\uFBEC': '\u0626\u06D5',
  18115. '\uFBED': '\u0626\u06D5',
  18116. '\uFBEE': '\u0626\u0648',
  18117. '\uFBEF': '\u0626\u0648',
  18118. '\uFBF0': '\u0626\u06C7',
  18119. '\uFBF1': '\u0626\u06C7',
  18120. '\uFBF2': '\u0626\u06C6',
  18121. '\uFBF3': '\u0626\u06C6',
  18122. '\uFBF4': '\u0626\u06C8',
  18123. '\uFBF5': '\u0626\u06C8',
  18124. '\uFBF6': '\u0626\u06D0',
  18125. '\uFBF7': '\u0626\u06D0',
  18126. '\uFBF8': '\u0626\u06D0',
  18127. '\uFBF9': '\u0626\u0649',
  18128. '\uFBFA': '\u0626\u0649',
  18129. '\uFBFB': '\u0626\u0649',
  18130. '\uFBFC': '\u06CC',
  18131. '\uFBFD': '\u06CC',
  18132. '\uFBFE': '\u06CC',
  18133. '\uFBFF': '\u06CC',
  18134. '\uFC00': '\u0626\u062C',
  18135. '\uFC01': '\u0626\u062D',
  18136. '\uFC02': '\u0626\u0645',
  18137. '\uFC03': '\u0626\u0649',
  18138. '\uFC04': '\u0626\u064A',
  18139. '\uFC05': '\u0628\u062C',
  18140. '\uFC06': '\u0628\u062D',
  18141. '\uFC07': '\u0628\u062E',
  18142. '\uFC08': '\u0628\u0645',
  18143. '\uFC09': '\u0628\u0649',
  18144. '\uFC0A': '\u0628\u064A',
  18145. '\uFC0B': '\u062A\u062C',
  18146. '\uFC0C': '\u062A\u062D',
  18147. '\uFC0D': '\u062A\u062E',
  18148. '\uFC0E': '\u062A\u0645',
  18149. '\uFC0F': '\u062A\u0649',
  18150. '\uFC10': '\u062A\u064A',
  18151. '\uFC11': '\u062B\u062C',
  18152. '\uFC12': '\u062B\u0645',
  18153. '\uFC13': '\u062B\u0649',
  18154. '\uFC14': '\u062B\u064A',
  18155. '\uFC15': '\u062C\u062D',
  18156. '\uFC16': '\u062C\u0645',
  18157. '\uFC17': '\u062D\u062C',
  18158. '\uFC18': '\u062D\u0645',
  18159. '\uFC19': '\u062E\u062C',
  18160. '\uFC1A': '\u062E\u062D',
  18161. '\uFC1B': '\u062E\u0645',
  18162. '\uFC1C': '\u0633\u062C',
  18163. '\uFC1D': '\u0633\u062D',
  18164. '\uFC1E': '\u0633\u062E',
  18165. '\uFC1F': '\u0633\u0645',
  18166. '\uFC20': '\u0635\u062D',
  18167. '\uFC21': '\u0635\u0645',
  18168. '\uFC22': '\u0636\u062C',
  18169. '\uFC23': '\u0636\u062D',
  18170. '\uFC24': '\u0636\u062E',
  18171. '\uFC25': '\u0636\u0645',
  18172. '\uFC26': '\u0637\u062D',
  18173. '\uFC27': '\u0637\u0645',
  18174. '\uFC28': '\u0638\u0645',
  18175. '\uFC29': '\u0639\u062C',
  18176. '\uFC2A': '\u0639\u0645',
  18177. '\uFC2B': '\u063A\u062C',
  18178. '\uFC2C': '\u063A\u0645',
  18179. '\uFC2D': '\u0641\u062C',
  18180. '\uFC2E': '\u0641\u062D',
  18181. '\uFC2F': '\u0641\u062E',
  18182. '\uFC30': '\u0641\u0645',
  18183. '\uFC31': '\u0641\u0649',
  18184. '\uFC32': '\u0641\u064A',
  18185. '\uFC33': '\u0642\u062D',
  18186. '\uFC34': '\u0642\u0645',
  18187. '\uFC35': '\u0642\u0649',
  18188. '\uFC36': '\u0642\u064A',
  18189. '\uFC37': '\u0643\u0627',
  18190. '\uFC38': '\u0643\u062C',
  18191. '\uFC39': '\u0643\u062D',
  18192. '\uFC3A': '\u0643\u062E',
  18193. '\uFC3B': '\u0643\u0644',
  18194. '\uFC3C': '\u0643\u0645',
  18195. '\uFC3D': '\u0643\u0649',
  18196. '\uFC3E': '\u0643\u064A',
  18197. '\uFC3F': '\u0644\u062C',
  18198. '\uFC40': '\u0644\u062D',
  18199. '\uFC41': '\u0644\u062E',
  18200. '\uFC42': '\u0644\u0645',
  18201. '\uFC43': '\u0644\u0649',
  18202. '\uFC44': '\u0644\u064A',
  18203. '\uFC45': '\u0645\u062C',
  18204. '\uFC46': '\u0645\u062D',
  18205. '\uFC47': '\u0645\u062E',
  18206. '\uFC48': '\u0645\u0645',
  18207. '\uFC49': '\u0645\u0649',
  18208. '\uFC4A': '\u0645\u064A',
  18209. '\uFC4B': '\u0646\u062C',
  18210. '\uFC4C': '\u0646\u062D',
  18211. '\uFC4D': '\u0646\u062E',
  18212. '\uFC4E': '\u0646\u0645',
  18213. '\uFC4F': '\u0646\u0649',
  18214. '\uFC50': '\u0646\u064A',
  18215. '\uFC51': '\u0647\u062C',
  18216. '\uFC52': '\u0647\u0645',
  18217. '\uFC53': '\u0647\u0649',
  18218. '\uFC54': '\u0647\u064A',
  18219. '\uFC55': '\u064A\u062C',
  18220. '\uFC56': '\u064A\u062D',
  18221. '\uFC57': '\u064A\u062E',
  18222. '\uFC58': '\u064A\u0645',
  18223. '\uFC59': '\u064A\u0649',
  18224. '\uFC5A': '\u064A\u064A',
  18225. '\uFC5B': '\u0630\u0670',
  18226. '\uFC5C': '\u0631\u0670',
  18227. '\uFC5D': '\u0649\u0670',
  18228. '\uFC5E': '\u0020\u064C\u0651',
  18229. '\uFC5F': '\u0020\u064D\u0651',
  18230. '\uFC60': '\u0020\u064E\u0651',
  18231. '\uFC61': '\u0020\u064F\u0651',
  18232. '\uFC62': '\u0020\u0650\u0651',
  18233. '\uFC63': '\u0020\u0651\u0670',
  18234. '\uFC64': '\u0626\u0631',
  18235. '\uFC65': '\u0626\u0632',
  18236. '\uFC66': '\u0626\u0645',
  18237. '\uFC67': '\u0626\u0646',
  18238. '\uFC68': '\u0626\u0649',
  18239. '\uFC69': '\u0626\u064A',
  18240. '\uFC6A': '\u0628\u0631',
  18241. '\uFC6B': '\u0628\u0632',
  18242. '\uFC6C': '\u0628\u0645',
  18243. '\uFC6D': '\u0628\u0646',
  18244. '\uFC6E': '\u0628\u0649',
  18245. '\uFC6F': '\u0628\u064A',
  18246. '\uFC70': '\u062A\u0631',
  18247. '\uFC71': '\u062A\u0632',
  18248. '\uFC72': '\u062A\u0645',
  18249. '\uFC73': '\u062A\u0646',
  18250. '\uFC74': '\u062A\u0649',
  18251. '\uFC75': '\u062A\u064A',
  18252. '\uFC76': '\u062B\u0631',
  18253. '\uFC77': '\u062B\u0632',
  18254. '\uFC78': '\u062B\u0645',
  18255. '\uFC79': '\u062B\u0646',
  18256. '\uFC7A': '\u062B\u0649',
  18257. '\uFC7B': '\u062B\u064A',
  18258. '\uFC7C': '\u0641\u0649',
  18259. '\uFC7D': '\u0641\u064A',
  18260. '\uFC7E': '\u0642\u0649',
  18261. '\uFC7F': '\u0642\u064A',
  18262. '\uFC80': '\u0643\u0627',
  18263. '\uFC81': '\u0643\u0644',
  18264. '\uFC82': '\u0643\u0645',
  18265. '\uFC83': '\u0643\u0649',
  18266. '\uFC84': '\u0643\u064A',
  18267. '\uFC85': '\u0644\u0645',
  18268. '\uFC86': '\u0644\u0649',
  18269. '\uFC87': '\u0644\u064A',
  18270. '\uFC88': '\u0645\u0627',
  18271. '\uFC89': '\u0645\u0645',
  18272. '\uFC8A': '\u0646\u0631',
  18273. '\uFC8B': '\u0646\u0632',
  18274. '\uFC8C': '\u0646\u0645',
  18275. '\uFC8D': '\u0646\u0646',
  18276. '\uFC8E': '\u0646\u0649',
  18277. '\uFC8F': '\u0646\u064A',
  18278. '\uFC90': '\u0649\u0670',
  18279. '\uFC91': '\u064A\u0631',
  18280. '\uFC92': '\u064A\u0632',
  18281. '\uFC93': '\u064A\u0645',
  18282. '\uFC94': '\u064A\u0646',
  18283. '\uFC95': '\u064A\u0649',
  18284. '\uFC96': '\u064A\u064A',
  18285. '\uFC97': '\u0626\u062C',
  18286. '\uFC98': '\u0626\u062D',
  18287. '\uFC99': '\u0626\u062E',
  18288. '\uFC9A': '\u0626\u0645',
  18289. '\uFC9B': '\u0626\u0647',
  18290. '\uFC9C': '\u0628\u062C',
  18291. '\uFC9D': '\u0628\u062D',
  18292. '\uFC9E': '\u0628\u062E',
  18293. '\uFC9F': '\u0628\u0645',
  18294. '\uFCA0': '\u0628\u0647',
  18295. '\uFCA1': '\u062A\u062C',
  18296. '\uFCA2': '\u062A\u062D',
  18297. '\uFCA3': '\u062A\u062E',
  18298. '\uFCA4': '\u062A\u0645',
  18299. '\uFCA5': '\u062A\u0647',
  18300. '\uFCA6': '\u062B\u0645',
  18301. '\uFCA7': '\u062C\u062D',
  18302. '\uFCA8': '\u062C\u0645',
  18303. '\uFCA9': '\u062D\u062C',
  18304. '\uFCAA': '\u062D\u0645',
  18305. '\uFCAB': '\u062E\u062C',
  18306. '\uFCAC': '\u062E\u0645',
  18307. '\uFCAD': '\u0633\u062C',
  18308. '\uFCAE': '\u0633\u062D',
  18309. '\uFCAF': '\u0633\u062E',
  18310. '\uFCB0': '\u0633\u0645',
  18311. '\uFCB1': '\u0635\u062D',
  18312. '\uFCB2': '\u0635\u062E',
  18313. '\uFCB3': '\u0635\u0645',
  18314. '\uFCB4': '\u0636\u062C',
  18315. '\uFCB5': '\u0636\u062D',
  18316. '\uFCB6': '\u0636\u062E',
  18317. '\uFCB7': '\u0636\u0645',
  18318. '\uFCB8': '\u0637\u062D',
  18319. '\uFCB9': '\u0638\u0645',
  18320. '\uFCBA': '\u0639\u062C',
  18321. '\uFCBB': '\u0639\u0645',
  18322. '\uFCBC': '\u063A\u062C',
  18323. '\uFCBD': '\u063A\u0645',
  18324. '\uFCBE': '\u0641\u062C',
  18325. '\uFCBF': '\u0641\u062D',
  18326. '\uFCC0': '\u0641\u062E',
  18327. '\uFCC1': '\u0641\u0645',
  18328. '\uFCC2': '\u0642\u062D',
  18329. '\uFCC3': '\u0642\u0645',
  18330. '\uFCC4': '\u0643\u062C',
  18331. '\uFCC5': '\u0643\u062D',
  18332. '\uFCC6': '\u0643\u062E',
  18333. '\uFCC7': '\u0643\u0644',
  18334. '\uFCC8': '\u0643\u0645',
  18335. '\uFCC9': '\u0644\u062C',
  18336. '\uFCCA': '\u0644\u062D',
  18337. '\uFCCB': '\u0644\u062E',
  18338. '\uFCCC': '\u0644\u0645',
  18339. '\uFCCD': '\u0644\u0647',
  18340. '\uFCCE': '\u0645\u062C',
  18341. '\uFCCF': '\u0645\u062D',
  18342. '\uFCD0': '\u0645\u062E',
  18343. '\uFCD1': '\u0645\u0645',
  18344. '\uFCD2': '\u0646\u062C',
  18345. '\uFCD3': '\u0646\u062D',
  18346. '\uFCD4': '\u0646\u062E',
  18347. '\uFCD5': '\u0646\u0645',
  18348. '\uFCD6': '\u0646\u0647',
  18349. '\uFCD7': '\u0647\u062C',
  18350. '\uFCD8': '\u0647\u0645',
  18351. '\uFCD9': '\u0647\u0670',
  18352. '\uFCDA': '\u064A\u062C',
  18353. '\uFCDB': '\u064A\u062D',
  18354. '\uFCDC': '\u064A\u062E',
  18355. '\uFCDD': '\u064A\u0645',
  18356. '\uFCDE': '\u064A\u0647',
  18357. '\uFCDF': '\u0626\u0645',
  18358. '\uFCE0': '\u0626\u0647',
  18359. '\uFCE1': '\u0628\u0645',
  18360. '\uFCE2': '\u0628\u0647',
  18361. '\uFCE3': '\u062A\u0645',
  18362. '\uFCE4': '\u062A\u0647',
  18363. '\uFCE5': '\u062B\u0645',
  18364. '\uFCE6': '\u062B\u0647',
  18365. '\uFCE7': '\u0633\u0645',
  18366. '\uFCE8': '\u0633\u0647',
  18367. '\uFCE9': '\u0634\u0645',
  18368. '\uFCEA': '\u0634\u0647',
  18369. '\uFCEB': '\u0643\u0644',
  18370. '\uFCEC': '\u0643\u0645',
  18371. '\uFCED': '\u0644\u0645',
  18372. '\uFCEE': '\u0646\u0645',
  18373. '\uFCEF': '\u0646\u0647',
  18374. '\uFCF0': '\u064A\u0645',
  18375. '\uFCF1': '\u064A\u0647',
  18376. '\uFCF2': '\u0640\u064E\u0651',
  18377. '\uFCF3': '\u0640\u064F\u0651',
  18378. '\uFCF4': '\u0640\u0650\u0651',
  18379. '\uFCF5': '\u0637\u0649',
  18380. '\uFCF6': '\u0637\u064A',
  18381. '\uFCF7': '\u0639\u0649',
  18382. '\uFCF8': '\u0639\u064A',
  18383. '\uFCF9': '\u063A\u0649',
  18384. '\uFCFA': '\u063A\u064A',
  18385. '\uFCFB': '\u0633\u0649',
  18386. '\uFCFC': '\u0633\u064A',
  18387. '\uFCFD': '\u0634\u0649',
  18388. '\uFCFE': '\u0634\u064A',
  18389. '\uFCFF': '\u062D\u0649',
  18390. '\uFD00': '\u062D\u064A',
  18391. '\uFD01': '\u062C\u0649',
  18392. '\uFD02': '\u062C\u064A',
  18393. '\uFD03': '\u062E\u0649',
  18394. '\uFD04': '\u062E\u064A',
  18395. '\uFD05': '\u0635\u0649',
  18396. '\uFD06': '\u0635\u064A',
  18397. '\uFD07': '\u0636\u0649',
  18398. '\uFD08': '\u0636\u064A',
  18399. '\uFD09': '\u0634\u062C',
  18400. '\uFD0A': '\u0634\u062D',
  18401. '\uFD0B': '\u0634\u062E',
  18402. '\uFD0C': '\u0634\u0645',
  18403. '\uFD0D': '\u0634\u0631',
  18404. '\uFD0E': '\u0633\u0631',
  18405. '\uFD0F': '\u0635\u0631',
  18406. '\uFD10': '\u0636\u0631',
  18407. '\uFD11': '\u0637\u0649',
  18408. '\uFD12': '\u0637\u064A',
  18409. '\uFD13': '\u0639\u0649',
  18410. '\uFD14': '\u0639\u064A',
  18411. '\uFD15': '\u063A\u0649',
  18412. '\uFD16': '\u063A\u064A',
  18413. '\uFD17': '\u0633\u0649',
  18414. '\uFD18': '\u0633\u064A',
  18415. '\uFD19': '\u0634\u0649',
  18416. '\uFD1A': '\u0634\u064A',
  18417. '\uFD1B': '\u062D\u0649',
  18418. '\uFD1C': '\u062D\u064A',
  18419. '\uFD1D': '\u062C\u0649',
  18420. '\uFD1E': '\u062C\u064A',
  18421. '\uFD1F': '\u062E\u0649',
  18422. '\uFD20': '\u062E\u064A',
  18423. '\uFD21': '\u0635\u0649',
  18424. '\uFD22': '\u0635\u064A',
  18425. '\uFD23': '\u0636\u0649',
  18426. '\uFD24': '\u0636\u064A',
  18427. '\uFD25': '\u0634\u062C',
  18428. '\uFD26': '\u0634\u062D',
  18429. '\uFD27': '\u0634\u062E',
  18430. '\uFD28': '\u0634\u0645',
  18431. '\uFD29': '\u0634\u0631',
  18432. '\uFD2A': '\u0633\u0631',
  18433. '\uFD2B': '\u0635\u0631',
  18434. '\uFD2C': '\u0636\u0631',
  18435. '\uFD2D': '\u0634\u062C',
  18436. '\uFD2E': '\u0634\u062D',
  18437. '\uFD2F': '\u0634\u062E',
  18438. '\uFD30': '\u0634\u0645',
  18439. '\uFD31': '\u0633\u0647',
  18440. '\uFD32': '\u0634\u0647',
  18441. '\uFD33': '\u0637\u0645',
  18442. '\uFD34': '\u0633\u062C',
  18443. '\uFD35': '\u0633\u062D',
  18444. '\uFD36': '\u0633\u062E',
  18445. '\uFD37': '\u0634\u062C',
  18446. '\uFD38': '\u0634\u062D',
  18447. '\uFD39': '\u0634\u062E',
  18448. '\uFD3A': '\u0637\u0645',
  18449. '\uFD3B': '\u0638\u0645',
  18450. '\uFD3C': '\u0627\u064B',
  18451. '\uFD3D': '\u0627\u064B',
  18452. '\uFD50': '\u062A\u062C\u0645',
  18453. '\uFD51': '\u062A\u062D\u062C',
  18454. '\uFD52': '\u062A\u062D\u062C',
  18455. '\uFD53': '\u062A\u062D\u0645',
  18456. '\uFD54': '\u062A\u062E\u0645',
  18457. '\uFD55': '\u062A\u0645\u062C',
  18458. '\uFD56': '\u062A\u0645\u062D',
  18459. '\uFD57': '\u062A\u0645\u062E',
  18460. '\uFD58': '\u062C\u0645\u062D',
  18461. '\uFD59': '\u062C\u0645\u062D',
  18462. '\uFD5A': '\u062D\u0645\u064A',
  18463. '\uFD5B': '\u062D\u0645\u0649',
  18464. '\uFD5C': '\u0633\u062D\u062C',
  18465. '\uFD5D': '\u0633\u062C\u062D',
  18466. '\uFD5E': '\u0633\u062C\u0649',
  18467. '\uFD5F': '\u0633\u0645\u062D',
  18468. '\uFD60': '\u0633\u0645\u062D',
  18469. '\uFD61': '\u0633\u0645\u062C',
  18470. '\uFD62': '\u0633\u0645\u0645',
  18471. '\uFD63': '\u0633\u0645\u0645',
  18472. '\uFD64': '\u0635\u062D\u062D',
  18473. '\uFD65': '\u0635\u062D\u062D',
  18474. '\uFD66': '\u0635\u0645\u0645',
  18475. '\uFD67': '\u0634\u062D\u0645',
  18476. '\uFD68': '\u0634\u062D\u0645',
  18477. '\uFD69': '\u0634\u062C\u064A',
  18478. '\uFD6A': '\u0634\u0645\u062E',
  18479. '\uFD6B': '\u0634\u0645\u062E',
  18480. '\uFD6C': '\u0634\u0645\u0645',
  18481. '\uFD6D': '\u0634\u0645\u0645',
  18482. '\uFD6E': '\u0636\u062D\u0649',
  18483. '\uFD6F': '\u0636\u062E\u0645',
  18484. '\uFD70': '\u0636\u062E\u0645',
  18485. '\uFD71': '\u0637\u0645\u062D',
  18486. '\uFD72': '\u0637\u0645\u062D',
  18487. '\uFD73': '\u0637\u0645\u0645',
  18488. '\uFD74': '\u0637\u0645\u064A',
  18489. '\uFD75': '\u0639\u062C\u0645',
  18490. '\uFD76': '\u0639\u0645\u0645',
  18491. '\uFD77': '\u0639\u0645\u0645',
  18492. '\uFD78': '\u0639\u0645\u0649',
  18493. '\uFD79': '\u063A\u0645\u0645',
  18494. '\uFD7A': '\u063A\u0645\u064A',
  18495. '\uFD7B': '\u063A\u0645\u0649',
  18496. '\uFD7C': '\u0641\u062E\u0645',
  18497. '\uFD7D': '\u0641\u062E\u0645',
  18498. '\uFD7E': '\u0642\u0645\u062D',
  18499. '\uFD7F': '\u0642\u0645\u0645',
  18500. '\uFD80': '\u0644\u062D\u0645',
  18501. '\uFD81': '\u0644\u062D\u064A',
  18502. '\uFD82': '\u0644\u062D\u0649',
  18503. '\uFD83': '\u0644\u062C\u062C',
  18504. '\uFD84': '\u0644\u062C\u062C',
  18505. '\uFD85': '\u0644\u062E\u0645',
  18506. '\uFD86': '\u0644\u062E\u0645',
  18507. '\uFD87': '\u0644\u0645\u062D',
  18508. '\uFD88': '\u0644\u0645\u062D',
  18509. '\uFD89': '\u0645\u062D\u062C',
  18510. '\uFD8A': '\u0645\u062D\u0645',
  18511. '\uFD8B': '\u0645\u062D\u064A',
  18512. '\uFD8C': '\u0645\u062C\u062D',
  18513. '\uFD8D': '\u0645\u062C\u0645',
  18514. '\uFD8E': '\u0645\u062E\u062C',
  18515. '\uFD8F': '\u0645\u062E\u0645',
  18516. '\uFD92': '\u0645\u062C\u062E',
  18517. '\uFD93': '\u0647\u0645\u062C',
  18518. '\uFD94': '\u0647\u0645\u0645',
  18519. '\uFD95': '\u0646\u062D\u0645',
  18520. '\uFD96': '\u0646\u062D\u0649',
  18521. '\uFD97': '\u0646\u062C\u0645',
  18522. '\uFD98': '\u0646\u062C\u0645',
  18523. '\uFD99': '\u0646\u062C\u0649',
  18524. '\uFD9A': '\u0646\u0645\u064A',
  18525. '\uFD9B': '\u0646\u0645\u0649',
  18526. '\uFD9C': '\u064A\u0645\u0645',
  18527. '\uFD9D': '\u064A\u0645\u0645',
  18528. '\uFD9E': '\u0628\u062E\u064A',
  18529. '\uFD9F': '\u062A\u062C\u064A',
  18530. '\uFDA0': '\u062A\u062C\u0649',
  18531. '\uFDA1': '\u062A\u062E\u064A',
  18532. '\uFDA2': '\u062A\u062E\u0649',
  18533. '\uFDA3': '\u062A\u0645\u064A',
  18534. '\uFDA4': '\u062A\u0645\u0649',
  18535. '\uFDA5': '\u062C\u0645\u064A',
  18536. '\uFDA6': '\u062C\u062D\u0649',
  18537. '\uFDA7': '\u062C\u0645\u0649',
  18538. '\uFDA8': '\u0633\u062E\u0649',
  18539. '\uFDA9': '\u0635\u062D\u064A',
  18540. '\uFDAA': '\u0634\u062D\u064A',
  18541. '\uFDAB': '\u0636\u062D\u064A',
  18542. '\uFDAC': '\u0644\u062C\u064A',
  18543. '\uFDAD': '\u0644\u0645\u064A',
  18544. '\uFDAE': '\u064A\u062D\u064A',
  18545. '\uFDAF': '\u064A\u062C\u064A',
  18546. '\uFDB0': '\u064A\u0645\u064A',
  18547. '\uFDB1': '\u0645\u0645\u064A',
  18548. '\uFDB2': '\u0642\u0645\u064A',
  18549. '\uFDB3': '\u0646\u062D\u064A',
  18550. '\uFDB4': '\u0642\u0645\u062D',
  18551. '\uFDB5': '\u0644\u062D\u0645',
  18552. '\uFDB6': '\u0639\u0645\u064A',
  18553. '\uFDB7': '\u0643\u0645\u064A',
  18554. '\uFDB8': '\u0646\u062C\u062D',
  18555. '\uFDB9': '\u0645\u062E\u064A',
  18556. '\uFDBA': '\u0644\u062C\u0645',
  18557. '\uFDBB': '\u0643\u0645\u0645',
  18558. '\uFDBC': '\u0644\u062C\u0645',
  18559. '\uFDBD': '\u0646\u062C\u062D',
  18560. '\uFDBE': '\u062C\u062D\u064A',
  18561. '\uFDBF': '\u062D\u062C\u064A',
  18562. '\uFDC0': '\u0645\u062C\u064A',
  18563. '\uFDC1': '\u0641\u0645\u064A',
  18564. '\uFDC2': '\u0628\u062D\u064A',
  18565. '\uFDC3': '\u0643\u0645\u0645',
  18566. '\uFDC4': '\u0639\u062C\u0645',
  18567. '\uFDC5': '\u0635\u0645\u0645',
  18568. '\uFDC6': '\u0633\u062E\u064A',
  18569. '\uFDC7': '\u0646\u062C\u064A',
  18570. '\uFE49': '\u203E',
  18571. '\uFE4A': '\u203E',
  18572. '\uFE4B': '\u203E',
  18573. '\uFE4C': '\u203E',
  18574. '\uFE4D': '\u005F',
  18575. '\uFE4E': '\u005F',
  18576. '\uFE4F': '\u005F',
  18577. '\uFE80': '\u0621',
  18578. '\uFE81': '\u0622',
  18579. '\uFE82': '\u0622',
  18580. '\uFE83': '\u0623',
  18581. '\uFE84': '\u0623',
  18582. '\uFE85': '\u0624',
  18583. '\uFE86': '\u0624',
  18584. '\uFE87': '\u0625',
  18585. '\uFE88': '\u0625',
  18586. '\uFE89': '\u0626',
  18587. '\uFE8A': '\u0626',
  18588. '\uFE8B': '\u0626',
  18589. '\uFE8C': '\u0626',
  18590. '\uFE8D': '\u0627',
  18591. '\uFE8E': '\u0627',
  18592. '\uFE8F': '\u0628',
  18593. '\uFE90': '\u0628',
  18594. '\uFE91': '\u0628',
  18595. '\uFE92': '\u0628',
  18596. '\uFE93': '\u0629',
  18597. '\uFE94': '\u0629',
  18598. '\uFE95': '\u062A',
  18599. '\uFE96': '\u062A',
  18600. '\uFE97': '\u062A',
  18601. '\uFE98': '\u062A',
  18602. '\uFE99': '\u062B',
  18603. '\uFE9A': '\u062B',
  18604. '\uFE9B': '\u062B',
  18605. '\uFE9C': '\u062B',
  18606. '\uFE9D': '\u062C',
  18607. '\uFE9E': '\u062C',
  18608. '\uFE9F': '\u062C',
  18609. '\uFEA0': '\u062C',
  18610. '\uFEA1': '\u062D',
  18611. '\uFEA2': '\u062D',
  18612. '\uFEA3': '\u062D',
  18613. '\uFEA4': '\u062D',
  18614. '\uFEA5': '\u062E',
  18615. '\uFEA6': '\u062E',
  18616. '\uFEA7': '\u062E',
  18617. '\uFEA8': '\u062E',
  18618. '\uFEA9': '\u062F',
  18619. '\uFEAA': '\u062F',
  18620. '\uFEAB': '\u0630',
  18621. '\uFEAC': '\u0630',
  18622. '\uFEAD': '\u0631',
  18623. '\uFEAE': '\u0631',
  18624. '\uFEAF': '\u0632',
  18625. '\uFEB0': '\u0632',
  18626. '\uFEB1': '\u0633',
  18627. '\uFEB2': '\u0633',
  18628. '\uFEB3': '\u0633',
  18629. '\uFEB4': '\u0633',
  18630. '\uFEB5': '\u0634',
  18631. '\uFEB6': '\u0634',
  18632. '\uFEB7': '\u0634',
  18633. '\uFEB8': '\u0634',
  18634. '\uFEB9': '\u0635',
  18635. '\uFEBA': '\u0635',
  18636. '\uFEBB': '\u0635',
  18637. '\uFEBC': '\u0635',
  18638. '\uFEBD': '\u0636',
  18639. '\uFEBE': '\u0636',
  18640. '\uFEBF': '\u0636',
  18641. '\uFEC0': '\u0636',
  18642. '\uFEC1': '\u0637',
  18643. '\uFEC2': '\u0637',
  18644. '\uFEC3': '\u0637',
  18645. '\uFEC4': '\u0637',
  18646. '\uFEC5': '\u0638',
  18647. '\uFEC6': '\u0638',
  18648. '\uFEC7': '\u0638',
  18649. '\uFEC8': '\u0638',
  18650. '\uFEC9': '\u0639',
  18651. '\uFECA': '\u0639',
  18652. '\uFECB': '\u0639',
  18653. '\uFECC': '\u0639',
  18654. '\uFECD': '\u063A',
  18655. '\uFECE': '\u063A',
  18656. '\uFECF': '\u063A',
  18657. '\uFED0': '\u063A',
  18658. '\uFED1': '\u0641',
  18659. '\uFED2': '\u0641',
  18660. '\uFED3': '\u0641',
  18661. '\uFED4': '\u0641',
  18662. '\uFED5': '\u0642',
  18663. '\uFED6': '\u0642',
  18664. '\uFED7': '\u0642',
  18665. '\uFED8': '\u0642',
  18666. '\uFED9': '\u0643',
  18667. '\uFEDA': '\u0643',
  18668. '\uFEDB': '\u0643',
  18669. '\uFEDC': '\u0643',
  18670. '\uFEDD': '\u0644',
  18671. '\uFEDE': '\u0644',
  18672. '\uFEDF': '\u0644',
  18673. '\uFEE0': '\u0644',
  18674. '\uFEE1': '\u0645',
  18675. '\uFEE2': '\u0645',
  18676. '\uFEE3': '\u0645',
  18677. '\uFEE4': '\u0645',
  18678. '\uFEE5': '\u0646',
  18679. '\uFEE6': '\u0646',
  18680. '\uFEE7': '\u0646',
  18681. '\uFEE8': '\u0646',
  18682. '\uFEE9': '\u0647',
  18683. '\uFEEA': '\u0647',
  18684. '\uFEEB': '\u0647',
  18685. '\uFEEC': '\u0647',
  18686. '\uFEED': '\u0648',
  18687. '\uFEEE': '\u0648',
  18688. '\uFEEF': '\u0649',
  18689. '\uFEF0': '\u0649',
  18690. '\uFEF1': '\u064A',
  18691. '\uFEF2': '\u064A',
  18692. '\uFEF3': '\u064A',
  18693. '\uFEF4': '\u064A',
  18694. '\uFEF5': '\u0644\u0622',
  18695. '\uFEF6': '\u0644\u0622',
  18696. '\uFEF7': '\u0644\u0623',
  18697. '\uFEF8': '\u0644\u0623',
  18698. '\uFEF9': '\u0644\u0625',
  18699. '\uFEFA': '\u0644\u0625',
  18700. '\uFEFB': '\u0644\u0627',
  18701. '\uFEFC': '\u0644\u0627'
  18702. };
  18703. function reverseIfRtl(chars) {
  18704. var charsLength = chars.length;
  18705. //reverse an arabic ligature
  18706. if (charsLength <= 1 || !isRTLRangeFor(chars.charCodeAt(0))) {
  18707. return chars;
  18708. }
  18709. var s = '';
  18710. for (var ii = charsLength - 1; ii >= 0; ii--) {
  18711. s += chars[ii];
  18712. }
  18713. return s;
  18714. }
  18715. function adjustWidths(properties) {
  18716. if (properties.fontMatrix[0] === FONT_IDENTITY_MATRIX[0]) {
  18717. return;
  18718. }
  18719. // adjusting width to fontMatrix scale
  18720. var scale = 0.001 / properties.fontMatrix[0];
  18721. var glyphsWidths = properties.widths;
  18722. for (var glyph in glyphsWidths) {
  18723. glyphsWidths[glyph] *= scale;
  18724. }
  18725. properties.defaultWidth *= scale;
  18726. }
  18727. function getFontType(type, subtype) {
  18728. switch (type) {
  18729. case 'Type1':
  18730. return subtype === 'Type1C' ? FontType.TYPE1C : FontType.TYPE1;
  18731. case 'CIDFontType0':
  18732. return subtype === 'CIDFontType0C' ? FontType.CIDFONTTYPE0C :
  18733. FontType.CIDFONTTYPE0;
  18734. case 'OpenType':
  18735. return FontType.OPENTYPE;
  18736. case 'TrueType':
  18737. return FontType.TRUETYPE;
  18738. case 'CIDFontType2':
  18739. return FontType.CIDFONTTYPE2;
  18740. case 'MMType1':
  18741. return FontType.MMTYPE1;
  18742. case 'Type0':
  18743. return FontType.TYPE0;
  18744. default:
  18745. return FontType.UNKNOWN;
  18746. }
  18747. }
  18748. var Glyph = (function GlyphClosure() {
  18749. function Glyph(fontChar, unicode, accent, width, vmetric, operatorListId) {
  18750. this.fontChar = fontChar;
  18751. this.unicode = unicode;
  18752. this.accent = accent;
  18753. this.width = width;
  18754. this.vmetric = vmetric;
  18755. this.operatorListId = operatorListId;
  18756. }
  18757. Glyph.prototype.matchesForCache =
  18758. function(fontChar, unicode, accent, width, vmetric, operatorListId) {
  18759. return this.fontChar === fontChar &&
  18760. this.unicode === unicode &&
  18761. this.accent === accent &&
  18762. this.width === width &&
  18763. this.vmetric === vmetric &&
  18764. this.operatorListId === operatorListId;
  18765. };
  18766. return Glyph;
  18767. })();
  18768. /**
  18769. * 'Font' is the class the outside world should use, it encapsulate all the font
  18770. * decoding logics whatever type it is (assuming the font type is supported).
  18771. *
  18772. * For example to read a Type1 font and to attach it to the document:
  18773. * var type1Font = new Font("MyFontName", binaryFile, propertiesObject);
  18774. * type1Font.bind();
  18775. */
  18776. var Font = (function FontClosure() {
  18777. function Font(name, file, properties) {
  18778. var charCode, glyphName;
  18779. this.name = name;
  18780. this.loadedName = properties.loadedName;
  18781. this.isType3Font = properties.isType3Font;
  18782. this.sizes = [];
  18783. this.glyphCache = {};
  18784. var names = name.split('+');
  18785. names = names.length > 1 ? names[1] : names[0];
  18786. names = names.split(/[-,_]/g)[0];
  18787. this.isSerifFont = !!(properties.flags & FontFlags.Serif);
  18788. this.isSymbolicFont = !!(properties.flags & FontFlags.Symbolic);
  18789. this.isMonospace = !!(properties.flags & FontFlags.FixedPitch);
  18790. var type = properties.type;
  18791. var subtype = properties.subtype;
  18792. this.type = type;
  18793. this.fallbackName = (this.isMonospace ? 'monospace' :
  18794. (this.isSerifFont ? 'serif' : 'sans-serif'));
  18795. this.differences = properties.differences;
  18796. this.widths = properties.widths;
  18797. this.defaultWidth = properties.defaultWidth;
  18798. this.composite = properties.composite;
  18799. this.wideChars = properties.wideChars;
  18800. this.cMap = properties.cMap;
  18801. this.ascent = properties.ascent / PDF_GLYPH_SPACE_UNITS;
  18802. this.descent = properties.descent / PDF_GLYPH_SPACE_UNITS;
  18803. this.fontMatrix = properties.fontMatrix;
  18804. var unicode = this.buildToUnicode(properties);
  18805. this.toUnicode = properties.toUnicode = unicode.toUnicode;
  18806. this.isIdentityUnicode = properties.isIdentityUnicode = unicode.isIdentity;
  18807. this.toFontChar = [];
  18808. if (properties.type === 'Type3') {
  18809. for (charCode = 0; charCode < 256; charCode++) {
  18810. this.toFontChar[charCode] = (this.differences[charCode] ||
  18811. properties.defaultEncoding[charCode]);
  18812. }
  18813. this.fontType = FontType.TYPE3;
  18814. return;
  18815. }
  18816. this.cidEncoding = properties.cidEncoding;
  18817. this.vertical = properties.vertical;
  18818. if (this.vertical) {
  18819. this.vmetrics = properties.vmetrics;
  18820. this.defaultVMetrics = properties.defaultVMetrics;
  18821. }
  18822. if (!file || file.isEmpty) {
  18823. if (file) {
  18824. // Some bad PDF generators will include empty font files,
  18825. // attempting to recover by assuming that no file exists.
  18826. warn('Font file is empty in "' + name + '" (' + this.loadedName + ')');
  18827. }
  18828. this.missingFile = true;
  18829. // The file data is not specified. Trying to fix the font name
  18830. // to be used with the canvas.font.
  18831. var fontName = name.replace(/[,_]/g, '-');
  18832. var isStandardFont = fontName in stdFontMap;
  18833. fontName = stdFontMap[fontName] || nonStdFontMap[fontName] || fontName;
  18834. this.bold = (fontName.search(/bold/gi) !== -1);
  18835. this.italic = ((fontName.search(/oblique/gi) !== -1) ||
  18836. (fontName.search(/italic/gi) !== -1));
  18837. // Use 'name' instead of 'fontName' here because the original
  18838. // name ArialBlack for example will be replaced by Helvetica.
  18839. this.black = (name.search(/Black/g) !== -1);
  18840. // if at least one width is present, remeasure all chars when exists
  18841. this.remeasure = Object.keys(this.widths).length > 0;
  18842. if (isStandardFont && type === 'CIDFontType2' &&
  18843. properties.cidEncoding.indexOf('Identity-') === 0) {
  18844. // Standard fonts might be embedded as CID font without glyph mapping.
  18845. // Building one based on GlyphMapForStandardFonts.
  18846. var map = [];
  18847. for (var code in GlyphMapForStandardFonts) {
  18848. map[+code] = GlyphMapForStandardFonts[code];
  18849. }
  18850. this.toFontChar = map;
  18851. this.toUnicode = map;
  18852. } else if (/Symbol/i.test(fontName)) {
  18853. var symbols = Encodings.SymbolSetEncoding;
  18854. for (charCode in symbols) {
  18855. var fontChar = GlyphsUnicode[symbols[charCode]];
  18856. if (!fontChar) {
  18857. continue;
  18858. }
  18859. this.toFontChar[charCode] = fontChar;
  18860. }
  18861. } else if (isStandardFont) {
  18862. this.toFontChar = [];
  18863. for (charCode in properties.defaultEncoding) {
  18864. glyphName = (properties.differences[charCode] ||
  18865. properties.defaultEncoding[charCode]);
  18866. this.toFontChar[charCode] = GlyphsUnicode[glyphName];
  18867. }
  18868. } else {
  18869. var unicodeCharCode, notCidFont = (type.indexOf('CIDFontType') === -1);
  18870. for (charCode in this.toUnicode) {
  18871. unicodeCharCode = this.toUnicode[charCode].charCodeAt(0);
  18872. if (notCidFont) {
  18873. glyphName = (properties.differences[charCode] ||
  18874. properties.defaultEncoding[charCode]);
  18875. unicodeCharCode = (GlyphsUnicode[glyphName] || unicodeCharCode);
  18876. }
  18877. this.toFontChar[charCode] = unicodeCharCode;
  18878. }
  18879. }
  18880. this.loadedName = fontName.split('-')[0];
  18881. this.loading = false;
  18882. this.fontType = getFontType(type, subtype);
  18883. return;
  18884. }
  18885. // Some fonts might use wrong font types for Type1C or CIDFontType0C
  18886. if (subtype === 'Type1C' && (type !== 'Type1' && type !== 'MMType1')) {
  18887. // Some TrueType fonts by mistake claim Type1C
  18888. if (isTrueTypeFile(file)) {
  18889. subtype = 'TrueType';
  18890. } else {
  18891. type = 'Type1';
  18892. }
  18893. }
  18894. if (subtype === 'CIDFontType0C' && type !== 'CIDFontType0') {
  18895. type = 'CIDFontType0';
  18896. }
  18897. // XXX: Temporarily change the type for open type so we trigger a warning.
  18898. // This should be removed when we add support for open type.
  18899. if (subtype === 'OpenType') {
  18900. type = 'OpenType';
  18901. }
  18902. var data;
  18903. switch (type) {
  18904. case 'Type1':
  18905. case 'CIDFontType0':
  18906. this.mimetype = 'font/opentype';
  18907. var cff = (subtype === 'Type1C' || subtype === 'CIDFontType0C') ?
  18908. new CFFFont(file, properties) : new Type1Font(name, file, properties);
  18909. adjustWidths(properties);
  18910. // Wrap the CFF data inside an OTF font file
  18911. data = this.convert(name, cff, properties);
  18912. break;
  18913. case 'OpenType':
  18914. case 'TrueType':
  18915. case 'CIDFontType2':
  18916. this.mimetype = 'font/opentype';
  18917. // Repair the TrueType file. It is can be damaged in the point of
  18918. // view of the sanitizer
  18919. data = this.checkAndRepair(name, file, properties);
  18920. if (this.isOpenType) {
  18921. type = 'OpenType';
  18922. }
  18923. break;
  18924. default:
  18925. error('Font ' + type + ' is not supported');
  18926. break;
  18927. }
  18928. this.data = data;
  18929. this.fontType = getFontType(type, subtype);
  18930. // Transfer some properties again that could change during font conversion
  18931. this.fontMatrix = properties.fontMatrix;
  18932. this.widths = properties.widths;
  18933. this.defaultWidth = properties.defaultWidth;
  18934. this.encoding = properties.baseEncoding;
  18935. this.seacMap = properties.seacMap;
  18936. this.loading = true;
  18937. }
  18938. Font.getFontID = (function () {
  18939. var ID = 1;
  18940. return function Font_getFontID() {
  18941. return String(ID++);
  18942. };
  18943. })();
  18944. function int16(b0, b1) {
  18945. return (b0 << 8) + b1;
  18946. }
  18947. function int32(b0, b1, b2, b3) {
  18948. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  18949. }
  18950. function getMaxPower2(number) {
  18951. var maxPower = 0;
  18952. var value = number;
  18953. while (value >= 2) {
  18954. value /= 2;
  18955. maxPower++;
  18956. }
  18957. value = 2;
  18958. for (var i = 1; i < maxPower; i++) {
  18959. value *= 2;
  18960. }
  18961. return value;
  18962. }
  18963. function string16(value) {
  18964. return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
  18965. }
  18966. function safeString16(value) {
  18967. // clamp value to the 16-bit int range
  18968. value = (value > 0x7FFF ? 0x7FFF : (value < -0x8000 ? -0x8000 : value));
  18969. return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
  18970. }
  18971. function createOpenTypeHeader(sfnt, file, numTables) {
  18972. // Windows hates the Mac TrueType sfnt version number
  18973. if (sfnt === 'true') {
  18974. sfnt = string32(0x00010000);
  18975. }
  18976. // sfnt version (4 bytes)
  18977. var header = sfnt;
  18978. // numTables (2 bytes)
  18979. header += string16(numTables);
  18980. // searchRange (2 bytes)
  18981. var tablesMaxPower2 = getMaxPower2(numTables);
  18982. var searchRange = tablesMaxPower2 * 16;
  18983. header += string16(searchRange);
  18984. // entrySelector (2 bytes)
  18985. header += string16(Math.log(tablesMaxPower2) / Math.log(2));
  18986. // rangeShift (2 bytes)
  18987. header += string16(numTables * 16 - searchRange);
  18988. file.file += header;
  18989. file.virtualOffset += header.length;
  18990. }
  18991. function createTableEntry(file, tag, data) {
  18992. // offset
  18993. var offset = file.virtualOffset;
  18994. // length
  18995. var length = data.length;
  18996. // Per spec tables must be 4-bytes align so add padding as needed.
  18997. var paddedLength = length;
  18998. while (paddedLength & 3) {
  18999. paddedLength++;
  19000. }
  19001. var i;
  19002. var padding = paddedLength - length;
  19003. if (padding !== 0) {
  19004. // Padding is required. |data| can be an Array, Uint8Array, or
  19005. // Uint16Array. In the latter two cases we need to create slightly larger
  19006. // typed arrays and copy the old contents in. Fortunately that's not a
  19007. // common case.
  19008. var data2;
  19009. if (data instanceof Array) {
  19010. for (i = 0; i < padding; i++) {
  19011. data.push(0);
  19012. }
  19013. } else if (data instanceof Uint8Array) {
  19014. data2 = new Uint8Array(paddedLength);
  19015. data2.set(data);
  19016. data = data2;
  19017. } else if (data instanceof Uint16Array) {
  19018. data2 = new Uint16Array(paddedLength);
  19019. data2.set(data);
  19020. data = data2;
  19021. } else {
  19022. error('bad array kind in createTableEntry');
  19023. }
  19024. }
  19025. while (file.virtualOffset & 3) {
  19026. file.virtualOffset++;
  19027. }
  19028. // checksum
  19029. var checksum = 0, n = data.length;
  19030. for (i = 0; i < n; i += 4) {
  19031. checksum = (checksum + int32(data[i], data[i + 1], data[i + 2],
  19032. data[i + 3])) | 0;
  19033. }
  19034. var tableEntry = (tag + string32(checksum) +
  19035. string32(offset) + string32(length));
  19036. file.file += tableEntry;
  19037. file.virtualOffset += data.length;
  19038. return data;
  19039. }
  19040. function isTrueTypeFile(file) {
  19041. var header = file.peekBytes(4);
  19042. return readUint32(header, 0) === 0x00010000;
  19043. }
  19044. /**
  19045. * Rebuilds the char code to glyph ID map by trying to replace the char codes
  19046. * with their unicode value. It also moves char codes that are in known
  19047. * problematic locations.
  19048. * @return {Object} Two properties:
  19049. * 'toFontChar' - maps original char codes(the value that will be read
  19050. * from commands such as show text) to the char codes that will be used in the
  19051. * font that we build
  19052. * 'charCodeToGlyphId' - maps the new font char codes to glyph ids
  19053. */
  19054. function adjustMapping(charCodeToGlyphId, properties) {
  19055. var toUnicode = properties.toUnicode;
  19056. var isSymbolic = !!(properties.flags & FontFlags.Symbolic);
  19057. var isIdentityUnicode = properties.isIdentityUnicode;
  19058. var isCidFontType2 = (properties.type === 'CIDFontType2');
  19059. var newMap = Object.create(null);
  19060. var toFontChar = [];
  19061. var usedFontCharCodes = [];
  19062. var nextAvailableFontCharCode = PRIVATE_USE_OFFSET_START;
  19063. for (var originalCharCode in charCodeToGlyphId) {
  19064. originalCharCode |= 0;
  19065. var glyphId = charCodeToGlyphId[originalCharCode];
  19066. var fontCharCode = originalCharCode;
  19067. // First try to map the value to a unicode position if a non identity map
  19068. // was created.
  19069. if (!isIdentityUnicode) {
  19070. if (toUnicode[originalCharCode] !== undefined) {
  19071. var unicode = toUnicode[fontCharCode];
  19072. // TODO: Try to map ligatures to the correct spot.
  19073. if (unicode.length === 1) {
  19074. fontCharCode = unicode.charCodeAt(0);
  19075. }
  19076. } else if (isCidFontType2) {
  19077. // For CIDFontType2, move characters not present in toUnicode
  19078. // to the private use area (fixes bug 1028735 and issue 4881).
  19079. fontCharCode = nextAvailableFontCharCode;
  19080. }
  19081. }
  19082. // Try to move control characters, special characters and already mapped
  19083. // characters to the private use area since they will not be drawn by
  19084. // canvas if left in their current position. Also, move characters if the
  19085. // font was symbolic and there is only an identity unicode map since the
  19086. // characters probably aren't in the correct position (fixes an issue
  19087. // with firefox and thuluthfont).
  19088. if ((usedFontCharCodes[fontCharCode] !== undefined ||
  19089. fontCharCode <= 0x1f || // Control chars
  19090. fontCharCode === 0x7F || // Control char
  19091. fontCharCode === 0xAD || // Soft hyphen
  19092. (fontCharCode >= 0x80 && fontCharCode <= 0x9F) || // Control chars
  19093. // Prevent drawing characters in the specials unicode block.
  19094. (fontCharCode >= 0xFFF0 && fontCharCode <= 0xFFFF) ||
  19095. (isSymbolic && isIdentityUnicode)) &&
  19096. nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END) { // Room left.
  19097. // Loop to try and find a free spot in the private use area.
  19098. do {
  19099. fontCharCode = nextAvailableFontCharCode++;
  19100. if (SKIP_PRIVATE_USE_RANGE_F000_TO_F01F && fontCharCode === 0xF000) {
  19101. fontCharCode = 0xF020;
  19102. nextAvailableFontCharCode = fontCharCode + 1;
  19103. }
  19104. } while (usedFontCharCodes[fontCharCode] !== undefined &&
  19105. nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END);
  19106. }
  19107. newMap[fontCharCode] = glyphId;
  19108. toFontChar[originalCharCode] = fontCharCode;
  19109. usedFontCharCodes[fontCharCode] = true;
  19110. }
  19111. return {
  19112. toFontChar: toFontChar,
  19113. charCodeToGlyphId: newMap,
  19114. nextAvailableFontCharCode: nextAvailableFontCharCode
  19115. };
  19116. }
  19117. function getRanges(glyphs) {
  19118. // Array.sort() sorts by characters, not numerically, so convert to an
  19119. // array of characters.
  19120. var codes = [];
  19121. for (var charCode in glyphs) {
  19122. codes.push({ fontCharCode: charCode | 0, glyphId: glyphs[charCode] });
  19123. }
  19124. codes.sort(function fontGetRangesSort(a, b) {
  19125. return a.fontCharCode - b.fontCharCode;
  19126. });
  19127. // Split the sorted codes into ranges.
  19128. var ranges = [];
  19129. var length = codes.length;
  19130. for (var n = 0; n < length; ) {
  19131. var start = codes[n].fontCharCode;
  19132. var codeIndices = [codes[n].glyphId];
  19133. ++n;
  19134. var end = start;
  19135. while (n < length && end + 1 === codes[n].fontCharCode) {
  19136. codeIndices.push(codes[n].glyphId);
  19137. ++end;
  19138. ++n;
  19139. if (end === 0xFFFF) {
  19140. break;
  19141. }
  19142. }
  19143. ranges.push([start, end, codeIndices]);
  19144. }
  19145. return ranges;
  19146. }
  19147. function createCmapTable(glyphs) {
  19148. var ranges = getRanges(glyphs);
  19149. var numTables = ranges[ranges.length - 1][1] > 0xFFFF ? 2 : 1;
  19150. var cmap = '\x00\x00' + // version
  19151. string16(numTables) + // numTables
  19152. '\x00\x03' + // platformID
  19153. '\x00\x01' + // encodingID
  19154. string32(4 + numTables * 8); // start of the table record
  19155. var i, ii, j, jj;
  19156. for (i = ranges.length - 1; i >= 0; --i) {
  19157. if (ranges[i][0] <= 0xFFFF) { break; }
  19158. }
  19159. var bmpLength = i + 1;
  19160. if (ranges[i][0] < 0xFFFF && ranges[i][1] === 0xFFFF) {
  19161. ranges[i][1] = 0xFFFE;
  19162. }
  19163. var trailingRangesCount = ranges[i][1] < 0xFFFF ? 1 : 0;
  19164. var segCount = bmpLength + trailingRangesCount;
  19165. var segCount2 = segCount * 2;
  19166. var searchRange = getMaxPower2(segCount) * 2;
  19167. var searchEntry = Math.log(segCount) / Math.log(2);
  19168. var rangeShift = 2 * segCount - searchRange;
  19169. // Fill up the 4 parallel arrays describing the segments.
  19170. var startCount = '';
  19171. var endCount = '';
  19172. var idDeltas = '';
  19173. var idRangeOffsets = '';
  19174. var glyphsIds = '';
  19175. var bias = 0;
  19176. var range, start, end, codes;
  19177. for (i = 0, ii = bmpLength; i < ii; i++) {
  19178. range = ranges[i];
  19179. start = range[0];
  19180. end = range[1];
  19181. startCount += string16(start);
  19182. endCount += string16(end);
  19183. codes = range[2];
  19184. var contiguous = true;
  19185. for (j = 1, jj = codes.length; j < jj; ++j) {
  19186. if (codes[j] !== codes[j - 1] + 1) {
  19187. contiguous = false;
  19188. break;
  19189. }
  19190. }
  19191. if (!contiguous) {
  19192. var offset = (segCount - i) * 2 + bias * 2;
  19193. bias += (end - start + 1);
  19194. idDeltas += string16(0);
  19195. idRangeOffsets += string16(offset);
  19196. for (j = 0, jj = codes.length; j < jj; ++j) {
  19197. glyphsIds += string16(codes[j]);
  19198. }
  19199. } else {
  19200. var startCode = codes[0];
  19201. idDeltas += string16((startCode - start) & 0xFFFF);
  19202. idRangeOffsets += string16(0);
  19203. }
  19204. }
  19205. if (trailingRangesCount > 0) {
  19206. endCount += '\xFF\xFF';
  19207. startCount += '\xFF\xFF';
  19208. idDeltas += '\x00\x01';
  19209. idRangeOffsets += '\x00\x00';
  19210. }
  19211. var format314 = '\x00\x00' + // language
  19212. string16(segCount2) +
  19213. string16(searchRange) +
  19214. string16(searchEntry) +
  19215. string16(rangeShift) +
  19216. endCount + '\x00\x00' + startCount +
  19217. idDeltas + idRangeOffsets + glyphsIds;
  19218. var format31012 = '';
  19219. var header31012 = '';
  19220. if (numTables > 1) {
  19221. cmap += '\x00\x03' + // platformID
  19222. '\x00\x0A' + // encodingID
  19223. string32(4 + numTables * 8 +
  19224. 4 + format314.length); // start of the table record
  19225. format31012 = '';
  19226. for (i = 0, ii = ranges.length; i < ii; i++) {
  19227. range = ranges[i];
  19228. start = range[0];
  19229. codes = range[2];
  19230. var code = codes[0];
  19231. for (j = 1, jj = codes.length; j < jj; ++j) {
  19232. if (codes[j] !== codes[j - 1] + 1) {
  19233. end = range[0] + j - 1;
  19234. format31012 += string32(start) + // startCharCode
  19235. string32(end) + // endCharCode
  19236. string32(code); // startGlyphID
  19237. start = end + 1;
  19238. code = codes[j];
  19239. }
  19240. }
  19241. format31012 += string32(start) + // startCharCode
  19242. string32(range[1]) + // endCharCode
  19243. string32(code); // startGlyphID
  19244. }
  19245. header31012 = '\x00\x0C' + // format
  19246. '\x00\x00' + // reserved
  19247. string32(format31012.length + 16) + // length
  19248. '\x00\x00\x00\x00' + // language
  19249. string32(format31012.length / 12); // nGroups
  19250. }
  19251. return stringToArray(cmap +
  19252. '\x00\x04' + // format
  19253. string16(format314.length + 4) + // length
  19254. format314 + header31012 + format31012);
  19255. }
  19256. function validateOS2Table(os2) {
  19257. var stream = new Stream(os2.data);
  19258. var version = stream.getUint16();
  19259. // TODO verify all OS/2 tables fields, but currently we validate only those
  19260. // that give us issues
  19261. stream.getBytes(60); // skipping type, misc sizes, panose, unicode ranges
  19262. var selection = stream.getUint16();
  19263. if (version < 4 && (selection & 0x0300)) {
  19264. return false;
  19265. }
  19266. var firstChar = stream.getUint16();
  19267. var lastChar = stream.getUint16();
  19268. if (firstChar > lastChar) {
  19269. return false;
  19270. }
  19271. stream.getBytes(6); // skipping sTypoAscender/Descender/LineGap
  19272. var usWinAscent = stream.getUint16();
  19273. if (usWinAscent === 0) { // makes font unreadable by windows
  19274. return false;
  19275. }
  19276. // OS/2 appears to be valid, resetting some fields
  19277. os2.data[8] = os2.data[9] = 0; // IE rejects fonts if fsType != 0
  19278. return true;
  19279. }
  19280. function createOS2Table(properties, charstrings, override) {
  19281. override = override || {
  19282. unitsPerEm: 0,
  19283. yMax: 0,
  19284. yMin: 0,
  19285. ascent: 0,
  19286. descent: 0
  19287. };
  19288. var ulUnicodeRange1 = 0;
  19289. var ulUnicodeRange2 = 0;
  19290. var ulUnicodeRange3 = 0;
  19291. var ulUnicodeRange4 = 0;
  19292. var firstCharIndex = null;
  19293. var lastCharIndex = 0;
  19294. if (charstrings) {
  19295. for (var code in charstrings) {
  19296. code |= 0;
  19297. if (firstCharIndex > code || !firstCharIndex) {
  19298. firstCharIndex = code;
  19299. }
  19300. if (lastCharIndex < code) {
  19301. lastCharIndex = code;
  19302. }
  19303. var position = getUnicodeRangeFor(code);
  19304. if (position < 32) {
  19305. ulUnicodeRange1 |= 1 << position;
  19306. } else if (position < 64) {
  19307. ulUnicodeRange2 |= 1 << position - 32;
  19308. } else if (position < 96) {
  19309. ulUnicodeRange3 |= 1 << position - 64;
  19310. } else if (position < 123) {
  19311. ulUnicodeRange4 |= 1 << position - 96;
  19312. } else {
  19313. error('Unicode ranges Bits > 123 are reserved for internal usage');
  19314. }
  19315. }
  19316. } else {
  19317. // TODO
  19318. firstCharIndex = 0;
  19319. lastCharIndex = 255;
  19320. }
  19321. var bbox = properties.bbox || [0, 0, 0, 0];
  19322. var unitsPerEm = (override.unitsPerEm ||
  19323. 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0]);
  19324. // if the font units differ to the PDF glyph space units
  19325. // then scale up the values
  19326. var scale = (properties.ascentScaled ? 1.0 :
  19327. unitsPerEm / PDF_GLYPH_SPACE_UNITS);
  19328. var typoAscent = (override.ascent ||
  19329. Math.round(scale * (properties.ascent || bbox[3])));
  19330. var typoDescent = (override.descent ||
  19331. Math.round(scale * (properties.descent || bbox[1])));
  19332. if (typoDescent > 0 && properties.descent > 0 && bbox[1] < 0) {
  19333. typoDescent = -typoDescent; // fixing incorrect descent
  19334. }
  19335. var winAscent = override.yMax || typoAscent;
  19336. var winDescent = -override.yMin || -typoDescent;
  19337. return '\x00\x03' + // version
  19338. '\x02\x24' + // xAvgCharWidth
  19339. '\x01\xF4' + // usWeightClass
  19340. '\x00\x05' + // usWidthClass
  19341. '\x00\x00' + // fstype (0 to let the font loads via font-face on IE)
  19342. '\x02\x8A' + // ySubscriptXSize
  19343. '\x02\xBB' + // ySubscriptYSize
  19344. '\x00\x00' + // ySubscriptXOffset
  19345. '\x00\x8C' + // ySubscriptYOffset
  19346. '\x02\x8A' + // ySuperScriptXSize
  19347. '\x02\xBB' + // ySuperScriptYSize
  19348. '\x00\x00' + // ySuperScriptXOffset
  19349. '\x01\xDF' + // ySuperScriptYOffset
  19350. '\x00\x31' + // yStrikeOutSize
  19351. '\x01\x02' + // yStrikeOutPosition
  19352. '\x00\x00' + // sFamilyClass
  19353. '\x00\x00\x06' +
  19354. String.fromCharCode(properties.fixedPitch ? 0x09 : 0x00) +
  19355. '\x00\x00\x00\x00\x00\x00' + // Panose
  19356. string32(ulUnicodeRange1) + // ulUnicodeRange1 (Bits 0-31)
  19357. string32(ulUnicodeRange2) + // ulUnicodeRange2 (Bits 32-63)
  19358. string32(ulUnicodeRange3) + // ulUnicodeRange3 (Bits 64-95)
  19359. string32(ulUnicodeRange4) + // ulUnicodeRange4 (Bits 96-127)
  19360. '\x2A\x32\x31\x2A' + // achVendID
  19361. string16(properties.italicAngle ? 1 : 0) + // fsSelection
  19362. string16(firstCharIndex ||
  19363. properties.firstChar) + // usFirstCharIndex
  19364. string16(lastCharIndex || properties.lastChar) + // usLastCharIndex
  19365. string16(typoAscent) + // sTypoAscender
  19366. string16(typoDescent) + // sTypoDescender
  19367. '\x00\x64' + // sTypoLineGap (7%-10% of the unitsPerEM value)
  19368. string16(winAscent) + // usWinAscent
  19369. string16(winDescent) + // usWinDescent
  19370. '\x00\x00\x00\x00' + // ulCodePageRange1 (Bits 0-31)
  19371. '\x00\x00\x00\x00' + // ulCodePageRange2 (Bits 32-63)
  19372. string16(properties.xHeight) + // sxHeight
  19373. string16(properties.capHeight) + // sCapHeight
  19374. string16(0) + // usDefaultChar
  19375. string16(firstCharIndex || properties.firstChar) + // usBreakChar
  19376. '\x00\x03'; // usMaxContext
  19377. }
  19378. function createPostTable(properties) {
  19379. var angle = Math.floor(properties.italicAngle * (Math.pow(2, 16)));
  19380. return ('\x00\x03\x00\x00' + // Version number
  19381. string32(angle) + // italicAngle
  19382. '\x00\x00' + // underlinePosition
  19383. '\x00\x00' + // underlineThickness
  19384. string32(properties.fixedPitch) + // isFixedPitch
  19385. '\x00\x00\x00\x00' + // minMemType42
  19386. '\x00\x00\x00\x00' + // maxMemType42
  19387. '\x00\x00\x00\x00' + // minMemType1
  19388. '\x00\x00\x00\x00'); // maxMemType1
  19389. }
  19390. function createNameTable(name, proto) {
  19391. if (!proto) {
  19392. proto = [[], []]; // no strings and unicode strings
  19393. }
  19394. var strings = [
  19395. proto[0][0] || 'Original licence', // 0.Copyright
  19396. proto[0][1] || name, // 1.Font family
  19397. proto[0][2] || 'Unknown', // 2.Font subfamily (font weight)
  19398. proto[0][3] || 'uniqueID', // 3.Unique ID
  19399. proto[0][4] || name, // 4.Full font name
  19400. proto[0][5] || 'Version 0.11', // 5.Version
  19401. proto[0][6] || '', // 6.Postscript name
  19402. proto[0][7] || 'Unknown', // 7.Trademark
  19403. proto[0][8] || 'Unknown', // 8.Manufacturer
  19404. proto[0][9] || 'Unknown' // 9.Designer
  19405. ];
  19406. // Mac want 1-byte per character strings while Windows want
  19407. // 2-bytes per character, so duplicate the names table
  19408. var stringsUnicode = [];
  19409. var i, ii, j, jj, str;
  19410. for (i = 0, ii = strings.length; i < ii; i++) {
  19411. str = proto[1][i] || strings[i];
  19412. var strBufUnicode = [];
  19413. for (j = 0, jj = str.length; j < jj; j++) {
  19414. strBufUnicode.push(string16(str.charCodeAt(j)));
  19415. }
  19416. stringsUnicode.push(strBufUnicode.join(''));
  19417. }
  19418. var names = [strings, stringsUnicode];
  19419. var platforms = ['\x00\x01', '\x00\x03'];
  19420. var encodings = ['\x00\x00', '\x00\x01'];
  19421. var languages = ['\x00\x00', '\x04\x09'];
  19422. var namesRecordCount = strings.length * platforms.length;
  19423. var nameTable =
  19424. '\x00\x00' + // format
  19425. string16(namesRecordCount) + // Number of names Record
  19426. string16(namesRecordCount * 12 + 6); // Storage
  19427. // Build the name records field
  19428. var strOffset = 0;
  19429. for (i = 0, ii = platforms.length; i < ii; i++) {
  19430. var strs = names[i];
  19431. for (j = 0, jj = strs.length; j < jj; j++) {
  19432. str = strs[j];
  19433. var nameRecord =
  19434. platforms[i] + // platform ID
  19435. encodings[i] + // encoding ID
  19436. languages[i] + // language ID
  19437. string16(j) + // name ID
  19438. string16(str.length) +
  19439. string16(strOffset);
  19440. nameTable += nameRecord;
  19441. strOffset += str.length;
  19442. }
  19443. }
  19444. nameTable += strings.join('') + stringsUnicode.join('');
  19445. return nameTable;
  19446. }
  19447. Font.prototype = {
  19448. name: null,
  19449. font: null,
  19450. mimetype: null,
  19451. encoding: null,
  19452. get renderer() {
  19453. var renderer = FontRendererFactory.create(this);
  19454. return shadow(this, 'renderer', renderer);
  19455. },
  19456. exportData: function Font_exportData() {
  19457. var data = {};
  19458. for (var i in this) {
  19459. if (this.hasOwnProperty(i)) {
  19460. data[i] = this[i];
  19461. }
  19462. }
  19463. return data;
  19464. },
  19465. checkAndRepair: function Font_checkAndRepair(name, font, properties) {
  19466. function readTableEntry(file) {
  19467. var tag = bytesToString(file.getBytes(4));
  19468. var checksum = file.getInt32();
  19469. var offset = file.getInt32() >>> 0;
  19470. var length = file.getInt32() >>> 0;
  19471. // Read the table associated data
  19472. var previousPosition = file.pos;
  19473. file.pos = file.start ? file.start : 0;
  19474. file.skip(offset);
  19475. var data = file.getBytes(length);
  19476. file.pos = previousPosition;
  19477. if (tag === 'head') {
  19478. // clearing checksum adjustment
  19479. data[8] = data[9] = data[10] = data[11] = 0;
  19480. data[17] |= 0x20; //Set font optimized for cleartype flag
  19481. }
  19482. return {
  19483. tag: tag,
  19484. checksum: checksum,
  19485. length: length,
  19486. offset: offset,
  19487. data: data
  19488. };
  19489. }
  19490. function readOpenTypeHeader(ttf) {
  19491. return {
  19492. version: bytesToString(ttf.getBytes(4)),
  19493. numTables: ttf.getUint16(),
  19494. searchRange: ttf.getUint16(),
  19495. entrySelector: ttf.getUint16(),
  19496. rangeShift: ttf.getUint16()
  19497. };
  19498. }
  19499. /**
  19500. * Read the appropriate subtable from the cmap according to 9.6.6.4 from
  19501. * PDF spec
  19502. */
  19503. function readCmapTable(cmap, font, isSymbolicFont) {
  19504. var segment;
  19505. var start = (font.start ? font.start : 0) + cmap.offset;
  19506. font.pos = start;
  19507. var version = font.getUint16();
  19508. var numTables = font.getUint16();
  19509. var potentialTable;
  19510. var canBreak = false;
  19511. // There's an order of preference in terms of which cmap subtable to
  19512. // use:
  19513. // - non-symbolic fonts the preference is a 3,1 table then a 1,0 table
  19514. // - symbolic fonts the preference is a 3,0 table then a 1,0 table
  19515. // The following takes advantage of the fact that the tables are sorted
  19516. // to work.
  19517. for (var i = 0; i < numTables; i++) {
  19518. var platformId = font.getUint16();
  19519. var encodingId = font.getUint16();
  19520. var offset = font.getInt32() >>> 0;
  19521. var useTable = false;
  19522. if (platformId === 1 && encodingId === 0) {
  19523. useTable = true;
  19524. // Continue the loop since there still may be a higher priority
  19525. // table.
  19526. } else if (!isSymbolicFont && platformId === 3 && encodingId === 1) {
  19527. useTable = true;
  19528. canBreak = true;
  19529. } else if (isSymbolicFont && platformId === 3 && encodingId === 0) {
  19530. useTable = true;
  19531. canBreak = true;
  19532. }
  19533. if (useTable) {
  19534. potentialTable = {
  19535. platformId: platformId,
  19536. encodingId: encodingId,
  19537. offset: offset
  19538. };
  19539. }
  19540. if (canBreak) {
  19541. break;
  19542. }
  19543. }
  19544. if (!potentialTable) {
  19545. warn('Could not find a preferred cmap table.');
  19546. return {
  19547. platformId: -1,
  19548. encodingId: -1,
  19549. mappings: [],
  19550. hasShortCmap: false
  19551. };
  19552. }
  19553. font.pos = start + potentialTable.offset;
  19554. var format = font.getUint16();
  19555. var length = font.getUint16();
  19556. var language = font.getUint16();
  19557. var hasShortCmap = false;
  19558. var mappings = [];
  19559. var j, glyphId;
  19560. // TODO(mack): refactor this cmap subtable reading logic out
  19561. if (format === 0) {
  19562. for (j = 0; j < 256; j++) {
  19563. var index = font.getByte();
  19564. if (!index) {
  19565. continue;
  19566. }
  19567. mappings.push({
  19568. charCode: j,
  19569. glyphId: index
  19570. });
  19571. }
  19572. hasShortCmap = true;
  19573. } else if (format === 4) {
  19574. // re-creating the table in format 4 since the encoding
  19575. // might be changed
  19576. var segCount = (font.getUint16() >> 1);
  19577. font.getBytes(6); // skipping range fields
  19578. var segIndex, segments = [];
  19579. for (segIndex = 0; segIndex < segCount; segIndex++) {
  19580. segments.push({ end: font.getUint16() });
  19581. }
  19582. font.getUint16();
  19583. for (segIndex = 0; segIndex < segCount; segIndex++) {
  19584. segments[segIndex].start = font.getUint16();
  19585. }
  19586. for (segIndex = 0; segIndex < segCount; segIndex++) {
  19587. segments[segIndex].delta = font.getUint16();
  19588. }
  19589. var offsetsCount = 0;
  19590. for (segIndex = 0; segIndex < segCount; segIndex++) {
  19591. segment = segments[segIndex];
  19592. var rangeOffset = font.getUint16();
  19593. if (!rangeOffset) {
  19594. segment.offsetIndex = -1;
  19595. continue;
  19596. }
  19597. var offsetIndex = (rangeOffset >> 1) - (segCount - segIndex);
  19598. segment.offsetIndex = offsetIndex;
  19599. offsetsCount = Math.max(offsetsCount, offsetIndex +
  19600. segment.end - segment.start + 1);
  19601. }
  19602. var offsets = [];
  19603. for (j = 0; j < offsetsCount; j++) {
  19604. offsets.push(font.getUint16());
  19605. }
  19606. for (segIndex = 0; segIndex < segCount; segIndex++) {
  19607. segment = segments[segIndex];
  19608. start = segment.start;
  19609. var end = segment.end;
  19610. var delta = segment.delta;
  19611. offsetIndex = segment.offsetIndex;
  19612. for (j = start; j <= end; j++) {
  19613. if (j === 0xFFFF) {
  19614. continue;
  19615. }
  19616. glyphId = (offsetIndex < 0 ?
  19617. j : offsets[offsetIndex + j - start]);
  19618. glyphId = (glyphId + delta) & 0xFFFF;
  19619. if (glyphId === 0) {
  19620. continue;
  19621. }
  19622. mappings.push({
  19623. charCode: j,
  19624. glyphId: glyphId
  19625. });
  19626. }
  19627. }
  19628. } else if (format === 6) {
  19629. // Format 6 is a 2-bytes dense mapping, which means the font data
  19630. // lives glue together even if they are pretty far in the unicode
  19631. // table. (This looks weird, so I can have missed something), this
  19632. // works on Linux but seems to fails on Mac so let's rewrite the
  19633. // cmap table to a 3-1-4 style
  19634. var firstCode = font.getUint16();
  19635. var entryCount = font.getUint16();
  19636. for (j = 0; j < entryCount; j++) {
  19637. glyphId = font.getUint16();
  19638. var charCode = firstCode + j;
  19639. mappings.push({
  19640. charCode: charCode,
  19641. glyphId: glyphId
  19642. });
  19643. }
  19644. } else {
  19645. error('cmap table has unsupported format: ' + format);
  19646. }
  19647. // removing duplicate entries
  19648. mappings.sort(function (a, b) {
  19649. return a.charCode - b.charCode;
  19650. });
  19651. for (i = 1; i < mappings.length; i++) {
  19652. if (mappings[i - 1].charCode === mappings[i].charCode) {
  19653. mappings.splice(i, 1);
  19654. i--;
  19655. }
  19656. }
  19657. return {
  19658. platformId: potentialTable.platformId,
  19659. encodingId: potentialTable.encodingId,
  19660. mappings: mappings,
  19661. hasShortCmap: hasShortCmap
  19662. };
  19663. }
  19664. function sanitizeMetrics(font, header, metrics, numGlyphs) {
  19665. if (!header) {
  19666. if (metrics) {
  19667. metrics.data = null;
  19668. }
  19669. return;
  19670. }
  19671. font.pos = (font.start ? font.start : 0) + header.offset;
  19672. font.pos += header.length - 2;
  19673. var numOfMetrics = font.getUint16();
  19674. if (numOfMetrics > numGlyphs) {
  19675. info('The numOfMetrics (' + numOfMetrics + ') should not be ' +
  19676. 'greater than the numGlyphs (' + numGlyphs + ')');
  19677. // Reduce numOfMetrics if it is greater than numGlyphs
  19678. numOfMetrics = numGlyphs;
  19679. header.data[34] = (numOfMetrics & 0xff00) >> 8;
  19680. header.data[35] = numOfMetrics & 0x00ff;
  19681. }
  19682. var numOfSidebearings = numGlyphs - numOfMetrics;
  19683. var numMissing = numOfSidebearings -
  19684. ((metrics.length - numOfMetrics * 4) >> 1);
  19685. var i, ii;
  19686. if (numMissing > 0) {
  19687. font.pos = (font.start ? font.start : 0) + metrics.offset;
  19688. var entries = '';
  19689. for (i = 0, ii = metrics.length; i < ii; i++) {
  19690. entries += String.fromCharCode(font.getByte());
  19691. }
  19692. for (i = 0; i < numMissing; i++) {
  19693. entries += '\x00\x00';
  19694. }
  19695. metrics.data = stringToArray(entries);
  19696. }
  19697. }
  19698. function sanitizeGlyph(source, sourceStart, sourceEnd, dest, destStart,
  19699. hintsValid) {
  19700. if (sourceEnd - sourceStart <= 12) {
  19701. // glyph with data less than 12 is invalid one
  19702. return 0;
  19703. }
  19704. var glyf = source.subarray(sourceStart, sourceEnd);
  19705. var contoursCount = (glyf[0] << 8) | glyf[1];
  19706. if (contoursCount & 0x8000) {
  19707. // complex glyph, writing as is
  19708. dest.set(glyf, destStart);
  19709. return glyf.length;
  19710. }
  19711. var i, j = 10, flagsCount = 0;
  19712. for (i = 0; i < contoursCount; i++) {
  19713. var endPoint = (glyf[j] << 8) | glyf[j + 1];
  19714. flagsCount = endPoint + 1;
  19715. j += 2;
  19716. }
  19717. // skipping instructions
  19718. var instructionsStart = j;
  19719. var instructionsLength = (glyf[j] << 8) | glyf[j + 1];
  19720. j += 2 + instructionsLength;
  19721. var instructionsEnd = j;
  19722. // validating flags
  19723. var coordinatesLength = 0;
  19724. for (i = 0; i < flagsCount; i++) {
  19725. var flag = glyf[j++];
  19726. if (flag & 0xC0) {
  19727. // reserved flags must be zero, cleaning up
  19728. glyf[j - 1] = flag & 0x3F;
  19729. }
  19730. var xyLength = ((flag & 2) ? 1 : (flag & 16) ? 0 : 2) +
  19731. ((flag & 4) ? 1 : (flag & 32) ? 0 : 2);
  19732. coordinatesLength += xyLength;
  19733. if (flag & 8) {
  19734. var repeat = glyf[j++];
  19735. i += repeat;
  19736. coordinatesLength += repeat * xyLength;
  19737. }
  19738. }
  19739. // glyph without coordinates will be rejected
  19740. if (coordinatesLength === 0) {
  19741. return 0;
  19742. }
  19743. var glyphDataLength = j + coordinatesLength;
  19744. if (glyphDataLength > glyf.length) {
  19745. // not enough data for coordinates
  19746. return 0;
  19747. }
  19748. if (!hintsValid && instructionsLength > 0) {
  19749. dest.set(glyf.subarray(0, instructionsStart), destStart);
  19750. dest.set([0, 0], destStart + instructionsStart);
  19751. dest.set(glyf.subarray(instructionsEnd, glyphDataLength),
  19752. destStart + instructionsStart + 2);
  19753. glyphDataLength -= instructionsLength;
  19754. if (glyf.length - glyphDataLength > 3) {
  19755. glyphDataLength = (glyphDataLength + 3) & ~3;
  19756. }
  19757. return glyphDataLength;
  19758. }
  19759. if (glyf.length - glyphDataLength > 3) {
  19760. // truncating and aligning to 4 bytes the long glyph data
  19761. glyphDataLength = (glyphDataLength + 3) & ~3;
  19762. dest.set(glyf.subarray(0, glyphDataLength), destStart);
  19763. return glyphDataLength;
  19764. }
  19765. // glyph data is fine
  19766. dest.set(glyf, destStart);
  19767. return glyf.length;
  19768. }
  19769. function sanitizeHead(head, numGlyphs, locaLength) {
  19770. var data = head.data;
  19771. // Validate version:
  19772. // Should always be 0x00010000
  19773. var version = int32(data[0], data[1], data[2], data[3]);
  19774. if (version >> 16 !== 1) {
  19775. info('Attempting to fix invalid version in head table: ' + version);
  19776. data[0] = 0;
  19777. data[1] = 1;
  19778. data[2] = 0;
  19779. data[3] = 0;
  19780. }
  19781. var indexToLocFormat = int16(data[50], data[51]);
  19782. if (indexToLocFormat < 0 || indexToLocFormat > 1) {
  19783. info('Attempting to fix invalid indexToLocFormat in head table: ' +
  19784. indexToLocFormat);
  19785. // The value of indexToLocFormat should be 0 if the loca table
  19786. // consists of short offsets, and should be 1 if the loca table
  19787. // consists of long offsets.
  19788. //
  19789. // The number of entries in the loca table should be numGlyphs + 1.
  19790. //
  19791. // Using this information, we can work backwards to deduce if the
  19792. // size of each offset in the loca table, and thus figure out the
  19793. // appropriate value for indexToLocFormat.
  19794. var numGlyphsPlusOne = numGlyphs + 1;
  19795. if (locaLength === numGlyphsPlusOne << 1) {
  19796. // 0x0000 indicates the loca table consists of short offsets
  19797. data[50] = 0;
  19798. data[51] = 0;
  19799. } else if (locaLength === numGlyphsPlusOne << 2) {
  19800. // 0x0001 indicates the loca table consists of long offsets
  19801. data[50] = 0;
  19802. data[51] = 1;
  19803. } else {
  19804. warn('Could not fix indexToLocFormat: ' + indexToLocFormat);
  19805. }
  19806. }
  19807. }
  19808. function sanitizeGlyphLocations(loca, glyf, numGlyphs,
  19809. isGlyphLocationsLong, hintsValid,
  19810. dupFirstEntry) {
  19811. var itemSize, itemDecode, itemEncode;
  19812. if (isGlyphLocationsLong) {
  19813. itemSize = 4;
  19814. itemDecode = function fontItemDecodeLong(data, offset) {
  19815. return (data[offset] << 24) | (data[offset + 1] << 16) |
  19816. (data[offset + 2] << 8) | data[offset + 3];
  19817. };
  19818. itemEncode = function fontItemEncodeLong(data, offset, value) {
  19819. data[offset] = (value >>> 24) & 0xFF;
  19820. data[offset + 1] = (value >> 16) & 0xFF;
  19821. data[offset + 2] = (value >> 8) & 0xFF;
  19822. data[offset + 3] = value & 0xFF;
  19823. };
  19824. } else {
  19825. itemSize = 2;
  19826. itemDecode = function fontItemDecode(data, offset) {
  19827. return (data[offset] << 9) | (data[offset + 1] << 1);
  19828. };
  19829. itemEncode = function fontItemEncode(data, offset, value) {
  19830. data[offset] = (value >> 9) & 0xFF;
  19831. data[offset + 1] = (value >> 1) & 0xFF;
  19832. };
  19833. }
  19834. var locaData = loca.data;
  19835. var locaDataSize = itemSize * (1 + numGlyphs);
  19836. // is loca.data too short or long?
  19837. if (locaData.length !== locaDataSize) {
  19838. locaData = new Uint8Array(locaDataSize);
  19839. locaData.set(loca.data.subarray(0, locaDataSize));
  19840. loca.data = locaData;
  19841. }
  19842. // removing the invalid glyphs
  19843. var oldGlyfData = glyf.data;
  19844. var oldGlyfDataLength = oldGlyfData.length;
  19845. var newGlyfData = new Uint8Array(oldGlyfDataLength);
  19846. var startOffset = itemDecode(locaData, 0);
  19847. var writeOffset = 0;
  19848. itemEncode(locaData, 0, writeOffset);
  19849. var i, j;
  19850. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  19851. var endOffset = itemDecode(locaData, j);
  19852. if (endOffset > oldGlyfDataLength &&
  19853. ((oldGlyfDataLength + 3) & ~3) === endOffset) {
  19854. // Aspose breaks fonts by aligning the glyphs to the qword, but not
  19855. // the glyf table size, which makes last glyph out of range.
  19856. endOffset = oldGlyfDataLength;
  19857. }
  19858. if (endOffset > oldGlyfDataLength) {
  19859. // glyph end offset points outside glyf data, rejecting the glyph
  19860. itemEncode(locaData, j, writeOffset);
  19861. startOffset = endOffset;
  19862. continue;
  19863. }
  19864. var newLength = sanitizeGlyph(oldGlyfData, startOffset, endOffset,
  19865. newGlyfData, writeOffset, hintsValid);
  19866. writeOffset += newLength;
  19867. itemEncode(locaData, j, writeOffset);
  19868. startOffset = endOffset;
  19869. }
  19870. if (writeOffset === 0) {
  19871. // glyf table cannot be empty -- redoing the glyf and loca tables
  19872. // to have single glyph with one point
  19873. var simpleGlyph = new Uint8Array(
  19874. [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 49, 0]);
  19875. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  19876. itemEncode(locaData, j, simpleGlyph.length);
  19877. }
  19878. glyf.data = simpleGlyph;
  19879. return;
  19880. }
  19881. if (dupFirstEntry) {
  19882. var firstEntryLength = itemDecode(locaData, itemSize);
  19883. if (newGlyfData.length > firstEntryLength + writeOffset) {
  19884. glyf.data = newGlyfData.subarray(0, firstEntryLength + writeOffset);
  19885. } else {
  19886. glyf.data = new Uint8Array(firstEntryLength + writeOffset);
  19887. glyf.data.set(newGlyfData.subarray(0, writeOffset));
  19888. }
  19889. glyf.data.set(newGlyfData.subarray(0, firstEntryLength), writeOffset);
  19890. itemEncode(loca.data, locaData.length - itemSize,
  19891. writeOffset + firstEntryLength);
  19892. } else {
  19893. glyf.data = newGlyfData.subarray(0, writeOffset);
  19894. }
  19895. }
  19896. function readPostScriptTable(post, properties, maxpNumGlyphs) {
  19897. var start = (font.start ? font.start : 0) + post.offset;
  19898. font.pos = start;
  19899. var length = post.length, end = start + length;
  19900. var version = font.getInt32();
  19901. // skip rest to the tables
  19902. font.getBytes(28);
  19903. var glyphNames;
  19904. var valid = true;
  19905. var i;
  19906. switch (version) {
  19907. case 0x00010000:
  19908. glyphNames = MacStandardGlyphOrdering;
  19909. break;
  19910. case 0x00020000:
  19911. var numGlyphs = font.getUint16();
  19912. if (numGlyphs !== maxpNumGlyphs) {
  19913. valid = false;
  19914. break;
  19915. }
  19916. var glyphNameIndexes = [];
  19917. for (i = 0; i < numGlyphs; ++i) {
  19918. var index = font.getUint16();
  19919. if (index >= 32768) {
  19920. valid = false;
  19921. break;
  19922. }
  19923. glyphNameIndexes.push(index);
  19924. }
  19925. if (!valid) {
  19926. break;
  19927. }
  19928. var customNames = [];
  19929. var strBuf = [];
  19930. while (font.pos < end) {
  19931. var stringLength = font.getByte();
  19932. strBuf.length = stringLength;
  19933. for (i = 0; i < stringLength; ++i) {
  19934. strBuf[i] = String.fromCharCode(font.getByte());
  19935. }
  19936. customNames.push(strBuf.join(''));
  19937. }
  19938. glyphNames = [];
  19939. for (i = 0; i < numGlyphs; ++i) {
  19940. var j = glyphNameIndexes[i];
  19941. if (j < 258) {
  19942. glyphNames.push(MacStandardGlyphOrdering[j]);
  19943. continue;
  19944. }
  19945. glyphNames.push(customNames[j - 258]);
  19946. }
  19947. break;
  19948. case 0x00030000:
  19949. break;
  19950. default:
  19951. warn('Unknown/unsupported post table version ' + version);
  19952. valid = false;
  19953. break;
  19954. }
  19955. properties.glyphNames = glyphNames;
  19956. return valid;
  19957. }
  19958. function readNameTable(nameTable) {
  19959. var start = (font.start ? font.start : 0) + nameTable.offset;
  19960. font.pos = start;
  19961. var names = [[], []];
  19962. var length = nameTable.length, end = start + length;
  19963. var format = font.getUint16();
  19964. var FORMAT_0_HEADER_LENGTH = 6;
  19965. if (format !== 0 || length < FORMAT_0_HEADER_LENGTH) {
  19966. // unsupported name table format or table "too" small
  19967. return names;
  19968. }
  19969. var numRecords = font.getUint16();
  19970. var stringsStart = font.getUint16();
  19971. var records = [];
  19972. var NAME_RECORD_LENGTH = 12;
  19973. var i, ii;
  19974. for (i = 0; i < numRecords &&
  19975. font.pos + NAME_RECORD_LENGTH <= end; i++) {
  19976. var r = {
  19977. platform: font.getUint16(),
  19978. encoding: font.getUint16(),
  19979. language: font.getUint16(),
  19980. name: font.getUint16(),
  19981. length: font.getUint16(),
  19982. offset: font.getUint16()
  19983. };
  19984. // using only Macintosh and Windows platform/encoding names
  19985. if ((r.platform === 1 && r.encoding === 0 && r.language === 0) ||
  19986. (r.platform === 3 && r.encoding === 1 && r.language === 0x409)) {
  19987. records.push(r);
  19988. }
  19989. }
  19990. for (i = 0, ii = records.length; i < ii; i++) {
  19991. var record = records[i];
  19992. var pos = start + stringsStart + record.offset;
  19993. if (pos + record.length > end) {
  19994. continue; // outside of name table, ignoring
  19995. }
  19996. font.pos = pos;
  19997. var nameIndex = record.name;
  19998. if (record.encoding) {
  19999. // unicode
  20000. var str = '';
  20001. for (var j = 0, jj = record.length; j < jj; j += 2) {
  20002. str += String.fromCharCode(font.getUint16());
  20003. }
  20004. names[1][nameIndex] = str;
  20005. } else {
  20006. names[0][nameIndex] = bytesToString(font.getBytes(record.length));
  20007. }
  20008. }
  20009. return names;
  20010. }
  20011. var TTOpsStackDeltas = [
  20012. 0, 0, 0, 0, 0, 0, 0, 0, -2, -2, -2, -2, 0, 0, -2, -5,
  20013. -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, -1, -1,
  20014. 1, -1, -999, 0, 1, 0, -1, -2, 0, -1, -2, -1, -1, 0, -1, -1,
  20015. 0, 0, -999, -999, -1, -1, -1, -1, -2, -999, -2, -2, -999, 0, -2, -2,
  20016. 0, 0, -2, 0, -2, 0, 0, 0, -2, -1, -1, 1, 1, 0, 0, -1,
  20017. -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, 0, -999, -1, -1,
  20018. -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  20019. -2, -999, -999, -999, -999, -999, -1, -1, -2, -2, 0, 0, 0, 0, -1, -1,
  20020. -999, -2, -2, 0, 0, -1, -2, -2, 0, 0, 0, -1, -1, -1, -2];
  20021. // 0xC0-DF == -1 and 0xE0-FF == -2
  20022. function sanitizeTTProgram(table, ttContext) {
  20023. var data = table.data;
  20024. var i = 0, j, n, b, funcId, pc, lastEndf = 0, lastDeff = 0;
  20025. var stack = [];
  20026. var callstack = [];
  20027. var functionsCalled = [];
  20028. var tooComplexToFollowFunctions =
  20029. ttContext.tooComplexToFollowFunctions;
  20030. var inFDEF = false, ifLevel = 0, inELSE = 0;
  20031. for (var ii = data.length; i < ii;) {
  20032. var op = data[i++];
  20033. // The TrueType instruction set docs can be found at
  20034. // https://developer.apple.com/fonts/TTRefMan/RM05/Chap5.html
  20035. if (op === 0x40) { // NPUSHB - pushes n bytes
  20036. n = data[i++];
  20037. if (inFDEF || inELSE) {
  20038. i += n;
  20039. } else {
  20040. for (j = 0; j < n; j++) {
  20041. stack.push(data[i++]);
  20042. }
  20043. }
  20044. } else if (op === 0x41) { // NPUSHW - pushes n words
  20045. n = data[i++];
  20046. if (inFDEF || inELSE) {
  20047. i += n * 2;
  20048. } else {
  20049. for (j = 0; j < n; j++) {
  20050. b = data[i++];
  20051. stack.push((b << 8) | data[i++]);
  20052. }
  20053. }
  20054. } else if ((op & 0xF8) === 0xB0) { // PUSHB - pushes bytes
  20055. n = op - 0xB0 + 1;
  20056. if (inFDEF || inELSE) {
  20057. i += n;
  20058. } else {
  20059. for (j = 0; j < n; j++) {
  20060. stack.push(data[i++]);
  20061. }
  20062. }
  20063. } else if ((op & 0xF8) === 0xB8) { // PUSHW - pushes words
  20064. n = op - 0xB8 + 1;
  20065. if (inFDEF || inELSE) {
  20066. i += n * 2;
  20067. } else {
  20068. for (j = 0; j < n; j++) {
  20069. b = data[i++];
  20070. stack.push((b << 8) | data[i++]);
  20071. }
  20072. }
  20073. } else if (op === 0x2B && !tooComplexToFollowFunctions) { // CALL
  20074. if (!inFDEF && !inELSE) {
  20075. // collecting inforamtion about which functions are used
  20076. funcId = stack[stack.length - 1];
  20077. ttContext.functionsUsed[funcId] = true;
  20078. if (funcId in ttContext.functionsStackDeltas) {
  20079. stack.length += ttContext.functionsStackDeltas[funcId];
  20080. } else if (funcId in ttContext.functionsDefined &&
  20081. functionsCalled.indexOf(funcId) < 0) {
  20082. callstack.push({data: data, i: i, stackTop: stack.length - 1});
  20083. functionsCalled.push(funcId);
  20084. pc = ttContext.functionsDefined[funcId];
  20085. if (!pc) {
  20086. warn('TT: CALL non-existent function');
  20087. ttContext.hintsValid = false;
  20088. return;
  20089. }
  20090. data = pc.data;
  20091. i = pc.i;
  20092. }
  20093. }
  20094. } else if (op === 0x2C && !tooComplexToFollowFunctions) { // FDEF
  20095. if (inFDEF || inELSE) {
  20096. warn('TT: nested FDEFs not allowed');
  20097. tooComplexToFollowFunctions = true;
  20098. }
  20099. inFDEF = true;
  20100. // collecting inforamtion about which functions are defined
  20101. lastDeff = i;
  20102. funcId = stack.pop();
  20103. ttContext.functionsDefined[funcId] = {data: data, i: i};
  20104. } else if (op === 0x2D) { // ENDF - end of function
  20105. if (inFDEF) {
  20106. inFDEF = false;
  20107. lastEndf = i;
  20108. } else {
  20109. pc = callstack.pop();
  20110. if (!pc) {
  20111. warn('TT: ENDF bad stack');
  20112. ttContext.hintsValid = false;
  20113. return;
  20114. }
  20115. funcId = functionsCalled.pop();
  20116. data = pc.data;
  20117. i = pc.i;
  20118. ttContext.functionsStackDeltas[funcId] =
  20119. stack.length - pc.stackTop;
  20120. }
  20121. } else if (op === 0x89) { // IDEF - instruction definition
  20122. if (inFDEF || inELSE) {
  20123. warn('TT: nested IDEFs not allowed');
  20124. tooComplexToFollowFunctions = true;
  20125. }
  20126. inFDEF = true;
  20127. // recording it as a function to track ENDF
  20128. lastDeff = i;
  20129. } else if (op === 0x58) { // IF
  20130. ++ifLevel;
  20131. } else if (op === 0x1B) { // ELSE
  20132. inELSE = ifLevel;
  20133. } else if (op === 0x59) { // EIF
  20134. if (inELSE === ifLevel) {
  20135. inELSE = 0;
  20136. }
  20137. --ifLevel;
  20138. } else if (op === 0x1C) { // JMPR
  20139. if (!inFDEF && !inELSE) {
  20140. var offset = stack[stack.length - 1];
  20141. // only jumping forward to prevent infinite loop
  20142. if (offset > 0) {
  20143. i += offset - 1;
  20144. }
  20145. }
  20146. }
  20147. // Adjusting stack not extactly, but just enough to get function id
  20148. if (!inFDEF && !inELSE) {
  20149. var stackDelta = op <= 0x8E ? TTOpsStackDeltas[op] :
  20150. op >= 0xC0 && op <= 0xDF ? -1 : op >= 0xE0 ? -2 : 0;
  20151. if (op >= 0x71 && op <= 0x75) {
  20152. n = stack.pop();
  20153. if (n === n) {
  20154. stackDelta = -n * 2;
  20155. }
  20156. }
  20157. while (stackDelta < 0 && stack.length > 0) {
  20158. stack.pop();
  20159. stackDelta++;
  20160. }
  20161. while (stackDelta > 0) {
  20162. stack.push(NaN); // pushing any number into stack
  20163. stackDelta--;
  20164. }
  20165. }
  20166. }
  20167. ttContext.tooComplexToFollowFunctions = tooComplexToFollowFunctions;
  20168. var content = [data];
  20169. if (i > data.length) {
  20170. content.push(new Uint8Array(i - data.length));
  20171. }
  20172. if (lastDeff > lastEndf) {
  20173. warn('TT: complementing a missing function tail');
  20174. // new function definition started, but not finished
  20175. // complete function by [CLEAR, ENDF]
  20176. content.push(new Uint8Array([0x22, 0x2D]));
  20177. }
  20178. foldTTTable(table, content);
  20179. }
  20180. function checkInvalidFunctions(ttContext, maxFunctionDefs) {
  20181. if (ttContext.tooComplexToFollowFunctions) {
  20182. return;
  20183. }
  20184. if (ttContext.functionsDefined.length > maxFunctionDefs) {
  20185. warn('TT: more functions defined than expected');
  20186. ttContext.hintsValid = false;
  20187. return;
  20188. }
  20189. for (var j = 0, jj = ttContext.functionsUsed.length; j < jj; j++) {
  20190. if (j > maxFunctionDefs) {
  20191. warn('TT: invalid function id: ' + j);
  20192. ttContext.hintsValid = false;
  20193. return;
  20194. }
  20195. if (ttContext.functionsUsed[j] && !ttContext.functionsDefined[j]) {
  20196. warn('TT: undefined function: ' + j);
  20197. ttContext.hintsValid = false;
  20198. return;
  20199. }
  20200. }
  20201. }
  20202. function foldTTTable(table, content) {
  20203. if (content.length > 1) {
  20204. // concatenating the content items
  20205. var newLength = 0;
  20206. var j, jj;
  20207. for (j = 0, jj = content.length; j < jj; j++) {
  20208. newLength += content[j].length;
  20209. }
  20210. newLength = (newLength + 3) & ~3;
  20211. var result = new Uint8Array(newLength);
  20212. var pos = 0;
  20213. for (j = 0, jj = content.length; j < jj; j++) {
  20214. result.set(content[j], pos);
  20215. pos += content[j].length;
  20216. }
  20217. table.data = result;
  20218. table.length = newLength;
  20219. }
  20220. }
  20221. function sanitizeTTPrograms(fpgm, prep, cvt) {
  20222. var ttContext = {
  20223. functionsDefined: [],
  20224. functionsUsed: [],
  20225. functionsStackDeltas: [],
  20226. tooComplexToFollowFunctions: false,
  20227. hintsValid: true
  20228. };
  20229. if (fpgm) {
  20230. sanitizeTTProgram(fpgm, ttContext);
  20231. }
  20232. if (prep) {
  20233. sanitizeTTProgram(prep, ttContext);
  20234. }
  20235. if (fpgm) {
  20236. checkInvalidFunctions(ttContext, maxFunctionDefs);
  20237. }
  20238. if (cvt && (cvt.length & 1)) {
  20239. var cvtData = new Uint8Array(cvt.length + 1);
  20240. cvtData.set(cvt.data);
  20241. cvt.data = cvtData;
  20242. }
  20243. return ttContext.hintsValid;
  20244. }
  20245. // The following steps modify the original font data, making copy
  20246. font = new Stream(new Uint8Array(font.getBytes()));
  20247. var VALID_TABLES = ['OS/2', 'cmap', 'head', 'hhea', 'hmtx', 'maxp',
  20248. 'name', 'post', 'loca', 'glyf', 'fpgm', 'prep', 'cvt ', 'CFF '];
  20249. var header = readOpenTypeHeader(font);
  20250. var numTables = header.numTables;
  20251. var cff, cffFile;
  20252. var tables = { 'OS/2': null, cmap: null, head: null, hhea: null,
  20253. hmtx: null, maxp: null, name: null, post: null };
  20254. var table, tableData;
  20255. for (var i = 0; i < numTables; i++) {
  20256. table = readTableEntry(font);
  20257. if (VALID_TABLES.indexOf(table.tag) < 0) {
  20258. continue; // skipping table if it's not a required or optional table
  20259. }
  20260. if (table.length === 0) {
  20261. continue; // skipping empty tables
  20262. }
  20263. tables[table.tag] = table;
  20264. }
  20265. var isTrueType = !tables['CFF '];
  20266. if (!isTrueType) {
  20267. // OpenType font
  20268. if (!tables.head || !tables.hhea || !tables.maxp || !tables.post) {
  20269. // no major tables: throwing everything at CFFFont
  20270. cffFile = new Stream(tables['CFF '].data);
  20271. cff = new CFFFont(cffFile, properties);
  20272. return this.convert(name, cff, properties);
  20273. }
  20274. delete tables.glyf;
  20275. delete tables.loca;
  20276. delete tables.fpgm;
  20277. delete tables.prep;
  20278. delete tables['cvt '];
  20279. this.isOpenType = true;
  20280. } else {
  20281. if (!tables.glyf || !tables.loca) {
  20282. error('Required "glyf" or "loca" tables are not found');
  20283. }
  20284. this.isOpenType = false;
  20285. }
  20286. if (!tables.maxp) {
  20287. error('Required "maxp" table is not found');
  20288. }
  20289. font.pos = (font.start || 0) + tables.maxp.offset;
  20290. var version = font.getInt32();
  20291. var numGlyphs = font.getUint16();
  20292. var maxFunctionDefs = 0;
  20293. if (version >= 0x00010000 && tables.maxp.length >= 22) {
  20294. // maxZones can be invalid
  20295. font.pos += 8;
  20296. var maxZones = font.getUint16();
  20297. if (maxZones > 2) { // reset to 2 if font has invalid maxZones
  20298. tables.maxp.data[14] = 0;
  20299. tables.maxp.data[15] = 2;
  20300. }
  20301. font.pos += 4;
  20302. maxFunctionDefs = font.getUint16();
  20303. }
  20304. var dupFirstEntry = false;
  20305. if (properties.type === 'CIDFontType2' && properties.toUnicode &&
  20306. properties.toUnicode[0] > '\u0000') {
  20307. // oracle's defect (see 3427), duplicating first entry
  20308. dupFirstEntry = true;
  20309. numGlyphs++;
  20310. tables.maxp.data[4] = numGlyphs >> 8;
  20311. tables.maxp.data[5] = numGlyphs & 255;
  20312. }
  20313. var hintsValid = sanitizeTTPrograms(tables.fpgm, tables.prep,
  20314. tables['cvt '], maxFunctionDefs);
  20315. if (!hintsValid) {
  20316. delete tables.fpgm;
  20317. delete tables.prep;
  20318. delete tables['cvt '];
  20319. }
  20320. // Tables needs to be written by ascendant alphabetic order
  20321. var tablesNames = Object.keys(tables);
  20322. tablesNames.sort();
  20323. numTables = tablesNames.length;
  20324. // header and new offsets. Table entry information is appended to the
  20325. // end of file. The virtualOffset represents where to put the actual
  20326. // data of a particular table;
  20327. var ttf = {
  20328. file: '',
  20329. virtualOffset: numTables * (4 * 4)
  20330. };
  20331. // The new numbers of tables will be the last one plus the num
  20332. // of missing tables
  20333. createOpenTypeHeader(header.version, ttf, numTables);
  20334. // Ensure the hmtx table contains the advance width and
  20335. // sidebearings information for numGlyphs in the maxp table
  20336. sanitizeMetrics(font, tables.hhea, tables.hmtx, numGlyphs);
  20337. if (!tables.head) {
  20338. error('Required "head" table is not found');
  20339. }
  20340. sanitizeHead(tables.head, numGlyphs, isTrueType ? tables.loca.length : 0);
  20341. if (isTrueType) {
  20342. var isGlyphLocationsLong = int16(tables.head.data[50],
  20343. tables.head.data[51]);
  20344. sanitizeGlyphLocations(tables.loca, tables.glyf, numGlyphs,
  20345. isGlyphLocationsLong, hintsValid, dupFirstEntry);
  20346. }
  20347. if (!tables.hhea) {
  20348. error('Required "hhea" table is not found');
  20349. }
  20350. // Sanitizer reduces the glyph advanceWidth to the maxAdvanceWidth
  20351. // Sometimes it's 0. That needs to be fixed
  20352. if (tables.hhea.data[10] === 0 && tables.hhea.data[11] === 0) {
  20353. tables.hhea.data[10] = 0xFF;
  20354. tables.hhea.data[11] = 0xFF;
  20355. }
  20356. // The 'post' table has glyphs names.
  20357. if (tables.post) {
  20358. var valid = readPostScriptTable(tables.post, properties, numGlyphs);
  20359. if (!valid) {
  20360. tables.post = null;
  20361. }
  20362. }
  20363. var charCodeToGlyphId = [], charCode;
  20364. if (properties.type === 'CIDFontType2') {
  20365. var cidToGidMap = properties.cidToGidMap || [];
  20366. var cidToGidMapLength = cidToGidMap.length;
  20367. properties.cMap.forEach(function(charCode, cid) {
  20368. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  20369. var glyphId = -1;
  20370. if (cidToGidMapLength === 0) {
  20371. glyphId = charCode;
  20372. } else if (cidToGidMap[cid] !== undefined) {
  20373. glyphId = cidToGidMap[cid];
  20374. }
  20375. if (glyphId >= 0 && glyphId < numGlyphs) {
  20376. charCodeToGlyphId[charCode] = glyphId;
  20377. }
  20378. });
  20379. if (dupFirstEntry) {
  20380. charCodeToGlyphId[0] = numGlyphs - 1;
  20381. }
  20382. } else {
  20383. // Most of the following logic in this code branch is based on the
  20384. // 9.6.6.4 of the PDF spec.
  20385. var cmapTable = readCmapTable(tables.cmap, font, this.isSymbolicFont);
  20386. var cmapPlatformId = cmapTable.platformId;
  20387. var cmapEncodingId = cmapTable.encodingId;
  20388. var cmapMappings = cmapTable.mappings;
  20389. var cmapMappingsLength = cmapMappings.length;
  20390. var hasEncoding = properties.differences.length ||
  20391. !!properties.baseEncodingName;
  20392. // The spec seems to imply that if the font is symbolic the encoding
  20393. // should be ignored, this doesn't appear to work for 'preistabelle.pdf'
  20394. // where the the font is symbolic and it has an encoding.
  20395. if (hasEncoding &&
  20396. (cmapPlatformId === 3 && cmapEncodingId === 1 ||
  20397. cmapPlatformId === 1 && cmapEncodingId === 0)) {
  20398. var baseEncoding = [];
  20399. if (properties.baseEncodingName === 'MacRomanEncoding' ||
  20400. properties.baseEncodingName === 'WinAnsiEncoding') {
  20401. baseEncoding = Encodings[properties.baseEncodingName];
  20402. }
  20403. for (charCode = 0; charCode < 256; charCode++) {
  20404. var glyphName;
  20405. if (this.differences && charCode in this.differences) {
  20406. glyphName = this.differences[charCode];
  20407. } else if (charCode in baseEncoding &&
  20408. baseEncoding[charCode] !== '') {
  20409. glyphName = baseEncoding[charCode];
  20410. } else {
  20411. glyphName = Encodings.StandardEncoding[charCode];
  20412. }
  20413. if (!glyphName) {
  20414. continue;
  20415. }
  20416. var unicodeOrCharCode;
  20417. if (cmapPlatformId === 3 && cmapEncodingId === 1) {
  20418. unicodeOrCharCode = GlyphsUnicode[glyphName];
  20419. } else if (cmapPlatformId === 1 && cmapEncodingId === 0) {
  20420. // TODO: the encoding needs to be updated with mac os table.
  20421. unicodeOrCharCode = Encodings.MacRomanEncoding.indexOf(glyphName);
  20422. }
  20423. var found = false;
  20424. for (i = 0; i < cmapMappingsLength; ++i) {
  20425. if (cmapMappings[i].charCode === unicodeOrCharCode) {
  20426. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  20427. found = true;
  20428. break;
  20429. }
  20430. }
  20431. if (!found && properties.glyphNames) {
  20432. // Try to map using the post table. There are currently no known
  20433. // pdfs that this fixes.
  20434. var glyphId = properties.glyphNames.indexOf(glyphName);
  20435. if (glyphId > 0) {
  20436. charCodeToGlyphId[charCode] = glyphId;
  20437. }
  20438. }
  20439. }
  20440. } else {
  20441. // For (3, 0) cmap tables:
  20442. // The charcode key being stored in charCodeToGlyphId is the lower
  20443. // byte of the two-byte charcodes of the cmap table since according to
  20444. // the spec: 'each byte from the string shall be prepended with the
  20445. // high byte of the range [of charcodes in the cmap table], to form
  20446. // a two-byte character, which shall be used to select the
  20447. // associated glyph description from the subtable'.
  20448. //
  20449. // For (1, 0) cmap tables:
  20450. // 'single bytes from the string shall be used to look up the
  20451. // associated glyph descriptions from the subtable'. This means
  20452. // charcodes in the cmap will be single bytes, so no-op since
  20453. // glyph.charCode & 0xFF === glyph.charCode
  20454. for (i = 0; i < cmapMappingsLength; ++i) {
  20455. charCode = cmapMappings[i].charCode & 0xFF;
  20456. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  20457. }
  20458. }
  20459. }
  20460. if (charCodeToGlyphId.length === 0) {
  20461. // defines at least one glyph
  20462. charCodeToGlyphId[0] = 0;
  20463. }
  20464. // Converting glyphs and ids into font's cmap table
  20465. var newMapping = adjustMapping(charCodeToGlyphId, properties);
  20466. this.toFontChar = newMapping.toFontChar;
  20467. tables.cmap = {
  20468. tag: 'cmap',
  20469. data: createCmapTable(newMapping.charCodeToGlyphId)
  20470. };
  20471. if (!tables['OS/2'] || !validateOS2Table(tables['OS/2'])) {
  20472. // extract some more font properties from the OpenType head and
  20473. // hhea tables; yMin and descent value are always negative
  20474. var override = {
  20475. unitsPerEm: int16(tables.head.data[18], tables.head.data[19]),
  20476. yMax: int16(tables.head.data[42], tables.head.data[43]),
  20477. yMin: int16(tables.head.data[38], tables.head.data[39]) - 0x10000,
  20478. ascent: int16(tables.hhea.data[4], tables.hhea.data[5]),
  20479. descent: int16(tables.hhea.data[6], tables.hhea.data[7]) - 0x10000
  20480. };
  20481. tables['OS/2'] = {
  20482. tag: 'OS/2',
  20483. data: stringToArray(createOS2Table(properties,
  20484. newMapping.charCodeToGlyphId,
  20485. override))
  20486. };
  20487. }
  20488. // Rewrite the 'post' table if needed
  20489. if (!tables.post) {
  20490. tables.post = {
  20491. tag: 'post',
  20492. data: stringToArray(createPostTable(properties))
  20493. };
  20494. }
  20495. if (!isTrueType) {
  20496. try {
  20497. // Trying to repair CFF file
  20498. cffFile = new Stream(tables['CFF '].data);
  20499. var parser = new CFFParser(cffFile, properties);
  20500. cff = parser.parse();
  20501. var compiler = new CFFCompiler(cff);
  20502. tables['CFF '].data = compiler.compile();
  20503. } catch (e) {
  20504. warn('Failed to compile font ' + properties.loadedName);
  20505. }
  20506. }
  20507. // Re-creating 'name' table
  20508. if (!tables.name) {
  20509. tables.name = {
  20510. tag: 'name',
  20511. data: stringToArray(createNameTable(this.name))
  20512. };
  20513. } else {
  20514. // ... using existing 'name' table as prototype
  20515. var namePrototype = readNameTable(tables.name);
  20516. tables.name.data = stringToArray(createNameTable(name, namePrototype));
  20517. }
  20518. // rewrite the tables but tweak offsets
  20519. for (i = 0; i < numTables; i++) {
  20520. table = tables[tablesNames[i]];
  20521. table.data = createTableEntry(ttf, table.tag, table.data);
  20522. }
  20523. // Add the table datas
  20524. for (i = 0; i < numTables; i++) {
  20525. table = tables[tablesNames[i]];
  20526. tableData = table.data;
  20527. ttf.file += bytesToString(new Uint8Array(tableData));
  20528. // 4-byte aligned data
  20529. while (ttf.file.length & 3) {
  20530. ttf.file += String.fromCharCode(0);
  20531. }
  20532. }
  20533. return stringToArray(ttf.file);
  20534. },
  20535. convert: function Font_convert(fontName, font, properties) {
  20536. // The offsets object holds at the same time a representation of where
  20537. // to write the table entry information about a table and another offset
  20538. // representing the offset where to draw the actual data of a particular
  20539. // table
  20540. var otf = {
  20541. file: '',
  20542. virtualOffset: 9 * (4 * 4)
  20543. };
  20544. createOpenTypeHeader('\x4F\x54\x54\x4F', otf, 9);
  20545. // TODO: Check the charstring widths to determine this.
  20546. properties.fixedPitch = false;
  20547. var mapping = font.getGlyphMapping(properties);
  20548. var newMapping = adjustMapping(mapping, properties);
  20549. this.toFontChar = newMapping.toFontChar;
  20550. var numGlyphs = font.numGlyphs;
  20551. function getCharCodes(charCodeToGlyphId, glyphId) {
  20552. var charCodes = null;
  20553. for (var charCode in charCodeToGlyphId) {
  20554. if (glyphId === charCodeToGlyphId[charCode]) {
  20555. if (!charCodes) {
  20556. charCodes = [];
  20557. }
  20558. charCodes.push(charCode | 0);
  20559. }
  20560. }
  20561. return charCodes;
  20562. }
  20563. function createCharCode(charCodeToGlyphId, glyphId) {
  20564. for (var charCode in charCodeToGlyphId) {
  20565. if (glyphId === charCodeToGlyphId[charCode]) {
  20566. return charCode | 0;
  20567. }
  20568. }
  20569. newMapping.charCodeToGlyphId[newMapping.nextAvailableFontCharCode] =
  20570. glyphId;
  20571. return newMapping.nextAvailableFontCharCode++;
  20572. }
  20573. var seacs = font.seacs;
  20574. if (SEAC_ANALYSIS_ENABLED && seacs && seacs.length) {
  20575. var matrix = properties.fontMatrix || FONT_IDENTITY_MATRIX;
  20576. var charset = font.getCharset();
  20577. var seacMap = Object.create(null);
  20578. for (var glyphId in seacs) {
  20579. glyphId |= 0;
  20580. var seac = seacs[glyphId];
  20581. var baseGlyphName = Encodings.StandardEncoding[seac[2]];
  20582. var accentGlyphName = Encodings.StandardEncoding[seac[3]];
  20583. var baseGlyphId = charset.indexOf(baseGlyphName);
  20584. var accentGlyphId = charset.indexOf(accentGlyphName);
  20585. if (baseGlyphId < 0 || accentGlyphId < 0) {
  20586. continue;
  20587. }
  20588. var accentOffset = {
  20589. x: seac[0] * matrix[0] + seac[1] * matrix[2] + matrix[4],
  20590. y: seac[0] * matrix[1] + seac[1] * matrix[3] + matrix[5]
  20591. };
  20592. var charCodes = getCharCodes(mapping, glyphId);
  20593. if (!charCodes) {
  20594. // There's no point in mapping it if the char code was never mapped
  20595. // to begin with.
  20596. continue;
  20597. }
  20598. for (var i = 0, ii = charCodes.length; i < ii; i++) {
  20599. var charCode = charCodes[i];
  20600. // Find a fontCharCode that maps to the base and accent glyphs.
  20601. // If one doesn't exists, create it.
  20602. var charCodeToGlyphId = newMapping.charCodeToGlyphId;
  20603. var baseFontCharCode = createCharCode(charCodeToGlyphId,
  20604. baseGlyphId);
  20605. var accentFontCharCode = createCharCode(charCodeToGlyphId,
  20606. accentGlyphId);
  20607. seacMap[charCode] = {
  20608. baseFontCharCode: baseFontCharCode,
  20609. accentFontCharCode: accentFontCharCode,
  20610. accentOffset: accentOffset
  20611. };
  20612. }
  20613. }
  20614. properties.seacMap = seacMap;
  20615. }
  20616. var unitsPerEm = 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0];
  20617. var fields = {
  20618. // PostScript Font Program
  20619. 'CFF ': font.data,
  20620. // OS/2 and Windows Specific metrics
  20621. 'OS/2': stringToArray(createOS2Table(properties,
  20622. newMapping.charCodeToGlyphId)),
  20623. // Character to glyphs mapping
  20624. 'cmap': createCmapTable(newMapping.charCodeToGlyphId),
  20625. // Font header
  20626. 'head': (function fontFieldsHead() {
  20627. return stringToArray(
  20628. '\x00\x01\x00\x00' + // Version number
  20629. '\x00\x00\x10\x00' + // fontRevision
  20630. '\x00\x00\x00\x00' + // checksumAdjustement
  20631. '\x5F\x0F\x3C\xF5' + // magicNumber
  20632. '\x00\x00' + // Flags
  20633. safeString16(unitsPerEm) + // unitsPerEM
  20634. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // creation date
  20635. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // modifification date
  20636. '\x00\x00' + // xMin
  20637. safeString16(properties.descent) + // yMin
  20638. '\x0F\xFF' + // xMax
  20639. safeString16(properties.ascent) + // yMax
  20640. string16(properties.italicAngle ? 2 : 0) + // macStyle
  20641. '\x00\x11' + // lowestRecPPEM
  20642. '\x00\x00' + // fontDirectionHint
  20643. '\x00\x00' + // indexToLocFormat
  20644. '\x00\x00'); // glyphDataFormat
  20645. })(),
  20646. // Horizontal header
  20647. 'hhea': (function fontFieldsHhea() {
  20648. return stringToArray(
  20649. '\x00\x01\x00\x00' + // Version number
  20650. safeString16(properties.ascent) + // Typographic Ascent
  20651. safeString16(properties.descent) + // Typographic Descent
  20652. '\x00\x00' + // Line Gap
  20653. '\xFF\xFF' + // advanceWidthMax
  20654. '\x00\x00' + // minLeftSidebearing
  20655. '\x00\x00' + // minRightSidebearing
  20656. '\x00\x00' + // xMaxExtent
  20657. safeString16(properties.capHeight) + // caretSlopeRise
  20658. safeString16(Math.tan(properties.italicAngle) *
  20659. properties.xHeight) + // caretSlopeRun
  20660. '\x00\x00' + // caretOffset
  20661. '\x00\x00' + // -reserved-
  20662. '\x00\x00' + // -reserved-
  20663. '\x00\x00' + // -reserved-
  20664. '\x00\x00' + // -reserved-
  20665. '\x00\x00' + // metricDataFormat
  20666. string16(numGlyphs)); // Number of HMetrics
  20667. })(),
  20668. // Horizontal metrics
  20669. 'hmtx': (function fontFieldsHmtx() {
  20670. var charstrings = font.charstrings;
  20671. var hmtx = '\x00\x00\x00\x00'; // Fake .notdef
  20672. for (var i = 1, ii = numGlyphs; i < ii; i++) {
  20673. // TODO: For CFF fonts the width should technically match th x in
  20674. // the glyph, but it doesn't seem to matter.
  20675. var charstring = charstrings ? charstrings[i - 1] : {};
  20676. var width = 'width' in charstring ? charstring.width : 0;
  20677. hmtx += string16(width) + string16(0);
  20678. }
  20679. return stringToArray(hmtx);
  20680. })(),
  20681. // Maximum profile
  20682. 'maxp': (function fontFieldsMaxp() {
  20683. return stringToArray(
  20684. '\x00\x00\x50\x00' + // Version number
  20685. string16(numGlyphs)); // Num of glyphs
  20686. })(),
  20687. // Naming tables
  20688. 'name': stringToArray(createNameTable(fontName)),
  20689. // PostScript informations
  20690. 'post': stringToArray(createPostTable(properties))
  20691. };
  20692. var field;
  20693. for (field in fields) {
  20694. fields[field] = createTableEntry(otf, field, fields[field]);
  20695. }
  20696. for (field in fields) {
  20697. var table = fields[field];
  20698. otf.file += bytesToString(new Uint8Array(table));
  20699. }
  20700. return stringToArray(otf.file);
  20701. },
  20702. /**
  20703. * Builds a char code to unicode map based on section 9.10 of the spec.
  20704. * @param {Object} properties Font properties object.
  20705. * @return {Object} Has two properties: 'toUnicode' which maps char codes to
  20706. * unicode (string) values and 'isIdentity' which is true if an identity map
  20707. * is used.
  20708. */
  20709. buildToUnicode: function Font_buildToUnicode(properties) {
  20710. var map = {
  20711. isIdentity: false,
  20712. toUnicode: null
  20713. };
  20714. // Section 9.10.2 Mapping Character Codes to Unicode Values
  20715. if (properties.toUnicode && properties.toUnicode.length !== 0) {
  20716. map.toUnicode = properties.toUnicode;
  20717. return map;
  20718. }
  20719. // According to the spec if the font is a simple font we should only map
  20720. // to unicode if the base encoding is MacRoman, MacExpert, or WinAnsi or
  20721. // the differences array only contains adobe standard or symbol set names,
  20722. // in pratice it seems better to always try to create a toUnicode
  20723. // map based of the default encoding.
  20724. var toUnicode, charcode;
  20725. if (!properties.composite /* is simple font */) {
  20726. toUnicode = [];
  20727. var encoding = properties.defaultEncoding.slice();
  20728. var baseEncodingName = properties.baseEncodingName;
  20729. // Merge in the differences array.
  20730. var differences = properties.differences;
  20731. for (charcode in differences) {
  20732. encoding[charcode] = differences[charcode];
  20733. }
  20734. for (charcode in encoding) {
  20735. // a) Map the character code to a character name.
  20736. var glyphName = encoding[charcode];
  20737. // b) Look up the character name in the Adobe Glyph List (see the
  20738. // Bibliography) to obtain the corresponding Unicode value.
  20739. if (glyphName === '') {
  20740. continue;
  20741. } else if (GlyphsUnicode[glyphName] === undefined) {
  20742. // (undocumented) c) Few heuristics to recognize unknown glyphs
  20743. // NOTE: Adobe Reader does not do this step, but OSX Preview does
  20744. var code = 0;
  20745. switch (glyphName[0]) {
  20746. case 'G': // Gxx glyph
  20747. if (glyphName.length === 3) {
  20748. code = parseInt(glyphName.substr(1), 16);
  20749. }
  20750. break;
  20751. case 'g': // g00xx glyph
  20752. if (glyphName.length === 5) {
  20753. code = parseInt(glyphName.substr(1), 16);
  20754. }
  20755. break;
  20756. case 'C': // Cddd glyph
  20757. case 'c': // cddd glyph
  20758. if (glyphName.length >= 3) {
  20759. code = +glyphName.substr(1);
  20760. }
  20761. break;
  20762. }
  20763. if (code) {
  20764. // If |baseEncodingName| is one the predefined encodings,
  20765. // and |code| equals |charcode|, using the glyph defined in the
  20766. // baseEncoding seems to yield a better |toUnicode| mapping
  20767. // (fixes issue 5070).
  20768. if (baseEncodingName && code === +charcode) {
  20769. var baseEncoding = Encodings[baseEncodingName];
  20770. if (baseEncoding && (glyphName = baseEncoding[charcode])) {
  20771. toUnicode[charcode] =
  20772. String.fromCharCode(GlyphsUnicode[glyphName]);
  20773. continue;
  20774. }
  20775. }
  20776. toUnicode[charcode] = String.fromCharCode(code);
  20777. }
  20778. continue;
  20779. }
  20780. toUnicode[charcode] = String.fromCharCode(GlyphsUnicode[glyphName]);
  20781. }
  20782. map.toUnicode = toUnicode;
  20783. return map;
  20784. }
  20785. // If the font is a composite font that uses one of the predefined CMaps
  20786. // listed in Table 118 (except Identity–H and Identity–V) or whose
  20787. // descendant CIDFont uses the Adobe-GB1, Adobe-CNS1, Adobe-Japan1, or
  20788. // Adobe-Korea1 character collection:
  20789. if (properties.composite && (
  20790. (properties.cMap.builtInCMap &&
  20791. !(properties.cMap instanceof IdentityCMap)) ||
  20792. (properties.cidSystemInfo.registry === 'Adobe' &&
  20793. (properties.cidSystemInfo.ordering === 'GB1' ||
  20794. properties.cidSystemInfo.ordering === 'CNS1' ||
  20795. properties.cidSystemInfo.ordering === 'Japan1' ||
  20796. properties.cidSystemInfo.ordering === 'Korea1')))) {
  20797. // Then:
  20798. // a) Map the character code to a character identifier (CID) according
  20799. // to the font’s CMap.
  20800. // b) Obtain the registry and ordering of the character collection used
  20801. // by the font’s CMap (for example, Adobe and Japan1) from its
  20802. // CIDSystemInfo dictionary.
  20803. var registry = properties.cidSystemInfo.registry;
  20804. var ordering = properties.cidSystemInfo.ordering;
  20805. // c) Construct a second CMap name by concatenating the registry and
  20806. // ordering obtained in step (b) in the format registry–ordering–UCS2
  20807. // (for example, Adobe–Japan1–UCS2).
  20808. var ucs2CMapName = new Name(registry + '-' + ordering + '-UCS2');
  20809. // d) Obtain the CMap with the name constructed in step (c) (available
  20810. // from the ASN Web site; see the Bibliography).
  20811. var ucs2CMap = CMapFactory.create(ucs2CMapName,
  20812. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  20813. var cMap = properties.cMap;
  20814. toUnicode = [];
  20815. cMap.forEach(function(charcode, cid) {
  20816. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  20817. // e) Map the CID obtained in step (a) according to the CMap obtained
  20818. // in step (d), producing a Unicode value.
  20819. var ucs2 = ucs2CMap.lookup(cid);
  20820. if (ucs2) {
  20821. toUnicode[charcode] =
  20822. String.fromCharCode((ucs2.charCodeAt(0) << 8) +
  20823. ucs2.charCodeAt(1));
  20824. }
  20825. });
  20826. map.toUnicode = toUnicode;
  20827. return map;
  20828. }
  20829. // The viewer's choice, just use an identity map.
  20830. toUnicode = [];
  20831. var firstChar = properties.firstChar, lastChar = properties.lastChar;
  20832. for (var i = firstChar; i <= lastChar; i++) {
  20833. toUnicode[i] = String.fromCharCode(i);
  20834. }
  20835. map.isIdentity = true;
  20836. map.toUnicode = toUnicode;
  20837. return map;
  20838. },
  20839. get spaceWidth() {
  20840. if ('_shadowWidth' in this) {
  20841. return this._shadowWidth;
  20842. }
  20843. // trying to estimate space character width
  20844. var possibleSpaceReplacements = ['space', 'minus', 'one', 'i'];
  20845. var width;
  20846. for (var i = 0, ii = possibleSpaceReplacements.length; i < ii; i++) {
  20847. var glyphName = possibleSpaceReplacements[i];
  20848. // if possible, getting width by glyph name
  20849. if (glyphName in this.widths) {
  20850. width = this.widths[glyphName];
  20851. break;
  20852. }
  20853. var glyphUnicode = GlyphsUnicode[glyphName];
  20854. // finding the charcode via unicodeToCID map
  20855. var charcode = 0;
  20856. if (this.composite) {
  20857. if (this.cMap.contains(glyphUnicode)) {
  20858. charcode = this.cMap.lookup(glyphUnicode);
  20859. }
  20860. }
  20861. // ... via toUnicode map
  20862. if (!charcode && 'toUnicode' in this) {
  20863. charcode = this.toUnicode.indexOf(glyphUnicode);
  20864. }
  20865. // setting it to unicode if negative or undefined
  20866. if (charcode <= 0) {
  20867. charcode = glyphUnicode;
  20868. }
  20869. // trying to get width via charcode
  20870. width = this.widths[charcode];
  20871. if (width) {
  20872. break; // the non-zero width found
  20873. }
  20874. }
  20875. width = width || this.defaultWidth;
  20876. // Do not shadow the property here. See discussion:
  20877. // https://github.com/mozilla/pdf.js/pull/2127#discussion_r1662280
  20878. this._shadowWidth = width;
  20879. return width;
  20880. },
  20881. charToGlyph: function Font_charToGlyph(charcode) {
  20882. var fontCharCode, width, operatorListId;
  20883. var widthCode = charcode;
  20884. if (this.cMap && this.cMap.contains(charcode)) {
  20885. widthCode = this.cMap.lookup(charcode);
  20886. }
  20887. width = this.widths[widthCode];
  20888. width = isNum(width) ? width : this.defaultWidth;
  20889. var vmetric = this.vmetrics && this.vmetrics[widthCode];
  20890. var unicode = this.toUnicode[charcode] || charcode;
  20891. if (typeof unicode === 'number') {
  20892. unicode = String.fromCharCode(unicode);
  20893. }
  20894. // First try the toFontChar map, if it's not there then try falling
  20895. // back to the char code.
  20896. fontCharCode = this.toFontChar[charcode] || charcode;
  20897. if (this.missingFile) {
  20898. fontCharCode = mapSpecialUnicodeValues(fontCharCode);
  20899. }
  20900. if (this.isType3Font) {
  20901. // Font char code in this case is actually a glyph name.
  20902. operatorListId = fontCharCode;
  20903. }
  20904. var accent = null;
  20905. if (this.seacMap && this.seacMap[charcode]) {
  20906. var seac = this.seacMap[charcode];
  20907. fontCharCode = seac.baseFontCharCode;
  20908. accent = {
  20909. fontChar: String.fromCharCode(seac.accentFontCharCode),
  20910. offset: seac.accentOffset
  20911. };
  20912. }
  20913. var fontChar = String.fromCharCode(fontCharCode);
  20914. var glyph = this.glyphCache[charcode];
  20915. if (!glyph ||
  20916. !glyph.matchesForCache(fontChar, unicode, accent, width, vmetric,
  20917. operatorListId)) {
  20918. glyph = new Glyph(fontChar, unicode, accent, width, vmetric,
  20919. operatorListId);
  20920. this.glyphCache[charcode] = glyph;
  20921. }
  20922. return glyph;
  20923. },
  20924. charsToGlyphs: function Font_charsToGlyphs(chars) {
  20925. var charsCache = this.charsCache;
  20926. var glyphs, glyph, charcode;
  20927. // if we translated this string before, just grab it from the cache
  20928. if (charsCache) {
  20929. glyphs = charsCache[chars];
  20930. if (glyphs) {
  20931. return glyphs;
  20932. }
  20933. }
  20934. // lazily create the translation cache
  20935. if (!charsCache) {
  20936. charsCache = this.charsCache = Object.create(null);
  20937. }
  20938. glyphs = [];
  20939. var charsCacheKey = chars;
  20940. var i = 0, ii;
  20941. if (this.cMap) {
  20942. // composite fonts have multi-byte strings convert the string from
  20943. // single-byte to multi-byte
  20944. while (i < chars.length) {
  20945. var c = this.cMap.readCharCode(chars, i);
  20946. charcode = c[0];
  20947. var length = c[1];
  20948. i += length;
  20949. glyph = this.charToGlyph(charcode);
  20950. glyphs.push(glyph);
  20951. // placing null after each word break charcode (ASCII SPACE)
  20952. // Ignore occurences of 0x20 in multiple-byte codes.
  20953. if (length === 1 && chars.charCodeAt(i - 1) === 0x20) {
  20954. glyphs.push(null);
  20955. }
  20956. }
  20957. } else {
  20958. for (i = 0, ii = chars.length; i < ii; ++i) {
  20959. charcode = chars.charCodeAt(i);
  20960. glyph = this.charToGlyph(charcode);
  20961. glyphs.push(glyph);
  20962. if (charcode === 0x20) {
  20963. glyphs.push(null);
  20964. }
  20965. }
  20966. }
  20967. // Enter the translated string into the cache
  20968. return (charsCache[charsCacheKey] = glyphs);
  20969. }
  20970. };
  20971. return Font;
  20972. })();
  20973. var ErrorFont = (function ErrorFontClosure() {
  20974. function ErrorFont(error) {
  20975. this.error = error;
  20976. this.loadedName = 'g_font_error';
  20977. this.loading = false;
  20978. }
  20979. ErrorFont.prototype = {
  20980. charsToGlyphs: function ErrorFont_charsToGlyphs() {
  20981. return [];
  20982. },
  20983. exportData: function ErrorFont_exportData() {
  20984. return {error: this.error};
  20985. }
  20986. };
  20987. return ErrorFont;
  20988. })();
  20989. /**
  20990. * Shared logic for building a char code to glyph id mapping for Type1 and
  20991. * simple CFF fonts. See section 9.6.6.2 of the spec.
  20992. * @param {Object} properties Font properties object.
  20993. * @param {Object} builtInEncoding The encoding contained within the actual font
  20994. * data.
  20995. * @param {Array} Array of glyph names where the index is the glyph ID.
  20996. * @returns {Object} A char code to glyph ID map.
  20997. */
  20998. function type1FontGlyphMapping(properties, builtInEncoding, glyphNames) {
  20999. var charCodeToGlyphId = Object.create(null);
  21000. var glyphId, charCode, baseEncoding;
  21001. if (properties.baseEncodingName) {
  21002. // If a valid base encoding name was used, the mapping is initialized with
  21003. // that.
  21004. baseEncoding = Encodings[properties.baseEncodingName];
  21005. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  21006. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  21007. if (glyphId >= 0) {
  21008. charCodeToGlyphId[charCode] = glyphId;
  21009. }
  21010. }
  21011. } else if (!!(properties.flags & FontFlags.Symbolic)) {
  21012. // For a symbolic font the encoding should be the fonts built-in
  21013. // encoding.
  21014. for (charCode in builtInEncoding) {
  21015. charCodeToGlyphId[charCode] = builtInEncoding[charCode];
  21016. }
  21017. } else {
  21018. // For non-symbolic fonts that don't have a base encoding the standard
  21019. // encoding should be used.
  21020. baseEncoding = Encodings.StandardEncoding;
  21021. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  21022. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  21023. if (glyphId >= 0) {
  21024. charCodeToGlyphId[charCode] = glyphId;
  21025. }
  21026. }
  21027. }
  21028. // Lastly, merge in the differences.
  21029. var differences = properties.differences;
  21030. if (differences) {
  21031. for (charCode in differences) {
  21032. var glyphName = differences[charCode];
  21033. glyphId = glyphNames.indexOf(glyphName);
  21034. if (glyphId >= 0) {
  21035. charCodeToGlyphId[charCode] = glyphId;
  21036. }
  21037. }
  21038. }
  21039. return charCodeToGlyphId;
  21040. }
  21041. /*
  21042. * CharStrings are encoded following the the CharString Encoding sequence
  21043. * describe in Chapter 6 of the "Adobe Type1 Font Format" specification.
  21044. * The value in a byte indicates a command, a number, or subsequent bytes
  21045. * that are to be interpreted in a special way.
  21046. *
  21047. * CharString Number Encoding:
  21048. * A CharString byte containing the values from 32 through 255 inclusive
  21049. * indicate an integer. These values are decoded in four ranges.
  21050. *
  21051. * 1. A CharString byte containing a value, v, between 32 and 246 inclusive,
  21052. * indicate the integer v - 139. Thus, the integer values from -107 through
  21053. * 107 inclusive may be encoded in single byte.
  21054. *
  21055. * 2. A CharString byte containing a value, v, between 247 and 250 inclusive,
  21056. * indicates an integer involving the next byte, w, according to the formula:
  21057. * [(v - 247) x 256] + w + 108
  21058. *
  21059. * 3. A CharString byte containing a value, v, between 251 and 254 inclusive,
  21060. * indicates an integer involving the next byte, w, according to the formula:
  21061. * -[(v - 251) * 256] - w - 108
  21062. *
  21063. * 4. A CharString containing the value 255 indicates that the next 4 bytes
  21064. * are a two complement signed integer. The first of these bytes contains the
  21065. * highest order bits, the second byte contains the next higher order bits
  21066. * and the fourth byte contain the lowest order bits.
  21067. *
  21068. *
  21069. * CharString Command Encoding:
  21070. * CharStrings commands are encoded in 1 or 2 bytes.
  21071. *
  21072. * Single byte commands are encoded in 1 byte that contains a value between
  21073. * 0 and 31 inclusive.
  21074. * If a command byte contains the value 12, then the value in the next byte
  21075. * indicates a command. This "escape" mechanism allows many extra commands
  21076. * to be encoded and this encoding technique helps to minimize the length of
  21077. * the charStrings.
  21078. */
  21079. var Type1CharString = (function Type1CharStringClosure() {
  21080. var COMMAND_MAP = {
  21081. 'hstem': [1],
  21082. 'vstem': [3],
  21083. 'vmoveto': [4],
  21084. 'rlineto': [5],
  21085. 'hlineto': [6],
  21086. 'vlineto': [7],
  21087. 'rrcurveto': [8],
  21088. 'callsubr': [10],
  21089. 'flex': [12, 35],
  21090. 'drop' : [12, 18],
  21091. 'endchar': [14],
  21092. 'rmoveto': [21],
  21093. 'hmoveto': [22],
  21094. 'vhcurveto': [30],
  21095. 'hvcurveto': [31]
  21096. };
  21097. function Type1CharString() {
  21098. this.width = 0;
  21099. this.lsb = 0;
  21100. this.flexing = false;
  21101. this.output = [];
  21102. this.stack = [];
  21103. }
  21104. Type1CharString.prototype = {
  21105. convert: function Type1CharString_convert(encoded, subrs) {
  21106. var count = encoded.length;
  21107. var error = false;
  21108. var wx, sbx, subrNumber;
  21109. for (var i = 0; i < count; i++) {
  21110. var value = encoded[i];
  21111. if (value < 32) {
  21112. if (value === 12) {
  21113. value = (value << 8) + encoded[++i];
  21114. }
  21115. switch (value) {
  21116. case 1: // hstem
  21117. if (!HINTING_ENABLED) {
  21118. this.stack = [];
  21119. break;
  21120. }
  21121. error = this.executeCommand(2, COMMAND_MAP.hstem);
  21122. break;
  21123. case 3: // vstem
  21124. if (!HINTING_ENABLED) {
  21125. this.stack = [];
  21126. break;
  21127. }
  21128. error = this.executeCommand(2, COMMAND_MAP.vstem);
  21129. break;
  21130. case 4: // vmoveto
  21131. if (this.flexing) {
  21132. if (this.stack.length < 1) {
  21133. error = true;
  21134. break;
  21135. }
  21136. // Add the dx for flex and but also swap the values so they are
  21137. // the right order.
  21138. var dy = this.stack.pop();
  21139. this.stack.push(0, dy);
  21140. break;
  21141. }
  21142. error = this.executeCommand(1, COMMAND_MAP.vmoveto);
  21143. break;
  21144. case 5: // rlineto
  21145. error = this.executeCommand(2, COMMAND_MAP.rlineto);
  21146. break;
  21147. case 6: // hlineto
  21148. error = this.executeCommand(1, COMMAND_MAP.hlineto);
  21149. break;
  21150. case 7: // vlineto
  21151. error = this.executeCommand(1, COMMAND_MAP.vlineto);
  21152. break;
  21153. case 8: // rrcurveto
  21154. error = this.executeCommand(6, COMMAND_MAP.rrcurveto);
  21155. break;
  21156. case 9: // closepath
  21157. // closepath is a Type1 command that does not take argument and is
  21158. // useless in Type2 and it can simply be ignored.
  21159. this.stack = [];
  21160. break;
  21161. case 10: // callsubr
  21162. if (this.stack.length < 1) {
  21163. error = true;
  21164. break;
  21165. }
  21166. subrNumber = this.stack.pop();
  21167. error = this.convert(subrs[subrNumber], subrs);
  21168. break;
  21169. case 11: // return
  21170. return error;
  21171. case 13: // hsbw
  21172. if (this.stack.length < 2) {
  21173. error = true;
  21174. break;
  21175. }
  21176. // To convert to type2 we have to move the width value to the
  21177. // first part of the charstring and then use hmoveto with lsb.
  21178. wx = this.stack.pop();
  21179. sbx = this.stack.pop();
  21180. this.lsb = sbx;
  21181. this.width = wx;
  21182. this.stack.push(sbx);
  21183. error = this.executeCommand(1, COMMAND_MAP.hmoveto);
  21184. break;
  21185. case 14: // endchar
  21186. this.output.push(COMMAND_MAP.endchar[0]);
  21187. break;
  21188. case 21: // rmoveto
  21189. if (this.flexing) {
  21190. break;
  21191. }
  21192. error = this.executeCommand(2, COMMAND_MAP.rmoveto);
  21193. break;
  21194. case 22: // hmoveto
  21195. if (this.flexing) {
  21196. // Add the dy for flex.
  21197. this.stack.push(0);
  21198. break;
  21199. }
  21200. error = this.executeCommand(1, COMMAND_MAP.hmoveto);
  21201. break;
  21202. case 30: // vhcurveto
  21203. error = this.executeCommand(4, COMMAND_MAP.vhcurveto);
  21204. break;
  21205. case 31: // hvcurveto
  21206. error = this.executeCommand(4, COMMAND_MAP.hvcurveto);
  21207. break;
  21208. case (12 << 8) + 0: // dotsection
  21209. // dotsection is a Type1 command to specify some hinting feature
  21210. // for dots that do not take a parameter and it can safely be
  21211. // ignored for Type2.
  21212. this.stack = [];
  21213. break;
  21214. case (12 << 8) + 1: // vstem3
  21215. if (!HINTING_ENABLED) {
  21216. this.stack = [];
  21217. break;
  21218. }
  21219. // [vh]stem3 are Type1 only and Type2 supports [vh]stem with
  21220. // multiple parameters, so instead of returning [vh]stem3 take a
  21221. // shortcut and return [vhstem] instead.
  21222. error = this.executeCommand(2, COMMAND_MAP.vstem);
  21223. break;
  21224. case (12 << 8) + 2: // hstem3
  21225. if (!HINTING_ENABLED) {
  21226. this.stack = [];
  21227. break;
  21228. }
  21229. // See vstem3.
  21230. error = this.executeCommand(2, COMMAND_MAP.hstem);
  21231. break;
  21232. case (12 << 8) + 6: // seac
  21233. // seac is like type 2's special endchar but it doesn't use the
  21234. // first argument asb, so remove it.
  21235. if (SEAC_ANALYSIS_ENABLED) {
  21236. this.seac = this.stack.splice(-4, 4);
  21237. error = this.executeCommand(0, COMMAND_MAP.endchar);
  21238. } else {
  21239. error = this.executeCommand(4, COMMAND_MAP.endchar);
  21240. }
  21241. break;
  21242. case (12 << 8) + 7: // sbw
  21243. if (this.stack.length < 4) {
  21244. error = true;
  21245. break;
  21246. }
  21247. // To convert to type2 we have to move the width value to the
  21248. // first part of the charstring and then use rmoveto with
  21249. // (dx, dy). The height argument will not be used for vmtx and
  21250. // vhea tables reconstruction -- ignoring it.
  21251. var wy = this.stack.pop();
  21252. wx = this.stack.pop();
  21253. var sby = this.stack.pop();
  21254. sbx = this.stack.pop();
  21255. this.lsb = sbx;
  21256. this.width = wx;
  21257. this.stack.push(sbx, sby);
  21258. error = this.executeCommand(2, COMMAND_MAP.rmoveto);
  21259. break;
  21260. case (12 << 8) + 12: // div
  21261. if (this.stack.length < 2) {
  21262. error = true;
  21263. break;
  21264. }
  21265. var num2 = this.stack.pop();
  21266. var num1 = this.stack.pop();
  21267. this.stack.push(num1 / num2);
  21268. break;
  21269. case (12 << 8) + 16: // callothersubr
  21270. if (this.stack.length < 2) {
  21271. error = true;
  21272. break;
  21273. }
  21274. subrNumber = this.stack.pop();
  21275. var numArgs = this.stack.pop();
  21276. if (subrNumber === 0 && numArgs === 3) {
  21277. var flexArgs = this.stack.splice(this.stack.length - 17, 17);
  21278. this.stack.push(
  21279. flexArgs[2] + flexArgs[0], // bcp1x + rpx
  21280. flexArgs[3] + flexArgs[1], // bcp1y + rpy
  21281. flexArgs[4], // bcp2x
  21282. flexArgs[5], // bcp2y
  21283. flexArgs[6], // p2x
  21284. flexArgs[7], // p2y
  21285. flexArgs[8], // bcp3x
  21286. flexArgs[9], // bcp3y
  21287. flexArgs[10], // bcp4x
  21288. flexArgs[11], // bcp4y
  21289. flexArgs[12], // p3x
  21290. flexArgs[13], // p3y
  21291. flexArgs[14] // flexDepth
  21292. // 15 = finalx unused by flex
  21293. // 16 = finaly unused by flex
  21294. );
  21295. error = this.executeCommand(13, COMMAND_MAP.flex, true);
  21296. this.flexing = false;
  21297. this.stack.push(flexArgs[15], flexArgs[16]);
  21298. } else if (subrNumber === 1 && numArgs === 0) {
  21299. this.flexing = true;
  21300. }
  21301. break;
  21302. case (12 << 8) + 17: // pop
  21303. // Ignore this since it is only used with othersubr.
  21304. break;
  21305. case (12 << 8) + 33: // setcurrentpoint
  21306. // Ignore for now.
  21307. this.stack = [];
  21308. break;
  21309. default:
  21310. warn('Unknown type 1 charstring command of "' + value + '"');
  21311. break;
  21312. }
  21313. if (error) {
  21314. break;
  21315. }
  21316. continue;
  21317. } else if (value <= 246) {
  21318. value = value - 139;
  21319. } else if (value <= 250) {
  21320. value = ((value - 247) * 256) + encoded[++i] + 108;
  21321. } else if (value <= 254) {
  21322. value = -((value - 251) * 256) - encoded[++i] - 108;
  21323. } else {
  21324. value = (encoded[++i] & 0xff) << 24 | (encoded[++i] & 0xff) << 16 |
  21325. (encoded[++i] & 0xff) << 8 | (encoded[++i] & 0xff) << 0;
  21326. }
  21327. this.stack.push(value);
  21328. }
  21329. return error;
  21330. },
  21331. executeCommand: function(howManyArgs, command, keepStack) {
  21332. var stackLength = this.stack.length;
  21333. if (howManyArgs > stackLength) {
  21334. return true;
  21335. }
  21336. var start = stackLength - howManyArgs;
  21337. for (var i = start; i < stackLength; i++) {
  21338. var value = this.stack[i];
  21339. if (value === (value | 0)) { // int
  21340. this.output.push(28, (value >> 8) & 0xff, value & 0xff);
  21341. } else { // fixed point
  21342. value = (65536 * value) | 0;
  21343. this.output.push(255,
  21344. (value >> 24) & 0xFF,
  21345. (value >> 16) & 0xFF,
  21346. (value >> 8) & 0xFF,
  21347. value & 0xFF);
  21348. }
  21349. }
  21350. this.output.push.apply(this.output, command);
  21351. if (keepStack) {
  21352. this.stack.splice(start, howManyArgs);
  21353. } else {
  21354. this.stack.length = 0;
  21355. }
  21356. return false;
  21357. }
  21358. };
  21359. return Type1CharString;
  21360. })();
  21361. /*
  21362. * Type1Parser encapsulate the needed code for parsing a Type1 font
  21363. * program. Some of its logic depends on the Type2 charstrings
  21364. * structure.
  21365. * Note: this doesn't really parse the font since that would require evaluation
  21366. * of PostScript, but it is possible in most cases to extract what we need
  21367. * without a full parse.
  21368. */
  21369. var Type1Parser = (function Type1ParserClosure() {
  21370. /*
  21371. * Decrypt a Sequence of Ciphertext Bytes to Produce the Original Sequence
  21372. * of Plaintext Bytes. The function took a key as a parameter which can be
  21373. * for decrypting the eexec block of for decoding charStrings.
  21374. */
  21375. var EEXEC_ENCRYPT_KEY = 55665;
  21376. var CHAR_STRS_ENCRYPT_KEY = 4330;
  21377. function isHexDigit(code) {
  21378. return code >= 48 && code <= 57 || // '0'-'9'
  21379. code >= 65 && code <= 70 || // 'A'-'F'
  21380. code >= 97 && code <= 102; // 'a'-'f'
  21381. }
  21382. function decrypt(data, key, discardNumber) {
  21383. var r = key | 0, c1 = 52845, c2 = 22719;
  21384. var count = data.length;
  21385. var decrypted = new Uint8Array(count);
  21386. for (var i = 0; i < count; i++) {
  21387. var value = data[i];
  21388. decrypted[i] = value ^ (r >> 8);
  21389. r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
  21390. }
  21391. return Array.prototype.slice.call(decrypted, discardNumber);
  21392. }
  21393. function decryptAscii(data, key, discardNumber) {
  21394. var r = key | 0, c1 = 52845, c2 = 22719;
  21395. var count = data.length, maybeLength = count >>> 1;
  21396. var decrypted = new Uint8Array(maybeLength);
  21397. var i, j;
  21398. for (i = 0, j = 0; i < count; i++) {
  21399. var digit1 = data[i];
  21400. if (!isHexDigit(digit1)) {
  21401. continue;
  21402. }
  21403. i++;
  21404. var digit2;
  21405. while (i < count && !isHexDigit(digit2 = data[i])) {
  21406. i++;
  21407. }
  21408. if (i < count) {
  21409. var value = parseInt(String.fromCharCode(digit1, digit2), 16);
  21410. decrypted[j++] = value ^ (r >> 8);
  21411. r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
  21412. }
  21413. }
  21414. return Array.prototype.slice.call(decrypted, discardNumber, j);
  21415. }
  21416. function isSpecial(c) {
  21417. return c === 0x2F || // '/'
  21418. c === 0x5B || c === 0x5D || // '[', ']'
  21419. c === 0x7B || c === 0x7D || // '{', '}'
  21420. c === 0x28 || c === 0x29; // '(', ')'
  21421. }
  21422. function Type1Parser(stream, encrypted) {
  21423. if (encrypted) {
  21424. var data = stream.getBytes();
  21425. var isBinary = !(isHexDigit(data[0]) && isHexDigit(data[1]) &&
  21426. isHexDigit(data[2]) && isHexDigit(data[3]));
  21427. stream = new Stream(isBinary ? decrypt(data, EEXEC_ENCRYPT_KEY, 4) :
  21428. decryptAscii(data, EEXEC_ENCRYPT_KEY, 4));
  21429. }
  21430. this.stream = stream;
  21431. this.nextChar();
  21432. }
  21433. Type1Parser.prototype = {
  21434. readNumberArray: function Type1Parser_readNumberArray() {
  21435. this.getToken(); // read '[' or '{' (arrays can start with either)
  21436. var array = [];
  21437. while (true) {
  21438. var token = this.getToken();
  21439. if (token === null || token === ']' || token === '}') {
  21440. break;
  21441. }
  21442. array.push(parseFloat(token || 0));
  21443. }
  21444. return array;
  21445. },
  21446. readNumber: function Type1Parser_readNumber() {
  21447. var token = this.getToken();
  21448. return parseFloat(token || 0);
  21449. },
  21450. readInt: function Type1Parser_readInt() {
  21451. // Use '| 0' to prevent setting a double into length such as the double
  21452. // does not flow into the loop variable.
  21453. var token = this.getToken();
  21454. return parseInt(token || 0, 10) | 0;
  21455. },
  21456. readBoolean: function Type1Parser_readBoolean() {
  21457. var token = this.getToken();
  21458. // Use 1 and 0 since that's what type2 charstrings use.
  21459. return token === 'true' ? 1 : 0;
  21460. },
  21461. nextChar : function Type1_nextChar() {
  21462. return (this.currentChar = this.stream.getByte());
  21463. },
  21464. getToken: function Type1Parser_getToken() {
  21465. // Eat whitespace and comments.
  21466. var comment = false;
  21467. var ch = this.currentChar;
  21468. while (true) {
  21469. if (ch === -1) {
  21470. return null;
  21471. }
  21472. if (comment) {
  21473. if (ch === 0x0A || ch === 0x0D) {
  21474. comment = false;
  21475. }
  21476. } else if (ch === 0x25) { // '%'
  21477. comment = true;
  21478. } else if (!Lexer.isSpace(ch)) {
  21479. break;
  21480. }
  21481. ch = this.nextChar();
  21482. }
  21483. if (isSpecial(ch)) {
  21484. this.nextChar();
  21485. return String.fromCharCode(ch);
  21486. }
  21487. var token = '';
  21488. do {
  21489. token += String.fromCharCode(ch);
  21490. ch = this.nextChar();
  21491. } while (ch >= 0 && !Lexer.isSpace(ch) && !isSpecial(ch));
  21492. return token;
  21493. },
  21494. /*
  21495. * Returns an object containing a Subrs array and a CharStrings
  21496. * array extracted from and eexec encrypted block of data
  21497. */
  21498. extractFontProgram: function Type1Parser_extractFontProgram() {
  21499. var stream = this.stream;
  21500. var subrs = [], charstrings = [];
  21501. var program = {
  21502. subrs: [],
  21503. charstrings: [],
  21504. properties: {
  21505. 'privateData': {
  21506. 'lenIV': 4
  21507. }
  21508. }
  21509. };
  21510. var token, length, data, lenIV, encoded;
  21511. while ((token = this.getToken()) !== null) {
  21512. if (token !== '/') {
  21513. continue;
  21514. }
  21515. token = this.getToken();
  21516. switch (token) {
  21517. case 'CharStrings':
  21518. // The number immediately following CharStrings must be greater or
  21519. // equal to the number of CharStrings.
  21520. this.getToken();
  21521. this.getToken(); // read in 'dict'
  21522. this.getToken(); // read in 'dup'
  21523. this.getToken(); // read in 'begin'
  21524. while(true) {
  21525. token = this.getToken();
  21526. if (token === null || token === 'end') {
  21527. break;
  21528. }
  21529. if (token !== '/') {
  21530. continue;
  21531. }
  21532. var glyph = this.getToken();
  21533. length = this.readInt();
  21534. this.getToken(); // read in 'RD' or '-|'
  21535. data = stream.makeSubStream(stream.pos, length);
  21536. lenIV = program.properties.privateData['lenIV'];
  21537. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  21538. // Skip past the required space and binary data.
  21539. stream.skip(length);
  21540. this.nextChar();
  21541. token = this.getToken(); // read in 'ND' or '|-'
  21542. if (token === 'noaccess') {
  21543. this.getToken(); // read in 'def'
  21544. }
  21545. charstrings.push({
  21546. glyph: glyph,
  21547. encoded: encoded
  21548. });
  21549. }
  21550. break;
  21551. case 'Subrs':
  21552. var num = this.readInt();
  21553. this.getToken(); // read in 'array'
  21554. while ((token = this.getToken()) === 'dup') {
  21555. var index = this.readInt();
  21556. length = this.readInt();
  21557. this.getToken(); // read in 'RD' or '-|'
  21558. data = stream.makeSubStream(stream.pos, length);
  21559. lenIV = program.properties.privateData['lenIV'];
  21560. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  21561. // Skip past the required space and binary data.
  21562. stream.skip(length);
  21563. this.nextChar();
  21564. token = this.getToken(); // read in 'NP' or '|'
  21565. if (token === 'noaccess') {
  21566. this.getToken(); // read in 'put'
  21567. }
  21568. subrs[index] = encoded;
  21569. }
  21570. break;
  21571. case 'BlueValues':
  21572. case 'OtherBlues':
  21573. case 'FamilyBlues':
  21574. case 'FamilyOtherBlues':
  21575. var blueArray = this.readNumberArray();
  21576. // *Blue* values may contain invalid data: disables reading of
  21577. // those values when hinting is disabled.
  21578. if (blueArray.length > 0 && (blueArray.length % 2) === 0 &&
  21579. HINTING_ENABLED) {
  21580. program.properties.privateData[token] = blueArray;
  21581. }
  21582. break;
  21583. case 'StemSnapH':
  21584. case 'StemSnapV':
  21585. program.properties.privateData[token] = this.readNumberArray();
  21586. break;
  21587. case 'StdHW':
  21588. case 'StdVW':
  21589. program.properties.privateData[token] =
  21590. this.readNumberArray()[0];
  21591. break;
  21592. case 'BlueShift':
  21593. case 'lenIV':
  21594. case 'BlueFuzz':
  21595. case 'BlueScale':
  21596. case 'LanguageGroup':
  21597. case 'ExpansionFactor':
  21598. program.properties.privateData[token] = this.readNumber();
  21599. break;
  21600. case 'ForceBold':
  21601. program.properties.privateData[token] = this.readBoolean();
  21602. break;
  21603. }
  21604. }
  21605. for (var i = 0; i < charstrings.length; i++) {
  21606. glyph = charstrings[i].glyph;
  21607. encoded = charstrings[i].encoded;
  21608. var charString = new Type1CharString();
  21609. var error = charString.convert(encoded, subrs);
  21610. var output = charString.output;
  21611. if (error) {
  21612. // It seems when FreeType encounters an error while evaluating a glyph
  21613. // that it completely ignores the glyph so we'll mimic that behaviour
  21614. // here and put an endchar to make the validator happy.
  21615. output = [14];
  21616. }
  21617. program.charstrings.push({
  21618. glyphName: glyph,
  21619. charstring: output,
  21620. width: charString.width,
  21621. lsb: charString.lsb,
  21622. seac: charString.seac
  21623. });
  21624. }
  21625. return program;
  21626. },
  21627. extractFontHeader: function Type1Parser_extractFontHeader(properties) {
  21628. var token;
  21629. while ((token = this.getToken()) !== null) {
  21630. if (token !== '/') {
  21631. continue;
  21632. }
  21633. token = this.getToken();
  21634. switch (token) {
  21635. case 'FontMatrix':
  21636. var matrix = this.readNumberArray();
  21637. properties.fontMatrix = matrix;
  21638. break;
  21639. case 'Encoding':
  21640. var encodingArg = this.getToken();
  21641. var encoding;
  21642. if (!/^\d+$/.test(encodingArg)) {
  21643. // encoding name is specified
  21644. encoding = Encodings[encodingArg];
  21645. } else {
  21646. encoding = [];
  21647. var size = parseInt(encodingArg, 10) | 0;
  21648. this.getToken(); // read in 'array'
  21649. for (var j = 0; j < size; j++) {
  21650. token = this.getToken();
  21651. // skipping till first dup or def (e.g. ignoring for statement)
  21652. while (token !== 'dup' && token !== 'def') {
  21653. token = this.getToken();
  21654. if (token === null) {
  21655. return; // invalid header
  21656. }
  21657. }
  21658. if (token === 'def') {
  21659. break; // read all array data
  21660. }
  21661. var index = this.readInt();
  21662. this.getToken(); // read in '/'
  21663. var glyph = this.getToken();
  21664. encoding[index] = glyph;
  21665. this.getToken(); // read the in 'put'
  21666. }
  21667. }
  21668. properties.builtInEncoding = encoding;
  21669. break;
  21670. case 'FontBBox':
  21671. var fontBBox = this.readNumberArray();
  21672. // adjusting ascent/descent
  21673. properties.ascent = fontBBox[3];
  21674. properties.descent = fontBBox[1];
  21675. properties.ascentScaled = true;
  21676. break;
  21677. }
  21678. }
  21679. }
  21680. };
  21681. return Type1Parser;
  21682. })();
  21683. /**
  21684. * The CFF class takes a Type1 file and wrap it into a
  21685. * 'Compact Font Format' which itself embed Type2 charstrings.
  21686. */
  21687. var CFFStandardStrings = [
  21688. '.notdef', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  21689. 'ampersand', 'quoteright', 'parenleft', 'parenright', 'asterisk', 'plus',
  21690. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three', 'four',
  21691. 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon', 'less',
  21692. 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
  21693. 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
  21694. 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright', 'asciicircum',
  21695. 'underscore', 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
  21696. 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y',
  21697. 'z', 'braceleft', 'bar', 'braceright', 'asciitilde', 'exclamdown', 'cent',
  21698. 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  21699. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  21700. 'guilsinglright', 'fi', 'fl', 'endash', 'dagger', 'daggerdbl',
  21701. 'periodcentered', 'paragraph', 'bullet', 'quotesinglbase', 'quotedblbase',
  21702. 'quotedblright', 'guillemotright', 'ellipsis', 'perthousand', 'questiondown',
  21703. 'grave', 'acute', 'circumflex', 'tilde', 'macron', 'breve', 'dotaccent',
  21704. 'dieresis', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron', 'emdash',
  21705. 'AE', 'ordfeminine', 'Lslash', 'Oslash', 'OE', 'ordmasculine', 'ae',
  21706. 'dotlessi', 'lslash', 'oslash', 'oe', 'germandbls', 'onesuperior',
  21707. 'logicalnot', 'mu', 'trademark', 'Eth', 'onehalf', 'plusminus', 'Thorn',
  21708. 'onequarter', 'divide', 'brokenbar', 'degree', 'thorn', 'threequarters',
  21709. 'twosuperior', 'registered', 'minus', 'eth', 'multiply', 'threesuperior',
  21710. 'copyright', 'Aacute', 'Acircumflex', 'Adieresis', 'Agrave', 'Aring',
  21711. 'Atilde', 'Ccedilla', 'Eacute', 'Ecircumflex', 'Edieresis', 'Egrave',
  21712. 'Iacute', 'Icircumflex', 'Idieresis', 'Igrave', 'Ntilde', 'Oacute',
  21713. 'Ocircumflex', 'Odieresis', 'Ograve', 'Otilde', 'Scaron', 'Uacute',
  21714. 'Ucircumflex', 'Udieresis', 'Ugrave', 'Yacute', 'Ydieresis', 'Zcaron',
  21715. 'aacute', 'acircumflex', 'adieresis', 'agrave', 'aring', 'atilde',
  21716. 'ccedilla', 'eacute', 'ecircumflex', 'edieresis', 'egrave', 'iacute',
  21717. 'icircumflex', 'idieresis', 'igrave', 'ntilde', 'oacute', 'ocircumflex',
  21718. 'odieresis', 'ograve', 'otilde', 'scaron', 'uacute', 'ucircumflex',
  21719. 'udieresis', 'ugrave', 'yacute', 'ydieresis', 'zcaron', 'exclamsmall',
  21720. 'Hungarumlautsmall', 'dollaroldstyle', 'dollarsuperior', 'ampersandsmall',
  21721. 'Acutesmall', 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  21722. 'onedotenleader', 'zerooldstyle', 'oneoldstyle', 'twooldstyle',
  21723. 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle', 'sixoldstyle',
  21724. 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle', 'commasuperior',
  21725. 'threequartersemdash', 'periodsuperior', 'questionsmall', 'asuperior',
  21726. 'bsuperior', 'centsuperior', 'dsuperior', 'esuperior', 'isuperior',
  21727. 'lsuperior', 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  21728. 'tsuperior', 'ff', 'ffi', 'ffl', 'parenleftinferior', 'parenrightinferior',
  21729. 'Circumflexsmall', 'hyphensuperior', 'Gravesmall', 'Asmall', 'Bsmall',
  21730. 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall', 'Hsmall', 'Ismall',
  21731. 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall', 'Osmall', 'Psmall',
  21732. 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall', 'Vsmall', 'Wsmall',
  21733. 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary', 'onefitted', 'rupiah',
  21734. 'Tildesmall', 'exclamdownsmall', 'centoldstyle', 'Lslashsmall',
  21735. 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall', 'Brevesmall', 'Caronsmall',
  21736. 'Dotaccentsmall', 'Macronsmall', 'figuredash', 'hypheninferior',
  21737. 'Ogoneksmall', 'Ringsmall', 'Cedillasmall', 'questiondownsmall', 'oneeighth',
  21738. 'threeeighths', 'fiveeighths', 'seveneighths', 'onethird', 'twothirds',
  21739. 'zerosuperior', 'foursuperior', 'fivesuperior', 'sixsuperior',
  21740. 'sevensuperior', 'eightsuperior', 'ninesuperior', 'zeroinferior',
  21741. 'oneinferior', 'twoinferior', 'threeinferior', 'fourinferior',
  21742. 'fiveinferior', 'sixinferior', 'seveninferior', 'eightinferior',
  21743. 'nineinferior', 'centinferior', 'dollarinferior', 'periodinferior',
  21744. 'commainferior', 'Agravesmall', 'Aacutesmall', 'Acircumflexsmall',
  21745. 'Atildesmall', 'Adieresissmall', 'Aringsmall', 'AEsmall', 'Ccedillasmall',
  21746. 'Egravesmall', 'Eacutesmall', 'Ecircumflexsmall', 'Edieresissmall',
  21747. 'Igravesmall', 'Iacutesmall', 'Icircumflexsmall', 'Idieresissmall',
  21748. 'Ethsmall', 'Ntildesmall', 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall',
  21749. 'Otildesmall', 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall',
  21750. 'Uacutesmall', 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall',
  21751. 'Thornsmall', 'Ydieresissmall', '001.000', '001.001', '001.002', '001.003',
  21752. 'Black', 'Bold', 'Book', 'Light', 'Medium', 'Regular', 'Roman', 'Semibold'
  21753. ];
  21754. // Type1Font is also a CIDFontType0.
  21755. var Type1Font = function Type1Font(name, file, properties) {
  21756. // Some bad generators embed pfb file as is, we have to strip 6-byte headers.
  21757. // Also, length1 and length2 might be off by 6 bytes as well.
  21758. // http://www.math.ubc.ca/~cass/piscript/type1.pdf
  21759. var PFB_HEADER_SIZE = 6;
  21760. var headerBlockLength = properties.length1;
  21761. var eexecBlockLength = properties.length2;
  21762. var pfbHeader = file.peekBytes(PFB_HEADER_SIZE);
  21763. var pfbHeaderPresent = pfbHeader[0] === 0x80 && pfbHeader[1] === 0x01;
  21764. if (pfbHeaderPresent) {
  21765. file.skip(PFB_HEADER_SIZE);
  21766. headerBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
  21767. (pfbHeader[3] << 8) | pfbHeader[2];
  21768. }
  21769. // Get the data block containing glyphs and subrs informations
  21770. var headerBlock = new Stream(file.getBytes(headerBlockLength));
  21771. var headerBlockParser = new Type1Parser(headerBlock);
  21772. headerBlockParser.extractFontHeader(properties);
  21773. if (pfbHeaderPresent) {
  21774. pfbHeader = file.getBytes(PFB_HEADER_SIZE);
  21775. eexecBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
  21776. (pfbHeader[3] << 8) | pfbHeader[2];
  21777. }
  21778. // Decrypt the data blocks and retrieve it's content
  21779. var eexecBlock = new Stream(file.getBytes(eexecBlockLength));
  21780. var eexecBlockParser = new Type1Parser(eexecBlock, true);
  21781. var data = eexecBlockParser.extractFontProgram();
  21782. for (var info in data.properties) {
  21783. properties[info] = data.properties[info];
  21784. }
  21785. var charstrings = data.charstrings;
  21786. var type2Charstrings = this.getType2Charstrings(charstrings);
  21787. var subrs = this.getType2Subrs(data.subrs);
  21788. this.charstrings = charstrings;
  21789. this.data = this.wrap(name, type2Charstrings, this.charstrings,
  21790. subrs, properties);
  21791. this.seacs = this.getSeacs(data.charstrings);
  21792. };
  21793. Type1Font.prototype = {
  21794. get numGlyphs() {
  21795. return this.charstrings.length + 1;
  21796. },
  21797. getCharset: function Type1Font_getCharset() {
  21798. var charset = ['.notdef'];
  21799. var charstrings = this.charstrings;
  21800. for (var glyphId = 0; glyphId < charstrings.length; glyphId++) {
  21801. charset.push(charstrings[glyphId].glyphName);
  21802. }
  21803. return charset;
  21804. },
  21805. getGlyphMapping: function Type1Font_getGlyphMapping(properties) {
  21806. var charstrings = this.charstrings;
  21807. var glyphNames = ['.notdef'], glyphId;
  21808. for (glyphId = 0; glyphId < charstrings.length; glyphId++) {
  21809. glyphNames.push(charstrings[glyphId].glyphName);
  21810. }
  21811. var encoding = properties.builtInEncoding;
  21812. if (encoding) {
  21813. var builtInEncoding = {};
  21814. for (var charCode in encoding) {
  21815. glyphId = glyphNames.indexOf(encoding[charCode]);
  21816. if (glyphId >= 0) {
  21817. builtInEncoding[charCode] = glyphId;
  21818. }
  21819. }
  21820. }
  21821. return type1FontGlyphMapping(properties, builtInEncoding, glyphNames);
  21822. },
  21823. getSeacs: function Type1Font_getSeacs(charstrings) {
  21824. var i, ii;
  21825. var seacMap = [];
  21826. for (i = 0, ii = charstrings.length; i < ii; i++) {
  21827. var charstring = charstrings[i];
  21828. if (charstring.seac) {
  21829. // Offset by 1 for .notdef
  21830. seacMap[i + 1] = charstring.seac;
  21831. }
  21832. }
  21833. return seacMap;
  21834. },
  21835. getType2Charstrings: function Type1Font_getType2Charstrings(
  21836. type1Charstrings) {
  21837. var type2Charstrings = [];
  21838. for (var i = 0, ii = type1Charstrings.length; i < ii; i++) {
  21839. type2Charstrings.push(type1Charstrings[i].charstring);
  21840. }
  21841. return type2Charstrings;
  21842. },
  21843. getType2Subrs: function Type1Font_getType2Subrs(type1Subrs) {
  21844. var bias = 0;
  21845. var count = type1Subrs.length;
  21846. if (count < 1133) {
  21847. bias = 107;
  21848. } else if (count < 33769) {
  21849. bias = 1131;
  21850. } else {
  21851. bias = 32768;
  21852. }
  21853. // Add a bunch of empty subrs to deal with the Type2 bias
  21854. var type2Subrs = [];
  21855. var i;
  21856. for (i = 0; i < bias; i++) {
  21857. type2Subrs.push([0x0B]);
  21858. }
  21859. for (i = 0; i < count; i++) {
  21860. type2Subrs.push(type1Subrs[i]);
  21861. }
  21862. return type2Subrs;
  21863. },
  21864. wrap: function Type1Font_wrap(name, glyphs, charstrings, subrs, properties) {
  21865. var cff = new CFF();
  21866. cff.header = new CFFHeader(1, 0, 4, 4);
  21867. cff.names = [name];
  21868. var topDict = new CFFTopDict();
  21869. // CFF strings IDs 0...390 are predefined names, so refering
  21870. // to entries in our own String INDEX starts at SID 391.
  21871. topDict.setByName('version', 391);
  21872. topDict.setByName('Notice', 392);
  21873. topDict.setByName('FullName', 393);
  21874. topDict.setByName('FamilyName', 394);
  21875. topDict.setByName('Weight', 395);
  21876. topDict.setByName('Encoding', null); // placeholder
  21877. topDict.setByName('FontMatrix', properties.fontMatrix);
  21878. topDict.setByName('FontBBox', properties.bbox);
  21879. topDict.setByName('charset', null); // placeholder
  21880. topDict.setByName('CharStrings', null); // placeholder
  21881. topDict.setByName('Private', null); // placeholder
  21882. cff.topDict = topDict;
  21883. var strings = new CFFStrings();
  21884. strings.add('Version 0.11'); // Version
  21885. strings.add('See original notice'); // Notice
  21886. strings.add(name); // FullName
  21887. strings.add(name); // FamilyName
  21888. strings.add('Medium'); // Weight
  21889. cff.strings = strings;
  21890. cff.globalSubrIndex = new CFFIndex();
  21891. var count = glyphs.length;
  21892. var charsetArray = [0];
  21893. var i, ii;
  21894. for (i = 0; i < count; i++) {
  21895. var index = CFFStandardStrings.indexOf(charstrings[i].glyphName);
  21896. // TODO: Insert the string and correctly map it. Previously it was
  21897. // thought mapping names that aren't in the standard strings to .notdef
  21898. // was fine, however in issue818 when mapping them all to .notdef the
  21899. // adieresis glyph no longer worked.
  21900. if (index === -1) {
  21901. index = 0;
  21902. }
  21903. charsetArray.push((index >> 8) & 0xff, index & 0xff);
  21904. }
  21905. cff.charset = new CFFCharset(false, 0, [], charsetArray);
  21906. var charStringsIndex = new CFFIndex();
  21907. charStringsIndex.add([0x8B, 0x0E]); // .notdef
  21908. for (i = 0; i < count; i++) {
  21909. charStringsIndex.add(glyphs[i]);
  21910. }
  21911. cff.charStrings = charStringsIndex;
  21912. var privateDict = new CFFPrivateDict();
  21913. privateDict.setByName('Subrs', null); // placeholder
  21914. var fields = [
  21915. 'BlueValues',
  21916. 'OtherBlues',
  21917. 'FamilyBlues',
  21918. 'FamilyOtherBlues',
  21919. 'StemSnapH',
  21920. 'StemSnapV',
  21921. 'BlueShift',
  21922. 'BlueFuzz',
  21923. 'BlueScale',
  21924. 'LanguageGroup',
  21925. 'ExpansionFactor',
  21926. 'ForceBold',
  21927. 'StdHW',
  21928. 'StdVW'
  21929. ];
  21930. for (i = 0, ii = fields.length; i < ii; i++) {
  21931. var field = fields[i];
  21932. if (!properties.privateData.hasOwnProperty(field)) {
  21933. continue;
  21934. }
  21935. var value = properties.privateData[field];
  21936. if (isArray(value)) {
  21937. // All of the private dictionary array data in CFF must be stored as
  21938. // "delta-encoded" numbers.
  21939. for (var j = value.length - 1; j > 0; j--) {
  21940. value[j] -= value[j - 1]; // ... difference from previous value
  21941. }
  21942. }
  21943. privateDict.setByName(field, value);
  21944. }
  21945. cff.topDict.privateDict = privateDict;
  21946. var subrIndex = new CFFIndex();
  21947. for (i = 0, ii = subrs.length; i < ii; i++) {
  21948. subrIndex.add(subrs[i]);
  21949. }
  21950. privateDict.subrsIndex = subrIndex;
  21951. var compiler = new CFFCompiler(cff);
  21952. return compiler.compile();
  21953. }
  21954. };
  21955. var CFFFont = (function CFFFontClosure() {
  21956. function CFFFont(file, properties) {
  21957. this.properties = properties;
  21958. var parser = new CFFParser(file, properties);
  21959. this.cff = parser.parse();
  21960. var compiler = new CFFCompiler(this.cff);
  21961. this.seacs = this.cff.seacs;
  21962. try {
  21963. this.data = compiler.compile();
  21964. } catch (e) {
  21965. warn('Failed to compile font ' + properties.loadedName);
  21966. // There may have just been an issue with the compiler, set the data
  21967. // anyway and hope the font loaded.
  21968. this.data = file;
  21969. }
  21970. }
  21971. CFFFont.prototype = {
  21972. get numGlyphs() {
  21973. return this.cff.charStrings.count;
  21974. },
  21975. getCharset: function CFFFont_getCharset() {
  21976. return this.cff.charset.charset;
  21977. },
  21978. getGlyphMapping: function CFFFont_getGlyphMapping() {
  21979. var cff = this.cff;
  21980. var properties = this.properties;
  21981. var charsets = cff.charset.charset;
  21982. var charCodeToGlyphId;
  21983. var glyphId;
  21984. if (properties.composite) {
  21985. charCodeToGlyphId = Object.create(null);
  21986. if (cff.isCIDFont) {
  21987. // If the font is actually a CID font then we should use the charset
  21988. // to map CIDs to GIDs.
  21989. for (glyphId = 0; glyphId < charsets.length; glyphId++) {
  21990. var cid = charsets[glyphId];
  21991. var charCode = properties.cMap.charCodeOf(cid);
  21992. charCodeToGlyphId[charCode] = glyphId;
  21993. }
  21994. } else {
  21995. // If it is NOT actually a CID font then CIDs should be mapped
  21996. // directly to GIDs.
  21997. for (glyphId = 0; glyphId < cff.charStrings.count; glyphId++) {
  21998. charCodeToGlyphId[glyphId] = glyphId;
  21999. }
  22000. }
  22001. return charCodeToGlyphId;
  22002. }
  22003. var encoding = cff.encoding ? cff.encoding.encoding : null;
  22004. charCodeToGlyphId = type1FontGlyphMapping(properties, encoding, charsets);
  22005. return charCodeToGlyphId;
  22006. }
  22007. };
  22008. return CFFFont;
  22009. })();
  22010. var CFFParser = (function CFFParserClosure() {
  22011. var CharstringValidationData = [
  22012. null,
  22013. { id: 'hstem', min: 2, resetStack: true, stem: true },
  22014. null,
  22015. { id: 'vstem', min: 2, resetStack: true, stem: true },
  22016. { id: 'vmoveto', min: 1, resetStack: true },
  22017. { id: 'rlineto', min: 2, resetStack: true },
  22018. { id: 'hlineto', min: 1, resetStack: true },
  22019. { id: 'vlineto', min: 1, resetStack: true },
  22020. { id: 'rrcurveto', min: 6, resetStack: true },
  22021. null,
  22022. { id: 'callsubr', min: 1, undefStack: true },
  22023. { id: 'return', min: 0, undefStack: true },
  22024. null, // 12
  22025. null,
  22026. null, // endchar
  22027. null,
  22028. null,
  22029. null,
  22030. { id: 'hstemhm', min: 2, resetStack: true, stem: true },
  22031. null, // hintmask
  22032. null, // cntrmask
  22033. { id: 'rmoveto', min: 2, resetStack: true },
  22034. { id: 'hmoveto', min: 1, resetStack: true },
  22035. { id: 'vstemhm', min: 2, resetStack: true, stem: true },
  22036. { id: 'rcurveline', min: 8, resetStack: true },
  22037. { id: 'rlinecurve', min: 8, resetStack: true },
  22038. { id: 'vvcurveto', min: 4, resetStack: true },
  22039. { id: 'hhcurveto', min: 4, resetStack: true },
  22040. null, // shortint
  22041. { id: 'callgsubr', min: 1, undefStack: true },
  22042. { id: 'vhcurveto', min: 4, resetStack: true },
  22043. { id: 'hvcurveto', min: 4, resetStack: true }
  22044. ];
  22045. var CharstringValidationData12 = [
  22046. null,
  22047. null,
  22048. null,
  22049. { id: 'and', min: 2, stackDelta: -1 },
  22050. { id: 'or', min: 2, stackDelta: -1 },
  22051. { id: 'not', min: 1, stackDelta: 0 },
  22052. null,
  22053. null,
  22054. null,
  22055. { id: 'abs', min: 1, stackDelta: 0 },
  22056. { id: 'add', min: 2, stackDelta: -1,
  22057. stackFn: function stack_div(stack, index) {
  22058. stack[index - 2] = stack[index - 2] + stack[index - 1];
  22059. }
  22060. },
  22061. { id: 'sub', min: 2, stackDelta: -1,
  22062. stackFn: function stack_div(stack, index) {
  22063. stack[index - 2] = stack[index - 2] - stack[index - 1];
  22064. }
  22065. },
  22066. { id: 'div', min: 2, stackDelta: -1,
  22067. stackFn: function stack_div(stack, index) {
  22068. stack[index - 2] = stack[index - 2] / stack[index - 1];
  22069. }
  22070. },
  22071. null,
  22072. { id: 'neg', min: 1, stackDelta: 0,
  22073. stackFn: function stack_div(stack, index) {
  22074. stack[index - 1] = -stack[index - 1];
  22075. }
  22076. },
  22077. { id: 'eq', min: 2, stackDelta: -1 },
  22078. null,
  22079. null,
  22080. { id: 'drop', min: 1, stackDelta: -1 },
  22081. null,
  22082. { id: 'put', min: 2, stackDelta: -2 },
  22083. { id: 'get', min: 1, stackDelta: 0 },
  22084. { id: 'ifelse', min: 4, stackDelta: -3 },
  22085. { id: 'random', min: 0, stackDelta: 1 },
  22086. { id: 'mul', min: 2, stackDelta: -1,
  22087. stackFn: function stack_div(stack, index) {
  22088. stack[index - 2] = stack[index - 2] * stack[index - 1];
  22089. }
  22090. },
  22091. null,
  22092. { id: 'sqrt', min: 1, stackDelta: 0 },
  22093. { id: 'dup', min: 1, stackDelta: 1 },
  22094. { id: 'exch', min: 2, stackDelta: 0 },
  22095. { id: 'index', min: 2, stackDelta: 0 },
  22096. { id: 'roll', min: 3, stackDelta: -2 },
  22097. null,
  22098. null,
  22099. null,
  22100. { id: 'hflex', min: 7, resetStack: true },
  22101. { id: 'flex', min: 13, resetStack: true },
  22102. { id: 'hflex1', min: 9, resetStack: true },
  22103. { id: 'flex1', min: 11, resetStack: true }
  22104. ];
  22105. function CFFParser(file, properties) {
  22106. this.bytes = file.getBytes();
  22107. this.properties = properties;
  22108. }
  22109. CFFParser.prototype = {
  22110. parse: function CFFParser_parse() {
  22111. var properties = this.properties;
  22112. var cff = new CFF();
  22113. this.cff = cff;
  22114. // The first five sections must be in order, all the others are reached
  22115. // via offsets contained in one of the below.
  22116. var header = this.parseHeader();
  22117. var nameIndex = this.parseIndex(header.endPos);
  22118. var topDictIndex = this.parseIndex(nameIndex.endPos);
  22119. var stringIndex = this.parseIndex(topDictIndex.endPos);
  22120. var globalSubrIndex = this.parseIndex(stringIndex.endPos);
  22121. var topDictParsed = this.parseDict(topDictIndex.obj.get(0));
  22122. var topDict = this.createDict(CFFTopDict, topDictParsed, cff.strings);
  22123. cff.header = header.obj;
  22124. cff.names = this.parseNameIndex(nameIndex.obj);
  22125. cff.strings = this.parseStringIndex(stringIndex.obj);
  22126. cff.topDict = topDict;
  22127. cff.globalSubrIndex = globalSubrIndex.obj;
  22128. this.parsePrivateDict(cff.topDict);
  22129. cff.isCIDFont = topDict.hasName('ROS');
  22130. var charStringOffset = topDict.getByName('CharStrings');
  22131. var charStringsAndSeacs = this.parseCharStrings(charStringOffset);
  22132. cff.charStrings = charStringsAndSeacs.charStrings;
  22133. cff.seacs = charStringsAndSeacs.seacs;
  22134. var fontMatrix = topDict.getByName('FontMatrix');
  22135. if (fontMatrix) {
  22136. properties.fontMatrix = fontMatrix;
  22137. }
  22138. var fontBBox = topDict.getByName('FontBBox');
  22139. if (fontBBox) {
  22140. // adjusting ascent/descent
  22141. properties.ascent = fontBBox[3];
  22142. properties.descent = fontBBox[1];
  22143. properties.ascentScaled = true;
  22144. }
  22145. var charset, encoding;
  22146. if (cff.isCIDFont) {
  22147. var fdArrayIndex = this.parseIndex(topDict.getByName('FDArray')).obj;
  22148. for (var i = 0, ii = fdArrayIndex.count; i < ii; ++i) {
  22149. var dictRaw = fdArrayIndex.get(i);
  22150. var fontDict = this.createDict(CFFTopDict, this.parseDict(dictRaw),
  22151. cff.strings);
  22152. this.parsePrivateDict(fontDict);
  22153. cff.fdArray.push(fontDict);
  22154. }
  22155. // cid fonts don't have an encoding
  22156. encoding = null;
  22157. charset = this.parseCharsets(topDict.getByName('charset'),
  22158. cff.charStrings.count, cff.strings, true);
  22159. cff.fdSelect = this.parseFDSelect(topDict.getByName('FDSelect'),
  22160. cff.charStrings.count);
  22161. } else {
  22162. charset = this.parseCharsets(topDict.getByName('charset'),
  22163. cff.charStrings.count, cff.strings, false);
  22164. encoding = this.parseEncoding(topDict.getByName('Encoding'),
  22165. properties,
  22166. cff.strings, charset.charset);
  22167. }
  22168. cff.charset = charset;
  22169. cff.encoding = encoding;
  22170. return cff;
  22171. },
  22172. parseHeader: function CFFParser_parseHeader() {
  22173. var bytes = this.bytes;
  22174. var bytesLength = bytes.length;
  22175. var offset = 0;
  22176. // Prevent an infinite loop, by checking that the offset is within the
  22177. // bounds of the bytes array. Necessary in empty, or invalid, font files.
  22178. while (offset < bytesLength && bytes[offset] !== 1) {
  22179. ++offset;
  22180. }
  22181. if (offset >= bytesLength) {
  22182. error('Invalid CFF header');
  22183. } else if (offset !== 0) {
  22184. info('cff data is shifted');
  22185. bytes = bytes.subarray(offset);
  22186. this.bytes = bytes;
  22187. }
  22188. var major = bytes[0];
  22189. var minor = bytes[1];
  22190. var hdrSize = bytes[2];
  22191. var offSize = bytes[3];
  22192. var header = new CFFHeader(major, minor, hdrSize, offSize);
  22193. return { obj: header, endPos: hdrSize };
  22194. },
  22195. parseDict: function CFFParser_parseDict(dict) {
  22196. var pos = 0;
  22197. function parseOperand() {
  22198. var value = dict[pos++];
  22199. if (value === 30) {
  22200. return parseFloatOperand(pos);
  22201. } else if (value === 28) {
  22202. value = dict[pos++];
  22203. value = ((value << 24) | (dict[pos++] << 16)) >> 16;
  22204. return value;
  22205. } else if (value === 29) {
  22206. value = dict[pos++];
  22207. value = (value << 8) | dict[pos++];
  22208. value = (value << 8) | dict[pos++];
  22209. value = (value << 8) | dict[pos++];
  22210. return value;
  22211. } else if (value >= 32 && value <= 246) {
  22212. return value - 139;
  22213. } else if (value >= 247 && value <= 250) {
  22214. return ((value - 247) * 256) + dict[pos++] + 108;
  22215. } else if (value >= 251 && value <= 254) {
  22216. return -((value - 251) * 256) - dict[pos++] - 108;
  22217. } else {
  22218. error('255 is not a valid DICT command');
  22219. }
  22220. return -1;
  22221. }
  22222. function parseFloatOperand() {
  22223. var str = '';
  22224. var eof = 15;
  22225. var lookup = ['0', '1', '2', '3', '4', '5', '6', '7', '8',
  22226. '9', '.', 'E', 'E-', null, '-'];
  22227. var length = dict.length;
  22228. while (pos < length) {
  22229. var b = dict[pos++];
  22230. var b1 = b >> 4;
  22231. var b2 = b & 15;
  22232. if (b1 === eof) {
  22233. break;
  22234. }
  22235. str += lookup[b1];
  22236. if (b2 === eof) {
  22237. break;
  22238. }
  22239. str += lookup[b2];
  22240. }
  22241. return parseFloat(str);
  22242. }
  22243. var operands = [];
  22244. var entries = [];
  22245. pos = 0;
  22246. var end = dict.length;
  22247. while (pos < end) {
  22248. var b = dict[pos];
  22249. if (b <= 21) {
  22250. if (b === 12) {
  22251. b = (b << 8) | dict[++pos];
  22252. }
  22253. entries.push([b, operands]);
  22254. operands = [];
  22255. ++pos;
  22256. } else {
  22257. operands.push(parseOperand());
  22258. }
  22259. }
  22260. return entries;
  22261. },
  22262. parseIndex: function CFFParser_parseIndex(pos) {
  22263. var cffIndex = new CFFIndex();
  22264. var bytes = this.bytes;
  22265. var count = (bytes[pos++] << 8) | bytes[pos++];
  22266. var offsets = [];
  22267. var end = pos;
  22268. var i, ii;
  22269. if (count !== 0) {
  22270. var offsetSize = bytes[pos++];
  22271. // add 1 for offset to determine size of last object
  22272. var startPos = pos + ((count + 1) * offsetSize) - 1;
  22273. for (i = 0, ii = count + 1; i < ii; ++i) {
  22274. var offset = 0;
  22275. for (var j = 0; j < offsetSize; ++j) {
  22276. offset <<= 8;
  22277. offset += bytes[pos++];
  22278. }
  22279. offsets.push(startPos + offset);
  22280. }
  22281. end = offsets[count];
  22282. }
  22283. for (i = 0, ii = offsets.length - 1; i < ii; ++i) {
  22284. var offsetStart = offsets[i];
  22285. var offsetEnd = offsets[i + 1];
  22286. cffIndex.add(bytes.subarray(offsetStart, offsetEnd));
  22287. }
  22288. return {obj: cffIndex, endPos: end};
  22289. },
  22290. parseNameIndex: function CFFParser_parseNameIndex(index) {
  22291. var names = [];
  22292. for (var i = 0, ii = index.count; i < ii; ++i) {
  22293. var name = index.get(i);
  22294. // OTS doesn't allow names to be over 127 characters.
  22295. var length = Math.min(name.length, 127);
  22296. var data = [];
  22297. // OTS also only permits certain characters in the name.
  22298. for (var j = 0; j < length; ++j) {
  22299. var c = name[j];
  22300. if (j === 0 && c === 0) {
  22301. data[j] = c;
  22302. continue;
  22303. }
  22304. if ((c < 33 || c > 126) || c === 91 /* [ */ || c === 93 /* ] */ ||
  22305. c === 40 /* ( */ || c === 41 /* ) */ || c === 123 /* { */ ||
  22306. c === 125 /* } */ || c === 60 /* < */ || c === 62 /* > */ ||
  22307. c === 47 /* / */ || c === 37 /* % */ || c === 35 /* # */) {
  22308. data[j] = 95;
  22309. continue;
  22310. }
  22311. data[j] = c;
  22312. }
  22313. names.push(bytesToString(data));
  22314. }
  22315. return names;
  22316. },
  22317. parseStringIndex: function CFFParser_parseStringIndex(index) {
  22318. var strings = new CFFStrings();
  22319. for (var i = 0, ii = index.count; i < ii; ++i) {
  22320. var data = index.get(i);
  22321. strings.add(bytesToString(data));
  22322. }
  22323. return strings;
  22324. },
  22325. createDict: function CFFParser_createDict(Type, dict, strings) {
  22326. var cffDict = new Type(strings);
  22327. for (var i = 0, ii = dict.length; i < ii; ++i) {
  22328. var pair = dict[i];
  22329. var key = pair[0];
  22330. var value = pair[1];
  22331. cffDict.setByKey(key, value);
  22332. }
  22333. return cffDict;
  22334. },
  22335. parseCharStrings: function CFFParser_parseCharStrings(charStringOffset) {
  22336. var charStrings = this.parseIndex(charStringOffset).obj;
  22337. var seacs = [];
  22338. var count = charStrings.count;
  22339. for (var i = 0; i < count; i++) {
  22340. var charstring = charStrings.get(i);
  22341. var stackSize = 0;
  22342. var stack = [];
  22343. var undefStack = true;
  22344. var hints = 0;
  22345. var valid = true;
  22346. var data = charstring;
  22347. var length = data.length;
  22348. for (var j = 0; j < length;) {
  22349. var value = data[j++];
  22350. var validationCommand = null;
  22351. if (value === 12) {
  22352. var q = data[j++];
  22353. if (q === 0) {
  22354. // The CFF specification state that the 'dotsection' command
  22355. // (12, 0) is deprecated and treated as a no-op, but all Type2
  22356. // charstrings processors should support them. Unfortunately
  22357. // the font sanitizer don't. As a workaround the sequence (12, 0)
  22358. // is replaced by a useless (0, hmoveto).
  22359. data[j - 2] = 139;
  22360. data[j - 1] = 22;
  22361. stackSize = 0;
  22362. } else {
  22363. validationCommand = CharstringValidationData12[q];
  22364. }
  22365. } else if (value === 28) { // number (16 bit)
  22366. stack[stackSize] = ((data[j] << 24) | (data[j + 1] << 16)) >> 16;
  22367. j += 2;
  22368. stackSize++;
  22369. } else if (value === 14) {
  22370. if (stackSize >= 4) {
  22371. stackSize -= 4;
  22372. if (SEAC_ANALYSIS_ENABLED) {
  22373. seacs[i] = stack.slice(stackSize, stackSize + 4);
  22374. valid = false;
  22375. }
  22376. }
  22377. } else if (value >= 32 && value <= 246) { // number
  22378. stack[stackSize] = value - 139;
  22379. stackSize++;
  22380. } else if (value >= 247 && value <= 254) { // number (+1 bytes)
  22381. stack[stackSize] = (value < 251 ?
  22382. ((value - 247) << 8) + data[j] + 108 :
  22383. -((value - 251) << 8) - data[j] - 108);
  22384. j++;
  22385. stackSize++;
  22386. } else if (value === 255) { // number (32 bit)
  22387. stack[stackSize] = ((data[j] << 24) | (data[j + 1] << 16) |
  22388. (data[j + 2] << 8) | data[j + 3]) / 65536;
  22389. j += 4;
  22390. stackSize++;
  22391. } else if (value === 19 || value === 20) {
  22392. hints += stackSize >> 1;
  22393. j += (hints + 7) >> 3; // skipping right amount of hints flag data
  22394. stackSize = 0;
  22395. } else {
  22396. validationCommand = CharstringValidationData[value];
  22397. }
  22398. if (validationCommand) {
  22399. if (validationCommand.stem) {
  22400. hints += stackSize >> 1;
  22401. }
  22402. if ('min' in validationCommand) {
  22403. if (!undefStack && stackSize < validationCommand.min) {
  22404. warn('Not enough parameters for ' + validationCommand.id +
  22405. '; actual: ' + stackSize +
  22406. ', expected: ' + validationCommand.min);
  22407. valid = false;
  22408. break;
  22409. }
  22410. }
  22411. if ('stackDelta' in validationCommand) {
  22412. if ('stackFn' in validationCommand) {
  22413. validationCommand.stackFn(stack, stackSize);
  22414. }
  22415. stackSize += validationCommand.stackDelta;
  22416. } else if (validationCommand.resetStack) {
  22417. stackSize = 0;
  22418. undefStack = false;
  22419. } else if (validationCommand.undefStack) {
  22420. stackSize = 0;
  22421. undefStack = true;
  22422. }
  22423. }
  22424. }
  22425. if (!valid) {
  22426. // resetting invalid charstring to single 'endchar'
  22427. charStrings.set(i, new Uint8Array([14]));
  22428. }
  22429. }
  22430. return { charStrings: charStrings, seacs: seacs };
  22431. },
  22432. emptyPrivateDictionary:
  22433. function CFFParser_emptyPrivateDictionary(parentDict) {
  22434. var privateDict = this.createDict(CFFPrivateDict, [],
  22435. parentDict.strings);
  22436. parentDict.setByKey(18, [0, 0]);
  22437. parentDict.privateDict = privateDict;
  22438. },
  22439. parsePrivateDict: function CFFParser_parsePrivateDict(parentDict) {
  22440. // no private dict, do nothing
  22441. if (!parentDict.hasName('Private')) {
  22442. this.emptyPrivateDictionary(parentDict);
  22443. return;
  22444. }
  22445. var privateOffset = parentDict.getByName('Private');
  22446. // make sure the params are formatted correctly
  22447. if (!isArray(privateOffset) || privateOffset.length !== 2) {
  22448. parentDict.removeByName('Private');
  22449. return;
  22450. }
  22451. var size = privateOffset[0];
  22452. var offset = privateOffset[1];
  22453. // remove empty dicts or ones that refer to invalid location
  22454. if (size === 0 || offset >= this.bytes.length) {
  22455. this.emptyPrivateDictionary(parentDict);
  22456. return;
  22457. }
  22458. var privateDictEnd = offset + size;
  22459. var dictData = this.bytes.subarray(offset, privateDictEnd);
  22460. var dict = this.parseDict(dictData);
  22461. var privateDict = this.createDict(CFFPrivateDict, dict,
  22462. parentDict.strings);
  22463. parentDict.privateDict = privateDict;
  22464. // Parse the Subrs index also since it's relative to the private dict.
  22465. if (!privateDict.getByName('Subrs')) {
  22466. return;
  22467. }
  22468. var subrsOffset = privateDict.getByName('Subrs');
  22469. var relativeOffset = offset + subrsOffset;
  22470. // Validate the offset.
  22471. if (subrsOffset === 0 || relativeOffset >= this.bytes.length) {
  22472. this.emptyPrivateDictionary(parentDict);
  22473. return;
  22474. }
  22475. var subrsIndex = this.parseIndex(relativeOffset);
  22476. privateDict.subrsIndex = subrsIndex.obj;
  22477. },
  22478. parseCharsets: function CFFParser_parseCharsets(pos, length, strings, cid) {
  22479. if (pos === 0) {
  22480. return new CFFCharset(true, CFFCharsetPredefinedTypes.ISO_ADOBE,
  22481. ISOAdobeCharset);
  22482. } else if (pos === 1) {
  22483. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT,
  22484. ExpertCharset);
  22485. } else if (pos === 2) {
  22486. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT_SUBSET,
  22487. ExpertSubsetCharset);
  22488. }
  22489. var bytes = this.bytes;
  22490. var start = pos;
  22491. var format = bytes[pos++];
  22492. var charset = ['.notdef'];
  22493. var id, count, i;
  22494. // subtract 1 for the .notdef glyph
  22495. length -= 1;
  22496. switch (format) {
  22497. case 0:
  22498. for (i = 0; i < length; i++) {
  22499. id = (bytes[pos++] << 8) | bytes[pos++];
  22500. charset.push(cid ? id : strings.get(id));
  22501. }
  22502. break;
  22503. case 1:
  22504. while (charset.length <= length) {
  22505. id = (bytes[pos++] << 8) | bytes[pos++];
  22506. count = bytes[pos++];
  22507. for (i = 0; i <= count; i++) {
  22508. charset.push(cid ? id++ : strings.get(id++));
  22509. }
  22510. }
  22511. break;
  22512. case 2:
  22513. while (charset.length <= length) {
  22514. id = (bytes[pos++] << 8) | bytes[pos++];
  22515. count = (bytes[pos++] << 8) | bytes[pos++];
  22516. for (i = 0; i <= count; i++) {
  22517. charset.push(cid ? id++ : strings.get(id++));
  22518. }
  22519. }
  22520. break;
  22521. default:
  22522. error('Unknown charset format');
  22523. }
  22524. // Raw won't be needed if we actually compile the charset.
  22525. var end = pos;
  22526. var raw = bytes.subarray(start, end);
  22527. return new CFFCharset(false, format, charset, raw);
  22528. },
  22529. parseEncoding: function CFFParser_parseEncoding(pos,
  22530. properties,
  22531. strings,
  22532. charset) {
  22533. var encoding = {};
  22534. var bytes = this.bytes;
  22535. var predefined = false;
  22536. var hasSupplement = false;
  22537. var format, i, ii;
  22538. var raw = null;
  22539. function readSupplement() {
  22540. var supplementsCount = bytes[pos++];
  22541. for (i = 0; i < supplementsCount; i++) {
  22542. var code = bytes[pos++];
  22543. var sid = (bytes[pos++] << 8) + (bytes[pos++] & 0xff);
  22544. encoding[code] = charset.indexOf(strings.get(sid));
  22545. }
  22546. }
  22547. if (pos === 0 || pos === 1) {
  22548. predefined = true;
  22549. format = pos;
  22550. var baseEncoding = pos ? Encodings.ExpertEncoding :
  22551. Encodings.StandardEncoding;
  22552. for (i = 0, ii = charset.length; i < ii; i++) {
  22553. var index = baseEncoding.indexOf(charset[i]);
  22554. if (index !== -1) {
  22555. encoding[index] = i;
  22556. }
  22557. }
  22558. } else {
  22559. var dataStart = pos;
  22560. format = bytes[pos++];
  22561. switch (format & 0x7f) {
  22562. case 0:
  22563. var glyphsCount = bytes[pos++];
  22564. for (i = 1; i <= glyphsCount; i++) {
  22565. encoding[bytes[pos++]] = i;
  22566. }
  22567. break;
  22568. case 1:
  22569. var rangesCount = bytes[pos++];
  22570. var gid = 1;
  22571. for (i = 0; i < rangesCount; i++) {
  22572. var start = bytes[pos++];
  22573. var left = bytes[pos++];
  22574. for (var j = start; j <= start + left; j++) {
  22575. encoding[j] = gid++;
  22576. }
  22577. }
  22578. break;
  22579. default:
  22580. error('Unknow encoding format: ' + format + ' in CFF');
  22581. break;
  22582. }
  22583. var dataEnd = pos;
  22584. if (format & 0x80) {
  22585. // The font sanitizer does not support CFF encoding with a
  22586. // supplement, since the encoding is not really used to map
  22587. // between gid to glyph, let's overwrite what is declared in
  22588. // the top dictionary to let the sanitizer think the font use
  22589. // StandardEncoding, that's a lie but that's ok.
  22590. bytes[dataStart] &= 0x7f;
  22591. readSupplement();
  22592. hasSupplement = true;
  22593. }
  22594. raw = bytes.subarray(dataStart, dataEnd);
  22595. }
  22596. format = format & 0x7f;
  22597. return new CFFEncoding(predefined, format, encoding, raw);
  22598. },
  22599. parseFDSelect: function CFFParser_parseFDSelect(pos, length) {
  22600. var start = pos;
  22601. var bytes = this.bytes;
  22602. var format = bytes[pos++];
  22603. var fdSelect = [];
  22604. var i;
  22605. switch (format) {
  22606. case 0:
  22607. for (i = 0; i < length; ++i) {
  22608. var id = bytes[pos++];
  22609. fdSelect.push(id);
  22610. }
  22611. break;
  22612. case 3:
  22613. var rangesCount = (bytes[pos++] << 8) | bytes[pos++];
  22614. for (i = 0; i < rangesCount; ++i) {
  22615. var first = (bytes[pos++] << 8) | bytes[pos++];
  22616. var fdIndex = bytes[pos++];
  22617. var next = (bytes[pos] << 8) | bytes[pos + 1];
  22618. for (var j = first; j < next; ++j) {
  22619. fdSelect.push(fdIndex);
  22620. }
  22621. }
  22622. // Advance past the sentinel(next).
  22623. pos += 2;
  22624. break;
  22625. default:
  22626. error('Unknown fdselect format ' + format);
  22627. break;
  22628. }
  22629. var end = pos;
  22630. return new CFFFDSelect(fdSelect, bytes.subarray(start, end));
  22631. }
  22632. };
  22633. return CFFParser;
  22634. })();
  22635. // Compact Font Format
  22636. var CFF = (function CFFClosure() {
  22637. function CFF() {
  22638. this.header = null;
  22639. this.names = [];
  22640. this.topDict = null;
  22641. this.strings = new CFFStrings();
  22642. this.globalSubrIndex = null;
  22643. // The following could really be per font, but since we only have one font
  22644. // store them here.
  22645. this.encoding = null;
  22646. this.charset = null;
  22647. this.charStrings = null;
  22648. this.fdArray = [];
  22649. this.fdSelect = null;
  22650. this.isCIDFont = false;
  22651. }
  22652. return CFF;
  22653. })();
  22654. var CFFHeader = (function CFFHeaderClosure() {
  22655. function CFFHeader(major, minor, hdrSize, offSize) {
  22656. this.major = major;
  22657. this.minor = minor;
  22658. this.hdrSize = hdrSize;
  22659. this.offSize = offSize;
  22660. }
  22661. return CFFHeader;
  22662. })();
  22663. var CFFStrings = (function CFFStringsClosure() {
  22664. function CFFStrings() {
  22665. this.strings = [];
  22666. }
  22667. CFFStrings.prototype = {
  22668. get: function CFFStrings_get(index) {
  22669. if (index >= 0 && index <= 390) {
  22670. return CFFStandardStrings[index];
  22671. }
  22672. if (index - 391 <= this.strings.length) {
  22673. return this.strings[index - 391];
  22674. }
  22675. return CFFStandardStrings[0];
  22676. },
  22677. add: function CFFStrings_add(value) {
  22678. this.strings.push(value);
  22679. },
  22680. get count() {
  22681. return this.strings.length;
  22682. }
  22683. };
  22684. return CFFStrings;
  22685. })();
  22686. var CFFIndex = (function CFFIndexClosure() {
  22687. function CFFIndex() {
  22688. this.objects = [];
  22689. this.length = 0;
  22690. }
  22691. CFFIndex.prototype = {
  22692. add: function CFFIndex_add(data) {
  22693. this.length += data.length;
  22694. this.objects.push(data);
  22695. },
  22696. set: function CFFIndex_set(index, data) {
  22697. this.length += data.length - this.objects[index].length;
  22698. this.objects[index] = data;
  22699. },
  22700. get: function CFFIndex_get(index) {
  22701. return this.objects[index];
  22702. },
  22703. get count() {
  22704. return this.objects.length;
  22705. }
  22706. };
  22707. return CFFIndex;
  22708. })();
  22709. var CFFDict = (function CFFDictClosure() {
  22710. function CFFDict(tables, strings) {
  22711. this.keyToNameMap = tables.keyToNameMap;
  22712. this.nameToKeyMap = tables.nameToKeyMap;
  22713. this.defaults = tables.defaults;
  22714. this.types = tables.types;
  22715. this.opcodes = tables.opcodes;
  22716. this.order = tables.order;
  22717. this.strings = strings;
  22718. this.values = {};
  22719. }
  22720. CFFDict.prototype = {
  22721. // value should always be an array
  22722. setByKey: function CFFDict_setByKey(key, value) {
  22723. if (!(key in this.keyToNameMap)) {
  22724. return false;
  22725. }
  22726. // ignore empty values
  22727. if (value.length === 0) {
  22728. return true;
  22729. }
  22730. var type = this.types[key];
  22731. // remove the array wrapping these types of values
  22732. if (type === 'num' || type === 'sid' || type === 'offset') {
  22733. value = value[0];
  22734. }
  22735. this.values[key] = value;
  22736. return true;
  22737. },
  22738. setByName: function CFFDict_setByName(name, value) {
  22739. if (!(name in this.nameToKeyMap)) {
  22740. error('Invalid dictionary name "' + name + '"');
  22741. }
  22742. this.values[this.nameToKeyMap[name]] = value;
  22743. },
  22744. hasName: function CFFDict_hasName(name) {
  22745. return this.nameToKeyMap[name] in this.values;
  22746. },
  22747. getByName: function CFFDict_getByName(name) {
  22748. if (!(name in this.nameToKeyMap)) {
  22749. error('Invalid dictionary name "' + name + '"');
  22750. }
  22751. var key = this.nameToKeyMap[name];
  22752. if (!(key in this.values)) {
  22753. return this.defaults[key];
  22754. }
  22755. return this.values[key];
  22756. },
  22757. removeByName: function CFFDict_removeByName(name) {
  22758. delete this.values[this.nameToKeyMap[name]];
  22759. }
  22760. };
  22761. CFFDict.createTables = function CFFDict_createTables(layout) {
  22762. var tables = {
  22763. keyToNameMap: {},
  22764. nameToKeyMap: {},
  22765. defaults: {},
  22766. types: {},
  22767. opcodes: {},
  22768. order: []
  22769. };
  22770. for (var i = 0, ii = layout.length; i < ii; ++i) {
  22771. var entry = layout[i];
  22772. var key = isArray(entry[0]) ? (entry[0][0] << 8) + entry[0][1] : entry[0];
  22773. tables.keyToNameMap[key] = entry[1];
  22774. tables.nameToKeyMap[entry[1]] = key;
  22775. tables.types[key] = entry[2];
  22776. tables.defaults[key] = entry[3];
  22777. tables.opcodes[key] = isArray(entry[0]) ? entry[0] : [entry[0]];
  22778. tables.order.push(key);
  22779. }
  22780. return tables;
  22781. };
  22782. return CFFDict;
  22783. })();
  22784. var CFFTopDict = (function CFFTopDictClosure() {
  22785. var layout = [
  22786. [[12, 30], 'ROS', ['sid', 'sid', 'num'], null],
  22787. [[12, 20], 'SyntheticBase', 'num', null],
  22788. [0, 'version', 'sid', null],
  22789. [1, 'Notice', 'sid', null],
  22790. [[12, 0], 'Copyright', 'sid', null],
  22791. [2, 'FullName', 'sid', null],
  22792. [3, 'FamilyName', 'sid', null],
  22793. [4, 'Weight', 'sid', null],
  22794. [[12, 1], 'isFixedPitch', 'num', 0],
  22795. [[12, 2], 'ItalicAngle', 'num', 0],
  22796. [[12, 3], 'UnderlinePosition', 'num', -100],
  22797. [[12, 4], 'UnderlineThickness', 'num', 50],
  22798. [[12, 5], 'PaintType', 'num', 0],
  22799. [[12, 6], 'CharstringType', 'num', 2],
  22800. [[12, 7], 'FontMatrix', ['num', 'num', 'num', 'num', 'num', 'num'],
  22801. [0.001, 0, 0, 0.001, 0, 0]],
  22802. [13, 'UniqueID', 'num', null],
  22803. [5, 'FontBBox', ['num', 'num', 'num', 'num'], [0, 0, 0, 0]],
  22804. [[12, 8], 'StrokeWidth', 'num', 0],
  22805. [14, 'XUID', 'array', null],
  22806. [15, 'charset', 'offset', 0],
  22807. [16, 'Encoding', 'offset', 0],
  22808. [17, 'CharStrings', 'offset', 0],
  22809. [18, 'Private', ['offset', 'offset'], null],
  22810. [[12, 21], 'PostScript', 'sid', null],
  22811. [[12, 22], 'BaseFontName', 'sid', null],
  22812. [[12, 23], 'BaseFontBlend', 'delta', null],
  22813. [[12, 31], 'CIDFontVersion', 'num', 0],
  22814. [[12, 32], 'CIDFontRevision', 'num', 0],
  22815. [[12, 33], 'CIDFontType', 'num', 0],
  22816. [[12, 34], 'CIDCount', 'num', 8720],
  22817. [[12, 35], 'UIDBase', 'num', null],
  22818. // XXX: CID Fonts on DirectWrite 6.1 only seem to work if FDSelect comes
  22819. // before FDArray.
  22820. [[12, 37], 'FDSelect', 'offset', null],
  22821. [[12, 36], 'FDArray', 'offset', null],
  22822. [[12, 38], 'FontName', 'sid', null]
  22823. ];
  22824. var tables = null;
  22825. function CFFTopDict(strings) {
  22826. if (tables === null) {
  22827. tables = CFFDict.createTables(layout);
  22828. }
  22829. CFFDict.call(this, tables, strings);
  22830. this.privateDict = null;
  22831. }
  22832. CFFTopDict.prototype = Object.create(CFFDict.prototype);
  22833. return CFFTopDict;
  22834. })();
  22835. var CFFPrivateDict = (function CFFPrivateDictClosure() {
  22836. var layout = [
  22837. [6, 'BlueValues', 'delta', null],
  22838. [7, 'OtherBlues', 'delta', null],
  22839. [8, 'FamilyBlues', 'delta', null],
  22840. [9, 'FamilyOtherBlues', 'delta', null],
  22841. [[12, 9], 'BlueScale', 'num', 0.039625],
  22842. [[12, 10], 'BlueShift', 'num', 7],
  22843. [[12, 11], 'BlueFuzz', 'num', 1],
  22844. [10, 'StdHW', 'num', null],
  22845. [11, 'StdVW', 'num', null],
  22846. [[12, 12], 'StemSnapH', 'delta', null],
  22847. [[12, 13], 'StemSnapV', 'delta', null],
  22848. [[12, 14], 'ForceBold', 'num', 0],
  22849. [[12, 17], 'LanguageGroup', 'num', 0],
  22850. [[12, 18], 'ExpansionFactor', 'num', 0.06],
  22851. [[12, 19], 'initialRandomSeed', 'num', 0],
  22852. [20, 'defaultWidthX', 'num', 0],
  22853. [21, 'nominalWidthX', 'num', 0],
  22854. [19, 'Subrs', 'offset', null]
  22855. ];
  22856. var tables = null;
  22857. function CFFPrivateDict(strings) {
  22858. if (tables === null) {
  22859. tables = CFFDict.createTables(layout);
  22860. }
  22861. CFFDict.call(this, tables, strings);
  22862. this.subrsIndex = null;
  22863. }
  22864. CFFPrivateDict.prototype = Object.create(CFFDict.prototype);
  22865. return CFFPrivateDict;
  22866. })();
  22867. var CFFCharsetPredefinedTypes = {
  22868. ISO_ADOBE: 0,
  22869. EXPERT: 1,
  22870. EXPERT_SUBSET: 2
  22871. };
  22872. var CFFCharset = (function CFFCharsetClosure() {
  22873. function CFFCharset(predefined, format, charset, raw) {
  22874. this.predefined = predefined;
  22875. this.format = format;
  22876. this.charset = charset;
  22877. this.raw = raw;
  22878. }
  22879. return CFFCharset;
  22880. })();
  22881. var CFFEncoding = (function CFFEncodingClosure() {
  22882. function CFFEncoding(predefined, format, encoding, raw) {
  22883. this.predefined = predefined;
  22884. this.format = format;
  22885. this.encoding = encoding;
  22886. this.raw = raw;
  22887. }
  22888. return CFFEncoding;
  22889. })();
  22890. var CFFFDSelect = (function CFFFDSelectClosure() {
  22891. function CFFFDSelect(fdSelect, raw) {
  22892. this.fdSelect = fdSelect;
  22893. this.raw = raw;
  22894. }
  22895. return CFFFDSelect;
  22896. })();
  22897. // Helper class to keep track of where an offset is within the data and helps
  22898. // filling in that offset once it's known.
  22899. var CFFOffsetTracker = (function CFFOffsetTrackerClosure() {
  22900. function CFFOffsetTracker() {
  22901. this.offsets = {};
  22902. }
  22903. CFFOffsetTracker.prototype = {
  22904. isTracking: function CFFOffsetTracker_isTracking(key) {
  22905. return key in this.offsets;
  22906. },
  22907. track: function CFFOffsetTracker_track(key, location) {
  22908. if (key in this.offsets) {
  22909. error('Already tracking location of ' + key);
  22910. }
  22911. this.offsets[key] = location;
  22912. },
  22913. offset: function CFFOffsetTracker_offset(value) {
  22914. for (var key in this.offsets) {
  22915. this.offsets[key] += value;
  22916. }
  22917. },
  22918. setEntryLocation: function CFFOffsetTracker_setEntryLocation(key,
  22919. values,
  22920. output) {
  22921. if (!(key in this.offsets)) {
  22922. error('Not tracking location of ' + key);
  22923. }
  22924. var data = output.data;
  22925. var dataOffset = this.offsets[key];
  22926. var size = 5;
  22927. for (var i = 0, ii = values.length; i < ii; ++i) {
  22928. var offset0 = i * size + dataOffset;
  22929. var offset1 = offset0 + 1;
  22930. var offset2 = offset0 + 2;
  22931. var offset3 = offset0 + 3;
  22932. var offset4 = offset0 + 4;
  22933. // It's easy to screw up offsets so perform this sanity check.
  22934. if (data[offset0] !== 0x1d || data[offset1] !== 0 ||
  22935. data[offset2] !== 0 || data[offset3] !== 0 || data[offset4] !== 0) {
  22936. error('writing to an offset that is not empty');
  22937. }
  22938. var value = values[i];
  22939. data[offset0] = 0x1d;
  22940. data[offset1] = (value >> 24) & 0xFF;
  22941. data[offset2] = (value >> 16) & 0xFF;
  22942. data[offset3] = (value >> 8) & 0xFF;
  22943. data[offset4] = value & 0xFF;
  22944. }
  22945. }
  22946. };
  22947. return CFFOffsetTracker;
  22948. })();
  22949. // Takes a CFF and converts it to the binary representation.
  22950. var CFFCompiler = (function CFFCompilerClosure() {
  22951. function CFFCompiler(cff) {
  22952. this.cff = cff;
  22953. }
  22954. CFFCompiler.prototype = {
  22955. compile: function CFFCompiler_compile() {
  22956. var cff = this.cff;
  22957. var output = {
  22958. data: [],
  22959. length: 0,
  22960. add: function CFFCompiler_add(data) {
  22961. this.data = this.data.concat(data);
  22962. this.length = this.data.length;
  22963. }
  22964. };
  22965. // Compile the five entries that must be in order.
  22966. var header = this.compileHeader(cff.header);
  22967. output.add(header);
  22968. var nameIndex = this.compileNameIndex(cff.names);
  22969. output.add(nameIndex);
  22970. if (cff.isCIDFont) {
  22971. // The spec is unclear on how font matrices should relate to each other
  22972. // when there is one in the main top dict and the sub top dicts.
  22973. // Windows handles this differently than linux and osx so we have to
  22974. // normalize to work on all.
  22975. // Rules based off of some mailing list discussions:
  22976. // - If main font has a matrix and subfont doesn't, use the main matrix.
  22977. // - If no main font matrix and there is a subfont matrix, use the
  22978. // subfont matrix.
  22979. // - If both have matrices, concat together.
  22980. // - If neither have matrices, use default.
  22981. // To make this work on all platforms we move the top matrix into each
  22982. // sub top dict and concat if necessary.
  22983. if (cff.topDict.hasName('FontMatrix')) {
  22984. var base = cff.topDict.getByName('FontMatrix');
  22985. cff.topDict.removeByName('FontMatrix');
  22986. for (var i = 0, ii = cff.fdArray.length; i < ii; i++) {
  22987. var subDict = cff.fdArray[i];
  22988. var matrix = base.slice(0);
  22989. if (subDict.hasName('FontMatrix')) {
  22990. matrix = Util.transform(matrix, subDict.getByName('FontMatrix'));
  22991. }
  22992. subDict.setByName('FontMatrix', matrix);
  22993. }
  22994. }
  22995. }
  22996. var compiled = this.compileTopDicts([cff.topDict],
  22997. output.length,
  22998. cff.isCIDFont);
  22999. output.add(compiled.output);
  23000. var topDictTracker = compiled.trackers[0];
  23001. var stringIndex = this.compileStringIndex(cff.strings.strings);
  23002. output.add(stringIndex);
  23003. var globalSubrIndex = this.compileIndex(cff.globalSubrIndex);
  23004. output.add(globalSubrIndex);
  23005. // Now start on the other entries that have no specfic order.
  23006. if (cff.encoding && cff.topDict.hasName('Encoding')) {
  23007. if (cff.encoding.predefined) {
  23008. topDictTracker.setEntryLocation('Encoding', [cff.encoding.format],
  23009. output);
  23010. } else {
  23011. var encoding = this.compileEncoding(cff.encoding);
  23012. topDictTracker.setEntryLocation('Encoding', [output.length], output);
  23013. output.add(encoding);
  23014. }
  23015. }
  23016. if (cff.charset && cff.topDict.hasName('charset')) {
  23017. if (cff.charset.predefined) {
  23018. topDictTracker.setEntryLocation('charset', [cff.charset.format],
  23019. output);
  23020. } else {
  23021. var charset = this.compileCharset(cff.charset);
  23022. topDictTracker.setEntryLocation('charset', [output.length], output);
  23023. output.add(charset);
  23024. }
  23025. }
  23026. var charStrings = this.compileCharStrings(cff.charStrings);
  23027. topDictTracker.setEntryLocation('CharStrings', [output.length], output);
  23028. output.add(charStrings);
  23029. if (cff.isCIDFont) {
  23030. // For some reason FDSelect must be in front of FDArray on windows. OSX
  23031. // and linux don't seem to care.
  23032. topDictTracker.setEntryLocation('FDSelect', [output.length], output);
  23033. var fdSelect = this.compileFDSelect(cff.fdSelect.raw);
  23034. output.add(fdSelect);
  23035. // It is unclear if the sub font dictionary can have CID related
  23036. // dictionary keys, but the sanitizer doesn't like them so remove them.
  23037. compiled = this.compileTopDicts(cff.fdArray, output.length, true);
  23038. topDictTracker.setEntryLocation('FDArray', [output.length], output);
  23039. output.add(compiled.output);
  23040. var fontDictTrackers = compiled.trackers;
  23041. this.compilePrivateDicts(cff.fdArray, fontDictTrackers, output);
  23042. }
  23043. this.compilePrivateDicts([cff.topDict], [topDictTracker], output);
  23044. // If the font data ends with INDEX whose object data is zero-length,
  23045. // the sanitizer will bail out. Add a dummy byte to avoid that.
  23046. output.add([0]);
  23047. return output.data;
  23048. },
  23049. encodeNumber: function CFFCompiler_encodeNumber(value) {
  23050. if (parseFloat(value) === parseInt(value, 10) && !isNaN(value)) { // isInt
  23051. return this.encodeInteger(value);
  23052. } else {
  23053. return this.encodeFloat(value);
  23054. }
  23055. },
  23056. encodeFloat: function CFFCompiler_encodeFloat(num) {
  23057. var value = num.toString();
  23058. // rounding inaccurate doubles
  23059. var m = /\.(\d*?)(?:9{5,20}|0{5,20})\d{0,2}(?:e(.+)|$)/.exec(value);
  23060. if (m) {
  23061. var epsilon = parseFloat('1e' + ((m[2] ? +m[2] : 0) + m[1].length));
  23062. value = (Math.round(num * epsilon) / epsilon).toString();
  23063. }
  23064. var nibbles = '';
  23065. var i, ii;
  23066. for (i = 0, ii = value.length; i < ii; ++i) {
  23067. var a = value[i];
  23068. if (a === 'e') {
  23069. nibbles += value[++i] === '-' ? 'c' : 'b';
  23070. } else if (a === '.') {
  23071. nibbles += 'a';
  23072. } else if (a === '-') {
  23073. nibbles += 'e';
  23074. } else {
  23075. nibbles += a;
  23076. }
  23077. }
  23078. nibbles += (nibbles.length & 1) ? 'f' : 'ff';
  23079. var out = [30];
  23080. for (i = 0, ii = nibbles.length; i < ii; i += 2) {
  23081. out.push(parseInt(nibbles.substr(i, 2), 16));
  23082. }
  23083. return out;
  23084. },
  23085. encodeInteger: function CFFCompiler_encodeInteger(value) {
  23086. var code;
  23087. if (value >= -107 && value <= 107) {
  23088. code = [value + 139];
  23089. } else if (value >= 108 && value <= 1131) {
  23090. value = [value - 108];
  23091. code = [(value >> 8) + 247, value & 0xFF];
  23092. } else if (value >= -1131 && value <= -108) {
  23093. value = -value - 108;
  23094. code = [(value >> 8) + 251, value & 0xFF];
  23095. } else if (value >= -32768 && value <= 32767) {
  23096. code = [0x1c, (value >> 8) & 0xFF, value & 0xFF];
  23097. } else {
  23098. code = [0x1d,
  23099. (value >> 24) & 0xFF,
  23100. (value >> 16) & 0xFF,
  23101. (value >> 8) & 0xFF,
  23102. value & 0xFF];
  23103. }
  23104. return code;
  23105. },
  23106. compileHeader: function CFFCompiler_compileHeader(header) {
  23107. return [
  23108. header.major,
  23109. header.minor,
  23110. header.hdrSize,
  23111. header.offSize
  23112. ];
  23113. },
  23114. compileNameIndex: function CFFCompiler_compileNameIndex(names) {
  23115. var nameIndex = new CFFIndex();
  23116. for (var i = 0, ii = names.length; i < ii; ++i) {
  23117. nameIndex.add(stringToArray(names[i]));
  23118. }
  23119. return this.compileIndex(nameIndex);
  23120. },
  23121. compileTopDicts: function CFFCompiler_compileTopDicts(dicts,
  23122. length,
  23123. removeCidKeys) {
  23124. var fontDictTrackers = [];
  23125. var fdArrayIndex = new CFFIndex();
  23126. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  23127. var fontDict = dicts[i];
  23128. if (removeCidKeys) {
  23129. fontDict.removeByName('CIDFontVersion');
  23130. fontDict.removeByName('CIDFontRevision');
  23131. fontDict.removeByName('CIDFontType');
  23132. fontDict.removeByName('CIDCount');
  23133. fontDict.removeByName('UIDBase');
  23134. }
  23135. var fontDictTracker = new CFFOffsetTracker();
  23136. var fontDictData = this.compileDict(fontDict, fontDictTracker);
  23137. fontDictTrackers.push(fontDictTracker);
  23138. fdArrayIndex.add(fontDictData);
  23139. fontDictTracker.offset(length);
  23140. }
  23141. fdArrayIndex = this.compileIndex(fdArrayIndex, fontDictTrackers);
  23142. return {
  23143. trackers: fontDictTrackers,
  23144. output: fdArrayIndex
  23145. };
  23146. },
  23147. compilePrivateDicts: function CFFCompiler_compilePrivateDicts(dicts,
  23148. trackers,
  23149. output) {
  23150. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  23151. var fontDict = dicts[i];
  23152. assert(fontDict.privateDict && fontDict.hasName('Private'),
  23153. 'There must be an private dictionary.');
  23154. var privateDict = fontDict.privateDict;
  23155. var privateDictTracker = new CFFOffsetTracker();
  23156. var privateDictData = this.compileDict(privateDict, privateDictTracker);
  23157. var outputLength = output.length;
  23158. privateDictTracker.offset(outputLength);
  23159. if (!privateDictData.length) {
  23160. // The private dictionary was empty, set the output length to zero to
  23161. // ensure the offset length isn't out of bounds in the eyes of the
  23162. // sanitizer.
  23163. outputLength = 0;
  23164. }
  23165. trackers[i].setEntryLocation('Private',
  23166. [privateDictData.length, outputLength],
  23167. output);
  23168. output.add(privateDictData);
  23169. if (privateDict.subrsIndex && privateDict.hasName('Subrs')) {
  23170. var subrs = this.compileIndex(privateDict.subrsIndex);
  23171. privateDictTracker.setEntryLocation('Subrs', [privateDictData.length],
  23172. output);
  23173. output.add(subrs);
  23174. }
  23175. }
  23176. },
  23177. compileDict: function CFFCompiler_compileDict(dict, offsetTracker) {
  23178. var out = [];
  23179. // The dictionary keys must be in a certain order.
  23180. var order = dict.order;
  23181. for (var i = 0; i < order.length; ++i) {
  23182. var key = order[i];
  23183. if (!(key in dict.values)) {
  23184. continue;
  23185. }
  23186. var values = dict.values[key];
  23187. var types = dict.types[key];
  23188. if (!isArray(types)) {
  23189. types = [types];
  23190. }
  23191. if (!isArray(values)) {
  23192. values = [values];
  23193. }
  23194. // Remove any empty dict values.
  23195. if (values.length === 0) {
  23196. continue;
  23197. }
  23198. for (var j = 0, jj = types.length; j < jj; ++j) {
  23199. var type = types[j];
  23200. var value = values[j];
  23201. switch (type) {
  23202. case 'num':
  23203. case 'sid':
  23204. out = out.concat(this.encodeNumber(value));
  23205. break;
  23206. case 'offset':
  23207. // For offsets we just insert a 32bit integer so we don't have to
  23208. // deal with figuring out the length of the offset when it gets
  23209. // replaced later on by the compiler.
  23210. var name = dict.keyToNameMap[key];
  23211. // Some offsets have the offset and the length, so just record the
  23212. // position of the first one.
  23213. if (!offsetTracker.isTracking(name)) {
  23214. offsetTracker.track(name, out.length);
  23215. }
  23216. out = out.concat([0x1d, 0, 0, 0, 0]);
  23217. break;
  23218. case 'array':
  23219. case 'delta':
  23220. out = out.concat(this.encodeNumber(value));
  23221. for (var k = 1, kk = values.length; k < kk; ++k) {
  23222. out = out.concat(this.encodeNumber(values[k]));
  23223. }
  23224. break;
  23225. default:
  23226. error('Unknown data type of ' + type);
  23227. break;
  23228. }
  23229. }
  23230. out = out.concat(dict.opcodes[key]);
  23231. }
  23232. return out;
  23233. },
  23234. compileStringIndex: function CFFCompiler_compileStringIndex(strings) {
  23235. var stringIndex = new CFFIndex();
  23236. for (var i = 0, ii = strings.length; i < ii; ++i) {
  23237. stringIndex.add(stringToArray(strings[i]));
  23238. }
  23239. return this.compileIndex(stringIndex);
  23240. },
  23241. compileGlobalSubrIndex: function CFFCompiler_compileGlobalSubrIndex() {
  23242. var globalSubrIndex = this.cff.globalSubrIndex;
  23243. this.out.writeByteArray(this.compileIndex(globalSubrIndex));
  23244. },
  23245. compileCharStrings: function CFFCompiler_compileCharStrings(charStrings) {
  23246. return this.compileIndex(charStrings);
  23247. },
  23248. compileCharset: function CFFCompiler_compileCharset(charset) {
  23249. return this.compileTypedArray(charset.raw);
  23250. },
  23251. compileEncoding: function CFFCompiler_compileEncoding(encoding) {
  23252. return this.compileTypedArray(encoding.raw);
  23253. },
  23254. compileFDSelect: function CFFCompiler_compileFDSelect(fdSelect) {
  23255. return this.compileTypedArray(fdSelect);
  23256. },
  23257. compileTypedArray: function CFFCompiler_compileTypedArray(data) {
  23258. var out = [];
  23259. for (var i = 0, ii = data.length; i < ii; ++i) {
  23260. out[i] = data[i];
  23261. }
  23262. return out;
  23263. },
  23264. compileIndex: function CFFCompiler_compileIndex(index, trackers) {
  23265. trackers = trackers || [];
  23266. var objects = index.objects;
  23267. // First 2 bytes contains the number of objects contained into this index
  23268. var count = objects.length;
  23269. // If there is no object, just create an index. This technically
  23270. // should just be [0, 0] but OTS has an issue with that.
  23271. if (count === 0) {
  23272. return [0, 0, 0];
  23273. }
  23274. var data = [(count >> 8) & 0xFF, count & 0xff];
  23275. var lastOffset = 1, i;
  23276. for (i = 0; i < count; ++i) {
  23277. lastOffset += objects[i].length;
  23278. }
  23279. var offsetSize;
  23280. if (lastOffset < 0x100) {
  23281. offsetSize = 1;
  23282. } else if (lastOffset < 0x10000) {
  23283. offsetSize = 2;
  23284. } else if (lastOffset < 0x1000000) {
  23285. offsetSize = 3;
  23286. } else {
  23287. offsetSize = 4;
  23288. }
  23289. // Next byte contains the offset size use to reference object in the file
  23290. data.push(offsetSize);
  23291. // Add another offset after this one because we need a new offset
  23292. var relativeOffset = 1;
  23293. for (i = 0; i < count + 1; i++) {
  23294. if (offsetSize === 1) {
  23295. data.push(relativeOffset & 0xFF);
  23296. } else if (offsetSize === 2) {
  23297. data.push((relativeOffset >> 8) & 0xFF,
  23298. relativeOffset & 0xFF);
  23299. } else if (offsetSize === 3) {
  23300. data.push((relativeOffset >> 16) & 0xFF,
  23301. (relativeOffset >> 8) & 0xFF,
  23302. relativeOffset & 0xFF);
  23303. } else {
  23304. data.push((relativeOffset >>> 24) & 0xFF,
  23305. (relativeOffset >> 16) & 0xFF,
  23306. (relativeOffset >> 8) & 0xFF,
  23307. relativeOffset & 0xFF);
  23308. }
  23309. if (objects[i]) {
  23310. relativeOffset += objects[i].length;
  23311. }
  23312. }
  23313. for (i = 0; i < count; i++) {
  23314. // Notify the tracker where the object will be offset in the data.
  23315. if (trackers[i]) {
  23316. trackers[i].offset(data.length);
  23317. }
  23318. for (var j = 0, jj = objects[i].length; j < jj; j++) {
  23319. data.push(objects[i][j]);
  23320. }
  23321. }
  23322. return data;
  23323. }
  23324. };
  23325. return CFFCompiler;
  23326. })();
  23327. // Workaround for seac on Windows.
  23328. (function checkSeacSupport() {
  23329. if (/Windows/.test(navigator.userAgent)) {
  23330. SEAC_ANALYSIS_ENABLED = true;
  23331. }
  23332. })();
  23333. // Workaround for Private Use Area characters in Chrome on Windows
  23334. // http://code.google.com/p/chromium/issues/detail?id=122465
  23335. // https://github.com/mozilla/pdf.js/issues/1689
  23336. (function checkChromeWindows() {
  23337. if (/Windows.*Chrome/.test(navigator.userAgent)) {
  23338. SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = true;
  23339. }
  23340. })();
  23341. var FontRendererFactory = (function FontRendererFactoryClosure() {
  23342. function getLong(data, offset) {
  23343. return (data[offset] << 24) | (data[offset + 1] << 16) |
  23344. (data[offset + 2] << 8) | data[offset + 3];
  23345. }
  23346. function getUshort(data, offset) {
  23347. return (data[offset] << 8) | data[offset + 1];
  23348. }
  23349. function parseCmap(data, start, end) {
  23350. var offset = (getUshort(data, start + 2) === 1 ?
  23351. getLong(data, start + 8) : getLong(data, start + 16));
  23352. var format = getUshort(data, start + offset);
  23353. var length, ranges, p, i;
  23354. if (format === 4) {
  23355. length = getUshort(data, start + offset + 2);
  23356. var segCount = getUshort(data, start + offset + 6) >> 1;
  23357. p = start + offset + 14;
  23358. ranges = [];
  23359. for (i = 0; i < segCount; i++, p += 2) {
  23360. ranges[i] = {end: getUshort(data, p)};
  23361. }
  23362. p += 2;
  23363. for (i = 0; i < segCount; i++, p += 2) {
  23364. ranges[i].start = getUshort(data, p);
  23365. }
  23366. for (i = 0; i < segCount; i++, p += 2) {
  23367. ranges[i].idDelta = getUshort(data, p);
  23368. }
  23369. for (i = 0; i < segCount; i++, p += 2) {
  23370. var idOffset = getUshort(data, p);
  23371. if (idOffset === 0) {
  23372. continue;
  23373. }
  23374. ranges[i].ids = [];
  23375. for (var j = 0, jj = ranges[i].end - ranges[i].start + 1; j < jj; j++) {
  23376. ranges[i].ids[j] = getUshort(data, p + idOffset);
  23377. idOffset += 2;
  23378. }
  23379. }
  23380. return ranges;
  23381. } else if (format === 12) {
  23382. length = getLong(data, start + offset + 4);
  23383. var groups = getLong(data, start + offset + 12);
  23384. p = start + offset + 16;
  23385. ranges = [];
  23386. for (i = 0; i < groups; i++) {
  23387. ranges.push({
  23388. start: getLong(data, p),
  23389. end: getLong(data, p + 4),
  23390. idDelta: getLong(data, p + 8) - getLong(data, p)
  23391. });
  23392. p += 12;
  23393. }
  23394. return ranges;
  23395. }
  23396. error('not supported cmap: ' + format);
  23397. }
  23398. function parseCff(data, start, end) {
  23399. var properties = {};
  23400. var parser = new CFFParser(new Stream(data, start, end - start),
  23401. properties);
  23402. var cff = parser.parse();
  23403. return {
  23404. glyphs: cff.charStrings.objects,
  23405. subrs: (cff.topDict.privateDict && cff.topDict.privateDict.subrsIndex &&
  23406. cff.topDict.privateDict.subrsIndex.objects),
  23407. gsubrs: cff.globalSubrIndex && cff.globalSubrIndex.objects
  23408. };
  23409. }
  23410. function parseGlyfTable(glyf, loca, isGlyphLocationsLong) {
  23411. var itemSize, itemDecode;
  23412. if (isGlyphLocationsLong) {
  23413. itemSize = 4;
  23414. itemDecode = function fontItemDecodeLong(data, offset) {
  23415. return (data[offset] << 24) | (data[offset + 1] << 16) |
  23416. (data[offset + 2] << 8) | data[offset + 3];
  23417. };
  23418. } else {
  23419. itemSize = 2;
  23420. itemDecode = function fontItemDecode(data, offset) {
  23421. return (data[offset] << 9) | (data[offset + 1] << 1);
  23422. };
  23423. }
  23424. var glyphs = [];
  23425. var startOffset = itemDecode(loca, 0);
  23426. for (var j = itemSize; j < loca.length; j += itemSize) {
  23427. var endOffset = itemDecode(loca, j);
  23428. glyphs.push(glyf.subarray(startOffset, endOffset));
  23429. startOffset = endOffset;
  23430. }
  23431. return glyphs;
  23432. }
  23433. function lookupCmap(ranges, unicode) {
  23434. var code = unicode.charCodeAt(0);
  23435. var l = 0, r = ranges.length - 1;
  23436. while (l < r) {
  23437. var c = (l + r + 1) >> 1;
  23438. if (code < ranges[c].start) {
  23439. r = c - 1;
  23440. } else {
  23441. l = c;
  23442. }
  23443. }
  23444. if (ranges[l].start <= code && code <= ranges[l].end) {
  23445. return (ranges[l].idDelta + (ranges[l].ids ?
  23446. ranges[l].ids[code - ranges[l].start] : code)) & 0xFFFF;
  23447. }
  23448. return 0;
  23449. }
  23450. function compileGlyf(code, js, font) {
  23451. function moveTo(x, y) {
  23452. js.push('c.moveTo(' + x + ',' + y + ');');
  23453. }
  23454. function lineTo(x, y) {
  23455. js.push('c.lineTo(' + x + ',' + y + ');');
  23456. }
  23457. function quadraticCurveTo(xa, ya, x, y) {
  23458. js.push('c.quadraticCurveTo(' + xa + ',' + ya + ',' +
  23459. x + ',' + y + ');');
  23460. }
  23461. var i = 0;
  23462. var numberOfContours = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  23463. var flags;
  23464. var x = 0, y = 0;
  23465. i += 10;
  23466. if (numberOfContours < 0) {
  23467. // composite glyph
  23468. do {
  23469. flags = (code[i] << 8) | code[i + 1];
  23470. var glyphIndex = (code[i + 2] << 8) | code[i + 3];
  23471. i += 4;
  23472. var arg1, arg2;
  23473. if ((flags & 0x01)) {
  23474. arg1 = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  23475. arg2 = ((code[i + 2] << 24) | (code[i + 3] << 16)) >> 16;
  23476. i += 4;
  23477. } else {
  23478. arg1 = code[i++]; arg2 = code[i++];
  23479. }
  23480. if ((flags & 0x02)) {
  23481. x = arg1;
  23482. y = arg2;
  23483. } else {
  23484. x = 0; y = 0; // TODO "they are points" ?
  23485. }
  23486. var scaleX = 1, scaleY = 1, scale01 = 0, scale10 = 0;
  23487. if ((flags & 0x08)) {
  23488. scaleX =
  23489. scaleY = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  23490. i += 2;
  23491. } else if ((flags & 0x40)) {
  23492. scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  23493. scaleY = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
  23494. i += 4;
  23495. } else if ((flags & 0x80)) {
  23496. scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  23497. scale01 = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
  23498. scale10 = ((code[i + 4] << 24) | (code[i + 5] << 16)) / 1073741824;
  23499. scaleY = ((code[i + 6] << 24) | (code[i + 7] << 16)) / 1073741824;
  23500. i += 8;
  23501. }
  23502. var subglyph = font.glyphs[glyphIndex];
  23503. if (subglyph) {
  23504. js.push('c.save();');
  23505. js.push('c.transform(' + scaleX + ',' + scale01 + ',' +
  23506. scale10 + ',' + scaleY + ',' + x + ',' + y + ');');
  23507. compileGlyf(subglyph, js, font);
  23508. js.push('c.restore();');
  23509. }
  23510. } while ((flags & 0x20));
  23511. } else {
  23512. // simple glyph
  23513. var endPtsOfContours = [];
  23514. var j, jj;
  23515. for (j = 0; j < numberOfContours; j++) {
  23516. endPtsOfContours.push((code[i] << 8) | code[i + 1]);
  23517. i += 2;
  23518. }
  23519. var instructionLength = (code[i] << 8) | code[i + 1];
  23520. i += 2 + instructionLength; // skipping the instructions
  23521. var numberOfPoints = endPtsOfContours[endPtsOfContours.length - 1] + 1;
  23522. var points = [];
  23523. while (points.length < numberOfPoints) {
  23524. flags = code[i++];
  23525. var repeat = 1;
  23526. if ((flags & 0x08)) {
  23527. repeat += code[i++];
  23528. }
  23529. while (repeat-- > 0) {
  23530. points.push({flags: flags});
  23531. }
  23532. }
  23533. for (j = 0; j < numberOfPoints; j++) {
  23534. switch (points[j].flags & 0x12) {
  23535. case 0x00:
  23536. x += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  23537. i += 2;
  23538. break;
  23539. case 0x02:
  23540. x -= code[i++];
  23541. break;
  23542. case 0x12:
  23543. x += code[i++];
  23544. break;
  23545. }
  23546. points[j].x = x;
  23547. }
  23548. for (j = 0; j < numberOfPoints; j++) {
  23549. switch (points[j].flags & 0x24) {
  23550. case 0x00:
  23551. y += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  23552. i += 2;
  23553. break;
  23554. case 0x04:
  23555. y -= code[i++];
  23556. break;
  23557. case 0x24:
  23558. y += code[i++];
  23559. break;
  23560. }
  23561. points[j].y = y;
  23562. }
  23563. var startPoint = 0;
  23564. for (i = 0; i < numberOfContours; i++) {
  23565. var endPoint = endPtsOfContours[i];
  23566. // contours might have implicit points, which is located in the middle
  23567. // between two neighboring off-curve points
  23568. var contour = points.slice(startPoint, endPoint + 1);
  23569. if ((contour[0].flags & 1)) {
  23570. contour.push(contour[0]); // using start point at the contour end
  23571. } else if ((contour[contour.length - 1].flags & 1)) {
  23572. // first is off-curve point, trying to use one from the end
  23573. contour.unshift(contour[contour.length - 1]);
  23574. } else {
  23575. // start and end are off-curve points, creating implicit one
  23576. var p = {
  23577. flags: 1,
  23578. x: (contour[0].x + contour[contour.length - 1].x) / 2,
  23579. y: (contour[0].y + contour[contour.length - 1].y) / 2
  23580. };
  23581. contour.unshift(p);
  23582. contour.push(p);
  23583. }
  23584. moveTo(contour[0].x, contour[0].y);
  23585. for (j = 1, jj = contour.length; j < jj; j++) {
  23586. if ((contour[j].flags & 1)) {
  23587. lineTo(contour[j].x, contour[j].y);
  23588. } else if ((contour[j + 1].flags & 1)){
  23589. quadraticCurveTo(contour[j].x, contour[j].y,
  23590. contour[j + 1].x, contour[j + 1].y);
  23591. j++;
  23592. } else {
  23593. quadraticCurveTo(contour[j].x, contour[j].y,
  23594. (contour[j].x + contour[j + 1].x) / 2,
  23595. (contour[j].y + contour[j + 1].y) / 2);
  23596. }
  23597. }
  23598. startPoint = endPoint + 1;
  23599. }
  23600. }
  23601. }
  23602. function compileCharString(code, js, font) {
  23603. var stack = [];
  23604. var x = 0, y = 0;
  23605. var stems = 0;
  23606. function moveTo(x, y) {
  23607. js.push('c.moveTo(' + x + ',' + y + ');');
  23608. }
  23609. function lineTo(x, y) {
  23610. js.push('c.lineTo(' + x + ',' + y + ');');
  23611. }
  23612. function bezierCurveTo(x1, y1, x2, y2, x, y) {
  23613. js.push('c.bezierCurveTo(' + x1 + ',' + y1 + ',' + x2 + ',' + y2 + ',' +
  23614. x + ',' + y + ');');
  23615. }
  23616. function parse(code) {
  23617. var i = 0;
  23618. while (i < code.length) {
  23619. var stackClean = false;
  23620. var v = code[i++];
  23621. var xa, xb, ya, yb, y1, y2, y3, n, subrCode;
  23622. switch (v) {
  23623. case 1: // hstem
  23624. stems += stack.length >> 1;
  23625. stackClean = true;
  23626. break;
  23627. case 3: // vstem
  23628. stems += stack.length >> 1;
  23629. stackClean = true;
  23630. break;
  23631. case 4: // vmoveto
  23632. y += stack.pop();
  23633. moveTo(x, y);
  23634. stackClean = true;
  23635. break;
  23636. case 5: // rlineto
  23637. while (stack.length > 0) {
  23638. x += stack.shift();
  23639. y += stack.shift();
  23640. lineTo(x, y);
  23641. }
  23642. break;
  23643. case 6: // hlineto
  23644. while (stack.length > 0) {
  23645. x += stack.shift();
  23646. lineTo(x, y);
  23647. if (stack.length === 0) {
  23648. break;
  23649. }
  23650. y += stack.shift();
  23651. lineTo(x, y);
  23652. }
  23653. break;
  23654. case 7: // vlineto
  23655. while (stack.length > 0) {
  23656. y += stack.shift();
  23657. lineTo(x, y);
  23658. if (stack.length === 0) {
  23659. break;
  23660. }
  23661. x += stack.shift();
  23662. lineTo(x, y);
  23663. }
  23664. break;
  23665. case 8: // rrcurveto
  23666. while (stack.length > 0) {
  23667. xa = x + stack.shift(); ya = y + stack.shift();
  23668. xb = xa + stack.shift(); yb = ya + stack.shift();
  23669. x = xb + stack.shift(); y = yb + stack.shift();
  23670. bezierCurveTo(xa, ya, xb, yb, x, y);
  23671. }
  23672. break;
  23673. case 10: // callsubr
  23674. n = stack.pop() + font.subrsBias;
  23675. subrCode = font.subrs[n];
  23676. if (subrCode) {
  23677. parse(subrCode);
  23678. }
  23679. break;
  23680. case 11: // return
  23681. return;
  23682. case 12:
  23683. v = code[i++];
  23684. switch (v) {
  23685. case 34: // flex
  23686. xa = x + stack.shift();
  23687. xb = xa + stack.shift(); y1 = y + stack.shift();
  23688. x = xb + stack.shift();
  23689. bezierCurveTo(xa, y, xb, y1, x, y1);
  23690. xa = x + stack.shift();
  23691. xb = xa + stack.shift();
  23692. x = xb + stack.shift();
  23693. bezierCurveTo(xa, y1, xb, y, x, y);
  23694. break;
  23695. case 35: // flex
  23696. xa = x + stack.shift(); ya = y + stack.shift();
  23697. xb = xa + stack.shift(); yb = ya + stack.shift();
  23698. x = xb + stack.shift(); y = yb + stack.shift();
  23699. bezierCurveTo(xa, ya, xb, yb, x, y);
  23700. xa = x + stack.shift(); ya = y + stack.shift();
  23701. xb = xa + stack.shift(); yb = ya + stack.shift();
  23702. x = xb + stack.shift(); y = yb + stack.shift();
  23703. bezierCurveTo(xa, ya, xb, yb, x, y);
  23704. stack.pop(); // fd
  23705. break;
  23706. case 36: // hflex1
  23707. xa = x + stack.shift(); y1 = y + stack.shift();
  23708. xb = xa + stack.shift(); y2 = y1 + stack.shift();
  23709. x = xb + stack.shift();
  23710. bezierCurveTo(xa, y1, xb, y2, x, y2);
  23711. xa = x + stack.shift();
  23712. xb = xa + stack.shift(); y3 = y2 + stack.shift();
  23713. x = xb + stack.shift();
  23714. bezierCurveTo(xa, y2, xb, y3, x, y);
  23715. break;
  23716. case 37: // flex1
  23717. var x0 = x, y0 = y;
  23718. xa = x + stack.shift(); ya = y + stack.shift();
  23719. xb = xa + stack.shift(); yb = ya + stack.shift();
  23720. x = xb + stack.shift(); y = yb + stack.shift();
  23721. bezierCurveTo(xa, ya, xb, yb, x, y);
  23722. xa = x + stack.shift(); ya = y + stack.shift();
  23723. xb = xa + stack.shift(); yb = ya + stack.shift();
  23724. x = xb; y = yb;
  23725. if (Math.abs(x - x0) > Math.abs(y - y0)) {
  23726. x += stack.shift();
  23727. } else {
  23728. y += stack.shift();
  23729. }
  23730. bezierCurveTo(xa, ya, xb, yb, x, y);
  23731. break;
  23732. default:
  23733. error('unknown operator: 12 ' + v);
  23734. }
  23735. break;
  23736. case 14: // endchar
  23737. if (stack.length >= 4) {
  23738. var achar = stack.pop();
  23739. var bchar = stack.pop();
  23740. y = stack.pop();
  23741. x = stack.pop();
  23742. js.push('c.save();');
  23743. js.push('c.translate('+ x + ',' + y + ');');
  23744. var gid = lookupCmap(font.cmap, String.fromCharCode(
  23745. font.glyphNameMap[Encodings.StandardEncoding[achar]]));
  23746. compileCharString(font.glyphs[gid], js, font);
  23747. js.push('c.restore();');
  23748. gid = lookupCmap(font.cmap, String.fromCharCode(
  23749. font.glyphNameMap[Encodings.StandardEncoding[bchar]]));
  23750. compileCharString(font.glyphs[gid], js, font);
  23751. }
  23752. return;
  23753. case 18: // hstemhm
  23754. stems += stack.length >> 1;
  23755. stackClean = true;
  23756. break;
  23757. case 19: // hintmask
  23758. stems += stack.length >> 1;
  23759. i += (stems + 7) >> 3;
  23760. stackClean = true;
  23761. break;
  23762. case 20: // cntrmask
  23763. stems += stack.length >> 1;
  23764. i += (stems + 7) >> 3;
  23765. stackClean = true;
  23766. break;
  23767. case 21: // rmoveto
  23768. y += stack.pop();
  23769. x += stack.pop();
  23770. moveTo(x, y);
  23771. stackClean = true;
  23772. break;
  23773. case 22: // hmoveto
  23774. x += stack.pop();
  23775. moveTo(x, y);
  23776. stackClean = true;
  23777. break;
  23778. case 23: // vstemhm
  23779. stems += stack.length >> 1;
  23780. stackClean = true;
  23781. break;
  23782. case 24: // rcurveline
  23783. while (stack.length > 2) {
  23784. xa = x + stack.shift(); ya = y + stack.shift();
  23785. xb = xa + stack.shift(); yb = ya + stack.shift();
  23786. x = xb + stack.shift(); y = yb + stack.shift();
  23787. bezierCurveTo(xa, ya, xb, yb, x, y);
  23788. }
  23789. x += stack.shift();
  23790. y += stack.shift();
  23791. lineTo(x, y);
  23792. break;
  23793. case 25: // rlinecurve
  23794. while (stack.length > 6) {
  23795. x += stack.shift();
  23796. y += stack.shift();
  23797. lineTo(x, y);
  23798. }
  23799. xa = x + stack.shift(); ya = y + stack.shift();
  23800. xb = xa + stack.shift(); yb = ya + stack.shift();
  23801. x = xb + stack.shift(); y = yb + stack.shift();
  23802. bezierCurveTo(xa, ya, xb, yb, x, y);
  23803. break;
  23804. case 26: // vvcurveto
  23805. if (stack.length % 2) {
  23806. x += stack.shift();
  23807. }
  23808. while (stack.length > 0) {
  23809. xa = x; ya = y + stack.shift();
  23810. xb = xa + stack.shift(); yb = ya + stack.shift();
  23811. x = xb; y = yb + stack.shift();
  23812. bezierCurveTo(xa, ya, xb, yb, x, y);
  23813. }
  23814. break;
  23815. case 27: // hhcurveto
  23816. if (stack.length % 2) {
  23817. y += stack.shift();
  23818. }
  23819. while (stack.length > 0) {
  23820. xa = x + stack.shift(); ya = y;
  23821. xb = xa + stack.shift(); yb = ya + stack.shift();
  23822. x = xb + stack.shift(); y = yb;
  23823. bezierCurveTo(xa, ya, xb, yb, x, y);
  23824. }
  23825. break;
  23826. case 28:
  23827. stack.push(((code[i] << 24) | (code[i + 1] << 16)) >> 16);
  23828. i += 2;
  23829. break;
  23830. case 29: // callgsubr
  23831. n = stack.pop() + font.gsubrsBias;
  23832. subrCode = font.gsubrs[n];
  23833. if (subrCode) {
  23834. parse(subrCode);
  23835. }
  23836. break;
  23837. case 30: // vhcurveto
  23838. while (stack.length > 0) {
  23839. xa = x; ya = y + stack.shift();
  23840. xb = xa + stack.shift(); yb = ya + stack.shift();
  23841. x = xb + stack.shift();
  23842. y = yb + (stack.length === 1 ? stack.shift() : 0);
  23843. bezierCurveTo(xa, ya, xb, yb, x, y);
  23844. if (stack.length === 0) {
  23845. break;
  23846. }
  23847. xa = x + stack.shift(); ya = y;
  23848. xb = xa + stack.shift(); yb = ya + stack.shift();
  23849. y = yb + stack.shift();
  23850. x = xb + (stack.length === 1 ? stack.shift() : 0);
  23851. bezierCurveTo(xa, ya, xb, yb, x, y);
  23852. }
  23853. break;
  23854. case 31: // hvcurveto
  23855. while (stack.length > 0) {
  23856. xa = x + stack.shift(); ya = y;
  23857. xb = xa + stack.shift(); yb = ya + stack.shift();
  23858. y = yb + stack.shift();
  23859. x = xb + (stack.length === 1 ? stack.shift() : 0);
  23860. bezierCurveTo(xa, ya, xb, yb, x, y);
  23861. if (stack.length === 0) {
  23862. break;
  23863. }
  23864. xa = x; ya = y + stack.shift();
  23865. xb = xa + stack.shift(); yb = ya + stack.shift();
  23866. x = xb + stack.shift();
  23867. y = yb + (stack.length === 1 ? stack.shift() : 0);
  23868. bezierCurveTo(xa, ya, xb, yb, x, y);
  23869. }
  23870. break;
  23871. default:
  23872. if (v < 32) {
  23873. error('unknown operator: ' + v);
  23874. }
  23875. if (v < 247) {
  23876. stack.push(v - 139);
  23877. } else if (v < 251) {
  23878. stack.push((v - 247) * 256 + code[i++] + 108);
  23879. } else if (v < 255) {
  23880. stack.push(-(v - 251) * 256 - code[i++] - 108);
  23881. } else {
  23882. stack.push(((code[i] << 24) | (code[i + 1] << 16) |
  23883. (code[i + 2] << 8) | code[i + 3]) / 65536);
  23884. i += 4;
  23885. }
  23886. break;
  23887. }
  23888. if (stackClean) {
  23889. stack.length = 0;
  23890. }
  23891. }
  23892. }
  23893. parse(code);
  23894. }
  23895. var noop = '';
  23896. function CompiledFont(fontMatrix) {
  23897. this.compiledGlyphs = {};
  23898. this.fontMatrix = fontMatrix;
  23899. }
  23900. CompiledFont.prototype = {
  23901. getPathJs: function (unicode) {
  23902. var gid = lookupCmap(this.cmap, unicode);
  23903. var fn = this.compiledGlyphs[gid];
  23904. if (!fn) {
  23905. this.compiledGlyphs[gid] = fn = this.compileGlyph(this.glyphs[gid]);
  23906. }
  23907. return fn;
  23908. },
  23909. compileGlyph: function (code) {
  23910. if (!code || code.length === 0 || code[0] === 14) {
  23911. return noop;
  23912. }
  23913. var js = [];
  23914. js.push('c.save();');
  23915. js.push('c.transform(' + this.fontMatrix.join(',') + ');');
  23916. js.push('c.scale(size, -size);');
  23917. this.compileGlyphImpl(code, js);
  23918. js.push('c.restore();');
  23919. return js.join('\n');
  23920. },
  23921. compileGlyphImpl: function () {
  23922. error('Children classes should implement this.');
  23923. },
  23924. hasBuiltPath: function (unicode) {
  23925. var gid = lookupCmap(this.cmap, unicode);
  23926. return gid in this.compiledGlyphs;
  23927. }
  23928. };
  23929. function TrueTypeCompiled(glyphs, cmap, fontMatrix) {
  23930. fontMatrix = fontMatrix || [0.000488, 0, 0, 0.000488, 0, 0];
  23931. CompiledFont.call(this, fontMatrix);
  23932. this.glyphs = glyphs;
  23933. this.cmap = cmap;
  23934. this.compiledGlyphs = [];
  23935. }
  23936. Util.inherit(TrueTypeCompiled, CompiledFont, {
  23937. compileGlyphImpl: function (code, js) {
  23938. compileGlyf(code, js, this);
  23939. }
  23940. });
  23941. function Type2Compiled(cffInfo, cmap, fontMatrix, glyphNameMap) {
  23942. fontMatrix = fontMatrix || [0.001, 0, 0, 0.001, 0, 0];
  23943. CompiledFont.call(this, fontMatrix);
  23944. this.glyphs = cffInfo.glyphs;
  23945. this.gsubrs = cffInfo.gsubrs || [];
  23946. this.subrs = cffInfo.subrs || [];
  23947. this.cmap = cmap;
  23948. this.glyphNameMap = glyphNameMap || GlyphsUnicode;
  23949. this.compiledGlyphs = [];
  23950. this.gsubrsBias = (this.gsubrs.length < 1240 ?
  23951. 107 : (this.gsubrs.length < 33900 ? 1131 : 32768));
  23952. this.subrsBias = (this.subrs.length < 1240 ?
  23953. 107 : (this.subrs.length < 33900 ? 1131 : 32768));
  23954. }
  23955. Util.inherit(Type2Compiled, CompiledFont, {
  23956. compileGlyphImpl: function (code, js) {
  23957. compileCharString(code, js, this);
  23958. }
  23959. });
  23960. return {
  23961. create: function FontRendererFactory_create(font) {
  23962. var data = new Uint8Array(font.data);
  23963. var cmap, glyf, loca, cff, indexToLocFormat, unitsPerEm;
  23964. var numTables = getUshort(data, 4);
  23965. for (var i = 0, p = 12; i < numTables; i++, p += 16) {
  23966. var tag = bytesToString(data.subarray(p, p + 4));
  23967. var offset = getLong(data, p + 8);
  23968. var length = getLong(data, p + 12);
  23969. switch (tag) {
  23970. case 'cmap':
  23971. cmap = parseCmap(data, offset, offset + length);
  23972. break;
  23973. case 'glyf':
  23974. glyf = data.subarray(offset, offset + length);
  23975. break;
  23976. case 'loca':
  23977. loca = data.subarray(offset, offset + length);
  23978. break;
  23979. case 'head':
  23980. unitsPerEm = getUshort(data, offset + 18);
  23981. indexToLocFormat = getUshort(data, offset + 50);
  23982. break;
  23983. case 'CFF ':
  23984. cff = parseCff(data, offset, offset + length);
  23985. break;
  23986. }
  23987. }
  23988. if (glyf) {
  23989. var fontMatrix = (!unitsPerEm ? font.fontMatrix :
  23990. [1 / unitsPerEm, 0, 0, 1 / unitsPerEm, 0, 0]);
  23991. return new TrueTypeCompiled(
  23992. parseGlyfTable(glyf, loca, indexToLocFormat), cmap, fontMatrix);
  23993. } else {
  23994. return new Type2Compiled(cff, cmap, font.fontMatrix, font.glyphNameMap);
  23995. }
  23996. }
  23997. };
  23998. })();
  23999. var GlyphsUnicode = {
  24000. A: 0x0041,
  24001. AE: 0x00C6,
  24002. AEacute: 0x01FC,
  24003. AEmacron: 0x01E2,
  24004. AEsmall: 0xF7E6,
  24005. Aacute: 0x00C1,
  24006. Aacutesmall: 0xF7E1,
  24007. Abreve: 0x0102,
  24008. Abreveacute: 0x1EAE,
  24009. Abrevecyrillic: 0x04D0,
  24010. Abrevedotbelow: 0x1EB6,
  24011. Abrevegrave: 0x1EB0,
  24012. Abrevehookabove: 0x1EB2,
  24013. Abrevetilde: 0x1EB4,
  24014. Acaron: 0x01CD,
  24015. Acircle: 0x24B6,
  24016. Acircumflex: 0x00C2,
  24017. Acircumflexacute: 0x1EA4,
  24018. Acircumflexdotbelow: 0x1EAC,
  24019. Acircumflexgrave: 0x1EA6,
  24020. Acircumflexhookabove: 0x1EA8,
  24021. Acircumflexsmall: 0xF7E2,
  24022. Acircumflextilde: 0x1EAA,
  24023. Acute: 0xF6C9,
  24024. Acutesmall: 0xF7B4,
  24025. Acyrillic: 0x0410,
  24026. Adblgrave: 0x0200,
  24027. Adieresis: 0x00C4,
  24028. Adieresiscyrillic: 0x04D2,
  24029. Adieresismacron: 0x01DE,
  24030. Adieresissmall: 0xF7E4,
  24031. Adotbelow: 0x1EA0,
  24032. Adotmacron: 0x01E0,
  24033. Agrave: 0x00C0,
  24034. Agravesmall: 0xF7E0,
  24035. Ahookabove: 0x1EA2,
  24036. Aiecyrillic: 0x04D4,
  24037. Ainvertedbreve: 0x0202,
  24038. Alpha: 0x0391,
  24039. Alphatonos: 0x0386,
  24040. Amacron: 0x0100,
  24041. Amonospace: 0xFF21,
  24042. Aogonek: 0x0104,
  24043. Aring: 0x00C5,
  24044. Aringacute: 0x01FA,
  24045. Aringbelow: 0x1E00,
  24046. Aringsmall: 0xF7E5,
  24047. Asmall: 0xF761,
  24048. Atilde: 0x00C3,
  24049. Atildesmall: 0xF7E3,
  24050. Aybarmenian: 0x0531,
  24051. B: 0x0042,
  24052. Bcircle: 0x24B7,
  24053. Bdotaccent: 0x1E02,
  24054. Bdotbelow: 0x1E04,
  24055. Becyrillic: 0x0411,
  24056. Benarmenian: 0x0532,
  24057. Beta: 0x0392,
  24058. Bhook: 0x0181,
  24059. Blinebelow: 0x1E06,
  24060. Bmonospace: 0xFF22,
  24061. Brevesmall: 0xF6F4,
  24062. Bsmall: 0xF762,
  24063. Btopbar: 0x0182,
  24064. C: 0x0043,
  24065. Caarmenian: 0x053E,
  24066. Cacute: 0x0106,
  24067. Caron: 0xF6CA,
  24068. Caronsmall: 0xF6F5,
  24069. Ccaron: 0x010C,
  24070. Ccedilla: 0x00C7,
  24071. Ccedillaacute: 0x1E08,
  24072. Ccedillasmall: 0xF7E7,
  24073. Ccircle: 0x24B8,
  24074. Ccircumflex: 0x0108,
  24075. Cdot: 0x010A,
  24076. Cdotaccent: 0x010A,
  24077. Cedillasmall: 0xF7B8,
  24078. Chaarmenian: 0x0549,
  24079. Cheabkhasiancyrillic: 0x04BC,
  24080. Checyrillic: 0x0427,
  24081. Chedescenderabkhasiancyrillic: 0x04BE,
  24082. Chedescendercyrillic: 0x04B6,
  24083. Chedieresiscyrillic: 0x04F4,
  24084. Cheharmenian: 0x0543,
  24085. Chekhakassiancyrillic: 0x04CB,
  24086. Cheverticalstrokecyrillic: 0x04B8,
  24087. Chi: 0x03A7,
  24088. Chook: 0x0187,
  24089. Circumflexsmall: 0xF6F6,
  24090. Cmonospace: 0xFF23,
  24091. Coarmenian: 0x0551,
  24092. Csmall: 0xF763,
  24093. D: 0x0044,
  24094. DZ: 0x01F1,
  24095. DZcaron: 0x01C4,
  24096. Daarmenian: 0x0534,
  24097. Dafrican: 0x0189,
  24098. Dcaron: 0x010E,
  24099. Dcedilla: 0x1E10,
  24100. Dcircle: 0x24B9,
  24101. Dcircumflexbelow: 0x1E12,
  24102. Dcroat: 0x0110,
  24103. Ddotaccent: 0x1E0A,
  24104. Ddotbelow: 0x1E0C,
  24105. Decyrillic: 0x0414,
  24106. Deicoptic: 0x03EE,
  24107. Delta: 0x2206,
  24108. Deltagreek: 0x0394,
  24109. Dhook: 0x018A,
  24110. Dieresis: 0xF6CB,
  24111. DieresisAcute: 0xF6CC,
  24112. DieresisGrave: 0xF6CD,
  24113. Dieresissmall: 0xF7A8,
  24114. Digammagreek: 0x03DC,
  24115. Djecyrillic: 0x0402,
  24116. Dlinebelow: 0x1E0E,
  24117. Dmonospace: 0xFF24,
  24118. Dotaccentsmall: 0xF6F7,
  24119. Dslash: 0x0110,
  24120. Dsmall: 0xF764,
  24121. Dtopbar: 0x018B,
  24122. Dz: 0x01F2,
  24123. Dzcaron: 0x01C5,
  24124. Dzeabkhasiancyrillic: 0x04E0,
  24125. Dzecyrillic: 0x0405,
  24126. Dzhecyrillic: 0x040F,
  24127. E: 0x0045,
  24128. Eacute: 0x00C9,
  24129. Eacutesmall: 0xF7E9,
  24130. Ebreve: 0x0114,
  24131. Ecaron: 0x011A,
  24132. Ecedillabreve: 0x1E1C,
  24133. Echarmenian: 0x0535,
  24134. Ecircle: 0x24BA,
  24135. Ecircumflex: 0x00CA,
  24136. Ecircumflexacute: 0x1EBE,
  24137. Ecircumflexbelow: 0x1E18,
  24138. Ecircumflexdotbelow: 0x1EC6,
  24139. Ecircumflexgrave: 0x1EC0,
  24140. Ecircumflexhookabove: 0x1EC2,
  24141. Ecircumflexsmall: 0xF7EA,
  24142. Ecircumflextilde: 0x1EC4,
  24143. Ecyrillic: 0x0404,
  24144. Edblgrave: 0x0204,
  24145. Edieresis: 0x00CB,
  24146. Edieresissmall: 0xF7EB,
  24147. Edot: 0x0116,
  24148. Edotaccent: 0x0116,
  24149. Edotbelow: 0x1EB8,
  24150. Efcyrillic: 0x0424,
  24151. Egrave: 0x00C8,
  24152. Egravesmall: 0xF7E8,
  24153. Eharmenian: 0x0537,
  24154. Ehookabove: 0x1EBA,
  24155. Eightroman: 0x2167,
  24156. Einvertedbreve: 0x0206,
  24157. Eiotifiedcyrillic: 0x0464,
  24158. Elcyrillic: 0x041B,
  24159. Elevenroman: 0x216A,
  24160. Emacron: 0x0112,
  24161. Emacronacute: 0x1E16,
  24162. Emacrongrave: 0x1E14,
  24163. Emcyrillic: 0x041C,
  24164. Emonospace: 0xFF25,
  24165. Encyrillic: 0x041D,
  24166. Endescendercyrillic: 0x04A2,
  24167. Eng: 0x014A,
  24168. Enghecyrillic: 0x04A4,
  24169. Enhookcyrillic: 0x04C7,
  24170. Eogonek: 0x0118,
  24171. Eopen: 0x0190,
  24172. Epsilon: 0x0395,
  24173. Epsilontonos: 0x0388,
  24174. Ercyrillic: 0x0420,
  24175. Ereversed: 0x018E,
  24176. Ereversedcyrillic: 0x042D,
  24177. Escyrillic: 0x0421,
  24178. Esdescendercyrillic: 0x04AA,
  24179. Esh: 0x01A9,
  24180. Esmall: 0xF765,
  24181. Eta: 0x0397,
  24182. Etarmenian: 0x0538,
  24183. Etatonos: 0x0389,
  24184. Eth: 0x00D0,
  24185. Ethsmall: 0xF7F0,
  24186. Etilde: 0x1EBC,
  24187. Etildebelow: 0x1E1A,
  24188. Euro: 0x20AC,
  24189. Ezh: 0x01B7,
  24190. Ezhcaron: 0x01EE,
  24191. Ezhreversed: 0x01B8,
  24192. F: 0x0046,
  24193. Fcircle: 0x24BB,
  24194. Fdotaccent: 0x1E1E,
  24195. Feharmenian: 0x0556,
  24196. Feicoptic: 0x03E4,
  24197. Fhook: 0x0191,
  24198. Fitacyrillic: 0x0472,
  24199. Fiveroman: 0x2164,
  24200. Fmonospace: 0xFF26,
  24201. Fourroman: 0x2163,
  24202. Fsmall: 0xF766,
  24203. G: 0x0047,
  24204. GBsquare: 0x3387,
  24205. Gacute: 0x01F4,
  24206. Gamma: 0x0393,
  24207. Gammaafrican: 0x0194,
  24208. Gangiacoptic: 0x03EA,
  24209. Gbreve: 0x011E,
  24210. Gcaron: 0x01E6,
  24211. Gcedilla: 0x0122,
  24212. Gcircle: 0x24BC,
  24213. Gcircumflex: 0x011C,
  24214. Gcommaaccent: 0x0122,
  24215. Gdot: 0x0120,
  24216. Gdotaccent: 0x0120,
  24217. Gecyrillic: 0x0413,
  24218. Ghadarmenian: 0x0542,
  24219. Ghemiddlehookcyrillic: 0x0494,
  24220. Ghestrokecyrillic: 0x0492,
  24221. Gheupturncyrillic: 0x0490,
  24222. Ghook: 0x0193,
  24223. Gimarmenian: 0x0533,
  24224. Gjecyrillic: 0x0403,
  24225. Gmacron: 0x1E20,
  24226. Gmonospace: 0xFF27,
  24227. Grave: 0xF6CE,
  24228. Gravesmall: 0xF760,
  24229. Gsmall: 0xF767,
  24230. Gsmallhook: 0x029B,
  24231. Gstroke: 0x01E4,
  24232. H: 0x0048,
  24233. H18533: 0x25CF,
  24234. H18543: 0x25AA,
  24235. H18551: 0x25AB,
  24236. H22073: 0x25A1,
  24237. HPsquare: 0x33CB,
  24238. Haabkhasiancyrillic: 0x04A8,
  24239. Hadescendercyrillic: 0x04B2,
  24240. Hardsigncyrillic: 0x042A,
  24241. Hbar: 0x0126,
  24242. Hbrevebelow: 0x1E2A,
  24243. Hcedilla: 0x1E28,
  24244. Hcircle: 0x24BD,
  24245. Hcircumflex: 0x0124,
  24246. Hdieresis: 0x1E26,
  24247. Hdotaccent: 0x1E22,
  24248. Hdotbelow: 0x1E24,
  24249. Hmonospace: 0xFF28,
  24250. Hoarmenian: 0x0540,
  24251. Horicoptic: 0x03E8,
  24252. Hsmall: 0xF768,
  24253. Hungarumlaut: 0xF6CF,
  24254. Hungarumlautsmall: 0xF6F8,
  24255. Hzsquare: 0x3390,
  24256. I: 0x0049,
  24257. IAcyrillic: 0x042F,
  24258. IJ: 0x0132,
  24259. IUcyrillic: 0x042E,
  24260. Iacute: 0x00CD,
  24261. Iacutesmall: 0xF7ED,
  24262. Ibreve: 0x012C,
  24263. Icaron: 0x01CF,
  24264. Icircle: 0x24BE,
  24265. Icircumflex: 0x00CE,
  24266. Icircumflexsmall: 0xF7EE,
  24267. Icyrillic: 0x0406,
  24268. Idblgrave: 0x0208,
  24269. Idieresis: 0x00CF,
  24270. Idieresisacute: 0x1E2E,
  24271. Idieresiscyrillic: 0x04E4,
  24272. Idieresissmall: 0xF7EF,
  24273. Idot: 0x0130,
  24274. Idotaccent: 0x0130,
  24275. Idotbelow: 0x1ECA,
  24276. Iebrevecyrillic: 0x04D6,
  24277. Iecyrillic: 0x0415,
  24278. Ifraktur: 0x2111,
  24279. Igrave: 0x00CC,
  24280. Igravesmall: 0xF7EC,
  24281. Ihookabove: 0x1EC8,
  24282. Iicyrillic: 0x0418,
  24283. Iinvertedbreve: 0x020A,
  24284. Iishortcyrillic: 0x0419,
  24285. Imacron: 0x012A,
  24286. Imacroncyrillic: 0x04E2,
  24287. Imonospace: 0xFF29,
  24288. Iniarmenian: 0x053B,
  24289. Iocyrillic: 0x0401,
  24290. Iogonek: 0x012E,
  24291. Iota: 0x0399,
  24292. Iotaafrican: 0x0196,
  24293. Iotadieresis: 0x03AA,
  24294. Iotatonos: 0x038A,
  24295. Ismall: 0xF769,
  24296. Istroke: 0x0197,
  24297. Itilde: 0x0128,
  24298. Itildebelow: 0x1E2C,
  24299. Izhitsacyrillic: 0x0474,
  24300. Izhitsadblgravecyrillic: 0x0476,
  24301. J: 0x004A,
  24302. Jaarmenian: 0x0541,
  24303. Jcircle: 0x24BF,
  24304. Jcircumflex: 0x0134,
  24305. Jecyrillic: 0x0408,
  24306. Jheharmenian: 0x054B,
  24307. Jmonospace: 0xFF2A,
  24308. Jsmall: 0xF76A,
  24309. K: 0x004B,
  24310. KBsquare: 0x3385,
  24311. KKsquare: 0x33CD,
  24312. Kabashkircyrillic: 0x04A0,
  24313. Kacute: 0x1E30,
  24314. Kacyrillic: 0x041A,
  24315. Kadescendercyrillic: 0x049A,
  24316. Kahookcyrillic: 0x04C3,
  24317. Kappa: 0x039A,
  24318. Kastrokecyrillic: 0x049E,
  24319. Kaverticalstrokecyrillic: 0x049C,
  24320. Kcaron: 0x01E8,
  24321. Kcedilla: 0x0136,
  24322. Kcircle: 0x24C0,
  24323. Kcommaaccent: 0x0136,
  24324. Kdotbelow: 0x1E32,
  24325. Keharmenian: 0x0554,
  24326. Kenarmenian: 0x053F,
  24327. Khacyrillic: 0x0425,
  24328. Kheicoptic: 0x03E6,
  24329. Khook: 0x0198,
  24330. Kjecyrillic: 0x040C,
  24331. Klinebelow: 0x1E34,
  24332. Kmonospace: 0xFF2B,
  24333. Koppacyrillic: 0x0480,
  24334. Koppagreek: 0x03DE,
  24335. Ksicyrillic: 0x046E,
  24336. Ksmall: 0xF76B,
  24337. L: 0x004C,
  24338. LJ: 0x01C7,
  24339. LL: 0xF6BF,
  24340. Lacute: 0x0139,
  24341. Lambda: 0x039B,
  24342. Lcaron: 0x013D,
  24343. Lcedilla: 0x013B,
  24344. Lcircle: 0x24C1,
  24345. Lcircumflexbelow: 0x1E3C,
  24346. Lcommaaccent: 0x013B,
  24347. Ldot: 0x013F,
  24348. Ldotaccent: 0x013F,
  24349. Ldotbelow: 0x1E36,
  24350. Ldotbelowmacron: 0x1E38,
  24351. Liwnarmenian: 0x053C,
  24352. Lj: 0x01C8,
  24353. Ljecyrillic: 0x0409,
  24354. Llinebelow: 0x1E3A,
  24355. Lmonospace: 0xFF2C,
  24356. Lslash: 0x0141,
  24357. Lslashsmall: 0xF6F9,
  24358. Lsmall: 0xF76C,
  24359. M: 0x004D,
  24360. MBsquare: 0x3386,
  24361. Macron: 0xF6D0,
  24362. Macronsmall: 0xF7AF,
  24363. Macute: 0x1E3E,
  24364. Mcircle: 0x24C2,
  24365. Mdotaccent: 0x1E40,
  24366. Mdotbelow: 0x1E42,
  24367. Menarmenian: 0x0544,
  24368. Mmonospace: 0xFF2D,
  24369. Msmall: 0xF76D,
  24370. Mturned: 0x019C,
  24371. Mu: 0x039C,
  24372. N: 0x004E,
  24373. NJ: 0x01CA,
  24374. Nacute: 0x0143,
  24375. Ncaron: 0x0147,
  24376. Ncedilla: 0x0145,
  24377. Ncircle: 0x24C3,
  24378. Ncircumflexbelow: 0x1E4A,
  24379. Ncommaaccent: 0x0145,
  24380. Ndotaccent: 0x1E44,
  24381. Ndotbelow: 0x1E46,
  24382. Nhookleft: 0x019D,
  24383. Nineroman: 0x2168,
  24384. Nj: 0x01CB,
  24385. Njecyrillic: 0x040A,
  24386. Nlinebelow: 0x1E48,
  24387. Nmonospace: 0xFF2E,
  24388. Nowarmenian: 0x0546,
  24389. Nsmall: 0xF76E,
  24390. Ntilde: 0x00D1,
  24391. Ntildesmall: 0xF7F1,
  24392. Nu: 0x039D,
  24393. O: 0x004F,
  24394. OE: 0x0152,
  24395. OEsmall: 0xF6FA,
  24396. Oacute: 0x00D3,
  24397. Oacutesmall: 0xF7F3,
  24398. Obarredcyrillic: 0x04E8,
  24399. Obarreddieresiscyrillic: 0x04EA,
  24400. Obreve: 0x014E,
  24401. Ocaron: 0x01D1,
  24402. Ocenteredtilde: 0x019F,
  24403. Ocircle: 0x24C4,
  24404. Ocircumflex: 0x00D4,
  24405. Ocircumflexacute: 0x1ED0,
  24406. Ocircumflexdotbelow: 0x1ED8,
  24407. Ocircumflexgrave: 0x1ED2,
  24408. Ocircumflexhookabove: 0x1ED4,
  24409. Ocircumflexsmall: 0xF7F4,
  24410. Ocircumflextilde: 0x1ED6,
  24411. Ocyrillic: 0x041E,
  24412. Odblacute: 0x0150,
  24413. Odblgrave: 0x020C,
  24414. Odieresis: 0x00D6,
  24415. Odieresiscyrillic: 0x04E6,
  24416. Odieresissmall: 0xF7F6,
  24417. Odotbelow: 0x1ECC,
  24418. Ogoneksmall: 0xF6FB,
  24419. Ograve: 0x00D2,
  24420. Ogravesmall: 0xF7F2,
  24421. Oharmenian: 0x0555,
  24422. Ohm: 0x2126,
  24423. Ohookabove: 0x1ECE,
  24424. Ohorn: 0x01A0,
  24425. Ohornacute: 0x1EDA,
  24426. Ohorndotbelow: 0x1EE2,
  24427. Ohorngrave: 0x1EDC,
  24428. Ohornhookabove: 0x1EDE,
  24429. Ohorntilde: 0x1EE0,
  24430. Ohungarumlaut: 0x0150,
  24431. Oi: 0x01A2,
  24432. Oinvertedbreve: 0x020E,
  24433. Omacron: 0x014C,
  24434. Omacronacute: 0x1E52,
  24435. Omacrongrave: 0x1E50,
  24436. Omega: 0x2126,
  24437. Omegacyrillic: 0x0460,
  24438. Omegagreek: 0x03A9,
  24439. Omegaroundcyrillic: 0x047A,
  24440. Omegatitlocyrillic: 0x047C,
  24441. Omegatonos: 0x038F,
  24442. Omicron: 0x039F,
  24443. Omicrontonos: 0x038C,
  24444. Omonospace: 0xFF2F,
  24445. Oneroman: 0x2160,
  24446. Oogonek: 0x01EA,
  24447. Oogonekmacron: 0x01EC,
  24448. Oopen: 0x0186,
  24449. Oslash: 0x00D8,
  24450. Oslashacute: 0x01FE,
  24451. Oslashsmall: 0xF7F8,
  24452. Osmall: 0xF76F,
  24453. Ostrokeacute: 0x01FE,
  24454. Otcyrillic: 0x047E,
  24455. Otilde: 0x00D5,
  24456. Otildeacute: 0x1E4C,
  24457. Otildedieresis: 0x1E4E,
  24458. Otildesmall: 0xF7F5,
  24459. P: 0x0050,
  24460. Pacute: 0x1E54,
  24461. Pcircle: 0x24C5,
  24462. Pdotaccent: 0x1E56,
  24463. Pecyrillic: 0x041F,
  24464. Peharmenian: 0x054A,
  24465. Pemiddlehookcyrillic: 0x04A6,
  24466. Phi: 0x03A6,
  24467. Phook: 0x01A4,
  24468. Pi: 0x03A0,
  24469. Piwrarmenian: 0x0553,
  24470. Pmonospace: 0xFF30,
  24471. Psi: 0x03A8,
  24472. Psicyrillic: 0x0470,
  24473. Psmall: 0xF770,
  24474. Q: 0x0051,
  24475. Qcircle: 0x24C6,
  24476. Qmonospace: 0xFF31,
  24477. Qsmall: 0xF771,
  24478. R: 0x0052,
  24479. Raarmenian: 0x054C,
  24480. Racute: 0x0154,
  24481. Rcaron: 0x0158,
  24482. Rcedilla: 0x0156,
  24483. Rcircle: 0x24C7,
  24484. Rcommaaccent: 0x0156,
  24485. Rdblgrave: 0x0210,
  24486. Rdotaccent: 0x1E58,
  24487. Rdotbelow: 0x1E5A,
  24488. Rdotbelowmacron: 0x1E5C,
  24489. Reharmenian: 0x0550,
  24490. Rfraktur: 0x211C,
  24491. Rho: 0x03A1,
  24492. Ringsmall: 0xF6FC,
  24493. Rinvertedbreve: 0x0212,
  24494. Rlinebelow: 0x1E5E,
  24495. Rmonospace: 0xFF32,
  24496. Rsmall: 0xF772,
  24497. Rsmallinverted: 0x0281,
  24498. Rsmallinvertedsuperior: 0x02B6,
  24499. S: 0x0053,
  24500. SF010000: 0x250C,
  24501. SF020000: 0x2514,
  24502. SF030000: 0x2510,
  24503. SF040000: 0x2518,
  24504. SF050000: 0x253C,
  24505. SF060000: 0x252C,
  24506. SF070000: 0x2534,
  24507. SF080000: 0x251C,
  24508. SF090000: 0x2524,
  24509. SF100000: 0x2500,
  24510. SF110000: 0x2502,
  24511. SF190000: 0x2561,
  24512. SF200000: 0x2562,
  24513. SF210000: 0x2556,
  24514. SF220000: 0x2555,
  24515. SF230000: 0x2563,
  24516. SF240000: 0x2551,
  24517. SF250000: 0x2557,
  24518. SF260000: 0x255D,
  24519. SF270000: 0x255C,
  24520. SF280000: 0x255B,
  24521. SF360000: 0x255E,
  24522. SF370000: 0x255F,
  24523. SF380000: 0x255A,
  24524. SF390000: 0x2554,
  24525. SF400000: 0x2569,
  24526. SF410000: 0x2566,
  24527. SF420000: 0x2560,
  24528. SF430000: 0x2550,
  24529. SF440000: 0x256C,
  24530. SF450000: 0x2567,
  24531. SF460000: 0x2568,
  24532. SF470000: 0x2564,
  24533. SF480000: 0x2565,
  24534. SF490000: 0x2559,
  24535. SF500000: 0x2558,
  24536. SF510000: 0x2552,
  24537. SF520000: 0x2553,
  24538. SF530000: 0x256B,
  24539. SF540000: 0x256A,
  24540. Sacute: 0x015A,
  24541. Sacutedotaccent: 0x1E64,
  24542. Sampigreek: 0x03E0,
  24543. Scaron: 0x0160,
  24544. Scarondotaccent: 0x1E66,
  24545. Scaronsmall: 0xF6FD,
  24546. Scedilla: 0x015E,
  24547. Schwa: 0x018F,
  24548. Schwacyrillic: 0x04D8,
  24549. Schwadieresiscyrillic: 0x04DA,
  24550. Scircle: 0x24C8,
  24551. Scircumflex: 0x015C,
  24552. Scommaaccent: 0x0218,
  24553. Sdotaccent: 0x1E60,
  24554. Sdotbelow: 0x1E62,
  24555. Sdotbelowdotaccent: 0x1E68,
  24556. Seharmenian: 0x054D,
  24557. Sevenroman: 0x2166,
  24558. Shaarmenian: 0x0547,
  24559. Shacyrillic: 0x0428,
  24560. Shchacyrillic: 0x0429,
  24561. Sheicoptic: 0x03E2,
  24562. Shhacyrillic: 0x04BA,
  24563. Shimacoptic: 0x03EC,
  24564. Sigma: 0x03A3,
  24565. Sixroman: 0x2165,
  24566. Smonospace: 0xFF33,
  24567. Softsigncyrillic: 0x042C,
  24568. Ssmall: 0xF773,
  24569. Stigmagreek: 0x03DA,
  24570. T: 0x0054,
  24571. Tau: 0x03A4,
  24572. Tbar: 0x0166,
  24573. Tcaron: 0x0164,
  24574. Tcedilla: 0x0162,
  24575. Tcircle: 0x24C9,
  24576. Tcircumflexbelow: 0x1E70,
  24577. Tcommaaccent: 0x0162,
  24578. Tdotaccent: 0x1E6A,
  24579. Tdotbelow: 0x1E6C,
  24580. Tecyrillic: 0x0422,
  24581. Tedescendercyrillic: 0x04AC,
  24582. Tenroman: 0x2169,
  24583. Tetsecyrillic: 0x04B4,
  24584. Theta: 0x0398,
  24585. Thook: 0x01AC,
  24586. Thorn: 0x00DE,
  24587. Thornsmall: 0xF7FE,
  24588. Threeroman: 0x2162,
  24589. Tildesmall: 0xF6FE,
  24590. Tiwnarmenian: 0x054F,
  24591. Tlinebelow: 0x1E6E,
  24592. Tmonospace: 0xFF34,
  24593. Toarmenian: 0x0539,
  24594. Tonefive: 0x01BC,
  24595. Tonesix: 0x0184,
  24596. Tonetwo: 0x01A7,
  24597. Tretroflexhook: 0x01AE,
  24598. Tsecyrillic: 0x0426,
  24599. Tshecyrillic: 0x040B,
  24600. Tsmall: 0xF774,
  24601. Twelveroman: 0x216B,
  24602. Tworoman: 0x2161,
  24603. U: 0x0055,
  24604. Uacute: 0x00DA,
  24605. Uacutesmall: 0xF7FA,
  24606. Ubreve: 0x016C,
  24607. Ucaron: 0x01D3,
  24608. Ucircle: 0x24CA,
  24609. Ucircumflex: 0x00DB,
  24610. Ucircumflexbelow: 0x1E76,
  24611. Ucircumflexsmall: 0xF7FB,
  24612. Ucyrillic: 0x0423,
  24613. Udblacute: 0x0170,
  24614. Udblgrave: 0x0214,
  24615. Udieresis: 0x00DC,
  24616. Udieresisacute: 0x01D7,
  24617. Udieresisbelow: 0x1E72,
  24618. Udieresiscaron: 0x01D9,
  24619. Udieresiscyrillic: 0x04F0,
  24620. Udieresisgrave: 0x01DB,
  24621. Udieresismacron: 0x01D5,
  24622. Udieresissmall: 0xF7FC,
  24623. Udotbelow: 0x1EE4,
  24624. Ugrave: 0x00D9,
  24625. Ugravesmall: 0xF7F9,
  24626. Uhookabove: 0x1EE6,
  24627. Uhorn: 0x01AF,
  24628. Uhornacute: 0x1EE8,
  24629. Uhorndotbelow: 0x1EF0,
  24630. Uhorngrave: 0x1EEA,
  24631. Uhornhookabove: 0x1EEC,
  24632. Uhorntilde: 0x1EEE,
  24633. Uhungarumlaut: 0x0170,
  24634. Uhungarumlautcyrillic: 0x04F2,
  24635. Uinvertedbreve: 0x0216,
  24636. Ukcyrillic: 0x0478,
  24637. Umacron: 0x016A,
  24638. Umacroncyrillic: 0x04EE,
  24639. Umacrondieresis: 0x1E7A,
  24640. Umonospace: 0xFF35,
  24641. Uogonek: 0x0172,
  24642. Upsilon: 0x03A5,
  24643. Upsilon1: 0x03D2,
  24644. Upsilonacutehooksymbolgreek: 0x03D3,
  24645. Upsilonafrican: 0x01B1,
  24646. Upsilondieresis: 0x03AB,
  24647. Upsilondieresishooksymbolgreek: 0x03D4,
  24648. Upsilonhooksymbol: 0x03D2,
  24649. Upsilontonos: 0x038E,
  24650. Uring: 0x016E,
  24651. Ushortcyrillic: 0x040E,
  24652. Usmall: 0xF775,
  24653. Ustraightcyrillic: 0x04AE,
  24654. Ustraightstrokecyrillic: 0x04B0,
  24655. Utilde: 0x0168,
  24656. Utildeacute: 0x1E78,
  24657. Utildebelow: 0x1E74,
  24658. V: 0x0056,
  24659. Vcircle: 0x24CB,
  24660. Vdotbelow: 0x1E7E,
  24661. Vecyrillic: 0x0412,
  24662. Vewarmenian: 0x054E,
  24663. Vhook: 0x01B2,
  24664. Vmonospace: 0xFF36,
  24665. Voarmenian: 0x0548,
  24666. Vsmall: 0xF776,
  24667. Vtilde: 0x1E7C,
  24668. W: 0x0057,
  24669. Wacute: 0x1E82,
  24670. Wcircle: 0x24CC,
  24671. Wcircumflex: 0x0174,
  24672. Wdieresis: 0x1E84,
  24673. Wdotaccent: 0x1E86,
  24674. Wdotbelow: 0x1E88,
  24675. Wgrave: 0x1E80,
  24676. Wmonospace: 0xFF37,
  24677. Wsmall: 0xF777,
  24678. X: 0x0058,
  24679. Xcircle: 0x24CD,
  24680. Xdieresis: 0x1E8C,
  24681. Xdotaccent: 0x1E8A,
  24682. Xeharmenian: 0x053D,
  24683. Xi: 0x039E,
  24684. Xmonospace: 0xFF38,
  24685. Xsmall: 0xF778,
  24686. Y: 0x0059,
  24687. Yacute: 0x00DD,
  24688. Yacutesmall: 0xF7FD,
  24689. Yatcyrillic: 0x0462,
  24690. Ycircle: 0x24CE,
  24691. Ycircumflex: 0x0176,
  24692. Ydieresis: 0x0178,
  24693. Ydieresissmall: 0xF7FF,
  24694. Ydotaccent: 0x1E8E,
  24695. Ydotbelow: 0x1EF4,
  24696. Yericyrillic: 0x042B,
  24697. Yerudieresiscyrillic: 0x04F8,
  24698. Ygrave: 0x1EF2,
  24699. Yhook: 0x01B3,
  24700. Yhookabove: 0x1EF6,
  24701. Yiarmenian: 0x0545,
  24702. Yicyrillic: 0x0407,
  24703. Yiwnarmenian: 0x0552,
  24704. Ymonospace: 0xFF39,
  24705. Ysmall: 0xF779,
  24706. Ytilde: 0x1EF8,
  24707. Yusbigcyrillic: 0x046A,
  24708. Yusbigiotifiedcyrillic: 0x046C,
  24709. Yuslittlecyrillic: 0x0466,
  24710. Yuslittleiotifiedcyrillic: 0x0468,
  24711. Z: 0x005A,
  24712. Zaarmenian: 0x0536,
  24713. Zacute: 0x0179,
  24714. Zcaron: 0x017D,
  24715. Zcaronsmall: 0xF6FF,
  24716. Zcircle: 0x24CF,
  24717. Zcircumflex: 0x1E90,
  24718. Zdot: 0x017B,
  24719. Zdotaccent: 0x017B,
  24720. Zdotbelow: 0x1E92,
  24721. Zecyrillic: 0x0417,
  24722. Zedescendercyrillic: 0x0498,
  24723. Zedieresiscyrillic: 0x04DE,
  24724. Zeta: 0x0396,
  24725. Zhearmenian: 0x053A,
  24726. Zhebrevecyrillic: 0x04C1,
  24727. Zhecyrillic: 0x0416,
  24728. Zhedescendercyrillic: 0x0496,
  24729. Zhedieresiscyrillic: 0x04DC,
  24730. Zlinebelow: 0x1E94,
  24731. Zmonospace: 0xFF3A,
  24732. Zsmall: 0xF77A,
  24733. Zstroke: 0x01B5,
  24734. a: 0x0061,
  24735. aabengali: 0x0986,
  24736. aacute: 0x00E1,
  24737. aadeva: 0x0906,
  24738. aagujarati: 0x0A86,
  24739. aagurmukhi: 0x0A06,
  24740. aamatragurmukhi: 0x0A3E,
  24741. aarusquare: 0x3303,
  24742. aavowelsignbengali: 0x09BE,
  24743. aavowelsigndeva: 0x093E,
  24744. aavowelsigngujarati: 0x0ABE,
  24745. abbreviationmarkarmenian: 0x055F,
  24746. abbreviationsigndeva: 0x0970,
  24747. abengali: 0x0985,
  24748. abopomofo: 0x311A,
  24749. abreve: 0x0103,
  24750. abreveacute: 0x1EAF,
  24751. abrevecyrillic: 0x04D1,
  24752. abrevedotbelow: 0x1EB7,
  24753. abrevegrave: 0x1EB1,
  24754. abrevehookabove: 0x1EB3,
  24755. abrevetilde: 0x1EB5,
  24756. acaron: 0x01CE,
  24757. acircle: 0x24D0,
  24758. acircumflex: 0x00E2,
  24759. acircumflexacute: 0x1EA5,
  24760. acircumflexdotbelow: 0x1EAD,
  24761. acircumflexgrave: 0x1EA7,
  24762. acircumflexhookabove: 0x1EA9,
  24763. acircumflextilde: 0x1EAB,
  24764. acute: 0x00B4,
  24765. acutebelowcmb: 0x0317,
  24766. acutecmb: 0x0301,
  24767. acutecomb: 0x0301,
  24768. acutedeva: 0x0954,
  24769. acutelowmod: 0x02CF,
  24770. acutetonecmb: 0x0341,
  24771. acyrillic: 0x0430,
  24772. adblgrave: 0x0201,
  24773. addakgurmukhi: 0x0A71,
  24774. adeva: 0x0905,
  24775. adieresis: 0x00E4,
  24776. adieresiscyrillic: 0x04D3,
  24777. adieresismacron: 0x01DF,
  24778. adotbelow: 0x1EA1,
  24779. adotmacron: 0x01E1,
  24780. ae: 0x00E6,
  24781. aeacute: 0x01FD,
  24782. aekorean: 0x3150,
  24783. aemacron: 0x01E3,
  24784. afii00208: 0x2015,
  24785. afii08941: 0x20A4,
  24786. afii10017: 0x0410,
  24787. afii10018: 0x0411,
  24788. afii10019: 0x0412,
  24789. afii10020: 0x0413,
  24790. afii10021: 0x0414,
  24791. afii10022: 0x0415,
  24792. afii10023: 0x0401,
  24793. afii10024: 0x0416,
  24794. afii10025: 0x0417,
  24795. afii10026: 0x0418,
  24796. afii10027: 0x0419,
  24797. afii10028: 0x041A,
  24798. afii10029: 0x041B,
  24799. afii10030: 0x041C,
  24800. afii10031: 0x041D,
  24801. afii10032: 0x041E,
  24802. afii10033: 0x041F,
  24803. afii10034: 0x0420,
  24804. afii10035: 0x0421,
  24805. afii10036: 0x0422,
  24806. afii10037: 0x0423,
  24807. afii10038: 0x0424,
  24808. afii10039: 0x0425,
  24809. afii10040: 0x0426,
  24810. afii10041: 0x0427,
  24811. afii10042: 0x0428,
  24812. afii10043: 0x0429,
  24813. afii10044: 0x042A,
  24814. afii10045: 0x042B,
  24815. afii10046: 0x042C,
  24816. afii10047: 0x042D,
  24817. afii10048: 0x042E,
  24818. afii10049: 0x042F,
  24819. afii10050: 0x0490,
  24820. afii10051: 0x0402,
  24821. afii10052: 0x0403,
  24822. afii10053: 0x0404,
  24823. afii10054: 0x0405,
  24824. afii10055: 0x0406,
  24825. afii10056: 0x0407,
  24826. afii10057: 0x0408,
  24827. afii10058: 0x0409,
  24828. afii10059: 0x040A,
  24829. afii10060: 0x040B,
  24830. afii10061: 0x040C,
  24831. afii10062: 0x040E,
  24832. afii10063: 0xF6C4,
  24833. afii10064: 0xF6C5,
  24834. afii10065: 0x0430,
  24835. afii10066: 0x0431,
  24836. afii10067: 0x0432,
  24837. afii10068: 0x0433,
  24838. afii10069: 0x0434,
  24839. afii10070: 0x0435,
  24840. afii10071: 0x0451,
  24841. afii10072: 0x0436,
  24842. afii10073: 0x0437,
  24843. afii10074: 0x0438,
  24844. afii10075: 0x0439,
  24845. afii10076: 0x043A,
  24846. afii10077: 0x043B,
  24847. afii10078: 0x043C,
  24848. afii10079: 0x043D,
  24849. afii10080: 0x043E,
  24850. afii10081: 0x043F,
  24851. afii10082: 0x0440,
  24852. afii10083: 0x0441,
  24853. afii10084: 0x0442,
  24854. afii10085: 0x0443,
  24855. afii10086: 0x0444,
  24856. afii10087: 0x0445,
  24857. afii10088: 0x0446,
  24858. afii10089: 0x0447,
  24859. afii10090: 0x0448,
  24860. afii10091: 0x0449,
  24861. afii10092: 0x044A,
  24862. afii10093: 0x044B,
  24863. afii10094: 0x044C,
  24864. afii10095: 0x044D,
  24865. afii10096: 0x044E,
  24866. afii10097: 0x044F,
  24867. afii10098: 0x0491,
  24868. afii10099: 0x0452,
  24869. afii10100: 0x0453,
  24870. afii10101: 0x0454,
  24871. afii10102: 0x0455,
  24872. afii10103: 0x0456,
  24873. afii10104: 0x0457,
  24874. afii10105: 0x0458,
  24875. afii10106: 0x0459,
  24876. afii10107: 0x045A,
  24877. afii10108: 0x045B,
  24878. afii10109: 0x045C,
  24879. afii10110: 0x045E,
  24880. afii10145: 0x040F,
  24881. afii10146: 0x0462,
  24882. afii10147: 0x0472,
  24883. afii10148: 0x0474,
  24884. afii10192: 0xF6C6,
  24885. afii10193: 0x045F,
  24886. afii10194: 0x0463,
  24887. afii10195: 0x0473,
  24888. afii10196: 0x0475,
  24889. afii10831: 0xF6C7,
  24890. afii10832: 0xF6C8,
  24891. afii10846: 0x04D9,
  24892. afii299: 0x200E,
  24893. afii300: 0x200F,
  24894. afii301: 0x200D,
  24895. afii57381: 0x066A,
  24896. afii57388: 0x060C,
  24897. afii57392: 0x0660,
  24898. afii57393: 0x0661,
  24899. afii57394: 0x0662,
  24900. afii57395: 0x0663,
  24901. afii57396: 0x0664,
  24902. afii57397: 0x0665,
  24903. afii57398: 0x0666,
  24904. afii57399: 0x0667,
  24905. afii57400: 0x0668,
  24906. afii57401: 0x0669,
  24907. afii57403: 0x061B,
  24908. afii57407: 0x061F,
  24909. afii57409: 0x0621,
  24910. afii57410: 0x0622,
  24911. afii57411: 0x0623,
  24912. afii57412: 0x0624,
  24913. afii57413: 0x0625,
  24914. afii57414: 0x0626,
  24915. afii57415: 0x0627,
  24916. afii57416: 0x0628,
  24917. afii57417: 0x0629,
  24918. afii57418: 0x062A,
  24919. afii57419: 0x062B,
  24920. afii57420: 0x062C,
  24921. afii57421: 0x062D,
  24922. afii57422: 0x062E,
  24923. afii57423: 0x062F,
  24924. afii57424: 0x0630,
  24925. afii57425: 0x0631,
  24926. afii57426: 0x0632,
  24927. afii57427: 0x0633,
  24928. afii57428: 0x0634,
  24929. afii57429: 0x0635,
  24930. afii57430: 0x0636,
  24931. afii57431: 0x0637,
  24932. afii57432: 0x0638,
  24933. afii57433: 0x0639,
  24934. afii57434: 0x063A,
  24935. afii57440: 0x0640,
  24936. afii57441: 0x0641,
  24937. afii57442: 0x0642,
  24938. afii57443: 0x0643,
  24939. afii57444: 0x0644,
  24940. afii57445: 0x0645,
  24941. afii57446: 0x0646,
  24942. afii57448: 0x0648,
  24943. afii57449: 0x0649,
  24944. afii57450: 0x064A,
  24945. afii57451: 0x064B,
  24946. afii57452: 0x064C,
  24947. afii57453: 0x064D,
  24948. afii57454: 0x064E,
  24949. afii57455: 0x064F,
  24950. afii57456: 0x0650,
  24951. afii57457: 0x0651,
  24952. afii57458: 0x0652,
  24953. afii57470: 0x0647,
  24954. afii57505: 0x06A4,
  24955. afii57506: 0x067E,
  24956. afii57507: 0x0686,
  24957. afii57508: 0x0698,
  24958. afii57509: 0x06AF,
  24959. afii57511: 0x0679,
  24960. afii57512: 0x0688,
  24961. afii57513: 0x0691,
  24962. afii57514: 0x06BA,
  24963. afii57519: 0x06D2,
  24964. afii57534: 0x06D5,
  24965. afii57636: 0x20AA,
  24966. afii57645: 0x05BE,
  24967. afii57658: 0x05C3,
  24968. afii57664: 0x05D0,
  24969. afii57665: 0x05D1,
  24970. afii57666: 0x05D2,
  24971. afii57667: 0x05D3,
  24972. afii57668: 0x05D4,
  24973. afii57669: 0x05D5,
  24974. afii57670: 0x05D6,
  24975. afii57671: 0x05D7,
  24976. afii57672: 0x05D8,
  24977. afii57673: 0x05D9,
  24978. afii57674: 0x05DA,
  24979. afii57675: 0x05DB,
  24980. afii57676: 0x05DC,
  24981. afii57677: 0x05DD,
  24982. afii57678: 0x05DE,
  24983. afii57679: 0x05DF,
  24984. afii57680: 0x05E0,
  24985. afii57681: 0x05E1,
  24986. afii57682: 0x05E2,
  24987. afii57683: 0x05E3,
  24988. afii57684: 0x05E4,
  24989. afii57685: 0x05E5,
  24990. afii57686: 0x05E6,
  24991. afii57687: 0x05E7,
  24992. afii57688: 0x05E8,
  24993. afii57689: 0x05E9,
  24994. afii57690: 0x05EA,
  24995. afii57694: 0xFB2A,
  24996. afii57695: 0xFB2B,
  24997. afii57700: 0xFB4B,
  24998. afii57705: 0xFB1F,
  24999. afii57716: 0x05F0,
  25000. afii57717: 0x05F1,
  25001. afii57718: 0x05F2,
  25002. afii57723: 0xFB35,
  25003. afii57793: 0x05B4,
  25004. afii57794: 0x05B5,
  25005. afii57795: 0x05B6,
  25006. afii57796: 0x05BB,
  25007. afii57797: 0x05B8,
  25008. afii57798: 0x05B7,
  25009. afii57799: 0x05B0,
  25010. afii57800: 0x05B2,
  25011. afii57801: 0x05B1,
  25012. afii57802: 0x05B3,
  25013. afii57803: 0x05C2,
  25014. afii57804: 0x05C1,
  25015. afii57806: 0x05B9,
  25016. afii57807: 0x05BC,
  25017. afii57839: 0x05BD,
  25018. afii57841: 0x05BF,
  25019. afii57842: 0x05C0,
  25020. afii57929: 0x02BC,
  25021. afii61248: 0x2105,
  25022. afii61289: 0x2113,
  25023. afii61352: 0x2116,
  25024. afii61573: 0x202C,
  25025. afii61574: 0x202D,
  25026. afii61575: 0x202E,
  25027. afii61664: 0x200C,
  25028. afii63167: 0x066D,
  25029. afii64937: 0x02BD,
  25030. agrave: 0x00E0,
  25031. agujarati: 0x0A85,
  25032. agurmukhi: 0x0A05,
  25033. ahiragana: 0x3042,
  25034. ahookabove: 0x1EA3,
  25035. aibengali: 0x0990,
  25036. aibopomofo: 0x311E,
  25037. aideva: 0x0910,
  25038. aiecyrillic: 0x04D5,
  25039. aigujarati: 0x0A90,
  25040. aigurmukhi: 0x0A10,
  25041. aimatragurmukhi: 0x0A48,
  25042. ainarabic: 0x0639,
  25043. ainfinalarabic: 0xFECA,
  25044. aininitialarabic: 0xFECB,
  25045. ainmedialarabic: 0xFECC,
  25046. ainvertedbreve: 0x0203,
  25047. aivowelsignbengali: 0x09C8,
  25048. aivowelsigndeva: 0x0948,
  25049. aivowelsigngujarati: 0x0AC8,
  25050. akatakana: 0x30A2,
  25051. akatakanahalfwidth: 0xFF71,
  25052. akorean: 0x314F,
  25053. alef: 0x05D0,
  25054. alefarabic: 0x0627,
  25055. alefdageshhebrew: 0xFB30,
  25056. aleffinalarabic: 0xFE8E,
  25057. alefhamzaabovearabic: 0x0623,
  25058. alefhamzaabovefinalarabic: 0xFE84,
  25059. alefhamzabelowarabic: 0x0625,
  25060. alefhamzabelowfinalarabic: 0xFE88,
  25061. alefhebrew: 0x05D0,
  25062. aleflamedhebrew: 0xFB4F,
  25063. alefmaddaabovearabic: 0x0622,
  25064. alefmaddaabovefinalarabic: 0xFE82,
  25065. alefmaksuraarabic: 0x0649,
  25066. alefmaksurafinalarabic: 0xFEF0,
  25067. alefmaksurainitialarabic: 0xFEF3,
  25068. alefmaksuramedialarabic: 0xFEF4,
  25069. alefpatahhebrew: 0xFB2E,
  25070. alefqamatshebrew: 0xFB2F,
  25071. aleph: 0x2135,
  25072. allequal: 0x224C,
  25073. alpha: 0x03B1,
  25074. alphatonos: 0x03AC,
  25075. amacron: 0x0101,
  25076. amonospace: 0xFF41,
  25077. ampersand: 0x0026,
  25078. ampersandmonospace: 0xFF06,
  25079. ampersandsmall: 0xF726,
  25080. amsquare: 0x33C2,
  25081. anbopomofo: 0x3122,
  25082. angbopomofo: 0x3124,
  25083. angbracketleft: 0x3008, // This glyph is missing from Adobe's original list.
  25084. angbracketright: 0x3009, // This glyph is missing from Adobe's original list.
  25085. angkhankhuthai: 0x0E5A,
  25086. angle: 0x2220,
  25087. anglebracketleft: 0x3008,
  25088. anglebracketleftvertical: 0xFE3F,
  25089. anglebracketright: 0x3009,
  25090. anglebracketrightvertical: 0xFE40,
  25091. angleleft: 0x2329,
  25092. angleright: 0x232A,
  25093. angstrom: 0x212B,
  25094. anoteleia: 0x0387,
  25095. anudattadeva: 0x0952,
  25096. anusvarabengali: 0x0982,
  25097. anusvaradeva: 0x0902,
  25098. anusvaragujarati: 0x0A82,
  25099. aogonek: 0x0105,
  25100. apaatosquare: 0x3300,
  25101. aparen: 0x249C,
  25102. apostrophearmenian: 0x055A,
  25103. apostrophemod: 0x02BC,
  25104. apple: 0xF8FF,
  25105. approaches: 0x2250,
  25106. approxequal: 0x2248,
  25107. approxequalorimage: 0x2252,
  25108. approximatelyequal: 0x2245,
  25109. araeaekorean: 0x318E,
  25110. araeakorean: 0x318D,
  25111. arc: 0x2312,
  25112. arighthalfring: 0x1E9A,
  25113. aring: 0x00E5,
  25114. aringacute: 0x01FB,
  25115. aringbelow: 0x1E01,
  25116. arrowboth: 0x2194,
  25117. arrowdashdown: 0x21E3,
  25118. arrowdashleft: 0x21E0,
  25119. arrowdashright: 0x21E2,
  25120. arrowdashup: 0x21E1,
  25121. arrowdblboth: 0x21D4,
  25122. arrowdbldown: 0x21D3,
  25123. arrowdblleft: 0x21D0,
  25124. arrowdblright: 0x21D2,
  25125. arrowdblup: 0x21D1,
  25126. arrowdown: 0x2193,
  25127. arrowdownleft: 0x2199,
  25128. arrowdownright: 0x2198,
  25129. arrowdownwhite: 0x21E9,
  25130. arrowheaddownmod: 0x02C5,
  25131. arrowheadleftmod: 0x02C2,
  25132. arrowheadrightmod: 0x02C3,
  25133. arrowheadupmod: 0x02C4,
  25134. arrowhorizex: 0xF8E7,
  25135. arrowleft: 0x2190,
  25136. arrowleftdbl: 0x21D0,
  25137. arrowleftdblstroke: 0x21CD,
  25138. arrowleftoverright: 0x21C6,
  25139. arrowleftwhite: 0x21E6,
  25140. arrowright: 0x2192,
  25141. arrowrightdblstroke: 0x21CF,
  25142. arrowrightheavy: 0x279E,
  25143. arrowrightoverleft: 0x21C4,
  25144. arrowrightwhite: 0x21E8,
  25145. arrowtableft: 0x21E4,
  25146. arrowtabright: 0x21E5,
  25147. arrowup: 0x2191,
  25148. arrowupdn: 0x2195,
  25149. arrowupdnbse: 0x21A8,
  25150. arrowupdownbase: 0x21A8,
  25151. arrowupleft: 0x2196,
  25152. arrowupleftofdown: 0x21C5,
  25153. arrowupright: 0x2197,
  25154. arrowupwhite: 0x21E7,
  25155. arrowvertex: 0xF8E6,
  25156. asciicircum: 0x005E,
  25157. asciicircummonospace: 0xFF3E,
  25158. asciitilde: 0x007E,
  25159. asciitildemonospace: 0xFF5E,
  25160. ascript: 0x0251,
  25161. ascriptturned: 0x0252,
  25162. asmallhiragana: 0x3041,
  25163. asmallkatakana: 0x30A1,
  25164. asmallkatakanahalfwidth: 0xFF67,
  25165. asterisk: 0x002A,
  25166. asteriskaltonearabic: 0x066D,
  25167. asteriskarabic: 0x066D,
  25168. asteriskmath: 0x2217,
  25169. asteriskmonospace: 0xFF0A,
  25170. asterisksmall: 0xFE61,
  25171. asterism: 0x2042,
  25172. asuperior: 0xF6E9,
  25173. asymptoticallyequal: 0x2243,
  25174. at: 0x0040,
  25175. atilde: 0x00E3,
  25176. atmonospace: 0xFF20,
  25177. atsmall: 0xFE6B,
  25178. aturned: 0x0250,
  25179. aubengali: 0x0994,
  25180. aubopomofo: 0x3120,
  25181. audeva: 0x0914,
  25182. augujarati: 0x0A94,
  25183. augurmukhi: 0x0A14,
  25184. aulengthmarkbengali: 0x09D7,
  25185. aumatragurmukhi: 0x0A4C,
  25186. auvowelsignbengali: 0x09CC,
  25187. auvowelsigndeva: 0x094C,
  25188. auvowelsigngujarati: 0x0ACC,
  25189. avagrahadeva: 0x093D,
  25190. aybarmenian: 0x0561,
  25191. ayin: 0x05E2,
  25192. ayinaltonehebrew: 0xFB20,
  25193. ayinhebrew: 0x05E2,
  25194. b: 0x0062,
  25195. babengali: 0x09AC,
  25196. backslash: 0x005C,
  25197. backslashmonospace: 0xFF3C,
  25198. badeva: 0x092C,
  25199. bagujarati: 0x0AAC,
  25200. bagurmukhi: 0x0A2C,
  25201. bahiragana: 0x3070,
  25202. bahtthai: 0x0E3F,
  25203. bakatakana: 0x30D0,
  25204. bar: 0x007C,
  25205. barmonospace: 0xFF5C,
  25206. bbopomofo: 0x3105,
  25207. bcircle: 0x24D1,
  25208. bdotaccent: 0x1E03,
  25209. bdotbelow: 0x1E05,
  25210. beamedsixteenthnotes: 0x266C,
  25211. because: 0x2235,
  25212. becyrillic: 0x0431,
  25213. beharabic: 0x0628,
  25214. behfinalarabic: 0xFE90,
  25215. behinitialarabic: 0xFE91,
  25216. behiragana: 0x3079,
  25217. behmedialarabic: 0xFE92,
  25218. behmeeminitialarabic: 0xFC9F,
  25219. behmeemisolatedarabic: 0xFC08,
  25220. behnoonfinalarabic: 0xFC6D,
  25221. bekatakana: 0x30D9,
  25222. benarmenian: 0x0562,
  25223. bet: 0x05D1,
  25224. beta: 0x03B2,
  25225. betasymbolgreek: 0x03D0,
  25226. betdagesh: 0xFB31,
  25227. betdageshhebrew: 0xFB31,
  25228. bethebrew: 0x05D1,
  25229. betrafehebrew: 0xFB4C,
  25230. bhabengali: 0x09AD,
  25231. bhadeva: 0x092D,
  25232. bhagujarati: 0x0AAD,
  25233. bhagurmukhi: 0x0A2D,
  25234. bhook: 0x0253,
  25235. bihiragana: 0x3073,
  25236. bikatakana: 0x30D3,
  25237. bilabialclick: 0x0298,
  25238. bindigurmukhi: 0x0A02,
  25239. birusquare: 0x3331,
  25240. blackcircle: 0x25CF,
  25241. blackdiamond: 0x25C6,
  25242. blackdownpointingtriangle: 0x25BC,
  25243. blackleftpointingpointer: 0x25C4,
  25244. blackleftpointingtriangle: 0x25C0,
  25245. blacklenticularbracketleft: 0x3010,
  25246. blacklenticularbracketleftvertical: 0xFE3B,
  25247. blacklenticularbracketright: 0x3011,
  25248. blacklenticularbracketrightvertical: 0xFE3C,
  25249. blacklowerlefttriangle: 0x25E3,
  25250. blacklowerrighttriangle: 0x25E2,
  25251. blackrectangle: 0x25AC,
  25252. blackrightpointingpointer: 0x25BA,
  25253. blackrightpointingtriangle: 0x25B6,
  25254. blacksmallsquare: 0x25AA,
  25255. blacksmilingface: 0x263B,
  25256. blacksquare: 0x25A0,
  25257. blackstar: 0x2605,
  25258. blackupperlefttriangle: 0x25E4,
  25259. blackupperrighttriangle: 0x25E5,
  25260. blackuppointingsmalltriangle: 0x25B4,
  25261. blackuppointingtriangle: 0x25B2,
  25262. blank: 0x2423,
  25263. blinebelow: 0x1E07,
  25264. block: 0x2588,
  25265. bmonospace: 0xFF42,
  25266. bobaimaithai: 0x0E1A,
  25267. bohiragana: 0x307C,
  25268. bokatakana: 0x30DC,
  25269. bparen: 0x249D,
  25270. bqsquare: 0x33C3,
  25271. braceex: 0xF8F4,
  25272. braceleft: 0x007B,
  25273. braceleftbt: 0xF8F3,
  25274. braceleftmid: 0xF8F2,
  25275. braceleftmonospace: 0xFF5B,
  25276. braceleftsmall: 0xFE5B,
  25277. bracelefttp: 0xF8F1,
  25278. braceleftvertical: 0xFE37,
  25279. braceright: 0x007D,
  25280. bracerightbt: 0xF8FE,
  25281. bracerightmid: 0xF8FD,
  25282. bracerightmonospace: 0xFF5D,
  25283. bracerightsmall: 0xFE5C,
  25284. bracerighttp: 0xF8FC,
  25285. bracerightvertical: 0xFE38,
  25286. bracketleft: 0x005B,
  25287. bracketleftbt: 0xF8F0,
  25288. bracketleftex: 0xF8EF,
  25289. bracketleftmonospace: 0xFF3B,
  25290. bracketlefttp: 0xF8EE,
  25291. bracketright: 0x005D,
  25292. bracketrightbt: 0xF8FB,
  25293. bracketrightex: 0xF8FA,
  25294. bracketrightmonospace: 0xFF3D,
  25295. bracketrighttp: 0xF8F9,
  25296. breve: 0x02D8,
  25297. brevebelowcmb: 0x032E,
  25298. brevecmb: 0x0306,
  25299. breveinvertedbelowcmb: 0x032F,
  25300. breveinvertedcmb: 0x0311,
  25301. breveinverteddoublecmb: 0x0361,
  25302. bridgebelowcmb: 0x032A,
  25303. bridgeinvertedbelowcmb: 0x033A,
  25304. brokenbar: 0x00A6,
  25305. bstroke: 0x0180,
  25306. bsuperior: 0xF6EA,
  25307. btopbar: 0x0183,
  25308. buhiragana: 0x3076,
  25309. bukatakana: 0x30D6,
  25310. bullet: 0x2022,
  25311. bulletinverse: 0x25D8,
  25312. bulletoperator: 0x2219,
  25313. bullseye: 0x25CE,
  25314. c: 0x0063,
  25315. caarmenian: 0x056E,
  25316. cabengali: 0x099A,
  25317. cacute: 0x0107,
  25318. cadeva: 0x091A,
  25319. cagujarati: 0x0A9A,
  25320. cagurmukhi: 0x0A1A,
  25321. calsquare: 0x3388,
  25322. candrabindubengali: 0x0981,
  25323. candrabinducmb: 0x0310,
  25324. candrabindudeva: 0x0901,
  25325. candrabindugujarati: 0x0A81,
  25326. capslock: 0x21EA,
  25327. careof: 0x2105,
  25328. caron: 0x02C7,
  25329. caronbelowcmb: 0x032C,
  25330. caroncmb: 0x030C,
  25331. carriagereturn: 0x21B5,
  25332. cbopomofo: 0x3118,
  25333. ccaron: 0x010D,
  25334. ccedilla: 0x00E7,
  25335. ccedillaacute: 0x1E09,
  25336. ccircle: 0x24D2,
  25337. ccircumflex: 0x0109,
  25338. ccurl: 0x0255,
  25339. cdot: 0x010B,
  25340. cdotaccent: 0x010B,
  25341. cdsquare: 0x33C5,
  25342. cedilla: 0x00B8,
  25343. cedillacmb: 0x0327,
  25344. cent: 0x00A2,
  25345. centigrade: 0x2103,
  25346. centinferior: 0xF6DF,
  25347. centmonospace: 0xFFE0,
  25348. centoldstyle: 0xF7A2,
  25349. centsuperior: 0xF6E0,
  25350. chaarmenian: 0x0579,
  25351. chabengali: 0x099B,
  25352. chadeva: 0x091B,
  25353. chagujarati: 0x0A9B,
  25354. chagurmukhi: 0x0A1B,
  25355. chbopomofo: 0x3114,
  25356. cheabkhasiancyrillic: 0x04BD,
  25357. checkmark: 0x2713,
  25358. checyrillic: 0x0447,
  25359. chedescenderabkhasiancyrillic: 0x04BF,
  25360. chedescendercyrillic: 0x04B7,
  25361. chedieresiscyrillic: 0x04F5,
  25362. cheharmenian: 0x0573,
  25363. chekhakassiancyrillic: 0x04CC,
  25364. cheverticalstrokecyrillic: 0x04B9,
  25365. chi: 0x03C7,
  25366. chieuchacirclekorean: 0x3277,
  25367. chieuchaparenkorean: 0x3217,
  25368. chieuchcirclekorean: 0x3269,
  25369. chieuchkorean: 0x314A,
  25370. chieuchparenkorean: 0x3209,
  25371. chochangthai: 0x0E0A,
  25372. chochanthai: 0x0E08,
  25373. chochingthai: 0x0E09,
  25374. chochoethai: 0x0E0C,
  25375. chook: 0x0188,
  25376. cieucacirclekorean: 0x3276,
  25377. cieucaparenkorean: 0x3216,
  25378. cieuccirclekorean: 0x3268,
  25379. cieuckorean: 0x3148,
  25380. cieucparenkorean: 0x3208,
  25381. cieucuparenkorean: 0x321C,
  25382. circle: 0x25CB,
  25383. circlecopyrt: 0x00A9, // This glyph is missing from Adobe's original list.
  25384. circlemultiply: 0x2297,
  25385. circleot: 0x2299,
  25386. circleplus: 0x2295,
  25387. circlepostalmark: 0x3036,
  25388. circlewithlefthalfblack: 0x25D0,
  25389. circlewithrighthalfblack: 0x25D1,
  25390. circumflex: 0x02C6,
  25391. circumflexbelowcmb: 0x032D,
  25392. circumflexcmb: 0x0302,
  25393. clear: 0x2327,
  25394. clickalveolar: 0x01C2,
  25395. clickdental: 0x01C0,
  25396. clicklateral: 0x01C1,
  25397. clickretroflex: 0x01C3,
  25398. club: 0x2663,
  25399. clubsuitblack: 0x2663,
  25400. clubsuitwhite: 0x2667,
  25401. cmcubedsquare: 0x33A4,
  25402. cmonospace: 0xFF43,
  25403. cmsquaredsquare: 0x33A0,
  25404. coarmenian: 0x0581,
  25405. colon: 0x003A,
  25406. colonmonetary: 0x20A1,
  25407. colonmonospace: 0xFF1A,
  25408. colonsign: 0x20A1,
  25409. colonsmall: 0xFE55,
  25410. colontriangularhalfmod: 0x02D1,
  25411. colontriangularmod: 0x02D0,
  25412. comma: 0x002C,
  25413. commaabovecmb: 0x0313,
  25414. commaaboverightcmb: 0x0315,
  25415. commaaccent: 0xF6C3,
  25416. commaarabic: 0x060C,
  25417. commaarmenian: 0x055D,
  25418. commainferior: 0xF6E1,
  25419. commamonospace: 0xFF0C,
  25420. commareversedabovecmb: 0x0314,
  25421. commareversedmod: 0x02BD,
  25422. commasmall: 0xFE50,
  25423. commasuperior: 0xF6E2,
  25424. commaturnedabovecmb: 0x0312,
  25425. commaturnedmod: 0x02BB,
  25426. compass: 0x263C,
  25427. congruent: 0x2245,
  25428. contourintegral: 0x222E,
  25429. control: 0x2303,
  25430. controlACK: 0x0006,
  25431. controlBEL: 0x0007,
  25432. controlBS: 0x0008,
  25433. controlCAN: 0x0018,
  25434. controlCR: 0x000D,
  25435. controlDC1: 0x0011,
  25436. controlDC2: 0x0012,
  25437. controlDC3: 0x0013,
  25438. controlDC4: 0x0014,
  25439. controlDEL: 0x007F,
  25440. controlDLE: 0x0010,
  25441. controlEM: 0x0019,
  25442. controlENQ: 0x0005,
  25443. controlEOT: 0x0004,
  25444. controlESC: 0x001B,
  25445. controlETB: 0x0017,
  25446. controlETX: 0x0003,
  25447. controlFF: 0x000C,
  25448. controlFS: 0x001C,
  25449. controlGS: 0x001D,
  25450. controlHT: 0x0009,
  25451. controlLF: 0x000A,
  25452. controlNAK: 0x0015,
  25453. controlRS: 0x001E,
  25454. controlSI: 0x000F,
  25455. controlSO: 0x000E,
  25456. controlSOT: 0x0002,
  25457. controlSTX: 0x0001,
  25458. controlSUB: 0x001A,
  25459. controlSYN: 0x0016,
  25460. controlUS: 0x001F,
  25461. controlVT: 0x000B,
  25462. copyright: 0x00A9,
  25463. copyrightsans: 0xF8E9,
  25464. copyrightserif: 0xF6D9,
  25465. cornerbracketleft: 0x300C,
  25466. cornerbracketlefthalfwidth: 0xFF62,
  25467. cornerbracketleftvertical: 0xFE41,
  25468. cornerbracketright: 0x300D,
  25469. cornerbracketrighthalfwidth: 0xFF63,
  25470. cornerbracketrightvertical: 0xFE42,
  25471. corporationsquare: 0x337F,
  25472. cosquare: 0x33C7,
  25473. coverkgsquare: 0x33C6,
  25474. cparen: 0x249E,
  25475. cruzeiro: 0x20A2,
  25476. cstretched: 0x0297,
  25477. curlyand: 0x22CF,
  25478. curlyor: 0x22CE,
  25479. currency: 0x00A4,
  25480. cyrBreve: 0xF6D1,
  25481. cyrFlex: 0xF6D2,
  25482. cyrbreve: 0xF6D4,
  25483. cyrflex: 0xF6D5,
  25484. d: 0x0064,
  25485. daarmenian: 0x0564,
  25486. dabengali: 0x09A6,
  25487. dadarabic: 0x0636,
  25488. dadeva: 0x0926,
  25489. dadfinalarabic: 0xFEBE,
  25490. dadinitialarabic: 0xFEBF,
  25491. dadmedialarabic: 0xFEC0,
  25492. dagesh: 0x05BC,
  25493. dageshhebrew: 0x05BC,
  25494. dagger: 0x2020,
  25495. daggerdbl: 0x2021,
  25496. dagujarati: 0x0AA6,
  25497. dagurmukhi: 0x0A26,
  25498. dahiragana: 0x3060,
  25499. dakatakana: 0x30C0,
  25500. dalarabic: 0x062F,
  25501. dalet: 0x05D3,
  25502. daletdagesh: 0xFB33,
  25503. daletdageshhebrew: 0xFB33,
  25504. dalethebrew: 0x05D3,
  25505. dalfinalarabic: 0xFEAA,
  25506. dammaarabic: 0x064F,
  25507. dammalowarabic: 0x064F,
  25508. dammatanaltonearabic: 0x064C,
  25509. dammatanarabic: 0x064C,
  25510. danda: 0x0964,
  25511. dargahebrew: 0x05A7,
  25512. dargalefthebrew: 0x05A7,
  25513. dasiapneumatacyrilliccmb: 0x0485,
  25514. dblGrave: 0xF6D3,
  25515. dblanglebracketleft: 0x300A,
  25516. dblanglebracketleftvertical: 0xFE3D,
  25517. dblanglebracketright: 0x300B,
  25518. dblanglebracketrightvertical: 0xFE3E,
  25519. dblarchinvertedbelowcmb: 0x032B,
  25520. dblarrowleft: 0x21D4,
  25521. dblarrowright: 0x21D2,
  25522. dbldanda: 0x0965,
  25523. dblgrave: 0xF6D6,
  25524. dblgravecmb: 0x030F,
  25525. dblintegral: 0x222C,
  25526. dbllowline: 0x2017,
  25527. dbllowlinecmb: 0x0333,
  25528. dbloverlinecmb: 0x033F,
  25529. dblprimemod: 0x02BA,
  25530. dblverticalbar: 0x2016,
  25531. dblverticallineabovecmb: 0x030E,
  25532. dbopomofo: 0x3109,
  25533. dbsquare: 0x33C8,
  25534. dcaron: 0x010F,
  25535. dcedilla: 0x1E11,
  25536. dcircle: 0x24D3,
  25537. dcircumflexbelow: 0x1E13,
  25538. dcroat: 0x0111,
  25539. ddabengali: 0x09A1,
  25540. ddadeva: 0x0921,
  25541. ddagujarati: 0x0AA1,
  25542. ddagurmukhi: 0x0A21,
  25543. ddalarabic: 0x0688,
  25544. ddalfinalarabic: 0xFB89,
  25545. dddhadeva: 0x095C,
  25546. ddhabengali: 0x09A2,
  25547. ddhadeva: 0x0922,
  25548. ddhagujarati: 0x0AA2,
  25549. ddhagurmukhi: 0x0A22,
  25550. ddotaccent: 0x1E0B,
  25551. ddotbelow: 0x1E0D,
  25552. decimalseparatorarabic: 0x066B,
  25553. decimalseparatorpersian: 0x066B,
  25554. decyrillic: 0x0434,
  25555. degree: 0x00B0,
  25556. dehihebrew: 0x05AD,
  25557. dehiragana: 0x3067,
  25558. deicoptic: 0x03EF,
  25559. dekatakana: 0x30C7,
  25560. deleteleft: 0x232B,
  25561. deleteright: 0x2326,
  25562. delta: 0x03B4,
  25563. deltaturned: 0x018D,
  25564. denominatorminusonenumeratorbengali: 0x09F8,
  25565. dezh: 0x02A4,
  25566. dhabengali: 0x09A7,
  25567. dhadeva: 0x0927,
  25568. dhagujarati: 0x0AA7,
  25569. dhagurmukhi: 0x0A27,
  25570. dhook: 0x0257,
  25571. dialytikatonos: 0x0385,
  25572. dialytikatonoscmb: 0x0344,
  25573. diamond: 0x2666,
  25574. diamondsuitwhite: 0x2662,
  25575. dieresis: 0x00A8,
  25576. dieresisacute: 0xF6D7,
  25577. dieresisbelowcmb: 0x0324,
  25578. dieresiscmb: 0x0308,
  25579. dieresisgrave: 0xF6D8,
  25580. dieresistonos: 0x0385,
  25581. dihiragana: 0x3062,
  25582. dikatakana: 0x30C2,
  25583. dittomark: 0x3003,
  25584. divide: 0x00F7,
  25585. divides: 0x2223,
  25586. divisionslash: 0x2215,
  25587. djecyrillic: 0x0452,
  25588. dkshade: 0x2593,
  25589. dlinebelow: 0x1E0F,
  25590. dlsquare: 0x3397,
  25591. dmacron: 0x0111,
  25592. dmonospace: 0xFF44,
  25593. dnblock: 0x2584,
  25594. dochadathai: 0x0E0E,
  25595. dodekthai: 0x0E14,
  25596. dohiragana: 0x3069,
  25597. dokatakana: 0x30C9,
  25598. dollar: 0x0024,
  25599. dollarinferior: 0xF6E3,
  25600. dollarmonospace: 0xFF04,
  25601. dollaroldstyle: 0xF724,
  25602. dollarsmall: 0xFE69,
  25603. dollarsuperior: 0xF6E4,
  25604. dong: 0x20AB,
  25605. dorusquare: 0x3326,
  25606. dotaccent: 0x02D9,
  25607. dotaccentcmb: 0x0307,
  25608. dotbelowcmb: 0x0323,
  25609. dotbelowcomb: 0x0323,
  25610. dotkatakana: 0x30FB,
  25611. dotlessi: 0x0131,
  25612. dotlessj: 0xF6BE,
  25613. dotlessjstrokehook: 0x0284,
  25614. dotmath: 0x22C5,
  25615. dottedcircle: 0x25CC,
  25616. doubleyodpatah: 0xFB1F,
  25617. doubleyodpatahhebrew: 0xFB1F,
  25618. downtackbelowcmb: 0x031E,
  25619. downtackmod: 0x02D5,
  25620. dparen: 0x249F,
  25621. dsuperior: 0xF6EB,
  25622. dtail: 0x0256,
  25623. dtopbar: 0x018C,
  25624. duhiragana: 0x3065,
  25625. dukatakana: 0x30C5,
  25626. dz: 0x01F3,
  25627. dzaltone: 0x02A3,
  25628. dzcaron: 0x01C6,
  25629. dzcurl: 0x02A5,
  25630. dzeabkhasiancyrillic: 0x04E1,
  25631. dzecyrillic: 0x0455,
  25632. dzhecyrillic: 0x045F,
  25633. e: 0x0065,
  25634. eacute: 0x00E9,
  25635. earth: 0x2641,
  25636. ebengali: 0x098F,
  25637. ebopomofo: 0x311C,
  25638. ebreve: 0x0115,
  25639. ecandradeva: 0x090D,
  25640. ecandragujarati: 0x0A8D,
  25641. ecandravowelsigndeva: 0x0945,
  25642. ecandravowelsigngujarati: 0x0AC5,
  25643. ecaron: 0x011B,
  25644. ecedillabreve: 0x1E1D,
  25645. echarmenian: 0x0565,
  25646. echyiwnarmenian: 0x0587,
  25647. ecircle: 0x24D4,
  25648. ecircumflex: 0x00EA,
  25649. ecircumflexacute: 0x1EBF,
  25650. ecircumflexbelow: 0x1E19,
  25651. ecircumflexdotbelow: 0x1EC7,
  25652. ecircumflexgrave: 0x1EC1,
  25653. ecircumflexhookabove: 0x1EC3,
  25654. ecircumflextilde: 0x1EC5,
  25655. ecyrillic: 0x0454,
  25656. edblgrave: 0x0205,
  25657. edeva: 0x090F,
  25658. edieresis: 0x00EB,
  25659. edot: 0x0117,
  25660. edotaccent: 0x0117,
  25661. edotbelow: 0x1EB9,
  25662. eegurmukhi: 0x0A0F,
  25663. eematragurmukhi: 0x0A47,
  25664. efcyrillic: 0x0444,
  25665. egrave: 0x00E8,
  25666. egujarati: 0x0A8F,
  25667. eharmenian: 0x0567,
  25668. ehbopomofo: 0x311D,
  25669. ehiragana: 0x3048,
  25670. ehookabove: 0x1EBB,
  25671. eibopomofo: 0x311F,
  25672. eight: 0x0038,
  25673. eightarabic: 0x0668,
  25674. eightbengali: 0x09EE,
  25675. eightcircle: 0x2467,
  25676. eightcircleinversesansserif: 0x2791,
  25677. eightdeva: 0x096E,
  25678. eighteencircle: 0x2471,
  25679. eighteenparen: 0x2485,
  25680. eighteenperiod: 0x2499,
  25681. eightgujarati: 0x0AEE,
  25682. eightgurmukhi: 0x0A6E,
  25683. eighthackarabic: 0x0668,
  25684. eighthangzhou: 0x3028,
  25685. eighthnotebeamed: 0x266B,
  25686. eightideographicparen: 0x3227,
  25687. eightinferior: 0x2088,
  25688. eightmonospace: 0xFF18,
  25689. eightoldstyle: 0xF738,
  25690. eightparen: 0x247B,
  25691. eightperiod: 0x248F,
  25692. eightpersian: 0x06F8,
  25693. eightroman: 0x2177,
  25694. eightsuperior: 0x2078,
  25695. eightthai: 0x0E58,
  25696. einvertedbreve: 0x0207,
  25697. eiotifiedcyrillic: 0x0465,
  25698. ekatakana: 0x30A8,
  25699. ekatakanahalfwidth: 0xFF74,
  25700. ekonkargurmukhi: 0x0A74,
  25701. ekorean: 0x3154,
  25702. elcyrillic: 0x043B,
  25703. element: 0x2208,
  25704. elevencircle: 0x246A,
  25705. elevenparen: 0x247E,
  25706. elevenperiod: 0x2492,
  25707. elevenroman: 0x217A,
  25708. ellipsis: 0x2026,
  25709. ellipsisvertical: 0x22EE,
  25710. emacron: 0x0113,
  25711. emacronacute: 0x1E17,
  25712. emacrongrave: 0x1E15,
  25713. emcyrillic: 0x043C,
  25714. emdash: 0x2014,
  25715. emdashvertical: 0xFE31,
  25716. emonospace: 0xFF45,
  25717. emphasismarkarmenian: 0x055B,
  25718. emptyset: 0x2205,
  25719. enbopomofo: 0x3123,
  25720. encyrillic: 0x043D,
  25721. endash: 0x2013,
  25722. endashvertical: 0xFE32,
  25723. endescendercyrillic: 0x04A3,
  25724. eng: 0x014B,
  25725. engbopomofo: 0x3125,
  25726. enghecyrillic: 0x04A5,
  25727. enhookcyrillic: 0x04C8,
  25728. enspace: 0x2002,
  25729. eogonek: 0x0119,
  25730. eokorean: 0x3153,
  25731. eopen: 0x025B,
  25732. eopenclosed: 0x029A,
  25733. eopenreversed: 0x025C,
  25734. eopenreversedclosed: 0x025E,
  25735. eopenreversedhook: 0x025D,
  25736. eparen: 0x24A0,
  25737. epsilon: 0x03B5,
  25738. epsilontonos: 0x03AD,
  25739. equal: 0x003D,
  25740. equalmonospace: 0xFF1D,
  25741. equalsmall: 0xFE66,
  25742. equalsuperior: 0x207C,
  25743. equivalence: 0x2261,
  25744. erbopomofo: 0x3126,
  25745. ercyrillic: 0x0440,
  25746. ereversed: 0x0258,
  25747. ereversedcyrillic: 0x044D,
  25748. escyrillic: 0x0441,
  25749. esdescendercyrillic: 0x04AB,
  25750. esh: 0x0283,
  25751. eshcurl: 0x0286,
  25752. eshortdeva: 0x090E,
  25753. eshortvowelsigndeva: 0x0946,
  25754. eshreversedloop: 0x01AA,
  25755. eshsquatreversed: 0x0285,
  25756. esmallhiragana: 0x3047,
  25757. esmallkatakana: 0x30A7,
  25758. esmallkatakanahalfwidth: 0xFF6A,
  25759. estimated: 0x212E,
  25760. esuperior: 0xF6EC,
  25761. eta: 0x03B7,
  25762. etarmenian: 0x0568,
  25763. etatonos: 0x03AE,
  25764. eth: 0x00F0,
  25765. etilde: 0x1EBD,
  25766. etildebelow: 0x1E1B,
  25767. etnahtafoukhhebrew: 0x0591,
  25768. etnahtafoukhlefthebrew: 0x0591,
  25769. etnahtahebrew: 0x0591,
  25770. etnahtalefthebrew: 0x0591,
  25771. eturned: 0x01DD,
  25772. eukorean: 0x3161,
  25773. euro: 0x20AC,
  25774. evowelsignbengali: 0x09C7,
  25775. evowelsigndeva: 0x0947,
  25776. evowelsigngujarati: 0x0AC7,
  25777. exclam: 0x0021,
  25778. exclamarmenian: 0x055C,
  25779. exclamdbl: 0x203C,
  25780. exclamdown: 0x00A1,
  25781. exclamdownsmall: 0xF7A1,
  25782. exclammonospace: 0xFF01,
  25783. exclamsmall: 0xF721,
  25784. existential: 0x2203,
  25785. ezh: 0x0292,
  25786. ezhcaron: 0x01EF,
  25787. ezhcurl: 0x0293,
  25788. ezhreversed: 0x01B9,
  25789. ezhtail: 0x01BA,
  25790. f: 0x0066,
  25791. fadeva: 0x095E,
  25792. fagurmukhi: 0x0A5E,
  25793. fahrenheit: 0x2109,
  25794. fathaarabic: 0x064E,
  25795. fathalowarabic: 0x064E,
  25796. fathatanarabic: 0x064B,
  25797. fbopomofo: 0x3108,
  25798. fcircle: 0x24D5,
  25799. fdotaccent: 0x1E1F,
  25800. feharabic: 0x0641,
  25801. feharmenian: 0x0586,
  25802. fehfinalarabic: 0xFED2,
  25803. fehinitialarabic: 0xFED3,
  25804. fehmedialarabic: 0xFED4,
  25805. feicoptic: 0x03E5,
  25806. female: 0x2640,
  25807. ff: 0xFB00,
  25808. ffi: 0xFB03,
  25809. ffl: 0xFB04,
  25810. fi: 0xFB01,
  25811. fifteencircle: 0x246E,
  25812. fifteenparen: 0x2482,
  25813. fifteenperiod: 0x2496,
  25814. figuredash: 0x2012,
  25815. filledbox: 0x25A0,
  25816. filledrect: 0x25AC,
  25817. finalkaf: 0x05DA,
  25818. finalkafdagesh: 0xFB3A,
  25819. finalkafdageshhebrew: 0xFB3A,
  25820. finalkafhebrew: 0x05DA,
  25821. finalmem: 0x05DD,
  25822. finalmemhebrew: 0x05DD,
  25823. finalnun: 0x05DF,
  25824. finalnunhebrew: 0x05DF,
  25825. finalpe: 0x05E3,
  25826. finalpehebrew: 0x05E3,
  25827. finaltsadi: 0x05E5,
  25828. finaltsadihebrew: 0x05E5,
  25829. firsttonechinese: 0x02C9,
  25830. fisheye: 0x25C9,
  25831. fitacyrillic: 0x0473,
  25832. five: 0x0035,
  25833. fivearabic: 0x0665,
  25834. fivebengali: 0x09EB,
  25835. fivecircle: 0x2464,
  25836. fivecircleinversesansserif: 0x278E,
  25837. fivedeva: 0x096B,
  25838. fiveeighths: 0x215D,
  25839. fivegujarati: 0x0AEB,
  25840. fivegurmukhi: 0x0A6B,
  25841. fivehackarabic: 0x0665,
  25842. fivehangzhou: 0x3025,
  25843. fiveideographicparen: 0x3224,
  25844. fiveinferior: 0x2085,
  25845. fivemonospace: 0xFF15,
  25846. fiveoldstyle: 0xF735,
  25847. fiveparen: 0x2478,
  25848. fiveperiod: 0x248C,
  25849. fivepersian: 0x06F5,
  25850. fiveroman: 0x2174,
  25851. fivesuperior: 0x2075,
  25852. fivethai: 0x0E55,
  25853. fl: 0xFB02,
  25854. florin: 0x0192,
  25855. fmonospace: 0xFF46,
  25856. fmsquare: 0x3399,
  25857. fofanthai: 0x0E1F,
  25858. fofathai: 0x0E1D,
  25859. fongmanthai: 0x0E4F,
  25860. forall: 0x2200,
  25861. four: 0x0034,
  25862. fourarabic: 0x0664,
  25863. fourbengali: 0x09EA,
  25864. fourcircle: 0x2463,
  25865. fourcircleinversesansserif: 0x278D,
  25866. fourdeva: 0x096A,
  25867. fourgujarati: 0x0AEA,
  25868. fourgurmukhi: 0x0A6A,
  25869. fourhackarabic: 0x0664,
  25870. fourhangzhou: 0x3024,
  25871. fourideographicparen: 0x3223,
  25872. fourinferior: 0x2084,
  25873. fourmonospace: 0xFF14,
  25874. fournumeratorbengali: 0x09F7,
  25875. fouroldstyle: 0xF734,
  25876. fourparen: 0x2477,
  25877. fourperiod: 0x248B,
  25878. fourpersian: 0x06F4,
  25879. fourroman: 0x2173,
  25880. foursuperior: 0x2074,
  25881. fourteencircle: 0x246D,
  25882. fourteenparen: 0x2481,
  25883. fourteenperiod: 0x2495,
  25884. fourthai: 0x0E54,
  25885. fourthtonechinese: 0x02CB,
  25886. fparen: 0x24A1,
  25887. fraction: 0x2044,
  25888. franc: 0x20A3,
  25889. g: 0x0067,
  25890. gabengali: 0x0997,
  25891. gacute: 0x01F5,
  25892. gadeva: 0x0917,
  25893. gafarabic: 0x06AF,
  25894. gaffinalarabic: 0xFB93,
  25895. gafinitialarabic: 0xFB94,
  25896. gafmedialarabic: 0xFB95,
  25897. gagujarati: 0x0A97,
  25898. gagurmukhi: 0x0A17,
  25899. gahiragana: 0x304C,
  25900. gakatakana: 0x30AC,
  25901. gamma: 0x03B3,
  25902. gammalatinsmall: 0x0263,
  25903. gammasuperior: 0x02E0,
  25904. gangiacoptic: 0x03EB,
  25905. gbopomofo: 0x310D,
  25906. gbreve: 0x011F,
  25907. gcaron: 0x01E7,
  25908. gcedilla: 0x0123,
  25909. gcircle: 0x24D6,
  25910. gcircumflex: 0x011D,
  25911. gcommaaccent: 0x0123,
  25912. gdot: 0x0121,
  25913. gdotaccent: 0x0121,
  25914. gecyrillic: 0x0433,
  25915. gehiragana: 0x3052,
  25916. gekatakana: 0x30B2,
  25917. geometricallyequal: 0x2251,
  25918. gereshaccenthebrew: 0x059C,
  25919. gereshhebrew: 0x05F3,
  25920. gereshmuqdamhebrew: 0x059D,
  25921. germandbls: 0x00DF,
  25922. gershayimaccenthebrew: 0x059E,
  25923. gershayimhebrew: 0x05F4,
  25924. getamark: 0x3013,
  25925. ghabengali: 0x0998,
  25926. ghadarmenian: 0x0572,
  25927. ghadeva: 0x0918,
  25928. ghagujarati: 0x0A98,
  25929. ghagurmukhi: 0x0A18,
  25930. ghainarabic: 0x063A,
  25931. ghainfinalarabic: 0xFECE,
  25932. ghaininitialarabic: 0xFECF,
  25933. ghainmedialarabic: 0xFED0,
  25934. ghemiddlehookcyrillic: 0x0495,
  25935. ghestrokecyrillic: 0x0493,
  25936. gheupturncyrillic: 0x0491,
  25937. ghhadeva: 0x095A,
  25938. ghhagurmukhi: 0x0A5A,
  25939. ghook: 0x0260,
  25940. ghzsquare: 0x3393,
  25941. gihiragana: 0x304E,
  25942. gikatakana: 0x30AE,
  25943. gimarmenian: 0x0563,
  25944. gimel: 0x05D2,
  25945. gimeldagesh: 0xFB32,
  25946. gimeldageshhebrew: 0xFB32,
  25947. gimelhebrew: 0x05D2,
  25948. gjecyrillic: 0x0453,
  25949. glottalinvertedstroke: 0x01BE,
  25950. glottalstop: 0x0294,
  25951. glottalstopinverted: 0x0296,
  25952. glottalstopmod: 0x02C0,
  25953. glottalstopreversed: 0x0295,
  25954. glottalstopreversedmod: 0x02C1,
  25955. glottalstopreversedsuperior: 0x02E4,
  25956. glottalstopstroke: 0x02A1,
  25957. glottalstopstrokereversed: 0x02A2,
  25958. gmacron: 0x1E21,
  25959. gmonospace: 0xFF47,
  25960. gohiragana: 0x3054,
  25961. gokatakana: 0x30B4,
  25962. gparen: 0x24A2,
  25963. gpasquare: 0x33AC,
  25964. gradient: 0x2207,
  25965. grave: 0x0060,
  25966. gravebelowcmb: 0x0316,
  25967. gravecmb: 0x0300,
  25968. gravecomb: 0x0300,
  25969. gravedeva: 0x0953,
  25970. gravelowmod: 0x02CE,
  25971. gravemonospace: 0xFF40,
  25972. gravetonecmb: 0x0340,
  25973. greater: 0x003E,
  25974. greaterequal: 0x2265,
  25975. greaterequalorless: 0x22DB,
  25976. greatermonospace: 0xFF1E,
  25977. greaterorequivalent: 0x2273,
  25978. greaterorless: 0x2277,
  25979. greateroverequal: 0x2267,
  25980. greatersmall: 0xFE65,
  25981. gscript: 0x0261,
  25982. gstroke: 0x01E5,
  25983. guhiragana: 0x3050,
  25984. guillemotleft: 0x00AB,
  25985. guillemotright: 0x00BB,
  25986. guilsinglleft: 0x2039,
  25987. guilsinglright: 0x203A,
  25988. gukatakana: 0x30B0,
  25989. guramusquare: 0x3318,
  25990. gysquare: 0x33C9,
  25991. h: 0x0068,
  25992. haabkhasiancyrillic: 0x04A9,
  25993. haaltonearabic: 0x06C1,
  25994. habengali: 0x09B9,
  25995. hadescendercyrillic: 0x04B3,
  25996. hadeva: 0x0939,
  25997. hagujarati: 0x0AB9,
  25998. hagurmukhi: 0x0A39,
  25999. haharabic: 0x062D,
  26000. hahfinalarabic: 0xFEA2,
  26001. hahinitialarabic: 0xFEA3,
  26002. hahiragana: 0x306F,
  26003. hahmedialarabic: 0xFEA4,
  26004. haitusquare: 0x332A,
  26005. hakatakana: 0x30CF,
  26006. hakatakanahalfwidth: 0xFF8A,
  26007. halantgurmukhi: 0x0A4D,
  26008. hamzaarabic: 0x0621,
  26009. hamzalowarabic: 0x0621,
  26010. hangulfiller: 0x3164,
  26011. hardsigncyrillic: 0x044A,
  26012. harpoonleftbarbup: 0x21BC,
  26013. harpoonrightbarbup: 0x21C0,
  26014. hasquare: 0x33CA,
  26015. hatafpatah: 0x05B2,
  26016. hatafpatah16: 0x05B2,
  26017. hatafpatah23: 0x05B2,
  26018. hatafpatah2f: 0x05B2,
  26019. hatafpatahhebrew: 0x05B2,
  26020. hatafpatahnarrowhebrew: 0x05B2,
  26021. hatafpatahquarterhebrew: 0x05B2,
  26022. hatafpatahwidehebrew: 0x05B2,
  26023. hatafqamats: 0x05B3,
  26024. hatafqamats1b: 0x05B3,
  26025. hatafqamats28: 0x05B3,
  26026. hatafqamats34: 0x05B3,
  26027. hatafqamatshebrew: 0x05B3,
  26028. hatafqamatsnarrowhebrew: 0x05B3,
  26029. hatafqamatsquarterhebrew: 0x05B3,
  26030. hatafqamatswidehebrew: 0x05B3,
  26031. hatafsegol: 0x05B1,
  26032. hatafsegol17: 0x05B1,
  26033. hatafsegol24: 0x05B1,
  26034. hatafsegol30: 0x05B1,
  26035. hatafsegolhebrew: 0x05B1,
  26036. hatafsegolnarrowhebrew: 0x05B1,
  26037. hatafsegolquarterhebrew: 0x05B1,
  26038. hatafsegolwidehebrew: 0x05B1,
  26039. hbar: 0x0127,
  26040. hbopomofo: 0x310F,
  26041. hbrevebelow: 0x1E2B,
  26042. hcedilla: 0x1E29,
  26043. hcircle: 0x24D7,
  26044. hcircumflex: 0x0125,
  26045. hdieresis: 0x1E27,
  26046. hdotaccent: 0x1E23,
  26047. hdotbelow: 0x1E25,
  26048. he: 0x05D4,
  26049. heart: 0x2665,
  26050. heartsuitblack: 0x2665,
  26051. heartsuitwhite: 0x2661,
  26052. hedagesh: 0xFB34,
  26053. hedageshhebrew: 0xFB34,
  26054. hehaltonearabic: 0x06C1,
  26055. heharabic: 0x0647,
  26056. hehebrew: 0x05D4,
  26057. hehfinalaltonearabic: 0xFBA7,
  26058. hehfinalalttwoarabic: 0xFEEA,
  26059. hehfinalarabic: 0xFEEA,
  26060. hehhamzaabovefinalarabic: 0xFBA5,
  26061. hehhamzaaboveisolatedarabic: 0xFBA4,
  26062. hehinitialaltonearabic: 0xFBA8,
  26063. hehinitialarabic: 0xFEEB,
  26064. hehiragana: 0x3078,
  26065. hehmedialaltonearabic: 0xFBA9,
  26066. hehmedialarabic: 0xFEEC,
  26067. heiseierasquare: 0x337B,
  26068. hekatakana: 0x30D8,
  26069. hekatakanahalfwidth: 0xFF8D,
  26070. hekutaarusquare: 0x3336,
  26071. henghook: 0x0267,
  26072. herutusquare: 0x3339,
  26073. het: 0x05D7,
  26074. hethebrew: 0x05D7,
  26075. hhook: 0x0266,
  26076. hhooksuperior: 0x02B1,
  26077. hieuhacirclekorean: 0x327B,
  26078. hieuhaparenkorean: 0x321B,
  26079. hieuhcirclekorean: 0x326D,
  26080. hieuhkorean: 0x314E,
  26081. hieuhparenkorean: 0x320D,
  26082. hihiragana: 0x3072,
  26083. hikatakana: 0x30D2,
  26084. hikatakanahalfwidth: 0xFF8B,
  26085. hiriq: 0x05B4,
  26086. hiriq14: 0x05B4,
  26087. hiriq21: 0x05B4,
  26088. hiriq2d: 0x05B4,
  26089. hiriqhebrew: 0x05B4,
  26090. hiriqnarrowhebrew: 0x05B4,
  26091. hiriqquarterhebrew: 0x05B4,
  26092. hiriqwidehebrew: 0x05B4,
  26093. hlinebelow: 0x1E96,
  26094. hmonospace: 0xFF48,
  26095. hoarmenian: 0x0570,
  26096. hohipthai: 0x0E2B,
  26097. hohiragana: 0x307B,
  26098. hokatakana: 0x30DB,
  26099. hokatakanahalfwidth: 0xFF8E,
  26100. holam: 0x05B9,
  26101. holam19: 0x05B9,
  26102. holam26: 0x05B9,
  26103. holam32: 0x05B9,
  26104. holamhebrew: 0x05B9,
  26105. holamnarrowhebrew: 0x05B9,
  26106. holamquarterhebrew: 0x05B9,
  26107. holamwidehebrew: 0x05B9,
  26108. honokhukthai: 0x0E2E,
  26109. hookabovecomb: 0x0309,
  26110. hookcmb: 0x0309,
  26111. hookpalatalizedbelowcmb: 0x0321,
  26112. hookretroflexbelowcmb: 0x0322,
  26113. hoonsquare: 0x3342,
  26114. horicoptic: 0x03E9,
  26115. horizontalbar: 0x2015,
  26116. horncmb: 0x031B,
  26117. hotsprings: 0x2668,
  26118. house: 0x2302,
  26119. hparen: 0x24A3,
  26120. hsuperior: 0x02B0,
  26121. hturned: 0x0265,
  26122. huhiragana: 0x3075,
  26123. huiitosquare: 0x3333,
  26124. hukatakana: 0x30D5,
  26125. hukatakanahalfwidth: 0xFF8C,
  26126. hungarumlaut: 0x02DD,
  26127. hungarumlautcmb: 0x030B,
  26128. hv: 0x0195,
  26129. hyphen: 0x002D,
  26130. hypheninferior: 0xF6E5,
  26131. hyphenmonospace: 0xFF0D,
  26132. hyphensmall: 0xFE63,
  26133. hyphensuperior: 0xF6E6,
  26134. hyphentwo: 0x2010,
  26135. i: 0x0069,
  26136. iacute: 0x00ED,
  26137. iacyrillic: 0x044F,
  26138. ibengali: 0x0987,
  26139. ibopomofo: 0x3127,
  26140. ibreve: 0x012D,
  26141. icaron: 0x01D0,
  26142. icircle: 0x24D8,
  26143. icircumflex: 0x00EE,
  26144. icyrillic: 0x0456,
  26145. idblgrave: 0x0209,
  26146. ideographearthcircle: 0x328F,
  26147. ideographfirecircle: 0x328B,
  26148. ideographicallianceparen: 0x323F,
  26149. ideographiccallparen: 0x323A,
  26150. ideographiccentrecircle: 0x32A5,
  26151. ideographicclose: 0x3006,
  26152. ideographiccomma: 0x3001,
  26153. ideographiccommaleft: 0xFF64,
  26154. ideographiccongratulationparen: 0x3237,
  26155. ideographiccorrectcircle: 0x32A3,
  26156. ideographicearthparen: 0x322F,
  26157. ideographicenterpriseparen: 0x323D,
  26158. ideographicexcellentcircle: 0x329D,
  26159. ideographicfestivalparen: 0x3240,
  26160. ideographicfinancialcircle: 0x3296,
  26161. ideographicfinancialparen: 0x3236,
  26162. ideographicfireparen: 0x322B,
  26163. ideographichaveparen: 0x3232,
  26164. ideographichighcircle: 0x32A4,
  26165. ideographiciterationmark: 0x3005,
  26166. ideographiclaborcircle: 0x3298,
  26167. ideographiclaborparen: 0x3238,
  26168. ideographicleftcircle: 0x32A7,
  26169. ideographiclowcircle: 0x32A6,
  26170. ideographicmedicinecircle: 0x32A9,
  26171. ideographicmetalparen: 0x322E,
  26172. ideographicmoonparen: 0x322A,
  26173. ideographicnameparen: 0x3234,
  26174. ideographicperiod: 0x3002,
  26175. ideographicprintcircle: 0x329E,
  26176. ideographicreachparen: 0x3243,
  26177. ideographicrepresentparen: 0x3239,
  26178. ideographicresourceparen: 0x323E,
  26179. ideographicrightcircle: 0x32A8,
  26180. ideographicsecretcircle: 0x3299,
  26181. ideographicselfparen: 0x3242,
  26182. ideographicsocietyparen: 0x3233,
  26183. ideographicspace: 0x3000,
  26184. ideographicspecialparen: 0x3235,
  26185. ideographicstockparen: 0x3231,
  26186. ideographicstudyparen: 0x323B,
  26187. ideographicsunparen: 0x3230,
  26188. ideographicsuperviseparen: 0x323C,
  26189. ideographicwaterparen: 0x322C,
  26190. ideographicwoodparen: 0x322D,
  26191. ideographiczero: 0x3007,
  26192. ideographmetalcircle: 0x328E,
  26193. ideographmooncircle: 0x328A,
  26194. ideographnamecircle: 0x3294,
  26195. ideographsuncircle: 0x3290,
  26196. ideographwatercircle: 0x328C,
  26197. ideographwoodcircle: 0x328D,
  26198. ideva: 0x0907,
  26199. idieresis: 0x00EF,
  26200. idieresisacute: 0x1E2F,
  26201. idieresiscyrillic: 0x04E5,
  26202. idotbelow: 0x1ECB,
  26203. iebrevecyrillic: 0x04D7,
  26204. iecyrillic: 0x0435,
  26205. ieungacirclekorean: 0x3275,
  26206. ieungaparenkorean: 0x3215,
  26207. ieungcirclekorean: 0x3267,
  26208. ieungkorean: 0x3147,
  26209. ieungparenkorean: 0x3207,
  26210. igrave: 0x00EC,
  26211. igujarati: 0x0A87,
  26212. igurmukhi: 0x0A07,
  26213. ihiragana: 0x3044,
  26214. ihookabove: 0x1EC9,
  26215. iibengali: 0x0988,
  26216. iicyrillic: 0x0438,
  26217. iideva: 0x0908,
  26218. iigujarati: 0x0A88,
  26219. iigurmukhi: 0x0A08,
  26220. iimatragurmukhi: 0x0A40,
  26221. iinvertedbreve: 0x020B,
  26222. iishortcyrillic: 0x0439,
  26223. iivowelsignbengali: 0x09C0,
  26224. iivowelsigndeva: 0x0940,
  26225. iivowelsigngujarati: 0x0AC0,
  26226. ij: 0x0133,
  26227. ikatakana: 0x30A4,
  26228. ikatakanahalfwidth: 0xFF72,
  26229. ikorean: 0x3163,
  26230. ilde: 0x02DC,
  26231. iluyhebrew: 0x05AC,
  26232. imacron: 0x012B,
  26233. imacroncyrillic: 0x04E3,
  26234. imageorapproximatelyequal: 0x2253,
  26235. imatragurmukhi: 0x0A3F,
  26236. imonospace: 0xFF49,
  26237. increment: 0x2206,
  26238. infinity: 0x221E,
  26239. iniarmenian: 0x056B,
  26240. integral: 0x222B,
  26241. integralbottom: 0x2321,
  26242. integralbt: 0x2321,
  26243. integralex: 0xF8F5,
  26244. integraltop: 0x2320,
  26245. integraltp: 0x2320,
  26246. intersection: 0x2229,
  26247. intisquare: 0x3305,
  26248. invbullet: 0x25D8,
  26249. invcircle: 0x25D9,
  26250. invsmileface: 0x263B,
  26251. iocyrillic: 0x0451,
  26252. iogonek: 0x012F,
  26253. iota: 0x03B9,
  26254. iotadieresis: 0x03CA,
  26255. iotadieresistonos: 0x0390,
  26256. iotalatin: 0x0269,
  26257. iotatonos: 0x03AF,
  26258. iparen: 0x24A4,
  26259. irigurmukhi: 0x0A72,
  26260. ismallhiragana: 0x3043,
  26261. ismallkatakana: 0x30A3,
  26262. ismallkatakanahalfwidth: 0xFF68,
  26263. issharbengali: 0x09FA,
  26264. istroke: 0x0268,
  26265. isuperior: 0xF6ED,
  26266. iterationhiragana: 0x309D,
  26267. iterationkatakana: 0x30FD,
  26268. itilde: 0x0129,
  26269. itildebelow: 0x1E2D,
  26270. iubopomofo: 0x3129,
  26271. iucyrillic: 0x044E,
  26272. ivowelsignbengali: 0x09BF,
  26273. ivowelsigndeva: 0x093F,
  26274. ivowelsigngujarati: 0x0ABF,
  26275. izhitsacyrillic: 0x0475,
  26276. izhitsadblgravecyrillic: 0x0477,
  26277. j: 0x006A,
  26278. jaarmenian: 0x0571,
  26279. jabengali: 0x099C,
  26280. jadeva: 0x091C,
  26281. jagujarati: 0x0A9C,
  26282. jagurmukhi: 0x0A1C,
  26283. jbopomofo: 0x3110,
  26284. jcaron: 0x01F0,
  26285. jcircle: 0x24D9,
  26286. jcircumflex: 0x0135,
  26287. jcrossedtail: 0x029D,
  26288. jdotlessstroke: 0x025F,
  26289. jecyrillic: 0x0458,
  26290. jeemarabic: 0x062C,
  26291. jeemfinalarabic: 0xFE9E,
  26292. jeeminitialarabic: 0xFE9F,
  26293. jeemmedialarabic: 0xFEA0,
  26294. jeharabic: 0x0698,
  26295. jehfinalarabic: 0xFB8B,
  26296. jhabengali: 0x099D,
  26297. jhadeva: 0x091D,
  26298. jhagujarati: 0x0A9D,
  26299. jhagurmukhi: 0x0A1D,
  26300. jheharmenian: 0x057B,
  26301. jis: 0x3004,
  26302. jmonospace: 0xFF4A,
  26303. jparen: 0x24A5,
  26304. jsuperior: 0x02B2,
  26305. k: 0x006B,
  26306. kabashkircyrillic: 0x04A1,
  26307. kabengali: 0x0995,
  26308. kacute: 0x1E31,
  26309. kacyrillic: 0x043A,
  26310. kadescendercyrillic: 0x049B,
  26311. kadeva: 0x0915,
  26312. kaf: 0x05DB,
  26313. kafarabic: 0x0643,
  26314. kafdagesh: 0xFB3B,
  26315. kafdageshhebrew: 0xFB3B,
  26316. kaffinalarabic: 0xFEDA,
  26317. kafhebrew: 0x05DB,
  26318. kafinitialarabic: 0xFEDB,
  26319. kafmedialarabic: 0xFEDC,
  26320. kafrafehebrew: 0xFB4D,
  26321. kagujarati: 0x0A95,
  26322. kagurmukhi: 0x0A15,
  26323. kahiragana: 0x304B,
  26324. kahookcyrillic: 0x04C4,
  26325. kakatakana: 0x30AB,
  26326. kakatakanahalfwidth: 0xFF76,
  26327. kappa: 0x03BA,
  26328. kappasymbolgreek: 0x03F0,
  26329. kapyeounmieumkorean: 0x3171,
  26330. kapyeounphieuphkorean: 0x3184,
  26331. kapyeounpieupkorean: 0x3178,
  26332. kapyeounssangpieupkorean: 0x3179,
  26333. karoriisquare: 0x330D,
  26334. kashidaautoarabic: 0x0640,
  26335. kashidaautonosidebearingarabic: 0x0640,
  26336. kasmallkatakana: 0x30F5,
  26337. kasquare: 0x3384,
  26338. kasraarabic: 0x0650,
  26339. kasratanarabic: 0x064D,
  26340. kastrokecyrillic: 0x049F,
  26341. katahiraprolongmarkhalfwidth: 0xFF70,
  26342. kaverticalstrokecyrillic: 0x049D,
  26343. kbopomofo: 0x310E,
  26344. kcalsquare: 0x3389,
  26345. kcaron: 0x01E9,
  26346. kcedilla: 0x0137,
  26347. kcircle: 0x24DA,
  26348. kcommaaccent: 0x0137,
  26349. kdotbelow: 0x1E33,
  26350. keharmenian: 0x0584,
  26351. kehiragana: 0x3051,
  26352. kekatakana: 0x30B1,
  26353. kekatakanahalfwidth: 0xFF79,
  26354. kenarmenian: 0x056F,
  26355. kesmallkatakana: 0x30F6,
  26356. kgreenlandic: 0x0138,
  26357. khabengali: 0x0996,
  26358. khacyrillic: 0x0445,
  26359. khadeva: 0x0916,
  26360. khagujarati: 0x0A96,
  26361. khagurmukhi: 0x0A16,
  26362. khaharabic: 0x062E,
  26363. khahfinalarabic: 0xFEA6,
  26364. khahinitialarabic: 0xFEA7,
  26365. khahmedialarabic: 0xFEA8,
  26366. kheicoptic: 0x03E7,
  26367. khhadeva: 0x0959,
  26368. khhagurmukhi: 0x0A59,
  26369. khieukhacirclekorean: 0x3278,
  26370. khieukhaparenkorean: 0x3218,
  26371. khieukhcirclekorean: 0x326A,
  26372. khieukhkorean: 0x314B,
  26373. khieukhparenkorean: 0x320A,
  26374. khokhaithai: 0x0E02,
  26375. khokhonthai: 0x0E05,
  26376. khokhuatthai: 0x0E03,
  26377. khokhwaithai: 0x0E04,
  26378. khomutthai: 0x0E5B,
  26379. khook: 0x0199,
  26380. khorakhangthai: 0x0E06,
  26381. khzsquare: 0x3391,
  26382. kihiragana: 0x304D,
  26383. kikatakana: 0x30AD,
  26384. kikatakanahalfwidth: 0xFF77,
  26385. kiroguramusquare: 0x3315,
  26386. kiromeetorusquare: 0x3316,
  26387. kirosquare: 0x3314,
  26388. kiyeokacirclekorean: 0x326E,
  26389. kiyeokaparenkorean: 0x320E,
  26390. kiyeokcirclekorean: 0x3260,
  26391. kiyeokkorean: 0x3131,
  26392. kiyeokparenkorean: 0x3200,
  26393. kiyeoksioskorean: 0x3133,
  26394. kjecyrillic: 0x045C,
  26395. klinebelow: 0x1E35,
  26396. klsquare: 0x3398,
  26397. kmcubedsquare: 0x33A6,
  26398. kmonospace: 0xFF4B,
  26399. kmsquaredsquare: 0x33A2,
  26400. kohiragana: 0x3053,
  26401. kohmsquare: 0x33C0,
  26402. kokaithai: 0x0E01,
  26403. kokatakana: 0x30B3,
  26404. kokatakanahalfwidth: 0xFF7A,
  26405. kooposquare: 0x331E,
  26406. koppacyrillic: 0x0481,
  26407. koreanstandardsymbol: 0x327F,
  26408. koroniscmb: 0x0343,
  26409. kparen: 0x24A6,
  26410. kpasquare: 0x33AA,
  26411. ksicyrillic: 0x046F,
  26412. ktsquare: 0x33CF,
  26413. kturned: 0x029E,
  26414. kuhiragana: 0x304F,
  26415. kukatakana: 0x30AF,
  26416. kukatakanahalfwidth: 0xFF78,
  26417. kvsquare: 0x33B8,
  26418. kwsquare: 0x33BE,
  26419. l: 0x006C,
  26420. labengali: 0x09B2,
  26421. lacute: 0x013A,
  26422. ladeva: 0x0932,
  26423. lagujarati: 0x0AB2,
  26424. lagurmukhi: 0x0A32,
  26425. lakkhangyaothai: 0x0E45,
  26426. lamaleffinalarabic: 0xFEFC,
  26427. lamalefhamzaabovefinalarabic: 0xFEF8,
  26428. lamalefhamzaaboveisolatedarabic: 0xFEF7,
  26429. lamalefhamzabelowfinalarabic: 0xFEFA,
  26430. lamalefhamzabelowisolatedarabic: 0xFEF9,
  26431. lamalefisolatedarabic: 0xFEFB,
  26432. lamalefmaddaabovefinalarabic: 0xFEF6,
  26433. lamalefmaddaaboveisolatedarabic: 0xFEF5,
  26434. lamarabic: 0x0644,
  26435. lambda: 0x03BB,
  26436. lambdastroke: 0x019B,
  26437. lamed: 0x05DC,
  26438. lameddagesh: 0xFB3C,
  26439. lameddageshhebrew: 0xFB3C,
  26440. lamedhebrew: 0x05DC,
  26441. lamfinalarabic: 0xFEDE,
  26442. lamhahinitialarabic: 0xFCCA,
  26443. laminitialarabic: 0xFEDF,
  26444. lamjeeminitialarabic: 0xFCC9,
  26445. lamkhahinitialarabic: 0xFCCB,
  26446. lamlamhehisolatedarabic: 0xFDF2,
  26447. lammedialarabic: 0xFEE0,
  26448. lammeemhahinitialarabic: 0xFD88,
  26449. lammeeminitialarabic: 0xFCCC,
  26450. largecircle: 0x25EF,
  26451. lbar: 0x019A,
  26452. lbelt: 0x026C,
  26453. lbopomofo: 0x310C,
  26454. lcaron: 0x013E,
  26455. lcedilla: 0x013C,
  26456. lcircle: 0x24DB,
  26457. lcircumflexbelow: 0x1E3D,
  26458. lcommaaccent: 0x013C,
  26459. ldot: 0x0140,
  26460. ldotaccent: 0x0140,
  26461. ldotbelow: 0x1E37,
  26462. ldotbelowmacron: 0x1E39,
  26463. leftangleabovecmb: 0x031A,
  26464. lefttackbelowcmb: 0x0318,
  26465. less: 0x003C,
  26466. lessequal: 0x2264,
  26467. lessequalorgreater: 0x22DA,
  26468. lessmonospace: 0xFF1C,
  26469. lessorequivalent: 0x2272,
  26470. lessorgreater: 0x2276,
  26471. lessoverequal: 0x2266,
  26472. lesssmall: 0xFE64,
  26473. lezh: 0x026E,
  26474. lfblock: 0x258C,
  26475. lhookretroflex: 0x026D,
  26476. lira: 0x20A4,
  26477. liwnarmenian: 0x056C,
  26478. lj: 0x01C9,
  26479. ljecyrillic: 0x0459,
  26480. ll: 0xF6C0,
  26481. lladeva: 0x0933,
  26482. llagujarati: 0x0AB3,
  26483. llinebelow: 0x1E3B,
  26484. llladeva: 0x0934,
  26485. llvocalicbengali: 0x09E1,
  26486. llvocalicdeva: 0x0961,
  26487. llvocalicvowelsignbengali: 0x09E3,
  26488. llvocalicvowelsigndeva: 0x0963,
  26489. lmiddletilde: 0x026B,
  26490. lmonospace: 0xFF4C,
  26491. lmsquare: 0x33D0,
  26492. lochulathai: 0x0E2C,
  26493. logicaland: 0x2227,
  26494. logicalnot: 0x00AC,
  26495. logicalnotreversed: 0x2310,
  26496. logicalor: 0x2228,
  26497. lolingthai: 0x0E25,
  26498. longs: 0x017F,
  26499. lowlinecenterline: 0xFE4E,
  26500. lowlinecmb: 0x0332,
  26501. lowlinedashed: 0xFE4D,
  26502. lozenge: 0x25CA,
  26503. lparen: 0x24A7,
  26504. lslash: 0x0142,
  26505. lsquare: 0x2113,
  26506. lsuperior: 0xF6EE,
  26507. ltshade: 0x2591,
  26508. luthai: 0x0E26,
  26509. lvocalicbengali: 0x098C,
  26510. lvocalicdeva: 0x090C,
  26511. lvocalicvowelsignbengali: 0x09E2,
  26512. lvocalicvowelsigndeva: 0x0962,
  26513. lxsquare: 0x33D3,
  26514. m: 0x006D,
  26515. mabengali: 0x09AE,
  26516. macron: 0x00AF,
  26517. macronbelowcmb: 0x0331,
  26518. macroncmb: 0x0304,
  26519. macronlowmod: 0x02CD,
  26520. macronmonospace: 0xFFE3,
  26521. macute: 0x1E3F,
  26522. madeva: 0x092E,
  26523. magujarati: 0x0AAE,
  26524. magurmukhi: 0x0A2E,
  26525. mahapakhhebrew: 0x05A4,
  26526. mahapakhlefthebrew: 0x05A4,
  26527. mahiragana: 0x307E,
  26528. maichattawalowleftthai: 0xF895,
  26529. maichattawalowrightthai: 0xF894,
  26530. maichattawathai: 0x0E4B,
  26531. maichattawaupperleftthai: 0xF893,
  26532. maieklowleftthai: 0xF88C,
  26533. maieklowrightthai: 0xF88B,
  26534. maiekthai: 0x0E48,
  26535. maiekupperleftthai: 0xF88A,
  26536. maihanakatleftthai: 0xF884,
  26537. maihanakatthai: 0x0E31,
  26538. maitaikhuleftthai: 0xF889,
  26539. maitaikhuthai: 0x0E47,
  26540. maitholowleftthai: 0xF88F,
  26541. maitholowrightthai: 0xF88E,
  26542. maithothai: 0x0E49,
  26543. maithoupperleftthai: 0xF88D,
  26544. maitrilowleftthai: 0xF892,
  26545. maitrilowrightthai: 0xF891,
  26546. maitrithai: 0x0E4A,
  26547. maitriupperleftthai: 0xF890,
  26548. maiyamokthai: 0x0E46,
  26549. makatakana: 0x30DE,
  26550. makatakanahalfwidth: 0xFF8F,
  26551. male: 0x2642,
  26552. mansyonsquare: 0x3347,
  26553. maqafhebrew: 0x05BE,
  26554. mars: 0x2642,
  26555. masoracirclehebrew: 0x05AF,
  26556. masquare: 0x3383,
  26557. mbopomofo: 0x3107,
  26558. mbsquare: 0x33D4,
  26559. mcircle: 0x24DC,
  26560. mcubedsquare: 0x33A5,
  26561. mdotaccent: 0x1E41,
  26562. mdotbelow: 0x1E43,
  26563. meemarabic: 0x0645,
  26564. meemfinalarabic: 0xFEE2,
  26565. meeminitialarabic: 0xFEE3,
  26566. meemmedialarabic: 0xFEE4,
  26567. meemmeeminitialarabic: 0xFCD1,
  26568. meemmeemisolatedarabic: 0xFC48,
  26569. meetorusquare: 0x334D,
  26570. mehiragana: 0x3081,
  26571. meizierasquare: 0x337E,
  26572. mekatakana: 0x30E1,
  26573. mekatakanahalfwidth: 0xFF92,
  26574. mem: 0x05DE,
  26575. memdagesh: 0xFB3E,
  26576. memdageshhebrew: 0xFB3E,
  26577. memhebrew: 0x05DE,
  26578. menarmenian: 0x0574,
  26579. merkhahebrew: 0x05A5,
  26580. merkhakefulahebrew: 0x05A6,
  26581. merkhakefulalefthebrew: 0x05A6,
  26582. merkhalefthebrew: 0x05A5,
  26583. mhook: 0x0271,
  26584. mhzsquare: 0x3392,
  26585. middledotkatakanahalfwidth: 0xFF65,
  26586. middot: 0x00B7,
  26587. mieumacirclekorean: 0x3272,
  26588. mieumaparenkorean: 0x3212,
  26589. mieumcirclekorean: 0x3264,
  26590. mieumkorean: 0x3141,
  26591. mieumpansioskorean: 0x3170,
  26592. mieumparenkorean: 0x3204,
  26593. mieumpieupkorean: 0x316E,
  26594. mieumsioskorean: 0x316F,
  26595. mihiragana: 0x307F,
  26596. mikatakana: 0x30DF,
  26597. mikatakanahalfwidth: 0xFF90,
  26598. minus: 0x2212,
  26599. minusbelowcmb: 0x0320,
  26600. minuscircle: 0x2296,
  26601. minusmod: 0x02D7,
  26602. minusplus: 0x2213,
  26603. minute: 0x2032,
  26604. miribaarusquare: 0x334A,
  26605. mirisquare: 0x3349,
  26606. mlonglegturned: 0x0270,
  26607. mlsquare: 0x3396,
  26608. mmcubedsquare: 0x33A3,
  26609. mmonospace: 0xFF4D,
  26610. mmsquaredsquare: 0x339F,
  26611. mohiragana: 0x3082,
  26612. mohmsquare: 0x33C1,
  26613. mokatakana: 0x30E2,
  26614. mokatakanahalfwidth: 0xFF93,
  26615. molsquare: 0x33D6,
  26616. momathai: 0x0E21,
  26617. moverssquare: 0x33A7,
  26618. moverssquaredsquare: 0x33A8,
  26619. mparen: 0x24A8,
  26620. mpasquare: 0x33AB,
  26621. mssquare: 0x33B3,
  26622. msuperior: 0xF6EF,
  26623. mturned: 0x026F,
  26624. mu: 0x00B5,
  26625. mu1: 0x00B5,
  26626. muasquare: 0x3382,
  26627. muchgreater: 0x226B,
  26628. muchless: 0x226A,
  26629. mufsquare: 0x338C,
  26630. mugreek: 0x03BC,
  26631. mugsquare: 0x338D,
  26632. muhiragana: 0x3080,
  26633. mukatakana: 0x30E0,
  26634. mukatakanahalfwidth: 0xFF91,
  26635. mulsquare: 0x3395,
  26636. multiply: 0x00D7,
  26637. mumsquare: 0x339B,
  26638. munahhebrew: 0x05A3,
  26639. munahlefthebrew: 0x05A3,
  26640. musicalnote: 0x266A,
  26641. musicalnotedbl: 0x266B,
  26642. musicflatsign: 0x266D,
  26643. musicsharpsign: 0x266F,
  26644. mussquare: 0x33B2,
  26645. muvsquare: 0x33B6,
  26646. muwsquare: 0x33BC,
  26647. mvmegasquare: 0x33B9,
  26648. mvsquare: 0x33B7,
  26649. mwmegasquare: 0x33BF,
  26650. mwsquare: 0x33BD,
  26651. n: 0x006E,
  26652. nabengali: 0x09A8,
  26653. nabla: 0x2207,
  26654. nacute: 0x0144,
  26655. nadeva: 0x0928,
  26656. nagujarati: 0x0AA8,
  26657. nagurmukhi: 0x0A28,
  26658. nahiragana: 0x306A,
  26659. nakatakana: 0x30CA,
  26660. nakatakanahalfwidth: 0xFF85,
  26661. napostrophe: 0x0149,
  26662. nasquare: 0x3381,
  26663. nbopomofo: 0x310B,
  26664. nbspace: 0x00A0,
  26665. ncaron: 0x0148,
  26666. ncedilla: 0x0146,
  26667. ncircle: 0x24DD,
  26668. ncircumflexbelow: 0x1E4B,
  26669. ncommaaccent: 0x0146,
  26670. ndotaccent: 0x1E45,
  26671. ndotbelow: 0x1E47,
  26672. nehiragana: 0x306D,
  26673. nekatakana: 0x30CD,
  26674. nekatakanahalfwidth: 0xFF88,
  26675. newsheqelsign: 0x20AA,
  26676. nfsquare: 0x338B,
  26677. ngabengali: 0x0999,
  26678. ngadeva: 0x0919,
  26679. ngagujarati: 0x0A99,
  26680. ngagurmukhi: 0x0A19,
  26681. ngonguthai: 0x0E07,
  26682. nhiragana: 0x3093,
  26683. nhookleft: 0x0272,
  26684. nhookretroflex: 0x0273,
  26685. nieunacirclekorean: 0x326F,
  26686. nieunaparenkorean: 0x320F,
  26687. nieuncieuckorean: 0x3135,
  26688. nieuncirclekorean: 0x3261,
  26689. nieunhieuhkorean: 0x3136,
  26690. nieunkorean: 0x3134,
  26691. nieunpansioskorean: 0x3168,
  26692. nieunparenkorean: 0x3201,
  26693. nieunsioskorean: 0x3167,
  26694. nieuntikeutkorean: 0x3166,
  26695. nihiragana: 0x306B,
  26696. nikatakana: 0x30CB,
  26697. nikatakanahalfwidth: 0xFF86,
  26698. nikhahitleftthai: 0xF899,
  26699. nikhahitthai: 0x0E4D,
  26700. nine: 0x0039,
  26701. ninearabic: 0x0669,
  26702. ninebengali: 0x09EF,
  26703. ninecircle: 0x2468,
  26704. ninecircleinversesansserif: 0x2792,
  26705. ninedeva: 0x096F,
  26706. ninegujarati: 0x0AEF,
  26707. ninegurmukhi: 0x0A6F,
  26708. ninehackarabic: 0x0669,
  26709. ninehangzhou: 0x3029,
  26710. nineideographicparen: 0x3228,
  26711. nineinferior: 0x2089,
  26712. ninemonospace: 0xFF19,
  26713. nineoldstyle: 0xF739,
  26714. nineparen: 0x247C,
  26715. nineperiod: 0x2490,
  26716. ninepersian: 0x06F9,
  26717. nineroman: 0x2178,
  26718. ninesuperior: 0x2079,
  26719. nineteencircle: 0x2472,
  26720. nineteenparen: 0x2486,
  26721. nineteenperiod: 0x249A,
  26722. ninethai: 0x0E59,
  26723. nj: 0x01CC,
  26724. njecyrillic: 0x045A,
  26725. nkatakana: 0x30F3,
  26726. nkatakanahalfwidth: 0xFF9D,
  26727. nlegrightlong: 0x019E,
  26728. nlinebelow: 0x1E49,
  26729. nmonospace: 0xFF4E,
  26730. nmsquare: 0x339A,
  26731. nnabengali: 0x09A3,
  26732. nnadeva: 0x0923,
  26733. nnagujarati: 0x0AA3,
  26734. nnagurmukhi: 0x0A23,
  26735. nnnadeva: 0x0929,
  26736. nohiragana: 0x306E,
  26737. nokatakana: 0x30CE,
  26738. nokatakanahalfwidth: 0xFF89,
  26739. nonbreakingspace: 0x00A0,
  26740. nonenthai: 0x0E13,
  26741. nonuthai: 0x0E19,
  26742. noonarabic: 0x0646,
  26743. noonfinalarabic: 0xFEE6,
  26744. noonghunnaarabic: 0x06BA,
  26745. noonghunnafinalarabic: 0xFB9F,
  26746. nooninitialarabic: 0xFEE7,
  26747. noonjeeminitialarabic: 0xFCD2,
  26748. noonjeemisolatedarabic: 0xFC4B,
  26749. noonmedialarabic: 0xFEE8,
  26750. noonmeeminitialarabic: 0xFCD5,
  26751. noonmeemisolatedarabic: 0xFC4E,
  26752. noonnoonfinalarabic: 0xFC8D,
  26753. notcontains: 0x220C,
  26754. notelement: 0x2209,
  26755. notelementof: 0x2209,
  26756. notequal: 0x2260,
  26757. notgreater: 0x226F,
  26758. notgreaternorequal: 0x2271,
  26759. notgreaternorless: 0x2279,
  26760. notidentical: 0x2262,
  26761. notless: 0x226E,
  26762. notlessnorequal: 0x2270,
  26763. notparallel: 0x2226,
  26764. notprecedes: 0x2280,
  26765. notsubset: 0x2284,
  26766. notsucceeds: 0x2281,
  26767. notsuperset: 0x2285,
  26768. nowarmenian: 0x0576,
  26769. nparen: 0x24A9,
  26770. nssquare: 0x33B1,
  26771. nsuperior: 0x207F,
  26772. ntilde: 0x00F1,
  26773. nu: 0x03BD,
  26774. nuhiragana: 0x306C,
  26775. nukatakana: 0x30CC,
  26776. nukatakanahalfwidth: 0xFF87,
  26777. nuktabengali: 0x09BC,
  26778. nuktadeva: 0x093C,
  26779. nuktagujarati: 0x0ABC,
  26780. nuktagurmukhi: 0x0A3C,
  26781. numbersign: 0x0023,
  26782. numbersignmonospace: 0xFF03,
  26783. numbersignsmall: 0xFE5F,
  26784. numeralsigngreek: 0x0374,
  26785. numeralsignlowergreek: 0x0375,
  26786. numero: 0x2116,
  26787. nun: 0x05E0,
  26788. nundagesh: 0xFB40,
  26789. nundageshhebrew: 0xFB40,
  26790. nunhebrew: 0x05E0,
  26791. nvsquare: 0x33B5,
  26792. nwsquare: 0x33BB,
  26793. nyabengali: 0x099E,
  26794. nyadeva: 0x091E,
  26795. nyagujarati: 0x0A9E,
  26796. nyagurmukhi: 0x0A1E,
  26797. o: 0x006F,
  26798. oacute: 0x00F3,
  26799. oangthai: 0x0E2D,
  26800. obarred: 0x0275,
  26801. obarredcyrillic: 0x04E9,
  26802. obarreddieresiscyrillic: 0x04EB,
  26803. obengali: 0x0993,
  26804. obopomofo: 0x311B,
  26805. obreve: 0x014F,
  26806. ocandradeva: 0x0911,
  26807. ocandragujarati: 0x0A91,
  26808. ocandravowelsigndeva: 0x0949,
  26809. ocandravowelsigngujarati: 0x0AC9,
  26810. ocaron: 0x01D2,
  26811. ocircle: 0x24DE,
  26812. ocircumflex: 0x00F4,
  26813. ocircumflexacute: 0x1ED1,
  26814. ocircumflexdotbelow: 0x1ED9,
  26815. ocircumflexgrave: 0x1ED3,
  26816. ocircumflexhookabove: 0x1ED5,
  26817. ocircumflextilde: 0x1ED7,
  26818. ocyrillic: 0x043E,
  26819. odblacute: 0x0151,
  26820. odblgrave: 0x020D,
  26821. odeva: 0x0913,
  26822. odieresis: 0x00F6,
  26823. odieresiscyrillic: 0x04E7,
  26824. odotbelow: 0x1ECD,
  26825. oe: 0x0153,
  26826. oekorean: 0x315A,
  26827. ogonek: 0x02DB,
  26828. ogonekcmb: 0x0328,
  26829. ograve: 0x00F2,
  26830. ogujarati: 0x0A93,
  26831. oharmenian: 0x0585,
  26832. ohiragana: 0x304A,
  26833. ohookabove: 0x1ECF,
  26834. ohorn: 0x01A1,
  26835. ohornacute: 0x1EDB,
  26836. ohorndotbelow: 0x1EE3,
  26837. ohorngrave: 0x1EDD,
  26838. ohornhookabove: 0x1EDF,
  26839. ohorntilde: 0x1EE1,
  26840. ohungarumlaut: 0x0151,
  26841. oi: 0x01A3,
  26842. oinvertedbreve: 0x020F,
  26843. okatakana: 0x30AA,
  26844. okatakanahalfwidth: 0xFF75,
  26845. okorean: 0x3157,
  26846. olehebrew: 0x05AB,
  26847. omacron: 0x014D,
  26848. omacronacute: 0x1E53,
  26849. omacrongrave: 0x1E51,
  26850. omdeva: 0x0950,
  26851. omega: 0x03C9,
  26852. omega1: 0x03D6,
  26853. omegacyrillic: 0x0461,
  26854. omegalatinclosed: 0x0277,
  26855. omegaroundcyrillic: 0x047B,
  26856. omegatitlocyrillic: 0x047D,
  26857. omegatonos: 0x03CE,
  26858. omgujarati: 0x0AD0,
  26859. omicron: 0x03BF,
  26860. omicrontonos: 0x03CC,
  26861. omonospace: 0xFF4F,
  26862. one: 0x0031,
  26863. onearabic: 0x0661,
  26864. onebengali: 0x09E7,
  26865. onecircle: 0x2460,
  26866. onecircleinversesansserif: 0x278A,
  26867. onedeva: 0x0967,
  26868. onedotenleader: 0x2024,
  26869. oneeighth: 0x215B,
  26870. onefitted: 0xF6DC,
  26871. onegujarati: 0x0AE7,
  26872. onegurmukhi: 0x0A67,
  26873. onehackarabic: 0x0661,
  26874. onehalf: 0x00BD,
  26875. onehangzhou: 0x3021,
  26876. oneideographicparen: 0x3220,
  26877. oneinferior: 0x2081,
  26878. onemonospace: 0xFF11,
  26879. onenumeratorbengali: 0x09F4,
  26880. oneoldstyle: 0xF731,
  26881. oneparen: 0x2474,
  26882. oneperiod: 0x2488,
  26883. onepersian: 0x06F1,
  26884. onequarter: 0x00BC,
  26885. oneroman: 0x2170,
  26886. onesuperior: 0x00B9,
  26887. onethai: 0x0E51,
  26888. onethird: 0x2153,
  26889. oogonek: 0x01EB,
  26890. oogonekmacron: 0x01ED,
  26891. oogurmukhi: 0x0A13,
  26892. oomatragurmukhi: 0x0A4B,
  26893. oopen: 0x0254,
  26894. oparen: 0x24AA,
  26895. openbullet: 0x25E6,
  26896. option: 0x2325,
  26897. ordfeminine: 0x00AA,
  26898. ordmasculine: 0x00BA,
  26899. orthogonal: 0x221F,
  26900. oshortdeva: 0x0912,
  26901. oshortvowelsigndeva: 0x094A,
  26902. oslash: 0x00F8,
  26903. oslashacute: 0x01FF,
  26904. osmallhiragana: 0x3049,
  26905. osmallkatakana: 0x30A9,
  26906. osmallkatakanahalfwidth: 0xFF6B,
  26907. ostrokeacute: 0x01FF,
  26908. osuperior: 0xF6F0,
  26909. otcyrillic: 0x047F,
  26910. otilde: 0x00F5,
  26911. otildeacute: 0x1E4D,
  26912. otildedieresis: 0x1E4F,
  26913. oubopomofo: 0x3121,
  26914. overline: 0x203E,
  26915. overlinecenterline: 0xFE4A,
  26916. overlinecmb: 0x0305,
  26917. overlinedashed: 0xFE49,
  26918. overlinedblwavy: 0xFE4C,
  26919. overlinewavy: 0xFE4B,
  26920. overscore: 0x00AF,
  26921. ovowelsignbengali: 0x09CB,
  26922. ovowelsigndeva: 0x094B,
  26923. ovowelsigngujarati: 0x0ACB,
  26924. p: 0x0070,
  26925. paampssquare: 0x3380,
  26926. paasentosquare: 0x332B,
  26927. pabengali: 0x09AA,
  26928. pacute: 0x1E55,
  26929. padeva: 0x092A,
  26930. pagedown: 0x21DF,
  26931. pageup: 0x21DE,
  26932. pagujarati: 0x0AAA,
  26933. pagurmukhi: 0x0A2A,
  26934. pahiragana: 0x3071,
  26935. paiyannoithai: 0x0E2F,
  26936. pakatakana: 0x30D1,
  26937. palatalizationcyrilliccmb: 0x0484,
  26938. palochkacyrillic: 0x04C0,
  26939. pansioskorean: 0x317F,
  26940. paragraph: 0x00B6,
  26941. parallel: 0x2225,
  26942. parenleft: 0x0028,
  26943. parenleftaltonearabic: 0xFD3E,
  26944. parenleftbt: 0xF8ED,
  26945. parenleftex: 0xF8EC,
  26946. parenleftinferior: 0x208D,
  26947. parenleftmonospace: 0xFF08,
  26948. parenleftsmall: 0xFE59,
  26949. parenleftsuperior: 0x207D,
  26950. parenlefttp: 0xF8EB,
  26951. parenleftvertical: 0xFE35,
  26952. parenright: 0x0029,
  26953. parenrightaltonearabic: 0xFD3F,
  26954. parenrightbt: 0xF8F8,
  26955. parenrightex: 0xF8F7,
  26956. parenrightinferior: 0x208E,
  26957. parenrightmonospace: 0xFF09,
  26958. parenrightsmall: 0xFE5A,
  26959. parenrightsuperior: 0x207E,
  26960. parenrighttp: 0xF8F6,
  26961. parenrightvertical: 0xFE36,
  26962. partialdiff: 0x2202,
  26963. paseqhebrew: 0x05C0,
  26964. pashtahebrew: 0x0599,
  26965. pasquare: 0x33A9,
  26966. patah: 0x05B7,
  26967. patah11: 0x05B7,
  26968. patah1d: 0x05B7,
  26969. patah2a: 0x05B7,
  26970. patahhebrew: 0x05B7,
  26971. patahnarrowhebrew: 0x05B7,
  26972. patahquarterhebrew: 0x05B7,
  26973. patahwidehebrew: 0x05B7,
  26974. pazerhebrew: 0x05A1,
  26975. pbopomofo: 0x3106,
  26976. pcircle: 0x24DF,
  26977. pdotaccent: 0x1E57,
  26978. pe: 0x05E4,
  26979. pecyrillic: 0x043F,
  26980. pedagesh: 0xFB44,
  26981. pedageshhebrew: 0xFB44,
  26982. peezisquare: 0x333B,
  26983. pefinaldageshhebrew: 0xFB43,
  26984. peharabic: 0x067E,
  26985. peharmenian: 0x057A,
  26986. pehebrew: 0x05E4,
  26987. pehfinalarabic: 0xFB57,
  26988. pehinitialarabic: 0xFB58,
  26989. pehiragana: 0x307A,
  26990. pehmedialarabic: 0xFB59,
  26991. pekatakana: 0x30DA,
  26992. pemiddlehookcyrillic: 0x04A7,
  26993. perafehebrew: 0xFB4E,
  26994. percent: 0x0025,
  26995. percentarabic: 0x066A,
  26996. percentmonospace: 0xFF05,
  26997. percentsmall: 0xFE6A,
  26998. period: 0x002E,
  26999. periodarmenian: 0x0589,
  27000. periodcentered: 0x00B7,
  27001. periodhalfwidth: 0xFF61,
  27002. periodinferior: 0xF6E7,
  27003. periodmonospace: 0xFF0E,
  27004. periodsmall: 0xFE52,
  27005. periodsuperior: 0xF6E8,
  27006. perispomenigreekcmb: 0x0342,
  27007. perpendicular: 0x22A5,
  27008. perthousand: 0x2030,
  27009. peseta: 0x20A7,
  27010. pfsquare: 0x338A,
  27011. phabengali: 0x09AB,
  27012. phadeva: 0x092B,
  27013. phagujarati: 0x0AAB,
  27014. phagurmukhi: 0x0A2B,
  27015. phi: 0x03C6,
  27016. phi1: 0x03D5,
  27017. phieuphacirclekorean: 0x327A,
  27018. phieuphaparenkorean: 0x321A,
  27019. phieuphcirclekorean: 0x326C,
  27020. phieuphkorean: 0x314D,
  27021. phieuphparenkorean: 0x320C,
  27022. philatin: 0x0278,
  27023. phinthuthai: 0x0E3A,
  27024. phisymbolgreek: 0x03D5,
  27025. phook: 0x01A5,
  27026. phophanthai: 0x0E1E,
  27027. phophungthai: 0x0E1C,
  27028. phosamphaothai: 0x0E20,
  27029. pi: 0x03C0,
  27030. pieupacirclekorean: 0x3273,
  27031. pieupaparenkorean: 0x3213,
  27032. pieupcieuckorean: 0x3176,
  27033. pieupcirclekorean: 0x3265,
  27034. pieupkiyeokkorean: 0x3172,
  27035. pieupkorean: 0x3142,
  27036. pieupparenkorean: 0x3205,
  27037. pieupsioskiyeokkorean: 0x3174,
  27038. pieupsioskorean: 0x3144,
  27039. pieupsiostikeutkorean: 0x3175,
  27040. pieupthieuthkorean: 0x3177,
  27041. pieuptikeutkorean: 0x3173,
  27042. pihiragana: 0x3074,
  27043. pikatakana: 0x30D4,
  27044. pisymbolgreek: 0x03D6,
  27045. piwrarmenian: 0x0583,
  27046. plus: 0x002B,
  27047. plusbelowcmb: 0x031F,
  27048. pluscircle: 0x2295,
  27049. plusminus: 0x00B1,
  27050. plusmod: 0x02D6,
  27051. plusmonospace: 0xFF0B,
  27052. plussmall: 0xFE62,
  27053. plussuperior: 0x207A,
  27054. pmonospace: 0xFF50,
  27055. pmsquare: 0x33D8,
  27056. pohiragana: 0x307D,
  27057. pointingindexdownwhite: 0x261F,
  27058. pointingindexleftwhite: 0x261C,
  27059. pointingindexrightwhite: 0x261E,
  27060. pointingindexupwhite: 0x261D,
  27061. pokatakana: 0x30DD,
  27062. poplathai: 0x0E1B,
  27063. postalmark: 0x3012,
  27064. postalmarkface: 0x3020,
  27065. pparen: 0x24AB,
  27066. precedes: 0x227A,
  27067. prescription: 0x211E,
  27068. primemod: 0x02B9,
  27069. primereversed: 0x2035,
  27070. product: 0x220F,
  27071. projective: 0x2305,
  27072. prolongedkana: 0x30FC,
  27073. propellor: 0x2318,
  27074. propersubset: 0x2282,
  27075. propersuperset: 0x2283,
  27076. proportion: 0x2237,
  27077. proportional: 0x221D,
  27078. psi: 0x03C8,
  27079. psicyrillic: 0x0471,
  27080. psilipneumatacyrilliccmb: 0x0486,
  27081. pssquare: 0x33B0,
  27082. puhiragana: 0x3077,
  27083. pukatakana: 0x30D7,
  27084. pvsquare: 0x33B4,
  27085. pwsquare: 0x33BA,
  27086. q: 0x0071,
  27087. qadeva: 0x0958,
  27088. qadmahebrew: 0x05A8,
  27089. qafarabic: 0x0642,
  27090. qaffinalarabic: 0xFED6,
  27091. qafinitialarabic: 0xFED7,
  27092. qafmedialarabic: 0xFED8,
  27093. qamats: 0x05B8,
  27094. qamats10: 0x05B8,
  27095. qamats1a: 0x05B8,
  27096. qamats1c: 0x05B8,
  27097. qamats27: 0x05B8,
  27098. qamats29: 0x05B8,
  27099. qamats33: 0x05B8,
  27100. qamatsde: 0x05B8,
  27101. qamatshebrew: 0x05B8,
  27102. qamatsnarrowhebrew: 0x05B8,
  27103. qamatsqatanhebrew: 0x05B8,
  27104. qamatsqatannarrowhebrew: 0x05B8,
  27105. qamatsqatanquarterhebrew: 0x05B8,
  27106. qamatsqatanwidehebrew: 0x05B8,
  27107. qamatsquarterhebrew: 0x05B8,
  27108. qamatswidehebrew: 0x05B8,
  27109. qarneyparahebrew: 0x059F,
  27110. qbopomofo: 0x3111,
  27111. qcircle: 0x24E0,
  27112. qhook: 0x02A0,
  27113. qmonospace: 0xFF51,
  27114. qof: 0x05E7,
  27115. qofdagesh: 0xFB47,
  27116. qofdageshhebrew: 0xFB47,
  27117. qofhebrew: 0x05E7,
  27118. qparen: 0x24AC,
  27119. quarternote: 0x2669,
  27120. qubuts: 0x05BB,
  27121. qubuts18: 0x05BB,
  27122. qubuts25: 0x05BB,
  27123. qubuts31: 0x05BB,
  27124. qubutshebrew: 0x05BB,
  27125. qubutsnarrowhebrew: 0x05BB,
  27126. qubutsquarterhebrew: 0x05BB,
  27127. qubutswidehebrew: 0x05BB,
  27128. question: 0x003F,
  27129. questionarabic: 0x061F,
  27130. questionarmenian: 0x055E,
  27131. questiondown: 0x00BF,
  27132. questiondownsmall: 0xF7BF,
  27133. questiongreek: 0x037E,
  27134. questionmonospace: 0xFF1F,
  27135. questionsmall: 0xF73F,
  27136. quotedbl: 0x0022,
  27137. quotedblbase: 0x201E,
  27138. quotedblleft: 0x201C,
  27139. quotedblmonospace: 0xFF02,
  27140. quotedblprime: 0x301E,
  27141. quotedblprimereversed: 0x301D,
  27142. quotedblright: 0x201D,
  27143. quoteleft: 0x2018,
  27144. quoteleftreversed: 0x201B,
  27145. quotereversed: 0x201B,
  27146. quoteright: 0x2019,
  27147. quoterightn: 0x0149,
  27148. quotesinglbase: 0x201A,
  27149. quotesingle: 0x0027,
  27150. quotesinglemonospace: 0xFF07,
  27151. r: 0x0072,
  27152. raarmenian: 0x057C,
  27153. rabengali: 0x09B0,
  27154. racute: 0x0155,
  27155. radeva: 0x0930,
  27156. radical: 0x221A,
  27157. radicalex: 0xF8E5,
  27158. radoverssquare: 0x33AE,
  27159. radoverssquaredsquare: 0x33AF,
  27160. radsquare: 0x33AD,
  27161. rafe: 0x05BF,
  27162. rafehebrew: 0x05BF,
  27163. ragujarati: 0x0AB0,
  27164. ragurmukhi: 0x0A30,
  27165. rahiragana: 0x3089,
  27166. rakatakana: 0x30E9,
  27167. rakatakanahalfwidth: 0xFF97,
  27168. ralowerdiagonalbengali: 0x09F1,
  27169. ramiddlediagonalbengali: 0x09F0,
  27170. ramshorn: 0x0264,
  27171. ratio: 0x2236,
  27172. rbopomofo: 0x3116,
  27173. rcaron: 0x0159,
  27174. rcedilla: 0x0157,
  27175. rcircle: 0x24E1,
  27176. rcommaaccent: 0x0157,
  27177. rdblgrave: 0x0211,
  27178. rdotaccent: 0x1E59,
  27179. rdotbelow: 0x1E5B,
  27180. rdotbelowmacron: 0x1E5D,
  27181. referencemark: 0x203B,
  27182. reflexsubset: 0x2286,
  27183. reflexsuperset: 0x2287,
  27184. registered: 0x00AE,
  27185. registersans: 0xF8E8,
  27186. registerserif: 0xF6DA,
  27187. reharabic: 0x0631,
  27188. reharmenian: 0x0580,
  27189. rehfinalarabic: 0xFEAE,
  27190. rehiragana: 0x308C,
  27191. rekatakana: 0x30EC,
  27192. rekatakanahalfwidth: 0xFF9A,
  27193. resh: 0x05E8,
  27194. reshdageshhebrew: 0xFB48,
  27195. reshhebrew: 0x05E8,
  27196. reversedtilde: 0x223D,
  27197. reviahebrew: 0x0597,
  27198. reviamugrashhebrew: 0x0597,
  27199. revlogicalnot: 0x2310,
  27200. rfishhook: 0x027E,
  27201. rfishhookreversed: 0x027F,
  27202. rhabengali: 0x09DD,
  27203. rhadeva: 0x095D,
  27204. rho: 0x03C1,
  27205. rhook: 0x027D,
  27206. rhookturned: 0x027B,
  27207. rhookturnedsuperior: 0x02B5,
  27208. rhosymbolgreek: 0x03F1,
  27209. rhotichookmod: 0x02DE,
  27210. rieulacirclekorean: 0x3271,
  27211. rieulaparenkorean: 0x3211,
  27212. rieulcirclekorean: 0x3263,
  27213. rieulhieuhkorean: 0x3140,
  27214. rieulkiyeokkorean: 0x313A,
  27215. rieulkiyeoksioskorean: 0x3169,
  27216. rieulkorean: 0x3139,
  27217. rieulmieumkorean: 0x313B,
  27218. rieulpansioskorean: 0x316C,
  27219. rieulparenkorean: 0x3203,
  27220. rieulphieuphkorean: 0x313F,
  27221. rieulpieupkorean: 0x313C,
  27222. rieulpieupsioskorean: 0x316B,
  27223. rieulsioskorean: 0x313D,
  27224. rieulthieuthkorean: 0x313E,
  27225. rieultikeutkorean: 0x316A,
  27226. rieulyeorinhieuhkorean: 0x316D,
  27227. rightangle: 0x221F,
  27228. righttackbelowcmb: 0x0319,
  27229. righttriangle: 0x22BF,
  27230. rihiragana: 0x308A,
  27231. rikatakana: 0x30EA,
  27232. rikatakanahalfwidth: 0xFF98,
  27233. ring: 0x02DA,
  27234. ringbelowcmb: 0x0325,
  27235. ringcmb: 0x030A,
  27236. ringhalfleft: 0x02BF,
  27237. ringhalfleftarmenian: 0x0559,
  27238. ringhalfleftbelowcmb: 0x031C,
  27239. ringhalfleftcentered: 0x02D3,
  27240. ringhalfright: 0x02BE,
  27241. ringhalfrightbelowcmb: 0x0339,
  27242. ringhalfrightcentered: 0x02D2,
  27243. rinvertedbreve: 0x0213,
  27244. rittorusquare: 0x3351,
  27245. rlinebelow: 0x1E5F,
  27246. rlongleg: 0x027C,
  27247. rlonglegturned: 0x027A,
  27248. rmonospace: 0xFF52,
  27249. rohiragana: 0x308D,
  27250. rokatakana: 0x30ED,
  27251. rokatakanahalfwidth: 0xFF9B,
  27252. roruathai: 0x0E23,
  27253. rparen: 0x24AD,
  27254. rrabengali: 0x09DC,
  27255. rradeva: 0x0931,
  27256. rragurmukhi: 0x0A5C,
  27257. rreharabic: 0x0691,
  27258. rrehfinalarabic: 0xFB8D,
  27259. rrvocalicbengali: 0x09E0,
  27260. rrvocalicdeva: 0x0960,
  27261. rrvocalicgujarati: 0x0AE0,
  27262. rrvocalicvowelsignbengali: 0x09C4,
  27263. rrvocalicvowelsigndeva: 0x0944,
  27264. rrvocalicvowelsigngujarati: 0x0AC4,
  27265. rsuperior: 0xF6F1,
  27266. rtblock: 0x2590,
  27267. rturned: 0x0279,
  27268. rturnedsuperior: 0x02B4,
  27269. ruhiragana: 0x308B,
  27270. rukatakana: 0x30EB,
  27271. rukatakanahalfwidth: 0xFF99,
  27272. rupeemarkbengali: 0x09F2,
  27273. rupeesignbengali: 0x09F3,
  27274. rupiah: 0xF6DD,
  27275. ruthai: 0x0E24,
  27276. rvocalicbengali: 0x098B,
  27277. rvocalicdeva: 0x090B,
  27278. rvocalicgujarati: 0x0A8B,
  27279. rvocalicvowelsignbengali: 0x09C3,
  27280. rvocalicvowelsigndeva: 0x0943,
  27281. rvocalicvowelsigngujarati: 0x0AC3,
  27282. s: 0x0073,
  27283. sabengali: 0x09B8,
  27284. sacute: 0x015B,
  27285. sacutedotaccent: 0x1E65,
  27286. sadarabic: 0x0635,
  27287. sadeva: 0x0938,
  27288. sadfinalarabic: 0xFEBA,
  27289. sadinitialarabic: 0xFEBB,
  27290. sadmedialarabic: 0xFEBC,
  27291. sagujarati: 0x0AB8,
  27292. sagurmukhi: 0x0A38,
  27293. sahiragana: 0x3055,
  27294. sakatakana: 0x30B5,
  27295. sakatakanahalfwidth: 0xFF7B,
  27296. sallallahoualayhewasallamarabic: 0xFDFA,
  27297. samekh: 0x05E1,
  27298. samekhdagesh: 0xFB41,
  27299. samekhdageshhebrew: 0xFB41,
  27300. samekhhebrew: 0x05E1,
  27301. saraaathai: 0x0E32,
  27302. saraaethai: 0x0E41,
  27303. saraaimaimalaithai: 0x0E44,
  27304. saraaimaimuanthai: 0x0E43,
  27305. saraamthai: 0x0E33,
  27306. saraathai: 0x0E30,
  27307. saraethai: 0x0E40,
  27308. saraiileftthai: 0xF886,
  27309. saraiithai: 0x0E35,
  27310. saraileftthai: 0xF885,
  27311. saraithai: 0x0E34,
  27312. saraothai: 0x0E42,
  27313. saraueeleftthai: 0xF888,
  27314. saraueethai: 0x0E37,
  27315. saraueleftthai: 0xF887,
  27316. sarauethai: 0x0E36,
  27317. sarauthai: 0x0E38,
  27318. sarauuthai: 0x0E39,
  27319. sbopomofo: 0x3119,
  27320. scaron: 0x0161,
  27321. scarondotaccent: 0x1E67,
  27322. scedilla: 0x015F,
  27323. schwa: 0x0259,
  27324. schwacyrillic: 0x04D9,
  27325. schwadieresiscyrillic: 0x04DB,
  27326. schwahook: 0x025A,
  27327. scircle: 0x24E2,
  27328. scircumflex: 0x015D,
  27329. scommaaccent: 0x0219,
  27330. sdotaccent: 0x1E61,
  27331. sdotbelow: 0x1E63,
  27332. sdotbelowdotaccent: 0x1E69,
  27333. seagullbelowcmb: 0x033C,
  27334. second: 0x2033,
  27335. secondtonechinese: 0x02CA,
  27336. section: 0x00A7,
  27337. seenarabic: 0x0633,
  27338. seenfinalarabic: 0xFEB2,
  27339. seeninitialarabic: 0xFEB3,
  27340. seenmedialarabic: 0xFEB4,
  27341. segol: 0x05B6,
  27342. segol13: 0x05B6,
  27343. segol1f: 0x05B6,
  27344. segol2c: 0x05B6,
  27345. segolhebrew: 0x05B6,
  27346. segolnarrowhebrew: 0x05B6,
  27347. segolquarterhebrew: 0x05B6,
  27348. segoltahebrew: 0x0592,
  27349. segolwidehebrew: 0x05B6,
  27350. seharmenian: 0x057D,
  27351. sehiragana: 0x305B,
  27352. sekatakana: 0x30BB,
  27353. sekatakanahalfwidth: 0xFF7E,
  27354. semicolon: 0x003B,
  27355. semicolonarabic: 0x061B,
  27356. semicolonmonospace: 0xFF1B,
  27357. semicolonsmall: 0xFE54,
  27358. semivoicedmarkkana: 0x309C,
  27359. semivoicedmarkkanahalfwidth: 0xFF9F,
  27360. sentisquare: 0x3322,
  27361. sentosquare: 0x3323,
  27362. seven: 0x0037,
  27363. sevenarabic: 0x0667,
  27364. sevenbengali: 0x09ED,
  27365. sevencircle: 0x2466,
  27366. sevencircleinversesansserif: 0x2790,
  27367. sevendeva: 0x096D,
  27368. seveneighths: 0x215E,
  27369. sevengujarati: 0x0AED,
  27370. sevengurmukhi: 0x0A6D,
  27371. sevenhackarabic: 0x0667,
  27372. sevenhangzhou: 0x3027,
  27373. sevenideographicparen: 0x3226,
  27374. seveninferior: 0x2087,
  27375. sevenmonospace: 0xFF17,
  27376. sevenoldstyle: 0xF737,
  27377. sevenparen: 0x247A,
  27378. sevenperiod: 0x248E,
  27379. sevenpersian: 0x06F7,
  27380. sevenroman: 0x2176,
  27381. sevensuperior: 0x2077,
  27382. seventeencircle: 0x2470,
  27383. seventeenparen: 0x2484,
  27384. seventeenperiod: 0x2498,
  27385. seventhai: 0x0E57,
  27386. sfthyphen: 0x00AD,
  27387. shaarmenian: 0x0577,
  27388. shabengali: 0x09B6,
  27389. shacyrillic: 0x0448,
  27390. shaddaarabic: 0x0651,
  27391. shaddadammaarabic: 0xFC61,
  27392. shaddadammatanarabic: 0xFC5E,
  27393. shaddafathaarabic: 0xFC60,
  27394. shaddakasraarabic: 0xFC62,
  27395. shaddakasratanarabic: 0xFC5F,
  27396. shade: 0x2592,
  27397. shadedark: 0x2593,
  27398. shadelight: 0x2591,
  27399. shademedium: 0x2592,
  27400. shadeva: 0x0936,
  27401. shagujarati: 0x0AB6,
  27402. shagurmukhi: 0x0A36,
  27403. shalshelethebrew: 0x0593,
  27404. shbopomofo: 0x3115,
  27405. shchacyrillic: 0x0449,
  27406. sheenarabic: 0x0634,
  27407. sheenfinalarabic: 0xFEB6,
  27408. sheeninitialarabic: 0xFEB7,
  27409. sheenmedialarabic: 0xFEB8,
  27410. sheicoptic: 0x03E3,
  27411. sheqel: 0x20AA,
  27412. sheqelhebrew: 0x20AA,
  27413. sheva: 0x05B0,
  27414. sheva115: 0x05B0,
  27415. sheva15: 0x05B0,
  27416. sheva22: 0x05B0,
  27417. sheva2e: 0x05B0,
  27418. shevahebrew: 0x05B0,
  27419. shevanarrowhebrew: 0x05B0,
  27420. shevaquarterhebrew: 0x05B0,
  27421. shevawidehebrew: 0x05B0,
  27422. shhacyrillic: 0x04BB,
  27423. shimacoptic: 0x03ED,
  27424. shin: 0x05E9,
  27425. shindagesh: 0xFB49,
  27426. shindageshhebrew: 0xFB49,
  27427. shindageshshindot: 0xFB2C,
  27428. shindageshshindothebrew: 0xFB2C,
  27429. shindageshsindot: 0xFB2D,
  27430. shindageshsindothebrew: 0xFB2D,
  27431. shindothebrew: 0x05C1,
  27432. shinhebrew: 0x05E9,
  27433. shinshindot: 0xFB2A,
  27434. shinshindothebrew: 0xFB2A,
  27435. shinsindot: 0xFB2B,
  27436. shinsindothebrew: 0xFB2B,
  27437. shook: 0x0282,
  27438. sigma: 0x03C3,
  27439. sigma1: 0x03C2,
  27440. sigmafinal: 0x03C2,
  27441. sigmalunatesymbolgreek: 0x03F2,
  27442. sihiragana: 0x3057,
  27443. sikatakana: 0x30B7,
  27444. sikatakanahalfwidth: 0xFF7C,
  27445. siluqhebrew: 0x05BD,
  27446. siluqlefthebrew: 0x05BD,
  27447. similar: 0x223C,
  27448. sindothebrew: 0x05C2,
  27449. siosacirclekorean: 0x3274,
  27450. siosaparenkorean: 0x3214,
  27451. sioscieuckorean: 0x317E,
  27452. sioscirclekorean: 0x3266,
  27453. sioskiyeokkorean: 0x317A,
  27454. sioskorean: 0x3145,
  27455. siosnieunkorean: 0x317B,
  27456. siosparenkorean: 0x3206,
  27457. siospieupkorean: 0x317D,
  27458. siostikeutkorean: 0x317C,
  27459. six: 0x0036,
  27460. sixarabic: 0x0666,
  27461. sixbengali: 0x09EC,
  27462. sixcircle: 0x2465,
  27463. sixcircleinversesansserif: 0x278F,
  27464. sixdeva: 0x096C,
  27465. sixgujarati: 0x0AEC,
  27466. sixgurmukhi: 0x0A6C,
  27467. sixhackarabic: 0x0666,
  27468. sixhangzhou: 0x3026,
  27469. sixideographicparen: 0x3225,
  27470. sixinferior: 0x2086,
  27471. sixmonospace: 0xFF16,
  27472. sixoldstyle: 0xF736,
  27473. sixparen: 0x2479,
  27474. sixperiod: 0x248D,
  27475. sixpersian: 0x06F6,
  27476. sixroman: 0x2175,
  27477. sixsuperior: 0x2076,
  27478. sixteencircle: 0x246F,
  27479. sixteencurrencydenominatorbengali: 0x09F9,
  27480. sixteenparen: 0x2483,
  27481. sixteenperiod: 0x2497,
  27482. sixthai: 0x0E56,
  27483. slash: 0x002F,
  27484. slashmonospace: 0xFF0F,
  27485. slong: 0x017F,
  27486. slongdotaccent: 0x1E9B,
  27487. smileface: 0x263A,
  27488. smonospace: 0xFF53,
  27489. sofpasuqhebrew: 0x05C3,
  27490. softhyphen: 0x00AD,
  27491. softsigncyrillic: 0x044C,
  27492. sohiragana: 0x305D,
  27493. sokatakana: 0x30BD,
  27494. sokatakanahalfwidth: 0xFF7F,
  27495. soliduslongoverlaycmb: 0x0338,
  27496. solidusshortoverlaycmb: 0x0337,
  27497. sorusithai: 0x0E29,
  27498. sosalathai: 0x0E28,
  27499. sosothai: 0x0E0B,
  27500. sosuathai: 0x0E2A,
  27501. space: 0x0020,
  27502. spacehackarabic: 0x0020,
  27503. spade: 0x2660,
  27504. spadesuitblack: 0x2660,
  27505. spadesuitwhite: 0x2664,
  27506. sparen: 0x24AE,
  27507. squarebelowcmb: 0x033B,
  27508. squarecc: 0x33C4,
  27509. squarecm: 0x339D,
  27510. squarediagonalcrosshatchfill: 0x25A9,
  27511. squarehorizontalfill: 0x25A4,
  27512. squarekg: 0x338F,
  27513. squarekm: 0x339E,
  27514. squarekmcapital: 0x33CE,
  27515. squareln: 0x33D1,
  27516. squarelog: 0x33D2,
  27517. squaremg: 0x338E,
  27518. squaremil: 0x33D5,
  27519. squaremm: 0x339C,
  27520. squaremsquared: 0x33A1,
  27521. squareorthogonalcrosshatchfill: 0x25A6,
  27522. squareupperlefttolowerrightfill: 0x25A7,
  27523. squareupperrighttolowerleftfill: 0x25A8,
  27524. squareverticalfill: 0x25A5,
  27525. squarewhitewithsmallblack: 0x25A3,
  27526. srsquare: 0x33DB,
  27527. ssabengali: 0x09B7,
  27528. ssadeva: 0x0937,
  27529. ssagujarati: 0x0AB7,
  27530. ssangcieuckorean: 0x3149,
  27531. ssanghieuhkorean: 0x3185,
  27532. ssangieungkorean: 0x3180,
  27533. ssangkiyeokkorean: 0x3132,
  27534. ssangnieunkorean: 0x3165,
  27535. ssangpieupkorean: 0x3143,
  27536. ssangsioskorean: 0x3146,
  27537. ssangtikeutkorean: 0x3138,
  27538. ssuperior: 0xF6F2,
  27539. sterling: 0x00A3,
  27540. sterlingmonospace: 0xFFE1,
  27541. strokelongoverlaycmb: 0x0336,
  27542. strokeshortoverlaycmb: 0x0335,
  27543. subset: 0x2282,
  27544. subsetnotequal: 0x228A,
  27545. subsetorequal: 0x2286,
  27546. succeeds: 0x227B,
  27547. suchthat: 0x220B,
  27548. suhiragana: 0x3059,
  27549. sukatakana: 0x30B9,
  27550. sukatakanahalfwidth: 0xFF7D,
  27551. sukunarabic: 0x0652,
  27552. summation: 0x2211,
  27553. sun: 0x263C,
  27554. superset: 0x2283,
  27555. supersetnotequal: 0x228B,
  27556. supersetorequal: 0x2287,
  27557. svsquare: 0x33DC,
  27558. syouwaerasquare: 0x337C,
  27559. t: 0x0074,
  27560. tabengali: 0x09A4,
  27561. tackdown: 0x22A4,
  27562. tackleft: 0x22A3,
  27563. tadeva: 0x0924,
  27564. tagujarati: 0x0AA4,
  27565. tagurmukhi: 0x0A24,
  27566. taharabic: 0x0637,
  27567. tahfinalarabic: 0xFEC2,
  27568. tahinitialarabic: 0xFEC3,
  27569. tahiragana: 0x305F,
  27570. tahmedialarabic: 0xFEC4,
  27571. taisyouerasquare: 0x337D,
  27572. takatakana: 0x30BF,
  27573. takatakanahalfwidth: 0xFF80,
  27574. tatweelarabic: 0x0640,
  27575. tau: 0x03C4,
  27576. tav: 0x05EA,
  27577. tavdages: 0xFB4A,
  27578. tavdagesh: 0xFB4A,
  27579. tavdageshhebrew: 0xFB4A,
  27580. tavhebrew: 0x05EA,
  27581. tbar: 0x0167,
  27582. tbopomofo: 0x310A,
  27583. tcaron: 0x0165,
  27584. tccurl: 0x02A8,
  27585. tcedilla: 0x0163,
  27586. tcheharabic: 0x0686,
  27587. tchehfinalarabic: 0xFB7B,
  27588. tchehinitialarabic: 0xFB7C,
  27589. tchehmedialarabic: 0xFB7D,
  27590. tcircle: 0x24E3,
  27591. tcircumflexbelow: 0x1E71,
  27592. tcommaaccent: 0x0163,
  27593. tdieresis: 0x1E97,
  27594. tdotaccent: 0x1E6B,
  27595. tdotbelow: 0x1E6D,
  27596. tecyrillic: 0x0442,
  27597. tedescendercyrillic: 0x04AD,
  27598. teharabic: 0x062A,
  27599. tehfinalarabic: 0xFE96,
  27600. tehhahinitialarabic: 0xFCA2,
  27601. tehhahisolatedarabic: 0xFC0C,
  27602. tehinitialarabic: 0xFE97,
  27603. tehiragana: 0x3066,
  27604. tehjeeminitialarabic: 0xFCA1,
  27605. tehjeemisolatedarabic: 0xFC0B,
  27606. tehmarbutaarabic: 0x0629,
  27607. tehmarbutafinalarabic: 0xFE94,
  27608. tehmedialarabic: 0xFE98,
  27609. tehmeeminitialarabic: 0xFCA4,
  27610. tehmeemisolatedarabic: 0xFC0E,
  27611. tehnoonfinalarabic: 0xFC73,
  27612. tekatakana: 0x30C6,
  27613. tekatakanahalfwidth: 0xFF83,
  27614. telephone: 0x2121,
  27615. telephoneblack: 0x260E,
  27616. telishagedolahebrew: 0x05A0,
  27617. telishaqetanahebrew: 0x05A9,
  27618. tencircle: 0x2469,
  27619. tenideographicparen: 0x3229,
  27620. tenparen: 0x247D,
  27621. tenperiod: 0x2491,
  27622. tenroman: 0x2179,
  27623. tesh: 0x02A7,
  27624. tet: 0x05D8,
  27625. tetdagesh: 0xFB38,
  27626. tetdageshhebrew: 0xFB38,
  27627. tethebrew: 0x05D8,
  27628. tetsecyrillic: 0x04B5,
  27629. tevirhebrew: 0x059B,
  27630. tevirlefthebrew: 0x059B,
  27631. thabengali: 0x09A5,
  27632. thadeva: 0x0925,
  27633. thagujarati: 0x0AA5,
  27634. thagurmukhi: 0x0A25,
  27635. thalarabic: 0x0630,
  27636. thalfinalarabic: 0xFEAC,
  27637. thanthakhatlowleftthai: 0xF898,
  27638. thanthakhatlowrightthai: 0xF897,
  27639. thanthakhatthai: 0x0E4C,
  27640. thanthakhatupperleftthai: 0xF896,
  27641. theharabic: 0x062B,
  27642. thehfinalarabic: 0xFE9A,
  27643. thehinitialarabic: 0xFE9B,
  27644. thehmedialarabic: 0xFE9C,
  27645. thereexists: 0x2203,
  27646. therefore: 0x2234,
  27647. theta: 0x03B8,
  27648. theta1: 0x03D1,
  27649. thetasymbolgreek: 0x03D1,
  27650. thieuthacirclekorean: 0x3279,
  27651. thieuthaparenkorean: 0x3219,
  27652. thieuthcirclekorean: 0x326B,
  27653. thieuthkorean: 0x314C,
  27654. thieuthparenkorean: 0x320B,
  27655. thirteencircle: 0x246C,
  27656. thirteenparen: 0x2480,
  27657. thirteenperiod: 0x2494,
  27658. thonangmonthothai: 0x0E11,
  27659. thook: 0x01AD,
  27660. thophuthaothai: 0x0E12,
  27661. thorn: 0x00FE,
  27662. thothahanthai: 0x0E17,
  27663. thothanthai: 0x0E10,
  27664. thothongthai: 0x0E18,
  27665. thothungthai: 0x0E16,
  27666. thousandcyrillic: 0x0482,
  27667. thousandsseparatorarabic: 0x066C,
  27668. thousandsseparatorpersian: 0x066C,
  27669. three: 0x0033,
  27670. threearabic: 0x0663,
  27671. threebengali: 0x09E9,
  27672. threecircle: 0x2462,
  27673. threecircleinversesansserif: 0x278C,
  27674. threedeva: 0x0969,
  27675. threeeighths: 0x215C,
  27676. threegujarati: 0x0AE9,
  27677. threegurmukhi: 0x0A69,
  27678. threehackarabic: 0x0663,
  27679. threehangzhou: 0x3023,
  27680. threeideographicparen: 0x3222,
  27681. threeinferior: 0x2083,
  27682. threemonospace: 0xFF13,
  27683. threenumeratorbengali: 0x09F6,
  27684. threeoldstyle: 0xF733,
  27685. threeparen: 0x2476,
  27686. threeperiod: 0x248A,
  27687. threepersian: 0x06F3,
  27688. threequarters: 0x00BE,
  27689. threequartersemdash: 0xF6DE,
  27690. threeroman: 0x2172,
  27691. threesuperior: 0x00B3,
  27692. threethai: 0x0E53,
  27693. thzsquare: 0x3394,
  27694. tihiragana: 0x3061,
  27695. tikatakana: 0x30C1,
  27696. tikatakanahalfwidth: 0xFF81,
  27697. tikeutacirclekorean: 0x3270,
  27698. tikeutaparenkorean: 0x3210,
  27699. tikeutcirclekorean: 0x3262,
  27700. tikeutkorean: 0x3137,
  27701. tikeutparenkorean: 0x3202,
  27702. tilde: 0x02DC,
  27703. tildebelowcmb: 0x0330,
  27704. tildecmb: 0x0303,
  27705. tildecomb: 0x0303,
  27706. tildedoublecmb: 0x0360,
  27707. tildeoperator: 0x223C,
  27708. tildeoverlaycmb: 0x0334,
  27709. tildeverticalcmb: 0x033E,
  27710. timescircle: 0x2297,
  27711. tipehahebrew: 0x0596,
  27712. tipehalefthebrew: 0x0596,
  27713. tippigurmukhi: 0x0A70,
  27714. titlocyrilliccmb: 0x0483,
  27715. tiwnarmenian: 0x057F,
  27716. tlinebelow: 0x1E6F,
  27717. tmonospace: 0xFF54,
  27718. toarmenian: 0x0569,
  27719. tohiragana: 0x3068,
  27720. tokatakana: 0x30C8,
  27721. tokatakanahalfwidth: 0xFF84,
  27722. tonebarextrahighmod: 0x02E5,
  27723. tonebarextralowmod: 0x02E9,
  27724. tonebarhighmod: 0x02E6,
  27725. tonebarlowmod: 0x02E8,
  27726. tonebarmidmod: 0x02E7,
  27727. tonefive: 0x01BD,
  27728. tonesix: 0x0185,
  27729. tonetwo: 0x01A8,
  27730. tonos: 0x0384,
  27731. tonsquare: 0x3327,
  27732. topatakthai: 0x0E0F,
  27733. tortoiseshellbracketleft: 0x3014,
  27734. tortoiseshellbracketleftsmall: 0xFE5D,
  27735. tortoiseshellbracketleftvertical: 0xFE39,
  27736. tortoiseshellbracketright: 0x3015,
  27737. tortoiseshellbracketrightsmall: 0xFE5E,
  27738. tortoiseshellbracketrightvertical: 0xFE3A,
  27739. totaothai: 0x0E15,
  27740. tpalatalhook: 0x01AB,
  27741. tparen: 0x24AF,
  27742. trademark: 0x2122,
  27743. trademarksans: 0xF8EA,
  27744. trademarkserif: 0xF6DB,
  27745. tretroflexhook: 0x0288,
  27746. triagdn: 0x25BC,
  27747. triaglf: 0x25C4,
  27748. triagrt: 0x25BA,
  27749. triagup: 0x25B2,
  27750. ts: 0x02A6,
  27751. tsadi: 0x05E6,
  27752. tsadidagesh: 0xFB46,
  27753. tsadidageshhebrew: 0xFB46,
  27754. tsadihebrew: 0x05E6,
  27755. tsecyrillic: 0x0446,
  27756. tsere: 0x05B5,
  27757. tsere12: 0x05B5,
  27758. tsere1e: 0x05B5,
  27759. tsere2b: 0x05B5,
  27760. tserehebrew: 0x05B5,
  27761. tserenarrowhebrew: 0x05B5,
  27762. tserequarterhebrew: 0x05B5,
  27763. tserewidehebrew: 0x05B5,
  27764. tshecyrillic: 0x045B,
  27765. tsuperior: 0xF6F3,
  27766. ttabengali: 0x099F,
  27767. ttadeva: 0x091F,
  27768. ttagujarati: 0x0A9F,
  27769. ttagurmukhi: 0x0A1F,
  27770. tteharabic: 0x0679,
  27771. ttehfinalarabic: 0xFB67,
  27772. ttehinitialarabic: 0xFB68,
  27773. ttehmedialarabic: 0xFB69,
  27774. tthabengali: 0x09A0,
  27775. tthadeva: 0x0920,
  27776. tthagujarati: 0x0AA0,
  27777. tthagurmukhi: 0x0A20,
  27778. tturned: 0x0287,
  27779. tuhiragana: 0x3064,
  27780. tukatakana: 0x30C4,
  27781. tukatakanahalfwidth: 0xFF82,
  27782. tusmallhiragana: 0x3063,
  27783. tusmallkatakana: 0x30C3,
  27784. tusmallkatakanahalfwidth: 0xFF6F,
  27785. twelvecircle: 0x246B,
  27786. twelveparen: 0x247F,
  27787. twelveperiod: 0x2493,
  27788. twelveroman: 0x217B,
  27789. twentycircle: 0x2473,
  27790. twentyhangzhou: 0x5344,
  27791. twentyparen: 0x2487,
  27792. twentyperiod: 0x249B,
  27793. two: 0x0032,
  27794. twoarabic: 0x0662,
  27795. twobengali: 0x09E8,
  27796. twocircle: 0x2461,
  27797. twocircleinversesansserif: 0x278B,
  27798. twodeva: 0x0968,
  27799. twodotenleader: 0x2025,
  27800. twodotleader: 0x2025,
  27801. twodotleadervertical: 0xFE30,
  27802. twogujarati: 0x0AE8,
  27803. twogurmukhi: 0x0A68,
  27804. twohackarabic: 0x0662,
  27805. twohangzhou: 0x3022,
  27806. twoideographicparen: 0x3221,
  27807. twoinferior: 0x2082,
  27808. twomonospace: 0xFF12,
  27809. twonumeratorbengali: 0x09F5,
  27810. twooldstyle: 0xF732,
  27811. twoparen: 0x2475,
  27812. twoperiod: 0x2489,
  27813. twopersian: 0x06F2,
  27814. tworoman: 0x2171,
  27815. twostroke: 0x01BB,
  27816. twosuperior: 0x00B2,
  27817. twothai: 0x0E52,
  27818. twothirds: 0x2154,
  27819. u: 0x0075,
  27820. uacute: 0x00FA,
  27821. ubar: 0x0289,
  27822. ubengali: 0x0989,
  27823. ubopomofo: 0x3128,
  27824. ubreve: 0x016D,
  27825. ucaron: 0x01D4,
  27826. ucircle: 0x24E4,
  27827. ucircumflex: 0x00FB,
  27828. ucircumflexbelow: 0x1E77,
  27829. ucyrillic: 0x0443,
  27830. udattadeva: 0x0951,
  27831. udblacute: 0x0171,
  27832. udblgrave: 0x0215,
  27833. udeva: 0x0909,
  27834. udieresis: 0x00FC,
  27835. udieresisacute: 0x01D8,
  27836. udieresisbelow: 0x1E73,
  27837. udieresiscaron: 0x01DA,
  27838. udieresiscyrillic: 0x04F1,
  27839. udieresisgrave: 0x01DC,
  27840. udieresismacron: 0x01D6,
  27841. udotbelow: 0x1EE5,
  27842. ugrave: 0x00F9,
  27843. ugujarati: 0x0A89,
  27844. ugurmukhi: 0x0A09,
  27845. uhiragana: 0x3046,
  27846. uhookabove: 0x1EE7,
  27847. uhorn: 0x01B0,
  27848. uhornacute: 0x1EE9,
  27849. uhorndotbelow: 0x1EF1,
  27850. uhorngrave: 0x1EEB,
  27851. uhornhookabove: 0x1EED,
  27852. uhorntilde: 0x1EEF,
  27853. uhungarumlaut: 0x0171,
  27854. uhungarumlautcyrillic: 0x04F3,
  27855. uinvertedbreve: 0x0217,
  27856. ukatakana: 0x30A6,
  27857. ukatakanahalfwidth: 0xFF73,
  27858. ukcyrillic: 0x0479,
  27859. ukorean: 0x315C,
  27860. umacron: 0x016B,
  27861. umacroncyrillic: 0x04EF,
  27862. umacrondieresis: 0x1E7B,
  27863. umatragurmukhi: 0x0A41,
  27864. umonospace: 0xFF55,
  27865. underscore: 0x005F,
  27866. underscoredbl: 0x2017,
  27867. underscoremonospace: 0xFF3F,
  27868. underscorevertical: 0xFE33,
  27869. underscorewavy: 0xFE4F,
  27870. union: 0x222A,
  27871. universal: 0x2200,
  27872. uogonek: 0x0173,
  27873. uparen: 0x24B0,
  27874. upblock: 0x2580,
  27875. upperdothebrew: 0x05C4,
  27876. upsilon: 0x03C5,
  27877. upsilondieresis: 0x03CB,
  27878. upsilondieresistonos: 0x03B0,
  27879. upsilonlatin: 0x028A,
  27880. upsilontonos: 0x03CD,
  27881. uptackbelowcmb: 0x031D,
  27882. uptackmod: 0x02D4,
  27883. uragurmukhi: 0x0A73,
  27884. uring: 0x016F,
  27885. ushortcyrillic: 0x045E,
  27886. usmallhiragana: 0x3045,
  27887. usmallkatakana: 0x30A5,
  27888. usmallkatakanahalfwidth: 0xFF69,
  27889. ustraightcyrillic: 0x04AF,
  27890. ustraightstrokecyrillic: 0x04B1,
  27891. utilde: 0x0169,
  27892. utildeacute: 0x1E79,
  27893. utildebelow: 0x1E75,
  27894. uubengali: 0x098A,
  27895. uudeva: 0x090A,
  27896. uugujarati: 0x0A8A,
  27897. uugurmukhi: 0x0A0A,
  27898. uumatragurmukhi: 0x0A42,
  27899. uuvowelsignbengali: 0x09C2,
  27900. uuvowelsigndeva: 0x0942,
  27901. uuvowelsigngujarati: 0x0AC2,
  27902. uvowelsignbengali: 0x09C1,
  27903. uvowelsigndeva: 0x0941,
  27904. uvowelsigngujarati: 0x0AC1,
  27905. v: 0x0076,
  27906. vadeva: 0x0935,
  27907. vagujarati: 0x0AB5,
  27908. vagurmukhi: 0x0A35,
  27909. vakatakana: 0x30F7,
  27910. vav: 0x05D5,
  27911. vavdagesh: 0xFB35,
  27912. vavdagesh65: 0xFB35,
  27913. vavdageshhebrew: 0xFB35,
  27914. vavhebrew: 0x05D5,
  27915. vavholam: 0xFB4B,
  27916. vavholamhebrew: 0xFB4B,
  27917. vavvavhebrew: 0x05F0,
  27918. vavyodhebrew: 0x05F1,
  27919. vcircle: 0x24E5,
  27920. vdotbelow: 0x1E7F,
  27921. vecyrillic: 0x0432,
  27922. veharabic: 0x06A4,
  27923. vehfinalarabic: 0xFB6B,
  27924. vehinitialarabic: 0xFB6C,
  27925. vehmedialarabic: 0xFB6D,
  27926. vekatakana: 0x30F9,
  27927. venus: 0x2640,
  27928. verticalbar: 0x007C,
  27929. verticallineabovecmb: 0x030D,
  27930. verticallinebelowcmb: 0x0329,
  27931. verticallinelowmod: 0x02CC,
  27932. verticallinemod: 0x02C8,
  27933. vewarmenian: 0x057E,
  27934. vhook: 0x028B,
  27935. vikatakana: 0x30F8,
  27936. viramabengali: 0x09CD,
  27937. viramadeva: 0x094D,
  27938. viramagujarati: 0x0ACD,
  27939. visargabengali: 0x0983,
  27940. visargadeva: 0x0903,
  27941. visargagujarati: 0x0A83,
  27942. vmonospace: 0xFF56,
  27943. voarmenian: 0x0578,
  27944. voicediterationhiragana: 0x309E,
  27945. voicediterationkatakana: 0x30FE,
  27946. voicedmarkkana: 0x309B,
  27947. voicedmarkkanahalfwidth: 0xFF9E,
  27948. vokatakana: 0x30FA,
  27949. vparen: 0x24B1,
  27950. vtilde: 0x1E7D,
  27951. vturned: 0x028C,
  27952. vuhiragana: 0x3094,
  27953. vukatakana: 0x30F4,
  27954. w: 0x0077,
  27955. wacute: 0x1E83,
  27956. waekorean: 0x3159,
  27957. wahiragana: 0x308F,
  27958. wakatakana: 0x30EF,
  27959. wakatakanahalfwidth: 0xFF9C,
  27960. wakorean: 0x3158,
  27961. wasmallhiragana: 0x308E,
  27962. wasmallkatakana: 0x30EE,
  27963. wattosquare: 0x3357,
  27964. wavedash: 0x301C,
  27965. wavyunderscorevertical: 0xFE34,
  27966. wawarabic: 0x0648,
  27967. wawfinalarabic: 0xFEEE,
  27968. wawhamzaabovearabic: 0x0624,
  27969. wawhamzaabovefinalarabic: 0xFE86,
  27970. wbsquare: 0x33DD,
  27971. wcircle: 0x24E6,
  27972. wcircumflex: 0x0175,
  27973. wdieresis: 0x1E85,
  27974. wdotaccent: 0x1E87,
  27975. wdotbelow: 0x1E89,
  27976. wehiragana: 0x3091,
  27977. weierstrass: 0x2118,
  27978. wekatakana: 0x30F1,
  27979. wekorean: 0x315E,
  27980. weokorean: 0x315D,
  27981. wgrave: 0x1E81,
  27982. whitebullet: 0x25E6,
  27983. whitecircle: 0x25CB,
  27984. whitecircleinverse: 0x25D9,
  27985. whitecornerbracketleft: 0x300E,
  27986. whitecornerbracketleftvertical: 0xFE43,
  27987. whitecornerbracketright: 0x300F,
  27988. whitecornerbracketrightvertical: 0xFE44,
  27989. whitediamond: 0x25C7,
  27990. whitediamondcontainingblacksmalldiamond: 0x25C8,
  27991. whitedownpointingsmalltriangle: 0x25BF,
  27992. whitedownpointingtriangle: 0x25BD,
  27993. whiteleftpointingsmalltriangle: 0x25C3,
  27994. whiteleftpointingtriangle: 0x25C1,
  27995. whitelenticularbracketleft: 0x3016,
  27996. whitelenticularbracketright: 0x3017,
  27997. whiterightpointingsmalltriangle: 0x25B9,
  27998. whiterightpointingtriangle: 0x25B7,
  27999. whitesmallsquare: 0x25AB,
  28000. whitesmilingface: 0x263A,
  28001. whitesquare: 0x25A1,
  28002. whitestar: 0x2606,
  28003. whitetelephone: 0x260F,
  28004. whitetortoiseshellbracketleft: 0x3018,
  28005. whitetortoiseshellbracketright: 0x3019,
  28006. whiteuppointingsmalltriangle: 0x25B5,
  28007. whiteuppointingtriangle: 0x25B3,
  28008. wihiragana: 0x3090,
  28009. wikatakana: 0x30F0,
  28010. wikorean: 0x315F,
  28011. wmonospace: 0xFF57,
  28012. wohiragana: 0x3092,
  28013. wokatakana: 0x30F2,
  28014. wokatakanahalfwidth: 0xFF66,
  28015. won: 0x20A9,
  28016. wonmonospace: 0xFFE6,
  28017. wowaenthai: 0x0E27,
  28018. wparen: 0x24B2,
  28019. wring: 0x1E98,
  28020. wsuperior: 0x02B7,
  28021. wturned: 0x028D,
  28022. wynn: 0x01BF,
  28023. x: 0x0078,
  28024. xabovecmb: 0x033D,
  28025. xbopomofo: 0x3112,
  28026. xcircle: 0x24E7,
  28027. xdieresis: 0x1E8D,
  28028. xdotaccent: 0x1E8B,
  28029. xeharmenian: 0x056D,
  28030. xi: 0x03BE,
  28031. xmonospace: 0xFF58,
  28032. xparen: 0x24B3,
  28033. xsuperior: 0x02E3,
  28034. y: 0x0079,
  28035. yaadosquare: 0x334E,
  28036. yabengali: 0x09AF,
  28037. yacute: 0x00FD,
  28038. yadeva: 0x092F,
  28039. yaekorean: 0x3152,
  28040. yagujarati: 0x0AAF,
  28041. yagurmukhi: 0x0A2F,
  28042. yahiragana: 0x3084,
  28043. yakatakana: 0x30E4,
  28044. yakatakanahalfwidth: 0xFF94,
  28045. yakorean: 0x3151,
  28046. yamakkanthai: 0x0E4E,
  28047. yasmallhiragana: 0x3083,
  28048. yasmallkatakana: 0x30E3,
  28049. yasmallkatakanahalfwidth: 0xFF6C,
  28050. yatcyrillic: 0x0463,
  28051. ycircle: 0x24E8,
  28052. ycircumflex: 0x0177,
  28053. ydieresis: 0x00FF,
  28054. ydotaccent: 0x1E8F,
  28055. ydotbelow: 0x1EF5,
  28056. yeharabic: 0x064A,
  28057. yehbarreearabic: 0x06D2,
  28058. yehbarreefinalarabic: 0xFBAF,
  28059. yehfinalarabic: 0xFEF2,
  28060. yehhamzaabovearabic: 0x0626,
  28061. yehhamzaabovefinalarabic: 0xFE8A,
  28062. yehhamzaaboveinitialarabic: 0xFE8B,
  28063. yehhamzaabovemedialarabic: 0xFE8C,
  28064. yehinitialarabic: 0xFEF3,
  28065. yehmedialarabic: 0xFEF4,
  28066. yehmeeminitialarabic: 0xFCDD,
  28067. yehmeemisolatedarabic: 0xFC58,
  28068. yehnoonfinalarabic: 0xFC94,
  28069. yehthreedotsbelowarabic: 0x06D1,
  28070. yekorean: 0x3156,
  28071. yen: 0x00A5,
  28072. yenmonospace: 0xFFE5,
  28073. yeokorean: 0x3155,
  28074. yeorinhieuhkorean: 0x3186,
  28075. yerahbenyomohebrew: 0x05AA,
  28076. yerahbenyomolefthebrew: 0x05AA,
  28077. yericyrillic: 0x044B,
  28078. yerudieresiscyrillic: 0x04F9,
  28079. yesieungkorean: 0x3181,
  28080. yesieungpansioskorean: 0x3183,
  28081. yesieungsioskorean: 0x3182,
  28082. yetivhebrew: 0x059A,
  28083. ygrave: 0x1EF3,
  28084. yhook: 0x01B4,
  28085. yhookabove: 0x1EF7,
  28086. yiarmenian: 0x0575,
  28087. yicyrillic: 0x0457,
  28088. yikorean: 0x3162,
  28089. yinyang: 0x262F,
  28090. yiwnarmenian: 0x0582,
  28091. ymonospace: 0xFF59,
  28092. yod: 0x05D9,
  28093. yoddagesh: 0xFB39,
  28094. yoddageshhebrew: 0xFB39,
  28095. yodhebrew: 0x05D9,
  28096. yodyodhebrew: 0x05F2,
  28097. yodyodpatahhebrew: 0xFB1F,
  28098. yohiragana: 0x3088,
  28099. yoikorean: 0x3189,
  28100. yokatakana: 0x30E8,
  28101. yokatakanahalfwidth: 0xFF96,
  28102. yokorean: 0x315B,
  28103. yosmallhiragana: 0x3087,
  28104. yosmallkatakana: 0x30E7,
  28105. yosmallkatakanahalfwidth: 0xFF6E,
  28106. yotgreek: 0x03F3,
  28107. yoyaekorean: 0x3188,
  28108. yoyakorean: 0x3187,
  28109. yoyakthai: 0x0E22,
  28110. yoyingthai: 0x0E0D,
  28111. yparen: 0x24B4,
  28112. ypogegrammeni: 0x037A,
  28113. ypogegrammenigreekcmb: 0x0345,
  28114. yr: 0x01A6,
  28115. yring: 0x1E99,
  28116. ysuperior: 0x02B8,
  28117. ytilde: 0x1EF9,
  28118. yturned: 0x028E,
  28119. yuhiragana: 0x3086,
  28120. yuikorean: 0x318C,
  28121. yukatakana: 0x30E6,
  28122. yukatakanahalfwidth: 0xFF95,
  28123. yukorean: 0x3160,
  28124. yusbigcyrillic: 0x046B,
  28125. yusbigiotifiedcyrillic: 0x046D,
  28126. yuslittlecyrillic: 0x0467,
  28127. yuslittleiotifiedcyrillic: 0x0469,
  28128. yusmallhiragana: 0x3085,
  28129. yusmallkatakana: 0x30E5,
  28130. yusmallkatakanahalfwidth: 0xFF6D,
  28131. yuyekorean: 0x318B,
  28132. yuyeokorean: 0x318A,
  28133. yyabengali: 0x09DF,
  28134. yyadeva: 0x095F,
  28135. z: 0x007A,
  28136. zaarmenian: 0x0566,
  28137. zacute: 0x017A,
  28138. zadeva: 0x095B,
  28139. zagurmukhi: 0x0A5B,
  28140. zaharabic: 0x0638,
  28141. zahfinalarabic: 0xFEC6,
  28142. zahinitialarabic: 0xFEC7,
  28143. zahiragana: 0x3056,
  28144. zahmedialarabic: 0xFEC8,
  28145. zainarabic: 0x0632,
  28146. zainfinalarabic: 0xFEB0,
  28147. zakatakana: 0x30B6,
  28148. zaqefgadolhebrew: 0x0595,
  28149. zaqefqatanhebrew: 0x0594,
  28150. zarqahebrew: 0x0598,
  28151. zayin: 0x05D6,
  28152. zayindagesh: 0xFB36,
  28153. zayindageshhebrew: 0xFB36,
  28154. zayinhebrew: 0x05D6,
  28155. zbopomofo: 0x3117,
  28156. zcaron: 0x017E,
  28157. zcircle: 0x24E9,
  28158. zcircumflex: 0x1E91,
  28159. zcurl: 0x0291,
  28160. zdot: 0x017C,
  28161. zdotaccent: 0x017C,
  28162. zdotbelow: 0x1E93,
  28163. zecyrillic: 0x0437,
  28164. zedescendercyrillic: 0x0499,
  28165. zedieresiscyrillic: 0x04DF,
  28166. zehiragana: 0x305C,
  28167. zekatakana: 0x30BC,
  28168. zero: 0x0030,
  28169. zeroarabic: 0x0660,
  28170. zerobengali: 0x09E6,
  28171. zerodeva: 0x0966,
  28172. zerogujarati: 0x0AE6,
  28173. zerogurmukhi: 0x0A66,
  28174. zerohackarabic: 0x0660,
  28175. zeroinferior: 0x2080,
  28176. zeromonospace: 0xFF10,
  28177. zerooldstyle: 0xF730,
  28178. zeropersian: 0x06F0,
  28179. zerosuperior: 0x2070,
  28180. zerothai: 0x0E50,
  28181. zerowidthjoiner: 0xFEFF,
  28182. zerowidthnonjoiner: 0x200C,
  28183. zerowidthspace: 0x200B,
  28184. zeta: 0x03B6,
  28185. zhbopomofo: 0x3113,
  28186. zhearmenian: 0x056A,
  28187. zhebrevecyrillic: 0x04C2,
  28188. zhecyrillic: 0x0436,
  28189. zhedescendercyrillic: 0x0497,
  28190. zhedieresiscyrillic: 0x04DD,
  28191. zihiragana: 0x3058,
  28192. zikatakana: 0x30B8,
  28193. zinorhebrew: 0x05AE,
  28194. zlinebelow: 0x1E95,
  28195. zmonospace: 0xFF5A,
  28196. zohiragana: 0x305E,
  28197. zokatakana: 0x30BE,
  28198. zparen: 0x24B5,
  28199. zretroflexhook: 0x0290,
  28200. zstroke: 0x01B6,
  28201. zuhiragana: 0x305A,
  28202. zukatakana: 0x30BA,
  28203. '.notdef': 0x0000
  28204. };
  28205. var PDFImage = (function PDFImageClosure() {
  28206. /**
  28207. * Decode the image in the main thread if it supported. Resovles the promise
  28208. * when the image data is ready.
  28209. */
  28210. function handleImageData(handler, xref, res, image) {
  28211. if (image instanceof JpegStream && image.isNativelyDecodable(xref, res)) {
  28212. // For natively supported jpegs send them to the main thread for decoding.
  28213. var dict = image.dict;
  28214. var colorSpace = dict.get('ColorSpace', 'CS');
  28215. colorSpace = ColorSpace.parse(colorSpace, xref, res);
  28216. var numComps = colorSpace.numComps;
  28217. var decodePromise = handler.sendWithPromise('JpegDecode',
  28218. [image.getIR(), numComps]);
  28219. return decodePromise.then(function (message) {
  28220. var data = message.data;
  28221. return new Stream(data, 0, data.length, image.dict);
  28222. });
  28223. } else {
  28224. return Promise.resolve(image);
  28225. }
  28226. }
  28227. /**
  28228. * Decode and clamp a value. The formula is different from the spec because we
  28229. * don't decode to float range [0,1], we decode it in the [0,max] range.
  28230. */
  28231. function decodeAndClamp(value, addend, coefficient, max) {
  28232. value = addend + value * coefficient;
  28233. // Clamp the value to the range
  28234. return (value < 0 ? 0 : (value > max ? max : value));
  28235. }
  28236. function PDFImage(xref, res, image, inline, smask, mask, isMask) {
  28237. this.image = image;
  28238. var dict = image.dict;
  28239. if (dict.has('Filter')) {
  28240. var filter = dict.get('Filter').name;
  28241. if (filter === 'JPXDecode') {
  28242. var jpxImage = new JpxImage();
  28243. jpxImage.parseImageProperties(image.stream);
  28244. image.stream.reset();
  28245. image.bitsPerComponent = jpxImage.bitsPerComponent;
  28246. image.numComps = jpxImage.componentsCount;
  28247. } else if (filter === 'JBIG2Decode') {
  28248. image.bitsPerComponent = 1;
  28249. image.numComps = 1;
  28250. }
  28251. }
  28252. // TODO cache rendered images?
  28253. this.width = dict.get('Width', 'W');
  28254. this.height = dict.get('Height', 'H');
  28255. if (this.width < 1 || this.height < 1) {
  28256. error('Invalid image width: ' + this.width + ' or height: ' +
  28257. this.height);
  28258. }
  28259. this.interpolate = dict.get('Interpolate', 'I') || false;
  28260. this.imageMask = dict.get('ImageMask', 'IM') || false;
  28261. this.matte = dict.get('Matte') || false;
  28262. var bitsPerComponent = image.bitsPerComponent;
  28263. if (!bitsPerComponent) {
  28264. bitsPerComponent = dict.get('BitsPerComponent', 'BPC');
  28265. if (!bitsPerComponent) {
  28266. if (this.imageMask) {
  28267. bitsPerComponent = 1;
  28268. } else {
  28269. error('Bits per component missing in image: ' + this.imageMask);
  28270. }
  28271. }
  28272. }
  28273. this.bpc = bitsPerComponent;
  28274. if (!this.imageMask) {
  28275. var colorSpace = dict.get('ColorSpace', 'CS');
  28276. if (!colorSpace) {
  28277. info('JPX images (which do not require color spaces)');
  28278. switch (image.numComps) {
  28279. case 1:
  28280. colorSpace = Name.get('DeviceGray');
  28281. break;
  28282. case 3:
  28283. colorSpace = Name.get('DeviceRGB');
  28284. break;
  28285. case 4:
  28286. colorSpace = Name.get('DeviceCMYK');
  28287. break;
  28288. default:
  28289. error('JPX images with ' + this.numComps +
  28290. ' color components not supported.');
  28291. }
  28292. }
  28293. this.colorSpace = ColorSpace.parse(colorSpace, xref, res);
  28294. this.numComps = this.colorSpace.numComps;
  28295. }
  28296. this.decode = dict.get('Decode', 'D');
  28297. this.needsDecode = false;
  28298. if (this.decode &&
  28299. ((this.colorSpace && !this.colorSpace.isDefaultDecode(this.decode)) ||
  28300. (isMask && !ColorSpace.isDefaultDecode(this.decode, 1)))) {
  28301. this.needsDecode = true;
  28302. // Do some preprocessing to avoid more math.
  28303. var max = (1 << bitsPerComponent) - 1;
  28304. this.decodeCoefficients = [];
  28305. this.decodeAddends = [];
  28306. for (var i = 0, j = 0; i < this.decode.length; i += 2, ++j) {
  28307. var dmin = this.decode[i];
  28308. var dmax = this.decode[i + 1];
  28309. this.decodeCoefficients[j] = dmax - dmin;
  28310. this.decodeAddends[j] = max * dmin;
  28311. }
  28312. }
  28313. if (smask) {
  28314. this.smask = new PDFImage(xref, res, smask, false);
  28315. } else if (mask) {
  28316. if (isStream(mask)) {
  28317. this.mask = new PDFImage(xref, res, mask, false, null, null, true);
  28318. } else {
  28319. // Color key mask (just an array).
  28320. this.mask = mask;
  28321. }
  28322. }
  28323. }
  28324. /**
  28325. * Handles processing of image data and returns the Promise that is resolved
  28326. * with a PDFImage when the image is ready to be used.
  28327. */
  28328. PDFImage.buildImage = function PDFImage_buildImage(handler, xref,
  28329. res, image, inline) {
  28330. var imagePromise = handleImageData(handler, xref, res, image);
  28331. var smaskPromise;
  28332. var maskPromise;
  28333. var smask = image.dict.get('SMask');
  28334. var mask = image.dict.get('Mask');
  28335. if (smask) {
  28336. smaskPromise = handleImageData(handler, xref, res, smask);
  28337. maskPromise = Promise.resolve(null);
  28338. } else {
  28339. smaskPromise = Promise.resolve(null);
  28340. if (mask) {
  28341. if (isStream(mask)) {
  28342. maskPromise = handleImageData(handler, xref, res, mask);
  28343. } else if (isArray(mask)) {
  28344. maskPromise = Promise.resolve(mask);
  28345. } else {
  28346. warn('Unsupported mask format.');
  28347. maskPromise = Promise.resolve(null);
  28348. }
  28349. } else {
  28350. maskPromise = Promise.resolve(null);
  28351. }
  28352. }
  28353. return Promise.all([imagePromise, smaskPromise, maskPromise]).then(
  28354. function(results) {
  28355. var imageData = results[0];
  28356. var smaskData = results[1];
  28357. var maskData = results[2];
  28358. return new PDFImage(xref, res, imageData, inline, smaskData, maskData);
  28359. });
  28360. };
  28361. /**
  28362. * Resize an image using the nearest neighbor algorithm. Currently only
  28363. * supports one and three component images.
  28364. * @param {TypedArray} pixels The original image with one component.
  28365. * @param {Number} bpc Number of bits per component.
  28366. * @param {Number} components Number of color components, 1 or 3 is supported.
  28367. * @param {Number} w1 Original width.
  28368. * @param {Number} h1 Original height.
  28369. * @param {Number} w2 New width.
  28370. * @param {Number} h2 New height.
  28371. * @param {TypedArray} dest (Optional) The destination buffer.
  28372. * @param {Number} alpha01 (Optional) Size reserved for the alpha channel.
  28373. * @return {TypedArray} Resized image data.
  28374. */
  28375. PDFImage.resize = function PDFImage_resize(pixels, bpc, components,
  28376. w1, h1, w2, h2, dest, alpha01) {
  28377. if (components !== 1 && components !== 3) {
  28378. error('Unsupported component count for resizing.');
  28379. }
  28380. var length = w2 * h2 * components;
  28381. var temp = dest ? dest : (bpc <= 8 ? new Uint8Array(length) :
  28382. (bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length)));
  28383. var xRatio = w1 / w2;
  28384. var yRatio = h1 / h2;
  28385. var i, j, py, newIndex = 0, oldIndex;
  28386. var xScaled = new Uint16Array(w2);
  28387. var w1Scanline = w1 * components;
  28388. if (alpha01 !== 1) {
  28389. alpha01 = 0;
  28390. }
  28391. for (j = 0; j < w2; j++) {
  28392. xScaled[j] = Math.floor(j * xRatio) * components;
  28393. }
  28394. if (components === 1) {
  28395. for (i = 0; i < h2; i++) {
  28396. py = Math.floor(i * yRatio) * w1Scanline;
  28397. for (j = 0; j < w2; j++) {
  28398. oldIndex = py + xScaled[j];
  28399. temp[newIndex++] = pixels[oldIndex];
  28400. }
  28401. }
  28402. } else if (components === 3) {
  28403. for (i = 0; i < h2; i++) {
  28404. py = Math.floor(i * yRatio) * w1Scanline;
  28405. for (j = 0; j < w2; j++) {
  28406. oldIndex = py + xScaled[j];
  28407. temp[newIndex++] = pixels[oldIndex++];
  28408. temp[newIndex++] = pixels[oldIndex++];
  28409. temp[newIndex++] = pixels[oldIndex++];
  28410. newIndex += alpha01;
  28411. }
  28412. }
  28413. }
  28414. return temp;
  28415. };
  28416. PDFImage.createMask =
  28417. function PDFImage_createMask(imgArray, width, height,
  28418. imageIsFromDecodeStream, inverseDecode) {
  28419. // |imgArray| might not contain full data for every pixel of the mask, so
  28420. // we need to distinguish between |computedLength| and |actualLength|.
  28421. // In particular, if inverseDecode is true, then the array we return must
  28422. // have a length of |computedLength|.
  28423. var computedLength = ((width + 7) >> 3) * height;
  28424. var actualLength = imgArray.byteLength;
  28425. var haveFullData = computedLength === actualLength;
  28426. var data, i;
  28427. if (imageIsFromDecodeStream && (!inverseDecode || haveFullData)) {
  28428. // imgArray came from a DecodeStream and its data is in an appropriate
  28429. // form, so we can just transfer it.
  28430. data = imgArray;
  28431. } else if (!inverseDecode) {
  28432. data = new Uint8Array(actualLength);
  28433. data.set(imgArray);
  28434. } else {
  28435. data = new Uint8Array(computedLength);
  28436. data.set(imgArray);
  28437. for (i = actualLength; i < computedLength; i++) {
  28438. data[i] = 0xff;
  28439. }
  28440. }
  28441. // If necessary, invert the original mask data (but not any extra we might
  28442. // have added above). It's safe to modify the array -- whether it's the
  28443. // original or a copy, we're about to transfer it anyway, so nothing else
  28444. // in this thread can be relying on its contents.
  28445. if (inverseDecode) {
  28446. for (i = 0; i < actualLength; i++) {
  28447. data[i] = ~data[i];
  28448. }
  28449. }
  28450. return {data: data, width: width, height: height};
  28451. };
  28452. PDFImage.prototype = {
  28453. get drawWidth() {
  28454. return Math.max(this.width,
  28455. this.smask && this.smask.width || 0,
  28456. this.mask && this.mask.width || 0);
  28457. },
  28458. get drawHeight() {
  28459. return Math.max(this.height,
  28460. this.smask && this.smask.height || 0,
  28461. this.mask && this.mask.height || 0);
  28462. },
  28463. decodeBuffer: function PDFImage_decodeBuffer(buffer) {
  28464. var bpc = this.bpc;
  28465. var numComps = this.numComps;
  28466. var decodeAddends = this.decodeAddends;
  28467. var decodeCoefficients = this.decodeCoefficients;
  28468. var max = (1 << bpc) - 1;
  28469. var i, ii;
  28470. if (bpc === 1) {
  28471. // If the buffer needed decode that means it just needs to be inverted.
  28472. for (i = 0, ii = buffer.length; i < ii; i++) {
  28473. buffer[i] = +!(buffer[i]);
  28474. }
  28475. return;
  28476. }
  28477. var index = 0;
  28478. for (i = 0, ii = this.width * this.height; i < ii; i++) {
  28479. for (var j = 0; j < numComps; j++) {
  28480. buffer[index] = decodeAndClamp(buffer[index], decodeAddends[j],
  28481. decodeCoefficients[j], max);
  28482. index++;
  28483. }
  28484. }
  28485. },
  28486. getComponents: function PDFImage_getComponents(buffer) {
  28487. var bpc = this.bpc;
  28488. // This image doesn't require any extra work.
  28489. if (bpc === 8) {
  28490. return buffer;
  28491. }
  28492. var width = this.width;
  28493. var height = this.height;
  28494. var numComps = this.numComps;
  28495. var length = width * height * numComps;
  28496. var bufferPos = 0;
  28497. var output = (bpc <= 8 ? new Uint8Array(length) :
  28498. (bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length)));
  28499. var rowComps = width * numComps;
  28500. var max = (1 << bpc) - 1;
  28501. var i = 0, ii, buf;
  28502. if (bpc === 1) {
  28503. // Optimization for reading 1 bpc images.
  28504. var mask, loop1End, loop2End;
  28505. for (var j = 0; j < height; j++) {
  28506. loop1End = i + (rowComps & ~7);
  28507. loop2End = i + rowComps;
  28508. // unroll loop for all full bytes
  28509. while (i < loop1End) {
  28510. buf = buffer[bufferPos++];
  28511. output[i] = (buf >> 7) & 1;
  28512. output[i + 1] = (buf >> 6) & 1;
  28513. output[i + 2] = (buf >> 5) & 1;
  28514. output[i + 3] = (buf >> 4) & 1;
  28515. output[i + 4] = (buf >> 3) & 1;
  28516. output[i + 5] = (buf >> 2) & 1;
  28517. output[i + 6] = (buf >> 1) & 1;
  28518. output[i + 7] = buf & 1;
  28519. i += 8;
  28520. }
  28521. // handle remaing bits
  28522. if (i < loop2End) {
  28523. buf = buffer[bufferPos++];
  28524. mask = 128;
  28525. while (i < loop2End) {
  28526. output[i++] = +!!(buf & mask);
  28527. mask >>= 1;
  28528. }
  28529. }
  28530. }
  28531. } else {
  28532. // The general case that handles all other bpc values.
  28533. var bits = 0;
  28534. buf = 0;
  28535. for (i = 0, ii = length; i < ii; ++i) {
  28536. if (i % rowComps === 0) {
  28537. buf = 0;
  28538. bits = 0;
  28539. }
  28540. while (bits < bpc) {
  28541. buf = (buf << 8) | buffer[bufferPos++];
  28542. bits += 8;
  28543. }
  28544. var remainingBits = bits - bpc;
  28545. var value = buf >> remainingBits;
  28546. output[i] = (value < 0 ? 0 : (value > max ? max : value));
  28547. buf = buf & ((1 << remainingBits) - 1);
  28548. bits = remainingBits;
  28549. }
  28550. }
  28551. return output;
  28552. },
  28553. fillOpacity: function PDFImage_fillOpacity(rgbaBuf, width, height,
  28554. actualHeight, image) {
  28555. var smask = this.smask;
  28556. var mask = this.mask;
  28557. var alphaBuf, sw, sh, i, ii, j;
  28558. if (smask) {
  28559. sw = smask.width;
  28560. sh = smask.height;
  28561. alphaBuf = new Uint8Array(sw * sh);
  28562. smask.fillGrayBuffer(alphaBuf);
  28563. if (sw !== width || sh !== height) {
  28564. alphaBuf = PDFImage.resize(alphaBuf, smask.bpc, 1, sw, sh, width,
  28565. height);
  28566. }
  28567. } else if (mask) {
  28568. if (mask instanceof PDFImage) {
  28569. sw = mask.width;
  28570. sh = mask.height;
  28571. alphaBuf = new Uint8Array(sw * sh);
  28572. mask.numComps = 1;
  28573. mask.fillGrayBuffer(alphaBuf);
  28574. // Need to invert values in rgbaBuf
  28575. for (i = 0, ii = sw * sh; i < ii; ++i) {
  28576. alphaBuf[i] = 255 - alphaBuf[i];
  28577. }
  28578. if (sw !== width || sh !== height) {
  28579. alphaBuf = PDFImage.resize(alphaBuf, mask.bpc, 1, sw, sh, width,
  28580. height);
  28581. }
  28582. } else if (isArray(mask)) {
  28583. // Color key mask: if any of the compontents are outside the range
  28584. // then they should be painted.
  28585. alphaBuf = new Uint8Array(width * height);
  28586. var numComps = this.numComps;
  28587. for (i = 0, ii = width * height; i < ii; ++i) {
  28588. var opacity = 0;
  28589. var imageOffset = i * numComps;
  28590. for (j = 0; j < numComps; ++j) {
  28591. var color = image[imageOffset + j];
  28592. var maskOffset = j * 2;
  28593. if (color < mask[maskOffset] || color > mask[maskOffset + 1]) {
  28594. opacity = 255;
  28595. break;
  28596. }
  28597. }
  28598. alphaBuf[i] = opacity;
  28599. }
  28600. } else {
  28601. error('Unknown mask format.');
  28602. }
  28603. }
  28604. if (alphaBuf) {
  28605. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  28606. rgbaBuf[j] = alphaBuf[i];
  28607. }
  28608. } else {
  28609. // No mask.
  28610. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  28611. rgbaBuf[j] = 255;
  28612. }
  28613. }
  28614. },
  28615. undoPreblend: function PDFImage_undoPreblend(buffer, width, height) {
  28616. var matte = this.smask && this.smask.matte;
  28617. if (!matte) {
  28618. return;
  28619. }
  28620. var matteRgb = this.colorSpace.getRgb(matte, 0);
  28621. var matteR = matteRgb[0];
  28622. var matteG = matteRgb[1];
  28623. var matteB = matteRgb[2];
  28624. var length = width * height * 4;
  28625. var r, g, b;
  28626. for (var i = 0; i < length; i += 4) {
  28627. var alpha = buffer[i + 3];
  28628. if (alpha === 0) {
  28629. // according formula we have to get Infinity in all components
  28630. // making it white (typical paper color) should be okay
  28631. buffer[i] = 255;
  28632. buffer[i + 1] = 255;
  28633. buffer[i + 2] = 255;
  28634. continue;
  28635. }
  28636. var k = 255 / alpha;
  28637. r = (buffer[i] - matteR) * k + matteR;
  28638. g = (buffer[i + 1] - matteG) * k + matteG;
  28639. b = (buffer[i + 2] - matteB) * k + matteB;
  28640. buffer[i] = r <= 0 ? 0 : r >= 255 ? 255 : r | 0;
  28641. buffer[i + 1] = g <= 0 ? 0 : g >= 255 ? 255 : g | 0;
  28642. buffer[i + 2] = b <= 0 ? 0 : b >= 255 ? 255 : b | 0;
  28643. }
  28644. },
  28645. createImageData: function PDFImage_createImageData(forceRGBA) {
  28646. var drawWidth = this.drawWidth;
  28647. var drawHeight = this.drawHeight;
  28648. var imgData = { // other fields are filled in below
  28649. width: drawWidth,
  28650. height: drawHeight
  28651. };
  28652. var numComps = this.numComps;
  28653. var originalWidth = this.width;
  28654. var originalHeight = this.height;
  28655. var bpc = this.bpc;
  28656. // Rows start at byte boundary.
  28657. var rowBytes = (originalWidth * numComps * bpc + 7) >> 3;
  28658. var imgArray;
  28659. if (!forceRGBA) {
  28660. // If it is a 1-bit-per-pixel grayscale (i.e. black-and-white) image
  28661. // without any complications, we pass a same-sized copy to the main
  28662. // thread rather than expanding by 32x to RGBA form. This saves *lots*
  28663. // of memory for many scanned documents. It's also much faster.
  28664. //
  28665. // Similarly, if it is a 24-bit-per pixel RGB image without any
  28666. // complications, we avoid expanding by 1.333x to RGBA form.
  28667. var kind;
  28668. if (this.colorSpace.name === 'DeviceGray' && bpc === 1) {
  28669. kind = ImageKind.GRAYSCALE_1BPP;
  28670. } else if (this.colorSpace.name === 'DeviceRGB' && bpc === 8) {
  28671. kind = ImageKind.RGB_24BPP;
  28672. }
  28673. if (kind && !this.smask && !this.mask && !this.needsDecode &&
  28674. drawWidth === originalWidth && drawHeight === originalHeight) {
  28675. imgData.kind = kind;
  28676. imgArray = this.getImageBytes(originalHeight * rowBytes);
  28677. // If imgArray came from a DecodeStream, we're safe to transfer it
  28678. // (and thus neuter it) because it will constitute the entire
  28679. // DecodeStream's data. But if it came from a Stream, we need to
  28680. // copy it because it'll only be a portion of the Stream's data, and
  28681. // the rest will be read later on.
  28682. if (this.image instanceof DecodeStream) {
  28683. imgData.data = imgArray;
  28684. } else {
  28685. var newArray = new Uint8Array(imgArray.length);
  28686. newArray.set(imgArray);
  28687. imgData.data = newArray;
  28688. }
  28689. return imgData;
  28690. }
  28691. if (this.image instanceof JpegStream && !this.smask && !this.mask) {
  28692. imgData.kind = ImageKind.RGB_24BPP;
  28693. imgData.data = this.getImageBytes(originalHeight * rowBytes,
  28694. drawWidth, drawHeight, true);
  28695. return imgData;
  28696. }
  28697. }
  28698. imgArray = this.getImageBytes(originalHeight * rowBytes);
  28699. // imgArray can be incomplete (e.g. after CCITT fax encoding).
  28700. var actualHeight = 0 | (imgArray.length / rowBytes *
  28701. drawHeight / originalHeight);
  28702. var comps = this.getComponents(imgArray);
  28703. // If opacity data is present, use RGBA_32BPP form. Otherwise, use the
  28704. // more compact RGB_24BPP form if allowable.
  28705. var alpha01, maybeUndoPreblend;
  28706. if (!forceRGBA && !this.smask && !this.mask) {
  28707. imgData.kind = ImageKind.RGB_24BPP;
  28708. imgData.data = new Uint8Array(drawWidth * drawHeight * 3);
  28709. alpha01 = 0;
  28710. maybeUndoPreblend = false;
  28711. } else {
  28712. imgData.kind = ImageKind.RGBA_32BPP;
  28713. imgData.data = new Uint8Array(drawWidth * drawHeight * 4);
  28714. alpha01 = 1;
  28715. maybeUndoPreblend = true;
  28716. // Color key masking (opacity) must be performed before decoding.
  28717. this.fillOpacity(imgData.data, drawWidth, drawHeight, actualHeight,
  28718. comps);
  28719. }
  28720. if (this.needsDecode) {
  28721. this.decodeBuffer(comps);
  28722. }
  28723. this.colorSpace.fillRgb(imgData.data, originalWidth, originalHeight,
  28724. drawWidth, drawHeight, actualHeight, bpc, comps,
  28725. alpha01);
  28726. if (maybeUndoPreblend) {
  28727. this.undoPreblend(imgData.data, drawWidth, actualHeight);
  28728. }
  28729. return imgData;
  28730. },
  28731. fillGrayBuffer: function PDFImage_fillGrayBuffer(buffer) {
  28732. var numComps = this.numComps;
  28733. if (numComps !== 1) {
  28734. error('Reading gray scale from a color image: ' + numComps);
  28735. }
  28736. var width = this.width;
  28737. var height = this.height;
  28738. var bpc = this.bpc;
  28739. // rows start at byte boundary
  28740. var rowBytes = (width * numComps * bpc + 7) >> 3;
  28741. var imgArray = this.getImageBytes(height * rowBytes);
  28742. var comps = this.getComponents(imgArray);
  28743. var i, length;
  28744. if (bpc === 1) {
  28745. // inline decoding (= inversion) for 1 bpc images
  28746. length = width * height;
  28747. if (this.needsDecode) {
  28748. // invert and scale to {0, 255}
  28749. for (i = 0; i < length; ++i) {
  28750. buffer[i] = (comps[i] - 1) & 255;
  28751. }
  28752. } else {
  28753. // scale to {0, 255}
  28754. for (i = 0; i < length; ++i) {
  28755. buffer[i] = (-comps[i]) & 255;
  28756. }
  28757. }
  28758. return;
  28759. }
  28760. if (this.needsDecode) {
  28761. this.decodeBuffer(comps);
  28762. }
  28763. length = width * height;
  28764. // we aren't using a colorspace so we need to scale the value
  28765. var scale = 255 / ((1 << bpc) - 1);
  28766. for (i = 0; i < length; ++i) {
  28767. buffer[i] = (scale * comps[i]) | 0;
  28768. }
  28769. },
  28770. getImageBytes: function PDFImage_getImageBytes(length,
  28771. drawWidth, drawHeight,
  28772. forceRGB) {
  28773. this.image.reset();
  28774. this.image.drawWidth = drawWidth || this.width;
  28775. this.image.drawHeight = drawHeight || this.height;
  28776. this.image.forceRGB = !!forceRGB;
  28777. return this.image.getBytes(length);
  28778. }
  28779. };
  28780. return PDFImage;
  28781. })();
  28782. // The Metrics object contains glyph widths (in glyph space units).
  28783. // As per PDF spec, for most fonts (Type 3 being an exception) a glyph
  28784. // space unit corresponds to 1/1000th of text space unit.
  28785. var Metrics = {
  28786. 'Courier': 600,
  28787. 'Courier-Bold': 600,
  28788. 'Courier-BoldOblique': 600,
  28789. 'Courier-Oblique': 600,
  28790. 'Helvetica' : {
  28791. 'space': 278,
  28792. 'exclam': 278,
  28793. 'quotedbl': 355,
  28794. 'numbersign': 556,
  28795. 'dollar': 556,
  28796. 'percent': 889,
  28797. 'ampersand': 667,
  28798. 'quoteright': 222,
  28799. 'parenleft': 333,
  28800. 'parenright': 333,
  28801. 'asterisk': 389,
  28802. 'plus': 584,
  28803. 'comma': 278,
  28804. 'hyphen': 333,
  28805. 'period': 278,
  28806. 'slash': 278,
  28807. 'zero': 556,
  28808. 'one': 556,
  28809. 'two': 556,
  28810. 'three': 556,
  28811. 'four': 556,
  28812. 'five': 556,
  28813. 'six': 556,
  28814. 'seven': 556,
  28815. 'eight': 556,
  28816. 'nine': 556,
  28817. 'colon': 278,
  28818. 'semicolon': 278,
  28819. 'less': 584,
  28820. 'equal': 584,
  28821. 'greater': 584,
  28822. 'question': 556,
  28823. 'at': 1015,
  28824. 'A': 667,
  28825. 'B': 667,
  28826. 'C': 722,
  28827. 'D': 722,
  28828. 'E': 667,
  28829. 'F': 611,
  28830. 'G': 778,
  28831. 'H': 722,
  28832. 'I': 278,
  28833. 'J': 500,
  28834. 'K': 667,
  28835. 'L': 556,
  28836. 'M': 833,
  28837. 'N': 722,
  28838. 'O': 778,
  28839. 'P': 667,
  28840. 'Q': 778,
  28841. 'R': 722,
  28842. 'S': 667,
  28843. 'T': 611,
  28844. 'U': 722,
  28845. 'V': 667,
  28846. 'W': 944,
  28847. 'X': 667,
  28848. 'Y': 667,
  28849. 'Z': 611,
  28850. 'bracketleft': 278,
  28851. 'backslash': 278,
  28852. 'bracketright': 278,
  28853. 'asciicircum': 469,
  28854. 'underscore': 556,
  28855. 'quoteleft': 222,
  28856. 'a': 556,
  28857. 'b': 556,
  28858. 'c': 500,
  28859. 'd': 556,
  28860. 'e': 556,
  28861. 'f': 278,
  28862. 'g': 556,
  28863. 'h': 556,
  28864. 'i': 222,
  28865. 'j': 222,
  28866. 'k': 500,
  28867. 'l': 222,
  28868. 'm': 833,
  28869. 'n': 556,
  28870. 'o': 556,
  28871. 'p': 556,
  28872. 'q': 556,
  28873. 'r': 333,
  28874. 's': 500,
  28875. 't': 278,
  28876. 'u': 556,
  28877. 'v': 500,
  28878. 'w': 722,
  28879. 'x': 500,
  28880. 'y': 500,
  28881. 'z': 500,
  28882. 'braceleft': 334,
  28883. 'bar': 260,
  28884. 'braceright': 334,
  28885. 'asciitilde': 584,
  28886. 'exclamdown': 333,
  28887. 'cent': 556,
  28888. 'sterling': 556,
  28889. 'fraction': 167,
  28890. 'yen': 556,
  28891. 'florin': 556,
  28892. 'section': 556,
  28893. 'currency': 556,
  28894. 'quotesingle': 191,
  28895. 'quotedblleft': 333,
  28896. 'guillemotleft': 556,
  28897. 'guilsinglleft': 333,
  28898. 'guilsinglright': 333,
  28899. 'fi': 500,
  28900. 'fl': 500,
  28901. 'endash': 556,
  28902. 'dagger': 556,
  28903. 'daggerdbl': 556,
  28904. 'periodcentered': 278,
  28905. 'paragraph': 537,
  28906. 'bullet': 350,
  28907. 'quotesinglbase': 222,
  28908. 'quotedblbase': 333,
  28909. 'quotedblright': 333,
  28910. 'guillemotright': 556,
  28911. 'ellipsis': 1000,
  28912. 'perthousand': 1000,
  28913. 'questiondown': 611,
  28914. 'grave': 333,
  28915. 'acute': 333,
  28916. 'circumflex': 333,
  28917. 'tilde': 333,
  28918. 'macron': 333,
  28919. 'breve': 333,
  28920. 'dotaccent': 333,
  28921. 'dieresis': 333,
  28922. 'ring': 333,
  28923. 'cedilla': 333,
  28924. 'hungarumlaut': 333,
  28925. 'ogonek': 333,
  28926. 'caron': 333,
  28927. 'emdash': 1000,
  28928. 'AE': 1000,
  28929. 'ordfeminine': 370,
  28930. 'Lslash': 556,
  28931. 'Oslash': 778,
  28932. 'OE': 1000,
  28933. 'ordmasculine': 365,
  28934. 'ae': 889,
  28935. 'dotlessi': 278,
  28936. 'lslash': 222,
  28937. 'oslash': 611,
  28938. 'oe': 944,
  28939. 'germandbls': 611,
  28940. 'Idieresis': 278,
  28941. 'eacute': 556,
  28942. 'abreve': 556,
  28943. 'uhungarumlaut': 556,
  28944. 'ecaron': 556,
  28945. 'Ydieresis': 667,
  28946. 'divide': 584,
  28947. 'Yacute': 667,
  28948. 'Acircumflex': 667,
  28949. 'aacute': 556,
  28950. 'Ucircumflex': 722,
  28951. 'yacute': 500,
  28952. 'scommaaccent': 500,
  28953. 'ecircumflex': 556,
  28954. 'Uring': 722,
  28955. 'Udieresis': 722,
  28956. 'aogonek': 556,
  28957. 'Uacute': 722,
  28958. 'uogonek': 556,
  28959. 'Edieresis': 667,
  28960. 'Dcroat': 722,
  28961. 'commaaccent': 250,
  28962. 'copyright': 737,
  28963. 'Emacron': 667,
  28964. 'ccaron': 500,
  28965. 'aring': 556,
  28966. 'Ncommaaccent': 722,
  28967. 'lacute': 222,
  28968. 'agrave': 556,
  28969. 'Tcommaaccent': 611,
  28970. 'Cacute': 722,
  28971. 'atilde': 556,
  28972. 'Edotaccent': 667,
  28973. 'scaron': 500,
  28974. 'scedilla': 500,
  28975. 'iacute': 278,
  28976. 'lozenge': 471,
  28977. 'Rcaron': 722,
  28978. 'Gcommaaccent': 778,
  28979. 'ucircumflex': 556,
  28980. 'acircumflex': 556,
  28981. 'Amacron': 667,
  28982. 'rcaron': 333,
  28983. 'ccedilla': 500,
  28984. 'Zdotaccent': 611,
  28985. 'Thorn': 667,
  28986. 'Omacron': 778,
  28987. 'Racute': 722,
  28988. 'Sacute': 667,
  28989. 'dcaron': 643,
  28990. 'Umacron': 722,
  28991. 'uring': 556,
  28992. 'threesuperior': 333,
  28993. 'Ograve': 778,
  28994. 'Agrave': 667,
  28995. 'Abreve': 667,
  28996. 'multiply': 584,
  28997. 'uacute': 556,
  28998. 'Tcaron': 611,
  28999. 'partialdiff': 476,
  29000. 'ydieresis': 500,
  29001. 'Nacute': 722,
  29002. 'icircumflex': 278,
  29003. 'Ecircumflex': 667,
  29004. 'adieresis': 556,
  29005. 'edieresis': 556,
  29006. 'cacute': 500,
  29007. 'nacute': 556,
  29008. 'umacron': 556,
  29009. 'Ncaron': 722,
  29010. 'Iacute': 278,
  29011. 'plusminus': 584,
  29012. 'brokenbar': 260,
  29013. 'registered': 737,
  29014. 'Gbreve': 778,
  29015. 'Idotaccent': 278,
  29016. 'summation': 600,
  29017. 'Egrave': 667,
  29018. 'racute': 333,
  29019. 'omacron': 556,
  29020. 'Zacute': 611,
  29021. 'Zcaron': 611,
  29022. 'greaterequal': 549,
  29023. 'Eth': 722,
  29024. 'Ccedilla': 722,
  29025. 'lcommaaccent': 222,
  29026. 'tcaron': 317,
  29027. 'eogonek': 556,
  29028. 'Uogonek': 722,
  29029. 'Aacute': 667,
  29030. 'Adieresis': 667,
  29031. 'egrave': 556,
  29032. 'zacute': 500,
  29033. 'iogonek': 222,
  29034. 'Oacute': 778,
  29035. 'oacute': 556,
  29036. 'amacron': 556,
  29037. 'sacute': 500,
  29038. 'idieresis': 278,
  29039. 'Ocircumflex': 778,
  29040. 'Ugrave': 722,
  29041. 'Delta': 612,
  29042. 'thorn': 556,
  29043. 'twosuperior': 333,
  29044. 'Odieresis': 778,
  29045. 'mu': 556,
  29046. 'igrave': 278,
  29047. 'ohungarumlaut': 556,
  29048. 'Eogonek': 667,
  29049. 'dcroat': 556,
  29050. 'threequarters': 834,
  29051. 'Scedilla': 667,
  29052. 'lcaron': 299,
  29053. 'Kcommaaccent': 667,
  29054. 'Lacute': 556,
  29055. 'trademark': 1000,
  29056. 'edotaccent': 556,
  29057. 'Igrave': 278,
  29058. 'Imacron': 278,
  29059. 'Lcaron': 556,
  29060. 'onehalf': 834,
  29061. 'lessequal': 549,
  29062. 'ocircumflex': 556,
  29063. 'ntilde': 556,
  29064. 'Uhungarumlaut': 722,
  29065. 'Eacute': 667,
  29066. 'emacron': 556,
  29067. 'gbreve': 556,
  29068. 'onequarter': 834,
  29069. 'Scaron': 667,
  29070. 'Scommaaccent': 667,
  29071. 'Ohungarumlaut': 778,
  29072. 'degree': 400,
  29073. 'ograve': 556,
  29074. 'Ccaron': 722,
  29075. 'ugrave': 556,
  29076. 'radical': 453,
  29077. 'Dcaron': 722,
  29078. 'rcommaaccent': 333,
  29079. 'Ntilde': 722,
  29080. 'otilde': 556,
  29081. 'Rcommaaccent': 722,
  29082. 'Lcommaaccent': 556,
  29083. 'Atilde': 667,
  29084. 'Aogonek': 667,
  29085. 'Aring': 667,
  29086. 'Otilde': 778,
  29087. 'zdotaccent': 500,
  29088. 'Ecaron': 667,
  29089. 'Iogonek': 278,
  29090. 'kcommaaccent': 500,
  29091. 'minus': 584,
  29092. 'Icircumflex': 278,
  29093. 'ncaron': 556,
  29094. 'tcommaaccent': 278,
  29095. 'logicalnot': 584,
  29096. 'odieresis': 556,
  29097. 'udieresis': 556,
  29098. 'notequal': 549,
  29099. 'gcommaaccent': 556,
  29100. 'eth': 556,
  29101. 'zcaron': 500,
  29102. 'ncommaaccent': 556,
  29103. 'onesuperior': 333,
  29104. 'imacron': 278,
  29105. 'Euro': 556
  29106. },
  29107. 'Helvetica-Bold': {
  29108. 'space': 278,
  29109. 'exclam': 333,
  29110. 'quotedbl': 474,
  29111. 'numbersign': 556,
  29112. 'dollar': 556,
  29113. 'percent': 889,
  29114. 'ampersand': 722,
  29115. 'quoteright': 278,
  29116. 'parenleft': 333,
  29117. 'parenright': 333,
  29118. 'asterisk': 389,
  29119. 'plus': 584,
  29120. 'comma': 278,
  29121. 'hyphen': 333,
  29122. 'period': 278,
  29123. 'slash': 278,
  29124. 'zero': 556,
  29125. 'one': 556,
  29126. 'two': 556,
  29127. 'three': 556,
  29128. 'four': 556,
  29129. 'five': 556,
  29130. 'six': 556,
  29131. 'seven': 556,
  29132. 'eight': 556,
  29133. 'nine': 556,
  29134. 'colon': 333,
  29135. 'semicolon': 333,
  29136. 'less': 584,
  29137. 'equal': 584,
  29138. 'greater': 584,
  29139. 'question': 611,
  29140. 'at': 975,
  29141. 'A': 722,
  29142. 'B': 722,
  29143. 'C': 722,
  29144. 'D': 722,
  29145. 'E': 667,
  29146. 'F': 611,
  29147. 'G': 778,
  29148. 'H': 722,
  29149. 'I': 278,
  29150. 'J': 556,
  29151. 'K': 722,
  29152. 'L': 611,
  29153. 'M': 833,
  29154. 'N': 722,
  29155. 'O': 778,
  29156. 'P': 667,
  29157. 'Q': 778,
  29158. 'R': 722,
  29159. 'S': 667,
  29160. 'T': 611,
  29161. 'U': 722,
  29162. 'V': 667,
  29163. 'W': 944,
  29164. 'X': 667,
  29165. 'Y': 667,
  29166. 'Z': 611,
  29167. 'bracketleft': 333,
  29168. 'backslash': 278,
  29169. 'bracketright': 333,
  29170. 'asciicircum': 584,
  29171. 'underscore': 556,
  29172. 'quoteleft': 278,
  29173. 'a': 556,
  29174. 'b': 611,
  29175. 'c': 556,
  29176. 'd': 611,
  29177. 'e': 556,
  29178. 'f': 333,
  29179. 'g': 611,
  29180. 'h': 611,
  29181. 'i': 278,
  29182. 'j': 278,
  29183. 'k': 556,
  29184. 'l': 278,
  29185. 'm': 889,
  29186. 'n': 611,
  29187. 'o': 611,
  29188. 'p': 611,
  29189. 'q': 611,
  29190. 'r': 389,
  29191. 's': 556,
  29192. 't': 333,
  29193. 'u': 611,
  29194. 'v': 556,
  29195. 'w': 778,
  29196. 'x': 556,
  29197. 'y': 556,
  29198. 'z': 500,
  29199. 'braceleft': 389,
  29200. 'bar': 280,
  29201. 'braceright': 389,
  29202. 'asciitilde': 584,
  29203. 'exclamdown': 333,
  29204. 'cent': 556,
  29205. 'sterling': 556,
  29206. 'fraction': 167,
  29207. 'yen': 556,
  29208. 'florin': 556,
  29209. 'section': 556,
  29210. 'currency': 556,
  29211. 'quotesingle': 238,
  29212. 'quotedblleft': 500,
  29213. 'guillemotleft': 556,
  29214. 'guilsinglleft': 333,
  29215. 'guilsinglright': 333,
  29216. 'fi': 611,
  29217. 'fl': 611,
  29218. 'endash': 556,
  29219. 'dagger': 556,
  29220. 'daggerdbl': 556,
  29221. 'periodcentered': 278,
  29222. 'paragraph': 556,
  29223. 'bullet': 350,
  29224. 'quotesinglbase': 278,
  29225. 'quotedblbase': 500,
  29226. 'quotedblright': 500,
  29227. 'guillemotright': 556,
  29228. 'ellipsis': 1000,
  29229. 'perthousand': 1000,
  29230. 'questiondown': 611,
  29231. 'grave': 333,
  29232. 'acute': 333,
  29233. 'circumflex': 333,
  29234. 'tilde': 333,
  29235. 'macron': 333,
  29236. 'breve': 333,
  29237. 'dotaccent': 333,
  29238. 'dieresis': 333,
  29239. 'ring': 333,
  29240. 'cedilla': 333,
  29241. 'hungarumlaut': 333,
  29242. 'ogonek': 333,
  29243. 'caron': 333,
  29244. 'emdash': 1000,
  29245. 'AE': 1000,
  29246. 'ordfeminine': 370,
  29247. 'Lslash': 611,
  29248. 'Oslash': 778,
  29249. 'OE': 1000,
  29250. 'ordmasculine': 365,
  29251. 'ae': 889,
  29252. 'dotlessi': 278,
  29253. 'lslash': 278,
  29254. 'oslash': 611,
  29255. 'oe': 944,
  29256. 'germandbls': 611,
  29257. 'Idieresis': 278,
  29258. 'eacute': 556,
  29259. 'abreve': 556,
  29260. 'uhungarumlaut': 611,
  29261. 'ecaron': 556,
  29262. 'Ydieresis': 667,
  29263. 'divide': 584,
  29264. 'Yacute': 667,
  29265. 'Acircumflex': 722,
  29266. 'aacute': 556,
  29267. 'Ucircumflex': 722,
  29268. 'yacute': 556,
  29269. 'scommaaccent': 556,
  29270. 'ecircumflex': 556,
  29271. 'Uring': 722,
  29272. 'Udieresis': 722,
  29273. 'aogonek': 556,
  29274. 'Uacute': 722,
  29275. 'uogonek': 611,
  29276. 'Edieresis': 667,
  29277. 'Dcroat': 722,
  29278. 'commaaccent': 250,
  29279. 'copyright': 737,
  29280. 'Emacron': 667,
  29281. 'ccaron': 556,
  29282. 'aring': 556,
  29283. 'Ncommaaccent': 722,
  29284. 'lacute': 278,
  29285. 'agrave': 556,
  29286. 'Tcommaaccent': 611,
  29287. 'Cacute': 722,
  29288. 'atilde': 556,
  29289. 'Edotaccent': 667,
  29290. 'scaron': 556,
  29291. 'scedilla': 556,
  29292. 'iacute': 278,
  29293. 'lozenge': 494,
  29294. 'Rcaron': 722,
  29295. 'Gcommaaccent': 778,
  29296. 'ucircumflex': 611,
  29297. 'acircumflex': 556,
  29298. 'Amacron': 722,
  29299. 'rcaron': 389,
  29300. 'ccedilla': 556,
  29301. 'Zdotaccent': 611,
  29302. 'Thorn': 667,
  29303. 'Omacron': 778,
  29304. 'Racute': 722,
  29305. 'Sacute': 667,
  29306. 'dcaron': 743,
  29307. 'Umacron': 722,
  29308. 'uring': 611,
  29309. 'threesuperior': 333,
  29310. 'Ograve': 778,
  29311. 'Agrave': 722,
  29312. 'Abreve': 722,
  29313. 'multiply': 584,
  29314. 'uacute': 611,
  29315. 'Tcaron': 611,
  29316. 'partialdiff': 494,
  29317. 'ydieresis': 556,
  29318. 'Nacute': 722,
  29319. 'icircumflex': 278,
  29320. 'Ecircumflex': 667,
  29321. 'adieresis': 556,
  29322. 'edieresis': 556,
  29323. 'cacute': 556,
  29324. 'nacute': 611,
  29325. 'umacron': 611,
  29326. 'Ncaron': 722,
  29327. 'Iacute': 278,
  29328. 'plusminus': 584,
  29329. 'brokenbar': 280,
  29330. 'registered': 737,
  29331. 'Gbreve': 778,
  29332. 'Idotaccent': 278,
  29333. 'summation': 600,
  29334. 'Egrave': 667,
  29335. 'racute': 389,
  29336. 'omacron': 611,
  29337. 'Zacute': 611,
  29338. 'Zcaron': 611,
  29339. 'greaterequal': 549,
  29340. 'Eth': 722,
  29341. 'Ccedilla': 722,
  29342. 'lcommaaccent': 278,
  29343. 'tcaron': 389,
  29344. 'eogonek': 556,
  29345. 'Uogonek': 722,
  29346. 'Aacute': 722,
  29347. 'Adieresis': 722,
  29348. 'egrave': 556,
  29349. 'zacute': 500,
  29350. 'iogonek': 278,
  29351. 'Oacute': 778,
  29352. 'oacute': 611,
  29353. 'amacron': 556,
  29354. 'sacute': 556,
  29355. 'idieresis': 278,
  29356. 'Ocircumflex': 778,
  29357. 'Ugrave': 722,
  29358. 'Delta': 612,
  29359. 'thorn': 611,
  29360. 'twosuperior': 333,
  29361. 'Odieresis': 778,
  29362. 'mu': 611,
  29363. 'igrave': 278,
  29364. 'ohungarumlaut': 611,
  29365. 'Eogonek': 667,
  29366. 'dcroat': 611,
  29367. 'threequarters': 834,
  29368. 'Scedilla': 667,
  29369. 'lcaron': 400,
  29370. 'Kcommaaccent': 722,
  29371. 'Lacute': 611,
  29372. 'trademark': 1000,
  29373. 'edotaccent': 556,
  29374. 'Igrave': 278,
  29375. 'Imacron': 278,
  29376. 'Lcaron': 611,
  29377. 'onehalf': 834,
  29378. 'lessequal': 549,
  29379. 'ocircumflex': 611,
  29380. 'ntilde': 611,
  29381. 'Uhungarumlaut': 722,
  29382. 'Eacute': 667,
  29383. 'emacron': 556,
  29384. 'gbreve': 611,
  29385. 'onequarter': 834,
  29386. 'Scaron': 667,
  29387. 'Scommaaccent': 667,
  29388. 'Ohungarumlaut': 778,
  29389. 'degree': 400,
  29390. 'ograve': 611,
  29391. 'Ccaron': 722,
  29392. 'ugrave': 611,
  29393. 'radical': 549,
  29394. 'Dcaron': 722,
  29395. 'rcommaaccent': 389,
  29396. 'Ntilde': 722,
  29397. 'otilde': 611,
  29398. 'Rcommaaccent': 722,
  29399. 'Lcommaaccent': 611,
  29400. 'Atilde': 722,
  29401. 'Aogonek': 722,
  29402. 'Aring': 722,
  29403. 'Otilde': 778,
  29404. 'zdotaccent': 500,
  29405. 'Ecaron': 667,
  29406. 'Iogonek': 278,
  29407. 'kcommaaccent': 556,
  29408. 'minus': 584,
  29409. 'Icircumflex': 278,
  29410. 'ncaron': 611,
  29411. 'tcommaaccent': 333,
  29412. 'logicalnot': 584,
  29413. 'odieresis': 611,
  29414. 'udieresis': 611,
  29415. 'notequal': 549,
  29416. 'gcommaaccent': 611,
  29417. 'eth': 611,
  29418. 'zcaron': 500,
  29419. 'ncommaaccent': 611,
  29420. 'onesuperior': 333,
  29421. 'imacron': 278,
  29422. 'Euro': 556
  29423. },
  29424. 'Helvetica-BoldOblique': {
  29425. 'space': 278,
  29426. 'exclam': 333,
  29427. 'quotedbl': 474,
  29428. 'numbersign': 556,
  29429. 'dollar': 556,
  29430. 'percent': 889,
  29431. 'ampersand': 722,
  29432. 'quoteright': 278,
  29433. 'parenleft': 333,
  29434. 'parenright': 333,
  29435. 'asterisk': 389,
  29436. 'plus': 584,
  29437. 'comma': 278,
  29438. 'hyphen': 333,
  29439. 'period': 278,
  29440. 'slash': 278,
  29441. 'zero': 556,
  29442. 'one': 556,
  29443. 'two': 556,
  29444. 'three': 556,
  29445. 'four': 556,
  29446. 'five': 556,
  29447. 'six': 556,
  29448. 'seven': 556,
  29449. 'eight': 556,
  29450. 'nine': 556,
  29451. 'colon': 333,
  29452. 'semicolon': 333,
  29453. 'less': 584,
  29454. 'equal': 584,
  29455. 'greater': 584,
  29456. 'question': 611,
  29457. 'at': 975,
  29458. 'A': 722,
  29459. 'B': 722,
  29460. 'C': 722,
  29461. 'D': 722,
  29462. 'E': 667,
  29463. 'F': 611,
  29464. 'G': 778,
  29465. 'H': 722,
  29466. 'I': 278,
  29467. 'J': 556,
  29468. 'K': 722,
  29469. 'L': 611,
  29470. 'M': 833,
  29471. 'N': 722,
  29472. 'O': 778,
  29473. 'P': 667,
  29474. 'Q': 778,
  29475. 'R': 722,
  29476. 'S': 667,
  29477. 'T': 611,
  29478. 'U': 722,
  29479. 'V': 667,
  29480. 'W': 944,
  29481. 'X': 667,
  29482. 'Y': 667,
  29483. 'Z': 611,
  29484. 'bracketleft': 333,
  29485. 'backslash': 278,
  29486. 'bracketright': 333,
  29487. 'asciicircum': 584,
  29488. 'underscore': 556,
  29489. 'quoteleft': 278,
  29490. 'a': 556,
  29491. 'b': 611,
  29492. 'c': 556,
  29493. 'd': 611,
  29494. 'e': 556,
  29495. 'f': 333,
  29496. 'g': 611,
  29497. 'h': 611,
  29498. 'i': 278,
  29499. 'j': 278,
  29500. 'k': 556,
  29501. 'l': 278,
  29502. 'm': 889,
  29503. 'n': 611,
  29504. 'o': 611,
  29505. 'p': 611,
  29506. 'q': 611,
  29507. 'r': 389,
  29508. 's': 556,
  29509. 't': 333,
  29510. 'u': 611,
  29511. 'v': 556,
  29512. 'w': 778,
  29513. 'x': 556,
  29514. 'y': 556,
  29515. 'z': 500,
  29516. 'braceleft': 389,
  29517. 'bar': 280,
  29518. 'braceright': 389,
  29519. 'asciitilde': 584,
  29520. 'exclamdown': 333,
  29521. 'cent': 556,
  29522. 'sterling': 556,
  29523. 'fraction': 167,
  29524. 'yen': 556,
  29525. 'florin': 556,
  29526. 'section': 556,
  29527. 'currency': 556,
  29528. 'quotesingle': 238,
  29529. 'quotedblleft': 500,
  29530. 'guillemotleft': 556,
  29531. 'guilsinglleft': 333,
  29532. 'guilsinglright': 333,
  29533. 'fi': 611,
  29534. 'fl': 611,
  29535. 'endash': 556,
  29536. 'dagger': 556,
  29537. 'daggerdbl': 556,
  29538. 'periodcentered': 278,
  29539. 'paragraph': 556,
  29540. 'bullet': 350,
  29541. 'quotesinglbase': 278,
  29542. 'quotedblbase': 500,
  29543. 'quotedblright': 500,
  29544. 'guillemotright': 556,
  29545. 'ellipsis': 1000,
  29546. 'perthousand': 1000,
  29547. 'questiondown': 611,
  29548. 'grave': 333,
  29549. 'acute': 333,
  29550. 'circumflex': 333,
  29551. 'tilde': 333,
  29552. 'macron': 333,
  29553. 'breve': 333,
  29554. 'dotaccent': 333,
  29555. 'dieresis': 333,
  29556. 'ring': 333,
  29557. 'cedilla': 333,
  29558. 'hungarumlaut': 333,
  29559. 'ogonek': 333,
  29560. 'caron': 333,
  29561. 'emdash': 1000,
  29562. 'AE': 1000,
  29563. 'ordfeminine': 370,
  29564. 'Lslash': 611,
  29565. 'Oslash': 778,
  29566. 'OE': 1000,
  29567. 'ordmasculine': 365,
  29568. 'ae': 889,
  29569. 'dotlessi': 278,
  29570. 'lslash': 278,
  29571. 'oslash': 611,
  29572. 'oe': 944,
  29573. 'germandbls': 611,
  29574. 'Idieresis': 278,
  29575. 'eacute': 556,
  29576. 'abreve': 556,
  29577. 'uhungarumlaut': 611,
  29578. 'ecaron': 556,
  29579. 'Ydieresis': 667,
  29580. 'divide': 584,
  29581. 'Yacute': 667,
  29582. 'Acircumflex': 722,
  29583. 'aacute': 556,
  29584. 'Ucircumflex': 722,
  29585. 'yacute': 556,
  29586. 'scommaaccent': 556,
  29587. 'ecircumflex': 556,
  29588. 'Uring': 722,
  29589. 'Udieresis': 722,
  29590. 'aogonek': 556,
  29591. 'Uacute': 722,
  29592. 'uogonek': 611,
  29593. 'Edieresis': 667,
  29594. 'Dcroat': 722,
  29595. 'commaaccent': 250,
  29596. 'copyright': 737,
  29597. 'Emacron': 667,
  29598. 'ccaron': 556,
  29599. 'aring': 556,
  29600. 'Ncommaaccent': 722,
  29601. 'lacute': 278,
  29602. 'agrave': 556,
  29603. 'Tcommaaccent': 611,
  29604. 'Cacute': 722,
  29605. 'atilde': 556,
  29606. 'Edotaccent': 667,
  29607. 'scaron': 556,
  29608. 'scedilla': 556,
  29609. 'iacute': 278,
  29610. 'lozenge': 494,
  29611. 'Rcaron': 722,
  29612. 'Gcommaaccent': 778,
  29613. 'ucircumflex': 611,
  29614. 'acircumflex': 556,
  29615. 'Amacron': 722,
  29616. 'rcaron': 389,
  29617. 'ccedilla': 556,
  29618. 'Zdotaccent': 611,
  29619. 'Thorn': 667,
  29620. 'Omacron': 778,
  29621. 'Racute': 722,
  29622. 'Sacute': 667,
  29623. 'dcaron': 743,
  29624. 'Umacron': 722,
  29625. 'uring': 611,
  29626. 'threesuperior': 333,
  29627. 'Ograve': 778,
  29628. 'Agrave': 722,
  29629. 'Abreve': 722,
  29630. 'multiply': 584,
  29631. 'uacute': 611,
  29632. 'Tcaron': 611,
  29633. 'partialdiff': 494,
  29634. 'ydieresis': 556,
  29635. 'Nacute': 722,
  29636. 'icircumflex': 278,
  29637. 'Ecircumflex': 667,
  29638. 'adieresis': 556,
  29639. 'edieresis': 556,
  29640. 'cacute': 556,
  29641. 'nacute': 611,
  29642. 'umacron': 611,
  29643. 'Ncaron': 722,
  29644. 'Iacute': 278,
  29645. 'plusminus': 584,
  29646. 'brokenbar': 280,
  29647. 'registered': 737,
  29648. 'Gbreve': 778,
  29649. 'Idotaccent': 278,
  29650. 'summation': 600,
  29651. 'Egrave': 667,
  29652. 'racute': 389,
  29653. 'omacron': 611,
  29654. 'Zacute': 611,
  29655. 'Zcaron': 611,
  29656. 'greaterequal': 549,
  29657. 'Eth': 722,
  29658. 'Ccedilla': 722,
  29659. 'lcommaaccent': 278,
  29660. 'tcaron': 389,
  29661. 'eogonek': 556,
  29662. 'Uogonek': 722,
  29663. 'Aacute': 722,
  29664. 'Adieresis': 722,
  29665. 'egrave': 556,
  29666. 'zacute': 500,
  29667. 'iogonek': 278,
  29668. 'Oacute': 778,
  29669. 'oacute': 611,
  29670. 'amacron': 556,
  29671. 'sacute': 556,
  29672. 'idieresis': 278,
  29673. 'Ocircumflex': 778,
  29674. 'Ugrave': 722,
  29675. 'Delta': 612,
  29676. 'thorn': 611,
  29677. 'twosuperior': 333,
  29678. 'Odieresis': 778,
  29679. 'mu': 611,
  29680. 'igrave': 278,
  29681. 'ohungarumlaut': 611,
  29682. 'Eogonek': 667,
  29683. 'dcroat': 611,
  29684. 'threequarters': 834,
  29685. 'Scedilla': 667,
  29686. 'lcaron': 400,
  29687. 'Kcommaaccent': 722,
  29688. 'Lacute': 611,
  29689. 'trademark': 1000,
  29690. 'edotaccent': 556,
  29691. 'Igrave': 278,
  29692. 'Imacron': 278,
  29693. 'Lcaron': 611,
  29694. 'onehalf': 834,
  29695. 'lessequal': 549,
  29696. 'ocircumflex': 611,
  29697. 'ntilde': 611,
  29698. 'Uhungarumlaut': 722,
  29699. 'Eacute': 667,
  29700. 'emacron': 556,
  29701. 'gbreve': 611,
  29702. 'onequarter': 834,
  29703. 'Scaron': 667,
  29704. 'Scommaaccent': 667,
  29705. 'Ohungarumlaut': 778,
  29706. 'degree': 400,
  29707. 'ograve': 611,
  29708. 'Ccaron': 722,
  29709. 'ugrave': 611,
  29710. 'radical': 549,
  29711. 'Dcaron': 722,
  29712. 'rcommaaccent': 389,
  29713. 'Ntilde': 722,
  29714. 'otilde': 611,
  29715. 'Rcommaaccent': 722,
  29716. 'Lcommaaccent': 611,
  29717. 'Atilde': 722,
  29718. 'Aogonek': 722,
  29719. 'Aring': 722,
  29720. 'Otilde': 778,
  29721. 'zdotaccent': 500,
  29722. 'Ecaron': 667,
  29723. 'Iogonek': 278,
  29724. 'kcommaaccent': 556,
  29725. 'minus': 584,
  29726. 'Icircumflex': 278,
  29727. 'ncaron': 611,
  29728. 'tcommaaccent': 333,
  29729. 'logicalnot': 584,
  29730. 'odieresis': 611,
  29731. 'udieresis': 611,
  29732. 'notequal': 549,
  29733. 'gcommaaccent': 611,
  29734. 'eth': 611,
  29735. 'zcaron': 500,
  29736. 'ncommaaccent': 611,
  29737. 'onesuperior': 333,
  29738. 'imacron': 278,
  29739. 'Euro': 556
  29740. },
  29741. 'Helvetica-Oblique' : {
  29742. 'space': 278,
  29743. 'exclam': 278,
  29744. 'quotedbl': 355,
  29745. 'numbersign': 556,
  29746. 'dollar': 556,
  29747. 'percent': 889,
  29748. 'ampersand': 667,
  29749. 'quoteright': 222,
  29750. 'parenleft': 333,
  29751. 'parenright': 333,
  29752. 'asterisk': 389,
  29753. 'plus': 584,
  29754. 'comma': 278,
  29755. 'hyphen': 333,
  29756. 'period': 278,
  29757. 'slash': 278,
  29758. 'zero': 556,
  29759. 'one': 556,
  29760. 'two': 556,
  29761. 'three': 556,
  29762. 'four': 556,
  29763. 'five': 556,
  29764. 'six': 556,
  29765. 'seven': 556,
  29766. 'eight': 556,
  29767. 'nine': 556,
  29768. 'colon': 278,
  29769. 'semicolon': 278,
  29770. 'less': 584,
  29771. 'equal': 584,
  29772. 'greater': 584,
  29773. 'question': 556,
  29774. 'at': 1015,
  29775. 'A': 667,
  29776. 'B': 667,
  29777. 'C': 722,
  29778. 'D': 722,
  29779. 'E': 667,
  29780. 'F': 611,
  29781. 'G': 778,
  29782. 'H': 722,
  29783. 'I': 278,
  29784. 'J': 500,
  29785. 'K': 667,
  29786. 'L': 556,
  29787. 'M': 833,
  29788. 'N': 722,
  29789. 'O': 778,
  29790. 'P': 667,
  29791. 'Q': 778,
  29792. 'R': 722,
  29793. 'S': 667,
  29794. 'T': 611,
  29795. 'U': 722,
  29796. 'V': 667,
  29797. 'W': 944,
  29798. 'X': 667,
  29799. 'Y': 667,
  29800. 'Z': 611,
  29801. 'bracketleft': 278,
  29802. 'backslash': 278,
  29803. 'bracketright': 278,
  29804. 'asciicircum': 469,
  29805. 'underscore': 556,
  29806. 'quoteleft': 222,
  29807. 'a': 556,
  29808. 'b': 556,
  29809. 'c': 500,
  29810. 'd': 556,
  29811. 'e': 556,
  29812. 'f': 278,
  29813. 'g': 556,
  29814. 'h': 556,
  29815. 'i': 222,
  29816. 'j': 222,
  29817. 'k': 500,
  29818. 'l': 222,
  29819. 'm': 833,
  29820. 'n': 556,
  29821. 'o': 556,
  29822. 'p': 556,
  29823. 'q': 556,
  29824. 'r': 333,
  29825. 's': 500,
  29826. 't': 278,
  29827. 'u': 556,
  29828. 'v': 500,
  29829. 'w': 722,
  29830. 'x': 500,
  29831. 'y': 500,
  29832. 'z': 500,
  29833. 'braceleft': 334,
  29834. 'bar': 260,
  29835. 'braceright': 334,
  29836. 'asciitilde': 584,
  29837. 'exclamdown': 333,
  29838. 'cent': 556,
  29839. 'sterling': 556,
  29840. 'fraction': 167,
  29841. 'yen': 556,
  29842. 'florin': 556,
  29843. 'section': 556,
  29844. 'currency': 556,
  29845. 'quotesingle': 191,
  29846. 'quotedblleft': 333,
  29847. 'guillemotleft': 556,
  29848. 'guilsinglleft': 333,
  29849. 'guilsinglright': 333,
  29850. 'fi': 500,
  29851. 'fl': 500,
  29852. 'endash': 556,
  29853. 'dagger': 556,
  29854. 'daggerdbl': 556,
  29855. 'periodcentered': 278,
  29856. 'paragraph': 537,
  29857. 'bullet': 350,
  29858. 'quotesinglbase': 222,
  29859. 'quotedblbase': 333,
  29860. 'quotedblright': 333,
  29861. 'guillemotright': 556,
  29862. 'ellipsis': 1000,
  29863. 'perthousand': 1000,
  29864. 'questiondown': 611,
  29865. 'grave': 333,
  29866. 'acute': 333,
  29867. 'circumflex': 333,
  29868. 'tilde': 333,
  29869. 'macron': 333,
  29870. 'breve': 333,
  29871. 'dotaccent': 333,
  29872. 'dieresis': 333,
  29873. 'ring': 333,
  29874. 'cedilla': 333,
  29875. 'hungarumlaut': 333,
  29876. 'ogonek': 333,
  29877. 'caron': 333,
  29878. 'emdash': 1000,
  29879. 'AE': 1000,
  29880. 'ordfeminine': 370,
  29881. 'Lslash': 556,
  29882. 'Oslash': 778,
  29883. 'OE': 1000,
  29884. 'ordmasculine': 365,
  29885. 'ae': 889,
  29886. 'dotlessi': 278,
  29887. 'lslash': 222,
  29888. 'oslash': 611,
  29889. 'oe': 944,
  29890. 'germandbls': 611,
  29891. 'Idieresis': 278,
  29892. 'eacute': 556,
  29893. 'abreve': 556,
  29894. 'uhungarumlaut': 556,
  29895. 'ecaron': 556,
  29896. 'Ydieresis': 667,
  29897. 'divide': 584,
  29898. 'Yacute': 667,
  29899. 'Acircumflex': 667,
  29900. 'aacute': 556,
  29901. 'Ucircumflex': 722,
  29902. 'yacute': 500,
  29903. 'scommaaccent': 500,
  29904. 'ecircumflex': 556,
  29905. 'Uring': 722,
  29906. 'Udieresis': 722,
  29907. 'aogonek': 556,
  29908. 'Uacute': 722,
  29909. 'uogonek': 556,
  29910. 'Edieresis': 667,
  29911. 'Dcroat': 722,
  29912. 'commaaccent': 250,
  29913. 'copyright': 737,
  29914. 'Emacron': 667,
  29915. 'ccaron': 500,
  29916. 'aring': 556,
  29917. 'Ncommaaccent': 722,
  29918. 'lacute': 222,
  29919. 'agrave': 556,
  29920. 'Tcommaaccent': 611,
  29921. 'Cacute': 722,
  29922. 'atilde': 556,
  29923. 'Edotaccent': 667,
  29924. 'scaron': 500,
  29925. 'scedilla': 500,
  29926. 'iacute': 278,
  29927. 'lozenge': 471,
  29928. 'Rcaron': 722,
  29929. 'Gcommaaccent': 778,
  29930. 'ucircumflex': 556,
  29931. 'acircumflex': 556,
  29932. 'Amacron': 667,
  29933. 'rcaron': 333,
  29934. 'ccedilla': 500,
  29935. 'Zdotaccent': 611,
  29936. 'Thorn': 667,
  29937. 'Omacron': 778,
  29938. 'Racute': 722,
  29939. 'Sacute': 667,
  29940. 'dcaron': 643,
  29941. 'Umacron': 722,
  29942. 'uring': 556,
  29943. 'threesuperior': 333,
  29944. 'Ograve': 778,
  29945. 'Agrave': 667,
  29946. 'Abreve': 667,
  29947. 'multiply': 584,
  29948. 'uacute': 556,
  29949. 'Tcaron': 611,
  29950. 'partialdiff': 476,
  29951. 'ydieresis': 500,
  29952. 'Nacute': 722,
  29953. 'icircumflex': 278,
  29954. 'Ecircumflex': 667,
  29955. 'adieresis': 556,
  29956. 'edieresis': 556,
  29957. 'cacute': 500,
  29958. 'nacute': 556,
  29959. 'umacron': 556,
  29960. 'Ncaron': 722,
  29961. 'Iacute': 278,
  29962. 'plusminus': 584,
  29963. 'brokenbar': 260,
  29964. 'registered': 737,
  29965. 'Gbreve': 778,
  29966. 'Idotaccent': 278,
  29967. 'summation': 600,
  29968. 'Egrave': 667,
  29969. 'racute': 333,
  29970. 'omacron': 556,
  29971. 'Zacute': 611,
  29972. 'Zcaron': 611,
  29973. 'greaterequal': 549,
  29974. 'Eth': 722,
  29975. 'Ccedilla': 722,
  29976. 'lcommaaccent': 222,
  29977. 'tcaron': 317,
  29978. 'eogonek': 556,
  29979. 'Uogonek': 722,
  29980. 'Aacute': 667,
  29981. 'Adieresis': 667,
  29982. 'egrave': 556,
  29983. 'zacute': 500,
  29984. 'iogonek': 222,
  29985. 'Oacute': 778,
  29986. 'oacute': 556,
  29987. 'amacron': 556,
  29988. 'sacute': 500,
  29989. 'idieresis': 278,
  29990. 'Ocircumflex': 778,
  29991. 'Ugrave': 722,
  29992. 'Delta': 612,
  29993. 'thorn': 556,
  29994. 'twosuperior': 333,
  29995. 'Odieresis': 778,
  29996. 'mu': 556,
  29997. 'igrave': 278,
  29998. 'ohungarumlaut': 556,
  29999. 'Eogonek': 667,
  30000. 'dcroat': 556,
  30001. 'threequarters': 834,
  30002. 'Scedilla': 667,
  30003. 'lcaron': 299,
  30004. 'Kcommaaccent': 667,
  30005. 'Lacute': 556,
  30006. 'trademark': 1000,
  30007. 'edotaccent': 556,
  30008. 'Igrave': 278,
  30009. 'Imacron': 278,
  30010. 'Lcaron': 556,
  30011. 'onehalf': 834,
  30012. 'lessequal': 549,
  30013. 'ocircumflex': 556,
  30014. 'ntilde': 556,
  30015. 'Uhungarumlaut': 722,
  30016. 'Eacute': 667,
  30017. 'emacron': 556,
  30018. 'gbreve': 556,
  30019. 'onequarter': 834,
  30020. 'Scaron': 667,
  30021. 'Scommaaccent': 667,
  30022. 'Ohungarumlaut': 778,
  30023. 'degree': 400,
  30024. 'ograve': 556,
  30025. 'Ccaron': 722,
  30026. 'ugrave': 556,
  30027. 'radical': 453,
  30028. 'Dcaron': 722,
  30029. 'rcommaaccent': 333,
  30030. 'Ntilde': 722,
  30031. 'otilde': 556,
  30032. 'Rcommaaccent': 722,
  30033. 'Lcommaaccent': 556,
  30034. 'Atilde': 667,
  30035. 'Aogonek': 667,
  30036. 'Aring': 667,
  30037. 'Otilde': 778,
  30038. 'zdotaccent': 500,
  30039. 'Ecaron': 667,
  30040. 'Iogonek': 278,
  30041. 'kcommaaccent': 500,
  30042. 'minus': 584,
  30043. 'Icircumflex': 278,
  30044. 'ncaron': 556,
  30045. 'tcommaaccent': 278,
  30046. 'logicalnot': 584,
  30047. 'odieresis': 556,
  30048. 'udieresis': 556,
  30049. 'notequal': 549,
  30050. 'gcommaaccent': 556,
  30051. 'eth': 556,
  30052. 'zcaron': 500,
  30053. 'ncommaaccent': 556,
  30054. 'onesuperior': 333,
  30055. 'imacron': 278,
  30056. 'Euro': 556
  30057. },
  30058. 'Symbol': {
  30059. 'space': 250,
  30060. 'exclam': 333,
  30061. 'universal': 713,
  30062. 'numbersign': 500,
  30063. 'existential': 549,
  30064. 'percent': 833,
  30065. 'ampersand': 778,
  30066. 'suchthat': 439,
  30067. 'parenleft': 333,
  30068. 'parenright': 333,
  30069. 'asteriskmath': 500,
  30070. 'plus': 549,
  30071. 'comma': 250,
  30072. 'minus': 549,
  30073. 'period': 250,
  30074. 'slash': 278,
  30075. 'zero': 500,
  30076. 'one': 500,
  30077. 'two': 500,
  30078. 'three': 500,
  30079. 'four': 500,
  30080. 'five': 500,
  30081. 'six': 500,
  30082. 'seven': 500,
  30083. 'eight': 500,
  30084. 'nine': 500,
  30085. 'colon': 278,
  30086. 'semicolon': 278,
  30087. 'less': 549,
  30088. 'equal': 549,
  30089. 'greater': 549,
  30090. 'question': 444,
  30091. 'congruent': 549,
  30092. 'Alpha': 722,
  30093. 'Beta': 667,
  30094. 'Chi': 722,
  30095. 'Delta': 612,
  30096. 'Epsilon': 611,
  30097. 'Phi': 763,
  30098. 'Gamma': 603,
  30099. 'Eta': 722,
  30100. 'Iota': 333,
  30101. 'theta1': 631,
  30102. 'Kappa': 722,
  30103. 'Lambda': 686,
  30104. 'Mu': 889,
  30105. 'Nu': 722,
  30106. 'Omicron': 722,
  30107. 'Pi': 768,
  30108. 'Theta': 741,
  30109. 'Rho': 556,
  30110. 'Sigma': 592,
  30111. 'Tau': 611,
  30112. 'Upsilon': 690,
  30113. 'sigma1': 439,
  30114. 'Omega': 768,
  30115. 'Xi': 645,
  30116. 'Psi': 795,
  30117. 'Zeta': 611,
  30118. 'bracketleft': 333,
  30119. 'therefore': 863,
  30120. 'bracketright': 333,
  30121. 'perpendicular': 658,
  30122. 'underscore': 500,
  30123. 'radicalex': 500,
  30124. 'alpha': 631,
  30125. 'beta': 549,
  30126. 'chi': 549,
  30127. 'delta': 494,
  30128. 'epsilon': 439,
  30129. 'phi': 521,
  30130. 'gamma': 411,
  30131. 'eta': 603,
  30132. 'iota': 329,
  30133. 'phi1': 603,
  30134. 'kappa': 549,
  30135. 'lambda': 549,
  30136. 'mu': 576,
  30137. 'nu': 521,
  30138. 'omicron': 549,
  30139. 'pi': 549,
  30140. 'theta': 521,
  30141. 'rho': 549,
  30142. 'sigma': 603,
  30143. 'tau': 439,
  30144. 'upsilon': 576,
  30145. 'omega1': 713,
  30146. 'omega': 686,
  30147. 'xi': 493,
  30148. 'psi': 686,
  30149. 'zeta': 494,
  30150. 'braceleft': 480,
  30151. 'bar': 200,
  30152. 'braceright': 480,
  30153. 'similar': 549,
  30154. 'Euro': 750,
  30155. 'Upsilon1': 620,
  30156. 'minute': 247,
  30157. 'lessequal': 549,
  30158. 'fraction': 167,
  30159. 'infinity': 713,
  30160. 'florin': 500,
  30161. 'club': 753,
  30162. 'diamond': 753,
  30163. 'heart': 753,
  30164. 'spade': 753,
  30165. 'arrowboth': 1042,
  30166. 'arrowleft': 987,
  30167. 'arrowup': 603,
  30168. 'arrowright': 987,
  30169. 'arrowdown': 603,
  30170. 'degree': 400,
  30171. 'plusminus': 549,
  30172. 'second': 411,
  30173. 'greaterequal': 549,
  30174. 'multiply': 549,
  30175. 'proportional': 713,
  30176. 'partialdiff': 494,
  30177. 'bullet': 460,
  30178. 'divide': 549,
  30179. 'notequal': 549,
  30180. 'equivalence': 549,
  30181. 'approxequal': 549,
  30182. 'ellipsis': 1000,
  30183. 'arrowvertex': 603,
  30184. 'arrowhorizex': 1000,
  30185. 'carriagereturn': 658,
  30186. 'aleph': 823,
  30187. 'Ifraktur': 686,
  30188. 'Rfraktur': 795,
  30189. 'weierstrass': 987,
  30190. 'circlemultiply': 768,
  30191. 'circleplus': 768,
  30192. 'emptyset': 823,
  30193. 'intersection': 768,
  30194. 'union': 768,
  30195. 'propersuperset': 713,
  30196. 'reflexsuperset': 713,
  30197. 'notsubset': 713,
  30198. 'propersubset': 713,
  30199. 'reflexsubset': 713,
  30200. 'element': 713,
  30201. 'notelement': 713,
  30202. 'angle': 768,
  30203. 'gradient': 713,
  30204. 'registerserif': 790,
  30205. 'copyrightserif': 790,
  30206. 'trademarkserif': 890,
  30207. 'product': 823,
  30208. 'radical': 549,
  30209. 'dotmath': 250,
  30210. 'logicalnot': 713,
  30211. 'logicaland': 603,
  30212. 'logicalor': 603,
  30213. 'arrowdblboth': 1042,
  30214. 'arrowdblleft': 987,
  30215. 'arrowdblup': 603,
  30216. 'arrowdblright': 987,
  30217. 'arrowdbldown': 603,
  30218. 'lozenge': 494,
  30219. 'angleleft': 329,
  30220. 'registersans': 790,
  30221. 'copyrightsans': 790,
  30222. 'trademarksans': 786,
  30223. 'summation': 713,
  30224. 'parenlefttp': 384,
  30225. 'parenleftex': 384,
  30226. 'parenleftbt': 384,
  30227. 'bracketlefttp': 384,
  30228. 'bracketleftex': 384,
  30229. 'bracketleftbt': 384,
  30230. 'bracelefttp': 494,
  30231. 'braceleftmid': 494,
  30232. 'braceleftbt': 494,
  30233. 'braceex': 494,
  30234. 'angleright': 329,
  30235. 'integral': 274,
  30236. 'integraltp': 686,
  30237. 'integralex': 686,
  30238. 'integralbt': 686,
  30239. 'parenrighttp': 384,
  30240. 'parenrightex': 384,
  30241. 'parenrightbt': 384,
  30242. 'bracketrighttp': 384,
  30243. 'bracketrightex': 384,
  30244. 'bracketrightbt': 384,
  30245. 'bracerighttp': 494,
  30246. 'bracerightmid': 494,
  30247. 'bracerightbt': 494,
  30248. 'apple': 790
  30249. },
  30250. 'Times-Roman': {
  30251. 'space': 250,
  30252. 'exclam': 333,
  30253. 'quotedbl': 408,
  30254. 'numbersign': 500,
  30255. 'dollar': 500,
  30256. 'percent': 833,
  30257. 'ampersand': 778,
  30258. 'quoteright': 333,
  30259. 'parenleft': 333,
  30260. 'parenright': 333,
  30261. 'asterisk': 500,
  30262. 'plus': 564,
  30263. 'comma': 250,
  30264. 'hyphen': 333,
  30265. 'period': 250,
  30266. 'slash': 278,
  30267. 'zero': 500,
  30268. 'one': 500,
  30269. 'two': 500,
  30270. 'three': 500,
  30271. 'four': 500,
  30272. 'five': 500,
  30273. 'six': 500,
  30274. 'seven': 500,
  30275. 'eight': 500,
  30276. 'nine': 500,
  30277. 'colon': 278,
  30278. 'semicolon': 278,
  30279. 'less': 564,
  30280. 'equal': 564,
  30281. 'greater': 564,
  30282. 'question': 444,
  30283. 'at': 921,
  30284. 'A': 722,
  30285. 'B': 667,
  30286. 'C': 667,
  30287. 'D': 722,
  30288. 'E': 611,
  30289. 'F': 556,
  30290. 'G': 722,
  30291. 'H': 722,
  30292. 'I': 333,
  30293. 'J': 389,
  30294. 'K': 722,
  30295. 'L': 611,
  30296. 'M': 889,
  30297. 'N': 722,
  30298. 'O': 722,
  30299. 'P': 556,
  30300. 'Q': 722,
  30301. 'R': 667,
  30302. 'S': 556,
  30303. 'T': 611,
  30304. 'U': 722,
  30305. 'V': 722,
  30306. 'W': 944,
  30307. 'X': 722,
  30308. 'Y': 722,
  30309. 'Z': 611,
  30310. 'bracketleft': 333,
  30311. 'backslash': 278,
  30312. 'bracketright': 333,
  30313. 'asciicircum': 469,
  30314. 'underscore': 500,
  30315. 'quoteleft': 333,
  30316. 'a': 444,
  30317. 'b': 500,
  30318. 'c': 444,
  30319. 'd': 500,
  30320. 'e': 444,
  30321. 'f': 333,
  30322. 'g': 500,
  30323. 'h': 500,
  30324. 'i': 278,
  30325. 'j': 278,
  30326. 'k': 500,
  30327. 'l': 278,
  30328. 'm': 778,
  30329. 'n': 500,
  30330. 'o': 500,
  30331. 'p': 500,
  30332. 'q': 500,
  30333. 'r': 333,
  30334. 's': 389,
  30335. 't': 278,
  30336. 'u': 500,
  30337. 'v': 500,
  30338. 'w': 722,
  30339. 'x': 500,
  30340. 'y': 500,
  30341. 'z': 444,
  30342. 'braceleft': 480,
  30343. 'bar': 200,
  30344. 'braceright': 480,
  30345. 'asciitilde': 541,
  30346. 'exclamdown': 333,
  30347. 'cent': 500,
  30348. 'sterling': 500,
  30349. 'fraction': 167,
  30350. 'yen': 500,
  30351. 'florin': 500,
  30352. 'section': 500,
  30353. 'currency': 500,
  30354. 'quotesingle': 180,
  30355. 'quotedblleft': 444,
  30356. 'guillemotleft': 500,
  30357. 'guilsinglleft': 333,
  30358. 'guilsinglright': 333,
  30359. 'fi': 556,
  30360. 'fl': 556,
  30361. 'endash': 500,
  30362. 'dagger': 500,
  30363. 'daggerdbl': 500,
  30364. 'periodcentered': 250,
  30365. 'paragraph': 453,
  30366. 'bullet': 350,
  30367. 'quotesinglbase': 333,
  30368. 'quotedblbase': 444,
  30369. 'quotedblright': 444,
  30370. 'guillemotright': 500,
  30371. 'ellipsis': 1000,
  30372. 'perthousand': 1000,
  30373. 'questiondown': 444,
  30374. 'grave': 333,
  30375. 'acute': 333,
  30376. 'circumflex': 333,
  30377. 'tilde': 333,
  30378. 'macron': 333,
  30379. 'breve': 333,
  30380. 'dotaccent': 333,
  30381. 'dieresis': 333,
  30382. 'ring': 333,
  30383. 'cedilla': 333,
  30384. 'hungarumlaut': 333,
  30385. 'ogonek': 333,
  30386. 'caron': 333,
  30387. 'emdash': 1000,
  30388. 'AE': 889,
  30389. 'ordfeminine': 276,
  30390. 'Lslash': 611,
  30391. 'Oslash': 722,
  30392. 'OE': 889,
  30393. 'ordmasculine': 310,
  30394. 'ae': 667,
  30395. 'dotlessi': 278,
  30396. 'lslash': 278,
  30397. 'oslash': 500,
  30398. 'oe': 722,
  30399. 'germandbls': 500,
  30400. 'Idieresis': 333,
  30401. 'eacute': 444,
  30402. 'abreve': 444,
  30403. 'uhungarumlaut': 500,
  30404. 'ecaron': 444,
  30405. 'Ydieresis': 722,
  30406. 'divide': 564,
  30407. 'Yacute': 722,
  30408. 'Acircumflex': 722,
  30409. 'aacute': 444,
  30410. 'Ucircumflex': 722,
  30411. 'yacute': 500,
  30412. 'scommaaccent': 389,
  30413. 'ecircumflex': 444,
  30414. 'Uring': 722,
  30415. 'Udieresis': 722,
  30416. 'aogonek': 444,
  30417. 'Uacute': 722,
  30418. 'uogonek': 500,
  30419. 'Edieresis': 611,
  30420. 'Dcroat': 722,
  30421. 'commaaccent': 250,
  30422. 'copyright': 760,
  30423. 'Emacron': 611,
  30424. 'ccaron': 444,
  30425. 'aring': 444,
  30426. 'Ncommaaccent': 722,
  30427. 'lacute': 278,
  30428. 'agrave': 444,
  30429. 'Tcommaaccent': 611,
  30430. 'Cacute': 667,
  30431. 'atilde': 444,
  30432. 'Edotaccent': 611,
  30433. 'scaron': 389,
  30434. 'scedilla': 389,
  30435. 'iacute': 278,
  30436. 'lozenge': 471,
  30437. 'Rcaron': 667,
  30438. 'Gcommaaccent': 722,
  30439. 'ucircumflex': 500,
  30440. 'acircumflex': 444,
  30441. 'Amacron': 722,
  30442. 'rcaron': 333,
  30443. 'ccedilla': 444,
  30444. 'Zdotaccent': 611,
  30445. 'Thorn': 556,
  30446. 'Omacron': 722,
  30447. 'Racute': 667,
  30448. 'Sacute': 556,
  30449. 'dcaron': 588,
  30450. 'Umacron': 722,
  30451. 'uring': 500,
  30452. 'threesuperior': 300,
  30453. 'Ograve': 722,
  30454. 'Agrave': 722,
  30455. 'Abreve': 722,
  30456. 'multiply': 564,
  30457. 'uacute': 500,
  30458. 'Tcaron': 611,
  30459. 'partialdiff': 476,
  30460. 'ydieresis': 500,
  30461. 'Nacute': 722,
  30462. 'icircumflex': 278,
  30463. 'Ecircumflex': 611,
  30464. 'adieresis': 444,
  30465. 'edieresis': 444,
  30466. 'cacute': 444,
  30467. 'nacute': 500,
  30468. 'umacron': 500,
  30469. 'Ncaron': 722,
  30470. 'Iacute': 333,
  30471. 'plusminus': 564,
  30472. 'brokenbar': 200,
  30473. 'registered': 760,
  30474. 'Gbreve': 722,
  30475. 'Idotaccent': 333,
  30476. 'summation': 600,
  30477. 'Egrave': 611,
  30478. 'racute': 333,
  30479. 'omacron': 500,
  30480. 'Zacute': 611,
  30481. 'Zcaron': 611,
  30482. 'greaterequal': 549,
  30483. 'Eth': 722,
  30484. 'Ccedilla': 667,
  30485. 'lcommaaccent': 278,
  30486. 'tcaron': 326,
  30487. 'eogonek': 444,
  30488. 'Uogonek': 722,
  30489. 'Aacute': 722,
  30490. 'Adieresis': 722,
  30491. 'egrave': 444,
  30492. 'zacute': 444,
  30493. 'iogonek': 278,
  30494. 'Oacute': 722,
  30495. 'oacute': 500,
  30496. 'amacron': 444,
  30497. 'sacute': 389,
  30498. 'idieresis': 278,
  30499. 'Ocircumflex': 722,
  30500. 'Ugrave': 722,
  30501. 'Delta': 612,
  30502. 'thorn': 500,
  30503. 'twosuperior': 300,
  30504. 'Odieresis': 722,
  30505. 'mu': 500,
  30506. 'igrave': 278,
  30507. 'ohungarumlaut': 500,
  30508. 'Eogonek': 611,
  30509. 'dcroat': 500,
  30510. 'threequarters': 750,
  30511. 'Scedilla': 556,
  30512. 'lcaron': 344,
  30513. 'Kcommaaccent': 722,
  30514. 'Lacute': 611,
  30515. 'trademark': 980,
  30516. 'edotaccent': 444,
  30517. 'Igrave': 333,
  30518. 'Imacron': 333,
  30519. 'Lcaron': 611,
  30520. 'onehalf': 750,
  30521. 'lessequal': 549,
  30522. 'ocircumflex': 500,
  30523. 'ntilde': 500,
  30524. 'Uhungarumlaut': 722,
  30525. 'Eacute': 611,
  30526. 'emacron': 444,
  30527. 'gbreve': 500,
  30528. 'onequarter': 750,
  30529. 'Scaron': 556,
  30530. 'Scommaaccent': 556,
  30531. 'Ohungarumlaut': 722,
  30532. 'degree': 400,
  30533. 'ograve': 500,
  30534. 'Ccaron': 667,
  30535. 'ugrave': 500,
  30536. 'radical': 453,
  30537. 'Dcaron': 722,
  30538. 'rcommaaccent': 333,
  30539. 'Ntilde': 722,
  30540. 'otilde': 500,
  30541. 'Rcommaaccent': 667,
  30542. 'Lcommaaccent': 611,
  30543. 'Atilde': 722,
  30544. 'Aogonek': 722,
  30545. 'Aring': 722,
  30546. 'Otilde': 722,
  30547. 'zdotaccent': 444,
  30548. 'Ecaron': 611,
  30549. 'Iogonek': 333,
  30550. 'kcommaaccent': 500,
  30551. 'minus': 564,
  30552. 'Icircumflex': 333,
  30553. 'ncaron': 500,
  30554. 'tcommaaccent': 278,
  30555. 'logicalnot': 564,
  30556. 'odieresis': 500,
  30557. 'udieresis': 500,
  30558. 'notequal': 549,
  30559. 'gcommaaccent': 500,
  30560. 'eth': 500,
  30561. 'zcaron': 444,
  30562. 'ncommaaccent': 500,
  30563. 'onesuperior': 300,
  30564. 'imacron': 278,
  30565. 'Euro': 500
  30566. },
  30567. 'Times-Bold': {
  30568. 'space': 250,
  30569. 'exclam': 333,
  30570. 'quotedbl': 555,
  30571. 'numbersign': 500,
  30572. 'dollar': 500,
  30573. 'percent': 1000,
  30574. 'ampersand': 833,
  30575. 'quoteright': 333,
  30576. 'parenleft': 333,
  30577. 'parenright': 333,
  30578. 'asterisk': 500,
  30579. 'plus': 570,
  30580. 'comma': 250,
  30581. 'hyphen': 333,
  30582. 'period': 250,
  30583. 'slash': 278,
  30584. 'zero': 500,
  30585. 'one': 500,
  30586. 'two': 500,
  30587. 'three': 500,
  30588. 'four': 500,
  30589. 'five': 500,
  30590. 'six': 500,
  30591. 'seven': 500,
  30592. 'eight': 500,
  30593. 'nine': 500,
  30594. 'colon': 333,
  30595. 'semicolon': 333,
  30596. 'less': 570,
  30597. 'equal': 570,
  30598. 'greater': 570,
  30599. 'question': 500,
  30600. 'at': 930,
  30601. 'A': 722,
  30602. 'B': 667,
  30603. 'C': 722,
  30604. 'D': 722,
  30605. 'E': 667,
  30606. 'F': 611,
  30607. 'G': 778,
  30608. 'H': 778,
  30609. 'I': 389,
  30610. 'J': 500,
  30611. 'K': 778,
  30612. 'L': 667,
  30613. 'M': 944,
  30614. 'N': 722,
  30615. 'O': 778,
  30616. 'P': 611,
  30617. 'Q': 778,
  30618. 'R': 722,
  30619. 'S': 556,
  30620. 'T': 667,
  30621. 'U': 722,
  30622. 'V': 722,
  30623. 'W': 1000,
  30624. 'X': 722,
  30625. 'Y': 722,
  30626. 'Z': 667,
  30627. 'bracketleft': 333,
  30628. 'backslash': 278,
  30629. 'bracketright': 333,
  30630. 'asciicircum': 581,
  30631. 'underscore': 500,
  30632. 'quoteleft': 333,
  30633. 'a': 500,
  30634. 'b': 556,
  30635. 'c': 444,
  30636. 'd': 556,
  30637. 'e': 444,
  30638. 'f': 333,
  30639. 'g': 500,
  30640. 'h': 556,
  30641. 'i': 278,
  30642. 'j': 333,
  30643. 'k': 556,
  30644. 'l': 278,
  30645. 'm': 833,
  30646. 'n': 556,
  30647. 'o': 500,
  30648. 'p': 556,
  30649. 'q': 556,
  30650. 'r': 444,
  30651. 's': 389,
  30652. 't': 333,
  30653. 'u': 556,
  30654. 'v': 500,
  30655. 'w': 722,
  30656. 'x': 500,
  30657. 'y': 500,
  30658. 'z': 444,
  30659. 'braceleft': 394,
  30660. 'bar': 220,
  30661. 'braceright': 394,
  30662. 'asciitilde': 520,
  30663. 'exclamdown': 333,
  30664. 'cent': 500,
  30665. 'sterling': 500,
  30666. 'fraction': 167,
  30667. 'yen': 500,
  30668. 'florin': 500,
  30669. 'section': 500,
  30670. 'currency': 500,
  30671. 'quotesingle': 278,
  30672. 'quotedblleft': 500,
  30673. 'guillemotleft': 500,
  30674. 'guilsinglleft': 333,
  30675. 'guilsinglright': 333,
  30676. 'fi': 556,
  30677. 'fl': 556,
  30678. 'endash': 500,
  30679. 'dagger': 500,
  30680. 'daggerdbl': 500,
  30681. 'periodcentered': 250,
  30682. 'paragraph': 540,
  30683. 'bullet': 350,
  30684. 'quotesinglbase': 333,
  30685. 'quotedblbase': 500,
  30686. 'quotedblright': 500,
  30687. 'guillemotright': 500,
  30688. 'ellipsis': 1000,
  30689. 'perthousand': 1000,
  30690. 'questiondown': 500,
  30691. 'grave': 333,
  30692. 'acute': 333,
  30693. 'circumflex': 333,
  30694. 'tilde': 333,
  30695. 'macron': 333,
  30696. 'breve': 333,
  30697. 'dotaccent': 333,
  30698. 'dieresis': 333,
  30699. 'ring': 333,
  30700. 'cedilla': 333,
  30701. 'hungarumlaut': 333,
  30702. 'ogonek': 333,
  30703. 'caron': 333,
  30704. 'emdash': 1000,
  30705. 'AE': 1000,
  30706. 'ordfeminine': 300,
  30707. 'Lslash': 667,
  30708. 'Oslash': 778,
  30709. 'OE': 1000,
  30710. 'ordmasculine': 330,
  30711. 'ae': 722,
  30712. 'dotlessi': 278,
  30713. 'lslash': 278,
  30714. 'oslash': 500,
  30715. 'oe': 722,
  30716. 'germandbls': 556,
  30717. 'Idieresis': 389,
  30718. 'eacute': 444,
  30719. 'abreve': 500,
  30720. 'uhungarumlaut': 556,
  30721. 'ecaron': 444,
  30722. 'Ydieresis': 722,
  30723. 'divide': 570,
  30724. 'Yacute': 722,
  30725. 'Acircumflex': 722,
  30726. 'aacute': 500,
  30727. 'Ucircumflex': 722,
  30728. 'yacute': 500,
  30729. 'scommaaccent': 389,
  30730. 'ecircumflex': 444,
  30731. 'Uring': 722,
  30732. 'Udieresis': 722,
  30733. 'aogonek': 500,
  30734. 'Uacute': 722,
  30735. 'uogonek': 556,
  30736. 'Edieresis': 667,
  30737. 'Dcroat': 722,
  30738. 'commaaccent': 250,
  30739. 'copyright': 747,
  30740. 'Emacron': 667,
  30741. 'ccaron': 444,
  30742. 'aring': 500,
  30743. 'Ncommaaccent': 722,
  30744. 'lacute': 278,
  30745. 'agrave': 500,
  30746. 'Tcommaaccent': 667,
  30747. 'Cacute': 722,
  30748. 'atilde': 500,
  30749. 'Edotaccent': 667,
  30750. 'scaron': 389,
  30751. 'scedilla': 389,
  30752. 'iacute': 278,
  30753. 'lozenge': 494,
  30754. 'Rcaron': 722,
  30755. 'Gcommaaccent': 778,
  30756. 'ucircumflex': 556,
  30757. 'acircumflex': 500,
  30758. 'Amacron': 722,
  30759. 'rcaron': 444,
  30760. 'ccedilla': 444,
  30761. 'Zdotaccent': 667,
  30762. 'Thorn': 611,
  30763. 'Omacron': 778,
  30764. 'Racute': 722,
  30765. 'Sacute': 556,
  30766. 'dcaron': 672,
  30767. 'Umacron': 722,
  30768. 'uring': 556,
  30769. 'threesuperior': 300,
  30770. 'Ograve': 778,
  30771. 'Agrave': 722,
  30772. 'Abreve': 722,
  30773. 'multiply': 570,
  30774. 'uacute': 556,
  30775. 'Tcaron': 667,
  30776. 'partialdiff': 494,
  30777. 'ydieresis': 500,
  30778. 'Nacute': 722,
  30779. 'icircumflex': 278,
  30780. 'Ecircumflex': 667,
  30781. 'adieresis': 500,
  30782. 'edieresis': 444,
  30783. 'cacute': 444,
  30784. 'nacute': 556,
  30785. 'umacron': 556,
  30786. 'Ncaron': 722,
  30787. 'Iacute': 389,
  30788. 'plusminus': 570,
  30789. 'brokenbar': 220,
  30790. 'registered': 747,
  30791. 'Gbreve': 778,
  30792. 'Idotaccent': 389,
  30793. 'summation': 600,
  30794. 'Egrave': 667,
  30795. 'racute': 444,
  30796. 'omacron': 500,
  30797. 'Zacute': 667,
  30798. 'Zcaron': 667,
  30799. 'greaterequal': 549,
  30800. 'Eth': 722,
  30801. 'Ccedilla': 722,
  30802. 'lcommaaccent': 278,
  30803. 'tcaron': 416,
  30804. 'eogonek': 444,
  30805. 'Uogonek': 722,
  30806. 'Aacute': 722,
  30807. 'Adieresis': 722,
  30808. 'egrave': 444,
  30809. 'zacute': 444,
  30810. 'iogonek': 278,
  30811. 'Oacute': 778,
  30812. 'oacute': 500,
  30813. 'amacron': 500,
  30814. 'sacute': 389,
  30815. 'idieresis': 278,
  30816. 'Ocircumflex': 778,
  30817. 'Ugrave': 722,
  30818. 'Delta': 612,
  30819. 'thorn': 556,
  30820. 'twosuperior': 300,
  30821. 'Odieresis': 778,
  30822. 'mu': 556,
  30823. 'igrave': 278,
  30824. 'ohungarumlaut': 500,
  30825. 'Eogonek': 667,
  30826. 'dcroat': 556,
  30827. 'threequarters': 750,
  30828. 'Scedilla': 556,
  30829. 'lcaron': 394,
  30830. 'Kcommaaccent': 778,
  30831. 'Lacute': 667,
  30832. 'trademark': 1000,
  30833. 'edotaccent': 444,
  30834. 'Igrave': 389,
  30835. 'Imacron': 389,
  30836. 'Lcaron': 667,
  30837. 'onehalf': 750,
  30838. 'lessequal': 549,
  30839. 'ocircumflex': 500,
  30840. 'ntilde': 556,
  30841. 'Uhungarumlaut': 722,
  30842. 'Eacute': 667,
  30843. 'emacron': 444,
  30844. 'gbreve': 500,
  30845. 'onequarter': 750,
  30846. 'Scaron': 556,
  30847. 'Scommaaccent': 556,
  30848. 'Ohungarumlaut': 778,
  30849. 'degree': 400,
  30850. 'ograve': 500,
  30851. 'Ccaron': 722,
  30852. 'ugrave': 556,
  30853. 'radical': 549,
  30854. 'Dcaron': 722,
  30855. 'rcommaaccent': 444,
  30856. 'Ntilde': 722,
  30857. 'otilde': 500,
  30858. 'Rcommaaccent': 722,
  30859. 'Lcommaaccent': 667,
  30860. 'Atilde': 722,
  30861. 'Aogonek': 722,
  30862. 'Aring': 722,
  30863. 'Otilde': 778,
  30864. 'zdotaccent': 444,
  30865. 'Ecaron': 667,
  30866. 'Iogonek': 389,
  30867. 'kcommaaccent': 556,
  30868. 'minus': 570,
  30869. 'Icircumflex': 389,
  30870. 'ncaron': 556,
  30871. 'tcommaaccent': 333,
  30872. 'logicalnot': 570,
  30873. 'odieresis': 500,
  30874. 'udieresis': 556,
  30875. 'notequal': 549,
  30876. 'gcommaaccent': 500,
  30877. 'eth': 500,
  30878. 'zcaron': 444,
  30879. 'ncommaaccent': 556,
  30880. 'onesuperior': 300,
  30881. 'imacron': 278,
  30882. 'Euro': 500
  30883. },
  30884. 'Times-BoldItalic': {
  30885. 'space': 250,
  30886. 'exclam': 389,
  30887. 'quotedbl': 555,
  30888. 'numbersign': 500,
  30889. 'dollar': 500,
  30890. 'percent': 833,
  30891. 'ampersand': 778,
  30892. 'quoteright': 333,
  30893. 'parenleft': 333,
  30894. 'parenright': 333,
  30895. 'asterisk': 500,
  30896. 'plus': 570,
  30897. 'comma': 250,
  30898. 'hyphen': 333,
  30899. 'period': 250,
  30900. 'slash': 278,
  30901. 'zero': 500,
  30902. 'one': 500,
  30903. 'two': 500,
  30904. 'three': 500,
  30905. 'four': 500,
  30906. 'five': 500,
  30907. 'six': 500,
  30908. 'seven': 500,
  30909. 'eight': 500,
  30910. 'nine': 500,
  30911. 'colon': 333,
  30912. 'semicolon': 333,
  30913. 'less': 570,
  30914. 'equal': 570,
  30915. 'greater': 570,
  30916. 'question': 500,
  30917. 'at': 832,
  30918. 'A': 667,
  30919. 'B': 667,
  30920. 'C': 667,
  30921. 'D': 722,
  30922. 'E': 667,
  30923. 'F': 667,
  30924. 'G': 722,
  30925. 'H': 778,
  30926. 'I': 389,
  30927. 'J': 500,
  30928. 'K': 667,
  30929. 'L': 611,
  30930. 'M': 889,
  30931. 'N': 722,
  30932. 'O': 722,
  30933. 'P': 611,
  30934. 'Q': 722,
  30935. 'R': 667,
  30936. 'S': 556,
  30937. 'T': 611,
  30938. 'U': 722,
  30939. 'V': 667,
  30940. 'W': 889,
  30941. 'X': 667,
  30942. 'Y': 611,
  30943. 'Z': 611,
  30944. 'bracketleft': 333,
  30945. 'backslash': 278,
  30946. 'bracketright': 333,
  30947. 'asciicircum': 570,
  30948. 'underscore': 500,
  30949. 'quoteleft': 333,
  30950. 'a': 500,
  30951. 'b': 500,
  30952. 'c': 444,
  30953. 'd': 500,
  30954. 'e': 444,
  30955. 'f': 333,
  30956. 'g': 500,
  30957. 'h': 556,
  30958. 'i': 278,
  30959. 'j': 278,
  30960. 'k': 500,
  30961. 'l': 278,
  30962. 'm': 778,
  30963. 'n': 556,
  30964. 'o': 500,
  30965. 'p': 500,
  30966. 'q': 500,
  30967. 'r': 389,
  30968. 's': 389,
  30969. 't': 278,
  30970. 'u': 556,
  30971. 'v': 444,
  30972. 'w': 667,
  30973. 'x': 500,
  30974. 'y': 444,
  30975. 'z': 389,
  30976. 'braceleft': 348,
  30977. 'bar': 220,
  30978. 'braceright': 348,
  30979. 'asciitilde': 570,
  30980. 'exclamdown': 389,
  30981. 'cent': 500,
  30982. 'sterling': 500,
  30983. 'fraction': 167,
  30984. 'yen': 500,
  30985. 'florin': 500,
  30986. 'section': 500,
  30987. 'currency': 500,
  30988. 'quotesingle': 278,
  30989. 'quotedblleft': 500,
  30990. 'guillemotleft': 500,
  30991. 'guilsinglleft': 333,
  30992. 'guilsinglright': 333,
  30993. 'fi': 556,
  30994. 'fl': 556,
  30995. 'endash': 500,
  30996. 'dagger': 500,
  30997. 'daggerdbl': 500,
  30998. 'periodcentered': 250,
  30999. 'paragraph': 500,
  31000. 'bullet': 350,
  31001. 'quotesinglbase': 333,
  31002. 'quotedblbase': 500,
  31003. 'quotedblright': 500,
  31004. 'guillemotright': 500,
  31005. 'ellipsis': 1000,
  31006. 'perthousand': 1000,
  31007. 'questiondown': 500,
  31008. 'grave': 333,
  31009. 'acute': 333,
  31010. 'circumflex': 333,
  31011. 'tilde': 333,
  31012. 'macron': 333,
  31013. 'breve': 333,
  31014. 'dotaccent': 333,
  31015. 'dieresis': 333,
  31016. 'ring': 333,
  31017. 'cedilla': 333,
  31018. 'hungarumlaut': 333,
  31019. 'ogonek': 333,
  31020. 'caron': 333,
  31021. 'emdash': 1000,
  31022. 'AE': 944,
  31023. 'ordfeminine': 266,
  31024. 'Lslash': 611,
  31025. 'Oslash': 722,
  31026. 'OE': 944,
  31027. 'ordmasculine': 300,
  31028. 'ae': 722,
  31029. 'dotlessi': 278,
  31030. 'lslash': 278,
  31031. 'oslash': 500,
  31032. 'oe': 722,
  31033. 'germandbls': 500,
  31034. 'Idieresis': 389,
  31035. 'eacute': 444,
  31036. 'abreve': 500,
  31037. 'uhungarumlaut': 556,
  31038. 'ecaron': 444,
  31039. 'Ydieresis': 611,
  31040. 'divide': 570,
  31041. 'Yacute': 611,
  31042. 'Acircumflex': 667,
  31043. 'aacute': 500,
  31044. 'Ucircumflex': 722,
  31045. 'yacute': 444,
  31046. 'scommaaccent': 389,
  31047. 'ecircumflex': 444,
  31048. 'Uring': 722,
  31049. 'Udieresis': 722,
  31050. 'aogonek': 500,
  31051. 'Uacute': 722,
  31052. 'uogonek': 556,
  31053. 'Edieresis': 667,
  31054. 'Dcroat': 722,
  31055. 'commaaccent': 250,
  31056. 'copyright': 747,
  31057. 'Emacron': 667,
  31058. 'ccaron': 444,
  31059. 'aring': 500,
  31060. 'Ncommaaccent': 722,
  31061. 'lacute': 278,
  31062. 'agrave': 500,
  31063. 'Tcommaaccent': 611,
  31064. 'Cacute': 667,
  31065. 'atilde': 500,
  31066. 'Edotaccent': 667,
  31067. 'scaron': 389,
  31068. 'scedilla': 389,
  31069. 'iacute': 278,
  31070. 'lozenge': 494,
  31071. 'Rcaron': 667,
  31072. 'Gcommaaccent': 722,
  31073. 'ucircumflex': 556,
  31074. 'acircumflex': 500,
  31075. 'Amacron': 667,
  31076. 'rcaron': 389,
  31077. 'ccedilla': 444,
  31078. 'Zdotaccent': 611,
  31079. 'Thorn': 611,
  31080. 'Omacron': 722,
  31081. 'Racute': 667,
  31082. 'Sacute': 556,
  31083. 'dcaron': 608,
  31084. 'Umacron': 722,
  31085. 'uring': 556,
  31086. 'threesuperior': 300,
  31087. 'Ograve': 722,
  31088. 'Agrave': 667,
  31089. 'Abreve': 667,
  31090. 'multiply': 570,
  31091. 'uacute': 556,
  31092. 'Tcaron': 611,
  31093. 'partialdiff': 494,
  31094. 'ydieresis': 444,
  31095. 'Nacute': 722,
  31096. 'icircumflex': 278,
  31097. 'Ecircumflex': 667,
  31098. 'adieresis': 500,
  31099. 'edieresis': 444,
  31100. 'cacute': 444,
  31101. 'nacute': 556,
  31102. 'umacron': 556,
  31103. 'Ncaron': 722,
  31104. 'Iacute': 389,
  31105. 'plusminus': 570,
  31106. 'brokenbar': 220,
  31107. 'registered': 747,
  31108. 'Gbreve': 722,
  31109. 'Idotaccent': 389,
  31110. 'summation': 600,
  31111. 'Egrave': 667,
  31112. 'racute': 389,
  31113. 'omacron': 500,
  31114. 'Zacute': 611,
  31115. 'Zcaron': 611,
  31116. 'greaterequal': 549,
  31117. 'Eth': 722,
  31118. 'Ccedilla': 667,
  31119. 'lcommaaccent': 278,
  31120. 'tcaron': 366,
  31121. 'eogonek': 444,
  31122. 'Uogonek': 722,
  31123. 'Aacute': 667,
  31124. 'Adieresis': 667,
  31125. 'egrave': 444,
  31126. 'zacute': 389,
  31127. 'iogonek': 278,
  31128. 'Oacute': 722,
  31129. 'oacute': 500,
  31130. 'amacron': 500,
  31131. 'sacute': 389,
  31132. 'idieresis': 278,
  31133. 'Ocircumflex': 722,
  31134. 'Ugrave': 722,
  31135. 'Delta': 612,
  31136. 'thorn': 500,
  31137. 'twosuperior': 300,
  31138. 'Odieresis': 722,
  31139. 'mu': 576,
  31140. 'igrave': 278,
  31141. 'ohungarumlaut': 500,
  31142. 'Eogonek': 667,
  31143. 'dcroat': 500,
  31144. 'threequarters': 750,
  31145. 'Scedilla': 556,
  31146. 'lcaron': 382,
  31147. 'Kcommaaccent': 667,
  31148. 'Lacute': 611,
  31149. 'trademark': 1000,
  31150. 'edotaccent': 444,
  31151. 'Igrave': 389,
  31152. 'Imacron': 389,
  31153. 'Lcaron': 611,
  31154. 'onehalf': 750,
  31155. 'lessequal': 549,
  31156. 'ocircumflex': 500,
  31157. 'ntilde': 556,
  31158. 'Uhungarumlaut': 722,
  31159. 'Eacute': 667,
  31160. 'emacron': 444,
  31161. 'gbreve': 500,
  31162. 'onequarter': 750,
  31163. 'Scaron': 556,
  31164. 'Scommaaccent': 556,
  31165. 'Ohungarumlaut': 722,
  31166. 'degree': 400,
  31167. 'ograve': 500,
  31168. 'Ccaron': 667,
  31169. 'ugrave': 556,
  31170. 'radical': 549,
  31171. 'Dcaron': 722,
  31172. 'rcommaaccent': 389,
  31173. 'Ntilde': 722,
  31174. 'otilde': 500,
  31175. 'Rcommaaccent': 667,
  31176. 'Lcommaaccent': 611,
  31177. 'Atilde': 667,
  31178. 'Aogonek': 667,
  31179. 'Aring': 667,
  31180. 'Otilde': 722,
  31181. 'zdotaccent': 389,
  31182. 'Ecaron': 667,
  31183. 'Iogonek': 389,
  31184. 'kcommaaccent': 500,
  31185. 'minus': 606,
  31186. 'Icircumflex': 389,
  31187. 'ncaron': 556,
  31188. 'tcommaaccent': 278,
  31189. 'logicalnot': 606,
  31190. 'odieresis': 500,
  31191. 'udieresis': 556,
  31192. 'notequal': 549,
  31193. 'gcommaaccent': 500,
  31194. 'eth': 500,
  31195. 'zcaron': 389,
  31196. 'ncommaaccent': 556,
  31197. 'onesuperior': 300,
  31198. 'imacron': 278,
  31199. 'Euro': 500
  31200. },
  31201. 'Times-Italic': {
  31202. 'space': 250,
  31203. 'exclam': 333,
  31204. 'quotedbl': 420,
  31205. 'numbersign': 500,
  31206. 'dollar': 500,
  31207. 'percent': 833,
  31208. 'ampersand': 778,
  31209. 'quoteright': 333,
  31210. 'parenleft': 333,
  31211. 'parenright': 333,
  31212. 'asterisk': 500,
  31213. 'plus': 675,
  31214. 'comma': 250,
  31215. 'hyphen': 333,
  31216. 'period': 250,
  31217. 'slash': 278,
  31218. 'zero': 500,
  31219. 'one': 500,
  31220. 'two': 500,
  31221. 'three': 500,
  31222. 'four': 500,
  31223. 'five': 500,
  31224. 'six': 500,
  31225. 'seven': 500,
  31226. 'eight': 500,
  31227. 'nine': 500,
  31228. 'colon': 333,
  31229. 'semicolon': 333,
  31230. 'less': 675,
  31231. 'equal': 675,
  31232. 'greater': 675,
  31233. 'question': 500,
  31234. 'at': 920,
  31235. 'A': 611,
  31236. 'B': 611,
  31237. 'C': 667,
  31238. 'D': 722,
  31239. 'E': 611,
  31240. 'F': 611,
  31241. 'G': 722,
  31242. 'H': 722,
  31243. 'I': 333,
  31244. 'J': 444,
  31245. 'K': 667,
  31246. 'L': 556,
  31247. 'M': 833,
  31248. 'N': 667,
  31249. 'O': 722,
  31250. 'P': 611,
  31251. 'Q': 722,
  31252. 'R': 611,
  31253. 'S': 500,
  31254. 'T': 556,
  31255. 'U': 722,
  31256. 'V': 611,
  31257. 'W': 833,
  31258. 'X': 611,
  31259. 'Y': 556,
  31260. 'Z': 556,
  31261. 'bracketleft': 389,
  31262. 'backslash': 278,
  31263. 'bracketright': 389,
  31264. 'asciicircum': 422,
  31265. 'underscore': 500,
  31266. 'quoteleft': 333,
  31267. 'a': 500,
  31268. 'b': 500,
  31269. 'c': 444,
  31270. 'd': 500,
  31271. 'e': 444,
  31272. 'f': 278,
  31273. 'g': 500,
  31274. 'h': 500,
  31275. 'i': 278,
  31276. 'j': 278,
  31277. 'k': 444,
  31278. 'l': 278,
  31279. 'm': 722,
  31280. 'n': 500,
  31281. 'o': 500,
  31282. 'p': 500,
  31283. 'q': 500,
  31284. 'r': 389,
  31285. 's': 389,
  31286. 't': 278,
  31287. 'u': 500,
  31288. 'v': 444,
  31289. 'w': 667,
  31290. 'x': 444,
  31291. 'y': 444,
  31292. 'z': 389,
  31293. 'braceleft': 400,
  31294. 'bar': 275,
  31295. 'braceright': 400,
  31296. 'asciitilde': 541,
  31297. 'exclamdown': 389,
  31298. 'cent': 500,
  31299. 'sterling': 500,
  31300. 'fraction': 167,
  31301. 'yen': 500,
  31302. 'florin': 500,
  31303. 'section': 500,
  31304. 'currency': 500,
  31305. 'quotesingle': 214,
  31306. 'quotedblleft': 556,
  31307. 'guillemotleft': 500,
  31308. 'guilsinglleft': 333,
  31309. 'guilsinglright': 333,
  31310. 'fi': 500,
  31311. 'fl': 500,
  31312. 'endash': 500,
  31313. 'dagger': 500,
  31314. 'daggerdbl': 500,
  31315. 'periodcentered': 250,
  31316. 'paragraph': 523,
  31317. 'bullet': 350,
  31318. 'quotesinglbase': 333,
  31319. 'quotedblbase': 556,
  31320. 'quotedblright': 556,
  31321. 'guillemotright': 500,
  31322. 'ellipsis': 889,
  31323. 'perthousand': 1000,
  31324. 'questiondown': 500,
  31325. 'grave': 333,
  31326. 'acute': 333,
  31327. 'circumflex': 333,
  31328. 'tilde': 333,
  31329. 'macron': 333,
  31330. 'breve': 333,
  31331. 'dotaccent': 333,
  31332. 'dieresis': 333,
  31333. 'ring': 333,
  31334. 'cedilla': 333,
  31335. 'hungarumlaut': 333,
  31336. 'ogonek': 333,
  31337. 'caron': 333,
  31338. 'emdash': 889,
  31339. 'AE': 889,
  31340. 'ordfeminine': 276,
  31341. 'Lslash': 556,
  31342. 'Oslash': 722,
  31343. 'OE': 944,
  31344. 'ordmasculine': 310,
  31345. 'ae': 667,
  31346. 'dotlessi': 278,
  31347. 'lslash': 278,
  31348. 'oslash': 500,
  31349. 'oe': 667,
  31350. 'germandbls': 500,
  31351. 'Idieresis': 333,
  31352. 'eacute': 444,
  31353. 'abreve': 500,
  31354. 'uhungarumlaut': 500,
  31355. 'ecaron': 444,
  31356. 'Ydieresis': 556,
  31357. 'divide': 675,
  31358. 'Yacute': 556,
  31359. 'Acircumflex': 611,
  31360. 'aacute': 500,
  31361. 'Ucircumflex': 722,
  31362. 'yacute': 444,
  31363. 'scommaaccent': 389,
  31364. 'ecircumflex': 444,
  31365. 'Uring': 722,
  31366. 'Udieresis': 722,
  31367. 'aogonek': 500,
  31368. 'Uacute': 722,
  31369. 'uogonek': 500,
  31370. 'Edieresis': 611,
  31371. 'Dcroat': 722,
  31372. 'commaaccent': 250,
  31373. 'copyright': 760,
  31374. 'Emacron': 611,
  31375. 'ccaron': 444,
  31376. 'aring': 500,
  31377. 'Ncommaaccent': 667,
  31378. 'lacute': 278,
  31379. 'agrave': 500,
  31380. 'Tcommaaccent': 556,
  31381. 'Cacute': 667,
  31382. 'atilde': 500,
  31383. 'Edotaccent': 611,
  31384. 'scaron': 389,
  31385. 'scedilla': 389,
  31386. 'iacute': 278,
  31387. 'lozenge': 471,
  31388. 'Rcaron': 611,
  31389. 'Gcommaaccent': 722,
  31390. 'ucircumflex': 500,
  31391. 'acircumflex': 500,
  31392. 'Amacron': 611,
  31393. 'rcaron': 389,
  31394. 'ccedilla': 444,
  31395. 'Zdotaccent': 556,
  31396. 'Thorn': 611,
  31397. 'Omacron': 722,
  31398. 'Racute': 611,
  31399. 'Sacute': 500,
  31400. 'dcaron': 544,
  31401. 'Umacron': 722,
  31402. 'uring': 500,
  31403. 'threesuperior': 300,
  31404. 'Ograve': 722,
  31405. 'Agrave': 611,
  31406. 'Abreve': 611,
  31407. 'multiply': 675,
  31408. 'uacute': 500,
  31409. 'Tcaron': 556,
  31410. 'partialdiff': 476,
  31411. 'ydieresis': 444,
  31412. 'Nacute': 667,
  31413. 'icircumflex': 278,
  31414. 'Ecircumflex': 611,
  31415. 'adieresis': 500,
  31416. 'edieresis': 444,
  31417. 'cacute': 444,
  31418. 'nacute': 500,
  31419. 'umacron': 500,
  31420. 'Ncaron': 667,
  31421. 'Iacute': 333,
  31422. 'plusminus': 675,
  31423. 'brokenbar': 275,
  31424. 'registered': 760,
  31425. 'Gbreve': 722,
  31426. 'Idotaccent': 333,
  31427. 'summation': 600,
  31428. 'Egrave': 611,
  31429. 'racute': 389,
  31430. 'omacron': 500,
  31431. 'Zacute': 556,
  31432. 'Zcaron': 556,
  31433. 'greaterequal': 549,
  31434. 'Eth': 722,
  31435. 'Ccedilla': 667,
  31436. 'lcommaaccent': 278,
  31437. 'tcaron': 300,
  31438. 'eogonek': 444,
  31439. 'Uogonek': 722,
  31440. 'Aacute': 611,
  31441. 'Adieresis': 611,
  31442. 'egrave': 444,
  31443. 'zacute': 389,
  31444. 'iogonek': 278,
  31445. 'Oacute': 722,
  31446. 'oacute': 500,
  31447. 'amacron': 500,
  31448. 'sacute': 389,
  31449. 'idieresis': 278,
  31450. 'Ocircumflex': 722,
  31451. 'Ugrave': 722,
  31452. 'Delta': 612,
  31453. 'thorn': 500,
  31454. 'twosuperior': 300,
  31455. 'Odieresis': 722,
  31456. 'mu': 500,
  31457. 'igrave': 278,
  31458. 'ohungarumlaut': 500,
  31459. 'Eogonek': 611,
  31460. 'dcroat': 500,
  31461. 'threequarters': 750,
  31462. 'Scedilla': 500,
  31463. 'lcaron': 300,
  31464. 'Kcommaaccent': 667,
  31465. 'Lacute': 556,
  31466. 'trademark': 980,
  31467. 'edotaccent': 444,
  31468. 'Igrave': 333,
  31469. 'Imacron': 333,
  31470. 'Lcaron': 611,
  31471. 'onehalf': 750,
  31472. 'lessequal': 549,
  31473. 'ocircumflex': 500,
  31474. 'ntilde': 500,
  31475. 'Uhungarumlaut': 722,
  31476. 'Eacute': 611,
  31477. 'emacron': 444,
  31478. 'gbreve': 500,
  31479. 'onequarter': 750,
  31480. 'Scaron': 500,
  31481. 'Scommaaccent': 500,
  31482. 'Ohungarumlaut': 722,
  31483. 'degree': 400,
  31484. 'ograve': 500,
  31485. 'Ccaron': 667,
  31486. 'ugrave': 500,
  31487. 'radical': 453,
  31488. 'Dcaron': 722,
  31489. 'rcommaaccent': 389,
  31490. 'Ntilde': 667,
  31491. 'otilde': 500,
  31492. 'Rcommaaccent': 611,
  31493. 'Lcommaaccent': 556,
  31494. 'Atilde': 611,
  31495. 'Aogonek': 611,
  31496. 'Aring': 611,
  31497. 'Otilde': 722,
  31498. 'zdotaccent': 389,
  31499. 'Ecaron': 611,
  31500. 'Iogonek': 333,
  31501. 'kcommaaccent': 444,
  31502. 'minus': 675,
  31503. 'Icircumflex': 333,
  31504. 'ncaron': 500,
  31505. 'tcommaaccent': 278,
  31506. 'logicalnot': 675,
  31507. 'odieresis': 500,
  31508. 'udieresis': 500,
  31509. 'notequal': 549,
  31510. 'gcommaaccent': 500,
  31511. 'eth': 500,
  31512. 'zcaron': 389,
  31513. 'ncommaaccent': 500,
  31514. 'onesuperior': 300,
  31515. 'imacron': 278,
  31516. 'Euro': 500
  31517. },
  31518. 'ZapfDingbats': {
  31519. 'space': 278,
  31520. 'a1': 974,
  31521. 'a2': 961,
  31522. 'a202': 974,
  31523. 'a3': 980,
  31524. 'a4': 719,
  31525. 'a5': 789,
  31526. 'a119': 790,
  31527. 'a118': 791,
  31528. 'a117': 690,
  31529. 'a11': 960,
  31530. 'a12': 939,
  31531. 'a13': 549,
  31532. 'a14': 855,
  31533. 'a15': 911,
  31534. 'a16': 933,
  31535. 'a105': 911,
  31536. 'a17': 945,
  31537. 'a18': 974,
  31538. 'a19': 755,
  31539. 'a20': 846,
  31540. 'a21': 762,
  31541. 'a22': 761,
  31542. 'a23': 571,
  31543. 'a24': 677,
  31544. 'a25': 763,
  31545. 'a26': 760,
  31546. 'a27': 759,
  31547. 'a28': 754,
  31548. 'a6': 494,
  31549. 'a7': 552,
  31550. 'a8': 537,
  31551. 'a9': 577,
  31552. 'a10': 692,
  31553. 'a29': 786,
  31554. 'a30': 788,
  31555. 'a31': 788,
  31556. 'a32': 790,
  31557. 'a33': 793,
  31558. 'a34': 794,
  31559. 'a35': 816,
  31560. 'a36': 823,
  31561. 'a37': 789,
  31562. 'a38': 841,
  31563. 'a39': 823,
  31564. 'a40': 833,
  31565. 'a41': 816,
  31566. 'a42': 831,
  31567. 'a43': 923,
  31568. 'a44': 744,
  31569. 'a45': 723,
  31570. 'a46': 749,
  31571. 'a47': 790,
  31572. 'a48': 792,
  31573. 'a49': 695,
  31574. 'a50': 776,
  31575. 'a51': 768,
  31576. 'a52': 792,
  31577. 'a53': 759,
  31578. 'a54': 707,
  31579. 'a55': 708,
  31580. 'a56': 682,
  31581. 'a57': 701,
  31582. 'a58': 826,
  31583. 'a59': 815,
  31584. 'a60': 789,
  31585. 'a61': 789,
  31586. 'a62': 707,
  31587. 'a63': 687,
  31588. 'a64': 696,
  31589. 'a65': 689,
  31590. 'a66': 786,
  31591. 'a67': 787,
  31592. 'a68': 713,
  31593. 'a69': 791,
  31594. 'a70': 785,
  31595. 'a71': 791,
  31596. 'a72': 873,
  31597. 'a73': 761,
  31598. 'a74': 762,
  31599. 'a203': 762,
  31600. 'a75': 759,
  31601. 'a204': 759,
  31602. 'a76': 892,
  31603. 'a77': 892,
  31604. 'a78': 788,
  31605. 'a79': 784,
  31606. 'a81': 438,
  31607. 'a82': 138,
  31608. 'a83': 277,
  31609. 'a84': 415,
  31610. 'a97': 392,
  31611. 'a98': 392,
  31612. 'a99': 668,
  31613. 'a100': 668,
  31614. 'a89': 390,
  31615. 'a90': 390,
  31616. 'a93': 317,
  31617. 'a94': 317,
  31618. 'a91': 276,
  31619. 'a92': 276,
  31620. 'a205': 509,
  31621. 'a85': 509,
  31622. 'a206': 410,
  31623. 'a86': 410,
  31624. 'a87': 234,
  31625. 'a88': 234,
  31626. 'a95': 334,
  31627. 'a96': 334,
  31628. 'a101': 732,
  31629. 'a102': 544,
  31630. 'a103': 544,
  31631. 'a104': 910,
  31632. 'a106': 667,
  31633. 'a107': 760,
  31634. 'a108': 760,
  31635. 'a112': 776,
  31636. 'a111': 595,
  31637. 'a110': 694,
  31638. 'a109': 626,
  31639. 'a120': 788,
  31640. 'a121': 788,
  31641. 'a122': 788,
  31642. 'a123': 788,
  31643. 'a124': 788,
  31644. 'a125': 788,
  31645. 'a126': 788,
  31646. 'a127': 788,
  31647. 'a128': 788,
  31648. 'a129': 788,
  31649. 'a130': 788,
  31650. 'a131': 788,
  31651. 'a132': 788,
  31652. 'a133': 788,
  31653. 'a134': 788,
  31654. 'a135': 788,
  31655. 'a136': 788,
  31656. 'a137': 788,
  31657. 'a138': 788,
  31658. 'a139': 788,
  31659. 'a140': 788,
  31660. 'a141': 788,
  31661. 'a142': 788,
  31662. 'a143': 788,
  31663. 'a144': 788,
  31664. 'a145': 788,
  31665. 'a146': 788,
  31666. 'a147': 788,
  31667. 'a148': 788,
  31668. 'a149': 788,
  31669. 'a150': 788,
  31670. 'a151': 788,
  31671. 'a152': 788,
  31672. 'a153': 788,
  31673. 'a154': 788,
  31674. 'a155': 788,
  31675. 'a156': 788,
  31676. 'a157': 788,
  31677. 'a158': 788,
  31678. 'a159': 788,
  31679. 'a160': 894,
  31680. 'a161': 838,
  31681. 'a163': 1016,
  31682. 'a164': 458,
  31683. 'a196': 748,
  31684. 'a165': 924,
  31685. 'a192': 748,
  31686. 'a166': 918,
  31687. 'a167': 927,
  31688. 'a168': 928,
  31689. 'a169': 928,
  31690. 'a170': 834,
  31691. 'a171': 873,
  31692. 'a172': 828,
  31693. 'a173': 924,
  31694. 'a162': 924,
  31695. 'a174': 917,
  31696. 'a175': 930,
  31697. 'a176': 931,
  31698. 'a177': 463,
  31699. 'a178': 883,
  31700. 'a179': 836,
  31701. 'a193': 836,
  31702. 'a180': 867,
  31703. 'a199': 867,
  31704. 'a181': 696,
  31705. 'a200': 696,
  31706. 'a182': 874,
  31707. 'a201': 874,
  31708. 'a183': 760,
  31709. 'a184': 946,
  31710. 'a197': 771,
  31711. 'a185': 865,
  31712. 'a194': 771,
  31713. 'a198': 888,
  31714. 'a186': 967,
  31715. 'a195': 888,
  31716. 'a187': 831,
  31717. 'a188': 873,
  31718. 'a189': 927,
  31719. 'a190': 970,
  31720. 'a191': 918
  31721. }
  31722. };
  31723. var EOF = {};
  31724. function isEOF(v) {
  31725. return (v === EOF);
  31726. }
  31727. var Parser = (function ParserClosure() {
  31728. function Parser(lexer, allowStreams, xref) {
  31729. this.lexer = lexer;
  31730. this.allowStreams = allowStreams;
  31731. this.xref = xref;
  31732. this.imageCache = {
  31733. length: 0,
  31734. adler32: 0,
  31735. stream: null
  31736. };
  31737. this.refill();
  31738. }
  31739. Parser.prototype = {
  31740. refill: function Parser_refill() {
  31741. this.buf1 = this.lexer.getObj();
  31742. this.buf2 = this.lexer.getObj();
  31743. },
  31744. shift: function Parser_shift() {
  31745. if (isCmd(this.buf2, 'ID')) {
  31746. this.buf1 = this.buf2;
  31747. this.buf2 = null;
  31748. } else {
  31749. this.buf1 = this.buf2;
  31750. this.buf2 = this.lexer.getObj();
  31751. }
  31752. },
  31753. getObj: function Parser_getObj(cipherTransform) {
  31754. var buf1 = this.buf1;
  31755. this.shift();
  31756. if (buf1 instanceof Cmd) {
  31757. switch (buf1.cmd) {
  31758. case 'BI': // inline image
  31759. return this.makeInlineImage(cipherTransform);
  31760. case '[': // array
  31761. var array = [];
  31762. while (!isCmd(this.buf1, ']') && !isEOF(this.buf1)) {
  31763. array.push(this.getObj(cipherTransform));
  31764. }
  31765. if (isEOF(this.buf1)) {
  31766. error('End of file inside array');
  31767. }
  31768. this.shift();
  31769. return array;
  31770. case '<<': // dictionary or stream
  31771. var dict = new Dict(this.xref);
  31772. while (!isCmd(this.buf1, '>>') && !isEOF(this.buf1)) {
  31773. if (!isName(this.buf1)) {
  31774. info('Malformed dictionary: key must be a name object');
  31775. this.shift();
  31776. continue;
  31777. }
  31778. var key = this.buf1.name;
  31779. this.shift();
  31780. if (isEOF(this.buf1)) {
  31781. break;
  31782. }
  31783. dict.set(key, this.getObj(cipherTransform));
  31784. }
  31785. if (isEOF(this.buf1)) {
  31786. error('End of file inside dictionary');
  31787. }
  31788. // Stream objects are not allowed inside content streams or
  31789. // object streams.
  31790. if (isCmd(this.buf2, 'stream')) {
  31791. return (this.allowStreams ?
  31792. this.makeStream(dict, cipherTransform) : dict);
  31793. }
  31794. this.shift();
  31795. return dict;
  31796. default: // simple object
  31797. return buf1;
  31798. }
  31799. }
  31800. if (isInt(buf1)) { // indirect reference or integer
  31801. var num = buf1;
  31802. if (isInt(this.buf1) && isCmd(this.buf2, 'R')) {
  31803. var ref = new Ref(num, this.buf1);
  31804. this.shift();
  31805. this.shift();
  31806. return ref;
  31807. }
  31808. return num;
  31809. }
  31810. if (isString(buf1)) { // string
  31811. var str = buf1;
  31812. if (cipherTransform) {
  31813. str = cipherTransform.decryptString(str);
  31814. }
  31815. return str;
  31816. }
  31817. // simple object
  31818. return buf1;
  31819. },
  31820. makeInlineImage: function Parser_makeInlineImage(cipherTransform) {
  31821. var lexer = this.lexer;
  31822. var stream = lexer.stream;
  31823. // parse dictionary
  31824. var dict = new Dict(null);
  31825. while (!isCmd(this.buf1, 'ID') && !isEOF(this.buf1)) {
  31826. if (!isName(this.buf1)) {
  31827. error('Dictionary key must be a name object');
  31828. }
  31829. var key = this.buf1.name;
  31830. this.shift();
  31831. if (isEOF(this.buf1)) {
  31832. break;
  31833. }
  31834. dict.set(key, this.getObj(cipherTransform));
  31835. }
  31836. // parse image stream
  31837. var startPos = stream.pos;
  31838. // searching for the /EI\s/
  31839. var state = 0, ch, i, ii;
  31840. while (state !== 4 && (ch = stream.getByte()) !== -1) {
  31841. switch (ch | 0) {
  31842. case 0x20:
  31843. case 0x0D:
  31844. case 0x0A:
  31845. // let's check next five bytes to be ASCII... just be sure
  31846. var followingBytes = stream.peekBytes(5);
  31847. for (i = 0, ii = followingBytes.length; i < ii; i++) {
  31848. ch = followingBytes[i];
  31849. if (ch !== 0x0A && ch !== 0x0D && (ch < 0x20 || ch > 0x7F)) {
  31850. // not a LF, CR, SPACE or any visible ASCII character
  31851. state = 0;
  31852. break; // some binary stuff found, resetting the state
  31853. }
  31854. }
  31855. state = (state === 3 ? 4 : 0);
  31856. break;
  31857. case 0x45:
  31858. state = 2;
  31859. break;
  31860. case 0x49:
  31861. state = (state === 2 ? 3 : 0);
  31862. break;
  31863. default:
  31864. state = 0;
  31865. break;
  31866. }
  31867. }
  31868. var length = (stream.pos - 4) - startPos;
  31869. var imageStream = stream.makeSubStream(startPos, length, dict);
  31870. // trying to cache repeat images, first we are trying to "warm up" caching
  31871. // using length, then comparing adler32
  31872. var MAX_LENGTH_TO_CACHE = 1000;
  31873. var cacheImage = false, adler32;
  31874. if (length < MAX_LENGTH_TO_CACHE && this.imageCache.length === length) {
  31875. var imageBytes = imageStream.getBytes();
  31876. imageStream.reset();
  31877. var a = 1;
  31878. var b = 0;
  31879. for (i = 0, ii = imageBytes.length; i < ii; ++i) {
  31880. a = (a + (imageBytes[i] & 0xff)) % 65521;
  31881. b = (b + a) % 65521;
  31882. }
  31883. adler32 = (b << 16) | a;
  31884. if (this.imageCache.stream && this.imageCache.adler32 === adler32) {
  31885. this.buf2 = Cmd.get('EI');
  31886. this.shift();
  31887. this.imageCache.stream.reset();
  31888. return this.imageCache.stream;
  31889. }
  31890. cacheImage = true;
  31891. }
  31892. if (!cacheImage && !this.imageCache.stream) {
  31893. this.imageCache.length = length;
  31894. this.imageCache.stream = null;
  31895. }
  31896. if (cipherTransform) {
  31897. imageStream = cipherTransform.createStream(imageStream, length);
  31898. }
  31899. imageStream = this.filter(imageStream, dict, length);
  31900. imageStream.dict = dict;
  31901. if (cacheImage) {
  31902. imageStream.cacheKey = 'inline_' + length + '_' + adler32;
  31903. this.imageCache.adler32 = adler32;
  31904. this.imageCache.stream = imageStream;
  31905. }
  31906. this.buf2 = Cmd.get('EI');
  31907. this.shift();
  31908. return imageStream;
  31909. },
  31910. fetchIfRef: function Parser_fetchIfRef(obj) {
  31911. // not relying on the xref.fetchIfRef -- xref might not be set
  31912. return (isRef(obj) ? this.xref.fetch(obj) : obj);
  31913. },
  31914. makeStream: function Parser_makeStream(dict, cipherTransform) {
  31915. var lexer = this.lexer;
  31916. var stream = lexer.stream;
  31917. // get stream start position
  31918. lexer.skipToNextLine();
  31919. var pos = stream.pos - 1;
  31920. // get length
  31921. var length = this.fetchIfRef(dict.get('Length'));
  31922. if (!isInt(length)) {
  31923. info('Bad ' + length + ' attribute in stream');
  31924. length = 0;
  31925. }
  31926. // skip over the stream data
  31927. stream.pos = pos + length;
  31928. lexer.nextChar();
  31929. this.shift(); // '>>'
  31930. this.shift(); // 'stream'
  31931. if (!isCmd(this.buf1, 'endstream')) {
  31932. // bad stream length, scanning for endstream
  31933. stream.pos = pos;
  31934. var SCAN_BLOCK_SIZE = 2048;
  31935. var ENDSTREAM_SIGNATURE_LENGTH = 9;
  31936. var ENDSTREAM_SIGNATURE = [0x65, 0x6E, 0x64, 0x73, 0x74, 0x72, 0x65,
  31937. 0x61, 0x6D];
  31938. var skipped = 0, found = false, i, j;
  31939. while (stream.pos < stream.end) {
  31940. var scanBytes = stream.peekBytes(SCAN_BLOCK_SIZE);
  31941. var scanLength = scanBytes.length - ENDSTREAM_SIGNATURE_LENGTH;
  31942. if (scanLength <= 0) {
  31943. break;
  31944. }
  31945. found = false;
  31946. for (i = 0, j = 0; i < scanLength; i++) {
  31947. var b = scanBytes[i];
  31948. if (b !== ENDSTREAM_SIGNATURE[j]) {
  31949. i -= j;
  31950. j = 0;
  31951. } else {
  31952. j++;
  31953. if (j >= ENDSTREAM_SIGNATURE_LENGTH) {
  31954. i++;
  31955. found = true;
  31956. break;
  31957. }
  31958. }
  31959. }
  31960. if (found) {
  31961. skipped += i - ENDSTREAM_SIGNATURE_LENGTH;
  31962. stream.pos += i - ENDSTREAM_SIGNATURE_LENGTH;
  31963. break;
  31964. }
  31965. skipped += scanLength;
  31966. stream.pos += scanLength;
  31967. }
  31968. if (!found) {
  31969. error('Missing endstream');
  31970. }
  31971. length = skipped;
  31972. lexer.nextChar();
  31973. this.shift();
  31974. this.shift();
  31975. }
  31976. this.shift(); // 'endstream'
  31977. stream = stream.makeSubStream(pos, length, dict);
  31978. if (cipherTransform) {
  31979. stream = cipherTransform.createStream(stream, length);
  31980. }
  31981. stream = this.filter(stream, dict, length);
  31982. stream.dict = dict;
  31983. return stream;
  31984. },
  31985. filter: function Parser_filter(stream, dict, length) {
  31986. var filter = this.fetchIfRef(dict.get('Filter', 'F'));
  31987. var params = this.fetchIfRef(dict.get('DecodeParms', 'DP'));
  31988. if (isName(filter)) {
  31989. return this.makeFilter(stream, filter.name, length, params);
  31990. }
  31991. var maybeLength = length;
  31992. if (isArray(filter)) {
  31993. var filterArray = filter;
  31994. var paramsArray = params;
  31995. for (var i = 0, ii = filterArray.length; i < ii; ++i) {
  31996. filter = filterArray[i];
  31997. if (!isName(filter)) {
  31998. error('Bad filter name: ' + filter);
  31999. }
  32000. params = null;
  32001. if (isArray(paramsArray) && (i in paramsArray)) {
  32002. params = paramsArray[i];
  32003. }
  32004. stream = this.makeFilter(stream, filter.name, maybeLength, params);
  32005. // after the first stream the length variable is invalid
  32006. maybeLength = null;
  32007. }
  32008. }
  32009. return stream;
  32010. },
  32011. makeFilter: function Parser_makeFilter(stream, name, maybeLength, params) {
  32012. if (stream.dict.get('Length') === 0) {
  32013. return new NullStream(stream);
  32014. }
  32015. try {
  32016. var xrefStreamStats = this.xref.stats.streamTypes;
  32017. if (name === 'FlateDecode' || name === 'Fl') {
  32018. xrefStreamStats[StreamType.FLATE] = true;
  32019. if (params) {
  32020. return new PredictorStream(new FlateStream(stream, maybeLength),
  32021. maybeLength, params);
  32022. }
  32023. return new FlateStream(stream, maybeLength);
  32024. }
  32025. if (name === 'LZWDecode' || name === 'LZW') {
  32026. xrefStreamStats[StreamType.LZW] = true;
  32027. var earlyChange = 1;
  32028. if (params) {
  32029. if (params.has('EarlyChange')) {
  32030. earlyChange = params.get('EarlyChange');
  32031. }
  32032. return new PredictorStream(
  32033. new LZWStream(stream, maybeLength, earlyChange),
  32034. maybeLength, params);
  32035. }
  32036. return new LZWStream(stream, maybeLength, earlyChange);
  32037. }
  32038. if (name === 'DCTDecode' || name === 'DCT') {
  32039. xrefStreamStats[StreamType.DCT] = true;
  32040. return new JpegStream(stream, maybeLength, stream.dict, this.xref);
  32041. }
  32042. if (name === 'JPXDecode' || name === 'JPX') {
  32043. xrefStreamStats[StreamType.JPX] = true;
  32044. return new JpxStream(stream, maybeLength, stream.dict);
  32045. }
  32046. if (name === 'ASCII85Decode' || name === 'A85') {
  32047. xrefStreamStats[StreamType.A85] = true;
  32048. return new Ascii85Stream(stream, maybeLength);
  32049. }
  32050. if (name === 'ASCIIHexDecode' || name === 'AHx') {
  32051. xrefStreamStats[StreamType.AHX] = true;
  32052. return new AsciiHexStream(stream, maybeLength);
  32053. }
  32054. if (name === 'CCITTFaxDecode' || name === 'CCF') {
  32055. xrefStreamStats[StreamType.CCF] = true;
  32056. return new CCITTFaxStream(stream, maybeLength, params);
  32057. }
  32058. if (name === 'RunLengthDecode' || name === 'RL') {
  32059. xrefStreamStats[StreamType.RL] = true;
  32060. return new RunLengthStream(stream, maybeLength);
  32061. }
  32062. if (name === 'JBIG2Decode') {
  32063. xrefStreamStats[StreamType.JBIG] = true;
  32064. return new Jbig2Stream(stream, maybeLength, stream.dict);
  32065. }
  32066. warn('filter "' + name + '" not supported yet');
  32067. return stream;
  32068. } catch (ex) {
  32069. if (ex instanceof MissingDataException) {
  32070. throw ex;
  32071. }
  32072. warn('Invalid stream: \"' + ex + '\"');
  32073. return new NullStream(stream);
  32074. }
  32075. }
  32076. };
  32077. return Parser;
  32078. })();
  32079. var Lexer = (function LexerClosure() {
  32080. function Lexer(stream, knownCommands) {
  32081. this.stream = stream;
  32082. this.nextChar();
  32083. // While lexing, we build up many strings one char at a time. Using += for
  32084. // this can result in lots of garbage strings. It's better to build an
  32085. // array of single-char strings and then join() them together at the end.
  32086. // And reusing a single array (i.e. |this.strBuf|) over and over for this
  32087. // purpose uses less memory than using a new array for each string.
  32088. this.strBuf = [];
  32089. // The PDFs might have "glued" commands with other commands, operands or
  32090. // literals, e.g. "q1". The knownCommands is a dictionary of the valid
  32091. // commands and their prefixes. The prefixes are built the following way:
  32092. // if there a command that is a prefix of the other valid command or
  32093. // literal (e.g. 'f' and 'false') the following prefixes must be included,
  32094. // 'fa', 'fal', 'fals'. The prefixes are not needed, if the command has no
  32095. // other commands or literals as a prefix. The knowCommands is optional.
  32096. this.knownCommands = knownCommands;
  32097. }
  32098. Lexer.isSpace = function Lexer_isSpace(ch) {
  32099. // Space is one of the following characters: SPACE, TAB, CR or LF.
  32100. return (ch === 0x20 || ch === 0x09 || ch === 0x0D || ch === 0x0A);
  32101. };
  32102. // A '1' in this array means the character is white space. A '1' or
  32103. // '2' means the character ends a name or command.
  32104. var specialChars = [
  32105. 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, // 0x
  32106. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 1x
  32107. 1, 0, 0, 0, 0, 2, 0, 0, 2, 2, 0, 0, 0, 0, 0, 2, // 2x
  32108. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, // 3x
  32109. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 4x
  32110. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 5x
  32111. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 6x
  32112. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 7x
  32113. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 8x
  32114. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 9x
  32115. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ax
  32116. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // bx
  32117. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // cx
  32118. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // dx
  32119. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ex
  32120. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 // fx
  32121. ];
  32122. function toHexDigit(ch) {
  32123. if (ch >= 0x30 && ch <= 0x39) { // '0'-'9'
  32124. return ch & 0x0F;
  32125. }
  32126. if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
  32127. // 'A'-'F', 'a'-'f'
  32128. return (ch & 0x0F) + 9;
  32129. }
  32130. return -1;
  32131. }
  32132. Lexer.prototype = {
  32133. nextChar: function Lexer_nextChar() {
  32134. return (this.currentChar = this.stream.getByte());
  32135. },
  32136. peekChar: function Lexer_peekChar() {
  32137. return this.stream.peekBytes(1)[0];
  32138. },
  32139. getNumber: function Lexer_getNumber() {
  32140. var ch = this.currentChar;
  32141. var eNotation = false;
  32142. var divideBy = 0; // different from 0 if it's a floating point value
  32143. var sign = 1;
  32144. if (ch === 0x2D) { // '-'
  32145. sign = -1;
  32146. ch = this.nextChar();
  32147. } else if (ch === 0x2B) { // '+'
  32148. ch = this.nextChar();
  32149. }
  32150. if (ch === 0x2E) { // '.'
  32151. divideBy = 10;
  32152. ch = this.nextChar();
  32153. }
  32154. if (ch < 0x30 || ch > 0x39) { // '0' - '9'
  32155. error('Invalid number: ' + String.fromCharCode(ch));
  32156. return 0;
  32157. }
  32158. var baseValue = ch - 0x30; // '0'
  32159. var powerValue = 0;
  32160. var powerValueSign = 1;
  32161. while ((ch = this.nextChar()) >= 0) {
  32162. if (0x30 <= ch && ch <= 0x39) { // '0' - '9'
  32163. var currentDigit = ch - 0x30; // '0'
  32164. if (eNotation) { // We are after an 'e' or 'E'
  32165. powerValue = powerValue * 10 + currentDigit;
  32166. } else {
  32167. if (divideBy !== 0) { // We are after a point
  32168. divideBy *= 10;
  32169. }
  32170. baseValue = baseValue * 10 + currentDigit;
  32171. }
  32172. } else if (ch === 0x2E) { // '.'
  32173. if (divideBy === 0) {
  32174. divideBy = 1;
  32175. } else {
  32176. // A number can have only one '.'
  32177. break;
  32178. }
  32179. } else if (ch === 0x2D) { // '-'
  32180. // ignore minus signs in the middle of numbers to match
  32181. // Adobe's behavior
  32182. warn('Badly formated number');
  32183. } else if (ch === 0x45 || ch === 0x65) { // 'E', 'e'
  32184. // 'E' can be either a scientific notation or the beginning of a new
  32185. // operator
  32186. ch = this.peekChar();
  32187. if (ch === 0x2B || ch === 0x2D) { // '+', '-'
  32188. powerValueSign = (ch === 0x2D) ? -1 : 1;
  32189. this.nextChar(); // Consume the sign character
  32190. } else if (ch < 0x30 || ch > 0x39) { // '0' - '9'
  32191. // The 'E' must be the beginning of a new operator
  32192. break;
  32193. }
  32194. eNotation = true;
  32195. } else {
  32196. // the last character doesn't belong to us
  32197. break;
  32198. }
  32199. }
  32200. if (divideBy !== 0) {
  32201. baseValue /= divideBy;
  32202. }
  32203. if (eNotation) {
  32204. baseValue *= Math.pow(10, powerValueSign * powerValue);
  32205. }
  32206. return sign * baseValue;
  32207. },
  32208. getString: function Lexer_getString() {
  32209. var numParen = 1;
  32210. var done = false;
  32211. var strBuf = this.strBuf;
  32212. strBuf.length = 0;
  32213. var ch = this.nextChar();
  32214. while (true) {
  32215. var charBuffered = false;
  32216. switch (ch | 0) {
  32217. case -1:
  32218. warn('Unterminated string');
  32219. done = true;
  32220. break;
  32221. case 0x28: // '('
  32222. ++numParen;
  32223. strBuf.push('(');
  32224. break;
  32225. case 0x29: // ')'
  32226. if (--numParen === 0) {
  32227. this.nextChar(); // consume strings ')'
  32228. done = true;
  32229. } else {
  32230. strBuf.push(')');
  32231. }
  32232. break;
  32233. case 0x5C: // '\\'
  32234. ch = this.nextChar();
  32235. switch (ch) {
  32236. case -1:
  32237. warn('Unterminated string');
  32238. done = true;
  32239. break;
  32240. case 0x6E: // 'n'
  32241. strBuf.push('\n');
  32242. break;
  32243. case 0x72: // 'r'
  32244. strBuf.push('\r');
  32245. break;
  32246. case 0x74: // 't'
  32247. strBuf.push('\t');
  32248. break;
  32249. case 0x62: // 'b'
  32250. strBuf.push('\b');
  32251. break;
  32252. case 0x66: // 'f'
  32253. strBuf.push('\f');
  32254. break;
  32255. case 0x5C: // '\'
  32256. case 0x28: // '('
  32257. case 0x29: // ')'
  32258. strBuf.push(String.fromCharCode(ch));
  32259. break;
  32260. case 0x30: case 0x31: case 0x32: case 0x33: // '0'-'3'
  32261. case 0x34: case 0x35: case 0x36: case 0x37: // '4'-'7'
  32262. var x = ch & 0x0F;
  32263. ch = this.nextChar();
  32264. charBuffered = true;
  32265. if (ch >= 0x30 && ch <= 0x37) { // '0'-'7'
  32266. x = (x << 3) + (ch & 0x0F);
  32267. ch = this.nextChar();
  32268. if (ch >= 0x30 && ch <= 0x37) { // '0'-'7'
  32269. charBuffered = false;
  32270. x = (x << 3) + (ch & 0x0F);
  32271. }
  32272. }
  32273. strBuf.push(String.fromCharCode(x));
  32274. break;
  32275. case 0x0D: // CR
  32276. if (this.peekChar() === 0x0A) { // LF
  32277. this.nextChar();
  32278. }
  32279. break;
  32280. case 0x0A: // LF
  32281. break;
  32282. default:
  32283. strBuf.push(String.fromCharCode(ch));
  32284. break;
  32285. }
  32286. break;
  32287. default:
  32288. strBuf.push(String.fromCharCode(ch));
  32289. break;
  32290. }
  32291. if (done) {
  32292. break;
  32293. }
  32294. if (!charBuffered) {
  32295. ch = this.nextChar();
  32296. }
  32297. }
  32298. return strBuf.join('');
  32299. },
  32300. getName: function Lexer_getName() {
  32301. var ch;
  32302. var strBuf = this.strBuf;
  32303. strBuf.length = 0;
  32304. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  32305. if (ch === 0x23) { // '#'
  32306. ch = this.nextChar();
  32307. var x = toHexDigit(ch);
  32308. if (x !== -1) {
  32309. var x2 = toHexDigit(this.nextChar());
  32310. if (x2 === -1) {
  32311. error('Illegal digit in hex char in name: ' + x2);
  32312. }
  32313. strBuf.push(String.fromCharCode((x << 4) | x2));
  32314. } else {
  32315. strBuf.push('#', String.fromCharCode(ch));
  32316. }
  32317. } else {
  32318. strBuf.push(String.fromCharCode(ch));
  32319. }
  32320. }
  32321. if (strBuf.length > 128) {
  32322. error('Warning: name token is longer than allowed by the spec: ' +
  32323. strBuf.length);
  32324. }
  32325. return Name.get(strBuf.join(''));
  32326. },
  32327. getHexString: function Lexer_getHexString() {
  32328. var strBuf = this.strBuf;
  32329. strBuf.length = 0;
  32330. var ch = this.currentChar;
  32331. var isFirstHex = true;
  32332. var firstDigit;
  32333. var secondDigit;
  32334. while (true) {
  32335. if (ch < 0) {
  32336. warn('Unterminated hex string');
  32337. break;
  32338. } else if (ch === 0x3E) { // '>'
  32339. this.nextChar();
  32340. break;
  32341. } else if (specialChars[ch] === 1) {
  32342. ch = this.nextChar();
  32343. continue;
  32344. } else {
  32345. if (isFirstHex) {
  32346. firstDigit = toHexDigit(ch);
  32347. if (firstDigit === -1) {
  32348. warn('Ignoring invalid character "' + ch + '" in hex string');
  32349. ch = this.nextChar();
  32350. continue;
  32351. }
  32352. } else {
  32353. secondDigit = toHexDigit(ch);
  32354. if (secondDigit === -1) {
  32355. warn('Ignoring invalid character "' + ch + '" in hex string');
  32356. ch = this.nextChar();
  32357. continue;
  32358. }
  32359. strBuf.push(String.fromCharCode((firstDigit << 4) | secondDigit));
  32360. }
  32361. isFirstHex = !isFirstHex;
  32362. ch = this.nextChar();
  32363. }
  32364. }
  32365. return strBuf.join('');
  32366. },
  32367. getObj: function Lexer_getObj() {
  32368. // skip whitespace and comments
  32369. var comment = false;
  32370. var ch = this.currentChar;
  32371. while (true) {
  32372. if (ch < 0) {
  32373. return EOF;
  32374. }
  32375. if (comment) {
  32376. if (ch === 0x0A || ch === 0x0D) { // LF, CR
  32377. comment = false;
  32378. }
  32379. } else if (ch === 0x25) { // '%'
  32380. comment = true;
  32381. } else if (specialChars[ch] !== 1) {
  32382. break;
  32383. }
  32384. ch = this.nextChar();
  32385. }
  32386. // start reading token
  32387. switch (ch | 0) {
  32388. case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: // '0'-'4'
  32389. case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: // '5'-'9'
  32390. case 0x2B: case 0x2D: case 0x2E: // '+', '-', '.'
  32391. return this.getNumber();
  32392. case 0x28: // '('
  32393. return this.getString();
  32394. case 0x2F: // '/'
  32395. return this.getName();
  32396. // array punctuation
  32397. case 0x5B: // '['
  32398. this.nextChar();
  32399. return Cmd.get('[');
  32400. case 0x5D: // ']'
  32401. this.nextChar();
  32402. return Cmd.get(']');
  32403. // hex string or dict punctuation
  32404. case 0x3C: // '<'
  32405. ch = this.nextChar();
  32406. if (ch === 0x3C) {
  32407. // dict punctuation
  32408. this.nextChar();
  32409. return Cmd.get('<<');
  32410. }
  32411. return this.getHexString();
  32412. // dict punctuation
  32413. case 0x3E: // '>'
  32414. ch = this.nextChar();
  32415. if (ch === 0x3E) {
  32416. this.nextChar();
  32417. return Cmd.get('>>');
  32418. }
  32419. return Cmd.get('>');
  32420. case 0x7B: // '{'
  32421. this.nextChar();
  32422. return Cmd.get('{');
  32423. case 0x7D: // '}'
  32424. this.nextChar();
  32425. return Cmd.get('}');
  32426. case 0x29: // ')'
  32427. error('Illegal character: ' + ch);
  32428. break;
  32429. }
  32430. // command
  32431. var str = String.fromCharCode(ch);
  32432. var knownCommands = this.knownCommands;
  32433. var knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  32434. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  32435. // stop if known command is found and next character does not make
  32436. // the str a command
  32437. var possibleCommand = str + String.fromCharCode(ch);
  32438. if (knownCommandFound && knownCommands[possibleCommand] === undefined) {
  32439. break;
  32440. }
  32441. if (str.length === 128) {
  32442. error('Command token too long: ' + str.length);
  32443. }
  32444. str = possibleCommand;
  32445. knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  32446. }
  32447. if (str === 'true') {
  32448. return true;
  32449. }
  32450. if (str === 'false') {
  32451. return false;
  32452. }
  32453. if (str === 'null') {
  32454. return null;
  32455. }
  32456. return Cmd.get(str);
  32457. },
  32458. skipToNextLine: function Lexer_skipToNextLine() {
  32459. var ch = this.currentChar;
  32460. while (ch >= 0) {
  32461. if (ch === 0x0D) { // CR
  32462. ch = this.nextChar();
  32463. if (ch === 0x0A) { // LF
  32464. this.nextChar();
  32465. }
  32466. break;
  32467. } else if (ch === 0x0A) { // LF
  32468. this.nextChar();
  32469. break;
  32470. }
  32471. ch = this.nextChar();
  32472. }
  32473. }
  32474. };
  32475. return Lexer;
  32476. })();
  32477. var Linearization = {
  32478. create: function LinearizationCreate(stream) {
  32479. function getInt(name, allowZeroValue) {
  32480. var obj = linDict.get(name);
  32481. if (isInt(obj) && (allowZeroValue ? obj >= 0 : obj > 0)) {
  32482. return obj;
  32483. }
  32484. throw new Error('The "' + name + '" parameter in the linearization ' +
  32485. 'dictionary is invalid.');
  32486. }
  32487. function getHints() {
  32488. var hints = linDict.get('H'), hintsLength, item;
  32489. if (isArray(hints) &&
  32490. ((hintsLength = hints.length) === 2 || hintsLength === 4)) {
  32491. for (var index = 0; index < hintsLength; index++) {
  32492. if (!(isInt(item = hints[index]) && item > 0)) {
  32493. throw new Error('Hint (' + index +
  32494. ') in the linearization dictionary is invalid.');
  32495. }
  32496. }
  32497. return hints;
  32498. }
  32499. throw new Error('Hint array in the linearization dictionary is invalid.');
  32500. }
  32501. var parser = new Parser(new Lexer(stream), false, null);
  32502. var obj1 = parser.getObj();
  32503. var obj2 = parser.getObj();
  32504. var obj3 = parser.getObj();
  32505. var linDict = parser.getObj();
  32506. var obj, length;
  32507. if (!(isInt(obj1) && isInt(obj2) && isCmd(obj3, 'obj') && isDict(linDict) &&
  32508. isNum(obj = linDict.get('Linearized')) && obj > 0)) {
  32509. return null; // No valid linearization dictionary found.
  32510. } else if ((length = getInt('L')) !== stream.length) {
  32511. throw new Error('The "L" parameter in the linearization dictionary ' +
  32512. 'does not equal the stream length.');
  32513. }
  32514. return {
  32515. length: length,
  32516. hints: getHints(),
  32517. objectNumberFirst: getInt('O'),
  32518. endFirst: getInt('E'),
  32519. numPages: getInt('N'),
  32520. mainXRefEntriesOffset: getInt('T'),
  32521. pageFirst: (linDict.has('P') ? getInt('P', true) : 0)
  32522. };
  32523. }
  32524. };
  32525. var PostScriptParser = (function PostScriptParserClosure() {
  32526. function PostScriptParser(lexer) {
  32527. this.lexer = lexer;
  32528. this.operators = [];
  32529. this.token = null;
  32530. this.prev = null;
  32531. }
  32532. PostScriptParser.prototype = {
  32533. nextToken: function PostScriptParser_nextToken() {
  32534. this.prev = this.token;
  32535. this.token = this.lexer.getToken();
  32536. },
  32537. accept: function PostScriptParser_accept(type) {
  32538. if (this.token.type === type) {
  32539. this.nextToken();
  32540. return true;
  32541. }
  32542. return false;
  32543. },
  32544. expect: function PostScriptParser_expect(type) {
  32545. if (this.accept(type)) {
  32546. return true;
  32547. }
  32548. error('Unexpected symbol: found ' + this.token.type + ' expected ' +
  32549. type + '.');
  32550. },
  32551. parse: function PostScriptParser_parse() {
  32552. this.nextToken();
  32553. this.expect(PostScriptTokenTypes.LBRACE);
  32554. this.parseBlock();
  32555. this.expect(PostScriptTokenTypes.RBRACE);
  32556. return this.operators;
  32557. },
  32558. parseBlock: function PostScriptParser_parseBlock() {
  32559. while (true) {
  32560. if (this.accept(PostScriptTokenTypes.NUMBER)) {
  32561. this.operators.push(this.prev.value);
  32562. } else if (this.accept(PostScriptTokenTypes.OPERATOR)) {
  32563. this.operators.push(this.prev.value);
  32564. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  32565. this.parseCondition();
  32566. } else {
  32567. return;
  32568. }
  32569. }
  32570. },
  32571. parseCondition: function PostScriptParser_parseCondition() {
  32572. // Add two place holders that will be updated later
  32573. var conditionLocation = this.operators.length;
  32574. this.operators.push(null, null);
  32575. this.parseBlock();
  32576. this.expect(PostScriptTokenTypes.RBRACE);
  32577. if (this.accept(PostScriptTokenTypes.IF)) {
  32578. // The true block is right after the 'if' so it just falls through on
  32579. // true else it jumps and skips the true block.
  32580. this.operators[conditionLocation] = this.operators.length;
  32581. this.operators[conditionLocation + 1] = 'jz';
  32582. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  32583. var jumpLocation = this.operators.length;
  32584. this.operators.push(null, null);
  32585. var endOfTrue = this.operators.length;
  32586. this.parseBlock();
  32587. this.expect(PostScriptTokenTypes.RBRACE);
  32588. this.expect(PostScriptTokenTypes.IFELSE);
  32589. // The jump is added at the end of the true block to skip the false
  32590. // block.
  32591. this.operators[jumpLocation] = this.operators.length;
  32592. this.operators[jumpLocation + 1] = 'j';
  32593. this.operators[conditionLocation] = endOfTrue;
  32594. this.operators[conditionLocation + 1] = 'jz';
  32595. } else {
  32596. error('PS Function: error parsing conditional.');
  32597. }
  32598. }
  32599. };
  32600. return PostScriptParser;
  32601. })();
  32602. var PostScriptTokenTypes = {
  32603. LBRACE: 0,
  32604. RBRACE: 1,
  32605. NUMBER: 2,
  32606. OPERATOR: 3,
  32607. IF: 4,
  32608. IFELSE: 5
  32609. };
  32610. var PostScriptToken = (function PostScriptTokenClosure() {
  32611. function PostScriptToken(type, value) {
  32612. this.type = type;
  32613. this.value = value;
  32614. }
  32615. var opCache = {};
  32616. PostScriptToken.getOperator = function PostScriptToken_getOperator(op) {
  32617. var opValue = opCache[op];
  32618. if (opValue) {
  32619. return opValue;
  32620. }
  32621. return opCache[op] = new PostScriptToken(PostScriptTokenTypes.OPERATOR, op);
  32622. };
  32623. PostScriptToken.LBRACE = new PostScriptToken(PostScriptTokenTypes.LBRACE,
  32624. '{');
  32625. PostScriptToken.RBRACE = new PostScriptToken(PostScriptTokenTypes.RBRACE,
  32626. '}');
  32627. PostScriptToken.IF = new PostScriptToken(PostScriptTokenTypes.IF, 'IF');
  32628. PostScriptToken.IFELSE = new PostScriptToken(PostScriptTokenTypes.IFELSE,
  32629. 'IFELSE');
  32630. return PostScriptToken;
  32631. })();
  32632. var PostScriptLexer = (function PostScriptLexerClosure() {
  32633. function PostScriptLexer(stream) {
  32634. this.stream = stream;
  32635. this.nextChar();
  32636. this.strBuf = [];
  32637. }
  32638. PostScriptLexer.prototype = {
  32639. nextChar: function PostScriptLexer_nextChar() {
  32640. return (this.currentChar = this.stream.getByte());
  32641. },
  32642. getToken: function PostScriptLexer_getToken() {
  32643. var comment = false;
  32644. var ch = this.currentChar;
  32645. // skip comments
  32646. while (true) {
  32647. if (ch < 0) {
  32648. return EOF;
  32649. }
  32650. if (comment) {
  32651. if (ch === 0x0A || ch === 0x0D) {
  32652. comment = false;
  32653. }
  32654. } else if (ch === 0x25) { // '%'
  32655. comment = true;
  32656. } else if (!Lexer.isSpace(ch)) {
  32657. break;
  32658. }
  32659. ch = this.nextChar();
  32660. }
  32661. switch (ch | 0) {
  32662. case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: // '0'-'4'
  32663. case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: // '5'-'9'
  32664. case 0x2B: case 0x2D: case 0x2E: // '+', '-', '.'
  32665. return new PostScriptToken(PostScriptTokenTypes.NUMBER,
  32666. this.getNumber());
  32667. case 0x7B: // '{'
  32668. this.nextChar();
  32669. return PostScriptToken.LBRACE;
  32670. case 0x7D: // '}'
  32671. this.nextChar();
  32672. return PostScriptToken.RBRACE;
  32673. }
  32674. // operator
  32675. var strBuf = this.strBuf;
  32676. strBuf.length = 0;
  32677. strBuf[0] = String.fromCharCode(ch);
  32678. while ((ch = this.nextChar()) >= 0 && // and 'A'-'Z', 'a'-'z'
  32679. ((ch >= 0x41 && ch <= 0x5A) || (ch >= 0x61 && ch <= 0x7A))) {
  32680. strBuf.push(String.fromCharCode(ch));
  32681. }
  32682. var str = strBuf.join('');
  32683. switch (str.toLowerCase()) {
  32684. case 'if':
  32685. return PostScriptToken.IF;
  32686. case 'ifelse':
  32687. return PostScriptToken.IFELSE;
  32688. default:
  32689. return PostScriptToken.getOperator(str);
  32690. }
  32691. },
  32692. getNumber: function PostScriptLexer_getNumber() {
  32693. var ch = this.currentChar;
  32694. var strBuf = this.strBuf;
  32695. strBuf.length = 0;
  32696. strBuf[0] = String.fromCharCode(ch);
  32697. while ((ch = this.nextChar()) >= 0) {
  32698. if ((ch >= 0x30 && ch <= 0x39) || // '0'-'9'
  32699. ch === 0x2D || ch === 0x2E) { // '-', '.'
  32700. strBuf.push(String.fromCharCode(ch));
  32701. } else {
  32702. break;
  32703. }
  32704. }
  32705. var value = parseFloat(strBuf.join(''));
  32706. if (isNaN(value)) {
  32707. error('Invalid floating point number: ' + value);
  32708. }
  32709. return value;
  32710. }
  32711. };
  32712. return PostScriptLexer;
  32713. })();
  32714. var Stream = (function StreamClosure() {
  32715. function Stream(arrayBuffer, start, length, dict) {
  32716. this.bytes = (arrayBuffer instanceof Uint8Array ?
  32717. arrayBuffer : new Uint8Array(arrayBuffer));
  32718. this.start = start || 0;
  32719. this.pos = this.start;
  32720. this.end = (start + length) || this.bytes.length;
  32721. this.dict = dict;
  32722. }
  32723. // required methods for a stream. if a particular stream does not
  32724. // implement these, an error should be thrown
  32725. Stream.prototype = {
  32726. get length() {
  32727. return this.end - this.start;
  32728. },
  32729. get isEmpty() {
  32730. return this.length === 0;
  32731. },
  32732. getByte: function Stream_getByte() {
  32733. if (this.pos >= this.end) {
  32734. return -1;
  32735. }
  32736. return this.bytes[this.pos++];
  32737. },
  32738. getUint16: function Stream_getUint16() {
  32739. var b0 = this.getByte();
  32740. var b1 = this.getByte();
  32741. return (b0 << 8) + b1;
  32742. },
  32743. getInt32: function Stream_getInt32() {
  32744. var b0 = this.getByte();
  32745. var b1 = this.getByte();
  32746. var b2 = this.getByte();
  32747. var b3 = this.getByte();
  32748. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  32749. },
  32750. // returns subarray of original buffer
  32751. // should only be read
  32752. getBytes: function Stream_getBytes(length) {
  32753. var bytes = this.bytes;
  32754. var pos = this.pos;
  32755. var strEnd = this.end;
  32756. if (!length) {
  32757. return bytes.subarray(pos, strEnd);
  32758. }
  32759. var end = pos + length;
  32760. if (end > strEnd) {
  32761. end = strEnd;
  32762. }
  32763. this.pos = end;
  32764. return bytes.subarray(pos, end);
  32765. },
  32766. peekBytes: function Stream_peekBytes(length) {
  32767. var bytes = this.getBytes(length);
  32768. this.pos -= bytes.length;
  32769. return bytes;
  32770. },
  32771. skip: function Stream_skip(n) {
  32772. if (!n) {
  32773. n = 1;
  32774. }
  32775. this.pos += n;
  32776. },
  32777. reset: function Stream_reset() {
  32778. this.pos = this.start;
  32779. },
  32780. moveStart: function Stream_moveStart() {
  32781. this.start = this.pos;
  32782. },
  32783. makeSubStream: function Stream_makeSubStream(start, length, dict) {
  32784. return new Stream(this.bytes.buffer, start, length, dict);
  32785. },
  32786. isStream: true
  32787. };
  32788. return Stream;
  32789. })();
  32790. var StringStream = (function StringStreamClosure() {
  32791. function StringStream(str) {
  32792. var length = str.length;
  32793. var bytes = new Uint8Array(length);
  32794. for (var n = 0; n < length; ++n) {
  32795. bytes[n] = str.charCodeAt(n);
  32796. }
  32797. Stream.call(this, bytes);
  32798. }
  32799. StringStream.prototype = Stream.prototype;
  32800. return StringStream;
  32801. })();
  32802. // super class for the decoding streams
  32803. var DecodeStream = (function DecodeStreamClosure() {
  32804. // Lots of DecodeStreams are created whose buffers are never used. For these
  32805. // we share a single empty buffer. This is (a) space-efficient and (b) avoids
  32806. // having special cases that would be required if we used |null| for an empty
  32807. // buffer.
  32808. var emptyBuffer = new Uint8Array(0);
  32809. function DecodeStream(maybeMinBufferLength) {
  32810. this.pos = 0;
  32811. this.bufferLength = 0;
  32812. this.eof = false;
  32813. this.buffer = emptyBuffer;
  32814. this.minBufferLength = 512;
  32815. if (maybeMinBufferLength) {
  32816. // Compute the first power of two that is as big as maybeMinBufferLength.
  32817. while (this.minBufferLength < maybeMinBufferLength) {
  32818. this.minBufferLength *= 2;
  32819. }
  32820. }
  32821. }
  32822. DecodeStream.prototype = {
  32823. get isEmpty() {
  32824. while (!this.eof && this.bufferLength === 0) {
  32825. this.readBlock();
  32826. }
  32827. return this.bufferLength === 0;
  32828. },
  32829. ensureBuffer: function DecodeStream_ensureBuffer(requested) {
  32830. var buffer = this.buffer;
  32831. if (requested <= buffer.byteLength) {
  32832. return buffer;
  32833. }
  32834. var size = this.minBufferLength;
  32835. while (size < requested) {
  32836. size *= 2;
  32837. }
  32838. var buffer2 = new Uint8Array(size);
  32839. buffer2.set(buffer);
  32840. return (this.buffer = buffer2);
  32841. },
  32842. getByte: function DecodeStream_getByte() {
  32843. var pos = this.pos;
  32844. while (this.bufferLength <= pos) {
  32845. if (this.eof) {
  32846. return -1;
  32847. }
  32848. this.readBlock();
  32849. }
  32850. return this.buffer[this.pos++];
  32851. },
  32852. getUint16: function DecodeStream_getUint16() {
  32853. var b0 = this.getByte();
  32854. var b1 = this.getByte();
  32855. return (b0 << 8) + b1;
  32856. },
  32857. getInt32: function DecodeStream_getInt32() {
  32858. var b0 = this.getByte();
  32859. var b1 = this.getByte();
  32860. var b2 = this.getByte();
  32861. var b3 = this.getByte();
  32862. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  32863. },
  32864. getBytes: function DecodeStream_getBytes(length) {
  32865. var end, pos = this.pos;
  32866. if (length) {
  32867. this.ensureBuffer(pos + length);
  32868. end = pos + length;
  32869. while (!this.eof && this.bufferLength < end) {
  32870. this.readBlock();
  32871. }
  32872. var bufEnd = this.bufferLength;
  32873. if (end > bufEnd) {
  32874. end = bufEnd;
  32875. }
  32876. } else {
  32877. while (!this.eof) {
  32878. this.readBlock();
  32879. }
  32880. end = this.bufferLength;
  32881. }
  32882. this.pos = end;
  32883. return this.buffer.subarray(pos, end);
  32884. },
  32885. peekBytes: function DecodeStream_peekBytes(length) {
  32886. var bytes = this.getBytes(length);
  32887. this.pos -= bytes.length;
  32888. return bytes;
  32889. },
  32890. makeSubStream: function DecodeStream_makeSubStream(start, length, dict) {
  32891. var end = start + length;
  32892. while (this.bufferLength <= end && !this.eof) {
  32893. this.readBlock();
  32894. }
  32895. return new Stream(this.buffer, start, length, dict);
  32896. },
  32897. skip: function DecodeStream_skip(n) {
  32898. if (!n) {
  32899. n = 1;
  32900. }
  32901. this.pos += n;
  32902. },
  32903. reset: function DecodeStream_reset() {
  32904. this.pos = 0;
  32905. },
  32906. getBaseStreams: function DecodeStream_getBaseStreams() {
  32907. if (this.str && this.str.getBaseStreams) {
  32908. return this.str.getBaseStreams();
  32909. }
  32910. return [];
  32911. }
  32912. };
  32913. return DecodeStream;
  32914. })();
  32915. var StreamsSequenceStream = (function StreamsSequenceStreamClosure() {
  32916. function StreamsSequenceStream(streams) {
  32917. this.streams = streams;
  32918. DecodeStream.call(this, /* maybeLength = */ null);
  32919. }
  32920. StreamsSequenceStream.prototype = Object.create(DecodeStream.prototype);
  32921. StreamsSequenceStream.prototype.readBlock =
  32922. function streamSequenceStreamReadBlock() {
  32923. var streams = this.streams;
  32924. if (streams.length === 0) {
  32925. this.eof = true;
  32926. return;
  32927. }
  32928. var stream = streams.shift();
  32929. var chunk = stream.getBytes();
  32930. var bufferLength = this.bufferLength;
  32931. var newLength = bufferLength + chunk.length;
  32932. var buffer = this.ensureBuffer(newLength);
  32933. buffer.set(chunk, bufferLength);
  32934. this.bufferLength = newLength;
  32935. };
  32936. StreamsSequenceStream.prototype.getBaseStreams =
  32937. function StreamsSequenceStream_getBaseStreams() {
  32938. var baseStreams = [];
  32939. for (var i = 0, ii = this.streams.length; i < ii; i++) {
  32940. var stream = this.streams[i];
  32941. if (stream.getBaseStreams) {
  32942. Util.appendToArray(baseStreams, stream.getBaseStreams());
  32943. }
  32944. }
  32945. return baseStreams;
  32946. };
  32947. return StreamsSequenceStream;
  32948. })();
  32949. var FlateStream = (function FlateStreamClosure() {
  32950. var codeLenCodeMap = new Uint32Array([
  32951. 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15
  32952. ]);
  32953. var lengthDecode = new Uint32Array([
  32954. 0x00003, 0x00004, 0x00005, 0x00006, 0x00007, 0x00008, 0x00009, 0x0000a,
  32955. 0x1000b, 0x1000d, 0x1000f, 0x10011, 0x20013, 0x20017, 0x2001b, 0x2001f,
  32956. 0x30023, 0x3002b, 0x30033, 0x3003b, 0x40043, 0x40053, 0x40063, 0x40073,
  32957. 0x50083, 0x500a3, 0x500c3, 0x500e3, 0x00102, 0x00102, 0x00102
  32958. ]);
  32959. var distDecode = new Uint32Array([
  32960. 0x00001, 0x00002, 0x00003, 0x00004, 0x10005, 0x10007, 0x20009, 0x2000d,
  32961. 0x30011, 0x30019, 0x40021, 0x40031, 0x50041, 0x50061, 0x60081, 0x600c1,
  32962. 0x70101, 0x70181, 0x80201, 0x80301, 0x90401, 0x90601, 0xa0801, 0xa0c01,
  32963. 0xb1001, 0xb1801, 0xc2001, 0xc3001, 0xd4001, 0xd6001
  32964. ]);
  32965. var fixedLitCodeTab = [new Uint32Array([
  32966. 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c0,
  32967. 0x70108, 0x80060, 0x80020, 0x900a0, 0x80000, 0x80080, 0x80040, 0x900e0,
  32968. 0x70104, 0x80058, 0x80018, 0x90090, 0x70114, 0x80078, 0x80038, 0x900d0,
  32969. 0x7010c, 0x80068, 0x80028, 0x900b0, 0x80008, 0x80088, 0x80048, 0x900f0,
  32970. 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c8,
  32971. 0x7010a, 0x80064, 0x80024, 0x900a8, 0x80004, 0x80084, 0x80044, 0x900e8,
  32972. 0x70106, 0x8005c, 0x8001c, 0x90098, 0x70116, 0x8007c, 0x8003c, 0x900d8,
  32973. 0x7010e, 0x8006c, 0x8002c, 0x900b8, 0x8000c, 0x8008c, 0x8004c, 0x900f8,
  32974. 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c4,
  32975. 0x70109, 0x80062, 0x80022, 0x900a4, 0x80002, 0x80082, 0x80042, 0x900e4,
  32976. 0x70105, 0x8005a, 0x8001a, 0x90094, 0x70115, 0x8007a, 0x8003a, 0x900d4,
  32977. 0x7010d, 0x8006a, 0x8002a, 0x900b4, 0x8000a, 0x8008a, 0x8004a, 0x900f4,
  32978. 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cc,
  32979. 0x7010b, 0x80066, 0x80026, 0x900ac, 0x80006, 0x80086, 0x80046, 0x900ec,
  32980. 0x70107, 0x8005e, 0x8001e, 0x9009c, 0x70117, 0x8007e, 0x8003e, 0x900dc,
  32981. 0x7010f, 0x8006e, 0x8002e, 0x900bc, 0x8000e, 0x8008e, 0x8004e, 0x900fc,
  32982. 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c2,
  32983. 0x70108, 0x80061, 0x80021, 0x900a2, 0x80001, 0x80081, 0x80041, 0x900e2,
  32984. 0x70104, 0x80059, 0x80019, 0x90092, 0x70114, 0x80079, 0x80039, 0x900d2,
  32985. 0x7010c, 0x80069, 0x80029, 0x900b2, 0x80009, 0x80089, 0x80049, 0x900f2,
  32986. 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900ca,
  32987. 0x7010a, 0x80065, 0x80025, 0x900aa, 0x80005, 0x80085, 0x80045, 0x900ea,
  32988. 0x70106, 0x8005d, 0x8001d, 0x9009a, 0x70116, 0x8007d, 0x8003d, 0x900da,
  32989. 0x7010e, 0x8006d, 0x8002d, 0x900ba, 0x8000d, 0x8008d, 0x8004d, 0x900fa,
  32990. 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c6,
  32991. 0x70109, 0x80063, 0x80023, 0x900a6, 0x80003, 0x80083, 0x80043, 0x900e6,
  32992. 0x70105, 0x8005b, 0x8001b, 0x90096, 0x70115, 0x8007b, 0x8003b, 0x900d6,
  32993. 0x7010d, 0x8006b, 0x8002b, 0x900b6, 0x8000b, 0x8008b, 0x8004b, 0x900f6,
  32994. 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900ce,
  32995. 0x7010b, 0x80067, 0x80027, 0x900ae, 0x80007, 0x80087, 0x80047, 0x900ee,
  32996. 0x70107, 0x8005f, 0x8001f, 0x9009e, 0x70117, 0x8007f, 0x8003f, 0x900de,
  32997. 0x7010f, 0x8006f, 0x8002f, 0x900be, 0x8000f, 0x8008f, 0x8004f, 0x900fe,
  32998. 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c1,
  32999. 0x70108, 0x80060, 0x80020, 0x900a1, 0x80000, 0x80080, 0x80040, 0x900e1,
  33000. 0x70104, 0x80058, 0x80018, 0x90091, 0x70114, 0x80078, 0x80038, 0x900d1,
  33001. 0x7010c, 0x80068, 0x80028, 0x900b1, 0x80008, 0x80088, 0x80048, 0x900f1,
  33002. 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c9,
  33003. 0x7010a, 0x80064, 0x80024, 0x900a9, 0x80004, 0x80084, 0x80044, 0x900e9,
  33004. 0x70106, 0x8005c, 0x8001c, 0x90099, 0x70116, 0x8007c, 0x8003c, 0x900d9,
  33005. 0x7010e, 0x8006c, 0x8002c, 0x900b9, 0x8000c, 0x8008c, 0x8004c, 0x900f9,
  33006. 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c5,
  33007. 0x70109, 0x80062, 0x80022, 0x900a5, 0x80002, 0x80082, 0x80042, 0x900e5,
  33008. 0x70105, 0x8005a, 0x8001a, 0x90095, 0x70115, 0x8007a, 0x8003a, 0x900d5,
  33009. 0x7010d, 0x8006a, 0x8002a, 0x900b5, 0x8000a, 0x8008a, 0x8004a, 0x900f5,
  33010. 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cd,
  33011. 0x7010b, 0x80066, 0x80026, 0x900ad, 0x80006, 0x80086, 0x80046, 0x900ed,
  33012. 0x70107, 0x8005e, 0x8001e, 0x9009d, 0x70117, 0x8007e, 0x8003e, 0x900dd,
  33013. 0x7010f, 0x8006e, 0x8002e, 0x900bd, 0x8000e, 0x8008e, 0x8004e, 0x900fd,
  33014. 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c3,
  33015. 0x70108, 0x80061, 0x80021, 0x900a3, 0x80001, 0x80081, 0x80041, 0x900e3,
  33016. 0x70104, 0x80059, 0x80019, 0x90093, 0x70114, 0x80079, 0x80039, 0x900d3,
  33017. 0x7010c, 0x80069, 0x80029, 0x900b3, 0x80009, 0x80089, 0x80049, 0x900f3,
  33018. 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900cb,
  33019. 0x7010a, 0x80065, 0x80025, 0x900ab, 0x80005, 0x80085, 0x80045, 0x900eb,
  33020. 0x70106, 0x8005d, 0x8001d, 0x9009b, 0x70116, 0x8007d, 0x8003d, 0x900db,
  33021. 0x7010e, 0x8006d, 0x8002d, 0x900bb, 0x8000d, 0x8008d, 0x8004d, 0x900fb,
  33022. 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c7,
  33023. 0x70109, 0x80063, 0x80023, 0x900a7, 0x80003, 0x80083, 0x80043, 0x900e7,
  33024. 0x70105, 0x8005b, 0x8001b, 0x90097, 0x70115, 0x8007b, 0x8003b, 0x900d7,
  33025. 0x7010d, 0x8006b, 0x8002b, 0x900b7, 0x8000b, 0x8008b, 0x8004b, 0x900f7,
  33026. 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900cf,
  33027. 0x7010b, 0x80067, 0x80027, 0x900af, 0x80007, 0x80087, 0x80047, 0x900ef,
  33028. 0x70107, 0x8005f, 0x8001f, 0x9009f, 0x70117, 0x8007f, 0x8003f, 0x900df,
  33029. 0x7010f, 0x8006f, 0x8002f, 0x900bf, 0x8000f, 0x8008f, 0x8004f, 0x900ff
  33030. ]), 9];
  33031. var fixedDistCodeTab = [new Uint32Array([
  33032. 0x50000, 0x50010, 0x50008, 0x50018, 0x50004, 0x50014, 0x5000c, 0x5001c,
  33033. 0x50002, 0x50012, 0x5000a, 0x5001a, 0x50006, 0x50016, 0x5000e, 0x00000,
  33034. 0x50001, 0x50011, 0x50009, 0x50019, 0x50005, 0x50015, 0x5000d, 0x5001d,
  33035. 0x50003, 0x50013, 0x5000b, 0x5001b, 0x50007, 0x50017, 0x5000f, 0x00000
  33036. ]), 5];
  33037. function FlateStream(str, maybeLength) {
  33038. this.str = str;
  33039. this.dict = str.dict;
  33040. var cmf = str.getByte();
  33041. var flg = str.getByte();
  33042. if (cmf === -1 || flg === -1) {
  33043. error('Invalid header in flate stream: ' + cmf + ', ' + flg);
  33044. }
  33045. if ((cmf & 0x0f) !== 0x08) {
  33046. error('Unknown compression method in flate stream: ' + cmf + ', ' + flg);
  33047. }
  33048. if ((((cmf << 8) + flg) % 31) !== 0) {
  33049. error('Bad FCHECK in flate stream: ' + cmf + ', ' + flg);
  33050. }
  33051. if (flg & 0x20) {
  33052. error('FDICT bit set in flate stream: ' + cmf + ', ' + flg);
  33053. }
  33054. this.codeSize = 0;
  33055. this.codeBuf = 0;
  33056. DecodeStream.call(this, maybeLength);
  33057. }
  33058. FlateStream.prototype = Object.create(DecodeStream.prototype);
  33059. FlateStream.prototype.getBits = function FlateStream_getBits(bits) {
  33060. var str = this.str;
  33061. var codeSize = this.codeSize;
  33062. var codeBuf = this.codeBuf;
  33063. var b;
  33064. while (codeSize < bits) {
  33065. if ((b = str.getByte()) === -1) {
  33066. error('Bad encoding in flate stream');
  33067. }
  33068. codeBuf |= b << codeSize;
  33069. codeSize += 8;
  33070. }
  33071. b = codeBuf & ((1 << bits) - 1);
  33072. this.codeBuf = codeBuf >> bits;
  33073. this.codeSize = codeSize -= bits;
  33074. return b;
  33075. };
  33076. FlateStream.prototype.getCode = function FlateStream_getCode(table) {
  33077. var str = this.str;
  33078. var codes = table[0];
  33079. var maxLen = table[1];
  33080. var codeSize = this.codeSize;
  33081. var codeBuf = this.codeBuf;
  33082. var b;
  33083. while (codeSize < maxLen) {
  33084. if ((b = str.getByte()) === -1) {
  33085. // premature end of stream. code might however still be valid.
  33086. // codeSize < codeLen check below guards against incomplete codeVal.
  33087. break;
  33088. }
  33089. codeBuf |= (b << codeSize);
  33090. codeSize += 8;
  33091. }
  33092. var code = codes[codeBuf & ((1 << maxLen) - 1)];
  33093. var codeLen = code >> 16;
  33094. var codeVal = code & 0xffff;
  33095. if (codeLen < 1 || codeSize < codeLen) {
  33096. error('Bad encoding in flate stream');
  33097. }
  33098. this.codeBuf = (codeBuf >> codeLen);
  33099. this.codeSize = (codeSize - codeLen);
  33100. return codeVal;
  33101. };
  33102. FlateStream.prototype.generateHuffmanTable =
  33103. function flateStreamGenerateHuffmanTable(lengths) {
  33104. var n = lengths.length;
  33105. // find max code length
  33106. var maxLen = 0;
  33107. var i;
  33108. for (i = 0; i < n; ++i) {
  33109. if (lengths[i] > maxLen) {
  33110. maxLen = lengths[i];
  33111. }
  33112. }
  33113. // build the table
  33114. var size = 1 << maxLen;
  33115. var codes = new Uint32Array(size);
  33116. for (var len = 1, code = 0, skip = 2;
  33117. len <= maxLen;
  33118. ++len, code <<= 1, skip <<= 1) {
  33119. for (var val = 0; val < n; ++val) {
  33120. if (lengths[val] === len) {
  33121. // bit-reverse the code
  33122. var code2 = 0;
  33123. var t = code;
  33124. for (i = 0; i < len; ++i) {
  33125. code2 = (code2 << 1) | (t & 1);
  33126. t >>= 1;
  33127. }
  33128. // fill the table entries
  33129. for (i = code2; i < size; i += skip) {
  33130. codes[i] = (len << 16) | val;
  33131. }
  33132. ++code;
  33133. }
  33134. }
  33135. }
  33136. return [codes, maxLen];
  33137. };
  33138. FlateStream.prototype.readBlock = function FlateStream_readBlock() {
  33139. var buffer, len;
  33140. var str = this.str;
  33141. // read block header
  33142. var hdr = this.getBits(3);
  33143. if (hdr & 1) {
  33144. this.eof = true;
  33145. }
  33146. hdr >>= 1;
  33147. if (hdr === 0) { // uncompressed block
  33148. var b;
  33149. if ((b = str.getByte()) === -1) {
  33150. error('Bad block header in flate stream');
  33151. }
  33152. var blockLen = b;
  33153. if ((b = str.getByte()) === -1) {
  33154. error('Bad block header in flate stream');
  33155. }
  33156. blockLen |= (b << 8);
  33157. if ((b = str.getByte()) === -1) {
  33158. error('Bad block header in flate stream');
  33159. }
  33160. var check = b;
  33161. if ((b = str.getByte()) === -1) {
  33162. error('Bad block header in flate stream');
  33163. }
  33164. check |= (b << 8);
  33165. if (check !== (~blockLen & 0xffff) &&
  33166. (blockLen !== 0 || check !== 0)) {
  33167. // Ignoring error for bad "empty" block (see issue 1277)
  33168. error('Bad uncompressed block length in flate stream');
  33169. }
  33170. this.codeBuf = 0;
  33171. this.codeSize = 0;
  33172. var bufferLength = this.bufferLength;
  33173. buffer = this.ensureBuffer(bufferLength + blockLen);
  33174. var end = bufferLength + blockLen;
  33175. this.bufferLength = end;
  33176. if (blockLen === 0) {
  33177. if (str.peekBytes(1).length === 0) {
  33178. this.eof = true;
  33179. }
  33180. } else {
  33181. for (var n = bufferLength; n < end; ++n) {
  33182. if ((b = str.getByte()) === -1) {
  33183. this.eof = true;
  33184. break;
  33185. }
  33186. buffer[n] = b;
  33187. }
  33188. }
  33189. return;
  33190. }
  33191. var litCodeTable;
  33192. var distCodeTable;
  33193. if (hdr === 1) { // compressed block, fixed codes
  33194. litCodeTable = fixedLitCodeTab;
  33195. distCodeTable = fixedDistCodeTab;
  33196. } else if (hdr === 2) { // compressed block, dynamic codes
  33197. var numLitCodes = this.getBits(5) + 257;
  33198. var numDistCodes = this.getBits(5) + 1;
  33199. var numCodeLenCodes = this.getBits(4) + 4;
  33200. // build the code lengths code table
  33201. var codeLenCodeLengths = new Uint8Array(codeLenCodeMap.length);
  33202. var i;
  33203. for (i = 0; i < numCodeLenCodes; ++i) {
  33204. codeLenCodeLengths[codeLenCodeMap[i]] = this.getBits(3);
  33205. }
  33206. var codeLenCodeTab = this.generateHuffmanTable(codeLenCodeLengths);
  33207. // build the literal and distance code tables
  33208. len = 0;
  33209. i = 0;
  33210. var codes = numLitCodes + numDistCodes;
  33211. var codeLengths = new Uint8Array(codes);
  33212. var bitsLength, bitsOffset, what;
  33213. while (i < codes) {
  33214. var code = this.getCode(codeLenCodeTab);
  33215. if (code === 16) {
  33216. bitsLength = 2; bitsOffset = 3; what = len;
  33217. } else if (code === 17) {
  33218. bitsLength = 3; bitsOffset = 3; what = (len = 0);
  33219. } else if (code === 18) {
  33220. bitsLength = 7; bitsOffset = 11; what = (len = 0);
  33221. } else {
  33222. codeLengths[i++] = len = code;
  33223. continue;
  33224. }
  33225. var repeatLength = this.getBits(bitsLength) + bitsOffset;
  33226. while (repeatLength-- > 0) {
  33227. codeLengths[i++] = what;
  33228. }
  33229. }
  33230. litCodeTable =
  33231. this.generateHuffmanTable(codeLengths.subarray(0, numLitCodes));
  33232. distCodeTable =
  33233. this.generateHuffmanTable(codeLengths.subarray(numLitCodes, codes));
  33234. } else {
  33235. error('Unknown block type in flate stream');
  33236. }
  33237. buffer = this.buffer;
  33238. var limit = buffer ? buffer.length : 0;
  33239. var pos = this.bufferLength;
  33240. while (true) {
  33241. var code1 = this.getCode(litCodeTable);
  33242. if (code1 < 256) {
  33243. if (pos + 1 >= limit) {
  33244. buffer = this.ensureBuffer(pos + 1);
  33245. limit = buffer.length;
  33246. }
  33247. buffer[pos++] = code1;
  33248. continue;
  33249. }
  33250. if (code1 === 256) {
  33251. this.bufferLength = pos;
  33252. return;
  33253. }
  33254. code1 -= 257;
  33255. code1 = lengthDecode[code1];
  33256. var code2 = code1 >> 16;
  33257. if (code2 > 0) {
  33258. code2 = this.getBits(code2);
  33259. }
  33260. len = (code1 & 0xffff) + code2;
  33261. code1 = this.getCode(distCodeTable);
  33262. code1 = distDecode[code1];
  33263. code2 = code1 >> 16;
  33264. if (code2 > 0) {
  33265. code2 = this.getBits(code2);
  33266. }
  33267. var dist = (code1 & 0xffff) + code2;
  33268. if (pos + len >= limit) {
  33269. buffer = this.ensureBuffer(pos + len);
  33270. limit = buffer.length;
  33271. }
  33272. for (var k = 0; k < len; ++k, ++pos) {
  33273. buffer[pos] = buffer[pos - dist];
  33274. }
  33275. }
  33276. };
  33277. return FlateStream;
  33278. })();
  33279. var PredictorStream = (function PredictorStreamClosure() {
  33280. function PredictorStream(str, maybeLength, params) {
  33281. var predictor = this.predictor = params.get('Predictor') || 1;
  33282. if (predictor <= 1) {
  33283. return str; // no prediction
  33284. }
  33285. if (predictor !== 2 && (predictor < 10 || predictor > 15)) {
  33286. error('Unsupported predictor: ' + predictor);
  33287. }
  33288. if (predictor === 2) {
  33289. this.readBlock = this.readBlockTiff;
  33290. } else {
  33291. this.readBlock = this.readBlockPng;
  33292. }
  33293. this.str = str;
  33294. this.dict = str.dict;
  33295. var colors = this.colors = params.get('Colors') || 1;
  33296. var bits = this.bits = params.get('BitsPerComponent') || 8;
  33297. var columns = this.columns = params.get('Columns') || 1;
  33298. this.pixBytes = (colors * bits + 7) >> 3;
  33299. this.rowBytes = (columns * colors * bits + 7) >> 3;
  33300. DecodeStream.call(this, maybeLength);
  33301. return this;
  33302. }
  33303. PredictorStream.prototype = Object.create(DecodeStream.prototype);
  33304. PredictorStream.prototype.readBlockTiff =
  33305. function predictorStreamReadBlockTiff() {
  33306. var rowBytes = this.rowBytes;
  33307. var bufferLength = this.bufferLength;
  33308. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  33309. var bits = this.bits;
  33310. var colors = this.colors;
  33311. var rawBytes = this.str.getBytes(rowBytes);
  33312. this.eof = !rawBytes.length;
  33313. if (this.eof) {
  33314. return;
  33315. }
  33316. var inbuf = 0, outbuf = 0;
  33317. var inbits = 0, outbits = 0;
  33318. var pos = bufferLength;
  33319. var i;
  33320. if (bits === 1) {
  33321. for (i = 0; i < rowBytes; ++i) {
  33322. var c = rawBytes[i];
  33323. inbuf = (inbuf << 8) | c;
  33324. // bitwise addition is exclusive or
  33325. // first shift inbuf and then add
  33326. buffer[pos++] = (c ^ (inbuf >> colors)) & 0xFF;
  33327. // truncate inbuf (assumes colors < 16)
  33328. inbuf &= 0xFFFF;
  33329. }
  33330. } else if (bits === 8) {
  33331. for (i = 0; i < colors; ++i) {
  33332. buffer[pos++] = rawBytes[i];
  33333. }
  33334. for (; i < rowBytes; ++i) {
  33335. buffer[pos] = buffer[pos - colors] + rawBytes[i];
  33336. pos++;
  33337. }
  33338. } else {
  33339. var compArray = new Uint8Array(colors + 1);
  33340. var bitMask = (1 << bits) - 1;
  33341. var j = 0, k = bufferLength;
  33342. var columns = this.columns;
  33343. for (i = 0; i < columns; ++i) {
  33344. for (var kk = 0; kk < colors; ++kk) {
  33345. if (inbits < bits) {
  33346. inbuf = (inbuf << 8) | (rawBytes[j++] & 0xFF);
  33347. inbits += 8;
  33348. }
  33349. compArray[kk] = (compArray[kk] +
  33350. (inbuf >> (inbits - bits))) & bitMask;
  33351. inbits -= bits;
  33352. outbuf = (outbuf << bits) | compArray[kk];
  33353. outbits += bits;
  33354. if (outbits >= 8) {
  33355. buffer[k++] = (outbuf >> (outbits - 8)) & 0xFF;
  33356. outbits -= 8;
  33357. }
  33358. }
  33359. }
  33360. if (outbits > 0) {
  33361. buffer[k++] = (outbuf << (8 - outbits)) +
  33362. (inbuf & ((1 << (8 - outbits)) - 1));
  33363. }
  33364. }
  33365. this.bufferLength += rowBytes;
  33366. };
  33367. PredictorStream.prototype.readBlockPng =
  33368. function predictorStreamReadBlockPng() {
  33369. var rowBytes = this.rowBytes;
  33370. var pixBytes = this.pixBytes;
  33371. var predictor = this.str.getByte();
  33372. var rawBytes = this.str.getBytes(rowBytes);
  33373. this.eof = !rawBytes.length;
  33374. if (this.eof) {
  33375. return;
  33376. }
  33377. var bufferLength = this.bufferLength;
  33378. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  33379. var prevRow = buffer.subarray(bufferLength - rowBytes, bufferLength);
  33380. if (prevRow.length === 0) {
  33381. prevRow = new Uint8Array(rowBytes);
  33382. }
  33383. var i, j = bufferLength, up, c;
  33384. switch (predictor) {
  33385. case 0:
  33386. for (i = 0; i < rowBytes; ++i) {
  33387. buffer[j++] = rawBytes[i];
  33388. }
  33389. break;
  33390. case 1:
  33391. for (i = 0; i < pixBytes; ++i) {
  33392. buffer[j++] = rawBytes[i];
  33393. }
  33394. for (; i < rowBytes; ++i) {
  33395. buffer[j] = (buffer[j - pixBytes] + rawBytes[i]) & 0xFF;
  33396. j++;
  33397. }
  33398. break;
  33399. case 2:
  33400. for (i = 0; i < rowBytes; ++i) {
  33401. buffer[j++] = (prevRow[i] + rawBytes[i]) & 0xFF;
  33402. }
  33403. break;
  33404. case 3:
  33405. for (i = 0; i < pixBytes; ++i) {
  33406. buffer[j++] = (prevRow[i] >> 1) + rawBytes[i];
  33407. }
  33408. for (; i < rowBytes; ++i) {
  33409. buffer[j] = (((prevRow[i] + buffer[j - pixBytes]) >> 1) +
  33410. rawBytes[i]) & 0xFF;
  33411. j++;
  33412. }
  33413. break;
  33414. case 4:
  33415. // we need to save the up left pixels values. the simplest way
  33416. // is to create a new buffer
  33417. for (i = 0; i < pixBytes; ++i) {
  33418. up = prevRow[i];
  33419. c = rawBytes[i];
  33420. buffer[j++] = up + c;
  33421. }
  33422. for (; i < rowBytes; ++i) {
  33423. up = prevRow[i];
  33424. var upLeft = prevRow[i - pixBytes];
  33425. var left = buffer[j - pixBytes];
  33426. var p = left + up - upLeft;
  33427. var pa = p - left;
  33428. if (pa < 0) {
  33429. pa = -pa;
  33430. }
  33431. var pb = p - up;
  33432. if (pb < 0) {
  33433. pb = -pb;
  33434. }
  33435. var pc = p - upLeft;
  33436. if (pc < 0) {
  33437. pc = -pc;
  33438. }
  33439. c = rawBytes[i];
  33440. if (pa <= pb && pa <= pc) {
  33441. buffer[j++] = left + c;
  33442. } else if (pb <= pc) {
  33443. buffer[j++] = up + c;
  33444. } else {
  33445. buffer[j++] = upLeft + c;
  33446. }
  33447. }
  33448. break;
  33449. default:
  33450. error('Unsupported predictor: ' + predictor);
  33451. }
  33452. this.bufferLength += rowBytes;
  33453. };
  33454. return PredictorStream;
  33455. })();
  33456. /**
  33457. * Depending on the type of JPEG a JpegStream is handled in different ways. For
  33458. * JPEG's that are supported natively such as DeviceGray and DeviceRGB the image
  33459. * data is stored and then loaded by the browser. For unsupported JPEG's we use
  33460. * a library to decode these images and the stream behaves like all the other
  33461. * DecodeStreams.
  33462. */
  33463. var JpegStream = (function JpegStreamClosure() {
  33464. function JpegStream(stream, maybeLength, dict, xref) {
  33465. // TODO: per poppler, some images may have 'junk' before that
  33466. // need to be removed
  33467. this.stream = stream;
  33468. this.maybeLength = maybeLength;
  33469. this.dict = dict;
  33470. DecodeStream.call(this, maybeLength);
  33471. }
  33472. JpegStream.prototype = Object.create(DecodeStream.prototype);
  33473. Object.defineProperty(JpegStream.prototype, 'bytes', {
  33474. get: function JpegStream_bytes() {
  33475. // If this.maybeLength is null, we'll get the entire stream.
  33476. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  33477. },
  33478. configurable: true
  33479. });
  33480. JpegStream.prototype.ensureBuffer = function JpegStream_ensureBuffer(req) {
  33481. if (this.bufferLength) {
  33482. return;
  33483. }
  33484. try {
  33485. var jpegImage = new JpegImage();
  33486. // checking if values needs to be transformed before conversion
  33487. if (this.dict && isArray(this.dict.get('Decode'))) {
  33488. var decodeArr = this.dict.get('Decode');
  33489. var bitsPerComponent = this.dict.get('BitsPerComponent') || 8;
  33490. var decodeArrLength = decodeArr.length;
  33491. var transform = new Int32Array(decodeArrLength);
  33492. var transformNeeded = false;
  33493. var maxValue = (1 << bitsPerComponent) - 1;
  33494. for (var i = 0; i < decodeArrLength; i += 2) {
  33495. transform[i] = ((decodeArr[i + 1] - decodeArr[i]) * 256) | 0;
  33496. transform[i + 1] = (decodeArr[i] * maxValue) | 0;
  33497. if (transform[i] !== 256 || transform[i + 1] !== 0) {
  33498. transformNeeded = true;
  33499. }
  33500. }
  33501. if (transformNeeded) {
  33502. jpegImage.decodeTransform = transform;
  33503. }
  33504. }
  33505. jpegImage.parse(this.bytes);
  33506. var data = jpegImage.getData(this.drawWidth, this.drawHeight,
  33507. this.forceRGB);
  33508. this.buffer = data;
  33509. this.bufferLength = data.length;
  33510. this.eof = true;
  33511. } catch (e) {
  33512. error('JPEG error: ' + e);
  33513. }
  33514. };
  33515. JpegStream.prototype.getBytes = function JpegStream_getBytes(length) {
  33516. this.ensureBuffer();
  33517. return this.buffer;
  33518. };
  33519. JpegStream.prototype.getIR = function JpegStream_getIR() {
  33520. return PDFJS.createObjectURL(this.bytes, 'image/jpeg');
  33521. };
  33522. /**
  33523. * Checks if the image can be decoded and displayed by the browser without any
  33524. * further processing such as color space conversions.
  33525. */
  33526. JpegStream.prototype.isNativelySupported =
  33527. function JpegStream_isNativelySupported(xref, res) {
  33528. var cs = ColorSpace.parse(this.dict.get('ColorSpace', 'CS'), xref, res);
  33529. return cs.name === 'DeviceGray' || cs.name === 'DeviceRGB';
  33530. };
  33531. /**
  33532. * Checks if the image can be decoded by the browser.
  33533. */
  33534. JpegStream.prototype.isNativelyDecodable =
  33535. function JpegStream_isNativelyDecodable(xref, res) {
  33536. var cs = ColorSpace.parse(this.dict.get('ColorSpace', 'CS'), xref, res);
  33537. var numComps = cs.numComps;
  33538. return numComps === 1 || numComps === 3;
  33539. };
  33540. return JpegStream;
  33541. })();
  33542. /**
  33543. * For JPEG 2000's we use a library to decode these images and
  33544. * the stream behaves like all the other DecodeStreams.
  33545. */
  33546. var JpxStream = (function JpxStreamClosure() {
  33547. function JpxStream(stream, maybeLength, dict) {
  33548. this.stream = stream;
  33549. this.maybeLength = maybeLength;
  33550. this.dict = dict;
  33551. DecodeStream.call(this, maybeLength);
  33552. }
  33553. JpxStream.prototype = Object.create(DecodeStream.prototype);
  33554. Object.defineProperty(JpxStream.prototype, 'bytes', {
  33555. get: function JpxStream_bytes() {
  33556. // If this.maybeLength is null, we'll get the entire stream.
  33557. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  33558. },
  33559. configurable: true
  33560. });
  33561. JpxStream.prototype.ensureBuffer = function JpxStream_ensureBuffer(req) {
  33562. if (this.bufferLength) {
  33563. return;
  33564. }
  33565. var jpxImage = new JpxImage();
  33566. jpxImage.parse(this.bytes);
  33567. var width = jpxImage.width;
  33568. var height = jpxImage.height;
  33569. var componentsCount = jpxImage.componentsCount;
  33570. var tileCount = jpxImage.tiles.length;
  33571. if (tileCount === 1) {
  33572. this.buffer = jpxImage.tiles[0].items;
  33573. } else {
  33574. var data = new Uint8Array(width * height * componentsCount);
  33575. for (var k = 0; k < tileCount; k++) {
  33576. var tileComponents = jpxImage.tiles[k];
  33577. var tileWidth = tileComponents.width;
  33578. var tileHeight = tileComponents.height;
  33579. var tileLeft = tileComponents.left;
  33580. var tileTop = tileComponents.top;
  33581. var src = tileComponents.items;
  33582. var srcPosition = 0;
  33583. var dataPosition = (width * tileTop + tileLeft) * componentsCount;
  33584. var imgRowSize = width * componentsCount;
  33585. var tileRowSize = tileWidth * componentsCount;
  33586. for (var j = 0; j < tileHeight; j++) {
  33587. var rowBytes = src.subarray(srcPosition, srcPosition + tileRowSize);
  33588. data.set(rowBytes, dataPosition);
  33589. srcPosition += tileRowSize;
  33590. dataPosition += imgRowSize;
  33591. }
  33592. }
  33593. this.buffer = data;
  33594. }
  33595. this.bufferLength = this.buffer.length;
  33596. this.eof = true;
  33597. };
  33598. return JpxStream;
  33599. })();
  33600. /**
  33601. * For JBIG2's we use a library to decode these images and
  33602. * the stream behaves like all the other DecodeStreams.
  33603. */
  33604. var Jbig2Stream = (function Jbig2StreamClosure() {
  33605. function Jbig2Stream(stream, maybeLength, dict) {
  33606. this.stream = stream;
  33607. this.maybeLength = maybeLength;
  33608. this.dict = dict;
  33609. DecodeStream.call(this, maybeLength);
  33610. }
  33611. Jbig2Stream.prototype = Object.create(DecodeStream.prototype);
  33612. Object.defineProperty(Jbig2Stream.prototype, 'bytes', {
  33613. get: function Jbig2Stream_bytes() {
  33614. // If this.maybeLength is null, we'll get the entire stream.
  33615. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  33616. },
  33617. configurable: true
  33618. });
  33619. Jbig2Stream.prototype.ensureBuffer = function Jbig2Stream_ensureBuffer(req) {
  33620. if (this.bufferLength) {
  33621. return;
  33622. }
  33623. var jbig2Image = new Jbig2Image();
  33624. var chunks = [], decodeParams = this.dict.get('DecodeParms');
  33625. // According to the PDF specification, DecodeParms can be either
  33626. // a dictionary, or an array whose elements are dictionaries.
  33627. if (isArray(decodeParams)) {
  33628. if (decodeParams.length > 1) {
  33629. warn('JBIG2 - \'DecodeParms\' array with multiple elements ' +
  33630. 'not supported.');
  33631. }
  33632. decodeParams = decodeParams[0];
  33633. }
  33634. if (decodeParams && decodeParams.has('JBIG2Globals')) {
  33635. var globalsStream = decodeParams.get('JBIG2Globals');
  33636. var globals = globalsStream.getBytes();
  33637. chunks.push({data: globals, start: 0, end: globals.length});
  33638. }
  33639. chunks.push({data: this.bytes, start: 0, end: this.bytes.length});
  33640. var data = jbig2Image.parseChunks(chunks);
  33641. var dataLength = data.length;
  33642. // JBIG2 had black as 1 and white as 0, inverting the colors
  33643. for (var i = 0; i < dataLength; i++) {
  33644. data[i] ^= 0xFF;
  33645. }
  33646. this.buffer = data;
  33647. this.bufferLength = dataLength;
  33648. this.eof = true;
  33649. };
  33650. return Jbig2Stream;
  33651. })();
  33652. var DecryptStream = (function DecryptStreamClosure() {
  33653. function DecryptStream(str, maybeLength, decrypt) {
  33654. this.str = str;
  33655. this.dict = str.dict;
  33656. this.decrypt = decrypt;
  33657. this.nextChunk = null;
  33658. this.initialized = false;
  33659. DecodeStream.call(this, maybeLength);
  33660. }
  33661. var chunkSize = 512;
  33662. DecryptStream.prototype = Object.create(DecodeStream.prototype);
  33663. DecryptStream.prototype.readBlock = function DecryptStream_readBlock() {
  33664. var chunk;
  33665. if (this.initialized) {
  33666. chunk = this.nextChunk;
  33667. } else {
  33668. chunk = this.str.getBytes(chunkSize);
  33669. this.initialized = true;
  33670. }
  33671. if (!chunk || chunk.length === 0) {
  33672. this.eof = true;
  33673. return;
  33674. }
  33675. this.nextChunk = this.str.getBytes(chunkSize);
  33676. var hasMoreData = this.nextChunk && this.nextChunk.length > 0;
  33677. var decrypt = this.decrypt;
  33678. chunk = decrypt(chunk, !hasMoreData);
  33679. var bufferLength = this.bufferLength;
  33680. var i, n = chunk.length;
  33681. var buffer = this.ensureBuffer(bufferLength + n);
  33682. for (i = 0; i < n; i++) {
  33683. buffer[bufferLength++] = chunk[i];
  33684. }
  33685. this.bufferLength = bufferLength;
  33686. };
  33687. return DecryptStream;
  33688. })();
  33689. var Ascii85Stream = (function Ascii85StreamClosure() {
  33690. function Ascii85Stream(str, maybeLength) {
  33691. this.str = str;
  33692. this.dict = str.dict;
  33693. this.input = new Uint8Array(5);
  33694. // Most streams increase in size when decoded, but Ascii85 streams
  33695. // typically shrink by ~20%.
  33696. if (maybeLength) {
  33697. maybeLength = 0.8 * maybeLength;
  33698. }
  33699. DecodeStream.call(this, maybeLength);
  33700. }
  33701. Ascii85Stream.prototype = Object.create(DecodeStream.prototype);
  33702. Ascii85Stream.prototype.readBlock = function Ascii85Stream_readBlock() {
  33703. var TILDA_CHAR = 0x7E; // '~'
  33704. var Z_LOWER_CHAR = 0x7A; // 'z'
  33705. var EOF = -1;
  33706. var str = this.str;
  33707. var c = str.getByte();
  33708. while (Lexer.isSpace(c)) {
  33709. c = str.getByte();
  33710. }
  33711. if (c === EOF || c === TILDA_CHAR) {
  33712. this.eof = true;
  33713. return;
  33714. }
  33715. var bufferLength = this.bufferLength, buffer;
  33716. var i;
  33717. // special code for z
  33718. if (c === Z_LOWER_CHAR) {
  33719. buffer = this.ensureBuffer(bufferLength + 4);
  33720. for (i = 0; i < 4; ++i) {
  33721. buffer[bufferLength + i] = 0;
  33722. }
  33723. this.bufferLength += 4;
  33724. } else {
  33725. var input = this.input;
  33726. input[0] = c;
  33727. for (i = 1; i < 5; ++i) {
  33728. c = str.getByte();
  33729. while (Lexer.isSpace(c)) {
  33730. c = str.getByte();
  33731. }
  33732. input[i] = c;
  33733. if (c === EOF || c === TILDA_CHAR) {
  33734. break;
  33735. }
  33736. }
  33737. buffer = this.ensureBuffer(bufferLength + i - 1);
  33738. this.bufferLength += i - 1;
  33739. // partial ending;
  33740. if (i < 5) {
  33741. for (; i < 5; ++i) {
  33742. input[i] = 0x21 + 84;
  33743. }
  33744. this.eof = true;
  33745. }
  33746. var t = 0;
  33747. for (i = 0; i < 5; ++i) {
  33748. t = t * 85 + (input[i] - 0x21);
  33749. }
  33750. for (i = 3; i >= 0; --i) {
  33751. buffer[bufferLength + i] = t & 0xFF;
  33752. t >>= 8;
  33753. }
  33754. }
  33755. };
  33756. return Ascii85Stream;
  33757. })();
  33758. var AsciiHexStream = (function AsciiHexStreamClosure() {
  33759. function AsciiHexStream(str, maybeLength) {
  33760. this.str = str;
  33761. this.dict = str.dict;
  33762. this.firstDigit = -1;
  33763. // Most streams increase in size when decoded, but AsciiHex streams shrink
  33764. // by 50%.
  33765. if (maybeLength) {
  33766. maybeLength = 0.5 * maybeLength;
  33767. }
  33768. DecodeStream.call(this, maybeLength);
  33769. }
  33770. AsciiHexStream.prototype = Object.create(DecodeStream.prototype);
  33771. AsciiHexStream.prototype.readBlock = function AsciiHexStream_readBlock() {
  33772. var UPSTREAM_BLOCK_SIZE = 8000;
  33773. var bytes = this.str.getBytes(UPSTREAM_BLOCK_SIZE);
  33774. if (!bytes.length) {
  33775. this.eof = true;
  33776. return;
  33777. }
  33778. var maxDecodeLength = (bytes.length + 1) >> 1;
  33779. var buffer = this.ensureBuffer(this.bufferLength + maxDecodeLength);
  33780. var bufferLength = this.bufferLength;
  33781. var firstDigit = this.firstDigit;
  33782. for (var i = 0, ii = bytes.length; i < ii; i++) {
  33783. var ch = bytes[i], digit;
  33784. if (ch >= 0x30 && ch <= 0x39) { // '0'-'9'
  33785. digit = ch & 0x0F;
  33786. } else if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
  33787. // 'A'-'Z', 'a'-'z'
  33788. digit = (ch & 0x0F) + 9;
  33789. } else if (ch === 0x3E) { // '>'
  33790. this.eof = true;
  33791. break;
  33792. } else { // probably whitespace
  33793. continue; // ignoring
  33794. }
  33795. if (firstDigit < 0) {
  33796. firstDigit = digit;
  33797. } else {
  33798. buffer[bufferLength++] = (firstDigit << 4) | digit;
  33799. firstDigit = -1;
  33800. }
  33801. }
  33802. if (firstDigit >= 0 && this.eof) {
  33803. // incomplete byte
  33804. buffer[bufferLength++] = (firstDigit << 4);
  33805. firstDigit = -1;
  33806. }
  33807. this.firstDigit = firstDigit;
  33808. this.bufferLength = bufferLength;
  33809. };
  33810. return AsciiHexStream;
  33811. })();
  33812. var RunLengthStream = (function RunLengthStreamClosure() {
  33813. function RunLengthStream(str, maybeLength) {
  33814. this.str = str;
  33815. this.dict = str.dict;
  33816. DecodeStream.call(this, maybeLength);
  33817. }
  33818. RunLengthStream.prototype = Object.create(DecodeStream.prototype);
  33819. RunLengthStream.prototype.readBlock = function RunLengthStream_readBlock() {
  33820. // The repeatHeader has following format. The first byte defines type of run
  33821. // and amount of bytes to repeat/copy: n = 0 through 127 - copy next n bytes
  33822. // (in addition to the second byte from the header), n = 129 through 255 -
  33823. // duplicate the second byte from the header (257 - n) times, n = 128 - end.
  33824. var repeatHeader = this.str.getBytes(2);
  33825. if (!repeatHeader || repeatHeader.length < 2 || repeatHeader[0] === 128) {
  33826. this.eof = true;
  33827. return;
  33828. }
  33829. var buffer;
  33830. var bufferLength = this.bufferLength;
  33831. var n = repeatHeader[0];
  33832. if (n < 128) {
  33833. // copy n bytes
  33834. buffer = this.ensureBuffer(bufferLength + n + 1);
  33835. buffer[bufferLength++] = repeatHeader[1];
  33836. if (n > 0) {
  33837. var source = this.str.getBytes(n);
  33838. buffer.set(source, bufferLength);
  33839. bufferLength += n;
  33840. }
  33841. } else {
  33842. n = 257 - n;
  33843. var b = repeatHeader[1];
  33844. buffer = this.ensureBuffer(bufferLength + n + 1);
  33845. for (var i = 0; i < n; i++) {
  33846. buffer[bufferLength++] = b;
  33847. }
  33848. }
  33849. this.bufferLength = bufferLength;
  33850. };
  33851. return RunLengthStream;
  33852. })();
  33853. var CCITTFaxStream = (function CCITTFaxStreamClosure() {
  33854. var ccittEOL = -2;
  33855. var twoDimPass = 0;
  33856. var twoDimHoriz = 1;
  33857. var twoDimVert0 = 2;
  33858. var twoDimVertR1 = 3;
  33859. var twoDimVertL1 = 4;
  33860. var twoDimVertR2 = 5;
  33861. var twoDimVertL2 = 6;
  33862. var twoDimVertR3 = 7;
  33863. var twoDimVertL3 = 8;
  33864. var twoDimTable = [
  33865. [-1, -1], [-1, -1], // 000000x
  33866. [7, twoDimVertL3], // 0000010
  33867. [7, twoDimVertR3], // 0000011
  33868. [6, twoDimVertL2], [6, twoDimVertL2], // 000010x
  33869. [6, twoDimVertR2], [6, twoDimVertR2], // 000011x
  33870. [4, twoDimPass], [4, twoDimPass], // 0001xxx
  33871. [4, twoDimPass], [4, twoDimPass],
  33872. [4, twoDimPass], [4, twoDimPass],
  33873. [4, twoDimPass], [4, twoDimPass],
  33874. [3, twoDimHoriz], [3, twoDimHoriz], // 001xxxx
  33875. [3, twoDimHoriz], [3, twoDimHoriz],
  33876. [3, twoDimHoriz], [3, twoDimHoriz],
  33877. [3, twoDimHoriz], [3, twoDimHoriz],
  33878. [3, twoDimHoriz], [3, twoDimHoriz],
  33879. [3, twoDimHoriz], [3, twoDimHoriz],
  33880. [3, twoDimHoriz], [3, twoDimHoriz],
  33881. [3, twoDimHoriz], [3, twoDimHoriz],
  33882. [3, twoDimVertL1], [3, twoDimVertL1], // 010xxxx
  33883. [3, twoDimVertL1], [3, twoDimVertL1],
  33884. [3, twoDimVertL1], [3, twoDimVertL1],
  33885. [3, twoDimVertL1], [3, twoDimVertL1],
  33886. [3, twoDimVertL1], [3, twoDimVertL1],
  33887. [3, twoDimVertL1], [3, twoDimVertL1],
  33888. [3, twoDimVertL1], [3, twoDimVertL1],
  33889. [3, twoDimVertL1], [3, twoDimVertL1],
  33890. [3, twoDimVertR1], [3, twoDimVertR1], // 011xxxx
  33891. [3, twoDimVertR1], [3, twoDimVertR1],
  33892. [3, twoDimVertR1], [3, twoDimVertR1],
  33893. [3, twoDimVertR1], [3, twoDimVertR1],
  33894. [3, twoDimVertR1], [3, twoDimVertR1],
  33895. [3, twoDimVertR1], [3, twoDimVertR1],
  33896. [3, twoDimVertR1], [3, twoDimVertR1],
  33897. [3, twoDimVertR1], [3, twoDimVertR1],
  33898. [1, twoDimVert0], [1, twoDimVert0], // 1xxxxxx
  33899. [1, twoDimVert0], [1, twoDimVert0],
  33900. [1, twoDimVert0], [1, twoDimVert0],
  33901. [1, twoDimVert0], [1, twoDimVert0],
  33902. [1, twoDimVert0], [1, twoDimVert0],
  33903. [1, twoDimVert0], [1, twoDimVert0],
  33904. [1, twoDimVert0], [1, twoDimVert0],
  33905. [1, twoDimVert0], [1, twoDimVert0],
  33906. [1, twoDimVert0], [1, twoDimVert0],
  33907. [1, twoDimVert0], [1, twoDimVert0],
  33908. [1, twoDimVert0], [1, twoDimVert0],
  33909. [1, twoDimVert0], [1, twoDimVert0],
  33910. [1, twoDimVert0], [1, twoDimVert0],
  33911. [1, twoDimVert0], [1, twoDimVert0],
  33912. [1, twoDimVert0], [1, twoDimVert0],
  33913. [1, twoDimVert0], [1, twoDimVert0],
  33914. [1, twoDimVert0], [1, twoDimVert0],
  33915. [1, twoDimVert0], [1, twoDimVert0],
  33916. [1, twoDimVert0], [1, twoDimVert0],
  33917. [1, twoDimVert0], [1, twoDimVert0],
  33918. [1, twoDimVert0], [1, twoDimVert0],
  33919. [1, twoDimVert0], [1, twoDimVert0],
  33920. [1, twoDimVert0], [1, twoDimVert0],
  33921. [1, twoDimVert0], [1, twoDimVert0],
  33922. [1, twoDimVert0], [1, twoDimVert0],
  33923. [1, twoDimVert0], [1, twoDimVert0],
  33924. [1, twoDimVert0], [1, twoDimVert0],
  33925. [1, twoDimVert0], [1, twoDimVert0],
  33926. [1, twoDimVert0], [1, twoDimVert0],
  33927. [1, twoDimVert0], [1, twoDimVert0],
  33928. [1, twoDimVert0], [1, twoDimVert0],
  33929. [1, twoDimVert0], [1, twoDimVert0]
  33930. ];
  33931. var whiteTable1 = [
  33932. [-1, -1], // 00000
  33933. [12, ccittEOL], // 00001
  33934. [-1, -1], [-1, -1], // 0001x
  33935. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 001xx
  33936. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 010xx
  33937. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 011xx
  33938. [11, 1792], [11, 1792], // 1000x
  33939. [12, 1984], // 10010
  33940. [12, 2048], // 10011
  33941. [12, 2112], // 10100
  33942. [12, 2176], // 10101
  33943. [12, 2240], // 10110
  33944. [12, 2304], // 10111
  33945. [11, 1856], [11, 1856], // 1100x
  33946. [11, 1920], [11, 1920], // 1101x
  33947. [12, 2368], // 11100
  33948. [12, 2432], // 11101
  33949. [12, 2496], // 11110
  33950. [12, 2560] // 11111
  33951. ];
  33952. var whiteTable2 = [
  33953. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000000xx
  33954. [8, 29], [8, 29], // 00000010x
  33955. [8, 30], [8, 30], // 00000011x
  33956. [8, 45], [8, 45], // 00000100x
  33957. [8, 46], [8, 46], // 00000101x
  33958. [7, 22], [7, 22], [7, 22], [7, 22], // 0000011xx
  33959. [7, 23], [7, 23], [7, 23], [7, 23], // 0000100xx
  33960. [8, 47], [8, 47], // 00001010x
  33961. [8, 48], [8, 48], // 00001011x
  33962. [6, 13], [6, 13], [6, 13], [6, 13], // 000011xxx
  33963. [6, 13], [6, 13], [6, 13], [6, 13],
  33964. [7, 20], [7, 20], [7, 20], [7, 20], // 0001000xx
  33965. [8, 33], [8, 33], // 00010010x
  33966. [8, 34], [8, 34], // 00010011x
  33967. [8, 35], [8, 35], // 00010100x
  33968. [8, 36], [8, 36], // 00010101x
  33969. [8, 37], [8, 37], // 00010110x
  33970. [8, 38], [8, 38], // 00010111x
  33971. [7, 19], [7, 19], [7, 19], [7, 19], // 0001100xx
  33972. [8, 31], [8, 31], // 00011010x
  33973. [8, 32], [8, 32], // 00011011x
  33974. [6, 1], [6, 1], [6, 1], [6, 1], // 000111xxx
  33975. [6, 1], [6, 1], [6, 1], [6, 1],
  33976. [6, 12], [6, 12], [6, 12], [6, 12], // 001000xxx
  33977. [6, 12], [6, 12], [6, 12], [6, 12],
  33978. [8, 53], [8, 53], // 00100100x
  33979. [8, 54], [8, 54], // 00100101x
  33980. [7, 26], [7, 26], [7, 26], [7, 26], // 0010011xx
  33981. [8, 39], [8, 39], // 00101000x
  33982. [8, 40], [8, 40], // 00101001x
  33983. [8, 41], [8, 41], // 00101010x
  33984. [8, 42], [8, 42], // 00101011x
  33985. [8, 43], [8, 43], // 00101100x
  33986. [8, 44], [8, 44], // 00101101x
  33987. [7, 21], [7, 21], [7, 21], [7, 21], // 0010111xx
  33988. [7, 28], [7, 28], [7, 28], [7, 28], // 0011000xx
  33989. [8, 61], [8, 61], // 00110010x
  33990. [8, 62], [8, 62], // 00110011x
  33991. [8, 63], [8, 63], // 00110100x
  33992. [8, 0], [8, 0], // 00110101x
  33993. [8, 320], [8, 320], // 00110110x
  33994. [8, 384], [8, 384], // 00110111x
  33995. [5, 10], [5, 10], [5, 10], [5, 10], // 00111xxxx
  33996. [5, 10], [5, 10], [5, 10], [5, 10],
  33997. [5, 10], [5, 10], [5, 10], [5, 10],
  33998. [5, 10], [5, 10], [5, 10], [5, 10],
  33999. [5, 11], [5, 11], [5, 11], [5, 11], // 01000xxxx
  34000. [5, 11], [5, 11], [5, 11], [5, 11],
  34001. [5, 11], [5, 11], [5, 11], [5, 11],
  34002. [5, 11], [5, 11], [5, 11], [5, 11],
  34003. [7, 27], [7, 27], [7, 27], [7, 27], // 0100100xx
  34004. [8, 59], [8, 59], // 01001010x
  34005. [8, 60], [8, 60], // 01001011x
  34006. [9, 1472], // 010011000
  34007. [9, 1536], // 010011001
  34008. [9, 1600], // 010011010
  34009. [9, 1728], // 010011011
  34010. [7, 18], [7, 18], [7, 18], [7, 18], // 0100111xx
  34011. [7, 24], [7, 24], [7, 24], [7, 24], // 0101000xx
  34012. [8, 49], [8, 49], // 01010010x
  34013. [8, 50], [8, 50], // 01010011x
  34014. [8, 51], [8, 51], // 01010100x
  34015. [8, 52], [8, 52], // 01010101x
  34016. [7, 25], [7, 25], [7, 25], [7, 25], // 0101011xx
  34017. [8, 55], [8, 55], // 01011000x
  34018. [8, 56], [8, 56], // 01011001x
  34019. [8, 57], [8, 57], // 01011010x
  34020. [8, 58], [8, 58], // 01011011x
  34021. [6, 192], [6, 192], [6, 192], [6, 192], // 010111xxx
  34022. [6, 192], [6, 192], [6, 192], [6, 192],
  34023. [6, 1664], [6, 1664], [6, 1664], [6, 1664], // 011000xxx
  34024. [6, 1664], [6, 1664], [6, 1664], [6, 1664],
  34025. [8, 448], [8, 448], // 01100100x
  34026. [8, 512], [8, 512], // 01100101x
  34027. [9, 704], // 011001100
  34028. [9, 768], // 011001101
  34029. [8, 640], [8, 640], // 01100111x
  34030. [8, 576], [8, 576], // 01101000x
  34031. [9, 832], // 011010010
  34032. [9, 896], // 011010011
  34033. [9, 960], // 011010100
  34034. [9, 1024], // 011010101
  34035. [9, 1088], // 011010110
  34036. [9, 1152], // 011010111
  34037. [9, 1216], // 011011000
  34038. [9, 1280], // 011011001
  34039. [9, 1344], // 011011010
  34040. [9, 1408], // 011011011
  34041. [7, 256], [7, 256], [7, 256], [7, 256], // 0110111xx
  34042. [4, 2], [4, 2], [4, 2], [4, 2], // 0111xxxxx
  34043. [4, 2], [4, 2], [4, 2], [4, 2],
  34044. [4, 2], [4, 2], [4, 2], [4, 2],
  34045. [4, 2], [4, 2], [4, 2], [4, 2],
  34046. [4, 2], [4, 2], [4, 2], [4, 2],
  34047. [4, 2], [4, 2], [4, 2], [4, 2],
  34048. [4, 2], [4, 2], [4, 2], [4, 2],
  34049. [4, 2], [4, 2], [4, 2], [4, 2],
  34050. [4, 3], [4, 3], [4, 3], [4, 3], // 1000xxxxx
  34051. [4, 3], [4, 3], [4, 3], [4, 3],
  34052. [4, 3], [4, 3], [4, 3], [4, 3],
  34053. [4, 3], [4, 3], [4, 3], [4, 3],
  34054. [4, 3], [4, 3], [4, 3], [4, 3],
  34055. [4, 3], [4, 3], [4, 3], [4, 3],
  34056. [4, 3], [4, 3], [4, 3], [4, 3],
  34057. [4, 3], [4, 3], [4, 3], [4, 3],
  34058. [5, 128], [5, 128], [5, 128], [5, 128], // 10010xxxx
  34059. [5, 128], [5, 128], [5, 128], [5, 128],
  34060. [5, 128], [5, 128], [5, 128], [5, 128],
  34061. [5, 128], [5, 128], [5, 128], [5, 128],
  34062. [5, 8], [5, 8], [5, 8], [5, 8], // 10011xxxx
  34063. [5, 8], [5, 8], [5, 8], [5, 8],
  34064. [5, 8], [5, 8], [5, 8], [5, 8],
  34065. [5, 8], [5, 8], [5, 8], [5, 8],
  34066. [5, 9], [5, 9], [5, 9], [5, 9], // 10100xxxx
  34067. [5, 9], [5, 9], [5, 9], [5, 9],
  34068. [5, 9], [5, 9], [5, 9], [5, 9],
  34069. [5, 9], [5, 9], [5, 9], [5, 9],
  34070. [6, 16], [6, 16], [6, 16], [6, 16], // 101010xxx
  34071. [6, 16], [6, 16], [6, 16], [6, 16],
  34072. [6, 17], [6, 17], [6, 17], [6, 17], // 101011xxx
  34073. [6, 17], [6, 17], [6, 17], [6, 17],
  34074. [4, 4], [4, 4], [4, 4], [4, 4], // 1011xxxxx
  34075. [4, 4], [4, 4], [4, 4], [4, 4],
  34076. [4, 4], [4, 4], [4, 4], [4, 4],
  34077. [4, 4], [4, 4], [4, 4], [4, 4],
  34078. [4, 4], [4, 4], [4, 4], [4, 4],
  34079. [4, 4], [4, 4], [4, 4], [4, 4],
  34080. [4, 4], [4, 4], [4, 4], [4, 4],
  34081. [4, 4], [4, 4], [4, 4], [4, 4],
  34082. [4, 5], [4, 5], [4, 5], [4, 5], // 1100xxxxx
  34083. [4, 5], [4, 5], [4, 5], [4, 5],
  34084. [4, 5], [4, 5], [4, 5], [4, 5],
  34085. [4, 5], [4, 5], [4, 5], [4, 5],
  34086. [4, 5], [4, 5], [4, 5], [4, 5],
  34087. [4, 5], [4, 5], [4, 5], [4, 5],
  34088. [4, 5], [4, 5], [4, 5], [4, 5],
  34089. [4, 5], [4, 5], [4, 5], [4, 5],
  34090. [6, 14], [6, 14], [6, 14], [6, 14], // 110100xxx
  34091. [6, 14], [6, 14], [6, 14], [6, 14],
  34092. [6, 15], [6, 15], [6, 15], [6, 15], // 110101xxx
  34093. [6, 15], [6, 15], [6, 15], [6, 15],
  34094. [5, 64], [5, 64], [5, 64], [5, 64], // 11011xxxx
  34095. [5, 64], [5, 64], [5, 64], [5, 64],
  34096. [5, 64], [5, 64], [5, 64], [5, 64],
  34097. [5, 64], [5, 64], [5, 64], [5, 64],
  34098. [4, 6], [4, 6], [4, 6], [4, 6], // 1110xxxxx
  34099. [4, 6], [4, 6], [4, 6], [4, 6],
  34100. [4, 6], [4, 6], [4, 6], [4, 6],
  34101. [4, 6], [4, 6], [4, 6], [4, 6],
  34102. [4, 6], [4, 6], [4, 6], [4, 6],
  34103. [4, 6], [4, 6], [4, 6], [4, 6],
  34104. [4, 6], [4, 6], [4, 6], [4, 6],
  34105. [4, 6], [4, 6], [4, 6], [4, 6],
  34106. [4, 7], [4, 7], [4, 7], [4, 7], // 1111xxxxx
  34107. [4, 7], [4, 7], [4, 7], [4, 7],
  34108. [4, 7], [4, 7], [4, 7], [4, 7],
  34109. [4, 7], [4, 7], [4, 7], [4, 7],
  34110. [4, 7], [4, 7], [4, 7], [4, 7],
  34111. [4, 7], [4, 7], [4, 7], [4, 7],
  34112. [4, 7], [4, 7], [4, 7], [4, 7],
  34113. [4, 7], [4, 7], [4, 7], [4, 7]
  34114. ];
  34115. var blackTable1 = [
  34116. [-1, -1], [-1, -1], // 000000000000x
  34117. [12, ccittEOL], [12, ccittEOL], // 000000000001x
  34118. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000001xx
  34119. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000010xx
  34120. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000011xx
  34121. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000100xx
  34122. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000101xx
  34123. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000110xx
  34124. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000111xx
  34125. [11, 1792], [11, 1792], [11, 1792], [11, 1792], // 00000001000xx
  34126. [12, 1984], [12, 1984], // 000000010010x
  34127. [12, 2048], [12, 2048], // 000000010011x
  34128. [12, 2112], [12, 2112], // 000000010100x
  34129. [12, 2176], [12, 2176], // 000000010101x
  34130. [12, 2240], [12, 2240], // 000000010110x
  34131. [12, 2304], [12, 2304], // 000000010111x
  34132. [11, 1856], [11, 1856], [11, 1856], [11, 1856], // 00000001100xx
  34133. [11, 1920], [11, 1920], [11, 1920], [11, 1920], // 00000001101xx
  34134. [12, 2368], [12, 2368], // 000000011100x
  34135. [12, 2432], [12, 2432], // 000000011101x
  34136. [12, 2496], [12, 2496], // 000000011110x
  34137. [12, 2560], [12, 2560], // 000000011111x
  34138. [10, 18], [10, 18], [10, 18], [10, 18], // 0000001000xxx
  34139. [10, 18], [10, 18], [10, 18], [10, 18],
  34140. [12, 52], [12, 52], // 000000100100x
  34141. [13, 640], // 0000001001010
  34142. [13, 704], // 0000001001011
  34143. [13, 768], // 0000001001100
  34144. [13, 832], // 0000001001101
  34145. [12, 55], [12, 55], // 000000100111x
  34146. [12, 56], [12, 56], // 000000101000x
  34147. [13, 1280], // 0000001010010
  34148. [13, 1344], // 0000001010011
  34149. [13, 1408], // 0000001010100
  34150. [13, 1472], // 0000001010101
  34151. [12, 59], [12, 59], // 000000101011x
  34152. [12, 60], [12, 60], // 000000101100x
  34153. [13, 1536], // 0000001011010
  34154. [13, 1600], // 0000001011011
  34155. [11, 24], [11, 24], [11, 24], [11, 24], // 00000010111xx
  34156. [11, 25], [11, 25], [11, 25], [11, 25], // 00000011000xx
  34157. [13, 1664], // 0000001100100
  34158. [13, 1728], // 0000001100101
  34159. [12, 320], [12, 320], // 000000110011x
  34160. [12, 384], [12, 384], // 000000110100x
  34161. [12, 448], [12, 448], // 000000110101x
  34162. [13, 512], // 0000001101100
  34163. [13, 576], // 0000001101101
  34164. [12, 53], [12, 53], // 000000110111x
  34165. [12, 54], [12, 54], // 000000111000x
  34166. [13, 896], // 0000001110010
  34167. [13, 960], // 0000001110011
  34168. [13, 1024], // 0000001110100
  34169. [13, 1088], // 0000001110101
  34170. [13, 1152], // 0000001110110
  34171. [13, 1216], // 0000001110111
  34172. [10, 64], [10, 64], [10, 64], [10, 64], // 0000001111xxx
  34173. [10, 64], [10, 64], [10, 64], [10, 64]
  34174. ];
  34175. var blackTable2 = [
  34176. [8, 13], [8, 13], [8, 13], [8, 13], // 00000100xxxx
  34177. [8, 13], [8, 13], [8, 13], [8, 13],
  34178. [8, 13], [8, 13], [8, 13], [8, 13],
  34179. [8, 13], [8, 13], [8, 13], [8, 13],
  34180. [11, 23], [11, 23], // 00000101000x
  34181. [12, 50], // 000001010010
  34182. [12, 51], // 000001010011
  34183. [12, 44], // 000001010100
  34184. [12, 45], // 000001010101
  34185. [12, 46], // 000001010110
  34186. [12, 47], // 000001010111
  34187. [12, 57], // 000001011000
  34188. [12, 58], // 000001011001
  34189. [12, 61], // 000001011010
  34190. [12, 256], // 000001011011
  34191. [10, 16], [10, 16], [10, 16], [10, 16], // 0000010111xx
  34192. [10, 17], [10, 17], [10, 17], [10, 17], // 0000011000xx
  34193. [12, 48], // 000001100100
  34194. [12, 49], // 000001100101
  34195. [12, 62], // 000001100110
  34196. [12, 63], // 000001100111
  34197. [12, 30], // 000001101000
  34198. [12, 31], // 000001101001
  34199. [12, 32], // 000001101010
  34200. [12, 33], // 000001101011
  34201. [12, 40], // 000001101100
  34202. [12, 41], // 000001101101
  34203. [11, 22], [11, 22], // 00000110111x
  34204. [8, 14], [8, 14], [8, 14], [8, 14], // 00000111xxxx
  34205. [8, 14], [8, 14], [8, 14], [8, 14],
  34206. [8, 14], [8, 14], [8, 14], [8, 14],
  34207. [8, 14], [8, 14], [8, 14], [8, 14],
  34208. [7, 10], [7, 10], [7, 10], [7, 10], // 0000100xxxxx
  34209. [7, 10], [7, 10], [7, 10], [7, 10],
  34210. [7, 10], [7, 10], [7, 10], [7, 10],
  34211. [7, 10], [7, 10], [7, 10], [7, 10],
  34212. [7, 10], [7, 10], [7, 10], [7, 10],
  34213. [7, 10], [7, 10], [7, 10], [7, 10],
  34214. [7, 10], [7, 10], [7, 10], [7, 10],
  34215. [7, 10], [7, 10], [7, 10], [7, 10],
  34216. [7, 11], [7, 11], [7, 11], [7, 11], // 0000101xxxxx
  34217. [7, 11], [7, 11], [7, 11], [7, 11],
  34218. [7, 11], [7, 11], [7, 11], [7, 11],
  34219. [7, 11], [7, 11], [7, 11], [7, 11],
  34220. [7, 11], [7, 11], [7, 11], [7, 11],
  34221. [7, 11], [7, 11], [7, 11], [7, 11],
  34222. [7, 11], [7, 11], [7, 11], [7, 11],
  34223. [7, 11], [7, 11], [7, 11], [7, 11],
  34224. [9, 15], [9, 15], [9, 15], [9, 15], // 000011000xxx
  34225. [9, 15], [9, 15], [9, 15], [9, 15],
  34226. [12, 128], // 000011001000
  34227. [12, 192], // 000011001001
  34228. [12, 26], // 000011001010
  34229. [12, 27], // 000011001011
  34230. [12, 28], // 000011001100
  34231. [12, 29], // 000011001101
  34232. [11, 19], [11, 19], // 00001100111x
  34233. [11, 20], [11, 20], // 00001101000x
  34234. [12, 34], // 000011010010
  34235. [12, 35], // 000011010011
  34236. [12, 36], // 000011010100
  34237. [12, 37], // 000011010101
  34238. [12, 38], // 000011010110
  34239. [12, 39], // 000011010111
  34240. [11, 21], [11, 21], // 00001101100x
  34241. [12, 42], // 000011011010
  34242. [12, 43], // 000011011011
  34243. [10, 0], [10, 0], [10, 0], [10, 0], // 0000110111xx
  34244. [7, 12], [7, 12], [7, 12], [7, 12], // 0000111xxxxx
  34245. [7, 12], [7, 12], [7, 12], [7, 12],
  34246. [7, 12], [7, 12], [7, 12], [7, 12],
  34247. [7, 12], [7, 12], [7, 12], [7, 12],
  34248. [7, 12], [7, 12], [7, 12], [7, 12],
  34249. [7, 12], [7, 12], [7, 12], [7, 12],
  34250. [7, 12], [7, 12], [7, 12], [7, 12],
  34251. [7, 12], [7, 12], [7, 12], [7, 12]
  34252. ];
  34253. var blackTable3 = [
  34254. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000xx
  34255. [6, 9], // 000100
  34256. [6, 8], // 000101
  34257. [5, 7], [5, 7], // 00011x
  34258. [4, 6], [4, 6], [4, 6], [4, 6], // 0010xx
  34259. [4, 5], [4, 5], [4, 5], [4, 5], // 0011xx
  34260. [3, 1], [3, 1], [3, 1], [3, 1], // 010xxx
  34261. [3, 1], [3, 1], [3, 1], [3, 1],
  34262. [3, 4], [3, 4], [3, 4], [3, 4], // 011xxx
  34263. [3, 4], [3, 4], [3, 4], [3, 4],
  34264. [2, 3], [2, 3], [2, 3], [2, 3], // 10xxxx
  34265. [2, 3], [2, 3], [2, 3], [2, 3],
  34266. [2, 3], [2, 3], [2, 3], [2, 3],
  34267. [2, 3], [2, 3], [2, 3], [2, 3],
  34268. [2, 2], [2, 2], [2, 2], [2, 2], // 11xxxx
  34269. [2, 2], [2, 2], [2, 2], [2, 2],
  34270. [2, 2], [2, 2], [2, 2], [2, 2],
  34271. [2, 2], [2, 2], [2, 2], [2, 2]
  34272. ];
  34273. function CCITTFaxStream(str, maybeLength, params) {
  34274. this.str = str;
  34275. this.dict = str.dict;
  34276. params = params || Dict.empty;
  34277. this.encoding = params.get('K') || 0;
  34278. this.eoline = params.get('EndOfLine') || false;
  34279. this.byteAlign = params.get('EncodedByteAlign') || false;
  34280. this.columns = params.get('Columns') || 1728;
  34281. this.rows = params.get('Rows') || 0;
  34282. var eoblock = params.get('EndOfBlock');
  34283. if (eoblock === null || eoblock === undefined) {
  34284. eoblock = true;
  34285. }
  34286. this.eoblock = eoblock;
  34287. this.black = params.get('BlackIs1') || false;
  34288. this.codingLine = new Uint32Array(this.columns + 1);
  34289. this.refLine = new Uint32Array(this.columns + 2);
  34290. this.codingLine[0] = this.columns;
  34291. this.codingPos = 0;
  34292. this.row = 0;
  34293. this.nextLine2D = this.encoding < 0;
  34294. this.inputBits = 0;
  34295. this.inputBuf = 0;
  34296. this.outputBits = 0;
  34297. var code1;
  34298. while ((code1 = this.lookBits(12)) === 0) {
  34299. this.eatBits(1);
  34300. }
  34301. if (code1 === 1) {
  34302. this.eatBits(12);
  34303. }
  34304. if (this.encoding > 0) {
  34305. this.nextLine2D = !this.lookBits(1);
  34306. this.eatBits(1);
  34307. }
  34308. DecodeStream.call(this, maybeLength);
  34309. }
  34310. CCITTFaxStream.prototype = Object.create(DecodeStream.prototype);
  34311. CCITTFaxStream.prototype.readBlock = function CCITTFaxStream_readBlock() {
  34312. while (!this.eof) {
  34313. var c = this.lookChar();
  34314. this.ensureBuffer(this.bufferLength + 1);
  34315. this.buffer[this.bufferLength++] = c;
  34316. }
  34317. };
  34318. CCITTFaxStream.prototype.addPixels =
  34319. function ccittFaxStreamAddPixels(a1, blackPixels) {
  34320. var codingLine = this.codingLine;
  34321. var codingPos = this.codingPos;
  34322. if (a1 > codingLine[codingPos]) {
  34323. if (a1 > this.columns) {
  34324. info('row is wrong length');
  34325. this.err = true;
  34326. a1 = this.columns;
  34327. }
  34328. if ((codingPos & 1) ^ blackPixels) {
  34329. ++codingPos;
  34330. }
  34331. codingLine[codingPos] = a1;
  34332. }
  34333. this.codingPos = codingPos;
  34334. };
  34335. CCITTFaxStream.prototype.addPixelsNeg =
  34336. function ccittFaxStreamAddPixelsNeg(a1, blackPixels) {
  34337. var codingLine = this.codingLine;
  34338. var codingPos = this.codingPos;
  34339. if (a1 > codingLine[codingPos]) {
  34340. if (a1 > this.columns) {
  34341. info('row is wrong length');
  34342. this.err = true;
  34343. a1 = this.columns;
  34344. }
  34345. if ((codingPos & 1) ^ blackPixels) {
  34346. ++codingPos;
  34347. }
  34348. codingLine[codingPos] = a1;
  34349. } else if (a1 < codingLine[codingPos]) {
  34350. if (a1 < 0) {
  34351. info('invalid code');
  34352. this.err = true;
  34353. a1 = 0;
  34354. }
  34355. while (codingPos > 0 && a1 < codingLine[codingPos - 1]) {
  34356. --codingPos;
  34357. }
  34358. codingLine[codingPos] = a1;
  34359. }
  34360. this.codingPos = codingPos;
  34361. };
  34362. CCITTFaxStream.prototype.lookChar = function CCITTFaxStream_lookChar() {
  34363. var refLine = this.refLine;
  34364. var codingLine = this.codingLine;
  34365. var columns = this.columns;
  34366. var refPos, blackPixels, bits, i;
  34367. if (this.outputBits === 0) {
  34368. if (this.eof) {
  34369. return null;
  34370. }
  34371. this.err = false;
  34372. var code1, code2, code3;
  34373. if (this.nextLine2D) {
  34374. for (i = 0; codingLine[i] < columns; ++i) {
  34375. refLine[i] = codingLine[i];
  34376. }
  34377. refLine[i++] = columns;
  34378. refLine[i] = columns;
  34379. codingLine[0] = 0;
  34380. this.codingPos = 0;
  34381. refPos = 0;
  34382. blackPixels = 0;
  34383. while (codingLine[this.codingPos] < columns) {
  34384. code1 = this.getTwoDimCode();
  34385. switch (code1) {
  34386. case twoDimPass:
  34387. this.addPixels(refLine[refPos + 1], blackPixels);
  34388. if (refLine[refPos + 1] < columns) {
  34389. refPos += 2;
  34390. }
  34391. break;
  34392. case twoDimHoriz:
  34393. code1 = code2 = 0;
  34394. if (blackPixels) {
  34395. do {
  34396. code1 += (code3 = this.getBlackCode());
  34397. } while (code3 >= 64);
  34398. do {
  34399. code2 += (code3 = this.getWhiteCode());
  34400. } while (code3 >= 64);
  34401. } else {
  34402. do {
  34403. code1 += (code3 = this.getWhiteCode());
  34404. } while (code3 >= 64);
  34405. do {
  34406. code2 += (code3 = this.getBlackCode());
  34407. } while (code3 >= 64);
  34408. }
  34409. this.addPixels(codingLine[this.codingPos] +
  34410. code1, blackPixels);
  34411. if (codingLine[this.codingPos] < columns) {
  34412. this.addPixels(codingLine[this.codingPos] + code2,
  34413. blackPixels ^ 1);
  34414. }
  34415. while (refLine[refPos] <= codingLine[this.codingPos] &&
  34416. refLine[refPos] < columns) {
  34417. refPos += 2;
  34418. }
  34419. break;
  34420. case twoDimVertR3:
  34421. this.addPixels(refLine[refPos] + 3, blackPixels);
  34422. blackPixels ^= 1;
  34423. if (codingLine[this.codingPos] < columns) {
  34424. ++refPos;
  34425. while (refLine[refPos] <= codingLine[this.codingPos] &&
  34426. refLine[refPos] < columns) {
  34427. refPos += 2;
  34428. }
  34429. }
  34430. break;
  34431. case twoDimVertR2:
  34432. this.addPixels(refLine[refPos] + 2, blackPixels);
  34433. blackPixels ^= 1;
  34434. if (codingLine[this.codingPos] < columns) {
  34435. ++refPos;
  34436. while (refLine[refPos] <= codingLine[this.codingPos] &&
  34437. refLine[refPos] < columns) {
  34438. refPos += 2;
  34439. }
  34440. }
  34441. break;
  34442. case twoDimVertR1:
  34443. this.addPixels(refLine[refPos] + 1, blackPixels);
  34444. blackPixels ^= 1;
  34445. if (codingLine[this.codingPos] < columns) {
  34446. ++refPos;
  34447. while (refLine[refPos] <= codingLine[this.codingPos] &&
  34448. refLine[refPos] < columns) {
  34449. refPos += 2;
  34450. }
  34451. }
  34452. break;
  34453. case twoDimVert0:
  34454. this.addPixels(refLine[refPos], blackPixels);
  34455. blackPixels ^= 1;
  34456. if (codingLine[this.codingPos] < columns) {
  34457. ++refPos;
  34458. while (refLine[refPos] <= codingLine[this.codingPos] &&
  34459. refLine[refPos] < columns) {
  34460. refPos += 2;
  34461. }
  34462. }
  34463. break;
  34464. case twoDimVertL3:
  34465. this.addPixelsNeg(refLine[refPos] - 3, blackPixels);
  34466. blackPixels ^= 1;
  34467. if (codingLine[this.codingPos] < columns) {
  34468. if (refPos > 0) {
  34469. --refPos;
  34470. } else {
  34471. ++refPos;
  34472. }
  34473. while (refLine[refPos] <= codingLine[this.codingPos] &&
  34474. refLine[refPos] < columns) {
  34475. refPos += 2;
  34476. }
  34477. }
  34478. break;
  34479. case twoDimVertL2:
  34480. this.addPixelsNeg(refLine[refPos] - 2, blackPixels);
  34481. blackPixels ^= 1;
  34482. if (codingLine[this.codingPos] < columns) {
  34483. if (refPos > 0) {
  34484. --refPos;
  34485. } else {
  34486. ++refPos;
  34487. }
  34488. while (refLine[refPos] <= codingLine[this.codingPos] &&
  34489. refLine[refPos] < columns) {
  34490. refPos += 2;
  34491. }
  34492. }
  34493. break;
  34494. case twoDimVertL1:
  34495. this.addPixelsNeg(refLine[refPos] - 1, blackPixels);
  34496. blackPixels ^= 1;
  34497. if (codingLine[this.codingPos] < columns) {
  34498. if (refPos > 0) {
  34499. --refPos;
  34500. } else {
  34501. ++refPos;
  34502. }
  34503. while (refLine[refPos] <= codingLine[this.codingPos] &&
  34504. refLine[refPos] < columns) {
  34505. refPos += 2;
  34506. }
  34507. }
  34508. break;
  34509. case EOF:
  34510. this.addPixels(columns, 0);
  34511. this.eof = true;
  34512. break;
  34513. default:
  34514. info('bad 2d code');
  34515. this.addPixels(columns, 0);
  34516. this.err = true;
  34517. }
  34518. }
  34519. } else {
  34520. codingLine[0] = 0;
  34521. this.codingPos = 0;
  34522. blackPixels = 0;
  34523. while (codingLine[this.codingPos] < columns) {
  34524. code1 = 0;
  34525. if (blackPixels) {
  34526. do {
  34527. code1 += (code3 = this.getBlackCode());
  34528. } while (code3 >= 64);
  34529. } else {
  34530. do {
  34531. code1 += (code3 = this.getWhiteCode());
  34532. } while (code3 >= 64);
  34533. }
  34534. this.addPixels(codingLine[this.codingPos] + code1, blackPixels);
  34535. blackPixels ^= 1;
  34536. }
  34537. }
  34538. var gotEOL = false;
  34539. if (!this.eoblock && this.row === this.rows - 1) {
  34540. this.eof = true;
  34541. } else if (this.eoline || !this.byteAlign) {
  34542. code1 = this.lookBits(12);
  34543. if (this.eoline) {
  34544. while (code1 !== EOF && code1 !== 1) {
  34545. this.eatBits(1);
  34546. code1 = this.lookBits(12);
  34547. }
  34548. } else {
  34549. while (code1 === 0) {
  34550. this.eatBits(1);
  34551. code1 = this.lookBits(12);
  34552. }
  34553. }
  34554. if (code1 === 1) {
  34555. this.eatBits(12);
  34556. gotEOL = true;
  34557. } else if (code1 === EOF) {
  34558. this.eof = true;
  34559. }
  34560. }
  34561. if (this.byteAlign && !gotEOL) {
  34562. this.inputBits &= ~7;
  34563. }
  34564. if (!this.eof && this.encoding > 0) {
  34565. this.nextLine2D = !this.lookBits(1);
  34566. this.eatBits(1);
  34567. }
  34568. if (this.eoblock && gotEOL && this.byteAlign) {
  34569. code1 = this.lookBits(12);
  34570. if (code1 === 1) {
  34571. this.eatBits(12);
  34572. if (this.encoding > 0) {
  34573. this.lookBits(1);
  34574. this.eatBits(1);
  34575. }
  34576. if (this.encoding >= 0) {
  34577. for (i = 0; i < 4; ++i) {
  34578. code1 = this.lookBits(12);
  34579. if (code1 !== 1) {
  34580. info('bad rtc code: ' + code1);
  34581. }
  34582. this.eatBits(12);
  34583. if (this.encoding > 0) {
  34584. this.lookBits(1);
  34585. this.eatBits(1);
  34586. }
  34587. }
  34588. }
  34589. this.eof = true;
  34590. }
  34591. } else if (this.err && this.eoline) {
  34592. while (true) {
  34593. code1 = this.lookBits(13);
  34594. if (code1 === EOF) {
  34595. this.eof = true;
  34596. return null;
  34597. }
  34598. if ((code1 >> 1) === 1) {
  34599. break;
  34600. }
  34601. this.eatBits(1);
  34602. }
  34603. this.eatBits(12);
  34604. if (this.encoding > 0) {
  34605. this.eatBits(1);
  34606. this.nextLine2D = !(code1 & 1);
  34607. }
  34608. }
  34609. if (codingLine[0] > 0) {
  34610. this.outputBits = codingLine[this.codingPos = 0];
  34611. } else {
  34612. this.outputBits = codingLine[this.codingPos = 1];
  34613. }
  34614. this.row++;
  34615. }
  34616. var c;
  34617. if (this.outputBits >= 8) {
  34618. c = (this.codingPos & 1) ? 0 : 0xFF;
  34619. this.outputBits -= 8;
  34620. if (this.outputBits === 0 && codingLine[this.codingPos] < columns) {
  34621. this.codingPos++;
  34622. this.outputBits = (codingLine[this.codingPos] -
  34623. codingLine[this.codingPos - 1]);
  34624. }
  34625. } else {
  34626. bits = 8;
  34627. c = 0;
  34628. do {
  34629. if (this.outputBits > bits) {
  34630. c <<= bits;
  34631. if (!(this.codingPos & 1)) {
  34632. c |= 0xFF >> (8 - bits);
  34633. }
  34634. this.outputBits -= bits;
  34635. bits = 0;
  34636. } else {
  34637. c <<= this.outputBits;
  34638. if (!(this.codingPos & 1)) {
  34639. c |= 0xFF >> (8 - this.outputBits);
  34640. }
  34641. bits -= this.outputBits;
  34642. this.outputBits = 0;
  34643. if (codingLine[this.codingPos] < columns) {
  34644. this.codingPos++;
  34645. this.outputBits = (codingLine[this.codingPos] -
  34646. codingLine[this.codingPos - 1]);
  34647. } else if (bits > 0) {
  34648. c <<= bits;
  34649. bits = 0;
  34650. }
  34651. }
  34652. } while (bits);
  34653. }
  34654. if (this.black) {
  34655. c ^= 0xFF;
  34656. }
  34657. return c;
  34658. };
  34659. // This functions returns the code found from the table.
  34660. // The start and end parameters set the boundaries for searching the table.
  34661. // The limit parameter is optional. Function returns an array with three
  34662. // values. The first array element indicates whether a valid code is being
  34663. // returned. The second array element is the actual code. The third array
  34664. // element indicates whether EOF was reached.
  34665. CCITTFaxStream.prototype.findTableCode =
  34666. function ccittFaxStreamFindTableCode(start, end, table, limit) {
  34667. var limitValue = limit || 0;
  34668. for (var i = start; i <= end; ++i) {
  34669. var code = this.lookBits(i);
  34670. if (code === EOF) {
  34671. return [true, 1, false];
  34672. }
  34673. if (i < end) {
  34674. code <<= end - i;
  34675. }
  34676. if (!limitValue || code >= limitValue) {
  34677. var p = table[code - limitValue];
  34678. if (p[0] === i) {
  34679. this.eatBits(i);
  34680. return [true, p[1], true];
  34681. }
  34682. }
  34683. }
  34684. return [false, 0, false];
  34685. };
  34686. CCITTFaxStream.prototype.getTwoDimCode =
  34687. function ccittFaxStreamGetTwoDimCode() {
  34688. var code = 0;
  34689. var p;
  34690. if (this.eoblock) {
  34691. code = this.lookBits(7);
  34692. p = twoDimTable[code];
  34693. if (p && p[0] > 0) {
  34694. this.eatBits(p[0]);
  34695. return p[1];
  34696. }
  34697. } else {
  34698. var result = this.findTableCode(1, 7, twoDimTable);
  34699. if (result[0] && result[2]) {
  34700. return result[1];
  34701. }
  34702. }
  34703. info('Bad two dim code');
  34704. return EOF;
  34705. };
  34706. CCITTFaxStream.prototype.getWhiteCode =
  34707. function ccittFaxStreamGetWhiteCode() {
  34708. var code = 0;
  34709. var p;
  34710. if (this.eoblock) {
  34711. code = this.lookBits(12);
  34712. if (code === EOF) {
  34713. return 1;
  34714. }
  34715. if ((code >> 5) === 0) {
  34716. p = whiteTable1[code];
  34717. } else {
  34718. p = whiteTable2[code >> 3];
  34719. }
  34720. if (p[0] > 0) {
  34721. this.eatBits(p[0]);
  34722. return p[1];
  34723. }
  34724. } else {
  34725. var result = this.findTableCode(1, 9, whiteTable2);
  34726. if (result[0]) {
  34727. return result[1];
  34728. }
  34729. result = this.findTableCode(11, 12, whiteTable1);
  34730. if (result[0]) {
  34731. return result[1];
  34732. }
  34733. }
  34734. info('bad white code');
  34735. this.eatBits(1);
  34736. return 1;
  34737. };
  34738. CCITTFaxStream.prototype.getBlackCode =
  34739. function ccittFaxStreamGetBlackCode() {
  34740. var code, p;
  34741. if (this.eoblock) {
  34742. code = this.lookBits(13);
  34743. if (code === EOF) {
  34744. return 1;
  34745. }
  34746. if ((code >> 7) === 0) {
  34747. p = blackTable1[code];
  34748. } else if ((code >> 9) === 0 && (code >> 7) !== 0) {
  34749. p = blackTable2[(code >> 1) - 64];
  34750. } else {
  34751. p = blackTable3[code >> 7];
  34752. }
  34753. if (p[0] > 0) {
  34754. this.eatBits(p[0]);
  34755. return p[1];
  34756. }
  34757. } else {
  34758. var result = this.findTableCode(2, 6, blackTable3);
  34759. if (result[0]) {
  34760. return result[1];
  34761. }
  34762. result = this.findTableCode(7, 12, blackTable2, 64);
  34763. if (result[0]) {
  34764. return result[1];
  34765. }
  34766. result = this.findTableCode(10, 13, blackTable1);
  34767. if (result[0]) {
  34768. return result[1];
  34769. }
  34770. }
  34771. info('bad black code');
  34772. this.eatBits(1);
  34773. return 1;
  34774. };
  34775. CCITTFaxStream.prototype.lookBits = function CCITTFaxStream_lookBits(n) {
  34776. var c;
  34777. while (this.inputBits < n) {
  34778. if ((c = this.str.getByte()) === -1) {
  34779. if (this.inputBits === 0) {
  34780. return EOF;
  34781. }
  34782. return ((this.inputBuf << (n - this.inputBits)) &
  34783. (0xFFFF >> (16 - n)));
  34784. }
  34785. this.inputBuf = (this.inputBuf << 8) + c;
  34786. this.inputBits += 8;
  34787. }
  34788. return (this.inputBuf >> (this.inputBits - n)) & (0xFFFF >> (16 - n));
  34789. };
  34790. CCITTFaxStream.prototype.eatBits = function CCITTFaxStream_eatBits(n) {
  34791. if ((this.inputBits -= n) < 0) {
  34792. this.inputBits = 0;
  34793. }
  34794. };
  34795. return CCITTFaxStream;
  34796. })();
  34797. var LZWStream = (function LZWStreamClosure() {
  34798. function LZWStream(str, maybeLength, earlyChange) {
  34799. this.str = str;
  34800. this.dict = str.dict;
  34801. this.cachedData = 0;
  34802. this.bitsCached = 0;
  34803. var maxLzwDictionarySize = 4096;
  34804. var lzwState = {
  34805. earlyChange: earlyChange,
  34806. codeLength: 9,
  34807. nextCode: 258,
  34808. dictionaryValues: new Uint8Array(maxLzwDictionarySize),
  34809. dictionaryLengths: new Uint16Array(maxLzwDictionarySize),
  34810. dictionaryPrevCodes: new Uint16Array(maxLzwDictionarySize),
  34811. currentSequence: new Uint8Array(maxLzwDictionarySize),
  34812. currentSequenceLength: 0
  34813. };
  34814. for (var i = 0; i < 256; ++i) {
  34815. lzwState.dictionaryValues[i] = i;
  34816. lzwState.dictionaryLengths[i] = 1;
  34817. }
  34818. this.lzwState = lzwState;
  34819. DecodeStream.call(this, maybeLength);
  34820. }
  34821. LZWStream.prototype = Object.create(DecodeStream.prototype);
  34822. LZWStream.prototype.readBits = function LZWStream_readBits(n) {
  34823. var bitsCached = this.bitsCached;
  34824. var cachedData = this.cachedData;
  34825. while (bitsCached < n) {
  34826. var c = this.str.getByte();
  34827. if (c === -1) {
  34828. this.eof = true;
  34829. return null;
  34830. }
  34831. cachedData = (cachedData << 8) | c;
  34832. bitsCached += 8;
  34833. }
  34834. this.bitsCached = (bitsCached -= n);
  34835. this.cachedData = cachedData;
  34836. this.lastCode = null;
  34837. return (cachedData >>> bitsCached) & ((1 << n) - 1);
  34838. };
  34839. LZWStream.prototype.readBlock = function LZWStream_readBlock() {
  34840. var blockSize = 512;
  34841. var estimatedDecodedSize = blockSize * 2, decodedSizeDelta = blockSize;
  34842. var i, j, q;
  34843. var lzwState = this.lzwState;
  34844. if (!lzwState) {
  34845. return; // eof was found
  34846. }
  34847. var earlyChange = lzwState.earlyChange;
  34848. var nextCode = lzwState.nextCode;
  34849. var dictionaryValues = lzwState.dictionaryValues;
  34850. var dictionaryLengths = lzwState.dictionaryLengths;
  34851. var dictionaryPrevCodes = lzwState.dictionaryPrevCodes;
  34852. var codeLength = lzwState.codeLength;
  34853. var prevCode = lzwState.prevCode;
  34854. var currentSequence = lzwState.currentSequence;
  34855. var currentSequenceLength = lzwState.currentSequenceLength;
  34856. var decodedLength = 0;
  34857. var currentBufferLength = this.bufferLength;
  34858. var buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  34859. for (i = 0; i < blockSize; i++) {
  34860. var code = this.readBits(codeLength);
  34861. var hasPrev = currentSequenceLength > 0;
  34862. if (code < 256) {
  34863. currentSequence[0] = code;
  34864. currentSequenceLength = 1;
  34865. } else if (code >= 258) {
  34866. if (code < nextCode) {
  34867. currentSequenceLength = dictionaryLengths[code];
  34868. for (j = currentSequenceLength - 1, q = code; j >= 0; j--) {
  34869. currentSequence[j] = dictionaryValues[q];
  34870. q = dictionaryPrevCodes[q];
  34871. }
  34872. } else {
  34873. currentSequence[currentSequenceLength++] = currentSequence[0];
  34874. }
  34875. } else if (code === 256) {
  34876. codeLength = 9;
  34877. nextCode = 258;
  34878. currentSequenceLength = 0;
  34879. continue;
  34880. } else {
  34881. this.eof = true;
  34882. delete this.lzwState;
  34883. break;
  34884. }
  34885. if (hasPrev) {
  34886. dictionaryPrevCodes[nextCode] = prevCode;
  34887. dictionaryLengths[nextCode] = dictionaryLengths[prevCode] + 1;
  34888. dictionaryValues[nextCode] = currentSequence[0];
  34889. nextCode++;
  34890. codeLength = (nextCode + earlyChange) & (nextCode + earlyChange - 1) ?
  34891. codeLength : Math.min(Math.log(nextCode + earlyChange) /
  34892. 0.6931471805599453 + 1, 12) | 0;
  34893. }
  34894. prevCode = code;
  34895. decodedLength += currentSequenceLength;
  34896. if (estimatedDecodedSize < decodedLength) {
  34897. do {
  34898. estimatedDecodedSize += decodedSizeDelta;
  34899. } while (estimatedDecodedSize < decodedLength);
  34900. buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  34901. }
  34902. for (j = 0; j < currentSequenceLength; j++) {
  34903. buffer[currentBufferLength++] = currentSequence[j];
  34904. }
  34905. }
  34906. lzwState.nextCode = nextCode;
  34907. lzwState.codeLength = codeLength;
  34908. lzwState.prevCode = prevCode;
  34909. lzwState.currentSequenceLength = currentSequenceLength;
  34910. this.bufferLength = currentBufferLength;
  34911. };
  34912. return LZWStream;
  34913. })();
  34914. var NullStream = (function NullStreamClosure() {
  34915. function NullStream() {
  34916. Stream.call(this, new Uint8Array(0));
  34917. }
  34918. NullStream.prototype = Stream.prototype;
  34919. return NullStream;
  34920. })();
  34921. var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
  34922. setup: function wphSetup(handler) {
  34923. var pdfManager;
  34924. function loadDocument(recoveryMode) {
  34925. var loadDocumentCapability = createPromiseCapability();
  34926. var parseSuccess = function parseSuccess() {
  34927. var numPagesPromise = pdfManager.ensureDoc('numPages');
  34928. var fingerprintPromise = pdfManager.ensureDoc('fingerprint');
  34929. var encryptedPromise = pdfManager.ensureXRef('encrypt');
  34930. Promise.all([numPagesPromise, fingerprintPromise,
  34931. encryptedPromise]).then(function onDocReady(results) {
  34932. var doc = {
  34933. numPages: results[0],
  34934. fingerprint: results[1],
  34935. encrypted: !!results[2],
  34936. };
  34937. loadDocumentCapability.resolve(doc);
  34938. },
  34939. parseFailure);
  34940. };
  34941. var parseFailure = function parseFailure(e) {
  34942. loadDocumentCapability.reject(e);
  34943. };
  34944. pdfManager.ensureDoc('checkHeader', []).then(function() {
  34945. pdfManager.ensureDoc('parseStartXRef', []).then(function() {
  34946. pdfManager.ensureDoc('parse', [recoveryMode]).then(
  34947. parseSuccess, parseFailure);
  34948. }, parseFailure);
  34949. }, parseFailure);
  34950. return loadDocumentCapability.promise;
  34951. }
  34952. function getPdfManager(data) {
  34953. var pdfManagerCapability = createPromiseCapability();
  34954. var source = data.source;
  34955. var disableRange = data.disableRange;
  34956. if (source.data) {
  34957. try {
  34958. pdfManager = new LocalPdfManager(source.data, source.password);
  34959. pdfManagerCapability.resolve();
  34960. } catch (ex) {
  34961. pdfManagerCapability.reject(ex);
  34962. }
  34963. return pdfManagerCapability.promise;
  34964. } else if (source.chunkedViewerLoading) {
  34965. try {
  34966. pdfManager = new NetworkPdfManager(source, handler);
  34967. pdfManagerCapability.resolve();
  34968. } catch (ex) {
  34969. pdfManagerCapability.reject(ex);
  34970. }
  34971. return pdfManagerCapability.promise;
  34972. }
  34973. var networkManager = new NetworkManager(source.url, {
  34974. httpHeaders: source.httpHeaders,
  34975. withCredentials: source.withCredentials
  34976. });
  34977. var fullRequestXhrId = networkManager.requestFull({
  34978. onHeadersReceived: function onHeadersReceived() {
  34979. if (disableRange) {
  34980. return;
  34981. }
  34982. var fullRequestXhr = networkManager.getRequestXhr(fullRequestXhrId);
  34983. if (fullRequestXhr.getResponseHeader('Accept-Ranges') !== 'bytes') {
  34984. return;
  34985. }
  34986. var contentEncoding =
  34987. fullRequestXhr.getResponseHeader('Content-Encoding') || 'identity';
  34988. if (contentEncoding !== 'identity') {
  34989. return;
  34990. }
  34991. var length = fullRequestXhr.getResponseHeader('Content-Length');
  34992. length = parseInt(length, 10);
  34993. if (!isInt(length)) {
  34994. return;
  34995. }
  34996. source.length = length;
  34997. if (length <= 2 * RANGE_CHUNK_SIZE) {
  34998. // The file size is smaller than the size of two chunks, so it does
  34999. // not make any sense to abort the request and retry with a range
  35000. // request.
  35001. return;
  35002. }
  35003. // NOTE: by cancelling the full request, and then issuing range
  35004. // requests, there will be an issue for sites where you can only
  35005. // request the pdf once. However, if this is the case, then the
  35006. // server should not be returning that it can support range requests.
  35007. networkManager.abortRequest(fullRequestXhrId);
  35008. try {
  35009. pdfManager = new NetworkPdfManager(source, handler);
  35010. pdfManagerCapability.resolve(pdfManager);
  35011. } catch (ex) {
  35012. pdfManagerCapability.reject(ex);
  35013. }
  35014. },
  35015. onDone: function onDone(args) {
  35016. // the data is array, instantiating directly from it
  35017. try {
  35018. pdfManager = new LocalPdfManager(args.chunk, source.password);
  35019. pdfManagerCapability.resolve();
  35020. } catch (ex) {
  35021. pdfManagerCapability.reject(ex);
  35022. }
  35023. },
  35024. onError: function onError(status) {
  35025. if (status === 404) {
  35026. var exception = new MissingPDFException('Missing PDF "' +
  35027. source.url + '".');
  35028. handler.send('MissingPDF', { exception: exception });
  35029. } else {
  35030. handler.send('DocError', 'Unexpected server response (' +
  35031. status + ') while retrieving PDF "' +
  35032. source.url + '".');
  35033. }
  35034. },
  35035. onProgress: function onProgress(evt) {
  35036. handler.send('DocProgress', {
  35037. loaded: evt.loaded,
  35038. total: evt.lengthComputable ? evt.total : source.length
  35039. });
  35040. }
  35041. });
  35042. return pdfManagerCapability.promise;
  35043. }
  35044. handler.on('test', function wphSetupTest(data) {
  35045. // check if Uint8Array can be sent to worker
  35046. if (!(data instanceof Uint8Array)) {
  35047. handler.send('test', false);
  35048. return;
  35049. }
  35050. // making sure postMessage transfers are working
  35051. var supportTransfers = data[0] === 255;
  35052. handler.postMessageTransfers = supportTransfers;
  35053. // check if the response property is supported by xhr
  35054. var xhr = new XMLHttpRequest();
  35055. var responseExists = 'response' in xhr;
  35056. // check if the property is actually implemented
  35057. try {
  35058. var dummy = xhr.responseType;
  35059. } catch (e) {
  35060. responseExists = false;
  35061. }
  35062. if (!responseExists) {
  35063. handler.send('test', false);
  35064. return;
  35065. }
  35066. handler.send('test', {
  35067. supportTypedArray: true,
  35068. supportTransfers: supportTransfers
  35069. });
  35070. });
  35071. handler.on('GetDocRequest', function wphSetupDoc(data) {
  35072. var onSuccess = function(doc) {
  35073. handler.send('GetDoc', { pdfInfo: doc });
  35074. };
  35075. var onFailure = function(e) {
  35076. if (e instanceof PasswordException) {
  35077. if (e.code === PasswordResponses.NEED_PASSWORD) {
  35078. handler.send('NeedPassword', {
  35079. exception: e
  35080. });
  35081. } else if (e.code === PasswordResponses.INCORRECT_PASSWORD) {
  35082. handler.send('IncorrectPassword', {
  35083. exception: e
  35084. });
  35085. }
  35086. } else if (e instanceof InvalidPDFException) {
  35087. handler.send('InvalidPDF', {
  35088. exception: e
  35089. });
  35090. } else if (e instanceof MissingPDFException) {
  35091. handler.send('MissingPDF', {
  35092. exception: e
  35093. });
  35094. } else {
  35095. handler.send('UnknownError', {
  35096. exception: new UnknownErrorException(e.message, e.toString())
  35097. });
  35098. }
  35099. };
  35100. PDFJS.maxImageSize = data.maxImageSize === undefined ?
  35101. -1 : data.maxImageSize;
  35102. PDFJS.disableFontFace = data.disableFontFace;
  35103. PDFJS.disableCreateObjectURL = data.disableCreateObjectURL;
  35104. PDFJS.verbosity = data.verbosity;
  35105. PDFJS.cMapUrl = data.cMapUrl === undefined ?
  35106. null : data.cMapUrl;
  35107. PDFJS.cMapPacked = data.cMapPacked === true;
  35108. getPdfManager(data).then(function () {
  35109. pdfManager.onLoadedStream().then(function(stream) {
  35110. handler.send('DataLoaded', { length: stream.bytes.byteLength });
  35111. });
  35112. }).then(function pdfManagerReady() {
  35113. loadDocument(false).then(onSuccess, function loadFailure(ex) {
  35114. // Try again with recoveryMode == true
  35115. if (!(ex instanceof XRefParseException)) {
  35116. if (ex instanceof PasswordException) {
  35117. // after password exception prepare to receive a new password
  35118. // to repeat loading
  35119. pdfManager.passwordChanged().then(pdfManagerReady);
  35120. }
  35121. onFailure(ex);
  35122. return;
  35123. }
  35124. pdfManager.requestLoadedStream();
  35125. pdfManager.onLoadedStream().then(function() {
  35126. loadDocument(true).then(onSuccess, onFailure);
  35127. });
  35128. }, onFailure);
  35129. }, onFailure);
  35130. });
  35131. handler.on('GetPage', function wphSetupGetPage(data) {
  35132. return pdfManager.getPage(data.pageIndex).then(function(page) {
  35133. var rotatePromise = pdfManager.ensure(page, 'rotate');
  35134. var refPromise = pdfManager.ensure(page, 'ref');
  35135. var viewPromise = pdfManager.ensure(page, 'view');
  35136. return Promise.all([rotatePromise, refPromise, viewPromise]).then(
  35137. function(results) {
  35138. return {
  35139. rotate: results[0],
  35140. ref: results[1],
  35141. view: results[2]
  35142. };
  35143. });
  35144. });
  35145. });
  35146. handler.on('GetPageIndex', function wphSetupGetPageIndex(data) {
  35147. var ref = new Ref(data.ref.num, data.ref.gen);
  35148. var catalog = pdfManager.pdfDocument.catalog;
  35149. return catalog.getPageIndex(ref);
  35150. });
  35151. handler.on('GetDestinations',
  35152. function wphSetupGetDestinations(data) {
  35153. return pdfManager.ensureCatalog('destinations');
  35154. }
  35155. );
  35156. handler.on('GetAttachments',
  35157. function wphSetupGetAttachments(data) {
  35158. return pdfManager.ensureCatalog('attachments');
  35159. }
  35160. );
  35161. handler.on('GetJavaScript',
  35162. function wphSetupGetJavaScript(data) {
  35163. return pdfManager.ensureCatalog('javaScript');
  35164. }
  35165. );
  35166. handler.on('GetOutline',
  35167. function wphSetupGetOutline(data) {
  35168. return pdfManager.ensureCatalog('documentOutline');
  35169. }
  35170. );
  35171. handler.on('GetMetadata',
  35172. function wphSetupGetMetadata(data) {
  35173. return Promise.all([pdfManager.ensureDoc('documentInfo'),
  35174. pdfManager.ensureCatalog('metadata')]);
  35175. }
  35176. );
  35177. handler.on('GetData', function wphSetupGetData(data) {
  35178. pdfManager.requestLoadedStream();
  35179. return pdfManager.onLoadedStream().then(function(stream) {
  35180. return stream.bytes;
  35181. });
  35182. });
  35183. handler.on('GetStats',
  35184. function wphSetupGetStats(data) {
  35185. return pdfManager.pdfDocument.xref.stats;
  35186. }
  35187. );
  35188. handler.on('UpdatePassword', function wphSetupUpdatePassword(data) {
  35189. pdfManager.updatePassword(data);
  35190. });
  35191. handler.on('GetAnnotations', function wphSetupGetAnnotations(data) {
  35192. return pdfManager.getPage(data.pageIndex).then(function(page) {
  35193. return pdfManager.ensure(page, 'getAnnotationsData', []);
  35194. });
  35195. });
  35196. handler.on('RenderPageRequest', function wphSetupRenderPage(data) {
  35197. pdfManager.getPage(data.pageIndex).then(function(page) {
  35198. var pageNum = data.pageIndex + 1;
  35199. var start = Date.now();
  35200. // Pre compile the pdf page and fetch the fonts/images.
  35201. page.getOperatorList(handler, data.intent).then(function(operatorList) {
  35202. info('page=' + pageNum + ' - getOperatorList: time=' +
  35203. (Date.now() - start) + 'ms, len=' + operatorList.fnArray.length);
  35204. }, function(e) {
  35205. var minimumStackMessage =
  35206. 'worker.js: while trying to getPage() and getOperatorList()';
  35207. var wrappedException;
  35208. // Turn the error into an obj that can be serialized
  35209. if (typeof e === 'string') {
  35210. wrappedException = {
  35211. message: e,
  35212. stack: minimumStackMessage
  35213. };
  35214. } else if (typeof e === 'object') {
  35215. wrappedException = {
  35216. message: e.message || e.toString(),
  35217. stack: e.stack || minimumStackMessage
  35218. };
  35219. } else {
  35220. wrappedException = {
  35221. message: 'Unknown exception type: ' + (typeof e),
  35222. stack: minimumStackMessage
  35223. };
  35224. }
  35225. handler.send('PageError', {
  35226. pageNum: pageNum,
  35227. error: wrappedException,
  35228. intent: data.intent
  35229. });
  35230. });
  35231. });
  35232. }, this);
  35233. handler.on('GetTextContent', function wphExtractText(data) {
  35234. return pdfManager.getPage(data.pageIndex).then(function(page) {
  35235. var pageNum = data.pageIndex + 1;
  35236. var start = Date.now();
  35237. return page.extractTextContent().then(function(textContent) {
  35238. info('text indexing: page=' + pageNum + ' - time=' +
  35239. (Date.now() - start) + 'ms');
  35240. return textContent;
  35241. });
  35242. });
  35243. });
  35244. handler.on('Cleanup', function wphCleanup(data) {
  35245. return pdfManager.cleanup();
  35246. });
  35247. handler.on('Terminate', function wphTerminate(data) {
  35248. pdfManager.terminate();
  35249. });
  35250. }
  35251. };
  35252. var consoleTimer = {};
  35253. var workerConsole = {
  35254. log: function log() {
  35255. var args = Array.prototype.slice.call(arguments);
  35256. globalScope.postMessage({
  35257. action: 'console_log',
  35258. data: args
  35259. });
  35260. },
  35261. error: function error() {
  35262. var args = Array.prototype.slice.call(arguments);
  35263. globalScope.postMessage({
  35264. action: 'console_error',
  35265. data: args
  35266. });
  35267. throw 'pdf.js execution error';
  35268. },
  35269. time: function time(name) {
  35270. consoleTimer[name] = Date.now();
  35271. },
  35272. timeEnd: function timeEnd(name) {
  35273. var time = consoleTimer[name];
  35274. if (!time) {
  35275. error('Unknown timer name ' + name);
  35276. }
  35277. this.log('Timer:', name, Date.now() - time);
  35278. }
  35279. };
  35280. // Worker thread?
  35281. if (typeof window === 'undefined') {
  35282. if (!('console' in globalScope)) {
  35283. globalScope.console = workerConsole;
  35284. }
  35285. // Listen for unsupported features so we can pass them on to the main thread.
  35286. PDFJS.UnsupportedManager.listen(function (msg) {
  35287. globalScope.postMessage({
  35288. action: '_unsupported_feature',
  35289. data: msg
  35290. });
  35291. });
  35292. var handler = new MessageHandler('worker_processor', this);
  35293. WorkerMessageHandler.setup(handler);
  35294. }
  35295. /* This class implements the QM Coder decoding as defined in
  35296. * JPEG 2000 Part I Final Committee Draft Version 1.0
  35297. * Annex C.3 Arithmetic decoding procedure
  35298. * available at http://www.jpeg.org/public/fcd15444-1.pdf
  35299. *
  35300. * The arithmetic decoder is used in conjunction with context models to decode
  35301. * JPEG2000 and JBIG2 streams.
  35302. */
  35303. var ArithmeticDecoder = (function ArithmeticDecoderClosure() {
  35304. // Table C-2
  35305. var QeTable = [
  35306. {qe: 0x5601, nmps: 1, nlps: 1, switchFlag: 1},
  35307. {qe: 0x3401, nmps: 2, nlps: 6, switchFlag: 0},
  35308. {qe: 0x1801, nmps: 3, nlps: 9, switchFlag: 0},
  35309. {qe: 0x0AC1, nmps: 4, nlps: 12, switchFlag: 0},
  35310. {qe: 0x0521, nmps: 5, nlps: 29, switchFlag: 0},
  35311. {qe: 0x0221, nmps: 38, nlps: 33, switchFlag: 0},
  35312. {qe: 0x5601, nmps: 7, nlps: 6, switchFlag: 1},
  35313. {qe: 0x5401, nmps: 8, nlps: 14, switchFlag: 0},
  35314. {qe: 0x4801, nmps: 9, nlps: 14, switchFlag: 0},
  35315. {qe: 0x3801, nmps: 10, nlps: 14, switchFlag: 0},
  35316. {qe: 0x3001, nmps: 11, nlps: 17, switchFlag: 0},
  35317. {qe: 0x2401, nmps: 12, nlps: 18, switchFlag: 0},
  35318. {qe: 0x1C01, nmps: 13, nlps: 20, switchFlag: 0},
  35319. {qe: 0x1601, nmps: 29, nlps: 21, switchFlag: 0},
  35320. {qe: 0x5601, nmps: 15, nlps: 14, switchFlag: 1},
  35321. {qe: 0x5401, nmps: 16, nlps: 14, switchFlag: 0},
  35322. {qe: 0x5101, nmps: 17, nlps: 15, switchFlag: 0},
  35323. {qe: 0x4801, nmps: 18, nlps: 16, switchFlag: 0},
  35324. {qe: 0x3801, nmps: 19, nlps: 17, switchFlag: 0},
  35325. {qe: 0x3401, nmps: 20, nlps: 18, switchFlag: 0},
  35326. {qe: 0x3001, nmps: 21, nlps: 19, switchFlag: 0},
  35327. {qe: 0x2801, nmps: 22, nlps: 19, switchFlag: 0},
  35328. {qe: 0x2401, nmps: 23, nlps: 20, switchFlag: 0},
  35329. {qe: 0x2201, nmps: 24, nlps: 21, switchFlag: 0},
  35330. {qe: 0x1C01, nmps: 25, nlps: 22, switchFlag: 0},
  35331. {qe: 0x1801, nmps: 26, nlps: 23, switchFlag: 0},
  35332. {qe: 0x1601, nmps: 27, nlps: 24, switchFlag: 0},
  35333. {qe: 0x1401, nmps: 28, nlps: 25, switchFlag: 0},
  35334. {qe: 0x1201, nmps: 29, nlps: 26, switchFlag: 0},
  35335. {qe: 0x1101, nmps: 30, nlps: 27, switchFlag: 0},
  35336. {qe: 0x0AC1, nmps: 31, nlps: 28, switchFlag: 0},
  35337. {qe: 0x09C1, nmps: 32, nlps: 29, switchFlag: 0},
  35338. {qe: 0x08A1, nmps: 33, nlps: 30, switchFlag: 0},
  35339. {qe: 0x0521, nmps: 34, nlps: 31, switchFlag: 0},
  35340. {qe: 0x0441, nmps: 35, nlps: 32, switchFlag: 0},
  35341. {qe: 0x02A1, nmps: 36, nlps: 33, switchFlag: 0},
  35342. {qe: 0x0221, nmps: 37, nlps: 34, switchFlag: 0},
  35343. {qe: 0x0141, nmps: 38, nlps: 35, switchFlag: 0},
  35344. {qe: 0x0111, nmps: 39, nlps: 36, switchFlag: 0},
  35345. {qe: 0x0085, nmps: 40, nlps: 37, switchFlag: 0},
  35346. {qe: 0x0049, nmps: 41, nlps: 38, switchFlag: 0},
  35347. {qe: 0x0025, nmps: 42, nlps: 39, switchFlag: 0},
  35348. {qe: 0x0015, nmps: 43, nlps: 40, switchFlag: 0},
  35349. {qe: 0x0009, nmps: 44, nlps: 41, switchFlag: 0},
  35350. {qe: 0x0005, nmps: 45, nlps: 42, switchFlag: 0},
  35351. {qe: 0x0001, nmps: 45, nlps: 43, switchFlag: 0},
  35352. {qe: 0x5601, nmps: 46, nlps: 46, switchFlag: 0}
  35353. ];
  35354. // C.3.5 Initialisation of the decoder (INITDEC)
  35355. function ArithmeticDecoder(data, start, end) {
  35356. this.data = data;
  35357. this.bp = start;
  35358. this.dataEnd = end;
  35359. this.chigh = data[start];
  35360. this.clow = 0;
  35361. this.byteIn();
  35362. this.chigh = ((this.chigh << 7) & 0xFFFF) | ((this.clow >> 9) & 0x7F);
  35363. this.clow = (this.clow << 7) & 0xFFFF;
  35364. this.ct -= 7;
  35365. this.a = 0x8000;
  35366. }
  35367. ArithmeticDecoder.prototype = {
  35368. // C.3.4 Compressed data input (BYTEIN)
  35369. byteIn: function ArithmeticDecoder_byteIn() {
  35370. var data = this.data;
  35371. var bp = this.bp;
  35372. if (data[bp] === 0xFF) {
  35373. var b1 = data[bp + 1];
  35374. if (b1 > 0x8F) {
  35375. this.clow += 0xFF00;
  35376. this.ct = 8;
  35377. } else {
  35378. bp++;
  35379. this.clow += (data[bp] << 9);
  35380. this.ct = 7;
  35381. this.bp = bp;
  35382. }
  35383. } else {
  35384. bp++;
  35385. this.clow += bp < this.dataEnd ? (data[bp] << 8) : 0xFF00;
  35386. this.ct = 8;
  35387. this.bp = bp;
  35388. }
  35389. if (this.clow > 0xFFFF) {
  35390. this.chigh += (this.clow >> 16);
  35391. this.clow &= 0xFFFF;
  35392. }
  35393. },
  35394. // C.3.2 Decoding a decision (DECODE)
  35395. readBit: function ArithmeticDecoder_readBit(contexts, pos) {
  35396. // contexts are packed into 1 byte:
  35397. // highest 7 bits carry cx.index, lowest bit carries cx.mps
  35398. var cx_index = contexts[pos] >> 1, cx_mps = contexts[pos] & 1;
  35399. var qeTableIcx = QeTable[cx_index];
  35400. var qeIcx = qeTableIcx.qe;
  35401. var d;
  35402. var a = this.a - qeIcx;
  35403. if (this.chigh < qeIcx) {
  35404. // exchangeLps
  35405. if (a < qeIcx) {
  35406. a = qeIcx;
  35407. d = cx_mps;
  35408. cx_index = qeTableIcx.nmps;
  35409. } else {
  35410. a = qeIcx;
  35411. d = 1 ^ cx_mps;
  35412. if (qeTableIcx.switchFlag === 1) {
  35413. cx_mps = d;
  35414. }
  35415. cx_index = qeTableIcx.nlps;
  35416. }
  35417. } else {
  35418. this.chigh -= qeIcx;
  35419. if ((a & 0x8000) !== 0) {
  35420. this.a = a;
  35421. return cx_mps;
  35422. }
  35423. // exchangeMps
  35424. if (a < qeIcx) {
  35425. d = 1 ^ cx_mps;
  35426. if (qeTableIcx.switchFlag === 1) {
  35427. cx_mps = d;
  35428. }
  35429. cx_index = qeTableIcx.nlps;
  35430. } else {
  35431. d = cx_mps;
  35432. cx_index = qeTableIcx.nmps;
  35433. }
  35434. }
  35435. // C.3.3 renormD;
  35436. do {
  35437. if (this.ct === 0) {
  35438. this.byteIn();
  35439. }
  35440. a <<= 1;
  35441. this.chigh = ((this.chigh << 1) & 0xFFFF) | ((this.clow >> 15) & 1);
  35442. this.clow = (this.clow << 1) & 0xFFFF;
  35443. this.ct--;
  35444. } while ((a & 0x8000) === 0);
  35445. this.a = a;
  35446. contexts[pos] = cx_index << 1 | cx_mps;
  35447. return d;
  35448. }
  35449. };
  35450. return ArithmeticDecoder;
  35451. })();
  35452. var JpegImage = (function jpegImage() {
  35453. var dctZigZag = new Uint8Array([
  35454. 0,
  35455. 1, 8,
  35456. 16, 9, 2,
  35457. 3, 10, 17, 24,
  35458. 32, 25, 18, 11, 4,
  35459. 5, 12, 19, 26, 33, 40,
  35460. 48, 41, 34, 27, 20, 13, 6,
  35461. 7, 14, 21, 28, 35, 42, 49, 56,
  35462. 57, 50, 43, 36, 29, 22, 15,
  35463. 23, 30, 37, 44, 51, 58,
  35464. 59, 52, 45, 38, 31,
  35465. 39, 46, 53, 60,
  35466. 61, 54, 47,
  35467. 55, 62,
  35468. 63
  35469. ]);
  35470. var dctCos1 = 4017; // cos(pi/16)
  35471. var dctSin1 = 799; // sin(pi/16)
  35472. var dctCos3 = 3406; // cos(3*pi/16)
  35473. var dctSin3 = 2276; // sin(3*pi/16)
  35474. var dctCos6 = 1567; // cos(6*pi/16)
  35475. var dctSin6 = 3784; // sin(6*pi/16)
  35476. var dctSqrt2 = 5793; // sqrt(2)
  35477. var dctSqrt1d2 = 2896; // sqrt(2) / 2
  35478. function constructor() {
  35479. }
  35480. function buildHuffmanTable(codeLengths, values) {
  35481. var k = 0, code = [], i, j, length = 16;
  35482. while (length > 0 && !codeLengths[length - 1]) {
  35483. length--;
  35484. }
  35485. code.push({children: [], index: 0});
  35486. var p = code[0], q;
  35487. for (i = 0; i < length; i++) {
  35488. for (j = 0; j < codeLengths[i]; j++) {
  35489. p = code.pop();
  35490. p.children[p.index] = values[k];
  35491. while (p.index > 0) {
  35492. p = code.pop();
  35493. }
  35494. p.index++;
  35495. code.push(p);
  35496. while (code.length <= i) {
  35497. code.push(q = {children: [], index: 0});
  35498. p.children[p.index] = q.children;
  35499. p = q;
  35500. }
  35501. k++;
  35502. }
  35503. if (i + 1 < length) {
  35504. // p here points to last code
  35505. code.push(q = {children: [], index: 0});
  35506. p.children[p.index] = q.children;
  35507. p = q;
  35508. }
  35509. }
  35510. return code[0].children;
  35511. }
  35512. function getBlockBufferOffset(component, row, col) {
  35513. return 64 * ((component.blocksPerLine + 1) * row + col);
  35514. }
  35515. function decodeScan(data, offset, frame, components, resetInterval,
  35516. spectralStart, spectralEnd, successivePrev, successive) {
  35517. var precision = frame.precision;
  35518. var samplesPerLine = frame.samplesPerLine;
  35519. var scanLines = frame.scanLines;
  35520. var mcusPerLine = frame.mcusPerLine;
  35521. var progressive = frame.progressive;
  35522. var maxH = frame.maxH, maxV = frame.maxV;
  35523. var startOffset = offset, bitsData = 0, bitsCount = 0;
  35524. function readBit() {
  35525. if (bitsCount > 0) {
  35526. bitsCount--;
  35527. return (bitsData >> bitsCount) & 1;
  35528. }
  35529. bitsData = data[offset++];
  35530. if (bitsData === 0xFF) {
  35531. var nextByte = data[offset++];
  35532. if (nextByte) {
  35533. throw 'unexpected marker: ' +
  35534. ((bitsData << 8) | nextByte).toString(16);
  35535. }
  35536. // unstuff 0
  35537. }
  35538. bitsCount = 7;
  35539. return bitsData >>> 7;
  35540. }
  35541. function decodeHuffman(tree) {
  35542. var node = tree;
  35543. var bit;
  35544. while ((bit = readBit()) !== null) {
  35545. node = node[bit];
  35546. if (typeof node === 'number') {
  35547. return node;
  35548. }
  35549. if (typeof node !== 'object') {
  35550. throw 'invalid huffman sequence';
  35551. }
  35552. }
  35553. return null;
  35554. }
  35555. function receive(length) {
  35556. var n = 0;
  35557. while (length > 0) {
  35558. var bit = readBit();
  35559. if (bit === null) {
  35560. return;
  35561. }
  35562. n = (n << 1) | bit;
  35563. length--;
  35564. }
  35565. return n;
  35566. }
  35567. function receiveAndExtend(length) {
  35568. if (length === 1) {
  35569. return readBit() === 1 ? 1 : -1;
  35570. }
  35571. var n = receive(length);
  35572. if (n >= 1 << (length - 1)) {
  35573. return n;
  35574. }
  35575. return n + (-1 << length) + 1;
  35576. }
  35577. function decodeBaseline(component, offset) {
  35578. var t = decodeHuffman(component.huffmanTableDC);
  35579. var diff = t === 0 ? 0 : receiveAndExtend(t);
  35580. component.blockData[offset] = (component.pred += diff);
  35581. var k = 1;
  35582. while (k < 64) {
  35583. var rs = decodeHuffman(component.huffmanTableAC);
  35584. var s = rs & 15, r = rs >> 4;
  35585. if (s === 0) {
  35586. if (r < 15) {
  35587. break;
  35588. }
  35589. k += 16;
  35590. continue;
  35591. }
  35592. k += r;
  35593. var z = dctZigZag[k];
  35594. component.blockData[offset + z] = receiveAndExtend(s);
  35595. k++;
  35596. }
  35597. }
  35598. function decodeDCFirst(component, offset) {
  35599. var t = decodeHuffman(component.huffmanTableDC);
  35600. var diff = t === 0 ? 0 : (receiveAndExtend(t) << successive);
  35601. component.blockData[offset] = (component.pred += diff);
  35602. }
  35603. function decodeDCSuccessive(component, offset) {
  35604. component.blockData[offset] |= readBit() << successive;
  35605. }
  35606. var eobrun = 0;
  35607. function decodeACFirst(component, offset) {
  35608. if (eobrun > 0) {
  35609. eobrun--;
  35610. return;
  35611. }
  35612. var k = spectralStart, e = spectralEnd;
  35613. while (k <= e) {
  35614. var rs = decodeHuffman(component.huffmanTableAC);
  35615. var s = rs & 15, r = rs >> 4;
  35616. if (s === 0) {
  35617. if (r < 15) {
  35618. eobrun = receive(r) + (1 << r) - 1;
  35619. break;
  35620. }
  35621. k += 16;
  35622. continue;
  35623. }
  35624. k += r;
  35625. var z = dctZigZag[k];
  35626. component.blockData[offset + z] =
  35627. receiveAndExtend(s) * (1 << successive);
  35628. k++;
  35629. }
  35630. }
  35631. var successiveACState = 0, successiveACNextValue;
  35632. function decodeACSuccessive(component, offset) {
  35633. var k = spectralStart;
  35634. var e = spectralEnd;
  35635. var r = 0;
  35636. var s;
  35637. var rs;
  35638. while (k <= e) {
  35639. var z = dctZigZag[k];
  35640. switch (successiveACState) {
  35641. case 0: // initial state
  35642. rs = decodeHuffman(component.huffmanTableAC);
  35643. s = rs & 15;
  35644. r = rs >> 4;
  35645. if (s === 0) {
  35646. if (r < 15) {
  35647. eobrun = receive(r) + (1 << r);
  35648. successiveACState = 4;
  35649. } else {
  35650. r = 16;
  35651. successiveACState = 1;
  35652. }
  35653. } else {
  35654. if (s !== 1) {
  35655. throw 'invalid ACn encoding';
  35656. }
  35657. successiveACNextValue = receiveAndExtend(s);
  35658. successiveACState = r ? 2 : 3;
  35659. }
  35660. continue;
  35661. case 1: // skipping r zero items
  35662. case 2:
  35663. if (component.blockData[offset + z]) {
  35664. component.blockData[offset + z] += (readBit() << successive);
  35665. } else {
  35666. r--;
  35667. if (r === 0) {
  35668. successiveACState = successiveACState === 2 ? 3 : 0;
  35669. }
  35670. }
  35671. break;
  35672. case 3: // set value for a zero item
  35673. if (component.blockData[offset + z]) {
  35674. component.blockData[offset + z] += (readBit() << successive);
  35675. } else {
  35676. component.blockData[offset + z] =
  35677. successiveACNextValue << successive;
  35678. successiveACState = 0;
  35679. }
  35680. break;
  35681. case 4: // eob
  35682. if (component.blockData[offset + z]) {
  35683. component.blockData[offset + z] += (readBit() << successive);
  35684. }
  35685. break;
  35686. }
  35687. k++;
  35688. }
  35689. if (successiveACState === 4) {
  35690. eobrun--;
  35691. if (eobrun === 0) {
  35692. successiveACState = 0;
  35693. }
  35694. }
  35695. }
  35696. function decodeMcu(component, decode, mcu, row, col) {
  35697. var mcuRow = (mcu / mcusPerLine) | 0;
  35698. var mcuCol = mcu % mcusPerLine;
  35699. var blockRow = mcuRow * component.v + row;
  35700. var blockCol = mcuCol * component.h + col;
  35701. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  35702. decode(component, offset);
  35703. }
  35704. function decodeBlock(component, decode, mcu) {
  35705. var blockRow = (mcu / component.blocksPerLine) | 0;
  35706. var blockCol = mcu % component.blocksPerLine;
  35707. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  35708. decode(component, offset);
  35709. }
  35710. var componentsLength = components.length;
  35711. var component, i, j, k, n;
  35712. var decodeFn;
  35713. if (progressive) {
  35714. if (spectralStart === 0) {
  35715. decodeFn = successivePrev === 0 ? decodeDCFirst : decodeDCSuccessive;
  35716. } else {
  35717. decodeFn = successivePrev === 0 ? decodeACFirst : decodeACSuccessive;
  35718. }
  35719. } else {
  35720. decodeFn = decodeBaseline;
  35721. }
  35722. var mcu = 0, marker;
  35723. var mcuExpected;
  35724. if (componentsLength === 1) {
  35725. mcuExpected = components[0].blocksPerLine * components[0].blocksPerColumn;
  35726. } else {
  35727. mcuExpected = mcusPerLine * frame.mcusPerColumn;
  35728. }
  35729. if (!resetInterval) {
  35730. resetInterval = mcuExpected;
  35731. }
  35732. var h, v;
  35733. while (mcu < mcuExpected) {
  35734. // reset interval stuff
  35735. for (i = 0; i < componentsLength; i++) {
  35736. components[i].pred = 0;
  35737. }
  35738. eobrun = 0;
  35739. if (componentsLength === 1) {
  35740. component = components[0];
  35741. for (n = 0; n < resetInterval; n++) {
  35742. decodeBlock(component, decodeFn, mcu);
  35743. mcu++;
  35744. }
  35745. } else {
  35746. for (n = 0; n < resetInterval; n++) {
  35747. for (i = 0; i < componentsLength; i++) {
  35748. component = components[i];
  35749. h = component.h;
  35750. v = component.v;
  35751. for (j = 0; j < v; j++) {
  35752. for (k = 0; k < h; k++) {
  35753. decodeMcu(component, decodeFn, mcu, j, k);
  35754. }
  35755. }
  35756. }
  35757. mcu++;
  35758. }
  35759. }
  35760. // find marker
  35761. bitsCount = 0;
  35762. marker = (data[offset] << 8) | data[offset + 1];
  35763. if (marker <= 0xFF00) {
  35764. throw 'marker was not found';
  35765. }
  35766. if (marker >= 0xFFD0 && marker <= 0xFFD7) { // RSTx
  35767. offset += 2;
  35768. } else {
  35769. break;
  35770. }
  35771. }
  35772. return offset - startOffset;
  35773. }
  35774. // A port of poppler's IDCT method which in turn is taken from:
  35775. // Christoph Loeffler, Adriaan Ligtenberg, George S. Moschytz,
  35776. // 'Practical Fast 1-D DCT Algorithms with 11 Multiplications',
  35777. // IEEE Intl. Conf. on Acoustics, Speech & Signal Processing, 1989,
  35778. // 988-991.
  35779. function quantizeAndInverse(component, blockBufferOffset, p) {
  35780. var qt = component.quantizationTable, blockData = component.blockData;
  35781. var v0, v1, v2, v3, v4, v5, v6, v7;
  35782. var p0, p1, p2, p3, p4, p5, p6, p7;
  35783. var t;
  35784. // inverse DCT on rows
  35785. for (var row = 0; row < 64; row += 8) {
  35786. // gather block data
  35787. p0 = blockData[blockBufferOffset + row];
  35788. p1 = blockData[blockBufferOffset + row + 1];
  35789. p2 = blockData[blockBufferOffset + row + 2];
  35790. p3 = blockData[blockBufferOffset + row + 3];
  35791. p4 = blockData[blockBufferOffset + row + 4];
  35792. p5 = blockData[blockBufferOffset + row + 5];
  35793. p6 = blockData[blockBufferOffset + row + 6];
  35794. p7 = blockData[blockBufferOffset + row + 7];
  35795. // dequant p0
  35796. p0 *= qt[row];
  35797. // check for all-zero AC coefficients
  35798. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  35799. t = (dctSqrt2 * p0 + 512) >> 10;
  35800. p[row] = t;
  35801. p[row + 1] = t;
  35802. p[row + 2] = t;
  35803. p[row + 3] = t;
  35804. p[row + 4] = t;
  35805. p[row + 5] = t;
  35806. p[row + 6] = t;
  35807. p[row + 7] = t;
  35808. continue;
  35809. }
  35810. // dequant p1 ... p7
  35811. p1 *= qt[row + 1];
  35812. p2 *= qt[row + 2];
  35813. p3 *= qt[row + 3];
  35814. p4 *= qt[row + 4];
  35815. p5 *= qt[row + 5];
  35816. p6 *= qt[row + 6];
  35817. p7 *= qt[row + 7];
  35818. // stage 4
  35819. v0 = (dctSqrt2 * p0 + 128) >> 8;
  35820. v1 = (dctSqrt2 * p4 + 128) >> 8;
  35821. v2 = p2;
  35822. v3 = p6;
  35823. v4 = (dctSqrt1d2 * (p1 - p7) + 128) >> 8;
  35824. v7 = (dctSqrt1d2 * (p1 + p7) + 128) >> 8;
  35825. v5 = p3 << 4;
  35826. v6 = p5 << 4;
  35827. // stage 3
  35828. v0 = (v0 + v1 + 1) >> 1;
  35829. v1 = v0 - v1;
  35830. t = (v2 * dctSin6 + v3 * dctCos6 + 128) >> 8;
  35831. v2 = (v2 * dctCos6 - v3 * dctSin6 + 128) >> 8;
  35832. v3 = t;
  35833. v4 = (v4 + v6 + 1) >> 1;
  35834. v6 = v4 - v6;
  35835. v7 = (v7 + v5 + 1) >> 1;
  35836. v5 = v7 - v5;
  35837. // stage 2
  35838. v0 = (v0 + v3 + 1) >> 1;
  35839. v3 = v0 - v3;
  35840. v1 = (v1 + v2 + 1) >> 1;
  35841. v2 = v1 - v2;
  35842. t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12;
  35843. v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12;
  35844. v7 = t;
  35845. t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12;
  35846. v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12;
  35847. v6 = t;
  35848. // stage 1
  35849. p[row] = v0 + v7;
  35850. p[row + 7] = v0 - v7;
  35851. p[row + 1] = v1 + v6;
  35852. p[row + 6] = v1 - v6;
  35853. p[row + 2] = v2 + v5;
  35854. p[row + 5] = v2 - v5;
  35855. p[row + 3] = v3 + v4;
  35856. p[row + 4] = v3 - v4;
  35857. }
  35858. // inverse DCT on columns
  35859. for (var col = 0; col < 8; ++col) {
  35860. p0 = p[col];
  35861. p1 = p[col + 8];
  35862. p2 = p[col + 16];
  35863. p3 = p[col + 24];
  35864. p4 = p[col + 32];
  35865. p5 = p[col + 40];
  35866. p6 = p[col + 48];
  35867. p7 = p[col + 56];
  35868. // check for all-zero AC coefficients
  35869. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  35870. t = (dctSqrt2 * p0 + 8192) >> 14;
  35871. // convert to 8 bit
  35872. t = (t < -2040) ? 0 : (t >= 2024) ? 255 : (t + 2056) >> 4;
  35873. blockData[blockBufferOffset + col] = t;
  35874. blockData[blockBufferOffset + col + 8] = t;
  35875. blockData[blockBufferOffset + col + 16] = t;
  35876. blockData[blockBufferOffset + col + 24] = t;
  35877. blockData[blockBufferOffset + col + 32] = t;
  35878. blockData[blockBufferOffset + col + 40] = t;
  35879. blockData[blockBufferOffset + col + 48] = t;
  35880. blockData[blockBufferOffset + col + 56] = t;
  35881. continue;
  35882. }
  35883. // stage 4
  35884. v0 = (dctSqrt2 * p0 + 2048) >> 12;
  35885. v1 = (dctSqrt2 * p4 + 2048) >> 12;
  35886. v2 = p2;
  35887. v3 = p6;
  35888. v4 = (dctSqrt1d2 * (p1 - p7) + 2048) >> 12;
  35889. v7 = (dctSqrt1d2 * (p1 + p7) + 2048) >> 12;
  35890. v5 = p3;
  35891. v6 = p5;
  35892. // stage 3
  35893. // Shift v0 by 128.5 << 5 here, so we don't need to shift p0...p7 when
  35894. // converting to UInt8 range later.
  35895. v0 = ((v0 + v1 + 1) >> 1) + 4112;
  35896. v1 = v0 - v1;
  35897. t = (v2 * dctSin6 + v3 * dctCos6 + 2048) >> 12;
  35898. v2 = (v2 * dctCos6 - v3 * dctSin6 + 2048) >> 12;
  35899. v3 = t;
  35900. v4 = (v4 + v6 + 1) >> 1;
  35901. v6 = v4 - v6;
  35902. v7 = (v7 + v5 + 1) >> 1;
  35903. v5 = v7 - v5;
  35904. // stage 2
  35905. v0 = (v0 + v3 + 1) >> 1;
  35906. v3 = v0 - v3;
  35907. v1 = (v1 + v2 + 1) >> 1;
  35908. v2 = v1 - v2;
  35909. t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12;
  35910. v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12;
  35911. v7 = t;
  35912. t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12;
  35913. v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12;
  35914. v6 = t;
  35915. // stage 1
  35916. p0 = v0 + v7;
  35917. p7 = v0 - v7;
  35918. p1 = v1 + v6;
  35919. p6 = v1 - v6;
  35920. p2 = v2 + v5;
  35921. p5 = v2 - v5;
  35922. p3 = v3 + v4;
  35923. p4 = v3 - v4;
  35924. // convert to 8-bit integers
  35925. p0 = (p0 < 16) ? 0 : (p0 >= 4080) ? 255 : p0 >> 4;
  35926. p1 = (p1 < 16) ? 0 : (p1 >= 4080) ? 255 : p1 >> 4;
  35927. p2 = (p2 < 16) ? 0 : (p2 >= 4080) ? 255 : p2 >> 4;
  35928. p3 = (p3 < 16) ? 0 : (p3 >= 4080) ? 255 : p3 >> 4;
  35929. p4 = (p4 < 16) ? 0 : (p4 >= 4080) ? 255 : p4 >> 4;
  35930. p5 = (p5 < 16) ? 0 : (p5 >= 4080) ? 255 : p5 >> 4;
  35931. p6 = (p6 < 16) ? 0 : (p6 >= 4080) ? 255 : p6 >> 4;
  35932. p7 = (p7 < 16) ? 0 : (p7 >= 4080) ? 255 : p7 >> 4;
  35933. // store block data
  35934. blockData[blockBufferOffset + col] = p0;
  35935. blockData[blockBufferOffset + col + 8] = p1;
  35936. blockData[blockBufferOffset + col + 16] = p2;
  35937. blockData[blockBufferOffset + col + 24] = p3;
  35938. blockData[blockBufferOffset + col + 32] = p4;
  35939. blockData[blockBufferOffset + col + 40] = p5;
  35940. blockData[blockBufferOffset + col + 48] = p6;
  35941. blockData[blockBufferOffset + col + 56] = p7;
  35942. }
  35943. }
  35944. function buildComponentData(frame, component) {
  35945. var blocksPerLine = component.blocksPerLine;
  35946. var blocksPerColumn = component.blocksPerColumn;
  35947. var computationBuffer = new Int16Array(64);
  35948. for (var blockRow = 0; blockRow < blocksPerColumn; blockRow++) {
  35949. for (var blockCol = 0; blockCol < blocksPerLine; blockCol++) {
  35950. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  35951. quantizeAndInverse(component, offset, computationBuffer);
  35952. }
  35953. }
  35954. return component.blockData;
  35955. }
  35956. function clamp0to255(a) {
  35957. return a <= 0 ? 0 : a >= 255 ? 255 : a;
  35958. }
  35959. constructor.prototype = {
  35960. parse: function parse(data) {
  35961. function readUint16() {
  35962. var value = (data[offset] << 8) | data[offset + 1];
  35963. offset += 2;
  35964. return value;
  35965. }
  35966. function readDataBlock() {
  35967. var length = readUint16();
  35968. var array = data.subarray(offset, offset + length - 2);
  35969. offset += array.length;
  35970. return array;
  35971. }
  35972. function prepareComponents(frame) {
  35973. var mcusPerLine = Math.ceil(frame.samplesPerLine / 8 / frame.maxH);
  35974. var mcusPerColumn = Math.ceil(frame.scanLines / 8 / frame.maxV);
  35975. for (var i = 0; i < frame.components.length; i++) {
  35976. component = frame.components[i];
  35977. var blocksPerLine = Math.ceil(Math.ceil(frame.samplesPerLine / 8) *
  35978. component.h / frame.maxH);
  35979. var blocksPerColumn = Math.ceil(Math.ceil(frame.scanLines / 8) *
  35980. component.v / frame.maxV);
  35981. var blocksPerLineForMcu = mcusPerLine * component.h;
  35982. var blocksPerColumnForMcu = mcusPerColumn * component.v;
  35983. var blocksBufferSize = 64 * blocksPerColumnForMcu *
  35984. (blocksPerLineForMcu + 1);
  35985. component.blockData = new Int16Array(blocksBufferSize);
  35986. component.blocksPerLine = blocksPerLine;
  35987. component.blocksPerColumn = blocksPerColumn;
  35988. }
  35989. frame.mcusPerLine = mcusPerLine;
  35990. frame.mcusPerColumn = mcusPerColumn;
  35991. }
  35992. var offset = 0, length = data.length;
  35993. var jfif = null;
  35994. var adobe = null;
  35995. var pixels = null;
  35996. var frame, resetInterval;
  35997. var quantizationTables = [];
  35998. var huffmanTablesAC = [], huffmanTablesDC = [];
  35999. var fileMarker = readUint16();
  36000. if (fileMarker !== 0xFFD8) { // SOI (Start of Image)
  36001. throw 'SOI not found';
  36002. }
  36003. fileMarker = readUint16();
  36004. while (fileMarker !== 0xFFD9) { // EOI (End of image)
  36005. var i, j, l;
  36006. switch(fileMarker) {
  36007. case 0xFFE0: // APP0 (Application Specific)
  36008. case 0xFFE1: // APP1
  36009. case 0xFFE2: // APP2
  36010. case 0xFFE3: // APP3
  36011. case 0xFFE4: // APP4
  36012. case 0xFFE5: // APP5
  36013. case 0xFFE6: // APP6
  36014. case 0xFFE7: // APP7
  36015. case 0xFFE8: // APP8
  36016. case 0xFFE9: // APP9
  36017. case 0xFFEA: // APP10
  36018. case 0xFFEB: // APP11
  36019. case 0xFFEC: // APP12
  36020. case 0xFFED: // APP13
  36021. case 0xFFEE: // APP14
  36022. case 0xFFEF: // APP15
  36023. case 0xFFFE: // COM (Comment)
  36024. var appData = readDataBlock();
  36025. if (fileMarker === 0xFFE0) {
  36026. if (appData[0] === 0x4A && appData[1] === 0x46 &&
  36027. appData[2] === 0x49 && appData[3] === 0x46 &&
  36028. appData[4] === 0) { // 'JFIF\x00'
  36029. jfif = {
  36030. version: { major: appData[5], minor: appData[6] },
  36031. densityUnits: appData[7],
  36032. xDensity: (appData[8] << 8) | appData[9],
  36033. yDensity: (appData[10] << 8) | appData[11],
  36034. thumbWidth: appData[12],
  36035. thumbHeight: appData[13],
  36036. thumbData: appData.subarray(14, 14 +
  36037. 3 * appData[12] * appData[13])
  36038. };
  36039. }
  36040. }
  36041. // TODO APP1 - Exif
  36042. if (fileMarker === 0xFFEE) {
  36043. if (appData[0] === 0x41 && appData[1] === 0x64 &&
  36044. appData[2] === 0x6F && appData[3] === 0x62 &&
  36045. appData[4] === 0x65 && appData[5] === 0) { // 'Adobe\x00'
  36046. adobe = {
  36047. version: appData[6],
  36048. flags0: (appData[7] << 8) | appData[8],
  36049. flags1: (appData[9] << 8) | appData[10],
  36050. transformCode: appData[11]
  36051. };
  36052. }
  36053. }
  36054. break;
  36055. case 0xFFDB: // DQT (Define Quantization Tables)
  36056. var quantizationTablesLength = readUint16();
  36057. var quantizationTablesEnd = quantizationTablesLength + offset - 2;
  36058. var z;
  36059. while (offset < quantizationTablesEnd) {
  36060. var quantizationTableSpec = data[offset++];
  36061. var tableData = new Uint16Array(64);
  36062. if ((quantizationTableSpec >> 4) === 0) { // 8 bit values
  36063. for (j = 0; j < 64; j++) {
  36064. z = dctZigZag[j];
  36065. tableData[z] = data[offset++];
  36066. }
  36067. } else if ((quantizationTableSpec >> 4) === 1) { //16 bit
  36068. for (j = 0; j < 64; j++) {
  36069. z = dctZigZag[j];
  36070. tableData[z] = readUint16();
  36071. }
  36072. } else {
  36073. throw 'DQT: invalid table spec';
  36074. }
  36075. quantizationTables[quantizationTableSpec & 15] = tableData;
  36076. }
  36077. break;
  36078. case 0xFFC0: // SOF0 (Start of Frame, Baseline DCT)
  36079. case 0xFFC1: // SOF1 (Start of Frame, Extended DCT)
  36080. case 0xFFC2: // SOF2 (Start of Frame, Progressive DCT)
  36081. if (frame) {
  36082. throw 'Only single frame JPEGs supported';
  36083. }
  36084. readUint16(); // skip data length
  36085. frame = {};
  36086. frame.extended = (fileMarker === 0xFFC1);
  36087. frame.progressive = (fileMarker === 0xFFC2);
  36088. frame.precision = data[offset++];
  36089. frame.scanLines = readUint16();
  36090. frame.samplesPerLine = readUint16();
  36091. frame.components = [];
  36092. frame.componentIds = {};
  36093. var componentsCount = data[offset++], componentId;
  36094. var maxH = 0, maxV = 0;
  36095. for (i = 0; i < componentsCount; i++) {
  36096. componentId = data[offset];
  36097. var h = data[offset + 1] >> 4;
  36098. var v = data[offset + 1] & 15;
  36099. if (maxH < h) {
  36100. maxH = h;
  36101. }
  36102. if (maxV < v) {
  36103. maxV = v;
  36104. }
  36105. var qId = data[offset + 2];
  36106. l = frame.components.push({
  36107. h: h,
  36108. v: v,
  36109. quantizationTable: quantizationTables[qId]
  36110. });
  36111. frame.componentIds[componentId] = l - 1;
  36112. offset += 3;
  36113. }
  36114. frame.maxH = maxH;
  36115. frame.maxV = maxV;
  36116. prepareComponents(frame);
  36117. break;
  36118. case 0xFFC4: // DHT (Define Huffman Tables)
  36119. var huffmanLength = readUint16();
  36120. for (i = 2; i < huffmanLength;) {
  36121. var huffmanTableSpec = data[offset++];
  36122. var codeLengths = new Uint8Array(16);
  36123. var codeLengthSum = 0;
  36124. for (j = 0; j < 16; j++, offset++) {
  36125. codeLengthSum += (codeLengths[j] = data[offset]);
  36126. }
  36127. var huffmanValues = new Uint8Array(codeLengthSum);
  36128. for (j = 0; j < codeLengthSum; j++, offset++) {
  36129. huffmanValues[j] = data[offset];
  36130. }
  36131. i += 17 + codeLengthSum;
  36132. ((huffmanTableSpec >> 4) === 0 ?
  36133. huffmanTablesDC : huffmanTablesAC)[huffmanTableSpec & 15] =
  36134. buildHuffmanTable(codeLengths, huffmanValues);
  36135. }
  36136. break;
  36137. case 0xFFDD: // DRI (Define Restart Interval)
  36138. readUint16(); // skip data length
  36139. resetInterval = readUint16();
  36140. break;
  36141. case 0xFFDA: // SOS (Start of Scan)
  36142. var scanLength = readUint16();
  36143. var selectorsCount = data[offset++];
  36144. var components = [], component;
  36145. for (i = 0; i < selectorsCount; i++) {
  36146. var componentIndex = frame.componentIds[data[offset++]];
  36147. component = frame.components[componentIndex];
  36148. var tableSpec = data[offset++];
  36149. component.huffmanTableDC = huffmanTablesDC[tableSpec >> 4];
  36150. component.huffmanTableAC = huffmanTablesAC[tableSpec & 15];
  36151. components.push(component);
  36152. }
  36153. var spectralStart = data[offset++];
  36154. var spectralEnd = data[offset++];
  36155. var successiveApproximation = data[offset++];
  36156. var processed = decodeScan(data, offset,
  36157. frame, components, resetInterval,
  36158. spectralStart, spectralEnd,
  36159. successiveApproximation >> 4, successiveApproximation & 15);
  36160. offset += processed;
  36161. break;
  36162. default:
  36163. if (data[offset - 3] === 0xFF &&
  36164. data[offset - 2] >= 0xC0 && data[offset - 2] <= 0xFE) {
  36165. // could be incorrect encoding -- last 0xFF byte of the previous
  36166. // block was eaten by the encoder
  36167. offset -= 3;
  36168. break;
  36169. }
  36170. throw 'unknown JPEG marker ' + fileMarker.toString(16);
  36171. }
  36172. fileMarker = readUint16();
  36173. }
  36174. this.width = frame.samplesPerLine;
  36175. this.height = frame.scanLines;
  36176. this.jfif = jfif;
  36177. this.adobe = adobe;
  36178. this.components = [];
  36179. for (i = 0; i < frame.components.length; i++) {
  36180. component = frame.components[i];
  36181. this.components.push({
  36182. output: buildComponentData(frame, component),
  36183. scaleX: component.h / frame.maxH,
  36184. scaleY: component.v / frame.maxV,
  36185. blocksPerLine: component.blocksPerLine,
  36186. blocksPerColumn: component.blocksPerColumn
  36187. });
  36188. }
  36189. this.numComponents = this.components.length;
  36190. },
  36191. _getLinearizedBlockData: function getLinearizedBlockData(width, height) {
  36192. var scaleX = this.width / width, scaleY = this.height / height;
  36193. var component, componentScaleX, componentScaleY, blocksPerScanline;
  36194. var x, y, i, j, k;
  36195. var index;
  36196. var offset = 0;
  36197. var output;
  36198. var numComponents = this.components.length;
  36199. var dataLength = width * height * numComponents;
  36200. var data = new Uint8Array(dataLength);
  36201. var xScaleBlockOffset = new Uint32Array(width);
  36202. var mask3LSB = 0xfffffff8; // used to clear the 3 LSBs
  36203. for (i = 0; i < numComponents; i++) {
  36204. component = this.components[i];
  36205. componentScaleX = component.scaleX * scaleX;
  36206. componentScaleY = component.scaleY * scaleY;
  36207. offset = i;
  36208. output = component.output;
  36209. blocksPerScanline = (component.blocksPerLine + 1) << 3;
  36210. // precalculate the xScaleBlockOffset
  36211. for (x = 0; x < width; x++) {
  36212. j = 0 | (x * componentScaleX);
  36213. xScaleBlockOffset[x] = ((j & mask3LSB) << 3) | (j & 7);
  36214. }
  36215. // linearize the blocks of the component
  36216. for (y = 0; y < height; y++) {
  36217. j = 0 | (y * componentScaleY);
  36218. index = blocksPerScanline * (j & mask3LSB) | ((j & 7) << 3);
  36219. for (x = 0; x < width; x++) {
  36220. data[offset] = output[index + xScaleBlockOffset[x]];
  36221. offset += numComponents;
  36222. }
  36223. }
  36224. }
  36225. // decodeTransform will contains pairs of multiplier (-256..256) and
  36226. // additive
  36227. var transform = this.decodeTransform;
  36228. if (transform) {
  36229. for (i = 0; i < dataLength;) {
  36230. for (j = 0, k = 0; j < numComponents; j++, i++, k += 2) {
  36231. data[i] = ((data[i] * transform[k]) >> 8) + transform[k + 1];
  36232. }
  36233. }
  36234. }
  36235. return data;
  36236. },
  36237. _isColorConversionNeeded: function isColorConversionNeeded() {
  36238. if (this.adobe && this.adobe.transformCode) {
  36239. // The adobe transform marker overrides any previous setting
  36240. return true;
  36241. } else if (this.numComponents === 3) {
  36242. return true;
  36243. } else {
  36244. return false;
  36245. }
  36246. },
  36247. _convertYccToRgb: function convertYccToRgb(data) {
  36248. var Y, Cb, Cr;
  36249. for (var i = 0, length = data.length; i < length; i += 3) {
  36250. Y = data[i ];
  36251. Cb = data[i + 1];
  36252. Cr = data[i + 2];
  36253. data[i ] = clamp0to255(Y - 179.456 + 1.402 * Cr);
  36254. data[i + 1] = clamp0to255(Y + 135.459 - 0.344 * Cb - 0.714 * Cr);
  36255. data[i + 2] = clamp0to255(Y - 226.816 + 1.772 * Cb);
  36256. }
  36257. return data;
  36258. },
  36259. _convertYcckToRgb: function convertYcckToRgb(data) {
  36260. var Y, Cb, Cr, k, CbCb, CbCr, CbY, Cbk, CrCr, Crk, CrY, YY, Yk, kk;
  36261. var offset = 0;
  36262. for (var i = 0, length = data.length; i < length; i += 4) {
  36263. Y = data[i];
  36264. Cb = data[i + 1];
  36265. Cr = data[i + 2];
  36266. k = data[i + 3];
  36267. CbCb = Cb * Cb;
  36268. CbCr = Cb * Cr;
  36269. CbY = Cb * Y;
  36270. Cbk = Cb * k;
  36271. CrCr = Cr * Cr;
  36272. Crk = Cr * k;
  36273. CrY = Cr * Y;
  36274. YY = Y * Y;
  36275. Yk = Y * k;
  36276. kk = k * k;
  36277. var r = - 122.67195406894 -
  36278. 6.60635669420364e-5 * CbCb + 0.000437130475926232 * CbCr -
  36279. 5.4080610064599e-5* CbY + 0.00048449797120281* Cbk -
  36280. 0.154362151871126 * Cb - 0.000957964378445773 * CrCr +
  36281. 0.000817076911346625 * CrY - 0.00477271405408747 * Crk +
  36282. 1.53380253221734 * Cr + 0.000961250184130688 * YY -
  36283. 0.00266257332283933 * Yk + 0.48357088451265 * Y -
  36284. 0.000336197177618394 * kk + 0.484791561490776 * k;
  36285. var g = 107.268039397724 +
  36286. 2.19927104525741e-5 * CbCb - 0.000640992018297945 * CbCr +
  36287. 0.000659397001245577* CbY + 0.000426105652938837* Cbk -
  36288. 0.176491792462875 * Cb - 0.000778269941513683 * CrCr +
  36289. 0.00130872261408275 * CrY + 0.000770482631801132 * Crk -
  36290. 0.151051492775562 * Cr + 0.00126935368114843 * YY -
  36291. 0.00265090189010898 * Yk + 0.25802910206845 * Y -
  36292. 0.000318913117588328 * kk - 0.213742400323665 * k;
  36293. var b = - 20.810012546947 -
  36294. 0.000570115196973677 * CbCb - 2.63409051004589e-5 * CbCr +
  36295. 0.0020741088115012* CbY - 0.00288260236853442* Cbk +
  36296. 0.814272968359295 * Cb - 1.53496057440975e-5 * CrCr -
  36297. 0.000132689043961446 * CrY + 0.000560833691242812 * Crk -
  36298. 0.195152027534049 * Cr + 0.00174418132927582 * YY -
  36299. 0.00255243321439347 * Yk + 0.116935020465145 * Y -
  36300. 0.000343531996510555 * kk + 0.24165260232407 * k;
  36301. data[offset++] = clamp0to255(r);
  36302. data[offset++] = clamp0to255(g);
  36303. data[offset++] = clamp0to255(b);
  36304. }
  36305. return data;
  36306. },
  36307. _convertYcckToCmyk: function convertYcckToCmyk(data) {
  36308. var Y, Cb, Cr;
  36309. for (var i = 0, length = data.length; i < length; i += 4) {
  36310. Y = data[i];
  36311. Cb = data[i + 1];
  36312. Cr = data[i + 2];
  36313. data[i ] = clamp0to255(434.456 - Y - 1.402 * Cr);
  36314. data[i + 1] = clamp0to255(119.541 - Y + 0.344 * Cb + 0.714 * Cr);
  36315. data[i + 2] = clamp0to255(481.816 - Y - 1.772 * Cb);
  36316. // K in data[i + 3] is unchanged
  36317. }
  36318. return data;
  36319. },
  36320. _convertCmykToRgb: function convertCmykToRgb(data) {
  36321. var c, m, y, k;
  36322. var offset = 0;
  36323. var min = -255 * 255 * 255;
  36324. var scale = 1 / 255 / 255;
  36325. for (var i = 0, length = data.length; i < length; i += 4) {
  36326. c = data[i];
  36327. m = data[i + 1];
  36328. y = data[i + 2];
  36329. k = data[i + 3];
  36330. var r =
  36331. c * (-4.387332384609988 * c + 54.48615194189176 * m +
  36332. 18.82290502165302 * y + 212.25662451639585 * k -
  36333. 72734.4411664936) +
  36334. m * (1.7149763477362134 * m - 5.6096736904047315 * y -
  36335. 17.873870861415444 * k - 1401.7366389350734) +
  36336. y * (-2.5217340131683033 * y - 21.248923337353073 * k +
  36337. 4465.541406466231) -
  36338. k * (21.86122147463605 * k + 48317.86113160301);
  36339. var g =
  36340. c * (8.841041422036149 * c + 60.118027045597366 * m +
  36341. 6.871425592049007 * y + 31.159100130055922 * k -
  36342. 20220.756542821975) +
  36343. m * (-15.310361306967817 * m + 17.575251261109482 * y +
  36344. 131.35250912493976 * k - 48691.05921601825) +
  36345. y * (4.444339102852739 * y + 9.8632861493405 * k -
  36346. 6341.191035517494) -
  36347. k * (20.737325471181034 * k + 47890.15695978492);
  36348. var b =
  36349. c * (0.8842522430003296 * c + 8.078677503112928 * m +
  36350. 30.89978309703729 * y - 0.23883238689178934 * k -
  36351. 3616.812083916688) +
  36352. m * (10.49593273432072 * m + 63.02378494754052 * y +
  36353. 50.606957656360734 * k - 28620.90484698408) +
  36354. y * (0.03296041114873217 * y + 115.60384449646641 * k -
  36355. 49363.43385999684) -
  36356. k * (22.33816807309886 * k + 45932.16563550634);
  36357. data[offset++] = r >= 0 ? 255 : r <= min ? 0 : 255 + r * scale | 0;
  36358. data[offset++] = g >= 0 ? 255 : g <= min ? 0 : 255 + g * scale | 0;
  36359. data[offset++] = b >= 0 ? 255 : b <= min ? 0 : 255 + b * scale | 0;
  36360. }
  36361. return data;
  36362. },
  36363. getData: function getData(width, height, forceRGBoutput) {
  36364. if (this.numComponents > 4) {
  36365. throw 'Unsupported color mode';
  36366. }
  36367. // type of data: Uint8Array(width * height * numComponents)
  36368. var data = this._getLinearizedBlockData(width, height);
  36369. if (this.numComponents === 3) {
  36370. return this._convertYccToRgb(data);
  36371. } else if (this.numComponents === 4) {
  36372. if (this._isColorConversionNeeded()) {
  36373. if (forceRGBoutput) {
  36374. return this._convertYcckToRgb(data);
  36375. } else {
  36376. return this._convertYcckToCmyk(data);
  36377. }
  36378. } else if (forceRGBoutput) {
  36379. return this._convertCmykToRgb(data);
  36380. }
  36381. }
  36382. return data;
  36383. }
  36384. };
  36385. return constructor;
  36386. })();
  36387. var JpxImage = (function JpxImageClosure() {
  36388. // Table E.1
  36389. var SubbandsGainLog2 = {
  36390. 'LL': 0,
  36391. 'LH': 1,
  36392. 'HL': 1,
  36393. 'HH': 2
  36394. };
  36395. function JpxImage() {
  36396. this.failOnCorruptedImage = false;
  36397. }
  36398. JpxImage.prototype = {
  36399. parse: function JpxImage_parse(data) {
  36400. var head = readUint16(data, 0);
  36401. // No box header, immediate start of codestream (SOC)
  36402. if (head === 0xFF4F) {
  36403. this.parseCodestream(data, 0, data.length);
  36404. return;
  36405. }
  36406. var position = 0, length = data.length;
  36407. while (position < length) {
  36408. var headerSize = 8;
  36409. var lbox = readUint32(data, position);
  36410. var tbox = readUint32(data, position + 4);
  36411. position += headerSize;
  36412. if (lbox === 1) {
  36413. // XLBox: read UInt64 according to spec.
  36414. // JavaScript's int precision of 53 bit should be sufficient here.
  36415. lbox = readUint32(data, position) * 4294967296 +
  36416. readUint32(data, position + 4);
  36417. position += 8;
  36418. headerSize += 8;
  36419. }
  36420. if (lbox === 0) {
  36421. lbox = length - position + headerSize;
  36422. }
  36423. if (lbox < headerSize) {
  36424. throw new Error('JPX Error: Invalid box field size');
  36425. }
  36426. var dataLength = lbox - headerSize;
  36427. var jumpDataLength = true;
  36428. switch (tbox) {
  36429. case 0x6A501A1A: // 'jP\032\032'
  36430. // TODO
  36431. break;
  36432. case 0x6A703268: // 'jp2h'
  36433. jumpDataLength = false; // parsing child boxes
  36434. break;
  36435. case 0x636F6C72: // 'colr'
  36436. // TODO
  36437. break;
  36438. case 0x6A703263: // 'jp2c'
  36439. this.parseCodestream(data, position, position + dataLength);
  36440. break;
  36441. }
  36442. if (jumpDataLength) {
  36443. position += dataLength;
  36444. }
  36445. }
  36446. },
  36447. parseImageProperties: function JpxImage_parseImageProperties(stream) {
  36448. var newByte = stream.getByte();
  36449. while (newByte >= 0) {
  36450. var oldByte = newByte;
  36451. newByte = stream.getByte();
  36452. var code = (oldByte << 8) | newByte;
  36453. // Image and tile size (SIZ)
  36454. if (code === 0xFF51) {
  36455. stream.skip(4);
  36456. var Xsiz = stream.getInt32() >>> 0; // Byte 4
  36457. var Ysiz = stream.getInt32() >>> 0; // Byte 8
  36458. var XOsiz = stream.getInt32() >>> 0; // Byte 12
  36459. var YOsiz = stream.getInt32() >>> 0; // Byte 16
  36460. stream.skip(16);
  36461. var Csiz = stream.getUint16(); // Byte 36
  36462. this.width = Xsiz - XOsiz;
  36463. this.height = Ysiz - YOsiz;
  36464. this.componentsCount = Csiz;
  36465. // Results are always returned as Uint8Arrays
  36466. this.bitsPerComponent = 8;
  36467. return;
  36468. }
  36469. }
  36470. throw new Error('JPX Error: No size marker found in JPX stream');
  36471. },
  36472. parseCodestream: function JpxImage_parseCodestream(data, start, end) {
  36473. var context = {};
  36474. try {
  36475. var doNotRecover = false;
  36476. var position = start;
  36477. while (position + 1 < end) {
  36478. var code = readUint16(data, position);
  36479. position += 2;
  36480. var length = 0, j, sqcd, spqcds, spqcdSize, scalarExpounded, tile;
  36481. switch (code) {
  36482. case 0xFF4F: // Start of codestream (SOC)
  36483. context.mainHeader = true;
  36484. break;
  36485. case 0xFFD9: // End of codestream (EOC)
  36486. break;
  36487. case 0xFF51: // Image and tile size (SIZ)
  36488. length = readUint16(data, position);
  36489. var siz = {};
  36490. siz.Xsiz = readUint32(data, position + 4);
  36491. siz.Ysiz = readUint32(data, position + 8);
  36492. siz.XOsiz = readUint32(data, position + 12);
  36493. siz.YOsiz = readUint32(data, position + 16);
  36494. siz.XTsiz = readUint32(data, position + 20);
  36495. siz.YTsiz = readUint32(data, position + 24);
  36496. siz.XTOsiz = readUint32(data, position + 28);
  36497. siz.YTOsiz = readUint32(data, position + 32);
  36498. var componentsCount = readUint16(data, position + 36);
  36499. siz.Csiz = componentsCount;
  36500. var components = [];
  36501. j = position + 38;
  36502. for (var i = 0; i < componentsCount; i++) {
  36503. var component = {
  36504. precision: (data[j] & 0x7F) + 1,
  36505. isSigned: !!(data[j] & 0x80),
  36506. XRsiz: data[j + 1],
  36507. YRsiz: data[j + 1]
  36508. };
  36509. calculateComponentDimensions(component, siz);
  36510. components.push(component);
  36511. }
  36512. context.SIZ = siz;
  36513. context.components = components;
  36514. calculateTileGrids(context, components);
  36515. context.QCC = [];
  36516. context.COC = [];
  36517. break;
  36518. case 0xFF55: // Tile-part lengths, main header (TLM)
  36519. var Ltlm = readUint16(data, position); // Marker segment length
  36520. // Skip tile length markers
  36521. position += Ltlm;
  36522. break;
  36523. case 0xFF5C: // Quantization default (QCD)
  36524. length = readUint16(data, position);
  36525. var qcd = {};
  36526. j = position + 2;
  36527. sqcd = data[j++];
  36528. switch (sqcd & 0x1F) {
  36529. case 0:
  36530. spqcdSize = 8;
  36531. scalarExpounded = true;
  36532. break;
  36533. case 1:
  36534. spqcdSize = 16;
  36535. scalarExpounded = false;
  36536. break;
  36537. case 2:
  36538. spqcdSize = 16;
  36539. scalarExpounded = true;
  36540. break;
  36541. default:
  36542. throw new Error('JPX Error: Invalid SQcd value ' + sqcd);
  36543. }
  36544. qcd.noQuantization = (spqcdSize === 8);
  36545. qcd.scalarExpounded = scalarExpounded;
  36546. qcd.guardBits = sqcd >> 5;
  36547. spqcds = [];
  36548. while (j < length + position) {
  36549. var spqcd = {};
  36550. if (spqcdSize === 8) {
  36551. spqcd.epsilon = data[j++] >> 3;
  36552. spqcd.mu = 0;
  36553. } else {
  36554. spqcd.epsilon = data[j] >> 3;
  36555. spqcd.mu = ((data[j] & 0x7) << 8) | data[j + 1];
  36556. j += 2;
  36557. }
  36558. spqcds.push(spqcd);
  36559. }
  36560. qcd.SPqcds = spqcds;
  36561. if (context.mainHeader) {
  36562. context.QCD = qcd;
  36563. } else {
  36564. context.currentTile.QCD = qcd;
  36565. context.currentTile.QCC = [];
  36566. }
  36567. break;
  36568. case 0xFF5D: // Quantization component (QCC)
  36569. length = readUint16(data, position);
  36570. var qcc = {};
  36571. j = position + 2;
  36572. var cqcc;
  36573. if (context.SIZ.Csiz < 257) {
  36574. cqcc = data[j++];
  36575. } else {
  36576. cqcc = readUint16(data, j);
  36577. j += 2;
  36578. }
  36579. sqcd = data[j++];
  36580. switch (sqcd & 0x1F) {
  36581. case 0:
  36582. spqcdSize = 8;
  36583. scalarExpounded = true;
  36584. break;
  36585. case 1:
  36586. spqcdSize = 16;
  36587. scalarExpounded = false;
  36588. break;
  36589. case 2:
  36590. spqcdSize = 16;
  36591. scalarExpounded = true;
  36592. break;
  36593. default:
  36594. throw new Error('JPX Error: Invalid SQcd value ' + sqcd);
  36595. }
  36596. qcc.noQuantization = (spqcdSize === 8);
  36597. qcc.scalarExpounded = scalarExpounded;
  36598. qcc.guardBits = sqcd >> 5;
  36599. spqcds = [];
  36600. while (j < (length + position)) {
  36601. spqcd = {};
  36602. if (spqcdSize === 8) {
  36603. spqcd.epsilon = data[j++] >> 3;
  36604. spqcd.mu = 0;
  36605. } else {
  36606. spqcd.epsilon = data[j] >> 3;
  36607. spqcd.mu = ((data[j] & 0x7) << 8) | data[j + 1];
  36608. j += 2;
  36609. }
  36610. spqcds.push(spqcd);
  36611. }
  36612. qcc.SPqcds = spqcds;
  36613. if (context.mainHeader) {
  36614. context.QCC[cqcc] = qcc;
  36615. } else {
  36616. context.currentTile.QCC[cqcc] = qcc;
  36617. }
  36618. break;
  36619. case 0xFF52: // Coding style default (COD)
  36620. length = readUint16(data, position);
  36621. var cod = {};
  36622. j = position + 2;
  36623. var scod = data[j++];
  36624. cod.entropyCoderWithCustomPrecincts = !!(scod & 1);
  36625. cod.sopMarkerUsed = !!(scod & 2);
  36626. cod.ephMarkerUsed = !!(scod & 4);
  36627. cod.progressionOrder = data[j++];
  36628. cod.layersCount = readUint16(data, j);
  36629. j += 2;
  36630. cod.multipleComponentTransform = data[j++];
  36631. cod.decompositionLevelsCount = data[j++];
  36632. cod.xcb = (data[j++] & 0xF) + 2;
  36633. cod.ycb = (data[j++] & 0xF) + 2;
  36634. var blockStyle = data[j++];
  36635. cod.selectiveArithmeticCodingBypass = !!(blockStyle & 1);
  36636. cod.resetContextProbabilities = !!(blockStyle & 2);
  36637. cod.terminationOnEachCodingPass = !!(blockStyle & 4);
  36638. cod.verticalyStripe = !!(blockStyle & 8);
  36639. cod.predictableTermination = !!(blockStyle & 16);
  36640. cod.segmentationSymbolUsed = !!(blockStyle & 32);
  36641. cod.reversibleTransformation = data[j++];
  36642. if (cod.entropyCoderWithCustomPrecincts) {
  36643. var precinctsSizes = [];
  36644. while (j < length + position) {
  36645. var precinctsSize = data[j++];
  36646. precinctsSizes.push({
  36647. PPx: precinctsSize & 0xF,
  36648. PPy: precinctsSize >> 4
  36649. });
  36650. }
  36651. cod.precinctsSizes = precinctsSizes;
  36652. }
  36653. var unsupported = [];
  36654. if (cod.sopMarkerUsed) {
  36655. unsupported.push('sopMarkerUsed');
  36656. }
  36657. if (cod.ephMarkerUsed) {
  36658. unsupported.push('ephMarkerUsed');
  36659. }
  36660. if (cod.selectiveArithmeticCodingBypass) {
  36661. unsupported.push('selectiveArithmeticCodingBypass');
  36662. }
  36663. if (cod.resetContextProbabilities) {
  36664. unsupported.push('resetContextProbabilities');
  36665. }
  36666. if (cod.terminationOnEachCodingPass) {
  36667. unsupported.push('terminationOnEachCodingPass');
  36668. }
  36669. if (cod.verticalyStripe) {
  36670. unsupported.push('verticalyStripe');
  36671. }
  36672. if (cod.predictableTermination) {
  36673. unsupported.push('predictableTermination');
  36674. }
  36675. if (unsupported.length > 0) {
  36676. doNotRecover = true;
  36677. throw new Error('JPX Error: Unsupported COD options (' +
  36678. unsupported.join(', ') + ')');
  36679. }
  36680. if (context.mainHeader) {
  36681. context.COD = cod;
  36682. } else {
  36683. context.currentTile.COD = cod;
  36684. context.currentTile.COC = [];
  36685. }
  36686. break;
  36687. case 0xFF90: // Start of tile-part (SOT)
  36688. length = readUint16(data, position);
  36689. tile = {};
  36690. tile.index = readUint16(data, position + 2);
  36691. tile.length = readUint32(data, position + 4);
  36692. tile.dataEnd = tile.length + position - 2;
  36693. tile.partIndex = data[position + 8];
  36694. tile.partsCount = data[position + 9];
  36695. context.mainHeader = false;
  36696. if (tile.partIndex === 0) {
  36697. // reset component specific settings
  36698. tile.COD = context.COD;
  36699. tile.COC = context.COC.slice(0); // clone of the global COC
  36700. tile.QCD = context.QCD;
  36701. tile.QCC = context.QCC.slice(0); // clone of the global COC
  36702. }
  36703. context.currentTile = tile;
  36704. break;
  36705. case 0xFF93: // Start of data (SOD)
  36706. tile = context.currentTile;
  36707. if (tile.partIndex === 0) {
  36708. initializeTile(context, tile.index);
  36709. buildPackets(context);
  36710. }
  36711. // moving to the end of the data
  36712. length = tile.dataEnd - position;
  36713. parseTilePackets(context, data, position, length);
  36714. break;
  36715. case 0xFF64: // Comment (COM)
  36716. length = readUint16(data, position);
  36717. // skipping content
  36718. break;
  36719. case 0xFF53: // Coding style component (COC)
  36720. throw new Error('JPX Error: Codestream code 0xFF53 (COC) is ' +
  36721. 'not implemented');
  36722. default:
  36723. throw new Error('JPX Error: Unknown codestream code: ' +
  36724. code.toString(16));
  36725. }
  36726. position += length;
  36727. }
  36728. } catch (e) {
  36729. if (doNotRecover || this.failOnCorruptedImage) {
  36730. throw e;
  36731. } else {
  36732. warn('Trying to recover from ' + e.message);
  36733. }
  36734. }
  36735. this.tiles = transformComponents(context);
  36736. this.width = context.SIZ.Xsiz - context.SIZ.XOsiz;
  36737. this.height = context.SIZ.Ysiz - context.SIZ.YOsiz;
  36738. this.componentsCount = context.SIZ.Csiz;
  36739. }
  36740. };
  36741. function calculateComponentDimensions(component, siz) {
  36742. // Section B.2 Component mapping
  36743. component.x0 = Math.ceil(siz.XOsiz / component.XRsiz);
  36744. component.x1 = Math.ceil(siz.Xsiz / component.XRsiz);
  36745. component.y0 = Math.ceil(siz.YOsiz / component.YRsiz);
  36746. component.y1 = Math.ceil(siz.Ysiz / component.YRsiz);
  36747. component.width = component.x1 - component.x0;
  36748. component.height = component.y1 - component.y0;
  36749. }
  36750. function calculateTileGrids(context, components) {
  36751. var siz = context.SIZ;
  36752. // Section B.3 Division into tile and tile-components
  36753. var tile, tiles = [];
  36754. var numXtiles = Math.ceil((siz.Xsiz - siz.XTOsiz) / siz.XTsiz);
  36755. var numYtiles = Math.ceil((siz.Ysiz - siz.YTOsiz) / siz.YTsiz);
  36756. for (var q = 0; q < numYtiles; q++) {
  36757. for (var p = 0; p < numXtiles; p++) {
  36758. tile = {};
  36759. tile.tx0 = Math.max(siz.XTOsiz + p * siz.XTsiz, siz.XOsiz);
  36760. tile.ty0 = Math.max(siz.YTOsiz + q * siz.YTsiz, siz.YOsiz);
  36761. tile.tx1 = Math.min(siz.XTOsiz + (p + 1) * siz.XTsiz, siz.Xsiz);
  36762. tile.ty1 = Math.min(siz.YTOsiz + (q + 1) * siz.YTsiz, siz.Ysiz);
  36763. tile.width = tile.tx1 - tile.tx0;
  36764. tile.height = tile.ty1 - tile.ty0;
  36765. tile.components = [];
  36766. tiles.push(tile);
  36767. }
  36768. }
  36769. context.tiles = tiles;
  36770. var componentsCount = siz.Csiz;
  36771. for (var i = 0, ii = componentsCount; i < ii; i++) {
  36772. var component = components[i];
  36773. for (var j = 0, jj = tiles.length; j < jj; j++) {
  36774. var tileComponent = {};
  36775. tile = tiles[j];
  36776. tileComponent.tcx0 = Math.ceil(tile.tx0 / component.XRsiz);
  36777. tileComponent.tcy0 = Math.ceil(tile.ty0 / component.YRsiz);
  36778. tileComponent.tcx1 = Math.ceil(tile.tx1 / component.XRsiz);
  36779. tileComponent.tcy1 = Math.ceil(tile.ty1 / component.YRsiz);
  36780. tileComponent.width = tileComponent.tcx1 - tileComponent.tcx0;
  36781. tileComponent.height = tileComponent.tcy1 - tileComponent.tcy0;
  36782. tile.components[i] = tileComponent;
  36783. }
  36784. }
  36785. }
  36786. function getBlocksDimensions(context, component, r) {
  36787. var codOrCoc = component.codingStyleParameters;
  36788. var result = {};
  36789. if (!codOrCoc.entropyCoderWithCustomPrecincts) {
  36790. result.PPx = 15;
  36791. result.PPy = 15;
  36792. } else {
  36793. result.PPx = codOrCoc.precinctsSizes[r].PPx;
  36794. result.PPy = codOrCoc.precinctsSizes[r].PPy;
  36795. }
  36796. // calculate codeblock size as described in section B.7
  36797. result.xcb_ = (r > 0 ? Math.min(codOrCoc.xcb, result.PPx - 1) :
  36798. Math.min(codOrCoc.xcb, result.PPx));
  36799. result.ycb_ = (r > 0 ? Math.min(codOrCoc.ycb, result.PPy - 1) :
  36800. Math.min(codOrCoc.ycb, result.PPy));
  36801. return result;
  36802. }
  36803. function buildPrecincts(context, resolution, dimensions) {
  36804. // Section B.6 Division resolution to precincts
  36805. var precinctWidth = 1 << dimensions.PPx;
  36806. var precinctHeight = 1 << dimensions.PPy;
  36807. var numprecinctswide = (resolution.trx1 > resolution.trx0 ?
  36808. Math.ceil(resolution.trx1 / precinctWidth) -
  36809. Math.floor(resolution.trx0 / precinctWidth) : 0);
  36810. var numprecinctshigh = (resolution.try1 > resolution.try0 ?
  36811. Math.ceil(resolution.try1 / precinctHeight) -
  36812. Math.floor(resolution.try0 / precinctHeight) : 0);
  36813. var numprecincts = numprecinctswide * numprecinctshigh;
  36814. var precinctXOffset = Math.floor(resolution.trx0 / precinctWidth) *
  36815. precinctWidth;
  36816. var precinctYOffset = Math.floor(resolution.try0 / precinctHeight) *
  36817. precinctHeight;
  36818. resolution.precinctParameters = {
  36819. precinctXOffset: precinctXOffset,
  36820. precinctYOffset: precinctYOffset,
  36821. precinctWidth: precinctWidth,
  36822. precinctHeight: precinctHeight,
  36823. numprecinctswide: numprecinctswide,
  36824. numprecinctshigh: numprecinctshigh,
  36825. numprecincts: numprecincts
  36826. };
  36827. }
  36828. function buildCodeblocks(context, subband, dimensions) {
  36829. // Section B.7 Division sub-band into code-blocks
  36830. var xcb_ = dimensions.xcb_;
  36831. var ycb_ = dimensions.ycb_;
  36832. var codeblockWidth = 1 << xcb_;
  36833. var codeblockHeight = 1 << ycb_;
  36834. var cbx0 = subband.tbx0 >> xcb_;
  36835. var cby0 = subband.tby0 >> ycb_;
  36836. var cbx1 = (subband.tbx1 + codeblockWidth - 1) >> xcb_;
  36837. var cby1 = (subband.tby1 + codeblockHeight - 1) >> ycb_;
  36838. var precinctParameters = subband.resolution.precinctParameters;
  36839. var codeblocks = [];
  36840. var precincts = [];
  36841. var i, j, codeblock, precinctNumber;
  36842. for (j = cby0; j < cby1; j++) {
  36843. for (i = cbx0; i < cbx1; i++) {
  36844. codeblock = {
  36845. cbx: i,
  36846. cby: j,
  36847. tbx0: codeblockWidth * i,
  36848. tby0: codeblockHeight * j,
  36849. tbx1: codeblockWidth * (i + 1),
  36850. tby1: codeblockHeight * (j + 1)
  36851. };
  36852. // calculate precinct number
  36853. var pi = Math.floor((codeblock.tbx0 -
  36854. precinctParameters.precinctXOffset) /
  36855. precinctParameters.precinctWidth);
  36856. var pj = Math.floor((codeblock.tby0 -
  36857. precinctParameters.precinctYOffset) /
  36858. precinctParameters.precinctHeight);
  36859. precinctNumber = pj + pi * precinctParameters.numprecinctswide;
  36860. codeblock.tbx0_ = Math.max(subband.tbx0, codeblock.tbx0);
  36861. codeblock.tby0_ = Math.max(subband.tby0, codeblock.tby0);
  36862. codeblock.tbx1_ = Math.min(subband.tbx1, codeblock.tbx1);
  36863. codeblock.tby1_ = Math.min(subband.tby1, codeblock.tby1);
  36864. codeblock.precinctNumber = precinctNumber;
  36865. codeblock.subbandType = subband.type;
  36866. codeblock.Lblock = 3;
  36867. codeblocks.push(codeblock);
  36868. // building precinct for the sub-band
  36869. var precinct = precincts[precinctNumber];
  36870. if (precinct !== undefined) {
  36871. if (i < precinct.cbxMin) {
  36872. precinct.cbxMin = i;
  36873. } else if (i > precinct.cbxMax) {
  36874. precinct.cbxMax = i;
  36875. }
  36876. if (j < precinct.cbyMin) {
  36877. precinct.cbxMin = j;
  36878. } else if (j > precinct.cbyMax) {
  36879. precinct.cbyMax = j;
  36880. }
  36881. } else {
  36882. precincts[precinctNumber] = precinct = {
  36883. cbxMin: i,
  36884. cbyMin: j,
  36885. cbxMax: i,
  36886. cbyMax: j
  36887. };
  36888. }
  36889. codeblock.precinct = precinct;
  36890. }
  36891. }
  36892. subband.codeblockParameters = {
  36893. codeblockWidth: xcb_,
  36894. codeblockHeight: ycb_,
  36895. numcodeblockwide: cbx1 - cbx0 + 1,
  36896. numcodeblockhigh: cby1 - cby1 + 1
  36897. };
  36898. subband.codeblocks = codeblocks;
  36899. subband.precincts = precincts;
  36900. }
  36901. function createPacket(resolution, precinctNumber, layerNumber) {
  36902. var precinctCodeblocks = [];
  36903. // Section B.10.8 Order of info in packet
  36904. var subbands = resolution.subbands;
  36905. // sub-bands already ordered in 'LL', 'HL', 'LH', and 'HH' sequence
  36906. for (var i = 0, ii = subbands.length; i < ii; i++) {
  36907. var subband = subbands[i];
  36908. var codeblocks = subband.codeblocks;
  36909. for (var j = 0, jj = codeblocks.length; j < jj; j++) {
  36910. var codeblock = codeblocks[j];
  36911. if (codeblock.precinctNumber !== precinctNumber) {
  36912. continue;
  36913. }
  36914. precinctCodeblocks.push(codeblock);
  36915. }
  36916. }
  36917. return {
  36918. layerNumber: layerNumber,
  36919. codeblocks: precinctCodeblocks
  36920. };
  36921. }
  36922. function LayerResolutionComponentPositionIterator(context) {
  36923. var siz = context.SIZ;
  36924. var tileIndex = context.currentTile.index;
  36925. var tile = context.tiles[tileIndex];
  36926. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  36927. var componentsCount = siz.Csiz;
  36928. var maxDecompositionLevelsCount = 0;
  36929. for (var q = 0; q < componentsCount; q++) {
  36930. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  36931. tile.components[q].codingStyleParameters.decompositionLevelsCount);
  36932. }
  36933. var l = 0, r = 0, i = 0, k = 0;
  36934. this.nextPacket = function JpxImage_nextPacket() {
  36935. // Section B.12.1.1 Layer-resolution-component-position
  36936. for (; l < layersCount; l++) {
  36937. for (; r <= maxDecompositionLevelsCount; r++) {
  36938. for (; i < componentsCount; i++) {
  36939. var component = tile.components[i];
  36940. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  36941. continue;
  36942. }
  36943. var resolution = component.resolutions[r];
  36944. var numprecincts = resolution.precinctParameters.numprecincts;
  36945. for (; k < numprecincts;) {
  36946. var packet = createPacket(resolution, k, l);
  36947. k++;
  36948. return packet;
  36949. }
  36950. k = 0;
  36951. }
  36952. i = 0;
  36953. }
  36954. r = 0;
  36955. }
  36956. throw new Error('JPX Error: Out of packets');
  36957. };
  36958. }
  36959. function ResolutionLayerComponentPositionIterator(context) {
  36960. var siz = context.SIZ;
  36961. var tileIndex = context.currentTile.index;
  36962. var tile = context.tiles[tileIndex];
  36963. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  36964. var componentsCount = siz.Csiz;
  36965. var maxDecompositionLevelsCount = 0;
  36966. for (var q = 0; q < componentsCount; q++) {
  36967. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  36968. tile.components[q].codingStyleParameters.decompositionLevelsCount);
  36969. }
  36970. var r = 0, l = 0, i = 0, k = 0;
  36971. this.nextPacket = function JpxImage_nextPacket() {
  36972. // Section B.12.1.2 Resolution-layer-component-position
  36973. for (; r <= maxDecompositionLevelsCount; r++) {
  36974. for (; l < layersCount; l++) {
  36975. for (; i < componentsCount; i++) {
  36976. var component = tile.components[i];
  36977. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  36978. continue;
  36979. }
  36980. var resolution = component.resolutions[r];
  36981. var numprecincts = resolution.precinctParameters.numprecincts;
  36982. for (; k < numprecincts;) {
  36983. var packet = createPacket(resolution, k, l);
  36984. k++;
  36985. return packet;
  36986. }
  36987. k = 0;
  36988. }
  36989. i = 0;
  36990. }
  36991. l = 0;
  36992. }
  36993. throw new Error('JPX Error: Out of packets');
  36994. };
  36995. }
  36996. function buildPackets(context) {
  36997. var siz = context.SIZ;
  36998. var tileIndex = context.currentTile.index;
  36999. var tile = context.tiles[tileIndex];
  37000. var componentsCount = siz.Csiz;
  37001. // Creating resolutions and sub-bands for each component
  37002. for (var c = 0; c < componentsCount; c++) {
  37003. var component = tile.components[c];
  37004. var decompositionLevelsCount =
  37005. component.codingStyleParameters.decompositionLevelsCount;
  37006. // Section B.5 Resolution levels and sub-bands
  37007. var resolutions = [];
  37008. var subbands = [];
  37009. for (var r = 0; r <= decompositionLevelsCount; r++) {
  37010. var blocksDimensions = getBlocksDimensions(context, component, r);
  37011. var resolution = {};
  37012. var scale = 1 << (decompositionLevelsCount - r);
  37013. resolution.trx0 = Math.ceil(component.tcx0 / scale);
  37014. resolution.try0 = Math.ceil(component.tcy0 / scale);
  37015. resolution.trx1 = Math.ceil(component.tcx1 / scale);
  37016. resolution.try1 = Math.ceil(component.tcy1 / scale);
  37017. buildPrecincts(context, resolution, blocksDimensions);
  37018. resolutions.push(resolution);
  37019. var subband;
  37020. if (r === 0) {
  37021. // one sub-band (LL) with last decomposition
  37022. subband = {};
  37023. subband.type = 'LL';
  37024. subband.tbx0 = Math.ceil(component.tcx0 / scale);
  37025. subband.tby0 = Math.ceil(component.tcy0 / scale);
  37026. subband.tbx1 = Math.ceil(component.tcx1 / scale);
  37027. subband.tby1 = Math.ceil(component.tcy1 / scale);
  37028. subband.resolution = resolution;
  37029. buildCodeblocks(context, subband, blocksDimensions);
  37030. subbands.push(subband);
  37031. resolution.subbands = [subband];
  37032. } else {
  37033. var bscale = 1 << (decompositionLevelsCount - r + 1);
  37034. var resolutionSubbands = [];
  37035. // three sub-bands (HL, LH and HH) with rest of decompositions
  37036. subband = {};
  37037. subband.type = 'HL';
  37038. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  37039. subband.tby0 = Math.ceil(component.tcy0 / bscale);
  37040. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  37041. subband.tby1 = Math.ceil(component.tcy1 / bscale);
  37042. subband.resolution = resolution;
  37043. buildCodeblocks(context, subband, blocksDimensions);
  37044. subbands.push(subband);
  37045. resolutionSubbands.push(subband);
  37046. subband = {};
  37047. subband.type = 'LH';
  37048. subband.tbx0 = Math.ceil(component.tcx0 / bscale);
  37049. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  37050. subband.tbx1 = Math.ceil(component.tcx1 / bscale);
  37051. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  37052. subband.resolution = resolution;
  37053. buildCodeblocks(context, subband, blocksDimensions);
  37054. subbands.push(subband);
  37055. resolutionSubbands.push(subband);
  37056. subband = {};
  37057. subband.type = 'HH';
  37058. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  37059. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  37060. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  37061. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  37062. subband.resolution = resolution;
  37063. buildCodeblocks(context, subband, blocksDimensions);
  37064. subbands.push(subband);
  37065. resolutionSubbands.push(subband);
  37066. resolution.subbands = resolutionSubbands;
  37067. }
  37068. }
  37069. component.resolutions = resolutions;
  37070. component.subbands = subbands;
  37071. }
  37072. // Generate the packets sequence
  37073. var progressionOrder = tile.codingStyleDefaultParameters.progressionOrder;
  37074. switch (progressionOrder) {
  37075. case 0:
  37076. tile.packetsIterator =
  37077. new LayerResolutionComponentPositionIterator(context);
  37078. break;
  37079. case 1:
  37080. tile.packetsIterator =
  37081. new ResolutionLayerComponentPositionIterator(context);
  37082. break;
  37083. default:
  37084. throw new Error('JPX Error: Unsupported progression order ' +
  37085. progressionOrder);
  37086. }
  37087. }
  37088. function parseTilePackets(context, data, offset, dataLength) {
  37089. var position = 0;
  37090. var buffer, bufferSize = 0, skipNextBit = false;
  37091. function readBits(count) {
  37092. while (bufferSize < count) {
  37093. var b = data[offset + position];
  37094. position++;
  37095. if (skipNextBit) {
  37096. buffer = (buffer << 7) | b;
  37097. bufferSize += 7;
  37098. skipNextBit = false;
  37099. } else {
  37100. buffer = (buffer << 8) | b;
  37101. bufferSize += 8;
  37102. }
  37103. if (b === 0xFF) {
  37104. skipNextBit = true;
  37105. }
  37106. }
  37107. bufferSize -= count;
  37108. return (buffer >>> bufferSize) & ((1 << count) - 1);
  37109. }
  37110. function alignToByte() {
  37111. bufferSize = 0;
  37112. if (skipNextBit) {
  37113. position++;
  37114. skipNextBit = false;
  37115. }
  37116. }
  37117. function readCodingpasses() {
  37118. if (readBits(1) === 0) {
  37119. return 1;
  37120. }
  37121. if (readBits(1) === 0) {
  37122. return 2;
  37123. }
  37124. var value = readBits(2);
  37125. if (value < 3) {
  37126. return value + 3;
  37127. }
  37128. value = readBits(5);
  37129. if (value < 31) {
  37130. return value + 6;
  37131. }
  37132. value = readBits(7);
  37133. return value + 37;
  37134. }
  37135. var tileIndex = context.currentTile.index;
  37136. var tile = context.tiles[tileIndex];
  37137. var packetsIterator = tile.packetsIterator;
  37138. while (position < dataLength) {
  37139. var packet = packetsIterator.nextPacket();
  37140. if (!readBits(1)) {
  37141. alignToByte();
  37142. continue;
  37143. }
  37144. var layerNumber = packet.layerNumber;
  37145. var queue = [], codeblock;
  37146. for (var i = 0, ii = packet.codeblocks.length; i < ii; i++) {
  37147. codeblock = packet.codeblocks[i];
  37148. var precinct = codeblock.precinct;
  37149. var codeblockColumn = codeblock.cbx - precinct.cbxMin;
  37150. var codeblockRow = codeblock.cby - precinct.cbyMin;
  37151. var codeblockIncluded = false;
  37152. var firstTimeInclusion = false;
  37153. var valueReady;
  37154. if ('included' in codeblock) {
  37155. codeblockIncluded = !!readBits(1);
  37156. } else {
  37157. // reading inclusion tree
  37158. precinct = codeblock.precinct;
  37159. var inclusionTree, zeroBitPlanesTree;
  37160. if ('inclusionTree' in precinct) {
  37161. inclusionTree = precinct.inclusionTree;
  37162. } else {
  37163. // building inclusion and zero bit-planes trees
  37164. var width = precinct.cbxMax - precinct.cbxMin + 1;
  37165. var height = precinct.cbyMax - precinct.cbyMin + 1;
  37166. inclusionTree = new InclusionTree(width, height, layerNumber);
  37167. zeroBitPlanesTree = new TagTree(width, height);
  37168. precinct.inclusionTree = inclusionTree;
  37169. precinct.zeroBitPlanesTree = zeroBitPlanesTree;
  37170. }
  37171. if (inclusionTree.reset(codeblockColumn, codeblockRow, layerNumber)) {
  37172. while (true) {
  37173. if (readBits(1)) {
  37174. valueReady = !inclusionTree.nextLevel();
  37175. if (valueReady) {
  37176. codeblock.included = true;
  37177. codeblockIncluded = firstTimeInclusion = true;
  37178. break;
  37179. }
  37180. } else {
  37181. inclusionTree.incrementValue(layerNumber);
  37182. break;
  37183. }
  37184. }
  37185. }
  37186. }
  37187. if (!codeblockIncluded) {
  37188. continue;
  37189. }
  37190. if (firstTimeInclusion) {
  37191. zeroBitPlanesTree = precinct.zeroBitPlanesTree;
  37192. zeroBitPlanesTree.reset(codeblockColumn, codeblockRow);
  37193. while (true) {
  37194. if (readBits(1)) {
  37195. valueReady = !zeroBitPlanesTree.nextLevel();
  37196. if (valueReady) {
  37197. break;
  37198. }
  37199. } else {
  37200. zeroBitPlanesTree.incrementValue();
  37201. }
  37202. }
  37203. codeblock.zeroBitPlanes = zeroBitPlanesTree.value;
  37204. }
  37205. var codingpasses = readCodingpasses();
  37206. while (readBits(1)) {
  37207. codeblock.Lblock++;
  37208. }
  37209. var codingpassesLog2 = log2(codingpasses);
  37210. // rounding down log2
  37211. var bits = ((codingpasses < (1 << codingpassesLog2)) ?
  37212. codingpassesLog2 - 1 : codingpassesLog2) + codeblock.Lblock;
  37213. var codedDataLength = readBits(bits);
  37214. queue.push({
  37215. codeblock: codeblock,
  37216. codingpasses: codingpasses,
  37217. dataLength: codedDataLength
  37218. });
  37219. }
  37220. alignToByte();
  37221. while (queue.length > 0) {
  37222. var packetItem = queue.shift();
  37223. codeblock = packetItem.codeblock;
  37224. if (!('data' in codeblock)) {
  37225. codeblock.data = [];
  37226. }
  37227. codeblock.data.push({
  37228. data: data,
  37229. start: offset + position,
  37230. end: offset + position + packetItem.dataLength,
  37231. codingpasses: packetItem.codingpasses
  37232. });
  37233. position += packetItem.dataLength;
  37234. }
  37235. }
  37236. return position;
  37237. }
  37238. function copyCoefficients(coefficients, levelWidth, levelHeight, subband,
  37239. delta, mb, reversible, segmentationSymbolUsed) {
  37240. var x0 = subband.tbx0;
  37241. var y0 = subband.tby0;
  37242. var width = subband.tbx1 - subband.tbx0;
  37243. var codeblocks = subband.codeblocks;
  37244. var right = subband.type.charAt(0) === 'H' ? 1 : 0;
  37245. var bottom = subband.type.charAt(1) === 'H' ? levelWidth : 0;
  37246. for (var i = 0, ii = codeblocks.length; i < ii; ++i) {
  37247. var codeblock = codeblocks[i];
  37248. var blockWidth = codeblock.tbx1_ - codeblock.tbx0_;
  37249. var blockHeight = codeblock.tby1_ - codeblock.tby0_;
  37250. if (blockWidth === 0 || blockHeight === 0) {
  37251. continue;
  37252. }
  37253. if (!('data' in codeblock)) {
  37254. continue;
  37255. }
  37256. var bitModel, currentCodingpassType;
  37257. bitModel = new BitModel(blockWidth, blockHeight, codeblock.subbandType,
  37258. codeblock.zeroBitPlanes, mb);
  37259. currentCodingpassType = 2; // first bit plane starts from cleanup
  37260. // collect data
  37261. var data = codeblock.data, totalLength = 0, codingpasses = 0;
  37262. var j, jj, dataItem;
  37263. for (j = 0, jj = data.length; j < jj; j++) {
  37264. dataItem = data[j];
  37265. totalLength += dataItem.end - dataItem.start;
  37266. codingpasses += dataItem.codingpasses;
  37267. }
  37268. var encodedData = new Uint8Array(totalLength);
  37269. var position = 0;
  37270. for (j = 0, jj = data.length; j < jj; j++) {
  37271. dataItem = data[j];
  37272. var chunk = dataItem.data.subarray(dataItem.start, dataItem.end);
  37273. encodedData.set(chunk, position);
  37274. position += chunk.length;
  37275. }
  37276. // decoding the item
  37277. var decoder = new ArithmeticDecoder(encodedData, 0, totalLength);
  37278. bitModel.setDecoder(decoder);
  37279. for (j = 0; j < codingpasses; j++) {
  37280. switch (currentCodingpassType) {
  37281. case 0:
  37282. bitModel.runSignificancePropogationPass();
  37283. break;
  37284. case 1:
  37285. bitModel.runMagnitudeRefinementPass();
  37286. break;
  37287. case 2:
  37288. bitModel.runCleanupPass();
  37289. if (segmentationSymbolUsed) {
  37290. bitModel.checkSegmentationSymbol();
  37291. }
  37292. break;
  37293. }
  37294. currentCodingpassType = (currentCodingpassType + 1) % 3;
  37295. }
  37296. var offset = (codeblock.tbx0_ - x0) + (codeblock.tby0_ - y0) * width;
  37297. var sign = bitModel.coefficentsSign;
  37298. var magnitude = bitModel.coefficentsMagnitude;
  37299. var bitsDecoded = bitModel.bitsDecoded;
  37300. var magnitudeCorrection = reversible ? 0 : 0.5;
  37301. var k, n, nb;
  37302. position = 0;
  37303. // Do the interleaving of Section F.3.3 here, so we do not need
  37304. // to copy later. LL level is not interleaved, just copied.
  37305. var interleave = (subband.type !== 'LL');
  37306. for (j = 0; j < blockHeight; j++) {
  37307. var row = (offset / width) | 0; // row in the non-interleaved subband
  37308. var levelOffset = 2 * row * (levelWidth - width) + right + bottom;
  37309. for (k = 0; k < blockWidth; k++) {
  37310. n = magnitude[position];
  37311. if (n !== 0) {
  37312. n = (n + magnitudeCorrection) * delta;
  37313. if (sign[position] !== 0) {
  37314. n = -n;
  37315. }
  37316. nb = bitsDecoded[position];
  37317. var pos = interleave ? (levelOffset + (offset << 1)) : offset;
  37318. if (reversible && (nb >= mb)) {
  37319. coefficients[pos] = n;
  37320. } else {
  37321. coefficients[pos] = n * (1 << (mb - nb));
  37322. }
  37323. }
  37324. offset++;
  37325. position++;
  37326. }
  37327. offset += width - blockWidth;
  37328. }
  37329. }
  37330. }
  37331. function transformTile(context, tile, c) {
  37332. var component = tile.components[c];
  37333. var codingStyleParameters = component.codingStyleParameters;
  37334. var quantizationParameters = component.quantizationParameters;
  37335. var decompositionLevelsCount =
  37336. codingStyleParameters.decompositionLevelsCount;
  37337. var spqcds = quantizationParameters.SPqcds;
  37338. var scalarExpounded = quantizationParameters.scalarExpounded;
  37339. var guardBits = quantizationParameters.guardBits;
  37340. var segmentationSymbolUsed = codingStyleParameters.segmentationSymbolUsed;
  37341. var precision = context.components[c].precision;
  37342. var reversible = codingStyleParameters.reversibleTransformation;
  37343. var transform = (reversible ? new ReversibleTransform() :
  37344. new IrreversibleTransform());
  37345. var subbandCoefficients = [];
  37346. var b = 0;
  37347. for (var i = 0; i <= decompositionLevelsCount; i++) {
  37348. var resolution = component.resolutions[i];
  37349. var width = resolution.trx1 - resolution.trx0;
  37350. var height = resolution.try1 - resolution.try0;
  37351. // Allocate space for the whole sublevel.
  37352. var coefficients = new Float32Array(width * height);
  37353. for (var j = 0, jj = resolution.subbands.length; j < jj; j++) {
  37354. var mu, epsilon;
  37355. if (!scalarExpounded) {
  37356. // formula E-5
  37357. mu = spqcds[0].mu;
  37358. epsilon = spqcds[0].epsilon + (i > 0 ? 1 - i : 0);
  37359. } else {
  37360. mu = spqcds[b].mu;
  37361. epsilon = spqcds[b].epsilon;
  37362. b++;
  37363. }
  37364. var subband = resolution.subbands[j];
  37365. var gainLog2 = SubbandsGainLog2[subband.type];
  37366. // calulate quantization coefficient (Section E.1.1.1)
  37367. var delta = (reversible ? 1 :
  37368. Math.pow(2, precision + gainLog2 - epsilon) * (1 + mu / 2048));
  37369. var mb = (guardBits + epsilon - 1);
  37370. // In the first resolution level, copyCoefficients will fill the
  37371. // whole array with coefficients. In the succeding passes,
  37372. // copyCoefficients will consecutively fill in the values that belong
  37373. // to the interleaved positions of the HL, LH, and HH coefficients.
  37374. // The LL coefficients will then be interleaved in Transform.iterate().
  37375. copyCoefficients(coefficients, width, height, subband, delta, mb,
  37376. reversible, segmentationSymbolUsed);
  37377. }
  37378. subbandCoefficients.push({
  37379. width: width,
  37380. height: height,
  37381. items: coefficients
  37382. });
  37383. }
  37384. var result = transform.calculate(subbandCoefficients,
  37385. component.tcx0, component.tcy0);
  37386. return {
  37387. left: component.tcx0,
  37388. top: component.tcy0,
  37389. width: result.width,
  37390. height: result.height,
  37391. items: result.items
  37392. };
  37393. }
  37394. function transformComponents(context) {
  37395. var siz = context.SIZ;
  37396. var components = context.components;
  37397. var componentsCount = siz.Csiz;
  37398. var resultImages = [];
  37399. for (var i = 0, ii = context.tiles.length; i < ii; i++) {
  37400. var tile = context.tiles[i];
  37401. var transformedTiles = [];
  37402. var c;
  37403. for (c = 0; c < componentsCount; c++) {
  37404. transformedTiles[c] = transformTile(context, tile, c);
  37405. }
  37406. var tile0 = transformedTiles[0];
  37407. var out = new Uint8Array(tile0.items.length * componentsCount);
  37408. var result = {
  37409. left: tile0.left,
  37410. top: tile0.top,
  37411. width: tile0.width,
  37412. height: tile0.height,
  37413. items: out
  37414. };
  37415. // Section G.2.2 Inverse multi component transform
  37416. var shift, offset, max, min, maxK;
  37417. var pos = 0, j, jj, y0, y1, y2, r, g, b, k, val;
  37418. if (tile.codingStyleDefaultParameters.multipleComponentTransform) {
  37419. var fourComponents = componentsCount === 4;
  37420. var y0items = transformedTiles[0].items;
  37421. var y1items = transformedTiles[1].items;
  37422. var y2items = transformedTiles[2].items;
  37423. var y3items = fourComponents ? transformedTiles[3].items : null;
  37424. // HACK: The multiple component transform formulas below assume that
  37425. // all components have the same precision. With this in mind, we
  37426. // compute shift and offset only once.
  37427. shift = components[0].precision - 8;
  37428. offset = (128 << shift) + 0.5;
  37429. max = 255 * (1 << shift);
  37430. maxK = max * 0.5;
  37431. min = -maxK;
  37432. var component0 = tile.components[0];
  37433. var alpha01 = componentsCount - 3;
  37434. jj = y0items.length;
  37435. if (!component0.codingStyleParameters.reversibleTransformation) {
  37436. // inverse irreversible multiple component transform
  37437. for (j = 0; j < jj; j++, pos += alpha01) {
  37438. y0 = y0items[j] + offset;
  37439. y1 = y1items[j];
  37440. y2 = y2items[j];
  37441. r = y0 + 1.402 * y2;
  37442. g = y0 - 0.34413 * y1 - 0.71414 * y2;
  37443. b = y0 + 1.772 * y1;
  37444. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  37445. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  37446. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  37447. }
  37448. } else {
  37449. // inverse reversible multiple component transform
  37450. for (j = 0; j < jj; j++, pos += alpha01) {
  37451. y0 = y0items[j] + offset;
  37452. y1 = y1items[j];
  37453. y2 = y2items[j];
  37454. g = y0 - ((y2 + y1) >> 2);
  37455. r = g + y2;
  37456. b = g + y1;
  37457. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  37458. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  37459. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  37460. }
  37461. }
  37462. if (fourComponents) {
  37463. for (j = 0, pos = 3; j < jj; j++, pos += 4) {
  37464. k = y3items[j];
  37465. out[pos] = k <= min ? 0 : k >= maxK ? 255 : (k + offset) >> shift;
  37466. }
  37467. }
  37468. } else { // no multi-component transform
  37469. for (c = 0; c < componentsCount; c++) {
  37470. var items = transformedTiles[c].items;
  37471. shift = components[c].precision - 8;
  37472. offset = (128 << shift) + 0.5;
  37473. max = (127.5 * (1 << shift));
  37474. min = -max;
  37475. for (pos = c, j = 0, jj = items.length; j < jj; j++) {
  37476. val = items[j];
  37477. out[pos] = val <= min ? 0 :
  37478. val >= max ? 255 : (val + offset) >> shift;
  37479. pos += componentsCount;
  37480. }
  37481. }
  37482. }
  37483. resultImages.push(result);
  37484. }
  37485. return resultImages;
  37486. }
  37487. function initializeTile(context, tileIndex) {
  37488. var siz = context.SIZ;
  37489. var componentsCount = siz.Csiz;
  37490. var tile = context.tiles[tileIndex];
  37491. for (var c = 0; c < componentsCount; c++) {
  37492. var component = tile.components[c];
  37493. var qcdOrQcc = (c in context.currentTile.QCC ?
  37494. context.currentTile.QCC[c] : context.currentTile.QCD);
  37495. component.quantizationParameters = qcdOrQcc;
  37496. var codOrCoc = (c in context.currentTile.COC ?
  37497. context.currentTile.COC[c] : context.currentTile.COD);
  37498. component.codingStyleParameters = codOrCoc;
  37499. }
  37500. tile.codingStyleDefaultParameters = context.currentTile.COD;
  37501. }
  37502. // Section B.10.2 Tag trees
  37503. var TagTree = (function TagTreeClosure() {
  37504. function TagTree(width, height) {
  37505. var levelsLength = log2(Math.max(width, height)) + 1;
  37506. this.levels = [];
  37507. for (var i = 0; i < levelsLength; i++) {
  37508. var level = {
  37509. width: width,
  37510. height: height,
  37511. items: []
  37512. };
  37513. this.levels.push(level);
  37514. width = Math.ceil(width / 2);
  37515. height = Math.ceil(height / 2);
  37516. }
  37517. }
  37518. TagTree.prototype = {
  37519. reset: function TagTree_reset(i, j) {
  37520. var currentLevel = 0, value = 0, level;
  37521. while (currentLevel < this.levels.length) {
  37522. level = this.levels[currentLevel];
  37523. var index = i + j * level.width;
  37524. if (index in level.items) {
  37525. value = level.items[index];
  37526. break;
  37527. }
  37528. level.index = index;
  37529. i >>= 1;
  37530. j >>= 1;
  37531. currentLevel++;
  37532. }
  37533. currentLevel--;
  37534. level = this.levels[currentLevel];
  37535. level.items[level.index] = value;
  37536. this.currentLevel = currentLevel;
  37537. delete this.value;
  37538. },
  37539. incrementValue: function TagTree_incrementValue() {
  37540. var level = this.levels[this.currentLevel];
  37541. level.items[level.index]++;
  37542. },
  37543. nextLevel: function TagTree_nextLevel() {
  37544. var currentLevel = this.currentLevel;
  37545. var level = this.levels[currentLevel];
  37546. var value = level.items[level.index];
  37547. currentLevel--;
  37548. if (currentLevel < 0) {
  37549. this.value = value;
  37550. return false;
  37551. }
  37552. this.currentLevel = currentLevel;
  37553. level = this.levels[currentLevel];
  37554. level.items[level.index] = value;
  37555. return true;
  37556. }
  37557. };
  37558. return TagTree;
  37559. })();
  37560. var InclusionTree = (function InclusionTreeClosure() {
  37561. function InclusionTree(width, height, defaultValue) {
  37562. var levelsLength = log2(Math.max(width, height)) + 1;
  37563. this.levels = [];
  37564. for (var i = 0; i < levelsLength; i++) {
  37565. var items = new Uint8Array(width * height);
  37566. for (var j = 0, jj = items.length; j < jj; j++) {
  37567. items[j] = defaultValue;
  37568. }
  37569. var level = {
  37570. width: width,
  37571. height: height,
  37572. items: items
  37573. };
  37574. this.levels.push(level);
  37575. width = Math.ceil(width / 2);
  37576. height = Math.ceil(height / 2);
  37577. }
  37578. }
  37579. InclusionTree.prototype = {
  37580. reset: function InclusionTree_reset(i, j, stopValue) {
  37581. var currentLevel = 0;
  37582. while (currentLevel < this.levels.length) {
  37583. var level = this.levels[currentLevel];
  37584. var index = i + j * level.width;
  37585. level.index = index;
  37586. var value = level.items[index];
  37587. if (value === 0xFF) {
  37588. break;
  37589. }
  37590. if (value > stopValue) {
  37591. this.currentLevel = currentLevel;
  37592. // already know about this one, propagating the value to top levels
  37593. this.propagateValues();
  37594. return false;
  37595. }
  37596. i >>= 1;
  37597. j >>= 1;
  37598. currentLevel++;
  37599. }
  37600. this.currentLevel = currentLevel - 1;
  37601. return true;
  37602. },
  37603. incrementValue: function InclusionTree_incrementValue(stopValue) {
  37604. var level = this.levels[this.currentLevel];
  37605. level.items[level.index] = stopValue + 1;
  37606. this.propagateValues();
  37607. },
  37608. propagateValues: function InclusionTree_propagateValues() {
  37609. var levelIndex = this.currentLevel;
  37610. var level = this.levels[levelIndex];
  37611. var currentValue = level.items[level.index];
  37612. while (--levelIndex >= 0) {
  37613. level = this.levels[levelIndex];
  37614. level.items[level.index] = currentValue;
  37615. }
  37616. },
  37617. nextLevel: function InclusionTree_nextLevel() {
  37618. var currentLevel = this.currentLevel;
  37619. var level = this.levels[currentLevel];
  37620. var value = level.items[level.index];
  37621. level.items[level.index] = 0xFF;
  37622. currentLevel--;
  37623. if (currentLevel < 0) {
  37624. return false;
  37625. }
  37626. this.currentLevel = currentLevel;
  37627. level = this.levels[currentLevel];
  37628. level.items[level.index] = value;
  37629. return true;
  37630. }
  37631. };
  37632. return InclusionTree;
  37633. })();
  37634. // Section D. Coefficient bit modeling
  37635. var BitModel = (function BitModelClosure() {
  37636. var UNIFORM_CONTEXT = 17;
  37637. var RUNLENGTH_CONTEXT = 18;
  37638. // Table D-1
  37639. // The index is binary presentation: 0dddvvhh, ddd - sum of Di (0..4),
  37640. // vv - sum of Vi (0..2), and hh - sum of Hi (0..2)
  37641. var LLAndLHContextsLabel = new Uint8Array([
  37642. 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,
  37643. 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,
  37644. 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
  37645. ]);
  37646. var HLContextLabel = new Uint8Array([
  37647. 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,
  37648. 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,
  37649. 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
  37650. ]);
  37651. var HHContextLabel = new Uint8Array([
  37652. 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,
  37653. 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,
  37654. 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
  37655. ]);
  37656. function BitModel(width, height, subband, zeroBitPlanes, mb) {
  37657. this.width = width;
  37658. this.height = height;
  37659. this.contextLabelTable = (subband === 'HH' ? HHContextLabel :
  37660. (subband === 'HL' ? HLContextLabel : LLAndLHContextsLabel));
  37661. var coefficientCount = width * height;
  37662. // coefficients outside the encoding region treated as insignificant
  37663. // add border state cells for significanceState
  37664. this.neighborsSignificance = new Uint8Array(coefficientCount);
  37665. this.coefficentsSign = new Uint8Array(coefficientCount);
  37666. this.coefficentsMagnitude = mb > 14 ? new Uint32Array(coefficientCount) :
  37667. mb > 6 ? new Uint16Array(coefficientCount) :
  37668. new Uint8Array(coefficientCount);
  37669. this.processingFlags = new Uint8Array(coefficientCount);
  37670. var bitsDecoded = new Uint8Array(coefficientCount);
  37671. if (zeroBitPlanes !== 0) {
  37672. for (var i = 0; i < coefficientCount; i++) {
  37673. bitsDecoded[i] = zeroBitPlanes;
  37674. }
  37675. }
  37676. this.bitsDecoded = bitsDecoded;
  37677. this.reset();
  37678. }
  37679. BitModel.prototype = {
  37680. setDecoder: function BitModel_setDecoder(decoder) {
  37681. this.decoder = decoder;
  37682. },
  37683. reset: function BitModel_reset() {
  37684. // We have 17 contexts that are accessed via context labels,
  37685. // plus the uniform and runlength context.
  37686. this.contexts = new Int8Array(19);
  37687. // Contexts are packed into 1 byte:
  37688. // highest 7 bits carry the index, lowest bit carries mps
  37689. this.contexts[0] = (4 << 1) | 0;
  37690. this.contexts[UNIFORM_CONTEXT] = (46 << 1) | 0;
  37691. this.contexts[RUNLENGTH_CONTEXT] = (3 << 1) | 0;
  37692. },
  37693. setNeighborsSignificance:
  37694. function BitModel_setNeighborsSignificance(row, column, index) {
  37695. var neighborsSignificance = this.neighborsSignificance;
  37696. var width = this.width, height = this.height;
  37697. var left = (column > 0);
  37698. var right = (column + 1 < width);
  37699. var i;
  37700. if (row > 0) {
  37701. i = index - width;
  37702. if (left) {
  37703. neighborsSignificance[i - 1] += 0x10;
  37704. }
  37705. if (right) {
  37706. neighborsSignificance[i + 1] += 0x10;
  37707. }
  37708. neighborsSignificance[i] += 0x04;
  37709. }
  37710. if (row + 1 < height) {
  37711. i = index + width;
  37712. if (left) {
  37713. neighborsSignificance[i - 1] += 0x10;
  37714. }
  37715. if (right) {
  37716. neighborsSignificance[i + 1] += 0x10;
  37717. }
  37718. neighborsSignificance[i] += 0x04;
  37719. }
  37720. if (left) {
  37721. neighborsSignificance[index - 1] += 0x01;
  37722. }
  37723. if (right) {
  37724. neighborsSignificance[index + 1] += 0x01;
  37725. }
  37726. neighborsSignificance[index] |= 0x80;
  37727. },
  37728. runSignificancePropogationPass:
  37729. function BitModel_runSignificancePropogationPass() {
  37730. var decoder = this.decoder;
  37731. var width = this.width, height = this.height;
  37732. var coefficentsMagnitude = this.coefficentsMagnitude;
  37733. var coefficentsSign = this.coefficentsSign;
  37734. var neighborsSignificance = this.neighborsSignificance;
  37735. var processingFlags = this.processingFlags;
  37736. var contexts = this.contexts;
  37737. var labels = this.contextLabelTable;
  37738. var bitsDecoded = this.bitsDecoded;
  37739. var processedInverseMask = ~1;
  37740. var processedMask = 1;
  37741. var firstMagnitudeBitMask = 2;
  37742. for (var i0 = 0; i0 < height; i0 += 4) {
  37743. for (var j = 0; j < width; j++) {
  37744. var index = i0 * width + j;
  37745. for (var i1 = 0; i1 < 4; i1++, index += width) {
  37746. var i = i0 + i1;
  37747. if (i >= height) {
  37748. break;
  37749. }
  37750. // clear processed flag first
  37751. processingFlags[index] &= processedInverseMask;
  37752. if (coefficentsMagnitude[index] ||
  37753. !neighborsSignificance[index]) {
  37754. continue;
  37755. }
  37756. var contextLabel = labels[neighborsSignificance[index]];
  37757. var decision = decoder.readBit(contexts, contextLabel);
  37758. if (decision) {
  37759. var sign = this.decodeSignBit(i, j, index);
  37760. coefficentsSign[index] = sign;
  37761. coefficentsMagnitude[index] = 1;
  37762. this.setNeighborsSignificance(i, j, index);
  37763. processingFlags[index] |= firstMagnitudeBitMask;
  37764. }
  37765. bitsDecoded[index]++;
  37766. processingFlags[index] |= processedMask;
  37767. }
  37768. }
  37769. }
  37770. },
  37771. decodeSignBit: function BitModel_decodeSignBit(row, column, index) {
  37772. var width = this.width, height = this.height;
  37773. var coefficentsMagnitude = this.coefficentsMagnitude;
  37774. var coefficentsSign = this.coefficentsSign;
  37775. var contribution, sign0, sign1, significance1;
  37776. var contextLabel, decoded;
  37777. // calculate horizontal contribution
  37778. significance1 = (column > 0 && coefficentsMagnitude[index - 1] !== 0);
  37779. if (column + 1 < width && coefficentsMagnitude[index + 1] !== 0) {
  37780. sign1 = coefficentsSign[index + 1];
  37781. if (significance1) {
  37782. sign0 = coefficentsSign[index - 1];
  37783. contribution = 1 - sign1 - sign0;
  37784. } else {
  37785. contribution = 1 - sign1 - sign1;
  37786. }
  37787. } else if (significance1) {
  37788. sign0 = coefficentsSign[index - 1];
  37789. contribution = 1 - sign0 - sign0;
  37790. } else {
  37791. contribution = 0;
  37792. }
  37793. var horizontalContribution = 3 * contribution;
  37794. // calculate vertical contribution and combine with the horizontal
  37795. significance1 = (row > 0 && coefficentsMagnitude[index - width] !== 0);
  37796. if (row + 1 < height && coefficentsMagnitude[index + width] !== 0) {
  37797. sign1 = coefficentsSign[index + width];
  37798. if (significance1) {
  37799. sign0 = coefficentsSign[index - width];
  37800. contribution = 1 - sign1 - sign0 + horizontalContribution;
  37801. } else {
  37802. contribution = 1 - sign1 - sign1 + horizontalContribution;
  37803. }
  37804. } else if (significance1) {
  37805. sign0 = coefficentsSign[index - width];
  37806. contribution = 1 - sign0 - sign0 + horizontalContribution;
  37807. } else {
  37808. contribution = horizontalContribution;
  37809. }
  37810. if (contribution >= 0) {
  37811. contextLabel = 9 + contribution;
  37812. decoded = this.decoder.readBit(this.contexts, contextLabel);
  37813. } else {
  37814. contextLabel = 9 - contribution;
  37815. decoded = this.decoder.readBit(this.contexts, contextLabel) ^ 1;
  37816. }
  37817. return decoded;
  37818. },
  37819. runMagnitudeRefinementPass:
  37820. function BitModel_runMagnitudeRefinementPass() {
  37821. var decoder = this.decoder;
  37822. var width = this.width, height = this.height;
  37823. var coefficentsMagnitude = this.coefficentsMagnitude;
  37824. var neighborsSignificance = this.neighborsSignificance;
  37825. var contexts = this.contexts;
  37826. var bitsDecoded = this.bitsDecoded;
  37827. var processingFlags = this.processingFlags;
  37828. var processedMask = 1;
  37829. var firstMagnitudeBitMask = 2;
  37830. var length = width * height;
  37831. var width4 = width * 4;
  37832. for (var index0 = 0, indexNext; index0 < length; index0 = indexNext) {
  37833. indexNext = Math.min(length, index0 + width4);
  37834. for (var j = 0; j < width; j++) {
  37835. for (var index = index0 + j; index < indexNext; index += width) {
  37836. // significant but not those that have just become
  37837. if (!coefficentsMagnitude[index] ||
  37838. (processingFlags[index] & processedMask) !== 0) {
  37839. continue;
  37840. }
  37841. var contextLabel = 16;
  37842. if ((processingFlags[index] & firstMagnitudeBitMask) !== 0) {
  37843. processingFlags[index] ^= firstMagnitudeBitMask;
  37844. // first refinement
  37845. var significance = neighborsSignificance[index] & 127;
  37846. contextLabel = significance === 0 ? 15 : 14;
  37847. }
  37848. var bit = decoder.readBit(contexts, contextLabel);
  37849. coefficentsMagnitude[index] =
  37850. (coefficentsMagnitude[index] << 1) | bit;
  37851. bitsDecoded[index]++;
  37852. processingFlags[index] |= processedMask;
  37853. }
  37854. }
  37855. }
  37856. },
  37857. runCleanupPass: function BitModel_runCleanupPass() {
  37858. var decoder = this.decoder;
  37859. var width = this.width, height = this.height;
  37860. var neighborsSignificance = this.neighborsSignificance;
  37861. var coefficentsMagnitude = this.coefficentsMagnitude;
  37862. var coefficentsSign = this.coefficentsSign;
  37863. var contexts = this.contexts;
  37864. var labels = this.contextLabelTable;
  37865. var bitsDecoded = this.bitsDecoded;
  37866. var processingFlags = this.processingFlags;
  37867. var processedMask = 1;
  37868. var firstMagnitudeBitMask = 2;
  37869. var oneRowDown = width;
  37870. var twoRowsDown = width * 2;
  37871. var threeRowsDown = width * 3;
  37872. var iNext;
  37873. for (var i0 = 0; i0 < height; i0 = iNext) {
  37874. iNext = Math.min(i0 + 4, height);
  37875. var indexBase = i0 * width;
  37876. var checkAllEmpty = i0 + 3 < height;
  37877. for (var j = 0; j < width; j++) {
  37878. var index0 = indexBase + j;
  37879. // using the property: labels[neighborsSignificance[index]] === 0
  37880. // when neighborsSignificance[index] === 0
  37881. var allEmpty = (checkAllEmpty &&
  37882. processingFlags[index0] === 0 &&
  37883. processingFlags[index0 + oneRowDown] === 0 &&
  37884. processingFlags[index0 + twoRowsDown] === 0 &&
  37885. processingFlags[index0 + threeRowsDown] === 0 &&
  37886. neighborsSignificance[index0] === 0 &&
  37887. neighborsSignificance[index0 + oneRowDown] === 0 &&
  37888. neighborsSignificance[index0 + twoRowsDown] === 0 &&
  37889. neighborsSignificance[index0 + threeRowsDown] === 0);
  37890. var i1 = 0, index = index0;
  37891. var i = i0, sign;
  37892. if (allEmpty) {
  37893. var hasSignificantCoefficent =
  37894. decoder.readBit(contexts, RUNLENGTH_CONTEXT);
  37895. if (!hasSignificantCoefficent) {
  37896. bitsDecoded[index0]++;
  37897. bitsDecoded[index0 + oneRowDown]++;
  37898. bitsDecoded[index0 + twoRowsDown]++;
  37899. bitsDecoded[index0 + threeRowsDown]++;
  37900. continue; // next column
  37901. }
  37902. i1 = (decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
  37903. decoder.readBit(contexts, UNIFORM_CONTEXT);
  37904. if (i1 !== 0) {
  37905. i = i0 + i1;
  37906. index += i1 * width;
  37907. }
  37908. sign = this.decodeSignBit(i, j, index);
  37909. coefficentsSign[index] = sign;
  37910. coefficentsMagnitude[index] = 1;
  37911. this.setNeighborsSignificance(i, j, index);
  37912. processingFlags[index] |= firstMagnitudeBitMask;
  37913. index = index0;
  37914. for (var i2 = i0; i2 <= i; i2++, index += width) {
  37915. bitsDecoded[index]++;
  37916. }
  37917. i1++;
  37918. }
  37919. for (i = i0 + i1; i < iNext; i++, index += width) {
  37920. if (coefficentsMagnitude[index] ||
  37921. (processingFlags[index] & processedMask) !== 0) {
  37922. continue;
  37923. }
  37924. var contextLabel = labels[neighborsSignificance[index]];
  37925. var decision = decoder.readBit(contexts, contextLabel);
  37926. if (decision === 1) {
  37927. sign = this.decodeSignBit(i, j, index);
  37928. coefficentsSign[index] = sign;
  37929. coefficentsMagnitude[index] = 1;
  37930. this.setNeighborsSignificance(i, j, index);
  37931. processingFlags[index] |= firstMagnitudeBitMask;
  37932. }
  37933. bitsDecoded[index]++;
  37934. }
  37935. }
  37936. }
  37937. },
  37938. checkSegmentationSymbol: function BitModel_checkSegmentationSymbol() {
  37939. var decoder = this.decoder;
  37940. var contexts = this.contexts;
  37941. var symbol = (decoder.readBit(contexts, UNIFORM_CONTEXT) << 3) |
  37942. (decoder.readBit(contexts, UNIFORM_CONTEXT) << 2) |
  37943. (decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
  37944. decoder.readBit(contexts, UNIFORM_CONTEXT);
  37945. if (symbol !== 0xA) {
  37946. throw new Error('JPX Error: Invalid segmentation symbol');
  37947. }
  37948. }
  37949. };
  37950. return BitModel;
  37951. })();
  37952. // Section F, Discrete wavelet transformation
  37953. var Transform = (function TransformClosure() {
  37954. function Transform() {}
  37955. Transform.prototype.calculate =
  37956. function transformCalculate(subbands, u0, v0) {
  37957. var ll = subbands[0];
  37958. for (var i = 1, ii = subbands.length; i < ii; i++) {
  37959. ll = this.iterate(ll, subbands[i], u0, v0);
  37960. }
  37961. return ll;
  37962. };
  37963. Transform.prototype.extend = function extend(buffer, offset, size) {
  37964. // Section F.3.7 extending... using max extension of 4
  37965. var i1 = offset - 1, j1 = offset + 1;
  37966. var i2 = offset + size - 2, j2 = offset + size;
  37967. buffer[i1--] = buffer[j1++];
  37968. buffer[j2++] = buffer[i2--];
  37969. buffer[i1--] = buffer[j1++];
  37970. buffer[j2++] = buffer[i2--];
  37971. buffer[i1--] = buffer[j1++];
  37972. buffer[j2++] = buffer[i2--];
  37973. buffer[i1] = buffer[j1];
  37974. buffer[j2] = buffer[i2];
  37975. };
  37976. Transform.prototype.iterate = function Transform_iterate(ll, hl_lh_hh,
  37977. u0, v0) {
  37978. var llWidth = ll.width, llHeight = ll.height, llItems = ll.items;
  37979. var width = hl_lh_hh.width;
  37980. var height = hl_lh_hh.height;
  37981. var items = hl_lh_hh.items;
  37982. var i, j, k, l, u, v;
  37983. // Interleave LL according to Section F.3.3
  37984. for (k = 0, i = 0; i < llHeight; i++) {
  37985. l = i * 2 * width;
  37986. for (j = 0; j < llWidth; j++, k++, l += 2) {
  37987. items[l] = llItems[k];
  37988. }
  37989. }
  37990. // The LL band is not needed anymore.
  37991. llItems = ll.items = null;
  37992. var bufferPadding = 4;
  37993. var rowBuffer = new Float32Array(width + 2 * bufferPadding);
  37994. // Section F.3.4 HOR_SR
  37995. if (width === 1) {
  37996. // if width = 1, when u0 even keep items as is, when odd divide by 2
  37997. if ((u0 & 1) !== 0) {
  37998. for (v = 0, k = 0; v < height; v++, k += width) {
  37999. items[k] *= 0.5;
  38000. }
  38001. }
  38002. } else {
  38003. for (v = 0, k = 0; v < height; v++, k += width) {
  38004. rowBuffer.set(items.subarray(k, k + width), bufferPadding);
  38005. this.extend(rowBuffer, bufferPadding, width);
  38006. this.filter(rowBuffer, bufferPadding, width);
  38007. items.set(
  38008. rowBuffer.subarray(bufferPadding, bufferPadding + width),
  38009. k);
  38010. }
  38011. }
  38012. // Accesses to the items array can take long, because it may not fit into
  38013. // CPU cache and has to be fetched from main memory. Since subsequent
  38014. // accesses to the items array are not local when reading columns, we
  38015. // have a cache miss every time. To reduce cache misses, get up to
  38016. // 'numBuffers' items at a time and store them into the individual
  38017. // buffers. The colBuffers should be small enough to fit into CPU cache.
  38018. var numBuffers = 16;
  38019. var colBuffers = [];
  38020. for (i = 0; i < numBuffers; i++) {
  38021. colBuffers.push(new Float32Array(height + 2 * bufferPadding));
  38022. }
  38023. var b, currentBuffer = 0;
  38024. ll = bufferPadding + height;
  38025. // Section F.3.5 VER_SR
  38026. if (height === 1) {
  38027. // if height = 1, when v0 even keep items as is, when odd divide by 2
  38028. if ((v0 & 1) !== 0) {
  38029. for (u = 0; u < width; u++) {
  38030. items[u] *= 0.5;
  38031. }
  38032. }
  38033. } else {
  38034. for (u = 0; u < width; u++) {
  38035. // if we ran out of buffers, copy several image columns at once
  38036. if (currentBuffer === 0) {
  38037. numBuffers = Math.min(width - u, numBuffers);
  38038. for (k = u, l = bufferPadding; l < ll; k += width, l++) {
  38039. for (b = 0; b < numBuffers; b++) {
  38040. colBuffers[b][l] = items[k + b];
  38041. }
  38042. }
  38043. currentBuffer = numBuffers;
  38044. }
  38045. currentBuffer--;
  38046. var buffer = colBuffers[currentBuffer];
  38047. this.extend(buffer, bufferPadding, height);
  38048. this.filter(buffer, bufferPadding, height);
  38049. // If this is last buffer in this group of buffers, flush all buffers.
  38050. if (currentBuffer === 0) {
  38051. k = u - numBuffers + 1;
  38052. for (l = bufferPadding; l < ll; k += width, l++) {
  38053. for (b = 0; b < numBuffers; b++) {
  38054. items[k + b] = colBuffers[b][l];
  38055. }
  38056. }
  38057. }
  38058. }
  38059. }
  38060. return {
  38061. width: width,
  38062. height: height,
  38063. items: items
  38064. };
  38065. };
  38066. return Transform;
  38067. })();
  38068. // Section 3.8.2 Irreversible 9-7 filter
  38069. var IrreversibleTransform = (function IrreversibleTransformClosure() {
  38070. function IrreversibleTransform() {
  38071. Transform.call(this);
  38072. }
  38073. IrreversibleTransform.prototype = Object.create(Transform.prototype);
  38074. IrreversibleTransform.prototype.filter =
  38075. function irreversibleTransformFilter(x, offset, length) {
  38076. var len = length >> 1;
  38077. offset = offset | 0;
  38078. var j, n, current, next;
  38079. var alpha = -1.586134342059924;
  38080. var beta = -0.052980118572961;
  38081. var gamma = 0.882911075530934;
  38082. var delta = 0.443506852043971;
  38083. var K = 1.230174104914001;
  38084. var K_ = 1 / K;
  38085. // step 1 is combined with step 3
  38086. // step 2
  38087. j = offset - 3;
  38088. for (n = len + 4; n--; j += 2) {
  38089. x[j] *= K_;
  38090. }
  38091. // step 1 & 3
  38092. j = offset - 2;
  38093. current = delta * x[j -1];
  38094. for (n = len + 3; n--; j += 2) {
  38095. next = delta * x[j + 1];
  38096. x[j] = K * x[j] - current - next;
  38097. if (n--) {
  38098. j += 2;
  38099. current = delta * x[j + 1];
  38100. x[j] = K * x[j] - current - next;
  38101. } else {
  38102. break;
  38103. }
  38104. }
  38105. // step 4
  38106. j = offset - 1;
  38107. current = gamma * x[j - 1];
  38108. for (n = len + 2; n--; j += 2) {
  38109. next = gamma * x[j + 1];
  38110. x[j] -= current + next;
  38111. if (n--) {
  38112. j += 2;
  38113. current = gamma * x[j + 1];
  38114. x[j] -= current + next;
  38115. } else {
  38116. break;
  38117. }
  38118. }
  38119. // step 5
  38120. j = offset;
  38121. current = beta * x[j - 1];
  38122. for (n = len + 1; n--; j += 2) {
  38123. next = beta * x[j + 1];
  38124. x[j] -= current + next;
  38125. if (n--) {
  38126. j += 2;
  38127. current = beta * x[j + 1];
  38128. x[j] -= current + next;
  38129. } else {
  38130. break;
  38131. }
  38132. }
  38133. // step 6
  38134. if (len !== 0) {
  38135. j = offset + 1;
  38136. current = alpha * x[j - 1];
  38137. for (n = len; n--; j += 2) {
  38138. next = alpha * x[j + 1];
  38139. x[j] -= current + next;
  38140. if (n--) {
  38141. j += 2;
  38142. current = alpha * x[j + 1];
  38143. x[j] -= current + next;
  38144. } else {
  38145. break;
  38146. }
  38147. }
  38148. }
  38149. };
  38150. return IrreversibleTransform;
  38151. })();
  38152. // Section 3.8.1 Reversible 5-3 filter
  38153. var ReversibleTransform = (function ReversibleTransformClosure() {
  38154. function ReversibleTransform() {
  38155. Transform.call(this);
  38156. }
  38157. ReversibleTransform.prototype = Object.create(Transform.prototype);
  38158. ReversibleTransform.prototype.filter =
  38159. function reversibleTransformFilter(x, offset, length) {
  38160. var len = length >> 1;
  38161. offset = offset | 0;
  38162. var j, n;
  38163. for (j = offset, n = len + 1; n--; j += 2) {
  38164. x[j] -= (x[j - 1] + x[j + 1] + 2) >> 2;
  38165. }
  38166. for (j = offset + 1, n = len; n--; j += 2) {
  38167. x[j] += (x[j - 1] + x[j + 1]) >> 1;
  38168. }
  38169. };
  38170. return ReversibleTransform;
  38171. })();
  38172. return JpxImage;
  38173. })();
  38174. var Jbig2Image = (function Jbig2ImageClosure() {
  38175. // Utility data structures
  38176. function ContextCache() {}
  38177. ContextCache.prototype = {
  38178. getContexts: function(id) {
  38179. if (id in this) {
  38180. return this[id];
  38181. }
  38182. return (this[id] = new Int8Array(1 << 16));
  38183. }
  38184. };
  38185. function DecodingContext(data, start, end) {
  38186. this.data = data;
  38187. this.start = start;
  38188. this.end = end;
  38189. }
  38190. DecodingContext.prototype = {
  38191. get decoder() {
  38192. var decoder = new ArithmeticDecoder(this.data, this.start, this.end);
  38193. return shadow(this, 'decoder', decoder);
  38194. },
  38195. get contextCache() {
  38196. var cache = new ContextCache();
  38197. return shadow(this, 'contextCache', cache);
  38198. }
  38199. };
  38200. // Annex A. Arithmetic Integer Decoding Procedure
  38201. // A.2 Procedure for decoding values
  38202. function decodeInteger(contextCache, procedure, decoder) {
  38203. var contexts = contextCache.getContexts(procedure);
  38204. var prev = 1;
  38205. function readBits(length) {
  38206. var v = 0;
  38207. for (var i = 0; i < length; i++) {
  38208. var bit = decoder.readBit(contexts, prev);
  38209. prev = (prev < 256 ? (prev << 1) | bit :
  38210. (((prev << 1) | bit) & 511) | 256);
  38211. v = (v << 1) | bit;
  38212. }
  38213. return v >>> 0;
  38214. }
  38215. var sign = readBits(1);
  38216. var value = readBits(1) ?
  38217. (readBits(1) ?
  38218. (readBits(1) ?
  38219. (readBits(1) ?
  38220. (readBits(1) ?
  38221. (readBits(32) + 4436) :
  38222. readBits(12) + 340) :
  38223. readBits(8) + 84) :
  38224. readBits(6) + 20) :
  38225. readBits(4) + 4) :
  38226. readBits(2);
  38227. return (sign === 0 ? value : (value > 0 ? -value : null));
  38228. }
  38229. // A.3 The IAID decoding procedure
  38230. function decodeIAID(contextCache, decoder, codeLength) {
  38231. var contexts = contextCache.getContexts('IAID');
  38232. var prev = 1;
  38233. for (var i = 0; i < codeLength; i++) {
  38234. var bit = decoder.readBit(contexts, prev);
  38235. prev = (prev << 1) | bit;
  38236. }
  38237. if (codeLength < 31) {
  38238. return prev & ((1 << codeLength) - 1);
  38239. }
  38240. return prev & 0x7FFFFFFF;
  38241. }
  38242. // 7.3 Segment types
  38243. var SegmentTypes = [
  38244. 'SymbolDictionary', null, null, null, 'IntermediateTextRegion', null,
  38245. 'ImmediateTextRegion', 'ImmediateLosslessTextRegion', null, null, null,
  38246. null, null, null, null, null, 'patternDictionary', null, null, null,
  38247. 'IntermediateHalftoneRegion', null, 'ImmediateHalftoneRegion',
  38248. 'ImmediateLosslessHalftoneRegion', null, null, null, null, null, null, null,
  38249. null, null, null, null, null, 'IntermediateGenericRegion', null,
  38250. 'ImmediateGenericRegion', 'ImmediateLosslessGenericRegion',
  38251. 'IntermediateGenericRefinementRegion', null,
  38252. 'ImmediateGenericRefinementRegion',
  38253. 'ImmediateLosslessGenericRefinementRegion', null, null, null, null,
  38254. 'PageInformation', 'EndOfPage', 'EndOfStripe', 'EndOfFile', 'Profiles',
  38255. 'Tables', null, null, null, null, null, null, null, null,
  38256. 'Extension'
  38257. ];
  38258. var CodingTemplates = [
  38259. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: -2, y: -1},
  38260. {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: 2, y: -1},
  38261. {x: -4, y: 0}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}],
  38262. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: 2, y: -2},
  38263. {x: -2, y: -1}, {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1},
  38264. {x: 2, y: -1}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}],
  38265. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: -2, y: -1},
  38266. {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: -2, y: 0},
  38267. {x: -1, y: 0}],
  38268. [{x: -3, y: -1}, {x: -2, y: -1}, {x: -1, y: -1}, {x: 0, y: -1},
  38269. {x: 1, y: -1}, {x: -4, y: 0}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}]
  38270. ];
  38271. var RefinementTemplates = [
  38272. {
  38273. coding: [{x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}],
  38274. reference: [{x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}, {x: 0, y: 0},
  38275. {x: 1, y: 0}, {x: -1, y: 1}, {x: 0, y: 1}, {x: 1, y: 1}]
  38276. },
  38277. {
  38278. coding: [{x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}],
  38279. reference: [{x: 0, y: -1}, {x: -1, y: 0}, {x: 0, y: 0}, {x: 1, y: 0},
  38280. {x: 0, y: 1}, {x: 1, y: 1}]
  38281. }
  38282. ];
  38283. // See 6.2.5.7 Decoding the bitmap.
  38284. var ReusedContexts = [
  38285. 0x9B25, // 10011 0110010 0101
  38286. 0x0795, // 0011 110010 101
  38287. 0x00E5, // 001 11001 01
  38288. 0x0195 // 011001 0101
  38289. ];
  38290. var RefinementReusedContexts = [
  38291. 0x0020, // '000' + '0' (coding) + '00010000' + '0' (reference)
  38292. 0x0008 // '0000' + '001000'
  38293. ];
  38294. function decodeBitmapTemplate0(width, height, decodingContext) {
  38295. var decoder = decodingContext.decoder;
  38296. var contexts = decodingContext.contextCache.getContexts('GB');
  38297. var contextLabel, i, j, pixel, row, row1, row2, bitmap = [];
  38298. // ...ooooo....
  38299. // ..ooooooo... Context template for current pixel (X)
  38300. // .ooooX...... (concatenate values of 'o'-pixels to get contextLabel)
  38301. var OLD_PIXEL_MASK = 0x7BF7; // 01111 0111111 0111
  38302. for (i = 0; i < height; i++) {
  38303. row = bitmap[i] = new Uint8Array(width);
  38304. row1 = (i < 1) ? row : bitmap[i - 1];
  38305. row2 = (i < 2) ? row : bitmap[i - 2];
  38306. // At the beginning of each row:
  38307. // Fill contextLabel with pixels that are above/right of (X)
  38308. contextLabel = (row2[0] << 13) | (row2[1] << 12) | (row2[2] << 11) |
  38309. (row1[0] << 7) | (row1[1] << 6) | (row1[2] << 5) |
  38310. (row1[3] << 4);
  38311. for (j = 0; j < width; j++) {
  38312. row[j] = pixel = decoder.readBit(contexts, contextLabel);
  38313. // At each pixel: Clear contextLabel pixels that are shifted
  38314. // out of the context, then add new ones.
  38315. // If j + n is out of range at the right image border, then
  38316. // the undefined value of bitmap[i - 2][j + n] is shifted to 0
  38317. contextLabel = ((contextLabel & OLD_PIXEL_MASK) << 1) |
  38318. (row2[j + 3] << 11) | (row1[j + 4] << 4) | pixel;
  38319. }
  38320. }
  38321. return bitmap;
  38322. }
  38323. // 6.2 Generic Region Decoding Procedure
  38324. function decodeBitmap(mmr, width, height, templateIndex, prediction, skip, at,
  38325. decodingContext) {
  38326. if (mmr) {
  38327. error('JBIG2 error: MMR encoding is not supported');
  38328. }
  38329. // Use optimized version for the most common case
  38330. if (templateIndex === 0 && !skip && !prediction && at.length === 4 &&
  38331. at[0].x === 3 && at[0].y === -1 && at[1].x === -3 && at[1].y === -1 &&
  38332. at[2].x === 2 && at[2].y === -2 && at[3].x === -2 && at[3].y === -2) {
  38333. return decodeBitmapTemplate0(width, height, decodingContext);
  38334. }
  38335. var useskip = !!skip;
  38336. var template = CodingTemplates[templateIndex].concat(at);
  38337. // Sorting is non-standard, and it is not required. But sorting increases
  38338. // the number of template bits that can be reused from the previous
  38339. // contextLabel in the main loop.
  38340. template.sort(function (a, b) {
  38341. return (a.y - b.y) || (a.x - b.x);
  38342. });
  38343. var templateLength = template.length;
  38344. var templateX = new Int8Array(templateLength);
  38345. var templateY = new Int8Array(templateLength);
  38346. var changingTemplateEntries = [];
  38347. var reuseMask = 0, minX = 0, maxX = 0, minY = 0;
  38348. var c, k;
  38349. for (k = 0; k < templateLength; k++) {
  38350. templateX[k] = template[k].x;
  38351. templateY[k] = template[k].y;
  38352. minX = Math.min(minX, template[k].x);
  38353. maxX = Math.max(maxX, template[k].x);
  38354. minY = Math.min(minY, template[k].y);
  38355. // Check if the template pixel appears in two consecutive context labels,
  38356. // so it can be reused. Otherwise, we add it to the list of changing
  38357. // template entries.
  38358. if (k < templateLength - 1 &&
  38359. template[k].y === template[k + 1].y &&
  38360. template[k].x === template[k + 1].x - 1) {
  38361. reuseMask |= 1 << (templateLength - 1 - k);
  38362. } else {
  38363. changingTemplateEntries.push(k);
  38364. }
  38365. }
  38366. var changingEntriesLength = changingTemplateEntries.length;
  38367. var changingTemplateX = new Int8Array(changingEntriesLength);
  38368. var changingTemplateY = new Int8Array(changingEntriesLength);
  38369. var changingTemplateBit = new Uint16Array(changingEntriesLength);
  38370. for (c = 0; c < changingEntriesLength; c++) {
  38371. k = changingTemplateEntries[c];
  38372. changingTemplateX[c] = template[k].x;
  38373. changingTemplateY[c] = template[k].y;
  38374. changingTemplateBit[c] = 1 << (templateLength - 1 - k);
  38375. }
  38376. // Get the safe bounding box edges from the width, height, minX, maxX, minY
  38377. var sbb_left = -minX;
  38378. var sbb_top = -minY;
  38379. var sbb_right = width - maxX;
  38380. var pseudoPixelContext = ReusedContexts[templateIndex];
  38381. var row = new Uint8Array(width);
  38382. var bitmap = [];
  38383. var decoder = decodingContext.decoder;
  38384. var contexts = decodingContext.contextCache.getContexts('GB');
  38385. var ltp = 0, j, i0, j0, contextLabel = 0, bit, shift;
  38386. for (var i = 0; i < height; i++) {
  38387. if (prediction) {
  38388. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  38389. ltp ^= sltp;
  38390. if (ltp) {
  38391. bitmap.push(row); // duplicate previous row
  38392. continue;
  38393. }
  38394. }
  38395. row = new Uint8Array(row);
  38396. bitmap.push(row);
  38397. for (j = 0; j < width; j++) {
  38398. if (useskip && skip[i][j]) {
  38399. row[j] = 0;
  38400. continue;
  38401. }
  38402. // Are we in the middle of a scanline, so we can reuse contextLabel
  38403. // bits?
  38404. if (j >= sbb_left && j < sbb_right && i >= sbb_top) {
  38405. // If yes, we can just shift the bits that are reusable and only
  38406. // fetch the remaining ones.
  38407. contextLabel = (contextLabel << 1) & reuseMask;
  38408. for (k = 0; k < changingEntriesLength; k++) {
  38409. i0 = i + changingTemplateY[k];
  38410. j0 = j + changingTemplateX[k];
  38411. bit = bitmap[i0][j0];
  38412. if (bit) {
  38413. bit = changingTemplateBit[k];
  38414. contextLabel |= bit;
  38415. }
  38416. }
  38417. } else {
  38418. // compute the contextLabel from scratch
  38419. contextLabel = 0;
  38420. shift = templateLength - 1;
  38421. for (k = 0; k < templateLength; k++, shift--) {
  38422. j0 = j + templateX[k];
  38423. if (j0 >= 0 && j0 < width) {
  38424. i0 = i + templateY[k];
  38425. if (i0 >= 0) {
  38426. bit = bitmap[i0][j0];
  38427. if (bit) {
  38428. contextLabel |= bit << shift;
  38429. }
  38430. }
  38431. }
  38432. }
  38433. }
  38434. var pixel = decoder.readBit(contexts, contextLabel);
  38435. row[j] = pixel;
  38436. }
  38437. }
  38438. return bitmap;
  38439. }
  38440. // 6.3.2 Generic Refinement Region Decoding Procedure
  38441. function decodeRefinement(width, height, templateIndex, referenceBitmap,
  38442. offsetX, offsetY, prediction, at,
  38443. decodingContext) {
  38444. var codingTemplate = RefinementTemplates[templateIndex].coding;
  38445. if (templateIndex === 0) {
  38446. codingTemplate = codingTemplate.concat([at[0]]);
  38447. }
  38448. var codingTemplateLength = codingTemplate.length;
  38449. var codingTemplateX = new Int32Array(codingTemplateLength);
  38450. var codingTemplateY = new Int32Array(codingTemplateLength);
  38451. var k;
  38452. for (k = 0; k < codingTemplateLength; k++) {
  38453. codingTemplateX[k] = codingTemplate[k].x;
  38454. codingTemplateY[k] = codingTemplate[k].y;
  38455. }
  38456. var referenceTemplate = RefinementTemplates[templateIndex].reference;
  38457. if (templateIndex === 0) {
  38458. referenceTemplate = referenceTemplate.concat([at[1]]);
  38459. }
  38460. var referenceTemplateLength = referenceTemplate.length;
  38461. var referenceTemplateX = new Int32Array(referenceTemplateLength);
  38462. var referenceTemplateY = new Int32Array(referenceTemplateLength);
  38463. for (k = 0; k < referenceTemplateLength; k++) {
  38464. referenceTemplateX[k] = referenceTemplate[k].x;
  38465. referenceTemplateY[k] = referenceTemplate[k].y;
  38466. }
  38467. var referenceWidth = referenceBitmap[0].length;
  38468. var referenceHeight = referenceBitmap.length;
  38469. var pseudoPixelContext = RefinementReusedContexts[templateIndex];
  38470. var bitmap = [];
  38471. var decoder = decodingContext.decoder;
  38472. var contexts = decodingContext.contextCache.getContexts('GR');
  38473. var ltp = 0;
  38474. for (var i = 0; i < height; i++) {
  38475. if (prediction) {
  38476. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  38477. ltp ^= sltp;
  38478. if (ltp) {
  38479. error('JBIG2 error: prediction is not supported');
  38480. }
  38481. }
  38482. var row = new Uint8Array(width);
  38483. bitmap.push(row);
  38484. for (var j = 0; j < width; j++) {
  38485. var i0, j0;
  38486. var contextLabel = 0;
  38487. for (k = 0; k < codingTemplateLength; k++) {
  38488. i0 = i + codingTemplateY[k];
  38489. j0 = j + codingTemplateX[k];
  38490. if (i0 < 0 || j0 < 0 || j0 >= width) {
  38491. contextLabel <<= 1; // out of bound pixel
  38492. } else {
  38493. contextLabel = (contextLabel << 1) | bitmap[i0][j0];
  38494. }
  38495. }
  38496. for (k = 0; k < referenceTemplateLength; k++) {
  38497. i0 = i + referenceTemplateY[k] + offsetY;
  38498. j0 = j + referenceTemplateX[k] + offsetX;
  38499. if (i0 < 0 || i0 >= referenceHeight || j0 < 0 ||
  38500. j0 >= referenceWidth) {
  38501. contextLabel <<= 1; // out of bound pixel
  38502. } else {
  38503. contextLabel = (contextLabel << 1) | referenceBitmap[i0][j0];
  38504. }
  38505. }
  38506. var pixel = decoder.readBit(contexts, contextLabel);
  38507. row[j] = pixel;
  38508. }
  38509. }
  38510. return bitmap;
  38511. }
  38512. // 6.5.5 Decoding the symbol dictionary
  38513. function decodeSymbolDictionary(huffman, refinement, symbols,
  38514. numberOfNewSymbols, numberOfExportedSymbols,
  38515. huffmanTables, templateIndex, at,
  38516. refinementTemplateIndex, refinementAt,
  38517. decodingContext) {
  38518. if (huffman) {
  38519. error('JBIG2 error: huffman is not supported');
  38520. }
  38521. var newSymbols = [];
  38522. var currentHeight = 0;
  38523. var symbolCodeLength = log2(symbols.length + numberOfNewSymbols);
  38524. var decoder = decodingContext.decoder;
  38525. var contextCache = decodingContext.contextCache;
  38526. while (newSymbols.length < numberOfNewSymbols) {
  38527. var deltaHeight = decodeInteger(contextCache, 'IADH', decoder); // 6.5.6
  38528. currentHeight += deltaHeight;
  38529. var currentWidth = 0;
  38530. var totalWidth = 0;
  38531. while (true) {
  38532. var deltaWidth = decodeInteger(contextCache, 'IADW', decoder); // 6.5.7
  38533. if (deltaWidth === null) {
  38534. break; // OOB
  38535. }
  38536. currentWidth += deltaWidth;
  38537. totalWidth += currentWidth;
  38538. var bitmap;
  38539. if (refinement) {
  38540. // 6.5.8.2 Refinement/aggregate-coded symbol bitmap
  38541. var numberOfInstances = decodeInteger(contextCache, 'IAAI', decoder);
  38542. if (numberOfInstances > 1) {
  38543. bitmap = decodeTextRegion(huffman, refinement,
  38544. currentWidth, currentHeight, 0,
  38545. numberOfInstances, 1, //strip size
  38546. symbols.concat(newSymbols),
  38547. symbolCodeLength,
  38548. 0, //transposed
  38549. 0, //ds offset
  38550. 1, //top left 7.4.3.1.1
  38551. 0, //OR operator
  38552. huffmanTables,
  38553. refinementTemplateIndex, refinementAt,
  38554. decodingContext);
  38555. } else {
  38556. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  38557. var rdx = decodeInteger(contextCache, 'IARDX', decoder); // 6.4.11.3
  38558. var rdy = decodeInteger(contextCache, 'IARDY', decoder); // 6.4.11.4
  38559. var symbol = (symbolId < symbols.length ? symbols[symbolId] :
  38560. newSymbols[symbolId - symbols.length]);
  38561. bitmap = decodeRefinement(currentWidth, currentHeight,
  38562. refinementTemplateIndex, symbol, rdx, rdy, false, refinementAt,
  38563. decodingContext);
  38564. }
  38565. } else {
  38566. // 6.5.8.1 Direct-coded symbol bitmap
  38567. bitmap = decodeBitmap(false, currentWidth, currentHeight,
  38568. templateIndex, false, null, at, decodingContext);
  38569. }
  38570. newSymbols.push(bitmap);
  38571. }
  38572. }
  38573. // 6.5.10 Exported symbols
  38574. var exportedSymbols = [];
  38575. var flags = [], currentFlag = false;
  38576. var totalSymbolsLength = symbols.length + numberOfNewSymbols;
  38577. while (flags.length < totalSymbolsLength) {
  38578. var runLength = decodeInteger(contextCache, 'IAEX', decoder);
  38579. while (runLength--) {
  38580. flags.push(currentFlag);
  38581. }
  38582. currentFlag = !currentFlag;
  38583. }
  38584. for (var i = 0, ii = symbols.length; i < ii; i++) {
  38585. if (flags[i]) {
  38586. exportedSymbols.push(symbols[i]);
  38587. }
  38588. }
  38589. for (var j = 0; j < numberOfNewSymbols; i++, j++) {
  38590. if (flags[i]) {
  38591. exportedSymbols.push(newSymbols[j]);
  38592. }
  38593. }
  38594. return exportedSymbols;
  38595. }
  38596. function decodeTextRegion(huffman, refinement, width, height,
  38597. defaultPixelValue, numberOfSymbolInstances,
  38598. stripSize, inputSymbols, symbolCodeLength,
  38599. transposed, dsOffset, referenceCorner,
  38600. combinationOperator, huffmanTables,
  38601. refinementTemplateIndex, refinementAt,
  38602. decodingContext) {
  38603. if (huffman) {
  38604. error('JBIG2 error: huffman is not supported');
  38605. }
  38606. // Prepare bitmap
  38607. var bitmap = [];
  38608. var i, row;
  38609. for (i = 0; i < height; i++) {
  38610. row = new Uint8Array(width);
  38611. if (defaultPixelValue) {
  38612. for (var j = 0; j < width; j++) {
  38613. row[j] = defaultPixelValue;
  38614. }
  38615. }
  38616. bitmap.push(row);
  38617. }
  38618. var decoder = decodingContext.decoder;
  38619. var contextCache = decodingContext.contextCache;
  38620. var stripT = -decodeInteger(contextCache, 'IADT', decoder); // 6.4.6
  38621. var firstS = 0;
  38622. i = 0;
  38623. while (i < numberOfSymbolInstances) {
  38624. var deltaT = decodeInteger(contextCache, 'IADT', decoder); // 6.4.6
  38625. stripT += deltaT;
  38626. var deltaFirstS = decodeInteger(contextCache, 'IAFS', decoder); // 6.4.7
  38627. firstS += deltaFirstS;
  38628. var currentS = firstS;
  38629. do {
  38630. var currentT = (stripSize === 1 ? 0 :
  38631. decodeInteger(contextCache, 'IAIT', decoder)); // 6.4.9
  38632. var t = stripSize * stripT + currentT;
  38633. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  38634. var applyRefinement = (refinement &&
  38635. decodeInteger(contextCache, 'IARI', decoder));
  38636. var symbolBitmap = inputSymbols[symbolId];
  38637. var symbolWidth = symbolBitmap[0].length;
  38638. var symbolHeight = symbolBitmap.length;
  38639. if (applyRefinement) {
  38640. var rdw = decodeInteger(contextCache, 'IARDW', decoder); // 6.4.11.1
  38641. var rdh = decodeInteger(contextCache, 'IARDH', decoder); // 6.4.11.2
  38642. var rdx = decodeInteger(contextCache, 'IARDX', decoder); // 6.4.11.3
  38643. var rdy = decodeInteger(contextCache, 'IARDY', decoder); // 6.4.11.4
  38644. symbolWidth += rdw;
  38645. symbolHeight += rdh;
  38646. symbolBitmap = decodeRefinement(symbolWidth, symbolHeight,
  38647. refinementTemplateIndex, symbolBitmap, (rdw >> 1) + rdx,
  38648. (rdh >> 1) + rdy, false, refinementAt,
  38649. decodingContext);
  38650. }
  38651. var offsetT = t - ((referenceCorner & 1) ? 0 : symbolHeight);
  38652. var offsetS = currentS - ((referenceCorner & 2) ? symbolWidth : 0);
  38653. var s2, t2, symbolRow;
  38654. if (transposed) {
  38655. // Place Symbol Bitmap from T1,S1
  38656. for (s2 = 0; s2 < symbolHeight; s2++) {
  38657. row = bitmap[offsetS + s2];
  38658. if (!row) {
  38659. continue;
  38660. }
  38661. symbolRow = symbolBitmap[s2];
  38662. // To ignore Parts of Symbol bitmap which goes
  38663. // outside bitmap region
  38664. var maxWidth = Math.min(width - offsetT, symbolWidth);
  38665. switch (combinationOperator) {
  38666. case 0: // OR
  38667. for (t2 = 0; t2 < maxWidth; t2++) {
  38668. row[offsetT + t2] |= symbolRow[t2];
  38669. }
  38670. break;
  38671. case 2: // XOR
  38672. for (t2 = 0; t2 < maxWidth; t2++) {
  38673. row[offsetT + t2] ^= symbolRow[t2];
  38674. }
  38675. break;
  38676. default:
  38677. error('JBIG2 error: operator ' + combinationOperator +
  38678. ' is not supported');
  38679. }
  38680. }
  38681. currentS += symbolHeight - 1;
  38682. } else {
  38683. for (t2 = 0; t2 < symbolHeight; t2++) {
  38684. row = bitmap[offsetT + t2];
  38685. if (!row) {
  38686. continue;
  38687. }
  38688. symbolRow = symbolBitmap[t2];
  38689. switch (combinationOperator) {
  38690. case 0: // OR
  38691. for (s2 = 0; s2 < symbolWidth; s2++) {
  38692. row[offsetS + s2] |= symbolRow[s2];
  38693. }
  38694. break;
  38695. case 2: // XOR
  38696. for (s2 = 0; s2 < symbolWidth; s2++) {
  38697. row[offsetS + s2] ^= symbolRow[s2];
  38698. }
  38699. break;
  38700. default:
  38701. error('JBIG2 error: operator ' + combinationOperator +
  38702. ' is not supported');
  38703. }
  38704. }
  38705. currentS += symbolWidth - 1;
  38706. }
  38707. i++;
  38708. var deltaS = decodeInteger(contextCache, 'IADS', decoder); // 6.4.8
  38709. if (deltaS === null) {
  38710. break; // OOB
  38711. }
  38712. currentS += deltaS + dsOffset;
  38713. } while (true);
  38714. }
  38715. return bitmap;
  38716. }
  38717. function readSegmentHeader(data, start) {
  38718. var segmentHeader = {};
  38719. segmentHeader.number = readUint32(data, start);
  38720. var flags = data[start + 4];
  38721. var segmentType = flags & 0x3F;
  38722. if (!SegmentTypes[segmentType]) {
  38723. error('JBIG2 error: invalid segment type: ' + segmentType);
  38724. }
  38725. segmentHeader.type = segmentType;
  38726. segmentHeader.typeName = SegmentTypes[segmentType];
  38727. segmentHeader.deferredNonRetain = !!(flags & 0x80);
  38728. var pageAssociationFieldSize = !!(flags & 0x40);
  38729. var referredFlags = data[start + 5];
  38730. var referredToCount = (referredFlags >> 5) & 7;
  38731. var retainBits = [referredFlags & 31];
  38732. var position = start + 6;
  38733. if (referredFlags === 7) {
  38734. referredToCount = readUint32(data, position - 1) & 0x1FFFFFFF;
  38735. position += 3;
  38736. var bytes = (referredToCount + 7) >> 3;
  38737. retainBits[0] = data[position++];
  38738. while (--bytes > 0) {
  38739. retainBits.push(data[position++]);
  38740. }
  38741. } else if (referredFlags === 5 || referredFlags === 6) {
  38742. error('JBIG2 error: invalid referred-to flags');
  38743. }
  38744. segmentHeader.retainBits = retainBits;
  38745. var referredToSegmentNumberSize = (segmentHeader.number <= 256 ? 1 :
  38746. (segmentHeader.number <= 65536 ? 2 : 4));
  38747. var referredTo = [];
  38748. var i, ii;
  38749. for (i = 0; i < referredToCount; i++) {
  38750. var number = (referredToSegmentNumberSize === 1 ? data[position] :
  38751. (referredToSegmentNumberSize === 2 ? readUint16(data, position) :
  38752. readUint32(data, position)));
  38753. referredTo.push(number);
  38754. position += referredToSegmentNumberSize;
  38755. }
  38756. segmentHeader.referredTo = referredTo;
  38757. if (!pageAssociationFieldSize) {
  38758. segmentHeader.pageAssociation = data[position++];
  38759. } else {
  38760. segmentHeader.pageAssociation = readUint32(data, position);
  38761. position += 4;
  38762. }
  38763. segmentHeader.length = readUint32(data, position);
  38764. position += 4;
  38765. if (segmentHeader.length === 0xFFFFFFFF) {
  38766. // 7.2.7 Segment data length, unknown segment length
  38767. if (segmentType === 38) { // ImmediateGenericRegion
  38768. var genericRegionInfo = readRegionSegmentInformation(data, position);
  38769. var genericRegionSegmentFlags = data[position +
  38770. RegionSegmentInformationFieldLength];
  38771. var genericRegionMmr = !!(genericRegionSegmentFlags & 1);
  38772. // searching for the segment end
  38773. var searchPatternLength = 6;
  38774. var searchPattern = new Uint8Array(searchPatternLength);
  38775. if (!genericRegionMmr) {
  38776. searchPattern[0] = 0xFF;
  38777. searchPattern[1] = 0xAC;
  38778. }
  38779. searchPattern[2] = (genericRegionInfo.height >>> 24) & 0xFF;
  38780. searchPattern[3] = (genericRegionInfo.height >> 16) & 0xFF;
  38781. searchPattern[4] = (genericRegionInfo.height >> 8) & 0xFF;
  38782. searchPattern[5] = genericRegionInfo.height & 0xFF;
  38783. for (i = position, ii = data.length; i < ii; i++) {
  38784. var j = 0;
  38785. while (j < searchPatternLength && searchPattern[j] === data[i + j]) {
  38786. j++;
  38787. }
  38788. if (j === searchPatternLength) {
  38789. segmentHeader.length = i + searchPatternLength;
  38790. break;
  38791. }
  38792. }
  38793. if (segmentHeader.length === 0xFFFFFFFF) {
  38794. error('JBIG2 error: segment end was not found');
  38795. }
  38796. } else {
  38797. error('JBIG2 error: invalid unknown segment length');
  38798. }
  38799. }
  38800. segmentHeader.headerEnd = position;
  38801. return segmentHeader;
  38802. }
  38803. function readSegments(header, data, start, end) {
  38804. var segments = [];
  38805. var position = start;
  38806. while (position < end) {
  38807. var segmentHeader = readSegmentHeader(data, position);
  38808. position = segmentHeader.headerEnd;
  38809. var segment = {
  38810. header: segmentHeader,
  38811. data: data
  38812. };
  38813. if (!header.randomAccess) {
  38814. segment.start = position;
  38815. position += segmentHeader.length;
  38816. segment.end = position;
  38817. }
  38818. segments.push(segment);
  38819. if (segmentHeader.type === 51) {
  38820. break; // end of file is found
  38821. }
  38822. }
  38823. if (header.randomAccess) {
  38824. for (var i = 0, ii = segments.length; i < ii; i++) {
  38825. segments[i].start = position;
  38826. position += segments[i].header.length;
  38827. segments[i].end = position;
  38828. }
  38829. }
  38830. return segments;
  38831. }
  38832. // 7.4.1 Region segment information field
  38833. function readRegionSegmentInformation(data, start) {
  38834. return {
  38835. width: readUint32(data, start),
  38836. height: readUint32(data, start + 4),
  38837. x: readUint32(data, start + 8),
  38838. y: readUint32(data, start + 12),
  38839. combinationOperator: data[start + 16] & 7
  38840. };
  38841. }
  38842. var RegionSegmentInformationFieldLength = 17;
  38843. function processSegment(segment, visitor) {
  38844. var header = segment.header;
  38845. var data = segment.data, position = segment.start, end = segment.end;
  38846. var args, at, i, atLength;
  38847. switch (header.type) {
  38848. case 0: // SymbolDictionary
  38849. // 7.4.2 Symbol dictionary segment syntax
  38850. var dictionary = {};
  38851. var dictionaryFlags = readUint16(data, position); // 7.4.2.1.1
  38852. dictionary.huffman = !!(dictionaryFlags & 1);
  38853. dictionary.refinement = !!(dictionaryFlags & 2);
  38854. dictionary.huffmanDHSelector = (dictionaryFlags >> 2) & 3;
  38855. dictionary.huffmanDWSelector = (dictionaryFlags >> 4) & 3;
  38856. dictionary.bitmapSizeSelector = (dictionaryFlags >> 6) & 1;
  38857. dictionary.aggregationInstancesSelector = (dictionaryFlags >> 7) & 1;
  38858. dictionary.bitmapCodingContextUsed = !!(dictionaryFlags & 256);
  38859. dictionary.bitmapCodingContextRetained = !!(dictionaryFlags & 512);
  38860. dictionary.template = (dictionaryFlags >> 10) & 3;
  38861. dictionary.refinementTemplate = (dictionaryFlags >> 12) & 1;
  38862. position += 2;
  38863. if (!dictionary.huffman) {
  38864. atLength = dictionary.template === 0 ? 4 : 1;
  38865. at = [];
  38866. for (i = 0; i < atLength; i++) {
  38867. at.push({
  38868. x: readInt8(data, position),
  38869. y: readInt8(data, position + 1)
  38870. });
  38871. position += 2;
  38872. }
  38873. dictionary.at = at;
  38874. }
  38875. if (dictionary.refinement && !dictionary.refinementTemplate) {
  38876. at = [];
  38877. for (i = 0; i < 2; i++) {
  38878. at.push({
  38879. x: readInt8(data, position),
  38880. y: readInt8(data, position + 1)
  38881. });
  38882. position += 2;
  38883. }
  38884. dictionary.refinementAt = at;
  38885. }
  38886. dictionary.numberOfExportedSymbols = readUint32(data, position);
  38887. position += 4;
  38888. dictionary.numberOfNewSymbols = readUint32(data, position);
  38889. position += 4;
  38890. args = [dictionary, header.number, header.referredTo,
  38891. data, position, end];
  38892. break;
  38893. case 6: // ImmediateTextRegion
  38894. case 7: // ImmediateLosslessTextRegion
  38895. var textRegion = {};
  38896. textRegion.info = readRegionSegmentInformation(data, position);
  38897. position += RegionSegmentInformationFieldLength;
  38898. var textRegionSegmentFlags = readUint16(data, position);
  38899. position += 2;
  38900. textRegion.huffman = !!(textRegionSegmentFlags & 1);
  38901. textRegion.refinement = !!(textRegionSegmentFlags & 2);
  38902. textRegion.stripSize = 1 << ((textRegionSegmentFlags >> 2) & 3);
  38903. textRegion.referenceCorner = (textRegionSegmentFlags >> 4) & 3;
  38904. textRegion.transposed = !!(textRegionSegmentFlags & 64);
  38905. textRegion.combinationOperator = (textRegionSegmentFlags >> 7) & 3;
  38906. textRegion.defaultPixelValue = (textRegionSegmentFlags >> 9) & 1;
  38907. textRegion.dsOffset = (textRegionSegmentFlags << 17) >> 27;
  38908. textRegion.refinementTemplate = (textRegionSegmentFlags >> 15) & 1;
  38909. if (textRegion.huffman) {
  38910. var textRegionHuffmanFlags = readUint16(data, position);
  38911. position += 2;
  38912. textRegion.huffmanFS = (textRegionHuffmanFlags) & 3;
  38913. textRegion.huffmanDS = (textRegionHuffmanFlags >> 2) & 3;
  38914. textRegion.huffmanDT = (textRegionHuffmanFlags >> 4) & 3;
  38915. textRegion.huffmanRefinementDW = (textRegionHuffmanFlags >> 6) & 3;
  38916. textRegion.huffmanRefinementDH = (textRegionHuffmanFlags >> 8) & 3;
  38917. textRegion.huffmanRefinementDX = (textRegionHuffmanFlags >> 10) & 3;
  38918. textRegion.huffmanRefinementDY = (textRegionHuffmanFlags >> 12) & 3;
  38919. textRegion.huffmanRefinementSizeSelector =
  38920. !!(textRegionHuffmanFlags & 14);
  38921. }
  38922. if (textRegion.refinement && !textRegion.refinementTemplate) {
  38923. at = [];
  38924. for (i = 0; i < 2; i++) {
  38925. at.push({
  38926. x: readInt8(data, position),
  38927. y: readInt8(data, position + 1)
  38928. });
  38929. position += 2;
  38930. }
  38931. textRegion.refinementAt = at;
  38932. }
  38933. textRegion.numberOfSymbolInstances = readUint32(data, position);
  38934. position += 4;
  38935. // TODO 7.4.3.1.7 Symbol ID Huffman table decoding
  38936. if (textRegion.huffman) {
  38937. error('JBIG2 error: huffman is not supported');
  38938. }
  38939. args = [textRegion, header.referredTo, data, position, end];
  38940. break;
  38941. case 38: // ImmediateGenericRegion
  38942. case 39: // ImmediateLosslessGenericRegion
  38943. var genericRegion = {};
  38944. genericRegion.info = readRegionSegmentInformation(data, position);
  38945. position += RegionSegmentInformationFieldLength;
  38946. var genericRegionSegmentFlags = data[position++];
  38947. genericRegion.mmr = !!(genericRegionSegmentFlags & 1);
  38948. genericRegion.template = (genericRegionSegmentFlags >> 1) & 3;
  38949. genericRegion.prediction = !!(genericRegionSegmentFlags & 8);
  38950. if (!genericRegion.mmr) {
  38951. atLength = genericRegion.template === 0 ? 4 : 1;
  38952. at = [];
  38953. for (i = 0; i < atLength; i++) {
  38954. at.push({
  38955. x: readInt8(data, position),
  38956. y: readInt8(data, position + 1)
  38957. });
  38958. position += 2;
  38959. }
  38960. genericRegion.at = at;
  38961. }
  38962. args = [genericRegion, data, position, end];
  38963. break;
  38964. case 48: // PageInformation
  38965. var pageInfo = {
  38966. width: readUint32(data, position),
  38967. height: readUint32(data, position + 4),
  38968. resolutionX: readUint32(data, position + 8),
  38969. resolutionY: readUint32(data, position + 12)
  38970. };
  38971. if (pageInfo.height === 0xFFFFFFFF) {
  38972. delete pageInfo.height;
  38973. }
  38974. var pageSegmentFlags = data[position + 16];
  38975. var pageStripingInformatiom = readUint16(data, position + 17);
  38976. pageInfo.lossless = !!(pageSegmentFlags & 1);
  38977. pageInfo.refinement = !!(pageSegmentFlags & 2);
  38978. pageInfo.defaultPixelValue = (pageSegmentFlags >> 2) & 1;
  38979. pageInfo.combinationOperator = (pageSegmentFlags >> 3) & 3;
  38980. pageInfo.requiresBuffer = !!(pageSegmentFlags & 32);
  38981. pageInfo.combinationOperatorOverride = !!(pageSegmentFlags & 64);
  38982. args = [pageInfo];
  38983. break;
  38984. case 49: // EndOfPage
  38985. break;
  38986. case 50: // EndOfStripe
  38987. break;
  38988. case 51: // EndOfFile
  38989. break;
  38990. case 62: // 7.4.15 defines 2 extension types which
  38991. // are comments and can be ignored.
  38992. break;
  38993. default:
  38994. error('JBIG2 error: segment type ' + header.typeName + '(' +
  38995. header.type + ') is not implemented');
  38996. }
  38997. var callbackName = 'on' + header.typeName;
  38998. if (callbackName in visitor) {
  38999. visitor[callbackName].apply(visitor, args);
  39000. }
  39001. }
  39002. function processSegments(segments, visitor) {
  39003. for (var i = 0, ii = segments.length; i < ii; i++) {
  39004. processSegment(segments[i], visitor);
  39005. }
  39006. }
  39007. function parseJbig2(data, start, end) {
  39008. var position = start;
  39009. if (data[position] !== 0x97 || data[position + 1] !== 0x4A ||
  39010. data[position + 2] !== 0x42 || data[position + 3] !== 0x32 ||
  39011. data[position + 4] !== 0x0D || data[position + 5] !== 0x0A ||
  39012. data[position + 6] !== 0x1A || data[position + 7] !== 0x0A) {
  39013. error('JBIG2 error: invalid header');
  39014. }
  39015. var header = {};
  39016. position += 8;
  39017. var flags = data[position++];
  39018. header.randomAccess = !(flags & 1);
  39019. if (!(flags & 2)) {
  39020. header.numberOfPages = readUint32(data, position);
  39021. position += 4;
  39022. }
  39023. var segments = readSegments(header, data, position, end);
  39024. error('Not implemented');
  39025. // processSegments(segments, new SimpleSegmentVisitor());
  39026. }
  39027. function parseJbig2Chunks(chunks) {
  39028. var visitor = new SimpleSegmentVisitor();
  39029. for (var i = 0, ii = chunks.length; i < ii; i++) {
  39030. var chunk = chunks[i];
  39031. var segments = readSegments({}, chunk.data, chunk.start, chunk.end);
  39032. processSegments(segments, visitor);
  39033. }
  39034. return visitor.buffer;
  39035. }
  39036. function SimpleSegmentVisitor() {}
  39037. SimpleSegmentVisitor.prototype = {
  39038. onPageInformation: function SimpleSegmentVisitor_onPageInformation(info) {
  39039. this.currentPageInfo = info;
  39040. var rowSize = (info.width + 7) >> 3;
  39041. var buffer = new Uint8Array(rowSize * info.height);
  39042. // The contents of ArrayBuffers are initialized to 0.
  39043. // Fill the buffer with 0xFF only if info.defaultPixelValue is set
  39044. if (info.defaultPixelValue) {
  39045. for (var i = 0, ii = buffer.length; i < ii; i++) {
  39046. buffer[i] = 0xFF;
  39047. }
  39048. }
  39049. this.buffer = buffer;
  39050. },
  39051. drawBitmap: function SimpleSegmentVisitor_drawBitmap(regionInfo, bitmap) {
  39052. var pageInfo = this.currentPageInfo;
  39053. var width = regionInfo.width, height = regionInfo.height;
  39054. var rowSize = (pageInfo.width + 7) >> 3;
  39055. var combinationOperator = pageInfo.combinationOperatorOverride ?
  39056. regionInfo.combinationOperator : pageInfo.combinationOperator;
  39057. var buffer = this.buffer;
  39058. var mask0 = 128 >> (regionInfo.x & 7);
  39059. var offset0 = regionInfo.y * rowSize + (regionInfo.x >> 3);
  39060. var i, j, mask, offset;
  39061. switch (combinationOperator) {
  39062. case 0: // OR
  39063. for (i = 0; i < height; i++) {
  39064. mask = mask0;
  39065. offset = offset0;
  39066. for (j = 0; j < width; j++) {
  39067. if (bitmap[i][j]) {
  39068. buffer[offset] |= mask;
  39069. }
  39070. mask >>= 1;
  39071. if (!mask) {
  39072. mask = 128;
  39073. offset++;
  39074. }
  39075. }
  39076. offset0 += rowSize;
  39077. }
  39078. break;
  39079. case 2: // XOR
  39080. for (i = 0; i < height; i++) {
  39081. mask = mask0;
  39082. offset = offset0;
  39083. for (j = 0; j < width; j++) {
  39084. if (bitmap[i][j]) {
  39085. buffer[offset] ^= mask;
  39086. }
  39087. mask >>= 1;
  39088. if (!mask) {
  39089. mask = 128;
  39090. offset++;
  39091. }
  39092. }
  39093. offset0 += rowSize;
  39094. }
  39095. break;
  39096. default:
  39097. error('JBIG2 error: operator ' + combinationOperator +
  39098. ' is not supported');
  39099. }
  39100. },
  39101. onImmediateGenericRegion:
  39102. function SimpleSegmentVisitor_onImmediateGenericRegion(region, data,
  39103. start, end) {
  39104. var regionInfo = region.info;
  39105. var decodingContext = new DecodingContext(data, start, end);
  39106. var bitmap = decodeBitmap(region.mmr, regionInfo.width, regionInfo.height,
  39107. region.template, region.prediction, null,
  39108. region.at, decodingContext);
  39109. this.drawBitmap(regionInfo, bitmap);
  39110. },
  39111. onImmediateLosslessGenericRegion:
  39112. function SimpleSegmentVisitor_onImmediateLosslessGenericRegion() {
  39113. this.onImmediateGenericRegion.apply(this, arguments);
  39114. },
  39115. onSymbolDictionary:
  39116. function SimpleSegmentVisitor_onSymbolDictionary(dictionary,
  39117. currentSegment,
  39118. referredSegments,
  39119. data, start, end) {
  39120. var huffmanTables;
  39121. if (dictionary.huffman) {
  39122. error('JBIG2 error: huffman is not supported');
  39123. }
  39124. // Combines exported symbols from all referred segments
  39125. var symbols = this.symbols;
  39126. if (!symbols) {
  39127. this.symbols = symbols = {};
  39128. }
  39129. var inputSymbols = [];
  39130. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  39131. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  39132. }
  39133. var decodingContext = new DecodingContext(data, start, end);
  39134. symbols[currentSegment] = decodeSymbolDictionary(dictionary.huffman,
  39135. dictionary.refinement, inputSymbols, dictionary.numberOfNewSymbols,
  39136. dictionary.numberOfExportedSymbols, huffmanTables,
  39137. dictionary.template, dictionary.at,
  39138. dictionary.refinementTemplate, dictionary.refinementAt,
  39139. decodingContext);
  39140. },
  39141. onImmediateTextRegion:
  39142. function SimpleSegmentVisitor_onImmediateTextRegion(region,
  39143. referredSegments,
  39144. data, start, end) {
  39145. var regionInfo = region.info;
  39146. var huffmanTables;
  39147. // Combines exported symbols from all referred segments
  39148. var symbols = this.symbols;
  39149. var inputSymbols = [];
  39150. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  39151. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  39152. }
  39153. var symbolCodeLength = log2(inputSymbols.length);
  39154. var decodingContext = new DecodingContext(data, start, end);
  39155. var bitmap = decodeTextRegion(region.huffman, region.refinement,
  39156. regionInfo.width, regionInfo.height, region.defaultPixelValue,
  39157. region.numberOfSymbolInstances, region.stripSize, inputSymbols,
  39158. symbolCodeLength, region.transposed, region.dsOffset,
  39159. region.referenceCorner, region.combinationOperator, huffmanTables,
  39160. region.refinementTemplate, region.refinementAt, decodingContext);
  39161. this.drawBitmap(regionInfo, bitmap);
  39162. },
  39163. onImmediateLosslessTextRegion:
  39164. function SimpleSegmentVisitor_onImmediateLosslessTextRegion() {
  39165. this.onImmediateTextRegion.apply(this, arguments);
  39166. }
  39167. };
  39168. function Jbig2Image() {}
  39169. Jbig2Image.prototype = {
  39170. parseChunks: function Jbig2Image_parseChunks(chunks) {
  39171. return parseJbig2Chunks(chunks);
  39172. }
  39173. };
  39174. return Jbig2Image;
  39175. })();
  39176. var bidi = PDFJS.bidi = (function bidiClosure() {
  39177. // Character types for symbols from 0000 to 00FF.
  39178. var baseTypes = [
  39179. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'S', 'B', 'S', 'WS',
  39180. 'B', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  39181. 'BN', 'BN', 'B', 'B', 'B', 'S', 'WS', 'ON', 'ON', 'ET', 'ET', 'ET', 'ON',
  39182. 'ON', 'ON', 'ON', 'ON', 'ON', 'CS', 'ON', 'CS', 'ON', 'EN', 'EN', 'EN',
  39183. 'EN', 'EN', 'EN', 'EN', 'EN', 'EN', 'EN', 'ON', 'ON', 'ON', 'ON', 'ON',
  39184. 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  39185. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'ON', 'ON',
  39186. 'ON', 'ON', 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  39187. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  39188. 'L', 'ON', 'ON', 'ON', 'ON', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'B', 'BN',
  39189. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  39190. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  39191. 'BN', 'CS', 'ON', 'ET', 'ET', 'ET', 'ET', 'ON', 'ON', 'ON', 'ON', 'L', 'ON',
  39192. 'ON', 'ON', 'ON', 'ON', 'ET', 'ET', 'EN', 'EN', 'ON', 'L', 'ON', 'ON', 'ON',
  39193. 'EN', 'L', 'ON', 'ON', 'ON', 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  39194. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  39195. 'L', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  39196. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  39197. 'L', 'L', 'L', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L'
  39198. ];
  39199. // Character types for symbols from 0600 to 06FF
  39200. var arabicTypes = [
  39201. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  39202. 'CS', 'AL', 'ON', 'ON', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'AL',
  39203. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  39204. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  39205. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  39206. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  39207. 'AL', 'AL', 'AL', 'AL', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM',
  39208. 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'AL', 'AL', 'AL', 'AL',
  39209. 'AL', 'AL', 'AL', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN',
  39210. 'AN', 'ET', 'AN', 'AN', 'AL', 'AL', 'AL', 'NSM', 'AL', 'AL', 'AL', 'AL',
  39211. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  39212. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  39213. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  39214. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  39215. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  39216. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  39217. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  39218. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  39219. 'AL', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM',
  39220. 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'ON', 'NSM',
  39221. 'NSM', 'NSM', 'NSM', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  39222. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL'
  39223. ];
  39224. function isOdd(i) {
  39225. return (i & 1) !== 0;
  39226. }
  39227. function isEven(i) {
  39228. return (i & 1) === 0;
  39229. }
  39230. function findUnequal(arr, start, value) {
  39231. for (var j = start, jj = arr.length; j < jj; ++j) {
  39232. if (arr[j] !== value) {
  39233. return j;
  39234. }
  39235. }
  39236. return j;
  39237. }
  39238. function setValues(arr, start, end, value) {
  39239. for (var j = start; j < end; ++j) {
  39240. arr[j] = value;
  39241. }
  39242. }
  39243. function reverseValues(arr, start, end) {
  39244. for (var i = start, j = end - 1; i < j; ++i, --j) {
  39245. var temp = arr[i];
  39246. arr[i] = arr[j];
  39247. arr[j] = temp;
  39248. }
  39249. }
  39250. function createBidiText(str, isLTR, vertical) {
  39251. return {
  39252. str: str,
  39253. dir: (vertical ? 'ttb' : (isLTR ? 'ltr' : 'rtl'))
  39254. };
  39255. }
  39256. // These are used in bidi(), which is called frequently. We re-use them on
  39257. // each call to avoid unnecessary allocations.
  39258. var chars = [];
  39259. var types = [];
  39260. function bidi(str, startLevel, vertical) {
  39261. var isLTR = true;
  39262. var strLength = str.length;
  39263. if (strLength === 0 || vertical) {
  39264. return createBidiText(str, isLTR, vertical);
  39265. }
  39266. // Get types and fill arrays
  39267. chars.length = strLength;
  39268. types.length = strLength;
  39269. var numBidi = 0;
  39270. var i, ii;
  39271. for (i = 0; i < strLength; ++i) {
  39272. chars[i] = str.charAt(i);
  39273. var charCode = str.charCodeAt(i);
  39274. var charType = 'L';
  39275. if (charCode <= 0x00ff) {
  39276. charType = baseTypes[charCode];
  39277. } else if (0x0590 <= charCode && charCode <= 0x05f4) {
  39278. charType = 'R';
  39279. } else if (0x0600 <= charCode && charCode <= 0x06ff) {
  39280. charType = arabicTypes[charCode & 0xff];
  39281. } else if (0x0700 <= charCode && charCode <= 0x08AC) {
  39282. charType = 'AL';
  39283. }
  39284. if (charType === 'R' || charType === 'AL' || charType === 'AN') {
  39285. numBidi++;
  39286. }
  39287. types[i] = charType;
  39288. }
  39289. // Detect the bidi method
  39290. // - If there are no rtl characters then no bidi needed
  39291. // - If less than 30% chars are rtl then string is primarily ltr
  39292. // - If more than 30% chars are rtl then string is primarily rtl
  39293. if (numBidi === 0) {
  39294. isLTR = true;
  39295. return createBidiText(str, isLTR);
  39296. }
  39297. if (startLevel === -1) {
  39298. if ((strLength / numBidi) < 0.3) {
  39299. isLTR = true;
  39300. startLevel = 0;
  39301. } else {
  39302. isLTR = false;
  39303. startLevel = 1;
  39304. }
  39305. }
  39306. var levels = [];
  39307. for (i = 0; i < strLength; ++i) {
  39308. levels[i] = startLevel;
  39309. }
  39310. /*
  39311. X1-X10: skip most of this, since we are NOT doing the embeddings.
  39312. */
  39313. var e = (isOdd(startLevel) ? 'R' : 'L');
  39314. var sor = e;
  39315. var eor = sor;
  39316. /*
  39317. W1. Examine each non-spacing mark (NSM) in the level run, and change the
  39318. type of the NSM to the type of the previous character. If the NSM is at the
  39319. start of the level run, it will get the type of sor.
  39320. */
  39321. var lastType = sor;
  39322. for (i = 0; i < strLength; ++i) {
  39323. if (types[i] === 'NSM') {
  39324. types[i] = lastType;
  39325. } else {
  39326. lastType = types[i];
  39327. }
  39328. }
  39329. /*
  39330. W2. Search backwards from each instance of a European number until the
  39331. first strong type (R, L, AL, or sor) is found. If an AL is found, change
  39332. the type of the European number to Arabic number.
  39333. */
  39334. lastType = sor;
  39335. var t;
  39336. for (i = 0; i < strLength; ++i) {
  39337. t = types[i];
  39338. if (t === 'EN') {
  39339. types[i] = (lastType === 'AL') ? 'AN' : 'EN';
  39340. } else if (t === 'R' || t === 'L' || t === 'AL') {
  39341. lastType = t;
  39342. }
  39343. }
  39344. /*
  39345. W3. Change all ALs to R.
  39346. */
  39347. for (i = 0; i < strLength; ++i) {
  39348. t = types[i];
  39349. if (t === 'AL') {
  39350. types[i] = 'R';
  39351. }
  39352. }
  39353. /*
  39354. W4. A single European separator between two European numbers changes to a
  39355. European number. A single common separator between two numbers of the same
  39356. type changes to that type:
  39357. */
  39358. for (i = 1; i < strLength - 1; ++i) {
  39359. if (types[i] === 'ES' && types[i - 1] === 'EN' && types[i + 1] === 'EN') {
  39360. types[i] = 'EN';
  39361. }
  39362. if (types[i] === 'CS' &&
  39363. (types[i - 1] === 'EN' || types[i - 1] === 'AN') &&
  39364. types[i + 1] === types[i - 1]) {
  39365. types[i] = types[i - 1];
  39366. }
  39367. }
  39368. /*
  39369. W5. A sequence of European terminators adjacent to European numbers changes
  39370. to all European numbers:
  39371. */
  39372. for (i = 0; i < strLength; ++i) {
  39373. if (types[i] === 'EN') {
  39374. // do before
  39375. var j;
  39376. for (j = i - 1; j >= 0; --j) {
  39377. if (types[j] !== 'ET') {
  39378. break;
  39379. }
  39380. types[j] = 'EN';
  39381. }
  39382. // do after
  39383. for (j = i + 1; j < strLength; --j) {
  39384. if (types[j] !== 'ET') {
  39385. break;
  39386. }
  39387. types[j] = 'EN';
  39388. }
  39389. }
  39390. }
  39391. /*
  39392. W6. Otherwise, separators and terminators change to Other Neutral:
  39393. */
  39394. for (i = 0; i < strLength; ++i) {
  39395. t = types[i];
  39396. if (t === 'WS' || t === 'ES' || t === 'ET' || t === 'CS') {
  39397. types[i] = 'ON';
  39398. }
  39399. }
  39400. /*
  39401. W7. Search backwards from each instance of a European number until the
  39402. first strong type (R, L, or sor) is found. If an L is found, then change
  39403. the type of the European number to L.
  39404. */
  39405. lastType = sor;
  39406. for (i = 0; i < strLength; ++i) {
  39407. t = types[i];
  39408. if (t === 'EN') {
  39409. types[i] = ((lastType === 'L') ? 'L' : 'EN');
  39410. } else if (t === 'R' || t === 'L') {
  39411. lastType = t;
  39412. }
  39413. }
  39414. /*
  39415. N1. A sequence of neutrals takes the direction of the surrounding strong
  39416. text if the text on both sides has the same direction. European and Arabic
  39417. numbers are treated as though they were R. Start-of-level-run (sor) and
  39418. end-of-level-run (eor) are used at level run boundaries.
  39419. */
  39420. for (i = 0; i < strLength; ++i) {
  39421. if (types[i] === 'ON') {
  39422. var end = findUnequal(types, i + 1, 'ON');
  39423. var before = sor;
  39424. if (i > 0) {
  39425. before = types[i - 1];
  39426. }
  39427. var after = eor;
  39428. if (end + 1 < strLength) {
  39429. after = types[end + 1];
  39430. }
  39431. if (before !== 'L') {
  39432. before = 'R';
  39433. }
  39434. if (after !== 'L') {
  39435. after = 'R';
  39436. }
  39437. if (before === after) {
  39438. setValues(types, i, end, before);
  39439. }
  39440. i = end - 1; // reset to end (-1 so next iteration is ok)
  39441. }
  39442. }
  39443. /*
  39444. N2. Any remaining neutrals take the embedding direction.
  39445. */
  39446. for (i = 0; i < strLength; ++i) {
  39447. if (types[i] === 'ON') {
  39448. types[i] = e;
  39449. }
  39450. }
  39451. /*
  39452. I1. For all characters with an even (left-to-right) embedding direction,
  39453. those of type R go up one level and those of type AN or EN go up two
  39454. levels.
  39455. I2. For all characters with an odd (right-to-left) embedding direction,
  39456. those of type L, EN or AN go up one level.
  39457. */
  39458. for (i = 0; i < strLength; ++i) {
  39459. t = types[i];
  39460. if (isEven(levels[i])) {
  39461. if (t === 'R') {
  39462. levels[i] += 1;
  39463. } else if (t === 'AN' || t === 'EN') {
  39464. levels[i] += 2;
  39465. }
  39466. } else { // isOdd
  39467. if (t === 'L' || t === 'AN' || t === 'EN') {
  39468. levels[i] += 1;
  39469. }
  39470. }
  39471. }
  39472. /*
  39473. L1. On each line, reset the embedding level of the following characters to
  39474. the paragraph embedding level:
  39475. segment separators,
  39476. paragraph separators,
  39477. any sequence of whitespace characters preceding a segment separator or
  39478. paragraph separator, and any sequence of white space characters at the end
  39479. of the line.
  39480. */
  39481. // don't bother as text is only single line
  39482. /*
  39483. L2. From the highest level found in the text to the lowest odd level on
  39484. each line, reverse any contiguous sequence of characters that are at that
  39485. level or higher.
  39486. */
  39487. // find highest level & lowest odd level
  39488. var highestLevel = -1;
  39489. var lowestOddLevel = 99;
  39490. var level;
  39491. for (i = 0, ii = levels.length; i < ii; ++i) {
  39492. level = levels[i];
  39493. if (highestLevel < level) {
  39494. highestLevel = level;
  39495. }
  39496. if (lowestOddLevel > level && isOdd(level)) {
  39497. lowestOddLevel = level;
  39498. }
  39499. }
  39500. // now reverse between those limits
  39501. for (level = highestLevel; level >= lowestOddLevel; --level) {
  39502. // find segments to reverse
  39503. var start = -1;
  39504. for (i = 0, ii = levels.length; i < ii; ++i) {
  39505. if (levels[i] < level) {
  39506. if (start >= 0) {
  39507. reverseValues(chars, start, i);
  39508. start = -1;
  39509. }
  39510. } else if (start < 0) {
  39511. start = i;
  39512. }
  39513. }
  39514. if (start >= 0) {
  39515. reverseValues(chars, start, levels.length);
  39516. }
  39517. }
  39518. /*
  39519. L3. Combining marks applied to a right-to-left base character will at this
  39520. point precede their base character. If the rendering engine expects them to
  39521. follow the base characters in the final display process, then the ordering
  39522. of the marks and the base character must be reversed.
  39523. */
  39524. // don't bother for now
  39525. /*
  39526. L4. A character that possesses the mirrored property as specified by
  39527. Section 4.7, Mirrored, must be depicted by a mirrored glyph if the resolved
  39528. directionality of that character is R.
  39529. */
  39530. // don't mirror as characters are already mirrored in the pdf
  39531. // Finally, return string
  39532. var result = '';
  39533. for (i = 0, ii = chars.length; i < ii; ++i) {
  39534. var ch = chars[i];
  39535. if (ch !== '<' && ch !== '>') {
  39536. result += ch;
  39537. }
  39538. }
  39539. return createBidiText(result, isLTR);
  39540. }
  39541. return bidi;
  39542. })();
  39543. /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  39544. /* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
  39545. /* Copyright 2014 Opera Software ASA
  39546. *
  39547. * Licensed under the Apache License, Version 2.0 (the "License");
  39548. * you may not use this file except in compliance with the License.
  39549. * You may obtain a copy of the License at
  39550. *
  39551. * http://www.apache.org/licenses/LICENSE-2.0
  39552. *
  39553. * Unless required by applicable law or agreed to in writing, software
  39554. * distributed under the License is distributed on an "AS IS" BASIS,
  39555. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  39556. * See the License for the specific language governing permissions and
  39557. * limitations under the License.
  39558. *
  39559. *
  39560. * Based on https://code.google.com/p/smhasher/wiki/MurmurHash3.
  39561. * Hashes roughly 100 KB per millisecond on i7 3.4 GHz.
  39562. */
  39563. /* globals Uint32ArrayView */
  39564. 'use strict';
  39565. var MurmurHash3_64 = (function MurmurHash3_64Closure (seed) {
  39566. // Workaround for missing math precison in JS.
  39567. var MASK_HIGH = 0xffff0000;
  39568. var MASK_LOW = 0xffff;
  39569. function MurmurHash3_64 (seed) {
  39570. var SEED = 0xc3d2e1f0;
  39571. this.h1 = seed ? seed & 0xffffffff : SEED;
  39572. this.h2 = seed ? seed & 0xffffffff : SEED;
  39573. }
  39574. var alwaysUseUint32ArrayView = false;
  39575. // old webkits have issues with non-aligned arrays
  39576. try {
  39577. new Uint32Array(new Uint8Array(5).buffer, 0, 1);
  39578. } catch (e) {
  39579. alwaysUseUint32ArrayView = true;
  39580. }
  39581. MurmurHash3_64.prototype = {
  39582. update: function MurmurHash3_64_update(input) {
  39583. var useUint32ArrayView = alwaysUseUint32ArrayView;
  39584. var i;
  39585. if (typeof input === 'string') {
  39586. var data = new Uint8Array(input.length * 2);
  39587. var length = 0;
  39588. for (i = 0; i < input.length; i++) {
  39589. var code = input.charCodeAt(i);
  39590. if (code <= 0xff) {
  39591. data[length++] = code;
  39592. }
  39593. else {
  39594. data[length++] = code >>> 8;
  39595. data[length++] = code & 0xff;
  39596. }
  39597. }
  39598. } else if (input instanceof Uint8Array) {
  39599. data = input;
  39600. length = data.length;
  39601. } else if (typeof input === 'object' && ('length' in input)) {
  39602. // processing regular arrays as well, e.g. for IE9
  39603. data = input;
  39604. length = data.length;
  39605. useUint32ArrayView = true;
  39606. } else {
  39607. throw new Error('Wrong data format in MurmurHash3_64_update. ' +
  39608. 'Input must be a string or array.');
  39609. }
  39610. var blockCounts = length >> 2;
  39611. var tailLength = length - blockCounts * 4;
  39612. // we don't care about endianness here
  39613. var dataUint32 = useUint32ArrayView ?
  39614. new Uint32ArrayView(data, blockCounts) :
  39615. new Uint32Array(data.buffer, 0, blockCounts);
  39616. var k1 = 0;
  39617. var k2 = 0;
  39618. var h1 = this.h1;
  39619. var h2 = this.h2;
  39620. var C1 = 0xcc9e2d51;
  39621. var C2 = 0x1b873593;
  39622. var C1_LOW = C1 & MASK_LOW;
  39623. var C2_LOW = C2 & MASK_LOW;
  39624. for (i = 0; i < blockCounts; i++) {
  39625. if (i & 1) {
  39626. k1 = dataUint32[i];
  39627. k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);
  39628. k1 = k1 << 15 | k1 >>> 17;
  39629. k1 = (k1 * C2 & MASK_HIGH) | (k1 * C2_LOW & MASK_LOW);
  39630. h1 ^= k1;
  39631. h1 = h1 << 13 | h1 >>> 19;
  39632. h1 = h1 * 5 + 0xe6546b64;
  39633. } else {
  39634. k2 = dataUint32[i];
  39635. k2 = (k2 * C1 & MASK_HIGH) | (k2 * C1_LOW & MASK_LOW);
  39636. k2 = k2 << 15 | k2 >>> 17;
  39637. k2 = (k2 * C2 & MASK_HIGH) | (k2 * C2_LOW & MASK_LOW);
  39638. h2 ^= k2;
  39639. h2 = h2 << 13 | h2 >>> 19;
  39640. h2 = h2 * 5 + 0xe6546b64;
  39641. }
  39642. }
  39643. k1 = 0;
  39644. switch (tailLength) {
  39645. case 3:
  39646. k1 ^= data[blockCounts * 4 + 2] << 16;
  39647. /* falls through */
  39648. case 2:
  39649. k1 ^= data[blockCounts * 4 + 1] << 8;
  39650. /* falls through */
  39651. case 1:
  39652. k1 ^= data[blockCounts * 4];
  39653. /* falls through */
  39654. k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);
  39655. k1 = k1 << 15 | k1 >>> 17;
  39656. k1 = (k1 * C2 & MASK_HIGH) | (k1 * C2_LOW & MASK_LOW);
  39657. if (blockCounts & 1) {
  39658. h1 ^= k1;
  39659. } else {
  39660. h2 ^= k1;
  39661. }
  39662. }
  39663. this.h1 = h1;
  39664. this.h2 = h2;
  39665. return this;
  39666. },
  39667. hexdigest: function MurmurHash3_64_hexdigest () {
  39668. var h1 = this.h1;
  39669. var h2 = this.h2;
  39670. h1 ^= h2 >>> 1;
  39671. h1 = (h1 * 0xed558ccd & MASK_HIGH) | (h1 * 0x8ccd & MASK_LOW);
  39672. h2 = (h2 * 0xff51afd7 & MASK_HIGH) |
  39673. (((h2 << 16 | h1 >>> 16) * 0xafd7ed55 & MASK_HIGH) >>> 16);
  39674. h1 ^= h2 >>> 1;
  39675. h1 = (h1 * 0x1a85ec53 & MASK_HIGH) | (h1 * 0xec53 & MASK_LOW);
  39676. h2 = (h2 * 0xc4ceb9fe & MASK_HIGH) |
  39677. (((h2 << 16 | h1 >>> 16) * 0xb9fe1a85 & MASK_HIGH) >>> 16);
  39678. h1 ^= h2 >>> 1;
  39679. for (var i = 0, arr = [h1, h2], str = ''; i < arr.length; i++) {
  39680. var hex = (arr[i] >>> 0).toString(16);
  39681. while (hex.length < 8) {
  39682. hex = '0' + hex;
  39683. }
  39684. str += hex;
  39685. }
  39686. return str;
  39687. }
  39688. };
  39689. return MurmurHash3_64;
  39690. })();
  39691. }).call((typeof window === 'undefined') ? this : window);
  39692. if (!PDFJS.workerSrc && typeof document !== 'undefined') {
  39693. // workerSrc is not set -- using last script url to define default location
  39694. PDFJS.workerSrc = (function () {
  39695. 'use strict';
  39696. var scriptTagContainer = document.body ||
  39697. document.getElementsByTagName('head')[0];
  39698. var pdfjsSrc = scriptTagContainer.lastChild.src;
  39699. return pdfjsSrc && pdfjsSrc.replace(/\.js$/i, '.worker.js');
  39700. })();
  39701. }