pdf.combined.js 1.5 MB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079280802808128082280832808428085280862808728088280892809028091280922809328094280952809628097280982809928100281012810228103281042810528106281072810828109281102811128112281132811428115281162811728118281192812028121281222812328124281252812628127281282812928130281312813228133281342813528136281372813828139281402814128142281432814428145281462814728148281492815028151281522815328154281552815628157281582815928160281612816228163281642816528166281672816828169281702817128172281732817428175281762817728178281792818028181281822818328184281852818628187281882818928190281912819228193281942819528196281972819828199282002820128202282032820428205282062820728208282092821028211282122821328214282152821628217282182821928220282212822228223282242822528226282272822828229282302823128232282332823428235282362823728238282392824028241282422824328244282452824628247282482824928250282512825228253282542825528256282572825828259282602826128262282632826428265282662826728268282692827028271282722827328274282752827628277282782827928280282812828228283282842828528286282872828828289282902829128292282932829428295282962829728298282992830028301283022830328304283052830628307283082830928310283112831228313283142831528316283172831828319283202832128322283232832428325283262832728328283292833028331283322833328334283352833628337283382833928340283412834228343283442834528346283472834828349283502835128352283532835428355283562835728358283592836028361283622836328364283652836628367283682836928370283712837228373283742837528376283772837828379283802838128382283832838428385283862838728388283892839028391283922839328394283952839628397283982839928400284012840228403284042840528406284072840828409284102841128412284132841428415284162841728418284192842028421284222842328424284252842628427284282842928430284312843228433284342843528436284372843828439284402844128442284432844428445284462844728448284492845028451284522845328454284552845628457284582845928460284612846228463284642846528466284672846828469284702847128472284732847428475284762847728478284792848028481284822848328484284852848628487284882848928490284912849228493284942849528496284972849828499285002850128502285032850428505285062850728508285092851028511285122851328514285152851628517285182851928520285212852228523285242852528526285272852828529285302853128532285332853428535285362853728538285392854028541285422854328544285452854628547285482854928550285512855228553285542855528556285572855828559285602856128562285632856428565285662856728568285692857028571285722857328574285752857628577285782857928580285812858228583285842858528586285872858828589285902859128592285932859428595285962859728598285992860028601286022860328604286052860628607286082860928610286112861228613286142861528616286172861828619286202862128622286232862428625286262862728628286292863028631286322863328634286352863628637286382863928640286412864228643286442864528646286472864828649286502865128652286532865428655286562865728658286592866028661286622866328664286652866628667286682866928670286712867228673286742867528676286772867828679286802868128682286832868428685286862868728688286892869028691286922869328694286952869628697286982869928700287012870228703287042870528706287072870828709287102871128712287132871428715287162871728718287192872028721287222872328724287252872628727287282872928730287312873228733287342873528736287372873828739287402874128742287432874428745287462874728748287492875028751287522875328754287552875628757287582875928760287612876228763287642876528766287672876828769287702877128772287732877428775287762877728778287792878028781287822878328784287852878628787287882878928790287912879228793287942879528796287972879828799288002880128802288032880428805288062880728808288092881028811288122881328814288152881628817288182881928820288212882228823288242882528826288272882828829288302883128832288332883428835288362883728838288392884028841288422884328844288452884628847288482884928850288512885228853288542885528856288572885828859288602886128862288632886428865288662886728868288692887028871288722887328874288752887628877288782887928880288812888228883288842888528886288872888828889288902889128892288932889428895288962889728898288992890028901289022890328904289052890628907289082890928910289112891228913289142891528916289172891828919289202892128922289232892428925289262892728928289292893028931289322893328934289352893628937289382893928940289412894228943289442894528946289472894828949289502895128952289532895428955289562895728958289592896028961289622896328964289652896628967289682896928970289712897228973289742897528976289772897828979289802898128982289832898428985289862898728988289892899028991289922899328994289952899628997289982899929000290012900229003290042900529006290072900829009290102901129012290132901429015290162901729018290192902029021290222902329024290252902629027290282902929030290312903229033290342903529036290372903829039290402904129042290432904429045290462904729048290492905029051290522905329054290552905629057290582905929060290612906229063290642906529066290672906829069290702907129072290732907429075290762907729078290792908029081290822908329084290852908629087290882908929090290912909229093290942909529096290972909829099291002910129102291032910429105291062910729108291092911029111291122911329114291152911629117291182911929120291212912229123291242912529126291272912829129291302913129132291332913429135291362913729138291392914029141291422914329144291452914629147291482914929150291512915229153291542915529156291572915829159291602916129162291632916429165291662916729168291692917029171291722917329174291752917629177291782917929180291812918229183291842918529186291872918829189291902919129192291932919429195291962919729198291992920029201292022920329204292052920629207292082920929210292112921229213292142921529216292172921829219292202922129222292232922429225292262922729228292292923029231292322923329234292352923629237292382923929240292412924229243292442924529246292472924829249292502925129252292532925429255292562925729258292592926029261292622926329264292652926629267292682926929270292712927229273292742927529276292772927829279292802928129282292832928429285292862928729288292892929029291292922929329294292952929629297292982929929300293012930229303293042930529306293072930829309293102931129312293132931429315293162931729318293192932029321293222932329324293252932629327293282932929330293312933229333293342933529336293372933829339293402934129342293432934429345293462934729348293492935029351293522935329354293552935629357293582935929360293612936229363293642936529366293672936829369293702937129372293732937429375293762937729378293792938029381293822938329384293852938629387293882938929390293912939229393293942939529396293972939829399294002940129402294032940429405294062940729408294092941029411294122941329414294152941629417294182941929420294212942229423294242942529426294272942829429294302943129432294332943429435294362943729438294392944029441294422944329444294452944629447294482944929450294512945229453294542945529456294572945829459294602946129462294632946429465294662946729468294692947029471294722947329474294752947629477294782947929480294812948229483294842948529486294872948829489294902949129492294932949429495294962949729498294992950029501295022950329504295052950629507295082950929510295112951229513295142951529516295172951829519295202952129522295232952429525295262952729528295292953029531295322953329534295352953629537295382953929540295412954229543295442954529546295472954829549295502955129552295532955429555295562955729558295592956029561295622956329564295652956629567295682956929570295712957229573295742957529576295772957829579295802958129582295832958429585295862958729588295892959029591295922959329594295952959629597295982959929600296012960229603296042960529606296072960829609296102961129612296132961429615296162961729618296192962029621296222962329624296252962629627296282962929630296312963229633296342963529636296372963829639296402964129642296432964429645296462964729648296492965029651296522965329654296552965629657296582965929660296612966229663296642966529666296672966829669296702967129672296732967429675296762967729678296792968029681296822968329684296852968629687296882968929690296912969229693296942969529696296972969829699297002970129702297032970429705297062970729708297092971029711297122971329714297152971629717297182971929720297212972229723297242972529726297272972829729297302973129732297332973429735297362973729738297392974029741297422974329744297452974629747297482974929750297512975229753297542975529756297572975829759297602976129762297632976429765297662976729768297692977029771297722977329774297752977629777297782977929780297812978229783297842978529786297872978829789297902979129792297932979429795297962979729798297992980029801298022980329804298052980629807298082980929810298112981229813298142981529816298172981829819298202982129822298232982429825298262982729828298292983029831298322983329834298352983629837298382983929840298412984229843298442984529846298472984829849298502985129852298532985429855298562985729858298592986029861298622986329864298652986629867298682986929870298712987229873298742987529876298772987829879298802988129882298832988429885298862988729888298892989029891298922989329894298952989629897298982989929900299012990229903299042990529906299072990829909299102991129912299132991429915299162991729918299192992029921299222992329924299252992629927299282992929930299312993229933299342993529936299372993829939299402994129942299432994429945299462994729948299492995029951299522995329954299552995629957299582995929960299612996229963299642996529966299672996829969299702997129972299732997429975299762997729978299792998029981299822998329984299852998629987299882998929990299912999229993299942999529996299972999829999300003000130002300033000430005300063000730008300093001030011300123001330014300153001630017300183001930020300213002230023300243002530026300273002830029300303003130032300333003430035300363003730038300393004030041300423004330044300453004630047300483004930050300513005230053300543005530056300573005830059300603006130062300633006430065300663006730068300693007030071300723007330074300753007630077300783007930080300813008230083300843008530086300873008830089300903009130092300933009430095300963009730098300993010030101301023010330104301053010630107301083010930110301113011230113301143011530116301173011830119301203012130122301233012430125301263012730128301293013030131301323013330134301353013630137301383013930140301413014230143301443014530146301473014830149301503015130152301533015430155301563015730158301593016030161301623016330164301653016630167301683016930170301713017230173301743017530176301773017830179301803018130182301833018430185301863018730188301893019030191301923019330194301953019630197301983019930200302013020230203302043020530206302073020830209302103021130212302133021430215302163021730218302193022030221302223022330224302253022630227302283022930230302313023230233302343023530236302373023830239302403024130242302433024430245302463024730248302493025030251302523025330254302553025630257302583025930260302613026230263302643026530266302673026830269302703027130272302733027430275302763027730278302793028030281302823028330284302853028630287302883028930290302913029230293302943029530296302973029830299303003030130302303033030430305303063030730308303093031030311303123031330314303153031630317303183031930320303213032230323303243032530326303273032830329303303033130332303333033430335303363033730338303393034030341303423034330344303453034630347303483034930350303513035230353303543035530356303573035830359303603036130362303633036430365303663036730368303693037030371303723037330374303753037630377303783037930380303813038230383303843038530386303873038830389303903039130392303933039430395303963039730398303993040030401304023040330404304053040630407304083040930410304113041230413304143041530416304173041830419304203042130422304233042430425304263042730428304293043030431304323043330434304353043630437304383043930440304413044230443304443044530446304473044830449304503045130452304533045430455304563045730458304593046030461304623046330464304653046630467304683046930470304713047230473304743047530476304773047830479304803048130482304833048430485304863048730488304893049030491304923049330494304953049630497304983049930500305013050230503305043050530506305073050830509305103051130512305133051430515305163051730518305193052030521305223052330524305253052630527305283052930530305313053230533305343053530536305373053830539305403054130542305433054430545305463054730548305493055030551305523055330554305553055630557305583055930560305613056230563305643056530566305673056830569305703057130572305733057430575305763057730578305793058030581305823058330584305853058630587305883058930590305913059230593305943059530596305973059830599306003060130602306033060430605306063060730608306093061030611306123061330614306153061630617306183061930620306213062230623306243062530626306273062830629306303063130632306333063430635306363063730638306393064030641306423064330644306453064630647306483064930650306513065230653306543065530656306573065830659306603066130662306633066430665306663066730668306693067030671306723067330674306753067630677306783067930680306813068230683306843068530686306873068830689306903069130692306933069430695306963069730698306993070030701307023070330704307053070630707307083070930710307113071230713307143071530716307173071830719307203072130722307233072430725307263072730728307293073030731307323073330734307353073630737307383073930740307413074230743307443074530746307473074830749307503075130752307533075430755307563075730758307593076030761307623076330764307653076630767307683076930770307713077230773307743077530776307773077830779307803078130782307833078430785307863078730788307893079030791307923079330794307953079630797307983079930800308013080230803308043080530806308073080830809308103081130812308133081430815308163081730818308193082030821308223082330824308253082630827308283082930830308313083230833308343083530836308373083830839308403084130842308433084430845308463084730848308493085030851308523085330854308553085630857308583085930860308613086230863308643086530866308673086830869308703087130872308733087430875308763087730878308793088030881308823088330884308853088630887308883088930890308913089230893308943089530896308973089830899309003090130902309033090430905309063090730908309093091030911309123091330914309153091630917309183091930920309213092230923309243092530926309273092830929309303093130932309333093430935309363093730938309393094030941309423094330944309453094630947309483094930950309513095230953309543095530956309573095830959309603096130962309633096430965309663096730968309693097030971309723097330974309753097630977309783097930980309813098230983309843098530986309873098830989309903099130992309933099430995309963099730998309993100031001310023100331004310053100631007310083100931010310113101231013310143101531016310173101831019310203102131022310233102431025310263102731028310293103031031310323103331034310353103631037310383103931040310413104231043310443104531046310473104831049310503105131052310533105431055310563105731058310593106031061310623106331064310653106631067310683106931070310713107231073310743107531076310773107831079310803108131082310833108431085310863108731088310893109031091310923109331094310953109631097310983109931100311013110231103311043110531106311073110831109311103111131112311133111431115311163111731118311193112031121311223112331124311253112631127311283112931130311313113231133311343113531136311373113831139311403114131142311433114431145311463114731148311493115031151311523115331154311553115631157311583115931160311613116231163311643116531166311673116831169311703117131172311733117431175311763117731178311793118031181311823118331184311853118631187311883118931190311913119231193311943119531196311973119831199312003120131202312033120431205312063120731208312093121031211312123121331214312153121631217312183121931220312213122231223312243122531226312273122831229312303123131232312333123431235312363123731238312393124031241312423124331244312453124631247312483124931250312513125231253312543125531256312573125831259312603126131262312633126431265312663126731268312693127031271312723127331274312753127631277312783127931280312813128231283312843128531286312873128831289312903129131292312933129431295312963129731298312993130031301313023130331304313053130631307313083130931310313113131231313313143131531316313173131831319313203132131322313233132431325313263132731328313293133031331313323133331334313353133631337313383133931340313413134231343313443134531346313473134831349313503135131352313533135431355313563135731358313593136031361313623136331364313653136631367313683136931370313713137231373313743137531376313773137831379313803138131382313833138431385313863138731388313893139031391313923139331394313953139631397313983139931400314013140231403314043140531406314073140831409314103141131412314133141431415314163141731418314193142031421314223142331424314253142631427314283142931430314313143231433314343143531436314373143831439314403144131442314433144431445314463144731448314493145031451314523145331454314553145631457314583145931460314613146231463314643146531466314673146831469314703147131472314733147431475314763147731478314793148031481314823148331484314853148631487314883148931490314913149231493314943149531496314973149831499315003150131502315033150431505315063150731508315093151031511315123151331514315153151631517315183151931520315213152231523315243152531526315273152831529315303153131532315333153431535315363153731538315393154031541315423154331544315453154631547315483154931550315513155231553315543155531556315573155831559315603156131562315633156431565315663156731568315693157031571315723157331574315753157631577315783157931580315813158231583315843158531586315873158831589315903159131592315933159431595315963159731598315993160031601316023160331604316053160631607316083160931610316113161231613316143161531616316173161831619316203162131622316233162431625316263162731628316293163031631316323163331634316353163631637316383163931640316413164231643316443164531646316473164831649316503165131652316533165431655316563165731658316593166031661316623166331664316653166631667316683166931670316713167231673316743167531676316773167831679316803168131682316833168431685316863168731688316893169031691316923169331694316953169631697316983169931700317013170231703317043170531706317073170831709317103171131712317133171431715317163171731718317193172031721317223172331724317253172631727317283172931730317313173231733317343173531736317373173831739317403174131742317433174431745317463174731748317493175031751317523175331754317553175631757317583175931760317613176231763317643176531766317673176831769317703177131772317733177431775317763177731778317793178031781317823178331784317853178631787317883178931790317913179231793317943179531796317973179831799318003180131802318033180431805318063180731808318093181031811318123181331814318153181631817318183181931820318213182231823318243182531826318273182831829318303183131832318333183431835318363183731838318393184031841318423184331844318453184631847318483184931850318513185231853318543185531856318573185831859318603186131862318633186431865318663186731868318693187031871318723187331874318753187631877318783187931880318813188231883318843188531886318873188831889318903189131892318933189431895318963189731898318993190031901319023190331904319053190631907319083190931910319113191231913319143191531916319173191831919319203192131922319233192431925319263192731928319293193031931319323193331934319353193631937319383193931940319413194231943319443194531946319473194831949319503195131952319533195431955319563195731958319593196031961319623196331964319653196631967319683196931970319713197231973319743197531976319773197831979319803198131982319833198431985319863198731988319893199031991319923199331994319953199631997319983199932000320013200232003320043200532006320073200832009320103201132012320133201432015320163201732018320193202032021320223202332024320253202632027320283202932030320313203232033320343203532036320373203832039320403204132042320433204432045320463204732048320493205032051320523205332054320553205632057320583205932060320613206232063320643206532066320673206832069320703207132072320733207432075320763207732078320793208032081320823208332084320853208632087320883208932090320913209232093320943209532096320973209832099321003210132102321033210432105321063210732108321093211032111321123211332114321153211632117321183211932120321213212232123321243212532126321273212832129321303213132132321333213432135321363213732138321393214032141321423214332144321453214632147321483214932150321513215232153321543215532156321573215832159321603216132162321633216432165321663216732168321693217032171321723217332174321753217632177321783217932180321813218232183321843218532186321873218832189321903219132192321933219432195321963219732198321993220032201322023220332204322053220632207322083220932210322113221232213322143221532216322173221832219322203222132222322233222432225322263222732228322293223032231322323223332234322353223632237322383223932240322413224232243322443224532246322473224832249322503225132252322533225432255322563225732258322593226032261322623226332264322653226632267322683226932270322713227232273322743227532276322773227832279322803228132282322833228432285322863228732288322893229032291322923229332294322953229632297322983229932300323013230232303323043230532306323073230832309323103231132312323133231432315323163231732318323193232032321323223232332324323253232632327323283232932330323313233232333323343233532336323373233832339323403234132342323433234432345323463234732348323493235032351323523235332354323553235632357323583235932360323613236232363323643236532366323673236832369323703237132372323733237432375323763237732378323793238032381323823238332384323853238632387323883238932390323913239232393323943239532396323973239832399324003240132402324033240432405324063240732408324093241032411324123241332414324153241632417324183241932420324213242232423324243242532426324273242832429324303243132432324333243432435324363243732438324393244032441324423244332444324453244632447324483244932450324513245232453324543245532456324573245832459324603246132462324633246432465324663246732468324693247032471324723247332474324753247632477324783247932480324813248232483324843248532486324873248832489324903249132492324933249432495324963249732498324993250032501325023250332504325053250632507325083250932510325113251232513325143251532516325173251832519325203252132522325233252432525325263252732528325293253032531325323253332534325353253632537325383253932540325413254232543325443254532546325473254832549325503255132552325533255432555325563255732558325593256032561325623256332564325653256632567325683256932570325713257232573325743257532576325773257832579325803258132582325833258432585325863258732588325893259032591325923259332594325953259632597325983259932600326013260232603326043260532606326073260832609326103261132612326133261432615326163261732618326193262032621326223262332624326253262632627326283262932630326313263232633326343263532636326373263832639326403264132642326433264432645326463264732648326493265032651326523265332654326553265632657326583265932660326613266232663326643266532666326673266832669326703267132672326733267432675326763267732678326793268032681326823268332684326853268632687326883268932690326913269232693326943269532696326973269832699327003270132702327033270432705327063270732708327093271032711327123271332714327153271632717327183271932720327213272232723327243272532726327273272832729327303273132732327333273432735327363273732738327393274032741327423274332744327453274632747327483274932750327513275232753327543275532756327573275832759327603276132762327633276432765327663276732768327693277032771327723277332774327753277632777327783277932780327813278232783327843278532786327873278832789327903279132792327933279432795327963279732798327993280032801328023280332804328053280632807328083280932810328113281232813328143281532816328173281832819328203282132822328233282432825328263282732828328293283032831328323283332834328353283632837328383283932840328413284232843328443284532846328473284832849328503285132852328533285432855328563285732858328593286032861328623286332864328653286632867328683286932870328713287232873328743287532876328773287832879328803288132882328833288432885328863288732888328893289032891328923289332894328953289632897328983289932900329013290232903329043290532906329073290832909329103291132912329133291432915329163291732918329193292032921329223292332924329253292632927329283292932930329313293232933329343293532936329373293832939329403294132942329433294432945329463294732948329493295032951329523295332954329553295632957329583295932960329613296232963329643296532966329673296832969329703297132972329733297432975329763297732978329793298032981329823298332984329853298632987329883298932990329913299232993329943299532996329973299832999330003300133002330033300433005330063300733008330093301033011330123301333014330153301633017330183301933020330213302233023330243302533026330273302833029330303303133032330333303433035330363303733038330393304033041330423304333044330453304633047330483304933050330513305233053330543305533056330573305833059330603306133062330633306433065330663306733068330693307033071330723307333074330753307633077330783307933080330813308233083330843308533086330873308833089330903309133092330933309433095330963309733098330993310033101331023310333104331053310633107331083310933110331113311233113331143311533116331173311833119331203312133122331233312433125331263312733128331293313033131331323313333134331353313633137331383313933140331413314233143331443314533146331473314833149331503315133152331533315433155331563315733158331593316033161331623316333164331653316633167331683316933170331713317233173331743317533176331773317833179331803318133182331833318433185331863318733188331893319033191331923319333194331953319633197331983319933200332013320233203332043320533206332073320833209332103321133212332133321433215332163321733218332193322033221332223322333224332253322633227332283322933230332313323233233332343323533236332373323833239332403324133242332433324433245332463324733248332493325033251332523325333254332553325633257332583325933260332613326233263332643326533266332673326833269332703327133272332733327433275332763327733278332793328033281332823328333284332853328633287332883328933290332913329233293332943329533296332973329833299333003330133302333033330433305333063330733308333093331033311333123331333314333153331633317333183331933320333213332233323333243332533326333273332833329333303333133332333333333433335333363333733338333393334033341333423334333344333453334633347333483334933350333513335233353333543335533356333573335833359333603336133362333633336433365333663336733368333693337033371333723337333374333753337633377333783337933380333813338233383333843338533386333873338833389333903339133392333933339433395333963339733398333993340033401334023340333404334053340633407334083340933410334113341233413334143341533416334173341833419334203342133422334233342433425334263342733428334293343033431334323343333434334353343633437334383343933440334413344233443334443344533446334473344833449334503345133452334533345433455334563345733458334593346033461334623346333464334653346633467334683346933470334713347233473334743347533476334773347833479334803348133482334833348433485334863348733488334893349033491334923349333494334953349633497334983349933500335013350233503335043350533506335073350833509335103351133512335133351433515335163351733518335193352033521335223352333524335253352633527335283352933530335313353233533335343353533536335373353833539335403354133542335433354433545335463354733548335493355033551335523355333554335553355633557335583355933560335613356233563335643356533566335673356833569335703357133572335733357433575335763357733578335793358033581335823358333584335853358633587335883358933590335913359233593335943359533596335973359833599336003360133602336033360433605336063360733608336093361033611336123361333614336153361633617336183361933620336213362233623336243362533626336273362833629336303363133632336333363433635336363363733638336393364033641336423364333644336453364633647336483364933650336513365233653336543365533656336573365833659336603366133662336633366433665336663366733668336693367033671336723367333674336753367633677336783367933680336813368233683336843368533686336873368833689336903369133692336933369433695336963369733698336993370033701337023370333704337053370633707337083370933710337113371233713337143371533716337173371833719337203372133722337233372433725337263372733728337293373033731337323373333734337353373633737337383373933740337413374233743337443374533746337473374833749337503375133752337533375433755337563375733758337593376033761337623376333764337653376633767337683376933770337713377233773337743377533776337773377833779337803378133782337833378433785337863378733788337893379033791337923379333794337953379633797337983379933800338013380233803338043380533806338073380833809338103381133812338133381433815338163381733818338193382033821338223382333824338253382633827338283382933830338313383233833338343383533836338373383833839338403384133842338433384433845338463384733848338493385033851338523385333854338553385633857338583385933860338613386233863338643386533866338673386833869338703387133872338733387433875338763387733878338793388033881338823388333884338853388633887338883388933890338913389233893338943389533896338973389833899339003390133902339033390433905339063390733908339093391033911339123391333914339153391633917339183391933920339213392233923339243392533926339273392833929339303393133932339333393433935339363393733938339393394033941339423394333944339453394633947339483394933950339513395233953339543395533956339573395833959339603396133962339633396433965339663396733968339693397033971339723397333974339753397633977339783397933980339813398233983339843398533986339873398833989339903399133992339933399433995339963399733998339993400034001340023400334004340053400634007340083400934010340113401234013340143401534016340173401834019340203402134022340233402434025340263402734028340293403034031340323403334034340353403634037340383403934040340413404234043340443404534046340473404834049340503405134052340533405434055340563405734058340593406034061340623406334064340653406634067340683406934070340713407234073340743407534076340773407834079340803408134082340833408434085340863408734088340893409034091340923409334094340953409634097340983409934100341013410234103341043410534106341073410834109341103411134112341133411434115341163411734118341193412034121341223412334124341253412634127341283412934130341313413234133341343413534136341373413834139341403414134142341433414434145341463414734148341493415034151341523415334154341553415634157341583415934160341613416234163341643416534166341673416834169341703417134172341733417434175341763417734178341793418034181341823418334184341853418634187341883418934190341913419234193341943419534196341973419834199342003420134202342033420434205342063420734208342093421034211342123421334214342153421634217342183421934220342213422234223342243422534226342273422834229342303423134232342333423434235342363423734238342393424034241342423424334244342453424634247342483424934250342513425234253342543425534256342573425834259342603426134262342633426434265342663426734268342693427034271342723427334274342753427634277342783427934280342813428234283342843428534286342873428834289342903429134292342933429434295342963429734298342993430034301343023430334304343053430634307343083430934310343113431234313343143431534316343173431834319343203432134322343233432434325343263432734328343293433034331343323433334334343353433634337343383433934340343413434234343343443434534346343473434834349343503435134352343533435434355343563435734358343593436034361343623436334364343653436634367343683436934370343713437234373343743437534376343773437834379343803438134382343833438434385343863438734388343893439034391343923439334394343953439634397343983439934400344013440234403344043440534406344073440834409344103441134412344133441434415344163441734418344193442034421344223442334424344253442634427344283442934430344313443234433344343443534436344373443834439344403444134442344433444434445344463444734448344493445034451344523445334454344553445634457344583445934460344613446234463344643446534466344673446834469344703447134472344733447434475344763447734478344793448034481344823448334484344853448634487344883448934490344913449234493344943449534496344973449834499345003450134502345033450434505345063450734508345093451034511345123451334514345153451634517345183451934520345213452234523345243452534526345273452834529345303453134532345333453434535345363453734538345393454034541345423454334544345453454634547345483454934550345513455234553345543455534556345573455834559345603456134562345633456434565345663456734568345693457034571345723457334574345753457634577345783457934580345813458234583345843458534586345873458834589345903459134592345933459434595345963459734598345993460034601346023460334604346053460634607346083460934610346113461234613346143461534616346173461834619346203462134622346233462434625346263462734628346293463034631346323463334634346353463634637346383463934640346413464234643346443464534646346473464834649346503465134652346533465434655346563465734658346593466034661346623466334664346653466634667346683466934670346713467234673346743467534676346773467834679346803468134682346833468434685346863468734688346893469034691346923469334694346953469634697346983469934700347013470234703347043470534706347073470834709347103471134712347133471434715347163471734718347193472034721347223472334724347253472634727347283472934730347313473234733347343473534736347373473834739347403474134742347433474434745347463474734748347493475034751347523475334754347553475634757347583475934760347613476234763347643476534766347673476834769347703477134772347733477434775347763477734778347793478034781347823478334784347853478634787347883478934790347913479234793347943479534796347973479834799348003480134802348033480434805348063480734808348093481034811348123481334814348153481634817348183481934820348213482234823348243482534826348273482834829348303483134832348333483434835348363483734838348393484034841348423484334844348453484634847348483484934850348513485234853348543485534856348573485834859348603486134862348633486434865348663486734868348693487034871348723487334874348753487634877348783487934880348813488234883348843488534886348873488834889348903489134892348933489434895348963489734898348993490034901349023490334904349053490634907349083490934910349113491234913349143491534916349173491834919349203492134922349233492434925349263492734928349293493034931349323493334934349353493634937349383493934940349413494234943349443494534946349473494834949349503495134952349533495434955349563495734958349593496034961349623496334964349653496634967349683496934970349713497234973349743497534976349773497834979349803498134982349833498434985349863498734988349893499034991349923499334994349953499634997349983499935000350013500235003350043500535006350073500835009350103501135012350133501435015350163501735018350193502035021350223502335024350253502635027350283502935030350313503235033350343503535036350373503835039350403504135042350433504435045350463504735048350493505035051350523505335054350553505635057350583505935060350613506235063350643506535066350673506835069350703507135072350733507435075350763507735078350793508035081350823508335084350853508635087350883508935090350913509235093350943509535096350973509835099351003510135102351033510435105351063510735108351093511035111351123511335114351153511635117351183511935120351213512235123351243512535126351273512835129351303513135132351333513435135351363513735138351393514035141351423514335144351453514635147351483514935150351513515235153351543515535156351573515835159351603516135162351633516435165351663516735168351693517035171351723517335174351753517635177351783517935180351813518235183351843518535186351873518835189351903519135192351933519435195351963519735198351993520035201352023520335204352053520635207352083520935210352113521235213352143521535216352173521835219352203522135222352233522435225352263522735228352293523035231352323523335234352353523635237352383523935240352413524235243352443524535246352473524835249352503525135252352533525435255352563525735258352593526035261352623526335264352653526635267352683526935270352713527235273352743527535276352773527835279352803528135282352833528435285352863528735288352893529035291352923529335294352953529635297352983529935300353013530235303353043530535306353073530835309353103531135312353133531435315353163531735318353193532035321353223532335324353253532635327353283532935330353313533235333353343533535336353373533835339353403534135342353433534435345353463534735348353493535035351353523535335354353553535635357353583535935360353613536235363353643536535366353673536835369353703537135372353733537435375353763537735378353793538035381353823538335384353853538635387353883538935390353913539235393353943539535396353973539835399354003540135402354033540435405354063540735408354093541035411354123541335414354153541635417354183541935420354213542235423354243542535426354273542835429354303543135432354333543435435354363543735438354393544035441354423544335444354453544635447354483544935450354513545235453354543545535456354573545835459354603546135462354633546435465354663546735468354693547035471354723547335474354753547635477354783547935480354813548235483354843548535486354873548835489354903549135492354933549435495354963549735498354993550035501355023550335504355053550635507355083550935510355113551235513355143551535516355173551835519355203552135522355233552435525355263552735528355293553035531355323553335534355353553635537355383553935540355413554235543355443554535546355473554835549355503555135552355533555435555355563555735558355593556035561355623556335564355653556635567355683556935570355713557235573355743557535576355773557835579355803558135582355833558435585355863558735588355893559035591355923559335594355953559635597355983559935600356013560235603356043560535606356073560835609356103561135612356133561435615356163561735618356193562035621356223562335624356253562635627356283562935630356313563235633356343563535636356373563835639356403564135642356433564435645356463564735648356493565035651356523565335654356553565635657356583565935660356613566235663356643566535666356673566835669356703567135672356733567435675356763567735678356793568035681356823568335684356853568635687356883568935690356913569235693356943569535696356973569835699357003570135702357033570435705357063570735708357093571035711357123571335714357153571635717357183571935720357213572235723357243572535726357273572835729357303573135732357333573435735357363573735738357393574035741357423574335744357453574635747357483574935750357513575235753357543575535756357573575835759357603576135762357633576435765357663576735768357693577035771357723577335774357753577635777357783577935780357813578235783357843578535786357873578835789357903579135792357933579435795357963579735798357993580035801358023580335804358053580635807358083580935810358113581235813358143581535816358173581835819358203582135822358233582435825358263582735828358293583035831358323583335834358353583635837358383583935840358413584235843358443584535846358473584835849358503585135852358533585435855358563585735858358593586035861358623586335864358653586635867358683586935870358713587235873358743587535876358773587835879358803588135882358833588435885358863588735888358893589035891358923589335894358953589635897358983589935900359013590235903359043590535906359073590835909359103591135912359133591435915359163591735918359193592035921359223592335924359253592635927359283592935930359313593235933359343593535936359373593835939359403594135942359433594435945359463594735948359493595035951359523595335954359553595635957359583595935960359613596235963359643596535966359673596835969359703597135972359733597435975359763597735978359793598035981359823598335984359853598635987359883598935990359913599235993359943599535996359973599835999360003600136002360033600436005360063600736008360093601036011360123601336014360153601636017360183601936020360213602236023360243602536026360273602836029360303603136032360333603436035360363603736038360393604036041360423604336044360453604636047360483604936050360513605236053360543605536056360573605836059360603606136062360633606436065360663606736068360693607036071360723607336074360753607636077360783607936080360813608236083360843608536086360873608836089360903609136092360933609436095360963609736098360993610036101361023610336104361053610636107361083610936110361113611236113361143611536116361173611836119361203612136122361233612436125361263612736128361293613036131361323613336134361353613636137361383613936140361413614236143361443614536146361473614836149361503615136152361533615436155361563615736158361593616036161361623616336164361653616636167361683616936170361713617236173361743617536176361773617836179361803618136182361833618436185361863618736188361893619036191361923619336194361953619636197361983619936200362013620236203362043620536206362073620836209362103621136212362133621436215362163621736218362193622036221362223622336224362253622636227362283622936230362313623236233362343623536236362373623836239362403624136242362433624436245362463624736248362493625036251362523625336254362553625636257362583625936260362613626236263362643626536266362673626836269362703627136272362733627436275362763627736278362793628036281362823628336284362853628636287362883628936290362913629236293362943629536296362973629836299363003630136302363033630436305363063630736308363093631036311363123631336314363153631636317363183631936320363213632236323363243632536326363273632836329363303633136332363333633436335363363633736338363393634036341363423634336344363453634636347363483634936350363513635236353363543635536356363573635836359363603636136362363633636436365363663636736368363693637036371363723637336374363753637636377363783637936380363813638236383363843638536386363873638836389363903639136392363933639436395363963639736398363993640036401364023640336404364053640636407364083640936410364113641236413364143641536416364173641836419364203642136422364233642436425364263642736428364293643036431364323643336434364353643636437364383643936440364413644236443364443644536446364473644836449364503645136452364533645436455364563645736458364593646036461364623646336464364653646636467364683646936470364713647236473364743647536476364773647836479364803648136482364833648436485364863648736488364893649036491364923649336494364953649636497364983649936500365013650236503365043650536506365073650836509365103651136512365133651436515365163651736518365193652036521365223652336524365253652636527365283652936530365313653236533365343653536536365373653836539365403654136542365433654436545365463654736548365493655036551365523655336554365553655636557365583655936560365613656236563365643656536566365673656836569365703657136572365733657436575365763657736578365793658036581365823658336584365853658636587365883658936590365913659236593365943659536596365973659836599366003660136602366033660436605366063660736608366093661036611366123661336614366153661636617366183661936620366213662236623366243662536626366273662836629366303663136632366333663436635366363663736638366393664036641366423664336644366453664636647366483664936650366513665236653366543665536656366573665836659366603666136662366633666436665366663666736668366693667036671366723667336674366753667636677366783667936680366813668236683366843668536686366873668836689366903669136692366933669436695366963669736698366993670036701367023670336704367053670636707367083670936710367113671236713367143671536716367173671836719367203672136722367233672436725367263672736728367293673036731367323673336734367353673636737367383673936740367413674236743367443674536746367473674836749367503675136752367533675436755367563675736758367593676036761367623676336764367653676636767367683676936770367713677236773367743677536776367773677836779367803678136782367833678436785367863678736788367893679036791367923679336794367953679636797367983679936800368013680236803368043680536806368073680836809368103681136812368133681436815368163681736818368193682036821368223682336824368253682636827368283682936830368313683236833368343683536836368373683836839368403684136842368433684436845368463684736848368493685036851368523685336854368553685636857368583685936860368613686236863368643686536866368673686836869368703687136872368733687436875368763687736878368793688036881368823688336884368853688636887368883688936890368913689236893368943689536896368973689836899369003690136902369033690436905369063690736908369093691036911369123691336914369153691636917369183691936920369213692236923369243692536926369273692836929369303693136932369333693436935369363693736938369393694036941369423694336944369453694636947369483694936950369513695236953369543695536956369573695836959369603696136962369633696436965369663696736968369693697036971369723697336974369753697636977369783697936980369813698236983369843698536986369873698836989369903699136992369933699436995369963699736998369993700037001370023700337004370053700637007370083700937010370113701237013370143701537016370173701837019370203702137022370233702437025370263702737028370293703037031370323703337034370353703637037370383703937040370413704237043370443704537046370473704837049370503705137052370533705437055370563705737058370593706037061370623706337064370653706637067370683706937070370713707237073370743707537076370773707837079370803708137082370833708437085370863708737088370893709037091370923709337094370953709637097370983709937100371013710237103371043710537106371073710837109371103711137112371133711437115371163711737118371193712037121371223712337124371253712637127371283712937130371313713237133371343713537136371373713837139371403714137142371433714437145371463714737148371493715037151371523715337154371553715637157371583715937160371613716237163371643716537166371673716837169371703717137172371733717437175371763717737178371793718037181371823718337184371853718637187371883718937190371913719237193371943719537196371973719837199372003720137202372033720437205372063720737208372093721037211372123721337214372153721637217372183721937220372213722237223372243722537226372273722837229372303723137232372333723437235372363723737238372393724037241372423724337244372453724637247372483724937250372513725237253372543725537256372573725837259372603726137262372633726437265372663726737268372693727037271372723727337274372753727637277372783727937280372813728237283372843728537286372873728837289372903729137292372933729437295372963729737298372993730037301373023730337304373053730637307373083730937310373113731237313373143731537316373173731837319373203732137322373233732437325373263732737328373293733037331373323733337334373353733637337373383733937340373413734237343373443734537346373473734837349373503735137352373533735437355373563735737358373593736037361373623736337364373653736637367373683736937370373713737237373373743737537376373773737837379373803738137382373833738437385373863738737388373893739037391373923739337394373953739637397373983739937400374013740237403374043740537406374073740837409374103741137412374133741437415374163741737418374193742037421374223742337424374253742637427374283742937430374313743237433374343743537436374373743837439374403744137442374433744437445374463744737448374493745037451374523745337454374553745637457374583745937460374613746237463374643746537466374673746837469374703747137472374733747437475374763747737478374793748037481374823748337484374853748637487374883748937490374913749237493374943749537496374973749837499375003750137502375033750437505375063750737508375093751037511375123751337514375153751637517375183751937520375213752237523375243752537526375273752837529375303753137532375333753437535375363753737538375393754037541375423754337544375453754637547375483754937550375513755237553375543755537556375573755837559375603756137562375633756437565375663756737568375693757037571375723757337574375753757637577375783757937580375813758237583375843758537586375873758837589375903759137592375933759437595375963759737598375993760037601376023760337604376053760637607376083760937610376113761237613376143761537616376173761837619376203762137622376233762437625376263762737628376293763037631376323763337634376353763637637376383763937640376413764237643376443764537646376473764837649376503765137652376533765437655376563765737658376593766037661376623766337664376653766637667376683766937670376713767237673376743767537676376773767837679376803768137682376833768437685376863768737688376893769037691376923769337694376953769637697376983769937700377013770237703377043770537706377073770837709377103771137712377133771437715377163771737718377193772037721377223772337724377253772637727377283772937730377313773237733377343773537736377373773837739377403774137742377433774437745377463774737748377493775037751377523775337754377553775637757377583775937760377613776237763377643776537766377673776837769377703777137772377733777437775377763777737778377793778037781377823778337784377853778637787377883778937790377913779237793377943779537796377973779837799378003780137802378033780437805378063780737808378093781037811378123781337814378153781637817378183781937820378213782237823378243782537826378273782837829378303783137832378333783437835378363783737838378393784037841378423784337844378453784637847378483784937850378513785237853378543785537856378573785837859378603786137862378633786437865378663786737868378693787037871378723787337874378753787637877378783787937880378813788237883378843788537886378873788837889378903789137892378933789437895378963789737898378993790037901379023790337904379053790637907379083790937910379113791237913379143791537916379173791837919379203792137922379233792437925379263792737928379293793037931379323793337934379353793637937379383793937940379413794237943379443794537946379473794837949379503795137952379533795437955379563795737958379593796037961379623796337964379653796637967379683796937970379713797237973379743797537976379773797837979379803798137982379833798437985379863798737988379893799037991379923799337994379953799637997379983799938000380013800238003380043800538006380073800838009380103801138012380133801438015380163801738018380193802038021380223802338024380253802638027380283802938030380313803238033380343803538036380373803838039380403804138042380433804438045380463804738048380493805038051380523805338054380553805638057380583805938060380613806238063380643806538066380673806838069380703807138072380733807438075380763807738078380793808038081380823808338084380853808638087380883808938090380913809238093380943809538096380973809838099381003810138102381033810438105381063810738108381093811038111381123811338114381153811638117381183811938120381213812238123381243812538126381273812838129381303813138132381333813438135381363813738138381393814038141381423814338144381453814638147381483814938150381513815238153381543815538156381573815838159381603816138162381633816438165381663816738168381693817038171381723817338174381753817638177381783817938180381813818238183381843818538186381873818838189381903819138192381933819438195381963819738198381993820038201382023820338204382053820638207382083820938210382113821238213382143821538216382173821838219382203822138222382233822438225382263822738228382293823038231382323823338234382353823638237382383823938240382413824238243382443824538246382473824838249382503825138252382533825438255382563825738258382593826038261382623826338264382653826638267382683826938270382713827238273382743827538276382773827838279382803828138282382833828438285382863828738288382893829038291382923829338294382953829638297382983829938300383013830238303383043830538306383073830838309383103831138312383133831438315383163831738318383193832038321383223832338324383253832638327383283832938330383313833238333383343833538336383373833838339383403834138342383433834438345383463834738348383493835038351383523835338354383553835638357383583835938360383613836238363383643836538366383673836838369383703837138372383733837438375383763837738378383793838038381383823838338384383853838638387383883838938390383913839238393383943839538396383973839838399384003840138402384033840438405384063840738408384093841038411384123841338414384153841638417384183841938420384213842238423384243842538426384273842838429384303843138432384333843438435384363843738438384393844038441384423844338444384453844638447384483844938450384513845238453384543845538456384573845838459384603846138462384633846438465384663846738468384693847038471384723847338474384753847638477384783847938480384813848238483384843848538486384873848838489384903849138492384933849438495384963849738498384993850038501385023850338504385053850638507385083850938510385113851238513385143851538516385173851838519385203852138522385233852438525385263852738528385293853038531385323853338534385353853638537385383853938540385413854238543385443854538546385473854838549385503855138552385533855438555385563855738558385593856038561385623856338564385653856638567385683856938570385713857238573385743857538576385773857838579385803858138582385833858438585385863858738588385893859038591385923859338594385953859638597385983859938600386013860238603386043860538606386073860838609386103861138612386133861438615386163861738618386193862038621386223862338624386253862638627386283862938630386313863238633386343863538636386373863838639386403864138642386433864438645386463864738648386493865038651386523865338654386553865638657386583865938660386613866238663386643866538666386673866838669386703867138672386733867438675386763867738678386793868038681386823868338684386853868638687386883868938690386913869238693386943869538696386973869838699387003870138702387033870438705387063870738708387093871038711387123871338714387153871638717387183871938720387213872238723387243872538726387273872838729387303873138732387333873438735387363873738738387393874038741387423874338744387453874638747387483874938750387513875238753387543875538756387573875838759387603876138762387633876438765387663876738768387693877038771387723877338774387753877638777387783877938780387813878238783387843878538786387873878838789387903879138792387933879438795387963879738798387993880038801388023880338804388053880638807388083880938810388113881238813388143881538816388173881838819388203882138822388233882438825388263882738828388293883038831388323883338834388353883638837388383883938840388413884238843388443884538846388473884838849388503885138852388533885438855388563885738858388593886038861388623886338864388653886638867388683886938870388713887238873388743887538876388773887838879388803888138882388833888438885388863888738888388893889038891388923889338894388953889638897388983889938900389013890238903389043890538906389073890838909389103891138912389133891438915389163891738918389193892038921389223892338924389253892638927389283892938930389313893238933389343893538936389373893838939389403894138942389433894438945389463894738948389493895038951389523895338954389553895638957389583895938960389613896238963389643896538966389673896838969389703897138972389733897438975389763897738978389793898038981389823898338984389853898638987389883898938990389913899238993389943899538996389973899838999390003900139002390033900439005390063900739008390093901039011390123901339014390153901639017390183901939020390213902239023390243902539026390273902839029390303903139032390333903439035390363903739038390393904039041390423904339044390453904639047390483904939050390513905239053390543905539056390573905839059390603906139062390633906439065390663906739068390693907039071390723907339074390753907639077390783907939080390813908239083390843908539086390873908839089390903909139092390933909439095390963909739098390993910039101391023910339104391053910639107391083910939110391113911239113391143911539116391173911839119391203912139122391233912439125391263912739128391293913039131391323913339134391353913639137391383913939140391413914239143391443914539146391473914839149391503915139152391533915439155391563915739158391593916039161391623916339164391653916639167391683916939170391713917239173391743917539176391773917839179391803918139182391833918439185391863918739188391893919039191391923919339194391953919639197391983919939200392013920239203392043920539206392073920839209392103921139212392133921439215392163921739218392193922039221392223922339224392253922639227392283922939230392313923239233392343923539236392373923839239392403924139242392433924439245392463924739248392493925039251392523925339254392553925639257392583925939260392613926239263392643926539266392673926839269392703927139272392733927439275392763927739278392793928039281392823928339284392853928639287392883928939290392913929239293392943929539296392973929839299393003930139302393033930439305393063930739308393093931039311393123931339314393153931639317393183931939320393213932239323393243932539326393273932839329393303933139332393333933439335393363933739338393393934039341393423934339344393453934639347393483934939350393513935239353393543935539356393573935839359393603936139362393633936439365393663936739368393693937039371393723937339374393753937639377393783937939380393813938239383393843938539386393873938839389393903939139392393933939439395393963939739398393993940039401394023940339404394053940639407394083940939410394113941239413394143941539416394173941839419394203942139422394233942439425394263942739428394293943039431394323943339434394353943639437394383943939440394413944239443394443944539446394473944839449394503945139452394533945439455394563945739458394593946039461394623946339464394653946639467394683946939470394713947239473394743947539476394773947839479394803948139482394833948439485394863948739488394893949039491394923949339494394953949639497394983949939500395013950239503395043950539506395073950839509395103951139512395133951439515395163951739518395193952039521395223952339524395253952639527395283952939530395313953239533395343953539536395373953839539395403954139542395433954439545395463954739548395493955039551395523955339554395553955639557395583955939560395613956239563395643956539566395673956839569395703957139572395733957439575395763957739578395793958039581395823958339584395853958639587395883958939590395913959239593395943959539596395973959839599396003960139602396033960439605396063960739608396093961039611396123961339614396153961639617396183961939620396213962239623396243962539626396273962839629396303963139632396333963439635396363963739638396393964039641396423964339644396453964639647396483964939650396513965239653396543965539656396573965839659396603966139662396633966439665396663966739668396693967039671396723967339674396753967639677396783967939680396813968239683396843968539686396873968839689396903969139692396933969439695396963969739698396993970039701397023970339704397053970639707397083970939710397113971239713397143971539716397173971839719397203972139722397233972439725397263972739728397293973039731397323973339734397353973639737397383973939740397413974239743397443974539746397473974839749397503975139752397533975439755397563975739758397593976039761397623976339764397653976639767397683976939770397713977239773397743977539776397773977839779397803978139782397833978439785397863978739788397893979039791397923979339794397953979639797397983979939800398013980239803398043980539806398073980839809398103981139812398133981439815398163981739818398193982039821398223982339824398253982639827398283982939830398313983239833398343983539836398373983839839398403984139842398433984439845398463984739848398493985039851398523985339854398553985639857398583985939860398613986239863398643986539866398673986839869398703987139872398733987439875398763987739878398793988039881398823988339884398853988639887398883988939890398913989239893398943989539896398973989839899399003990139902399033990439905399063990739908399093991039911399123991339914399153991639917399183991939920399213992239923399243992539926399273992839929399303993139932399333993439935399363993739938399393994039941399423994339944399453994639947399483994939950399513995239953399543995539956399573995839959399603996139962399633996439965399663996739968399693997039971399723997339974399753997639977399783997939980399813998239983399843998539986399873998839989399903999139992399933999439995399963999739998399994000040001400024000340004400054000640007400084000940010400114001240013400144001540016400174001840019400204002140022400234002440025400264002740028400294003040031400324003340034400354003640037400384003940040400414004240043400444004540046400474004840049400504005140052400534005440055400564005740058400594006040061400624006340064400654006640067400684006940070400714007240073400744007540076400774007840079400804008140082400834008440085400864008740088400894009040091400924009340094400954009640097400984009940100401014010240103401044010540106401074010840109401104011140112401134011440115401164011740118401194012040121401224012340124401254012640127401284012940130401314013240133401344013540136401374013840139401404014140142401434014440145401464014740148401494015040151401524015340154401554015640157401584015940160401614016240163401644016540166401674016840169401704017140172401734017440175401764017740178401794018040181401824018340184401854018640187401884018940190401914019240193401944019540196401974019840199402004020140202402034020440205402064020740208402094021040211402124021340214402154021640217402184021940220402214022240223402244022540226402274022840229402304023140232402334023440235402364023740238402394024040241402424024340244402454024640247402484024940250402514025240253402544025540256402574025840259402604026140262402634026440265402664026740268402694027040271402724027340274402754027640277402784027940280402814028240283402844028540286402874028840289402904029140292402934029440295402964029740298402994030040301403024030340304403054030640307403084030940310403114031240313403144031540316403174031840319403204032140322403234032440325403264032740328403294033040331403324033340334403354033640337403384033940340403414034240343403444034540346403474034840349403504035140352403534035440355403564035740358403594036040361403624036340364403654036640367403684036940370403714037240373403744037540376403774037840379403804038140382403834038440385403864038740388403894039040391403924039340394403954039640397403984039940400404014040240403404044040540406404074040840409404104041140412404134041440415404164041740418404194042040421404224042340424404254042640427404284042940430404314043240433404344043540436404374043840439404404044140442404434044440445404464044740448404494045040451404524045340454404554045640457404584045940460404614046240463404644046540466404674046840469404704047140472404734047440475404764047740478404794048040481404824048340484404854048640487404884048940490404914049240493404944049540496404974049840499405004050140502405034050440505405064050740508405094051040511405124051340514405154051640517405184051940520405214052240523405244052540526405274052840529405304053140532405334053440535405364053740538405394054040541405424054340544405454054640547405484054940550405514055240553405544055540556405574055840559405604056140562405634056440565405664056740568405694057040571405724057340574405754057640577405784057940580405814058240583405844058540586405874058840589405904059140592405934059440595405964059740598405994060040601406024060340604406054060640607406084060940610406114061240613406144061540616406174061840619406204062140622406234062440625406264062740628406294063040631406324063340634406354063640637406384063940640406414064240643406444064540646406474064840649406504065140652406534065440655406564065740658406594066040661406624066340664406654066640667406684066940670406714067240673406744067540676406774067840679406804068140682406834068440685406864068740688406894069040691406924069340694406954069640697406984069940700407014070240703407044070540706407074070840709407104071140712407134071440715407164071740718407194072040721407224072340724407254072640727407284072940730407314073240733407344073540736407374073840739407404074140742407434074440745407464074740748407494075040751407524075340754407554075640757407584075940760407614076240763407644076540766407674076840769407704077140772407734077440775407764077740778407794078040781407824078340784407854078640787407884078940790407914079240793407944079540796407974079840799408004080140802408034080440805408064080740808408094081040811408124081340814408154081640817408184081940820408214082240823408244082540826408274082840829408304083140832408334083440835408364083740838408394084040841408424084340844408454084640847408484084940850408514085240853408544085540856408574085840859408604086140862408634086440865408664086740868408694087040871408724087340874408754087640877408784087940880408814088240883408844088540886408874088840889408904089140892408934089440895408964089740898408994090040901409024090340904409054090640907409084090940910409114091240913409144091540916409174091840919409204092140922409234092440925409264092740928409294093040931409324093340934409354093640937409384093940940409414094240943409444094540946409474094840949409504095140952409534095440955409564095740958409594096040961409624096340964409654096640967409684096940970409714097240973409744097540976409774097840979409804098140982409834098440985409864098740988409894099040991409924099340994409954099640997409984099941000410014100241003410044100541006410074100841009410104101141012410134101441015410164101741018410194102041021410224102341024410254102641027410284102941030410314103241033410344103541036410374103841039410404104141042410434104441045410464104741048410494105041051410524105341054410554105641057410584105941060410614106241063410644106541066410674106841069410704107141072410734107441075410764107741078410794108041081410824108341084410854108641087410884108941090410914109241093410944109541096410974109841099411004110141102411034110441105411064110741108411094111041111411124111341114411154111641117411184111941120411214112241123411244112541126411274112841129411304113141132411334113441135411364113741138411394114041141411424114341144411454114641147411484114941150411514115241153411544115541156411574115841159411604116141162411634116441165411664116741168411694117041171411724117341174411754117641177411784117941180411814118241183411844118541186411874118841189411904119141192411934119441195411964119741198411994120041201412024120341204412054120641207412084120941210412114121241213412144121541216412174121841219412204122141222412234122441225412264122741228412294123041231412324123341234412354123641237412384123941240412414124241243412444124541246412474124841249412504125141252412534125441255412564125741258412594126041261412624126341264412654126641267412684126941270412714127241273412744127541276412774127841279412804128141282412834128441285412864128741288412894129041291412924129341294412954129641297412984129941300413014130241303413044130541306413074130841309413104131141312413134131441315413164131741318413194132041321413224132341324413254132641327413284132941330413314133241333413344133541336413374133841339413404134141342413434134441345413464134741348413494135041351413524135341354413554135641357413584135941360413614136241363413644136541366413674136841369413704137141372413734137441375413764137741378413794138041381413824138341384413854138641387413884138941390413914139241393413944139541396413974139841399414004140141402414034140441405414064140741408414094141041411414124141341414414154141641417414184141941420414214142241423414244142541426414274142841429414304143141432414334143441435414364143741438414394144041441414424144341444414454144641447414484144941450414514145241453414544145541456414574145841459414604146141462414634146441465414664146741468414694147041471414724147341474414754147641477414784147941480414814148241483414844148541486414874148841489414904149141492414934149441495414964149741498414994150041501415024150341504415054150641507415084150941510415114151241513415144151541516415174151841519415204152141522415234152441525415264152741528415294153041531415324153341534415354153641537415384153941540415414154241543415444154541546415474154841549415504155141552415534155441555415564155741558415594156041561415624156341564415654156641567415684156941570415714157241573415744157541576415774157841579415804158141582415834158441585415864158741588415894159041591415924159341594415954159641597415984159941600416014160241603416044160541606416074160841609416104161141612416134161441615416164161741618416194162041621416224162341624416254162641627416284162941630416314163241633416344163541636416374163841639416404164141642416434164441645416464164741648416494165041651416524165341654416554165641657416584165941660416614166241663416644166541666416674166841669416704167141672416734167441675416764167741678416794168041681416824168341684416854168641687416884168941690416914169241693416944169541696416974169841699417004170141702417034170441705417064170741708417094171041711417124171341714417154171641717417184171941720417214172241723417244172541726417274172841729417304173141732417334173441735417364173741738417394174041741417424174341744417454174641747417484174941750417514175241753417544175541756417574175841759417604176141762417634176441765417664176741768417694177041771417724177341774417754177641777417784177941780417814178241783417844178541786417874178841789417904179141792417934179441795417964179741798417994180041801418024180341804418054180641807418084180941810418114181241813418144181541816418174181841819418204182141822418234182441825418264182741828418294183041831418324183341834418354183641837418384183941840418414184241843418444184541846418474184841849418504185141852418534185441855418564185741858418594186041861418624186341864418654186641867418684186941870418714187241873418744187541876418774187841879418804188141882418834188441885418864188741888418894189041891418924189341894418954189641897418984189941900419014190241903419044190541906419074190841909419104191141912419134191441915419164191741918419194192041921419224192341924419254192641927419284192941930419314193241933419344193541936419374193841939419404194141942419434194441945419464194741948419494195041951419524195341954419554195641957419584195941960419614196241963419644196541966419674196841969419704197141972419734197441975419764197741978419794198041981419824198341984419854198641987419884198941990419914199241993419944199541996419974199841999420004200142002420034200442005420064200742008420094201042011420124201342014420154201642017420184201942020420214202242023420244202542026420274202842029420304203142032420334203442035420364203742038420394204042041420424204342044420454204642047420484204942050420514205242053420544205542056420574205842059420604206142062420634206442065420664206742068420694207042071420724207342074420754207642077420784207942080420814208242083420844208542086420874208842089420904209142092420934209442095420964209742098420994210042101421024210342104421054210642107421084210942110421114211242113421144211542116421174211842119421204212142122421234212442125421264212742128421294213042131421324213342134421354213642137421384213942140421414214242143421444214542146421474214842149421504215142152421534215442155421564215742158421594216042161421624216342164421654216642167421684216942170421714217242173421744217542176421774217842179421804218142182421834218442185421864218742188421894219042191421924219342194421954219642197421984219942200422014220242203422044220542206422074220842209422104221142212422134221442215422164221742218422194222042221422224222342224422254222642227422284222942230422314223242233422344223542236422374223842239422404224142242422434224442245422464224742248422494225042251422524225342254422554225642257422584225942260422614226242263422644226542266422674226842269422704227142272422734227442275422764227742278422794228042281422824228342284422854228642287422884228942290422914229242293422944229542296422974229842299423004230142302423034230442305423064230742308423094231042311423124231342314423154231642317423184231942320423214232242323423244232542326423274232842329423304233142332423334233442335423364233742338423394234042341423424234342344423454234642347423484234942350423514235242353423544235542356423574235842359423604236142362423634236442365423664236742368423694237042371423724237342374423754237642377423784237942380423814238242383423844238542386423874238842389423904239142392423934239442395423964239742398423994240042401424024240342404424054240642407424084240942410424114241242413424144241542416424174241842419424204242142422424234242442425424264242742428424294243042431424324243342434424354243642437424384243942440424414244242443424444244542446424474244842449424504245142452424534245442455424564245742458424594246042461424624246342464424654246642467424684246942470424714247242473424744247542476424774247842479424804248142482424834248442485424864248742488424894249042491424924249342494424954249642497424984249942500425014250242503425044250542506425074250842509425104251142512425134251442515425164251742518425194252042521425224252342524425254252642527425284252942530425314253242533425344253542536425374253842539425404254142542425434254442545425464254742548425494255042551425524255342554425554255642557425584255942560425614256242563425644256542566425674256842569425704257142572425734257442575425764257742578425794258042581425824258342584425854258642587425884258942590425914259242593425944259542596425974259842599426004260142602426034260442605426064260742608426094261042611426124261342614426154261642617426184261942620426214262242623426244262542626426274262842629426304263142632426334263442635426364263742638426394264042641426424264342644426454264642647426484264942650426514265242653426544265542656426574265842659426604266142662426634266442665426664266742668426694267042671426724267342674426754267642677426784267942680426814268242683426844268542686426874268842689426904269142692426934269442695426964269742698426994270042701427024270342704427054270642707427084270942710427114271242713427144271542716427174271842719427204272142722427234272442725427264272742728427294273042731427324273342734427354273642737427384273942740427414274242743427444274542746427474274842749427504275142752427534275442755427564275742758427594276042761427624276342764427654276642767427684276942770427714277242773427744277542776427774277842779427804278142782427834278442785427864278742788427894279042791427924279342794427954279642797427984279942800428014280242803428044280542806428074280842809428104281142812428134281442815428164281742818428194282042821428224282342824428254282642827428284282942830428314283242833428344283542836428374283842839428404284142842428434284442845428464284742848428494285042851428524285342854428554285642857428584285942860428614286242863428644286542866428674286842869428704287142872428734287442875428764287742878428794288042881428824288342884428854288642887428884288942890428914289242893428944289542896428974289842899429004290142902429034290442905429064290742908429094291042911429124291342914429154291642917429184291942920429214292242923429244292542926429274292842929429304293142932429334293442935429364293742938429394294042941429424294342944429454294642947429484294942950429514295242953429544295542956429574295842959429604296142962429634296442965429664296742968429694297042971429724297342974429754297642977429784297942980429814298242983429844298542986429874298842989429904299142992429934299442995429964299742998429994300043001430024300343004430054300643007430084300943010430114301243013430144301543016430174301843019430204302143022430234302443025430264302743028430294303043031430324303343034430354303643037430384303943040430414304243043430444304543046430474304843049430504305143052430534305443055430564305743058430594306043061430624306343064430654306643067430684306943070430714307243073430744307543076430774307843079430804308143082430834308443085430864308743088430894309043091430924309343094430954309643097430984309943100431014310243103431044310543106431074310843109431104311143112431134311443115431164311743118431194312043121431224312343124431254312643127431284312943130431314313243133431344313543136431374313843139431404314143142431434314443145431464314743148431494315043151431524315343154431554315643157431584315943160431614316243163431644316543166431674316843169431704317143172431734317443175431764317743178431794318043181431824318343184431854318643187431884318943190431914319243193431944319543196431974319843199432004320143202432034320443205432064320743208432094321043211432124321343214432154321643217432184321943220432214322243223432244322543226432274322843229432304323143232432334323443235432364323743238432394324043241432424324343244432454324643247432484324943250432514325243253432544325543256432574325843259432604326143262432634326443265432664326743268432694327043271432724327343274432754327643277432784327943280432814328243283432844328543286432874328843289432904329143292432934329443295432964329743298432994330043301433024330343304433054330643307433084330943310433114331243313433144331543316433174331843319433204332143322433234332443325433264332743328433294333043331433324333343334433354333643337433384333943340433414334243343433444334543346433474334843349433504335143352433534335443355433564335743358433594336043361433624336343364433654336643367433684336943370433714337243373433744337543376433774337843379433804338143382433834338443385433864338743388433894339043391433924339343394433954339643397433984339943400434014340243403434044340543406434074340843409434104341143412434134341443415434164341743418434194342043421434224342343424434254342643427434284342943430434314343243433434344343543436434374343843439434404344143442434434344443445434464344743448434494345043451434524345343454434554345643457434584345943460434614346243463434644346543466434674346843469434704347143472434734347443475434764347743478434794348043481434824348343484434854348643487434884348943490434914349243493434944349543496434974349843499435004350143502435034350443505435064350743508435094351043511435124351343514435154351643517435184351943520435214352243523435244352543526435274352843529435304353143532435334353443535435364353743538435394354043541435424354343544435454354643547435484354943550435514355243553435544355543556435574355843559435604356143562435634356443565435664356743568435694357043571435724357343574435754357643577435784357943580435814358243583435844358543586435874358843589435904359143592435934359443595435964359743598435994360043601436024360343604436054360643607436084360943610436114361243613436144361543616436174361843619436204362143622436234362443625436264362743628436294363043631436324363343634436354363643637436384363943640436414364243643436444364543646436474364843649436504365143652436534365443655436564365743658436594366043661436624366343664436654366643667436684366943670436714367243673436744367543676436774367843679436804368143682436834368443685436864368743688436894369043691436924369343694436954369643697436984369943700437014370243703437044370543706437074370843709437104371143712437134371443715437164371743718437194372043721437224372343724437254372643727437284372943730437314373243733437344373543736437374373843739437404374143742437434374443745437464374743748437494375043751437524375343754437554375643757437584375943760437614376243763437644376543766437674376843769437704377143772437734377443775437764377743778437794378043781437824378343784437854378643787437884378943790437914379243793437944379543796437974379843799438004380143802438034380443805438064380743808438094381043811438124381343814438154381643817438184381943820438214382243823438244382543826438274382843829438304383143832438334383443835438364383743838438394384043841438424384343844438454384643847438484384943850438514385243853438544385543856438574385843859438604386143862438634386443865438664386743868438694387043871438724387343874438754387643877438784387943880438814388243883438844388543886438874388843889438904389143892438934389443895438964389743898438994390043901439024390343904439054390643907439084390943910439114391243913439144391543916439174391843919439204392143922439234392443925439264392743928439294393043931439324393343934439354393643937439384393943940439414394243943439444394543946439474394843949439504395143952439534395443955439564395743958439594396043961439624396343964439654396643967439684396943970439714397243973439744397543976439774397843979439804398143982439834398443985439864398743988439894399043991439924399343994439954399643997439984399944000440014400244003440044400544006440074400844009440104401144012440134401444015440164401744018440194402044021440224402344024440254402644027440284402944030440314403244033440344403544036440374403844039440404404144042440434404444045440464404744048440494405044051440524405344054440554405644057440584405944060440614406244063440644406544066440674406844069440704407144072440734407444075440764407744078440794408044081440824408344084440854408644087440884408944090440914409244093440944409544096440974409844099441004410144102441034410444105441064410744108441094411044111441124411344114441154411644117441184411944120441214412244123441244412544126441274412844129441304413144132441334413444135441364413744138441394414044141441424414344144441454414644147441484414944150441514415244153441544415544156441574415844159441604416144162441634416444165441664416744168441694417044171441724417344174441754417644177441784417944180441814418244183441844418544186441874418844189441904419144192441934419444195441964419744198441994420044201442024420344204442054420644207442084420944210442114421244213442144421544216442174421844219442204422144222442234422444225442264422744228442294423044231442324423344234442354423644237442384423944240442414424244243442444424544246442474424844249442504425144252442534425444255442564425744258442594426044261442624426344264442654426644267442684426944270442714427244273442744427544276442774427844279442804428144282442834428444285442864428744288442894429044291442924429344294442954429644297442984429944300443014430244303443044430544306443074430844309443104431144312443134431444315443164431744318443194432044321443224432344324443254432644327443284432944330443314433244333443344433544336443374433844339443404434144342443434434444345443464434744348443494435044351443524435344354443554435644357443584435944360443614436244363443644436544366443674436844369443704437144372443734437444375443764437744378443794438044381443824438344384443854438644387443884438944390443914439244393443944439544396443974439844399444004440144402444034440444405444064440744408444094441044411444124441344414444154441644417444184441944420444214442244423444244442544426444274442844429444304443144432444334443444435444364443744438444394444044441444424444344444444454444644447444484444944450444514445244453444544445544456444574445844459444604446144462444634446444465444664446744468444694447044471444724447344474444754447644477444784447944480444814448244483444844448544486444874448844489444904449144492444934449444495444964449744498444994450044501445024450344504445054450644507445084450944510445114451244513445144451544516445174451844519445204452144522445234452444525445264452744528445294453044531445324453344534445354453644537445384453944540445414454244543445444454544546445474454844549445504455144552445534455444555445564455744558445594456044561445624456344564445654456644567445684456944570445714457244573445744457544576445774457844579445804458144582445834458444585445864458744588445894459044591445924459344594445954459644597445984459944600446014460244603446044460544606446074460844609446104461144612446134461444615446164461744618446194462044621446224462344624446254462644627446284462944630446314463244633446344463544636446374463844639446404464144642446434464444645446464464744648446494465044651446524465344654446554465644657446584465944660446614466244663446644466544666446674466844669446704467144672446734467444675446764467744678446794468044681446824468344684446854468644687446884468944690446914469244693446944469544696446974469844699447004470144702447034470444705447064470744708447094471044711447124471344714447154471644717447184471944720447214472244723447244472544726447274472844729447304473144732447334473444735447364473744738447394474044741447424474344744447454474644747447484474944750447514475244753447544475544756447574475844759447604476144762447634476444765447664476744768447694477044771447724477344774447754477644777447784477944780447814478244783447844478544786447874478844789447904479144792447934479444795447964479744798447994480044801448024480344804448054480644807448084480944810448114481244813448144481544816448174481844819448204482144822448234482444825448264482744828448294483044831448324483344834448354483644837448384483944840448414484244843448444484544846448474484844849448504485144852448534485444855448564485744858448594486044861448624486344864448654486644867448684486944870448714487244873448744487544876448774487844879448804488144882448834488444885448864488744888448894489044891448924489344894448954489644897448984489944900449014490244903449044490544906449074490844909449104491144912449134491444915449164491744918449194492044921449224492344924449254492644927449284492944930449314493244933449344493544936449374493844939449404494144942449434494444945449464494744948449494495044951449524495344954449554495644957449584495944960449614496244963449644496544966449674496844969449704497144972449734497444975449764497744978449794498044981449824498344984449854498644987449884498944990449914499244993449944499544996449974499844999450004500145002450034500445005450064500745008450094501045011450124501345014450154501645017450184501945020450214502245023450244502545026450274502845029450304503145032450334503445035450364503745038450394504045041450424504345044450454504645047450484504945050450514505245053450544505545056450574505845059450604506145062450634506445065450664506745068450694507045071450724507345074450754507645077450784507945080450814508245083450844508545086450874508845089450904509145092450934509445095450964509745098450994510045101451024510345104451054510645107451084510945110451114511245113451144511545116451174511845119451204512145122451234512445125451264512745128451294513045131451324513345134451354513645137451384513945140451414514245143451444514545146451474514845149451504515145152451534515445155451564515745158451594516045161451624516345164451654516645167451684516945170451714517245173451744517545176451774517845179451804518145182451834518445185451864518745188451894519045191451924519345194451954519645197451984519945200452014520245203452044520545206452074520845209452104521145212452134521445215452164521745218452194522045221452224522345224452254522645227452284522945230452314523245233452344523545236452374523845239452404524145242452434524445245452464524745248452494525045251452524525345254452554525645257452584525945260452614526245263452644526545266452674526845269452704527145272452734527445275452764527745278452794528045281452824528345284452854528645287452884528945290452914529245293452944529545296452974529845299453004530145302453034530445305453064530745308453094531045311453124531345314453154531645317453184531945320453214532245323453244532545326453274532845329453304533145332453334533445335453364533745338453394534045341453424534345344453454534645347453484534945350453514535245353453544535545356453574535845359453604536145362453634536445365453664536745368453694537045371453724537345374453754537645377453784537945380453814538245383453844538545386453874538845389453904539145392453934539445395453964539745398453994540045401454024540345404454054540645407454084540945410454114541245413454144541545416454174541845419454204542145422454234542445425454264542745428454294543045431454324543345434454354543645437454384543945440454414544245443454444544545446454474544845449454504545145452454534545445455454564545745458454594546045461454624546345464454654546645467454684546945470454714547245473454744547545476454774547845479454804548145482454834548445485454864548745488454894549045491454924549345494454954549645497454984549945500455014550245503455044550545506455074550845509455104551145512455134551445515455164551745518455194552045521455224552345524455254552645527455284552945530455314553245533455344553545536455374553845539455404554145542455434554445545455464554745548455494555045551455524555345554455554555645557455584555945560455614556245563455644556545566455674556845569455704557145572455734557445575455764557745578455794558045581455824558345584455854558645587455884558945590455914559245593455944559545596455974559845599456004560145602456034560445605456064560745608456094561045611456124561345614456154561645617456184561945620456214562245623456244562545626456274562845629456304563145632456334563445635456364563745638456394564045641456424564345644456454564645647456484564945650456514565245653456544565545656456574565845659456604566145662456634566445665456664566745668456694567045671456724567345674456754567645677456784567945680456814568245683456844568545686456874568845689456904569145692456934569445695456964569745698456994570045701457024570345704457054570645707457084570945710457114571245713457144571545716457174571845719457204572145722457234572445725457264572745728457294573045731457324573345734457354573645737457384573945740457414574245743457444574545746457474574845749457504575145752457534575445755457564575745758457594576045761457624576345764457654576645767457684576945770457714577245773457744577545776457774577845779457804578145782457834578445785457864578745788457894579045791457924579345794457954579645797457984579945800458014580245803458044580545806458074580845809458104581145812458134581445815458164581745818458194582045821458224582345824458254582645827458284582945830458314583245833458344583545836458374583845839458404584145842458434584445845458464584745848458494585045851458524585345854458554585645857458584585945860458614586245863458644586545866458674586845869458704587145872458734587445875458764587745878458794588045881458824588345884458854588645887458884588945890458914589245893458944589545896458974589845899459004590145902459034590445905459064590745908459094591045911459124591345914459154591645917459184591945920459214592245923459244592545926459274592845929459304593145932459334593445935459364593745938459394594045941459424594345944459454594645947459484594945950459514595245953459544595545956459574595845959459604596145962459634596445965459664596745968459694597045971459724597345974459754597645977459784597945980459814598245983459844598545986459874598845989459904599145992459934599445995459964599745998459994600046001460024600346004460054600646007460084600946010460114601246013460144601546016460174601846019460204602146022460234602446025460264602746028460294603046031460324603346034460354603646037460384603946040460414604246043460444604546046460474604846049460504605146052460534605446055460564605746058460594606046061460624606346064460654606646067460684606946070460714607246073460744607546076460774607846079460804608146082460834608446085460864608746088460894609046091460924609346094460954609646097460984609946100461014610246103461044610546106461074610846109461104611146112461134611446115461164611746118461194612046121461224612346124461254612646127461284612946130461314613246133461344613546136461374613846139461404614146142461434614446145461464614746148461494615046151461524615346154461554615646157461584615946160461614616246163461644616546166461674616846169461704617146172461734617446175461764617746178461794618046181461824618346184461854618646187461884618946190461914619246193461944619546196461974619846199462004620146202462034620446205462064620746208462094621046211462124621346214462154621646217462184621946220462214622246223462244622546226462274622846229462304623146232462334623446235462364623746238462394624046241462424624346244462454624646247462484624946250462514625246253462544625546256462574625846259462604626146262462634626446265462664626746268462694627046271462724627346274462754627646277462784627946280462814628246283462844628546286462874628846289462904629146292462934629446295462964629746298462994630046301463024630346304463054630646307463084630946310463114631246313463144631546316463174631846319463204632146322463234632446325463264632746328463294633046331463324633346334463354633646337463384633946340463414634246343463444634546346463474634846349463504635146352463534635446355463564635746358463594636046361463624636346364463654636646367463684636946370463714637246373463744637546376463774637846379463804638146382463834638446385463864638746388463894639046391463924639346394463954639646397463984639946400464014640246403464044640546406464074640846409464104641146412464134641446415464164641746418464194642046421464224642346424464254642646427464284642946430464314643246433464344643546436464374643846439464404644146442464434644446445464464644746448464494645046451464524645346454464554645646457464584645946460464614646246463464644646546466464674646846469464704647146472464734647446475464764647746478464794648046481464824648346484464854648646487464884648946490464914649246493464944649546496464974649846499465004650146502465034650446505465064650746508465094651046511465124651346514465154651646517465184651946520465214652246523465244652546526465274652846529465304653146532465334653446535465364653746538465394654046541465424654346544465454654646547465484654946550465514655246553465544655546556465574655846559465604656146562465634656446565465664656746568465694657046571465724657346574465754657646577465784657946580465814658246583465844658546586465874658846589465904659146592465934659446595465964659746598465994660046601466024660346604466054660646607466084660946610466114661246613466144661546616466174661846619466204662146622466234662446625466264662746628466294663046631466324663346634466354663646637466384663946640466414664246643466444664546646466474664846649466504665146652466534665446655466564665746658466594666046661466624666346664466654666646667466684666946670466714667246673466744667546676466774667846679466804668146682466834668446685466864668746688466894669046691466924669346694466954669646697466984669946700467014670246703467044670546706467074670846709467104671146712467134671446715467164671746718467194672046721467224672346724467254672646727467284672946730467314673246733467344673546736467374673846739467404674146742467434674446745467464674746748467494675046751467524675346754467554675646757467584675946760467614676246763467644676546766467674676846769467704677146772467734677446775467764677746778467794678046781467824678346784467854678646787467884678946790467914679246793467944679546796467974679846799468004680146802468034680446805468064680746808468094681046811468124681346814468154681646817468184681946820468214682246823468244682546826468274682846829468304683146832468334683446835468364683746838468394684046841468424684346844468454684646847468484684946850468514685246853468544685546856468574685846859468604686146862468634686446865468664686746868468694687046871468724687346874468754687646877468784687946880468814688246883468844688546886468874688846889468904689146892468934689446895468964689746898468994690046901469024690346904469054690646907469084690946910469114691246913469144691546916469174691846919469204692146922469234692446925469264692746928469294693046931469324693346934469354693646937469384693946940469414694246943469444694546946469474694846949469504695146952469534695446955469564695746958469594696046961469624696346964469654696646967469684696946970469714697246973469744697546976469774697846979469804698146982469834698446985469864698746988469894699046991469924699346994469954699646997469984699947000470014700247003470044700547006470074700847009470104701147012470134701447015470164701747018470194702047021470224702347024470254702647027470284702947030470314703247033470344703547036470374703847039470404704147042470434704447045470464704747048470494705047051470524705347054470554705647057470584705947060470614706247063470644706547066470674706847069470704707147072470734707447075470764707747078470794708047081470824708347084470854708647087470884708947090470914709247093470944709547096470974709847099471004710147102471034710447105471064710747108471094711047111471124711347114471154711647117471184711947120471214712247123471244712547126471274712847129471304713147132471334713447135471364713747138471394714047141471424714347144471454714647147471484714947150471514715247153471544715547156471574715847159471604716147162471634716447165471664716747168471694717047171471724717347174471754717647177471784717947180471814718247183471844718547186471874718847189471904719147192471934719447195471964719747198471994720047201472024720347204472054720647207472084720947210472114721247213472144721547216472174721847219472204722147222472234722447225472264722747228472294723047231472324723347234472354723647237472384723947240472414724247243472444724547246472474724847249472504725147252472534725447255472564725747258472594726047261472624726347264472654726647267472684726947270472714727247273472744727547276472774727847279472804728147282472834728447285472864728747288472894729047291472924729347294472954729647297472984729947300473014730247303473044730547306473074730847309473104731147312473134731447315473164731747318473194732047321473224732347324473254732647327473284732947330473314733247333473344733547336473374733847339473404734147342473434734447345473464734747348473494735047351473524735347354473554735647357473584735947360473614736247363473644736547366473674736847369473704737147372473734737447375473764737747378473794738047381473824738347384473854738647387473884738947390473914739247393473944739547396473974739847399474004740147402474034740447405474064740747408474094741047411474124741347414474154741647417474184741947420474214742247423474244742547426474274742847429474304743147432474334743447435474364743747438474394744047441474424744347444474454744647447474484744947450474514745247453474544745547456474574745847459474604746147462474634746447465474664746747468474694747047471474724747347474474754747647477474784747947480474814748247483474844748547486474874748847489474904749147492474934749447495474964749747498474994750047501475024750347504475054750647507475084750947510475114751247513475144751547516475174751847519475204752147522475234752447525475264752747528475294753047531475324753347534475354753647537475384753947540475414754247543475444754547546475474754847549475504755147552475534755447555475564755747558475594756047561475624756347564475654756647567475684756947570475714757247573475744757547576475774757847579475804758147582475834758447585475864758747588475894759047591475924759347594475954759647597475984759947600476014760247603476044760547606476074760847609476104761147612476134761447615476164761747618476194762047621476224762347624476254762647627476284762947630476314763247633476344763547636476374763847639476404764147642476434764447645476464764747648476494765047651476524765347654476554765647657476584765947660476614766247663476644766547666476674766847669476704767147672476734767447675476764767747678476794768047681476824768347684476854768647687476884768947690476914769247693476944769547696476974769847699477004770147702477034770447705477064770747708477094771047711477124771347714477154771647717477184771947720477214772247723477244772547726477274772847729477304773147732477334773447735477364773747738477394774047741477424774347744477454774647747477484774947750477514775247753477544775547756477574775847759477604776147762477634776447765477664776747768477694777047771477724777347774477754777647777477784777947780477814778247783477844778547786477874778847789477904779147792477934779447795477964779747798477994780047801478024780347804478054780647807478084780947810478114781247813478144781547816478174781847819478204782147822478234782447825478264782747828478294783047831478324783347834478354783647837478384783947840478414784247843478444784547846478474784847849478504785147852478534785447855478564785747858478594786047861478624786347864478654786647867478684786947870478714787247873478744787547876478774787847879478804788147882478834788447885478864788747888478894789047891478924789347894478954789647897478984789947900479014790247903479044790547906479074790847909479104791147912479134791447915479164791747918479194792047921479224792347924479254792647927479284792947930479314793247933479344793547936479374793847939479404794147942479434794447945479464794747948479494795047951479524795347954479554795647957479584795947960479614796247963479644796547966479674796847969479704797147972479734797447975479764797747978479794798047981479824798347984479854798647987479884798947990479914799247993479944799547996479974799847999480004800148002480034800448005480064800748008480094801048011480124801348014480154801648017480184801948020480214802248023480244802548026480274802848029480304803148032480334803448035480364803748038480394804048041480424804348044480454804648047480484804948050480514805248053480544805548056480574805848059480604806148062480634806448065480664806748068480694807048071480724807348074480754807648077480784807948080480814808248083480844808548086480874808848089480904809148092480934809448095480964809748098480994810048101481024810348104481054810648107481084810948110481114811248113481144811548116481174811848119481204812148122481234812448125481264812748128481294813048131481324813348134481354813648137481384813948140481414814248143481444814548146481474814848149481504815148152481534815448155481564815748158481594816048161481624816348164481654816648167481684816948170481714817248173481744817548176481774817848179481804818148182481834818448185481864818748188481894819048191481924819348194481954819648197481984819948200482014820248203482044820548206482074820848209482104821148212482134821448215482164821748218482194822048221482224822348224482254822648227482284822948230482314823248233482344823548236482374823848239482404824148242482434824448245482464824748248482494825048251482524825348254482554825648257482584825948260482614826248263482644826548266482674826848269482704827148272482734827448275482764827748278482794828048281482824828348284482854828648287482884828948290482914829248293482944829548296482974829848299483004830148302483034830448305483064830748308483094831048311483124831348314483154831648317483184831948320483214832248323483244832548326483274832848329483304833148332483334833448335483364833748338483394834048341483424834348344483454834648347
  1. /* Copyright 2012 Mozilla Foundation
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. /*jshint globalstrict: false */
  16. /* globals PDFJS */
  17. // Initializing PDFJS global object (if still undefined)
  18. if (typeof PDFJS === 'undefined') {
  19. (typeof window !== 'undefined' ? window : this).PDFJS = {};
  20. }
  21. PDFJS.version = '1.3.114';
  22. PDFJS.build = '9228e1f';
  23. (function pdfjsWrapper() {
  24. // Use strict in our context only - users might not want it
  25. 'use strict';
  26. (function (root, factory) {
  27. {
  28. factory((root.pdfjsSharedGlobal = {}));
  29. }
  30. }(this, function (exports) {
  31. var globalScope = (typeof window !== 'undefined') ? window :
  32. (typeof global !== 'undefined') ? global :
  33. (typeof self !== 'undefined') ? self : this;
  34. var isWorker = (typeof window === 'undefined');
  35. // The global PDFJS object exposes the API
  36. // In production, it will be declared outside a global wrapper
  37. // In development, it will be declared here
  38. if (!globalScope.PDFJS) {
  39. globalScope.PDFJS = {};
  40. }
  41. globalScope.PDFJS.pdfBug = false;
  42. exports.globalScope = globalScope;
  43. exports.isWorker = isWorker;
  44. exports.PDFJS = globalScope.PDFJS;
  45. }));
  46. (function (root, factory) {
  47. {
  48. factory((root.pdfjsSharedUtil = {}), root.pdfjsSharedGlobal);
  49. }
  50. }(this, function (exports, sharedGlobal) {
  51. var PDFJS = sharedGlobal.PDFJS;
  52. var globalScope = sharedGlobal.globalScope;
  53. var FONT_IDENTITY_MATRIX = [0.001, 0, 0, 0.001, 0, 0];
  54. var TextRenderingMode = {
  55. FILL: 0,
  56. STROKE: 1,
  57. FILL_STROKE: 2,
  58. INVISIBLE: 3,
  59. FILL_ADD_TO_PATH: 4,
  60. STROKE_ADD_TO_PATH: 5,
  61. FILL_STROKE_ADD_TO_PATH: 6,
  62. ADD_TO_PATH: 7,
  63. FILL_STROKE_MASK: 3,
  64. ADD_TO_PATH_FLAG: 4
  65. };
  66. var ImageKind = {
  67. GRAYSCALE_1BPP: 1,
  68. RGB_24BPP: 2,
  69. RGBA_32BPP: 3
  70. };
  71. var AnnotationType = {
  72. TEXT: 1,
  73. LINK: 2,
  74. FREETEXT: 3,
  75. LINE: 4,
  76. SQUARE: 5,
  77. CIRCLE: 6,
  78. POLYGON: 7,
  79. POLYLINE: 8,
  80. HIGHLIGHT: 9,
  81. UNDERLINE: 10,
  82. SQUIGGLY: 11,
  83. STRIKEOUT: 12,
  84. STAMP: 13,
  85. CARET: 14,
  86. INK: 15,
  87. POPUP: 16,
  88. FILEATTACHMENT: 17,
  89. SOUND: 18,
  90. MOVIE: 19,
  91. WIDGET: 20,
  92. SCREEN: 21,
  93. PRINTERMARK: 22,
  94. TRAPNET: 23,
  95. WATERMARK: 24,
  96. THREED: 25,
  97. REDACT: 26
  98. };
  99. var AnnotationFlag = {
  100. INVISIBLE: 0x01,
  101. HIDDEN: 0x02,
  102. PRINT: 0x04,
  103. NOZOOM: 0x08,
  104. NOROTATE: 0x10,
  105. NOVIEW: 0x20,
  106. READONLY: 0x40,
  107. LOCKED: 0x80,
  108. TOGGLENOVIEW: 0x100,
  109. LOCKEDCONTENTS: 0x200
  110. };
  111. var AnnotationBorderStyleType = {
  112. SOLID: 1,
  113. DASHED: 2,
  114. BEVELED: 3,
  115. INSET: 4,
  116. UNDERLINE: 5
  117. };
  118. var StreamType = {
  119. UNKNOWN: 0,
  120. FLATE: 1,
  121. LZW: 2,
  122. DCT: 3,
  123. JPX: 4,
  124. JBIG: 5,
  125. A85: 6,
  126. AHX: 7,
  127. CCF: 8,
  128. RL: 9
  129. };
  130. var FontType = {
  131. UNKNOWN: 0,
  132. TYPE1: 1,
  133. TYPE1C: 2,
  134. CIDFONTTYPE0: 3,
  135. CIDFONTTYPE0C: 4,
  136. TRUETYPE: 5,
  137. CIDFONTTYPE2: 6,
  138. TYPE3: 7,
  139. OPENTYPE: 8,
  140. TYPE0: 9,
  141. MMTYPE1: 10
  142. };
  143. PDFJS.VERBOSITY_LEVELS = {
  144. errors: 0,
  145. warnings: 1,
  146. infos: 5
  147. };
  148. // All the possible operations for an operator list.
  149. var OPS = PDFJS.OPS = {
  150. // Intentionally start from 1 so it is easy to spot bad operators that will be
  151. // 0's.
  152. dependency: 1,
  153. setLineWidth: 2,
  154. setLineCap: 3,
  155. setLineJoin: 4,
  156. setMiterLimit: 5,
  157. setDash: 6,
  158. setRenderingIntent: 7,
  159. setFlatness: 8,
  160. setGState: 9,
  161. save: 10,
  162. restore: 11,
  163. transform: 12,
  164. moveTo: 13,
  165. lineTo: 14,
  166. curveTo: 15,
  167. curveTo2: 16,
  168. curveTo3: 17,
  169. closePath: 18,
  170. rectangle: 19,
  171. stroke: 20,
  172. closeStroke: 21,
  173. fill: 22,
  174. eoFill: 23,
  175. fillStroke: 24,
  176. eoFillStroke: 25,
  177. closeFillStroke: 26,
  178. closeEOFillStroke: 27,
  179. endPath: 28,
  180. clip: 29,
  181. eoClip: 30,
  182. beginText: 31,
  183. endText: 32,
  184. setCharSpacing: 33,
  185. setWordSpacing: 34,
  186. setHScale: 35,
  187. setLeading: 36,
  188. setFont: 37,
  189. setTextRenderingMode: 38,
  190. setTextRise: 39,
  191. moveText: 40,
  192. setLeadingMoveText: 41,
  193. setTextMatrix: 42,
  194. nextLine: 43,
  195. showText: 44,
  196. showSpacedText: 45,
  197. nextLineShowText: 46,
  198. nextLineSetSpacingShowText: 47,
  199. setCharWidth: 48,
  200. setCharWidthAndBounds: 49,
  201. setStrokeColorSpace: 50,
  202. setFillColorSpace: 51,
  203. setStrokeColor: 52,
  204. setStrokeColorN: 53,
  205. setFillColor: 54,
  206. setFillColorN: 55,
  207. setStrokeGray: 56,
  208. setFillGray: 57,
  209. setStrokeRGBColor: 58,
  210. setFillRGBColor: 59,
  211. setStrokeCMYKColor: 60,
  212. setFillCMYKColor: 61,
  213. shadingFill: 62,
  214. beginInlineImage: 63,
  215. beginImageData: 64,
  216. endInlineImage: 65,
  217. paintXObject: 66,
  218. markPoint: 67,
  219. markPointProps: 68,
  220. beginMarkedContent: 69,
  221. beginMarkedContentProps: 70,
  222. endMarkedContent: 71,
  223. beginCompat: 72,
  224. endCompat: 73,
  225. paintFormXObjectBegin: 74,
  226. paintFormXObjectEnd: 75,
  227. beginGroup: 76,
  228. endGroup: 77,
  229. beginAnnotations: 78,
  230. endAnnotations: 79,
  231. beginAnnotation: 80,
  232. endAnnotation: 81,
  233. paintJpegXObject: 82,
  234. paintImageMaskXObject: 83,
  235. paintImageMaskXObjectGroup: 84,
  236. paintImageXObject: 85,
  237. paintInlineImageXObject: 86,
  238. paintInlineImageXObjectGroup: 87,
  239. paintImageXObjectRepeat: 88,
  240. paintImageMaskXObjectRepeat: 89,
  241. paintSolidColorImageMask: 90,
  242. constructPath: 91
  243. };
  244. // A notice for devs. These are good for things that are helpful to devs, such
  245. // as warning that Workers were disabled, which is important to devs but not
  246. // end users.
  247. function info(msg) {
  248. if (PDFJS.verbosity >= PDFJS.VERBOSITY_LEVELS.infos) {
  249. console.log('Info: ' + msg);
  250. }
  251. }
  252. // Non-fatal warnings.
  253. function warn(msg) {
  254. if (PDFJS.verbosity >= PDFJS.VERBOSITY_LEVELS.warnings) {
  255. console.log('Warning: ' + msg);
  256. }
  257. }
  258. // Deprecated API function -- treated as warnings.
  259. function deprecated(details) {
  260. warn('Deprecated API usage: ' + details);
  261. }
  262. // Fatal errors that should trigger the fallback UI and halt execution by
  263. // throwing an exception.
  264. function error(msg) {
  265. if (PDFJS.verbosity >= PDFJS.VERBOSITY_LEVELS.errors) {
  266. console.log('Error: ' + msg);
  267. console.log(backtrace());
  268. }
  269. throw new Error(msg);
  270. }
  271. function backtrace() {
  272. try {
  273. throw new Error();
  274. } catch (e) {
  275. return e.stack ? e.stack.split('\n').slice(2).join('\n') : '';
  276. }
  277. }
  278. function assert(cond, msg) {
  279. if (!cond) {
  280. error(msg);
  281. }
  282. }
  283. var UNSUPPORTED_FEATURES = PDFJS.UNSUPPORTED_FEATURES = {
  284. unknown: 'unknown',
  285. forms: 'forms',
  286. javaScript: 'javaScript',
  287. smask: 'smask',
  288. shadingPattern: 'shadingPattern',
  289. font: 'font'
  290. };
  291. // Combines two URLs. The baseUrl shall be absolute URL. If the url is an
  292. // absolute URL, it will be returned as is.
  293. function combineUrl(baseUrl, url) {
  294. if (!url) {
  295. return baseUrl;
  296. }
  297. if (/^[a-z][a-z0-9+\-.]*:/i.test(url)) {
  298. return url;
  299. }
  300. var i;
  301. if (url.charAt(0) === '/') {
  302. // absolute path
  303. i = baseUrl.indexOf('://');
  304. if (url.charAt(1) === '/') {
  305. ++i;
  306. } else {
  307. i = baseUrl.indexOf('/', i + 3);
  308. }
  309. return baseUrl.substring(0, i) + url;
  310. } else {
  311. // relative path
  312. var pathLength = baseUrl.length;
  313. i = baseUrl.lastIndexOf('#');
  314. pathLength = i >= 0 ? i : pathLength;
  315. i = baseUrl.lastIndexOf('?', pathLength);
  316. pathLength = i >= 0 ? i : pathLength;
  317. var prefixLength = baseUrl.lastIndexOf('/', pathLength);
  318. return baseUrl.substring(0, prefixLength + 1) + url;
  319. }
  320. }
  321. // Validates if URL is safe and allowed, e.g. to avoid XSS.
  322. function isValidUrl(url, allowRelative) {
  323. if (!url) {
  324. return false;
  325. }
  326. // RFC 3986 (http://tools.ietf.org/html/rfc3986#section-3.1)
  327. // scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
  328. var protocol = /^[a-z][a-z0-9+\-.]*(?=:)/i.exec(url);
  329. if (!protocol) {
  330. return allowRelative;
  331. }
  332. protocol = protocol[0].toLowerCase();
  333. switch (protocol) {
  334. case 'http':
  335. case 'https':
  336. case 'ftp':
  337. case 'mailto':
  338. case 'tel':
  339. return true;
  340. default:
  341. return false;
  342. }
  343. }
  344. PDFJS.isValidUrl = isValidUrl;
  345. function shadow(obj, prop, value) {
  346. Object.defineProperty(obj, prop, { value: value,
  347. enumerable: true,
  348. configurable: true,
  349. writable: false });
  350. return value;
  351. }
  352. PDFJS.shadow = shadow;
  353. var LinkTarget = PDFJS.LinkTarget = {
  354. NONE: 0, // Default value.
  355. SELF: 1,
  356. BLANK: 2,
  357. PARENT: 3,
  358. TOP: 4,
  359. };
  360. var LinkTargetStringMap = [
  361. '',
  362. '_self',
  363. '_blank',
  364. '_parent',
  365. '_top'
  366. ];
  367. function isExternalLinkTargetSet() {
  368. if (PDFJS.openExternalLinksInNewWindow) {
  369. deprecated('PDFJS.openExternalLinksInNewWindow, please use ' +
  370. '"PDFJS.externalLinkTarget = PDFJS.LinkTarget.BLANK" instead.');
  371. if (PDFJS.externalLinkTarget === LinkTarget.NONE) {
  372. PDFJS.externalLinkTarget = LinkTarget.BLANK;
  373. }
  374. // Reset the deprecated parameter, to suppress further warnings.
  375. PDFJS.openExternalLinksInNewWindow = false;
  376. }
  377. switch (PDFJS.externalLinkTarget) {
  378. case LinkTarget.NONE:
  379. return false;
  380. case LinkTarget.SELF:
  381. case LinkTarget.BLANK:
  382. case LinkTarget.PARENT:
  383. case LinkTarget.TOP:
  384. return true;
  385. }
  386. warn('PDFJS.externalLinkTarget is invalid: ' + PDFJS.externalLinkTarget);
  387. // Reset the external link target, to suppress further warnings.
  388. PDFJS.externalLinkTarget = LinkTarget.NONE;
  389. return false;
  390. }
  391. PDFJS.isExternalLinkTargetSet = isExternalLinkTargetSet;
  392. var PasswordResponses = PDFJS.PasswordResponses = {
  393. NEED_PASSWORD: 1,
  394. INCORRECT_PASSWORD: 2
  395. };
  396. var PasswordException = (function PasswordExceptionClosure() {
  397. function PasswordException(msg, code) {
  398. this.name = 'PasswordException';
  399. this.message = msg;
  400. this.code = code;
  401. }
  402. PasswordException.prototype = new Error();
  403. PasswordException.constructor = PasswordException;
  404. return PasswordException;
  405. })();
  406. PDFJS.PasswordException = PasswordException;
  407. var UnknownErrorException = (function UnknownErrorExceptionClosure() {
  408. function UnknownErrorException(msg, details) {
  409. this.name = 'UnknownErrorException';
  410. this.message = msg;
  411. this.details = details;
  412. }
  413. UnknownErrorException.prototype = new Error();
  414. UnknownErrorException.constructor = UnknownErrorException;
  415. return UnknownErrorException;
  416. })();
  417. PDFJS.UnknownErrorException = UnknownErrorException;
  418. var InvalidPDFException = (function InvalidPDFExceptionClosure() {
  419. function InvalidPDFException(msg) {
  420. this.name = 'InvalidPDFException';
  421. this.message = msg;
  422. }
  423. InvalidPDFException.prototype = new Error();
  424. InvalidPDFException.constructor = InvalidPDFException;
  425. return InvalidPDFException;
  426. })();
  427. PDFJS.InvalidPDFException = InvalidPDFException;
  428. var MissingPDFException = (function MissingPDFExceptionClosure() {
  429. function MissingPDFException(msg) {
  430. this.name = 'MissingPDFException';
  431. this.message = msg;
  432. }
  433. MissingPDFException.prototype = new Error();
  434. MissingPDFException.constructor = MissingPDFException;
  435. return MissingPDFException;
  436. })();
  437. PDFJS.MissingPDFException = MissingPDFException;
  438. var UnexpectedResponseException =
  439. (function UnexpectedResponseExceptionClosure() {
  440. function UnexpectedResponseException(msg, status) {
  441. this.name = 'UnexpectedResponseException';
  442. this.message = msg;
  443. this.status = status;
  444. }
  445. UnexpectedResponseException.prototype = new Error();
  446. UnexpectedResponseException.constructor = UnexpectedResponseException;
  447. return UnexpectedResponseException;
  448. })();
  449. PDFJS.UnexpectedResponseException = UnexpectedResponseException;
  450. var NotImplementedException = (function NotImplementedExceptionClosure() {
  451. function NotImplementedException(msg) {
  452. this.message = msg;
  453. }
  454. NotImplementedException.prototype = new Error();
  455. NotImplementedException.prototype.name = 'NotImplementedException';
  456. NotImplementedException.constructor = NotImplementedException;
  457. return NotImplementedException;
  458. })();
  459. var MissingDataException = (function MissingDataExceptionClosure() {
  460. function MissingDataException(begin, end) {
  461. this.begin = begin;
  462. this.end = end;
  463. this.message = 'Missing data [' + begin + ', ' + end + ')';
  464. }
  465. MissingDataException.prototype = new Error();
  466. MissingDataException.prototype.name = 'MissingDataException';
  467. MissingDataException.constructor = MissingDataException;
  468. return MissingDataException;
  469. })();
  470. var XRefParseException = (function XRefParseExceptionClosure() {
  471. function XRefParseException(msg) {
  472. this.message = msg;
  473. }
  474. XRefParseException.prototype = new Error();
  475. XRefParseException.prototype.name = 'XRefParseException';
  476. XRefParseException.constructor = XRefParseException;
  477. return XRefParseException;
  478. })();
  479. function bytesToString(bytes) {
  480. assert(bytes !== null && typeof bytes === 'object' &&
  481. bytes.length !== undefined, 'Invalid argument for bytesToString');
  482. var length = bytes.length;
  483. var MAX_ARGUMENT_COUNT = 8192;
  484. if (length < MAX_ARGUMENT_COUNT) {
  485. return String.fromCharCode.apply(null, bytes);
  486. }
  487. var strBuf = [];
  488. for (var i = 0; i < length; i += MAX_ARGUMENT_COUNT) {
  489. var chunkEnd = Math.min(i + MAX_ARGUMENT_COUNT, length);
  490. var chunk = bytes.subarray(i, chunkEnd);
  491. strBuf.push(String.fromCharCode.apply(null, chunk));
  492. }
  493. return strBuf.join('');
  494. }
  495. function stringToBytes(str) {
  496. assert(typeof str === 'string', 'Invalid argument for stringToBytes');
  497. var length = str.length;
  498. var bytes = new Uint8Array(length);
  499. for (var i = 0; i < length; ++i) {
  500. bytes[i] = str.charCodeAt(i) & 0xFF;
  501. }
  502. return bytes;
  503. }
  504. function string32(value) {
  505. return String.fromCharCode((value >> 24) & 0xff, (value >> 16) & 0xff,
  506. (value >> 8) & 0xff, value & 0xff);
  507. }
  508. function log2(x) {
  509. var n = 1, i = 0;
  510. while (x > n) {
  511. n <<= 1;
  512. i++;
  513. }
  514. return i;
  515. }
  516. function readInt8(data, start) {
  517. return (data[start] << 24) >> 24;
  518. }
  519. function readUint16(data, offset) {
  520. return (data[offset] << 8) | data[offset + 1];
  521. }
  522. function readUint32(data, offset) {
  523. return ((data[offset] << 24) | (data[offset + 1] << 16) |
  524. (data[offset + 2] << 8) | data[offset + 3]) >>> 0;
  525. }
  526. // Lazy test the endianness of the platform
  527. // NOTE: This will be 'true' for simulated TypedArrays
  528. function isLittleEndian() {
  529. var buffer8 = new Uint8Array(2);
  530. buffer8[0] = 1;
  531. var buffer16 = new Uint16Array(buffer8.buffer);
  532. return (buffer16[0] === 1);
  533. }
  534. Object.defineProperty(PDFJS, 'isLittleEndian', {
  535. configurable: true,
  536. get: function PDFJS_isLittleEndian() {
  537. return shadow(PDFJS, 'isLittleEndian', isLittleEndian());
  538. }
  539. });
  540. // Lazy test if the userAgent support CanvasTypedArrays
  541. function hasCanvasTypedArrays() {
  542. var canvas = document.createElement('canvas');
  543. canvas.width = canvas.height = 1;
  544. var ctx = canvas.getContext('2d');
  545. var imageData = ctx.createImageData(1, 1);
  546. return (typeof imageData.data.buffer !== 'undefined');
  547. }
  548. Object.defineProperty(PDFJS, 'hasCanvasTypedArrays', {
  549. configurable: true,
  550. get: function PDFJS_hasCanvasTypedArrays() {
  551. return shadow(PDFJS, 'hasCanvasTypedArrays', hasCanvasTypedArrays());
  552. }
  553. });
  554. var Uint32ArrayView = (function Uint32ArrayViewClosure() {
  555. function Uint32ArrayView(buffer, length) {
  556. this.buffer = buffer;
  557. this.byteLength = buffer.length;
  558. this.length = length === undefined ? (this.byteLength >> 2) : length;
  559. ensureUint32ArrayViewProps(this.length);
  560. }
  561. Uint32ArrayView.prototype = Object.create(null);
  562. var uint32ArrayViewSetters = 0;
  563. function createUint32ArrayProp(index) {
  564. return {
  565. get: function () {
  566. var buffer = this.buffer, offset = index << 2;
  567. return (buffer[offset] | (buffer[offset + 1] << 8) |
  568. (buffer[offset + 2] << 16) | (buffer[offset + 3] << 24)) >>> 0;
  569. },
  570. set: function (value) {
  571. var buffer = this.buffer, offset = index << 2;
  572. buffer[offset] = value & 255;
  573. buffer[offset + 1] = (value >> 8) & 255;
  574. buffer[offset + 2] = (value >> 16) & 255;
  575. buffer[offset + 3] = (value >>> 24) & 255;
  576. }
  577. };
  578. }
  579. function ensureUint32ArrayViewProps(length) {
  580. while (uint32ArrayViewSetters < length) {
  581. Object.defineProperty(Uint32ArrayView.prototype,
  582. uint32ArrayViewSetters,
  583. createUint32ArrayProp(uint32ArrayViewSetters));
  584. uint32ArrayViewSetters++;
  585. }
  586. }
  587. return Uint32ArrayView;
  588. })();
  589. exports.Uint32ArrayView = Uint32ArrayView;
  590. var IDENTITY_MATRIX = [1, 0, 0, 1, 0, 0];
  591. var Util = PDFJS.Util = (function UtilClosure() {
  592. function Util() {}
  593. var rgbBuf = ['rgb(', 0, ',', 0, ',', 0, ')'];
  594. // makeCssRgb() can be called thousands of times. Using |rgbBuf| avoids
  595. // creating many intermediate strings.
  596. Util.makeCssRgb = function Util_makeCssRgb(r, g, b) {
  597. rgbBuf[1] = r;
  598. rgbBuf[3] = g;
  599. rgbBuf[5] = b;
  600. return rgbBuf.join('');
  601. };
  602. // Concatenates two transformation matrices together and returns the result.
  603. Util.transform = function Util_transform(m1, m2) {
  604. return [
  605. m1[0] * m2[0] + m1[2] * m2[1],
  606. m1[1] * m2[0] + m1[3] * m2[1],
  607. m1[0] * m2[2] + m1[2] * m2[3],
  608. m1[1] * m2[2] + m1[3] * m2[3],
  609. m1[0] * m2[4] + m1[2] * m2[5] + m1[4],
  610. m1[1] * m2[4] + m1[3] * m2[5] + m1[5]
  611. ];
  612. };
  613. // For 2d affine transforms
  614. Util.applyTransform = function Util_applyTransform(p, m) {
  615. var xt = p[0] * m[0] + p[1] * m[2] + m[4];
  616. var yt = p[0] * m[1] + p[1] * m[3] + m[5];
  617. return [xt, yt];
  618. };
  619. Util.applyInverseTransform = function Util_applyInverseTransform(p, m) {
  620. var d = m[0] * m[3] - m[1] * m[2];
  621. var xt = (p[0] * m[3] - p[1] * m[2] + m[2] * m[5] - m[4] * m[3]) / d;
  622. var yt = (-p[0] * m[1] + p[1] * m[0] + m[4] * m[1] - m[5] * m[0]) / d;
  623. return [xt, yt];
  624. };
  625. // Applies the transform to the rectangle and finds the minimum axially
  626. // aligned bounding box.
  627. Util.getAxialAlignedBoundingBox =
  628. function Util_getAxialAlignedBoundingBox(r, m) {
  629. var p1 = Util.applyTransform(r, m);
  630. var p2 = Util.applyTransform(r.slice(2, 4), m);
  631. var p3 = Util.applyTransform([r[0], r[3]], m);
  632. var p4 = Util.applyTransform([r[2], r[1]], m);
  633. return [
  634. Math.min(p1[0], p2[0], p3[0], p4[0]),
  635. Math.min(p1[1], p2[1], p3[1], p4[1]),
  636. Math.max(p1[0], p2[0], p3[0], p4[0]),
  637. Math.max(p1[1], p2[1], p3[1], p4[1])
  638. ];
  639. };
  640. Util.inverseTransform = function Util_inverseTransform(m) {
  641. var d = m[0] * m[3] - m[1] * m[2];
  642. return [m[3] / d, -m[1] / d, -m[2] / d, m[0] / d,
  643. (m[2] * m[5] - m[4] * m[3]) / d, (m[4] * m[1] - m[5] * m[0]) / d];
  644. };
  645. // Apply a generic 3d matrix M on a 3-vector v:
  646. // | a b c | | X |
  647. // | d e f | x | Y |
  648. // | g h i | | Z |
  649. // M is assumed to be serialized as [a,b,c,d,e,f,g,h,i],
  650. // with v as [X,Y,Z]
  651. Util.apply3dTransform = function Util_apply3dTransform(m, v) {
  652. return [
  653. m[0] * v[0] + m[1] * v[1] + m[2] * v[2],
  654. m[3] * v[0] + m[4] * v[1] + m[5] * v[2],
  655. m[6] * v[0] + m[7] * v[1] + m[8] * v[2]
  656. ];
  657. };
  658. // This calculation uses Singular Value Decomposition.
  659. // The SVD can be represented with formula A = USV. We are interested in the
  660. // matrix S here because it represents the scale values.
  661. Util.singularValueDecompose2dScale =
  662. function Util_singularValueDecompose2dScale(m) {
  663. var transpose = [m[0], m[2], m[1], m[3]];
  664. // Multiply matrix m with its transpose.
  665. var a = m[0] * transpose[0] + m[1] * transpose[2];
  666. var b = m[0] * transpose[1] + m[1] * transpose[3];
  667. var c = m[2] * transpose[0] + m[3] * transpose[2];
  668. var d = m[2] * transpose[1] + m[3] * transpose[3];
  669. // Solve the second degree polynomial to get roots.
  670. var first = (a + d) / 2;
  671. var second = Math.sqrt((a + d) * (a + d) - 4 * (a * d - c * b)) / 2;
  672. var sx = first + second || 1;
  673. var sy = first - second || 1;
  674. // Scale values are the square roots of the eigenvalues.
  675. return [Math.sqrt(sx), Math.sqrt(sy)];
  676. };
  677. // Normalize rectangle rect=[x1, y1, x2, y2] so that (x1,y1) < (x2,y2)
  678. // For coordinate systems whose origin lies in the bottom-left, this
  679. // means normalization to (BL,TR) ordering. For systems with origin in the
  680. // top-left, this means (TL,BR) ordering.
  681. Util.normalizeRect = function Util_normalizeRect(rect) {
  682. var r = rect.slice(0); // clone rect
  683. if (rect[0] > rect[2]) {
  684. r[0] = rect[2];
  685. r[2] = rect[0];
  686. }
  687. if (rect[1] > rect[3]) {
  688. r[1] = rect[3];
  689. r[3] = rect[1];
  690. }
  691. return r;
  692. };
  693. // Returns a rectangle [x1, y1, x2, y2] corresponding to the
  694. // intersection of rect1 and rect2. If no intersection, returns 'false'
  695. // The rectangle coordinates of rect1, rect2 should be [x1, y1, x2, y2]
  696. Util.intersect = function Util_intersect(rect1, rect2) {
  697. function compare(a, b) {
  698. return a - b;
  699. }
  700. // Order points along the axes
  701. var orderedX = [rect1[0], rect1[2], rect2[0], rect2[2]].sort(compare),
  702. orderedY = [rect1[1], rect1[3], rect2[1], rect2[3]].sort(compare),
  703. result = [];
  704. rect1 = Util.normalizeRect(rect1);
  705. rect2 = Util.normalizeRect(rect2);
  706. // X: first and second points belong to different rectangles?
  707. if ((orderedX[0] === rect1[0] && orderedX[1] === rect2[0]) ||
  708. (orderedX[0] === rect2[0] && orderedX[1] === rect1[0])) {
  709. // Intersection must be between second and third points
  710. result[0] = orderedX[1];
  711. result[2] = orderedX[2];
  712. } else {
  713. return false;
  714. }
  715. // Y: first and second points belong to different rectangles?
  716. if ((orderedY[0] === rect1[1] && orderedY[1] === rect2[1]) ||
  717. (orderedY[0] === rect2[1] && orderedY[1] === rect1[1])) {
  718. // Intersection must be between second and third points
  719. result[1] = orderedY[1];
  720. result[3] = orderedY[2];
  721. } else {
  722. return false;
  723. }
  724. return result;
  725. };
  726. Util.sign = function Util_sign(num) {
  727. return num < 0 ? -1 : 1;
  728. };
  729. Util.appendToArray = function Util_appendToArray(arr1, arr2) {
  730. Array.prototype.push.apply(arr1, arr2);
  731. };
  732. Util.prependToArray = function Util_prependToArray(arr1, arr2) {
  733. Array.prototype.unshift.apply(arr1, arr2);
  734. };
  735. Util.extendObj = function extendObj(obj1, obj2) {
  736. for (var key in obj2) {
  737. obj1[key] = obj2[key];
  738. }
  739. };
  740. Util.getInheritableProperty = function Util_getInheritableProperty(dict,
  741. name) {
  742. while (dict && !dict.has(name)) {
  743. dict = dict.get('Parent');
  744. }
  745. if (!dict) {
  746. return null;
  747. }
  748. return dict.get(name);
  749. };
  750. Util.inherit = function Util_inherit(sub, base, prototype) {
  751. sub.prototype = Object.create(base.prototype);
  752. sub.prototype.constructor = sub;
  753. for (var prop in prototype) {
  754. sub.prototype[prop] = prototype[prop];
  755. }
  756. };
  757. Util.loadScript = function Util_loadScript(src, callback) {
  758. var script = document.createElement('script');
  759. var loaded = false;
  760. script.setAttribute('src', src);
  761. if (callback) {
  762. script.onload = function() {
  763. if (!loaded) {
  764. callback();
  765. }
  766. loaded = true;
  767. };
  768. }
  769. document.getElementsByTagName('head')[0].appendChild(script);
  770. };
  771. return Util;
  772. })();
  773. /**
  774. * PDF page viewport created based on scale, rotation and offset.
  775. * @class
  776. * @alias PDFJS.PageViewport
  777. */
  778. var PageViewport = PDFJS.PageViewport = (function PageViewportClosure() {
  779. /**
  780. * @constructor
  781. * @private
  782. * @param viewBox {Array} xMin, yMin, xMax and yMax coordinates.
  783. * @param scale {number} scale of the viewport.
  784. * @param rotation {number} rotations of the viewport in degrees.
  785. * @param offsetX {number} offset X
  786. * @param offsetY {number} offset Y
  787. * @param dontFlip {boolean} if true, axis Y will not be flipped.
  788. */
  789. function PageViewport(viewBox, scale, rotation, offsetX, offsetY, dontFlip) {
  790. this.viewBox = viewBox;
  791. this.scale = scale;
  792. this.rotation = rotation;
  793. this.offsetX = offsetX;
  794. this.offsetY = offsetY;
  795. // creating transform to convert pdf coordinate system to the normal
  796. // canvas like coordinates taking in account scale and rotation
  797. var centerX = (viewBox[2] + viewBox[0]) / 2;
  798. var centerY = (viewBox[3] + viewBox[1]) / 2;
  799. var rotateA, rotateB, rotateC, rotateD;
  800. rotation = rotation % 360;
  801. rotation = rotation < 0 ? rotation + 360 : rotation;
  802. switch (rotation) {
  803. case 180:
  804. rotateA = -1; rotateB = 0; rotateC = 0; rotateD = 1;
  805. break;
  806. case 90:
  807. rotateA = 0; rotateB = 1; rotateC = 1; rotateD = 0;
  808. break;
  809. case 270:
  810. rotateA = 0; rotateB = -1; rotateC = -1; rotateD = 0;
  811. break;
  812. //case 0:
  813. default:
  814. rotateA = 1; rotateB = 0; rotateC = 0; rotateD = -1;
  815. break;
  816. }
  817. if (dontFlip) {
  818. rotateC = -rotateC; rotateD = -rotateD;
  819. }
  820. var offsetCanvasX, offsetCanvasY;
  821. var width, height;
  822. if (rotateA === 0) {
  823. offsetCanvasX = Math.abs(centerY - viewBox[1]) * scale + offsetX;
  824. offsetCanvasY = Math.abs(centerX - viewBox[0]) * scale + offsetY;
  825. width = Math.abs(viewBox[3] - viewBox[1]) * scale;
  826. height = Math.abs(viewBox[2] - viewBox[0]) * scale;
  827. } else {
  828. offsetCanvasX = Math.abs(centerX - viewBox[0]) * scale + offsetX;
  829. offsetCanvasY = Math.abs(centerY - viewBox[1]) * scale + offsetY;
  830. width = Math.abs(viewBox[2] - viewBox[0]) * scale;
  831. height = Math.abs(viewBox[3] - viewBox[1]) * scale;
  832. }
  833. // creating transform for the following operations:
  834. // translate(-centerX, -centerY), rotate and flip vertically,
  835. // scale, and translate(offsetCanvasX, offsetCanvasY)
  836. this.transform = [
  837. rotateA * scale,
  838. rotateB * scale,
  839. rotateC * scale,
  840. rotateD * scale,
  841. offsetCanvasX - rotateA * scale * centerX - rotateC * scale * centerY,
  842. offsetCanvasY - rotateB * scale * centerX - rotateD * scale * centerY
  843. ];
  844. this.width = width;
  845. this.height = height;
  846. this.fontScale = scale;
  847. }
  848. PageViewport.prototype = /** @lends PDFJS.PageViewport.prototype */ {
  849. /**
  850. * Clones viewport with additional properties.
  851. * @param args {Object} (optional) If specified, may contain the 'scale' or
  852. * 'rotation' properties to override the corresponding properties in
  853. * the cloned viewport.
  854. * @returns {PDFJS.PageViewport} Cloned viewport.
  855. */
  856. clone: function PageViewPort_clone(args) {
  857. args = args || {};
  858. var scale = 'scale' in args ? args.scale : this.scale;
  859. var rotation = 'rotation' in args ? args.rotation : this.rotation;
  860. return new PageViewport(this.viewBox.slice(), scale, rotation,
  861. this.offsetX, this.offsetY, args.dontFlip);
  862. },
  863. /**
  864. * Converts PDF point to the viewport coordinates. For examples, useful for
  865. * converting PDF location into canvas pixel coordinates.
  866. * @param x {number} X coordinate.
  867. * @param y {number} Y coordinate.
  868. * @returns {Object} Object that contains 'x' and 'y' properties of the
  869. * point in the viewport coordinate space.
  870. * @see {@link convertToPdfPoint}
  871. * @see {@link convertToViewportRectangle}
  872. */
  873. convertToViewportPoint: function PageViewport_convertToViewportPoint(x, y) {
  874. return Util.applyTransform([x, y], this.transform);
  875. },
  876. /**
  877. * Converts PDF rectangle to the viewport coordinates.
  878. * @param rect {Array} xMin, yMin, xMax and yMax coordinates.
  879. * @returns {Array} Contains corresponding coordinates of the rectangle
  880. * in the viewport coordinate space.
  881. * @see {@link convertToViewportPoint}
  882. */
  883. convertToViewportRectangle:
  884. function PageViewport_convertToViewportRectangle(rect) {
  885. var tl = Util.applyTransform([rect[0], rect[1]], this.transform);
  886. var br = Util.applyTransform([rect[2], rect[3]], this.transform);
  887. return [tl[0], tl[1], br[0], br[1]];
  888. },
  889. /**
  890. * Converts viewport coordinates to the PDF location. For examples, useful
  891. * for converting canvas pixel location into PDF one.
  892. * @param x {number} X coordinate.
  893. * @param y {number} Y coordinate.
  894. * @returns {Object} Object that contains 'x' and 'y' properties of the
  895. * point in the PDF coordinate space.
  896. * @see {@link convertToViewportPoint}
  897. */
  898. convertToPdfPoint: function PageViewport_convertToPdfPoint(x, y) {
  899. return Util.applyInverseTransform([x, y], this.transform);
  900. }
  901. };
  902. return PageViewport;
  903. })();
  904. var PDFStringTranslateTable = [
  905. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  906. 0x2D8, 0x2C7, 0x2C6, 0x2D9, 0x2DD, 0x2DB, 0x2DA, 0x2DC, 0, 0, 0, 0, 0, 0, 0,
  907. 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,
  908. 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,
  909. 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,
  910. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x2022, 0x2020, 0x2021, 0x2026, 0x2014,
  911. 0x2013, 0x192, 0x2044, 0x2039, 0x203A, 0x2212, 0x2030, 0x201E, 0x201C,
  912. 0x201D, 0x2018, 0x2019, 0x201A, 0x2122, 0xFB01, 0xFB02, 0x141, 0x152, 0x160,
  913. 0x178, 0x17D, 0x131, 0x142, 0x153, 0x161, 0x17E, 0, 0x20AC
  914. ];
  915. function stringToPDFString(str) {
  916. var i, n = str.length, strBuf = [];
  917. if (str[0] === '\xFE' && str[1] === '\xFF') {
  918. // UTF16BE BOM
  919. for (i = 2; i < n; i += 2) {
  920. strBuf.push(String.fromCharCode(
  921. (str.charCodeAt(i) << 8) | str.charCodeAt(i + 1)));
  922. }
  923. } else {
  924. for (i = 0; i < n; ++i) {
  925. var code = PDFStringTranslateTable[str.charCodeAt(i)];
  926. strBuf.push(code ? String.fromCharCode(code) : str.charAt(i));
  927. }
  928. }
  929. return strBuf.join('');
  930. }
  931. function stringToUTF8String(str) {
  932. return decodeURIComponent(escape(str));
  933. }
  934. function utf8StringToString(str) {
  935. return unescape(encodeURIComponent(str));
  936. }
  937. function isEmptyObj(obj) {
  938. for (var key in obj) {
  939. return false;
  940. }
  941. return true;
  942. }
  943. function isBool(v) {
  944. return typeof v === 'boolean';
  945. }
  946. function isInt(v) {
  947. return typeof v === 'number' && ((v | 0) === v);
  948. }
  949. function isNum(v) {
  950. return typeof v === 'number';
  951. }
  952. function isString(v) {
  953. return typeof v === 'string';
  954. }
  955. function isArray(v) {
  956. return v instanceof Array;
  957. }
  958. function isArrayBuffer(v) {
  959. return typeof v === 'object' && v !== null && v.byteLength !== undefined;
  960. }
  961. /**
  962. * Promise Capability object.
  963. *
  964. * @typedef {Object} PromiseCapability
  965. * @property {Promise} promise - A promise object.
  966. * @property {function} resolve - Fullfills the promise.
  967. * @property {function} reject - Rejects the promise.
  968. */
  969. /**
  970. * Creates a promise capability object.
  971. * @alias PDFJS.createPromiseCapability
  972. *
  973. * @return {PromiseCapability} A capability object contains:
  974. * - a Promise, resolve and reject methods.
  975. */
  976. function createPromiseCapability() {
  977. var capability = {};
  978. capability.promise = new Promise(function (resolve, reject) {
  979. capability.resolve = resolve;
  980. capability.reject = reject;
  981. });
  982. return capability;
  983. }
  984. PDFJS.createPromiseCapability = createPromiseCapability;
  985. /**
  986. * Polyfill for Promises:
  987. * The following promise implementation tries to generally implement the
  988. * Promise/A+ spec. Some notable differences from other promise libaries are:
  989. * - There currently isn't a seperate deferred and promise object.
  990. * - Unhandled rejections eventually show an error if they aren't handled.
  991. *
  992. * Based off of the work in:
  993. * https://bugzilla.mozilla.org/show_bug.cgi?id=810490
  994. */
  995. (function PromiseClosure() {
  996. if (globalScope.Promise) {
  997. // Promises existing in the DOM/Worker, checking presence of all/resolve
  998. if (typeof globalScope.Promise.all !== 'function') {
  999. globalScope.Promise.all = function (iterable) {
  1000. var count = 0, results = [], resolve, reject;
  1001. var promise = new globalScope.Promise(function (resolve_, reject_) {
  1002. resolve = resolve_;
  1003. reject = reject_;
  1004. });
  1005. iterable.forEach(function (p, i) {
  1006. count++;
  1007. p.then(function (result) {
  1008. results[i] = result;
  1009. count--;
  1010. if (count === 0) {
  1011. resolve(results);
  1012. }
  1013. }, reject);
  1014. });
  1015. if (count === 0) {
  1016. resolve(results);
  1017. }
  1018. return promise;
  1019. };
  1020. }
  1021. if (typeof globalScope.Promise.resolve !== 'function') {
  1022. globalScope.Promise.resolve = function (value) {
  1023. return new globalScope.Promise(function (resolve) { resolve(value); });
  1024. };
  1025. }
  1026. if (typeof globalScope.Promise.reject !== 'function') {
  1027. globalScope.Promise.reject = function (reason) {
  1028. return new globalScope.Promise(function (resolve, reject) {
  1029. reject(reason);
  1030. });
  1031. };
  1032. }
  1033. if (typeof globalScope.Promise.prototype.catch !== 'function') {
  1034. globalScope.Promise.prototype.catch = function (onReject) {
  1035. return globalScope.Promise.prototype.then(undefined, onReject);
  1036. };
  1037. }
  1038. return;
  1039. }
  1040. var STATUS_PENDING = 0;
  1041. var STATUS_RESOLVED = 1;
  1042. var STATUS_REJECTED = 2;
  1043. // In an attempt to avoid silent exceptions, unhandled rejections are
  1044. // tracked and if they aren't handled in a certain amount of time an
  1045. // error is logged.
  1046. var REJECTION_TIMEOUT = 500;
  1047. var HandlerManager = {
  1048. handlers: [],
  1049. running: false,
  1050. unhandledRejections: [],
  1051. pendingRejectionCheck: false,
  1052. scheduleHandlers: function scheduleHandlers(promise) {
  1053. if (promise._status === STATUS_PENDING) {
  1054. return;
  1055. }
  1056. this.handlers = this.handlers.concat(promise._handlers);
  1057. promise._handlers = [];
  1058. if (this.running) {
  1059. return;
  1060. }
  1061. this.running = true;
  1062. setTimeout(this.runHandlers.bind(this), 0);
  1063. },
  1064. runHandlers: function runHandlers() {
  1065. var RUN_TIMEOUT = 1; // ms
  1066. var timeoutAt = Date.now() + RUN_TIMEOUT;
  1067. while (this.handlers.length > 0) {
  1068. var handler = this.handlers.shift();
  1069. var nextStatus = handler.thisPromise._status;
  1070. var nextValue = handler.thisPromise._value;
  1071. try {
  1072. if (nextStatus === STATUS_RESOLVED) {
  1073. if (typeof handler.onResolve === 'function') {
  1074. nextValue = handler.onResolve(nextValue);
  1075. }
  1076. } else if (typeof handler.onReject === 'function') {
  1077. nextValue = handler.onReject(nextValue);
  1078. nextStatus = STATUS_RESOLVED;
  1079. if (handler.thisPromise._unhandledRejection) {
  1080. this.removeUnhandeledRejection(handler.thisPromise);
  1081. }
  1082. }
  1083. } catch (ex) {
  1084. nextStatus = STATUS_REJECTED;
  1085. nextValue = ex;
  1086. }
  1087. handler.nextPromise._updateStatus(nextStatus, nextValue);
  1088. if (Date.now() >= timeoutAt) {
  1089. break;
  1090. }
  1091. }
  1092. if (this.handlers.length > 0) {
  1093. setTimeout(this.runHandlers.bind(this), 0);
  1094. return;
  1095. }
  1096. this.running = false;
  1097. },
  1098. addUnhandledRejection: function addUnhandledRejection(promise) {
  1099. this.unhandledRejections.push({
  1100. promise: promise,
  1101. time: Date.now()
  1102. });
  1103. this.scheduleRejectionCheck();
  1104. },
  1105. removeUnhandeledRejection: function removeUnhandeledRejection(promise) {
  1106. promise._unhandledRejection = false;
  1107. for (var i = 0; i < this.unhandledRejections.length; i++) {
  1108. if (this.unhandledRejections[i].promise === promise) {
  1109. this.unhandledRejections.splice(i);
  1110. i--;
  1111. }
  1112. }
  1113. },
  1114. scheduleRejectionCheck: function scheduleRejectionCheck() {
  1115. if (this.pendingRejectionCheck) {
  1116. return;
  1117. }
  1118. this.pendingRejectionCheck = true;
  1119. setTimeout(function rejectionCheck() {
  1120. this.pendingRejectionCheck = false;
  1121. var now = Date.now();
  1122. for (var i = 0; i < this.unhandledRejections.length; i++) {
  1123. if (now - this.unhandledRejections[i].time > REJECTION_TIMEOUT) {
  1124. var unhandled = this.unhandledRejections[i].promise._value;
  1125. var msg = 'Unhandled rejection: ' + unhandled;
  1126. if (unhandled.stack) {
  1127. msg += '\n' + unhandled.stack;
  1128. }
  1129. warn(msg);
  1130. this.unhandledRejections.splice(i);
  1131. i--;
  1132. }
  1133. }
  1134. if (this.unhandledRejections.length) {
  1135. this.scheduleRejectionCheck();
  1136. }
  1137. }.bind(this), REJECTION_TIMEOUT);
  1138. }
  1139. };
  1140. function Promise(resolver) {
  1141. this._status = STATUS_PENDING;
  1142. this._handlers = [];
  1143. try {
  1144. resolver.call(this, this._resolve.bind(this), this._reject.bind(this));
  1145. } catch (e) {
  1146. this._reject(e);
  1147. }
  1148. }
  1149. /**
  1150. * Builds a promise that is resolved when all the passed in promises are
  1151. * resolved.
  1152. * @param {array} array of data and/or promises to wait for.
  1153. * @return {Promise} New dependant promise.
  1154. */
  1155. Promise.all = function Promise_all(promises) {
  1156. var resolveAll, rejectAll;
  1157. var deferred = new Promise(function (resolve, reject) {
  1158. resolveAll = resolve;
  1159. rejectAll = reject;
  1160. });
  1161. var unresolved = promises.length;
  1162. var results = [];
  1163. if (unresolved === 0) {
  1164. resolveAll(results);
  1165. return deferred;
  1166. }
  1167. function reject(reason) {
  1168. if (deferred._status === STATUS_REJECTED) {
  1169. return;
  1170. }
  1171. results = [];
  1172. rejectAll(reason);
  1173. }
  1174. for (var i = 0, ii = promises.length; i < ii; ++i) {
  1175. var promise = promises[i];
  1176. var resolve = (function(i) {
  1177. return function(value) {
  1178. if (deferred._status === STATUS_REJECTED) {
  1179. return;
  1180. }
  1181. results[i] = value;
  1182. unresolved--;
  1183. if (unresolved === 0) {
  1184. resolveAll(results);
  1185. }
  1186. };
  1187. })(i);
  1188. if (Promise.isPromise(promise)) {
  1189. promise.then(resolve, reject);
  1190. } else {
  1191. resolve(promise);
  1192. }
  1193. }
  1194. return deferred;
  1195. };
  1196. /**
  1197. * Checks if the value is likely a promise (has a 'then' function).
  1198. * @return {boolean} true if value is thenable
  1199. */
  1200. Promise.isPromise = function Promise_isPromise(value) {
  1201. return value && typeof value.then === 'function';
  1202. };
  1203. /**
  1204. * Creates resolved promise
  1205. * @param value resolve value
  1206. * @returns {Promise}
  1207. */
  1208. Promise.resolve = function Promise_resolve(value) {
  1209. return new Promise(function (resolve) { resolve(value); });
  1210. };
  1211. /**
  1212. * Creates rejected promise
  1213. * @param reason rejection value
  1214. * @returns {Promise}
  1215. */
  1216. Promise.reject = function Promise_reject(reason) {
  1217. return new Promise(function (resolve, reject) { reject(reason); });
  1218. };
  1219. Promise.prototype = {
  1220. _status: null,
  1221. _value: null,
  1222. _handlers: null,
  1223. _unhandledRejection: null,
  1224. _updateStatus: function Promise__updateStatus(status, value) {
  1225. if (this._status === STATUS_RESOLVED ||
  1226. this._status === STATUS_REJECTED) {
  1227. return;
  1228. }
  1229. if (status === STATUS_RESOLVED &&
  1230. Promise.isPromise(value)) {
  1231. value.then(this._updateStatus.bind(this, STATUS_RESOLVED),
  1232. this._updateStatus.bind(this, STATUS_REJECTED));
  1233. return;
  1234. }
  1235. this._status = status;
  1236. this._value = value;
  1237. if (status === STATUS_REJECTED && this._handlers.length === 0) {
  1238. this._unhandledRejection = true;
  1239. HandlerManager.addUnhandledRejection(this);
  1240. }
  1241. HandlerManager.scheduleHandlers(this);
  1242. },
  1243. _resolve: function Promise_resolve(value) {
  1244. this._updateStatus(STATUS_RESOLVED, value);
  1245. },
  1246. _reject: function Promise_reject(reason) {
  1247. this._updateStatus(STATUS_REJECTED, reason);
  1248. },
  1249. then: function Promise_then(onResolve, onReject) {
  1250. var nextPromise = new Promise(function (resolve, reject) {
  1251. this.resolve = resolve;
  1252. this.reject = reject;
  1253. });
  1254. this._handlers.push({
  1255. thisPromise: this,
  1256. onResolve: onResolve,
  1257. onReject: onReject,
  1258. nextPromise: nextPromise
  1259. });
  1260. HandlerManager.scheduleHandlers(this);
  1261. return nextPromise;
  1262. },
  1263. catch: function Promise_catch(onReject) {
  1264. return this.then(undefined, onReject);
  1265. }
  1266. };
  1267. globalScope.Promise = Promise;
  1268. })();
  1269. var StatTimer = (function StatTimerClosure() {
  1270. function rpad(str, pad, length) {
  1271. while (str.length < length) {
  1272. str += pad;
  1273. }
  1274. return str;
  1275. }
  1276. function StatTimer() {
  1277. this.started = {};
  1278. this.times = [];
  1279. this.enabled = true;
  1280. }
  1281. StatTimer.prototype = {
  1282. time: function StatTimer_time(name) {
  1283. if (!this.enabled) {
  1284. return;
  1285. }
  1286. if (name in this.started) {
  1287. warn('Timer is already running for ' + name);
  1288. }
  1289. this.started[name] = Date.now();
  1290. },
  1291. timeEnd: function StatTimer_timeEnd(name) {
  1292. if (!this.enabled) {
  1293. return;
  1294. }
  1295. if (!(name in this.started)) {
  1296. warn('Timer has not been started for ' + name);
  1297. }
  1298. this.times.push({
  1299. 'name': name,
  1300. 'start': this.started[name],
  1301. 'end': Date.now()
  1302. });
  1303. // Remove timer from started so it can be called again.
  1304. delete this.started[name];
  1305. },
  1306. toString: function StatTimer_toString() {
  1307. var i, ii;
  1308. var times = this.times;
  1309. var out = '';
  1310. // Find the longest name for padding purposes.
  1311. var longest = 0;
  1312. for (i = 0, ii = times.length; i < ii; ++i) {
  1313. var name = times[i]['name'];
  1314. if (name.length > longest) {
  1315. longest = name.length;
  1316. }
  1317. }
  1318. for (i = 0, ii = times.length; i < ii; ++i) {
  1319. var span = times[i];
  1320. var duration = span.end - span.start;
  1321. out += rpad(span['name'], ' ', longest) + ' ' + duration + 'ms\n';
  1322. }
  1323. return out;
  1324. }
  1325. };
  1326. return StatTimer;
  1327. })();
  1328. PDFJS.createBlob = function createBlob(data, contentType) {
  1329. if (typeof Blob !== 'undefined') {
  1330. return new Blob([data], { type: contentType });
  1331. }
  1332. // Blob builder is deprecated in FF14 and removed in FF18.
  1333. var bb = new MozBlobBuilder();
  1334. bb.append(data);
  1335. return bb.getBlob(contentType);
  1336. };
  1337. PDFJS.createObjectURL = (function createObjectURLClosure() {
  1338. // Blob/createObjectURL is not available, falling back to data schema.
  1339. var digits =
  1340. 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
  1341. return function createObjectURL(data, contentType) {
  1342. if (!PDFJS.disableCreateObjectURL &&
  1343. typeof URL !== 'undefined' && URL.createObjectURL) {
  1344. var blob = PDFJS.createBlob(data, contentType);
  1345. return URL.createObjectURL(blob);
  1346. }
  1347. var buffer = 'data:' + contentType + ';base64,';
  1348. for (var i = 0, ii = data.length; i < ii; i += 3) {
  1349. var b1 = data[i] & 0xFF;
  1350. var b2 = data[i + 1] & 0xFF;
  1351. var b3 = data[i + 2] & 0xFF;
  1352. var d1 = b1 >> 2, d2 = ((b1 & 3) << 4) | (b2 >> 4);
  1353. var d3 = i + 1 < ii ? ((b2 & 0xF) << 2) | (b3 >> 6) : 64;
  1354. var d4 = i + 2 < ii ? (b3 & 0x3F) : 64;
  1355. buffer += digits[d1] + digits[d2] + digits[d3] + digits[d4];
  1356. }
  1357. return buffer;
  1358. };
  1359. })();
  1360. function MessageHandler(sourceName, targetName, comObj) {
  1361. this.sourceName = sourceName;
  1362. this.targetName = targetName;
  1363. this.comObj = comObj;
  1364. this.callbackIndex = 1;
  1365. this.postMessageTransfers = true;
  1366. var callbacksCapabilities = this.callbacksCapabilities = {};
  1367. var ah = this.actionHandler = {};
  1368. this._onComObjOnMessage = function messageHandlerComObjOnMessage(event) {
  1369. var data = event.data;
  1370. if (data.targetName !== this.sourceName) {
  1371. return;
  1372. }
  1373. if (data.isReply) {
  1374. var callbackId = data.callbackId;
  1375. if (data.callbackId in callbacksCapabilities) {
  1376. var callback = callbacksCapabilities[callbackId];
  1377. delete callbacksCapabilities[callbackId];
  1378. if ('error' in data) {
  1379. callback.reject(data.error);
  1380. } else {
  1381. callback.resolve(data.data);
  1382. }
  1383. } else {
  1384. error('Cannot resolve callback ' + callbackId);
  1385. }
  1386. } else if (data.action in ah) {
  1387. var action = ah[data.action];
  1388. if (data.callbackId) {
  1389. var sourceName = this.sourceName;
  1390. var targetName = data.sourceName;
  1391. Promise.resolve().then(function () {
  1392. return action[0].call(action[1], data.data);
  1393. }).then(function (result) {
  1394. comObj.postMessage({
  1395. sourceName: sourceName,
  1396. targetName: targetName,
  1397. isReply: true,
  1398. callbackId: data.callbackId,
  1399. data: result
  1400. });
  1401. }, function (reason) {
  1402. if (reason instanceof Error) {
  1403. // Serialize error to avoid "DataCloneError"
  1404. reason = reason + '';
  1405. }
  1406. comObj.postMessage({
  1407. sourceName: sourceName,
  1408. targetName: targetName,
  1409. isReply: true,
  1410. callbackId: data.callbackId,
  1411. error: reason
  1412. });
  1413. });
  1414. } else {
  1415. action[0].call(action[1], data.data);
  1416. }
  1417. } else {
  1418. error('Unknown action from worker: ' + data.action);
  1419. }
  1420. }.bind(this);
  1421. comObj.addEventListener('message', this._onComObjOnMessage);
  1422. }
  1423. MessageHandler.prototype = {
  1424. on: function messageHandlerOn(actionName, handler, scope) {
  1425. var ah = this.actionHandler;
  1426. if (ah[actionName]) {
  1427. error('There is already an actionName called "' + actionName + '"');
  1428. }
  1429. ah[actionName] = [handler, scope];
  1430. },
  1431. /**
  1432. * Sends a message to the comObj to invoke the action with the supplied data.
  1433. * @param {String} actionName Action to call.
  1434. * @param {JSON} data JSON data to send.
  1435. * @param {Array} [transfers] Optional list of transfers/ArrayBuffers
  1436. */
  1437. send: function messageHandlerSend(actionName, data, transfers) {
  1438. var message = {
  1439. sourceName: this.sourceName,
  1440. targetName: this.targetName,
  1441. action: actionName,
  1442. data: data
  1443. };
  1444. this.postMessage(message, transfers);
  1445. },
  1446. /**
  1447. * Sends a message to the comObj to invoke the action with the supplied data.
  1448. * Expects that other side will callback with the response.
  1449. * @param {String} actionName Action to call.
  1450. * @param {JSON} data JSON data to send.
  1451. * @param {Array} [transfers] Optional list of transfers/ArrayBuffers.
  1452. * @returns {Promise} Promise to be resolved with response data.
  1453. */
  1454. sendWithPromise:
  1455. function messageHandlerSendWithPromise(actionName, data, transfers) {
  1456. var callbackId = this.callbackIndex++;
  1457. var message = {
  1458. sourceName: this.sourceName,
  1459. targetName: this.targetName,
  1460. action: actionName,
  1461. data: data,
  1462. callbackId: callbackId
  1463. };
  1464. var capability = createPromiseCapability();
  1465. this.callbacksCapabilities[callbackId] = capability;
  1466. try {
  1467. this.postMessage(message, transfers);
  1468. } catch (e) {
  1469. capability.reject(e);
  1470. }
  1471. return capability.promise;
  1472. },
  1473. /**
  1474. * Sends raw message to the comObj.
  1475. * @private
  1476. * @param message {Object} Raw message.
  1477. * @param transfers List of transfers/ArrayBuffers, or undefined.
  1478. */
  1479. postMessage: function (message, transfers) {
  1480. if (transfers && this.postMessageTransfers) {
  1481. this.comObj.postMessage(message, transfers);
  1482. } else {
  1483. this.comObj.postMessage(message);
  1484. }
  1485. },
  1486. destroy: function () {
  1487. this.comObj.removeEventListener('message', this._onComObjOnMessage);
  1488. }
  1489. };
  1490. function loadJpegStream(id, imageUrl, objs) {
  1491. var img = new Image();
  1492. img.onload = (function loadJpegStream_onloadClosure() {
  1493. objs.resolve(id, img);
  1494. });
  1495. img.onerror = (function loadJpegStream_onerrorClosure() {
  1496. objs.resolve(id, null);
  1497. warn('Error during JPEG image loading');
  1498. });
  1499. img.src = imageUrl;
  1500. }
  1501. exports.FONT_IDENTITY_MATRIX = FONT_IDENTITY_MATRIX;
  1502. exports.IDENTITY_MATRIX = IDENTITY_MATRIX;
  1503. exports.OPS = OPS;
  1504. exports.UNSUPPORTED_FEATURES = UNSUPPORTED_FEATURES;
  1505. exports.AnnotationBorderStyleType = AnnotationBorderStyleType;
  1506. exports.AnnotationFlag = AnnotationFlag;
  1507. exports.AnnotationType = AnnotationType;
  1508. exports.FontType = FontType;
  1509. exports.ImageKind = ImageKind;
  1510. exports.InvalidPDFException = InvalidPDFException;
  1511. exports.LinkTarget = LinkTarget;
  1512. exports.LinkTargetStringMap = LinkTargetStringMap;
  1513. exports.MessageHandler = MessageHandler;
  1514. exports.MissingDataException = MissingDataException;
  1515. exports.MissingPDFException = MissingPDFException;
  1516. exports.NotImplementedException = NotImplementedException;
  1517. exports.PasswordException = PasswordException;
  1518. exports.PasswordResponses = PasswordResponses;
  1519. exports.StatTimer = StatTimer;
  1520. exports.StreamType = StreamType;
  1521. exports.TextRenderingMode = TextRenderingMode;
  1522. exports.UnexpectedResponseException = UnexpectedResponseException;
  1523. exports.UnknownErrorException = UnknownErrorException;
  1524. exports.Util = Util;
  1525. exports.XRefParseException = XRefParseException;
  1526. exports.assert = assert;
  1527. exports.bytesToString = bytesToString;
  1528. exports.combineUrl = combineUrl;
  1529. exports.createPromiseCapability = createPromiseCapability;
  1530. exports.deprecated = deprecated;
  1531. exports.error = error;
  1532. exports.info = info;
  1533. exports.isArray = isArray;
  1534. exports.isArrayBuffer = isArrayBuffer;
  1535. exports.isBool = isBool;
  1536. exports.isEmptyObj = isEmptyObj;
  1537. exports.isExternalLinkTargetSet = isExternalLinkTargetSet;
  1538. exports.isInt = isInt;
  1539. exports.isNum = isNum;
  1540. exports.isString = isString;
  1541. exports.isValidUrl = isValidUrl;
  1542. exports.loadJpegStream = loadJpegStream;
  1543. exports.log2 = log2;
  1544. exports.readInt8 = readInt8;
  1545. exports.readUint16 = readUint16;
  1546. exports.readUint32 = readUint32;
  1547. exports.shadow = shadow;
  1548. exports.string32 = string32;
  1549. exports.stringToBytes = stringToBytes;
  1550. exports.stringToPDFString = stringToPDFString;
  1551. exports.stringToUTF8String = stringToUTF8String;
  1552. exports.utf8StringToString = utf8StringToString;
  1553. exports.warn = warn;
  1554. }));
  1555. (function (root, factory) {
  1556. {
  1557. factory((root.pdfjsDisplayDOMUtils = {}), root.pdfjsSharedGlobal);
  1558. }
  1559. }(this, function (exports, sharedGlobal) {
  1560. var PDFJS = sharedGlobal.PDFJS;
  1561. /**
  1562. * Optimised CSS custom property getter/setter.
  1563. * @class
  1564. */
  1565. var CustomStyle = (function CustomStyleClosure() {
  1566. // As noted on: http://www.zachstronaut.com/posts/2009/02/17/
  1567. // animate-css-transforms-firefox-webkit.html
  1568. // in some versions of IE9 it is critical that ms appear in this list
  1569. // before Moz
  1570. var prefixes = ['ms', 'Moz', 'Webkit', 'O'];
  1571. var _cache = {};
  1572. function CustomStyle() {}
  1573. CustomStyle.getProp = function get(propName, element) {
  1574. // check cache only when no element is given
  1575. if (arguments.length === 1 && typeof _cache[propName] === 'string') {
  1576. return _cache[propName];
  1577. }
  1578. element = element || document.documentElement;
  1579. var style = element.style, prefixed, uPropName;
  1580. // test standard property first
  1581. if (typeof style[propName] === 'string') {
  1582. return (_cache[propName] = propName);
  1583. }
  1584. // capitalize
  1585. uPropName = propName.charAt(0).toUpperCase() + propName.slice(1);
  1586. // test vendor specific properties
  1587. for (var i = 0, l = prefixes.length; i < l; i++) {
  1588. prefixed = prefixes[i] + uPropName;
  1589. if (typeof style[prefixed] === 'string') {
  1590. return (_cache[propName] = prefixed);
  1591. }
  1592. }
  1593. //if all fails then set to undefined
  1594. return (_cache[propName] = 'undefined');
  1595. };
  1596. CustomStyle.setProp = function set(propName, element, str) {
  1597. var prop = this.getProp(propName);
  1598. if (prop !== 'undefined') {
  1599. element.style[prop] = str;
  1600. }
  1601. };
  1602. return CustomStyle;
  1603. })();
  1604. PDFJS.CustomStyle = CustomStyle;
  1605. exports.CustomStyle = CustomStyle;
  1606. }));
  1607. (function (root, factory) {
  1608. {
  1609. factory((root.pdfjsDisplayAnnotationLayer = {}), root.pdfjsSharedUtil,
  1610. root.pdfjsDisplayDOMUtils);
  1611. }
  1612. }(this, function (exports, sharedUtil, displayDOMUtils) {
  1613. var AnnotationBorderStyleType = sharedUtil.AnnotationBorderStyleType;
  1614. var AnnotationType = sharedUtil.AnnotationType;
  1615. var Util = sharedUtil.Util;
  1616. var isExternalLinkTargetSet = sharedUtil.isExternalLinkTargetSet;
  1617. var LinkTargetStringMap = sharedUtil.LinkTargetStringMap;
  1618. var warn = sharedUtil.warn;
  1619. var CustomStyle = displayDOMUtils.CustomStyle;
  1620. var ANNOT_MIN_SIZE = 10; // px
  1621. var AnnotationLayer = (function AnnotationLayerClosure() {
  1622. // TODO(mack): This dupes some of the logic in CanvasGraphics.setFont()
  1623. function setTextStyles(element, item, fontObj) {
  1624. var style = element.style;
  1625. style.fontSize = item.fontSize + 'px';
  1626. style.direction = item.fontDirection < 0 ? 'rtl': 'ltr';
  1627. if (!fontObj) {
  1628. return;
  1629. }
  1630. style.fontWeight = fontObj.black ?
  1631. (fontObj.bold ? 'bolder' : 'bold') :
  1632. (fontObj.bold ? 'bold' : 'normal');
  1633. style.fontStyle = fontObj.italic ? 'italic' : 'normal';
  1634. var fontName = fontObj.loadedName;
  1635. var fontFamily = fontName ? '"' + fontName + '", ' : '';
  1636. // Use a reasonable default font if the font doesn't specify a fallback
  1637. var fallbackName = fontObj.fallbackName || 'Helvetica, sans-serif';
  1638. style.fontFamily = fontFamily + fallbackName;
  1639. }
  1640. function getContainer(data, page, viewport) {
  1641. var container = document.createElement('section');
  1642. var width = data.rect[2] - data.rect[0];
  1643. var height = data.rect[3] - data.rect[1];
  1644. container.setAttribute('data-annotation-id', data.id);
  1645. data.rect = Util.normalizeRect([
  1646. data.rect[0],
  1647. page.view[3] - data.rect[1] + page.view[1],
  1648. data.rect[2],
  1649. page.view[3] - data.rect[3] + page.view[1]
  1650. ]);
  1651. CustomStyle.setProp('transform', container,
  1652. 'matrix(' + viewport.transform.join(',') + ')');
  1653. CustomStyle.setProp('transformOrigin', container,
  1654. -data.rect[0] + 'px ' + -data.rect[1] + 'px');
  1655. if (data.borderStyle.width > 0) {
  1656. container.style.borderWidth = data.borderStyle.width + 'px';
  1657. if (data.borderStyle.style !== AnnotationBorderStyleType.UNDERLINE) {
  1658. // Underline styles only have a bottom border, so we do not need
  1659. // to adjust for all borders. This yields a similar result as
  1660. // Adobe Acrobat/Reader.
  1661. width = width - 2 * data.borderStyle.width;
  1662. height = height - 2 * data.borderStyle.width;
  1663. }
  1664. var horizontalRadius = data.borderStyle.horizontalCornerRadius;
  1665. var verticalRadius = data.borderStyle.verticalCornerRadius;
  1666. if (horizontalRadius > 0 || verticalRadius > 0) {
  1667. var radius = horizontalRadius + 'px / ' + verticalRadius + 'px';
  1668. CustomStyle.setProp('borderRadius', container, radius);
  1669. }
  1670. switch (data.borderStyle.style) {
  1671. case AnnotationBorderStyleType.SOLID:
  1672. container.style.borderStyle = 'solid';
  1673. break;
  1674. case AnnotationBorderStyleType.DASHED:
  1675. container.style.borderStyle = 'dashed';
  1676. break;
  1677. case AnnotationBorderStyleType.BEVELED:
  1678. warn('Unimplemented border style: beveled');
  1679. break;
  1680. case AnnotationBorderStyleType.INSET:
  1681. warn('Unimplemented border style: inset');
  1682. break;
  1683. case AnnotationBorderStyleType.UNDERLINE:
  1684. container.style.borderBottomStyle = 'solid';
  1685. break;
  1686. default:
  1687. break;
  1688. }
  1689. if (data.color) {
  1690. container.style.borderColor =
  1691. Util.makeCssRgb(data.color[0] | 0,
  1692. data.color[1] | 0,
  1693. data.color[2] | 0);
  1694. } else {
  1695. // Transparent (invisible) border, so do not draw it at all.
  1696. container.style.borderWidth = 0;
  1697. }
  1698. }
  1699. container.style.left = data.rect[0] + 'px';
  1700. container.style.top = data.rect[1] + 'px';
  1701. container.style.width = width + 'px';
  1702. container.style.height = height + 'px';
  1703. return container;
  1704. }
  1705. function getHtmlElementForTextWidgetAnnotation(item, page, viewport) {
  1706. var container = getContainer(item, page, viewport);
  1707. var content = document.createElement('div');
  1708. content.textContent = item.fieldValue;
  1709. var textAlignment = item.textAlignment;
  1710. content.style.textAlign = ['left', 'center', 'right'][textAlignment];
  1711. content.style.verticalAlign = 'middle';
  1712. content.style.display = 'table-cell';
  1713. var fontObj = item.fontRefName ?
  1714. page.commonObjs.getData(item.fontRefName) : null;
  1715. setTextStyles(content, item, fontObj);
  1716. container.appendChild(content);
  1717. return container;
  1718. }
  1719. function getHtmlElementForTextAnnotation(item, page, viewport) {
  1720. var rect = item.rect;
  1721. // sanity check because of OOo-generated PDFs
  1722. if ((rect[3] - rect[1]) < ANNOT_MIN_SIZE) {
  1723. rect[3] = rect[1] + ANNOT_MIN_SIZE;
  1724. }
  1725. if ((rect[2] - rect[0]) < ANNOT_MIN_SIZE) {
  1726. rect[2] = rect[0] + (rect[3] - rect[1]); // make it square
  1727. }
  1728. var container = getContainer(item, page, viewport);
  1729. container.className = 'annotText';
  1730. var image = document.createElement('img');
  1731. image.style.height = container.style.height;
  1732. image.style.width = container.style.width;
  1733. var iconName = item.name;
  1734. image.src = PDFJS.imageResourcesPath + 'annotation-' +
  1735. iconName.toLowerCase() + '.svg';
  1736. image.alt = '[{{type}} Annotation]';
  1737. image.dataset.l10nId = 'text_annotation_type';
  1738. image.dataset.l10nArgs = JSON.stringify({type: iconName});
  1739. var contentWrapper = document.createElement('div');
  1740. contentWrapper.className = 'annotTextContentWrapper';
  1741. contentWrapper.style.left = Math.floor(rect[2] - rect[0] + 5) + 'px';
  1742. contentWrapper.style.top = '-10px';
  1743. var content = document.createElement('div');
  1744. content.className = 'annotTextContent';
  1745. content.setAttribute('hidden', true);
  1746. var i, ii;
  1747. if (item.hasBgColor && item.color) {
  1748. var color = item.color;
  1749. // Enlighten the color (70%)
  1750. var BACKGROUND_ENLIGHT = 0.7;
  1751. var r = BACKGROUND_ENLIGHT * (255 - color[0]) + color[0];
  1752. var g = BACKGROUND_ENLIGHT * (255 - color[1]) + color[1];
  1753. var b = BACKGROUND_ENLIGHT * (255 - color[2]) + color[2];
  1754. content.style.backgroundColor = Util.makeCssRgb(r | 0, g | 0, b | 0);
  1755. }
  1756. var title = document.createElement('h1');
  1757. var text = document.createElement('p');
  1758. title.textContent = item.title;
  1759. if (!item.content && !item.title) {
  1760. content.setAttribute('hidden', true);
  1761. } else {
  1762. var e = document.createElement('span');
  1763. var lines = item.content.split(/(?:\r\n?|\n)/);
  1764. for (i = 0, ii = lines.length; i < ii; ++i) {
  1765. var line = lines[i];
  1766. e.appendChild(document.createTextNode(line));
  1767. if (i < (ii - 1)) {
  1768. e.appendChild(document.createElement('br'));
  1769. }
  1770. }
  1771. text.appendChild(e);
  1772. var pinned = false;
  1773. var showAnnotation = function showAnnotation(pin) {
  1774. if (pin) {
  1775. pinned = true;
  1776. }
  1777. if (content.hasAttribute('hidden')) {
  1778. container.style.zIndex += 1;
  1779. content.removeAttribute('hidden');
  1780. }
  1781. };
  1782. var hideAnnotation = function hideAnnotation(unpin) {
  1783. if (unpin) {
  1784. pinned = false;
  1785. }
  1786. if (!content.hasAttribute('hidden') && !pinned) {
  1787. container.style.zIndex -= 1;
  1788. content.setAttribute('hidden', true);
  1789. }
  1790. };
  1791. var toggleAnnotation = function toggleAnnotation() {
  1792. if (pinned) {
  1793. hideAnnotation(true);
  1794. } else {
  1795. showAnnotation(true);
  1796. }
  1797. };
  1798. image.addEventListener('click', function image_clickHandler() {
  1799. toggleAnnotation();
  1800. }, false);
  1801. image.addEventListener('mouseover', function image_mouseOverHandler() {
  1802. showAnnotation();
  1803. }, false);
  1804. image.addEventListener('mouseout', function image_mouseOutHandler() {
  1805. hideAnnotation();
  1806. }, false);
  1807. content.addEventListener('click', function content_clickHandler() {
  1808. hideAnnotation(true);
  1809. }, false);
  1810. }
  1811. content.appendChild(title);
  1812. content.appendChild(text);
  1813. contentWrapper.appendChild(content);
  1814. container.appendChild(image);
  1815. container.appendChild(contentWrapper);
  1816. return container;
  1817. }
  1818. function getHtmlElementForLinkAnnotation(item, page, viewport, linkService) {
  1819. function bindLink(link, dest) {
  1820. link.href = linkService.getDestinationHash(dest);
  1821. link.onclick = function annotationsLayerBuilderLinksOnclick() {
  1822. if (dest) {
  1823. linkService.navigateTo(dest);
  1824. }
  1825. return false;
  1826. };
  1827. if (dest) {
  1828. link.className = 'internalLink';
  1829. }
  1830. }
  1831. function bindNamedAction(link, action) {
  1832. link.href = linkService.getAnchorUrl('');
  1833. link.onclick = function annotationsLayerBuilderNamedActionOnClick() {
  1834. linkService.executeNamedAction(action);
  1835. return false;
  1836. };
  1837. link.className = 'internalLink';
  1838. }
  1839. var container = getContainer(item, page, viewport);
  1840. container.className = 'annotLink';
  1841. var link = document.createElement('a');
  1842. link.href = link.title = item.url || '';
  1843. if (item.url && isExternalLinkTargetSet()) {
  1844. link.target = LinkTargetStringMap[PDFJS.externalLinkTarget];
  1845. }
  1846. // Strip referrer
  1847. if (item.url) {
  1848. link.rel = PDFJS.externalLinkRel;
  1849. }
  1850. if (!item.url) {
  1851. if (item.action) {
  1852. bindNamedAction(link, item.action);
  1853. } else {
  1854. bindLink(link, ('dest' in item) ? item.dest : null);
  1855. }
  1856. }
  1857. container.appendChild(link);
  1858. return container;
  1859. }
  1860. function getHtmlElement(data, page, viewport, linkService) {
  1861. switch (data.annotationType) {
  1862. case AnnotationType.WIDGET:
  1863. return getHtmlElementForTextWidgetAnnotation(data, page, viewport);
  1864. case AnnotationType.TEXT:
  1865. return getHtmlElementForTextAnnotation(data, page, viewport);
  1866. case AnnotationType.LINK:
  1867. return getHtmlElementForLinkAnnotation(data, page, viewport,
  1868. linkService);
  1869. default:
  1870. throw new Error('Unsupported annotationType: ' + data.annotationType);
  1871. }
  1872. }
  1873. function render(viewport, div, annotations, page, linkService) {
  1874. for (var i = 0, ii = annotations.length; i < ii; i++) {
  1875. var data = annotations[i];
  1876. if (!data || !data.hasHtml) {
  1877. continue;
  1878. }
  1879. var element = getHtmlElement(data, page, viewport, linkService);
  1880. div.appendChild(element);
  1881. }
  1882. }
  1883. function update(viewport, div, annotations) {
  1884. for (var i = 0, ii = annotations.length; i < ii; i++) {
  1885. var data = annotations[i];
  1886. var element = div.querySelector(
  1887. '[data-annotation-id="' + data.id + '"]');
  1888. if (element) {
  1889. CustomStyle.setProp('transform', element,
  1890. 'matrix(' + viewport.transform.join(',') + ')');
  1891. }
  1892. }
  1893. div.removeAttribute('hidden');
  1894. }
  1895. return {
  1896. render: render,
  1897. update: update
  1898. };
  1899. })();
  1900. PDFJS.AnnotationLayer = AnnotationLayer;
  1901. exports.AnnotationLayer = AnnotationLayer;
  1902. }));
  1903. (function (root, factory) {
  1904. {
  1905. factory((root.pdfjsDisplayFontLoader = {}), root.pdfjsSharedUtil,
  1906. root.pdfjsSharedGlobal);
  1907. }
  1908. }(this, function (exports, sharedUtil, sharedGlobal) {
  1909. var assert = sharedUtil.assert;
  1910. var bytesToString = sharedUtil.bytesToString;
  1911. var string32 = sharedUtil.string32;
  1912. var shadow = sharedUtil.shadow;
  1913. var warn = sharedUtil.warn;
  1914. var PDFJS = sharedGlobal.PDFJS;
  1915. var globalScope = sharedGlobal.globalScope;
  1916. var isWorker = sharedGlobal.isWorker;
  1917. function FontLoader(docId) {
  1918. this.docId = docId;
  1919. this.styleElement = null;
  1920. this.nativeFontFaces = [];
  1921. this.loadTestFontId = 0;
  1922. this.loadingContext = {
  1923. requests: [],
  1924. nextRequestId: 0
  1925. };
  1926. }
  1927. FontLoader.prototype = {
  1928. insertRule: function fontLoaderInsertRule(rule) {
  1929. var styleElement = this.styleElement;
  1930. if (!styleElement) {
  1931. styleElement = this.styleElement = document.createElement('style');
  1932. styleElement.id = 'PDFJS_FONT_STYLE_TAG_' + this.docId;
  1933. document.documentElement.getElementsByTagName('head')[0].appendChild(
  1934. styleElement);
  1935. }
  1936. var styleSheet = styleElement.sheet;
  1937. styleSheet.insertRule(rule, styleSheet.cssRules.length);
  1938. },
  1939. clear: function fontLoaderClear() {
  1940. var styleElement = this.styleElement;
  1941. if (styleElement) {
  1942. styleElement.parentNode.removeChild(styleElement);
  1943. styleElement = this.styleElement = null;
  1944. }
  1945. this.nativeFontFaces.forEach(function(nativeFontFace) {
  1946. document.fonts.delete(nativeFontFace);
  1947. });
  1948. this.nativeFontFaces.length = 0;
  1949. },
  1950. get loadTestFont() {
  1951. // This is a CFF font with 1 glyph for '.' that fills its entire width and
  1952. // height.
  1953. return shadow(this, 'loadTestFont', atob(
  1954. 'T1RUTwALAIAAAwAwQ0ZGIDHtZg4AAAOYAAAAgUZGVE1lkzZwAAAEHAAAABxHREVGABQAFQ' +
  1955. 'AABDgAAAAeT1MvMlYNYwkAAAEgAAAAYGNtYXABDQLUAAACNAAAAUJoZWFk/xVFDQAAALwA' +
  1956. 'AAA2aGhlYQdkA+oAAAD0AAAAJGhtdHgD6AAAAAAEWAAAAAZtYXhwAAJQAAAAARgAAAAGbm' +
  1957. 'FtZVjmdH4AAAGAAAAAsXBvc3T/hgAzAAADeAAAACAAAQAAAAEAALZRFsRfDzz1AAsD6AAA' +
  1958. 'AADOBOTLAAAAAM4KHDwAAAAAA+gDIQAAAAgAAgAAAAAAAAABAAADIQAAAFoD6AAAAAAD6A' +
  1959. 'ABAAAAAAAAAAAAAAAAAAAAAQAAUAAAAgAAAAQD6AH0AAUAAAKKArwAAACMAooCvAAAAeAA' +
  1960. 'MQECAAACAAYJAAAAAAAAAAAAAQAAAAAAAAAAAAAAAFBmRWQAwAAuAC4DIP84AFoDIQAAAA' +
  1961. 'AAAQAAAAAAAAAAACAAIAABAAAADgCuAAEAAAAAAAAAAQAAAAEAAAAAAAEAAQAAAAEAAAAA' +
  1962. 'AAIAAQAAAAEAAAAAAAMAAQAAAAEAAAAAAAQAAQAAAAEAAAAAAAUAAQAAAAEAAAAAAAYAAQ' +
  1963. 'AAAAMAAQQJAAAAAgABAAMAAQQJAAEAAgABAAMAAQQJAAIAAgABAAMAAQQJAAMAAgABAAMA' +
  1964. 'AQQJAAQAAgABAAMAAQQJAAUAAgABAAMAAQQJAAYAAgABWABYAAAAAAAAAwAAAAMAAAAcAA' +
  1965. 'EAAAAAADwAAwABAAAAHAAEACAAAAAEAAQAAQAAAC7//wAAAC7////TAAEAAAAAAAABBgAA' +
  1966. 'AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAA' +
  1967. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' +
  1968. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' +
  1969. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' +
  1970. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMAAA' +
  1971. 'AAAAD/gwAyAAAAAQAAAAAAAAAAAAAAAAAAAAABAAQEAAEBAQJYAAEBASH4DwD4GwHEAvgc' +
  1972. 'A/gXBIwMAYuL+nz5tQXkD5j3CBLnEQACAQEBIVhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWF' +
  1973. 'hYWFhYWFhYAAABAQAADwACAQEEE/t3Dov6fAH6fAT+fPp8+nwHDosMCvm1Cvm1DAz6fBQA' +
  1974. 'AAAAAAABAAAAAMmJbzEAAAAAzgTjFQAAAADOBOQpAAEAAAAAAAAADAAUAAQAAAABAAAAAg' +
  1975. 'ABAAAAAAAAAAAD6AAAAAAAAA=='
  1976. ));
  1977. },
  1978. addNativeFontFace: function fontLoader_addNativeFontFace(nativeFontFace) {
  1979. this.nativeFontFaces.push(nativeFontFace);
  1980. document.fonts.add(nativeFontFace);
  1981. },
  1982. bind: function fontLoaderBind(fonts, callback) {
  1983. assert(!isWorker, 'bind() shall be called from main thread');
  1984. var rules = [];
  1985. var fontsToLoad = [];
  1986. var fontLoadPromises = [];
  1987. var getNativeFontPromise = function(nativeFontFace) {
  1988. // Return a promise that is always fulfilled, even when the font fails to
  1989. // load.
  1990. return nativeFontFace.loaded.catch(function(e) {
  1991. warn('Failed to load font "' + nativeFontFace.family + '": ' + e);
  1992. });
  1993. };
  1994. for (var i = 0, ii = fonts.length; i < ii; i++) {
  1995. var font = fonts[i];
  1996. // Add the font to the DOM only once or skip if the font
  1997. // is already loaded.
  1998. if (font.attached || font.loading === false) {
  1999. continue;
  2000. }
  2001. font.attached = true;
  2002. if (FontLoader.isFontLoadingAPISupported) {
  2003. var nativeFontFace = font.createNativeFontFace();
  2004. if (nativeFontFace) {
  2005. this.addNativeFontFace(nativeFontFace);
  2006. fontLoadPromises.push(getNativeFontPromise(nativeFontFace));
  2007. }
  2008. } else {
  2009. var rule = font.createFontFaceRule();
  2010. if (rule) {
  2011. this.insertRule(rule);
  2012. rules.push(rule);
  2013. fontsToLoad.push(font);
  2014. }
  2015. }
  2016. }
  2017. var request = this.queueLoadingCallback(callback);
  2018. if (FontLoader.isFontLoadingAPISupported) {
  2019. Promise.all(fontLoadPromises).then(function() {
  2020. request.complete();
  2021. });
  2022. } else if (rules.length > 0 && !FontLoader.isSyncFontLoadingSupported) {
  2023. this.prepareFontLoadEvent(rules, fontsToLoad, request);
  2024. } else {
  2025. request.complete();
  2026. }
  2027. },
  2028. queueLoadingCallback: function FontLoader_queueLoadingCallback(callback) {
  2029. function LoadLoader_completeRequest() {
  2030. assert(!request.end, 'completeRequest() cannot be called twice');
  2031. request.end = Date.now();
  2032. // sending all completed requests in order how they were queued
  2033. while (context.requests.length > 0 && context.requests[0].end) {
  2034. var otherRequest = context.requests.shift();
  2035. setTimeout(otherRequest.callback, 0);
  2036. }
  2037. }
  2038. var context = this.loadingContext;
  2039. var requestId = 'pdfjs-font-loading-' + (context.nextRequestId++);
  2040. var request = {
  2041. id: requestId,
  2042. complete: LoadLoader_completeRequest,
  2043. callback: callback,
  2044. started: Date.now()
  2045. };
  2046. context.requests.push(request);
  2047. return request;
  2048. },
  2049. prepareFontLoadEvent: function fontLoaderPrepareFontLoadEvent(rules,
  2050. fonts,
  2051. request) {
  2052. /** Hack begin */
  2053. // There's currently no event when a font has finished downloading so the
  2054. // following code is a dirty hack to 'guess' when a font is
  2055. // ready. It's assumed fonts are loaded in order, so add a known test
  2056. // font after the desired fonts and then test for the loading of that
  2057. // test font.
  2058. function int32(data, offset) {
  2059. return (data.charCodeAt(offset) << 24) |
  2060. (data.charCodeAt(offset + 1) << 16) |
  2061. (data.charCodeAt(offset + 2) << 8) |
  2062. (data.charCodeAt(offset + 3) & 0xff);
  2063. }
  2064. function spliceString(s, offset, remove, insert) {
  2065. var chunk1 = s.substr(0, offset);
  2066. var chunk2 = s.substr(offset + remove);
  2067. return chunk1 + insert + chunk2;
  2068. }
  2069. var i, ii;
  2070. var canvas = document.createElement('canvas');
  2071. canvas.width = 1;
  2072. canvas.height = 1;
  2073. var ctx = canvas.getContext('2d');
  2074. var called = 0;
  2075. function isFontReady(name, callback) {
  2076. called++;
  2077. // With setTimeout clamping this gives the font ~100ms to load.
  2078. if(called > 30) {
  2079. warn('Load test font never loaded.');
  2080. callback();
  2081. return;
  2082. }
  2083. ctx.font = '30px ' + name;
  2084. ctx.fillText('.', 0, 20);
  2085. var imageData = ctx.getImageData(0, 0, 1, 1);
  2086. if (imageData.data[3] > 0) {
  2087. callback();
  2088. return;
  2089. }
  2090. setTimeout(isFontReady.bind(null, name, callback));
  2091. }
  2092. var loadTestFontId = 'lt' + Date.now() + this.loadTestFontId++;
  2093. // Chromium seems to cache fonts based on a hash of the actual font data,
  2094. // so the font must be modified for each load test else it will appear to
  2095. // be loaded already.
  2096. // TODO: This could maybe be made faster by avoiding the btoa of the full
  2097. // font by splitting it in chunks before hand and padding the font id.
  2098. var data = this.loadTestFont;
  2099. var COMMENT_OFFSET = 976; // has to be on 4 byte boundary (for checksum)
  2100. data = spliceString(data, COMMENT_OFFSET, loadTestFontId.length,
  2101. loadTestFontId);
  2102. // CFF checksum is important for IE, adjusting it
  2103. var CFF_CHECKSUM_OFFSET = 16;
  2104. var XXXX_VALUE = 0x58585858; // the "comment" filled with 'X'
  2105. var checksum = int32(data, CFF_CHECKSUM_OFFSET);
  2106. for (i = 0, ii = loadTestFontId.length - 3; i < ii; i += 4) {
  2107. checksum = (checksum - XXXX_VALUE + int32(loadTestFontId, i)) | 0;
  2108. }
  2109. if (i < loadTestFontId.length) { // align to 4 bytes boundary
  2110. checksum = (checksum - XXXX_VALUE +
  2111. int32(loadTestFontId + 'XXX', i)) | 0;
  2112. }
  2113. data = spliceString(data, CFF_CHECKSUM_OFFSET, 4, string32(checksum));
  2114. var url = 'url(data:font/opentype;base64,' + btoa(data) + ');';
  2115. var rule = '@font-face { font-family:"' + loadTestFontId + '";src:' +
  2116. url + '}';
  2117. this.insertRule(rule);
  2118. var names = [];
  2119. for (i = 0, ii = fonts.length; i < ii; i++) {
  2120. names.push(fonts[i].loadedName);
  2121. }
  2122. names.push(loadTestFontId);
  2123. var div = document.createElement('div');
  2124. div.setAttribute('style',
  2125. 'visibility: hidden;' +
  2126. 'width: 10px; height: 10px;' +
  2127. 'position: absolute; top: 0px; left: 0px;');
  2128. for (i = 0, ii = names.length; i < ii; ++i) {
  2129. var span = document.createElement('span');
  2130. span.textContent = 'Hi';
  2131. span.style.fontFamily = names[i];
  2132. div.appendChild(span);
  2133. }
  2134. document.body.appendChild(div);
  2135. isFontReady(loadTestFontId, function() {
  2136. document.body.removeChild(div);
  2137. request.complete();
  2138. });
  2139. /** Hack end */
  2140. }
  2141. };
  2142. FontLoader.isFontLoadingAPISupported = (!isWorker &&
  2143. typeof document !== 'undefined' && !!document.fonts);
  2144. Object.defineProperty(FontLoader, 'isSyncFontLoadingSupported', {
  2145. get: function () {
  2146. var supported = false;
  2147. // User agent string sniffing is bad, but there is no reliable way to tell
  2148. // if font is fully loaded and ready to be used with canvas.
  2149. var userAgent = window.navigator.userAgent;
  2150. var m = /Mozilla\/5.0.*?rv:(\d+).*? Gecko/.exec(userAgent);
  2151. if (m && m[1] >= 14) {
  2152. supported = true;
  2153. }
  2154. // TODO other browsers
  2155. if (userAgent === 'node') {
  2156. supported = true;
  2157. }
  2158. return shadow(FontLoader, 'isSyncFontLoadingSupported', supported);
  2159. },
  2160. enumerable: true,
  2161. configurable: true
  2162. });
  2163. var FontFaceObject = (function FontFaceObjectClosure() {
  2164. function FontFaceObject(translatedData) {
  2165. this.compiledGlyphs = {};
  2166. // importing translated data
  2167. for (var i in translatedData) {
  2168. this[i] = translatedData[i];
  2169. }
  2170. }
  2171. Object.defineProperty(FontFaceObject, 'isEvalSupported', {
  2172. get: function () {
  2173. var evalSupport = false;
  2174. if (PDFJS.isEvalSupported) {
  2175. try {
  2176. /* jshint evil: true */
  2177. new Function('');
  2178. evalSupport = true;
  2179. } catch (e) {}
  2180. }
  2181. return shadow(this, 'isEvalSupported', evalSupport);
  2182. },
  2183. enumerable: true,
  2184. configurable: true
  2185. });
  2186. FontFaceObject.prototype = {
  2187. createNativeFontFace: function FontFaceObject_createNativeFontFace() {
  2188. if (!this.data) {
  2189. return null;
  2190. }
  2191. if (PDFJS.disableFontFace) {
  2192. this.disableFontFace = true;
  2193. return null;
  2194. }
  2195. var nativeFontFace = new FontFace(this.loadedName, this.data, {});
  2196. if (PDFJS.pdfBug && 'FontInspector' in globalScope &&
  2197. globalScope['FontInspector'].enabled) {
  2198. globalScope['FontInspector'].fontAdded(this);
  2199. }
  2200. return nativeFontFace;
  2201. },
  2202. createFontFaceRule: function FontFaceObject_createFontFaceRule() {
  2203. if (!this.data) {
  2204. return null;
  2205. }
  2206. if (PDFJS.disableFontFace) {
  2207. this.disableFontFace = true;
  2208. return null;
  2209. }
  2210. var data = bytesToString(new Uint8Array(this.data));
  2211. var fontName = this.loadedName;
  2212. // Add the font-face rule to the document
  2213. var url = ('url(data:' + this.mimetype + ';base64,' +
  2214. window.btoa(data) + ');');
  2215. var rule = '@font-face { font-family:"' + fontName + '";src:' + url + '}';
  2216. if (PDFJS.pdfBug && 'FontInspector' in globalScope &&
  2217. globalScope['FontInspector'].enabled) {
  2218. globalScope['FontInspector'].fontAdded(this, url);
  2219. }
  2220. return rule;
  2221. },
  2222. getPathGenerator:
  2223. function FontFaceObject_getPathGenerator(objs, character) {
  2224. if (!(character in this.compiledGlyphs)) {
  2225. var cmds = objs.get(this.loadedName + '_path_' + character);
  2226. var current, i, len;
  2227. // If we can, compile cmds into JS for MAXIMUM SPEED
  2228. if (FontFaceObject.isEvalSupported) {
  2229. var args, js = '';
  2230. for (i = 0, len = cmds.length; i < len; i++) {
  2231. current = cmds[i];
  2232. if (current.args !== undefined) {
  2233. args = current.args.join(',');
  2234. } else {
  2235. args = '';
  2236. }
  2237. js += 'c.' + current.cmd + '(' + args + ');\n';
  2238. }
  2239. /* jshint -W054 */
  2240. this.compiledGlyphs[character] = new Function('c', 'size', js);
  2241. } else {
  2242. // But fall back on using Function.prototype.apply() if we're
  2243. // blocked from using eval() for whatever reason (like CSP policies)
  2244. this.compiledGlyphs[character] = function(c, size) {
  2245. for (i = 0, len = cmds.length; i < len; i++) {
  2246. current = cmds[i];
  2247. if (current.cmd === 'scale') {
  2248. current.args = [size, -size];
  2249. }
  2250. c[current.cmd].apply(c, current.args);
  2251. }
  2252. };
  2253. }
  2254. }
  2255. return this.compiledGlyphs[character];
  2256. }
  2257. };
  2258. return FontFaceObject;
  2259. })();
  2260. exports.FontFaceObject = FontFaceObject;
  2261. exports.FontLoader = FontLoader;
  2262. }));
  2263. (function (root, factory) {
  2264. {
  2265. factory((root.pdfjsDisplayMetadata = {}), root.pdfjsSharedUtil);
  2266. }
  2267. }(this, function (exports, sharedUtil) {
  2268. var error = sharedUtil.error;
  2269. var Metadata = PDFJS.Metadata = (function MetadataClosure() {
  2270. function fixMetadata(meta) {
  2271. return meta.replace(/>\\376\\377([^<]+)/g, function(all, codes) {
  2272. var bytes = codes.replace(/\\([0-3])([0-7])([0-7])/g,
  2273. function(code, d1, d2, d3) {
  2274. return String.fromCharCode(d1 * 64 + d2 * 8 + d3 * 1);
  2275. });
  2276. var chars = '';
  2277. for (var i = 0; i < bytes.length; i += 2) {
  2278. var code = bytes.charCodeAt(i) * 256 + bytes.charCodeAt(i + 1);
  2279. chars += code >= 32 && code < 127 && code !== 60 && code !== 62 &&
  2280. code !== 38 && false ? String.fromCharCode(code) :
  2281. '&#x' + (0x10000 + code).toString(16).substring(1) + ';';
  2282. }
  2283. return '>' + chars;
  2284. });
  2285. }
  2286. function Metadata(meta) {
  2287. if (typeof meta === 'string') {
  2288. // Ghostscript produces invalid metadata
  2289. meta = fixMetadata(meta);
  2290. var parser = new DOMParser();
  2291. meta = parser.parseFromString(meta, 'application/xml');
  2292. } else if (!(meta instanceof Document)) {
  2293. error('Metadata: Invalid metadata object');
  2294. }
  2295. this.metaDocument = meta;
  2296. this.metadata = {};
  2297. this.parse();
  2298. }
  2299. Metadata.prototype = {
  2300. parse: function Metadata_parse() {
  2301. var doc = this.metaDocument;
  2302. var rdf = doc.documentElement;
  2303. if (rdf.nodeName.toLowerCase() !== 'rdf:rdf') { // Wrapped in <xmpmeta>
  2304. rdf = rdf.firstChild;
  2305. while (rdf && rdf.nodeName.toLowerCase() !== 'rdf:rdf') {
  2306. rdf = rdf.nextSibling;
  2307. }
  2308. }
  2309. var nodeName = (rdf) ? rdf.nodeName.toLowerCase() : null;
  2310. if (!rdf || nodeName !== 'rdf:rdf' || !rdf.hasChildNodes()) {
  2311. return;
  2312. }
  2313. var children = rdf.childNodes, desc, entry, name, i, ii, length, iLength;
  2314. for (i = 0, length = children.length; i < length; i++) {
  2315. desc = children[i];
  2316. if (desc.nodeName.toLowerCase() !== 'rdf:description') {
  2317. continue;
  2318. }
  2319. for (ii = 0, iLength = desc.childNodes.length; ii < iLength; ii++) {
  2320. if (desc.childNodes[ii].nodeName.toLowerCase() !== '#text') {
  2321. entry = desc.childNodes[ii];
  2322. name = entry.nodeName.toLowerCase();
  2323. this.metadata[name] = entry.textContent.trim();
  2324. }
  2325. }
  2326. }
  2327. },
  2328. get: function Metadata_get(name) {
  2329. return this.metadata[name] || null;
  2330. },
  2331. has: function Metadata_has(name) {
  2332. return typeof this.metadata[name] !== 'undefined';
  2333. }
  2334. };
  2335. return Metadata;
  2336. })();
  2337. exports.Metadata = Metadata;
  2338. }));
  2339. (function (root, factory) {
  2340. {
  2341. factory((root.pdfjsDisplayTextLayer = {}), root.pdfjsSharedUtil);
  2342. }
  2343. }(this, function (exports, sharedUtil) {
  2344. var createPromiseCapability = sharedUtil.createPromiseCapability;
  2345. /**
  2346. * Text layer render parameters.
  2347. *
  2348. * @typedef {Object} TextLayerRenderParameters
  2349. * @property {TextContent} textContent - Text content to render (the object is
  2350. * returned by the page's getTextContent() method).
  2351. * @property {HTMLElement} container - HTML element that will contain text runs.
  2352. * @property {PDFJS.PageViewport} viewport - The target viewport to properly
  2353. * layout the text runs.
  2354. * @property {Array} textDivs - (optional) HTML elements that are correspond
  2355. * the text items of the textContent input. This is output and shall be
  2356. * initially be set to empty array.
  2357. * @property {number} timeout - (optional) Delay in milliseconds before
  2358. * rendering of the text runs occurs.
  2359. */
  2360. var renderTextLayer = (function renderTextLayerClosure() {
  2361. var MAX_TEXT_DIVS_TO_RENDER = 100000;
  2362. var NonWhitespaceRegexp = /\S/;
  2363. function isAllWhitespace(str) {
  2364. return !NonWhitespaceRegexp.test(str);
  2365. }
  2366. function appendText(textDivs, viewport, geom, styles) {
  2367. var style = styles[geom.fontName];
  2368. var textDiv = document.createElement('div');
  2369. textDivs.push(textDiv);
  2370. if (isAllWhitespace(geom.str)) {
  2371. textDiv.dataset.isWhitespace = true;
  2372. return;
  2373. }
  2374. var tx = PDFJS.Util.transform(viewport.transform, geom.transform);
  2375. var angle = Math.atan2(tx[1], tx[0]);
  2376. if (style.vertical) {
  2377. angle += Math.PI / 2;
  2378. }
  2379. var fontHeight = Math.sqrt((tx[2] * tx[2]) + (tx[3] * tx[3]));
  2380. var fontAscent = fontHeight;
  2381. if (style.ascent) {
  2382. fontAscent = style.ascent * fontAscent;
  2383. } else if (style.descent) {
  2384. fontAscent = (1 + style.descent) * fontAscent;
  2385. }
  2386. var left;
  2387. var top;
  2388. if (angle === 0) {
  2389. left = tx[4];
  2390. top = tx[5] - fontAscent;
  2391. } else {
  2392. left = tx[4] + (fontAscent * Math.sin(angle));
  2393. top = tx[5] - (fontAscent * Math.cos(angle));
  2394. }
  2395. textDiv.style.left = left + 'px';
  2396. textDiv.style.top = top + 'px';
  2397. textDiv.style.fontSize = fontHeight + 'px';
  2398. textDiv.style.fontFamily = style.fontFamily;
  2399. textDiv.textContent = geom.str;
  2400. // |fontName| is only used by the Font Inspector. This test will succeed
  2401. // when e.g. the Font Inspector is off but the Stepper is on, but it's
  2402. // not worth the effort to do a more accurate test.
  2403. if (PDFJS.pdfBug) {
  2404. textDiv.dataset.fontName = geom.fontName;
  2405. }
  2406. // Storing into dataset will convert number into string.
  2407. if (angle !== 0) {
  2408. textDiv.dataset.angle = angle * (180 / Math.PI);
  2409. }
  2410. // We don't bother scaling single-char text divs, because it has very
  2411. // little effect on text highlighting. This makes scrolling on docs with
  2412. // lots of such divs a lot faster.
  2413. if (geom.str.length > 1) {
  2414. if (style.vertical) {
  2415. textDiv.dataset.canvasWidth = geom.height * viewport.scale;
  2416. } else {
  2417. textDiv.dataset.canvasWidth = geom.width * viewport.scale;
  2418. }
  2419. }
  2420. }
  2421. function render(task) {
  2422. if (task._canceled) {
  2423. return;
  2424. }
  2425. var textLayerFrag = task._container;
  2426. var textDivs = task._textDivs;
  2427. var capability = task._capability;
  2428. var textDivsLength = textDivs.length;
  2429. // No point in rendering many divs as it would make the browser
  2430. // unusable even after the divs are rendered.
  2431. if (textDivsLength > MAX_TEXT_DIVS_TO_RENDER) {
  2432. capability.resolve();
  2433. return;
  2434. }
  2435. var canvas = document.createElement('canvas');
  2436. var ctx = canvas.getContext('2d', {alpha: false});
  2437. var lastFontSize;
  2438. var lastFontFamily;
  2439. for (var i = 0; i < textDivsLength; i++) {
  2440. var textDiv = textDivs[i];
  2441. if (textDiv.dataset.isWhitespace !== undefined) {
  2442. continue;
  2443. }
  2444. var fontSize = textDiv.style.fontSize;
  2445. var fontFamily = textDiv.style.fontFamily;
  2446. // Only build font string and set to context if different from last.
  2447. if (fontSize !== lastFontSize || fontFamily !== lastFontFamily) {
  2448. ctx.font = fontSize + ' ' + fontFamily;
  2449. lastFontSize = fontSize;
  2450. lastFontFamily = fontFamily;
  2451. }
  2452. var width = ctx.measureText(textDiv.textContent).width;
  2453. if (width > 0) {
  2454. textLayerFrag.appendChild(textDiv);
  2455. var transform;
  2456. if (textDiv.dataset.canvasWidth !== undefined) {
  2457. // Dataset values come of type string.
  2458. var textScale = textDiv.dataset.canvasWidth / width;
  2459. transform = 'scaleX(' + textScale + ')';
  2460. } else {
  2461. transform = '';
  2462. }
  2463. var rotation = textDiv.dataset.angle;
  2464. if (rotation) {
  2465. transform = 'rotate(' + rotation + 'deg) ' + transform;
  2466. }
  2467. if (transform) {
  2468. PDFJS.CustomStyle.setProp('transform' , textDiv, transform);
  2469. }
  2470. }
  2471. }
  2472. capability.resolve();
  2473. }
  2474. /**
  2475. * Text layer rendering task.
  2476. *
  2477. * @param {TextContent} textContent
  2478. * @param {HTMLElement} container
  2479. * @param {PDFJS.PageViewport} viewport
  2480. * @param {Array} textDivs
  2481. * @private
  2482. */
  2483. function TextLayerRenderTask(textContent, container, viewport, textDivs) {
  2484. this._textContent = textContent;
  2485. this._container = container;
  2486. this._viewport = viewport;
  2487. textDivs = textDivs || [];
  2488. this._textDivs = textDivs;
  2489. this._canceled = false;
  2490. this._capability = createPromiseCapability();
  2491. this._renderTimer = null;
  2492. }
  2493. TextLayerRenderTask.prototype = {
  2494. get promise() {
  2495. return this._capability.promise;
  2496. },
  2497. cancel: function TextLayer_cancel() {
  2498. this._canceled = true;
  2499. if (this._renderTimer !== null) {
  2500. clearTimeout(this._renderTimer);
  2501. this._renderTimer = null;
  2502. }
  2503. this._capability.reject('canceled');
  2504. },
  2505. _render: function TextLayer_render(timeout) {
  2506. var textItems = this._textContent.items;
  2507. var styles = this._textContent.styles;
  2508. var textDivs = this._textDivs;
  2509. var viewport = this._viewport;
  2510. for (var i = 0, len = textItems.length; i < len; i++) {
  2511. appendText(textDivs, viewport, textItems[i], styles);
  2512. }
  2513. if (!timeout) { // Render right away
  2514. render(this);
  2515. } else { // Schedule
  2516. var self = this;
  2517. this._renderTimer = setTimeout(function() {
  2518. render(self);
  2519. self._renderTimer = null;
  2520. }, timeout);
  2521. }
  2522. }
  2523. };
  2524. /**
  2525. * Starts rendering of the text layer.
  2526. *
  2527. * @param {TextLayerRenderParameters} renderParameters
  2528. * @returns {TextLayerRenderTask}
  2529. */
  2530. function renderTextLayer(renderParameters) {
  2531. var task = new TextLayerRenderTask(renderParameters.textContent,
  2532. renderParameters.container,
  2533. renderParameters.viewport,
  2534. renderParameters.textDivs);
  2535. task._render(renderParameters.timeout);
  2536. return task;
  2537. }
  2538. return renderTextLayer;
  2539. })();
  2540. PDFJS.renderTextLayer = renderTextLayer;
  2541. exports.renderTextLayer = renderTextLayer;
  2542. }));
  2543. (function (root, factory) {
  2544. {
  2545. factory((root.pdfjsDisplayWebGL = {}), root.pdfjsSharedUtil);
  2546. }
  2547. }(this, function (exports, sharedUtil) {
  2548. var shadow = sharedUtil.shadow;
  2549. var WebGLUtils = (function WebGLUtilsClosure() {
  2550. function loadShader(gl, code, shaderType) {
  2551. var shader = gl.createShader(shaderType);
  2552. gl.shaderSource(shader, code);
  2553. gl.compileShader(shader);
  2554. var compiled = gl.getShaderParameter(shader, gl.COMPILE_STATUS);
  2555. if (!compiled) {
  2556. var errorMsg = gl.getShaderInfoLog(shader);
  2557. throw new Error('Error during shader compilation: ' + errorMsg);
  2558. }
  2559. return shader;
  2560. }
  2561. function createVertexShader(gl, code) {
  2562. return loadShader(gl, code, gl.VERTEX_SHADER);
  2563. }
  2564. function createFragmentShader(gl, code) {
  2565. return loadShader(gl, code, gl.FRAGMENT_SHADER);
  2566. }
  2567. function createProgram(gl, shaders) {
  2568. var program = gl.createProgram();
  2569. for (var i = 0, ii = shaders.length; i < ii; ++i) {
  2570. gl.attachShader(program, shaders[i]);
  2571. }
  2572. gl.linkProgram(program);
  2573. var linked = gl.getProgramParameter(program, gl.LINK_STATUS);
  2574. if (!linked) {
  2575. var errorMsg = gl.getProgramInfoLog(program);
  2576. throw new Error('Error during program linking: ' + errorMsg);
  2577. }
  2578. return program;
  2579. }
  2580. function createTexture(gl, image, textureId) {
  2581. gl.activeTexture(textureId);
  2582. var texture = gl.createTexture();
  2583. gl.bindTexture(gl.TEXTURE_2D, texture);
  2584. // Set the parameters so we can render any size image.
  2585. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
  2586. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
  2587. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
  2588. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
  2589. // Upload the image into the texture.
  2590. gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image);
  2591. return texture;
  2592. }
  2593. var currentGL, currentCanvas;
  2594. function generateGL() {
  2595. if (currentGL) {
  2596. return;
  2597. }
  2598. currentCanvas = document.createElement('canvas');
  2599. currentGL = currentCanvas.getContext('webgl',
  2600. { premultipliedalpha: false });
  2601. }
  2602. var smaskVertexShaderCode = '\
  2603. attribute vec2 a_position; \
  2604. attribute vec2 a_texCoord; \
  2605. \
  2606. uniform vec2 u_resolution; \
  2607. \
  2608. varying vec2 v_texCoord; \
  2609. \
  2610. void main() { \
  2611. vec2 clipSpace = (a_position / u_resolution) * 2.0 - 1.0; \
  2612. gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1); \
  2613. \
  2614. v_texCoord = a_texCoord; \
  2615. } ';
  2616. var smaskFragmentShaderCode = '\
  2617. precision mediump float; \
  2618. \
  2619. uniform vec4 u_backdrop; \
  2620. uniform int u_subtype; \
  2621. uniform sampler2D u_image; \
  2622. uniform sampler2D u_mask; \
  2623. \
  2624. varying vec2 v_texCoord; \
  2625. \
  2626. void main() { \
  2627. vec4 imageColor = texture2D(u_image, v_texCoord); \
  2628. vec4 maskColor = texture2D(u_mask, v_texCoord); \
  2629. if (u_backdrop.a > 0.0) { \
  2630. maskColor.rgb = maskColor.rgb * maskColor.a + \
  2631. u_backdrop.rgb * (1.0 - maskColor.a); \
  2632. } \
  2633. float lum; \
  2634. if (u_subtype == 0) { \
  2635. lum = maskColor.a; \
  2636. } else { \
  2637. lum = maskColor.r * 0.3 + maskColor.g * 0.59 + \
  2638. maskColor.b * 0.11; \
  2639. } \
  2640. imageColor.a *= lum; \
  2641. imageColor.rgb *= imageColor.a; \
  2642. gl_FragColor = imageColor; \
  2643. } ';
  2644. var smaskCache = null;
  2645. function initSmaskGL() {
  2646. var canvas, gl;
  2647. generateGL();
  2648. canvas = currentCanvas;
  2649. currentCanvas = null;
  2650. gl = currentGL;
  2651. currentGL = null;
  2652. // setup a GLSL program
  2653. var vertexShader = createVertexShader(gl, smaskVertexShaderCode);
  2654. var fragmentShader = createFragmentShader(gl, smaskFragmentShaderCode);
  2655. var program = createProgram(gl, [vertexShader, fragmentShader]);
  2656. gl.useProgram(program);
  2657. var cache = {};
  2658. cache.gl = gl;
  2659. cache.canvas = canvas;
  2660. cache.resolutionLocation = gl.getUniformLocation(program, 'u_resolution');
  2661. cache.positionLocation = gl.getAttribLocation(program, 'a_position');
  2662. cache.backdropLocation = gl.getUniformLocation(program, 'u_backdrop');
  2663. cache.subtypeLocation = gl.getUniformLocation(program, 'u_subtype');
  2664. var texCoordLocation = gl.getAttribLocation(program, 'a_texCoord');
  2665. var texLayerLocation = gl.getUniformLocation(program, 'u_image');
  2666. var texMaskLocation = gl.getUniformLocation(program, 'u_mask');
  2667. // provide texture coordinates for the rectangle.
  2668. var texCoordBuffer = gl.createBuffer();
  2669. gl.bindBuffer(gl.ARRAY_BUFFER, texCoordBuffer);
  2670. gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
  2671. 0.0, 0.0,
  2672. 1.0, 0.0,
  2673. 0.0, 1.0,
  2674. 0.0, 1.0,
  2675. 1.0, 0.0,
  2676. 1.0, 1.0]), gl.STATIC_DRAW);
  2677. gl.enableVertexAttribArray(texCoordLocation);
  2678. gl.vertexAttribPointer(texCoordLocation, 2, gl.FLOAT, false, 0, 0);
  2679. gl.uniform1i(texLayerLocation, 0);
  2680. gl.uniform1i(texMaskLocation, 1);
  2681. smaskCache = cache;
  2682. }
  2683. function composeSMask(layer, mask, properties) {
  2684. var width = layer.width, height = layer.height;
  2685. if (!smaskCache) {
  2686. initSmaskGL();
  2687. }
  2688. var cache = smaskCache,canvas = cache.canvas, gl = cache.gl;
  2689. canvas.width = width;
  2690. canvas.height = height;
  2691. gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
  2692. gl.uniform2f(cache.resolutionLocation, width, height);
  2693. if (properties.backdrop) {
  2694. gl.uniform4f(cache.resolutionLocation, properties.backdrop[0],
  2695. properties.backdrop[1], properties.backdrop[2], 1);
  2696. } else {
  2697. gl.uniform4f(cache.resolutionLocation, 0, 0, 0, 0);
  2698. }
  2699. gl.uniform1i(cache.subtypeLocation,
  2700. properties.subtype === 'Luminosity' ? 1 : 0);
  2701. // Create a textures
  2702. var texture = createTexture(gl, layer, gl.TEXTURE0);
  2703. var maskTexture = createTexture(gl, mask, gl.TEXTURE1);
  2704. // Create a buffer and put a single clipspace rectangle in
  2705. // it (2 triangles)
  2706. var buffer = gl.createBuffer();
  2707. gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
  2708. gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
  2709. 0, 0,
  2710. width, 0,
  2711. 0, height,
  2712. 0, height,
  2713. width, 0,
  2714. width, height]), gl.STATIC_DRAW);
  2715. gl.enableVertexAttribArray(cache.positionLocation);
  2716. gl.vertexAttribPointer(cache.positionLocation, 2, gl.FLOAT, false, 0, 0);
  2717. // draw
  2718. gl.clearColor(0, 0, 0, 0);
  2719. gl.enable(gl.BLEND);
  2720. gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
  2721. gl.clear(gl.COLOR_BUFFER_BIT);
  2722. gl.drawArrays(gl.TRIANGLES, 0, 6);
  2723. gl.flush();
  2724. gl.deleteTexture(texture);
  2725. gl.deleteTexture(maskTexture);
  2726. gl.deleteBuffer(buffer);
  2727. return canvas;
  2728. }
  2729. var figuresVertexShaderCode = '\
  2730. attribute vec2 a_position; \
  2731. attribute vec3 a_color; \
  2732. \
  2733. uniform vec2 u_resolution; \
  2734. uniform vec2 u_scale; \
  2735. uniform vec2 u_offset; \
  2736. \
  2737. varying vec4 v_color; \
  2738. \
  2739. void main() { \
  2740. vec2 position = (a_position + u_offset) * u_scale; \
  2741. vec2 clipSpace = (position / u_resolution) * 2.0 - 1.0; \
  2742. gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1); \
  2743. \
  2744. v_color = vec4(a_color / 255.0, 1.0); \
  2745. } ';
  2746. var figuresFragmentShaderCode = '\
  2747. precision mediump float; \
  2748. \
  2749. varying vec4 v_color; \
  2750. \
  2751. void main() { \
  2752. gl_FragColor = v_color; \
  2753. } ';
  2754. var figuresCache = null;
  2755. function initFiguresGL() {
  2756. var canvas, gl;
  2757. generateGL();
  2758. canvas = currentCanvas;
  2759. currentCanvas = null;
  2760. gl = currentGL;
  2761. currentGL = null;
  2762. // setup a GLSL program
  2763. var vertexShader = createVertexShader(gl, figuresVertexShaderCode);
  2764. var fragmentShader = createFragmentShader(gl, figuresFragmentShaderCode);
  2765. var program = createProgram(gl, [vertexShader, fragmentShader]);
  2766. gl.useProgram(program);
  2767. var cache = {};
  2768. cache.gl = gl;
  2769. cache.canvas = canvas;
  2770. cache.resolutionLocation = gl.getUniformLocation(program, 'u_resolution');
  2771. cache.scaleLocation = gl.getUniformLocation(program, 'u_scale');
  2772. cache.offsetLocation = gl.getUniformLocation(program, 'u_offset');
  2773. cache.positionLocation = gl.getAttribLocation(program, 'a_position');
  2774. cache.colorLocation = gl.getAttribLocation(program, 'a_color');
  2775. figuresCache = cache;
  2776. }
  2777. function drawFigures(width, height, backgroundColor, figures, context) {
  2778. if (!figuresCache) {
  2779. initFiguresGL();
  2780. }
  2781. var cache = figuresCache, canvas = cache.canvas, gl = cache.gl;
  2782. canvas.width = width;
  2783. canvas.height = height;
  2784. gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
  2785. gl.uniform2f(cache.resolutionLocation, width, height);
  2786. // count triangle points
  2787. var count = 0;
  2788. var i, ii, rows;
  2789. for (i = 0, ii = figures.length; i < ii; i++) {
  2790. switch (figures[i].type) {
  2791. case 'lattice':
  2792. rows = (figures[i].coords.length / figures[i].verticesPerRow) | 0;
  2793. count += (rows - 1) * (figures[i].verticesPerRow - 1) * 6;
  2794. break;
  2795. case 'triangles':
  2796. count += figures[i].coords.length;
  2797. break;
  2798. }
  2799. }
  2800. // transfer data
  2801. var coords = new Float32Array(count * 2);
  2802. var colors = new Uint8Array(count * 3);
  2803. var coordsMap = context.coords, colorsMap = context.colors;
  2804. var pIndex = 0, cIndex = 0;
  2805. for (i = 0, ii = figures.length; i < ii; i++) {
  2806. var figure = figures[i], ps = figure.coords, cs = figure.colors;
  2807. switch (figure.type) {
  2808. case 'lattice':
  2809. var cols = figure.verticesPerRow;
  2810. rows = (ps.length / cols) | 0;
  2811. for (var row = 1; row < rows; row++) {
  2812. var offset = row * cols + 1;
  2813. for (var col = 1; col < cols; col++, offset++) {
  2814. coords[pIndex] = coordsMap[ps[offset - cols - 1]];
  2815. coords[pIndex + 1] = coordsMap[ps[offset - cols - 1] + 1];
  2816. coords[pIndex + 2] = coordsMap[ps[offset - cols]];
  2817. coords[pIndex + 3] = coordsMap[ps[offset - cols] + 1];
  2818. coords[pIndex + 4] = coordsMap[ps[offset - 1]];
  2819. coords[pIndex + 5] = coordsMap[ps[offset - 1] + 1];
  2820. colors[cIndex] = colorsMap[cs[offset - cols - 1]];
  2821. colors[cIndex + 1] = colorsMap[cs[offset - cols - 1] + 1];
  2822. colors[cIndex + 2] = colorsMap[cs[offset - cols - 1] + 2];
  2823. colors[cIndex + 3] = colorsMap[cs[offset - cols]];
  2824. colors[cIndex + 4] = colorsMap[cs[offset - cols] + 1];
  2825. colors[cIndex + 5] = colorsMap[cs[offset - cols] + 2];
  2826. colors[cIndex + 6] = colorsMap[cs[offset - 1]];
  2827. colors[cIndex + 7] = colorsMap[cs[offset - 1] + 1];
  2828. colors[cIndex + 8] = colorsMap[cs[offset - 1] + 2];
  2829. coords[pIndex + 6] = coords[pIndex + 2];
  2830. coords[pIndex + 7] = coords[pIndex + 3];
  2831. coords[pIndex + 8] = coords[pIndex + 4];
  2832. coords[pIndex + 9] = coords[pIndex + 5];
  2833. coords[pIndex + 10] = coordsMap[ps[offset]];
  2834. coords[pIndex + 11] = coordsMap[ps[offset] + 1];
  2835. colors[cIndex + 9] = colors[cIndex + 3];
  2836. colors[cIndex + 10] = colors[cIndex + 4];
  2837. colors[cIndex + 11] = colors[cIndex + 5];
  2838. colors[cIndex + 12] = colors[cIndex + 6];
  2839. colors[cIndex + 13] = colors[cIndex + 7];
  2840. colors[cIndex + 14] = colors[cIndex + 8];
  2841. colors[cIndex + 15] = colorsMap[cs[offset]];
  2842. colors[cIndex + 16] = colorsMap[cs[offset] + 1];
  2843. colors[cIndex + 17] = colorsMap[cs[offset] + 2];
  2844. pIndex += 12;
  2845. cIndex += 18;
  2846. }
  2847. }
  2848. break;
  2849. case 'triangles':
  2850. for (var j = 0, jj = ps.length; j < jj; j++) {
  2851. coords[pIndex] = coordsMap[ps[j]];
  2852. coords[pIndex + 1] = coordsMap[ps[j] + 1];
  2853. colors[cIndex] = colorsMap[cs[j]];
  2854. colors[cIndex + 1] = colorsMap[cs[j] + 1];
  2855. colors[cIndex + 2] = colorsMap[cs[j] + 2];
  2856. pIndex += 2;
  2857. cIndex += 3;
  2858. }
  2859. break;
  2860. }
  2861. }
  2862. // draw
  2863. if (backgroundColor) {
  2864. gl.clearColor(backgroundColor[0] / 255, backgroundColor[1] / 255,
  2865. backgroundColor[2] / 255, 1.0);
  2866. } else {
  2867. gl.clearColor(0, 0, 0, 0);
  2868. }
  2869. gl.clear(gl.COLOR_BUFFER_BIT);
  2870. var coordsBuffer = gl.createBuffer();
  2871. gl.bindBuffer(gl.ARRAY_BUFFER, coordsBuffer);
  2872. gl.bufferData(gl.ARRAY_BUFFER, coords, gl.STATIC_DRAW);
  2873. gl.enableVertexAttribArray(cache.positionLocation);
  2874. gl.vertexAttribPointer(cache.positionLocation, 2, gl.FLOAT, false, 0, 0);
  2875. var colorsBuffer = gl.createBuffer();
  2876. gl.bindBuffer(gl.ARRAY_BUFFER, colorsBuffer);
  2877. gl.bufferData(gl.ARRAY_BUFFER, colors, gl.STATIC_DRAW);
  2878. gl.enableVertexAttribArray(cache.colorLocation);
  2879. gl.vertexAttribPointer(cache.colorLocation, 3, gl.UNSIGNED_BYTE, false,
  2880. 0, 0);
  2881. gl.uniform2f(cache.scaleLocation, context.scaleX, context.scaleY);
  2882. gl.uniform2f(cache.offsetLocation, context.offsetX, context.offsetY);
  2883. gl.drawArrays(gl.TRIANGLES, 0, count);
  2884. gl.flush();
  2885. gl.deleteBuffer(coordsBuffer);
  2886. gl.deleteBuffer(colorsBuffer);
  2887. return canvas;
  2888. }
  2889. function cleanup() {
  2890. if (smaskCache && smaskCache.canvas) {
  2891. smaskCache.canvas.width = 0;
  2892. smaskCache.canvas.height = 0;
  2893. }
  2894. if (figuresCache && figuresCache.canvas) {
  2895. figuresCache.canvas.width = 0;
  2896. figuresCache.canvas.height = 0;
  2897. }
  2898. smaskCache = null;
  2899. figuresCache = null;
  2900. }
  2901. return {
  2902. get isEnabled() {
  2903. if (PDFJS.disableWebGL) {
  2904. return false;
  2905. }
  2906. var enabled = false;
  2907. try {
  2908. generateGL();
  2909. enabled = !!currentGL;
  2910. } catch (e) { }
  2911. return shadow(this, 'isEnabled', enabled);
  2912. },
  2913. composeSMask: composeSMask,
  2914. drawFigures: drawFigures,
  2915. clear: cleanup
  2916. };
  2917. })();
  2918. exports.WebGLUtils = WebGLUtils;
  2919. }));
  2920. (function (root, factory) {
  2921. {
  2922. factory((root.pdfjsDisplayPatternHelper = {}), root.pdfjsSharedUtil,
  2923. root.pdfjsDisplayWebGL);
  2924. }
  2925. }(this, function (exports, sharedUtil, displayWebGL) {
  2926. var Util = sharedUtil.Util;
  2927. var info = sharedUtil.info;
  2928. var isArray = sharedUtil.isArray;
  2929. var error = sharedUtil.error;
  2930. var WebGLUtils = displayWebGL.WebGLUtils;
  2931. var ShadingIRs = {};
  2932. ShadingIRs.RadialAxial = {
  2933. fromIR: function RadialAxial_fromIR(raw) {
  2934. var type = raw[1];
  2935. var colorStops = raw[2];
  2936. var p0 = raw[3];
  2937. var p1 = raw[4];
  2938. var r0 = raw[5];
  2939. var r1 = raw[6];
  2940. return {
  2941. type: 'Pattern',
  2942. getPattern: function RadialAxial_getPattern(ctx) {
  2943. var grad;
  2944. if (type === 'axial') {
  2945. grad = ctx.createLinearGradient(p0[0], p0[1], p1[0], p1[1]);
  2946. } else if (type === 'radial') {
  2947. grad = ctx.createRadialGradient(p0[0], p0[1], r0, p1[0], p1[1], r1);
  2948. }
  2949. for (var i = 0, ii = colorStops.length; i < ii; ++i) {
  2950. var c = colorStops[i];
  2951. grad.addColorStop(c[0], c[1]);
  2952. }
  2953. return grad;
  2954. }
  2955. };
  2956. }
  2957. };
  2958. var createMeshCanvas = (function createMeshCanvasClosure() {
  2959. function drawTriangle(data, context, p1, p2, p3, c1, c2, c3) {
  2960. // Very basic Gouraud-shaded triangle rasterization algorithm.
  2961. var coords = context.coords, colors = context.colors;
  2962. var bytes = data.data, rowSize = data.width * 4;
  2963. var tmp;
  2964. if (coords[p1 + 1] > coords[p2 + 1]) {
  2965. tmp = p1; p1 = p2; p2 = tmp; tmp = c1; c1 = c2; c2 = tmp;
  2966. }
  2967. if (coords[p2 + 1] > coords[p3 + 1]) {
  2968. tmp = p2; p2 = p3; p3 = tmp; tmp = c2; c2 = c3; c3 = tmp;
  2969. }
  2970. if (coords[p1 + 1] > coords[p2 + 1]) {
  2971. tmp = p1; p1 = p2; p2 = tmp; tmp = c1; c1 = c2; c2 = tmp;
  2972. }
  2973. var x1 = (coords[p1] + context.offsetX) * context.scaleX;
  2974. var y1 = (coords[p1 + 1] + context.offsetY) * context.scaleY;
  2975. var x2 = (coords[p2] + context.offsetX) * context.scaleX;
  2976. var y2 = (coords[p2 + 1] + context.offsetY) * context.scaleY;
  2977. var x3 = (coords[p3] + context.offsetX) * context.scaleX;
  2978. var y3 = (coords[p3 + 1] + context.offsetY) * context.scaleY;
  2979. if (y1 >= y3) {
  2980. return;
  2981. }
  2982. var c1r = colors[c1], c1g = colors[c1 + 1], c1b = colors[c1 + 2];
  2983. var c2r = colors[c2], c2g = colors[c2 + 1], c2b = colors[c2 + 2];
  2984. var c3r = colors[c3], c3g = colors[c3 + 1], c3b = colors[c3 + 2];
  2985. var minY = Math.round(y1), maxY = Math.round(y3);
  2986. var xa, car, cag, cab;
  2987. var xb, cbr, cbg, cbb;
  2988. var k;
  2989. for (var y = minY; y <= maxY; y++) {
  2990. if (y < y2) {
  2991. k = y < y1 ? 0 : y1 === y2 ? 1 : (y1 - y) / (y1 - y2);
  2992. xa = x1 - (x1 - x2) * k;
  2993. car = c1r - (c1r - c2r) * k;
  2994. cag = c1g - (c1g - c2g) * k;
  2995. cab = c1b - (c1b - c2b) * k;
  2996. } else {
  2997. k = y > y3 ? 1 : y2 === y3 ? 0 : (y2 - y) / (y2 - y3);
  2998. xa = x2 - (x2 - x3) * k;
  2999. car = c2r - (c2r - c3r) * k;
  3000. cag = c2g - (c2g - c3g) * k;
  3001. cab = c2b - (c2b - c3b) * k;
  3002. }
  3003. k = y < y1 ? 0 : y > y3 ? 1 : (y1 - y) / (y1 - y3);
  3004. xb = x1 - (x1 - x3) * k;
  3005. cbr = c1r - (c1r - c3r) * k;
  3006. cbg = c1g - (c1g - c3g) * k;
  3007. cbb = c1b - (c1b - c3b) * k;
  3008. var x1_ = Math.round(Math.min(xa, xb));
  3009. var x2_ = Math.round(Math.max(xa, xb));
  3010. var j = rowSize * y + x1_ * 4;
  3011. for (var x = x1_; x <= x2_; x++) {
  3012. k = (xa - x) / (xa - xb);
  3013. k = k < 0 ? 0 : k > 1 ? 1 : k;
  3014. bytes[j++] = (car - (car - cbr) * k) | 0;
  3015. bytes[j++] = (cag - (cag - cbg) * k) | 0;
  3016. bytes[j++] = (cab - (cab - cbb) * k) | 0;
  3017. bytes[j++] = 255;
  3018. }
  3019. }
  3020. }
  3021. function drawFigure(data, figure, context) {
  3022. var ps = figure.coords;
  3023. var cs = figure.colors;
  3024. var i, ii;
  3025. switch (figure.type) {
  3026. case 'lattice':
  3027. var verticesPerRow = figure.verticesPerRow;
  3028. var rows = Math.floor(ps.length / verticesPerRow) - 1;
  3029. var cols = verticesPerRow - 1;
  3030. for (i = 0; i < rows; i++) {
  3031. var q = i * verticesPerRow;
  3032. for (var j = 0; j < cols; j++, q++) {
  3033. drawTriangle(data, context,
  3034. ps[q], ps[q + 1], ps[q + verticesPerRow],
  3035. cs[q], cs[q + 1], cs[q + verticesPerRow]);
  3036. drawTriangle(data, context,
  3037. ps[q + verticesPerRow + 1], ps[q + 1], ps[q + verticesPerRow],
  3038. cs[q + verticesPerRow + 1], cs[q + 1], cs[q + verticesPerRow]);
  3039. }
  3040. }
  3041. break;
  3042. case 'triangles':
  3043. for (i = 0, ii = ps.length; i < ii; i += 3) {
  3044. drawTriangle(data, context,
  3045. ps[i], ps[i + 1], ps[i + 2],
  3046. cs[i], cs[i + 1], cs[i + 2]);
  3047. }
  3048. break;
  3049. default:
  3050. error('illigal figure');
  3051. break;
  3052. }
  3053. }
  3054. function createMeshCanvas(bounds, combinesScale, coords, colors, figures,
  3055. backgroundColor, cachedCanvases) {
  3056. // we will increase scale on some weird factor to let antialiasing take
  3057. // care of "rough" edges
  3058. var EXPECTED_SCALE = 1.1;
  3059. // MAX_PATTERN_SIZE is used to avoid OOM situation.
  3060. var MAX_PATTERN_SIZE = 3000; // 10in @ 300dpi shall be enough
  3061. var offsetX = Math.floor(bounds[0]);
  3062. var offsetY = Math.floor(bounds[1]);
  3063. var boundsWidth = Math.ceil(bounds[2]) - offsetX;
  3064. var boundsHeight = Math.ceil(bounds[3]) - offsetY;
  3065. var width = Math.min(Math.ceil(Math.abs(boundsWidth * combinesScale[0] *
  3066. EXPECTED_SCALE)), MAX_PATTERN_SIZE);
  3067. var height = Math.min(Math.ceil(Math.abs(boundsHeight * combinesScale[1] *
  3068. EXPECTED_SCALE)), MAX_PATTERN_SIZE);
  3069. var scaleX = boundsWidth / width;
  3070. var scaleY = boundsHeight / height;
  3071. var context = {
  3072. coords: coords,
  3073. colors: colors,
  3074. offsetX: -offsetX,
  3075. offsetY: -offsetY,
  3076. scaleX: 1 / scaleX,
  3077. scaleY: 1 / scaleY
  3078. };
  3079. var canvas, tmpCanvas, i, ii;
  3080. if (WebGLUtils.isEnabled) {
  3081. canvas = WebGLUtils.drawFigures(width, height, backgroundColor,
  3082. figures, context);
  3083. // https://bugzilla.mozilla.org/show_bug.cgi?id=972126
  3084. tmpCanvas = cachedCanvases.getCanvas('mesh', width, height, false);
  3085. tmpCanvas.context.drawImage(canvas, 0, 0);
  3086. canvas = tmpCanvas.canvas;
  3087. } else {
  3088. tmpCanvas = cachedCanvases.getCanvas('mesh', width, height, false);
  3089. var tmpCtx = tmpCanvas.context;
  3090. var data = tmpCtx.createImageData(width, height);
  3091. if (backgroundColor) {
  3092. var bytes = data.data;
  3093. for (i = 0, ii = bytes.length; i < ii; i += 4) {
  3094. bytes[i] = backgroundColor[0];
  3095. bytes[i + 1] = backgroundColor[1];
  3096. bytes[i + 2] = backgroundColor[2];
  3097. bytes[i + 3] = 255;
  3098. }
  3099. }
  3100. for (i = 0; i < figures.length; i++) {
  3101. drawFigure(data, figures[i], context);
  3102. }
  3103. tmpCtx.putImageData(data, 0, 0);
  3104. canvas = tmpCanvas.canvas;
  3105. }
  3106. return {canvas: canvas, offsetX: offsetX, offsetY: offsetY,
  3107. scaleX: scaleX, scaleY: scaleY};
  3108. }
  3109. return createMeshCanvas;
  3110. })();
  3111. ShadingIRs.Mesh = {
  3112. fromIR: function Mesh_fromIR(raw) {
  3113. //var type = raw[1];
  3114. var coords = raw[2];
  3115. var colors = raw[3];
  3116. var figures = raw[4];
  3117. var bounds = raw[5];
  3118. var matrix = raw[6];
  3119. //var bbox = raw[7];
  3120. var background = raw[8];
  3121. return {
  3122. type: 'Pattern',
  3123. getPattern: function Mesh_getPattern(ctx, owner, shadingFill) {
  3124. var scale;
  3125. if (shadingFill) {
  3126. scale = Util.singularValueDecompose2dScale(ctx.mozCurrentTransform);
  3127. } else {
  3128. // Obtain scale from matrix and current transformation matrix.
  3129. scale = Util.singularValueDecompose2dScale(owner.baseTransform);
  3130. if (matrix) {
  3131. var matrixScale = Util.singularValueDecompose2dScale(matrix);
  3132. scale = [scale[0] * matrixScale[0],
  3133. scale[1] * matrixScale[1]];
  3134. }
  3135. }
  3136. // Rasterizing on the main thread since sending/queue large canvases
  3137. // might cause OOM.
  3138. var temporaryPatternCanvas = createMeshCanvas(bounds, scale, coords,
  3139. colors, figures, shadingFill ? null : background,
  3140. owner.cachedCanvases);
  3141. if (!shadingFill) {
  3142. ctx.setTransform.apply(ctx, owner.baseTransform);
  3143. if (matrix) {
  3144. ctx.transform.apply(ctx, matrix);
  3145. }
  3146. }
  3147. ctx.translate(temporaryPatternCanvas.offsetX,
  3148. temporaryPatternCanvas.offsetY);
  3149. ctx.scale(temporaryPatternCanvas.scaleX,
  3150. temporaryPatternCanvas.scaleY);
  3151. return ctx.createPattern(temporaryPatternCanvas.canvas, 'no-repeat');
  3152. }
  3153. };
  3154. }
  3155. };
  3156. ShadingIRs.Dummy = {
  3157. fromIR: function Dummy_fromIR() {
  3158. return {
  3159. type: 'Pattern',
  3160. getPattern: function Dummy_fromIR_getPattern() {
  3161. return 'hotpink';
  3162. }
  3163. };
  3164. }
  3165. };
  3166. function getShadingPatternFromIR(raw) {
  3167. var shadingIR = ShadingIRs[raw[0]];
  3168. if (!shadingIR) {
  3169. error('Unknown IR type: ' + raw[0]);
  3170. }
  3171. return shadingIR.fromIR(raw);
  3172. }
  3173. var TilingPattern = (function TilingPatternClosure() {
  3174. var PaintType = {
  3175. COLORED: 1,
  3176. UNCOLORED: 2
  3177. };
  3178. var MAX_PATTERN_SIZE = 3000; // 10in @ 300dpi shall be enough
  3179. function TilingPattern(IR, color, ctx, canvasGraphicsFactory, baseTransform) {
  3180. this.operatorList = IR[2];
  3181. this.matrix = IR[3] || [1, 0, 0, 1, 0, 0];
  3182. this.bbox = IR[4];
  3183. this.xstep = IR[5];
  3184. this.ystep = IR[6];
  3185. this.paintType = IR[7];
  3186. this.tilingType = IR[8];
  3187. this.color = color;
  3188. this.canvasGraphicsFactory = canvasGraphicsFactory;
  3189. this.baseTransform = baseTransform;
  3190. this.type = 'Pattern';
  3191. this.ctx = ctx;
  3192. }
  3193. TilingPattern.prototype = {
  3194. createPatternCanvas: function TilinPattern_createPatternCanvas(owner) {
  3195. var operatorList = this.operatorList;
  3196. var bbox = this.bbox;
  3197. var xstep = this.xstep;
  3198. var ystep = this.ystep;
  3199. var paintType = this.paintType;
  3200. var tilingType = this.tilingType;
  3201. var color = this.color;
  3202. var canvasGraphicsFactory = this.canvasGraphicsFactory;
  3203. info('TilingType: ' + tilingType);
  3204. var x0 = bbox[0], y0 = bbox[1], x1 = bbox[2], y1 = bbox[3];
  3205. var topLeft = [x0, y0];
  3206. // we want the canvas to be as large as the step size
  3207. var botRight = [x0 + xstep, y0 + ystep];
  3208. var width = botRight[0] - topLeft[0];
  3209. var height = botRight[1] - topLeft[1];
  3210. // Obtain scale from matrix and current transformation matrix.
  3211. var matrixScale = Util.singularValueDecompose2dScale(this.matrix);
  3212. var curMatrixScale = Util.singularValueDecompose2dScale(
  3213. this.baseTransform);
  3214. var combinedScale = [matrixScale[0] * curMatrixScale[0],
  3215. matrixScale[1] * curMatrixScale[1]];
  3216. // MAX_PATTERN_SIZE is used to avoid OOM situation.
  3217. // Use width and height values that are as close as possible to the end
  3218. // result when the pattern is used. Too low value makes the pattern look
  3219. // blurry. Too large value makes it look too crispy.
  3220. width = Math.min(Math.ceil(Math.abs(width * combinedScale[0])),
  3221. MAX_PATTERN_SIZE);
  3222. height = Math.min(Math.ceil(Math.abs(height * combinedScale[1])),
  3223. MAX_PATTERN_SIZE);
  3224. var tmpCanvas = owner.cachedCanvases.getCanvas('pattern',
  3225. width, height, true);
  3226. var tmpCtx = tmpCanvas.context;
  3227. var graphics = canvasGraphicsFactory.createCanvasGraphics(tmpCtx);
  3228. graphics.groupLevel = owner.groupLevel;
  3229. this.setFillAndStrokeStyleToContext(tmpCtx, paintType, color);
  3230. this.setScale(width, height, xstep, ystep);
  3231. this.transformToScale(graphics);
  3232. // transform coordinates to pattern space
  3233. var tmpTranslate = [1, 0, 0, 1, -topLeft[0], -topLeft[1]];
  3234. graphics.transform.apply(graphics, tmpTranslate);
  3235. this.clipBbox(graphics, bbox, x0, y0, x1, y1);
  3236. graphics.executeOperatorList(operatorList);
  3237. return tmpCanvas.canvas;
  3238. },
  3239. setScale: function TilingPattern_setScale(width, height, xstep, ystep) {
  3240. this.scale = [width / xstep, height / ystep];
  3241. },
  3242. transformToScale: function TilingPattern_transformToScale(graphics) {
  3243. var scale = this.scale;
  3244. var tmpScale = [scale[0], 0, 0, scale[1], 0, 0];
  3245. graphics.transform.apply(graphics, tmpScale);
  3246. },
  3247. scaleToContext: function TilingPattern_scaleToContext() {
  3248. var scale = this.scale;
  3249. this.ctx.scale(1 / scale[0], 1 / scale[1]);
  3250. },
  3251. clipBbox: function clipBbox(graphics, bbox, x0, y0, x1, y1) {
  3252. if (bbox && isArray(bbox) && bbox.length === 4) {
  3253. var bboxWidth = x1 - x0;
  3254. var bboxHeight = y1 - y0;
  3255. graphics.ctx.rect(x0, y0, bboxWidth, bboxHeight);
  3256. graphics.clip();
  3257. graphics.endPath();
  3258. }
  3259. },
  3260. setFillAndStrokeStyleToContext:
  3261. function setFillAndStrokeStyleToContext(context, paintType, color) {
  3262. switch (paintType) {
  3263. case PaintType.COLORED:
  3264. var ctx = this.ctx;
  3265. context.fillStyle = ctx.fillStyle;
  3266. context.strokeStyle = ctx.strokeStyle;
  3267. break;
  3268. case PaintType.UNCOLORED:
  3269. var cssColor = Util.makeCssRgb(color[0], color[1], color[2]);
  3270. context.fillStyle = cssColor;
  3271. context.strokeStyle = cssColor;
  3272. break;
  3273. default:
  3274. error('Unsupported paint type: ' + paintType);
  3275. }
  3276. },
  3277. getPattern: function TilingPattern_getPattern(ctx, owner) {
  3278. var temporaryPatternCanvas = this.createPatternCanvas(owner);
  3279. ctx = this.ctx;
  3280. ctx.setTransform.apply(ctx, this.baseTransform);
  3281. ctx.transform.apply(ctx, this.matrix);
  3282. this.scaleToContext();
  3283. return ctx.createPattern(temporaryPatternCanvas, 'repeat');
  3284. }
  3285. };
  3286. return TilingPattern;
  3287. })();
  3288. exports.getShadingPatternFromIR = getShadingPatternFromIR;
  3289. exports.TilingPattern = TilingPattern;
  3290. }));
  3291. (function (root, factory) {
  3292. {
  3293. factory((root.pdfjsDisplayCanvas = {}), root.pdfjsSharedUtil,
  3294. root.pdfjsDisplayPatternHelper, root.pdfjsDisplayWebGL);
  3295. }
  3296. }(this, function (exports, sharedUtil, displayPatternHelper, displayWebGL) {
  3297. var FONT_IDENTITY_MATRIX = sharedUtil.FONT_IDENTITY_MATRIX;
  3298. var IDENTITY_MATRIX = sharedUtil.IDENTITY_MATRIX;
  3299. var ImageKind = sharedUtil.ImageKind;
  3300. var OPS = sharedUtil.OPS;
  3301. var TextRenderingMode = sharedUtil.TextRenderingMode;
  3302. var Uint32ArrayView = sharedUtil.Uint32ArrayView;
  3303. var Util = sharedUtil.Util;
  3304. var assert = sharedUtil.assert;
  3305. var info = sharedUtil.info;
  3306. var isNum = sharedUtil.isNum;
  3307. var isArray = sharedUtil.isArray;
  3308. var error = sharedUtil.error;
  3309. var shadow = sharedUtil.shadow;
  3310. var warn = sharedUtil.warn;
  3311. var TilingPattern = displayPatternHelper.TilingPattern;
  3312. var getShadingPatternFromIR = displayPatternHelper.getShadingPatternFromIR;
  3313. var WebGLUtils = displayWebGL.WebGLUtils;
  3314. // <canvas> contexts store most of the state we need natively.
  3315. // However, PDF needs a bit more state, which we store here.
  3316. // Minimal font size that would be used during canvas fillText operations.
  3317. var MIN_FONT_SIZE = 16;
  3318. // Maximum font size that would be used during canvas fillText operations.
  3319. var MAX_FONT_SIZE = 100;
  3320. var MAX_GROUP_SIZE = 4096;
  3321. // Heuristic value used when enforcing minimum line widths.
  3322. var MIN_WIDTH_FACTOR = 0.65;
  3323. var COMPILE_TYPE3_GLYPHS = true;
  3324. var MAX_SIZE_TO_COMPILE = 1000;
  3325. var FULL_CHUNK_HEIGHT = 16;
  3326. function createScratchCanvas(width, height) {
  3327. var canvas = document.createElement('canvas');
  3328. canvas.width = width;
  3329. canvas.height = height;
  3330. return canvas;
  3331. }
  3332. function addContextCurrentTransform(ctx) {
  3333. // If the context doesn't expose a `mozCurrentTransform`, add a JS based one.
  3334. if (!ctx.mozCurrentTransform) {
  3335. ctx._originalSave = ctx.save;
  3336. ctx._originalRestore = ctx.restore;
  3337. ctx._originalRotate = ctx.rotate;
  3338. ctx._originalScale = ctx.scale;
  3339. ctx._originalTranslate = ctx.translate;
  3340. ctx._originalTransform = ctx.transform;
  3341. ctx._originalSetTransform = ctx.setTransform;
  3342. ctx._transformMatrix = ctx._transformMatrix || [1, 0, 0, 1, 0, 0];
  3343. ctx._transformStack = [];
  3344. Object.defineProperty(ctx, 'mozCurrentTransform', {
  3345. get: function getCurrentTransform() {
  3346. return this._transformMatrix;
  3347. }
  3348. });
  3349. Object.defineProperty(ctx, 'mozCurrentTransformInverse', {
  3350. get: function getCurrentTransformInverse() {
  3351. // Calculation done using WolframAlpha:
  3352. // http://www.wolframalpha.com/input/?
  3353. // i=Inverse+{{a%2C+c%2C+e}%2C+{b%2C+d%2C+f}%2C+{0%2C+0%2C+1}}
  3354. var m = this._transformMatrix;
  3355. var a = m[0], b = m[1], c = m[2], d = m[3], e = m[4], f = m[5];
  3356. var ad_bc = a * d - b * c;
  3357. var bc_ad = b * c - a * d;
  3358. return [
  3359. d / ad_bc,
  3360. b / bc_ad,
  3361. c / bc_ad,
  3362. a / ad_bc,
  3363. (d * e - c * f) / bc_ad,
  3364. (b * e - a * f) / ad_bc
  3365. ];
  3366. }
  3367. });
  3368. ctx.save = function ctxSave() {
  3369. var old = this._transformMatrix;
  3370. this._transformStack.push(old);
  3371. this._transformMatrix = old.slice(0, 6);
  3372. this._originalSave();
  3373. };
  3374. ctx.restore = function ctxRestore() {
  3375. var prev = this._transformStack.pop();
  3376. if (prev) {
  3377. this._transformMatrix = prev;
  3378. this._originalRestore();
  3379. }
  3380. };
  3381. ctx.translate = function ctxTranslate(x, y) {
  3382. var m = this._transformMatrix;
  3383. m[4] = m[0] * x + m[2] * y + m[4];
  3384. m[5] = m[1] * x + m[3] * y + m[5];
  3385. this._originalTranslate(x, y);
  3386. };
  3387. ctx.scale = function ctxScale(x, y) {
  3388. var m = this._transformMatrix;
  3389. m[0] = m[0] * x;
  3390. m[1] = m[1] * x;
  3391. m[2] = m[2] * y;
  3392. m[3] = m[3] * y;
  3393. this._originalScale(x, y);
  3394. };
  3395. ctx.transform = function ctxTransform(a, b, c, d, e, f) {
  3396. var m = this._transformMatrix;
  3397. this._transformMatrix = [
  3398. m[0] * a + m[2] * b,
  3399. m[1] * a + m[3] * b,
  3400. m[0] * c + m[2] * d,
  3401. m[1] * c + m[3] * d,
  3402. m[0] * e + m[2] * f + m[4],
  3403. m[1] * e + m[3] * f + m[5]
  3404. ];
  3405. ctx._originalTransform(a, b, c, d, e, f);
  3406. };
  3407. ctx.setTransform = function ctxSetTransform(a, b, c, d, e, f) {
  3408. this._transformMatrix = [a, b, c, d, e, f];
  3409. ctx._originalSetTransform(a, b, c, d, e, f);
  3410. };
  3411. ctx.rotate = function ctxRotate(angle) {
  3412. var cosValue = Math.cos(angle);
  3413. var sinValue = Math.sin(angle);
  3414. var m = this._transformMatrix;
  3415. this._transformMatrix = [
  3416. m[0] * cosValue + m[2] * sinValue,
  3417. m[1] * cosValue + m[3] * sinValue,
  3418. m[0] * (-sinValue) + m[2] * cosValue,
  3419. m[1] * (-sinValue) + m[3] * cosValue,
  3420. m[4],
  3421. m[5]
  3422. ];
  3423. this._originalRotate(angle);
  3424. };
  3425. }
  3426. }
  3427. var CachedCanvases = (function CachedCanvasesClosure() {
  3428. function CachedCanvases() {
  3429. this.cache = Object.create(null);
  3430. }
  3431. CachedCanvases.prototype = {
  3432. getCanvas: function CachedCanvases_getCanvas(id, width, height,
  3433. trackTransform) {
  3434. var canvasEntry;
  3435. if (this.cache[id] !== undefined) {
  3436. canvasEntry = this.cache[id];
  3437. canvasEntry.canvas.width = width;
  3438. canvasEntry.canvas.height = height;
  3439. // reset canvas transform for emulated mozCurrentTransform, if needed
  3440. canvasEntry.context.setTransform(1, 0, 0, 1, 0, 0);
  3441. } else {
  3442. var canvas = createScratchCanvas(width, height);
  3443. var ctx = canvas.getContext('2d');
  3444. if (trackTransform) {
  3445. addContextCurrentTransform(ctx);
  3446. }
  3447. this.cache[id] = canvasEntry = {canvas: canvas, context: ctx};
  3448. }
  3449. return canvasEntry;
  3450. },
  3451. clear: function () {
  3452. for (var id in this.cache) {
  3453. var canvasEntry = this.cache[id];
  3454. // Zeroing the width and height causes Firefox to release graphics
  3455. // resources immediately, which can greatly reduce memory consumption.
  3456. canvasEntry.canvas.width = 0;
  3457. canvasEntry.canvas.height = 0;
  3458. delete this.cache[id];
  3459. }
  3460. }
  3461. };
  3462. return CachedCanvases;
  3463. })();
  3464. function compileType3Glyph(imgData) {
  3465. var POINT_TO_PROCESS_LIMIT = 1000;
  3466. var width = imgData.width, height = imgData.height;
  3467. var i, j, j0, width1 = width + 1;
  3468. var points = new Uint8Array(width1 * (height + 1));
  3469. var POINT_TYPES =
  3470. new Uint8Array([0, 2, 4, 0, 1, 0, 5, 4, 8, 10, 0, 8, 0, 2, 1, 0]);
  3471. // decodes bit-packed mask data
  3472. var lineSize = (width + 7) & ~7, data0 = imgData.data;
  3473. var data = new Uint8Array(lineSize * height), pos = 0, ii;
  3474. for (i = 0, ii = data0.length; i < ii; i++) {
  3475. var mask = 128, elem = data0[i];
  3476. while (mask > 0) {
  3477. data[pos++] = (elem & mask) ? 0 : 255;
  3478. mask >>= 1;
  3479. }
  3480. }
  3481. // finding iteresting points: every point is located between mask pixels,
  3482. // so there will be points of the (width + 1)x(height + 1) grid. Every point
  3483. // will have flags assigned based on neighboring mask pixels:
  3484. // 4 | 8
  3485. // --P--
  3486. // 2 | 1
  3487. // We are interested only in points with the flags:
  3488. // - outside corners: 1, 2, 4, 8;
  3489. // - inside corners: 7, 11, 13, 14;
  3490. // - and, intersections: 5, 10.
  3491. var count = 0;
  3492. pos = 0;
  3493. if (data[pos] !== 0) {
  3494. points[0] = 1;
  3495. ++count;
  3496. }
  3497. for (j = 1; j < width; j++) {
  3498. if (data[pos] !== data[pos + 1]) {
  3499. points[j] = data[pos] ? 2 : 1;
  3500. ++count;
  3501. }
  3502. pos++;
  3503. }
  3504. if (data[pos] !== 0) {
  3505. points[j] = 2;
  3506. ++count;
  3507. }
  3508. for (i = 1; i < height; i++) {
  3509. pos = i * lineSize;
  3510. j0 = i * width1;
  3511. if (data[pos - lineSize] !== data[pos]) {
  3512. points[j0] = data[pos] ? 1 : 8;
  3513. ++count;
  3514. }
  3515. // 'sum' is the position of the current pixel configuration in the 'TYPES'
  3516. // array (in order 8-1-2-4, so we can use '>>2' to shift the column).
  3517. var sum = (data[pos] ? 4 : 0) + (data[pos - lineSize] ? 8 : 0);
  3518. for (j = 1; j < width; j++) {
  3519. sum = (sum >> 2) + (data[pos + 1] ? 4 : 0) +
  3520. (data[pos - lineSize + 1] ? 8 : 0);
  3521. if (POINT_TYPES[sum]) {
  3522. points[j0 + j] = POINT_TYPES[sum];
  3523. ++count;
  3524. }
  3525. pos++;
  3526. }
  3527. if (data[pos - lineSize] !== data[pos]) {
  3528. points[j0 + j] = data[pos] ? 2 : 4;
  3529. ++count;
  3530. }
  3531. if (count > POINT_TO_PROCESS_LIMIT) {
  3532. return null;
  3533. }
  3534. }
  3535. pos = lineSize * (height - 1);
  3536. j0 = i * width1;
  3537. if (data[pos] !== 0) {
  3538. points[j0] = 8;
  3539. ++count;
  3540. }
  3541. for (j = 1; j < width; j++) {
  3542. if (data[pos] !== data[pos + 1]) {
  3543. points[j0 + j] = data[pos] ? 4 : 8;
  3544. ++count;
  3545. }
  3546. pos++;
  3547. }
  3548. if (data[pos] !== 0) {
  3549. points[j0 + j] = 4;
  3550. ++count;
  3551. }
  3552. if (count > POINT_TO_PROCESS_LIMIT) {
  3553. return null;
  3554. }
  3555. // building outlines
  3556. var steps = new Int32Array([0, width1, -1, 0, -width1, 0, 0, 0, 1]);
  3557. var outlines = [];
  3558. for (i = 0; count && i <= height; i++) {
  3559. var p = i * width1;
  3560. var end = p + width;
  3561. while (p < end && !points[p]) {
  3562. p++;
  3563. }
  3564. if (p === end) {
  3565. continue;
  3566. }
  3567. var coords = [p % width1, i];
  3568. var type = points[p], p0 = p, pp;
  3569. do {
  3570. var step = steps[type];
  3571. do {
  3572. p += step;
  3573. } while (!points[p]);
  3574. pp = points[p];
  3575. if (pp !== 5 && pp !== 10) {
  3576. // set new direction
  3577. type = pp;
  3578. // delete mark
  3579. points[p] = 0;
  3580. } else { // type is 5 or 10, ie, a crossing
  3581. // set new direction
  3582. type = pp & ((0x33 * type) >> 4);
  3583. // set new type for "future hit"
  3584. points[p] &= (type >> 2 | type << 2);
  3585. }
  3586. coords.push(p % width1);
  3587. coords.push((p / width1) | 0);
  3588. --count;
  3589. } while (p0 !== p);
  3590. outlines.push(coords);
  3591. --i;
  3592. }
  3593. var drawOutline = function(c) {
  3594. c.save();
  3595. // the path shall be painted in [0..1]x[0..1] space
  3596. c.scale(1 / width, -1 / height);
  3597. c.translate(0, -height);
  3598. c.beginPath();
  3599. for (var i = 0, ii = outlines.length; i < ii; i++) {
  3600. var o = outlines[i];
  3601. c.moveTo(o[0], o[1]);
  3602. for (var j = 2, jj = o.length; j < jj; j += 2) {
  3603. c.lineTo(o[j], o[j+1]);
  3604. }
  3605. }
  3606. c.fill();
  3607. c.beginPath();
  3608. c.restore();
  3609. };
  3610. return drawOutline;
  3611. }
  3612. var CanvasExtraState = (function CanvasExtraStateClosure() {
  3613. function CanvasExtraState(old) {
  3614. // Are soft masks and alpha values shapes or opacities?
  3615. this.alphaIsShape = false;
  3616. this.fontSize = 0;
  3617. this.fontSizeScale = 1;
  3618. this.textMatrix = IDENTITY_MATRIX;
  3619. this.textMatrixScale = 1;
  3620. this.fontMatrix = FONT_IDENTITY_MATRIX;
  3621. this.leading = 0;
  3622. // Current point (in user coordinates)
  3623. this.x = 0;
  3624. this.y = 0;
  3625. // Start of text line (in text coordinates)
  3626. this.lineX = 0;
  3627. this.lineY = 0;
  3628. // Character and word spacing
  3629. this.charSpacing = 0;
  3630. this.wordSpacing = 0;
  3631. this.textHScale = 1;
  3632. this.textRenderingMode = TextRenderingMode.FILL;
  3633. this.textRise = 0;
  3634. // Default fore and background colors
  3635. this.fillColor = '#000000';
  3636. this.strokeColor = '#000000';
  3637. this.patternFill = false;
  3638. // Note: fill alpha applies to all non-stroking operations
  3639. this.fillAlpha = 1;
  3640. this.strokeAlpha = 1;
  3641. this.lineWidth = 1;
  3642. this.activeSMask = null; // nonclonable field (see the save method below)
  3643. this.old = old;
  3644. }
  3645. CanvasExtraState.prototype = {
  3646. clone: function CanvasExtraState_clone() {
  3647. return Object.create(this);
  3648. },
  3649. setCurrentPoint: function CanvasExtraState_setCurrentPoint(x, y) {
  3650. this.x = x;
  3651. this.y = y;
  3652. }
  3653. };
  3654. return CanvasExtraState;
  3655. })();
  3656. var CanvasGraphics = (function CanvasGraphicsClosure() {
  3657. // Defines the time the executeOperatorList is going to be executing
  3658. // before it stops and shedules a continue of execution.
  3659. var EXECUTION_TIME = 15;
  3660. // Defines the number of steps before checking the execution time
  3661. var EXECUTION_STEPS = 10;
  3662. function CanvasGraphics(canvasCtx, commonObjs, objs, imageLayer) {
  3663. this.ctx = canvasCtx;
  3664. this.current = new CanvasExtraState();
  3665. this.stateStack = [];
  3666. this.pendingClip = null;
  3667. this.pendingEOFill = false;
  3668. this.res = null;
  3669. this.xobjs = null;
  3670. this.commonObjs = commonObjs;
  3671. this.objs = objs;
  3672. this.imageLayer = imageLayer;
  3673. this.groupStack = [];
  3674. this.processingType3 = null;
  3675. // Patterns are painted relative to the initial page/form transform, see pdf
  3676. // spec 8.7.2 NOTE 1.
  3677. this.baseTransform = null;
  3678. this.baseTransformStack = [];
  3679. this.groupLevel = 0;
  3680. this.smaskStack = [];
  3681. this.smaskCounter = 0;
  3682. this.tempSMask = null;
  3683. this.cachedCanvases = new CachedCanvases();
  3684. if (canvasCtx) {
  3685. // NOTE: if mozCurrentTransform is polyfilled, then the current state of
  3686. // the transformation must already be set in canvasCtx._transformMatrix.
  3687. addContextCurrentTransform(canvasCtx);
  3688. }
  3689. this.cachedGetSinglePixelWidth = null;
  3690. }
  3691. function putBinaryImageData(ctx, imgData) {
  3692. if (typeof ImageData !== 'undefined' && imgData instanceof ImageData) {
  3693. ctx.putImageData(imgData, 0, 0);
  3694. return;
  3695. }
  3696. // Put the image data to the canvas in chunks, rather than putting the
  3697. // whole image at once. This saves JS memory, because the ImageData object
  3698. // is smaller. It also possibly saves C++ memory within the implementation
  3699. // of putImageData(). (E.g. in Firefox we make two short-lived copies of
  3700. // the data passed to putImageData()). |n| shouldn't be too small, however,
  3701. // because too many putImageData() calls will slow things down.
  3702. //
  3703. // Note: as written, if the last chunk is partial, the putImageData() call
  3704. // will (conceptually) put pixels past the bounds of the canvas. But
  3705. // that's ok; any such pixels are ignored.
  3706. var height = imgData.height, width = imgData.width;
  3707. var partialChunkHeight = height % FULL_CHUNK_HEIGHT;
  3708. var fullChunks = (height - partialChunkHeight) / FULL_CHUNK_HEIGHT;
  3709. var totalChunks = partialChunkHeight === 0 ? fullChunks : fullChunks + 1;
  3710. var chunkImgData = ctx.createImageData(width, FULL_CHUNK_HEIGHT);
  3711. var srcPos = 0, destPos;
  3712. var src = imgData.data;
  3713. var dest = chunkImgData.data;
  3714. var i, j, thisChunkHeight, elemsInThisChunk;
  3715. // There are multiple forms in which the pixel data can be passed, and
  3716. // imgData.kind tells us which one this is.
  3717. if (imgData.kind === ImageKind.GRAYSCALE_1BPP) {
  3718. // Grayscale, 1 bit per pixel (i.e. black-and-white).
  3719. var srcLength = src.byteLength;
  3720. var dest32 = PDFJS.hasCanvasTypedArrays ? new Uint32Array(dest.buffer) :
  3721. new Uint32ArrayView(dest);
  3722. var dest32DataLength = dest32.length;
  3723. var fullSrcDiff = (width + 7) >> 3;
  3724. var white = 0xFFFFFFFF;
  3725. var black = (PDFJS.isLittleEndian || !PDFJS.hasCanvasTypedArrays) ?
  3726. 0xFF000000 : 0x000000FF;
  3727. for (i = 0; i < totalChunks; i++) {
  3728. thisChunkHeight =
  3729. (i < fullChunks) ? FULL_CHUNK_HEIGHT : partialChunkHeight;
  3730. destPos = 0;
  3731. for (j = 0; j < thisChunkHeight; j++) {
  3732. var srcDiff = srcLength - srcPos;
  3733. var k = 0;
  3734. var kEnd = (srcDiff > fullSrcDiff) ? width : srcDiff * 8 - 7;
  3735. var kEndUnrolled = kEnd & ~7;
  3736. var mask = 0;
  3737. var srcByte = 0;
  3738. for (; k < kEndUnrolled; k += 8) {
  3739. srcByte = src[srcPos++];
  3740. dest32[destPos++] = (srcByte & 128) ? white : black;
  3741. dest32[destPos++] = (srcByte & 64) ? white : black;
  3742. dest32[destPos++] = (srcByte & 32) ? white : black;
  3743. dest32[destPos++] = (srcByte & 16) ? white : black;
  3744. dest32[destPos++] = (srcByte & 8) ? white : black;
  3745. dest32[destPos++] = (srcByte & 4) ? white : black;
  3746. dest32[destPos++] = (srcByte & 2) ? white : black;
  3747. dest32[destPos++] = (srcByte & 1) ? white : black;
  3748. }
  3749. for (; k < kEnd; k++) {
  3750. if (mask === 0) {
  3751. srcByte = src[srcPos++];
  3752. mask = 128;
  3753. }
  3754. dest32[destPos++] = (srcByte & mask) ? white : black;
  3755. mask >>= 1;
  3756. }
  3757. }
  3758. // We ran out of input. Make all remaining pixels transparent.
  3759. while (destPos < dest32DataLength) {
  3760. dest32[destPos++] = 0;
  3761. }
  3762. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  3763. }
  3764. } else if (imgData.kind === ImageKind.RGBA_32BPP) {
  3765. // RGBA, 32-bits per pixel.
  3766. j = 0;
  3767. elemsInThisChunk = width * FULL_CHUNK_HEIGHT * 4;
  3768. for (i = 0; i < fullChunks; i++) {
  3769. dest.set(src.subarray(srcPos, srcPos + elemsInThisChunk));
  3770. srcPos += elemsInThisChunk;
  3771. ctx.putImageData(chunkImgData, 0, j);
  3772. j += FULL_CHUNK_HEIGHT;
  3773. }
  3774. if (i < totalChunks) {
  3775. elemsInThisChunk = width * partialChunkHeight * 4;
  3776. dest.set(src.subarray(srcPos, srcPos + elemsInThisChunk));
  3777. ctx.putImageData(chunkImgData, 0, j);
  3778. }
  3779. } else if (imgData.kind === ImageKind.RGB_24BPP) {
  3780. // RGB, 24-bits per pixel.
  3781. thisChunkHeight = FULL_CHUNK_HEIGHT;
  3782. elemsInThisChunk = width * thisChunkHeight;
  3783. for (i = 0; i < totalChunks; i++) {
  3784. if (i >= fullChunks) {
  3785. thisChunkHeight = partialChunkHeight;
  3786. elemsInThisChunk = width * thisChunkHeight;
  3787. }
  3788. destPos = 0;
  3789. for (j = elemsInThisChunk; j--;) {
  3790. dest[destPos++] = src[srcPos++];
  3791. dest[destPos++] = src[srcPos++];
  3792. dest[destPos++] = src[srcPos++];
  3793. dest[destPos++] = 255;
  3794. }
  3795. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  3796. }
  3797. } else {
  3798. error('bad image kind: ' + imgData.kind);
  3799. }
  3800. }
  3801. function putBinaryImageMask(ctx, imgData) {
  3802. var height = imgData.height, width = imgData.width;
  3803. var partialChunkHeight = height % FULL_CHUNK_HEIGHT;
  3804. var fullChunks = (height - partialChunkHeight) / FULL_CHUNK_HEIGHT;
  3805. var totalChunks = partialChunkHeight === 0 ? fullChunks : fullChunks + 1;
  3806. var chunkImgData = ctx.createImageData(width, FULL_CHUNK_HEIGHT);
  3807. var srcPos = 0;
  3808. var src = imgData.data;
  3809. var dest = chunkImgData.data;
  3810. for (var i = 0; i < totalChunks; i++) {
  3811. var thisChunkHeight =
  3812. (i < fullChunks) ? FULL_CHUNK_HEIGHT : partialChunkHeight;
  3813. // Expand the mask so it can be used by the canvas. Any required
  3814. // inversion has already been handled.
  3815. var destPos = 3; // alpha component offset
  3816. for (var j = 0; j < thisChunkHeight; j++) {
  3817. var mask = 0;
  3818. for (var k = 0; k < width; k++) {
  3819. if (!mask) {
  3820. var elem = src[srcPos++];
  3821. mask = 128;
  3822. }
  3823. dest[destPos] = (elem & mask) ? 0 : 255;
  3824. destPos += 4;
  3825. mask >>= 1;
  3826. }
  3827. }
  3828. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  3829. }
  3830. }
  3831. function copyCtxState(sourceCtx, destCtx) {
  3832. var properties = ['strokeStyle', 'fillStyle', 'fillRule', 'globalAlpha',
  3833. 'lineWidth', 'lineCap', 'lineJoin', 'miterLimit',
  3834. 'globalCompositeOperation', 'font'];
  3835. for (var i = 0, ii = properties.length; i < ii; i++) {
  3836. var property = properties[i];
  3837. if (sourceCtx[property] !== undefined) {
  3838. destCtx[property] = sourceCtx[property];
  3839. }
  3840. }
  3841. if (sourceCtx.setLineDash !== undefined) {
  3842. destCtx.setLineDash(sourceCtx.getLineDash());
  3843. destCtx.lineDashOffset = sourceCtx.lineDashOffset;
  3844. } else if (sourceCtx.mozDashOffset !== undefined) {
  3845. destCtx.mozDash = sourceCtx.mozDash;
  3846. destCtx.mozDashOffset = sourceCtx.mozDashOffset;
  3847. }
  3848. }
  3849. function composeSMaskBackdrop(bytes, r0, g0, b0) {
  3850. var length = bytes.length;
  3851. for (var i = 3; i < length; i += 4) {
  3852. var alpha = bytes[i];
  3853. if (alpha === 0) {
  3854. bytes[i - 3] = r0;
  3855. bytes[i - 2] = g0;
  3856. bytes[i - 1] = b0;
  3857. } else if (alpha < 255) {
  3858. var alpha_ = 255 - alpha;
  3859. bytes[i - 3] = (bytes[i - 3] * alpha + r0 * alpha_) >> 8;
  3860. bytes[i - 2] = (bytes[i - 2] * alpha + g0 * alpha_) >> 8;
  3861. bytes[i - 1] = (bytes[i - 1] * alpha + b0 * alpha_) >> 8;
  3862. }
  3863. }
  3864. }
  3865. function composeSMaskAlpha(maskData, layerData, transferMap) {
  3866. var length = maskData.length;
  3867. var scale = 1 / 255;
  3868. for (var i = 3; i < length; i += 4) {
  3869. var alpha = transferMap ? transferMap[maskData[i]] : maskData[i];
  3870. layerData[i] = (layerData[i] * alpha * scale) | 0;
  3871. }
  3872. }
  3873. function composeSMaskLuminosity(maskData, layerData, transferMap) {
  3874. var length = maskData.length;
  3875. for (var i = 3; i < length; i += 4) {
  3876. var y = (maskData[i - 3] * 77) + // * 0.3 / 255 * 0x10000
  3877. (maskData[i - 2] * 152) + // * 0.59 ....
  3878. (maskData[i - 1] * 28); // * 0.11 ....
  3879. layerData[i] = transferMap ?
  3880. (layerData[i] * transferMap[y >> 8]) >> 8 :
  3881. (layerData[i] * y) >> 16;
  3882. }
  3883. }
  3884. function genericComposeSMask(maskCtx, layerCtx, width, height,
  3885. subtype, backdrop, transferMap) {
  3886. var hasBackdrop = !!backdrop;
  3887. var r0 = hasBackdrop ? backdrop[0] : 0;
  3888. var g0 = hasBackdrop ? backdrop[1] : 0;
  3889. var b0 = hasBackdrop ? backdrop[2] : 0;
  3890. var composeFn;
  3891. if (subtype === 'Luminosity') {
  3892. composeFn = composeSMaskLuminosity;
  3893. } else {
  3894. composeFn = composeSMaskAlpha;
  3895. }
  3896. // processing image in chunks to save memory
  3897. var PIXELS_TO_PROCESS = 1048576;
  3898. var chunkSize = Math.min(height, Math.ceil(PIXELS_TO_PROCESS / width));
  3899. for (var row = 0; row < height; row += chunkSize) {
  3900. var chunkHeight = Math.min(chunkSize, height - row);
  3901. var maskData = maskCtx.getImageData(0, row, width, chunkHeight);
  3902. var layerData = layerCtx.getImageData(0, row, width, chunkHeight);
  3903. if (hasBackdrop) {
  3904. composeSMaskBackdrop(maskData.data, r0, g0, b0);
  3905. }
  3906. composeFn(maskData.data, layerData.data, transferMap);
  3907. maskCtx.putImageData(layerData, 0, row);
  3908. }
  3909. }
  3910. function composeSMask(ctx, smask, layerCtx) {
  3911. var mask = smask.canvas;
  3912. var maskCtx = smask.context;
  3913. ctx.setTransform(smask.scaleX, 0, 0, smask.scaleY,
  3914. smask.offsetX, smask.offsetY);
  3915. var backdrop = smask.backdrop || null;
  3916. if (!smask.transferMap && WebGLUtils.isEnabled) {
  3917. var composed = WebGLUtils.composeSMask(layerCtx.canvas, mask,
  3918. {subtype: smask.subtype, backdrop: backdrop});
  3919. ctx.setTransform(1, 0, 0, 1, 0, 0);
  3920. ctx.drawImage(composed, smask.offsetX, smask.offsetY);
  3921. return;
  3922. }
  3923. genericComposeSMask(maskCtx, layerCtx, mask.width, mask.height,
  3924. smask.subtype, backdrop, smask.transferMap);
  3925. ctx.drawImage(mask, 0, 0);
  3926. }
  3927. var LINE_CAP_STYLES = ['butt', 'round', 'square'];
  3928. var LINE_JOIN_STYLES = ['miter', 'round', 'bevel'];
  3929. var NORMAL_CLIP = {};
  3930. var EO_CLIP = {};
  3931. CanvasGraphics.prototype = {
  3932. beginDrawing: function CanvasGraphics_beginDrawing(transform, viewport,
  3933. transparency) {
  3934. // For pdfs that use blend modes we have to clear the canvas else certain
  3935. // blend modes can look wrong since we'd be blending with a white
  3936. // backdrop. The problem with a transparent backdrop though is we then
  3937. // don't get sub pixel anti aliasing on text, creating temporary
  3938. // transparent canvas when we have blend modes.
  3939. var width = this.ctx.canvas.width;
  3940. var height = this.ctx.canvas.height;
  3941. this.ctx.save();
  3942. this.ctx.fillStyle = 'rgb(255, 255, 255)';
  3943. this.ctx.fillRect(0, 0, width, height);
  3944. this.ctx.restore();
  3945. if (transparency) {
  3946. var transparentCanvas = this.cachedCanvases.getCanvas(
  3947. 'transparent', width, height, true);
  3948. this.compositeCtx = this.ctx;
  3949. this.transparentCanvas = transparentCanvas.canvas;
  3950. this.ctx = transparentCanvas.context;
  3951. this.ctx.save();
  3952. // The transform can be applied before rendering, transferring it to
  3953. // the new canvas.
  3954. this.ctx.transform.apply(this.ctx,
  3955. this.compositeCtx.mozCurrentTransform);
  3956. }
  3957. this.ctx.save();
  3958. if (transform) {
  3959. this.ctx.transform.apply(this.ctx, transform);
  3960. }
  3961. this.ctx.transform.apply(this.ctx, viewport.transform);
  3962. this.baseTransform = this.ctx.mozCurrentTransform.slice();
  3963. if (this.imageLayer) {
  3964. this.imageLayer.beginLayout();
  3965. }
  3966. },
  3967. executeOperatorList: function CanvasGraphics_executeOperatorList(
  3968. operatorList,
  3969. executionStartIdx, continueCallback,
  3970. stepper) {
  3971. var argsArray = operatorList.argsArray;
  3972. var fnArray = operatorList.fnArray;
  3973. var i = executionStartIdx || 0;
  3974. var argsArrayLen = argsArray.length;
  3975. // Sometimes the OperatorList to execute is empty.
  3976. if (argsArrayLen === i) {
  3977. return i;
  3978. }
  3979. var chunkOperations = (argsArrayLen - i > EXECUTION_STEPS &&
  3980. typeof continueCallback === 'function');
  3981. var endTime = chunkOperations ? Date.now() + EXECUTION_TIME : 0;
  3982. var steps = 0;
  3983. var commonObjs = this.commonObjs;
  3984. var objs = this.objs;
  3985. var fnId;
  3986. while (true) {
  3987. if (stepper !== undefined && i === stepper.nextBreakPoint) {
  3988. stepper.breakIt(i, continueCallback);
  3989. return i;
  3990. }
  3991. fnId = fnArray[i];
  3992. if (fnId !== OPS.dependency) {
  3993. this[fnId].apply(this, argsArray[i]);
  3994. } else {
  3995. var deps = argsArray[i];
  3996. for (var n = 0, nn = deps.length; n < nn; n++) {
  3997. var depObjId = deps[n];
  3998. var common = depObjId[0] === 'g' && depObjId[1] === '_';
  3999. var objsPool = common ? commonObjs : objs;
  4000. // If the promise isn't resolved yet, add the continueCallback
  4001. // to the promise and bail out.
  4002. if (!objsPool.isResolved(depObjId)) {
  4003. objsPool.get(depObjId, continueCallback);
  4004. return i;
  4005. }
  4006. }
  4007. }
  4008. i++;
  4009. // If the entire operatorList was executed, stop as were done.
  4010. if (i === argsArrayLen) {
  4011. return i;
  4012. }
  4013. // If the execution took longer then a certain amount of time and
  4014. // `continueCallback` is specified, interrupt the execution.
  4015. if (chunkOperations && ++steps > EXECUTION_STEPS) {
  4016. if (Date.now() > endTime) {
  4017. continueCallback();
  4018. return i;
  4019. }
  4020. steps = 0;
  4021. }
  4022. // If the operatorList isn't executed completely yet OR the execution
  4023. // time was short enough, do another execution round.
  4024. }
  4025. },
  4026. endDrawing: function CanvasGraphics_endDrawing() {
  4027. this.ctx.restore();
  4028. if (this.transparentCanvas) {
  4029. this.ctx = this.compositeCtx;
  4030. this.ctx.drawImage(this.transparentCanvas, 0, 0);
  4031. this.transparentCanvas = null;
  4032. }
  4033. this.cachedCanvases.clear();
  4034. WebGLUtils.clear();
  4035. if (this.imageLayer) {
  4036. this.imageLayer.endLayout();
  4037. }
  4038. },
  4039. // Graphics state
  4040. setLineWidth: function CanvasGraphics_setLineWidth(width) {
  4041. this.current.lineWidth = width;
  4042. this.ctx.lineWidth = width;
  4043. },
  4044. setLineCap: function CanvasGraphics_setLineCap(style) {
  4045. this.ctx.lineCap = LINE_CAP_STYLES[style];
  4046. },
  4047. setLineJoin: function CanvasGraphics_setLineJoin(style) {
  4048. this.ctx.lineJoin = LINE_JOIN_STYLES[style];
  4049. },
  4050. setMiterLimit: function CanvasGraphics_setMiterLimit(limit) {
  4051. this.ctx.miterLimit = limit;
  4052. },
  4053. setDash: function CanvasGraphics_setDash(dashArray, dashPhase) {
  4054. var ctx = this.ctx;
  4055. if (ctx.setLineDash !== undefined) {
  4056. ctx.setLineDash(dashArray);
  4057. ctx.lineDashOffset = dashPhase;
  4058. } else {
  4059. ctx.mozDash = dashArray;
  4060. ctx.mozDashOffset = dashPhase;
  4061. }
  4062. },
  4063. setRenderingIntent: function CanvasGraphics_setRenderingIntent(intent) {
  4064. // Maybe if we one day fully support color spaces this will be important
  4065. // for now we can ignore.
  4066. // TODO set rendering intent?
  4067. },
  4068. setFlatness: function CanvasGraphics_setFlatness(flatness) {
  4069. // There's no way to control this with canvas, but we can safely ignore.
  4070. // TODO set flatness?
  4071. },
  4072. setGState: function CanvasGraphics_setGState(states) {
  4073. for (var i = 0, ii = states.length; i < ii; i++) {
  4074. var state = states[i];
  4075. var key = state[0];
  4076. var value = state[1];
  4077. switch (key) {
  4078. case 'LW':
  4079. this.setLineWidth(value);
  4080. break;
  4081. case 'LC':
  4082. this.setLineCap(value);
  4083. break;
  4084. case 'LJ':
  4085. this.setLineJoin(value);
  4086. break;
  4087. case 'ML':
  4088. this.setMiterLimit(value);
  4089. break;
  4090. case 'D':
  4091. this.setDash(value[0], value[1]);
  4092. break;
  4093. case 'RI':
  4094. this.setRenderingIntent(value);
  4095. break;
  4096. case 'FL':
  4097. this.setFlatness(value);
  4098. break;
  4099. case 'Font':
  4100. this.setFont(value[0], value[1]);
  4101. break;
  4102. case 'CA':
  4103. this.current.strokeAlpha = state[1];
  4104. break;
  4105. case 'ca':
  4106. this.current.fillAlpha = state[1];
  4107. this.ctx.globalAlpha = state[1];
  4108. break;
  4109. case 'BM':
  4110. if (value && value.name && (value.name !== 'Normal')) {
  4111. var mode = value.name.replace(/([A-Z])/g,
  4112. function(c) {
  4113. return '-' + c.toLowerCase();
  4114. }
  4115. ).substring(1);
  4116. this.ctx.globalCompositeOperation = mode;
  4117. if (this.ctx.globalCompositeOperation !== mode) {
  4118. warn('globalCompositeOperation "' + mode +
  4119. '" is not supported');
  4120. }
  4121. } else {
  4122. this.ctx.globalCompositeOperation = 'source-over';
  4123. }
  4124. break;
  4125. case 'SMask':
  4126. if (this.current.activeSMask) {
  4127. this.endSMaskGroup();
  4128. }
  4129. this.current.activeSMask = value ? this.tempSMask : null;
  4130. if (this.current.activeSMask) {
  4131. this.beginSMaskGroup();
  4132. }
  4133. this.tempSMask = null;
  4134. break;
  4135. }
  4136. }
  4137. },
  4138. beginSMaskGroup: function CanvasGraphics_beginSMaskGroup() {
  4139. var activeSMask = this.current.activeSMask;
  4140. var drawnWidth = activeSMask.canvas.width;
  4141. var drawnHeight = activeSMask.canvas.height;
  4142. var cacheId = 'smaskGroupAt' + this.groupLevel;
  4143. var scratchCanvas = this.cachedCanvases.getCanvas(
  4144. cacheId, drawnWidth, drawnHeight, true);
  4145. var currentCtx = this.ctx;
  4146. var currentTransform = currentCtx.mozCurrentTransform;
  4147. this.ctx.save();
  4148. var groupCtx = scratchCanvas.context;
  4149. groupCtx.scale(1 / activeSMask.scaleX, 1 / activeSMask.scaleY);
  4150. groupCtx.translate(-activeSMask.offsetX, -activeSMask.offsetY);
  4151. groupCtx.transform.apply(groupCtx, currentTransform);
  4152. copyCtxState(currentCtx, groupCtx);
  4153. this.ctx = groupCtx;
  4154. this.setGState([
  4155. ['BM', 'Normal'],
  4156. ['ca', 1],
  4157. ['CA', 1]
  4158. ]);
  4159. this.groupStack.push(currentCtx);
  4160. this.groupLevel++;
  4161. },
  4162. endSMaskGroup: function CanvasGraphics_endSMaskGroup() {
  4163. var groupCtx = this.ctx;
  4164. this.groupLevel--;
  4165. this.ctx = this.groupStack.pop();
  4166. composeSMask(this.ctx, this.current.activeSMask, groupCtx);
  4167. this.ctx.restore();
  4168. copyCtxState(groupCtx, this.ctx);
  4169. },
  4170. save: function CanvasGraphics_save() {
  4171. this.ctx.save();
  4172. var old = this.current;
  4173. this.stateStack.push(old);
  4174. this.current = old.clone();
  4175. this.current.activeSMask = null;
  4176. },
  4177. restore: function CanvasGraphics_restore() {
  4178. if (this.stateStack.length !== 0) {
  4179. if (this.current.activeSMask !== null) {
  4180. this.endSMaskGroup();
  4181. }
  4182. this.current = this.stateStack.pop();
  4183. this.ctx.restore();
  4184. // Ensure that the clipping path is reset (fixes issue6413.pdf).
  4185. this.pendingClip = null;
  4186. this.cachedGetSinglePixelWidth = null;
  4187. }
  4188. },
  4189. transform: function CanvasGraphics_transform(a, b, c, d, e, f) {
  4190. this.ctx.transform(a, b, c, d, e, f);
  4191. this.cachedGetSinglePixelWidth = null;
  4192. },
  4193. // Path
  4194. constructPath: function CanvasGraphics_constructPath(ops, args) {
  4195. var ctx = this.ctx;
  4196. var current = this.current;
  4197. var x = current.x, y = current.y;
  4198. for (var i = 0, j = 0, ii = ops.length; i < ii; i++) {
  4199. switch (ops[i] | 0) {
  4200. case OPS.rectangle:
  4201. x = args[j++];
  4202. y = args[j++];
  4203. var width = args[j++];
  4204. var height = args[j++];
  4205. if (width === 0) {
  4206. width = this.getSinglePixelWidth();
  4207. }
  4208. if (height === 0) {
  4209. height = this.getSinglePixelWidth();
  4210. }
  4211. var xw = x + width;
  4212. var yh = y + height;
  4213. this.ctx.moveTo(x, y);
  4214. this.ctx.lineTo(xw, y);
  4215. this.ctx.lineTo(xw, yh);
  4216. this.ctx.lineTo(x, yh);
  4217. this.ctx.lineTo(x, y);
  4218. this.ctx.closePath();
  4219. break;
  4220. case OPS.moveTo:
  4221. x = args[j++];
  4222. y = args[j++];
  4223. ctx.moveTo(x, y);
  4224. break;
  4225. case OPS.lineTo:
  4226. x = args[j++];
  4227. y = args[j++];
  4228. ctx.lineTo(x, y);
  4229. break;
  4230. case OPS.curveTo:
  4231. x = args[j + 4];
  4232. y = args[j + 5];
  4233. ctx.bezierCurveTo(args[j], args[j + 1], args[j + 2], args[j + 3],
  4234. x, y);
  4235. j += 6;
  4236. break;
  4237. case OPS.curveTo2:
  4238. ctx.bezierCurveTo(x, y, args[j], args[j + 1],
  4239. args[j + 2], args[j + 3]);
  4240. x = args[j + 2];
  4241. y = args[j + 3];
  4242. j += 4;
  4243. break;
  4244. case OPS.curveTo3:
  4245. x = args[j + 2];
  4246. y = args[j + 3];
  4247. ctx.bezierCurveTo(args[j], args[j + 1], x, y, x, y);
  4248. j += 4;
  4249. break;
  4250. case OPS.closePath:
  4251. ctx.closePath();
  4252. break;
  4253. }
  4254. }
  4255. current.setCurrentPoint(x, y);
  4256. },
  4257. closePath: function CanvasGraphics_closePath() {
  4258. this.ctx.closePath();
  4259. },
  4260. stroke: function CanvasGraphics_stroke(consumePath) {
  4261. consumePath = typeof consumePath !== 'undefined' ? consumePath : true;
  4262. var ctx = this.ctx;
  4263. var strokeColor = this.current.strokeColor;
  4264. // Prevent drawing too thin lines by enforcing a minimum line width.
  4265. ctx.lineWidth = Math.max(this.getSinglePixelWidth() * MIN_WIDTH_FACTOR,
  4266. this.current.lineWidth);
  4267. // For stroke we want to temporarily change the global alpha to the
  4268. // stroking alpha.
  4269. ctx.globalAlpha = this.current.strokeAlpha;
  4270. if (strokeColor && strokeColor.hasOwnProperty('type') &&
  4271. strokeColor.type === 'Pattern') {
  4272. // for patterns, we transform to pattern space, calculate
  4273. // the pattern, call stroke, and restore to user space
  4274. ctx.save();
  4275. ctx.strokeStyle = strokeColor.getPattern(ctx, this);
  4276. ctx.stroke();
  4277. ctx.restore();
  4278. } else {
  4279. ctx.stroke();
  4280. }
  4281. if (consumePath) {
  4282. this.consumePath();
  4283. }
  4284. // Restore the global alpha to the fill alpha
  4285. ctx.globalAlpha = this.current.fillAlpha;
  4286. },
  4287. closeStroke: function CanvasGraphics_closeStroke() {
  4288. this.closePath();
  4289. this.stroke();
  4290. },
  4291. fill: function CanvasGraphics_fill(consumePath) {
  4292. consumePath = typeof consumePath !== 'undefined' ? consumePath : true;
  4293. var ctx = this.ctx;
  4294. var fillColor = this.current.fillColor;
  4295. var isPatternFill = this.current.patternFill;
  4296. var needRestore = false;
  4297. if (isPatternFill) {
  4298. ctx.save();
  4299. if (this.baseTransform) {
  4300. ctx.setTransform.apply(ctx, this.baseTransform);
  4301. }
  4302. ctx.fillStyle = fillColor.getPattern(ctx, this);
  4303. needRestore = true;
  4304. }
  4305. if (this.pendingEOFill) {
  4306. if (ctx.mozFillRule !== undefined) {
  4307. ctx.mozFillRule = 'evenodd';
  4308. ctx.fill();
  4309. ctx.mozFillRule = 'nonzero';
  4310. } else {
  4311. ctx.fill('evenodd');
  4312. }
  4313. this.pendingEOFill = false;
  4314. } else {
  4315. ctx.fill();
  4316. }
  4317. if (needRestore) {
  4318. ctx.restore();
  4319. }
  4320. if (consumePath) {
  4321. this.consumePath();
  4322. }
  4323. },
  4324. eoFill: function CanvasGraphics_eoFill() {
  4325. this.pendingEOFill = true;
  4326. this.fill();
  4327. },
  4328. fillStroke: function CanvasGraphics_fillStroke() {
  4329. this.fill(false);
  4330. this.stroke(false);
  4331. this.consumePath();
  4332. },
  4333. eoFillStroke: function CanvasGraphics_eoFillStroke() {
  4334. this.pendingEOFill = true;
  4335. this.fillStroke();
  4336. },
  4337. closeFillStroke: function CanvasGraphics_closeFillStroke() {
  4338. this.closePath();
  4339. this.fillStroke();
  4340. },
  4341. closeEOFillStroke: function CanvasGraphics_closeEOFillStroke() {
  4342. this.pendingEOFill = true;
  4343. this.closePath();
  4344. this.fillStroke();
  4345. },
  4346. endPath: function CanvasGraphics_endPath() {
  4347. this.consumePath();
  4348. },
  4349. // Clipping
  4350. clip: function CanvasGraphics_clip() {
  4351. this.pendingClip = NORMAL_CLIP;
  4352. },
  4353. eoClip: function CanvasGraphics_eoClip() {
  4354. this.pendingClip = EO_CLIP;
  4355. },
  4356. // Text
  4357. beginText: function CanvasGraphics_beginText() {
  4358. this.current.textMatrix = IDENTITY_MATRIX;
  4359. this.current.textMatrixScale = 1;
  4360. this.current.x = this.current.lineX = 0;
  4361. this.current.y = this.current.lineY = 0;
  4362. },
  4363. endText: function CanvasGraphics_endText() {
  4364. var paths = this.pendingTextPaths;
  4365. var ctx = this.ctx;
  4366. if (paths === undefined) {
  4367. ctx.beginPath();
  4368. return;
  4369. }
  4370. ctx.save();
  4371. ctx.beginPath();
  4372. for (var i = 0; i < paths.length; i++) {
  4373. var path = paths[i];
  4374. ctx.setTransform.apply(ctx, path.transform);
  4375. ctx.translate(path.x, path.y);
  4376. path.addToPath(ctx, path.fontSize);
  4377. }
  4378. ctx.restore();
  4379. ctx.clip();
  4380. ctx.beginPath();
  4381. delete this.pendingTextPaths;
  4382. },
  4383. setCharSpacing: function CanvasGraphics_setCharSpacing(spacing) {
  4384. this.current.charSpacing = spacing;
  4385. },
  4386. setWordSpacing: function CanvasGraphics_setWordSpacing(spacing) {
  4387. this.current.wordSpacing = spacing;
  4388. },
  4389. setHScale: function CanvasGraphics_setHScale(scale) {
  4390. this.current.textHScale = scale / 100;
  4391. },
  4392. setLeading: function CanvasGraphics_setLeading(leading) {
  4393. this.current.leading = -leading;
  4394. },
  4395. setFont: function CanvasGraphics_setFont(fontRefName, size) {
  4396. var fontObj = this.commonObjs.get(fontRefName);
  4397. var current = this.current;
  4398. if (!fontObj) {
  4399. error('Can\'t find font for ' + fontRefName);
  4400. }
  4401. current.fontMatrix = (fontObj.fontMatrix ?
  4402. fontObj.fontMatrix : FONT_IDENTITY_MATRIX);
  4403. // A valid matrix needs all main diagonal elements to be non-zero
  4404. // This also ensures we bypass FF bugzilla bug #719844.
  4405. if (current.fontMatrix[0] === 0 ||
  4406. current.fontMatrix[3] === 0) {
  4407. warn('Invalid font matrix for font ' + fontRefName);
  4408. }
  4409. // The spec for Tf (setFont) says that 'size' specifies the font 'scale',
  4410. // and in some docs this can be negative (inverted x-y axes).
  4411. if (size < 0) {
  4412. size = -size;
  4413. current.fontDirection = -1;
  4414. } else {
  4415. current.fontDirection = 1;
  4416. }
  4417. this.current.font = fontObj;
  4418. this.current.fontSize = size;
  4419. if (fontObj.isType3Font) {
  4420. return; // we don't need ctx.font for Type3 fonts
  4421. }
  4422. var name = fontObj.loadedName || 'sans-serif';
  4423. var bold = fontObj.black ? (fontObj.bold ? '900' : 'bold') :
  4424. (fontObj.bold ? 'bold' : 'normal');
  4425. var italic = fontObj.italic ? 'italic' : 'normal';
  4426. var typeface = '"' + name + '", ' + fontObj.fallbackName;
  4427. // Some font backends cannot handle fonts below certain size.
  4428. // Keeping the font at minimal size and using the fontSizeScale to change
  4429. // the current transformation matrix before the fillText/strokeText.
  4430. // See https://bugzilla.mozilla.org/show_bug.cgi?id=726227
  4431. var browserFontSize = size < MIN_FONT_SIZE ? MIN_FONT_SIZE :
  4432. size > MAX_FONT_SIZE ? MAX_FONT_SIZE : size;
  4433. this.current.fontSizeScale = size / browserFontSize;
  4434. var rule = italic + ' ' + bold + ' ' + browserFontSize + 'px ' + typeface;
  4435. this.ctx.font = rule;
  4436. },
  4437. setTextRenderingMode: function CanvasGraphics_setTextRenderingMode(mode) {
  4438. this.current.textRenderingMode = mode;
  4439. },
  4440. setTextRise: function CanvasGraphics_setTextRise(rise) {
  4441. this.current.textRise = rise;
  4442. },
  4443. moveText: function CanvasGraphics_moveText(x, y) {
  4444. this.current.x = this.current.lineX += x;
  4445. this.current.y = this.current.lineY += y;
  4446. },
  4447. setLeadingMoveText: function CanvasGraphics_setLeadingMoveText(x, y) {
  4448. this.setLeading(-y);
  4449. this.moveText(x, y);
  4450. },
  4451. setTextMatrix: function CanvasGraphics_setTextMatrix(a, b, c, d, e, f) {
  4452. this.current.textMatrix = [a, b, c, d, e, f];
  4453. this.current.textMatrixScale = Math.sqrt(a * a + b * b);
  4454. this.current.x = this.current.lineX = 0;
  4455. this.current.y = this.current.lineY = 0;
  4456. },
  4457. nextLine: function CanvasGraphics_nextLine() {
  4458. this.moveText(0, this.current.leading);
  4459. },
  4460. paintChar: function CanvasGraphics_paintChar(character, x, y) {
  4461. var ctx = this.ctx;
  4462. var current = this.current;
  4463. var font = current.font;
  4464. var textRenderingMode = current.textRenderingMode;
  4465. var fontSize = current.fontSize / current.fontSizeScale;
  4466. var fillStrokeMode = textRenderingMode &
  4467. TextRenderingMode.FILL_STROKE_MASK;
  4468. var isAddToPathSet = !!(textRenderingMode &
  4469. TextRenderingMode.ADD_TO_PATH_FLAG);
  4470. var addToPath;
  4471. if (font.disableFontFace || isAddToPathSet) {
  4472. addToPath = font.getPathGenerator(this.commonObjs, character);
  4473. }
  4474. if (font.disableFontFace) {
  4475. ctx.save();
  4476. ctx.translate(x, y);
  4477. ctx.beginPath();
  4478. addToPath(ctx, fontSize);
  4479. if (fillStrokeMode === TextRenderingMode.FILL ||
  4480. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  4481. ctx.fill();
  4482. }
  4483. if (fillStrokeMode === TextRenderingMode.STROKE ||
  4484. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  4485. ctx.stroke();
  4486. }
  4487. ctx.restore();
  4488. } else {
  4489. if (fillStrokeMode === TextRenderingMode.FILL ||
  4490. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  4491. ctx.fillText(character, x, y);
  4492. }
  4493. if (fillStrokeMode === TextRenderingMode.STROKE ||
  4494. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  4495. ctx.strokeText(character, x, y);
  4496. }
  4497. }
  4498. if (isAddToPathSet) {
  4499. var paths = this.pendingTextPaths || (this.pendingTextPaths = []);
  4500. paths.push({
  4501. transform: ctx.mozCurrentTransform,
  4502. x: x,
  4503. y: y,
  4504. fontSize: fontSize,
  4505. addToPath: addToPath
  4506. });
  4507. }
  4508. },
  4509. get isFontSubpixelAAEnabled() {
  4510. // Checks if anti-aliasing is enabled when scaled text is painted.
  4511. // On Windows GDI scaled fonts looks bad.
  4512. var ctx = document.createElement('canvas').getContext('2d');
  4513. ctx.scale(1.5, 1);
  4514. ctx.fillText('I', 0, 10);
  4515. var data = ctx.getImageData(0, 0, 10, 10).data;
  4516. var enabled = false;
  4517. for (var i = 3; i < data.length; i += 4) {
  4518. if (data[i] > 0 && data[i] < 255) {
  4519. enabled = true;
  4520. break;
  4521. }
  4522. }
  4523. return shadow(this, 'isFontSubpixelAAEnabled', enabled);
  4524. },
  4525. showText: function CanvasGraphics_showText(glyphs) {
  4526. var current = this.current;
  4527. var font = current.font;
  4528. if (font.isType3Font) {
  4529. return this.showType3Text(glyphs);
  4530. }
  4531. var fontSize = current.fontSize;
  4532. if (fontSize === 0) {
  4533. return;
  4534. }
  4535. var ctx = this.ctx;
  4536. var fontSizeScale = current.fontSizeScale;
  4537. var charSpacing = current.charSpacing;
  4538. var wordSpacing = current.wordSpacing;
  4539. var fontDirection = current.fontDirection;
  4540. var textHScale = current.textHScale * fontDirection;
  4541. var glyphsLength = glyphs.length;
  4542. var vertical = font.vertical;
  4543. var spacingDir = vertical ? 1 : -1;
  4544. var defaultVMetrics = font.defaultVMetrics;
  4545. var widthAdvanceScale = fontSize * current.fontMatrix[0];
  4546. var simpleFillText =
  4547. current.textRenderingMode === TextRenderingMode.FILL &&
  4548. !font.disableFontFace;
  4549. ctx.save();
  4550. ctx.transform.apply(ctx, current.textMatrix);
  4551. ctx.translate(current.x, current.y + current.textRise);
  4552. if (fontDirection > 0) {
  4553. ctx.scale(textHScale, -1);
  4554. } else {
  4555. ctx.scale(textHScale, 1);
  4556. }
  4557. var lineWidth = current.lineWidth;
  4558. var scale = current.textMatrixScale;
  4559. if (scale === 0 || lineWidth === 0) {
  4560. var fillStrokeMode = current.textRenderingMode &
  4561. TextRenderingMode.FILL_STROKE_MASK;
  4562. if (fillStrokeMode === TextRenderingMode.STROKE ||
  4563. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  4564. this.cachedGetSinglePixelWidth = null;
  4565. lineWidth = this.getSinglePixelWidth() * MIN_WIDTH_FACTOR;
  4566. }
  4567. } else {
  4568. lineWidth /= scale;
  4569. }
  4570. if (fontSizeScale !== 1.0) {
  4571. ctx.scale(fontSizeScale, fontSizeScale);
  4572. lineWidth /= fontSizeScale;
  4573. }
  4574. ctx.lineWidth = lineWidth;
  4575. var x = 0, i;
  4576. for (i = 0; i < glyphsLength; ++i) {
  4577. var glyph = glyphs[i];
  4578. if (isNum(glyph)) {
  4579. x += spacingDir * glyph * fontSize / 1000;
  4580. continue;
  4581. }
  4582. var restoreNeeded = false;
  4583. var spacing = (glyph.isSpace ? wordSpacing : 0) + charSpacing;
  4584. var character = glyph.fontChar;
  4585. var accent = glyph.accent;
  4586. var scaledX, scaledY, scaledAccentX, scaledAccentY;
  4587. var width = glyph.width;
  4588. if (vertical) {
  4589. var vmetric, vx, vy;
  4590. vmetric = glyph.vmetric || defaultVMetrics;
  4591. vx = glyph.vmetric ? vmetric[1] : width * 0.5;
  4592. vx = -vx * widthAdvanceScale;
  4593. vy = vmetric[2] * widthAdvanceScale;
  4594. width = vmetric ? -vmetric[0] : width;
  4595. scaledX = vx / fontSizeScale;
  4596. scaledY = (x + vy) / fontSizeScale;
  4597. } else {
  4598. scaledX = x / fontSizeScale;
  4599. scaledY = 0;
  4600. }
  4601. if (font.remeasure && width > 0) {
  4602. // Some standard fonts may not have the exact width: rescale per
  4603. // character if measured width is greater than expected glyph width
  4604. // and subpixel-aa is enabled, otherwise just center the glyph.
  4605. var measuredWidth = ctx.measureText(character).width * 1000 /
  4606. fontSize * fontSizeScale;
  4607. if (width < measuredWidth && this.isFontSubpixelAAEnabled) {
  4608. var characterScaleX = width / measuredWidth;
  4609. restoreNeeded = true;
  4610. ctx.save();
  4611. ctx.scale(characterScaleX, 1);
  4612. scaledX /= characterScaleX;
  4613. } else if (width !== measuredWidth) {
  4614. scaledX += (width - measuredWidth) / 2000 *
  4615. fontSize / fontSizeScale;
  4616. }
  4617. }
  4618. if (simpleFillText && !accent) {
  4619. // common case
  4620. ctx.fillText(character, scaledX, scaledY);
  4621. } else {
  4622. this.paintChar(character, scaledX, scaledY);
  4623. if (accent) {
  4624. scaledAccentX = scaledX + accent.offset.x / fontSizeScale;
  4625. scaledAccentY = scaledY - accent.offset.y / fontSizeScale;
  4626. this.paintChar(accent.fontChar, scaledAccentX, scaledAccentY);
  4627. }
  4628. }
  4629. var charWidth = width * widthAdvanceScale + spacing * fontDirection;
  4630. x += charWidth;
  4631. if (restoreNeeded) {
  4632. ctx.restore();
  4633. }
  4634. }
  4635. if (vertical) {
  4636. current.y -= x * textHScale;
  4637. } else {
  4638. current.x += x * textHScale;
  4639. }
  4640. ctx.restore();
  4641. },
  4642. showType3Text: function CanvasGraphics_showType3Text(glyphs) {
  4643. // Type3 fonts - each glyph is a "mini-PDF"
  4644. var ctx = this.ctx;
  4645. var current = this.current;
  4646. var font = current.font;
  4647. var fontSize = current.fontSize;
  4648. var fontDirection = current.fontDirection;
  4649. var spacingDir = font.vertical ? 1 : -1;
  4650. var charSpacing = current.charSpacing;
  4651. var wordSpacing = current.wordSpacing;
  4652. var textHScale = current.textHScale * fontDirection;
  4653. var fontMatrix = current.fontMatrix || FONT_IDENTITY_MATRIX;
  4654. var glyphsLength = glyphs.length;
  4655. var isTextInvisible =
  4656. current.textRenderingMode === TextRenderingMode.INVISIBLE;
  4657. var i, glyph, width, spacingLength;
  4658. if (isTextInvisible || fontSize === 0) {
  4659. return;
  4660. }
  4661. this.cachedGetSinglePixelWidth = null;
  4662. ctx.save();
  4663. ctx.transform.apply(ctx, current.textMatrix);
  4664. ctx.translate(current.x, current.y);
  4665. ctx.scale(textHScale, fontDirection);
  4666. for (i = 0; i < glyphsLength; ++i) {
  4667. glyph = glyphs[i];
  4668. if (isNum(glyph)) {
  4669. spacingLength = spacingDir * glyph * fontSize / 1000;
  4670. this.ctx.translate(spacingLength, 0);
  4671. current.x += spacingLength * textHScale;
  4672. continue;
  4673. }
  4674. var spacing = (glyph.isSpace ? wordSpacing : 0) + charSpacing;
  4675. var operatorList = font.charProcOperatorList[glyph.operatorListId];
  4676. if (!operatorList) {
  4677. warn('Type3 character \"' + glyph.operatorListId +
  4678. '\" is not available');
  4679. continue;
  4680. }
  4681. this.processingType3 = glyph;
  4682. this.save();
  4683. ctx.scale(fontSize, fontSize);
  4684. ctx.transform.apply(ctx, fontMatrix);
  4685. this.executeOperatorList(operatorList);
  4686. this.restore();
  4687. var transformed = Util.applyTransform([glyph.width, 0], fontMatrix);
  4688. width = transformed[0] * fontSize + spacing;
  4689. ctx.translate(width, 0);
  4690. current.x += width * textHScale;
  4691. }
  4692. ctx.restore();
  4693. this.processingType3 = null;
  4694. },
  4695. // Type3 fonts
  4696. setCharWidth: function CanvasGraphics_setCharWidth(xWidth, yWidth) {
  4697. // We can safely ignore this since the width should be the same
  4698. // as the width in the Widths array.
  4699. },
  4700. setCharWidthAndBounds: function CanvasGraphics_setCharWidthAndBounds(xWidth,
  4701. yWidth,
  4702. llx,
  4703. lly,
  4704. urx,
  4705. ury) {
  4706. // TODO According to the spec we're also suppose to ignore any operators
  4707. // that set color or include images while processing this type3 font.
  4708. this.ctx.rect(llx, lly, urx - llx, ury - lly);
  4709. this.clip();
  4710. this.endPath();
  4711. },
  4712. // Color
  4713. getColorN_Pattern: function CanvasGraphics_getColorN_Pattern(IR) {
  4714. var pattern;
  4715. if (IR[0] === 'TilingPattern') {
  4716. var color = IR[1];
  4717. var baseTransform = this.baseTransform ||
  4718. this.ctx.mozCurrentTransform.slice();
  4719. var self = this;
  4720. var canvasGraphicsFactory = {
  4721. createCanvasGraphics: function (ctx) {
  4722. return new CanvasGraphics(ctx, self.commonObjs, self.objs);
  4723. }
  4724. };
  4725. pattern = new TilingPattern(IR, color, this.ctx, canvasGraphicsFactory,
  4726. baseTransform);
  4727. } else {
  4728. pattern = getShadingPatternFromIR(IR);
  4729. }
  4730. return pattern;
  4731. },
  4732. setStrokeColorN: function CanvasGraphics_setStrokeColorN(/*...*/) {
  4733. this.current.strokeColor = this.getColorN_Pattern(arguments);
  4734. },
  4735. setFillColorN: function CanvasGraphics_setFillColorN(/*...*/) {
  4736. this.current.fillColor = this.getColorN_Pattern(arguments);
  4737. this.current.patternFill = true;
  4738. },
  4739. setStrokeRGBColor: function CanvasGraphics_setStrokeRGBColor(r, g, b) {
  4740. var color = Util.makeCssRgb(r, g, b);
  4741. this.ctx.strokeStyle = color;
  4742. this.current.strokeColor = color;
  4743. },
  4744. setFillRGBColor: function CanvasGraphics_setFillRGBColor(r, g, b) {
  4745. var color = Util.makeCssRgb(r, g, b);
  4746. this.ctx.fillStyle = color;
  4747. this.current.fillColor = color;
  4748. this.current.patternFill = false;
  4749. },
  4750. shadingFill: function CanvasGraphics_shadingFill(patternIR) {
  4751. var ctx = this.ctx;
  4752. this.save();
  4753. var pattern = getShadingPatternFromIR(patternIR);
  4754. ctx.fillStyle = pattern.getPattern(ctx, this, true);
  4755. var inv = ctx.mozCurrentTransformInverse;
  4756. if (inv) {
  4757. var canvas = ctx.canvas;
  4758. var width = canvas.width;
  4759. var height = canvas.height;
  4760. var bl = Util.applyTransform([0, 0], inv);
  4761. var br = Util.applyTransform([0, height], inv);
  4762. var ul = Util.applyTransform([width, 0], inv);
  4763. var ur = Util.applyTransform([width, height], inv);
  4764. var x0 = Math.min(bl[0], br[0], ul[0], ur[0]);
  4765. var y0 = Math.min(bl[1], br[1], ul[1], ur[1]);
  4766. var x1 = Math.max(bl[0], br[0], ul[0], ur[0]);
  4767. var y1 = Math.max(bl[1], br[1], ul[1], ur[1]);
  4768. this.ctx.fillRect(x0, y0, x1 - x0, y1 - y0);
  4769. } else {
  4770. // HACK to draw the gradient onto an infinite rectangle.
  4771. // PDF gradients are drawn across the entire image while
  4772. // Canvas only allows gradients to be drawn in a rectangle
  4773. // The following bug should allow us to remove this.
  4774. // https://bugzilla.mozilla.org/show_bug.cgi?id=664884
  4775. this.ctx.fillRect(-1e10, -1e10, 2e10, 2e10);
  4776. }
  4777. this.restore();
  4778. },
  4779. // Images
  4780. beginInlineImage: function CanvasGraphics_beginInlineImage() {
  4781. error('Should not call beginInlineImage');
  4782. },
  4783. beginImageData: function CanvasGraphics_beginImageData() {
  4784. error('Should not call beginImageData');
  4785. },
  4786. paintFormXObjectBegin: function CanvasGraphics_paintFormXObjectBegin(matrix,
  4787. bbox) {
  4788. this.save();
  4789. this.baseTransformStack.push(this.baseTransform);
  4790. if (isArray(matrix) && 6 === matrix.length) {
  4791. this.transform.apply(this, matrix);
  4792. }
  4793. this.baseTransform = this.ctx.mozCurrentTransform;
  4794. if (isArray(bbox) && 4 === bbox.length) {
  4795. var width = bbox[2] - bbox[0];
  4796. var height = bbox[3] - bbox[1];
  4797. this.ctx.rect(bbox[0], bbox[1], width, height);
  4798. this.clip();
  4799. this.endPath();
  4800. }
  4801. },
  4802. paintFormXObjectEnd: function CanvasGraphics_paintFormXObjectEnd() {
  4803. this.restore();
  4804. this.baseTransform = this.baseTransformStack.pop();
  4805. },
  4806. beginGroup: function CanvasGraphics_beginGroup(group) {
  4807. this.save();
  4808. var currentCtx = this.ctx;
  4809. // TODO non-isolated groups - according to Rik at adobe non-isolated
  4810. // group results aren't usually that different and they even have tools
  4811. // that ignore this setting. Notes from Rik on implmenting:
  4812. // - When you encounter an transparency group, create a new canvas with
  4813. // the dimensions of the bbox
  4814. // - copy the content from the previous canvas to the new canvas
  4815. // - draw as usual
  4816. // - remove the backdrop alpha:
  4817. // alphaNew = 1 - (1 - alpha)/(1 - alphaBackdrop) with 'alpha' the alpha
  4818. // value of your transparency group and 'alphaBackdrop' the alpha of the
  4819. // backdrop
  4820. // - remove background color:
  4821. // colorNew = color - alphaNew *colorBackdrop /(1 - alphaNew)
  4822. if (!group.isolated) {
  4823. info('TODO: Support non-isolated groups.');
  4824. }
  4825. // TODO knockout - supposedly possible with the clever use of compositing
  4826. // modes.
  4827. if (group.knockout) {
  4828. warn('Knockout groups not supported.');
  4829. }
  4830. var currentTransform = currentCtx.mozCurrentTransform;
  4831. if (group.matrix) {
  4832. currentCtx.transform.apply(currentCtx, group.matrix);
  4833. }
  4834. assert(group.bbox, 'Bounding box is required.');
  4835. // Based on the current transform figure out how big the bounding box
  4836. // will actually be.
  4837. var bounds = Util.getAxialAlignedBoundingBox(
  4838. group.bbox,
  4839. currentCtx.mozCurrentTransform);
  4840. // Clip the bounding box to the current canvas.
  4841. var canvasBounds = [0,
  4842. 0,
  4843. currentCtx.canvas.width,
  4844. currentCtx.canvas.height];
  4845. bounds = Util.intersect(bounds, canvasBounds) || [0, 0, 0, 0];
  4846. // Use ceil in case we're between sizes so we don't create canvas that is
  4847. // too small and make the canvas at least 1x1 pixels.
  4848. var offsetX = Math.floor(bounds[0]);
  4849. var offsetY = Math.floor(bounds[1]);
  4850. var drawnWidth = Math.max(Math.ceil(bounds[2]) - offsetX, 1);
  4851. var drawnHeight = Math.max(Math.ceil(bounds[3]) - offsetY, 1);
  4852. var scaleX = 1, scaleY = 1;
  4853. if (drawnWidth > MAX_GROUP_SIZE) {
  4854. scaleX = drawnWidth / MAX_GROUP_SIZE;
  4855. drawnWidth = MAX_GROUP_SIZE;
  4856. }
  4857. if (drawnHeight > MAX_GROUP_SIZE) {
  4858. scaleY = drawnHeight / MAX_GROUP_SIZE;
  4859. drawnHeight = MAX_GROUP_SIZE;
  4860. }
  4861. var cacheId = 'groupAt' + this.groupLevel;
  4862. if (group.smask) {
  4863. // Using two cache entries is case if masks are used one after another.
  4864. cacheId += '_smask_' + ((this.smaskCounter++) % 2);
  4865. }
  4866. var scratchCanvas = this.cachedCanvases.getCanvas(
  4867. cacheId, drawnWidth, drawnHeight, true);
  4868. var groupCtx = scratchCanvas.context;
  4869. // Since we created a new canvas that is just the size of the bounding box
  4870. // we have to translate the group ctx.
  4871. groupCtx.scale(1 / scaleX, 1 / scaleY);
  4872. groupCtx.translate(-offsetX, -offsetY);
  4873. groupCtx.transform.apply(groupCtx, currentTransform);
  4874. if (group.smask) {
  4875. // Saving state and cached mask to be used in setGState.
  4876. this.smaskStack.push({
  4877. canvas: scratchCanvas.canvas,
  4878. context: groupCtx,
  4879. offsetX: offsetX,
  4880. offsetY: offsetY,
  4881. scaleX: scaleX,
  4882. scaleY: scaleY,
  4883. subtype: group.smask.subtype,
  4884. backdrop: group.smask.backdrop,
  4885. transferMap: group.smask.transferMap || null
  4886. });
  4887. } else {
  4888. // Setup the current ctx so when the group is popped we draw it at the
  4889. // right location.
  4890. currentCtx.setTransform(1, 0, 0, 1, 0, 0);
  4891. currentCtx.translate(offsetX, offsetY);
  4892. currentCtx.scale(scaleX, scaleY);
  4893. }
  4894. // The transparency group inherits all off the current graphics state
  4895. // except the blend mode, soft mask, and alpha constants.
  4896. copyCtxState(currentCtx, groupCtx);
  4897. this.ctx = groupCtx;
  4898. this.setGState([
  4899. ['BM', 'Normal'],
  4900. ['ca', 1],
  4901. ['CA', 1]
  4902. ]);
  4903. this.groupStack.push(currentCtx);
  4904. this.groupLevel++;
  4905. },
  4906. endGroup: function CanvasGraphics_endGroup(group) {
  4907. this.groupLevel--;
  4908. var groupCtx = this.ctx;
  4909. this.ctx = this.groupStack.pop();
  4910. // Turn off image smoothing to avoid sub pixel interpolation which can
  4911. // look kind of blurry for some pdfs.
  4912. if (this.ctx.imageSmoothingEnabled !== undefined) {
  4913. this.ctx.imageSmoothingEnabled = false;
  4914. } else {
  4915. this.ctx.mozImageSmoothingEnabled = false;
  4916. }
  4917. if (group.smask) {
  4918. this.tempSMask = this.smaskStack.pop();
  4919. } else {
  4920. this.ctx.drawImage(groupCtx.canvas, 0, 0);
  4921. }
  4922. this.restore();
  4923. },
  4924. beginAnnotations: function CanvasGraphics_beginAnnotations() {
  4925. this.save();
  4926. this.current = new CanvasExtraState();
  4927. },
  4928. endAnnotations: function CanvasGraphics_endAnnotations() {
  4929. this.restore();
  4930. },
  4931. beginAnnotation: function CanvasGraphics_beginAnnotation(rect, transform,
  4932. matrix) {
  4933. this.save();
  4934. if (isArray(rect) && 4 === rect.length) {
  4935. var width = rect[2] - rect[0];
  4936. var height = rect[3] - rect[1];
  4937. this.ctx.rect(rect[0], rect[1], width, height);
  4938. this.clip();
  4939. this.endPath();
  4940. }
  4941. this.transform.apply(this, transform);
  4942. this.transform.apply(this, matrix);
  4943. },
  4944. endAnnotation: function CanvasGraphics_endAnnotation() {
  4945. this.restore();
  4946. },
  4947. paintJpegXObject: function CanvasGraphics_paintJpegXObject(objId, w, h) {
  4948. var domImage = this.objs.get(objId);
  4949. if (!domImage) {
  4950. warn('Dependent image isn\'t ready yet');
  4951. return;
  4952. }
  4953. this.save();
  4954. var ctx = this.ctx;
  4955. // scale the image to the unit square
  4956. ctx.scale(1 / w, -1 / h);
  4957. ctx.drawImage(domImage, 0, 0, domImage.width, domImage.height,
  4958. 0, -h, w, h);
  4959. if (this.imageLayer) {
  4960. var currentTransform = ctx.mozCurrentTransformInverse;
  4961. var position = this.getCanvasPosition(0, 0);
  4962. this.imageLayer.appendImage({
  4963. objId: objId,
  4964. left: position[0],
  4965. top: position[1],
  4966. width: w / currentTransform[0],
  4967. height: h / currentTransform[3]
  4968. });
  4969. }
  4970. this.restore();
  4971. },
  4972. paintImageMaskXObject: function CanvasGraphics_paintImageMaskXObject(img) {
  4973. var ctx = this.ctx;
  4974. var width = img.width, height = img.height;
  4975. var fillColor = this.current.fillColor;
  4976. var isPatternFill = this.current.patternFill;
  4977. var glyph = this.processingType3;
  4978. if (COMPILE_TYPE3_GLYPHS && glyph && glyph.compiled === undefined) {
  4979. if (width <= MAX_SIZE_TO_COMPILE && height <= MAX_SIZE_TO_COMPILE) {
  4980. glyph.compiled =
  4981. compileType3Glyph({data: img.data, width: width, height: height});
  4982. } else {
  4983. glyph.compiled = null;
  4984. }
  4985. }
  4986. if (glyph && glyph.compiled) {
  4987. glyph.compiled(ctx);
  4988. return;
  4989. }
  4990. var maskCanvas = this.cachedCanvases.getCanvas('maskCanvas',
  4991. width, height);
  4992. var maskCtx = maskCanvas.context;
  4993. maskCtx.save();
  4994. putBinaryImageMask(maskCtx, img);
  4995. maskCtx.globalCompositeOperation = 'source-in';
  4996. maskCtx.fillStyle = isPatternFill ?
  4997. fillColor.getPattern(maskCtx, this) : fillColor;
  4998. maskCtx.fillRect(0, 0, width, height);
  4999. maskCtx.restore();
  5000. this.paintInlineImageXObject(maskCanvas.canvas);
  5001. },
  5002. paintImageMaskXObjectRepeat:
  5003. function CanvasGraphics_paintImageMaskXObjectRepeat(imgData, scaleX,
  5004. scaleY, positions) {
  5005. var width = imgData.width;
  5006. var height = imgData.height;
  5007. var fillColor = this.current.fillColor;
  5008. var isPatternFill = this.current.patternFill;
  5009. var maskCanvas = this.cachedCanvases.getCanvas('maskCanvas',
  5010. width, height);
  5011. var maskCtx = maskCanvas.context;
  5012. maskCtx.save();
  5013. putBinaryImageMask(maskCtx, imgData);
  5014. maskCtx.globalCompositeOperation = 'source-in';
  5015. maskCtx.fillStyle = isPatternFill ?
  5016. fillColor.getPattern(maskCtx, this) : fillColor;
  5017. maskCtx.fillRect(0, 0, width, height);
  5018. maskCtx.restore();
  5019. var ctx = this.ctx;
  5020. for (var i = 0, ii = positions.length; i < ii; i += 2) {
  5021. ctx.save();
  5022. ctx.transform(scaleX, 0, 0, scaleY, positions[i], positions[i + 1]);
  5023. ctx.scale(1, -1);
  5024. ctx.drawImage(maskCanvas.canvas, 0, 0, width, height,
  5025. 0, -1, 1, 1);
  5026. ctx.restore();
  5027. }
  5028. },
  5029. paintImageMaskXObjectGroup:
  5030. function CanvasGraphics_paintImageMaskXObjectGroup(images) {
  5031. var ctx = this.ctx;
  5032. var fillColor = this.current.fillColor;
  5033. var isPatternFill = this.current.patternFill;
  5034. for (var i = 0, ii = images.length; i < ii; i++) {
  5035. var image = images[i];
  5036. var width = image.width, height = image.height;
  5037. var maskCanvas = this.cachedCanvases.getCanvas('maskCanvas',
  5038. width, height);
  5039. var maskCtx = maskCanvas.context;
  5040. maskCtx.save();
  5041. putBinaryImageMask(maskCtx, image);
  5042. maskCtx.globalCompositeOperation = 'source-in';
  5043. maskCtx.fillStyle = isPatternFill ?
  5044. fillColor.getPattern(maskCtx, this) : fillColor;
  5045. maskCtx.fillRect(0, 0, width, height);
  5046. maskCtx.restore();
  5047. ctx.save();
  5048. ctx.transform.apply(ctx, image.transform);
  5049. ctx.scale(1, -1);
  5050. ctx.drawImage(maskCanvas.canvas, 0, 0, width, height,
  5051. 0, -1, 1, 1);
  5052. ctx.restore();
  5053. }
  5054. },
  5055. paintImageXObject: function CanvasGraphics_paintImageXObject(objId) {
  5056. var imgData = this.objs.get(objId);
  5057. if (!imgData) {
  5058. warn('Dependent image isn\'t ready yet');
  5059. return;
  5060. }
  5061. this.paintInlineImageXObject(imgData);
  5062. },
  5063. paintImageXObjectRepeat:
  5064. function CanvasGraphics_paintImageXObjectRepeat(objId, scaleX, scaleY,
  5065. positions) {
  5066. var imgData = this.objs.get(objId);
  5067. if (!imgData) {
  5068. warn('Dependent image isn\'t ready yet');
  5069. return;
  5070. }
  5071. var width = imgData.width;
  5072. var height = imgData.height;
  5073. var map = [];
  5074. for (var i = 0, ii = positions.length; i < ii; i += 2) {
  5075. map.push({transform: [scaleX, 0, 0, scaleY, positions[i],
  5076. positions[i + 1]], x: 0, y: 0, w: width, h: height});
  5077. }
  5078. this.paintInlineImageXObjectGroup(imgData, map);
  5079. },
  5080. paintInlineImageXObject:
  5081. function CanvasGraphics_paintInlineImageXObject(imgData) {
  5082. var width = imgData.width;
  5083. var height = imgData.height;
  5084. var ctx = this.ctx;
  5085. this.save();
  5086. // scale the image to the unit square
  5087. ctx.scale(1 / width, -1 / height);
  5088. var currentTransform = ctx.mozCurrentTransformInverse;
  5089. var a = currentTransform[0], b = currentTransform[1];
  5090. var widthScale = Math.max(Math.sqrt(a * a + b * b), 1);
  5091. var c = currentTransform[2], d = currentTransform[3];
  5092. var heightScale = Math.max(Math.sqrt(c * c + d * d), 1);
  5093. var imgToPaint, tmpCanvas;
  5094. // instanceof HTMLElement does not work in jsdom node.js module
  5095. if (imgData instanceof HTMLElement || !imgData.data) {
  5096. imgToPaint = imgData;
  5097. } else {
  5098. tmpCanvas = this.cachedCanvases.getCanvas('inlineImage',
  5099. width, height);
  5100. var tmpCtx = tmpCanvas.context;
  5101. putBinaryImageData(tmpCtx, imgData);
  5102. imgToPaint = tmpCanvas.canvas;
  5103. }
  5104. var paintWidth = width, paintHeight = height;
  5105. var tmpCanvasId = 'prescale1';
  5106. // Vertial or horizontal scaling shall not be more than 2 to not loose the
  5107. // pixels during drawImage operation, painting on the temporary canvas(es)
  5108. // that are twice smaller in size
  5109. while ((widthScale > 2 && paintWidth > 1) ||
  5110. (heightScale > 2 && paintHeight > 1)) {
  5111. var newWidth = paintWidth, newHeight = paintHeight;
  5112. if (widthScale > 2 && paintWidth > 1) {
  5113. newWidth = Math.ceil(paintWidth / 2);
  5114. widthScale /= paintWidth / newWidth;
  5115. }
  5116. if (heightScale > 2 && paintHeight > 1) {
  5117. newHeight = Math.ceil(paintHeight / 2);
  5118. heightScale /= paintHeight / newHeight;
  5119. }
  5120. tmpCanvas = this.cachedCanvases.getCanvas(tmpCanvasId,
  5121. newWidth, newHeight);
  5122. tmpCtx = tmpCanvas.context;
  5123. tmpCtx.clearRect(0, 0, newWidth, newHeight);
  5124. tmpCtx.drawImage(imgToPaint, 0, 0, paintWidth, paintHeight,
  5125. 0, 0, newWidth, newHeight);
  5126. imgToPaint = tmpCanvas.canvas;
  5127. paintWidth = newWidth;
  5128. paintHeight = newHeight;
  5129. tmpCanvasId = tmpCanvasId === 'prescale1' ? 'prescale2' : 'prescale1';
  5130. }
  5131. ctx.drawImage(imgToPaint, 0, 0, paintWidth, paintHeight,
  5132. 0, -height, width, height);
  5133. if (this.imageLayer) {
  5134. var position = this.getCanvasPosition(0, -height);
  5135. this.imageLayer.appendImage({
  5136. imgData: imgData,
  5137. left: position[0],
  5138. top: position[1],
  5139. width: width / currentTransform[0],
  5140. height: height / currentTransform[3]
  5141. });
  5142. }
  5143. this.restore();
  5144. },
  5145. paintInlineImageXObjectGroup:
  5146. function CanvasGraphics_paintInlineImageXObjectGroup(imgData, map) {
  5147. var ctx = this.ctx;
  5148. var w = imgData.width;
  5149. var h = imgData.height;
  5150. var tmpCanvas = this.cachedCanvases.getCanvas('inlineImage', w, h);
  5151. var tmpCtx = tmpCanvas.context;
  5152. putBinaryImageData(tmpCtx, imgData);
  5153. for (var i = 0, ii = map.length; i < ii; i++) {
  5154. var entry = map[i];
  5155. ctx.save();
  5156. ctx.transform.apply(ctx, entry.transform);
  5157. ctx.scale(1, -1);
  5158. ctx.drawImage(tmpCanvas.canvas, entry.x, entry.y, entry.w, entry.h,
  5159. 0, -1, 1, 1);
  5160. if (this.imageLayer) {
  5161. var position = this.getCanvasPosition(entry.x, entry.y);
  5162. this.imageLayer.appendImage({
  5163. imgData: imgData,
  5164. left: position[0],
  5165. top: position[1],
  5166. width: w,
  5167. height: h
  5168. });
  5169. }
  5170. ctx.restore();
  5171. }
  5172. },
  5173. paintSolidColorImageMask:
  5174. function CanvasGraphics_paintSolidColorImageMask() {
  5175. this.ctx.fillRect(0, 0, 1, 1);
  5176. },
  5177. paintXObject: function CanvasGraphics_paintXObject() {
  5178. warn('Unsupported \'paintXObject\' command.');
  5179. },
  5180. // Marked content
  5181. markPoint: function CanvasGraphics_markPoint(tag) {
  5182. // TODO Marked content.
  5183. },
  5184. markPointProps: function CanvasGraphics_markPointProps(tag, properties) {
  5185. // TODO Marked content.
  5186. },
  5187. beginMarkedContent: function CanvasGraphics_beginMarkedContent(tag) {
  5188. // TODO Marked content.
  5189. },
  5190. beginMarkedContentProps: function CanvasGraphics_beginMarkedContentProps(
  5191. tag, properties) {
  5192. // TODO Marked content.
  5193. },
  5194. endMarkedContent: function CanvasGraphics_endMarkedContent() {
  5195. // TODO Marked content.
  5196. },
  5197. // Compatibility
  5198. beginCompat: function CanvasGraphics_beginCompat() {
  5199. // TODO ignore undefined operators (should we do that anyway?)
  5200. },
  5201. endCompat: function CanvasGraphics_endCompat() {
  5202. // TODO stop ignoring undefined operators
  5203. },
  5204. // Helper functions
  5205. consumePath: function CanvasGraphics_consumePath() {
  5206. var ctx = this.ctx;
  5207. if (this.pendingClip) {
  5208. if (this.pendingClip === EO_CLIP) {
  5209. if (ctx.mozFillRule !== undefined) {
  5210. ctx.mozFillRule = 'evenodd';
  5211. ctx.clip();
  5212. ctx.mozFillRule = 'nonzero';
  5213. } else {
  5214. ctx.clip('evenodd');
  5215. }
  5216. } else {
  5217. ctx.clip();
  5218. }
  5219. this.pendingClip = null;
  5220. }
  5221. ctx.beginPath();
  5222. },
  5223. getSinglePixelWidth: function CanvasGraphics_getSinglePixelWidth(scale) {
  5224. if (this.cachedGetSinglePixelWidth === null) {
  5225. var inverse = this.ctx.mozCurrentTransformInverse;
  5226. // max of the current horizontal and vertical scale
  5227. this.cachedGetSinglePixelWidth = Math.sqrt(Math.max(
  5228. (inverse[0] * inverse[0] + inverse[1] * inverse[1]),
  5229. (inverse[2] * inverse[2] + inverse[3] * inverse[3])));
  5230. }
  5231. return this.cachedGetSinglePixelWidth;
  5232. },
  5233. getCanvasPosition: function CanvasGraphics_getCanvasPosition(x, y) {
  5234. var transform = this.ctx.mozCurrentTransform;
  5235. return [
  5236. transform[0] * x + transform[2] * y + transform[4],
  5237. transform[1] * x + transform[3] * y + transform[5]
  5238. ];
  5239. }
  5240. };
  5241. for (var op in OPS) {
  5242. CanvasGraphics.prototype[OPS[op]] = CanvasGraphics.prototype[op];
  5243. }
  5244. return CanvasGraphics;
  5245. })();
  5246. exports.CanvasGraphics = CanvasGraphics;
  5247. exports.createScratchCanvas = createScratchCanvas;
  5248. }));
  5249. (function (root, factory) {
  5250. {
  5251. factory((root.pdfjsDisplayAPI = {}), root.pdfjsSharedUtil,
  5252. root.pdfjsDisplayFontLoader, root.pdfjsDisplayCanvas,
  5253. root.pdfjsSharedGlobal);
  5254. }
  5255. }(this, function (exports, sharedUtil, displayFontLoader, displayCanvas,
  5256. sharedGlobal, amdRequire) {
  5257. var InvalidPDFException = sharedUtil.InvalidPDFException;
  5258. var MessageHandler = sharedUtil.MessageHandler;
  5259. var MissingPDFException = sharedUtil.MissingPDFException;
  5260. var PasswordResponses = sharedUtil.PasswordResponses;
  5261. var PasswordException = sharedUtil.PasswordException;
  5262. var StatTimer = sharedUtil.StatTimer;
  5263. var UnexpectedResponseException = sharedUtil.UnexpectedResponseException;
  5264. var UnknownErrorException = sharedUtil.UnknownErrorException;
  5265. var Util = sharedUtil.Util;
  5266. var createPromiseCapability = sharedUtil.createPromiseCapability;
  5267. var combineUrl = sharedUtil.combineUrl;
  5268. var error = sharedUtil.error;
  5269. var deprecated = sharedUtil.deprecated;
  5270. var info = sharedUtil.info;
  5271. var isArrayBuffer = sharedUtil.isArrayBuffer;
  5272. var loadJpegStream = sharedUtil.loadJpegStream;
  5273. var stringToBytes = sharedUtil.stringToBytes;
  5274. var warn = sharedUtil.warn;
  5275. var FontFaceObject = displayFontLoader.FontFaceObject;
  5276. var FontLoader = displayFontLoader.FontLoader;
  5277. var CanvasGraphics = displayCanvas.CanvasGraphics;
  5278. var createScratchCanvas = displayCanvas.createScratchCanvas;
  5279. var PDFJS = sharedGlobal.PDFJS;
  5280. var globalScope = sharedGlobal.globalScope;
  5281. var DEFAULT_RANGE_CHUNK_SIZE = 65536; // 2^16 = 65536
  5282. /**
  5283. * The maximum allowed image size in total pixels e.g. width * height. Images
  5284. * above this value will not be drawn. Use -1 for no limit.
  5285. * @var {number}
  5286. */
  5287. PDFJS.maxImageSize = (PDFJS.maxImageSize === undefined ?
  5288. -1 : PDFJS.maxImageSize);
  5289. /**
  5290. * The url of where the predefined Adobe CMaps are located. Include trailing
  5291. * slash.
  5292. * @var {string}
  5293. */
  5294. PDFJS.cMapUrl = (PDFJS.cMapUrl === undefined ? null : PDFJS.cMapUrl);
  5295. /**
  5296. * Specifies if CMaps are binary packed.
  5297. * @var {boolean}
  5298. */
  5299. PDFJS.cMapPacked = PDFJS.cMapPacked === undefined ? false : PDFJS.cMapPacked;
  5300. /**
  5301. * By default fonts are converted to OpenType fonts and loaded via font face
  5302. * rules. If disabled, the font will be rendered using a built in font renderer
  5303. * that constructs the glyphs with primitive path commands.
  5304. * @var {boolean}
  5305. */
  5306. PDFJS.disableFontFace = (PDFJS.disableFontFace === undefined ?
  5307. false : PDFJS.disableFontFace);
  5308. /**
  5309. * Path for image resources, mainly for annotation icons. Include trailing
  5310. * slash.
  5311. * @var {string}
  5312. */
  5313. PDFJS.imageResourcesPath = (PDFJS.imageResourcesPath === undefined ?
  5314. '' : PDFJS.imageResourcesPath);
  5315. /**
  5316. * Disable the web worker and run all code on the main thread. This will happen
  5317. * automatically if the browser doesn't support workers or sending typed arrays
  5318. * to workers.
  5319. * @var {boolean}
  5320. */
  5321. PDFJS.disableWorker = (PDFJS.disableWorker === undefined ?
  5322. false : PDFJS.disableWorker);
  5323. /**
  5324. * Path and filename of the worker file. Required when the worker is enabled in
  5325. * development mode. If unspecified in the production build, the worker will be
  5326. * loaded based on the location of the pdf.js file. It is recommended that
  5327. * the workerSrc is set in a custom application to prevent issues caused by
  5328. * third-party frameworks and libraries.
  5329. * @var {string}
  5330. */
  5331. PDFJS.workerSrc = (PDFJS.workerSrc === undefined ? null : PDFJS.workerSrc);
  5332. /**
  5333. * Disable range request loading of PDF files. When enabled and if the server
  5334. * supports partial content requests then the PDF will be fetched in chunks.
  5335. * Enabled (false) by default.
  5336. * @var {boolean}
  5337. */
  5338. PDFJS.disableRange = (PDFJS.disableRange === undefined ?
  5339. false : PDFJS.disableRange);
  5340. /**
  5341. * Disable streaming of PDF file data. By default PDF.js attempts to load PDF
  5342. * in chunks. This default behavior can be disabled.
  5343. * @var {boolean}
  5344. */
  5345. PDFJS.disableStream = (PDFJS.disableStream === undefined ?
  5346. false : PDFJS.disableStream);
  5347. /**
  5348. * Disable pre-fetching of PDF file data. When range requests are enabled PDF.js
  5349. * will automatically keep fetching more data even if it isn't needed to display
  5350. * the current page. This default behavior can be disabled.
  5351. *
  5352. * NOTE: It is also necessary to disable streaming, see above,
  5353. * in order for disabling of pre-fetching to work correctly.
  5354. * @var {boolean}
  5355. */
  5356. PDFJS.disableAutoFetch = (PDFJS.disableAutoFetch === undefined ?
  5357. false : PDFJS.disableAutoFetch);
  5358. /**
  5359. * Enables special hooks for debugging PDF.js.
  5360. * @var {boolean}
  5361. */
  5362. PDFJS.pdfBug = (PDFJS.pdfBug === undefined ? false : PDFJS.pdfBug);
  5363. /**
  5364. * Enables transfer usage in postMessage for ArrayBuffers.
  5365. * @var {boolean}
  5366. */
  5367. PDFJS.postMessageTransfers = (PDFJS.postMessageTransfers === undefined ?
  5368. true : PDFJS.postMessageTransfers);
  5369. /**
  5370. * Disables URL.createObjectURL usage.
  5371. * @var {boolean}
  5372. */
  5373. PDFJS.disableCreateObjectURL = (PDFJS.disableCreateObjectURL === undefined ?
  5374. false : PDFJS.disableCreateObjectURL);
  5375. /**
  5376. * Disables WebGL usage.
  5377. * @var {boolean}
  5378. */
  5379. PDFJS.disableWebGL = (PDFJS.disableWebGL === undefined ?
  5380. true : PDFJS.disableWebGL);
  5381. /**
  5382. * Disables fullscreen support, and by extension Presentation Mode,
  5383. * in browsers which support the fullscreen API.
  5384. * @var {boolean}
  5385. */
  5386. PDFJS.disableFullscreen = (PDFJS.disableFullscreen === undefined ?
  5387. false : PDFJS.disableFullscreen);
  5388. /**
  5389. * Enables CSS only zooming.
  5390. * @var {boolean}
  5391. */
  5392. PDFJS.useOnlyCssZoom = (PDFJS.useOnlyCssZoom === undefined ?
  5393. false : PDFJS.useOnlyCssZoom);
  5394. /**
  5395. * Controls the logging level.
  5396. * The constants from PDFJS.VERBOSITY_LEVELS should be used:
  5397. * - errors
  5398. * - warnings [default]
  5399. * - infos
  5400. * @var {number}
  5401. */
  5402. PDFJS.verbosity = (PDFJS.verbosity === undefined ?
  5403. PDFJS.VERBOSITY_LEVELS.warnings : PDFJS.verbosity);
  5404. /**
  5405. * The maximum supported canvas size in total pixels e.g. width * height.
  5406. * The default value is 4096 * 4096. Use -1 for no limit.
  5407. * @var {number}
  5408. */
  5409. PDFJS.maxCanvasPixels = (PDFJS.maxCanvasPixels === undefined ?
  5410. 16777216 : PDFJS.maxCanvasPixels);
  5411. /**
  5412. * (Deprecated) Opens external links in a new window if enabled.
  5413. * The default behavior opens external links in the PDF.js window.
  5414. *
  5415. * NOTE: This property has been deprecated, please use
  5416. * `PDFJS.externalLinkTarget = PDFJS.LinkTarget.BLANK` instead.
  5417. * @var {boolean}
  5418. */
  5419. PDFJS.openExternalLinksInNewWindow = (
  5420. PDFJS.openExternalLinksInNewWindow === undefined ?
  5421. false : PDFJS.openExternalLinksInNewWindow);
  5422. /**
  5423. * Specifies the |target| attribute for external links.
  5424. * The constants from PDFJS.LinkTarget should be used:
  5425. * - NONE [default]
  5426. * - SELF
  5427. * - BLANK
  5428. * - PARENT
  5429. * - TOP
  5430. * @var {number}
  5431. */
  5432. PDFJS.externalLinkTarget = (PDFJS.externalLinkTarget === undefined ?
  5433. PDFJS.LinkTarget.NONE : PDFJS.externalLinkTarget);
  5434. /**
  5435. * Specifies the |rel| attribute for external links. Defaults to stripping
  5436. * the referrer.
  5437. * @var {string}
  5438. */
  5439. PDFJS.externalLinkRel = (PDFJS.externalLinkRel === undefined ?
  5440. 'noreferrer' : PDFJS.externalLinkRel);
  5441. /**
  5442. * Determines if we can eval strings as JS. Primarily used to improve
  5443. * performance for font rendering.
  5444. * @var {boolean}
  5445. */
  5446. PDFJS.isEvalSupported = (PDFJS.isEvalSupported === undefined ?
  5447. true : PDFJS.isEvalSupported);
  5448. /**
  5449. * Document initialization / loading parameters object.
  5450. *
  5451. * @typedef {Object} DocumentInitParameters
  5452. * @property {string} url - The URL of the PDF.
  5453. * @property {TypedArray|Array|string} data - Binary PDF data. Use typed arrays
  5454. * (Uint8Array) to improve the memory usage. If PDF data is BASE64-encoded,
  5455. * use atob() to convert it to a binary string first.
  5456. * @property {Object} httpHeaders - Basic authentication headers.
  5457. * @property {boolean} withCredentials - Indicates whether or not cross-site
  5458. * Access-Control requests should be made using credentials such as cookies
  5459. * or authorization headers. The default is false.
  5460. * @property {string} password - For decrypting password-protected PDFs.
  5461. * @property {TypedArray} initialData - A typed array with the first portion or
  5462. * all of the pdf data. Used by the extension since some data is already
  5463. * loaded before the switch to range requests.
  5464. * @property {number} length - The PDF file length. It's used for progress
  5465. * reports and range requests operations.
  5466. * @property {PDFDataRangeTransport} range
  5467. * @property {number} rangeChunkSize - Optional parameter to specify
  5468. * maximum number of bytes fetched per range request. The default value is
  5469. * 2^16 = 65536.
  5470. * @property {PDFWorker} worker - The worker that will be used for the loading
  5471. * and parsing of the PDF data.
  5472. */
  5473. /**
  5474. * @typedef {Object} PDFDocumentStats
  5475. * @property {Array} streamTypes - Used stream types in the document (an item
  5476. * is set to true if specific stream ID was used in the document).
  5477. * @property {Array} fontTypes - Used font type in the document (an item is set
  5478. * to true if specific font ID was used in the document).
  5479. */
  5480. /**
  5481. * This is the main entry point for loading a PDF and interacting with it.
  5482. * NOTE: If a URL is used to fetch the PDF data a standard XMLHttpRequest(XHR)
  5483. * is used, which means it must follow the same origin rules that any XHR does
  5484. * e.g. No cross domain requests without CORS.
  5485. *
  5486. * @param {string|TypedArray|DocumentInitParameters|PDFDataRangeTransport} src
  5487. * Can be a url to where a PDF is located, a typed array (Uint8Array)
  5488. * already populated with data or parameter object.
  5489. *
  5490. * @param {PDFDataRangeTransport} pdfDataRangeTransport (deprecated) It is used
  5491. * if you want to manually serve range requests for data in the PDF.
  5492. *
  5493. * @param {function} passwordCallback (deprecated) It is used to request a
  5494. * password if wrong or no password was provided. The callback receives two
  5495. * parameters: function that needs to be called with new password and reason
  5496. * (see {PasswordResponses}).
  5497. *
  5498. * @param {function} progressCallback (deprecated) It is used to be able to
  5499. * monitor the loading progress of the PDF file (necessary to implement e.g.
  5500. * a loading bar). The callback receives an {Object} with the properties:
  5501. * {number} loaded and {number} total.
  5502. *
  5503. * @return {PDFDocumentLoadingTask}
  5504. */
  5505. PDFJS.getDocument = function getDocument(src,
  5506. pdfDataRangeTransport,
  5507. passwordCallback,
  5508. progressCallback) {
  5509. var task = new PDFDocumentLoadingTask();
  5510. // Support of the obsolete arguments (for compatibility with API v1.0)
  5511. if (arguments.length > 1) {
  5512. deprecated('getDocument is called with pdfDataRangeTransport, ' +
  5513. 'passwordCallback or progressCallback argument');
  5514. }
  5515. if (pdfDataRangeTransport) {
  5516. if (!(pdfDataRangeTransport instanceof PDFDataRangeTransport)) {
  5517. // Not a PDFDataRangeTransport instance, trying to add missing properties.
  5518. pdfDataRangeTransport = Object.create(pdfDataRangeTransport);
  5519. pdfDataRangeTransport.length = src.length;
  5520. pdfDataRangeTransport.initialData = src.initialData;
  5521. if (!pdfDataRangeTransport.abort) {
  5522. pdfDataRangeTransport.abort = function () {};
  5523. }
  5524. }
  5525. src = Object.create(src);
  5526. src.range = pdfDataRangeTransport;
  5527. }
  5528. task.onPassword = passwordCallback || null;
  5529. task.onProgress = progressCallback || null;
  5530. var source;
  5531. if (typeof src === 'string') {
  5532. source = { url: src };
  5533. } else if (isArrayBuffer(src)) {
  5534. source = { data: src };
  5535. } else if (src instanceof PDFDataRangeTransport) {
  5536. source = { range: src };
  5537. } else {
  5538. if (typeof src !== 'object') {
  5539. error('Invalid parameter in getDocument, need either Uint8Array, ' +
  5540. 'string or a parameter object');
  5541. }
  5542. if (!src.url && !src.data && !src.range) {
  5543. error('Invalid parameter object: need either .data, .range or .url');
  5544. }
  5545. source = src;
  5546. }
  5547. var params = {};
  5548. var rangeTransport = null;
  5549. var worker = null;
  5550. for (var key in source) {
  5551. if (key === 'url' && typeof window !== 'undefined') {
  5552. // The full path is required in the 'url' field.
  5553. params[key] = combineUrl(window.location.href, source[key]);
  5554. continue;
  5555. } else if (key === 'range') {
  5556. rangeTransport = source[key];
  5557. continue;
  5558. } else if (key === 'worker') {
  5559. worker = source[key];
  5560. continue;
  5561. } else if (key === 'data' && !(source[key] instanceof Uint8Array)) {
  5562. // Converting string or array-like data to Uint8Array.
  5563. var pdfBytes = source[key];
  5564. if (typeof pdfBytes === 'string') {
  5565. params[key] = stringToBytes(pdfBytes);
  5566. } else if (typeof pdfBytes === 'object' && pdfBytes !== null &&
  5567. !isNaN(pdfBytes.length)) {
  5568. params[key] = new Uint8Array(pdfBytes);
  5569. } else if (isArrayBuffer(pdfBytes)) {
  5570. params[key] = new Uint8Array(pdfBytes);
  5571. } else {
  5572. error('Invalid PDF binary data: either typed array, string or ' +
  5573. 'array-like object is expected in the data property.');
  5574. }
  5575. continue;
  5576. }
  5577. params[key] = source[key];
  5578. }
  5579. params.rangeChunkSize = params.rangeChunkSize || DEFAULT_RANGE_CHUNK_SIZE;
  5580. if (!worker) {
  5581. // Worker was not provided -- creating and owning our own.
  5582. worker = new PDFWorker();
  5583. task._worker = worker;
  5584. }
  5585. var docId = task.docId;
  5586. worker.promise.then(function () {
  5587. if (task.destroyed) {
  5588. throw new Error('Loading aborted');
  5589. }
  5590. return _fetchDocument(worker, params, rangeTransport, docId).then(
  5591. function (workerId) {
  5592. if (task.destroyed) {
  5593. throw new Error('Loading aborted');
  5594. }
  5595. var messageHandler = new MessageHandler(docId, workerId, worker.port);
  5596. messageHandler.send('Ready', null);
  5597. var transport = new WorkerTransport(messageHandler, task, rangeTransport);
  5598. task._transport = transport;
  5599. });
  5600. }, task._capability.reject);
  5601. return task;
  5602. };
  5603. /**
  5604. * Starts fetching of specified PDF document/data.
  5605. * @param {PDFWorker} worker
  5606. * @param {Object} source
  5607. * @param {PDFDataRangeTransport} pdfDataRangeTransport
  5608. * @param {string} docId Unique document id, used as MessageHandler id.
  5609. * @returns {Promise} The promise, which is resolved when worker id of
  5610. * MessageHandler is known.
  5611. * @private
  5612. */
  5613. function _fetchDocument(worker, source, pdfDataRangeTransport, docId) {
  5614. if (worker.destroyed) {
  5615. return Promise.reject(new Error('Worker was destroyed'));
  5616. }
  5617. source.disableAutoFetch = PDFJS.disableAutoFetch;
  5618. source.disableStream = PDFJS.disableStream;
  5619. source.chunkedViewerLoading = !!pdfDataRangeTransport;
  5620. if (pdfDataRangeTransport) {
  5621. source.length = pdfDataRangeTransport.length;
  5622. source.initialData = pdfDataRangeTransport.initialData;
  5623. }
  5624. return worker.messageHandler.sendWithPromise('GetDocRequest', {
  5625. docId: docId,
  5626. source: source,
  5627. disableRange: PDFJS.disableRange,
  5628. maxImageSize: PDFJS.maxImageSize,
  5629. cMapUrl: PDFJS.cMapUrl,
  5630. cMapPacked: PDFJS.cMapPacked,
  5631. disableFontFace: PDFJS.disableFontFace,
  5632. disableCreateObjectURL: PDFJS.disableCreateObjectURL,
  5633. verbosity: PDFJS.verbosity
  5634. }).then(function (workerId) {
  5635. if (worker.destroyed) {
  5636. throw new Error('Worker was destroyed');
  5637. }
  5638. return workerId;
  5639. });
  5640. }
  5641. /**
  5642. * PDF document loading operation.
  5643. * @class
  5644. * @alias PDFDocumentLoadingTask
  5645. */
  5646. var PDFDocumentLoadingTask = (function PDFDocumentLoadingTaskClosure() {
  5647. var nextDocumentId = 0;
  5648. /** @constructs PDFDocumentLoadingTask */
  5649. function PDFDocumentLoadingTask() {
  5650. this._capability = createPromiseCapability();
  5651. this._transport = null;
  5652. this._worker = null;
  5653. /**
  5654. * Unique document loading task id -- used in MessageHandlers.
  5655. * @type {string}
  5656. */
  5657. this.docId = 'd' + (nextDocumentId++);
  5658. /**
  5659. * Shows if loading task is destroyed.
  5660. * @type {boolean}
  5661. */
  5662. this.destroyed = false;
  5663. /**
  5664. * Callback to request a password if wrong or no password was provided.
  5665. * The callback receives two parameters: function that needs to be called
  5666. * with new password and reason (see {PasswordResponses}).
  5667. */
  5668. this.onPassword = null;
  5669. /**
  5670. * Callback to be able to monitor the loading progress of the PDF file
  5671. * (necessary to implement e.g. a loading bar). The callback receives
  5672. * an {Object} with the properties: {number} loaded and {number} total.
  5673. */
  5674. this.onProgress = null;
  5675. /**
  5676. * Callback to when unsupported feature is used. The callback receives
  5677. * an {PDFJS.UNSUPPORTED_FEATURES} argument.
  5678. */
  5679. this.onUnsupportedFeature = null;
  5680. }
  5681. PDFDocumentLoadingTask.prototype =
  5682. /** @lends PDFDocumentLoadingTask.prototype */ {
  5683. /**
  5684. * @return {Promise}
  5685. */
  5686. get promise() {
  5687. return this._capability.promise;
  5688. },
  5689. /**
  5690. * Aborts all network requests and destroys worker.
  5691. * @return {Promise} A promise that is resolved after destruction activity
  5692. * is completed.
  5693. */
  5694. destroy: function () {
  5695. this.destroyed = true;
  5696. var transportDestroyed = !this._transport ? Promise.resolve() :
  5697. this._transport.destroy();
  5698. return transportDestroyed.then(function () {
  5699. this._transport = null;
  5700. if (this._worker) {
  5701. this._worker.destroy();
  5702. this._worker = null;
  5703. }
  5704. }.bind(this));
  5705. },
  5706. /**
  5707. * Registers callbacks to indicate the document loading completion.
  5708. *
  5709. * @param {function} onFulfilled The callback for the loading completion.
  5710. * @param {function} onRejected The callback for the loading failure.
  5711. * @return {Promise} A promise that is resolved after the onFulfilled or
  5712. * onRejected callback.
  5713. */
  5714. then: function PDFDocumentLoadingTask_then(onFulfilled, onRejected) {
  5715. return this.promise.then.apply(this.promise, arguments);
  5716. }
  5717. };
  5718. return PDFDocumentLoadingTask;
  5719. })();
  5720. /**
  5721. * Abstract class to support range requests file loading.
  5722. * @class
  5723. * @alias PDFJS.PDFDataRangeTransport
  5724. * @param {number} length
  5725. * @param {Uint8Array} initialData
  5726. */
  5727. var PDFDataRangeTransport = (function pdfDataRangeTransportClosure() {
  5728. function PDFDataRangeTransport(length, initialData) {
  5729. this.length = length;
  5730. this.initialData = initialData;
  5731. this._rangeListeners = [];
  5732. this._progressListeners = [];
  5733. this._progressiveReadListeners = [];
  5734. this._readyCapability = createPromiseCapability();
  5735. }
  5736. PDFDataRangeTransport.prototype =
  5737. /** @lends PDFDataRangeTransport.prototype */ {
  5738. addRangeListener:
  5739. function PDFDataRangeTransport_addRangeListener(listener) {
  5740. this._rangeListeners.push(listener);
  5741. },
  5742. addProgressListener:
  5743. function PDFDataRangeTransport_addProgressListener(listener) {
  5744. this._progressListeners.push(listener);
  5745. },
  5746. addProgressiveReadListener:
  5747. function PDFDataRangeTransport_addProgressiveReadListener(listener) {
  5748. this._progressiveReadListeners.push(listener);
  5749. },
  5750. onDataRange: function PDFDataRangeTransport_onDataRange(begin, chunk) {
  5751. var listeners = this._rangeListeners;
  5752. for (var i = 0, n = listeners.length; i < n; ++i) {
  5753. listeners[i](begin, chunk);
  5754. }
  5755. },
  5756. onDataProgress: function PDFDataRangeTransport_onDataProgress(loaded) {
  5757. this._readyCapability.promise.then(function () {
  5758. var listeners = this._progressListeners;
  5759. for (var i = 0, n = listeners.length; i < n; ++i) {
  5760. listeners[i](loaded);
  5761. }
  5762. }.bind(this));
  5763. },
  5764. onDataProgressiveRead:
  5765. function PDFDataRangeTransport_onDataProgress(chunk) {
  5766. this._readyCapability.promise.then(function () {
  5767. var listeners = this._progressiveReadListeners;
  5768. for (var i = 0, n = listeners.length; i < n; ++i) {
  5769. listeners[i](chunk);
  5770. }
  5771. }.bind(this));
  5772. },
  5773. transportReady: function PDFDataRangeTransport_transportReady() {
  5774. this._readyCapability.resolve();
  5775. },
  5776. requestDataRange:
  5777. function PDFDataRangeTransport_requestDataRange(begin, end) {
  5778. throw new Error('Abstract method PDFDataRangeTransport.requestDataRange');
  5779. },
  5780. abort: function PDFDataRangeTransport_abort() {
  5781. }
  5782. };
  5783. return PDFDataRangeTransport;
  5784. })();
  5785. PDFJS.PDFDataRangeTransport = PDFDataRangeTransport;
  5786. /**
  5787. * Proxy to a PDFDocument in the worker thread. Also, contains commonly used
  5788. * properties that can be read synchronously.
  5789. * @class
  5790. * @alias PDFDocumentProxy
  5791. */
  5792. var PDFDocumentProxy = (function PDFDocumentProxyClosure() {
  5793. function PDFDocumentProxy(pdfInfo, transport, loadingTask) {
  5794. this.pdfInfo = pdfInfo;
  5795. this.transport = transport;
  5796. this.loadingTask = loadingTask;
  5797. }
  5798. PDFDocumentProxy.prototype = /** @lends PDFDocumentProxy.prototype */ {
  5799. /**
  5800. * @return {number} Total number of pages the PDF contains.
  5801. */
  5802. get numPages() {
  5803. return this.pdfInfo.numPages;
  5804. },
  5805. /**
  5806. * @return {string} A unique ID to identify a PDF. Not guaranteed to be
  5807. * unique.
  5808. */
  5809. get fingerprint() {
  5810. return this.pdfInfo.fingerprint;
  5811. },
  5812. /**
  5813. * @param {number} pageNumber The page number to get. The first page is 1.
  5814. * @return {Promise} A promise that is resolved with a {@link PDFPageProxy}
  5815. * object.
  5816. */
  5817. getPage: function PDFDocumentProxy_getPage(pageNumber) {
  5818. return this.transport.getPage(pageNumber);
  5819. },
  5820. /**
  5821. * @param {{num: number, gen: number}} ref The page reference. Must have
  5822. * the 'num' and 'gen' properties.
  5823. * @return {Promise} A promise that is resolved with the page index that is
  5824. * associated with the reference.
  5825. */
  5826. getPageIndex: function PDFDocumentProxy_getPageIndex(ref) {
  5827. return this.transport.getPageIndex(ref);
  5828. },
  5829. /**
  5830. * @return {Promise} A promise that is resolved with a lookup table for
  5831. * mapping named destinations to reference numbers.
  5832. *
  5833. * This can be slow for large documents: use getDestination instead
  5834. */
  5835. getDestinations: function PDFDocumentProxy_getDestinations() {
  5836. return this.transport.getDestinations();
  5837. },
  5838. /**
  5839. * @param {string} id The named destination to get.
  5840. * @return {Promise} A promise that is resolved with all information
  5841. * of the given named destination.
  5842. */
  5843. getDestination: function PDFDocumentProxy_getDestination(id) {
  5844. return this.transport.getDestination(id);
  5845. },
  5846. /**
  5847. * @return {Promise} A promise that is resolved with a lookup table for
  5848. * mapping named attachments to their content.
  5849. */
  5850. getAttachments: function PDFDocumentProxy_getAttachments() {
  5851. return this.transport.getAttachments();
  5852. },
  5853. /**
  5854. * @return {Promise} A promise that is resolved with an array of all the
  5855. * JavaScript strings in the name tree.
  5856. */
  5857. getJavaScript: function PDFDocumentProxy_getJavaScript() {
  5858. return this.transport.getJavaScript();
  5859. },
  5860. /**
  5861. * @return {Promise} A promise that is resolved with an {Array} that is a
  5862. * tree outline (if it has one) of the PDF. The tree is in the format of:
  5863. * [
  5864. * {
  5865. * title: string,
  5866. * bold: boolean,
  5867. * italic: boolean,
  5868. * color: rgb array,
  5869. * dest: dest obj,
  5870. * items: array of more items like this
  5871. * },
  5872. * ...
  5873. * ].
  5874. */
  5875. getOutline: function PDFDocumentProxy_getOutline() {
  5876. return this.transport.getOutline();
  5877. },
  5878. /**
  5879. * @return {Promise} A promise that is resolved with an {Object} that has
  5880. * info and metadata properties. Info is an {Object} filled with anything
  5881. * available in the information dictionary and similarly metadata is a
  5882. * {Metadata} object with information from the metadata section of the PDF.
  5883. */
  5884. getMetadata: function PDFDocumentProxy_getMetadata() {
  5885. return this.transport.getMetadata();
  5886. },
  5887. /**
  5888. * @return {Promise} A promise that is resolved with a TypedArray that has
  5889. * the raw data from the PDF.
  5890. */
  5891. getData: function PDFDocumentProxy_getData() {
  5892. return this.transport.getData();
  5893. },
  5894. /**
  5895. * @return {Promise} A promise that is resolved when the document's data
  5896. * is loaded. It is resolved with an {Object} that contains the length
  5897. * property that indicates size of the PDF data in bytes.
  5898. */
  5899. getDownloadInfo: function PDFDocumentProxy_getDownloadInfo() {
  5900. return this.transport.downloadInfoCapability.promise;
  5901. },
  5902. /**
  5903. * @return {Promise} A promise this is resolved with current stats about
  5904. * document structures (see {@link PDFDocumentStats}).
  5905. */
  5906. getStats: function PDFDocumentProxy_getStats() {
  5907. return this.transport.getStats();
  5908. },
  5909. /**
  5910. * Cleans up resources allocated by the document, e.g. created @font-face.
  5911. */
  5912. cleanup: function PDFDocumentProxy_cleanup() {
  5913. this.transport.startCleanup();
  5914. },
  5915. /**
  5916. * Destroys current document instance and terminates worker.
  5917. */
  5918. destroy: function PDFDocumentProxy_destroy() {
  5919. return this.loadingTask.destroy();
  5920. }
  5921. };
  5922. return PDFDocumentProxy;
  5923. })();
  5924. /**
  5925. * Page getTextContent parameters.
  5926. *
  5927. * @typedef {Object} getTextContentParameters
  5928. * @param {boolean} normalizeWhitespace - replaces all occurrences of
  5929. * whitespace with standard spaces (0x20). The default value is `false`.
  5930. */
  5931. /**
  5932. * Page text content.
  5933. *
  5934. * @typedef {Object} TextContent
  5935. * @property {array} items - array of {@link TextItem}
  5936. * @property {Object} styles - {@link TextStyles} objects, indexed by font
  5937. * name.
  5938. */
  5939. /**
  5940. * Page text content part.
  5941. *
  5942. * @typedef {Object} TextItem
  5943. * @property {string} str - text content.
  5944. * @property {string} dir - text direction: 'ttb', 'ltr' or 'rtl'.
  5945. * @property {array} transform - transformation matrix.
  5946. * @property {number} width - width in device space.
  5947. * @property {number} height - height in device space.
  5948. * @property {string} fontName - font name used by pdf.js for converted font.
  5949. */
  5950. /**
  5951. * Text style.
  5952. *
  5953. * @typedef {Object} TextStyle
  5954. * @property {number} ascent - font ascent.
  5955. * @property {number} descent - font descent.
  5956. * @property {boolean} vertical - text is in vertical mode.
  5957. * @property {string} fontFamily - possible font family
  5958. */
  5959. /**
  5960. * Page annotation parameters.
  5961. *
  5962. * @typedef {Object} GetAnnotationsParameters
  5963. * @param {string} intent - Determines the annotations that will be fetched,
  5964. * can be either 'display' (viewable annotations) or 'print'
  5965. * (printable annotations).
  5966. * If the parameter is omitted, all annotations are fetched.
  5967. */
  5968. /**
  5969. * Page render parameters.
  5970. *
  5971. * @typedef {Object} RenderParameters
  5972. * @property {Object} canvasContext - A 2D context of a DOM Canvas object.
  5973. * @property {PDFJS.PageViewport} viewport - Rendering viewport obtained by
  5974. * calling of PDFPage.getViewport method.
  5975. * @property {string} intent - Rendering intent, can be 'display' or 'print'
  5976. * (default value is 'display').
  5977. * @property {Array} transform - (optional) Additional transform, applied
  5978. * just before viewport transform.
  5979. * @property {Object} imageLayer - (optional) An object that has beginLayout,
  5980. * endLayout and appendImage functions.
  5981. * @property {function} continueCallback - (deprecated) A function that will be
  5982. * called each time the rendering is paused. To continue
  5983. * rendering call the function that is the first argument
  5984. * to the callback.
  5985. */
  5986. /**
  5987. * PDF page operator list.
  5988. *
  5989. * @typedef {Object} PDFOperatorList
  5990. * @property {Array} fnArray - Array containing the operator functions.
  5991. * @property {Array} argsArray - Array containing the arguments of the
  5992. * functions.
  5993. */
  5994. /**
  5995. * Proxy to a PDFPage in the worker thread.
  5996. * @class
  5997. * @alias PDFPageProxy
  5998. */
  5999. var PDFPageProxy = (function PDFPageProxyClosure() {
  6000. function PDFPageProxy(pageIndex, pageInfo, transport) {
  6001. this.pageIndex = pageIndex;
  6002. this.pageInfo = pageInfo;
  6003. this.transport = transport;
  6004. this.stats = new StatTimer();
  6005. this.stats.enabled = !!globalScope.PDFJS.enableStats;
  6006. this.commonObjs = transport.commonObjs;
  6007. this.objs = new PDFObjects();
  6008. this.cleanupAfterRender = false;
  6009. this.pendingCleanup = false;
  6010. this.intentStates = {};
  6011. this.destroyed = false;
  6012. }
  6013. PDFPageProxy.prototype = /** @lends PDFPageProxy.prototype */ {
  6014. /**
  6015. * @return {number} Page number of the page. First page is 1.
  6016. */
  6017. get pageNumber() {
  6018. return this.pageIndex + 1;
  6019. },
  6020. /**
  6021. * @return {number} The number of degrees the page is rotated clockwise.
  6022. */
  6023. get rotate() {
  6024. return this.pageInfo.rotate;
  6025. },
  6026. /**
  6027. * @return {Object} The reference that points to this page. It has 'num' and
  6028. * 'gen' properties.
  6029. */
  6030. get ref() {
  6031. return this.pageInfo.ref;
  6032. },
  6033. /**
  6034. * @return {Array} An array of the visible portion of the PDF page in the
  6035. * user space units - [x1, y1, x2, y2].
  6036. */
  6037. get view() {
  6038. return this.pageInfo.view;
  6039. },
  6040. /**
  6041. * @param {number} scale The desired scale of the viewport.
  6042. * @param {number} rotate Degrees to rotate the viewport. If omitted this
  6043. * defaults to the page rotation.
  6044. * @return {PDFJS.PageViewport} Contains 'width' and 'height' properties
  6045. * along with transforms required for rendering.
  6046. */
  6047. getViewport: function PDFPageProxy_getViewport(scale, rotate) {
  6048. if (arguments.length < 2) {
  6049. rotate = this.rotate;
  6050. }
  6051. return new PDFJS.PageViewport(this.view, scale, rotate, 0, 0);
  6052. },
  6053. /**
  6054. * @param {GetAnnotationsParameters} params - Annotation parameters.
  6055. * @return {Promise} A promise that is resolved with an {Array} of the
  6056. * annotation objects.
  6057. */
  6058. getAnnotations: function PDFPageProxy_getAnnotations(params) {
  6059. var intent = (params && params.intent) || null;
  6060. if (!this.annotationsPromise || this.annotationsIntent !== intent) {
  6061. this.annotationsPromise = this.transport.getAnnotations(this.pageIndex,
  6062. intent);
  6063. this.annotationsIntent = intent;
  6064. }
  6065. return this.annotationsPromise;
  6066. },
  6067. /**
  6068. * Begins the process of rendering a page to the desired context.
  6069. * @param {RenderParameters} params Page render parameters.
  6070. * @return {RenderTask} An object that contains the promise, which
  6071. * is resolved when the page finishes rendering.
  6072. */
  6073. render: function PDFPageProxy_render(params) {
  6074. var stats = this.stats;
  6075. stats.time('Overall');
  6076. // If there was a pending destroy cancel it so no cleanup happens during
  6077. // this call to render.
  6078. this.pendingCleanup = false;
  6079. var renderingIntent = (params.intent === 'print' ? 'print' : 'display');
  6080. if (!this.intentStates[renderingIntent]) {
  6081. this.intentStates[renderingIntent] = {};
  6082. }
  6083. var intentState = this.intentStates[renderingIntent];
  6084. // If there's no displayReadyCapability yet, then the operatorList
  6085. // was never requested before. Make the request and create the promise.
  6086. if (!intentState.displayReadyCapability) {
  6087. intentState.receivingOperatorList = true;
  6088. intentState.displayReadyCapability = createPromiseCapability();
  6089. intentState.operatorList = {
  6090. fnArray: [],
  6091. argsArray: [],
  6092. lastChunk: false
  6093. };
  6094. this.stats.time('Page Request');
  6095. this.transport.messageHandler.send('RenderPageRequest', {
  6096. pageIndex: this.pageNumber - 1,
  6097. intent: renderingIntent
  6098. });
  6099. }
  6100. var internalRenderTask = new InternalRenderTask(complete, params,
  6101. this.objs,
  6102. this.commonObjs,
  6103. intentState.operatorList,
  6104. this.pageNumber);
  6105. internalRenderTask.useRequestAnimationFrame = renderingIntent !== 'print';
  6106. if (!intentState.renderTasks) {
  6107. intentState.renderTasks = [];
  6108. }
  6109. intentState.renderTasks.push(internalRenderTask);
  6110. var renderTask = internalRenderTask.task;
  6111. // Obsolete parameter support
  6112. if (params.continueCallback) {
  6113. deprecated('render is used with continueCallback parameter');
  6114. renderTask.onContinue = params.continueCallback;
  6115. }
  6116. var self = this;
  6117. intentState.displayReadyCapability.promise.then(
  6118. function pageDisplayReadyPromise(transparency) {
  6119. if (self.pendingCleanup) {
  6120. complete();
  6121. return;
  6122. }
  6123. stats.time('Rendering');
  6124. internalRenderTask.initalizeGraphics(transparency);
  6125. internalRenderTask.operatorListChanged();
  6126. },
  6127. function pageDisplayReadPromiseError(reason) {
  6128. complete(reason);
  6129. }
  6130. );
  6131. function complete(error) {
  6132. var i = intentState.renderTasks.indexOf(internalRenderTask);
  6133. if (i >= 0) {
  6134. intentState.renderTasks.splice(i, 1);
  6135. }
  6136. if (self.cleanupAfterRender) {
  6137. self.pendingCleanup = true;
  6138. }
  6139. self._tryCleanup();
  6140. if (error) {
  6141. internalRenderTask.capability.reject(error);
  6142. } else {
  6143. internalRenderTask.capability.resolve();
  6144. }
  6145. stats.timeEnd('Rendering');
  6146. stats.timeEnd('Overall');
  6147. }
  6148. return renderTask;
  6149. },
  6150. /**
  6151. * @return {Promise} A promise resolved with an {@link PDFOperatorList}
  6152. * object that represents page's operator list.
  6153. */
  6154. getOperatorList: function PDFPageProxy_getOperatorList() {
  6155. function operatorListChanged() {
  6156. if (intentState.operatorList.lastChunk) {
  6157. intentState.opListReadCapability.resolve(intentState.operatorList);
  6158. }
  6159. }
  6160. var renderingIntent = 'oplist';
  6161. if (!this.intentStates[renderingIntent]) {
  6162. this.intentStates[renderingIntent] = {};
  6163. }
  6164. var intentState = this.intentStates[renderingIntent];
  6165. if (!intentState.opListReadCapability) {
  6166. var opListTask = {};
  6167. opListTask.operatorListChanged = operatorListChanged;
  6168. intentState.receivingOperatorList = true;
  6169. intentState.opListReadCapability = createPromiseCapability();
  6170. intentState.renderTasks = [];
  6171. intentState.renderTasks.push(opListTask);
  6172. intentState.operatorList = {
  6173. fnArray: [],
  6174. argsArray: [],
  6175. lastChunk: false
  6176. };
  6177. this.transport.messageHandler.send('RenderPageRequest', {
  6178. pageIndex: this.pageIndex,
  6179. intent: renderingIntent
  6180. });
  6181. }
  6182. return intentState.opListReadCapability.promise;
  6183. },
  6184. /**
  6185. * @param {getTextContentParameters} params - getTextContent parameters.
  6186. * @return {Promise} That is resolved a {@link TextContent}
  6187. * object that represent the page text content.
  6188. */
  6189. getTextContent: function PDFPageProxy_getTextContent(params) {
  6190. var normalizeWhitespace = (params && params.normalizeWhitespace) || false;
  6191. return this.transport.messageHandler.sendWithPromise('GetTextContent', {
  6192. pageIndex: this.pageNumber - 1,
  6193. normalizeWhitespace: normalizeWhitespace,
  6194. });
  6195. },
  6196. /**
  6197. * Destroys page object.
  6198. */
  6199. _destroy: function PDFPageProxy_destroy() {
  6200. this.destroyed = true;
  6201. this.transport.pageCache[this.pageIndex] = null;
  6202. var waitOn = [];
  6203. Object.keys(this.intentStates).forEach(function(intent) {
  6204. var intentState = this.intentStates[intent];
  6205. intentState.renderTasks.forEach(function(renderTask) {
  6206. var renderCompleted = renderTask.capability.promise.
  6207. catch(function () {}); // ignoring failures
  6208. waitOn.push(renderCompleted);
  6209. renderTask.cancel();
  6210. });
  6211. }, this);
  6212. this.objs.clear();
  6213. this.annotationsPromise = null;
  6214. this.pendingCleanup = false;
  6215. return Promise.all(waitOn);
  6216. },
  6217. /**
  6218. * Cleans up resources allocated by the page. (deprecated)
  6219. */
  6220. destroy: function() {
  6221. deprecated('page destroy method, use cleanup() instead');
  6222. this.cleanup();
  6223. },
  6224. /**
  6225. * Cleans up resources allocated by the page.
  6226. */
  6227. cleanup: function PDFPageProxy_cleanup() {
  6228. this.pendingCleanup = true;
  6229. this._tryCleanup();
  6230. },
  6231. /**
  6232. * For internal use only. Attempts to clean up if rendering is in a state
  6233. * where that's possible.
  6234. * @ignore
  6235. */
  6236. _tryCleanup: function PDFPageProxy_tryCleanup() {
  6237. if (!this.pendingCleanup ||
  6238. Object.keys(this.intentStates).some(function(intent) {
  6239. var intentState = this.intentStates[intent];
  6240. return (intentState.renderTasks.length !== 0 ||
  6241. intentState.receivingOperatorList);
  6242. }, this)) {
  6243. return;
  6244. }
  6245. Object.keys(this.intentStates).forEach(function(intent) {
  6246. delete this.intentStates[intent];
  6247. }, this);
  6248. this.objs.clear();
  6249. this.annotationsPromise = null;
  6250. this.pendingCleanup = false;
  6251. },
  6252. /**
  6253. * For internal use only.
  6254. * @ignore
  6255. */
  6256. _startRenderPage: function PDFPageProxy_startRenderPage(transparency,
  6257. intent) {
  6258. var intentState = this.intentStates[intent];
  6259. // TODO Refactor RenderPageRequest to separate rendering
  6260. // and operator list logic
  6261. if (intentState.displayReadyCapability) {
  6262. intentState.displayReadyCapability.resolve(transparency);
  6263. }
  6264. },
  6265. /**
  6266. * For internal use only.
  6267. * @ignore
  6268. */
  6269. _renderPageChunk: function PDFPageProxy_renderPageChunk(operatorListChunk,
  6270. intent) {
  6271. var intentState = this.intentStates[intent];
  6272. var i, ii;
  6273. // Add the new chunk to the current operator list.
  6274. for (i = 0, ii = operatorListChunk.length; i < ii; i++) {
  6275. intentState.operatorList.fnArray.push(operatorListChunk.fnArray[i]);
  6276. intentState.operatorList.argsArray.push(
  6277. operatorListChunk.argsArray[i]);
  6278. }
  6279. intentState.operatorList.lastChunk = operatorListChunk.lastChunk;
  6280. // Notify all the rendering tasks there are more operators to be consumed.
  6281. for (i = 0; i < intentState.renderTasks.length; i++) {
  6282. intentState.renderTasks[i].operatorListChanged();
  6283. }
  6284. if (operatorListChunk.lastChunk) {
  6285. intentState.receivingOperatorList = false;
  6286. this._tryCleanup();
  6287. }
  6288. }
  6289. };
  6290. return PDFPageProxy;
  6291. })();
  6292. /**
  6293. * PDF.js web worker abstraction, it controls instantiation of PDF documents and
  6294. * WorkerTransport for them. If creation of a web worker is not possible,
  6295. * a "fake" worker will be used instead.
  6296. * @class
  6297. */
  6298. var PDFWorker = (function PDFWorkerClosure() {
  6299. var nextFakeWorkerId = 0;
  6300. // Loads worker code into main thread.
  6301. function setupFakeWorkerGlobal() {
  6302. if (!PDFJS.fakeWorkerFilesLoadedCapability) {
  6303. PDFJS.fakeWorkerFilesLoadedCapability = createPromiseCapability();
  6304. // In the developer build load worker_loader which in turn loads all the
  6305. // other files and resolves the promise. In production only the
  6306. // pdf.worker.js file is needed.
  6307. PDFJS.fakeWorkerFilesLoadedCapability.resolve();
  6308. }
  6309. return PDFJS.fakeWorkerFilesLoadedCapability.promise;
  6310. }
  6311. function PDFWorker(name) {
  6312. this.name = name;
  6313. this.destroyed = false;
  6314. this._readyCapability = createPromiseCapability();
  6315. this._port = null;
  6316. this._webWorker = null;
  6317. this._messageHandler = null;
  6318. this._initialize();
  6319. }
  6320. PDFWorker.prototype = /** @lends PDFWorker.prototype */ {
  6321. get promise() {
  6322. return this._readyCapability.promise;
  6323. },
  6324. get port() {
  6325. return this._port;
  6326. },
  6327. get messageHandler() {
  6328. return this._messageHandler;
  6329. },
  6330. _initialize: function PDFWorker_initialize() {
  6331. // If worker support isn't disabled explicit and the browser has worker
  6332. // support, create a new web worker and test if it/the browser fullfills
  6333. // all requirements to run parts of pdf.js in a web worker.
  6334. // Right now, the requirement is, that an Uint8Array is still an
  6335. // Uint8Array as it arrives on the worker. (Chrome added this with v.15.)
  6336. // Either workers are disabled, not supported or have thrown an exception.
  6337. // Thus, we fallback to a faked worker.
  6338. this._setupFakeWorker();
  6339. },
  6340. _setupFakeWorker: function PDFWorker_setupFakeWorker() {
  6341. warn('Setting up fake worker.');
  6342. globalScope.PDFJS.disableWorker = true;
  6343. setupFakeWorkerGlobal().then(function () {
  6344. if (this.destroyed) {
  6345. this._readyCapability.reject(new Error('Worker was destroyed'));
  6346. return;
  6347. }
  6348. // If we don't use a worker, just post/sendMessage to the main thread.
  6349. var port = {
  6350. _listeners: [],
  6351. postMessage: function (obj) {
  6352. var e = {data: obj};
  6353. this._listeners.forEach(function (listener) {
  6354. listener.call(this, e);
  6355. }, this);
  6356. },
  6357. addEventListener: function (name, listener) {
  6358. this._listeners.push(listener);
  6359. },
  6360. removeEventListener: function (name, listener) {
  6361. var i = this._listeners.indexOf(listener);
  6362. this._listeners.splice(i, 1);
  6363. },
  6364. terminate: function () {}
  6365. };
  6366. this._port = port;
  6367. // All fake workers use the same port, making id unique.
  6368. var id = 'fake' + (nextFakeWorkerId++);
  6369. // If the main thread is our worker, setup the handling for the
  6370. // messages -- the main thread sends to it self.
  6371. var workerHandler = new MessageHandler(id + '_worker', id, port);
  6372. PDFJS.WorkerMessageHandler.setup(workerHandler, port);
  6373. var messageHandler = new MessageHandler(id, id + '_worker', port);
  6374. this._messageHandler = messageHandler;
  6375. this._readyCapability.resolve();
  6376. }.bind(this));
  6377. },
  6378. /**
  6379. * Destroys the worker instance.
  6380. */
  6381. destroy: function PDFWorker_destroy() {
  6382. this.destroyed = true;
  6383. if (this._webWorker) {
  6384. // We need to terminate only web worker created resource.
  6385. this._webWorker.terminate();
  6386. this._webWorker = null;
  6387. }
  6388. this._port = null;
  6389. if (this._messageHandler) {
  6390. this._messageHandler.destroy();
  6391. this._messageHandler = null;
  6392. }
  6393. }
  6394. };
  6395. return PDFWorker;
  6396. })();
  6397. PDFJS.PDFWorker = PDFWorker;
  6398. /**
  6399. * For internal use only.
  6400. * @ignore
  6401. */
  6402. var WorkerTransport = (function WorkerTransportClosure() {
  6403. function WorkerTransport(messageHandler, loadingTask, pdfDataRangeTransport) {
  6404. this.messageHandler = messageHandler;
  6405. this.loadingTask = loadingTask;
  6406. this.pdfDataRangeTransport = pdfDataRangeTransport;
  6407. this.commonObjs = new PDFObjects();
  6408. this.fontLoader = new FontLoader(loadingTask.docId);
  6409. this.destroyed = false;
  6410. this.destroyCapability = null;
  6411. this.pageCache = [];
  6412. this.pagePromises = [];
  6413. this.downloadInfoCapability = createPromiseCapability();
  6414. this.setupMessageHandler();
  6415. }
  6416. WorkerTransport.prototype = {
  6417. destroy: function WorkerTransport_destroy() {
  6418. if (this.destroyCapability) {
  6419. return this.destroyCapability.promise;
  6420. }
  6421. this.destroyed = true;
  6422. this.destroyCapability = createPromiseCapability();
  6423. var waitOn = [];
  6424. // We need to wait for all renderings to be completed, e.g.
  6425. // timeout/rAF can take a long time.
  6426. this.pageCache.forEach(function (page) {
  6427. if (page) {
  6428. waitOn.push(page._destroy());
  6429. }
  6430. });
  6431. this.pageCache = [];
  6432. this.pagePromises = [];
  6433. var self = this;
  6434. // We also need to wait for the worker to finish its long running tasks.
  6435. var terminated = this.messageHandler.sendWithPromise('Terminate', null);
  6436. waitOn.push(terminated);
  6437. Promise.all(waitOn).then(function () {
  6438. self.fontLoader.clear();
  6439. if (self.pdfDataRangeTransport) {
  6440. self.pdfDataRangeTransport.abort();
  6441. self.pdfDataRangeTransport = null;
  6442. }
  6443. if (self.messageHandler) {
  6444. self.messageHandler.destroy();
  6445. self.messageHandler = null;
  6446. }
  6447. self.destroyCapability.resolve();
  6448. }, this.destroyCapability.reject);
  6449. return this.destroyCapability.promise;
  6450. },
  6451. setupMessageHandler:
  6452. function WorkerTransport_setupMessageHandler() {
  6453. var messageHandler = this.messageHandler;
  6454. function updatePassword(password) {
  6455. messageHandler.send('UpdatePassword', password);
  6456. }
  6457. var pdfDataRangeTransport = this.pdfDataRangeTransport;
  6458. if (pdfDataRangeTransport) {
  6459. pdfDataRangeTransport.addRangeListener(function(begin, chunk) {
  6460. messageHandler.send('OnDataRange', {
  6461. begin: begin,
  6462. chunk: chunk
  6463. });
  6464. });
  6465. pdfDataRangeTransport.addProgressListener(function(loaded) {
  6466. messageHandler.send('OnDataProgress', {
  6467. loaded: loaded
  6468. });
  6469. });
  6470. pdfDataRangeTransport.addProgressiveReadListener(function(chunk) {
  6471. messageHandler.send('OnDataRange', {
  6472. chunk: chunk
  6473. });
  6474. });
  6475. messageHandler.on('RequestDataRange',
  6476. function transportDataRange(data) {
  6477. pdfDataRangeTransport.requestDataRange(data.begin, data.end);
  6478. }, this);
  6479. }
  6480. messageHandler.on('GetDoc', function transportDoc(data) {
  6481. var pdfInfo = data.pdfInfo;
  6482. this.numPages = data.pdfInfo.numPages;
  6483. var loadingTask = this.loadingTask;
  6484. var pdfDocument = new PDFDocumentProxy(pdfInfo, this, loadingTask);
  6485. this.pdfDocument = pdfDocument;
  6486. loadingTask._capability.resolve(pdfDocument);
  6487. }, this);
  6488. messageHandler.on('NeedPassword',
  6489. function transportNeedPassword(exception) {
  6490. var loadingTask = this.loadingTask;
  6491. if (loadingTask.onPassword) {
  6492. return loadingTask.onPassword(updatePassword,
  6493. PasswordResponses.NEED_PASSWORD);
  6494. }
  6495. loadingTask._capability.reject(
  6496. new PasswordException(exception.message, exception.code));
  6497. }, this);
  6498. messageHandler.on('IncorrectPassword',
  6499. function transportIncorrectPassword(exception) {
  6500. var loadingTask = this.loadingTask;
  6501. if (loadingTask.onPassword) {
  6502. return loadingTask.onPassword(updatePassword,
  6503. PasswordResponses.INCORRECT_PASSWORD);
  6504. }
  6505. loadingTask._capability.reject(
  6506. new PasswordException(exception.message, exception.code));
  6507. }, this);
  6508. messageHandler.on('InvalidPDF', function transportInvalidPDF(exception) {
  6509. this.loadingTask._capability.reject(
  6510. new InvalidPDFException(exception.message));
  6511. }, this);
  6512. messageHandler.on('MissingPDF', function transportMissingPDF(exception) {
  6513. this.loadingTask._capability.reject(
  6514. new MissingPDFException(exception.message));
  6515. }, this);
  6516. messageHandler.on('UnexpectedResponse',
  6517. function transportUnexpectedResponse(exception) {
  6518. this.loadingTask._capability.reject(
  6519. new UnexpectedResponseException(exception.message, exception.status));
  6520. }, this);
  6521. messageHandler.on('UnknownError',
  6522. function transportUnknownError(exception) {
  6523. this.loadingTask._capability.reject(
  6524. new UnknownErrorException(exception.message, exception.details));
  6525. }, this);
  6526. messageHandler.on('DataLoaded', function transportPage(data) {
  6527. this.downloadInfoCapability.resolve(data);
  6528. }, this);
  6529. messageHandler.on('PDFManagerReady', function transportPage(data) {
  6530. if (this.pdfDataRangeTransport) {
  6531. this.pdfDataRangeTransport.transportReady();
  6532. }
  6533. }, this);
  6534. messageHandler.on('StartRenderPage', function transportRender(data) {
  6535. if (this.destroyed) {
  6536. return; // Ignore any pending requests if the worker was terminated.
  6537. }
  6538. var page = this.pageCache[data.pageIndex];
  6539. page.stats.timeEnd('Page Request');
  6540. page._startRenderPage(data.transparency, data.intent);
  6541. }, this);
  6542. messageHandler.on('RenderPageChunk', function transportRender(data) {
  6543. if (this.destroyed) {
  6544. return; // Ignore any pending requests if the worker was terminated.
  6545. }
  6546. var page = this.pageCache[data.pageIndex];
  6547. page._renderPageChunk(data.operatorList, data.intent);
  6548. }, this);
  6549. messageHandler.on('commonobj', function transportObj(data) {
  6550. if (this.destroyed) {
  6551. return; // Ignore any pending requests if the worker was terminated.
  6552. }
  6553. var id = data[0];
  6554. var type = data[1];
  6555. if (this.commonObjs.hasData(id)) {
  6556. return;
  6557. }
  6558. switch (type) {
  6559. case 'Font':
  6560. var exportedData = data[2];
  6561. var font;
  6562. if ('error' in exportedData) {
  6563. var error = exportedData.error;
  6564. warn('Error during font loading: ' + error);
  6565. this.commonObjs.resolve(id, error);
  6566. break;
  6567. } else {
  6568. font = new FontFaceObject(exportedData);
  6569. }
  6570. this.fontLoader.bind(
  6571. [font],
  6572. function fontReady(fontObjs) {
  6573. this.commonObjs.resolve(id, font);
  6574. }.bind(this)
  6575. );
  6576. break;
  6577. case 'FontPath':
  6578. this.commonObjs.resolve(id, data[2]);
  6579. break;
  6580. default:
  6581. error('Got unknown common object type ' + type);
  6582. }
  6583. }, this);
  6584. messageHandler.on('obj', function transportObj(data) {
  6585. if (this.destroyed) {
  6586. return; // Ignore any pending requests if the worker was terminated.
  6587. }
  6588. var id = data[0];
  6589. var pageIndex = data[1];
  6590. var type = data[2];
  6591. var pageProxy = this.pageCache[pageIndex];
  6592. var imageData;
  6593. if (pageProxy.objs.hasData(id)) {
  6594. return;
  6595. }
  6596. switch (type) {
  6597. case 'JpegStream':
  6598. imageData = data[3];
  6599. loadJpegStream(id, imageData, pageProxy.objs);
  6600. break;
  6601. case 'Image':
  6602. imageData = data[3];
  6603. pageProxy.objs.resolve(id, imageData);
  6604. // heuristics that will allow not to store large data
  6605. var MAX_IMAGE_SIZE_TO_STORE = 8000000;
  6606. if (imageData && 'data' in imageData &&
  6607. imageData.data.length > MAX_IMAGE_SIZE_TO_STORE) {
  6608. pageProxy.cleanupAfterRender = true;
  6609. }
  6610. break;
  6611. default:
  6612. error('Got unknown object type ' + type);
  6613. }
  6614. }, this);
  6615. messageHandler.on('DocProgress', function transportDocProgress(data) {
  6616. if (this.destroyed) {
  6617. return; // Ignore any pending requests if the worker was terminated.
  6618. }
  6619. var loadingTask = this.loadingTask;
  6620. if (loadingTask.onProgress) {
  6621. loadingTask.onProgress({
  6622. loaded: data.loaded,
  6623. total: data.total
  6624. });
  6625. }
  6626. }, this);
  6627. messageHandler.on('PageError', function transportError(data) {
  6628. if (this.destroyed) {
  6629. return; // Ignore any pending requests if the worker was terminated.
  6630. }
  6631. var page = this.pageCache[data.pageNum - 1];
  6632. var intentState = page.intentStates[data.intent];
  6633. if (intentState.displayReadyCapability) {
  6634. intentState.displayReadyCapability.reject(data.error);
  6635. } else {
  6636. error(data.error);
  6637. }
  6638. }, this);
  6639. messageHandler.on('UnsupportedFeature',
  6640. function transportUnsupportedFeature(data) {
  6641. if (this.destroyed) {
  6642. return; // Ignore any pending requests if the worker was terminated.
  6643. }
  6644. var featureId = data.featureId;
  6645. var loadingTask = this.loadingTask;
  6646. if (loadingTask.onUnsupportedFeature) {
  6647. loadingTask.onUnsupportedFeature(featureId);
  6648. }
  6649. PDFJS.UnsupportedManager.notify(featureId);
  6650. }, this);
  6651. messageHandler.on('JpegDecode', function(data) {
  6652. if (this.destroyed) {
  6653. return Promise.reject('Worker was terminated');
  6654. }
  6655. var imageUrl = data[0];
  6656. var components = data[1];
  6657. if (components !== 3 && components !== 1) {
  6658. return Promise.reject(
  6659. new Error('Only 3 components or 1 component can be returned'));
  6660. }
  6661. return new Promise(function (resolve, reject) {
  6662. var img = new Image();
  6663. img.onload = function () {
  6664. var width = img.width;
  6665. var height = img.height;
  6666. var size = width * height;
  6667. var rgbaLength = size * 4;
  6668. var buf = new Uint8Array(size * components);
  6669. var tmpCanvas = createScratchCanvas(width, height);
  6670. var tmpCtx = tmpCanvas.getContext('2d');
  6671. tmpCtx.drawImage(img, 0, 0);
  6672. var data = tmpCtx.getImageData(0, 0, width, height).data;
  6673. var i, j;
  6674. if (components === 3) {
  6675. for (i = 0, j = 0; i < rgbaLength; i += 4, j += 3) {
  6676. buf[j] = data[i];
  6677. buf[j + 1] = data[i + 1];
  6678. buf[j + 2] = data[i + 2];
  6679. }
  6680. } else if (components === 1) {
  6681. for (i = 0, j = 0; i < rgbaLength; i += 4, j++) {
  6682. buf[j] = data[i];
  6683. }
  6684. }
  6685. resolve({ data: buf, width: width, height: height});
  6686. };
  6687. img.onerror = function () {
  6688. reject(new Error('JpegDecode failed to load image'));
  6689. };
  6690. img.src = imageUrl;
  6691. });
  6692. }, this);
  6693. },
  6694. getData: function WorkerTransport_getData() {
  6695. return this.messageHandler.sendWithPromise('GetData', null);
  6696. },
  6697. getPage: function WorkerTransport_getPage(pageNumber, capability) {
  6698. if (pageNumber <= 0 || pageNumber > this.numPages ||
  6699. (pageNumber|0) !== pageNumber) {
  6700. return Promise.reject(new Error('Invalid page request'));
  6701. }
  6702. var pageIndex = pageNumber - 1;
  6703. if (pageIndex in this.pagePromises) {
  6704. return this.pagePromises[pageIndex];
  6705. }
  6706. var promise = this.messageHandler.sendWithPromise('GetPage', {
  6707. pageIndex: pageIndex
  6708. }).then(function (pageInfo) {
  6709. if (this.destroyed) {
  6710. throw new Error('Transport destroyed');
  6711. }
  6712. var page = new PDFPageProxy(pageIndex, pageInfo, this);
  6713. this.pageCache[pageIndex] = page;
  6714. return page;
  6715. }.bind(this));
  6716. this.pagePromises[pageIndex] = promise;
  6717. return promise;
  6718. },
  6719. getPageIndex: function WorkerTransport_getPageIndexByRef(ref) {
  6720. return this.messageHandler.sendWithPromise('GetPageIndex', { ref: ref });
  6721. },
  6722. getAnnotations: function WorkerTransport_getAnnotations(pageIndex, intent) {
  6723. return this.messageHandler.sendWithPromise('GetAnnotations', {
  6724. pageIndex: pageIndex,
  6725. intent: intent,
  6726. });
  6727. },
  6728. getDestinations: function WorkerTransport_getDestinations() {
  6729. return this.messageHandler.sendWithPromise('GetDestinations', null);
  6730. },
  6731. getDestination: function WorkerTransport_getDestination(id) {
  6732. return this.messageHandler.sendWithPromise('GetDestination', { id: id });
  6733. },
  6734. getAttachments: function WorkerTransport_getAttachments() {
  6735. return this.messageHandler.sendWithPromise('GetAttachments', null);
  6736. },
  6737. getJavaScript: function WorkerTransport_getJavaScript() {
  6738. return this.messageHandler.sendWithPromise('GetJavaScript', null);
  6739. },
  6740. getOutline: function WorkerTransport_getOutline() {
  6741. return this.messageHandler.sendWithPromise('GetOutline', null);
  6742. },
  6743. getMetadata: function WorkerTransport_getMetadata() {
  6744. return this.messageHandler.sendWithPromise('GetMetadata', null).
  6745. then(function transportMetadata(results) {
  6746. return {
  6747. info: results[0],
  6748. metadata: (results[1] ? new PDFJS.Metadata(results[1]) : null)
  6749. };
  6750. });
  6751. },
  6752. getStats: function WorkerTransport_getStats() {
  6753. return this.messageHandler.sendWithPromise('GetStats', null);
  6754. },
  6755. startCleanup: function WorkerTransport_startCleanup() {
  6756. this.messageHandler.sendWithPromise('Cleanup', null).
  6757. then(function endCleanup() {
  6758. for (var i = 0, ii = this.pageCache.length; i < ii; i++) {
  6759. var page = this.pageCache[i];
  6760. if (page) {
  6761. page.cleanup();
  6762. }
  6763. }
  6764. this.commonObjs.clear();
  6765. this.fontLoader.clear();
  6766. }.bind(this));
  6767. }
  6768. };
  6769. return WorkerTransport;
  6770. })();
  6771. /**
  6772. * A PDF document and page is built of many objects. E.g. there are objects
  6773. * for fonts, images, rendering code and such. These objects might get processed
  6774. * inside of a worker. The `PDFObjects` implements some basic functions to
  6775. * manage these objects.
  6776. * @ignore
  6777. */
  6778. var PDFObjects = (function PDFObjectsClosure() {
  6779. function PDFObjects() {
  6780. this.objs = {};
  6781. }
  6782. PDFObjects.prototype = {
  6783. /**
  6784. * Internal function.
  6785. * Ensures there is an object defined for `objId`.
  6786. */
  6787. ensureObj: function PDFObjects_ensureObj(objId) {
  6788. if (this.objs[objId]) {
  6789. return this.objs[objId];
  6790. }
  6791. var obj = {
  6792. capability: createPromiseCapability(),
  6793. data: null,
  6794. resolved: false
  6795. };
  6796. this.objs[objId] = obj;
  6797. return obj;
  6798. },
  6799. /**
  6800. * If called *without* callback, this returns the data of `objId` but the
  6801. * object needs to be resolved. If it isn't, this function throws.
  6802. *
  6803. * If called *with* a callback, the callback is called with the data of the
  6804. * object once the object is resolved. That means, if you call this
  6805. * function and the object is already resolved, the callback gets called
  6806. * right away.
  6807. */
  6808. get: function PDFObjects_get(objId, callback) {
  6809. // If there is a callback, then the get can be async and the object is
  6810. // not required to be resolved right now
  6811. if (callback) {
  6812. this.ensureObj(objId).capability.promise.then(callback);
  6813. return null;
  6814. }
  6815. // If there isn't a callback, the user expects to get the resolved data
  6816. // directly.
  6817. var obj = this.objs[objId];
  6818. // If there isn't an object yet or the object isn't resolved, then the
  6819. // data isn't ready yet!
  6820. if (!obj || !obj.resolved) {
  6821. error('Requesting object that isn\'t resolved yet ' + objId);
  6822. }
  6823. return obj.data;
  6824. },
  6825. /**
  6826. * Resolves the object `objId` with optional `data`.
  6827. */
  6828. resolve: function PDFObjects_resolve(objId, data) {
  6829. var obj = this.ensureObj(objId);
  6830. obj.resolved = true;
  6831. obj.data = data;
  6832. obj.capability.resolve(data);
  6833. },
  6834. isResolved: function PDFObjects_isResolved(objId) {
  6835. var objs = this.objs;
  6836. if (!objs[objId]) {
  6837. return false;
  6838. } else {
  6839. return objs[objId].resolved;
  6840. }
  6841. },
  6842. hasData: function PDFObjects_hasData(objId) {
  6843. return this.isResolved(objId);
  6844. },
  6845. /**
  6846. * Returns the data of `objId` if object exists, null otherwise.
  6847. */
  6848. getData: function PDFObjects_getData(objId) {
  6849. var objs = this.objs;
  6850. if (!objs[objId] || !objs[objId].resolved) {
  6851. return null;
  6852. } else {
  6853. return objs[objId].data;
  6854. }
  6855. },
  6856. clear: function PDFObjects_clear() {
  6857. this.objs = {};
  6858. }
  6859. };
  6860. return PDFObjects;
  6861. })();
  6862. /**
  6863. * Allows controlling of the rendering tasks.
  6864. * @class
  6865. * @alias RenderTask
  6866. */
  6867. var RenderTask = (function RenderTaskClosure() {
  6868. function RenderTask(internalRenderTask) {
  6869. this._internalRenderTask = internalRenderTask;
  6870. /**
  6871. * Callback for incremental rendering -- a function that will be called
  6872. * each time the rendering is paused. To continue rendering call the
  6873. * function that is the first argument to the callback.
  6874. * @type {function}
  6875. */
  6876. this.onContinue = null;
  6877. }
  6878. RenderTask.prototype = /** @lends RenderTask.prototype */ {
  6879. /**
  6880. * Promise for rendering task completion.
  6881. * @return {Promise}
  6882. */
  6883. get promise() {
  6884. return this._internalRenderTask.capability.promise;
  6885. },
  6886. /**
  6887. * Cancels the rendering task. If the task is currently rendering it will
  6888. * not be cancelled until graphics pauses with a timeout. The promise that
  6889. * this object extends will resolved when cancelled.
  6890. */
  6891. cancel: function RenderTask_cancel() {
  6892. this._internalRenderTask.cancel();
  6893. },
  6894. /**
  6895. * Registers callbacks to indicate the rendering task completion.
  6896. *
  6897. * @param {function} onFulfilled The callback for the rendering completion.
  6898. * @param {function} onRejected The callback for the rendering failure.
  6899. * @return {Promise} A promise that is resolved after the onFulfilled or
  6900. * onRejected callback.
  6901. */
  6902. then: function RenderTask_then(onFulfilled, onRejected) {
  6903. return this.promise.then.apply(this.promise, arguments);
  6904. }
  6905. };
  6906. return RenderTask;
  6907. })();
  6908. /**
  6909. * For internal use only.
  6910. * @ignore
  6911. */
  6912. var InternalRenderTask = (function InternalRenderTaskClosure() {
  6913. function InternalRenderTask(callback, params, objs, commonObjs, operatorList,
  6914. pageNumber) {
  6915. this.callback = callback;
  6916. this.params = params;
  6917. this.objs = objs;
  6918. this.commonObjs = commonObjs;
  6919. this.operatorListIdx = null;
  6920. this.operatorList = operatorList;
  6921. this.pageNumber = pageNumber;
  6922. this.running = false;
  6923. this.graphicsReadyCallback = null;
  6924. this.graphicsReady = false;
  6925. this.useRequestAnimationFrame = false;
  6926. this.cancelled = false;
  6927. this.capability = createPromiseCapability();
  6928. this.task = new RenderTask(this);
  6929. // caching this-bound methods
  6930. this._continueBound = this._continue.bind(this);
  6931. this._scheduleNextBound = this._scheduleNext.bind(this);
  6932. this._nextBound = this._next.bind(this);
  6933. }
  6934. InternalRenderTask.prototype = {
  6935. initalizeGraphics:
  6936. function InternalRenderTask_initalizeGraphics(transparency) {
  6937. if (this.cancelled) {
  6938. return;
  6939. }
  6940. if (PDFJS.pdfBug && 'StepperManager' in globalScope &&
  6941. globalScope.StepperManager.enabled) {
  6942. this.stepper = globalScope.StepperManager.create(this.pageNumber - 1);
  6943. this.stepper.init(this.operatorList);
  6944. this.stepper.nextBreakPoint = this.stepper.getNextBreakPoint();
  6945. }
  6946. var params = this.params;
  6947. this.gfx = new CanvasGraphics(params.canvasContext, this.commonObjs,
  6948. this.objs, params.imageLayer);
  6949. this.gfx.beginDrawing(params.transform, params.viewport, transparency);
  6950. this.operatorListIdx = 0;
  6951. this.graphicsReady = true;
  6952. if (this.graphicsReadyCallback) {
  6953. this.graphicsReadyCallback();
  6954. }
  6955. },
  6956. cancel: function InternalRenderTask_cancel() {
  6957. this.running = false;
  6958. this.cancelled = true;
  6959. this.callback('cancelled');
  6960. },
  6961. operatorListChanged: function InternalRenderTask_operatorListChanged() {
  6962. if (!this.graphicsReady) {
  6963. if (!this.graphicsReadyCallback) {
  6964. this.graphicsReadyCallback = this._continueBound;
  6965. }
  6966. return;
  6967. }
  6968. if (this.stepper) {
  6969. this.stepper.updateOperatorList(this.operatorList);
  6970. }
  6971. if (this.running) {
  6972. return;
  6973. }
  6974. this._continue();
  6975. },
  6976. _continue: function InternalRenderTask__continue() {
  6977. this.running = true;
  6978. if (this.cancelled) {
  6979. return;
  6980. }
  6981. if (this.task.onContinue) {
  6982. this.task.onContinue.call(this.task, this._scheduleNextBound);
  6983. } else {
  6984. this._scheduleNext();
  6985. }
  6986. },
  6987. _scheduleNext: function InternalRenderTask__scheduleNext() {
  6988. if (this.useRequestAnimationFrame) {
  6989. window.requestAnimationFrame(this._nextBound);
  6990. } else {
  6991. Promise.resolve(undefined).then(this._nextBound);
  6992. }
  6993. },
  6994. _next: function InternalRenderTask__next() {
  6995. if (this.cancelled) {
  6996. return;
  6997. }
  6998. this.operatorListIdx = this.gfx.executeOperatorList(this.operatorList,
  6999. this.operatorListIdx,
  7000. this._continueBound,
  7001. this.stepper);
  7002. if (this.operatorListIdx === this.operatorList.argsArray.length) {
  7003. this.running = false;
  7004. if (this.operatorList.lastChunk) {
  7005. this.gfx.endDrawing();
  7006. this.callback();
  7007. }
  7008. }
  7009. }
  7010. };
  7011. return InternalRenderTask;
  7012. })();
  7013. /**
  7014. * (Deprecated) Global observer of unsupported feature usages. Use
  7015. * onUnsupportedFeature callback of the {PDFDocumentLoadingTask} instance.
  7016. */
  7017. PDFJS.UnsupportedManager = (function UnsupportedManagerClosure() {
  7018. var listeners = [];
  7019. return {
  7020. listen: function (cb) {
  7021. deprecated('Global UnsupportedManager.listen is used: ' +
  7022. ' use PDFDocumentLoadingTask.onUnsupportedFeature instead');
  7023. listeners.push(cb);
  7024. },
  7025. notify: function (featureId) {
  7026. for (var i = 0, ii = listeners.length; i < ii; i++) {
  7027. listeners[i](featureId);
  7028. }
  7029. }
  7030. };
  7031. })();
  7032. exports.getDocument = PDFJS.getDocument;
  7033. exports.PDFDataRangeTransport = PDFDataRangeTransport;
  7034. exports.PDFDocumentProxy = PDFDocumentProxy;
  7035. exports.PDFPageProxy = PDFPageProxy;
  7036. }));
  7037. (function (root, factory) {
  7038. {
  7039. factory((root.pdfjsDisplaySVG = {}), root.pdfjsSharedUtil);
  7040. }
  7041. }(this, function (exports, sharedUtil) {
  7042. var FONT_IDENTITY_MATRIX = sharedUtil.FONT_IDENTITY_MATRIX;
  7043. var IDENTITY_MATRIX = sharedUtil.IDENTITY_MATRIX;
  7044. var ImageKind = sharedUtil.ImageKind;
  7045. var OPS = sharedUtil.OPS;
  7046. var Util = sharedUtil.Util;
  7047. var isNum = sharedUtil.isNum;
  7048. var isArray = sharedUtil.isArray;
  7049. var warn = sharedUtil.warn;
  7050. var SVG_DEFAULTS = {
  7051. fontStyle: 'normal',
  7052. fontWeight: 'normal',
  7053. fillColor: '#000000'
  7054. };
  7055. var convertImgDataToPng = (function convertImgDataToPngClosure() {
  7056. var PNG_HEADER =
  7057. new Uint8Array([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);
  7058. var CHUNK_WRAPPER_SIZE = 12;
  7059. var crcTable = new Int32Array(256);
  7060. for (var i = 0; i < 256; i++) {
  7061. var c = i;
  7062. for (var h = 0; h < 8; h++) {
  7063. if (c & 1) {
  7064. c = 0xedB88320 ^ ((c >> 1) & 0x7fffffff);
  7065. } else {
  7066. c = (c >> 1) & 0x7fffffff;
  7067. }
  7068. }
  7069. crcTable[i] = c;
  7070. }
  7071. function crc32(data, start, end) {
  7072. var crc = -1;
  7073. for (var i = start; i < end; i++) {
  7074. var a = (crc ^ data[i]) & 0xff;
  7075. var b = crcTable[a];
  7076. crc = (crc >>> 8) ^ b;
  7077. }
  7078. return crc ^ -1;
  7079. }
  7080. function writePngChunk(type, body, data, offset) {
  7081. var p = offset;
  7082. var len = body.length;
  7083. data[p] = len >> 24 & 0xff;
  7084. data[p + 1] = len >> 16 & 0xff;
  7085. data[p + 2] = len >> 8 & 0xff;
  7086. data[p + 3] = len & 0xff;
  7087. p += 4;
  7088. data[p] = type.charCodeAt(0) & 0xff;
  7089. data[p + 1] = type.charCodeAt(1) & 0xff;
  7090. data[p + 2] = type.charCodeAt(2) & 0xff;
  7091. data[p + 3] = type.charCodeAt(3) & 0xff;
  7092. p += 4;
  7093. data.set(body, p);
  7094. p += body.length;
  7095. var crc = crc32(data, offset + 4, p);
  7096. data[p] = crc >> 24 & 0xff;
  7097. data[p + 1] = crc >> 16 & 0xff;
  7098. data[p + 2] = crc >> 8 & 0xff;
  7099. data[p + 3] = crc & 0xff;
  7100. }
  7101. function adler32(data, start, end) {
  7102. var a = 1;
  7103. var b = 0;
  7104. for (var i = start; i < end; ++i) {
  7105. a = (a + (data[i] & 0xff)) % 65521;
  7106. b = (b + a) % 65521;
  7107. }
  7108. return (b << 16) | a;
  7109. }
  7110. function encode(imgData, kind) {
  7111. var width = imgData.width;
  7112. var height = imgData.height;
  7113. var bitDepth, colorType, lineSize;
  7114. var bytes = imgData.data;
  7115. switch (kind) {
  7116. case ImageKind.GRAYSCALE_1BPP:
  7117. colorType = 0;
  7118. bitDepth = 1;
  7119. lineSize = (width + 7) >> 3;
  7120. break;
  7121. case ImageKind.RGB_24BPP:
  7122. colorType = 2;
  7123. bitDepth = 8;
  7124. lineSize = width * 3;
  7125. break;
  7126. case ImageKind.RGBA_32BPP:
  7127. colorType = 6;
  7128. bitDepth = 8;
  7129. lineSize = width * 4;
  7130. break;
  7131. default:
  7132. throw new Error('invalid format');
  7133. }
  7134. // prefix every row with predictor 0
  7135. var literals = new Uint8Array((1 + lineSize) * height);
  7136. var offsetLiterals = 0, offsetBytes = 0;
  7137. var y, i;
  7138. for (y = 0; y < height; ++y) {
  7139. literals[offsetLiterals++] = 0; // no prediction
  7140. literals.set(bytes.subarray(offsetBytes, offsetBytes + lineSize),
  7141. offsetLiterals);
  7142. offsetBytes += lineSize;
  7143. offsetLiterals += lineSize;
  7144. }
  7145. if (kind === ImageKind.GRAYSCALE_1BPP) {
  7146. // inverting for B/W
  7147. offsetLiterals = 0;
  7148. for (y = 0; y < height; y++) {
  7149. offsetLiterals++; // skipping predictor
  7150. for (i = 0; i < lineSize; i++) {
  7151. literals[offsetLiterals++] ^= 0xFF;
  7152. }
  7153. }
  7154. }
  7155. var ihdr = new Uint8Array([
  7156. width >> 24 & 0xff,
  7157. width >> 16 & 0xff,
  7158. width >> 8 & 0xff,
  7159. width & 0xff,
  7160. height >> 24 & 0xff,
  7161. height >> 16 & 0xff,
  7162. height >> 8 & 0xff,
  7163. height & 0xff,
  7164. bitDepth, // bit depth
  7165. colorType, // color type
  7166. 0x00, // compression method
  7167. 0x00, // filter method
  7168. 0x00 // interlace method
  7169. ]);
  7170. var len = literals.length;
  7171. var maxBlockLength = 0xFFFF;
  7172. var deflateBlocks = Math.ceil(len / maxBlockLength);
  7173. var idat = new Uint8Array(2 + len + deflateBlocks * 5 + 4);
  7174. var pi = 0;
  7175. idat[pi++] = 0x78; // compression method and flags
  7176. idat[pi++] = 0x9c; // flags
  7177. var pos = 0;
  7178. while (len > maxBlockLength) {
  7179. // writing non-final DEFLATE blocks type 0 and length of 65535
  7180. idat[pi++] = 0x00;
  7181. idat[pi++] = 0xff;
  7182. idat[pi++] = 0xff;
  7183. idat[pi++] = 0x00;
  7184. idat[pi++] = 0x00;
  7185. idat.set(literals.subarray(pos, pos + maxBlockLength), pi);
  7186. pi += maxBlockLength;
  7187. pos += maxBlockLength;
  7188. len -= maxBlockLength;
  7189. }
  7190. // writing non-final DEFLATE blocks type 0
  7191. idat[pi++] = 0x01;
  7192. idat[pi++] = len & 0xff;
  7193. idat[pi++] = len >> 8 & 0xff;
  7194. idat[pi++] = (~len & 0xffff) & 0xff;
  7195. idat[pi++] = (~len & 0xffff) >> 8 & 0xff;
  7196. idat.set(literals.subarray(pos), pi);
  7197. pi += literals.length - pos;
  7198. var adler = adler32(literals, 0, literals.length); // checksum
  7199. idat[pi++] = adler >> 24 & 0xff;
  7200. idat[pi++] = adler >> 16 & 0xff;
  7201. idat[pi++] = adler >> 8 & 0xff;
  7202. idat[pi++] = adler & 0xff;
  7203. // PNG will consists: header, IHDR+data, IDAT+data, and IEND.
  7204. var pngLength = PNG_HEADER.length + (CHUNK_WRAPPER_SIZE * 3) +
  7205. ihdr.length + idat.length;
  7206. var data = new Uint8Array(pngLength);
  7207. var offset = 0;
  7208. data.set(PNG_HEADER, offset);
  7209. offset += PNG_HEADER.length;
  7210. writePngChunk('IHDR', ihdr, data, offset);
  7211. offset += CHUNK_WRAPPER_SIZE + ihdr.length;
  7212. writePngChunk('IDATA', idat, data, offset);
  7213. offset += CHUNK_WRAPPER_SIZE + idat.length;
  7214. writePngChunk('IEND', new Uint8Array(0), data, offset);
  7215. return PDFJS.createObjectURL(data, 'image/png');
  7216. }
  7217. return function convertImgDataToPng(imgData) {
  7218. var kind = (imgData.kind === undefined ?
  7219. ImageKind.GRAYSCALE_1BPP : imgData.kind);
  7220. return encode(imgData, kind);
  7221. };
  7222. })();
  7223. var SVGExtraState = (function SVGExtraStateClosure() {
  7224. function SVGExtraState() {
  7225. this.fontSizeScale = 1;
  7226. this.fontWeight = SVG_DEFAULTS.fontWeight;
  7227. this.fontSize = 0;
  7228. this.textMatrix = IDENTITY_MATRIX;
  7229. this.fontMatrix = FONT_IDENTITY_MATRIX;
  7230. this.leading = 0;
  7231. // Current point (in user coordinates)
  7232. this.x = 0;
  7233. this.y = 0;
  7234. // Start of text line (in text coordinates)
  7235. this.lineX = 0;
  7236. this.lineY = 0;
  7237. // Character and word spacing
  7238. this.charSpacing = 0;
  7239. this.wordSpacing = 0;
  7240. this.textHScale = 1;
  7241. this.textRise = 0;
  7242. // Default foreground and background colors
  7243. this.fillColor = SVG_DEFAULTS.fillColor;
  7244. this.strokeColor = '#000000';
  7245. this.fillAlpha = 1;
  7246. this.strokeAlpha = 1;
  7247. this.lineWidth = 1;
  7248. this.lineJoin = '';
  7249. this.lineCap = '';
  7250. this.miterLimit = 0;
  7251. this.dashArray = [];
  7252. this.dashPhase = 0;
  7253. this.dependencies = [];
  7254. // Clipping
  7255. this.clipId = '';
  7256. this.pendingClip = false;
  7257. this.maskId = '';
  7258. }
  7259. SVGExtraState.prototype = {
  7260. clone: function SVGExtraState_clone() {
  7261. return Object.create(this);
  7262. },
  7263. setCurrentPoint: function SVGExtraState_setCurrentPoint(x, y) {
  7264. this.x = x;
  7265. this.y = y;
  7266. }
  7267. };
  7268. return SVGExtraState;
  7269. })();
  7270. var SVGGraphics = (function SVGGraphicsClosure() {
  7271. function createScratchSVG(width, height) {
  7272. var NS = 'http://www.w3.org/2000/svg';
  7273. var svg = document.createElementNS(NS, 'svg:svg');
  7274. svg.setAttributeNS(null, 'version', '1.1');
  7275. svg.setAttributeNS(null, 'width', width + 'px');
  7276. svg.setAttributeNS(null, 'height', height + 'px');
  7277. svg.setAttributeNS(null, 'viewBox', '0 0 ' + width + ' ' + height);
  7278. return svg;
  7279. }
  7280. function opListToTree(opList) {
  7281. var opTree = [];
  7282. var tmp = [];
  7283. var opListLen = opList.length;
  7284. for (var x = 0; x < opListLen; x++) {
  7285. if (opList[x].fn === 'save') {
  7286. opTree.push({'fnId': 92, 'fn': 'group', 'items': []});
  7287. tmp.push(opTree);
  7288. opTree = opTree[opTree.length - 1].items;
  7289. continue;
  7290. }
  7291. if(opList[x].fn === 'restore') {
  7292. opTree = tmp.pop();
  7293. } else {
  7294. opTree.push(opList[x]);
  7295. }
  7296. }
  7297. return opTree;
  7298. }
  7299. /**
  7300. * Formats float number.
  7301. * @param value {number} number to format.
  7302. * @returns {string}
  7303. */
  7304. function pf(value) {
  7305. if (value === (value | 0)) { // integer number
  7306. return value.toString();
  7307. }
  7308. var s = value.toFixed(10);
  7309. var i = s.length - 1;
  7310. if (s[i] !== '0') {
  7311. return s;
  7312. }
  7313. // removing trailing zeros
  7314. do {
  7315. i--;
  7316. } while (s[i] === '0');
  7317. return s.substr(0, s[i] === '.' ? i : i + 1);
  7318. }
  7319. /**
  7320. * Formats transform matrix. The standard rotation, scale and translate
  7321. * matrices are replaced by their shorter forms, and for identity matrix
  7322. * returns empty string to save the memory.
  7323. * @param m {Array} matrix to format.
  7324. * @returns {string}
  7325. */
  7326. function pm(m) {
  7327. if (m[4] === 0 && m[5] === 0) {
  7328. if (m[1] === 0 && m[2] === 0) {
  7329. if (m[0] === 1 && m[3] === 1) {
  7330. return '';
  7331. }
  7332. return 'scale(' + pf(m[0]) + ' ' + pf(m[3]) + ')';
  7333. }
  7334. if (m[0] === m[3] && m[1] === -m[2]) {
  7335. var a = Math.acos(m[0]) * 180 / Math.PI;
  7336. return 'rotate(' + pf(a) + ')';
  7337. }
  7338. } else {
  7339. if (m[0] === 1 && m[1] === 0 && m[2] === 0 && m[3] === 1) {
  7340. return 'translate(' + pf(m[4]) + ' ' + pf(m[5]) + ')';
  7341. }
  7342. }
  7343. return 'matrix(' + pf(m[0]) + ' ' + pf(m[1]) + ' ' + pf(m[2]) + ' ' +
  7344. pf(m[3]) + ' ' + pf(m[4]) + ' ' + pf(m[5]) + ')';
  7345. }
  7346. function SVGGraphics(commonObjs, objs) {
  7347. this.current = new SVGExtraState();
  7348. this.transformMatrix = IDENTITY_MATRIX; // Graphics state matrix
  7349. this.transformStack = [];
  7350. this.extraStack = [];
  7351. this.commonObjs = commonObjs;
  7352. this.objs = objs;
  7353. this.pendingEOFill = false;
  7354. this.embedFonts = false;
  7355. this.embeddedFonts = {};
  7356. this.cssStyle = null;
  7357. }
  7358. var NS = 'http://www.w3.org/2000/svg';
  7359. var XML_NS = 'http://www.w3.org/XML/1998/namespace';
  7360. var XLINK_NS = 'http://www.w3.org/1999/xlink';
  7361. var LINE_CAP_STYLES = ['butt', 'round', 'square'];
  7362. var LINE_JOIN_STYLES = ['miter', 'round', 'bevel'];
  7363. var clipCount = 0;
  7364. var maskCount = 0;
  7365. SVGGraphics.prototype = {
  7366. save: function SVGGraphics_save() {
  7367. this.transformStack.push(this.transformMatrix);
  7368. var old = this.current;
  7369. this.extraStack.push(old);
  7370. this.current = old.clone();
  7371. },
  7372. restore: function SVGGraphics_restore() {
  7373. this.transformMatrix = this.transformStack.pop();
  7374. this.current = this.extraStack.pop();
  7375. this.tgrp = document.createElementNS(NS, 'svg:g');
  7376. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  7377. this.pgrp.appendChild(this.tgrp);
  7378. },
  7379. group: function SVGGraphics_group(items) {
  7380. this.save();
  7381. this.executeOpTree(items);
  7382. this.restore();
  7383. },
  7384. loadDependencies: function SVGGraphics_loadDependencies(operatorList) {
  7385. var fnArray = operatorList.fnArray;
  7386. var fnArrayLen = fnArray.length;
  7387. var argsArray = operatorList.argsArray;
  7388. var self = this;
  7389. for (var i = 0; i < fnArrayLen; i++) {
  7390. if (OPS.dependency === fnArray[i]) {
  7391. var deps = argsArray[i];
  7392. for (var n = 0, nn = deps.length; n < nn; n++) {
  7393. var obj = deps[n];
  7394. var common = obj.substring(0, 2) === 'g_';
  7395. var promise;
  7396. if (common) {
  7397. promise = new Promise(function(resolve) {
  7398. self.commonObjs.get(obj, resolve);
  7399. });
  7400. } else {
  7401. promise = new Promise(function(resolve) {
  7402. self.objs.get(obj, resolve);
  7403. });
  7404. }
  7405. this.current.dependencies.push(promise);
  7406. }
  7407. }
  7408. }
  7409. return Promise.all(this.current.dependencies);
  7410. },
  7411. transform: function SVGGraphics_transform(a, b, c, d, e, f) {
  7412. var transformMatrix = [a, b, c, d, e, f];
  7413. this.transformMatrix = PDFJS.Util.transform(this.transformMatrix,
  7414. transformMatrix);
  7415. this.tgrp = document.createElementNS(NS, 'svg:g');
  7416. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  7417. },
  7418. getSVG: function SVGGraphics_getSVG(operatorList, viewport) {
  7419. this.svg = createScratchSVG(viewport.width, viewport.height);
  7420. this.viewport = viewport;
  7421. return this.loadDependencies(operatorList).then(function () {
  7422. this.transformMatrix = IDENTITY_MATRIX;
  7423. this.pgrp = document.createElementNS(NS, 'svg:g'); // Parent group
  7424. this.pgrp.setAttributeNS(null, 'transform', pm(viewport.transform));
  7425. this.tgrp = document.createElementNS(NS, 'svg:g'); // Transform group
  7426. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  7427. this.defs = document.createElementNS(NS, 'svg:defs');
  7428. this.pgrp.appendChild(this.defs);
  7429. this.pgrp.appendChild(this.tgrp);
  7430. this.svg.appendChild(this.pgrp);
  7431. var opTree = this.convertOpList(operatorList);
  7432. this.executeOpTree(opTree);
  7433. return this.svg;
  7434. }.bind(this));
  7435. },
  7436. convertOpList: function SVGGraphics_convertOpList(operatorList) {
  7437. var argsArray = operatorList.argsArray;
  7438. var fnArray = operatorList.fnArray;
  7439. var fnArrayLen = fnArray.length;
  7440. var REVOPS = [];
  7441. var opList = [];
  7442. for (var op in OPS) {
  7443. REVOPS[OPS[op]] = op;
  7444. }
  7445. for (var x = 0; x < fnArrayLen; x++) {
  7446. var fnId = fnArray[x];
  7447. opList.push({'fnId' : fnId, 'fn': REVOPS[fnId], 'args': argsArray[x]});
  7448. }
  7449. return opListToTree(opList);
  7450. },
  7451. executeOpTree: function SVGGraphics_executeOpTree(opTree) {
  7452. var opTreeLen = opTree.length;
  7453. for(var x = 0; x < opTreeLen; x++) {
  7454. var fn = opTree[x].fn;
  7455. var fnId = opTree[x].fnId;
  7456. var args = opTree[x].args;
  7457. switch (fnId | 0) {
  7458. case OPS.beginText:
  7459. this.beginText();
  7460. break;
  7461. case OPS.setLeading:
  7462. this.setLeading(args);
  7463. break;
  7464. case OPS.setLeadingMoveText:
  7465. this.setLeadingMoveText(args[0], args[1]);
  7466. break;
  7467. case OPS.setFont:
  7468. this.setFont(args);
  7469. break;
  7470. case OPS.showText:
  7471. this.showText(args[0]);
  7472. break;
  7473. case OPS.showSpacedText:
  7474. this.showText(args[0]);
  7475. break;
  7476. case OPS.endText:
  7477. this.endText();
  7478. break;
  7479. case OPS.moveText:
  7480. this.moveText(args[0], args[1]);
  7481. break;
  7482. case OPS.setCharSpacing:
  7483. this.setCharSpacing(args[0]);
  7484. break;
  7485. case OPS.setWordSpacing:
  7486. this.setWordSpacing(args[0]);
  7487. break;
  7488. case OPS.setHScale:
  7489. this.setHScale(args[0]);
  7490. break;
  7491. case OPS.setTextMatrix:
  7492. this.setTextMatrix(args[0], args[1], args[2],
  7493. args[3], args[4], args[5]);
  7494. break;
  7495. case OPS.setLineWidth:
  7496. this.setLineWidth(args[0]);
  7497. break;
  7498. case OPS.setLineJoin:
  7499. this.setLineJoin(args[0]);
  7500. break;
  7501. case OPS.setLineCap:
  7502. this.setLineCap(args[0]);
  7503. break;
  7504. case OPS.setMiterLimit:
  7505. this.setMiterLimit(args[0]);
  7506. break;
  7507. case OPS.setFillRGBColor:
  7508. this.setFillRGBColor(args[0], args[1], args[2]);
  7509. break;
  7510. case OPS.setStrokeRGBColor:
  7511. this.setStrokeRGBColor(args[0], args[1], args[2]);
  7512. break;
  7513. case OPS.setDash:
  7514. this.setDash(args[0], args[1]);
  7515. break;
  7516. case OPS.setGState:
  7517. this.setGState(args[0]);
  7518. break;
  7519. case OPS.fill:
  7520. this.fill();
  7521. break;
  7522. case OPS.eoFill:
  7523. this.eoFill();
  7524. break;
  7525. case OPS.stroke:
  7526. this.stroke();
  7527. break;
  7528. case OPS.fillStroke:
  7529. this.fillStroke();
  7530. break;
  7531. case OPS.eoFillStroke:
  7532. this.eoFillStroke();
  7533. break;
  7534. case OPS.clip:
  7535. this.clip('nonzero');
  7536. break;
  7537. case OPS.eoClip:
  7538. this.clip('evenodd');
  7539. break;
  7540. case OPS.paintSolidColorImageMask:
  7541. this.paintSolidColorImageMask();
  7542. break;
  7543. case OPS.paintJpegXObject:
  7544. this.paintJpegXObject(args[0], args[1], args[2]);
  7545. break;
  7546. case OPS.paintImageXObject:
  7547. this.paintImageXObject(args[0]);
  7548. break;
  7549. case OPS.paintInlineImageXObject:
  7550. this.paintInlineImageXObject(args[0]);
  7551. break;
  7552. case OPS.paintImageMaskXObject:
  7553. this.paintImageMaskXObject(args[0]);
  7554. break;
  7555. case OPS.paintFormXObjectBegin:
  7556. this.paintFormXObjectBegin(args[0], args[1]);
  7557. break;
  7558. case OPS.paintFormXObjectEnd:
  7559. this.paintFormXObjectEnd();
  7560. break;
  7561. case OPS.closePath:
  7562. this.closePath();
  7563. break;
  7564. case OPS.closeStroke:
  7565. this.closeStroke();
  7566. break;
  7567. case OPS.closeFillStroke:
  7568. this.closeFillStroke();
  7569. break;
  7570. case OPS.nextLine:
  7571. this.nextLine();
  7572. break;
  7573. case OPS.transform:
  7574. this.transform(args[0], args[1], args[2], args[3],
  7575. args[4], args[5]);
  7576. break;
  7577. case OPS.constructPath:
  7578. this.constructPath(args[0], args[1]);
  7579. break;
  7580. case OPS.endPath:
  7581. this.endPath();
  7582. break;
  7583. case 92:
  7584. this.group(opTree[x].items);
  7585. break;
  7586. default:
  7587. warn('Unimplemented method '+ fn);
  7588. break;
  7589. }
  7590. }
  7591. },
  7592. setWordSpacing: function SVGGraphics_setWordSpacing(wordSpacing) {
  7593. this.current.wordSpacing = wordSpacing;
  7594. },
  7595. setCharSpacing: function SVGGraphics_setCharSpacing(charSpacing) {
  7596. this.current.charSpacing = charSpacing;
  7597. },
  7598. nextLine: function SVGGraphics_nextLine() {
  7599. this.moveText(0, this.current.leading);
  7600. },
  7601. setTextMatrix: function SVGGraphics_setTextMatrix(a, b, c, d, e, f) {
  7602. var current = this.current;
  7603. this.current.textMatrix = this.current.lineMatrix = [a, b, c, d, e, f];
  7604. this.current.x = this.current.lineX = 0;
  7605. this.current.y = this.current.lineY = 0;
  7606. current.xcoords = [];
  7607. current.tspan = document.createElementNS(NS, 'svg:tspan');
  7608. current.tspan.setAttributeNS(null, 'font-family', current.fontFamily);
  7609. current.tspan.setAttributeNS(null, 'font-size',
  7610. pf(current.fontSize) + 'px');
  7611. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  7612. current.txtElement = document.createElementNS(NS, 'svg:text');
  7613. current.txtElement.appendChild(current.tspan);
  7614. },
  7615. beginText: function SVGGraphics_beginText() {
  7616. this.current.x = this.current.lineX = 0;
  7617. this.current.y = this.current.lineY = 0;
  7618. this.current.textMatrix = IDENTITY_MATRIX;
  7619. this.current.lineMatrix = IDENTITY_MATRIX;
  7620. this.current.tspan = document.createElementNS(NS, 'svg:tspan');
  7621. this.current.txtElement = document.createElementNS(NS, 'svg:text');
  7622. this.current.txtgrp = document.createElementNS(NS, 'svg:g');
  7623. this.current.xcoords = [];
  7624. },
  7625. moveText: function SVGGraphics_moveText(x, y) {
  7626. var current = this.current;
  7627. this.current.x = this.current.lineX += x;
  7628. this.current.y = this.current.lineY += y;
  7629. current.xcoords = [];
  7630. current.tspan = document.createElementNS(NS, 'svg:tspan');
  7631. current.tspan.setAttributeNS(null, 'font-family', current.fontFamily);
  7632. current.tspan.setAttributeNS(null, 'font-size',
  7633. pf(current.fontSize) + 'px');
  7634. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  7635. },
  7636. showText: function SVGGraphics_showText(glyphs) {
  7637. var current = this.current;
  7638. var font = current.font;
  7639. var fontSize = current.fontSize;
  7640. if (fontSize === 0) {
  7641. return;
  7642. }
  7643. var charSpacing = current.charSpacing;
  7644. var wordSpacing = current.wordSpacing;
  7645. var fontDirection = current.fontDirection;
  7646. var textHScale = current.textHScale * fontDirection;
  7647. var glyphsLength = glyphs.length;
  7648. var vertical = font.vertical;
  7649. var widthAdvanceScale = fontSize * current.fontMatrix[0];
  7650. var x = 0, i;
  7651. for (i = 0; i < glyphsLength; ++i) {
  7652. var glyph = glyphs[i];
  7653. if (glyph === null) {
  7654. // word break
  7655. x += fontDirection * wordSpacing;
  7656. continue;
  7657. } else if (isNum(glyph)) {
  7658. x += -glyph * fontSize * 0.001;
  7659. continue;
  7660. }
  7661. current.xcoords.push(current.x + x * textHScale);
  7662. var width = glyph.width;
  7663. var character = glyph.fontChar;
  7664. var charWidth = width * widthAdvanceScale + charSpacing * fontDirection;
  7665. x += charWidth;
  7666. current.tspan.textContent += character;
  7667. }
  7668. if (vertical) {
  7669. current.y -= x * textHScale;
  7670. } else {
  7671. current.x += x * textHScale;
  7672. }
  7673. current.tspan.setAttributeNS(null, 'x',
  7674. current.xcoords.map(pf).join(' '));
  7675. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  7676. current.tspan.setAttributeNS(null, 'font-family', current.fontFamily);
  7677. current.tspan.setAttributeNS(null, 'font-size',
  7678. pf(current.fontSize) + 'px');
  7679. if (current.fontStyle !== SVG_DEFAULTS.fontStyle) {
  7680. current.tspan.setAttributeNS(null, 'font-style', current.fontStyle);
  7681. }
  7682. if (current.fontWeight !== SVG_DEFAULTS.fontWeight) {
  7683. current.tspan.setAttributeNS(null, 'font-weight', current.fontWeight);
  7684. }
  7685. if (current.fillColor !== SVG_DEFAULTS.fillColor) {
  7686. current.tspan.setAttributeNS(null, 'fill', current.fillColor);
  7687. }
  7688. current.txtElement.setAttributeNS(null, 'transform',
  7689. pm(current.textMatrix) +
  7690. ' scale(1, -1)' );
  7691. current.txtElement.setAttributeNS(XML_NS, 'xml:space', 'preserve');
  7692. current.txtElement.appendChild(current.tspan);
  7693. current.txtgrp.appendChild(current.txtElement);
  7694. this.tgrp.appendChild(current.txtElement);
  7695. },
  7696. setLeadingMoveText: function SVGGraphics_setLeadingMoveText(x, y) {
  7697. this.setLeading(-y);
  7698. this.moveText(x, y);
  7699. },
  7700. addFontStyle: function SVGGraphics_addFontStyle(fontObj) {
  7701. if (!this.cssStyle) {
  7702. this.cssStyle = document.createElementNS(NS, 'svg:style');
  7703. this.cssStyle.setAttributeNS(null, 'type', 'text/css');
  7704. this.defs.appendChild(this.cssStyle);
  7705. }
  7706. var url = PDFJS.createObjectURL(fontObj.data, fontObj.mimetype);
  7707. this.cssStyle.textContent +=
  7708. '@font-face { font-family: "' + fontObj.loadedName + '";' +
  7709. ' src: url(' + url + '); }\n';
  7710. },
  7711. setFont: function SVGGraphics_setFont(details) {
  7712. var current = this.current;
  7713. var fontObj = this.commonObjs.get(details[0]);
  7714. var size = details[1];
  7715. this.current.font = fontObj;
  7716. if (this.embedFonts && fontObj.data &&
  7717. !this.embeddedFonts[fontObj.loadedName]) {
  7718. this.addFontStyle(fontObj);
  7719. this.embeddedFonts[fontObj.loadedName] = fontObj;
  7720. }
  7721. current.fontMatrix = (fontObj.fontMatrix ?
  7722. fontObj.fontMatrix : FONT_IDENTITY_MATRIX);
  7723. var bold = fontObj.black ? (fontObj.bold ? 'bolder' : 'bold') :
  7724. (fontObj.bold ? 'bold' : 'normal');
  7725. var italic = fontObj.italic ? 'italic' : 'normal';
  7726. if (size < 0) {
  7727. size = -size;
  7728. current.fontDirection = -1;
  7729. } else {
  7730. current.fontDirection = 1;
  7731. }
  7732. current.fontSize = size;
  7733. current.fontFamily = fontObj.loadedName;
  7734. current.fontWeight = bold;
  7735. current.fontStyle = italic;
  7736. current.tspan = document.createElementNS(NS, 'svg:tspan');
  7737. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  7738. current.xcoords = [];
  7739. },
  7740. endText: function SVGGraphics_endText() {
  7741. if (this.current.pendingClip) {
  7742. this.cgrp.appendChild(this.tgrp);
  7743. this.pgrp.appendChild(this.cgrp);
  7744. } else {
  7745. this.pgrp.appendChild(this.tgrp);
  7746. }
  7747. this.tgrp = document.createElementNS(NS, 'svg:g');
  7748. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  7749. },
  7750. // Path properties
  7751. setLineWidth: function SVGGraphics_setLineWidth(width) {
  7752. this.current.lineWidth = width;
  7753. },
  7754. setLineCap: function SVGGraphics_setLineCap(style) {
  7755. this.current.lineCap = LINE_CAP_STYLES[style];
  7756. },
  7757. setLineJoin: function SVGGraphics_setLineJoin(style) {
  7758. this.current.lineJoin = LINE_JOIN_STYLES[style];
  7759. },
  7760. setMiterLimit: function SVGGraphics_setMiterLimit(limit) {
  7761. this.current.miterLimit = limit;
  7762. },
  7763. setStrokeRGBColor: function SVGGraphics_setStrokeRGBColor(r, g, b) {
  7764. var color = Util.makeCssRgb(r, g, b);
  7765. this.current.strokeColor = color;
  7766. },
  7767. setFillRGBColor: function SVGGraphics_setFillRGBColor(r, g, b) {
  7768. var color = Util.makeCssRgb(r, g, b);
  7769. this.current.fillColor = color;
  7770. this.current.tspan = document.createElementNS(NS, 'svg:tspan');
  7771. this.current.xcoords = [];
  7772. },
  7773. setDash: function SVGGraphics_setDash(dashArray, dashPhase) {
  7774. this.current.dashArray = dashArray;
  7775. this.current.dashPhase = dashPhase;
  7776. },
  7777. constructPath: function SVGGraphics_constructPath(ops, args) {
  7778. var current = this.current;
  7779. var x = current.x, y = current.y;
  7780. current.path = document.createElementNS(NS, 'svg:path');
  7781. var d = [];
  7782. var opLength = ops.length;
  7783. for (var i = 0, j = 0; i < opLength; i++) {
  7784. switch (ops[i] | 0) {
  7785. case OPS.rectangle:
  7786. x = args[j++];
  7787. y = args[j++];
  7788. var width = args[j++];
  7789. var height = args[j++];
  7790. var xw = x + width;
  7791. var yh = y + height;
  7792. d.push('M', pf(x), pf(y), 'L', pf(xw) , pf(y), 'L', pf(xw), pf(yh),
  7793. 'L', pf(x), pf(yh), 'Z');
  7794. break;
  7795. case OPS.moveTo:
  7796. x = args[j++];
  7797. y = args[j++];
  7798. d.push('M', pf(x), pf(y));
  7799. break;
  7800. case OPS.lineTo:
  7801. x = args[j++];
  7802. y = args[j++];
  7803. d.push('L', pf(x) , pf(y));
  7804. break;
  7805. case OPS.curveTo:
  7806. x = args[j + 4];
  7807. y = args[j + 5];
  7808. d.push('C', pf(args[j]), pf(args[j + 1]), pf(args[j + 2]),
  7809. pf(args[j + 3]), pf(x), pf(y));
  7810. j += 6;
  7811. break;
  7812. case OPS.curveTo2:
  7813. x = args[j + 2];
  7814. y = args[j + 3];
  7815. d.push('C', pf(x), pf(y), pf(args[j]), pf(args[j + 1]),
  7816. pf(args[j + 2]), pf(args[j + 3]));
  7817. j += 4;
  7818. break;
  7819. case OPS.curveTo3:
  7820. x = args[j + 2];
  7821. y = args[j + 3];
  7822. d.push('C', pf(args[j]), pf(args[j + 1]), pf(x), pf(y),
  7823. pf(x), pf(y));
  7824. j += 4;
  7825. break;
  7826. case OPS.closePath:
  7827. d.push('Z');
  7828. break;
  7829. }
  7830. }
  7831. current.path.setAttributeNS(null, 'd', d.join(' '));
  7832. current.path.setAttributeNS(null, 'stroke-miterlimit',
  7833. pf(current.miterLimit));
  7834. current.path.setAttributeNS(null, 'stroke-linecap', current.lineCap);
  7835. current.path.setAttributeNS(null, 'stroke-linejoin', current.lineJoin);
  7836. current.path.setAttributeNS(null, 'stroke-width',
  7837. pf(current.lineWidth) + 'px');
  7838. current.path.setAttributeNS(null, 'stroke-dasharray',
  7839. current.dashArray.map(pf).join(' '));
  7840. current.path.setAttributeNS(null, 'stroke-dashoffset',
  7841. pf(current.dashPhase) + 'px');
  7842. current.path.setAttributeNS(null, 'fill', 'none');
  7843. this.tgrp.appendChild(current.path);
  7844. if (current.pendingClip) {
  7845. this.cgrp.appendChild(this.tgrp);
  7846. this.pgrp.appendChild(this.cgrp);
  7847. } else {
  7848. this.pgrp.appendChild(this.tgrp);
  7849. }
  7850. // Saving a reference in current.element so that it can be addressed
  7851. // in 'fill' and 'stroke'
  7852. current.element = current.path;
  7853. current.setCurrentPoint(x, y);
  7854. },
  7855. endPath: function SVGGraphics_endPath() {
  7856. var current = this.current;
  7857. if (current.pendingClip) {
  7858. this.cgrp.appendChild(this.tgrp);
  7859. this.pgrp.appendChild(this.cgrp);
  7860. } else {
  7861. this.pgrp.appendChild(this.tgrp);
  7862. }
  7863. this.tgrp = document.createElementNS(NS, 'svg:g');
  7864. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  7865. },
  7866. clip: function SVGGraphics_clip(type) {
  7867. var current = this.current;
  7868. // Add current path to clipping path
  7869. current.clipId = 'clippath' + clipCount;
  7870. clipCount++;
  7871. this.clippath = document.createElementNS(NS, 'svg:clipPath');
  7872. this.clippath.setAttributeNS(null, 'id', current.clipId);
  7873. var clipElement = current.element.cloneNode();
  7874. if (type === 'evenodd') {
  7875. clipElement.setAttributeNS(null, 'clip-rule', 'evenodd');
  7876. } else {
  7877. clipElement.setAttributeNS(null, 'clip-rule', 'nonzero');
  7878. }
  7879. this.clippath.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  7880. this.clippath.appendChild(clipElement);
  7881. this.defs.appendChild(this.clippath);
  7882. // Create a new group with that attribute
  7883. current.pendingClip = true;
  7884. this.cgrp = document.createElementNS(NS, 'svg:g');
  7885. this.cgrp.setAttributeNS(null, 'clip-path',
  7886. 'url(#' + current.clipId + ')');
  7887. this.pgrp.appendChild(this.cgrp);
  7888. },
  7889. closePath: function SVGGraphics_closePath() {
  7890. var current = this.current;
  7891. var d = current.path.getAttributeNS(null, 'd');
  7892. d += 'Z';
  7893. current.path.setAttributeNS(null, 'd', d);
  7894. },
  7895. setLeading: function SVGGraphics_setLeading(leading) {
  7896. this.current.leading = -leading;
  7897. },
  7898. setTextRise: function SVGGraphics_setTextRise(textRise) {
  7899. this.current.textRise = textRise;
  7900. },
  7901. setHScale: function SVGGraphics_setHScale(scale) {
  7902. this.current.textHScale = scale / 100;
  7903. },
  7904. setGState: function SVGGraphics_setGState(states) {
  7905. for (var i = 0, ii = states.length; i < ii; i++) {
  7906. var state = states[i];
  7907. var key = state[0];
  7908. var value = state[1];
  7909. switch (key) {
  7910. case 'LW':
  7911. this.setLineWidth(value);
  7912. break;
  7913. case 'LC':
  7914. this.setLineCap(value);
  7915. break;
  7916. case 'LJ':
  7917. this.setLineJoin(value);
  7918. break;
  7919. case 'ML':
  7920. this.setMiterLimit(value);
  7921. break;
  7922. case 'D':
  7923. this.setDash(value[0], value[1]);
  7924. break;
  7925. case 'RI':
  7926. break;
  7927. case 'FL':
  7928. break;
  7929. case 'Font':
  7930. this.setFont(value);
  7931. break;
  7932. case 'CA':
  7933. break;
  7934. case 'ca':
  7935. break;
  7936. case 'BM':
  7937. break;
  7938. case 'SMask':
  7939. break;
  7940. }
  7941. }
  7942. },
  7943. fill: function SVGGraphics_fill() {
  7944. var current = this.current;
  7945. current.element.setAttributeNS(null, 'fill', current.fillColor);
  7946. },
  7947. stroke: function SVGGraphics_stroke() {
  7948. var current = this.current;
  7949. current.element.setAttributeNS(null, 'stroke', current.strokeColor);
  7950. current.element.setAttributeNS(null, 'fill', 'none');
  7951. },
  7952. eoFill: function SVGGraphics_eoFill() {
  7953. var current = this.current;
  7954. current.element.setAttributeNS(null, 'fill', current.fillColor);
  7955. current.element.setAttributeNS(null, 'fill-rule', 'evenodd');
  7956. },
  7957. fillStroke: function SVGGraphics_fillStroke() {
  7958. // Order is important since stroke wants fill to be none.
  7959. // First stroke, then if fill needed, it will be overwritten.
  7960. this.stroke();
  7961. this.fill();
  7962. },
  7963. eoFillStroke: function SVGGraphics_eoFillStroke() {
  7964. this.current.element.setAttributeNS(null, 'fill-rule', 'evenodd');
  7965. this.fillStroke();
  7966. },
  7967. closeStroke: function SVGGraphics_closeStroke() {
  7968. this.closePath();
  7969. this.stroke();
  7970. },
  7971. closeFillStroke: function SVGGraphics_closeFillStroke() {
  7972. this.closePath();
  7973. this.fillStroke();
  7974. },
  7975. paintSolidColorImageMask:
  7976. function SVGGraphics_paintSolidColorImageMask() {
  7977. var current = this.current;
  7978. var rect = document.createElementNS(NS, 'svg:rect');
  7979. rect.setAttributeNS(null, 'x', '0');
  7980. rect.setAttributeNS(null, 'y', '0');
  7981. rect.setAttributeNS(null, 'width', '1px');
  7982. rect.setAttributeNS(null, 'height', '1px');
  7983. rect.setAttributeNS(null, 'fill', current.fillColor);
  7984. this.tgrp.appendChild(rect);
  7985. },
  7986. paintJpegXObject: function SVGGraphics_paintJpegXObject(objId, w, h) {
  7987. var current = this.current;
  7988. var imgObj = this.objs.get(objId);
  7989. var imgEl = document.createElementNS(NS, 'svg:image');
  7990. imgEl.setAttributeNS(XLINK_NS, 'xlink:href', imgObj.src);
  7991. imgEl.setAttributeNS(null, 'width', imgObj.width + 'px');
  7992. imgEl.setAttributeNS(null, 'height', imgObj.height + 'px');
  7993. imgEl.setAttributeNS(null, 'x', '0');
  7994. imgEl.setAttributeNS(null, 'y', pf(-h));
  7995. imgEl.setAttributeNS(null, 'transform',
  7996. 'scale(' + pf(1 / w) + ' ' + pf(-1 / h) + ')');
  7997. this.tgrp.appendChild(imgEl);
  7998. if (current.pendingClip) {
  7999. this.cgrp.appendChild(this.tgrp);
  8000. this.pgrp.appendChild(this.cgrp);
  8001. } else {
  8002. this.pgrp.appendChild(this.tgrp);
  8003. }
  8004. },
  8005. paintImageXObject: function SVGGraphics_paintImageXObject(objId) {
  8006. var imgData = this.objs.get(objId);
  8007. if (!imgData) {
  8008. warn('Dependent image isn\'t ready yet');
  8009. return;
  8010. }
  8011. this.paintInlineImageXObject(imgData);
  8012. },
  8013. paintInlineImageXObject:
  8014. function SVGGraphics_paintInlineImageXObject(imgData, mask) {
  8015. var current = this.current;
  8016. var width = imgData.width;
  8017. var height = imgData.height;
  8018. var imgSrc = convertImgDataToPng(imgData);
  8019. var cliprect = document.createElementNS(NS, 'svg:rect');
  8020. cliprect.setAttributeNS(null, 'x', '0');
  8021. cliprect.setAttributeNS(null, 'y', '0');
  8022. cliprect.setAttributeNS(null, 'width', pf(width));
  8023. cliprect.setAttributeNS(null, 'height', pf(height));
  8024. current.element = cliprect;
  8025. this.clip('nonzero');
  8026. var imgEl = document.createElementNS(NS, 'svg:image');
  8027. imgEl.setAttributeNS(XLINK_NS, 'xlink:href', imgSrc);
  8028. imgEl.setAttributeNS(null, 'x', '0');
  8029. imgEl.setAttributeNS(null, 'y', pf(-height));
  8030. imgEl.setAttributeNS(null, 'width', pf(width) + 'px');
  8031. imgEl.setAttributeNS(null, 'height', pf(height) + 'px');
  8032. imgEl.setAttributeNS(null, 'transform',
  8033. 'scale(' + pf(1 / width) + ' ' +
  8034. pf(-1 / height) + ')');
  8035. if (mask) {
  8036. mask.appendChild(imgEl);
  8037. } else {
  8038. this.tgrp.appendChild(imgEl);
  8039. }
  8040. if (current.pendingClip) {
  8041. this.cgrp.appendChild(this.tgrp);
  8042. this.pgrp.appendChild(this.cgrp);
  8043. } else {
  8044. this.pgrp.appendChild(this.tgrp);
  8045. }
  8046. },
  8047. paintImageMaskXObject:
  8048. function SVGGraphics_paintImageMaskXObject(imgData) {
  8049. var current = this.current;
  8050. var width = imgData.width;
  8051. var height = imgData.height;
  8052. var fillColor = current.fillColor;
  8053. current.maskId = 'mask' + maskCount++;
  8054. var mask = document.createElementNS(NS, 'svg:mask');
  8055. mask.setAttributeNS(null, 'id', current.maskId);
  8056. var rect = document.createElementNS(NS, 'svg:rect');
  8057. rect.setAttributeNS(null, 'x', '0');
  8058. rect.setAttributeNS(null, 'y', '0');
  8059. rect.setAttributeNS(null, 'width', pf(width));
  8060. rect.setAttributeNS(null, 'height', pf(height));
  8061. rect.setAttributeNS(null, 'fill', fillColor);
  8062. rect.setAttributeNS(null, 'mask', 'url(#' + current.maskId +')');
  8063. this.defs.appendChild(mask);
  8064. this.tgrp.appendChild(rect);
  8065. this.paintInlineImageXObject(imgData, mask);
  8066. },
  8067. paintFormXObjectBegin:
  8068. function SVGGraphics_paintFormXObjectBegin(matrix, bbox) {
  8069. this.save();
  8070. if (isArray(matrix) && matrix.length === 6) {
  8071. this.transform(matrix[0], matrix[1], matrix[2],
  8072. matrix[3], matrix[4], matrix[5]);
  8073. }
  8074. if (isArray(bbox) && bbox.length === 4) {
  8075. var width = bbox[2] - bbox[0];
  8076. var height = bbox[3] - bbox[1];
  8077. var cliprect = document.createElementNS(NS, 'svg:rect');
  8078. cliprect.setAttributeNS(null, 'x', bbox[0]);
  8079. cliprect.setAttributeNS(null, 'y', bbox[1]);
  8080. cliprect.setAttributeNS(null, 'width', pf(width));
  8081. cliprect.setAttributeNS(null, 'height', pf(height));
  8082. this.current.element = cliprect;
  8083. this.clip('nonzero');
  8084. this.endPath();
  8085. }
  8086. },
  8087. paintFormXObjectEnd:
  8088. function SVGGraphics_paintFormXObjectEnd() {
  8089. this.restore();
  8090. }
  8091. };
  8092. return SVGGraphics;
  8093. })();
  8094. PDFJS.SVGGraphics = SVGGraphics;
  8095. exports.SVGGraphics = SVGGraphics;
  8096. }));
  8097. var NetworkManager = (function NetworkManagerClosure() {
  8098. var OK_RESPONSE = 200;
  8099. var PARTIAL_CONTENT_RESPONSE = 206;
  8100. function NetworkManager(url, args) {
  8101. this.url = url;
  8102. args = args || {};
  8103. this.isHttp = /^https?:/i.test(url);
  8104. this.httpHeaders = (this.isHttp && args.httpHeaders) || {};
  8105. this.withCredentials = args.withCredentials || false;
  8106. this.getXhr = args.getXhr ||
  8107. function NetworkManager_getXhr() {
  8108. return new XMLHttpRequest();
  8109. };
  8110. this.currXhrId = 0;
  8111. this.pendingRequests = {};
  8112. this.loadedRequests = {};
  8113. }
  8114. function getArrayBuffer(xhr) {
  8115. var data = xhr.response;
  8116. if (typeof data !== 'string') {
  8117. return data;
  8118. }
  8119. var length = data.length;
  8120. var array = new Uint8Array(length);
  8121. for (var i = 0; i < length; i++) {
  8122. array[i] = data.charCodeAt(i) & 0xFF;
  8123. }
  8124. return array.buffer;
  8125. }
  8126. var supportsMozChunked = (function supportsMozChunkedClosure() {
  8127. try {
  8128. var x = new XMLHttpRequest();
  8129. // Firefox 37- required .open() to be called before setting responseType.
  8130. // https://bugzilla.mozilla.org/show_bug.cgi?id=707484
  8131. // Even though the URL is not visited, .open() could fail if the URL is
  8132. // blocked, e.g. via the connect-src CSP directive or the NoScript addon.
  8133. // When this error occurs, this feature detection method will mistakenly
  8134. // report that moz-chunked-arraybuffer is not supported in Firefox 37-.
  8135. x.open('GET', 'https://example.com');
  8136. x.responseType = 'moz-chunked-arraybuffer';
  8137. return x.responseType === 'moz-chunked-arraybuffer';
  8138. } catch (e) {
  8139. return false;
  8140. }
  8141. })();
  8142. NetworkManager.prototype = {
  8143. requestRange: function NetworkManager_requestRange(begin, end, listeners) {
  8144. var args = {
  8145. begin: begin,
  8146. end: end
  8147. };
  8148. for (var prop in listeners) {
  8149. args[prop] = listeners[prop];
  8150. }
  8151. return this.request(args);
  8152. },
  8153. requestFull: function NetworkManager_requestFull(listeners) {
  8154. return this.request(listeners);
  8155. },
  8156. request: function NetworkManager_request(args) {
  8157. var xhr = this.getXhr();
  8158. var xhrId = this.currXhrId++;
  8159. var pendingRequest = this.pendingRequests[xhrId] = {
  8160. xhr: xhr
  8161. };
  8162. xhr.open('GET', this.url);
  8163. xhr.withCredentials = this.withCredentials;
  8164. for (var property in this.httpHeaders) {
  8165. var value = this.httpHeaders[property];
  8166. if (typeof value === 'undefined') {
  8167. continue;
  8168. }
  8169. xhr.setRequestHeader(property, value);
  8170. }
  8171. if (this.isHttp && 'begin' in args && 'end' in args) {
  8172. var rangeStr = args.begin + '-' + (args.end - 1);
  8173. xhr.setRequestHeader('Range', 'bytes=' + rangeStr);
  8174. pendingRequest.expectedStatus = 206;
  8175. } else {
  8176. pendingRequest.expectedStatus = 200;
  8177. }
  8178. var useMozChunkedLoading = supportsMozChunked && !!args.onProgressiveData;
  8179. if (useMozChunkedLoading) {
  8180. xhr.responseType = 'moz-chunked-arraybuffer';
  8181. pendingRequest.onProgressiveData = args.onProgressiveData;
  8182. pendingRequest.mozChunked = true;
  8183. } else {
  8184. xhr.responseType = 'arraybuffer';
  8185. }
  8186. if (args.onError) {
  8187. xhr.onerror = function(evt) {
  8188. args.onError(xhr.status);
  8189. };
  8190. }
  8191. xhr.onreadystatechange = this.onStateChange.bind(this, xhrId);
  8192. xhr.onprogress = this.onProgress.bind(this, xhrId);
  8193. pendingRequest.onHeadersReceived = args.onHeadersReceived;
  8194. pendingRequest.onDone = args.onDone;
  8195. pendingRequest.onError = args.onError;
  8196. pendingRequest.onProgress = args.onProgress;
  8197. xhr.send(null);
  8198. return xhrId;
  8199. },
  8200. onProgress: function NetworkManager_onProgress(xhrId, evt) {
  8201. var pendingRequest = this.pendingRequests[xhrId];
  8202. if (!pendingRequest) {
  8203. // Maybe abortRequest was called...
  8204. return;
  8205. }
  8206. if (pendingRequest.mozChunked) {
  8207. var chunk = getArrayBuffer(pendingRequest.xhr);
  8208. pendingRequest.onProgressiveData(chunk);
  8209. }
  8210. var onProgress = pendingRequest.onProgress;
  8211. if (onProgress) {
  8212. onProgress(evt);
  8213. }
  8214. },
  8215. onStateChange: function NetworkManager_onStateChange(xhrId, evt) {
  8216. var pendingRequest = this.pendingRequests[xhrId];
  8217. if (!pendingRequest) {
  8218. // Maybe abortRequest was called...
  8219. return;
  8220. }
  8221. var xhr = pendingRequest.xhr;
  8222. if (xhr.readyState >= 2 && pendingRequest.onHeadersReceived) {
  8223. pendingRequest.onHeadersReceived();
  8224. delete pendingRequest.onHeadersReceived;
  8225. }
  8226. if (xhr.readyState !== 4) {
  8227. return;
  8228. }
  8229. if (!(xhrId in this.pendingRequests)) {
  8230. // The XHR request might have been aborted in onHeadersReceived()
  8231. // callback, in which case we should abort request
  8232. return;
  8233. }
  8234. delete this.pendingRequests[xhrId];
  8235. // success status == 0 can be on ftp, file and other protocols
  8236. if (xhr.status === 0 && this.isHttp) {
  8237. if (pendingRequest.onError) {
  8238. pendingRequest.onError(xhr.status);
  8239. }
  8240. return;
  8241. }
  8242. var xhrStatus = xhr.status || OK_RESPONSE;
  8243. // From http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35.2:
  8244. // "A server MAY ignore the Range header". This means it's possible to
  8245. // get a 200 rather than a 206 response from a range request.
  8246. var ok_response_on_range_request =
  8247. xhrStatus === OK_RESPONSE &&
  8248. pendingRequest.expectedStatus === PARTIAL_CONTENT_RESPONSE;
  8249. if (!ok_response_on_range_request &&
  8250. xhrStatus !== pendingRequest.expectedStatus) {
  8251. if (pendingRequest.onError) {
  8252. pendingRequest.onError(xhr.status);
  8253. }
  8254. return;
  8255. }
  8256. this.loadedRequests[xhrId] = true;
  8257. var chunk = getArrayBuffer(xhr);
  8258. if (xhrStatus === PARTIAL_CONTENT_RESPONSE) {
  8259. var rangeHeader = xhr.getResponseHeader('Content-Range');
  8260. var matches = /bytes (\d+)-(\d+)\/(\d+)/.exec(rangeHeader);
  8261. var begin = parseInt(matches[1], 10);
  8262. pendingRequest.onDone({
  8263. begin: begin,
  8264. chunk: chunk
  8265. });
  8266. } else if (pendingRequest.onProgressiveData) {
  8267. pendingRequest.onDone(null);
  8268. } else if (chunk) {
  8269. pendingRequest.onDone({
  8270. begin: 0,
  8271. chunk: chunk
  8272. });
  8273. } else if (pendingRequest.onError) {
  8274. pendingRequest.onError(xhr.status);
  8275. }
  8276. },
  8277. hasPendingRequests: function NetworkManager_hasPendingRequests() {
  8278. for (var xhrId in this.pendingRequests) {
  8279. return true;
  8280. }
  8281. return false;
  8282. },
  8283. getRequestXhr: function NetworkManager_getXhr(xhrId) {
  8284. return this.pendingRequests[xhrId].xhr;
  8285. },
  8286. isStreamingRequest: function NetworkManager_isStreamingRequest(xhrId) {
  8287. return !!(this.pendingRequests[xhrId].onProgressiveData);
  8288. },
  8289. isPendingRequest: function NetworkManager_isPendingRequest(xhrId) {
  8290. return xhrId in this.pendingRequests;
  8291. },
  8292. isLoadedRequest: function NetworkManager_isLoadedRequest(xhrId) {
  8293. return xhrId in this.loadedRequests;
  8294. },
  8295. abortAllRequests: function NetworkManager_abortAllRequests() {
  8296. for (var xhrId in this.pendingRequests) {
  8297. this.abortRequest(xhrId | 0);
  8298. }
  8299. },
  8300. abortRequest: function NetworkManager_abortRequest(xhrId) {
  8301. var xhr = this.pendingRequests[xhrId].xhr;
  8302. delete this.pendingRequests[xhrId];
  8303. xhr.abort();
  8304. }
  8305. };
  8306. return NetworkManager;
  8307. })();
  8308. (function (root, factory) {
  8309. {
  8310. factory((root.pdfjsCoreArithmeticDecoder = {}));
  8311. }
  8312. }(this, function (exports) {
  8313. /* This class implements the QM Coder decoding as defined in
  8314. * JPEG 2000 Part I Final Committee Draft Version 1.0
  8315. * Annex C.3 Arithmetic decoding procedure
  8316. * available at http://www.jpeg.org/public/fcd15444-1.pdf
  8317. *
  8318. * The arithmetic decoder is used in conjunction with context models to decode
  8319. * JPEG2000 and JBIG2 streams.
  8320. */
  8321. var ArithmeticDecoder = (function ArithmeticDecoderClosure() {
  8322. // Table C-2
  8323. var QeTable = [
  8324. {qe: 0x5601, nmps: 1, nlps: 1, switchFlag: 1},
  8325. {qe: 0x3401, nmps: 2, nlps: 6, switchFlag: 0},
  8326. {qe: 0x1801, nmps: 3, nlps: 9, switchFlag: 0},
  8327. {qe: 0x0AC1, nmps: 4, nlps: 12, switchFlag: 0},
  8328. {qe: 0x0521, nmps: 5, nlps: 29, switchFlag: 0},
  8329. {qe: 0x0221, nmps: 38, nlps: 33, switchFlag: 0},
  8330. {qe: 0x5601, nmps: 7, nlps: 6, switchFlag: 1},
  8331. {qe: 0x5401, nmps: 8, nlps: 14, switchFlag: 0},
  8332. {qe: 0x4801, nmps: 9, nlps: 14, switchFlag: 0},
  8333. {qe: 0x3801, nmps: 10, nlps: 14, switchFlag: 0},
  8334. {qe: 0x3001, nmps: 11, nlps: 17, switchFlag: 0},
  8335. {qe: 0x2401, nmps: 12, nlps: 18, switchFlag: 0},
  8336. {qe: 0x1C01, nmps: 13, nlps: 20, switchFlag: 0},
  8337. {qe: 0x1601, nmps: 29, nlps: 21, switchFlag: 0},
  8338. {qe: 0x5601, nmps: 15, nlps: 14, switchFlag: 1},
  8339. {qe: 0x5401, nmps: 16, nlps: 14, switchFlag: 0},
  8340. {qe: 0x5101, nmps: 17, nlps: 15, switchFlag: 0},
  8341. {qe: 0x4801, nmps: 18, nlps: 16, switchFlag: 0},
  8342. {qe: 0x3801, nmps: 19, nlps: 17, switchFlag: 0},
  8343. {qe: 0x3401, nmps: 20, nlps: 18, switchFlag: 0},
  8344. {qe: 0x3001, nmps: 21, nlps: 19, switchFlag: 0},
  8345. {qe: 0x2801, nmps: 22, nlps: 19, switchFlag: 0},
  8346. {qe: 0x2401, nmps: 23, nlps: 20, switchFlag: 0},
  8347. {qe: 0x2201, nmps: 24, nlps: 21, switchFlag: 0},
  8348. {qe: 0x1C01, nmps: 25, nlps: 22, switchFlag: 0},
  8349. {qe: 0x1801, nmps: 26, nlps: 23, switchFlag: 0},
  8350. {qe: 0x1601, nmps: 27, nlps: 24, switchFlag: 0},
  8351. {qe: 0x1401, nmps: 28, nlps: 25, switchFlag: 0},
  8352. {qe: 0x1201, nmps: 29, nlps: 26, switchFlag: 0},
  8353. {qe: 0x1101, nmps: 30, nlps: 27, switchFlag: 0},
  8354. {qe: 0x0AC1, nmps: 31, nlps: 28, switchFlag: 0},
  8355. {qe: 0x09C1, nmps: 32, nlps: 29, switchFlag: 0},
  8356. {qe: 0x08A1, nmps: 33, nlps: 30, switchFlag: 0},
  8357. {qe: 0x0521, nmps: 34, nlps: 31, switchFlag: 0},
  8358. {qe: 0x0441, nmps: 35, nlps: 32, switchFlag: 0},
  8359. {qe: 0x02A1, nmps: 36, nlps: 33, switchFlag: 0},
  8360. {qe: 0x0221, nmps: 37, nlps: 34, switchFlag: 0},
  8361. {qe: 0x0141, nmps: 38, nlps: 35, switchFlag: 0},
  8362. {qe: 0x0111, nmps: 39, nlps: 36, switchFlag: 0},
  8363. {qe: 0x0085, nmps: 40, nlps: 37, switchFlag: 0},
  8364. {qe: 0x0049, nmps: 41, nlps: 38, switchFlag: 0},
  8365. {qe: 0x0025, nmps: 42, nlps: 39, switchFlag: 0},
  8366. {qe: 0x0015, nmps: 43, nlps: 40, switchFlag: 0},
  8367. {qe: 0x0009, nmps: 44, nlps: 41, switchFlag: 0},
  8368. {qe: 0x0005, nmps: 45, nlps: 42, switchFlag: 0},
  8369. {qe: 0x0001, nmps: 45, nlps: 43, switchFlag: 0},
  8370. {qe: 0x5601, nmps: 46, nlps: 46, switchFlag: 0}
  8371. ];
  8372. // C.3.5 Initialisation of the decoder (INITDEC)
  8373. function ArithmeticDecoder(data, start, end) {
  8374. this.data = data;
  8375. this.bp = start;
  8376. this.dataEnd = end;
  8377. this.chigh = data[start];
  8378. this.clow = 0;
  8379. this.byteIn();
  8380. this.chigh = ((this.chigh << 7) & 0xFFFF) | ((this.clow >> 9) & 0x7F);
  8381. this.clow = (this.clow << 7) & 0xFFFF;
  8382. this.ct -= 7;
  8383. this.a = 0x8000;
  8384. }
  8385. ArithmeticDecoder.prototype = {
  8386. // C.3.4 Compressed data input (BYTEIN)
  8387. byteIn: function ArithmeticDecoder_byteIn() {
  8388. var data = this.data;
  8389. var bp = this.bp;
  8390. if (data[bp] === 0xFF) {
  8391. var b1 = data[bp + 1];
  8392. if (b1 > 0x8F) {
  8393. this.clow += 0xFF00;
  8394. this.ct = 8;
  8395. } else {
  8396. bp++;
  8397. this.clow += (data[bp] << 9);
  8398. this.ct = 7;
  8399. this.bp = bp;
  8400. }
  8401. } else {
  8402. bp++;
  8403. this.clow += bp < this.dataEnd ? (data[bp] << 8) : 0xFF00;
  8404. this.ct = 8;
  8405. this.bp = bp;
  8406. }
  8407. if (this.clow > 0xFFFF) {
  8408. this.chigh += (this.clow >> 16);
  8409. this.clow &= 0xFFFF;
  8410. }
  8411. },
  8412. // C.3.2 Decoding a decision (DECODE)
  8413. readBit: function ArithmeticDecoder_readBit(contexts, pos) {
  8414. // contexts are packed into 1 byte:
  8415. // highest 7 bits carry cx.index, lowest bit carries cx.mps
  8416. var cx_index = contexts[pos] >> 1, cx_mps = contexts[pos] & 1;
  8417. var qeTableIcx = QeTable[cx_index];
  8418. var qeIcx = qeTableIcx.qe;
  8419. var d;
  8420. var a = this.a - qeIcx;
  8421. if (this.chigh < qeIcx) {
  8422. // exchangeLps
  8423. if (a < qeIcx) {
  8424. a = qeIcx;
  8425. d = cx_mps;
  8426. cx_index = qeTableIcx.nmps;
  8427. } else {
  8428. a = qeIcx;
  8429. d = 1 ^ cx_mps;
  8430. if (qeTableIcx.switchFlag === 1) {
  8431. cx_mps = d;
  8432. }
  8433. cx_index = qeTableIcx.nlps;
  8434. }
  8435. } else {
  8436. this.chigh -= qeIcx;
  8437. if ((a & 0x8000) !== 0) {
  8438. this.a = a;
  8439. return cx_mps;
  8440. }
  8441. // exchangeMps
  8442. if (a < qeIcx) {
  8443. d = 1 ^ cx_mps;
  8444. if (qeTableIcx.switchFlag === 1) {
  8445. cx_mps = d;
  8446. }
  8447. cx_index = qeTableIcx.nlps;
  8448. } else {
  8449. d = cx_mps;
  8450. cx_index = qeTableIcx.nmps;
  8451. }
  8452. }
  8453. // C.3.3 renormD;
  8454. do {
  8455. if (this.ct === 0) {
  8456. this.byteIn();
  8457. }
  8458. a <<= 1;
  8459. this.chigh = ((this.chigh << 1) & 0xFFFF) | ((this.clow >> 15) & 1);
  8460. this.clow = (this.clow << 1) & 0xFFFF;
  8461. this.ct--;
  8462. } while ((a & 0x8000) === 0);
  8463. this.a = a;
  8464. contexts[pos] = cx_index << 1 | cx_mps;
  8465. return d;
  8466. }
  8467. };
  8468. return ArithmeticDecoder;
  8469. })();
  8470. exports.ArithmeticDecoder = ArithmeticDecoder;
  8471. }));
  8472. (function (root, factory) {
  8473. {
  8474. factory((root.pdfjsCoreCharsets = {}));
  8475. }
  8476. }(this, function (exports) {
  8477. var ISOAdobeCharset = [
  8478. '.notdef', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar',
  8479. 'percent', 'ampersand', 'quoteright', 'parenleft', 'parenright',
  8480. 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash', 'zero',
  8481. 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',
  8482. 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater', 'question',
  8483. 'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
  8484. 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
  8485. 'bracketleft', 'backslash', 'bracketright', 'asciicircum', 'underscore',
  8486. 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
  8487. 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
  8488. 'braceleft', 'bar', 'braceright', 'asciitilde', 'exclamdown', 'cent',
  8489. 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  8490. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  8491. 'guilsinglright', 'fi', 'fl', 'endash', 'dagger', 'daggerdbl',
  8492. 'periodcentered', 'paragraph', 'bullet', 'quotesinglbase',
  8493. 'quotedblbase', 'quotedblright', 'guillemotright', 'ellipsis',
  8494. 'perthousand', 'questiondown', 'grave', 'acute', 'circumflex', 'tilde',
  8495. 'macron', 'breve', 'dotaccent', 'dieresis', 'ring', 'cedilla',
  8496. 'hungarumlaut', 'ogonek', 'caron', 'emdash', 'AE', 'ordfeminine',
  8497. 'Lslash', 'Oslash', 'OE', 'ordmasculine', 'ae', 'dotlessi', 'lslash',
  8498. 'oslash', 'oe', 'germandbls', 'onesuperior', 'logicalnot', 'mu',
  8499. 'trademark', 'Eth', 'onehalf', 'plusminus', 'Thorn', 'onequarter',
  8500. 'divide', 'brokenbar', 'degree', 'thorn', 'threequarters', 'twosuperior',
  8501. 'registered', 'minus', 'eth', 'multiply', 'threesuperior', 'copyright',
  8502. 'Aacute', 'Acircumflex', 'Adieresis', 'Agrave', 'Aring', 'Atilde',
  8503. 'Ccedilla', 'Eacute', 'Ecircumflex', 'Edieresis', 'Egrave', 'Iacute',
  8504. 'Icircumflex', 'Idieresis', 'Igrave', 'Ntilde', 'Oacute', 'Ocircumflex',
  8505. 'Odieresis', 'Ograve', 'Otilde', 'Scaron', 'Uacute', 'Ucircumflex',
  8506. 'Udieresis', 'Ugrave', 'Yacute', 'Ydieresis', 'Zcaron', 'aacute',
  8507. 'acircumflex', 'adieresis', 'agrave', 'aring', 'atilde', 'ccedilla',
  8508. 'eacute', 'ecircumflex', 'edieresis', 'egrave', 'iacute', 'icircumflex',
  8509. 'idieresis', 'igrave', 'ntilde', 'oacute', 'ocircumflex', 'odieresis',
  8510. 'ograve', 'otilde', 'scaron', 'uacute', 'ucircumflex', 'udieresis',
  8511. 'ugrave', 'yacute', 'ydieresis', 'zcaron'
  8512. ];
  8513. var ExpertCharset = [
  8514. '.notdef', 'space', 'exclamsmall', 'Hungarumlautsmall', 'dollaroldstyle',
  8515. 'dollarsuperior', 'ampersandsmall', 'Acutesmall', 'parenleftsuperior',
  8516. 'parenrightsuperior', 'twodotenleader', 'onedotenleader', 'comma',
  8517. 'hyphen', 'period', 'fraction', 'zerooldstyle', 'oneoldstyle',
  8518. 'twooldstyle', 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle',
  8519. 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle',
  8520. 'colon', 'semicolon', 'commasuperior', 'threequartersemdash',
  8521. 'periodsuperior', 'questionsmall', 'asuperior', 'bsuperior',
  8522. 'centsuperior', 'dsuperior', 'esuperior', 'isuperior', 'lsuperior',
  8523. 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  8524. 'tsuperior', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior',
  8525. 'parenrightinferior', 'Circumflexsmall', 'hyphensuperior', 'Gravesmall',
  8526. 'Asmall', 'Bsmall', 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall',
  8527. 'Hsmall', 'Ismall', 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall',
  8528. 'Osmall', 'Psmall', 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall',
  8529. 'Vsmall', 'Wsmall', 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary',
  8530. 'onefitted', 'rupiah', 'Tildesmall', 'exclamdownsmall', 'centoldstyle',
  8531. 'Lslashsmall', 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall',
  8532. 'Brevesmall', 'Caronsmall', 'Dotaccentsmall', 'Macronsmall',
  8533. 'figuredash', 'hypheninferior', 'Ogoneksmall', 'Ringsmall',
  8534. 'Cedillasmall', 'onequarter', 'onehalf', 'threequarters',
  8535. 'questiondownsmall', 'oneeighth', 'threeeighths', 'fiveeighths',
  8536. 'seveneighths', 'onethird', 'twothirds', 'zerosuperior', 'onesuperior',
  8537. 'twosuperior', 'threesuperior', 'foursuperior', 'fivesuperior',
  8538. 'sixsuperior', 'sevensuperior', 'eightsuperior', 'ninesuperior',
  8539. 'zeroinferior', 'oneinferior', 'twoinferior', 'threeinferior',
  8540. 'fourinferior', 'fiveinferior', 'sixinferior', 'seveninferior',
  8541. 'eightinferior', 'nineinferior', 'centinferior', 'dollarinferior',
  8542. 'periodinferior', 'commainferior', 'Agravesmall', 'Aacutesmall',
  8543. 'Acircumflexsmall', 'Atildesmall', 'Adieresissmall', 'Aringsmall',
  8544. 'AEsmall', 'Ccedillasmall', 'Egravesmall', 'Eacutesmall',
  8545. 'Ecircumflexsmall', 'Edieresissmall', 'Igravesmall', 'Iacutesmall',
  8546. 'Icircumflexsmall', 'Idieresissmall', 'Ethsmall', 'Ntildesmall',
  8547. 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall', 'Otildesmall',
  8548. 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall', 'Uacutesmall',
  8549. 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall', 'Thornsmall',
  8550. 'Ydieresissmall'
  8551. ];
  8552. var ExpertSubsetCharset = [
  8553. '.notdef', 'space', 'dollaroldstyle', 'dollarsuperior',
  8554. 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  8555. 'onedotenleader', 'comma', 'hyphen', 'period', 'fraction',
  8556. 'zerooldstyle', 'oneoldstyle', 'twooldstyle', 'threeoldstyle',
  8557. 'fouroldstyle', 'fiveoldstyle', 'sixoldstyle', 'sevenoldstyle',
  8558. 'eightoldstyle', 'nineoldstyle', 'colon', 'semicolon', 'commasuperior',
  8559. 'threequartersemdash', 'periodsuperior', 'asuperior', 'bsuperior',
  8560. 'centsuperior', 'dsuperior', 'esuperior', 'isuperior', 'lsuperior',
  8561. 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  8562. 'tsuperior', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior',
  8563. 'parenrightinferior', 'hyphensuperior', 'colonmonetary', 'onefitted',
  8564. 'rupiah', 'centoldstyle', 'figuredash', 'hypheninferior', 'onequarter',
  8565. 'onehalf', 'threequarters', 'oneeighth', 'threeeighths', 'fiveeighths',
  8566. 'seveneighths', 'onethird', 'twothirds', 'zerosuperior', 'onesuperior',
  8567. 'twosuperior', 'threesuperior', 'foursuperior', 'fivesuperior',
  8568. 'sixsuperior', 'sevensuperior', 'eightsuperior', 'ninesuperior',
  8569. 'zeroinferior', 'oneinferior', 'twoinferior', 'threeinferior',
  8570. 'fourinferior', 'fiveinferior', 'sixinferior', 'seveninferior',
  8571. 'eightinferior', 'nineinferior', 'centinferior', 'dollarinferior',
  8572. 'periodinferior', 'commainferior'
  8573. ];
  8574. exports.ISOAdobeCharset = ISOAdobeCharset;
  8575. exports.ExpertCharset = ExpertCharset;
  8576. exports.ExpertSubsetCharset = ExpertSubsetCharset;
  8577. }));
  8578. (function (root, factory) {
  8579. {
  8580. factory((root.pdfjsCoreGlyphList = {}));
  8581. }
  8582. }(this, function (exports) {
  8583. var GlyphsUnicode = {
  8584. A: 0x0041,
  8585. AE: 0x00C6,
  8586. AEacute: 0x01FC,
  8587. AEmacron: 0x01E2,
  8588. AEsmall: 0xF7E6,
  8589. Aacute: 0x00C1,
  8590. Aacutesmall: 0xF7E1,
  8591. Abreve: 0x0102,
  8592. Abreveacute: 0x1EAE,
  8593. Abrevecyrillic: 0x04D0,
  8594. Abrevedotbelow: 0x1EB6,
  8595. Abrevegrave: 0x1EB0,
  8596. Abrevehookabove: 0x1EB2,
  8597. Abrevetilde: 0x1EB4,
  8598. Acaron: 0x01CD,
  8599. Acircle: 0x24B6,
  8600. Acircumflex: 0x00C2,
  8601. Acircumflexacute: 0x1EA4,
  8602. Acircumflexdotbelow: 0x1EAC,
  8603. Acircumflexgrave: 0x1EA6,
  8604. Acircumflexhookabove: 0x1EA8,
  8605. Acircumflexsmall: 0xF7E2,
  8606. Acircumflextilde: 0x1EAA,
  8607. Acute: 0xF6C9,
  8608. Acutesmall: 0xF7B4,
  8609. Acyrillic: 0x0410,
  8610. Adblgrave: 0x0200,
  8611. Adieresis: 0x00C4,
  8612. Adieresiscyrillic: 0x04D2,
  8613. Adieresismacron: 0x01DE,
  8614. Adieresissmall: 0xF7E4,
  8615. Adotbelow: 0x1EA0,
  8616. Adotmacron: 0x01E0,
  8617. Agrave: 0x00C0,
  8618. Agravesmall: 0xF7E0,
  8619. Ahookabove: 0x1EA2,
  8620. Aiecyrillic: 0x04D4,
  8621. Ainvertedbreve: 0x0202,
  8622. Alpha: 0x0391,
  8623. Alphatonos: 0x0386,
  8624. Amacron: 0x0100,
  8625. Amonospace: 0xFF21,
  8626. Aogonek: 0x0104,
  8627. Aring: 0x00C5,
  8628. Aringacute: 0x01FA,
  8629. Aringbelow: 0x1E00,
  8630. Aringsmall: 0xF7E5,
  8631. Asmall: 0xF761,
  8632. Atilde: 0x00C3,
  8633. Atildesmall: 0xF7E3,
  8634. Aybarmenian: 0x0531,
  8635. B: 0x0042,
  8636. Bcircle: 0x24B7,
  8637. Bdotaccent: 0x1E02,
  8638. Bdotbelow: 0x1E04,
  8639. Becyrillic: 0x0411,
  8640. Benarmenian: 0x0532,
  8641. Beta: 0x0392,
  8642. Bhook: 0x0181,
  8643. Blinebelow: 0x1E06,
  8644. Bmonospace: 0xFF22,
  8645. Brevesmall: 0xF6F4,
  8646. Bsmall: 0xF762,
  8647. Btopbar: 0x0182,
  8648. C: 0x0043,
  8649. Caarmenian: 0x053E,
  8650. Cacute: 0x0106,
  8651. Caron: 0xF6CA,
  8652. Caronsmall: 0xF6F5,
  8653. Ccaron: 0x010C,
  8654. Ccedilla: 0x00C7,
  8655. Ccedillaacute: 0x1E08,
  8656. Ccedillasmall: 0xF7E7,
  8657. Ccircle: 0x24B8,
  8658. Ccircumflex: 0x0108,
  8659. Cdot: 0x010A,
  8660. Cdotaccent: 0x010A,
  8661. Cedillasmall: 0xF7B8,
  8662. Chaarmenian: 0x0549,
  8663. Cheabkhasiancyrillic: 0x04BC,
  8664. Checyrillic: 0x0427,
  8665. Chedescenderabkhasiancyrillic: 0x04BE,
  8666. Chedescendercyrillic: 0x04B6,
  8667. Chedieresiscyrillic: 0x04F4,
  8668. Cheharmenian: 0x0543,
  8669. Chekhakassiancyrillic: 0x04CB,
  8670. Cheverticalstrokecyrillic: 0x04B8,
  8671. Chi: 0x03A7,
  8672. Chook: 0x0187,
  8673. Circumflexsmall: 0xF6F6,
  8674. Cmonospace: 0xFF23,
  8675. Coarmenian: 0x0551,
  8676. Csmall: 0xF763,
  8677. D: 0x0044,
  8678. DZ: 0x01F1,
  8679. DZcaron: 0x01C4,
  8680. Daarmenian: 0x0534,
  8681. Dafrican: 0x0189,
  8682. Dcaron: 0x010E,
  8683. Dcedilla: 0x1E10,
  8684. Dcircle: 0x24B9,
  8685. Dcircumflexbelow: 0x1E12,
  8686. Dcroat: 0x0110,
  8687. Ddotaccent: 0x1E0A,
  8688. Ddotbelow: 0x1E0C,
  8689. Decyrillic: 0x0414,
  8690. Deicoptic: 0x03EE,
  8691. Delta: 0x2206,
  8692. Deltagreek: 0x0394,
  8693. Dhook: 0x018A,
  8694. Dieresis: 0xF6CB,
  8695. DieresisAcute: 0xF6CC,
  8696. DieresisGrave: 0xF6CD,
  8697. Dieresissmall: 0xF7A8,
  8698. Digammagreek: 0x03DC,
  8699. Djecyrillic: 0x0402,
  8700. Dlinebelow: 0x1E0E,
  8701. Dmonospace: 0xFF24,
  8702. Dotaccentsmall: 0xF6F7,
  8703. Dslash: 0x0110,
  8704. Dsmall: 0xF764,
  8705. Dtopbar: 0x018B,
  8706. Dz: 0x01F2,
  8707. Dzcaron: 0x01C5,
  8708. Dzeabkhasiancyrillic: 0x04E0,
  8709. Dzecyrillic: 0x0405,
  8710. Dzhecyrillic: 0x040F,
  8711. E: 0x0045,
  8712. Eacute: 0x00C9,
  8713. Eacutesmall: 0xF7E9,
  8714. Ebreve: 0x0114,
  8715. Ecaron: 0x011A,
  8716. Ecedillabreve: 0x1E1C,
  8717. Echarmenian: 0x0535,
  8718. Ecircle: 0x24BA,
  8719. Ecircumflex: 0x00CA,
  8720. Ecircumflexacute: 0x1EBE,
  8721. Ecircumflexbelow: 0x1E18,
  8722. Ecircumflexdotbelow: 0x1EC6,
  8723. Ecircumflexgrave: 0x1EC0,
  8724. Ecircumflexhookabove: 0x1EC2,
  8725. Ecircumflexsmall: 0xF7EA,
  8726. Ecircumflextilde: 0x1EC4,
  8727. Ecyrillic: 0x0404,
  8728. Edblgrave: 0x0204,
  8729. Edieresis: 0x00CB,
  8730. Edieresissmall: 0xF7EB,
  8731. Edot: 0x0116,
  8732. Edotaccent: 0x0116,
  8733. Edotbelow: 0x1EB8,
  8734. Efcyrillic: 0x0424,
  8735. Egrave: 0x00C8,
  8736. Egravesmall: 0xF7E8,
  8737. Eharmenian: 0x0537,
  8738. Ehookabove: 0x1EBA,
  8739. Eightroman: 0x2167,
  8740. Einvertedbreve: 0x0206,
  8741. Eiotifiedcyrillic: 0x0464,
  8742. Elcyrillic: 0x041B,
  8743. Elevenroman: 0x216A,
  8744. Emacron: 0x0112,
  8745. Emacronacute: 0x1E16,
  8746. Emacrongrave: 0x1E14,
  8747. Emcyrillic: 0x041C,
  8748. Emonospace: 0xFF25,
  8749. Encyrillic: 0x041D,
  8750. Endescendercyrillic: 0x04A2,
  8751. Eng: 0x014A,
  8752. Enghecyrillic: 0x04A4,
  8753. Enhookcyrillic: 0x04C7,
  8754. Eogonek: 0x0118,
  8755. Eopen: 0x0190,
  8756. Epsilon: 0x0395,
  8757. Epsilontonos: 0x0388,
  8758. Ercyrillic: 0x0420,
  8759. Ereversed: 0x018E,
  8760. Ereversedcyrillic: 0x042D,
  8761. Escyrillic: 0x0421,
  8762. Esdescendercyrillic: 0x04AA,
  8763. Esh: 0x01A9,
  8764. Esmall: 0xF765,
  8765. Eta: 0x0397,
  8766. Etarmenian: 0x0538,
  8767. Etatonos: 0x0389,
  8768. Eth: 0x00D0,
  8769. Ethsmall: 0xF7F0,
  8770. Etilde: 0x1EBC,
  8771. Etildebelow: 0x1E1A,
  8772. Euro: 0x20AC,
  8773. Ezh: 0x01B7,
  8774. Ezhcaron: 0x01EE,
  8775. Ezhreversed: 0x01B8,
  8776. F: 0x0046,
  8777. Fcircle: 0x24BB,
  8778. Fdotaccent: 0x1E1E,
  8779. Feharmenian: 0x0556,
  8780. Feicoptic: 0x03E4,
  8781. Fhook: 0x0191,
  8782. Fitacyrillic: 0x0472,
  8783. Fiveroman: 0x2164,
  8784. Fmonospace: 0xFF26,
  8785. Fourroman: 0x2163,
  8786. Fsmall: 0xF766,
  8787. G: 0x0047,
  8788. GBsquare: 0x3387,
  8789. Gacute: 0x01F4,
  8790. Gamma: 0x0393,
  8791. Gammaafrican: 0x0194,
  8792. Gangiacoptic: 0x03EA,
  8793. Gbreve: 0x011E,
  8794. Gcaron: 0x01E6,
  8795. Gcedilla: 0x0122,
  8796. Gcircle: 0x24BC,
  8797. Gcircumflex: 0x011C,
  8798. Gcommaaccent: 0x0122,
  8799. Gdot: 0x0120,
  8800. Gdotaccent: 0x0120,
  8801. Gecyrillic: 0x0413,
  8802. Ghadarmenian: 0x0542,
  8803. Ghemiddlehookcyrillic: 0x0494,
  8804. Ghestrokecyrillic: 0x0492,
  8805. Gheupturncyrillic: 0x0490,
  8806. Ghook: 0x0193,
  8807. Gimarmenian: 0x0533,
  8808. Gjecyrillic: 0x0403,
  8809. Gmacron: 0x1E20,
  8810. Gmonospace: 0xFF27,
  8811. Grave: 0xF6CE,
  8812. Gravesmall: 0xF760,
  8813. Gsmall: 0xF767,
  8814. Gsmallhook: 0x029B,
  8815. Gstroke: 0x01E4,
  8816. H: 0x0048,
  8817. H18533: 0x25CF,
  8818. H18543: 0x25AA,
  8819. H18551: 0x25AB,
  8820. H22073: 0x25A1,
  8821. HPsquare: 0x33CB,
  8822. Haabkhasiancyrillic: 0x04A8,
  8823. Hadescendercyrillic: 0x04B2,
  8824. Hardsigncyrillic: 0x042A,
  8825. Hbar: 0x0126,
  8826. Hbrevebelow: 0x1E2A,
  8827. Hcedilla: 0x1E28,
  8828. Hcircle: 0x24BD,
  8829. Hcircumflex: 0x0124,
  8830. Hdieresis: 0x1E26,
  8831. Hdotaccent: 0x1E22,
  8832. Hdotbelow: 0x1E24,
  8833. Hmonospace: 0xFF28,
  8834. Hoarmenian: 0x0540,
  8835. Horicoptic: 0x03E8,
  8836. Hsmall: 0xF768,
  8837. Hungarumlaut: 0xF6CF,
  8838. Hungarumlautsmall: 0xF6F8,
  8839. Hzsquare: 0x3390,
  8840. I: 0x0049,
  8841. IAcyrillic: 0x042F,
  8842. IJ: 0x0132,
  8843. IUcyrillic: 0x042E,
  8844. Iacute: 0x00CD,
  8845. Iacutesmall: 0xF7ED,
  8846. Ibreve: 0x012C,
  8847. Icaron: 0x01CF,
  8848. Icircle: 0x24BE,
  8849. Icircumflex: 0x00CE,
  8850. Icircumflexsmall: 0xF7EE,
  8851. Icyrillic: 0x0406,
  8852. Idblgrave: 0x0208,
  8853. Idieresis: 0x00CF,
  8854. Idieresisacute: 0x1E2E,
  8855. Idieresiscyrillic: 0x04E4,
  8856. Idieresissmall: 0xF7EF,
  8857. Idot: 0x0130,
  8858. Idotaccent: 0x0130,
  8859. Idotbelow: 0x1ECA,
  8860. Iebrevecyrillic: 0x04D6,
  8861. Iecyrillic: 0x0415,
  8862. Ifraktur: 0x2111,
  8863. Igrave: 0x00CC,
  8864. Igravesmall: 0xF7EC,
  8865. Ihookabove: 0x1EC8,
  8866. Iicyrillic: 0x0418,
  8867. Iinvertedbreve: 0x020A,
  8868. Iishortcyrillic: 0x0419,
  8869. Imacron: 0x012A,
  8870. Imacroncyrillic: 0x04E2,
  8871. Imonospace: 0xFF29,
  8872. Iniarmenian: 0x053B,
  8873. Iocyrillic: 0x0401,
  8874. Iogonek: 0x012E,
  8875. Iota: 0x0399,
  8876. Iotaafrican: 0x0196,
  8877. Iotadieresis: 0x03AA,
  8878. Iotatonos: 0x038A,
  8879. Ismall: 0xF769,
  8880. Istroke: 0x0197,
  8881. Itilde: 0x0128,
  8882. Itildebelow: 0x1E2C,
  8883. Izhitsacyrillic: 0x0474,
  8884. Izhitsadblgravecyrillic: 0x0476,
  8885. J: 0x004A,
  8886. Jaarmenian: 0x0541,
  8887. Jcircle: 0x24BF,
  8888. Jcircumflex: 0x0134,
  8889. Jecyrillic: 0x0408,
  8890. Jheharmenian: 0x054B,
  8891. Jmonospace: 0xFF2A,
  8892. Jsmall: 0xF76A,
  8893. K: 0x004B,
  8894. KBsquare: 0x3385,
  8895. KKsquare: 0x33CD,
  8896. Kabashkircyrillic: 0x04A0,
  8897. Kacute: 0x1E30,
  8898. Kacyrillic: 0x041A,
  8899. Kadescendercyrillic: 0x049A,
  8900. Kahookcyrillic: 0x04C3,
  8901. Kappa: 0x039A,
  8902. Kastrokecyrillic: 0x049E,
  8903. Kaverticalstrokecyrillic: 0x049C,
  8904. Kcaron: 0x01E8,
  8905. Kcedilla: 0x0136,
  8906. Kcircle: 0x24C0,
  8907. Kcommaaccent: 0x0136,
  8908. Kdotbelow: 0x1E32,
  8909. Keharmenian: 0x0554,
  8910. Kenarmenian: 0x053F,
  8911. Khacyrillic: 0x0425,
  8912. Kheicoptic: 0x03E6,
  8913. Khook: 0x0198,
  8914. Kjecyrillic: 0x040C,
  8915. Klinebelow: 0x1E34,
  8916. Kmonospace: 0xFF2B,
  8917. Koppacyrillic: 0x0480,
  8918. Koppagreek: 0x03DE,
  8919. Ksicyrillic: 0x046E,
  8920. Ksmall: 0xF76B,
  8921. L: 0x004C,
  8922. LJ: 0x01C7,
  8923. LL: 0xF6BF,
  8924. Lacute: 0x0139,
  8925. Lambda: 0x039B,
  8926. Lcaron: 0x013D,
  8927. Lcedilla: 0x013B,
  8928. Lcircle: 0x24C1,
  8929. Lcircumflexbelow: 0x1E3C,
  8930. Lcommaaccent: 0x013B,
  8931. Ldot: 0x013F,
  8932. Ldotaccent: 0x013F,
  8933. Ldotbelow: 0x1E36,
  8934. Ldotbelowmacron: 0x1E38,
  8935. Liwnarmenian: 0x053C,
  8936. Lj: 0x01C8,
  8937. Ljecyrillic: 0x0409,
  8938. Llinebelow: 0x1E3A,
  8939. Lmonospace: 0xFF2C,
  8940. Lslash: 0x0141,
  8941. Lslashsmall: 0xF6F9,
  8942. Lsmall: 0xF76C,
  8943. M: 0x004D,
  8944. MBsquare: 0x3386,
  8945. Macron: 0xF6D0,
  8946. Macronsmall: 0xF7AF,
  8947. Macute: 0x1E3E,
  8948. Mcircle: 0x24C2,
  8949. Mdotaccent: 0x1E40,
  8950. Mdotbelow: 0x1E42,
  8951. Menarmenian: 0x0544,
  8952. Mmonospace: 0xFF2D,
  8953. Msmall: 0xF76D,
  8954. Mturned: 0x019C,
  8955. Mu: 0x039C,
  8956. N: 0x004E,
  8957. NJ: 0x01CA,
  8958. Nacute: 0x0143,
  8959. Ncaron: 0x0147,
  8960. Ncedilla: 0x0145,
  8961. Ncircle: 0x24C3,
  8962. Ncircumflexbelow: 0x1E4A,
  8963. Ncommaaccent: 0x0145,
  8964. Ndotaccent: 0x1E44,
  8965. Ndotbelow: 0x1E46,
  8966. Nhookleft: 0x019D,
  8967. Nineroman: 0x2168,
  8968. Nj: 0x01CB,
  8969. Njecyrillic: 0x040A,
  8970. Nlinebelow: 0x1E48,
  8971. Nmonospace: 0xFF2E,
  8972. Nowarmenian: 0x0546,
  8973. Nsmall: 0xF76E,
  8974. Ntilde: 0x00D1,
  8975. Ntildesmall: 0xF7F1,
  8976. Nu: 0x039D,
  8977. O: 0x004F,
  8978. OE: 0x0152,
  8979. OEsmall: 0xF6FA,
  8980. Oacute: 0x00D3,
  8981. Oacutesmall: 0xF7F3,
  8982. Obarredcyrillic: 0x04E8,
  8983. Obarreddieresiscyrillic: 0x04EA,
  8984. Obreve: 0x014E,
  8985. Ocaron: 0x01D1,
  8986. Ocenteredtilde: 0x019F,
  8987. Ocircle: 0x24C4,
  8988. Ocircumflex: 0x00D4,
  8989. Ocircumflexacute: 0x1ED0,
  8990. Ocircumflexdotbelow: 0x1ED8,
  8991. Ocircumflexgrave: 0x1ED2,
  8992. Ocircumflexhookabove: 0x1ED4,
  8993. Ocircumflexsmall: 0xF7F4,
  8994. Ocircumflextilde: 0x1ED6,
  8995. Ocyrillic: 0x041E,
  8996. Odblacute: 0x0150,
  8997. Odblgrave: 0x020C,
  8998. Odieresis: 0x00D6,
  8999. Odieresiscyrillic: 0x04E6,
  9000. Odieresissmall: 0xF7F6,
  9001. Odotbelow: 0x1ECC,
  9002. Ogoneksmall: 0xF6FB,
  9003. Ograve: 0x00D2,
  9004. Ogravesmall: 0xF7F2,
  9005. Oharmenian: 0x0555,
  9006. Ohm: 0x2126,
  9007. Ohookabove: 0x1ECE,
  9008. Ohorn: 0x01A0,
  9009. Ohornacute: 0x1EDA,
  9010. Ohorndotbelow: 0x1EE2,
  9011. Ohorngrave: 0x1EDC,
  9012. Ohornhookabove: 0x1EDE,
  9013. Ohorntilde: 0x1EE0,
  9014. Ohungarumlaut: 0x0150,
  9015. Oi: 0x01A2,
  9016. Oinvertedbreve: 0x020E,
  9017. Omacron: 0x014C,
  9018. Omacronacute: 0x1E52,
  9019. Omacrongrave: 0x1E50,
  9020. Omega: 0x2126,
  9021. Omegacyrillic: 0x0460,
  9022. Omegagreek: 0x03A9,
  9023. Omegaroundcyrillic: 0x047A,
  9024. Omegatitlocyrillic: 0x047C,
  9025. Omegatonos: 0x038F,
  9026. Omicron: 0x039F,
  9027. Omicrontonos: 0x038C,
  9028. Omonospace: 0xFF2F,
  9029. Oneroman: 0x2160,
  9030. Oogonek: 0x01EA,
  9031. Oogonekmacron: 0x01EC,
  9032. Oopen: 0x0186,
  9033. Oslash: 0x00D8,
  9034. Oslashacute: 0x01FE,
  9035. Oslashsmall: 0xF7F8,
  9036. Osmall: 0xF76F,
  9037. Ostrokeacute: 0x01FE,
  9038. Otcyrillic: 0x047E,
  9039. Otilde: 0x00D5,
  9040. Otildeacute: 0x1E4C,
  9041. Otildedieresis: 0x1E4E,
  9042. Otildesmall: 0xF7F5,
  9043. P: 0x0050,
  9044. Pacute: 0x1E54,
  9045. Pcircle: 0x24C5,
  9046. Pdotaccent: 0x1E56,
  9047. Pecyrillic: 0x041F,
  9048. Peharmenian: 0x054A,
  9049. Pemiddlehookcyrillic: 0x04A6,
  9050. Phi: 0x03A6,
  9051. Phook: 0x01A4,
  9052. Pi: 0x03A0,
  9053. Piwrarmenian: 0x0553,
  9054. Pmonospace: 0xFF30,
  9055. Psi: 0x03A8,
  9056. Psicyrillic: 0x0470,
  9057. Psmall: 0xF770,
  9058. Q: 0x0051,
  9059. Qcircle: 0x24C6,
  9060. Qmonospace: 0xFF31,
  9061. Qsmall: 0xF771,
  9062. R: 0x0052,
  9063. Raarmenian: 0x054C,
  9064. Racute: 0x0154,
  9065. Rcaron: 0x0158,
  9066. Rcedilla: 0x0156,
  9067. Rcircle: 0x24C7,
  9068. Rcommaaccent: 0x0156,
  9069. Rdblgrave: 0x0210,
  9070. Rdotaccent: 0x1E58,
  9071. Rdotbelow: 0x1E5A,
  9072. Rdotbelowmacron: 0x1E5C,
  9073. Reharmenian: 0x0550,
  9074. Rfraktur: 0x211C,
  9075. Rho: 0x03A1,
  9076. Ringsmall: 0xF6FC,
  9077. Rinvertedbreve: 0x0212,
  9078. Rlinebelow: 0x1E5E,
  9079. Rmonospace: 0xFF32,
  9080. Rsmall: 0xF772,
  9081. Rsmallinverted: 0x0281,
  9082. Rsmallinvertedsuperior: 0x02B6,
  9083. S: 0x0053,
  9084. SF010000: 0x250C,
  9085. SF020000: 0x2514,
  9086. SF030000: 0x2510,
  9087. SF040000: 0x2518,
  9088. SF050000: 0x253C,
  9089. SF060000: 0x252C,
  9090. SF070000: 0x2534,
  9091. SF080000: 0x251C,
  9092. SF090000: 0x2524,
  9093. SF100000: 0x2500,
  9094. SF110000: 0x2502,
  9095. SF190000: 0x2561,
  9096. SF200000: 0x2562,
  9097. SF210000: 0x2556,
  9098. SF220000: 0x2555,
  9099. SF230000: 0x2563,
  9100. SF240000: 0x2551,
  9101. SF250000: 0x2557,
  9102. SF260000: 0x255D,
  9103. SF270000: 0x255C,
  9104. SF280000: 0x255B,
  9105. SF360000: 0x255E,
  9106. SF370000: 0x255F,
  9107. SF380000: 0x255A,
  9108. SF390000: 0x2554,
  9109. SF400000: 0x2569,
  9110. SF410000: 0x2566,
  9111. SF420000: 0x2560,
  9112. SF430000: 0x2550,
  9113. SF440000: 0x256C,
  9114. SF450000: 0x2567,
  9115. SF460000: 0x2568,
  9116. SF470000: 0x2564,
  9117. SF480000: 0x2565,
  9118. SF490000: 0x2559,
  9119. SF500000: 0x2558,
  9120. SF510000: 0x2552,
  9121. SF520000: 0x2553,
  9122. SF530000: 0x256B,
  9123. SF540000: 0x256A,
  9124. Sacute: 0x015A,
  9125. Sacutedotaccent: 0x1E64,
  9126. Sampigreek: 0x03E0,
  9127. Scaron: 0x0160,
  9128. Scarondotaccent: 0x1E66,
  9129. Scaronsmall: 0xF6FD,
  9130. Scedilla: 0x015E,
  9131. Schwa: 0x018F,
  9132. Schwacyrillic: 0x04D8,
  9133. Schwadieresiscyrillic: 0x04DA,
  9134. Scircle: 0x24C8,
  9135. Scircumflex: 0x015C,
  9136. Scommaaccent: 0x0218,
  9137. Sdotaccent: 0x1E60,
  9138. Sdotbelow: 0x1E62,
  9139. Sdotbelowdotaccent: 0x1E68,
  9140. Seharmenian: 0x054D,
  9141. Sevenroman: 0x2166,
  9142. Shaarmenian: 0x0547,
  9143. Shacyrillic: 0x0428,
  9144. Shchacyrillic: 0x0429,
  9145. Sheicoptic: 0x03E2,
  9146. Shhacyrillic: 0x04BA,
  9147. Shimacoptic: 0x03EC,
  9148. Sigma: 0x03A3,
  9149. Sixroman: 0x2165,
  9150. Smonospace: 0xFF33,
  9151. Softsigncyrillic: 0x042C,
  9152. Ssmall: 0xF773,
  9153. Stigmagreek: 0x03DA,
  9154. T: 0x0054,
  9155. Tau: 0x03A4,
  9156. Tbar: 0x0166,
  9157. Tcaron: 0x0164,
  9158. Tcedilla: 0x0162,
  9159. Tcircle: 0x24C9,
  9160. Tcircumflexbelow: 0x1E70,
  9161. Tcommaaccent: 0x0162,
  9162. Tdotaccent: 0x1E6A,
  9163. Tdotbelow: 0x1E6C,
  9164. Tecyrillic: 0x0422,
  9165. Tedescendercyrillic: 0x04AC,
  9166. Tenroman: 0x2169,
  9167. Tetsecyrillic: 0x04B4,
  9168. Theta: 0x0398,
  9169. Thook: 0x01AC,
  9170. Thorn: 0x00DE,
  9171. Thornsmall: 0xF7FE,
  9172. Threeroman: 0x2162,
  9173. Tildesmall: 0xF6FE,
  9174. Tiwnarmenian: 0x054F,
  9175. Tlinebelow: 0x1E6E,
  9176. Tmonospace: 0xFF34,
  9177. Toarmenian: 0x0539,
  9178. Tonefive: 0x01BC,
  9179. Tonesix: 0x0184,
  9180. Tonetwo: 0x01A7,
  9181. Tretroflexhook: 0x01AE,
  9182. Tsecyrillic: 0x0426,
  9183. Tshecyrillic: 0x040B,
  9184. Tsmall: 0xF774,
  9185. Twelveroman: 0x216B,
  9186. Tworoman: 0x2161,
  9187. U: 0x0055,
  9188. Uacute: 0x00DA,
  9189. Uacutesmall: 0xF7FA,
  9190. Ubreve: 0x016C,
  9191. Ucaron: 0x01D3,
  9192. Ucircle: 0x24CA,
  9193. Ucircumflex: 0x00DB,
  9194. Ucircumflexbelow: 0x1E76,
  9195. Ucircumflexsmall: 0xF7FB,
  9196. Ucyrillic: 0x0423,
  9197. Udblacute: 0x0170,
  9198. Udblgrave: 0x0214,
  9199. Udieresis: 0x00DC,
  9200. Udieresisacute: 0x01D7,
  9201. Udieresisbelow: 0x1E72,
  9202. Udieresiscaron: 0x01D9,
  9203. Udieresiscyrillic: 0x04F0,
  9204. Udieresisgrave: 0x01DB,
  9205. Udieresismacron: 0x01D5,
  9206. Udieresissmall: 0xF7FC,
  9207. Udotbelow: 0x1EE4,
  9208. Ugrave: 0x00D9,
  9209. Ugravesmall: 0xF7F9,
  9210. Uhookabove: 0x1EE6,
  9211. Uhorn: 0x01AF,
  9212. Uhornacute: 0x1EE8,
  9213. Uhorndotbelow: 0x1EF0,
  9214. Uhorngrave: 0x1EEA,
  9215. Uhornhookabove: 0x1EEC,
  9216. Uhorntilde: 0x1EEE,
  9217. Uhungarumlaut: 0x0170,
  9218. Uhungarumlautcyrillic: 0x04F2,
  9219. Uinvertedbreve: 0x0216,
  9220. Ukcyrillic: 0x0478,
  9221. Umacron: 0x016A,
  9222. Umacroncyrillic: 0x04EE,
  9223. Umacrondieresis: 0x1E7A,
  9224. Umonospace: 0xFF35,
  9225. Uogonek: 0x0172,
  9226. Upsilon: 0x03A5,
  9227. Upsilon1: 0x03D2,
  9228. Upsilonacutehooksymbolgreek: 0x03D3,
  9229. Upsilonafrican: 0x01B1,
  9230. Upsilondieresis: 0x03AB,
  9231. Upsilondieresishooksymbolgreek: 0x03D4,
  9232. Upsilonhooksymbol: 0x03D2,
  9233. Upsilontonos: 0x038E,
  9234. Uring: 0x016E,
  9235. Ushortcyrillic: 0x040E,
  9236. Usmall: 0xF775,
  9237. Ustraightcyrillic: 0x04AE,
  9238. Ustraightstrokecyrillic: 0x04B0,
  9239. Utilde: 0x0168,
  9240. Utildeacute: 0x1E78,
  9241. Utildebelow: 0x1E74,
  9242. V: 0x0056,
  9243. Vcircle: 0x24CB,
  9244. Vdotbelow: 0x1E7E,
  9245. Vecyrillic: 0x0412,
  9246. Vewarmenian: 0x054E,
  9247. Vhook: 0x01B2,
  9248. Vmonospace: 0xFF36,
  9249. Voarmenian: 0x0548,
  9250. Vsmall: 0xF776,
  9251. Vtilde: 0x1E7C,
  9252. W: 0x0057,
  9253. Wacute: 0x1E82,
  9254. Wcircle: 0x24CC,
  9255. Wcircumflex: 0x0174,
  9256. Wdieresis: 0x1E84,
  9257. Wdotaccent: 0x1E86,
  9258. Wdotbelow: 0x1E88,
  9259. Wgrave: 0x1E80,
  9260. Wmonospace: 0xFF37,
  9261. Wsmall: 0xF777,
  9262. X: 0x0058,
  9263. Xcircle: 0x24CD,
  9264. Xdieresis: 0x1E8C,
  9265. Xdotaccent: 0x1E8A,
  9266. Xeharmenian: 0x053D,
  9267. Xi: 0x039E,
  9268. Xmonospace: 0xFF38,
  9269. Xsmall: 0xF778,
  9270. Y: 0x0059,
  9271. Yacute: 0x00DD,
  9272. Yacutesmall: 0xF7FD,
  9273. Yatcyrillic: 0x0462,
  9274. Ycircle: 0x24CE,
  9275. Ycircumflex: 0x0176,
  9276. Ydieresis: 0x0178,
  9277. Ydieresissmall: 0xF7FF,
  9278. Ydotaccent: 0x1E8E,
  9279. Ydotbelow: 0x1EF4,
  9280. Yericyrillic: 0x042B,
  9281. Yerudieresiscyrillic: 0x04F8,
  9282. Ygrave: 0x1EF2,
  9283. Yhook: 0x01B3,
  9284. Yhookabove: 0x1EF6,
  9285. Yiarmenian: 0x0545,
  9286. Yicyrillic: 0x0407,
  9287. Yiwnarmenian: 0x0552,
  9288. Ymonospace: 0xFF39,
  9289. Ysmall: 0xF779,
  9290. Ytilde: 0x1EF8,
  9291. Yusbigcyrillic: 0x046A,
  9292. Yusbigiotifiedcyrillic: 0x046C,
  9293. Yuslittlecyrillic: 0x0466,
  9294. Yuslittleiotifiedcyrillic: 0x0468,
  9295. Z: 0x005A,
  9296. Zaarmenian: 0x0536,
  9297. Zacute: 0x0179,
  9298. Zcaron: 0x017D,
  9299. Zcaronsmall: 0xF6FF,
  9300. Zcircle: 0x24CF,
  9301. Zcircumflex: 0x1E90,
  9302. Zdot: 0x017B,
  9303. Zdotaccent: 0x017B,
  9304. Zdotbelow: 0x1E92,
  9305. Zecyrillic: 0x0417,
  9306. Zedescendercyrillic: 0x0498,
  9307. Zedieresiscyrillic: 0x04DE,
  9308. Zeta: 0x0396,
  9309. Zhearmenian: 0x053A,
  9310. Zhebrevecyrillic: 0x04C1,
  9311. Zhecyrillic: 0x0416,
  9312. Zhedescendercyrillic: 0x0496,
  9313. Zhedieresiscyrillic: 0x04DC,
  9314. Zlinebelow: 0x1E94,
  9315. Zmonospace: 0xFF3A,
  9316. Zsmall: 0xF77A,
  9317. Zstroke: 0x01B5,
  9318. a: 0x0061,
  9319. aabengali: 0x0986,
  9320. aacute: 0x00E1,
  9321. aadeva: 0x0906,
  9322. aagujarati: 0x0A86,
  9323. aagurmukhi: 0x0A06,
  9324. aamatragurmukhi: 0x0A3E,
  9325. aarusquare: 0x3303,
  9326. aavowelsignbengali: 0x09BE,
  9327. aavowelsigndeva: 0x093E,
  9328. aavowelsigngujarati: 0x0ABE,
  9329. abbreviationmarkarmenian: 0x055F,
  9330. abbreviationsigndeva: 0x0970,
  9331. abengali: 0x0985,
  9332. abopomofo: 0x311A,
  9333. abreve: 0x0103,
  9334. abreveacute: 0x1EAF,
  9335. abrevecyrillic: 0x04D1,
  9336. abrevedotbelow: 0x1EB7,
  9337. abrevegrave: 0x1EB1,
  9338. abrevehookabove: 0x1EB3,
  9339. abrevetilde: 0x1EB5,
  9340. acaron: 0x01CE,
  9341. acircle: 0x24D0,
  9342. acircumflex: 0x00E2,
  9343. acircumflexacute: 0x1EA5,
  9344. acircumflexdotbelow: 0x1EAD,
  9345. acircumflexgrave: 0x1EA7,
  9346. acircumflexhookabove: 0x1EA9,
  9347. acircumflextilde: 0x1EAB,
  9348. acute: 0x00B4,
  9349. acutebelowcmb: 0x0317,
  9350. acutecmb: 0x0301,
  9351. acutecomb: 0x0301,
  9352. acutedeva: 0x0954,
  9353. acutelowmod: 0x02CF,
  9354. acutetonecmb: 0x0341,
  9355. acyrillic: 0x0430,
  9356. adblgrave: 0x0201,
  9357. addakgurmukhi: 0x0A71,
  9358. adeva: 0x0905,
  9359. adieresis: 0x00E4,
  9360. adieresiscyrillic: 0x04D3,
  9361. adieresismacron: 0x01DF,
  9362. adotbelow: 0x1EA1,
  9363. adotmacron: 0x01E1,
  9364. ae: 0x00E6,
  9365. aeacute: 0x01FD,
  9366. aekorean: 0x3150,
  9367. aemacron: 0x01E3,
  9368. afii00208: 0x2015,
  9369. afii08941: 0x20A4,
  9370. afii10017: 0x0410,
  9371. afii10018: 0x0411,
  9372. afii10019: 0x0412,
  9373. afii10020: 0x0413,
  9374. afii10021: 0x0414,
  9375. afii10022: 0x0415,
  9376. afii10023: 0x0401,
  9377. afii10024: 0x0416,
  9378. afii10025: 0x0417,
  9379. afii10026: 0x0418,
  9380. afii10027: 0x0419,
  9381. afii10028: 0x041A,
  9382. afii10029: 0x041B,
  9383. afii10030: 0x041C,
  9384. afii10031: 0x041D,
  9385. afii10032: 0x041E,
  9386. afii10033: 0x041F,
  9387. afii10034: 0x0420,
  9388. afii10035: 0x0421,
  9389. afii10036: 0x0422,
  9390. afii10037: 0x0423,
  9391. afii10038: 0x0424,
  9392. afii10039: 0x0425,
  9393. afii10040: 0x0426,
  9394. afii10041: 0x0427,
  9395. afii10042: 0x0428,
  9396. afii10043: 0x0429,
  9397. afii10044: 0x042A,
  9398. afii10045: 0x042B,
  9399. afii10046: 0x042C,
  9400. afii10047: 0x042D,
  9401. afii10048: 0x042E,
  9402. afii10049: 0x042F,
  9403. afii10050: 0x0490,
  9404. afii10051: 0x0402,
  9405. afii10052: 0x0403,
  9406. afii10053: 0x0404,
  9407. afii10054: 0x0405,
  9408. afii10055: 0x0406,
  9409. afii10056: 0x0407,
  9410. afii10057: 0x0408,
  9411. afii10058: 0x0409,
  9412. afii10059: 0x040A,
  9413. afii10060: 0x040B,
  9414. afii10061: 0x040C,
  9415. afii10062: 0x040E,
  9416. afii10063: 0xF6C4,
  9417. afii10064: 0xF6C5,
  9418. afii10065: 0x0430,
  9419. afii10066: 0x0431,
  9420. afii10067: 0x0432,
  9421. afii10068: 0x0433,
  9422. afii10069: 0x0434,
  9423. afii10070: 0x0435,
  9424. afii10071: 0x0451,
  9425. afii10072: 0x0436,
  9426. afii10073: 0x0437,
  9427. afii10074: 0x0438,
  9428. afii10075: 0x0439,
  9429. afii10076: 0x043A,
  9430. afii10077: 0x043B,
  9431. afii10078: 0x043C,
  9432. afii10079: 0x043D,
  9433. afii10080: 0x043E,
  9434. afii10081: 0x043F,
  9435. afii10082: 0x0440,
  9436. afii10083: 0x0441,
  9437. afii10084: 0x0442,
  9438. afii10085: 0x0443,
  9439. afii10086: 0x0444,
  9440. afii10087: 0x0445,
  9441. afii10088: 0x0446,
  9442. afii10089: 0x0447,
  9443. afii10090: 0x0448,
  9444. afii10091: 0x0449,
  9445. afii10092: 0x044A,
  9446. afii10093: 0x044B,
  9447. afii10094: 0x044C,
  9448. afii10095: 0x044D,
  9449. afii10096: 0x044E,
  9450. afii10097: 0x044F,
  9451. afii10098: 0x0491,
  9452. afii10099: 0x0452,
  9453. afii10100: 0x0453,
  9454. afii10101: 0x0454,
  9455. afii10102: 0x0455,
  9456. afii10103: 0x0456,
  9457. afii10104: 0x0457,
  9458. afii10105: 0x0458,
  9459. afii10106: 0x0459,
  9460. afii10107: 0x045A,
  9461. afii10108: 0x045B,
  9462. afii10109: 0x045C,
  9463. afii10110: 0x045E,
  9464. afii10145: 0x040F,
  9465. afii10146: 0x0462,
  9466. afii10147: 0x0472,
  9467. afii10148: 0x0474,
  9468. afii10192: 0xF6C6,
  9469. afii10193: 0x045F,
  9470. afii10194: 0x0463,
  9471. afii10195: 0x0473,
  9472. afii10196: 0x0475,
  9473. afii10831: 0xF6C7,
  9474. afii10832: 0xF6C8,
  9475. afii10846: 0x04D9,
  9476. afii299: 0x200E,
  9477. afii300: 0x200F,
  9478. afii301: 0x200D,
  9479. afii57381: 0x066A,
  9480. afii57388: 0x060C,
  9481. afii57392: 0x0660,
  9482. afii57393: 0x0661,
  9483. afii57394: 0x0662,
  9484. afii57395: 0x0663,
  9485. afii57396: 0x0664,
  9486. afii57397: 0x0665,
  9487. afii57398: 0x0666,
  9488. afii57399: 0x0667,
  9489. afii57400: 0x0668,
  9490. afii57401: 0x0669,
  9491. afii57403: 0x061B,
  9492. afii57407: 0x061F,
  9493. afii57409: 0x0621,
  9494. afii57410: 0x0622,
  9495. afii57411: 0x0623,
  9496. afii57412: 0x0624,
  9497. afii57413: 0x0625,
  9498. afii57414: 0x0626,
  9499. afii57415: 0x0627,
  9500. afii57416: 0x0628,
  9501. afii57417: 0x0629,
  9502. afii57418: 0x062A,
  9503. afii57419: 0x062B,
  9504. afii57420: 0x062C,
  9505. afii57421: 0x062D,
  9506. afii57422: 0x062E,
  9507. afii57423: 0x062F,
  9508. afii57424: 0x0630,
  9509. afii57425: 0x0631,
  9510. afii57426: 0x0632,
  9511. afii57427: 0x0633,
  9512. afii57428: 0x0634,
  9513. afii57429: 0x0635,
  9514. afii57430: 0x0636,
  9515. afii57431: 0x0637,
  9516. afii57432: 0x0638,
  9517. afii57433: 0x0639,
  9518. afii57434: 0x063A,
  9519. afii57440: 0x0640,
  9520. afii57441: 0x0641,
  9521. afii57442: 0x0642,
  9522. afii57443: 0x0643,
  9523. afii57444: 0x0644,
  9524. afii57445: 0x0645,
  9525. afii57446: 0x0646,
  9526. afii57448: 0x0648,
  9527. afii57449: 0x0649,
  9528. afii57450: 0x064A,
  9529. afii57451: 0x064B,
  9530. afii57452: 0x064C,
  9531. afii57453: 0x064D,
  9532. afii57454: 0x064E,
  9533. afii57455: 0x064F,
  9534. afii57456: 0x0650,
  9535. afii57457: 0x0651,
  9536. afii57458: 0x0652,
  9537. afii57470: 0x0647,
  9538. afii57505: 0x06A4,
  9539. afii57506: 0x067E,
  9540. afii57507: 0x0686,
  9541. afii57508: 0x0698,
  9542. afii57509: 0x06AF,
  9543. afii57511: 0x0679,
  9544. afii57512: 0x0688,
  9545. afii57513: 0x0691,
  9546. afii57514: 0x06BA,
  9547. afii57519: 0x06D2,
  9548. afii57534: 0x06D5,
  9549. afii57636: 0x20AA,
  9550. afii57645: 0x05BE,
  9551. afii57658: 0x05C3,
  9552. afii57664: 0x05D0,
  9553. afii57665: 0x05D1,
  9554. afii57666: 0x05D2,
  9555. afii57667: 0x05D3,
  9556. afii57668: 0x05D4,
  9557. afii57669: 0x05D5,
  9558. afii57670: 0x05D6,
  9559. afii57671: 0x05D7,
  9560. afii57672: 0x05D8,
  9561. afii57673: 0x05D9,
  9562. afii57674: 0x05DA,
  9563. afii57675: 0x05DB,
  9564. afii57676: 0x05DC,
  9565. afii57677: 0x05DD,
  9566. afii57678: 0x05DE,
  9567. afii57679: 0x05DF,
  9568. afii57680: 0x05E0,
  9569. afii57681: 0x05E1,
  9570. afii57682: 0x05E2,
  9571. afii57683: 0x05E3,
  9572. afii57684: 0x05E4,
  9573. afii57685: 0x05E5,
  9574. afii57686: 0x05E6,
  9575. afii57687: 0x05E7,
  9576. afii57688: 0x05E8,
  9577. afii57689: 0x05E9,
  9578. afii57690: 0x05EA,
  9579. afii57694: 0xFB2A,
  9580. afii57695: 0xFB2B,
  9581. afii57700: 0xFB4B,
  9582. afii57705: 0xFB1F,
  9583. afii57716: 0x05F0,
  9584. afii57717: 0x05F1,
  9585. afii57718: 0x05F2,
  9586. afii57723: 0xFB35,
  9587. afii57793: 0x05B4,
  9588. afii57794: 0x05B5,
  9589. afii57795: 0x05B6,
  9590. afii57796: 0x05BB,
  9591. afii57797: 0x05B8,
  9592. afii57798: 0x05B7,
  9593. afii57799: 0x05B0,
  9594. afii57800: 0x05B2,
  9595. afii57801: 0x05B1,
  9596. afii57802: 0x05B3,
  9597. afii57803: 0x05C2,
  9598. afii57804: 0x05C1,
  9599. afii57806: 0x05B9,
  9600. afii57807: 0x05BC,
  9601. afii57839: 0x05BD,
  9602. afii57841: 0x05BF,
  9603. afii57842: 0x05C0,
  9604. afii57929: 0x02BC,
  9605. afii61248: 0x2105,
  9606. afii61289: 0x2113,
  9607. afii61352: 0x2116,
  9608. afii61573: 0x202C,
  9609. afii61574: 0x202D,
  9610. afii61575: 0x202E,
  9611. afii61664: 0x200C,
  9612. afii63167: 0x066D,
  9613. afii64937: 0x02BD,
  9614. agrave: 0x00E0,
  9615. agujarati: 0x0A85,
  9616. agurmukhi: 0x0A05,
  9617. ahiragana: 0x3042,
  9618. ahookabove: 0x1EA3,
  9619. aibengali: 0x0990,
  9620. aibopomofo: 0x311E,
  9621. aideva: 0x0910,
  9622. aiecyrillic: 0x04D5,
  9623. aigujarati: 0x0A90,
  9624. aigurmukhi: 0x0A10,
  9625. aimatragurmukhi: 0x0A48,
  9626. ainarabic: 0x0639,
  9627. ainfinalarabic: 0xFECA,
  9628. aininitialarabic: 0xFECB,
  9629. ainmedialarabic: 0xFECC,
  9630. ainvertedbreve: 0x0203,
  9631. aivowelsignbengali: 0x09C8,
  9632. aivowelsigndeva: 0x0948,
  9633. aivowelsigngujarati: 0x0AC8,
  9634. akatakana: 0x30A2,
  9635. akatakanahalfwidth: 0xFF71,
  9636. akorean: 0x314F,
  9637. alef: 0x05D0,
  9638. alefarabic: 0x0627,
  9639. alefdageshhebrew: 0xFB30,
  9640. aleffinalarabic: 0xFE8E,
  9641. alefhamzaabovearabic: 0x0623,
  9642. alefhamzaabovefinalarabic: 0xFE84,
  9643. alefhamzabelowarabic: 0x0625,
  9644. alefhamzabelowfinalarabic: 0xFE88,
  9645. alefhebrew: 0x05D0,
  9646. aleflamedhebrew: 0xFB4F,
  9647. alefmaddaabovearabic: 0x0622,
  9648. alefmaddaabovefinalarabic: 0xFE82,
  9649. alefmaksuraarabic: 0x0649,
  9650. alefmaksurafinalarabic: 0xFEF0,
  9651. alefmaksurainitialarabic: 0xFEF3,
  9652. alefmaksuramedialarabic: 0xFEF4,
  9653. alefpatahhebrew: 0xFB2E,
  9654. alefqamatshebrew: 0xFB2F,
  9655. aleph: 0x2135,
  9656. allequal: 0x224C,
  9657. alpha: 0x03B1,
  9658. alphatonos: 0x03AC,
  9659. amacron: 0x0101,
  9660. amonospace: 0xFF41,
  9661. ampersand: 0x0026,
  9662. ampersandmonospace: 0xFF06,
  9663. ampersandsmall: 0xF726,
  9664. amsquare: 0x33C2,
  9665. anbopomofo: 0x3122,
  9666. angbopomofo: 0x3124,
  9667. angbracketleft: 0x3008, // This glyph is missing from Adobe's original list.
  9668. angbracketright: 0x3009, // This glyph is missing from Adobe's original list.
  9669. angkhankhuthai: 0x0E5A,
  9670. angle: 0x2220,
  9671. anglebracketleft: 0x3008,
  9672. anglebracketleftvertical: 0xFE3F,
  9673. anglebracketright: 0x3009,
  9674. anglebracketrightvertical: 0xFE40,
  9675. angleleft: 0x2329,
  9676. angleright: 0x232A,
  9677. angstrom: 0x212B,
  9678. anoteleia: 0x0387,
  9679. anudattadeva: 0x0952,
  9680. anusvarabengali: 0x0982,
  9681. anusvaradeva: 0x0902,
  9682. anusvaragujarati: 0x0A82,
  9683. aogonek: 0x0105,
  9684. apaatosquare: 0x3300,
  9685. aparen: 0x249C,
  9686. apostrophearmenian: 0x055A,
  9687. apostrophemod: 0x02BC,
  9688. apple: 0xF8FF,
  9689. approaches: 0x2250,
  9690. approxequal: 0x2248,
  9691. approxequalorimage: 0x2252,
  9692. approximatelyequal: 0x2245,
  9693. araeaekorean: 0x318E,
  9694. araeakorean: 0x318D,
  9695. arc: 0x2312,
  9696. arighthalfring: 0x1E9A,
  9697. aring: 0x00E5,
  9698. aringacute: 0x01FB,
  9699. aringbelow: 0x1E01,
  9700. arrowboth: 0x2194,
  9701. arrowdashdown: 0x21E3,
  9702. arrowdashleft: 0x21E0,
  9703. arrowdashright: 0x21E2,
  9704. arrowdashup: 0x21E1,
  9705. arrowdblboth: 0x21D4,
  9706. arrowdbldown: 0x21D3,
  9707. arrowdblleft: 0x21D0,
  9708. arrowdblright: 0x21D2,
  9709. arrowdblup: 0x21D1,
  9710. arrowdown: 0x2193,
  9711. arrowdownleft: 0x2199,
  9712. arrowdownright: 0x2198,
  9713. arrowdownwhite: 0x21E9,
  9714. arrowheaddownmod: 0x02C5,
  9715. arrowheadleftmod: 0x02C2,
  9716. arrowheadrightmod: 0x02C3,
  9717. arrowheadupmod: 0x02C4,
  9718. arrowhorizex: 0xF8E7,
  9719. arrowleft: 0x2190,
  9720. arrowleftdbl: 0x21D0,
  9721. arrowleftdblstroke: 0x21CD,
  9722. arrowleftoverright: 0x21C6,
  9723. arrowleftwhite: 0x21E6,
  9724. arrowright: 0x2192,
  9725. arrowrightdblstroke: 0x21CF,
  9726. arrowrightheavy: 0x279E,
  9727. arrowrightoverleft: 0x21C4,
  9728. arrowrightwhite: 0x21E8,
  9729. arrowtableft: 0x21E4,
  9730. arrowtabright: 0x21E5,
  9731. arrowup: 0x2191,
  9732. arrowupdn: 0x2195,
  9733. arrowupdnbse: 0x21A8,
  9734. arrowupdownbase: 0x21A8,
  9735. arrowupleft: 0x2196,
  9736. arrowupleftofdown: 0x21C5,
  9737. arrowupright: 0x2197,
  9738. arrowupwhite: 0x21E7,
  9739. arrowvertex: 0xF8E6,
  9740. asciicircum: 0x005E,
  9741. asciicircummonospace: 0xFF3E,
  9742. asciitilde: 0x007E,
  9743. asciitildemonospace: 0xFF5E,
  9744. ascript: 0x0251,
  9745. ascriptturned: 0x0252,
  9746. asmallhiragana: 0x3041,
  9747. asmallkatakana: 0x30A1,
  9748. asmallkatakanahalfwidth: 0xFF67,
  9749. asterisk: 0x002A,
  9750. asteriskaltonearabic: 0x066D,
  9751. asteriskarabic: 0x066D,
  9752. asteriskmath: 0x2217,
  9753. asteriskmonospace: 0xFF0A,
  9754. asterisksmall: 0xFE61,
  9755. asterism: 0x2042,
  9756. asuperior: 0xF6E9,
  9757. asymptoticallyequal: 0x2243,
  9758. at: 0x0040,
  9759. atilde: 0x00E3,
  9760. atmonospace: 0xFF20,
  9761. atsmall: 0xFE6B,
  9762. aturned: 0x0250,
  9763. aubengali: 0x0994,
  9764. aubopomofo: 0x3120,
  9765. audeva: 0x0914,
  9766. augujarati: 0x0A94,
  9767. augurmukhi: 0x0A14,
  9768. aulengthmarkbengali: 0x09D7,
  9769. aumatragurmukhi: 0x0A4C,
  9770. auvowelsignbengali: 0x09CC,
  9771. auvowelsigndeva: 0x094C,
  9772. auvowelsigngujarati: 0x0ACC,
  9773. avagrahadeva: 0x093D,
  9774. aybarmenian: 0x0561,
  9775. ayin: 0x05E2,
  9776. ayinaltonehebrew: 0xFB20,
  9777. ayinhebrew: 0x05E2,
  9778. b: 0x0062,
  9779. babengali: 0x09AC,
  9780. backslash: 0x005C,
  9781. backslashmonospace: 0xFF3C,
  9782. badeva: 0x092C,
  9783. bagujarati: 0x0AAC,
  9784. bagurmukhi: 0x0A2C,
  9785. bahiragana: 0x3070,
  9786. bahtthai: 0x0E3F,
  9787. bakatakana: 0x30D0,
  9788. bar: 0x007C,
  9789. barmonospace: 0xFF5C,
  9790. bbopomofo: 0x3105,
  9791. bcircle: 0x24D1,
  9792. bdotaccent: 0x1E03,
  9793. bdotbelow: 0x1E05,
  9794. beamedsixteenthnotes: 0x266C,
  9795. because: 0x2235,
  9796. becyrillic: 0x0431,
  9797. beharabic: 0x0628,
  9798. behfinalarabic: 0xFE90,
  9799. behinitialarabic: 0xFE91,
  9800. behiragana: 0x3079,
  9801. behmedialarabic: 0xFE92,
  9802. behmeeminitialarabic: 0xFC9F,
  9803. behmeemisolatedarabic: 0xFC08,
  9804. behnoonfinalarabic: 0xFC6D,
  9805. bekatakana: 0x30D9,
  9806. benarmenian: 0x0562,
  9807. bet: 0x05D1,
  9808. beta: 0x03B2,
  9809. betasymbolgreek: 0x03D0,
  9810. betdagesh: 0xFB31,
  9811. betdageshhebrew: 0xFB31,
  9812. bethebrew: 0x05D1,
  9813. betrafehebrew: 0xFB4C,
  9814. bhabengali: 0x09AD,
  9815. bhadeva: 0x092D,
  9816. bhagujarati: 0x0AAD,
  9817. bhagurmukhi: 0x0A2D,
  9818. bhook: 0x0253,
  9819. bihiragana: 0x3073,
  9820. bikatakana: 0x30D3,
  9821. bilabialclick: 0x0298,
  9822. bindigurmukhi: 0x0A02,
  9823. birusquare: 0x3331,
  9824. blackcircle: 0x25CF,
  9825. blackdiamond: 0x25C6,
  9826. blackdownpointingtriangle: 0x25BC,
  9827. blackleftpointingpointer: 0x25C4,
  9828. blackleftpointingtriangle: 0x25C0,
  9829. blacklenticularbracketleft: 0x3010,
  9830. blacklenticularbracketleftvertical: 0xFE3B,
  9831. blacklenticularbracketright: 0x3011,
  9832. blacklenticularbracketrightvertical: 0xFE3C,
  9833. blacklowerlefttriangle: 0x25E3,
  9834. blacklowerrighttriangle: 0x25E2,
  9835. blackrectangle: 0x25AC,
  9836. blackrightpointingpointer: 0x25BA,
  9837. blackrightpointingtriangle: 0x25B6,
  9838. blacksmallsquare: 0x25AA,
  9839. blacksmilingface: 0x263B,
  9840. blacksquare: 0x25A0,
  9841. blackstar: 0x2605,
  9842. blackupperlefttriangle: 0x25E4,
  9843. blackupperrighttriangle: 0x25E5,
  9844. blackuppointingsmalltriangle: 0x25B4,
  9845. blackuppointingtriangle: 0x25B2,
  9846. blank: 0x2423,
  9847. blinebelow: 0x1E07,
  9848. block: 0x2588,
  9849. bmonospace: 0xFF42,
  9850. bobaimaithai: 0x0E1A,
  9851. bohiragana: 0x307C,
  9852. bokatakana: 0x30DC,
  9853. bparen: 0x249D,
  9854. bqsquare: 0x33C3,
  9855. braceex: 0xF8F4,
  9856. braceleft: 0x007B,
  9857. braceleftbt: 0xF8F3,
  9858. braceleftmid: 0xF8F2,
  9859. braceleftmonospace: 0xFF5B,
  9860. braceleftsmall: 0xFE5B,
  9861. bracelefttp: 0xF8F1,
  9862. braceleftvertical: 0xFE37,
  9863. braceright: 0x007D,
  9864. bracerightbt: 0xF8FE,
  9865. bracerightmid: 0xF8FD,
  9866. bracerightmonospace: 0xFF5D,
  9867. bracerightsmall: 0xFE5C,
  9868. bracerighttp: 0xF8FC,
  9869. bracerightvertical: 0xFE38,
  9870. bracketleft: 0x005B,
  9871. bracketleftbt: 0xF8F0,
  9872. bracketleftex: 0xF8EF,
  9873. bracketleftmonospace: 0xFF3B,
  9874. bracketlefttp: 0xF8EE,
  9875. bracketright: 0x005D,
  9876. bracketrightbt: 0xF8FB,
  9877. bracketrightex: 0xF8FA,
  9878. bracketrightmonospace: 0xFF3D,
  9879. bracketrighttp: 0xF8F9,
  9880. breve: 0x02D8,
  9881. brevebelowcmb: 0x032E,
  9882. brevecmb: 0x0306,
  9883. breveinvertedbelowcmb: 0x032F,
  9884. breveinvertedcmb: 0x0311,
  9885. breveinverteddoublecmb: 0x0361,
  9886. bridgebelowcmb: 0x032A,
  9887. bridgeinvertedbelowcmb: 0x033A,
  9888. brokenbar: 0x00A6,
  9889. bstroke: 0x0180,
  9890. bsuperior: 0xF6EA,
  9891. btopbar: 0x0183,
  9892. buhiragana: 0x3076,
  9893. bukatakana: 0x30D6,
  9894. bullet: 0x2022,
  9895. bulletinverse: 0x25D8,
  9896. bulletoperator: 0x2219,
  9897. bullseye: 0x25CE,
  9898. c: 0x0063,
  9899. caarmenian: 0x056E,
  9900. cabengali: 0x099A,
  9901. cacute: 0x0107,
  9902. cadeva: 0x091A,
  9903. cagujarati: 0x0A9A,
  9904. cagurmukhi: 0x0A1A,
  9905. calsquare: 0x3388,
  9906. candrabindubengali: 0x0981,
  9907. candrabinducmb: 0x0310,
  9908. candrabindudeva: 0x0901,
  9909. candrabindugujarati: 0x0A81,
  9910. capslock: 0x21EA,
  9911. careof: 0x2105,
  9912. caron: 0x02C7,
  9913. caronbelowcmb: 0x032C,
  9914. caroncmb: 0x030C,
  9915. carriagereturn: 0x21B5,
  9916. cbopomofo: 0x3118,
  9917. ccaron: 0x010D,
  9918. ccedilla: 0x00E7,
  9919. ccedillaacute: 0x1E09,
  9920. ccircle: 0x24D2,
  9921. ccircumflex: 0x0109,
  9922. ccurl: 0x0255,
  9923. cdot: 0x010B,
  9924. cdotaccent: 0x010B,
  9925. cdsquare: 0x33C5,
  9926. cedilla: 0x00B8,
  9927. cedillacmb: 0x0327,
  9928. cent: 0x00A2,
  9929. centigrade: 0x2103,
  9930. centinferior: 0xF6DF,
  9931. centmonospace: 0xFFE0,
  9932. centoldstyle: 0xF7A2,
  9933. centsuperior: 0xF6E0,
  9934. chaarmenian: 0x0579,
  9935. chabengali: 0x099B,
  9936. chadeva: 0x091B,
  9937. chagujarati: 0x0A9B,
  9938. chagurmukhi: 0x0A1B,
  9939. chbopomofo: 0x3114,
  9940. cheabkhasiancyrillic: 0x04BD,
  9941. checkmark: 0x2713,
  9942. checyrillic: 0x0447,
  9943. chedescenderabkhasiancyrillic: 0x04BF,
  9944. chedescendercyrillic: 0x04B7,
  9945. chedieresiscyrillic: 0x04F5,
  9946. cheharmenian: 0x0573,
  9947. chekhakassiancyrillic: 0x04CC,
  9948. cheverticalstrokecyrillic: 0x04B9,
  9949. chi: 0x03C7,
  9950. chieuchacirclekorean: 0x3277,
  9951. chieuchaparenkorean: 0x3217,
  9952. chieuchcirclekorean: 0x3269,
  9953. chieuchkorean: 0x314A,
  9954. chieuchparenkorean: 0x3209,
  9955. chochangthai: 0x0E0A,
  9956. chochanthai: 0x0E08,
  9957. chochingthai: 0x0E09,
  9958. chochoethai: 0x0E0C,
  9959. chook: 0x0188,
  9960. cieucacirclekorean: 0x3276,
  9961. cieucaparenkorean: 0x3216,
  9962. cieuccirclekorean: 0x3268,
  9963. cieuckorean: 0x3148,
  9964. cieucparenkorean: 0x3208,
  9965. cieucuparenkorean: 0x321C,
  9966. circle: 0x25CB,
  9967. circlecopyrt: 0x00A9, // This glyph is missing from Adobe's original list.
  9968. circlemultiply: 0x2297,
  9969. circleot: 0x2299,
  9970. circleplus: 0x2295,
  9971. circlepostalmark: 0x3036,
  9972. circlewithlefthalfblack: 0x25D0,
  9973. circlewithrighthalfblack: 0x25D1,
  9974. circumflex: 0x02C6,
  9975. circumflexbelowcmb: 0x032D,
  9976. circumflexcmb: 0x0302,
  9977. clear: 0x2327,
  9978. clickalveolar: 0x01C2,
  9979. clickdental: 0x01C0,
  9980. clicklateral: 0x01C1,
  9981. clickretroflex: 0x01C3,
  9982. club: 0x2663,
  9983. clubsuitblack: 0x2663,
  9984. clubsuitwhite: 0x2667,
  9985. cmcubedsquare: 0x33A4,
  9986. cmonospace: 0xFF43,
  9987. cmsquaredsquare: 0x33A0,
  9988. coarmenian: 0x0581,
  9989. colon: 0x003A,
  9990. colonmonetary: 0x20A1,
  9991. colonmonospace: 0xFF1A,
  9992. colonsign: 0x20A1,
  9993. colonsmall: 0xFE55,
  9994. colontriangularhalfmod: 0x02D1,
  9995. colontriangularmod: 0x02D0,
  9996. comma: 0x002C,
  9997. commaabovecmb: 0x0313,
  9998. commaaboverightcmb: 0x0315,
  9999. commaaccent: 0xF6C3,
  10000. commaarabic: 0x060C,
  10001. commaarmenian: 0x055D,
  10002. commainferior: 0xF6E1,
  10003. commamonospace: 0xFF0C,
  10004. commareversedabovecmb: 0x0314,
  10005. commareversedmod: 0x02BD,
  10006. commasmall: 0xFE50,
  10007. commasuperior: 0xF6E2,
  10008. commaturnedabovecmb: 0x0312,
  10009. commaturnedmod: 0x02BB,
  10010. compass: 0x263C,
  10011. congruent: 0x2245,
  10012. contourintegral: 0x222E,
  10013. control: 0x2303,
  10014. controlACK: 0x0006,
  10015. controlBEL: 0x0007,
  10016. controlBS: 0x0008,
  10017. controlCAN: 0x0018,
  10018. controlCR: 0x000D,
  10019. controlDC1: 0x0011,
  10020. controlDC2: 0x0012,
  10021. controlDC3: 0x0013,
  10022. controlDC4: 0x0014,
  10023. controlDEL: 0x007F,
  10024. controlDLE: 0x0010,
  10025. controlEM: 0x0019,
  10026. controlENQ: 0x0005,
  10027. controlEOT: 0x0004,
  10028. controlESC: 0x001B,
  10029. controlETB: 0x0017,
  10030. controlETX: 0x0003,
  10031. controlFF: 0x000C,
  10032. controlFS: 0x001C,
  10033. controlGS: 0x001D,
  10034. controlHT: 0x0009,
  10035. controlLF: 0x000A,
  10036. controlNAK: 0x0015,
  10037. controlRS: 0x001E,
  10038. controlSI: 0x000F,
  10039. controlSO: 0x000E,
  10040. controlSOT: 0x0002,
  10041. controlSTX: 0x0001,
  10042. controlSUB: 0x001A,
  10043. controlSYN: 0x0016,
  10044. controlUS: 0x001F,
  10045. controlVT: 0x000B,
  10046. copyright: 0x00A9,
  10047. copyrightsans: 0xF8E9,
  10048. copyrightserif: 0xF6D9,
  10049. cornerbracketleft: 0x300C,
  10050. cornerbracketlefthalfwidth: 0xFF62,
  10051. cornerbracketleftvertical: 0xFE41,
  10052. cornerbracketright: 0x300D,
  10053. cornerbracketrighthalfwidth: 0xFF63,
  10054. cornerbracketrightvertical: 0xFE42,
  10055. corporationsquare: 0x337F,
  10056. cosquare: 0x33C7,
  10057. coverkgsquare: 0x33C6,
  10058. cparen: 0x249E,
  10059. cruzeiro: 0x20A2,
  10060. cstretched: 0x0297,
  10061. curlyand: 0x22CF,
  10062. curlyor: 0x22CE,
  10063. currency: 0x00A4,
  10064. cyrBreve: 0xF6D1,
  10065. cyrFlex: 0xF6D2,
  10066. cyrbreve: 0xF6D4,
  10067. cyrflex: 0xF6D5,
  10068. d: 0x0064,
  10069. daarmenian: 0x0564,
  10070. dabengali: 0x09A6,
  10071. dadarabic: 0x0636,
  10072. dadeva: 0x0926,
  10073. dadfinalarabic: 0xFEBE,
  10074. dadinitialarabic: 0xFEBF,
  10075. dadmedialarabic: 0xFEC0,
  10076. dagesh: 0x05BC,
  10077. dageshhebrew: 0x05BC,
  10078. dagger: 0x2020,
  10079. daggerdbl: 0x2021,
  10080. dagujarati: 0x0AA6,
  10081. dagurmukhi: 0x0A26,
  10082. dahiragana: 0x3060,
  10083. dakatakana: 0x30C0,
  10084. dalarabic: 0x062F,
  10085. dalet: 0x05D3,
  10086. daletdagesh: 0xFB33,
  10087. daletdageshhebrew: 0xFB33,
  10088. dalethebrew: 0x05D3,
  10089. dalfinalarabic: 0xFEAA,
  10090. dammaarabic: 0x064F,
  10091. dammalowarabic: 0x064F,
  10092. dammatanaltonearabic: 0x064C,
  10093. dammatanarabic: 0x064C,
  10094. danda: 0x0964,
  10095. dargahebrew: 0x05A7,
  10096. dargalefthebrew: 0x05A7,
  10097. dasiapneumatacyrilliccmb: 0x0485,
  10098. dblGrave: 0xF6D3,
  10099. dblanglebracketleft: 0x300A,
  10100. dblanglebracketleftvertical: 0xFE3D,
  10101. dblanglebracketright: 0x300B,
  10102. dblanglebracketrightvertical: 0xFE3E,
  10103. dblarchinvertedbelowcmb: 0x032B,
  10104. dblarrowleft: 0x21D4,
  10105. dblarrowright: 0x21D2,
  10106. dbldanda: 0x0965,
  10107. dblgrave: 0xF6D6,
  10108. dblgravecmb: 0x030F,
  10109. dblintegral: 0x222C,
  10110. dbllowline: 0x2017,
  10111. dbllowlinecmb: 0x0333,
  10112. dbloverlinecmb: 0x033F,
  10113. dblprimemod: 0x02BA,
  10114. dblverticalbar: 0x2016,
  10115. dblverticallineabovecmb: 0x030E,
  10116. dbopomofo: 0x3109,
  10117. dbsquare: 0x33C8,
  10118. dcaron: 0x010F,
  10119. dcedilla: 0x1E11,
  10120. dcircle: 0x24D3,
  10121. dcircumflexbelow: 0x1E13,
  10122. dcroat: 0x0111,
  10123. ddabengali: 0x09A1,
  10124. ddadeva: 0x0921,
  10125. ddagujarati: 0x0AA1,
  10126. ddagurmukhi: 0x0A21,
  10127. ddalarabic: 0x0688,
  10128. ddalfinalarabic: 0xFB89,
  10129. dddhadeva: 0x095C,
  10130. ddhabengali: 0x09A2,
  10131. ddhadeva: 0x0922,
  10132. ddhagujarati: 0x0AA2,
  10133. ddhagurmukhi: 0x0A22,
  10134. ddotaccent: 0x1E0B,
  10135. ddotbelow: 0x1E0D,
  10136. decimalseparatorarabic: 0x066B,
  10137. decimalseparatorpersian: 0x066B,
  10138. decyrillic: 0x0434,
  10139. degree: 0x00B0,
  10140. dehihebrew: 0x05AD,
  10141. dehiragana: 0x3067,
  10142. deicoptic: 0x03EF,
  10143. dekatakana: 0x30C7,
  10144. deleteleft: 0x232B,
  10145. deleteright: 0x2326,
  10146. delta: 0x03B4,
  10147. deltaturned: 0x018D,
  10148. denominatorminusonenumeratorbengali: 0x09F8,
  10149. dezh: 0x02A4,
  10150. dhabengali: 0x09A7,
  10151. dhadeva: 0x0927,
  10152. dhagujarati: 0x0AA7,
  10153. dhagurmukhi: 0x0A27,
  10154. dhook: 0x0257,
  10155. dialytikatonos: 0x0385,
  10156. dialytikatonoscmb: 0x0344,
  10157. diamond: 0x2666,
  10158. diamondsuitwhite: 0x2662,
  10159. dieresis: 0x00A8,
  10160. dieresisacute: 0xF6D7,
  10161. dieresisbelowcmb: 0x0324,
  10162. dieresiscmb: 0x0308,
  10163. dieresisgrave: 0xF6D8,
  10164. dieresistonos: 0x0385,
  10165. dihiragana: 0x3062,
  10166. dikatakana: 0x30C2,
  10167. dittomark: 0x3003,
  10168. divide: 0x00F7,
  10169. divides: 0x2223,
  10170. divisionslash: 0x2215,
  10171. djecyrillic: 0x0452,
  10172. dkshade: 0x2593,
  10173. dlinebelow: 0x1E0F,
  10174. dlsquare: 0x3397,
  10175. dmacron: 0x0111,
  10176. dmonospace: 0xFF44,
  10177. dnblock: 0x2584,
  10178. dochadathai: 0x0E0E,
  10179. dodekthai: 0x0E14,
  10180. dohiragana: 0x3069,
  10181. dokatakana: 0x30C9,
  10182. dollar: 0x0024,
  10183. dollarinferior: 0xF6E3,
  10184. dollarmonospace: 0xFF04,
  10185. dollaroldstyle: 0xF724,
  10186. dollarsmall: 0xFE69,
  10187. dollarsuperior: 0xF6E4,
  10188. dong: 0x20AB,
  10189. dorusquare: 0x3326,
  10190. dotaccent: 0x02D9,
  10191. dotaccentcmb: 0x0307,
  10192. dotbelowcmb: 0x0323,
  10193. dotbelowcomb: 0x0323,
  10194. dotkatakana: 0x30FB,
  10195. dotlessi: 0x0131,
  10196. dotlessj: 0xF6BE,
  10197. dotlessjstrokehook: 0x0284,
  10198. dotmath: 0x22C5,
  10199. dottedcircle: 0x25CC,
  10200. doubleyodpatah: 0xFB1F,
  10201. doubleyodpatahhebrew: 0xFB1F,
  10202. downtackbelowcmb: 0x031E,
  10203. downtackmod: 0x02D5,
  10204. dparen: 0x249F,
  10205. dsuperior: 0xF6EB,
  10206. dtail: 0x0256,
  10207. dtopbar: 0x018C,
  10208. duhiragana: 0x3065,
  10209. dukatakana: 0x30C5,
  10210. dz: 0x01F3,
  10211. dzaltone: 0x02A3,
  10212. dzcaron: 0x01C6,
  10213. dzcurl: 0x02A5,
  10214. dzeabkhasiancyrillic: 0x04E1,
  10215. dzecyrillic: 0x0455,
  10216. dzhecyrillic: 0x045F,
  10217. e: 0x0065,
  10218. eacute: 0x00E9,
  10219. earth: 0x2641,
  10220. ebengali: 0x098F,
  10221. ebopomofo: 0x311C,
  10222. ebreve: 0x0115,
  10223. ecandradeva: 0x090D,
  10224. ecandragujarati: 0x0A8D,
  10225. ecandravowelsigndeva: 0x0945,
  10226. ecandravowelsigngujarati: 0x0AC5,
  10227. ecaron: 0x011B,
  10228. ecedillabreve: 0x1E1D,
  10229. echarmenian: 0x0565,
  10230. echyiwnarmenian: 0x0587,
  10231. ecircle: 0x24D4,
  10232. ecircumflex: 0x00EA,
  10233. ecircumflexacute: 0x1EBF,
  10234. ecircumflexbelow: 0x1E19,
  10235. ecircumflexdotbelow: 0x1EC7,
  10236. ecircumflexgrave: 0x1EC1,
  10237. ecircumflexhookabove: 0x1EC3,
  10238. ecircumflextilde: 0x1EC5,
  10239. ecyrillic: 0x0454,
  10240. edblgrave: 0x0205,
  10241. edeva: 0x090F,
  10242. edieresis: 0x00EB,
  10243. edot: 0x0117,
  10244. edotaccent: 0x0117,
  10245. edotbelow: 0x1EB9,
  10246. eegurmukhi: 0x0A0F,
  10247. eematragurmukhi: 0x0A47,
  10248. efcyrillic: 0x0444,
  10249. egrave: 0x00E8,
  10250. egujarati: 0x0A8F,
  10251. eharmenian: 0x0567,
  10252. ehbopomofo: 0x311D,
  10253. ehiragana: 0x3048,
  10254. ehookabove: 0x1EBB,
  10255. eibopomofo: 0x311F,
  10256. eight: 0x0038,
  10257. eightarabic: 0x0668,
  10258. eightbengali: 0x09EE,
  10259. eightcircle: 0x2467,
  10260. eightcircleinversesansserif: 0x2791,
  10261. eightdeva: 0x096E,
  10262. eighteencircle: 0x2471,
  10263. eighteenparen: 0x2485,
  10264. eighteenperiod: 0x2499,
  10265. eightgujarati: 0x0AEE,
  10266. eightgurmukhi: 0x0A6E,
  10267. eighthackarabic: 0x0668,
  10268. eighthangzhou: 0x3028,
  10269. eighthnotebeamed: 0x266B,
  10270. eightideographicparen: 0x3227,
  10271. eightinferior: 0x2088,
  10272. eightmonospace: 0xFF18,
  10273. eightoldstyle: 0xF738,
  10274. eightparen: 0x247B,
  10275. eightperiod: 0x248F,
  10276. eightpersian: 0x06F8,
  10277. eightroman: 0x2177,
  10278. eightsuperior: 0x2078,
  10279. eightthai: 0x0E58,
  10280. einvertedbreve: 0x0207,
  10281. eiotifiedcyrillic: 0x0465,
  10282. ekatakana: 0x30A8,
  10283. ekatakanahalfwidth: 0xFF74,
  10284. ekonkargurmukhi: 0x0A74,
  10285. ekorean: 0x3154,
  10286. elcyrillic: 0x043B,
  10287. element: 0x2208,
  10288. elevencircle: 0x246A,
  10289. elevenparen: 0x247E,
  10290. elevenperiod: 0x2492,
  10291. elevenroman: 0x217A,
  10292. ellipsis: 0x2026,
  10293. ellipsisvertical: 0x22EE,
  10294. emacron: 0x0113,
  10295. emacronacute: 0x1E17,
  10296. emacrongrave: 0x1E15,
  10297. emcyrillic: 0x043C,
  10298. emdash: 0x2014,
  10299. emdashvertical: 0xFE31,
  10300. emonospace: 0xFF45,
  10301. emphasismarkarmenian: 0x055B,
  10302. emptyset: 0x2205,
  10303. enbopomofo: 0x3123,
  10304. encyrillic: 0x043D,
  10305. endash: 0x2013,
  10306. endashvertical: 0xFE32,
  10307. endescendercyrillic: 0x04A3,
  10308. eng: 0x014B,
  10309. engbopomofo: 0x3125,
  10310. enghecyrillic: 0x04A5,
  10311. enhookcyrillic: 0x04C8,
  10312. enspace: 0x2002,
  10313. eogonek: 0x0119,
  10314. eokorean: 0x3153,
  10315. eopen: 0x025B,
  10316. eopenclosed: 0x029A,
  10317. eopenreversed: 0x025C,
  10318. eopenreversedclosed: 0x025E,
  10319. eopenreversedhook: 0x025D,
  10320. eparen: 0x24A0,
  10321. epsilon: 0x03B5,
  10322. epsilontonos: 0x03AD,
  10323. equal: 0x003D,
  10324. equalmonospace: 0xFF1D,
  10325. equalsmall: 0xFE66,
  10326. equalsuperior: 0x207C,
  10327. equivalence: 0x2261,
  10328. erbopomofo: 0x3126,
  10329. ercyrillic: 0x0440,
  10330. ereversed: 0x0258,
  10331. ereversedcyrillic: 0x044D,
  10332. escyrillic: 0x0441,
  10333. esdescendercyrillic: 0x04AB,
  10334. esh: 0x0283,
  10335. eshcurl: 0x0286,
  10336. eshortdeva: 0x090E,
  10337. eshortvowelsigndeva: 0x0946,
  10338. eshreversedloop: 0x01AA,
  10339. eshsquatreversed: 0x0285,
  10340. esmallhiragana: 0x3047,
  10341. esmallkatakana: 0x30A7,
  10342. esmallkatakanahalfwidth: 0xFF6A,
  10343. estimated: 0x212E,
  10344. esuperior: 0xF6EC,
  10345. eta: 0x03B7,
  10346. etarmenian: 0x0568,
  10347. etatonos: 0x03AE,
  10348. eth: 0x00F0,
  10349. etilde: 0x1EBD,
  10350. etildebelow: 0x1E1B,
  10351. etnahtafoukhhebrew: 0x0591,
  10352. etnahtafoukhlefthebrew: 0x0591,
  10353. etnahtahebrew: 0x0591,
  10354. etnahtalefthebrew: 0x0591,
  10355. eturned: 0x01DD,
  10356. eukorean: 0x3161,
  10357. euro: 0x20AC,
  10358. evowelsignbengali: 0x09C7,
  10359. evowelsigndeva: 0x0947,
  10360. evowelsigngujarati: 0x0AC7,
  10361. exclam: 0x0021,
  10362. exclamarmenian: 0x055C,
  10363. exclamdbl: 0x203C,
  10364. exclamdown: 0x00A1,
  10365. exclamdownsmall: 0xF7A1,
  10366. exclammonospace: 0xFF01,
  10367. exclamsmall: 0xF721,
  10368. existential: 0x2203,
  10369. ezh: 0x0292,
  10370. ezhcaron: 0x01EF,
  10371. ezhcurl: 0x0293,
  10372. ezhreversed: 0x01B9,
  10373. ezhtail: 0x01BA,
  10374. f: 0x0066,
  10375. fadeva: 0x095E,
  10376. fagurmukhi: 0x0A5E,
  10377. fahrenheit: 0x2109,
  10378. fathaarabic: 0x064E,
  10379. fathalowarabic: 0x064E,
  10380. fathatanarabic: 0x064B,
  10381. fbopomofo: 0x3108,
  10382. fcircle: 0x24D5,
  10383. fdotaccent: 0x1E1F,
  10384. feharabic: 0x0641,
  10385. feharmenian: 0x0586,
  10386. fehfinalarabic: 0xFED2,
  10387. fehinitialarabic: 0xFED3,
  10388. fehmedialarabic: 0xFED4,
  10389. feicoptic: 0x03E5,
  10390. female: 0x2640,
  10391. ff: 0xFB00,
  10392. ffi: 0xFB03,
  10393. ffl: 0xFB04,
  10394. fi: 0xFB01,
  10395. fifteencircle: 0x246E,
  10396. fifteenparen: 0x2482,
  10397. fifteenperiod: 0x2496,
  10398. figuredash: 0x2012,
  10399. filledbox: 0x25A0,
  10400. filledrect: 0x25AC,
  10401. finalkaf: 0x05DA,
  10402. finalkafdagesh: 0xFB3A,
  10403. finalkafdageshhebrew: 0xFB3A,
  10404. finalkafhebrew: 0x05DA,
  10405. finalmem: 0x05DD,
  10406. finalmemhebrew: 0x05DD,
  10407. finalnun: 0x05DF,
  10408. finalnunhebrew: 0x05DF,
  10409. finalpe: 0x05E3,
  10410. finalpehebrew: 0x05E3,
  10411. finaltsadi: 0x05E5,
  10412. finaltsadihebrew: 0x05E5,
  10413. firsttonechinese: 0x02C9,
  10414. fisheye: 0x25C9,
  10415. fitacyrillic: 0x0473,
  10416. five: 0x0035,
  10417. fivearabic: 0x0665,
  10418. fivebengali: 0x09EB,
  10419. fivecircle: 0x2464,
  10420. fivecircleinversesansserif: 0x278E,
  10421. fivedeva: 0x096B,
  10422. fiveeighths: 0x215D,
  10423. fivegujarati: 0x0AEB,
  10424. fivegurmukhi: 0x0A6B,
  10425. fivehackarabic: 0x0665,
  10426. fivehangzhou: 0x3025,
  10427. fiveideographicparen: 0x3224,
  10428. fiveinferior: 0x2085,
  10429. fivemonospace: 0xFF15,
  10430. fiveoldstyle: 0xF735,
  10431. fiveparen: 0x2478,
  10432. fiveperiod: 0x248C,
  10433. fivepersian: 0x06F5,
  10434. fiveroman: 0x2174,
  10435. fivesuperior: 0x2075,
  10436. fivethai: 0x0E55,
  10437. fl: 0xFB02,
  10438. florin: 0x0192,
  10439. fmonospace: 0xFF46,
  10440. fmsquare: 0x3399,
  10441. fofanthai: 0x0E1F,
  10442. fofathai: 0x0E1D,
  10443. fongmanthai: 0x0E4F,
  10444. forall: 0x2200,
  10445. four: 0x0034,
  10446. fourarabic: 0x0664,
  10447. fourbengali: 0x09EA,
  10448. fourcircle: 0x2463,
  10449. fourcircleinversesansserif: 0x278D,
  10450. fourdeva: 0x096A,
  10451. fourgujarati: 0x0AEA,
  10452. fourgurmukhi: 0x0A6A,
  10453. fourhackarabic: 0x0664,
  10454. fourhangzhou: 0x3024,
  10455. fourideographicparen: 0x3223,
  10456. fourinferior: 0x2084,
  10457. fourmonospace: 0xFF14,
  10458. fournumeratorbengali: 0x09F7,
  10459. fouroldstyle: 0xF734,
  10460. fourparen: 0x2477,
  10461. fourperiod: 0x248B,
  10462. fourpersian: 0x06F4,
  10463. fourroman: 0x2173,
  10464. foursuperior: 0x2074,
  10465. fourteencircle: 0x246D,
  10466. fourteenparen: 0x2481,
  10467. fourteenperiod: 0x2495,
  10468. fourthai: 0x0E54,
  10469. fourthtonechinese: 0x02CB,
  10470. fparen: 0x24A1,
  10471. fraction: 0x2044,
  10472. franc: 0x20A3,
  10473. g: 0x0067,
  10474. gabengali: 0x0997,
  10475. gacute: 0x01F5,
  10476. gadeva: 0x0917,
  10477. gafarabic: 0x06AF,
  10478. gaffinalarabic: 0xFB93,
  10479. gafinitialarabic: 0xFB94,
  10480. gafmedialarabic: 0xFB95,
  10481. gagujarati: 0x0A97,
  10482. gagurmukhi: 0x0A17,
  10483. gahiragana: 0x304C,
  10484. gakatakana: 0x30AC,
  10485. gamma: 0x03B3,
  10486. gammalatinsmall: 0x0263,
  10487. gammasuperior: 0x02E0,
  10488. gangiacoptic: 0x03EB,
  10489. gbopomofo: 0x310D,
  10490. gbreve: 0x011F,
  10491. gcaron: 0x01E7,
  10492. gcedilla: 0x0123,
  10493. gcircle: 0x24D6,
  10494. gcircumflex: 0x011D,
  10495. gcommaaccent: 0x0123,
  10496. gdot: 0x0121,
  10497. gdotaccent: 0x0121,
  10498. gecyrillic: 0x0433,
  10499. gehiragana: 0x3052,
  10500. gekatakana: 0x30B2,
  10501. geometricallyequal: 0x2251,
  10502. gereshaccenthebrew: 0x059C,
  10503. gereshhebrew: 0x05F3,
  10504. gereshmuqdamhebrew: 0x059D,
  10505. germandbls: 0x00DF,
  10506. gershayimaccenthebrew: 0x059E,
  10507. gershayimhebrew: 0x05F4,
  10508. getamark: 0x3013,
  10509. ghabengali: 0x0998,
  10510. ghadarmenian: 0x0572,
  10511. ghadeva: 0x0918,
  10512. ghagujarati: 0x0A98,
  10513. ghagurmukhi: 0x0A18,
  10514. ghainarabic: 0x063A,
  10515. ghainfinalarabic: 0xFECE,
  10516. ghaininitialarabic: 0xFECF,
  10517. ghainmedialarabic: 0xFED0,
  10518. ghemiddlehookcyrillic: 0x0495,
  10519. ghestrokecyrillic: 0x0493,
  10520. gheupturncyrillic: 0x0491,
  10521. ghhadeva: 0x095A,
  10522. ghhagurmukhi: 0x0A5A,
  10523. ghook: 0x0260,
  10524. ghzsquare: 0x3393,
  10525. gihiragana: 0x304E,
  10526. gikatakana: 0x30AE,
  10527. gimarmenian: 0x0563,
  10528. gimel: 0x05D2,
  10529. gimeldagesh: 0xFB32,
  10530. gimeldageshhebrew: 0xFB32,
  10531. gimelhebrew: 0x05D2,
  10532. gjecyrillic: 0x0453,
  10533. glottalinvertedstroke: 0x01BE,
  10534. glottalstop: 0x0294,
  10535. glottalstopinverted: 0x0296,
  10536. glottalstopmod: 0x02C0,
  10537. glottalstopreversed: 0x0295,
  10538. glottalstopreversedmod: 0x02C1,
  10539. glottalstopreversedsuperior: 0x02E4,
  10540. glottalstopstroke: 0x02A1,
  10541. glottalstopstrokereversed: 0x02A2,
  10542. gmacron: 0x1E21,
  10543. gmonospace: 0xFF47,
  10544. gohiragana: 0x3054,
  10545. gokatakana: 0x30B4,
  10546. gparen: 0x24A2,
  10547. gpasquare: 0x33AC,
  10548. gradient: 0x2207,
  10549. grave: 0x0060,
  10550. gravebelowcmb: 0x0316,
  10551. gravecmb: 0x0300,
  10552. gravecomb: 0x0300,
  10553. gravedeva: 0x0953,
  10554. gravelowmod: 0x02CE,
  10555. gravemonospace: 0xFF40,
  10556. gravetonecmb: 0x0340,
  10557. greater: 0x003E,
  10558. greaterequal: 0x2265,
  10559. greaterequalorless: 0x22DB,
  10560. greatermonospace: 0xFF1E,
  10561. greaterorequivalent: 0x2273,
  10562. greaterorless: 0x2277,
  10563. greateroverequal: 0x2267,
  10564. greatersmall: 0xFE65,
  10565. gscript: 0x0261,
  10566. gstroke: 0x01E5,
  10567. guhiragana: 0x3050,
  10568. guillemotleft: 0x00AB,
  10569. guillemotright: 0x00BB,
  10570. guilsinglleft: 0x2039,
  10571. guilsinglright: 0x203A,
  10572. gukatakana: 0x30B0,
  10573. guramusquare: 0x3318,
  10574. gysquare: 0x33C9,
  10575. h: 0x0068,
  10576. haabkhasiancyrillic: 0x04A9,
  10577. haaltonearabic: 0x06C1,
  10578. habengali: 0x09B9,
  10579. hadescendercyrillic: 0x04B3,
  10580. hadeva: 0x0939,
  10581. hagujarati: 0x0AB9,
  10582. hagurmukhi: 0x0A39,
  10583. haharabic: 0x062D,
  10584. hahfinalarabic: 0xFEA2,
  10585. hahinitialarabic: 0xFEA3,
  10586. hahiragana: 0x306F,
  10587. hahmedialarabic: 0xFEA4,
  10588. haitusquare: 0x332A,
  10589. hakatakana: 0x30CF,
  10590. hakatakanahalfwidth: 0xFF8A,
  10591. halantgurmukhi: 0x0A4D,
  10592. hamzaarabic: 0x0621,
  10593. hamzalowarabic: 0x0621,
  10594. hangulfiller: 0x3164,
  10595. hardsigncyrillic: 0x044A,
  10596. harpoonleftbarbup: 0x21BC,
  10597. harpoonrightbarbup: 0x21C0,
  10598. hasquare: 0x33CA,
  10599. hatafpatah: 0x05B2,
  10600. hatafpatah16: 0x05B2,
  10601. hatafpatah23: 0x05B2,
  10602. hatafpatah2f: 0x05B2,
  10603. hatafpatahhebrew: 0x05B2,
  10604. hatafpatahnarrowhebrew: 0x05B2,
  10605. hatafpatahquarterhebrew: 0x05B2,
  10606. hatafpatahwidehebrew: 0x05B2,
  10607. hatafqamats: 0x05B3,
  10608. hatafqamats1b: 0x05B3,
  10609. hatafqamats28: 0x05B3,
  10610. hatafqamats34: 0x05B3,
  10611. hatafqamatshebrew: 0x05B3,
  10612. hatafqamatsnarrowhebrew: 0x05B3,
  10613. hatafqamatsquarterhebrew: 0x05B3,
  10614. hatafqamatswidehebrew: 0x05B3,
  10615. hatafsegol: 0x05B1,
  10616. hatafsegol17: 0x05B1,
  10617. hatafsegol24: 0x05B1,
  10618. hatafsegol30: 0x05B1,
  10619. hatafsegolhebrew: 0x05B1,
  10620. hatafsegolnarrowhebrew: 0x05B1,
  10621. hatafsegolquarterhebrew: 0x05B1,
  10622. hatafsegolwidehebrew: 0x05B1,
  10623. hbar: 0x0127,
  10624. hbopomofo: 0x310F,
  10625. hbrevebelow: 0x1E2B,
  10626. hcedilla: 0x1E29,
  10627. hcircle: 0x24D7,
  10628. hcircumflex: 0x0125,
  10629. hdieresis: 0x1E27,
  10630. hdotaccent: 0x1E23,
  10631. hdotbelow: 0x1E25,
  10632. he: 0x05D4,
  10633. heart: 0x2665,
  10634. heartsuitblack: 0x2665,
  10635. heartsuitwhite: 0x2661,
  10636. hedagesh: 0xFB34,
  10637. hedageshhebrew: 0xFB34,
  10638. hehaltonearabic: 0x06C1,
  10639. heharabic: 0x0647,
  10640. hehebrew: 0x05D4,
  10641. hehfinalaltonearabic: 0xFBA7,
  10642. hehfinalalttwoarabic: 0xFEEA,
  10643. hehfinalarabic: 0xFEEA,
  10644. hehhamzaabovefinalarabic: 0xFBA5,
  10645. hehhamzaaboveisolatedarabic: 0xFBA4,
  10646. hehinitialaltonearabic: 0xFBA8,
  10647. hehinitialarabic: 0xFEEB,
  10648. hehiragana: 0x3078,
  10649. hehmedialaltonearabic: 0xFBA9,
  10650. hehmedialarabic: 0xFEEC,
  10651. heiseierasquare: 0x337B,
  10652. hekatakana: 0x30D8,
  10653. hekatakanahalfwidth: 0xFF8D,
  10654. hekutaarusquare: 0x3336,
  10655. henghook: 0x0267,
  10656. herutusquare: 0x3339,
  10657. het: 0x05D7,
  10658. hethebrew: 0x05D7,
  10659. hhook: 0x0266,
  10660. hhooksuperior: 0x02B1,
  10661. hieuhacirclekorean: 0x327B,
  10662. hieuhaparenkorean: 0x321B,
  10663. hieuhcirclekorean: 0x326D,
  10664. hieuhkorean: 0x314E,
  10665. hieuhparenkorean: 0x320D,
  10666. hihiragana: 0x3072,
  10667. hikatakana: 0x30D2,
  10668. hikatakanahalfwidth: 0xFF8B,
  10669. hiriq: 0x05B4,
  10670. hiriq14: 0x05B4,
  10671. hiriq21: 0x05B4,
  10672. hiriq2d: 0x05B4,
  10673. hiriqhebrew: 0x05B4,
  10674. hiriqnarrowhebrew: 0x05B4,
  10675. hiriqquarterhebrew: 0x05B4,
  10676. hiriqwidehebrew: 0x05B4,
  10677. hlinebelow: 0x1E96,
  10678. hmonospace: 0xFF48,
  10679. hoarmenian: 0x0570,
  10680. hohipthai: 0x0E2B,
  10681. hohiragana: 0x307B,
  10682. hokatakana: 0x30DB,
  10683. hokatakanahalfwidth: 0xFF8E,
  10684. holam: 0x05B9,
  10685. holam19: 0x05B9,
  10686. holam26: 0x05B9,
  10687. holam32: 0x05B9,
  10688. holamhebrew: 0x05B9,
  10689. holamnarrowhebrew: 0x05B9,
  10690. holamquarterhebrew: 0x05B9,
  10691. holamwidehebrew: 0x05B9,
  10692. honokhukthai: 0x0E2E,
  10693. hookabovecomb: 0x0309,
  10694. hookcmb: 0x0309,
  10695. hookpalatalizedbelowcmb: 0x0321,
  10696. hookretroflexbelowcmb: 0x0322,
  10697. hoonsquare: 0x3342,
  10698. horicoptic: 0x03E9,
  10699. horizontalbar: 0x2015,
  10700. horncmb: 0x031B,
  10701. hotsprings: 0x2668,
  10702. house: 0x2302,
  10703. hparen: 0x24A3,
  10704. hsuperior: 0x02B0,
  10705. hturned: 0x0265,
  10706. huhiragana: 0x3075,
  10707. huiitosquare: 0x3333,
  10708. hukatakana: 0x30D5,
  10709. hukatakanahalfwidth: 0xFF8C,
  10710. hungarumlaut: 0x02DD,
  10711. hungarumlautcmb: 0x030B,
  10712. hv: 0x0195,
  10713. hyphen: 0x002D,
  10714. hypheninferior: 0xF6E5,
  10715. hyphenmonospace: 0xFF0D,
  10716. hyphensmall: 0xFE63,
  10717. hyphensuperior: 0xF6E6,
  10718. hyphentwo: 0x2010,
  10719. i: 0x0069,
  10720. iacute: 0x00ED,
  10721. iacyrillic: 0x044F,
  10722. ibengali: 0x0987,
  10723. ibopomofo: 0x3127,
  10724. ibreve: 0x012D,
  10725. icaron: 0x01D0,
  10726. icircle: 0x24D8,
  10727. icircumflex: 0x00EE,
  10728. icyrillic: 0x0456,
  10729. idblgrave: 0x0209,
  10730. ideographearthcircle: 0x328F,
  10731. ideographfirecircle: 0x328B,
  10732. ideographicallianceparen: 0x323F,
  10733. ideographiccallparen: 0x323A,
  10734. ideographiccentrecircle: 0x32A5,
  10735. ideographicclose: 0x3006,
  10736. ideographiccomma: 0x3001,
  10737. ideographiccommaleft: 0xFF64,
  10738. ideographiccongratulationparen: 0x3237,
  10739. ideographiccorrectcircle: 0x32A3,
  10740. ideographicearthparen: 0x322F,
  10741. ideographicenterpriseparen: 0x323D,
  10742. ideographicexcellentcircle: 0x329D,
  10743. ideographicfestivalparen: 0x3240,
  10744. ideographicfinancialcircle: 0x3296,
  10745. ideographicfinancialparen: 0x3236,
  10746. ideographicfireparen: 0x322B,
  10747. ideographichaveparen: 0x3232,
  10748. ideographichighcircle: 0x32A4,
  10749. ideographiciterationmark: 0x3005,
  10750. ideographiclaborcircle: 0x3298,
  10751. ideographiclaborparen: 0x3238,
  10752. ideographicleftcircle: 0x32A7,
  10753. ideographiclowcircle: 0x32A6,
  10754. ideographicmedicinecircle: 0x32A9,
  10755. ideographicmetalparen: 0x322E,
  10756. ideographicmoonparen: 0x322A,
  10757. ideographicnameparen: 0x3234,
  10758. ideographicperiod: 0x3002,
  10759. ideographicprintcircle: 0x329E,
  10760. ideographicreachparen: 0x3243,
  10761. ideographicrepresentparen: 0x3239,
  10762. ideographicresourceparen: 0x323E,
  10763. ideographicrightcircle: 0x32A8,
  10764. ideographicsecretcircle: 0x3299,
  10765. ideographicselfparen: 0x3242,
  10766. ideographicsocietyparen: 0x3233,
  10767. ideographicspace: 0x3000,
  10768. ideographicspecialparen: 0x3235,
  10769. ideographicstockparen: 0x3231,
  10770. ideographicstudyparen: 0x323B,
  10771. ideographicsunparen: 0x3230,
  10772. ideographicsuperviseparen: 0x323C,
  10773. ideographicwaterparen: 0x322C,
  10774. ideographicwoodparen: 0x322D,
  10775. ideographiczero: 0x3007,
  10776. ideographmetalcircle: 0x328E,
  10777. ideographmooncircle: 0x328A,
  10778. ideographnamecircle: 0x3294,
  10779. ideographsuncircle: 0x3290,
  10780. ideographwatercircle: 0x328C,
  10781. ideographwoodcircle: 0x328D,
  10782. ideva: 0x0907,
  10783. idieresis: 0x00EF,
  10784. idieresisacute: 0x1E2F,
  10785. idieresiscyrillic: 0x04E5,
  10786. idotbelow: 0x1ECB,
  10787. iebrevecyrillic: 0x04D7,
  10788. iecyrillic: 0x0435,
  10789. ieungacirclekorean: 0x3275,
  10790. ieungaparenkorean: 0x3215,
  10791. ieungcirclekorean: 0x3267,
  10792. ieungkorean: 0x3147,
  10793. ieungparenkorean: 0x3207,
  10794. igrave: 0x00EC,
  10795. igujarati: 0x0A87,
  10796. igurmukhi: 0x0A07,
  10797. ihiragana: 0x3044,
  10798. ihookabove: 0x1EC9,
  10799. iibengali: 0x0988,
  10800. iicyrillic: 0x0438,
  10801. iideva: 0x0908,
  10802. iigujarati: 0x0A88,
  10803. iigurmukhi: 0x0A08,
  10804. iimatragurmukhi: 0x0A40,
  10805. iinvertedbreve: 0x020B,
  10806. iishortcyrillic: 0x0439,
  10807. iivowelsignbengali: 0x09C0,
  10808. iivowelsigndeva: 0x0940,
  10809. iivowelsigngujarati: 0x0AC0,
  10810. ij: 0x0133,
  10811. ikatakana: 0x30A4,
  10812. ikatakanahalfwidth: 0xFF72,
  10813. ikorean: 0x3163,
  10814. ilde: 0x02DC,
  10815. iluyhebrew: 0x05AC,
  10816. imacron: 0x012B,
  10817. imacroncyrillic: 0x04E3,
  10818. imageorapproximatelyequal: 0x2253,
  10819. imatragurmukhi: 0x0A3F,
  10820. imonospace: 0xFF49,
  10821. increment: 0x2206,
  10822. infinity: 0x221E,
  10823. iniarmenian: 0x056B,
  10824. integral: 0x222B,
  10825. integralbottom: 0x2321,
  10826. integralbt: 0x2321,
  10827. integralex: 0xF8F5,
  10828. integraltop: 0x2320,
  10829. integraltp: 0x2320,
  10830. intersection: 0x2229,
  10831. intisquare: 0x3305,
  10832. invbullet: 0x25D8,
  10833. invcircle: 0x25D9,
  10834. invsmileface: 0x263B,
  10835. iocyrillic: 0x0451,
  10836. iogonek: 0x012F,
  10837. iota: 0x03B9,
  10838. iotadieresis: 0x03CA,
  10839. iotadieresistonos: 0x0390,
  10840. iotalatin: 0x0269,
  10841. iotatonos: 0x03AF,
  10842. iparen: 0x24A4,
  10843. irigurmukhi: 0x0A72,
  10844. ismallhiragana: 0x3043,
  10845. ismallkatakana: 0x30A3,
  10846. ismallkatakanahalfwidth: 0xFF68,
  10847. issharbengali: 0x09FA,
  10848. istroke: 0x0268,
  10849. isuperior: 0xF6ED,
  10850. iterationhiragana: 0x309D,
  10851. iterationkatakana: 0x30FD,
  10852. itilde: 0x0129,
  10853. itildebelow: 0x1E2D,
  10854. iubopomofo: 0x3129,
  10855. iucyrillic: 0x044E,
  10856. ivowelsignbengali: 0x09BF,
  10857. ivowelsigndeva: 0x093F,
  10858. ivowelsigngujarati: 0x0ABF,
  10859. izhitsacyrillic: 0x0475,
  10860. izhitsadblgravecyrillic: 0x0477,
  10861. j: 0x006A,
  10862. jaarmenian: 0x0571,
  10863. jabengali: 0x099C,
  10864. jadeva: 0x091C,
  10865. jagujarati: 0x0A9C,
  10866. jagurmukhi: 0x0A1C,
  10867. jbopomofo: 0x3110,
  10868. jcaron: 0x01F0,
  10869. jcircle: 0x24D9,
  10870. jcircumflex: 0x0135,
  10871. jcrossedtail: 0x029D,
  10872. jdotlessstroke: 0x025F,
  10873. jecyrillic: 0x0458,
  10874. jeemarabic: 0x062C,
  10875. jeemfinalarabic: 0xFE9E,
  10876. jeeminitialarabic: 0xFE9F,
  10877. jeemmedialarabic: 0xFEA0,
  10878. jeharabic: 0x0698,
  10879. jehfinalarabic: 0xFB8B,
  10880. jhabengali: 0x099D,
  10881. jhadeva: 0x091D,
  10882. jhagujarati: 0x0A9D,
  10883. jhagurmukhi: 0x0A1D,
  10884. jheharmenian: 0x057B,
  10885. jis: 0x3004,
  10886. jmonospace: 0xFF4A,
  10887. jparen: 0x24A5,
  10888. jsuperior: 0x02B2,
  10889. k: 0x006B,
  10890. kabashkircyrillic: 0x04A1,
  10891. kabengali: 0x0995,
  10892. kacute: 0x1E31,
  10893. kacyrillic: 0x043A,
  10894. kadescendercyrillic: 0x049B,
  10895. kadeva: 0x0915,
  10896. kaf: 0x05DB,
  10897. kafarabic: 0x0643,
  10898. kafdagesh: 0xFB3B,
  10899. kafdageshhebrew: 0xFB3B,
  10900. kaffinalarabic: 0xFEDA,
  10901. kafhebrew: 0x05DB,
  10902. kafinitialarabic: 0xFEDB,
  10903. kafmedialarabic: 0xFEDC,
  10904. kafrafehebrew: 0xFB4D,
  10905. kagujarati: 0x0A95,
  10906. kagurmukhi: 0x0A15,
  10907. kahiragana: 0x304B,
  10908. kahookcyrillic: 0x04C4,
  10909. kakatakana: 0x30AB,
  10910. kakatakanahalfwidth: 0xFF76,
  10911. kappa: 0x03BA,
  10912. kappasymbolgreek: 0x03F0,
  10913. kapyeounmieumkorean: 0x3171,
  10914. kapyeounphieuphkorean: 0x3184,
  10915. kapyeounpieupkorean: 0x3178,
  10916. kapyeounssangpieupkorean: 0x3179,
  10917. karoriisquare: 0x330D,
  10918. kashidaautoarabic: 0x0640,
  10919. kashidaautonosidebearingarabic: 0x0640,
  10920. kasmallkatakana: 0x30F5,
  10921. kasquare: 0x3384,
  10922. kasraarabic: 0x0650,
  10923. kasratanarabic: 0x064D,
  10924. kastrokecyrillic: 0x049F,
  10925. katahiraprolongmarkhalfwidth: 0xFF70,
  10926. kaverticalstrokecyrillic: 0x049D,
  10927. kbopomofo: 0x310E,
  10928. kcalsquare: 0x3389,
  10929. kcaron: 0x01E9,
  10930. kcedilla: 0x0137,
  10931. kcircle: 0x24DA,
  10932. kcommaaccent: 0x0137,
  10933. kdotbelow: 0x1E33,
  10934. keharmenian: 0x0584,
  10935. kehiragana: 0x3051,
  10936. kekatakana: 0x30B1,
  10937. kekatakanahalfwidth: 0xFF79,
  10938. kenarmenian: 0x056F,
  10939. kesmallkatakana: 0x30F6,
  10940. kgreenlandic: 0x0138,
  10941. khabengali: 0x0996,
  10942. khacyrillic: 0x0445,
  10943. khadeva: 0x0916,
  10944. khagujarati: 0x0A96,
  10945. khagurmukhi: 0x0A16,
  10946. khaharabic: 0x062E,
  10947. khahfinalarabic: 0xFEA6,
  10948. khahinitialarabic: 0xFEA7,
  10949. khahmedialarabic: 0xFEA8,
  10950. kheicoptic: 0x03E7,
  10951. khhadeva: 0x0959,
  10952. khhagurmukhi: 0x0A59,
  10953. khieukhacirclekorean: 0x3278,
  10954. khieukhaparenkorean: 0x3218,
  10955. khieukhcirclekorean: 0x326A,
  10956. khieukhkorean: 0x314B,
  10957. khieukhparenkorean: 0x320A,
  10958. khokhaithai: 0x0E02,
  10959. khokhonthai: 0x0E05,
  10960. khokhuatthai: 0x0E03,
  10961. khokhwaithai: 0x0E04,
  10962. khomutthai: 0x0E5B,
  10963. khook: 0x0199,
  10964. khorakhangthai: 0x0E06,
  10965. khzsquare: 0x3391,
  10966. kihiragana: 0x304D,
  10967. kikatakana: 0x30AD,
  10968. kikatakanahalfwidth: 0xFF77,
  10969. kiroguramusquare: 0x3315,
  10970. kiromeetorusquare: 0x3316,
  10971. kirosquare: 0x3314,
  10972. kiyeokacirclekorean: 0x326E,
  10973. kiyeokaparenkorean: 0x320E,
  10974. kiyeokcirclekorean: 0x3260,
  10975. kiyeokkorean: 0x3131,
  10976. kiyeokparenkorean: 0x3200,
  10977. kiyeoksioskorean: 0x3133,
  10978. kjecyrillic: 0x045C,
  10979. klinebelow: 0x1E35,
  10980. klsquare: 0x3398,
  10981. kmcubedsquare: 0x33A6,
  10982. kmonospace: 0xFF4B,
  10983. kmsquaredsquare: 0x33A2,
  10984. kohiragana: 0x3053,
  10985. kohmsquare: 0x33C0,
  10986. kokaithai: 0x0E01,
  10987. kokatakana: 0x30B3,
  10988. kokatakanahalfwidth: 0xFF7A,
  10989. kooposquare: 0x331E,
  10990. koppacyrillic: 0x0481,
  10991. koreanstandardsymbol: 0x327F,
  10992. koroniscmb: 0x0343,
  10993. kparen: 0x24A6,
  10994. kpasquare: 0x33AA,
  10995. ksicyrillic: 0x046F,
  10996. ktsquare: 0x33CF,
  10997. kturned: 0x029E,
  10998. kuhiragana: 0x304F,
  10999. kukatakana: 0x30AF,
  11000. kukatakanahalfwidth: 0xFF78,
  11001. kvsquare: 0x33B8,
  11002. kwsquare: 0x33BE,
  11003. l: 0x006C,
  11004. labengali: 0x09B2,
  11005. lacute: 0x013A,
  11006. ladeva: 0x0932,
  11007. lagujarati: 0x0AB2,
  11008. lagurmukhi: 0x0A32,
  11009. lakkhangyaothai: 0x0E45,
  11010. lamaleffinalarabic: 0xFEFC,
  11011. lamalefhamzaabovefinalarabic: 0xFEF8,
  11012. lamalefhamzaaboveisolatedarabic: 0xFEF7,
  11013. lamalefhamzabelowfinalarabic: 0xFEFA,
  11014. lamalefhamzabelowisolatedarabic: 0xFEF9,
  11015. lamalefisolatedarabic: 0xFEFB,
  11016. lamalefmaddaabovefinalarabic: 0xFEF6,
  11017. lamalefmaddaaboveisolatedarabic: 0xFEF5,
  11018. lamarabic: 0x0644,
  11019. lambda: 0x03BB,
  11020. lambdastroke: 0x019B,
  11021. lamed: 0x05DC,
  11022. lameddagesh: 0xFB3C,
  11023. lameddageshhebrew: 0xFB3C,
  11024. lamedhebrew: 0x05DC,
  11025. lamfinalarabic: 0xFEDE,
  11026. lamhahinitialarabic: 0xFCCA,
  11027. laminitialarabic: 0xFEDF,
  11028. lamjeeminitialarabic: 0xFCC9,
  11029. lamkhahinitialarabic: 0xFCCB,
  11030. lamlamhehisolatedarabic: 0xFDF2,
  11031. lammedialarabic: 0xFEE0,
  11032. lammeemhahinitialarabic: 0xFD88,
  11033. lammeeminitialarabic: 0xFCCC,
  11034. largecircle: 0x25EF,
  11035. lbar: 0x019A,
  11036. lbelt: 0x026C,
  11037. lbopomofo: 0x310C,
  11038. lcaron: 0x013E,
  11039. lcedilla: 0x013C,
  11040. lcircle: 0x24DB,
  11041. lcircumflexbelow: 0x1E3D,
  11042. lcommaaccent: 0x013C,
  11043. ldot: 0x0140,
  11044. ldotaccent: 0x0140,
  11045. ldotbelow: 0x1E37,
  11046. ldotbelowmacron: 0x1E39,
  11047. leftangleabovecmb: 0x031A,
  11048. lefttackbelowcmb: 0x0318,
  11049. less: 0x003C,
  11050. lessequal: 0x2264,
  11051. lessequalorgreater: 0x22DA,
  11052. lessmonospace: 0xFF1C,
  11053. lessorequivalent: 0x2272,
  11054. lessorgreater: 0x2276,
  11055. lessoverequal: 0x2266,
  11056. lesssmall: 0xFE64,
  11057. lezh: 0x026E,
  11058. lfblock: 0x258C,
  11059. lhookretroflex: 0x026D,
  11060. lira: 0x20A4,
  11061. liwnarmenian: 0x056C,
  11062. lj: 0x01C9,
  11063. ljecyrillic: 0x0459,
  11064. ll: 0xF6C0,
  11065. lladeva: 0x0933,
  11066. llagujarati: 0x0AB3,
  11067. llinebelow: 0x1E3B,
  11068. llladeva: 0x0934,
  11069. llvocalicbengali: 0x09E1,
  11070. llvocalicdeva: 0x0961,
  11071. llvocalicvowelsignbengali: 0x09E3,
  11072. llvocalicvowelsigndeva: 0x0963,
  11073. lmiddletilde: 0x026B,
  11074. lmonospace: 0xFF4C,
  11075. lmsquare: 0x33D0,
  11076. lochulathai: 0x0E2C,
  11077. logicaland: 0x2227,
  11078. logicalnot: 0x00AC,
  11079. logicalnotreversed: 0x2310,
  11080. logicalor: 0x2228,
  11081. lolingthai: 0x0E25,
  11082. longs: 0x017F,
  11083. lowlinecenterline: 0xFE4E,
  11084. lowlinecmb: 0x0332,
  11085. lowlinedashed: 0xFE4D,
  11086. lozenge: 0x25CA,
  11087. lparen: 0x24A7,
  11088. lslash: 0x0142,
  11089. lsquare: 0x2113,
  11090. lsuperior: 0xF6EE,
  11091. ltshade: 0x2591,
  11092. luthai: 0x0E26,
  11093. lvocalicbengali: 0x098C,
  11094. lvocalicdeva: 0x090C,
  11095. lvocalicvowelsignbengali: 0x09E2,
  11096. lvocalicvowelsigndeva: 0x0962,
  11097. lxsquare: 0x33D3,
  11098. m: 0x006D,
  11099. mabengali: 0x09AE,
  11100. macron: 0x00AF,
  11101. macronbelowcmb: 0x0331,
  11102. macroncmb: 0x0304,
  11103. macronlowmod: 0x02CD,
  11104. macronmonospace: 0xFFE3,
  11105. macute: 0x1E3F,
  11106. madeva: 0x092E,
  11107. magujarati: 0x0AAE,
  11108. magurmukhi: 0x0A2E,
  11109. mahapakhhebrew: 0x05A4,
  11110. mahapakhlefthebrew: 0x05A4,
  11111. mahiragana: 0x307E,
  11112. maichattawalowleftthai: 0xF895,
  11113. maichattawalowrightthai: 0xF894,
  11114. maichattawathai: 0x0E4B,
  11115. maichattawaupperleftthai: 0xF893,
  11116. maieklowleftthai: 0xF88C,
  11117. maieklowrightthai: 0xF88B,
  11118. maiekthai: 0x0E48,
  11119. maiekupperleftthai: 0xF88A,
  11120. maihanakatleftthai: 0xF884,
  11121. maihanakatthai: 0x0E31,
  11122. maitaikhuleftthai: 0xF889,
  11123. maitaikhuthai: 0x0E47,
  11124. maitholowleftthai: 0xF88F,
  11125. maitholowrightthai: 0xF88E,
  11126. maithothai: 0x0E49,
  11127. maithoupperleftthai: 0xF88D,
  11128. maitrilowleftthai: 0xF892,
  11129. maitrilowrightthai: 0xF891,
  11130. maitrithai: 0x0E4A,
  11131. maitriupperleftthai: 0xF890,
  11132. maiyamokthai: 0x0E46,
  11133. makatakana: 0x30DE,
  11134. makatakanahalfwidth: 0xFF8F,
  11135. male: 0x2642,
  11136. mansyonsquare: 0x3347,
  11137. maqafhebrew: 0x05BE,
  11138. mars: 0x2642,
  11139. masoracirclehebrew: 0x05AF,
  11140. masquare: 0x3383,
  11141. mbopomofo: 0x3107,
  11142. mbsquare: 0x33D4,
  11143. mcircle: 0x24DC,
  11144. mcubedsquare: 0x33A5,
  11145. mdotaccent: 0x1E41,
  11146. mdotbelow: 0x1E43,
  11147. meemarabic: 0x0645,
  11148. meemfinalarabic: 0xFEE2,
  11149. meeminitialarabic: 0xFEE3,
  11150. meemmedialarabic: 0xFEE4,
  11151. meemmeeminitialarabic: 0xFCD1,
  11152. meemmeemisolatedarabic: 0xFC48,
  11153. meetorusquare: 0x334D,
  11154. mehiragana: 0x3081,
  11155. meizierasquare: 0x337E,
  11156. mekatakana: 0x30E1,
  11157. mekatakanahalfwidth: 0xFF92,
  11158. mem: 0x05DE,
  11159. memdagesh: 0xFB3E,
  11160. memdageshhebrew: 0xFB3E,
  11161. memhebrew: 0x05DE,
  11162. menarmenian: 0x0574,
  11163. merkhahebrew: 0x05A5,
  11164. merkhakefulahebrew: 0x05A6,
  11165. merkhakefulalefthebrew: 0x05A6,
  11166. merkhalefthebrew: 0x05A5,
  11167. mhook: 0x0271,
  11168. mhzsquare: 0x3392,
  11169. middledotkatakanahalfwidth: 0xFF65,
  11170. middot: 0x00B7,
  11171. mieumacirclekorean: 0x3272,
  11172. mieumaparenkorean: 0x3212,
  11173. mieumcirclekorean: 0x3264,
  11174. mieumkorean: 0x3141,
  11175. mieumpansioskorean: 0x3170,
  11176. mieumparenkorean: 0x3204,
  11177. mieumpieupkorean: 0x316E,
  11178. mieumsioskorean: 0x316F,
  11179. mihiragana: 0x307F,
  11180. mikatakana: 0x30DF,
  11181. mikatakanahalfwidth: 0xFF90,
  11182. minus: 0x2212,
  11183. minusbelowcmb: 0x0320,
  11184. minuscircle: 0x2296,
  11185. minusmod: 0x02D7,
  11186. minusplus: 0x2213,
  11187. minute: 0x2032,
  11188. miribaarusquare: 0x334A,
  11189. mirisquare: 0x3349,
  11190. mlonglegturned: 0x0270,
  11191. mlsquare: 0x3396,
  11192. mmcubedsquare: 0x33A3,
  11193. mmonospace: 0xFF4D,
  11194. mmsquaredsquare: 0x339F,
  11195. mohiragana: 0x3082,
  11196. mohmsquare: 0x33C1,
  11197. mokatakana: 0x30E2,
  11198. mokatakanahalfwidth: 0xFF93,
  11199. molsquare: 0x33D6,
  11200. momathai: 0x0E21,
  11201. moverssquare: 0x33A7,
  11202. moverssquaredsquare: 0x33A8,
  11203. mparen: 0x24A8,
  11204. mpasquare: 0x33AB,
  11205. mssquare: 0x33B3,
  11206. msuperior: 0xF6EF,
  11207. mturned: 0x026F,
  11208. mu: 0x00B5,
  11209. mu1: 0x00B5,
  11210. muasquare: 0x3382,
  11211. muchgreater: 0x226B,
  11212. muchless: 0x226A,
  11213. mufsquare: 0x338C,
  11214. mugreek: 0x03BC,
  11215. mugsquare: 0x338D,
  11216. muhiragana: 0x3080,
  11217. mukatakana: 0x30E0,
  11218. mukatakanahalfwidth: 0xFF91,
  11219. mulsquare: 0x3395,
  11220. multiply: 0x00D7,
  11221. mumsquare: 0x339B,
  11222. munahhebrew: 0x05A3,
  11223. munahlefthebrew: 0x05A3,
  11224. musicalnote: 0x266A,
  11225. musicalnotedbl: 0x266B,
  11226. musicflatsign: 0x266D,
  11227. musicsharpsign: 0x266F,
  11228. mussquare: 0x33B2,
  11229. muvsquare: 0x33B6,
  11230. muwsquare: 0x33BC,
  11231. mvmegasquare: 0x33B9,
  11232. mvsquare: 0x33B7,
  11233. mwmegasquare: 0x33BF,
  11234. mwsquare: 0x33BD,
  11235. n: 0x006E,
  11236. nabengali: 0x09A8,
  11237. nabla: 0x2207,
  11238. nacute: 0x0144,
  11239. nadeva: 0x0928,
  11240. nagujarati: 0x0AA8,
  11241. nagurmukhi: 0x0A28,
  11242. nahiragana: 0x306A,
  11243. nakatakana: 0x30CA,
  11244. nakatakanahalfwidth: 0xFF85,
  11245. napostrophe: 0x0149,
  11246. nasquare: 0x3381,
  11247. nbopomofo: 0x310B,
  11248. nbspace: 0x00A0,
  11249. ncaron: 0x0148,
  11250. ncedilla: 0x0146,
  11251. ncircle: 0x24DD,
  11252. ncircumflexbelow: 0x1E4B,
  11253. ncommaaccent: 0x0146,
  11254. ndotaccent: 0x1E45,
  11255. ndotbelow: 0x1E47,
  11256. nehiragana: 0x306D,
  11257. nekatakana: 0x30CD,
  11258. nekatakanahalfwidth: 0xFF88,
  11259. newsheqelsign: 0x20AA,
  11260. nfsquare: 0x338B,
  11261. ngabengali: 0x0999,
  11262. ngadeva: 0x0919,
  11263. ngagujarati: 0x0A99,
  11264. ngagurmukhi: 0x0A19,
  11265. ngonguthai: 0x0E07,
  11266. nhiragana: 0x3093,
  11267. nhookleft: 0x0272,
  11268. nhookretroflex: 0x0273,
  11269. nieunacirclekorean: 0x326F,
  11270. nieunaparenkorean: 0x320F,
  11271. nieuncieuckorean: 0x3135,
  11272. nieuncirclekorean: 0x3261,
  11273. nieunhieuhkorean: 0x3136,
  11274. nieunkorean: 0x3134,
  11275. nieunpansioskorean: 0x3168,
  11276. nieunparenkorean: 0x3201,
  11277. nieunsioskorean: 0x3167,
  11278. nieuntikeutkorean: 0x3166,
  11279. nihiragana: 0x306B,
  11280. nikatakana: 0x30CB,
  11281. nikatakanahalfwidth: 0xFF86,
  11282. nikhahitleftthai: 0xF899,
  11283. nikhahitthai: 0x0E4D,
  11284. nine: 0x0039,
  11285. ninearabic: 0x0669,
  11286. ninebengali: 0x09EF,
  11287. ninecircle: 0x2468,
  11288. ninecircleinversesansserif: 0x2792,
  11289. ninedeva: 0x096F,
  11290. ninegujarati: 0x0AEF,
  11291. ninegurmukhi: 0x0A6F,
  11292. ninehackarabic: 0x0669,
  11293. ninehangzhou: 0x3029,
  11294. nineideographicparen: 0x3228,
  11295. nineinferior: 0x2089,
  11296. ninemonospace: 0xFF19,
  11297. nineoldstyle: 0xF739,
  11298. nineparen: 0x247C,
  11299. nineperiod: 0x2490,
  11300. ninepersian: 0x06F9,
  11301. nineroman: 0x2178,
  11302. ninesuperior: 0x2079,
  11303. nineteencircle: 0x2472,
  11304. nineteenparen: 0x2486,
  11305. nineteenperiod: 0x249A,
  11306. ninethai: 0x0E59,
  11307. nj: 0x01CC,
  11308. njecyrillic: 0x045A,
  11309. nkatakana: 0x30F3,
  11310. nkatakanahalfwidth: 0xFF9D,
  11311. nlegrightlong: 0x019E,
  11312. nlinebelow: 0x1E49,
  11313. nmonospace: 0xFF4E,
  11314. nmsquare: 0x339A,
  11315. nnabengali: 0x09A3,
  11316. nnadeva: 0x0923,
  11317. nnagujarati: 0x0AA3,
  11318. nnagurmukhi: 0x0A23,
  11319. nnnadeva: 0x0929,
  11320. nohiragana: 0x306E,
  11321. nokatakana: 0x30CE,
  11322. nokatakanahalfwidth: 0xFF89,
  11323. nonbreakingspace: 0x00A0,
  11324. nonenthai: 0x0E13,
  11325. nonuthai: 0x0E19,
  11326. noonarabic: 0x0646,
  11327. noonfinalarabic: 0xFEE6,
  11328. noonghunnaarabic: 0x06BA,
  11329. noonghunnafinalarabic: 0xFB9F,
  11330. nooninitialarabic: 0xFEE7,
  11331. noonjeeminitialarabic: 0xFCD2,
  11332. noonjeemisolatedarabic: 0xFC4B,
  11333. noonmedialarabic: 0xFEE8,
  11334. noonmeeminitialarabic: 0xFCD5,
  11335. noonmeemisolatedarabic: 0xFC4E,
  11336. noonnoonfinalarabic: 0xFC8D,
  11337. notcontains: 0x220C,
  11338. notelement: 0x2209,
  11339. notelementof: 0x2209,
  11340. notequal: 0x2260,
  11341. notgreater: 0x226F,
  11342. notgreaternorequal: 0x2271,
  11343. notgreaternorless: 0x2279,
  11344. notidentical: 0x2262,
  11345. notless: 0x226E,
  11346. notlessnorequal: 0x2270,
  11347. notparallel: 0x2226,
  11348. notprecedes: 0x2280,
  11349. notsubset: 0x2284,
  11350. notsucceeds: 0x2281,
  11351. notsuperset: 0x2285,
  11352. nowarmenian: 0x0576,
  11353. nparen: 0x24A9,
  11354. nssquare: 0x33B1,
  11355. nsuperior: 0x207F,
  11356. ntilde: 0x00F1,
  11357. nu: 0x03BD,
  11358. nuhiragana: 0x306C,
  11359. nukatakana: 0x30CC,
  11360. nukatakanahalfwidth: 0xFF87,
  11361. nuktabengali: 0x09BC,
  11362. nuktadeva: 0x093C,
  11363. nuktagujarati: 0x0ABC,
  11364. nuktagurmukhi: 0x0A3C,
  11365. numbersign: 0x0023,
  11366. numbersignmonospace: 0xFF03,
  11367. numbersignsmall: 0xFE5F,
  11368. numeralsigngreek: 0x0374,
  11369. numeralsignlowergreek: 0x0375,
  11370. numero: 0x2116,
  11371. nun: 0x05E0,
  11372. nundagesh: 0xFB40,
  11373. nundageshhebrew: 0xFB40,
  11374. nunhebrew: 0x05E0,
  11375. nvsquare: 0x33B5,
  11376. nwsquare: 0x33BB,
  11377. nyabengali: 0x099E,
  11378. nyadeva: 0x091E,
  11379. nyagujarati: 0x0A9E,
  11380. nyagurmukhi: 0x0A1E,
  11381. o: 0x006F,
  11382. oacute: 0x00F3,
  11383. oangthai: 0x0E2D,
  11384. obarred: 0x0275,
  11385. obarredcyrillic: 0x04E9,
  11386. obarreddieresiscyrillic: 0x04EB,
  11387. obengali: 0x0993,
  11388. obopomofo: 0x311B,
  11389. obreve: 0x014F,
  11390. ocandradeva: 0x0911,
  11391. ocandragujarati: 0x0A91,
  11392. ocandravowelsigndeva: 0x0949,
  11393. ocandravowelsigngujarati: 0x0AC9,
  11394. ocaron: 0x01D2,
  11395. ocircle: 0x24DE,
  11396. ocircumflex: 0x00F4,
  11397. ocircumflexacute: 0x1ED1,
  11398. ocircumflexdotbelow: 0x1ED9,
  11399. ocircumflexgrave: 0x1ED3,
  11400. ocircumflexhookabove: 0x1ED5,
  11401. ocircumflextilde: 0x1ED7,
  11402. ocyrillic: 0x043E,
  11403. odblacute: 0x0151,
  11404. odblgrave: 0x020D,
  11405. odeva: 0x0913,
  11406. odieresis: 0x00F6,
  11407. odieresiscyrillic: 0x04E7,
  11408. odotbelow: 0x1ECD,
  11409. oe: 0x0153,
  11410. oekorean: 0x315A,
  11411. ogonek: 0x02DB,
  11412. ogonekcmb: 0x0328,
  11413. ograve: 0x00F2,
  11414. ogujarati: 0x0A93,
  11415. oharmenian: 0x0585,
  11416. ohiragana: 0x304A,
  11417. ohookabove: 0x1ECF,
  11418. ohorn: 0x01A1,
  11419. ohornacute: 0x1EDB,
  11420. ohorndotbelow: 0x1EE3,
  11421. ohorngrave: 0x1EDD,
  11422. ohornhookabove: 0x1EDF,
  11423. ohorntilde: 0x1EE1,
  11424. ohungarumlaut: 0x0151,
  11425. oi: 0x01A3,
  11426. oinvertedbreve: 0x020F,
  11427. okatakana: 0x30AA,
  11428. okatakanahalfwidth: 0xFF75,
  11429. okorean: 0x3157,
  11430. olehebrew: 0x05AB,
  11431. omacron: 0x014D,
  11432. omacronacute: 0x1E53,
  11433. omacrongrave: 0x1E51,
  11434. omdeva: 0x0950,
  11435. omega: 0x03C9,
  11436. omega1: 0x03D6,
  11437. omegacyrillic: 0x0461,
  11438. omegalatinclosed: 0x0277,
  11439. omegaroundcyrillic: 0x047B,
  11440. omegatitlocyrillic: 0x047D,
  11441. omegatonos: 0x03CE,
  11442. omgujarati: 0x0AD0,
  11443. omicron: 0x03BF,
  11444. omicrontonos: 0x03CC,
  11445. omonospace: 0xFF4F,
  11446. one: 0x0031,
  11447. onearabic: 0x0661,
  11448. onebengali: 0x09E7,
  11449. onecircle: 0x2460,
  11450. onecircleinversesansserif: 0x278A,
  11451. onedeva: 0x0967,
  11452. onedotenleader: 0x2024,
  11453. oneeighth: 0x215B,
  11454. onefitted: 0xF6DC,
  11455. onegujarati: 0x0AE7,
  11456. onegurmukhi: 0x0A67,
  11457. onehackarabic: 0x0661,
  11458. onehalf: 0x00BD,
  11459. onehangzhou: 0x3021,
  11460. oneideographicparen: 0x3220,
  11461. oneinferior: 0x2081,
  11462. onemonospace: 0xFF11,
  11463. onenumeratorbengali: 0x09F4,
  11464. oneoldstyle: 0xF731,
  11465. oneparen: 0x2474,
  11466. oneperiod: 0x2488,
  11467. onepersian: 0x06F1,
  11468. onequarter: 0x00BC,
  11469. oneroman: 0x2170,
  11470. onesuperior: 0x00B9,
  11471. onethai: 0x0E51,
  11472. onethird: 0x2153,
  11473. oogonek: 0x01EB,
  11474. oogonekmacron: 0x01ED,
  11475. oogurmukhi: 0x0A13,
  11476. oomatragurmukhi: 0x0A4B,
  11477. oopen: 0x0254,
  11478. oparen: 0x24AA,
  11479. openbullet: 0x25E6,
  11480. option: 0x2325,
  11481. ordfeminine: 0x00AA,
  11482. ordmasculine: 0x00BA,
  11483. orthogonal: 0x221F,
  11484. oshortdeva: 0x0912,
  11485. oshortvowelsigndeva: 0x094A,
  11486. oslash: 0x00F8,
  11487. oslashacute: 0x01FF,
  11488. osmallhiragana: 0x3049,
  11489. osmallkatakana: 0x30A9,
  11490. osmallkatakanahalfwidth: 0xFF6B,
  11491. ostrokeacute: 0x01FF,
  11492. osuperior: 0xF6F0,
  11493. otcyrillic: 0x047F,
  11494. otilde: 0x00F5,
  11495. otildeacute: 0x1E4D,
  11496. otildedieresis: 0x1E4F,
  11497. oubopomofo: 0x3121,
  11498. overline: 0x203E,
  11499. overlinecenterline: 0xFE4A,
  11500. overlinecmb: 0x0305,
  11501. overlinedashed: 0xFE49,
  11502. overlinedblwavy: 0xFE4C,
  11503. overlinewavy: 0xFE4B,
  11504. overscore: 0x00AF,
  11505. ovowelsignbengali: 0x09CB,
  11506. ovowelsigndeva: 0x094B,
  11507. ovowelsigngujarati: 0x0ACB,
  11508. p: 0x0070,
  11509. paampssquare: 0x3380,
  11510. paasentosquare: 0x332B,
  11511. pabengali: 0x09AA,
  11512. pacute: 0x1E55,
  11513. padeva: 0x092A,
  11514. pagedown: 0x21DF,
  11515. pageup: 0x21DE,
  11516. pagujarati: 0x0AAA,
  11517. pagurmukhi: 0x0A2A,
  11518. pahiragana: 0x3071,
  11519. paiyannoithai: 0x0E2F,
  11520. pakatakana: 0x30D1,
  11521. palatalizationcyrilliccmb: 0x0484,
  11522. palochkacyrillic: 0x04C0,
  11523. pansioskorean: 0x317F,
  11524. paragraph: 0x00B6,
  11525. parallel: 0x2225,
  11526. parenleft: 0x0028,
  11527. parenleftaltonearabic: 0xFD3E,
  11528. parenleftbt: 0xF8ED,
  11529. parenleftex: 0xF8EC,
  11530. parenleftinferior: 0x208D,
  11531. parenleftmonospace: 0xFF08,
  11532. parenleftsmall: 0xFE59,
  11533. parenleftsuperior: 0x207D,
  11534. parenlefttp: 0xF8EB,
  11535. parenleftvertical: 0xFE35,
  11536. parenright: 0x0029,
  11537. parenrightaltonearabic: 0xFD3F,
  11538. parenrightbt: 0xF8F8,
  11539. parenrightex: 0xF8F7,
  11540. parenrightinferior: 0x208E,
  11541. parenrightmonospace: 0xFF09,
  11542. parenrightsmall: 0xFE5A,
  11543. parenrightsuperior: 0x207E,
  11544. parenrighttp: 0xF8F6,
  11545. parenrightvertical: 0xFE36,
  11546. partialdiff: 0x2202,
  11547. paseqhebrew: 0x05C0,
  11548. pashtahebrew: 0x0599,
  11549. pasquare: 0x33A9,
  11550. patah: 0x05B7,
  11551. patah11: 0x05B7,
  11552. patah1d: 0x05B7,
  11553. patah2a: 0x05B7,
  11554. patahhebrew: 0x05B7,
  11555. patahnarrowhebrew: 0x05B7,
  11556. patahquarterhebrew: 0x05B7,
  11557. patahwidehebrew: 0x05B7,
  11558. pazerhebrew: 0x05A1,
  11559. pbopomofo: 0x3106,
  11560. pcircle: 0x24DF,
  11561. pdotaccent: 0x1E57,
  11562. pe: 0x05E4,
  11563. pecyrillic: 0x043F,
  11564. pedagesh: 0xFB44,
  11565. pedageshhebrew: 0xFB44,
  11566. peezisquare: 0x333B,
  11567. pefinaldageshhebrew: 0xFB43,
  11568. peharabic: 0x067E,
  11569. peharmenian: 0x057A,
  11570. pehebrew: 0x05E4,
  11571. pehfinalarabic: 0xFB57,
  11572. pehinitialarabic: 0xFB58,
  11573. pehiragana: 0x307A,
  11574. pehmedialarabic: 0xFB59,
  11575. pekatakana: 0x30DA,
  11576. pemiddlehookcyrillic: 0x04A7,
  11577. perafehebrew: 0xFB4E,
  11578. percent: 0x0025,
  11579. percentarabic: 0x066A,
  11580. percentmonospace: 0xFF05,
  11581. percentsmall: 0xFE6A,
  11582. period: 0x002E,
  11583. periodarmenian: 0x0589,
  11584. periodcentered: 0x00B7,
  11585. periodhalfwidth: 0xFF61,
  11586. periodinferior: 0xF6E7,
  11587. periodmonospace: 0xFF0E,
  11588. periodsmall: 0xFE52,
  11589. periodsuperior: 0xF6E8,
  11590. perispomenigreekcmb: 0x0342,
  11591. perpendicular: 0x22A5,
  11592. perthousand: 0x2030,
  11593. peseta: 0x20A7,
  11594. pfsquare: 0x338A,
  11595. phabengali: 0x09AB,
  11596. phadeva: 0x092B,
  11597. phagujarati: 0x0AAB,
  11598. phagurmukhi: 0x0A2B,
  11599. phi: 0x03C6,
  11600. phi1: 0x03D5,
  11601. phieuphacirclekorean: 0x327A,
  11602. phieuphaparenkorean: 0x321A,
  11603. phieuphcirclekorean: 0x326C,
  11604. phieuphkorean: 0x314D,
  11605. phieuphparenkorean: 0x320C,
  11606. philatin: 0x0278,
  11607. phinthuthai: 0x0E3A,
  11608. phisymbolgreek: 0x03D5,
  11609. phook: 0x01A5,
  11610. phophanthai: 0x0E1E,
  11611. phophungthai: 0x0E1C,
  11612. phosamphaothai: 0x0E20,
  11613. pi: 0x03C0,
  11614. pieupacirclekorean: 0x3273,
  11615. pieupaparenkorean: 0x3213,
  11616. pieupcieuckorean: 0x3176,
  11617. pieupcirclekorean: 0x3265,
  11618. pieupkiyeokkorean: 0x3172,
  11619. pieupkorean: 0x3142,
  11620. pieupparenkorean: 0x3205,
  11621. pieupsioskiyeokkorean: 0x3174,
  11622. pieupsioskorean: 0x3144,
  11623. pieupsiostikeutkorean: 0x3175,
  11624. pieupthieuthkorean: 0x3177,
  11625. pieuptikeutkorean: 0x3173,
  11626. pihiragana: 0x3074,
  11627. pikatakana: 0x30D4,
  11628. pisymbolgreek: 0x03D6,
  11629. piwrarmenian: 0x0583,
  11630. plus: 0x002B,
  11631. plusbelowcmb: 0x031F,
  11632. pluscircle: 0x2295,
  11633. plusminus: 0x00B1,
  11634. plusmod: 0x02D6,
  11635. plusmonospace: 0xFF0B,
  11636. plussmall: 0xFE62,
  11637. plussuperior: 0x207A,
  11638. pmonospace: 0xFF50,
  11639. pmsquare: 0x33D8,
  11640. pohiragana: 0x307D,
  11641. pointingindexdownwhite: 0x261F,
  11642. pointingindexleftwhite: 0x261C,
  11643. pointingindexrightwhite: 0x261E,
  11644. pointingindexupwhite: 0x261D,
  11645. pokatakana: 0x30DD,
  11646. poplathai: 0x0E1B,
  11647. postalmark: 0x3012,
  11648. postalmarkface: 0x3020,
  11649. pparen: 0x24AB,
  11650. precedes: 0x227A,
  11651. prescription: 0x211E,
  11652. primemod: 0x02B9,
  11653. primereversed: 0x2035,
  11654. product: 0x220F,
  11655. projective: 0x2305,
  11656. prolongedkana: 0x30FC,
  11657. propellor: 0x2318,
  11658. propersubset: 0x2282,
  11659. propersuperset: 0x2283,
  11660. proportion: 0x2237,
  11661. proportional: 0x221D,
  11662. psi: 0x03C8,
  11663. psicyrillic: 0x0471,
  11664. psilipneumatacyrilliccmb: 0x0486,
  11665. pssquare: 0x33B0,
  11666. puhiragana: 0x3077,
  11667. pukatakana: 0x30D7,
  11668. pvsquare: 0x33B4,
  11669. pwsquare: 0x33BA,
  11670. q: 0x0071,
  11671. qadeva: 0x0958,
  11672. qadmahebrew: 0x05A8,
  11673. qafarabic: 0x0642,
  11674. qaffinalarabic: 0xFED6,
  11675. qafinitialarabic: 0xFED7,
  11676. qafmedialarabic: 0xFED8,
  11677. qamats: 0x05B8,
  11678. qamats10: 0x05B8,
  11679. qamats1a: 0x05B8,
  11680. qamats1c: 0x05B8,
  11681. qamats27: 0x05B8,
  11682. qamats29: 0x05B8,
  11683. qamats33: 0x05B8,
  11684. qamatsde: 0x05B8,
  11685. qamatshebrew: 0x05B8,
  11686. qamatsnarrowhebrew: 0x05B8,
  11687. qamatsqatanhebrew: 0x05B8,
  11688. qamatsqatannarrowhebrew: 0x05B8,
  11689. qamatsqatanquarterhebrew: 0x05B8,
  11690. qamatsqatanwidehebrew: 0x05B8,
  11691. qamatsquarterhebrew: 0x05B8,
  11692. qamatswidehebrew: 0x05B8,
  11693. qarneyparahebrew: 0x059F,
  11694. qbopomofo: 0x3111,
  11695. qcircle: 0x24E0,
  11696. qhook: 0x02A0,
  11697. qmonospace: 0xFF51,
  11698. qof: 0x05E7,
  11699. qofdagesh: 0xFB47,
  11700. qofdageshhebrew: 0xFB47,
  11701. qofhebrew: 0x05E7,
  11702. qparen: 0x24AC,
  11703. quarternote: 0x2669,
  11704. qubuts: 0x05BB,
  11705. qubuts18: 0x05BB,
  11706. qubuts25: 0x05BB,
  11707. qubuts31: 0x05BB,
  11708. qubutshebrew: 0x05BB,
  11709. qubutsnarrowhebrew: 0x05BB,
  11710. qubutsquarterhebrew: 0x05BB,
  11711. qubutswidehebrew: 0x05BB,
  11712. question: 0x003F,
  11713. questionarabic: 0x061F,
  11714. questionarmenian: 0x055E,
  11715. questiondown: 0x00BF,
  11716. questiondownsmall: 0xF7BF,
  11717. questiongreek: 0x037E,
  11718. questionmonospace: 0xFF1F,
  11719. questionsmall: 0xF73F,
  11720. quotedbl: 0x0022,
  11721. quotedblbase: 0x201E,
  11722. quotedblleft: 0x201C,
  11723. quotedblmonospace: 0xFF02,
  11724. quotedblprime: 0x301E,
  11725. quotedblprimereversed: 0x301D,
  11726. quotedblright: 0x201D,
  11727. quoteleft: 0x2018,
  11728. quoteleftreversed: 0x201B,
  11729. quotereversed: 0x201B,
  11730. quoteright: 0x2019,
  11731. quoterightn: 0x0149,
  11732. quotesinglbase: 0x201A,
  11733. quotesingle: 0x0027,
  11734. quotesinglemonospace: 0xFF07,
  11735. r: 0x0072,
  11736. raarmenian: 0x057C,
  11737. rabengali: 0x09B0,
  11738. racute: 0x0155,
  11739. radeva: 0x0930,
  11740. radical: 0x221A,
  11741. radicalex: 0xF8E5,
  11742. radoverssquare: 0x33AE,
  11743. radoverssquaredsquare: 0x33AF,
  11744. radsquare: 0x33AD,
  11745. rafe: 0x05BF,
  11746. rafehebrew: 0x05BF,
  11747. ragujarati: 0x0AB0,
  11748. ragurmukhi: 0x0A30,
  11749. rahiragana: 0x3089,
  11750. rakatakana: 0x30E9,
  11751. rakatakanahalfwidth: 0xFF97,
  11752. ralowerdiagonalbengali: 0x09F1,
  11753. ramiddlediagonalbengali: 0x09F0,
  11754. ramshorn: 0x0264,
  11755. ratio: 0x2236,
  11756. rbopomofo: 0x3116,
  11757. rcaron: 0x0159,
  11758. rcedilla: 0x0157,
  11759. rcircle: 0x24E1,
  11760. rcommaaccent: 0x0157,
  11761. rdblgrave: 0x0211,
  11762. rdotaccent: 0x1E59,
  11763. rdotbelow: 0x1E5B,
  11764. rdotbelowmacron: 0x1E5D,
  11765. referencemark: 0x203B,
  11766. reflexsubset: 0x2286,
  11767. reflexsuperset: 0x2287,
  11768. registered: 0x00AE,
  11769. registersans: 0xF8E8,
  11770. registerserif: 0xF6DA,
  11771. reharabic: 0x0631,
  11772. reharmenian: 0x0580,
  11773. rehfinalarabic: 0xFEAE,
  11774. rehiragana: 0x308C,
  11775. rekatakana: 0x30EC,
  11776. rekatakanahalfwidth: 0xFF9A,
  11777. resh: 0x05E8,
  11778. reshdageshhebrew: 0xFB48,
  11779. reshhebrew: 0x05E8,
  11780. reversedtilde: 0x223D,
  11781. reviahebrew: 0x0597,
  11782. reviamugrashhebrew: 0x0597,
  11783. revlogicalnot: 0x2310,
  11784. rfishhook: 0x027E,
  11785. rfishhookreversed: 0x027F,
  11786. rhabengali: 0x09DD,
  11787. rhadeva: 0x095D,
  11788. rho: 0x03C1,
  11789. rhook: 0x027D,
  11790. rhookturned: 0x027B,
  11791. rhookturnedsuperior: 0x02B5,
  11792. rhosymbolgreek: 0x03F1,
  11793. rhotichookmod: 0x02DE,
  11794. rieulacirclekorean: 0x3271,
  11795. rieulaparenkorean: 0x3211,
  11796. rieulcirclekorean: 0x3263,
  11797. rieulhieuhkorean: 0x3140,
  11798. rieulkiyeokkorean: 0x313A,
  11799. rieulkiyeoksioskorean: 0x3169,
  11800. rieulkorean: 0x3139,
  11801. rieulmieumkorean: 0x313B,
  11802. rieulpansioskorean: 0x316C,
  11803. rieulparenkorean: 0x3203,
  11804. rieulphieuphkorean: 0x313F,
  11805. rieulpieupkorean: 0x313C,
  11806. rieulpieupsioskorean: 0x316B,
  11807. rieulsioskorean: 0x313D,
  11808. rieulthieuthkorean: 0x313E,
  11809. rieultikeutkorean: 0x316A,
  11810. rieulyeorinhieuhkorean: 0x316D,
  11811. rightangle: 0x221F,
  11812. righttackbelowcmb: 0x0319,
  11813. righttriangle: 0x22BF,
  11814. rihiragana: 0x308A,
  11815. rikatakana: 0x30EA,
  11816. rikatakanahalfwidth: 0xFF98,
  11817. ring: 0x02DA,
  11818. ringbelowcmb: 0x0325,
  11819. ringcmb: 0x030A,
  11820. ringhalfleft: 0x02BF,
  11821. ringhalfleftarmenian: 0x0559,
  11822. ringhalfleftbelowcmb: 0x031C,
  11823. ringhalfleftcentered: 0x02D3,
  11824. ringhalfright: 0x02BE,
  11825. ringhalfrightbelowcmb: 0x0339,
  11826. ringhalfrightcentered: 0x02D2,
  11827. rinvertedbreve: 0x0213,
  11828. rittorusquare: 0x3351,
  11829. rlinebelow: 0x1E5F,
  11830. rlongleg: 0x027C,
  11831. rlonglegturned: 0x027A,
  11832. rmonospace: 0xFF52,
  11833. rohiragana: 0x308D,
  11834. rokatakana: 0x30ED,
  11835. rokatakanahalfwidth: 0xFF9B,
  11836. roruathai: 0x0E23,
  11837. rparen: 0x24AD,
  11838. rrabengali: 0x09DC,
  11839. rradeva: 0x0931,
  11840. rragurmukhi: 0x0A5C,
  11841. rreharabic: 0x0691,
  11842. rrehfinalarabic: 0xFB8D,
  11843. rrvocalicbengali: 0x09E0,
  11844. rrvocalicdeva: 0x0960,
  11845. rrvocalicgujarati: 0x0AE0,
  11846. rrvocalicvowelsignbengali: 0x09C4,
  11847. rrvocalicvowelsigndeva: 0x0944,
  11848. rrvocalicvowelsigngujarati: 0x0AC4,
  11849. rsuperior: 0xF6F1,
  11850. rtblock: 0x2590,
  11851. rturned: 0x0279,
  11852. rturnedsuperior: 0x02B4,
  11853. ruhiragana: 0x308B,
  11854. rukatakana: 0x30EB,
  11855. rukatakanahalfwidth: 0xFF99,
  11856. rupeemarkbengali: 0x09F2,
  11857. rupeesignbengali: 0x09F3,
  11858. rupiah: 0xF6DD,
  11859. ruthai: 0x0E24,
  11860. rvocalicbengali: 0x098B,
  11861. rvocalicdeva: 0x090B,
  11862. rvocalicgujarati: 0x0A8B,
  11863. rvocalicvowelsignbengali: 0x09C3,
  11864. rvocalicvowelsigndeva: 0x0943,
  11865. rvocalicvowelsigngujarati: 0x0AC3,
  11866. s: 0x0073,
  11867. sabengali: 0x09B8,
  11868. sacute: 0x015B,
  11869. sacutedotaccent: 0x1E65,
  11870. sadarabic: 0x0635,
  11871. sadeva: 0x0938,
  11872. sadfinalarabic: 0xFEBA,
  11873. sadinitialarabic: 0xFEBB,
  11874. sadmedialarabic: 0xFEBC,
  11875. sagujarati: 0x0AB8,
  11876. sagurmukhi: 0x0A38,
  11877. sahiragana: 0x3055,
  11878. sakatakana: 0x30B5,
  11879. sakatakanahalfwidth: 0xFF7B,
  11880. sallallahoualayhewasallamarabic: 0xFDFA,
  11881. samekh: 0x05E1,
  11882. samekhdagesh: 0xFB41,
  11883. samekhdageshhebrew: 0xFB41,
  11884. samekhhebrew: 0x05E1,
  11885. saraaathai: 0x0E32,
  11886. saraaethai: 0x0E41,
  11887. saraaimaimalaithai: 0x0E44,
  11888. saraaimaimuanthai: 0x0E43,
  11889. saraamthai: 0x0E33,
  11890. saraathai: 0x0E30,
  11891. saraethai: 0x0E40,
  11892. saraiileftthai: 0xF886,
  11893. saraiithai: 0x0E35,
  11894. saraileftthai: 0xF885,
  11895. saraithai: 0x0E34,
  11896. saraothai: 0x0E42,
  11897. saraueeleftthai: 0xF888,
  11898. saraueethai: 0x0E37,
  11899. saraueleftthai: 0xF887,
  11900. sarauethai: 0x0E36,
  11901. sarauthai: 0x0E38,
  11902. sarauuthai: 0x0E39,
  11903. sbopomofo: 0x3119,
  11904. scaron: 0x0161,
  11905. scarondotaccent: 0x1E67,
  11906. scedilla: 0x015F,
  11907. schwa: 0x0259,
  11908. schwacyrillic: 0x04D9,
  11909. schwadieresiscyrillic: 0x04DB,
  11910. schwahook: 0x025A,
  11911. scircle: 0x24E2,
  11912. scircumflex: 0x015D,
  11913. scommaaccent: 0x0219,
  11914. sdotaccent: 0x1E61,
  11915. sdotbelow: 0x1E63,
  11916. sdotbelowdotaccent: 0x1E69,
  11917. seagullbelowcmb: 0x033C,
  11918. second: 0x2033,
  11919. secondtonechinese: 0x02CA,
  11920. section: 0x00A7,
  11921. seenarabic: 0x0633,
  11922. seenfinalarabic: 0xFEB2,
  11923. seeninitialarabic: 0xFEB3,
  11924. seenmedialarabic: 0xFEB4,
  11925. segol: 0x05B6,
  11926. segol13: 0x05B6,
  11927. segol1f: 0x05B6,
  11928. segol2c: 0x05B6,
  11929. segolhebrew: 0x05B6,
  11930. segolnarrowhebrew: 0x05B6,
  11931. segolquarterhebrew: 0x05B6,
  11932. segoltahebrew: 0x0592,
  11933. segolwidehebrew: 0x05B6,
  11934. seharmenian: 0x057D,
  11935. sehiragana: 0x305B,
  11936. sekatakana: 0x30BB,
  11937. sekatakanahalfwidth: 0xFF7E,
  11938. semicolon: 0x003B,
  11939. semicolonarabic: 0x061B,
  11940. semicolonmonospace: 0xFF1B,
  11941. semicolonsmall: 0xFE54,
  11942. semivoicedmarkkana: 0x309C,
  11943. semivoicedmarkkanahalfwidth: 0xFF9F,
  11944. sentisquare: 0x3322,
  11945. sentosquare: 0x3323,
  11946. seven: 0x0037,
  11947. sevenarabic: 0x0667,
  11948. sevenbengali: 0x09ED,
  11949. sevencircle: 0x2466,
  11950. sevencircleinversesansserif: 0x2790,
  11951. sevendeva: 0x096D,
  11952. seveneighths: 0x215E,
  11953. sevengujarati: 0x0AED,
  11954. sevengurmukhi: 0x0A6D,
  11955. sevenhackarabic: 0x0667,
  11956. sevenhangzhou: 0x3027,
  11957. sevenideographicparen: 0x3226,
  11958. seveninferior: 0x2087,
  11959. sevenmonospace: 0xFF17,
  11960. sevenoldstyle: 0xF737,
  11961. sevenparen: 0x247A,
  11962. sevenperiod: 0x248E,
  11963. sevenpersian: 0x06F7,
  11964. sevenroman: 0x2176,
  11965. sevensuperior: 0x2077,
  11966. seventeencircle: 0x2470,
  11967. seventeenparen: 0x2484,
  11968. seventeenperiod: 0x2498,
  11969. seventhai: 0x0E57,
  11970. sfthyphen: 0x00AD,
  11971. shaarmenian: 0x0577,
  11972. shabengali: 0x09B6,
  11973. shacyrillic: 0x0448,
  11974. shaddaarabic: 0x0651,
  11975. shaddadammaarabic: 0xFC61,
  11976. shaddadammatanarabic: 0xFC5E,
  11977. shaddafathaarabic: 0xFC60,
  11978. shaddakasraarabic: 0xFC62,
  11979. shaddakasratanarabic: 0xFC5F,
  11980. shade: 0x2592,
  11981. shadedark: 0x2593,
  11982. shadelight: 0x2591,
  11983. shademedium: 0x2592,
  11984. shadeva: 0x0936,
  11985. shagujarati: 0x0AB6,
  11986. shagurmukhi: 0x0A36,
  11987. shalshelethebrew: 0x0593,
  11988. shbopomofo: 0x3115,
  11989. shchacyrillic: 0x0449,
  11990. sheenarabic: 0x0634,
  11991. sheenfinalarabic: 0xFEB6,
  11992. sheeninitialarabic: 0xFEB7,
  11993. sheenmedialarabic: 0xFEB8,
  11994. sheicoptic: 0x03E3,
  11995. sheqel: 0x20AA,
  11996. sheqelhebrew: 0x20AA,
  11997. sheva: 0x05B0,
  11998. sheva115: 0x05B0,
  11999. sheva15: 0x05B0,
  12000. sheva22: 0x05B0,
  12001. sheva2e: 0x05B0,
  12002. shevahebrew: 0x05B0,
  12003. shevanarrowhebrew: 0x05B0,
  12004. shevaquarterhebrew: 0x05B0,
  12005. shevawidehebrew: 0x05B0,
  12006. shhacyrillic: 0x04BB,
  12007. shimacoptic: 0x03ED,
  12008. shin: 0x05E9,
  12009. shindagesh: 0xFB49,
  12010. shindageshhebrew: 0xFB49,
  12011. shindageshshindot: 0xFB2C,
  12012. shindageshshindothebrew: 0xFB2C,
  12013. shindageshsindot: 0xFB2D,
  12014. shindageshsindothebrew: 0xFB2D,
  12015. shindothebrew: 0x05C1,
  12016. shinhebrew: 0x05E9,
  12017. shinshindot: 0xFB2A,
  12018. shinshindothebrew: 0xFB2A,
  12019. shinsindot: 0xFB2B,
  12020. shinsindothebrew: 0xFB2B,
  12021. shook: 0x0282,
  12022. sigma: 0x03C3,
  12023. sigma1: 0x03C2,
  12024. sigmafinal: 0x03C2,
  12025. sigmalunatesymbolgreek: 0x03F2,
  12026. sihiragana: 0x3057,
  12027. sikatakana: 0x30B7,
  12028. sikatakanahalfwidth: 0xFF7C,
  12029. siluqhebrew: 0x05BD,
  12030. siluqlefthebrew: 0x05BD,
  12031. similar: 0x223C,
  12032. sindothebrew: 0x05C2,
  12033. siosacirclekorean: 0x3274,
  12034. siosaparenkorean: 0x3214,
  12035. sioscieuckorean: 0x317E,
  12036. sioscirclekorean: 0x3266,
  12037. sioskiyeokkorean: 0x317A,
  12038. sioskorean: 0x3145,
  12039. siosnieunkorean: 0x317B,
  12040. siosparenkorean: 0x3206,
  12041. siospieupkorean: 0x317D,
  12042. siostikeutkorean: 0x317C,
  12043. six: 0x0036,
  12044. sixarabic: 0x0666,
  12045. sixbengali: 0x09EC,
  12046. sixcircle: 0x2465,
  12047. sixcircleinversesansserif: 0x278F,
  12048. sixdeva: 0x096C,
  12049. sixgujarati: 0x0AEC,
  12050. sixgurmukhi: 0x0A6C,
  12051. sixhackarabic: 0x0666,
  12052. sixhangzhou: 0x3026,
  12053. sixideographicparen: 0x3225,
  12054. sixinferior: 0x2086,
  12055. sixmonospace: 0xFF16,
  12056. sixoldstyle: 0xF736,
  12057. sixparen: 0x2479,
  12058. sixperiod: 0x248D,
  12059. sixpersian: 0x06F6,
  12060. sixroman: 0x2175,
  12061. sixsuperior: 0x2076,
  12062. sixteencircle: 0x246F,
  12063. sixteencurrencydenominatorbengali: 0x09F9,
  12064. sixteenparen: 0x2483,
  12065. sixteenperiod: 0x2497,
  12066. sixthai: 0x0E56,
  12067. slash: 0x002F,
  12068. slashmonospace: 0xFF0F,
  12069. slong: 0x017F,
  12070. slongdotaccent: 0x1E9B,
  12071. smileface: 0x263A,
  12072. smonospace: 0xFF53,
  12073. sofpasuqhebrew: 0x05C3,
  12074. softhyphen: 0x00AD,
  12075. softsigncyrillic: 0x044C,
  12076. sohiragana: 0x305D,
  12077. sokatakana: 0x30BD,
  12078. sokatakanahalfwidth: 0xFF7F,
  12079. soliduslongoverlaycmb: 0x0338,
  12080. solidusshortoverlaycmb: 0x0337,
  12081. sorusithai: 0x0E29,
  12082. sosalathai: 0x0E28,
  12083. sosothai: 0x0E0B,
  12084. sosuathai: 0x0E2A,
  12085. space: 0x0020,
  12086. spacehackarabic: 0x0020,
  12087. spade: 0x2660,
  12088. spadesuitblack: 0x2660,
  12089. spadesuitwhite: 0x2664,
  12090. sparen: 0x24AE,
  12091. squarebelowcmb: 0x033B,
  12092. squarecc: 0x33C4,
  12093. squarecm: 0x339D,
  12094. squarediagonalcrosshatchfill: 0x25A9,
  12095. squarehorizontalfill: 0x25A4,
  12096. squarekg: 0x338F,
  12097. squarekm: 0x339E,
  12098. squarekmcapital: 0x33CE,
  12099. squareln: 0x33D1,
  12100. squarelog: 0x33D2,
  12101. squaremg: 0x338E,
  12102. squaremil: 0x33D5,
  12103. squaremm: 0x339C,
  12104. squaremsquared: 0x33A1,
  12105. squareorthogonalcrosshatchfill: 0x25A6,
  12106. squareupperlefttolowerrightfill: 0x25A7,
  12107. squareupperrighttolowerleftfill: 0x25A8,
  12108. squareverticalfill: 0x25A5,
  12109. squarewhitewithsmallblack: 0x25A3,
  12110. srsquare: 0x33DB,
  12111. ssabengali: 0x09B7,
  12112. ssadeva: 0x0937,
  12113. ssagujarati: 0x0AB7,
  12114. ssangcieuckorean: 0x3149,
  12115. ssanghieuhkorean: 0x3185,
  12116. ssangieungkorean: 0x3180,
  12117. ssangkiyeokkorean: 0x3132,
  12118. ssangnieunkorean: 0x3165,
  12119. ssangpieupkorean: 0x3143,
  12120. ssangsioskorean: 0x3146,
  12121. ssangtikeutkorean: 0x3138,
  12122. ssuperior: 0xF6F2,
  12123. sterling: 0x00A3,
  12124. sterlingmonospace: 0xFFE1,
  12125. strokelongoverlaycmb: 0x0336,
  12126. strokeshortoverlaycmb: 0x0335,
  12127. subset: 0x2282,
  12128. subsetnotequal: 0x228A,
  12129. subsetorequal: 0x2286,
  12130. succeeds: 0x227B,
  12131. suchthat: 0x220B,
  12132. suhiragana: 0x3059,
  12133. sukatakana: 0x30B9,
  12134. sukatakanahalfwidth: 0xFF7D,
  12135. sukunarabic: 0x0652,
  12136. summation: 0x2211,
  12137. sun: 0x263C,
  12138. superset: 0x2283,
  12139. supersetnotequal: 0x228B,
  12140. supersetorequal: 0x2287,
  12141. svsquare: 0x33DC,
  12142. syouwaerasquare: 0x337C,
  12143. t: 0x0074,
  12144. tabengali: 0x09A4,
  12145. tackdown: 0x22A4,
  12146. tackleft: 0x22A3,
  12147. tadeva: 0x0924,
  12148. tagujarati: 0x0AA4,
  12149. tagurmukhi: 0x0A24,
  12150. taharabic: 0x0637,
  12151. tahfinalarabic: 0xFEC2,
  12152. tahinitialarabic: 0xFEC3,
  12153. tahiragana: 0x305F,
  12154. tahmedialarabic: 0xFEC4,
  12155. taisyouerasquare: 0x337D,
  12156. takatakana: 0x30BF,
  12157. takatakanahalfwidth: 0xFF80,
  12158. tatweelarabic: 0x0640,
  12159. tau: 0x03C4,
  12160. tav: 0x05EA,
  12161. tavdages: 0xFB4A,
  12162. tavdagesh: 0xFB4A,
  12163. tavdageshhebrew: 0xFB4A,
  12164. tavhebrew: 0x05EA,
  12165. tbar: 0x0167,
  12166. tbopomofo: 0x310A,
  12167. tcaron: 0x0165,
  12168. tccurl: 0x02A8,
  12169. tcedilla: 0x0163,
  12170. tcheharabic: 0x0686,
  12171. tchehfinalarabic: 0xFB7B,
  12172. tchehinitialarabic: 0xFB7C,
  12173. tchehmedialarabic: 0xFB7D,
  12174. tcircle: 0x24E3,
  12175. tcircumflexbelow: 0x1E71,
  12176. tcommaaccent: 0x0163,
  12177. tdieresis: 0x1E97,
  12178. tdotaccent: 0x1E6B,
  12179. tdotbelow: 0x1E6D,
  12180. tecyrillic: 0x0442,
  12181. tedescendercyrillic: 0x04AD,
  12182. teharabic: 0x062A,
  12183. tehfinalarabic: 0xFE96,
  12184. tehhahinitialarabic: 0xFCA2,
  12185. tehhahisolatedarabic: 0xFC0C,
  12186. tehinitialarabic: 0xFE97,
  12187. tehiragana: 0x3066,
  12188. tehjeeminitialarabic: 0xFCA1,
  12189. tehjeemisolatedarabic: 0xFC0B,
  12190. tehmarbutaarabic: 0x0629,
  12191. tehmarbutafinalarabic: 0xFE94,
  12192. tehmedialarabic: 0xFE98,
  12193. tehmeeminitialarabic: 0xFCA4,
  12194. tehmeemisolatedarabic: 0xFC0E,
  12195. tehnoonfinalarabic: 0xFC73,
  12196. tekatakana: 0x30C6,
  12197. tekatakanahalfwidth: 0xFF83,
  12198. telephone: 0x2121,
  12199. telephoneblack: 0x260E,
  12200. telishagedolahebrew: 0x05A0,
  12201. telishaqetanahebrew: 0x05A9,
  12202. tencircle: 0x2469,
  12203. tenideographicparen: 0x3229,
  12204. tenparen: 0x247D,
  12205. tenperiod: 0x2491,
  12206. tenroman: 0x2179,
  12207. tesh: 0x02A7,
  12208. tet: 0x05D8,
  12209. tetdagesh: 0xFB38,
  12210. tetdageshhebrew: 0xFB38,
  12211. tethebrew: 0x05D8,
  12212. tetsecyrillic: 0x04B5,
  12213. tevirhebrew: 0x059B,
  12214. tevirlefthebrew: 0x059B,
  12215. thabengali: 0x09A5,
  12216. thadeva: 0x0925,
  12217. thagujarati: 0x0AA5,
  12218. thagurmukhi: 0x0A25,
  12219. thalarabic: 0x0630,
  12220. thalfinalarabic: 0xFEAC,
  12221. thanthakhatlowleftthai: 0xF898,
  12222. thanthakhatlowrightthai: 0xF897,
  12223. thanthakhatthai: 0x0E4C,
  12224. thanthakhatupperleftthai: 0xF896,
  12225. theharabic: 0x062B,
  12226. thehfinalarabic: 0xFE9A,
  12227. thehinitialarabic: 0xFE9B,
  12228. thehmedialarabic: 0xFE9C,
  12229. thereexists: 0x2203,
  12230. therefore: 0x2234,
  12231. theta: 0x03B8,
  12232. theta1: 0x03D1,
  12233. thetasymbolgreek: 0x03D1,
  12234. thieuthacirclekorean: 0x3279,
  12235. thieuthaparenkorean: 0x3219,
  12236. thieuthcirclekorean: 0x326B,
  12237. thieuthkorean: 0x314C,
  12238. thieuthparenkorean: 0x320B,
  12239. thirteencircle: 0x246C,
  12240. thirteenparen: 0x2480,
  12241. thirteenperiod: 0x2494,
  12242. thonangmonthothai: 0x0E11,
  12243. thook: 0x01AD,
  12244. thophuthaothai: 0x0E12,
  12245. thorn: 0x00FE,
  12246. thothahanthai: 0x0E17,
  12247. thothanthai: 0x0E10,
  12248. thothongthai: 0x0E18,
  12249. thothungthai: 0x0E16,
  12250. thousandcyrillic: 0x0482,
  12251. thousandsseparatorarabic: 0x066C,
  12252. thousandsseparatorpersian: 0x066C,
  12253. three: 0x0033,
  12254. threearabic: 0x0663,
  12255. threebengali: 0x09E9,
  12256. threecircle: 0x2462,
  12257. threecircleinversesansserif: 0x278C,
  12258. threedeva: 0x0969,
  12259. threeeighths: 0x215C,
  12260. threegujarati: 0x0AE9,
  12261. threegurmukhi: 0x0A69,
  12262. threehackarabic: 0x0663,
  12263. threehangzhou: 0x3023,
  12264. threeideographicparen: 0x3222,
  12265. threeinferior: 0x2083,
  12266. threemonospace: 0xFF13,
  12267. threenumeratorbengali: 0x09F6,
  12268. threeoldstyle: 0xF733,
  12269. threeparen: 0x2476,
  12270. threeperiod: 0x248A,
  12271. threepersian: 0x06F3,
  12272. threequarters: 0x00BE,
  12273. threequartersemdash: 0xF6DE,
  12274. threeroman: 0x2172,
  12275. threesuperior: 0x00B3,
  12276. threethai: 0x0E53,
  12277. thzsquare: 0x3394,
  12278. tihiragana: 0x3061,
  12279. tikatakana: 0x30C1,
  12280. tikatakanahalfwidth: 0xFF81,
  12281. tikeutacirclekorean: 0x3270,
  12282. tikeutaparenkorean: 0x3210,
  12283. tikeutcirclekorean: 0x3262,
  12284. tikeutkorean: 0x3137,
  12285. tikeutparenkorean: 0x3202,
  12286. tilde: 0x02DC,
  12287. tildebelowcmb: 0x0330,
  12288. tildecmb: 0x0303,
  12289. tildecomb: 0x0303,
  12290. tildedoublecmb: 0x0360,
  12291. tildeoperator: 0x223C,
  12292. tildeoverlaycmb: 0x0334,
  12293. tildeverticalcmb: 0x033E,
  12294. timescircle: 0x2297,
  12295. tipehahebrew: 0x0596,
  12296. tipehalefthebrew: 0x0596,
  12297. tippigurmukhi: 0x0A70,
  12298. titlocyrilliccmb: 0x0483,
  12299. tiwnarmenian: 0x057F,
  12300. tlinebelow: 0x1E6F,
  12301. tmonospace: 0xFF54,
  12302. toarmenian: 0x0569,
  12303. tohiragana: 0x3068,
  12304. tokatakana: 0x30C8,
  12305. tokatakanahalfwidth: 0xFF84,
  12306. tonebarextrahighmod: 0x02E5,
  12307. tonebarextralowmod: 0x02E9,
  12308. tonebarhighmod: 0x02E6,
  12309. tonebarlowmod: 0x02E8,
  12310. tonebarmidmod: 0x02E7,
  12311. tonefive: 0x01BD,
  12312. tonesix: 0x0185,
  12313. tonetwo: 0x01A8,
  12314. tonos: 0x0384,
  12315. tonsquare: 0x3327,
  12316. topatakthai: 0x0E0F,
  12317. tortoiseshellbracketleft: 0x3014,
  12318. tortoiseshellbracketleftsmall: 0xFE5D,
  12319. tortoiseshellbracketleftvertical: 0xFE39,
  12320. tortoiseshellbracketright: 0x3015,
  12321. tortoiseshellbracketrightsmall: 0xFE5E,
  12322. tortoiseshellbracketrightvertical: 0xFE3A,
  12323. totaothai: 0x0E15,
  12324. tpalatalhook: 0x01AB,
  12325. tparen: 0x24AF,
  12326. trademark: 0x2122,
  12327. trademarksans: 0xF8EA,
  12328. trademarkserif: 0xF6DB,
  12329. tretroflexhook: 0x0288,
  12330. triagdn: 0x25BC,
  12331. triaglf: 0x25C4,
  12332. triagrt: 0x25BA,
  12333. triagup: 0x25B2,
  12334. ts: 0x02A6,
  12335. tsadi: 0x05E6,
  12336. tsadidagesh: 0xFB46,
  12337. tsadidageshhebrew: 0xFB46,
  12338. tsadihebrew: 0x05E6,
  12339. tsecyrillic: 0x0446,
  12340. tsere: 0x05B5,
  12341. tsere12: 0x05B5,
  12342. tsere1e: 0x05B5,
  12343. tsere2b: 0x05B5,
  12344. tserehebrew: 0x05B5,
  12345. tserenarrowhebrew: 0x05B5,
  12346. tserequarterhebrew: 0x05B5,
  12347. tserewidehebrew: 0x05B5,
  12348. tshecyrillic: 0x045B,
  12349. tsuperior: 0xF6F3,
  12350. ttabengali: 0x099F,
  12351. ttadeva: 0x091F,
  12352. ttagujarati: 0x0A9F,
  12353. ttagurmukhi: 0x0A1F,
  12354. tteharabic: 0x0679,
  12355. ttehfinalarabic: 0xFB67,
  12356. ttehinitialarabic: 0xFB68,
  12357. ttehmedialarabic: 0xFB69,
  12358. tthabengali: 0x09A0,
  12359. tthadeva: 0x0920,
  12360. tthagujarati: 0x0AA0,
  12361. tthagurmukhi: 0x0A20,
  12362. tturned: 0x0287,
  12363. tuhiragana: 0x3064,
  12364. tukatakana: 0x30C4,
  12365. tukatakanahalfwidth: 0xFF82,
  12366. tusmallhiragana: 0x3063,
  12367. tusmallkatakana: 0x30C3,
  12368. tusmallkatakanahalfwidth: 0xFF6F,
  12369. twelvecircle: 0x246B,
  12370. twelveparen: 0x247F,
  12371. twelveperiod: 0x2493,
  12372. twelveroman: 0x217B,
  12373. twentycircle: 0x2473,
  12374. twentyhangzhou: 0x5344,
  12375. twentyparen: 0x2487,
  12376. twentyperiod: 0x249B,
  12377. two: 0x0032,
  12378. twoarabic: 0x0662,
  12379. twobengali: 0x09E8,
  12380. twocircle: 0x2461,
  12381. twocircleinversesansserif: 0x278B,
  12382. twodeva: 0x0968,
  12383. twodotenleader: 0x2025,
  12384. twodotleader: 0x2025,
  12385. twodotleadervertical: 0xFE30,
  12386. twogujarati: 0x0AE8,
  12387. twogurmukhi: 0x0A68,
  12388. twohackarabic: 0x0662,
  12389. twohangzhou: 0x3022,
  12390. twoideographicparen: 0x3221,
  12391. twoinferior: 0x2082,
  12392. twomonospace: 0xFF12,
  12393. twonumeratorbengali: 0x09F5,
  12394. twooldstyle: 0xF732,
  12395. twoparen: 0x2475,
  12396. twoperiod: 0x2489,
  12397. twopersian: 0x06F2,
  12398. tworoman: 0x2171,
  12399. twostroke: 0x01BB,
  12400. twosuperior: 0x00B2,
  12401. twothai: 0x0E52,
  12402. twothirds: 0x2154,
  12403. u: 0x0075,
  12404. uacute: 0x00FA,
  12405. ubar: 0x0289,
  12406. ubengali: 0x0989,
  12407. ubopomofo: 0x3128,
  12408. ubreve: 0x016D,
  12409. ucaron: 0x01D4,
  12410. ucircle: 0x24E4,
  12411. ucircumflex: 0x00FB,
  12412. ucircumflexbelow: 0x1E77,
  12413. ucyrillic: 0x0443,
  12414. udattadeva: 0x0951,
  12415. udblacute: 0x0171,
  12416. udblgrave: 0x0215,
  12417. udeva: 0x0909,
  12418. udieresis: 0x00FC,
  12419. udieresisacute: 0x01D8,
  12420. udieresisbelow: 0x1E73,
  12421. udieresiscaron: 0x01DA,
  12422. udieresiscyrillic: 0x04F1,
  12423. udieresisgrave: 0x01DC,
  12424. udieresismacron: 0x01D6,
  12425. udotbelow: 0x1EE5,
  12426. ugrave: 0x00F9,
  12427. ugujarati: 0x0A89,
  12428. ugurmukhi: 0x0A09,
  12429. uhiragana: 0x3046,
  12430. uhookabove: 0x1EE7,
  12431. uhorn: 0x01B0,
  12432. uhornacute: 0x1EE9,
  12433. uhorndotbelow: 0x1EF1,
  12434. uhorngrave: 0x1EEB,
  12435. uhornhookabove: 0x1EED,
  12436. uhorntilde: 0x1EEF,
  12437. uhungarumlaut: 0x0171,
  12438. uhungarumlautcyrillic: 0x04F3,
  12439. uinvertedbreve: 0x0217,
  12440. ukatakana: 0x30A6,
  12441. ukatakanahalfwidth: 0xFF73,
  12442. ukcyrillic: 0x0479,
  12443. ukorean: 0x315C,
  12444. umacron: 0x016B,
  12445. umacroncyrillic: 0x04EF,
  12446. umacrondieresis: 0x1E7B,
  12447. umatragurmukhi: 0x0A41,
  12448. umonospace: 0xFF55,
  12449. underscore: 0x005F,
  12450. underscoredbl: 0x2017,
  12451. underscoremonospace: 0xFF3F,
  12452. underscorevertical: 0xFE33,
  12453. underscorewavy: 0xFE4F,
  12454. union: 0x222A,
  12455. universal: 0x2200,
  12456. uogonek: 0x0173,
  12457. uparen: 0x24B0,
  12458. upblock: 0x2580,
  12459. upperdothebrew: 0x05C4,
  12460. upsilon: 0x03C5,
  12461. upsilondieresis: 0x03CB,
  12462. upsilondieresistonos: 0x03B0,
  12463. upsilonlatin: 0x028A,
  12464. upsilontonos: 0x03CD,
  12465. uptackbelowcmb: 0x031D,
  12466. uptackmod: 0x02D4,
  12467. uragurmukhi: 0x0A73,
  12468. uring: 0x016F,
  12469. ushortcyrillic: 0x045E,
  12470. usmallhiragana: 0x3045,
  12471. usmallkatakana: 0x30A5,
  12472. usmallkatakanahalfwidth: 0xFF69,
  12473. ustraightcyrillic: 0x04AF,
  12474. ustraightstrokecyrillic: 0x04B1,
  12475. utilde: 0x0169,
  12476. utildeacute: 0x1E79,
  12477. utildebelow: 0x1E75,
  12478. uubengali: 0x098A,
  12479. uudeva: 0x090A,
  12480. uugujarati: 0x0A8A,
  12481. uugurmukhi: 0x0A0A,
  12482. uumatragurmukhi: 0x0A42,
  12483. uuvowelsignbengali: 0x09C2,
  12484. uuvowelsigndeva: 0x0942,
  12485. uuvowelsigngujarati: 0x0AC2,
  12486. uvowelsignbengali: 0x09C1,
  12487. uvowelsigndeva: 0x0941,
  12488. uvowelsigngujarati: 0x0AC1,
  12489. v: 0x0076,
  12490. vadeva: 0x0935,
  12491. vagujarati: 0x0AB5,
  12492. vagurmukhi: 0x0A35,
  12493. vakatakana: 0x30F7,
  12494. vav: 0x05D5,
  12495. vavdagesh: 0xFB35,
  12496. vavdagesh65: 0xFB35,
  12497. vavdageshhebrew: 0xFB35,
  12498. vavhebrew: 0x05D5,
  12499. vavholam: 0xFB4B,
  12500. vavholamhebrew: 0xFB4B,
  12501. vavvavhebrew: 0x05F0,
  12502. vavyodhebrew: 0x05F1,
  12503. vcircle: 0x24E5,
  12504. vdotbelow: 0x1E7F,
  12505. vecyrillic: 0x0432,
  12506. veharabic: 0x06A4,
  12507. vehfinalarabic: 0xFB6B,
  12508. vehinitialarabic: 0xFB6C,
  12509. vehmedialarabic: 0xFB6D,
  12510. vekatakana: 0x30F9,
  12511. venus: 0x2640,
  12512. verticalbar: 0x007C,
  12513. verticallineabovecmb: 0x030D,
  12514. verticallinebelowcmb: 0x0329,
  12515. verticallinelowmod: 0x02CC,
  12516. verticallinemod: 0x02C8,
  12517. vewarmenian: 0x057E,
  12518. vhook: 0x028B,
  12519. vikatakana: 0x30F8,
  12520. viramabengali: 0x09CD,
  12521. viramadeva: 0x094D,
  12522. viramagujarati: 0x0ACD,
  12523. visargabengali: 0x0983,
  12524. visargadeva: 0x0903,
  12525. visargagujarati: 0x0A83,
  12526. vmonospace: 0xFF56,
  12527. voarmenian: 0x0578,
  12528. voicediterationhiragana: 0x309E,
  12529. voicediterationkatakana: 0x30FE,
  12530. voicedmarkkana: 0x309B,
  12531. voicedmarkkanahalfwidth: 0xFF9E,
  12532. vokatakana: 0x30FA,
  12533. vparen: 0x24B1,
  12534. vtilde: 0x1E7D,
  12535. vturned: 0x028C,
  12536. vuhiragana: 0x3094,
  12537. vukatakana: 0x30F4,
  12538. w: 0x0077,
  12539. wacute: 0x1E83,
  12540. waekorean: 0x3159,
  12541. wahiragana: 0x308F,
  12542. wakatakana: 0x30EF,
  12543. wakatakanahalfwidth: 0xFF9C,
  12544. wakorean: 0x3158,
  12545. wasmallhiragana: 0x308E,
  12546. wasmallkatakana: 0x30EE,
  12547. wattosquare: 0x3357,
  12548. wavedash: 0x301C,
  12549. wavyunderscorevertical: 0xFE34,
  12550. wawarabic: 0x0648,
  12551. wawfinalarabic: 0xFEEE,
  12552. wawhamzaabovearabic: 0x0624,
  12553. wawhamzaabovefinalarabic: 0xFE86,
  12554. wbsquare: 0x33DD,
  12555. wcircle: 0x24E6,
  12556. wcircumflex: 0x0175,
  12557. wdieresis: 0x1E85,
  12558. wdotaccent: 0x1E87,
  12559. wdotbelow: 0x1E89,
  12560. wehiragana: 0x3091,
  12561. weierstrass: 0x2118,
  12562. wekatakana: 0x30F1,
  12563. wekorean: 0x315E,
  12564. weokorean: 0x315D,
  12565. wgrave: 0x1E81,
  12566. whitebullet: 0x25E6,
  12567. whitecircle: 0x25CB,
  12568. whitecircleinverse: 0x25D9,
  12569. whitecornerbracketleft: 0x300E,
  12570. whitecornerbracketleftvertical: 0xFE43,
  12571. whitecornerbracketright: 0x300F,
  12572. whitecornerbracketrightvertical: 0xFE44,
  12573. whitediamond: 0x25C7,
  12574. whitediamondcontainingblacksmalldiamond: 0x25C8,
  12575. whitedownpointingsmalltriangle: 0x25BF,
  12576. whitedownpointingtriangle: 0x25BD,
  12577. whiteleftpointingsmalltriangle: 0x25C3,
  12578. whiteleftpointingtriangle: 0x25C1,
  12579. whitelenticularbracketleft: 0x3016,
  12580. whitelenticularbracketright: 0x3017,
  12581. whiterightpointingsmalltriangle: 0x25B9,
  12582. whiterightpointingtriangle: 0x25B7,
  12583. whitesmallsquare: 0x25AB,
  12584. whitesmilingface: 0x263A,
  12585. whitesquare: 0x25A1,
  12586. whitestar: 0x2606,
  12587. whitetelephone: 0x260F,
  12588. whitetortoiseshellbracketleft: 0x3018,
  12589. whitetortoiseshellbracketright: 0x3019,
  12590. whiteuppointingsmalltriangle: 0x25B5,
  12591. whiteuppointingtriangle: 0x25B3,
  12592. wihiragana: 0x3090,
  12593. wikatakana: 0x30F0,
  12594. wikorean: 0x315F,
  12595. wmonospace: 0xFF57,
  12596. wohiragana: 0x3092,
  12597. wokatakana: 0x30F2,
  12598. wokatakanahalfwidth: 0xFF66,
  12599. won: 0x20A9,
  12600. wonmonospace: 0xFFE6,
  12601. wowaenthai: 0x0E27,
  12602. wparen: 0x24B2,
  12603. wring: 0x1E98,
  12604. wsuperior: 0x02B7,
  12605. wturned: 0x028D,
  12606. wynn: 0x01BF,
  12607. x: 0x0078,
  12608. xabovecmb: 0x033D,
  12609. xbopomofo: 0x3112,
  12610. xcircle: 0x24E7,
  12611. xdieresis: 0x1E8D,
  12612. xdotaccent: 0x1E8B,
  12613. xeharmenian: 0x056D,
  12614. xi: 0x03BE,
  12615. xmonospace: 0xFF58,
  12616. xparen: 0x24B3,
  12617. xsuperior: 0x02E3,
  12618. y: 0x0079,
  12619. yaadosquare: 0x334E,
  12620. yabengali: 0x09AF,
  12621. yacute: 0x00FD,
  12622. yadeva: 0x092F,
  12623. yaekorean: 0x3152,
  12624. yagujarati: 0x0AAF,
  12625. yagurmukhi: 0x0A2F,
  12626. yahiragana: 0x3084,
  12627. yakatakana: 0x30E4,
  12628. yakatakanahalfwidth: 0xFF94,
  12629. yakorean: 0x3151,
  12630. yamakkanthai: 0x0E4E,
  12631. yasmallhiragana: 0x3083,
  12632. yasmallkatakana: 0x30E3,
  12633. yasmallkatakanahalfwidth: 0xFF6C,
  12634. yatcyrillic: 0x0463,
  12635. ycircle: 0x24E8,
  12636. ycircumflex: 0x0177,
  12637. ydieresis: 0x00FF,
  12638. ydotaccent: 0x1E8F,
  12639. ydotbelow: 0x1EF5,
  12640. yeharabic: 0x064A,
  12641. yehbarreearabic: 0x06D2,
  12642. yehbarreefinalarabic: 0xFBAF,
  12643. yehfinalarabic: 0xFEF2,
  12644. yehhamzaabovearabic: 0x0626,
  12645. yehhamzaabovefinalarabic: 0xFE8A,
  12646. yehhamzaaboveinitialarabic: 0xFE8B,
  12647. yehhamzaabovemedialarabic: 0xFE8C,
  12648. yehinitialarabic: 0xFEF3,
  12649. yehmedialarabic: 0xFEF4,
  12650. yehmeeminitialarabic: 0xFCDD,
  12651. yehmeemisolatedarabic: 0xFC58,
  12652. yehnoonfinalarabic: 0xFC94,
  12653. yehthreedotsbelowarabic: 0x06D1,
  12654. yekorean: 0x3156,
  12655. yen: 0x00A5,
  12656. yenmonospace: 0xFFE5,
  12657. yeokorean: 0x3155,
  12658. yeorinhieuhkorean: 0x3186,
  12659. yerahbenyomohebrew: 0x05AA,
  12660. yerahbenyomolefthebrew: 0x05AA,
  12661. yericyrillic: 0x044B,
  12662. yerudieresiscyrillic: 0x04F9,
  12663. yesieungkorean: 0x3181,
  12664. yesieungpansioskorean: 0x3183,
  12665. yesieungsioskorean: 0x3182,
  12666. yetivhebrew: 0x059A,
  12667. ygrave: 0x1EF3,
  12668. yhook: 0x01B4,
  12669. yhookabove: 0x1EF7,
  12670. yiarmenian: 0x0575,
  12671. yicyrillic: 0x0457,
  12672. yikorean: 0x3162,
  12673. yinyang: 0x262F,
  12674. yiwnarmenian: 0x0582,
  12675. ymonospace: 0xFF59,
  12676. yod: 0x05D9,
  12677. yoddagesh: 0xFB39,
  12678. yoddageshhebrew: 0xFB39,
  12679. yodhebrew: 0x05D9,
  12680. yodyodhebrew: 0x05F2,
  12681. yodyodpatahhebrew: 0xFB1F,
  12682. yohiragana: 0x3088,
  12683. yoikorean: 0x3189,
  12684. yokatakana: 0x30E8,
  12685. yokatakanahalfwidth: 0xFF96,
  12686. yokorean: 0x315B,
  12687. yosmallhiragana: 0x3087,
  12688. yosmallkatakana: 0x30E7,
  12689. yosmallkatakanahalfwidth: 0xFF6E,
  12690. yotgreek: 0x03F3,
  12691. yoyaekorean: 0x3188,
  12692. yoyakorean: 0x3187,
  12693. yoyakthai: 0x0E22,
  12694. yoyingthai: 0x0E0D,
  12695. yparen: 0x24B4,
  12696. ypogegrammeni: 0x037A,
  12697. ypogegrammenigreekcmb: 0x0345,
  12698. yr: 0x01A6,
  12699. yring: 0x1E99,
  12700. ysuperior: 0x02B8,
  12701. ytilde: 0x1EF9,
  12702. yturned: 0x028E,
  12703. yuhiragana: 0x3086,
  12704. yuikorean: 0x318C,
  12705. yukatakana: 0x30E6,
  12706. yukatakanahalfwidth: 0xFF95,
  12707. yukorean: 0x3160,
  12708. yusbigcyrillic: 0x046B,
  12709. yusbigiotifiedcyrillic: 0x046D,
  12710. yuslittlecyrillic: 0x0467,
  12711. yuslittleiotifiedcyrillic: 0x0469,
  12712. yusmallhiragana: 0x3085,
  12713. yusmallkatakana: 0x30E5,
  12714. yusmallkatakanahalfwidth: 0xFF6D,
  12715. yuyekorean: 0x318B,
  12716. yuyeokorean: 0x318A,
  12717. yyabengali: 0x09DF,
  12718. yyadeva: 0x095F,
  12719. z: 0x007A,
  12720. zaarmenian: 0x0566,
  12721. zacute: 0x017A,
  12722. zadeva: 0x095B,
  12723. zagurmukhi: 0x0A5B,
  12724. zaharabic: 0x0638,
  12725. zahfinalarabic: 0xFEC6,
  12726. zahinitialarabic: 0xFEC7,
  12727. zahiragana: 0x3056,
  12728. zahmedialarabic: 0xFEC8,
  12729. zainarabic: 0x0632,
  12730. zainfinalarabic: 0xFEB0,
  12731. zakatakana: 0x30B6,
  12732. zaqefgadolhebrew: 0x0595,
  12733. zaqefqatanhebrew: 0x0594,
  12734. zarqahebrew: 0x0598,
  12735. zayin: 0x05D6,
  12736. zayindagesh: 0xFB36,
  12737. zayindageshhebrew: 0xFB36,
  12738. zayinhebrew: 0x05D6,
  12739. zbopomofo: 0x3117,
  12740. zcaron: 0x017E,
  12741. zcircle: 0x24E9,
  12742. zcircumflex: 0x1E91,
  12743. zcurl: 0x0291,
  12744. zdot: 0x017C,
  12745. zdotaccent: 0x017C,
  12746. zdotbelow: 0x1E93,
  12747. zecyrillic: 0x0437,
  12748. zedescendercyrillic: 0x0499,
  12749. zedieresiscyrillic: 0x04DF,
  12750. zehiragana: 0x305C,
  12751. zekatakana: 0x30BC,
  12752. zero: 0x0030,
  12753. zeroarabic: 0x0660,
  12754. zerobengali: 0x09E6,
  12755. zerodeva: 0x0966,
  12756. zerogujarati: 0x0AE6,
  12757. zerogurmukhi: 0x0A66,
  12758. zerohackarabic: 0x0660,
  12759. zeroinferior: 0x2080,
  12760. zeromonospace: 0xFF10,
  12761. zerooldstyle: 0xF730,
  12762. zeropersian: 0x06F0,
  12763. zerosuperior: 0x2070,
  12764. zerothai: 0x0E50,
  12765. zerowidthjoiner: 0xFEFF,
  12766. zerowidthnonjoiner: 0x200C,
  12767. zerowidthspace: 0x200B,
  12768. zeta: 0x03B6,
  12769. zhbopomofo: 0x3113,
  12770. zhearmenian: 0x056A,
  12771. zhebrevecyrillic: 0x04C2,
  12772. zhecyrillic: 0x0436,
  12773. zhedescendercyrillic: 0x0497,
  12774. zhedieresiscyrillic: 0x04DD,
  12775. zihiragana: 0x3058,
  12776. zikatakana: 0x30B8,
  12777. zinorhebrew: 0x05AE,
  12778. zlinebelow: 0x1E95,
  12779. zmonospace: 0xFF5A,
  12780. zohiragana: 0x305E,
  12781. zokatakana: 0x30BE,
  12782. zparen: 0x24B5,
  12783. zretroflexhook: 0x0290,
  12784. zstroke: 0x01B6,
  12785. zuhiragana: 0x305A,
  12786. zukatakana: 0x30BA,
  12787. '.notdef': 0x0000
  12788. };
  12789. var DingbatsGlyphsUnicode = {
  12790. space: 0x0020,
  12791. a1: 0x2701,
  12792. a2: 0x2702,
  12793. a202: 0x2703,
  12794. a3: 0x2704,
  12795. a4: 0x260E,
  12796. a5: 0x2706,
  12797. a119: 0x2707,
  12798. a118: 0x2708,
  12799. a117: 0x2709,
  12800. a11: 0x261B,
  12801. a12: 0x261E,
  12802. a13: 0x270C,
  12803. a14: 0x270D,
  12804. a15: 0x270E,
  12805. a16: 0x270F,
  12806. a105: 0x2710,
  12807. a17: 0x2711,
  12808. a18: 0x2712,
  12809. a19: 0x2713,
  12810. a20: 0x2714,
  12811. a21: 0x2715,
  12812. a22: 0x2716,
  12813. a23: 0x2717,
  12814. a24: 0x2718,
  12815. a25: 0x2719,
  12816. a26: 0x271A,
  12817. a27: 0x271B,
  12818. a28: 0x271C,
  12819. a6: 0x271D,
  12820. a7: 0x271E,
  12821. a8: 0x271F,
  12822. a9: 0x2720,
  12823. a10: 0x2721,
  12824. a29: 0x2722,
  12825. a30: 0x2723,
  12826. a31: 0x2724,
  12827. a32: 0x2725,
  12828. a33: 0x2726,
  12829. a34: 0x2727,
  12830. a35: 0x2605,
  12831. a36: 0x2729,
  12832. a37: 0x272A,
  12833. a38: 0x272B,
  12834. a39: 0x272C,
  12835. a40: 0x272D,
  12836. a41: 0x272E,
  12837. a42: 0x272F,
  12838. a43: 0x2730,
  12839. a44: 0x2731,
  12840. a45: 0x2732,
  12841. a46: 0x2733,
  12842. a47: 0x2734,
  12843. a48: 0x2735,
  12844. a49: 0x2736,
  12845. a50: 0x2737,
  12846. a51: 0x2738,
  12847. a52: 0x2739,
  12848. a53: 0x273A,
  12849. a54: 0x273B,
  12850. a55: 0x273C,
  12851. a56: 0x273D,
  12852. a57: 0x273E,
  12853. a58: 0x273F,
  12854. a59: 0x2740,
  12855. a60: 0x2741,
  12856. a61: 0x2742,
  12857. a62: 0x2743,
  12858. a63: 0x2744,
  12859. a64: 0x2745,
  12860. a65: 0x2746,
  12861. a66: 0x2747,
  12862. a67: 0x2748,
  12863. a68: 0x2749,
  12864. a69: 0x274A,
  12865. a70: 0x274B,
  12866. a71: 0x25CF,
  12867. a72: 0x274D,
  12868. a73: 0x25A0,
  12869. a74: 0x274F,
  12870. a203: 0x2750,
  12871. a75: 0x2751,
  12872. a204: 0x2752,
  12873. a76: 0x25B2,
  12874. a77: 0x25BC,
  12875. a78: 0x25C6,
  12876. a79: 0x2756,
  12877. a81: 0x25D7,
  12878. a82: 0x2758,
  12879. a83: 0x2759,
  12880. a84: 0x275A,
  12881. a97: 0x275B,
  12882. a98: 0x275C,
  12883. a99: 0x275D,
  12884. a100: 0x275E,
  12885. a101: 0x2761,
  12886. a102: 0x2762,
  12887. a103: 0x2763,
  12888. a104: 0x2764,
  12889. a106: 0x2765,
  12890. a107: 0x2766,
  12891. a108: 0x2767,
  12892. a112: 0x2663,
  12893. a111: 0x2666,
  12894. a110: 0x2665,
  12895. a109: 0x2660,
  12896. a120: 0x2460,
  12897. a121: 0x2461,
  12898. a122: 0x2462,
  12899. a123: 0x2463,
  12900. a124: 0x2464,
  12901. a125: 0x2465,
  12902. a126: 0x2466,
  12903. a127: 0x2467,
  12904. a128: 0x2468,
  12905. a129: 0x2469,
  12906. a130: 0x2776,
  12907. a131: 0x2777,
  12908. a132: 0x2778,
  12909. a133: 0x2779,
  12910. a134: 0x277A,
  12911. a135: 0x277B,
  12912. a136: 0x277C,
  12913. a137: 0x277D,
  12914. a138: 0x277E,
  12915. a139: 0x277F,
  12916. a140: 0x2780,
  12917. a141: 0x2781,
  12918. a142: 0x2782,
  12919. a143: 0x2783,
  12920. a144: 0x2784,
  12921. a145: 0x2785,
  12922. a146: 0x2786,
  12923. a147: 0x2787,
  12924. a148: 0x2788,
  12925. a149: 0x2789,
  12926. a150: 0x278A,
  12927. a151: 0x278B,
  12928. a152: 0x278C,
  12929. a153: 0x278D,
  12930. a154: 0x278E,
  12931. a155: 0x278F,
  12932. a156: 0x2790,
  12933. a157: 0x2791,
  12934. a158: 0x2792,
  12935. a159: 0x2793,
  12936. a160: 0x2794,
  12937. a161: 0x2192,
  12938. a163: 0x2194,
  12939. a164: 0x2195,
  12940. a196: 0x2798,
  12941. a165: 0x2799,
  12942. a192: 0x279A,
  12943. a166: 0x279B,
  12944. a167: 0x279C,
  12945. a168: 0x279D,
  12946. a169: 0x279E,
  12947. a170: 0x279F,
  12948. a171: 0x27A0,
  12949. a172: 0x27A1,
  12950. a173: 0x27A2,
  12951. a162: 0x27A3,
  12952. a174: 0x27A4,
  12953. a175: 0x27A5,
  12954. a176: 0x27A6,
  12955. a177: 0x27A7,
  12956. a178: 0x27A8,
  12957. a179: 0x27A9,
  12958. a193: 0x27AA,
  12959. a180: 0x27AB,
  12960. a199: 0x27AC,
  12961. a181: 0x27AD,
  12962. a200: 0x27AE,
  12963. a182: 0x27AF,
  12964. a201: 0x27B1,
  12965. a183: 0x27B2,
  12966. a184: 0x27B3,
  12967. a197: 0x27B4,
  12968. a185: 0x27B5,
  12969. a194: 0x27B6,
  12970. a198: 0x27B7,
  12971. a186: 0x27B8,
  12972. a195: 0x27B9,
  12973. a187: 0x27BA,
  12974. a188: 0x27BB,
  12975. a189: 0x27BC,
  12976. a190: 0x27BD,
  12977. a191: 0x27BE,
  12978. a89: 0x2768, // 0xF8D7
  12979. a90: 0x2769, // 0xF8D8
  12980. a93: 0x276A, // 0xF8D9
  12981. a94: 0x276B, // 0xF8DA
  12982. a91: 0x276C, // 0xF8DB
  12983. a92: 0x276D, // 0xF8DC
  12984. a205: 0x276E, // 0xF8DD
  12985. a85: 0x276F, // 0xF8DE
  12986. a206: 0x2770, // 0xF8DF
  12987. a86: 0x2771, // 0xF8E0
  12988. a87: 0x2772, // 0xF8E1
  12989. a88: 0x2773, // 0xF8E2
  12990. a95: 0x2774, // 0xF8E3
  12991. a96: 0x2775, // 0xF8E4
  12992. '.notdef': 0x0000
  12993. };
  12994. exports.GlyphsUnicode = GlyphsUnicode;
  12995. exports.DingbatsGlyphsUnicode = DingbatsGlyphsUnicode;
  12996. }));
  12997. (function (root, factory) {
  12998. {
  12999. factory((root.pdfjsCoreJpg = {}));
  13000. }
  13001. }(this, function (exports) {
  13002. /*
  13003. This code was forked from https://github.com/notmasteryet/jpgjs. The original
  13004. version was created by github user notmasteryet
  13005. - The JPEG specification can be found in the ITU CCITT Recommendation T.81
  13006. (www.w3.org/Graphics/JPEG/itu-t81.pdf)
  13007. - The JFIF specification can be found in the JPEG File Interchange Format
  13008. (www.w3.org/Graphics/JPEG/jfif3.pdf)
  13009. - The Adobe Application-Specific JPEG markers in the Supporting the DCT Filters
  13010. in PostScript Level 2, Technical Note #5116
  13011. (partners.adobe.com/public/developer/en/ps/sdk/5116.DCT_Filter.pdf)
  13012. */
  13013. var JpegImage = (function jpegImage() {
  13014. var dctZigZag = new Uint8Array([
  13015. 0,
  13016. 1, 8,
  13017. 16, 9, 2,
  13018. 3, 10, 17, 24,
  13019. 32, 25, 18, 11, 4,
  13020. 5, 12, 19, 26, 33, 40,
  13021. 48, 41, 34, 27, 20, 13, 6,
  13022. 7, 14, 21, 28, 35, 42, 49, 56,
  13023. 57, 50, 43, 36, 29, 22, 15,
  13024. 23, 30, 37, 44, 51, 58,
  13025. 59, 52, 45, 38, 31,
  13026. 39, 46, 53, 60,
  13027. 61, 54, 47,
  13028. 55, 62,
  13029. 63
  13030. ]);
  13031. var dctCos1 = 4017; // cos(pi/16)
  13032. var dctSin1 = 799; // sin(pi/16)
  13033. var dctCos3 = 3406; // cos(3*pi/16)
  13034. var dctSin3 = 2276; // sin(3*pi/16)
  13035. var dctCos6 = 1567; // cos(6*pi/16)
  13036. var dctSin6 = 3784; // sin(6*pi/16)
  13037. var dctSqrt2 = 5793; // sqrt(2)
  13038. var dctSqrt1d2 = 2896; // sqrt(2) / 2
  13039. function constructor() {
  13040. }
  13041. function buildHuffmanTable(codeLengths, values) {
  13042. var k = 0, code = [], i, j, length = 16;
  13043. while (length > 0 && !codeLengths[length - 1]) {
  13044. length--;
  13045. }
  13046. code.push({children: [], index: 0});
  13047. var p = code[0], q;
  13048. for (i = 0; i < length; i++) {
  13049. for (j = 0; j < codeLengths[i]; j++) {
  13050. p = code.pop();
  13051. p.children[p.index] = values[k];
  13052. while (p.index > 0) {
  13053. p = code.pop();
  13054. }
  13055. p.index++;
  13056. code.push(p);
  13057. while (code.length <= i) {
  13058. code.push(q = {children: [], index: 0});
  13059. p.children[p.index] = q.children;
  13060. p = q;
  13061. }
  13062. k++;
  13063. }
  13064. if (i + 1 < length) {
  13065. // p here points to last code
  13066. code.push(q = {children: [], index: 0});
  13067. p.children[p.index] = q.children;
  13068. p = q;
  13069. }
  13070. }
  13071. return code[0].children;
  13072. }
  13073. function getBlockBufferOffset(component, row, col) {
  13074. return 64 * ((component.blocksPerLine + 1) * row + col);
  13075. }
  13076. function decodeScan(data, offset, frame, components, resetInterval,
  13077. spectralStart, spectralEnd, successivePrev, successive) {
  13078. var mcusPerLine = frame.mcusPerLine;
  13079. var progressive = frame.progressive;
  13080. var startOffset = offset, bitsData = 0, bitsCount = 0;
  13081. function readBit() {
  13082. if (bitsCount > 0) {
  13083. bitsCount--;
  13084. return (bitsData >> bitsCount) & 1;
  13085. }
  13086. bitsData = data[offset++];
  13087. if (bitsData === 0xFF) {
  13088. var nextByte = data[offset++];
  13089. if (nextByte) {
  13090. throw 'unexpected marker: ' +
  13091. ((bitsData << 8) | nextByte).toString(16);
  13092. }
  13093. // unstuff 0
  13094. }
  13095. bitsCount = 7;
  13096. return bitsData >>> 7;
  13097. }
  13098. function decodeHuffman(tree) {
  13099. var node = tree;
  13100. while (true) {
  13101. node = node[readBit()];
  13102. if (typeof node === 'number') {
  13103. return node;
  13104. }
  13105. if (typeof node !== 'object') {
  13106. throw 'invalid huffman sequence';
  13107. }
  13108. }
  13109. }
  13110. function receive(length) {
  13111. var n = 0;
  13112. while (length > 0) {
  13113. n = (n << 1) | readBit();
  13114. length--;
  13115. }
  13116. return n;
  13117. }
  13118. function receiveAndExtend(length) {
  13119. if (length === 1) {
  13120. return readBit() === 1 ? 1 : -1;
  13121. }
  13122. var n = receive(length);
  13123. if (n >= 1 << (length - 1)) {
  13124. return n;
  13125. }
  13126. return n + (-1 << length) + 1;
  13127. }
  13128. function decodeBaseline(component, offset) {
  13129. var t = decodeHuffman(component.huffmanTableDC);
  13130. var diff = t === 0 ? 0 : receiveAndExtend(t);
  13131. component.blockData[offset] = (component.pred += diff);
  13132. var k = 1;
  13133. while (k < 64) {
  13134. var rs = decodeHuffman(component.huffmanTableAC);
  13135. var s = rs & 15, r = rs >> 4;
  13136. if (s === 0) {
  13137. if (r < 15) {
  13138. break;
  13139. }
  13140. k += 16;
  13141. continue;
  13142. }
  13143. k += r;
  13144. var z = dctZigZag[k];
  13145. component.blockData[offset + z] = receiveAndExtend(s);
  13146. k++;
  13147. }
  13148. }
  13149. function decodeDCFirst(component, offset) {
  13150. var t = decodeHuffman(component.huffmanTableDC);
  13151. var diff = t === 0 ? 0 : (receiveAndExtend(t) << successive);
  13152. component.blockData[offset] = (component.pred += diff);
  13153. }
  13154. function decodeDCSuccessive(component, offset) {
  13155. component.blockData[offset] |= readBit() << successive;
  13156. }
  13157. var eobrun = 0;
  13158. function decodeACFirst(component, offset) {
  13159. if (eobrun > 0) {
  13160. eobrun--;
  13161. return;
  13162. }
  13163. var k = spectralStart, e = spectralEnd;
  13164. while (k <= e) {
  13165. var rs = decodeHuffman(component.huffmanTableAC);
  13166. var s = rs & 15, r = rs >> 4;
  13167. if (s === 0) {
  13168. if (r < 15) {
  13169. eobrun = receive(r) + (1 << r) - 1;
  13170. break;
  13171. }
  13172. k += 16;
  13173. continue;
  13174. }
  13175. k += r;
  13176. var z = dctZigZag[k];
  13177. component.blockData[offset + z] =
  13178. receiveAndExtend(s) * (1 << successive);
  13179. k++;
  13180. }
  13181. }
  13182. var successiveACState = 0, successiveACNextValue;
  13183. function decodeACSuccessive(component, offset) {
  13184. var k = spectralStart;
  13185. var e = spectralEnd;
  13186. var r = 0;
  13187. var s;
  13188. var rs;
  13189. while (k <= e) {
  13190. var z = dctZigZag[k];
  13191. switch (successiveACState) {
  13192. case 0: // initial state
  13193. rs = decodeHuffman(component.huffmanTableAC);
  13194. s = rs & 15;
  13195. r = rs >> 4;
  13196. if (s === 0) {
  13197. if (r < 15) {
  13198. eobrun = receive(r) + (1 << r);
  13199. successiveACState = 4;
  13200. } else {
  13201. r = 16;
  13202. successiveACState = 1;
  13203. }
  13204. } else {
  13205. if (s !== 1) {
  13206. throw 'invalid ACn encoding';
  13207. }
  13208. successiveACNextValue = receiveAndExtend(s);
  13209. successiveACState = r ? 2 : 3;
  13210. }
  13211. continue;
  13212. case 1: // skipping r zero items
  13213. case 2:
  13214. if (component.blockData[offset + z]) {
  13215. component.blockData[offset + z] += (readBit() << successive);
  13216. } else {
  13217. r--;
  13218. if (r === 0) {
  13219. successiveACState = successiveACState === 2 ? 3 : 0;
  13220. }
  13221. }
  13222. break;
  13223. case 3: // set value for a zero item
  13224. if (component.blockData[offset + z]) {
  13225. component.blockData[offset + z] += (readBit() << successive);
  13226. } else {
  13227. component.blockData[offset + z] =
  13228. successiveACNextValue << successive;
  13229. successiveACState = 0;
  13230. }
  13231. break;
  13232. case 4: // eob
  13233. if (component.blockData[offset + z]) {
  13234. component.blockData[offset + z] += (readBit() << successive);
  13235. }
  13236. break;
  13237. }
  13238. k++;
  13239. }
  13240. if (successiveACState === 4) {
  13241. eobrun--;
  13242. if (eobrun === 0) {
  13243. successiveACState = 0;
  13244. }
  13245. }
  13246. }
  13247. function decodeMcu(component, decode, mcu, row, col) {
  13248. var mcuRow = (mcu / mcusPerLine) | 0;
  13249. var mcuCol = mcu % mcusPerLine;
  13250. var blockRow = mcuRow * component.v + row;
  13251. var blockCol = mcuCol * component.h + col;
  13252. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  13253. decode(component, offset);
  13254. }
  13255. function decodeBlock(component, decode, mcu) {
  13256. var blockRow = (mcu / component.blocksPerLine) | 0;
  13257. var blockCol = mcu % component.blocksPerLine;
  13258. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  13259. decode(component, offset);
  13260. }
  13261. var componentsLength = components.length;
  13262. var component, i, j, k, n;
  13263. var decodeFn;
  13264. if (progressive) {
  13265. if (spectralStart === 0) {
  13266. decodeFn = successivePrev === 0 ? decodeDCFirst : decodeDCSuccessive;
  13267. } else {
  13268. decodeFn = successivePrev === 0 ? decodeACFirst : decodeACSuccessive;
  13269. }
  13270. } else {
  13271. decodeFn = decodeBaseline;
  13272. }
  13273. var mcu = 0, marker;
  13274. var mcuExpected;
  13275. if (componentsLength === 1) {
  13276. mcuExpected = components[0].blocksPerLine * components[0].blocksPerColumn;
  13277. } else {
  13278. mcuExpected = mcusPerLine * frame.mcusPerColumn;
  13279. }
  13280. if (!resetInterval) {
  13281. resetInterval = mcuExpected;
  13282. }
  13283. var h, v;
  13284. while (mcu < mcuExpected) {
  13285. // reset interval stuff
  13286. for (i = 0; i < componentsLength; i++) {
  13287. components[i].pred = 0;
  13288. }
  13289. eobrun = 0;
  13290. if (componentsLength === 1) {
  13291. component = components[0];
  13292. for (n = 0; n < resetInterval; n++) {
  13293. decodeBlock(component, decodeFn, mcu);
  13294. mcu++;
  13295. }
  13296. } else {
  13297. for (n = 0; n < resetInterval; n++) {
  13298. for (i = 0; i < componentsLength; i++) {
  13299. component = components[i];
  13300. h = component.h;
  13301. v = component.v;
  13302. for (j = 0; j < v; j++) {
  13303. for (k = 0; k < h; k++) {
  13304. decodeMcu(component, decodeFn, mcu, j, k);
  13305. }
  13306. }
  13307. }
  13308. mcu++;
  13309. }
  13310. }
  13311. // find marker
  13312. bitsCount = 0;
  13313. marker = (data[offset] << 8) | data[offset + 1];
  13314. if (marker <= 0xFF00) {
  13315. throw 'marker was not found';
  13316. }
  13317. if (marker >= 0xFFD0 && marker <= 0xFFD7) { // RSTx
  13318. offset += 2;
  13319. } else {
  13320. break;
  13321. }
  13322. }
  13323. return offset - startOffset;
  13324. }
  13325. // A port of poppler's IDCT method which in turn is taken from:
  13326. // Christoph Loeffler, Adriaan Ligtenberg, George S. Moschytz,
  13327. // 'Practical Fast 1-D DCT Algorithms with 11 Multiplications',
  13328. // IEEE Intl. Conf. on Acoustics, Speech & Signal Processing, 1989,
  13329. // 988-991.
  13330. function quantizeAndInverse(component, blockBufferOffset, p) {
  13331. var qt = component.quantizationTable, blockData = component.blockData;
  13332. var v0, v1, v2, v3, v4, v5, v6, v7;
  13333. var p0, p1, p2, p3, p4, p5, p6, p7;
  13334. var t;
  13335. // inverse DCT on rows
  13336. for (var row = 0; row < 64; row += 8) {
  13337. // gather block data
  13338. p0 = blockData[blockBufferOffset + row];
  13339. p1 = blockData[blockBufferOffset + row + 1];
  13340. p2 = blockData[blockBufferOffset + row + 2];
  13341. p3 = blockData[blockBufferOffset + row + 3];
  13342. p4 = blockData[blockBufferOffset + row + 4];
  13343. p5 = blockData[blockBufferOffset + row + 5];
  13344. p6 = blockData[blockBufferOffset + row + 6];
  13345. p7 = blockData[blockBufferOffset + row + 7];
  13346. // dequant p0
  13347. p0 *= qt[row];
  13348. // check for all-zero AC coefficients
  13349. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  13350. t = (dctSqrt2 * p0 + 512) >> 10;
  13351. p[row] = t;
  13352. p[row + 1] = t;
  13353. p[row + 2] = t;
  13354. p[row + 3] = t;
  13355. p[row + 4] = t;
  13356. p[row + 5] = t;
  13357. p[row + 6] = t;
  13358. p[row + 7] = t;
  13359. continue;
  13360. }
  13361. // dequant p1 ... p7
  13362. p1 *= qt[row + 1];
  13363. p2 *= qt[row + 2];
  13364. p3 *= qt[row + 3];
  13365. p4 *= qt[row + 4];
  13366. p5 *= qt[row + 5];
  13367. p6 *= qt[row + 6];
  13368. p7 *= qt[row + 7];
  13369. // stage 4
  13370. v0 = (dctSqrt2 * p0 + 128) >> 8;
  13371. v1 = (dctSqrt2 * p4 + 128) >> 8;
  13372. v2 = p2;
  13373. v3 = p6;
  13374. v4 = (dctSqrt1d2 * (p1 - p7) + 128) >> 8;
  13375. v7 = (dctSqrt1d2 * (p1 + p7) + 128) >> 8;
  13376. v5 = p3 << 4;
  13377. v6 = p5 << 4;
  13378. // stage 3
  13379. v0 = (v0 + v1 + 1) >> 1;
  13380. v1 = v0 - v1;
  13381. t = (v2 * dctSin6 + v3 * dctCos6 + 128) >> 8;
  13382. v2 = (v2 * dctCos6 - v3 * dctSin6 + 128) >> 8;
  13383. v3 = t;
  13384. v4 = (v4 + v6 + 1) >> 1;
  13385. v6 = v4 - v6;
  13386. v7 = (v7 + v5 + 1) >> 1;
  13387. v5 = v7 - v5;
  13388. // stage 2
  13389. v0 = (v0 + v3 + 1) >> 1;
  13390. v3 = v0 - v3;
  13391. v1 = (v1 + v2 + 1) >> 1;
  13392. v2 = v1 - v2;
  13393. t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12;
  13394. v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12;
  13395. v7 = t;
  13396. t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12;
  13397. v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12;
  13398. v6 = t;
  13399. // stage 1
  13400. p[row] = v0 + v7;
  13401. p[row + 7] = v0 - v7;
  13402. p[row + 1] = v1 + v6;
  13403. p[row + 6] = v1 - v6;
  13404. p[row + 2] = v2 + v5;
  13405. p[row + 5] = v2 - v5;
  13406. p[row + 3] = v3 + v4;
  13407. p[row + 4] = v3 - v4;
  13408. }
  13409. // inverse DCT on columns
  13410. for (var col = 0; col < 8; ++col) {
  13411. p0 = p[col];
  13412. p1 = p[col + 8];
  13413. p2 = p[col + 16];
  13414. p3 = p[col + 24];
  13415. p4 = p[col + 32];
  13416. p5 = p[col + 40];
  13417. p6 = p[col + 48];
  13418. p7 = p[col + 56];
  13419. // check for all-zero AC coefficients
  13420. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  13421. t = (dctSqrt2 * p0 + 8192) >> 14;
  13422. // convert to 8 bit
  13423. t = (t < -2040) ? 0 : (t >= 2024) ? 255 : (t + 2056) >> 4;
  13424. blockData[blockBufferOffset + col] = t;
  13425. blockData[blockBufferOffset + col + 8] = t;
  13426. blockData[blockBufferOffset + col + 16] = t;
  13427. blockData[blockBufferOffset + col + 24] = t;
  13428. blockData[blockBufferOffset + col + 32] = t;
  13429. blockData[blockBufferOffset + col + 40] = t;
  13430. blockData[blockBufferOffset + col + 48] = t;
  13431. blockData[blockBufferOffset + col + 56] = t;
  13432. continue;
  13433. }
  13434. // stage 4
  13435. v0 = (dctSqrt2 * p0 + 2048) >> 12;
  13436. v1 = (dctSqrt2 * p4 + 2048) >> 12;
  13437. v2 = p2;
  13438. v3 = p6;
  13439. v4 = (dctSqrt1d2 * (p1 - p7) + 2048) >> 12;
  13440. v7 = (dctSqrt1d2 * (p1 + p7) + 2048) >> 12;
  13441. v5 = p3;
  13442. v6 = p5;
  13443. // stage 3
  13444. // Shift v0 by 128.5 << 5 here, so we don't need to shift p0...p7 when
  13445. // converting to UInt8 range later.
  13446. v0 = ((v0 + v1 + 1) >> 1) + 4112;
  13447. v1 = v0 - v1;
  13448. t = (v2 * dctSin6 + v3 * dctCos6 + 2048) >> 12;
  13449. v2 = (v2 * dctCos6 - v3 * dctSin6 + 2048) >> 12;
  13450. v3 = t;
  13451. v4 = (v4 + v6 + 1) >> 1;
  13452. v6 = v4 - v6;
  13453. v7 = (v7 + v5 + 1) >> 1;
  13454. v5 = v7 - v5;
  13455. // stage 2
  13456. v0 = (v0 + v3 + 1) >> 1;
  13457. v3 = v0 - v3;
  13458. v1 = (v1 + v2 + 1) >> 1;
  13459. v2 = v1 - v2;
  13460. t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12;
  13461. v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12;
  13462. v7 = t;
  13463. t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12;
  13464. v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12;
  13465. v6 = t;
  13466. // stage 1
  13467. p0 = v0 + v7;
  13468. p7 = v0 - v7;
  13469. p1 = v1 + v6;
  13470. p6 = v1 - v6;
  13471. p2 = v2 + v5;
  13472. p5 = v2 - v5;
  13473. p3 = v3 + v4;
  13474. p4 = v3 - v4;
  13475. // convert to 8-bit integers
  13476. p0 = (p0 < 16) ? 0 : (p0 >= 4080) ? 255 : p0 >> 4;
  13477. p1 = (p1 < 16) ? 0 : (p1 >= 4080) ? 255 : p1 >> 4;
  13478. p2 = (p2 < 16) ? 0 : (p2 >= 4080) ? 255 : p2 >> 4;
  13479. p3 = (p3 < 16) ? 0 : (p3 >= 4080) ? 255 : p3 >> 4;
  13480. p4 = (p4 < 16) ? 0 : (p4 >= 4080) ? 255 : p4 >> 4;
  13481. p5 = (p5 < 16) ? 0 : (p5 >= 4080) ? 255 : p5 >> 4;
  13482. p6 = (p6 < 16) ? 0 : (p6 >= 4080) ? 255 : p6 >> 4;
  13483. p7 = (p7 < 16) ? 0 : (p7 >= 4080) ? 255 : p7 >> 4;
  13484. // store block data
  13485. blockData[blockBufferOffset + col] = p0;
  13486. blockData[blockBufferOffset + col + 8] = p1;
  13487. blockData[blockBufferOffset + col + 16] = p2;
  13488. blockData[blockBufferOffset + col + 24] = p3;
  13489. blockData[blockBufferOffset + col + 32] = p4;
  13490. blockData[blockBufferOffset + col + 40] = p5;
  13491. blockData[blockBufferOffset + col + 48] = p6;
  13492. blockData[blockBufferOffset + col + 56] = p7;
  13493. }
  13494. }
  13495. function buildComponentData(frame, component) {
  13496. var blocksPerLine = component.blocksPerLine;
  13497. var blocksPerColumn = component.blocksPerColumn;
  13498. var computationBuffer = new Int16Array(64);
  13499. for (var blockRow = 0; blockRow < blocksPerColumn; blockRow++) {
  13500. for (var blockCol = 0; blockCol < blocksPerLine; blockCol++) {
  13501. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  13502. quantizeAndInverse(component, offset, computationBuffer);
  13503. }
  13504. }
  13505. return component.blockData;
  13506. }
  13507. function clamp0to255(a) {
  13508. return a <= 0 ? 0 : a >= 255 ? 255 : a;
  13509. }
  13510. constructor.prototype = {
  13511. parse: function parse(data) {
  13512. function readUint16() {
  13513. var value = (data[offset] << 8) | data[offset + 1];
  13514. offset += 2;
  13515. return value;
  13516. }
  13517. function readDataBlock() {
  13518. var length = readUint16();
  13519. var array = data.subarray(offset, offset + length - 2);
  13520. offset += array.length;
  13521. return array;
  13522. }
  13523. function prepareComponents(frame) {
  13524. var mcusPerLine = Math.ceil(frame.samplesPerLine / 8 / frame.maxH);
  13525. var mcusPerColumn = Math.ceil(frame.scanLines / 8 / frame.maxV);
  13526. for (var i = 0; i < frame.components.length; i++) {
  13527. component = frame.components[i];
  13528. var blocksPerLine = Math.ceil(Math.ceil(frame.samplesPerLine / 8) *
  13529. component.h / frame.maxH);
  13530. var blocksPerColumn = Math.ceil(Math.ceil(frame.scanLines / 8) *
  13531. component.v / frame.maxV);
  13532. var blocksPerLineForMcu = mcusPerLine * component.h;
  13533. var blocksPerColumnForMcu = mcusPerColumn * component.v;
  13534. var blocksBufferSize = 64 * blocksPerColumnForMcu *
  13535. (blocksPerLineForMcu + 1);
  13536. component.blockData = new Int16Array(blocksBufferSize);
  13537. component.blocksPerLine = blocksPerLine;
  13538. component.blocksPerColumn = blocksPerColumn;
  13539. }
  13540. frame.mcusPerLine = mcusPerLine;
  13541. frame.mcusPerColumn = mcusPerColumn;
  13542. }
  13543. var offset = 0;
  13544. var jfif = null;
  13545. var adobe = null;
  13546. var frame, resetInterval;
  13547. var quantizationTables = [];
  13548. var huffmanTablesAC = [], huffmanTablesDC = [];
  13549. var fileMarker = readUint16();
  13550. if (fileMarker !== 0xFFD8) { // SOI (Start of Image)
  13551. throw 'SOI not found';
  13552. }
  13553. fileMarker = readUint16();
  13554. while (fileMarker !== 0xFFD9) { // EOI (End of image)
  13555. var i, j, l;
  13556. switch(fileMarker) {
  13557. case 0xFFE0: // APP0 (Application Specific)
  13558. case 0xFFE1: // APP1
  13559. case 0xFFE2: // APP2
  13560. case 0xFFE3: // APP3
  13561. case 0xFFE4: // APP4
  13562. case 0xFFE5: // APP5
  13563. case 0xFFE6: // APP6
  13564. case 0xFFE7: // APP7
  13565. case 0xFFE8: // APP8
  13566. case 0xFFE9: // APP9
  13567. case 0xFFEA: // APP10
  13568. case 0xFFEB: // APP11
  13569. case 0xFFEC: // APP12
  13570. case 0xFFED: // APP13
  13571. case 0xFFEE: // APP14
  13572. case 0xFFEF: // APP15
  13573. case 0xFFFE: // COM (Comment)
  13574. var appData = readDataBlock();
  13575. if (fileMarker === 0xFFE0) {
  13576. if (appData[0] === 0x4A && appData[1] === 0x46 &&
  13577. appData[2] === 0x49 && appData[3] === 0x46 &&
  13578. appData[4] === 0) { // 'JFIF\x00'
  13579. jfif = {
  13580. version: { major: appData[5], minor: appData[6] },
  13581. densityUnits: appData[7],
  13582. xDensity: (appData[8] << 8) | appData[9],
  13583. yDensity: (appData[10] << 8) | appData[11],
  13584. thumbWidth: appData[12],
  13585. thumbHeight: appData[13],
  13586. thumbData: appData.subarray(14, 14 +
  13587. 3 * appData[12] * appData[13])
  13588. };
  13589. }
  13590. }
  13591. // TODO APP1 - Exif
  13592. if (fileMarker === 0xFFEE) {
  13593. if (appData[0] === 0x41 && appData[1] === 0x64 &&
  13594. appData[2] === 0x6F && appData[3] === 0x62 &&
  13595. appData[4] === 0x65) { // 'Adobe'
  13596. adobe = {
  13597. version: (appData[5] << 8) | appData[6],
  13598. flags0: (appData[7] << 8) | appData[8],
  13599. flags1: (appData[9] << 8) | appData[10],
  13600. transformCode: appData[11]
  13601. };
  13602. }
  13603. }
  13604. break;
  13605. case 0xFFDB: // DQT (Define Quantization Tables)
  13606. var quantizationTablesLength = readUint16();
  13607. var quantizationTablesEnd = quantizationTablesLength + offset - 2;
  13608. var z;
  13609. while (offset < quantizationTablesEnd) {
  13610. var quantizationTableSpec = data[offset++];
  13611. var tableData = new Uint16Array(64);
  13612. if ((quantizationTableSpec >> 4) === 0) { // 8 bit values
  13613. for (j = 0; j < 64; j++) {
  13614. z = dctZigZag[j];
  13615. tableData[z] = data[offset++];
  13616. }
  13617. } else if ((quantizationTableSpec >> 4) === 1) { //16 bit
  13618. for (j = 0; j < 64; j++) {
  13619. z = dctZigZag[j];
  13620. tableData[z] = readUint16();
  13621. }
  13622. } else {
  13623. throw 'DQT: invalid table spec';
  13624. }
  13625. quantizationTables[quantizationTableSpec & 15] = tableData;
  13626. }
  13627. break;
  13628. case 0xFFC0: // SOF0 (Start of Frame, Baseline DCT)
  13629. case 0xFFC1: // SOF1 (Start of Frame, Extended DCT)
  13630. case 0xFFC2: // SOF2 (Start of Frame, Progressive DCT)
  13631. if (frame) {
  13632. throw 'Only single frame JPEGs supported';
  13633. }
  13634. readUint16(); // skip data length
  13635. frame = {};
  13636. frame.extended = (fileMarker === 0xFFC1);
  13637. frame.progressive = (fileMarker === 0xFFC2);
  13638. frame.precision = data[offset++];
  13639. frame.scanLines = readUint16();
  13640. frame.samplesPerLine = readUint16();
  13641. frame.components = [];
  13642. frame.componentIds = {};
  13643. var componentsCount = data[offset++], componentId;
  13644. var maxH = 0, maxV = 0;
  13645. for (i = 0; i < componentsCount; i++) {
  13646. componentId = data[offset];
  13647. var h = data[offset + 1] >> 4;
  13648. var v = data[offset + 1] & 15;
  13649. if (maxH < h) {
  13650. maxH = h;
  13651. }
  13652. if (maxV < v) {
  13653. maxV = v;
  13654. }
  13655. var qId = data[offset + 2];
  13656. l = frame.components.push({
  13657. h: h,
  13658. v: v,
  13659. quantizationTable: quantizationTables[qId]
  13660. });
  13661. frame.componentIds[componentId] = l - 1;
  13662. offset += 3;
  13663. }
  13664. frame.maxH = maxH;
  13665. frame.maxV = maxV;
  13666. prepareComponents(frame);
  13667. break;
  13668. case 0xFFC4: // DHT (Define Huffman Tables)
  13669. var huffmanLength = readUint16();
  13670. for (i = 2; i < huffmanLength;) {
  13671. var huffmanTableSpec = data[offset++];
  13672. var codeLengths = new Uint8Array(16);
  13673. var codeLengthSum = 0;
  13674. for (j = 0; j < 16; j++, offset++) {
  13675. codeLengthSum += (codeLengths[j] = data[offset]);
  13676. }
  13677. var huffmanValues = new Uint8Array(codeLengthSum);
  13678. for (j = 0; j < codeLengthSum; j++, offset++) {
  13679. huffmanValues[j] = data[offset];
  13680. }
  13681. i += 17 + codeLengthSum;
  13682. ((huffmanTableSpec >> 4) === 0 ?
  13683. huffmanTablesDC : huffmanTablesAC)[huffmanTableSpec & 15] =
  13684. buildHuffmanTable(codeLengths, huffmanValues);
  13685. }
  13686. break;
  13687. case 0xFFDD: // DRI (Define Restart Interval)
  13688. readUint16(); // skip data length
  13689. resetInterval = readUint16();
  13690. break;
  13691. case 0xFFDA: // SOS (Start of Scan)
  13692. var scanLength = readUint16();
  13693. var selectorsCount = data[offset++];
  13694. var components = [], component;
  13695. for (i = 0; i < selectorsCount; i++) {
  13696. var componentIndex = frame.componentIds[data[offset++]];
  13697. component = frame.components[componentIndex];
  13698. var tableSpec = data[offset++];
  13699. component.huffmanTableDC = huffmanTablesDC[tableSpec >> 4];
  13700. component.huffmanTableAC = huffmanTablesAC[tableSpec & 15];
  13701. components.push(component);
  13702. }
  13703. var spectralStart = data[offset++];
  13704. var spectralEnd = data[offset++];
  13705. var successiveApproximation = data[offset++];
  13706. var processed = decodeScan(data, offset,
  13707. frame, components, resetInterval,
  13708. spectralStart, spectralEnd,
  13709. successiveApproximation >> 4, successiveApproximation & 15);
  13710. offset += processed;
  13711. break;
  13712. case 0xFFFF: // Fill bytes
  13713. if (data[offset] !== 0xFF) { // Avoid skipping a valid marker.
  13714. offset--;
  13715. }
  13716. break;
  13717. default:
  13718. if (data[offset - 3] === 0xFF &&
  13719. data[offset - 2] >= 0xC0 && data[offset - 2] <= 0xFE) {
  13720. // could be incorrect encoding -- last 0xFF byte of the previous
  13721. // block was eaten by the encoder
  13722. offset -= 3;
  13723. break;
  13724. }
  13725. throw 'unknown JPEG marker ' + fileMarker.toString(16);
  13726. }
  13727. fileMarker = readUint16();
  13728. }
  13729. this.width = frame.samplesPerLine;
  13730. this.height = frame.scanLines;
  13731. this.jfif = jfif;
  13732. this.adobe = adobe;
  13733. this.components = [];
  13734. for (i = 0; i < frame.components.length; i++) {
  13735. component = frame.components[i];
  13736. this.components.push({
  13737. output: buildComponentData(frame, component),
  13738. scaleX: component.h / frame.maxH,
  13739. scaleY: component.v / frame.maxV,
  13740. blocksPerLine: component.blocksPerLine,
  13741. blocksPerColumn: component.blocksPerColumn
  13742. });
  13743. }
  13744. this.numComponents = this.components.length;
  13745. },
  13746. _getLinearizedBlockData: function getLinearizedBlockData(width, height) {
  13747. var scaleX = this.width / width, scaleY = this.height / height;
  13748. var component, componentScaleX, componentScaleY, blocksPerScanline;
  13749. var x, y, i, j, k;
  13750. var index;
  13751. var offset = 0;
  13752. var output;
  13753. var numComponents = this.components.length;
  13754. var dataLength = width * height * numComponents;
  13755. var data = new Uint8Array(dataLength);
  13756. var xScaleBlockOffset = new Uint32Array(width);
  13757. var mask3LSB = 0xfffffff8; // used to clear the 3 LSBs
  13758. for (i = 0; i < numComponents; i++) {
  13759. component = this.components[i];
  13760. componentScaleX = component.scaleX * scaleX;
  13761. componentScaleY = component.scaleY * scaleY;
  13762. offset = i;
  13763. output = component.output;
  13764. blocksPerScanline = (component.blocksPerLine + 1) << 3;
  13765. // precalculate the xScaleBlockOffset
  13766. for (x = 0; x < width; x++) {
  13767. j = 0 | (x * componentScaleX);
  13768. xScaleBlockOffset[x] = ((j & mask3LSB) << 3) | (j & 7);
  13769. }
  13770. // linearize the blocks of the component
  13771. for (y = 0; y < height; y++) {
  13772. j = 0 | (y * componentScaleY);
  13773. index = blocksPerScanline * (j & mask3LSB) | ((j & 7) << 3);
  13774. for (x = 0; x < width; x++) {
  13775. data[offset] = output[index + xScaleBlockOffset[x]];
  13776. offset += numComponents;
  13777. }
  13778. }
  13779. }
  13780. // decodeTransform contains pairs of multiplier (-256..256) and additive
  13781. var transform = this.decodeTransform;
  13782. if (transform) {
  13783. for (i = 0; i < dataLength;) {
  13784. for (j = 0, k = 0; j < numComponents; j++, i++, k += 2) {
  13785. data[i] = ((data[i] * transform[k]) >> 8) + transform[k + 1];
  13786. }
  13787. }
  13788. }
  13789. return data;
  13790. },
  13791. _isColorConversionNeeded: function isColorConversionNeeded() {
  13792. if (this.adobe && this.adobe.transformCode) {
  13793. // The adobe transform marker overrides any previous setting
  13794. return true;
  13795. } else if (this.numComponents === 3) {
  13796. return true;
  13797. } else {
  13798. return false;
  13799. }
  13800. },
  13801. _convertYccToRgb: function convertYccToRgb(data) {
  13802. var Y, Cb, Cr;
  13803. for (var i = 0, length = data.length; i < length; i += 3) {
  13804. Y = data[i ];
  13805. Cb = data[i + 1];
  13806. Cr = data[i + 2];
  13807. data[i ] = clamp0to255(Y - 179.456 + 1.402 * Cr);
  13808. data[i + 1] = clamp0to255(Y + 135.459 - 0.344 * Cb - 0.714 * Cr);
  13809. data[i + 2] = clamp0to255(Y - 226.816 + 1.772 * Cb);
  13810. }
  13811. return data;
  13812. },
  13813. _convertYcckToRgb: function convertYcckToRgb(data) {
  13814. var Y, Cb, Cr, k;
  13815. var offset = 0;
  13816. for (var i = 0, length = data.length; i < length; i += 4) {
  13817. Y = data[i];
  13818. Cb = data[i + 1];
  13819. Cr = data[i + 2];
  13820. k = data[i + 3];
  13821. var r = -122.67195406894 +
  13822. Cb * (-6.60635669420364e-5 * Cb + 0.000437130475926232 * Cr -
  13823. 5.4080610064599e-5 * Y + 0.00048449797120281 * k -
  13824. 0.154362151871126) +
  13825. Cr * (-0.000957964378445773 * Cr + 0.000817076911346625 * Y -
  13826. 0.00477271405408747 * k + 1.53380253221734) +
  13827. Y * (0.000961250184130688 * Y - 0.00266257332283933 * k +
  13828. 0.48357088451265) +
  13829. k * (-0.000336197177618394 * k + 0.484791561490776);
  13830. var g = 107.268039397724 +
  13831. Cb * (2.19927104525741e-5 * Cb - 0.000640992018297945 * Cr +
  13832. 0.000659397001245577 * Y + 0.000426105652938837 * k -
  13833. 0.176491792462875) +
  13834. Cr * (-0.000778269941513683 * Cr + 0.00130872261408275 * Y +
  13835. 0.000770482631801132 * k - 0.151051492775562) +
  13836. Y * (0.00126935368114843 * Y - 0.00265090189010898 * k +
  13837. 0.25802910206845) +
  13838. k * (-0.000318913117588328 * k - 0.213742400323665);
  13839. var b = -20.810012546947 +
  13840. Cb * (-0.000570115196973677 * Cb - 2.63409051004589e-5 * Cr +
  13841. 0.0020741088115012 * Y - 0.00288260236853442 * k +
  13842. 0.814272968359295) +
  13843. Cr * (-1.53496057440975e-5 * Cr - 0.000132689043961446 * Y +
  13844. 0.000560833691242812 * k - 0.195152027534049) +
  13845. Y * (0.00174418132927582 * Y - 0.00255243321439347 * k +
  13846. 0.116935020465145) +
  13847. k * (-0.000343531996510555 * k + 0.24165260232407);
  13848. data[offset++] = clamp0to255(r);
  13849. data[offset++] = clamp0to255(g);
  13850. data[offset++] = clamp0to255(b);
  13851. }
  13852. return data;
  13853. },
  13854. _convertYcckToCmyk: function convertYcckToCmyk(data) {
  13855. var Y, Cb, Cr;
  13856. for (var i = 0, length = data.length; i < length; i += 4) {
  13857. Y = data[i];
  13858. Cb = data[i + 1];
  13859. Cr = data[i + 2];
  13860. data[i ] = clamp0to255(434.456 - Y - 1.402 * Cr);
  13861. data[i + 1] = clamp0to255(119.541 - Y + 0.344 * Cb + 0.714 * Cr);
  13862. data[i + 2] = clamp0to255(481.816 - Y - 1.772 * Cb);
  13863. // K in data[i + 3] is unchanged
  13864. }
  13865. return data;
  13866. },
  13867. _convertCmykToRgb: function convertCmykToRgb(data) {
  13868. var c, m, y, k;
  13869. var offset = 0;
  13870. var min = -255 * 255 * 255;
  13871. var scale = 1 / 255 / 255;
  13872. for (var i = 0, length = data.length; i < length; i += 4) {
  13873. c = data[i];
  13874. m = data[i + 1];
  13875. y = data[i + 2];
  13876. k = data[i + 3];
  13877. var r =
  13878. c * (-4.387332384609988 * c + 54.48615194189176 * m +
  13879. 18.82290502165302 * y + 212.25662451639585 * k -
  13880. 72734.4411664936) +
  13881. m * (1.7149763477362134 * m - 5.6096736904047315 * y -
  13882. 17.873870861415444 * k - 1401.7366389350734) +
  13883. y * (-2.5217340131683033 * y - 21.248923337353073 * k +
  13884. 4465.541406466231) -
  13885. k * (21.86122147463605 * k + 48317.86113160301);
  13886. var g =
  13887. c * (8.841041422036149 * c + 60.118027045597366 * m +
  13888. 6.871425592049007 * y + 31.159100130055922 * k -
  13889. 20220.756542821975) +
  13890. m * (-15.310361306967817 * m + 17.575251261109482 * y +
  13891. 131.35250912493976 * k - 48691.05921601825) +
  13892. y * (4.444339102852739 * y + 9.8632861493405 * k -
  13893. 6341.191035517494) -
  13894. k * (20.737325471181034 * k + 47890.15695978492);
  13895. var b =
  13896. c * (0.8842522430003296 * c + 8.078677503112928 * m +
  13897. 30.89978309703729 * y - 0.23883238689178934 * k -
  13898. 3616.812083916688) +
  13899. m * (10.49593273432072 * m + 63.02378494754052 * y +
  13900. 50.606957656360734 * k - 28620.90484698408) +
  13901. y * (0.03296041114873217 * y + 115.60384449646641 * k -
  13902. 49363.43385999684) -
  13903. k * (22.33816807309886 * k + 45932.16563550634);
  13904. data[offset++] = r >= 0 ? 255 : r <= min ? 0 : 255 + r * scale | 0;
  13905. data[offset++] = g >= 0 ? 255 : g <= min ? 0 : 255 + g * scale | 0;
  13906. data[offset++] = b >= 0 ? 255 : b <= min ? 0 : 255 + b * scale | 0;
  13907. }
  13908. return data;
  13909. },
  13910. getData: function getData(width, height, forceRGBoutput) {
  13911. if (this.numComponents > 4) {
  13912. throw 'Unsupported color mode';
  13913. }
  13914. // type of data: Uint8Array(width * height * numComponents)
  13915. var data = this._getLinearizedBlockData(width, height);
  13916. if (this.numComponents === 3) {
  13917. return this._convertYccToRgb(data);
  13918. } else if (this.numComponents === 4) {
  13919. if (this._isColorConversionNeeded()) {
  13920. if (forceRGBoutput) {
  13921. return this._convertYcckToRgb(data);
  13922. } else {
  13923. return this._convertYcckToCmyk(data);
  13924. }
  13925. } else if (forceRGBoutput) {
  13926. return this._convertCmykToRgb(data);
  13927. }
  13928. }
  13929. return data;
  13930. }
  13931. };
  13932. return constructor;
  13933. })();
  13934. exports.JpegImage = JpegImage;
  13935. }));
  13936. (function (root, factory) {
  13937. {
  13938. factory((root.pdfjsCoreMetrics = {}));
  13939. }
  13940. }(this, function (exports) {
  13941. // The Metrics object contains glyph widths (in glyph space units).
  13942. // As per PDF spec, for most fonts (Type 3 being an exception) a glyph
  13943. // space unit corresponds to 1/1000th of text space unit.
  13944. var Metrics = {
  13945. 'Courier': 600,
  13946. 'Courier-Bold': 600,
  13947. 'Courier-BoldOblique': 600,
  13948. 'Courier-Oblique': 600,
  13949. 'Helvetica' : {
  13950. 'space': 278,
  13951. 'exclam': 278,
  13952. 'quotedbl': 355,
  13953. 'numbersign': 556,
  13954. 'dollar': 556,
  13955. 'percent': 889,
  13956. 'ampersand': 667,
  13957. 'quoteright': 222,
  13958. 'parenleft': 333,
  13959. 'parenright': 333,
  13960. 'asterisk': 389,
  13961. 'plus': 584,
  13962. 'comma': 278,
  13963. 'hyphen': 333,
  13964. 'period': 278,
  13965. 'slash': 278,
  13966. 'zero': 556,
  13967. 'one': 556,
  13968. 'two': 556,
  13969. 'three': 556,
  13970. 'four': 556,
  13971. 'five': 556,
  13972. 'six': 556,
  13973. 'seven': 556,
  13974. 'eight': 556,
  13975. 'nine': 556,
  13976. 'colon': 278,
  13977. 'semicolon': 278,
  13978. 'less': 584,
  13979. 'equal': 584,
  13980. 'greater': 584,
  13981. 'question': 556,
  13982. 'at': 1015,
  13983. 'A': 667,
  13984. 'B': 667,
  13985. 'C': 722,
  13986. 'D': 722,
  13987. 'E': 667,
  13988. 'F': 611,
  13989. 'G': 778,
  13990. 'H': 722,
  13991. 'I': 278,
  13992. 'J': 500,
  13993. 'K': 667,
  13994. 'L': 556,
  13995. 'M': 833,
  13996. 'N': 722,
  13997. 'O': 778,
  13998. 'P': 667,
  13999. 'Q': 778,
  14000. 'R': 722,
  14001. 'S': 667,
  14002. 'T': 611,
  14003. 'U': 722,
  14004. 'V': 667,
  14005. 'W': 944,
  14006. 'X': 667,
  14007. 'Y': 667,
  14008. 'Z': 611,
  14009. 'bracketleft': 278,
  14010. 'backslash': 278,
  14011. 'bracketright': 278,
  14012. 'asciicircum': 469,
  14013. 'underscore': 556,
  14014. 'quoteleft': 222,
  14015. 'a': 556,
  14016. 'b': 556,
  14017. 'c': 500,
  14018. 'd': 556,
  14019. 'e': 556,
  14020. 'f': 278,
  14021. 'g': 556,
  14022. 'h': 556,
  14023. 'i': 222,
  14024. 'j': 222,
  14025. 'k': 500,
  14026. 'l': 222,
  14027. 'm': 833,
  14028. 'n': 556,
  14029. 'o': 556,
  14030. 'p': 556,
  14031. 'q': 556,
  14032. 'r': 333,
  14033. 's': 500,
  14034. 't': 278,
  14035. 'u': 556,
  14036. 'v': 500,
  14037. 'w': 722,
  14038. 'x': 500,
  14039. 'y': 500,
  14040. 'z': 500,
  14041. 'braceleft': 334,
  14042. 'bar': 260,
  14043. 'braceright': 334,
  14044. 'asciitilde': 584,
  14045. 'exclamdown': 333,
  14046. 'cent': 556,
  14047. 'sterling': 556,
  14048. 'fraction': 167,
  14049. 'yen': 556,
  14050. 'florin': 556,
  14051. 'section': 556,
  14052. 'currency': 556,
  14053. 'quotesingle': 191,
  14054. 'quotedblleft': 333,
  14055. 'guillemotleft': 556,
  14056. 'guilsinglleft': 333,
  14057. 'guilsinglright': 333,
  14058. 'fi': 500,
  14059. 'fl': 500,
  14060. 'endash': 556,
  14061. 'dagger': 556,
  14062. 'daggerdbl': 556,
  14063. 'periodcentered': 278,
  14064. 'paragraph': 537,
  14065. 'bullet': 350,
  14066. 'quotesinglbase': 222,
  14067. 'quotedblbase': 333,
  14068. 'quotedblright': 333,
  14069. 'guillemotright': 556,
  14070. 'ellipsis': 1000,
  14071. 'perthousand': 1000,
  14072. 'questiondown': 611,
  14073. 'grave': 333,
  14074. 'acute': 333,
  14075. 'circumflex': 333,
  14076. 'tilde': 333,
  14077. 'macron': 333,
  14078. 'breve': 333,
  14079. 'dotaccent': 333,
  14080. 'dieresis': 333,
  14081. 'ring': 333,
  14082. 'cedilla': 333,
  14083. 'hungarumlaut': 333,
  14084. 'ogonek': 333,
  14085. 'caron': 333,
  14086. 'emdash': 1000,
  14087. 'AE': 1000,
  14088. 'ordfeminine': 370,
  14089. 'Lslash': 556,
  14090. 'Oslash': 778,
  14091. 'OE': 1000,
  14092. 'ordmasculine': 365,
  14093. 'ae': 889,
  14094. 'dotlessi': 278,
  14095. 'lslash': 222,
  14096. 'oslash': 611,
  14097. 'oe': 944,
  14098. 'germandbls': 611,
  14099. 'Idieresis': 278,
  14100. 'eacute': 556,
  14101. 'abreve': 556,
  14102. 'uhungarumlaut': 556,
  14103. 'ecaron': 556,
  14104. 'Ydieresis': 667,
  14105. 'divide': 584,
  14106. 'Yacute': 667,
  14107. 'Acircumflex': 667,
  14108. 'aacute': 556,
  14109. 'Ucircumflex': 722,
  14110. 'yacute': 500,
  14111. 'scommaaccent': 500,
  14112. 'ecircumflex': 556,
  14113. 'Uring': 722,
  14114. 'Udieresis': 722,
  14115. 'aogonek': 556,
  14116. 'Uacute': 722,
  14117. 'uogonek': 556,
  14118. 'Edieresis': 667,
  14119. 'Dcroat': 722,
  14120. 'commaaccent': 250,
  14121. 'copyright': 737,
  14122. 'Emacron': 667,
  14123. 'ccaron': 500,
  14124. 'aring': 556,
  14125. 'Ncommaaccent': 722,
  14126. 'lacute': 222,
  14127. 'agrave': 556,
  14128. 'Tcommaaccent': 611,
  14129. 'Cacute': 722,
  14130. 'atilde': 556,
  14131. 'Edotaccent': 667,
  14132. 'scaron': 500,
  14133. 'scedilla': 500,
  14134. 'iacute': 278,
  14135. 'lozenge': 471,
  14136. 'Rcaron': 722,
  14137. 'Gcommaaccent': 778,
  14138. 'ucircumflex': 556,
  14139. 'acircumflex': 556,
  14140. 'Amacron': 667,
  14141. 'rcaron': 333,
  14142. 'ccedilla': 500,
  14143. 'Zdotaccent': 611,
  14144. 'Thorn': 667,
  14145. 'Omacron': 778,
  14146. 'Racute': 722,
  14147. 'Sacute': 667,
  14148. 'dcaron': 643,
  14149. 'Umacron': 722,
  14150. 'uring': 556,
  14151. 'threesuperior': 333,
  14152. 'Ograve': 778,
  14153. 'Agrave': 667,
  14154. 'Abreve': 667,
  14155. 'multiply': 584,
  14156. 'uacute': 556,
  14157. 'Tcaron': 611,
  14158. 'partialdiff': 476,
  14159. 'ydieresis': 500,
  14160. 'Nacute': 722,
  14161. 'icircumflex': 278,
  14162. 'Ecircumflex': 667,
  14163. 'adieresis': 556,
  14164. 'edieresis': 556,
  14165. 'cacute': 500,
  14166. 'nacute': 556,
  14167. 'umacron': 556,
  14168. 'Ncaron': 722,
  14169. 'Iacute': 278,
  14170. 'plusminus': 584,
  14171. 'brokenbar': 260,
  14172. 'registered': 737,
  14173. 'Gbreve': 778,
  14174. 'Idotaccent': 278,
  14175. 'summation': 600,
  14176. 'Egrave': 667,
  14177. 'racute': 333,
  14178. 'omacron': 556,
  14179. 'Zacute': 611,
  14180. 'Zcaron': 611,
  14181. 'greaterequal': 549,
  14182. 'Eth': 722,
  14183. 'Ccedilla': 722,
  14184. 'lcommaaccent': 222,
  14185. 'tcaron': 317,
  14186. 'eogonek': 556,
  14187. 'Uogonek': 722,
  14188. 'Aacute': 667,
  14189. 'Adieresis': 667,
  14190. 'egrave': 556,
  14191. 'zacute': 500,
  14192. 'iogonek': 222,
  14193. 'Oacute': 778,
  14194. 'oacute': 556,
  14195. 'amacron': 556,
  14196. 'sacute': 500,
  14197. 'idieresis': 278,
  14198. 'Ocircumflex': 778,
  14199. 'Ugrave': 722,
  14200. 'Delta': 612,
  14201. 'thorn': 556,
  14202. 'twosuperior': 333,
  14203. 'Odieresis': 778,
  14204. 'mu': 556,
  14205. 'igrave': 278,
  14206. 'ohungarumlaut': 556,
  14207. 'Eogonek': 667,
  14208. 'dcroat': 556,
  14209. 'threequarters': 834,
  14210. 'Scedilla': 667,
  14211. 'lcaron': 299,
  14212. 'Kcommaaccent': 667,
  14213. 'Lacute': 556,
  14214. 'trademark': 1000,
  14215. 'edotaccent': 556,
  14216. 'Igrave': 278,
  14217. 'Imacron': 278,
  14218. 'Lcaron': 556,
  14219. 'onehalf': 834,
  14220. 'lessequal': 549,
  14221. 'ocircumflex': 556,
  14222. 'ntilde': 556,
  14223. 'Uhungarumlaut': 722,
  14224. 'Eacute': 667,
  14225. 'emacron': 556,
  14226. 'gbreve': 556,
  14227. 'onequarter': 834,
  14228. 'Scaron': 667,
  14229. 'Scommaaccent': 667,
  14230. 'Ohungarumlaut': 778,
  14231. 'degree': 400,
  14232. 'ograve': 556,
  14233. 'Ccaron': 722,
  14234. 'ugrave': 556,
  14235. 'radical': 453,
  14236. 'Dcaron': 722,
  14237. 'rcommaaccent': 333,
  14238. 'Ntilde': 722,
  14239. 'otilde': 556,
  14240. 'Rcommaaccent': 722,
  14241. 'Lcommaaccent': 556,
  14242. 'Atilde': 667,
  14243. 'Aogonek': 667,
  14244. 'Aring': 667,
  14245. 'Otilde': 778,
  14246. 'zdotaccent': 500,
  14247. 'Ecaron': 667,
  14248. 'Iogonek': 278,
  14249. 'kcommaaccent': 500,
  14250. 'minus': 584,
  14251. 'Icircumflex': 278,
  14252. 'ncaron': 556,
  14253. 'tcommaaccent': 278,
  14254. 'logicalnot': 584,
  14255. 'odieresis': 556,
  14256. 'udieresis': 556,
  14257. 'notequal': 549,
  14258. 'gcommaaccent': 556,
  14259. 'eth': 556,
  14260. 'zcaron': 500,
  14261. 'ncommaaccent': 556,
  14262. 'onesuperior': 333,
  14263. 'imacron': 278,
  14264. 'Euro': 556
  14265. },
  14266. 'Helvetica-Bold': {
  14267. 'space': 278,
  14268. 'exclam': 333,
  14269. 'quotedbl': 474,
  14270. 'numbersign': 556,
  14271. 'dollar': 556,
  14272. 'percent': 889,
  14273. 'ampersand': 722,
  14274. 'quoteright': 278,
  14275. 'parenleft': 333,
  14276. 'parenright': 333,
  14277. 'asterisk': 389,
  14278. 'plus': 584,
  14279. 'comma': 278,
  14280. 'hyphen': 333,
  14281. 'period': 278,
  14282. 'slash': 278,
  14283. 'zero': 556,
  14284. 'one': 556,
  14285. 'two': 556,
  14286. 'three': 556,
  14287. 'four': 556,
  14288. 'five': 556,
  14289. 'six': 556,
  14290. 'seven': 556,
  14291. 'eight': 556,
  14292. 'nine': 556,
  14293. 'colon': 333,
  14294. 'semicolon': 333,
  14295. 'less': 584,
  14296. 'equal': 584,
  14297. 'greater': 584,
  14298. 'question': 611,
  14299. 'at': 975,
  14300. 'A': 722,
  14301. 'B': 722,
  14302. 'C': 722,
  14303. 'D': 722,
  14304. 'E': 667,
  14305. 'F': 611,
  14306. 'G': 778,
  14307. 'H': 722,
  14308. 'I': 278,
  14309. 'J': 556,
  14310. 'K': 722,
  14311. 'L': 611,
  14312. 'M': 833,
  14313. 'N': 722,
  14314. 'O': 778,
  14315. 'P': 667,
  14316. 'Q': 778,
  14317. 'R': 722,
  14318. 'S': 667,
  14319. 'T': 611,
  14320. 'U': 722,
  14321. 'V': 667,
  14322. 'W': 944,
  14323. 'X': 667,
  14324. 'Y': 667,
  14325. 'Z': 611,
  14326. 'bracketleft': 333,
  14327. 'backslash': 278,
  14328. 'bracketright': 333,
  14329. 'asciicircum': 584,
  14330. 'underscore': 556,
  14331. 'quoteleft': 278,
  14332. 'a': 556,
  14333. 'b': 611,
  14334. 'c': 556,
  14335. 'd': 611,
  14336. 'e': 556,
  14337. 'f': 333,
  14338. 'g': 611,
  14339. 'h': 611,
  14340. 'i': 278,
  14341. 'j': 278,
  14342. 'k': 556,
  14343. 'l': 278,
  14344. 'm': 889,
  14345. 'n': 611,
  14346. 'o': 611,
  14347. 'p': 611,
  14348. 'q': 611,
  14349. 'r': 389,
  14350. 's': 556,
  14351. 't': 333,
  14352. 'u': 611,
  14353. 'v': 556,
  14354. 'w': 778,
  14355. 'x': 556,
  14356. 'y': 556,
  14357. 'z': 500,
  14358. 'braceleft': 389,
  14359. 'bar': 280,
  14360. 'braceright': 389,
  14361. 'asciitilde': 584,
  14362. 'exclamdown': 333,
  14363. 'cent': 556,
  14364. 'sterling': 556,
  14365. 'fraction': 167,
  14366. 'yen': 556,
  14367. 'florin': 556,
  14368. 'section': 556,
  14369. 'currency': 556,
  14370. 'quotesingle': 238,
  14371. 'quotedblleft': 500,
  14372. 'guillemotleft': 556,
  14373. 'guilsinglleft': 333,
  14374. 'guilsinglright': 333,
  14375. 'fi': 611,
  14376. 'fl': 611,
  14377. 'endash': 556,
  14378. 'dagger': 556,
  14379. 'daggerdbl': 556,
  14380. 'periodcentered': 278,
  14381. 'paragraph': 556,
  14382. 'bullet': 350,
  14383. 'quotesinglbase': 278,
  14384. 'quotedblbase': 500,
  14385. 'quotedblright': 500,
  14386. 'guillemotright': 556,
  14387. 'ellipsis': 1000,
  14388. 'perthousand': 1000,
  14389. 'questiondown': 611,
  14390. 'grave': 333,
  14391. 'acute': 333,
  14392. 'circumflex': 333,
  14393. 'tilde': 333,
  14394. 'macron': 333,
  14395. 'breve': 333,
  14396. 'dotaccent': 333,
  14397. 'dieresis': 333,
  14398. 'ring': 333,
  14399. 'cedilla': 333,
  14400. 'hungarumlaut': 333,
  14401. 'ogonek': 333,
  14402. 'caron': 333,
  14403. 'emdash': 1000,
  14404. 'AE': 1000,
  14405. 'ordfeminine': 370,
  14406. 'Lslash': 611,
  14407. 'Oslash': 778,
  14408. 'OE': 1000,
  14409. 'ordmasculine': 365,
  14410. 'ae': 889,
  14411. 'dotlessi': 278,
  14412. 'lslash': 278,
  14413. 'oslash': 611,
  14414. 'oe': 944,
  14415. 'germandbls': 611,
  14416. 'Idieresis': 278,
  14417. 'eacute': 556,
  14418. 'abreve': 556,
  14419. 'uhungarumlaut': 611,
  14420. 'ecaron': 556,
  14421. 'Ydieresis': 667,
  14422. 'divide': 584,
  14423. 'Yacute': 667,
  14424. 'Acircumflex': 722,
  14425. 'aacute': 556,
  14426. 'Ucircumflex': 722,
  14427. 'yacute': 556,
  14428. 'scommaaccent': 556,
  14429. 'ecircumflex': 556,
  14430. 'Uring': 722,
  14431. 'Udieresis': 722,
  14432. 'aogonek': 556,
  14433. 'Uacute': 722,
  14434. 'uogonek': 611,
  14435. 'Edieresis': 667,
  14436. 'Dcroat': 722,
  14437. 'commaaccent': 250,
  14438. 'copyright': 737,
  14439. 'Emacron': 667,
  14440. 'ccaron': 556,
  14441. 'aring': 556,
  14442. 'Ncommaaccent': 722,
  14443. 'lacute': 278,
  14444. 'agrave': 556,
  14445. 'Tcommaaccent': 611,
  14446. 'Cacute': 722,
  14447. 'atilde': 556,
  14448. 'Edotaccent': 667,
  14449. 'scaron': 556,
  14450. 'scedilla': 556,
  14451. 'iacute': 278,
  14452. 'lozenge': 494,
  14453. 'Rcaron': 722,
  14454. 'Gcommaaccent': 778,
  14455. 'ucircumflex': 611,
  14456. 'acircumflex': 556,
  14457. 'Amacron': 722,
  14458. 'rcaron': 389,
  14459. 'ccedilla': 556,
  14460. 'Zdotaccent': 611,
  14461. 'Thorn': 667,
  14462. 'Omacron': 778,
  14463. 'Racute': 722,
  14464. 'Sacute': 667,
  14465. 'dcaron': 743,
  14466. 'Umacron': 722,
  14467. 'uring': 611,
  14468. 'threesuperior': 333,
  14469. 'Ograve': 778,
  14470. 'Agrave': 722,
  14471. 'Abreve': 722,
  14472. 'multiply': 584,
  14473. 'uacute': 611,
  14474. 'Tcaron': 611,
  14475. 'partialdiff': 494,
  14476. 'ydieresis': 556,
  14477. 'Nacute': 722,
  14478. 'icircumflex': 278,
  14479. 'Ecircumflex': 667,
  14480. 'adieresis': 556,
  14481. 'edieresis': 556,
  14482. 'cacute': 556,
  14483. 'nacute': 611,
  14484. 'umacron': 611,
  14485. 'Ncaron': 722,
  14486. 'Iacute': 278,
  14487. 'plusminus': 584,
  14488. 'brokenbar': 280,
  14489. 'registered': 737,
  14490. 'Gbreve': 778,
  14491. 'Idotaccent': 278,
  14492. 'summation': 600,
  14493. 'Egrave': 667,
  14494. 'racute': 389,
  14495. 'omacron': 611,
  14496. 'Zacute': 611,
  14497. 'Zcaron': 611,
  14498. 'greaterequal': 549,
  14499. 'Eth': 722,
  14500. 'Ccedilla': 722,
  14501. 'lcommaaccent': 278,
  14502. 'tcaron': 389,
  14503. 'eogonek': 556,
  14504. 'Uogonek': 722,
  14505. 'Aacute': 722,
  14506. 'Adieresis': 722,
  14507. 'egrave': 556,
  14508. 'zacute': 500,
  14509. 'iogonek': 278,
  14510. 'Oacute': 778,
  14511. 'oacute': 611,
  14512. 'amacron': 556,
  14513. 'sacute': 556,
  14514. 'idieresis': 278,
  14515. 'Ocircumflex': 778,
  14516. 'Ugrave': 722,
  14517. 'Delta': 612,
  14518. 'thorn': 611,
  14519. 'twosuperior': 333,
  14520. 'Odieresis': 778,
  14521. 'mu': 611,
  14522. 'igrave': 278,
  14523. 'ohungarumlaut': 611,
  14524. 'Eogonek': 667,
  14525. 'dcroat': 611,
  14526. 'threequarters': 834,
  14527. 'Scedilla': 667,
  14528. 'lcaron': 400,
  14529. 'Kcommaaccent': 722,
  14530. 'Lacute': 611,
  14531. 'trademark': 1000,
  14532. 'edotaccent': 556,
  14533. 'Igrave': 278,
  14534. 'Imacron': 278,
  14535. 'Lcaron': 611,
  14536. 'onehalf': 834,
  14537. 'lessequal': 549,
  14538. 'ocircumflex': 611,
  14539. 'ntilde': 611,
  14540. 'Uhungarumlaut': 722,
  14541. 'Eacute': 667,
  14542. 'emacron': 556,
  14543. 'gbreve': 611,
  14544. 'onequarter': 834,
  14545. 'Scaron': 667,
  14546. 'Scommaaccent': 667,
  14547. 'Ohungarumlaut': 778,
  14548. 'degree': 400,
  14549. 'ograve': 611,
  14550. 'Ccaron': 722,
  14551. 'ugrave': 611,
  14552. 'radical': 549,
  14553. 'Dcaron': 722,
  14554. 'rcommaaccent': 389,
  14555. 'Ntilde': 722,
  14556. 'otilde': 611,
  14557. 'Rcommaaccent': 722,
  14558. 'Lcommaaccent': 611,
  14559. 'Atilde': 722,
  14560. 'Aogonek': 722,
  14561. 'Aring': 722,
  14562. 'Otilde': 778,
  14563. 'zdotaccent': 500,
  14564. 'Ecaron': 667,
  14565. 'Iogonek': 278,
  14566. 'kcommaaccent': 556,
  14567. 'minus': 584,
  14568. 'Icircumflex': 278,
  14569. 'ncaron': 611,
  14570. 'tcommaaccent': 333,
  14571. 'logicalnot': 584,
  14572. 'odieresis': 611,
  14573. 'udieresis': 611,
  14574. 'notequal': 549,
  14575. 'gcommaaccent': 611,
  14576. 'eth': 611,
  14577. 'zcaron': 500,
  14578. 'ncommaaccent': 611,
  14579. 'onesuperior': 333,
  14580. 'imacron': 278,
  14581. 'Euro': 556
  14582. },
  14583. 'Helvetica-BoldOblique': {
  14584. 'space': 278,
  14585. 'exclam': 333,
  14586. 'quotedbl': 474,
  14587. 'numbersign': 556,
  14588. 'dollar': 556,
  14589. 'percent': 889,
  14590. 'ampersand': 722,
  14591. 'quoteright': 278,
  14592. 'parenleft': 333,
  14593. 'parenright': 333,
  14594. 'asterisk': 389,
  14595. 'plus': 584,
  14596. 'comma': 278,
  14597. 'hyphen': 333,
  14598. 'period': 278,
  14599. 'slash': 278,
  14600. 'zero': 556,
  14601. 'one': 556,
  14602. 'two': 556,
  14603. 'three': 556,
  14604. 'four': 556,
  14605. 'five': 556,
  14606. 'six': 556,
  14607. 'seven': 556,
  14608. 'eight': 556,
  14609. 'nine': 556,
  14610. 'colon': 333,
  14611. 'semicolon': 333,
  14612. 'less': 584,
  14613. 'equal': 584,
  14614. 'greater': 584,
  14615. 'question': 611,
  14616. 'at': 975,
  14617. 'A': 722,
  14618. 'B': 722,
  14619. 'C': 722,
  14620. 'D': 722,
  14621. 'E': 667,
  14622. 'F': 611,
  14623. 'G': 778,
  14624. 'H': 722,
  14625. 'I': 278,
  14626. 'J': 556,
  14627. 'K': 722,
  14628. 'L': 611,
  14629. 'M': 833,
  14630. 'N': 722,
  14631. 'O': 778,
  14632. 'P': 667,
  14633. 'Q': 778,
  14634. 'R': 722,
  14635. 'S': 667,
  14636. 'T': 611,
  14637. 'U': 722,
  14638. 'V': 667,
  14639. 'W': 944,
  14640. 'X': 667,
  14641. 'Y': 667,
  14642. 'Z': 611,
  14643. 'bracketleft': 333,
  14644. 'backslash': 278,
  14645. 'bracketright': 333,
  14646. 'asciicircum': 584,
  14647. 'underscore': 556,
  14648. 'quoteleft': 278,
  14649. 'a': 556,
  14650. 'b': 611,
  14651. 'c': 556,
  14652. 'd': 611,
  14653. 'e': 556,
  14654. 'f': 333,
  14655. 'g': 611,
  14656. 'h': 611,
  14657. 'i': 278,
  14658. 'j': 278,
  14659. 'k': 556,
  14660. 'l': 278,
  14661. 'm': 889,
  14662. 'n': 611,
  14663. 'o': 611,
  14664. 'p': 611,
  14665. 'q': 611,
  14666. 'r': 389,
  14667. 's': 556,
  14668. 't': 333,
  14669. 'u': 611,
  14670. 'v': 556,
  14671. 'w': 778,
  14672. 'x': 556,
  14673. 'y': 556,
  14674. 'z': 500,
  14675. 'braceleft': 389,
  14676. 'bar': 280,
  14677. 'braceright': 389,
  14678. 'asciitilde': 584,
  14679. 'exclamdown': 333,
  14680. 'cent': 556,
  14681. 'sterling': 556,
  14682. 'fraction': 167,
  14683. 'yen': 556,
  14684. 'florin': 556,
  14685. 'section': 556,
  14686. 'currency': 556,
  14687. 'quotesingle': 238,
  14688. 'quotedblleft': 500,
  14689. 'guillemotleft': 556,
  14690. 'guilsinglleft': 333,
  14691. 'guilsinglright': 333,
  14692. 'fi': 611,
  14693. 'fl': 611,
  14694. 'endash': 556,
  14695. 'dagger': 556,
  14696. 'daggerdbl': 556,
  14697. 'periodcentered': 278,
  14698. 'paragraph': 556,
  14699. 'bullet': 350,
  14700. 'quotesinglbase': 278,
  14701. 'quotedblbase': 500,
  14702. 'quotedblright': 500,
  14703. 'guillemotright': 556,
  14704. 'ellipsis': 1000,
  14705. 'perthousand': 1000,
  14706. 'questiondown': 611,
  14707. 'grave': 333,
  14708. 'acute': 333,
  14709. 'circumflex': 333,
  14710. 'tilde': 333,
  14711. 'macron': 333,
  14712. 'breve': 333,
  14713. 'dotaccent': 333,
  14714. 'dieresis': 333,
  14715. 'ring': 333,
  14716. 'cedilla': 333,
  14717. 'hungarumlaut': 333,
  14718. 'ogonek': 333,
  14719. 'caron': 333,
  14720. 'emdash': 1000,
  14721. 'AE': 1000,
  14722. 'ordfeminine': 370,
  14723. 'Lslash': 611,
  14724. 'Oslash': 778,
  14725. 'OE': 1000,
  14726. 'ordmasculine': 365,
  14727. 'ae': 889,
  14728. 'dotlessi': 278,
  14729. 'lslash': 278,
  14730. 'oslash': 611,
  14731. 'oe': 944,
  14732. 'germandbls': 611,
  14733. 'Idieresis': 278,
  14734. 'eacute': 556,
  14735. 'abreve': 556,
  14736. 'uhungarumlaut': 611,
  14737. 'ecaron': 556,
  14738. 'Ydieresis': 667,
  14739. 'divide': 584,
  14740. 'Yacute': 667,
  14741. 'Acircumflex': 722,
  14742. 'aacute': 556,
  14743. 'Ucircumflex': 722,
  14744. 'yacute': 556,
  14745. 'scommaaccent': 556,
  14746. 'ecircumflex': 556,
  14747. 'Uring': 722,
  14748. 'Udieresis': 722,
  14749. 'aogonek': 556,
  14750. 'Uacute': 722,
  14751. 'uogonek': 611,
  14752. 'Edieresis': 667,
  14753. 'Dcroat': 722,
  14754. 'commaaccent': 250,
  14755. 'copyright': 737,
  14756. 'Emacron': 667,
  14757. 'ccaron': 556,
  14758. 'aring': 556,
  14759. 'Ncommaaccent': 722,
  14760. 'lacute': 278,
  14761. 'agrave': 556,
  14762. 'Tcommaaccent': 611,
  14763. 'Cacute': 722,
  14764. 'atilde': 556,
  14765. 'Edotaccent': 667,
  14766. 'scaron': 556,
  14767. 'scedilla': 556,
  14768. 'iacute': 278,
  14769. 'lozenge': 494,
  14770. 'Rcaron': 722,
  14771. 'Gcommaaccent': 778,
  14772. 'ucircumflex': 611,
  14773. 'acircumflex': 556,
  14774. 'Amacron': 722,
  14775. 'rcaron': 389,
  14776. 'ccedilla': 556,
  14777. 'Zdotaccent': 611,
  14778. 'Thorn': 667,
  14779. 'Omacron': 778,
  14780. 'Racute': 722,
  14781. 'Sacute': 667,
  14782. 'dcaron': 743,
  14783. 'Umacron': 722,
  14784. 'uring': 611,
  14785. 'threesuperior': 333,
  14786. 'Ograve': 778,
  14787. 'Agrave': 722,
  14788. 'Abreve': 722,
  14789. 'multiply': 584,
  14790. 'uacute': 611,
  14791. 'Tcaron': 611,
  14792. 'partialdiff': 494,
  14793. 'ydieresis': 556,
  14794. 'Nacute': 722,
  14795. 'icircumflex': 278,
  14796. 'Ecircumflex': 667,
  14797. 'adieresis': 556,
  14798. 'edieresis': 556,
  14799. 'cacute': 556,
  14800. 'nacute': 611,
  14801. 'umacron': 611,
  14802. 'Ncaron': 722,
  14803. 'Iacute': 278,
  14804. 'plusminus': 584,
  14805. 'brokenbar': 280,
  14806. 'registered': 737,
  14807. 'Gbreve': 778,
  14808. 'Idotaccent': 278,
  14809. 'summation': 600,
  14810. 'Egrave': 667,
  14811. 'racute': 389,
  14812. 'omacron': 611,
  14813. 'Zacute': 611,
  14814. 'Zcaron': 611,
  14815. 'greaterequal': 549,
  14816. 'Eth': 722,
  14817. 'Ccedilla': 722,
  14818. 'lcommaaccent': 278,
  14819. 'tcaron': 389,
  14820. 'eogonek': 556,
  14821. 'Uogonek': 722,
  14822. 'Aacute': 722,
  14823. 'Adieresis': 722,
  14824. 'egrave': 556,
  14825. 'zacute': 500,
  14826. 'iogonek': 278,
  14827. 'Oacute': 778,
  14828. 'oacute': 611,
  14829. 'amacron': 556,
  14830. 'sacute': 556,
  14831. 'idieresis': 278,
  14832. 'Ocircumflex': 778,
  14833. 'Ugrave': 722,
  14834. 'Delta': 612,
  14835. 'thorn': 611,
  14836. 'twosuperior': 333,
  14837. 'Odieresis': 778,
  14838. 'mu': 611,
  14839. 'igrave': 278,
  14840. 'ohungarumlaut': 611,
  14841. 'Eogonek': 667,
  14842. 'dcroat': 611,
  14843. 'threequarters': 834,
  14844. 'Scedilla': 667,
  14845. 'lcaron': 400,
  14846. 'Kcommaaccent': 722,
  14847. 'Lacute': 611,
  14848. 'trademark': 1000,
  14849. 'edotaccent': 556,
  14850. 'Igrave': 278,
  14851. 'Imacron': 278,
  14852. 'Lcaron': 611,
  14853. 'onehalf': 834,
  14854. 'lessequal': 549,
  14855. 'ocircumflex': 611,
  14856. 'ntilde': 611,
  14857. 'Uhungarumlaut': 722,
  14858. 'Eacute': 667,
  14859. 'emacron': 556,
  14860. 'gbreve': 611,
  14861. 'onequarter': 834,
  14862. 'Scaron': 667,
  14863. 'Scommaaccent': 667,
  14864. 'Ohungarumlaut': 778,
  14865. 'degree': 400,
  14866. 'ograve': 611,
  14867. 'Ccaron': 722,
  14868. 'ugrave': 611,
  14869. 'radical': 549,
  14870. 'Dcaron': 722,
  14871. 'rcommaaccent': 389,
  14872. 'Ntilde': 722,
  14873. 'otilde': 611,
  14874. 'Rcommaaccent': 722,
  14875. 'Lcommaaccent': 611,
  14876. 'Atilde': 722,
  14877. 'Aogonek': 722,
  14878. 'Aring': 722,
  14879. 'Otilde': 778,
  14880. 'zdotaccent': 500,
  14881. 'Ecaron': 667,
  14882. 'Iogonek': 278,
  14883. 'kcommaaccent': 556,
  14884. 'minus': 584,
  14885. 'Icircumflex': 278,
  14886. 'ncaron': 611,
  14887. 'tcommaaccent': 333,
  14888. 'logicalnot': 584,
  14889. 'odieresis': 611,
  14890. 'udieresis': 611,
  14891. 'notequal': 549,
  14892. 'gcommaaccent': 611,
  14893. 'eth': 611,
  14894. 'zcaron': 500,
  14895. 'ncommaaccent': 611,
  14896. 'onesuperior': 333,
  14897. 'imacron': 278,
  14898. 'Euro': 556
  14899. },
  14900. 'Helvetica-Oblique' : {
  14901. 'space': 278,
  14902. 'exclam': 278,
  14903. 'quotedbl': 355,
  14904. 'numbersign': 556,
  14905. 'dollar': 556,
  14906. 'percent': 889,
  14907. 'ampersand': 667,
  14908. 'quoteright': 222,
  14909. 'parenleft': 333,
  14910. 'parenright': 333,
  14911. 'asterisk': 389,
  14912. 'plus': 584,
  14913. 'comma': 278,
  14914. 'hyphen': 333,
  14915. 'period': 278,
  14916. 'slash': 278,
  14917. 'zero': 556,
  14918. 'one': 556,
  14919. 'two': 556,
  14920. 'three': 556,
  14921. 'four': 556,
  14922. 'five': 556,
  14923. 'six': 556,
  14924. 'seven': 556,
  14925. 'eight': 556,
  14926. 'nine': 556,
  14927. 'colon': 278,
  14928. 'semicolon': 278,
  14929. 'less': 584,
  14930. 'equal': 584,
  14931. 'greater': 584,
  14932. 'question': 556,
  14933. 'at': 1015,
  14934. 'A': 667,
  14935. 'B': 667,
  14936. 'C': 722,
  14937. 'D': 722,
  14938. 'E': 667,
  14939. 'F': 611,
  14940. 'G': 778,
  14941. 'H': 722,
  14942. 'I': 278,
  14943. 'J': 500,
  14944. 'K': 667,
  14945. 'L': 556,
  14946. 'M': 833,
  14947. 'N': 722,
  14948. 'O': 778,
  14949. 'P': 667,
  14950. 'Q': 778,
  14951. 'R': 722,
  14952. 'S': 667,
  14953. 'T': 611,
  14954. 'U': 722,
  14955. 'V': 667,
  14956. 'W': 944,
  14957. 'X': 667,
  14958. 'Y': 667,
  14959. 'Z': 611,
  14960. 'bracketleft': 278,
  14961. 'backslash': 278,
  14962. 'bracketright': 278,
  14963. 'asciicircum': 469,
  14964. 'underscore': 556,
  14965. 'quoteleft': 222,
  14966. 'a': 556,
  14967. 'b': 556,
  14968. 'c': 500,
  14969. 'd': 556,
  14970. 'e': 556,
  14971. 'f': 278,
  14972. 'g': 556,
  14973. 'h': 556,
  14974. 'i': 222,
  14975. 'j': 222,
  14976. 'k': 500,
  14977. 'l': 222,
  14978. 'm': 833,
  14979. 'n': 556,
  14980. 'o': 556,
  14981. 'p': 556,
  14982. 'q': 556,
  14983. 'r': 333,
  14984. 's': 500,
  14985. 't': 278,
  14986. 'u': 556,
  14987. 'v': 500,
  14988. 'w': 722,
  14989. 'x': 500,
  14990. 'y': 500,
  14991. 'z': 500,
  14992. 'braceleft': 334,
  14993. 'bar': 260,
  14994. 'braceright': 334,
  14995. 'asciitilde': 584,
  14996. 'exclamdown': 333,
  14997. 'cent': 556,
  14998. 'sterling': 556,
  14999. 'fraction': 167,
  15000. 'yen': 556,
  15001. 'florin': 556,
  15002. 'section': 556,
  15003. 'currency': 556,
  15004. 'quotesingle': 191,
  15005. 'quotedblleft': 333,
  15006. 'guillemotleft': 556,
  15007. 'guilsinglleft': 333,
  15008. 'guilsinglright': 333,
  15009. 'fi': 500,
  15010. 'fl': 500,
  15011. 'endash': 556,
  15012. 'dagger': 556,
  15013. 'daggerdbl': 556,
  15014. 'periodcentered': 278,
  15015. 'paragraph': 537,
  15016. 'bullet': 350,
  15017. 'quotesinglbase': 222,
  15018. 'quotedblbase': 333,
  15019. 'quotedblright': 333,
  15020. 'guillemotright': 556,
  15021. 'ellipsis': 1000,
  15022. 'perthousand': 1000,
  15023. 'questiondown': 611,
  15024. 'grave': 333,
  15025. 'acute': 333,
  15026. 'circumflex': 333,
  15027. 'tilde': 333,
  15028. 'macron': 333,
  15029. 'breve': 333,
  15030. 'dotaccent': 333,
  15031. 'dieresis': 333,
  15032. 'ring': 333,
  15033. 'cedilla': 333,
  15034. 'hungarumlaut': 333,
  15035. 'ogonek': 333,
  15036. 'caron': 333,
  15037. 'emdash': 1000,
  15038. 'AE': 1000,
  15039. 'ordfeminine': 370,
  15040. 'Lslash': 556,
  15041. 'Oslash': 778,
  15042. 'OE': 1000,
  15043. 'ordmasculine': 365,
  15044. 'ae': 889,
  15045. 'dotlessi': 278,
  15046. 'lslash': 222,
  15047. 'oslash': 611,
  15048. 'oe': 944,
  15049. 'germandbls': 611,
  15050. 'Idieresis': 278,
  15051. 'eacute': 556,
  15052. 'abreve': 556,
  15053. 'uhungarumlaut': 556,
  15054. 'ecaron': 556,
  15055. 'Ydieresis': 667,
  15056. 'divide': 584,
  15057. 'Yacute': 667,
  15058. 'Acircumflex': 667,
  15059. 'aacute': 556,
  15060. 'Ucircumflex': 722,
  15061. 'yacute': 500,
  15062. 'scommaaccent': 500,
  15063. 'ecircumflex': 556,
  15064. 'Uring': 722,
  15065. 'Udieresis': 722,
  15066. 'aogonek': 556,
  15067. 'Uacute': 722,
  15068. 'uogonek': 556,
  15069. 'Edieresis': 667,
  15070. 'Dcroat': 722,
  15071. 'commaaccent': 250,
  15072. 'copyright': 737,
  15073. 'Emacron': 667,
  15074. 'ccaron': 500,
  15075. 'aring': 556,
  15076. 'Ncommaaccent': 722,
  15077. 'lacute': 222,
  15078. 'agrave': 556,
  15079. 'Tcommaaccent': 611,
  15080. 'Cacute': 722,
  15081. 'atilde': 556,
  15082. 'Edotaccent': 667,
  15083. 'scaron': 500,
  15084. 'scedilla': 500,
  15085. 'iacute': 278,
  15086. 'lozenge': 471,
  15087. 'Rcaron': 722,
  15088. 'Gcommaaccent': 778,
  15089. 'ucircumflex': 556,
  15090. 'acircumflex': 556,
  15091. 'Amacron': 667,
  15092. 'rcaron': 333,
  15093. 'ccedilla': 500,
  15094. 'Zdotaccent': 611,
  15095. 'Thorn': 667,
  15096. 'Omacron': 778,
  15097. 'Racute': 722,
  15098. 'Sacute': 667,
  15099. 'dcaron': 643,
  15100. 'Umacron': 722,
  15101. 'uring': 556,
  15102. 'threesuperior': 333,
  15103. 'Ograve': 778,
  15104. 'Agrave': 667,
  15105. 'Abreve': 667,
  15106. 'multiply': 584,
  15107. 'uacute': 556,
  15108. 'Tcaron': 611,
  15109. 'partialdiff': 476,
  15110. 'ydieresis': 500,
  15111. 'Nacute': 722,
  15112. 'icircumflex': 278,
  15113. 'Ecircumflex': 667,
  15114. 'adieresis': 556,
  15115. 'edieresis': 556,
  15116. 'cacute': 500,
  15117. 'nacute': 556,
  15118. 'umacron': 556,
  15119. 'Ncaron': 722,
  15120. 'Iacute': 278,
  15121. 'plusminus': 584,
  15122. 'brokenbar': 260,
  15123. 'registered': 737,
  15124. 'Gbreve': 778,
  15125. 'Idotaccent': 278,
  15126. 'summation': 600,
  15127. 'Egrave': 667,
  15128. 'racute': 333,
  15129. 'omacron': 556,
  15130. 'Zacute': 611,
  15131. 'Zcaron': 611,
  15132. 'greaterequal': 549,
  15133. 'Eth': 722,
  15134. 'Ccedilla': 722,
  15135. 'lcommaaccent': 222,
  15136. 'tcaron': 317,
  15137. 'eogonek': 556,
  15138. 'Uogonek': 722,
  15139. 'Aacute': 667,
  15140. 'Adieresis': 667,
  15141. 'egrave': 556,
  15142. 'zacute': 500,
  15143. 'iogonek': 222,
  15144. 'Oacute': 778,
  15145. 'oacute': 556,
  15146. 'amacron': 556,
  15147. 'sacute': 500,
  15148. 'idieresis': 278,
  15149. 'Ocircumflex': 778,
  15150. 'Ugrave': 722,
  15151. 'Delta': 612,
  15152. 'thorn': 556,
  15153. 'twosuperior': 333,
  15154. 'Odieresis': 778,
  15155. 'mu': 556,
  15156. 'igrave': 278,
  15157. 'ohungarumlaut': 556,
  15158. 'Eogonek': 667,
  15159. 'dcroat': 556,
  15160. 'threequarters': 834,
  15161. 'Scedilla': 667,
  15162. 'lcaron': 299,
  15163. 'Kcommaaccent': 667,
  15164. 'Lacute': 556,
  15165. 'trademark': 1000,
  15166. 'edotaccent': 556,
  15167. 'Igrave': 278,
  15168. 'Imacron': 278,
  15169. 'Lcaron': 556,
  15170. 'onehalf': 834,
  15171. 'lessequal': 549,
  15172. 'ocircumflex': 556,
  15173. 'ntilde': 556,
  15174. 'Uhungarumlaut': 722,
  15175. 'Eacute': 667,
  15176. 'emacron': 556,
  15177. 'gbreve': 556,
  15178. 'onequarter': 834,
  15179. 'Scaron': 667,
  15180. 'Scommaaccent': 667,
  15181. 'Ohungarumlaut': 778,
  15182. 'degree': 400,
  15183. 'ograve': 556,
  15184. 'Ccaron': 722,
  15185. 'ugrave': 556,
  15186. 'radical': 453,
  15187. 'Dcaron': 722,
  15188. 'rcommaaccent': 333,
  15189. 'Ntilde': 722,
  15190. 'otilde': 556,
  15191. 'Rcommaaccent': 722,
  15192. 'Lcommaaccent': 556,
  15193. 'Atilde': 667,
  15194. 'Aogonek': 667,
  15195. 'Aring': 667,
  15196. 'Otilde': 778,
  15197. 'zdotaccent': 500,
  15198. 'Ecaron': 667,
  15199. 'Iogonek': 278,
  15200. 'kcommaaccent': 500,
  15201. 'minus': 584,
  15202. 'Icircumflex': 278,
  15203. 'ncaron': 556,
  15204. 'tcommaaccent': 278,
  15205. 'logicalnot': 584,
  15206. 'odieresis': 556,
  15207. 'udieresis': 556,
  15208. 'notequal': 549,
  15209. 'gcommaaccent': 556,
  15210. 'eth': 556,
  15211. 'zcaron': 500,
  15212. 'ncommaaccent': 556,
  15213. 'onesuperior': 333,
  15214. 'imacron': 278,
  15215. 'Euro': 556
  15216. },
  15217. 'Symbol': {
  15218. 'space': 250,
  15219. 'exclam': 333,
  15220. 'universal': 713,
  15221. 'numbersign': 500,
  15222. 'existential': 549,
  15223. 'percent': 833,
  15224. 'ampersand': 778,
  15225. 'suchthat': 439,
  15226. 'parenleft': 333,
  15227. 'parenright': 333,
  15228. 'asteriskmath': 500,
  15229. 'plus': 549,
  15230. 'comma': 250,
  15231. 'minus': 549,
  15232. 'period': 250,
  15233. 'slash': 278,
  15234. 'zero': 500,
  15235. 'one': 500,
  15236. 'two': 500,
  15237. 'three': 500,
  15238. 'four': 500,
  15239. 'five': 500,
  15240. 'six': 500,
  15241. 'seven': 500,
  15242. 'eight': 500,
  15243. 'nine': 500,
  15244. 'colon': 278,
  15245. 'semicolon': 278,
  15246. 'less': 549,
  15247. 'equal': 549,
  15248. 'greater': 549,
  15249. 'question': 444,
  15250. 'congruent': 549,
  15251. 'Alpha': 722,
  15252. 'Beta': 667,
  15253. 'Chi': 722,
  15254. 'Delta': 612,
  15255. 'Epsilon': 611,
  15256. 'Phi': 763,
  15257. 'Gamma': 603,
  15258. 'Eta': 722,
  15259. 'Iota': 333,
  15260. 'theta1': 631,
  15261. 'Kappa': 722,
  15262. 'Lambda': 686,
  15263. 'Mu': 889,
  15264. 'Nu': 722,
  15265. 'Omicron': 722,
  15266. 'Pi': 768,
  15267. 'Theta': 741,
  15268. 'Rho': 556,
  15269. 'Sigma': 592,
  15270. 'Tau': 611,
  15271. 'Upsilon': 690,
  15272. 'sigma1': 439,
  15273. 'Omega': 768,
  15274. 'Xi': 645,
  15275. 'Psi': 795,
  15276. 'Zeta': 611,
  15277. 'bracketleft': 333,
  15278. 'therefore': 863,
  15279. 'bracketright': 333,
  15280. 'perpendicular': 658,
  15281. 'underscore': 500,
  15282. 'radicalex': 500,
  15283. 'alpha': 631,
  15284. 'beta': 549,
  15285. 'chi': 549,
  15286. 'delta': 494,
  15287. 'epsilon': 439,
  15288. 'phi': 521,
  15289. 'gamma': 411,
  15290. 'eta': 603,
  15291. 'iota': 329,
  15292. 'phi1': 603,
  15293. 'kappa': 549,
  15294. 'lambda': 549,
  15295. 'mu': 576,
  15296. 'nu': 521,
  15297. 'omicron': 549,
  15298. 'pi': 549,
  15299. 'theta': 521,
  15300. 'rho': 549,
  15301. 'sigma': 603,
  15302. 'tau': 439,
  15303. 'upsilon': 576,
  15304. 'omega1': 713,
  15305. 'omega': 686,
  15306. 'xi': 493,
  15307. 'psi': 686,
  15308. 'zeta': 494,
  15309. 'braceleft': 480,
  15310. 'bar': 200,
  15311. 'braceright': 480,
  15312. 'similar': 549,
  15313. 'Euro': 750,
  15314. 'Upsilon1': 620,
  15315. 'minute': 247,
  15316. 'lessequal': 549,
  15317. 'fraction': 167,
  15318. 'infinity': 713,
  15319. 'florin': 500,
  15320. 'club': 753,
  15321. 'diamond': 753,
  15322. 'heart': 753,
  15323. 'spade': 753,
  15324. 'arrowboth': 1042,
  15325. 'arrowleft': 987,
  15326. 'arrowup': 603,
  15327. 'arrowright': 987,
  15328. 'arrowdown': 603,
  15329. 'degree': 400,
  15330. 'plusminus': 549,
  15331. 'second': 411,
  15332. 'greaterequal': 549,
  15333. 'multiply': 549,
  15334. 'proportional': 713,
  15335. 'partialdiff': 494,
  15336. 'bullet': 460,
  15337. 'divide': 549,
  15338. 'notequal': 549,
  15339. 'equivalence': 549,
  15340. 'approxequal': 549,
  15341. 'ellipsis': 1000,
  15342. 'arrowvertex': 603,
  15343. 'arrowhorizex': 1000,
  15344. 'carriagereturn': 658,
  15345. 'aleph': 823,
  15346. 'Ifraktur': 686,
  15347. 'Rfraktur': 795,
  15348. 'weierstrass': 987,
  15349. 'circlemultiply': 768,
  15350. 'circleplus': 768,
  15351. 'emptyset': 823,
  15352. 'intersection': 768,
  15353. 'union': 768,
  15354. 'propersuperset': 713,
  15355. 'reflexsuperset': 713,
  15356. 'notsubset': 713,
  15357. 'propersubset': 713,
  15358. 'reflexsubset': 713,
  15359. 'element': 713,
  15360. 'notelement': 713,
  15361. 'angle': 768,
  15362. 'gradient': 713,
  15363. 'registerserif': 790,
  15364. 'copyrightserif': 790,
  15365. 'trademarkserif': 890,
  15366. 'product': 823,
  15367. 'radical': 549,
  15368. 'dotmath': 250,
  15369. 'logicalnot': 713,
  15370. 'logicaland': 603,
  15371. 'logicalor': 603,
  15372. 'arrowdblboth': 1042,
  15373. 'arrowdblleft': 987,
  15374. 'arrowdblup': 603,
  15375. 'arrowdblright': 987,
  15376. 'arrowdbldown': 603,
  15377. 'lozenge': 494,
  15378. 'angleleft': 329,
  15379. 'registersans': 790,
  15380. 'copyrightsans': 790,
  15381. 'trademarksans': 786,
  15382. 'summation': 713,
  15383. 'parenlefttp': 384,
  15384. 'parenleftex': 384,
  15385. 'parenleftbt': 384,
  15386. 'bracketlefttp': 384,
  15387. 'bracketleftex': 384,
  15388. 'bracketleftbt': 384,
  15389. 'bracelefttp': 494,
  15390. 'braceleftmid': 494,
  15391. 'braceleftbt': 494,
  15392. 'braceex': 494,
  15393. 'angleright': 329,
  15394. 'integral': 274,
  15395. 'integraltp': 686,
  15396. 'integralex': 686,
  15397. 'integralbt': 686,
  15398. 'parenrighttp': 384,
  15399. 'parenrightex': 384,
  15400. 'parenrightbt': 384,
  15401. 'bracketrighttp': 384,
  15402. 'bracketrightex': 384,
  15403. 'bracketrightbt': 384,
  15404. 'bracerighttp': 494,
  15405. 'bracerightmid': 494,
  15406. 'bracerightbt': 494,
  15407. 'apple': 790
  15408. },
  15409. 'Times-Roman': {
  15410. 'space': 250,
  15411. 'exclam': 333,
  15412. 'quotedbl': 408,
  15413. 'numbersign': 500,
  15414. 'dollar': 500,
  15415. 'percent': 833,
  15416. 'ampersand': 778,
  15417. 'quoteright': 333,
  15418. 'parenleft': 333,
  15419. 'parenright': 333,
  15420. 'asterisk': 500,
  15421. 'plus': 564,
  15422. 'comma': 250,
  15423. 'hyphen': 333,
  15424. 'period': 250,
  15425. 'slash': 278,
  15426. 'zero': 500,
  15427. 'one': 500,
  15428. 'two': 500,
  15429. 'three': 500,
  15430. 'four': 500,
  15431. 'five': 500,
  15432. 'six': 500,
  15433. 'seven': 500,
  15434. 'eight': 500,
  15435. 'nine': 500,
  15436. 'colon': 278,
  15437. 'semicolon': 278,
  15438. 'less': 564,
  15439. 'equal': 564,
  15440. 'greater': 564,
  15441. 'question': 444,
  15442. 'at': 921,
  15443. 'A': 722,
  15444. 'B': 667,
  15445. 'C': 667,
  15446. 'D': 722,
  15447. 'E': 611,
  15448. 'F': 556,
  15449. 'G': 722,
  15450. 'H': 722,
  15451. 'I': 333,
  15452. 'J': 389,
  15453. 'K': 722,
  15454. 'L': 611,
  15455. 'M': 889,
  15456. 'N': 722,
  15457. 'O': 722,
  15458. 'P': 556,
  15459. 'Q': 722,
  15460. 'R': 667,
  15461. 'S': 556,
  15462. 'T': 611,
  15463. 'U': 722,
  15464. 'V': 722,
  15465. 'W': 944,
  15466. 'X': 722,
  15467. 'Y': 722,
  15468. 'Z': 611,
  15469. 'bracketleft': 333,
  15470. 'backslash': 278,
  15471. 'bracketright': 333,
  15472. 'asciicircum': 469,
  15473. 'underscore': 500,
  15474. 'quoteleft': 333,
  15475. 'a': 444,
  15476. 'b': 500,
  15477. 'c': 444,
  15478. 'd': 500,
  15479. 'e': 444,
  15480. 'f': 333,
  15481. 'g': 500,
  15482. 'h': 500,
  15483. 'i': 278,
  15484. 'j': 278,
  15485. 'k': 500,
  15486. 'l': 278,
  15487. 'm': 778,
  15488. 'n': 500,
  15489. 'o': 500,
  15490. 'p': 500,
  15491. 'q': 500,
  15492. 'r': 333,
  15493. 's': 389,
  15494. 't': 278,
  15495. 'u': 500,
  15496. 'v': 500,
  15497. 'w': 722,
  15498. 'x': 500,
  15499. 'y': 500,
  15500. 'z': 444,
  15501. 'braceleft': 480,
  15502. 'bar': 200,
  15503. 'braceright': 480,
  15504. 'asciitilde': 541,
  15505. 'exclamdown': 333,
  15506. 'cent': 500,
  15507. 'sterling': 500,
  15508. 'fraction': 167,
  15509. 'yen': 500,
  15510. 'florin': 500,
  15511. 'section': 500,
  15512. 'currency': 500,
  15513. 'quotesingle': 180,
  15514. 'quotedblleft': 444,
  15515. 'guillemotleft': 500,
  15516. 'guilsinglleft': 333,
  15517. 'guilsinglright': 333,
  15518. 'fi': 556,
  15519. 'fl': 556,
  15520. 'endash': 500,
  15521. 'dagger': 500,
  15522. 'daggerdbl': 500,
  15523. 'periodcentered': 250,
  15524. 'paragraph': 453,
  15525. 'bullet': 350,
  15526. 'quotesinglbase': 333,
  15527. 'quotedblbase': 444,
  15528. 'quotedblright': 444,
  15529. 'guillemotright': 500,
  15530. 'ellipsis': 1000,
  15531. 'perthousand': 1000,
  15532. 'questiondown': 444,
  15533. 'grave': 333,
  15534. 'acute': 333,
  15535. 'circumflex': 333,
  15536. 'tilde': 333,
  15537. 'macron': 333,
  15538. 'breve': 333,
  15539. 'dotaccent': 333,
  15540. 'dieresis': 333,
  15541. 'ring': 333,
  15542. 'cedilla': 333,
  15543. 'hungarumlaut': 333,
  15544. 'ogonek': 333,
  15545. 'caron': 333,
  15546. 'emdash': 1000,
  15547. 'AE': 889,
  15548. 'ordfeminine': 276,
  15549. 'Lslash': 611,
  15550. 'Oslash': 722,
  15551. 'OE': 889,
  15552. 'ordmasculine': 310,
  15553. 'ae': 667,
  15554. 'dotlessi': 278,
  15555. 'lslash': 278,
  15556. 'oslash': 500,
  15557. 'oe': 722,
  15558. 'germandbls': 500,
  15559. 'Idieresis': 333,
  15560. 'eacute': 444,
  15561. 'abreve': 444,
  15562. 'uhungarumlaut': 500,
  15563. 'ecaron': 444,
  15564. 'Ydieresis': 722,
  15565. 'divide': 564,
  15566. 'Yacute': 722,
  15567. 'Acircumflex': 722,
  15568. 'aacute': 444,
  15569. 'Ucircumflex': 722,
  15570. 'yacute': 500,
  15571. 'scommaaccent': 389,
  15572. 'ecircumflex': 444,
  15573. 'Uring': 722,
  15574. 'Udieresis': 722,
  15575. 'aogonek': 444,
  15576. 'Uacute': 722,
  15577. 'uogonek': 500,
  15578. 'Edieresis': 611,
  15579. 'Dcroat': 722,
  15580. 'commaaccent': 250,
  15581. 'copyright': 760,
  15582. 'Emacron': 611,
  15583. 'ccaron': 444,
  15584. 'aring': 444,
  15585. 'Ncommaaccent': 722,
  15586. 'lacute': 278,
  15587. 'agrave': 444,
  15588. 'Tcommaaccent': 611,
  15589. 'Cacute': 667,
  15590. 'atilde': 444,
  15591. 'Edotaccent': 611,
  15592. 'scaron': 389,
  15593. 'scedilla': 389,
  15594. 'iacute': 278,
  15595. 'lozenge': 471,
  15596. 'Rcaron': 667,
  15597. 'Gcommaaccent': 722,
  15598. 'ucircumflex': 500,
  15599. 'acircumflex': 444,
  15600. 'Amacron': 722,
  15601. 'rcaron': 333,
  15602. 'ccedilla': 444,
  15603. 'Zdotaccent': 611,
  15604. 'Thorn': 556,
  15605. 'Omacron': 722,
  15606. 'Racute': 667,
  15607. 'Sacute': 556,
  15608. 'dcaron': 588,
  15609. 'Umacron': 722,
  15610. 'uring': 500,
  15611. 'threesuperior': 300,
  15612. 'Ograve': 722,
  15613. 'Agrave': 722,
  15614. 'Abreve': 722,
  15615. 'multiply': 564,
  15616. 'uacute': 500,
  15617. 'Tcaron': 611,
  15618. 'partialdiff': 476,
  15619. 'ydieresis': 500,
  15620. 'Nacute': 722,
  15621. 'icircumflex': 278,
  15622. 'Ecircumflex': 611,
  15623. 'adieresis': 444,
  15624. 'edieresis': 444,
  15625. 'cacute': 444,
  15626. 'nacute': 500,
  15627. 'umacron': 500,
  15628. 'Ncaron': 722,
  15629. 'Iacute': 333,
  15630. 'plusminus': 564,
  15631. 'brokenbar': 200,
  15632. 'registered': 760,
  15633. 'Gbreve': 722,
  15634. 'Idotaccent': 333,
  15635. 'summation': 600,
  15636. 'Egrave': 611,
  15637. 'racute': 333,
  15638. 'omacron': 500,
  15639. 'Zacute': 611,
  15640. 'Zcaron': 611,
  15641. 'greaterequal': 549,
  15642. 'Eth': 722,
  15643. 'Ccedilla': 667,
  15644. 'lcommaaccent': 278,
  15645. 'tcaron': 326,
  15646. 'eogonek': 444,
  15647. 'Uogonek': 722,
  15648. 'Aacute': 722,
  15649. 'Adieresis': 722,
  15650. 'egrave': 444,
  15651. 'zacute': 444,
  15652. 'iogonek': 278,
  15653. 'Oacute': 722,
  15654. 'oacute': 500,
  15655. 'amacron': 444,
  15656. 'sacute': 389,
  15657. 'idieresis': 278,
  15658. 'Ocircumflex': 722,
  15659. 'Ugrave': 722,
  15660. 'Delta': 612,
  15661. 'thorn': 500,
  15662. 'twosuperior': 300,
  15663. 'Odieresis': 722,
  15664. 'mu': 500,
  15665. 'igrave': 278,
  15666. 'ohungarumlaut': 500,
  15667. 'Eogonek': 611,
  15668. 'dcroat': 500,
  15669. 'threequarters': 750,
  15670. 'Scedilla': 556,
  15671. 'lcaron': 344,
  15672. 'Kcommaaccent': 722,
  15673. 'Lacute': 611,
  15674. 'trademark': 980,
  15675. 'edotaccent': 444,
  15676. 'Igrave': 333,
  15677. 'Imacron': 333,
  15678. 'Lcaron': 611,
  15679. 'onehalf': 750,
  15680. 'lessequal': 549,
  15681. 'ocircumflex': 500,
  15682. 'ntilde': 500,
  15683. 'Uhungarumlaut': 722,
  15684. 'Eacute': 611,
  15685. 'emacron': 444,
  15686. 'gbreve': 500,
  15687. 'onequarter': 750,
  15688. 'Scaron': 556,
  15689. 'Scommaaccent': 556,
  15690. 'Ohungarumlaut': 722,
  15691. 'degree': 400,
  15692. 'ograve': 500,
  15693. 'Ccaron': 667,
  15694. 'ugrave': 500,
  15695. 'radical': 453,
  15696. 'Dcaron': 722,
  15697. 'rcommaaccent': 333,
  15698. 'Ntilde': 722,
  15699. 'otilde': 500,
  15700. 'Rcommaaccent': 667,
  15701. 'Lcommaaccent': 611,
  15702. 'Atilde': 722,
  15703. 'Aogonek': 722,
  15704. 'Aring': 722,
  15705. 'Otilde': 722,
  15706. 'zdotaccent': 444,
  15707. 'Ecaron': 611,
  15708. 'Iogonek': 333,
  15709. 'kcommaaccent': 500,
  15710. 'minus': 564,
  15711. 'Icircumflex': 333,
  15712. 'ncaron': 500,
  15713. 'tcommaaccent': 278,
  15714. 'logicalnot': 564,
  15715. 'odieresis': 500,
  15716. 'udieresis': 500,
  15717. 'notequal': 549,
  15718. 'gcommaaccent': 500,
  15719. 'eth': 500,
  15720. 'zcaron': 444,
  15721. 'ncommaaccent': 500,
  15722. 'onesuperior': 300,
  15723. 'imacron': 278,
  15724. 'Euro': 500
  15725. },
  15726. 'Times-Bold': {
  15727. 'space': 250,
  15728. 'exclam': 333,
  15729. 'quotedbl': 555,
  15730. 'numbersign': 500,
  15731. 'dollar': 500,
  15732. 'percent': 1000,
  15733. 'ampersand': 833,
  15734. 'quoteright': 333,
  15735. 'parenleft': 333,
  15736. 'parenright': 333,
  15737. 'asterisk': 500,
  15738. 'plus': 570,
  15739. 'comma': 250,
  15740. 'hyphen': 333,
  15741. 'period': 250,
  15742. 'slash': 278,
  15743. 'zero': 500,
  15744. 'one': 500,
  15745. 'two': 500,
  15746. 'three': 500,
  15747. 'four': 500,
  15748. 'five': 500,
  15749. 'six': 500,
  15750. 'seven': 500,
  15751. 'eight': 500,
  15752. 'nine': 500,
  15753. 'colon': 333,
  15754. 'semicolon': 333,
  15755. 'less': 570,
  15756. 'equal': 570,
  15757. 'greater': 570,
  15758. 'question': 500,
  15759. 'at': 930,
  15760. 'A': 722,
  15761. 'B': 667,
  15762. 'C': 722,
  15763. 'D': 722,
  15764. 'E': 667,
  15765. 'F': 611,
  15766. 'G': 778,
  15767. 'H': 778,
  15768. 'I': 389,
  15769. 'J': 500,
  15770. 'K': 778,
  15771. 'L': 667,
  15772. 'M': 944,
  15773. 'N': 722,
  15774. 'O': 778,
  15775. 'P': 611,
  15776. 'Q': 778,
  15777. 'R': 722,
  15778. 'S': 556,
  15779. 'T': 667,
  15780. 'U': 722,
  15781. 'V': 722,
  15782. 'W': 1000,
  15783. 'X': 722,
  15784. 'Y': 722,
  15785. 'Z': 667,
  15786. 'bracketleft': 333,
  15787. 'backslash': 278,
  15788. 'bracketright': 333,
  15789. 'asciicircum': 581,
  15790. 'underscore': 500,
  15791. 'quoteleft': 333,
  15792. 'a': 500,
  15793. 'b': 556,
  15794. 'c': 444,
  15795. 'd': 556,
  15796. 'e': 444,
  15797. 'f': 333,
  15798. 'g': 500,
  15799. 'h': 556,
  15800. 'i': 278,
  15801. 'j': 333,
  15802. 'k': 556,
  15803. 'l': 278,
  15804. 'm': 833,
  15805. 'n': 556,
  15806. 'o': 500,
  15807. 'p': 556,
  15808. 'q': 556,
  15809. 'r': 444,
  15810. 's': 389,
  15811. 't': 333,
  15812. 'u': 556,
  15813. 'v': 500,
  15814. 'w': 722,
  15815. 'x': 500,
  15816. 'y': 500,
  15817. 'z': 444,
  15818. 'braceleft': 394,
  15819. 'bar': 220,
  15820. 'braceright': 394,
  15821. 'asciitilde': 520,
  15822. 'exclamdown': 333,
  15823. 'cent': 500,
  15824. 'sterling': 500,
  15825. 'fraction': 167,
  15826. 'yen': 500,
  15827. 'florin': 500,
  15828. 'section': 500,
  15829. 'currency': 500,
  15830. 'quotesingle': 278,
  15831. 'quotedblleft': 500,
  15832. 'guillemotleft': 500,
  15833. 'guilsinglleft': 333,
  15834. 'guilsinglright': 333,
  15835. 'fi': 556,
  15836. 'fl': 556,
  15837. 'endash': 500,
  15838. 'dagger': 500,
  15839. 'daggerdbl': 500,
  15840. 'periodcentered': 250,
  15841. 'paragraph': 540,
  15842. 'bullet': 350,
  15843. 'quotesinglbase': 333,
  15844. 'quotedblbase': 500,
  15845. 'quotedblright': 500,
  15846. 'guillemotright': 500,
  15847. 'ellipsis': 1000,
  15848. 'perthousand': 1000,
  15849. 'questiondown': 500,
  15850. 'grave': 333,
  15851. 'acute': 333,
  15852. 'circumflex': 333,
  15853. 'tilde': 333,
  15854. 'macron': 333,
  15855. 'breve': 333,
  15856. 'dotaccent': 333,
  15857. 'dieresis': 333,
  15858. 'ring': 333,
  15859. 'cedilla': 333,
  15860. 'hungarumlaut': 333,
  15861. 'ogonek': 333,
  15862. 'caron': 333,
  15863. 'emdash': 1000,
  15864. 'AE': 1000,
  15865. 'ordfeminine': 300,
  15866. 'Lslash': 667,
  15867. 'Oslash': 778,
  15868. 'OE': 1000,
  15869. 'ordmasculine': 330,
  15870. 'ae': 722,
  15871. 'dotlessi': 278,
  15872. 'lslash': 278,
  15873. 'oslash': 500,
  15874. 'oe': 722,
  15875. 'germandbls': 556,
  15876. 'Idieresis': 389,
  15877. 'eacute': 444,
  15878. 'abreve': 500,
  15879. 'uhungarumlaut': 556,
  15880. 'ecaron': 444,
  15881. 'Ydieresis': 722,
  15882. 'divide': 570,
  15883. 'Yacute': 722,
  15884. 'Acircumflex': 722,
  15885. 'aacute': 500,
  15886. 'Ucircumflex': 722,
  15887. 'yacute': 500,
  15888. 'scommaaccent': 389,
  15889. 'ecircumflex': 444,
  15890. 'Uring': 722,
  15891. 'Udieresis': 722,
  15892. 'aogonek': 500,
  15893. 'Uacute': 722,
  15894. 'uogonek': 556,
  15895. 'Edieresis': 667,
  15896. 'Dcroat': 722,
  15897. 'commaaccent': 250,
  15898. 'copyright': 747,
  15899. 'Emacron': 667,
  15900. 'ccaron': 444,
  15901. 'aring': 500,
  15902. 'Ncommaaccent': 722,
  15903. 'lacute': 278,
  15904. 'agrave': 500,
  15905. 'Tcommaaccent': 667,
  15906. 'Cacute': 722,
  15907. 'atilde': 500,
  15908. 'Edotaccent': 667,
  15909. 'scaron': 389,
  15910. 'scedilla': 389,
  15911. 'iacute': 278,
  15912. 'lozenge': 494,
  15913. 'Rcaron': 722,
  15914. 'Gcommaaccent': 778,
  15915. 'ucircumflex': 556,
  15916. 'acircumflex': 500,
  15917. 'Amacron': 722,
  15918. 'rcaron': 444,
  15919. 'ccedilla': 444,
  15920. 'Zdotaccent': 667,
  15921. 'Thorn': 611,
  15922. 'Omacron': 778,
  15923. 'Racute': 722,
  15924. 'Sacute': 556,
  15925. 'dcaron': 672,
  15926. 'Umacron': 722,
  15927. 'uring': 556,
  15928. 'threesuperior': 300,
  15929. 'Ograve': 778,
  15930. 'Agrave': 722,
  15931. 'Abreve': 722,
  15932. 'multiply': 570,
  15933. 'uacute': 556,
  15934. 'Tcaron': 667,
  15935. 'partialdiff': 494,
  15936. 'ydieresis': 500,
  15937. 'Nacute': 722,
  15938. 'icircumflex': 278,
  15939. 'Ecircumflex': 667,
  15940. 'adieresis': 500,
  15941. 'edieresis': 444,
  15942. 'cacute': 444,
  15943. 'nacute': 556,
  15944. 'umacron': 556,
  15945. 'Ncaron': 722,
  15946. 'Iacute': 389,
  15947. 'plusminus': 570,
  15948. 'brokenbar': 220,
  15949. 'registered': 747,
  15950. 'Gbreve': 778,
  15951. 'Idotaccent': 389,
  15952. 'summation': 600,
  15953. 'Egrave': 667,
  15954. 'racute': 444,
  15955. 'omacron': 500,
  15956. 'Zacute': 667,
  15957. 'Zcaron': 667,
  15958. 'greaterequal': 549,
  15959. 'Eth': 722,
  15960. 'Ccedilla': 722,
  15961. 'lcommaaccent': 278,
  15962. 'tcaron': 416,
  15963. 'eogonek': 444,
  15964. 'Uogonek': 722,
  15965. 'Aacute': 722,
  15966. 'Adieresis': 722,
  15967. 'egrave': 444,
  15968. 'zacute': 444,
  15969. 'iogonek': 278,
  15970. 'Oacute': 778,
  15971. 'oacute': 500,
  15972. 'amacron': 500,
  15973. 'sacute': 389,
  15974. 'idieresis': 278,
  15975. 'Ocircumflex': 778,
  15976. 'Ugrave': 722,
  15977. 'Delta': 612,
  15978. 'thorn': 556,
  15979. 'twosuperior': 300,
  15980. 'Odieresis': 778,
  15981. 'mu': 556,
  15982. 'igrave': 278,
  15983. 'ohungarumlaut': 500,
  15984. 'Eogonek': 667,
  15985. 'dcroat': 556,
  15986. 'threequarters': 750,
  15987. 'Scedilla': 556,
  15988. 'lcaron': 394,
  15989. 'Kcommaaccent': 778,
  15990. 'Lacute': 667,
  15991. 'trademark': 1000,
  15992. 'edotaccent': 444,
  15993. 'Igrave': 389,
  15994. 'Imacron': 389,
  15995. 'Lcaron': 667,
  15996. 'onehalf': 750,
  15997. 'lessequal': 549,
  15998. 'ocircumflex': 500,
  15999. 'ntilde': 556,
  16000. 'Uhungarumlaut': 722,
  16001. 'Eacute': 667,
  16002. 'emacron': 444,
  16003. 'gbreve': 500,
  16004. 'onequarter': 750,
  16005. 'Scaron': 556,
  16006. 'Scommaaccent': 556,
  16007. 'Ohungarumlaut': 778,
  16008. 'degree': 400,
  16009. 'ograve': 500,
  16010. 'Ccaron': 722,
  16011. 'ugrave': 556,
  16012. 'radical': 549,
  16013. 'Dcaron': 722,
  16014. 'rcommaaccent': 444,
  16015. 'Ntilde': 722,
  16016. 'otilde': 500,
  16017. 'Rcommaaccent': 722,
  16018. 'Lcommaaccent': 667,
  16019. 'Atilde': 722,
  16020. 'Aogonek': 722,
  16021. 'Aring': 722,
  16022. 'Otilde': 778,
  16023. 'zdotaccent': 444,
  16024. 'Ecaron': 667,
  16025. 'Iogonek': 389,
  16026. 'kcommaaccent': 556,
  16027. 'minus': 570,
  16028. 'Icircumflex': 389,
  16029. 'ncaron': 556,
  16030. 'tcommaaccent': 333,
  16031. 'logicalnot': 570,
  16032. 'odieresis': 500,
  16033. 'udieresis': 556,
  16034. 'notequal': 549,
  16035. 'gcommaaccent': 500,
  16036. 'eth': 500,
  16037. 'zcaron': 444,
  16038. 'ncommaaccent': 556,
  16039. 'onesuperior': 300,
  16040. 'imacron': 278,
  16041. 'Euro': 500
  16042. },
  16043. 'Times-BoldItalic': {
  16044. 'space': 250,
  16045. 'exclam': 389,
  16046. 'quotedbl': 555,
  16047. 'numbersign': 500,
  16048. 'dollar': 500,
  16049. 'percent': 833,
  16050. 'ampersand': 778,
  16051. 'quoteright': 333,
  16052. 'parenleft': 333,
  16053. 'parenright': 333,
  16054. 'asterisk': 500,
  16055. 'plus': 570,
  16056. 'comma': 250,
  16057. 'hyphen': 333,
  16058. 'period': 250,
  16059. 'slash': 278,
  16060. 'zero': 500,
  16061. 'one': 500,
  16062. 'two': 500,
  16063. 'three': 500,
  16064. 'four': 500,
  16065. 'five': 500,
  16066. 'six': 500,
  16067. 'seven': 500,
  16068. 'eight': 500,
  16069. 'nine': 500,
  16070. 'colon': 333,
  16071. 'semicolon': 333,
  16072. 'less': 570,
  16073. 'equal': 570,
  16074. 'greater': 570,
  16075. 'question': 500,
  16076. 'at': 832,
  16077. 'A': 667,
  16078. 'B': 667,
  16079. 'C': 667,
  16080. 'D': 722,
  16081. 'E': 667,
  16082. 'F': 667,
  16083. 'G': 722,
  16084. 'H': 778,
  16085. 'I': 389,
  16086. 'J': 500,
  16087. 'K': 667,
  16088. 'L': 611,
  16089. 'M': 889,
  16090. 'N': 722,
  16091. 'O': 722,
  16092. 'P': 611,
  16093. 'Q': 722,
  16094. 'R': 667,
  16095. 'S': 556,
  16096. 'T': 611,
  16097. 'U': 722,
  16098. 'V': 667,
  16099. 'W': 889,
  16100. 'X': 667,
  16101. 'Y': 611,
  16102. 'Z': 611,
  16103. 'bracketleft': 333,
  16104. 'backslash': 278,
  16105. 'bracketright': 333,
  16106. 'asciicircum': 570,
  16107. 'underscore': 500,
  16108. 'quoteleft': 333,
  16109. 'a': 500,
  16110. 'b': 500,
  16111. 'c': 444,
  16112. 'd': 500,
  16113. 'e': 444,
  16114. 'f': 333,
  16115. 'g': 500,
  16116. 'h': 556,
  16117. 'i': 278,
  16118. 'j': 278,
  16119. 'k': 500,
  16120. 'l': 278,
  16121. 'm': 778,
  16122. 'n': 556,
  16123. 'o': 500,
  16124. 'p': 500,
  16125. 'q': 500,
  16126. 'r': 389,
  16127. 's': 389,
  16128. 't': 278,
  16129. 'u': 556,
  16130. 'v': 444,
  16131. 'w': 667,
  16132. 'x': 500,
  16133. 'y': 444,
  16134. 'z': 389,
  16135. 'braceleft': 348,
  16136. 'bar': 220,
  16137. 'braceright': 348,
  16138. 'asciitilde': 570,
  16139. 'exclamdown': 389,
  16140. 'cent': 500,
  16141. 'sterling': 500,
  16142. 'fraction': 167,
  16143. 'yen': 500,
  16144. 'florin': 500,
  16145. 'section': 500,
  16146. 'currency': 500,
  16147. 'quotesingle': 278,
  16148. 'quotedblleft': 500,
  16149. 'guillemotleft': 500,
  16150. 'guilsinglleft': 333,
  16151. 'guilsinglright': 333,
  16152. 'fi': 556,
  16153. 'fl': 556,
  16154. 'endash': 500,
  16155. 'dagger': 500,
  16156. 'daggerdbl': 500,
  16157. 'periodcentered': 250,
  16158. 'paragraph': 500,
  16159. 'bullet': 350,
  16160. 'quotesinglbase': 333,
  16161. 'quotedblbase': 500,
  16162. 'quotedblright': 500,
  16163. 'guillemotright': 500,
  16164. 'ellipsis': 1000,
  16165. 'perthousand': 1000,
  16166. 'questiondown': 500,
  16167. 'grave': 333,
  16168. 'acute': 333,
  16169. 'circumflex': 333,
  16170. 'tilde': 333,
  16171. 'macron': 333,
  16172. 'breve': 333,
  16173. 'dotaccent': 333,
  16174. 'dieresis': 333,
  16175. 'ring': 333,
  16176. 'cedilla': 333,
  16177. 'hungarumlaut': 333,
  16178. 'ogonek': 333,
  16179. 'caron': 333,
  16180. 'emdash': 1000,
  16181. 'AE': 944,
  16182. 'ordfeminine': 266,
  16183. 'Lslash': 611,
  16184. 'Oslash': 722,
  16185. 'OE': 944,
  16186. 'ordmasculine': 300,
  16187. 'ae': 722,
  16188. 'dotlessi': 278,
  16189. 'lslash': 278,
  16190. 'oslash': 500,
  16191. 'oe': 722,
  16192. 'germandbls': 500,
  16193. 'Idieresis': 389,
  16194. 'eacute': 444,
  16195. 'abreve': 500,
  16196. 'uhungarumlaut': 556,
  16197. 'ecaron': 444,
  16198. 'Ydieresis': 611,
  16199. 'divide': 570,
  16200. 'Yacute': 611,
  16201. 'Acircumflex': 667,
  16202. 'aacute': 500,
  16203. 'Ucircumflex': 722,
  16204. 'yacute': 444,
  16205. 'scommaaccent': 389,
  16206. 'ecircumflex': 444,
  16207. 'Uring': 722,
  16208. 'Udieresis': 722,
  16209. 'aogonek': 500,
  16210. 'Uacute': 722,
  16211. 'uogonek': 556,
  16212. 'Edieresis': 667,
  16213. 'Dcroat': 722,
  16214. 'commaaccent': 250,
  16215. 'copyright': 747,
  16216. 'Emacron': 667,
  16217. 'ccaron': 444,
  16218. 'aring': 500,
  16219. 'Ncommaaccent': 722,
  16220. 'lacute': 278,
  16221. 'agrave': 500,
  16222. 'Tcommaaccent': 611,
  16223. 'Cacute': 667,
  16224. 'atilde': 500,
  16225. 'Edotaccent': 667,
  16226. 'scaron': 389,
  16227. 'scedilla': 389,
  16228. 'iacute': 278,
  16229. 'lozenge': 494,
  16230. 'Rcaron': 667,
  16231. 'Gcommaaccent': 722,
  16232. 'ucircumflex': 556,
  16233. 'acircumflex': 500,
  16234. 'Amacron': 667,
  16235. 'rcaron': 389,
  16236. 'ccedilla': 444,
  16237. 'Zdotaccent': 611,
  16238. 'Thorn': 611,
  16239. 'Omacron': 722,
  16240. 'Racute': 667,
  16241. 'Sacute': 556,
  16242. 'dcaron': 608,
  16243. 'Umacron': 722,
  16244. 'uring': 556,
  16245. 'threesuperior': 300,
  16246. 'Ograve': 722,
  16247. 'Agrave': 667,
  16248. 'Abreve': 667,
  16249. 'multiply': 570,
  16250. 'uacute': 556,
  16251. 'Tcaron': 611,
  16252. 'partialdiff': 494,
  16253. 'ydieresis': 444,
  16254. 'Nacute': 722,
  16255. 'icircumflex': 278,
  16256. 'Ecircumflex': 667,
  16257. 'adieresis': 500,
  16258. 'edieresis': 444,
  16259. 'cacute': 444,
  16260. 'nacute': 556,
  16261. 'umacron': 556,
  16262. 'Ncaron': 722,
  16263. 'Iacute': 389,
  16264. 'plusminus': 570,
  16265. 'brokenbar': 220,
  16266. 'registered': 747,
  16267. 'Gbreve': 722,
  16268. 'Idotaccent': 389,
  16269. 'summation': 600,
  16270. 'Egrave': 667,
  16271. 'racute': 389,
  16272. 'omacron': 500,
  16273. 'Zacute': 611,
  16274. 'Zcaron': 611,
  16275. 'greaterequal': 549,
  16276. 'Eth': 722,
  16277. 'Ccedilla': 667,
  16278. 'lcommaaccent': 278,
  16279. 'tcaron': 366,
  16280. 'eogonek': 444,
  16281. 'Uogonek': 722,
  16282. 'Aacute': 667,
  16283. 'Adieresis': 667,
  16284. 'egrave': 444,
  16285. 'zacute': 389,
  16286. 'iogonek': 278,
  16287. 'Oacute': 722,
  16288. 'oacute': 500,
  16289. 'amacron': 500,
  16290. 'sacute': 389,
  16291. 'idieresis': 278,
  16292. 'Ocircumflex': 722,
  16293. 'Ugrave': 722,
  16294. 'Delta': 612,
  16295. 'thorn': 500,
  16296. 'twosuperior': 300,
  16297. 'Odieresis': 722,
  16298. 'mu': 576,
  16299. 'igrave': 278,
  16300. 'ohungarumlaut': 500,
  16301. 'Eogonek': 667,
  16302. 'dcroat': 500,
  16303. 'threequarters': 750,
  16304. 'Scedilla': 556,
  16305. 'lcaron': 382,
  16306. 'Kcommaaccent': 667,
  16307. 'Lacute': 611,
  16308. 'trademark': 1000,
  16309. 'edotaccent': 444,
  16310. 'Igrave': 389,
  16311. 'Imacron': 389,
  16312. 'Lcaron': 611,
  16313. 'onehalf': 750,
  16314. 'lessequal': 549,
  16315. 'ocircumflex': 500,
  16316. 'ntilde': 556,
  16317. 'Uhungarumlaut': 722,
  16318. 'Eacute': 667,
  16319. 'emacron': 444,
  16320. 'gbreve': 500,
  16321. 'onequarter': 750,
  16322. 'Scaron': 556,
  16323. 'Scommaaccent': 556,
  16324. 'Ohungarumlaut': 722,
  16325. 'degree': 400,
  16326. 'ograve': 500,
  16327. 'Ccaron': 667,
  16328. 'ugrave': 556,
  16329. 'radical': 549,
  16330. 'Dcaron': 722,
  16331. 'rcommaaccent': 389,
  16332. 'Ntilde': 722,
  16333. 'otilde': 500,
  16334. 'Rcommaaccent': 667,
  16335. 'Lcommaaccent': 611,
  16336. 'Atilde': 667,
  16337. 'Aogonek': 667,
  16338. 'Aring': 667,
  16339. 'Otilde': 722,
  16340. 'zdotaccent': 389,
  16341. 'Ecaron': 667,
  16342. 'Iogonek': 389,
  16343. 'kcommaaccent': 500,
  16344. 'minus': 606,
  16345. 'Icircumflex': 389,
  16346. 'ncaron': 556,
  16347. 'tcommaaccent': 278,
  16348. 'logicalnot': 606,
  16349. 'odieresis': 500,
  16350. 'udieresis': 556,
  16351. 'notequal': 549,
  16352. 'gcommaaccent': 500,
  16353. 'eth': 500,
  16354. 'zcaron': 389,
  16355. 'ncommaaccent': 556,
  16356. 'onesuperior': 300,
  16357. 'imacron': 278,
  16358. 'Euro': 500
  16359. },
  16360. 'Times-Italic': {
  16361. 'space': 250,
  16362. 'exclam': 333,
  16363. 'quotedbl': 420,
  16364. 'numbersign': 500,
  16365. 'dollar': 500,
  16366. 'percent': 833,
  16367. 'ampersand': 778,
  16368. 'quoteright': 333,
  16369. 'parenleft': 333,
  16370. 'parenright': 333,
  16371. 'asterisk': 500,
  16372. 'plus': 675,
  16373. 'comma': 250,
  16374. 'hyphen': 333,
  16375. 'period': 250,
  16376. 'slash': 278,
  16377. 'zero': 500,
  16378. 'one': 500,
  16379. 'two': 500,
  16380. 'three': 500,
  16381. 'four': 500,
  16382. 'five': 500,
  16383. 'six': 500,
  16384. 'seven': 500,
  16385. 'eight': 500,
  16386. 'nine': 500,
  16387. 'colon': 333,
  16388. 'semicolon': 333,
  16389. 'less': 675,
  16390. 'equal': 675,
  16391. 'greater': 675,
  16392. 'question': 500,
  16393. 'at': 920,
  16394. 'A': 611,
  16395. 'B': 611,
  16396. 'C': 667,
  16397. 'D': 722,
  16398. 'E': 611,
  16399. 'F': 611,
  16400. 'G': 722,
  16401. 'H': 722,
  16402. 'I': 333,
  16403. 'J': 444,
  16404. 'K': 667,
  16405. 'L': 556,
  16406. 'M': 833,
  16407. 'N': 667,
  16408. 'O': 722,
  16409. 'P': 611,
  16410. 'Q': 722,
  16411. 'R': 611,
  16412. 'S': 500,
  16413. 'T': 556,
  16414. 'U': 722,
  16415. 'V': 611,
  16416. 'W': 833,
  16417. 'X': 611,
  16418. 'Y': 556,
  16419. 'Z': 556,
  16420. 'bracketleft': 389,
  16421. 'backslash': 278,
  16422. 'bracketright': 389,
  16423. 'asciicircum': 422,
  16424. 'underscore': 500,
  16425. 'quoteleft': 333,
  16426. 'a': 500,
  16427. 'b': 500,
  16428. 'c': 444,
  16429. 'd': 500,
  16430. 'e': 444,
  16431. 'f': 278,
  16432. 'g': 500,
  16433. 'h': 500,
  16434. 'i': 278,
  16435. 'j': 278,
  16436. 'k': 444,
  16437. 'l': 278,
  16438. 'm': 722,
  16439. 'n': 500,
  16440. 'o': 500,
  16441. 'p': 500,
  16442. 'q': 500,
  16443. 'r': 389,
  16444. 's': 389,
  16445. 't': 278,
  16446. 'u': 500,
  16447. 'v': 444,
  16448. 'w': 667,
  16449. 'x': 444,
  16450. 'y': 444,
  16451. 'z': 389,
  16452. 'braceleft': 400,
  16453. 'bar': 275,
  16454. 'braceright': 400,
  16455. 'asciitilde': 541,
  16456. 'exclamdown': 389,
  16457. 'cent': 500,
  16458. 'sterling': 500,
  16459. 'fraction': 167,
  16460. 'yen': 500,
  16461. 'florin': 500,
  16462. 'section': 500,
  16463. 'currency': 500,
  16464. 'quotesingle': 214,
  16465. 'quotedblleft': 556,
  16466. 'guillemotleft': 500,
  16467. 'guilsinglleft': 333,
  16468. 'guilsinglright': 333,
  16469. 'fi': 500,
  16470. 'fl': 500,
  16471. 'endash': 500,
  16472. 'dagger': 500,
  16473. 'daggerdbl': 500,
  16474. 'periodcentered': 250,
  16475. 'paragraph': 523,
  16476. 'bullet': 350,
  16477. 'quotesinglbase': 333,
  16478. 'quotedblbase': 556,
  16479. 'quotedblright': 556,
  16480. 'guillemotright': 500,
  16481. 'ellipsis': 889,
  16482. 'perthousand': 1000,
  16483. 'questiondown': 500,
  16484. 'grave': 333,
  16485. 'acute': 333,
  16486. 'circumflex': 333,
  16487. 'tilde': 333,
  16488. 'macron': 333,
  16489. 'breve': 333,
  16490. 'dotaccent': 333,
  16491. 'dieresis': 333,
  16492. 'ring': 333,
  16493. 'cedilla': 333,
  16494. 'hungarumlaut': 333,
  16495. 'ogonek': 333,
  16496. 'caron': 333,
  16497. 'emdash': 889,
  16498. 'AE': 889,
  16499. 'ordfeminine': 276,
  16500. 'Lslash': 556,
  16501. 'Oslash': 722,
  16502. 'OE': 944,
  16503. 'ordmasculine': 310,
  16504. 'ae': 667,
  16505. 'dotlessi': 278,
  16506. 'lslash': 278,
  16507. 'oslash': 500,
  16508. 'oe': 667,
  16509. 'germandbls': 500,
  16510. 'Idieresis': 333,
  16511. 'eacute': 444,
  16512. 'abreve': 500,
  16513. 'uhungarumlaut': 500,
  16514. 'ecaron': 444,
  16515. 'Ydieresis': 556,
  16516. 'divide': 675,
  16517. 'Yacute': 556,
  16518. 'Acircumflex': 611,
  16519. 'aacute': 500,
  16520. 'Ucircumflex': 722,
  16521. 'yacute': 444,
  16522. 'scommaaccent': 389,
  16523. 'ecircumflex': 444,
  16524. 'Uring': 722,
  16525. 'Udieresis': 722,
  16526. 'aogonek': 500,
  16527. 'Uacute': 722,
  16528. 'uogonek': 500,
  16529. 'Edieresis': 611,
  16530. 'Dcroat': 722,
  16531. 'commaaccent': 250,
  16532. 'copyright': 760,
  16533. 'Emacron': 611,
  16534. 'ccaron': 444,
  16535. 'aring': 500,
  16536. 'Ncommaaccent': 667,
  16537. 'lacute': 278,
  16538. 'agrave': 500,
  16539. 'Tcommaaccent': 556,
  16540. 'Cacute': 667,
  16541. 'atilde': 500,
  16542. 'Edotaccent': 611,
  16543. 'scaron': 389,
  16544. 'scedilla': 389,
  16545. 'iacute': 278,
  16546. 'lozenge': 471,
  16547. 'Rcaron': 611,
  16548. 'Gcommaaccent': 722,
  16549. 'ucircumflex': 500,
  16550. 'acircumflex': 500,
  16551. 'Amacron': 611,
  16552. 'rcaron': 389,
  16553. 'ccedilla': 444,
  16554. 'Zdotaccent': 556,
  16555. 'Thorn': 611,
  16556. 'Omacron': 722,
  16557. 'Racute': 611,
  16558. 'Sacute': 500,
  16559. 'dcaron': 544,
  16560. 'Umacron': 722,
  16561. 'uring': 500,
  16562. 'threesuperior': 300,
  16563. 'Ograve': 722,
  16564. 'Agrave': 611,
  16565. 'Abreve': 611,
  16566. 'multiply': 675,
  16567. 'uacute': 500,
  16568. 'Tcaron': 556,
  16569. 'partialdiff': 476,
  16570. 'ydieresis': 444,
  16571. 'Nacute': 667,
  16572. 'icircumflex': 278,
  16573. 'Ecircumflex': 611,
  16574. 'adieresis': 500,
  16575. 'edieresis': 444,
  16576. 'cacute': 444,
  16577. 'nacute': 500,
  16578. 'umacron': 500,
  16579. 'Ncaron': 667,
  16580. 'Iacute': 333,
  16581. 'plusminus': 675,
  16582. 'brokenbar': 275,
  16583. 'registered': 760,
  16584. 'Gbreve': 722,
  16585. 'Idotaccent': 333,
  16586. 'summation': 600,
  16587. 'Egrave': 611,
  16588. 'racute': 389,
  16589. 'omacron': 500,
  16590. 'Zacute': 556,
  16591. 'Zcaron': 556,
  16592. 'greaterequal': 549,
  16593. 'Eth': 722,
  16594. 'Ccedilla': 667,
  16595. 'lcommaaccent': 278,
  16596. 'tcaron': 300,
  16597. 'eogonek': 444,
  16598. 'Uogonek': 722,
  16599. 'Aacute': 611,
  16600. 'Adieresis': 611,
  16601. 'egrave': 444,
  16602. 'zacute': 389,
  16603. 'iogonek': 278,
  16604. 'Oacute': 722,
  16605. 'oacute': 500,
  16606. 'amacron': 500,
  16607. 'sacute': 389,
  16608. 'idieresis': 278,
  16609. 'Ocircumflex': 722,
  16610. 'Ugrave': 722,
  16611. 'Delta': 612,
  16612. 'thorn': 500,
  16613. 'twosuperior': 300,
  16614. 'Odieresis': 722,
  16615. 'mu': 500,
  16616. 'igrave': 278,
  16617. 'ohungarumlaut': 500,
  16618. 'Eogonek': 611,
  16619. 'dcroat': 500,
  16620. 'threequarters': 750,
  16621. 'Scedilla': 500,
  16622. 'lcaron': 300,
  16623. 'Kcommaaccent': 667,
  16624. 'Lacute': 556,
  16625. 'trademark': 980,
  16626. 'edotaccent': 444,
  16627. 'Igrave': 333,
  16628. 'Imacron': 333,
  16629. 'Lcaron': 611,
  16630. 'onehalf': 750,
  16631. 'lessequal': 549,
  16632. 'ocircumflex': 500,
  16633. 'ntilde': 500,
  16634. 'Uhungarumlaut': 722,
  16635. 'Eacute': 611,
  16636. 'emacron': 444,
  16637. 'gbreve': 500,
  16638. 'onequarter': 750,
  16639. 'Scaron': 500,
  16640. 'Scommaaccent': 500,
  16641. 'Ohungarumlaut': 722,
  16642. 'degree': 400,
  16643. 'ograve': 500,
  16644. 'Ccaron': 667,
  16645. 'ugrave': 500,
  16646. 'radical': 453,
  16647. 'Dcaron': 722,
  16648. 'rcommaaccent': 389,
  16649. 'Ntilde': 667,
  16650. 'otilde': 500,
  16651. 'Rcommaaccent': 611,
  16652. 'Lcommaaccent': 556,
  16653. 'Atilde': 611,
  16654. 'Aogonek': 611,
  16655. 'Aring': 611,
  16656. 'Otilde': 722,
  16657. 'zdotaccent': 389,
  16658. 'Ecaron': 611,
  16659. 'Iogonek': 333,
  16660. 'kcommaaccent': 444,
  16661. 'minus': 675,
  16662. 'Icircumflex': 333,
  16663. 'ncaron': 500,
  16664. 'tcommaaccent': 278,
  16665. 'logicalnot': 675,
  16666. 'odieresis': 500,
  16667. 'udieresis': 500,
  16668. 'notequal': 549,
  16669. 'gcommaaccent': 500,
  16670. 'eth': 500,
  16671. 'zcaron': 389,
  16672. 'ncommaaccent': 500,
  16673. 'onesuperior': 300,
  16674. 'imacron': 278,
  16675. 'Euro': 500
  16676. },
  16677. 'ZapfDingbats': {
  16678. 'space': 278,
  16679. 'a1': 974,
  16680. 'a2': 961,
  16681. 'a202': 974,
  16682. 'a3': 980,
  16683. 'a4': 719,
  16684. 'a5': 789,
  16685. 'a119': 790,
  16686. 'a118': 791,
  16687. 'a117': 690,
  16688. 'a11': 960,
  16689. 'a12': 939,
  16690. 'a13': 549,
  16691. 'a14': 855,
  16692. 'a15': 911,
  16693. 'a16': 933,
  16694. 'a105': 911,
  16695. 'a17': 945,
  16696. 'a18': 974,
  16697. 'a19': 755,
  16698. 'a20': 846,
  16699. 'a21': 762,
  16700. 'a22': 761,
  16701. 'a23': 571,
  16702. 'a24': 677,
  16703. 'a25': 763,
  16704. 'a26': 760,
  16705. 'a27': 759,
  16706. 'a28': 754,
  16707. 'a6': 494,
  16708. 'a7': 552,
  16709. 'a8': 537,
  16710. 'a9': 577,
  16711. 'a10': 692,
  16712. 'a29': 786,
  16713. 'a30': 788,
  16714. 'a31': 788,
  16715. 'a32': 790,
  16716. 'a33': 793,
  16717. 'a34': 794,
  16718. 'a35': 816,
  16719. 'a36': 823,
  16720. 'a37': 789,
  16721. 'a38': 841,
  16722. 'a39': 823,
  16723. 'a40': 833,
  16724. 'a41': 816,
  16725. 'a42': 831,
  16726. 'a43': 923,
  16727. 'a44': 744,
  16728. 'a45': 723,
  16729. 'a46': 749,
  16730. 'a47': 790,
  16731. 'a48': 792,
  16732. 'a49': 695,
  16733. 'a50': 776,
  16734. 'a51': 768,
  16735. 'a52': 792,
  16736. 'a53': 759,
  16737. 'a54': 707,
  16738. 'a55': 708,
  16739. 'a56': 682,
  16740. 'a57': 701,
  16741. 'a58': 826,
  16742. 'a59': 815,
  16743. 'a60': 789,
  16744. 'a61': 789,
  16745. 'a62': 707,
  16746. 'a63': 687,
  16747. 'a64': 696,
  16748. 'a65': 689,
  16749. 'a66': 786,
  16750. 'a67': 787,
  16751. 'a68': 713,
  16752. 'a69': 791,
  16753. 'a70': 785,
  16754. 'a71': 791,
  16755. 'a72': 873,
  16756. 'a73': 761,
  16757. 'a74': 762,
  16758. 'a203': 762,
  16759. 'a75': 759,
  16760. 'a204': 759,
  16761. 'a76': 892,
  16762. 'a77': 892,
  16763. 'a78': 788,
  16764. 'a79': 784,
  16765. 'a81': 438,
  16766. 'a82': 138,
  16767. 'a83': 277,
  16768. 'a84': 415,
  16769. 'a97': 392,
  16770. 'a98': 392,
  16771. 'a99': 668,
  16772. 'a100': 668,
  16773. 'a89': 390,
  16774. 'a90': 390,
  16775. 'a93': 317,
  16776. 'a94': 317,
  16777. 'a91': 276,
  16778. 'a92': 276,
  16779. 'a205': 509,
  16780. 'a85': 509,
  16781. 'a206': 410,
  16782. 'a86': 410,
  16783. 'a87': 234,
  16784. 'a88': 234,
  16785. 'a95': 334,
  16786. 'a96': 334,
  16787. 'a101': 732,
  16788. 'a102': 544,
  16789. 'a103': 544,
  16790. 'a104': 910,
  16791. 'a106': 667,
  16792. 'a107': 760,
  16793. 'a108': 760,
  16794. 'a112': 776,
  16795. 'a111': 595,
  16796. 'a110': 694,
  16797. 'a109': 626,
  16798. 'a120': 788,
  16799. 'a121': 788,
  16800. 'a122': 788,
  16801. 'a123': 788,
  16802. 'a124': 788,
  16803. 'a125': 788,
  16804. 'a126': 788,
  16805. 'a127': 788,
  16806. 'a128': 788,
  16807. 'a129': 788,
  16808. 'a130': 788,
  16809. 'a131': 788,
  16810. 'a132': 788,
  16811. 'a133': 788,
  16812. 'a134': 788,
  16813. 'a135': 788,
  16814. 'a136': 788,
  16815. 'a137': 788,
  16816. 'a138': 788,
  16817. 'a139': 788,
  16818. 'a140': 788,
  16819. 'a141': 788,
  16820. 'a142': 788,
  16821. 'a143': 788,
  16822. 'a144': 788,
  16823. 'a145': 788,
  16824. 'a146': 788,
  16825. 'a147': 788,
  16826. 'a148': 788,
  16827. 'a149': 788,
  16828. 'a150': 788,
  16829. 'a151': 788,
  16830. 'a152': 788,
  16831. 'a153': 788,
  16832. 'a154': 788,
  16833. 'a155': 788,
  16834. 'a156': 788,
  16835. 'a157': 788,
  16836. 'a158': 788,
  16837. 'a159': 788,
  16838. 'a160': 894,
  16839. 'a161': 838,
  16840. 'a163': 1016,
  16841. 'a164': 458,
  16842. 'a196': 748,
  16843. 'a165': 924,
  16844. 'a192': 748,
  16845. 'a166': 918,
  16846. 'a167': 927,
  16847. 'a168': 928,
  16848. 'a169': 928,
  16849. 'a170': 834,
  16850. 'a171': 873,
  16851. 'a172': 828,
  16852. 'a173': 924,
  16853. 'a162': 924,
  16854. 'a174': 917,
  16855. 'a175': 930,
  16856. 'a176': 931,
  16857. 'a177': 463,
  16858. 'a178': 883,
  16859. 'a179': 836,
  16860. 'a193': 836,
  16861. 'a180': 867,
  16862. 'a199': 867,
  16863. 'a181': 696,
  16864. 'a200': 696,
  16865. 'a182': 874,
  16866. 'a201': 874,
  16867. 'a183': 760,
  16868. 'a184': 946,
  16869. 'a197': 771,
  16870. 'a185': 865,
  16871. 'a194': 771,
  16872. 'a198': 888,
  16873. 'a186': 967,
  16874. 'a195': 888,
  16875. 'a187': 831,
  16876. 'a188': 873,
  16877. 'a189': 927,
  16878. 'a190': 970,
  16879. 'a191': 918
  16880. }
  16881. };
  16882. exports.Metrics = Metrics;
  16883. }));
  16884. (function (root, factory) {
  16885. {
  16886. factory((root.pdfjsCoreBidi = {}), root.pdfjsSharedGlobal);
  16887. }
  16888. }(this, function (exports, sharedGlobal) {
  16889. var PDFJS = sharedGlobal.PDFJS;
  16890. var bidi = PDFJS.bidi = (function bidiClosure() {
  16891. // Character types for symbols from 0000 to 00FF.
  16892. var baseTypes = [
  16893. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'S', 'B', 'S', 'WS',
  16894. 'B', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  16895. 'BN', 'BN', 'B', 'B', 'B', 'S', 'WS', 'ON', 'ON', 'ET', 'ET', 'ET', 'ON',
  16896. 'ON', 'ON', 'ON', 'ON', 'ON', 'CS', 'ON', 'CS', 'ON', 'EN', 'EN', 'EN',
  16897. 'EN', 'EN', 'EN', 'EN', 'EN', 'EN', 'EN', 'ON', 'ON', 'ON', 'ON', 'ON',
  16898. 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  16899. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'ON', 'ON',
  16900. 'ON', 'ON', 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  16901. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  16902. 'L', 'ON', 'ON', 'ON', 'ON', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'B', 'BN',
  16903. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  16904. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  16905. 'BN', 'CS', 'ON', 'ET', 'ET', 'ET', 'ET', 'ON', 'ON', 'ON', 'ON', 'L', 'ON',
  16906. 'ON', 'ON', 'ON', 'ON', 'ET', 'ET', 'EN', 'EN', 'ON', 'L', 'ON', 'ON', 'ON',
  16907. 'EN', 'L', 'ON', 'ON', 'ON', 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  16908. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  16909. 'L', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  16910. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  16911. 'L', 'L', 'L', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L'
  16912. ];
  16913. // Character types for symbols from 0600 to 06FF
  16914. var arabicTypes = [
  16915. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  16916. 'CS', 'AL', 'ON', 'ON', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'AL',
  16917. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  16918. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  16919. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  16920. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  16921. 'AL', 'AL', 'AL', 'AL', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM',
  16922. 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'AL', 'AL', 'AL', 'AL',
  16923. 'AL', 'AL', 'AL', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN',
  16924. 'AN', 'ET', 'AN', 'AN', 'AL', 'AL', 'AL', 'NSM', 'AL', 'AL', 'AL', 'AL',
  16925. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  16926. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  16927. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  16928. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  16929. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  16930. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  16931. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  16932. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  16933. 'AL', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM',
  16934. 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'ON', 'NSM',
  16935. 'NSM', 'NSM', 'NSM', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  16936. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL'
  16937. ];
  16938. function isOdd(i) {
  16939. return (i & 1) !== 0;
  16940. }
  16941. function isEven(i) {
  16942. return (i & 1) === 0;
  16943. }
  16944. function findUnequal(arr, start, value) {
  16945. for (var j = start, jj = arr.length; j < jj; ++j) {
  16946. if (arr[j] !== value) {
  16947. return j;
  16948. }
  16949. }
  16950. return j;
  16951. }
  16952. function setValues(arr, start, end, value) {
  16953. for (var j = start; j < end; ++j) {
  16954. arr[j] = value;
  16955. }
  16956. }
  16957. function reverseValues(arr, start, end) {
  16958. for (var i = start, j = end - 1; i < j; ++i, --j) {
  16959. var temp = arr[i];
  16960. arr[i] = arr[j];
  16961. arr[j] = temp;
  16962. }
  16963. }
  16964. function createBidiText(str, isLTR, vertical) {
  16965. return {
  16966. str: str,
  16967. dir: (vertical ? 'ttb' : (isLTR ? 'ltr' : 'rtl'))
  16968. };
  16969. }
  16970. // These are used in bidi(), which is called frequently. We re-use them on
  16971. // each call to avoid unnecessary allocations.
  16972. var chars = [];
  16973. var types = [];
  16974. function bidi(str, startLevel, vertical) {
  16975. var isLTR = true;
  16976. var strLength = str.length;
  16977. if (strLength === 0 || vertical) {
  16978. return createBidiText(str, isLTR, vertical);
  16979. }
  16980. // Get types and fill arrays
  16981. chars.length = strLength;
  16982. types.length = strLength;
  16983. var numBidi = 0;
  16984. var i, ii;
  16985. for (i = 0; i < strLength; ++i) {
  16986. chars[i] = str.charAt(i);
  16987. var charCode = str.charCodeAt(i);
  16988. var charType = 'L';
  16989. if (charCode <= 0x00ff) {
  16990. charType = baseTypes[charCode];
  16991. } else if (0x0590 <= charCode && charCode <= 0x05f4) {
  16992. charType = 'R';
  16993. } else if (0x0600 <= charCode && charCode <= 0x06ff) {
  16994. charType = arabicTypes[charCode & 0xff];
  16995. } else if (0x0700 <= charCode && charCode <= 0x08AC) {
  16996. charType = 'AL';
  16997. }
  16998. if (charType === 'R' || charType === 'AL' || charType === 'AN') {
  16999. numBidi++;
  17000. }
  17001. types[i] = charType;
  17002. }
  17003. // Detect the bidi method
  17004. // - If there are no rtl characters then no bidi needed
  17005. // - If less than 30% chars are rtl then string is primarily ltr
  17006. // - If more than 30% chars are rtl then string is primarily rtl
  17007. if (numBidi === 0) {
  17008. isLTR = true;
  17009. return createBidiText(str, isLTR);
  17010. }
  17011. if (startLevel === -1) {
  17012. if ((strLength / numBidi) < 0.3) {
  17013. isLTR = true;
  17014. startLevel = 0;
  17015. } else {
  17016. isLTR = false;
  17017. startLevel = 1;
  17018. }
  17019. }
  17020. var levels = [];
  17021. for (i = 0; i < strLength; ++i) {
  17022. levels[i] = startLevel;
  17023. }
  17024. /*
  17025. X1-X10: skip most of this, since we are NOT doing the embeddings.
  17026. */
  17027. var e = (isOdd(startLevel) ? 'R' : 'L');
  17028. var sor = e;
  17029. var eor = sor;
  17030. /*
  17031. W1. Examine each non-spacing mark (NSM) in the level run, and change the
  17032. type of the NSM to the type of the previous character. If the NSM is at the
  17033. start of the level run, it will get the type of sor.
  17034. */
  17035. var lastType = sor;
  17036. for (i = 0; i < strLength; ++i) {
  17037. if (types[i] === 'NSM') {
  17038. types[i] = lastType;
  17039. } else {
  17040. lastType = types[i];
  17041. }
  17042. }
  17043. /*
  17044. W2. Search backwards from each instance of a European number until the
  17045. first strong type (R, L, AL, or sor) is found. If an AL is found, change
  17046. the type of the European number to Arabic number.
  17047. */
  17048. lastType = sor;
  17049. var t;
  17050. for (i = 0; i < strLength; ++i) {
  17051. t = types[i];
  17052. if (t === 'EN') {
  17053. types[i] = (lastType === 'AL') ? 'AN' : 'EN';
  17054. } else if (t === 'R' || t === 'L' || t === 'AL') {
  17055. lastType = t;
  17056. }
  17057. }
  17058. /*
  17059. W3. Change all ALs to R.
  17060. */
  17061. for (i = 0; i < strLength; ++i) {
  17062. t = types[i];
  17063. if (t === 'AL') {
  17064. types[i] = 'R';
  17065. }
  17066. }
  17067. /*
  17068. W4. A single European separator between two European numbers changes to a
  17069. European number. A single common separator between two numbers of the same
  17070. type changes to that type:
  17071. */
  17072. for (i = 1; i < strLength - 1; ++i) {
  17073. if (types[i] === 'ES' && types[i - 1] === 'EN' && types[i + 1] === 'EN') {
  17074. types[i] = 'EN';
  17075. }
  17076. if (types[i] === 'CS' &&
  17077. (types[i - 1] === 'EN' || types[i - 1] === 'AN') &&
  17078. types[i + 1] === types[i - 1]) {
  17079. types[i] = types[i - 1];
  17080. }
  17081. }
  17082. /*
  17083. W5. A sequence of European terminators adjacent to European numbers changes
  17084. to all European numbers:
  17085. */
  17086. for (i = 0; i < strLength; ++i) {
  17087. if (types[i] === 'EN') {
  17088. // do before
  17089. var j;
  17090. for (j = i - 1; j >= 0; --j) {
  17091. if (types[j] !== 'ET') {
  17092. break;
  17093. }
  17094. types[j] = 'EN';
  17095. }
  17096. // do after
  17097. for (j = i + 1; j < strLength; --j) {
  17098. if (types[j] !== 'ET') {
  17099. break;
  17100. }
  17101. types[j] = 'EN';
  17102. }
  17103. }
  17104. }
  17105. /*
  17106. W6. Otherwise, separators and terminators change to Other Neutral:
  17107. */
  17108. for (i = 0; i < strLength; ++i) {
  17109. t = types[i];
  17110. if (t === 'WS' || t === 'ES' || t === 'ET' || t === 'CS') {
  17111. types[i] = 'ON';
  17112. }
  17113. }
  17114. /*
  17115. W7. Search backwards from each instance of a European number until the
  17116. first strong type (R, L, or sor) is found. If an L is found, then change
  17117. the type of the European number to L.
  17118. */
  17119. lastType = sor;
  17120. for (i = 0; i < strLength; ++i) {
  17121. t = types[i];
  17122. if (t === 'EN') {
  17123. types[i] = ((lastType === 'L') ? 'L' : 'EN');
  17124. } else if (t === 'R' || t === 'L') {
  17125. lastType = t;
  17126. }
  17127. }
  17128. /*
  17129. N1. A sequence of neutrals takes the direction of the surrounding strong
  17130. text if the text on both sides has the same direction. European and Arabic
  17131. numbers are treated as though they were R. Start-of-level-run (sor) and
  17132. end-of-level-run (eor) are used at level run boundaries.
  17133. */
  17134. for (i = 0; i < strLength; ++i) {
  17135. if (types[i] === 'ON') {
  17136. var end = findUnequal(types, i + 1, 'ON');
  17137. var before = sor;
  17138. if (i > 0) {
  17139. before = types[i - 1];
  17140. }
  17141. var after = eor;
  17142. if (end + 1 < strLength) {
  17143. after = types[end + 1];
  17144. }
  17145. if (before !== 'L') {
  17146. before = 'R';
  17147. }
  17148. if (after !== 'L') {
  17149. after = 'R';
  17150. }
  17151. if (before === after) {
  17152. setValues(types, i, end, before);
  17153. }
  17154. i = end - 1; // reset to end (-1 so next iteration is ok)
  17155. }
  17156. }
  17157. /*
  17158. N2. Any remaining neutrals take the embedding direction.
  17159. */
  17160. for (i = 0; i < strLength; ++i) {
  17161. if (types[i] === 'ON') {
  17162. types[i] = e;
  17163. }
  17164. }
  17165. /*
  17166. I1. For all characters with an even (left-to-right) embedding direction,
  17167. those of type R go up one level and those of type AN or EN go up two
  17168. levels.
  17169. I2. For all characters with an odd (right-to-left) embedding direction,
  17170. those of type L, EN or AN go up one level.
  17171. */
  17172. for (i = 0; i < strLength; ++i) {
  17173. t = types[i];
  17174. if (isEven(levels[i])) {
  17175. if (t === 'R') {
  17176. levels[i] += 1;
  17177. } else if (t === 'AN' || t === 'EN') {
  17178. levels[i] += 2;
  17179. }
  17180. } else { // isOdd
  17181. if (t === 'L' || t === 'AN' || t === 'EN') {
  17182. levels[i] += 1;
  17183. }
  17184. }
  17185. }
  17186. /*
  17187. L1. On each line, reset the embedding level of the following characters to
  17188. the paragraph embedding level:
  17189. segment separators,
  17190. paragraph separators,
  17191. any sequence of whitespace characters preceding a segment separator or
  17192. paragraph separator, and any sequence of white space characters at the end
  17193. of the line.
  17194. */
  17195. // don't bother as text is only single line
  17196. /*
  17197. L2. From the highest level found in the text to the lowest odd level on
  17198. each line, reverse any contiguous sequence of characters that are at that
  17199. level or higher.
  17200. */
  17201. // find highest level & lowest odd level
  17202. var highestLevel = -1;
  17203. var lowestOddLevel = 99;
  17204. var level;
  17205. for (i = 0, ii = levels.length; i < ii; ++i) {
  17206. level = levels[i];
  17207. if (highestLevel < level) {
  17208. highestLevel = level;
  17209. }
  17210. if (lowestOddLevel > level && isOdd(level)) {
  17211. lowestOddLevel = level;
  17212. }
  17213. }
  17214. // now reverse between those limits
  17215. for (level = highestLevel; level >= lowestOddLevel; --level) {
  17216. // find segments to reverse
  17217. var start = -1;
  17218. for (i = 0, ii = levels.length; i < ii; ++i) {
  17219. if (levels[i] < level) {
  17220. if (start >= 0) {
  17221. reverseValues(chars, start, i);
  17222. start = -1;
  17223. }
  17224. } else if (start < 0) {
  17225. start = i;
  17226. }
  17227. }
  17228. if (start >= 0) {
  17229. reverseValues(chars, start, levels.length);
  17230. }
  17231. }
  17232. /*
  17233. L3. Combining marks applied to a right-to-left base character will at this
  17234. point precede their base character. If the rendering engine expects them to
  17235. follow the base characters in the final display process, then the ordering
  17236. of the marks and the base character must be reversed.
  17237. */
  17238. // don't bother for now
  17239. /*
  17240. L4. A character that possesses the mirrored property as specified by
  17241. Section 4.7, Mirrored, must be depicted by a mirrored glyph if the resolved
  17242. directionality of that character is R.
  17243. */
  17244. // don't mirror as characters are already mirrored in the pdf
  17245. // Finally, return string
  17246. for (i = 0, ii = chars.length; i < ii; ++i) {
  17247. var ch = chars[i];
  17248. if (ch === '<' || ch === '>') {
  17249. chars[i] = '';
  17250. }
  17251. }
  17252. return createBidiText(chars.join(''), isLTR);
  17253. }
  17254. return bidi;
  17255. })();
  17256. exports.bidi = bidi;
  17257. }));
  17258. (function (root, factory) {
  17259. {
  17260. factory((root.pdfjsCoreChunkedStream = {}), root.pdfjsSharedUtil);
  17261. }
  17262. }(this, function (exports, sharedUtil) {
  17263. var MissingDataException = sharedUtil.MissingDataException;
  17264. var assert = sharedUtil.assert;
  17265. var createPromiseCapability = sharedUtil.createPromiseCapability;
  17266. var isInt = sharedUtil.isInt;
  17267. var isEmptyObj = sharedUtil.isEmptyObj;
  17268. var ChunkedStream = (function ChunkedStreamClosure() {
  17269. function ChunkedStream(length, chunkSize, manager) {
  17270. this.bytes = new Uint8Array(length);
  17271. this.start = 0;
  17272. this.pos = 0;
  17273. this.end = length;
  17274. this.chunkSize = chunkSize;
  17275. this.loadedChunks = [];
  17276. this.numChunksLoaded = 0;
  17277. this.numChunks = Math.ceil(length / chunkSize);
  17278. this.manager = manager;
  17279. this.progressiveDataLength = 0;
  17280. this.lastSuccessfulEnsureByteChunk = -1; // a single-entry cache
  17281. }
  17282. // required methods for a stream. if a particular stream does not
  17283. // implement these, an error should be thrown
  17284. ChunkedStream.prototype = {
  17285. getMissingChunks: function ChunkedStream_getMissingChunks() {
  17286. var chunks = [];
  17287. for (var chunk = 0, n = this.numChunks; chunk < n; ++chunk) {
  17288. if (!this.loadedChunks[chunk]) {
  17289. chunks.push(chunk);
  17290. }
  17291. }
  17292. return chunks;
  17293. },
  17294. getBaseStreams: function ChunkedStream_getBaseStreams() {
  17295. return [this];
  17296. },
  17297. allChunksLoaded: function ChunkedStream_allChunksLoaded() {
  17298. return this.numChunksLoaded === this.numChunks;
  17299. },
  17300. onReceiveData: function ChunkedStream_onReceiveData(begin, chunk) {
  17301. var end = begin + chunk.byteLength;
  17302. assert(begin % this.chunkSize === 0, 'Bad begin offset: ' + begin);
  17303. // Using this.length is inaccurate here since this.start can be moved
  17304. // See ChunkedStream.moveStart()
  17305. var length = this.bytes.length;
  17306. assert(end % this.chunkSize === 0 || end === length,
  17307. 'Bad end offset: ' + end);
  17308. this.bytes.set(new Uint8Array(chunk), begin);
  17309. var chunkSize = this.chunkSize;
  17310. var beginChunk = Math.floor(begin / chunkSize);
  17311. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  17312. var curChunk;
  17313. for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  17314. if (!this.loadedChunks[curChunk]) {
  17315. this.loadedChunks[curChunk] = true;
  17316. ++this.numChunksLoaded;
  17317. }
  17318. }
  17319. },
  17320. onReceiveProgressiveData:
  17321. function ChunkedStream_onReceiveProgressiveData(data) {
  17322. var position = this.progressiveDataLength;
  17323. var beginChunk = Math.floor(position / this.chunkSize);
  17324. this.bytes.set(new Uint8Array(data), position);
  17325. position += data.byteLength;
  17326. this.progressiveDataLength = position;
  17327. var endChunk = position >= this.end ? this.numChunks :
  17328. Math.floor(position / this.chunkSize);
  17329. var curChunk;
  17330. for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  17331. if (!this.loadedChunks[curChunk]) {
  17332. this.loadedChunks[curChunk] = true;
  17333. ++this.numChunksLoaded;
  17334. }
  17335. }
  17336. },
  17337. ensureByte: function ChunkedStream_ensureByte(pos) {
  17338. var chunk = Math.floor(pos / this.chunkSize);
  17339. if (chunk === this.lastSuccessfulEnsureByteChunk) {
  17340. return;
  17341. }
  17342. if (!this.loadedChunks[chunk]) {
  17343. throw new MissingDataException(pos, pos + 1);
  17344. }
  17345. this.lastSuccessfulEnsureByteChunk = chunk;
  17346. },
  17347. ensureRange: function ChunkedStream_ensureRange(begin, end) {
  17348. if (begin >= end) {
  17349. return;
  17350. }
  17351. if (end <= this.progressiveDataLength) {
  17352. return;
  17353. }
  17354. var chunkSize = this.chunkSize;
  17355. var beginChunk = Math.floor(begin / chunkSize);
  17356. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  17357. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  17358. if (!this.loadedChunks[chunk]) {
  17359. throw new MissingDataException(begin, end);
  17360. }
  17361. }
  17362. },
  17363. nextEmptyChunk: function ChunkedStream_nextEmptyChunk(beginChunk) {
  17364. var chunk, numChunks = this.numChunks;
  17365. for (var i = 0; i < numChunks; ++i) {
  17366. chunk = (beginChunk + i) % numChunks; // Wrap around to beginning
  17367. if (!this.loadedChunks[chunk]) {
  17368. return chunk;
  17369. }
  17370. }
  17371. return null;
  17372. },
  17373. hasChunk: function ChunkedStream_hasChunk(chunk) {
  17374. return !!this.loadedChunks[chunk];
  17375. },
  17376. get length() {
  17377. return this.end - this.start;
  17378. },
  17379. get isEmpty() {
  17380. return this.length === 0;
  17381. },
  17382. getByte: function ChunkedStream_getByte() {
  17383. var pos = this.pos;
  17384. if (pos >= this.end) {
  17385. return -1;
  17386. }
  17387. this.ensureByte(pos);
  17388. return this.bytes[this.pos++];
  17389. },
  17390. getUint16: function ChunkedStream_getUint16() {
  17391. var b0 = this.getByte();
  17392. var b1 = this.getByte();
  17393. if (b0 === -1 || b1 === -1) {
  17394. return -1;
  17395. }
  17396. return (b0 << 8) + b1;
  17397. },
  17398. getInt32: function ChunkedStream_getInt32() {
  17399. var b0 = this.getByte();
  17400. var b1 = this.getByte();
  17401. var b2 = this.getByte();
  17402. var b3 = this.getByte();
  17403. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  17404. },
  17405. // returns subarray of original buffer
  17406. // should only be read
  17407. getBytes: function ChunkedStream_getBytes(length) {
  17408. var bytes = this.bytes;
  17409. var pos = this.pos;
  17410. var strEnd = this.end;
  17411. if (!length) {
  17412. this.ensureRange(pos, strEnd);
  17413. return bytes.subarray(pos, strEnd);
  17414. }
  17415. var end = pos + length;
  17416. if (end > strEnd) {
  17417. end = strEnd;
  17418. }
  17419. this.ensureRange(pos, end);
  17420. this.pos = end;
  17421. return bytes.subarray(pos, end);
  17422. },
  17423. peekByte: function ChunkedStream_peekByte() {
  17424. var peekedByte = this.getByte();
  17425. this.pos--;
  17426. return peekedByte;
  17427. },
  17428. peekBytes: function ChunkedStream_peekBytes(length) {
  17429. var bytes = this.getBytes(length);
  17430. this.pos -= bytes.length;
  17431. return bytes;
  17432. },
  17433. getByteRange: function ChunkedStream_getBytes(begin, end) {
  17434. this.ensureRange(begin, end);
  17435. return this.bytes.subarray(begin, end);
  17436. },
  17437. skip: function ChunkedStream_skip(n) {
  17438. if (!n) {
  17439. n = 1;
  17440. }
  17441. this.pos += n;
  17442. },
  17443. reset: function ChunkedStream_reset() {
  17444. this.pos = this.start;
  17445. },
  17446. moveStart: function ChunkedStream_moveStart() {
  17447. this.start = this.pos;
  17448. },
  17449. makeSubStream: function ChunkedStream_makeSubStream(start, length, dict) {
  17450. this.ensureRange(start, start + length);
  17451. function ChunkedStreamSubstream() {}
  17452. ChunkedStreamSubstream.prototype = Object.create(this);
  17453. ChunkedStreamSubstream.prototype.getMissingChunks = function() {
  17454. var chunkSize = this.chunkSize;
  17455. var beginChunk = Math.floor(this.start / chunkSize);
  17456. var endChunk = Math.floor((this.end - 1) / chunkSize) + 1;
  17457. var missingChunks = [];
  17458. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  17459. if (!this.loadedChunks[chunk]) {
  17460. missingChunks.push(chunk);
  17461. }
  17462. }
  17463. return missingChunks;
  17464. };
  17465. var subStream = new ChunkedStreamSubstream();
  17466. subStream.pos = subStream.start = start;
  17467. subStream.end = start + length || this.end;
  17468. subStream.dict = dict;
  17469. return subStream;
  17470. },
  17471. isStream: true
  17472. };
  17473. return ChunkedStream;
  17474. })();
  17475. var ChunkedStreamManager = (function ChunkedStreamManagerClosure() {
  17476. function ChunkedStreamManager(length, chunkSize, url, args) {
  17477. this.stream = new ChunkedStream(length, chunkSize, this);
  17478. this.length = length;
  17479. this.chunkSize = chunkSize;
  17480. this.url = url;
  17481. this.disableAutoFetch = args.disableAutoFetch;
  17482. var msgHandler = this.msgHandler = args.msgHandler;
  17483. if (args.chunkedViewerLoading) {
  17484. msgHandler.on('OnDataRange', this.onReceiveData.bind(this));
  17485. msgHandler.on('OnDataProgress', this.onProgress.bind(this));
  17486. this.sendRequest = function ChunkedStreamManager_sendRequest(begin, end) {
  17487. msgHandler.send('RequestDataRange', { begin: begin, end: end });
  17488. };
  17489. } else {
  17490. var getXhr = function getXhr() {
  17491. return new XMLHttpRequest();
  17492. };
  17493. this.networkManager = new NetworkManager(this.url, {
  17494. getXhr: getXhr,
  17495. httpHeaders: args.httpHeaders,
  17496. withCredentials: args.withCredentials
  17497. });
  17498. this.sendRequest = function ChunkedStreamManager_sendRequest(begin, end) {
  17499. this.networkManager.requestRange(begin, end, {
  17500. onDone: this.onReceiveData.bind(this),
  17501. onProgress: this.onProgress.bind(this)
  17502. });
  17503. };
  17504. }
  17505. this.currRequestId = 0;
  17506. this.chunksNeededByRequest = {};
  17507. this.requestsByChunk = {};
  17508. this.promisesByRequest = {};
  17509. this.progressiveDataLength = 0;
  17510. this._loadedStreamCapability = createPromiseCapability();
  17511. if (args.initialData) {
  17512. this.onReceiveData({chunk: args.initialData});
  17513. }
  17514. }
  17515. ChunkedStreamManager.prototype = {
  17516. onLoadedStream: function ChunkedStreamManager_getLoadedStream() {
  17517. return this._loadedStreamCapability.promise;
  17518. },
  17519. // Get all the chunks that are not yet loaded and groups them into
  17520. // contiguous ranges to load in as few requests as possible
  17521. requestAllChunks: function ChunkedStreamManager_requestAllChunks() {
  17522. var missingChunks = this.stream.getMissingChunks();
  17523. this._requestChunks(missingChunks);
  17524. return this._loadedStreamCapability.promise;
  17525. },
  17526. _requestChunks: function ChunkedStreamManager_requestChunks(chunks) {
  17527. var requestId = this.currRequestId++;
  17528. var chunksNeeded;
  17529. var i, ii;
  17530. this.chunksNeededByRequest[requestId] = chunksNeeded = {};
  17531. for (i = 0, ii = chunks.length; i < ii; i++) {
  17532. if (!this.stream.hasChunk(chunks[i])) {
  17533. chunksNeeded[chunks[i]] = true;
  17534. }
  17535. }
  17536. if (isEmptyObj(chunksNeeded)) {
  17537. return Promise.resolve();
  17538. }
  17539. var capability = createPromiseCapability();
  17540. this.promisesByRequest[requestId] = capability;
  17541. var chunksToRequest = [];
  17542. for (var chunk in chunksNeeded) {
  17543. chunk = chunk | 0;
  17544. if (!(chunk in this.requestsByChunk)) {
  17545. this.requestsByChunk[chunk] = [];
  17546. chunksToRequest.push(chunk);
  17547. }
  17548. this.requestsByChunk[chunk].push(requestId);
  17549. }
  17550. if (!chunksToRequest.length) {
  17551. return capability.promise;
  17552. }
  17553. var groupedChunksToRequest = this.groupChunks(chunksToRequest);
  17554. for (i = 0; i < groupedChunksToRequest.length; ++i) {
  17555. var groupedChunk = groupedChunksToRequest[i];
  17556. var begin = groupedChunk.beginChunk * this.chunkSize;
  17557. var end = Math.min(groupedChunk.endChunk * this.chunkSize, this.length);
  17558. this.sendRequest(begin, end);
  17559. }
  17560. return capability.promise;
  17561. },
  17562. getStream: function ChunkedStreamManager_getStream() {
  17563. return this.stream;
  17564. },
  17565. // Loads any chunks in the requested range that are not yet loaded
  17566. requestRange: function ChunkedStreamManager_requestRange(begin, end) {
  17567. end = Math.min(end, this.length);
  17568. var beginChunk = this.getBeginChunk(begin);
  17569. var endChunk = this.getEndChunk(end);
  17570. var chunks = [];
  17571. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  17572. chunks.push(chunk);
  17573. }
  17574. return this._requestChunks(chunks);
  17575. },
  17576. requestRanges: function ChunkedStreamManager_requestRanges(ranges) {
  17577. ranges = ranges || [];
  17578. var chunksToRequest = [];
  17579. for (var i = 0; i < ranges.length; i++) {
  17580. var beginChunk = this.getBeginChunk(ranges[i].begin);
  17581. var endChunk = this.getEndChunk(ranges[i].end);
  17582. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  17583. if (chunksToRequest.indexOf(chunk) < 0) {
  17584. chunksToRequest.push(chunk);
  17585. }
  17586. }
  17587. }
  17588. chunksToRequest.sort(function(a, b) { return a - b; });
  17589. return this._requestChunks(chunksToRequest);
  17590. },
  17591. // Groups a sorted array of chunks into as few contiguous larger
  17592. // chunks as possible
  17593. groupChunks: function ChunkedStreamManager_groupChunks(chunks) {
  17594. var groupedChunks = [];
  17595. var beginChunk = -1;
  17596. var prevChunk = -1;
  17597. for (var i = 0; i < chunks.length; ++i) {
  17598. var chunk = chunks[i];
  17599. if (beginChunk < 0) {
  17600. beginChunk = chunk;
  17601. }
  17602. if (prevChunk >= 0 && prevChunk + 1 !== chunk) {
  17603. groupedChunks.push({ beginChunk: beginChunk,
  17604. endChunk: prevChunk + 1 });
  17605. beginChunk = chunk;
  17606. }
  17607. if (i + 1 === chunks.length) {
  17608. groupedChunks.push({ beginChunk: beginChunk,
  17609. endChunk: chunk + 1 });
  17610. }
  17611. prevChunk = chunk;
  17612. }
  17613. return groupedChunks;
  17614. },
  17615. onProgress: function ChunkedStreamManager_onProgress(args) {
  17616. var bytesLoaded = (this.stream.numChunksLoaded * this.chunkSize +
  17617. args.loaded);
  17618. this.msgHandler.send('DocProgress', {
  17619. loaded: bytesLoaded,
  17620. total: this.length
  17621. });
  17622. },
  17623. onReceiveData: function ChunkedStreamManager_onReceiveData(args) {
  17624. var chunk = args.chunk;
  17625. var isProgressive = args.begin === undefined;
  17626. var begin = isProgressive ? this.progressiveDataLength : args.begin;
  17627. var end = begin + chunk.byteLength;
  17628. var beginChunk = Math.floor(begin / this.chunkSize);
  17629. var endChunk = end < this.length ? Math.floor(end / this.chunkSize) :
  17630. Math.ceil(end / this.chunkSize);
  17631. if (isProgressive) {
  17632. this.stream.onReceiveProgressiveData(chunk);
  17633. this.progressiveDataLength = end;
  17634. } else {
  17635. this.stream.onReceiveData(begin, chunk);
  17636. }
  17637. if (this.stream.allChunksLoaded()) {
  17638. this._loadedStreamCapability.resolve(this.stream);
  17639. }
  17640. var loadedRequests = [];
  17641. var i, requestId;
  17642. for (chunk = beginChunk; chunk < endChunk; ++chunk) {
  17643. // The server might return more chunks than requested
  17644. var requestIds = this.requestsByChunk[chunk] || [];
  17645. delete this.requestsByChunk[chunk];
  17646. for (i = 0; i < requestIds.length; ++i) {
  17647. requestId = requestIds[i];
  17648. var chunksNeeded = this.chunksNeededByRequest[requestId];
  17649. if (chunk in chunksNeeded) {
  17650. delete chunksNeeded[chunk];
  17651. }
  17652. if (!isEmptyObj(chunksNeeded)) {
  17653. continue;
  17654. }
  17655. loadedRequests.push(requestId);
  17656. }
  17657. }
  17658. // If there are no pending requests, automatically fetch the next
  17659. // unfetched chunk of the PDF
  17660. if (!this.disableAutoFetch && isEmptyObj(this.requestsByChunk)) {
  17661. var nextEmptyChunk;
  17662. if (this.stream.numChunksLoaded === 1) {
  17663. // This is a special optimization so that after fetching the first
  17664. // chunk, rather than fetching the second chunk, we fetch the last
  17665. // chunk.
  17666. var lastChunk = this.stream.numChunks - 1;
  17667. if (!this.stream.hasChunk(lastChunk)) {
  17668. nextEmptyChunk = lastChunk;
  17669. }
  17670. } else {
  17671. nextEmptyChunk = this.stream.nextEmptyChunk(endChunk);
  17672. }
  17673. if (isInt(nextEmptyChunk)) {
  17674. this._requestChunks([nextEmptyChunk]);
  17675. }
  17676. }
  17677. for (i = 0; i < loadedRequests.length; ++i) {
  17678. requestId = loadedRequests[i];
  17679. var capability = this.promisesByRequest[requestId];
  17680. delete this.promisesByRequest[requestId];
  17681. capability.resolve();
  17682. }
  17683. this.msgHandler.send('DocProgress', {
  17684. loaded: this.stream.numChunksLoaded * this.chunkSize,
  17685. total: this.length
  17686. });
  17687. },
  17688. onError: function ChunkedStreamManager_onError(err) {
  17689. this._loadedStreamCapability.reject(err);
  17690. },
  17691. getBeginChunk: function ChunkedStreamManager_getBeginChunk(begin) {
  17692. var chunk = Math.floor(begin / this.chunkSize);
  17693. return chunk;
  17694. },
  17695. getEndChunk: function ChunkedStreamManager_getEndChunk(end) {
  17696. var chunk = Math.floor((end - 1) / this.chunkSize) + 1;
  17697. return chunk;
  17698. },
  17699. abort: function ChunkedStreamManager_abort() {
  17700. if (this.networkManager) {
  17701. this.networkManager.abortAllRequests();
  17702. }
  17703. for(var requestId in this.promisesByRequest) {
  17704. var capability = this.promisesByRequest[requestId];
  17705. capability.reject(new Error('Request was aborted'));
  17706. }
  17707. }
  17708. };
  17709. return ChunkedStreamManager;
  17710. })();
  17711. exports.ChunkedStream = ChunkedStream;
  17712. exports.ChunkedStreamManager = ChunkedStreamManager;
  17713. }));
  17714. (function (root, factory) {
  17715. {
  17716. factory((root.pdfjsCoreJbig2 = {}), root.pdfjsSharedUtil,
  17717. root.pdfjsCoreArithmeticDecoder);
  17718. }
  17719. }(this, function (exports, sharedUtil, coreArithmeticDecoder) {
  17720. var error = sharedUtil.error;
  17721. var log2 = sharedUtil.log2;
  17722. var readInt8 = sharedUtil.readInt8;
  17723. var readUint16 = sharedUtil.readUint16;
  17724. var readUint32 = sharedUtil.readUint32;
  17725. var shadow = sharedUtil.shadow;
  17726. var ArithmeticDecoder = coreArithmeticDecoder.ArithmeticDecoder;
  17727. var Jbig2Image = (function Jbig2ImageClosure() {
  17728. // Utility data structures
  17729. function ContextCache() {}
  17730. ContextCache.prototype = {
  17731. getContexts: function(id) {
  17732. if (id in this) {
  17733. return this[id];
  17734. }
  17735. return (this[id] = new Int8Array(1 << 16));
  17736. }
  17737. };
  17738. function DecodingContext(data, start, end) {
  17739. this.data = data;
  17740. this.start = start;
  17741. this.end = end;
  17742. }
  17743. DecodingContext.prototype = {
  17744. get decoder() {
  17745. var decoder = new ArithmeticDecoder(this.data, this.start, this.end);
  17746. return shadow(this, 'decoder', decoder);
  17747. },
  17748. get contextCache() {
  17749. var cache = new ContextCache();
  17750. return shadow(this, 'contextCache', cache);
  17751. }
  17752. };
  17753. // Annex A. Arithmetic Integer Decoding Procedure
  17754. // A.2 Procedure for decoding values
  17755. function decodeInteger(contextCache, procedure, decoder) {
  17756. var contexts = contextCache.getContexts(procedure);
  17757. var prev = 1;
  17758. function readBits(length) {
  17759. var v = 0;
  17760. for (var i = 0; i < length; i++) {
  17761. var bit = decoder.readBit(contexts, prev);
  17762. prev = (prev < 256 ? (prev << 1) | bit :
  17763. (((prev << 1) | bit) & 511) | 256);
  17764. v = (v << 1) | bit;
  17765. }
  17766. return v >>> 0;
  17767. }
  17768. var sign = readBits(1);
  17769. var value = readBits(1) ?
  17770. (readBits(1) ?
  17771. (readBits(1) ?
  17772. (readBits(1) ?
  17773. (readBits(1) ?
  17774. (readBits(32) + 4436) :
  17775. readBits(12) + 340) :
  17776. readBits(8) + 84) :
  17777. readBits(6) + 20) :
  17778. readBits(4) + 4) :
  17779. readBits(2);
  17780. return (sign === 0 ? value : (value > 0 ? -value : null));
  17781. }
  17782. // A.3 The IAID decoding procedure
  17783. function decodeIAID(contextCache, decoder, codeLength) {
  17784. var contexts = contextCache.getContexts('IAID');
  17785. var prev = 1;
  17786. for (var i = 0; i < codeLength; i++) {
  17787. var bit = decoder.readBit(contexts, prev);
  17788. prev = (prev << 1) | bit;
  17789. }
  17790. if (codeLength < 31) {
  17791. return prev & ((1 << codeLength) - 1);
  17792. }
  17793. return prev & 0x7FFFFFFF;
  17794. }
  17795. // 7.3 Segment types
  17796. var SegmentTypes = [
  17797. 'SymbolDictionary', null, null, null, 'IntermediateTextRegion', null,
  17798. 'ImmediateTextRegion', 'ImmediateLosslessTextRegion', null, null, null,
  17799. null, null, null, null, null, 'patternDictionary', null, null, null,
  17800. 'IntermediateHalftoneRegion', null, 'ImmediateHalftoneRegion',
  17801. 'ImmediateLosslessHalftoneRegion', null, null, null, null, null, null, null,
  17802. null, null, null, null, null, 'IntermediateGenericRegion', null,
  17803. 'ImmediateGenericRegion', 'ImmediateLosslessGenericRegion',
  17804. 'IntermediateGenericRefinementRegion', null,
  17805. 'ImmediateGenericRefinementRegion',
  17806. 'ImmediateLosslessGenericRefinementRegion', null, null, null, null,
  17807. 'PageInformation', 'EndOfPage', 'EndOfStripe', 'EndOfFile', 'Profiles',
  17808. 'Tables', null, null, null, null, null, null, null, null,
  17809. 'Extension'
  17810. ];
  17811. var CodingTemplates = [
  17812. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: -2, y: -1},
  17813. {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: 2, y: -1},
  17814. {x: -4, y: 0}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}],
  17815. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: 2, y: -2},
  17816. {x: -2, y: -1}, {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1},
  17817. {x: 2, y: -1}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}],
  17818. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: -2, y: -1},
  17819. {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: -2, y: 0},
  17820. {x: -1, y: 0}],
  17821. [{x: -3, y: -1}, {x: -2, y: -1}, {x: -1, y: -1}, {x: 0, y: -1},
  17822. {x: 1, y: -1}, {x: -4, y: 0}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}]
  17823. ];
  17824. var RefinementTemplates = [
  17825. {
  17826. coding: [{x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}],
  17827. reference: [{x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}, {x: 0, y: 0},
  17828. {x: 1, y: 0}, {x: -1, y: 1}, {x: 0, y: 1}, {x: 1, y: 1}]
  17829. },
  17830. {
  17831. coding: [{x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}],
  17832. reference: [{x: 0, y: -1}, {x: -1, y: 0}, {x: 0, y: 0}, {x: 1, y: 0},
  17833. {x: 0, y: 1}, {x: 1, y: 1}]
  17834. }
  17835. ];
  17836. // See 6.2.5.7 Decoding the bitmap.
  17837. var ReusedContexts = [
  17838. 0x9B25, // 10011 0110010 0101
  17839. 0x0795, // 0011 110010 101
  17840. 0x00E5, // 001 11001 01
  17841. 0x0195 // 011001 0101
  17842. ];
  17843. var RefinementReusedContexts = [
  17844. 0x0020, // '000' + '0' (coding) + '00010000' + '0' (reference)
  17845. 0x0008 // '0000' + '001000'
  17846. ];
  17847. function decodeBitmapTemplate0(width, height, decodingContext) {
  17848. var decoder = decodingContext.decoder;
  17849. var contexts = decodingContext.contextCache.getContexts('GB');
  17850. var contextLabel, i, j, pixel, row, row1, row2, bitmap = [];
  17851. // ...ooooo....
  17852. // ..ooooooo... Context template for current pixel (X)
  17853. // .ooooX...... (concatenate values of 'o'-pixels to get contextLabel)
  17854. var OLD_PIXEL_MASK = 0x7BF7; // 01111 0111111 0111
  17855. for (i = 0; i < height; i++) {
  17856. row = bitmap[i] = new Uint8Array(width);
  17857. row1 = (i < 1) ? row : bitmap[i - 1];
  17858. row2 = (i < 2) ? row : bitmap[i - 2];
  17859. // At the beginning of each row:
  17860. // Fill contextLabel with pixels that are above/right of (X)
  17861. contextLabel = (row2[0] << 13) | (row2[1] << 12) | (row2[2] << 11) |
  17862. (row1[0] << 7) | (row1[1] << 6) | (row1[2] << 5) |
  17863. (row1[3] << 4);
  17864. for (j = 0; j < width; j++) {
  17865. row[j] = pixel = decoder.readBit(contexts, contextLabel);
  17866. // At each pixel: Clear contextLabel pixels that are shifted
  17867. // out of the context, then add new ones.
  17868. contextLabel = ((contextLabel & OLD_PIXEL_MASK) << 1) |
  17869. (j + 3 < width ? row2[j + 3] << 11 : 0) |
  17870. (j + 4 < width ? row1[j + 4] << 4 : 0) | pixel;
  17871. }
  17872. }
  17873. return bitmap;
  17874. }
  17875. // 6.2 Generic Region Decoding Procedure
  17876. function decodeBitmap(mmr, width, height, templateIndex, prediction, skip, at,
  17877. decodingContext) {
  17878. if (mmr) {
  17879. error('JBIG2 error: MMR encoding is not supported');
  17880. }
  17881. // Use optimized version for the most common case
  17882. if (templateIndex === 0 && !skip && !prediction && at.length === 4 &&
  17883. at[0].x === 3 && at[0].y === -1 && at[1].x === -3 && at[1].y === -1 &&
  17884. at[2].x === 2 && at[2].y === -2 && at[3].x === -2 && at[3].y === -2) {
  17885. return decodeBitmapTemplate0(width, height, decodingContext);
  17886. }
  17887. var useskip = !!skip;
  17888. var template = CodingTemplates[templateIndex].concat(at);
  17889. // Sorting is non-standard, and it is not required. But sorting increases
  17890. // the number of template bits that can be reused from the previous
  17891. // contextLabel in the main loop.
  17892. template.sort(function (a, b) {
  17893. return (a.y - b.y) || (a.x - b.x);
  17894. });
  17895. var templateLength = template.length;
  17896. var templateX = new Int8Array(templateLength);
  17897. var templateY = new Int8Array(templateLength);
  17898. var changingTemplateEntries = [];
  17899. var reuseMask = 0, minX = 0, maxX = 0, minY = 0;
  17900. var c, k;
  17901. for (k = 0; k < templateLength; k++) {
  17902. templateX[k] = template[k].x;
  17903. templateY[k] = template[k].y;
  17904. minX = Math.min(minX, template[k].x);
  17905. maxX = Math.max(maxX, template[k].x);
  17906. minY = Math.min(minY, template[k].y);
  17907. // Check if the template pixel appears in two consecutive context labels,
  17908. // so it can be reused. Otherwise, we add it to the list of changing
  17909. // template entries.
  17910. if (k < templateLength - 1 &&
  17911. template[k].y === template[k + 1].y &&
  17912. template[k].x === template[k + 1].x - 1) {
  17913. reuseMask |= 1 << (templateLength - 1 - k);
  17914. } else {
  17915. changingTemplateEntries.push(k);
  17916. }
  17917. }
  17918. var changingEntriesLength = changingTemplateEntries.length;
  17919. var changingTemplateX = new Int8Array(changingEntriesLength);
  17920. var changingTemplateY = new Int8Array(changingEntriesLength);
  17921. var changingTemplateBit = new Uint16Array(changingEntriesLength);
  17922. for (c = 0; c < changingEntriesLength; c++) {
  17923. k = changingTemplateEntries[c];
  17924. changingTemplateX[c] = template[k].x;
  17925. changingTemplateY[c] = template[k].y;
  17926. changingTemplateBit[c] = 1 << (templateLength - 1 - k);
  17927. }
  17928. // Get the safe bounding box edges from the width, height, minX, maxX, minY
  17929. var sbb_left = -minX;
  17930. var sbb_top = -minY;
  17931. var sbb_right = width - maxX;
  17932. var pseudoPixelContext = ReusedContexts[templateIndex];
  17933. var row = new Uint8Array(width);
  17934. var bitmap = [];
  17935. var decoder = decodingContext.decoder;
  17936. var contexts = decodingContext.contextCache.getContexts('GB');
  17937. var ltp = 0, j, i0, j0, contextLabel = 0, bit, shift;
  17938. for (var i = 0; i < height; i++) {
  17939. if (prediction) {
  17940. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  17941. ltp ^= sltp;
  17942. if (ltp) {
  17943. bitmap.push(row); // duplicate previous row
  17944. continue;
  17945. }
  17946. }
  17947. row = new Uint8Array(row);
  17948. bitmap.push(row);
  17949. for (j = 0; j < width; j++) {
  17950. if (useskip && skip[i][j]) {
  17951. row[j] = 0;
  17952. continue;
  17953. }
  17954. // Are we in the middle of a scanline, so we can reuse contextLabel
  17955. // bits?
  17956. if (j >= sbb_left && j < sbb_right && i >= sbb_top) {
  17957. // If yes, we can just shift the bits that are reusable and only
  17958. // fetch the remaining ones.
  17959. contextLabel = (contextLabel << 1) & reuseMask;
  17960. for (k = 0; k < changingEntriesLength; k++) {
  17961. i0 = i + changingTemplateY[k];
  17962. j0 = j + changingTemplateX[k];
  17963. bit = bitmap[i0][j0];
  17964. if (bit) {
  17965. bit = changingTemplateBit[k];
  17966. contextLabel |= bit;
  17967. }
  17968. }
  17969. } else {
  17970. // compute the contextLabel from scratch
  17971. contextLabel = 0;
  17972. shift = templateLength - 1;
  17973. for (k = 0; k < templateLength; k++, shift--) {
  17974. j0 = j + templateX[k];
  17975. if (j0 >= 0 && j0 < width) {
  17976. i0 = i + templateY[k];
  17977. if (i0 >= 0) {
  17978. bit = bitmap[i0][j0];
  17979. if (bit) {
  17980. contextLabel |= bit << shift;
  17981. }
  17982. }
  17983. }
  17984. }
  17985. }
  17986. var pixel = decoder.readBit(contexts, contextLabel);
  17987. row[j] = pixel;
  17988. }
  17989. }
  17990. return bitmap;
  17991. }
  17992. // 6.3.2 Generic Refinement Region Decoding Procedure
  17993. function decodeRefinement(width, height, templateIndex, referenceBitmap,
  17994. offsetX, offsetY, prediction, at,
  17995. decodingContext) {
  17996. var codingTemplate = RefinementTemplates[templateIndex].coding;
  17997. if (templateIndex === 0) {
  17998. codingTemplate = codingTemplate.concat([at[0]]);
  17999. }
  18000. var codingTemplateLength = codingTemplate.length;
  18001. var codingTemplateX = new Int32Array(codingTemplateLength);
  18002. var codingTemplateY = new Int32Array(codingTemplateLength);
  18003. var k;
  18004. for (k = 0; k < codingTemplateLength; k++) {
  18005. codingTemplateX[k] = codingTemplate[k].x;
  18006. codingTemplateY[k] = codingTemplate[k].y;
  18007. }
  18008. var referenceTemplate = RefinementTemplates[templateIndex].reference;
  18009. if (templateIndex === 0) {
  18010. referenceTemplate = referenceTemplate.concat([at[1]]);
  18011. }
  18012. var referenceTemplateLength = referenceTemplate.length;
  18013. var referenceTemplateX = new Int32Array(referenceTemplateLength);
  18014. var referenceTemplateY = new Int32Array(referenceTemplateLength);
  18015. for (k = 0; k < referenceTemplateLength; k++) {
  18016. referenceTemplateX[k] = referenceTemplate[k].x;
  18017. referenceTemplateY[k] = referenceTemplate[k].y;
  18018. }
  18019. var referenceWidth = referenceBitmap[0].length;
  18020. var referenceHeight = referenceBitmap.length;
  18021. var pseudoPixelContext = RefinementReusedContexts[templateIndex];
  18022. var bitmap = [];
  18023. var decoder = decodingContext.decoder;
  18024. var contexts = decodingContext.contextCache.getContexts('GR');
  18025. var ltp = 0;
  18026. for (var i = 0; i < height; i++) {
  18027. if (prediction) {
  18028. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  18029. ltp ^= sltp;
  18030. if (ltp) {
  18031. error('JBIG2 error: prediction is not supported');
  18032. }
  18033. }
  18034. var row = new Uint8Array(width);
  18035. bitmap.push(row);
  18036. for (var j = 0; j < width; j++) {
  18037. var i0, j0;
  18038. var contextLabel = 0;
  18039. for (k = 0; k < codingTemplateLength; k++) {
  18040. i0 = i + codingTemplateY[k];
  18041. j0 = j + codingTemplateX[k];
  18042. if (i0 < 0 || j0 < 0 || j0 >= width) {
  18043. contextLabel <<= 1; // out of bound pixel
  18044. } else {
  18045. contextLabel = (contextLabel << 1) | bitmap[i0][j0];
  18046. }
  18047. }
  18048. for (k = 0; k < referenceTemplateLength; k++) {
  18049. i0 = i + referenceTemplateY[k] + offsetY;
  18050. j0 = j + referenceTemplateX[k] + offsetX;
  18051. if (i0 < 0 || i0 >= referenceHeight || j0 < 0 ||
  18052. j0 >= referenceWidth) {
  18053. contextLabel <<= 1; // out of bound pixel
  18054. } else {
  18055. contextLabel = (contextLabel << 1) | referenceBitmap[i0][j0];
  18056. }
  18057. }
  18058. var pixel = decoder.readBit(contexts, contextLabel);
  18059. row[j] = pixel;
  18060. }
  18061. }
  18062. return bitmap;
  18063. }
  18064. // 6.5.5 Decoding the symbol dictionary
  18065. function decodeSymbolDictionary(huffman, refinement, symbols,
  18066. numberOfNewSymbols, numberOfExportedSymbols,
  18067. huffmanTables, templateIndex, at,
  18068. refinementTemplateIndex, refinementAt,
  18069. decodingContext) {
  18070. if (huffman) {
  18071. error('JBIG2 error: huffman is not supported');
  18072. }
  18073. var newSymbols = [];
  18074. var currentHeight = 0;
  18075. var symbolCodeLength = log2(symbols.length + numberOfNewSymbols);
  18076. var decoder = decodingContext.decoder;
  18077. var contextCache = decodingContext.contextCache;
  18078. while (newSymbols.length < numberOfNewSymbols) {
  18079. var deltaHeight = decodeInteger(contextCache, 'IADH', decoder); // 6.5.6
  18080. currentHeight += deltaHeight;
  18081. var currentWidth = 0;
  18082. var totalWidth = 0;
  18083. while (true) {
  18084. var deltaWidth = decodeInteger(contextCache, 'IADW', decoder); // 6.5.7
  18085. if (deltaWidth === null) {
  18086. break; // OOB
  18087. }
  18088. currentWidth += deltaWidth;
  18089. totalWidth += currentWidth;
  18090. var bitmap;
  18091. if (refinement) {
  18092. // 6.5.8.2 Refinement/aggregate-coded symbol bitmap
  18093. var numberOfInstances = decodeInteger(contextCache, 'IAAI', decoder);
  18094. if (numberOfInstances > 1) {
  18095. bitmap = decodeTextRegion(huffman, refinement,
  18096. currentWidth, currentHeight, 0,
  18097. numberOfInstances, 1, //strip size
  18098. symbols.concat(newSymbols),
  18099. symbolCodeLength,
  18100. 0, //transposed
  18101. 0, //ds offset
  18102. 1, //top left 7.4.3.1.1
  18103. 0, //OR operator
  18104. huffmanTables,
  18105. refinementTemplateIndex, refinementAt,
  18106. decodingContext);
  18107. } else {
  18108. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  18109. var rdx = decodeInteger(contextCache, 'IARDX', decoder); // 6.4.11.3
  18110. var rdy = decodeInteger(contextCache, 'IARDY', decoder); // 6.4.11.4
  18111. var symbol = (symbolId < symbols.length ? symbols[symbolId] :
  18112. newSymbols[symbolId - symbols.length]);
  18113. bitmap = decodeRefinement(currentWidth, currentHeight,
  18114. refinementTemplateIndex, symbol, rdx, rdy, false, refinementAt,
  18115. decodingContext);
  18116. }
  18117. } else {
  18118. // 6.5.8.1 Direct-coded symbol bitmap
  18119. bitmap = decodeBitmap(false, currentWidth, currentHeight,
  18120. templateIndex, false, null, at, decodingContext);
  18121. }
  18122. newSymbols.push(bitmap);
  18123. }
  18124. }
  18125. // 6.5.10 Exported symbols
  18126. var exportedSymbols = [];
  18127. var flags = [], currentFlag = false;
  18128. var totalSymbolsLength = symbols.length + numberOfNewSymbols;
  18129. while (flags.length < totalSymbolsLength) {
  18130. var runLength = decodeInteger(contextCache, 'IAEX', decoder);
  18131. while (runLength--) {
  18132. flags.push(currentFlag);
  18133. }
  18134. currentFlag = !currentFlag;
  18135. }
  18136. for (var i = 0, ii = symbols.length; i < ii; i++) {
  18137. if (flags[i]) {
  18138. exportedSymbols.push(symbols[i]);
  18139. }
  18140. }
  18141. for (var j = 0; j < numberOfNewSymbols; i++, j++) {
  18142. if (flags[i]) {
  18143. exportedSymbols.push(newSymbols[j]);
  18144. }
  18145. }
  18146. return exportedSymbols;
  18147. }
  18148. function decodeTextRegion(huffman, refinement, width, height,
  18149. defaultPixelValue, numberOfSymbolInstances,
  18150. stripSize, inputSymbols, symbolCodeLength,
  18151. transposed, dsOffset, referenceCorner,
  18152. combinationOperator, huffmanTables,
  18153. refinementTemplateIndex, refinementAt,
  18154. decodingContext) {
  18155. if (huffman) {
  18156. error('JBIG2 error: huffman is not supported');
  18157. }
  18158. // Prepare bitmap
  18159. var bitmap = [];
  18160. var i, row;
  18161. for (i = 0; i < height; i++) {
  18162. row = new Uint8Array(width);
  18163. if (defaultPixelValue) {
  18164. for (var j = 0; j < width; j++) {
  18165. row[j] = defaultPixelValue;
  18166. }
  18167. }
  18168. bitmap.push(row);
  18169. }
  18170. var decoder = decodingContext.decoder;
  18171. var contextCache = decodingContext.contextCache;
  18172. var stripT = -decodeInteger(contextCache, 'IADT', decoder); // 6.4.6
  18173. var firstS = 0;
  18174. i = 0;
  18175. while (i < numberOfSymbolInstances) {
  18176. var deltaT = decodeInteger(contextCache, 'IADT', decoder); // 6.4.6
  18177. stripT += deltaT;
  18178. var deltaFirstS = decodeInteger(contextCache, 'IAFS', decoder); // 6.4.7
  18179. firstS += deltaFirstS;
  18180. var currentS = firstS;
  18181. do {
  18182. var currentT = (stripSize === 1 ? 0 :
  18183. decodeInteger(contextCache, 'IAIT', decoder)); // 6.4.9
  18184. var t = stripSize * stripT + currentT;
  18185. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  18186. var applyRefinement = (refinement &&
  18187. decodeInteger(contextCache, 'IARI', decoder));
  18188. var symbolBitmap = inputSymbols[symbolId];
  18189. var symbolWidth = symbolBitmap[0].length;
  18190. var symbolHeight = symbolBitmap.length;
  18191. if (applyRefinement) {
  18192. var rdw = decodeInteger(contextCache, 'IARDW', decoder); // 6.4.11.1
  18193. var rdh = decodeInteger(contextCache, 'IARDH', decoder); // 6.4.11.2
  18194. var rdx = decodeInteger(contextCache, 'IARDX', decoder); // 6.4.11.3
  18195. var rdy = decodeInteger(contextCache, 'IARDY', decoder); // 6.4.11.4
  18196. symbolWidth += rdw;
  18197. symbolHeight += rdh;
  18198. symbolBitmap = decodeRefinement(symbolWidth, symbolHeight,
  18199. refinementTemplateIndex, symbolBitmap, (rdw >> 1) + rdx,
  18200. (rdh >> 1) + rdy, false, refinementAt,
  18201. decodingContext);
  18202. }
  18203. var offsetT = t - ((referenceCorner & 1) ? 0 : symbolHeight);
  18204. var offsetS = currentS - ((referenceCorner & 2) ? symbolWidth : 0);
  18205. var s2, t2, symbolRow;
  18206. if (transposed) {
  18207. // Place Symbol Bitmap from T1,S1
  18208. for (s2 = 0; s2 < symbolHeight; s2++) {
  18209. row = bitmap[offsetS + s2];
  18210. if (!row) {
  18211. continue;
  18212. }
  18213. symbolRow = symbolBitmap[s2];
  18214. // To ignore Parts of Symbol bitmap which goes
  18215. // outside bitmap region
  18216. var maxWidth = Math.min(width - offsetT, symbolWidth);
  18217. switch (combinationOperator) {
  18218. case 0: // OR
  18219. for (t2 = 0; t2 < maxWidth; t2++) {
  18220. row[offsetT + t2] |= symbolRow[t2];
  18221. }
  18222. break;
  18223. case 2: // XOR
  18224. for (t2 = 0; t2 < maxWidth; t2++) {
  18225. row[offsetT + t2] ^= symbolRow[t2];
  18226. }
  18227. break;
  18228. default:
  18229. error('JBIG2 error: operator ' + combinationOperator +
  18230. ' is not supported');
  18231. }
  18232. }
  18233. currentS += symbolHeight - 1;
  18234. } else {
  18235. for (t2 = 0; t2 < symbolHeight; t2++) {
  18236. row = bitmap[offsetT + t2];
  18237. if (!row) {
  18238. continue;
  18239. }
  18240. symbolRow = symbolBitmap[t2];
  18241. switch (combinationOperator) {
  18242. case 0: // OR
  18243. for (s2 = 0; s2 < symbolWidth; s2++) {
  18244. row[offsetS + s2] |= symbolRow[s2];
  18245. }
  18246. break;
  18247. case 2: // XOR
  18248. for (s2 = 0; s2 < symbolWidth; s2++) {
  18249. row[offsetS + s2] ^= symbolRow[s2];
  18250. }
  18251. break;
  18252. default:
  18253. error('JBIG2 error: operator ' + combinationOperator +
  18254. ' is not supported');
  18255. }
  18256. }
  18257. currentS += symbolWidth - 1;
  18258. }
  18259. i++;
  18260. var deltaS = decodeInteger(contextCache, 'IADS', decoder); // 6.4.8
  18261. if (deltaS === null) {
  18262. break; // OOB
  18263. }
  18264. currentS += deltaS + dsOffset;
  18265. } while (true);
  18266. }
  18267. return bitmap;
  18268. }
  18269. function readSegmentHeader(data, start) {
  18270. var segmentHeader = {};
  18271. segmentHeader.number = readUint32(data, start);
  18272. var flags = data[start + 4];
  18273. var segmentType = flags & 0x3F;
  18274. if (!SegmentTypes[segmentType]) {
  18275. error('JBIG2 error: invalid segment type: ' + segmentType);
  18276. }
  18277. segmentHeader.type = segmentType;
  18278. segmentHeader.typeName = SegmentTypes[segmentType];
  18279. segmentHeader.deferredNonRetain = !!(flags & 0x80);
  18280. var pageAssociationFieldSize = !!(flags & 0x40);
  18281. var referredFlags = data[start + 5];
  18282. var referredToCount = (referredFlags >> 5) & 7;
  18283. var retainBits = [referredFlags & 31];
  18284. var position = start + 6;
  18285. if (referredFlags === 7) {
  18286. referredToCount = readUint32(data, position - 1) & 0x1FFFFFFF;
  18287. position += 3;
  18288. var bytes = (referredToCount + 7) >> 3;
  18289. retainBits[0] = data[position++];
  18290. while (--bytes > 0) {
  18291. retainBits.push(data[position++]);
  18292. }
  18293. } else if (referredFlags === 5 || referredFlags === 6) {
  18294. error('JBIG2 error: invalid referred-to flags');
  18295. }
  18296. segmentHeader.retainBits = retainBits;
  18297. var referredToSegmentNumberSize = (segmentHeader.number <= 256 ? 1 :
  18298. (segmentHeader.number <= 65536 ? 2 : 4));
  18299. var referredTo = [];
  18300. var i, ii;
  18301. for (i = 0; i < referredToCount; i++) {
  18302. var number = (referredToSegmentNumberSize === 1 ? data[position] :
  18303. (referredToSegmentNumberSize === 2 ? readUint16(data, position) :
  18304. readUint32(data, position)));
  18305. referredTo.push(number);
  18306. position += referredToSegmentNumberSize;
  18307. }
  18308. segmentHeader.referredTo = referredTo;
  18309. if (!pageAssociationFieldSize) {
  18310. segmentHeader.pageAssociation = data[position++];
  18311. } else {
  18312. segmentHeader.pageAssociation = readUint32(data, position);
  18313. position += 4;
  18314. }
  18315. segmentHeader.length = readUint32(data, position);
  18316. position += 4;
  18317. if (segmentHeader.length === 0xFFFFFFFF) {
  18318. // 7.2.7 Segment data length, unknown segment length
  18319. if (segmentType === 38) { // ImmediateGenericRegion
  18320. var genericRegionInfo = readRegionSegmentInformation(data, position);
  18321. var genericRegionSegmentFlags = data[position +
  18322. RegionSegmentInformationFieldLength];
  18323. var genericRegionMmr = !!(genericRegionSegmentFlags & 1);
  18324. // searching for the segment end
  18325. var searchPatternLength = 6;
  18326. var searchPattern = new Uint8Array(searchPatternLength);
  18327. if (!genericRegionMmr) {
  18328. searchPattern[0] = 0xFF;
  18329. searchPattern[1] = 0xAC;
  18330. }
  18331. searchPattern[2] = (genericRegionInfo.height >>> 24) & 0xFF;
  18332. searchPattern[3] = (genericRegionInfo.height >> 16) & 0xFF;
  18333. searchPattern[4] = (genericRegionInfo.height >> 8) & 0xFF;
  18334. searchPattern[5] = genericRegionInfo.height & 0xFF;
  18335. for (i = position, ii = data.length; i < ii; i++) {
  18336. var j = 0;
  18337. while (j < searchPatternLength && searchPattern[j] === data[i + j]) {
  18338. j++;
  18339. }
  18340. if (j === searchPatternLength) {
  18341. segmentHeader.length = i + searchPatternLength;
  18342. break;
  18343. }
  18344. }
  18345. if (segmentHeader.length === 0xFFFFFFFF) {
  18346. error('JBIG2 error: segment end was not found');
  18347. }
  18348. } else {
  18349. error('JBIG2 error: invalid unknown segment length');
  18350. }
  18351. }
  18352. segmentHeader.headerEnd = position;
  18353. return segmentHeader;
  18354. }
  18355. function readSegments(header, data, start, end) {
  18356. var segments = [];
  18357. var position = start;
  18358. while (position < end) {
  18359. var segmentHeader = readSegmentHeader(data, position);
  18360. position = segmentHeader.headerEnd;
  18361. var segment = {
  18362. header: segmentHeader,
  18363. data: data
  18364. };
  18365. if (!header.randomAccess) {
  18366. segment.start = position;
  18367. position += segmentHeader.length;
  18368. segment.end = position;
  18369. }
  18370. segments.push(segment);
  18371. if (segmentHeader.type === 51) {
  18372. break; // end of file is found
  18373. }
  18374. }
  18375. if (header.randomAccess) {
  18376. for (var i = 0, ii = segments.length; i < ii; i++) {
  18377. segments[i].start = position;
  18378. position += segments[i].header.length;
  18379. segments[i].end = position;
  18380. }
  18381. }
  18382. return segments;
  18383. }
  18384. // 7.4.1 Region segment information field
  18385. function readRegionSegmentInformation(data, start) {
  18386. return {
  18387. width: readUint32(data, start),
  18388. height: readUint32(data, start + 4),
  18389. x: readUint32(data, start + 8),
  18390. y: readUint32(data, start + 12),
  18391. combinationOperator: data[start + 16] & 7
  18392. };
  18393. }
  18394. var RegionSegmentInformationFieldLength = 17;
  18395. function processSegment(segment, visitor) {
  18396. var header = segment.header;
  18397. var data = segment.data, position = segment.start, end = segment.end;
  18398. var args, at, i, atLength;
  18399. switch (header.type) {
  18400. case 0: // SymbolDictionary
  18401. // 7.4.2 Symbol dictionary segment syntax
  18402. var dictionary = {};
  18403. var dictionaryFlags = readUint16(data, position); // 7.4.2.1.1
  18404. dictionary.huffman = !!(dictionaryFlags & 1);
  18405. dictionary.refinement = !!(dictionaryFlags & 2);
  18406. dictionary.huffmanDHSelector = (dictionaryFlags >> 2) & 3;
  18407. dictionary.huffmanDWSelector = (dictionaryFlags >> 4) & 3;
  18408. dictionary.bitmapSizeSelector = (dictionaryFlags >> 6) & 1;
  18409. dictionary.aggregationInstancesSelector = (dictionaryFlags >> 7) & 1;
  18410. dictionary.bitmapCodingContextUsed = !!(dictionaryFlags & 256);
  18411. dictionary.bitmapCodingContextRetained = !!(dictionaryFlags & 512);
  18412. dictionary.template = (dictionaryFlags >> 10) & 3;
  18413. dictionary.refinementTemplate = (dictionaryFlags >> 12) & 1;
  18414. position += 2;
  18415. if (!dictionary.huffman) {
  18416. atLength = dictionary.template === 0 ? 4 : 1;
  18417. at = [];
  18418. for (i = 0; i < atLength; i++) {
  18419. at.push({
  18420. x: readInt8(data, position),
  18421. y: readInt8(data, position + 1)
  18422. });
  18423. position += 2;
  18424. }
  18425. dictionary.at = at;
  18426. }
  18427. if (dictionary.refinement && !dictionary.refinementTemplate) {
  18428. at = [];
  18429. for (i = 0; i < 2; i++) {
  18430. at.push({
  18431. x: readInt8(data, position),
  18432. y: readInt8(data, position + 1)
  18433. });
  18434. position += 2;
  18435. }
  18436. dictionary.refinementAt = at;
  18437. }
  18438. dictionary.numberOfExportedSymbols = readUint32(data, position);
  18439. position += 4;
  18440. dictionary.numberOfNewSymbols = readUint32(data, position);
  18441. position += 4;
  18442. args = [dictionary, header.number, header.referredTo,
  18443. data, position, end];
  18444. break;
  18445. case 6: // ImmediateTextRegion
  18446. case 7: // ImmediateLosslessTextRegion
  18447. var textRegion = {};
  18448. textRegion.info = readRegionSegmentInformation(data, position);
  18449. position += RegionSegmentInformationFieldLength;
  18450. var textRegionSegmentFlags = readUint16(data, position);
  18451. position += 2;
  18452. textRegion.huffman = !!(textRegionSegmentFlags & 1);
  18453. textRegion.refinement = !!(textRegionSegmentFlags & 2);
  18454. textRegion.stripSize = 1 << ((textRegionSegmentFlags >> 2) & 3);
  18455. textRegion.referenceCorner = (textRegionSegmentFlags >> 4) & 3;
  18456. textRegion.transposed = !!(textRegionSegmentFlags & 64);
  18457. textRegion.combinationOperator = (textRegionSegmentFlags >> 7) & 3;
  18458. textRegion.defaultPixelValue = (textRegionSegmentFlags >> 9) & 1;
  18459. textRegion.dsOffset = (textRegionSegmentFlags << 17) >> 27;
  18460. textRegion.refinementTemplate = (textRegionSegmentFlags >> 15) & 1;
  18461. if (textRegion.huffman) {
  18462. var textRegionHuffmanFlags = readUint16(data, position);
  18463. position += 2;
  18464. textRegion.huffmanFS = (textRegionHuffmanFlags) & 3;
  18465. textRegion.huffmanDS = (textRegionHuffmanFlags >> 2) & 3;
  18466. textRegion.huffmanDT = (textRegionHuffmanFlags >> 4) & 3;
  18467. textRegion.huffmanRefinementDW = (textRegionHuffmanFlags >> 6) & 3;
  18468. textRegion.huffmanRefinementDH = (textRegionHuffmanFlags >> 8) & 3;
  18469. textRegion.huffmanRefinementDX = (textRegionHuffmanFlags >> 10) & 3;
  18470. textRegion.huffmanRefinementDY = (textRegionHuffmanFlags >> 12) & 3;
  18471. textRegion.huffmanRefinementSizeSelector =
  18472. !!(textRegionHuffmanFlags & 14);
  18473. }
  18474. if (textRegion.refinement && !textRegion.refinementTemplate) {
  18475. at = [];
  18476. for (i = 0; i < 2; i++) {
  18477. at.push({
  18478. x: readInt8(data, position),
  18479. y: readInt8(data, position + 1)
  18480. });
  18481. position += 2;
  18482. }
  18483. textRegion.refinementAt = at;
  18484. }
  18485. textRegion.numberOfSymbolInstances = readUint32(data, position);
  18486. position += 4;
  18487. // TODO 7.4.3.1.7 Symbol ID Huffman table decoding
  18488. if (textRegion.huffman) {
  18489. error('JBIG2 error: huffman is not supported');
  18490. }
  18491. args = [textRegion, header.referredTo, data, position, end];
  18492. break;
  18493. case 38: // ImmediateGenericRegion
  18494. case 39: // ImmediateLosslessGenericRegion
  18495. var genericRegion = {};
  18496. genericRegion.info = readRegionSegmentInformation(data, position);
  18497. position += RegionSegmentInformationFieldLength;
  18498. var genericRegionSegmentFlags = data[position++];
  18499. genericRegion.mmr = !!(genericRegionSegmentFlags & 1);
  18500. genericRegion.template = (genericRegionSegmentFlags >> 1) & 3;
  18501. genericRegion.prediction = !!(genericRegionSegmentFlags & 8);
  18502. if (!genericRegion.mmr) {
  18503. atLength = genericRegion.template === 0 ? 4 : 1;
  18504. at = [];
  18505. for (i = 0; i < atLength; i++) {
  18506. at.push({
  18507. x: readInt8(data, position),
  18508. y: readInt8(data, position + 1)
  18509. });
  18510. position += 2;
  18511. }
  18512. genericRegion.at = at;
  18513. }
  18514. args = [genericRegion, data, position, end];
  18515. break;
  18516. case 48: // PageInformation
  18517. var pageInfo = {
  18518. width: readUint32(data, position),
  18519. height: readUint32(data, position + 4),
  18520. resolutionX: readUint32(data, position + 8),
  18521. resolutionY: readUint32(data, position + 12)
  18522. };
  18523. if (pageInfo.height === 0xFFFFFFFF) {
  18524. delete pageInfo.height;
  18525. }
  18526. var pageSegmentFlags = data[position + 16];
  18527. var pageStripingInformation = readUint16(data, position + 17);
  18528. pageInfo.lossless = !!(pageSegmentFlags & 1);
  18529. pageInfo.refinement = !!(pageSegmentFlags & 2);
  18530. pageInfo.defaultPixelValue = (pageSegmentFlags >> 2) & 1;
  18531. pageInfo.combinationOperator = (pageSegmentFlags >> 3) & 3;
  18532. pageInfo.requiresBuffer = !!(pageSegmentFlags & 32);
  18533. pageInfo.combinationOperatorOverride = !!(pageSegmentFlags & 64);
  18534. args = [pageInfo];
  18535. break;
  18536. case 49: // EndOfPage
  18537. break;
  18538. case 50: // EndOfStripe
  18539. break;
  18540. case 51: // EndOfFile
  18541. break;
  18542. case 62: // 7.4.15 defines 2 extension types which
  18543. // are comments and can be ignored.
  18544. break;
  18545. default:
  18546. error('JBIG2 error: segment type ' + header.typeName + '(' +
  18547. header.type + ') is not implemented');
  18548. }
  18549. var callbackName = 'on' + header.typeName;
  18550. if (callbackName in visitor) {
  18551. visitor[callbackName].apply(visitor, args);
  18552. }
  18553. }
  18554. function processSegments(segments, visitor) {
  18555. for (var i = 0, ii = segments.length; i < ii; i++) {
  18556. processSegment(segments[i], visitor);
  18557. }
  18558. }
  18559. function parseJbig2(data, start, end) {
  18560. var position = start;
  18561. if (data[position] !== 0x97 || data[position + 1] !== 0x4A ||
  18562. data[position + 2] !== 0x42 || data[position + 3] !== 0x32 ||
  18563. data[position + 4] !== 0x0D || data[position + 5] !== 0x0A ||
  18564. data[position + 6] !== 0x1A || data[position + 7] !== 0x0A) {
  18565. error('JBIG2 error: invalid header');
  18566. }
  18567. var header = {};
  18568. position += 8;
  18569. var flags = data[position++];
  18570. header.randomAccess = !(flags & 1);
  18571. if (!(flags & 2)) {
  18572. header.numberOfPages = readUint32(data, position);
  18573. position += 4;
  18574. }
  18575. var segments = readSegments(header, data, position, end);
  18576. error('Not implemented');
  18577. // processSegments(segments, new SimpleSegmentVisitor());
  18578. }
  18579. function parseJbig2Chunks(chunks) {
  18580. var visitor = new SimpleSegmentVisitor();
  18581. for (var i = 0, ii = chunks.length; i < ii; i++) {
  18582. var chunk = chunks[i];
  18583. var segments = readSegments({}, chunk.data, chunk.start, chunk.end);
  18584. processSegments(segments, visitor);
  18585. }
  18586. return visitor.buffer;
  18587. }
  18588. function SimpleSegmentVisitor() {}
  18589. SimpleSegmentVisitor.prototype = {
  18590. onPageInformation: function SimpleSegmentVisitor_onPageInformation(info) {
  18591. this.currentPageInfo = info;
  18592. var rowSize = (info.width + 7) >> 3;
  18593. var buffer = new Uint8Array(rowSize * info.height);
  18594. // The contents of ArrayBuffers are initialized to 0.
  18595. // Fill the buffer with 0xFF only if info.defaultPixelValue is set
  18596. if (info.defaultPixelValue) {
  18597. for (var i = 0, ii = buffer.length; i < ii; i++) {
  18598. buffer[i] = 0xFF;
  18599. }
  18600. }
  18601. this.buffer = buffer;
  18602. },
  18603. drawBitmap: function SimpleSegmentVisitor_drawBitmap(regionInfo, bitmap) {
  18604. var pageInfo = this.currentPageInfo;
  18605. var width = regionInfo.width, height = regionInfo.height;
  18606. var rowSize = (pageInfo.width + 7) >> 3;
  18607. var combinationOperator = pageInfo.combinationOperatorOverride ?
  18608. regionInfo.combinationOperator : pageInfo.combinationOperator;
  18609. var buffer = this.buffer;
  18610. var mask0 = 128 >> (regionInfo.x & 7);
  18611. var offset0 = regionInfo.y * rowSize + (regionInfo.x >> 3);
  18612. var i, j, mask, offset;
  18613. switch (combinationOperator) {
  18614. case 0: // OR
  18615. for (i = 0; i < height; i++) {
  18616. mask = mask0;
  18617. offset = offset0;
  18618. for (j = 0; j < width; j++) {
  18619. if (bitmap[i][j]) {
  18620. buffer[offset] |= mask;
  18621. }
  18622. mask >>= 1;
  18623. if (!mask) {
  18624. mask = 128;
  18625. offset++;
  18626. }
  18627. }
  18628. offset0 += rowSize;
  18629. }
  18630. break;
  18631. case 2: // XOR
  18632. for (i = 0; i < height; i++) {
  18633. mask = mask0;
  18634. offset = offset0;
  18635. for (j = 0; j < width; j++) {
  18636. if (bitmap[i][j]) {
  18637. buffer[offset] ^= mask;
  18638. }
  18639. mask >>= 1;
  18640. if (!mask) {
  18641. mask = 128;
  18642. offset++;
  18643. }
  18644. }
  18645. offset0 += rowSize;
  18646. }
  18647. break;
  18648. default:
  18649. error('JBIG2 error: operator ' + combinationOperator +
  18650. ' is not supported');
  18651. }
  18652. },
  18653. onImmediateGenericRegion:
  18654. function SimpleSegmentVisitor_onImmediateGenericRegion(region, data,
  18655. start, end) {
  18656. var regionInfo = region.info;
  18657. var decodingContext = new DecodingContext(data, start, end);
  18658. var bitmap = decodeBitmap(region.mmr, regionInfo.width, regionInfo.height,
  18659. region.template, region.prediction, null,
  18660. region.at, decodingContext);
  18661. this.drawBitmap(regionInfo, bitmap);
  18662. },
  18663. onImmediateLosslessGenericRegion:
  18664. function SimpleSegmentVisitor_onImmediateLosslessGenericRegion() {
  18665. this.onImmediateGenericRegion.apply(this, arguments);
  18666. },
  18667. onSymbolDictionary:
  18668. function SimpleSegmentVisitor_onSymbolDictionary(dictionary,
  18669. currentSegment,
  18670. referredSegments,
  18671. data, start, end) {
  18672. var huffmanTables;
  18673. if (dictionary.huffman) {
  18674. error('JBIG2 error: huffman is not supported');
  18675. }
  18676. // Combines exported symbols from all referred segments
  18677. var symbols = this.symbols;
  18678. if (!symbols) {
  18679. this.symbols = symbols = {};
  18680. }
  18681. var inputSymbols = [];
  18682. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  18683. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  18684. }
  18685. var decodingContext = new DecodingContext(data, start, end);
  18686. symbols[currentSegment] = decodeSymbolDictionary(dictionary.huffman,
  18687. dictionary.refinement, inputSymbols, dictionary.numberOfNewSymbols,
  18688. dictionary.numberOfExportedSymbols, huffmanTables,
  18689. dictionary.template, dictionary.at,
  18690. dictionary.refinementTemplate, dictionary.refinementAt,
  18691. decodingContext);
  18692. },
  18693. onImmediateTextRegion:
  18694. function SimpleSegmentVisitor_onImmediateTextRegion(region,
  18695. referredSegments,
  18696. data, start, end) {
  18697. var regionInfo = region.info;
  18698. var huffmanTables;
  18699. // Combines exported symbols from all referred segments
  18700. var symbols = this.symbols;
  18701. var inputSymbols = [];
  18702. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  18703. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  18704. }
  18705. var symbolCodeLength = log2(inputSymbols.length);
  18706. var decodingContext = new DecodingContext(data, start, end);
  18707. var bitmap = decodeTextRegion(region.huffman, region.refinement,
  18708. regionInfo.width, regionInfo.height, region.defaultPixelValue,
  18709. region.numberOfSymbolInstances, region.stripSize, inputSymbols,
  18710. symbolCodeLength, region.transposed, region.dsOffset,
  18711. region.referenceCorner, region.combinationOperator, huffmanTables,
  18712. region.refinementTemplate, region.refinementAt, decodingContext);
  18713. this.drawBitmap(regionInfo, bitmap);
  18714. },
  18715. onImmediateLosslessTextRegion:
  18716. function SimpleSegmentVisitor_onImmediateLosslessTextRegion() {
  18717. this.onImmediateTextRegion.apply(this, arguments);
  18718. }
  18719. };
  18720. function Jbig2Image() {}
  18721. Jbig2Image.prototype = {
  18722. parseChunks: function Jbig2Image_parseChunks(chunks) {
  18723. return parseJbig2Chunks(chunks);
  18724. }
  18725. };
  18726. return Jbig2Image;
  18727. })();
  18728. exports.Jbig2Image = Jbig2Image;
  18729. }));
  18730. (function (root, factory) {
  18731. {
  18732. factory((root.pdfjsCoreJpx = {}), root.pdfjsSharedUtil,
  18733. root.pdfjsCoreArithmeticDecoder);
  18734. }
  18735. }(this, function (exports, sharedUtil, coreArithmeticDecoder) {
  18736. var info = sharedUtil.info;
  18737. var log2 = sharedUtil.log2;
  18738. var readUint16 = sharedUtil.readUint16;
  18739. var readUint32 = sharedUtil.readUint32;
  18740. var warn = sharedUtil.warn;
  18741. var ArithmeticDecoder = coreArithmeticDecoder.ArithmeticDecoder;
  18742. var JpxImage = (function JpxImageClosure() {
  18743. // Table E.1
  18744. var SubbandsGainLog2 = {
  18745. 'LL': 0,
  18746. 'LH': 1,
  18747. 'HL': 1,
  18748. 'HH': 2
  18749. };
  18750. function JpxImage() {
  18751. this.failOnCorruptedImage = false;
  18752. }
  18753. JpxImage.prototype = {
  18754. parse: function JpxImage_parse(data) {
  18755. var head = readUint16(data, 0);
  18756. // No box header, immediate start of codestream (SOC)
  18757. if (head === 0xFF4F) {
  18758. this.parseCodestream(data, 0, data.length);
  18759. return;
  18760. }
  18761. var position = 0, length = data.length;
  18762. while (position < length) {
  18763. var headerSize = 8;
  18764. var lbox = readUint32(data, position);
  18765. var tbox = readUint32(data, position + 4);
  18766. position += headerSize;
  18767. if (lbox === 1) {
  18768. // XLBox: read UInt64 according to spec.
  18769. // JavaScript's int precision of 53 bit should be sufficient here.
  18770. lbox = readUint32(data, position) * 4294967296 +
  18771. readUint32(data, position + 4);
  18772. position += 8;
  18773. headerSize += 8;
  18774. }
  18775. if (lbox === 0) {
  18776. lbox = length - position + headerSize;
  18777. }
  18778. if (lbox < headerSize) {
  18779. throw new Error('JPX Error: Invalid box field size');
  18780. }
  18781. var dataLength = lbox - headerSize;
  18782. var jumpDataLength = true;
  18783. switch (tbox) {
  18784. case 0x6A703268: // 'jp2h'
  18785. jumpDataLength = false; // parsing child boxes
  18786. break;
  18787. case 0x636F6C72: // 'colr'
  18788. // Colorspaces are not used, the CS from the PDF is used.
  18789. var method = data[position];
  18790. if (method === 1) {
  18791. // enumerated colorspace
  18792. var colorspace = readUint32(data, position + 3);
  18793. switch (colorspace) {
  18794. case 16: // this indicates a sRGB colorspace
  18795. case 17: // this indicates a grayscale colorspace
  18796. case 18: // this indicates a YUV colorspace
  18797. break;
  18798. default:
  18799. warn('Unknown colorspace ' + colorspace);
  18800. break;
  18801. }
  18802. } else if (method === 2) {
  18803. info('ICC profile not supported');
  18804. }
  18805. break;
  18806. case 0x6A703263: // 'jp2c'
  18807. this.parseCodestream(data, position, position + dataLength);
  18808. break;
  18809. case 0x6A502020: // 'jP\024\024'
  18810. if (0x0d0a870a !== readUint32(data, position)) {
  18811. warn('Invalid JP2 signature');
  18812. }
  18813. break;
  18814. // The following header types are valid but currently not used:
  18815. case 0x6A501A1A: // 'jP\032\032'
  18816. case 0x66747970: // 'ftyp'
  18817. case 0x72726571: // 'rreq'
  18818. case 0x72657320: // 'res '
  18819. case 0x69686472: // 'ihdr'
  18820. break;
  18821. default:
  18822. var headerType = String.fromCharCode((tbox >> 24) & 0xFF,
  18823. (tbox >> 16) & 0xFF,
  18824. (tbox >> 8) & 0xFF,
  18825. tbox & 0xFF);
  18826. warn('Unsupported header type ' + tbox + ' (' + headerType + ')');
  18827. break;
  18828. }
  18829. if (jumpDataLength) {
  18830. position += dataLength;
  18831. }
  18832. }
  18833. },
  18834. parseImageProperties: function JpxImage_parseImageProperties(stream) {
  18835. var newByte = stream.getByte();
  18836. while (newByte >= 0) {
  18837. var oldByte = newByte;
  18838. newByte = stream.getByte();
  18839. var code = (oldByte << 8) | newByte;
  18840. // Image and tile size (SIZ)
  18841. if (code === 0xFF51) {
  18842. stream.skip(4);
  18843. var Xsiz = stream.getInt32() >>> 0; // Byte 4
  18844. var Ysiz = stream.getInt32() >>> 0; // Byte 8
  18845. var XOsiz = stream.getInt32() >>> 0; // Byte 12
  18846. var YOsiz = stream.getInt32() >>> 0; // Byte 16
  18847. stream.skip(16);
  18848. var Csiz = stream.getUint16(); // Byte 36
  18849. this.width = Xsiz - XOsiz;
  18850. this.height = Ysiz - YOsiz;
  18851. this.componentsCount = Csiz;
  18852. // Results are always returned as Uint8Arrays
  18853. this.bitsPerComponent = 8;
  18854. return;
  18855. }
  18856. }
  18857. throw new Error('JPX Error: No size marker found in JPX stream');
  18858. },
  18859. parseCodestream: function JpxImage_parseCodestream(data, start, end) {
  18860. var context = {};
  18861. try {
  18862. var doNotRecover = false;
  18863. var position = start;
  18864. while (position + 1 < end) {
  18865. var code = readUint16(data, position);
  18866. position += 2;
  18867. var length = 0, j, sqcd, spqcds, spqcdSize, scalarExpounded, tile;
  18868. switch (code) {
  18869. case 0xFF4F: // Start of codestream (SOC)
  18870. context.mainHeader = true;
  18871. break;
  18872. case 0xFFD9: // End of codestream (EOC)
  18873. break;
  18874. case 0xFF51: // Image and tile size (SIZ)
  18875. length = readUint16(data, position);
  18876. var siz = {};
  18877. siz.Xsiz = readUint32(data, position + 4);
  18878. siz.Ysiz = readUint32(data, position + 8);
  18879. siz.XOsiz = readUint32(data, position + 12);
  18880. siz.YOsiz = readUint32(data, position + 16);
  18881. siz.XTsiz = readUint32(data, position + 20);
  18882. siz.YTsiz = readUint32(data, position + 24);
  18883. siz.XTOsiz = readUint32(data, position + 28);
  18884. siz.YTOsiz = readUint32(data, position + 32);
  18885. var componentsCount = readUint16(data, position + 36);
  18886. siz.Csiz = componentsCount;
  18887. var components = [];
  18888. j = position + 38;
  18889. for (var i = 0; i < componentsCount; i++) {
  18890. var component = {
  18891. precision: (data[j] & 0x7F) + 1,
  18892. isSigned: !!(data[j] & 0x80),
  18893. XRsiz: data[j + 1],
  18894. YRsiz: data[j + 1]
  18895. };
  18896. calculateComponentDimensions(component, siz);
  18897. components.push(component);
  18898. }
  18899. context.SIZ = siz;
  18900. context.components = components;
  18901. calculateTileGrids(context, components);
  18902. context.QCC = [];
  18903. context.COC = [];
  18904. break;
  18905. case 0xFF5C: // Quantization default (QCD)
  18906. length = readUint16(data, position);
  18907. var qcd = {};
  18908. j = position + 2;
  18909. sqcd = data[j++];
  18910. switch (sqcd & 0x1F) {
  18911. case 0:
  18912. spqcdSize = 8;
  18913. scalarExpounded = true;
  18914. break;
  18915. case 1:
  18916. spqcdSize = 16;
  18917. scalarExpounded = false;
  18918. break;
  18919. case 2:
  18920. spqcdSize = 16;
  18921. scalarExpounded = true;
  18922. break;
  18923. default:
  18924. throw new Error('JPX Error: Invalid SQcd value ' + sqcd);
  18925. }
  18926. qcd.noQuantization = (spqcdSize === 8);
  18927. qcd.scalarExpounded = scalarExpounded;
  18928. qcd.guardBits = sqcd >> 5;
  18929. spqcds = [];
  18930. while (j < length + position) {
  18931. var spqcd = {};
  18932. if (spqcdSize === 8) {
  18933. spqcd.epsilon = data[j++] >> 3;
  18934. spqcd.mu = 0;
  18935. } else {
  18936. spqcd.epsilon = data[j] >> 3;
  18937. spqcd.mu = ((data[j] & 0x7) << 8) | data[j + 1];
  18938. j += 2;
  18939. }
  18940. spqcds.push(spqcd);
  18941. }
  18942. qcd.SPqcds = spqcds;
  18943. if (context.mainHeader) {
  18944. context.QCD = qcd;
  18945. } else {
  18946. context.currentTile.QCD = qcd;
  18947. context.currentTile.QCC = [];
  18948. }
  18949. break;
  18950. case 0xFF5D: // Quantization component (QCC)
  18951. length = readUint16(data, position);
  18952. var qcc = {};
  18953. j = position + 2;
  18954. var cqcc;
  18955. if (context.SIZ.Csiz < 257) {
  18956. cqcc = data[j++];
  18957. } else {
  18958. cqcc = readUint16(data, j);
  18959. j += 2;
  18960. }
  18961. sqcd = data[j++];
  18962. switch (sqcd & 0x1F) {
  18963. case 0:
  18964. spqcdSize = 8;
  18965. scalarExpounded = true;
  18966. break;
  18967. case 1:
  18968. spqcdSize = 16;
  18969. scalarExpounded = false;
  18970. break;
  18971. case 2:
  18972. spqcdSize = 16;
  18973. scalarExpounded = true;
  18974. break;
  18975. default:
  18976. throw new Error('JPX Error: Invalid SQcd value ' + sqcd);
  18977. }
  18978. qcc.noQuantization = (spqcdSize === 8);
  18979. qcc.scalarExpounded = scalarExpounded;
  18980. qcc.guardBits = sqcd >> 5;
  18981. spqcds = [];
  18982. while (j < (length + position)) {
  18983. spqcd = {};
  18984. if (spqcdSize === 8) {
  18985. spqcd.epsilon = data[j++] >> 3;
  18986. spqcd.mu = 0;
  18987. } else {
  18988. spqcd.epsilon = data[j] >> 3;
  18989. spqcd.mu = ((data[j] & 0x7) << 8) | data[j + 1];
  18990. j += 2;
  18991. }
  18992. spqcds.push(spqcd);
  18993. }
  18994. qcc.SPqcds = spqcds;
  18995. if (context.mainHeader) {
  18996. context.QCC[cqcc] = qcc;
  18997. } else {
  18998. context.currentTile.QCC[cqcc] = qcc;
  18999. }
  19000. break;
  19001. case 0xFF52: // Coding style default (COD)
  19002. length = readUint16(data, position);
  19003. var cod = {};
  19004. j = position + 2;
  19005. var scod = data[j++];
  19006. cod.entropyCoderWithCustomPrecincts = !!(scod & 1);
  19007. cod.sopMarkerUsed = !!(scod & 2);
  19008. cod.ephMarkerUsed = !!(scod & 4);
  19009. cod.progressionOrder = data[j++];
  19010. cod.layersCount = readUint16(data, j);
  19011. j += 2;
  19012. cod.multipleComponentTransform = data[j++];
  19013. cod.decompositionLevelsCount = data[j++];
  19014. cod.xcb = (data[j++] & 0xF) + 2;
  19015. cod.ycb = (data[j++] & 0xF) + 2;
  19016. var blockStyle = data[j++];
  19017. cod.selectiveArithmeticCodingBypass = !!(blockStyle & 1);
  19018. cod.resetContextProbabilities = !!(blockStyle & 2);
  19019. cod.terminationOnEachCodingPass = !!(blockStyle & 4);
  19020. cod.verticalyStripe = !!(blockStyle & 8);
  19021. cod.predictableTermination = !!(blockStyle & 16);
  19022. cod.segmentationSymbolUsed = !!(blockStyle & 32);
  19023. cod.reversibleTransformation = data[j++];
  19024. if (cod.entropyCoderWithCustomPrecincts) {
  19025. var precinctsSizes = [];
  19026. while (j < length + position) {
  19027. var precinctsSize = data[j++];
  19028. precinctsSizes.push({
  19029. PPx: precinctsSize & 0xF,
  19030. PPy: precinctsSize >> 4
  19031. });
  19032. }
  19033. cod.precinctsSizes = precinctsSizes;
  19034. }
  19035. var unsupported = [];
  19036. if (cod.selectiveArithmeticCodingBypass) {
  19037. unsupported.push('selectiveArithmeticCodingBypass');
  19038. }
  19039. if (cod.resetContextProbabilities) {
  19040. unsupported.push('resetContextProbabilities');
  19041. }
  19042. if (cod.terminationOnEachCodingPass) {
  19043. unsupported.push('terminationOnEachCodingPass');
  19044. }
  19045. if (cod.verticalyStripe) {
  19046. unsupported.push('verticalyStripe');
  19047. }
  19048. if (cod.predictableTermination) {
  19049. unsupported.push('predictableTermination');
  19050. }
  19051. if (unsupported.length > 0) {
  19052. doNotRecover = true;
  19053. throw new Error('JPX Error: Unsupported COD options (' +
  19054. unsupported.join(', ') + ')');
  19055. }
  19056. if (context.mainHeader) {
  19057. context.COD = cod;
  19058. } else {
  19059. context.currentTile.COD = cod;
  19060. context.currentTile.COC = [];
  19061. }
  19062. break;
  19063. case 0xFF90: // Start of tile-part (SOT)
  19064. length = readUint16(data, position);
  19065. tile = {};
  19066. tile.index = readUint16(data, position + 2);
  19067. tile.length = readUint32(data, position + 4);
  19068. tile.dataEnd = tile.length + position - 2;
  19069. tile.partIndex = data[position + 8];
  19070. tile.partsCount = data[position + 9];
  19071. context.mainHeader = false;
  19072. if (tile.partIndex === 0) {
  19073. // reset component specific settings
  19074. tile.COD = context.COD;
  19075. tile.COC = context.COC.slice(0); // clone of the global COC
  19076. tile.QCD = context.QCD;
  19077. tile.QCC = context.QCC.slice(0); // clone of the global COC
  19078. }
  19079. context.currentTile = tile;
  19080. break;
  19081. case 0xFF93: // Start of data (SOD)
  19082. tile = context.currentTile;
  19083. if (tile.partIndex === 0) {
  19084. initializeTile(context, tile.index);
  19085. buildPackets(context);
  19086. }
  19087. // moving to the end of the data
  19088. length = tile.dataEnd - position;
  19089. parseTilePackets(context, data, position, length);
  19090. break;
  19091. case 0xFF55: // Tile-part lengths, main header (TLM)
  19092. case 0xFF57: // Packet length, main header (PLM)
  19093. case 0xFF58: // Packet length, tile-part header (PLT)
  19094. case 0xFF64: // Comment (COM)
  19095. length = readUint16(data, position);
  19096. // skipping content
  19097. break;
  19098. case 0xFF53: // Coding style component (COC)
  19099. throw new Error('JPX Error: Codestream code 0xFF53 (COC) is ' +
  19100. 'not implemented');
  19101. default:
  19102. throw new Error('JPX Error: Unknown codestream code: ' +
  19103. code.toString(16));
  19104. }
  19105. position += length;
  19106. }
  19107. } catch (e) {
  19108. if (doNotRecover || this.failOnCorruptedImage) {
  19109. throw e;
  19110. } else {
  19111. warn('Trying to recover from ' + e.message);
  19112. }
  19113. }
  19114. this.tiles = transformComponents(context);
  19115. this.width = context.SIZ.Xsiz - context.SIZ.XOsiz;
  19116. this.height = context.SIZ.Ysiz - context.SIZ.YOsiz;
  19117. this.componentsCount = context.SIZ.Csiz;
  19118. }
  19119. };
  19120. function calculateComponentDimensions(component, siz) {
  19121. // Section B.2 Component mapping
  19122. component.x0 = Math.ceil(siz.XOsiz / component.XRsiz);
  19123. component.x1 = Math.ceil(siz.Xsiz / component.XRsiz);
  19124. component.y0 = Math.ceil(siz.YOsiz / component.YRsiz);
  19125. component.y1 = Math.ceil(siz.Ysiz / component.YRsiz);
  19126. component.width = component.x1 - component.x0;
  19127. component.height = component.y1 - component.y0;
  19128. }
  19129. function calculateTileGrids(context, components) {
  19130. var siz = context.SIZ;
  19131. // Section B.3 Division into tile and tile-components
  19132. var tile, tiles = [];
  19133. var numXtiles = Math.ceil((siz.Xsiz - siz.XTOsiz) / siz.XTsiz);
  19134. var numYtiles = Math.ceil((siz.Ysiz - siz.YTOsiz) / siz.YTsiz);
  19135. for (var q = 0; q < numYtiles; q++) {
  19136. for (var p = 0; p < numXtiles; p++) {
  19137. tile = {};
  19138. tile.tx0 = Math.max(siz.XTOsiz + p * siz.XTsiz, siz.XOsiz);
  19139. tile.ty0 = Math.max(siz.YTOsiz + q * siz.YTsiz, siz.YOsiz);
  19140. tile.tx1 = Math.min(siz.XTOsiz + (p + 1) * siz.XTsiz, siz.Xsiz);
  19141. tile.ty1 = Math.min(siz.YTOsiz + (q + 1) * siz.YTsiz, siz.Ysiz);
  19142. tile.width = tile.tx1 - tile.tx0;
  19143. tile.height = tile.ty1 - tile.ty0;
  19144. tile.components = [];
  19145. tiles.push(tile);
  19146. }
  19147. }
  19148. context.tiles = tiles;
  19149. var componentsCount = siz.Csiz;
  19150. for (var i = 0, ii = componentsCount; i < ii; i++) {
  19151. var component = components[i];
  19152. for (var j = 0, jj = tiles.length; j < jj; j++) {
  19153. var tileComponent = {};
  19154. tile = tiles[j];
  19155. tileComponent.tcx0 = Math.ceil(tile.tx0 / component.XRsiz);
  19156. tileComponent.tcy0 = Math.ceil(tile.ty0 / component.YRsiz);
  19157. tileComponent.tcx1 = Math.ceil(tile.tx1 / component.XRsiz);
  19158. tileComponent.tcy1 = Math.ceil(tile.ty1 / component.YRsiz);
  19159. tileComponent.width = tileComponent.tcx1 - tileComponent.tcx0;
  19160. tileComponent.height = tileComponent.tcy1 - tileComponent.tcy0;
  19161. tile.components[i] = tileComponent;
  19162. }
  19163. }
  19164. }
  19165. function getBlocksDimensions(context, component, r) {
  19166. var codOrCoc = component.codingStyleParameters;
  19167. var result = {};
  19168. if (!codOrCoc.entropyCoderWithCustomPrecincts) {
  19169. result.PPx = 15;
  19170. result.PPy = 15;
  19171. } else {
  19172. result.PPx = codOrCoc.precinctsSizes[r].PPx;
  19173. result.PPy = codOrCoc.precinctsSizes[r].PPy;
  19174. }
  19175. // calculate codeblock size as described in section B.7
  19176. result.xcb_ = (r > 0 ? Math.min(codOrCoc.xcb, result.PPx - 1) :
  19177. Math.min(codOrCoc.xcb, result.PPx));
  19178. result.ycb_ = (r > 0 ? Math.min(codOrCoc.ycb, result.PPy - 1) :
  19179. Math.min(codOrCoc.ycb, result.PPy));
  19180. return result;
  19181. }
  19182. function buildPrecincts(context, resolution, dimensions) {
  19183. // Section B.6 Division resolution to precincts
  19184. var precinctWidth = 1 << dimensions.PPx;
  19185. var precinctHeight = 1 << dimensions.PPy;
  19186. // Jasper introduces codeblock groups for mapping each subband codeblocks
  19187. // to precincts. Precinct partition divides a resolution according to width
  19188. // and height parameters. The subband that belongs to the resolution level
  19189. // has a different size than the level, unless it is the zero resolution.
  19190. // From Jasper documentation: jpeg2000.pdf, section K: Tier-2 coding:
  19191. // The precinct partitioning for a particular subband is derived from a
  19192. // partitioning of its parent LL band (i.e., the LL band at the next higher
  19193. // resolution level)... The LL band associated with each resolution level is
  19194. // divided into precincts... Each of the resulting precinct regions is then
  19195. // mapped into its child subbands (if any) at the next lower resolution
  19196. // level. This is accomplished by using the coordinate transformation
  19197. // (u, v) = (ceil(x/2), ceil(y/2)) where (x, y) and (u, v) are the
  19198. // coordinates of a point in the LL band and child subband, respectively.
  19199. var isZeroRes = resolution.resLevel === 0;
  19200. var precinctWidthInSubband = 1 << (dimensions.PPx + (isZeroRes ? 0 : -1));
  19201. var precinctHeightInSubband = 1 << (dimensions.PPy + (isZeroRes ? 0 : -1));
  19202. var numprecinctswide = (resolution.trx1 > resolution.trx0 ?
  19203. Math.ceil(resolution.trx1 / precinctWidth) -
  19204. Math.floor(resolution.trx0 / precinctWidth) : 0);
  19205. var numprecinctshigh = (resolution.try1 > resolution.try0 ?
  19206. Math.ceil(resolution.try1 / precinctHeight) -
  19207. Math.floor(resolution.try0 / precinctHeight) : 0);
  19208. var numprecincts = numprecinctswide * numprecinctshigh;
  19209. resolution.precinctParameters = {
  19210. precinctWidth: precinctWidth,
  19211. precinctHeight: precinctHeight,
  19212. numprecinctswide: numprecinctswide,
  19213. numprecinctshigh: numprecinctshigh,
  19214. numprecincts: numprecincts,
  19215. precinctWidthInSubband: precinctWidthInSubband,
  19216. precinctHeightInSubband: precinctHeightInSubband
  19217. };
  19218. }
  19219. function buildCodeblocks(context, subband, dimensions) {
  19220. // Section B.7 Division sub-band into code-blocks
  19221. var xcb_ = dimensions.xcb_;
  19222. var ycb_ = dimensions.ycb_;
  19223. var codeblockWidth = 1 << xcb_;
  19224. var codeblockHeight = 1 << ycb_;
  19225. var cbx0 = subband.tbx0 >> xcb_;
  19226. var cby0 = subband.tby0 >> ycb_;
  19227. var cbx1 = (subband.tbx1 + codeblockWidth - 1) >> xcb_;
  19228. var cby1 = (subband.tby1 + codeblockHeight - 1) >> ycb_;
  19229. var precinctParameters = subband.resolution.precinctParameters;
  19230. var codeblocks = [];
  19231. var precincts = [];
  19232. var i, j, codeblock, precinctNumber;
  19233. for (j = cby0; j < cby1; j++) {
  19234. for (i = cbx0; i < cbx1; i++) {
  19235. codeblock = {
  19236. cbx: i,
  19237. cby: j,
  19238. tbx0: codeblockWidth * i,
  19239. tby0: codeblockHeight * j,
  19240. tbx1: codeblockWidth * (i + 1),
  19241. tby1: codeblockHeight * (j + 1)
  19242. };
  19243. codeblock.tbx0_ = Math.max(subband.tbx0, codeblock.tbx0);
  19244. codeblock.tby0_ = Math.max(subband.tby0, codeblock.tby0);
  19245. codeblock.tbx1_ = Math.min(subband.tbx1, codeblock.tbx1);
  19246. codeblock.tby1_ = Math.min(subband.tby1, codeblock.tby1);
  19247. // Calculate precinct number for this codeblock, codeblock position
  19248. // should be relative to its subband, use actual dimension and position
  19249. // See comment about codeblock group width and height
  19250. var pi = Math.floor((codeblock.tbx0_ - subband.tbx0) /
  19251. precinctParameters.precinctWidthInSubband);
  19252. var pj = Math.floor((codeblock.tby0_ - subband.tby0) /
  19253. precinctParameters.precinctHeightInSubband);
  19254. precinctNumber = pi + (pj * precinctParameters.numprecinctswide);
  19255. codeblock.precinctNumber = precinctNumber;
  19256. codeblock.subbandType = subband.type;
  19257. codeblock.Lblock = 3;
  19258. if (codeblock.tbx1_ <= codeblock.tbx0_ ||
  19259. codeblock.tby1_ <= codeblock.tby0_) {
  19260. continue;
  19261. }
  19262. codeblocks.push(codeblock);
  19263. // building precinct for the sub-band
  19264. var precinct = precincts[precinctNumber];
  19265. if (precinct !== undefined) {
  19266. if (i < precinct.cbxMin) {
  19267. precinct.cbxMin = i;
  19268. } else if (i > precinct.cbxMax) {
  19269. precinct.cbxMax = i;
  19270. }
  19271. if (j < precinct.cbyMin) {
  19272. precinct.cbxMin = j;
  19273. } else if (j > precinct.cbyMax) {
  19274. precinct.cbyMax = j;
  19275. }
  19276. } else {
  19277. precincts[precinctNumber] = precinct = {
  19278. cbxMin: i,
  19279. cbyMin: j,
  19280. cbxMax: i,
  19281. cbyMax: j
  19282. };
  19283. }
  19284. codeblock.precinct = precinct;
  19285. }
  19286. }
  19287. subband.codeblockParameters = {
  19288. codeblockWidth: xcb_,
  19289. codeblockHeight: ycb_,
  19290. numcodeblockwide: cbx1 - cbx0 + 1,
  19291. numcodeblockhigh: cby1 - cby0 + 1
  19292. };
  19293. subband.codeblocks = codeblocks;
  19294. subband.precincts = precincts;
  19295. }
  19296. function createPacket(resolution, precinctNumber, layerNumber) {
  19297. var precinctCodeblocks = [];
  19298. // Section B.10.8 Order of info in packet
  19299. var subbands = resolution.subbands;
  19300. // sub-bands already ordered in 'LL', 'HL', 'LH', and 'HH' sequence
  19301. for (var i = 0, ii = subbands.length; i < ii; i++) {
  19302. var subband = subbands[i];
  19303. var codeblocks = subband.codeblocks;
  19304. for (var j = 0, jj = codeblocks.length; j < jj; j++) {
  19305. var codeblock = codeblocks[j];
  19306. if (codeblock.precinctNumber !== precinctNumber) {
  19307. continue;
  19308. }
  19309. precinctCodeblocks.push(codeblock);
  19310. }
  19311. }
  19312. return {
  19313. layerNumber: layerNumber,
  19314. codeblocks: precinctCodeblocks
  19315. };
  19316. }
  19317. function LayerResolutionComponentPositionIterator(context) {
  19318. var siz = context.SIZ;
  19319. var tileIndex = context.currentTile.index;
  19320. var tile = context.tiles[tileIndex];
  19321. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  19322. var componentsCount = siz.Csiz;
  19323. var maxDecompositionLevelsCount = 0;
  19324. for (var q = 0; q < componentsCount; q++) {
  19325. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  19326. tile.components[q].codingStyleParameters.decompositionLevelsCount);
  19327. }
  19328. var l = 0, r = 0, i = 0, k = 0;
  19329. this.nextPacket = function JpxImage_nextPacket() {
  19330. // Section B.12.1.1 Layer-resolution-component-position
  19331. for (; l < layersCount; l++) {
  19332. for (; r <= maxDecompositionLevelsCount; r++) {
  19333. for (; i < componentsCount; i++) {
  19334. var component = tile.components[i];
  19335. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  19336. continue;
  19337. }
  19338. var resolution = component.resolutions[r];
  19339. var numprecincts = resolution.precinctParameters.numprecincts;
  19340. for (; k < numprecincts;) {
  19341. var packet = createPacket(resolution, k, l);
  19342. k++;
  19343. return packet;
  19344. }
  19345. k = 0;
  19346. }
  19347. i = 0;
  19348. }
  19349. r = 0;
  19350. }
  19351. throw new Error('JPX Error: Out of packets');
  19352. };
  19353. }
  19354. function ResolutionLayerComponentPositionIterator(context) {
  19355. var siz = context.SIZ;
  19356. var tileIndex = context.currentTile.index;
  19357. var tile = context.tiles[tileIndex];
  19358. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  19359. var componentsCount = siz.Csiz;
  19360. var maxDecompositionLevelsCount = 0;
  19361. for (var q = 0; q < componentsCount; q++) {
  19362. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  19363. tile.components[q].codingStyleParameters.decompositionLevelsCount);
  19364. }
  19365. var r = 0, l = 0, i = 0, k = 0;
  19366. this.nextPacket = function JpxImage_nextPacket() {
  19367. // Section B.12.1.2 Resolution-layer-component-position
  19368. for (; r <= maxDecompositionLevelsCount; r++) {
  19369. for (; l < layersCount; l++) {
  19370. for (; i < componentsCount; i++) {
  19371. var component = tile.components[i];
  19372. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  19373. continue;
  19374. }
  19375. var resolution = component.resolutions[r];
  19376. var numprecincts = resolution.precinctParameters.numprecincts;
  19377. for (; k < numprecincts;) {
  19378. var packet = createPacket(resolution, k, l);
  19379. k++;
  19380. return packet;
  19381. }
  19382. k = 0;
  19383. }
  19384. i = 0;
  19385. }
  19386. l = 0;
  19387. }
  19388. throw new Error('JPX Error: Out of packets');
  19389. };
  19390. }
  19391. function ResolutionPositionComponentLayerIterator(context) {
  19392. var siz = context.SIZ;
  19393. var tileIndex = context.currentTile.index;
  19394. var tile = context.tiles[tileIndex];
  19395. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  19396. var componentsCount = siz.Csiz;
  19397. var l, r, c, p;
  19398. var maxDecompositionLevelsCount = 0;
  19399. for (c = 0; c < componentsCount; c++) {
  19400. var component = tile.components[c];
  19401. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  19402. component.codingStyleParameters.decompositionLevelsCount);
  19403. }
  19404. var maxNumPrecinctsInLevel = new Int32Array(
  19405. maxDecompositionLevelsCount + 1);
  19406. for (r = 0; r <= maxDecompositionLevelsCount; ++r) {
  19407. var maxNumPrecincts = 0;
  19408. for (c = 0; c < componentsCount; ++c) {
  19409. var resolutions = tile.components[c].resolutions;
  19410. if (r < resolutions.length) {
  19411. maxNumPrecincts = Math.max(maxNumPrecincts,
  19412. resolutions[r].precinctParameters.numprecincts);
  19413. }
  19414. }
  19415. maxNumPrecinctsInLevel[r] = maxNumPrecincts;
  19416. }
  19417. l = 0;
  19418. r = 0;
  19419. c = 0;
  19420. p = 0;
  19421. this.nextPacket = function JpxImage_nextPacket() {
  19422. // Section B.12.1.3 Resolution-position-component-layer
  19423. for (; r <= maxDecompositionLevelsCount; r++) {
  19424. for (; p < maxNumPrecinctsInLevel[r]; p++) {
  19425. for (; c < componentsCount; c++) {
  19426. var component = tile.components[c];
  19427. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  19428. continue;
  19429. }
  19430. var resolution = component.resolutions[r];
  19431. var numprecincts = resolution.precinctParameters.numprecincts;
  19432. if (p >= numprecincts) {
  19433. continue;
  19434. }
  19435. for (; l < layersCount;) {
  19436. var packet = createPacket(resolution, p, l);
  19437. l++;
  19438. return packet;
  19439. }
  19440. l = 0;
  19441. }
  19442. c = 0;
  19443. }
  19444. p = 0;
  19445. }
  19446. throw new Error('JPX Error: Out of packets');
  19447. };
  19448. }
  19449. function PositionComponentResolutionLayerIterator(context) {
  19450. var siz = context.SIZ;
  19451. var tileIndex = context.currentTile.index;
  19452. var tile = context.tiles[tileIndex];
  19453. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  19454. var componentsCount = siz.Csiz;
  19455. var precinctsSizes = getPrecinctSizesInImageScale(tile);
  19456. var precinctsIterationSizes = precinctsSizes;
  19457. var l = 0, r = 0, c = 0, px = 0, py = 0;
  19458. this.nextPacket = function JpxImage_nextPacket() {
  19459. // Section B.12.1.4 Position-component-resolution-layer
  19460. for (; py < precinctsIterationSizes.maxNumHigh; py++) {
  19461. for (; px < precinctsIterationSizes.maxNumWide; px++) {
  19462. for (; c < componentsCount; c++) {
  19463. var component = tile.components[c];
  19464. var decompositionLevelsCount =
  19465. component.codingStyleParameters.decompositionLevelsCount;
  19466. for (; r <= decompositionLevelsCount; r++) {
  19467. var resolution = component.resolutions[r];
  19468. var sizeInImageScale =
  19469. precinctsSizes.components[c].resolutions[r];
  19470. var k = getPrecinctIndexIfExist(
  19471. px,
  19472. py,
  19473. sizeInImageScale,
  19474. precinctsIterationSizes,
  19475. resolution);
  19476. if (k === null) {
  19477. continue;
  19478. }
  19479. for (; l < layersCount;) {
  19480. var packet = createPacket(resolution, k, l);
  19481. l++;
  19482. return packet;
  19483. }
  19484. l = 0;
  19485. }
  19486. r = 0;
  19487. }
  19488. c = 0;
  19489. }
  19490. px = 0;
  19491. }
  19492. throw new Error('JPX Error: Out of packets');
  19493. };
  19494. }
  19495. function ComponentPositionResolutionLayerIterator(context) {
  19496. var siz = context.SIZ;
  19497. var tileIndex = context.currentTile.index;
  19498. var tile = context.tiles[tileIndex];
  19499. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  19500. var componentsCount = siz.Csiz;
  19501. var precinctsSizes = getPrecinctSizesInImageScale(tile);
  19502. var l = 0, r = 0, c = 0, px = 0, py = 0;
  19503. this.nextPacket = function JpxImage_nextPacket() {
  19504. // Section B.12.1.5 Component-position-resolution-layer
  19505. for (; c < componentsCount; ++c) {
  19506. var component = tile.components[c];
  19507. var precinctsIterationSizes = precinctsSizes.components[c];
  19508. var decompositionLevelsCount =
  19509. component.codingStyleParameters.decompositionLevelsCount;
  19510. for (; py < precinctsIterationSizes.maxNumHigh; py++) {
  19511. for (; px < precinctsIterationSizes.maxNumWide; px++) {
  19512. for (; r <= decompositionLevelsCount; r++) {
  19513. var resolution = component.resolutions[r];
  19514. var sizeInImageScale = precinctsIterationSizes.resolutions[r];
  19515. var k = getPrecinctIndexIfExist(
  19516. px,
  19517. py,
  19518. sizeInImageScale,
  19519. precinctsIterationSizes,
  19520. resolution);
  19521. if (k === null) {
  19522. continue;
  19523. }
  19524. for (; l < layersCount;) {
  19525. var packet = createPacket(resolution, k, l);
  19526. l++;
  19527. return packet;
  19528. }
  19529. l = 0;
  19530. }
  19531. r = 0;
  19532. }
  19533. px = 0;
  19534. }
  19535. py = 0;
  19536. }
  19537. throw new Error('JPX Error: Out of packets');
  19538. };
  19539. }
  19540. function getPrecinctIndexIfExist(
  19541. pxIndex, pyIndex, sizeInImageScale, precinctIterationSizes, resolution) {
  19542. var posX = pxIndex * precinctIterationSizes.minWidth;
  19543. var posY = pyIndex * precinctIterationSizes.minHeight;
  19544. if (posX % sizeInImageScale.width !== 0 ||
  19545. posY % sizeInImageScale.height !== 0) {
  19546. return null;
  19547. }
  19548. var startPrecinctRowIndex =
  19549. (posY / sizeInImageScale.width) *
  19550. resolution.precinctParameters.numprecinctswide;
  19551. return (posX / sizeInImageScale.height) + startPrecinctRowIndex;
  19552. }
  19553. function getPrecinctSizesInImageScale(tile) {
  19554. var componentsCount = tile.components.length;
  19555. var minWidth = Number.MAX_VALUE;
  19556. var minHeight = Number.MAX_VALUE;
  19557. var maxNumWide = 0;
  19558. var maxNumHigh = 0;
  19559. var sizePerComponent = new Array(componentsCount);
  19560. for (var c = 0; c < componentsCount; c++) {
  19561. var component = tile.components[c];
  19562. var decompositionLevelsCount =
  19563. component.codingStyleParameters.decompositionLevelsCount;
  19564. var sizePerResolution = new Array(decompositionLevelsCount + 1);
  19565. var minWidthCurrentComponent = Number.MAX_VALUE;
  19566. var minHeightCurrentComponent = Number.MAX_VALUE;
  19567. var maxNumWideCurrentComponent = 0;
  19568. var maxNumHighCurrentComponent = 0;
  19569. var scale = 1;
  19570. for (var r = decompositionLevelsCount; r >= 0; --r) {
  19571. var resolution = component.resolutions[r];
  19572. var widthCurrentResolution =
  19573. scale * resolution.precinctParameters.precinctWidth;
  19574. var heightCurrentResolution =
  19575. scale * resolution.precinctParameters.precinctHeight;
  19576. minWidthCurrentComponent = Math.min(
  19577. minWidthCurrentComponent,
  19578. widthCurrentResolution);
  19579. minHeightCurrentComponent = Math.min(
  19580. minHeightCurrentComponent,
  19581. heightCurrentResolution);
  19582. maxNumWideCurrentComponent = Math.max(maxNumWideCurrentComponent,
  19583. resolution.precinctParameters.numprecinctswide);
  19584. maxNumHighCurrentComponent = Math.max(maxNumHighCurrentComponent,
  19585. resolution.precinctParameters.numprecinctshigh);
  19586. sizePerResolution[r] = {
  19587. width: widthCurrentResolution,
  19588. height: heightCurrentResolution
  19589. };
  19590. scale <<= 1;
  19591. }
  19592. minWidth = Math.min(minWidth, minWidthCurrentComponent);
  19593. minHeight = Math.min(minHeight, minHeightCurrentComponent);
  19594. maxNumWide = Math.max(maxNumWide, maxNumWideCurrentComponent);
  19595. maxNumHigh = Math.max(maxNumHigh, maxNumHighCurrentComponent);
  19596. sizePerComponent[c] = {
  19597. resolutions: sizePerResolution,
  19598. minWidth: minWidthCurrentComponent,
  19599. minHeight: minHeightCurrentComponent,
  19600. maxNumWide: maxNumWideCurrentComponent,
  19601. maxNumHigh: maxNumHighCurrentComponent
  19602. };
  19603. }
  19604. return {
  19605. components: sizePerComponent,
  19606. minWidth: minWidth,
  19607. minHeight: minHeight,
  19608. maxNumWide: maxNumWide,
  19609. maxNumHigh: maxNumHigh
  19610. };
  19611. }
  19612. function buildPackets(context) {
  19613. var siz = context.SIZ;
  19614. var tileIndex = context.currentTile.index;
  19615. var tile = context.tiles[tileIndex];
  19616. var componentsCount = siz.Csiz;
  19617. // Creating resolutions and sub-bands for each component
  19618. for (var c = 0; c < componentsCount; c++) {
  19619. var component = tile.components[c];
  19620. var decompositionLevelsCount =
  19621. component.codingStyleParameters.decompositionLevelsCount;
  19622. // Section B.5 Resolution levels and sub-bands
  19623. var resolutions = [];
  19624. var subbands = [];
  19625. for (var r = 0; r <= decompositionLevelsCount; r++) {
  19626. var blocksDimensions = getBlocksDimensions(context, component, r);
  19627. var resolution = {};
  19628. var scale = 1 << (decompositionLevelsCount - r);
  19629. resolution.trx0 = Math.ceil(component.tcx0 / scale);
  19630. resolution.try0 = Math.ceil(component.tcy0 / scale);
  19631. resolution.trx1 = Math.ceil(component.tcx1 / scale);
  19632. resolution.try1 = Math.ceil(component.tcy1 / scale);
  19633. resolution.resLevel = r;
  19634. buildPrecincts(context, resolution, blocksDimensions);
  19635. resolutions.push(resolution);
  19636. var subband;
  19637. if (r === 0) {
  19638. // one sub-band (LL) with last decomposition
  19639. subband = {};
  19640. subband.type = 'LL';
  19641. subband.tbx0 = Math.ceil(component.tcx0 / scale);
  19642. subband.tby0 = Math.ceil(component.tcy0 / scale);
  19643. subband.tbx1 = Math.ceil(component.tcx1 / scale);
  19644. subband.tby1 = Math.ceil(component.tcy1 / scale);
  19645. subband.resolution = resolution;
  19646. buildCodeblocks(context, subband, blocksDimensions);
  19647. subbands.push(subband);
  19648. resolution.subbands = [subband];
  19649. } else {
  19650. var bscale = 1 << (decompositionLevelsCount - r + 1);
  19651. var resolutionSubbands = [];
  19652. // three sub-bands (HL, LH and HH) with rest of decompositions
  19653. subband = {};
  19654. subband.type = 'HL';
  19655. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  19656. subband.tby0 = Math.ceil(component.tcy0 / bscale);
  19657. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  19658. subband.tby1 = Math.ceil(component.tcy1 / bscale);
  19659. subband.resolution = resolution;
  19660. buildCodeblocks(context, subband, blocksDimensions);
  19661. subbands.push(subband);
  19662. resolutionSubbands.push(subband);
  19663. subband = {};
  19664. subband.type = 'LH';
  19665. subband.tbx0 = Math.ceil(component.tcx0 / bscale);
  19666. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  19667. subband.tbx1 = Math.ceil(component.tcx1 / bscale);
  19668. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  19669. subband.resolution = resolution;
  19670. buildCodeblocks(context, subband, blocksDimensions);
  19671. subbands.push(subband);
  19672. resolutionSubbands.push(subband);
  19673. subband = {};
  19674. subband.type = 'HH';
  19675. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  19676. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  19677. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  19678. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  19679. subband.resolution = resolution;
  19680. buildCodeblocks(context, subband, blocksDimensions);
  19681. subbands.push(subband);
  19682. resolutionSubbands.push(subband);
  19683. resolution.subbands = resolutionSubbands;
  19684. }
  19685. }
  19686. component.resolutions = resolutions;
  19687. component.subbands = subbands;
  19688. }
  19689. // Generate the packets sequence
  19690. var progressionOrder = tile.codingStyleDefaultParameters.progressionOrder;
  19691. switch (progressionOrder) {
  19692. case 0:
  19693. tile.packetsIterator =
  19694. new LayerResolutionComponentPositionIterator(context);
  19695. break;
  19696. case 1:
  19697. tile.packetsIterator =
  19698. new ResolutionLayerComponentPositionIterator(context);
  19699. break;
  19700. case 2:
  19701. tile.packetsIterator =
  19702. new ResolutionPositionComponentLayerIterator(context);
  19703. break;
  19704. case 3:
  19705. tile.packetsIterator =
  19706. new PositionComponentResolutionLayerIterator(context);
  19707. break;
  19708. case 4:
  19709. tile.packetsIterator =
  19710. new ComponentPositionResolutionLayerIterator(context);
  19711. break;
  19712. default:
  19713. throw new Error('JPX Error: Unsupported progression order ' +
  19714. progressionOrder);
  19715. }
  19716. }
  19717. function parseTilePackets(context, data, offset, dataLength) {
  19718. var position = 0;
  19719. var buffer, bufferSize = 0, skipNextBit = false;
  19720. function readBits(count) {
  19721. while (bufferSize < count) {
  19722. var b = data[offset + position];
  19723. position++;
  19724. if (skipNextBit) {
  19725. buffer = (buffer << 7) | b;
  19726. bufferSize += 7;
  19727. skipNextBit = false;
  19728. } else {
  19729. buffer = (buffer << 8) | b;
  19730. bufferSize += 8;
  19731. }
  19732. if (b === 0xFF) {
  19733. skipNextBit = true;
  19734. }
  19735. }
  19736. bufferSize -= count;
  19737. return (buffer >>> bufferSize) & ((1 << count) - 1);
  19738. }
  19739. function skipMarkerIfEqual(value) {
  19740. if (data[offset + position - 1] === 0xFF &&
  19741. data[offset + position] === value) {
  19742. skipBytes(1);
  19743. return true;
  19744. } else if (data[offset + position] === 0xFF &&
  19745. data[offset + position + 1] === value) {
  19746. skipBytes(2);
  19747. return true;
  19748. }
  19749. return false;
  19750. }
  19751. function skipBytes(count) {
  19752. position += count;
  19753. }
  19754. function alignToByte() {
  19755. bufferSize = 0;
  19756. if (skipNextBit) {
  19757. position++;
  19758. skipNextBit = false;
  19759. }
  19760. }
  19761. function readCodingpasses() {
  19762. if (readBits(1) === 0) {
  19763. return 1;
  19764. }
  19765. if (readBits(1) === 0) {
  19766. return 2;
  19767. }
  19768. var value = readBits(2);
  19769. if (value < 3) {
  19770. return value + 3;
  19771. }
  19772. value = readBits(5);
  19773. if (value < 31) {
  19774. return value + 6;
  19775. }
  19776. value = readBits(7);
  19777. return value + 37;
  19778. }
  19779. var tileIndex = context.currentTile.index;
  19780. var tile = context.tiles[tileIndex];
  19781. var sopMarkerUsed = context.COD.sopMarkerUsed;
  19782. var ephMarkerUsed = context.COD.ephMarkerUsed;
  19783. var packetsIterator = tile.packetsIterator;
  19784. while (position < dataLength) {
  19785. alignToByte();
  19786. if (sopMarkerUsed && skipMarkerIfEqual(0x91)) {
  19787. // Skip also marker segment length and packet sequence ID
  19788. skipBytes(4);
  19789. }
  19790. var packet = packetsIterator.nextPacket();
  19791. if (!readBits(1)) {
  19792. continue;
  19793. }
  19794. var layerNumber = packet.layerNumber;
  19795. var queue = [], codeblock;
  19796. for (var i = 0, ii = packet.codeblocks.length; i < ii; i++) {
  19797. codeblock = packet.codeblocks[i];
  19798. var precinct = codeblock.precinct;
  19799. var codeblockColumn = codeblock.cbx - precinct.cbxMin;
  19800. var codeblockRow = codeblock.cby - precinct.cbyMin;
  19801. var codeblockIncluded = false;
  19802. var firstTimeInclusion = false;
  19803. var valueReady;
  19804. if (codeblock['included'] !== undefined) {
  19805. codeblockIncluded = !!readBits(1);
  19806. } else {
  19807. // reading inclusion tree
  19808. precinct = codeblock.precinct;
  19809. var inclusionTree, zeroBitPlanesTree;
  19810. if (precinct['inclusionTree'] !== undefined) {
  19811. inclusionTree = precinct.inclusionTree;
  19812. } else {
  19813. // building inclusion and zero bit-planes trees
  19814. var width = precinct.cbxMax - precinct.cbxMin + 1;
  19815. var height = precinct.cbyMax - precinct.cbyMin + 1;
  19816. inclusionTree = new InclusionTree(width, height, layerNumber);
  19817. zeroBitPlanesTree = new TagTree(width, height);
  19818. precinct.inclusionTree = inclusionTree;
  19819. precinct.zeroBitPlanesTree = zeroBitPlanesTree;
  19820. }
  19821. if (inclusionTree.reset(codeblockColumn, codeblockRow, layerNumber)) {
  19822. while (true) {
  19823. if (readBits(1)) {
  19824. valueReady = !inclusionTree.nextLevel();
  19825. if (valueReady) {
  19826. codeblock.included = true;
  19827. codeblockIncluded = firstTimeInclusion = true;
  19828. break;
  19829. }
  19830. } else {
  19831. inclusionTree.incrementValue(layerNumber);
  19832. break;
  19833. }
  19834. }
  19835. }
  19836. }
  19837. if (!codeblockIncluded) {
  19838. continue;
  19839. }
  19840. if (firstTimeInclusion) {
  19841. zeroBitPlanesTree = precinct.zeroBitPlanesTree;
  19842. zeroBitPlanesTree.reset(codeblockColumn, codeblockRow);
  19843. while (true) {
  19844. if (readBits(1)) {
  19845. valueReady = !zeroBitPlanesTree.nextLevel();
  19846. if (valueReady) {
  19847. break;
  19848. }
  19849. } else {
  19850. zeroBitPlanesTree.incrementValue();
  19851. }
  19852. }
  19853. codeblock.zeroBitPlanes = zeroBitPlanesTree.value;
  19854. }
  19855. var codingpasses = readCodingpasses();
  19856. while (readBits(1)) {
  19857. codeblock.Lblock++;
  19858. }
  19859. var codingpassesLog2 = log2(codingpasses);
  19860. // rounding down log2
  19861. var bits = ((codingpasses < (1 << codingpassesLog2)) ?
  19862. codingpassesLog2 - 1 : codingpassesLog2) + codeblock.Lblock;
  19863. var codedDataLength = readBits(bits);
  19864. queue.push({
  19865. codeblock: codeblock,
  19866. codingpasses: codingpasses,
  19867. dataLength: codedDataLength
  19868. });
  19869. }
  19870. alignToByte();
  19871. if (ephMarkerUsed) {
  19872. skipMarkerIfEqual(0x92);
  19873. }
  19874. while (queue.length > 0) {
  19875. var packetItem = queue.shift();
  19876. codeblock = packetItem.codeblock;
  19877. if (codeblock['data'] === undefined) {
  19878. codeblock.data = [];
  19879. }
  19880. codeblock.data.push({
  19881. data: data,
  19882. start: offset + position,
  19883. end: offset + position + packetItem.dataLength,
  19884. codingpasses: packetItem.codingpasses
  19885. });
  19886. position += packetItem.dataLength;
  19887. }
  19888. }
  19889. return position;
  19890. }
  19891. function copyCoefficients(coefficients, levelWidth, levelHeight, subband,
  19892. delta, mb, reversible, segmentationSymbolUsed) {
  19893. var x0 = subband.tbx0;
  19894. var y0 = subband.tby0;
  19895. var width = subband.tbx1 - subband.tbx0;
  19896. var codeblocks = subband.codeblocks;
  19897. var right = subband.type.charAt(0) === 'H' ? 1 : 0;
  19898. var bottom = subband.type.charAt(1) === 'H' ? levelWidth : 0;
  19899. for (var i = 0, ii = codeblocks.length; i < ii; ++i) {
  19900. var codeblock = codeblocks[i];
  19901. var blockWidth = codeblock.tbx1_ - codeblock.tbx0_;
  19902. var blockHeight = codeblock.tby1_ - codeblock.tby0_;
  19903. if (blockWidth === 0 || blockHeight === 0) {
  19904. continue;
  19905. }
  19906. if (codeblock['data'] === undefined) {
  19907. continue;
  19908. }
  19909. var bitModel, currentCodingpassType;
  19910. bitModel = new BitModel(blockWidth, blockHeight, codeblock.subbandType,
  19911. codeblock.zeroBitPlanes, mb);
  19912. currentCodingpassType = 2; // first bit plane starts from cleanup
  19913. // collect data
  19914. var data = codeblock.data, totalLength = 0, codingpasses = 0;
  19915. var j, jj, dataItem;
  19916. for (j = 0, jj = data.length; j < jj; j++) {
  19917. dataItem = data[j];
  19918. totalLength += dataItem.end - dataItem.start;
  19919. codingpasses += dataItem.codingpasses;
  19920. }
  19921. var encodedData = new Uint8Array(totalLength);
  19922. var position = 0;
  19923. for (j = 0, jj = data.length; j < jj; j++) {
  19924. dataItem = data[j];
  19925. var chunk = dataItem.data.subarray(dataItem.start, dataItem.end);
  19926. encodedData.set(chunk, position);
  19927. position += chunk.length;
  19928. }
  19929. // decoding the item
  19930. var decoder = new ArithmeticDecoder(encodedData, 0, totalLength);
  19931. bitModel.setDecoder(decoder);
  19932. for (j = 0; j < codingpasses; j++) {
  19933. switch (currentCodingpassType) {
  19934. case 0:
  19935. bitModel.runSignificancePropogationPass();
  19936. break;
  19937. case 1:
  19938. bitModel.runMagnitudeRefinementPass();
  19939. break;
  19940. case 2:
  19941. bitModel.runCleanupPass();
  19942. if (segmentationSymbolUsed) {
  19943. bitModel.checkSegmentationSymbol();
  19944. }
  19945. break;
  19946. }
  19947. currentCodingpassType = (currentCodingpassType + 1) % 3;
  19948. }
  19949. var offset = (codeblock.tbx0_ - x0) + (codeblock.tby0_ - y0) * width;
  19950. var sign = bitModel.coefficentsSign;
  19951. var magnitude = bitModel.coefficentsMagnitude;
  19952. var bitsDecoded = bitModel.bitsDecoded;
  19953. var magnitudeCorrection = reversible ? 0 : 0.5;
  19954. var k, n, nb;
  19955. position = 0;
  19956. // Do the interleaving of Section F.3.3 here, so we do not need
  19957. // to copy later. LL level is not interleaved, just copied.
  19958. var interleave = (subband.type !== 'LL');
  19959. for (j = 0; j < blockHeight; j++) {
  19960. var row = (offset / width) | 0; // row in the non-interleaved subband
  19961. var levelOffset = 2 * row * (levelWidth - width) + right + bottom;
  19962. for (k = 0; k < blockWidth; k++) {
  19963. n = magnitude[position];
  19964. if (n !== 0) {
  19965. n = (n + magnitudeCorrection) * delta;
  19966. if (sign[position] !== 0) {
  19967. n = -n;
  19968. }
  19969. nb = bitsDecoded[position];
  19970. var pos = interleave ? (levelOffset + (offset << 1)) : offset;
  19971. if (reversible && (nb >= mb)) {
  19972. coefficients[pos] = n;
  19973. } else {
  19974. coefficients[pos] = n * (1 << (mb - nb));
  19975. }
  19976. }
  19977. offset++;
  19978. position++;
  19979. }
  19980. offset += width - blockWidth;
  19981. }
  19982. }
  19983. }
  19984. function transformTile(context, tile, c) {
  19985. var component = tile.components[c];
  19986. var codingStyleParameters = component.codingStyleParameters;
  19987. var quantizationParameters = component.quantizationParameters;
  19988. var decompositionLevelsCount =
  19989. codingStyleParameters.decompositionLevelsCount;
  19990. var spqcds = quantizationParameters.SPqcds;
  19991. var scalarExpounded = quantizationParameters.scalarExpounded;
  19992. var guardBits = quantizationParameters.guardBits;
  19993. var segmentationSymbolUsed = codingStyleParameters.segmentationSymbolUsed;
  19994. var precision = context.components[c].precision;
  19995. var reversible = codingStyleParameters.reversibleTransformation;
  19996. var transform = (reversible ? new ReversibleTransform() :
  19997. new IrreversibleTransform());
  19998. var subbandCoefficients = [];
  19999. var b = 0;
  20000. for (var i = 0; i <= decompositionLevelsCount; i++) {
  20001. var resolution = component.resolutions[i];
  20002. var width = resolution.trx1 - resolution.trx0;
  20003. var height = resolution.try1 - resolution.try0;
  20004. // Allocate space for the whole sublevel.
  20005. var coefficients = new Float32Array(width * height);
  20006. for (var j = 0, jj = resolution.subbands.length; j < jj; j++) {
  20007. var mu, epsilon;
  20008. if (!scalarExpounded) {
  20009. // formula E-5
  20010. mu = spqcds[0].mu;
  20011. epsilon = spqcds[0].epsilon + (i > 0 ? 1 - i : 0);
  20012. } else {
  20013. mu = spqcds[b].mu;
  20014. epsilon = spqcds[b].epsilon;
  20015. b++;
  20016. }
  20017. var subband = resolution.subbands[j];
  20018. var gainLog2 = SubbandsGainLog2[subband.type];
  20019. // calulate quantization coefficient (Section E.1.1.1)
  20020. var delta = (reversible ? 1 :
  20021. Math.pow(2, precision + gainLog2 - epsilon) * (1 + mu / 2048));
  20022. var mb = (guardBits + epsilon - 1);
  20023. // In the first resolution level, copyCoefficients will fill the
  20024. // whole array with coefficients. In the succeding passes,
  20025. // copyCoefficients will consecutively fill in the values that belong
  20026. // to the interleaved positions of the HL, LH, and HH coefficients.
  20027. // The LL coefficients will then be interleaved in Transform.iterate().
  20028. copyCoefficients(coefficients, width, height, subband, delta, mb,
  20029. reversible, segmentationSymbolUsed);
  20030. }
  20031. subbandCoefficients.push({
  20032. width: width,
  20033. height: height,
  20034. items: coefficients
  20035. });
  20036. }
  20037. var result = transform.calculate(subbandCoefficients,
  20038. component.tcx0, component.tcy0);
  20039. return {
  20040. left: component.tcx0,
  20041. top: component.tcy0,
  20042. width: result.width,
  20043. height: result.height,
  20044. items: result.items
  20045. };
  20046. }
  20047. function transformComponents(context) {
  20048. var siz = context.SIZ;
  20049. var components = context.components;
  20050. var componentsCount = siz.Csiz;
  20051. var resultImages = [];
  20052. for (var i = 0, ii = context.tiles.length; i < ii; i++) {
  20053. var tile = context.tiles[i];
  20054. var transformedTiles = [];
  20055. var c;
  20056. for (c = 0; c < componentsCount; c++) {
  20057. transformedTiles[c] = transformTile(context, tile, c);
  20058. }
  20059. var tile0 = transformedTiles[0];
  20060. var out = new Uint8Array(tile0.items.length * componentsCount);
  20061. var result = {
  20062. left: tile0.left,
  20063. top: tile0.top,
  20064. width: tile0.width,
  20065. height: tile0.height,
  20066. items: out
  20067. };
  20068. // Section G.2.2 Inverse multi component transform
  20069. var shift, offset, max, min, maxK;
  20070. var pos = 0, j, jj, y0, y1, y2, r, g, b, k, val;
  20071. if (tile.codingStyleDefaultParameters.multipleComponentTransform) {
  20072. var fourComponents = componentsCount === 4;
  20073. var y0items = transformedTiles[0].items;
  20074. var y1items = transformedTiles[1].items;
  20075. var y2items = transformedTiles[2].items;
  20076. var y3items = fourComponents ? transformedTiles[3].items : null;
  20077. // HACK: The multiple component transform formulas below assume that
  20078. // all components have the same precision. With this in mind, we
  20079. // compute shift and offset only once.
  20080. shift = components[0].precision - 8;
  20081. offset = (128 << shift) + 0.5;
  20082. max = 255 * (1 << shift);
  20083. maxK = max * 0.5;
  20084. min = -maxK;
  20085. var component0 = tile.components[0];
  20086. var alpha01 = componentsCount - 3;
  20087. jj = y0items.length;
  20088. if (!component0.codingStyleParameters.reversibleTransformation) {
  20089. // inverse irreversible multiple component transform
  20090. for (j = 0; j < jj; j++, pos += alpha01) {
  20091. y0 = y0items[j] + offset;
  20092. y1 = y1items[j];
  20093. y2 = y2items[j];
  20094. r = y0 + 1.402 * y2;
  20095. g = y0 - 0.34413 * y1 - 0.71414 * y2;
  20096. b = y0 + 1.772 * y1;
  20097. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  20098. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  20099. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  20100. }
  20101. } else {
  20102. // inverse reversible multiple component transform
  20103. for (j = 0; j < jj; j++, pos += alpha01) {
  20104. y0 = y0items[j] + offset;
  20105. y1 = y1items[j];
  20106. y2 = y2items[j];
  20107. g = y0 - ((y2 + y1) >> 2);
  20108. r = g + y2;
  20109. b = g + y1;
  20110. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  20111. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  20112. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  20113. }
  20114. }
  20115. if (fourComponents) {
  20116. for (j = 0, pos = 3; j < jj; j++, pos += 4) {
  20117. k = y3items[j];
  20118. out[pos] = k <= min ? 0 : k >= maxK ? 255 : (k + offset) >> shift;
  20119. }
  20120. }
  20121. } else { // no multi-component transform
  20122. for (c = 0; c < componentsCount; c++) {
  20123. var items = transformedTiles[c].items;
  20124. shift = components[c].precision - 8;
  20125. offset = (128 << shift) + 0.5;
  20126. max = (127.5 * (1 << shift));
  20127. min = -max;
  20128. for (pos = c, j = 0, jj = items.length; j < jj; j++) {
  20129. val = items[j];
  20130. out[pos] = val <= min ? 0 :
  20131. val >= max ? 255 : (val + offset) >> shift;
  20132. pos += componentsCount;
  20133. }
  20134. }
  20135. }
  20136. resultImages.push(result);
  20137. }
  20138. return resultImages;
  20139. }
  20140. function initializeTile(context, tileIndex) {
  20141. var siz = context.SIZ;
  20142. var componentsCount = siz.Csiz;
  20143. var tile = context.tiles[tileIndex];
  20144. for (var c = 0; c < componentsCount; c++) {
  20145. var component = tile.components[c];
  20146. var qcdOrQcc = (context.currentTile.QCC[c] !== undefined ?
  20147. context.currentTile.QCC[c] : context.currentTile.QCD);
  20148. component.quantizationParameters = qcdOrQcc;
  20149. var codOrCoc = (context.currentTile.COC[c] !== undefined ?
  20150. context.currentTile.COC[c] : context.currentTile.COD);
  20151. component.codingStyleParameters = codOrCoc;
  20152. }
  20153. tile.codingStyleDefaultParameters = context.currentTile.COD;
  20154. }
  20155. // Section B.10.2 Tag trees
  20156. var TagTree = (function TagTreeClosure() {
  20157. function TagTree(width, height) {
  20158. var levelsLength = log2(Math.max(width, height)) + 1;
  20159. this.levels = [];
  20160. for (var i = 0; i < levelsLength; i++) {
  20161. var level = {
  20162. width: width,
  20163. height: height,
  20164. items: []
  20165. };
  20166. this.levels.push(level);
  20167. width = Math.ceil(width / 2);
  20168. height = Math.ceil(height / 2);
  20169. }
  20170. }
  20171. TagTree.prototype = {
  20172. reset: function TagTree_reset(i, j) {
  20173. var currentLevel = 0, value = 0, level;
  20174. while (currentLevel < this.levels.length) {
  20175. level = this.levels[currentLevel];
  20176. var index = i + j * level.width;
  20177. if (level.items[index] !== undefined) {
  20178. value = level.items[index];
  20179. break;
  20180. }
  20181. level.index = index;
  20182. i >>= 1;
  20183. j >>= 1;
  20184. currentLevel++;
  20185. }
  20186. currentLevel--;
  20187. level = this.levels[currentLevel];
  20188. level.items[level.index] = value;
  20189. this.currentLevel = currentLevel;
  20190. delete this.value;
  20191. },
  20192. incrementValue: function TagTree_incrementValue() {
  20193. var level = this.levels[this.currentLevel];
  20194. level.items[level.index]++;
  20195. },
  20196. nextLevel: function TagTree_nextLevel() {
  20197. var currentLevel = this.currentLevel;
  20198. var level = this.levels[currentLevel];
  20199. var value = level.items[level.index];
  20200. currentLevel--;
  20201. if (currentLevel < 0) {
  20202. this.value = value;
  20203. return false;
  20204. }
  20205. this.currentLevel = currentLevel;
  20206. level = this.levels[currentLevel];
  20207. level.items[level.index] = value;
  20208. return true;
  20209. }
  20210. };
  20211. return TagTree;
  20212. })();
  20213. var InclusionTree = (function InclusionTreeClosure() {
  20214. function InclusionTree(width, height, defaultValue) {
  20215. var levelsLength = log2(Math.max(width, height)) + 1;
  20216. this.levels = [];
  20217. for (var i = 0; i < levelsLength; i++) {
  20218. var items = new Uint8Array(width * height);
  20219. for (var j = 0, jj = items.length; j < jj; j++) {
  20220. items[j] = defaultValue;
  20221. }
  20222. var level = {
  20223. width: width,
  20224. height: height,
  20225. items: items
  20226. };
  20227. this.levels.push(level);
  20228. width = Math.ceil(width / 2);
  20229. height = Math.ceil(height / 2);
  20230. }
  20231. }
  20232. InclusionTree.prototype = {
  20233. reset: function InclusionTree_reset(i, j, stopValue) {
  20234. var currentLevel = 0;
  20235. while (currentLevel < this.levels.length) {
  20236. var level = this.levels[currentLevel];
  20237. var index = i + j * level.width;
  20238. level.index = index;
  20239. var value = level.items[index];
  20240. if (value === 0xFF) {
  20241. break;
  20242. }
  20243. if (value > stopValue) {
  20244. this.currentLevel = currentLevel;
  20245. // already know about this one, propagating the value to top levels
  20246. this.propagateValues();
  20247. return false;
  20248. }
  20249. i >>= 1;
  20250. j >>= 1;
  20251. currentLevel++;
  20252. }
  20253. this.currentLevel = currentLevel - 1;
  20254. return true;
  20255. },
  20256. incrementValue: function InclusionTree_incrementValue(stopValue) {
  20257. var level = this.levels[this.currentLevel];
  20258. level.items[level.index] = stopValue + 1;
  20259. this.propagateValues();
  20260. },
  20261. propagateValues: function InclusionTree_propagateValues() {
  20262. var levelIndex = this.currentLevel;
  20263. var level = this.levels[levelIndex];
  20264. var currentValue = level.items[level.index];
  20265. while (--levelIndex >= 0) {
  20266. level = this.levels[levelIndex];
  20267. level.items[level.index] = currentValue;
  20268. }
  20269. },
  20270. nextLevel: function InclusionTree_nextLevel() {
  20271. var currentLevel = this.currentLevel;
  20272. var level = this.levels[currentLevel];
  20273. var value = level.items[level.index];
  20274. level.items[level.index] = 0xFF;
  20275. currentLevel--;
  20276. if (currentLevel < 0) {
  20277. return false;
  20278. }
  20279. this.currentLevel = currentLevel;
  20280. level = this.levels[currentLevel];
  20281. level.items[level.index] = value;
  20282. return true;
  20283. }
  20284. };
  20285. return InclusionTree;
  20286. })();
  20287. // Section D. Coefficient bit modeling
  20288. var BitModel = (function BitModelClosure() {
  20289. var UNIFORM_CONTEXT = 17;
  20290. var RUNLENGTH_CONTEXT = 18;
  20291. // Table D-1
  20292. // The index is binary presentation: 0dddvvhh, ddd - sum of Di (0..4),
  20293. // vv - sum of Vi (0..2), and hh - sum of Hi (0..2)
  20294. var LLAndLHContextsLabel = new Uint8Array([
  20295. 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,
  20296. 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,
  20297. 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
  20298. ]);
  20299. var HLContextLabel = new Uint8Array([
  20300. 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,
  20301. 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,
  20302. 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
  20303. ]);
  20304. var HHContextLabel = new Uint8Array([
  20305. 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,
  20306. 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,
  20307. 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
  20308. ]);
  20309. function BitModel(width, height, subband, zeroBitPlanes, mb) {
  20310. this.width = width;
  20311. this.height = height;
  20312. this.contextLabelTable = (subband === 'HH' ? HHContextLabel :
  20313. (subband === 'HL' ? HLContextLabel : LLAndLHContextsLabel));
  20314. var coefficientCount = width * height;
  20315. // coefficients outside the encoding region treated as insignificant
  20316. // add border state cells for significanceState
  20317. this.neighborsSignificance = new Uint8Array(coefficientCount);
  20318. this.coefficentsSign = new Uint8Array(coefficientCount);
  20319. this.coefficentsMagnitude = mb > 14 ? new Uint32Array(coefficientCount) :
  20320. mb > 6 ? new Uint16Array(coefficientCount) :
  20321. new Uint8Array(coefficientCount);
  20322. this.processingFlags = new Uint8Array(coefficientCount);
  20323. var bitsDecoded = new Uint8Array(coefficientCount);
  20324. if (zeroBitPlanes !== 0) {
  20325. for (var i = 0; i < coefficientCount; i++) {
  20326. bitsDecoded[i] = zeroBitPlanes;
  20327. }
  20328. }
  20329. this.bitsDecoded = bitsDecoded;
  20330. this.reset();
  20331. }
  20332. BitModel.prototype = {
  20333. setDecoder: function BitModel_setDecoder(decoder) {
  20334. this.decoder = decoder;
  20335. },
  20336. reset: function BitModel_reset() {
  20337. // We have 17 contexts that are accessed via context labels,
  20338. // plus the uniform and runlength context.
  20339. this.contexts = new Int8Array(19);
  20340. // Contexts are packed into 1 byte:
  20341. // highest 7 bits carry the index, lowest bit carries mps
  20342. this.contexts[0] = (4 << 1) | 0;
  20343. this.contexts[UNIFORM_CONTEXT] = (46 << 1) | 0;
  20344. this.contexts[RUNLENGTH_CONTEXT] = (3 << 1) | 0;
  20345. },
  20346. setNeighborsSignificance:
  20347. function BitModel_setNeighborsSignificance(row, column, index) {
  20348. var neighborsSignificance = this.neighborsSignificance;
  20349. var width = this.width, height = this.height;
  20350. var left = (column > 0);
  20351. var right = (column + 1 < width);
  20352. var i;
  20353. if (row > 0) {
  20354. i = index - width;
  20355. if (left) {
  20356. neighborsSignificance[i - 1] += 0x10;
  20357. }
  20358. if (right) {
  20359. neighborsSignificance[i + 1] += 0x10;
  20360. }
  20361. neighborsSignificance[i] += 0x04;
  20362. }
  20363. if (row + 1 < height) {
  20364. i = index + width;
  20365. if (left) {
  20366. neighborsSignificance[i - 1] += 0x10;
  20367. }
  20368. if (right) {
  20369. neighborsSignificance[i + 1] += 0x10;
  20370. }
  20371. neighborsSignificance[i] += 0x04;
  20372. }
  20373. if (left) {
  20374. neighborsSignificance[index - 1] += 0x01;
  20375. }
  20376. if (right) {
  20377. neighborsSignificance[index + 1] += 0x01;
  20378. }
  20379. neighborsSignificance[index] |= 0x80;
  20380. },
  20381. runSignificancePropogationPass:
  20382. function BitModel_runSignificancePropogationPass() {
  20383. var decoder = this.decoder;
  20384. var width = this.width, height = this.height;
  20385. var coefficentsMagnitude = this.coefficentsMagnitude;
  20386. var coefficentsSign = this.coefficentsSign;
  20387. var neighborsSignificance = this.neighborsSignificance;
  20388. var processingFlags = this.processingFlags;
  20389. var contexts = this.contexts;
  20390. var labels = this.contextLabelTable;
  20391. var bitsDecoded = this.bitsDecoded;
  20392. var processedInverseMask = ~1;
  20393. var processedMask = 1;
  20394. var firstMagnitudeBitMask = 2;
  20395. for (var i0 = 0; i0 < height; i0 += 4) {
  20396. for (var j = 0; j < width; j++) {
  20397. var index = i0 * width + j;
  20398. for (var i1 = 0; i1 < 4; i1++, index += width) {
  20399. var i = i0 + i1;
  20400. if (i >= height) {
  20401. break;
  20402. }
  20403. // clear processed flag first
  20404. processingFlags[index] &= processedInverseMask;
  20405. if (coefficentsMagnitude[index] ||
  20406. !neighborsSignificance[index]) {
  20407. continue;
  20408. }
  20409. var contextLabel = labels[neighborsSignificance[index]];
  20410. var decision = decoder.readBit(contexts, contextLabel);
  20411. if (decision) {
  20412. var sign = this.decodeSignBit(i, j, index);
  20413. coefficentsSign[index] = sign;
  20414. coefficentsMagnitude[index] = 1;
  20415. this.setNeighborsSignificance(i, j, index);
  20416. processingFlags[index] |= firstMagnitudeBitMask;
  20417. }
  20418. bitsDecoded[index]++;
  20419. processingFlags[index] |= processedMask;
  20420. }
  20421. }
  20422. }
  20423. },
  20424. decodeSignBit: function BitModel_decodeSignBit(row, column, index) {
  20425. var width = this.width, height = this.height;
  20426. var coefficentsMagnitude = this.coefficentsMagnitude;
  20427. var coefficentsSign = this.coefficentsSign;
  20428. var contribution, sign0, sign1, significance1;
  20429. var contextLabel, decoded;
  20430. // calculate horizontal contribution
  20431. significance1 = (column > 0 && coefficentsMagnitude[index - 1] !== 0);
  20432. if (column + 1 < width && coefficentsMagnitude[index + 1] !== 0) {
  20433. sign1 = coefficentsSign[index + 1];
  20434. if (significance1) {
  20435. sign0 = coefficentsSign[index - 1];
  20436. contribution = 1 - sign1 - sign0;
  20437. } else {
  20438. contribution = 1 - sign1 - sign1;
  20439. }
  20440. } else if (significance1) {
  20441. sign0 = coefficentsSign[index - 1];
  20442. contribution = 1 - sign0 - sign0;
  20443. } else {
  20444. contribution = 0;
  20445. }
  20446. var horizontalContribution = 3 * contribution;
  20447. // calculate vertical contribution and combine with the horizontal
  20448. significance1 = (row > 0 && coefficentsMagnitude[index - width] !== 0);
  20449. if (row + 1 < height && coefficentsMagnitude[index + width] !== 0) {
  20450. sign1 = coefficentsSign[index + width];
  20451. if (significance1) {
  20452. sign0 = coefficentsSign[index - width];
  20453. contribution = 1 - sign1 - sign0 + horizontalContribution;
  20454. } else {
  20455. contribution = 1 - sign1 - sign1 + horizontalContribution;
  20456. }
  20457. } else if (significance1) {
  20458. sign0 = coefficentsSign[index - width];
  20459. contribution = 1 - sign0 - sign0 + horizontalContribution;
  20460. } else {
  20461. contribution = horizontalContribution;
  20462. }
  20463. if (contribution >= 0) {
  20464. contextLabel = 9 + contribution;
  20465. decoded = this.decoder.readBit(this.contexts, contextLabel);
  20466. } else {
  20467. contextLabel = 9 - contribution;
  20468. decoded = this.decoder.readBit(this.contexts, contextLabel) ^ 1;
  20469. }
  20470. return decoded;
  20471. },
  20472. runMagnitudeRefinementPass:
  20473. function BitModel_runMagnitudeRefinementPass() {
  20474. var decoder = this.decoder;
  20475. var width = this.width, height = this.height;
  20476. var coefficentsMagnitude = this.coefficentsMagnitude;
  20477. var neighborsSignificance = this.neighborsSignificance;
  20478. var contexts = this.contexts;
  20479. var bitsDecoded = this.bitsDecoded;
  20480. var processingFlags = this.processingFlags;
  20481. var processedMask = 1;
  20482. var firstMagnitudeBitMask = 2;
  20483. var length = width * height;
  20484. var width4 = width * 4;
  20485. for (var index0 = 0, indexNext; index0 < length; index0 = indexNext) {
  20486. indexNext = Math.min(length, index0 + width4);
  20487. for (var j = 0; j < width; j++) {
  20488. for (var index = index0 + j; index < indexNext; index += width) {
  20489. // significant but not those that have just become
  20490. if (!coefficentsMagnitude[index] ||
  20491. (processingFlags[index] & processedMask) !== 0) {
  20492. continue;
  20493. }
  20494. var contextLabel = 16;
  20495. if ((processingFlags[index] & firstMagnitudeBitMask) !== 0) {
  20496. processingFlags[index] ^= firstMagnitudeBitMask;
  20497. // first refinement
  20498. var significance = neighborsSignificance[index] & 127;
  20499. contextLabel = significance === 0 ? 15 : 14;
  20500. }
  20501. var bit = decoder.readBit(contexts, contextLabel);
  20502. coefficentsMagnitude[index] =
  20503. (coefficentsMagnitude[index] << 1) | bit;
  20504. bitsDecoded[index]++;
  20505. processingFlags[index] |= processedMask;
  20506. }
  20507. }
  20508. }
  20509. },
  20510. runCleanupPass: function BitModel_runCleanupPass() {
  20511. var decoder = this.decoder;
  20512. var width = this.width, height = this.height;
  20513. var neighborsSignificance = this.neighborsSignificance;
  20514. var coefficentsMagnitude = this.coefficentsMagnitude;
  20515. var coefficentsSign = this.coefficentsSign;
  20516. var contexts = this.contexts;
  20517. var labels = this.contextLabelTable;
  20518. var bitsDecoded = this.bitsDecoded;
  20519. var processingFlags = this.processingFlags;
  20520. var processedMask = 1;
  20521. var firstMagnitudeBitMask = 2;
  20522. var oneRowDown = width;
  20523. var twoRowsDown = width * 2;
  20524. var threeRowsDown = width * 3;
  20525. var iNext;
  20526. for (var i0 = 0; i0 < height; i0 = iNext) {
  20527. iNext = Math.min(i0 + 4, height);
  20528. var indexBase = i0 * width;
  20529. var checkAllEmpty = i0 + 3 < height;
  20530. for (var j = 0; j < width; j++) {
  20531. var index0 = indexBase + j;
  20532. // using the property: labels[neighborsSignificance[index]] === 0
  20533. // when neighborsSignificance[index] === 0
  20534. var allEmpty = (checkAllEmpty &&
  20535. processingFlags[index0] === 0 &&
  20536. processingFlags[index0 + oneRowDown] === 0 &&
  20537. processingFlags[index0 + twoRowsDown] === 0 &&
  20538. processingFlags[index0 + threeRowsDown] === 0 &&
  20539. neighborsSignificance[index0] === 0 &&
  20540. neighborsSignificance[index0 + oneRowDown] === 0 &&
  20541. neighborsSignificance[index0 + twoRowsDown] === 0 &&
  20542. neighborsSignificance[index0 + threeRowsDown] === 0);
  20543. var i1 = 0, index = index0;
  20544. var i = i0, sign;
  20545. if (allEmpty) {
  20546. var hasSignificantCoefficent =
  20547. decoder.readBit(contexts, RUNLENGTH_CONTEXT);
  20548. if (!hasSignificantCoefficent) {
  20549. bitsDecoded[index0]++;
  20550. bitsDecoded[index0 + oneRowDown]++;
  20551. bitsDecoded[index0 + twoRowsDown]++;
  20552. bitsDecoded[index0 + threeRowsDown]++;
  20553. continue; // next column
  20554. }
  20555. i1 = (decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
  20556. decoder.readBit(contexts, UNIFORM_CONTEXT);
  20557. if (i1 !== 0) {
  20558. i = i0 + i1;
  20559. index += i1 * width;
  20560. }
  20561. sign = this.decodeSignBit(i, j, index);
  20562. coefficentsSign[index] = sign;
  20563. coefficentsMagnitude[index] = 1;
  20564. this.setNeighborsSignificance(i, j, index);
  20565. processingFlags[index] |= firstMagnitudeBitMask;
  20566. index = index0;
  20567. for (var i2 = i0; i2 <= i; i2++, index += width) {
  20568. bitsDecoded[index]++;
  20569. }
  20570. i1++;
  20571. }
  20572. for (i = i0 + i1; i < iNext; i++, index += width) {
  20573. if (coefficentsMagnitude[index] ||
  20574. (processingFlags[index] & processedMask) !== 0) {
  20575. continue;
  20576. }
  20577. var contextLabel = labels[neighborsSignificance[index]];
  20578. var decision = decoder.readBit(contexts, contextLabel);
  20579. if (decision === 1) {
  20580. sign = this.decodeSignBit(i, j, index);
  20581. coefficentsSign[index] = sign;
  20582. coefficentsMagnitude[index] = 1;
  20583. this.setNeighborsSignificance(i, j, index);
  20584. processingFlags[index] |= firstMagnitudeBitMask;
  20585. }
  20586. bitsDecoded[index]++;
  20587. }
  20588. }
  20589. }
  20590. },
  20591. checkSegmentationSymbol: function BitModel_checkSegmentationSymbol() {
  20592. var decoder = this.decoder;
  20593. var contexts = this.contexts;
  20594. var symbol = (decoder.readBit(contexts, UNIFORM_CONTEXT) << 3) |
  20595. (decoder.readBit(contexts, UNIFORM_CONTEXT) << 2) |
  20596. (decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
  20597. decoder.readBit(contexts, UNIFORM_CONTEXT);
  20598. if (symbol !== 0xA) {
  20599. throw new Error('JPX Error: Invalid segmentation symbol');
  20600. }
  20601. }
  20602. };
  20603. return BitModel;
  20604. })();
  20605. // Section F, Discrete wavelet transformation
  20606. var Transform = (function TransformClosure() {
  20607. function Transform() {}
  20608. Transform.prototype.calculate =
  20609. function transformCalculate(subbands, u0, v0) {
  20610. var ll = subbands[0];
  20611. for (var i = 1, ii = subbands.length; i < ii; i++) {
  20612. ll = this.iterate(ll, subbands[i], u0, v0);
  20613. }
  20614. return ll;
  20615. };
  20616. Transform.prototype.extend = function extend(buffer, offset, size) {
  20617. // Section F.3.7 extending... using max extension of 4
  20618. var i1 = offset - 1, j1 = offset + 1;
  20619. var i2 = offset + size - 2, j2 = offset + size;
  20620. buffer[i1--] = buffer[j1++];
  20621. buffer[j2++] = buffer[i2--];
  20622. buffer[i1--] = buffer[j1++];
  20623. buffer[j2++] = buffer[i2--];
  20624. buffer[i1--] = buffer[j1++];
  20625. buffer[j2++] = buffer[i2--];
  20626. buffer[i1] = buffer[j1];
  20627. buffer[j2] = buffer[i2];
  20628. };
  20629. Transform.prototype.iterate = function Transform_iterate(ll, hl_lh_hh,
  20630. u0, v0) {
  20631. var llWidth = ll.width, llHeight = ll.height, llItems = ll.items;
  20632. var width = hl_lh_hh.width;
  20633. var height = hl_lh_hh.height;
  20634. var items = hl_lh_hh.items;
  20635. var i, j, k, l, u, v;
  20636. // Interleave LL according to Section F.3.3
  20637. for (k = 0, i = 0; i < llHeight; i++) {
  20638. l = i * 2 * width;
  20639. for (j = 0; j < llWidth; j++, k++, l += 2) {
  20640. items[l] = llItems[k];
  20641. }
  20642. }
  20643. // The LL band is not needed anymore.
  20644. llItems = ll.items = null;
  20645. var bufferPadding = 4;
  20646. var rowBuffer = new Float32Array(width + 2 * bufferPadding);
  20647. // Section F.3.4 HOR_SR
  20648. if (width === 1) {
  20649. // if width = 1, when u0 even keep items as is, when odd divide by 2
  20650. if ((u0 & 1) !== 0) {
  20651. for (v = 0, k = 0; v < height; v++, k += width) {
  20652. items[k] *= 0.5;
  20653. }
  20654. }
  20655. } else {
  20656. for (v = 0, k = 0; v < height; v++, k += width) {
  20657. rowBuffer.set(items.subarray(k, k + width), bufferPadding);
  20658. this.extend(rowBuffer, bufferPadding, width);
  20659. this.filter(rowBuffer, bufferPadding, width);
  20660. items.set(
  20661. rowBuffer.subarray(bufferPadding, bufferPadding + width),
  20662. k);
  20663. }
  20664. }
  20665. // Accesses to the items array can take long, because it may not fit into
  20666. // CPU cache and has to be fetched from main memory. Since subsequent
  20667. // accesses to the items array are not local when reading columns, we
  20668. // have a cache miss every time. To reduce cache misses, get up to
  20669. // 'numBuffers' items at a time and store them into the individual
  20670. // buffers. The colBuffers should be small enough to fit into CPU cache.
  20671. var numBuffers = 16;
  20672. var colBuffers = [];
  20673. for (i = 0; i < numBuffers; i++) {
  20674. colBuffers.push(new Float32Array(height + 2 * bufferPadding));
  20675. }
  20676. var b, currentBuffer = 0;
  20677. ll = bufferPadding + height;
  20678. // Section F.3.5 VER_SR
  20679. if (height === 1) {
  20680. // if height = 1, when v0 even keep items as is, when odd divide by 2
  20681. if ((v0 & 1) !== 0) {
  20682. for (u = 0; u < width; u++) {
  20683. items[u] *= 0.5;
  20684. }
  20685. }
  20686. } else {
  20687. for (u = 0; u < width; u++) {
  20688. // if we ran out of buffers, copy several image columns at once
  20689. if (currentBuffer === 0) {
  20690. numBuffers = Math.min(width - u, numBuffers);
  20691. for (k = u, l = bufferPadding; l < ll; k += width, l++) {
  20692. for (b = 0; b < numBuffers; b++) {
  20693. colBuffers[b][l] = items[k + b];
  20694. }
  20695. }
  20696. currentBuffer = numBuffers;
  20697. }
  20698. currentBuffer--;
  20699. var buffer = colBuffers[currentBuffer];
  20700. this.extend(buffer, bufferPadding, height);
  20701. this.filter(buffer, bufferPadding, height);
  20702. // If this is last buffer in this group of buffers, flush all buffers.
  20703. if (currentBuffer === 0) {
  20704. k = u - numBuffers + 1;
  20705. for (l = bufferPadding; l < ll; k += width, l++) {
  20706. for (b = 0; b < numBuffers; b++) {
  20707. items[k + b] = colBuffers[b][l];
  20708. }
  20709. }
  20710. }
  20711. }
  20712. }
  20713. return {
  20714. width: width,
  20715. height: height,
  20716. items: items
  20717. };
  20718. };
  20719. return Transform;
  20720. })();
  20721. // Section 3.8.2 Irreversible 9-7 filter
  20722. var IrreversibleTransform = (function IrreversibleTransformClosure() {
  20723. function IrreversibleTransform() {
  20724. Transform.call(this);
  20725. }
  20726. IrreversibleTransform.prototype = Object.create(Transform.prototype);
  20727. IrreversibleTransform.prototype.filter =
  20728. function irreversibleTransformFilter(x, offset, length) {
  20729. var len = length >> 1;
  20730. offset = offset | 0;
  20731. var j, n, current, next;
  20732. var alpha = -1.586134342059924;
  20733. var beta = -0.052980118572961;
  20734. var gamma = 0.882911075530934;
  20735. var delta = 0.443506852043971;
  20736. var K = 1.230174104914001;
  20737. var K_ = 1 / K;
  20738. // step 1 is combined with step 3
  20739. // step 2
  20740. j = offset - 3;
  20741. for (n = len + 4; n--; j += 2) {
  20742. x[j] *= K_;
  20743. }
  20744. // step 1 & 3
  20745. j = offset - 2;
  20746. current = delta * x[j -1];
  20747. for (n = len + 3; n--; j += 2) {
  20748. next = delta * x[j + 1];
  20749. x[j] = K * x[j] - current - next;
  20750. if (n--) {
  20751. j += 2;
  20752. current = delta * x[j + 1];
  20753. x[j] = K * x[j] - current - next;
  20754. } else {
  20755. break;
  20756. }
  20757. }
  20758. // step 4
  20759. j = offset - 1;
  20760. current = gamma * x[j - 1];
  20761. for (n = len + 2; n--; j += 2) {
  20762. next = gamma * x[j + 1];
  20763. x[j] -= current + next;
  20764. if (n--) {
  20765. j += 2;
  20766. current = gamma * x[j + 1];
  20767. x[j] -= current + next;
  20768. } else {
  20769. break;
  20770. }
  20771. }
  20772. // step 5
  20773. j = offset;
  20774. current = beta * x[j - 1];
  20775. for (n = len + 1; n--; j += 2) {
  20776. next = beta * x[j + 1];
  20777. x[j] -= current + next;
  20778. if (n--) {
  20779. j += 2;
  20780. current = beta * x[j + 1];
  20781. x[j] -= current + next;
  20782. } else {
  20783. break;
  20784. }
  20785. }
  20786. // step 6
  20787. if (len !== 0) {
  20788. j = offset + 1;
  20789. current = alpha * x[j - 1];
  20790. for (n = len; n--; j += 2) {
  20791. next = alpha * x[j + 1];
  20792. x[j] -= current + next;
  20793. if (n--) {
  20794. j += 2;
  20795. current = alpha * x[j + 1];
  20796. x[j] -= current + next;
  20797. } else {
  20798. break;
  20799. }
  20800. }
  20801. }
  20802. };
  20803. return IrreversibleTransform;
  20804. })();
  20805. // Section 3.8.1 Reversible 5-3 filter
  20806. var ReversibleTransform = (function ReversibleTransformClosure() {
  20807. function ReversibleTransform() {
  20808. Transform.call(this);
  20809. }
  20810. ReversibleTransform.prototype = Object.create(Transform.prototype);
  20811. ReversibleTransform.prototype.filter =
  20812. function reversibleTransformFilter(x, offset, length) {
  20813. var len = length >> 1;
  20814. offset = offset | 0;
  20815. var j, n;
  20816. for (j = offset, n = len + 1; n--; j += 2) {
  20817. x[j] -= (x[j - 1] + x[j + 1] + 2) >> 2;
  20818. }
  20819. for (j = offset + 1, n = len; n--; j += 2) {
  20820. x[j] += (x[j - 1] + x[j + 1]) >> 1;
  20821. }
  20822. };
  20823. return ReversibleTransform;
  20824. })();
  20825. return JpxImage;
  20826. })();
  20827. exports.JpxImage = JpxImage;
  20828. }));
  20829. (function (root, factory) {
  20830. {
  20831. factory((root.pdfjsCoreMurmurHash3 = {}), root.pdfjsSharedUtil);
  20832. }
  20833. }(this, function (exports, sharedUtil) {
  20834. var Uint32ArrayView = sharedUtil.Uint32ArrayView;
  20835. var MurmurHash3_64 = (function MurmurHash3_64Closure (seed) {
  20836. // Workaround for missing math precison in JS.
  20837. var MASK_HIGH = 0xffff0000;
  20838. var MASK_LOW = 0xffff;
  20839. function MurmurHash3_64 (seed) {
  20840. var SEED = 0xc3d2e1f0;
  20841. this.h1 = seed ? seed & 0xffffffff : SEED;
  20842. this.h2 = seed ? seed & 0xffffffff : SEED;
  20843. }
  20844. var alwaysUseUint32ArrayView = false;
  20845. // old webkits have issues with non-aligned arrays
  20846. try {
  20847. new Uint32Array(new Uint8Array(5).buffer, 0, 1);
  20848. } catch (e) {
  20849. alwaysUseUint32ArrayView = true;
  20850. }
  20851. MurmurHash3_64.prototype = {
  20852. update: function MurmurHash3_64_update(input) {
  20853. var useUint32ArrayView = alwaysUseUint32ArrayView;
  20854. var i;
  20855. if (typeof input === 'string') {
  20856. var data = new Uint8Array(input.length * 2);
  20857. var length = 0;
  20858. for (i = 0; i < input.length; i++) {
  20859. var code = input.charCodeAt(i);
  20860. if (code <= 0xff) {
  20861. data[length++] = code;
  20862. }
  20863. else {
  20864. data[length++] = code >>> 8;
  20865. data[length++] = code & 0xff;
  20866. }
  20867. }
  20868. } else if (input instanceof Uint8Array) {
  20869. data = input;
  20870. length = data.length;
  20871. } else if (typeof input === 'object' && ('length' in input)) {
  20872. // processing regular arrays as well, e.g. for IE9
  20873. data = input;
  20874. length = data.length;
  20875. useUint32ArrayView = true;
  20876. } else {
  20877. throw new Error('Wrong data format in MurmurHash3_64_update. ' +
  20878. 'Input must be a string or array.');
  20879. }
  20880. var blockCounts = length >> 2;
  20881. var tailLength = length - blockCounts * 4;
  20882. // we don't care about endianness here
  20883. var dataUint32 = useUint32ArrayView ?
  20884. new Uint32ArrayView(data, blockCounts) :
  20885. new Uint32Array(data.buffer, 0, blockCounts);
  20886. var k1 = 0;
  20887. var k2 = 0;
  20888. var h1 = this.h1;
  20889. var h2 = this.h2;
  20890. var C1 = 0xcc9e2d51;
  20891. var C2 = 0x1b873593;
  20892. var C1_LOW = C1 & MASK_LOW;
  20893. var C2_LOW = C2 & MASK_LOW;
  20894. for (i = 0; i < blockCounts; i++) {
  20895. if (i & 1) {
  20896. k1 = dataUint32[i];
  20897. k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);
  20898. k1 = k1 << 15 | k1 >>> 17;
  20899. k1 = (k1 * C2 & MASK_HIGH) | (k1 * C2_LOW & MASK_LOW);
  20900. h1 ^= k1;
  20901. h1 = h1 << 13 | h1 >>> 19;
  20902. h1 = h1 * 5 + 0xe6546b64;
  20903. } else {
  20904. k2 = dataUint32[i];
  20905. k2 = (k2 * C1 & MASK_HIGH) | (k2 * C1_LOW & MASK_LOW);
  20906. k2 = k2 << 15 | k2 >>> 17;
  20907. k2 = (k2 * C2 & MASK_HIGH) | (k2 * C2_LOW & MASK_LOW);
  20908. h2 ^= k2;
  20909. h2 = h2 << 13 | h2 >>> 19;
  20910. h2 = h2 * 5 + 0xe6546b64;
  20911. }
  20912. }
  20913. k1 = 0;
  20914. switch (tailLength) {
  20915. case 3:
  20916. k1 ^= data[blockCounts * 4 + 2] << 16;
  20917. /* falls through */
  20918. case 2:
  20919. k1 ^= data[blockCounts * 4 + 1] << 8;
  20920. /* falls through */
  20921. case 1:
  20922. k1 ^= data[blockCounts * 4];
  20923. /* falls through */
  20924. k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);
  20925. k1 = k1 << 15 | k1 >>> 17;
  20926. k1 = (k1 * C2 & MASK_HIGH) | (k1 * C2_LOW & MASK_LOW);
  20927. if (blockCounts & 1) {
  20928. h1 ^= k1;
  20929. } else {
  20930. h2 ^= k1;
  20931. }
  20932. }
  20933. this.h1 = h1;
  20934. this.h2 = h2;
  20935. return this;
  20936. },
  20937. hexdigest: function MurmurHash3_64_hexdigest () {
  20938. var h1 = this.h1;
  20939. var h2 = this.h2;
  20940. h1 ^= h2 >>> 1;
  20941. h1 = (h1 * 0xed558ccd & MASK_HIGH) | (h1 * 0x8ccd & MASK_LOW);
  20942. h2 = (h2 * 0xff51afd7 & MASK_HIGH) |
  20943. (((h2 << 16 | h1 >>> 16) * 0xafd7ed55 & MASK_HIGH) >>> 16);
  20944. h1 ^= h2 >>> 1;
  20945. h1 = (h1 * 0x1a85ec53 & MASK_HIGH) | (h1 * 0xec53 & MASK_LOW);
  20946. h2 = (h2 * 0xc4ceb9fe & MASK_HIGH) |
  20947. (((h2 << 16 | h1 >>> 16) * 0xb9fe1a85 & MASK_HIGH) >>> 16);
  20948. h1 ^= h2 >>> 1;
  20949. for (var i = 0, arr = [h1, h2], str = ''; i < arr.length; i++) {
  20950. var hex = (arr[i] >>> 0).toString(16);
  20951. while (hex.length < 8) {
  20952. hex = '0' + hex;
  20953. }
  20954. str += hex;
  20955. }
  20956. return str;
  20957. }
  20958. };
  20959. return MurmurHash3_64;
  20960. })();
  20961. exports.MurmurHash3_64 = MurmurHash3_64;
  20962. }));
  20963. (function (root, factory) {
  20964. {
  20965. factory((root.pdfjsCorePrimitives = {}), root.pdfjsSharedUtil);
  20966. }
  20967. }(this, function (exports, sharedUtil) {
  20968. var isArray = sharedUtil.isArray;
  20969. var Name = (function NameClosure() {
  20970. function Name(name) {
  20971. this.name = name;
  20972. }
  20973. Name.prototype = {};
  20974. var nameCache = {};
  20975. Name.get = function Name_get(name) {
  20976. var nameValue = nameCache[name];
  20977. return (nameValue ? nameValue : (nameCache[name] = new Name(name)));
  20978. };
  20979. return Name;
  20980. })();
  20981. var Cmd = (function CmdClosure() {
  20982. function Cmd(cmd) {
  20983. this.cmd = cmd;
  20984. }
  20985. Cmd.prototype = {};
  20986. var cmdCache = {};
  20987. Cmd.get = function Cmd_get(cmd) {
  20988. var cmdValue = cmdCache[cmd];
  20989. return (cmdValue ? cmdValue : (cmdCache[cmd] = new Cmd(cmd)));
  20990. };
  20991. return Cmd;
  20992. })();
  20993. var Dict = (function DictClosure() {
  20994. var nonSerializable = function nonSerializableClosure() {
  20995. return nonSerializable; // creating closure on some variable
  20996. };
  20997. var GETALL_DICTIONARY_TYPES_WHITELIST = {
  20998. 'Background': true,
  20999. 'ExtGState': true,
  21000. 'Halftone': true,
  21001. 'Layout': true,
  21002. 'Mask': true,
  21003. 'Pagination': true,
  21004. 'Printing': true
  21005. };
  21006. function isRecursionAllowedFor(dict) {
  21007. if (!isName(dict.Type)) {
  21008. return true;
  21009. }
  21010. var dictType = dict.Type.name;
  21011. return GETALL_DICTIONARY_TYPES_WHITELIST[dictType] === true;
  21012. }
  21013. // xref is optional
  21014. function Dict(xref) {
  21015. // Map should only be used internally, use functions below to access.
  21016. this.map = Object.create(null);
  21017. this.xref = xref;
  21018. this.objId = null;
  21019. this.__nonSerializable__ = nonSerializable; // disable cloning of the Dict
  21020. }
  21021. Dict.prototype = {
  21022. assignXref: function Dict_assignXref(newXref) {
  21023. this.xref = newXref;
  21024. },
  21025. // automatically dereferences Ref objects
  21026. get: function Dict_get(key1, key2, key3) {
  21027. var value;
  21028. var xref = this.xref;
  21029. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
  21030. typeof key2 === 'undefined') {
  21031. return xref ? xref.fetchIfRef(value) : value;
  21032. }
  21033. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
  21034. typeof key3 === 'undefined') {
  21035. return xref ? xref.fetchIfRef(value) : value;
  21036. }
  21037. value = this.map[key3] || null;
  21038. return xref ? xref.fetchIfRef(value) : value;
  21039. },
  21040. // Same as get(), but returns a promise and uses fetchIfRefAsync().
  21041. getAsync: function Dict_getAsync(key1, key2, key3) {
  21042. var value;
  21043. var xref = this.xref;
  21044. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
  21045. typeof key2 === 'undefined') {
  21046. if (xref) {
  21047. return xref.fetchIfRefAsync(value);
  21048. }
  21049. return Promise.resolve(value);
  21050. }
  21051. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
  21052. typeof key3 === 'undefined') {
  21053. if (xref) {
  21054. return xref.fetchIfRefAsync(value);
  21055. }
  21056. return Promise.resolve(value);
  21057. }
  21058. value = this.map[key3] || null;
  21059. if (xref) {
  21060. return xref.fetchIfRefAsync(value);
  21061. }
  21062. return Promise.resolve(value);
  21063. },
  21064. // Same as get(), but dereferences all elements if the result is an Array.
  21065. getArray: function Dict_getArray(key1, key2, key3) {
  21066. var value = this.get(key1, key2, key3);
  21067. var xref = this.xref;
  21068. if (!isArray(value) || !xref) {
  21069. return value;
  21070. }
  21071. value = value.slice(); // Ensure that we don't modify the Dict data.
  21072. for (var i = 0, ii = value.length; i < ii; i++) {
  21073. if (!isRef(value[i])) {
  21074. continue;
  21075. }
  21076. value[i] = xref.fetch(value[i]);
  21077. }
  21078. return value;
  21079. },
  21080. // no dereferencing
  21081. getRaw: function Dict_getRaw(key) {
  21082. return this.map[key];
  21083. },
  21084. // creates new map and dereferences all Refs
  21085. getAll: function Dict_getAll() {
  21086. var all = Object.create(null);
  21087. var queue = null;
  21088. var key, obj;
  21089. for (key in this.map) {
  21090. obj = this.get(key);
  21091. if (obj instanceof Dict) {
  21092. if (isRecursionAllowedFor(obj)) {
  21093. (queue || (queue = [])).push({target: all, key: key, obj: obj});
  21094. } else {
  21095. all[key] = this.getRaw(key);
  21096. }
  21097. } else {
  21098. all[key] = obj;
  21099. }
  21100. }
  21101. if (!queue) {
  21102. return all;
  21103. }
  21104. // trying to take cyclic references into the account
  21105. var processed = Object.create(null);
  21106. while (queue.length > 0) {
  21107. var item = queue.shift();
  21108. var itemObj = item.obj;
  21109. var objId = itemObj.objId;
  21110. if (objId && objId in processed) {
  21111. item.target[item.key] = processed[objId];
  21112. continue;
  21113. }
  21114. var dereferenced = Object.create(null);
  21115. for (key in itemObj.map) {
  21116. obj = itemObj.get(key);
  21117. if (obj instanceof Dict) {
  21118. if (isRecursionAllowedFor(obj)) {
  21119. queue.push({target: dereferenced, key: key, obj: obj});
  21120. } else {
  21121. dereferenced[key] = itemObj.getRaw(key);
  21122. }
  21123. } else {
  21124. dereferenced[key] = obj;
  21125. }
  21126. }
  21127. if (objId) {
  21128. processed[objId] = dereferenced;
  21129. }
  21130. item.target[item.key] = dereferenced;
  21131. }
  21132. return all;
  21133. },
  21134. getKeys: function Dict_getKeys() {
  21135. return Object.keys(this.map);
  21136. },
  21137. set: function Dict_set(key, value) {
  21138. this.map[key] = value;
  21139. },
  21140. has: function Dict_has(key) {
  21141. return key in this.map;
  21142. },
  21143. forEach: function Dict_forEach(callback) {
  21144. for (var key in this.map) {
  21145. callback(key, this.get(key));
  21146. }
  21147. }
  21148. };
  21149. Dict.empty = new Dict(null);
  21150. Dict.merge = function Dict_merge(xref, dictArray) {
  21151. var mergedDict = new Dict(xref);
  21152. for (var i = 0, ii = dictArray.length; i < ii; i++) {
  21153. var dict = dictArray[i];
  21154. if (!isDict(dict)) {
  21155. continue;
  21156. }
  21157. for (var keyName in dict.map) {
  21158. if (mergedDict.map[keyName]) {
  21159. continue;
  21160. }
  21161. mergedDict.map[keyName] = dict.map[keyName];
  21162. }
  21163. }
  21164. return mergedDict;
  21165. };
  21166. return Dict;
  21167. })();
  21168. var Ref = (function RefClosure() {
  21169. function Ref(num, gen) {
  21170. this.num = num;
  21171. this.gen = gen;
  21172. }
  21173. Ref.prototype = {
  21174. toString: function Ref_toString() {
  21175. // This function is hot, so we make the string as compact as possible.
  21176. // |this.gen| is almost always zero, so we treat that case specially.
  21177. var str = this.num + 'R';
  21178. if (this.gen !== 0) {
  21179. str += this.gen;
  21180. }
  21181. return str;
  21182. }
  21183. };
  21184. return Ref;
  21185. })();
  21186. // The reference is identified by number and generation.
  21187. // This structure stores only one instance of the reference.
  21188. var RefSet = (function RefSetClosure() {
  21189. function RefSet() {
  21190. this.dict = {};
  21191. }
  21192. RefSet.prototype = {
  21193. has: function RefSet_has(ref) {
  21194. return ref.toString() in this.dict;
  21195. },
  21196. put: function RefSet_put(ref) {
  21197. this.dict[ref.toString()] = true;
  21198. },
  21199. remove: function RefSet_remove(ref) {
  21200. delete this.dict[ref.toString()];
  21201. }
  21202. };
  21203. return RefSet;
  21204. })();
  21205. var RefSetCache = (function RefSetCacheClosure() {
  21206. function RefSetCache() {
  21207. this.dict = Object.create(null);
  21208. }
  21209. RefSetCache.prototype = {
  21210. get: function RefSetCache_get(ref) {
  21211. return this.dict[ref.toString()];
  21212. },
  21213. has: function RefSetCache_has(ref) {
  21214. return ref.toString() in this.dict;
  21215. },
  21216. put: function RefSetCache_put(ref, obj) {
  21217. this.dict[ref.toString()] = obj;
  21218. },
  21219. putAlias: function RefSetCache_putAlias(ref, aliasRef) {
  21220. this.dict[ref.toString()] = this.get(aliasRef);
  21221. },
  21222. forEach: function RefSetCache_forEach(fn, thisArg) {
  21223. for (var i in this.dict) {
  21224. fn.call(thisArg, this.dict[i]);
  21225. }
  21226. },
  21227. clear: function RefSetCache_clear() {
  21228. this.dict = Object.create(null);
  21229. }
  21230. };
  21231. return RefSetCache;
  21232. })();
  21233. function isName(v) {
  21234. return v instanceof Name;
  21235. }
  21236. function isCmd(v, cmd) {
  21237. return v instanceof Cmd && (cmd === undefined || v.cmd === cmd);
  21238. }
  21239. function isDict(v, type) {
  21240. if (!(v instanceof Dict)) {
  21241. return false;
  21242. }
  21243. if (!type) {
  21244. return true;
  21245. }
  21246. var dictType = v.get('Type');
  21247. return isName(dictType) && dictType.name === type;
  21248. }
  21249. function isRef(v) {
  21250. return v instanceof Ref;
  21251. }
  21252. function isStream(v) {
  21253. return typeof v === 'object' && v !== null && v.getBytes !== undefined;
  21254. }
  21255. exports.Cmd = Cmd;
  21256. exports.Dict = Dict;
  21257. exports.Name = Name;
  21258. exports.Ref = Ref;
  21259. exports.RefSet = RefSet;
  21260. exports.RefSetCache = RefSetCache;
  21261. exports.isCmd = isCmd;
  21262. exports.isDict = isDict;
  21263. exports.isName = isName;
  21264. exports.isRef = isRef;
  21265. exports.isStream = isStream;
  21266. }));
  21267. (function (root, factory) {
  21268. {
  21269. factory((root.pdfjsCoreStream = {}), root.pdfjsSharedUtil,
  21270. root.pdfjsCorePrimitives, root.pdfjsCoreJbig2, root.pdfjsCoreJpg,
  21271. root.pdfjsCoreJpx);
  21272. }
  21273. }(this, function (exports, sharedUtil, corePrimitives, coreJbig2, coreJpg,
  21274. coreJpx) {
  21275. var Util = sharedUtil.Util;
  21276. var error = sharedUtil.error;
  21277. var info = sharedUtil.info;
  21278. var isArray = sharedUtil.isArray;
  21279. var shadow = sharedUtil.shadow;
  21280. var warn = sharedUtil.warn;
  21281. var Dict = corePrimitives.Dict;
  21282. var Jbig2Image = coreJbig2.Jbig2Image;
  21283. var JpegImage = coreJpg.JpegImage;
  21284. var JpxImage = coreJpx.JpxImage;
  21285. var coreParser; // see _setCoreParser below
  21286. var EOF; // = coreParser.EOF;
  21287. var Lexer; // = coreParser.Lexer;
  21288. var coreColorSpace; // see _setCoreColorSpace below
  21289. var ColorSpace; // = coreColorSpace.ColorSpace;
  21290. var Stream = (function StreamClosure() {
  21291. function Stream(arrayBuffer, start, length, dict) {
  21292. this.bytes = (arrayBuffer instanceof Uint8Array ?
  21293. arrayBuffer : new Uint8Array(arrayBuffer));
  21294. this.start = start || 0;
  21295. this.pos = this.start;
  21296. this.end = (start + length) || this.bytes.length;
  21297. this.dict = dict;
  21298. }
  21299. // required methods for a stream. if a particular stream does not
  21300. // implement these, an error should be thrown
  21301. Stream.prototype = {
  21302. get length() {
  21303. return this.end - this.start;
  21304. },
  21305. get isEmpty() {
  21306. return this.length === 0;
  21307. },
  21308. getByte: function Stream_getByte() {
  21309. if (this.pos >= this.end) {
  21310. return -1;
  21311. }
  21312. return this.bytes[this.pos++];
  21313. },
  21314. getUint16: function Stream_getUint16() {
  21315. var b0 = this.getByte();
  21316. var b1 = this.getByte();
  21317. if (b0 === -1 || b1 === -1) {
  21318. return -1;
  21319. }
  21320. return (b0 << 8) + b1;
  21321. },
  21322. getInt32: function Stream_getInt32() {
  21323. var b0 = this.getByte();
  21324. var b1 = this.getByte();
  21325. var b2 = this.getByte();
  21326. var b3 = this.getByte();
  21327. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  21328. },
  21329. // returns subarray of original buffer
  21330. // should only be read
  21331. getBytes: function Stream_getBytes(length) {
  21332. var bytes = this.bytes;
  21333. var pos = this.pos;
  21334. var strEnd = this.end;
  21335. if (!length) {
  21336. return bytes.subarray(pos, strEnd);
  21337. }
  21338. var end = pos + length;
  21339. if (end > strEnd) {
  21340. end = strEnd;
  21341. }
  21342. this.pos = end;
  21343. return bytes.subarray(pos, end);
  21344. },
  21345. peekByte: function Stream_peekByte() {
  21346. var peekedByte = this.getByte();
  21347. this.pos--;
  21348. return peekedByte;
  21349. },
  21350. peekBytes: function Stream_peekBytes(length) {
  21351. var bytes = this.getBytes(length);
  21352. this.pos -= bytes.length;
  21353. return bytes;
  21354. },
  21355. skip: function Stream_skip(n) {
  21356. if (!n) {
  21357. n = 1;
  21358. }
  21359. this.pos += n;
  21360. },
  21361. reset: function Stream_reset() {
  21362. this.pos = this.start;
  21363. },
  21364. moveStart: function Stream_moveStart() {
  21365. this.start = this.pos;
  21366. },
  21367. makeSubStream: function Stream_makeSubStream(start, length, dict) {
  21368. return new Stream(this.bytes.buffer, start, length, dict);
  21369. },
  21370. isStream: true
  21371. };
  21372. return Stream;
  21373. })();
  21374. var StringStream = (function StringStreamClosure() {
  21375. function StringStream(str) {
  21376. var length = str.length;
  21377. var bytes = new Uint8Array(length);
  21378. for (var n = 0; n < length; ++n) {
  21379. bytes[n] = str.charCodeAt(n);
  21380. }
  21381. Stream.call(this, bytes);
  21382. }
  21383. StringStream.prototype = Stream.prototype;
  21384. return StringStream;
  21385. })();
  21386. // super class for the decoding streams
  21387. var DecodeStream = (function DecodeStreamClosure() {
  21388. // Lots of DecodeStreams are created whose buffers are never used. For these
  21389. // we share a single empty buffer. This is (a) space-efficient and (b) avoids
  21390. // having special cases that would be required if we used |null| for an empty
  21391. // buffer.
  21392. var emptyBuffer = new Uint8Array(0);
  21393. function DecodeStream(maybeMinBufferLength) {
  21394. this.pos = 0;
  21395. this.bufferLength = 0;
  21396. this.eof = false;
  21397. this.buffer = emptyBuffer;
  21398. this.minBufferLength = 512;
  21399. if (maybeMinBufferLength) {
  21400. // Compute the first power of two that is as big as maybeMinBufferLength.
  21401. while (this.minBufferLength < maybeMinBufferLength) {
  21402. this.minBufferLength *= 2;
  21403. }
  21404. }
  21405. }
  21406. DecodeStream.prototype = {
  21407. get isEmpty() {
  21408. while (!this.eof && this.bufferLength === 0) {
  21409. this.readBlock();
  21410. }
  21411. return this.bufferLength === 0;
  21412. },
  21413. ensureBuffer: function DecodeStream_ensureBuffer(requested) {
  21414. var buffer = this.buffer;
  21415. if (requested <= buffer.byteLength) {
  21416. return buffer;
  21417. }
  21418. var size = this.minBufferLength;
  21419. while (size < requested) {
  21420. size *= 2;
  21421. }
  21422. var buffer2 = new Uint8Array(size);
  21423. buffer2.set(buffer);
  21424. return (this.buffer = buffer2);
  21425. },
  21426. getByte: function DecodeStream_getByte() {
  21427. var pos = this.pos;
  21428. while (this.bufferLength <= pos) {
  21429. if (this.eof) {
  21430. return -1;
  21431. }
  21432. this.readBlock();
  21433. }
  21434. return this.buffer[this.pos++];
  21435. },
  21436. getUint16: function DecodeStream_getUint16() {
  21437. var b0 = this.getByte();
  21438. var b1 = this.getByte();
  21439. if (b0 === -1 || b1 === -1) {
  21440. return -1;
  21441. }
  21442. return (b0 << 8) + b1;
  21443. },
  21444. getInt32: function DecodeStream_getInt32() {
  21445. var b0 = this.getByte();
  21446. var b1 = this.getByte();
  21447. var b2 = this.getByte();
  21448. var b3 = this.getByte();
  21449. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  21450. },
  21451. getBytes: function DecodeStream_getBytes(length) {
  21452. var end, pos = this.pos;
  21453. if (length) {
  21454. this.ensureBuffer(pos + length);
  21455. end = pos + length;
  21456. while (!this.eof && this.bufferLength < end) {
  21457. this.readBlock();
  21458. }
  21459. var bufEnd = this.bufferLength;
  21460. if (end > bufEnd) {
  21461. end = bufEnd;
  21462. }
  21463. } else {
  21464. while (!this.eof) {
  21465. this.readBlock();
  21466. }
  21467. end = this.bufferLength;
  21468. }
  21469. this.pos = end;
  21470. return this.buffer.subarray(pos, end);
  21471. },
  21472. peekByte: function DecodeStream_peekByte() {
  21473. var peekedByte = this.getByte();
  21474. this.pos--;
  21475. return peekedByte;
  21476. },
  21477. peekBytes: function DecodeStream_peekBytes(length) {
  21478. var bytes = this.getBytes(length);
  21479. this.pos -= bytes.length;
  21480. return bytes;
  21481. },
  21482. makeSubStream: function DecodeStream_makeSubStream(start, length, dict) {
  21483. var end = start + length;
  21484. while (this.bufferLength <= end && !this.eof) {
  21485. this.readBlock();
  21486. }
  21487. return new Stream(this.buffer, start, length, dict);
  21488. },
  21489. skip: function DecodeStream_skip(n) {
  21490. if (!n) {
  21491. n = 1;
  21492. }
  21493. this.pos += n;
  21494. },
  21495. reset: function DecodeStream_reset() {
  21496. this.pos = 0;
  21497. },
  21498. getBaseStreams: function DecodeStream_getBaseStreams() {
  21499. if (this.str && this.str.getBaseStreams) {
  21500. return this.str.getBaseStreams();
  21501. }
  21502. return [];
  21503. }
  21504. };
  21505. return DecodeStream;
  21506. })();
  21507. var StreamsSequenceStream = (function StreamsSequenceStreamClosure() {
  21508. function StreamsSequenceStream(streams) {
  21509. this.streams = streams;
  21510. DecodeStream.call(this, /* maybeLength = */ null);
  21511. }
  21512. StreamsSequenceStream.prototype = Object.create(DecodeStream.prototype);
  21513. StreamsSequenceStream.prototype.readBlock =
  21514. function streamSequenceStreamReadBlock() {
  21515. var streams = this.streams;
  21516. if (streams.length === 0) {
  21517. this.eof = true;
  21518. return;
  21519. }
  21520. var stream = streams.shift();
  21521. var chunk = stream.getBytes();
  21522. var bufferLength = this.bufferLength;
  21523. var newLength = bufferLength + chunk.length;
  21524. var buffer = this.ensureBuffer(newLength);
  21525. buffer.set(chunk, bufferLength);
  21526. this.bufferLength = newLength;
  21527. };
  21528. StreamsSequenceStream.prototype.getBaseStreams =
  21529. function StreamsSequenceStream_getBaseStreams() {
  21530. var baseStreams = [];
  21531. for (var i = 0, ii = this.streams.length; i < ii; i++) {
  21532. var stream = this.streams[i];
  21533. if (stream.getBaseStreams) {
  21534. Util.appendToArray(baseStreams, stream.getBaseStreams());
  21535. }
  21536. }
  21537. return baseStreams;
  21538. };
  21539. return StreamsSequenceStream;
  21540. })();
  21541. var FlateStream = (function FlateStreamClosure() {
  21542. var codeLenCodeMap = new Int32Array([
  21543. 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15
  21544. ]);
  21545. var lengthDecode = new Int32Array([
  21546. 0x00003, 0x00004, 0x00005, 0x00006, 0x00007, 0x00008, 0x00009, 0x0000a,
  21547. 0x1000b, 0x1000d, 0x1000f, 0x10011, 0x20013, 0x20017, 0x2001b, 0x2001f,
  21548. 0x30023, 0x3002b, 0x30033, 0x3003b, 0x40043, 0x40053, 0x40063, 0x40073,
  21549. 0x50083, 0x500a3, 0x500c3, 0x500e3, 0x00102, 0x00102, 0x00102
  21550. ]);
  21551. var distDecode = new Int32Array([
  21552. 0x00001, 0x00002, 0x00003, 0x00004, 0x10005, 0x10007, 0x20009, 0x2000d,
  21553. 0x30011, 0x30019, 0x40021, 0x40031, 0x50041, 0x50061, 0x60081, 0x600c1,
  21554. 0x70101, 0x70181, 0x80201, 0x80301, 0x90401, 0x90601, 0xa0801, 0xa0c01,
  21555. 0xb1001, 0xb1801, 0xc2001, 0xc3001, 0xd4001, 0xd6001
  21556. ]);
  21557. var fixedLitCodeTab = [new Int32Array([
  21558. 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c0,
  21559. 0x70108, 0x80060, 0x80020, 0x900a0, 0x80000, 0x80080, 0x80040, 0x900e0,
  21560. 0x70104, 0x80058, 0x80018, 0x90090, 0x70114, 0x80078, 0x80038, 0x900d0,
  21561. 0x7010c, 0x80068, 0x80028, 0x900b0, 0x80008, 0x80088, 0x80048, 0x900f0,
  21562. 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c8,
  21563. 0x7010a, 0x80064, 0x80024, 0x900a8, 0x80004, 0x80084, 0x80044, 0x900e8,
  21564. 0x70106, 0x8005c, 0x8001c, 0x90098, 0x70116, 0x8007c, 0x8003c, 0x900d8,
  21565. 0x7010e, 0x8006c, 0x8002c, 0x900b8, 0x8000c, 0x8008c, 0x8004c, 0x900f8,
  21566. 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c4,
  21567. 0x70109, 0x80062, 0x80022, 0x900a4, 0x80002, 0x80082, 0x80042, 0x900e4,
  21568. 0x70105, 0x8005a, 0x8001a, 0x90094, 0x70115, 0x8007a, 0x8003a, 0x900d4,
  21569. 0x7010d, 0x8006a, 0x8002a, 0x900b4, 0x8000a, 0x8008a, 0x8004a, 0x900f4,
  21570. 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cc,
  21571. 0x7010b, 0x80066, 0x80026, 0x900ac, 0x80006, 0x80086, 0x80046, 0x900ec,
  21572. 0x70107, 0x8005e, 0x8001e, 0x9009c, 0x70117, 0x8007e, 0x8003e, 0x900dc,
  21573. 0x7010f, 0x8006e, 0x8002e, 0x900bc, 0x8000e, 0x8008e, 0x8004e, 0x900fc,
  21574. 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c2,
  21575. 0x70108, 0x80061, 0x80021, 0x900a2, 0x80001, 0x80081, 0x80041, 0x900e2,
  21576. 0x70104, 0x80059, 0x80019, 0x90092, 0x70114, 0x80079, 0x80039, 0x900d2,
  21577. 0x7010c, 0x80069, 0x80029, 0x900b2, 0x80009, 0x80089, 0x80049, 0x900f2,
  21578. 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900ca,
  21579. 0x7010a, 0x80065, 0x80025, 0x900aa, 0x80005, 0x80085, 0x80045, 0x900ea,
  21580. 0x70106, 0x8005d, 0x8001d, 0x9009a, 0x70116, 0x8007d, 0x8003d, 0x900da,
  21581. 0x7010e, 0x8006d, 0x8002d, 0x900ba, 0x8000d, 0x8008d, 0x8004d, 0x900fa,
  21582. 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c6,
  21583. 0x70109, 0x80063, 0x80023, 0x900a6, 0x80003, 0x80083, 0x80043, 0x900e6,
  21584. 0x70105, 0x8005b, 0x8001b, 0x90096, 0x70115, 0x8007b, 0x8003b, 0x900d6,
  21585. 0x7010d, 0x8006b, 0x8002b, 0x900b6, 0x8000b, 0x8008b, 0x8004b, 0x900f6,
  21586. 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900ce,
  21587. 0x7010b, 0x80067, 0x80027, 0x900ae, 0x80007, 0x80087, 0x80047, 0x900ee,
  21588. 0x70107, 0x8005f, 0x8001f, 0x9009e, 0x70117, 0x8007f, 0x8003f, 0x900de,
  21589. 0x7010f, 0x8006f, 0x8002f, 0x900be, 0x8000f, 0x8008f, 0x8004f, 0x900fe,
  21590. 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c1,
  21591. 0x70108, 0x80060, 0x80020, 0x900a1, 0x80000, 0x80080, 0x80040, 0x900e1,
  21592. 0x70104, 0x80058, 0x80018, 0x90091, 0x70114, 0x80078, 0x80038, 0x900d1,
  21593. 0x7010c, 0x80068, 0x80028, 0x900b1, 0x80008, 0x80088, 0x80048, 0x900f1,
  21594. 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c9,
  21595. 0x7010a, 0x80064, 0x80024, 0x900a9, 0x80004, 0x80084, 0x80044, 0x900e9,
  21596. 0x70106, 0x8005c, 0x8001c, 0x90099, 0x70116, 0x8007c, 0x8003c, 0x900d9,
  21597. 0x7010e, 0x8006c, 0x8002c, 0x900b9, 0x8000c, 0x8008c, 0x8004c, 0x900f9,
  21598. 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c5,
  21599. 0x70109, 0x80062, 0x80022, 0x900a5, 0x80002, 0x80082, 0x80042, 0x900e5,
  21600. 0x70105, 0x8005a, 0x8001a, 0x90095, 0x70115, 0x8007a, 0x8003a, 0x900d5,
  21601. 0x7010d, 0x8006a, 0x8002a, 0x900b5, 0x8000a, 0x8008a, 0x8004a, 0x900f5,
  21602. 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cd,
  21603. 0x7010b, 0x80066, 0x80026, 0x900ad, 0x80006, 0x80086, 0x80046, 0x900ed,
  21604. 0x70107, 0x8005e, 0x8001e, 0x9009d, 0x70117, 0x8007e, 0x8003e, 0x900dd,
  21605. 0x7010f, 0x8006e, 0x8002e, 0x900bd, 0x8000e, 0x8008e, 0x8004e, 0x900fd,
  21606. 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c3,
  21607. 0x70108, 0x80061, 0x80021, 0x900a3, 0x80001, 0x80081, 0x80041, 0x900e3,
  21608. 0x70104, 0x80059, 0x80019, 0x90093, 0x70114, 0x80079, 0x80039, 0x900d3,
  21609. 0x7010c, 0x80069, 0x80029, 0x900b3, 0x80009, 0x80089, 0x80049, 0x900f3,
  21610. 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900cb,
  21611. 0x7010a, 0x80065, 0x80025, 0x900ab, 0x80005, 0x80085, 0x80045, 0x900eb,
  21612. 0x70106, 0x8005d, 0x8001d, 0x9009b, 0x70116, 0x8007d, 0x8003d, 0x900db,
  21613. 0x7010e, 0x8006d, 0x8002d, 0x900bb, 0x8000d, 0x8008d, 0x8004d, 0x900fb,
  21614. 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c7,
  21615. 0x70109, 0x80063, 0x80023, 0x900a7, 0x80003, 0x80083, 0x80043, 0x900e7,
  21616. 0x70105, 0x8005b, 0x8001b, 0x90097, 0x70115, 0x8007b, 0x8003b, 0x900d7,
  21617. 0x7010d, 0x8006b, 0x8002b, 0x900b7, 0x8000b, 0x8008b, 0x8004b, 0x900f7,
  21618. 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900cf,
  21619. 0x7010b, 0x80067, 0x80027, 0x900af, 0x80007, 0x80087, 0x80047, 0x900ef,
  21620. 0x70107, 0x8005f, 0x8001f, 0x9009f, 0x70117, 0x8007f, 0x8003f, 0x900df,
  21621. 0x7010f, 0x8006f, 0x8002f, 0x900bf, 0x8000f, 0x8008f, 0x8004f, 0x900ff
  21622. ]), 9];
  21623. var fixedDistCodeTab = [new Int32Array([
  21624. 0x50000, 0x50010, 0x50008, 0x50018, 0x50004, 0x50014, 0x5000c, 0x5001c,
  21625. 0x50002, 0x50012, 0x5000a, 0x5001a, 0x50006, 0x50016, 0x5000e, 0x00000,
  21626. 0x50001, 0x50011, 0x50009, 0x50019, 0x50005, 0x50015, 0x5000d, 0x5001d,
  21627. 0x50003, 0x50013, 0x5000b, 0x5001b, 0x50007, 0x50017, 0x5000f, 0x00000
  21628. ]), 5];
  21629. function FlateStream(str, maybeLength) {
  21630. this.str = str;
  21631. this.dict = str.dict;
  21632. var cmf = str.getByte();
  21633. var flg = str.getByte();
  21634. if (cmf === -1 || flg === -1) {
  21635. error('Invalid header in flate stream: ' + cmf + ', ' + flg);
  21636. }
  21637. if ((cmf & 0x0f) !== 0x08) {
  21638. error('Unknown compression method in flate stream: ' + cmf + ', ' + flg);
  21639. }
  21640. if ((((cmf << 8) + flg) % 31) !== 0) {
  21641. error('Bad FCHECK in flate stream: ' + cmf + ', ' + flg);
  21642. }
  21643. if (flg & 0x20) {
  21644. error('FDICT bit set in flate stream: ' + cmf + ', ' + flg);
  21645. }
  21646. this.codeSize = 0;
  21647. this.codeBuf = 0;
  21648. DecodeStream.call(this, maybeLength);
  21649. }
  21650. FlateStream.prototype = Object.create(DecodeStream.prototype);
  21651. FlateStream.prototype.getBits = function FlateStream_getBits(bits) {
  21652. var str = this.str;
  21653. var codeSize = this.codeSize;
  21654. var codeBuf = this.codeBuf;
  21655. var b;
  21656. while (codeSize < bits) {
  21657. if ((b = str.getByte()) === -1) {
  21658. error('Bad encoding in flate stream');
  21659. }
  21660. codeBuf |= b << codeSize;
  21661. codeSize += 8;
  21662. }
  21663. b = codeBuf & ((1 << bits) - 1);
  21664. this.codeBuf = codeBuf >> bits;
  21665. this.codeSize = codeSize -= bits;
  21666. return b;
  21667. };
  21668. FlateStream.prototype.getCode = function FlateStream_getCode(table) {
  21669. var str = this.str;
  21670. var codes = table[0];
  21671. var maxLen = table[1];
  21672. var codeSize = this.codeSize;
  21673. var codeBuf = this.codeBuf;
  21674. var b;
  21675. while (codeSize < maxLen) {
  21676. if ((b = str.getByte()) === -1) {
  21677. // premature end of stream. code might however still be valid.
  21678. // codeSize < codeLen check below guards against incomplete codeVal.
  21679. break;
  21680. }
  21681. codeBuf |= (b << codeSize);
  21682. codeSize += 8;
  21683. }
  21684. var code = codes[codeBuf & ((1 << maxLen) - 1)];
  21685. var codeLen = code >> 16;
  21686. var codeVal = code & 0xffff;
  21687. if (codeLen < 1 || codeSize < codeLen) {
  21688. error('Bad encoding in flate stream');
  21689. }
  21690. this.codeBuf = (codeBuf >> codeLen);
  21691. this.codeSize = (codeSize - codeLen);
  21692. return codeVal;
  21693. };
  21694. FlateStream.prototype.generateHuffmanTable =
  21695. function flateStreamGenerateHuffmanTable(lengths) {
  21696. var n = lengths.length;
  21697. // find max code length
  21698. var maxLen = 0;
  21699. var i;
  21700. for (i = 0; i < n; ++i) {
  21701. if (lengths[i] > maxLen) {
  21702. maxLen = lengths[i];
  21703. }
  21704. }
  21705. // build the table
  21706. var size = 1 << maxLen;
  21707. var codes = new Int32Array(size);
  21708. for (var len = 1, code = 0, skip = 2;
  21709. len <= maxLen;
  21710. ++len, code <<= 1, skip <<= 1) {
  21711. for (var val = 0; val < n; ++val) {
  21712. if (lengths[val] === len) {
  21713. // bit-reverse the code
  21714. var code2 = 0;
  21715. var t = code;
  21716. for (i = 0; i < len; ++i) {
  21717. code2 = (code2 << 1) | (t & 1);
  21718. t >>= 1;
  21719. }
  21720. // fill the table entries
  21721. for (i = code2; i < size; i += skip) {
  21722. codes[i] = (len << 16) | val;
  21723. }
  21724. ++code;
  21725. }
  21726. }
  21727. }
  21728. return [codes, maxLen];
  21729. };
  21730. FlateStream.prototype.readBlock = function FlateStream_readBlock() {
  21731. var buffer, len;
  21732. var str = this.str;
  21733. // read block header
  21734. var hdr = this.getBits(3);
  21735. if (hdr & 1) {
  21736. this.eof = true;
  21737. }
  21738. hdr >>= 1;
  21739. if (hdr === 0) { // uncompressed block
  21740. var b;
  21741. if ((b = str.getByte()) === -1) {
  21742. error('Bad block header in flate stream');
  21743. }
  21744. var blockLen = b;
  21745. if ((b = str.getByte()) === -1) {
  21746. error('Bad block header in flate stream');
  21747. }
  21748. blockLen |= (b << 8);
  21749. if ((b = str.getByte()) === -1) {
  21750. error('Bad block header in flate stream');
  21751. }
  21752. var check = b;
  21753. if ((b = str.getByte()) === -1) {
  21754. error('Bad block header in flate stream');
  21755. }
  21756. check |= (b << 8);
  21757. if (check !== (~blockLen & 0xffff) &&
  21758. (blockLen !== 0 || check !== 0)) {
  21759. // Ignoring error for bad "empty" block (see issue 1277)
  21760. error('Bad uncompressed block length in flate stream');
  21761. }
  21762. this.codeBuf = 0;
  21763. this.codeSize = 0;
  21764. var bufferLength = this.bufferLength;
  21765. buffer = this.ensureBuffer(bufferLength + blockLen);
  21766. var end = bufferLength + blockLen;
  21767. this.bufferLength = end;
  21768. if (blockLen === 0) {
  21769. if (str.peekByte() === -1) {
  21770. this.eof = true;
  21771. }
  21772. } else {
  21773. for (var n = bufferLength; n < end; ++n) {
  21774. if ((b = str.getByte()) === -1) {
  21775. this.eof = true;
  21776. break;
  21777. }
  21778. buffer[n] = b;
  21779. }
  21780. }
  21781. return;
  21782. }
  21783. var litCodeTable;
  21784. var distCodeTable;
  21785. if (hdr === 1) { // compressed block, fixed codes
  21786. litCodeTable = fixedLitCodeTab;
  21787. distCodeTable = fixedDistCodeTab;
  21788. } else if (hdr === 2) { // compressed block, dynamic codes
  21789. var numLitCodes = this.getBits(5) + 257;
  21790. var numDistCodes = this.getBits(5) + 1;
  21791. var numCodeLenCodes = this.getBits(4) + 4;
  21792. // build the code lengths code table
  21793. var codeLenCodeLengths = new Uint8Array(codeLenCodeMap.length);
  21794. var i;
  21795. for (i = 0; i < numCodeLenCodes; ++i) {
  21796. codeLenCodeLengths[codeLenCodeMap[i]] = this.getBits(3);
  21797. }
  21798. var codeLenCodeTab = this.generateHuffmanTable(codeLenCodeLengths);
  21799. // build the literal and distance code tables
  21800. len = 0;
  21801. i = 0;
  21802. var codes = numLitCodes + numDistCodes;
  21803. var codeLengths = new Uint8Array(codes);
  21804. var bitsLength, bitsOffset, what;
  21805. while (i < codes) {
  21806. var code = this.getCode(codeLenCodeTab);
  21807. if (code === 16) {
  21808. bitsLength = 2; bitsOffset = 3; what = len;
  21809. } else if (code === 17) {
  21810. bitsLength = 3; bitsOffset = 3; what = (len = 0);
  21811. } else if (code === 18) {
  21812. bitsLength = 7; bitsOffset = 11; what = (len = 0);
  21813. } else {
  21814. codeLengths[i++] = len = code;
  21815. continue;
  21816. }
  21817. var repeatLength = this.getBits(bitsLength) + bitsOffset;
  21818. while (repeatLength-- > 0) {
  21819. codeLengths[i++] = what;
  21820. }
  21821. }
  21822. litCodeTable =
  21823. this.generateHuffmanTable(codeLengths.subarray(0, numLitCodes));
  21824. distCodeTable =
  21825. this.generateHuffmanTable(codeLengths.subarray(numLitCodes, codes));
  21826. } else {
  21827. error('Unknown block type in flate stream');
  21828. }
  21829. buffer = this.buffer;
  21830. var limit = buffer ? buffer.length : 0;
  21831. var pos = this.bufferLength;
  21832. while (true) {
  21833. var code1 = this.getCode(litCodeTable);
  21834. if (code1 < 256) {
  21835. if (pos + 1 >= limit) {
  21836. buffer = this.ensureBuffer(pos + 1);
  21837. limit = buffer.length;
  21838. }
  21839. buffer[pos++] = code1;
  21840. continue;
  21841. }
  21842. if (code1 === 256) {
  21843. this.bufferLength = pos;
  21844. return;
  21845. }
  21846. code1 -= 257;
  21847. code1 = lengthDecode[code1];
  21848. var code2 = code1 >> 16;
  21849. if (code2 > 0) {
  21850. code2 = this.getBits(code2);
  21851. }
  21852. len = (code1 & 0xffff) + code2;
  21853. code1 = this.getCode(distCodeTable);
  21854. code1 = distDecode[code1];
  21855. code2 = code1 >> 16;
  21856. if (code2 > 0) {
  21857. code2 = this.getBits(code2);
  21858. }
  21859. var dist = (code1 & 0xffff) + code2;
  21860. if (pos + len >= limit) {
  21861. buffer = this.ensureBuffer(pos + len);
  21862. limit = buffer.length;
  21863. }
  21864. for (var k = 0; k < len; ++k, ++pos) {
  21865. buffer[pos] = buffer[pos - dist];
  21866. }
  21867. }
  21868. };
  21869. return FlateStream;
  21870. })();
  21871. var PredictorStream = (function PredictorStreamClosure() {
  21872. function PredictorStream(str, maybeLength, params) {
  21873. var predictor = this.predictor = params.get('Predictor') || 1;
  21874. if (predictor <= 1) {
  21875. return str; // no prediction
  21876. }
  21877. if (predictor !== 2 && (predictor < 10 || predictor > 15)) {
  21878. error('Unsupported predictor: ' + predictor);
  21879. }
  21880. if (predictor === 2) {
  21881. this.readBlock = this.readBlockTiff;
  21882. } else {
  21883. this.readBlock = this.readBlockPng;
  21884. }
  21885. this.str = str;
  21886. this.dict = str.dict;
  21887. var colors = this.colors = params.get('Colors') || 1;
  21888. var bits = this.bits = params.get('BitsPerComponent') || 8;
  21889. var columns = this.columns = params.get('Columns') || 1;
  21890. this.pixBytes = (colors * bits + 7) >> 3;
  21891. this.rowBytes = (columns * colors * bits + 7) >> 3;
  21892. DecodeStream.call(this, maybeLength);
  21893. return this;
  21894. }
  21895. PredictorStream.prototype = Object.create(DecodeStream.prototype);
  21896. PredictorStream.prototype.readBlockTiff =
  21897. function predictorStreamReadBlockTiff() {
  21898. var rowBytes = this.rowBytes;
  21899. var bufferLength = this.bufferLength;
  21900. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  21901. var bits = this.bits;
  21902. var colors = this.colors;
  21903. var rawBytes = this.str.getBytes(rowBytes);
  21904. this.eof = !rawBytes.length;
  21905. if (this.eof) {
  21906. return;
  21907. }
  21908. var inbuf = 0, outbuf = 0;
  21909. var inbits = 0, outbits = 0;
  21910. var pos = bufferLength;
  21911. var i;
  21912. if (bits === 1) {
  21913. for (i = 0; i < rowBytes; ++i) {
  21914. var c = rawBytes[i];
  21915. inbuf = (inbuf << 8) | c;
  21916. // bitwise addition is exclusive or
  21917. // first shift inbuf and then add
  21918. buffer[pos++] = (c ^ (inbuf >> colors)) & 0xFF;
  21919. // truncate inbuf (assumes colors < 16)
  21920. inbuf &= 0xFFFF;
  21921. }
  21922. } else if (bits === 8) {
  21923. for (i = 0; i < colors; ++i) {
  21924. buffer[pos++] = rawBytes[i];
  21925. }
  21926. for (; i < rowBytes; ++i) {
  21927. buffer[pos] = buffer[pos - colors] + rawBytes[i];
  21928. pos++;
  21929. }
  21930. } else {
  21931. var compArray = new Uint8Array(colors + 1);
  21932. var bitMask = (1 << bits) - 1;
  21933. var j = 0, k = bufferLength;
  21934. var columns = this.columns;
  21935. for (i = 0; i < columns; ++i) {
  21936. for (var kk = 0; kk < colors; ++kk) {
  21937. if (inbits < bits) {
  21938. inbuf = (inbuf << 8) | (rawBytes[j++] & 0xFF);
  21939. inbits += 8;
  21940. }
  21941. compArray[kk] = (compArray[kk] +
  21942. (inbuf >> (inbits - bits))) & bitMask;
  21943. inbits -= bits;
  21944. outbuf = (outbuf << bits) | compArray[kk];
  21945. outbits += bits;
  21946. if (outbits >= 8) {
  21947. buffer[k++] = (outbuf >> (outbits - 8)) & 0xFF;
  21948. outbits -= 8;
  21949. }
  21950. }
  21951. }
  21952. if (outbits > 0) {
  21953. buffer[k++] = (outbuf << (8 - outbits)) +
  21954. (inbuf & ((1 << (8 - outbits)) - 1));
  21955. }
  21956. }
  21957. this.bufferLength += rowBytes;
  21958. };
  21959. PredictorStream.prototype.readBlockPng =
  21960. function predictorStreamReadBlockPng() {
  21961. var rowBytes = this.rowBytes;
  21962. var pixBytes = this.pixBytes;
  21963. var predictor = this.str.getByte();
  21964. var rawBytes = this.str.getBytes(rowBytes);
  21965. this.eof = !rawBytes.length;
  21966. if (this.eof) {
  21967. return;
  21968. }
  21969. var bufferLength = this.bufferLength;
  21970. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  21971. var prevRow = buffer.subarray(bufferLength - rowBytes, bufferLength);
  21972. if (prevRow.length === 0) {
  21973. prevRow = new Uint8Array(rowBytes);
  21974. }
  21975. var i, j = bufferLength, up, c;
  21976. switch (predictor) {
  21977. case 0:
  21978. for (i = 0; i < rowBytes; ++i) {
  21979. buffer[j++] = rawBytes[i];
  21980. }
  21981. break;
  21982. case 1:
  21983. for (i = 0; i < pixBytes; ++i) {
  21984. buffer[j++] = rawBytes[i];
  21985. }
  21986. for (; i < rowBytes; ++i) {
  21987. buffer[j] = (buffer[j - pixBytes] + rawBytes[i]) & 0xFF;
  21988. j++;
  21989. }
  21990. break;
  21991. case 2:
  21992. for (i = 0; i < rowBytes; ++i) {
  21993. buffer[j++] = (prevRow[i] + rawBytes[i]) & 0xFF;
  21994. }
  21995. break;
  21996. case 3:
  21997. for (i = 0; i < pixBytes; ++i) {
  21998. buffer[j++] = (prevRow[i] >> 1) + rawBytes[i];
  21999. }
  22000. for (; i < rowBytes; ++i) {
  22001. buffer[j] = (((prevRow[i] + buffer[j - pixBytes]) >> 1) +
  22002. rawBytes[i]) & 0xFF;
  22003. j++;
  22004. }
  22005. break;
  22006. case 4:
  22007. // we need to save the up left pixels values. the simplest way
  22008. // is to create a new buffer
  22009. for (i = 0; i < pixBytes; ++i) {
  22010. up = prevRow[i];
  22011. c = rawBytes[i];
  22012. buffer[j++] = up + c;
  22013. }
  22014. for (; i < rowBytes; ++i) {
  22015. up = prevRow[i];
  22016. var upLeft = prevRow[i - pixBytes];
  22017. var left = buffer[j - pixBytes];
  22018. var p = left + up - upLeft;
  22019. var pa = p - left;
  22020. if (pa < 0) {
  22021. pa = -pa;
  22022. }
  22023. var pb = p - up;
  22024. if (pb < 0) {
  22025. pb = -pb;
  22026. }
  22027. var pc = p - upLeft;
  22028. if (pc < 0) {
  22029. pc = -pc;
  22030. }
  22031. c = rawBytes[i];
  22032. if (pa <= pb && pa <= pc) {
  22033. buffer[j++] = left + c;
  22034. } else if (pb <= pc) {
  22035. buffer[j++] = up + c;
  22036. } else {
  22037. buffer[j++] = upLeft + c;
  22038. }
  22039. }
  22040. break;
  22041. default:
  22042. error('Unsupported predictor: ' + predictor);
  22043. }
  22044. this.bufferLength += rowBytes;
  22045. };
  22046. return PredictorStream;
  22047. })();
  22048. /**
  22049. * Depending on the type of JPEG a JpegStream is handled in different ways. For
  22050. * JPEG's that are supported natively such as DeviceGray and DeviceRGB the image
  22051. * data is stored and then loaded by the browser. For unsupported JPEG's we use
  22052. * a library to decode these images and the stream behaves like all the other
  22053. * DecodeStreams.
  22054. */
  22055. var JpegStream = (function JpegStreamClosure() {
  22056. function JpegStream(stream, maybeLength, dict, xref) {
  22057. // Some images may contain 'junk' before the SOI (start-of-image) marker.
  22058. // Note: this seems to mainly affect inline images.
  22059. var ch;
  22060. while ((ch = stream.getByte()) !== -1) {
  22061. if (ch === 0xFF) { // Find the first byte of the SOI marker (0xFFD8).
  22062. stream.skip(-1); // Reset the stream position to the SOI.
  22063. break;
  22064. }
  22065. }
  22066. this.stream = stream;
  22067. this.maybeLength = maybeLength;
  22068. this.dict = dict;
  22069. DecodeStream.call(this, maybeLength);
  22070. }
  22071. JpegStream.prototype = Object.create(DecodeStream.prototype);
  22072. Object.defineProperty(JpegStream.prototype, 'bytes', {
  22073. get: function JpegStream_bytes() {
  22074. // If this.maybeLength is null, we'll get the entire stream.
  22075. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  22076. },
  22077. configurable: true
  22078. });
  22079. JpegStream.prototype.ensureBuffer = function JpegStream_ensureBuffer(req) {
  22080. if (this.bufferLength) {
  22081. return;
  22082. }
  22083. try {
  22084. var jpegImage = new JpegImage();
  22085. // checking if values needs to be transformed before conversion
  22086. if (this.forceRGB && this.dict && isArray(this.dict.get('Decode'))) {
  22087. var decodeArr = this.dict.get('Decode');
  22088. var bitsPerComponent = this.dict.get('BitsPerComponent') || 8;
  22089. var decodeArrLength = decodeArr.length;
  22090. var transform = new Int32Array(decodeArrLength);
  22091. var transformNeeded = false;
  22092. var maxValue = (1 << bitsPerComponent) - 1;
  22093. for (var i = 0; i < decodeArrLength; i += 2) {
  22094. transform[i] = ((decodeArr[i + 1] - decodeArr[i]) * 256) | 0;
  22095. transform[i + 1] = (decodeArr[i] * maxValue) | 0;
  22096. if (transform[i] !== 256 || transform[i + 1] !== 0) {
  22097. transformNeeded = true;
  22098. }
  22099. }
  22100. if (transformNeeded) {
  22101. jpegImage.decodeTransform = transform;
  22102. }
  22103. }
  22104. jpegImage.parse(this.bytes);
  22105. var data = jpegImage.getData(this.drawWidth, this.drawHeight,
  22106. this.forceRGB);
  22107. this.buffer = data;
  22108. this.bufferLength = data.length;
  22109. this.eof = true;
  22110. } catch (e) {
  22111. error('JPEG error: ' + e);
  22112. }
  22113. };
  22114. JpegStream.prototype.getBytes = function JpegStream_getBytes(length) {
  22115. this.ensureBuffer();
  22116. return this.buffer;
  22117. };
  22118. JpegStream.prototype.getIR = function JpegStream_getIR() {
  22119. return PDFJS.createObjectURL(this.bytes, 'image/jpeg');
  22120. };
  22121. /**
  22122. * Checks if the image can be decoded and displayed by the browser without any
  22123. * further processing such as color space conversions.
  22124. */
  22125. JpegStream.prototype.isNativelySupported =
  22126. function JpegStream_isNativelySupported(xref, res) {
  22127. var cs = ColorSpace.parse(this.dict.get('ColorSpace', 'CS'), xref, res);
  22128. return (cs.name === 'DeviceGray' || cs.name === 'DeviceRGB') &&
  22129. cs.isDefaultDecode(this.dict.get('Decode', 'D'));
  22130. };
  22131. /**
  22132. * Checks if the image can be decoded by the browser.
  22133. */
  22134. JpegStream.prototype.isNativelyDecodable =
  22135. function JpegStream_isNativelyDecodable(xref, res) {
  22136. var cs = ColorSpace.parse(this.dict.get('ColorSpace', 'CS'), xref, res);
  22137. return (cs.numComps === 1 || cs.numComps === 3) &&
  22138. cs.isDefaultDecode(this.dict.get('Decode', 'D'));
  22139. };
  22140. return JpegStream;
  22141. })();
  22142. /**
  22143. * For JPEG 2000's we use a library to decode these images and
  22144. * the stream behaves like all the other DecodeStreams.
  22145. */
  22146. var JpxStream = (function JpxStreamClosure() {
  22147. function JpxStream(stream, maybeLength, dict) {
  22148. this.stream = stream;
  22149. this.maybeLength = maybeLength;
  22150. this.dict = dict;
  22151. DecodeStream.call(this, maybeLength);
  22152. }
  22153. JpxStream.prototype = Object.create(DecodeStream.prototype);
  22154. Object.defineProperty(JpxStream.prototype, 'bytes', {
  22155. get: function JpxStream_bytes() {
  22156. // If this.maybeLength is null, we'll get the entire stream.
  22157. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  22158. },
  22159. configurable: true
  22160. });
  22161. JpxStream.prototype.ensureBuffer = function JpxStream_ensureBuffer(req) {
  22162. if (this.bufferLength) {
  22163. return;
  22164. }
  22165. var jpxImage = new JpxImage();
  22166. jpxImage.parse(this.bytes);
  22167. var width = jpxImage.width;
  22168. var height = jpxImage.height;
  22169. var componentsCount = jpxImage.componentsCount;
  22170. var tileCount = jpxImage.tiles.length;
  22171. if (tileCount === 1) {
  22172. this.buffer = jpxImage.tiles[0].items;
  22173. } else {
  22174. var data = new Uint8Array(width * height * componentsCount);
  22175. for (var k = 0; k < tileCount; k++) {
  22176. var tileComponents = jpxImage.tiles[k];
  22177. var tileWidth = tileComponents.width;
  22178. var tileHeight = tileComponents.height;
  22179. var tileLeft = tileComponents.left;
  22180. var tileTop = tileComponents.top;
  22181. var src = tileComponents.items;
  22182. var srcPosition = 0;
  22183. var dataPosition = (width * tileTop + tileLeft) * componentsCount;
  22184. var imgRowSize = width * componentsCount;
  22185. var tileRowSize = tileWidth * componentsCount;
  22186. for (var j = 0; j < tileHeight; j++) {
  22187. var rowBytes = src.subarray(srcPosition, srcPosition + tileRowSize);
  22188. data.set(rowBytes, dataPosition);
  22189. srcPosition += tileRowSize;
  22190. dataPosition += imgRowSize;
  22191. }
  22192. }
  22193. this.buffer = data;
  22194. }
  22195. this.bufferLength = this.buffer.length;
  22196. this.eof = true;
  22197. };
  22198. return JpxStream;
  22199. })();
  22200. /**
  22201. * For JBIG2's we use a library to decode these images and
  22202. * the stream behaves like all the other DecodeStreams.
  22203. */
  22204. var Jbig2Stream = (function Jbig2StreamClosure() {
  22205. function Jbig2Stream(stream, maybeLength, dict) {
  22206. this.stream = stream;
  22207. this.maybeLength = maybeLength;
  22208. this.dict = dict;
  22209. DecodeStream.call(this, maybeLength);
  22210. }
  22211. Jbig2Stream.prototype = Object.create(DecodeStream.prototype);
  22212. Object.defineProperty(Jbig2Stream.prototype, 'bytes', {
  22213. get: function Jbig2Stream_bytes() {
  22214. // If this.maybeLength is null, we'll get the entire stream.
  22215. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  22216. },
  22217. configurable: true
  22218. });
  22219. Jbig2Stream.prototype.ensureBuffer = function Jbig2Stream_ensureBuffer(req) {
  22220. if (this.bufferLength) {
  22221. return;
  22222. }
  22223. var jbig2Image = new Jbig2Image();
  22224. var chunks = [], xref = this.dict.xref;
  22225. var decodeParams = xref.fetchIfRef(this.dict.get('DecodeParms'));
  22226. // According to the PDF specification, DecodeParms can be either
  22227. // a dictionary, or an array whose elements are dictionaries.
  22228. if (isArray(decodeParams)) {
  22229. if (decodeParams.length > 1) {
  22230. warn('JBIG2 - \'DecodeParms\' array with multiple elements ' +
  22231. 'not supported.');
  22232. }
  22233. decodeParams = xref.fetchIfRef(decodeParams[0]);
  22234. }
  22235. if (decodeParams && decodeParams.has('JBIG2Globals')) {
  22236. var globalsStream = decodeParams.get('JBIG2Globals');
  22237. var globals = globalsStream.getBytes();
  22238. chunks.push({data: globals, start: 0, end: globals.length});
  22239. }
  22240. chunks.push({data: this.bytes, start: 0, end: this.bytes.length});
  22241. var data = jbig2Image.parseChunks(chunks);
  22242. var dataLength = data.length;
  22243. // JBIG2 had black as 1 and white as 0, inverting the colors
  22244. for (var i = 0; i < dataLength; i++) {
  22245. data[i] ^= 0xFF;
  22246. }
  22247. this.buffer = data;
  22248. this.bufferLength = dataLength;
  22249. this.eof = true;
  22250. };
  22251. return Jbig2Stream;
  22252. })();
  22253. var DecryptStream = (function DecryptStreamClosure() {
  22254. function DecryptStream(str, maybeLength, decrypt) {
  22255. this.str = str;
  22256. this.dict = str.dict;
  22257. this.decrypt = decrypt;
  22258. this.nextChunk = null;
  22259. this.initialized = false;
  22260. DecodeStream.call(this, maybeLength);
  22261. }
  22262. var chunkSize = 512;
  22263. DecryptStream.prototype = Object.create(DecodeStream.prototype);
  22264. DecryptStream.prototype.readBlock = function DecryptStream_readBlock() {
  22265. var chunk;
  22266. if (this.initialized) {
  22267. chunk = this.nextChunk;
  22268. } else {
  22269. chunk = this.str.getBytes(chunkSize);
  22270. this.initialized = true;
  22271. }
  22272. if (!chunk || chunk.length === 0) {
  22273. this.eof = true;
  22274. return;
  22275. }
  22276. this.nextChunk = this.str.getBytes(chunkSize);
  22277. var hasMoreData = this.nextChunk && this.nextChunk.length > 0;
  22278. var decrypt = this.decrypt;
  22279. chunk = decrypt(chunk, !hasMoreData);
  22280. var bufferLength = this.bufferLength;
  22281. var i, n = chunk.length;
  22282. var buffer = this.ensureBuffer(bufferLength + n);
  22283. for (i = 0; i < n; i++) {
  22284. buffer[bufferLength++] = chunk[i];
  22285. }
  22286. this.bufferLength = bufferLength;
  22287. };
  22288. return DecryptStream;
  22289. })();
  22290. var Ascii85Stream = (function Ascii85StreamClosure() {
  22291. function Ascii85Stream(str, maybeLength) {
  22292. this.str = str;
  22293. this.dict = str.dict;
  22294. this.input = new Uint8Array(5);
  22295. // Most streams increase in size when decoded, but Ascii85 streams
  22296. // typically shrink by ~20%.
  22297. if (maybeLength) {
  22298. maybeLength = 0.8 * maybeLength;
  22299. }
  22300. DecodeStream.call(this, maybeLength);
  22301. }
  22302. Ascii85Stream.prototype = Object.create(DecodeStream.prototype);
  22303. Ascii85Stream.prototype.readBlock = function Ascii85Stream_readBlock() {
  22304. var TILDA_CHAR = 0x7E; // '~'
  22305. var Z_LOWER_CHAR = 0x7A; // 'z'
  22306. var EOF = -1;
  22307. var str = this.str;
  22308. var c = str.getByte();
  22309. while (Lexer.isSpace(c)) {
  22310. c = str.getByte();
  22311. }
  22312. if (c === EOF || c === TILDA_CHAR) {
  22313. this.eof = true;
  22314. return;
  22315. }
  22316. var bufferLength = this.bufferLength, buffer;
  22317. var i;
  22318. // special code for z
  22319. if (c === Z_LOWER_CHAR) {
  22320. buffer = this.ensureBuffer(bufferLength + 4);
  22321. for (i = 0; i < 4; ++i) {
  22322. buffer[bufferLength + i] = 0;
  22323. }
  22324. this.bufferLength += 4;
  22325. } else {
  22326. var input = this.input;
  22327. input[0] = c;
  22328. for (i = 1; i < 5; ++i) {
  22329. c = str.getByte();
  22330. while (Lexer.isSpace(c)) {
  22331. c = str.getByte();
  22332. }
  22333. input[i] = c;
  22334. if (c === EOF || c === TILDA_CHAR) {
  22335. break;
  22336. }
  22337. }
  22338. buffer = this.ensureBuffer(bufferLength + i - 1);
  22339. this.bufferLength += i - 1;
  22340. // partial ending;
  22341. if (i < 5) {
  22342. for (; i < 5; ++i) {
  22343. input[i] = 0x21 + 84;
  22344. }
  22345. this.eof = true;
  22346. }
  22347. var t = 0;
  22348. for (i = 0; i < 5; ++i) {
  22349. t = t * 85 + (input[i] - 0x21);
  22350. }
  22351. for (i = 3; i >= 0; --i) {
  22352. buffer[bufferLength + i] = t & 0xFF;
  22353. t >>= 8;
  22354. }
  22355. }
  22356. };
  22357. return Ascii85Stream;
  22358. })();
  22359. var AsciiHexStream = (function AsciiHexStreamClosure() {
  22360. function AsciiHexStream(str, maybeLength) {
  22361. this.str = str;
  22362. this.dict = str.dict;
  22363. this.firstDigit = -1;
  22364. // Most streams increase in size when decoded, but AsciiHex streams shrink
  22365. // by 50%.
  22366. if (maybeLength) {
  22367. maybeLength = 0.5 * maybeLength;
  22368. }
  22369. DecodeStream.call(this, maybeLength);
  22370. }
  22371. AsciiHexStream.prototype = Object.create(DecodeStream.prototype);
  22372. AsciiHexStream.prototype.readBlock = function AsciiHexStream_readBlock() {
  22373. var UPSTREAM_BLOCK_SIZE = 8000;
  22374. var bytes = this.str.getBytes(UPSTREAM_BLOCK_SIZE);
  22375. if (!bytes.length) {
  22376. this.eof = true;
  22377. return;
  22378. }
  22379. var maxDecodeLength = (bytes.length + 1) >> 1;
  22380. var buffer = this.ensureBuffer(this.bufferLength + maxDecodeLength);
  22381. var bufferLength = this.bufferLength;
  22382. var firstDigit = this.firstDigit;
  22383. for (var i = 0, ii = bytes.length; i < ii; i++) {
  22384. var ch = bytes[i], digit;
  22385. if (ch >= 0x30 && ch <= 0x39) { // '0'-'9'
  22386. digit = ch & 0x0F;
  22387. } else if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
  22388. // 'A'-'Z', 'a'-'z'
  22389. digit = (ch & 0x0F) + 9;
  22390. } else if (ch === 0x3E) { // '>'
  22391. this.eof = true;
  22392. break;
  22393. } else { // probably whitespace
  22394. continue; // ignoring
  22395. }
  22396. if (firstDigit < 0) {
  22397. firstDigit = digit;
  22398. } else {
  22399. buffer[bufferLength++] = (firstDigit << 4) | digit;
  22400. firstDigit = -1;
  22401. }
  22402. }
  22403. if (firstDigit >= 0 && this.eof) {
  22404. // incomplete byte
  22405. buffer[bufferLength++] = (firstDigit << 4);
  22406. firstDigit = -1;
  22407. }
  22408. this.firstDigit = firstDigit;
  22409. this.bufferLength = bufferLength;
  22410. };
  22411. return AsciiHexStream;
  22412. })();
  22413. var RunLengthStream = (function RunLengthStreamClosure() {
  22414. function RunLengthStream(str, maybeLength) {
  22415. this.str = str;
  22416. this.dict = str.dict;
  22417. DecodeStream.call(this, maybeLength);
  22418. }
  22419. RunLengthStream.prototype = Object.create(DecodeStream.prototype);
  22420. RunLengthStream.prototype.readBlock = function RunLengthStream_readBlock() {
  22421. // The repeatHeader has following format. The first byte defines type of run
  22422. // and amount of bytes to repeat/copy: n = 0 through 127 - copy next n bytes
  22423. // (in addition to the second byte from the header), n = 129 through 255 -
  22424. // duplicate the second byte from the header (257 - n) times, n = 128 - end.
  22425. var repeatHeader = this.str.getBytes(2);
  22426. if (!repeatHeader || repeatHeader.length < 2 || repeatHeader[0] === 128) {
  22427. this.eof = true;
  22428. return;
  22429. }
  22430. var buffer;
  22431. var bufferLength = this.bufferLength;
  22432. var n = repeatHeader[0];
  22433. if (n < 128) {
  22434. // copy n bytes
  22435. buffer = this.ensureBuffer(bufferLength + n + 1);
  22436. buffer[bufferLength++] = repeatHeader[1];
  22437. if (n > 0) {
  22438. var source = this.str.getBytes(n);
  22439. buffer.set(source, bufferLength);
  22440. bufferLength += n;
  22441. }
  22442. } else {
  22443. n = 257 - n;
  22444. var b = repeatHeader[1];
  22445. buffer = this.ensureBuffer(bufferLength + n + 1);
  22446. for (var i = 0; i < n; i++) {
  22447. buffer[bufferLength++] = b;
  22448. }
  22449. }
  22450. this.bufferLength = bufferLength;
  22451. };
  22452. return RunLengthStream;
  22453. })();
  22454. var CCITTFaxStream = (function CCITTFaxStreamClosure() {
  22455. var ccittEOL = -2;
  22456. var twoDimPass = 0;
  22457. var twoDimHoriz = 1;
  22458. var twoDimVert0 = 2;
  22459. var twoDimVertR1 = 3;
  22460. var twoDimVertL1 = 4;
  22461. var twoDimVertR2 = 5;
  22462. var twoDimVertL2 = 6;
  22463. var twoDimVertR3 = 7;
  22464. var twoDimVertL3 = 8;
  22465. var twoDimTable = [
  22466. [-1, -1], [-1, -1], // 000000x
  22467. [7, twoDimVertL3], // 0000010
  22468. [7, twoDimVertR3], // 0000011
  22469. [6, twoDimVertL2], [6, twoDimVertL2], // 000010x
  22470. [6, twoDimVertR2], [6, twoDimVertR2], // 000011x
  22471. [4, twoDimPass], [4, twoDimPass], // 0001xxx
  22472. [4, twoDimPass], [4, twoDimPass],
  22473. [4, twoDimPass], [4, twoDimPass],
  22474. [4, twoDimPass], [4, twoDimPass],
  22475. [3, twoDimHoriz], [3, twoDimHoriz], // 001xxxx
  22476. [3, twoDimHoriz], [3, twoDimHoriz],
  22477. [3, twoDimHoriz], [3, twoDimHoriz],
  22478. [3, twoDimHoriz], [3, twoDimHoriz],
  22479. [3, twoDimHoriz], [3, twoDimHoriz],
  22480. [3, twoDimHoriz], [3, twoDimHoriz],
  22481. [3, twoDimHoriz], [3, twoDimHoriz],
  22482. [3, twoDimHoriz], [3, twoDimHoriz],
  22483. [3, twoDimVertL1], [3, twoDimVertL1], // 010xxxx
  22484. [3, twoDimVertL1], [3, twoDimVertL1],
  22485. [3, twoDimVertL1], [3, twoDimVertL1],
  22486. [3, twoDimVertL1], [3, twoDimVertL1],
  22487. [3, twoDimVertL1], [3, twoDimVertL1],
  22488. [3, twoDimVertL1], [3, twoDimVertL1],
  22489. [3, twoDimVertL1], [3, twoDimVertL1],
  22490. [3, twoDimVertL1], [3, twoDimVertL1],
  22491. [3, twoDimVertR1], [3, twoDimVertR1], // 011xxxx
  22492. [3, twoDimVertR1], [3, twoDimVertR1],
  22493. [3, twoDimVertR1], [3, twoDimVertR1],
  22494. [3, twoDimVertR1], [3, twoDimVertR1],
  22495. [3, twoDimVertR1], [3, twoDimVertR1],
  22496. [3, twoDimVertR1], [3, twoDimVertR1],
  22497. [3, twoDimVertR1], [3, twoDimVertR1],
  22498. [3, twoDimVertR1], [3, twoDimVertR1],
  22499. [1, twoDimVert0], [1, twoDimVert0], // 1xxxxxx
  22500. [1, twoDimVert0], [1, twoDimVert0],
  22501. [1, twoDimVert0], [1, twoDimVert0],
  22502. [1, twoDimVert0], [1, twoDimVert0],
  22503. [1, twoDimVert0], [1, twoDimVert0],
  22504. [1, twoDimVert0], [1, twoDimVert0],
  22505. [1, twoDimVert0], [1, twoDimVert0],
  22506. [1, twoDimVert0], [1, twoDimVert0],
  22507. [1, twoDimVert0], [1, twoDimVert0],
  22508. [1, twoDimVert0], [1, twoDimVert0],
  22509. [1, twoDimVert0], [1, twoDimVert0],
  22510. [1, twoDimVert0], [1, twoDimVert0],
  22511. [1, twoDimVert0], [1, twoDimVert0],
  22512. [1, twoDimVert0], [1, twoDimVert0],
  22513. [1, twoDimVert0], [1, twoDimVert0],
  22514. [1, twoDimVert0], [1, twoDimVert0],
  22515. [1, twoDimVert0], [1, twoDimVert0],
  22516. [1, twoDimVert0], [1, twoDimVert0],
  22517. [1, twoDimVert0], [1, twoDimVert0],
  22518. [1, twoDimVert0], [1, twoDimVert0],
  22519. [1, twoDimVert0], [1, twoDimVert0],
  22520. [1, twoDimVert0], [1, twoDimVert0],
  22521. [1, twoDimVert0], [1, twoDimVert0],
  22522. [1, twoDimVert0], [1, twoDimVert0],
  22523. [1, twoDimVert0], [1, twoDimVert0],
  22524. [1, twoDimVert0], [1, twoDimVert0],
  22525. [1, twoDimVert0], [1, twoDimVert0],
  22526. [1, twoDimVert0], [1, twoDimVert0],
  22527. [1, twoDimVert0], [1, twoDimVert0],
  22528. [1, twoDimVert0], [1, twoDimVert0],
  22529. [1, twoDimVert0], [1, twoDimVert0],
  22530. [1, twoDimVert0], [1, twoDimVert0]
  22531. ];
  22532. var whiteTable1 = [
  22533. [-1, -1], // 00000
  22534. [12, ccittEOL], // 00001
  22535. [-1, -1], [-1, -1], // 0001x
  22536. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 001xx
  22537. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 010xx
  22538. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 011xx
  22539. [11, 1792], [11, 1792], // 1000x
  22540. [12, 1984], // 10010
  22541. [12, 2048], // 10011
  22542. [12, 2112], // 10100
  22543. [12, 2176], // 10101
  22544. [12, 2240], // 10110
  22545. [12, 2304], // 10111
  22546. [11, 1856], [11, 1856], // 1100x
  22547. [11, 1920], [11, 1920], // 1101x
  22548. [12, 2368], // 11100
  22549. [12, 2432], // 11101
  22550. [12, 2496], // 11110
  22551. [12, 2560] // 11111
  22552. ];
  22553. var whiteTable2 = [
  22554. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000000xx
  22555. [8, 29], [8, 29], // 00000010x
  22556. [8, 30], [8, 30], // 00000011x
  22557. [8, 45], [8, 45], // 00000100x
  22558. [8, 46], [8, 46], // 00000101x
  22559. [7, 22], [7, 22], [7, 22], [7, 22], // 0000011xx
  22560. [7, 23], [7, 23], [7, 23], [7, 23], // 0000100xx
  22561. [8, 47], [8, 47], // 00001010x
  22562. [8, 48], [8, 48], // 00001011x
  22563. [6, 13], [6, 13], [6, 13], [6, 13], // 000011xxx
  22564. [6, 13], [6, 13], [6, 13], [6, 13],
  22565. [7, 20], [7, 20], [7, 20], [7, 20], // 0001000xx
  22566. [8, 33], [8, 33], // 00010010x
  22567. [8, 34], [8, 34], // 00010011x
  22568. [8, 35], [8, 35], // 00010100x
  22569. [8, 36], [8, 36], // 00010101x
  22570. [8, 37], [8, 37], // 00010110x
  22571. [8, 38], [8, 38], // 00010111x
  22572. [7, 19], [7, 19], [7, 19], [7, 19], // 0001100xx
  22573. [8, 31], [8, 31], // 00011010x
  22574. [8, 32], [8, 32], // 00011011x
  22575. [6, 1], [6, 1], [6, 1], [6, 1], // 000111xxx
  22576. [6, 1], [6, 1], [6, 1], [6, 1],
  22577. [6, 12], [6, 12], [6, 12], [6, 12], // 001000xxx
  22578. [6, 12], [6, 12], [6, 12], [6, 12],
  22579. [8, 53], [8, 53], // 00100100x
  22580. [8, 54], [8, 54], // 00100101x
  22581. [7, 26], [7, 26], [7, 26], [7, 26], // 0010011xx
  22582. [8, 39], [8, 39], // 00101000x
  22583. [8, 40], [8, 40], // 00101001x
  22584. [8, 41], [8, 41], // 00101010x
  22585. [8, 42], [8, 42], // 00101011x
  22586. [8, 43], [8, 43], // 00101100x
  22587. [8, 44], [8, 44], // 00101101x
  22588. [7, 21], [7, 21], [7, 21], [7, 21], // 0010111xx
  22589. [7, 28], [7, 28], [7, 28], [7, 28], // 0011000xx
  22590. [8, 61], [8, 61], // 00110010x
  22591. [8, 62], [8, 62], // 00110011x
  22592. [8, 63], [8, 63], // 00110100x
  22593. [8, 0], [8, 0], // 00110101x
  22594. [8, 320], [8, 320], // 00110110x
  22595. [8, 384], [8, 384], // 00110111x
  22596. [5, 10], [5, 10], [5, 10], [5, 10], // 00111xxxx
  22597. [5, 10], [5, 10], [5, 10], [5, 10],
  22598. [5, 10], [5, 10], [5, 10], [5, 10],
  22599. [5, 10], [5, 10], [5, 10], [5, 10],
  22600. [5, 11], [5, 11], [5, 11], [5, 11], // 01000xxxx
  22601. [5, 11], [5, 11], [5, 11], [5, 11],
  22602. [5, 11], [5, 11], [5, 11], [5, 11],
  22603. [5, 11], [5, 11], [5, 11], [5, 11],
  22604. [7, 27], [7, 27], [7, 27], [7, 27], // 0100100xx
  22605. [8, 59], [8, 59], // 01001010x
  22606. [8, 60], [8, 60], // 01001011x
  22607. [9, 1472], // 010011000
  22608. [9, 1536], // 010011001
  22609. [9, 1600], // 010011010
  22610. [9, 1728], // 010011011
  22611. [7, 18], [7, 18], [7, 18], [7, 18], // 0100111xx
  22612. [7, 24], [7, 24], [7, 24], [7, 24], // 0101000xx
  22613. [8, 49], [8, 49], // 01010010x
  22614. [8, 50], [8, 50], // 01010011x
  22615. [8, 51], [8, 51], // 01010100x
  22616. [8, 52], [8, 52], // 01010101x
  22617. [7, 25], [7, 25], [7, 25], [7, 25], // 0101011xx
  22618. [8, 55], [8, 55], // 01011000x
  22619. [8, 56], [8, 56], // 01011001x
  22620. [8, 57], [8, 57], // 01011010x
  22621. [8, 58], [8, 58], // 01011011x
  22622. [6, 192], [6, 192], [6, 192], [6, 192], // 010111xxx
  22623. [6, 192], [6, 192], [6, 192], [6, 192],
  22624. [6, 1664], [6, 1664], [6, 1664], [6, 1664], // 011000xxx
  22625. [6, 1664], [6, 1664], [6, 1664], [6, 1664],
  22626. [8, 448], [8, 448], // 01100100x
  22627. [8, 512], [8, 512], // 01100101x
  22628. [9, 704], // 011001100
  22629. [9, 768], // 011001101
  22630. [8, 640], [8, 640], // 01100111x
  22631. [8, 576], [8, 576], // 01101000x
  22632. [9, 832], // 011010010
  22633. [9, 896], // 011010011
  22634. [9, 960], // 011010100
  22635. [9, 1024], // 011010101
  22636. [9, 1088], // 011010110
  22637. [9, 1152], // 011010111
  22638. [9, 1216], // 011011000
  22639. [9, 1280], // 011011001
  22640. [9, 1344], // 011011010
  22641. [9, 1408], // 011011011
  22642. [7, 256], [7, 256], [7, 256], [7, 256], // 0110111xx
  22643. [4, 2], [4, 2], [4, 2], [4, 2], // 0111xxxxx
  22644. [4, 2], [4, 2], [4, 2], [4, 2],
  22645. [4, 2], [4, 2], [4, 2], [4, 2],
  22646. [4, 2], [4, 2], [4, 2], [4, 2],
  22647. [4, 2], [4, 2], [4, 2], [4, 2],
  22648. [4, 2], [4, 2], [4, 2], [4, 2],
  22649. [4, 2], [4, 2], [4, 2], [4, 2],
  22650. [4, 2], [4, 2], [4, 2], [4, 2],
  22651. [4, 3], [4, 3], [4, 3], [4, 3], // 1000xxxxx
  22652. [4, 3], [4, 3], [4, 3], [4, 3],
  22653. [4, 3], [4, 3], [4, 3], [4, 3],
  22654. [4, 3], [4, 3], [4, 3], [4, 3],
  22655. [4, 3], [4, 3], [4, 3], [4, 3],
  22656. [4, 3], [4, 3], [4, 3], [4, 3],
  22657. [4, 3], [4, 3], [4, 3], [4, 3],
  22658. [4, 3], [4, 3], [4, 3], [4, 3],
  22659. [5, 128], [5, 128], [5, 128], [5, 128], // 10010xxxx
  22660. [5, 128], [5, 128], [5, 128], [5, 128],
  22661. [5, 128], [5, 128], [5, 128], [5, 128],
  22662. [5, 128], [5, 128], [5, 128], [5, 128],
  22663. [5, 8], [5, 8], [5, 8], [5, 8], // 10011xxxx
  22664. [5, 8], [5, 8], [5, 8], [5, 8],
  22665. [5, 8], [5, 8], [5, 8], [5, 8],
  22666. [5, 8], [5, 8], [5, 8], [5, 8],
  22667. [5, 9], [5, 9], [5, 9], [5, 9], // 10100xxxx
  22668. [5, 9], [5, 9], [5, 9], [5, 9],
  22669. [5, 9], [5, 9], [5, 9], [5, 9],
  22670. [5, 9], [5, 9], [5, 9], [5, 9],
  22671. [6, 16], [6, 16], [6, 16], [6, 16], // 101010xxx
  22672. [6, 16], [6, 16], [6, 16], [6, 16],
  22673. [6, 17], [6, 17], [6, 17], [6, 17], // 101011xxx
  22674. [6, 17], [6, 17], [6, 17], [6, 17],
  22675. [4, 4], [4, 4], [4, 4], [4, 4], // 1011xxxxx
  22676. [4, 4], [4, 4], [4, 4], [4, 4],
  22677. [4, 4], [4, 4], [4, 4], [4, 4],
  22678. [4, 4], [4, 4], [4, 4], [4, 4],
  22679. [4, 4], [4, 4], [4, 4], [4, 4],
  22680. [4, 4], [4, 4], [4, 4], [4, 4],
  22681. [4, 4], [4, 4], [4, 4], [4, 4],
  22682. [4, 4], [4, 4], [4, 4], [4, 4],
  22683. [4, 5], [4, 5], [4, 5], [4, 5], // 1100xxxxx
  22684. [4, 5], [4, 5], [4, 5], [4, 5],
  22685. [4, 5], [4, 5], [4, 5], [4, 5],
  22686. [4, 5], [4, 5], [4, 5], [4, 5],
  22687. [4, 5], [4, 5], [4, 5], [4, 5],
  22688. [4, 5], [4, 5], [4, 5], [4, 5],
  22689. [4, 5], [4, 5], [4, 5], [4, 5],
  22690. [4, 5], [4, 5], [4, 5], [4, 5],
  22691. [6, 14], [6, 14], [6, 14], [6, 14], // 110100xxx
  22692. [6, 14], [6, 14], [6, 14], [6, 14],
  22693. [6, 15], [6, 15], [6, 15], [6, 15], // 110101xxx
  22694. [6, 15], [6, 15], [6, 15], [6, 15],
  22695. [5, 64], [5, 64], [5, 64], [5, 64], // 11011xxxx
  22696. [5, 64], [5, 64], [5, 64], [5, 64],
  22697. [5, 64], [5, 64], [5, 64], [5, 64],
  22698. [5, 64], [5, 64], [5, 64], [5, 64],
  22699. [4, 6], [4, 6], [4, 6], [4, 6], // 1110xxxxx
  22700. [4, 6], [4, 6], [4, 6], [4, 6],
  22701. [4, 6], [4, 6], [4, 6], [4, 6],
  22702. [4, 6], [4, 6], [4, 6], [4, 6],
  22703. [4, 6], [4, 6], [4, 6], [4, 6],
  22704. [4, 6], [4, 6], [4, 6], [4, 6],
  22705. [4, 6], [4, 6], [4, 6], [4, 6],
  22706. [4, 6], [4, 6], [4, 6], [4, 6],
  22707. [4, 7], [4, 7], [4, 7], [4, 7], // 1111xxxxx
  22708. [4, 7], [4, 7], [4, 7], [4, 7],
  22709. [4, 7], [4, 7], [4, 7], [4, 7],
  22710. [4, 7], [4, 7], [4, 7], [4, 7],
  22711. [4, 7], [4, 7], [4, 7], [4, 7],
  22712. [4, 7], [4, 7], [4, 7], [4, 7],
  22713. [4, 7], [4, 7], [4, 7], [4, 7],
  22714. [4, 7], [4, 7], [4, 7], [4, 7]
  22715. ];
  22716. var blackTable1 = [
  22717. [-1, -1], [-1, -1], // 000000000000x
  22718. [12, ccittEOL], [12, ccittEOL], // 000000000001x
  22719. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000001xx
  22720. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000010xx
  22721. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000011xx
  22722. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000100xx
  22723. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000101xx
  22724. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000110xx
  22725. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000111xx
  22726. [11, 1792], [11, 1792], [11, 1792], [11, 1792], // 00000001000xx
  22727. [12, 1984], [12, 1984], // 000000010010x
  22728. [12, 2048], [12, 2048], // 000000010011x
  22729. [12, 2112], [12, 2112], // 000000010100x
  22730. [12, 2176], [12, 2176], // 000000010101x
  22731. [12, 2240], [12, 2240], // 000000010110x
  22732. [12, 2304], [12, 2304], // 000000010111x
  22733. [11, 1856], [11, 1856], [11, 1856], [11, 1856], // 00000001100xx
  22734. [11, 1920], [11, 1920], [11, 1920], [11, 1920], // 00000001101xx
  22735. [12, 2368], [12, 2368], // 000000011100x
  22736. [12, 2432], [12, 2432], // 000000011101x
  22737. [12, 2496], [12, 2496], // 000000011110x
  22738. [12, 2560], [12, 2560], // 000000011111x
  22739. [10, 18], [10, 18], [10, 18], [10, 18], // 0000001000xxx
  22740. [10, 18], [10, 18], [10, 18], [10, 18],
  22741. [12, 52], [12, 52], // 000000100100x
  22742. [13, 640], // 0000001001010
  22743. [13, 704], // 0000001001011
  22744. [13, 768], // 0000001001100
  22745. [13, 832], // 0000001001101
  22746. [12, 55], [12, 55], // 000000100111x
  22747. [12, 56], [12, 56], // 000000101000x
  22748. [13, 1280], // 0000001010010
  22749. [13, 1344], // 0000001010011
  22750. [13, 1408], // 0000001010100
  22751. [13, 1472], // 0000001010101
  22752. [12, 59], [12, 59], // 000000101011x
  22753. [12, 60], [12, 60], // 000000101100x
  22754. [13, 1536], // 0000001011010
  22755. [13, 1600], // 0000001011011
  22756. [11, 24], [11, 24], [11, 24], [11, 24], // 00000010111xx
  22757. [11, 25], [11, 25], [11, 25], [11, 25], // 00000011000xx
  22758. [13, 1664], // 0000001100100
  22759. [13, 1728], // 0000001100101
  22760. [12, 320], [12, 320], // 000000110011x
  22761. [12, 384], [12, 384], // 000000110100x
  22762. [12, 448], [12, 448], // 000000110101x
  22763. [13, 512], // 0000001101100
  22764. [13, 576], // 0000001101101
  22765. [12, 53], [12, 53], // 000000110111x
  22766. [12, 54], [12, 54], // 000000111000x
  22767. [13, 896], // 0000001110010
  22768. [13, 960], // 0000001110011
  22769. [13, 1024], // 0000001110100
  22770. [13, 1088], // 0000001110101
  22771. [13, 1152], // 0000001110110
  22772. [13, 1216], // 0000001110111
  22773. [10, 64], [10, 64], [10, 64], [10, 64], // 0000001111xxx
  22774. [10, 64], [10, 64], [10, 64], [10, 64]
  22775. ];
  22776. var blackTable2 = [
  22777. [8, 13], [8, 13], [8, 13], [8, 13], // 00000100xxxx
  22778. [8, 13], [8, 13], [8, 13], [8, 13],
  22779. [8, 13], [8, 13], [8, 13], [8, 13],
  22780. [8, 13], [8, 13], [8, 13], [8, 13],
  22781. [11, 23], [11, 23], // 00000101000x
  22782. [12, 50], // 000001010010
  22783. [12, 51], // 000001010011
  22784. [12, 44], // 000001010100
  22785. [12, 45], // 000001010101
  22786. [12, 46], // 000001010110
  22787. [12, 47], // 000001010111
  22788. [12, 57], // 000001011000
  22789. [12, 58], // 000001011001
  22790. [12, 61], // 000001011010
  22791. [12, 256], // 000001011011
  22792. [10, 16], [10, 16], [10, 16], [10, 16], // 0000010111xx
  22793. [10, 17], [10, 17], [10, 17], [10, 17], // 0000011000xx
  22794. [12, 48], // 000001100100
  22795. [12, 49], // 000001100101
  22796. [12, 62], // 000001100110
  22797. [12, 63], // 000001100111
  22798. [12, 30], // 000001101000
  22799. [12, 31], // 000001101001
  22800. [12, 32], // 000001101010
  22801. [12, 33], // 000001101011
  22802. [12, 40], // 000001101100
  22803. [12, 41], // 000001101101
  22804. [11, 22], [11, 22], // 00000110111x
  22805. [8, 14], [8, 14], [8, 14], [8, 14], // 00000111xxxx
  22806. [8, 14], [8, 14], [8, 14], [8, 14],
  22807. [8, 14], [8, 14], [8, 14], [8, 14],
  22808. [8, 14], [8, 14], [8, 14], [8, 14],
  22809. [7, 10], [7, 10], [7, 10], [7, 10], // 0000100xxxxx
  22810. [7, 10], [7, 10], [7, 10], [7, 10],
  22811. [7, 10], [7, 10], [7, 10], [7, 10],
  22812. [7, 10], [7, 10], [7, 10], [7, 10],
  22813. [7, 10], [7, 10], [7, 10], [7, 10],
  22814. [7, 10], [7, 10], [7, 10], [7, 10],
  22815. [7, 10], [7, 10], [7, 10], [7, 10],
  22816. [7, 10], [7, 10], [7, 10], [7, 10],
  22817. [7, 11], [7, 11], [7, 11], [7, 11], // 0000101xxxxx
  22818. [7, 11], [7, 11], [7, 11], [7, 11],
  22819. [7, 11], [7, 11], [7, 11], [7, 11],
  22820. [7, 11], [7, 11], [7, 11], [7, 11],
  22821. [7, 11], [7, 11], [7, 11], [7, 11],
  22822. [7, 11], [7, 11], [7, 11], [7, 11],
  22823. [7, 11], [7, 11], [7, 11], [7, 11],
  22824. [7, 11], [7, 11], [7, 11], [7, 11],
  22825. [9, 15], [9, 15], [9, 15], [9, 15], // 000011000xxx
  22826. [9, 15], [9, 15], [9, 15], [9, 15],
  22827. [12, 128], // 000011001000
  22828. [12, 192], // 000011001001
  22829. [12, 26], // 000011001010
  22830. [12, 27], // 000011001011
  22831. [12, 28], // 000011001100
  22832. [12, 29], // 000011001101
  22833. [11, 19], [11, 19], // 00001100111x
  22834. [11, 20], [11, 20], // 00001101000x
  22835. [12, 34], // 000011010010
  22836. [12, 35], // 000011010011
  22837. [12, 36], // 000011010100
  22838. [12, 37], // 000011010101
  22839. [12, 38], // 000011010110
  22840. [12, 39], // 000011010111
  22841. [11, 21], [11, 21], // 00001101100x
  22842. [12, 42], // 000011011010
  22843. [12, 43], // 000011011011
  22844. [10, 0], [10, 0], [10, 0], [10, 0], // 0000110111xx
  22845. [7, 12], [7, 12], [7, 12], [7, 12], // 0000111xxxxx
  22846. [7, 12], [7, 12], [7, 12], [7, 12],
  22847. [7, 12], [7, 12], [7, 12], [7, 12],
  22848. [7, 12], [7, 12], [7, 12], [7, 12],
  22849. [7, 12], [7, 12], [7, 12], [7, 12],
  22850. [7, 12], [7, 12], [7, 12], [7, 12],
  22851. [7, 12], [7, 12], [7, 12], [7, 12],
  22852. [7, 12], [7, 12], [7, 12], [7, 12]
  22853. ];
  22854. var blackTable3 = [
  22855. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000xx
  22856. [6, 9], // 000100
  22857. [6, 8], // 000101
  22858. [5, 7], [5, 7], // 00011x
  22859. [4, 6], [4, 6], [4, 6], [4, 6], // 0010xx
  22860. [4, 5], [4, 5], [4, 5], [4, 5], // 0011xx
  22861. [3, 1], [3, 1], [3, 1], [3, 1], // 010xxx
  22862. [3, 1], [3, 1], [3, 1], [3, 1],
  22863. [3, 4], [3, 4], [3, 4], [3, 4], // 011xxx
  22864. [3, 4], [3, 4], [3, 4], [3, 4],
  22865. [2, 3], [2, 3], [2, 3], [2, 3], // 10xxxx
  22866. [2, 3], [2, 3], [2, 3], [2, 3],
  22867. [2, 3], [2, 3], [2, 3], [2, 3],
  22868. [2, 3], [2, 3], [2, 3], [2, 3],
  22869. [2, 2], [2, 2], [2, 2], [2, 2], // 11xxxx
  22870. [2, 2], [2, 2], [2, 2], [2, 2],
  22871. [2, 2], [2, 2], [2, 2], [2, 2],
  22872. [2, 2], [2, 2], [2, 2], [2, 2]
  22873. ];
  22874. function CCITTFaxStream(str, maybeLength, params) {
  22875. this.str = str;
  22876. this.dict = str.dict;
  22877. params = params || Dict.empty;
  22878. this.encoding = params.get('K') || 0;
  22879. this.eoline = params.get('EndOfLine') || false;
  22880. this.byteAlign = params.get('EncodedByteAlign') || false;
  22881. this.columns = params.get('Columns') || 1728;
  22882. this.rows = params.get('Rows') || 0;
  22883. var eoblock = params.get('EndOfBlock');
  22884. if (eoblock === null || eoblock === undefined) {
  22885. eoblock = true;
  22886. }
  22887. this.eoblock = eoblock;
  22888. this.black = params.get('BlackIs1') || false;
  22889. this.codingLine = new Uint32Array(this.columns + 1);
  22890. this.refLine = new Uint32Array(this.columns + 2);
  22891. this.codingLine[0] = this.columns;
  22892. this.codingPos = 0;
  22893. this.row = 0;
  22894. this.nextLine2D = this.encoding < 0;
  22895. this.inputBits = 0;
  22896. this.inputBuf = 0;
  22897. this.outputBits = 0;
  22898. var code1;
  22899. while ((code1 = this.lookBits(12)) === 0) {
  22900. this.eatBits(1);
  22901. }
  22902. if (code1 === 1) {
  22903. this.eatBits(12);
  22904. }
  22905. if (this.encoding > 0) {
  22906. this.nextLine2D = !this.lookBits(1);
  22907. this.eatBits(1);
  22908. }
  22909. DecodeStream.call(this, maybeLength);
  22910. }
  22911. CCITTFaxStream.prototype = Object.create(DecodeStream.prototype);
  22912. CCITTFaxStream.prototype.readBlock = function CCITTFaxStream_readBlock() {
  22913. while (!this.eof) {
  22914. var c = this.lookChar();
  22915. this.ensureBuffer(this.bufferLength + 1);
  22916. this.buffer[this.bufferLength++] = c;
  22917. }
  22918. };
  22919. CCITTFaxStream.prototype.addPixels =
  22920. function ccittFaxStreamAddPixels(a1, blackPixels) {
  22921. var codingLine = this.codingLine;
  22922. var codingPos = this.codingPos;
  22923. if (a1 > codingLine[codingPos]) {
  22924. if (a1 > this.columns) {
  22925. info('row is wrong length');
  22926. this.err = true;
  22927. a1 = this.columns;
  22928. }
  22929. if ((codingPos & 1) ^ blackPixels) {
  22930. ++codingPos;
  22931. }
  22932. codingLine[codingPos] = a1;
  22933. }
  22934. this.codingPos = codingPos;
  22935. };
  22936. CCITTFaxStream.prototype.addPixelsNeg =
  22937. function ccittFaxStreamAddPixelsNeg(a1, blackPixels) {
  22938. var codingLine = this.codingLine;
  22939. var codingPos = this.codingPos;
  22940. if (a1 > codingLine[codingPos]) {
  22941. if (a1 > this.columns) {
  22942. info('row is wrong length');
  22943. this.err = true;
  22944. a1 = this.columns;
  22945. }
  22946. if ((codingPos & 1) ^ blackPixels) {
  22947. ++codingPos;
  22948. }
  22949. codingLine[codingPos] = a1;
  22950. } else if (a1 < codingLine[codingPos]) {
  22951. if (a1 < 0) {
  22952. info('invalid code');
  22953. this.err = true;
  22954. a1 = 0;
  22955. }
  22956. while (codingPos > 0 && a1 < codingLine[codingPos - 1]) {
  22957. --codingPos;
  22958. }
  22959. codingLine[codingPos] = a1;
  22960. }
  22961. this.codingPos = codingPos;
  22962. };
  22963. CCITTFaxStream.prototype.lookChar = function CCITTFaxStream_lookChar() {
  22964. var refLine = this.refLine;
  22965. var codingLine = this.codingLine;
  22966. var columns = this.columns;
  22967. var refPos, blackPixels, bits, i;
  22968. if (this.outputBits === 0) {
  22969. if (this.eof) {
  22970. return null;
  22971. }
  22972. this.err = false;
  22973. var code1, code2, code3;
  22974. if (this.nextLine2D) {
  22975. for (i = 0; codingLine[i] < columns; ++i) {
  22976. refLine[i] = codingLine[i];
  22977. }
  22978. refLine[i++] = columns;
  22979. refLine[i] = columns;
  22980. codingLine[0] = 0;
  22981. this.codingPos = 0;
  22982. refPos = 0;
  22983. blackPixels = 0;
  22984. while (codingLine[this.codingPos] < columns) {
  22985. code1 = this.getTwoDimCode();
  22986. switch (code1) {
  22987. case twoDimPass:
  22988. this.addPixels(refLine[refPos + 1], blackPixels);
  22989. if (refLine[refPos + 1] < columns) {
  22990. refPos += 2;
  22991. }
  22992. break;
  22993. case twoDimHoriz:
  22994. code1 = code2 = 0;
  22995. if (blackPixels) {
  22996. do {
  22997. code1 += (code3 = this.getBlackCode());
  22998. } while (code3 >= 64);
  22999. do {
  23000. code2 += (code3 = this.getWhiteCode());
  23001. } while (code3 >= 64);
  23002. } else {
  23003. do {
  23004. code1 += (code3 = this.getWhiteCode());
  23005. } while (code3 >= 64);
  23006. do {
  23007. code2 += (code3 = this.getBlackCode());
  23008. } while (code3 >= 64);
  23009. }
  23010. this.addPixels(codingLine[this.codingPos] +
  23011. code1, blackPixels);
  23012. if (codingLine[this.codingPos] < columns) {
  23013. this.addPixels(codingLine[this.codingPos] + code2,
  23014. blackPixels ^ 1);
  23015. }
  23016. while (refLine[refPos] <= codingLine[this.codingPos] &&
  23017. refLine[refPos] < columns) {
  23018. refPos += 2;
  23019. }
  23020. break;
  23021. case twoDimVertR3:
  23022. this.addPixels(refLine[refPos] + 3, blackPixels);
  23023. blackPixels ^= 1;
  23024. if (codingLine[this.codingPos] < columns) {
  23025. ++refPos;
  23026. while (refLine[refPos] <= codingLine[this.codingPos] &&
  23027. refLine[refPos] < columns) {
  23028. refPos += 2;
  23029. }
  23030. }
  23031. break;
  23032. case twoDimVertR2:
  23033. this.addPixels(refLine[refPos] + 2, blackPixels);
  23034. blackPixels ^= 1;
  23035. if (codingLine[this.codingPos] < columns) {
  23036. ++refPos;
  23037. while (refLine[refPos] <= codingLine[this.codingPos] &&
  23038. refLine[refPos] < columns) {
  23039. refPos += 2;
  23040. }
  23041. }
  23042. break;
  23043. case twoDimVertR1:
  23044. this.addPixels(refLine[refPos] + 1, blackPixels);
  23045. blackPixels ^= 1;
  23046. if (codingLine[this.codingPos] < columns) {
  23047. ++refPos;
  23048. while (refLine[refPos] <= codingLine[this.codingPos] &&
  23049. refLine[refPos] < columns) {
  23050. refPos += 2;
  23051. }
  23052. }
  23053. break;
  23054. case twoDimVert0:
  23055. this.addPixels(refLine[refPos], blackPixels);
  23056. blackPixels ^= 1;
  23057. if (codingLine[this.codingPos] < columns) {
  23058. ++refPos;
  23059. while (refLine[refPos] <= codingLine[this.codingPos] &&
  23060. refLine[refPos] < columns) {
  23061. refPos += 2;
  23062. }
  23063. }
  23064. break;
  23065. case twoDimVertL3:
  23066. this.addPixelsNeg(refLine[refPos] - 3, blackPixels);
  23067. blackPixels ^= 1;
  23068. if (codingLine[this.codingPos] < columns) {
  23069. if (refPos > 0) {
  23070. --refPos;
  23071. } else {
  23072. ++refPos;
  23073. }
  23074. while (refLine[refPos] <= codingLine[this.codingPos] &&
  23075. refLine[refPos] < columns) {
  23076. refPos += 2;
  23077. }
  23078. }
  23079. break;
  23080. case twoDimVertL2:
  23081. this.addPixelsNeg(refLine[refPos] - 2, blackPixels);
  23082. blackPixels ^= 1;
  23083. if (codingLine[this.codingPos] < columns) {
  23084. if (refPos > 0) {
  23085. --refPos;
  23086. } else {
  23087. ++refPos;
  23088. }
  23089. while (refLine[refPos] <= codingLine[this.codingPos] &&
  23090. refLine[refPos] < columns) {
  23091. refPos += 2;
  23092. }
  23093. }
  23094. break;
  23095. case twoDimVertL1:
  23096. this.addPixelsNeg(refLine[refPos] - 1, blackPixels);
  23097. blackPixels ^= 1;
  23098. if (codingLine[this.codingPos] < columns) {
  23099. if (refPos > 0) {
  23100. --refPos;
  23101. } else {
  23102. ++refPos;
  23103. }
  23104. while (refLine[refPos] <= codingLine[this.codingPos] &&
  23105. refLine[refPos] < columns) {
  23106. refPos += 2;
  23107. }
  23108. }
  23109. break;
  23110. case EOF:
  23111. this.addPixels(columns, 0);
  23112. this.eof = true;
  23113. break;
  23114. default:
  23115. info('bad 2d code');
  23116. this.addPixels(columns, 0);
  23117. this.err = true;
  23118. }
  23119. }
  23120. } else {
  23121. codingLine[0] = 0;
  23122. this.codingPos = 0;
  23123. blackPixels = 0;
  23124. while (codingLine[this.codingPos] < columns) {
  23125. code1 = 0;
  23126. if (blackPixels) {
  23127. do {
  23128. code1 += (code3 = this.getBlackCode());
  23129. } while (code3 >= 64);
  23130. } else {
  23131. do {
  23132. code1 += (code3 = this.getWhiteCode());
  23133. } while (code3 >= 64);
  23134. }
  23135. this.addPixels(codingLine[this.codingPos] + code1, blackPixels);
  23136. blackPixels ^= 1;
  23137. }
  23138. }
  23139. var gotEOL = false;
  23140. if (this.byteAlign) {
  23141. this.inputBits &= ~7;
  23142. }
  23143. if (!this.eoblock && this.row === this.rows - 1) {
  23144. this.eof = true;
  23145. } else {
  23146. code1 = this.lookBits(12);
  23147. if (this.eoline) {
  23148. while (code1 !== EOF && code1 !== 1) {
  23149. this.eatBits(1);
  23150. code1 = this.lookBits(12);
  23151. }
  23152. } else {
  23153. while (code1 === 0) {
  23154. this.eatBits(1);
  23155. code1 = this.lookBits(12);
  23156. }
  23157. }
  23158. if (code1 === 1) {
  23159. this.eatBits(12);
  23160. gotEOL = true;
  23161. } else if (code1 === EOF) {
  23162. this.eof = true;
  23163. }
  23164. }
  23165. if (!this.eof && this.encoding > 0) {
  23166. this.nextLine2D = !this.lookBits(1);
  23167. this.eatBits(1);
  23168. }
  23169. if (this.eoblock && gotEOL && this.byteAlign) {
  23170. code1 = this.lookBits(12);
  23171. if (code1 === 1) {
  23172. this.eatBits(12);
  23173. if (this.encoding > 0) {
  23174. this.lookBits(1);
  23175. this.eatBits(1);
  23176. }
  23177. if (this.encoding >= 0) {
  23178. for (i = 0; i < 4; ++i) {
  23179. code1 = this.lookBits(12);
  23180. if (code1 !== 1) {
  23181. info('bad rtc code: ' + code1);
  23182. }
  23183. this.eatBits(12);
  23184. if (this.encoding > 0) {
  23185. this.lookBits(1);
  23186. this.eatBits(1);
  23187. }
  23188. }
  23189. }
  23190. this.eof = true;
  23191. }
  23192. } else if (this.err && this.eoline) {
  23193. while (true) {
  23194. code1 = this.lookBits(13);
  23195. if (code1 === EOF) {
  23196. this.eof = true;
  23197. return null;
  23198. }
  23199. if ((code1 >> 1) === 1) {
  23200. break;
  23201. }
  23202. this.eatBits(1);
  23203. }
  23204. this.eatBits(12);
  23205. if (this.encoding > 0) {
  23206. this.eatBits(1);
  23207. this.nextLine2D = !(code1 & 1);
  23208. }
  23209. }
  23210. if (codingLine[0] > 0) {
  23211. this.outputBits = codingLine[this.codingPos = 0];
  23212. } else {
  23213. this.outputBits = codingLine[this.codingPos = 1];
  23214. }
  23215. this.row++;
  23216. }
  23217. var c;
  23218. if (this.outputBits >= 8) {
  23219. c = (this.codingPos & 1) ? 0 : 0xFF;
  23220. this.outputBits -= 8;
  23221. if (this.outputBits === 0 && codingLine[this.codingPos] < columns) {
  23222. this.codingPos++;
  23223. this.outputBits = (codingLine[this.codingPos] -
  23224. codingLine[this.codingPos - 1]);
  23225. }
  23226. } else {
  23227. bits = 8;
  23228. c = 0;
  23229. do {
  23230. if (this.outputBits > bits) {
  23231. c <<= bits;
  23232. if (!(this.codingPos & 1)) {
  23233. c |= 0xFF >> (8 - bits);
  23234. }
  23235. this.outputBits -= bits;
  23236. bits = 0;
  23237. } else {
  23238. c <<= this.outputBits;
  23239. if (!(this.codingPos & 1)) {
  23240. c |= 0xFF >> (8 - this.outputBits);
  23241. }
  23242. bits -= this.outputBits;
  23243. this.outputBits = 0;
  23244. if (codingLine[this.codingPos] < columns) {
  23245. this.codingPos++;
  23246. this.outputBits = (codingLine[this.codingPos] -
  23247. codingLine[this.codingPos - 1]);
  23248. } else if (bits > 0) {
  23249. c <<= bits;
  23250. bits = 0;
  23251. }
  23252. }
  23253. } while (bits);
  23254. }
  23255. if (this.black) {
  23256. c ^= 0xFF;
  23257. }
  23258. return c;
  23259. };
  23260. // This functions returns the code found from the table.
  23261. // The start and end parameters set the boundaries for searching the table.
  23262. // The limit parameter is optional. Function returns an array with three
  23263. // values. The first array element indicates whether a valid code is being
  23264. // returned. The second array element is the actual code. The third array
  23265. // element indicates whether EOF was reached.
  23266. CCITTFaxStream.prototype.findTableCode =
  23267. function ccittFaxStreamFindTableCode(start, end, table, limit) {
  23268. var limitValue = limit || 0;
  23269. for (var i = start; i <= end; ++i) {
  23270. var code = this.lookBits(i);
  23271. if (code === EOF) {
  23272. return [true, 1, false];
  23273. }
  23274. if (i < end) {
  23275. code <<= end - i;
  23276. }
  23277. if (!limitValue || code >= limitValue) {
  23278. var p = table[code - limitValue];
  23279. if (p[0] === i) {
  23280. this.eatBits(i);
  23281. return [true, p[1], true];
  23282. }
  23283. }
  23284. }
  23285. return [false, 0, false];
  23286. };
  23287. CCITTFaxStream.prototype.getTwoDimCode =
  23288. function ccittFaxStreamGetTwoDimCode() {
  23289. var code = 0;
  23290. var p;
  23291. if (this.eoblock) {
  23292. code = this.lookBits(7);
  23293. p = twoDimTable[code];
  23294. if (p && p[0] > 0) {
  23295. this.eatBits(p[0]);
  23296. return p[1];
  23297. }
  23298. } else {
  23299. var result = this.findTableCode(1, 7, twoDimTable);
  23300. if (result[0] && result[2]) {
  23301. return result[1];
  23302. }
  23303. }
  23304. info('Bad two dim code');
  23305. return EOF;
  23306. };
  23307. CCITTFaxStream.prototype.getWhiteCode =
  23308. function ccittFaxStreamGetWhiteCode() {
  23309. var code = 0;
  23310. var p;
  23311. if (this.eoblock) {
  23312. code = this.lookBits(12);
  23313. if (code === EOF) {
  23314. return 1;
  23315. }
  23316. if ((code >> 5) === 0) {
  23317. p = whiteTable1[code];
  23318. } else {
  23319. p = whiteTable2[code >> 3];
  23320. }
  23321. if (p[0] > 0) {
  23322. this.eatBits(p[0]);
  23323. return p[1];
  23324. }
  23325. } else {
  23326. var result = this.findTableCode(1, 9, whiteTable2);
  23327. if (result[0]) {
  23328. return result[1];
  23329. }
  23330. result = this.findTableCode(11, 12, whiteTable1);
  23331. if (result[0]) {
  23332. return result[1];
  23333. }
  23334. }
  23335. info('bad white code');
  23336. this.eatBits(1);
  23337. return 1;
  23338. };
  23339. CCITTFaxStream.prototype.getBlackCode =
  23340. function ccittFaxStreamGetBlackCode() {
  23341. var code, p;
  23342. if (this.eoblock) {
  23343. code = this.lookBits(13);
  23344. if (code === EOF) {
  23345. return 1;
  23346. }
  23347. if ((code >> 7) === 0) {
  23348. p = blackTable1[code];
  23349. } else if ((code >> 9) === 0 && (code >> 7) !== 0) {
  23350. p = blackTable2[(code >> 1) - 64];
  23351. } else {
  23352. p = blackTable3[code >> 7];
  23353. }
  23354. if (p[0] > 0) {
  23355. this.eatBits(p[0]);
  23356. return p[1];
  23357. }
  23358. } else {
  23359. var result = this.findTableCode(2, 6, blackTable3);
  23360. if (result[0]) {
  23361. return result[1];
  23362. }
  23363. result = this.findTableCode(7, 12, blackTable2, 64);
  23364. if (result[0]) {
  23365. return result[1];
  23366. }
  23367. result = this.findTableCode(10, 13, blackTable1);
  23368. if (result[0]) {
  23369. return result[1];
  23370. }
  23371. }
  23372. info('bad black code');
  23373. this.eatBits(1);
  23374. return 1;
  23375. };
  23376. CCITTFaxStream.prototype.lookBits = function CCITTFaxStream_lookBits(n) {
  23377. var c;
  23378. while (this.inputBits < n) {
  23379. if ((c = this.str.getByte()) === -1) {
  23380. if (this.inputBits === 0) {
  23381. return EOF;
  23382. }
  23383. return ((this.inputBuf << (n - this.inputBits)) &
  23384. (0xFFFF >> (16 - n)));
  23385. }
  23386. this.inputBuf = (this.inputBuf << 8) + c;
  23387. this.inputBits += 8;
  23388. }
  23389. return (this.inputBuf >> (this.inputBits - n)) & (0xFFFF >> (16 - n));
  23390. };
  23391. CCITTFaxStream.prototype.eatBits = function CCITTFaxStream_eatBits(n) {
  23392. if ((this.inputBits -= n) < 0) {
  23393. this.inputBits = 0;
  23394. }
  23395. };
  23396. return CCITTFaxStream;
  23397. })();
  23398. var LZWStream = (function LZWStreamClosure() {
  23399. function LZWStream(str, maybeLength, earlyChange) {
  23400. this.str = str;
  23401. this.dict = str.dict;
  23402. this.cachedData = 0;
  23403. this.bitsCached = 0;
  23404. var maxLzwDictionarySize = 4096;
  23405. var lzwState = {
  23406. earlyChange: earlyChange,
  23407. codeLength: 9,
  23408. nextCode: 258,
  23409. dictionaryValues: new Uint8Array(maxLzwDictionarySize),
  23410. dictionaryLengths: new Uint16Array(maxLzwDictionarySize),
  23411. dictionaryPrevCodes: new Uint16Array(maxLzwDictionarySize),
  23412. currentSequence: new Uint8Array(maxLzwDictionarySize),
  23413. currentSequenceLength: 0
  23414. };
  23415. for (var i = 0; i < 256; ++i) {
  23416. lzwState.dictionaryValues[i] = i;
  23417. lzwState.dictionaryLengths[i] = 1;
  23418. }
  23419. this.lzwState = lzwState;
  23420. DecodeStream.call(this, maybeLength);
  23421. }
  23422. LZWStream.prototype = Object.create(DecodeStream.prototype);
  23423. LZWStream.prototype.readBits = function LZWStream_readBits(n) {
  23424. var bitsCached = this.bitsCached;
  23425. var cachedData = this.cachedData;
  23426. while (bitsCached < n) {
  23427. var c = this.str.getByte();
  23428. if (c === -1) {
  23429. this.eof = true;
  23430. return null;
  23431. }
  23432. cachedData = (cachedData << 8) | c;
  23433. bitsCached += 8;
  23434. }
  23435. this.bitsCached = (bitsCached -= n);
  23436. this.cachedData = cachedData;
  23437. this.lastCode = null;
  23438. return (cachedData >>> bitsCached) & ((1 << n) - 1);
  23439. };
  23440. LZWStream.prototype.readBlock = function LZWStream_readBlock() {
  23441. var blockSize = 512;
  23442. var estimatedDecodedSize = blockSize * 2, decodedSizeDelta = blockSize;
  23443. var i, j, q;
  23444. var lzwState = this.lzwState;
  23445. if (!lzwState) {
  23446. return; // eof was found
  23447. }
  23448. var earlyChange = lzwState.earlyChange;
  23449. var nextCode = lzwState.nextCode;
  23450. var dictionaryValues = lzwState.dictionaryValues;
  23451. var dictionaryLengths = lzwState.dictionaryLengths;
  23452. var dictionaryPrevCodes = lzwState.dictionaryPrevCodes;
  23453. var codeLength = lzwState.codeLength;
  23454. var prevCode = lzwState.prevCode;
  23455. var currentSequence = lzwState.currentSequence;
  23456. var currentSequenceLength = lzwState.currentSequenceLength;
  23457. var decodedLength = 0;
  23458. var currentBufferLength = this.bufferLength;
  23459. var buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  23460. for (i = 0; i < blockSize; i++) {
  23461. var code = this.readBits(codeLength);
  23462. var hasPrev = currentSequenceLength > 0;
  23463. if (code < 256) {
  23464. currentSequence[0] = code;
  23465. currentSequenceLength = 1;
  23466. } else if (code >= 258) {
  23467. if (code < nextCode) {
  23468. currentSequenceLength = dictionaryLengths[code];
  23469. for (j = currentSequenceLength - 1, q = code; j >= 0; j--) {
  23470. currentSequence[j] = dictionaryValues[q];
  23471. q = dictionaryPrevCodes[q];
  23472. }
  23473. } else {
  23474. currentSequence[currentSequenceLength++] = currentSequence[0];
  23475. }
  23476. } else if (code === 256) {
  23477. codeLength = 9;
  23478. nextCode = 258;
  23479. currentSequenceLength = 0;
  23480. continue;
  23481. } else {
  23482. this.eof = true;
  23483. delete this.lzwState;
  23484. break;
  23485. }
  23486. if (hasPrev) {
  23487. dictionaryPrevCodes[nextCode] = prevCode;
  23488. dictionaryLengths[nextCode] = dictionaryLengths[prevCode] + 1;
  23489. dictionaryValues[nextCode] = currentSequence[0];
  23490. nextCode++;
  23491. codeLength = (nextCode + earlyChange) & (nextCode + earlyChange - 1) ?
  23492. codeLength : Math.min(Math.log(nextCode + earlyChange) /
  23493. 0.6931471805599453 + 1, 12) | 0;
  23494. }
  23495. prevCode = code;
  23496. decodedLength += currentSequenceLength;
  23497. if (estimatedDecodedSize < decodedLength) {
  23498. do {
  23499. estimatedDecodedSize += decodedSizeDelta;
  23500. } while (estimatedDecodedSize < decodedLength);
  23501. buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  23502. }
  23503. for (j = 0; j < currentSequenceLength; j++) {
  23504. buffer[currentBufferLength++] = currentSequence[j];
  23505. }
  23506. }
  23507. lzwState.nextCode = nextCode;
  23508. lzwState.codeLength = codeLength;
  23509. lzwState.prevCode = prevCode;
  23510. lzwState.currentSequenceLength = currentSequenceLength;
  23511. this.bufferLength = currentBufferLength;
  23512. };
  23513. return LZWStream;
  23514. })();
  23515. var NullStream = (function NullStreamClosure() {
  23516. function NullStream() {
  23517. Stream.call(this, new Uint8Array(0));
  23518. }
  23519. NullStream.prototype = Stream.prototype;
  23520. return NullStream;
  23521. })();
  23522. // TODO refactor to remove dependency on parser.js
  23523. function _setCoreParser(coreParser_) {
  23524. coreParser = coreParser_;
  23525. EOF = coreParser_.EOF;
  23526. Lexer = coreParser_.Lexer;
  23527. }
  23528. exports._setCoreParser = _setCoreParser;
  23529. // TODO refactor to remove dependency on colorspace.js
  23530. function _setCoreColorSpace(coreColorSpace_) {
  23531. coreColorSpace = coreColorSpace_;
  23532. ColorSpace = coreColorSpace_.ColorSpace;
  23533. }
  23534. exports._setCoreColorSpace = _setCoreColorSpace;
  23535. exports.Ascii85Stream = Ascii85Stream;
  23536. exports.AsciiHexStream = AsciiHexStream;
  23537. exports.CCITTFaxStream = CCITTFaxStream;
  23538. exports.DecryptStream = DecryptStream;
  23539. exports.DecodeStream = DecodeStream;
  23540. exports.FlateStream = FlateStream;
  23541. exports.Jbig2Stream = Jbig2Stream;
  23542. exports.JpegStream = JpegStream;
  23543. exports.JpxStream = JpxStream;
  23544. exports.NullStream = NullStream;
  23545. exports.PredictorStream = PredictorStream;
  23546. exports.RunLengthStream = RunLengthStream;
  23547. exports.Stream = Stream;
  23548. exports.StreamsSequenceStream = StreamsSequenceStream;
  23549. exports.StringStream = StringStream;
  23550. exports.LZWStream = LZWStream;
  23551. }));
  23552. (function (root, factory) {
  23553. {
  23554. factory((root.pdfjsCoreCrypto = {}), root.pdfjsSharedUtil,
  23555. root.pdfjsCorePrimitives, root.pdfjsCoreStream);
  23556. }
  23557. }(this, function (exports, sharedUtil, corePrimitives, coreStream) {
  23558. var PasswordException = sharedUtil.PasswordException;
  23559. var PasswordResponses = sharedUtil.PasswordResponses;
  23560. var bytesToString = sharedUtil.bytesToString;
  23561. var error = sharedUtil.error;
  23562. var isInt = sharedUtil.isInt;
  23563. var stringToBytes = sharedUtil.stringToBytes;
  23564. var utf8StringToString = sharedUtil.utf8StringToString;
  23565. var warn = sharedUtil.warn;
  23566. var Name = corePrimitives.Name;
  23567. var isName = corePrimitives.isName;
  23568. var DecryptStream = coreStream.DecryptStream;
  23569. var ARCFourCipher = (function ARCFourCipherClosure() {
  23570. function ARCFourCipher(key) {
  23571. this.a = 0;
  23572. this.b = 0;
  23573. var s = new Uint8Array(256);
  23574. var i, j = 0, tmp, keyLength = key.length;
  23575. for (i = 0; i < 256; ++i) {
  23576. s[i] = i;
  23577. }
  23578. for (i = 0; i < 256; ++i) {
  23579. tmp = s[i];
  23580. j = (j + tmp + key[i % keyLength]) & 0xFF;
  23581. s[i] = s[j];
  23582. s[j] = tmp;
  23583. }
  23584. this.s = s;
  23585. }
  23586. ARCFourCipher.prototype = {
  23587. encryptBlock: function ARCFourCipher_encryptBlock(data) {
  23588. var i, n = data.length, tmp, tmp2;
  23589. var a = this.a, b = this.b, s = this.s;
  23590. var output = new Uint8Array(n);
  23591. for (i = 0; i < n; ++i) {
  23592. a = (a + 1) & 0xFF;
  23593. tmp = s[a];
  23594. b = (b + tmp) & 0xFF;
  23595. tmp2 = s[b];
  23596. s[a] = tmp2;
  23597. s[b] = tmp;
  23598. output[i] = data[i] ^ s[(tmp + tmp2) & 0xFF];
  23599. }
  23600. this.a = a;
  23601. this.b = b;
  23602. return output;
  23603. }
  23604. };
  23605. ARCFourCipher.prototype.decryptBlock = ARCFourCipher.prototype.encryptBlock;
  23606. return ARCFourCipher;
  23607. })();
  23608. var calculateMD5 = (function calculateMD5Closure() {
  23609. var r = new Uint8Array([
  23610. 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22,
  23611. 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20,
  23612. 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23,
  23613. 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21]);
  23614. var k = new Int32Array([
  23615. -680876936, -389564586, 606105819, -1044525330, -176418897, 1200080426,
  23616. -1473231341, -45705983, 1770035416, -1958414417, -42063, -1990404162,
  23617. 1804603682, -40341101, -1502002290, 1236535329, -165796510, -1069501632,
  23618. 643717713, -373897302, -701558691, 38016083, -660478335, -405537848,
  23619. 568446438, -1019803690, -187363961, 1163531501, -1444681467, -51403784,
  23620. 1735328473, -1926607734, -378558, -2022574463, 1839030562, -35309556,
  23621. -1530992060, 1272893353, -155497632, -1094730640, 681279174, -358537222,
  23622. -722521979, 76029189, -640364487, -421815835, 530742520, -995338651,
  23623. -198630844, 1126891415, -1416354905, -57434055, 1700485571, -1894986606,
  23624. -1051523, -2054922799, 1873313359, -30611744, -1560198380, 1309151649,
  23625. -145523070, -1120210379, 718787259, -343485551]);
  23626. function hash(data, offset, length) {
  23627. var h0 = 1732584193, h1 = -271733879, h2 = -1732584194, h3 = 271733878;
  23628. // pre-processing
  23629. var paddedLength = (length + 72) & ~63; // data + 9 extra bytes
  23630. var padded = new Uint8Array(paddedLength);
  23631. var i, j, n;
  23632. for (i = 0; i < length; ++i) {
  23633. padded[i] = data[offset++];
  23634. }
  23635. padded[i++] = 0x80;
  23636. n = paddedLength - 8;
  23637. while (i < n) {
  23638. padded[i++] = 0;
  23639. }
  23640. padded[i++] = (length << 3) & 0xFF;
  23641. padded[i++] = (length >> 5) & 0xFF;
  23642. padded[i++] = (length >> 13) & 0xFF;
  23643. padded[i++] = (length >> 21) & 0xFF;
  23644. padded[i++] = (length >>> 29) & 0xFF;
  23645. padded[i++] = 0;
  23646. padded[i++] = 0;
  23647. padded[i++] = 0;
  23648. var w = new Int32Array(16);
  23649. for (i = 0; i < paddedLength;) {
  23650. for (j = 0; j < 16; ++j, i += 4) {
  23651. w[j] = (padded[i] | (padded[i + 1] << 8) |
  23652. (padded[i + 2] << 16) | (padded[i + 3] << 24));
  23653. }
  23654. var a = h0, b = h1, c = h2, d = h3, f, g;
  23655. for (j = 0; j < 64; ++j) {
  23656. if (j < 16) {
  23657. f = (b & c) | ((~b) & d);
  23658. g = j;
  23659. } else if (j < 32) {
  23660. f = (d & b) | ((~d) & c);
  23661. g = (5 * j + 1) & 15;
  23662. } else if (j < 48) {
  23663. f = b ^ c ^ d;
  23664. g = (3 * j + 5) & 15;
  23665. } else {
  23666. f = c ^ (b | (~d));
  23667. g = (7 * j) & 15;
  23668. }
  23669. var tmp = d, rotateArg = (a + f + k[j] + w[g]) | 0, rotate = r[j];
  23670. d = c;
  23671. c = b;
  23672. b = (b + ((rotateArg << rotate) | (rotateArg >>> (32 - rotate)))) | 0;
  23673. a = tmp;
  23674. }
  23675. h0 = (h0 + a) | 0;
  23676. h1 = (h1 + b) | 0;
  23677. h2 = (h2 + c) | 0;
  23678. h3 = (h3 + d) | 0;
  23679. }
  23680. return new Uint8Array([
  23681. h0 & 0xFF, (h0 >> 8) & 0xFF, (h0 >> 16) & 0xFF, (h0 >>> 24) & 0xFF,
  23682. h1 & 0xFF, (h1 >> 8) & 0xFF, (h1 >> 16) & 0xFF, (h1 >>> 24) & 0xFF,
  23683. h2 & 0xFF, (h2 >> 8) & 0xFF, (h2 >> 16) & 0xFF, (h2 >>> 24) & 0xFF,
  23684. h3 & 0xFF, (h3 >> 8) & 0xFF, (h3 >> 16) & 0xFF, (h3 >>> 24) & 0xFF
  23685. ]);
  23686. }
  23687. return hash;
  23688. })();
  23689. var Word64 = (function Word64Closure() {
  23690. function Word64(highInteger, lowInteger) {
  23691. this.high = highInteger | 0;
  23692. this.low = lowInteger | 0;
  23693. }
  23694. Word64.prototype = {
  23695. and: function Word64_and(word) {
  23696. this.high &= word.high;
  23697. this.low &= word.low;
  23698. },
  23699. xor: function Word64_xor(word) {
  23700. this.high ^= word.high;
  23701. this.low ^= word.low;
  23702. },
  23703. or: function Word64_or(word) {
  23704. this.high |= word.high;
  23705. this.low |= word.low;
  23706. },
  23707. shiftRight: function Word64_shiftRight(places) {
  23708. if (places >= 32) {
  23709. this.low = (this.high >>> (places - 32)) | 0;
  23710. this.high = 0;
  23711. } else {
  23712. this.low = (this.low >>> places) | (this.high << (32 - places));
  23713. this.high = (this.high >>> places) | 0;
  23714. }
  23715. },
  23716. shiftLeft: function Word64_shiftLeft(places) {
  23717. if (places >= 32) {
  23718. this.high = this.low << (places - 32);
  23719. this.low = 0;
  23720. } else {
  23721. this.high = (this.high << places) | (this.low >>> (32 - places));
  23722. this.low = this.low << places;
  23723. }
  23724. },
  23725. rotateRight: function Word64_rotateRight(places) {
  23726. var low, high;
  23727. if (places & 32) {
  23728. high = this.low;
  23729. low = this.high;
  23730. } else {
  23731. low = this.low;
  23732. high = this.high;
  23733. }
  23734. places &= 31;
  23735. this.low = (low >>> places) | (high << (32 - places));
  23736. this.high = (high >>> places) | (low << (32 - places));
  23737. },
  23738. not: function Word64_not() {
  23739. this.high = ~this.high;
  23740. this.low = ~this.low;
  23741. },
  23742. add: function Word64_add(word) {
  23743. var lowAdd = (this.low >>> 0) + (word.low >>> 0);
  23744. var highAdd = (this.high >>> 0) + (word.high >>> 0);
  23745. if (lowAdd > 0xFFFFFFFF) {
  23746. highAdd += 1;
  23747. }
  23748. this.low = lowAdd | 0;
  23749. this.high = highAdd | 0;
  23750. },
  23751. copyTo: function Word64_copyTo(bytes, offset) {
  23752. bytes[offset] = (this.high >>> 24) & 0xFF;
  23753. bytes[offset + 1] = (this.high >> 16) & 0xFF;
  23754. bytes[offset + 2] = (this.high >> 8) & 0xFF;
  23755. bytes[offset + 3] = this.high & 0xFF;
  23756. bytes[offset + 4] = (this.low >>> 24) & 0xFF;
  23757. bytes[offset + 5] = (this.low >> 16) & 0xFF;
  23758. bytes[offset + 6] = (this.low >> 8) & 0xFF;
  23759. bytes[offset + 7] = this.low & 0xFF;
  23760. },
  23761. assign: function Word64_assign(word) {
  23762. this.high = word.high;
  23763. this.low = word.low;
  23764. }
  23765. };
  23766. return Word64;
  23767. })();
  23768. var calculateSHA256 = (function calculateSHA256Closure() {
  23769. function rotr(x, n) {
  23770. return (x >>> n) | (x << 32 - n);
  23771. }
  23772. function ch(x, y, z) {
  23773. return (x & y) ^ (~x & z);
  23774. }
  23775. function maj(x, y, z) {
  23776. return (x & y) ^ (x & z) ^ (y & z);
  23777. }
  23778. function sigma(x) {
  23779. return rotr(x, 2) ^ rotr(x, 13) ^ rotr(x, 22);
  23780. }
  23781. function sigmaPrime(x) {
  23782. return rotr(x, 6) ^ rotr(x, 11) ^ rotr(x, 25);
  23783. }
  23784. function littleSigma(x) {
  23785. return rotr(x, 7) ^ rotr(x, 18) ^ x >>> 3;
  23786. }
  23787. function littleSigmaPrime(x) {
  23788. return rotr(x, 17) ^ rotr(x, 19) ^ x >>> 10;
  23789. }
  23790. var k = [0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
  23791. 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
  23792. 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
  23793. 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
  23794. 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
  23795. 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
  23796. 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
  23797. 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
  23798. 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
  23799. 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
  23800. 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
  23801. 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
  23802. 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
  23803. 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
  23804. 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
  23805. 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2];
  23806. function hash(data, offset, length) {
  23807. // initial hash values
  23808. var h0 = 0x6a09e667, h1 = 0xbb67ae85, h2 = 0x3c6ef372,
  23809. h3 = 0xa54ff53a, h4 = 0x510e527f, h5 = 0x9b05688c,
  23810. h6 = 0x1f83d9ab, h7 = 0x5be0cd19;
  23811. // pre-processing
  23812. var paddedLength = Math.ceil((length + 9) / 64) * 64;
  23813. var padded = new Uint8Array(paddedLength);
  23814. var i, j, n;
  23815. for (i = 0; i < length; ++i) {
  23816. padded[i] = data[offset++];
  23817. }
  23818. padded[i++] = 0x80;
  23819. n = paddedLength - 8;
  23820. while (i < n) {
  23821. padded[i++] = 0;
  23822. }
  23823. padded[i++] = 0;
  23824. padded[i++] = 0;
  23825. padded[i++] = 0;
  23826. padded[i++] = (length >>> 29) & 0xFF;
  23827. padded[i++] = (length >> 21) & 0xFF;
  23828. padded[i++] = (length >> 13) & 0xFF;
  23829. padded[i++] = (length >> 5) & 0xFF;
  23830. padded[i++] = (length << 3) & 0xFF;
  23831. var w = new Uint32Array(64);
  23832. // for each 512 bit block
  23833. for (i = 0; i < paddedLength;) {
  23834. for (j = 0; j < 16; ++j) {
  23835. w[j] = (padded[i] << 24 | (padded[i + 1] << 16) |
  23836. (padded[i + 2] << 8) | (padded[i + 3]));
  23837. i += 4;
  23838. }
  23839. for (j = 16; j < 64; ++j) {
  23840. w[j] = littleSigmaPrime(w[j - 2]) + w[j - 7] +
  23841. littleSigma(w[j - 15]) + w[j - 16] | 0;
  23842. }
  23843. var a = h0, b = h1, c = h2, d = h3, e = h4,
  23844. f = h5, g = h6, h = h7, t1, t2;
  23845. for (j = 0; j < 64; ++j) {
  23846. t1 = h + sigmaPrime(e) + ch(e, f, g) + k[j] + w[j];
  23847. t2 = sigma(a) + maj(a, b, c);
  23848. h = g;
  23849. g = f;
  23850. f = e;
  23851. e = (d + t1) | 0;
  23852. d = c;
  23853. c = b;
  23854. b = a;
  23855. a = (t1 + t2) | 0;
  23856. }
  23857. h0 = (h0 + a) | 0;
  23858. h1 = (h1 + b) | 0;
  23859. h2 = (h2 + c) | 0;
  23860. h3 = (h3 + d) | 0;
  23861. h4 = (h4 + e) | 0;
  23862. h5 = (h5 + f) | 0;
  23863. h6 = (h6 + g) | 0;
  23864. h7 = (h7 + h) | 0;
  23865. }
  23866. return new Uint8Array([
  23867. (h0 >> 24) & 0xFF, (h0 >> 16) & 0xFF, (h0 >> 8) & 0xFF, (h0) & 0xFF,
  23868. (h1 >> 24) & 0xFF, (h1 >> 16) & 0xFF, (h1 >> 8) & 0xFF, (h1) & 0xFF,
  23869. (h2 >> 24) & 0xFF, (h2 >> 16) & 0xFF, (h2 >> 8) & 0xFF, (h2) & 0xFF,
  23870. (h3 >> 24) & 0xFF, (h3 >> 16) & 0xFF, (h3 >> 8) & 0xFF, (h3) & 0xFF,
  23871. (h4 >> 24) & 0xFF, (h4 >> 16) & 0xFF, (h4 >> 8) & 0xFF, (h4) & 0xFF,
  23872. (h5 >> 24) & 0xFF, (h5 >> 16) & 0xFF, (h5 >> 8) & 0xFF, (h5) & 0xFF,
  23873. (h6 >> 24) & 0xFF, (h6 >> 16) & 0xFF, (h6 >> 8) & 0xFF, (h6) & 0xFF,
  23874. (h7 >> 24) & 0xFF, (h7 >> 16) & 0xFF, (h7 >> 8) & 0xFF, (h7) & 0xFF
  23875. ]);
  23876. }
  23877. return hash;
  23878. })();
  23879. var calculateSHA512 = (function calculateSHA512Closure() {
  23880. function ch(result, x, y, z, tmp) {
  23881. result.assign(x);
  23882. result.and(y);
  23883. tmp.assign(x);
  23884. tmp.not();
  23885. tmp.and(z);
  23886. result.xor(tmp);
  23887. }
  23888. function maj(result, x, y, z, tmp) {
  23889. result.assign(x);
  23890. result.and(y);
  23891. tmp.assign(x);
  23892. tmp.and(z);
  23893. result.xor(tmp);
  23894. tmp.assign(y);
  23895. tmp.and(z);
  23896. result.xor(tmp);
  23897. }
  23898. function sigma(result, x, tmp) {
  23899. result.assign(x);
  23900. result.rotateRight(28);
  23901. tmp.assign(x);
  23902. tmp.rotateRight(34);
  23903. result.xor(tmp);
  23904. tmp.assign(x);
  23905. tmp.rotateRight(39);
  23906. result.xor(tmp);
  23907. }
  23908. function sigmaPrime(result, x, tmp) {
  23909. result.assign(x);
  23910. result.rotateRight(14);
  23911. tmp.assign(x);
  23912. tmp.rotateRight(18);
  23913. result.xor(tmp);
  23914. tmp.assign(x);
  23915. tmp.rotateRight(41);
  23916. result.xor(tmp);
  23917. }
  23918. function littleSigma(result, x, tmp) {
  23919. result.assign(x);
  23920. result.rotateRight(1);
  23921. tmp.assign(x);
  23922. tmp.rotateRight(8);
  23923. result.xor(tmp);
  23924. tmp.assign(x);
  23925. tmp.shiftRight(7);
  23926. result.xor(tmp);
  23927. }
  23928. function littleSigmaPrime(result, x, tmp) {
  23929. result.assign(x);
  23930. result.rotateRight(19);
  23931. tmp.assign(x);
  23932. tmp.rotateRight(61);
  23933. result.xor(tmp);
  23934. tmp.assign(x);
  23935. tmp.shiftRight(6);
  23936. result.xor(tmp);
  23937. }
  23938. var k = [
  23939. new Word64(0x428a2f98, 0xd728ae22), new Word64(0x71374491, 0x23ef65cd),
  23940. new Word64(0xb5c0fbcf, 0xec4d3b2f), new Word64(0xe9b5dba5, 0x8189dbbc),
  23941. new Word64(0x3956c25b, 0xf348b538), new Word64(0x59f111f1, 0xb605d019),
  23942. new Word64(0x923f82a4, 0xaf194f9b), new Word64(0xab1c5ed5, 0xda6d8118),
  23943. new Word64(0xd807aa98, 0xa3030242), new Word64(0x12835b01, 0x45706fbe),
  23944. new Word64(0x243185be, 0x4ee4b28c), new Word64(0x550c7dc3, 0xd5ffb4e2),
  23945. new Word64(0x72be5d74, 0xf27b896f), new Word64(0x80deb1fe, 0x3b1696b1),
  23946. new Word64(0x9bdc06a7, 0x25c71235), new Word64(0xc19bf174, 0xcf692694),
  23947. new Word64(0xe49b69c1, 0x9ef14ad2), new Word64(0xefbe4786, 0x384f25e3),
  23948. new Word64(0x0fc19dc6, 0x8b8cd5b5), new Word64(0x240ca1cc, 0x77ac9c65),
  23949. new Word64(0x2de92c6f, 0x592b0275), new Word64(0x4a7484aa, 0x6ea6e483),
  23950. new Word64(0x5cb0a9dc, 0xbd41fbd4), new Word64(0x76f988da, 0x831153b5),
  23951. new Word64(0x983e5152, 0xee66dfab), new Word64(0xa831c66d, 0x2db43210),
  23952. new Word64(0xb00327c8, 0x98fb213f), new Word64(0xbf597fc7, 0xbeef0ee4),
  23953. new Word64(0xc6e00bf3, 0x3da88fc2), new Word64(0xd5a79147, 0x930aa725),
  23954. new Word64(0x06ca6351, 0xe003826f), new Word64(0x14292967, 0x0a0e6e70),
  23955. new Word64(0x27b70a85, 0x46d22ffc), new Word64(0x2e1b2138, 0x5c26c926),
  23956. new Word64(0x4d2c6dfc, 0x5ac42aed), new Word64(0x53380d13, 0x9d95b3df),
  23957. new Word64(0x650a7354, 0x8baf63de), new Word64(0x766a0abb, 0x3c77b2a8),
  23958. new Word64(0x81c2c92e, 0x47edaee6), new Word64(0x92722c85, 0x1482353b),
  23959. new Word64(0xa2bfe8a1, 0x4cf10364), new Word64(0xa81a664b, 0xbc423001),
  23960. new Word64(0xc24b8b70, 0xd0f89791), new Word64(0xc76c51a3, 0x0654be30),
  23961. new Word64(0xd192e819, 0xd6ef5218), new Word64(0xd6990624, 0x5565a910),
  23962. new Word64(0xf40e3585, 0x5771202a), new Word64(0x106aa070, 0x32bbd1b8),
  23963. new Word64(0x19a4c116, 0xb8d2d0c8), new Word64(0x1e376c08, 0x5141ab53),
  23964. new Word64(0x2748774c, 0xdf8eeb99), new Word64(0x34b0bcb5, 0xe19b48a8),
  23965. new Word64(0x391c0cb3, 0xc5c95a63), new Word64(0x4ed8aa4a, 0xe3418acb),
  23966. new Word64(0x5b9cca4f, 0x7763e373), new Word64(0x682e6ff3, 0xd6b2b8a3),
  23967. new Word64(0x748f82ee, 0x5defb2fc), new Word64(0x78a5636f, 0x43172f60),
  23968. new Word64(0x84c87814, 0xa1f0ab72), new Word64(0x8cc70208, 0x1a6439ec),
  23969. new Word64(0x90befffa, 0x23631e28), new Word64(0xa4506ceb, 0xde82bde9),
  23970. new Word64(0xbef9a3f7, 0xb2c67915), new Word64(0xc67178f2, 0xe372532b),
  23971. new Word64(0xca273ece, 0xea26619c), new Word64(0xd186b8c7, 0x21c0c207),
  23972. new Word64(0xeada7dd6, 0xcde0eb1e), new Word64(0xf57d4f7f, 0xee6ed178),
  23973. new Word64(0x06f067aa, 0x72176fba), new Word64(0x0a637dc5, 0xa2c898a6),
  23974. new Word64(0x113f9804, 0xbef90dae), new Word64(0x1b710b35, 0x131c471b),
  23975. new Word64(0x28db77f5, 0x23047d84), new Word64(0x32caab7b, 0x40c72493),
  23976. new Word64(0x3c9ebe0a, 0x15c9bebc), new Word64(0x431d67c4, 0x9c100d4c),
  23977. new Word64(0x4cc5d4be, 0xcb3e42b6), new Word64(0x597f299c, 0xfc657e2a),
  23978. new Word64(0x5fcb6fab, 0x3ad6faec), new Word64(0x6c44198c, 0x4a475817)];
  23979. function hash(data, offset, length, mode384) {
  23980. mode384 = !!mode384;
  23981. // initial hash values
  23982. var h0, h1, h2, h3, h4, h5, h6, h7;
  23983. if (!mode384) {
  23984. h0 = new Word64(0x6a09e667, 0xf3bcc908);
  23985. h1 = new Word64(0xbb67ae85, 0x84caa73b);
  23986. h2 = new Word64(0x3c6ef372, 0xfe94f82b);
  23987. h3 = new Word64(0xa54ff53a, 0x5f1d36f1);
  23988. h4 = new Word64(0x510e527f, 0xade682d1);
  23989. h5 = new Word64(0x9b05688c, 0x2b3e6c1f);
  23990. h6 = new Word64(0x1f83d9ab, 0xfb41bd6b);
  23991. h7 = new Word64(0x5be0cd19, 0x137e2179);
  23992. }
  23993. else {
  23994. // SHA384 is exactly the same
  23995. // except with different starting values and a trimmed result
  23996. h0 = new Word64(0xcbbb9d5d, 0xc1059ed8);
  23997. h1 = new Word64(0x629a292a, 0x367cd507);
  23998. h2 = new Word64(0x9159015a, 0x3070dd17);
  23999. h3 = new Word64(0x152fecd8, 0xf70e5939);
  24000. h4 = new Word64(0x67332667, 0xffc00b31);
  24001. h5 = new Word64(0x8eb44a87, 0x68581511);
  24002. h6 = new Word64(0xdb0c2e0d, 0x64f98fa7);
  24003. h7 = new Word64(0x47b5481d, 0xbefa4fa4);
  24004. }
  24005. // pre-processing
  24006. var paddedLength = Math.ceil((length + 17) / 128) * 128;
  24007. var padded = new Uint8Array(paddedLength);
  24008. var i, j, n;
  24009. for (i = 0; i < length; ++i) {
  24010. padded[i] = data[offset++];
  24011. }
  24012. padded[i++] = 0x80;
  24013. n = paddedLength - 16;
  24014. while (i < n) {
  24015. padded[i++] = 0;
  24016. }
  24017. padded[i++] = 0;
  24018. padded[i++] = 0;
  24019. padded[i++] = 0;
  24020. padded[i++] = 0;
  24021. padded[i++] = 0;
  24022. padded[i++] = 0;
  24023. padded[i++] = 0;
  24024. padded[i++] = 0;
  24025. padded[i++] = 0;
  24026. padded[i++] = 0;
  24027. padded[i++] = 0;
  24028. padded[i++] = (length >>> 29) & 0xFF;
  24029. padded[i++] = (length >> 21) & 0xFF;
  24030. padded[i++] = (length >> 13) & 0xFF;
  24031. padded[i++] = (length >> 5) & 0xFF;
  24032. padded[i++] = (length << 3) & 0xFF;
  24033. var w = new Array(80);
  24034. for (i = 0; i < 80; i++) {
  24035. w[i] = new Word64(0, 0);
  24036. }
  24037. var a = new Word64(0, 0), b = new Word64(0, 0), c = new Word64(0, 0);
  24038. var d = new Word64(0, 0), e = new Word64(0, 0), f = new Word64(0, 0);
  24039. var g = new Word64(0, 0), h = new Word64(0, 0);
  24040. var t1 = new Word64(0, 0), t2 = new Word64(0, 0);
  24041. var tmp1 = new Word64(0, 0), tmp2 = new Word64(0, 0), tmp3;
  24042. // for each 1024 bit block
  24043. for (i = 0; i < paddedLength;) {
  24044. for (j = 0; j < 16; ++j) {
  24045. w[j].high = (padded[i] << 24) | (padded[i + 1] << 16) |
  24046. (padded[i + 2] << 8) | (padded[i + 3]);
  24047. w[j].low = (padded[i + 4]) << 24 | (padded[i + 5]) << 16 |
  24048. (padded[i + 6]) << 8 | (padded[i + 7]);
  24049. i += 8;
  24050. }
  24051. for (j = 16; j < 80; ++j) {
  24052. tmp3 = w[j];
  24053. littleSigmaPrime(tmp3, w[j - 2], tmp2);
  24054. tmp3.add(w[j - 7]);
  24055. littleSigma(tmp1, w[j - 15], tmp2);
  24056. tmp3.add(tmp1);
  24057. tmp3.add(w[j - 16]);
  24058. }
  24059. a.assign(h0); b.assign(h1); c.assign(h2); d.assign(h3);
  24060. e.assign(h4); f.assign(h5); g.assign(h6); h.assign(h7);
  24061. for (j = 0; j < 80; ++j) {
  24062. t1.assign(h);
  24063. sigmaPrime(tmp1, e, tmp2);
  24064. t1.add(tmp1);
  24065. ch(tmp1, e, f, g, tmp2);
  24066. t1.add(tmp1);
  24067. t1.add(k[j]);
  24068. t1.add(w[j]);
  24069. sigma(t2, a, tmp2);
  24070. maj(tmp1, a, b, c, tmp2);
  24071. t2.add(tmp1);
  24072. tmp3 = h;
  24073. h = g;
  24074. g = f;
  24075. f = e;
  24076. d.add(t1);
  24077. e = d;
  24078. d = c;
  24079. c = b;
  24080. b = a;
  24081. tmp3.assign(t1);
  24082. tmp3.add(t2);
  24083. a = tmp3;
  24084. }
  24085. h0.add(a);
  24086. h1.add(b);
  24087. h2.add(c);
  24088. h3.add(d);
  24089. h4.add(e);
  24090. h5.add(f);
  24091. h6.add(g);
  24092. h7.add(h);
  24093. }
  24094. var result;
  24095. if (!mode384) {
  24096. result = new Uint8Array(64);
  24097. h0.copyTo(result,0);
  24098. h1.copyTo(result,8);
  24099. h2.copyTo(result,16);
  24100. h3.copyTo(result,24);
  24101. h4.copyTo(result,32);
  24102. h5.copyTo(result,40);
  24103. h6.copyTo(result,48);
  24104. h7.copyTo(result,56);
  24105. }
  24106. else {
  24107. result = new Uint8Array(48);
  24108. h0.copyTo(result,0);
  24109. h1.copyTo(result,8);
  24110. h2.copyTo(result,16);
  24111. h3.copyTo(result,24);
  24112. h4.copyTo(result,32);
  24113. h5.copyTo(result,40);
  24114. }
  24115. return result;
  24116. }
  24117. return hash;
  24118. })();
  24119. var calculateSHA384 = (function calculateSHA384Closure() {
  24120. function hash(data, offset, length) {
  24121. return calculateSHA512(data, offset, length, true);
  24122. }
  24123. return hash;
  24124. })();
  24125. var NullCipher = (function NullCipherClosure() {
  24126. function NullCipher() {
  24127. }
  24128. NullCipher.prototype = {
  24129. decryptBlock: function NullCipher_decryptBlock(data) {
  24130. return data;
  24131. }
  24132. };
  24133. return NullCipher;
  24134. })();
  24135. var AES128Cipher = (function AES128CipherClosure() {
  24136. var rcon = new Uint8Array([
  24137. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  24138. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  24139. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  24140. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  24141. 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  24142. 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
  24143. 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
  24144. 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
  24145. 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
  24146. 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
  24147. 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
  24148. 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
  24149. 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
  24150. 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
  24151. 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
  24152. 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
  24153. 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
  24154. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  24155. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  24156. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  24157. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  24158. 0x74, 0xe8, 0xcb, 0x8d]);
  24159. var s = new Uint8Array([
  24160. 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
  24161. 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
  24162. 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
  24163. 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
  24164. 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
  24165. 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
  24166. 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
  24167. 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
  24168. 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
  24169. 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
  24170. 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
  24171. 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
  24172. 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
  24173. 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
  24174. 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
  24175. 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
  24176. 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
  24177. 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
  24178. 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
  24179. 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
  24180. 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
  24181. 0xb0, 0x54, 0xbb, 0x16]);
  24182. var inv_s = new Uint8Array([
  24183. 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
  24184. 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
  24185. 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
  24186. 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
  24187. 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
  24188. 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
  24189. 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
  24190. 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
  24191. 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
  24192. 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
  24193. 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
  24194. 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
  24195. 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
  24196. 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
  24197. 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
  24198. 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
  24199. 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
  24200. 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
  24201. 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
  24202. 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
  24203. 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
  24204. 0x55, 0x21, 0x0c, 0x7d]);
  24205. var mixCol = new Uint8Array(256);
  24206. for (var i = 0; i < 256; i++) {
  24207. if (i < 128) {
  24208. mixCol[i] = i << 1;
  24209. } else {
  24210. mixCol[i] = (i << 1) ^ 0x1b;
  24211. }
  24212. }
  24213. var mix = new Uint32Array([
  24214. 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
  24215. 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
  24216. 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
  24217. 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
  24218. 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
  24219. 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
  24220. 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
  24221. 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
  24222. 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
  24223. 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
  24224. 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
  24225. 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
  24226. 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
  24227. 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
  24228. 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
  24229. 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
  24230. 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
  24231. 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
  24232. 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
  24233. 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
  24234. 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
  24235. 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
  24236. 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
  24237. 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
  24238. 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
  24239. 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
  24240. 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
  24241. 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
  24242. 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
  24243. 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
  24244. 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
  24245. 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
  24246. 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
  24247. 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
  24248. 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
  24249. 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
  24250. 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
  24251. 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
  24252. 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
  24253. 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
  24254. 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
  24255. 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
  24256. 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
  24257. function expandKey128(cipherKey) {
  24258. var b = 176, result = new Uint8Array(b);
  24259. result.set(cipherKey);
  24260. for (var j = 16, i = 1; j < b; ++i) {
  24261. // RotWord
  24262. var t1 = result[j - 3], t2 = result[j - 2],
  24263. t3 = result[j - 1], t4 = result[j - 4];
  24264. // SubWord
  24265. t1 = s[t1];
  24266. t2 = s[t2];
  24267. t3 = s[t3];
  24268. t4 = s[t4];
  24269. // Rcon
  24270. t1 = t1 ^ rcon[i];
  24271. for (var n = 0; n < 4; ++n) {
  24272. result[j] = (t1 ^= result[j - 16]);
  24273. j++;
  24274. result[j] = (t2 ^= result[j - 16]);
  24275. j++;
  24276. result[j] = (t3 ^= result[j - 16]);
  24277. j++;
  24278. result[j] = (t4 ^= result[j - 16]);
  24279. j++;
  24280. }
  24281. }
  24282. return result;
  24283. }
  24284. function decrypt128(input, key) {
  24285. var state = new Uint8Array(16);
  24286. state.set(input);
  24287. var i, j, k;
  24288. var t, u, v;
  24289. // AddRoundKey
  24290. for (j = 0, k = 160; j < 16; ++j, ++k) {
  24291. state[j] ^= key[k];
  24292. }
  24293. for (i = 9; i >= 1; --i) {
  24294. // InvShiftRows
  24295. t = state[13];
  24296. state[13] = state[9];
  24297. state[9] = state[5];
  24298. state[5] = state[1];
  24299. state[1] = t;
  24300. t = state[14];
  24301. u = state[10];
  24302. state[14] = state[6];
  24303. state[10] = state[2];
  24304. state[6] = t;
  24305. state[2] = u;
  24306. t = state[15];
  24307. u = state[11];
  24308. v = state[7];
  24309. state[15] = state[3];
  24310. state[11] = t;
  24311. state[7] = u;
  24312. state[3] = v;
  24313. // InvSubBytes
  24314. for (j = 0; j < 16; ++j) {
  24315. state[j] = inv_s[state[j]];
  24316. }
  24317. // AddRoundKey
  24318. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  24319. state[j] ^= key[k];
  24320. }
  24321. // InvMixColumns
  24322. for (j = 0; j < 16; j += 4) {
  24323. var s0 = mix[state[j]], s1 = mix[state[j + 1]],
  24324. s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  24325. t = (s0 ^ (s1 >>> 8) ^ (s1 << 24) ^ (s2 >>> 16) ^ (s2 << 16) ^
  24326. (s3 >>> 24) ^ (s3 << 8));
  24327. state[j] = (t >>> 24) & 0xFF;
  24328. state[j + 1] = (t >> 16) & 0xFF;
  24329. state[j + 2] = (t >> 8) & 0xFF;
  24330. state[j + 3] = t & 0xFF;
  24331. }
  24332. }
  24333. // InvShiftRows
  24334. t = state[13];
  24335. state[13] = state[9];
  24336. state[9] = state[5];
  24337. state[5] = state[1];
  24338. state[1] = t;
  24339. t = state[14];
  24340. u = state[10];
  24341. state[14] = state[6];
  24342. state[10] = state[2];
  24343. state[6] = t;
  24344. state[2] = u;
  24345. t = state[15];
  24346. u = state[11];
  24347. v = state[7];
  24348. state[15] = state[3];
  24349. state[11] = t;
  24350. state[7] = u;
  24351. state[3] = v;
  24352. for (j = 0; j < 16; ++j) {
  24353. // InvSubBytes
  24354. state[j] = inv_s[state[j]];
  24355. // AddRoundKey
  24356. state[j] ^= key[j];
  24357. }
  24358. return state;
  24359. }
  24360. function encrypt128(input, key) {
  24361. var t, u, v, k;
  24362. var state = new Uint8Array(16);
  24363. state.set(input);
  24364. for (j = 0; j < 16; ++j) {
  24365. // AddRoundKey
  24366. state[j] ^= key[j];
  24367. }
  24368. for (i = 1; i < 10; i++) {
  24369. //SubBytes
  24370. for (j = 0; j < 16; ++j) {
  24371. state[j] = s[state[j]];
  24372. }
  24373. //ShiftRows
  24374. v = state[1];
  24375. state[1] = state[5];
  24376. state[5] = state[9];
  24377. state[9] = state[13];
  24378. state[13] = v;
  24379. v = state[2];
  24380. u = state[6];
  24381. state[2] = state[10];
  24382. state[6] = state[14];
  24383. state[10] = v;
  24384. state[14] = u;
  24385. v = state[3];
  24386. u = state[7];
  24387. t = state[11];
  24388. state[3] = state[15];
  24389. state[7] = v;
  24390. state[11] = u;
  24391. state[15] = t;
  24392. //MixColumns
  24393. for (var j = 0; j < 16; j += 4) {
  24394. var s0 = state[j + 0], s1 = state[j + 1];
  24395. var s2 = state[j + 2], s3 = state[j + 3];
  24396. t = s0 ^ s1 ^ s2 ^ s3;
  24397. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  24398. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  24399. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  24400. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  24401. }
  24402. //AddRoundKey
  24403. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  24404. state[j] ^= key[k];
  24405. }
  24406. }
  24407. //SubBytes
  24408. for (j = 0; j < 16; ++j) {
  24409. state[j] = s[state[j]];
  24410. }
  24411. //ShiftRows
  24412. v = state[1];
  24413. state[1] = state[5];
  24414. state[5] = state[9];
  24415. state[9] = state[13];
  24416. state[13] = v;
  24417. v = state[2];
  24418. u = state[6];
  24419. state[2] = state[10];
  24420. state[6] = state[14];
  24421. state[10] = v;
  24422. state[14] = u;
  24423. v = state[3];
  24424. u = state[7];
  24425. t = state[11];
  24426. state[3] = state[15];
  24427. state[7] = v;
  24428. state[11] = u;
  24429. state[15] = t;
  24430. //AddRoundKey
  24431. for (j = 0, k = 160; j < 16; ++j, ++k) {
  24432. state[j] ^= key[k];
  24433. }
  24434. return state;
  24435. }
  24436. function AES128Cipher(key) {
  24437. this.key = expandKey128(key);
  24438. this.buffer = new Uint8Array(16);
  24439. this.bufferPosition = 0;
  24440. }
  24441. function decryptBlock2(data, finalize) {
  24442. var i, j, ii, sourceLength = data.length,
  24443. buffer = this.buffer, bufferLength = this.bufferPosition,
  24444. result = [], iv = this.iv;
  24445. for (i = 0; i < sourceLength; ++i) {
  24446. buffer[bufferLength] = data[i];
  24447. ++bufferLength;
  24448. if (bufferLength < 16) {
  24449. continue;
  24450. }
  24451. // buffer is full, decrypting
  24452. var plain = decrypt128(buffer, this.key);
  24453. // xor-ing the IV vector to get plain text
  24454. for (j = 0; j < 16; ++j) {
  24455. plain[j] ^= iv[j];
  24456. }
  24457. iv = buffer;
  24458. result.push(plain);
  24459. buffer = new Uint8Array(16);
  24460. bufferLength = 0;
  24461. }
  24462. // saving incomplete buffer
  24463. this.buffer = buffer;
  24464. this.bufferLength = bufferLength;
  24465. this.iv = iv;
  24466. if (result.length === 0) {
  24467. return new Uint8Array([]);
  24468. }
  24469. // combining plain text blocks into one
  24470. var outputLength = 16 * result.length;
  24471. if (finalize) {
  24472. // undo a padding that is described in RFC 2898
  24473. var lastBlock = result[result.length - 1];
  24474. var psLen = lastBlock[15];
  24475. if (psLen <= 16) {
  24476. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  24477. if (lastBlock[i] !== psLen) {
  24478. // Invalid padding, assume that the block has no padding.
  24479. psLen = 0;
  24480. break;
  24481. }
  24482. }
  24483. outputLength -= psLen;
  24484. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  24485. }
  24486. }
  24487. var output = new Uint8Array(outputLength);
  24488. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  24489. output.set(result[i], j);
  24490. }
  24491. return output;
  24492. }
  24493. AES128Cipher.prototype = {
  24494. decryptBlock: function AES128Cipher_decryptBlock(data, finalize) {
  24495. var i, sourceLength = data.length;
  24496. var buffer = this.buffer, bufferLength = this.bufferPosition;
  24497. // waiting for IV values -- they are at the start of the stream
  24498. for (i = 0; bufferLength < 16 && i < sourceLength; ++i, ++bufferLength) {
  24499. buffer[bufferLength] = data[i];
  24500. }
  24501. if (bufferLength < 16) {
  24502. // need more data
  24503. this.bufferLength = bufferLength;
  24504. return new Uint8Array([]);
  24505. }
  24506. this.iv = buffer;
  24507. this.buffer = new Uint8Array(16);
  24508. this.bufferLength = 0;
  24509. // starting decryption
  24510. this.decryptBlock = decryptBlock2;
  24511. return this.decryptBlock(data.subarray(16), finalize);
  24512. },
  24513. encrypt: function AES128Cipher_encrypt(data, iv) {
  24514. var i, j, ii, sourceLength = data.length,
  24515. buffer = this.buffer, bufferLength = this.bufferPosition,
  24516. result = [];
  24517. if (!iv) {
  24518. iv = new Uint8Array(16);
  24519. }
  24520. for (i = 0; i < sourceLength; ++i) {
  24521. buffer[bufferLength] = data[i];
  24522. ++bufferLength;
  24523. if (bufferLength < 16) {
  24524. continue;
  24525. }
  24526. for (j = 0; j < 16; ++j) {
  24527. buffer[j] ^= iv[j];
  24528. }
  24529. // buffer is full, encrypting
  24530. var cipher = encrypt128(buffer, this.key);
  24531. iv = cipher;
  24532. result.push(cipher);
  24533. buffer = new Uint8Array(16);
  24534. bufferLength = 0;
  24535. }
  24536. // saving incomplete buffer
  24537. this.buffer = buffer;
  24538. this.bufferLength = bufferLength;
  24539. this.iv = iv;
  24540. if (result.length === 0) {
  24541. return new Uint8Array([]);
  24542. }
  24543. // combining plain text blocks into one
  24544. var outputLength = 16 * result.length;
  24545. var output = new Uint8Array(outputLength);
  24546. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  24547. output.set(result[i], j);
  24548. }
  24549. return output;
  24550. }
  24551. };
  24552. return AES128Cipher;
  24553. })();
  24554. var AES256Cipher = (function AES256CipherClosure() {
  24555. var rcon = new Uint8Array([
  24556. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  24557. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  24558. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  24559. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  24560. 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  24561. 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
  24562. 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
  24563. 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
  24564. 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
  24565. 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
  24566. 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
  24567. 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
  24568. 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
  24569. 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
  24570. 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
  24571. 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
  24572. 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
  24573. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  24574. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  24575. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  24576. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  24577. 0x74, 0xe8, 0xcb, 0x8d]);
  24578. var s = new Uint8Array([
  24579. 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
  24580. 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
  24581. 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
  24582. 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
  24583. 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
  24584. 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
  24585. 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
  24586. 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
  24587. 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
  24588. 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
  24589. 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
  24590. 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
  24591. 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
  24592. 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
  24593. 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
  24594. 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
  24595. 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
  24596. 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
  24597. 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
  24598. 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
  24599. 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
  24600. 0xb0, 0x54, 0xbb, 0x16]);
  24601. var inv_s = new Uint8Array([
  24602. 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
  24603. 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
  24604. 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
  24605. 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
  24606. 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
  24607. 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
  24608. 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
  24609. 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
  24610. 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
  24611. 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
  24612. 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
  24613. 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
  24614. 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
  24615. 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
  24616. 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
  24617. 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
  24618. 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
  24619. 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
  24620. 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
  24621. 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
  24622. 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
  24623. 0x55, 0x21, 0x0c, 0x7d]);
  24624. var mixCol = new Uint8Array(256);
  24625. for (var i = 0; i < 256; i++) {
  24626. if (i < 128) {
  24627. mixCol[i] = i << 1;
  24628. } else {
  24629. mixCol[i] = (i << 1) ^ 0x1b;
  24630. }
  24631. }
  24632. var mix = new Uint32Array([
  24633. 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
  24634. 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
  24635. 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
  24636. 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
  24637. 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
  24638. 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
  24639. 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
  24640. 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
  24641. 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
  24642. 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
  24643. 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
  24644. 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
  24645. 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
  24646. 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
  24647. 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
  24648. 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
  24649. 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
  24650. 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
  24651. 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
  24652. 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
  24653. 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
  24654. 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
  24655. 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
  24656. 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
  24657. 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
  24658. 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
  24659. 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
  24660. 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
  24661. 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
  24662. 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
  24663. 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
  24664. 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
  24665. 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
  24666. 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
  24667. 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
  24668. 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
  24669. 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
  24670. 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
  24671. 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
  24672. 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
  24673. 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
  24674. 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
  24675. 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
  24676. function expandKey256(cipherKey) {
  24677. var b = 240, result = new Uint8Array(b);
  24678. var r = 1;
  24679. result.set(cipherKey);
  24680. for (var j = 32, i = 1; j < b; ++i) {
  24681. if (j % 32 === 16) {
  24682. t1 = s[t1];
  24683. t2 = s[t2];
  24684. t3 = s[t3];
  24685. t4 = s[t4];
  24686. } else if (j % 32 === 0) {
  24687. // RotWord
  24688. var t1 = result[j - 3], t2 = result[j - 2],
  24689. t3 = result[j - 1], t4 = result[j - 4];
  24690. // SubWord
  24691. t1 = s[t1];
  24692. t2 = s[t2];
  24693. t3 = s[t3];
  24694. t4 = s[t4];
  24695. // Rcon
  24696. t1 = t1 ^ r;
  24697. if ((r <<= 1) >= 256) {
  24698. r = (r ^ 0x1b) & 0xFF;
  24699. }
  24700. }
  24701. for (var n = 0; n < 4; ++n) {
  24702. result[j] = (t1 ^= result[j - 32]);
  24703. j++;
  24704. result[j] = (t2 ^= result[j - 32]);
  24705. j++;
  24706. result[j] = (t3 ^= result[j - 32]);
  24707. j++;
  24708. result[j] = (t4 ^= result[j - 32]);
  24709. j++;
  24710. }
  24711. }
  24712. return result;
  24713. }
  24714. function decrypt256(input, key) {
  24715. var state = new Uint8Array(16);
  24716. state.set(input);
  24717. var i, j, k;
  24718. var t, u, v;
  24719. // AddRoundKey
  24720. for (j = 0, k = 224; j < 16; ++j, ++k) {
  24721. state[j] ^= key[k];
  24722. }
  24723. for (i = 13; i >= 1; --i) {
  24724. // InvShiftRows
  24725. t = state[13];
  24726. state[13] = state[9];
  24727. state[9] = state[5];
  24728. state[5] = state[1];
  24729. state[1] = t;
  24730. t = state[14];
  24731. u = state[10];
  24732. state[14] = state[6];
  24733. state[10] = state[2];
  24734. state[6] = t;
  24735. state[2] = u;
  24736. t = state[15];
  24737. u = state[11];
  24738. v = state[7];
  24739. state[15] = state[3];
  24740. state[11] = t;
  24741. state[7] = u;
  24742. state[3] = v;
  24743. // InvSubBytes
  24744. for (j = 0; j < 16; ++j) {
  24745. state[j] = inv_s[state[j]];
  24746. }
  24747. // AddRoundKey
  24748. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  24749. state[j] ^= key[k];
  24750. }
  24751. // InvMixColumns
  24752. for (j = 0; j < 16; j += 4) {
  24753. var s0 = mix[state[j]], s1 = mix[state[j + 1]],
  24754. s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  24755. t = (s0 ^ (s1 >>> 8) ^ (s1 << 24) ^ (s2 >>> 16) ^ (s2 << 16) ^
  24756. (s3 >>> 24) ^ (s3 << 8));
  24757. state[j] = (t >>> 24) & 0xFF;
  24758. state[j + 1] = (t >> 16) & 0xFF;
  24759. state[j + 2] = (t >> 8) & 0xFF;
  24760. state[j + 3] = t & 0xFF;
  24761. }
  24762. }
  24763. // InvShiftRows
  24764. t = state[13];
  24765. state[13] = state[9];
  24766. state[9] = state[5];
  24767. state[5] = state[1];
  24768. state[1] = t;
  24769. t = state[14];
  24770. u = state[10];
  24771. state[14] = state[6];
  24772. state[10] = state[2];
  24773. state[6] = t;
  24774. state[2] = u;
  24775. t = state[15];
  24776. u = state[11];
  24777. v = state[7];
  24778. state[15] = state[3];
  24779. state[11] = t;
  24780. state[7] = u;
  24781. state[3] = v;
  24782. for (j = 0; j < 16; ++j) {
  24783. // InvSubBytes
  24784. state[j] = inv_s[state[j]];
  24785. // AddRoundKey
  24786. state[j] ^= key[j];
  24787. }
  24788. return state;
  24789. }
  24790. function encrypt256(input, key) {
  24791. var t, u, v, k;
  24792. var state = new Uint8Array(16);
  24793. state.set(input);
  24794. for (j = 0; j < 16; ++j) {
  24795. // AddRoundKey
  24796. state[j] ^= key[j];
  24797. }
  24798. for (i = 1; i < 14; i++) {
  24799. //SubBytes
  24800. for (j = 0; j < 16; ++j) {
  24801. state[j] = s[state[j]];
  24802. }
  24803. //ShiftRows
  24804. v = state[1];
  24805. state[1] = state[5];
  24806. state[5] = state[9];
  24807. state[9] = state[13];
  24808. state[13] = v;
  24809. v = state[2];
  24810. u = state[6];
  24811. state[2] = state[10];
  24812. state[6] = state[14];
  24813. state[10] = v;
  24814. state[14] = u;
  24815. v = state[3];
  24816. u = state[7];
  24817. t = state[11];
  24818. state[3] = state[15];
  24819. state[7] = v;
  24820. state[11] = u;
  24821. state[15] = t;
  24822. //MixColumns
  24823. for (var j = 0; j < 16; j += 4) {
  24824. var s0 = state[j + 0], s1 = state[j + 1];
  24825. var s2 = state[j + 2], s3 = state[j + 3];
  24826. t = s0 ^ s1 ^ s2 ^ s3;
  24827. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  24828. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  24829. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  24830. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  24831. }
  24832. //AddRoundKey
  24833. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  24834. state[j] ^= key[k];
  24835. }
  24836. }
  24837. //SubBytes
  24838. for (j = 0; j < 16; ++j) {
  24839. state[j] = s[state[j]];
  24840. }
  24841. //ShiftRows
  24842. v = state[1];
  24843. state[1] = state[5];
  24844. state[5] = state[9];
  24845. state[9] = state[13];
  24846. state[13] = v;
  24847. v = state[2];
  24848. u = state[6];
  24849. state[2] = state[10];
  24850. state[6] = state[14];
  24851. state[10] = v;
  24852. state[14] = u;
  24853. v = state[3];
  24854. u = state[7];
  24855. t = state[11];
  24856. state[3] = state[15];
  24857. state[7] = v;
  24858. state[11] = u;
  24859. state[15] = t;
  24860. //AddRoundKey
  24861. for (j = 0, k = 224; j < 16; ++j, ++k) {
  24862. state[j] ^= key[k];
  24863. }
  24864. return state;
  24865. }
  24866. function AES256Cipher(key) {
  24867. this.key = expandKey256(key);
  24868. this.buffer = new Uint8Array(16);
  24869. this.bufferPosition = 0;
  24870. }
  24871. function decryptBlock2(data, finalize) {
  24872. var i, j, ii, sourceLength = data.length,
  24873. buffer = this.buffer, bufferLength = this.bufferPosition,
  24874. result = [], iv = this.iv;
  24875. for (i = 0; i < sourceLength; ++i) {
  24876. buffer[bufferLength] = data[i];
  24877. ++bufferLength;
  24878. if (bufferLength < 16) {
  24879. continue;
  24880. }
  24881. // buffer is full, decrypting
  24882. var plain = decrypt256(buffer, this.key);
  24883. // xor-ing the IV vector to get plain text
  24884. for (j = 0; j < 16; ++j) {
  24885. plain[j] ^= iv[j];
  24886. }
  24887. iv = buffer;
  24888. result.push(plain);
  24889. buffer = new Uint8Array(16);
  24890. bufferLength = 0;
  24891. }
  24892. // saving incomplete buffer
  24893. this.buffer = buffer;
  24894. this.bufferLength = bufferLength;
  24895. this.iv = iv;
  24896. if (result.length === 0) {
  24897. return new Uint8Array([]);
  24898. }
  24899. // combining plain text blocks into one
  24900. var outputLength = 16 * result.length;
  24901. if (finalize) {
  24902. // undo a padding that is described in RFC 2898
  24903. var lastBlock = result[result.length - 1];
  24904. var psLen = lastBlock[15];
  24905. if (psLen <= 16) {
  24906. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  24907. if (lastBlock[i] !== psLen) {
  24908. // Invalid padding, assume that the block has no padding.
  24909. psLen = 0;
  24910. break;
  24911. }
  24912. }
  24913. outputLength -= psLen;
  24914. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  24915. }
  24916. }
  24917. var output = new Uint8Array(outputLength);
  24918. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  24919. output.set(result[i], j);
  24920. }
  24921. return output;
  24922. }
  24923. AES256Cipher.prototype = {
  24924. decryptBlock: function AES256Cipher_decryptBlock(data, finalize, iv) {
  24925. var i, sourceLength = data.length;
  24926. var buffer = this.buffer, bufferLength = this.bufferPosition;
  24927. // if not supplied an IV wait for IV values
  24928. // they are at the start of the stream
  24929. if (iv) {
  24930. this.iv = iv;
  24931. } else {
  24932. for (i = 0; bufferLength < 16 &&
  24933. i < sourceLength; ++i, ++bufferLength) {
  24934. buffer[bufferLength] = data[i];
  24935. }
  24936. if (bufferLength < 16) {
  24937. //need more data
  24938. this.bufferLength = bufferLength;
  24939. return new Uint8Array([]);
  24940. }
  24941. this.iv = buffer;
  24942. data = data.subarray(16);
  24943. }
  24944. this.buffer = new Uint8Array(16);
  24945. this.bufferLength = 0;
  24946. // starting decryption
  24947. this.decryptBlock = decryptBlock2;
  24948. return this.decryptBlock(data, finalize);
  24949. },
  24950. encrypt: function AES256Cipher_encrypt(data, iv) {
  24951. var i, j, ii, sourceLength = data.length,
  24952. buffer = this.buffer, bufferLength = this.bufferPosition,
  24953. result = [];
  24954. if (!iv) {
  24955. iv = new Uint8Array(16);
  24956. }
  24957. for (i = 0; i < sourceLength; ++i) {
  24958. buffer[bufferLength] = data[i];
  24959. ++bufferLength;
  24960. if (bufferLength < 16) {
  24961. continue;
  24962. }
  24963. for (j = 0; j < 16; ++j) {
  24964. buffer[j] ^= iv[j];
  24965. }
  24966. // buffer is full, encrypting
  24967. var cipher = encrypt256(buffer, this.key);
  24968. this.iv = cipher;
  24969. result.push(cipher);
  24970. buffer = new Uint8Array(16);
  24971. bufferLength = 0;
  24972. }
  24973. // saving incomplete buffer
  24974. this.buffer = buffer;
  24975. this.bufferLength = bufferLength;
  24976. this.iv = iv;
  24977. if (result.length === 0) {
  24978. return new Uint8Array([]);
  24979. }
  24980. // combining plain text blocks into one
  24981. var outputLength = 16 * result.length;
  24982. var output = new Uint8Array(outputLength);
  24983. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  24984. output.set(result[i], j);
  24985. }
  24986. return output;
  24987. }
  24988. };
  24989. return AES256Cipher;
  24990. })();
  24991. var PDF17 = (function PDF17Closure() {
  24992. function compareByteArrays(array1, array2) {
  24993. if (array1.length !== array2.length) {
  24994. return false;
  24995. }
  24996. for (var i = 0; i < array1.length; i++) {
  24997. if (array1[i] !== array2[i]) {
  24998. return false;
  24999. }
  25000. }
  25001. return true;
  25002. }
  25003. function PDF17() {
  25004. }
  25005. PDF17.prototype = {
  25006. checkOwnerPassword: function PDF17_checkOwnerPassword(password,
  25007. ownerValidationSalt,
  25008. userBytes,
  25009. ownerPassword) {
  25010. var hashData = new Uint8Array(password.length + 56);
  25011. hashData.set(password, 0);
  25012. hashData.set(ownerValidationSalt, password.length);
  25013. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  25014. var result = calculateSHA256(hashData, 0, hashData.length);
  25015. return compareByteArrays(result, ownerPassword);
  25016. },
  25017. checkUserPassword: function PDF17_checkUserPassword(password,
  25018. userValidationSalt,
  25019. userPassword) {
  25020. var hashData = new Uint8Array(password.length + 8);
  25021. hashData.set(password, 0);
  25022. hashData.set(userValidationSalt, password.length);
  25023. var result = calculateSHA256(hashData, 0, hashData.length);
  25024. return compareByteArrays(result, userPassword);
  25025. },
  25026. getOwnerKey: function PDF17_getOwnerKey(password, ownerKeySalt, userBytes,
  25027. ownerEncryption) {
  25028. var hashData = new Uint8Array(password.length + 56);
  25029. hashData.set(password, 0);
  25030. hashData.set(ownerKeySalt, password.length);
  25031. hashData.set(userBytes, password.length + ownerKeySalt.length);
  25032. var key = calculateSHA256(hashData, 0, hashData.length);
  25033. var cipher = new AES256Cipher(key);
  25034. return cipher.decryptBlock(ownerEncryption,
  25035. false,
  25036. new Uint8Array(16));
  25037. },
  25038. getUserKey: function PDF17_getUserKey(password, userKeySalt,
  25039. userEncryption) {
  25040. var hashData = new Uint8Array(password.length + 8);
  25041. hashData.set(password, 0);
  25042. hashData.set(userKeySalt, password.length);
  25043. //key is the decryption key for the UE string
  25044. var key = calculateSHA256(hashData, 0, hashData.length);
  25045. var cipher = new AES256Cipher(key);
  25046. return cipher.decryptBlock(userEncryption,
  25047. false,
  25048. new Uint8Array(16));
  25049. }
  25050. };
  25051. return PDF17;
  25052. })();
  25053. var PDF20 = (function PDF20Closure() {
  25054. function concatArrays(array1, array2) {
  25055. var t = new Uint8Array(array1.length + array2.length);
  25056. t.set(array1, 0);
  25057. t.set(array2, array1.length);
  25058. return t;
  25059. }
  25060. function calculatePDF20Hash(password, input, userBytes) {
  25061. //This refers to Algorithm 2.B as defined in ISO 32000-2
  25062. var k = calculateSHA256(input, 0, input.length).subarray(0, 32);
  25063. var e = [0];
  25064. var i = 0;
  25065. while (i < 64 || e[e.length - 1] > i - 32) {
  25066. var arrayLength = password.length + k.length + userBytes.length;
  25067. var k1 = new Uint8Array(arrayLength * 64);
  25068. var array = concatArrays(password, k);
  25069. array = concatArrays(array, userBytes);
  25070. for (var j = 0, pos = 0; j < 64; j++, pos += arrayLength) {
  25071. k1.set(array, pos);
  25072. }
  25073. //AES128 CBC NO PADDING with
  25074. //first 16 bytes of k as the key and the second 16 as the iv.
  25075. var cipher = new AES128Cipher(k.subarray(0, 16));
  25076. e = cipher.encrypt(k1, k.subarray(16, 32));
  25077. //Now we have to take the first 16 bytes of an unsigned
  25078. //big endian integer... and compute the remainder
  25079. //modulo 3.... That is a fairly large number and
  25080. //JavaScript isn't going to handle that well...
  25081. //So we're using a trick that allows us to perform
  25082. //modulo math byte by byte
  25083. var remainder = 0;
  25084. for (var z = 0; z < 16; z++) {
  25085. remainder *= (256 % 3);
  25086. remainder %= 3;
  25087. remainder += ((e[z] >>> 0) % 3);
  25088. remainder %= 3;
  25089. }
  25090. if (remainder === 0) {
  25091. k = calculateSHA256(e, 0, e.length);
  25092. }
  25093. else if (remainder === 1) {
  25094. k = calculateSHA384(e, 0, e.length);
  25095. }
  25096. else if (remainder === 2) {
  25097. k = calculateSHA512(e, 0, e.length);
  25098. }
  25099. i++;
  25100. }
  25101. return k.subarray(0, 32);
  25102. }
  25103. function PDF20() {
  25104. }
  25105. function compareByteArrays(array1, array2) {
  25106. if (array1.length !== array2.length) {
  25107. return false;
  25108. }
  25109. for (var i = 0; i < array1.length; i++) {
  25110. if (array1[i] !== array2[i]) {
  25111. return false;
  25112. }
  25113. }
  25114. return true;
  25115. }
  25116. PDF20.prototype = {
  25117. hash: function PDF20_hash(password, concatBytes, userBytes) {
  25118. return calculatePDF20Hash(password, concatBytes, userBytes);
  25119. },
  25120. checkOwnerPassword: function PDF20_checkOwnerPassword(password,
  25121. ownerValidationSalt,
  25122. userBytes,
  25123. ownerPassword) {
  25124. var hashData = new Uint8Array(password.length + 56);
  25125. hashData.set(password, 0);
  25126. hashData.set(ownerValidationSalt, password.length);
  25127. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  25128. var result = calculatePDF20Hash(password, hashData, userBytes);
  25129. return compareByteArrays(result, ownerPassword);
  25130. },
  25131. checkUserPassword: function PDF20_checkUserPassword(password,
  25132. userValidationSalt,
  25133. userPassword) {
  25134. var hashData = new Uint8Array(password.length + 8);
  25135. hashData.set(password, 0);
  25136. hashData.set(userValidationSalt, password.length);
  25137. var result = calculatePDF20Hash(password, hashData, []);
  25138. return compareByteArrays(result, userPassword);
  25139. },
  25140. getOwnerKey: function PDF20_getOwnerKey(password, ownerKeySalt, userBytes,
  25141. ownerEncryption) {
  25142. var hashData = new Uint8Array(password.length + 56);
  25143. hashData.set(password, 0);
  25144. hashData.set(ownerKeySalt, password.length);
  25145. hashData.set(userBytes, password.length + ownerKeySalt.length);
  25146. var key = calculatePDF20Hash(password, hashData, userBytes);
  25147. var cipher = new AES256Cipher(key);
  25148. return cipher.decryptBlock(ownerEncryption,
  25149. false,
  25150. new Uint8Array(16));
  25151. },
  25152. getUserKey: function PDF20_getUserKey(password, userKeySalt,
  25153. userEncryption) {
  25154. var hashData = new Uint8Array(password.length + 8);
  25155. hashData.set(password, 0);
  25156. hashData.set(userKeySalt, password.length);
  25157. //key is the decryption key for the UE string
  25158. var key = calculatePDF20Hash(password, hashData, []);
  25159. var cipher = new AES256Cipher(key);
  25160. return cipher.decryptBlock(userEncryption,
  25161. false,
  25162. new Uint8Array(16));
  25163. }
  25164. };
  25165. return PDF20;
  25166. })();
  25167. var CipherTransform = (function CipherTransformClosure() {
  25168. function CipherTransform(stringCipherConstructor, streamCipherConstructor) {
  25169. this.stringCipherConstructor = stringCipherConstructor;
  25170. this.streamCipherConstructor = streamCipherConstructor;
  25171. }
  25172. CipherTransform.prototype = {
  25173. createStream: function CipherTransform_createStream(stream, length) {
  25174. var cipher = new this.streamCipherConstructor();
  25175. return new DecryptStream(stream, length,
  25176. function cipherTransformDecryptStream(data, finalize) {
  25177. return cipher.decryptBlock(data, finalize);
  25178. }
  25179. );
  25180. },
  25181. decryptString: function CipherTransform_decryptString(s) {
  25182. var cipher = new this.stringCipherConstructor();
  25183. var data = stringToBytes(s);
  25184. data = cipher.decryptBlock(data, true);
  25185. return bytesToString(data);
  25186. }
  25187. };
  25188. return CipherTransform;
  25189. })();
  25190. var CipherTransformFactory = (function CipherTransformFactoryClosure() {
  25191. var defaultPasswordBytes = new Uint8Array([
  25192. 0x28, 0xBF, 0x4E, 0x5E, 0x4E, 0x75, 0x8A, 0x41,
  25193. 0x64, 0x00, 0x4E, 0x56, 0xFF, 0xFA, 0x01, 0x08,
  25194. 0x2E, 0x2E, 0x00, 0xB6, 0xD0, 0x68, 0x3E, 0x80,
  25195. 0x2F, 0x0C, 0xA9, 0xFE, 0x64, 0x53, 0x69, 0x7A]);
  25196. function createEncryptionKey20(revision, password, ownerPassword,
  25197. ownerValidationSalt, ownerKeySalt, uBytes,
  25198. userPassword, userValidationSalt, userKeySalt,
  25199. ownerEncryption, userEncryption, perms) {
  25200. if (password) {
  25201. var passwordLength = Math.min(127, password.length);
  25202. password = password.subarray(0, passwordLength);
  25203. } else {
  25204. password = [];
  25205. }
  25206. var pdfAlgorithm;
  25207. if (revision === 6) {
  25208. pdfAlgorithm = new PDF20();
  25209. } else {
  25210. pdfAlgorithm = new PDF17();
  25211. }
  25212. if (pdfAlgorithm) {
  25213. if (pdfAlgorithm.checkUserPassword(password, userValidationSalt,
  25214. userPassword)) {
  25215. return pdfAlgorithm.getUserKey(password, userKeySalt, userEncryption);
  25216. } else if (password.length && pdfAlgorithm.checkOwnerPassword(password,
  25217. ownerValidationSalt,
  25218. uBytes,
  25219. ownerPassword)) {
  25220. return pdfAlgorithm.getOwnerKey(password, ownerKeySalt, uBytes,
  25221. ownerEncryption);
  25222. }
  25223. }
  25224. return null;
  25225. }
  25226. function prepareKeyData(fileId, password, ownerPassword, userPassword,
  25227. flags, revision, keyLength, encryptMetadata) {
  25228. var hashDataSize = 40 + ownerPassword.length + fileId.length;
  25229. var hashData = new Uint8Array(hashDataSize), i = 0, j, n;
  25230. if (password) {
  25231. n = Math.min(32, password.length);
  25232. for (; i < n; ++i) {
  25233. hashData[i] = password[i];
  25234. }
  25235. }
  25236. j = 0;
  25237. while (i < 32) {
  25238. hashData[i++] = defaultPasswordBytes[j++];
  25239. }
  25240. // as now the padded password in the hashData[0..i]
  25241. for (j = 0, n = ownerPassword.length; j < n; ++j) {
  25242. hashData[i++] = ownerPassword[j];
  25243. }
  25244. hashData[i++] = flags & 0xFF;
  25245. hashData[i++] = (flags >> 8) & 0xFF;
  25246. hashData[i++] = (flags >> 16) & 0xFF;
  25247. hashData[i++] = (flags >>> 24) & 0xFF;
  25248. for (j = 0, n = fileId.length; j < n; ++j) {
  25249. hashData[i++] = fileId[j];
  25250. }
  25251. if (revision >= 4 && !encryptMetadata) {
  25252. hashData[i++] = 0xFF;
  25253. hashData[i++] = 0xFF;
  25254. hashData[i++] = 0xFF;
  25255. hashData[i++] = 0xFF;
  25256. }
  25257. var hash = calculateMD5(hashData, 0, i);
  25258. var keyLengthInBytes = keyLength >> 3;
  25259. if (revision >= 3) {
  25260. for (j = 0; j < 50; ++j) {
  25261. hash = calculateMD5(hash, 0, keyLengthInBytes);
  25262. }
  25263. }
  25264. var encryptionKey = hash.subarray(0, keyLengthInBytes);
  25265. var cipher, checkData;
  25266. if (revision >= 3) {
  25267. for (i = 0; i < 32; ++i) {
  25268. hashData[i] = defaultPasswordBytes[i];
  25269. }
  25270. for (j = 0, n = fileId.length; j < n; ++j) {
  25271. hashData[i++] = fileId[j];
  25272. }
  25273. cipher = new ARCFourCipher(encryptionKey);
  25274. checkData = cipher.encryptBlock(calculateMD5(hashData, 0, i));
  25275. n = encryptionKey.length;
  25276. var derivedKey = new Uint8Array(n), k;
  25277. for (j = 1; j <= 19; ++j) {
  25278. for (k = 0; k < n; ++k) {
  25279. derivedKey[k] = encryptionKey[k] ^ j;
  25280. }
  25281. cipher = new ARCFourCipher(derivedKey);
  25282. checkData = cipher.encryptBlock(checkData);
  25283. }
  25284. for (j = 0, n = checkData.length; j < n; ++j) {
  25285. if (userPassword[j] !== checkData[j]) {
  25286. return null;
  25287. }
  25288. }
  25289. } else {
  25290. cipher = new ARCFourCipher(encryptionKey);
  25291. checkData = cipher.encryptBlock(defaultPasswordBytes);
  25292. for (j = 0, n = checkData.length; j < n; ++j) {
  25293. if (userPassword[j] !== checkData[j]) {
  25294. return null;
  25295. }
  25296. }
  25297. }
  25298. return encryptionKey;
  25299. }
  25300. function decodeUserPassword(password, ownerPassword, revision, keyLength) {
  25301. var hashData = new Uint8Array(32), i = 0, j, n;
  25302. n = Math.min(32, password.length);
  25303. for (; i < n; ++i) {
  25304. hashData[i] = password[i];
  25305. }
  25306. j = 0;
  25307. while (i < 32) {
  25308. hashData[i++] = defaultPasswordBytes[j++];
  25309. }
  25310. var hash = calculateMD5(hashData, 0, i);
  25311. var keyLengthInBytes = keyLength >> 3;
  25312. if (revision >= 3) {
  25313. for (j = 0; j < 50; ++j) {
  25314. hash = calculateMD5(hash, 0, hash.length);
  25315. }
  25316. }
  25317. var cipher, userPassword;
  25318. if (revision >= 3) {
  25319. userPassword = ownerPassword;
  25320. var derivedKey = new Uint8Array(keyLengthInBytes), k;
  25321. for (j = 19; j >= 0; j--) {
  25322. for (k = 0; k < keyLengthInBytes; ++k) {
  25323. derivedKey[k] = hash[k] ^ j;
  25324. }
  25325. cipher = new ARCFourCipher(derivedKey);
  25326. userPassword = cipher.encryptBlock(userPassword);
  25327. }
  25328. } else {
  25329. cipher = new ARCFourCipher(hash.subarray(0, keyLengthInBytes));
  25330. userPassword = cipher.encryptBlock(ownerPassword);
  25331. }
  25332. return userPassword;
  25333. }
  25334. var identityName = Name.get('Identity');
  25335. function CipherTransformFactory(dict, fileId, password) {
  25336. var filter = dict.get('Filter');
  25337. if (!isName(filter) || filter.name !== 'Standard') {
  25338. error('unknown encryption method');
  25339. }
  25340. this.dict = dict;
  25341. var algorithm = dict.get('V');
  25342. if (!isInt(algorithm) ||
  25343. (algorithm !== 1 && algorithm !== 2 && algorithm !== 4 &&
  25344. algorithm !== 5)) {
  25345. error('unsupported encryption algorithm');
  25346. }
  25347. this.algorithm = algorithm;
  25348. var keyLength = dict.get('Length') || 40;
  25349. if (!isInt(keyLength) ||
  25350. keyLength < 40 || (keyLength % 8) !== 0) {
  25351. error('invalid key length');
  25352. }
  25353. // prepare keys
  25354. var ownerPassword = stringToBytes(dict.get('O')).subarray(0, 32);
  25355. var userPassword = stringToBytes(dict.get('U')).subarray(0, 32);
  25356. var flags = dict.get('P');
  25357. var revision = dict.get('R');
  25358. // meaningful when V is 4 or 5
  25359. var encryptMetadata = ((algorithm === 4 || algorithm === 5) &&
  25360. dict.get('EncryptMetadata') !== false);
  25361. this.encryptMetadata = encryptMetadata;
  25362. var fileIdBytes = stringToBytes(fileId);
  25363. var passwordBytes;
  25364. if (password) {
  25365. if (revision === 6) {
  25366. try {
  25367. password = utf8StringToString(password);
  25368. } catch (ex) {
  25369. warn('CipherTransformFactory: ' +
  25370. 'Unable to convert UTF8 encoded password.');
  25371. }
  25372. }
  25373. passwordBytes = stringToBytes(password);
  25374. }
  25375. var encryptionKey;
  25376. if (algorithm !== 5) {
  25377. encryptionKey = prepareKeyData(fileIdBytes, passwordBytes,
  25378. ownerPassword, userPassword, flags,
  25379. revision, keyLength, encryptMetadata);
  25380. }
  25381. else {
  25382. var ownerValidationSalt = stringToBytes(dict.get('O')).subarray(32, 40);
  25383. var ownerKeySalt = stringToBytes(dict.get('O')).subarray(40, 48);
  25384. var uBytes = stringToBytes(dict.get('U')).subarray(0, 48);
  25385. var userValidationSalt = stringToBytes(dict.get('U')).subarray(32, 40);
  25386. var userKeySalt = stringToBytes(dict.get('U')).subarray(40, 48);
  25387. var ownerEncryption = stringToBytes(dict.get('OE'));
  25388. var userEncryption = stringToBytes(dict.get('UE'));
  25389. var perms = stringToBytes(dict.get('Perms'));
  25390. encryptionKey =
  25391. createEncryptionKey20(revision, passwordBytes,
  25392. ownerPassword, ownerValidationSalt,
  25393. ownerKeySalt, uBytes,
  25394. userPassword, userValidationSalt,
  25395. userKeySalt, ownerEncryption,
  25396. userEncryption, perms);
  25397. }
  25398. if (!encryptionKey && !password) {
  25399. throw new PasswordException('No password given',
  25400. PasswordResponses.NEED_PASSWORD);
  25401. } else if (!encryptionKey && password) {
  25402. // Attempting use the password as an owner password
  25403. var decodedPassword = decodeUserPassword(passwordBytes, ownerPassword,
  25404. revision, keyLength);
  25405. encryptionKey = prepareKeyData(fileIdBytes, decodedPassword,
  25406. ownerPassword, userPassword, flags,
  25407. revision, keyLength, encryptMetadata);
  25408. }
  25409. if (!encryptionKey) {
  25410. throw new PasswordException('Incorrect Password',
  25411. PasswordResponses.INCORRECT_PASSWORD);
  25412. }
  25413. this.encryptionKey = encryptionKey;
  25414. if (algorithm >= 4) {
  25415. this.cf = dict.get('CF');
  25416. this.stmf = dict.get('StmF') || identityName;
  25417. this.strf = dict.get('StrF') || identityName;
  25418. this.eff = dict.get('EFF') || this.stmf;
  25419. }
  25420. }
  25421. function buildObjectKey(num, gen, encryptionKey, isAes) {
  25422. var key = new Uint8Array(encryptionKey.length + 9), i, n;
  25423. for (i = 0, n = encryptionKey.length; i < n; ++i) {
  25424. key[i] = encryptionKey[i];
  25425. }
  25426. key[i++] = num & 0xFF;
  25427. key[i++] = (num >> 8) & 0xFF;
  25428. key[i++] = (num >> 16) & 0xFF;
  25429. key[i++] = gen & 0xFF;
  25430. key[i++] = (gen >> 8) & 0xFF;
  25431. if (isAes) {
  25432. key[i++] = 0x73;
  25433. key[i++] = 0x41;
  25434. key[i++] = 0x6C;
  25435. key[i++] = 0x54;
  25436. }
  25437. var hash = calculateMD5(key, 0, i);
  25438. return hash.subarray(0, Math.min(encryptionKey.length + 5, 16));
  25439. }
  25440. function buildCipherConstructor(cf, name, num, gen, key) {
  25441. var cryptFilter = cf.get(name.name);
  25442. var cfm;
  25443. if (cryptFilter !== null && cryptFilter !== undefined) {
  25444. cfm = cryptFilter.get('CFM');
  25445. }
  25446. if (!cfm || cfm.name === 'None') {
  25447. return function cipherTransformFactoryBuildCipherConstructorNone() {
  25448. return new NullCipher();
  25449. };
  25450. }
  25451. if ('V2' === cfm.name) {
  25452. return function cipherTransformFactoryBuildCipherConstructorV2() {
  25453. return new ARCFourCipher(buildObjectKey(num, gen, key, false));
  25454. };
  25455. }
  25456. if ('AESV2' === cfm.name) {
  25457. return function cipherTransformFactoryBuildCipherConstructorAESV2() {
  25458. return new AES128Cipher(buildObjectKey(num, gen, key, true));
  25459. };
  25460. }
  25461. if ('AESV3' === cfm.name) {
  25462. return function cipherTransformFactoryBuildCipherConstructorAESV3() {
  25463. return new AES256Cipher(key);
  25464. };
  25465. }
  25466. error('Unknown crypto method');
  25467. }
  25468. CipherTransformFactory.prototype = {
  25469. createCipherTransform:
  25470. function CipherTransformFactory_createCipherTransform(num, gen) {
  25471. if (this.algorithm === 4 || this.algorithm === 5) {
  25472. return new CipherTransform(
  25473. buildCipherConstructor(this.cf, this.stmf,
  25474. num, gen, this.encryptionKey),
  25475. buildCipherConstructor(this.cf, this.strf,
  25476. num, gen, this.encryptionKey));
  25477. }
  25478. // algorithms 1 and 2
  25479. var key = buildObjectKey(num, gen, this.encryptionKey, false);
  25480. var cipherConstructor = function buildCipherCipherConstructor() {
  25481. return new ARCFourCipher(key);
  25482. };
  25483. return new CipherTransform(cipherConstructor, cipherConstructor);
  25484. }
  25485. };
  25486. return CipherTransformFactory;
  25487. })();
  25488. exports.AES128Cipher = AES128Cipher;
  25489. exports.AES256Cipher = AES256Cipher;
  25490. exports.ARCFourCipher = ARCFourCipher;
  25491. exports.CipherTransformFactory = CipherTransformFactory;
  25492. exports.PDF17 = PDF17;
  25493. exports.PDF20 = PDF20;
  25494. exports.calculateMD5 = calculateMD5;
  25495. exports.calculateSHA256 = calculateSHA256;
  25496. exports.calculateSHA384 = calculateSHA384;
  25497. exports.calculateSHA512 = calculateSHA512;
  25498. }));
  25499. (function (root, factory) {
  25500. {
  25501. factory((root.pdfjsCoreFontRenderer = {}), root.pdfjsSharedUtil,
  25502. root.pdfjsCoreStream, root.pdfjsCoreGlyphList);
  25503. }
  25504. }(this, function (exports, sharedUtil, coreStream, coreGlyphList) {
  25505. var Util = sharedUtil.Util;
  25506. var bytesToString = sharedUtil.bytesToString;
  25507. var error = sharedUtil.error;
  25508. var Stream = coreStream.Stream;
  25509. var GlyphsUnicode = coreGlyphList.GlyphsUnicode;
  25510. var coreFonts; // see _setCoreFonts below
  25511. var CFFParser; // = coreFonts.CFFParser;
  25512. var Encodings; // = coreFonts.Encodings;
  25513. var FontRendererFactory = (function FontRendererFactoryClosure() {
  25514. function getLong(data, offset) {
  25515. return (data[offset] << 24) | (data[offset + 1] << 16) |
  25516. (data[offset + 2] << 8) | data[offset + 3];
  25517. }
  25518. function getUshort(data, offset) {
  25519. return (data[offset] << 8) | data[offset + 1];
  25520. }
  25521. function parseCmap(data, start, end) {
  25522. var offset = (getUshort(data, start + 2) === 1 ?
  25523. getLong(data, start + 8) : getLong(data, start + 16));
  25524. var format = getUshort(data, start + offset);
  25525. var length, ranges, p, i;
  25526. if (format === 4) {
  25527. length = getUshort(data, start + offset + 2);
  25528. var segCount = getUshort(data, start + offset + 6) >> 1;
  25529. p = start + offset + 14;
  25530. ranges = [];
  25531. for (i = 0; i < segCount; i++, p += 2) {
  25532. ranges[i] = {end: getUshort(data, p)};
  25533. }
  25534. p += 2;
  25535. for (i = 0; i < segCount; i++, p += 2) {
  25536. ranges[i].start = getUshort(data, p);
  25537. }
  25538. for (i = 0; i < segCount; i++, p += 2) {
  25539. ranges[i].idDelta = getUshort(data, p);
  25540. }
  25541. for (i = 0; i < segCount; i++, p += 2) {
  25542. var idOffset = getUshort(data, p);
  25543. if (idOffset === 0) {
  25544. continue;
  25545. }
  25546. ranges[i].ids = [];
  25547. for (var j = 0, jj = ranges[i].end - ranges[i].start + 1; j < jj; j++) {
  25548. ranges[i].ids[j] = getUshort(data, p + idOffset);
  25549. idOffset += 2;
  25550. }
  25551. }
  25552. return ranges;
  25553. } else if (format === 12) {
  25554. length = getLong(data, start + offset + 4);
  25555. var groups = getLong(data, start + offset + 12);
  25556. p = start + offset + 16;
  25557. ranges = [];
  25558. for (i = 0; i < groups; i++) {
  25559. ranges.push({
  25560. start: getLong(data, p),
  25561. end: getLong(data, p + 4),
  25562. idDelta: getLong(data, p + 8) - getLong(data, p)
  25563. });
  25564. p += 12;
  25565. }
  25566. return ranges;
  25567. }
  25568. error('not supported cmap: ' + format);
  25569. }
  25570. function parseCff(data, start, end) {
  25571. var properties = {};
  25572. var parser = new CFFParser(new Stream(data, start, end - start),
  25573. properties);
  25574. var cff = parser.parse();
  25575. return {
  25576. glyphs: cff.charStrings.objects,
  25577. subrs: (cff.topDict.privateDict && cff.topDict.privateDict.subrsIndex &&
  25578. cff.topDict.privateDict.subrsIndex.objects),
  25579. gsubrs: cff.globalSubrIndex && cff.globalSubrIndex.objects
  25580. };
  25581. }
  25582. function parseGlyfTable(glyf, loca, isGlyphLocationsLong) {
  25583. var itemSize, itemDecode;
  25584. if (isGlyphLocationsLong) {
  25585. itemSize = 4;
  25586. itemDecode = function fontItemDecodeLong(data, offset) {
  25587. return (data[offset] << 24) | (data[offset + 1] << 16) |
  25588. (data[offset + 2] << 8) | data[offset + 3];
  25589. };
  25590. } else {
  25591. itemSize = 2;
  25592. itemDecode = function fontItemDecode(data, offset) {
  25593. return (data[offset] << 9) | (data[offset + 1] << 1);
  25594. };
  25595. }
  25596. var glyphs = [];
  25597. var startOffset = itemDecode(loca, 0);
  25598. for (var j = itemSize; j < loca.length; j += itemSize) {
  25599. var endOffset = itemDecode(loca, j);
  25600. glyphs.push(glyf.subarray(startOffset, endOffset));
  25601. startOffset = endOffset;
  25602. }
  25603. return glyphs;
  25604. }
  25605. function lookupCmap(ranges, unicode) {
  25606. var code = unicode.charCodeAt(0);
  25607. var l = 0, r = ranges.length - 1;
  25608. while (l < r) {
  25609. var c = (l + r + 1) >> 1;
  25610. if (code < ranges[c].start) {
  25611. r = c - 1;
  25612. } else {
  25613. l = c;
  25614. }
  25615. }
  25616. if (ranges[l].start <= code && code <= ranges[l].end) {
  25617. return (ranges[l].idDelta + (ranges[l].ids ?
  25618. ranges[l].ids[code - ranges[l].start] : code)) & 0xFFFF;
  25619. }
  25620. return 0;
  25621. }
  25622. function compileGlyf(code, cmds, font) {
  25623. function moveTo(x, y) {
  25624. cmds.push({cmd: 'moveTo', args: [x, y]});
  25625. }
  25626. function lineTo(x, y) {
  25627. cmds.push({cmd: 'lineTo', args: [x, y]});
  25628. }
  25629. function quadraticCurveTo(xa, ya, x, y) {
  25630. cmds.push({cmd: 'quadraticCurveTo', args: [xa, ya, x, y]});
  25631. }
  25632. var i = 0;
  25633. var numberOfContours = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  25634. var flags;
  25635. var x = 0, y = 0;
  25636. i += 10;
  25637. if (numberOfContours < 0) {
  25638. // composite glyph
  25639. do {
  25640. flags = (code[i] << 8) | code[i + 1];
  25641. var glyphIndex = (code[i + 2] << 8) | code[i + 3];
  25642. i += 4;
  25643. var arg1, arg2;
  25644. if ((flags & 0x01)) {
  25645. arg1 = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  25646. arg2 = ((code[i + 2] << 24) | (code[i + 3] << 16)) >> 16;
  25647. i += 4;
  25648. } else {
  25649. arg1 = code[i++]; arg2 = code[i++];
  25650. }
  25651. if ((flags & 0x02)) {
  25652. x = arg1;
  25653. y = arg2;
  25654. } else {
  25655. x = 0; y = 0; // TODO "they are points" ?
  25656. }
  25657. var scaleX = 1, scaleY = 1, scale01 = 0, scale10 = 0;
  25658. if ((flags & 0x08)) {
  25659. scaleX =
  25660. scaleY = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  25661. i += 2;
  25662. } else if ((flags & 0x40)) {
  25663. scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  25664. scaleY = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
  25665. i += 4;
  25666. } else if ((flags & 0x80)) {
  25667. scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  25668. scale01 = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
  25669. scale10 = ((code[i + 4] << 24) | (code[i + 5] << 16)) / 1073741824;
  25670. scaleY = ((code[i + 6] << 24) | (code[i + 7] << 16)) / 1073741824;
  25671. i += 8;
  25672. }
  25673. var subglyph = font.glyphs[glyphIndex];
  25674. if (subglyph) {
  25675. cmds.push({cmd: 'save'});
  25676. cmds.push({cmd: 'transform',
  25677. args: [scaleX, scale01, scale10, scaleY, x, y]});
  25678. compileGlyf(subglyph, cmds, font);
  25679. cmds.push({cmd: 'restore'});
  25680. }
  25681. } while ((flags & 0x20));
  25682. } else {
  25683. // simple glyph
  25684. var endPtsOfContours = [];
  25685. var j, jj;
  25686. for (j = 0; j < numberOfContours; j++) {
  25687. endPtsOfContours.push((code[i] << 8) | code[i + 1]);
  25688. i += 2;
  25689. }
  25690. var instructionLength = (code[i] << 8) | code[i + 1];
  25691. i += 2 + instructionLength; // skipping the instructions
  25692. var numberOfPoints = endPtsOfContours[endPtsOfContours.length - 1] + 1;
  25693. var points = [];
  25694. while (points.length < numberOfPoints) {
  25695. flags = code[i++];
  25696. var repeat = 1;
  25697. if ((flags & 0x08)) {
  25698. repeat += code[i++];
  25699. }
  25700. while (repeat-- > 0) {
  25701. points.push({flags: flags});
  25702. }
  25703. }
  25704. for (j = 0; j < numberOfPoints; j++) {
  25705. switch (points[j].flags & 0x12) {
  25706. case 0x00:
  25707. x += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  25708. i += 2;
  25709. break;
  25710. case 0x02:
  25711. x -= code[i++];
  25712. break;
  25713. case 0x12:
  25714. x += code[i++];
  25715. break;
  25716. }
  25717. points[j].x = x;
  25718. }
  25719. for (j = 0; j < numberOfPoints; j++) {
  25720. switch (points[j].flags & 0x24) {
  25721. case 0x00:
  25722. y += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  25723. i += 2;
  25724. break;
  25725. case 0x04:
  25726. y -= code[i++];
  25727. break;
  25728. case 0x24:
  25729. y += code[i++];
  25730. break;
  25731. }
  25732. points[j].y = y;
  25733. }
  25734. var startPoint = 0;
  25735. for (i = 0; i < numberOfContours; i++) {
  25736. var endPoint = endPtsOfContours[i];
  25737. // contours might have implicit points, which is located in the middle
  25738. // between two neighboring off-curve points
  25739. var contour = points.slice(startPoint, endPoint + 1);
  25740. if ((contour[0].flags & 1)) {
  25741. contour.push(contour[0]); // using start point at the contour end
  25742. } else if ((contour[contour.length - 1].flags & 1)) {
  25743. // first is off-curve point, trying to use one from the end
  25744. contour.unshift(contour[contour.length - 1]);
  25745. } else {
  25746. // start and end are off-curve points, creating implicit one
  25747. var p = {
  25748. flags: 1,
  25749. x: (contour[0].x + contour[contour.length - 1].x) / 2,
  25750. y: (contour[0].y + contour[contour.length - 1].y) / 2
  25751. };
  25752. contour.unshift(p);
  25753. contour.push(p);
  25754. }
  25755. moveTo(contour[0].x, contour[0].y);
  25756. for (j = 1, jj = contour.length; j < jj; j++) {
  25757. if ((contour[j].flags & 1)) {
  25758. lineTo(contour[j].x, contour[j].y);
  25759. } else if ((contour[j + 1].flags & 1)){
  25760. quadraticCurveTo(contour[j].x, contour[j].y,
  25761. contour[j + 1].x, contour[j + 1].y);
  25762. j++;
  25763. } else {
  25764. quadraticCurveTo(contour[j].x, contour[j].y,
  25765. (contour[j].x + contour[j + 1].x) / 2,
  25766. (contour[j].y + contour[j + 1].y) / 2);
  25767. }
  25768. }
  25769. startPoint = endPoint + 1;
  25770. }
  25771. }
  25772. }
  25773. function compileCharString(code, cmds, font) {
  25774. var stack = [];
  25775. var x = 0, y = 0;
  25776. var stems = 0;
  25777. function moveTo(x, y) {
  25778. cmds.push({cmd: 'moveTo', args: [x, y]});
  25779. }
  25780. function lineTo(x, y) {
  25781. cmds.push({cmd: 'lineTo', args: [x, y]});
  25782. }
  25783. function bezierCurveTo(x1, y1, x2, y2, x, y) {
  25784. cmds.push({cmd: 'bezierCurveTo', args: [x1, y1, x2, y2, x, y]});
  25785. }
  25786. function parse(code) {
  25787. var i = 0;
  25788. while (i < code.length) {
  25789. var stackClean = false;
  25790. var v = code[i++];
  25791. var xa, xb, ya, yb, y1, y2, y3, n, subrCode;
  25792. switch (v) {
  25793. case 1: // hstem
  25794. stems += stack.length >> 1;
  25795. stackClean = true;
  25796. break;
  25797. case 3: // vstem
  25798. stems += stack.length >> 1;
  25799. stackClean = true;
  25800. break;
  25801. case 4: // vmoveto
  25802. y += stack.pop();
  25803. moveTo(x, y);
  25804. stackClean = true;
  25805. break;
  25806. case 5: // rlineto
  25807. while (stack.length > 0) {
  25808. x += stack.shift();
  25809. y += stack.shift();
  25810. lineTo(x, y);
  25811. }
  25812. break;
  25813. case 6: // hlineto
  25814. while (stack.length > 0) {
  25815. x += stack.shift();
  25816. lineTo(x, y);
  25817. if (stack.length === 0) {
  25818. break;
  25819. }
  25820. y += stack.shift();
  25821. lineTo(x, y);
  25822. }
  25823. break;
  25824. case 7: // vlineto
  25825. while (stack.length > 0) {
  25826. y += stack.shift();
  25827. lineTo(x, y);
  25828. if (stack.length === 0) {
  25829. break;
  25830. }
  25831. x += stack.shift();
  25832. lineTo(x, y);
  25833. }
  25834. break;
  25835. case 8: // rrcurveto
  25836. while (stack.length > 0) {
  25837. xa = x + stack.shift(); ya = y + stack.shift();
  25838. xb = xa + stack.shift(); yb = ya + stack.shift();
  25839. x = xb + stack.shift(); y = yb + stack.shift();
  25840. bezierCurveTo(xa, ya, xb, yb, x, y);
  25841. }
  25842. break;
  25843. case 10: // callsubr
  25844. n = stack.pop() + font.subrsBias;
  25845. subrCode = font.subrs[n];
  25846. if (subrCode) {
  25847. parse(subrCode);
  25848. }
  25849. break;
  25850. case 11: // return
  25851. return;
  25852. case 12:
  25853. v = code[i++];
  25854. switch (v) {
  25855. case 34: // flex
  25856. xa = x + stack.shift();
  25857. xb = xa + stack.shift(); y1 = y + stack.shift();
  25858. x = xb + stack.shift();
  25859. bezierCurveTo(xa, y, xb, y1, x, y1);
  25860. xa = x + stack.shift();
  25861. xb = xa + stack.shift();
  25862. x = xb + stack.shift();
  25863. bezierCurveTo(xa, y1, xb, y, x, y);
  25864. break;
  25865. case 35: // flex
  25866. xa = x + stack.shift(); ya = y + stack.shift();
  25867. xb = xa + stack.shift(); yb = ya + stack.shift();
  25868. x = xb + stack.shift(); y = yb + stack.shift();
  25869. bezierCurveTo(xa, ya, xb, yb, x, y);
  25870. xa = x + stack.shift(); ya = y + stack.shift();
  25871. xb = xa + stack.shift(); yb = ya + stack.shift();
  25872. x = xb + stack.shift(); y = yb + stack.shift();
  25873. bezierCurveTo(xa, ya, xb, yb, x, y);
  25874. stack.pop(); // fd
  25875. break;
  25876. case 36: // hflex1
  25877. xa = x + stack.shift(); y1 = y + stack.shift();
  25878. xb = xa + stack.shift(); y2 = y1 + stack.shift();
  25879. x = xb + stack.shift();
  25880. bezierCurveTo(xa, y1, xb, y2, x, y2);
  25881. xa = x + stack.shift();
  25882. xb = xa + stack.shift(); y3 = y2 + stack.shift();
  25883. x = xb + stack.shift();
  25884. bezierCurveTo(xa, y2, xb, y3, x, y);
  25885. break;
  25886. case 37: // flex1
  25887. var x0 = x, y0 = y;
  25888. xa = x + stack.shift(); ya = y + stack.shift();
  25889. xb = xa + stack.shift(); yb = ya + stack.shift();
  25890. x = xb + stack.shift(); y = yb + stack.shift();
  25891. bezierCurveTo(xa, ya, xb, yb, x, y);
  25892. xa = x + stack.shift(); ya = y + stack.shift();
  25893. xb = xa + stack.shift(); yb = ya + stack.shift();
  25894. x = xb; y = yb;
  25895. if (Math.abs(x - x0) > Math.abs(y - y0)) {
  25896. x += stack.shift();
  25897. } else {
  25898. y += stack.shift();
  25899. }
  25900. bezierCurveTo(xa, ya, xb, yb, x, y);
  25901. break;
  25902. default:
  25903. error('unknown operator: 12 ' + v);
  25904. }
  25905. break;
  25906. case 14: // endchar
  25907. if (stack.length >= 4) {
  25908. var achar = stack.pop();
  25909. var bchar = stack.pop();
  25910. y = stack.pop();
  25911. x = stack.pop();
  25912. cmds.push({cmd: 'save'});
  25913. cmds.push({cmd: 'translate', args: [x, y]});
  25914. var gid = lookupCmap(font.cmap, String.fromCharCode(
  25915. font.glyphNameMap[Encodings.StandardEncoding[achar]]));
  25916. compileCharString(font.glyphs[gid], cmds, font);
  25917. cmds.push({cmd: 'restore'});
  25918. gid = lookupCmap(font.cmap, String.fromCharCode(
  25919. font.glyphNameMap[Encodings.StandardEncoding[bchar]]));
  25920. compileCharString(font.glyphs[gid], cmds, font);
  25921. }
  25922. return;
  25923. case 18: // hstemhm
  25924. stems += stack.length >> 1;
  25925. stackClean = true;
  25926. break;
  25927. case 19: // hintmask
  25928. stems += stack.length >> 1;
  25929. i += (stems + 7) >> 3;
  25930. stackClean = true;
  25931. break;
  25932. case 20: // cntrmask
  25933. stems += stack.length >> 1;
  25934. i += (stems + 7) >> 3;
  25935. stackClean = true;
  25936. break;
  25937. case 21: // rmoveto
  25938. y += stack.pop();
  25939. x += stack.pop();
  25940. moveTo(x, y);
  25941. stackClean = true;
  25942. break;
  25943. case 22: // hmoveto
  25944. x += stack.pop();
  25945. moveTo(x, y);
  25946. stackClean = true;
  25947. break;
  25948. case 23: // vstemhm
  25949. stems += stack.length >> 1;
  25950. stackClean = true;
  25951. break;
  25952. case 24: // rcurveline
  25953. while (stack.length > 2) {
  25954. xa = x + stack.shift(); ya = y + stack.shift();
  25955. xb = xa + stack.shift(); yb = ya + stack.shift();
  25956. x = xb + stack.shift(); y = yb + stack.shift();
  25957. bezierCurveTo(xa, ya, xb, yb, x, y);
  25958. }
  25959. x += stack.shift();
  25960. y += stack.shift();
  25961. lineTo(x, y);
  25962. break;
  25963. case 25: // rlinecurve
  25964. while (stack.length > 6) {
  25965. x += stack.shift();
  25966. y += stack.shift();
  25967. lineTo(x, y);
  25968. }
  25969. xa = x + stack.shift(); ya = y + stack.shift();
  25970. xb = xa + stack.shift(); yb = ya + stack.shift();
  25971. x = xb + stack.shift(); y = yb + stack.shift();
  25972. bezierCurveTo(xa, ya, xb, yb, x, y);
  25973. break;
  25974. case 26: // vvcurveto
  25975. if (stack.length % 2) {
  25976. x += stack.shift();
  25977. }
  25978. while (stack.length > 0) {
  25979. xa = x; ya = y + stack.shift();
  25980. xb = xa + stack.shift(); yb = ya + stack.shift();
  25981. x = xb; y = yb + stack.shift();
  25982. bezierCurveTo(xa, ya, xb, yb, x, y);
  25983. }
  25984. break;
  25985. case 27: // hhcurveto
  25986. if (stack.length % 2) {
  25987. y += stack.shift();
  25988. }
  25989. while (stack.length > 0) {
  25990. xa = x + stack.shift(); ya = y;
  25991. xb = xa + stack.shift(); yb = ya + stack.shift();
  25992. x = xb + stack.shift(); y = yb;
  25993. bezierCurveTo(xa, ya, xb, yb, x, y);
  25994. }
  25995. break;
  25996. case 28:
  25997. stack.push(((code[i] << 24) | (code[i + 1] << 16)) >> 16);
  25998. i += 2;
  25999. break;
  26000. case 29: // callgsubr
  26001. n = stack.pop() + font.gsubrsBias;
  26002. subrCode = font.gsubrs[n];
  26003. if (subrCode) {
  26004. parse(subrCode);
  26005. }
  26006. break;
  26007. case 30: // vhcurveto
  26008. while (stack.length > 0) {
  26009. xa = x; ya = y + stack.shift();
  26010. xb = xa + stack.shift(); yb = ya + stack.shift();
  26011. x = xb + stack.shift();
  26012. y = yb + (stack.length === 1 ? stack.shift() : 0);
  26013. bezierCurveTo(xa, ya, xb, yb, x, y);
  26014. if (stack.length === 0) {
  26015. break;
  26016. }
  26017. xa = x + stack.shift(); ya = y;
  26018. xb = xa + stack.shift(); yb = ya + stack.shift();
  26019. y = yb + stack.shift();
  26020. x = xb + (stack.length === 1 ? stack.shift() : 0);
  26021. bezierCurveTo(xa, ya, xb, yb, x, y);
  26022. }
  26023. break;
  26024. case 31: // hvcurveto
  26025. while (stack.length > 0) {
  26026. xa = x + stack.shift(); ya = y;
  26027. xb = xa + stack.shift(); yb = ya + stack.shift();
  26028. y = yb + stack.shift();
  26029. x = xb + (stack.length === 1 ? stack.shift() : 0);
  26030. bezierCurveTo(xa, ya, xb, yb, x, y);
  26031. if (stack.length === 0) {
  26032. break;
  26033. }
  26034. xa = x; ya = y + stack.shift();
  26035. xb = xa + stack.shift(); yb = ya + stack.shift();
  26036. x = xb + stack.shift();
  26037. y = yb + (stack.length === 1 ? stack.shift() : 0);
  26038. bezierCurveTo(xa, ya, xb, yb, x, y);
  26039. }
  26040. break;
  26041. default:
  26042. if (v < 32) {
  26043. error('unknown operator: ' + v);
  26044. }
  26045. if (v < 247) {
  26046. stack.push(v - 139);
  26047. } else if (v < 251) {
  26048. stack.push((v - 247) * 256 + code[i++] + 108);
  26049. } else if (v < 255) {
  26050. stack.push(-(v - 251) * 256 - code[i++] - 108);
  26051. } else {
  26052. stack.push(((code[i] << 24) | (code[i + 1] << 16) |
  26053. (code[i + 2] << 8) | code[i + 3]) / 65536);
  26054. i += 4;
  26055. }
  26056. break;
  26057. }
  26058. if (stackClean) {
  26059. stack.length = 0;
  26060. }
  26061. }
  26062. }
  26063. parse(code);
  26064. }
  26065. var noop = '';
  26066. function CompiledFont(fontMatrix) {
  26067. this.compiledGlyphs = {};
  26068. this.fontMatrix = fontMatrix;
  26069. }
  26070. CompiledFont.prototype = {
  26071. getPathJs: function (unicode) {
  26072. var gid = lookupCmap(this.cmap, unicode);
  26073. var fn = this.compiledGlyphs[gid];
  26074. if (!fn) {
  26075. this.compiledGlyphs[gid] = fn = this.compileGlyph(this.glyphs[gid]);
  26076. }
  26077. return fn;
  26078. },
  26079. compileGlyph: function (code) {
  26080. if (!code || code.length === 0 || code[0] === 14) {
  26081. return noop;
  26082. }
  26083. var cmds = [];
  26084. cmds.push({cmd: 'save'});
  26085. cmds.push({cmd: 'transform', args: this.fontMatrix.slice()});
  26086. cmds.push({cmd: 'scale', args: ['size', '-size']});
  26087. this.compileGlyphImpl(code, cmds);
  26088. cmds.push({cmd: 'restore'});
  26089. return cmds;
  26090. },
  26091. compileGlyphImpl: function () {
  26092. error('Children classes should implement this.');
  26093. },
  26094. hasBuiltPath: function (unicode) {
  26095. var gid = lookupCmap(this.cmap, unicode);
  26096. return gid in this.compiledGlyphs;
  26097. }
  26098. };
  26099. function TrueTypeCompiled(glyphs, cmap, fontMatrix) {
  26100. fontMatrix = fontMatrix || [0.000488, 0, 0, 0.000488, 0, 0];
  26101. CompiledFont.call(this, fontMatrix);
  26102. this.glyphs = glyphs;
  26103. this.cmap = cmap;
  26104. this.compiledGlyphs = [];
  26105. }
  26106. Util.inherit(TrueTypeCompiled, CompiledFont, {
  26107. compileGlyphImpl: function (code, cmds) {
  26108. compileGlyf(code, cmds, this);
  26109. }
  26110. });
  26111. function Type2Compiled(cffInfo, cmap, fontMatrix, glyphNameMap) {
  26112. fontMatrix = fontMatrix || [0.001, 0, 0, 0.001, 0, 0];
  26113. CompiledFont.call(this, fontMatrix);
  26114. this.glyphs = cffInfo.glyphs;
  26115. this.gsubrs = cffInfo.gsubrs || [];
  26116. this.subrs = cffInfo.subrs || [];
  26117. this.cmap = cmap;
  26118. this.glyphNameMap = glyphNameMap || GlyphsUnicode;
  26119. this.compiledGlyphs = [];
  26120. this.gsubrsBias = (this.gsubrs.length < 1240 ?
  26121. 107 : (this.gsubrs.length < 33900 ? 1131 : 32768));
  26122. this.subrsBias = (this.subrs.length < 1240 ?
  26123. 107 : (this.subrs.length < 33900 ? 1131 : 32768));
  26124. }
  26125. Util.inherit(Type2Compiled, CompiledFont, {
  26126. compileGlyphImpl: function (code, cmds) {
  26127. compileCharString(code, cmds, this);
  26128. }
  26129. });
  26130. return {
  26131. create: function FontRendererFactory_create(font) {
  26132. var data = new Uint8Array(font.data);
  26133. var cmap, glyf, loca, cff, indexToLocFormat, unitsPerEm;
  26134. var numTables = getUshort(data, 4);
  26135. for (var i = 0, p = 12; i < numTables; i++, p += 16) {
  26136. var tag = bytesToString(data.subarray(p, p + 4));
  26137. var offset = getLong(data, p + 8);
  26138. var length = getLong(data, p + 12);
  26139. switch (tag) {
  26140. case 'cmap':
  26141. cmap = parseCmap(data, offset, offset + length);
  26142. break;
  26143. case 'glyf':
  26144. glyf = data.subarray(offset, offset + length);
  26145. break;
  26146. case 'loca':
  26147. loca = data.subarray(offset, offset + length);
  26148. break;
  26149. case 'head':
  26150. unitsPerEm = getUshort(data, offset + 18);
  26151. indexToLocFormat = getUshort(data, offset + 50);
  26152. break;
  26153. case 'CFF ':
  26154. cff = parseCff(data, offset, offset + length);
  26155. break;
  26156. }
  26157. }
  26158. if (glyf) {
  26159. var fontMatrix = (!unitsPerEm ? font.fontMatrix :
  26160. [1 / unitsPerEm, 0, 0, 1 / unitsPerEm, 0, 0]);
  26161. return new TrueTypeCompiled(
  26162. parseGlyfTable(glyf, loca, indexToLocFormat), cmap, fontMatrix);
  26163. } else {
  26164. return new Type2Compiled(cff, cmap, font.fontMatrix, font.glyphNameMap);
  26165. }
  26166. }
  26167. };
  26168. })();
  26169. // TODO refactor to remove cyclic dependency on fonts.js
  26170. function _setCoreFonts(coreFonts_) {
  26171. coreFonts = coreFonts_;
  26172. Encodings = coreFonts_.Encodings;
  26173. CFFParser = coreFonts_.CFFParser;
  26174. }
  26175. exports._setCoreFonts = _setCoreFonts;
  26176. exports.FontRendererFactory = FontRendererFactory;
  26177. }));
  26178. (function (root, factory) {
  26179. {
  26180. factory((root.pdfjsCoreParser = {}), root.pdfjsSharedUtil,
  26181. root.pdfjsCorePrimitives, root.pdfjsCoreStream);
  26182. }
  26183. }(this, function (exports, sharedUtil, corePrimitives, coreStream) {
  26184. var MissingDataException = sharedUtil.MissingDataException;
  26185. var StreamType = sharedUtil.StreamType;
  26186. var assert = sharedUtil.assert;
  26187. var error = sharedUtil.error;
  26188. var info = sharedUtil.info;
  26189. var isArray = sharedUtil.isArray;
  26190. var isInt = sharedUtil.isInt;
  26191. var isNum = sharedUtil.isNum;
  26192. var isString = sharedUtil.isString;
  26193. var warn = sharedUtil.warn;
  26194. var Cmd = corePrimitives.Cmd;
  26195. var Dict = corePrimitives.Dict;
  26196. var Name = corePrimitives.Name;
  26197. var Ref = corePrimitives.Ref;
  26198. var isCmd = corePrimitives.isCmd;
  26199. var isDict = corePrimitives.isDict;
  26200. var isName = corePrimitives.isName;
  26201. var Ascii85Stream = coreStream.Ascii85Stream;
  26202. var AsciiHexStream = coreStream.AsciiHexStream;
  26203. var CCITTFaxStream = coreStream.CCITTFaxStream;
  26204. var FlateStream = coreStream.FlateStream;
  26205. var Jbig2Stream = coreStream.Jbig2Stream;
  26206. var JpegStream = coreStream.JpegStream;
  26207. var JpxStream = coreStream.JpxStream;
  26208. var LZWStream = coreStream.LZWStream;
  26209. var NullStream = coreStream.NullStream;
  26210. var PredictorStream = coreStream.PredictorStream;
  26211. var RunLengthStream = coreStream.RunLengthStream;
  26212. var EOF = {};
  26213. function isEOF(v) {
  26214. return (v === EOF);
  26215. }
  26216. var MAX_LENGTH_TO_CACHE = 1000;
  26217. var Parser = (function ParserClosure() {
  26218. function Parser(lexer, allowStreams, xref) {
  26219. this.lexer = lexer;
  26220. this.allowStreams = allowStreams;
  26221. this.xref = xref;
  26222. this.imageCache = {};
  26223. this.refill();
  26224. }
  26225. Parser.prototype = {
  26226. refill: function Parser_refill() {
  26227. this.buf1 = this.lexer.getObj();
  26228. this.buf2 = this.lexer.getObj();
  26229. },
  26230. shift: function Parser_shift() {
  26231. if (isCmd(this.buf2, 'ID')) {
  26232. this.buf1 = this.buf2;
  26233. this.buf2 = null;
  26234. } else {
  26235. this.buf1 = this.buf2;
  26236. this.buf2 = this.lexer.getObj();
  26237. }
  26238. },
  26239. tryShift: function Parser_tryShift() {
  26240. try {
  26241. this.shift();
  26242. return true;
  26243. } catch (e) {
  26244. if (e instanceof MissingDataException) {
  26245. throw e;
  26246. }
  26247. // Upon failure, the caller should reset this.lexer.pos to a known good
  26248. // state and call this.shift() twice to reset the buffers.
  26249. return false;
  26250. }
  26251. },
  26252. getObj: function Parser_getObj(cipherTransform) {
  26253. var buf1 = this.buf1;
  26254. this.shift();
  26255. if (buf1 instanceof Cmd) {
  26256. switch (buf1.cmd) {
  26257. case 'BI': // inline image
  26258. return this.makeInlineImage(cipherTransform);
  26259. case '[': // array
  26260. var array = [];
  26261. while (!isCmd(this.buf1, ']') && !isEOF(this.buf1)) {
  26262. array.push(this.getObj(cipherTransform));
  26263. }
  26264. if (isEOF(this.buf1)) {
  26265. error('End of file inside array');
  26266. }
  26267. this.shift();
  26268. return array;
  26269. case '<<': // dictionary or stream
  26270. var dict = new Dict(this.xref);
  26271. while (!isCmd(this.buf1, '>>') && !isEOF(this.buf1)) {
  26272. if (!isName(this.buf1)) {
  26273. info('Malformed dictionary: key must be a name object');
  26274. this.shift();
  26275. continue;
  26276. }
  26277. var key = this.buf1.name;
  26278. this.shift();
  26279. if (isEOF(this.buf1)) {
  26280. break;
  26281. }
  26282. dict.set(key, this.getObj(cipherTransform));
  26283. }
  26284. if (isEOF(this.buf1)) {
  26285. error('End of file inside dictionary');
  26286. }
  26287. // Stream objects are not allowed inside content streams or
  26288. // object streams.
  26289. if (isCmd(this.buf2, 'stream')) {
  26290. return (this.allowStreams ?
  26291. this.makeStream(dict, cipherTransform) : dict);
  26292. }
  26293. this.shift();
  26294. return dict;
  26295. default: // simple object
  26296. return buf1;
  26297. }
  26298. }
  26299. if (isInt(buf1)) { // indirect reference or integer
  26300. var num = buf1;
  26301. if (isInt(this.buf1) && isCmd(this.buf2, 'R')) {
  26302. var ref = new Ref(num, this.buf1);
  26303. this.shift();
  26304. this.shift();
  26305. return ref;
  26306. }
  26307. return num;
  26308. }
  26309. if (isString(buf1)) { // string
  26310. var str = buf1;
  26311. if (cipherTransform) {
  26312. str = cipherTransform.decryptString(str);
  26313. }
  26314. return str;
  26315. }
  26316. // simple object
  26317. return buf1;
  26318. },
  26319. /**
  26320. * Find the end of the stream by searching for the /EI\s/.
  26321. * @returns {number} The inline stream length.
  26322. */
  26323. findDefaultInlineStreamEnd:
  26324. function Parser_findDefaultInlineStreamEnd(stream) {
  26325. var E = 0x45, I = 0x49, SPACE = 0x20, LF = 0xA, CR = 0xD;
  26326. var startPos = stream.pos, state = 0, ch, i, n, followingBytes;
  26327. while ((ch = stream.getByte()) !== -1) {
  26328. if (state === 0) {
  26329. state = (ch === E) ? 1 : 0;
  26330. } else if (state === 1) {
  26331. state = (ch === I) ? 2 : 0;
  26332. } else {
  26333. assert(state === 2);
  26334. if (ch === SPACE || ch === LF || ch === CR) {
  26335. // Let's check the next five bytes are ASCII... just be sure.
  26336. n = 5;
  26337. followingBytes = stream.peekBytes(n);
  26338. for (i = 0; i < n; i++) {
  26339. ch = followingBytes[i];
  26340. if (ch !== LF && ch !== CR && (ch < SPACE || ch > 0x7F)) {
  26341. // Not a LF, CR, SPACE or any visible ASCII character, i.e.
  26342. // it's binary stuff. Resetting the state.
  26343. state = 0;
  26344. break;
  26345. }
  26346. }
  26347. if (state === 2) {
  26348. break; // Finished!
  26349. }
  26350. } else {
  26351. state = 0;
  26352. }
  26353. }
  26354. }
  26355. return ((stream.pos - 4) - startPos);
  26356. },
  26357. /**
  26358. * Find the EOI (end-of-image) marker 0xFFD9 of the stream.
  26359. * @returns {number} The inline stream length.
  26360. */
  26361. findDCTDecodeInlineStreamEnd:
  26362. function Parser_findDCTDecodeInlineStreamEnd(stream) {
  26363. var startPos = stream.pos, foundEOI = false, b, markerLength, length;
  26364. while ((b = stream.getByte()) !== -1) {
  26365. if (b !== 0xFF) { // Not a valid marker.
  26366. continue;
  26367. }
  26368. switch (stream.getByte()) {
  26369. case 0x00: // Byte stuffing.
  26370. // 0xFF00 appears to be a very common byte sequence in JPEG images.
  26371. break;
  26372. case 0xFF: // Fill byte.
  26373. // Avoid skipping a valid marker, resetting the stream position.
  26374. stream.skip(-1);
  26375. break;
  26376. case 0xD9: // EOI
  26377. foundEOI = true;
  26378. break;
  26379. case 0xC0: // SOF0
  26380. case 0xC1: // SOF1
  26381. case 0xC2: // SOF2
  26382. case 0xC3: // SOF3
  26383. case 0xC5: // SOF5
  26384. case 0xC6: // SOF6
  26385. case 0xC7: // SOF7
  26386. case 0xC9: // SOF9
  26387. case 0xCA: // SOF10
  26388. case 0xCB: // SOF11
  26389. case 0xCD: // SOF13
  26390. case 0xCE: // SOF14
  26391. case 0xCF: // SOF15
  26392. case 0xC4: // DHT
  26393. case 0xCC: // DAC
  26394. case 0xDA: // SOS
  26395. case 0xDB: // DQT
  26396. case 0xDC: // DNL
  26397. case 0xDD: // DRI
  26398. case 0xDE: // DHP
  26399. case 0xDF: // EXP
  26400. case 0xE0: // APP0
  26401. case 0xE1: // APP1
  26402. case 0xE2: // APP2
  26403. case 0xE3: // APP3
  26404. case 0xE4: // APP4
  26405. case 0xE5: // APP5
  26406. case 0xE6: // APP6
  26407. case 0xE7: // APP7
  26408. case 0xE8: // APP8
  26409. case 0xE9: // APP9
  26410. case 0xEA: // APP10
  26411. case 0xEB: // APP11
  26412. case 0xEC: // APP12
  26413. case 0xED: // APP13
  26414. case 0xEE: // APP14
  26415. case 0xEF: // APP15
  26416. case 0xFE: // COM
  26417. // The marker should be followed by the length of the segment.
  26418. markerLength = stream.getUint16();
  26419. if (markerLength > 2) {
  26420. // |markerLength| contains the byte length of the marker segment,
  26421. // including its own length (2 bytes) and excluding the marker.
  26422. stream.skip(markerLength - 2); // Jump to the next marker.
  26423. } else {
  26424. // The marker length is invalid, resetting the stream position.
  26425. stream.skip(-2);
  26426. }
  26427. break;
  26428. }
  26429. if (foundEOI) {
  26430. break;
  26431. }
  26432. }
  26433. length = stream.pos - startPos;
  26434. if (b === -1) {
  26435. warn('Inline DCTDecode image stream: ' +
  26436. 'EOI marker not found, searching for /EI/ instead.');
  26437. stream.skip(-length); // Reset the stream position.
  26438. return this.findDefaultInlineStreamEnd(stream);
  26439. }
  26440. this.inlineStreamSkipEI(stream);
  26441. return length;
  26442. },
  26443. /**
  26444. * Find the EOD (end-of-data) marker '~>' (i.e. TILDE + GT) of the stream.
  26445. * @returns {number} The inline stream length.
  26446. */
  26447. findASCII85DecodeInlineStreamEnd:
  26448. function Parser_findASCII85DecodeInlineStreamEnd(stream) {
  26449. var TILDE = 0x7E, GT = 0x3E;
  26450. var startPos = stream.pos, ch, length;
  26451. while ((ch = stream.getByte()) !== -1) {
  26452. if (ch === TILDE && stream.peekByte() === GT) {
  26453. stream.skip();
  26454. break;
  26455. }
  26456. }
  26457. length = stream.pos - startPos;
  26458. if (ch === -1) {
  26459. warn('Inline ASCII85Decode image stream: ' +
  26460. 'EOD marker not found, searching for /EI/ instead.');
  26461. stream.skip(-length); // Reset the stream position.
  26462. return this.findDefaultInlineStreamEnd(stream);
  26463. }
  26464. this.inlineStreamSkipEI(stream);
  26465. return length;
  26466. },
  26467. /**
  26468. * Find the EOD (end-of-data) marker '>' (i.e. GT) of the stream.
  26469. * @returns {number} The inline stream length.
  26470. */
  26471. findASCIIHexDecodeInlineStreamEnd:
  26472. function Parser_findASCIIHexDecodeInlineStreamEnd(stream) {
  26473. var GT = 0x3E;
  26474. var startPos = stream.pos, ch, length;
  26475. while ((ch = stream.getByte()) !== -1) {
  26476. if (ch === GT) {
  26477. break;
  26478. }
  26479. }
  26480. length = stream.pos - startPos;
  26481. if (ch === -1) {
  26482. warn('Inline ASCIIHexDecode image stream: ' +
  26483. 'EOD marker not found, searching for /EI/ instead.');
  26484. stream.skip(-length); // Reset the stream position.
  26485. return this.findDefaultInlineStreamEnd(stream);
  26486. }
  26487. this.inlineStreamSkipEI(stream);
  26488. return length;
  26489. },
  26490. /**
  26491. * Skip over the /EI/ for streams where we search for an EOD marker.
  26492. */
  26493. inlineStreamSkipEI: function Parser_inlineStreamSkipEI(stream) {
  26494. var E = 0x45, I = 0x49;
  26495. var state = 0, ch;
  26496. while ((ch = stream.getByte()) !== -1) {
  26497. if (state === 0) {
  26498. state = (ch === E) ? 1 : 0;
  26499. } else if (state === 1) {
  26500. state = (ch === I) ? 2 : 0;
  26501. } else if (state === 2) {
  26502. break;
  26503. }
  26504. }
  26505. },
  26506. makeInlineImage: function Parser_makeInlineImage(cipherTransform) {
  26507. var lexer = this.lexer;
  26508. var stream = lexer.stream;
  26509. // Parse dictionary.
  26510. var dict = new Dict(this.xref);
  26511. while (!isCmd(this.buf1, 'ID') && !isEOF(this.buf1)) {
  26512. if (!isName(this.buf1)) {
  26513. error('Dictionary key must be a name object');
  26514. }
  26515. var key = this.buf1.name;
  26516. this.shift();
  26517. if (isEOF(this.buf1)) {
  26518. break;
  26519. }
  26520. dict.set(key, this.getObj(cipherTransform));
  26521. }
  26522. // Extract the name of the first (i.e. the current) image filter.
  26523. var filter = dict.get('Filter', 'F'), filterName;
  26524. if (isName(filter)) {
  26525. filterName = filter.name;
  26526. } else if (isArray(filter) && isName(filter[0])) {
  26527. filterName = filter[0].name;
  26528. }
  26529. // Parse image stream.
  26530. var startPos = stream.pos, length, i, ii;
  26531. if (filterName === 'DCTDecode' || filterName === 'DCT') {
  26532. length = this.findDCTDecodeInlineStreamEnd(stream);
  26533. } else if (filterName === 'ASCII85Decide' || filterName === 'A85') {
  26534. length = this.findASCII85DecodeInlineStreamEnd(stream);
  26535. } else if (filterName === 'ASCIIHexDecode' || filterName === 'AHx') {
  26536. length = this.findASCIIHexDecodeInlineStreamEnd(stream);
  26537. } else {
  26538. length = this.findDefaultInlineStreamEnd(stream);
  26539. }
  26540. var imageStream = stream.makeSubStream(startPos, length, dict);
  26541. // Cache all images below the MAX_LENGTH_TO_CACHE threshold by their
  26542. // adler32 checksum.
  26543. var adler32;
  26544. if (length < MAX_LENGTH_TO_CACHE) {
  26545. var imageBytes = imageStream.getBytes();
  26546. imageStream.reset();
  26547. var a = 1;
  26548. var b = 0;
  26549. for (i = 0, ii = imageBytes.length; i < ii; ++i) {
  26550. // No modulo required in the loop if imageBytes.length < 5552.
  26551. a += imageBytes[i] & 0xff;
  26552. b += a;
  26553. }
  26554. adler32 = ((b % 65521) << 16) | (a % 65521);
  26555. if (this.imageCache.adler32 === adler32) {
  26556. this.buf2 = Cmd.get('EI');
  26557. this.shift();
  26558. this.imageCache[adler32].reset();
  26559. return this.imageCache[adler32];
  26560. }
  26561. }
  26562. if (cipherTransform) {
  26563. imageStream = cipherTransform.createStream(imageStream, length);
  26564. }
  26565. imageStream = this.filter(imageStream, dict, length);
  26566. imageStream.dict = dict;
  26567. if (adler32 !== undefined) {
  26568. imageStream.cacheKey = 'inline_' + length + '_' + adler32;
  26569. this.imageCache[adler32] = imageStream;
  26570. }
  26571. this.buf2 = Cmd.get('EI');
  26572. this.shift();
  26573. return imageStream;
  26574. },
  26575. makeStream: function Parser_makeStream(dict, cipherTransform) {
  26576. var lexer = this.lexer;
  26577. var stream = lexer.stream;
  26578. // get stream start position
  26579. lexer.skipToNextLine();
  26580. var pos = stream.pos - 1;
  26581. // get length
  26582. var length = dict.get('Length');
  26583. if (!isInt(length)) {
  26584. info('Bad ' + length + ' attribute in stream');
  26585. length = 0;
  26586. }
  26587. // skip over the stream data
  26588. stream.pos = pos + length;
  26589. lexer.nextChar();
  26590. // Shift '>>' and check whether the new object marks the end of the stream
  26591. if (this.tryShift() && isCmd(this.buf2, 'endstream')) {
  26592. this.shift(); // 'stream'
  26593. } else {
  26594. // bad stream length, scanning for endstream
  26595. stream.pos = pos;
  26596. var SCAN_BLOCK_SIZE = 2048;
  26597. var ENDSTREAM_SIGNATURE_LENGTH = 9;
  26598. var ENDSTREAM_SIGNATURE = [0x65, 0x6E, 0x64, 0x73, 0x74, 0x72, 0x65,
  26599. 0x61, 0x6D];
  26600. var skipped = 0, found = false, i, j;
  26601. while (stream.pos < stream.end) {
  26602. var scanBytes = stream.peekBytes(SCAN_BLOCK_SIZE);
  26603. var scanLength = scanBytes.length - ENDSTREAM_SIGNATURE_LENGTH;
  26604. if (scanLength <= 0) {
  26605. break;
  26606. }
  26607. found = false;
  26608. for (i = 0, j = 0; i < scanLength; i++) {
  26609. var b = scanBytes[i];
  26610. if (b !== ENDSTREAM_SIGNATURE[j]) {
  26611. i -= j;
  26612. j = 0;
  26613. } else {
  26614. j++;
  26615. if (j >= ENDSTREAM_SIGNATURE_LENGTH) {
  26616. i++;
  26617. found = true;
  26618. break;
  26619. }
  26620. }
  26621. }
  26622. if (found) {
  26623. skipped += i - ENDSTREAM_SIGNATURE_LENGTH;
  26624. stream.pos += i - ENDSTREAM_SIGNATURE_LENGTH;
  26625. break;
  26626. }
  26627. skipped += scanLength;
  26628. stream.pos += scanLength;
  26629. }
  26630. if (!found) {
  26631. error('Missing endstream');
  26632. }
  26633. length = skipped;
  26634. lexer.nextChar();
  26635. this.shift();
  26636. this.shift();
  26637. }
  26638. this.shift(); // 'endstream'
  26639. stream = stream.makeSubStream(pos, length, dict);
  26640. if (cipherTransform) {
  26641. stream = cipherTransform.createStream(stream, length);
  26642. }
  26643. stream = this.filter(stream, dict, length);
  26644. stream.dict = dict;
  26645. return stream;
  26646. },
  26647. filter: function Parser_filter(stream, dict, length) {
  26648. var filter = dict.get('Filter', 'F');
  26649. var params = dict.get('DecodeParms', 'DP');
  26650. if (isName(filter)) {
  26651. return this.makeFilter(stream, filter.name, length, params);
  26652. }
  26653. var maybeLength = length;
  26654. if (isArray(filter)) {
  26655. var filterArray = filter;
  26656. var paramsArray = params;
  26657. for (var i = 0, ii = filterArray.length; i < ii; ++i) {
  26658. filter = filterArray[i];
  26659. if (!isName(filter)) {
  26660. error('Bad filter name: ' + filter);
  26661. }
  26662. params = null;
  26663. if (isArray(paramsArray) && (i in paramsArray)) {
  26664. params = paramsArray[i];
  26665. }
  26666. stream = this.makeFilter(stream, filter.name, maybeLength, params);
  26667. // after the first stream the length variable is invalid
  26668. maybeLength = null;
  26669. }
  26670. }
  26671. return stream;
  26672. },
  26673. makeFilter: function Parser_makeFilter(stream, name, maybeLength, params) {
  26674. if (stream.dict.get('Length') === 0 && !maybeLength) {
  26675. warn('Empty "' + name + '" stream.');
  26676. return new NullStream(stream);
  26677. }
  26678. try {
  26679. if (params && this.xref) {
  26680. params = this.xref.fetchIfRef(params);
  26681. }
  26682. var xrefStreamStats = this.xref.stats.streamTypes;
  26683. if (name === 'FlateDecode' || name === 'Fl') {
  26684. xrefStreamStats[StreamType.FLATE] = true;
  26685. if (params) {
  26686. return new PredictorStream(new FlateStream(stream, maybeLength),
  26687. maybeLength, params);
  26688. }
  26689. return new FlateStream(stream, maybeLength);
  26690. }
  26691. if (name === 'LZWDecode' || name === 'LZW') {
  26692. xrefStreamStats[StreamType.LZW] = true;
  26693. var earlyChange = 1;
  26694. if (params) {
  26695. if (params.has('EarlyChange')) {
  26696. earlyChange = params.get('EarlyChange');
  26697. }
  26698. return new PredictorStream(
  26699. new LZWStream(stream, maybeLength, earlyChange),
  26700. maybeLength, params);
  26701. }
  26702. return new LZWStream(stream, maybeLength, earlyChange);
  26703. }
  26704. if (name === 'DCTDecode' || name === 'DCT') {
  26705. xrefStreamStats[StreamType.DCT] = true;
  26706. return new JpegStream(stream, maybeLength, stream.dict, this.xref);
  26707. }
  26708. if (name === 'JPXDecode' || name === 'JPX') {
  26709. xrefStreamStats[StreamType.JPX] = true;
  26710. return new JpxStream(stream, maybeLength, stream.dict);
  26711. }
  26712. if (name === 'ASCII85Decode' || name === 'A85') {
  26713. xrefStreamStats[StreamType.A85] = true;
  26714. return new Ascii85Stream(stream, maybeLength);
  26715. }
  26716. if (name === 'ASCIIHexDecode' || name === 'AHx') {
  26717. xrefStreamStats[StreamType.AHX] = true;
  26718. return new AsciiHexStream(stream, maybeLength);
  26719. }
  26720. if (name === 'CCITTFaxDecode' || name === 'CCF') {
  26721. xrefStreamStats[StreamType.CCF] = true;
  26722. return new CCITTFaxStream(stream, maybeLength, params);
  26723. }
  26724. if (name === 'RunLengthDecode' || name === 'RL') {
  26725. xrefStreamStats[StreamType.RL] = true;
  26726. return new RunLengthStream(stream, maybeLength);
  26727. }
  26728. if (name === 'JBIG2Decode') {
  26729. xrefStreamStats[StreamType.JBIG] = true;
  26730. return new Jbig2Stream(stream, maybeLength, stream.dict);
  26731. }
  26732. warn('filter "' + name + '" not supported yet');
  26733. return stream;
  26734. } catch (ex) {
  26735. if (ex instanceof MissingDataException) {
  26736. throw ex;
  26737. }
  26738. warn('Invalid stream: \"' + ex + '\"');
  26739. return new NullStream(stream);
  26740. }
  26741. }
  26742. };
  26743. return Parser;
  26744. })();
  26745. var Lexer = (function LexerClosure() {
  26746. function Lexer(stream, knownCommands) {
  26747. this.stream = stream;
  26748. this.nextChar();
  26749. // While lexing, we build up many strings one char at a time. Using += for
  26750. // this can result in lots of garbage strings. It's better to build an
  26751. // array of single-char strings and then join() them together at the end.
  26752. // And reusing a single array (i.e. |this.strBuf|) over and over for this
  26753. // purpose uses less memory than using a new array for each string.
  26754. this.strBuf = [];
  26755. // The PDFs might have "glued" commands with other commands, operands or
  26756. // literals, e.g. "q1". The knownCommands is a dictionary of the valid
  26757. // commands and their prefixes. The prefixes are built the following way:
  26758. // if there a command that is a prefix of the other valid command or
  26759. // literal (e.g. 'f' and 'false') the following prefixes must be included,
  26760. // 'fa', 'fal', 'fals'. The prefixes are not needed, if the command has no
  26761. // other commands or literals as a prefix. The knowCommands is optional.
  26762. this.knownCommands = knownCommands;
  26763. }
  26764. Lexer.isSpace = function Lexer_isSpace(ch) {
  26765. // Space is one of the following characters: SPACE, TAB, CR or LF.
  26766. return (ch === 0x20 || ch === 0x09 || ch === 0x0D || ch === 0x0A);
  26767. };
  26768. // A '1' in this array means the character is white space. A '1' or
  26769. // '2' means the character ends a name or command.
  26770. var specialChars = [
  26771. 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, // 0x
  26772. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 1x
  26773. 1, 0, 0, 0, 0, 2, 0, 0, 2, 2, 0, 0, 0, 0, 0, 2, // 2x
  26774. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, // 3x
  26775. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 4x
  26776. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 5x
  26777. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 6x
  26778. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 7x
  26779. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 8x
  26780. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 9x
  26781. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ax
  26782. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // bx
  26783. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // cx
  26784. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // dx
  26785. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ex
  26786. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 // fx
  26787. ];
  26788. function toHexDigit(ch) {
  26789. if (ch >= 0x30 && ch <= 0x39) { // '0'-'9'
  26790. return ch & 0x0F;
  26791. }
  26792. if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
  26793. // 'A'-'F', 'a'-'f'
  26794. return (ch & 0x0F) + 9;
  26795. }
  26796. return -1;
  26797. }
  26798. Lexer.prototype = {
  26799. nextChar: function Lexer_nextChar() {
  26800. return (this.currentChar = this.stream.getByte());
  26801. },
  26802. peekChar: function Lexer_peekChar() {
  26803. return this.stream.peekByte();
  26804. },
  26805. getNumber: function Lexer_getNumber() {
  26806. var ch = this.currentChar;
  26807. var eNotation = false;
  26808. var divideBy = 0; // different from 0 if it's a floating point value
  26809. var sign = 1;
  26810. if (ch === 0x2D) { // '-'
  26811. sign = -1;
  26812. ch = this.nextChar();
  26813. if (ch === 0x2D) { // '-'
  26814. // Ignore double negative (this is consistent with Adobe Reader).
  26815. ch = this.nextChar();
  26816. }
  26817. } else if (ch === 0x2B) { // '+'
  26818. ch = this.nextChar();
  26819. }
  26820. if (ch === 0x2E) { // '.'
  26821. divideBy = 10;
  26822. ch = this.nextChar();
  26823. }
  26824. if (ch < 0x30 || ch > 0x39) { // '0' - '9'
  26825. error('Invalid number: ' + String.fromCharCode(ch));
  26826. return 0;
  26827. }
  26828. var baseValue = ch - 0x30; // '0'
  26829. var powerValue = 0;
  26830. var powerValueSign = 1;
  26831. while ((ch = this.nextChar()) >= 0) {
  26832. if (0x30 <= ch && ch <= 0x39) { // '0' - '9'
  26833. var currentDigit = ch - 0x30; // '0'
  26834. if (eNotation) { // We are after an 'e' or 'E'
  26835. powerValue = powerValue * 10 + currentDigit;
  26836. } else {
  26837. if (divideBy !== 0) { // We are after a point
  26838. divideBy *= 10;
  26839. }
  26840. baseValue = baseValue * 10 + currentDigit;
  26841. }
  26842. } else if (ch === 0x2E) { // '.'
  26843. if (divideBy === 0) {
  26844. divideBy = 1;
  26845. } else {
  26846. // A number can have only one '.'
  26847. break;
  26848. }
  26849. } else if (ch === 0x2D) { // '-'
  26850. // ignore minus signs in the middle of numbers to match
  26851. // Adobe's behavior
  26852. warn('Badly formated number');
  26853. } else if (ch === 0x45 || ch === 0x65) { // 'E', 'e'
  26854. // 'E' can be either a scientific notation or the beginning of a new
  26855. // operator
  26856. ch = this.peekChar();
  26857. if (ch === 0x2B || ch === 0x2D) { // '+', '-'
  26858. powerValueSign = (ch === 0x2D) ? -1 : 1;
  26859. this.nextChar(); // Consume the sign character
  26860. } else if (ch < 0x30 || ch > 0x39) { // '0' - '9'
  26861. // The 'E' must be the beginning of a new operator
  26862. break;
  26863. }
  26864. eNotation = true;
  26865. } else {
  26866. // the last character doesn't belong to us
  26867. break;
  26868. }
  26869. }
  26870. if (divideBy !== 0) {
  26871. baseValue /= divideBy;
  26872. }
  26873. if (eNotation) {
  26874. baseValue *= Math.pow(10, powerValueSign * powerValue);
  26875. }
  26876. return sign * baseValue;
  26877. },
  26878. getString: function Lexer_getString() {
  26879. var numParen = 1;
  26880. var done = false;
  26881. var strBuf = this.strBuf;
  26882. strBuf.length = 0;
  26883. var ch = this.nextChar();
  26884. while (true) {
  26885. var charBuffered = false;
  26886. switch (ch | 0) {
  26887. case -1:
  26888. warn('Unterminated string');
  26889. done = true;
  26890. break;
  26891. case 0x28: // '('
  26892. ++numParen;
  26893. strBuf.push('(');
  26894. break;
  26895. case 0x29: // ')'
  26896. if (--numParen === 0) {
  26897. this.nextChar(); // consume strings ')'
  26898. done = true;
  26899. } else {
  26900. strBuf.push(')');
  26901. }
  26902. break;
  26903. case 0x5C: // '\\'
  26904. ch = this.nextChar();
  26905. switch (ch) {
  26906. case -1:
  26907. warn('Unterminated string');
  26908. done = true;
  26909. break;
  26910. case 0x6E: // 'n'
  26911. strBuf.push('\n');
  26912. break;
  26913. case 0x72: // 'r'
  26914. strBuf.push('\r');
  26915. break;
  26916. case 0x74: // 't'
  26917. strBuf.push('\t');
  26918. break;
  26919. case 0x62: // 'b'
  26920. strBuf.push('\b');
  26921. break;
  26922. case 0x66: // 'f'
  26923. strBuf.push('\f');
  26924. break;
  26925. case 0x5C: // '\'
  26926. case 0x28: // '('
  26927. case 0x29: // ')'
  26928. strBuf.push(String.fromCharCode(ch));
  26929. break;
  26930. case 0x30: case 0x31: case 0x32: case 0x33: // '0'-'3'
  26931. case 0x34: case 0x35: case 0x36: case 0x37: // '4'-'7'
  26932. var x = ch & 0x0F;
  26933. ch = this.nextChar();
  26934. charBuffered = true;
  26935. if (ch >= 0x30 && ch <= 0x37) { // '0'-'7'
  26936. x = (x << 3) + (ch & 0x0F);
  26937. ch = this.nextChar();
  26938. if (ch >= 0x30 && ch <= 0x37) { // '0'-'7'
  26939. charBuffered = false;
  26940. x = (x << 3) + (ch & 0x0F);
  26941. }
  26942. }
  26943. strBuf.push(String.fromCharCode(x));
  26944. break;
  26945. case 0x0D: // CR
  26946. if (this.peekChar() === 0x0A) { // LF
  26947. this.nextChar();
  26948. }
  26949. break;
  26950. case 0x0A: // LF
  26951. break;
  26952. default:
  26953. strBuf.push(String.fromCharCode(ch));
  26954. break;
  26955. }
  26956. break;
  26957. default:
  26958. strBuf.push(String.fromCharCode(ch));
  26959. break;
  26960. }
  26961. if (done) {
  26962. break;
  26963. }
  26964. if (!charBuffered) {
  26965. ch = this.nextChar();
  26966. }
  26967. }
  26968. return strBuf.join('');
  26969. },
  26970. getName: function Lexer_getName() {
  26971. var ch, previousCh;
  26972. var strBuf = this.strBuf;
  26973. strBuf.length = 0;
  26974. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  26975. if (ch === 0x23) { // '#'
  26976. ch = this.nextChar();
  26977. if (specialChars[ch]) {
  26978. warn('Lexer_getName: ' +
  26979. 'NUMBER SIGN (#) should be followed by a hexadecimal number.');
  26980. strBuf.push('#');
  26981. break;
  26982. }
  26983. var x = toHexDigit(ch);
  26984. if (x !== -1) {
  26985. previousCh = ch;
  26986. ch = this.nextChar();
  26987. var x2 = toHexDigit(ch);
  26988. if (x2 === -1) {
  26989. warn('Lexer_getName: Illegal digit (' +
  26990. String.fromCharCode(ch) +') in hexadecimal number.');
  26991. strBuf.push('#', String.fromCharCode(previousCh));
  26992. if (specialChars[ch]) {
  26993. break;
  26994. }
  26995. strBuf.push(String.fromCharCode(ch));
  26996. continue;
  26997. }
  26998. strBuf.push(String.fromCharCode((x << 4) | x2));
  26999. } else {
  27000. strBuf.push('#', String.fromCharCode(ch));
  27001. }
  27002. } else {
  27003. strBuf.push(String.fromCharCode(ch));
  27004. }
  27005. }
  27006. if (strBuf.length > 127) {
  27007. warn('name token is longer than allowed by the spec: ' + strBuf.length);
  27008. }
  27009. return Name.get(strBuf.join(''));
  27010. },
  27011. getHexString: function Lexer_getHexString() {
  27012. var strBuf = this.strBuf;
  27013. strBuf.length = 0;
  27014. var ch = this.currentChar;
  27015. var isFirstHex = true;
  27016. var firstDigit;
  27017. var secondDigit;
  27018. while (true) {
  27019. if (ch < 0) {
  27020. warn('Unterminated hex string');
  27021. break;
  27022. } else if (ch === 0x3E) { // '>'
  27023. this.nextChar();
  27024. break;
  27025. } else if (specialChars[ch] === 1) {
  27026. ch = this.nextChar();
  27027. continue;
  27028. } else {
  27029. if (isFirstHex) {
  27030. firstDigit = toHexDigit(ch);
  27031. if (firstDigit === -1) {
  27032. warn('Ignoring invalid character "' + ch + '" in hex string');
  27033. ch = this.nextChar();
  27034. continue;
  27035. }
  27036. } else {
  27037. secondDigit = toHexDigit(ch);
  27038. if (secondDigit === -1) {
  27039. warn('Ignoring invalid character "' + ch + '" in hex string');
  27040. ch = this.nextChar();
  27041. continue;
  27042. }
  27043. strBuf.push(String.fromCharCode((firstDigit << 4) | secondDigit));
  27044. }
  27045. isFirstHex = !isFirstHex;
  27046. ch = this.nextChar();
  27047. }
  27048. }
  27049. return strBuf.join('');
  27050. },
  27051. getObj: function Lexer_getObj() {
  27052. // skip whitespace and comments
  27053. var comment = false;
  27054. var ch = this.currentChar;
  27055. while (true) {
  27056. if (ch < 0) {
  27057. return EOF;
  27058. }
  27059. if (comment) {
  27060. if (ch === 0x0A || ch === 0x0D) { // LF, CR
  27061. comment = false;
  27062. }
  27063. } else if (ch === 0x25) { // '%'
  27064. comment = true;
  27065. } else if (specialChars[ch] !== 1) {
  27066. break;
  27067. }
  27068. ch = this.nextChar();
  27069. }
  27070. // start reading token
  27071. switch (ch | 0) {
  27072. case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: // '0'-'4'
  27073. case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: // '5'-'9'
  27074. case 0x2B: case 0x2D: case 0x2E: // '+', '-', '.'
  27075. return this.getNumber();
  27076. case 0x28: // '('
  27077. return this.getString();
  27078. case 0x2F: // '/'
  27079. return this.getName();
  27080. // array punctuation
  27081. case 0x5B: // '['
  27082. this.nextChar();
  27083. return Cmd.get('[');
  27084. case 0x5D: // ']'
  27085. this.nextChar();
  27086. return Cmd.get(']');
  27087. // hex string or dict punctuation
  27088. case 0x3C: // '<'
  27089. ch = this.nextChar();
  27090. if (ch === 0x3C) {
  27091. // dict punctuation
  27092. this.nextChar();
  27093. return Cmd.get('<<');
  27094. }
  27095. return this.getHexString();
  27096. // dict punctuation
  27097. case 0x3E: // '>'
  27098. ch = this.nextChar();
  27099. if (ch === 0x3E) {
  27100. this.nextChar();
  27101. return Cmd.get('>>');
  27102. }
  27103. return Cmd.get('>');
  27104. case 0x7B: // '{'
  27105. this.nextChar();
  27106. return Cmd.get('{');
  27107. case 0x7D: // '}'
  27108. this.nextChar();
  27109. return Cmd.get('}');
  27110. case 0x29: // ')'
  27111. error('Illegal character: ' + ch);
  27112. break;
  27113. }
  27114. // command
  27115. var str = String.fromCharCode(ch);
  27116. var knownCommands = this.knownCommands;
  27117. var knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  27118. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  27119. // stop if known command is found and next character does not make
  27120. // the str a command
  27121. var possibleCommand = str + String.fromCharCode(ch);
  27122. if (knownCommandFound && knownCommands[possibleCommand] === undefined) {
  27123. break;
  27124. }
  27125. if (str.length === 128) {
  27126. error('Command token too long: ' + str.length);
  27127. }
  27128. str = possibleCommand;
  27129. knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  27130. }
  27131. if (str === 'true') {
  27132. return true;
  27133. }
  27134. if (str === 'false') {
  27135. return false;
  27136. }
  27137. if (str === 'null') {
  27138. return null;
  27139. }
  27140. return Cmd.get(str);
  27141. },
  27142. skipToNextLine: function Lexer_skipToNextLine() {
  27143. var ch = this.currentChar;
  27144. while (ch >= 0) {
  27145. if (ch === 0x0D) { // CR
  27146. ch = this.nextChar();
  27147. if (ch === 0x0A) { // LF
  27148. this.nextChar();
  27149. }
  27150. break;
  27151. } else if (ch === 0x0A) { // LF
  27152. this.nextChar();
  27153. break;
  27154. }
  27155. ch = this.nextChar();
  27156. }
  27157. }
  27158. };
  27159. return Lexer;
  27160. })();
  27161. var Linearization = {
  27162. create: function LinearizationCreate(stream) {
  27163. function getInt(name, allowZeroValue) {
  27164. var obj = linDict.get(name);
  27165. if (isInt(obj) && (allowZeroValue ? obj >= 0 : obj > 0)) {
  27166. return obj;
  27167. }
  27168. throw new Error('The "' + name + '" parameter in the linearization ' +
  27169. 'dictionary is invalid.');
  27170. }
  27171. function getHints() {
  27172. var hints = linDict.get('H'), hintsLength, item;
  27173. if (isArray(hints) &&
  27174. ((hintsLength = hints.length) === 2 || hintsLength === 4)) {
  27175. for (var index = 0; index < hintsLength; index++) {
  27176. if (!(isInt(item = hints[index]) && item > 0)) {
  27177. throw new Error('Hint (' + index +
  27178. ') in the linearization dictionary is invalid.');
  27179. }
  27180. }
  27181. return hints;
  27182. }
  27183. throw new Error('Hint array in the linearization dictionary is invalid.');
  27184. }
  27185. var parser = new Parser(new Lexer(stream), false, null);
  27186. var obj1 = parser.getObj();
  27187. var obj2 = parser.getObj();
  27188. var obj3 = parser.getObj();
  27189. var linDict = parser.getObj();
  27190. var obj, length;
  27191. if (!(isInt(obj1) && isInt(obj2) && isCmd(obj3, 'obj') && isDict(linDict) &&
  27192. isNum(obj = linDict.get('Linearized')) && obj > 0)) {
  27193. return null; // No valid linearization dictionary found.
  27194. } else if ((length = getInt('L')) !== stream.length) {
  27195. throw new Error('The "L" parameter in the linearization dictionary ' +
  27196. 'does not equal the stream length.');
  27197. }
  27198. return {
  27199. length: length,
  27200. hints: getHints(),
  27201. objectNumberFirst: getInt('O'),
  27202. endFirst: getInt('E'),
  27203. numPages: getInt('N'),
  27204. mainXRefEntriesOffset: getInt('T'),
  27205. pageFirst: (linDict.has('P') ? getInt('P', true) : 0)
  27206. };
  27207. }
  27208. };
  27209. exports.EOF = EOF;
  27210. exports.Lexer = Lexer;
  27211. exports.Linearization = Linearization;
  27212. exports.Parser = Parser;
  27213. exports.isEOF = isEOF;
  27214. // TODO refactor to remove dependency on stream.js
  27215. coreStream._setCoreParser(exports);
  27216. }));
  27217. (function (root, factory) {
  27218. {
  27219. factory((root.pdfjsCoreCMap = {}), root.pdfjsSharedUtil,
  27220. root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreParser);
  27221. }
  27222. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreParser) {
  27223. var Util = sharedUtil.Util;
  27224. var assert = sharedUtil.assert;
  27225. var error = sharedUtil.error;
  27226. var isInt = sharedUtil.isInt;
  27227. var isString = sharedUtil.isString;
  27228. var warn = sharedUtil.warn;
  27229. var isName = corePrimitives.isName;
  27230. var isCmd = corePrimitives.isCmd;
  27231. var isStream = corePrimitives.isStream;
  27232. var StringStream = coreStream.StringStream;
  27233. var Lexer = coreParser.Lexer;
  27234. var isEOF = coreParser.isEOF;
  27235. var BUILT_IN_CMAPS = [
  27236. // << Start unicode maps.
  27237. 'Adobe-GB1-UCS2',
  27238. 'Adobe-CNS1-UCS2',
  27239. 'Adobe-Japan1-UCS2',
  27240. 'Adobe-Korea1-UCS2',
  27241. // >> End unicode maps.
  27242. '78-EUC-H',
  27243. '78-EUC-V',
  27244. '78-H',
  27245. '78-RKSJ-H',
  27246. '78-RKSJ-V',
  27247. '78-V',
  27248. '78ms-RKSJ-H',
  27249. '78ms-RKSJ-V',
  27250. '83pv-RKSJ-H',
  27251. '90ms-RKSJ-H',
  27252. '90ms-RKSJ-V',
  27253. '90msp-RKSJ-H',
  27254. '90msp-RKSJ-V',
  27255. '90pv-RKSJ-H',
  27256. '90pv-RKSJ-V',
  27257. 'Add-H',
  27258. 'Add-RKSJ-H',
  27259. 'Add-RKSJ-V',
  27260. 'Add-V',
  27261. 'Adobe-CNS1-0',
  27262. 'Adobe-CNS1-1',
  27263. 'Adobe-CNS1-2',
  27264. 'Adobe-CNS1-3',
  27265. 'Adobe-CNS1-4',
  27266. 'Adobe-CNS1-5',
  27267. 'Adobe-CNS1-6',
  27268. 'Adobe-GB1-0',
  27269. 'Adobe-GB1-1',
  27270. 'Adobe-GB1-2',
  27271. 'Adobe-GB1-3',
  27272. 'Adobe-GB1-4',
  27273. 'Adobe-GB1-5',
  27274. 'Adobe-Japan1-0',
  27275. 'Adobe-Japan1-1',
  27276. 'Adobe-Japan1-2',
  27277. 'Adobe-Japan1-3',
  27278. 'Adobe-Japan1-4',
  27279. 'Adobe-Japan1-5',
  27280. 'Adobe-Japan1-6',
  27281. 'Adobe-Korea1-0',
  27282. 'Adobe-Korea1-1',
  27283. 'Adobe-Korea1-2',
  27284. 'B5-H',
  27285. 'B5-V',
  27286. 'B5pc-H',
  27287. 'B5pc-V',
  27288. 'CNS-EUC-H',
  27289. 'CNS-EUC-V',
  27290. 'CNS1-H',
  27291. 'CNS1-V',
  27292. 'CNS2-H',
  27293. 'CNS2-V',
  27294. 'ETHK-B5-H',
  27295. 'ETHK-B5-V',
  27296. 'ETen-B5-H',
  27297. 'ETen-B5-V',
  27298. 'ETenms-B5-H',
  27299. 'ETenms-B5-V',
  27300. 'EUC-H',
  27301. 'EUC-V',
  27302. 'Ext-H',
  27303. 'Ext-RKSJ-H',
  27304. 'Ext-RKSJ-V',
  27305. 'Ext-V',
  27306. 'GB-EUC-H',
  27307. 'GB-EUC-V',
  27308. 'GB-H',
  27309. 'GB-V',
  27310. 'GBK-EUC-H',
  27311. 'GBK-EUC-V',
  27312. 'GBK2K-H',
  27313. 'GBK2K-V',
  27314. 'GBKp-EUC-H',
  27315. 'GBKp-EUC-V',
  27316. 'GBT-EUC-H',
  27317. 'GBT-EUC-V',
  27318. 'GBT-H',
  27319. 'GBT-V',
  27320. 'GBTpc-EUC-H',
  27321. 'GBTpc-EUC-V',
  27322. 'GBpc-EUC-H',
  27323. 'GBpc-EUC-V',
  27324. 'H',
  27325. 'HKdla-B5-H',
  27326. 'HKdla-B5-V',
  27327. 'HKdlb-B5-H',
  27328. 'HKdlb-B5-V',
  27329. 'HKgccs-B5-H',
  27330. 'HKgccs-B5-V',
  27331. 'HKm314-B5-H',
  27332. 'HKm314-B5-V',
  27333. 'HKm471-B5-H',
  27334. 'HKm471-B5-V',
  27335. 'HKscs-B5-H',
  27336. 'HKscs-B5-V',
  27337. 'Hankaku',
  27338. 'Hiragana',
  27339. 'KSC-EUC-H',
  27340. 'KSC-EUC-V',
  27341. 'KSC-H',
  27342. 'KSC-Johab-H',
  27343. 'KSC-Johab-V',
  27344. 'KSC-V',
  27345. 'KSCms-UHC-H',
  27346. 'KSCms-UHC-HW-H',
  27347. 'KSCms-UHC-HW-V',
  27348. 'KSCms-UHC-V',
  27349. 'KSCpc-EUC-H',
  27350. 'KSCpc-EUC-V',
  27351. 'Katakana',
  27352. 'NWP-H',
  27353. 'NWP-V',
  27354. 'RKSJ-H',
  27355. 'RKSJ-V',
  27356. 'Roman',
  27357. 'UniCNS-UCS2-H',
  27358. 'UniCNS-UCS2-V',
  27359. 'UniCNS-UTF16-H',
  27360. 'UniCNS-UTF16-V',
  27361. 'UniCNS-UTF32-H',
  27362. 'UniCNS-UTF32-V',
  27363. 'UniCNS-UTF8-H',
  27364. 'UniCNS-UTF8-V',
  27365. 'UniGB-UCS2-H',
  27366. 'UniGB-UCS2-V',
  27367. 'UniGB-UTF16-H',
  27368. 'UniGB-UTF16-V',
  27369. 'UniGB-UTF32-H',
  27370. 'UniGB-UTF32-V',
  27371. 'UniGB-UTF8-H',
  27372. 'UniGB-UTF8-V',
  27373. 'UniJIS-UCS2-H',
  27374. 'UniJIS-UCS2-HW-H',
  27375. 'UniJIS-UCS2-HW-V',
  27376. 'UniJIS-UCS2-V',
  27377. 'UniJIS-UTF16-H',
  27378. 'UniJIS-UTF16-V',
  27379. 'UniJIS-UTF32-H',
  27380. 'UniJIS-UTF32-V',
  27381. 'UniJIS-UTF8-H',
  27382. 'UniJIS-UTF8-V',
  27383. 'UniJIS2004-UTF16-H',
  27384. 'UniJIS2004-UTF16-V',
  27385. 'UniJIS2004-UTF32-H',
  27386. 'UniJIS2004-UTF32-V',
  27387. 'UniJIS2004-UTF8-H',
  27388. 'UniJIS2004-UTF8-V',
  27389. 'UniJISPro-UCS2-HW-V',
  27390. 'UniJISPro-UCS2-V',
  27391. 'UniJISPro-UTF8-V',
  27392. 'UniJISX0213-UTF32-H',
  27393. 'UniJISX0213-UTF32-V',
  27394. 'UniJISX02132004-UTF32-H',
  27395. 'UniJISX02132004-UTF32-V',
  27396. 'UniKS-UCS2-H',
  27397. 'UniKS-UCS2-V',
  27398. 'UniKS-UTF16-H',
  27399. 'UniKS-UTF16-V',
  27400. 'UniKS-UTF32-H',
  27401. 'UniKS-UTF32-V',
  27402. 'UniKS-UTF8-H',
  27403. 'UniKS-UTF8-V',
  27404. 'V',
  27405. 'WP-Symbol'];
  27406. // CMap, not to be confused with TrueType's cmap.
  27407. var CMap = (function CMapClosure() {
  27408. function CMap(builtInCMap) {
  27409. // Codespace ranges are stored as follows:
  27410. // [[1BytePairs], [2BytePairs], [3BytePairs], [4BytePairs]]
  27411. // where nBytePairs are ranges e.g. [low1, high1, low2, high2, ...]
  27412. this.codespaceRanges = [[], [], [], []];
  27413. this.numCodespaceRanges = 0;
  27414. // Map entries have one of two forms.
  27415. // - cid chars are 16-bit unsigned integers, stored as integers.
  27416. // - bf chars are variable-length byte sequences, stored as strings, with
  27417. // one byte per character.
  27418. this._map = [];
  27419. this.name = '';
  27420. this.vertical = false;
  27421. this.useCMap = null;
  27422. this.builtInCMap = builtInCMap;
  27423. }
  27424. CMap.prototype = {
  27425. addCodespaceRange: function(n, low, high) {
  27426. this.codespaceRanges[n - 1].push(low, high);
  27427. this.numCodespaceRanges++;
  27428. },
  27429. mapCidRange: function(low, high, dstLow) {
  27430. while (low <= high) {
  27431. this._map[low++] = dstLow++;
  27432. }
  27433. },
  27434. mapBfRange: function(low, high, dstLow) {
  27435. var lastByte = dstLow.length - 1;
  27436. while (low <= high) {
  27437. this._map[low++] = dstLow;
  27438. // Only the last byte has to be incremented.
  27439. dstLow = dstLow.substr(0, lastByte) +
  27440. String.fromCharCode(dstLow.charCodeAt(lastByte) + 1);
  27441. }
  27442. },
  27443. mapBfRangeToArray: function(low, high, array) {
  27444. var i = 0, ii = array.length;
  27445. while (low <= high && i < ii) {
  27446. this._map[low] = array[i++];
  27447. ++low;
  27448. }
  27449. },
  27450. // This is used for both bf and cid chars.
  27451. mapOne: function(src, dst) {
  27452. this._map[src] = dst;
  27453. },
  27454. lookup: function(code) {
  27455. return this._map[code];
  27456. },
  27457. contains: function(code) {
  27458. return this._map[code] !== undefined;
  27459. },
  27460. forEach: function(callback) {
  27461. // Most maps have fewer than 65536 entries, and for those we use normal
  27462. // array iteration. But really sparse tables are possible -- e.g. with
  27463. // indices in the *billions*. For such tables we use for..in, which isn't
  27464. // ideal because it stringifies the indices for all present elements, but
  27465. // it does avoid iterating over every undefined entry.
  27466. var map = this._map;
  27467. var length = map.length;
  27468. var i;
  27469. if (length <= 0x10000) {
  27470. for (i = 0; i < length; i++) {
  27471. if (map[i] !== undefined) {
  27472. callback(i, map[i]);
  27473. }
  27474. }
  27475. } else {
  27476. for (i in this._map) {
  27477. callback(i, map[i]);
  27478. }
  27479. }
  27480. },
  27481. charCodeOf: function(value) {
  27482. return this._map.indexOf(value);
  27483. },
  27484. getMap: function() {
  27485. return this._map;
  27486. },
  27487. readCharCode: function(str, offset, out) {
  27488. var c = 0;
  27489. var codespaceRanges = this.codespaceRanges;
  27490. var codespaceRangesLen = this.codespaceRanges.length;
  27491. // 9.7.6.2 CMap Mapping
  27492. // The code length is at most 4.
  27493. for (var n = 0; n < codespaceRangesLen; n++) {
  27494. c = ((c << 8) | str.charCodeAt(offset + n)) >>> 0;
  27495. // Check each codespace range to see if it falls within.
  27496. var codespaceRange = codespaceRanges[n];
  27497. for (var k = 0, kk = codespaceRange.length; k < kk;) {
  27498. var low = codespaceRange[k++];
  27499. var high = codespaceRange[k++];
  27500. if (c >= low && c <= high) {
  27501. out.charcode = c;
  27502. out.length = n + 1;
  27503. return;
  27504. }
  27505. }
  27506. }
  27507. out.charcode = 0;
  27508. out.length = 1;
  27509. },
  27510. get length() {
  27511. return this._map.length;
  27512. },
  27513. get isIdentityCMap() {
  27514. if (!(this.name === 'Identity-H' || this.name === 'Identity-V')) {
  27515. return false;
  27516. }
  27517. if (this._map.length !== 0x10000) {
  27518. return false;
  27519. }
  27520. for (var i = 0; i < 0x10000; i++) {
  27521. if (this._map[i] !== i) {
  27522. return false;
  27523. }
  27524. }
  27525. return true;
  27526. }
  27527. };
  27528. return CMap;
  27529. })();
  27530. // A special case of CMap, where the _map array implicitly has a length of
  27531. // 65536 and each element is equal to its index.
  27532. var IdentityCMap = (function IdentityCMapClosure() {
  27533. function IdentityCMap(vertical, n) {
  27534. CMap.call(this);
  27535. this.vertical = vertical;
  27536. this.addCodespaceRange(n, 0, 0xffff);
  27537. }
  27538. Util.inherit(IdentityCMap, CMap, {});
  27539. IdentityCMap.prototype = {
  27540. addCodespaceRange: CMap.prototype.addCodespaceRange,
  27541. mapCidRange: function(low, high, dstLow) {
  27542. error('should not call mapCidRange');
  27543. },
  27544. mapBfRange: function(low, high, dstLow) {
  27545. error('should not call mapBfRange');
  27546. },
  27547. mapBfRangeToArray: function(low, high, array) {
  27548. error('should not call mapBfRangeToArray');
  27549. },
  27550. mapOne: function(src, dst) {
  27551. error('should not call mapCidOne');
  27552. },
  27553. lookup: function(code) {
  27554. return (isInt(code) && code <= 0xffff) ? code : undefined;
  27555. },
  27556. contains: function(code) {
  27557. return isInt(code) && code <= 0xffff;
  27558. },
  27559. forEach: function(callback) {
  27560. for (var i = 0; i <= 0xffff; i++) {
  27561. callback(i, i);
  27562. }
  27563. },
  27564. charCodeOf: function(value) {
  27565. return (isInt(value) && value <= 0xffff) ? value : -1;
  27566. },
  27567. getMap: function() {
  27568. // Sometimes identity maps must be instantiated, but it's rare.
  27569. var map = new Array(0x10000);
  27570. for (var i = 0; i <= 0xffff; i++) {
  27571. map[i] = i;
  27572. }
  27573. return map;
  27574. },
  27575. readCharCode: CMap.prototype.readCharCode,
  27576. get length() {
  27577. return 0x10000;
  27578. },
  27579. get isIdentityCMap() {
  27580. error('should not access .isIdentityCMap');
  27581. }
  27582. };
  27583. return IdentityCMap;
  27584. })();
  27585. var BinaryCMapReader = (function BinaryCMapReaderClosure() {
  27586. function fetchBinaryData(url) {
  27587. var nonBinaryRequest = PDFJS.disableWorker;
  27588. var request = new XMLHttpRequest();
  27589. request.open('GET', url, false);
  27590. if (!nonBinaryRequest) {
  27591. try {
  27592. request.responseType = 'arraybuffer';
  27593. nonBinaryRequest = request.responseType !== 'arraybuffer';
  27594. } catch (e) {
  27595. nonBinaryRequest = true;
  27596. }
  27597. }
  27598. if (nonBinaryRequest && request.overrideMimeType) {
  27599. request.overrideMimeType('text/plain; charset=x-user-defined');
  27600. }
  27601. request.send(null);
  27602. if (nonBinaryRequest ? !request.responseText : !request.response) {
  27603. error('Unable to get binary cMap at: ' + url);
  27604. }
  27605. if (nonBinaryRequest) {
  27606. var data = Array.prototype.map.call(request.responseText, function (ch) {
  27607. return ch.charCodeAt(0) & 255;
  27608. });
  27609. return new Uint8Array(data);
  27610. }
  27611. return new Uint8Array(request.response);
  27612. }
  27613. function hexToInt(a, size) {
  27614. var n = 0;
  27615. for (var i = 0; i <= size; i++) {
  27616. n = (n << 8) | a[i];
  27617. }
  27618. return n >>> 0;
  27619. }
  27620. function hexToStr(a, size) {
  27621. // This code is hot. Special-case some common values to avoid creating an
  27622. // object with subarray().
  27623. if (size === 1) {
  27624. return String.fromCharCode(a[0], a[1]);
  27625. }
  27626. if (size === 3) {
  27627. return String.fromCharCode(a[0], a[1], a[2], a[3]);
  27628. }
  27629. return String.fromCharCode.apply(null, a.subarray(0, size + 1));
  27630. }
  27631. function addHex(a, b, size) {
  27632. var c = 0;
  27633. for (var i = size; i >= 0; i--) {
  27634. c += a[i] + b[i];
  27635. a[i] = c & 255;
  27636. c >>= 8;
  27637. }
  27638. }
  27639. function incHex(a, size) {
  27640. var c = 1;
  27641. for (var i = size; i >= 0 && c > 0; i--) {
  27642. c += a[i];
  27643. a[i] = c & 255;
  27644. c >>= 8;
  27645. }
  27646. }
  27647. var MAX_NUM_SIZE = 16;
  27648. var MAX_ENCODED_NUM_SIZE = 19; // ceil(MAX_NUM_SIZE * 7 / 8)
  27649. function BinaryCMapStream(data) {
  27650. this.buffer = data;
  27651. this.pos = 0;
  27652. this.end = data.length;
  27653. this.tmpBuf = new Uint8Array(MAX_ENCODED_NUM_SIZE);
  27654. }
  27655. BinaryCMapStream.prototype = {
  27656. readByte: function () {
  27657. if (this.pos >= this.end) {
  27658. return -1;
  27659. }
  27660. return this.buffer[this.pos++];
  27661. },
  27662. readNumber: function () {
  27663. var n = 0;
  27664. var last;
  27665. do {
  27666. var b = this.readByte();
  27667. if (b < 0) {
  27668. error('unexpected EOF in bcmap');
  27669. }
  27670. last = !(b & 0x80);
  27671. n = (n << 7) | (b & 0x7F);
  27672. } while (!last);
  27673. return n;
  27674. },
  27675. readSigned: function () {
  27676. var n = this.readNumber();
  27677. return (n & 1) ? ~(n >>> 1) : n >>> 1;
  27678. },
  27679. readHex: function (num, size) {
  27680. num.set(this.buffer.subarray(this.pos,
  27681. this.pos + size + 1));
  27682. this.pos += size + 1;
  27683. },
  27684. readHexNumber: function (num, size) {
  27685. var last;
  27686. var stack = this.tmpBuf, sp = 0;
  27687. do {
  27688. var b = this.readByte();
  27689. if (b < 0) {
  27690. error('unexpected EOF in bcmap');
  27691. }
  27692. last = !(b & 0x80);
  27693. stack[sp++] = b & 0x7F;
  27694. } while (!last);
  27695. var i = size, buffer = 0, bufferSize = 0;
  27696. while (i >= 0) {
  27697. while (bufferSize < 8 && stack.length > 0) {
  27698. buffer = (stack[--sp] << bufferSize) | buffer;
  27699. bufferSize += 7;
  27700. }
  27701. num[i] = buffer & 255;
  27702. i--;
  27703. buffer >>= 8;
  27704. bufferSize -= 8;
  27705. }
  27706. },
  27707. readHexSigned: function (num, size) {
  27708. this.readHexNumber(num, size);
  27709. var sign = num[size] & 1 ? 255 : 0;
  27710. var c = 0;
  27711. for (var i = 0; i <= size; i++) {
  27712. c = ((c & 1) << 8) | num[i];
  27713. num[i] = (c >> 1) ^ sign;
  27714. }
  27715. },
  27716. readString: function () {
  27717. var len = this.readNumber();
  27718. var s = '';
  27719. for (var i = 0; i < len; i++) {
  27720. s += String.fromCharCode(this.readNumber());
  27721. }
  27722. return s;
  27723. }
  27724. };
  27725. function processBinaryCMap(url, cMap, extend) {
  27726. var data = fetchBinaryData(url);
  27727. var stream = new BinaryCMapStream(data);
  27728. var header = stream.readByte();
  27729. cMap.vertical = !!(header & 1);
  27730. var useCMap = null;
  27731. var start = new Uint8Array(MAX_NUM_SIZE);
  27732. var end = new Uint8Array(MAX_NUM_SIZE);
  27733. var char = new Uint8Array(MAX_NUM_SIZE);
  27734. var charCode = new Uint8Array(MAX_NUM_SIZE);
  27735. var tmp = new Uint8Array(MAX_NUM_SIZE);
  27736. var code;
  27737. var b;
  27738. while ((b = stream.readByte()) >= 0) {
  27739. var type = b >> 5;
  27740. if (type === 7) { // metadata, e.g. comment or usecmap
  27741. switch (b & 0x1F) {
  27742. case 0:
  27743. stream.readString(); // skipping comment
  27744. break;
  27745. case 1:
  27746. useCMap = stream.readString();
  27747. break;
  27748. }
  27749. continue;
  27750. }
  27751. var sequence = !!(b & 0x10);
  27752. var dataSize = b & 15;
  27753. assert(dataSize + 1 <= MAX_NUM_SIZE);
  27754. var ucs2DataSize = 1;
  27755. var subitemsCount = stream.readNumber();
  27756. var i;
  27757. switch (type) {
  27758. case 0: // codespacerange
  27759. stream.readHex(start, dataSize);
  27760. stream.readHexNumber(end, dataSize);
  27761. addHex(end, start, dataSize);
  27762. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
  27763. hexToInt(end, dataSize));
  27764. for (i = 1; i < subitemsCount; i++) {
  27765. incHex(end, dataSize);
  27766. stream.readHexNumber(start, dataSize);
  27767. addHex(start, end, dataSize);
  27768. stream.readHexNumber(end, dataSize);
  27769. addHex(end, start, dataSize);
  27770. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
  27771. hexToInt(end, dataSize));
  27772. }
  27773. break;
  27774. case 1: // notdefrange
  27775. stream.readHex(start, dataSize);
  27776. stream.readHexNumber(end, dataSize);
  27777. addHex(end, start, dataSize);
  27778. code = stream.readNumber();
  27779. // undefined range, skipping
  27780. for (i = 1; i < subitemsCount; i++) {
  27781. incHex(end, dataSize);
  27782. stream.readHexNumber(start, dataSize);
  27783. addHex(start, end, dataSize);
  27784. stream.readHexNumber(end, dataSize);
  27785. addHex(end, start, dataSize);
  27786. code = stream.readNumber();
  27787. // nop
  27788. }
  27789. break;
  27790. case 2: // cidchar
  27791. stream.readHex(char, dataSize);
  27792. code = stream.readNumber();
  27793. cMap.mapOne(hexToInt(char, dataSize), code);
  27794. for (i = 1; i < subitemsCount; i++) {
  27795. incHex(char, dataSize);
  27796. if (!sequence) {
  27797. stream.readHexNumber(tmp, dataSize);
  27798. addHex(char, tmp, dataSize);
  27799. }
  27800. code = stream.readSigned() + (code + 1);
  27801. cMap.mapOne(hexToInt(char, dataSize), code);
  27802. }
  27803. break;
  27804. case 3: // cidrange
  27805. stream.readHex(start, dataSize);
  27806. stream.readHexNumber(end, dataSize);
  27807. addHex(end, start, dataSize);
  27808. code = stream.readNumber();
  27809. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize),
  27810. code);
  27811. for (i = 1; i < subitemsCount; i++) {
  27812. incHex(end, dataSize);
  27813. if (!sequence) {
  27814. stream.readHexNumber(start, dataSize);
  27815. addHex(start, end, dataSize);
  27816. } else {
  27817. start.set(end);
  27818. }
  27819. stream.readHexNumber(end, dataSize);
  27820. addHex(end, start, dataSize);
  27821. code = stream.readNumber();
  27822. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize),
  27823. code);
  27824. }
  27825. break;
  27826. case 4: // bfchar
  27827. stream.readHex(char, ucs2DataSize);
  27828. stream.readHex(charCode, dataSize);
  27829. cMap.mapOne(hexToInt(char, ucs2DataSize),
  27830. hexToStr(charCode, dataSize));
  27831. for (i = 1; i < subitemsCount; i++) {
  27832. incHex(char, ucs2DataSize);
  27833. if (!sequence) {
  27834. stream.readHexNumber(tmp, ucs2DataSize);
  27835. addHex(char, tmp, ucs2DataSize);
  27836. }
  27837. incHex(charCode, dataSize);
  27838. stream.readHexSigned(tmp, dataSize);
  27839. addHex(charCode, tmp, dataSize);
  27840. cMap.mapOne(hexToInt(char, ucs2DataSize),
  27841. hexToStr(charCode, dataSize));
  27842. }
  27843. break;
  27844. case 5: // bfrange
  27845. stream.readHex(start, ucs2DataSize);
  27846. stream.readHexNumber(end, ucs2DataSize);
  27847. addHex(end, start, ucs2DataSize);
  27848. stream.readHex(charCode, dataSize);
  27849. cMap.mapBfRange(hexToInt(start, ucs2DataSize),
  27850. hexToInt(end, ucs2DataSize),
  27851. hexToStr(charCode, dataSize));
  27852. for (i = 1; i < subitemsCount; i++) {
  27853. incHex(end, ucs2DataSize);
  27854. if (!sequence) {
  27855. stream.readHexNumber(start, ucs2DataSize);
  27856. addHex(start, end, ucs2DataSize);
  27857. } else {
  27858. start.set(end);
  27859. }
  27860. stream.readHexNumber(end, ucs2DataSize);
  27861. addHex(end, start, ucs2DataSize);
  27862. stream.readHex(charCode, dataSize);
  27863. cMap.mapBfRange(hexToInt(start, ucs2DataSize),
  27864. hexToInt(end, ucs2DataSize),
  27865. hexToStr(charCode, dataSize));
  27866. }
  27867. break;
  27868. default:
  27869. error('Unknown type: ' + type);
  27870. break;
  27871. }
  27872. }
  27873. if (useCMap) {
  27874. extend(useCMap);
  27875. }
  27876. return cMap;
  27877. }
  27878. function BinaryCMapReader() {}
  27879. BinaryCMapReader.prototype = {
  27880. read: processBinaryCMap
  27881. };
  27882. return BinaryCMapReader;
  27883. })();
  27884. var CMapFactory = (function CMapFactoryClosure() {
  27885. function strToInt(str) {
  27886. var a = 0;
  27887. for (var i = 0; i < str.length; i++) {
  27888. a = (a << 8) | str.charCodeAt(i);
  27889. }
  27890. return a >>> 0;
  27891. }
  27892. function expectString(obj) {
  27893. if (!isString(obj)) {
  27894. error('Malformed CMap: expected string.');
  27895. }
  27896. }
  27897. function expectInt(obj) {
  27898. if (!isInt(obj)) {
  27899. error('Malformed CMap: expected int.');
  27900. }
  27901. }
  27902. function parseBfChar(cMap, lexer) {
  27903. while (true) {
  27904. var obj = lexer.getObj();
  27905. if (isEOF(obj)) {
  27906. break;
  27907. }
  27908. if (isCmd(obj, 'endbfchar')) {
  27909. return;
  27910. }
  27911. expectString(obj);
  27912. var src = strToInt(obj);
  27913. obj = lexer.getObj();
  27914. // TODO are /dstName used?
  27915. expectString(obj);
  27916. var dst = obj;
  27917. cMap.mapOne(src, dst);
  27918. }
  27919. }
  27920. function parseBfRange(cMap, lexer) {
  27921. while (true) {
  27922. var obj = lexer.getObj();
  27923. if (isEOF(obj)) {
  27924. break;
  27925. }
  27926. if (isCmd(obj, 'endbfrange')) {
  27927. return;
  27928. }
  27929. expectString(obj);
  27930. var low = strToInt(obj);
  27931. obj = lexer.getObj();
  27932. expectString(obj);
  27933. var high = strToInt(obj);
  27934. obj = lexer.getObj();
  27935. if (isInt(obj) || isString(obj)) {
  27936. var dstLow = isInt(obj) ? String.fromCharCode(obj) : obj;
  27937. cMap.mapBfRange(low, high, dstLow);
  27938. } else if (isCmd(obj, '[')) {
  27939. obj = lexer.getObj();
  27940. var array = [];
  27941. while (!isCmd(obj, ']') && !isEOF(obj)) {
  27942. array.push(obj);
  27943. obj = lexer.getObj();
  27944. }
  27945. cMap.mapBfRangeToArray(low, high, array);
  27946. } else {
  27947. break;
  27948. }
  27949. }
  27950. error('Invalid bf range.');
  27951. }
  27952. function parseCidChar(cMap, lexer) {
  27953. while (true) {
  27954. var obj = lexer.getObj();
  27955. if (isEOF(obj)) {
  27956. break;
  27957. }
  27958. if (isCmd(obj, 'endcidchar')) {
  27959. return;
  27960. }
  27961. expectString(obj);
  27962. var src = strToInt(obj);
  27963. obj = lexer.getObj();
  27964. expectInt(obj);
  27965. var dst = obj;
  27966. cMap.mapOne(src, dst);
  27967. }
  27968. }
  27969. function parseCidRange(cMap, lexer) {
  27970. while (true) {
  27971. var obj = lexer.getObj();
  27972. if (isEOF(obj)) {
  27973. break;
  27974. }
  27975. if (isCmd(obj, 'endcidrange')) {
  27976. return;
  27977. }
  27978. expectString(obj);
  27979. var low = strToInt(obj);
  27980. obj = lexer.getObj();
  27981. expectString(obj);
  27982. var high = strToInt(obj);
  27983. obj = lexer.getObj();
  27984. expectInt(obj);
  27985. var dstLow = obj;
  27986. cMap.mapCidRange(low, high, dstLow);
  27987. }
  27988. }
  27989. function parseCodespaceRange(cMap, lexer) {
  27990. while (true) {
  27991. var obj = lexer.getObj();
  27992. if (isEOF(obj)) {
  27993. break;
  27994. }
  27995. if (isCmd(obj, 'endcodespacerange')) {
  27996. return;
  27997. }
  27998. if (!isString(obj)) {
  27999. break;
  28000. }
  28001. var low = strToInt(obj);
  28002. obj = lexer.getObj();
  28003. if (!isString(obj)) {
  28004. break;
  28005. }
  28006. var high = strToInt(obj);
  28007. cMap.addCodespaceRange(obj.length, low, high);
  28008. }
  28009. error('Invalid codespace range.');
  28010. }
  28011. function parseWMode(cMap, lexer) {
  28012. var obj = lexer.getObj();
  28013. if (isInt(obj)) {
  28014. cMap.vertical = !!obj;
  28015. }
  28016. }
  28017. function parseCMapName(cMap, lexer) {
  28018. var obj = lexer.getObj();
  28019. if (isName(obj) && isString(obj.name)) {
  28020. cMap.name = obj.name;
  28021. }
  28022. }
  28023. function parseCMap(cMap, lexer, builtInCMapParams, useCMap) {
  28024. var previous;
  28025. var embededUseCMap;
  28026. objLoop: while (true) {
  28027. var obj = lexer.getObj();
  28028. if (isEOF(obj)) {
  28029. break;
  28030. } else if (isName(obj)) {
  28031. if (obj.name === 'WMode') {
  28032. parseWMode(cMap, lexer);
  28033. } else if (obj.name === 'CMapName') {
  28034. parseCMapName(cMap, lexer);
  28035. }
  28036. previous = obj;
  28037. } else if (isCmd(obj)) {
  28038. switch (obj.cmd) {
  28039. case 'endcmap':
  28040. break objLoop;
  28041. case 'usecmap':
  28042. if (isName(previous)) {
  28043. embededUseCMap = previous.name;
  28044. }
  28045. break;
  28046. case 'begincodespacerange':
  28047. parseCodespaceRange(cMap, lexer);
  28048. break;
  28049. case 'beginbfchar':
  28050. parseBfChar(cMap, lexer);
  28051. break;
  28052. case 'begincidchar':
  28053. parseCidChar(cMap, lexer);
  28054. break;
  28055. case 'beginbfrange':
  28056. parseBfRange(cMap, lexer);
  28057. break;
  28058. case 'begincidrange':
  28059. parseCidRange(cMap, lexer);
  28060. break;
  28061. }
  28062. }
  28063. }
  28064. if (!useCMap && embededUseCMap) {
  28065. // Load the usecmap definition from the file only if there wasn't one
  28066. // specified.
  28067. useCMap = embededUseCMap;
  28068. }
  28069. if (useCMap) {
  28070. extendCMap(cMap, builtInCMapParams, useCMap);
  28071. }
  28072. }
  28073. function extendCMap(cMap, builtInCMapParams, useCMap) {
  28074. cMap.useCMap = createBuiltInCMap(useCMap, builtInCMapParams);
  28075. // If there aren't any code space ranges defined clone all the parent ones
  28076. // into this cMap.
  28077. if (cMap.numCodespaceRanges === 0) {
  28078. var useCodespaceRanges = cMap.useCMap.codespaceRanges;
  28079. for (var i = 0; i < useCodespaceRanges.length; i++) {
  28080. cMap.codespaceRanges[i] = useCodespaceRanges[i].slice();
  28081. }
  28082. cMap.numCodespaceRanges = cMap.useCMap.numCodespaceRanges;
  28083. }
  28084. // Merge the map into the current one, making sure not to override
  28085. // any previously defined entries.
  28086. cMap.useCMap.forEach(function(key, value) {
  28087. if (!cMap.contains(key)) {
  28088. cMap.mapOne(key, cMap.useCMap.lookup(key));
  28089. }
  28090. });
  28091. }
  28092. function parseBinaryCMap(name, builtInCMapParams) {
  28093. var url = builtInCMapParams.url + name + '.bcmap';
  28094. var cMap = new CMap(true);
  28095. new BinaryCMapReader().read(url, cMap, function (useCMap) {
  28096. extendCMap(cMap, builtInCMapParams, useCMap);
  28097. });
  28098. return cMap;
  28099. }
  28100. function createBuiltInCMap(name, builtInCMapParams) {
  28101. if (name === 'Identity-H') {
  28102. return new IdentityCMap(false, 2);
  28103. } else if (name === 'Identity-V') {
  28104. return new IdentityCMap(true, 2);
  28105. }
  28106. if (BUILT_IN_CMAPS.indexOf(name) === -1) {
  28107. error('Unknown cMap name: ' + name);
  28108. }
  28109. assert(builtInCMapParams, 'built-in cMap parameters are not provided');
  28110. if (builtInCMapParams.packed) {
  28111. return parseBinaryCMap(name, builtInCMapParams);
  28112. }
  28113. var request = new XMLHttpRequest();
  28114. var url = builtInCMapParams.url + name;
  28115. request.open('GET', url, false);
  28116. request.send(null);
  28117. if (!request.responseText) {
  28118. error('Unable to get cMap at: ' + url);
  28119. }
  28120. var cMap = new CMap(true);
  28121. var lexer = new Lexer(new StringStream(request.responseText));
  28122. parseCMap(cMap, lexer, builtInCMapParams, null);
  28123. return cMap;
  28124. }
  28125. return {
  28126. create: function (encoding, builtInCMapParams, useCMap) {
  28127. if (isName(encoding)) {
  28128. return createBuiltInCMap(encoding.name, builtInCMapParams);
  28129. } else if (isStream(encoding)) {
  28130. var cMap = new CMap();
  28131. var lexer = new Lexer(encoding);
  28132. try {
  28133. parseCMap(cMap, lexer, builtInCMapParams, useCMap);
  28134. } catch (e) {
  28135. warn('Invalid CMap data. ' + e);
  28136. }
  28137. if (cMap.isIdentityCMap) {
  28138. return createBuiltInCMap(cMap.name, builtInCMapParams);
  28139. }
  28140. return cMap;
  28141. }
  28142. error('Encoding required.');
  28143. }
  28144. };
  28145. })();
  28146. exports.CMap = CMap;
  28147. exports.CMapFactory = CMapFactory;
  28148. exports.IdentityCMap = IdentityCMap;
  28149. }));
  28150. (function (root, factory) {
  28151. {
  28152. factory((root.pdfjsCoreObj = {}), root.pdfjsSharedUtil,
  28153. root.pdfjsCorePrimitives, root.pdfjsCoreCrypto, root.pdfjsCoreParser,
  28154. root.pdfjsCoreChunkedStream);
  28155. }
  28156. }(this, function (exports, sharedUtil, corePrimitives, coreCrypto, coreParser,
  28157. coreChunkedStream) {
  28158. var InvalidPDFException = sharedUtil.InvalidPDFException;
  28159. var MissingDataException = sharedUtil.MissingDataException;
  28160. var XRefParseException = sharedUtil.XRefParseException;
  28161. var assert = sharedUtil.assert;
  28162. var bytesToString = sharedUtil.bytesToString;
  28163. var createPromiseCapability = sharedUtil.createPromiseCapability;
  28164. var error = sharedUtil.error;
  28165. var info = sharedUtil.info;
  28166. var isArray = sharedUtil.isArray;
  28167. var isInt = sharedUtil.isInt;
  28168. var isString = sharedUtil.isString;
  28169. var shadow = sharedUtil.shadow;
  28170. var stringToPDFString = sharedUtil.stringToPDFString;
  28171. var stringToUTF8String = sharedUtil.stringToUTF8String;
  28172. var warn = sharedUtil.warn;
  28173. var Ref = corePrimitives.Ref;
  28174. var RefSet = corePrimitives.RefSet;
  28175. var RefSetCache = corePrimitives.RefSetCache;
  28176. var isName = corePrimitives.isName;
  28177. var isCmd = corePrimitives.isCmd;
  28178. var isDict = corePrimitives.isDict;
  28179. var isRef = corePrimitives.isRef;
  28180. var isStream = corePrimitives.isStream;
  28181. var CipherTransformFactory = coreCrypto.CipherTransformFactory;
  28182. var Lexer = coreParser.Lexer;
  28183. var Parser = coreParser.Parser;
  28184. var ChunkedStream = coreChunkedStream.ChunkedStream;
  28185. var Catalog = (function CatalogClosure() {
  28186. function Catalog(pdfManager, xref, pageFactory) {
  28187. this.pdfManager = pdfManager;
  28188. this.xref = xref;
  28189. this.catDict = xref.getCatalogObj();
  28190. this.fontCache = new RefSetCache();
  28191. assert(isDict(this.catDict),
  28192. 'catalog object is not a dictionary');
  28193. // TODO refactor to move getPage() to the PDFDocument.
  28194. this.pageFactory = pageFactory;
  28195. this.pagePromises = [];
  28196. }
  28197. Catalog.prototype = {
  28198. get metadata() {
  28199. var streamRef = this.catDict.getRaw('Metadata');
  28200. if (!isRef(streamRef)) {
  28201. return shadow(this, 'metadata', null);
  28202. }
  28203. var encryptMetadata = (!this.xref.encrypt ? false :
  28204. this.xref.encrypt.encryptMetadata);
  28205. var stream = this.xref.fetch(streamRef, !encryptMetadata);
  28206. var metadata;
  28207. if (stream && isDict(stream.dict)) {
  28208. var type = stream.dict.get('Type');
  28209. var subtype = stream.dict.get('Subtype');
  28210. if (isName(type) && isName(subtype) &&
  28211. type.name === 'Metadata' && subtype.name === 'XML') {
  28212. // XXX: This should examine the charset the XML document defines,
  28213. // however since there are currently no real means to decode
  28214. // arbitrary charsets, let's just hope that the author of the PDF
  28215. // was reasonable enough to stick with the XML default charset,
  28216. // which is UTF-8.
  28217. try {
  28218. metadata = stringToUTF8String(bytesToString(stream.getBytes()));
  28219. } catch (e) {
  28220. info('Skipping invalid metadata.');
  28221. }
  28222. }
  28223. }
  28224. return shadow(this, 'metadata', metadata);
  28225. },
  28226. get toplevelPagesDict() {
  28227. var pagesObj = this.catDict.get('Pages');
  28228. assert(isDict(pagesObj), 'invalid top-level pages dictionary');
  28229. // shadow the prototype getter
  28230. return shadow(this, 'toplevelPagesDict', pagesObj);
  28231. },
  28232. get documentOutline() {
  28233. var obj = null;
  28234. try {
  28235. obj = this.readDocumentOutline();
  28236. } catch (ex) {
  28237. if (ex instanceof MissingDataException) {
  28238. throw ex;
  28239. }
  28240. warn('Unable to read document outline');
  28241. }
  28242. return shadow(this, 'documentOutline', obj);
  28243. },
  28244. readDocumentOutline: function Catalog_readDocumentOutline() {
  28245. var xref = this.xref;
  28246. var obj = this.catDict.get('Outlines');
  28247. var root = { items: [] };
  28248. if (isDict(obj)) {
  28249. obj = obj.getRaw('First');
  28250. var processed = new RefSet();
  28251. if (isRef(obj)) {
  28252. var queue = [{obj: obj, parent: root}];
  28253. // to avoid recursion keeping track of the items
  28254. // in the processed dictionary
  28255. processed.put(obj);
  28256. while (queue.length > 0) {
  28257. var i = queue.shift();
  28258. var outlineDict = xref.fetchIfRef(i.obj);
  28259. if (outlineDict === null) {
  28260. continue;
  28261. }
  28262. if (!outlineDict.has('Title')) {
  28263. error('Invalid outline item');
  28264. }
  28265. var dest = outlineDict.get('A');
  28266. if (dest) {
  28267. dest = dest.get('D');
  28268. } else if (outlineDict.has('Dest')) {
  28269. dest = outlineDict.getRaw('Dest');
  28270. if (isName(dest)) {
  28271. dest = dest.name;
  28272. }
  28273. }
  28274. var title = outlineDict.get('Title');
  28275. var outlineItem = {
  28276. dest: dest,
  28277. title: stringToPDFString(title),
  28278. color: outlineDict.get('C') || [0, 0, 0],
  28279. count: outlineDict.get('Count'),
  28280. bold: !!(outlineDict.get('F') & 2),
  28281. italic: !!(outlineDict.get('F') & 1),
  28282. items: []
  28283. };
  28284. i.parent.items.push(outlineItem);
  28285. obj = outlineDict.getRaw('First');
  28286. if (isRef(obj) && !processed.has(obj)) {
  28287. queue.push({obj: obj, parent: outlineItem});
  28288. processed.put(obj);
  28289. }
  28290. obj = outlineDict.getRaw('Next');
  28291. if (isRef(obj) && !processed.has(obj)) {
  28292. queue.push({obj: obj, parent: i.parent});
  28293. processed.put(obj);
  28294. }
  28295. }
  28296. }
  28297. }
  28298. return (root.items.length > 0 ? root.items : null);
  28299. },
  28300. get numPages() {
  28301. var obj = this.toplevelPagesDict.get('Count');
  28302. assert(
  28303. isInt(obj),
  28304. 'page count in top level pages object is not an integer'
  28305. );
  28306. // shadow the prototype getter
  28307. return shadow(this, 'num', obj);
  28308. },
  28309. get destinations() {
  28310. function fetchDestination(dest) {
  28311. return isDict(dest) ? dest.get('D') : dest;
  28312. }
  28313. var xref = this.xref;
  28314. var dests = {}, nameTreeRef, nameDictionaryRef;
  28315. var obj = this.catDict.get('Names');
  28316. if (obj && obj.has('Dests')) {
  28317. nameTreeRef = obj.getRaw('Dests');
  28318. } else if (this.catDict.has('Dests')) {
  28319. nameDictionaryRef = this.catDict.get('Dests');
  28320. }
  28321. if (nameDictionaryRef) {
  28322. // reading simple destination dictionary
  28323. obj = nameDictionaryRef;
  28324. obj.forEach(function catalogForEach(key, value) {
  28325. if (!value) {
  28326. return;
  28327. }
  28328. dests[key] = fetchDestination(value);
  28329. });
  28330. }
  28331. if (nameTreeRef) {
  28332. var nameTree = new NameTree(nameTreeRef, xref);
  28333. var names = nameTree.getAll();
  28334. for (var name in names) {
  28335. if (!names.hasOwnProperty(name)) {
  28336. continue;
  28337. }
  28338. dests[name] = fetchDestination(names[name]);
  28339. }
  28340. }
  28341. return shadow(this, 'destinations', dests);
  28342. },
  28343. getDestination: function Catalog_getDestination(destinationId) {
  28344. function fetchDestination(dest) {
  28345. return isDict(dest) ? dest.get('D') : dest;
  28346. }
  28347. var xref = this.xref;
  28348. var dest = null, nameTreeRef, nameDictionaryRef;
  28349. var obj = this.catDict.get('Names');
  28350. if (obj && obj.has('Dests')) {
  28351. nameTreeRef = obj.getRaw('Dests');
  28352. } else if (this.catDict.has('Dests')) {
  28353. nameDictionaryRef = this.catDict.get('Dests');
  28354. }
  28355. if (nameDictionaryRef) { // Simple destination dictionary.
  28356. var value = nameDictionaryRef.get(destinationId);
  28357. if (value) {
  28358. dest = fetchDestination(value);
  28359. }
  28360. }
  28361. if (nameTreeRef) {
  28362. var nameTree = new NameTree(nameTreeRef, xref);
  28363. dest = fetchDestination(nameTree.get(destinationId));
  28364. }
  28365. return dest;
  28366. },
  28367. get attachments() {
  28368. var xref = this.xref;
  28369. var attachments = null, nameTreeRef;
  28370. var obj = this.catDict.get('Names');
  28371. if (obj) {
  28372. nameTreeRef = obj.getRaw('EmbeddedFiles');
  28373. }
  28374. if (nameTreeRef) {
  28375. var nameTree = new NameTree(nameTreeRef, xref);
  28376. var names = nameTree.getAll();
  28377. for (var name in names) {
  28378. if (!names.hasOwnProperty(name)) {
  28379. continue;
  28380. }
  28381. var fs = new FileSpec(names[name], xref);
  28382. if (!attachments) {
  28383. attachments = {};
  28384. }
  28385. attachments[stringToPDFString(name)] = fs.serializable;
  28386. }
  28387. }
  28388. return shadow(this, 'attachments', attachments);
  28389. },
  28390. get javaScript() {
  28391. var xref = this.xref;
  28392. var obj = this.catDict.get('Names');
  28393. var javaScript = [];
  28394. function appendIfJavaScriptDict(jsDict) {
  28395. var type = jsDict.get('S');
  28396. if (!isName(type) || type.name !== 'JavaScript') {
  28397. return;
  28398. }
  28399. var js = jsDict.get('JS');
  28400. if (isStream(js)) {
  28401. js = bytesToString(js.getBytes());
  28402. } else if (!isString(js)) {
  28403. return;
  28404. }
  28405. javaScript.push(stringToPDFString(js));
  28406. }
  28407. if (obj && obj.has('JavaScript')) {
  28408. var nameTree = new NameTree(obj.getRaw('JavaScript'), xref);
  28409. var names = nameTree.getAll();
  28410. for (var name in names) {
  28411. if (!names.hasOwnProperty(name)) {
  28412. continue;
  28413. }
  28414. // We don't really use the JavaScript right now. This code is
  28415. // defensive so we don't cause errors on document load.
  28416. var jsDict = names[name];
  28417. if (isDict(jsDict)) {
  28418. appendIfJavaScriptDict(jsDict);
  28419. }
  28420. }
  28421. }
  28422. // Append OpenAction actions to javaScript array
  28423. var openactionDict = this.catDict.get('OpenAction');
  28424. if (isDict(openactionDict, 'Action')) {
  28425. var actionType = openactionDict.get('S');
  28426. if (isName(actionType) && actionType.name === 'Named') {
  28427. // The named Print action is not a part of the PDF 1.7 specification,
  28428. // but is supported by many PDF readers/writers (including Adobe's).
  28429. var action = openactionDict.get('N');
  28430. if (isName(action) && action.name === 'Print') {
  28431. javaScript.push('print({});');
  28432. }
  28433. } else {
  28434. appendIfJavaScriptDict(openactionDict);
  28435. }
  28436. }
  28437. return shadow(this, 'javaScript', javaScript);
  28438. },
  28439. cleanup: function Catalog_cleanup() {
  28440. var promises = [];
  28441. this.fontCache.forEach(function (promise) {
  28442. promises.push(promise);
  28443. });
  28444. return Promise.all(promises).then(function (translatedFonts) {
  28445. for (var i = 0, ii = translatedFonts.length; i < ii; i++) {
  28446. var font = translatedFonts[i].dict;
  28447. delete font.translated;
  28448. }
  28449. this.fontCache.clear();
  28450. }.bind(this));
  28451. },
  28452. getPage: function Catalog_getPage(pageIndex) {
  28453. if (!(pageIndex in this.pagePromises)) {
  28454. this.pagePromises[pageIndex] = this.getPageDict(pageIndex).then(
  28455. function (a) {
  28456. var dict = a[0];
  28457. var ref = a[1];
  28458. return this.pageFactory.createPage(pageIndex, dict, ref,
  28459. this.fontCache);
  28460. }.bind(this)
  28461. );
  28462. }
  28463. return this.pagePromises[pageIndex];
  28464. },
  28465. getPageDict: function Catalog_getPageDict(pageIndex) {
  28466. var capability = createPromiseCapability();
  28467. var nodesToVisit = [this.catDict.getRaw('Pages')];
  28468. var currentPageIndex = 0;
  28469. var xref = this.xref;
  28470. var checkAllKids = false;
  28471. function next() {
  28472. while (nodesToVisit.length) {
  28473. var currentNode = nodesToVisit.pop();
  28474. if (isRef(currentNode)) {
  28475. xref.fetchAsync(currentNode).then(function (obj) {
  28476. if (isDict(obj, 'Page') || (isDict(obj) && !obj.has('Kids'))) {
  28477. if (pageIndex === currentPageIndex) {
  28478. capability.resolve([obj, currentNode]);
  28479. } else {
  28480. currentPageIndex++;
  28481. next();
  28482. }
  28483. return;
  28484. }
  28485. nodesToVisit.push(obj);
  28486. next();
  28487. }, capability.reject);
  28488. return;
  28489. }
  28490. // Must be a child page dictionary.
  28491. assert(
  28492. isDict(currentNode),
  28493. 'page dictionary kid reference points to wrong type of object'
  28494. );
  28495. var count = currentNode.get('Count');
  28496. // If the current node doesn't have any children, avoid getting stuck
  28497. // in an empty node further down in the tree (see issue5644.pdf).
  28498. if (count === 0) {
  28499. checkAllKids = true;
  28500. }
  28501. // Skip nodes where the page can't be.
  28502. if (currentPageIndex + count <= pageIndex) {
  28503. currentPageIndex += count;
  28504. continue;
  28505. }
  28506. var kids = currentNode.get('Kids');
  28507. assert(isArray(kids), 'page dictionary kids object is not an array');
  28508. if (!checkAllKids && count === kids.length) {
  28509. // Nodes that don't have the page have been skipped and this is the
  28510. // bottom of the tree which means the page requested must be a
  28511. // descendant of this pages node. Ideally we would just resolve the
  28512. // promise with the page ref here, but there is the case where more
  28513. // pages nodes could link to single a page (see issue 3666 pdf). To
  28514. // handle this push it back on the queue so if it is a pages node it
  28515. // will be descended into.
  28516. nodesToVisit = [kids[pageIndex - currentPageIndex]];
  28517. currentPageIndex = pageIndex;
  28518. continue;
  28519. } else {
  28520. for (var last = kids.length - 1; last >= 0; last--) {
  28521. nodesToVisit.push(kids[last]);
  28522. }
  28523. }
  28524. }
  28525. capability.reject('Page index ' + pageIndex + ' not found.');
  28526. }
  28527. next();
  28528. return capability.promise;
  28529. },
  28530. getPageIndex: function Catalog_getPageIndex(ref) {
  28531. // The page tree nodes have the count of all the leaves below them. To get
  28532. // how many pages are before we just have to walk up the tree and keep
  28533. // adding the count of siblings to the left of the node.
  28534. var xref = this.xref;
  28535. function pagesBeforeRef(kidRef) {
  28536. var total = 0;
  28537. var parentRef;
  28538. return xref.fetchAsync(kidRef).then(function (node) {
  28539. if (!node) {
  28540. return null;
  28541. }
  28542. parentRef = node.getRaw('Parent');
  28543. return node.getAsync('Parent');
  28544. }).then(function (parent) {
  28545. if (!parent) {
  28546. return null;
  28547. }
  28548. return parent.getAsync('Kids');
  28549. }).then(function (kids) {
  28550. if (!kids) {
  28551. return null;
  28552. }
  28553. var kidPromises = [];
  28554. var found = false;
  28555. for (var i = 0; i < kids.length; i++) {
  28556. var kid = kids[i];
  28557. assert(isRef(kid), 'kids must be a ref');
  28558. if (kid.num === kidRef.num) {
  28559. found = true;
  28560. break;
  28561. }
  28562. kidPromises.push(xref.fetchAsync(kid).then(function (kid) {
  28563. if (kid.has('Count')) {
  28564. var count = kid.get('Count');
  28565. total += count;
  28566. } else { // page leaf node
  28567. total++;
  28568. }
  28569. }));
  28570. }
  28571. if (!found) {
  28572. error('kid ref not found in parents kids');
  28573. }
  28574. return Promise.all(kidPromises).then(function () {
  28575. return [total, parentRef];
  28576. });
  28577. });
  28578. }
  28579. var total = 0;
  28580. function next(ref) {
  28581. return pagesBeforeRef(ref).then(function (args) {
  28582. if (!args) {
  28583. return total;
  28584. }
  28585. var count = args[0];
  28586. var parentRef = args[1];
  28587. total += count;
  28588. return next(parentRef);
  28589. });
  28590. }
  28591. return next(ref);
  28592. }
  28593. };
  28594. return Catalog;
  28595. })();
  28596. var XRef = (function XRefClosure() {
  28597. function XRef(stream, password) {
  28598. this.stream = stream;
  28599. this.entries = [];
  28600. this.xrefstms = {};
  28601. // prepare the XRef cache
  28602. this.cache = [];
  28603. this.password = password;
  28604. this.stats = {
  28605. streamTypes: [],
  28606. fontTypes: []
  28607. };
  28608. }
  28609. XRef.prototype = {
  28610. setStartXRef: function XRef_setStartXRef(startXRef) {
  28611. // Store the starting positions of xref tables as we process them
  28612. // so we can recover from missing data errors
  28613. this.startXRefQueue = [startXRef];
  28614. },
  28615. parse: function XRef_parse(recoveryMode) {
  28616. var trailerDict;
  28617. if (!recoveryMode) {
  28618. trailerDict = this.readXRef();
  28619. } else {
  28620. warn('Indexing all PDF objects');
  28621. trailerDict = this.indexObjects();
  28622. }
  28623. trailerDict.assignXref(this);
  28624. this.trailer = trailerDict;
  28625. var encrypt = trailerDict.get('Encrypt');
  28626. if (encrypt) {
  28627. var ids = trailerDict.get('ID');
  28628. var fileId = (ids && ids.length) ? ids[0] : '';
  28629. this.encrypt = new CipherTransformFactory(encrypt, fileId,
  28630. this.password);
  28631. }
  28632. // get the root dictionary (catalog) object
  28633. if (!(this.root = trailerDict.get('Root'))) {
  28634. error('Invalid root reference');
  28635. }
  28636. },
  28637. processXRefTable: function XRef_processXRefTable(parser) {
  28638. if (!('tableState' in this)) {
  28639. // Stores state of the table as we process it so we can resume
  28640. // from middle of table in case of missing data error
  28641. this.tableState = {
  28642. entryNum: 0,
  28643. streamPos: parser.lexer.stream.pos,
  28644. parserBuf1: parser.buf1,
  28645. parserBuf2: parser.buf2
  28646. };
  28647. }
  28648. var obj = this.readXRefTable(parser);
  28649. // Sanity check
  28650. if (!isCmd(obj, 'trailer')) {
  28651. error('Invalid XRef table: could not find trailer dictionary');
  28652. }
  28653. // Read trailer dictionary, e.g.
  28654. // trailer
  28655. // << /Size 22
  28656. // /Root 20R
  28657. // /Info 10R
  28658. // /ID [ <81b14aafa313db63dbd6f981e49f94f4> ]
  28659. // >>
  28660. // The parser goes through the entire stream << ... >> and provides
  28661. // a getter interface for the key-value table
  28662. var dict = parser.getObj();
  28663. // The pdflib PDF generator can generate a nested trailer dictionary
  28664. if (!isDict(dict) && dict.dict) {
  28665. dict = dict.dict;
  28666. }
  28667. if (!isDict(dict)) {
  28668. error('Invalid XRef table: could not parse trailer dictionary');
  28669. }
  28670. delete this.tableState;
  28671. return dict;
  28672. },
  28673. readXRefTable: function XRef_readXRefTable(parser) {
  28674. // Example of cross-reference table:
  28675. // xref
  28676. // 0 1 <-- subsection header (first obj #, obj count)
  28677. // 0000000000 65535 f <-- actual object (offset, generation #, f/n)
  28678. // 23 2 <-- subsection header ... and so on ...
  28679. // 0000025518 00002 n
  28680. // 0000025635 00000 n
  28681. // trailer
  28682. // ...
  28683. var stream = parser.lexer.stream;
  28684. var tableState = this.tableState;
  28685. stream.pos = tableState.streamPos;
  28686. parser.buf1 = tableState.parserBuf1;
  28687. parser.buf2 = tableState.parserBuf2;
  28688. // Outer loop is over subsection headers
  28689. var obj;
  28690. while (true) {
  28691. if (!('firstEntryNum' in tableState) || !('entryCount' in tableState)) {
  28692. if (isCmd(obj = parser.getObj(), 'trailer')) {
  28693. break;
  28694. }
  28695. tableState.firstEntryNum = obj;
  28696. tableState.entryCount = parser.getObj();
  28697. }
  28698. var first = tableState.firstEntryNum;
  28699. var count = tableState.entryCount;
  28700. if (!isInt(first) || !isInt(count)) {
  28701. error('Invalid XRef table: wrong types in subsection header');
  28702. }
  28703. // Inner loop is over objects themselves
  28704. for (var i = tableState.entryNum; i < count; i++) {
  28705. tableState.streamPos = stream.pos;
  28706. tableState.entryNum = i;
  28707. tableState.parserBuf1 = parser.buf1;
  28708. tableState.parserBuf2 = parser.buf2;
  28709. var entry = {};
  28710. entry.offset = parser.getObj();
  28711. entry.gen = parser.getObj();
  28712. var type = parser.getObj();
  28713. if (isCmd(type, 'f')) {
  28714. entry.free = true;
  28715. } else if (isCmd(type, 'n')) {
  28716. entry.uncompressed = true;
  28717. }
  28718. // Validate entry obj
  28719. if (!isInt(entry.offset) || !isInt(entry.gen) ||
  28720. !(entry.free || entry.uncompressed)) {
  28721. error('Invalid entry in XRef subsection: ' + first + ', ' + count);
  28722. }
  28723. if (!this.entries[i + first]) {
  28724. this.entries[i + first] = entry;
  28725. }
  28726. }
  28727. tableState.entryNum = 0;
  28728. tableState.streamPos = stream.pos;
  28729. tableState.parserBuf1 = parser.buf1;
  28730. tableState.parserBuf2 = parser.buf2;
  28731. delete tableState.firstEntryNum;
  28732. delete tableState.entryCount;
  28733. }
  28734. // Per issue 3248: hp scanners generate bad XRef
  28735. if (first === 1 && this.entries[1] && this.entries[1].free) {
  28736. // shifting the entries
  28737. this.entries.shift();
  28738. }
  28739. // Sanity check: as per spec, first object must be free
  28740. if (this.entries[0] && !this.entries[0].free) {
  28741. error('Invalid XRef table: unexpected first object');
  28742. }
  28743. return obj;
  28744. },
  28745. processXRefStream: function XRef_processXRefStream(stream) {
  28746. if (!('streamState' in this)) {
  28747. // Stores state of the stream as we process it so we can resume
  28748. // from middle of stream in case of missing data error
  28749. var streamParameters = stream.dict;
  28750. var byteWidths = streamParameters.get('W');
  28751. var range = streamParameters.get('Index');
  28752. if (!range) {
  28753. range = [0, streamParameters.get('Size')];
  28754. }
  28755. this.streamState = {
  28756. entryRanges: range,
  28757. byteWidths: byteWidths,
  28758. entryNum: 0,
  28759. streamPos: stream.pos
  28760. };
  28761. }
  28762. this.readXRefStream(stream);
  28763. delete this.streamState;
  28764. return stream.dict;
  28765. },
  28766. readXRefStream: function XRef_readXRefStream(stream) {
  28767. var i, j;
  28768. var streamState = this.streamState;
  28769. stream.pos = streamState.streamPos;
  28770. var byteWidths = streamState.byteWidths;
  28771. var typeFieldWidth = byteWidths[0];
  28772. var offsetFieldWidth = byteWidths[1];
  28773. var generationFieldWidth = byteWidths[2];
  28774. var entryRanges = streamState.entryRanges;
  28775. while (entryRanges.length > 0) {
  28776. var first = entryRanges[0];
  28777. var n = entryRanges[1];
  28778. if (!isInt(first) || !isInt(n)) {
  28779. error('Invalid XRef range fields: ' + first + ', ' + n);
  28780. }
  28781. if (!isInt(typeFieldWidth) || !isInt(offsetFieldWidth) ||
  28782. !isInt(generationFieldWidth)) {
  28783. error('Invalid XRef entry fields length: ' + first + ', ' + n);
  28784. }
  28785. for (i = streamState.entryNum; i < n; ++i) {
  28786. streamState.entryNum = i;
  28787. streamState.streamPos = stream.pos;
  28788. var type = 0, offset = 0, generation = 0;
  28789. for (j = 0; j < typeFieldWidth; ++j) {
  28790. type = (type << 8) | stream.getByte();
  28791. }
  28792. // if type field is absent, its default value is 1
  28793. if (typeFieldWidth === 0) {
  28794. type = 1;
  28795. }
  28796. for (j = 0; j < offsetFieldWidth; ++j) {
  28797. offset = (offset << 8) | stream.getByte();
  28798. }
  28799. for (j = 0; j < generationFieldWidth; ++j) {
  28800. generation = (generation << 8) | stream.getByte();
  28801. }
  28802. var entry = {};
  28803. entry.offset = offset;
  28804. entry.gen = generation;
  28805. switch (type) {
  28806. case 0:
  28807. entry.free = true;
  28808. break;
  28809. case 1:
  28810. entry.uncompressed = true;
  28811. break;
  28812. case 2:
  28813. break;
  28814. default:
  28815. error('Invalid XRef entry type: ' + type);
  28816. }
  28817. if (!this.entries[first + i]) {
  28818. this.entries[first + i] = entry;
  28819. }
  28820. }
  28821. streamState.entryNum = 0;
  28822. streamState.streamPos = stream.pos;
  28823. entryRanges.splice(0, 2);
  28824. }
  28825. },
  28826. indexObjects: function XRef_indexObjects() {
  28827. // Simple scan through the PDF content to find objects,
  28828. // trailers and XRef streams.
  28829. var TAB = 0x9, LF = 0xA, CR = 0xD, SPACE = 0x20;
  28830. var PERCENT = 0x25, LT = 0x3C;
  28831. function readToken(data, offset) {
  28832. var token = '', ch = data[offset];
  28833. while (ch !== LF && ch !== CR && ch !== LT) {
  28834. if (++offset >= data.length) {
  28835. break;
  28836. }
  28837. token += String.fromCharCode(ch);
  28838. ch = data[offset];
  28839. }
  28840. return token;
  28841. }
  28842. function skipUntil(data, offset, what) {
  28843. var length = what.length, dataLength = data.length;
  28844. var skipped = 0;
  28845. // finding byte sequence
  28846. while (offset < dataLength) {
  28847. var i = 0;
  28848. while (i < length && data[offset + i] === what[i]) {
  28849. ++i;
  28850. }
  28851. if (i >= length) {
  28852. break; // sequence found
  28853. }
  28854. offset++;
  28855. skipped++;
  28856. }
  28857. return skipped;
  28858. }
  28859. var objRegExp = /^(\d+)\s+(\d+)\s+obj\b/;
  28860. var trailerBytes = new Uint8Array([116, 114, 97, 105, 108, 101, 114]);
  28861. var startxrefBytes = new Uint8Array([115, 116, 97, 114, 116, 120, 114,
  28862. 101, 102]);
  28863. var endobjBytes = new Uint8Array([101, 110, 100, 111, 98, 106]);
  28864. var xrefBytes = new Uint8Array([47, 88, 82, 101, 102]);
  28865. // Clear out any existing entries, since they may be bogus.
  28866. this.entries.length = 0;
  28867. var stream = this.stream;
  28868. stream.pos = 0;
  28869. var buffer = stream.getBytes();
  28870. var position = stream.start, length = buffer.length;
  28871. var trailers = [], xrefStms = [];
  28872. while (position < length) {
  28873. var ch = buffer[position];
  28874. if (ch === TAB || ch === LF || ch === CR || ch === SPACE) {
  28875. ++position;
  28876. continue;
  28877. }
  28878. if (ch === PERCENT) { // %-comment
  28879. do {
  28880. ++position;
  28881. if (position >= length) {
  28882. break;
  28883. }
  28884. ch = buffer[position];
  28885. } while (ch !== LF && ch !== CR);
  28886. continue;
  28887. }
  28888. var token = readToken(buffer, position);
  28889. var m;
  28890. if (token.indexOf('xref') === 0 &&
  28891. (token.length === 4 || /\s/.test(token[4]))) {
  28892. position += skipUntil(buffer, position, trailerBytes);
  28893. trailers.push(position);
  28894. position += skipUntil(buffer, position, startxrefBytes);
  28895. } else if ((m = objRegExp.exec(token))) {
  28896. if (typeof this.entries[m[1]] === 'undefined') {
  28897. this.entries[m[1]] = {
  28898. offset: position - stream.start,
  28899. gen: m[2] | 0,
  28900. uncompressed: true
  28901. };
  28902. }
  28903. var contentLength = skipUntil(buffer, position, endobjBytes) + 7;
  28904. var content = buffer.subarray(position, position + contentLength);
  28905. // checking XRef stream suspect
  28906. // (it shall have '/XRef' and next char is not a letter)
  28907. var xrefTagOffset = skipUntil(content, 0, xrefBytes);
  28908. if (xrefTagOffset < contentLength &&
  28909. content[xrefTagOffset + 5] < 64) {
  28910. xrefStms.push(position - stream.start);
  28911. this.xrefstms[position - stream.start] = 1; // Avoid recursion
  28912. }
  28913. position += contentLength;
  28914. } else if (token.indexOf('trailer') === 0 &&
  28915. (token.length === 7 || /\s/.test(token[7]))) {
  28916. trailers.push(position);
  28917. position += skipUntil(buffer, position, startxrefBytes);
  28918. } else {
  28919. position += token.length + 1;
  28920. }
  28921. }
  28922. // reading XRef streams
  28923. var i, ii;
  28924. for (i = 0, ii = xrefStms.length; i < ii; ++i) {
  28925. this.startXRefQueue.push(xrefStms[i]);
  28926. this.readXRef(/* recoveryMode */ true);
  28927. }
  28928. // finding main trailer
  28929. var dict;
  28930. for (i = 0, ii = trailers.length; i < ii; ++i) {
  28931. stream.pos = trailers[i];
  28932. var parser = new Parser(new Lexer(stream), true, this);
  28933. var obj = parser.getObj();
  28934. if (!isCmd(obj, 'trailer')) {
  28935. continue;
  28936. }
  28937. // read the trailer dictionary
  28938. if (!isDict(dict = parser.getObj())) {
  28939. continue;
  28940. }
  28941. // taking the first one with 'ID'
  28942. if (dict.has('ID')) {
  28943. return dict;
  28944. }
  28945. }
  28946. // no tailer with 'ID', taking last one (if exists)
  28947. if (dict) {
  28948. return dict;
  28949. }
  28950. // nothing helps
  28951. // calling error() would reject worker with an UnknownErrorException.
  28952. throw new InvalidPDFException('Invalid PDF structure');
  28953. },
  28954. readXRef: function XRef_readXRef(recoveryMode) {
  28955. var stream = this.stream;
  28956. try {
  28957. while (this.startXRefQueue.length) {
  28958. var startXRef = this.startXRefQueue[0];
  28959. stream.pos = startXRef + stream.start;
  28960. var parser = new Parser(new Lexer(stream), true, this);
  28961. var obj = parser.getObj();
  28962. var dict;
  28963. // Get dictionary
  28964. if (isCmd(obj, 'xref')) {
  28965. // Parse end-of-file XRef
  28966. dict = this.processXRefTable(parser);
  28967. if (!this.topDict) {
  28968. this.topDict = dict;
  28969. }
  28970. // Recursively get other XRefs 'XRefStm', if any
  28971. obj = dict.get('XRefStm');
  28972. if (isInt(obj)) {
  28973. var pos = obj;
  28974. // ignore previously loaded xref streams
  28975. // (possible infinite recursion)
  28976. if (!(pos in this.xrefstms)) {
  28977. this.xrefstms[pos] = 1;
  28978. this.startXRefQueue.push(pos);
  28979. }
  28980. }
  28981. } else if (isInt(obj)) {
  28982. // Parse in-stream XRef
  28983. if (!isInt(parser.getObj()) ||
  28984. !isCmd(parser.getObj(), 'obj') ||
  28985. !isStream(obj = parser.getObj())) {
  28986. error('Invalid XRef stream');
  28987. }
  28988. dict = this.processXRefStream(obj);
  28989. if (!this.topDict) {
  28990. this.topDict = dict;
  28991. }
  28992. if (!dict) {
  28993. error('Failed to read XRef stream');
  28994. }
  28995. } else {
  28996. error('Invalid XRef stream header');
  28997. }
  28998. // Recursively get previous dictionary, if any
  28999. obj = dict.get('Prev');
  29000. if (isInt(obj)) {
  29001. this.startXRefQueue.push(obj);
  29002. } else if (isRef(obj)) {
  29003. // The spec says Prev must not be a reference, i.e. "/Prev NNN"
  29004. // This is a fallback for non-compliant PDFs, i.e. "/Prev NNN 0 R"
  29005. this.startXRefQueue.push(obj.num);
  29006. }
  29007. this.startXRefQueue.shift();
  29008. }
  29009. return this.topDict;
  29010. } catch (e) {
  29011. if (e instanceof MissingDataException) {
  29012. throw e;
  29013. }
  29014. info('(while reading XRef): ' + e);
  29015. }
  29016. if (recoveryMode) {
  29017. return;
  29018. }
  29019. throw new XRefParseException();
  29020. },
  29021. getEntry: function XRef_getEntry(i) {
  29022. var xrefEntry = this.entries[i];
  29023. if (xrefEntry && !xrefEntry.free && xrefEntry.offset) {
  29024. return xrefEntry;
  29025. }
  29026. return null;
  29027. },
  29028. fetchIfRef: function XRef_fetchIfRef(obj) {
  29029. if (!isRef(obj)) {
  29030. return obj;
  29031. }
  29032. return this.fetch(obj);
  29033. },
  29034. fetch: function XRef_fetch(ref, suppressEncryption) {
  29035. assert(isRef(ref), 'ref object is not a reference');
  29036. var num = ref.num;
  29037. if (num in this.cache) {
  29038. var cacheEntry = this.cache[num];
  29039. return cacheEntry;
  29040. }
  29041. var xrefEntry = this.getEntry(num);
  29042. // the referenced entry can be free
  29043. if (xrefEntry === null) {
  29044. return (this.cache[num] = null);
  29045. }
  29046. if (xrefEntry.uncompressed) {
  29047. xrefEntry = this.fetchUncompressed(ref, xrefEntry, suppressEncryption);
  29048. } else {
  29049. xrefEntry = this.fetchCompressed(xrefEntry, suppressEncryption);
  29050. }
  29051. if (isDict(xrefEntry)){
  29052. xrefEntry.objId = ref.toString();
  29053. } else if (isStream(xrefEntry)) {
  29054. xrefEntry.dict.objId = ref.toString();
  29055. }
  29056. return xrefEntry;
  29057. },
  29058. fetchUncompressed: function XRef_fetchUncompressed(ref, xrefEntry,
  29059. suppressEncryption) {
  29060. var gen = ref.gen;
  29061. var num = ref.num;
  29062. if (xrefEntry.gen !== gen) {
  29063. error('inconsistent generation in XRef');
  29064. }
  29065. var stream = this.stream.makeSubStream(xrefEntry.offset +
  29066. this.stream.start);
  29067. var parser = new Parser(new Lexer(stream), true, this);
  29068. var obj1 = parser.getObj();
  29069. var obj2 = parser.getObj();
  29070. var obj3 = parser.getObj();
  29071. if (!isInt(obj1) || parseInt(obj1, 10) !== num ||
  29072. !isInt(obj2) || parseInt(obj2, 10) !== gen ||
  29073. !isCmd(obj3)) {
  29074. error('bad XRef entry');
  29075. }
  29076. if (!isCmd(obj3, 'obj')) {
  29077. // some bad PDFs use "obj1234" and really mean 1234
  29078. if (obj3.cmd.indexOf('obj') === 0) {
  29079. num = parseInt(obj3.cmd.substring(3), 10);
  29080. if (!isNaN(num)) {
  29081. return num;
  29082. }
  29083. }
  29084. error('bad XRef entry');
  29085. }
  29086. if (this.encrypt && !suppressEncryption) {
  29087. xrefEntry = parser.getObj(this.encrypt.createCipherTransform(num, gen));
  29088. } else {
  29089. xrefEntry = parser.getObj();
  29090. }
  29091. if (!isStream(xrefEntry)) {
  29092. this.cache[num] = xrefEntry;
  29093. }
  29094. return xrefEntry;
  29095. },
  29096. fetchCompressed: function XRef_fetchCompressed(xrefEntry,
  29097. suppressEncryption) {
  29098. var tableOffset = xrefEntry.offset;
  29099. var stream = this.fetch(new Ref(tableOffset, 0));
  29100. if (!isStream(stream)) {
  29101. error('bad ObjStm stream');
  29102. }
  29103. var first = stream.dict.get('First');
  29104. var n = stream.dict.get('N');
  29105. if (!isInt(first) || !isInt(n)) {
  29106. error('invalid first and n parameters for ObjStm stream');
  29107. }
  29108. var parser = new Parser(new Lexer(stream), false, this);
  29109. parser.allowStreams = true;
  29110. var i, entries = [], num, nums = [];
  29111. // read the object numbers to populate cache
  29112. for (i = 0; i < n; ++i) {
  29113. num = parser.getObj();
  29114. if (!isInt(num)) {
  29115. error('invalid object number in the ObjStm stream: ' + num);
  29116. }
  29117. nums.push(num);
  29118. var offset = parser.getObj();
  29119. if (!isInt(offset)) {
  29120. error('invalid object offset in the ObjStm stream: ' + offset);
  29121. }
  29122. }
  29123. // read stream objects for cache
  29124. for (i = 0; i < n; ++i) {
  29125. entries.push(parser.getObj());
  29126. num = nums[i];
  29127. var entry = this.entries[num];
  29128. if (entry && entry.offset === tableOffset && entry.gen === i) {
  29129. this.cache[num] = entries[i];
  29130. }
  29131. }
  29132. xrefEntry = entries[xrefEntry.gen];
  29133. if (xrefEntry === undefined) {
  29134. error('bad XRef entry for compressed object');
  29135. }
  29136. return xrefEntry;
  29137. },
  29138. fetchIfRefAsync: function XRef_fetchIfRefAsync(obj) {
  29139. if (!isRef(obj)) {
  29140. return Promise.resolve(obj);
  29141. }
  29142. return this.fetchAsync(obj);
  29143. },
  29144. fetchAsync: function XRef_fetchAsync(ref, suppressEncryption) {
  29145. var streamManager = this.stream.manager;
  29146. var xref = this;
  29147. return new Promise(function tryFetch(resolve, reject) {
  29148. try {
  29149. resolve(xref.fetch(ref, suppressEncryption));
  29150. } catch (e) {
  29151. if (e instanceof MissingDataException) {
  29152. streamManager.requestRange(e.begin, e.end).then(function () {
  29153. tryFetch(resolve, reject);
  29154. }, reject);
  29155. return;
  29156. }
  29157. reject(e);
  29158. }
  29159. });
  29160. },
  29161. getCatalogObj: function XRef_getCatalogObj() {
  29162. return this.root;
  29163. }
  29164. };
  29165. return XRef;
  29166. })();
  29167. /**
  29168. * A NameTree is like a Dict but has some advantageous properties, see the
  29169. * spec (7.9.6) for more details.
  29170. * TODO: implement all the Dict functions and make this more efficent.
  29171. */
  29172. var NameTree = (function NameTreeClosure() {
  29173. function NameTree(root, xref) {
  29174. this.root = root;
  29175. this.xref = xref;
  29176. }
  29177. NameTree.prototype = {
  29178. getAll: function NameTree_getAll() {
  29179. var dict = {};
  29180. if (!this.root) {
  29181. return dict;
  29182. }
  29183. var xref = this.xref;
  29184. // reading name tree
  29185. var processed = new RefSet();
  29186. processed.put(this.root);
  29187. var queue = [this.root];
  29188. while (queue.length > 0) {
  29189. var i, n;
  29190. var obj = xref.fetchIfRef(queue.shift());
  29191. if (!isDict(obj)) {
  29192. continue;
  29193. }
  29194. if (obj.has('Kids')) {
  29195. var kids = obj.get('Kids');
  29196. for (i = 0, n = kids.length; i < n; i++) {
  29197. var kid = kids[i];
  29198. if (processed.has(kid)) {
  29199. error('invalid destinations');
  29200. }
  29201. queue.push(kid);
  29202. processed.put(kid);
  29203. }
  29204. continue;
  29205. }
  29206. var names = obj.get('Names');
  29207. if (names) {
  29208. for (i = 0, n = names.length; i < n; i += 2) {
  29209. dict[xref.fetchIfRef(names[i])] = xref.fetchIfRef(names[i + 1]);
  29210. }
  29211. }
  29212. }
  29213. return dict;
  29214. },
  29215. get: function NameTree_get(destinationId) {
  29216. if (!this.root) {
  29217. return null;
  29218. }
  29219. var xref = this.xref;
  29220. var kidsOrNames = xref.fetchIfRef(this.root);
  29221. var loopCount = 0;
  29222. var MAX_NAMES_LEVELS = 10;
  29223. var l, r, m;
  29224. // Perform a binary search to quickly find the entry that
  29225. // contains the named destination we are looking for.
  29226. while (kidsOrNames.has('Kids')) {
  29227. loopCount++;
  29228. if (loopCount > MAX_NAMES_LEVELS) {
  29229. warn('Search depth limit for named destionations has been reached.');
  29230. return null;
  29231. }
  29232. var kids = kidsOrNames.get('Kids');
  29233. if (!isArray(kids)) {
  29234. return null;
  29235. }
  29236. l = 0;
  29237. r = kids.length - 1;
  29238. while (l <= r) {
  29239. m = (l + r) >> 1;
  29240. var kid = xref.fetchIfRef(kids[m]);
  29241. var limits = kid.get('Limits');
  29242. if (destinationId < xref.fetchIfRef(limits[0])) {
  29243. r = m - 1;
  29244. } else if (destinationId > xref.fetchIfRef(limits[1])) {
  29245. l = m + 1;
  29246. } else {
  29247. kidsOrNames = xref.fetchIfRef(kids[m]);
  29248. break;
  29249. }
  29250. }
  29251. if (l > r) {
  29252. return null;
  29253. }
  29254. }
  29255. // If we get here, then we have found the right entry. Now
  29256. // go through the named destinations in the Named dictionary
  29257. // until we find the exact destination we're looking for.
  29258. var names = kidsOrNames.get('Names');
  29259. if (isArray(names)) {
  29260. // Perform a binary search to reduce the lookup time.
  29261. l = 0;
  29262. r = names.length - 2;
  29263. while (l <= r) {
  29264. // Check only even indices (0, 2, 4, ...) because the
  29265. // odd indices contain the actual D array.
  29266. m = (l + r) & ~1;
  29267. if (destinationId < xref.fetchIfRef(names[m])) {
  29268. r = m - 2;
  29269. } else if (destinationId > xref.fetchIfRef(names[m])) {
  29270. l = m + 2;
  29271. } else {
  29272. return xref.fetchIfRef(names[m + 1]);
  29273. }
  29274. }
  29275. }
  29276. return null;
  29277. }
  29278. };
  29279. return NameTree;
  29280. })();
  29281. /**
  29282. * "A PDF file can refer to the contents of another file by using a File
  29283. * Specification (PDF 1.1)", see the spec (7.11) for more details.
  29284. * NOTE: Only embedded files are supported (as part of the attachments support)
  29285. * TODO: support the 'URL' file system (with caching if !/V), portable
  29286. * collections attributes and related files (/RF)
  29287. */
  29288. var FileSpec = (function FileSpecClosure() {
  29289. function FileSpec(root, xref) {
  29290. if (!root || !isDict(root)) {
  29291. return;
  29292. }
  29293. this.xref = xref;
  29294. this.root = root;
  29295. if (root.has('FS')) {
  29296. this.fs = root.get('FS');
  29297. }
  29298. this.description = root.has('Desc') ?
  29299. stringToPDFString(root.get('Desc')) :
  29300. '';
  29301. if (root.has('RF')) {
  29302. warn('Related file specifications are not supported');
  29303. }
  29304. this.contentAvailable = true;
  29305. if (!root.has('EF')) {
  29306. this.contentAvailable = false;
  29307. warn('Non-embedded file specifications are not supported');
  29308. }
  29309. }
  29310. function pickPlatformItem(dict) {
  29311. // Look for the filename in this order:
  29312. // UF, F, Unix, Mac, DOS
  29313. if (dict.has('UF')) {
  29314. return dict.get('UF');
  29315. } else if (dict.has('F')) {
  29316. return dict.get('F');
  29317. } else if (dict.has('Unix')) {
  29318. return dict.get('Unix');
  29319. } else if (dict.has('Mac')) {
  29320. return dict.get('Mac');
  29321. } else if (dict.has('DOS')) {
  29322. return dict.get('DOS');
  29323. } else {
  29324. return null;
  29325. }
  29326. }
  29327. FileSpec.prototype = {
  29328. get filename() {
  29329. if (!this._filename && this.root) {
  29330. var filename = pickPlatformItem(this.root) || 'unnamed';
  29331. this._filename = stringToPDFString(filename).
  29332. replace(/\\\\/g, '\\').
  29333. replace(/\\\//g, '/').
  29334. replace(/\\/g, '/');
  29335. }
  29336. return this._filename;
  29337. },
  29338. get content() {
  29339. if (!this.contentAvailable) {
  29340. return null;
  29341. }
  29342. if (!this.contentRef && this.root) {
  29343. this.contentRef = pickPlatformItem(this.root.get('EF'));
  29344. }
  29345. var content = null;
  29346. if (this.contentRef) {
  29347. var xref = this.xref;
  29348. var fileObj = xref.fetchIfRef(this.contentRef);
  29349. if (fileObj && isStream(fileObj)) {
  29350. content = fileObj.getBytes();
  29351. } else {
  29352. warn('Embedded file specification points to non-existing/invalid ' +
  29353. 'content');
  29354. }
  29355. } else {
  29356. warn('Embedded file specification does not have a content');
  29357. }
  29358. return content;
  29359. },
  29360. get serializable() {
  29361. return {
  29362. filename: this.filename,
  29363. content: this.content
  29364. };
  29365. }
  29366. };
  29367. return FileSpec;
  29368. })();
  29369. /**
  29370. * A helper for loading missing data in object graphs. It traverses the graph
  29371. * depth first and queues up any objects that have missing data. Once it has
  29372. * has traversed as many objects that are available it attempts to bundle the
  29373. * missing data requests and then resume from the nodes that weren't ready.
  29374. *
  29375. * NOTE: It provides protection from circular references by keeping track of
  29376. * of loaded references. However, you must be careful not to load any graphs
  29377. * that have references to the catalog or other pages since that will cause the
  29378. * entire PDF document object graph to be traversed.
  29379. */
  29380. var ObjectLoader = (function() {
  29381. function mayHaveChildren(value) {
  29382. return isRef(value) || isDict(value) || isArray(value) || isStream(value);
  29383. }
  29384. function addChildren(node, nodesToVisit) {
  29385. var value;
  29386. if (isDict(node) || isStream(node)) {
  29387. var map;
  29388. if (isDict(node)) {
  29389. map = node.map;
  29390. } else {
  29391. map = node.dict.map;
  29392. }
  29393. for (var key in map) {
  29394. value = map[key];
  29395. if (mayHaveChildren(value)) {
  29396. nodesToVisit.push(value);
  29397. }
  29398. }
  29399. } else if (isArray(node)) {
  29400. for (var i = 0, ii = node.length; i < ii; i++) {
  29401. value = node[i];
  29402. if (mayHaveChildren(value)) {
  29403. nodesToVisit.push(value);
  29404. }
  29405. }
  29406. }
  29407. }
  29408. function ObjectLoader(obj, keys, xref) {
  29409. this.obj = obj;
  29410. this.keys = keys;
  29411. this.xref = xref;
  29412. this.refSet = null;
  29413. this.capability = null;
  29414. }
  29415. ObjectLoader.prototype = {
  29416. load: function ObjectLoader_load() {
  29417. var keys = this.keys;
  29418. this.capability = createPromiseCapability();
  29419. // Don't walk the graph if all the data is already loaded.
  29420. if (!(this.xref.stream instanceof ChunkedStream) ||
  29421. this.xref.stream.getMissingChunks().length === 0) {
  29422. this.capability.resolve();
  29423. return this.capability.promise;
  29424. }
  29425. this.refSet = new RefSet();
  29426. // Setup the initial nodes to visit.
  29427. var nodesToVisit = [];
  29428. for (var i = 0; i < keys.length; i++) {
  29429. nodesToVisit.push(this.obj[keys[i]]);
  29430. }
  29431. this._walk(nodesToVisit);
  29432. return this.capability.promise;
  29433. },
  29434. _walk: function ObjectLoader_walk(nodesToVisit) {
  29435. var nodesToRevisit = [];
  29436. var pendingRequests = [];
  29437. // DFS walk of the object graph.
  29438. while (nodesToVisit.length) {
  29439. var currentNode = nodesToVisit.pop();
  29440. // Only references or chunked streams can cause missing data exceptions.
  29441. if (isRef(currentNode)) {
  29442. // Skip nodes that have already been visited.
  29443. if (this.refSet.has(currentNode)) {
  29444. continue;
  29445. }
  29446. try {
  29447. var ref = currentNode;
  29448. this.refSet.put(ref);
  29449. currentNode = this.xref.fetch(currentNode);
  29450. } catch (e) {
  29451. if (!(e instanceof MissingDataException)) {
  29452. throw e;
  29453. }
  29454. nodesToRevisit.push(currentNode);
  29455. pendingRequests.push({ begin: e.begin, end: e.end });
  29456. }
  29457. }
  29458. if (currentNode && currentNode.getBaseStreams) {
  29459. var baseStreams = currentNode.getBaseStreams();
  29460. var foundMissingData = false;
  29461. for (var i = 0; i < baseStreams.length; i++) {
  29462. var stream = baseStreams[i];
  29463. if (stream.getMissingChunks && stream.getMissingChunks().length) {
  29464. foundMissingData = true;
  29465. pendingRequests.push({
  29466. begin: stream.start,
  29467. end: stream.end
  29468. });
  29469. }
  29470. }
  29471. if (foundMissingData) {
  29472. nodesToRevisit.push(currentNode);
  29473. }
  29474. }
  29475. addChildren(currentNode, nodesToVisit);
  29476. }
  29477. if (pendingRequests.length) {
  29478. this.xref.stream.manager.requestRanges(pendingRequests).then(
  29479. function pendingRequestCallback() {
  29480. nodesToVisit = nodesToRevisit;
  29481. for (var i = 0; i < nodesToRevisit.length; i++) {
  29482. var node = nodesToRevisit[i];
  29483. // Remove any reference nodes from the currrent refset so they
  29484. // aren't skipped when we revist them.
  29485. if (isRef(node)) {
  29486. this.refSet.remove(node);
  29487. }
  29488. }
  29489. this._walk(nodesToVisit);
  29490. }.bind(this), this.capability.reject);
  29491. return;
  29492. }
  29493. // Everything is loaded.
  29494. this.refSet = null;
  29495. this.capability.resolve();
  29496. }
  29497. };
  29498. return ObjectLoader;
  29499. })();
  29500. exports.Catalog = Catalog;
  29501. exports.ObjectLoader = ObjectLoader;
  29502. exports.XRef = XRef;
  29503. }));
  29504. (function (root, factory) {
  29505. {
  29506. factory((root.pdfjsCorePsParser = {}), root.pdfjsSharedUtil,
  29507. root.pdfjsCoreParser);
  29508. }
  29509. }(this, function (exports, sharedUtil, coreParser) {
  29510. var error = sharedUtil.error;
  29511. var EOF = coreParser.EOF;
  29512. var Lexer = coreParser.Lexer;
  29513. var PostScriptParser = (function PostScriptParserClosure() {
  29514. function PostScriptParser(lexer) {
  29515. this.lexer = lexer;
  29516. this.operators = [];
  29517. this.token = null;
  29518. this.prev = null;
  29519. }
  29520. PostScriptParser.prototype = {
  29521. nextToken: function PostScriptParser_nextToken() {
  29522. this.prev = this.token;
  29523. this.token = this.lexer.getToken();
  29524. },
  29525. accept: function PostScriptParser_accept(type) {
  29526. if (this.token.type === type) {
  29527. this.nextToken();
  29528. return true;
  29529. }
  29530. return false;
  29531. },
  29532. expect: function PostScriptParser_expect(type) {
  29533. if (this.accept(type)) {
  29534. return true;
  29535. }
  29536. error('Unexpected symbol: found ' + this.token.type + ' expected ' +
  29537. type + '.');
  29538. },
  29539. parse: function PostScriptParser_parse() {
  29540. this.nextToken();
  29541. this.expect(PostScriptTokenTypes.LBRACE);
  29542. this.parseBlock();
  29543. this.expect(PostScriptTokenTypes.RBRACE);
  29544. return this.operators;
  29545. },
  29546. parseBlock: function PostScriptParser_parseBlock() {
  29547. while (true) {
  29548. if (this.accept(PostScriptTokenTypes.NUMBER)) {
  29549. this.operators.push(this.prev.value);
  29550. } else if (this.accept(PostScriptTokenTypes.OPERATOR)) {
  29551. this.operators.push(this.prev.value);
  29552. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  29553. this.parseCondition();
  29554. } else {
  29555. return;
  29556. }
  29557. }
  29558. },
  29559. parseCondition: function PostScriptParser_parseCondition() {
  29560. // Add two place holders that will be updated later
  29561. var conditionLocation = this.operators.length;
  29562. this.operators.push(null, null);
  29563. this.parseBlock();
  29564. this.expect(PostScriptTokenTypes.RBRACE);
  29565. if (this.accept(PostScriptTokenTypes.IF)) {
  29566. // The true block is right after the 'if' so it just falls through on
  29567. // true else it jumps and skips the true block.
  29568. this.operators[conditionLocation] = this.operators.length;
  29569. this.operators[conditionLocation + 1] = 'jz';
  29570. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  29571. var jumpLocation = this.operators.length;
  29572. this.operators.push(null, null);
  29573. var endOfTrue = this.operators.length;
  29574. this.parseBlock();
  29575. this.expect(PostScriptTokenTypes.RBRACE);
  29576. this.expect(PostScriptTokenTypes.IFELSE);
  29577. // The jump is added at the end of the true block to skip the false
  29578. // block.
  29579. this.operators[jumpLocation] = this.operators.length;
  29580. this.operators[jumpLocation + 1] = 'j';
  29581. this.operators[conditionLocation] = endOfTrue;
  29582. this.operators[conditionLocation + 1] = 'jz';
  29583. } else {
  29584. error('PS Function: error parsing conditional.');
  29585. }
  29586. }
  29587. };
  29588. return PostScriptParser;
  29589. })();
  29590. var PostScriptTokenTypes = {
  29591. LBRACE: 0,
  29592. RBRACE: 1,
  29593. NUMBER: 2,
  29594. OPERATOR: 3,
  29595. IF: 4,
  29596. IFELSE: 5
  29597. };
  29598. var PostScriptToken = (function PostScriptTokenClosure() {
  29599. function PostScriptToken(type, value) {
  29600. this.type = type;
  29601. this.value = value;
  29602. }
  29603. var opCache = {};
  29604. PostScriptToken.getOperator = function PostScriptToken_getOperator(op) {
  29605. var opValue = opCache[op];
  29606. if (opValue) {
  29607. return opValue;
  29608. }
  29609. return opCache[op] = new PostScriptToken(PostScriptTokenTypes.OPERATOR, op);
  29610. };
  29611. PostScriptToken.LBRACE = new PostScriptToken(PostScriptTokenTypes.LBRACE,
  29612. '{');
  29613. PostScriptToken.RBRACE = new PostScriptToken(PostScriptTokenTypes.RBRACE,
  29614. '}');
  29615. PostScriptToken.IF = new PostScriptToken(PostScriptTokenTypes.IF, 'IF');
  29616. PostScriptToken.IFELSE = new PostScriptToken(PostScriptTokenTypes.IFELSE,
  29617. 'IFELSE');
  29618. return PostScriptToken;
  29619. })();
  29620. var PostScriptLexer = (function PostScriptLexerClosure() {
  29621. function PostScriptLexer(stream) {
  29622. this.stream = stream;
  29623. this.nextChar();
  29624. this.strBuf = [];
  29625. }
  29626. PostScriptLexer.prototype = {
  29627. nextChar: function PostScriptLexer_nextChar() {
  29628. return (this.currentChar = this.stream.getByte());
  29629. },
  29630. getToken: function PostScriptLexer_getToken() {
  29631. var comment = false;
  29632. var ch = this.currentChar;
  29633. // skip comments
  29634. while (true) {
  29635. if (ch < 0) {
  29636. return EOF;
  29637. }
  29638. if (comment) {
  29639. if (ch === 0x0A || ch === 0x0D) {
  29640. comment = false;
  29641. }
  29642. } else if (ch === 0x25) { // '%'
  29643. comment = true;
  29644. } else if (!Lexer.isSpace(ch)) {
  29645. break;
  29646. }
  29647. ch = this.nextChar();
  29648. }
  29649. switch (ch | 0) {
  29650. case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: // '0'-'4'
  29651. case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: // '5'-'9'
  29652. case 0x2B: case 0x2D: case 0x2E: // '+', '-', '.'
  29653. return new PostScriptToken(PostScriptTokenTypes.NUMBER,
  29654. this.getNumber());
  29655. case 0x7B: // '{'
  29656. this.nextChar();
  29657. return PostScriptToken.LBRACE;
  29658. case 0x7D: // '}'
  29659. this.nextChar();
  29660. return PostScriptToken.RBRACE;
  29661. }
  29662. // operator
  29663. var strBuf = this.strBuf;
  29664. strBuf.length = 0;
  29665. strBuf[0] = String.fromCharCode(ch);
  29666. while ((ch = this.nextChar()) >= 0 && // and 'A'-'Z', 'a'-'z'
  29667. ((ch >= 0x41 && ch <= 0x5A) || (ch >= 0x61 && ch <= 0x7A))) {
  29668. strBuf.push(String.fromCharCode(ch));
  29669. }
  29670. var str = strBuf.join('');
  29671. switch (str.toLowerCase()) {
  29672. case 'if':
  29673. return PostScriptToken.IF;
  29674. case 'ifelse':
  29675. return PostScriptToken.IFELSE;
  29676. default:
  29677. return PostScriptToken.getOperator(str);
  29678. }
  29679. },
  29680. getNumber: function PostScriptLexer_getNumber() {
  29681. var ch = this.currentChar;
  29682. var strBuf = this.strBuf;
  29683. strBuf.length = 0;
  29684. strBuf[0] = String.fromCharCode(ch);
  29685. while ((ch = this.nextChar()) >= 0) {
  29686. if ((ch >= 0x30 && ch <= 0x39) || // '0'-'9'
  29687. ch === 0x2D || ch === 0x2E) { // '-', '.'
  29688. strBuf.push(String.fromCharCode(ch));
  29689. } else {
  29690. break;
  29691. }
  29692. }
  29693. var value = parseFloat(strBuf.join(''));
  29694. if (isNaN(value)) {
  29695. error('Invalid floating point number: ' + value);
  29696. }
  29697. return value;
  29698. }
  29699. };
  29700. return PostScriptLexer;
  29701. })();
  29702. exports.PostScriptLexer = PostScriptLexer;
  29703. exports.PostScriptParser = PostScriptParser;
  29704. }));
  29705. (function (root, factory) {
  29706. {
  29707. factory((root.pdfjsCoreFonts = {}), root.pdfjsSharedUtil,
  29708. root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreParser,
  29709. root.pdfjsCoreCMap, root.pdfjsCoreGlyphList, root.pdfjsCoreCharsets,
  29710. root.pdfjsCoreFontRenderer);
  29711. }
  29712. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreParser,
  29713. coreCMap, coreGlyphList, coreCharsets, coreFontRenderer) {
  29714. var FONT_IDENTITY_MATRIX = sharedUtil.FONT_IDENTITY_MATRIX;
  29715. var FontType = sharedUtil.FontType;
  29716. var Util = sharedUtil.Util;
  29717. var assert = sharedUtil.assert;
  29718. var bytesToString = sharedUtil.bytesToString;
  29719. var error = sharedUtil.error;
  29720. var info = sharedUtil.info;
  29721. var isArray = sharedUtil.isArray;
  29722. var isInt = sharedUtil.isInt;
  29723. var isNum = sharedUtil.isNum;
  29724. var readUint32 = sharedUtil.readUint32;
  29725. var shadow = sharedUtil.shadow;
  29726. var stringToBytes = sharedUtil.stringToBytes;
  29727. var string32 = sharedUtil.string32;
  29728. var warn = sharedUtil.warn;
  29729. var Name = corePrimitives.Name;
  29730. var Stream = coreStream.Stream;
  29731. var Lexer = coreParser.Lexer;
  29732. var CMapFactory = coreCMap.CMapFactory;
  29733. var IdentityCMap = coreCMap.IdentityCMap;
  29734. var GlyphsUnicode = coreGlyphList.GlyphsUnicode;
  29735. var DingbatsGlyphsUnicode = coreGlyphList.DingbatsGlyphsUnicode;
  29736. var ISOAdobeCharset = coreCharsets.ISOAdobeCharset;
  29737. var ExpertCharset = coreCharsets.ExpertCharset;
  29738. var ExpertSubsetCharset = coreCharsets.ExpertSubsetCharset;
  29739. var FontRendererFactory = coreFontRenderer.FontRendererFactory;
  29740. // Unicode Private Use Area
  29741. var PRIVATE_USE_OFFSET_START = 0xE000;
  29742. var PRIVATE_USE_OFFSET_END = 0xF8FF;
  29743. var SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = false;
  29744. // PDF Glyph Space Units are one Thousandth of a TextSpace Unit
  29745. // except for Type 3 fonts
  29746. var PDF_GLYPH_SPACE_UNITS = 1000;
  29747. // Hinting is currently disabled due to unknown problems on windows
  29748. // in tracemonkey and various other pdfs with type1 fonts.
  29749. var HINTING_ENABLED = false;
  29750. // Accented charactars are not displayed properly on windows, using this flag
  29751. // to control analysis of seac charstrings.
  29752. var SEAC_ANALYSIS_ENABLED = false;
  29753. var FontFlags = {
  29754. FixedPitch: 1,
  29755. Serif: 2,
  29756. Symbolic: 4,
  29757. Script: 8,
  29758. Nonsymbolic: 32,
  29759. Italic: 64,
  29760. AllCap: 65536,
  29761. SmallCap: 131072,
  29762. ForceBold: 262144
  29763. };
  29764. var Encodings = {
  29765. ExpertEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  29766. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  29767. 'space', 'exclamsmall', 'Hungarumlautsmall', '', 'dollaroldstyle',
  29768. 'dollarsuperior', 'ampersandsmall', 'Acutesmall', 'parenleftsuperior',
  29769. 'parenrightsuperior', 'twodotenleader', 'onedotenleader', 'comma',
  29770. 'hyphen', 'period', 'fraction', 'zerooldstyle', 'oneoldstyle',
  29771. 'twooldstyle', 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle',
  29772. 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle', 'colon',
  29773. 'semicolon', 'commasuperior', 'threequartersemdash', 'periodsuperior',
  29774. 'questionsmall', '', 'asuperior', 'bsuperior', 'centsuperior', 'dsuperior',
  29775. 'esuperior', '', '', 'isuperior', '', '', 'lsuperior', 'msuperior',
  29776. 'nsuperior', 'osuperior', '', '', 'rsuperior', 'ssuperior', 'tsuperior',
  29777. '', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior', '',
  29778. 'parenrightinferior', 'Circumflexsmall', 'hyphensuperior', 'Gravesmall',
  29779. 'Asmall', 'Bsmall', 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall',
  29780. 'Hsmall', 'Ismall', 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall',
  29781. 'Osmall', 'Psmall', 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall',
  29782. 'Vsmall', 'Wsmall', 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary',
  29783. 'onefitted', 'rupiah', 'Tildesmall', '', '', '', '', '', '', '', '', '',
  29784. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  29785. '', '', '', '', '', '', 'exclamdownsmall', 'centoldstyle', 'Lslashsmall',
  29786. '', '', 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall', 'Brevesmall',
  29787. 'Caronsmall', '', 'Dotaccentsmall', '', '', 'Macronsmall', '', '',
  29788. 'figuredash', 'hypheninferior', '', '', 'Ogoneksmall', 'Ringsmall',
  29789. 'Cedillasmall', '', '', '', 'onequarter', 'onehalf', 'threequarters',
  29790. 'questiondownsmall', 'oneeighth', 'threeeighths', 'fiveeighths',
  29791. 'seveneighths', 'onethird', 'twothirds', '', '', 'zerosuperior',
  29792. 'onesuperior', 'twosuperior', 'threesuperior', 'foursuperior',
  29793. 'fivesuperior', 'sixsuperior', 'sevensuperior', 'eightsuperior',
  29794. 'ninesuperior', 'zeroinferior', 'oneinferior', 'twoinferior',
  29795. 'threeinferior', 'fourinferior', 'fiveinferior', 'sixinferior',
  29796. 'seveninferior', 'eightinferior', 'nineinferior', 'centinferior',
  29797. 'dollarinferior', 'periodinferior', 'commainferior', 'Agravesmall',
  29798. 'Aacutesmall', 'Acircumflexsmall', 'Atildesmall', 'Adieresissmall',
  29799. 'Aringsmall', 'AEsmall', 'Ccedillasmall', 'Egravesmall', 'Eacutesmall',
  29800. 'Ecircumflexsmall', 'Edieresissmall', 'Igravesmall', 'Iacutesmall',
  29801. 'Icircumflexsmall', 'Idieresissmall', 'Ethsmall', 'Ntildesmall',
  29802. 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall', 'Otildesmall',
  29803. 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall', 'Uacutesmall',
  29804. 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall', 'Thornsmall',
  29805. 'Ydieresissmall'],
  29806. MacExpertEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  29807. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  29808. 'space', 'exclamsmall', 'Hungarumlautsmall', 'centoldstyle',
  29809. 'dollaroldstyle', 'dollarsuperior', 'ampersandsmall', 'Acutesmall',
  29810. 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  29811. 'onedotenleader', 'comma', 'hyphen', 'period', 'fraction', 'zerooldstyle',
  29812. 'oneoldstyle', 'twooldstyle', 'threeoldstyle', 'fouroldstyle',
  29813. 'fiveoldstyle', 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle',
  29814. 'nineoldstyle', 'colon', 'semicolon', '', 'threequartersemdash', '',
  29815. 'questionsmall', '', '', '', '', 'Ethsmall', '', '', 'onequarter',
  29816. 'onehalf', 'threequarters', 'oneeighth', 'threeeighths', 'fiveeighths',
  29817. 'seveneighths', 'onethird', 'twothirds', '', '', '', '', '', '', 'ff',
  29818. 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior', '', 'parenrightinferior',
  29819. 'Circumflexsmall', 'hypheninferior', 'Gravesmall', 'Asmall', 'Bsmall',
  29820. 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall', 'Hsmall', 'Ismall',
  29821. 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall', 'Osmall', 'Psmall',
  29822. 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall', 'Vsmall', 'Wsmall',
  29823. 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary', 'onefitted', 'rupiah',
  29824. 'Tildesmall', '', '', 'asuperior', 'centsuperior', '', '', '', '',
  29825. 'Aacutesmall', 'Agravesmall', 'Acircumflexsmall', 'Adieresissmall',
  29826. 'Atildesmall', 'Aringsmall', 'Ccedillasmall', 'Eacutesmall', 'Egravesmall',
  29827. 'Ecircumflexsmall', 'Edieresissmall', 'Iacutesmall', 'Igravesmall',
  29828. 'Icircumflexsmall', 'Idieresissmall', 'Ntildesmall', 'Oacutesmall',
  29829. 'Ogravesmall', 'Ocircumflexsmall', 'Odieresissmall', 'Otildesmall',
  29830. 'Uacutesmall', 'Ugravesmall', 'Ucircumflexsmall', 'Udieresissmall', '',
  29831. 'eightsuperior', 'fourinferior', 'threeinferior', 'sixinferior',
  29832. 'eightinferior', 'seveninferior', 'Scaronsmall', '', 'centinferior',
  29833. 'twoinferior', '', 'Dieresissmall', '', 'Caronsmall', 'osuperior',
  29834. 'fiveinferior', '', 'commainferior', 'periodinferior', 'Yacutesmall', '',
  29835. 'dollarinferior', '', 'Thornsmall', '', 'nineinferior', 'zeroinferior',
  29836. 'Zcaronsmall', 'AEsmall', 'Oslashsmall', 'questiondownsmall',
  29837. 'oneinferior', 'Lslashsmall', '', '', '', '', '', '', 'Cedillasmall', '',
  29838. '', '', '', '', 'OEsmall', 'figuredash', 'hyphensuperior', '', '', '', '',
  29839. 'exclamdownsmall', '', 'Ydieresissmall', '', 'onesuperior', 'twosuperior',
  29840. 'threesuperior', 'foursuperior', 'fivesuperior', 'sixsuperior',
  29841. 'sevensuperior', 'ninesuperior', 'zerosuperior', '', 'esuperior',
  29842. 'rsuperior', 'tsuperior', '', '', 'isuperior', 'ssuperior', 'dsuperior',
  29843. '', '', '', '', '', 'lsuperior', 'Ogoneksmall', 'Brevesmall',
  29844. 'Macronsmall', 'bsuperior', 'nsuperior', 'msuperior', 'commasuperior',
  29845. 'periodsuperior', 'Dotaccentsmall', 'Ringsmall'],
  29846. MacRomanEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  29847. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  29848. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  29849. 'ampersand', 'quotesingle', 'parenleft', 'parenright', 'asterisk', 'plus',
  29850. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  29851. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  29852. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  29853. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  29854. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  29855. 'asciicircum', 'underscore', 'grave', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
  29856. 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
  29857. 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde', '',
  29858. 'Adieresis', 'Aring', 'Ccedilla', 'Eacute', 'Ntilde', 'Odieresis',
  29859. 'Udieresis', 'aacute', 'agrave', 'acircumflex', 'adieresis', 'atilde',
  29860. 'aring', 'ccedilla', 'eacute', 'egrave', 'ecircumflex', 'edieresis',
  29861. 'iacute', 'igrave', 'icircumflex', 'idieresis', 'ntilde', 'oacute',
  29862. 'ograve', 'ocircumflex', 'odieresis', 'otilde', 'uacute', 'ugrave',
  29863. 'ucircumflex', 'udieresis', 'dagger', 'degree', 'cent', 'sterling',
  29864. 'section', 'bullet', 'paragraph', 'germandbls', 'registered', 'copyright',
  29865. 'trademark', 'acute', 'dieresis', 'notequal', 'AE', 'Oslash', 'infinity',
  29866. 'plusminus', 'lessequal', 'greaterequal', 'yen', 'mu', 'partialdiff',
  29867. 'summation', 'product', 'pi', 'integral', 'ordfeminine', 'ordmasculine',
  29868. 'Omega', 'ae', 'oslash', 'questiondown', 'exclamdown', 'logicalnot',
  29869. 'radical', 'florin', 'approxequal', 'Delta', 'guillemotleft',
  29870. 'guillemotright', 'ellipsis', 'space', 'Agrave', 'Atilde', 'Otilde', 'OE',
  29871. 'oe', 'endash', 'emdash', 'quotedblleft', 'quotedblright', 'quoteleft',
  29872. 'quoteright', 'divide', 'lozenge', 'ydieresis', 'Ydieresis', 'fraction',
  29873. 'currency', 'guilsinglleft', 'guilsinglright', 'fi', 'fl', 'daggerdbl',
  29874. 'periodcentered', 'quotesinglbase', 'quotedblbase', 'perthousand',
  29875. 'Acircumflex', 'Ecircumflex', 'Aacute', 'Edieresis', 'Egrave', 'Iacute',
  29876. 'Icircumflex', 'Idieresis', 'Igrave', 'Oacute', 'Ocircumflex', 'apple',
  29877. 'Ograve', 'Uacute', 'Ucircumflex', 'Ugrave', 'dotlessi', 'circumflex',
  29878. 'tilde', 'macron', 'breve', 'dotaccent', 'ring', 'cedilla', 'hungarumlaut',
  29879. 'ogonek', 'caron'],
  29880. StandardEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  29881. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  29882. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  29883. 'ampersand', 'quoteright', 'parenleft', 'parenright', 'asterisk', 'plus',
  29884. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  29885. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  29886. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  29887. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  29888. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  29889. 'asciicircum', 'underscore', 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f',
  29890. 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u',
  29891. 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde',
  29892. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  29893. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', 'exclamdown',
  29894. 'cent', 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  29895. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  29896. 'guilsinglright', 'fi', 'fl', '', 'endash', 'dagger', 'daggerdbl',
  29897. 'periodcentered', '', 'paragraph', 'bullet', 'quotesinglbase',
  29898. 'quotedblbase', 'quotedblright', 'guillemotright', 'ellipsis',
  29899. 'perthousand', '', 'questiondown', '', 'grave', 'acute', 'circumflex',
  29900. 'tilde', 'macron', 'breve', 'dotaccent', 'dieresis', '', 'ring', 'cedilla',
  29901. '', 'hungarumlaut', 'ogonek', 'caron', 'emdash', '', '', '', '', '', '',
  29902. '', '', '', '', '', '', '', '', '', '', 'AE', '', 'ordfeminine', '', '',
  29903. '', '', 'Lslash', 'Oslash', 'OE', 'ordmasculine', '', '', '', '', '', 'ae',
  29904. '', '', '', 'dotlessi', '', '', 'lslash', 'oslash', 'oe', 'germandbls'],
  29905. WinAnsiEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  29906. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  29907. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  29908. 'ampersand', 'quotesingle', 'parenleft', 'parenright', 'asterisk', 'plus',
  29909. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  29910. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  29911. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  29912. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  29913. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  29914. 'asciicircum', 'underscore', 'grave', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
  29915. 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
  29916. 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde',
  29917. 'bullet', 'Euro', 'bullet', 'quotesinglbase', 'florin', 'quotedblbase',
  29918. 'ellipsis', 'dagger', 'daggerdbl', 'circumflex', 'perthousand', 'Scaron',
  29919. 'guilsinglleft', 'OE', 'bullet', 'Zcaron', 'bullet', 'bullet', 'quoteleft',
  29920. 'quoteright', 'quotedblleft', 'quotedblright', 'bullet', 'endash',
  29921. 'emdash', 'tilde', 'trademark', 'scaron', 'guilsinglright', 'oe', 'bullet',
  29922. 'zcaron', 'Ydieresis', 'space', 'exclamdown', 'cent', 'sterling',
  29923. 'currency', 'yen', 'brokenbar', 'section', 'dieresis', 'copyright',
  29924. 'ordfeminine', 'guillemotleft', 'logicalnot', 'hyphen', 'registered',
  29925. 'macron', 'degree', 'plusminus', 'twosuperior', 'threesuperior', 'acute',
  29926. 'mu', 'paragraph', 'periodcentered', 'cedilla', 'onesuperior',
  29927. 'ordmasculine', 'guillemotright', 'onequarter', 'onehalf', 'threequarters',
  29928. 'questiondown', 'Agrave', 'Aacute', 'Acircumflex', 'Atilde', 'Adieresis',
  29929. 'Aring', 'AE', 'Ccedilla', 'Egrave', 'Eacute', 'Ecircumflex', 'Edieresis',
  29930. 'Igrave', 'Iacute', 'Icircumflex', 'Idieresis', 'Eth', 'Ntilde', 'Ograve',
  29931. 'Oacute', 'Ocircumflex', 'Otilde', 'Odieresis', 'multiply', 'Oslash',
  29932. 'Ugrave', 'Uacute', 'Ucircumflex', 'Udieresis', 'Yacute', 'Thorn',
  29933. 'germandbls', 'agrave', 'aacute', 'acircumflex', 'atilde', 'adieresis',
  29934. 'aring', 'ae', 'ccedilla', 'egrave', 'eacute', 'ecircumflex', 'edieresis',
  29935. 'igrave', 'iacute', 'icircumflex', 'idieresis', 'eth', 'ntilde', 'ograve',
  29936. 'oacute', 'ocircumflex', 'otilde', 'odieresis', 'divide', 'oslash',
  29937. 'ugrave', 'uacute', 'ucircumflex', 'udieresis', 'yacute', 'thorn',
  29938. 'ydieresis'],
  29939. SymbolSetEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  29940. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  29941. 'space', 'exclam', 'universal', 'numbersign', 'existential', 'percent',
  29942. 'ampersand', 'suchthat', 'parenleft', 'parenright', 'asteriskmath', 'plus',
  29943. 'comma', 'minus', 'period', 'slash', 'zero', 'one', 'two', 'three', 'four',
  29944. 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon', 'less',
  29945. 'equal', 'greater', 'question', 'congruent', 'Alpha', 'Beta', 'Chi',
  29946. 'Delta', 'Epsilon', 'Phi', 'Gamma', 'Eta', 'Iota', 'theta1', 'Kappa',
  29947. 'Lambda', 'Mu', 'Nu', 'Omicron', 'Pi', 'Theta', 'Rho', 'Sigma', 'Tau',
  29948. 'Upsilon', 'sigma1', 'Omega', 'Xi', 'Psi', 'Zeta', 'bracketleft',
  29949. 'therefore', 'bracketright', 'perpendicular', 'underscore', 'radicalex',
  29950. 'alpha', 'beta', 'chi', 'delta', 'epsilon', 'phi', 'gamma', 'eta', 'iota',
  29951. 'phi1', 'kappa', 'lambda', 'mu', 'nu', 'omicron', 'pi', 'theta', 'rho',
  29952. 'sigma', 'tau', 'upsilon', 'omega1', 'omega', 'xi', 'psi', 'zeta',
  29953. 'braceleft', 'bar', 'braceright', 'similar', '', '', '', '', '', '', '',
  29954. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  29955. '', '', '', '', '', '', '', 'Euro', 'Upsilon1', 'minute', 'lessequal',
  29956. 'fraction', 'infinity', 'florin', 'club', 'diamond', 'heart', 'spade',
  29957. 'arrowboth', 'arrowleft', 'arrowup', 'arrowright', 'arrowdown', 'degree',
  29958. 'plusminus', 'second', 'greaterequal', 'multiply', 'proportional',
  29959. 'partialdiff', 'bullet', 'divide', 'notequal', 'equivalence',
  29960. 'approxequal', 'ellipsis', 'arrowvertex', 'arrowhorizex', 'carriagereturn',
  29961. 'aleph', 'Ifraktur', 'Rfraktur', 'weierstrass', 'circlemultiply',
  29962. 'circleplus', 'emptyset', 'intersection', 'union', 'propersuperset',
  29963. 'reflexsuperset', 'notsubset', 'propersubset', 'reflexsubset', 'element',
  29964. 'notelement', 'angle', 'gradient', 'registerserif', 'copyrightserif',
  29965. 'trademarkserif', 'product', 'radical', 'dotmath', 'logicalnot',
  29966. 'logicaland', 'logicalor', 'arrowdblboth', 'arrowdblleft', 'arrowdblup',
  29967. 'arrowdblright', 'arrowdbldown', 'lozenge', 'angleleft', 'registersans',
  29968. 'copyrightsans', 'trademarksans', 'summation', 'parenlefttp',
  29969. 'parenleftex', 'parenleftbt', 'bracketlefttp', 'bracketleftex',
  29970. 'bracketleftbt', 'bracelefttp', 'braceleftmid', 'braceleftbt', 'braceex',
  29971. '', 'angleright', 'integral', 'integraltp', 'integralex', 'integralbt',
  29972. 'parenrighttp', 'parenrightex', 'parenrightbt', 'bracketrighttp',
  29973. 'bracketrightex', 'bracketrightbt', 'bracerighttp', 'bracerightmid',
  29974. 'bracerightbt'],
  29975. ZapfDingbatsEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  29976. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  29977. 'space', 'a1', 'a2', 'a202', 'a3', 'a4', 'a5', 'a119', 'a118', 'a117',
  29978. 'a11', 'a12', 'a13', 'a14', 'a15', 'a16', 'a105', 'a17', 'a18', 'a19',
  29979. 'a20', 'a21', 'a22', 'a23', 'a24', 'a25', 'a26', 'a27', 'a28', 'a6', 'a7',
  29980. 'a8', 'a9', 'a10', 'a29', 'a30', 'a31', 'a32', 'a33', 'a34', 'a35', 'a36',
  29981. 'a37', 'a38', 'a39', 'a40', 'a41', 'a42', 'a43', 'a44', 'a45', 'a46',
  29982. 'a47', 'a48', 'a49', 'a50', 'a51', 'a52', 'a53', 'a54', 'a55', 'a56',
  29983. 'a57', 'a58', 'a59', 'a60', 'a61', 'a62', 'a63', 'a64', 'a65', 'a66',
  29984. 'a67', 'a68', 'a69', 'a70', 'a71', 'a72', 'a73', 'a74', 'a203', 'a75',
  29985. 'a204', 'a76', 'a77', 'a78', 'a79', 'a81', 'a82', 'a83', 'a84', 'a97',
  29986. 'a98', 'a99', 'a100', '', 'a89', 'a90', 'a93', 'a94', 'a91', 'a92', 'a205',
  29987. 'a85', 'a206', 'a86', 'a87', 'a88', 'a95', 'a96', '', '', '', '', '', '',
  29988. '', '', '', '', '', '', '', '', '', '', '', '', '', 'a101', 'a102', 'a103',
  29989. 'a104', 'a106', 'a107', 'a108', 'a112', 'a111', 'a110', 'a109', 'a120',
  29990. 'a121', 'a122', 'a123', 'a124', 'a125', 'a126', 'a127', 'a128', 'a129',
  29991. 'a130', 'a131', 'a132', 'a133', 'a134', 'a135', 'a136', 'a137', 'a138',
  29992. 'a139', 'a140', 'a141', 'a142', 'a143', 'a144', 'a145', 'a146', 'a147',
  29993. 'a148', 'a149', 'a150', 'a151', 'a152', 'a153', 'a154', 'a155', 'a156',
  29994. 'a157', 'a158', 'a159', 'a160', 'a161', 'a163', 'a164', 'a196', 'a165',
  29995. 'a192', 'a166', 'a167', 'a168', 'a169', 'a170', 'a171', 'a172', 'a173',
  29996. 'a162', 'a174', 'a175', 'a176', 'a177', 'a178', 'a179', 'a193', 'a180',
  29997. 'a199', 'a181', 'a200', 'a182', '', 'a201', 'a183', 'a184', 'a197', 'a185',
  29998. 'a194', 'a198', 'a186', 'a195', 'a187', 'a188', 'a189', 'a190', 'a191']
  29999. };
  30000. /**
  30001. * Hold a map of decoded fonts and of the standard fourteen Type1
  30002. * fonts and their acronyms.
  30003. */
  30004. var stdFontMap = {
  30005. 'ArialNarrow': 'Helvetica',
  30006. 'ArialNarrow-Bold': 'Helvetica-Bold',
  30007. 'ArialNarrow-BoldItalic': 'Helvetica-BoldOblique',
  30008. 'ArialNarrow-Italic': 'Helvetica-Oblique',
  30009. 'ArialBlack': 'Helvetica',
  30010. 'ArialBlack-Bold': 'Helvetica-Bold',
  30011. 'ArialBlack-BoldItalic': 'Helvetica-BoldOblique',
  30012. 'ArialBlack-Italic': 'Helvetica-Oblique',
  30013. 'Arial': 'Helvetica',
  30014. 'Arial-Bold': 'Helvetica-Bold',
  30015. 'Arial-BoldItalic': 'Helvetica-BoldOblique',
  30016. 'Arial-Italic': 'Helvetica-Oblique',
  30017. 'Arial-BoldItalicMT': 'Helvetica-BoldOblique',
  30018. 'Arial-BoldMT': 'Helvetica-Bold',
  30019. 'Arial-ItalicMT': 'Helvetica-Oblique',
  30020. 'ArialMT': 'Helvetica',
  30021. 'Courier-Bold': 'Courier-Bold',
  30022. 'Courier-BoldItalic': 'Courier-BoldOblique',
  30023. 'Courier-Italic': 'Courier-Oblique',
  30024. 'CourierNew': 'Courier',
  30025. 'CourierNew-Bold': 'Courier-Bold',
  30026. 'CourierNew-BoldItalic': 'Courier-BoldOblique',
  30027. 'CourierNew-Italic': 'Courier-Oblique',
  30028. 'CourierNewPS-BoldItalicMT': 'Courier-BoldOblique',
  30029. 'CourierNewPS-BoldMT': 'Courier-Bold',
  30030. 'CourierNewPS-ItalicMT': 'Courier-Oblique',
  30031. 'CourierNewPSMT': 'Courier',
  30032. 'Helvetica': 'Helvetica',
  30033. 'Helvetica-Bold': 'Helvetica-Bold',
  30034. 'Helvetica-BoldItalic': 'Helvetica-BoldOblique',
  30035. 'Helvetica-BoldOblique': 'Helvetica-BoldOblique',
  30036. 'Helvetica-Italic': 'Helvetica-Oblique',
  30037. 'Helvetica-Oblique':'Helvetica-Oblique',
  30038. 'Symbol-Bold': 'Symbol',
  30039. 'Symbol-BoldItalic': 'Symbol',
  30040. 'Symbol-Italic': 'Symbol',
  30041. 'TimesNewRoman': 'Times-Roman',
  30042. 'TimesNewRoman-Bold': 'Times-Bold',
  30043. 'TimesNewRoman-BoldItalic': 'Times-BoldItalic',
  30044. 'TimesNewRoman-Italic': 'Times-Italic',
  30045. 'TimesNewRomanPS': 'Times-Roman',
  30046. 'TimesNewRomanPS-Bold': 'Times-Bold',
  30047. 'TimesNewRomanPS-BoldItalic': 'Times-BoldItalic',
  30048. 'TimesNewRomanPS-BoldItalicMT': 'Times-BoldItalic',
  30049. 'TimesNewRomanPS-BoldMT': 'Times-Bold',
  30050. 'TimesNewRomanPS-Italic': 'Times-Italic',
  30051. 'TimesNewRomanPS-ItalicMT': 'Times-Italic',
  30052. 'TimesNewRomanPSMT': 'Times-Roman',
  30053. 'TimesNewRomanPSMT-Bold': 'Times-Bold',
  30054. 'TimesNewRomanPSMT-BoldItalic': 'Times-BoldItalic',
  30055. 'TimesNewRomanPSMT-Italic': 'Times-Italic'
  30056. };
  30057. /**
  30058. * Holds the map of the non-standard fonts that might be included as a standard
  30059. * fonts without glyph data.
  30060. */
  30061. var nonStdFontMap = {
  30062. 'CenturyGothic': 'Helvetica',
  30063. 'CenturyGothic-Bold': 'Helvetica-Bold',
  30064. 'CenturyGothic-BoldItalic': 'Helvetica-BoldOblique',
  30065. 'CenturyGothic-Italic': 'Helvetica-Oblique',
  30066. 'ComicSansMS': 'Comic Sans MS',
  30067. 'ComicSansMS-Bold': 'Comic Sans MS-Bold',
  30068. 'ComicSansMS-BoldItalic': 'Comic Sans MS-BoldItalic',
  30069. 'ComicSansMS-Italic': 'Comic Sans MS-Italic',
  30070. 'LucidaConsole': 'Courier',
  30071. 'LucidaConsole-Bold': 'Courier-Bold',
  30072. 'LucidaConsole-BoldItalic': 'Courier-BoldOblique',
  30073. 'LucidaConsole-Italic': 'Courier-Oblique',
  30074. 'MS-Gothic': 'MS Gothic',
  30075. 'MS-Gothic-Bold': 'MS Gothic-Bold',
  30076. 'MS-Gothic-BoldItalic': 'MS Gothic-BoldItalic',
  30077. 'MS-Gothic-Italic': 'MS Gothic-Italic',
  30078. 'MS-Mincho': 'MS Mincho',
  30079. 'MS-Mincho-Bold': 'MS Mincho-Bold',
  30080. 'MS-Mincho-BoldItalic': 'MS Mincho-BoldItalic',
  30081. 'MS-Mincho-Italic': 'MS Mincho-Italic',
  30082. 'MS-PGothic': 'MS PGothic',
  30083. 'MS-PGothic-Bold': 'MS PGothic-Bold',
  30084. 'MS-PGothic-BoldItalic': 'MS PGothic-BoldItalic',
  30085. 'MS-PGothic-Italic': 'MS PGothic-Italic',
  30086. 'MS-PMincho': 'MS PMincho',
  30087. 'MS-PMincho-Bold': 'MS PMincho-Bold',
  30088. 'MS-PMincho-BoldItalic': 'MS PMincho-BoldItalic',
  30089. 'MS-PMincho-Italic': 'MS PMincho-Italic',
  30090. 'Wingdings': 'ZapfDingbats'
  30091. };
  30092. var serifFonts = {
  30093. 'Adobe Jenson': true, 'Adobe Text': true, 'Albertus': true,
  30094. 'Aldus': true, 'Alexandria': true, 'Algerian': true,
  30095. 'American Typewriter': true, 'Antiqua': true, 'Apex': true,
  30096. 'Arno': true, 'Aster': true, 'Aurora': true,
  30097. 'Baskerville': true, 'Bell': true, 'Bembo': true,
  30098. 'Bembo Schoolbook': true, 'Benguiat': true, 'Berkeley Old Style': true,
  30099. 'Bernhard Modern': true, 'Berthold City': true, 'Bodoni': true,
  30100. 'Bauer Bodoni': true, 'Book Antiqua': true, 'Bookman': true,
  30101. 'Bordeaux Roman': true, 'Californian FB': true, 'Calisto': true,
  30102. 'Calvert': true, 'Capitals': true, 'Cambria': true,
  30103. 'Cartier': true, 'Caslon': true, 'Catull': true,
  30104. 'Centaur': true, 'Century Old Style': true, 'Century Schoolbook': true,
  30105. 'Chaparral': true, 'Charis SIL': true, 'Cheltenham': true,
  30106. 'Cholla Slab': true, 'Clarendon': true, 'Clearface': true,
  30107. 'Cochin': true, 'Colonna': true, 'Computer Modern': true,
  30108. 'Concrete Roman': true, 'Constantia': true, 'Cooper Black': true,
  30109. 'Corona': true, 'Ecotype': true, 'Egyptienne': true,
  30110. 'Elephant': true, 'Excelsior': true, 'Fairfield': true,
  30111. 'FF Scala': true, 'Folkard': true, 'Footlight': true,
  30112. 'FreeSerif': true, 'Friz Quadrata': true, 'Garamond': true,
  30113. 'Gentium': true, 'Georgia': true, 'Gloucester': true,
  30114. 'Goudy Old Style': true, 'Goudy Schoolbook': true, 'Goudy Pro Font': true,
  30115. 'Granjon': true, 'Guardian Egyptian': true, 'Heather': true,
  30116. 'Hercules': true, 'High Tower Text': true, 'Hiroshige': true,
  30117. 'Hoefler Text': true, 'Humana Serif': true, 'Imprint': true,
  30118. 'Ionic No. 5': true, 'Janson': true, 'Joanna': true,
  30119. 'Korinna': true, 'Lexicon': true, 'Liberation Serif': true,
  30120. 'Linux Libertine': true, 'Literaturnaya': true, 'Lucida': true,
  30121. 'Lucida Bright': true, 'Melior': true, 'Memphis': true,
  30122. 'Miller': true, 'Minion': true, 'Modern': true,
  30123. 'Mona Lisa': true, 'Mrs Eaves': true, 'MS Serif': true,
  30124. 'Museo Slab': true, 'New York': true, 'Nimbus Roman': true,
  30125. 'NPS Rawlinson Roadway': true, 'Palatino': true, 'Perpetua': true,
  30126. 'Plantin': true, 'Plantin Schoolbook': true, 'Playbill': true,
  30127. 'Poor Richard': true, 'Rawlinson Roadway': true, 'Renault': true,
  30128. 'Requiem': true, 'Rockwell': true, 'Roman': true,
  30129. 'Rotis Serif': true, 'Sabon': true, 'Scala': true,
  30130. 'Seagull': true, 'Sistina': true, 'Souvenir': true,
  30131. 'STIX': true, 'Stone Informal': true, 'Stone Serif': true,
  30132. 'Sylfaen': true, 'Times': true, 'Trajan': true,
  30133. 'Trinité': true, 'Trump Mediaeval': true, 'Utopia': true,
  30134. 'Vale Type': true, 'Bitstream Vera': true, 'Vera Serif': true,
  30135. 'Versailles': true, 'Wanted': true, 'Weiss': true,
  30136. 'Wide Latin': true, 'Windsor': true, 'XITS': true
  30137. };
  30138. var symbolsFonts = {
  30139. 'Dingbats': true, 'Symbol': true, 'ZapfDingbats': true
  30140. };
  30141. // Glyph map for well-known standard fonts. Sometimes Ghostscript uses CID fonts
  30142. // but does not embed the CID to GID mapping. The mapping is incomplete for all
  30143. // glyphs, but common for some set of the standard fonts.
  30144. var GlyphMapForStandardFonts = {
  30145. '2': 10, '3': 32, '4': 33, '5': 34, '6': 35, '7': 36, '8': 37, '9': 38,
  30146. '10': 39, '11': 40, '12': 41, '13': 42, '14': 43, '15': 44, '16': 45,
  30147. '17': 46, '18': 47, '19': 48, '20': 49, '21': 50, '22': 51, '23': 52,
  30148. '24': 53, '25': 54, '26': 55, '27': 56, '28': 57, '29': 58, '30': 894,
  30149. '31': 60, '32': 61, '33': 62, '34': 63, '35': 64, '36': 65, '37': 66,
  30150. '38': 67, '39': 68, '40': 69, '41': 70, '42': 71, '43': 72, '44': 73,
  30151. '45': 74, '46': 75, '47': 76, '48': 77, '49': 78, '50': 79, '51': 80,
  30152. '52': 81, '53': 82, '54': 83, '55': 84, '56': 85, '57': 86, '58': 87,
  30153. '59': 88, '60': 89, '61': 90, '62': 91, '63': 92, '64': 93, '65': 94,
  30154. '66': 95, '67': 96, '68': 97, '69': 98, '70': 99, '71': 100, '72': 101,
  30155. '73': 102, '74': 103, '75': 104, '76': 105, '77': 106, '78': 107, '79': 108,
  30156. '80': 109, '81': 110, '82': 111, '83': 112, '84': 113, '85': 114, '86': 115,
  30157. '87': 116, '88': 117, '89': 118, '90': 119, '91': 120, '92': 121, '93': 122,
  30158. '94': 123, '95': 124, '96': 125, '97': 126, '98': 196, '99': 197, '100': 199,
  30159. '101': 201, '102': 209, '103': 214, '104': 220, '105': 225, '106': 224,
  30160. '107': 226, '108': 228, '109': 227, '110': 229, '111': 231, '112': 233,
  30161. '113': 232, '114': 234, '115': 235, '116': 237, '117': 236, '118': 238,
  30162. '119': 239, '120': 241, '121': 243, '122': 242, '123': 244, '124': 246,
  30163. '125': 245, '126': 250, '127': 249, '128': 251, '129': 252, '130': 8224,
  30164. '131': 176, '132': 162, '133': 163, '134': 167, '135': 8226, '136': 182,
  30165. '137': 223, '138': 174, '139': 169, '140': 8482, '141': 180, '142': 168,
  30166. '143': 8800, '144': 198, '145': 216, '146': 8734, '147': 177, '148': 8804,
  30167. '149': 8805, '150': 165, '151': 181, '152': 8706, '153': 8721, '154': 8719,
  30168. '156': 8747, '157': 170, '158': 186, '159': 8486, '160': 230, '161': 248,
  30169. '162': 191, '163': 161, '164': 172, '165': 8730, '166': 402, '167': 8776,
  30170. '168': 8710, '169': 171, '170': 187, '171': 8230, '210': 218, '223': 711,
  30171. '224': 321, '225': 322, '227': 353, '229': 382, '234': 253, '252': 263,
  30172. '253': 268, '254': 269, '258': 258, '260': 260, '261': 261, '265': 280,
  30173. '266': 281, '268': 283, '269': 313, '275': 323, '276': 324, '278': 328,
  30174. '284': 345, '285': 346, '286': 347, '292': 367, '295': 377, '296': 378,
  30175. '298': 380, '305': 963,
  30176. '306': 964, '307': 966, '308': 8215, '309': 8252, '310': 8319, '311': 8359,
  30177. '312': 8592, '313': 8593, '337': 9552, '493': 1039, '494': 1040, '705': 1524,
  30178. '706': 8362, '710': 64288, '711': 64298, '759': 1617, '761': 1776,
  30179. '763': 1778, '775': 1652, '777': 1764, '778': 1780, '779': 1781, '780': 1782,
  30180. '782': 771, '783': 64726, '786': 8363, '788': 8532, '790': 768, '791': 769,
  30181. '792': 768, '795': 803, '797': 64336, '798': 64337, '799': 64342,
  30182. '800': 64343, '801': 64344, '802': 64345, '803': 64362, '804': 64363,
  30183. '805': 64364, '2424': 7821, '2425': 7822, '2426': 7823, '2427': 7824,
  30184. '2428': 7825, '2429': 7826, '2430': 7827, '2433': 7682, '2678': 8045,
  30185. '2679': 8046, '2830': 1552, '2838': 686, '2840': 751, '2842': 753,
  30186. '2843': 754, '2844': 755, '2846': 757, '2856': 767, '2857': 848, '2858': 849,
  30187. '2862': 853, '2863': 854, '2864': 855, '2865': 861, '2866': 862, '2906': 7460,
  30188. '2908': 7462, '2909': 7463, '2910': 7464, '2912': 7466, '2913': 7467,
  30189. '2914': 7468, '2916': 7470, '2917': 7471, '2918': 7472, '2920': 7474,
  30190. '2921': 7475, '2922': 7476, '2924': 7478, '2925': 7479, '2926': 7480,
  30191. '2928': 7482, '2929': 7483, '2930': 7484, '2932': 7486, '2933': 7487,
  30192. '2934': 7488, '2936': 7490, '2937': 7491, '2938': 7492, '2940': 7494,
  30193. '2941': 7495, '2942': 7496, '2944': 7498, '2946': 7500, '2948': 7502,
  30194. '2950': 7504, '2951': 7505, '2952': 7506, '2954': 7508, '2955': 7509,
  30195. '2956': 7510, '2958': 7512, '2959': 7513, '2960': 7514, '2962': 7516,
  30196. '2963': 7517, '2964': 7518, '2966': 7520, '2967': 7521, '2968': 7522,
  30197. '2970': 7524, '2971': 7525, '2972': 7526, '2974': 7528, '2975': 7529,
  30198. '2976': 7530, '2978': 1537, '2979': 1538, '2980': 1539, '2982': 1549,
  30199. '2983': 1551, '2984': 1552, '2986': 1554, '2987': 1555, '2988': 1556,
  30200. '2990': 1623, '2991': 1624, '2995': 1775, '2999': 1791, '3002': 64290,
  30201. '3003': 64291, '3004': 64292, '3006': 64294, '3007': 64295, '3008': 64296,
  30202. '3011': 1900, '3014': 8223, '3015': 8244, '3017': 7532, '3018': 7533,
  30203. '3019': 7534, '3075': 7590, '3076': 7591, '3079': 7594, '3080': 7595,
  30204. '3083': 7598, '3084': 7599, '3087': 7602, '3088': 7603, '3091': 7606,
  30205. '3092': 7607, '3095': 7610, '3096': 7611, '3099': 7614, '3100': 7615,
  30206. '3103': 7618, '3104': 7619, '3107': 8337, '3108': 8338, '3116': 1884,
  30207. '3119': 1885, '3120': 1885, '3123': 1886, '3124': 1886, '3127': 1887,
  30208. '3128': 1887, '3131': 1888, '3132': 1888, '3135': 1889, '3136': 1889,
  30209. '3139': 1890, '3140': 1890, '3143': 1891, '3144': 1891, '3147': 1892,
  30210. '3148': 1892, '3153': 580, '3154': 581, '3157': 584, '3158': 585, '3161': 588,
  30211. '3162': 589, '3165': 891, '3166': 892, '3169': 1274, '3170': 1275,
  30212. '3173': 1278, '3174': 1279, '3181': 7622, '3182': 7623, '3282': 11799,
  30213. '3316': 578, '3379': 42785, '3393': 1159, '3416': 8377
  30214. };
  30215. // The glyph map for ArialBlack differs slightly from the glyph map used for
  30216. // other well-known standard fonts. Hence we use this (incomplete) CID to GID
  30217. // mapping to adjust the glyph map for non-embedded ArialBlack fonts.
  30218. var SupplementalGlyphMapForArialBlack = {
  30219. '227': 322, '264': 261, '291': 346,
  30220. };
  30221. // Some characters, e.g. copyrightserif, are mapped to the private use area and
  30222. // might not be displayed using standard fonts. Mapping/hacking well-known chars
  30223. // to the similar equivalents in the normal characters range.
  30224. var SpecialPUASymbols = {
  30225. '63721': 0x00A9, // copyrightsans (0xF8E9) => copyright
  30226. '63193': 0x00A9, // copyrightserif (0xF6D9) => copyright
  30227. '63720': 0x00AE, // registersans (0xF8E8) => registered
  30228. '63194': 0x00AE, // registerserif (0xF6DA) => registered
  30229. '63722': 0x2122, // trademarksans (0xF8EA) => trademark
  30230. '63195': 0x2122, // trademarkserif (0xF6DB) => trademark
  30231. '63729': 0x23A7, // bracelefttp (0xF8F1)
  30232. '63730': 0x23A8, // braceleftmid (0xF8F2)
  30233. '63731': 0x23A9, // braceleftbt (0xF8F3)
  30234. '63740': 0x23AB, // bracerighttp (0xF8FC)
  30235. '63741': 0x23AC, // bracerightmid (0xF8FD)
  30236. '63742': 0x23AD, // bracerightbt (0xF8FE)
  30237. '63726': 0x23A1, // bracketlefttp (0xF8EE)
  30238. '63727': 0x23A2, // bracketleftex (0xF8EF)
  30239. '63728': 0x23A3, // bracketleftbt (0xF8F0)
  30240. '63737': 0x23A4, // bracketrighttp (0xF8F9)
  30241. '63738': 0x23A5, // bracketrightex (0xF8FA)
  30242. '63739': 0x23A6, // bracketrightbt (0xF8FB)
  30243. '63723': 0x239B, // parenlefttp (0xF8EB)
  30244. '63724': 0x239C, // parenleftex (0xF8EC)
  30245. '63725': 0x239D, // parenleftbt (0xF8ED)
  30246. '63734': 0x239E, // parenrighttp (0xF8F6)
  30247. '63735': 0x239F, // parenrightex (0xF8F7)
  30248. '63736': 0x23A0, // parenrightbt (0xF8F8)
  30249. };
  30250. function mapSpecialUnicodeValues(code) {
  30251. if (code >= 0xFFF0 && code <= 0xFFFF) { // Specials unicode block.
  30252. return 0;
  30253. } else if (code >= 0xF600 && code <= 0xF8FF) {
  30254. return (SpecialPUASymbols[code] || code);
  30255. }
  30256. return code;
  30257. }
  30258. var UnicodeRanges = [
  30259. { 'begin': 0x0000, 'end': 0x007F }, // Basic Latin
  30260. { 'begin': 0x0080, 'end': 0x00FF }, // Latin-1 Supplement
  30261. { 'begin': 0x0100, 'end': 0x017F }, // Latin Extended-A
  30262. { 'begin': 0x0180, 'end': 0x024F }, // Latin Extended-B
  30263. { 'begin': 0x0250, 'end': 0x02AF }, // IPA Extensions
  30264. { 'begin': 0x02B0, 'end': 0x02FF }, // Spacing Modifier Letters
  30265. { 'begin': 0x0300, 'end': 0x036F }, // Combining Diacritical Marks
  30266. { 'begin': 0x0370, 'end': 0x03FF }, // Greek and Coptic
  30267. { 'begin': 0x2C80, 'end': 0x2CFF }, // Coptic
  30268. { 'begin': 0x0400, 'end': 0x04FF }, // Cyrillic
  30269. { 'begin': 0x0530, 'end': 0x058F }, // Armenian
  30270. { 'begin': 0x0590, 'end': 0x05FF }, // Hebrew
  30271. { 'begin': 0xA500, 'end': 0xA63F }, // Vai
  30272. { 'begin': 0x0600, 'end': 0x06FF }, // Arabic
  30273. { 'begin': 0x07C0, 'end': 0x07FF }, // NKo
  30274. { 'begin': 0x0900, 'end': 0x097F }, // Devanagari
  30275. { 'begin': 0x0980, 'end': 0x09FF }, // Bengali
  30276. { 'begin': 0x0A00, 'end': 0x0A7F }, // Gurmukhi
  30277. { 'begin': 0x0A80, 'end': 0x0AFF }, // Gujarati
  30278. { 'begin': 0x0B00, 'end': 0x0B7F }, // Oriya
  30279. { 'begin': 0x0B80, 'end': 0x0BFF }, // Tamil
  30280. { 'begin': 0x0C00, 'end': 0x0C7F }, // Telugu
  30281. { 'begin': 0x0C80, 'end': 0x0CFF }, // Kannada
  30282. { 'begin': 0x0D00, 'end': 0x0D7F }, // Malayalam
  30283. { 'begin': 0x0E00, 'end': 0x0E7F }, // Thai
  30284. { 'begin': 0x0E80, 'end': 0x0EFF }, // Lao
  30285. { 'begin': 0x10A0, 'end': 0x10FF }, // Georgian
  30286. { 'begin': 0x1B00, 'end': 0x1B7F }, // Balinese
  30287. { 'begin': 0x1100, 'end': 0x11FF }, // Hangul Jamo
  30288. { 'begin': 0x1E00, 'end': 0x1EFF }, // Latin Extended Additional
  30289. { 'begin': 0x1F00, 'end': 0x1FFF }, // Greek Extended
  30290. { 'begin': 0x2000, 'end': 0x206F }, // General Punctuation
  30291. { 'begin': 0x2070, 'end': 0x209F }, // Superscripts And Subscripts
  30292. { 'begin': 0x20A0, 'end': 0x20CF }, // Currency Symbol
  30293. { 'begin': 0x20D0, 'end': 0x20FF }, // Combining Diacritical Marks For Symbols
  30294. { 'begin': 0x2100, 'end': 0x214F }, // Letterlike Symbols
  30295. { 'begin': 0x2150, 'end': 0x218F }, // Number Forms
  30296. { 'begin': 0x2190, 'end': 0x21FF }, // Arrows
  30297. { 'begin': 0x2200, 'end': 0x22FF }, // Mathematical Operators
  30298. { 'begin': 0x2300, 'end': 0x23FF }, // Miscellaneous Technical
  30299. { 'begin': 0x2400, 'end': 0x243F }, // Control Pictures
  30300. { 'begin': 0x2440, 'end': 0x245F }, // Optical Character Recognition
  30301. { 'begin': 0x2460, 'end': 0x24FF }, // Enclosed Alphanumerics
  30302. { 'begin': 0x2500, 'end': 0x257F }, // Box Drawing
  30303. { 'begin': 0x2580, 'end': 0x259F }, // Block Elements
  30304. { 'begin': 0x25A0, 'end': 0x25FF }, // Geometric Shapes
  30305. { 'begin': 0x2600, 'end': 0x26FF }, // Miscellaneous Symbols
  30306. { 'begin': 0x2700, 'end': 0x27BF }, // Dingbats
  30307. { 'begin': 0x3000, 'end': 0x303F }, // CJK Symbols And Punctuation
  30308. { 'begin': 0x3040, 'end': 0x309F }, // Hiragana
  30309. { 'begin': 0x30A0, 'end': 0x30FF }, // Katakana
  30310. { 'begin': 0x3100, 'end': 0x312F }, // Bopomofo
  30311. { 'begin': 0x3130, 'end': 0x318F }, // Hangul Compatibility Jamo
  30312. { 'begin': 0xA840, 'end': 0xA87F }, // Phags-pa
  30313. { 'begin': 0x3200, 'end': 0x32FF }, // Enclosed CJK Letters And Months
  30314. { 'begin': 0x3300, 'end': 0x33FF }, // CJK Compatibility
  30315. { 'begin': 0xAC00, 'end': 0xD7AF }, // Hangul Syllables
  30316. { 'begin': 0xD800, 'end': 0xDFFF }, // Non-Plane 0 *
  30317. { 'begin': 0x10900, 'end': 0x1091F }, // Phoenicia
  30318. { 'begin': 0x4E00, 'end': 0x9FFF }, // CJK Unified Ideographs
  30319. { 'begin': 0xE000, 'end': 0xF8FF }, // Private Use Area (plane 0)
  30320. { 'begin': 0x31C0, 'end': 0x31EF }, // CJK Strokes
  30321. { 'begin': 0xFB00, 'end': 0xFB4F }, // Alphabetic Presentation Forms
  30322. { 'begin': 0xFB50, 'end': 0xFDFF }, // Arabic Presentation Forms-A
  30323. { 'begin': 0xFE20, 'end': 0xFE2F }, // Combining Half Marks
  30324. { 'begin': 0xFE10, 'end': 0xFE1F }, // Vertical Forms
  30325. { 'begin': 0xFE50, 'end': 0xFE6F }, // Small Form Variants
  30326. { 'begin': 0xFE70, 'end': 0xFEFF }, // Arabic Presentation Forms-B
  30327. { 'begin': 0xFF00, 'end': 0xFFEF }, // Halfwidth And Fullwidth Forms
  30328. { 'begin': 0xFFF0, 'end': 0xFFFF }, // Specials
  30329. { 'begin': 0x0F00, 'end': 0x0FFF }, // Tibetan
  30330. { 'begin': 0x0700, 'end': 0x074F }, // Syriac
  30331. { 'begin': 0x0780, 'end': 0x07BF }, // Thaana
  30332. { 'begin': 0x0D80, 'end': 0x0DFF }, // Sinhala
  30333. { 'begin': 0x1000, 'end': 0x109F }, // Myanmar
  30334. { 'begin': 0x1200, 'end': 0x137F }, // Ethiopic
  30335. { 'begin': 0x13A0, 'end': 0x13FF }, // Cherokee
  30336. { 'begin': 0x1400, 'end': 0x167F }, // Unified Canadian Aboriginal Syllabics
  30337. { 'begin': 0x1680, 'end': 0x169F }, // Ogham
  30338. { 'begin': 0x16A0, 'end': 0x16FF }, // Runic
  30339. { 'begin': 0x1780, 'end': 0x17FF }, // Khmer
  30340. { 'begin': 0x1800, 'end': 0x18AF }, // Mongolian
  30341. { 'begin': 0x2800, 'end': 0x28FF }, // Braille Patterns
  30342. { 'begin': 0xA000, 'end': 0xA48F }, // Yi Syllables
  30343. { 'begin': 0x1700, 'end': 0x171F }, // Tagalog
  30344. { 'begin': 0x10300, 'end': 0x1032F }, // Old Italic
  30345. { 'begin': 0x10330, 'end': 0x1034F }, // Gothic
  30346. { 'begin': 0x10400, 'end': 0x1044F }, // Deseret
  30347. { 'begin': 0x1D000, 'end': 0x1D0FF }, // Byzantine Musical Symbols
  30348. { 'begin': 0x1D400, 'end': 0x1D7FF }, // Mathematical Alphanumeric Symbols
  30349. { 'begin': 0xFF000, 'end': 0xFFFFD }, // Private Use (plane 15)
  30350. { 'begin': 0xFE00, 'end': 0xFE0F }, // Variation Selectors
  30351. { 'begin': 0xE0000, 'end': 0xE007F }, // Tags
  30352. { 'begin': 0x1900, 'end': 0x194F }, // Limbu
  30353. { 'begin': 0x1950, 'end': 0x197F }, // Tai Le
  30354. { 'begin': 0x1980, 'end': 0x19DF }, // New Tai Lue
  30355. { 'begin': 0x1A00, 'end': 0x1A1F }, // Buginese
  30356. { 'begin': 0x2C00, 'end': 0x2C5F }, // Glagolitic
  30357. { 'begin': 0x2D30, 'end': 0x2D7F }, // Tifinagh
  30358. { 'begin': 0x4DC0, 'end': 0x4DFF }, // Yijing Hexagram Symbols
  30359. { 'begin': 0xA800, 'end': 0xA82F }, // Syloti Nagri
  30360. { 'begin': 0x10000, 'end': 0x1007F }, // Linear B Syllabary
  30361. { 'begin': 0x10140, 'end': 0x1018F }, // Ancient Greek Numbers
  30362. { 'begin': 0x10380, 'end': 0x1039F }, // Ugaritic
  30363. { 'begin': 0x103A0, 'end': 0x103DF }, // Old Persian
  30364. { 'begin': 0x10450, 'end': 0x1047F }, // Shavian
  30365. { 'begin': 0x10480, 'end': 0x104AF }, // Osmanya
  30366. { 'begin': 0x10800, 'end': 0x1083F }, // Cypriot Syllabary
  30367. { 'begin': 0x10A00, 'end': 0x10A5F }, // Kharoshthi
  30368. { 'begin': 0x1D300, 'end': 0x1D35F }, // Tai Xuan Jing Symbols
  30369. { 'begin': 0x12000, 'end': 0x123FF }, // Cuneiform
  30370. { 'begin': 0x1D360, 'end': 0x1D37F }, // Counting Rod Numerals
  30371. { 'begin': 0x1B80, 'end': 0x1BBF }, // Sundanese
  30372. { 'begin': 0x1C00, 'end': 0x1C4F }, // Lepcha
  30373. { 'begin': 0x1C50, 'end': 0x1C7F }, // Ol Chiki
  30374. { 'begin': 0xA880, 'end': 0xA8DF }, // Saurashtra
  30375. { 'begin': 0xA900, 'end': 0xA92F }, // Kayah Li
  30376. { 'begin': 0xA930, 'end': 0xA95F }, // Rejang
  30377. { 'begin': 0xAA00, 'end': 0xAA5F }, // Cham
  30378. { 'begin': 0x10190, 'end': 0x101CF }, // Ancient Symbols
  30379. { 'begin': 0x101D0, 'end': 0x101FF }, // Phaistos Disc
  30380. { 'begin': 0x102A0, 'end': 0x102DF }, // Carian
  30381. { 'begin': 0x1F030, 'end': 0x1F09F } // Domino Tiles
  30382. ];
  30383. var MacStandardGlyphOrdering = [
  30384. '.notdef', '.null', 'nonmarkingreturn', 'space', 'exclam', 'quotedbl',
  30385. 'numbersign', 'dollar', 'percent', 'ampersand', 'quotesingle', 'parenleft',
  30386. 'parenright', 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash',
  30387. 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',
  30388. 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater', 'question', 'at',
  30389. 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
  30390. 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'bracketleft',
  30391. 'backslash', 'bracketright', 'asciicircum', 'underscore', 'grave', 'a', 'b',
  30392. 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q',
  30393. 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright',
  30394. 'asciitilde', 'Adieresis', 'Aring', 'Ccedilla', 'Eacute', 'Ntilde',
  30395. 'Odieresis', 'Udieresis', 'aacute', 'agrave', 'acircumflex', 'adieresis',
  30396. 'atilde', 'aring', 'ccedilla', 'eacute', 'egrave', 'ecircumflex', 'edieresis',
  30397. 'iacute', 'igrave', 'icircumflex', 'idieresis', 'ntilde', 'oacute', 'ograve',
  30398. 'ocircumflex', 'odieresis', 'otilde', 'uacute', 'ugrave', 'ucircumflex',
  30399. 'udieresis', 'dagger', 'degree', 'cent', 'sterling', 'section', 'bullet',
  30400. 'paragraph', 'germandbls', 'registered', 'copyright', 'trademark', 'acute',
  30401. 'dieresis', 'notequal', 'AE', 'Oslash', 'infinity', 'plusminus', 'lessequal',
  30402. 'greaterequal', 'yen', 'mu', 'partialdiff', 'summation', 'product', 'pi',
  30403. 'integral', 'ordfeminine', 'ordmasculine', 'Omega', 'ae', 'oslash',
  30404. 'questiondown', 'exclamdown', 'logicalnot', 'radical', 'florin',
  30405. 'approxequal', 'Delta', 'guillemotleft', 'guillemotright', 'ellipsis',
  30406. 'nonbreakingspace', 'Agrave', 'Atilde', 'Otilde', 'OE', 'oe', 'endash',
  30407. 'emdash', 'quotedblleft', 'quotedblright', 'quoteleft', 'quoteright',
  30408. 'divide', 'lozenge', 'ydieresis', 'Ydieresis', 'fraction', 'currency',
  30409. 'guilsinglleft', 'guilsinglright', 'fi', 'fl', 'daggerdbl', 'periodcentered',
  30410. 'quotesinglbase', 'quotedblbase', 'perthousand', 'Acircumflex',
  30411. 'Ecircumflex', 'Aacute', 'Edieresis', 'Egrave', 'Iacute', 'Icircumflex',
  30412. 'Idieresis', 'Igrave', 'Oacute', 'Ocircumflex', 'apple', 'Ograve', 'Uacute',
  30413. 'Ucircumflex', 'Ugrave', 'dotlessi', 'circumflex', 'tilde', 'macron',
  30414. 'breve', 'dotaccent', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron',
  30415. 'Lslash', 'lslash', 'Scaron', 'scaron', 'Zcaron', 'zcaron', 'brokenbar',
  30416. 'Eth', 'eth', 'Yacute', 'yacute', 'Thorn', 'thorn', 'minus', 'multiply',
  30417. 'onesuperior', 'twosuperior', 'threesuperior', 'onehalf', 'onequarter',
  30418. 'threequarters', 'franc', 'Gbreve', 'gbreve', 'Idotaccent', 'Scedilla',
  30419. 'scedilla', 'Cacute', 'cacute', 'Ccaron', 'ccaron', 'dcroat'];
  30420. function getUnicodeRangeFor(value) {
  30421. for (var i = 0, ii = UnicodeRanges.length; i < ii; i++) {
  30422. var range = UnicodeRanges[i];
  30423. if (value >= range.begin && value < range.end) {
  30424. return i;
  30425. }
  30426. }
  30427. return -1;
  30428. }
  30429. function isRTLRangeFor(value) {
  30430. var range = UnicodeRanges[13];
  30431. if (value >= range.begin && value < range.end) {
  30432. return true;
  30433. }
  30434. range = UnicodeRanges[11];
  30435. if (value >= range.begin && value < range.end) {
  30436. return true;
  30437. }
  30438. return false;
  30439. }
  30440. // The normalization table is obtained by filtering the Unicode characters
  30441. // database with <compat> entries.
  30442. var NormalizedUnicodes = {
  30443. '\u00A8': '\u0020\u0308',
  30444. '\u00AF': '\u0020\u0304',
  30445. '\u00B4': '\u0020\u0301',
  30446. '\u00B5': '\u03BC',
  30447. '\u00B8': '\u0020\u0327',
  30448. '\u0132': '\u0049\u004A',
  30449. '\u0133': '\u0069\u006A',
  30450. '\u013F': '\u004C\u00B7',
  30451. '\u0140': '\u006C\u00B7',
  30452. '\u0149': '\u02BC\u006E',
  30453. '\u017F': '\u0073',
  30454. '\u01C4': '\u0044\u017D',
  30455. '\u01C5': '\u0044\u017E',
  30456. '\u01C6': '\u0064\u017E',
  30457. '\u01C7': '\u004C\u004A',
  30458. '\u01C8': '\u004C\u006A',
  30459. '\u01C9': '\u006C\u006A',
  30460. '\u01CA': '\u004E\u004A',
  30461. '\u01CB': '\u004E\u006A',
  30462. '\u01CC': '\u006E\u006A',
  30463. '\u01F1': '\u0044\u005A',
  30464. '\u01F2': '\u0044\u007A',
  30465. '\u01F3': '\u0064\u007A',
  30466. '\u02D8': '\u0020\u0306',
  30467. '\u02D9': '\u0020\u0307',
  30468. '\u02DA': '\u0020\u030A',
  30469. '\u02DB': '\u0020\u0328',
  30470. '\u02DC': '\u0020\u0303',
  30471. '\u02DD': '\u0020\u030B',
  30472. '\u037A': '\u0020\u0345',
  30473. '\u0384': '\u0020\u0301',
  30474. '\u03D0': '\u03B2',
  30475. '\u03D1': '\u03B8',
  30476. '\u03D2': '\u03A5',
  30477. '\u03D5': '\u03C6',
  30478. '\u03D6': '\u03C0',
  30479. '\u03F0': '\u03BA',
  30480. '\u03F1': '\u03C1',
  30481. '\u03F2': '\u03C2',
  30482. '\u03F4': '\u0398',
  30483. '\u03F5': '\u03B5',
  30484. '\u03F9': '\u03A3',
  30485. '\u0587': '\u0565\u0582',
  30486. '\u0675': '\u0627\u0674',
  30487. '\u0676': '\u0648\u0674',
  30488. '\u0677': '\u06C7\u0674',
  30489. '\u0678': '\u064A\u0674',
  30490. '\u0E33': '\u0E4D\u0E32',
  30491. '\u0EB3': '\u0ECD\u0EB2',
  30492. '\u0EDC': '\u0EAB\u0E99',
  30493. '\u0EDD': '\u0EAB\u0EA1',
  30494. '\u0F77': '\u0FB2\u0F81',
  30495. '\u0F79': '\u0FB3\u0F81',
  30496. '\u1E9A': '\u0061\u02BE',
  30497. '\u1FBD': '\u0020\u0313',
  30498. '\u1FBF': '\u0020\u0313',
  30499. '\u1FC0': '\u0020\u0342',
  30500. '\u1FFE': '\u0020\u0314',
  30501. '\u2002': '\u0020',
  30502. '\u2003': '\u0020',
  30503. '\u2004': '\u0020',
  30504. '\u2005': '\u0020',
  30505. '\u2006': '\u0020',
  30506. '\u2008': '\u0020',
  30507. '\u2009': '\u0020',
  30508. '\u200A': '\u0020',
  30509. '\u2017': '\u0020\u0333',
  30510. '\u2024': '\u002E',
  30511. '\u2025': '\u002E\u002E',
  30512. '\u2026': '\u002E\u002E\u002E',
  30513. '\u2033': '\u2032\u2032',
  30514. '\u2034': '\u2032\u2032\u2032',
  30515. '\u2036': '\u2035\u2035',
  30516. '\u2037': '\u2035\u2035\u2035',
  30517. '\u203C': '\u0021\u0021',
  30518. '\u203E': '\u0020\u0305',
  30519. '\u2047': '\u003F\u003F',
  30520. '\u2048': '\u003F\u0021',
  30521. '\u2049': '\u0021\u003F',
  30522. '\u2057': '\u2032\u2032\u2032\u2032',
  30523. '\u205F': '\u0020',
  30524. '\u20A8': '\u0052\u0073',
  30525. '\u2100': '\u0061\u002F\u0063',
  30526. '\u2101': '\u0061\u002F\u0073',
  30527. '\u2103': '\u00B0\u0043',
  30528. '\u2105': '\u0063\u002F\u006F',
  30529. '\u2106': '\u0063\u002F\u0075',
  30530. '\u2107': '\u0190',
  30531. '\u2109': '\u00B0\u0046',
  30532. '\u2116': '\u004E\u006F',
  30533. '\u2121': '\u0054\u0045\u004C',
  30534. '\u2135': '\u05D0',
  30535. '\u2136': '\u05D1',
  30536. '\u2137': '\u05D2',
  30537. '\u2138': '\u05D3',
  30538. '\u213B': '\u0046\u0041\u0058',
  30539. '\u2160': '\u0049',
  30540. '\u2161': '\u0049\u0049',
  30541. '\u2162': '\u0049\u0049\u0049',
  30542. '\u2163': '\u0049\u0056',
  30543. '\u2164': '\u0056',
  30544. '\u2165': '\u0056\u0049',
  30545. '\u2166': '\u0056\u0049\u0049',
  30546. '\u2167': '\u0056\u0049\u0049\u0049',
  30547. '\u2168': '\u0049\u0058',
  30548. '\u2169': '\u0058',
  30549. '\u216A': '\u0058\u0049',
  30550. '\u216B': '\u0058\u0049\u0049',
  30551. '\u216C': '\u004C',
  30552. '\u216D': '\u0043',
  30553. '\u216E': '\u0044',
  30554. '\u216F': '\u004D',
  30555. '\u2170': '\u0069',
  30556. '\u2171': '\u0069\u0069',
  30557. '\u2172': '\u0069\u0069\u0069',
  30558. '\u2173': '\u0069\u0076',
  30559. '\u2174': '\u0076',
  30560. '\u2175': '\u0076\u0069',
  30561. '\u2176': '\u0076\u0069\u0069',
  30562. '\u2177': '\u0076\u0069\u0069\u0069',
  30563. '\u2178': '\u0069\u0078',
  30564. '\u2179': '\u0078',
  30565. '\u217A': '\u0078\u0069',
  30566. '\u217B': '\u0078\u0069\u0069',
  30567. '\u217C': '\u006C',
  30568. '\u217D': '\u0063',
  30569. '\u217E': '\u0064',
  30570. '\u217F': '\u006D',
  30571. '\u222C': '\u222B\u222B',
  30572. '\u222D': '\u222B\u222B\u222B',
  30573. '\u222F': '\u222E\u222E',
  30574. '\u2230': '\u222E\u222E\u222E',
  30575. '\u2474': '\u0028\u0031\u0029',
  30576. '\u2475': '\u0028\u0032\u0029',
  30577. '\u2476': '\u0028\u0033\u0029',
  30578. '\u2477': '\u0028\u0034\u0029',
  30579. '\u2478': '\u0028\u0035\u0029',
  30580. '\u2479': '\u0028\u0036\u0029',
  30581. '\u247A': '\u0028\u0037\u0029',
  30582. '\u247B': '\u0028\u0038\u0029',
  30583. '\u247C': '\u0028\u0039\u0029',
  30584. '\u247D': '\u0028\u0031\u0030\u0029',
  30585. '\u247E': '\u0028\u0031\u0031\u0029',
  30586. '\u247F': '\u0028\u0031\u0032\u0029',
  30587. '\u2480': '\u0028\u0031\u0033\u0029',
  30588. '\u2481': '\u0028\u0031\u0034\u0029',
  30589. '\u2482': '\u0028\u0031\u0035\u0029',
  30590. '\u2483': '\u0028\u0031\u0036\u0029',
  30591. '\u2484': '\u0028\u0031\u0037\u0029',
  30592. '\u2485': '\u0028\u0031\u0038\u0029',
  30593. '\u2486': '\u0028\u0031\u0039\u0029',
  30594. '\u2487': '\u0028\u0032\u0030\u0029',
  30595. '\u2488': '\u0031\u002E',
  30596. '\u2489': '\u0032\u002E',
  30597. '\u248A': '\u0033\u002E',
  30598. '\u248B': '\u0034\u002E',
  30599. '\u248C': '\u0035\u002E',
  30600. '\u248D': '\u0036\u002E',
  30601. '\u248E': '\u0037\u002E',
  30602. '\u248F': '\u0038\u002E',
  30603. '\u2490': '\u0039\u002E',
  30604. '\u2491': '\u0031\u0030\u002E',
  30605. '\u2492': '\u0031\u0031\u002E',
  30606. '\u2493': '\u0031\u0032\u002E',
  30607. '\u2494': '\u0031\u0033\u002E',
  30608. '\u2495': '\u0031\u0034\u002E',
  30609. '\u2496': '\u0031\u0035\u002E',
  30610. '\u2497': '\u0031\u0036\u002E',
  30611. '\u2498': '\u0031\u0037\u002E',
  30612. '\u2499': '\u0031\u0038\u002E',
  30613. '\u249A': '\u0031\u0039\u002E',
  30614. '\u249B': '\u0032\u0030\u002E',
  30615. '\u249C': '\u0028\u0061\u0029',
  30616. '\u249D': '\u0028\u0062\u0029',
  30617. '\u249E': '\u0028\u0063\u0029',
  30618. '\u249F': '\u0028\u0064\u0029',
  30619. '\u24A0': '\u0028\u0065\u0029',
  30620. '\u24A1': '\u0028\u0066\u0029',
  30621. '\u24A2': '\u0028\u0067\u0029',
  30622. '\u24A3': '\u0028\u0068\u0029',
  30623. '\u24A4': '\u0028\u0069\u0029',
  30624. '\u24A5': '\u0028\u006A\u0029',
  30625. '\u24A6': '\u0028\u006B\u0029',
  30626. '\u24A7': '\u0028\u006C\u0029',
  30627. '\u24A8': '\u0028\u006D\u0029',
  30628. '\u24A9': '\u0028\u006E\u0029',
  30629. '\u24AA': '\u0028\u006F\u0029',
  30630. '\u24AB': '\u0028\u0070\u0029',
  30631. '\u24AC': '\u0028\u0071\u0029',
  30632. '\u24AD': '\u0028\u0072\u0029',
  30633. '\u24AE': '\u0028\u0073\u0029',
  30634. '\u24AF': '\u0028\u0074\u0029',
  30635. '\u24B0': '\u0028\u0075\u0029',
  30636. '\u24B1': '\u0028\u0076\u0029',
  30637. '\u24B2': '\u0028\u0077\u0029',
  30638. '\u24B3': '\u0028\u0078\u0029',
  30639. '\u24B4': '\u0028\u0079\u0029',
  30640. '\u24B5': '\u0028\u007A\u0029',
  30641. '\u2A0C': '\u222B\u222B\u222B\u222B',
  30642. '\u2A74': '\u003A\u003A\u003D',
  30643. '\u2A75': '\u003D\u003D',
  30644. '\u2A76': '\u003D\u003D\u003D',
  30645. '\u2E9F': '\u6BCD',
  30646. '\u2EF3': '\u9F9F',
  30647. '\u2F00': '\u4E00',
  30648. '\u2F01': '\u4E28',
  30649. '\u2F02': '\u4E36',
  30650. '\u2F03': '\u4E3F',
  30651. '\u2F04': '\u4E59',
  30652. '\u2F05': '\u4E85',
  30653. '\u2F06': '\u4E8C',
  30654. '\u2F07': '\u4EA0',
  30655. '\u2F08': '\u4EBA',
  30656. '\u2F09': '\u513F',
  30657. '\u2F0A': '\u5165',
  30658. '\u2F0B': '\u516B',
  30659. '\u2F0C': '\u5182',
  30660. '\u2F0D': '\u5196',
  30661. '\u2F0E': '\u51AB',
  30662. '\u2F0F': '\u51E0',
  30663. '\u2F10': '\u51F5',
  30664. '\u2F11': '\u5200',
  30665. '\u2F12': '\u529B',
  30666. '\u2F13': '\u52F9',
  30667. '\u2F14': '\u5315',
  30668. '\u2F15': '\u531A',
  30669. '\u2F16': '\u5338',
  30670. '\u2F17': '\u5341',
  30671. '\u2F18': '\u535C',
  30672. '\u2F19': '\u5369',
  30673. '\u2F1A': '\u5382',
  30674. '\u2F1B': '\u53B6',
  30675. '\u2F1C': '\u53C8',
  30676. '\u2F1D': '\u53E3',
  30677. '\u2F1E': '\u56D7',
  30678. '\u2F1F': '\u571F',
  30679. '\u2F20': '\u58EB',
  30680. '\u2F21': '\u5902',
  30681. '\u2F22': '\u590A',
  30682. '\u2F23': '\u5915',
  30683. '\u2F24': '\u5927',
  30684. '\u2F25': '\u5973',
  30685. '\u2F26': '\u5B50',
  30686. '\u2F27': '\u5B80',
  30687. '\u2F28': '\u5BF8',
  30688. '\u2F29': '\u5C0F',
  30689. '\u2F2A': '\u5C22',
  30690. '\u2F2B': '\u5C38',
  30691. '\u2F2C': '\u5C6E',
  30692. '\u2F2D': '\u5C71',
  30693. '\u2F2E': '\u5DDB',
  30694. '\u2F2F': '\u5DE5',
  30695. '\u2F30': '\u5DF1',
  30696. '\u2F31': '\u5DFE',
  30697. '\u2F32': '\u5E72',
  30698. '\u2F33': '\u5E7A',
  30699. '\u2F34': '\u5E7F',
  30700. '\u2F35': '\u5EF4',
  30701. '\u2F36': '\u5EFE',
  30702. '\u2F37': '\u5F0B',
  30703. '\u2F38': '\u5F13',
  30704. '\u2F39': '\u5F50',
  30705. '\u2F3A': '\u5F61',
  30706. '\u2F3B': '\u5F73',
  30707. '\u2F3C': '\u5FC3',
  30708. '\u2F3D': '\u6208',
  30709. '\u2F3E': '\u6236',
  30710. '\u2F3F': '\u624B',
  30711. '\u2F40': '\u652F',
  30712. '\u2F41': '\u6534',
  30713. '\u2F42': '\u6587',
  30714. '\u2F43': '\u6597',
  30715. '\u2F44': '\u65A4',
  30716. '\u2F45': '\u65B9',
  30717. '\u2F46': '\u65E0',
  30718. '\u2F47': '\u65E5',
  30719. '\u2F48': '\u66F0',
  30720. '\u2F49': '\u6708',
  30721. '\u2F4A': '\u6728',
  30722. '\u2F4B': '\u6B20',
  30723. '\u2F4C': '\u6B62',
  30724. '\u2F4D': '\u6B79',
  30725. '\u2F4E': '\u6BB3',
  30726. '\u2F4F': '\u6BCB',
  30727. '\u2F50': '\u6BD4',
  30728. '\u2F51': '\u6BDB',
  30729. '\u2F52': '\u6C0F',
  30730. '\u2F53': '\u6C14',
  30731. '\u2F54': '\u6C34',
  30732. '\u2F55': '\u706B',
  30733. '\u2F56': '\u722A',
  30734. '\u2F57': '\u7236',
  30735. '\u2F58': '\u723B',
  30736. '\u2F59': '\u723F',
  30737. '\u2F5A': '\u7247',
  30738. '\u2F5B': '\u7259',
  30739. '\u2F5C': '\u725B',
  30740. '\u2F5D': '\u72AC',
  30741. '\u2F5E': '\u7384',
  30742. '\u2F5F': '\u7389',
  30743. '\u2F60': '\u74DC',
  30744. '\u2F61': '\u74E6',
  30745. '\u2F62': '\u7518',
  30746. '\u2F63': '\u751F',
  30747. '\u2F64': '\u7528',
  30748. '\u2F65': '\u7530',
  30749. '\u2F66': '\u758B',
  30750. '\u2F67': '\u7592',
  30751. '\u2F68': '\u7676',
  30752. '\u2F69': '\u767D',
  30753. '\u2F6A': '\u76AE',
  30754. '\u2F6B': '\u76BF',
  30755. '\u2F6C': '\u76EE',
  30756. '\u2F6D': '\u77DB',
  30757. '\u2F6E': '\u77E2',
  30758. '\u2F6F': '\u77F3',
  30759. '\u2F70': '\u793A',
  30760. '\u2F71': '\u79B8',
  30761. '\u2F72': '\u79BE',
  30762. '\u2F73': '\u7A74',
  30763. '\u2F74': '\u7ACB',
  30764. '\u2F75': '\u7AF9',
  30765. '\u2F76': '\u7C73',
  30766. '\u2F77': '\u7CF8',
  30767. '\u2F78': '\u7F36',
  30768. '\u2F79': '\u7F51',
  30769. '\u2F7A': '\u7F8A',
  30770. '\u2F7B': '\u7FBD',
  30771. '\u2F7C': '\u8001',
  30772. '\u2F7D': '\u800C',
  30773. '\u2F7E': '\u8012',
  30774. '\u2F7F': '\u8033',
  30775. '\u2F80': '\u807F',
  30776. '\u2F81': '\u8089',
  30777. '\u2F82': '\u81E3',
  30778. '\u2F83': '\u81EA',
  30779. '\u2F84': '\u81F3',
  30780. '\u2F85': '\u81FC',
  30781. '\u2F86': '\u820C',
  30782. '\u2F87': '\u821B',
  30783. '\u2F88': '\u821F',
  30784. '\u2F89': '\u826E',
  30785. '\u2F8A': '\u8272',
  30786. '\u2F8B': '\u8278',
  30787. '\u2F8C': '\u864D',
  30788. '\u2F8D': '\u866B',
  30789. '\u2F8E': '\u8840',
  30790. '\u2F8F': '\u884C',
  30791. '\u2F90': '\u8863',
  30792. '\u2F91': '\u897E',
  30793. '\u2F92': '\u898B',
  30794. '\u2F93': '\u89D2',
  30795. '\u2F94': '\u8A00',
  30796. '\u2F95': '\u8C37',
  30797. '\u2F96': '\u8C46',
  30798. '\u2F97': '\u8C55',
  30799. '\u2F98': '\u8C78',
  30800. '\u2F99': '\u8C9D',
  30801. '\u2F9A': '\u8D64',
  30802. '\u2F9B': '\u8D70',
  30803. '\u2F9C': '\u8DB3',
  30804. '\u2F9D': '\u8EAB',
  30805. '\u2F9E': '\u8ECA',
  30806. '\u2F9F': '\u8F9B',
  30807. '\u2FA0': '\u8FB0',
  30808. '\u2FA1': '\u8FB5',
  30809. '\u2FA2': '\u9091',
  30810. '\u2FA3': '\u9149',
  30811. '\u2FA4': '\u91C6',
  30812. '\u2FA5': '\u91CC',
  30813. '\u2FA6': '\u91D1',
  30814. '\u2FA7': '\u9577',
  30815. '\u2FA8': '\u9580',
  30816. '\u2FA9': '\u961C',
  30817. '\u2FAA': '\u96B6',
  30818. '\u2FAB': '\u96B9',
  30819. '\u2FAC': '\u96E8',
  30820. '\u2FAD': '\u9751',
  30821. '\u2FAE': '\u975E',
  30822. '\u2FAF': '\u9762',
  30823. '\u2FB0': '\u9769',
  30824. '\u2FB1': '\u97CB',
  30825. '\u2FB2': '\u97ED',
  30826. '\u2FB3': '\u97F3',
  30827. '\u2FB4': '\u9801',
  30828. '\u2FB5': '\u98A8',
  30829. '\u2FB6': '\u98DB',
  30830. '\u2FB7': '\u98DF',
  30831. '\u2FB8': '\u9996',
  30832. '\u2FB9': '\u9999',
  30833. '\u2FBA': '\u99AC',
  30834. '\u2FBB': '\u9AA8',
  30835. '\u2FBC': '\u9AD8',
  30836. '\u2FBD': '\u9ADF',
  30837. '\u2FBE': '\u9B25',
  30838. '\u2FBF': '\u9B2F',
  30839. '\u2FC0': '\u9B32',
  30840. '\u2FC1': '\u9B3C',
  30841. '\u2FC2': '\u9B5A',
  30842. '\u2FC3': '\u9CE5',
  30843. '\u2FC4': '\u9E75',
  30844. '\u2FC5': '\u9E7F',
  30845. '\u2FC6': '\u9EA5',
  30846. '\u2FC7': '\u9EBB',
  30847. '\u2FC8': '\u9EC3',
  30848. '\u2FC9': '\u9ECD',
  30849. '\u2FCA': '\u9ED1',
  30850. '\u2FCB': '\u9EF9',
  30851. '\u2FCC': '\u9EFD',
  30852. '\u2FCD': '\u9F0E',
  30853. '\u2FCE': '\u9F13',
  30854. '\u2FCF': '\u9F20',
  30855. '\u2FD0': '\u9F3B',
  30856. '\u2FD1': '\u9F4A',
  30857. '\u2FD2': '\u9F52',
  30858. '\u2FD3': '\u9F8D',
  30859. '\u2FD4': '\u9F9C',
  30860. '\u2FD5': '\u9FA0',
  30861. '\u3036': '\u3012',
  30862. '\u3038': '\u5341',
  30863. '\u3039': '\u5344',
  30864. '\u303A': '\u5345',
  30865. '\u309B': '\u0020\u3099',
  30866. '\u309C': '\u0020\u309A',
  30867. '\u3131': '\u1100',
  30868. '\u3132': '\u1101',
  30869. '\u3133': '\u11AA',
  30870. '\u3134': '\u1102',
  30871. '\u3135': '\u11AC',
  30872. '\u3136': '\u11AD',
  30873. '\u3137': '\u1103',
  30874. '\u3138': '\u1104',
  30875. '\u3139': '\u1105',
  30876. '\u313A': '\u11B0',
  30877. '\u313B': '\u11B1',
  30878. '\u313C': '\u11B2',
  30879. '\u313D': '\u11B3',
  30880. '\u313E': '\u11B4',
  30881. '\u313F': '\u11B5',
  30882. '\u3140': '\u111A',
  30883. '\u3141': '\u1106',
  30884. '\u3142': '\u1107',
  30885. '\u3143': '\u1108',
  30886. '\u3144': '\u1121',
  30887. '\u3145': '\u1109',
  30888. '\u3146': '\u110A',
  30889. '\u3147': '\u110B',
  30890. '\u3148': '\u110C',
  30891. '\u3149': '\u110D',
  30892. '\u314A': '\u110E',
  30893. '\u314B': '\u110F',
  30894. '\u314C': '\u1110',
  30895. '\u314D': '\u1111',
  30896. '\u314E': '\u1112',
  30897. '\u314F': '\u1161',
  30898. '\u3150': '\u1162',
  30899. '\u3151': '\u1163',
  30900. '\u3152': '\u1164',
  30901. '\u3153': '\u1165',
  30902. '\u3154': '\u1166',
  30903. '\u3155': '\u1167',
  30904. '\u3156': '\u1168',
  30905. '\u3157': '\u1169',
  30906. '\u3158': '\u116A',
  30907. '\u3159': '\u116B',
  30908. '\u315A': '\u116C',
  30909. '\u315B': '\u116D',
  30910. '\u315C': '\u116E',
  30911. '\u315D': '\u116F',
  30912. '\u315E': '\u1170',
  30913. '\u315F': '\u1171',
  30914. '\u3160': '\u1172',
  30915. '\u3161': '\u1173',
  30916. '\u3162': '\u1174',
  30917. '\u3163': '\u1175',
  30918. '\u3164': '\u1160',
  30919. '\u3165': '\u1114',
  30920. '\u3166': '\u1115',
  30921. '\u3167': '\u11C7',
  30922. '\u3168': '\u11C8',
  30923. '\u3169': '\u11CC',
  30924. '\u316A': '\u11CE',
  30925. '\u316B': '\u11D3',
  30926. '\u316C': '\u11D7',
  30927. '\u316D': '\u11D9',
  30928. '\u316E': '\u111C',
  30929. '\u316F': '\u11DD',
  30930. '\u3170': '\u11DF',
  30931. '\u3171': '\u111D',
  30932. '\u3172': '\u111E',
  30933. '\u3173': '\u1120',
  30934. '\u3174': '\u1122',
  30935. '\u3175': '\u1123',
  30936. '\u3176': '\u1127',
  30937. '\u3177': '\u1129',
  30938. '\u3178': '\u112B',
  30939. '\u3179': '\u112C',
  30940. '\u317A': '\u112D',
  30941. '\u317B': '\u112E',
  30942. '\u317C': '\u112F',
  30943. '\u317D': '\u1132',
  30944. '\u317E': '\u1136',
  30945. '\u317F': '\u1140',
  30946. '\u3180': '\u1147',
  30947. '\u3181': '\u114C',
  30948. '\u3182': '\u11F1',
  30949. '\u3183': '\u11F2',
  30950. '\u3184': '\u1157',
  30951. '\u3185': '\u1158',
  30952. '\u3186': '\u1159',
  30953. '\u3187': '\u1184',
  30954. '\u3188': '\u1185',
  30955. '\u3189': '\u1188',
  30956. '\u318A': '\u1191',
  30957. '\u318B': '\u1192',
  30958. '\u318C': '\u1194',
  30959. '\u318D': '\u119E',
  30960. '\u318E': '\u11A1',
  30961. '\u3200': '\u0028\u1100\u0029',
  30962. '\u3201': '\u0028\u1102\u0029',
  30963. '\u3202': '\u0028\u1103\u0029',
  30964. '\u3203': '\u0028\u1105\u0029',
  30965. '\u3204': '\u0028\u1106\u0029',
  30966. '\u3205': '\u0028\u1107\u0029',
  30967. '\u3206': '\u0028\u1109\u0029',
  30968. '\u3207': '\u0028\u110B\u0029',
  30969. '\u3208': '\u0028\u110C\u0029',
  30970. '\u3209': '\u0028\u110E\u0029',
  30971. '\u320A': '\u0028\u110F\u0029',
  30972. '\u320B': '\u0028\u1110\u0029',
  30973. '\u320C': '\u0028\u1111\u0029',
  30974. '\u320D': '\u0028\u1112\u0029',
  30975. '\u320E': '\u0028\u1100\u1161\u0029',
  30976. '\u320F': '\u0028\u1102\u1161\u0029',
  30977. '\u3210': '\u0028\u1103\u1161\u0029',
  30978. '\u3211': '\u0028\u1105\u1161\u0029',
  30979. '\u3212': '\u0028\u1106\u1161\u0029',
  30980. '\u3213': '\u0028\u1107\u1161\u0029',
  30981. '\u3214': '\u0028\u1109\u1161\u0029',
  30982. '\u3215': '\u0028\u110B\u1161\u0029',
  30983. '\u3216': '\u0028\u110C\u1161\u0029',
  30984. '\u3217': '\u0028\u110E\u1161\u0029',
  30985. '\u3218': '\u0028\u110F\u1161\u0029',
  30986. '\u3219': '\u0028\u1110\u1161\u0029',
  30987. '\u321A': '\u0028\u1111\u1161\u0029',
  30988. '\u321B': '\u0028\u1112\u1161\u0029',
  30989. '\u321C': '\u0028\u110C\u116E\u0029',
  30990. '\u321D': '\u0028\u110B\u1169\u110C\u1165\u11AB\u0029',
  30991. '\u321E': '\u0028\u110B\u1169\u1112\u116E\u0029',
  30992. '\u3220': '\u0028\u4E00\u0029',
  30993. '\u3221': '\u0028\u4E8C\u0029',
  30994. '\u3222': '\u0028\u4E09\u0029',
  30995. '\u3223': '\u0028\u56DB\u0029',
  30996. '\u3224': '\u0028\u4E94\u0029',
  30997. '\u3225': '\u0028\u516D\u0029',
  30998. '\u3226': '\u0028\u4E03\u0029',
  30999. '\u3227': '\u0028\u516B\u0029',
  31000. '\u3228': '\u0028\u4E5D\u0029',
  31001. '\u3229': '\u0028\u5341\u0029',
  31002. '\u322A': '\u0028\u6708\u0029',
  31003. '\u322B': '\u0028\u706B\u0029',
  31004. '\u322C': '\u0028\u6C34\u0029',
  31005. '\u322D': '\u0028\u6728\u0029',
  31006. '\u322E': '\u0028\u91D1\u0029',
  31007. '\u322F': '\u0028\u571F\u0029',
  31008. '\u3230': '\u0028\u65E5\u0029',
  31009. '\u3231': '\u0028\u682A\u0029',
  31010. '\u3232': '\u0028\u6709\u0029',
  31011. '\u3233': '\u0028\u793E\u0029',
  31012. '\u3234': '\u0028\u540D\u0029',
  31013. '\u3235': '\u0028\u7279\u0029',
  31014. '\u3236': '\u0028\u8CA1\u0029',
  31015. '\u3237': '\u0028\u795D\u0029',
  31016. '\u3238': '\u0028\u52B4\u0029',
  31017. '\u3239': '\u0028\u4EE3\u0029',
  31018. '\u323A': '\u0028\u547C\u0029',
  31019. '\u323B': '\u0028\u5B66\u0029',
  31020. '\u323C': '\u0028\u76E3\u0029',
  31021. '\u323D': '\u0028\u4F01\u0029',
  31022. '\u323E': '\u0028\u8CC7\u0029',
  31023. '\u323F': '\u0028\u5354\u0029',
  31024. '\u3240': '\u0028\u796D\u0029',
  31025. '\u3241': '\u0028\u4F11\u0029',
  31026. '\u3242': '\u0028\u81EA\u0029',
  31027. '\u3243': '\u0028\u81F3\u0029',
  31028. '\u32C0': '\u0031\u6708',
  31029. '\u32C1': '\u0032\u6708',
  31030. '\u32C2': '\u0033\u6708',
  31031. '\u32C3': '\u0034\u6708',
  31032. '\u32C4': '\u0035\u6708',
  31033. '\u32C5': '\u0036\u6708',
  31034. '\u32C6': '\u0037\u6708',
  31035. '\u32C7': '\u0038\u6708',
  31036. '\u32C8': '\u0039\u6708',
  31037. '\u32C9': '\u0031\u0030\u6708',
  31038. '\u32CA': '\u0031\u0031\u6708',
  31039. '\u32CB': '\u0031\u0032\u6708',
  31040. '\u3358': '\u0030\u70B9',
  31041. '\u3359': '\u0031\u70B9',
  31042. '\u335A': '\u0032\u70B9',
  31043. '\u335B': '\u0033\u70B9',
  31044. '\u335C': '\u0034\u70B9',
  31045. '\u335D': '\u0035\u70B9',
  31046. '\u335E': '\u0036\u70B9',
  31047. '\u335F': '\u0037\u70B9',
  31048. '\u3360': '\u0038\u70B9',
  31049. '\u3361': '\u0039\u70B9',
  31050. '\u3362': '\u0031\u0030\u70B9',
  31051. '\u3363': '\u0031\u0031\u70B9',
  31052. '\u3364': '\u0031\u0032\u70B9',
  31053. '\u3365': '\u0031\u0033\u70B9',
  31054. '\u3366': '\u0031\u0034\u70B9',
  31055. '\u3367': '\u0031\u0035\u70B9',
  31056. '\u3368': '\u0031\u0036\u70B9',
  31057. '\u3369': '\u0031\u0037\u70B9',
  31058. '\u336A': '\u0031\u0038\u70B9',
  31059. '\u336B': '\u0031\u0039\u70B9',
  31060. '\u336C': '\u0032\u0030\u70B9',
  31061. '\u336D': '\u0032\u0031\u70B9',
  31062. '\u336E': '\u0032\u0032\u70B9',
  31063. '\u336F': '\u0032\u0033\u70B9',
  31064. '\u3370': '\u0032\u0034\u70B9',
  31065. '\u33E0': '\u0031\u65E5',
  31066. '\u33E1': '\u0032\u65E5',
  31067. '\u33E2': '\u0033\u65E5',
  31068. '\u33E3': '\u0034\u65E5',
  31069. '\u33E4': '\u0035\u65E5',
  31070. '\u33E5': '\u0036\u65E5',
  31071. '\u33E6': '\u0037\u65E5',
  31072. '\u33E7': '\u0038\u65E5',
  31073. '\u33E8': '\u0039\u65E5',
  31074. '\u33E9': '\u0031\u0030\u65E5',
  31075. '\u33EA': '\u0031\u0031\u65E5',
  31076. '\u33EB': '\u0031\u0032\u65E5',
  31077. '\u33EC': '\u0031\u0033\u65E5',
  31078. '\u33ED': '\u0031\u0034\u65E5',
  31079. '\u33EE': '\u0031\u0035\u65E5',
  31080. '\u33EF': '\u0031\u0036\u65E5',
  31081. '\u33F0': '\u0031\u0037\u65E5',
  31082. '\u33F1': '\u0031\u0038\u65E5',
  31083. '\u33F2': '\u0031\u0039\u65E5',
  31084. '\u33F3': '\u0032\u0030\u65E5',
  31085. '\u33F4': '\u0032\u0031\u65E5',
  31086. '\u33F5': '\u0032\u0032\u65E5',
  31087. '\u33F6': '\u0032\u0033\u65E5',
  31088. '\u33F7': '\u0032\u0034\u65E5',
  31089. '\u33F8': '\u0032\u0035\u65E5',
  31090. '\u33F9': '\u0032\u0036\u65E5',
  31091. '\u33FA': '\u0032\u0037\u65E5',
  31092. '\u33FB': '\u0032\u0038\u65E5',
  31093. '\u33FC': '\u0032\u0039\u65E5',
  31094. '\u33FD': '\u0033\u0030\u65E5',
  31095. '\u33FE': '\u0033\u0031\u65E5',
  31096. '\uFB00': '\u0066\u0066',
  31097. '\uFB01': '\u0066\u0069',
  31098. '\uFB02': '\u0066\u006C',
  31099. '\uFB03': '\u0066\u0066\u0069',
  31100. '\uFB04': '\u0066\u0066\u006C',
  31101. '\uFB05': '\u017F\u0074',
  31102. '\uFB06': '\u0073\u0074',
  31103. '\uFB13': '\u0574\u0576',
  31104. '\uFB14': '\u0574\u0565',
  31105. '\uFB15': '\u0574\u056B',
  31106. '\uFB16': '\u057E\u0576',
  31107. '\uFB17': '\u0574\u056D',
  31108. '\uFB4F': '\u05D0\u05DC',
  31109. '\uFB50': '\u0671',
  31110. '\uFB51': '\u0671',
  31111. '\uFB52': '\u067B',
  31112. '\uFB53': '\u067B',
  31113. '\uFB54': '\u067B',
  31114. '\uFB55': '\u067B',
  31115. '\uFB56': '\u067E',
  31116. '\uFB57': '\u067E',
  31117. '\uFB58': '\u067E',
  31118. '\uFB59': '\u067E',
  31119. '\uFB5A': '\u0680',
  31120. '\uFB5B': '\u0680',
  31121. '\uFB5C': '\u0680',
  31122. '\uFB5D': '\u0680',
  31123. '\uFB5E': '\u067A',
  31124. '\uFB5F': '\u067A',
  31125. '\uFB60': '\u067A',
  31126. '\uFB61': '\u067A',
  31127. '\uFB62': '\u067F',
  31128. '\uFB63': '\u067F',
  31129. '\uFB64': '\u067F',
  31130. '\uFB65': '\u067F',
  31131. '\uFB66': '\u0679',
  31132. '\uFB67': '\u0679',
  31133. '\uFB68': '\u0679',
  31134. '\uFB69': '\u0679',
  31135. '\uFB6A': '\u06A4',
  31136. '\uFB6B': '\u06A4',
  31137. '\uFB6C': '\u06A4',
  31138. '\uFB6D': '\u06A4',
  31139. '\uFB6E': '\u06A6',
  31140. '\uFB6F': '\u06A6',
  31141. '\uFB70': '\u06A6',
  31142. '\uFB71': '\u06A6',
  31143. '\uFB72': '\u0684',
  31144. '\uFB73': '\u0684',
  31145. '\uFB74': '\u0684',
  31146. '\uFB75': '\u0684',
  31147. '\uFB76': '\u0683',
  31148. '\uFB77': '\u0683',
  31149. '\uFB78': '\u0683',
  31150. '\uFB79': '\u0683',
  31151. '\uFB7A': '\u0686',
  31152. '\uFB7B': '\u0686',
  31153. '\uFB7C': '\u0686',
  31154. '\uFB7D': '\u0686',
  31155. '\uFB7E': '\u0687',
  31156. '\uFB7F': '\u0687',
  31157. '\uFB80': '\u0687',
  31158. '\uFB81': '\u0687',
  31159. '\uFB82': '\u068D',
  31160. '\uFB83': '\u068D',
  31161. '\uFB84': '\u068C',
  31162. '\uFB85': '\u068C',
  31163. '\uFB86': '\u068E',
  31164. '\uFB87': '\u068E',
  31165. '\uFB88': '\u0688',
  31166. '\uFB89': '\u0688',
  31167. '\uFB8A': '\u0698',
  31168. '\uFB8B': '\u0698',
  31169. '\uFB8C': '\u0691',
  31170. '\uFB8D': '\u0691',
  31171. '\uFB8E': '\u06A9',
  31172. '\uFB8F': '\u06A9',
  31173. '\uFB90': '\u06A9',
  31174. '\uFB91': '\u06A9',
  31175. '\uFB92': '\u06AF',
  31176. '\uFB93': '\u06AF',
  31177. '\uFB94': '\u06AF',
  31178. '\uFB95': '\u06AF',
  31179. '\uFB96': '\u06B3',
  31180. '\uFB97': '\u06B3',
  31181. '\uFB98': '\u06B3',
  31182. '\uFB99': '\u06B3',
  31183. '\uFB9A': '\u06B1',
  31184. '\uFB9B': '\u06B1',
  31185. '\uFB9C': '\u06B1',
  31186. '\uFB9D': '\u06B1',
  31187. '\uFB9E': '\u06BA',
  31188. '\uFB9F': '\u06BA',
  31189. '\uFBA0': '\u06BB',
  31190. '\uFBA1': '\u06BB',
  31191. '\uFBA2': '\u06BB',
  31192. '\uFBA3': '\u06BB',
  31193. '\uFBA4': '\u06C0',
  31194. '\uFBA5': '\u06C0',
  31195. '\uFBA6': '\u06C1',
  31196. '\uFBA7': '\u06C1',
  31197. '\uFBA8': '\u06C1',
  31198. '\uFBA9': '\u06C1',
  31199. '\uFBAA': '\u06BE',
  31200. '\uFBAB': '\u06BE',
  31201. '\uFBAC': '\u06BE',
  31202. '\uFBAD': '\u06BE',
  31203. '\uFBAE': '\u06D2',
  31204. '\uFBAF': '\u06D2',
  31205. '\uFBB0': '\u06D3',
  31206. '\uFBB1': '\u06D3',
  31207. '\uFBD3': '\u06AD',
  31208. '\uFBD4': '\u06AD',
  31209. '\uFBD5': '\u06AD',
  31210. '\uFBD6': '\u06AD',
  31211. '\uFBD7': '\u06C7',
  31212. '\uFBD8': '\u06C7',
  31213. '\uFBD9': '\u06C6',
  31214. '\uFBDA': '\u06C6',
  31215. '\uFBDB': '\u06C8',
  31216. '\uFBDC': '\u06C8',
  31217. '\uFBDD': '\u0677',
  31218. '\uFBDE': '\u06CB',
  31219. '\uFBDF': '\u06CB',
  31220. '\uFBE0': '\u06C5',
  31221. '\uFBE1': '\u06C5',
  31222. '\uFBE2': '\u06C9',
  31223. '\uFBE3': '\u06C9',
  31224. '\uFBE4': '\u06D0',
  31225. '\uFBE5': '\u06D0',
  31226. '\uFBE6': '\u06D0',
  31227. '\uFBE7': '\u06D0',
  31228. '\uFBE8': '\u0649',
  31229. '\uFBE9': '\u0649',
  31230. '\uFBEA': '\u0626\u0627',
  31231. '\uFBEB': '\u0626\u0627',
  31232. '\uFBEC': '\u0626\u06D5',
  31233. '\uFBED': '\u0626\u06D5',
  31234. '\uFBEE': '\u0626\u0648',
  31235. '\uFBEF': '\u0626\u0648',
  31236. '\uFBF0': '\u0626\u06C7',
  31237. '\uFBF1': '\u0626\u06C7',
  31238. '\uFBF2': '\u0626\u06C6',
  31239. '\uFBF3': '\u0626\u06C6',
  31240. '\uFBF4': '\u0626\u06C8',
  31241. '\uFBF5': '\u0626\u06C8',
  31242. '\uFBF6': '\u0626\u06D0',
  31243. '\uFBF7': '\u0626\u06D0',
  31244. '\uFBF8': '\u0626\u06D0',
  31245. '\uFBF9': '\u0626\u0649',
  31246. '\uFBFA': '\u0626\u0649',
  31247. '\uFBFB': '\u0626\u0649',
  31248. '\uFBFC': '\u06CC',
  31249. '\uFBFD': '\u06CC',
  31250. '\uFBFE': '\u06CC',
  31251. '\uFBFF': '\u06CC',
  31252. '\uFC00': '\u0626\u062C',
  31253. '\uFC01': '\u0626\u062D',
  31254. '\uFC02': '\u0626\u0645',
  31255. '\uFC03': '\u0626\u0649',
  31256. '\uFC04': '\u0626\u064A',
  31257. '\uFC05': '\u0628\u062C',
  31258. '\uFC06': '\u0628\u062D',
  31259. '\uFC07': '\u0628\u062E',
  31260. '\uFC08': '\u0628\u0645',
  31261. '\uFC09': '\u0628\u0649',
  31262. '\uFC0A': '\u0628\u064A',
  31263. '\uFC0B': '\u062A\u062C',
  31264. '\uFC0C': '\u062A\u062D',
  31265. '\uFC0D': '\u062A\u062E',
  31266. '\uFC0E': '\u062A\u0645',
  31267. '\uFC0F': '\u062A\u0649',
  31268. '\uFC10': '\u062A\u064A',
  31269. '\uFC11': '\u062B\u062C',
  31270. '\uFC12': '\u062B\u0645',
  31271. '\uFC13': '\u062B\u0649',
  31272. '\uFC14': '\u062B\u064A',
  31273. '\uFC15': '\u062C\u062D',
  31274. '\uFC16': '\u062C\u0645',
  31275. '\uFC17': '\u062D\u062C',
  31276. '\uFC18': '\u062D\u0645',
  31277. '\uFC19': '\u062E\u062C',
  31278. '\uFC1A': '\u062E\u062D',
  31279. '\uFC1B': '\u062E\u0645',
  31280. '\uFC1C': '\u0633\u062C',
  31281. '\uFC1D': '\u0633\u062D',
  31282. '\uFC1E': '\u0633\u062E',
  31283. '\uFC1F': '\u0633\u0645',
  31284. '\uFC20': '\u0635\u062D',
  31285. '\uFC21': '\u0635\u0645',
  31286. '\uFC22': '\u0636\u062C',
  31287. '\uFC23': '\u0636\u062D',
  31288. '\uFC24': '\u0636\u062E',
  31289. '\uFC25': '\u0636\u0645',
  31290. '\uFC26': '\u0637\u062D',
  31291. '\uFC27': '\u0637\u0645',
  31292. '\uFC28': '\u0638\u0645',
  31293. '\uFC29': '\u0639\u062C',
  31294. '\uFC2A': '\u0639\u0645',
  31295. '\uFC2B': '\u063A\u062C',
  31296. '\uFC2C': '\u063A\u0645',
  31297. '\uFC2D': '\u0641\u062C',
  31298. '\uFC2E': '\u0641\u062D',
  31299. '\uFC2F': '\u0641\u062E',
  31300. '\uFC30': '\u0641\u0645',
  31301. '\uFC31': '\u0641\u0649',
  31302. '\uFC32': '\u0641\u064A',
  31303. '\uFC33': '\u0642\u062D',
  31304. '\uFC34': '\u0642\u0645',
  31305. '\uFC35': '\u0642\u0649',
  31306. '\uFC36': '\u0642\u064A',
  31307. '\uFC37': '\u0643\u0627',
  31308. '\uFC38': '\u0643\u062C',
  31309. '\uFC39': '\u0643\u062D',
  31310. '\uFC3A': '\u0643\u062E',
  31311. '\uFC3B': '\u0643\u0644',
  31312. '\uFC3C': '\u0643\u0645',
  31313. '\uFC3D': '\u0643\u0649',
  31314. '\uFC3E': '\u0643\u064A',
  31315. '\uFC3F': '\u0644\u062C',
  31316. '\uFC40': '\u0644\u062D',
  31317. '\uFC41': '\u0644\u062E',
  31318. '\uFC42': '\u0644\u0645',
  31319. '\uFC43': '\u0644\u0649',
  31320. '\uFC44': '\u0644\u064A',
  31321. '\uFC45': '\u0645\u062C',
  31322. '\uFC46': '\u0645\u062D',
  31323. '\uFC47': '\u0645\u062E',
  31324. '\uFC48': '\u0645\u0645',
  31325. '\uFC49': '\u0645\u0649',
  31326. '\uFC4A': '\u0645\u064A',
  31327. '\uFC4B': '\u0646\u062C',
  31328. '\uFC4C': '\u0646\u062D',
  31329. '\uFC4D': '\u0646\u062E',
  31330. '\uFC4E': '\u0646\u0645',
  31331. '\uFC4F': '\u0646\u0649',
  31332. '\uFC50': '\u0646\u064A',
  31333. '\uFC51': '\u0647\u062C',
  31334. '\uFC52': '\u0647\u0645',
  31335. '\uFC53': '\u0647\u0649',
  31336. '\uFC54': '\u0647\u064A',
  31337. '\uFC55': '\u064A\u062C',
  31338. '\uFC56': '\u064A\u062D',
  31339. '\uFC57': '\u064A\u062E',
  31340. '\uFC58': '\u064A\u0645',
  31341. '\uFC59': '\u064A\u0649',
  31342. '\uFC5A': '\u064A\u064A',
  31343. '\uFC5B': '\u0630\u0670',
  31344. '\uFC5C': '\u0631\u0670',
  31345. '\uFC5D': '\u0649\u0670',
  31346. '\uFC5E': '\u0020\u064C\u0651',
  31347. '\uFC5F': '\u0020\u064D\u0651',
  31348. '\uFC60': '\u0020\u064E\u0651',
  31349. '\uFC61': '\u0020\u064F\u0651',
  31350. '\uFC62': '\u0020\u0650\u0651',
  31351. '\uFC63': '\u0020\u0651\u0670',
  31352. '\uFC64': '\u0626\u0631',
  31353. '\uFC65': '\u0626\u0632',
  31354. '\uFC66': '\u0626\u0645',
  31355. '\uFC67': '\u0626\u0646',
  31356. '\uFC68': '\u0626\u0649',
  31357. '\uFC69': '\u0626\u064A',
  31358. '\uFC6A': '\u0628\u0631',
  31359. '\uFC6B': '\u0628\u0632',
  31360. '\uFC6C': '\u0628\u0645',
  31361. '\uFC6D': '\u0628\u0646',
  31362. '\uFC6E': '\u0628\u0649',
  31363. '\uFC6F': '\u0628\u064A',
  31364. '\uFC70': '\u062A\u0631',
  31365. '\uFC71': '\u062A\u0632',
  31366. '\uFC72': '\u062A\u0645',
  31367. '\uFC73': '\u062A\u0646',
  31368. '\uFC74': '\u062A\u0649',
  31369. '\uFC75': '\u062A\u064A',
  31370. '\uFC76': '\u062B\u0631',
  31371. '\uFC77': '\u062B\u0632',
  31372. '\uFC78': '\u062B\u0645',
  31373. '\uFC79': '\u062B\u0646',
  31374. '\uFC7A': '\u062B\u0649',
  31375. '\uFC7B': '\u062B\u064A',
  31376. '\uFC7C': '\u0641\u0649',
  31377. '\uFC7D': '\u0641\u064A',
  31378. '\uFC7E': '\u0642\u0649',
  31379. '\uFC7F': '\u0642\u064A',
  31380. '\uFC80': '\u0643\u0627',
  31381. '\uFC81': '\u0643\u0644',
  31382. '\uFC82': '\u0643\u0645',
  31383. '\uFC83': '\u0643\u0649',
  31384. '\uFC84': '\u0643\u064A',
  31385. '\uFC85': '\u0644\u0645',
  31386. '\uFC86': '\u0644\u0649',
  31387. '\uFC87': '\u0644\u064A',
  31388. '\uFC88': '\u0645\u0627',
  31389. '\uFC89': '\u0645\u0645',
  31390. '\uFC8A': '\u0646\u0631',
  31391. '\uFC8B': '\u0646\u0632',
  31392. '\uFC8C': '\u0646\u0645',
  31393. '\uFC8D': '\u0646\u0646',
  31394. '\uFC8E': '\u0646\u0649',
  31395. '\uFC8F': '\u0646\u064A',
  31396. '\uFC90': '\u0649\u0670',
  31397. '\uFC91': '\u064A\u0631',
  31398. '\uFC92': '\u064A\u0632',
  31399. '\uFC93': '\u064A\u0645',
  31400. '\uFC94': '\u064A\u0646',
  31401. '\uFC95': '\u064A\u0649',
  31402. '\uFC96': '\u064A\u064A',
  31403. '\uFC97': '\u0626\u062C',
  31404. '\uFC98': '\u0626\u062D',
  31405. '\uFC99': '\u0626\u062E',
  31406. '\uFC9A': '\u0626\u0645',
  31407. '\uFC9B': '\u0626\u0647',
  31408. '\uFC9C': '\u0628\u062C',
  31409. '\uFC9D': '\u0628\u062D',
  31410. '\uFC9E': '\u0628\u062E',
  31411. '\uFC9F': '\u0628\u0645',
  31412. '\uFCA0': '\u0628\u0647',
  31413. '\uFCA1': '\u062A\u062C',
  31414. '\uFCA2': '\u062A\u062D',
  31415. '\uFCA3': '\u062A\u062E',
  31416. '\uFCA4': '\u062A\u0645',
  31417. '\uFCA5': '\u062A\u0647',
  31418. '\uFCA6': '\u062B\u0645',
  31419. '\uFCA7': '\u062C\u062D',
  31420. '\uFCA8': '\u062C\u0645',
  31421. '\uFCA9': '\u062D\u062C',
  31422. '\uFCAA': '\u062D\u0645',
  31423. '\uFCAB': '\u062E\u062C',
  31424. '\uFCAC': '\u062E\u0645',
  31425. '\uFCAD': '\u0633\u062C',
  31426. '\uFCAE': '\u0633\u062D',
  31427. '\uFCAF': '\u0633\u062E',
  31428. '\uFCB0': '\u0633\u0645',
  31429. '\uFCB1': '\u0635\u062D',
  31430. '\uFCB2': '\u0635\u062E',
  31431. '\uFCB3': '\u0635\u0645',
  31432. '\uFCB4': '\u0636\u062C',
  31433. '\uFCB5': '\u0636\u062D',
  31434. '\uFCB6': '\u0636\u062E',
  31435. '\uFCB7': '\u0636\u0645',
  31436. '\uFCB8': '\u0637\u062D',
  31437. '\uFCB9': '\u0638\u0645',
  31438. '\uFCBA': '\u0639\u062C',
  31439. '\uFCBB': '\u0639\u0645',
  31440. '\uFCBC': '\u063A\u062C',
  31441. '\uFCBD': '\u063A\u0645',
  31442. '\uFCBE': '\u0641\u062C',
  31443. '\uFCBF': '\u0641\u062D',
  31444. '\uFCC0': '\u0641\u062E',
  31445. '\uFCC1': '\u0641\u0645',
  31446. '\uFCC2': '\u0642\u062D',
  31447. '\uFCC3': '\u0642\u0645',
  31448. '\uFCC4': '\u0643\u062C',
  31449. '\uFCC5': '\u0643\u062D',
  31450. '\uFCC6': '\u0643\u062E',
  31451. '\uFCC7': '\u0643\u0644',
  31452. '\uFCC8': '\u0643\u0645',
  31453. '\uFCC9': '\u0644\u062C',
  31454. '\uFCCA': '\u0644\u062D',
  31455. '\uFCCB': '\u0644\u062E',
  31456. '\uFCCC': '\u0644\u0645',
  31457. '\uFCCD': '\u0644\u0647',
  31458. '\uFCCE': '\u0645\u062C',
  31459. '\uFCCF': '\u0645\u062D',
  31460. '\uFCD0': '\u0645\u062E',
  31461. '\uFCD1': '\u0645\u0645',
  31462. '\uFCD2': '\u0646\u062C',
  31463. '\uFCD3': '\u0646\u062D',
  31464. '\uFCD4': '\u0646\u062E',
  31465. '\uFCD5': '\u0646\u0645',
  31466. '\uFCD6': '\u0646\u0647',
  31467. '\uFCD7': '\u0647\u062C',
  31468. '\uFCD8': '\u0647\u0645',
  31469. '\uFCD9': '\u0647\u0670',
  31470. '\uFCDA': '\u064A\u062C',
  31471. '\uFCDB': '\u064A\u062D',
  31472. '\uFCDC': '\u064A\u062E',
  31473. '\uFCDD': '\u064A\u0645',
  31474. '\uFCDE': '\u064A\u0647',
  31475. '\uFCDF': '\u0626\u0645',
  31476. '\uFCE0': '\u0626\u0647',
  31477. '\uFCE1': '\u0628\u0645',
  31478. '\uFCE2': '\u0628\u0647',
  31479. '\uFCE3': '\u062A\u0645',
  31480. '\uFCE4': '\u062A\u0647',
  31481. '\uFCE5': '\u062B\u0645',
  31482. '\uFCE6': '\u062B\u0647',
  31483. '\uFCE7': '\u0633\u0645',
  31484. '\uFCE8': '\u0633\u0647',
  31485. '\uFCE9': '\u0634\u0645',
  31486. '\uFCEA': '\u0634\u0647',
  31487. '\uFCEB': '\u0643\u0644',
  31488. '\uFCEC': '\u0643\u0645',
  31489. '\uFCED': '\u0644\u0645',
  31490. '\uFCEE': '\u0646\u0645',
  31491. '\uFCEF': '\u0646\u0647',
  31492. '\uFCF0': '\u064A\u0645',
  31493. '\uFCF1': '\u064A\u0647',
  31494. '\uFCF2': '\u0640\u064E\u0651',
  31495. '\uFCF3': '\u0640\u064F\u0651',
  31496. '\uFCF4': '\u0640\u0650\u0651',
  31497. '\uFCF5': '\u0637\u0649',
  31498. '\uFCF6': '\u0637\u064A',
  31499. '\uFCF7': '\u0639\u0649',
  31500. '\uFCF8': '\u0639\u064A',
  31501. '\uFCF9': '\u063A\u0649',
  31502. '\uFCFA': '\u063A\u064A',
  31503. '\uFCFB': '\u0633\u0649',
  31504. '\uFCFC': '\u0633\u064A',
  31505. '\uFCFD': '\u0634\u0649',
  31506. '\uFCFE': '\u0634\u064A',
  31507. '\uFCFF': '\u062D\u0649',
  31508. '\uFD00': '\u062D\u064A',
  31509. '\uFD01': '\u062C\u0649',
  31510. '\uFD02': '\u062C\u064A',
  31511. '\uFD03': '\u062E\u0649',
  31512. '\uFD04': '\u062E\u064A',
  31513. '\uFD05': '\u0635\u0649',
  31514. '\uFD06': '\u0635\u064A',
  31515. '\uFD07': '\u0636\u0649',
  31516. '\uFD08': '\u0636\u064A',
  31517. '\uFD09': '\u0634\u062C',
  31518. '\uFD0A': '\u0634\u062D',
  31519. '\uFD0B': '\u0634\u062E',
  31520. '\uFD0C': '\u0634\u0645',
  31521. '\uFD0D': '\u0634\u0631',
  31522. '\uFD0E': '\u0633\u0631',
  31523. '\uFD0F': '\u0635\u0631',
  31524. '\uFD10': '\u0636\u0631',
  31525. '\uFD11': '\u0637\u0649',
  31526. '\uFD12': '\u0637\u064A',
  31527. '\uFD13': '\u0639\u0649',
  31528. '\uFD14': '\u0639\u064A',
  31529. '\uFD15': '\u063A\u0649',
  31530. '\uFD16': '\u063A\u064A',
  31531. '\uFD17': '\u0633\u0649',
  31532. '\uFD18': '\u0633\u064A',
  31533. '\uFD19': '\u0634\u0649',
  31534. '\uFD1A': '\u0634\u064A',
  31535. '\uFD1B': '\u062D\u0649',
  31536. '\uFD1C': '\u062D\u064A',
  31537. '\uFD1D': '\u062C\u0649',
  31538. '\uFD1E': '\u062C\u064A',
  31539. '\uFD1F': '\u062E\u0649',
  31540. '\uFD20': '\u062E\u064A',
  31541. '\uFD21': '\u0635\u0649',
  31542. '\uFD22': '\u0635\u064A',
  31543. '\uFD23': '\u0636\u0649',
  31544. '\uFD24': '\u0636\u064A',
  31545. '\uFD25': '\u0634\u062C',
  31546. '\uFD26': '\u0634\u062D',
  31547. '\uFD27': '\u0634\u062E',
  31548. '\uFD28': '\u0634\u0645',
  31549. '\uFD29': '\u0634\u0631',
  31550. '\uFD2A': '\u0633\u0631',
  31551. '\uFD2B': '\u0635\u0631',
  31552. '\uFD2C': '\u0636\u0631',
  31553. '\uFD2D': '\u0634\u062C',
  31554. '\uFD2E': '\u0634\u062D',
  31555. '\uFD2F': '\u0634\u062E',
  31556. '\uFD30': '\u0634\u0645',
  31557. '\uFD31': '\u0633\u0647',
  31558. '\uFD32': '\u0634\u0647',
  31559. '\uFD33': '\u0637\u0645',
  31560. '\uFD34': '\u0633\u062C',
  31561. '\uFD35': '\u0633\u062D',
  31562. '\uFD36': '\u0633\u062E',
  31563. '\uFD37': '\u0634\u062C',
  31564. '\uFD38': '\u0634\u062D',
  31565. '\uFD39': '\u0634\u062E',
  31566. '\uFD3A': '\u0637\u0645',
  31567. '\uFD3B': '\u0638\u0645',
  31568. '\uFD3C': '\u0627\u064B',
  31569. '\uFD3D': '\u0627\u064B',
  31570. '\uFD50': '\u062A\u062C\u0645',
  31571. '\uFD51': '\u062A\u062D\u062C',
  31572. '\uFD52': '\u062A\u062D\u062C',
  31573. '\uFD53': '\u062A\u062D\u0645',
  31574. '\uFD54': '\u062A\u062E\u0645',
  31575. '\uFD55': '\u062A\u0645\u062C',
  31576. '\uFD56': '\u062A\u0645\u062D',
  31577. '\uFD57': '\u062A\u0645\u062E',
  31578. '\uFD58': '\u062C\u0645\u062D',
  31579. '\uFD59': '\u062C\u0645\u062D',
  31580. '\uFD5A': '\u062D\u0645\u064A',
  31581. '\uFD5B': '\u062D\u0645\u0649',
  31582. '\uFD5C': '\u0633\u062D\u062C',
  31583. '\uFD5D': '\u0633\u062C\u062D',
  31584. '\uFD5E': '\u0633\u062C\u0649',
  31585. '\uFD5F': '\u0633\u0645\u062D',
  31586. '\uFD60': '\u0633\u0645\u062D',
  31587. '\uFD61': '\u0633\u0645\u062C',
  31588. '\uFD62': '\u0633\u0645\u0645',
  31589. '\uFD63': '\u0633\u0645\u0645',
  31590. '\uFD64': '\u0635\u062D\u062D',
  31591. '\uFD65': '\u0635\u062D\u062D',
  31592. '\uFD66': '\u0635\u0645\u0645',
  31593. '\uFD67': '\u0634\u062D\u0645',
  31594. '\uFD68': '\u0634\u062D\u0645',
  31595. '\uFD69': '\u0634\u062C\u064A',
  31596. '\uFD6A': '\u0634\u0645\u062E',
  31597. '\uFD6B': '\u0634\u0645\u062E',
  31598. '\uFD6C': '\u0634\u0645\u0645',
  31599. '\uFD6D': '\u0634\u0645\u0645',
  31600. '\uFD6E': '\u0636\u062D\u0649',
  31601. '\uFD6F': '\u0636\u062E\u0645',
  31602. '\uFD70': '\u0636\u062E\u0645',
  31603. '\uFD71': '\u0637\u0645\u062D',
  31604. '\uFD72': '\u0637\u0645\u062D',
  31605. '\uFD73': '\u0637\u0645\u0645',
  31606. '\uFD74': '\u0637\u0645\u064A',
  31607. '\uFD75': '\u0639\u062C\u0645',
  31608. '\uFD76': '\u0639\u0645\u0645',
  31609. '\uFD77': '\u0639\u0645\u0645',
  31610. '\uFD78': '\u0639\u0645\u0649',
  31611. '\uFD79': '\u063A\u0645\u0645',
  31612. '\uFD7A': '\u063A\u0645\u064A',
  31613. '\uFD7B': '\u063A\u0645\u0649',
  31614. '\uFD7C': '\u0641\u062E\u0645',
  31615. '\uFD7D': '\u0641\u062E\u0645',
  31616. '\uFD7E': '\u0642\u0645\u062D',
  31617. '\uFD7F': '\u0642\u0645\u0645',
  31618. '\uFD80': '\u0644\u062D\u0645',
  31619. '\uFD81': '\u0644\u062D\u064A',
  31620. '\uFD82': '\u0644\u062D\u0649',
  31621. '\uFD83': '\u0644\u062C\u062C',
  31622. '\uFD84': '\u0644\u062C\u062C',
  31623. '\uFD85': '\u0644\u062E\u0645',
  31624. '\uFD86': '\u0644\u062E\u0645',
  31625. '\uFD87': '\u0644\u0645\u062D',
  31626. '\uFD88': '\u0644\u0645\u062D',
  31627. '\uFD89': '\u0645\u062D\u062C',
  31628. '\uFD8A': '\u0645\u062D\u0645',
  31629. '\uFD8B': '\u0645\u062D\u064A',
  31630. '\uFD8C': '\u0645\u062C\u062D',
  31631. '\uFD8D': '\u0645\u062C\u0645',
  31632. '\uFD8E': '\u0645\u062E\u062C',
  31633. '\uFD8F': '\u0645\u062E\u0645',
  31634. '\uFD92': '\u0645\u062C\u062E',
  31635. '\uFD93': '\u0647\u0645\u062C',
  31636. '\uFD94': '\u0647\u0645\u0645',
  31637. '\uFD95': '\u0646\u062D\u0645',
  31638. '\uFD96': '\u0646\u062D\u0649',
  31639. '\uFD97': '\u0646\u062C\u0645',
  31640. '\uFD98': '\u0646\u062C\u0645',
  31641. '\uFD99': '\u0646\u062C\u0649',
  31642. '\uFD9A': '\u0646\u0645\u064A',
  31643. '\uFD9B': '\u0646\u0645\u0649',
  31644. '\uFD9C': '\u064A\u0645\u0645',
  31645. '\uFD9D': '\u064A\u0645\u0645',
  31646. '\uFD9E': '\u0628\u062E\u064A',
  31647. '\uFD9F': '\u062A\u062C\u064A',
  31648. '\uFDA0': '\u062A\u062C\u0649',
  31649. '\uFDA1': '\u062A\u062E\u064A',
  31650. '\uFDA2': '\u062A\u062E\u0649',
  31651. '\uFDA3': '\u062A\u0645\u064A',
  31652. '\uFDA4': '\u062A\u0645\u0649',
  31653. '\uFDA5': '\u062C\u0645\u064A',
  31654. '\uFDA6': '\u062C\u062D\u0649',
  31655. '\uFDA7': '\u062C\u0645\u0649',
  31656. '\uFDA8': '\u0633\u062E\u0649',
  31657. '\uFDA9': '\u0635\u062D\u064A',
  31658. '\uFDAA': '\u0634\u062D\u064A',
  31659. '\uFDAB': '\u0636\u062D\u064A',
  31660. '\uFDAC': '\u0644\u062C\u064A',
  31661. '\uFDAD': '\u0644\u0645\u064A',
  31662. '\uFDAE': '\u064A\u062D\u064A',
  31663. '\uFDAF': '\u064A\u062C\u064A',
  31664. '\uFDB0': '\u064A\u0645\u064A',
  31665. '\uFDB1': '\u0645\u0645\u064A',
  31666. '\uFDB2': '\u0642\u0645\u064A',
  31667. '\uFDB3': '\u0646\u062D\u064A',
  31668. '\uFDB4': '\u0642\u0645\u062D',
  31669. '\uFDB5': '\u0644\u062D\u0645',
  31670. '\uFDB6': '\u0639\u0645\u064A',
  31671. '\uFDB7': '\u0643\u0645\u064A',
  31672. '\uFDB8': '\u0646\u062C\u062D',
  31673. '\uFDB9': '\u0645\u062E\u064A',
  31674. '\uFDBA': '\u0644\u062C\u0645',
  31675. '\uFDBB': '\u0643\u0645\u0645',
  31676. '\uFDBC': '\u0644\u062C\u0645',
  31677. '\uFDBD': '\u0646\u062C\u062D',
  31678. '\uFDBE': '\u062C\u062D\u064A',
  31679. '\uFDBF': '\u062D\u062C\u064A',
  31680. '\uFDC0': '\u0645\u062C\u064A',
  31681. '\uFDC1': '\u0641\u0645\u064A',
  31682. '\uFDC2': '\u0628\u062D\u064A',
  31683. '\uFDC3': '\u0643\u0645\u0645',
  31684. '\uFDC4': '\u0639\u062C\u0645',
  31685. '\uFDC5': '\u0635\u0645\u0645',
  31686. '\uFDC6': '\u0633\u062E\u064A',
  31687. '\uFDC7': '\u0646\u062C\u064A',
  31688. '\uFE49': '\u203E',
  31689. '\uFE4A': '\u203E',
  31690. '\uFE4B': '\u203E',
  31691. '\uFE4C': '\u203E',
  31692. '\uFE4D': '\u005F',
  31693. '\uFE4E': '\u005F',
  31694. '\uFE4F': '\u005F',
  31695. '\uFE80': '\u0621',
  31696. '\uFE81': '\u0622',
  31697. '\uFE82': '\u0622',
  31698. '\uFE83': '\u0623',
  31699. '\uFE84': '\u0623',
  31700. '\uFE85': '\u0624',
  31701. '\uFE86': '\u0624',
  31702. '\uFE87': '\u0625',
  31703. '\uFE88': '\u0625',
  31704. '\uFE89': '\u0626',
  31705. '\uFE8A': '\u0626',
  31706. '\uFE8B': '\u0626',
  31707. '\uFE8C': '\u0626',
  31708. '\uFE8D': '\u0627',
  31709. '\uFE8E': '\u0627',
  31710. '\uFE8F': '\u0628',
  31711. '\uFE90': '\u0628',
  31712. '\uFE91': '\u0628',
  31713. '\uFE92': '\u0628',
  31714. '\uFE93': '\u0629',
  31715. '\uFE94': '\u0629',
  31716. '\uFE95': '\u062A',
  31717. '\uFE96': '\u062A',
  31718. '\uFE97': '\u062A',
  31719. '\uFE98': '\u062A',
  31720. '\uFE99': '\u062B',
  31721. '\uFE9A': '\u062B',
  31722. '\uFE9B': '\u062B',
  31723. '\uFE9C': '\u062B',
  31724. '\uFE9D': '\u062C',
  31725. '\uFE9E': '\u062C',
  31726. '\uFE9F': '\u062C',
  31727. '\uFEA0': '\u062C',
  31728. '\uFEA1': '\u062D',
  31729. '\uFEA2': '\u062D',
  31730. '\uFEA3': '\u062D',
  31731. '\uFEA4': '\u062D',
  31732. '\uFEA5': '\u062E',
  31733. '\uFEA6': '\u062E',
  31734. '\uFEA7': '\u062E',
  31735. '\uFEA8': '\u062E',
  31736. '\uFEA9': '\u062F',
  31737. '\uFEAA': '\u062F',
  31738. '\uFEAB': '\u0630',
  31739. '\uFEAC': '\u0630',
  31740. '\uFEAD': '\u0631',
  31741. '\uFEAE': '\u0631',
  31742. '\uFEAF': '\u0632',
  31743. '\uFEB0': '\u0632',
  31744. '\uFEB1': '\u0633',
  31745. '\uFEB2': '\u0633',
  31746. '\uFEB3': '\u0633',
  31747. '\uFEB4': '\u0633',
  31748. '\uFEB5': '\u0634',
  31749. '\uFEB6': '\u0634',
  31750. '\uFEB7': '\u0634',
  31751. '\uFEB8': '\u0634',
  31752. '\uFEB9': '\u0635',
  31753. '\uFEBA': '\u0635',
  31754. '\uFEBB': '\u0635',
  31755. '\uFEBC': '\u0635',
  31756. '\uFEBD': '\u0636',
  31757. '\uFEBE': '\u0636',
  31758. '\uFEBF': '\u0636',
  31759. '\uFEC0': '\u0636',
  31760. '\uFEC1': '\u0637',
  31761. '\uFEC2': '\u0637',
  31762. '\uFEC3': '\u0637',
  31763. '\uFEC4': '\u0637',
  31764. '\uFEC5': '\u0638',
  31765. '\uFEC6': '\u0638',
  31766. '\uFEC7': '\u0638',
  31767. '\uFEC8': '\u0638',
  31768. '\uFEC9': '\u0639',
  31769. '\uFECA': '\u0639',
  31770. '\uFECB': '\u0639',
  31771. '\uFECC': '\u0639',
  31772. '\uFECD': '\u063A',
  31773. '\uFECE': '\u063A',
  31774. '\uFECF': '\u063A',
  31775. '\uFED0': '\u063A',
  31776. '\uFED1': '\u0641',
  31777. '\uFED2': '\u0641',
  31778. '\uFED3': '\u0641',
  31779. '\uFED4': '\u0641',
  31780. '\uFED5': '\u0642',
  31781. '\uFED6': '\u0642',
  31782. '\uFED7': '\u0642',
  31783. '\uFED8': '\u0642',
  31784. '\uFED9': '\u0643',
  31785. '\uFEDA': '\u0643',
  31786. '\uFEDB': '\u0643',
  31787. '\uFEDC': '\u0643',
  31788. '\uFEDD': '\u0644',
  31789. '\uFEDE': '\u0644',
  31790. '\uFEDF': '\u0644',
  31791. '\uFEE0': '\u0644',
  31792. '\uFEE1': '\u0645',
  31793. '\uFEE2': '\u0645',
  31794. '\uFEE3': '\u0645',
  31795. '\uFEE4': '\u0645',
  31796. '\uFEE5': '\u0646',
  31797. '\uFEE6': '\u0646',
  31798. '\uFEE7': '\u0646',
  31799. '\uFEE8': '\u0646',
  31800. '\uFEE9': '\u0647',
  31801. '\uFEEA': '\u0647',
  31802. '\uFEEB': '\u0647',
  31803. '\uFEEC': '\u0647',
  31804. '\uFEED': '\u0648',
  31805. '\uFEEE': '\u0648',
  31806. '\uFEEF': '\u0649',
  31807. '\uFEF0': '\u0649',
  31808. '\uFEF1': '\u064A',
  31809. '\uFEF2': '\u064A',
  31810. '\uFEF3': '\u064A',
  31811. '\uFEF4': '\u064A',
  31812. '\uFEF5': '\u0644\u0622',
  31813. '\uFEF6': '\u0644\u0622',
  31814. '\uFEF7': '\u0644\u0623',
  31815. '\uFEF8': '\u0644\u0623',
  31816. '\uFEF9': '\u0644\u0625',
  31817. '\uFEFA': '\u0644\u0625',
  31818. '\uFEFB': '\u0644\u0627',
  31819. '\uFEFC': '\u0644\u0627'
  31820. };
  31821. function reverseIfRtl(chars) {
  31822. var charsLength = chars.length;
  31823. //reverse an arabic ligature
  31824. if (charsLength <= 1 || !isRTLRangeFor(chars.charCodeAt(0))) {
  31825. return chars;
  31826. }
  31827. var s = '';
  31828. for (var ii = charsLength - 1; ii >= 0; ii--) {
  31829. s += chars[ii];
  31830. }
  31831. return s;
  31832. }
  31833. function adjustWidths(properties) {
  31834. if (!properties.fontMatrix) {
  31835. return;
  31836. }
  31837. if (properties.fontMatrix[0] === FONT_IDENTITY_MATRIX[0]) {
  31838. return;
  31839. }
  31840. // adjusting width to fontMatrix scale
  31841. var scale = 0.001 / properties.fontMatrix[0];
  31842. var glyphsWidths = properties.widths;
  31843. for (var glyph in glyphsWidths) {
  31844. glyphsWidths[glyph] *= scale;
  31845. }
  31846. properties.defaultWidth *= scale;
  31847. }
  31848. function getFontType(type, subtype) {
  31849. switch (type) {
  31850. case 'Type1':
  31851. return subtype === 'Type1C' ? FontType.TYPE1C : FontType.TYPE1;
  31852. case 'CIDFontType0':
  31853. return subtype === 'CIDFontType0C' ? FontType.CIDFONTTYPE0C :
  31854. FontType.CIDFONTTYPE0;
  31855. case 'OpenType':
  31856. return FontType.OPENTYPE;
  31857. case 'TrueType':
  31858. return FontType.TRUETYPE;
  31859. case 'CIDFontType2':
  31860. return FontType.CIDFONTTYPE2;
  31861. case 'MMType1':
  31862. return FontType.MMTYPE1;
  31863. case 'Type0':
  31864. return FontType.TYPE0;
  31865. default:
  31866. return FontType.UNKNOWN;
  31867. }
  31868. }
  31869. var Glyph = (function GlyphClosure() {
  31870. function Glyph(fontChar, unicode, accent, width, vmetric, operatorListId,
  31871. isSpace) {
  31872. this.fontChar = fontChar;
  31873. this.unicode = unicode;
  31874. this.accent = accent;
  31875. this.width = width;
  31876. this.vmetric = vmetric;
  31877. this.operatorListId = operatorListId;
  31878. this.isSpace = isSpace;
  31879. }
  31880. Glyph.prototype.matchesForCache = function(fontChar, unicode, accent, width,
  31881. vmetric, operatorListId, isSpace) {
  31882. return this.fontChar === fontChar &&
  31883. this.unicode === unicode &&
  31884. this.accent === accent &&
  31885. this.width === width &&
  31886. this.vmetric === vmetric &&
  31887. this.operatorListId === operatorListId &&
  31888. this.isSpace === isSpace;
  31889. };
  31890. return Glyph;
  31891. })();
  31892. var ToUnicodeMap = (function ToUnicodeMapClosure() {
  31893. function ToUnicodeMap(cmap) {
  31894. // The elements of this._map can be integers or strings, depending on how
  31895. // |cmap| was created.
  31896. this._map = cmap;
  31897. }
  31898. ToUnicodeMap.prototype = {
  31899. get length() {
  31900. return this._map.length;
  31901. },
  31902. forEach: function(callback) {
  31903. for (var charCode in this._map) {
  31904. callback(charCode, this._map[charCode].charCodeAt(0));
  31905. }
  31906. },
  31907. has: function(i) {
  31908. return this._map[i] !== undefined;
  31909. },
  31910. get: function(i) {
  31911. return this._map[i];
  31912. },
  31913. charCodeOf: function(v) {
  31914. return this._map.indexOf(v);
  31915. }
  31916. };
  31917. return ToUnicodeMap;
  31918. })();
  31919. var IdentityToUnicodeMap = (function IdentityToUnicodeMapClosure() {
  31920. function IdentityToUnicodeMap(firstChar, lastChar) {
  31921. this.firstChar = firstChar;
  31922. this.lastChar = lastChar;
  31923. }
  31924. IdentityToUnicodeMap.prototype = {
  31925. get length() {
  31926. return (this.lastChar + 1) - this.firstChar;
  31927. },
  31928. forEach: function (callback) {
  31929. for (var i = this.firstChar, ii = this.lastChar; i <= ii; i++) {
  31930. callback(i, i);
  31931. }
  31932. },
  31933. has: function (i) {
  31934. return this.firstChar <= i && i <= this.lastChar;
  31935. },
  31936. get: function (i) {
  31937. if (this.firstChar <= i && i <= this.lastChar) {
  31938. return String.fromCharCode(i);
  31939. }
  31940. return undefined;
  31941. },
  31942. charCodeOf: function (v) {
  31943. return (isInt(v) && v >= this.firstChar && v <= this.lastChar) ? v : -1;
  31944. }
  31945. };
  31946. return IdentityToUnicodeMap;
  31947. })();
  31948. var OpenTypeFileBuilder = (function OpenTypeFileBuilderClosure() {
  31949. function writeInt16(dest, offset, num) {
  31950. dest[offset] = (num >> 8) & 0xFF;
  31951. dest[offset + 1] = num & 0xFF;
  31952. }
  31953. function writeInt32(dest, offset, num) {
  31954. dest[offset] = (num >> 24) & 0xFF;
  31955. dest[offset + 1] = (num >> 16) & 0xFF;
  31956. dest[offset + 2] = (num >> 8) & 0xFF;
  31957. dest[offset + 3] = num & 0xFF;
  31958. }
  31959. function writeData(dest, offset, data) {
  31960. var i, ii;
  31961. if (data instanceof Uint8Array) {
  31962. dest.set(data, offset);
  31963. } else if (typeof data === 'string') {
  31964. for (i = 0, ii = data.length; i < ii; i++) {
  31965. dest[offset++] = data.charCodeAt(i) & 0xFF;
  31966. }
  31967. } else {
  31968. // treating everything else as array
  31969. for (i = 0, ii = data.length; i < ii; i++) {
  31970. dest[offset++] = data[i] & 0xFF;
  31971. }
  31972. }
  31973. }
  31974. function OpenTypeFileBuilder(sfnt) {
  31975. this.sfnt = sfnt;
  31976. this.tables = Object.create(null);
  31977. }
  31978. OpenTypeFileBuilder.getSearchParams =
  31979. function OpenTypeFileBuilder_getSearchParams(entriesCount, entrySize) {
  31980. var maxPower2 = 1, log2 = 0;
  31981. while ((maxPower2 ^ entriesCount) > maxPower2) {
  31982. maxPower2 <<= 1;
  31983. log2++;
  31984. }
  31985. var searchRange = maxPower2 * entrySize;
  31986. return {
  31987. range: searchRange,
  31988. entry: log2,
  31989. rangeShift: entrySize * entriesCount - searchRange
  31990. };
  31991. };
  31992. var OTF_HEADER_SIZE = 12;
  31993. var OTF_TABLE_ENTRY_SIZE = 16;
  31994. OpenTypeFileBuilder.prototype = {
  31995. toArray: function OpenTypeFileBuilder_toArray() {
  31996. var sfnt = this.sfnt;
  31997. // Tables needs to be written by ascendant alphabetic order
  31998. var tables = this.tables;
  31999. var tablesNames = Object.keys(tables);
  32000. tablesNames.sort();
  32001. var numTables = tablesNames.length;
  32002. var i, j, jj, table, tableName;
  32003. // layout the tables data
  32004. var offset = OTF_HEADER_SIZE + numTables * OTF_TABLE_ENTRY_SIZE;
  32005. var tableOffsets = [offset];
  32006. for (i = 0; i < numTables; i++) {
  32007. table = tables[tablesNames[i]];
  32008. var paddedLength = ((table.length + 3) & ~3) >>> 0;
  32009. offset += paddedLength;
  32010. tableOffsets.push(offset);
  32011. }
  32012. var file = new Uint8Array(offset);
  32013. // write the table data first (mostly for checksum)
  32014. for (i = 0; i < numTables; i++) {
  32015. table = tables[tablesNames[i]];
  32016. writeData(file, tableOffsets[i], table);
  32017. }
  32018. // sfnt version (4 bytes)
  32019. if (sfnt === 'true') {
  32020. // Windows hates the Mac TrueType sfnt version number
  32021. sfnt = string32(0x00010000);
  32022. }
  32023. file[0] = sfnt.charCodeAt(0) & 0xFF;
  32024. file[1] = sfnt.charCodeAt(1) & 0xFF;
  32025. file[2] = sfnt.charCodeAt(2) & 0xFF;
  32026. file[3] = sfnt.charCodeAt(3) & 0xFF;
  32027. // numTables (2 bytes)
  32028. writeInt16(file, 4, numTables);
  32029. var searchParams = OpenTypeFileBuilder.getSearchParams(numTables, 16);
  32030. // searchRange (2 bytes)
  32031. writeInt16(file, 6, searchParams.range);
  32032. // entrySelector (2 bytes)
  32033. writeInt16(file, 8, searchParams.entry);
  32034. // rangeShift (2 bytes)
  32035. writeInt16(file, 10, searchParams.rangeShift);
  32036. offset = OTF_HEADER_SIZE;
  32037. // writing table entries
  32038. for (i = 0; i < numTables; i++) {
  32039. tableName = tablesNames[i];
  32040. file[offset] = tableName.charCodeAt(0) & 0xFF;
  32041. file[offset + 1] = tableName.charCodeAt(1) & 0xFF;
  32042. file[offset + 2] = tableName.charCodeAt(2) & 0xFF;
  32043. file[offset + 3] = tableName.charCodeAt(3) & 0xFF;
  32044. // checksum
  32045. var checksum = 0;
  32046. for (j = tableOffsets[i], jj = tableOffsets[i + 1]; j < jj; j += 4) {
  32047. var quad = (file[j] << 24) + (file[j + 1] << 16) +
  32048. (file[j + 2] << 8) + file[j + 3];
  32049. checksum = (checksum + quad) | 0;
  32050. }
  32051. writeInt32(file, offset + 4, checksum);
  32052. // offset
  32053. writeInt32(file, offset + 8, tableOffsets[i]);
  32054. // length
  32055. writeInt32(file, offset + 12, tables[tableName].length);
  32056. offset += OTF_TABLE_ENTRY_SIZE;
  32057. }
  32058. return file;
  32059. },
  32060. addTable: function OpenTypeFileBuilder_addTable(tag, data) {
  32061. if (tag in this.tables) {
  32062. throw new Error('Table ' + tag + ' already exists');
  32063. }
  32064. this.tables[tag] = data;
  32065. }
  32066. };
  32067. return OpenTypeFileBuilder;
  32068. })();
  32069. // Problematic Unicode characters in the fonts that needs to be moved to avoid
  32070. // issues when they are painted on the canvas, e.g. complex-script shaping or
  32071. // control/whitespace characters. The ranges are listed in pairs: the first item
  32072. // is a code of the first problematic code, the second one is the next
  32073. // non-problematic code. The ranges must be in sorted order.
  32074. var ProblematicCharRanges = new Int32Array([
  32075. // Control characters.
  32076. 0x0000, 0x0020,
  32077. 0x007F, 0x00A1,
  32078. 0x00AD, 0x00AE,
  32079. // Chars that is used in complex-script shaping.
  32080. 0x0600, 0x0780,
  32081. 0x08A0, 0x10A0,
  32082. 0x1780, 0x1800,
  32083. // General punctuation chars.
  32084. 0x2000, 0x2010,
  32085. 0x2011, 0x2012,
  32086. 0x2028, 0x2030,
  32087. 0x205F, 0x2070,
  32088. 0x25CC, 0x25CD,
  32089. // Chars that is used in complex-script shaping.
  32090. 0xAA60, 0xAA80,
  32091. // Specials Unicode block.
  32092. 0xFFF0, 0x10000
  32093. ]);
  32094. /**
  32095. * 'Font' is the class the outside world should use, it encapsulate all the font
  32096. * decoding logics whatever type it is (assuming the font type is supported).
  32097. *
  32098. * For example to read a Type1 font and to attach it to the document:
  32099. * var type1Font = new Font("MyFontName", binaryFile, propertiesObject);
  32100. * type1Font.bind();
  32101. */
  32102. var Font = (function FontClosure() {
  32103. function Font(name, file, properties) {
  32104. var charCode, glyphName, fontChar;
  32105. this.name = name;
  32106. this.loadedName = properties.loadedName;
  32107. this.isType3Font = properties.isType3Font;
  32108. this.sizes = [];
  32109. this.glyphCache = {};
  32110. var names = name.split('+');
  32111. names = names.length > 1 ? names[1] : names[0];
  32112. names = names.split(/[-,_]/g)[0];
  32113. this.isSerifFont = !!(properties.flags & FontFlags.Serif);
  32114. this.isSymbolicFont = !!(properties.flags & FontFlags.Symbolic);
  32115. this.isMonospace = !!(properties.flags & FontFlags.FixedPitch);
  32116. var type = properties.type;
  32117. var subtype = properties.subtype;
  32118. this.type = type;
  32119. this.fallbackName = (this.isMonospace ? 'monospace' :
  32120. (this.isSerifFont ? 'serif' : 'sans-serif'));
  32121. this.differences = properties.differences;
  32122. this.widths = properties.widths;
  32123. this.defaultWidth = properties.defaultWidth;
  32124. this.composite = properties.composite;
  32125. this.wideChars = properties.wideChars;
  32126. this.cMap = properties.cMap;
  32127. this.ascent = properties.ascent / PDF_GLYPH_SPACE_UNITS;
  32128. this.descent = properties.descent / PDF_GLYPH_SPACE_UNITS;
  32129. this.fontMatrix = properties.fontMatrix;
  32130. this.bbox = properties.bbox;
  32131. this.toUnicode = properties.toUnicode = this.buildToUnicode(properties);
  32132. this.toFontChar = [];
  32133. if (properties.type === 'Type3') {
  32134. for (charCode = 0; charCode < 256; charCode++) {
  32135. this.toFontChar[charCode] = (this.differences[charCode] ||
  32136. properties.defaultEncoding[charCode]);
  32137. }
  32138. this.fontType = FontType.TYPE3;
  32139. return;
  32140. }
  32141. this.cidEncoding = properties.cidEncoding;
  32142. this.vertical = properties.vertical;
  32143. if (this.vertical) {
  32144. this.vmetrics = properties.vmetrics;
  32145. this.defaultVMetrics = properties.defaultVMetrics;
  32146. }
  32147. if (!file || file.isEmpty) {
  32148. if (file) {
  32149. // Some bad PDF generators will include empty font files,
  32150. // attempting to recover by assuming that no file exists.
  32151. warn('Font file is empty in "' + name + '" (' + this.loadedName + ')');
  32152. }
  32153. this.missingFile = true;
  32154. // The file data is not specified. Trying to fix the font name
  32155. // to be used with the canvas.font.
  32156. var fontName = name.replace(/[,_]/g, '-');
  32157. var isStandardFont = !!stdFontMap[fontName] ||
  32158. !!(nonStdFontMap[fontName] && stdFontMap[nonStdFontMap[fontName]]);
  32159. fontName = stdFontMap[fontName] || nonStdFontMap[fontName] || fontName;
  32160. this.bold = (fontName.search(/bold/gi) !== -1);
  32161. this.italic = ((fontName.search(/oblique/gi) !== -1) ||
  32162. (fontName.search(/italic/gi) !== -1));
  32163. // Use 'name' instead of 'fontName' here because the original
  32164. // name ArialBlack for example will be replaced by Helvetica.
  32165. this.black = (name.search(/Black/g) !== -1);
  32166. // if at least one width is present, remeasure all chars when exists
  32167. this.remeasure = Object.keys(this.widths).length > 0;
  32168. if (isStandardFont && type === 'CIDFontType2' &&
  32169. properties.cidEncoding.indexOf('Identity-') === 0) {
  32170. // Standard fonts might be embedded as CID font without glyph mapping.
  32171. // Building one based on GlyphMapForStandardFonts.
  32172. var map = [];
  32173. for (charCode in GlyphMapForStandardFonts) {
  32174. map[+charCode] = GlyphMapForStandardFonts[charCode];
  32175. }
  32176. if (/ArialBlack/i.test(name)) {
  32177. for (charCode in SupplementalGlyphMapForArialBlack) {
  32178. map[+charCode] = SupplementalGlyphMapForArialBlack[charCode];
  32179. }
  32180. }
  32181. var isIdentityUnicode = this.toUnicode instanceof IdentityToUnicodeMap;
  32182. if (!isIdentityUnicode) {
  32183. this.toUnicode.forEach(function(charCode, unicodeCharCode) {
  32184. map[+charCode] = unicodeCharCode;
  32185. });
  32186. }
  32187. this.toFontChar = map;
  32188. this.toUnicode = new ToUnicodeMap(map);
  32189. } else if (/Symbol/i.test(fontName)) {
  32190. var symbols = Encodings.SymbolSetEncoding;
  32191. for (charCode in symbols) {
  32192. fontChar = GlyphsUnicode[symbols[charCode]];
  32193. if (!fontChar) {
  32194. continue;
  32195. }
  32196. this.toFontChar[charCode] = fontChar;
  32197. }
  32198. for (charCode in properties.differences) {
  32199. fontChar = GlyphsUnicode[properties.differences[charCode]];
  32200. if (!fontChar) {
  32201. continue;
  32202. }
  32203. this.toFontChar[charCode] = fontChar;
  32204. }
  32205. } else if (/Dingbats/i.test(fontName)) {
  32206. if (/Wingdings/i.test(name)) {
  32207. warn('Wingdings font without embedded font file, ' +
  32208. 'falling back to the ZapfDingbats encoding.');
  32209. }
  32210. var dingbats = Encodings.ZapfDingbatsEncoding;
  32211. for (charCode in dingbats) {
  32212. fontChar = DingbatsGlyphsUnicode[dingbats[charCode]];
  32213. if (!fontChar) {
  32214. continue;
  32215. }
  32216. this.toFontChar[charCode] = fontChar;
  32217. }
  32218. for (charCode in properties.differences) {
  32219. fontChar = DingbatsGlyphsUnicode[properties.differences[charCode]];
  32220. if (!fontChar) {
  32221. continue;
  32222. }
  32223. this.toFontChar[charCode] = fontChar;
  32224. }
  32225. } else if (isStandardFont) {
  32226. this.toFontChar = [];
  32227. for (charCode in properties.defaultEncoding) {
  32228. glyphName = (properties.differences[charCode] ||
  32229. properties.defaultEncoding[charCode]);
  32230. this.toFontChar[charCode] = GlyphsUnicode[glyphName];
  32231. }
  32232. } else {
  32233. var unicodeCharCode, notCidFont = (type.indexOf('CIDFontType') === -1);
  32234. this.toUnicode.forEach(function(charCode, unicodeCharCode) {
  32235. if (notCidFont) {
  32236. glyphName = (properties.differences[charCode] ||
  32237. properties.defaultEncoding[charCode]);
  32238. unicodeCharCode = (GlyphsUnicode[glyphName] || unicodeCharCode);
  32239. }
  32240. this.toFontChar[charCode] = unicodeCharCode;
  32241. }.bind(this));
  32242. }
  32243. this.loadedName = fontName.split('-')[0];
  32244. this.loading = false;
  32245. this.fontType = getFontType(type, subtype);
  32246. return;
  32247. }
  32248. // Some fonts might use wrong font types for Type1C or CIDFontType0C
  32249. if (subtype === 'Type1C' && (type !== 'Type1' && type !== 'MMType1')) {
  32250. // Some TrueType fonts by mistake claim Type1C
  32251. if (isTrueTypeFile(file)) {
  32252. subtype = 'TrueType';
  32253. } else {
  32254. type = 'Type1';
  32255. }
  32256. }
  32257. if (subtype === 'CIDFontType0C' && type !== 'CIDFontType0') {
  32258. type = 'CIDFontType0';
  32259. }
  32260. if (subtype === 'OpenType') {
  32261. type = 'OpenType';
  32262. }
  32263. // Some CIDFontType0C fonts by mistake claim CIDFontType0.
  32264. if (type === 'CIDFontType0') {
  32265. subtype = isType1File(file) ? 'CIDFontType0' : 'CIDFontType0C';
  32266. }
  32267. var data;
  32268. switch (type) {
  32269. case 'MMType1':
  32270. info('MMType1 font (' + name + '), falling back to Type1.');
  32271. /* falls through */
  32272. case 'Type1':
  32273. case 'CIDFontType0':
  32274. this.mimetype = 'font/opentype';
  32275. var cff = (subtype === 'Type1C' || subtype === 'CIDFontType0C') ?
  32276. new CFFFont(file, properties) : new Type1Font(name, file, properties);
  32277. adjustWidths(properties);
  32278. // Wrap the CFF data inside an OTF font file
  32279. data = this.convert(name, cff, properties);
  32280. break;
  32281. case 'OpenType':
  32282. case 'TrueType':
  32283. case 'CIDFontType2':
  32284. this.mimetype = 'font/opentype';
  32285. // Repair the TrueType file. It is can be damaged in the point of
  32286. // view of the sanitizer
  32287. data = this.checkAndRepair(name, file, properties);
  32288. if (this.isOpenType) {
  32289. adjustWidths(properties);
  32290. type = 'OpenType';
  32291. }
  32292. break;
  32293. default:
  32294. error('Font ' + type + ' is not supported');
  32295. break;
  32296. }
  32297. this.data = data;
  32298. this.fontType = getFontType(type, subtype);
  32299. // Transfer some properties again that could change during font conversion
  32300. this.fontMatrix = properties.fontMatrix;
  32301. this.widths = properties.widths;
  32302. this.defaultWidth = properties.defaultWidth;
  32303. this.encoding = properties.baseEncoding;
  32304. this.seacMap = properties.seacMap;
  32305. this.loading = true;
  32306. }
  32307. Font.getFontID = (function () {
  32308. var ID = 1;
  32309. return function Font_getFontID() {
  32310. return String(ID++);
  32311. };
  32312. })();
  32313. function int16(b0, b1) {
  32314. return (b0 << 8) + b1;
  32315. }
  32316. function int32(b0, b1, b2, b3) {
  32317. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  32318. }
  32319. function string16(value) {
  32320. return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
  32321. }
  32322. function safeString16(value) {
  32323. // clamp value to the 16-bit int range
  32324. value = (value > 0x7FFF ? 0x7FFF : (value < -0x8000 ? -0x8000 : value));
  32325. return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
  32326. }
  32327. function isTrueTypeFile(file) {
  32328. var header = file.peekBytes(4);
  32329. return readUint32(header, 0) === 0x00010000;
  32330. }
  32331. function isType1File(file) {
  32332. var header = file.peekBytes(2);
  32333. // All Type1 font programs must begin with the comment '%!' (0x25 + 0x21).
  32334. if (header[0] === 0x25 && header[1] === 0x21) {
  32335. return true;
  32336. }
  32337. // ... obviously some fonts violate that part of the specification,
  32338. // please refer to the comment in |Type1Font| below.
  32339. if (header[0] === 0x80 && header[1] === 0x01) { // pfb file header.
  32340. return true;
  32341. }
  32342. return false;
  32343. }
  32344. /**
  32345. * Helper function for |adjustMapping|.
  32346. * @return {boolean}
  32347. */
  32348. function isProblematicUnicodeLocation(code) {
  32349. // Using binary search to find a range start.
  32350. var i = 0, j = ProblematicCharRanges.length - 1;
  32351. while (i < j) {
  32352. var c = (i + j + 1) >> 1;
  32353. if (code < ProblematicCharRanges[c]) {
  32354. j = c - 1;
  32355. } else {
  32356. i = c;
  32357. }
  32358. }
  32359. // Even index means code in problematic range.
  32360. return !(i & 1);
  32361. }
  32362. /**
  32363. * Rebuilds the char code to glyph ID map by trying to replace the char codes
  32364. * with their unicode value. It also moves char codes that are in known
  32365. * problematic locations.
  32366. * @return {Object} Two properties:
  32367. * 'toFontChar' - maps original char codes(the value that will be read
  32368. * from commands such as show text) to the char codes that will be used in the
  32369. * font that we build
  32370. * 'charCodeToGlyphId' - maps the new font char codes to glyph ids
  32371. */
  32372. function adjustMapping(charCodeToGlyphId, properties) {
  32373. var toUnicode = properties.toUnicode;
  32374. var isSymbolic = !!(properties.flags & FontFlags.Symbolic);
  32375. var isIdentityUnicode =
  32376. properties.toUnicode instanceof IdentityToUnicodeMap;
  32377. var newMap = Object.create(null);
  32378. var toFontChar = [];
  32379. var usedFontCharCodes = [];
  32380. var nextAvailableFontCharCode = PRIVATE_USE_OFFSET_START;
  32381. for (var originalCharCode in charCodeToGlyphId) {
  32382. originalCharCode |= 0;
  32383. var glyphId = charCodeToGlyphId[originalCharCode];
  32384. var fontCharCode = originalCharCode;
  32385. // First try to map the value to a unicode position if a non identity map
  32386. // was created.
  32387. if (!isIdentityUnicode && toUnicode.has(originalCharCode)) {
  32388. var unicode = toUnicode.get(fontCharCode);
  32389. // TODO: Try to map ligatures to the correct spot.
  32390. if (unicode.length === 1) {
  32391. fontCharCode = unicode.charCodeAt(0);
  32392. }
  32393. }
  32394. // Try to move control characters, special characters and already mapped
  32395. // characters to the private use area since they will not be drawn by
  32396. // canvas if left in their current position. Also, move characters if the
  32397. // font was symbolic and there is only an identity unicode map since the
  32398. // characters probably aren't in the correct position (fixes an issue
  32399. // with firefox and thuluthfont).
  32400. if ((usedFontCharCodes[fontCharCode] !== undefined ||
  32401. isProblematicUnicodeLocation(fontCharCode) ||
  32402. (isSymbolic && isIdentityUnicode)) &&
  32403. nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END) { // Room left.
  32404. // Loop to try and find a free spot in the private use area.
  32405. do {
  32406. fontCharCode = nextAvailableFontCharCode++;
  32407. if (SKIP_PRIVATE_USE_RANGE_F000_TO_F01F && fontCharCode === 0xF000) {
  32408. fontCharCode = 0xF020;
  32409. nextAvailableFontCharCode = fontCharCode + 1;
  32410. }
  32411. } while (usedFontCharCodes[fontCharCode] !== undefined &&
  32412. nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END);
  32413. }
  32414. newMap[fontCharCode] = glyphId;
  32415. toFontChar[originalCharCode] = fontCharCode;
  32416. usedFontCharCodes[fontCharCode] = true;
  32417. }
  32418. return {
  32419. toFontChar: toFontChar,
  32420. charCodeToGlyphId: newMap,
  32421. nextAvailableFontCharCode: nextAvailableFontCharCode
  32422. };
  32423. }
  32424. function getRanges(glyphs, numGlyphs) {
  32425. // Array.sort() sorts by characters, not numerically, so convert to an
  32426. // array of characters.
  32427. var codes = [];
  32428. for (var charCode in glyphs) {
  32429. // Remove an invalid glyph ID mappings to make OTS happy.
  32430. if (glyphs[charCode] >= numGlyphs) {
  32431. continue;
  32432. }
  32433. codes.push({ fontCharCode: charCode | 0, glyphId: glyphs[charCode] });
  32434. }
  32435. codes.sort(function fontGetRangesSort(a, b) {
  32436. return a.fontCharCode - b.fontCharCode;
  32437. });
  32438. // Split the sorted codes into ranges.
  32439. var ranges = [];
  32440. var length = codes.length;
  32441. for (var n = 0; n < length; ) {
  32442. var start = codes[n].fontCharCode;
  32443. var codeIndices = [codes[n].glyphId];
  32444. ++n;
  32445. var end = start;
  32446. while (n < length && end + 1 === codes[n].fontCharCode) {
  32447. codeIndices.push(codes[n].glyphId);
  32448. ++end;
  32449. ++n;
  32450. if (end === 0xFFFF) {
  32451. break;
  32452. }
  32453. }
  32454. ranges.push([start, end, codeIndices]);
  32455. }
  32456. return ranges;
  32457. }
  32458. function createCmapTable(glyphs, numGlyphs) {
  32459. var ranges = getRanges(glyphs, numGlyphs);
  32460. var numTables = ranges[ranges.length - 1][1] > 0xFFFF ? 2 : 1;
  32461. var cmap = '\x00\x00' + // version
  32462. string16(numTables) + // numTables
  32463. '\x00\x03' + // platformID
  32464. '\x00\x01' + // encodingID
  32465. string32(4 + numTables * 8); // start of the table record
  32466. var i, ii, j, jj;
  32467. for (i = ranges.length - 1; i >= 0; --i) {
  32468. if (ranges[i][0] <= 0xFFFF) { break; }
  32469. }
  32470. var bmpLength = i + 1;
  32471. if (ranges[i][0] < 0xFFFF && ranges[i][1] === 0xFFFF) {
  32472. ranges[i][1] = 0xFFFE;
  32473. }
  32474. var trailingRangesCount = ranges[i][1] < 0xFFFF ? 1 : 0;
  32475. var segCount = bmpLength + trailingRangesCount;
  32476. var searchParams = OpenTypeFileBuilder.getSearchParams(segCount, 2);
  32477. // Fill up the 4 parallel arrays describing the segments.
  32478. var startCount = '';
  32479. var endCount = '';
  32480. var idDeltas = '';
  32481. var idRangeOffsets = '';
  32482. var glyphsIds = '';
  32483. var bias = 0;
  32484. var range, start, end, codes;
  32485. for (i = 0, ii = bmpLength; i < ii; i++) {
  32486. range = ranges[i];
  32487. start = range[0];
  32488. end = range[1];
  32489. startCount += string16(start);
  32490. endCount += string16(end);
  32491. codes = range[2];
  32492. var contiguous = true;
  32493. for (j = 1, jj = codes.length; j < jj; ++j) {
  32494. if (codes[j] !== codes[j - 1] + 1) {
  32495. contiguous = false;
  32496. break;
  32497. }
  32498. }
  32499. if (!contiguous) {
  32500. var offset = (segCount - i) * 2 + bias * 2;
  32501. bias += (end - start + 1);
  32502. idDeltas += string16(0);
  32503. idRangeOffsets += string16(offset);
  32504. for (j = 0, jj = codes.length; j < jj; ++j) {
  32505. glyphsIds += string16(codes[j]);
  32506. }
  32507. } else {
  32508. var startCode = codes[0];
  32509. idDeltas += string16((startCode - start) & 0xFFFF);
  32510. idRangeOffsets += string16(0);
  32511. }
  32512. }
  32513. if (trailingRangesCount > 0) {
  32514. endCount += '\xFF\xFF';
  32515. startCount += '\xFF\xFF';
  32516. idDeltas += '\x00\x01';
  32517. idRangeOffsets += '\x00\x00';
  32518. }
  32519. var format314 = '\x00\x00' + // language
  32520. string16(2 * segCount) +
  32521. string16(searchParams.range) +
  32522. string16(searchParams.entry) +
  32523. string16(searchParams.rangeShift) +
  32524. endCount + '\x00\x00' + startCount +
  32525. idDeltas + idRangeOffsets + glyphsIds;
  32526. var format31012 = '';
  32527. var header31012 = '';
  32528. if (numTables > 1) {
  32529. cmap += '\x00\x03' + // platformID
  32530. '\x00\x0A' + // encodingID
  32531. string32(4 + numTables * 8 +
  32532. 4 + format314.length); // start of the table record
  32533. format31012 = '';
  32534. for (i = 0, ii = ranges.length; i < ii; i++) {
  32535. range = ranges[i];
  32536. start = range[0];
  32537. codes = range[2];
  32538. var code = codes[0];
  32539. for (j = 1, jj = codes.length; j < jj; ++j) {
  32540. if (codes[j] !== codes[j - 1] + 1) {
  32541. end = range[0] + j - 1;
  32542. format31012 += string32(start) + // startCharCode
  32543. string32(end) + // endCharCode
  32544. string32(code); // startGlyphID
  32545. start = end + 1;
  32546. code = codes[j];
  32547. }
  32548. }
  32549. format31012 += string32(start) + // startCharCode
  32550. string32(range[1]) + // endCharCode
  32551. string32(code); // startGlyphID
  32552. }
  32553. header31012 = '\x00\x0C' + // format
  32554. '\x00\x00' + // reserved
  32555. string32(format31012.length + 16) + // length
  32556. '\x00\x00\x00\x00' + // language
  32557. string32(format31012.length / 12); // nGroups
  32558. }
  32559. return cmap + '\x00\x04' + // format
  32560. string16(format314.length + 4) + // length
  32561. format314 + header31012 + format31012;
  32562. }
  32563. function validateOS2Table(os2) {
  32564. var stream = new Stream(os2.data);
  32565. var version = stream.getUint16();
  32566. // TODO verify all OS/2 tables fields, but currently we validate only those
  32567. // that give us issues
  32568. stream.getBytes(60); // skipping type, misc sizes, panose, unicode ranges
  32569. var selection = stream.getUint16();
  32570. if (version < 4 && (selection & 0x0300)) {
  32571. return false;
  32572. }
  32573. var firstChar = stream.getUint16();
  32574. var lastChar = stream.getUint16();
  32575. if (firstChar > lastChar) {
  32576. return false;
  32577. }
  32578. stream.getBytes(6); // skipping sTypoAscender/Descender/LineGap
  32579. var usWinAscent = stream.getUint16();
  32580. if (usWinAscent === 0) { // makes font unreadable by windows
  32581. return false;
  32582. }
  32583. // OS/2 appears to be valid, resetting some fields
  32584. os2.data[8] = os2.data[9] = 0; // IE rejects fonts if fsType != 0
  32585. return true;
  32586. }
  32587. function createOS2Table(properties, charstrings, override) {
  32588. override = override || {
  32589. unitsPerEm: 0,
  32590. yMax: 0,
  32591. yMin: 0,
  32592. ascent: 0,
  32593. descent: 0
  32594. };
  32595. var ulUnicodeRange1 = 0;
  32596. var ulUnicodeRange2 = 0;
  32597. var ulUnicodeRange3 = 0;
  32598. var ulUnicodeRange4 = 0;
  32599. var firstCharIndex = null;
  32600. var lastCharIndex = 0;
  32601. if (charstrings) {
  32602. for (var code in charstrings) {
  32603. code |= 0;
  32604. if (firstCharIndex > code || !firstCharIndex) {
  32605. firstCharIndex = code;
  32606. }
  32607. if (lastCharIndex < code) {
  32608. lastCharIndex = code;
  32609. }
  32610. var position = getUnicodeRangeFor(code);
  32611. if (position < 32) {
  32612. ulUnicodeRange1 |= 1 << position;
  32613. } else if (position < 64) {
  32614. ulUnicodeRange2 |= 1 << position - 32;
  32615. } else if (position < 96) {
  32616. ulUnicodeRange3 |= 1 << position - 64;
  32617. } else if (position < 123) {
  32618. ulUnicodeRange4 |= 1 << position - 96;
  32619. } else {
  32620. error('Unicode ranges Bits > 123 are reserved for internal usage');
  32621. }
  32622. }
  32623. } else {
  32624. // TODO
  32625. firstCharIndex = 0;
  32626. lastCharIndex = 255;
  32627. }
  32628. var bbox = properties.bbox || [0, 0, 0, 0];
  32629. var unitsPerEm = (override.unitsPerEm ||
  32630. 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0]);
  32631. // if the font units differ to the PDF glyph space units
  32632. // then scale up the values
  32633. var scale = (properties.ascentScaled ? 1.0 :
  32634. unitsPerEm / PDF_GLYPH_SPACE_UNITS);
  32635. var typoAscent = (override.ascent ||
  32636. Math.round(scale * (properties.ascent || bbox[3])));
  32637. var typoDescent = (override.descent ||
  32638. Math.round(scale * (properties.descent || bbox[1])));
  32639. if (typoDescent > 0 && properties.descent > 0 && bbox[1] < 0) {
  32640. typoDescent = -typoDescent; // fixing incorrect descent
  32641. }
  32642. var winAscent = override.yMax || typoAscent;
  32643. var winDescent = -override.yMin || -typoDescent;
  32644. return '\x00\x03' + // version
  32645. '\x02\x24' + // xAvgCharWidth
  32646. '\x01\xF4' + // usWeightClass
  32647. '\x00\x05' + // usWidthClass
  32648. '\x00\x00' + // fstype (0 to let the font loads via font-face on IE)
  32649. '\x02\x8A' + // ySubscriptXSize
  32650. '\x02\xBB' + // ySubscriptYSize
  32651. '\x00\x00' + // ySubscriptXOffset
  32652. '\x00\x8C' + // ySubscriptYOffset
  32653. '\x02\x8A' + // ySuperScriptXSize
  32654. '\x02\xBB' + // ySuperScriptYSize
  32655. '\x00\x00' + // ySuperScriptXOffset
  32656. '\x01\xDF' + // ySuperScriptYOffset
  32657. '\x00\x31' + // yStrikeOutSize
  32658. '\x01\x02' + // yStrikeOutPosition
  32659. '\x00\x00' + // sFamilyClass
  32660. '\x00\x00\x06' +
  32661. String.fromCharCode(properties.fixedPitch ? 0x09 : 0x00) +
  32662. '\x00\x00\x00\x00\x00\x00' + // Panose
  32663. string32(ulUnicodeRange1) + // ulUnicodeRange1 (Bits 0-31)
  32664. string32(ulUnicodeRange2) + // ulUnicodeRange2 (Bits 32-63)
  32665. string32(ulUnicodeRange3) + // ulUnicodeRange3 (Bits 64-95)
  32666. string32(ulUnicodeRange4) + // ulUnicodeRange4 (Bits 96-127)
  32667. '\x2A\x32\x31\x2A' + // achVendID
  32668. string16(properties.italicAngle ? 1 : 0) + // fsSelection
  32669. string16(firstCharIndex ||
  32670. properties.firstChar) + // usFirstCharIndex
  32671. string16(lastCharIndex || properties.lastChar) + // usLastCharIndex
  32672. string16(typoAscent) + // sTypoAscender
  32673. string16(typoDescent) + // sTypoDescender
  32674. '\x00\x64' + // sTypoLineGap (7%-10% of the unitsPerEM value)
  32675. string16(winAscent) + // usWinAscent
  32676. string16(winDescent) + // usWinDescent
  32677. '\x00\x00\x00\x00' + // ulCodePageRange1 (Bits 0-31)
  32678. '\x00\x00\x00\x00' + // ulCodePageRange2 (Bits 32-63)
  32679. string16(properties.xHeight) + // sxHeight
  32680. string16(properties.capHeight) + // sCapHeight
  32681. string16(0) + // usDefaultChar
  32682. string16(firstCharIndex || properties.firstChar) + // usBreakChar
  32683. '\x00\x03'; // usMaxContext
  32684. }
  32685. function createPostTable(properties) {
  32686. var angle = Math.floor(properties.italicAngle * (Math.pow(2, 16)));
  32687. return ('\x00\x03\x00\x00' + // Version number
  32688. string32(angle) + // italicAngle
  32689. '\x00\x00' + // underlinePosition
  32690. '\x00\x00' + // underlineThickness
  32691. string32(properties.fixedPitch) + // isFixedPitch
  32692. '\x00\x00\x00\x00' + // minMemType42
  32693. '\x00\x00\x00\x00' + // maxMemType42
  32694. '\x00\x00\x00\x00' + // minMemType1
  32695. '\x00\x00\x00\x00'); // maxMemType1
  32696. }
  32697. function createNameTable(name, proto) {
  32698. if (!proto) {
  32699. proto = [[], []]; // no strings and unicode strings
  32700. }
  32701. var strings = [
  32702. proto[0][0] || 'Original licence', // 0.Copyright
  32703. proto[0][1] || name, // 1.Font family
  32704. proto[0][2] || 'Unknown', // 2.Font subfamily (font weight)
  32705. proto[0][3] || 'uniqueID', // 3.Unique ID
  32706. proto[0][4] || name, // 4.Full font name
  32707. proto[0][5] || 'Version 0.11', // 5.Version
  32708. proto[0][6] || '', // 6.Postscript name
  32709. proto[0][7] || 'Unknown', // 7.Trademark
  32710. proto[0][8] || 'Unknown', // 8.Manufacturer
  32711. proto[0][9] || 'Unknown' // 9.Designer
  32712. ];
  32713. // Mac want 1-byte per character strings while Windows want
  32714. // 2-bytes per character, so duplicate the names table
  32715. var stringsUnicode = [];
  32716. var i, ii, j, jj, str;
  32717. for (i = 0, ii = strings.length; i < ii; i++) {
  32718. str = proto[1][i] || strings[i];
  32719. var strBufUnicode = [];
  32720. for (j = 0, jj = str.length; j < jj; j++) {
  32721. strBufUnicode.push(string16(str.charCodeAt(j)));
  32722. }
  32723. stringsUnicode.push(strBufUnicode.join(''));
  32724. }
  32725. var names = [strings, stringsUnicode];
  32726. var platforms = ['\x00\x01', '\x00\x03'];
  32727. var encodings = ['\x00\x00', '\x00\x01'];
  32728. var languages = ['\x00\x00', '\x04\x09'];
  32729. var namesRecordCount = strings.length * platforms.length;
  32730. var nameTable =
  32731. '\x00\x00' + // format
  32732. string16(namesRecordCount) + // Number of names Record
  32733. string16(namesRecordCount * 12 + 6); // Storage
  32734. // Build the name records field
  32735. var strOffset = 0;
  32736. for (i = 0, ii = platforms.length; i < ii; i++) {
  32737. var strs = names[i];
  32738. for (j = 0, jj = strs.length; j < jj; j++) {
  32739. str = strs[j];
  32740. var nameRecord =
  32741. platforms[i] + // platform ID
  32742. encodings[i] + // encoding ID
  32743. languages[i] + // language ID
  32744. string16(j) + // name ID
  32745. string16(str.length) +
  32746. string16(strOffset);
  32747. nameTable += nameRecord;
  32748. strOffset += str.length;
  32749. }
  32750. }
  32751. nameTable += strings.join('') + stringsUnicode.join('');
  32752. return nameTable;
  32753. }
  32754. Font.prototype = {
  32755. name: null,
  32756. font: null,
  32757. mimetype: null,
  32758. encoding: null,
  32759. get renderer() {
  32760. var renderer = FontRendererFactory.create(this);
  32761. return shadow(this, 'renderer', renderer);
  32762. },
  32763. exportData: function Font_exportData() {
  32764. var data = {};
  32765. for (var i in this) {
  32766. if (this.hasOwnProperty(i)) {
  32767. data[i] = this[i];
  32768. }
  32769. }
  32770. return data;
  32771. },
  32772. checkAndRepair: function Font_checkAndRepair(name, font, properties) {
  32773. function readTableEntry(file) {
  32774. var tag = bytesToString(file.getBytes(4));
  32775. var checksum = file.getInt32();
  32776. var offset = file.getInt32() >>> 0;
  32777. var length = file.getInt32() >>> 0;
  32778. // Read the table associated data
  32779. var previousPosition = file.pos;
  32780. file.pos = file.start ? file.start : 0;
  32781. file.skip(offset);
  32782. var data = file.getBytes(length);
  32783. file.pos = previousPosition;
  32784. if (tag === 'head') {
  32785. // clearing checksum adjustment
  32786. data[8] = data[9] = data[10] = data[11] = 0;
  32787. data[17] |= 0x20; //Set font optimized for cleartype flag
  32788. }
  32789. return {
  32790. tag: tag,
  32791. checksum: checksum,
  32792. length: length,
  32793. offset: offset,
  32794. data: data
  32795. };
  32796. }
  32797. function readOpenTypeHeader(ttf) {
  32798. return {
  32799. version: bytesToString(ttf.getBytes(4)),
  32800. numTables: ttf.getUint16(),
  32801. searchRange: ttf.getUint16(),
  32802. entrySelector: ttf.getUint16(),
  32803. rangeShift: ttf.getUint16()
  32804. };
  32805. }
  32806. /**
  32807. * Read the appropriate subtable from the cmap according to 9.6.6.4 from
  32808. * PDF spec
  32809. */
  32810. function readCmapTable(cmap, font, isSymbolicFont, hasEncoding) {
  32811. if (!cmap) {
  32812. warn('No cmap table available.');
  32813. return {
  32814. platformId: -1,
  32815. encodingId: -1,
  32816. mappings: [],
  32817. hasShortCmap: false
  32818. };
  32819. }
  32820. var segment;
  32821. var start = (font.start ? font.start : 0) + cmap.offset;
  32822. font.pos = start;
  32823. var version = font.getUint16();
  32824. var numTables = font.getUint16();
  32825. var potentialTable;
  32826. var canBreak = false;
  32827. // There's an order of preference in terms of which cmap subtable to
  32828. // use:
  32829. // - non-symbolic fonts the preference is a 3,1 table then a 1,0 table
  32830. // - symbolic fonts the preference is a 3,0 table then a 1,0 table
  32831. // The following takes advantage of the fact that the tables are sorted
  32832. // to work.
  32833. for (var i = 0; i < numTables; i++) {
  32834. var platformId = font.getUint16();
  32835. var encodingId = font.getUint16();
  32836. var offset = font.getInt32() >>> 0;
  32837. var useTable = false;
  32838. if (platformId === 0 && encodingId === 0) {
  32839. useTable = true;
  32840. // Continue the loop since there still may be a higher priority
  32841. // table.
  32842. } else if (platformId === 1 && encodingId === 0) {
  32843. useTable = true;
  32844. // Continue the loop since there still may be a higher priority
  32845. // table.
  32846. } else if (platformId === 3 && encodingId === 1 &&
  32847. ((!isSymbolicFont && hasEncoding) || !potentialTable)) {
  32848. useTable = true;
  32849. if (!isSymbolicFont) {
  32850. canBreak = true;
  32851. }
  32852. } else if (isSymbolicFont && platformId === 3 && encodingId === 0) {
  32853. useTable = true;
  32854. canBreak = true;
  32855. }
  32856. if (useTable) {
  32857. potentialTable = {
  32858. platformId: platformId,
  32859. encodingId: encodingId,
  32860. offset: offset
  32861. };
  32862. }
  32863. if (canBreak) {
  32864. break;
  32865. }
  32866. }
  32867. if (potentialTable) {
  32868. font.pos = start + potentialTable.offset;
  32869. }
  32870. if (!potentialTable || font.peekByte() === -1) {
  32871. warn('Could not find a preferred cmap table.');
  32872. return {
  32873. platformId: -1,
  32874. encodingId: -1,
  32875. mappings: [],
  32876. hasShortCmap: false
  32877. };
  32878. }
  32879. var format = font.getUint16();
  32880. var length = font.getUint16();
  32881. var language = font.getUint16();
  32882. var hasShortCmap = false;
  32883. var mappings = [];
  32884. var j, glyphId;
  32885. // TODO(mack): refactor this cmap subtable reading logic out
  32886. if (format === 0) {
  32887. for (j = 0; j < 256; j++) {
  32888. var index = font.getByte();
  32889. if (!index) {
  32890. continue;
  32891. }
  32892. mappings.push({
  32893. charCode: j,
  32894. glyphId: index
  32895. });
  32896. }
  32897. hasShortCmap = true;
  32898. } else if (format === 4) {
  32899. // re-creating the table in format 4 since the encoding
  32900. // might be changed
  32901. var segCount = (font.getUint16() >> 1);
  32902. font.getBytes(6); // skipping range fields
  32903. var segIndex, segments = [];
  32904. for (segIndex = 0; segIndex < segCount; segIndex++) {
  32905. segments.push({ end: font.getUint16() });
  32906. }
  32907. font.getUint16();
  32908. for (segIndex = 0; segIndex < segCount; segIndex++) {
  32909. segments[segIndex].start = font.getUint16();
  32910. }
  32911. for (segIndex = 0; segIndex < segCount; segIndex++) {
  32912. segments[segIndex].delta = font.getUint16();
  32913. }
  32914. var offsetsCount = 0;
  32915. for (segIndex = 0; segIndex < segCount; segIndex++) {
  32916. segment = segments[segIndex];
  32917. var rangeOffset = font.getUint16();
  32918. if (!rangeOffset) {
  32919. segment.offsetIndex = -1;
  32920. continue;
  32921. }
  32922. var offsetIndex = (rangeOffset >> 1) - (segCount - segIndex);
  32923. segment.offsetIndex = offsetIndex;
  32924. offsetsCount = Math.max(offsetsCount, offsetIndex +
  32925. segment.end - segment.start + 1);
  32926. }
  32927. var offsets = [];
  32928. for (j = 0; j < offsetsCount; j++) {
  32929. offsets.push(font.getUint16());
  32930. }
  32931. for (segIndex = 0; segIndex < segCount; segIndex++) {
  32932. segment = segments[segIndex];
  32933. start = segment.start;
  32934. var end = segment.end;
  32935. var delta = segment.delta;
  32936. offsetIndex = segment.offsetIndex;
  32937. for (j = start; j <= end; j++) {
  32938. if (j === 0xFFFF) {
  32939. continue;
  32940. }
  32941. glyphId = (offsetIndex < 0 ?
  32942. j : offsets[offsetIndex + j - start]);
  32943. glyphId = (glyphId + delta) & 0xFFFF;
  32944. if (glyphId === 0) {
  32945. continue;
  32946. }
  32947. mappings.push({
  32948. charCode: j,
  32949. glyphId: glyphId
  32950. });
  32951. }
  32952. }
  32953. } else if (format === 6) {
  32954. // Format 6 is a 2-bytes dense mapping, which means the font data
  32955. // lives glue together even if they are pretty far in the unicode
  32956. // table. (This looks weird, so I can have missed something), this
  32957. // works on Linux but seems to fails on Mac so let's rewrite the
  32958. // cmap table to a 3-1-4 style
  32959. var firstCode = font.getUint16();
  32960. var entryCount = font.getUint16();
  32961. for (j = 0; j < entryCount; j++) {
  32962. glyphId = font.getUint16();
  32963. var charCode = firstCode + j;
  32964. mappings.push({
  32965. charCode: charCode,
  32966. glyphId: glyphId
  32967. });
  32968. }
  32969. } else {
  32970. warn('cmap table has unsupported format: ' + format);
  32971. return {
  32972. platformId: -1,
  32973. encodingId: -1,
  32974. mappings: [],
  32975. hasShortCmap: false
  32976. };
  32977. }
  32978. // removing duplicate entries
  32979. mappings.sort(function (a, b) {
  32980. return a.charCode - b.charCode;
  32981. });
  32982. for (i = 1; i < mappings.length; i++) {
  32983. if (mappings[i - 1].charCode === mappings[i].charCode) {
  32984. mappings.splice(i, 1);
  32985. i--;
  32986. }
  32987. }
  32988. return {
  32989. platformId: potentialTable.platformId,
  32990. encodingId: potentialTable.encodingId,
  32991. mappings: mappings,
  32992. hasShortCmap: hasShortCmap
  32993. };
  32994. }
  32995. function sanitizeMetrics(font, header, metrics, numGlyphs) {
  32996. if (!header) {
  32997. if (metrics) {
  32998. metrics.data = null;
  32999. }
  33000. return;
  33001. }
  33002. font.pos = (font.start ? font.start : 0) + header.offset;
  33003. font.pos += header.length - 2;
  33004. var numOfMetrics = font.getUint16();
  33005. if (numOfMetrics > numGlyphs) {
  33006. info('The numOfMetrics (' + numOfMetrics + ') should not be ' +
  33007. 'greater than the numGlyphs (' + numGlyphs + ')');
  33008. // Reduce numOfMetrics if it is greater than numGlyphs
  33009. numOfMetrics = numGlyphs;
  33010. header.data[34] = (numOfMetrics & 0xff00) >> 8;
  33011. header.data[35] = numOfMetrics & 0x00ff;
  33012. }
  33013. var numOfSidebearings = numGlyphs - numOfMetrics;
  33014. var numMissing = numOfSidebearings -
  33015. ((metrics.length - numOfMetrics * 4) >> 1);
  33016. if (numMissing > 0) {
  33017. // For each missing glyph, we set both the width and lsb to 0 (zero).
  33018. // Since we need to add two properties for each glyph, this explains
  33019. // the use of |numMissing * 2| when initializing the typed array.
  33020. var entries = new Uint8Array(metrics.length + numMissing * 2);
  33021. entries.set(metrics.data);
  33022. metrics.data = entries;
  33023. }
  33024. }
  33025. function sanitizeGlyph(source, sourceStart, sourceEnd, dest, destStart,
  33026. hintsValid) {
  33027. if (sourceEnd - sourceStart <= 12) {
  33028. // glyph with data less than 12 is invalid one
  33029. return 0;
  33030. }
  33031. var glyf = source.subarray(sourceStart, sourceEnd);
  33032. var contoursCount = (glyf[0] << 8) | glyf[1];
  33033. if (contoursCount & 0x8000) {
  33034. // complex glyph, writing as is
  33035. dest.set(glyf, destStart);
  33036. return glyf.length;
  33037. }
  33038. var i, j = 10, flagsCount = 0;
  33039. for (i = 0; i < contoursCount; i++) {
  33040. var endPoint = (glyf[j] << 8) | glyf[j + 1];
  33041. flagsCount = endPoint + 1;
  33042. j += 2;
  33043. }
  33044. // skipping instructions
  33045. var instructionsStart = j;
  33046. var instructionsLength = (glyf[j] << 8) | glyf[j + 1];
  33047. j += 2 + instructionsLength;
  33048. var instructionsEnd = j;
  33049. // validating flags
  33050. var coordinatesLength = 0;
  33051. for (i = 0; i < flagsCount; i++) {
  33052. var flag = glyf[j++];
  33053. if (flag & 0xC0) {
  33054. // reserved flags must be zero, cleaning up
  33055. glyf[j - 1] = flag & 0x3F;
  33056. }
  33057. var xyLength = ((flag & 2) ? 1 : (flag & 16) ? 0 : 2) +
  33058. ((flag & 4) ? 1 : (flag & 32) ? 0 : 2);
  33059. coordinatesLength += xyLength;
  33060. if (flag & 8) {
  33061. var repeat = glyf[j++];
  33062. i += repeat;
  33063. coordinatesLength += repeat * xyLength;
  33064. }
  33065. }
  33066. // glyph without coordinates will be rejected
  33067. if (coordinatesLength === 0) {
  33068. return 0;
  33069. }
  33070. var glyphDataLength = j + coordinatesLength;
  33071. if (glyphDataLength > glyf.length) {
  33072. // not enough data for coordinates
  33073. return 0;
  33074. }
  33075. if (!hintsValid && instructionsLength > 0) {
  33076. dest.set(glyf.subarray(0, instructionsStart), destStart);
  33077. dest.set([0, 0], destStart + instructionsStart);
  33078. dest.set(glyf.subarray(instructionsEnd, glyphDataLength),
  33079. destStart + instructionsStart + 2);
  33080. glyphDataLength -= instructionsLength;
  33081. if (glyf.length - glyphDataLength > 3) {
  33082. glyphDataLength = (glyphDataLength + 3) & ~3;
  33083. }
  33084. return glyphDataLength;
  33085. }
  33086. if (glyf.length - glyphDataLength > 3) {
  33087. // truncating and aligning to 4 bytes the long glyph data
  33088. glyphDataLength = (glyphDataLength + 3) & ~3;
  33089. dest.set(glyf.subarray(0, glyphDataLength), destStart);
  33090. return glyphDataLength;
  33091. }
  33092. // glyph data is fine
  33093. dest.set(glyf, destStart);
  33094. return glyf.length;
  33095. }
  33096. function sanitizeHead(head, numGlyphs, locaLength) {
  33097. var data = head.data;
  33098. // Validate version:
  33099. // Should always be 0x00010000
  33100. var version = int32(data[0], data[1], data[2], data[3]);
  33101. if (version >> 16 !== 1) {
  33102. info('Attempting to fix invalid version in head table: ' + version);
  33103. data[0] = 0;
  33104. data[1] = 1;
  33105. data[2] = 0;
  33106. data[3] = 0;
  33107. }
  33108. var indexToLocFormat = int16(data[50], data[51]);
  33109. if (indexToLocFormat < 0 || indexToLocFormat > 1) {
  33110. info('Attempting to fix invalid indexToLocFormat in head table: ' +
  33111. indexToLocFormat);
  33112. // The value of indexToLocFormat should be 0 if the loca table
  33113. // consists of short offsets, and should be 1 if the loca table
  33114. // consists of long offsets.
  33115. //
  33116. // The number of entries in the loca table should be numGlyphs + 1.
  33117. //
  33118. // Using this information, we can work backwards to deduce if the
  33119. // size of each offset in the loca table, and thus figure out the
  33120. // appropriate value for indexToLocFormat.
  33121. var numGlyphsPlusOne = numGlyphs + 1;
  33122. if (locaLength === numGlyphsPlusOne << 1) {
  33123. // 0x0000 indicates the loca table consists of short offsets
  33124. data[50] = 0;
  33125. data[51] = 0;
  33126. } else if (locaLength === numGlyphsPlusOne << 2) {
  33127. // 0x0001 indicates the loca table consists of long offsets
  33128. data[50] = 0;
  33129. data[51] = 1;
  33130. } else {
  33131. warn('Could not fix indexToLocFormat: ' + indexToLocFormat);
  33132. }
  33133. }
  33134. }
  33135. function sanitizeGlyphLocations(loca, glyf, numGlyphs,
  33136. isGlyphLocationsLong, hintsValid,
  33137. dupFirstEntry) {
  33138. var itemSize, itemDecode, itemEncode;
  33139. if (isGlyphLocationsLong) {
  33140. itemSize = 4;
  33141. itemDecode = function fontItemDecodeLong(data, offset) {
  33142. return (data[offset] << 24) | (data[offset + 1] << 16) |
  33143. (data[offset + 2] << 8) | data[offset + 3];
  33144. };
  33145. itemEncode = function fontItemEncodeLong(data, offset, value) {
  33146. data[offset] = (value >>> 24) & 0xFF;
  33147. data[offset + 1] = (value >> 16) & 0xFF;
  33148. data[offset + 2] = (value >> 8) & 0xFF;
  33149. data[offset + 3] = value & 0xFF;
  33150. };
  33151. } else {
  33152. itemSize = 2;
  33153. itemDecode = function fontItemDecode(data, offset) {
  33154. return (data[offset] << 9) | (data[offset + 1] << 1);
  33155. };
  33156. itemEncode = function fontItemEncode(data, offset, value) {
  33157. data[offset] = (value >> 9) & 0xFF;
  33158. data[offset + 1] = (value >> 1) & 0xFF;
  33159. };
  33160. }
  33161. var locaData = loca.data;
  33162. var locaDataSize = itemSize * (1 + numGlyphs);
  33163. // is loca.data too short or long?
  33164. if (locaData.length !== locaDataSize) {
  33165. locaData = new Uint8Array(locaDataSize);
  33166. locaData.set(loca.data.subarray(0, locaDataSize));
  33167. loca.data = locaData;
  33168. }
  33169. // removing the invalid glyphs
  33170. var oldGlyfData = glyf.data;
  33171. var oldGlyfDataLength = oldGlyfData.length;
  33172. var newGlyfData = new Uint8Array(oldGlyfDataLength);
  33173. var startOffset = itemDecode(locaData, 0);
  33174. var writeOffset = 0;
  33175. var missingGlyphData = {};
  33176. itemEncode(locaData, 0, writeOffset);
  33177. var i, j;
  33178. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  33179. var endOffset = itemDecode(locaData, j);
  33180. if (endOffset > oldGlyfDataLength &&
  33181. ((oldGlyfDataLength + 3) & ~3) === endOffset) {
  33182. // Aspose breaks fonts by aligning the glyphs to the qword, but not
  33183. // the glyf table size, which makes last glyph out of range.
  33184. endOffset = oldGlyfDataLength;
  33185. }
  33186. if (endOffset > oldGlyfDataLength) {
  33187. // glyph end offset points outside glyf data, rejecting the glyph
  33188. itemEncode(locaData, j, writeOffset);
  33189. startOffset = endOffset;
  33190. continue;
  33191. }
  33192. if (startOffset === endOffset) {
  33193. missingGlyphData[i] = true;
  33194. }
  33195. var newLength = sanitizeGlyph(oldGlyfData, startOffset, endOffset,
  33196. newGlyfData, writeOffset, hintsValid);
  33197. writeOffset += newLength;
  33198. itemEncode(locaData, j, writeOffset);
  33199. startOffset = endOffset;
  33200. }
  33201. if (writeOffset === 0) {
  33202. // glyf table cannot be empty -- redoing the glyf and loca tables
  33203. // to have single glyph with one point
  33204. var simpleGlyph = new Uint8Array(
  33205. [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 49, 0]);
  33206. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  33207. itemEncode(locaData, j, simpleGlyph.length);
  33208. }
  33209. glyf.data = simpleGlyph;
  33210. return missingGlyphData;
  33211. }
  33212. if (dupFirstEntry) {
  33213. var firstEntryLength = itemDecode(locaData, itemSize);
  33214. if (newGlyfData.length > firstEntryLength + writeOffset) {
  33215. glyf.data = newGlyfData.subarray(0, firstEntryLength + writeOffset);
  33216. } else {
  33217. glyf.data = new Uint8Array(firstEntryLength + writeOffset);
  33218. glyf.data.set(newGlyfData.subarray(0, writeOffset));
  33219. }
  33220. glyf.data.set(newGlyfData.subarray(0, firstEntryLength), writeOffset);
  33221. itemEncode(loca.data, locaData.length - itemSize,
  33222. writeOffset + firstEntryLength);
  33223. } else {
  33224. glyf.data = newGlyfData.subarray(0, writeOffset);
  33225. }
  33226. return missingGlyphData;
  33227. }
  33228. function readPostScriptTable(post, properties, maxpNumGlyphs) {
  33229. var start = (font.start ? font.start : 0) + post.offset;
  33230. font.pos = start;
  33231. var length = post.length, end = start + length;
  33232. var version = font.getInt32();
  33233. // skip rest to the tables
  33234. font.getBytes(28);
  33235. var glyphNames;
  33236. var valid = true;
  33237. var i;
  33238. switch (version) {
  33239. case 0x00010000:
  33240. glyphNames = MacStandardGlyphOrdering;
  33241. break;
  33242. case 0x00020000:
  33243. var numGlyphs = font.getUint16();
  33244. if (numGlyphs !== maxpNumGlyphs) {
  33245. valid = false;
  33246. break;
  33247. }
  33248. var glyphNameIndexes = [];
  33249. for (i = 0; i < numGlyphs; ++i) {
  33250. var index = font.getUint16();
  33251. if (index >= 32768) {
  33252. valid = false;
  33253. break;
  33254. }
  33255. glyphNameIndexes.push(index);
  33256. }
  33257. if (!valid) {
  33258. break;
  33259. }
  33260. var customNames = [];
  33261. var strBuf = [];
  33262. while (font.pos < end) {
  33263. var stringLength = font.getByte();
  33264. strBuf.length = stringLength;
  33265. for (i = 0; i < stringLength; ++i) {
  33266. strBuf[i] = String.fromCharCode(font.getByte());
  33267. }
  33268. customNames.push(strBuf.join(''));
  33269. }
  33270. glyphNames = [];
  33271. for (i = 0; i < numGlyphs; ++i) {
  33272. var j = glyphNameIndexes[i];
  33273. if (j < 258) {
  33274. glyphNames.push(MacStandardGlyphOrdering[j]);
  33275. continue;
  33276. }
  33277. glyphNames.push(customNames[j - 258]);
  33278. }
  33279. break;
  33280. case 0x00030000:
  33281. break;
  33282. default:
  33283. warn('Unknown/unsupported post table version ' + version);
  33284. valid = false;
  33285. if (properties.defaultEncoding) {
  33286. glyphNames = properties.defaultEncoding;
  33287. }
  33288. break;
  33289. }
  33290. properties.glyphNames = glyphNames;
  33291. return valid;
  33292. }
  33293. function readNameTable(nameTable) {
  33294. var start = (font.start ? font.start : 0) + nameTable.offset;
  33295. font.pos = start;
  33296. var names = [[], []];
  33297. var length = nameTable.length, end = start + length;
  33298. var format = font.getUint16();
  33299. var FORMAT_0_HEADER_LENGTH = 6;
  33300. if (format !== 0 || length < FORMAT_0_HEADER_LENGTH) {
  33301. // unsupported name table format or table "too" small
  33302. return names;
  33303. }
  33304. var numRecords = font.getUint16();
  33305. var stringsStart = font.getUint16();
  33306. var records = [];
  33307. var NAME_RECORD_LENGTH = 12;
  33308. var i, ii;
  33309. for (i = 0; i < numRecords &&
  33310. font.pos + NAME_RECORD_LENGTH <= end; i++) {
  33311. var r = {
  33312. platform: font.getUint16(),
  33313. encoding: font.getUint16(),
  33314. language: font.getUint16(),
  33315. name: font.getUint16(),
  33316. length: font.getUint16(),
  33317. offset: font.getUint16()
  33318. };
  33319. // using only Macintosh and Windows platform/encoding names
  33320. if ((r.platform === 1 && r.encoding === 0 && r.language === 0) ||
  33321. (r.platform === 3 && r.encoding === 1 && r.language === 0x409)) {
  33322. records.push(r);
  33323. }
  33324. }
  33325. for (i = 0, ii = records.length; i < ii; i++) {
  33326. var record = records[i];
  33327. var pos = start + stringsStart + record.offset;
  33328. if (pos + record.length > end) {
  33329. continue; // outside of name table, ignoring
  33330. }
  33331. font.pos = pos;
  33332. var nameIndex = record.name;
  33333. if (record.encoding) {
  33334. // unicode
  33335. var str = '';
  33336. for (var j = 0, jj = record.length; j < jj; j += 2) {
  33337. str += String.fromCharCode(font.getUint16());
  33338. }
  33339. names[1][nameIndex] = str;
  33340. } else {
  33341. names[0][nameIndex] = bytesToString(font.getBytes(record.length));
  33342. }
  33343. }
  33344. return names;
  33345. }
  33346. var TTOpsStackDeltas = [
  33347. 0, 0, 0, 0, 0, 0, 0, 0, -2, -2, -2, -2, 0, 0, -2, -5,
  33348. -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, -1, -1,
  33349. 1, -1, -999, 0, 1, 0, -1, -2, 0, -1, -2, -1, -1, 0, -1, -1,
  33350. 0, 0, -999, -999, -1, -1, -1, -1, -2, -999, -2, -2, -999, 0, -2, -2,
  33351. 0, 0, -2, 0, -2, 0, 0, 0, -2, -1, -1, 1, 1, 0, 0, -1,
  33352. -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, 0, -999, -1, -1,
  33353. -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  33354. -2, -999, -999, -999, -999, -999, -1, -1, -2, -2, 0, 0, 0, 0, -1, -1,
  33355. -999, -2, -2, 0, 0, -1, -2, -2, 0, 0, 0, -1, -1, -1, -2];
  33356. // 0xC0-DF == -1 and 0xE0-FF == -2
  33357. function sanitizeTTProgram(table, ttContext) {
  33358. var data = table.data;
  33359. var i = 0, j, n, b, funcId, pc, lastEndf = 0, lastDeff = 0;
  33360. var stack = [];
  33361. var callstack = [];
  33362. var functionsCalled = [];
  33363. var tooComplexToFollowFunctions =
  33364. ttContext.tooComplexToFollowFunctions;
  33365. var inFDEF = false, ifLevel = 0, inELSE = 0;
  33366. for (var ii = data.length; i < ii;) {
  33367. var op = data[i++];
  33368. // The TrueType instruction set docs can be found at
  33369. // https://developer.apple.com/fonts/TTRefMan/RM05/Chap5.html
  33370. if (op === 0x40) { // NPUSHB - pushes n bytes
  33371. n = data[i++];
  33372. if (inFDEF || inELSE) {
  33373. i += n;
  33374. } else {
  33375. for (j = 0; j < n; j++) {
  33376. stack.push(data[i++]);
  33377. }
  33378. }
  33379. } else if (op === 0x41) { // NPUSHW - pushes n words
  33380. n = data[i++];
  33381. if (inFDEF || inELSE) {
  33382. i += n * 2;
  33383. } else {
  33384. for (j = 0; j < n; j++) {
  33385. b = data[i++];
  33386. stack.push((b << 8) | data[i++]);
  33387. }
  33388. }
  33389. } else if ((op & 0xF8) === 0xB0) { // PUSHB - pushes bytes
  33390. n = op - 0xB0 + 1;
  33391. if (inFDEF || inELSE) {
  33392. i += n;
  33393. } else {
  33394. for (j = 0; j < n; j++) {
  33395. stack.push(data[i++]);
  33396. }
  33397. }
  33398. } else if ((op & 0xF8) === 0xB8) { // PUSHW - pushes words
  33399. n = op - 0xB8 + 1;
  33400. if (inFDEF || inELSE) {
  33401. i += n * 2;
  33402. } else {
  33403. for (j = 0; j < n; j++) {
  33404. b = data[i++];
  33405. stack.push((b << 8) | data[i++]);
  33406. }
  33407. }
  33408. } else if (op === 0x2B && !tooComplexToFollowFunctions) { // CALL
  33409. if (!inFDEF && !inELSE) {
  33410. // collecting inforamtion about which functions are used
  33411. funcId = stack[stack.length - 1];
  33412. ttContext.functionsUsed[funcId] = true;
  33413. if (funcId in ttContext.functionsStackDeltas) {
  33414. stack.length += ttContext.functionsStackDeltas[funcId];
  33415. } else if (funcId in ttContext.functionsDefined &&
  33416. functionsCalled.indexOf(funcId) < 0) {
  33417. callstack.push({data: data, i: i, stackTop: stack.length - 1});
  33418. functionsCalled.push(funcId);
  33419. pc = ttContext.functionsDefined[funcId];
  33420. if (!pc) {
  33421. warn('TT: CALL non-existent function');
  33422. ttContext.hintsValid = false;
  33423. return;
  33424. }
  33425. data = pc.data;
  33426. i = pc.i;
  33427. }
  33428. }
  33429. } else if (op === 0x2C && !tooComplexToFollowFunctions) { // FDEF
  33430. if (inFDEF || inELSE) {
  33431. warn('TT: nested FDEFs not allowed');
  33432. tooComplexToFollowFunctions = true;
  33433. }
  33434. inFDEF = true;
  33435. // collecting inforamtion about which functions are defined
  33436. lastDeff = i;
  33437. funcId = stack.pop();
  33438. ttContext.functionsDefined[funcId] = {data: data, i: i};
  33439. } else if (op === 0x2D) { // ENDF - end of function
  33440. if (inFDEF) {
  33441. inFDEF = false;
  33442. lastEndf = i;
  33443. } else {
  33444. pc = callstack.pop();
  33445. if (!pc) {
  33446. warn('TT: ENDF bad stack');
  33447. ttContext.hintsValid = false;
  33448. return;
  33449. }
  33450. funcId = functionsCalled.pop();
  33451. data = pc.data;
  33452. i = pc.i;
  33453. ttContext.functionsStackDeltas[funcId] =
  33454. stack.length - pc.stackTop;
  33455. }
  33456. } else if (op === 0x89) { // IDEF - instruction definition
  33457. if (inFDEF || inELSE) {
  33458. warn('TT: nested IDEFs not allowed');
  33459. tooComplexToFollowFunctions = true;
  33460. }
  33461. inFDEF = true;
  33462. // recording it as a function to track ENDF
  33463. lastDeff = i;
  33464. } else if (op === 0x58) { // IF
  33465. ++ifLevel;
  33466. } else if (op === 0x1B) { // ELSE
  33467. inELSE = ifLevel;
  33468. } else if (op === 0x59) { // EIF
  33469. if (inELSE === ifLevel) {
  33470. inELSE = 0;
  33471. }
  33472. --ifLevel;
  33473. } else if (op === 0x1C) { // JMPR
  33474. if (!inFDEF && !inELSE) {
  33475. var offset = stack[stack.length - 1];
  33476. // only jumping forward to prevent infinite loop
  33477. if (offset > 0) {
  33478. i += offset - 1;
  33479. }
  33480. }
  33481. }
  33482. // Adjusting stack not extactly, but just enough to get function id
  33483. if (!inFDEF && !inELSE) {
  33484. var stackDelta = op <= 0x8E ? TTOpsStackDeltas[op] :
  33485. op >= 0xC0 && op <= 0xDF ? -1 : op >= 0xE0 ? -2 : 0;
  33486. if (op >= 0x71 && op <= 0x75) {
  33487. n = stack.pop();
  33488. if (n === n) {
  33489. stackDelta = -n * 2;
  33490. }
  33491. }
  33492. while (stackDelta < 0 && stack.length > 0) {
  33493. stack.pop();
  33494. stackDelta++;
  33495. }
  33496. while (stackDelta > 0) {
  33497. stack.push(NaN); // pushing any number into stack
  33498. stackDelta--;
  33499. }
  33500. }
  33501. }
  33502. ttContext.tooComplexToFollowFunctions = tooComplexToFollowFunctions;
  33503. var content = [data];
  33504. if (i > data.length) {
  33505. content.push(new Uint8Array(i - data.length));
  33506. }
  33507. if (lastDeff > lastEndf) {
  33508. warn('TT: complementing a missing function tail');
  33509. // new function definition started, but not finished
  33510. // complete function by [CLEAR, ENDF]
  33511. content.push(new Uint8Array([0x22, 0x2D]));
  33512. }
  33513. foldTTTable(table, content);
  33514. }
  33515. function checkInvalidFunctions(ttContext, maxFunctionDefs) {
  33516. if (ttContext.tooComplexToFollowFunctions) {
  33517. return;
  33518. }
  33519. if (ttContext.functionsDefined.length > maxFunctionDefs) {
  33520. warn('TT: more functions defined than expected');
  33521. ttContext.hintsValid = false;
  33522. return;
  33523. }
  33524. for (var j = 0, jj = ttContext.functionsUsed.length; j < jj; j++) {
  33525. if (j > maxFunctionDefs) {
  33526. warn('TT: invalid function id: ' + j);
  33527. ttContext.hintsValid = false;
  33528. return;
  33529. }
  33530. if (ttContext.functionsUsed[j] && !ttContext.functionsDefined[j]) {
  33531. warn('TT: undefined function: ' + j);
  33532. ttContext.hintsValid = false;
  33533. return;
  33534. }
  33535. }
  33536. }
  33537. function foldTTTable(table, content) {
  33538. if (content.length > 1) {
  33539. // concatenating the content items
  33540. var newLength = 0;
  33541. var j, jj;
  33542. for (j = 0, jj = content.length; j < jj; j++) {
  33543. newLength += content[j].length;
  33544. }
  33545. newLength = (newLength + 3) & ~3;
  33546. var result = new Uint8Array(newLength);
  33547. var pos = 0;
  33548. for (j = 0, jj = content.length; j < jj; j++) {
  33549. result.set(content[j], pos);
  33550. pos += content[j].length;
  33551. }
  33552. table.data = result;
  33553. table.length = newLength;
  33554. }
  33555. }
  33556. function sanitizeTTPrograms(fpgm, prep, cvt) {
  33557. var ttContext = {
  33558. functionsDefined: [],
  33559. functionsUsed: [],
  33560. functionsStackDeltas: [],
  33561. tooComplexToFollowFunctions: false,
  33562. hintsValid: true
  33563. };
  33564. if (fpgm) {
  33565. sanitizeTTProgram(fpgm, ttContext);
  33566. }
  33567. if (prep) {
  33568. sanitizeTTProgram(prep, ttContext);
  33569. }
  33570. if (fpgm) {
  33571. checkInvalidFunctions(ttContext, maxFunctionDefs);
  33572. }
  33573. if (cvt && (cvt.length & 1)) {
  33574. var cvtData = new Uint8Array(cvt.length + 1);
  33575. cvtData.set(cvt.data);
  33576. cvt.data = cvtData;
  33577. }
  33578. return ttContext.hintsValid;
  33579. }
  33580. // The following steps modify the original font data, making copy
  33581. font = new Stream(new Uint8Array(font.getBytes()));
  33582. var VALID_TABLES = ['OS/2', 'cmap', 'head', 'hhea', 'hmtx', 'maxp',
  33583. 'name', 'post', 'loca', 'glyf', 'fpgm', 'prep', 'cvt ', 'CFF '];
  33584. var header = readOpenTypeHeader(font);
  33585. var numTables = header.numTables;
  33586. var cff, cffFile;
  33587. var tables = { 'OS/2': null, cmap: null, head: null, hhea: null,
  33588. hmtx: null, maxp: null, name: null, post: null };
  33589. var table;
  33590. for (var i = 0; i < numTables; i++) {
  33591. table = readTableEntry(font);
  33592. if (VALID_TABLES.indexOf(table.tag) < 0) {
  33593. continue; // skipping table if it's not a required or optional table
  33594. }
  33595. if (table.length === 0) {
  33596. continue; // skipping empty tables
  33597. }
  33598. tables[table.tag] = table;
  33599. }
  33600. var isTrueType = !tables['CFF '];
  33601. if (!isTrueType) {
  33602. // OpenType font
  33603. if ((header.version === 'OTTO' && properties.type !== 'CIDFontType2') ||
  33604. !tables.head || !tables.hhea || !tables.maxp || !tables.post) {
  33605. // no major tables: throwing everything at CFFFont
  33606. cffFile = new Stream(tables['CFF '].data);
  33607. cff = new CFFFont(cffFile, properties);
  33608. adjustWidths(properties);
  33609. return this.convert(name, cff, properties);
  33610. }
  33611. delete tables.glyf;
  33612. delete tables.loca;
  33613. delete tables.fpgm;
  33614. delete tables.prep;
  33615. delete tables['cvt '];
  33616. this.isOpenType = true;
  33617. } else {
  33618. if (!tables.glyf || !tables.loca) {
  33619. error('Required "glyf" or "loca" tables are not found');
  33620. }
  33621. this.isOpenType = false;
  33622. }
  33623. if (!tables.maxp) {
  33624. error('Required "maxp" table is not found');
  33625. }
  33626. font.pos = (font.start || 0) + tables.maxp.offset;
  33627. var version = font.getInt32();
  33628. var numGlyphs = font.getUint16();
  33629. var maxFunctionDefs = 0;
  33630. if (version >= 0x00010000 && tables.maxp.length >= 22) {
  33631. // maxZones can be invalid
  33632. font.pos += 8;
  33633. var maxZones = font.getUint16();
  33634. if (maxZones > 2) { // reset to 2 if font has invalid maxZones
  33635. tables.maxp.data[14] = 0;
  33636. tables.maxp.data[15] = 2;
  33637. }
  33638. font.pos += 4;
  33639. maxFunctionDefs = font.getUint16();
  33640. }
  33641. var dupFirstEntry = false;
  33642. if (properties.type === 'CIDFontType2' && properties.toUnicode &&
  33643. properties.toUnicode.get(0) > '\u0000') {
  33644. // oracle's defect (see 3427), duplicating first entry
  33645. dupFirstEntry = true;
  33646. numGlyphs++;
  33647. tables.maxp.data[4] = numGlyphs >> 8;
  33648. tables.maxp.data[5] = numGlyphs & 255;
  33649. }
  33650. var hintsValid = sanitizeTTPrograms(tables.fpgm, tables.prep,
  33651. tables['cvt '], maxFunctionDefs);
  33652. if (!hintsValid) {
  33653. delete tables.fpgm;
  33654. delete tables.prep;
  33655. delete tables['cvt '];
  33656. }
  33657. // Ensure the hmtx table contains the advance width and
  33658. // sidebearings information for numGlyphs in the maxp table
  33659. sanitizeMetrics(font, tables.hhea, tables.hmtx, numGlyphs);
  33660. if (!tables.head) {
  33661. error('Required "head" table is not found');
  33662. }
  33663. sanitizeHead(tables.head, numGlyphs, isTrueType ? tables.loca.length : 0);
  33664. var missingGlyphs = {};
  33665. if (isTrueType) {
  33666. var isGlyphLocationsLong = int16(tables.head.data[50],
  33667. tables.head.data[51]);
  33668. missingGlyphs = sanitizeGlyphLocations(tables.loca, tables.glyf,
  33669. numGlyphs, isGlyphLocationsLong,
  33670. hintsValid, dupFirstEntry);
  33671. }
  33672. if (!tables.hhea) {
  33673. error('Required "hhea" table is not found');
  33674. }
  33675. // Sanitizer reduces the glyph advanceWidth to the maxAdvanceWidth
  33676. // Sometimes it's 0. That needs to be fixed
  33677. if (tables.hhea.data[10] === 0 && tables.hhea.data[11] === 0) {
  33678. tables.hhea.data[10] = 0xFF;
  33679. tables.hhea.data[11] = 0xFF;
  33680. }
  33681. // Extract some more font properties from the OpenType head and
  33682. // hhea tables; yMin and descent value are always negative.
  33683. var metricsOverride = {
  33684. unitsPerEm: int16(tables.head.data[18], tables.head.data[19]),
  33685. yMax: int16(tables.head.data[42], tables.head.data[43]),
  33686. yMin: int16(tables.head.data[38], tables.head.data[39]) - 0x10000,
  33687. ascent: int16(tables.hhea.data[4], tables.hhea.data[5]),
  33688. descent: int16(tables.hhea.data[6], tables.hhea.data[7]) - 0x10000
  33689. };
  33690. // PDF FontDescriptor metrics lie -- using data from actual font.
  33691. this.ascent = metricsOverride.ascent / metricsOverride.unitsPerEm;
  33692. this.descent = metricsOverride.descent / metricsOverride.unitsPerEm;
  33693. // The 'post' table has glyphs names.
  33694. if (tables.post) {
  33695. var valid = readPostScriptTable(tables.post, properties, numGlyphs);
  33696. if (!valid) {
  33697. tables.post = null;
  33698. }
  33699. }
  33700. var charCodeToGlyphId = [], charCode;
  33701. var toUnicode = properties.toUnicode, widths = properties.widths;
  33702. var skipToUnicode = (toUnicode instanceof IdentityToUnicodeMap ||
  33703. toUnicode.length === 0x10000);
  33704. // Helper function to try to skip mapping of empty glyphs.
  33705. // Note: In some cases, just relying on the glyph data doesn't work,
  33706. // hence we also use a few heuristics to fix various PDF files.
  33707. function hasGlyph(glyphId, charCode, widthCode) {
  33708. if (!missingGlyphs[glyphId]) {
  33709. return true;
  33710. }
  33711. if (!skipToUnicode && charCode >= 0 && toUnicode.has(charCode)) {
  33712. return true;
  33713. }
  33714. if (widths && widthCode >= 0 && isNum(widths[widthCode])) {
  33715. return true;
  33716. }
  33717. return false;
  33718. }
  33719. if (properties.type === 'CIDFontType2') {
  33720. var cidToGidMap = properties.cidToGidMap || [];
  33721. var isCidToGidMapEmpty = cidToGidMap.length === 0;
  33722. properties.cMap.forEach(function(charCode, cid) {
  33723. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  33724. var glyphId = -1;
  33725. if (isCidToGidMapEmpty) {
  33726. glyphId = charCode;
  33727. } else if (cidToGidMap[cid] !== undefined) {
  33728. glyphId = cidToGidMap[cid];
  33729. }
  33730. if (glyphId >= 0 && glyphId < numGlyphs &&
  33731. hasGlyph(glyphId, charCode, cid)) {
  33732. charCodeToGlyphId[charCode] = glyphId;
  33733. }
  33734. });
  33735. if (dupFirstEntry) {
  33736. charCodeToGlyphId[0] = numGlyphs - 1;
  33737. }
  33738. } else {
  33739. // Most of the following logic in this code branch is based on the
  33740. // 9.6.6.4 of the PDF spec.
  33741. var hasEncoding =
  33742. properties.differences.length > 0 || !!properties.baseEncodingName;
  33743. var cmapTable =
  33744. readCmapTable(tables.cmap, font, this.isSymbolicFont, hasEncoding);
  33745. var cmapPlatformId = cmapTable.platformId;
  33746. var cmapEncodingId = cmapTable.encodingId;
  33747. var cmapMappings = cmapTable.mappings;
  33748. var cmapMappingsLength = cmapMappings.length;
  33749. // The spec seems to imply that if the font is symbolic the encoding
  33750. // should be ignored, this doesn't appear to work for 'preistabelle.pdf'
  33751. // where the the font is symbolic and it has an encoding.
  33752. if (hasEncoding &&
  33753. (cmapPlatformId === 3 && cmapEncodingId === 1 ||
  33754. cmapPlatformId === 1 && cmapEncodingId === 0) ||
  33755. (cmapPlatformId === -1 && cmapEncodingId === -1 && // Temporary hack
  33756. !!Encodings[properties.baseEncodingName])) { // Temporary hack
  33757. // When no preferred cmap table was found and |baseEncodingName| is
  33758. // one of the predefined encodings, we seem to obtain a better
  33759. // |charCodeToGlyphId| map from the code below (fixes bug 1057544).
  33760. // TODO: Note that this is a hack which should be removed as soon as
  33761. // we have proper support for more exotic cmap tables.
  33762. var baseEncoding = [];
  33763. if (properties.baseEncodingName === 'MacRomanEncoding' ||
  33764. properties.baseEncodingName === 'WinAnsiEncoding') {
  33765. baseEncoding = Encodings[properties.baseEncodingName];
  33766. }
  33767. for (charCode = 0; charCode < 256; charCode++) {
  33768. var glyphName;
  33769. if (this.differences && charCode in this.differences) {
  33770. glyphName = this.differences[charCode];
  33771. } else if (charCode in baseEncoding &&
  33772. baseEncoding[charCode] !== '') {
  33773. glyphName = baseEncoding[charCode];
  33774. } else {
  33775. glyphName = Encodings.StandardEncoding[charCode];
  33776. }
  33777. if (!glyphName) {
  33778. continue;
  33779. }
  33780. var unicodeOrCharCode, isUnicode = false;
  33781. if (cmapPlatformId === 3 && cmapEncodingId === 1) {
  33782. unicodeOrCharCode = GlyphsUnicode[glyphName];
  33783. isUnicode = true;
  33784. } else if (cmapPlatformId === 1 && cmapEncodingId === 0) {
  33785. // TODO: the encoding needs to be updated with mac os table.
  33786. unicodeOrCharCode = Encodings.MacRomanEncoding.indexOf(glyphName);
  33787. }
  33788. var found = false;
  33789. for (i = 0; i < cmapMappingsLength; ++i) {
  33790. if (cmapMappings[i].charCode !== unicodeOrCharCode) {
  33791. continue;
  33792. }
  33793. var code = isUnicode ? charCode : unicodeOrCharCode;
  33794. if (hasGlyph(cmapMappings[i].glyphId, code, -1)) {
  33795. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  33796. found = true;
  33797. break;
  33798. }
  33799. }
  33800. if (!found && properties.glyphNames) {
  33801. // Try to map using the post table.
  33802. var glyphId = properties.glyphNames.indexOf(glyphName);
  33803. if (glyphId > 0 && hasGlyph(glyphId, -1, -1)) {
  33804. charCodeToGlyphId[charCode] = glyphId;
  33805. } else {
  33806. charCodeToGlyphId[charCode] = 0; // notdef
  33807. }
  33808. }
  33809. }
  33810. } else if (cmapPlatformId === 0 && cmapEncodingId === 0) {
  33811. // Default Unicode semantics, use the charcodes as is.
  33812. for (i = 0; i < cmapMappingsLength; ++i) {
  33813. charCodeToGlyphId[cmapMappings[i].charCode] =
  33814. cmapMappings[i].glyphId;
  33815. }
  33816. } else {
  33817. // For (3, 0) cmap tables:
  33818. // The charcode key being stored in charCodeToGlyphId is the lower
  33819. // byte of the two-byte charcodes of the cmap table since according to
  33820. // the spec: 'each byte from the string shall be prepended with the
  33821. // high byte of the range [of charcodes in the cmap table], to form
  33822. // a two-byte character, which shall be used to select the
  33823. // associated glyph description from the subtable'.
  33824. //
  33825. // For (1, 0) cmap tables:
  33826. // 'single bytes from the string shall be used to look up the
  33827. // associated glyph descriptions from the subtable'. This means
  33828. // charcodes in the cmap will be single bytes, so no-op since
  33829. // glyph.charCode & 0xFF === glyph.charCode
  33830. for (i = 0; i < cmapMappingsLength; ++i) {
  33831. charCode = cmapMappings[i].charCode & 0xFF;
  33832. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  33833. }
  33834. }
  33835. }
  33836. if (charCodeToGlyphId.length === 0) {
  33837. // defines at least one glyph
  33838. charCodeToGlyphId[0] = 0;
  33839. }
  33840. // Converting glyphs and ids into font's cmap table
  33841. var newMapping = adjustMapping(charCodeToGlyphId, properties);
  33842. this.toFontChar = newMapping.toFontChar;
  33843. tables.cmap = {
  33844. tag: 'cmap',
  33845. data: createCmapTable(newMapping.charCodeToGlyphId, numGlyphs)
  33846. };
  33847. if (!tables['OS/2'] || !validateOS2Table(tables['OS/2'])) {
  33848. tables['OS/2'] = {
  33849. tag: 'OS/2',
  33850. data: createOS2Table(properties, newMapping.charCodeToGlyphId,
  33851. metricsOverride)
  33852. };
  33853. }
  33854. // Rewrite the 'post' table if needed
  33855. if (!tables.post) {
  33856. tables.post = {
  33857. tag: 'post',
  33858. data: createPostTable(properties)
  33859. };
  33860. }
  33861. if (!isTrueType) {
  33862. try {
  33863. // Trying to repair CFF file
  33864. cffFile = new Stream(tables['CFF '].data);
  33865. var parser = new CFFParser(cffFile, properties);
  33866. cff = parser.parse();
  33867. var compiler = new CFFCompiler(cff);
  33868. tables['CFF '].data = compiler.compile();
  33869. } catch (e) {
  33870. warn('Failed to compile font ' + properties.loadedName);
  33871. }
  33872. }
  33873. // Re-creating 'name' table
  33874. if (!tables.name) {
  33875. tables.name = {
  33876. tag: 'name',
  33877. data: createNameTable(this.name)
  33878. };
  33879. } else {
  33880. // ... using existing 'name' table as prototype
  33881. var namePrototype = readNameTable(tables.name);
  33882. tables.name.data = createNameTable(name, namePrototype);
  33883. }
  33884. var builder = new OpenTypeFileBuilder(header.version);
  33885. for (var tableTag in tables) {
  33886. builder.addTable(tableTag, tables[tableTag].data);
  33887. }
  33888. return builder.toArray();
  33889. },
  33890. convert: function Font_convert(fontName, font, properties) {
  33891. // TODO: Check the charstring widths to determine this.
  33892. properties.fixedPitch = false;
  33893. var mapping = font.getGlyphMapping(properties);
  33894. var newMapping = adjustMapping(mapping, properties);
  33895. this.toFontChar = newMapping.toFontChar;
  33896. var numGlyphs = font.numGlyphs;
  33897. function getCharCodes(charCodeToGlyphId, glyphId) {
  33898. var charCodes = null;
  33899. for (var charCode in charCodeToGlyphId) {
  33900. if (glyphId === charCodeToGlyphId[charCode]) {
  33901. if (!charCodes) {
  33902. charCodes = [];
  33903. }
  33904. charCodes.push(charCode | 0);
  33905. }
  33906. }
  33907. return charCodes;
  33908. }
  33909. function createCharCode(charCodeToGlyphId, glyphId) {
  33910. for (var charCode in charCodeToGlyphId) {
  33911. if (glyphId === charCodeToGlyphId[charCode]) {
  33912. return charCode | 0;
  33913. }
  33914. }
  33915. newMapping.charCodeToGlyphId[newMapping.nextAvailableFontCharCode] =
  33916. glyphId;
  33917. return newMapping.nextAvailableFontCharCode++;
  33918. }
  33919. var seacs = font.seacs;
  33920. if (SEAC_ANALYSIS_ENABLED && seacs && seacs.length) {
  33921. var matrix = properties.fontMatrix || FONT_IDENTITY_MATRIX;
  33922. var charset = font.getCharset();
  33923. var seacMap = Object.create(null);
  33924. for (var glyphId in seacs) {
  33925. glyphId |= 0;
  33926. var seac = seacs[glyphId];
  33927. var baseGlyphName = Encodings.StandardEncoding[seac[2]];
  33928. var accentGlyphName = Encodings.StandardEncoding[seac[3]];
  33929. var baseGlyphId = charset.indexOf(baseGlyphName);
  33930. var accentGlyphId = charset.indexOf(accentGlyphName);
  33931. if (baseGlyphId < 0 || accentGlyphId < 0) {
  33932. continue;
  33933. }
  33934. var accentOffset = {
  33935. x: seac[0] * matrix[0] + seac[1] * matrix[2] + matrix[4],
  33936. y: seac[0] * matrix[1] + seac[1] * matrix[3] + matrix[5]
  33937. };
  33938. var charCodes = getCharCodes(mapping, glyphId);
  33939. if (!charCodes) {
  33940. // There's no point in mapping it if the char code was never mapped
  33941. // to begin with.
  33942. continue;
  33943. }
  33944. for (var i = 0, ii = charCodes.length; i < ii; i++) {
  33945. var charCode = charCodes[i];
  33946. // Find a fontCharCode that maps to the base and accent glyphs.
  33947. // If one doesn't exists, create it.
  33948. var charCodeToGlyphId = newMapping.charCodeToGlyphId;
  33949. var baseFontCharCode = createCharCode(charCodeToGlyphId,
  33950. baseGlyphId);
  33951. var accentFontCharCode = createCharCode(charCodeToGlyphId,
  33952. accentGlyphId);
  33953. seacMap[charCode] = {
  33954. baseFontCharCode: baseFontCharCode,
  33955. accentFontCharCode: accentFontCharCode,
  33956. accentOffset: accentOffset
  33957. };
  33958. }
  33959. }
  33960. properties.seacMap = seacMap;
  33961. }
  33962. var unitsPerEm = 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0];
  33963. var builder = new OpenTypeFileBuilder('\x4F\x54\x54\x4F');
  33964. // PostScript Font Program
  33965. builder.addTable('CFF ', font.data);
  33966. // OS/2 and Windows Specific metrics
  33967. builder.addTable('OS/2', createOS2Table(properties,
  33968. newMapping.charCodeToGlyphId));
  33969. // Character to glyphs mapping
  33970. builder.addTable('cmap', createCmapTable(newMapping.charCodeToGlyphId,
  33971. numGlyphs));
  33972. // Font header
  33973. builder.addTable('head',
  33974. '\x00\x01\x00\x00' + // Version number
  33975. '\x00\x00\x10\x00' + // fontRevision
  33976. '\x00\x00\x00\x00' + // checksumAdjustement
  33977. '\x5F\x0F\x3C\xF5' + // magicNumber
  33978. '\x00\x00' + // Flags
  33979. safeString16(unitsPerEm) + // unitsPerEM
  33980. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // creation date
  33981. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // modifification date
  33982. '\x00\x00' + // xMin
  33983. safeString16(properties.descent) + // yMin
  33984. '\x0F\xFF' + // xMax
  33985. safeString16(properties.ascent) + // yMax
  33986. string16(properties.italicAngle ? 2 : 0) + // macStyle
  33987. '\x00\x11' + // lowestRecPPEM
  33988. '\x00\x00' + // fontDirectionHint
  33989. '\x00\x00' + // indexToLocFormat
  33990. '\x00\x00'); // glyphDataFormat
  33991. // Horizontal header
  33992. builder.addTable('hhea',
  33993. '\x00\x01\x00\x00' + // Version number
  33994. safeString16(properties.ascent) + // Typographic Ascent
  33995. safeString16(properties.descent) + // Typographic Descent
  33996. '\x00\x00' + // Line Gap
  33997. '\xFF\xFF' + // advanceWidthMax
  33998. '\x00\x00' + // minLeftSidebearing
  33999. '\x00\x00' + // minRightSidebearing
  34000. '\x00\x00' + // xMaxExtent
  34001. safeString16(properties.capHeight) + // caretSlopeRise
  34002. safeString16(Math.tan(properties.italicAngle) *
  34003. properties.xHeight) + // caretSlopeRun
  34004. '\x00\x00' + // caretOffset
  34005. '\x00\x00' + // -reserved-
  34006. '\x00\x00' + // -reserved-
  34007. '\x00\x00' + // -reserved-
  34008. '\x00\x00' + // -reserved-
  34009. '\x00\x00' + // metricDataFormat
  34010. string16(numGlyphs)); // Number of HMetrics
  34011. // Horizontal metrics
  34012. builder.addTable('hmtx', (function fontFieldsHmtx() {
  34013. var charstrings = font.charstrings;
  34014. var cffWidths = font.cff ? font.cff.widths : null;
  34015. var hmtx = '\x00\x00\x00\x00'; // Fake .notdef
  34016. for (var i = 1, ii = numGlyphs; i < ii; i++) {
  34017. var width = 0;
  34018. if (charstrings) {
  34019. var charstring = charstrings[i - 1];
  34020. width = 'width' in charstring ? charstring.width : 0;
  34021. } else if (cffWidths) {
  34022. width = Math.ceil(cffWidths[i] || 0);
  34023. }
  34024. hmtx += string16(width) + string16(0);
  34025. }
  34026. return hmtx;
  34027. })());
  34028. // Maximum profile
  34029. builder.addTable('maxp',
  34030. '\x00\x00\x50\x00' + // Version number
  34031. string16(numGlyphs)); // Num of glyphs
  34032. // Naming tables
  34033. builder.addTable('name', createNameTable(fontName));
  34034. // PostScript informations
  34035. builder.addTable('post', createPostTable(properties));
  34036. return builder.toArray();
  34037. },
  34038. /**
  34039. * Builds a char code to unicode map based on section 9.10 of the spec.
  34040. * @param {Object} properties Font properties object.
  34041. * @return {Object} A ToUnicodeMap object.
  34042. */
  34043. buildToUnicode: function Font_buildToUnicode(properties) {
  34044. // Section 9.10.2 Mapping Character Codes to Unicode Values
  34045. if (properties.toUnicode && properties.toUnicode.length !== 0) {
  34046. return properties.toUnicode;
  34047. }
  34048. // According to the spec if the font is a simple font we should only map
  34049. // to unicode if the base encoding is MacRoman, MacExpert, or WinAnsi or
  34050. // the differences array only contains adobe standard or symbol set names,
  34051. // in pratice it seems better to always try to create a toUnicode
  34052. // map based of the default encoding.
  34053. var toUnicode, charcode;
  34054. if (!properties.composite /* is simple font */) {
  34055. toUnicode = [];
  34056. var encoding = properties.defaultEncoding.slice();
  34057. var baseEncodingName = properties.baseEncodingName;
  34058. // Merge in the differences array.
  34059. var differences = properties.differences;
  34060. for (charcode in differences) {
  34061. encoding[charcode] = differences[charcode];
  34062. }
  34063. for (charcode in encoding) {
  34064. // a) Map the character code to a character name.
  34065. var glyphName = encoding[charcode];
  34066. // b) Look up the character name in the Adobe Glyph List (see the
  34067. // Bibliography) to obtain the corresponding Unicode value.
  34068. if (glyphName === '') {
  34069. continue;
  34070. } else if (GlyphsUnicode[glyphName] === undefined) {
  34071. // (undocumented) c) Few heuristics to recognize unknown glyphs
  34072. // NOTE: Adobe Reader does not do this step, but OSX Preview does
  34073. var code = 0;
  34074. switch (glyphName[0]) {
  34075. case 'G': // Gxx glyph
  34076. if (glyphName.length === 3) {
  34077. code = parseInt(glyphName.substr(1), 16);
  34078. }
  34079. break;
  34080. case 'g': // g00xx glyph
  34081. if (glyphName.length === 5) {
  34082. code = parseInt(glyphName.substr(1), 16);
  34083. }
  34084. break;
  34085. case 'C': // Cddd glyph
  34086. case 'c': // cddd glyph
  34087. if (glyphName.length >= 3) {
  34088. code = +glyphName.substr(1);
  34089. }
  34090. break;
  34091. }
  34092. if (code) {
  34093. // If |baseEncodingName| is one the predefined encodings,
  34094. // and |code| equals |charcode|, using the glyph defined in the
  34095. // baseEncoding seems to yield a better |toUnicode| mapping
  34096. // (fixes issue 5070).
  34097. if (baseEncodingName && code === +charcode) {
  34098. var baseEncoding = Encodings[baseEncodingName];
  34099. if (baseEncoding && (glyphName = baseEncoding[charcode])) {
  34100. toUnicode[charcode] =
  34101. String.fromCharCode(GlyphsUnicode[glyphName]);
  34102. continue;
  34103. }
  34104. }
  34105. toUnicode[charcode] = String.fromCharCode(code);
  34106. }
  34107. continue;
  34108. }
  34109. toUnicode[charcode] = String.fromCharCode(GlyphsUnicode[glyphName]);
  34110. }
  34111. return new ToUnicodeMap(toUnicode);
  34112. }
  34113. // If the font is a composite font that uses one of the predefined CMaps
  34114. // listed in Table 118 (except Identity–H and Identity–V) or whose
  34115. // descendant CIDFont uses the Adobe-GB1, Adobe-CNS1, Adobe-Japan1, or
  34116. // Adobe-Korea1 character collection:
  34117. if (properties.composite && (
  34118. (properties.cMap.builtInCMap &&
  34119. !(properties.cMap instanceof IdentityCMap)) ||
  34120. (properties.cidSystemInfo.registry === 'Adobe' &&
  34121. (properties.cidSystemInfo.ordering === 'GB1' ||
  34122. properties.cidSystemInfo.ordering === 'CNS1' ||
  34123. properties.cidSystemInfo.ordering === 'Japan1' ||
  34124. properties.cidSystemInfo.ordering === 'Korea1')))) {
  34125. // Then:
  34126. // a) Map the character code to a character identifier (CID) according
  34127. // to the font’s CMap.
  34128. // b) Obtain the registry and ordering of the character collection used
  34129. // by the font’s CMap (for example, Adobe and Japan1) from its
  34130. // CIDSystemInfo dictionary.
  34131. var registry = properties.cidSystemInfo.registry;
  34132. var ordering = properties.cidSystemInfo.ordering;
  34133. // c) Construct a second CMap name by concatenating the registry and
  34134. // ordering obtained in step (b) in the format registry–ordering–UCS2
  34135. // (for example, Adobe–Japan1–UCS2).
  34136. var ucs2CMapName = new Name(registry + '-' + ordering + '-UCS2');
  34137. // d) Obtain the CMap with the name constructed in step (c) (available
  34138. // from the ASN Web site; see the Bibliography).
  34139. var ucs2CMap = CMapFactory.create(ucs2CMapName,
  34140. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  34141. var cMap = properties.cMap;
  34142. toUnicode = [];
  34143. cMap.forEach(function(charcode, cid) {
  34144. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  34145. // e) Map the CID obtained in step (a) according to the CMap obtained
  34146. // in step (d), producing a Unicode value.
  34147. var ucs2 = ucs2CMap.lookup(cid);
  34148. if (ucs2) {
  34149. toUnicode[charcode] =
  34150. String.fromCharCode((ucs2.charCodeAt(0) << 8) +
  34151. ucs2.charCodeAt(1));
  34152. }
  34153. });
  34154. return new ToUnicodeMap(toUnicode);
  34155. }
  34156. // The viewer's choice, just use an identity map.
  34157. return new IdentityToUnicodeMap(properties.firstChar,
  34158. properties.lastChar);
  34159. },
  34160. get spaceWidth() {
  34161. if ('_shadowWidth' in this) {
  34162. return this._shadowWidth;
  34163. }
  34164. // trying to estimate space character width
  34165. var possibleSpaceReplacements = ['space', 'minus', 'one', 'i'];
  34166. var width;
  34167. for (var i = 0, ii = possibleSpaceReplacements.length; i < ii; i++) {
  34168. var glyphName = possibleSpaceReplacements[i];
  34169. // if possible, getting width by glyph name
  34170. if (glyphName in this.widths) {
  34171. width = this.widths[glyphName];
  34172. break;
  34173. }
  34174. var glyphUnicode = GlyphsUnicode[glyphName];
  34175. // finding the charcode via unicodeToCID map
  34176. var charcode = 0;
  34177. if (this.composite) {
  34178. if (this.cMap.contains(glyphUnicode)) {
  34179. charcode = this.cMap.lookup(glyphUnicode);
  34180. }
  34181. }
  34182. // ... via toUnicode map
  34183. if (!charcode && this.toUnicode) {
  34184. charcode = this.toUnicode.charCodeOf(glyphUnicode);
  34185. }
  34186. // setting it to unicode if negative or undefined
  34187. if (charcode <= 0) {
  34188. charcode = glyphUnicode;
  34189. }
  34190. // trying to get width via charcode
  34191. width = this.widths[charcode];
  34192. if (width) {
  34193. break; // the non-zero width found
  34194. }
  34195. }
  34196. width = width || this.defaultWidth;
  34197. // Do not shadow the property here. See discussion:
  34198. // https://github.com/mozilla/pdf.js/pull/2127#discussion_r1662280
  34199. this._shadowWidth = width;
  34200. return width;
  34201. },
  34202. charToGlyph: function Font_charToGlyph(charcode, isSpace) {
  34203. var fontCharCode, width, operatorListId;
  34204. var widthCode = charcode;
  34205. if (this.cMap && this.cMap.contains(charcode)) {
  34206. widthCode = this.cMap.lookup(charcode);
  34207. }
  34208. width = this.widths[widthCode];
  34209. width = isNum(width) ? width : this.defaultWidth;
  34210. var vmetric = this.vmetrics && this.vmetrics[widthCode];
  34211. var unicode = this.toUnicode.get(charcode) || charcode;
  34212. if (typeof unicode === 'number') {
  34213. unicode = String.fromCharCode(unicode);
  34214. }
  34215. // First try the toFontChar map, if it's not there then try falling
  34216. // back to the char code.
  34217. fontCharCode = this.toFontChar[charcode] || charcode;
  34218. if (this.missingFile) {
  34219. fontCharCode = mapSpecialUnicodeValues(fontCharCode);
  34220. }
  34221. if (this.isType3Font) {
  34222. // Font char code in this case is actually a glyph name.
  34223. operatorListId = fontCharCode;
  34224. }
  34225. var accent = null;
  34226. if (this.seacMap && this.seacMap[charcode]) {
  34227. var seac = this.seacMap[charcode];
  34228. fontCharCode = seac.baseFontCharCode;
  34229. accent = {
  34230. fontChar: String.fromCharCode(seac.accentFontCharCode),
  34231. offset: seac.accentOffset
  34232. };
  34233. }
  34234. var fontChar = String.fromCharCode(fontCharCode);
  34235. var glyph = this.glyphCache[charcode];
  34236. if (!glyph ||
  34237. !glyph.matchesForCache(fontChar, unicode, accent, width, vmetric,
  34238. operatorListId, isSpace)) {
  34239. glyph = new Glyph(fontChar, unicode, accent, width, vmetric,
  34240. operatorListId, isSpace);
  34241. this.glyphCache[charcode] = glyph;
  34242. }
  34243. return glyph;
  34244. },
  34245. charsToGlyphs: function Font_charsToGlyphs(chars) {
  34246. var charsCache = this.charsCache;
  34247. var glyphs, glyph, charcode;
  34248. // if we translated this string before, just grab it from the cache
  34249. if (charsCache) {
  34250. glyphs = charsCache[chars];
  34251. if (glyphs) {
  34252. return glyphs;
  34253. }
  34254. }
  34255. // lazily create the translation cache
  34256. if (!charsCache) {
  34257. charsCache = this.charsCache = Object.create(null);
  34258. }
  34259. glyphs = [];
  34260. var charsCacheKey = chars;
  34261. var i = 0, ii;
  34262. if (this.cMap) {
  34263. // composite fonts have multi-byte strings convert the string from
  34264. // single-byte to multi-byte
  34265. var c = {};
  34266. while (i < chars.length) {
  34267. this.cMap.readCharCode(chars, i, c);
  34268. charcode = c.charcode;
  34269. var length = c.length;
  34270. i += length;
  34271. // Space is char with code 0x20 and length 1 in multiple-byte codes.
  34272. var isSpace = length === 1 && chars.charCodeAt(i - 1) === 0x20;
  34273. glyph = this.charToGlyph(charcode, isSpace);
  34274. glyphs.push(glyph);
  34275. }
  34276. } else {
  34277. for (i = 0, ii = chars.length; i < ii; ++i) {
  34278. charcode = chars.charCodeAt(i);
  34279. glyph = this.charToGlyph(charcode, charcode === 0x20);
  34280. glyphs.push(glyph);
  34281. }
  34282. }
  34283. // Enter the translated string into the cache
  34284. return (charsCache[charsCacheKey] = glyphs);
  34285. }
  34286. };
  34287. return Font;
  34288. })();
  34289. var ErrorFont = (function ErrorFontClosure() {
  34290. function ErrorFont(error) {
  34291. this.error = error;
  34292. this.loadedName = 'g_font_error';
  34293. this.loading = false;
  34294. }
  34295. ErrorFont.prototype = {
  34296. charsToGlyphs: function ErrorFont_charsToGlyphs() {
  34297. return [];
  34298. },
  34299. exportData: function ErrorFont_exportData() {
  34300. return {error: this.error};
  34301. }
  34302. };
  34303. return ErrorFont;
  34304. })();
  34305. /**
  34306. * Shared logic for building a char code to glyph id mapping for Type1 and
  34307. * simple CFF fonts. See section 9.6.6.2 of the spec.
  34308. * @param {Object} properties Font properties object.
  34309. * @param {Object} builtInEncoding The encoding contained within the actual font
  34310. * data.
  34311. * @param {Array} Array of glyph names where the index is the glyph ID.
  34312. * @returns {Object} A char code to glyph ID map.
  34313. */
  34314. function type1FontGlyphMapping(properties, builtInEncoding, glyphNames) {
  34315. var charCodeToGlyphId = Object.create(null);
  34316. var glyphId, charCode, baseEncoding;
  34317. if (properties.baseEncodingName) {
  34318. // If a valid base encoding name was used, the mapping is initialized with
  34319. // that.
  34320. baseEncoding = Encodings[properties.baseEncodingName];
  34321. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  34322. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  34323. if (glyphId >= 0) {
  34324. charCodeToGlyphId[charCode] = glyphId;
  34325. } else {
  34326. charCodeToGlyphId[charCode] = 0; // notdef
  34327. }
  34328. }
  34329. } else if (!!(properties.flags & FontFlags.Symbolic)) {
  34330. // For a symbolic font the encoding should be the fonts built-in
  34331. // encoding.
  34332. for (charCode in builtInEncoding) {
  34333. charCodeToGlyphId[charCode] = builtInEncoding[charCode];
  34334. }
  34335. } else {
  34336. // For non-symbolic fonts that don't have a base encoding the standard
  34337. // encoding should be used.
  34338. baseEncoding = Encodings.StandardEncoding;
  34339. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  34340. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  34341. if (glyphId >= 0) {
  34342. charCodeToGlyphId[charCode] = glyphId;
  34343. } else {
  34344. charCodeToGlyphId[charCode] = 0; // notdef
  34345. }
  34346. }
  34347. }
  34348. // Lastly, merge in the differences.
  34349. var differences = properties.differences;
  34350. if (differences) {
  34351. for (charCode in differences) {
  34352. var glyphName = differences[charCode];
  34353. glyphId = glyphNames.indexOf(glyphName);
  34354. if (glyphId >= 0) {
  34355. charCodeToGlyphId[charCode] = glyphId;
  34356. } else {
  34357. charCodeToGlyphId[charCode] = 0; // notdef
  34358. }
  34359. }
  34360. }
  34361. return charCodeToGlyphId;
  34362. }
  34363. /*
  34364. * CharStrings are encoded following the the CharString Encoding sequence
  34365. * describe in Chapter 6 of the "Adobe Type1 Font Format" specification.
  34366. * The value in a byte indicates a command, a number, or subsequent bytes
  34367. * that are to be interpreted in a special way.
  34368. *
  34369. * CharString Number Encoding:
  34370. * A CharString byte containing the values from 32 through 255 inclusive
  34371. * indicate an integer. These values are decoded in four ranges.
  34372. *
  34373. * 1. A CharString byte containing a value, v, between 32 and 246 inclusive,
  34374. * indicate the integer v - 139. Thus, the integer values from -107 through
  34375. * 107 inclusive may be encoded in single byte.
  34376. *
  34377. * 2. A CharString byte containing a value, v, between 247 and 250 inclusive,
  34378. * indicates an integer involving the next byte, w, according to the formula:
  34379. * [(v - 247) x 256] + w + 108
  34380. *
  34381. * 3. A CharString byte containing a value, v, between 251 and 254 inclusive,
  34382. * indicates an integer involving the next byte, w, according to the formula:
  34383. * -[(v - 251) * 256] - w - 108
  34384. *
  34385. * 4. A CharString containing the value 255 indicates that the next 4 bytes
  34386. * are a two complement signed integer. The first of these bytes contains the
  34387. * highest order bits, the second byte contains the next higher order bits
  34388. * and the fourth byte contain the lowest order bits.
  34389. *
  34390. *
  34391. * CharString Command Encoding:
  34392. * CharStrings commands are encoded in 1 or 2 bytes.
  34393. *
  34394. * Single byte commands are encoded in 1 byte that contains a value between
  34395. * 0 and 31 inclusive.
  34396. * If a command byte contains the value 12, then the value in the next byte
  34397. * indicates a command. This "escape" mechanism allows many extra commands
  34398. * to be encoded and this encoding technique helps to minimize the length of
  34399. * the charStrings.
  34400. */
  34401. var Type1CharString = (function Type1CharStringClosure() {
  34402. var COMMAND_MAP = {
  34403. 'hstem': [1],
  34404. 'vstem': [3],
  34405. 'vmoveto': [4],
  34406. 'rlineto': [5],
  34407. 'hlineto': [6],
  34408. 'vlineto': [7],
  34409. 'rrcurveto': [8],
  34410. 'callsubr': [10],
  34411. 'flex': [12, 35],
  34412. 'drop' : [12, 18],
  34413. 'endchar': [14],
  34414. 'rmoveto': [21],
  34415. 'hmoveto': [22],
  34416. 'vhcurveto': [30],
  34417. 'hvcurveto': [31]
  34418. };
  34419. function Type1CharString() {
  34420. this.width = 0;
  34421. this.lsb = 0;
  34422. this.flexing = false;
  34423. this.output = [];
  34424. this.stack = [];
  34425. }
  34426. Type1CharString.prototype = {
  34427. convert: function Type1CharString_convert(encoded, subrs) {
  34428. var count = encoded.length;
  34429. var error = false;
  34430. var wx, sbx, subrNumber;
  34431. for (var i = 0; i < count; i++) {
  34432. var value = encoded[i];
  34433. if (value < 32) {
  34434. if (value === 12) {
  34435. value = (value << 8) + encoded[++i];
  34436. }
  34437. switch (value) {
  34438. case 1: // hstem
  34439. if (!HINTING_ENABLED) {
  34440. this.stack = [];
  34441. break;
  34442. }
  34443. error = this.executeCommand(2, COMMAND_MAP.hstem);
  34444. break;
  34445. case 3: // vstem
  34446. if (!HINTING_ENABLED) {
  34447. this.stack = [];
  34448. break;
  34449. }
  34450. error = this.executeCommand(2, COMMAND_MAP.vstem);
  34451. break;
  34452. case 4: // vmoveto
  34453. if (this.flexing) {
  34454. if (this.stack.length < 1) {
  34455. error = true;
  34456. break;
  34457. }
  34458. // Add the dx for flex and but also swap the values so they are
  34459. // the right order.
  34460. var dy = this.stack.pop();
  34461. this.stack.push(0, dy);
  34462. break;
  34463. }
  34464. error = this.executeCommand(1, COMMAND_MAP.vmoveto);
  34465. break;
  34466. case 5: // rlineto
  34467. error = this.executeCommand(2, COMMAND_MAP.rlineto);
  34468. break;
  34469. case 6: // hlineto
  34470. error = this.executeCommand(1, COMMAND_MAP.hlineto);
  34471. break;
  34472. case 7: // vlineto
  34473. error = this.executeCommand(1, COMMAND_MAP.vlineto);
  34474. break;
  34475. case 8: // rrcurveto
  34476. error = this.executeCommand(6, COMMAND_MAP.rrcurveto);
  34477. break;
  34478. case 9: // closepath
  34479. // closepath is a Type1 command that does not take argument and is
  34480. // useless in Type2 and it can simply be ignored.
  34481. this.stack = [];
  34482. break;
  34483. case 10: // callsubr
  34484. if (this.stack.length < 1) {
  34485. error = true;
  34486. break;
  34487. }
  34488. subrNumber = this.stack.pop();
  34489. error = this.convert(subrs[subrNumber], subrs);
  34490. break;
  34491. case 11: // return
  34492. return error;
  34493. case 13: // hsbw
  34494. if (this.stack.length < 2) {
  34495. error = true;
  34496. break;
  34497. }
  34498. // To convert to type2 we have to move the width value to the
  34499. // first part of the charstring and then use hmoveto with lsb.
  34500. wx = this.stack.pop();
  34501. sbx = this.stack.pop();
  34502. this.lsb = sbx;
  34503. this.width = wx;
  34504. this.stack.push(wx, sbx);
  34505. error = this.executeCommand(2, COMMAND_MAP.hmoveto);
  34506. break;
  34507. case 14: // endchar
  34508. this.output.push(COMMAND_MAP.endchar[0]);
  34509. break;
  34510. case 21: // rmoveto
  34511. if (this.flexing) {
  34512. break;
  34513. }
  34514. error = this.executeCommand(2, COMMAND_MAP.rmoveto);
  34515. break;
  34516. case 22: // hmoveto
  34517. if (this.flexing) {
  34518. // Add the dy for flex.
  34519. this.stack.push(0);
  34520. break;
  34521. }
  34522. error = this.executeCommand(1, COMMAND_MAP.hmoveto);
  34523. break;
  34524. case 30: // vhcurveto
  34525. error = this.executeCommand(4, COMMAND_MAP.vhcurveto);
  34526. break;
  34527. case 31: // hvcurveto
  34528. error = this.executeCommand(4, COMMAND_MAP.hvcurveto);
  34529. break;
  34530. case (12 << 8) + 0: // dotsection
  34531. // dotsection is a Type1 command to specify some hinting feature
  34532. // for dots that do not take a parameter and it can safely be
  34533. // ignored for Type2.
  34534. this.stack = [];
  34535. break;
  34536. case (12 << 8) + 1: // vstem3
  34537. if (!HINTING_ENABLED) {
  34538. this.stack = [];
  34539. break;
  34540. }
  34541. // [vh]stem3 are Type1 only and Type2 supports [vh]stem with
  34542. // multiple parameters, so instead of returning [vh]stem3 take a
  34543. // shortcut and return [vhstem] instead.
  34544. error = this.executeCommand(2, COMMAND_MAP.vstem);
  34545. break;
  34546. case (12 << 8) + 2: // hstem3
  34547. if (!HINTING_ENABLED) {
  34548. this.stack = [];
  34549. break;
  34550. }
  34551. // See vstem3.
  34552. error = this.executeCommand(2, COMMAND_MAP.hstem);
  34553. break;
  34554. case (12 << 8) + 6: // seac
  34555. // seac is like type 2's special endchar but it doesn't use the
  34556. // first argument asb, so remove it.
  34557. if (SEAC_ANALYSIS_ENABLED) {
  34558. this.seac = this.stack.splice(-4, 4);
  34559. error = this.executeCommand(0, COMMAND_MAP.endchar);
  34560. } else {
  34561. error = this.executeCommand(4, COMMAND_MAP.endchar);
  34562. }
  34563. break;
  34564. case (12 << 8) + 7: // sbw
  34565. if (this.stack.length < 4) {
  34566. error = true;
  34567. break;
  34568. }
  34569. // To convert to type2 we have to move the width value to the
  34570. // first part of the charstring and then use rmoveto with
  34571. // (dx, dy). The height argument will not be used for vmtx and
  34572. // vhea tables reconstruction -- ignoring it.
  34573. var wy = this.stack.pop();
  34574. wx = this.stack.pop();
  34575. var sby = this.stack.pop();
  34576. sbx = this.stack.pop();
  34577. this.lsb = sbx;
  34578. this.width = wx;
  34579. this.stack.push(wx, sbx, sby);
  34580. error = this.executeCommand(3, COMMAND_MAP.rmoveto);
  34581. break;
  34582. case (12 << 8) + 12: // div
  34583. if (this.stack.length < 2) {
  34584. error = true;
  34585. break;
  34586. }
  34587. var num2 = this.stack.pop();
  34588. var num1 = this.stack.pop();
  34589. this.stack.push(num1 / num2);
  34590. break;
  34591. case (12 << 8) + 16: // callothersubr
  34592. if (this.stack.length < 2) {
  34593. error = true;
  34594. break;
  34595. }
  34596. subrNumber = this.stack.pop();
  34597. var numArgs = this.stack.pop();
  34598. if (subrNumber === 0 && numArgs === 3) {
  34599. var flexArgs = this.stack.splice(this.stack.length - 17, 17);
  34600. this.stack.push(
  34601. flexArgs[2] + flexArgs[0], // bcp1x + rpx
  34602. flexArgs[3] + flexArgs[1], // bcp1y + rpy
  34603. flexArgs[4], // bcp2x
  34604. flexArgs[5], // bcp2y
  34605. flexArgs[6], // p2x
  34606. flexArgs[7], // p2y
  34607. flexArgs[8], // bcp3x
  34608. flexArgs[9], // bcp3y
  34609. flexArgs[10], // bcp4x
  34610. flexArgs[11], // bcp4y
  34611. flexArgs[12], // p3x
  34612. flexArgs[13], // p3y
  34613. flexArgs[14] // flexDepth
  34614. // 15 = finalx unused by flex
  34615. // 16 = finaly unused by flex
  34616. );
  34617. error = this.executeCommand(13, COMMAND_MAP.flex, true);
  34618. this.flexing = false;
  34619. this.stack.push(flexArgs[15], flexArgs[16]);
  34620. } else if (subrNumber === 1 && numArgs === 0) {
  34621. this.flexing = true;
  34622. }
  34623. break;
  34624. case (12 << 8) + 17: // pop
  34625. // Ignore this since it is only used with othersubr.
  34626. break;
  34627. case (12 << 8) + 33: // setcurrentpoint
  34628. // Ignore for now.
  34629. this.stack = [];
  34630. break;
  34631. default:
  34632. warn('Unknown type 1 charstring command of "' + value + '"');
  34633. break;
  34634. }
  34635. if (error) {
  34636. break;
  34637. }
  34638. continue;
  34639. } else if (value <= 246) {
  34640. value = value - 139;
  34641. } else if (value <= 250) {
  34642. value = ((value - 247) * 256) + encoded[++i] + 108;
  34643. } else if (value <= 254) {
  34644. value = -((value - 251) * 256) - encoded[++i] - 108;
  34645. } else {
  34646. value = (encoded[++i] & 0xff) << 24 | (encoded[++i] & 0xff) << 16 |
  34647. (encoded[++i] & 0xff) << 8 | (encoded[++i] & 0xff) << 0;
  34648. }
  34649. this.stack.push(value);
  34650. }
  34651. return error;
  34652. },
  34653. executeCommand: function(howManyArgs, command, keepStack) {
  34654. var stackLength = this.stack.length;
  34655. if (howManyArgs > stackLength) {
  34656. return true;
  34657. }
  34658. var start = stackLength - howManyArgs;
  34659. for (var i = start; i < stackLength; i++) {
  34660. var value = this.stack[i];
  34661. if (value === (value | 0)) { // int
  34662. this.output.push(28, (value >> 8) & 0xff, value & 0xff);
  34663. } else { // fixed point
  34664. value = (65536 * value) | 0;
  34665. this.output.push(255,
  34666. (value >> 24) & 0xFF,
  34667. (value >> 16) & 0xFF,
  34668. (value >> 8) & 0xFF,
  34669. value & 0xFF);
  34670. }
  34671. }
  34672. this.output.push.apply(this.output, command);
  34673. if (keepStack) {
  34674. this.stack.splice(start, howManyArgs);
  34675. } else {
  34676. this.stack.length = 0;
  34677. }
  34678. return false;
  34679. }
  34680. };
  34681. return Type1CharString;
  34682. })();
  34683. /*
  34684. * Type1Parser encapsulate the needed code for parsing a Type1 font
  34685. * program. Some of its logic depends on the Type2 charstrings
  34686. * structure.
  34687. * Note: this doesn't really parse the font since that would require evaluation
  34688. * of PostScript, but it is possible in most cases to extract what we need
  34689. * without a full parse.
  34690. */
  34691. var Type1Parser = (function Type1ParserClosure() {
  34692. /*
  34693. * Decrypt a Sequence of Ciphertext Bytes to Produce the Original Sequence
  34694. * of Plaintext Bytes. The function took a key as a parameter which can be
  34695. * for decrypting the eexec block of for decoding charStrings.
  34696. */
  34697. var EEXEC_ENCRYPT_KEY = 55665;
  34698. var CHAR_STRS_ENCRYPT_KEY = 4330;
  34699. function isHexDigit(code) {
  34700. return code >= 48 && code <= 57 || // '0'-'9'
  34701. code >= 65 && code <= 70 || // 'A'-'F'
  34702. code >= 97 && code <= 102; // 'a'-'f'
  34703. }
  34704. function decrypt(data, key, discardNumber) {
  34705. var r = key | 0, c1 = 52845, c2 = 22719;
  34706. var count = data.length;
  34707. var decrypted = new Uint8Array(count);
  34708. for (var i = 0; i < count; i++) {
  34709. var value = data[i];
  34710. decrypted[i] = value ^ (r >> 8);
  34711. r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
  34712. }
  34713. return Array.prototype.slice.call(decrypted, discardNumber);
  34714. }
  34715. function decryptAscii(data, key, discardNumber) {
  34716. var r = key | 0, c1 = 52845, c2 = 22719;
  34717. var count = data.length, maybeLength = count >>> 1;
  34718. var decrypted = new Uint8Array(maybeLength);
  34719. var i, j;
  34720. for (i = 0, j = 0; i < count; i++) {
  34721. var digit1 = data[i];
  34722. if (!isHexDigit(digit1)) {
  34723. continue;
  34724. }
  34725. i++;
  34726. var digit2;
  34727. while (i < count && !isHexDigit(digit2 = data[i])) {
  34728. i++;
  34729. }
  34730. if (i < count) {
  34731. var value = parseInt(String.fromCharCode(digit1, digit2), 16);
  34732. decrypted[j++] = value ^ (r >> 8);
  34733. r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
  34734. }
  34735. }
  34736. return Array.prototype.slice.call(decrypted, discardNumber, j);
  34737. }
  34738. function isSpecial(c) {
  34739. return c === 0x2F || // '/'
  34740. c === 0x5B || c === 0x5D || // '[', ']'
  34741. c === 0x7B || c === 0x7D || // '{', '}'
  34742. c === 0x28 || c === 0x29; // '(', ')'
  34743. }
  34744. function Type1Parser(stream, encrypted) {
  34745. if (encrypted) {
  34746. var data = stream.getBytes();
  34747. var isBinary = !(isHexDigit(data[0]) && isHexDigit(data[1]) &&
  34748. isHexDigit(data[2]) && isHexDigit(data[3]));
  34749. stream = new Stream(isBinary ? decrypt(data, EEXEC_ENCRYPT_KEY, 4) :
  34750. decryptAscii(data, EEXEC_ENCRYPT_KEY, 4));
  34751. }
  34752. this.stream = stream;
  34753. this.nextChar();
  34754. }
  34755. Type1Parser.prototype = {
  34756. readNumberArray: function Type1Parser_readNumberArray() {
  34757. this.getToken(); // read '[' or '{' (arrays can start with either)
  34758. var array = [];
  34759. while (true) {
  34760. var token = this.getToken();
  34761. if (token === null || token === ']' || token === '}') {
  34762. break;
  34763. }
  34764. array.push(parseFloat(token || 0));
  34765. }
  34766. return array;
  34767. },
  34768. readNumber: function Type1Parser_readNumber() {
  34769. var token = this.getToken();
  34770. return parseFloat(token || 0);
  34771. },
  34772. readInt: function Type1Parser_readInt() {
  34773. // Use '| 0' to prevent setting a double into length such as the double
  34774. // does not flow into the loop variable.
  34775. var token = this.getToken();
  34776. return parseInt(token || 0, 10) | 0;
  34777. },
  34778. readBoolean: function Type1Parser_readBoolean() {
  34779. var token = this.getToken();
  34780. // Use 1 and 0 since that's what type2 charstrings use.
  34781. return token === 'true' ? 1 : 0;
  34782. },
  34783. nextChar : function Type1_nextChar() {
  34784. return (this.currentChar = this.stream.getByte());
  34785. },
  34786. getToken: function Type1Parser_getToken() {
  34787. // Eat whitespace and comments.
  34788. var comment = false;
  34789. var ch = this.currentChar;
  34790. while (true) {
  34791. if (ch === -1) {
  34792. return null;
  34793. }
  34794. if (comment) {
  34795. if (ch === 0x0A || ch === 0x0D) {
  34796. comment = false;
  34797. }
  34798. } else if (ch === 0x25) { // '%'
  34799. comment = true;
  34800. } else if (!Lexer.isSpace(ch)) {
  34801. break;
  34802. }
  34803. ch = this.nextChar();
  34804. }
  34805. if (isSpecial(ch)) {
  34806. this.nextChar();
  34807. return String.fromCharCode(ch);
  34808. }
  34809. var token = '';
  34810. do {
  34811. token += String.fromCharCode(ch);
  34812. ch = this.nextChar();
  34813. } while (ch >= 0 && !Lexer.isSpace(ch) && !isSpecial(ch));
  34814. return token;
  34815. },
  34816. /*
  34817. * Returns an object containing a Subrs array and a CharStrings
  34818. * array extracted from and eexec encrypted block of data
  34819. */
  34820. extractFontProgram: function Type1Parser_extractFontProgram() {
  34821. var stream = this.stream;
  34822. var subrs = [], charstrings = [];
  34823. var program = {
  34824. subrs: [],
  34825. charstrings: [],
  34826. properties: {
  34827. 'privateData': {
  34828. 'lenIV': 4
  34829. }
  34830. }
  34831. };
  34832. var token, length, data, lenIV, encoded;
  34833. while ((token = this.getToken()) !== null) {
  34834. if (token !== '/') {
  34835. continue;
  34836. }
  34837. token = this.getToken();
  34838. switch (token) {
  34839. case 'CharStrings':
  34840. // The number immediately following CharStrings must be greater or
  34841. // equal to the number of CharStrings.
  34842. this.getToken();
  34843. this.getToken(); // read in 'dict'
  34844. this.getToken(); // read in 'dup'
  34845. this.getToken(); // read in 'begin'
  34846. while(true) {
  34847. token = this.getToken();
  34848. if (token === null || token === 'end') {
  34849. break;
  34850. }
  34851. if (token !== '/') {
  34852. continue;
  34853. }
  34854. var glyph = this.getToken();
  34855. length = this.readInt();
  34856. this.getToken(); // read in 'RD' or '-|'
  34857. data = stream.makeSubStream(stream.pos, length);
  34858. lenIV = program.properties.privateData['lenIV'];
  34859. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  34860. // Skip past the required space and binary data.
  34861. stream.skip(length);
  34862. this.nextChar();
  34863. token = this.getToken(); // read in 'ND' or '|-'
  34864. if (token === 'noaccess') {
  34865. this.getToken(); // read in 'def'
  34866. }
  34867. charstrings.push({
  34868. glyph: glyph,
  34869. encoded: encoded
  34870. });
  34871. }
  34872. break;
  34873. case 'Subrs':
  34874. var num = this.readInt();
  34875. this.getToken(); // read in 'array'
  34876. while ((token = this.getToken()) === 'dup') {
  34877. var index = this.readInt();
  34878. length = this.readInt();
  34879. this.getToken(); // read in 'RD' or '-|'
  34880. data = stream.makeSubStream(stream.pos, length);
  34881. lenIV = program.properties.privateData['lenIV'];
  34882. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  34883. // Skip past the required space and binary data.
  34884. stream.skip(length);
  34885. this.nextChar();
  34886. token = this.getToken(); // read in 'NP' or '|'
  34887. if (token === 'noaccess') {
  34888. this.getToken(); // read in 'put'
  34889. }
  34890. subrs[index] = encoded;
  34891. }
  34892. break;
  34893. case 'BlueValues':
  34894. case 'OtherBlues':
  34895. case 'FamilyBlues':
  34896. case 'FamilyOtherBlues':
  34897. var blueArray = this.readNumberArray();
  34898. // *Blue* values may contain invalid data: disables reading of
  34899. // those values when hinting is disabled.
  34900. if (blueArray.length > 0 && (blueArray.length % 2) === 0 &&
  34901. HINTING_ENABLED) {
  34902. program.properties.privateData[token] = blueArray;
  34903. }
  34904. break;
  34905. case 'StemSnapH':
  34906. case 'StemSnapV':
  34907. program.properties.privateData[token] = this.readNumberArray();
  34908. break;
  34909. case 'StdHW':
  34910. case 'StdVW':
  34911. program.properties.privateData[token] =
  34912. this.readNumberArray()[0];
  34913. break;
  34914. case 'BlueShift':
  34915. case 'lenIV':
  34916. case 'BlueFuzz':
  34917. case 'BlueScale':
  34918. case 'LanguageGroup':
  34919. case 'ExpansionFactor':
  34920. program.properties.privateData[token] = this.readNumber();
  34921. break;
  34922. case 'ForceBold':
  34923. program.properties.privateData[token] = this.readBoolean();
  34924. break;
  34925. }
  34926. }
  34927. for (var i = 0; i < charstrings.length; i++) {
  34928. glyph = charstrings[i].glyph;
  34929. encoded = charstrings[i].encoded;
  34930. var charString = new Type1CharString();
  34931. var error = charString.convert(encoded, subrs);
  34932. var output = charString.output;
  34933. if (error) {
  34934. // It seems when FreeType encounters an error while evaluating a glyph
  34935. // that it completely ignores the glyph so we'll mimic that behaviour
  34936. // here and put an endchar to make the validator happy.
  34937. output = [14];
  34938. }
  34939. program.charstrings.push({
  34940. glyphName: glyph,
  34941. charstring: output,
  34942. width: charString.width,
  34943. lsb: charString.lsb,
  34944. seac: charString.seac
  34945. });
  34946. }
  34947. return program;
  34948. },
  34949. extractFontHeader: function Type1Parser_extractFontHeader(properties) {
  34950. var token;
  34951. while ((token = this.getToken()) !== null) {
  34952. if (token !== '/') {
  34953. continue;
  34954. }
  34955. token = this.getToken();
  34956. switch (token) {
  34957. case 'FontMatrix':
  34958. var matrix = this.readNumberArray();
  34959. properties.fontMatrix = matrix;
  34960. break;
  34961. case 'Encoding':
  34962. var encodingArg = this.getToken();
  34963. var encoding;
  34964. if (!/^\d+$/.test(encodingArg)) {
  34965. // encoding name is specified
  34966. encoding = Encodings[encodingArg];
  34967. } else {
  34968. encoding = [];
  34969. var size = parseInt(encodingArg, 10) | 0;
  34970. this.getToken(); // read in 'array'
  34971. for (var j = 0; j < size; j++) {
  34972. token = this.getToken();
  34973. // skipping till first dup or def (e.g. ignoring for statement)
  34974. while (token !== 'dup' && token !== 'def') {
  34975. token = this.getToken();
  34976. if (token === null) {
  34977. return; // invalid header
  34978. }
  34979. }
  34980. if (token === 'def') {
  34981. break; // read all array data
  34982. }
  34983. var index = this.readInt();
  34984. this.getToken(); // read in '/'
  34985. var glyph = this.getToken();
  34986. encoding[index] = glyph;
  34987. this.getToken(); // read the in 'put'
  34988. }
  34989. }
  34990. properties.builtInEncoding = encoding;
  34991. break;
  34992. case 'FontBBox':
  34993. var fontBBox = this.readNumberArray();
  34994. // adjusting ascent/descent
  34995. properties.ascent = fontBBox[3];
  34996. properties.descent = fontBBox[1];
  34997. properties.ascentScaled = true;
  34998. break;
  34999. }
  35000. }
  35001. }
  35002. };
  35003. return Type1Parser;
  35004. })();
  35005. /**
  35006. * The CFF class takes a Type1 file and wrap it into a
  35007. * 'Compact Font Format' which itself embed Type2 charstrings.
  35008. */
  35009. var CFFStandardStrings = [
  35010. '.notdef', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  35011. 'ampersand', 'quoteright', 'parenleft', 'parenright', 'asterisk', 'plus',
  35012. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three', 'four',
  35013. 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon', 'less',
  35014. 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
  35015. 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
  35016. 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright', 'asciicircum',
  35017. 'underscore', 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
  35018. 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y',
  35019. 'z', 'braceleft', 'bar', 'braceright', 'asciitilde', 'exclamdown', 'cent',
  35020. 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  35021. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  35022. 'guilsinglright', 'fi', 'fl', 'endash', 'dagger', 'daggerdbl',
  35023. 'periodcentered', 'paragraph', 'bullet', 'quotesinglbase', 'quotedblbase',
  35024. 'quotedblright', 'guillemotright', 'ellipsis', 'perthousand', 'questiondown',
  35025. 'grave', 'acute', 'circumflex', 'tilde', 'macron', 'breve', 'dotaccent',
  35026. 'dieresis', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron', 'emdash',
  35027. 'AE', 'ordfeminine', 'Lslash', 'Oslash', 'OE', 'ordmasculine', 'ae',
  35028. 'dotlessi', 'lslash', 'oslash', 'oe', 'germandbls', 'onesuperior',
  35029. 'logicalnot', 'mu', 'trademark', 'Eth', 'onehalf', 'plusminus', 'Thorn',
  35030. 'onequarter', 'divide', 'brokenbar', 'degree', 'thorn', 'threequarters',
  35031. 'twosuperior', 'registered', 'minus', 'eth', 'multiply', 'threesuperior',
  35032. 'copyright', 'Aacute', 'Acircumflex', 'Adieresis', 'Agrave', 'Aring',
  35033. 'Atilde', 'Ccedilla', 'Eacute', 'Ecircumflex', 'Edieresis', 'Egrave',
  35034. 'Iacute', 'Icircumflex', 'Idieresis', 'Igrave', 'Ntilde', 'Oacute',
  35035. 'Ocircumflex', 'Odieresis', 'Ograve', 'Otilde', 'Scaron', 'Uacute',
  35036. 'Ucircumflex', 'Udieresis', 'Ugrave', 'Yacute', 'Ydieresis', 'Zcaron',
  35037. 'aacute', 'acircumflex', 'adieresis', 'agrave', 'aring', 'atilde',
  35038. 'ccedilla', 'eacute', 'ecircumflex', 'edieresis', 'egrave', 'iacute',
  35039. 'icircumflex', 'idieresis', 'igrave', 'ntilde', 'oacute', 'ocircumflex',
  35040. 'odieresis', 'ograve', 'otilde', 'scaron', 'uacute', 'ucircumflex',
  35041. 'udieresis', 'ugrave', 'yacute', 'ydieresis', 'zcaron', 'exclamsmall',
  35042. 'Hungarumlautsmall', 'dollaroldstyle', 'dollarsuperior', 'ampersandsmall',
  35043. 'Acutesmall', 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  35044. 'onedotenleader', 'zerooldstyle', 'oneoldstyle', 'twooldstyle',
  35045. 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle', 'sixoldstyle',
  35046. 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle', 'commasuperior',
  35047. 'threequartersemdash', 'periodsuperior', 'questionsmall', 'asuperior',
  35048. 'bsuperior', 'centsuperior', 'dsuperior', 'esuperior', 'isuperior',
  35049. 'lsuperior', 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  35050. 'tsuperior', 'ff', 'ffi', 'ffl', 'parenleftinferior', 'parenrightinferior',
  35051. 'Circumflexsmall', 'hyphensuperior', 'Gravesmall', 'Asmall', 'Bsmall',
  35052. 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall', 'Hsmall', 'Ismall',
  35053. 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall', 'Osmall', 'Psmall',
  35054. 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall', 'Vsmall', 'Wsmall',
  35055. 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary', 'onefitted', 'rupiah',
  35056. 'Tildesmall', 'exclamdownsmall', 'centoldstyle', 'Lslashsmall',
  35057. 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall', 'Brevesmall', 'Caronsmall',
  35058. 'Dotaccentsmall', 'Macronsmall', 'figuredash', 'hypheninferior',
  35059. 'Ogoneksmall', 'Ringsmall', 'Cedillasmall', 'questiondownsmall', 'oneeighth',
  35060. 'threeeighths', 'fiveeighths', 'seveneighths', 'onethird', 'twothirds',
  35061. 'zerosuperior', 'foursuperior', 'fivesuperior', 'sixsuperior',
  35062. 'sevensuperior', 'eightsuperior', 'ninesuperior', 'zeroinferior',
  35063. 'oneinferior', 'twoinferior', 'threeinferior', 'fourinferior',
  35064. 'fiveinferior', 'sixinferior', 'seveninferior', 'eightinferior',
  35065. 'nineinferior', 'centinferior', 'dollarinferior', 'periodinferior',
  35066. 'commainferior', 'Agravesmall', 'Aacutesmall', 'Acircumflexsmall',
  35067. 'Atildesmall', 'Adieresissmall', 'Aringsmall', 'AEsmall', 'Ccedillasmall',
  35068. 'Egravesmall', 'Eacutesmall', 'Ecircumflexsmall', 'Edieresissmall',
  35069. 'Igravesmall', 'Iacutesmall', 'Icircumflexsmall', 'Idieresissmall',
  35070. 'Ethsmall', 'Ntildesmall', 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall',
  35071. 'Otildesmall', 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall',
  35072. 'Uacutesmall', 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall',
  35073. 'Thornsmall', 'Ydieresissmall', '001.000', '001.001', '001.002', '001.003',
  35074. 'Black', 'Bold', 'Book', 'Light', 'Medium', 'Regular', 'Roman', 'Semibold'
  35075. ];
  35076. // Type1Font is also a CIDFontType0.
  35077. var Type1Font = function Type1Font(name, file, properties) {
  35078. // Some bad generators embed pfb file as is, we have to strip 6-byte headers.
  35079. // Also, length1 and length2 might be off by 6 bytes as well.
  35080. // http://www.math.ubc.ca/~cass/piscript/type1.pdf
  35081. var PFB_HEADER_SIZE = 6;
  35082. var headerBlockLength = properties.length1;
  35083. var eexecBlockLength = properties.length2;
  35084. var pfbHeader = file.peekBytes(PFB_HEADER_SIZE);
  35085. var pfbHeaderPresent = pfbHeader[0] === 0x80 && pfbHeader[1] === 0x01;
  35086. if (pfbHeaderPresent) {
  35087. file.skip(PFB_HEADER_SIZE);
  35088. headerBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
  35089. (pfbHeader[3] << 8) | pfbHeader[2];
  35090. }
  35091. // Get the data block containing glyphs and subrs informations
  35092. var headerBlock = new Stream(file.getBytes(headerBlockLength));
  35093. var headerBlockParser = new Type1Parser(headerBlock);
  35094. headerBlockParser.extractFontHeader(properties);
  35095. if (pfbHeaderPresent) {
  35096. pfbHeader = file.getBytes(PFB_HEADER_SIZE);
  35097. eexecBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
  35098. (pfbHeader[3] << 8) | pfbHeader[2];
  35099. }
  35100. // Decrypt the data blocks and retrieve it's content
  35101. var eexecBlock = new Stream(file.getBytes(eexecBlockLength));
  35102. var eexecBlockParser = new Type1Parser(eexecBlock, true);
  35103. var data = eexecBlockParser.extractFontProgram();
  35104. for (var info in data.properties) {
  35105. properties[info] = data.properties[info];
  35106. }
  35107. var charstrings = data.charstrings;
  35108. var type2Charstrings = this.getType2Charstrings(charstrings);
  35109. var subrs = this.getType2Subrs(data.subrs);
  35110. this.charstrings = charstrings;
  35111. this.data = this.wrap(name, type2Charstrings, this.charstrings,
  35112. subrs, properties);
  35113. this.seacs = this.getSeacs(data.charstrings);
  35114. };
  35115. Type1Font.prototype = {
  35116. get numGlyphs() {
  35117. return this.charstrings.length + 1;
  35118. },
  35119. getCharset: function Type1Font_getCharset() {
  35120. var charset = ['.notdef'];
  35121. var charstrings = this.charstrings;
  35122. for (var glyphId = 0; glyphId < charstrings.length; glyphId++) {
  35123. charset.push(charstrings[glyphId].glyphName);
  35124. }
  35125. return charset;
  35126. },
  35127. getGlyphMapping: function Type1Font_getGlyphMapping(properties) {
  35128. var charstrings = this.charstrings;
  35129. var glyphNames = ['.notdef'], glyphId;
  35130. for (glyphId = 0; glyphId < charstrings.length; glyphId++) {
  35131. glyphNames.push(charstrings[glyphId].glyphName);
  35132. }
  35133. var encoding = properties.builtInEncoding;
  35134. if (encoding) {
  35135. var builtInEncoding = {};
  35136. for (var charCode in encoding) {
  35137. glyphId = glyphNames.indexOf(encoding[charCode]);
  35138. if (glyphId >= 0) {
  35139. builtInEncoding[charCode] = glyphId;
  35140. }
  35141. }
  35142. }
  35143. return type1FontGlyphMapping(properties, builtInEncoding, glyphNames);
  35144. },
  35145. getSeacs: function Type1Font_getSeacs(charstrings) {
  35146. var i, ii;
  35147. var seacMap = [];
  35148. for (i = 0, ii = charstrings.length; i < ii; i++) {
  35149. var charstring = charstrings[i];
  35150. if (charstring.seac) {
  35151. // Offset by 1 for .notdef
  35152. seacMap[i + 1] = charstring.seac;
  35153. }
  35154. }
  35155. return seacMap;
  35156. },
  35157. getType2Charstrings: function Type1Font_getType2Charstrings(
  35158. type1Charstrings) {
  35159. var type2Charstrings = [];
  35160. for (var i = 0, ii = type1Charstrings.length; i < ii; i++) {
  35161. type2Charstrings.push(type1Charstrings[i].charstring);
  35162. }
  35163. return type2Charstrings;
  35164. },
  35165. getType2Subrs: function Type1Font_getType2Subrs(type1Subrs) {
  35166. var bias = 0;
  35167. var count = type1Subrs.length;
  35168. if (count < 1133) {
  35169. bias = 107;
  35170. } else if (count < 33769) {
  35171. bias = 1131;
  35172. } else {
  35173. bias = 32768;
  35174. }
  35175. // Add a bunch of empty subrs to deal with the Type2 bias
  35176. var type2Subrs = [];
  35177. var i;
  35178. for (i = 0; i < bias; i++) {
  35179. type2Subrs.push([0x0B]);
  35180. }
  35181. for (i = 0; i < count; i++) {
  35182. type2Subrs.push(type1Subrs[i]);
  35183. }
  35184. return type2Subrs;
  35185. },
  35186. wrap: function Type1Font_wrap(name, glyphs, charstrings, subrs, properties) {
  35187. var cff = new CFF();
  35188. cff.header = new CFFHeader(1, 0, 4, 4);
  35189. cff.names = [name];
  35190. var topDict = new CFFTopDict();
  35191. // CFF strings IDs 0...390 are predefined names, so refering
  35192. // to entries in our own String INDEX starts at SID 391.
  35193. topDict.setByName('version', 391);
  35194. topDict.setByName('Notice', 392);
  35195. topDict.setByName('FullName', 393);
  35196. topDict.setByName('FamilyName', 394);
  35197. topDict.setByName('Weight', 395);
  35198. topDict.setByName('Encoding', null); // placeholder
  35199. topDict.setByName('FontMatrix', properties.fontMatrix);
  35200. topDict.setByName('FontBBox', properties.bbox);
  35201. topDict.setByName('charset', null); // placeholder
  35202. topDict.setByName('CharStrings', null); // placeholder
  35203. topDict.setByName('Private', null); // placeholder
  35204. cff.topDict = topDict;
  35205. var strings = new CFFStrings();
  35206. strings.add('Version 0.11'); // Version
  35207. strings.add('See original notice'); // Notice
  35208. strings.add(name); // FullName
  35209. strings.add(name); // FamilyName
  35210. strings.add('Medium'); // Weight
  35211. cff.strings = strings;
  35212. cff.globalSubrIndex = new CFFIndex();
  35213. var count = glyphs.length;
  35214. var charsetArray = [0];
  35215. var i, ii;
  35216. for (i = 0; i < count; i++) {
  35217. var index = CFFStandardStrings.indexOf(charstrings[i].glyphName);
  35218. // TODO: Insert the string and correctly map it. Previously it was
  35219. // thought mapping names that aren't in the standard strings to .notdef
  35220. // was fine, however in issue818 when mapping them all to .notdef the
  35221. // adieresis glyph no longer worked.
  35222. if (index === -1) {
  35223. index = 0;
  35224. }
  35225. charsetArray.push((index >> 8) & 0xff, index & 0xff);
  35226. }
  35227. cff.charset = new CFFCharset(false, 0, [], charsetArray);
  35228. var charStringsIndex = new CFFIndex();
  35229. charStringsIndex.add([0x8B, 0x0E]); // .notdef
  35230. for (i = 0; i < count; i++) {
  35231. charStringsIndex.add(glyphs[i]);
  35232. }
  35233. cff.charStrings = charStringsIndex;
  35234. var privateDict = new CFFPrivateDict();
  35235. privateDict.setByName('Subrs', null); // placeholder
  35236. var fields = [
  35237. 'BlueValues',
  35238. 'OtherBlues',
  35239. 'FamilyBlues',
  35240. 'FamilyOtherBlues',
  35241. 'StemSnapH',
  35242. 'StemSnapV',
  35243. 'BlueShift',
  35244. 'BlueFuzz',
  35245. 'BlueScale',
  35246. 'LanguageGroup',
  35247. 'ExpansionFactor',
  35248. 'ForceBold',
  35249. 'StdHW',
  35250. 'StdVW'
  35251. ];
  35252. for (i = 0, ii = fields.length; i < ii; i++) {
  35253. var field = fields[i];
  35254. if (!properties.privateData.hasOwnProperty(field)) {
  35255. continue;
  35256. }
  35257. var value = properties.privateData[field];
  35258. if (isArray(value)) {
  35259. // All of the private dictionary array data in CFF must be stored as
  35260. // "delta-encoded" numbers.
  35261. for (var j = value.length - 1; j > 0; j--) {
  35262. value[j] -= value[j - 1]; // ... difference from previous value
  35263. }
  35264. }
  35265. privateDict.setByName(field, value);
  35266. }
  35267. cff.topDict.privateDict = privateDict;
  35268. var subrIndex = new CFFIndex();
  35269. for (i = 0, ii = subrs.length; i < ii; i++) {
  35270. subrIndex.add(subrs[i]);
  35271. }
  35272. privateDict.subrsIndex = subrIndex;
  35273. var compiler = new CFFCompiler(cff);
  35274. return compiler.compile();
  35275. }
  35276. };
  35277. var CFFFont = (function CFFFontClosure() {
  35278. function CFFFont(file, properties) {
  35279. this.properties = properties;
  35280. var parser = new CFFParser(file, properties);
  35281. this.cff = parser.parse();
  35282. var compiler = new CFFCompiler(this.cff);
  35283. this.seacs = this.cff.seacs;
  35284. try {
  35285. this.data = compiler.compile();
  35286. } catch (e) {
  35287. warn('Failed to compile font ' + properties.loadedName);
  35288. // There may have just been an issue with the compiler, set the data
  35289. // anyway and hope the font loaded.
  35290. this.data = file;
  35291. }
  35292. }
  35293. CFFFont.prototype = {
  35294. get numGlyphs() {
  35295. return this.cff.charStrings.count;
  35296. },
  35297. getCharset: function CFFFont_getCharset() {
  35298. return this.cff.charset.charset;
  35299. },
  35300. getGlyphMapping: function CFFFont_getGlyphMapping() {
  35301. var cff = this.cff;
  35302. var properties = this.properties;
  35303. var charsets = cff.charset.charset;
  35304. var charCodeToGlyphId;
  35305. var glyphId;
  35306. if (properties.composite) {
  35307. charCodeToGlyphId = Object.create(null);
  35308. if (cff.isCIDFont) {
  35309. // If the font is actually a CID font then we should use the charset
  35310. // to map CIDs to GIDs.
  35311. for (glyphId = 0; glyphId < charsets.length; glyphId++) {
  35312. var cid = charsets[glyphId];
  35313. var charCode = properties.cMap.charCodeOf(cid);
  35314. charCodeToGlyphId[charCode] = glyphId;
  35315. }
  35316. } else {
  35317. // If it is NOT actually a CID font then CIDs should be mapped
  35318. // directly to GIDs.
  35319. for (glyphId = 0; glyphId < cff.charStrings.count; glyphId++) {
  35320. charCodeToGlyphId[glyphId] = glyphId;
  35321. }
  35322. }
  35323. return charCodeToGlyphId;
  35324. }
  35325. var encoding = cff.encoding ? cff.encoding.encoding : null;
  35326. charCodeToGlyphId = type1FontGlyphMapping(properties, encoding, charsets);
  35327. return charCodeToGlyphId;
  35328. }
  35329. };
  35330. return CFFFont;
  35331. })();
  35332. var CFFParser = (function CFFParserClosure() {
  35333. var CharstringValidationData = [
  35334. null,
  35335. { id: 'hstem', min: 2, stackClearing: true, stem: true },
  35336. null,
  35337. { id: 'vstem', min: 2, stackClearing: true, stem: true },
  35338. { id: 'vmoveto', min: 1, stackClearing: true },
  35339. { id: 'rlineto', min: 2, resetStack: true },
  35340. { id: 'hlineto', min: 1, resetStack: true },
  35341. { id: 'vlineto', min: 1, resetStack: true },
  35342. { id: 'rrcurveto', min: 6, resetStack: true },
  35343. null,
  35344. { id: 'callsubr', min: 1, undefStack: true },
  35345. { id: 'return', min: 0, undefStack: true },
  35346. null, // 12
  35347. null,
  35348. { id: 'endchar', min: 0, stackClearing: true },
  35349. null,
  35350. null,
  35351. null,
  35352. { id: 'hstemhm', min: 2, stackClearing: true, stem: true },
  35353. { id: 'hintmask', min: 0, stackClearing: true },
  35354. { id: 'cntrmask', min: 0, stackClearing: true },
  35355. { id: 'rmoveto', min: 2, stackClearing: true },
  35356. { id: 'hmoveto', min: 1, stackClearing: true },
  35357. { id: 'vstemhm', min: 2, stackClearing: true, stem: true },
  35358. { id: 'rcurveline', min: 8, resetStack: true },
  35359. { id: 'rlinecurve', min: 8, resetStack: true },
  35360. { id: 'vvcurveto', min: 4, resetStack: true },
  35361. { id: 'hhcurveto', min: 4, resetStack: true },
  35362. null, // shortint
  35363. { id: 'callgsubr', min: 1, undefStack: true },
  35364. { id: 'vhcurveto', min: 4, resetStack: true },
  35365. { id: 'hvcurveto', min: 4, resetStack: true }
  35366. ];
  35367. var CharstringValidationData12 = [
  35368. null,
  35369. null,
  35370. null,
  35371. { id: 'and', min: 2, stackDelta: -1 },
  35372. { id: 'or', min: 2, stackDelta: -1 },
  35373. { id: 'not', min: 1, stackDelta: 0 },
  35374. null,
  35375. null,
  35376. null,
  35377. { id: 'abs', min: 1, stackDelta: 0 },
  35378. { id: 'add', min: 2, stackDelta: -1,
  35379. stackFn: function stack_div(stack, index) {
  35380. stack[index - 2] = stack[index - 2] + stack[index - 1];
  35381. }
  35382. },
  35383. { id: 'sub', min: 2, stackDelta: -1,
  35384. stackFn: function stack_div(stack, index) {
  35385. stack[index - 2] = stack[index - 2] - stack[index - 1];
  35386. }
  35387. },
  35388. { id: 'div', min: 2, stackDelta: -1,
  35389. stackFn: function stack_div(stack, index) {
  35390. stack[index - 2] = stack[index - 2] / stack[index - 1];
  35391. }
  35392. },
  35393. null,
  35394. { id: 'neg', min: 1, stackDelta: 0,
  35395. stackFn: function stack_div(stack, index) {
  35396. stack[index - 1] = -stack[index - 1];
  35397. }
  35398. },
  35399. { id: 'eq', min: 2, stackDelta: -1 },
  35400. null,
  35401. null,
  35402. { id: 'drop', min: 1, stackDelta: -1 },
  35403. null,
  35404. { id: 'put', min: 2, stackDelta: -2 },
  35405. { id: 'get', min: 1, stackDelta: 0 },
  35406. { id: 'ifelse', min: 4, stackDelta: -3 },
  35407. { id: 'random', min: 0, stackDelta: 1 },
  35408. { id: 'mul', min: 2, stackDelta: -1,
  35409. stackFn: function stack_div(stack, index) {
  35410. stack[index - 2] = stack[index - 2] * stack[index - 1];
  35411. }
  35412. },
  35413. null,
  35414. { id: 'sqrt', min: 1, stackDelta: 0 },
  35415. { id: 'dup', min: 1, stackDelta: 1 },
  35416. { id: 'exch', min: 2, stackDelta: 0 },
  35417. { id: 'index', min: 2, stackDelta: 0 },
  35418. { id: 'roll', min: 3, stackDelta: -2 },
  35419. null,
  35420. null,
  35421. null,
  35422. { id: 'hflex', min: 7, resetStack: true },
  35423. { id: 'flex', min: 13, resetStack: true },
  35424. { id: 'hflex1', min: 9, resetStack: true },
  35425. { id: 'flex1', min: 11, resetStack: true }
  35426. ];
  35427. function CFFParser(file, properties) {
  35428. this.bytes = file.getBytes();
  35429. this.properties = properties;
  35430. }
  35431. CFFParser.prototype = {
  35432. parse: function CFFParser_parse() {
  35433. var properties = this.properties;
  35434. var cff = new CFF();
  35435. this.cff = cff;
  35436. // The first five sections must be in order, all the others are reached
  35437. // via offsets contained in one of the below.
  35438. var header = this.parseHeader();
  35439. var nameIndex = this.parseIndex(header.endPos);
  35440. var topDictIndex = this.parseIndex(nameIndex.endPos);
  35441. var stringIndex = this.parseIndex(topDictIndex.endPos);
  35442. var globalSubrIndex = this.parseIndex(stringIndex.endPos);
  35443. var topDictParsed = this.parseDict(topDictIndex.obj.get(0));
  35444. var topDict = this.createDict(CFFTopDict, topDictParsed, cff.strings);
  35445. cff.header = header.obj;
  35446. cff.names = this.parseNameIndex(nameIndex.obj);
  35447. cff.strings = this.parseStringIndex(stringIndex.obj);
  35448. cff.topDict = topDict;
  35449. cff.globalSubrIndex = globalSubrIndex.obj;
  35450. this.parsePrivateDict(cff.topDict);
  35451. cff.isCIDFont = topDict.hasName('ROS');
  35452. var charStringOffset = topDict.getByName('CharStrings');
  35453. var charStringsAndSeacs = this.parseCharStrings(charStringOffset);
  35454. cff.charStrings = charStringsAndSeacs.charStrings;
  35455. cff.seacs = charStringsAndSeacs.seacs;
  35456. cff.widths = charStringsAndSeacs.widths;
  35457. var fontMatrix = topDict.getByName('FontMatrix');
  35458. if (fontMatrix) {
  35459. properties.fontMatrix = fontMatrix;
  35460. }
  35461. var fontBBox = topDict.getByName('FontBBox');
  35462. if (fontBBox) {
  35463. // adjusting ascent/descent
  35464. properties.ascent = fontBBox[3];
  35465. properties.descent = fontBBox[1];
  35466. properties.ascentScaled = true;
  35467. }
  35468. var charset, encoding;
  35469. if (cff.isCIDFont) {
  35470. var fdArrayIndex = this.parseIndex(topDict.getByName('FDArray')).obj;
  35471. for (var i = 0, ii = fdArrayIndex.count; i < ii; ++i) {
  35472. var dictRaw = fdArrayIndex.get(i);
  35473. var fontDict = this.createDict(CFFTopDict, this.parseDict(dictRaw),
  35474. cff.strings);
  35475. this.parsePrivateDict(fontDict);
  35476. cff.fdArray.push(fontDict);
  35477. }
  35478. // cid fonts don't have an encoding
  35479. encoding = null;
  35480. charset = this.parseCharsets(topDict.getByName('charset'),
  35481. cff.charStrings.count, cff.strings, true);
  35482. cff.fdSelect = this.parseFDSelect(topDict.getByName('FDSelect'),
  35483. cff.charStrings.count);
  35484. } else {
  35485. charset = this.parseCharsets(topDict.getByName('charset'),
  35486. cff.charStrings.count, cff.strings, false);
  35487. encoding = this.parseEncoding(topDict.getByName('Encoding'),
  35488. properties,
  35489. cff.strings, charset.charset);
  35490. }
  35491. cff.charset = charset;
  35492. cff.encoding = encoding;
  35493. return cff;
  35494. },
  35495. parseHeader: function CFFParser_parseHeader() {
  35496. var bytes = this.bytes;
  35497. var bytesLength = bytes.length;
  35498. var offset = 0;
  35499. // Prevent an infinite loop, by checking that the offset is within the
  35500. // bounds of the bytes array. Necessary in empty, or invalid, font files.
  35501. while (offset < bytesLength && bytes[offset] !== 1) {
  35502. ++offset;
  35503. }
  35504. if (offset >= bytesLength) {
  35505. error('Invalid CFF header');
  35506. } else if (offset !== 0) {
  35507. info('cff data is shifted');
  35508. bytes = bytes.subarray(offset);
  35509. this.bytes = bytes;
  35510. }
  35511. var major = bytes[0];
  35512. var minor = bytes[1];
  35513. var hdrSize = bytes[2];
  35514. var offSize = bytes[3];
  35515. var header = new CFFHeader(major, minor, hdrSize, offSize);
  35516. return { obj: header, endPos: hdrSize };
  35517. },
  35518. parseDict: function CFFParser_parseDict(dict) {
  35519. var pos = 0;
  35520. function parseOperand() {
  35521. var value = dict[pos++];
  35522. if (value === 30) {
  35523. return parseFloatOperand(pos);
  35524. } else if (value === 28) {
  35525. value = dict[pos++];
  35526. value = ((value << 24) | (dict[pos++] << 16)) >> 16;
  35527. return value;
  35528. } else if (value === 29) {
  35529. value = dict[pos++];
  35530. value = (value << 8) | dict[pos++];
  35531. value = (value << 8) | dict[pos++];
  35532. value = (value << 8) | dict[pos++];
  35533. return value;
  35534. } else if (value >= 32 && value <= 246) {
  35535. return value - 139;
  35536. } else if (value >= 247 && value <= 250) {
  35537. return ((value - 247) * 256) + dict[pos++] + 108;
  35538. } else if (value >= 251 && value <= 254) {
  35539. return -((value - 251) * 256) - dict[pos++] - 108;
  35540. } else {
  35541. error('255 is not a valid DICT command');
  35542. }
  35543. return -1;
  35544. }
  35545. function parseFloatOperand() {
  35546. var str = '';
  35547. var eof = 15;
  35548. var lookup = ['0', '1', '2', '3', '4', '5', '6', '7', '8',
  35549. '9', '.', 'E', 'E-', null, '-'];
  35550. var length = dict.length;
  35551. while (pos < length) {
  35552. var b = dict[pos++];
  35553. var b1 = b >> 4;
  35554. var b2 = b & 15;
  35555. if (b1 === eof) {
  35556. break;
  35557. }
  35558. str += lookup[b1];
  35559. if (b2 === eof) {
  35560. break;
  35561. }
  35562. str += lookup[b2];
  35563. }
  35564. return parseFloat(str);
  35565. }
  35566. var operands = [];
  35567. var entries = [];
  35568. pos = 0;
  35569. var end = dict.length;
  35570. while (pos < end) {
  35571. var b = dict[pos];
  35572. if (b <= 21) {
  35573. if (b === 12) {
  35574. b = (b << 8) | dict[++pos];
  35575. }
  35576. entries.push([b, operands]);
  35577. operands = [];
  35578. ++pos;
  35579. } else {
  35580. operands.push(parseOperand());
  35581. }
  35582. }
  35583. return entries;
  35584. },
  35585. parseIndex: function CFFParser_parseIndex(pos) {
  35586. var cffIndex = new CFFIndex();
  35587. var bytes = this.bytes;
  35588. var count = (bytes[pos++] << 8) | bytes[pos++];
  35589. var offsets = [];
  35590. var end = pos;
  35591. var i, ii;
  35592. if (count !== 0) {
  35593. var offsetSize = bytes[pos++];
  35594. // add 1 for offset to determine size of last object
  35595. var startPos = pos + ((count + 1) * offsetSize) - 1;
  35596. for (i = 0, ii = count + 1; i < ii; ++i) {
  35597. var offset = 0;
  35598. for (var j = 0; j < offsetSize; ++j) {
  35599. offset <<= 8;
  35600. offset += bytes[pos++];
  35601. }
  35602. offsets.push(startPos + offset);
  35603. }
  35604. end = offsets[count];
  35605. }
  35606. for (i = 0, ii = offsets.length - 1; i < ii; ++i) {
  35607. var offsetStart = offsets[i];
  35608. var offsetEnd = offsets[i + 1];
  35609. cffIndex.add(bytes.subarray(offsetStart, offsetEnd));
  35610. }
  35611. return {obj: cffIndex, endPos: end};
  35612. },
  35613. parseNameIndex: function CFFParser_parseNameIndex(index) {
  35614. var names = [];
  35615. for (var i = 0, ii = index.count; i < ii; ++i) {
  35616. var name = index.get(i);
  35617. // OTS doesn't allow names to be over 127 characters.
  35618. var length = Math.min(name.length, 127);
  35619. var data = [];
  35620. // OTS also only permits certain characters in the name.
  35621. for (var j = 0; j < length; ++j) {
  35622. var c = name[j];
  35623. if (j === 0 && c === 0) {
  35624. data[j] = c;
  35625. continue;
  35626. }
  35627. if ((c < 33 || c > 126) || c === 91 /* [ */ || c === 93 /* ] */ ||
  35628. c === 40 /* ( */ || c === 41 /* ) */ || c === 123 /* { */ ||
  35629. c === 125 /* } */ || c === 60 /* < */ || c === 62 /* > */ ||
  35630. c === 47 /* / */ || c === 37 /* % */ || c === 35 /* # */) {
  35631. data[j] = 95;
  35632. continue;
  35633. }
  35634. data[j] = c;
  35635. }
  35636. names.push(bytesToString(data));
  35637. }
  35638. return names;
  35639. },
  35640. parseStringIndex: function CFFParser_parseStringIndex(index) {
  35641. var strings = new CFFStrings();
  35642. for (var i = 0, ii = index.count; i < ii; ++i) {
  35643. var data = index.get(i);
  35644. strings.add(bytesToString(data));
  35645. }
  35646. return strings;
  35647. },
  35648. createDict: function CFFParser_createDict(Type, dict, strings) {
  35649. var cffDict = new Type(strings);
  35650. for (var i = 0, ii = dict.length; i < ii; ++i) {
  35651. var pair = dict[i];
  35652. var key = pair[0];
  35653. var value = pair[1];
  35654. cffDict.setByKey(key, value);
  35655. }
  35656. return cffDict;
  35657. },
  35658. parseCharStrings: function CFFParser_parseCharStrings(charStringOffset) {
  35659. var charStrings = this.parseIndex(charStringOffset).obj;
  35660. var seacs = [];
  35661. var widths = [];
  35662. var count = charStrings.count;
  35663. for (var i = 0; i < count; i++) {
  35664. var charstring = charStrings.get(i);
  35665. var stackSize = 0;
  35666. var stack = [];
  35667. var undefStack = true;
  35668. var hints = 0;
  35669. var valid = true;
  35670. var data = charstring;
  35671. var length = data.length;
  35672. var firstStackClearing = true;
  35673. for (var j = 0; j < length;) {
  35674. var value = data[j++];
  35675. var validationCommand = null;
  35676. if (value === 12) {
  35677. var q = data[j++];
  35678. if (q === 0) {
  35679. // The CFF specification state that the 'dotsection' command
  35680. // (12, 0) is deprecated and treated as a no-op, but all Type2
  35681. // charstrings processors should support them. Unfortunately
  35682. // the font sanitizer don't. As a workaround the sequence (12, 0)
  35683. // is replaced by a useless (0, hmoveto).
  35684. data[j - 2] = 139;
  35685. data[j - 1] = 22;
  35686. stackSize = 0;
  35687. } else {
  35688. validationCommand = CharstringValidationData12[q];
  35689. }
  35690. } else if (value === 28) { // number (16 bit)
  35691. stack[stackSize] = ((data[j] << 24) | (data[j + 1] << 16)) >> 16;
  35692. j += 2;
  35693. stackSize++;
  35694. } else if (value === 14) {
  35695. if (stackSize >= 4) {
  35696. stackSize -= 4;
  35697. if (SEAC_ANALYSIS_ENABLED) {
  35698. seacs[i] = stack.slice(stackSize, stackSize + 4);
  35699. valid = false;
  35700. }
  35701. }
  35702. validationCommand = CharstringValidationData[value];
  35703. } else if (value >= 32 && value <= 246) { // number
  35704. stack[stackSize] = value - 139;
  35705. stackSize++;
  35706. } else if (value >= 247 && value <= 254) { // number (+1 bytes)
  35707. stack[stackSize] = (value < 251 ?
  35708. ((value - 247) << 8) + data[j] + 108 :
  35709. -((value - 251) << 8) - data[j] - 108);
  35710. j++;
  35711. stackSize++;
  35712. } else if (value === 255) { // number (32 bit)
  35713. stack[stackSize] = ((data[j] << 24) | (data[j + 1] << 16) |
  35714. (data[j + 2] << 8) | data[j + 3]) / 65536;
  35715. j += 4;
  35716. stackSize++;
  35717. } else if (value === 19 || value === 20) {
  35718. hints += stackSize >> 1;
  35719. j += (hints + 7) >> 3; // skipping right amount of hints flag data
  35720. stackSize %= 2;
  35721. validationCommand = CharstringValidationData[value];
  35722. } else {
  35723. validationCommand = CharstringValidationData[value];
  35724. }
  35725. if (validationCommand) {
  35726. if (validationCommand.stem) {
  35727. hints += stackSize >> 1;
  35728. }
  35729. if ('min' in validationCommand) {
  35730. if (!undefStack && stackSize < validationCommand.min) {
  35731. warn('Not enough parameters for ' + validationCommand.id +
  35732. '; actual: ' + stackSize +
  35733. ', expected: ' + validationCommand.min);
  35734. valid = false;
  35735. break;
  35736. }
  35737. }
  35738. if (firstStackClearing && validationCommand.stackClearing) {
  35739. firstStackClearing = false;
  35740. // the optional character width can be found before the first
  35741. // stack-clearing command arguments
  35742. stackSize -= validationCommand.min;
  35743. if (stackSize >= 2 && validationCommand.stem) {
  35744. // there are even amount of arguments for stem commands
  35745. stackSize %= 2;
  35746. } else if (stackSize > 1) {
  35747. warn('Found too many parameters for stack-clearing command');
  35748. }
  35749. if (stackSize > 0 && stack[stackSize - 1] >= 0) {
  35750. widths[i] = stack[stackSize - 1];
  35751. }
  35752. }
  35753. if ('stackDelta' in validationCommand) {
  35754. if ('stackFn' in validationCommand) {
  35755. validationCommand.stackFn(stack, stackSize);
  35756. }
  35757. stackSize += validationCommand.stackDelta;
  35758. } else if (validationCommand.stackClearing) {
  35759. stackSize = 0;
  35760. } else if (validationCommand.resetStack) {
  35761. stackSize = 0;
  35762. undefStack = false;
  35763. } else if (validationCommand.undefStack) {
  35764. stackSize = 0;
  35765. undefStack = true;
  35766. firstStackClearing = false;
  35767. }
  35768. }
  35769. }
  35770. if (!valid) {
  35771. // resetting invalid charstring to single 'endchar'
  35772. charStrings.set(i, new Uint8Array([14]));
  35773. }
  35774. }
  35775. return { charStrings: charStrings, seacs: seacs, widths: widths };
  35776. },
  35777. emptyPrivateDictionary:
  35778. function CFFParser_emptyPrivateDictionary(parentDict) {
  35779. var privateDict = this.createDict(CFFPrivateDict, [],
  35780. parentDict.strings);
  35781. parentDict.setByKey(18, [0, 0]);
  35782. parentDict.privateDict = privateDict;
  35783. },
  35784. parsePrivateDict: function CFFParser_parsePrivateDict(parentDict) {
  35785. // no private dict, do nothing
  35786. if (!parentDict.hasName('Private')) {
  35787. this.emptyPrivateDictionary(parentDict);
  35788. return;
  35789. }
  35790. var privateOffset = parentDict.getByName('Private');
  35791. // make sure the params are formatted correctly
  35792. if (!isArray(privateOffset) || privateOffset.length !== 2) {
  35793. parentDict.removeByName('Private');
  35794. return;
  35795. }
  35796. var size = privateOffset[0];
  35797. var offset = privateOffset[1];
  35798. // remove empty dicts or ones that refer to invalid location
  35799. if (size === 0 || offset >= this.bytes.length) {
  35800. this.emptyPrivateDictionary(parentDict);
  35801. return;
  35802. }
  35803. var privateDictEnd = offset + size;
  35804. var dictData = this.bytes.subarray(offset, privateDictEnd);
  35805. var dict = this.parseDict(dictData);
  35806. var privateDict = this.createDict(CFFPrivateDict, dict,
  35807. parentDict.strings);
  35808. parentDict.privateDict = privateDict;
  35809. // Parse the Subrs index also since it's relative to the private dict.
  35810. if (!privateDict.getByName('Subrs')) {
  35811. return;
  35812. }
  35813. var subrsOffset = privateDict.getByName('Subrs');
  35814. var relativeOffset = offset + subrsOffset;
  35815. // Validate the offset.
  35816. if (subrsOffset === 0 || relativeOffset >= this.bytes.length) {
  35817. this.emptyPrivateDictionary(parentDict);
  35818. return;
  35819. }
  35820. var subrsIndex = this.parseIndex(relativeOffset);
  35821. privateDict.subrsIndex = subrsIndex.obj;
  35822. },
  35823. parseCharsets: function CFFParser_parseCharsets(pos, length, strings, cid) {
  35824. if (pos === 0) {
  35825. return new CFFCharset(true, CFFCharsetPredefinedTypes.ISO_ADOBE,
  35826. ISOAdobeCharset);
  35827. } else if (pos === 1) {
  35828. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT,
  35829. ExpertCharset);
  35830. } else if (pos === 2) {
  35831. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT_SUBSET,
  35832. ExpertSubsetCharset);
  35833. }
  35834. var bytes = this.bytes;
  35835. var start = pos;
  35836. var format = bytes[pos++];
  35837. var charset = ['.notdef'];
  35838. var id, count, i;
  35839. // subtract 1 for the .notdef glyph
  35840. length -= 1;
  35841. switch (format) {
  35842. case 0:
  35843. for (i = 0; i < length; i++) {
  35844. id = (bytes[pos++] << 8) | bytes[pos++];
  35845. charset.push(cid ? id : strings.get(id));
  35846. }
  35847. break;
  35848. case 1:
  35849. while (charset.length <= length) {
  35850. id = (bytes[pos++] << 8) | bytes[pos++];
  35851. count = bytes[pos++];
  35852. for (i = 0; i <= count; i++) {
  35853. charset.push(cid ? id++ : strings.get(id++));
  35854. }
  35855. }
  35856. break;
  35857. case 2:
  35858. while (charset.length <= length) {
  35859. id = (bytes[pos++] << 8) | bytes[pos++];
  35860. count = (bytes[pos++] << 8) | bytes[pos++];
  35861. for (i = 0; i <= count; i++) {
  35862. charset.push(cid ? id++ : strings.get(id++));
  35863. }
  35864. }
  35865. break;
  35866. default:
  35867. error('Unknown charset format');
  35868. }
  35869. // Raw won't be needed if we actually compile the charset.
  35870. var end = pos;
  35871. var raw = bytes.subarray(start, end);
  35872. return new CFFCharset(false, format, charset, raw);
  35873. },
  35874. parseEncoding: function CFFParser_parseEncoding(pos,
  35875. properties,
  35876. strings,
  35877. charset) {
  35878. var encoding = {};
  35879. var bytes = this.bytes;
  35880. var predefined = false;
  35881. var hasSupplement = false;
  35882. var format, i, ii;
  35883. var raw = null;
  35884. function readSupplement() {
  35885. var supplementsCount = bytes[pos++];
  35886. for (i = 0; i < supplementsCount; i++) {
  35887. var code = bytes[pos++];
  35888. var sid = (bytes[pos++] << 8) + (bytes[pos++] & 0xff);
  35889. encoding[code] = charset.indexOf(strings.get(sid));
  35890. }
  35891. }
  35892. if (pos === 0 || pos === 1) {
  35893. predefined = true;
  35894. format = pos;
  35895. var baseEncoding = pos ? Encodings.ExpertEncoding :
  35896. Encodings.StandardEncoding;
  35897. for (i = 0, ii = charset.length; i < ii; i++) {
  35898. var index = baseEncoding.indexOf(charset[i]);
  35899. if (index !== -1) {
  35900. encoding[index] = i;
  35901. }
  35902. }
  35903. } else {
  35904. var dataStart = pos;
  35905. format = bytes[pos++];
  35906. switch (format & 0x7f) {
  35907. case 0:
  35908. var glyphsCount = bytes[pos++];
  35909. for (i = 1; i <= glyphsCount; i++) {
  35910. encoding[bytes[pos++]] = i;
  35911. }
  35912. break;
  35913. case 1:
  35914. var rangesCount = bytes[pos++];
  35915. var gid = 1;
  35916. for (i = 0; i < rangesCount; i++) {
  35917. var start = bytes[pos++];
  35918. var left = bytes[pos++];
  35919. for (var j = start; j <= start + left; j++) {
  35920. encoding[j] = gid++;
  35921. }
  35922. }
  35923. break;
  35924. default:
  35925. error('Unknow encoding format: ' + format + ' in CFF');
  35926. break;
  35927. }
  35928. var dataEnd = pos;
  35929. if (format & 0x80) {
  35930. // The font sanitizer does not support CFF encoding with a
  35931. // supplement, since the encoding is not really used to map
  35932. // between gid to glyph, let's overwrite what is declared in
  35933. // the top dictionary to let the sanitizer think the font use
  35934. // StandardEncoding, that's a lie but that's ok.
  35935. bytes[dataStart] &= 0x7f;
  35936. readSupplement();
  35937. hasSupplement = true;
  35938. }
  35939. raw = bytes.subarray(dataStart, dataEnd);
  35940. }
  35941. format = format & 0x7f;
  35942. return new CFFEncoding(predefined, format, encoding, raw);
  35943. },
  35944. parseFDSelect: function CFFParser_parseFDSelect(pos, length) {
  35945. var start = pos;
  35946. var bytes = this.bytes;
  35947. var format = bytes[pos++];
  35948. var fdSelect = [];
  35949. var i;
  35950. switch (format) {
  35951. case 0:
  35952. for (i = 0; i < length; ++i) {
  35953. var id = bytes[pos++];
  35954. fdSelect.push(id);
  35955. }
  35956. break;
  35957. case 3:
  35958. var rangesCount = (bytes[pos++] << 8) | bytes[pos++];
  35959. for (i = 0; i < rangesCount; ++i) {
  35960. var first = (bytes[pos++] << 8) | bytes[pos++];
  35961. var fdIndex = bytes[pos++];
  35962. var next = (bytes[pos] << 8) | bytes[pos + 1];
  35963. for (var j = first; j < next; ++j) {
  35964. fdSelect.push(fdIndex);
  35965. }
  35966. }
  35967. // Advance past the sentinel(next).
  35968. pos += 2;
  35969. break;
  35970. default:
  35971. error('Unknown fdselect format ' + format);
  35972. break;
  35973. }
  35974. var end = pos;
  35975. return new CFFFDSelect(fdSelect, bytes.subarray(start, end));
  35976. }
  35977. };
  35978. return CFFParser;
  35979. })();
  35980. // Compact Font Format
  35981. var CFF = (function CFFClosure() {
  35982. function CFF() {
  35983. this.header = null;
  35984. this.names = [];
  35985. this.topDict = null;
  35986. this.strings = new CFFStrings();
  35987. this.globalSubrIndex = null;
  35988. // The following could really be per font, but since we only have one font
  35989. // store them here.
  35990. this.encoding = null;
  35991. this.charset = null;
  35992. this.charStrings = null;
  35993. this.fdArray = [];
  35994. this.fdSelect = null;
  35995. this.isCIDFont = false;
  35996. }
  35997. return CFF;
  35998. })();
  35999. var CFFHeader = (function CFFHeaderClosure() {
  36000. function CFFHeader(major, minor, hdrSize, offSize) {
  36001. this.major = major;
  36002. this.minor = minor;
  36003. this.hdrSize = hdrSize;
  36004. this.offSize = offSize;
  36005. }
  36006. return CFFHeader;
  36007. })();
  36008. var CFFStrings = (function CFFStringsClosure() {
  36009. function CFFStrings() {
  36010. this.strings = [];
  36011. }
  36012. CFFStrings.prototype = {
  36013. get: function CFFStrings_get(index) {
  36014. if (index >= 0 && index <= 390) {
  36015. return CFFStandardStrings[index];
  36016. }
  36017. if (index - 391 <= this.strings.length) {
  36018. return this.strings[index - 391];
  36019. }
  36020. return CFFStandardStrings[0];
  36021. },
  36022. add: function CFFStrings_add(value) {
  36023. this.strings.push(value);
  36024. },
  36025. get count() {
  36026. return this.strings.length;
  36027. }
  36028. };
  36029. return CFFStrings;
  36030. })();
  36031. var CFFIndex = (function CFFIndexClosure() {
  36032. function CFFIndex() {
  36033. this.objects = [];
  36034. this.length = 0;
  36035. }
  36036. CFFIndex.prototype = {
  36037. add: function CFFIndex_add(data) {
  36038. this.length += data.length;
  36039. this.objects.push(data);
  36040. },
  36041. set: function CFFIndex_set(index, data) {
  36042. this.length += data.length - this.objects[index].length;
  36043. this.objects[index] = data;
  36044. },
  36045. get: function CFFIndex_get(index) {
  36046. return this.objects[index];
  36047. },
  36048. get count() {
  36049. return this.objects.length;
  36050. }
  36051. };
  36052. return CFFIndex;
  36053. })();
  36054. var CFFDict = (function CFFDictClosure() {
  36055. function CFFDict(tables, strings) {
  36056. this.keyToNameMap = tables.keyToNameMap;
  36057. this.nameToKeyMap = tables.nameToKeyMap;
  36058. this.defaults = tables.defaults;
  36059. this.types = tables.types;
  36060. this.opcodes = tables.opcodes;
  36061. this.order = tables.order;
  36062. this.strings = strings;
  36063. this.values = {};
  36064. }
  36065. CFFDict.prototype = {
  36066. // value should always be an array
  36067. setByKey: function CFFDict_setByKey(key, value) {
  36068. if (!(key in this.keyToNameMap)) {
  36069. return false;
  36070. }
  36071. // ignore empty values
  36072. if (value.length === 0) {
  36073. return true;
  36074. }
  36075. var type = this.types[key];
  36076. // remove the array wrapping these types of values
  36077. if (type === 'num' || type === 'sid' || type === 'offset') {
  36078. value = value[0];
  36079. }
  36080. this.values[key] = value;
  36081. return true;
  36082. },
  36083. setByName: function CFFDict_setByName(name, value) {
  36084. if (!(name in this.nameToKeyMap)) {
  36085. error('Invalid dictionary name "' + name + '"');
  36086. }
  36087. this.values[this.nameToKeyMap[name]] = value;
  36088. },
  36089. hasName: function CFFDict_hasName(name) {
  36090. return this.nameToKeyMap[name] in this.values;
  36091. },
  36092. getByName: function CFFDict_getByName(name) {
  36093. if (!(name in this.nameToKeyMap)) {
  36094. error('Invalid dictionary name "' + name + '"');
  36095. }
  36096. var key = this.nameToKeyMap[name];
  36097. if (!(key in this.values)) {
  36098. return this.defaults[key];
  36099. }
  36100. return this.values[key];
  36101. },
  36102. removeByName: function CFFDict_removeByName(name) {
  36103. delete this.values[this.nameToKeyMap[name]];
  36104. }
  36105. };
  36106. CFFDict.createTables = function CFFDict_createTables(layout) {
  36107. var tables = {
  36108. keyToNameMap: {},
  36109. nameToKeyMap: {},
  36110. defaults: {},
  36111. types: {},
  36112. opcodes: {},
  36113. order: []
  36114. };
  36115. for (var i = 0, ii = layout.length; i < ii; ++i) {
  36116. var entry = layout[i];
  36117. var key = isArray(entry[0]) ? (entry[0][0] << 8) + entry[0][1] : entry[0];
  36118. tables.keyToNameMap[key] = entry[1];
  36119. tables.nameToKeyMap[entry[1]] = key;
  36120. tables.types[key] = entry[2];
  36121. tables.defaults[key] = entry[3];
  36122. tables.opcodes[key] = isArray(entry[0]) ? entry[0] : [entry[0]];
  36123. tables.order.push(key);
  36124. }
  36125. return tables;
  36126. };
  36127. return CFFDict;
  36128. })();
  36129. var CFFTopDict = (function CFFTopDictClosure() {
  36130. var layout = [
  36131. [[12, 30], 'ROS', ['sid', 'sid', 'num'], null],
  36132. [[12, 20], 'SyntheticBase', 'num', null],
  36133. [0, 'version', 'sid', null],
  36134. [1, 'Notice', 'sid', null],
  36135. [[12, 0], 'Copyright', 'sid', null],
  36136. [2, 'FullName', 'sid', null],
  36137. [3, 'FamilyName', 'sid', null],
  36138. [4, 'Weight', 'sid', null],
  36139. [[12, 1], 'isFixedPitch', 'num', 0],
  36140. [[12, 2], 'ItalicAngle', 'num', 0],
  36141. [[12, 3], 'UnderlinePosition', 'num', -100],
  36142. [[12, 4], 'UnderlineThickness', 'num', 50],
  36143. [[12, 5], 'PaintType', 'num', 0],
  36144. [[12, 6], 'CharstringType', 'num', 2],
  36145. [[12, 7], 'FontMatrix', ['num', 'num', 'num', 'num', 'num', 'num'],
  36146. [0.001, 0, 0, 0.001, 0, 0]],
  36147. [13, 'UniqueID', 'num', null],
  36148. [5, 'FontBBox', ['num', 'num', 'num', 'num'], [0, 0, 0, 0]],
  36149. [[12, 8], 'StrokeWidth', 'num', 0],
  36150. [14, 'XUID', 'array', null],
  36151. [15, 'charset', 'offset', 0],
  36152. [16, 'Encoding', 'offset', 0],
  36153. [17, 'CharStrings', 'offset', 0],
  36154. [18, 'Private', ['offset', 'offset'], null],
  36155. [[12, 21], 'PostScript', 'sid', null],
  36156. [[12, 22], 'BaseFontName', 'sid', null],
  36157. [[12, 23], 'BaseFontBlend', 'delta', null],
  36158. [[12, 31], 'CIDFontVersion', 'num', 0],
  36159. [[12, 32], 'CIDFontRevision', 'num', 0],
  36160. [[12, 33], 'CIDFontType', 'num', 0],
  36161. [[12, 34], 'CIDCount', 'num', 8720],
  36162. [[12, 35], 'UIDBase', 'num', null],
  36163. // XXX: CID Fonts on DirectWrite 6.1 only seem to work if FDSelect comes
  36164. // before FDArray.
  36165. [[12, 37], 'FDSelect', 'offset', null],
  36166. [[12, 36], 'FDArray', 'offset', null],
  36167. [[12, 38], 'FontName', 'sid', null]
  36168. ];
  36169. var tables = null;
  36170. function CFFTopDict(strings) {
  36171. if (tables === null) {
  36172. tables = CFFDict.createTables(layout);
  36173. }
  36174. CFFDict.call(this, tables, strings);
  36175. this.privateDict = null;
  36176. }
  36177. CFFTopDict.prototype = Object.create(CFFDict.prototype);
  36178. return CFFTopDict;
  36179. })();
  36180. var CFFPrivateDict = (function CFFPrivateDictClosure() {
  36181. var layout = [
  36182. [6, 'BlueValues', 'delta', null],
  36183. [7, 'OtherBlues', 'delta', null],
  36184. [8, 'FamilyBlues', 'delta', null],
  36185. [9, 'FamilyOtherBlues', 'delta', null],
  36186. [[12, 9], 'BlueScale', 'num', 0.039625],
  36187. [[12, 10], 'BlueShift', 'num', 7],
  36188. [[12, 11], 'BlueFuzz', 'num', 1],
  36189. [10, 'StdHW', 'num', null],
  36190. [11, 'StdVW', 'num', null],
  36191. [[12, 12], 'StemSnapH', 'delta', null],
  36192. [[12, 13], 'StemSnapV', 'delta', null],
  36193. [[12, 14], 'ForceBold', 'num', 0],
  36194. [[12, 17], 'LanguageGroup', 'num', 0],
  36195. [[12, 18], 'ExpansionFactor', 'num', 0.06],
  36196. [[12, 19], 'initialRandomSeed', 'num', 0],
  36197. [20, 'defaultWidthX', 'num', 0],
  36198. [21, 'nominalWidthX', 'num', 0],
  36199. [19, 'Subrs', 'offset', null]
  36200. ];
  36201. var tables = null;
  36202. function CFFPrivateDict(strings) {
  36203. if (tables === null) {
  36204. tables = CFFDict.createTables(layout);
  36205. }
  36206. CFFDict.call(this, tables, strings);
  36207. this.subrsIndex = null;
  36208. }
  36209. CFFPrivateDict.prototype = Object.create(CFFDict.prototype);
  36210. return CFFPrivateDict;
  36211. })();
  36212. var CFFCharsetPredefinedTypes = {
  36213. ISO_ADOBE: 0,
  36214. EXPERT: 1,
  36215. EXPERT_SUBSET: 2
  36216. };
  36217. var CFFCharset = (function CFFCharsetClosure() {
  36218. function CFFCharset(predefined, format, charset, raw) {
  36219. this.predefined = predefined;
  36220. this.format = format;
  36221. this.charset = charset;
  36222. this.raw = raw;
  36223. }
  36224. return CFFCharset;
  36225. })();
  36226. var CFFEncoding = (function CFFEncodingClosure() {
  36227. function CFFEncoding(predefined, format, encoding, raw) {
  36228. this.predefined = predefined;
  36229. this.format = format;
  36230. this.encoding = encoding;
  36231. this.raw = raw;
  36232. }
  36233. return CFFEncoding;
  36234. })();
  36235. var CFFFDSelect = (function CFFFDSelectClosure() {
  36236. function CFFFDSelect(fdSelect, raw) {
  36237. this.fdSelect = fdSelect;
  36238. this.raw = raw;
  36239. }
  36240. return CFFFDSelect;
  36241. })();
  36242. // Helper class to keep track of where an offset is within the data and helps
  36243. // filling in that offset once it's known.
  36244. var CFFOffsetTracker = (function CFFOffsetTrackerClosure() {
  36245. function CFFOffsetTracker() {
  36246. this.offsets = {};
  36247. }
  36248. CFFOffsetTracker.prototype = {
  36249. isTracking: function CFFOffsetTracker_isTracking(key) {
  36250. return key in this.offsets;
  36251. },
  36252. track: function CFFOffsetTracker_track(key, location) {
  36253. if (key in this.offsets) {
  36254. error('Already tracking location of ' + key);
  36255. }
  36256. this.offsets[key] = location;
  36257. },
  36258. offset: function CFFOffsetTracker_offset(value) {
  36259. for (var key in this.offsets) {
  36260. this.offsets[key] += value;
  36261. }
  36262. },
  36263. setEntryLocation: function CFFOffsetTracker_setEntryLocation(key,
  36264. values,
  36265. output) {
  36266. if (!(key in this.offsets)) {
  36267. error('Not tracking location of ' + key);
  36268. }
  36269. var data = output.data;
  36270. var dataOffset = this.offsets[key];
  36271. var size = 5;
  36272. for (var i = 0, ii = values.length; i < ii; ++i) {
  36273. var offset0 = i * size + dataOffset;
  36274. var offset1 = offset0 + 1;
  36275. var offset2 = offset0 + 2;
  36276. var offset3 = offset0 + 3;
  36277. var offset4 = offset0 + 4;
  36278. // It's easy to screw up offsets so perform this sanity check.
  36279. if (data[offset0] !== 0x1d || data[offset1] !== 0 ||
  36280. data[offset2] !== 0 || data[offset3] !== 0 || data[offset4] !== 0) {
  36281. error('writing to an offset that is not empty');
  36282. }
  36283. var value = values[i];
  36284. data[offset0] = 0x1d;
  36285. data[offset1] = (value >> 24) & 0xFF;
  36286. data[offset2] = (value >> 16) & 0xFF;
  36287. data[offset3] = (value >> 8) & 0xFF;
  36288. data[offset4] = value & 0xFF;
  36289. }
  36290. }
  36291. };
  36292. return CFFOffsetTracker;
  36293. })();
  36294. // Takes a CFF and converts it to the binary representation.
  36295. var CFFCompiler = (function CFFCompilerClosure() {
  36296. function CFFCompiler(cff) {
  36297. this.cff = cff;
  36298. }
  36299. CFFCompiler.prototype = {
  36300. compile: function CFFCompiler_compile() {
  36301. var cff = this.cff;
  36302. var output = {
  36303. data: [],
  36304. length: 0,
  36305. add: function CFFCompiler_add(data) {
  36306. this.data = this.data.concat(data);
  36307. this.length = this.data.length;
  36308. }
  36309. };
  36310. // Compile the five entries that must be in order.
  36311. var header = this.compileHeader(cff.header);
  36312. output.add(header);
  36313. var nameIndex = this.compileNameIndex(cff.names);
  36314. output.add(nameIndex);
  36315. if (cff.isCIDFont) {
  36316. // The spec is unclear on how font matrices should relate to each other
  36317. // when there is one in the main top dict and the sub top dicts.
  36318. // Windows handles this differently than linux and osx so we have to
  36319. // normalize to work on all.
  36320. // Rules based off of some mailing list discussions:
  36321. // - If main font has a matrix and subfont doesn't, use the main matrix.
  36322. // - If no main font matrix and there is a subfont matrix, use the
  36323. // subfont matrix.
  36324. // - If both have matrices, concat together.
  36325. // - If neither have matrices, use default.
  36326. // To make this work on all platforms we move the top matrix into each
  36327. // sub top dict and concat if necessary.
  36328. if (cff.topDict.hasName('FontMatrix')) {
  36329. var base = cff.topDict.getByName('FontMatrix');
  36330. cff.topDict.removeByName('FontMatrix');
  36331. for (var i = 0, ii = cff.fdArray.length; i < ii; i++) {
  36332. var subDict = cff.fdArray[i];
  36333. var matrix = base.slice(0);
  36334. if (subDict.hasName('FontMatrix')) {
  36335. matrix = Util.transform(matrix, subDict.getByName('FontMatrix'));
  36336. }
  36337. subDict.setByName('FontMatrix', matrix);
  36338. }
  36339. }
  36340. }
  36341. var compiled = this.compileTopDicts([cff.topDict],
  36342. output.length,
  36343. cff.isCIDFont);
  36344. output.add(compiled.output);
  36345. var topDictTracker = compiled.trackers[0];
  36346. var stringIndex = this.compileStringIndex(cff.strings.strings);
  36347. output.add(stringIndex);
  36348. var globalSubrIndex = this.compileIndex(cff.globalSubrIndex);
  36349. output.add(globalSubrIndex);
  36350. // Now start on the other entries that have no specfic order.
  36351. if (cff.encoding && cff.topDict.hasName('Encoding')) {
  36352. if (cff.encoding.predefined) {
  36353. topDictTracker.setEntryLocation('Encoding', [cff.encoding.format],
  36354. output);
  36355. } else {
  36356. var encoding = this.compileEncoding(cff.encoding);
  36357. topDictTracker.setEntryLocation('Encoding', [output.length], output);
  36358. output.add(encoding);
  36359. }
  36360. }
  36361. if (cff.charset && cff.topDict.hasName('charset')) {
  36362. if (cff.charset.predefined) {
  36363. topDictTracker.setEntryLocation('charset', [cff.charset.format],
  36364. output);
  36365. } else {
  36366. var charset = this.compileCharset(cff.charset);
  36367. topDictTracker.setEntryLocation('charset', [output.length], output);
  36368. output.add(charset);
  36369. }
  36370. }
  36371. var charStrings = this.compileCharStrings(cff.charStrings);
  36372. topDictTracker.setEntryLocation('CharStrings', [output.length], output);
  36373. output.add(charStrings);
  36374. if (cff.isCIDFont) {
  36375. // For some reason FDSelect must be in front of FDArray on windows. OSX
  36376. // and linux don't seem to care.
  36377. topDictTracker.setEntryLocation('FDSelect', [output.length], output);
  36378. var fdSelect = this.compileFDSelect(cff.fdSelect.raw);
  36379. output.add(fdSelect);
  36380. // It is unclear if the sub font dictionary can have CID related
  36381. // dictionary keys, but the sanitizer doesn't like them so remove them.
  36382. compiled = this.compileTopDicts(cff.fdArray, output.length, true);
  36383. topDictTracker.setEntryLocation('FDArray', [output.length], output);
  36384. output.add(compiled.output);
  36385. var fontDictTrackers = compiled.trackers;
  36386. this.compilePrivateDicts(cff.fdArray, fontDictTrackers, output);
  36387. }
  36388. this.compilePrivateDicts([cff.topDict], [topDictTracker], output);
  36389. // If the font data ends with INDEX whose object data is zero-length,
  36390. // the sanitizer will bail out. Add a dummy byte to avoid that.
  36391. output.add([0]);
  36392. return output.data;
  36393. },
  36394. encodeNumber: function CFFCompiler_encodeNumber(value) {
  36395. if (parseFloat(value) === parseInt(value, 10) && !isNaN(value)) { // isInt
  36396. return this.encodeInteger(value);
  36397. } else {
  36398. return this.encodeFloat(value);
  36399. }
  36400. },
  36401. encodeFloat: function CFFCompiler_encodeFloat(num) {
  36402. var value = num.toString();
  36403. // rounding inaccurate doubles
  36404. var m = /\.(\d*?)(?:9{5,20}|0{5,20})\d{0,2}(?:e(.+)|$)/.exec(value);
  36405. if (m) {
  36406. var epsilon = parseFloat('1e' + ((m[2] ? +m[2] : 0) + m[1].length));
  36407. value = (Math.round(num * epsilon) / epsilon).toString();
  36408. }
  36409. var nibbles = '';
  36410. var i, ii;
  36411. for (i = 0, ii = value.length; i < ii; ++i) {
  36412. var a = value[i];
  36413. if (a === 'e') {
  36414. nibbles += value[++i] === '-' ? 'c' : 'b';
  36415. } else if (a === '.') {
  36416. nibbles += 'a';
  36417. } else if (a === '-') {
  36418. nibbles += 'e';
  36419. } else {
  36420. nibbles += a;
  36421. }
  36422. }
  36423. nibbles += (nibbles.length & 1) ? 'f' : 'ff';
  36424. var out = [30];
  36425. for (i = 0, ii = nibbles.length; i < ii; i += 2) {
  36426. out.push(parseInt(nibbles.substr(i, 2), 16));
  36427. }
  36428. return out;
  36429. },
  36430. encodeInteger: function CFFCompiler_encodeInteger(value) {
  36431. var code;
  36432. if (value >= -107 && value <= 107) {
  36433. code = [value + 139];
  36434. } else if (value >= 108 && value <= 1131) {
  36435. value = [value - 108];
  36436. code = [(value >> 8) + 247, value & 0xFF];
  36437. } else if (value >= -1131 && value <= -108) {
  36438. value = -value - 108;
  36439. code = [(value >> 8) + 251, value & 0xFF];
  36440. } else if (value >= -32768 && value <= 32767) {
  36441. code = [0x1c, (value >> 8) & 0xFF, value & 0xFF];
  36442. } else {
  36443. code = [0x1d,
  36444. (value >> 24) & 0xFF,
  36445. (value >> 16) & 0xFF,
  36446. (value >> 8) & 0xFF,
  36447. value & 0xFF];
  36448. }
  36449. return code;
  36450. },
  36451. compileHeader: function CFFCompiler_compileHeader(header) {
  36452. return [
  36453. header.major,
  36454. header.minor,
  36455. header.hdrSize,
  36456. header.offSize
  36457. ];
  36458. },
  36459. compileNameIndex: function CFFCompiler_compileNameIndex(names) {
  36460. var nameIndex = new CFFIndex();
  36461. for (var i = 0, ii = names.length; i < ii; ++i) {
  36462. nameIndex.add(stringToBytes(names[i]));
  36463. }
  36464. return this.compileIndex(nameIndex);
  36465. },
  36466. compileTopDicts: function CFFCompiler_compileTopDicts(dicts,
  36467. length,
  36468. removeCidKeys) {
  36469. var fontDictTrackers = [];
  36470. var fdArrayIndex = new CFFIndex();
  36471. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  36472. var fontDict = dicts[i];
  36473. if (removeCidKeys) {
  36474. fontDict.removeByName('CIDFontVersion');
  36475. fontDict.removeByName('CIDFontRevision');
  36476. fontDict.removeByName('CIDFontType');
  36477. fontDict.removeByName('CIDCount');
  36478. fontDict.removeByName('UIDBase');
  36479. }
  36480. var fontDictTracker = new CFFOffsetTracker();
  36481. var fontDictData = this.compileDict(fontDict, fontDictTracker);
  36482. fontDictTrackers.push(fontDictTracker);
  36483. fdArrayIndex.add(fontDictData);
  36484. fontDictTracker.offset(length);
  36485. }
  36486. fdArrayIndex = this.compileIndex(fdArrayIndex, fontDictTrackers);
  36487. return {
  36488. trackers: fontDictTrackers,
  36489. output: fdArrayIndex
  36490. };
  36491. },
  36492. compilePrivateDicts: function CFFCompiler_compilePrivateDicts(dicts,
  36493. trackers,
  36494. output) {
  36495. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  36496. var fontDict = dicts[i];
  36497. assert(fontDict.privateDict && fontDict.hasName('Private'),
  36498. 'There must be an private dictionary.');
  36499. var privateDict = fontDict.privateDict;
  36500. var privateDictTracker = new CFFOffsetTracker();
  36501. var privateDictData = this.compileDict(privateDict, privateDictTracker);
  36502. var outputLength = output.length;
  36503. privateDictTracker.offset(outputLength);
  36504. if (!privateDictData.length) {
  36505. // The private dictionary was empty, set the output length to zero to
  36506. // ensure the offset length isn't out of bounds in the eyes of the
  36507. // sanitizer.
  36508. outputLength = 0;
  36509. }
  36510. trackers[i].setEntryLocation('Private',
  36511. [privateDictData.length, outputLength],
  36512. output);
  36513. output.add(privateDictData);
  36514. if (privateDict.subrsIndex && privateDict.hasName('Subrs')) {
  36515. var subrs = this.compileIndex(privateDict.subrsIndex);
  36516. privateDictTracker.setEntryLocation('Subrs', [privateDictData.length],
  36517. output);
  36518. output.add(subrs);
  36519. }
  36520. }
  36521. },
  36522. compileDict: function CFFCompiler_compileDict(dict, offsetTracker) {
  36523. var out = [];
  36524. // The dictionary keys must be in a certain order.
  36525. var order = dict.order;
  36526. for (var i = 0; i < order.length; ++i) {
  36527. var key = order[i];
  36528. if (!(key in dict.values)) {
  36529. continue;
  36530. }
  36531. var values = dict.values[key];
  36532. var types = dict.types[key];
  36533. if (!isArray(types)) {
  36534. types = [types];
  36535. }
  36536. if (!isArray(values)) {
  36537. values = [values];
  36538. }
  36539. // Remove any empty dict values.
  36540. if (values.length === 0) {
  36541. continue;
  36542. }
  36543. for (var j = 0, jj = types.length; j < jj; ++j) {
  36544. var type = types[j];
  36545. var value = values[j];
  36546. switch (type) {
  36547. case 'num':
  36548. case 'sid':
  36549. out = out.concat(this.encodeNumber(value));
  36550. break;
  36551. case 'offset':
  36552. // For offsets we just insert a 32bit integer so we don't have to
  36553. // deal with figuring out the length of the offset when it gets
  36554. // replaced later on by the compiler.
  36555. var name = dict.keyToNameMap[key];
  36556. // Some offsets have the offset and the length, so just record the
  36557. // position of the first one.
  36558. if (!offsetTracker.isTracking(name)) {
  36559. offsetTracker.track(name, out.length);
  36560. }
  36561. out = out.concat([0x1d, 0, 0, 0, 0]);
  36562. break;
  36563. case 'array':
  36564. case 'delta':
  36565. out = out.concat(this.encodeNumber(value));
  36566. for (var k = 1, kk = values.length; k < kk; ++k) {
  36567. out = out.concat(this.encodeNumber(values[k]));
  36568. }
  36569. break;
  36570. default:
  36571. error('Unknown data type of ' + type);
  36572. break;
  36573. }
  36574. }
  36575. out = out.concat(dict.opcodes[key]);
  36576. }
  36577. return out;
  36578. },
  36579. compileStringIndex: function CFFCompiler_compileStringIndex(strings) {
  36580. var stringIndex = new CFFIndex();
  36581. for (var i = 0, ii = strings.length; i < ii; ++i) {
  36582. stringIndex.add(stringToBytes(strings[i]));
  36583. }
  36584. return this.compileIndex(stringIndex);
  36585. },
  36586. compileGlobalSubrIndex: function CFFCompiler_compileGlobalSubrIndex() {
  36587. var globalSubrIndex = this.cff.globalSubrIndex;
  36588. this.out.writeByteArray(this.compileIndex(globalSubrIndex));
  36589. },
  36590. compileCharStrings: function CFFCompiler_compileCharStrings(charStrings) {
  36591. return this.compileIndex(charStrings);
  36592. },
  36593. compileCharset: function CFFCompiler_compileCharset(charset) {
  36594. return this.compileTypedArray(charset.raw);
  36595. },
  36596. compileEncoding: function CFFCompiler_compileEncoding(encoding) {
  36597. return this.compileTypedArray(encoding.raw);
  36598. },
  36599. compileFDSelect: function CFFCompiler_compileFDSelect(fdSelect) {
  36600. return this.compileTypedArray(fdSelect);
  36601. },
  36602. compileTypedArray: function CFFCompiler_compileTypedArray(data) {
  36603. var out = [];
  36604. for (var i = 0, ii = data.length; i < ii; ++i) {
  36605. out[i] = data[i];
  36606. }
  36607. return out;
  36608. },
  36609. compileIndex: function CFFCompiler_compileIndex(index, trackers) {
  36610. trackers = trackers || [];
  36611. var objects = index.objects;
  36612. // First 2 bytes contains the number of objects contained into this index
  36613. var count = objects.length;
  36614. // If there is no object, just create an index. This technically
  36615. // should just be [0, 0] but OTS has an issue with that.
  36616. if (count === 0) {
  36617. return [0, 0, 0];
  36618. }
  36619. var data = [(count >> 8) & 0xFF, count & 0xff];
  36620. var lastOffset = 1, i;
  36621. for (i = 0; i < count; ++i) {
  36622. lastOffset += objects[i].length;
  36623. }
  36624. var offsetSize;
  36625. if (lastOffset < 0x100) {
  36626. offsetSize = 1;
  36627. } else if (lastOffset < 0x10000) {
  36628. offsetSize = 2;
  36629. } else if (lastOffset < 0x1000000) {
  36630. offsetSize = 3;
  36631. } else {
  36632. offsetSize = 4;
  36633. }
  36634. // Next byte contains the offset size use to reference object in the file
  36635. data.push(offsetSize);
  36636. // Add another offset after this one because we need a new offset
  36637. var relativeOffset = 1;
  36638. for (i = 0; i < count + 1; i++) {
  36639. if (offsetSize === 1) {
  36640. data.push(relativeOffset & 0xFF);
  36641. } else if (offsetSize === 2) {
  36642. data.push((relativeOffset >> 8) & 0xFF,
  36643. relativeOffset & 0xFF);
  36644. } else if (offsetSize === 3) {
  36645. data.push((relativeOffset >> 16) & 0xFF,
  36646. (relativeOffset >> 8) & 0xFF,
  36647. relativeOffset & 0xFF);
  36648. } else {
  36649. data.push((relativeOffset >>> 24) & 0xFF,
  36650. (relativeOffset >> 16) & 0xFF,
  36651. (relativeOffset >> 8) & 0xFF,
  36652. relativeOffset & 0xFF);
  36653. }
  36654. if (objects[i]) {
  36655. relativeOffset += objects[i].length;
  36656. }
  36657. }
  36658. for (i = 0; i < count; i++) {
  36659. // Notify the tracker where the object will be offset in the data.
  36660. if (trackers[i]) {
  36661. trackers[i].offset(data.length);
  36662. }
  36663. for (var j = 0, jj = objects[i].length; j < jj; j++) {
  36664. data.push(objects[i][j]);
  36665. }
  36666. }
  36667. return data;
  36668. }
  36669. };
  36670. return CFFCompiler;
  36671. })();
  36672. function _enableSeacAnalysis(enabled) {
  36673. exports.SEAC_ANALYSIS_ENABLED = SEAC_ANALYSIS_ENABLED = enabled;
  36674. }
  36675. // Workaround for seac on Windows.
  36676. (function checkSeacSupport() {
  36677. if (typeof navigator !== 'undefined' && /Windows/.test(navigator.userAgent)) {
  36678. SEAC_ANALYSIS_ENABLED = true;
  36679. }
  36680. })();
  36681. // Workaround for Private Use Area characters in Chrome on Windows
  36682. // http://code.google.com/p/chromium/issues/detail?id=122465
  36683. // https://github.com/mozilla/pdf.js/issues/1689
  36684. (function checkChromeWindows() {
  36685. if (typeof navigator !== 'undefined' &&
  36686. /Windows.*Chrome/.test(navigator.userAgent)) {
  36687. SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = true;
  36688. }
  36689. })();
  36690. exports.SEAC_ANALYSIS_ENABLED = SEAC_ANALYSIS_ENABLED;
  36691. exports.CFFCompiler = CFFCompiler;
  36692. exports.CFFIndex = CFFIndex;
  36693. exports.CFFParser = CFFParser;
  36694. exports.CFFStrings = CFFStrings;
  36695. exports.Encodings = Encodings;
  36696. exports.ErrorFont = ErrorFont;
  36697. exports.FontFlags = FontFlags;
  36698. exports.Font = Font;
  36699. exports.IdentityToUnicodeMap = IdentityToUnicodeMap;
  36700. exports.NormalizedUnicodes = NormalizedUnicodes;
  36701. exports.ToUnicodeMap = ToUnicodeMap;
  36702. exports.Type1Parser = Type1Parser;
  36703. exports.getFontType = getFontType;
  36704. exports.reverseIfRtl = reverseIfRtl;
  36705. exports.serifFonts = serifFonts;
  36706. exports.symbolsFonts = symbolsFonts;
  36707. exports.stdFontMap = stdFontMap;
  36708. exports._enableSeacAnalysis = _enableSeacAnalysis;
  36709. // TODO refactor to remove cyclic dependency on font_renderer.js
  36710. coreFontRenderer._setCoreFonts(exports);
  36711. }));
  36712. (function (root, factory) {
  36713. {
  36714. factory((root.pdfjsCoreFunction = {}), root.pdfjsSharedUtil,
  36715. root.pdfjsCorePrimitives, root.pdfjsCorePsParser);
  36716. }
  36717. }(this, function (exports, sharedUtil, corePrimitives, corePsParser) {
  36718. var error = sharedUtil.error;
  36719. var info = sharedUtil.info;
  36720. var isArray = sharedUtil.isArray;
  36721. var isBool = sharedUtil.isBool;
  36722. var isDict = corePrimitives.isDict;
  36723. var isStream = corePrimitives.isStream;
  36724. var PostScriptLexer = corePsParser.PostScriptLexer;
  36725. var PostScriptParser = corePsParser.PostScriptParser;
  36726. var PDFFunction = (function PDFFunctionClosure() {
  36727. var CONSTRUCT_SAMPLED = 0;
  36728. var CONSTRUCT_INTERPOLATED = 2;
  36729. var CONSTRUCT_STICHED = 3;
  36730. var CONSTRUCT_POSTSCRIPT = 4;
  36731. return {
  36732. getSampleArray: function PDFFunction_getSampleArray(size, outputSize, bps,
  36733. str) {
  36734. var i, ii;
  36735. var length = 1;
  36736. for (i = 0, ii = size.length; i < ii; i++) {
  36737. length *= size[i];
  36738. }
  36739. length *= outputSize;
  36740. var array = new Array(length);
  36741. var codeSize = 0;
  36742. var codeBuf = 0;
  36743. // 32 is a valid bps so shifting won't work
  36744. var sampleMul = 1.0 / (Math.pow(2.0, bps) - 1);
  36745. var strBytes = str.getBytes((length * bps + 7) / 8);
  36746. var strIdx = 0;
  36747. for (i = 0; i < length; i++) {
  36748. while (codeSize < bps) {
  36749. codeBuf <<= 8;
  36750. codeBuf |= strBytes[strIdx++];
  36751. codeSize += 8;
  36752. }
  36753. codeSize -= bps;
  36754. array[i] = (codeBuf >> codeSize) * sampleMul;
  36755. codeBuf &= (1 << codeSize) - 1;
  36756. }
  36757. return array;
  36758. },
  36759. getIR: function PDFFunction_getIR(xref, fn) {
  36760. var dict = fn.dict;
  36761. if (!dict) {
  36762. dict = fn;
  36763. }
  36764. var types = [this.constructSampled,
  36765. null,
  36766. this.constructInterpolated,
  36767. this.constructStiched,
  36768. this.constructPostScript];
  36769. var typeNum = dict.get('FunctionType');
  36770. var typeFn = types[typeNum];
  36771. if (!typeFn) {
  36772. error('Unknown type of function');
  36773. }
  36774. return typeFn.call(this, fn, dict, xref);
  36775. },
  36776. fromIR: function PDFFunction_fromIR(IR) {
  36777. var type = IR[0];
  36778. switch (type) {
  36779. case CONSTRUCT_SAMPLED:
  36780. return this.constructSampledFromIR(IR);
  36781. case CONSTRUCT_INTERPOLATED:
  36782. return this.constructInterpolatedFromIR(IR);
  36783. case CONSTRUCT_STICHED:
  36784. return this.constructStichedFromIR(IR);
  36785. //case CONSTRUCT_POSTSCRIPT:
  36786. default:
  36787. return this.constructPostScriptFromIR(IR);
  36788. }
  36789. },
  36790. parse: function PDFFunction_parse(xref, fn) {
  36791. var IR = this.getIR(xref, fn);
  36792. return this.fromIR(IR);
  36793. },
  36794. parseArray: function PDFFunction_parseArray(xref, fnObj) {
  36795. if (!isArray(fnObj)) {
  36796. // not an array -- parsing as regular function
  36797. return this.parse(xref, fnObj);
  36798. }
  36799. var fnArray = [];
  36800. for (var j = 0, jj = fnObj.length; j < jj; j++) {
  36801. var obj = xref.fetchIfRef(fnObj[j]);
  36802. fnArray.push(PDFFunction.parse(xref, obj));
  36803. }
  36804. return function (src, srcOffset, dest, destOffset) {
  36805. for (var i = 0, ii = fnArray.length; i < ii; i++) {
  36806. fnArray[i](src, srcOffset, dest, destOffset + i);
  36807. }
  36808. };
  36809. },
  36810. constructSampled: function PDFFunction_constructSampled(str, dict) {
  36811. function toMultiArray(arr) {
  36812. var inputLength = arr.length;
  36813. var out = [];
  36814. var index = 0;
  36815. for (var i = 0; i < inputLength; i += 2) {
  36816. out[index] = [arr[i], arr[i + 1]];
  36817. ++index;
  36818. }
  36819. return out;
  36820. }
  36821. var domain = dict.get('Domain');
  36822. var range = dict.get('Range');
  36823. if (!domain || !range) {
  36824. error('No domain or range');
  36825. }
  36826. var inputSize = domain.length / 2;
  36827. var outputSize = range.length / 2;
  36828. domain = toMultiArray(domain);
  36829. range = toMultiArray(range);
  36830. var size = dict.get('Size');
  36831. var bps = dict.get('BitsPerSample');
  36832. var order = dict.get('Order') || 1;
  36833. if (order !== 1) {
  36834. // No description how cubic spline interpolation works in PDF32000:2008
  36835. // As in poppler, ignoring order, linear interpolation may work as good
  36836. info('No support for cubic spline interpolation: ' + order);
  36837. }
  36838. var encode = dict.get('Encode');
  36839. if (!encode) {
  36840. encode = [];
  36841. for (var i = 0; i < inputSize; ++i) {
  36842. encode.push(0);
  36843. encode.push(size[i] - 1);
  36844. }
  36845. }
  36846. encode = toMultiArray(encode);
  36847. var decode = dict.get('Decode');
  36848. if (!decode) {
  36849. decode = range;
  36850. } else {
  36851. decode = toMultiArray(decode);
  36852. }
  36853. var samples = this.getSampleArray(size, outputSize, bps, str);
  36854. return [
  36855. CONSTRUCT_SAMPLED, inputSize, domain, encode, decode, samples, size,
  36856. outputSize, Math.pow(2, bps) - 1, range
  36857. ];
  36858. },
  36859. constructSampledFromIR: function PDFFunction_constructSampledFromIR(IR) {
  36860. // See chapter 3, page 109 of the PDF reference
  36861. function interpolate(x, xmin, xmax, ymin, ymax) {
  36862. return ymin + ((x - xmin) * ((ymax - ymin) / (xmax - xmin)));
  36863. }
  36864. return function constructSampledFromIRResult(src, srcOffset,
  36865. dest, destOffset) {
  36866. // See chapter 3, page 110 of the PDF reference.
  36867. var m = IR[1];
  36868. var domain = IR[2];
  36869. var encode = IR[3];
  36870. var decode = IR[4];
  36871. var samples = IR[5];
  36872. var size = IR[6];
  36873. var n = IR[7];
  36874. //var mask = IR[8];
  36875. var range = IR[9];
  36876. // Building the cube vertices: its part and sample index
  36877. // http://rjwagner49.com/Mathematics/Interpolation.pdf
  36878. var cubeVertices = 1 << m;
  36879. var cubeN = new Float64Array(cubeVertices);
  36880. var cubeVertex = new Uint32Array(cubeVertices);
  36881. var i, j;
  36882. for (j = 0; j < cubeVertices; j++) {
  36883. cubeN[j] = 1;
  36884. }
  36885. var k = n, pos = 1;
  36886. // Map x_i to y_j for 0 <= i < m using the sampled function.
  36887. for (i = 0; i < m; ++i) {
  36888. // x_i' = min(max(x_i, Domain_2i), Domain_2i+1)
  36889. var domain_2i = domain[i][0];
  36890. var domain_2i_1 = domain[i][1];
  36891. var xi = Math.min(Math.max(src[srcOffset +i], domain_2i),
  36892. domain_2i_1);
  36893. // e_i = Interpolate(x_i', Domain_2i, Domain_2i+1,
  36894. // Encode_2i, Encode_2i+1)
  36895. var e = interpolate(xi, domain_2i, domain_2i_1,
  36896. encode[i][0], encode[i][1]);
  36897. // e_i' = min(max(e_i, 0), Size_i - 1)
  36898. var size_i = size[i];
  36899. e = Math.min(Math.max(e, 0), size_i - 1);
  36900. // Adjusting the cube: N and vertex sample index
  36901. var e0 = e < size_i - 1 ? Math.floor(e) : e - 1; // e1 = e0 + 1;
  36902. var n0 = e0 + 1 - e; // (e1 - e) / (e1 - e0);
  36903. var n1 = e - e0; // (e - e0) / (e1 - e0);
  36904. var offset0 = e0 * k;
  36905. var offset1 = offset0 + k; // e1 * k
  36906. for (j = 0; j < cubeVertices; j++) {
  36907. if (j & pos) {
  36908. cubeN[j] *= n1;
  36909. cubeVertex[j] += offset1;
  36910. } else {
  36911. cubeN[j] *= n0;
  36912. cubeVertex[j] += offset0;
  36913. }
  36914. }
  36915. k *= size_i;
  36916. pos <<= 1;
  36917. }
  36918. for (j = 0; j < n; ++j) {
  36919. // Sum all cube vertices' samples portions
  36920. var rj = 0;
  36921. for (i = 0; i < cubeVertices; i++) {
  36922. rj += samples[cubeVertex[i] + j] * cubeN[i];
  36923. }
  36924. // r_j' = Interpolate(r_j, 0, 2^BitsPerSample - 1,
  36925. // Decode_2j, Decode_2j+1)
  36926. rj = interpolate(rj, 0, 1, decode[j][0], decode[j][1]);
  36927. // y_j = min(max(r_j, range_2j), range_2j+1)
  36928. dest[destOffset + j] = Math.min(Math.max(rj, range[j][0]),
  36929. range[j][1]);
  36930. }
  36931. };
  36932. },
  36933. constructInterpolated: function PDFFunction_constructInterpolated(str,
  36934. dict) {
  36935. var c0 = dict.get('C0') || [0];
  36936. var c1 = dict.get('C1') || [1];
  36937. var n = dict.get('N');
  36938. if (!isArray(c0) || !isArray(c1)) {
  36939. error('Illegal dictionary for interpolated function');
  36940. }
  36941. var length = c0.length;
  36942. var diff = [];
  36943. for (var i = 0; i < length; ++i) {
  36944. diff.push(c1[i] - c0[i]);
  36945. }
  36946. return [CONSTRUCT_INTERPOLATED, c0, diff, n];
  36947. },
  36948. constructInterpolatedFromIR:
  36949. function PDFFunction_constructInterpolatedFromIR(IR) {
  36950. var c0 = IR[1];
  36951. var diff = IR[2];
  36952. var n = IR[3];
  36953. var length = diff.length;
  36954. return function constructInterpolatedFromIRResult(src, srcOffset,
  36955. dest, destOffset) {
  36956. var x = n === 1 ? src[srcOffset] : Math.pow(src[srcOffset], n);
  36957. for (var j = 0; j < length; ++j) {
  36958. dest[destOffset + j] = c0[j] + (x * diff[j]);
  36959. }
  36960. };
  36961. },
  36962. constructStiched: function PDFFunction_constructStiched(fn, dict, xref) {
  36963. var domain = dict.get('Domain');
  36964. if (!domain) {
  36965. error('No domain');
  36966. }
  36967. var inputSize = domain.length / 2;
  36968. if (inputSize !== 1) {
  36969. error('Bad domain for stiched function');
  36970. }
  36971. var fnRefs = dict.get('Functions');
  36972. var fns = [];
  36973. for (var i = 0, ii = fnRefs.length; i < ii; ++i) {
  36974. fns.push(PDFFunction.getIR(xref, xref.fetchIfRef(fnRefs[i])));
  36975. }
  36976. var bounds = dict.get('Bounds');
  36977. var encode = dict.get('Encode');
  36978. return [CONSTRUCT_STICHED, domain, bounds, encode, fns];
  36979. },
  36980. constructStichedFromIR: function PDFFunction_constructStichedFromIR(IR) {
  36981. var domain = IR[1];
  36982. var bounds = IR[2];
  36983. var encode = IR[3];
  36984. var fnsIR = IR[4];
  36985. var fns = [];
  36986. var tmpBuf = new Float32Array(1);
  36987. for (var i = 0, ii = fnsIR.length; i < ii; i++) {
  36988. fns.push(PDFFunction.fromIR(fnsIR[i]));
  36989. }
  36990. return function constructStichedFromIRResult(src, srcOffset,
  36991. dest, destOffset) {
  36992. var clip = function constructStichedFromIRClip(v, min, max) {
  36993. if (v > max) {
  36994. v = max;
  36995. } else if (v < min) {
  36996. v = min;
  36997. }
  36998. return v;
  36999. };
  37000. // clip to domain
  37001. var v = clip(src[srcOffset], domain[0], domain[1]);
  37002. // calulate which bound the value is in
  37003. for (var i = 0, ii = bounds.length; i < ii; ++i) {
  37004. if (v < bounds[i]) {
  37005. break;
  37006. }
  37007. }
  37008. // encode value into domain of function
  37009. var dmin = domain[0];
  37010. if (i > 0) {
  37011. dmin = bounds[i - 1];
  37012. }
  37013. var dmax = domain[1];
  37014. if (i < bounds.length) {
  37015. dmax = bounds[i];
  37016. }
  37017. var rmin = encode[2 * i];
  37018. var rmax = encode[2 * i + 1];
  37019. // Prevent the value from becoming NaN as a result
  37020. // of division by zero (fixes issue6113.pdf).
  37021. tmpBuf[0] = dmin === dmax ? rmin :
  37022. rmin + (v - dmin) * (rmax - rmin) / (dmax - dmin);
  37023. // call the appropriate function
  37024. fns[i](tmpBuf, 0, dest, destOffset);
  37025. };
  37026. },
  37027. constructPostScript: function PDFFunction_constructPostScript(fn, dict,
  37028. xref) {
  37029. var domain = dict.get('Domain');
  37030. var range = dict.get('Range');
  37031. if (!domain) {
  37032. error('No domain.');
  37033. }
  37034. if (!range) {
  37035. error('No range.');
  37036. }
  37037. var lexer = new PostScriptLexer(fn);
  37038. var parser = new PostScriptParser(lexer);
  37039. var code = parser.parse();
  37040. return [CONSTRUCT_POSTSCRIPT, domain, range, code];
  37041. },
  37042. constructPostScriptFromIR: function PDFFunction_constructPostScriptFromIR(
  37043. IR) {
  37044. var domain = IR[1];
  37045. var range = IR[2];
  37046. var code = IR[3];
  37047. var compiled = (new PostScriptCompiler()).compile(code, domain, range);
  37048. if (compiled) {
  37049. // Compiled function consists of simple expressions such as addition,
  37050. // subtraction, Math.max, and also contains 'var' and 'return'
  37051. // statements. See the generation in the PostScriptCompiler below.
  37052. /*jshint -W054 */
  37053. return new Function('src', 'srcOffset', 'dest', 'destOffset', compiled);
  37054. }
  37055. info('Unable to compile PS function');
  37056. var numOutputs = range.length >> 1;
  37057. var numInputs = domain.length >> 1;
  37058. var evaluator = new PostScriptEvaluator(code);
  37059. // Cache the values for a big speed up, the cache size is limited though
  37060. // since the number of possible values can be huge from a PS function.
  37061. var cache = {};
  37062. // The MAX_CACHE_SIZE is set to ~4x the maximum number of distinct values
  37063. // seen in our tests.
  37064. var MAX_CACHE_SIZE = 2048 * 4;
  37065. var cache_available = MAX_CACHE_SIZE;
  37066. var tmpBuf = new Float32Array(numInputs);
  37067. return function constructPostScriptFromIRResult(src, srcOffset,
  37068. dest, destOffset) {
  37069. var i, value;
  37070. var key = '';
  37071. var input = tmpBuf;
  37072. for (i = 0; i < numInputs; i++) {
  37073. value = src[srcOffset + i];
  37074. input[i] = value;
  37075. key += value + '_';
  37076. }
  37077. var cachedValue = cache[key];
  37078. if (cachedValue !== undefined) {
  37079. dest.set(cachedValue, destOffset);
  37080. return;
  37081. }
  37082. var output = new Float32Array(numOutputs);
  37083. var stack = evaluator.execute(input);
  37084. var stackIndex = stack.length - numOutputs;
  37085. for (i = 0; i < numOutputs; i++) {
  37086. value = stack[stackIndex + i];
  37087. var bound = range[i * 2];
  37088. if (value < bound) {
  37089. value = bound;
  37090. } else {
  37091. bound = range[i * 2 +1];
  37092. if (value > bound) {
  37093. value = bound;
  37094. }
  37095. }
  37096. output[i] = value;
  37097. }
  37098. if (cache_available > 0) {
  37099. cache_available--;
  37100. cache[key] = output;
  37101. }
  37102. dest.set(output, destOffset);
  37103. };
  37104. }
  37105. };
  37106. })();
  37107. function isPDFFunction(v) {
  37108. var fnDict;
  37109. if (typeof v !== 'object') {
  37110. return false;
  37111. } else if (isDict(v)) {
  37112. fnDict = v;
  37113. } else if (isStream(v)) {
  37114. fnDict = v.dict;
  37115. } else {
  37116. return false;
  37117. }
  37118. return fnDict.has('FunctionType');
  37119. }
  37120. var PostScriptStack = (function PostScriptStackClosure() {
  37121. var MAX_STACK_SIZE = 100;
  37122. function PostScriptStack(initialStack) {
  37123. this.stack = !initialStack ? [] :
  37124. Array.prototype.slice.call(initialStack, 0);
  37125. }
  37126. PostScriptStack.prototype = {
  37127. push: function PostScriptStack_push(value) {
  37128. if (this.stack.length >= MAX_STACK_SIZE) {
  37129. error('PostScript function stack overflow.');
  37130. }
  37131. this.stack.push(value);
  37132. },
  37133. pop: function PostScriptStack_pop() {
  37134. if (this.stack.length <= 0) {
  37135. error('PostScript function stack underflow.');
  37136. }
  37137. return this.stack.pop();
  37138. },
  37139. copy: function PostScriptStack_copy(n) {
  37140. if (this.stack.length + n >= MAX_STACK_SIZE) {
  37141. error('PostScript function stack overflow.');
  37142. }
  37143. var stack = this.stack;
  37144. for (var i = stack.length - n, j = n - 1; j >= 0; j--, i++) {
  37145. stack.push(stack[i]);
  37146. }
  37147. },
  37148. index: function PostScriptStack_index(n) {
  37149. this.push(this.stack[this.stack.length - n - 1]);
  37150. },
  37151. // rotate the last n stack elements p times
  37152. roll: function PostScriptStack_roll(n, p) {
  37153. var stack = this.stack;
  37154. var l = stack.length - n;
  37155. var r = stack.length - 1, c = l + (p - Math.floor(p / n) * n), i, j, t;
  37156. for (i = l, j = r; i < j; i++, j--) {
  37157. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  37158. }
  37159. for (i = l, j = c - 1; i < j; i++, j--) {
  37160. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  37161. }
  37162. for (i = c, j = r; i < j; i++, j--) {
  37163. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  37164. }
  37165. }
  37166. };
  37167. return PostScriptStack;
  37168. })();
  37169. var PostScriptEvaluator = (function PostScriptEvaluatorClosure() {
  37170. function PostScriptEvaluator(operators) {
  37171. this.operators = operators;
  37172. }
  37173. PostScriptEvaluator.prototype = {
  37174. execute: function PostScriptEvaluator_execute(initialStack) {
  37175. var stack = new PostScriptStack(initialStack);
  37176. var counter = 0;
  37177. var operators = this.operators;
  37178. var length = operators.length;
  37179. var operator, a, b;
  37180. while (counter < length) {
  37181. operator = operators[counter++];
  37182. if (typeof operator === 'number') {
  37183. // Operator is really an operand and should be pushed to the stack.
  37184. stack.push(operator);
  37185. continue;
  37186. }
  37187. switch (operator) {
  37188. // non standard ps operators
  37189. case 'jz': // jump if false
  37190. b = stack.pop();
  37191. a = stack.pop();
  37192. if (!a) {
  37193. counter = b;
  37194. }
  37195. break;
  37196. case 'j': // jump
  37197. a = stack.pop();
  37198. counter = a;
  37199. break;
  37200. // all ps operators in alphabetical order (excluding if/ifelse)
  37201. case 'abs':
  37202. a = stack.pop();
  37203. stack.push(Math.abs(a));
  37204. break;
  37205. case 'add':
  37206. b = stack.pop();
  37207. a = stack.pop();
  37208. stack.push(a + b);
  37209. break;
  37210. case 'and':
  37211. b = stack.pop();
  37212. a = stack.pop();
  37213. if (isBool(a) && isBool(b)) {
  37214. stack.push(a && b);
  37215. } else {
  37216. stack.push(a & b);
  37217. }
  37218. break;
  37219. case 'atan':
  37220. a = stack.pop();
  37221. stack.push(Math.atan(a));
  37222. break;
  37223. case 'bitshift':
  37224. b = stack.pop();
  37225. a = stack.pop();
  37226. if (a > 0) {
  37227. stack.push(a << b);
  37228. } else {
  37229. stack.push(a >> b);
  37230. }
  37231. break;
  37232. case 'ceiling':
  37233. a = stack.pop();
  37234. stack.push(Math.ceil(a));
  37235. break;
  37236. case 'copy':
  37237. a = stack.pop();
  37238. stack.copy(a);
  37239. break;
  37240. case 'cos':
  37241. a = stack.pop();
  37242. stack.push(Math.cos(a));
  37243. break;
  37244. case 'cvi':
  37245. a = stack.pop() | 0;
  37246. stack.push(a);
  37247. break;
  37248. case 'cvr':
  37249. // noop
  37250. break;
  37251. case 'div':
  37252. b = stack.pop();
  37253. a = stack.pop();
  37254. stack.push(a / b);
  37255. break;
  37256. case 'dup':
  37257. stack.copy(1);
  37258. break;
  37259. case 'eq':
  37260. b = stack.pop();
  37261. a = stack.pop();
  37262. stack.push(a === b);
  37263. break;
  37264. case 'exch':
  37265. stack.roll(2, 1);
  37266. break;
  37267. case 'exp':
  37268. b = stack.pop();
  37269. a = stack.pop();
  37270. stack.push(Math.pow(a, b));
  37271. break;
  37272. case 'false':
  37273. stack.push(false);
  37274. break;
  37275. case 'floor':
  37276. a = stack.pop();
  37277. stack.push(Math.floor(a));
  37278. break;
  37279. case 'ge':
  37280. b = stack.pop();
  37281. a = stack.pop();
  37282. stack.push(a >= b);
  37283. break;
  37284. case 'gt':
  37285. b = stack.pop();
  37286. a = stack.pop();
  37287. stack.push(a > b);
  37288. break;
  37289. case 'idiv':
  37290. b = stack.pop();
  37291. a = stack.pop();
  37292. stack.push((a / b) | 0);
  37293. break;
  37294. case 'index':
  37295. a = stack.pop();
  37296. stack.index(a);
  37297. break;
  37298. case 'le':
  37299. b = stack.pop();
  37300. a = stack.pop();
  37301. stack.push(a <= b);
  37302. break;
  37303. case 'ln':
  37304. a = stack.pop();
  37305. stack.push(Math.log(a));
  37306. break;
  37307. case 'log':
  37308. a = stack.pop();
  37309. stack.push(Math.log(a) / Math.LN10);
  37310. break;
  37311. case 'lt':
  37312. b = stack.pop();
  37313. a = stack.pop();
  37314. stack.push(a < b);
  37315. break;
  37316. case 'mod':
  37317. b = stack.pop();
  37318. a = stack.pop();
  37319. stack.push(a % b);
  37320. break;
  37321. case 'mul':
  37322. b = stack.pop();
  37323. a = stack.pop();
  37324. stack.push(a * b);
  37325. break;
  37326. case 'ne':
  37327. b = stack.pop();
  37328. a = stack.pop();
  37329. stack.push(a !== b);
  37330. break;
  37331. case 'neg':
  37332. a = stack.pop();
  37333. stack.push(-a);
  37334. break;
  37335. case 'not':
  37336. a = stack.pop();
  37337. if (isBool(a)) {
  37338. stack.push(!a);
  37339. } else {
  37340. stack.push(~a);
  37341. }
  37342. break;
  37343. case 'or':
  37344. b = stack.pop();
  37345. a = stack.pop();
  37346. if (isBool(a) && isBool(b)) {
  37347. stack.push(a || b);
  37348. } else {
  37349. stack.push(a | b);
  37350. }
  37351. break;
  37352. case 'pop':
  37353. stack.pop();
  37354. break;
  37355. case 'roll':
  37356. b = stack.pop();
  37357. a = stack.pop();
  37358. stack.roll(a, b);
  37359. break;
  37360. case 'round':
  37361. a = stack.pop();
  37362. stack.push(Math.round(a));
  37363. break;
  37364. case 'sin':
  37365. a = stack.pop();
  37366. stack.push(Math.sin(a));
  37367. break;
  37368. case 'sqrt':
  37369. a = stack.pop();
  37370. stack.push(Math.sqrt(a));
  37371. break;
  37372. case 'sub':
  37373. b = stack.pop();
  37374. a = stack.pop();
  37375. stack.push(a - b);
  37376. break;
  37377. case 'true':
  37378. stack.push(true);
  37379. break;
  37380. case 'truncate':
  37381. a = stack.pop();
  37382. a = a < 0 ? Math.ceil(a) : Math.floor(a);
  37383. stack.push(a);
  37384. break;
  37385. case 'xor':
  37386. b = stack.pop();
  37387. a = stack.pop();
  37388. if (isBool(a) && isBool(b)) {
  37389. stack.push(a !== b);
  37390. } else {
  37391. stack.push(a ^ b);
  37392. }
  37393. break;
  37394. default:
  37395. error('Unknown operator ' + operator);
  37396. break;
  37397. }
  37398. }
  37399. return stack.stack;
  37400. }
  37401. };
  37402. return PostScriptEvaluator;
  37403. })();
  37404. // Most of the PDFs functions consist of simple operations such as:
  37405. // roll, exch, sub, cvr, pop, index, dup, mul, if, gt, add.
  37406. //
  37407. // We can compile most of such programs, and at the same moment, we can
  37408. // optimize some expressions using basic math properties. Keeping track of
  37409. // min/max values will allow us to avoid extra Math.min/Math.max calls.
  37410. var PostScriptCompiler = (function PostScriptCompilerClosure() {
  37411. function AstNode(type) {
  37412. this.type = type;
  37413. }
  37414. AstNode.prototype.visit = function (visitor) {
  37415. throw new Error('abstract method');
  37416. };
  37417. function AstArgument(index, min, max) {
  37418. AstNode.call(this, 'args');
  37419. this.index = index;
  37420. this.min = min;
  37421. this.max = max;
  37422. }
  37423. AstArgument.prototype = Object.create(AstNode.prototype);
  37424. AstArgument.prototype.visit = function (visitor) {
  37425. visitor.visitArgument(this);
  37426. };
  37427. function AstLiteral(number) {
  37428. AstNode.call(this, 'literal');
  37429. this.number = number;
  37430. this.min = number;
  37431. this.max = number;
  37432. }
  37433. AstLiteral.prototype = Object.create(AstNode.prototype);
  37434. AstLiteral.prototype.visit = function (visitor) {
  37435. visitor.visitLiteral(this);
  37436. };
  37437. function AstBinaryOperation(op, arg1, arg2, min, max) {
  37438. AstNode.call(this, 'binary');
  37439. this.op = op;
  37440. this.arg1 = arg1;
  37441. this.arg2 = arg2;
  37442. this.min = min;
  37443. this.max = max;
  37444. }
  37445. AstBinaryOperation.prototype = Object.create(AstNode.prototype);
  37446. AstBinaryOperation.prototype.visit = function (visitor) {
  37447. visitor.visitBinaryOperation(this);
  37448. };
  37449. function AstMin(arg, max) {
  37450. AstNode.call(this, 'max');
  37451. this.arg = arg;
  37452. this.min = arg.min;
  37453. this.max = max;
  37454. }
  37455. AstMin.prototype = Object.create(AstNode.prototype);
  37456. AstMin.prototype.visit = function (visitor) {
  37457. visitor.visitMin(this);
  37458. };
  37459. function AstVariable(index, min, max) {
  37460. AstNode.call(this, 'var');
  37461. this.index = index;
  37462. this.min = min;
  37463. this.max = max;
  37464. }
  37465. AstVariable.prototype = Object.create(AstNode.prototype);
  37466. AstVariable.prototype.visit = function (visitor) {
  37467. visitor.visitVariable(this);
  37468. };
  37469. function AstVariableDefinition(variable, arg) {
  37470. AstNode.call(this, 'definition');
  37471. this.variable = variable;
  37472. this.arg = arg;
  37473. }
  37474. AstVariableDefinition.prototype = Object.create(AstNode.prototype);
  37475. AstVariableDefinition.prototype.visit = function (visitor) {
  37476. visitor.visitVariableDefinition(this);
  37477. };
  37478. function ExpressionBuilderVisitor() {
  37479. this.parts = [];
  37480. }
  37481. ExpressionBuilderVisitor.prototype = {
  37482. visitArgument: function (arg) {
  37483. this.parts.push('Math.max(', arg.min, ', Math.min(',
  37484. arg.max, ', src[srcOffset + ', arg.index, ']))');
  37485. },
  37486. visitVariable: function (variable) {
  37487. this.parts.push('v', variable.index);
  37488. },
  37489. visitLiteral: function (literal) {
  37490. this.parts.push(literal.number);
  37491. },
  37492. visitBinaryOperation: function (operation) {
  37493. this.parts.push('(');
  37494. operation.arg1.visit(this);
  37495. this.parts.push(' ', operation.op, ' ');
  37496. operation.arg2.visit(this);
  37497. this.parts.push(')');
  37498. },
  37499. visitVariableDefinition: function (definition) {
  37500. this.parts.push('var ');
  37501. definition.variable.visit(this);
  37502. this.parts.push(' = ');
  37503. definition.arg.visit(this);
  37504. this.parts.push(';');
  37505. },
  37506. visitMin: function (max) {
  37507. this.parts.push('Math.min(');
  37508. max.arg.visit(this);
  37509. this.parts.push(', ', max.max, ')');
  37510. },
  37511. toString: function () {
  37512. return this.parts.join('');
  37513. }
  37514. };
  37515. function buildAddOperation(num1, num2) {
  37516. if (num2.type === 'literal' && num2.number === 0) {
  37517. // optimization: second operand is 0
  37518. return num1;
  37519. }
  37520. if (num1.type === 'literal' && num1.number === 0) {
  37521. // optimization: first operand is 0
  37522. return num2;
  37523. }
  37524. if (num2.type === 'literal' && num1.type === 'literal') {
  37525. // optimization: operands operand are literals
  37526. return new AstLiteral(num1.number + num2.number);
  37527. }
  37528. return new AstBinaryOperation('+', num1, num2,
  37529. num1.min + num2.min, num1.max + num2.max);
  37530. }
  37531. function buildMulOperation(num1, num2) {
  37532. if (num2.type === 'literal') {
  37533. // optimization: second operands is a literal...
  37534. if (num2.number === 0) {
  37535. return new AstLiteral(0); // and it's 0
  37536. } else if (num2.number === 1) {
  37537. return num1; // and it's 1
  37538. } else if (num1.type === 'literal') {
  37539. // ... and first operands is a literal too
  37540. return new AstLiteral(num1.number * num2.number);
  37541. }
  37542. }
  37543. if (num1.type === 'literal') {
  37544. // optimization: first operands is a literal...
  37545. if (num1.number === 0) {
  37546. return new AstLiteral(0); // and it's 0
  37547. } else if (num1.number === 1) {
  37548. return num2; // and it's 1
  37549. }
  37550. }
  37551. var min = Math.min(num1.min * num2.min, num1.min * num2.max,
  37552. num1.max * num2.min, num1.max * num2.max);
  37553. var max = Math.max(num1.min * num2.min, num1.min * num2.max,
  37554. num1.max * num2.min, num1.max * num2.max);
  37555. return new AstBinaryOperation('*', num1, num2, min, max);
  37556. }
  37557. function buildSubOperation(num1, num2) {
  37558. if (num2.type === 'literal') {
  37559. // optimization: second operands is a literal...
  37560. if (num2.number === 0) {
  37561. return num1; // ... and it's 0
  37562. } else if (num1.type === 'literal') {
  37563. // ... and first operands is a literal too
  37564. return new AstLiteral(num1.number - num2.number);
  37565. }
  37566. }
  37567. if (num2.type === 'binary' && num2.op === '-' &&
  37568. num1.type === 'literal' && num1.number === 1 &&
  37569. num2.arg1.type === 'literal' && num2.arg1.number === 1) {
  37570. // optimization for case: 1 - (1 - x)
  37571. return num2.arg2;
  37572. }
  37573. return new AstBinaryOperation('-', num1, num2,
  37574. num1.min - num2.max, num1.max - num2.min);
  37575. }
  37576. function buildMinOperation(num1, max) {
  37577. if (num1.min >= max) {
  37578. // optimization: num1 min value is not less than required max
  37579. return new AstLiteral(max); // just returning max
  37580. } else if (num1.max <= max) {
  37581. // optimization: num1 max value is not greater than required max
  37582. return num1; // just returning an argument
  37583. }
  37584. return new AstMin(num1, max);
  37585. }
  37586. function PostScriptCompiler() {}
  37587. PostScriptCompiler.prototype = {
  37588. compile: function PostScriptCompiler_compile(code, domain, range) {
  37589. var stack = [];
  37590. var i, ii;
  37591. var instructions = [];
  37592. var inputSize = domain.length >> 1, outputSize = range.length >> 1;
  37593. var lastRegister = 0;
  37594. var n, j;
  37595. var num1, num2, ast1, ast2, tmpVar, item;
  37596. for (i = 0; i < inputSize; i++) {
  37597. stack.push(new AstArgument(i, domain[i * 2], domain[i * 2 + 1]));
  37598. }
  37599. for (i = 0, ii = code.length; i < ii; i++) {
  37600. item = code[i];
  37601. if (typeof item === 'number') {
  37602. stack.push(new AstLiteral(item));
  37603. continue;
  37604. }
  37605. switch (item) {
  37606. case 'add':
  37607. if (stack.length < 2) {
  37608. return null;
  37609. }
  37610. num2 = stack.pop();
  37611. num1 = stack.pop();
  37612. stack.push(buildAddOperation(num1, num2));
  37613. break;
  37614. case 'cvr':
  37615. if (stack.length < 1) {
  37616. return null;
  37617. }
  37618. break;
  37619. case 'mul':
  37620. if (stack.length < 2) {
  37621. return null;
  37622. }
  37623. num2 = stack.pop();
  37624. num1 = stack.pop();
  37625. stack.push(buildMulOperation(num1, num2));
  37626. break;
  37627. case 'sub':
  37628. if (stack.length < 2) {
  37629. return null;
  37630. }
  37631. num2 = stack.pop();
  37632. num1 = stack.pop();
  37633. stack.push(buildSubOperation(num1, num2));
  37634. break;
  37635. case 'exch':
  37636. if (stack.length < 2) {
  37637. return null;
  37638. }
  37639. ast1 = stack.pop(); ast2 = stack.pop();
  37640. stack.push(ast1, ast2);
  37641. break;
  37642. case 'pop':
  37643. if (stack.length < 1) {
  37644. return null;
  37645. }
  37646. stack.pop();
  37647. break;
  37648. case 'index':
  37649. if (stack.length < 1) {
  37650. return null;
  37651. }
  37652. num1 = stack.pop();
  37653. if (num1.type !== 'literal') {
  37654. return null;
  37655. }
  37656. n = num1.number;
  37657. if (n < 0 || (n|0) !== n || stack.length < n) {
  37658. return null;
  37659. }
  37660. ast1 = stack[stack.length - n - 1];
  37661. if (ast1.type === 'literal' || ast1.type === 'var') {
  37662. stack.push(ast1);
  37663. break;
  37664. }
  37665. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  37666. stack[stack.length - n - 1] = tmpVar;
  37667. stack.push(tmpVar);
  37668. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  37669. break;
  37670. case 'dup':
  37671. if (stack.length < 1) {
  37672. return null;
  37673. }
  37674. if (typeof code[i + 1] === 'number' && code[i + 2] === 'gt' &&
  37675. code[i + 3] === i + 7 && code[i + 4] === 'jz' &&
  37676. code[i + 5] === 'pop' && code[i + 6] === code[i + 1]) {
  37677. // special case of the commands sequence for the min operation
  37678. num1 = stack.pop();
  37679. stack.push(buildMinOperation(num1, code[i + 1]));
  37680. i += 6;
  37681. break;
  37682. }
  37683. ast1 = stack[stack.length - 1];
  37684. if (ast1.type === 'literal' || ast1.type === 'var') {
  37685. // we don't have to save into intermediate variable a literal or
  37686. // variable.
  37687. stack.push(ast1);
  37688. break;
  37689. }
  37690. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  37691. stack[stack.length - 1] = tmpVar;
  37692. stack.push(tmpVar);
  37693. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  37694. break;
  37695. case 'roll':
  37696. if (stack.length < 2) {
  37697. return null;
  37698. }
  37699. num2 = stack.pop();
  37700. num1 = stack.pop();
  37701. if (num2.type !== 'literal' || num1.type !== 'literal') {
  37702. // both roll operands must be numbers
  37703. return null;
  37704. }
  37705. j = num2.number;
  37706. n = num1.number;
  37707. if (n <= 0 || (n|0) !== n || (j|0) !== j || stack.length < n) {
  37708. // ... and integers
  37709. return null;
  37710. }
  37711. j = ((j % n) + n) % n;
  37712. if (j === 0) {
  37713. break; // just skipping -- there are nothing to rotate
  37714. }
  37715. Array.prototype.push.apply(stack,
  37716. stack.splice(stack.length - n, n - j));
  37717. break;
  37718. default:
  37719. return null; // unsupported operator
  37720. }
  37721. }
  37722. if (stack.length !== outputSize) {
  37723. return null;
  37724. }
  37725. var result = [];
  37726. instructions.forEach(function (instruction) {
  37727. var statementBuilder = new ExpressionBuilderVisitor();
  37728. instruction.visit(statementBuilder);
  37729. result.push(statementBuilder.toString());
  37730. });
  37731. stack.forEach(function (expr, i) {
  37732. var statementBuilder = new ExpressionBuilderVisitor();
  37733. expr.visit(statementBuilder);
  37734. var min = range[i * 2], max = range[i * 2 + 1];
  37735. var out = [statementBuilder.toString()];
  37736. if (min > expr.min) {
  37737. out.unshift('Math.max(', min, ', ');
  37738. out.push(')');
  37739. }
  37740. if (max < expr.max) {
  37741. out.unshift('Math.min(', max, ', ');
  37742. out.push(')');
  37743. }
  37744. out.unshift('dest[destOffset + ', i, '] = ');
  37745. out.push(';');
  37746. result.push(out.join(''));
  37747. });
  37748. return result.join('\n');
  37749. }
  37750. };
  37751. return PostScriptCompiler;
  37752. })();
  37753. exports.isPDFFunction = isPDFFunction;
  37754. exports.PDFFunction = PDFFunction;
  37755. exports.PostScriptEvaluator = PostScriptEvaluator;
  37756. exports.PostScriptCompiler = PostScriptCompiler;
  37757. }));
  37758. (function (root, factory) {
  37759. {
  37760. factory((root.pdfjsCoreColorSpace = {}), root.pdfjsSharedUtil,
  37761. root.pdfjsCorePrimitives, root.pdfjsCoreFunction, root.pdfjsCoreStream);
  37762. }
  37763. }(this, function (exports, sharedUtil, corePrimitives, coreFunction,
  37764. coreStream) {
  37765. var error = sharedUtil.error;
  37766. var info = sharedUtil.info;
  37767. var isArray = sharedUtil.isArray;
  37768. var isString = sharedUtil.isString;
  37769. var shadow = sharedUtil.shadow;
  37770. var warn = sharedUtil.warn;
  37771. var isDict = corePrimitives.isDict;
  37772. var isName = corePrimitives.isName;
  37773. var isStream = corePrimitives.isStream;
  37774. var PDFFunction = coreFunction.PDFFunction;
  37775. var coreImage; // see _setCoreImage below
  37776. var PDFImage; // = coreImage.PDFImage;
  37777. var ColorSpace = (function ColorSpaceClosure() {
  37778. // Constructor should define this.numComps, this.defaultColor, this.name
  37779. function ColorSpace() {
  37780. error('should not call ColorSpace constructor');
  37781. }
  37782. ColorSpace.prototype = {
  37783. /**
  37784. * Converts the color value to the RGB color. The color components are
  37785. * located in the src array starting from the srcOffset. Returns the array
  37786. * of the rgb components, each value ranging from [0,255].
  37787. */
  37788. getRgb: function ColorSpace_getRgb(src, srcOffset) {
  37789. var rgb = new Uint8Array(3);
  37790. this.getRgbItem(src, srcOffset, rgb, 0);
  37791. return rgb;
  37792. },
  37793. /**
  37794. * Converts the color value to the RGB color, similar to the getRgb method.
  37795. * The result placed into the dest array starting from the destOffset.
  37796. */
  37797. getRgbItem: function ColorSpace_getRgbItem(src, srcOffset,
  37798. dest, destOffset) {
  37799. error('Should not call ColorSpace.getRgbItem');
  37800. },
  37801. /**
  37802. * Converts the specified number of the color values to the RGB colors.
  37803. * The colors are located in the src array starting from the srcOffset.
  37804. * The result is placed into the dest array starting from the destOffset.
  37805. * The src array items shall be in [0,2^bits) range, the dest array items
  37806. * will be in [0,255] range. alpha01 indicates how many alpha components
  37807. * there are in the dest array; it will be either 0 (RGB array) or 1 (RGBA
  37808. * array).
  37809. */
  37810. getRgbBuffer: function ColorSpace_getRgbBuffer(src, srcOffset, count,
  37811. dest, destOffset, bits,
  37812. alpha01) {
  37813. error('Should not call ColorSpace.getRgbBuffer');
  37814. },
  37815. /**
  37816. * Determines the number of bytes required to store the result of the
  37817. * conversion done by the getRgbBuffer method. As in getRgbBuffer,
  37818. * |alpha01| is either 0 (RGB output) or 1 (RGBA output).
  37819. */
  37820. getOutputLength: function ColorSpace_getOutputLength(inputLength,
  37821. alpha01) {
  37822. error('Should not call ColorSpace.getOutputLength');
  37823. },
  37824. /**
  37825. * Returns true if source data will be equal the result/output data.
  37826. */
  37827. isPassthrough: function ColorSpace_isPassthrough(bits) {
  37828. return false;
  37829. },
  37830. /**
  37831. * Fills in the RGB colors in the destination buffer. alpha01 indicates
  37832. * how many alpha components there are in the dest array; it will be either
  37833. * 0 (RGB array) or 1 (RGBA array).
  37834. */
  37835. fillRgb: function ColorSpace_fillRgb(dest, originalWidth,
  37836. originalHeight, width, height,
  37837. actualHeight, bpc, comps, alpha01) {
  37838. var count = originalWidth * originalHeight;
  37839. var rgbBuf = null;
  37840. var numComponentColors = 1 << bpc;
  37841. var needsResizing = originalHeight !== height || originalWidth !== width;
  37842. var i, ii;
  37843. if (this.isPassthrough(bpc)) {
  37844. rgbBuf = comps;
  37845. } else if (this.numComps === 1 && count > numComponentColors &&
  37846. this.name !== 'DeviceGray' && this.name !== 'DeviceRGB') {
  37847. // Optimization: create a color map when there is just one component and
  37848. // we are converting more colors than the size of the color map. We
  37849. // don't build the map if the colorspace is gray or rgb since those
  37850. // methods are faster than building a map. This mainly offers big speed
  37851. // ups for indexed and alternate colorspaces.
  37852. //
  37853. // TODO it may be worth while to cache the color map. While running
  37854. // testing I never hit a cache so I will leave that out for now (perhaps
  37855. // we are reparsing colorspaces too much?).
  37856. var allColors = bpc <= 8 ? new Uint8Array(numComponentColors) :
  37857. new Uint16Array(numComponentColors);
  37858. var key;
  37859. for (i = 0; i < numComponentColors; i++) {
  37860. allColors[i] = i;
  37861. }
  37862. var colorMap = new Uint8Array(numComponentColors * 3);
  37863. this.getRgbBuffer(allColors, 0, numComponentColors, colorMap, 0, bpc,
  37864. /* alpha01 = */ 0);
  37865. var destPos, rgbPos;
  37866. if (!needsResizing) {
  37867. // Fill in the RGB values directly into |dest|.
  37868. destPos = 0;
  37869. for (i = 0; i < count; ++i) {
  37870. key = comps[i] * 3;
  37871. dest[destPos++] = colorMap[key];
  37872. dest[destPos++] = colorMap[key + 1];
  37873. dest[destPos++] = colorMap[key + 2];
  37874. destPos += alpha01;
  37875. }
  37876. } else {
  37877. rgbBuf = new Uint8Array(count * 3);
  37878. rgbPos = 0;
  37879. for (i = 0; i < count; ++i) {
  37880. key = comps[i] * 3;
  37881. rgbBuf[rgbPos++] = colorMap[key];
  37882. rgbBuf[rgbPos++] = colorMap[key + 1];
  37883. rgbBuf[rgbPos++] = colorMap[key + 2];
  37884. }
  37885. }
  37886. } else {
  37887. if (!needsResizing) {
  37888. // Fill in the RGB values directly into |dest|.
  37889. this.getRgbBuffer(comps, 0, width * actualHeight, dest, 0, bpc,
  37890. alpha01);
  37891. } else {
  37892. rgbBuf = new Uint8Array(count * 3);
  37893. this.getRgbBuffer(comps, 0, count, rgbBuf, 0, bpc,
  37894. /* alpha01 = */ 0);
  37895. }
  37896. }
  37897. if (rgbBuf) {
  37898. if (needsResizing) {
  37899. PDFImage.resize(rgbBuf, bpc, 3, originalWidth, originalHeight, width,
  37900. height, dest, alpha01);
  37901. } else {
  37902. rgbPos = 0;
  37903. destPos = 0;
  37904. for (i = 0, ii = width * actualHeight; i < ii; i++) {
  37905. dest[destPos++] = rgbBuf[rgbPos++];
  37906. dest[destPos++] = rgbBuf[rgbPos++];
  37907. dest[destPos++] = rgbBuf[rgbPos++];
  37908. destPos += alpha01;
  37909. }
  37910. }
  37911. }
  37912. },
  37913. /**
  37914. * True if the colorspace has components in the default range of [0, 1].
  37915. * This should be true for all colorspaces except for lab color spaces
  37916. * which are [0,100], [-128, 127], [-128, 127].
  37917. */
  37918. usesZeroToOneRange: true
  37919. };
  37920. ColorSpace.parse = function ColorSpace_parse(cs, xref, res) {
  37921. var IR = ColorSpace.parseToIR(cs, xref, res);
  37922. if (IR instanceof AlternateCS) {
  37923. return IR;
  37924. }
  37925. return ColorSpace.fromIR(IR);
  37926. };
  37927. ColorSpace.fromIR = function ColorSpace_fromIR(IR) {
  37928. var name = isArray(IR) ? IR[0] : IR;
  37929. var whitePoint, blackPoint, gamma;
  37930. switch (name) {
  37931. case 'DeviceGrayCS':
  37932. return this.singletons.gray;
  37933. case 'DeviceRgbCS':
  37934. return this.singletons.rgb;
  37935. case 'DeviceCmykCS':
  37936. return this.singletons.cmyk;
  37937. case 'CalGrayCS':
  37938. whitePoint = IR[1].WhitePoint;
  37939. blackPoint = IR[1].BlackPoint;
  37940. gamma = IR[1].Gamma;
  37941. return new CalGrayCS(whitePoint, blackPoint, gamma);
  37942. case 'CalRGBCS':
  37943. whitePoint = IR[1].WhitePoint;
  37944. blackPoint = IR[1].BlackPoint;
  37945. gamma = IR[1].Gamma;
  37946. var matrix = IR[1].Matrix;
  37947. return new CalRGBCS(whitePoint, blackPoint, gamma, matrix);
  37948. case 'PatternCS':
  37949. var basePatternCS = IR[1];
  37950. if (basePatternCS) {
  37951. basePatternCS = ColorSpace.fromIR(basePatternCS);
  37952. }
  37953. return new PatternCS(basePatternCS);
  37954. case 'IndexedCS':
  37955. var baseIndexedCS = IR[1];
  37956. var hiVal = IR[2];
  37957. var lookup = IR[3];
  37958. return new IndexedCS(ColorSpace.fromIR(baseIndexedCS), hiVal, lookup);
  37959. case 'AlternateCS':
  37960. var numComps = IR[1];
  37961. var alt = IR[2];
  37962. var tintFnIR = IR[3];
  37963. return new AlternateCS(numComps, ColorSpace.fromIR(alt),
  37964. PDFFunction.fromIR(tintFnIR));
  37965. case 'LabCS':
  37966. whitePoint = IR[1].WhitePoint;
  37967. blackPoint = IR[1].BlackPoint;
  37968. var range = IR[1].Range;
  37969. return new LabCS(whitePoint, blackPoint, range);
  37970. default:
  37971. error('Unknown name ' + name);
  37972. }
  37973. return null;
  37974. };
  37975. ColorSpace.parseToIR = function ColorSpace_parseToIR(cs, xref, res) {
  37976. if (isName(cs)) {
  37977. var colorSpaces = res.get('ColorSpace');
  37978. if (isDict(colorSpaces)) {
  37979. var refcs = colorSpaces.get(cs.name);
  37980. if (refcs) {
  37981. cs = refcs;
  37982. }
  37983. }
  37984. }
  37985. cs = xref.fetchIfRef(cs);
  37986. var mode;
  37987. if (isName(cs)) {
  37988. mode = cs.name;
  37989. this.mode = mode;
  37990. switch (mode) {
  37991. case 'DeviceGray':
  37992. case 'G':
  37993. return 'DeviceGrayCS';
  37994. case 'DeviceRGB':
  37995. case 'RGB':
  37996. return 'DeviceRgbCS';
  37997. case 'DeviceCMYK':
  37998. case 'CMYK':
  37999. return 'DeviceCmykCS';
  38000. case 'Pattern':
  38001. return ['PatternCS', null];
  38002. default:
  38003. error('unrecognized colorspace ' + mode);
  38004. }
  38005. } else if (isArray(cs)) {
  38006. mode = xref.fetchIfRef(cs[0]).name;
  38007. this.mode = mode;
  38008. var numComps, params, alt;
  38009. switch (mode) {
  38010. case 'DeviceGray':
  38011. case 'G':
  38012. return 'DeviceGrayCS';
  38013. case 'DeviceRGB':
  38014. case 'RGB':
  38015. return 'DeviceRgbCS';
  38016. case 'DeviceCMYK':
  38017. case 'CMYK':
  38018. return 'DeviceCmykCS';
  38019. case 'CalGray':
  38020. params = xref.fetchIfRef(cs[1]).getAll();
  38021. return ['CalGrayCS', params];
  38022. case 'CalRGB':
  38023. params = xref.fetchIfRef(cs[1]).getAll();
  38024. return ['CalRGBCS', params];
  38025. case 'ICCBased':
  38026. var stream = xref.fetchIfRef(cs[1]);
  38027. var dict = stream.dict;
  38028. numComps = dict.get('N');
  38029. alt = dict.get('Alternate');
  38030. if (alt) {
  38031. var altIR = ColorSpace.parseToIR(alt, xref, res);
  38032. // Parse the /Alternate CS to ensure that the number of components
  38033. // are correct, and also (indirectly) that it is not a PatternCS.
  38034. var altCS = ColorSpace.fromIR(altIR);
  38035. if (altCS.numComps === numComps) {
  38036. return altIR;
  38037. }
  38038. warn('ICCBased color space: Ignoring incorrect /Alternate entry.');
  38039. }
  38040. if (numComps === 1) {
  38041. return 'DeviceGrayCS';
  38042. } else if (numComps === 3) {
  38043. return 'DeviceRgbCS';
  38044. } else if (numComps === 4) {
  38045. return 'DeviceCmykCS';
  38046. }
  38047. break;
  38048. case 'Pattern':
  38049. var basePatternCS = cs[1] || null;
  38050. if (basePatternCS) {
  38051. basePatternCS = ColorSpace.parseToIR(basePatternCS, xref, res);
  38052. }
  38053. return ['PatternCS', basePatternCS];
  38054. case 'Indexed':
  38055. case 'I':
  38056. var baseIndexedCS = ColorSpace.parseToIR(cs[1], xref, res);
  38057. var hiVal = xref.fetchIfRef(cs[2]) + 1;
  38058. var lookup = xref.fetchIfRef(cs[3]);
  38059. if (isStream(lookup)) {
  38060. lookup = lookup.getBytes();
  38061. }
  38062. return ['IndexedCS', baseIndexedCS, hiVal, lookup];
  38063. case 'Separation':
  38064. case 'DeviceN':
  38065. var name = xref.fetchIfRef(cs[1]);
  38066. numComps = 1;
  38067. if (isName(name)) {
  38068. numComps = 1;
  38069. } else if (isArray(name)) {
  38070. numComps = name.length;
  38071. }
  38072. alt = ColorSpace.parseToIR(cs[2], xref, res);
  38073. var tintFnIR = PDFFunction.getIR(xref, xref.fetchIfRef(cs[3]));
  38074. return ['AlternateCS', numComps, alt, tintFnIR];
  38075. case 'Lab':
  38076. params = xref.fetchIfRef(cs[1]).getAll();
  38077. return ['LabCS', params];
  38078. default:
  38079. error('unimplemented color space object "' + mode + '"');
  38080. }
  38081. } else {
  38082. error('unrecognized color space object: "' + cs + '"');
  38083. }
  38084. return null;
  38085. };
  38086. /**
  38087. * Checks if a decode map matches the default decode map for a color space.
  38088. * This handles the general decode maps where there are two values per
  38089. * component. e.g. [0, 1, 0, 1, 0, 1] for a RGB color.
  38090. * This does not handle Lab, Indexed, or Pattern decode maps since they are
  38091. * slightly different.
  38092. * @param {Array} decode Decode map (usually from an image).
  38093. * @param {Number} n Number of components the color space has.
  38094. */
  38095. ColorSpace.isDefaultDecode = function ColorSpace_isDefaultDecode(decode, n) {
  38096. if (!isArray(decode)) {
  38097. return true;
  38098. }
  38099. if (n * 2 !== decode.length) {
  38100. warn('The decode map is not the correct length');
  38101. return true;
  38102. }
  38103. for (var i = 0, ii = decode.length; i < ii; i += 2) {
  38104. if (decode[i] !== 0 || decode[i + 1] !== 1) {
  38105. return false;
  38106. }
  38107. }
  38108. return true;
  38109. };
  38110. ColorSpace.singletons = {
  38111. get gray() {
  38112. return shadow(this, 'gray', new DeviceGrayCS());
  38113. },
  38114. get rgb() {
  38115. return shadow(this, 'rgb', new DeviceRgbCS());
  38116. },
  38117. get cmyk() {
  38118. return shadow(this, 'cmyk', new DeviceCmykCS());
  38119. }
  38120. };
  38121. return ColorSpace;
  38122. })();
  38123. /**
  38124. * Alternate color space handles both Separation and DeviceN color spaces. A
  38125. * Separation color space is actually just a DeviceN with one color component.
  38126. * Both color spaces use a tinting function to convert colors to a base color
  38127. * space.
  38128. */
  38129. var AlternateCS = (function AlternateCSClosure() {
  38130. function AlternateCS(numComps, base, tintFn) {
  38131. this.name = 'Alternate';
  38132. this.numComps = numComps;
  38133. this.defaultColor = new Float32Array(numComps);
  38134. for (var i = 0; i < numComps; ++i) {
  38135. this.defaultColor[i] = 1;
  38136. }
  38137. this.base = base;
  38138. this.tintFn = tintFn;
  38139. this.tmpBuf = new Float32Array(base.numComps);
  38140. }
  38141. AlternateCS.prototype = {
  38142. getRgb: ColorSpace.prototype.getRgb,
  38143. getRgbItem: function AlternateCS_getRgbItem(src, srcOffset,
  38144. dest, destOffset) {
  38145. var tmpBuf = this.tmpBuf;
  38146. this.tintFn(src, srcOffset, tmpBuf, 0);
  38147. this.base.getRgbItem(tmpBuf, 0, dest, destOffset);
  38148. },
  38149. getRgbBuffer: function AlternateCS_getRgbBuffer(src, srcOffset, count,
  38150. dest, destOffset, bits,
  38151. alpha01) {
  38152. var tintFn = this.tintFn;
  38153. var base = this.base;
  38154. var scale = 1 / ((1 << bits) - 1);
  38155. var baseNumComps = base.numComps;
  38156. var usesZeroToOneRange = base.usesZeroToOneRange;
  38157. var isPassthrough = (base.isPassthrough(8) || !usesZeroToOneRange) &&
  38158. alpha01 === 0;
  38159. var pos = isPassthrough ? destOffset : 0;
  38160. var baseBuf = isPassthrough ? dest : new Uint8Array(baseNumComps * count);
  38161. var numComps = this.numComps;
  38162. var scaled = new Float32Array(numComps);
  38163. var tinted = new Float32Array(baseNumComps);
  38164. var i, j;
  38165. if (usesZeroToOneRange) {
  38166. for (i = 0; i < count; i++) {
  38167. for (j = 0; j < numComps; j++) {
  38168. scaled[j] = src[srcOffset++] * scale;
  38169. }
  38170. tintFn(scaled, 0, tinted, 0);
  38171. for (j = 0; j < baseNumComps; j++) {
  38172. baseBuf[pos++] = tinted[j] * 255;
  38173. }
  38174. }
  38175. } else {
  38176. for (i = 0; i < count; i++) {
  38177. for (j = 0; j < numComps; j++) {
  38178. scaled[j] = src[srcOffset++] * scale;
  38179. }
  38180. tintFn(scaled, 0, tinted, 0);
  38181. base.getRgbItem(tinted, 0, baseBuf, pos);
  38182. pos += baseNumComps;
  38183. }
  38184. }
  38185. if (!isPassthrough) {
  38186. base.getRgbBuffer(baseBuf, 0, count, dest, destOffset, 8, alpha01);
  38187. }
  38188. },
  38189. getOutputLength: function AlternateCS_getOutputLength(inputLength,
  38190. alpha01) {
  38191. return this.base.getOutputLength(inputLength *
  38192. this.base.numComps / this.numComps,
  38193. alpha01);
  38194. },
  38195. isPassthrough: ColorSpace.prototype.isPassthrough,
  38196. fillRgb: ColorSpace.prototype.fillRgb,
  38197. isDefaultDecode: function AlternateCS_isDefaultDecode(decodeMap) {
  38198. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  38199. },
  38200. usesZeroToOneRange: true
  38201. };
  38202. return AlternateCS;
  38203. })();
  38204. var PatternCS = (function PatternCSClosure() {
  38205. function PatternCS(baseCS) {
  38206. this.name = 'Pattern';
  38207. this.base = baseCS;
  38208. }
  38209. PatternCS.prototype = {};
  38210. return PatternCS;
  38211. })();
  38212. var IndexedCS = (function IndexedCSClosure() {
  38213. function IndexedCS(base, highVal, lookup) {
  38214. this.name = 'Indexed';
  38215. this.numComps = 1;
  38216. this.defaultColor = new Uint8Array([0]);
  38217. this.base = base;
  38218. this.highVal = highVal;
  38219. var baseNumComps = base.numComps;
  38220. var length = baseNumComps * highVal;
  38221. var lookupArray;
  38222. if (isStream(lookup)) {
  38223. lookupArray = new Uint8Array(length);
  38224. var bytes = lookup.getBytes(length);
  38225. lookupArray.set(bytes);
  38226. } else if (isString(lookup)) {
  38227. lookupArray = new Uint8Array(length);
  38228. for (var i = 0; i < length; ++i) {
  38229. lookupArray[i] = lookup.charCodeAt(i);
  38230. }
  38231. } else if (lookup instanceof Uint8Array || lookup instanceof Array) {
  38232. lookupArray = lookup;
  38233. } else {
  38234. error('Unrecognized lookup table: ' + lookup);
  38235. }
  38236. this.lookup = lookupArray;
  38237. }
  38238. IndexedCS.prototype = {
  38239. getRgb: ColorSpace.prototype.getRgb,
  38240. getRgbItem: function IndexedCS_getRgbItem(src, srcOffset,
  38241. dest, destOffset) {
  38242. var numComps = this.base.numComps;
  38243. var start = src[srcOffset] * numComps;
  38244. this.base.getRgbItem(this.lookup, start, dest, destOffset);
  38245. },
  38246. getRgbBuffer: function IndexedCS_getRgbBuffer(src, srcOffset, count,
  38247. dest, destOffset, bits,
  38248. alpha01) {
  38249. var base = this.base;
  38250. var numComps = base.numComps;
  38251. var outputDelta = base.getOutputLength(numComps, alpha01);
  38252. var lookup = this.lookup;
  38253. for (var i = 0; i < count; ++i) {
  38254. var lookupPos = src[srcOffset++] * numComps;
  38255. base.getRgbBuffer(lookup, lookupPos, 1, dest, destOffset, 8, alpha01);
  38256. destOffset += outputDelta;
  38257. }
  38258. },
  38259. getOutputLength: function IndexedCS_getOutputLength(inputLength, alpha01) {
  38260. return this.base.getOutputLength(inputLength * this.base.numComps,
  38261. alpha01);
  38262. },
  38263. isPassthrough: ColorSpace.prototype.isPassthrough,
  38264. fillRgb: ColorSpace.prototype.fillRgb,
  38265. isDefaultDecode: function IndexedCS_isDefaultDecode(decodeMap) {
  38266. // indexed color maps shouldn't be changed
  38267. return true;
  38268. },
  38269. usesZeroToOneRange: true
  38270. };
  38271. return IndexedCS;
  38272. })();
  38273. var DeviceGrayCS = (function DeviceGrayCSClosure() {
  38274. function DeviceGrayCS() {
  38275. this.name = 'DeviceGray';
  38276. this.numComps = 1;
  38277. this.defaultColor = new Float32Array([0]);
  38278. }
  38279. DeviceGrayCS.prototype = {
  38280. getRgb: ColorSpace.prototype.getRgb,
  38281. getRgbItem: function DeviceGrayCS_getRgbItem(src, srcOffset,
  38282. dest, destOffset) {
  38283. var c = (src[srcOffset] * 255) | 0;
  38284. c = c < 0 ? 0 : c > 255 ? 255 : c;
  38285. dest[destOffset] = dest[destOffset + 1] = dest[destOffset + 2] = c;
  38286. },
  38287. getRgbBuffer: function DeviceGrayCS_getRgbBuffer(src, srcOffset, count,
  38288. dest, destOffset, bits,
  38289. alpha01) {
  38290. var scale = 255 / ((1 << bits) - 1);
  38291. var j = srcOffset, q = destOffset;
  38292. for (var i = 0; i < count; ++i) {
  38293. var c = (scale * src[j++]) | 0;
  38294. dest[q++] = c;
  38295. dest[q++] = c;
  38296. dest[q++] = c;
  38297. q += alpha01;
  38298. }
  38299. },
  38300. getOutputLength: function DeviceGrayCS_getOutputLength(inputLength,
  38301. alpha01) {
  38302. return inputLength * (3 + alpha01);
  38303. },
  38304. isPassthrough: ColorSpace.prototype.isPassthrough,
  38305. fillRgb: ColorSpace.prototype.fillRgb,
  38306. isDefaultDecode: function DeviceGrayCS_isDefaultDecode(decodeMap) {
  38307. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  38308. },
  38309. usesZeroToOneRange: true
  38310. };
  38311. return DeviceGrayCS;
  38312. })();
  38313. var DeviceRgbCS = (function DeviceRgbCSClosure() {
  38314. function DeviceRgbCS() {
  38315. this.name = 'DeviceRGB';
  38316. this.numComps = 3;
  38317. this.defaultColor = new Float32Array([0, 0, 0]);
  38318. }
  38319. DeviceRgbCS.prototype = {
  38320. getRgb: ColorSpace.prototype.getRgb,
  38321. getRgbItem: function DeviceRgbCS_getRgbItem(src, srcOffset,
  38322. dest, destOffset) {
  38323. var r = (src[srcOffset] * 255) | 0;
  38324. var g = (src[srcOffset + 1] * 255) | 0;
  38325. var b = (src[srcOffset + 2] * 255) | 0;
  38326. dest[destOffset] = r < 0 ? 0 : r > 255 ? 255 : r;
  38327. dest[destOffset + 1] = g < 0 ? 0 : g > 255 ? 255 : g;
  38328. dest[destOffset + 2] = b < 0 ? 0 : b > 255 ? 255 : b;
  38329. },
  38330. getRgbBuffer: function DeviceRgbCS_getRgbBuffer(src, srcOffset, count,
  38331. dest, destOffset, bits,
  38332. alpha01) {
  38333. if (bits === 8 && alpha01 === 0) {
  38334. dest.set(src.subarray(srcOffset, srcOffset + count * 3), destOffset);
  38335. return;
  38336. }
  38337. var scale = 255 / ((1 << bits) - 1);
  38338. var j = srcOffset, q = destOffset;
  38339. for (var i = 0; i < count; ++i) {
  38340. dest[q++] = (scale * src[j++]) | 0;
  38341. dest[q++] = (scale * src[j++]) | 0;
  38342. dest[q++] = (scale * src[j++]) | 0;
  38343. q += alpha01;
  38344. }
  38345. },
  38346. getOutputLength: function DeviceRgbCS_getOutputLength(inputLength,
  38347. alpha01) {
  38348. return (inputLength * (3 + alpha01) / 3) | 0;
  38349. },
  38350. isPassthrough: function DeviceRgbCS_isPassthrough(bits) {
  38351. return bits === 8;
  38352. },
  38353. fillRgb: ColorSpace.prototype.fillRgb,
  38354. isDefaultDecode: function DeviceRgbCS_isDefaultDecode(decodeMap) {
  38355. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  38356. },
  38357. usesZeroToOneRange: true
  38358. };
  38359. return DeviceRgbCS;
  38360. })();
  38361. var DeviceCmykCS = (function DeviceCmykCSClosure() {
  38362. // The coefficients below was found using numerical analysis: the method of
  38363. // steepest descent for the sum((f_i - color_value_i)^2) for r/g/b colors,
  38364. // where color_value is the tabular value from the table of sampled RGB colors
  38365. // from CMYK US Web Coated (SWOP) colorspace, and f_i is the corresponding
  38366. // CMYK color conversion using the estimation below:
  38367. // f(A, B,.. N) = Acc+Bcm+Ccy+Dck+c+Fmm+Gmy+Hmk+Im+Jyy+Kyk+Ly+Mkk+Nk+255
  38368. function convertToRgb(src, srcOffset, srcScale, dest, destOffset) {
  38369. var c = src[srcOffset + 0] * srcScale;
  38370. var m = src[srcOffset + 1] * srcScale;
  38371. var y = src[srcOffset + 2] * srcScale;
  38372. var k = src[srcOffset + 3] * srcScale;
  38373. var r =
  38374. (c * (-4.387332384609988 * c + 54.48615194189176 * m +
  38375. 18.82290502165302 * y + 212.25662451639585 * k +
  38376. -285.2331026137004) +
  38377. m * (1.7149763477362134 * m - 5.6096736904047315 * y +
  38378. -17.873870861415444 * k - 5.497006427196366) +
  38379. y * (-2.5217340131683033 * y - 21.248923337353073 * k +
  38380. 17.5119270841813) +
  38381. k * (-21.86122147463605 * k - 189.48180835922747) + 255) | 0;
  38382. var g =
  38383. (c * (8.841041422036149 * c + 60.118027045597366 * m +
  38384. 6.871425592049007 * y + 31.159100130055922 * k +
  38385. -79.2970844816548) +
  38386. m * (-15.310361306967817 * m + 17.575251261109482 * y +
  38387. 131.35250912493976 * k - 190.9453302588951) +
  38388. y * (4.444339102852739 * y + 9.8632861493405 * k - 24.86741582555878) +
  38389. k * (-20.737325471181034 * k - 187.80453709719578) + 255) | 0;
  38390. var b =
  38391. (c * (0.8842522430003296 * c + 8.078677503112928 * m +
  38392. 30.89978309703729 * y - 0.23883238689178934 * k +
  38393. -14.183576799673286) +
  38394. m * (10.49593273432072 * m + 63.02378494754052 * y +
  38395. 50.606957656360734 * k - 112.23884253719248) +
  38396. y * (0.03296041114873217 * y + 115.60384449646641 * k +
  38397. -193.58209356861505) +
  38398. k * (-22.33816807309886 * k - 180.12613974708367) + 255) | 0;
  38399. dest[destOffset] = r > 255 ? 255 : r < 0 ? 0 : r;
  38400. dest[destOffset + 1] = g > 255 ? 255 : g < 0 ? 0 : g;
  38401. dest[destOffset + 2] = b > 255 ? 255 : b < 0 ? 0 : b;
  38402. }
  38403. function DeviceCmykCS() {
  38404. this.name = 'DeviceCMYK';
  38405. this.numComps = 4;
  38406. this.defaultColor = new Float32Array([0, 0, 0, 1]);
  38407. }
  38408. DeviceCmykCS.prototype = {
  38409. getRgb: ColorSpace.prototype.getRgb,
  38410. getRgbItem: function DeviceCmykCS_getRgbItem(src, srcOffset,
  38411. dest, destOffset) {
  38412. convertToRgb(src, srcOffset, 1, dest, destOffset);
  38413. },
  38414. getRgbBuffer: function DeviceCmykCS_getRgbBuffer(src, srcOffset, count,
  38415. dest, destOffset, bits,
  38416. alpha01) {
  38417. var scale = 1 / ((1 << bits) - 1);
  38418. for (var i = 0; i < count; i++) {
  38419. convertToRgb(src, srcOffset, scale, dest, destOffset);
  38420. srcOffset += 4;
  38421. destOffset += 3 + alpha01;
  38422. }
  38423. },
  38424. getOutputLength: function DeviceCmykCS_getOutputLength(inputLength,
  38425. alpha01) {
  38426. return (inputLength / 4 * (3 + alpha01)) | 0;
  38427. },
  38428. isPassthrough: ColorSpace.prototype.isPassthrough,
  38429. fillRgb: ColorSpace.prototype.fillRgb,
  38430. isDefaultDecode: function DeviceCmykCS_isDefaultDecode(decodeMap) {
  38431. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  38432. },
  38433. usesZeroToOneRange: true
  38434. };
  38435. return DeviceCmykCS;
  38436. })();
  38437. //
  38438. // CalGrayCS: Based on "PDF Reference, Sixth Ed", p.245
  38439. //
  38440. var CalGrayCS = (function CalGrayCSClosure() {
  38441. function CalGrayCS(whitePoint, blackPoint, gamma) {
  38442. this.name = 'CalGray';
  38443. this.numComps = 1;
  38444. this.defaultColor = new Float32Array([0]);
  38445. if (!whitePoint) {
  38446. error('WhitePoint missing - required for color space CalGray');
  38447. }
  38448. blackPoint = blackPoint || [0, 0, 0];
  38449. gamma = gamma || 1;
  38450. // Translate arguments to spec variables.
  38451. this.XW = whitePoint[0];
  38452. this.YW = whitePoint[1];
  38453. this.ZW = whitePoint[2];
  38454. this.XB = blackPoint[0];
  38455. this.YB = blackPoint[1];
  38456. this.ZB = blackPoint[2];
  38457. this.G = gamma;
  38458. // Validate variables as per spec.
  38459. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  38460. error('Invalid WhitePoint components for ' + this.name +
  38461. ', no fallback available');
  38462. }
  38463. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  38464. info('Invalid BlackPoint for ' + this.name + ', falling back to default');
  38465. this.XB = this.YB = this.ZB = 0;
  38466. }
  38467. if (this.XB !== 0 || this.YB !== 0 || this.ZB !== 0) {
  38468. warn(this.name + ', BlackPoint: XB: ' + this.XB + ', YB: ' + this.YB +
  38469. ', ZB: ' + this.ZB + ', only default values are supported.');
  38470. }
  38471. if (this.G < 1) {
  38472. info('Invalid Gamma: ' + this.G + ' for ' + this.name +
  38473. ', falling back to default');
  38474. this.G = 1;
  38475. }
  38476. }
  38477. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  38478. // A represents a gray component of a calibrated gray space.
  38479. // A <---> AG in the spec
  38480. var A = src[srcOffset] * scale;
  38481. var AG = Math.pow(A, cs.G);
  38482. // Computes L as per spec. ( = cs.YW * AG )
  38483. // Except if other than default BlackPoint values are used.
  38484. var L = cs.YW * AG;
  38485. // http://www.poynton.com/notes/colour_and_gamma/ColorFAQ.html, Ch 4.
  38486. // Convert values to rgb range [0, 255].
  38487. var val = Math.max(295.8 * Math.pow(L, 0.333333333333333333) - 40.8, 0) | 0;
  38488. dest[destOffset] = val;
  38489. dest[destOffset + 1] = val;
  38490. dest[destOffset + 2] = val;
  38491. }
  38492. CalGrayCS.prototype = {
  38493. getRgb: ColorSpace.prototype.getRgb,
  38494. getRgbItem: function CalGrayCS_getRgbItem(src, srcOffset,
  38495. dest, destOffset) {
  38496. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  38497. },
  38498. getRgbBuffer: function CalGrayCS_getRgbBuffer(src, srcOffset, count,
  38499. dest, destOffset, bits,
  38500. alpha01) {
  38501. var scale = 1 / ((1 << bits) - 1);
  38502. for (var i = 0; i < count; ++i) {
  38503. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  38504. srcOffset += 1;
  38505. destOffset += 3 + alpha01;
  38506. }
  38507. },
  38508. getOutputLength: function CalGrayCS_getOutputLength(inputLength, alpha01) {
  38509. return inputLength * (3 + alpha01);
  38510. },
  38511. isPassthrough: ColorSpace.prototype.isPassthrough,
  38512. fillRgb: ColorSpace.prototype.fillRgb,
  38513. isDefaultDecode: function CalGrayCS_isDefaultDecode(decodeMap) {
  38514. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  38515. },
  38516. usesZeroToOneRange: true
  38517. };
  38518. return CalGrayCS;
  38519. })();
  38520. //
  38521. // CalRGBCS: Based on "PDF Reference, Sixth Ed", p.247
  38522. //
  38523. var CalRGBCS = (function CalRGBCSClosure() {
  38524. // See http://www.brucelindbloom.com/index.html?Eqn_ChromAdapt.html for these
  38525. // matrices.
  38526. var BRADFORD_SCALE_MATRIX = new Float32Array([
  38527. 0.8951, 0.2664, -0.1614,
  38528. -0.7502, 1.7135, 0.0367,
  38529. 0.0389, -0.0685, 1.0296]);
  38530. var BRADFORD_SCALE_INVERSE_MATRIX = new Float32Array([
  38531. 0.9869929, -0.1470543, 0.1599627,
  38532. 0.4323053, 0.5183603, 0.0492912,
  38533. -0.0085287, 0.0400428, 0.9684867]);
  38534. // See http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html.
  38535. var SRGB_D65_XYZ_TO_RGB_MATRIX = new Float32Array([
  38536. 3.2404542, -1.5371385, -0.4985314,
  38537. -0.9692660, 1.8760108, 0.0415560,
  38538. 0.0556434, -0.2040259, 1.0572252]);
  38539. var FLAT_WHITEPOINT_MATRIX = new Float32Array([1, 1, 1]);
  38540. var tempNormalizeMatrix = new Float32Array(3);
  38541. var tempConvertMatrix1 = new Float32Array(3);
  38542. var tempConvertMatrix2 = new Float32Array(3);
  38543. var DECODE_L_CONSTANT = Math.pow(((8 + 16) / 116), 3) / 8.0;
  38544. function CalRGBCS(whitePoint, blackPoint, gamma, matrix) {
  38545. this.name = 'CalRGB';
  38546. this.numComps = 3;
  38547. this.defaultColor = new Float32Array(3);
  38548. if (!whitePoint) {
  38549. error('WhitePoint missing - required for color space CalRGB');
  38550. }
  38551. blackPoint = blackPoint || new Float32Array(3);
  38552. gamma = gamma || new Float32Array([1, 1, 1]);
  38553. matrix = matrix || new Float32Array([1, 0, 0, 0, 1, 0, 0, 0, 1]);
  38554. // Translate arguments to spec variables.
  38555. var XW = whitePoint[0];
  38556. var YW = whitePoint[1];
  38557. var ZW = whitePoint[2];
  38558. this.whitePoint = whitePoint;
  38559. var XB = blackPoint[0];
  38560. var YB = blackPoint[1];
  38561. var ZB = blackPoint[2];
  38562. this.blackPoint = blackPoint;
  38563. this.GR = gamma[0];
  38564. this.GG = gamma[1];
  38565. this.GB = gamma[2];
  38566. this.MXA = matrix[0];
  38567. this.MYA = matrix[1];
  38568. this.MZA = matrix[2];
  38569. this.MXB = matrix[3];
  38570. this.MYB = matrix[4];
  38571. this.MZB = matrix[5];
  38572. this.MXC = matrix[6];
  38573. this.MYC = matrix[7];
  38574. this.MZC = matrix[8];
  38575. // Validate variables as per spec.
  38576. if (XW < 0 || ZW < 0 || YW !== 1) {
  38577. error('Invalid WhitePoint components for ' + this.name +
  38578. ', no fallback available');
  38579. }
  38580. if (XB < 0 || YB < 0 || ZB < 0) {
  38581. info('Invalid BlackPoint for ' + this.name + ' [' + XB + ', ' + YB +
  38582. ', ' + ZB + '], falling back to default');
  38583. this.blackPoint = new Float32Array(3);
  38584. }
  38585. if (this.GR < 0 || this.GG < 0 || this.GB < 0) {
  38586. info('Invalid Gamma [' + this.GR + ', ' + this.GG + ', ' + this.GB +
  38587. '] for ' + this.name + ', falling back to default');
  38588. this.GR = this.GG = this.GB = 1;
  38589. }
  38590. if (this.MXA < 0 || this.MYA < 0 || this.MZA < 0 ||
  38591. this.MXB < 0 || this.MYB < 0 || this.MZB < 0 ||
  38592. this.MXC < 0 || this.MYC < 0 || this.MZC < 0) {
  38593. info('Invalid Matrix for ' + this.name + ' [' +
  38594. this.MXA + ', ' + this.MYA + ', ' + this.MZA +
  38595. this.MXB + ', ' + this.MYB + ', ' + this.MZB +
  38596. this.MXC + ', ' + this.MYC + ', ' + this.MZC +
  38597. '], falling back to default');
  38598. this.MXA = this.MYB = this.MZC = 1;
  38599. this.MXB = this.MYA = this.MZA = this.MXC = this.MYC = this.MZB = 0;
  38600. }
  38601. }
  38602. function matrixProduct(a, b, result) {
  38603. result[0] = a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
  38604. result[1] = a[3] * b[0] + a[4] * b[1] + a[5] * b[2];
  38605. result[2] = a[6] * b[0] + a[7] * b[1] + a[8] * b[2];
  38606. }
  38607. function convertToFlat(sourceWhitePoint, LMS, result) {
  38608. result[0] = LMS[0] * 1 / sourceWhitePoint[0];
  38609. result[1] = LMS[1] * 1 / sourceWhitePoint[1];
  38610. result[2] = LMS[2] * 1 / sourceWhitePoint[2];
  38611. }
  38612. function convertToD65(sourceWhitePoint, LMS, result) {
  38613. var D65X = 0.95047;
  38614. var D65Y = 1;
  38615. var D65Z = 1.08883;
  38616. result[0] = LMS[0] * D65X / sourceWhitePoint[0];
  38617. result[1] = LMS[1] * D65Y / sourceWhitePoint[1];
  38618. result[2] = LMS[2] * D65Z / sourceWhitePoint[2];
  38619. }
  38620. function sRGBTransferFunction(color) {
  38621. // See http://en.wikipedia.org/wiki/SRGB.
  38622. if (color <= 0.0031308){
  38623. return adjustToRange(0, 1, 12.92 * color);
  38624. }
  38625. return adjustToRange(0, 1, (1 + 0.055) * Math.pow(color, 1 / 2.4) - 0.055);
  38626. }
  38627. function adjustToRange(min, max, value) {
  38628. return Math.max(min, Math.min(max, value));
  38629. }
  38630. function decodeL(L) {
  38631. if (L < 0) {
  38632. return -decodeL(-L);
  38633. }
  38634. if (L > 8.0) {
  38635. return Math.pow(((L + 16) / 116), 3);
  38636. }
  38637. return L * DECODE_L_CONSTANT;
  38638. }
  38639. function compensateBlackPoint(sourceBlackPoint, XYZ_Flat, result) {
  38640. // In case the blackPoint is already the default blackPoint then there is
  38641. // no need to do compensation.
  38642. if (sourceBlackPoint[0] === 0 &&
  38643. sourceBlackPoint[1] === 0 &&
  38644. sourceBlackPoint[2] === 0) {
  38645. result[0] = XYZ_Flat[0];
  38646. result[1] = XYZ_Flat[1];
  38647. result[2] = XYZ_Flat[2];
  38648. return;
  38649. }
  38650. // For the blackPoint calculation details, please see
  38651. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  38652. // AdobeBPC.pdf.
  38653. // The destination blackPoint is the default blackPoint [0, 0, 0].
  38654. var zeroDecodeL = decodeL(0);
  38655. var X_DST = zeroDecodeL;
  38656. var X_SRC = decodeL(sourceBlackPoint[0]);
  38657. var Y_DST = zeroDecodeL;
  38658. var Y_SRC = decodeL(sourceBlackPoint[1]);
  38659. var Z_DST = zeroDecodeL;
  38660. var Z_SRC = decodeL(sourceBlackPoint[2]);
  38661. var X_Scale = (1 - X_DST) / (1 - X_SRC);
  38662. var X_Offset = 1 - X_Scale;
  38663. var Y_Scale = (1 - Y_DST) / (1 - Y_SRC);
  38664. var Y_Offset = 1 - Y_Scale;
  38665. var Z_Scale = (1 - Z_DST) / (1 - Z_SRC);
  38666. var Z_Offset = 1 - Z_Scale;
  38667. result[0] = XYZ_Flat[0] * X_Scale + X_Offset;
  38668. result[1] = XYZ_Flat[1] * Y_Scale + Y_Offset;
  38669. result[2] = XYZ_Flat[2] * Z_Scale + Z_Offset;
  38670. }
  38671. function normalizeWhitePointToFlat(sourceWhitePoint, XYZ_In, result) {
  38672. // In case the whitePoint is already flat then there is no need to do
  38673. // normalization.
  38674. if (sourceWhitePoint[0] === 1 && sourceWhitePoint[2] === 1) {
  38675. result[0] = XYZ_In[0];
  38676. result[1] = XYZ_In[1];
  38677. result[2] = XYZ_In[2];
  38678. return;
  38679. }
  38680. var LMS = result;
  38681. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  38682. var LMS_Flat = tempNormalizeMatrix;
  38683. convertToFlat(sourceWhitePoint, LMS, LMS_Flat);
  38684. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_Flat, result);
  38685. }
  38686. function normalizeWhitePointToD65(sourceWhitePoint, XYZ_In, result) {
  38687. var LMS = result;
  38688. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  38689. var LMS_D65 = tempNormalizeMatrix;
  38690. convertToD65(sourceWhitePoint, LMS, LMS_D65);
  38691. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_D65, result);
  38692. }
  38693. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  38694. // A, B and C represent a red, green and blue components of a calibrated
  38695. // rgb space.
  38696. var A = adjustToRange(0, 1, src[srcOffset] * scale);
  38697. var B = adjustToRange(0, 1, src[srcOffset + 1] * scale);
  38698. var C = adjustToRange(0, 1, src[srcOffset + 2] * scale);
  38699. // A <---> AGR in the spec
  38700. // B <---> BGG in the spec
  38701. // C <---> CGB in the spec
  38702. var AGR = Math.pow(A, cs.GR);
  38703. var BGG = Math.pow(B, cs.GG);
  38704. var CGB = Math.pow(C, cs.GB);
  38705. // Computes intermediate variables L, M, N as per spec.
  38706. // To decode X, Y, Z values map L, M, N directly to them.
  38707. var X = cs.MXA * AGR + cs.MXB * BGG + cs.MXC * CGB;
  38708. var Y = cs.MYA * AGR + cs.MYB * BGG + cs.MYC * CGB;
  38709. var Z = cs.MZA * AGR + cs.MZB * BGG + cs.MZC * CGB;
  38710. // The following calculations are based on this document:
  38711. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  38712. // AdobeBPC.pdf.
  38713. var XYZ = tempConvertMatrix1;
  38714. XYZ[0] = X;
  38715. XYZ[1] = Y;
  38716. XYZ[2] = Z;
  38717. var XYZ_Flat = tempConvertMatrix2;
  38718. normalizeWhitePointToFlat(cs.whitePoint, XYZ, XYZ_Flat);
  38719. var XYZ_Black = tempConvertMatrix1;
  38720. compensateBlackPoint(cs.blackPoint, XYZ_Flat, XYZ_Black);
  38721. var XYZ_D65 = tempConvertMatrix2;
  38722. normalizeWhitePointToD65(FLAT_WHITEPOINT_MATRIX, XYZ_Black, XYZ_D65);
  38723. var SRGB = tempConvertMatrix1;
  38724. matrixProduct(SRGB_D65_XYZ_TO_RGB_MATRIX, XYZ_D65, SRGB);
  38725. var sR = sRGBTransferFunction(SRGB[0]);
  38726. var sG = sRGBTransferFunction(SRGB[1]);
  38727. var sB = sRGBTransferFunction(SRGB[2]);
  38728. // Convert the values to rgb range [0, 255].
  38729. dest[destOffset] = Math.round(sR * 255);
  38730. dest[destOffset + 1] = Math.round(sG * 255);
  38731. dest[destOffset + 2] = Math.round(sB * 255);
  38732. }
  38733. CalRGBCS.prototype = {
  38734. getRgb: function CalRGBCS_getRgb(src, srcOffset) {
  38735. var rgb = new Uint8Array(3);
  38736. this.getRgbItem(src, srcOffset, rgb, 0);
  38737. return rgb;
  38738. },
  38739. getRgbItem: function CalRGBCS_getRgbItem(src, srcOffset,
  38740. dest, destOffset) {
  38741. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  38742. },
  38743. getRgbBuffer: function CalRGBCS_getRgbBuffer(src, srcOffset, count,
  38744. dest, destOffset, bits,
  38745. alpha01) {
  38746. var scale = 1 / ((1 << bits) - 1);
  38747. for (var i = 0; i < count; ++i) {
  38748. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  38749. srcOffset += 3;
  38750. destOffset += 3 + alpha01;
  38751. }
  38752. },
  38753. getOutputLength: function CalRGBCS_getOutputLength(inputLength, alpha01) {
  38754. return (inputLength * (3 + alpha01) / 3) | 0;
  38755. },
  38756. isPassthrough: ColorSpace.prototype.isPassthrough,
  38757. fillRgb: ColorSpace.prototype.fillRgb,
  38758. isDefaultDecode: function CalRGBCS_isDefaultDecode(decodeMap) {
  38759. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  38760. },
  38761. usesZeroToOneRange: true
  38762. };
  38763. return CalRGBCS;
  38764. })();
  38765. //
  38766. // LabCS: Based on "PDF Reference, Sixth Ed", p.250
  38767. //
  38768. var LabCS = (function LabCSClosure() {
  38769. function LabCS(whitePoint, blackPoint, range) {
  38770. this.name = 'Lab';
  38771. this.numComps = 3;
  38772. this.defaultColor = new Float32Array([0, 0, 0]);
  38773. if (!whitePoint) {
  38774. error('WhitePoint missing - required for color space Lab');
  38775. }
  38776. blackPoint = blackPoint || [0, 0, 0];
  38777. range = range || [-100, 100, -100, 100];
  38778. // Translate args to spec variables
  38779. this.XW = whitePoint[0];
  38780. this.YW = whitePoint[1];
  38781. this.ZW = whitePoint[2];
  38782. this.amin = range[0];
  38783. this.amax = range[1];
  38784. this.bmin = range[2];
  38785. this.bmax = range[3];
  38786. // These are here just for completeness - the spec doesn't offer any
  38787. // formulas that use BlackPoint in Lab
  38788. this.XB = blackPoint[0];
  38789. this.YB = blackPoint[1];
  38790. this.ZB = blackPoint[2];
  38791. // Validate vars as per spec
  38792. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  38793. error('Invalid WhitePoint components, no fallback available');
  38794. }
  38795. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  38796. info('Invalid BlackPoint, falling back to default');
  38797. this.XB = this.YB = this.ZB = 0;
  38798. }
  38799. if (this.amin > this.amax || this.bmin > this.bmax) {
  38800. info('Invalid Range, falling back to defaults');
  38801. this.amin = -100;
  38802. this.amax = 100;
  38803. this.bmin = -100;
  38804. this.bmax = 100;
  38805. }
  38806. }
  38807. // Function g(x) from spec
  38808. function fn_g(x) {
  38809. if (x >= 6 / 29) {
  38810. return x * x * x;
  38811. } else {
  38812. return (108 / 841) * (x - 4 / 29);
  38813. }
  38814. }
  38815. function decode(value, high1, low2, high2) {
  38816. return low2 + (value) * (high2 - low2) / (high1);
  38817. }
  38818. // If decoding is needed maxVal should be 2^bits per component - 1.
  38819. function convertToRgb(cs, src, srcOffset, maxVal, dest, destOffset) {
  38820. // XXX: Lab input is in the range of [0, 100], [amin, amax], [bmin, bmax]
  38821. // not the usual [0, 1]. If a command like setFillColor is used the src
  38822. // values will already be within the correct range. However, if we are
  38823. // converting an image we have to map the values to the correct range given
  38824. // above.
  38825. // Ls,as,bs <---> L*,a*,b* in the spec
  38826. var Ls = src[srcOffset];
  38827. var as = src[srcOffset + 1];
  38828. var bs = src[srcOffset + 2];
  38829. if (maxVal !== false) {
  38830. Ls = decode(Ls, maxVal, 0, 100);
  38831. as = decode(as, maxVal, cs.amin, cs.amax);
  38832. bs = decode(bs, maxVal, cs.bmin, cs.bmax);
  38833. }
  38834. // Adjust limits of 'as' and 'bs'
  38835. as = as > cs.amax ? cs.amax : as < cs.amin ? cs.amin : as;
  38836. bs = bs > cs.bmax ? cs.bmax : bs < cs.bmin ? cs.bmin : bs;
  38837. // Computes intermediate variables X,Y,Z as per spec
  38838. var M = (Ls + 16) / 116;
  38839. var L = M + (as / 500);
  38840. var N = M - (bs / 200);
  38841. var X = cs.XW * fn_g(L);
  38842. var Y = cs.YW * fn_g(M);
  38843. var Z = cs.ZW * fn_g(N);
  38844. var r, g, b;
  38845. // Using different conversions for D50 and D65 white points,
  38846. // per http://www.color.org/srgb.pdf
  38847. if (cs.ZW < 1) {
  38848. // Assuming D50 (X=0.9642, Y=1.00, Z=0.8249)
  38849. r = X * 3.1339 + Y * -1.6170 + Z * -0.4906;
  38850. g = X * -0.9785 + Y * 1.9160 + Z * 0.0333;
  38851. b = X * 0.0720 + Y * -0.2290 + Z * 1.4057;
  38852. } else {
  38853. // Assuming D65 (X=0.9505, Y=1.00, Z=1.0888)
  38854. r = X * 3.2406 + Y * -1.5372 + Z * -0.4986;
  38855. g = X * -0.9689 + Y * 1.8758 + Z * 0.0415;
  38856. b = X * 0.0557 + Y * -0.2040 + Z * 1.0570;
  38857. }
  38858. // clamp color values to [0,1] range then convert to [0,255] range.
  38859. dest[destOffset] = r <= 0 ? 0 : r >= 1 ? 255 : Math.sqrt(r) * 255 | 0;
  38860. dest[destOffset + 1] = g <= 0 ? 0 : g >= 1 ? 255 : Math.sqrt(g) * 255 | 0;
  38861. dest[destOffset + 2] = b <= 0 ? 0 : b >= 1 ? 255 : Math.sqrt(b) * 255 | 0;
  38862. }
  38863. LabCS.prototype = {
  38864. getRgb: ColorSpace.prototype.getRgb,
  38865. getRgbItem: function LabCS_getRgbItem(src, srcOffset, dest, destOffset) {
  38866. convertToRgb(this, src, srcOffset, false, dest, destOffset);
  38867. },
  38868. getRgbBuffer: function LabCS_getRgbBuffer(src, srcOffset, count,
  38869. dest, destOffset, bits,
  38870. alpha01) {
  38871. var maxVal = (1 << bits) - 1;
  38872. for (var i = 0; i < count; i++) {
  38873. convertToRgb(this, src, srcOffset, maxVal, dest, destOffset);
  38874. srcOffset += 3;
  38875. destOffset += 3 + alpha01;
  38876. }
  38877. },
  38878. getOutputLength: function LabCS_getOutputLength(inputLength, alpha01) {
  38879. return (inputLength * (3 + alpha01) / 3) | 0;
  38880. },
  38881. isPassthrough: ColorSpace.prototype.isPassthrough,
  38882. fillRgb: ColorSpace.prototype.fillRgb,
  38883. isDefaultDecode: function LabCS_isDefaultDecode(decodeMap) {
  38884. // XXX: Decoding is handled with the lab conversion because of the strange
  38885. // ranges that are used.
  38886. return true;
  38887. },
  38888. usesZeroToOneRange: false
  38889. };
  38890. return LabCS;
  38891. })();
  38892. // TODO refactor to remove dependency on image.js
  38893. function _setCoreImage(coreImage_) {
  38894. coreImage = coreImage_;
  38895. PDFImage = coreImage_.PDFImage;
  38896. }
  38897. exports._setCoreImage = _setCoreImage;
  38898. exports.ColorSpace = ColorSpace;
  38899. // TODO refactor to remove dependency on colorspace.js
  38900. coreStream._setCoreColorSpace(exports);
  38901. }));
  38902. (function (root, factory) {
  38903. {
  38904. factory((root.pdfjsCoreImage = {}), root.pdfjsSharedUtil,
  38905. root.pdfjsCorePrimitives, root.pdfjsCoreColorSpace, root.pdfjsCoreStream,
  38906. root.pdfjsCoreJpx);
  38907. }
  38908. }(this, function (exports, sharedUtil, corePrimitives, coreColorSpace,
  38909. coreStream, coreJpx) {
  38910. var ImageKind = sharedUtil.ImageKind;
  38911. var assert = sharedUtil.assert;
  38912. var error = sharedUtil.error;
  38913. var info = sharedUtil.info;
  38914. var isArray = sharedUtil.isArray;
  38915. var warn = sharedUtil.warn;
  38916. var Name = corePrimitives.Name;
  38917. var isStream = corePrimitives.isStream;
  38918. var ColorSpace = coreColorSpace.ColorSpace;
  38919. var DecodeStream = coreStream.DecodeStream;
  38920. var Stream = coreStream.Stream;
  38921. var JpegStream = coreStream.JpegStream;
  38922. var JpxImage = coreJpx.JpxImage;
  38923. var PDFImage = (function PDFImageClosure() {
  38924. /**
  38925. * Decode the image in the main thread if it supported. Resovles the promise
  38926. * when the image data is ready.
  38927. */
  38928. function handleImageData(handler, xref, res, image) {
  38929. if (image instanceof JpegStream && image.isNativelyDecodable(xref, res)) {
  38930. // For natively supported jpegs send them to the main thread for decoding.
  38931. var dict = image.dict;
  38932. var colorSpace = dict.get('ColorSpace', 'CS');
  38933. colorSpace = ColorSpace.parse(colorSpace, xref, res);
  38934. var numComps = colorSpace.numComps;
  38935. var decodePromise = handler.sendWithPromise('JpegDecode',
  38936. [image.getIR(), numComps]);
  38937. return decodePromise.then(function (message) {
  38938. var data = message.data;
  38939. return new Stream(data, 0, data.length, image.dict);
  38940. });
  38941. } else {
  38942. return Promise.resolve(image);
  38943. }
  38944. }
  38945. /**
  38946. * Decode and clamp a value. The formula is different from the spec because we
  38947. * don't decode to float range [0,1], we decode it in the [0,max] range.
  38948. */
  38949. function decodeAndClamp(value, addend, coefficient, max) {
  38950. value = addend + value * coefficient;
  38951. // Clamp the value to the range
  38952. return (value < 0 ? 0 : (value > max ? max : value));
  38953. }
  38954. function PDFImage(xref, res, image, inline, smask, mask, isMask) {
  38955. this.image = image;
  38956. var dict = image.dict;
  38957. if (dict.has('Filter')) {
  38958. var filter = dict.get('Filter').name;
  38959. if (filter === 'JPXDecode') {
  38960. var jpxImage = new JpxImage();
  38961. jpxImage.parseImageProperties(image.stream);
  38962. image.stream.reset();
  38963. image.bitsPerComponent = jpxImage.bitsPerComponent;
  38964. image.numComps = jpxImage.componentsCount;
  38965. } else if (filter === 'JBIG2Decode') {
  38966. image.bitsPerComponent = 1;
  38967. image.numComps = 1;
  38968. }
  38969. }
  38970. // TODO cache rendered images?
  38971. this.width = dict.get('Width', 'W');
  38972. this.height = dict.get('Height', 'H');
  38973. if (this.width < 1 || this.height < 1) {
  38974. error('Invalid image width: ' + this.width + ' or height: ' +
  38975. this.height);
  38976. }
  38977. this.interpolate = dict.get('Interpolate', 'I') || false;
  38978. this.imageMask = dict.get('ImageMask', 'IM') || false;
  38979. this.matte = dict.get('Matte') || false;
  38980. var bitsPerComponent = image.bitsPerComponent;
  38981. if (!bitsPerComponent) {
  38982. bitsPerComponent = dict.get('BitsPerComponent', 'BPC');
  38983. if (!bitsPerComponent) {
  38984. if (this.imageMask) {
  38985. bitsPerComponent = 1;
  38986. } else {
  38987. error('Bits per component missing in image: ' + this.imageMask);
  38988. }
  38989. }
  38990. }
  38991. this.bpc = bitsPerComponent;
  38992. if (!this.imageMask) {
  38993. var colorSpace = dict.get('ColorSpace', 'CS');
  38994. if (!colorSpace) {
  38995. info('JPX images (which do not require color spaces)');
  38996. switch (image.numComps) {
  38997. case 1:
  38998. colorSpace = Name.get('DeviceGray');
  38999. break;
  39000. case 3:
  39001. colorSpace = Name.get('DeviceRGB');
  39002. break;
  39003. case 4:
  39004. colorSpace = Name.get('DeviceCMYK');
  39005. break;
  39006. default:
  39007. error('JPX images with ' + this.numComps +
  39008. ' color components not supported.');
  39009. }
  39010. }
  39011. this.colorSpace = ColorSpace.parse(colorSpace, xref, res);
  39012. this.numComps = this.colorSpace.numComps;
  39013. }
  39014. this.decode = dict.get('Decode', 'D');
  39015. this.needsDecode = false;
  39016. if (this.decode &&
  39017. ((this.colorSpace && !this.colorSpace.isDefaultDecode(this.decode)) ||
  39018. (isMask && !ColorSpace.isDefaultDecode(this.decode, 1)))) {
  39019. this.needsDecode = true;
  39020. // Do some preprocessing to avoid more math.
  39021. var max = (1 << bitsPerComponent) - 1;
  39022. this.decodeCoefficients = [];
  39023. this.decodeAddends = [];
  39024. for (var i = 0, j = 0; i < this.decode.length; i += 2, ++j) {
  39025. var dmin = this.decode[i];
  39026. var dmax = this.decode[i + 1];
  39027. this.decodeCoefficients[j] = dmax - dmin;
  39028. this.decodeAddends[j] = max * dmin;
  39029. }
  39030. }
  39031. if (smask) {
  39032. this.smask = new PDFImage(xref, res, smask, false);
  39033. } else if (mask) {
  39034. if (isStream(mask)) {
  39035. var maskDict = mask.dict, imageMask = maskDict.get('ImageMask', 'IM');
  39036. if (!imageMask) {
  39037. warn('Ignoring /Mask in image without /ImageMask.');
  39038. } else {
  39039. this.mask = new PDFImage(xref, res, mask, false, null, null, true);
  39040. }
  39041. } else {
  39042. // Color key mask (just an array).
  39043. this.mask = mask;
  39044. }
  39045. }
  39046. }
  39047. /**
  39048. * Handles processing of image data and returns the Promise that is resolved
  39049. * with a PDFImage when the image is ready to be used.
  39050. */
  39051. PDFImage.buildImage = function PDFImage_buildImage(handler, xref,
  39052. res, image, inline) {
  39053. var imagePromise = handleImageData(handler, xref, res, image);
  39054. var smaskPromise;
  39055. var maskPromise;
  39056. var smask = image.dict.get('SMask');
  39057. var mask = image.dict.get('Mask');
  39058. if (smask) {
  39059. smaskPromise = handleImageData(handler, xref, res, smask);
  39060. maskPromise = Promise.resolve(null);
  39061. } else {
  39062. smaskPromise = Promise.resolve(null);
  39063. if (mask) {
  39064. if (isStream(mask)) {
  39065. maskPromise = handleImageData(handler, xref, res, mask);
  39066. } else if (isArray(mask)) {
  39067. maskPromise = Promise.resolve(mask);
  39068. } else {
  39069. warn('Unsupported mask format.');
  39070. maskPromise = Promise.resolve(null);
  39071. }
  39072. } else {
  39073. maskPromise = Promise.resolve(null);
  39074. }
  39075. }
  39076. return Promise.all([imagePromise, smaskPromise, maskPromise]).then(
  39077. function(results) {
  39078. var imageData = results[0];
  39079. var smaskData = results[1];
  39080. var maskData = results[2];
  39081. return new PDFImage(xref, res, imageData, inline, smaskData, maskData);
  39082. });
  39083. };
  39084. /**
  39085. * Resize an image using the nearest neighbor algorithm. Currently only
  39086. * supports one and three component images.
  39087. * @param {TypedArray} pixels The original image with one component.
  39088. * @param {Number} bpc Number of bits per component.
  39089. * @param {Number} components Number of color components, 1 or 3 is supported.
  39090. * @param {Number} w1 Original width.
  39091. * @param {Number} h1 Original height.
  39092. * @param {Number} w2 New width.
  39093. * @param {Number} h2 New height.
  39094. * @param {TypedArray} dest (Optional) The destination buffer.
  39095. * @param {Number} alpha01 (Optional) Size reserved for the alpha channel.
  39096. * @return {TypedArray} Resized image data.
  39097. */
  39098. PDFImage.resize = function PDFImage_resize(pixels, bpc, components,
  39099. w1, h1, w2, h2, dest, alpha01) {
  39100. if (components !== 1 && components !== 3) {
  39101. error('Unsupported component count for resizing.');
  39102. }
  39103. var length = w2 * h2 * components;
  39104. var temp = dest ? dest : (bpc <= 8 ? new Uint8Array(length) :
  39105. (bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length)));
  39106. var xRatio = w1 / w2;
  39107. var yRatio = h1 / h2;
  39108. var i, j, py, newIndex = 0, oldIndex;
  39109. var xScaled = new Uint16Array(w2);
  39110. var w1Scanline = w1 * components;
  39111. if (alpha01 !== 1) {
  39112. alpha01 = 0;
  39113. }
  39114. for (j = 0; j < w2; j++) {
  39115. xScaled[j] = Math.floor(j * xRatio) * components;
  39116. }
  39117. if (components === 1) {
  39118. for (i = 0; i < h2; i++) {
  39119. py = Math.floor(i * yRatio) * w1Scanline;
  39120. for (j = 0; j < w2; j++) {
  39121. oldIndex = py + xScaled[j];
  39122. temp[newIndex++] = pixels[oldIndex];
  39123. }
  39124. }
  39125. } else if (components === 3) {
  39126. for (i = 0; i < h2; i++) {
  39127. py = Math.floor(i * yRatio) * w1Scanline;
  39128. for (j = 0; j < w2; j++) {
  39129. oldIndex = py + xScaled[j];
  39130. temp[newIndex++] = pixels[oldIndex++];
  39131. temp[newIndex++] = pixels[oldIndex++];
  39132. temp[newIndex++] = pixels[oldIndex++];
  39133. newIndex += alpha01;
  39134. }
  39135. }
  39136. }
  39137. return temp;
  39138. };
  39139. PDFImage.createMask =
  39140. function PDFImage_createMask(imgArray, width, height,
  39141. imageIsFromDecodeStream, inverseDecode) {
  39142. // |imgArray| might not contain full data for every pixel of the mask, so
  39143. // we need to distinguish between |computedLength| and |actualLength|.
  39144. // In particular, if inverseDecode is true, then the array we return must
  39145. // have a length of |computedLength|.
  39146. var computedLength = ((width + 7) >> 3) * height;
  39147. var actualLength = imgArray.byteLength;
  39148. var haveFullData = computedLength === actualLength;
  39149. var data, i;
  39150. if (imageIsFromDecodeStream && (!inverseDecode || haveFullData)) {
  39151. // imgArray came from a DecodeStream and its data is in an appropriate
  39152. // form, so we can just transfer it.
  39153. data = imgArray;
  39154. } else if (!inverseDecode) {
  39155. data = new Uint8Array(actualLength);
  39156. data.set(imgArray);
  39157. } else {
  39158. data = new Uint8Array(computedLength);
  39159. data.set(imgArray);
  39160. for (i = actualLength; i < computedLength; i++) {
  39161. data[i] = 0xff;
  39162. }
  39163. }
  39164. // If necessary, invert the original mask data (but not any extra we might
  39165. // have added above). It's safe to modify the array -- whether it's the
  39166. // original or a copy, we're about to transfer it anyway, so nothing else
  39167. // in this thread can be relying on its contents.
  39168. if (inverseDecode) {
  39169. for (i = 0; i < actualLength; i++) {
  39170. data[i] = ~data[i];
  39171. }
  39172. }
  39173. return {data: data, width: width, height: height};
  39174. };
  39175. PDFImage.prototype = {
  39176. get drawWidth() {
  39177. return Math.max(this.width,
  39178. this.smask && this.smask.width || 0,
  39179. this.mask && this.mask.width || 0);
  39180. },
  39181. get drawHeight() {
  39182. return Math.max(this.height,
  39183. this.smask && this.smask.height || 0,
  39184. this.mask && this.mask.height || 0);
  39185. },
  39186. decodeBuffer: function PDFImage_decodeBuffer(buffer) {
  39187. var bpc = this.bpc;
  39188. var numComps = this.numComps;
  39189. var decodeAddends = this.decodeAddends;
  39190. var decodeCoefficients = this.decodeCoefficients;
  39191. var max = (1 << bpc) - 1;
  39192. var i, ii;
  39193. if (bpc === 1) {
  39194. // If the buffer needed decode that means it just needs to be inverted.
  39195. for (i = 0, ii = buffer.length; i < ii; i++) {
  39196. buffer[i] = +!(buffer[i]);
  39197. }
  39198. return;
  39199. }
  39200. var index = 0;
  39201. for (i = 0, ii = this.width * this.height; i < ii; i++) {
  39202. for (var j = 0; j < numComps; j++) {
  39203. buffer[index] = decodeAndClamp(buffer[index], decodeAddends[j],
  39204. decodeCoefficients[j], max);
  39205. index++;
  39206. }
  39207. }
  39208. },
  39209. getComponents: function PDFImage_getComponents(buffer) {
  39210. var bpc = this.bpc;
  39211. // This image doesn't require any extra work.
  39212. if (bpc === 8) {
  39213. return buffer;
  39214. }
  39215. var width = this.width;
  39216. var height = this.height;
  39217. var numComps = this.numComps;
  39218. var length = width * height * numComps;
  39219. var bufferPos = 0;
  39220. var output = (bpc <= 8 ? new Uint8Array(length) :
  39221. (bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length)));
  39222. var rowComps = width * numComps;
  39223. var max = (1 << bpc) - 1;
  39224. var i = 0, ii, buf;
  39225. if (bpc === 1) {
  39226. // Optimization for reading 1 bpc images.
  39227. var mask, loop1End, loop2End;
  39228. for (var j = 0; j < height; j++) {
  39229. loop1End = i + (rowComps & ~7);
  39230. loop2End = i + rowComps;
  39231. // unroll loop for all full bytes
  39232. while (i < loop1End) {
  39233. buf = buffer[bufferPos++];
  39234. output[i] = (buf >> 7) & 1;
  39235. output[i + 1] = (buf >> 6) & 1;
  39236. output[i + 2] = (buf >> 5) & 1;
  39237. output[i + 3] = (buf >> 4) & 1;
  39238. output[i + 4] = (buf >> 3) & 1;
  39239. output[i + 5] = (buf >> 2) & 1;
  39240. output[i + 6] = (buf >> 1) & 1;
  39241. output[i + 7] = buf & 1;
  39242. i += 8;
  39243. }
  39244. // handle remaing bits
  39245. if (i < loop2End) {
  39246. buf = buffer[bufferPos++];
  39247. mask = 128;
  39248. while (i < loop2End) {
  39249. output[i++] = +!!(buf & mask);
  39250. mask >>= 1;
  39251. }
  39252. }
  39253. }
  39254. } else {
  39255. // The general case that handles all other bpc values.
  39256. var bits = 0;
  39257. buf = 0;
  39258. for (i = 0, ii = length; i < ii; ++i) {
  39259. if (i % rowComps === 0) {
  39260. buf = 0;
  39261. bits = 0;
  39262. }
  39263. while (bits < bpc) {
  39264. buf = (buf << 8) | buffer[bufferPos++];
  39265. bits += 8;
  39266. }
  39267. var remainingBits = bits - bpc;
  39268. var value = buf >> remainingBits;
  39269. output[i] = (value < 0 ? 0 : (value > max ? max : value));
  39270. buf = buf & ((1 << remainingBits) - 1);
  39271. bits = remainingBits;
  39272. }
  39273. }
  39274. return output;
  39275. },
  39276. fillOpacity: function PDFImage_fillOpacity(rgbaBuf, width, height,
  39277. actualHeight, image) {
  39278. var smask = this.smask;
  39279. var mask = this.mask;
  39280. var alphaBuf, sw, sh, i, ii, j;
  39281. if (smask) {
  39282. sw = smask.width;
  39283. sh = smask.height;
  39284. alphaBuf = new Uint8Array(sw * sh);
  39285. smask.fillGrayBuffer(alphaBuf);
  39286. if (sw !== width || sh !== height) {
  39287. alphaBuf = PDFImage.resize(alphaBuf, smask.bpc, 1, sw, sh, width,
  39288. height);
  39289. }
  39290. } else if (mask) {
  39291. if (mask instanceof PDFImage) {
  39292. sw = mask.width;
  39293. sh = mask.height;
  39294. alphaBuf = new Uint8Array(sw * sh);
  39295. mask.numComps = 1;
  39296. mask.fillGrayBuffer(alphaBuf);
  39297. // Need to invert values in rgbaBuf
  39298. for (i = 0, ii = sw * sh; i < ii; ++i) {
  39299. alphaBuf[i] = 255 - alphaBuf[i];
  39300. }
  39301. if (sw !== width || sh !== height) {
  39302. alphaBuf = PDFImage.resize(alphaBuf, mask.bpc, 1, sw, sh, width,
  39303. height);
  39304. }
  39305. } else if (isArray(mask)) {
  39306. // Color key mask: if any of the compontents are outside the range
  39307. // then they should be painted.
  39308. alphaBuf = new Uint8Array(width * height);
  39309. var numComps = this.numComps;
  39310. for (i = 0, ii = width * height; i < ii; ++i) {
  39311. var opacity = 0;
  39312. var imageOffset = i * numComps;
  39313. for (j = 0; j < numComps; ++j) {
  39314. var color = image[imageOffset + j];
  39315. var maskOffset = j * 2;
  39316. if (color < mask[maskOffset] || color > mask[maskOffset + 1]) {
  39317. opacity = 255;
  39318. break;
  39319. }
  39320. }
  39321. alphaBuf[i] = opacity;
  39322. }
  39323. } else {
  39324. error('Unknown mask format.');
  39325. }
  39326. }
  39327. if (alphaBuf) {
  39328. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  39329. rgbaBuf[j] = alphaBuf[i];
  39330. }
  39331. } else {
  39332. // No mask.
  39333. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  39334. rgbaBuf[j] = 255;
  39335. }
  39336. }
  39337. },
  39338. undoPreblend: function PDFImage_undoPreblend(buffer, width, height) {
  39339. var matte = this.smask && this.smask.matte;
  39340. if (!matte) {
  39341. return;
  39342. }
  39343. var matteRgb = this.colorSpace.getRgb(matte, 0);
  39344. var matteR = matteRgb[0];
  39345. var matteG = matteRgb[1];
  39346. var matteB = matteRgb[2];
  39347. var length = width * height * 4;
  39348. var r, g, b;
  39349. for (var i = 0; i < length; i += 4) {
  39350. var alpha = buffer[i + 3];
  39351. if (alpha === 0) {
  39352. // according formula we have to get Infinity in all components
  39353. // making it white (typical paper color) should be okay
  39354. buffer[i] = 255;
  39355. buffer[i + 1] = 255;
  39356. buffer[i + 2] = 255;
  39357. continue;
  39358. }
  39359. var k = 255 / alpha;
  39360. r = (buffer[i] - matteR) * k + matteR;
  39361. g = (buffer[i + 1] - matteG) * k + matteG;
  39362. b = (buffer[i + 2] - matteB) * k + matteB;
  39363. buffer[i] = r <= 0 ? 0 : r >= 255 ? 255 : r | 0;
  39364. buffer[i + 1] = g <= 0 ? 0 : g >= 255 ? 255 : g | 0;
  39365. buffer[i + 2] = b <= 0 ? 0 : b >= 255 ? 255 : b | 0;
  39366. }
  39367. },
  39368. createImageData: function PDFImage_createImageData(forceRGBA) {
  39369. var drawWidth = this.drawWidth;
  39370. var drawHeight = this.drawHeight;
  39371. var imgData = { // other fields are filled in below
  39372. width: drawWidth,
  39373. height: drawHeight
  39374. };
  39375. var numComps = this.numComps;
  39376. var originalWidth = this.width;
  39377. var originalHeight = this.height;
  39378. var bpc = this.bpc;
  39379. // Rows start at byte boundary.
  39380. var rowBytes = (originalWidth * numComps * bpc + 7) >> 3;
  39381. var imgArray;
  39382. if (!forceRGBA) {
  39383. // If it is a 1-bit-per-pixel grayscale (i.e. black-and-white) image
  39384. // without any complications, we pass a same-sized copy to the main
  39385. // thread rather than expanding by 32x to RGBA form. This saves *lots*
  39386. // of memory for many scanned documents. It's also much faster.
  39387. //
  39388. // Similarly, if it is a 24-bit-per pixel RGB image without any
  39389. // complications, we avoid expanding by 1.333x to RGBA form.
  39390. var kind;
  39391. if (this.colorSpace.name === 'DeviceGray' && bpc === 1) {
  39392. kind = ImageKind.GRAYSCALE_1BPP;
  39393. } else if (this.colorSpace.name === 'DeviceRGB' && bpc === 8 &&
  39394. !this.needsDecode) {
  39395. kind = ImageKind.RGB_24BPP;
  39396. }
  39397. if (kind && !this.smask && !this.mask &&
  39398. drawWidth === originalWidth && drawHeight === originalHeight) {
  39399. imgData.kind = kind;
  39400. imgArray = this.getImageBytes(originalHeight * rowBytes);
  39401. // If imgArray came from a DecodeStream, we're safe to transfer it
  39402. // (and thus neuter it) because it will constitute the entire
  39403. // DecodeStream's data. But if it came from a Stream, we need to
  39404. // copy it because it'll only be a portion of the Stream's data, and
  39405. // the rest will be read later on.
  39406. if (this.image instanceof DecodeStream) {
  39407. imgData.data = imgArray;
  39408. } else {
  39409. var newArray = new Uint8Array(imgArray.length);
  39410. newArray.set(imgArray);
  39411. imgData.data = newArray;
  39412. }
  39413. if (this.needsDecode) {
  39414. // Invert the buffer (which must be grayscale if we reached here).
  39415. assert(kind === ImageKind.GRAYSCALE_1BPP);
  39416. var buffer = imgData.data;
  39417. for (var i = 0, ii = buffer.length; i < ii; i++) {
  39418. buffer[i] ^= 0xff;
  39419. }
  39420. }
  39421. return imgData;
  39422. }
  39423. if (this.image instanceof JpegStream && !this.smask && !this.mask &&
  39424. (this.colorSpace.name === 'DeviceGray' ||
  39425. this.colorSpace.name === 'DeviceRGB' ||
  39426. this.colorSpace.name === 'DeviceCMYK')) {
  39427. imgData.kind = ImageKind.RGB_24BPP;
  39428. imgData.data = this.getImageBytes(originalHeight * rowBytes,
  39429. drawWidth, drawHeight, true);
  39430. return imgData;
  39431. }
  39432. }
  39433. imgArray = this.getImageBytes(originalHeight * rowBytes);
  39434. // imgArray can be incomplete (e.g. after CCITT fax encoding).
  39435. var actualHeight = 0 | (imgArray.length / rowBytes *
  39436. drawHeight / originalHeight);
  39437. var comps = this.getComponents(imgArray);
  39438. // If opacity data is present, use RGBA_32BPP form. Otherwise, use the
  39439. // more compact RGB_24BPP form if allowable.
  39440. var alpha01, maybeUndoPreblend;
  39441. if (!forceRGBA && !this.smask && !this.mask) {
  39442. imgData.kind = ImageKind.RGB_24BPP;
  39443. imgData.data = new Uint8Array(drawWidth * drawHeight * 3);
  39444. alpha01 = 0;
  39445. maybeUndoPreblend = false;
  39446. } else {
  39447. imgData.kind = ImageKind.RGBA_32BPP;
  39448. imgData.data = new Uint8Array(drawWidth * drawHeight * 4);
  39449. alpha01 = 1;
  39450. maybeUndoPreblend = true;
  39451. // Color key masking (opacity) must be performed before decoding.
  39452. this.fillOpacity(imgData.data, drawWidth, drawHeight, actualHeight,
  39453. comps);
  39454. }
  39455. if (this.needsDecode) {
  39456. this.decodeBuffer(comps);
  39457. }
  39458. this.colorSpace.fillRgb(imgData.data, originalWidth, originalHeight,
  39459. drawWidth, drawHeight, actualHeight, bpc, comps,
  39460. alpha01);
  39461. if (maybeUndoPreblend) {
  39462. this.undoPreblend(imgData.data, drawWidth, actualHeight);
  39463. }
  39464. return imgData;
  39465. },
  39466. fillGrayBuffer: function PDFImage_fillGrayBuffer(buffer) {
  39467. var numComps = this.numComps;
  39468. if (numComps !== 1) {
  39469. error('Reading gray scale from a color image: ' + numComps);
  39470. }
  39471. var width = this.width;
  39472. var height = this.height;
  39473. var bpc = this.bpc;
  39474. // rows start at byte boundary
  39475. var rowBytes = (width * numComps * bpc + 7) >> 3;
  39476. var imgArray = this.getImageBytes(height * rowBytes);
  39477. var comps = this.getComponents(imgArray);
  39478. var i, length;
  39479. if (bpc === 1) {
  39480. // inline decoding (= inversion) for 1 bpc images
  39481. length = width * height;
  39482. if (this.needsDecode) {
  39483. // invert and scale to {0, 255}
  39484. for (i = 0; i < length; ++i) {
  39485. buffer[i] = (comps[i] - 1) & 255;
  39486. }
  39487. } else {
  39488. // scale to {0, 255}
  39489. for (i = 0; i < length; ++i) {
  39490. buffer[i] = (-comps[i]) & 255;
  39491. }
  39492. }
  39493. return;
  39494. }
  39495. if (this.needsDecode) {
  39496. this.decodeBuffer(comps);
  39497. }
  39498. length = width * height;
  39499. // we aren't using a colorspace so we need to scale the value
  39500. var scale = 255 / ((1 << bpc) - 1);
  39501. for (i = 0; i < length; ++i) {
  39502. buffer[i] = (scale * comps[i]) | 0;
  39503. }
  39504. },
  39505. getImageBytes: function PDFImage_getImageBytes(length,
  39506. drawWidth, drawHeight,
  39507. forceRGB) {
  39508. this.image.reset();
  39509. this.image.drawWidth = drawWidth || this.width;
  39510. this.image.drawHeight = drawHeight || this.height;
  39511. this.image.forceRGB = !!forceRGB;
  39512. return this.image.getBytes(length);
  39513. }
  39514. };
  39515. return PDFImage;
  39516. })();
  39517. exports.PDFImage = PDFImage;
  39518. // TODO refactor to remove dependency on colorspace.js
  39519. coreColorSpace._setCoreImage(exports);
  39520. }));
  39521. (function (root, factory) {
  39522. {
  39523. factory((root.pdfjsCorePattern = {}), root.pdfjsSharedUtil,
  39524. root.pdfjsCorePrimitives, root.pdfjsCoreFunction,
  39525. root.pdfjsCoreColorSpace);
  39526. }
  39527. }(this, function (exports, sharedUtil, corePrimitives, coreFunction,
  39528. coreColorSpace) {
  39529. var UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
  39530. var MissingDataException = sharedUtil.MissingDataException;
  39531. var Util = sharedUtil.Util;
  39532. var assert = sharedUtil.assert;
  39533. var error = sharedUtil.error;
  39534. var info = sharedUtil.info;
  39535. var warn = sharedUtil.warn;
  39536. var isStream = corePrimitives.isStream;
  39537. var PDFFunction = coreFunction.PDFFunction;
  39538. var ColorSpace = coreColorSpace.ColorSpace;
  39539. var ShadingType = {
  39540. FUNCTION_BASED: 1,
  39541. AXIAL: 2,
  39542. RADIAL: 3,
  39543. FREE_FORM_MESH: 4,
  39544. LATTICE_FORM_MESH: 5,
  39545. COONS_PATCH_MESH: 6,
  39546. TENSOR_PATCH_MESH: 7
  39547. };
  39548. var Pattern = (function PatternClosure() {
  39549. // Constructor should define this.getPattern
  39550. function Pattern() {
  39551. error('should not call Pattern constructor');
  39552. }
  39553. Pattern.prototype = {
  39554. // Input: current Canvas context
  39555. // Output: the appropriate fillStyle or strokeStyle
  39556. getPattern: function Pattern_getPattern(ctx) {
  39557. error('Should not call Pattern.getStyle: ' + ctx);
  39558. }
  39559. };
  39560. Pattern.parseShading = function Pattern_parseShading(shading, matrix, xref,
  39561. res, handler) {
  39562. var dict = isStream(shading) ? shading.dict : shading;
  39563. var type = dict.get('ShadingType');
  39564. try {
  39565. switch (type) {
  39566. case ShadingType.AXIAL:
  39567. case ShadingType.RADIAL:
  39568. // Both radial and axial shadings are handled by RadialAxial shading.
  39569. return new Shadings.RadialAxial(dict, matrix, xref, res);
  39570. case ShadingType.FREE_FORM_MESH:
  39571. case ShadingType.LATTICE_FORM_MESH:
  39572. case ShadingType.COONS_PATCH_MESH:
  39573. case ShadingType.TENSOR_PATCH_MESH:
  39574. return new Shadings.Mesh(shading, matrix, xref, res);
  39575. default:
  39576. throw new Error('Unsupported ShadingType: ' + type);
  39577. }
  39578. } catch (ex) {
  39579. if (ex instanceof MissingDataException) {
  39580. throw ex;
  39581. }
  39582. handler.send('UnsupportedFeature',
  39583. {featureId: UNSUPPORTED_FEATURES.shadingPattern});
  39584. warn(ex);
  39585. return new Shadings.Dummy();
  39586. }
  39587. };
  39588. return Pattern;
  39589. })();
  39590. var Shadings = {};
  39591. // A small number to offset the first/last color stops so we can insert ones to
  39592. // support extend. Number.MIN_VALUE appears to be too small and breaks the
  39593. // extend. 1e-7 works in FF but chrome seems to use an even smaller sized number
  39594. // internally so we have to go bigger.
  39595. Shadings.SMALL_NUMBER = 1e-2;
  39596. // Radial and axial shading have very similar implementations
  39597. // If needed, the implementations can be broken into two classes
  39598. Shadings.RadialAxial = (function RadialAxialClosure() {
  39599. function RadialAxial(dict, matrix, xref, res) {
  39600. this.matrix = matrix;
  39601. this.coordsArr = dict.get('Coords');
  39602. this.shadingType = dict.get('ShadingType');
  39603. this.type = 'Pattern';
  39604. var cs = dict.get('ColorSpace', 'CS');
  39605. cs = ColorSpace.parse(cs, xref, res);
  39606. this.cs = cs;
  39607. var t0 = 0.0, t1 = 1.0;
  39608. if (dict.has('Domain')) {
  39609. var domainArr = dict.get('Domain');
  39610. t0 = domainArr[0];
  39611. t1 = domainArr[1];
  39612. }
  39613. var extendStart = false, extendEnd = false;
  39614. if (dict.has('Extend')) {
  39615. var extendArr = dict.get('Extend');
  39616. extendStart = extendArr[0];
  39617. extendEnd = extendArr[1];
  39618. }
  39619. if (this.shadingType === ShadingType.RADIAL &&
  39620. (!extendStart || !extendEnd)) {
  39621. // Radial gradient only currently works if either circle is fully within
  39622. // the other circle.
  39623. var x1 = this.coordsArr[0];
  39624. var y1 = this.coordsArr[1];
  39625. var r1 = this.coordsArr[2];
  39626. var x2 = this.coordsArr[3];
  39627. var y2 = this.coordsArr[4];
  39628. var r2 = this.coordsArr[5];
  39629. var distance = Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
  39630. if (r1 <= r2 + distance &&
  39631. r2 <= r1 + distance) {
  39632. warn('Unsupported radial gradient.');
  39633. }
  39634. }
  39635. this.extendStart = extendStart;
  39636. this.extendEnd = extendEnd;
  39637. var fnObj = dict.get('Function');
  39638. var fn = PDFFunction.parseArray(xref, fnObj);
  39639. // 10 samples seems good enough for now, but probably won't work
  39640. // if there are sharp color changes. Ideally, we would implement
  39641. // the spec faithfully and add lossless optimizations.
  39642. var diff = t1 - t0;
  39643. var step = diff / 10;
  39644. var colorStops = this.colorStops = [];
  39645. // Protect against bad domains so we don't end up in an infinte loop below.
  39646. if (t0 >= t1 || step <= 0) {
  39647. // Acrobat doesn't seem to handle these cases so we'll ignore for
  39648. // now.
  39649. info('Bad shading domain.');
  39650. return;
  39651. }
  39652. var color = new Float32Array(cs.numComps), ratio = new Float32Array(1);
  39653. var rgbColor;
  39654. for (var i = t0; i <= t1; i += step) {
  39655. ratio[0] = i;
  39656. fn(ratio, 0, color, 0);
  39657. rgbColor = cs.getRgb(color, 0);
  39658. var cssColor = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
  39659. colorStops.push([(i - t0) / diff, cssColor]);
  39660. }
  39661. var background = 'transparent';
  39662. if (dict.has('Background')) {
  39663. rgbColor = cs.getRgb(dict.get('Background'), 0);
  39664. background = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
  39665. }
  39666. if (!extendStart) {
  39667. // Insert a color stop at the front and offset the first real color stop
  39668. // so it doesn't conflict with the one we insert.
  39669. colorStops.unshift([0, background]);
  39670. colorStops[1][0] += Shadings.SMALL_NUMBER;
  39671. }
  39672. if (!extendEnd) {
  39673. // Same idea as above in extendStart but for the end.
  39674. colorStops[colorStops.length - 1][0] -= Shadings.SMALL_NUMBER;
  39675. colorStops.push([1, background]);
  39676. }
  39677. this.colorStops = colorStops;
  39678. }
  39679. RadialAxial.prototype = {
  39680. getIR: function RadialAxial_getIR() {
  39681. var coordsArr = this.coordsArr;
  39682. var shadingType = this.shadingType;
  39683. var type, p0, p1, r0, r1;
  39684. if (shadingType === ShadingType.AXIAL) {
  39685. p0 = [coordsArr[0], coordsArr[1]];
  39686. p1 = [coordsArr[2], coordsArr[3]];
  39687. r0 = null;
  39688. r1 = null;
  39689. type = 'axial';
  39690. } else if (shadingType === ShadingType.RADIAL) {
  39691. p0 = [coordsArr[0], coordsArr[1]];
  39692. p1 = [coordsArr[3], coordsArr[4]];
  39693. r0 = coordsArr[2];
  39694. r1 = coordsArr[5];
  39695. type = 'radial';
  39696. } else {
  39697. error('getPattern type unknown: ' + shadingType);
  39698. }
  39699. var matrix = this.matrix;
  39700. if (matrix) {
  39701. p0 = Util.applyTransform(p0, matrix);
  39702. p1 = Util.applyTransform(p1, matrix);
  39703. if (shadingType === ShadingType.RADIAL) {
  39704. var scale = Util.singularValueDecompose2dScale(matrix);
  39705. r0 *= scale[0];
  39706. r1 *= scale[1];
  39707. }
  39708. }
  39709. return ['RadialAxial', type, this.colorStops, p0, p1, r0, r1];
  39710. }
  39711. };
  39712. return RadialAxial;
  39713. })();
  39714. // All mesh shading. For now, they will be presented as set of the triangles
  39715. // to be drawn on the canvas and rgb color for each vertex.
  39716. Shadings.Mesh = (function MeshClosure() {
  39717. function MeshStreamReader(stream, context) {
  39718. this.stream = stream;
  39719. this.context = context;
  39720. this.buffer = 0;
  39721. this.bufferLength = 0;
  39722. var numComps = context.numComps;
  39723. this.tmpCompsBuf = new Float32Array(numComps);
  39724. var csNumComps = context.colorSpace.numComps;
  39725. this.tmpCsCompsBuf = context.colorFn ? new Float32Array(csNumComps) :
  39726. this.tmpCompsBuf;
  39727. }
  39728. MeshStreamReader.prototype = {
  39729. get hasData() {
  39730. if (this.stream.end) {
  39731. return this.stream.pos < this.stream.end;
  39732. }
  39733. if (this.bufferLength > 0) {
  39734. return true;
  39735. }
  39736. var nextByte = this.stream.getByte();
  39737. if (nextByte < 0) {
  39738. return false;
  39739. }
  39740. this.buffer = nextByte;
  39741. this.bufferLength = 8;
  39742. return true;
  39743. },
  39744. readBits: function MeshStreamReader_readBits(n) {
  39745. var buffer = this.buffer;
  39746. var bufferLength = this.bufferLength;
  39747. if (n === 32) {
  39748. if (bufferLength === 0) {
  39749. return ((this.stream.getByte() << 24) |
  39750. (this.stream.getByte() << 16) | (this.stream.getByte() << 8) |
  39751. this.stream.getByte()) >>> 0;
  39752. }
  39753. buffer = (buffer << 24) | (this.stream.getByte() << 16) |
  39754. (this.stream.getByte() << 8) | this.stream.getByte();
  39755. var nextByte = this.stream.getByte();
  39756. this.buffer = nextByte & ((1 << bufferLength) - 1);
  39757. return ((buffer << (8 - bufferLength)) |
  39758. ((nextByte & 0xFF) >> bufferLength)) >>> 0;
  39759. }
  39760. if (n === 8 && bufferLength === 0) {
  39761. return this.stream.getByte();
  39762. }
  39763. while (bufferLength < n) {
  39764. buffer = (buffer << 8) | this.stream.getByte();
  39765. bufferLength += 8;
  39766. }
  39767. bufferLength -= n;
  39768. this.bufferLength = bufferLength;
  39769. this.buffer = buffer & ((1 << bufferLength) - 1);
  39770. return buffer >> bufferLength;
  39771. },
  39772. align: function MeshStreamReader_align() {
  39773. this.buffer = 0;
  39774. this.bufferLength = 0;
  39775. },
  39776. readFlag: function MeshStreamReader_readFlag() {
  39777. return this.readBits(this.context.bitsPerFlag);
  39778. },
  39779. readCoordinate: function MeshStreamReader_readCoordinate() {
  39780. var bitsPerCoordinate = this.context.bitsPerCoordinate;
  39781. var xi = this.readBits(bitsPerCoordinate);
  39782. var yi = this.readBits(bitsPerCoordinate);
  39783. var decode = this.context.decode;
  39784. var scale = bitsPerCoordinate < 32 ? 1 / ((1 << bitsPerCoordinate) - 1) :
  39785. 2.3283064365386963e-10; // 2 ^ -32
  39786. return [
  39787. xi * scale * (decode[1] - decode[0]) + decode[0],
  39788. yi * scale * (decode[3] - decode[2]) + decode[2]
  39789. ];
  39790. },
  39791. readComponents: function MeshStreamReader_readComponents() {
  39792. var numComps = this.context.numComps;
  39793. var bitsPerComponent = this.context.bitsPerComponent;
  39794. var scale = bitsPerComponent < 32 ? 1 / ((1 << bitsPerComponent) - 1) :
  39795. 2.3283064365386963e-10; // 2 ^ -32
  39796. var decode = this.context.decode;
  39797. var components = this.tmpCompsBuf;
  39798. for (var i = 0, j = 4; i < numComps; i++, j += 2) {
  39799. var ci = this.readBits(bitsPerComponent);
  39800. components[i] = ci * scale * (decode[j + 1] - decode[j]) + decode[j];
  39801. }
  39802. var color = this.tmpCsCompsBuf;
  39803. if (this.context.colorFn) {
  39804. this.context.colorFn(components, 0, color, 0);
  39805. }
  39806. return this.context.colorSpace.getRgb(color, 0);
  39807. }
  39808. };
  39809. function decodeType4Shading(mesh, reader) {
  39810. var coords = mesh.coords;
  39811. var colors = mesh.colors;
  39812. var operators = [];
  39813. var ps = []; // not maintaining cs since that will match ps
  39814. var verticesLeft = 0; // assuming we have all data to start a new triangle
  39815. while (reader.hasData) {
  39816. var f = reader.readFlag();
  39817. var coord = reader.readCoordinate();
  39818. var color = reader.readComponents();
  39819. if (verticesLeft === 0) { // ignoring flags if we started a triangle
  39820. assert(0 <= f && f <= 2, 'Unknown type4 flag');
  39821. switch (f) {
  39822. case 0:
  39823. verticesLeft = 3;
  39824. break;
  39825. case 1:
  39826. ps.push(ps[ps.length - 2], ps[ps.length - 1]);
  39827. verticesLeft = 1;
  39828. break;
  39829. case 2:
  39830. ps.push(ps[ps.length - 3], ps[ps.length - 1]);
  39831. verticesLeft = 1;
  39832. break;
  39833. }
  39834. operators.push(f);
  39835. }
  39836. ps.push(coords.length);
  39837. coords.push(coord);
  39838. colors.push(color);
  39839. verticesLeft--;
  39840. reader.align();
  39841. }
  39842. mesh.figures.push({
  39843. type: 'triangles',
  39844. coords: new Int32Array(ps),
  39845. colors: new Int32Array(ps),
  39846. });
  39847. }
  39848. function decodeType5Shading(mesh, reader, verticesPerRow) {
  39849. var coords = mesh.coords;
  39850. var colors = mesh.colors;
  39851. var ps = []; // not maintaining cs since that will match ps
  39852. while (reader.hasData) {
  39853. var coord = reader.readCoordinate();
  39854. var color = reader.readComponents();
  39855. ps.push(coords.length);
  39856. coords.push(coord);
  39857. colors.push(color);
  39858. }
  39859. mesh.figures.push({
  39860. type: 'lattice',
  39861. coords: new Int32Array(ps),
  39862. colors: new Int32Array(ps),
  39863. verticesPerRow: verticesPerRow
  39864. });
  39865. }
  39866. var MIN_SPLIT_PATCH_CHUNKS_AMOUNT = 3;
  39867. var MAX_SPLIT_PATCH_CHUNKS_AMOUNT = 20;
  39868. var TRIANGLE_DENSITY = 20; // count of triangles per entire mesh bounds
  39869. var getB = (function getBClosure() {
  39870. function buildB(count) {
  39871. var lut = [];
  39872. for (var i = 0; i <= count; i++) {
  39873. var t = i / count, t_ = 1 - t;
  39874. lut.push(new Float32Array([t_ * t_ * t_, 3 * t * t_ * t_,
  39875. 3 * t * t * t_, t * t * t]));
  39876. }
  39877. return lut;
  39878. }
  39879. var cache = [];
  39880. return function getB(count) {
  39881. if (!cache[count]) {
  39882. cache[count] = buildB(count);
  39883. }
  39884. return cache[count];
  39885. };
  39886. })();
  39887. function buildFigureFromPatch(mesh, index) {
  39888. var figure = mesh.figures[index];
  39889. assert(figure.type === 'patch', 'Unexpected patch mesh figure');
  39890. var coords = mesh.coords, colors = mesh.colors;
  39891. var pi = figure.coords;
  39892. var ci = figure.colors;
  39893. var figureMinX = Math.min(coords[pi[0]][0], coords[pi[3]][0],
  39894. coords[pi[12]][0], coords[pi[15]][0]);
  39895. var figureMinY = Math.min(coords[pi[0]][1], coords[pi[3]][1],
  39896. coords[pi[12]][1], coords[pi[15]][1]);
  39897. var figureMaxX = Math.max(coords[pi[0]][0], coords[pi[3]][0],
  39898. coords[pi[12]][0], coords[pi[15]][0]);
  39899. var figureMaxY = Math.max(coords[pi[0]][1], coords[pi[3]][1],
  39900. coords[pi[12]][1], coords[pi[15]][1]);
  39901. var splitXBy = Math.ceil((figureMaxX - figureMinX) * TRIANGLE_DENSITY /
  39902. (mesh.bounds[2] - mesh.bounds[0]));
  39903. splitXBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
  39904. Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitXBy));
  39905. var splitYBy = Math.ceil((figureMaxY - figureMinY) * TRIANGLE_DENSITY /
  39906. (mesh.bounds[3] - mesh.bounds[1]));
  39907. splitYBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
  39908. Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitYBy));
  39909. var verticesPerRow = splitXBy + 1;
  39910. var figureCoords = new Int32Array((splitYBy + 1) * verticesPerRow);
  39911. var figureColors = new Int32Array((splitYBy + 1) * verticesPerRow);
  39912. var k = 0;
  39913. var cl = new Uint8Array(3), cr = new Uint8Array(3);
  39914. var c0 = colors[ci[0]], c1 = colors[ci[1]],
  39915. c2 = colors[ci[2]], c3 = colors[ci[3]];
  39916. var bRow = getB(splitYBy), bCol = getB(splitXBy);
  39917. for (var row = 0; row <= splitYBy; row++) {
  39918. cl[0] = ((c0[0] * (splitYBy - row) + c2[0] * row) / splitYBy) | 0;
  39919. cl[1] = ((c0[1] * (splitYBy - row) + c2[1] * row) / splitYBy) | 0;
  39920. cl[2] = ((c0[2] * (splitYBy - row) + c2[2] * row) / splitYBy) | 0;
  39921. cr[0] = ((c1[0] * (splitYBy - row) + c3[0] * row) / splitYBy) | 0;
  39922. cr[1] = ((c1[1] * (splitYBy - row) + c3[1] * row) / splitYBy) | 0;
  39923. cr[2] = ((c1[2] * (splitYBy - row) + c3[2] * row) / splitYBy) | 0;
  39924. for (var col = 0; col <= splitXBy; col++, k++) {
  39925. if ((row === 0 || row === splitYBy) &&
  39926. (col === 0 || col === splitXBy)) {
  39927. continue;
  39928. }
  39929. var x = 0, y = 0;
  39930. var q = 0;
  39931. for (var i = 0; i <= 3; i++) {
  39932. for (var j = 0; j <= 3; j++, q++) {
  39933. var m = bRow[row][i] * bCol[col][j];
  39934. x += coords[pi[q]][0] * m;
  39935. y += coords[pi[q]][1] * m;
  39936. }
  39937. }
  39938. figureCoords[k] = coords.length;
  39939. coords.push([x, y]);
  39940. figureColors[k] = colors.length;
  39941. var newColor = new Uint8Array(3);
  39942. newColor[0] = ((cl[0] * (splitXBy - col) + cr[0] * col) / splitXBy) | 0;
  39943. newColor[1] = ((cl[1] * (splitXBy - col) + cr[1] * col) / splitXBy) | 0;
  39944. newColor[2] = ((cl[2] * (splitXBy - col) + cr[2] * col) / splitXBy) | 0;
  39945. colors.push(newColor);
  39946. }
  39947. }
  39948. figureCoords[0] = pi[0];
  39949. figureColors[0] = ci[0];
  39950. figureCoords[splitXBy] = pi[3];
  39951. figureColors[splitXBy] = ci[1];
  39952. figureCoords[verticesPerRow * splitYBy] = pi[12];
  39953. figureColors[verticesPerRow * splitYBy] = ci[2];
  39954. figureCoords[verticesPerRow * splitYBy + splitXBy] = pi[15];
  39955. figureColors[verticesPerRow * splitYBy + splitXBy] = ci[3];
  39956. mesh.figures[index] = {
  39957. type: 'lattice',
  39958. coords: figureCoords,
  39959. colors: figureColors,
  39960. verticesPerRow: verticesPerRow
  39961. };
  39962. }
  39963. function decodeType6Shading(mesh, reader) {
  39964. // A special case of Type 7. The p11, p12, p21, p22 automatically filled
  39965. var coords = mesh.coords;
  39966. var colors = mesh.colors;
  39967. var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
  39968. var cs = new Int32Array(4); // c00, c30, c03, c33
  39969. while (reader.hasData) {
  39970. var f = reader.readFlag();
  39971. assert(0 <= f && f <= 3, 'Unknown type6 flag');
  39972. var i, ii;
  39973. var pi = coords.length;
  39974. for (i = 0, ii = (f !== 0 ? 8 : 12); i < ii; i++) {
  39975. coords.push(reader.readCoordinate());
  39976. }
  39977. var ci = colors.length;
  39978. for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
  39979. colors.push(reader.readComponents());
  39980. }
  39981. var tmp1, tmp2, tmp3, tmp4;
  39982. switch (f) {
  39983. case 0:
  39984. ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
  39985. ps[ 8] = pi + 2; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 7;
  39986. ps[ 4] = pi + 1; /* calculated below */ ps[ 7] = pi + 8;
  39987. ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
  39988. cs[2] = ci + 1; cs[3] = ci + 2;
  39989. cs[0] = ci; cs[1] = ci + 3;
  39990. break;
  39991. case 1:
  39992. tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
  39993. ps[12] = tmp4; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  39994. ps[ 8] = tmp3; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 3;
  39995. ps[ 4] = tmp2; /* calculated below */ ps[ 7] = pi + 4;
  39996. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  39997. tmp1 = cs[2]; tmp2 = cs[3];
  39998. cs[2] = tmp2; cs[3] = ci;
  39999. cs[0] = tmp1; cs[1] = ci + 1;
  40000. break;
  40001. case 2:
  40002. tmp1 = ps[15];
  40003. tmp2 = ps[11];
  40004. ps[12] = ps[3]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  40005. ps[ 8] = ps[7]; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 3;
  40006. ps[ 4] = tmp2; /* calculated below */ ps[ 7] = pi + 4;
  40007. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  40008. tmp1 = cs[3];
  40009. cs[2] = cs[1]; cs[3] = ci;
  40010. cs[0] = tmp1; cs[1] = ci + 1;
  40011. break;
  40012. case 3:
  40013. ps[12] = ps[0]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  40014. ps[ 8] = ps[1]; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 3;
  40015. ps[ 4] = ps[2]; /* calculated below */ ps[ 7] = pi + 4;
  40016. ps[ 0] = ps[3]; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  40017. cs[2] = cs[0]; cs[3] = ci;
  40018. cs[0] = cs[1]; cs[1] = ci + 1;
  40019. break;
  40020. }
  40021. // set p11, p12, p21, p22
  40022. ps[5] = coords.length;
  40023. coords.push([
  40024. (-4 * coords[ps[0]][0] - coords[ps[15]][0] +
  40025. 6 * (coords[ps[4]][0] + coords[ps[1]][0]) -
  40026. 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
  40027. 3 * (coords[ps[13]][0] + coords[ps[7]][0])) / 9,
  40028. (-4 * coords[ps[0]][1] - coords[ps[15]][1] +
  40029. 6 * (coords[ps[4]][1] + coords[ps[1]][1]) -
  40030. 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
  40031. 3 * (coords[ps[13]][1] + coords[ps[7]][1])) / 9
  40032. ]);
  40033. ps[6] = coords.length;
  40034. coords.push([
  40035. (-4 * coords[ps[3]][0] - coords[ps[12]][0] +
  40036. 6 * (coords[ps[2]][0] + coords[ps[7]][0]) -
  40037. 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
  40038. 3 * (coords[ps[4]][0] + coords[ps[14]][0])) / 9,
  40039. (-4 * coords[ps[3]][1] - coords[ps[12]][1] +
  40040. 6 * (coords[ps[2]][1] + coords[ps[7]][1]) -
  40041. 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
  40042. 3 * (coords[ps[4]][1] + coords[ps[14]][1])) / 9
  40043. ]);
  40044. ps[9] = coords.length;
  40045. coords.push([
  40046. (-4 * coords[ps[12]][0] - coords[ps[3]][0] +
  40047. 6 * (coords[ps[8]][0] + coords[ps[13]][0]) -
  40048. 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
  40049. 3 * (coords[ps[11]][0] + coords[ps[1]][0])) / 9,
  40050. (-4 * coords[ps[12]][1] - coords[ps[3]][1] +
  40051. 6 * (coords[ps[8]][1] + coords[ps[13]][1]) -
  40052. 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
  40053. 3 * (coords[ps[11]][1] + coords[ps[1]][1])) / 9
  40054. ]);
  40055. ps[10] = coords.length;
  40056. coords.push([
  40057. (-4 * coords[ps[15]][0] - coords[ps[0]][0] +
  40058. 6 * (coords[ps[11]][0] + coords[ps[14]][0]) -
  40059. 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
  40060. 3 * (coords[ps[2]][0] + coords[ps[8]][0])) / 9,
  40061. (-4 * coords[ps[15]][1] - coords[ps[0]][1] +
  40062. 6 * (coords[ps[11]][1] + coords[ps[14]][1]) -
  40063. 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
  40064. 3 * (coords[ps[2]][1] + coords[ps[8]][1])) / 9
  40065. ]);
  40066. mesh.figures.push({
  40067. type: 'patch',
  40068. coords: new Int32Array(ps), // making copies of ps and cs
  40069. colors: new Int32Array(cs)
  40070. });
  40071. }
  40072. }
  40073. function decodeType7Shading(mesh, reader) {
  40074. var coords = mesh.coords;
  40075. var colors = mesh.colors;
  40076. var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
  40077. var cs = new Int32Array(4); // c00, c30, c03, c33
  40078. while (reader.hasData) {
  40079. var f = reader.readFlag();
  40080. assert(0 <= f && f <= 3, 'Unknown type7 flag');
  40081. var i, ii;
  40082. var pi = coords.length;
  40083. for (i = 0, ii = (f !== 0 ? 12 : 16); i < ii; i++) {
  40084. coords.push(reader.readCoordinate());
  40085. }
  40086. var ci = colors.length;
  40087. for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
  40088. colors.push(reader.readComponents());
  40089. }
  40090. var tmp1, tmp2, tmp3, tmp4;
  40091. switch (f) {
  40092. case 0:
  40093. ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
  40094. ps[ 8] = pi + 2; ps[ 9] = pi + 13; ps[10] = pi + 14; ps[11] = pi + 7;
  40095. ps[ 4] = pi + 1; ps[ 5] = pi + 12; ps[ 6] = pi + 15; ps[ 7] = pi + 8;
  40096. ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
  40097. cs[2] = ci + 1; cs[3] = ci + 2;
  40098. cs[0] = ci; cs[1] = ci + 3;
  40099. break;
  40100. case 1:
  40101. tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
  40102. ps[12] = tmp4; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  40103. ps[ 8] = tmp3; ps[ 9] = pi + 9; ps[10] = pi + 10; ps[11] = pi + 3;
  40104. ps[ 4] = tmp2; ps[ 5] = pi + 8; ps[ 6] = pi + 11; ps[ 7] = pi + 4;
  40105. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  40106. tmp1 = cs[2]; tmp2 = cs[3];
  40107. cs[2] = tmp2; cs[3] = ci;
  40108. cs[0] = tmp1; cs[1] = ci + 1;
  40109. break;
  40110. case 2:
  40111. tmp1 = ps[15];
  40112. tmp2 = ps[11];
  40113. ps[12] = ps[3]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  40114. ps[ 8] = ps[7]; ps[ 9] = pi + 9; ps[10] = pi + 10; ps[11] = pi + 3;
  40115. ps[ 4] = tmp2; ps[ 5] = pi + 8; ps[ 6] = pi + 11; ps[ 7] = pi + 4;
  40116. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  40117. tmp1 = cs[3];
  40118. cs[2] = cs[1]; cs[3] = ci;
  40119. cs[0] = tmp1; cs[1] = ci + 1;
  40120. break;
  40121. case 3:
  40122. ps[12] = ps[0]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  40123. ps[ 8] = ps[1]; ps[ 9] = pi + 9; ps[10] = pi + 10; ps[11] = pi + 3;
  40124. ps[ 4] = ps[2]; ps[ 5] = pi + 8; ps[ 6] = pi + 11; ps[ 7] = pi + 4;
  40125. ps[ 0] = ps[3]; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  40126. cs[2] = cs[0]; cs[3] = ci;
  40127. cs[0] = cs[1]; cs[1] = ci + 1;
  40128. break;
  40129. }
  40130. mesh.figures.push({
  40131. type: 'patch',
  40132. coords: new Int32Array(ps), // making copies of ps and cs
  40133. colors: new Int32Array(cs)
  40134. });
  40135. }
  40136. }
  40137. function updateBounds(mesh) {
  40138. var minX = mesh.coords[0][0], minY = mesh.coords[0][1],
  40139. maxX = minX, maxY = minY;
  40140. for (var i = 1, ii = mesh.coords.length; i < ii; i++) {
  40141. var x = mesh.coords[i][0], y = mesh.coords[i][1];
  40142. minX = minX > x ? x : minX;
  40143. minY = minY > y ? y : minY;
  40144. maxX = maxX < x ? x : maxX;
  40145. maxY = maxY < y ? y : maxY;
  40146. }
  40147. mesh.bounds = [minX, minY, maxX, maxY];
  40148. }
  40149. function packData(mesh) {
  40150. var i, ii, j, jj;
  40151. var coords = mesh.coords;
  40152. var coordsPacked = new Float32Array(coords.length * 2);
  40153. for (i = 0, j = 0, ii = coords.length; i < ii; i++) {
  40154. var xy = coords[i];
  40155. coordsPacked[j++] = xy[0];
  40156. coordsPacked[j++] = xy[1];
  40157. }
  40158. mesh.coords = coordsPacked;
  40159. var colors = mesh.colors;
  40160. var colorsPacked = new Uint8Array(colors.length * 3);
  40161. for (i = 0, j = 0, ii = colors.length; i < ii; i++) {
  40162. var c = colors[i];
  40163. colorsPacked[j++] = c[0];
  40164. colorsPacked[j++] = c[1];
  40165. colorsPacked[j++] = c[2];
  40166. }
  40167. mesh.colors = colorsPacked;
  40168. var figures = mesh.figures;
  40169. for (i = 0, ii = figures.length; i < ii; i++) {
  40170. var figure = figures[i], ps = figure.coords, cs = figure.colors;
  40171. for (j = 0, jj = ps.length; j < jj; j++) {
  40172. ps[j] *= 2;
  40173. cs[j] *= 3;
  40174. }
  40175. }
  40176. }
  40177. function Mesh(stream, matrix, xref, res) {
  40178. assert(isStream(stream), 'Mesh data is not a stream');
  40179. var dict = stream.dict;
  40180. this.matrix = matrix;
  40181. this.shadingType = dict.get('ShadingType');
  40182. this.type = 'Pattern';
  40183. this.bbox = dict.get('BBox');
  40184. var cs = dict.get('ColorSpace', 'CS');
  40185. cs = ColorSpace.parse(cs, xref, res);
  40186. this.cs = cs;
  40187. this.background = dict.has('Background') ?
  40188. cs.getRgb(dict.get('Background'), 0) : null;
  40189. var fnObj = dict.get('Function');
  40190. var fn = fnObj ? PDFFunction.parseArray(xref, fnObj) : null;
  40191. this.coords = [];
  40192. this.colors = [];
  40193. this.figures = [];
  40194. var decodeContext = {
  40195. bitsPerCoordinate: dict.get('BitsPerCoordinate'),
  40196. bitsPerComponent: dict.get('BitsPerComponent'),
  40197. bitsPerFlag: dict.get('BitsPerFlag'),
  40198. decode: dict.get('Decode'),
  40199. colorFn: fn,
  40200. colorSpace: cs,
  40201. numComps: fn ? 1 : cs.numComps
  40202. };
  40203. var reader = new MeshStreamReader(stream, decodeContext);
  40204. var patchMesh = false;
  40205. switch (this.shadingType) {
  40206. case ShadingType.FREE_FORM_MESH:
  40207. decodeType4Shading(this, reader);
  40208. break;
  40209. case ShadingType.LATTICE_FORM_MESH:
  40210. var verticesPerRow = dict.get('VerticesPerRow') | 0;
  40211. assert(verticesPerRow >= 2, 'Invalid VerticesPerRow');
  40212. decodeType5Shading(this, reader, verticesPerRow);
  40213. break;
  40214. case ShadingType.COONS_PATCH_MESH:
  40215. decodeType6Shading(this, reader);
  40216. patchMesh = true;
  40217. break;
  40218. case ShadingType.TENSOR_PATCH_MESH:
  40219. decodeType7Shading(this, reader);
  40220. patchMesh = true;
  40221. break;
  40222. default:
  40223. error('Unsupported mesh type.');
  40224. break;
  40225. }
  40226. if (patchMesh) {
  40227. // dirty bounds calculation for determining, how dense shall be triangles
  40228. updateBounds(this);
  40229. for (var i = 0, ii = this.figures.length; i < ii; i++) {
  40230. buildFigureFromPatch(this, i);
  40231. }
  40232. }
  40233. // calculate bounds
  40234. updateBounds(this);
  40235. packData(this);
  40236. }
  40237. Mesh.prototype = {
  40238. getIR: function Mesh_getIR() {
  40239. return ['Mesh', this.shadingType, this.coords, this.colors, this.figures,
  40240. this.bounds, this.matrix, this.bbox, this.background];
  40241. }
  40242. };
  40243. return Mesh;
  40244. })();
  40245. Shadings.Dummy = (function DummyClosure() {
  40246. function Dummy() {
  40247. this.type = 'Pattern';
  40248. }
  40249. Dummy.prototype = {
  40250. getIR: function Dummy_getIR() {
  40251. return ['Dummy'];
  40252. }
  40253. };
  40254. return Dummy;
  40255. })();
  40256. function getTilingPatternIR(operatorList, dict, args) {
  40257. var matrix = dict.get('Matrix');
  40258. var bbox = dict.get('BBox');
  40259. var xstep = dict.get('XStep');
  40260. var ystep = dict.get('YStep');
  40261. var paintType = dict.get('PaintType');
  40262. var tilingType = dict.get('TilingType');
  40263. return [
  40264. 'TilingPattern', args, operatorList, matrix, bbox, xstep, ystep,
  40265. paintType, tilingType
  40266. ];
  40267. }
  40268. exports.Pattern = Pattern;
  40269. exports.getTilingPatternIR = getTilingPatternIR;
  40270. }));
  40271. (function (root, factory) {
  40272. {
  40273. factory((root.pdfjsCoreEvaluator = {}), root.pdfjsSharedUtil,
  40274. root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreParser,
  40275. root.pdfjsCoreImage, root.pdfjsCoreColorSpace, root.pdfjsCoreMurmurHash3,
  40276. root.pdfjsCoreFonts, root.pdfjsCoreFunction, root.pdfjsCorePattern,
  40277. root.pdfjsCoreCMap, root.pdfjsCoreMetrics, root.pdfjsCoreBidi);
  40278. }
  40279. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreParser,
  40280. coreImage, coreColorSpace, coreMurmurHash3, coreFonts,
  40281. coreFunction, corePattern, coreCMap, coreMetrics, coreBidi) {
  40282. var FONT_IDENTITY_MATRIX = sharedUtil.FONT_IDENTITY_MATRIX;
  40283. var IDENTITY_MATRIX = sharedUtil.IDENTITY_MATRIX;
  40284. var UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
  40285. var ImageKind = sharedUtil.ImageKind;
  40286. var OPS = sharedUtil.OPS;
  40287. var TextRenderingMode = sharedUtil.TextRenderingMode;
  40288. var Util = sharedUtil.Util;
  40289. var assert = sharedUtil.assert;
  40290. var createPromiseCapability = sharedUtil.createPromiseCapability;
  40291. var error = sharedUtil.error;
  40292. var info = sharedUtil.info;
  40293. var isArray = sharedUtil.isArray;
  40294. var isNum = sharedUtil.isNum;
  40295. var isString = sharedUtil.isString;
  40296. var warn = sharedUtil.warn;
  40297. var Dict = corePrimitives.Dict;
  40298. var Name = corePrimitives.Name;
  40299. var isCmd = corePrimitives.isCmd;
  40300. var isDict = corePrimitives.isDict;
  40301. var isName = corePrimitives.isName;
  40302. var isRef = corePrimitives.isRef;
  40303. var isStream = corePrimitives.isStream;
  40304. var DecodeStream = coreStream.DecodeStream;
  40305. var JpegStream = coreStream.JpegStream;
  40306. var Lexer = coreParser.Lexer;
  40307. var Parser = coreParser.Parser;
  40308. var isEOF = coreParser.isEOF;
  40309. var PDFImage = coreImage.PDFImage;
  40310. var ColorSpace = coreColorSpace.ColorSpace;
  40311. var MurmurHash3_64 = coreMurmurHash3.MurmurHash3_64;
  40312. var Encodings = coreFonts.Encodings;
  40313. var ErrorFont = coreFonts.ErrorFont;
  40314. var FontFlags = coreFonts.FontFlags;
  40315. var Font = coreFonts.Font;
  40316. var IdentityToUnicodeMap = coreFonts.IdentityToUnicodeMap;
  40317. var NormalizedUnicodes = coreFonts.NormalizedUnicodes;
  40318. var ToUnicodeMap = coreFonts.ToUnicodeMap;
  40319. var getFontType = coreFonts.getFontType;
  40320. var reverseIfRtl = coreFonts.reverseIfRtl;
  40321. var serifFonts = coreFonts.serifFonts;
  40322. var symbolsFonts = coreFonts.symbolsFonts;
  40323. var stdFontMap = coreFonts.stdFontMap;
  40324. var isPDFFunction = coreFunction.isPDFFunction;
  40325. var PDFFunction = coreFunction.PDFFunction;
  40326. var Pattern = corePattern.Pattern;
  40327. var getTilingPatternIR = corePattern.getTilingPatternIR;
  40328. var CMapFactory = coreCMap.CMapFactory;
  40329. var IdentityCMap = coreCMap.IdentityCMap;
  40330. var Metrics = coreMetrics.Metrics;
  40331. var bidi = coreBidi.bidi;
  40332. var PartialEvaluator = (function PartialEvaluatorClosure() {
  40333. function PartialEvaluator(pdfManager, xref, handler, pageIndex,
  40334. uniquePrefix, idCounters, fontCache) {
  40335. this.pdfManager = pdfManager;
  40336. this.xref = xref;
  40337. this.handler = handler;
  40338. this.pageIndex = pageIndex;
  40339. this.uniquePrefix = uniquePrefix;
  40340. this.idCounters = idCounters;
  40341. this.fontCache = fontCache;
  40342. }
  40343. // Trying to minimize Date.now() usage and check every 100 time
  40344. var TIME_SLOT_DURATION_MS = 20;
  40345. var CHECK_TIME_EVERY = 100;
  40346. function TimeSlotManager() {
  40347. this.reset();
  40348. }
  40349. TimeSlotManager.prototype = {
  40350. check: function TimeSlotManager_check() {
  40351. if (++this.checked < CHECK_TIME_EVERY) {
  40352. return false;
  40353. }
  40354. this.checked = 0;
  40355. return this.endTime <= Date.now();
  40356. },
  40357. reset: function TimeSlotManager_reset() {
  40358. this.endTime = Date.now() + TIME_SLOT_DURATION_MS;
  40359. this.checked = 0;
  40360. }
  40361. };
  40362. var deferred = Promise.resolve();
  40363. var TILING_PATTERN = 1, SHADING_PATTERN = 2;
  40364. PartialEvaluator.prototype = {
  40365. hasBlendModes: function PartialEvaluator_hasBlendModes(resources) {
  40366. if (!isDict(resources)) {
  40367. return false;
  40368. }
  40369. var processed = Object.create(null);
  40370. if (resources.objId) {
  40371. processed[resources.objId] = true;
  40372. }
  40373. var nodes = [resources];
  40374. while (nodes.length) {
  40375. var key;
  40376. var node = nodes.shift();
  40377. // First check the current resources for blend modes.
  40378. var graphicStates = node.get('ExtGState');
  40379. if (isDict(graphicStates)) {
  40380. graphicStates = graphicStates.getAll();
  40381. for (key in graphicStates) {
  40382. var graphicState = graphicStates[key];
  40383. var bm = graphicState['BM'];
  40384. if (isName(bm) && bm.name !== 'Normal') {
  40385. return true;
  40386. }
  40387. }
  40388. }
  40389. // Descend into the XObjects to look for more resources and blend modes.
  40390. var xObjects = node.get('XObject');
  40391. if (!isDict(xObjects)) {
  40392. continue;
  40393. }
  40394. xObjects = xObjects.getAll();
  40395. for (key in xObjects) {
  40396. var xObject = xObjects[key];
  40397. if (!isStream(xObject)) {
  40398. continue;
  40399. }
  40400. if (xObject.dict.objId) {
  40401. if (processed[xObject.dict.objId]) {
  40402. // stream has objId and is processed already
  40403. continue;
  40404. }
  40405. processed[xObject.dict.objId] = true;
  40406. }
  40407. var xResources = xObject.dict.get('Resources');
  40408. // Checking objId to detect an infinite loop.
  40409. if (isDict(xResources) &&
  40410. (!xResources.objId || !processed[xResources.objId])) {
  40411. nodes.push(xResources);
  40412. if (xResources.objId) {
  40413. processed[xResources.objId] = true;
  40414. }
  40415. }
  40416. }
  40417. }
  40418. return false;
  40419. },
  40420. buildFormXObject: function PartialEvaluator_buildFormXObject(resources,
  40421. xobj, smask,
  40422. operatorList,
  40423. task,
  40424. initialState) {
  40425. var matrix = xobj.dict.getArray('Matrix');
  40426. var bbox = xobj.dict.getArray('BBox');
  40427. var group = xobj.dict.get('Group');
  40428. if (group) {
  40429. var groupOptions = {
  40430. matrix: matrix,
  40431. bbox: bbox,
  40432. smask: smask,
  40433. isolated: false,
  40434. knockout: false
  40435. };
  40436. var groupSubtype = group.get('S');
  40437. var colorSpace;
  40438. if (isName(groupSubtype) && groupSubtype.name === 'Transparency') {
  40439. groupOptions.isolated = (group.get('I') || false);
  40440. groupOptions.knockout = (group.get('K') || false);
  40441. colorSpace = (group.has('CS') ?
  40442. ColorSpace.parse(group.get('CS'), this.xref, resources) : null);
  40443. }
  40444. if (smask && smask.backdrop) {
  40445. colorSpace = colorSpace || ColorSpace.singletons.rgb;
  40446. smask.backdrop = colorSpace.getRgb(smask.backdrop, 0);
  40447. }
  40448. operatorList.addOp(OPS.beginGroup, [groupOptions]);
  40449. }
  40450. operatorList.addOp(OPS.paintFormXObjectBegin, [matrix, bbox]);
  40451. return this.getOperatorList(xobj, task,
  40452. (xobj.dict.get('Resources') || resources), operatorList, initialState).
  40453. then(function () {
  40454. operatorList.addOp(OPS.paintFormXObjectEnd, []);
  40455. if (group) {
  40456. operatorList.addOp(OPS.endGroup, [groupOptions]);
  40457. }
  40458. });
  40459. },
  40460. buildPaintImageXObject:
  40461. function PartialEvaluator_buildPaintImageXObject(resources, image,
  40462. inline, operatorList,
  40463. cacheKey, imageCache) {
  40464. var self = this;
  40465. var dict = image.dict;
  40466. var w = dict.get('Width', 'W');
  40467. var h = dict.get('Height', 'H');
  40468. if (!(w && isNum(w)) || !(h && isNum(h))) {
  40469. warn('Image dimensions are missing, or not numbers.');
  40470. return;
  40471. }
  40472. if (PDFJS.maxImageSize !== -1 && w * h > PDFJS.maxImageSize) {
  40473. warn('Image exceeded maximum allowed size and was removed.');
  40474. return;
  40475. }
  40476. var imageMask = (dict.get('ImageMask', 'IM') || false);
  40477. var imgData, args;
  40478. if (imageMask) {
  40479. // This depends on a tmpCanvas being filled with the
  40480. // current fillStyle, such that processing the pixel
  40481. // data can't be done here. Instead of creating a
  40482. // complete PDFImage, only read the information needed
  40483. // for later.
  40484. var width = dict.get('Width', 'W');
  40485. var height = dict.get('Height', 'H');
  40486. var bitStrideLength = (width + 7) >> 3;
  40487. var imgArray = image.getBytes(bitStrideLength * height);
  40488. var decode = dict.get('Decode', 'D');
  40489. var inverseDecode = (!!decode && decode[0] > 0);
  40490. imgData = PDFImage.createMask(imgArray, width, height,
  40491. image instanceof DecodeStream,
  40492. inverseDecode);
  40493. imgData.cached = true;
  40494. args = [imgData];
  40495. operatorList.addOp(OPS.paintImageMaskXObject, args);
  40496. if (cacheKey) {
  40497. imageCache[cacheKey] = {
  40498. fn: OPS.paintImageMaskXObject,
  40499. args: args
  40500. };
  40501. }
  40502. return;
  40503. }
  40504. var softMask = (dict.get('SMask', 'SM') || false);
  40505. var mask = (dict.get('Mask') || false);
  40506. var SMALL_IMAGE_DIMENSIONS = 200;
  40507. // Inlining small images into the queue as RGB data
  40508. if (inline && !softMask && !mask && !(image instanceof JpegStream) &&
  40509. (w + h) < SMALL_IMAGE_DIMENSIONS) {
  40510. var imageObj = new PDFImage(this.xref, resources, image,
  40511. inline, null, null);
  40512. // We force the use of RGBA_32BPP images here, because we can't handle
  40513. // any other kind.
  40514. imgData = imageObj.createImageData(/* forceRGBA = */ true);
  40515. operatorList.addOp(OPS.paintInlineImageXObject, [imgData]);
  40516. return;
  40517. }
  40518. // If there is no imageMask, create the PDFImage and a lot
  40519. // of image processing can be done here.
  40520. var uniquePrefix = (this.uniquePrefix || '');
  40521. var objId = 'img_' + uniquePrefix + (++this.idCounters.obj);
  40522. operatorList.addDependency(objId);
  40523. args = [objId, w, h];
  40524. if (!softMask && !mask && image instanceof JpegStream &&
  40525. image.isNativelySupported(this.xref, resources)) {
  40526. // These JPEGs don't need any more processing so we can just send it.
  40527. operatorList.addOp(OPS.paintJpegXObject, args);
  40528. this.handler.send('obj',
  40529. [objId, this.pageIndex, 'JpegStream', image.getIR()]);
  40530. return;
  40531. }
  40532. PDFImage.buildImage(self.handler, self.xref, resources, image, inline).
  40533. then(function(imageObj) {
  40534. var imgData = imageObj.createImageData(/* forceRGBA = */ false);
  40535. self.handler.send('obj', [objId, self.pageIndex, 'Image', imgData],
  40536. [imgData.data.buffer]);
  40537. }).then(undefined, function (reason) {
  40538. warn('Unable to decode image: ' + reason);
  40539. self.handler.send('obj', [objId, self.pageIndex, 'Image', null]);
  40540. });
  40541. operatorList.addOp(OPS.paintImageXObject, args);
  40542. if (cacheKey) {
  40543. imageCache[cacheKey] = {
  40544. fn: OPS.paintImageXObject,
  40545. args: args
  40546. };
  40547. }
  40548. },
  40549. handleSMask: function PartialEvaluator_handleSmask(smask, resources,
  40550. operatorList, task,
  40551. stateManager) {
  40552. var smaskContent = smask.get('G');
  40553. var smaskOptions = {
  40554. subtype: smask.get('S').name,
  40555. backdrop: smask.get('BC')
  40556. };
  40557. // The SMask might have a alpha/luminosity value transfer function --
  40558. // we will build a map of integer values in range 0..255 to be fast.
  40559. var transferObj = smask.get('TR');
  40560. if (isPDFFunction(transferObj)) {
  40561. var transferFn = PDFFunction.parse(this.xref, transferObj);
  40562. var transferMap = new Uint8Array(256);
  40563. var tmp = new Float32Array(1);
  40564. for (var i = 0; i < 255; i++) {
  40565. tmp[0] = i / 255;
  40566. transferFn(tmp, 0, tmp, 0);
  40567. transferMap[i] = (tmp[0] * 255) | 0;
  40568. }
  40569. smaskOptions.transferMap = transferMap;
  40570. }
  40571. return this.buildFormXObject(resources, smaskContent, smaskOptions,
  40572. operatorList, task, stateManager.state.clone());
  40573. },
  40574. handleTilingType:
  40575. function PartialEvaluator_handleTilingType(fn, args, resources,
  40576. pattern, patternDict,
  40577. operatorList, task) {
  40578. // Create an IR of the pattern code.
  40579. var tilingOpList = new OperatorList();
  40580. // Merge the available resources, to prevent issues when the patternDict
  40581. // is missing some /Resources entries (fixes issue6541.pdf).
  40582. var resourcesArray = [patternDict.get('Resources'), resources];
  40583. var patternResources = Dict.merge(this.xref, resourcesArray);
  40584. return this.getOperatorList(pattern, task, patternResources,
  40585. tilingOpList).then(function () {
  40586. // Add the dependencies to the parent operator list so they are
  40587. // resolved before sub operator list is executed synchronously.
  40588. operatorList.addDependencies(tilingOpList.dependencies);
  40589. operatorList.addOp(fn, getTilingPatternIR({
  40590. fnArray: tilingOpList.fnArray,
  40591. argsArray: tilingOpList.argsArray
  40592. }, patternDict, args));
  40593. });
  40594. },
  40595. handleSetFont:
  40596. function PartialEvaluator_handleSetFont(resources, fontArgs, fontRef,
  40597. operatorList, task, state) {
  40598. // TODO(mack): Not needed?
  40599. var fontName;
  40600. if (fontArgs) {
  40601. fontArgs = fontArgs.slice();
  40602. fontName = fontArgs[0].name;
  40603. }
  40604. var self = this;
  40605. return this.loadFont(fontName, fontRef, this.xref, resources).then(
  40606. function (translated) {
  40607. if (!translated.font.isType3Font) {
  40608. return translated;
  40609. }
  40610. return translated.loadType3Data(self, resources, operatorList, task).
  40611. then(function () {
  40612. return translated;
  40613. }, function (reason) {
  40614. // Error in the font data -- sending unsupported feature notification.
  40615. self.handler.send('UnsupportedFeature',
  40616. {featureId: UNSUPPORTED_FEATURES.font});
  40617. return new TranslatedFont('g_font_error',
  40618. new ErrorFont('Type3 font load error: ' + reason), translated.font);
  40619. });
  40620. }).then(function (translated) {
  40621. state.font = translated.font;
  40622. translated.send(self.handler);
  40623. return translated.loadedName;
  40624. });
  40625. },
  40626. handleText: function PartialEvaluator_handleText(chars, state) {
  40627. var font = state.font;
  40628. var glyphs = font.charsToGlyphs(chars);
  40629. var isAddToPathSet = !!(state.textRenderingMode &
  40630. TextRenderingMode.ADD_TO_PATH_FLAG);
  40631. if (font.data && (isAddToPathSet || PDFJS.disableFontFace)) {
  40632. var buildPath = function (fontChar) {
  40633. if (!font.renderer.hasBuiltPath(fontChar)) {
  40634. var path = font.renderer.getPathJs(fontChar);
  40635. this.handler.send('commonobj', [
  40636. font.loadedName + '_path_' + fontChar,
  40637. 'FontPath',
  40638. path
  40639. ]);
  40640. }
  40641. }.bind(this);
  40642. for (var i = 0, ii = glyphs.length; i < ii; i++) {
  40643. var glyph = glyphs[i];
  40644. buildPath(glyph.fontChar);
  40645. // If the glyph has an accent we need to build a path for its
  40646. // fontChar too, otherwise CanvasGraphics_paintChar will fail.
  40647. var accent = glyph.accent;
  40648. if (accent && accent.fontChar) {
  40649. buildPath(accent.fontChar);
  40650. }
  40651. }
  40652. }
  40653. return glyphs;
  40654. },
  40655. setGState: function PartialEvaluator_setGState(resources, gState,
  40656. operatorList, task,
  40657. xref, stateManager) {
  40658. // This array holds the converted/processed state data.
  40659. var gStateObj = [];
  40660. var gStateMap = gState.map;
  40661. var self = this;
  40662. var promise = Promise.resolve();
  40663. for (var key in gStateMap) {
  40664. var value = gStateMap[key];
  40665. switch (key) {
  40666. case 'Type':
  40667. break;
  40668. case 'LW':
  40669. case 'LC':
  40670. case 'LJ':
  40671. case 'ML':
  40672. case 'D':
  40673. case 'RI':
  40674. case 'FL':
  40675. case 'CA':
  40676. case 'ca':
  40677. gStateObj.push([key, value]);
  40678. break;
  40679. case 'Font':
  40680. promise = promise.then(function () {
  40681. return self.handleSetFont(resources, null, value[0], operatorList,
  40682. task, stateManager.state).
  40683. then(function (loadedName) {
  40684. operatorList.addDependency(loadedName);
  40685. gStateObj.push([key, [loadedName, value[1]]]);
  40686. });
  40687. });
  40688. break;
  40689. case 'BM':
  40690. gStateObj.push([key, value]);
  40691. break;
  40692. case 'SMask':
  40693. if (isName(value) && value.name === 'None') {
  40694. gStateObj.push([key, false]);
  40695. break;
  40696. }
  40697. var dict = xref.fetchIfRef(value);
  40698. if (isDict(dict)) {
  40699. promise = promise.then(function () {
  40700. return self.handleSMask(dict, resources, operatorList,
  40701. task, stateManager);
  40702. });
  40703. gStateObj.push([key, true]);
  40704. } else {
  40705. warn('Unsupported SMask type');
  40706. }
  40707. break;
  40708. // Only generate info log messages for the following since
  40709. // they are unlikely to have a big impact on the rendering.
  40710. case 'OP':
  40711. case 'op':
  40712. case 'OPM':
  40713. case 'BG':
  40714. case 'BG2':
  40715. case 'UCR':
  40716. case 'UCR2':
  40717. case 'TR':
  40718. case 'TR2':
  40719. case 'HT':
  40720. case 'SM':
  40721. case 'SA':
  40722. case 'AIS':
  40723. case 'TK':
  40724. // TODO implement these operators.
  40725. info('graphic state operator ' + key);
  40726. break;
  40727. default:
  40728. info('Unknown graphic state operator ' + key);
  40729. break;
  40730. }
  40731. }
  40732. return promise.then(function () {
  40733. if (gStateObj.length >= 0) {
  40734. operatorList.addOp(OPS.setGState, [gStateObj]);
  40735. }
  40736. });
  40737. },
  40738. loadFont: function PartialEvaluator_loadFont(fontName, font, xref,
  40739. resources) {
  40740. function errorFont() {
  40741. return Promise.resolve(new TranslatedFont('g_font_error',
  40742. new ErrorFont('Font ' + fontName + ' is not available'), font));
  40743. }
  40744. var fontRef;
  40745. if (font) { // Loading by ref.
  40746. assert(isRef(font));
  40747. fontRef = font;
  40748. } else { // Loading by name.
  40749. var fontRes = resources.get('Font');
  40750. if (fontRes) {
  40751. fontRef = fontRes.getRaw(fontName);
  40752. } else {
  40753. warn('fontRes not available');
  40754. return errorFont();
  40755. }
  40756. }
  40757. if (!fontRef) {
  40758. warn('fontRef not available');
  40759. return errorFont();
  40760. }
  40761. if (this.fontCache.has(fontRef)) {
  40762. return this.fontCache.get(fontRef);
  40763. }
  40764. font = xref.fetchIfRef(fontRef);
  40765. if (!isDict(font)) {
  40766. return errorFont();
  40767. }
  40768. // We are holding font.translated references just for fontRef that are not
  40769. // dictionaries (Dict). See explanation below.
  40770. if (font.translated) {
  40771. return font.translated;
  40772. }
  40773. var fontCapability = createPromiseCapability();
  40774. var preEvaluatedFont = this.preEvaluateFont(font, xref);
  40775. var descriptor = preEvaluatedFont.descriptor;
  40776. var fontID = fontRef.num + '_' + fontRef.gen;
  40777. if (isDict(descriptor)) {
  40778. if (!descriptor.fontAliases) {
  40779. descriptor.fontAliases = Object.create(null);
  40780. }
  40781. var fontAliases = descriptor.fontAliases;
  40782. var hash = preEvaluatedFont.hash;
  40783. if (fontAliases[hash]) {
  40784. var aliasFontRef = fontAliases[hash].aliasRef;
  40785. if (aliasFontRef && this.fontCache.has(aliasFontRef)) {
  40786. this.fontCache.putAlias(fontRef, aliasFontRef);
  40787. return this.fontCache.get(fontRef);
  40788. }
  40789. }
  40790. if (!fontAliases[hash]) {
  40791. fontAliases[hash] = {
  40792. fontID: Font.getFontID()
  40793. };
  40794. }
  40795. fontAliases[hash].aliasRef = fontRef;
  40796. fontID = fontAliases[hash].fontID;
  40797. }
  40798. // Workaround for bad PDF generators that don't reference fonts
  40799. // properly, i.e. by not using an object identifier.
  40800. // Check if the fontRef is a Dict (as opposed to a standard object),
  40801. // in which case we don't cache the font and instead reference it by
  40802. // fontName in font.loadedName below.
  40803. var fontRefIsDict = isDict(fontRef);
  40804. if (!fontRefIsDict) {
  40805. this.fontCache.put(fontRef, fontCapability.promise);
  40806. }
  40807. // Keep track of each font we translated so the caller can
  40808. // load them asynchronously before calling display on a page.
  40809. font.loadedName = 'g_' + this.pdfManager.docId + '_f' + (fontRefIsDict ?
  40810. fontName.replace(/\W/g, '') : fontID);
  40811. font.translated = fontCapability.promise;
  40812. // TODO move promises into translate font
  40813. var translatedPromise;
  40814. try {
  40815. translatedPromise = Promise.resolve(
  40816. this.translateFont(preEvaluatedFont, xref));
  40817. } catch (e) {
  40818. translatedPromise = Promise.reject(e);
  40819. }
  40820. var self = this;
  40821. translatedPromise.then(function (translatedFont) {
  40822. if (translatedFont.fontType !== undefined) {
  40823. var xrefFontStats = xref.stats.fontTypes;
  40824. xrefFontStats[translatedFont.fontType] = true;
  40825. }
  40826. fontCapability.resolve(new TranslatedFont(font.loadedName,
  40827. translatedFont, font));
  40828. }, function (reason) {
  40829. // TODO fontCapability.reject?
  40830. // Error in the font data -- sending unsupported feature notification.
  40831. self.handler.send('UnsupportedFeature',
  40832. {featureId: UNSUPPORTED_FEATURES.font});
  40833. try {
  40834. // error, but it's still nice to have font type reported
  40835. var descriptor = preEvaluatedFont.descriptor;
  40836. var fontFile3 = descriptor && descriptor.get('FontFile3');
  40837. var subtype = fontFile3 && fontFile3.get('Subtype');
  40838. var fontType = getFontType(preEvaluatedFont.type,
  40839. subtype && subtype.name);
  40840. var xrefFontStats = xref.stats.fontTypes;
  40841. xrefFontStats[fontType] = true;
  40842. } catch (ex) { }
  40843. fontCapability.resolve(new TranslatedFont(font.loadedName,
  40844. new ErrorFont(reason instanceof Error ? reason.message : reason),
  40845. font));
  40846. });
  40847. return fontCapability.promise;
  40848. },
  40849. buildPath: function PartialEvaluator_buildPath(operatorList, fn, args) {
  40850. var lastIndex = operatorList.length - 1;
  40851. if (!args) {
  40852. args = [];
  40853. }
  40854. if (lastIndex < 0 ||
  40855. operatorList.fnArray[lastIndex] !== OPS.constructPath) {
  40856. operatorList.addOp(OPS.constructPath, [[fn], args]);
  40857. } else {
  40858. var opArgs = operatorList.argsArray[lastIndex];
  40859. opArgs[0].push(fn);
  40860. Array.prototype.push.apply(opArgs[1], args);
  40861. }
  40862. },
  40863. handleColorN: function PartialEvaluator_handleColorN(operatorList, fn, args,
  40864. cs, patterns, resources, task, xref) {
  40865. // compile tiling patterns
  40866. var patternName = args[args.length - 1];
  40867. // SCN/scn applies patterns along with normal colors
  40868. var pattern;
  40869. if (isName(patternName) &&
  40870. (pattern = patterns.get(patternName.name))) {
  40871. var dict = (isStream(pattern) ? pattern.dict : pattern);
  40872. var typeNum = dict.get('PatternType');
  40873. if (typeNum === TILING_PATTERN) {
  40874. var color = cs.base ? cs.base.getRgb(args, 0) : null;
  40875. return this.handleTilingType(fn, color, resources, pattern,
  40876. dict, operatorList, task);
  40877. } else if (typeNum === SHADING_PATTERN) {
  40878. var shading = dict.get('Shading');
  40879. var matrix = dict.get('Matrix');
  40880. pattern = Pattern.parseShading(shading, matrix, xref, resources,
  40881. this.handler);
  40882. operatorList.addOp(fn, pattern.getIR());
  40883. return Promise.resolve();
  40884. } else {
  40885. return Promise.reject('Unknown PatternType: ' + typeNum);
  40886. }
  40887. }
  40888. // TODO shall we fail here?
  40889. operatorList.addOp(fn, args);
  40890. return Promise.resolve();
  40891. },
  40892. getOperatorList: function PartialEvaluator_getOperatorList(stream,
  40893. task,
  40894. resources,
  40895. operatorList,
  40896. initialState) {
  40897. var self = this;
  40898. var xref = this.xref;
  40899. var imageCache = {};
  40900. assert(operatorList);
  40901. resources = (resources || Dict.empty);
  40902. var xobjs = (resources.get('XObject') || Dict.empty);
  40903. var patterns = (resources.get('Pattern') || Dict.empty);
  40904. var stateManager = new StateManager(initialState || new EvalState());
  40905. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  40906. var timeSlotManager = new TimeSlotManager();
  40907. return new Promise(function next(resolve, reject) {
  40908. task.ensureNotTerminated();
  40909. timeSlotManager.reset();
  40910. var stop, operation = {}, i, ii, cs;
  40911. while (!(stop = timeSlotManager.check())) {
  40912. // The arguments parsed by read() are used beyond this loop, so we
  40913. // cannot reuse the same array on each iteration. Therefore we pass
  40914. // in |null| as the initial value (see the comment on
  40915. // EvaluatorPreprocessor_read() for why).
  40916. operation.args = null;
  40917. if (!(preprocessor.read(operation))) {
  40918. break;
  40919. }
  40920. var args = operation.args;
  40921. var fn = operation.fn;
  40922. switch (fn | 0) {
  40923. case OPS.paintXObject:
  40924. if (args[0].code) {
  40925. break;
  40926. }
  40927. // eagerly compile XForm objects
  40928. var name = args[0].name;
  40929. if (!name) {
  40930. warn('XObject must be referred to by name.');
  40931. continue;
  40932. }
  40933. if (imageCache[name] !== undefined) {
  40934. operatorList.addOp(imageCache[name].fn, imageCache[name].args);
  40935. args = null;
  40936. continue;
  40937. }
  40938. var xobj = xobjs.get(name);
  40939. if (xobj) {
  40940. assert(isStream(xobj), 'XObject should be a stream');
  40941. var type = xobj.dict.get('Subtype');
  40942. assert(isName(type),
  40943. 'XObject should have a Name subtype');
  40944. if (type.name === 'Form') {
  40945. stateManager.save();
  40946. return self.buildFormXObject(resources, xobj, null,
  40947. operatorList, task,
  40948. stateManager.state.clone()).
  40949. then(function () {
  40950. stateManager.restore();
  40951. next(resolve, reject);
  40952. }, reject);
  40953. } else if (type.name === 'Image') {
  40954. self.buildPaintImageXObject(resources, xobj, false,
  40955. operatorList, name, imageCache);
  40956. args = null;
  40957. continue;
  40958. } else if (type.name === 'PS') {
  40959. // PostScript XObjects are unused when viewing documents.
  40960. // See section 4.7.1 of Adobe's PDF reference.
  40961. info('Ignored XObject subtype PS');
  40962. continue;
  40963. } else {
  40964. error('Unhandled XObject subtype ' + type.name);
  40965. }
  40966. }
  40967. break;
  40968. case OPS.setFont:
  40969. var fontSize = args[1];
  40970. // eagerly collect all fonts
  40971. return self.handleSetFont(resources, args, null, operatorList,
  40972. task, stateManager.state).
  40973. then(function (loadedName) {
  40974. operatorList.addDependency(loadedName);
  40975. operatorList.addOp(OPS.setFont, [loadedName, fontSize]);
  40976. next(resolve, reject);
  40977. }, reject);
  40978. case OPS.endInlineImage:
  40979. var cacheKey = args[0].cacheKey;
  40980. if (cacheKey) {
  40981. var cacheEntry = imageCache[cacheKey];
  40982. if (cacheEntry !== undefined) {
  40983. operatorList.addOp(cacheEntry.fn, cacheEntry.args);
  40984. args = null;
  40985. continue;
  40986. }
  40987. }
  40988. self.buildPaintImageXObject(resources, args[0], true,
  40989. operatorList, cacheKey, imageCache);
  40990. args = null;
  40991. continue;
  40992. case OPS.showText:
  40993. args[0] = self.handleText(args[0], stateManager.state);
  40994. break;
  40995. case OPS.showSpacedText:
  40996. var arr = args[0];
  40997. var combinedGlyphs = [];
  40998. var arrLength = arr.length;
  40999. var state = stateManager.state;
  41000. for (i = 0; i < arrLength; ++i) {
  41001. var arrItem = arr[i];
  41002. if (isString(arrItem)) {
  41003. Array.prototype.push.apply(combinedGlyphs,
  41004. self.handleText(arrItem, state));
  41005. } else if (isNum(arrItem)) {
  41006. combinedGlyphs.push(arrItem);
  41007. }
  41008. }
  41009. args[0] = combinedGlyphs;
  41010. fn = OPS.showText;
  41011. break;
  41012. case OPS.nextLineShowText:
  41013. operatorList.addOp(OPS.nextLine);
  41014. args[0] = self.handleText(args[0], stateManager.state);
  41015. fn = OPS.showText;
  41016. break;
  41017. case OPS.nextLineSetSpacingShowText:
  41018. operatorList.addOp(OPS.nextLine);
  41019. operatorList.addOp(OPS.setWordSpacing, [args.shift()]);
  41020. operatorList.addOp(OPS.setCharSpacing, [args.shift()]);
  41021. args[0] = self.handleText(args[0], stateManager.state);
  41022. fn = OPS.showText;
  41023. break;
  41024. case OPS.setTextRenderingMode:
  41025. stateManager.state.textRenderingMode = args[0];
  41026. break;
  41027. case OPS.setFillColorSpace:
  41028. stateManager.state.fillColorSpace =
  41029. ColorSpace.parse(args[0], xref, resources);
  41030. continue;
  41031. case OPS.setStrokeColorSpace:
  41032. stateManager.state.strokeColorSpace =
  41033. ColorSpace.parse(args[0], xref, resources);
  41034. continue;
  41035. case OPS.setFillColor:
  41036. cs = stateManager.state.fillColorSpace;
  41037. args = cs.getRgb(args, 0);
  41038. fn = OPS.setFillRGBColor;
  41039. break;
  41040. case OPS.setStrokeColor:
  41041. cs = stateManager.state.strokeColorSpace;
  41042. args = cs.getRgb(args, 0);
  41043. fn = OPS.setStrokeRGBColor;
  41044. break;
  41045. case OPS.setFillGray:
  41046. stateManager.state.fillColorSpace = ColorSpace.singletons.gray;
  41047. args = ColorSpace.singletons.gray.getRgb(args, 0);
  41048. fn = OPS.setFillRGBColor;
  41049. break;
  41050. case OPS.setStrokeGray:
  41051. stateManager.state.strokeColorSpace = ColorSpace.singletons.gray;
  41052. args = ColorSpace.singletons.gray.getRgb(args, 0);
  41053. fn = OPS.setStrokeRGBColor;
  41054. break;
  41055. case OPS.setFillCMYKColor:
  41056. stateManager.state.fillColorSpace = ColorSpace.singletons.cmyk;
  41057. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  41058. fn = OPS.setFillRGBColor;
  41059. break;
  41060. case OPS.setStrokeCMYKColor:
  41061. stateManager.state.strokeColorSpace = ColorSpace.singletons.cmyk;
  41062. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  41063. fn = OPS.setStrokeRGBColor;
  41064. break;
  41065. case OPS.setFillRGBColor:
  41066. stateManager.state.fillColorSpace = ColorSpace.singletons.rgb;
  41067. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  41068. break;
  41069. case OPS.setStrokeRGBColor:
  41070. stateManager.state.strokeColorSpace = ColorSpace.singletons.rgb;
  41071. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  41072. break;
  41073. case OPS.setFillColorN:
  41074. cs = stateManager.state.fillColorSpace;
  41075. if (cs.name === 'Pattern') {
  41076. return self.handleColorN(operatorList, OPS.setFillColorN,
  41077. args, cs, patterns, resources, task, xref).then(function() {
  41078. next(resolve, reject);
  41079. }, reject);
  41080. }
  41081. args = cs.getRgb(args, 0);
  41082. fn = OPS.setFillRGBColor;
  41083. break;
  41084. case OPS.setStrokeColorN:
  41085. cs = stateManager.state.strokeColorSpace;
  41086. if (cs.name === 'Pattern') {
  41087. return self.handleColorN(operatorList, OPS.setStrokeColorN,
  41088. args, cs, patterns, resources, task, xref).then(function() {
  41089. next(resolve, reject);
  41090. }, reject);
  41091. }
  41092. args = cs.getRgb(args, 0);
  41093. fn = OPS.setStrokeRGBColor;
  41094. break;
  41095. case OPS.shadingFill:
  41096. var shadingRes = resources.get('Shading');
  41097. if (!shadingRes) {
  41098. error('No shading resource found');
  41099. }
  41100. var shading = shadingRes.get(args[0].name);
  41101. if (!shading) {
  41102. error('No shading object found');
  41103. }
  41104. var shadingFill = Pattern.parseShading(shading, null, xref,
  41105. resources, self.handler);
  41106. var patternIR = shadingFill.getIR();
  41107. args = [patternIR];
  41108. fn = OPS.shadingFill;
  41109. break;
  41110. case OPS.setGState:
  41111. var dictName = args[0];
  41112. var extGState = resources.get('ExtGState');
  41113. if (!isDict(extGState) || !extGState.has(dictName.name)) {
  41114. break;
  41115. }
  41116. var gState = extGState.get(dictName.name);
  41117. return self.setGState(resources, gState, operatorList, task,
  41118. xref, stateManager).then(function() {
  41119. next(resolve, reject);
  41120. }, reject);
  41121. case OPS.moveTo:
  41122. case OPS.lineTo:
  41123. case OPS.curveTo:
  41124. case OPS.curveTo2:
  41125. case OPS.curveTo3:
  41126. case OPS.closePath:
  41127. self.buildPath(operatorList, fn, args);
  41128. continue;
  41129. case OPS.rectangle:
  41130. self.buildPath(operatorList, fn, args);
  41131. continue;
  41132. case OPS.markPoint:
  41133. case OPS.markPointProps:
  41134. case OPS.beginMarkedContent:
  41135. case OPS.beginMarkedContentProps:
  41136. case OPS.endMarkedContent:
  41137. case OPS.beginCompat:
  41138. case OPS.endCompat:
  41139. // Ignore operators where the corresponding handlers are known to
  41140. // be no-op in CanvasGraphics (display/canvas.js). This prevents
  41141. // serialization errors and is also a bit more efficient.
  41142. // We could also try to serialize all objects in a general way,
  41143. // e.g. as done in https://github.com/mozilla/pdf.js/pull/6266,
  41144. // but doing so is meaningless without knowing the semantics.
  41145. continue;
  41146. default:
  41147. // Note: Let's hope that the ignored operator does not have any
  41148. // non-serializable arguments, otherwise postMessage will throw
  41149. // "An object could not be cloned.".
  41150. }
  41151. operatorList.addOp(fn, args);
  41152. }
  41153. if (stop) {
  41154. deferred.then(function () {
  41155. next(resolve, reject);
  41156. }, reject);
  41157. return;
  41158. }
  41159. // Some PDFs don't close all restores inside object/form.
  41160. // Closing those for them.
  41161. for (i = 0, ii = preprocessor.savedStatesDepth; i < ii; i++) {
  41162. operatorList.addOp(OPS.restore, []);
  41163. }
  41164. resolve();
  41165. });
  41166. },
  41167. getTextContent:
  41168. function PartialEvaluator_getTextContent(stream, task, resources,
  41169. stateManager,
  41170. normalizeWhitespace) {
  41171. stateManager = (stateManager || new StateManager(new TextState()));
  41172. var WhitespaceRegexp = /\s/g;
  41173. var textContent = {
  41174. items: [],
  41175. styles: Object.create(null)
  41176. };
  41177. var textContentItem = {
  41178. initialized: false,
  41179. str: [],
  41180. width: 0,
  41181. height: 0,
  41182. vertical: false,
  41183. lastAdvanceWidth: 0,
  41184. lastAdvanceHeight: 0,
  41185. textAdvanceScale: 0,
  41186. spaceWidth: 0,
  41187. fakeSpaceMin: Infinity,
  41188. fakeMultiSpaceMin: Infinity,
  41189. fakeMultiSpaceMax: -0,
  41190. textRunBreakAllowed: false,
  41191. transform: null,
  41192. fontName: null
  41193. };
  41194. var SPACE_FACTOR = 0.3;
  41195. var MULTI_SPACE_FACTOR = 1.5;
  41196. var MULTI_SPACE_FACTOR_MAX = 4;
  41197. var self = this;
  41198. var xref = this.xref;
  41199. resources = (xref.fetchIfRef(resources) || Dict.empty);
  41200. // The xobj is parsed iff it's needed, e.g. if there is a `DO` cmd.
  41201. var xobjs = null;
  41202. var xobjsCache = {};
  41203. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  41204. var textState;
  41205. function ensureTextContentItem() {
  41206. if (textContentItem.initialized) {
  41207. return textContentItem;
  41208. }
  41209. var font = textState.font;
  41210. if (!(font.loadedName in textContent.styles)) {
  41211. textContent.styles[font.loadedName] = {
  41212. fontFamily: font.fallbackName,
  41213. ascent: font.ascent,
  41214. descent: font.descent,
  41215. vertical: font.vertical
  41216. };
  41217. }
  41218. textContentItem.fontName = font.loadedName;
  41219. // 9.4.4 Text Space Details
  41220. var tsm = [textState.fontSize * textState.textHScale, 0,
  41221. 0, textState.fontSize,
  41222. 0, textState.textRise];
  41223. if (font.isType3Font &&
  41224. textState.fontMatrix !== FONT_IDENTITY_MATRIX &&
  41225. textState.fontSize === 1) {
  41226. var glyphHeight = font.bbox[3] - font.bbox[1];
  41227. if (glyphHeight > 0) {
  41228. glyphHeight = glyphHeight * textState.fontMatrix[3];
  41229. tsm[3] *= glyphHeight;
  41230. }
  41231. }
  41232. var trm = Util.transform(textState.ctm,
  41233. Util.transform(textState.textMatrix, tsm));
  41234. textContentItem.transform = trm;
  41235. if (!font.vertical) {
  41236. textContentItem.width = 0;
  41237. textContentItem.height = Math.sqrt(trm[2] * trm[2] + trm[3] * trm[3]);
  41238. textContentItem.vertical = false;
  41239. } else {
  41240. textContentItem.width = Math.sqrt(trm[0] * trm[0] + trm[1] * trm[1]);
  41241. textContentItem.height = 0;
  41242. textContentItem.vertical = true;
  41243. }
  41244. var a = textState.textLineMatrix[0];
  41245. var b = textState.textLineMatrix[1];
  41246. var scaleLineX = Math.sqrt(a * a + b * b);
  41247. a = textState.ctm[0];
  41248. b = textState.ctm[1];
  41249. var scaleCtmX = Math.sqrt(a * a + b * b);
  41250. textContentItem.textAdvanceScale = scaleCtmX * scaleLineX;
  41251. textContentItem.lastAdvanceWidth = 0;
  41252. textContentItem.lastAdvanceHeight = 0;
  41253. var spaceWidth = font.spaceWidth / 1000 * textState.fontSize;
  41254. if (spaceWidth) {
  41255. textContentItem.spaceWidth = spaceWidth;
  41256. textContentItem.fakeSpaceMin = spaceWidth * SPACE_FACTOR;
  41257. textContentItem.fakeMultiSpaceMin = spaceWidth * MULTI_SPACE_FACTOR;
  41258. textContentItem.fakeMultiSpaceMax =
  41259. spaceWidth * MULTI_SPACE_FACTOR_MAX;
  41260. // It's okay for monospace fonts to fake as much space as needed.
  41261. textContentItem.textRunBreakAllowed = !font.isMonospace;
  41262. } else {
  41263. textContentItem.spaceWidth = 0;
  41264. textContentItem.fakeSpaceMin = Infinity;
  41265. textContentItem.fakeMultiSpaceMin = Infinity;
  41266. textContentItem.fakeMultiSpaceMax = 0;
  41267. textContentItem.textRunBreakAllowed = false;
  41268. }
  41269. textContentItem.initialized = true;
  41270. return textContentItem;
  41271. }
  41272. function replaceWhitespace(str) {
  41273. // Replaces all whitespaces with standard spaces (0x20), to avoid
  41274. // alignment issues between the textLayer and the canvas if the text
  41275. // contains e.g. tabs (fixes issue6612.pdf).
  41276. var i = 0, ii = str.length, code;
  41277. while (i < ii && (code = str.charCodeAt(i)) >= 0x20 && code <= 0x7F) {
  41278. i++;
  41279. }
  41280. return (i < ii ? str.replace(WhitespaceRegexp, ' ') : str);
  41281. }
  41282. function runBidiTransform(textChunk) {
  41283. var str = textChunk.str.join('');
  41284. var bidiResult = PDFJS.bidi(str, -1, textChunk.vertical);
  41285. return {
  41286. str: (normalizeWhitespace ? replaceWhitespace(bidiResult.str) :
  41287. bidiResult.str),
  41288. dir: bidiResult.dir,
  41289. width: textChunk.width,
  41290. height: textChunk.height,
  41291. transform: textChunk.transform,
  41292. fontName: textChunk.fontName
  41293. };
  41294. }
  41295. function handleSetFont(fontName, fontRef) {
  41296. return self.loadFont(fontName, fontRef, xref, resources).
  41297. then(function (translated) {
  41298. textState.font = translated.font;
  41299. textState.fontMatrix = translated.font.fontMatrix ||
  41300. FONT_IDENTITY_MATRIX;
  41301. });
  41302. }
  41303. function buildTextContentItem(chars) {
  41304. var font = textState.font;
  41305. var textChunk = ensureTextContentItem();
  41306. var width = 0;
  41307. var height = 0;
  41308. var glyphs = font.charsToGlyphs(chars);
  41309. var defaultVMetrics = font.defaultVMetrics;
  41310. for (var i = 0; i < glyphs.length; i++) {
  41311. var glyph = glyphs[i];
  41312. var vMetricX = null;
  41313. var vMetricY = null;
  41314. var glyphWidth = null;
  41315. if (font.vertical) {
  41316. if (glyph.vmetric) {
  41317. glyphWidth = glyph.vmetric[0];
  41318. vMetricX = glyph.vmetric[1];
  41319. vMetricY = glyph.vmetric[2];
  41320. } else {
  41321. glyphWidth = glyph.width;
  41322. vMetricX = glyph.width * 0.5;
  41323. vMetricY = defaultVMetrics[2];
  41324. }
  41325. } else {
  41326. glyphWidth = glyph.width;
  41327. }
  41328. var glyphUnicode = glyph.unicode;
  41329. if (NormalizedUnicodes[glyphUnicode] !== undefined) {
  41330. glyphUnicode = NormalizedUnicodes[glyphUnicode];
  41331. }
  41332. glyphUnicode = reverseIfRtl(glyphUnicode);
  41333. // The following will calculate the x and y of the individual glyphs.
  41334. // if (font.vertical) {
  41335. // tsm[4] -= vMetricX * Math.abs(textState.fontSize) *
  41336. // textState.fontMatrix[0];
  41337. // tsm[5] -= vMetricY * textState.fontSize *
  41338. // textState.fontMatrix[0];
  41339. // }
  41340. // var trm = Util.transform(textState.textMatrix, tsm);
  41341. // var pt = Util.applyTransform([trm[4], trm[5]], textState.ctm);
  41342. // var x = pt[0];
  41343. // var y = pt[1];
  41344. var charSpacing = textState.charSpacing;
  41345. if (glyph.isSpace) {
  41346. var wordSpacing = textState.wordSpacing;
  41347. charSpacing += wordSpacing;
  41348. if (wordSpacing > 0) {
  41349. addFakeSpaces(wordSpacing, textChunk.str);
  41350. }
  41351. }
  41352. var tx = 0;
  41353. var ty = 0;
  41354. if (!font.vertical) {
  41355. var w0 = glyphWidth * textState.fontMatrix[0];
  41356. tx = (w0 * textState.fontSize + charSpacing) *
  41357. textState.textHScale;
  41358. width += tx;
  41359. } else {
  41360. var w1 = glyphWidth * textState.fontMatrix[0];
  41361. ty = w1 * textState.fontSize + charSpacing;
  41362. height += ty;
  41363. }
  41364. textState.translateTextMatrix(tx, ty);
  41365. textChunk.str.push(glyphUnicode);
  41366. }
  41367. if (!font.vertical) {
  41368. textChunk.lastAdvanceWidth = width;
  41369. textChunk.width += width * textChunk.textAdvanceScale;
  41370. } else {
  41371. textChunk.lastAdvanceHeight = height;
  41372. textChunk.height += Math.abs(height * textChunk.textAdvanceScale);
  41373. }
  41374. return textChunk;
  41375. }
  41376. function addFakeSpaces(width, strBuf) {
  41377. if (width < textContentItem.fakeSpaceMin) {
  41378. return;
  41379. }
  41380. if (width < textContentItem.fakeMultiSpaceMin) {
  41381. strBuf.push(' ');
  41382. return;
  41383. }
  41384. var fakeSpaces = Math.round(width / textContentItem.spaceWidth);
  41385. while (fakeSpaces-- > 0) {
  41386. strBuf.push(' ');
  41387. }
  41388. }
  41389. function flushTextContentItem() {
  41390. if (!textContentItem.initialized) {
  41391. return;
  41392. }
  41393. textContent.items.push(runBidiTransform(textContentItem));
  41394. textContentItem.initialized = false;
  41395. textContentItem.str.length = 0;
  41396. }
  41397. var timeSlotManager = new TimeSlotManager();
  41398. return new Promise(function next(resolve, reject) {
  41399. task.ensureNotTerminated();
  41400. timeSlotManager.reset();
  41401. var stop, operation = {}, args = [];
  41402. while (!(stop = timeSlotManager.check())) {
  41403. // The arguments parsed by read() are not used beyond this loop, so
  41404. // we can reuse the same array on every iteration, thus avoiding
  41405. // unnecessary allocations.
  41406. args.length = 0;
  41407. operation.args = args;
  41408. if (!(preprocessor.read(operation))) {
  41409. break;
  41410. }
  41411. textState = stateManager.state;
  41412. var fn = operation.fn;
  41413. args = operation.args;
  41414. var advance;
  41415. switch (fn | 0) {
  41416. case OPS.setFont:
  41417. flushTextContentItem();
  41418. textState.fontSize = args[1];
  41419. return handleSetFont(args[0].name).then(function() {
  41420. next(resolve, reject);
  41421. }, reject);
  41422. case OPS.setTextRise:
  41423. flushTextContentItem();
  41424. textState.textRise = args[0];
  41425. break;
  41426. case OPS.setHScale:
  41427. flushTextContentItem();
  41428. textState.textHScale = args[0] / 100;
  41429. break;
  41430. case OPS.setLeading:
  41431. flushTextContentItem();
  41432. textState.leading = args[0];
  41433. break;
  41434. case OPS.moveText:
  41435. // Optimization to treat same line movement as advance
  41436. var isSameTextLine = !textState.font ? false :
  41437. ((textState.font.vertical ? args[0] : args[1]) === 0);
  41438. advance = args[0] - args[1];
  41439. if (isSameTextLine && textContentItem.initialized &&
  41440. advance > 0 &&
  41441. advance <= textContentItem.fakeMultiSpaceMax) {
  41442. textState.translateTextLineMatrix(args[0], args[1]);
  41443. textContentItem.width +=
  41444. (args[0] - textContentItem.lastAdvanceWidth);
  41445. textContentItem.height +=
  41446. (args[1] - textContentItem.lastAdvanceHeight);
  41447. var diff = (args[0] - textContentItem.lastAdvanceWidth) -
  41448. (args[1] - textContentItem.lastAdvanceHeight);
  41449. addFakeSpaces(diff, textContentItem.str);
  41450. break;
  41451. }
  41452. flushTextContentItem();
  41453. textState.translateTextLineMatrix(args[0], args[1]);
  41454. textState.textMatrix = textState.textLineMatrix.slice();
  41455. break;
  41456. case OPS.setLeadingMoveText:
  41457. flushTextContentItem();
  41458. textState.leading = -args[1];
  41459. textState.translateTextLineMatrix(args[0], args[1]);
  41460. textState.textMatrix = textState.textLineMatrix.slice();
  41461. break;
  41462. case OPS.nextLine:
  41463. flushTextContentItem();
  41464. textState.carriageReturn();
  41465. break;
  41466. case OPS.setTextMatrix:
  41467. flushTextContentItem();
  41468. textState.setTextMatrix(args[0], args[1], args[2], args[3],
  41469. args[4], args[5]);
  41470. textState.setTextLineMatrix(args[0], args[1], args[2], args[3],
  41471. args[4], args[5]);
  41472. break;
  41473. case OPS.setCharSpacing:
  41474. textState.charSpacing = args[0];
  41475. break;
  41476. case OPS.setWordSpacing:
  41477. textState.wordSpacing = args[0];
  41478. break;
  41479. case OPS.beginText:
  41480. flushTextContentItem();
  41481. textState.textMatrix = IDENTITY_MATRIX.slice();
  41482. textState.textLineMatrix = IDENTITY_MATRIX.slice();
  41483. break;
  41484. case OPS.showSpacedText:
  41485. var items = args[0];
  41486. var offset;
  41487. for (var j = 0, jj = items.length; j < jj; j++) {
  41488. if (typeof items[j] === 'string') {
  41489. buildTextContentItem(items[j]);
  41490. } else {
  41491. ensureTextContentItem();
  41492. // PDF Specification 5.3.2 states:
  41493. // The number is expressed in thousandths of a unit of text
  41494. // space.
  41495. // This amount is subtracted from the current horizontal or
  41496. // vertical coordinate, depending on the writing mode.
  41497. // In the default coordinate system, a positive adjustment
  41498. // has the effect of moving the next glyph painted either to
  41499. // the left or down by the given amount.
  41500. advance = items[j] * textState.fontSize / 1000;
  41501. var breakTextRun = false;
  41502. if (textState.font.vertical) {
  41503. offset = advance *
  41504. (textState.textHScale * textState.textMatrix[2] +
  41505. textState.textMatrix[3]);
  41506. textState.translateTextMatrix(0, advance);
  41507. breakTextRun = textContentItem.textRunBreakAllowed &&
  41508. advance > textContentItem.fakeMultiSpaceMax;
  41509. if (!breakTextRun) {
  41510. // Value needs to be added to height to paint down.
  41511. textContentItem.height += offset;
  41512. }
  41513. } else {
  41514. advance = -advance;
  41515. offset = advance * (
  41516. textState.textHScale * textState.textMatrix[0] +
  41517. textState.textMatrix[1]);
  41518. textState.translateTextMatrix(advance, 0);
  41519. breakTextRun = textContentItem.textRunBreakAllowed &&
  41520. advance > textContentItem.fakeMultiSpaceMax;
  41521. if (!breakTextRun) {
  41522. // Value needs to be subtracted from width to paint left.
  41523. textContentItem.width += offset;
  41524. }
  41525. }
  41526. if (breakTextRun) {
  41527. flushTextContentItem();
  41528. } else if (advance > 0) {
  41529. addFakeSpaces(advance, textContentItem.str);
  41530. }
  41531. }
  41532. }
  41533. break;
  41534. case OPS.showText:
  41535. buildTextContentItem(args[0]);
  41536. break;
  41537. case OPS.nextLineShowText:
  41538. flushTextContentItem();
  41539. textState.carriageReturn();
  41540. buildTextContentItem(args[0]);
  41541. break;
  41542. case OPS.nextLineSetSpacingShowText:
  41543. flushTextContentItem();
  41544. textState.wordSpacing = args[0];
  41545. textState.charSpacing = args[1];
  41546. textState.carriageReturn();
  41547. buildTextContentItem(args[2]);
  41548. break;
  41549. case OPS.paintXObject:
  41550. flushTextContentItem();
  41551. if (args[0].code) {
  41552. break;
  41553. }
  41554. if (!xobjs) {
  41555. xobjs = (resources.get('XObject') || Dict.empty);
  41556. }
  41557. var name = args[0].name;
  41558. if (xobjsCache.key === name) {
  41559. if (xobjsCache.texts) {
  41560. Util.appendToArray(textContent.items, xobjsCache.texts.items);
  41561. Util.extendObj(textContent.styles, xobjsCache.texts.styles);
  41562. }
  41563. break;
  41564. }
  41565. var xobj = xobjs.get(name);
  41566. if (!xobj) {
  41567. break;
  41568. }
  41569. assert(isStream(xobj), 'XObject should be a stream');
  41570. var type = xobj.dict.get('Subtype');
  41571. assert(isName(type),
  41572. 'XObject should have a Name subtype');
  41573. if ('Form' !== type.name) {
  41574. xobjsCache.key = name;
  41575. xobjsCache.texts = null;
  41576. break;
  41577. }
  41578. stateManager.save();
  41579. var matrix = xobj.dict.get('Matrix');
  41580. if (isArray(matrix) && matrix.length === 6) {
  41581. stateManager.transform(matrix);
  41582. }
  41583. return self.getTextContent(xobj, task,
  41584. xobj.dict.get('Resources') || resources, stateManager,
  41585. normalizeWhitespace).then(function (formTextContent) {
  41586. Util.appendToArray(textContent.items, formTextContent.items);
  41587. Util.extendObj(textContent.styles, formTextContent.styles);
  41588. stateManager.restore();
  41589. xobjsCache.key = name;
  41590. xobjsCache.texts = formTextContent;
  41591. next(resolve, reject);
  41592. }, reject);
  41593. case OPS.setGState:
  41594. flushTextContentItem();
  41595. var dictName = args[0];
  41596. var extGState = resources.get('ExtGState');
  41597. if (!isDict(extGState) || !extGState.has(dictName.name)) {
  41598. break;
  41599. }
  41600. var gsStateMap = extGState.get(dictName.name);
  41601. var gsStateFont = null;
  41602. for (var key in gsStateMap) {
  41603. if (key === 'Font') {
  41604. assert(!gsStateFont);
  41605. gsStateFont = gsStateMap[key];
  41606. }
  41607. }
  41608. if (gsStateFont) {
  41609. textState.fontSize = gsStateFont[1];
  41610. return handleSetFont(gsStateFont[0]).then(function() {
  41611. next(resolve, reject);
  41612. }, reject);
  41613. }
  41614. break;
  41615. } // switch
  41616. } // while
  41617. if (stop) {
  41618. deferred.then(function () {
  41619. next(resolve, reject);
  41620. }, reject);
  41621. return;
  41622. }
  41623. flushTextContentItem();
  41624. resolve(textContent);
  41625. });
  41626. },
  41627. extractDataStructures: function
  41628. partialEvaluatorExtractDataStructures(dict, baseDict,
  41629. xref, properties) {
  41630. // 9.10.2
  41631. var toUnicode = (dict.get('ToUnicode') || baseDict.get('ToUnicode'));
  41632. if (toUnicode) {
  41633. properties.toUnicode = this.readToUnicode(toUnicode);
  41634. }
  41635. if (properties.composite) {
  41636. // CIDSystemInfo helps to match CID to glyphs
  41637. var cidSystemInfo = dict.get('CIDSystemInfo');
  41638. if (isDict(cidSystemInfo)) {
  41639. properties.cidSystemInfo = {
  41640. registry: cidSystemInfo.get('Registry'),
  41641. ordering: cidSystemInfo.get('Ordering'),
  41642. supplement: cidSystemInfo.get('Supplement')
  41643. };
  41644. }
  41645. var cidToGidMap = dict.get('CIDToGIDMap');
  41646. if (isStream(cidToGidMap)) {
  41647. properties.cidToGidMap = this.readCidToGidMap(cidToGidMap);
  41648. }
  41649. }
  41650. // Based on 9.6.6 of the spec the encoding can come from multiple places
  41651. // and depends on the font type. The base encoding and differences are
  41652. // read here, but the encoding that is actually used is chosen during
  41653. // glyph mapping in the font.
  41654. // TODO: Loading the built in encoding in the font would allow the
  41655. // differences to be merged in here not require us to hold on to it.
  41656. var differences = [];
  41657. var baseEncodingName = null;
  41658. var encoding;
  41659. if (dict.has('Encoding')) {
  41660. encoding = dict.get('Encoding');
  41661. if (isDict(encoding)) {
  41662. baseEncodingName = encoding.get('BaseEncoding');
  41663. baseEncodingName = (isName(baseEncodingName) ?
  41664. baseEncodingName.name : null);
  41665. // Load the differences between the base and original
  41666. if (encoding.has('Differences')) {
  41667. var diffEncoding = encoding.get('Differences');
  41668. var index = 0;
  41669. for (var j = 0, jj = diffEncoding.length; j < jj; j++) {
  41670. var data = diffEncoding[j];
  41671. if (isNum(data)) {
  41672. index = data;
  41673. } else if (isName(data)) {
  41674. differences[index++] = data.name;
  41675. } else if (isRef(data)) {
  41676. diffEncoding[j--] = xref.fetch(data);
  41677. continue;
  41678. } else {
  41679. error('Invalid entry in \'Differences\' array: ' + data);
  41680. }
  41681. }
  41682. }
  41683. } else if (isName(encoding)) {
  41684. baseEncodingName = encoding.name;
  41685. } else {
  41686. error('Encoding is not a Name nor a Dict');
  41687. }
  41688. // According to table 114 if the encoding is a named encoding it must be
  41689. // one of these predefined encodings.
  41690. if ((baseEncodingName !== 'MacRomanEncoding' &&
  41691. baseEncodingName !== 'MacExpertEncoding' &&
  41692. baseEncodingName !== 'WinAnsiEncoding')) {
  41693. baseEncodingName = null;
  41694. }
  41695. }
  41696. if (baseEncodingName) {
  41697. properties.defaultEncoding = Encodings[baseEncodingName].slice();
  41698. } else {
  41699. encoding = (properties.type === 'TrueType' ?
  41700. Encodings.WinAnsiEncoding : Encodings.StandardEncoding);
  41701. // The Symbolic attribute can be misused for regular fonts
  41702. // Heuristic: we have to check if the font is a standard one also
  41703. if (!!(properties.flags & FontFlags.Symbolic)) {
  41704. encoding = Encodings.MacRomanEncoding;
  41705. if (!properties.file) {
  41706. if (/Symbol/i.test(properties.name)) {
  41707. encoding = Encodings.SymbolSetEncoding;
  41708. } else if (/Dingbats/i.test(properties.name)) {
  41709. encoding = Encodings.ZapfDingbatsEncoding;
  41710. }
  41711. }
  41712. }
  41713. properties.defaultEncoding = encoding;
  41714. }
  41715. properties.differences = differences;
  41716. properties.baseEncodingName = baseEncodingName;
  41717. properties.dict = dict;
  41718. },
  41719. readToUnicode: function PartialEvaluator_readToUnicode(toUnicode) {
  41720. var cmap, cmapObj = toUnicode;
  41721. if (isName(cmapObj)) {
  41722. cmap = CMapFactory.create(cmapObj,
  41723. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  41724. if (cmap instanceof IdentityCMap) {
  41725. return new IdentityToUnicodeMap(0, 0xFFFF);
  41726. }
  41727. return new ToUnicodeMap(cmap.getMap());
  41728. } else if (isStream(cmapObj)) {
  41729. cmap = CMapFactory.create(cmapObj,
  41730. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  41731. if (cmap instanceof IdentityCMap) {
  41732. return new IdentityToUnicodeMap(0, 0xFFFF);
  41733. }
  41734. var map = new Array(cmap.length);
  41735. // Convert UTF-16BE
  41736. // NOTE: cmap can be a sparse array, so use forEach instead of for(;;)
  41737. // to iterate over all keys.
  41738. cmap.forEach(function(charCode, token) {
  41739. var str = [];
  41740. for (var k = 0; k < token.length; k += 2) {
  41741. var w1 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
  41742. if ((w1 & 0xF800) !== 0xD800) { // w1 < 0xD800 || w1 > 0xDFFF
  41743. str.push(w1);
  41744. continue;
  41745. }
  41746. k += 2;
  41747. var w2 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
  41748. str.push(((w1 & 0x3ff) << 10) + (w2 & 0x3ff) + 0x10000);
  41749. }
  41750. map[charCode] = String.fromCharCode.apply(String, str);
  41751. });
  41752. return new ToUnicodeMap(map);
  41753. }
  41754. return null;
  41755. },
  41756. readCidToGidMap: function PartialEvaluator_readCidToGidMap(cidToGidStream) {
  41757. // Extract the encoding from the CIDToGIDMap
  41758. var glyphsData = cidToGidStream.getBytes();
  41759. // Set encoding 0 to later verify the font has an encoding
  41760. var result = [];
  41761. for (var j = 0, jj = glyphsData.length; j < jj; j++) {
  41762. var glyphID = (glyphsData[j++] << 8) | glyphsData[j];
  41763. if (glyphID === 0) {
  41764. continue;
  41765. }
  41766. var code = j >> 1;
  41767. result[code] = glyphID;
  41768. }
  41769. return result;
  41770. },
  41771. extractWidths: function PartialEvaluator_extractWidths(dict, xref,
  41772. descriptor,
  41773. properties) {
  41774. var glyphsWidths = [];
  41775. var defaultWidth = 0;
  41776. var glyphsVMetrics = [];
  41777. var defaultVMetrics;
  41778. var i, ii, j, jj, start, code, widths;
  41779. if (properties.composite) {
  41780. defaultWidth = dict.get('DW') || 1000;
  41781. widths = dict.get('W');
  41782. if (widths) {
  41783. for (i = 0, ii = widths.length; i < ii; i++) {
  41784. start = widths[i++];
  41785. code = xref.fetchIfRef(widths[i]);
  41786. if (isArray(code)) {
  41787. for (j = 0, jj = code.length; j < jj; j++) {
  41788. glyphsWidths[start++] = code[j];
  41789. }
  41790. } else {
  41791. var width = widths[++i];
  41792. for (j = start; j <= code; j++) {
  41793. glyphsWidths[j] = width;
  41794. }
  41795. }
  41796. }
  41797. }
  41798. if (properties.vertical) {
  41799. var vmetrics = (dict.get('DW2') || [880, -1000]);
  41800. defaultVMetrics = [vmetrics[1], defaultWidth * 0.5, vmetrics[0]];
  41801. vmetrics = dict.get('W2');
  41802. if (vmetrics) {
  41803. for (i = 0, ii = vmetrics.length; i < ii; i++) {
  41804. start = vmetrics[i++];
  41805. code = xref.fetchIfRef(vmetrics[i]);
  41806. if (isArray(code)) {
  41807. for (j = 0, jj = code.length; j < jj; j++) {
  41808. glyphsVMetrics[start++] = [code[j++], code[j++], code[j]];
  41809. }
  41810. } else {
  41811. var vmetric = [vmetrics[++i], vmetrics[++i], vmetrics[++i]];
  41812. for (j = start; j <= code; j++) {
  41813. glyphsVMetrics[j] = vmetric;
  41814. }
  41815. }
  41816. }
  41817. }
  41818. }
  41819. } else {
  41820. var firstChar = properties.firstChar;
  41821. widths = dict.get('Widths');
  41822. if (widths) {
  41823. j = firstChar;
  41824. for (i = 0, ii = widths.length; i < ii; i++) {
  41825. glyphsWidths[j++] = widths[i];
  41826. }
  41827. defaultWidth = (parseFloat(descriptor.get('MissingWidth')) || 0);
  41828. } else {
  41829. // Trying get the BaseFont metrics (see comment above).
  41830. var baseFontName = dict.get('BaseFont');
  41831. if (isName(baseFontName)) {
  41832. var metrics = this.getBaseFontMetrics(baseFontName.name);
  41833. glyphsWidths = this.buildCharCodeToWidth(metrics.widths,
  41834. properties);
  41835. defaultWidth = metrics.defaultWidth;
  41836. }
  41837. }
  41838. }
  41839. // Heuristic: detection of monospace font by checking all non-zero widths
  41840. var isMonospace = true;
  41841. var firstWidth = defaultWidth;
  41842. for (var glyph in glyphsWidths) {
  41843. var glyphWidth = glyphsWidths[glyph];
  41844. if (!glyphWidth) {
  41845. continue;
  41846. }
  41847. if (!firstWidth) {
  41848. firstWidth = glyphWidth;
  41849. continue;
  41850. }
  41851. if (firstWidth !== glyphWidth) {
  41852. isMonospace = false;
  41853. break;
  41854. }
  41855. }
  41856. if (isMonospace) {
  41857. properties.flags |= FontFlags.FixedPitch;
  41858. }
  41859. properties.defaultWidth = defaultWidth;
  41860. properties.widths = glyphsWidths;
  41861. properties.defaultVMetrics = defaultVMetrics;
  41862. properties.vmetrics = glyphsVMetrics;
  41863. },
  41864. isSerifFont: function PartialEvaluator_isSerifFont(baseFontName) {
  41865. // Simulating descriptor flags attribute
  41866. var fontNameWoStyle = baseFontName.split('-')[0];
  41867. return (fontNameWoStyle in serifFonts) ||
  41868. (fontNameWoStyle.search(/serif/gi) !== -1);
  41869. },
  41870. getBaseFontMetrics: function PartialEvaluator_getBaseFontMetrics(name) {
  41871. var defaultWidth = 0;
  41872. var widths = [];
  41873. var monospace = false;
  41874. var lookupName = (stdFontMap[name] || name);
  41875. if (!(lookupName in Metrics)) {
  41876. // Use default fonts for looking up font metrics if the passed
  41877. // font is not a base font
  41878. if (this.isSerifFont(name)) {
  41879. lookupName = 'Times-Roman';
  41880. } else {
  41881. lookupName = 'Helvetica';
  41882. }
  41883. }
  41884. var glyphWidths = Metrics[lookupName];
  41885. if (isNum(glyphWidths)) {
  41886. defaultWidth = glyphWidths;
  41887. monospace = true;
  41888. } else {
  41889. widths = glyphWidths;
  41890. }
  41891. return {
  41892. defaultWidth: defaultWidth,
  41893. monospace: monospace,
  41894. widths: widths
  41895. };
  41896. },
  41897. buildCharCodeToWidth:
  41898. function PartialEvaluator_bulildCharCodeToWidth(widthsByGlyphName,
  41899. properties) {
  41900. var widths = Object.create(null);
  41901. var differences = properties.differences;
  41902. var encoding = properties.defaultEncoding;
  41903. for (var charCode = 0; charCode < 256; charCode++) {
  41904. if (charCode in differences &&
  41905. widthsByGlyphName[differences[charCode]]) {
  41906. widths[charCode] = widthsByGlyphName[differences[charCode]];
  41907. continue;
  41908. }
  41909. if (charCode in encoding && widthsByGlyphName[encoding[charCode]]) {
  41910. widths[charCode] = widthsByGlyphName[encoding[charCode]];
  41911. continue;
  41912. }
  41913. }
  41914. return widths;
  41915. },
  41916. preEvaluateFont: function PartialEvaluator_preEvaluateFont(dict, xref) {
  41917. var baseDict = dict;
  41918. var type = dict.get('Subtype');
  41919. assert(isName(type), 'invalid font Subtype');
  41920. var composite = false;
  41921. var uint8array;
  41922. if (type.name === 'Type0') {
  41923. // If font is a composite
  41924. // - get the descendant font
  41925. // - set the type according to the descendant font
  41926. // - get the FontDescriptor from the descendant font
  41927. var df = dict.get('DescendantFonts');
  41928. if (!df) {
  41929. error('Descendant fonts are not specified');
  41930. }
  41931. dict = (isArray(df) ? xref.fetchIfRef(df[0]) : df);
  41932. type = dict.get('Subtype');
  41933. assert(isName(type), 'invalid font Subtype');
  41934. composite = true;
  41935. }
  41936. var descriptor = dict.get('FontDescriptor');
  41937. if (descriptor) {
  41938. var hash = new MurmurHash3_64();
  41939. var encoding = baseDict.getRaw('Encoding');
  41940. if (isName(encoding)) {
  41941. hash.update(encoding.name);
  41942. } else if (isRef(encoding)) {
  41943. hash.update(encoding.num + '_' + encoding.gen);
  41944. } else if (isDict(encoding)) {
  41945. var keys = encoding.getKeys();
  41946. for (var i = 0, ii = keys.length; i < ii; i++) {
  41947. var entry = encoding.getRaw(keys[i]);
  41948. if (isName(entry)) {
  41949. hash.update(entry.name);
  41950. } else if (isRef(entry)) {
  41951. hash.update(entry.num + '_' + entry.gen);
  41952. } else if (isArray(entry)) { // 'Differences' entry.
  41953. // Ideally we should check the contents of the array, but to avoid
  41954. // parsing it here and then again in |extractDataStructures|,
  41955. // we only use the array length for now (fixes bug1157493.pdf).
  41956. hash.update(entry.length.toString());
  41957. }
  41958. }
  41959. }
  41960. var toUnicode = dict.get('ToUnicode') || baseDict.get('ToUnicode');
  41961. if (isStream(toUnicode)) {
  41962. var stream = toUnicode.str || toUnicode;
  41963. uint8array = stream.buffer ?
  41964. new Uint8Array(stream.buffer.buffer, 0, stream.bufferLength) :
  41965. new Uint8Array(stream.bytes.buffer,
  41966. stream.start, stream.end - stream.start);
  41967. hash.update(uint8array);
  41968. } else if (isName(toUnicode)) {
  41969. hash.update(toUnicode.name);
  41970. }
  41971. var widths = dict.get('Widths') || baseDict.get('Widths');
  41972. if (widths) {
  41973. uint8array = new Uint8Array(new Uint32Array(widths).buffer);
  41974. hash.update(uint8array);
  41975. }
  41976. }
  41977. return {
  41978. descriptor: descriptor,
  41979. dict: dict,
  41980. baseDict: baseDict,
  41981. composite: composite,
  41982. type: type.name,
  41983. hash: hash ? hash.hexdigest() : ''
  41984. };
  41985. },
  41986. translateFont: function PartialEvaluator_translateFont(preEvaluatedFont,
  41987. xref) {
  41988. var baseDict = preEvaluatedFont.baseDict;
  41989. var dict = preEvaluatedFont.dict;
  41990. var composite = preEvaluatedFont.composite;
  41991. var descriptor = preEvaluatedFont.descriptor;
  41992. var type = preEvaluatedFont.type;
  41993. var maxCharIndex = (composite ? 0xFFFF : 0xFF);
  41994. var properties;
  41995. if (!descriptor) {
  41996. if (type === 'Type3') {
  41997. // FontDescriptor is only required for Type3 fonts when the document
  41998. // is a tagged pdf. Create a barbebones one to get by.
  41999. descriptor = new Dict(null);
  42000. descriptor.set('FontName', Name.get(type));
  42001. descriptor.set('FontBBox', dict.get('FontBBox'));
  42002. } else {
  42003. // Before PDF 1.5 if the font was one of the base 14 fonts, having a
  42004. // FontDescriptor was not required.
  42005. // This case is here for compatibility.
  42006. var baseFontName = dict.get('BaseFont');
  42007. if (!isName(baseFontName)) {
  42008. error('Base font is not specified');
  42009. }
  42010. // Using base font name as a font name.
  42011. baseFontName = baseFontName.name.replace(/[,_]/g, '-');
  42012. var metrics = this.getBaseFontMetrics(baseFontName);
  42013. // Simulating descriptor flags attribute
  42014. var fontNameWoStyle = baseFontName.split('-')[0];
  42015. var flags =
  42016. (this.isSerifFont(fontNameWoStyle) ? FontFlags.Serif : 0) |
  42017. (metrics.monospace ? FontFlags.FixedPitch : 0) |
  42018. (symbolsFonts[fontNameWoStyle] ? FontFlags.Symbolic :
  42019. FontFlags.Nonsymbolic);
  42020. properties = {
  42021. type: type,
  42022. name: baseFontName,
  42023. widths: metrics.widths,
  42024. defaultWidth: metrics.defaultWidth,
  42025. flags: flags,
  42026. firstChar: 0,
  42027. lastChar: maxCharIndex
  42028. };
  42029. this.extractDataStructures(dict, dict, xref, properties);
  42030. properties.widths = this.buildCharCodeToWidth(metrics.widths,
  42031. properties);
  42032. return new Font(baseFontName, null, properties);
  42033. }
  42034. }
  42035. // According to the spec if 'FontDescriptor' is declared, 'FirstChar',
  42036. // 'LastChar' and 'Widths' should exist too, but some PDF encoders seem
  42037. // to ignore this rule when a variant of a standart font is used.
  42038. // TODO Fill the width array depending on which of the base font this is
  42039. // a variant.
  42040. var firstChar = (dict.get('FirstChar') || 0);
  42041. var lastChar = (dict.get('LastChar') || maxCharIndex);
  42042. var fontName = descriptor.get('FontName');
  42043. var baseFont = dict.get('BaseFont');
  42044. // Some bad PDFs have a string as the font name.
  42045. if (isString(fontName)) {
  42046. fontName = Name.get(fontName);
  42047. }
  42048. if (isString(baseFont)) {
  42049. baseFont = Name.get(baseFont);
  42050. }
  42051. if (type !== 'Type3') {
  42052. var fontNameStr = fontName && fontName.name;
  42053. var baseFontStr = baseFont && baseFont.name;
  42054. if (fontNameStr !== baseFontStr) {
  42055. info('The FontDescriptor\'s FontName is "' + fontNameStr +
  42056. '" but should be the same as the Font\'s BaseFont "' +
  42057. baseFontStr + '"');
  42058. // Workaround for cases where e.g. fontNameStr = 'Arial' and
  42059. // baseFontStr = 'Arial,Bold' (needed when no font file is embedded).
  42060. if (fontNameStr && baseFontStr &&
  42061. baseFontStr.indexOf(fontNameStr) === 0) {
  42062. fontName = baseFont;
  42063. }
  42064. }
  42065. }
  42066. fontName = (fontName || baseFont);
  42067. assert(isName(fontName), 'invalid font name');
  42068. var fontFile = descriptor.get('FontFile', 'FontFile2', 'FontFile3');
  42069. if (fontFile) {
  42070. if (fontFile.dict) {
  42071. var subtype = fontFile.dict.get('Subtype');
  42072. if (subtype) {
  42073. subtype = subtype.name;
  42074. }
  42075. var length1 = fontFile.dict.get('Length1');
  42076. var length2 = fontFile.dict.get('Length2');
  42077. }
  42078. }
  42079. properties = {
  42080. type: type,
  42081. name: fontName.name,
  42082. subtype: subtype,
  42083. file: fontFile,
  42084. length1: length1,
  42085. length2: length2,
  42086. loadedName: baseDict.loadedName,
  42087. composite: composite,
  42088. wideChars: composite,
  42089. fixedPitch: false,
  42090. fontMatrix: (dict.get('FontMatrix') || FONT_IDENTITY_MATRIX),
  42091. firstChar: firstChar || 0,
  42092. lastChar: (lastChar || maxCharIndex),
  42093. bbox: descriptor.get('FontBBox'),
  42094. ascent: descriptor.get('Ascent'),
  42095. descent: descriptor.get('Descent'),
  42096. xHeight: descriptor.get('XHeight'),
  42097. capHeight: descriptor.get('CapHeight'),
  42098. flags: descriptor.get('Flags'),
  42099. italicAngle: descriptor.get('ItalicAngle'),
  42100. coded: false
  42101. };
  42102. if (composite) {
  42103. var cidEncoding = baseDict.get('Encoding');
  42104. if (isName(cidEncoding)) {
  42105. properties.cidEncoding = cidEncoding.name;
  42106. }
  42107. properties.cMap = CMapFactory.create(cidEncoding,
  42108. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  42109. properties.vertical = properties.cMap.vertical;
  42110. }
  42111. this.extractDataStructures(dict, baseDict, xref, properties);
  42112. this.extractWidths(dict, xref, descriptor, properties);
  42113. if (type === 'Type3') {
  42114. properties.isType3Font = true;
  42115. }
  42116. return new Font(fontName.name, fontFile, properties);
  42117. }
  42118. };
  42119. return PartialEvaluator;
  42120. })();
  42121. var TranslatedFont = (function TranslatedFontClosure() {
  42122. function TranslatedFont(loadedName, font, dict) {
  42123. this.loadedName = loadedName;
  42124. this.font = font;
  42125. this.dict = dict;
  42126. this.type3Loaded = null;
  42127. this.sent = false;
  42128. }
  42129. TranslatedFont.prototype = {
  42130. send: function (handler) {
  42131. if (this.sent) {
  42132. return;
  42133. }
  42134. var fontData = this.font.exportData();
  42135. handler.send('commonobj', [
  42136. this.loadedName,
  42137. 'Font',
  42138. fontData
  42139. ]);
  42140. this.sent = true;
  42141. },
  42142. loadType3Data: function (evaluator, resources, parentOperatorList, task) {
  42143. assert(this.font.isType3Font);
  42144. if (this.type3Loaded) {
  42145. return this.type3Loaded;
  42146. }
  42147. var translatedFont = this.font;
  42148. var loadCharProcsPromise = Promise.resolve();
  42149. var charProcs = this.dict.get('CharProcs').getAll();
  42150. var fontResources = this.dict.get('Resources') || resources;
  42151. var charProcKeys = Object.keys(charProcs);
  42152. var charProcOperatorList = {};
  42153. for (var i = 0, n = charProcKeys.length; i < n; ++i) {
  42154. loadCharProcsPromise = loadCharProcsPromise.then(function (key) {
  42155. var glyphStream = charProcs[key];
  42156. var operatorList = new OperatorList();
  42157. return evaluator.getOperatorList(glyphStream, task, fontResources,
  42158. operatorList).then(function () {
  42159. charProcOperatorList[key] = operatorList.getIR();
  42160. // Add the dependencies to the parent operator list so they are
  42161. // resolved before sub operator list is executed synchronously.
  42162. parentOperatorList.addDependencies(operatorList.dependencies);
  42163. }, function (reason) {
  42164. warn('Type3 font resource \"' + key + '\" is not available');
  42165. var operatorList = new OperatorList();
  42166. charProcOperatorList[key] = operatorList.getIR();
  42167. });
  42168. }.bind(this, charProcKeys[i]));
  42169. }
  42170. this.type3Loaded = loadCharProcsPromise.then(function () {
  42171. translatedFont.charProcOperatorList = charProcOperatorList;
  42172. });
  42173. return this.type3Loaded;
  42174. }
  42175. };
  42176. return TranslatedFont;
  42177. })();
  42178. var OperatorList = (function OperatorListClosure() {
  42179. var CHUNK_SIZE = 1000;
  42180. var CHUNK_SIZE_ABOUT = CHUNK_SIZE - 5; // close to chunk size
  42181. function getTransfers(queue) {
  42182. var transfers = [];
  42183. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  42184. for (var i = 0, ii = queue.length; i < ii; i++) {
  42185. switch (fnArray[i]) {
  42186. case OPS.paintInlineImageXObject:
  42187. case OPS.paintInlineImageXObjectGroup:
  42188. case OPS.paintImageMaskXObject:
  42189. var arg = argsArray[i][0]; // first param in imgData
  42190. if (!arg.cached) {
  42191. transfers.push(arg.data.buffer);
  42192. }
  42193. break;
  42194. }
  42195. }
  42196. return transfers;
  42197. }
  42198. function OperatorList(intent, messageHandler, pageIndex) {
  42199. this.messageHandler = messageHandler;
  42200. this.fnArray = [];
  42201. this.argsArray = [];
  42202. this.dependencies = {};
  42203. this._totalLength = 0;
  42204. this.pageIndex = pageIndex;
  42205. this.intent = intent;
  42206. }
  42207. OperatorList.prototype = {
  42208. get length() {
  42209. return this.argsArray.length;
  42210. },
  42211. /**
  42212. * @returns {number} The total length of the entire operator list,
  42213. * since `this.length === 0` after flushing.
  42214. */
  42215. get totalLength() {
  42216. return (this._totalLength + this.length);
  42217. },
  42218. addOp: function(fn, args) {
  42219. this.fnArray.push(fn);
  42220. this.argsArray.push(args);
  42221. if (this.messageHandler) {
  42222. if (this.fnArray.length >= CHUNK_SIZE) {
  42223. this.flush();
  42224. } else if (this.fnArray.length >= CHUNK_SIZE_ABOUT &&
  42225. (fn === OPS.restore || fn === OPS.endText)) {
  42226. // heuristic to flush on boundary of restore or endText
  42227. this.flush();
  42228. }
  42229. }
  42230. },
  42231. addDependency: function(dependency) {
  42232. if (dependency in this.dependencies) {
  42233. return;
  42234. }
  42235. this.dependencies[dependency] = true;
  42236. this.addOp(OPS.dependency, [dependency]);
  42237. },
  42238. addDependencies: function(dependencies) {
  42239. for (var key in dependencies) {
  42240. this.addDependency(key);
  42241. }
  42242. },
  42243. addOpList: function(opList) {
  42244. Util.extendObj(this.dependencies, opList.dependencies);
  42245. for (var i = 0, ii = opList.length; i < ii; i++) {
  42246. this.addOp(opList.fnArray[i], opList.argsArray[i]);
  42247. }
  42248. },
  42249. getIR: function() {
  42250. return {
  42251. fnArray: this.fnArray,
  42252. argsArray: this.argsArray,
  42253. length: this.length
  42254. };
  42255. },
  42256. flush: function(lastChunk) {
  42257. if (this.intent !== 'oplist') {
  42258. new QueueOptimizer().optimize(this);
  42259. }
  42260. var transfers = getTransfers(this);
  42261. var length = this.length;
  42262. this._totalLength += length;
  42263. this.messageHandler.send('RenderPageChunk', {
  42264. operatorList: {
  42265. fnArray: this.fnArray,
  42266. argsArray: this.argsArray,
  42267. lastChunk: lastChunk,
  42268. length: length
  42269. },
  42270. pageIndex: this.pageIndex,
  42271. intent: this.intent
  42272. }, transfers);
  42273. this.dependencies = {};
  42274. this.fnArray.length = 0;
  42275. this.argsArray.length = 0;
  42276. }
  42277. };
  42278. return OperatorList;
  42279. })();
  42280. var StateManager = (function StateManagerClosure() {
  42281. function StateManager(initialState) {
  42282. this.state = initialState;
  42283. this.stateStack = [];
  42284. }
  42285. StateManager.prototype = {
  42286. save: function () {
  42287. var old = this.state;
  42288. this.stateStack.push(this.state);
  42289. this.state = old.clone();
  42290. },
  42291. restore: function () {
  42292. var prev = this.stateStack.pop();
  42293. if (prev) {
  42294. this.state = prev;
  42295. }
  42296. },
  42297. transform: function (args) {
  42298. this.state.ctm = Util.transform(this.state.ctm, args);
  42299. }
  42300. };
  42301. return StateManager;
  42302. })();
  42303. var TextState = (function TextStateClosure() {
  42304. function TextState() {
  42305. this.ctm = new Float32Array(IDENTITY_MATRIX);
  42306. this.fontSize = 0;
  42307. this.font = null;
  42308. this.fontMatrix = FONT_IDENTITY_MATRIX;
  42309. this.textMatrix = IDENTITY_MATRIX.slice();
  42310. this.textLineMatrix = IDENTITY_MATRIX.slice();
  42311. this.charSpacing = 0;
  42312. this.wordSpacing = 0;
  42313. this.leading = 0;
  42314. this.textHScale = 1;
  42315. this.textRise = 0;
  42316. }
  42317. TextState.prototype = {
  42318. setTextMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  42319. var m = this.textMatrix;
  42320. m[0] = a; m[1] = b; m[2] = c; m[3] = d; m[4] = e; m[5] = f;
  42321. },
  42322. setTextLineMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  42323. var m = this.textLineMatrix;
  42324. m[0] = a; m[1] = b; m[2] = c; m[3] = d; m[4] = e; m[5] = f;
  42325. },
  42326. translateTextMatrix: function TextState_translateTextMatrix(x, y) {
  42327. var m = this.textMatrix;
  42328. m[4] = m[0] * x + m[2] * y + m[4];
  42329. m[5] = m[1] * x + m[3] * y + m[5];
  42330. },
  42331. translateTextLineMatrix: function TextState_translateTextMatrix(x, y) {
  42332. var m = this.textLineMatrix;
  42333. m[4] = m[0] * x + m[2] * y + m[4];
  42334. m[5] = m[1] * x + m[3] * y + m[5];
  42335. },
  42336. calcRenderMatrix: function TextState_calcRendeMatrix(ctm) {
  42337. // 9.4.4 Text Space Details
  42338. var tsm = [this.fontSize * this.textHScale, 0,
  42339. 0, this.fontSize,
  42340. 0, this.textRise];
  42341. return Util.transform(ctm, Util.transform(this.textMatrix, tsm));
  42342. },
  42343. carriageReturn: function TextState_carriageReturn() {
  42344. this.translateTextLineMatrix(0, -this.leading);
  42345. this.textMatrix = this.textLineMatrix.slice();
  42346. },
  42347. clone: function TextState_clone() {
  42348. var clone = Object.create(this);
  42349. clone.textMatrix = this.textMatrix.slice();
  42350. clone.textLineMatrix = this.textLineMatrix.slice();
  42351. clone.fontMatrix = this.fontMatrix.slice();
  42352. return clone;
  42353. }
  42354. };
  42355. return TextState;
  42356. })();
  42357. var EvalState = (function EvalStateClosure() {
  42358. function EvalState() {
  42359. this.ctm = new Float32Array(IDENTITY_MATRIX);
  42360. this.font = null;
  42361. this.textRenderingMode = TextRenderingMode.FILL;
  42362. this.fillColorSpace = ColorSpace.singletons.gray;
  42363. this.strokeColorSpace = ColorSpace.singletons.gray;
  42364. }
  42365. EvalState.prototype = {
  42366. clone: function CanvasExtraState_clone() {
  42367. return Object.create(this);
  42368. },
  42369. };
  42370. return EvalState;
  42371. })();
  42372. var EvaluatorPreprocessor = (function EvaluatorPreprocessorClosure() {
  42373. // Specifies properties for each command
  42374. //
  42375. // If variableArgs === true: [0, `numArgs`] expected
  42376. // If variableArgs === false: exactly `numArgs` expected
  42377. var OP_MAP = {
  42378. // Graphic state
  42379. w: { id: OPS.setLineWidth, numArgs: 1, variableArgs: false },
  42380. J: { id: OPS.setLineCap, numArgs: 1, variableArgs: false },
  42381. j: { id: OPS.setLineJoin, numArgs: 1, variableArgs: false },
  42382. M: { id: OPS.setMiterLimit, numArgs: 1, variableArgs: false },
  42383. d: { id: OPS.setDash, numArgs: 2, variableArgs: false },
  42384. ri: { id: OPS.setRenderingIntent, numArgs: 1, variableArgs: false },
  42385. i: { id: OPS.setFlatness, numArgs: 1, variableArgs: false },
  42386. gs: { id: OPS.setGState, numArgs: 1, variableArgs: false },
  42387. q: { id: OPS.save, numArgs: 0, variableArgs: false },
  42388. Q: { id: OPS.restore, numArgs: 0, variableArgs: false },
  42389. cm: { id: OPS.transform, numArgs: 6, variableArgs: false },
  42390. // Path
  42391. m: { id: OPS.moveTo, numArgs: 2, variableArgs: false },
  42392. l: { id: OPS.lineTo, numArgs: 2, variableArgs: false },
  42393. c: { id: OPS.curveTo, numArgs: 6, variableArgs: false },
  42394. v: { id: OPS.curveTo2, numArgs: 4, variableArgs: false },
  42395. y: { id: OPS.curveTo3, numArgs: 4, variableArgs: false },
  42396. h: { id: OPS.closePath, numArgs: 0, variableArgs: false },
  42397. re: { id: OPS.rectangle, numArgs: 4, variableArgs: false },
  42398. S: { id: OPS.stroke, numArgs: 0, variableArgs: false },
  42399. s: { id: OPS.closeStroke, numArgs: 0, variableArgs: false },
  42400. f: { id: OPS.fill, numArgs: 0, variableArgs: false },
  42401. F: { id: OPS.fill, numArgs: 0, variableArgs: false },
  42402. 'f*': { id: OPS.eoFill, numArgs: 0, variableArgs: false },
  42403. B: { id: OPS.fillStroke, numArgs: 0, variableArgs: false },
  42404. 'B*': { id: OPS.eoFillStroke, numArgs: 0, variableArgs: false },
  42405. b: { id: OPS.closeFillStroke, numArgs: 0, variableArgs: false },
  42406. 'b*': { id: OPS.closeEOFillStroke, numArgs: 0, variableArgs: false },
  42407. n: { id: OPS.endPath, numArgs: 0, variableArgs: false },
  42408. // Clipping
  42409. W: { id: OPS.clip, numArgs: 0, variableArgs: false },
  42410. 'W*': { id: OPS.eoClip, numArgs: 0, variableArgs: false },
  42411. // Text
  42412. BT: { id: OPS.beginText, numArgs: 0, variableArgs: false },
  42413. ET: { id: OPS.endText, numArgs: 0, variableArgs: false },
  42414. Tc: { id: OPS.setCharSpacing, numArgs: 1, variableArgs: false },
  42415. Tw: { id: OPS.setWordSpacing, numArgs: 1, variableArgs: false },
  42416. Tz: { id: OPS.setHScale, numArgs: 1, variableArgs: false },
  42417. TL: { id: OPS.setLeading, numArgs: 1, variableArgs: false },
  42418. Tf: { id: OPS.setFont, numArgs: 2, variableArgs: false },
  42419. Tr: { id: OPS.setTextRenderingMode, numArgs: 1, variableArgs: false },
  42420. Ts: { id: OPS.setTextRise, numArgs: 1, variableArgs: false },
  42421. Td: { id: OPS.moveText, numArgs: 2, variableArgs: false },
  42422. TD: { id: OPS.setLeadingMoveText, numArgs: 2, variableArgs: false },
  42423. Tm: { id: OPS.setTextMatrix, numArgs: 6, variableArgs: false },
  42424. 'T*': { id: OPS.nextLine, numArgs: 0, variableArgs: false },
  42425. Tj: { id: OPS.showText, numArgs: 1, variableArgs: false },
  42426. TJ: { id: OPS.showSpacedText, numArgs: 1, variableArgs: false },
  42427. '\'': { id: OPS.nextLineShowText, numArgs: 1, variableArgs: false },
  42428. '"': { id: OPS.nextLineSetSpacingShowText, numArgs: 3,
  42429. variableArgs: false },
  42430. // Type3 fonts
  42431. d0: { id: OPS.setCharWidth, numArgs: 2, variableArgs: false },
  42432. d1: { id: OPS.setCharWidthAndBounds, numArgs: 6, variableArgs: false },
  42433. // Color
  42434. CS: { id: OPS.setStrokeColorSpace, numArgs: 1, variableArgs: false },
  42435. cs: { id: OPS.setFillColorSpace, numArgs: 1, variableArgs: false },
  42436. SC: { id: OPS.setStrokeColor, numArgs: 4, variableArgs: true },
  42437. SCN: { id: OPS.setStrokeColorN, numArgs: 33, variableArgs: true },
  42438. sc: { id: OPS.setFillColor, numArgs: 4, variableArgs: true },
  42439. scn: { id: OPS.setFillColorN, numArgs: 33, variableArgs: true },
  42440. G: { id: OPS.setStrokeGray, numArgs: 1, variableArgs: false },
  42441. g: { id: OPS.setFillGray, numArgs: 1, variableArgs: false },
  42442. RG: { id: OPS.setStrokeRGBColor, numArgs: 3, variableArgs: false },
  42443. rg: { id: OPS.setFillRGBColor, numArgs: 3, variableArgs: false },
  42444. K: { id: OPS.setStrokeCMYKColor, numArgs: 4, variableArgs: false },
  42445. k: { id: OPS.setFillCMYKColor, numArgs: 4, variableArgs: false },
  42446. // Shading
  42447. sh: { id: OPS.shadingFill, numArgs: 1, variableArgs: false },
  42448. // Images
  42449. BI: { id: OPS.beginInlineImage, numArgs: 0, variableArgs: false },
  42450. ID: { id: OPS.beginImageData, numArgs: 0, variableArgs: false },
  42451. EI: { id: OPS.endInlineImage, numArgs: 1, variableArgs: false },
  42452. // XObjects
  42453. Do: { id: OPS.paintXObject, numArgs: 1, variableArgs: false },
  42454. MP: { id: OPS.markPoint, numArgs: 1, variableArgs: false },
  42455. DP: { id: OPS.markPointProps, numArgs: 2, variableArgs: false },
  42456. BMC: { id: OPS.beginMarkedContent, numArgs: 1, variableArgs: false },
  42457. BDC: { id: OPS.beginMarkedContentProps, numArgs: 2,
  42458. variableArgs: false },
  42459. EMC: { id: OPS.endMarkedContent, numArgs: 0, variableArgs: false },
  42460. // Compatibility
  42461. BX: { id: OPS.beginCompat, numArgs: 0, variableArgs: false },
  42462. EX: { id: OPS.endCompat, numArgs: 0, variableArgs: false },
  42463. // (reserved partial commands for the lexer)
  42464. BM: null,
  42465. BD: null,
  42466. 'true': null,
  42467. fa: null,
  42468. fal: null,
  42469. fals: null,
  42470. 'false': null,
  42471. nu: null,
  42472. nul: null,
  42473. 'null': null
  42474. };
  42475. function EvaluatorPreprocessor(stream, xref, stateManager) {
  42476. // TODO(mduan): pass array of knownCommands rather than OP_MAP
  42477. // dictionary
  42478. this.parser = new Parser(new Lexer(stream, OP_MAP), false, xref);
  42479. this.stateManager = stateManager;
  42480. this.nonProcessedArgs = [];
  42481. }
  42482. EvaluatorPreprocessor.prototype = {
  42483. get savedStatesDepth() {
  42484. return this.stateManager.stateStack.length;
  42485. },
  42486. // |operation| is an object with two fields:
  42487. //
  42488. // - |fn| is an out param.
  42489. //
  42490. // - |args| is an inout param. On entry, it should have one of two values.
  42491. //
  42492. // - An empty array. This indicates that the caller is providing the
  42493. // array in which the args will be stored in. The caller should use
  42494. // this value if it can reuse a single array for each call to read().
  42495. //
  42496. // - |null|. This indicates that the caller needs this function to create
  42497. // the array in which any args are stored in. If there are zero args,
  42498. // this function will leave |operation.args| as |null| (thus avoiding
  42499. // allocations that would occur if we used an empty array to represent
  42500. // zero arguments). Otherwise, it will replace |null| with a new array
  42501. // containing the arguments. The caller should use this value if it
  42502. // cannot reuse an array for each call to read().
  42503. //
  42504. // These two modes are present because this function is very hot and so
  42505. // avoiding allocations where possible is worthwhile.
  42506. //
  42507. read: function EvaluatorPreprocessor_read(operation) {
  42508. var args = operation.args;
  42509. while (true) {
  42510. var obj = this.parser.getObj();
  42511. if (isCmd(obj)) {
  42512. var cmd = obj.cmd;
  42513. // Check that the command is valid
  42514. var opSpec = OP_MAP[cmd];
  42515. if (!opSpec) {
  42516. warn('Unknown command "' + cmd + '"');
  42517. continue;
  42518. }
  42519. var fn = opSpec.id;
  42520. var numArgs = opSpec.numArgs;
  42521. var argsLength = args !== null ? args.length : 0;
  42522. if (!opSpec.variableArgs) {
  42523. // Postscript commands can be nested, e.g. /F2 /GS2 gs 5.711 Tf
  42524. if (argsLength !== numArgs) {
  42525. var nonProcessedArgs = this.nonProcessedArgs;
  42526. while (argsLength > numArgs) {
  42527. nonProcessedArgs.push(args.shift());
  42528. argsLength--;
  42529. }
  42530. while (argsLength < numArgs && nonProcessedArgs.length !== 0) {
  42531. if (!args) {
  42532. args = [];
  42533. }
  42534. args.unshift(nonProcessedArgs.pop());
  42535. argsLength++;
  42536. }
  42537. }
  42538. if (argsLength < numArgs) {
  42539. // If we receive too few args, it's not possible to possible
  42540. // to execute the command, so skip the command
  42541. info('Command ' + fn + ': because expected ' +
  42542. numArgs + ' args, but received ' + argsLength +
  42543. ' args; skipping');
  42544. args = null;
  42545. continue;
  42546. }
  42547. } else if (argsLength > numArgs) {
  42548. info('Command ' + fn + ': expected [0,' + numArgs +
  42549. '] args, but received ' + argsLength + ' args');
  42550. }
  42551. // TODO figure out how to type-check vararg functions
  42552. this.preprocessCommand(fn, args);
  42553. operation.fn = fn;
  42554. operation.args = args;
  42555. return true;
  42556. } else {
  42557. if (isEOF(obj)) {
  42558. return false; // no more commands
  42559. }
  42560. // argument
  42561. if (obj !== null) {
  42562. if (!args) {
  42563. args = [];
  42564. }
  42565. args.push((obj instanceof Dict ? obj.getAll() : obj));
  42566. assert(args.length <= 33, 'Too many arguments');
  42567. }
  42568. }
  42569. }
  42570. },
  42571. preprocessCommand:
  42572. function EvaluatorPreprocessor_preprocessCommand(fn, args) {
  42573. switch (fn | 0) {
  42574. case OPS.save:
  42575. this.stateManager.save();
  42576. break;
  42577. case OPS.restore:
  42578. this.stateManager.restore();
  42579. break;
  42580. case OPS.transform:
  42581. this.stateManager.transform(args);
  42582. break;
  42583. }
  42584. }
  42585. };
  42586. return EvaluatorPreprocessor;
  42587. })();
  42588. var QueueOptimizer = (function QueueOptimizerClosure() {
  42589. function addState(parentState, pattern, fn) {
  42590. var state = parentState;
  42591. for (var i = 0, ii = pattern.length - 1; i < ii; i++) {
  42592. var item = pattern[i];
  42593. state = (state[item] || (state[item] = []));
  42594. }
  42595. state[pattern[pattern.length - 1]] = fn;
  42596. }
  42597. function handlePaintSolidColorImageMask(iFirstSave, count, fnArray,
  42598. argsArray) {
  42599. // Handles special case of mainly LaTeX documents which use image masks to
  42600. // draw lines with the current fill style.
  42601. // 'count' groups of (save, transform, paintImageMaskXObject, restore)+
  42602. // have been found at iFirstSave.
  42603. var iFirstPIMXO = iFirstSave + 2;
  42604. for (var i = 0; i < count; i++) {
  42605. var arg = argsArray[iFirstPIMXO + 4 * i];
  42606. var imageMask = arg.length === 1 && arg[0];
  42607. if (imageMask && imageMask.width === 1 && imageMask.height === 1 &&
  42608. (!imageMask.data.length ||
  42609. (imageMask.data.length === 1 && imageMask.data[0] === 0))) {
  42610. fnArray[iFirstPIMXO + 4 * i] = OPS.paintSolidColorImageMask;
  42611. continue;
  42612. }
  42613. break;
  42614. }
  42615. return count - i;
  42616. }
  42617. var InitialState = [];
  42618. // This replaces (save, transform, paintInlineImageXObject, restore)+
  42619. // sequences with one |paintInlineImageXObjectGroup| operation.
  42620. addState(InitialState,
  42621. [OPS.save, OPS.transform, OPS.paintInlineImageXObject, OPS.restore],
  42622. function foundInlineImageGroup(context) {
  42623. var MIN_IMAGES_IN_INLINE_IMAGES_BLOCK = 10;
  42624. var MAX_IMAGES_IN_INLINE_IMAGES_BLOCK = 200;
  42625. var MAX_WIDTH = 1000;
  42626. var IMAGE_PADDING = 1;
  42627. var fnArray = context.fnArray, argsArray = context.argsArray;
  42628. var curr = context.iCurr;
  42629. var iFirstSave = curr - 3;
  42630. var iFirstTransform = curr - 2;
  42631. var iFirstPIIXO = curr - 1;
  42632. // Look for the quartets.
  42633. var i = iFirstSave + 4;
  42634. var ii = fnArray.length;
  42635. while (i + 3 < ii) {
  42636. if (fnArray[i] !== OPS.save ||
  42637. fnArray[i + 1] !== OPS.transform ||
  42638. fnArray[i + 2] !== OPS.paintInlineImageXObject ||
  42639. fnArray[i + 3] !== OPS.restore) {
  42640. break; // ops don't match
  42641. }
  42642. i += 4;
  42643. }
  42644. // At this point, i is the index of the first op past the last valid
  42645. // quartet.
  42646. var count = Math.min((i - iFirstSave) / 4,
  42647. MAX_IMAGES_IN_INLINE_IMAGES_BLOCK);
  42648. if (count < MIN_IMAGES_IN_INLINE_IMAGES_BLOCK) {
  42649. return i;
  42650. }
  42651. // assuming that heights of those image is too small (~1 pixel)
  42652. // packing as much as possible by lines
  42653. var maxX = 0;
  42654. var map = [], maxLineHeight = 0;
  42655. var currentX = IMAGE_PADDING, currentY = IMAGE_PADDING;
  42656. var q;
  42657. for (q = 0; q < count; q++) {
  42658. var transform = argsArray[iFirstTransform + (q << 2)];
  42659. var img = argsArray[iFirstPIIXO + (q << 2)][0];
  42660. if (currentX + img.width > MAX_WIDTH) {
  42661. // starting new line
  42662. maxX = Math.max(maxX, currentX);
  42663. currentY += maxLineHeight + 2 * IMAGE_PADDING;
  42664. currentX = 0;
  42665. maxLineHeight = 0;
  42666. }
  42667. map.push({
  42668. transform: transform,
  42669. x: currentX, y: currentY,
  42670. w: img.width, h: img.height
  42671. });
  42672. currentX += img.width + 2 * IMAGE_PADDING;
  42673. maxLineHeight = Math.max(maxLineHeight, img.height);
  42674. }
  42675. var imgWidth = Math.max(maxX, currentX) + IMAGE_PADDING;
  42676. var imgHeight = currentY + maxLineHeight + IMAGE_PADDING;
  42677. var imgData = new Uint8Array(imgWidth * imgHeight * 4);
  42678. var imgRowSize = imgWidth << 2;
  42679. for (q = 0; q < count; q++) {
  42680. var data = argsArray[iFirstPIIXO + (q << 2)][0].data;
  42681. // Copy image by lines and extends pixels into padding.
  42682. var rowSize = map[q].w << 2;
  42683. var dataOffset = 0;
  42684. var offset = (map[q].x + map[q].y * imgWidth) << 2;
  42685. imgData.set(data.subarray(0, rowSize), offset - imgRowSize);
  42686. for (var k = 0, kk = map[q].h; k < kk; k++) {
  42687. imgData.set(data.subarray(dataOffset, dataOffset + rowSize), offset);
  42688. dataOffset += rowSize;
  42689. offset += imgRowSize;
  42690. }
  42691. imgData.set(data.subarray(dataOffset - rowSize, dataOffset), offset);
  42692. while (offset >= 0) {
  42693. data[offset - 4] = data[offset];
  42694. data[offset - 3] = data[offset + 1];
  42695. data[offset - 2] = data[offset + 2];
  42696. data[offset - 1] = data[offset + 3];
  42697. data[offset + rowSize] = data[offset + rowSize - 4];
  42698. data[offset + rowSize + 1] = data[offset + rowSize - 3];
  42699. data[offset + rowSize + 2] = data[offset + rowSize - 2];
  42700. data[offset + rowSize + 3] = data[offset + rowSize - 1];
  42701. offset -= imgRowSize;
  42702. }
  42703. }
  42704. // Replace queue items.
  42705. fnArray.splice(iFirstSave, count * 4, OPS.paintInlineImageXObjectGroup);
  42706. argsArray.splice(iFirstSave, count * 4,
  42707. [{ width: imgWidth, height: imgHeight, kind: ImageKind.RGBA_32BPP,
  42708. data: imgData }, map]);
  42709. return iFirstSave + 1;
  42710. });
  42711. // This replaces (save, transform, paintImageMaskXObject, restore)+
  42712. // sequences with one |paintImageMaskXObjectGroup| or one
  42713. // |paintImageMaskXObjectRepeat| operation.
  42714. addState(InitialState,
  42715. [OPS.save, OPS.transform, OPS.paintImageMaskXObject, OPS.restore],
  42716. function foundImageMaskGroup(context) {
  42717. var MIN_IMAGES_IN_MASKS_BLOCK = 10;
  42718. var MAX_IMAGES_IN_MASKS_BLOCK = 100;
  42719. var MAX_SAME_IMAGES_IN_MASKS_BLOCK = 1000;
  42720. var fnArray = context.fnArray, argsArray = context.argsArray;
  42721. var curr = context.iCurr;
  42722. var iFirstSave = curr - 3;
  42723. var iFirstTransform = curr - 2;
  42724. var iFirstPIMXO = curr - 1;
  42725. // Look for the quartets.
  42726. var i = iFirstSave + 4;
  42727. var ii = fnArray.length;
  42728. while (i + 3 < ii) {
  42729. if (fnArray[i] !== OPS.save ||
  42730. fnArray[i + 1] !== OPS.transform ||
  42731. fnArray[i + 2] !== OPS.paintImageMaskXObject ||
  42732. fnArray[i + 3] !== OPS.restore) {
  42733. break; // ops don't match
  42734. }
  42735. i += 4;
  42736. }
  42737. // At this point, i is the index of the first op past the last valid
  42738. // quartet.
  42739. var count = (i - iFirstSave) / 4;
  42740. count = handlePaintSolidColorImageMask(iFirstSave, count, fnArray,
  42741. argsArray);
  42742. if (count < MIN_IMAGES_IN_MASKS_BLOCK) {
  42743. return i;
  42744. }
  42745. var q;
  42746. var isSameImage = false;
  42747. var iTransform, transformArgs;
  42748. var firstPIMXOArg0 = argsArray[iFirstPIMXO][0];
  42749. if (argsArray[iFirstTransform][1] === 0 &&
  42750. argsArray[iFirstTransform][2] === 0) {
  42751. isSameImage = true;
  42752. var firstTransformArg0 = argsArray[iFirstTransform][0];
  42753. var firstTransformArg3 = argsArray[iFirstTransform][3];
  42754. iTransform = iFirstTransform + 4;
  42755. var iPIMXO = iFirstPIMXO + 4;
  42756. for (q = 1; q < count; q++, iTransform += 4, iPIMXO += 4) {
  42757. transformArgs = argsArray[iTransform];
  42758. if (argsArray[iPIMXO][0] !== firstPIMXOArg0 ||
  42759. transformArgs[0] !== firstTransformArg0 ||
  42760. transformArgs[1] !== 0 ||
  42761. transformArgs[2] !== 0 ||
  42762. transformArgs[3] !== firstTransformArg3) {
  42763. if (q < MIN_IMAGES_IN_MASKS_BLOCK) {
  42764. isSameImage = false;
  42765. } else {
  42766. count = q;
  42767. }
  42768. break; // different image or transform
  42769. }
  42770. }
  42771. }
  42772. if (isSameImage) {
  42773. count = Math.min(count, MAX_SAME_IMAGES_IN_MASKS_BLOCK);
  42774. var positions = new Float32Array(count * 2);
  42775. iTransform = iFirstTransform;
  42776. for (q = 0; q < count; q++, iTransform += 4) {
  42777. transformArgs = argsArray[iTransform];
  42778. positions[(q << 1)] = transformArgs[4];
  42779. positions[(q << 1) + 1] = transformArgs[5];
  42780. }
  42781. // Replace queue items.
  42782. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectRepeat);
  42783. argsArray.splice(iFirstSave, count * 4,
  42784. [firstPIMXOArg0, firstTransformArg0, firstTransformArg3, positions]);
  42785. } else {
  42786. count = Math.min(count, MAX_IMAGES_IN_MASKS_BLOCK);
  42787. var images = [];
  42788. for (q = 0; q < count; q++) {
  42789. transformArgs = argsArray[iFirstTransform + (q << 2)];
  42790. var maskParams = argsArray[iFirstPIMXO + (q << 2)][0];
  42791. images.push({ data: maskParams.data, width: maskParams.width,
  42792. height: maskParams.height,
  42793. transform: transformArgs });
  42794. }
  42795. // Replace queue items.
  42796. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectGroup);
  42797. argsArray.splice(iFirstSave, count * 4, [images]);
  42798. }
  42799. return iFirstSave + 1;
  42800. });
  42801. // This replaces (save, transform, paintImageXObject, restore)+ sequences
  42802. // with one paintImageXObjectRepeat operation, if the |transform| and
  42803. // |paintImageXObjectRepeat| ops are appropriate.
  42804. addState(InitialState,
  42805. [OPS.save, OPS.transform, OPS.paintImageXObject, OPS.restore],
  42806. function (context) {
  42807. var MIN_IMAGES_IN_BLOCK = 3;
  42808. var MAX_IMAGES_IN_BLOCK = 1000;
  42809. var fnArray = context.fnArray, argsArray = context.argsArray;
  42810. var curr = context.iCurr;
  42811. var iFirstSave = curr - 3;
  42812. var iFirstTransform = curr - 2;
  42813. var iFirstPIXO = curr - 1;
  42814. var iFirstRestore = curr;
  42815. if (argsArray[iFirstTransform][1] !== 0 ||
  42816. argsArray[iFirstTransform][2] !== 0) {
  42817. return iFirstRestore + 1; // transform has the wrong form
  42818. }
  42819. // Look for the quartets.
  42820. var firstPIXOArg0 = argsArray[iFirstPIXO][0];
  42821. var firstTransformArg0 = argsArray[iFirstTransform][0];
  42822. var firstTransformArg3 = argsArray[iFirstTransform][3];
  42823. var i = iFirstSave + 4;
  42824. var ii = fnArray.length;
  42825. while (i + 3 < ii) {
  42826. if (fnArray[i] !== OPS.save ||
  42827. fnArray[i + 1] !== OPS.transform ||
  42828. fnArray[i + 2] !== OPS.paintImageXObject ||
  42829. fnArray[i + 3] !== OPS.restore) {
  42830. break; // ops don't match
  42831. }
  42832. if (argsArray[i + 1][0] !== firstTransformArg0 ||
  42833. argsArray[i + 1][1] !== 0 ||
  42834. argsArray[i + 1][2] !== 0 ||
  42835. argsArray[i + 1][3] !== firstTransformArg3) {
  42836. break; // transforms don't match
  42837. }
  42838. if (argsArray[i + 2][0] !== firstPIXOArg0) {
  42839. break; // images don't match
  42840. }
  42841. i += 4;
  42842. }
  42843. // At this point, i is the index of the first op past the last valid
  42844. // quartet.
  42845. var count = Math.min((i - iFirstSave) / 4, MAX_IMAGES_IN_BLOCK);
  42846. if (count < MIN_IMAGES_IN_BLOCK) {
  42847. return i;
  42848. }
  42849. // Extract the (x,y) positions from all of the matching transforms.
  42850. var positions = new Float32Array(count * 2);
  42851. var iTransform = iFirstTransform;
  42852. for (var q = 0; q < count; q++, iTransform += 4) {
  42853. var transformArgs = argsArray[iTransform];
  42854. positions[(q << 1)] = transformArgs[4];
  42855. positions[(q << 1) + 1] = transformArgs[5];
  42856. }
  42857. // Replace queue items.
  42858. var args = [firstPIXOArg0, firstTransformArg0, firstTransformArg3,
  42859. positions];
  42860. fnArray.splice(iFirstSave, count * 4, OPS.paintImageXObjectRepeat);
  42861. argsArray.splice(iFirstSave, count * 4, args);
  42862. return iFirstSave + 1;
  42863. });
  42864. // This replaces (beginText, setFont, setTextMatrix, showText, endText)+
  42865. // sequences with (beginText, setFont, (setTextMatrix, showText)+, endText)+
  42866. // sequences, if the font for each one is the same.
  42867. addState(InitialState,
  42868. [OPS.beginText, OPS.setFont, OPS.setTextMatrix, OPS.showText, OPS.endText],
  42869. function (context) {
  42870. var MIN_CHARS_IN_BLOCK = 3;
  42871. var MAX_CHARS_IN_BLOCK = 1000;
  42872. var fnArray = context.fnArray, argsArray = context.argsArray;
  42873. var curr = context.iCurr;
  42874. var iFirstBeginText = curr - 4;
  42875. var iFirstSetFont = curr - 3;
  42876. var iFirstSetTextMatrix = curr - 2;
  42877. var iFirstShowText = curr - 1;
  42878. var iFirstEndText = curr;
  42879. // Look for the quintets.
  42880. var firstSetFontArg0 = argsArray[iFirstSetFont][0];
  42881. var firstSetFontArg1 = argsArray[iFirstSetFont][1];
  42882. var i = iFirstBeginText + 5;
  42883. var ii = fnArray.length;
  42884. while (i + 4 < ii) {
  42885. if (fnArray[i] !== OPS.beginText ||
  42886. fnArray[i + 1] !== OPS.setFont ||
  42887. fnArray[i + 2] !== OPS.setTextMatrix ||
  42888. fnArray[i + 3] !== OPS.showText ||
  42889. fnArray[i + 4] !== OPS.endText) {
  42890. break; // ops don't match
  42891. }
  42892. if (argsArray[i + 1][0] !== firstSetFontArg0 ||
  42893. argsArray[i + 1][1] !== firstSetFontArg1) {
  42894. break; // fonts don't match
  42895. }
  42896. i += 5;
  42897. }
  42898. // At this point, i is the index of the first op past the last valid
  42899. // quintet.
  42900. var count = Math.min(((i - iFirstBeginText) / 5), MAX_CHARS_IN_BLOCK);
  42901. if (count < MIN_CHARS_IN_BLOCK) {
  42902. return i;
  42903. }
  42904. // If the preceding quintet is (<something>, setFont, setTextMatrix,
  42905. // showText, endText), include that as well. (E.g. <something> might be
  42906. // |dependency|.)
  42907. var iFirst = iFirstBeginText;
  42908. if (iFirstBeginText >= 4 &&
  42909. fnArray[iFirstBeginText - 4] === fnArray[iFirstSetFont] &&
  42910. fnArray[iFirstBeginText - 3] === fnArray[iFirstSetTextMatrix] &&
  42911. fnArray[iFirstBeginText - 2] === fnArray[iFirstShowText] &&
  42912. fnArray[iFirstBeginText - 1] === fnArray[iFirstEndText] &&
  42913. argsArray[iFirstBeginText - 4][0] === firstSetFontArg0 &&
  42914. argsArray[iFirstBeginText - 4][1] === firstSetFontArg1) {
  42915. count++;
  42916. iFirst -= 5;
  42917. }
  42918. // Remove (endText, beginText, setFont) trios.
  42919. var iEndText = iFirst + 4;
  42920. for (var q = 1; q < count; q++) {
  42921. fnArray.splice(iEndText, 3);
  42922. argsArray.splice(iEndText, 3);
  42923. iEndText += 2;
  42924. }
  42925. return iEndText + 1;
  42926. });
  42927. function QueueOptimizer() {}
  42928. QueueOptimizer.prototype = {
  42929. optimize: function QueueOptimizer_optimize(queue) {
  42930. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  42931. var context = {
  42932. iCurr: 0,
  42933. fnArray: fnArray,
  42934. argsArray: argsArray
  42935. };
  42936. var state;
  42937. var i = 0, ii = fnArray.length;
  42938. while (i < ii) {
  42939. state = (state || InitialState)[fnArray[i]];
  42940. if (typeof state === 'function') { // we found some handler
  42941. context.iCurr = i;
  42942. // state() returns the index of the first non-matching op (if we
  42943. // didn't match) or the first op past the modified ops (if we did
  42944. // match and replace).
  42945. i = state(context);
  42946. state = undefined; // reset the state machine
  42947. ii = context.fnArray.length;
  42948. } else {
  42949. i++;
  42950. }
  42951. }
  42952. }
  42953. };
  42954. return QueueOptimizer;
  42955. })();
  42956. exports.OperatorList = OperatorList;
  42957. exports.PartialEvaluator = PartialEvaluator;
  42958. }));
  42959. (function (root, factory) {
  42960. {
  42961. factory((root.pdfjsCoreAnnotation = {}), root.pdfjsSharedUtil,
  42962. root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreColorSpace,
  42963. root.pdfjsCoreObj, root.pdfjsCoreEvaluator);
  42964. }
  42965. }(this, function (exports, sharedUtil, corePrimitives, coreStream,
  42966. coreColorSpace, coreObj, coreEvaluator) {
  42967. var AnnotationBorderStyleType = sharedUtil.AnnotationBorderStyleType;
  42968. var AnnotationFlag = sharedUtil.AnnotationFlag;
  42969. var AnnotationType = sharedUtil.AnnotationType;
  42970. var OPS = sharedUtil.OPS;
  42971. var Util = sharedUtil.Util;
  42972. var isArray = sharedUtil.isArray;
  42973. var isInt = sharedUtil.isInt;
  42974. var isValidUrl = sharedUtil.isValidUrl;
  42975. var stringToBytes = sharedUtil.stringToBytes;
  42976. var stringToPDFString = sharedUtil.stringToPDFString;
  42977. var stringToUTF8String = sharedUtil.stringToUTF8String;
  42978. var warn = sharedUtil.warn;
  42979. var Dict = corePrimitives.Dict;
  42980. var isDict = corePrimitives.isDict;
  42981. var isName = corePrimitives.isName;
  42982. var Stream = coreStream.Stream;
  42983. var ColorSpace = coreColorSpace.ColorSpace;
  42984. var ObjectLoader = coreObj.ObjectLoader;
  42985. var OperatorList = coreEvaluator.OperatorList;
  42986. var DEFAULT_ICON_SIZE = 22; // px
  42987. /**
  42988. * @class
  42989. * @alias AnnotationFactory
  42990. */
  42991. function AnnotationFactory() {}
  42992. AnnotationFactory.prototype = /** @lends AnnotationFactory.prototype */ {
  42993. /**
  42994. * @param {XRef} xref
  42995. * @param {Object} ref
  42996. * @returns {Annotation}
  42997. */
  42998. create: function AnnotationFactory_create(xref, ref) {
  42999. var dict = xref.fetchIfRef(ref);
  43000. if (!isDict(dict)) {
  43001. return;
  43002. }
  43003. // Determine the annotation's subtype.
  43004. var subtype = dict.get('Subtype');
  43005. subtype = isName(subtype) ? subtype.name : '';
  43006. // Return the right annotation object based on the subtype and field type.
  43007. var parameters = {
  43008. dict: dict,
  43009. ref: ref
  43010. };
  43011. switch (subtype) {
  43012. case 'Link':
  43013. return new LinkAnnotation(parameters);
  43014. case 'Text':
  43015. return new TextAnnotation(parameters);
  43016. case 'Widget':
  43017. var fieldType = Util.getInheritableProperty(dict, 'FT');
  43018. if (isName(fieldType) && fieldType.name === 'Tx') {
  43019. return new TextWidgetAnnotation(parameters);
  43020. }
  43021. return new WidgetAnnotation(parameters);
  43022. default:
  43023. warn('Unimplemented annotation type "' + subtype + '", ' +
  43024. 'falling back to base annotation');
  43025. return new Annotation(parameters);
  43026. }
  43027. }
  43028. };
  43029. var Annotation = (function AnnotationClosure() {
  43030. // 12.5.5: Algorithm: Appearance streams
  43031. function getTransformMatrix(rect, bbox, matrix) {
  43032. var bounds = Util.getAxialAlignedBoundingBox(bbox, matrix);
  43033. var minX = bounds[0];
  43034. var minY = bounds[1];
  43035. var maxX = bounds[2];
  43036. var maxY = bounds[3];
  43037. if (minX === maxX || minY === maxY) {
  43038. // From real-life file, bbox was [0, 0, 0, 0]. In this case,
  43039. // just apply the transform for rect
  43040. return [1, 0, 0, 1, rect[0], rect[1]];
  43041. }
  43042. var xRatio = (rect[2] - rect[0]) / (maxX - minX);
  43043. var yRatio = (rect[3] - rect[1]) / (maxY - minY);
  43044. return [
  43045. xRatio,
  43046. 0,
  43047. 0,
  43048. yRatio,
  43049. rect[0] - minX * xRatio,
  43050. rect[1] - minY * yRatio
  43051. ];
  43052. }
  43053. function getDefaultAppearance(dict) {
  43054. var appearanceState = dict.get('AP');
  43055. if (!isDict(appearanceState)) {
  43056. return;
  43057. }
  43058. var appearance;
  43059. var appearances = appearanceState.get('N');
  43060. if (isDict(appearances)) {
  43061. var as = dict.get('AS');
  43062. if (as && appearances.has(as.name)) {
  43063. appearance = appearances.get(as.name);
  43064. }
  43065. } else {
  43066. appearance = appearances;
  43067. }
  43068. return appearance;
  43069. }
  43070. function Annotation(params) {
  43071. var dict = params.dict;
  43072. this.setFlags(dict.get('F'));
  43073. this.setRectangle(dict.get('Rect'));
  43074. this.setColor(dict.get('C'));
  43075. this.setBorderStyle(dict);
  43076. this.appearance = getDefaultAppearance(dict);
  43077. // Expose public properties using a data object.
  43078. this.data = {};
  43079. this.data.id = params.ref.num;
  43080. this.data.subtype = dict.get('Subtype').name;
  43081. this.data.annotationFlags = this.flags;
  43082. this.data.rect = this.rectangle;
  43083. this.data.color = this.color;
  43084. this.data.borderStyle = this.borderStyle;
  43085. this.data.hasAppearance = !!this.appearance;
  43086. }
  43087. Annotation.prototype = {
  43088. /**
  43089. * @return {boolean}
  43090. */
  43091. get viewable() {
  43092. if (this.flags) {
  43093. return !this.hasFlag(AnnotationFlag.INVISIBLE) &&
  43094. !this.hasFlag(AnnotationFlag.HIDDEN) &&
  43095. !this.hasFlag(AnnotationFlag.NOVIEW);
  43096. }
  43097. return true;
  43098. },
  43099. /**
  43100. * @return {boolean}
  43101. */
  43102. get printable() {
  43103. if (this.flags) {
  43104. return this.hasFlag(AnnotationFlag.PRINT) &&
  43105. !this.hasFlag(AnnotationFlag.INVISIBLE) &&
  43106. !this.hasFlag(AnnotationFlag.HIDDEN);
  43107. }
  43108. return false;
  43109. },
  43110. /**
  43111. * Set the flags.
  43112. *
  43113. * @public
  43114. * @memberof Annotation
  43115. * @param {number} flags - Unsigned 32-bit integer specifying annotation
  43116. * characteristics
  43117. * @see {@link shared/util.js}
  43118. */
  43119. setFlags: function Annotation_setFlags(flags) {
  43120. if (isInt(flags)) {
  43121. this.flags = flags;
  43122. } else {
  43123. this.flags = 0;
  43124. }
  43125. },
  43126. /**
  43127. * Check if a provided flag is set.
  43128. *
  43129. * @public
  43130. * @memberof Annotation
  43131. * @param {number} flag - Hexadecimal representation for an annotation
  43132. * characteristic
  43133. * @return {boolean}
  43134. * @see {@link shared/util.js}
  43135. */
  43136. hasFlag: function Annotation_hasFlag(flag) {
  43137. if (this.flags) {
  43138. return (this.flags & flag) > 0;
  43139. }
  43140. return false;
  43141. },
  43142. /**
  43143. * Set the rectangle.
  43144. *
  43145. * @public
  43146. * @memberof Annotation
  43147. * @param {Array} rectangle - The rectangle array with exactly four entries
  43148. */
  43149. setRectangle: function Annotation_setRectangle(rectangle) {
  43150. if (isArray(rectangle) && rectangle.length === 4) {
  43151. this.rectangle = Util.normalizeRect(rectangle);
  43152. } else {
  43153. this.rectangle = [0, 0, 0, 0];
  43154. }
  43155. },
  43156. /**
  43157. * Set the color and take care of color space conversion.
  43158. *
  43159. * @public
  43160. * @memberof Annotation
  43161. * @param {Array} color - The color array containing either 0
  43162. * (transparent), 1 (grayscale), 3 (RGB) or
  43163. * 4 (CMYK) elements
  43164. */
  43165. setColor: function Annotation_setColor(color) {
  43166. var rgbColor = new Uint8Array(3); // Black in RGB color space (default)
  43167. if (!isArray(color)) {
  43168. this.color = rgbColor;
  43169. return;
  43170. }
  43171. switch (color.length) {
  43172. case 0: // Transparent, which we indicate with a null value
  43173. this.color = null;
  43174. break;
  43175. case 1: // Convert grayscale to RGB
  43176. ColorSpace.singletons.gray.getRgbItem(color, 0, rgbColor, 0);
  43177. this.color = rgbColor;
  43178. break;
  43179. case 3: // Convert RGB percentages to RGB
  43180. ColorSpace.singletons.rgb.getRgbItem(color, 0, rgbColor, 0);
  43181. this.color = rgbColor;
  43182. break;
  43183. case 4: // Convert CMYK to RGB
  43184. ColorSpace.singletons.cmyk.getRgbItem(color, 0, rgbColor, 0);
  43185. this.color = rgbColor;
  43186. break;
  43187. default:
  43188. this.color = rgbColor;
  43189. break;
  43190. }
  43191. },
  43192. /**
  43193. * Set the border style (as AnnotationBorderStyle object).
  43194. *
  43195. * @public
  43196. * @memberof Annotation
  43197. * @param {Dict} borderStyle - The border style dictionary
  43198. */
  43199. setBorderStyle: function Annotation_setBorderStyle(borderStyle) {
  43200. this.borderStyle = new AnnotationBorderStyle();
  43201. if (!isDict(borderStyle)) {
  43202. return;
  43203. }
  43204. if (borderStyle.has('BS')) {
  43205. var dict = borderStyle.get('BS');
  43206. var dictType;
  43207. if (!dict.has('Type') || (isName(dictType = dict.get('Type')) &&
  43208. dictType.name === 'Border')) {
  43209. this.borderStyle.setWidth(dict.get('W'));
  43210. this.borderStyle.setStyle(dict.get('S'));
  43211. this.borderStyle.setDashArray(dict.get('D'));
  43212. }
  43213. } else if (borderStyle.has('Border')) {
  43214. var array = borderStyle.get('Border');
  43215. if (isArray(array) && array.length >= 3) {
  43216. this.borderStyle.setHorizontalCornerRadius(array[0]);
  43217. this.borderStyle.setVerticalCornerRadius(array[1]);
  43218. this.borderStyle.setWidth(array[2]);
  43219. if (array.length === 4) { // Dash array available
  43220. this.borderStyle.setDashArray(array[3]);
  43221. }
  43222. }
  43223. } else {
  43224. // There are no border entries in the dictionary. According to the
  43225. // specification, we should draw a solid border of width 1 in that
  43226. // case, but Adobe Reader did not implement that part of the
  43227. // specification and instead draws no border at all, so we do the same.
  43228. // See also https://github.com/mozilla/pdf.js/issues/6179.
  43229. this.borderStyle.setWidth(0);
  43230. }
  43231. },
  43232. loadResources: function Annotation_loadResources(keys) {
  43233. return new Promise(function (resolve, reject) {
  43234. this.appearance.dict.getAsync('Resources').then(function (resources) {
  43235. if (!resources) {
  43236. resolve();
  43237. return;
  43238. }
  43239. var objectLoader = new ObjectLoader(resources.map,
  43240. keys,
  43241. resources.xref);
  43242. objectLoader.load().then(function() {
  43243. resolve(resources);
  43244. }, reject);
  43245. }, reject);
  43246. }.bind(this));
  43247. },
  43248. getOperatorList: function Annotation_getOperatorList(evaluator, task) {
  43249. if (!this.appearance) {
  43250. return Promise.resolve(new OperatorList());
  43251. }
  43252. var data = this.data;
  43253. var appearanceDict = this.appearance.dict;
  43254. var resourcesPromise = this.loadResources([
  43255. 'ExtGState',
  43256. 'ColorSpace',
  43257. 'Pattern',
  43258. 'Shading',
  43259. 'XObject',
  43260. 'Font'
  43261. // ProcSet
  43262. // Properties
  43263. ]);
  43264. var bbox = appearanceDict.get('BBox') || [0, 0, 1, 1];
  43265. var matrix = appearanceDict.get('Matrix') || [1, 0, 0, 1, 0 ,0];
  43266. var transform = getTransformMatrix(data.rect, bbox, matrix);
  43267. var self = this;
  43268. return resourcesPromise.then(function(resources) {
  43269. var opList = new OperatorList();
  43270. opList.addOp(OPS.beginAnnotation, [data.rect, transform, matrix]);
  43271. return evaluator.getOperatorList(self.appearance, task,
  43272. resources, opList).
  43273. then(function () {
  43274. opList.addOp(OPS.endAnnotation, []);
  43275. self.appearance.reset();
  43276. return opList;
  43277. });
  43278. });
  43279. }
  43280. };
  43281. Annotation.appendToOperatorList = function Annotation_appendToOperatorList(
  43282. annotations, opList, partialEvaluator, task, intent) {
  43283. var annotationPromises = [];
  43284. for (var i = 0, n = annotations.length; i < n; ++i) {
  43285. if ((intent === 'display' && annotations[i].viewable) ||
  43286. (intent === 'print' && annotations[i].printable)) {
  43287. annotationPromises.push(
  43288. annotations[i].getOperatorList(partialEvaluator, task));
  43289. }
  43290. }
  43291. return Promise.all(annotationPromises).then(function(operatorLists) {
  43292. opList.addOp(OPS.beginAnnotations, []);
  43293. for (var i = 0, n = operatorLists.length; i < n; ++i) {
  43294. opList.addOpList(operatorLists[i]);
  43295. }
  43296. opList.addOp(OPS.endAnnotations, []);
  43297. });
  43298. };
  43299. return Annotation;
  43300. })();
  43301. /**
  43302. * Contains all data regarding an annotation's border style.
  43303. *
  43304. * @class
  43305. */
  43306. var AnnotationBorderStyle = (function AnnotationBorderStyleClosure() {
  43307. /**
  43308. * @constructor
  43309. * @private
  43310. */
  43311. function AnnotationBorderStyle() {
  43312. this.width = 1;
  43313. this.style = AnnotationBorderStyleType.SOLID;
  43314. this.dashArray = [3];
  43315. this.horizontalCornerRadius = 0;
  43316. this.verticalCornerRadius = 0;
  43317. }
  43318. AnnotationBorderStyle.prototype = {
  43319. /**
  43320. * Set the width.
  43321. *
  43322. * @public
  43323. * @memberof AnnotationBorderStyle
  43324. * @param {integer} width - The width
  43325. */
  43326. setWidth: function AnnotationBorderStyle_setWidth(width) {
  43327. if (width === (width | 0)) {
  43328. this.width = width;
  43329. }
  43330. },
  43331. /**
  43332. * Set the style.
  43333. *
  43334. * @public
  43335. * @memberof AnnotationBorderStyle
  43336. * @param {Object} style - The style object
  43337. * @see {@link shared/util.js}
  43338. */
  43339. setStyle: function AnnotationBorderStyle_setStyle(style) {
  43340. if (!style) {
  43341. return;
  43342. }
  43343. switch (style.name) {
  43344. case 'S':
  43345. this.style = AnnotationBorderStyleType.SOLID;
  43346. break;
  43347. case 'D':
  43348. this.style = AnnotationBorderStyleType.DASHED;
  43349. break;
  43350. case 'B':
  43351. this.style = AnnotationBorderStyleType.BEVELED;
  43352. break;
  43353. case 'I':
  43354. this.style = AnnotationBorderStyleType.INSET;
  43355. break;
  43356. case 'U':
  43357. this.style = AnnotationBorderStyleType.UNDERLINE;
  43358. break;
  43359. default:
  43360. break;
  43361. }
  43362. },
  43363. /**
  43364. * Set the dash array.
  43365. *
  43366. * @public
  43367. * @memberof AnnotationBorderStyle
  43368. * @param {Array} dashArray - The dash array with at least one element
  43369. */
  43370. setDashArray: function AnnotationBorderStyle_setDashArray(dashArray) {
  43371. // We validate the dash array, but we do not use it because CSS does not
  43372. // allow us to change spacing of dashes. For more information, visit
  43373. // http://www.w3.org/TR/css3-background/#the-border-style.
  43374. if (isArray(dashArray) && dashArray.length > 0) {
  43375. // According to the PDF specification: the elements in a dashArray
  43376. // shall be numbers that are nonnegative and not all equal to zero.
  43377. var isValid = true;
  43378. var allZeros = true;
  43379. for (var i = 0, len = dashArray.length; i < len; i++) {
  43380. var element = dashArray[i];
  43381. var validNumber = (+element >= 0);
  43382. if (!validNumber) {
  43383. isValid = false;
  43384. break;
  43385. } else if (element > 0) {
  43386. allZeros = false;
  43387. }
  43388. }
  43389. if (isValid && !allZeros) {
  43390. this.dashArray = dashArray;
  43391. } else {
  43392. this.width = 0; // Adobe behavior when the array is invalid.
  43393. }
  43394. } else if (dashArray) {
  43395. this.width = 0; // Adobe behavior when the array is invalid.
  43396. }
  43397. },
  43398. /**
  43399. * Set the horizontal corner radius (from a Border dictionary).
  43400. *
  43401. * @public
  43402. * @memberof AnnotationBorderStyle
  43403. * @param {integer} radius - The horizontal corner radius
  43404. */
  43405. setHorizontalCornerRadius:
  43406. function AnnotationBorderStyle_setHorizontalCornerRadius(radius) {
  43407. if (radius === (radius | 0)) {
  43408. this.horizontalCornerRadius = radius;
  43409. }
  43410. },
  43411. /**
  43412. * Set the vertical corner radius (from a Border dictionary).
  43413. *
  43414. * @public
  43415. * @memberof AnnotationBorderStyle
  43416. * @param {integer} radius - The vertical corner radius
  43417. */
  43418. setVerticalCornerRadius:
  43419. function AnnotationBorderStyle_setVerticalCornerRadius(radius) {
  43420. if (radius === (radius | 0)) {
  43421. this.verticalCornerRadius = radius;
  43422. }
  43423. }
  43424. };
  43425. return AnnotationBorderStyle;
  43426. })();
  43427. var WidgetAnnotation = (function WidgetAnnotationClosure() {
  43428. function WidgetAnnotation(params) {
  43429. Annotation.call(this, params);
  43430. var dict = params.dict;
  43431. var data = this.data;
  43432. data.annotationType = AnnotationType.WIDGET;
  43433. data.fieldValue = stringToPDFString(
  43434. Util.getInheritableProperty(dict, 'V') || '');
  43435. data.alternativeText = stringToPDFString(dict.get('TU') || '');
  43436. data.defaultAppearance = Util.getInheritableProperty(dict, 'DA') || '';
  43437. var fieldType = Util.getInheritableProperty(dict, 'FT');
  43438. data.fieldType = isName(fieldType) ? fieldType.name : '';
  43439. data.fieldFlags = Util.getInheritableProperty(dict, 'Ff') || 0;
  43440. this.fieldResources = Util.getInheritableProperty(dict, 'DR') || Dict.empty;
  43441. // Hide unsupported Widget signatures.
  43442. if (data.fieldType === 'Sig') {
  43443. warn('unimplemented annotation type: Widget signature');
  43444. this.setFlags(AnnotationFlag.HIDDEN);
  43445. }
  43446. // Building the full field name by collecting the field and
  43447. // its ancestors 'T' data and joining them using '.'.
  43448. var fieldName = [];
  43449. var namedItem = dict;
  43450. var ref = params.ref;
  43451. while (namedItem) {
  43452. var parent = namedItem.get('Parent');
  43453. var parentRef = namedItem.getRaw('Parent');
  43454. var name = namedItem.get('T');
  43455. if (name) {
  43456. fieldName.unshift(stringToPDFString(name));
  43457. } else if (parent && ref) {
  43458. // The field name is absent, that means more than one field
  43459. // with the same name may exist. Replacing the empty name
  43460. // with the '`' plus index in the parent's 'Kids' array.
  43461. // This is not in the PDF spec but necessary to id the
  43462. // the input controls.
  43463. var kids = parent.get('Kids');
  43464. var j, jj;
  43465. for (j = 0, jj = kids.length; j < jj; j++) {
  43466. var kidRef = kids[j];
  43467. if (kidRef.num === ref.num && kidRef.gen === ref.gen) {
  43468. break;
  43469. }
  43470. }
  43471. fieldName.unshift('`' + j);
  43472. }
  43473. namedItem = parent;
  43474. ref = parentRef;
  43475. }
  43476. data.fullName = fieldName.join('.');
  43477. }
  43478. Util.inherit(WidgetAnnotation, Annotation, {});
  43479. return WidgetAnnotation;
  43480. })();
  43481. var TextWidgetAnnotation = (function TextWidgetAnnotationClosure() {
  43482. function TextWidgetAnnotation(params) {
  43483. WidgetAnnotation.call(this, params);
  43484. this.data.textAlignment = Util.getInheritableProperty(params.dict, 'Q');
  43485. this.data.hasHtml = !this.data.hasAppearance && !!this.data.fieldValue;
  43486. }
  43487. Util.inherit(TextWidgetAnnotation, WidgetAnnotation, {
  43488. getOperatorList: function TextWidgetAnnotation_getOperatorList(evaluator,
  43489. task) {
  43490. if (this.appearance) {
  43491. return Annotation.prototype.getOperatorList.call(this, evaluator, task);
  43492. }
  43493. var opList = new OperatorList();
  43494. var data = this.data;
  43495. // Even if there is an appearance stream, ignore it. This is the
  43496. // behaviour used by Adobe Reader.
  43497. if (!data.defaultAppearance) {
  43498. return Promise.resolve(opList);
  43499. }
  43500. var stream = new Stream(stringToBytes(data.defaultAppearance));
  43501. return evaluator.getOperatorList(stream, task,
  43502. this.fieldResources, opList).
  43503. then(function () {
  43504. return opList;
  43505. });
  43506. }
  43507. });
  43508. return TextWidgetAnnotation;
  43509. })();
  43510. var TextAnnotation = (function TextAnnotationClosure() {
  43511. function TextAnnotation(params) {
  43512. Annotation.call(this, params);
  43513. var dict = params.dict;
  43514. var data = this.data;
  43515. var content = dict.get('Contents');
  43516. var title = dict.get('T');
  43517. data.annotationType = AnnotationType.TEXT;
  43518. data.content = stringToPDFString(content || '');
  43519. data.title = stringToPDFString(title || '');
  43520. data.hasHtml = true;
  43521. if (data.hasAppearance) {
  43522. data.name = 'NoIcon';
  43523. } else {
  43524. data.rect[1] = data.rect[3] - DEFAULT_ICON_SIZE;
  43525. data.rect[2] = data.rect[0] + DEFAULT_ICON_SIZE;
  43526. data.name = dict.has('Name') ? dict.get('Name').name : 'Note';
  43527. }
  43528. if (dict.has('C')) {
  43529. data.hasBgColor = true;
  43530. }
  43531. }
  43532. Util.inherit(TextAnnotation, Annotation, {});
  43533. return TextAnnotation;
  43534. })();
  43535. var LinkAnnotation = (function LinkAnnotationClosure() {
  43536. function LinkAnnotation(params) {
  43537. Annotation.call(this, params);
  43538. var dict = params.dict;
  43539. var data = this.data;
  43540. data.annotationType = AnnotationType.LINK;
  43541. data.hasHtml = true;
  43542. var action = dict.get('A');
  43543. if (action && isDict(action)) {
  43544. var linkType = action.get('S').name;
  43545. if (linkType === 'URI') {
  43546. var url = action.get('URI');
  43547. if (isName(url)) {
  43548. // Some bad PDFs do not put parentheses around relative URLs.
  43549. url = '/' + url.name;
  43550. } else if (url) {
  43551. url = addDefaultProtocolToUrl(url);
  43552. }
  43553. // TODO: pdf spec mentions urls can be relative to a Base
  43554. // entry in the dictionary.
  43555. if (!isValidUrl(url, false)) {
  43556. url = '';
  43557. }
  43558. // According to ISO 32000-1:2008, section 12.6.4.7,
  43559. // URI should to be encoded in 7-bit ASCII.
  43560. // Some bad PDFs may have URIs in UTF-8 encoding, see Bugzilla 1122280.
  43561. try {
  43562. data.url = stringToUTF8String(url);
  43563. } catch (e) {
  43564. // Fall back to a simple copy.
  43565. data.url = url;
  43566. }
  43567. } else if (linkType === 'GoTo') {
  43568. data.dest = action.get('D');
  43569. } else if (linkType === 'GoToR') {
  43570. var urlDict = action.get('F');
  43571. if (isDict(urlDict)) {
  43572. // We assume that the 'url' is a Filspec dictionary
  43573. // and fetch the url without checking any further
  43574. url = urlDict.get('F') || '';
  43575. }
  43576. // TODO: pdf reference says that GoToR
  43577. // can also have 'NewWindow' attribute
  43578. if (!isValidUrl(url, false)) {
  43579. url = '';
  43580. }
  43581. data.url = url;
  43582. data.dest = action.get('D');
  43583. } else if (linkType === 'Named') {
  43584. data.action = action.get('N').name;
  43585. } else {
  43586. warn('unrecognized link type: ' + linkType);
  43587. }
  43588. } else if (dict.has('Dest')) {
  43589. // simple destination link
  43590. var dest = dict.get('Dest');
  43591. data.dest = isName(dest) ? dest.name : dest;
  43592. }
  43593. }
  43594. // Lets URLs beginning with 'www.' default to using the 'http://' protocol.
  43595. function addDefaultProtocolToUrl(url) {
  43596. if (url && url.indexOf('www.') === 0) {
  43597. return ('http://' + url);
  43598. }
  43599. return url;
  43600. }
  43601. Util.inherit(LinkAnnotation, Annotation, {});
  43602. return LinkAnnotation;
  43603. })();
  43604. exports.Annotation = Annotation;
  43605. exports.AnnotationBorderStyle = AnnotationBorderStyle;
  43606. exports.AnnotationFactory = AnnotationFactory;
  43607. }));
  43608. (function (root, factory) {
  43609. {
  43610. factory((root.pdfjsCoreDocument = {}), root.pdfjsSharedUtil,
  43611. root.pdfjsCorePrimitives, root.pdfjsCoreStream,
  43612. root.pdfjsCoreObj, root.pdfjsCoreParser, root.pdfjsCoreCrypto,
  43613. root.pdfjsCoreEvaluator, root.pdfjsCoreAnnotation);
  43614. }
  43615. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreObj,
  43616. coreParser, coreCrypto, coreEvaluator, coreAnnotation) {
  43617. var MissingDataException = sharedUtil.MissingDataException;
  43618. var Util = sharedUtil.Util;
  43619. var assert = sharedUtil.assert;
  43620. var error = sharedUtil.error;
  43621. var info = sharedUtil.info;
  43622. var isArray = sharedUtil.isArray;
  43623. var isArrayBuffer = sharedUtil.isArrayBuffer;
  43624. var isString = sharedUtil.isString;
  43625. var shadow = sharedUtil.shadow;
  43626. var stringToBytes = sharedUtil.stringToBytes;
  43627. var stringToPDFString = sharedUtil.stringToPDFString;
  43628. var warn = sharedUtil.warn;
  43629. var Dict = corePrimitives.Dict;
  43630. var isDict = corePrimitives.isDict;
  43631. var isName = corePrimitives.isName;
  43632. var isStream = corePrimitives.isStream;
  43633. var NullStream = coreStream.NullStream;
  43634. var Stream = coreStream.Stream;
  43635. var StreamsSequenceStream = coreStream.StreamsSequenceStream;
  43636. var Catalog = coreObj.Catalog;
  43637. var ObjectLoader = coreObj.ObjectLoader;
  43638. var XRef = coreObj.XRef;
  43639. var Lexer = coreParser.Lexer;
  43640. var Linearization = coreParser.Linearization;
  43641. var calculateMD5 = coreCrypto.calculateMD5;
  43642. var OperatorList = coreEvaluator.OperatorList;
  43643. var PartialEvaluator = coreEvaluator.PartialEvaluator;
  43644. var Annotation = coreAnnotation.Annotation;
  43645. var AnnotationFactory = coreAnnotation.AnnotationFactory;
  43646. var Page = (function PageClosure() {
  43647. var LETTER_SIZE_MEDIABOX = [0, 0, 612, 792];
  43648. function Page(pdfManager, xref, pageIndex, pageDict, ref, fontCache) {
  43649. this.pdfManager = pdfManager;
  43650. this.pageIndex = pageIndex;
  43651. this.pageDict = pageDict;
  43652. this.xref = xref;
  43653. this.ref = ref;
  43654. this.fontCache = fontCache;
  43655. this.idCounters = {
  43656. obj: 0
  43657. };
  43658. this.resourcesPromise = null;
  43659. }
  43660. Page.prototype = {
  43661. getPageProp: function Page_getPageProp(key) {
  43662. return this.pageDict.get(key);
  43663. },
  43664. getInheritedPageProp: function Page_getInheritedPageProp(key) {
  43665. var dict = this.pageDict, valueArray = null, loopCount = 0;
  43666. var MAX_LOOP_COUNT = 100;
  43667. // Always walk up the entire parent chain, to be able to find
  43668. // e.g. \Resources placed on multiple levels of the tree.
  43669. while (dict) {
  43670. var value = dict.get(key);
  43671. if (value) {
  43672. if (!valueArray) {
  43673. valueArray = [];
  43674. }
  43675. valueArray.push(value);
  43676. }
  43677. if (++loopCount > MAX_LOOP_COUNT) {
  43678. warn('Page_getInheritedPageProp: maximum loop count exceeded.');
  43679. break;
  43680. }
  43681. dict = dict.get('Parent');
  43682. }
  43683. if (!valueArray) {
  43684. return Dict.empty;
  43685. }
  43686. if (valueArray.length === 1 || !isDict(valueArray[0]) ||
  43687. loopCount > MAX_LOOP_COUNT) {
  43688. return valueArray[0];
  43689. }
  43690. return Dict.merge(this.xref, valueArray);
  43691. },
  43692. get content() {
  43693. return this.getPageProp('Contents');
  43694. },
  43695. get resources() {
  43696. // For robustness: The spec states that a \Resources entry has to be
  43697. // present, but can be empty. Some document omit it still, in this case
  43698. // we return an empty dictionary.
  43699. return shadow(this, 'resources', this.getInheritedPageProp('Resources'));
  43700. },
  43701. get mediaBox() {
  43702. var obj = this.getInheritedPageProp('MediaBox');
  43703. // Reset invalid media box to letter size.
  43704. if (!isArray(obj) || obj.length !== 4) {
  43705. obj = LETTER_SIZE_MEDIABOX;
  43706. }
  43707. return shadow(this, 'mediaBox', obj);
  43708. },
  43709. get view() {
  43710. var mediaBox = this.mediaBox;
  43711. var cropBox = this.getInheritedPageProp('CropBox');
  43712. if (!isArray(cropBox) || cropBox.length !== 4) {
  43713. return shadow(this, 'view', mediaBox);
  43714. }
  43715. // From the spec, 6th ed., p.963:
  43716. // "The crop, bleed, trim, and art boxes should not ordinarily
  43717. // extend beyond the boundaries of the media box. If they do, they are
  43718. // effectively reduced to their intersection with the media box."
  43719. cropBox = Util.intersect(cropBox, mediaBox);
  43720. if (!cropBox) {
  43721. return shadow(this, 'view', mediaBox);
  43722. }
  43723. return shadow(this, 'view', cropBox);
  43724. },
  43725. get rotate() {
  43726. var rotate = this.getInheritedPageProp('Rotate') || 0;
  43727. // Normalize rotation so it's a multiple of 90 and between 0 and 270
  43728. if (rotate % 90 !== 0) {
  43729. rotate = 0;
  43730. } else if (rotate >= 360) {
  43731. rotate = rotate % 360;
  43732. } else if (rotate < 0) {
  43733. // The spec doesn't cover negatives, assume its counterclockwise
  43734. // rotation. The following is the other implementation of modulo.
  43735. rotate = ((rotate % 360) + 360) % 360;
  43736. }
  43737. return shadow(this, 'rotate', rotate);
  43738. },
  43739. getContentStream: function Page_getContentStream() {
  43740. var content = this.content;
  43741. var stream;
  43742. if (isArray(content)) {
  43743. // fetching items
  43744. var xref = this.xref;
  43745. var i, n = content.length;
  43746. var streams = [];
  43747. for (i = 0; i < n; ++i) {
  43748. streams.push(xref.fetchIfRef(content[i]));
  43749. }
  43750. stream = new StreamsSequenceStream(streams);
  43751. } else if (isStream(content)) {
  43752. stream = content;
  43753. } else {
  43754. // replacing non-existent page content with empty one
  43755. stream = new NullStream();
  43756. }
  43757. return stream;
  43758. },
  43759. loadResources: function Page_loadResources(keys) {
  43760. if (!this.resourcesPromise) {
  43761. // TODO: add async getInheritedPageProp and remove this.
  43762. this.resourcesPromise = this.pdfManager.ensure(this, 'resources');
  43763. }
  43764. return this.resourcesPromise.then(function resourceSuccess() {
  43765. var objectLoader = new ObjectLoader(this.resources.map,
  43766. keys,
  43767. this.xref);
  43768. return objectLoader.load();
  43769. }.bind(this));
  43770. },
  43771. getOperatorList: function Page_getOperatorList(handler, task, intent) {
  43772. var self = this;
  43773. var pdfManager = this.pdfManager;
  43774. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
  43775. []);
  43776. var resourcesPromise = this.loadResources([
  43777. 'ExtGState',
  43778. 'ColorSpace',
  43779. 'Pattern',
  43780. 'Shading',
  43781. 'XObject',
  43782. 'Font'
  43783. // ProcSet
  43784. // Properties
  43785. ]);
  43786. var partialEvaluator = new PartialEvaluator(pdfManager, this.xref,
  43787. handler, this.pageIndex,
  43788. 'p' + this.pageIndex + '_',
  43789. this.idCounters,
  43790. this.fontCache);
  43791. var dataPromises = Promise.all([contentStreamPromise, resourcesPromise]);
  43792. var pageListPromise = dataPromises.then(function(data) {
  43793. var contentStream = data[0];
  43794. var opList = new OperatorList(intent, handler, self.pageIndex);
  43795. handler.send('StartRenderPage', {
  43796. transparency: partialEvaluator.hasBlendModes(self.resources),
  43797. pageIndex: self.pageIndex,
  43798. intent: intent
  43799. });
  43800. return partialEvaluator.getOperatorList(contentStream, task,
  43801. self.resources, opList).then(function () {
  43802. return opList;
  43803. });
  43804. });
  43805. var annotationsPromise = pdfManager.ensure(this, 'annotations');
  43806. return Promise.all([pageListPromise, annotationsPromise]).then(
  43807. function(datas) {
  43808. var pageOpList = datas[0];
  43809. var annotations = datas[1];
  43810. if (annotations.length === 0) {
  43811. pageOpList.flush(true);
  43812. return pageOpList;
  43813. }
  43814. var annotationsReadyPromise = Annotation.appendToOperatorList(
  43815. annotations, pageOpList, partialEvaluator, task, intent);
  43816. return annotationsReadyPromise.then(function () {
  43817. pageOpList.flush(true);
  43818. return pageOpList;
  43819. });
  43820. });
  43821. },
  43822. extractTextContent: function Page_extractTextContent(task,
  43823. normalizeWhitespace) {
  43824. var handler = {
  43825. on: function nullHandlerOn() {},
  43826. send: function nullHandlerSend() {}
  43827. };
  43828. var self = this;
  43829. var pdfManager = this.pdfManager;
  43830. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
  43831. []);
  43832. var resourcesPromise = this.loadResources([
  43833. 'ExtGState',
  43834. 'XObject',
  43835. 'Font'
  43836. ]);
  43837. var dataPromises = Promise.all([contentStreamPromise,
  43838. resourcesPromise]);
  43839. return dataPromises.then(function(data) {
  43840. var contentStream = data[0];
  43841. var partialEvaluator = new PartialEvaluator(pdfManager, self.xref,
  43842. handler, self.pageIndex,
  43843. 'p' + self.pageIndex + '_',
  43844. self.idCounters,
  43845. self.fontCache);
  43846. return partialEvaluator.getTextContent(contentStream,
  43847. task,
  43848. self.resources,
  43849. /* stateManager = */ null,
  43850. normalizeWhitespace);
  43851. });
  43852. },
  43853. getAnnotationsData: function Page_getAnnotationsData(intent) {
  43854. var annotations = this.annotations;
  43855. var annotationsData = [];
  43856. for (var i = 0, n = annotations.length; i < n; ++i) {
  43857. if (intent) {
  43858. if (!(intent === 'display' && annotations[i].viewable) &&
  43859. !(intent === 'print' && annotations[i].printable)) {
  43860. continue;
  43861. }
  43862. }
  43863. annotationsData.push(annotations[i].data);
  43864. }
  43865. return annotationsData;
  43866. },
  43867. get annotations() {
  43868. var annotations = [];
  43869. var annotationRefs = this.getInheritedPageProp('Annots') || [];
  43870. var annotationFactory = new AnnotationFactory();
  43871. for (var i = 0, n = annotationRefs.length; i < n; ++i) {
  43872. var annotationRef = annotationRefs[i];
  43873. var annotation = annotationFactory.create(this.xref, annotationRef);
  43874. if (annotation) {
  43875. annotations.push(annotation);
  43876. }
  43877. }
  43878. return shadow(this, 'annotations', annotations);
  43879. }
  43880. };
  43881. return Page;
  43882. })();
  43883. /**
  43884. * The `PDFDocument` holds all the data of the PDF file. Compared to the
  43885. * `PDFDoc`, this one doesn't have any job management code.
  43886. * Right now there exists one PDFDocument on the main thread + one object
  43887. * for each worker. If there is no worker support enabled, there are two
  43888. * `PDFDocument` objects on the main thread created.
  43889. */
  43890. var PDFDocument = (function PDFDocumentClosure() {
  43891. var FINGERPRINT_FIRST_BYTES = 1024;
  43892. var EMPTY_FINGERPRINT = '\x00\x00\x00\x00\x00\x00\x00' +
  43893. '\x00\x00\x00\x00\x00\x00\x00\x00\x00';
  43894. function PDFDocument(pdfManager, arg, password) {
  43895. if (isStream(arg)) {
  43896. init.call(this, pdfManager, arg, password);
  43897. } else if (isArrayBuffer(arg)) {
  43898. init.call(this, pdfManager, new Stream(arg), password);
  43899. } else {
  43900. error('PDFDocument: Unknown argument type');
  43901. }
  43902. }
  43903. function init(pdfManager, stream, password) {
  43904. assert(stream.length > 0, 'stream must have data');
  43905. this.pdfManager = pdfManager;
  43906. this.stream = stream;
  43907. var xref = new XRef(this.stream, password, pdfManager);
  43908. this.xref = xref;
  43909. }
  43910. function find(stream, needle, limit, backwards) {
  43911. var pos = stream.pos;
  43912. var end = stream.end;
  43913. var strBuf = [];
  43914. if (pos + limit > end) {
  43915. limit = end - pos;
  43916. }
  43917. for (var n = 0; n < limit; ++n) {
  43918. strBuf.push(String.fromCharCode(stream.getByte()));
  43919. }
  43920. var str = strBuf.join('');
  43921. stream.pos = pos;
  43922. var index = backwards ? str.lastIndexOf(needle) : str.indexOf(needle);
  43923. if (index === -1) {
  43924. return false; /* not found */
  43925. }
  43926. stream.pos += index;
  43927. return true; /* found */
  43928. }
  43929. var DocumentInfoValidators = {
  43930. get entries() {
  43931. // Lazily build this since all the validation functions below are not
  43932. // defined until after this file loads.
  43933. return shadow(this, 'entries', {
  43934. Title: isString,
  43935. Author: isString,
  43936. Subject: isString,
  43937. Keywords: isString,
  43938. Creator: isString,
  43939. Producer: isString,
  43940. CreationDate: isString,
  43941. ModDate: isString,
  43942. Trapped: isName
  43943. });
  43944. }
  43945. };
  43946. PDFDocument.prototype = {
  43947. parse: function PDFDocument_parse(recoveryMode) {
  43948. this.setup(recoveryMode);
  43949. var version = this.catalog.catDict.get('Version');
  43950. if (isName(version)) {
  43951. this.pdfFormatVersion = version.name;
  43952. }
  43953. try {
  43954. // checking if AcroForm is present
  43955. this.acroForm = this.catalog.catDict.get('AcroForm');
  43956. if (this.acroForm) {
  43957. this.xfa = this.acroForm.get('XFA');
  43958. var fields = this.acroForm.get('Fields');
  43959. if ((!fields || !isArray(fields) || fields.length === 0) &&
  43960. !this.xfa) {
  43961. // no fields and no XFA -- not a form (?)
  43962. this.acroForm = null;
  43963. }
  43964. }
  43965. } catch (ex) {
  43966. info('Something wrong with AcroForm entry');
  43967. this.acroForm = null;
  43968. }
  43969. },
  43970. get linearization() {
  43971. var linearization = null;
  43972. if (this.stream.length) {
  43973. try {
  43974. linearization = Linearization.create(this.stream);
  43975. } catch (err) {
  43976. if (err instanceof MissingDataException) {
  43977. throw err;
  43978. }
  43979. info(err);
  43980. }
  43981. }
  43982. // shadow the prototype getter with a data property
  43983. return shadow(this, 'linearization', linearization);
  43984. },
  43985. get startXRef() {
  43986. var stream = this.stream;
  43987. var startXRef = 0;
  43988. var linearization = this.linearization;
  43989. if (linearization) {
  43990. // Find end of first obj.
  43991. stream.reset();
  43992. if (find(stream, 'endobj', 1024)) {
  43993. startXRef = stream.pos + 6;
  43994. }
  43995. } else {
  43996. // Find startxref by jumping backward from the end of the file.
  43997. var step = 1024;
  43998. var found = false, pos = stream.end;
  43999. while (!found && pos > 0) {
  44000. pos -= step - 'startxref'.length;
  44001. if (pos < 0) {
  44002. pos = 0;
  44003. }
  44004. stream.pos = pos;
  44005. found = find(stream, 'startxref', step, true);
  44006. }
  44007. if (found) {
  44008. stream.skip(9);
  44009. var ch;
  44010. do {
  44011. ch = stream.getByte();
  44012. } while (Lexer.isSpace(ch));
  44013. var str = '';
  44014. while (ch >= 0x20 && ch <= 0x39) { // < '9'
  44015. str += String.fromCharCode(ch);
  44016. ch = stream.getByte();
  44017. }
  44018. startXRef = parseInt(str, 10);
  44019. if (isNaN(startXRef)) {
  44020. startXRef = 0;
  44021. }
  44022. }
  44023. }
  44024. // shadow the prototype getter with a data property
  44025. return shadow(this, 'startXRef', startXRef);
  44026. },
  44027. get mainXRefEntriesOffset() {
  44028. var mainXRefEntriesOffset = 0;
  44029. var linearization = this.linearization;
  44030. if (linearization) {
  44031. mainXRefEntriesOffset = linearization.mainXRefEntriesOffset;
  44032. }
  44033. // shadow the prototype getter with a data property
  44034. return shadow(this, 'mainXRefEntriesOffset', mainXRefEntriesOffset);
  44035. },
  44036. // Find the header, remove leading garbage and setup the stream
  44037. // starting from the header.
  44038. checkHeader: function PDFDocument_checkHeader() {
  44039. var stream = this.stream;
  44040. stream.reset();
  44041. if (find(stream, '%PDF-', 1024)) {
  44042. // Found the header, trim off any garbage before it.
  44043. stream.moveStart();
  44044. // Reading file format version
  44045. var MAX_VERSION_LENGTH = 12;
  44046. var version = '', ch;
  44047. while ((ch = stream.getByte()) > 0x20) { // SPACE
  44048. if (version.length >= MAX_VERSION_LENGTH) {
  44049. break;
  44050. }
  44051. version += String.fromCharCode(ch);
  44052. }
  44053. if (!this.pdfFormatVersion) {
  44054. // removing "%PDF-"-prefix
  44055. this.pdfFormatVersion = version.substring(5);
  44056. }
  44057. return;
  44058. }
  44059. // May not be a PDF file, continue anyway.
  44060. },
  44061. parseStartXRef: function PDFDocument_parseStartXRef() {
  44062. var startXRef = this.startXRef;
  44063. this.xref.setStartXRef(startXRef);
  44064. },
  44065. setup: function PDFDocument_setup(recoveryMode) {
  44066. this.xref.parse(recoveryMode);
  44067. var self = this;
  44068. var pageFactory = {
  44069. createPage: function (pageIndex, dict, ref, fontCache) {
  44070. return new Page(self.pdfManager, self.xref, pageIndex, dict, ref,
  44071. fontCache);
  44072. }
  44073. };
  44074. this.catalog = new Catalog(this.pdfManager, this.xref, pageFactory);
  44075. },
  44076. get numPages() {
  44077. var linearization = this.linearization;
  44078. var num = linearization ? linearization.numPages : this.catalog.numPages;
  44079. // shadow the prototype getter
  44080. return shadow(this, 'numPages', num);
  44081. },
  44082. get documentInfo() {
  44083. var docInfo = {
  44084. PDFFormatVersion: this.pdfFormatVersion,
  44085. IsAcroFormPresent: !!this.acroForm,
  44086. IsXFAPresent: !!this.xfa
  44087. };
  44088. var infoDict;
  44089. try {
  44090. infoDict = this.xref.trailer.get('Info');
  44091. } catch (err) {
  44092. info('The document information dictionary is invalid.');
  44093. }
  44094. if (infoDict) {
  44095. var validEntries = DocumentInfoValidators.entries;
  44096. // Only fill the document info with valid entries from the spec.
  44097. for (var key in validEntries) {
  44098. if (infoDict.has(key)) {
  44099. var value = infoDict.get(key);
  44100. // Make sure the value conforms to the spec.
  44101. if (validEntries[key](value)) {
  44102. docInfo[key] = (typeof value !== 'string' ?
  44103. value : stringToPDFString(value));
  44104. } else {
  44105. info('Bad value in document info for "' + key + '"');
  44106. }
  44107. }
  44108. }
  44109. }
  44110. return shadow(this, 'documentInfo', docInfo);
  44111. },
  44112. get fingerprint() {
  44113. var xref = this.xref, hash, fileID = '';
  44114. var idArray = xref.trailer.get('ID');
  44115. if (idArray && isArray(idArray) && idArray[0] && isString(idArray[0]) &&
  44116. idArray[0] !== EMPTY_FINGERPRINT) {
  44117. hash = stringToBytes(idArray[0]);
  44118. } else {
  44119. if (this.stream.ensureRange) {
  44120. this.stream.ensureRange(0,
  44121. Math.min(FINGERPRINT_FIRST_BYTES, this.stream.end));
  44122. }
  44123. hash = calculateMD5(this.stream.bytes.subarray(0,
  44124. FINGERPRINT_FIRST_BYTES), 0, FINGERPRINT_FIRST_BYTES);
  44125. }
  44126. for (var i = 0, n = hash.length; i < n; i++) {
  44127. var hex = hash[i].toString(16);
  44128. fileID += hex.length === 1 ? '0' + hex : hex;
  44129. }
  44130. return shadow(this, 'fingerprint', fileID);
  44131. },
  44132. getPage: function PDFDocument_getPage(pageIndex) {
  44133. return this.catalog.getPage(pageIndex);
  44134. },
  44135. cleanup: function PDFDocument_cleanup() {
  44136. return this.catalog.cleanup();
  44137. }
  44138. };
  44139. return PDFDocument;
  44140. })();
  44141. exports.Page = Page;
  44142. exports.PDFDocument = PDFDocument;
  44143. }));
  44144. (function (root, factory) {
  44145. {
  44146. factory((root.pdfjsCorePdfManager = {}), root.pdfjsSharedUtil,
  44147. root.pdfjsCoreStream, root.pdfjsCoreChunkedStream,
  44148. root.pdfjsCoreDocument);
  44149. }
  44150. }(this, function (exports, sharedUtil, coreStream, coreChunkedStream,
  44151. coreDocument) {
  44152. var NotImplementedException = sharedUtil.NotImplementedException;
  44153. var MissingDataException = sharedUtil.MissingDataException;
  44154. var createPromiseCapability = sharedUtil.createPromiseCapability;
  44155. var Util = sharedUtil.Util;
  44156. var Stream = coreStream.Stream;
  44157. var ChunkedStreamManager = coreChunkedStream.ChunkedStreamManager;
  44158. var PDFDocument = coreDocument.PDFDocument;
  44159. var BasePdfManager = (function BasePdfManagerClosure() {
  44160. function BasePdfManager() {
  44161. throw new Error('Cannot initialize BaseManagerManager');
  44162. }
  44163. BasePdfManager.prototype = {
  44164. get docId() {
  44165. return this._docId;
  44166. },
  44167. onLoadedStream: function BasePdfManager_onLoadedStream() {
  44168. throw new NotImplementedException();
  44169. },
  44170. ensureDoc: function BasePdfManager_ensureDoc(prop, args) {
  44171. return this.ensure(this.pdfDocument, prop, args);
  44172. },
  44173. ensureXRef: function BasePdfManager_ensureXRef(prop, args) {
  44174. return this.ensure(this.pdfDocument.xref, prop, args);
  44175. },
  44176. ensureCatalog: function BasePdfManager_ensureCatalog(prop, args) {
  44177. return this.ensure(this.pdfDocument.catalog, prop, args);
  44178. },
  44179. getPage: function BasePdfManager_getPage(pageIndex) {
  44180. return this.pdfDocument.getPage(pageIndex);
  44181. },
  44182. cleanup: function BasePdfManager_cleanup() {
  44183. return this.pdfDocument.cleanup();
  44184. },
  44185. ensure: function BasePdfManager_ensure(obj, prop, args) {
  44186. return new NotImplementedException();
  44187. },
  44188. requestRange: function BasePdfManager_requestRange(begin, end) {
  44189. return new NotImplementedException();
  44190. },
  44191. requestLoadedStream: function BasePdfManager_requestLoadedStream() {
  44192. return new NotImplementedException();
  44193. },
  44194. sendProgressiveData: function BasePdfManager_sendProgressiveData(chunk) {
  44195. return new NotImplementedException();
  44196. },
  44197. updatePassword: function BasePdfManager_updatePassword(password) {
  44198. this.pdfDocument.xref.password = this.password = password;
  44199. if (this._passwordChangedCapability) {
  44200. this._passwordChangedCapability.resolve();
  44201. }
  44202. },
  44203. passwordChanged: function BasePdfManager_passwordChanged() {
  44204. this._passwordChangedCapability = createPromiseCapability();
  44205. return this._passwordChangedCapability.promise;
  44206. },
  44207. terminate: function BasePdfManager_terminate() {
  44208. return new NotImplementedException();
  44209. }
  44210. };
  44211. return BasePdfManager;
  44212. })();
  44213. var LocalPdfManager = (function LocalPdfManagerClosure() {
  44214. function LocalPdfManager(docId, data, password) {
  44215. this._docId = docId;
  44216. var stream = new Stream(data);
  44217. this.pdfDocument = new PDFDocument(this, stream, password);
  44218. this._loadedStreamCapability = createPromiseCapability();
  44219. this._loadedStreamCapability.resolve(stream);
  44220. }
  44221. Util.inherit(LocalPdfManager, BasePdfManager, {
  44222. ensure: function LocalPdfManager_ensure(obj, prop, args) {
  44223. return new Promise(function (resolve, reject) {
  44224. try {
  44225. var value = obj[prop];
  44226. var result;
  44227. if (typeof value === 'function') {
  44228. result = value.apply(obj, args);
  44229. } else {
  44230. result = value;
  44231. }
  44232. resolve(result);
  44233. } catch (e) {
  44234. reject(e);
  44235. }
  44236. });
  44237. },
  44238. requestRange: function LocalPdfManager_requestRange(begin, end) {
  44239. return Promise.resolve();
  44240. },
  44241. requestLoadedStream: function LocalPdfManager_requestLoadedStream() {
  44242. return;
  44243. },
  44244. onLoadedStream: function LocalPdfManager_onLoadedStream() {
  44245. return this._loadedStreamCapability.promise;
  44246. },
  44247. terminate: function LocalPdfManager_terminate() {
  44248. return;
  44249. }
  44250. });
  44251. return LocalPdfManager;
  44252. })();
  44253. var NetworkPdfManager = (function NetworkPdfManagerClosure() {
  44254. function NetworkPdfManager(docId, args, msgHandler) {
  44255. this._docId = docId;
  44256. this.msgHandler = msgHandler;
  44257. var params = {
  44258. msgHandler: msgHandler,
  44259. httpHeaders: args.httpHeaders,
  44260. withCredentials: args.withCredentials,
  44261. chunkedViewerLoading: args.chunkedViewerLoading,
  44262. disableAutoFetch: args.disableAutoFetch,
  44263. initialData: args.initialData
  44264. };
  44265. this.streamManager = new ChunkedStreamManager(args.length,
  44266. args.rangeChunkSize,
  44267. args.url, params);
  44268. this.pdfDocument = new PDFDocument(this, this.streamManager.getStream(),
  44269. args.password);
  44270. }
  44271. Util.inherit(NetworkPdfManager, BasePdfManager, {
  44272. ensure: function NetworkPdfManager_ensure(obj, prop, args) {
  44273. var pdfManager = this;
  44274. return new Promise(function (resolve, reject) {
  44275. function ensureHelper() {
  44276. try {
  44277. var result;
  44278. var value = obj[prop];
  44279. if (typeof value === 'function') {
  44280. result = value.apply(obj, args);
  44281. } else {
  44282. result = value;
  44283. }
  44284. resolve(result);
  44285. } catch(e) {
  44286. if (!(e instanceof MissingDataException)) {
  44287. reject(e);
  44288. return;
  44289. }
  44290. pdfManager.streamManager.requestRange(e.begin, e.end).
  44291. then(ensureHelper, reject);
  44292. }
  44293. }
  44294. ensureHelper();
  44295. });
  44296. },
  44297. requestRange: function NetworkPdfManager_requestRange(begin, end) {
  44298. return this.streamManager.requestRange(begin, end);
  44299. },
  44300. requestLoadedStream: function NetworkPdfManager_requestLoadedStream() {
  44301. this.streamManager.requestAllChunks();
  44302. },
  44303. sendProgressiveData:
  44304. function NetworkPdfManager_sendProgressiveData(chunk) {
  44305. this.streamManager.onReceiveData({ chunk: chunk });
  44306. },
  44307. onLoadedStream: function NetworkPdfManager_onLoadedStream() {
  44308. return this.streamManager.onLoadedStream();
  44309. },
  44310. terminate: function NetworkPdfManager_terminate() {
  44311. this.streamManager.abort();
  44312. }
  44313. });
  44314. return NetworkPdfManager;
  44315. })();
  44316. exports.LocalPdfManager = LocalPdfManager;
  44317. exports.NetworkPdfManager = NetworkPdfManager;
  44318. }));
  44319. (function (root, factory) {
  44320. {
  44321. factory((root.pdfjsCoreWorker = {}), root.pdfjsSharedUtil,
  44322. root.pdfjsCorePrimitives, root.pdfjsCorePdfManager,
  44323. root.pdfjsSharedGlobal);
  44324. }
  44325. }(this, function (exports, sharedUtil, corePrimitives, corePdfManager,
  44326. sharedGlobal) {
  44327. var UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
  44328. var InvalidPDFException = sharedUtil.InvalidPDFException;
  44329. var MessageHandler = sharedUtil.MessageHandler;
  44330. var MissingPDFException = sharedUtil.MissingPDFException;
  44331. var UnexpectedResponseException = sharedUtil.UnexpectedResponseException;
  44332. var PasswordException = sharedUtil.PasswordException;
  44333. var PasswordResponses = sharedUtil.PasswordResponses;
  44334. var UnknownErrorException = sharedUtil.UnknownErrorException;
  44335. var XRefParseException = sharedUtil.XRefParseException;
  44336. var createPromiseCapability = sharedUtil.createPromiseCapability;
  44337. var error = sharedUtil.error;
  44338. var info = sharedUtil.info;
  44339. var isInt = sharedUtil.isInt;
  44340. var warn = sharedUtil.warn;
  44341. var Ref = corePrimitives.Ref;
  44342. var LocalPdfManager = corePdfManager.LocalPdfManager;
  44343. var NetworkPdfManager = corePdfManager.NetworkPdfManager;
  44344. var globalScope = sharedGlobal.globalScope;
  44345. var PDFJS = sharedGlobal.PDFJS;
  44346. var WorkerTask = (function WorkerTaskClosure() {
  44347. function WorkerTask(name) {
  44348. this.name = name;
  44349. this.terminated = false;
  44350. this._capability = createPromiseCapability();
  44351. }
  44352. WorkerTask.prototype = {
  44353. get finished() {
  44354. return this._capability.promise;
  44355. },
  44356. finish: function () {
  44357. this._capability.resolve();
  44358. },
  44359. terminate: function () {
  44360. this.terminated = true;
  44361. },
  44362. ensureNotTerminated: function () {
  44363. if (this.terminated) {
  44364. throw new Error('Worker task was terminated');
  44365. }
  44366. }
  44367. };
  44368. return WorkerTask;
  44369. })();
  44370. var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
  44371. setup: function wphSetup(handler, port) {
  44372. handler.on('test', function wphSetupTest(data) {
  44373. // check if Uint8Array can be sent to worker
  44374. if (!(data instanceof Uint8Array)) {
  44375. handler.send('test', 'main', false);
  44376. return;
  44377. }
  44378. // making sure postMessage transfers are working
  44379. var supportTransfers = data[0] === 255;
  44380. handler.postMessageTransfers = supportTransfers;
  44381. // check if the response property is supported by xhr
  44382. var xhr = new XMLHttpRequest();
  44383. var responseExists = 'response' in xhr;
  44384. // check if the property is actually implemented
  44385. try {
  44386. var dummy = xhr.responseType;
  44387. } catch (e) {
  44388. responseExists = false;
  44389. }
  44390. if (!responseExists) {
  44391. handler.send('test', false);
  44392. return;
  44393. }
  44394. handler.send('test', {
  44395. supportTypedArray: true,
  44396. supportTransfers: supportTransfers
  44397. });
  44398. });
  44399. handler.on('GetDocRequest', function wphSetupDoc(data) {
  44400. return WorkerMessageHandler.createDocumentHandler(data, port);
  44401. });
  44402. },
  44403. createDocumentHandler: function wphCreateDocumentHandler(docParams, port) {
  44404. // This context is actually holds references on pdfManager and handler,
  44405. // until the latter is destroyed.
  44406. var pdfManager;
  44407. var terminated = false;
  44408. var cancelXHRs = null;
  44409. var WorkerTasks = [];
  44410. var docId = docParams.docId;
  44411. var workerHandlerName = docParams.docId + '_worker';
  44412. var handler = new MessageHandler(workerHandlerName, docId, port);
  44413. function ensureNotTerminated() {
  44414. if (terminated) {
  44415. throw new Error('Worker was terminated');
  44416. }
  44417. }
  44418. function startWorkerTask(task) {
  44419. WorkerTasks.push(task);
  44420. }
  44421. function finishWorkerTask(task) {
  44422. task.finish();
  44423. var i = WorkerTasks.indexOf(task);
  44424. WorkerTasks.splice(i, 1);
  44425. }
  44426. function loadDocument(recoveryMode) {
  44427. var loadDocumentCapability = createPromiseCapability();
  44428. var parseSuccess = function parseSuccess() {
  44429. var numPagesPromise = pdfManager.ensureDoc('numPages');
  44430. var fingerprintPromise = pdfManager.ensureDoc('fingerprint');
  44431. var encryptedPromise = pdfManager.ensureXRef('encrypt');
  44432. Promise.all([numPagesPromise, fingerprintPromise,
  44433. encryptedPromise]).then(function onDocReady(results) {
  44434. var doc = {
  44435. numPages: results[0],
  44436. fingerprint: results[1],
  44437. encrypted: !!results[2],
  44438. };
  44439. loadDocumentCapability.resolve(doc);
  44440. },
  44441. parseFailure);
  44442. };
  44443. var parseFailure = function parseFailure(e) {
  44444. loadDocumentCapability.reject(e);
  44445. };
  44446. pdfManager.ensureDoc('checkHeader', []).then(function() {
  44447. pdfManager.ensureDoc('parseStartXRef', []).then(function() {
  44448. pdfManager.ensureDoc('parse', [recoveryMode]).then(
  44449. parseSuccess, parseFailure);
  44450. }, parseFailure);
  44451. }, parseFailure);
  44452. return loadDocumentCapability.promise;
  44453. }
  44454. function getPdfManager(data) {
  44455. var pdfManagerCapability = createPromiseCapability();
  44456. var pdfManager;
  44457. var source = data.source;
  44458. var disableRange = data.disableRange;
  44459. if (source.data) {
  44460. try {
  44461. pdfManager = new LocalPdfManager(docId, source.data, source.password);
  44462. pdfManagerCapability.resolve(pdfManager);
  44463. } catch (ex) {
  44464. pdfManagerCapability.reject(ex);
  44465. }
  44466. return pdfManagerCapability.promise;
  44467. } else if (source.chunkedViewerLoading) {
  44468. try {
  44469. pdfManager = new NetworkPdfManager(docId, source, handler);
  44470. pdfManagerCapability.resolve(pdfManager);
  44471. } catch (ex) {
  44472. pdfManagerCapability.reject(ex);
  44473. }
  44474. return pdfManagerCapability.promise;
  44475. }
  44476. var networkManager = new NetworkManager(source.url, {
  44477. httpHeaders: source.httpHeaders,
  44478. withCredentials: source.withCredentials
  44479. });
  44480. var cachedChunks = [];
  44481. var fullRequestXhrId = networkManager.requestFull({
  44482. onHeadersReceived: function onHeadersReceived() {
  44483. if (disableRange) {
  44484. return;
  44485. }
  44486. var fullRequestXhr = networkManager.getRequestXhr(fullRequestXhrId);
  44487. if (fullRequestXhr.getResponseHeader('Accept-Ranges') !== 'bytes') {
  44488. return;
  44489. }
  44490. var contentEncoding =
  44491. fullRequestXhr.getResponseHeader('Content-Encoding') || 'identity';
  44492. if (contentEncoding !== 'identity') {
  44493. return;
  44494. }
  44495. var length = fullRequestXhr.getResponseHeader('Content-Length');
  44496. length = parseInt(length, 10);
  44497. if (!isInt(length)) {
  44498. return;
  44499. }
  44500. source.length = length;
  44501. if (length <= 2 * source.rangeChunkSize) {
  44502. // The file size is smaller than the size of two chunks, so it does
  44503. // not make any sense to abort the request and retry with a range
  44504. // request.
  44505. return;
  44506. }
  44507. if (networkManager.isStreamingRequest(fullRequestXhrId)) {
  44508. // We can continue fetching when progressive loading is enabled,
  44509. // and we don't need the autoFetch feature.
  44510. source.disableAutoFetch = true;
  44511. } else {
  44512. // NOTE: by cancelling the full request, and then issuing range
  44513. // requests, there will be an issue for sites where you can only
  44514. // request the pdf once. However, if this is the case, then the
  44515. // server should not be returning that it can support range
  44516. // requests.
  44517. networkManager.abortRequest(fullRequestXhrId);
  44518. }
  44519. try {
  44520. pdfManager = new NetworkPdfManager(docId, source, handler);
  44521. pdfManagerCapability.resolve(pdfManager);
  44522. } catch (ex) {
  44523. pdfManagerCapability.reject(ex);
  44524. }
  44525. cancelXHRs = null;
  44526. },
  44527. onProgressiveData: source.disableStream ? null :
  44528. function onProgressiveData(chunk) {
  44529. if (!pdfManager) {
  44530. cachedChunks.push(chunk);
  44531. return;
  44532. }
  44533. pdfManager.sendProgressiveData(chunk);
  44534. },
  44535. onDone: function onDone(args) {
  44536. if (pdfManager) {
  44537. return; // already processed
  44538. }
  44539. var pdfFile;
  44540. if (args === null) {
  44541. // TODO add some streaming manager, e.g. for unknown length files.
  44542. // The data was returned in the onProgressiveData, combining...
  44543. var pdfFileLength = 0, pos = 0;
  44544. cachedChunks.forEach(function (chunk) {
  44545. pdfFileLength += chunk.byteLength;
  44546. });
  44547. if (source.length && pdfFileLength !== source.length) {
  44548. warn('reported HTTP length is different from actual');
  44549. }
  44550. var pdfFileArray = new Uint8Array(pdfFileLength);
  44551. cachedChunks.forEach(function (chunk) {
  44552. pdfFileArray.set(new Uint8Array(chunk), pos);
  44553. pos += chunk.byteLength;
  44554. });
  44555. pdfFile = pdfFileArray.buffer;
  44556. } else {
  44557. pdfFile = args.chunk;
  44558. }
  44559. // the data is array, instantiating directly from it
  44560. try {
  44561. pdfManager = new LocalPdfManager(docId, pdfFile, source.password);
  44562. pdfManagerCapability.resolve(pdfManager);
  44563. } catch (ex) {
  44564. pdfManagerCapability.reject(ex);
  44565. }
  44566. cancelXHRs = null;
  44567. },
  44568. onError: function onError(status) {
  44569. var exception;
  44570. if (status === 404 || status === 0 && /^file:/.test(source.url)) {
  44571. exception = new MissingPDFException('Missing PDF "' +
  44572. source.url + '".');
  44573. handler.send('MissingPDF', exception);
  44574. } else {
  44575. exception = new UnexpectedResponseException(
  44576. 'Unexpected server response (' + status +
  44577. ') while retrieving PDF "' + source.url + '".', status);
  44578. handler.send('UnexpectedResponse', exception);
  44579. }
  44580. cancelXHRs = null;
  44581. },
  44582. onProgress: function onProgress(evt) {
  44583. handler.send('DocProgress', {
  44584. loaded: evt.loaded,
  44585. total: evt.lengthComputable ? evt.total : source.length
  44586. });
  44587. }
  44588. });
  44589. cancelXHRs = function () {
  44590. networkManager.abortRequest(fullRequestXhrId);
  44591. };
  44592. return pdfManagerCapability.promise;
  44593. }
  44594. var setupDoc = function(data) {
  44595. var onSuccess = function(doc) {
  44596. ensureNotTerminated();
  44597. handler.send('GetDoc', { pdfInfo: doc });
  44598. };
  44599. var onFailure = function(e) {
  44600. if (e instanceof PasswordException) {
  44601. if (e.code === PasswordResponses.NEED_PASSWORD) {
  44602. handler.send('NeedPassword', e);
  44603. } else if (e.code === PasswordResponses.INCORRECT_PASSWORD) {
  44604. handler.send('IncorrectPassword', e);
  44605. }
  44606. } else if (e instanceof InvalidPDFException) {
  44607. handler.send('InvalidPDF', e);
  44608. } else if (e instanceof MissingPDFException) {
  44609. handler.send('MissingPDF', e);
  44610. } else if (e instanceof UnexpectedResponseException) {
  44611. handler.send('UnexpectedResponse', e);
  44612. } else {
  44613. handler.send('UnknownError',
  44614. new UnknownErrorException(e.message, e.toString()));
  44615. }
  44616. };
  44617. ensureNotTerminated();
  44618. PDFJS.maxImageSize = data.maxImageSize === undefined ?
  44619. -1 : data.maxImageSize;
  44620. PDFJS.disableFontFace = data.disableFontFace;
  44621. PDFJS.disableCreateObjectURL = data.disableCreateObjectURL;
  44622. PDFJS.verbosity = data.verbosity;
  44623. PDFJS.cMapUrl = data.cMapUrl === undefined ?
  44624. null : data.cMapUrl;
  44625. PDFJS.cMapPacked = data.cMapPacked === true;
  44626. getPdfManager(data).then(function (newPdfManager) {
  44627. if (terminated) {
  44628. // We were in a process of setting up the manager, but it got
  44629. // terminated in the middle.
  44630. newPdfManager.terminate();
  44631. throw new Error('Worker was terminated');
  44632. }
  44633. pdfManager = newPdfManager;
  44634. handler.send('PDFManagerReady', null);
  44635. pdfManager.onLoadedStream().then(function(stream) {
  44636. handler.send('DataLoaded', { length: stream.bytes.byteLength });
  44637. });
  44638. }).then(function pdfManagerReady() {
  44639. ensureNotTerminated();
  44640. loadDocument(false).then(onSuccess, function loadFailure(ex) {
  44641. ensureNotTerminated();
  44642. // Try again with recoveryMode == true
  44643. if (!(ex instanceof XRefParseException)) {
  44644. if (ex instanceof PasswordException) {
  44645. // after password exception prepare to receive a new password
  44646. // to repeat loading
  44647. pdfManager.passwordChanged().then(pdfManagerReady);
  44648. }
  44649. onFailure(ex);
  44650. return;
  44651. }
  44652. pdfManager.requestLoadedStream();
  44653. pdfManager.onLoadedStream().then(function() {
  44654. ensureNotTerminated();
  44655. loadDocument(true).then(onSuccess, onFailure);
  44656. });
  44657. }, onFailure);
  44658. }, onFailure);
  44659. };
  44660. handler.on('GetPage', function wphSetupGetPage(data) {
  44661. return pdfManager.getPage(data.pageIndex).then(function(page) {
  44662. var rotatePromise = pdfManager.ensure(page, 'rotate');
  44663. var refPromise = pdfManager.ensure(page, 'ref');
  44664. var viewPromise = pdfManager.ensure(page, 'view');
  44665. return Promise.all([rotatePromise, refPromise, viewPromise]).then(
  44666. function(results) {
  44667. return {
  44668. rotate: results[0],
  44669. ref: results[1],
  44670. view: results[2]
  44671. };
  44672. });
  44673. });
  44674. });
  44675. handler.on('GetPageIndex', function wphSetupGetPageIndex(data) {
  44676. var ref = new Ref(data.ref.num, data.ref.gen);
  44677. var catalog = pdfManager.pdfDocument.catalog;
  44678. return catalog.getPageIndex(ref);
  44679. });
  44680. handler.on('GetDestinations',
  44681. function wphSetupGetDestinations(data) {
  44682. return pdfManager.ensureCatalog('destinations');
  44683. }
  44684. );
  44685. handler.on('GetDestination',
  44686. function wphSetupGetDestination(data) {
  44687. return pdfManager.ensureCatalog('getDestination', [data.id]);
  44688. }
  44689. );
  44690. handler.on('GetAttachments',
  44691. function wphSetupGetAttachments(data) {
  44692. return pdfManager.ensureCatalog('attachments');
  44693. }
  44694. );
  44695. handler.on('GetJavaScript',
  44696. function wphSetupGetJavaScript(data) {
  44697. return pdfManager.ensureCatalog('javaScript');
  44698. }
  44699. );
  44700. handler.on('GetOutline',
  44701. function wphSetupGetOutline(data) {
  44702. return pdfManager.ensureCatalog('documentOutline');
  44703. }
  44704. );
  44705. handler.on('GetMetadata',
  44706. function wphSetupGetMetadata(data) {
  44707. return Promise.all([pdfManager.ensureDoc('documentInfo'),
  44708. pdfManager.ensureCatalog('metadata')]);
  44709. }
  44710. );
  44711. handler.on('GetData', function wphSetupGetData(data) {
  44712. pdfManager.requestLoadedStream();
  44713. return pdfManager.onLoadedStream().then(function(stream) {
  44714. return stream.bytes;
  44715. });
  44716. });
  44717. handler.on('GetStats',
  44718. function wphSetupGetStats(data) {
  44719. return pdfManager.pdfDocument.xref.stats;
  44720. }
  44721. );
  44722. handler.on('UpdatePassword', function wphSetupUpdatePassword(data) {
  44723. pdfManager.updatePassword(data);
  44724. });
  44725. handler.on('GetAnnotations', function wphSetupGetAnnotations(data) {
  44726. return pdfManager.getPage(data.pageIndex).then(function(page) {
  44727. return pdfManager.ensure(page, 'getAnnotationsData', [data.intent]);
  44728. });
  44729. });
  44730. handler.on('RenderPageRequest', function wphSetupRenderPage(data) {
  44731. var pageIndex = data.pageIndex;
  44732. pdfManager.getPage(pageIndex).then(function(page) {
  44733. var task = new WorkerTask('RenderPageRequest: page ' + pageIndex);
  44734. startWorkerTask(task);
  44735. var pageNum = pageIndex + 1;
  44736. var start = Date.now();
  44737. // Pre compile the pdf page and fetch the fonts/images.
  44738. page.getOperatorList(handler, task, data.intent).then(
  44739. function(operatorList) {
  44740. finishWorkerTask(task);
  44741. info('page=' + pageNum + ' - getOperatorList: time=' +
  44742. (Date.now() - start) + 'ms, len=' + operatorList.totalLength);
  44743. }, function(e) {
  44744. finishWorkerTask(task);
  44745. if (task.terminated) {
  44746. return; // ignoring errors from the terminated thread
  44747. }
  44748. // For compatibility with older behavior, generating unknown
  44749. // unsupported feature notification on errors.
  44750. handler.send('UnsupportedFeature',
  44751. {featureId: UNSUPPORTED_FEATURES.unknown});
  44752. var minimumStackMessage =
  44753. 'worker.js: while trying to getPage() and getOperatorList()';
  44754. var wrappedException;
  44755. // Turn the error into an obj that can be serialized
  44756. if (typeof e === 'string') {
  44757. wrappedException = {
  44758. message: e,
  44759. stack: minimumStackMessage
  44760. };
  44761. } else if (typeof e === 'object') {
  44762. wrappedException = {
  44763. message: e.message || e.toString(),
  44764. stack: e.stack || minimumStackMessage
  44765. };
  44766. } else {
  44767. wrappedException = {
  44768. message: 'Unknown exception type: ' + (typeof e),
  44769. stack: minimumStackMessage
  44770. };
  44771. }
  44772. handler.send('PageError', {
  44773. pageNum: pageNum,
  44774. error: wrappedException,
  44775. intent: data.intent
  44776. });
  44777. });
  44778. });
  44779. }, this);
  44780. handler.on('GetTextContent', function wphExtractText(data) {
  44781. var pageIndex = data.pageIndex;
  44782. var normalizeWhitespace = data.normalizeWhitespace;
  44783. return pdfManager.getPage(pageIndex).then(function(page) {
  44784. var task = new WorkerTask('GetTextContent: page ' + pageIndex);
  44785. startWorkerTask(task);
  44786. var pageNum = pageIndex + 1;
  44787. var start = Date.now();
  44788. return page.extractTextContent(task, normalizeWhitespace).then(
  44789. function(textContent) {
  44790. finishWorkerTask(task);
  44791. info('text indexing: page=' + pageNum + ' - time=' +
  44792. (Date.now() - start) + 'ms');
  44793. return textContent;
  44794. }, function (reason) {
  44795. finishWorkerTask(task);
  44796. if (task.terminated) {
  44797. return; // ignoring errors from the terminated thread
  44798. }
  44799. throw reason;
  44800. });
  44801. });
  44802. });
  44803. handler.on('Cleanup', function wphCleanup(data) {
  44804. return pdfManager.cleanup();
  44805. });
  44806. handler.on('Terminate', function wphTerminate(data) {
  44807. terminated = true;
  44808. if (pdfManager) {
  44809. pdfManager.terminate();
  44810. pdfManager = null;
  44811. }
  44812. if (cancelXHRs) {
  44813. cancelXHRs();
  44814. }
  44815. var waitOn = [];
  44816. WorkerTasks.forEach(function (task) {
  44817. waitOn.push(task.finished);
  44818. task.terminate();
  44819. });
  44820. return Promise.all(waitOn).then(function () {
  44821. // Notice that even if we destroying handler, resolved response promise
  44822. // must be sent back.
  44823. handler.destroy();
  44824. handler = null;
  44825. });
  44826. });
  44827. handler.on('Ready', function wphReady(data) {
  44828. setupDoc(docParams);
  44829. docParams = null; // we don't need docParams anymore -- saving memory.
  44830. });
  44831. return workerHandlerName;
  44832. }
  44833. };
  44834. var consoleTimer = {};
  44835. var workerConsole = {
  44836. log: function log() {
  44837. var args = Array.prototype.slice.call(arguments);
  44838. globalScope.postMessage({
  44839. targetName: 'main',
  44840. action: 'console_log',
  44841. data: args
  44842. });
  44843. },
  44844. error: function error() {
  44845. var args = Array.prototype.slice.call(arguments);
  44846. globalScope.postMessage({
  44847. targetName: 'main',
  44848. action: 'console_error',
  44849. data: args
  44850. });
  44851. throw 'pdf.js execution error';
  44852. },
  44853. time: function time(name) {
  44854. consoleTimer[name] = Date.now();
  44855. },
  44856. timeEnd: function timeEnd(name) {
  44857. var time = consoleTimer[name];
  44858. if (!time) {
  44859. error('Unknown timer name ' + name);
  44860. }
  44861. this.log('Timer:', name, Date.now() - time);
  44862. }
  44863. };
  44864. // Worker thread?
  44865. if (typeof window === 'undefined' && typeof require === 'undefined') {
  44866. if (!('console' in globalScope)) {
  44867. globalScope.console = workerConsole;
  44868. }
  44869. var handler = new MessageHandler('worker', 'main', self);
  44870. WorkerMessageHandler.setup(handler, self);
  44871. }
  44872. exports.WorkerTask = WorkerTask;
  44873. exports.WorkerMessageHandler = WorkerMessageHandler;
  44874. }));
  44875. }).call((typeof window === 'undefined') ? this : window);
  44876. if (!PDFJS.workerSrc && typeof document !== 'undefined') {
  44877. // workerSrc is not set -- using last script url to define default location
  44878. PDFJS.workerSrc = (function () {
  44879. 'use strict';
  44880. var pdfJsSrc = document.currentScript.src;
  44881. return pdfJsSrc && pdfJsSrc.replace(/\.js$/i, '.worker.js');
  44882. })();
  44883. }