pdf.combined.js 1.4 MB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079280802808128082280832808428085280862808728088280892809028091280922809328094280952809628097280982809928100281012810228103281042810528106281072810828109281102811128112281132811428115281162811728118281192812028121281222812328124281252812628127281282812928130281312813228133281342813528136281372813828139281402814128142281432814428145281462814728148281492815028151281522815328154281552815628157281582815928160281612816228163281642816528166281672816828169281702817128172281732817428175281762817728178281792818028181281822818328184281852818628187281882818928190281912819228193281942819528196281972819828199282002820128202282032820428205282062820728208282092821028211282122821328214282152821628217282182821928220282212822228223282242822528226282272822828229282302823128232282332823428235282362823728238282392824028241282422824328244282452824628247282482824928250282512825228253282542825528256282572825828259282602826128262282632826428265282662826728268282692827028271282722827328274282752827628277282782827928280282812828228283282842828528286282872828828289282902829128292282932829428295282962829728298282992830028301283022830328304283052830628307283082830928310283112831228313283142831528316283172831828319283202832128322283232832428325283262832728328283292833028331283322833328334283352833628337283382833928340283412834228343283442834528346283472834828349283502835128352283532835428355283562835728358283592836028361283622836328364283652836628367283682836928370283712837228373283742837528376283772837828379283802838128382283832838428385283862838728388283892839028391283922839328394283952839628397283982839928400284012840228403284042840528406284072840828409284102841128412284132841428415284162841728418284192842028421284222842328424284252842628427284282842928430284312843228433284342843528436284372843828439284402844128442284432844428445284462844728448284492845028451284522845328454284552845628457284582845928460284612846228463284642846528466284672846828469284702847128472284732847428475284762847728478284792848028481284822848328484284852848628487284882848928490284912849228493284942849528496284972849828499285002850128502285032850428505285062850728508285092851028511285122851328514285152851628517285182851928520285212852228523285242852528526285272852828529285302853128532285332853428535285362853728538285392854028541285422854328544285452854628547285482854928550285512855228553285542855528556285572855828559285602856128562285632856428565285662856728568285692857028571285722857328574285752857628577285782857928580285812858228583285842858528586285872858828589285902859128592285932859428595285962859728598285992860028601286022860328604286052860628607286082860928610286112861228613286142861528616286172861828619286202862128622286232862428625286262862728628286292863028631286322863328634286352863628637286382863928640286412864228643286442864528646286472864828649286502865128652286532865428655286562865728658286592866028661286622866328664286652866628667286682866928670286712867228673286742867528676286772867828679286802868128682286832868428685286862868728688286892869028691286922869328694286952869628697286982869928700287012870228703287042870528706287072870828709287102871128712287132871428715287162871728718287192872028721287222872328724287252872628727287282872928730287312873228733287342873528736287372873828739287402874128742287432874428745287462874728748287492875028751287522875328754287552875628757287582875928760287612876228763287642876528766287672876828769287702877128772287732877428775287762877728778287792878028781287822878328784287852878628787287882878928790287912879228793287942879528796287972879828799288002880128802288032880428805288062880728808288092881028811288122881328814288152881628817288182881928820288212882228823288242882528826288272882828829288302883128832288332883428835288362883728838288392884028841288422884328844288452884628847288482884928850288512885228853288542885528856288572885828859288602886128862288632886428865288662886728868288692887028871288722887328874288752887628877288782887928880288812888228883288842888528886288872888828889288902889128892288932889428895288962889728898288992890028901289022890328904289052890628907289082890928910289112891228913289142891528916289172891828919289202892128922289232892428925289262892728928289292893028931289322893328934289352893628937289382893928940289412894228943289442894528946289472894828949289502895128952289532895428955289562895728958289592896028961289622896328964289652896628967289682896928970289712897228973289742897528976289772897828979289802898128982289832898428985289862898728988289892899028991289922899328994289952899628997289982899929000290012900229003290042900529006290072900829009290102901129012290132901429015290162901729018290192902029021290222902329024290252902629027290282902929030290312903229033290342903529036290372903829039290402904129042290432904429045290462904729048290492905029051290522905329054290552905629057290582905929060290612906229063290642906529066290672906829069290702907129072290732907429075290762907729078290792908029081290822908329084290852908629087290882908929090290912909229093290942909529096290972909829099291002910129102291032910429105291062910729108291092911029111291122911329114291152911629117291182911929120291212912229123291242912529126291272912829129291302913129132291332913429135291362913729138291392914029141291422914329144291452914629147291482914929150291512915229153291542915529156291572915829159291602916129162291632916429165291662916729168291692917029171291722917329174291752917629177291782917929180291812918229183291842918529186291872918829189291902919129192291932919429195291962919729198291992920029201292022920329204292052920629207292082920929210292112921229213292142921529216292172921829219292202922129222292232922429225292262922729228292292923029231292322923329234292352923629237292382923929240292412924229243292442924529246292472924829249292502925129252292532925429255292562925729258292592926029261292622926329264292652926629267292682926929270292712927229273292742927529276292772927829279292802928129282292832928429285292862928729288292892929029291292922929329294292952929629297292982929929300293012930229303293042930529306293072930829309293102931129312293132931429315293162931729318293192932029321293222932329324293252932629327293282932929330293312933229333293342933529336293372933829339293402934129342293432934429345293462934729348293492935029351293522935329354293552935629357293582935929360293612936229363293642936529366293672936829369293702937129372293732937429375293762937729378293792938029381293822938329384293852938629387293882938929390293912939229393293942939529396293972939829399294002940129402294032940429405294062940729408294092941029411294122941329414294152941629417294182941929420294212942229423294242942529426294272942829429294302943129432294332943429435294362943729438294392944029441294422944329444294452944629447294482944929450294512945229453294542945529456294572945829459294602946129462294632946429465294662946729468294692947029471294722947329474294752947629477294782947929480294812948229483294842948529486294872948829489294902949129492294932949429495294962949729498294992950029501295022950329504295052950629507295082950929510295112951229513295142951529516295172951829519295202952129522295232952429525295262952729528295292953029531295322953329534295352953629537295382953929540295412954229543295442954529546295472954829549295502955129552295532955429555295562955729558295592956029561295622956329564295652956629567295682956929570295712957229573295742957529576295772957829579295802958129582295832958429585295862958729588295892959029591295922959329594295952959629597295982959929600296012960229603296042960529606296072960829609296102961129612296132961429615296162961729618296192962029621296222962329624296252962629627296282962929630296312963229633296342963529636296372963829639296402964129642296432964429645296462964729648296492965029651296522965329654296552965629657296582965929660296612966229663296642966529666296672966829669296702967129672296732967429675296762967729678296792968029681296822968329684296852968629687296882968929690296912969229693296942969529696296972969829699297002970129702297032970429705297062970729708297092971029711297122971329714297152971629717297182971929720297212972229723297242972529726297272972829729297302973129732297332973429735297362973729738297392974029741297422974329744297452974629747297482974929750297512975229753297542975529756297572975829759297602976129762297632976429765297662976729768297692977029771297722977329774297752977629777297782977929780297812978229783297842978529786297872978829789297902979129792297932979429795297962979729798297992980029801298022980329804298052980629807298082980929810298112981229813298142981529816298172981829819298202982129822298232982429825298262982729828298292983029831298322983329834298352983629837298382983929840298412984229843298442984529846298472984829849298502985129852298532985429855298562985729858298592986029861298622986329864298652986629867298682986929870298712987229873298742987529876298772987829879298802988129882298832988429885298862988729888298892989029891298922989329894298952989629897298982989929900299012990229903299042990529906299072990829909299102991129912299132991429915299162991729918299192992029921299222992329924299252992629927299282992929930299312993229933299342993529936299372993829939299402994129942299432994429945299462994729948299492995029951299522995329954299552995629957299582995929960299612996229963299642996529966299672996829969299702997129972299732997429975299762997729978299792998029981299822998329984299852998629987299882998929990299912999229993299942999529996299972999829999300003000130002300033000430005300063000730008300093001030011300123001330014300153001630017300183001930020300213002230023300243002530026300273002830029300303003130032300333003430035300363003730038300393004030041300423004330044300453004630047300483004930050300513005230053300543005530056300573005830059300603006130062300633006430065300663006730068300693007030071300723007330074300753007630077300783007930080300813008230083300843008530086300873008830089300903009130092300933009430095300963009730098300993010030101301023010330104301053010630107301083010930110301113011230113301143011530116301173011830119301203012130122301233012430125301263012730128301293013030131301323013330134301353013630137301383013930140301413014230143301443014530146301473014830149301503015130152301533015430155301563015730158301593016030161301623016330164301653016630167301683016930170301713017230173301743017530176301773017830179301803018130182301833018430185301863018730188301893019030191301923019330194301953019630197301983019930200302013020230203302043020530206302073020830209302103021130212302133021430215302163021730218302193022030221302223022330224302253022630227302283022930230302313023230233302343023530236302373023830239302403024130242302433024430245302463024730248302493025030251302523025330254302553025630257302583025930260302613026230263302643026530266302673026830269302703027130272302733027430275302763027730278302793028030281302823028330284302853028630287302883028930290302913029230293302943029530296302973029830299303003030130302303033030430305303063030730308303093031030311303123031330314303153031630317303183031930320303213032230323303243032530326303273032830329303303033130332303333033430335303363033730338303393034030341303423034330344303453034630347303483034930350303513035230353303543035530356303573035830359303603036130362303633036430365303663036730368303693037030371303723037330374303753037630377303783037930380303813038230383303843038530386303873038830389303903039130392303933039430395303963039730398303993040030401304023040330404304053040630407304083040930410304113041230413304143041530416304173041830419304203042130422304233042430425304263042730428304293043030431304323043330434304353043630437304383043930440304413044230443304443044530446304473044830449304503045130452304533045430455304563045730458304593046030461304623046330464304653046630467304683046930470304713047230473304743047530476304773047830479304803048130482304833048430485304863048730488304893049030491304923049330494304953049630497304983049930500305013050230503305043050530506305073050830509305103051130512305133051430515305163051730518305193052030521305223052330524305253052630527305283052930530305313053230533305343053530536305373053830539305403054130542305433054430545305463054730548305493055030551305523055330554305553055630557305583055930560305613056230563305643056530566305673056830569305703057130572305733057430575305763057730578305793058030581305823058330584305853058630587305883058930590305913059230593305943059530596305973059830599306003060130602306033060430605306063060730608306093061030611306123061330614306153061630617306183061930620306213062230623306243062530626306273062830629306303063130632306333063430635306363063730638306393064030641306423064330644306453064630647306483064930650306513065230653306543065530656306573065830659306603066130662306633066430665306663066730668306693067030671306723067330674306753067630677306783067930680306813068230683306843068530686306873068830689306903069130692306933069430695306963069730698306993070030701307023070330704307053070630707307083070930710307113071230713307143071530716307173071830719307203072130722307233072430725307263072730728307293073030731307323073330734307353073630737307383073930740307413074230743307443074530746307473074830749307503075130752307533075430755307563075730758307593076030761307623076330764307653076630767307683076930770307713077230773307743077530776307773077830779307803078130782307833078430785307863078730788307893079030791307923079330794307953079630797307983079930800308013080230803308043080530806308073080830809308103081130812308133081430815308163081730818308193082030821308223082330824308253082630827308283082930830308313083230833308343083530836308373083830839308403084130842308433084430845308463084730848308493085030851308523085330854308553085630857308583085930860308613086230863308643086530866308673086830869308703087130872308733087430875308763087730878308793088030881308823088330884308853088630887308883088930890308913089230893308943089530896308973089830899309003090130902309033090430905309063090730908309093091030911309123091330914309153091630917309183091930920309213092230923309243092530926309273092830929309303093130932309333093430935309363093730938309393094030941309423094330944309453094630947309483094930950309513095230953309543095530956309573095830959309603096130962309633096430965309663096730968309693097030971309723097330974309753097630977309783097930980309813098230983309843098530986309873098830989309903099130992309933099430995309963099730998309993100031001310023100331004310053100631007310083100931010310113101231013310143101531016310173101831019310203102131022310233102431025310263102731028310293103031031310323103331034310353103631037310383103931040310413104231043310443104531046310473104831049310503105131052310533105431055310563105731058310593106031061310623106331064310653106631067310683106931070310713107231073310743107531076310773107831079310803108131082310833108431085310863108731088310893109031091310923109331094310953109631097310983109931100311013110231103311043110531106311073110831109311103111131112311133111431115311163111731118311193112031121311223112331124311253112631127311283112931130311313113231133311343113531136311373113831139311403114131142311433114431145311463114731148311493115031151311523115331154311553115631157311583115931160311613116231163311643116531166311673116831169311703117131172311733117431175311763117731178311793118031181311823118331184311853118631187311883118931190311913119231193311943119531196311973119831199312003120131202312033120431205312063120731208312093121031211312123121331214312153121631217312183121931220312213122231223312243122531226312273122831229312303123131232312333123431235312363123731238312393124031241312423124331244312453124631247312483124931250312513125231253312543125531256312573125831259312603126131262312633126431265312663126731268312693127031271312723127331274312753127631277312783127931280312813128231283312843128531286312873128831289312903129131292312933129431295312963129731298312993130031301313023130331304313053130631307313083130931310313113131231313313143131531316313173131831319313203132131322313233132431325313263132731328313293133031331313323133331334313353133631337313383133931340313413134231343313443134531346313473134831349313503135131352313533135431355313563135731358313593136031361313623136331364313653136631367313683136931370313713137231373313743137531376313773137831379313803138131382313833138431385313863138731388313893139031391313923139331394313953139631397313983139931400314013140231403314043140531406314073140831409314103141131412314133141431415314163141731418314193142031421314223142331424314253142631427314283142931430314313143231433314343143531436314373143831439314403144131442314433144431445314463144731448314493145031451314523145331454314553145631457314583145931460314613146231463314643146531466314673146831469314703147131472314733147431475314763147731478314793148031481314823148331484314853148631487314883148931490314913149231493314943149531496314973149831499315003150131502315033150431505315063150731508315093151031511315123151331514315153151631517315183151931520315213152231523315243152531526315273152831529315303153131532315333153431535315363153731538315393154031541315423154331544315453154631547315483154931550315513155231553315543155531556315573155831559315603156131562315633156431565315663156731568315693157031571315723157331574315753157631577315783157931580315813158231583315843158531586315873158831589315903159131592315933159431595315963159731598315993160031601316023160331604316053160631607316083160931610316113161231613316143161531616316173161831619316203162131622316233162431625316263162731628316293163031631316323163331634316353163631637316383163931640316413164231643316443164531646316473164831649316503165131652316533165431655316563165731658316593166031661316623166331664316653166631667316683166931670316713167231673316743167531676316773167831679316803168131682316833168431685316863168731688316893169031691316923169331694316953169631697316983169931700317013170231703317043170531706317073170831709317103171131712317133171431715317163171731718317193172031721317223172331724317253172631727317283172931730317313173231733317343173531736317373173831739317403174131742317433174431745317463174731748317493175031751317523175331754317553175631757317583175931760317613176231763317643176531766317673176831769317703177131772317733177431775317763177731778317793178031781317823178331784317853178631787317883178931790317913179231793317943179531796317973179831799318003180131802318033180431805318063180731808318093181031811318123181331814318153181631817318183181931820318213182231823318243182531826318273182831829318303183131832318333183431835318363183731838318393184031841318423184331844318453184631847318483184931850318513185231853318543185531856318573185831859318603186131862318633186431865318663186731868318693187031871318723187331874318753187631877318783187931880318813188231883318843188531886318873188831889318903189131892318933189431895318963189731898318993190031901319023190331904319053190631907319083190931910319113191231913319143191531916319173191831919319203192131922319233192431925319263192731928319293193031931319323193331934319353193631937319383193931940319413194231943319443194531946319473194831949319503195131952319533195431955319563195731958319593196031961319623196331964319653196631967319683196931970319713197231973319743197531976319773197831979319803198131982319833198431985319863198731988319893199031991319923199331994319953199631997319983199932000320013200232003320043200532006320073200832009320103201132012320133201432015320163201732018320193202032021320223202332024320253202632027320283202932030320313203232033320343203532036320373203832039320403204132042320433204432045320463204732048320493205032051320523205332054320553205632057320583205932060320613206232063320643206532066320673206832069320703207132072320733207432075320763207732078320793208032081320823208332084320853208632087320883208932090320913209232093320943209532096320973209832099321003210132102321033210432105321063210732108321093211032111321123211332114321153211632117321183211932120321213212232123321243212532126321273212832129321303213132132321333213432135321363213732138321393214032141321423214332144321453214632147321483214932150321513215232153321543215532156321573215832159321603216132162321633216432165321663216732168321693217032171321723217332174321753217632177321783217932180321813218232183321843218532186321873218832189321903219132192321933219432195321963219732198321993220032201322023220332204322053220632207322083220932210322113221232213322143221532216322173221832219322203222132222322233222432225322263222732228322293223032231322323223332234322353223632237322383223932240322413224232243322443224532246322473224832249322503225132252322533225432255322563225732258322593226032261322623226332264322653226632267322683226932270322713227232273322743227532276322773227832279322803228132282322833228432285322863228732288322893229032291322923229332294322953229632297322983229932300323013230232303323043230532306323073230832309323103231132312323133231432315323163231732318323193232032321323223232332324323253232632327323283232932330323313233232333323343233532336323373233832339323403234132342323433234432345323463234732348323493235032351323523235332354323553235632357323583235932360323613236232363323643236532366323673236832369323703237132372323733237432375323763237732378323793238032381323823238332384323853238632387323883238932390323913239232393323943239532396323973239832399324003240132402324033240432405324063240732408324093241032411324123241332414324153241632417324183241932420324213242232423324243242532426324273242832429324303243132432324333243432435324363243732438324393244032441324423244332444324453244632447324483244932450324513245232453324543245532456324573245832459324603246132462324633246432465324663246732468324693247032471324723247332474324753247632477324783247932480324813248232483324843248532486324873248832489324903249132492324933249432495324963249732498324993250032501325023250332504325053250632507325083250932510325113251232513325143251532516325173251832519325203252132522325233252432525325263252732528325293253032531325323253332534325353253632537325383253932540325413254232543325443254532546325473254832549325503255132552325533255432555325563255732558325593256032561325623256332564325653256632567325683256932570325713257232573325743257532576325773257832579325803258132582325833258432585325863258732588325893259032591325923259332594325953259632597325983259932600326013260232603326043260532606326073260832609326103261132612326133261432615326163261732618326193262032621326223262332624326253262632627326283262932630326313263232633326343263532636326373263832639326403264132642326433264432645326463264732648326493265032651326523265332654326553265632657326583265932660326613266232663326643266532666326673266832669326703267132672326733267432675326763267732678326793268032681326823268332684326853268632687326883268932690326913269232693326943269532696326973269832699327003270132702327033270432705327063270732708327093271032711327123271332714327153271632717327183271932720327213272232723327243272532726327273272832729327303273132732327333273432735327363273732738327393274032741327423274332744327453274632747327483274932750327513275232753327543275532756327573275832759327603276132762327633276432765327663276732768327693277032771327723277332774327753277632777327783277932780327813278232783327843278532786327873278832789327903279132792327933279432795327963279732798327993280032801328023280332804328053280632807328083280932810328113281232813328143281532816328173281832819328203282132822328233282432825328263282732828328293283032831328323283332834328353283632837328383283932840328413284232843328443284532846328473284832849328503285132852328533285432855328563285732858328593286032861328623286332864328653286632867328683286932870328713287232873328743287532876328773287832879328803288132882328833288432885328863288732888328893289032891328923289332894328953289632897328983289932900329013290232903329043290532906329073290832909329103291132912329133291432915329163291732918329193292032921329223292332924329253292632927329283292932930329313293232933329343293532936329373293832939329403294132942329433294432945329463294732948329493295032951329523295332954329553295632957329583295932960329613296232963329643296532966329673296832969329703297132972329733297432975329763297732978329793298032981329823298332984329853298632987329883298932990329913299232993329943299532996329973299832999330003300133002330033300433005330063300733008330093301033011330123301333014330153301633017330183301933020330213302233023330243302533026330273302833029330303303133032330333303433035330363303733038330393304033041330423304333044330453304633047330483304933050330513305233053330543305533056330573305833059330603306133062330633306433065330663306733068330693307033071330723307333074330753307633077330783307933080330813308233083330843308533086330873308833089330903309133092330933309433095330963309733098330993310033101331023310333104331053310633107331083310933110331113311233113331143311533116331173311833119331203312133122331233312433125331263312733128331293313033131331323313333134331353313633137331383313933140331413314233143331443314533146331473314833149331503315133152331533315433155331563315733158331593316033161331623316333164331653316633167331683316933170331713317233173331743317533176331773317833179331803318133182331833318433185331863318733188331893319033191331923319333194331953319633197331983319933200332013320233203332043320533206332073320833209332103321133212332133321433215332163321733218332193322033221332223322333224332253322633227332283322933230332313323233233332343323533236332373323833239332403324133242332433324433245332463324733248332493325033251332523325333254332553325633257332583325933260332613326233263332643326533266332673326833269332703327133272332733327433275332763327733278332793328033281332823328333284332853328633287332883328933290332913329233293332943329533296332973329833299333003330133302333033330433305333063330733308333093331033311333123331333314333153331633317333183331933320333213332233323333243332533326333273332833329333303333133332333333333433335333363333733338333393334033341333423334333344333453334633347333483334933350333513335233353333543335533356333573335833359333603336133362333633336433365333663336733368333693337033371333723337333374333753337633377333783337933380333813338233383333843338533386333873338833389333903339133392333933339433395333963339733398333993340033401334023340333404334053340633407334083340933410334113341233413334143341533416334173341833419334203342133422334233342433425334263342733428334293343033431334323343333434334353343633437334383343933440334413344233443334443344533446334473344833449334503345133452334533345433455334563345733458334593346033461334623346333464334653346633467334683346933470334713347233473334743347533476334773347833479334803348133482334833348433485334863348733488334893349033491334923349333494334953349633497334983349933500335013350233503335043350533506335073350833509335103351133512335133351433515335163351733518335193352033521335223352333524335253352633527335283352933530335313353233533335343353533536335373353833539335403354133542335433354433545335463354733548335493355033551335523355333554335553355633557335583355933560335613356233563335643356533566335673356833569335703357133572335733357433575335763357733578335793358033581335823358333584335853358633587335883358933590335913359233593335943359533596335973359833599336003360133602336033360433605336063360733608336093361033611336123361333614336153361633617336183361933620336213362233623336243362533626336273362833629336303363133632336333363433635336363363733638336393364033641336423364333644336453364633647336483364933650336513365233653336543365533656336573365833659336603366133662336633366433665336663366733668336693367033671336723367333674336753367633677336783367933680336813368233683336843368533686336873368833689336903369133692336933369433695336963369733698336993370033701337023370333704337053370633707337083370933710337113371233713337143371533716337173371833719337203372133722337233372433725337263372733728337293373033731337323373333734337353373633737337383373933740337413374233743337443374533746337473374833749337503375133752337533375433755337563375733758337593376033761337623376333764337653376633767337683376933770337713377233773337743377533776337773377833779337803378133782337833378433785337863378733788337893379033791337923379333794337953379633797337983379933800338013380233803338043380533806338073380833809338103381133812338133381433815338163381733818338193382033821338223382333824338253382633827338283382933830338313383233833338343383533836338373383833839338403384133842338433384433845338463384733848338493385033851338523385333854338553385633857338583385933860338613386233863338643386533866338673386833869338703387133872338733387433875338763387733878338793388033881338823388333884338853388633887338883388933890338913389233893338943389533896338973389833899339003390133902339033390433905339063390733908339093391033911339123391333914339153391633917339183391933920339213392233923339243392533926339273392833929339303393133932339333393433935339363393733938339393394033941339423394333944339453394633947339483394933950339513395233953339543395533956339573395833959339603396133962339633396433965339663396733968339693397033971339723397333974339753397633977339783397933980339813398233983339843398533986339873398833989339903399133992339933399433995339963399733998339993400034001340023400334004340053400634007340083400934010340113401234013340143401534016340173401834019340203402134022340233402434025340263402734028340293403034031340323403334034340353403634037340383403934040340413404234043340443404534046340473404834049340503405134052340533405434055340563405734058340593406034061340623406334064340653406634067340683406934070340713407234073340743407534076340773407834079340803408134082340833408434085340863408734088340893409034091340923409334094340953409634097340983409934100341013410234103341043410534106341073410834109341103411134112341133411434115341163411734118341193412034121341223412334124341253412634127341283412934130341313413234133341343413534136341373413834139341403414134142341433414434145341463414734148341493415034151341523415334154341553415634157341583415934160341613416234163341643416534166341673416834169341703417134172341733417434175341763417734178341793418034181341823418334184341853418634187341883418934190341913419234193341943419534196341973419834199342003420134202342033420434205342063420734208342093421034211342123421334214342153421634217342183421934220342213422234223342243422534226342273422834229342303423134232342333423434235342363423734238342393424034241342423424334244342453424634247342483424934250342513425234253342543425534256342573425834259342603426134262342633426434265342663426734268342693427034271342723427334274342753427634277342783427934280342813428234283342843428534286342873428834289342903429134292342933429434295342963429734298342993430034301343023430334304343053430634307343083430934310343113431234313343143431534316343173431834319343203432134322343233432434325343263432734328343293433034331343323433334334343353433634337343383433934340343413434234343343443434534346343473434834349343503435134352343533435434355343563435734358343593436034361343623436334364343653436634367343683436934370343713437234373343743437534376343773437834379343803438134382343833438434385343863438734388343893439034391343923439334394343953439634397343983439934400344013440234403344043440534406344073440834409344103441134412344133441434415344163441734418344193442034421344223442334424344253442634427344283442934430344313443234433344343443534436344373443834439344403444134442344433444434445344463444734448344493445034451344523445334454344553445634457344583445934460344613446234463344643446534466344673446834469344703447134472344733447434475344763447734478344793448034481344823448334484344853448634487344883448934490344913449234493344943449534496344973449834499345003450134502345033450434505345063450734508345093451034511345123451334514345153451634517345183451934520345213452234523345243452534526345273452834529345303453134532345333453434535345363453734538345393454034541345423454334544345453454634547345483454934550345513455234553345543455534556345573455834559345603456134562345633456434565345663456734568345693457034571345723457334574345753457634577345783457934580345813458234583345843458534586345873458834589345903459134592345933459434595345963459734598345993460034601346023460334604346053460634607346083460934610346113461234613346143461534616346173461834619346203462134622346233462434625346263462734628346293463034631346323463334634346353463634637346383463934640346413464234643346443464534646346473464834649346503465134652346533465434655346563465734658346593466034661346623466334664346653466634667346683466934670346713467234673346743467534676346773467834679346803468134682346833468434685346863468734688346893469034691346923469334694346953469634697346983469934700347013470234703347043470534706347073470834709347103471134712347133471434715347163471734718347193472034721347223472334724347253472634727347283472934730347313473234733347343473534736347373473834739347403474134742347433474434745347463474734748347493475034751347523475334754347553475634757347583475934760347613476234763347643476534766347673476834769347703477134772347733477434775347763477734778347793478034781347823478334784347853478634787347883478934790347913479234793347943479534796347973479834799348003480134802348033480434805348063480734808348093481034811348123481334814348153481634817348183481934820348213482234823348243482534826348273482834829348303483134832348333483434835348363483734838348393484034841348423484334844348453484634847348483484934850348513485234853348543485534856348573485834859348603486134862348633486434865348663486734868348693487034871348723487334874348753487634877348783487934880348813488234883348843488534886348873488834889348903489134892348933489434895348963489734898348993490034901349023490334904349053490634907349083490934910349113491234913349143491534916349173491834919349203492134922349233492434925349263492734928349293493034931349323493334934349353493634937349383493934940349413494234943349443494534946349473494834949349503495134952349533495434955349563495734958349593496034961349623496334964349653496634967349683496934970349713497234973349743497534976349773497834979349803498134982349833498434985349863498734988349893499034991349923499334994349953499634997349983499935000350013500235003350043500535006350073500835009350103501135012350133501435015350163501735018350193502035021350223502335024350253502635027350283502935030350313503235033350343503535036350373503835039350403504135042350433504435045350463504735048350493505035051350523505335054350553505635057350583505935060350613506235063350643506535066350673506835069350703507135072350733507435075350763507735078350793508035081350823508335084350853508635087350883508935090350913509235093350943509535096350973509835099351003510135102351033510435105351063510735108351093511035111351123511335114351153511635117351183511935120351213512235123351243512535126351273512835129351303513135132351333513435135351363513735138351393514035141351423514335144351453514635147351483514935150351513515235153351543515535156351573515835159351603516135162351633516435165351663516735168351693517035171351723517335174351753517635177351783517935180351813518235183351843518535186351873518835189351903519135192351933519435195351963519735198351993520035201352023520335204352053520635207352083520935210352113521235213352143521535216352173521835219352203522135222352233522435225352263522735228352293523035231352323523335234352353523635237352383523935240352413524235243352443524535246352473524835249352503525135252352533525435255352563525735258352593526035261352623526335264352653526635267352683526935270352713527235273352743527535276352773527835279352803528135282352833528435285352863528735288352893529035291352923529335294352953529635297352983529935300353013530235303353043530535306353073530835309353103531135312353133531435315353163531735318353193532035321353223532335324353253532635327353283532935330353313533235333353343533535336353373533835339353403534135342353433534435345353463534735348353493535035351353523535335354353553535635357353583535935360353613536235363353643536535366353673536835369353703537135372353733537435375353763537735378353793538035381353823538335384353853538635387353883538935390353913539235393353943539535396353973539835399354003540135402354033540435405354063540735408354093541035411354123541335414354153541635417354183541935420354213542235423354243542535426354273542835429354303543135432354333543435435354363543735438354393544035441354423544335444354453544635447354483544935450354513545235453354543545535456354573545835459354603546135462354633546435465354663546735468354693547035471354723547335474354753547635477354783547935480354813548235483354843548535486354873548835489354903549135492354933549435495354963549735498354993550035501355023550335504355053550635507355083550935510355113551235513355143551535516355173551835519355203552135522355233552435525355263552735528355293553035531355323553335534355353553635537355383553935540355413554235543355443554535546355473554835549355503555135552355533555435555355563555735558355593556035561355623556335564355653556635567355683556935570355713557235573355743557535576355773557835579355803558135582355833558435585355863558735588355893559035591355923559335594355953559635597355983559935600356013560235603356043560535606356073560835609356103561135612356133561435615356163561735618356193562035621356223562335624356253562635627356283562935630356313563235633356343563535636356373563835639356403564135642356433564435645356463564735648356493565035651356523565335654356553565635657356583565935660356613566235663356643566535666356673566835669356703567135672356733567435675356763567735678356793568035681356823568335684356853568635687356883568935690356913569235693356943569535696356973569835699357003570135702357033570435705357063570735708357093571035711357123571335714357153571635717357183571935720357213572235723357243572535726357273572835729357303573135732357333573435735357363573735738357393574035741357423574335744357453574635747357483574935750357513575235753357543575535756357573575835759357603576135762357633576435765357663576735768357693577035771357723577335774357753577635777357783577935780357813578235783357843578535786357873578835789357903579135792357933579435795357963579735798357993580035801358023580335804358053580635807358083580935810358113581235813358143581535816358173581835819358203582135822358233582435825358263582735828358293583035831358323583335834358353583635837358383583935840358413584235843358443584535846358473584835849358503585135852358533585435855358563585735858358593586035861358623586335864358653586635867358683586935870358713587235873358743587535876358773587835879358803588135882358833588435885358863588735888358893589035891358923589335894358953589635897358983589935900359013590235903359043590535906359073590835909359103591135912359133591435915359163591735918359193592035921359223592335924359253592635927359283592935930359313593235933359343593535936359373593835939359403594135942359433594435945359463594735948359493595035951359523595335954359553595635957359583595935960359613596235963359643596535966359673596835969359703597135972359733597435975359763597735978359793598035981359823598335984359853598635987359883598935990359913599235993359943599535996359973599835999360003600136002360033600436005360063600736008360093601036011360123601336014360153601636017360183601936020360213602236023360243602536026360273602836029360303603136032360333603436035360363603736038360393604036041360423604336044360453604636047360483604936050360513605236053360543605536056360573605836059360603606136062360633606436065360663606736068360693607036071360723607336074360753607636077360783607936080360813608236083360843608536086360873608836089360903609136092360933609436095360963609736098360993610036101361023610336104361053610636107361083610936110361113611236113361143611536116361173611836119361203612136122361233612436125361263612736128361293613036131361323613336134361353613636137361383613936140361413614236143361443614536146361473614836149361503615136152361533615436155361563615736158361593616036161361623616336164361653616636167361683616936170361713617236173361743617536176361773617836179361803618136182361833618436185361863618736188361893619036191361923619336194361953619636197361983619936200362013620236203362043620536206362073620836209362103621136212362133621436215362163621736218362193622036221362223622336224362253622636227362283622936230362313623236233362343623536236362373623836239362403624136242362433624436245362463624736248362493625036251362523625336254362553625636257362583625936260362613626236263362643626536266362673626836269362703627136272362733627436275362763627736278362793628036281362823628336284362853628636287362883628936290362913629236293362943629536296362973629836299363003630136302363033630436305363063630736308363093631036311363123631336314363153631636317363183631936320363213632236323363243632536326363273632836329363303633136332363333633436335363363633736338363393634036341363423634336344363453634636347363483634936350363513635236353363543635536356363573635836359363603636136362363633636436365363663636736368363693637036371363723637336374363753637636377363783637936380363813638236383363843638536386363873638836389363903639136392363933639436395363963639736398363993640036401364023640336404364053640636407364083640936410364113641236413364143641536416364173641836419364203642136422364233642436425364263642736428364293643036431364323643336434364353643636437364383643936440364413644236443364443644536446364473644836449364503645136452364533645436455364563645736458364593646036461364623646336464364653646636467364683646936470364713647236473364743647536476364773647836479364803648136482364833648436485364863648736488364893649036491364923649336494364953649636497364983649936500365013650236503365043650536506365073650836509365103651136512365133651436515365163651736518365193652036521365223652336524365253652636527365283652936530365313653236533365343653536536365373653836539365403654136542365433654436545365463654736548365493655036551365523655336554365553655636557365583655936560365613656236563365643656536566365673656836569365703657136572365733657436575365763657736578365793658036581365823658336584365853658636587365883658936590365913659236593365943659536596365973659836599366003660136602366033660436605366063660736608366093661036611366123661336614366153661636617366183661936620366213662236623366243662536626366273662836629366303663136632366333663436635366363663736638366393664036641366423664336644366453664636647366483664936650366513665236653366543665536656366573665836659366603666136662366633666436665366663666736668366693667036671366723667336674366753667636677366783667936680366813668236683366843668536686366873668836689366903669136692366933669436695366963669736698366993670036701367023670336704367053670636707367083670936710367113671236713367143671536716367173671836719367203672136722367233672436725367263672736728367293673036731367323673336734367353673636737367383673936740367413674236743367443674536746367473674836749367503675136752367533675436755367563675736758367593676036761367623676336764367653676636767367683676936770367713677236773367743677536776367773677836779367803678136782367833678436785367863678736788367893679036791367923679336794367953679636797367983679936800368013680236803368043680536806368073680836809368103681136812368133681436815368163681736818368193682036821368223682336824368253682636827368283682936830368313683236833368343683536836368373683836839368403684136842368433684436845368463684736848368493685036851368523685336854368553685636857368583685936860368613686236863368643686536866368673686836869368703687136872368733687436875368763687736878368793688036881368823688336884368853688636887368883688936890368913689236893368943689536896368973689836899369003690136902369033690436905369063690736908369093691036911369123691336914369153691636917369183691936920369213692236923369243692536926369273692836929369303693136932369333693436935369363693736938369393694036941369423694336944369453694636947369483694936950369513695236953369543695536956369573695836959369603696136962369633696436965369663696736968369693697036971369723697336974369753697636977369783697936980369813698236983369843698536986369873698836989369903699136992369933699436995369963699736998369993700037001370023700337004370053700637007370083700937010370113701237013370143701537016370173701837019370203702137022370233702437025370263702737028370293703037031370323703337034370353703637037370383703937040370413704237043370443704537046370473704837049370503705137052370533705437055370563705737058370593706037061370623706337064370653706637067370683706937070370713707237073370743707537076370773707837079370803708137082370833708437085370863708737088370893709037091370923709337094370953709637097370983709937100371013710237103371043710537106371073710837109371103711137112371133711437115371163711737118371193712037121371223712337124371253712637127371283712937130371313713237133371343713537136371373713837139371403714137142371433714437145371463714737148371493715037151371523715337154371553715637157371583715937160371613716237163371643716537166371673716837169371703717137172371733717437175371763717737178371793718037181371823718337184371853718637187371883718937190371913719237193371943719537196371973719837199372003720137202372033720437205372063720737208372093721037211372123721337214372153721637217372183721937220372213722237223372243722537226372273722837229372303723137232372333723437235372363723737238372393724037241372423724337244372453724637247372483724937250372513725237253372543725537256372573725837259372603726137262372633726437265372663726737268372693727037271372723727337274372753727637277372783727937280372813728237283372843728537286372873728837289372903729137292372933729437295372963729737298372993730037301373023730337304373053730637307373083730937310373113731237313373143731537316373173731837319373203732137322373233732437325373263732737328373293733037331373323733337334373353733637337373383733937340373413734237343373443734537346373473734837349373503735137352373533735437355373563735737358373593736037361373623736337364373653736637367373683736937370373713737237373373743737537376373773737837379373803738137382373833738437385373863738737388373893739037391373923739337394373953739637397373983739937400374013740237403374043740537406374073740837409374103741137412374133741437415374163741737418374193742037421374223742337424374253742637427374283742937430374313743237433374343743537436374373743837439374403744137442374433744437445374463744737448374493745037451374523745337454374553745637457374583745937460374613746237463374643746537466374673746837469374703747137472374733747437475374763747737478374793748037481374823748337484374853748637487374883748937490374913749237493374943749537496374973749837499375003750137502375033750437505375063750737508375093751037511375123751337514375153751637517375183751937520375213752237523375243752537526375273752837529375303753137532375333753437535375363753737538375393754037541375423754337544375453754637547375483754937550375513755237553375543755537556375573755837559375603756137562375633756437565375663756737568375693757037571375723757337574375753757637577375783757937580375813758237583375843758537586375873758837589375903759137592375933759437595375963759737598375993760037601376023760337604376053760637607376083760937610376113761237613376143761537616376173761837619376203762137622376233762437625376263762737628376293763037631376323763337634376353763637637376383763937640376413764237643376443764537646376473764837649376503765137652376533765437655376563765737658376593766037661376623766337664376653766637667376683766937670376713767237673376743767537676376773767837679376803768137682376833768437685376863768737688376893769037691376923769337694376953769637697376983769937700377013770237703377043770537706377073770837709377103771137712377133771437715377163771737718377193772037721377223772337724377253772637727377283772937730377313773237733377343773537736377373773837739377403774137742377433774437745377463774737748377493775037751377523775337754377553775637757377583775937760377613776237763377643776537766377673776837769377703777137772377733777437775377763777737778377793778037781377823778337784377853778637787377883778937790377913779237793377943779537796377973779837799378003780137802378033780437805378063780737808378093781037811378123781337814378153781637817378183781937820378213782237823378243782537826378273782837829378303783137832378333783437835378363783737838378393784037841378423784337844378453784637847378483784937850378513785237853378543785537856378573785837859378603786137862378633786437865378663786737868378693787037871378723787337874378753787637877378783787937880378813788237883378843788537886378873788837889378903789137892378933789437895378963789737898378993790037901379023790337904379053790637907379083790937910379113791237913379143791537916379173791837919379203792137922379233792437925379263792737928379293793037931379323793337934379353793637937379383793937940379413794237943379443794537946379473794837949379503795137952379533795437955379563795737958379593796037961379623796337964379653796637967379683796937970379713797237973379743797537976379773797837979379803798137982379833798437985379863798737988379893799037991379923799337994379953799637997379983799938000380013800238003380043800538006380073800838009380103801138012380133801438015380163801738018380193802038021380223802338024380253802638027380283802938030380313803238033380343803538036380373803838039380403804138042380433804438045380463804738048380493805038051380523805338054380553805638057380583805938060380613806238063380643806538066380673806838069380703807138072380733807438075380763807738078380793808038081380823808338084380853808638087380883808938090380913809238093380943809538096380973809838099381003810138102381033810438105381063810738108381093811038111381123811338114381153811638117381183811938120381213812238123381243812538126381273812838129381303813138132381333813438135381363813738138381393814038141381423814338144381453814638147381483814938150381513815238153381543815538156381573815838159381603816138162381633816438165381663816738168381693817038171381723817338174381753817638177381783817938180381813818238183381843818538186381873818838189381903819138192381933819438195381963819738198381993820038201382023820338204382053820638207382083820938210382113821238213382143821538216382173821838219382203822138222382233822438225382263822738228382293823038231382323823338234382353823638237382383823938240382413824238243382443824538246382473824838249382503825138252382533825438255382563825738258382593826038261382623826338264382653826638267382683826938270382713827238273382743827538276382773827838279382803828138282382833828438285382863828738288382893829038291382923829338294382953829638297382983829938300383013830238303383043830538306383073830838309383103831138312383133831438315383163831738318383193832038321383223832338324383253832638327383283832938330383313833238333383343833538336383373833838339383403834138342383433834438345383463834738348383493835038351383523835338354383553835638357383583835938360383613836238363383643836538366383673836838369383703837138372383733837438375383763837738378383793838038381383823838338384383853838638387383883838938390383913839238393383943839538396383973839838399384003840138402384033840438405384063840738408384093841038411384123841338414384153841638417384183841938420384213842238423384243842538426384273842838429384303843138432384333843438435384363843738438384393844038441384423844338444384453844638447384483844938450384513845238453384543845538456384573845838459384603846138462384633846438465384663846738468384693847038471384723847338474384753847638477384783847938480384813848238483384843848538486384873848838489384903849138492384933849438495384963849738498384993850038501385023850338504385053850638507385083850938510385113851238513385143851538516385173851838519385203852138522385233852438525385263852738528385293853038531385323853338534385353853638537385383853938540385413854238543385443854538546385473854838549385503855138552385533855438555385563855738558385593856038561385623856338564385653856638567385683856938570385713857238573385743857538576385773857838579385803858138582385833858438585385863858738588385893859038591385923859338594385953859638597385983859938600386013860238603386043860538606386073860838609386103861138612386133861438615386163861738618386193862038621386223862338624386253862638627386283862938630386313863238633386343863538636386373863838639386403864138642386433864438645386463864738648386493865038651386523865338654386553865638657386583865938660386613866238663386643866538666386673866838669386703867138672386733867438675386763867738678386793868038681386823868338684386853868638687386883868938690386913869238693386943869538696386973869838699387003870138702387033870438705387063870738708387093871038711387123871338714387153871638717387183871938720387213872238723387243872538726387273872838729387303873138732387333873438735387363873738738387393874038741387423874338744387453874638747387483874938750387513875238753387543875538756387573875838759387603876138762387633876438765387663876738768387693877038771387723877338774387753877638777387783877938780387813878238783387843878538786387873878838789387903879138792387933879438795387963879738798387993880038801388023880338804388053880638807388083880938810388113881238813388143881538816388173881838819388203882138822388233882438825388263882738828388293883038831388323883338834388353883638837388383883938840388413884238843388443884538846388473884838849388503885138852388533885438855388563885738858388593886038861388623886338864388653886638867388683886938870388713887238873388743887538876388773887838879388803888138882388833888438885388863888738888388893889038891388923889338894388953889638897388983889938900389013890238903389043890538906389073890838909389103891138912389133891438915389163891738918389193892038921389223892338924389253892638927389283892938930389313893238933389343893538936389373893838939389403894138942389433894438945389463894738948389493895038951389523895338954389553895638957389583895938960389613896238963389643896538966389673896838969389703897138972389733897438975389763897738978389793898038981389823898338984389853898638987389883898938990389913899238993389943899538996389973899838999390003900139002390033900439005390063900739008390093901039011390123901339014390153901639017390183901939020390213902239023390243902539026390273902839029390303903139032390333903439035390363903739038390393904039041390423904339044390453904639047390483904939050390513905239053390543905539056390573905839059390603906139062390633906439065390663906739068390693907039071390723907339074390753907639077390783907939080390813908239083390843908539086390873908839089390903909139092390933909439095390963909739098390993910039101391023910339104391053910639107391083910939110391113911239113391143911539116391173911839119391203912139122391233912439125391263912739128391293913039131391323913339134391353913639137391383913939140391413914239143391443914539146391473914839149391503915139152391533915439155391563915739158391593916039161391623916339164391653916639167391683916939170391713917239173391743917539176391773917839179391803918139182391833918439185391863918739188391893919039191391923919339194391953919639197391983919939200392013920239203392043920539206392073920839209392103921139212392133921439215392163921739218392193922039221392223922339224392253922639227392283922939230392313923239233392343923539236392373923839239392403924139242392433924439245392463924739248392493925039251392523925339254392553925639257392583925939260392613926239263392643926539266392673926839269392703927139272392733927439275392763927739278392793928039281392823928339284392853928639287392883928939290392913929239293392943929539296392973929839299393003930139302393033930439305393063930739308393093931039311393123931339314393153931639317393183931939320393213932239323393243932539326393273932839329393303933139332393333933439335393363933739338393393934039341393423934339344393453934639347393483934939350393513935239353393543935539356393573935839359393603936139362393633936439365393663936739368393693937039371393723937339374393753937639377393783937939380393813938239383393843938539386393873938839389393903939139392393933939439395393963939739398393993940039401394023940339404394053940639407394083940939410394113941239413394143941539416394173941839419394203942139422394233942439425394263942739428394293943039431394323943339434394353943639437394383943939440394413944239443394443944539446394473944839449394503945139452394533945439455394563945739458394593946039461394623946339464394653946639467394683946939470394713947239473394743947539476394773947839479394803948139482394833948439485394863948739488394893949039491394923949339494394953949639497394983949939500395013950239503395043950539506395073950839509395103951139512395133951439515395163951739518395193952039521395223952339524395253952639527395283952939530395313953239533395343953539536395373953839539395403954139542395433954439545395463954739548395493955039551395523955339554395553955639557395583955939560395613956239563395643956539566395673956839569395703957139572395733957439575395763957739578395793958039581395823958339584395853958639587395883958939590395913959239593395943959539596395973959839599396003960139602396033960439605396063960739608396093961039611396123961339614396153961639617396183961939620396213962239623396243962539626396273962839629396303963139632396333963439635396363963739638396393964039641396423964339644396453964639647396483964939650396513965239653396543965539656396573965839659396603966139662396633966439665396663966739668396693967039671396723967339674396753967639677396783967939680396813968239683396843968539686396873968839689396903969139692396933969439695396963969739698396993970039701397023970339704397053970639707397083970939710397113971239713397143971539716397173971839719397203972139722397233972439725397263972739728397293973039731397323973339734397353973639737397383973939740397413974239743397443974539746397473974839749397503975139752397533975439755397563975739758397593976039761397623976339764397653976639767397683976939770397713977239773397743977539776397773977839779397803978139782397833978439785397863978739788397893979039791397923979339794397953979639797397983979939800398013980239803398043980539806398073980839809398103981139812398133981439815398163981739818398193982039821398223982339824398253982639827398283982939830398313983239833398343983539836398373983839839398403984139842398433984439845398463984739848398493985039851398523985339854398553985639857398583985939860398613986239863398643986539866398673986839869398703987139872398733987439875398763987739878398793988039881398823988339884398853988639887398883988939890398913989239893398943989539896398973989839899399003990139902399033990439905399063990739908399093991039911399123991339914399153991639917399183991939920399213992239923399243992539926399273992839929399303993139932399333993439935399363993739938399393994039941399423994339944399453994639947399483994939950399513995239953399543995539956399573995839959399603996139962399633996439965399663996739968399693997039971399723997339974399753997639977399783997939980399813998239983399843998539986399873998839989399903999139992399933999439995399963999739998399994000040001400024000340004400054000640007400084000940010400114001240013400144001540016400174001840019400204002140022400234002440025400264002740028400294003040031400324003340034400354003640037400384003940040400414004240043400444004540046400474004840049400504005140052400534005440055400564005740058400594006040061400624006340064400654006640067400684006940070400714007240073400744007540076400774007840079400804008140082400834008440085400864008740088400894009040091400924009340094400954009640097400984009940100401014010240103401044010540106401074010840109401104011140112401134011440115401164011740118401194012040121401224012340124401254012640127401284012940130401314013240133401344013540136401374013840139401404014140142401434014440145401464014740148401494015040151401524015340154401554015640157401584015940160401614016240163401644016540166401674016840169401704017140172401734017440175401764017740178401794018040181401824018340184401854018640187401884018940190401914019240193401944019540196401974019840199402004020140202402034020440205402064020740208402094021040211402124021340214402154021640217402184021940220402214022240223402244022540226402274022840229402304023140232402334023440235402364023740238402394024040241402424024340244402454024640247402484024940250402514025240253402544025540256402574025840259402604026140262402634026440265402664026740268402694027040271402724027340274402754027640277402784027940280402814028240283402844028540286402874028840289402904029140292402934029440295402964029740298402994030040301403024030340304403054030640307403084030940310403114031240313403144031540316403174031840319403204032140322403234032440325403264032740328403294033040331403324033340334403354033640337403384033940340403414034240343403444034540346403474034840349403504035140352403534035440355403564035740358403594036040361403624036340364403654036640367403684036940370403714037240373403744037540376403774037840379403804038140382403834038440385403864038740388403894039040391403924039340394403954039640397403984039940400404014040240403404044040540406404074040840409404104041140412404134041440415404164041740418404194042040421404224042340424404254042640427404284042940430404314043240433404344043540436404374043840439404404044140442404434044440445404464044740448404494045040451404524045340454404554045640457404584045940460404614046240463404644046540466404674046840469404704047140472404734047440475404764047740478404794048040481404824048340484404854048640487404884048940490404914049240493404944049540496404974049840499405004050140502405034050440505405064050740508405094051040511405124051340514405154051640517405184051940520405214052240523405244052540526405274052840529405304053140532405334053440535405364053740538405394054040541405424054340544405454054640547405484054940550405514055240553405544055540556405574055840559405604056140562405634056440565405664056740568405694057040571405724057340574405754057640577405784057940580405814058240583405844058540586405874058840589405904059140592405934059440595405964059740598405994060040601406024060340604406054060640607406084060940610406114061240613406144061540616406174061840619406204062140622406234062440625406264062740628406294063040631406324063340634406354063640637406384063940640406414064240643406444064540646406474064840649406504065140652406534065440655406564065740658406594066040661406624066340664406654066640667406684066940670406714067240673406744067540676406774067840679406804068140682406834068440685406864068740688406894069040691406924069340694406954069640697406984069940700407014070240703407044070540706407074070840709407104071140712407134071440715407164071740718407194072040721407224072340724407254072640727407284072940730407314073240733407344073540736407374073840739407404074140742407434074440745407464074740748407494075040751407524075340754407554075640757407584075940760407614076240763407644076540766407674076840769407704077140772407734077440775407764077740778407794078040781407824078340784407854078640787407884078940790407914079240793407944079540796407974079840799408004080140802408034080440805408064080740808408094081040811408124081340814408154081640817408184081940820408214082240823408244082540826408274082840829408304083140832408334083440835408364083740838408394084040841408424084340844408454084640847408484084940850408514085240853408544085540856408574085840859408604086140862408634086440865408664086740868408694087040871408724087340874408754087640877408784087940880408814088240883408844088540886408874088840889408904089140892408934089440895408964089740898408994090040901409024090340904409054090640907409084090940910409114091240913409144091540916409174091840919409204092140922409234092440925409264092740928409294093040931409324093340934409354093640937409384093940940409414094240943409444094540946409474094840949409504095140952409534095440955409564095740958409594096040961409624096340964409654096640967409684096940970409714097240973409744097540976409774097840979409804098140982409834098440985409864098740988409894099040991409924099340994409954099640997409984099941000410014100241003410044100541006410074100841009410104101141012410134101441015410164101741018410194102041021410224102341024410254102641027410284102941030410314103241033410344103541036410374103841039410404104141042410434104441045410464104741048410494105041051410524105341054410554105641057410584105941060410614106241063410644106541066410674106841069410704107141072410734107441075410764107741078410794108041081410824108341084410854108641087410884108941090410914109241093410944109541096410974109841099411004110141102411034110441105411064110741108411094111041111411124111341114411154111641117411184111941120411214112241123411244112541126411274112841129411304113141132411334113441135411364113741138411394114041141411424114341144411454114641147411484114941150411514115241153411544115541156411574115841159411604116141162411634116441165411664116741168411694117041171411724117341174411754117641177411784117941180411814118241183411844118541186411874118841189411904119141192411934119441195411964119741198411994120041201412024120341204412054120641207412084120941210412114121241213412144121541216412174121841219412204122141222412234122441225412264122741228412294123041231412324123341234412354123641237412384123941240412414124241243412444124541246412474124841249412504125141252412534125441255412564125741258412594126041261412624126341264412654126641267412684126941270412714127241273412744127541276412774127841279412804128141282412834128441285412864128741288412894129041291412924129341294412954129641297412984129941300413014130241303413044130541306413074130841309413104131141312413134131441315413164131741318413194132041321413224132341324413254132641327413284132941330413314133241333413344133541336413374133841339413404134141342413434134441345413464134741348413494135041351413524135341354413554135641357413584135941360413614136241363413644136541366413674136841369413704137141372413734137441375413764137741378413794138041381413824138341384413854138641387413884138941390413914139241393413944139541396413974139841399414004140141402414034140441405414064140741408414094141041411414124141341414414154141641417414184141941420414214142241423414244142541426414274142841429414304143141432414334143441435414364143741438414394144041441414424144341444414454144641447414484144941450414514145241453414544145541456414574145841459414604146141462414634146441465414664146741468414694147041471414724147341474414754147641477414784147941480414814148241483414844148541486414874148841489414904149141492414934149441495414964149741498414994150041501415024150341504415054150641507415084150941510415114151241513415144151541516415174151841519415204152141522415234152441525415264152741528415294153041531415324153341534415354153641537415384153941540415414154241543415444154541546415474154841549415504155141552415534155441555415564155741558415594156041561415624156341564415654156641567415684156941570415714157241573415744157541576415774157841579415804158141582415834158441585415864158741588415894159041591415924159341594415954159641597415984159941600416014160241603416044160541606416074160841609416104161141612416134161441615416164161741618416194162041621416224162341624416254162641627416284162941630416314163241633416344163541636416374163841639416404164141642416434164441645416464164741648416494165041651416524165341654416554165641657416584165941660416614166241663416644166541666416674166841669416704167141672416734167441675416764167741678416794168041681416824168341684416854168641687416884168941690416914169241693416944169541696416974169841699417004170141702417034170441705417064170741708417094171041711417124171341714417154171641717417184171941720417214172241723417244172541726417274172841729417304173141732417334173441735417364173741738417394174041741417424174341744417454174641747417484174941750417514175241753417544175541756417574175841759417604176141762417634176441765417664176741768417694177041771417724177341774417754177641777417784177941780417814178241783417844178541786417874178841789417904179141792417934179441795417964179741798417994180041801418024180341804418054180641807418084180941810418114181241813418144181541816418174181841819418204182141822418234182441825418264182741828418294183041831418324183341834418354183641837418384183941840418414184241843418444184541846418474184841849418504185141852418534185441855418564185741858418594186041861418624186341864418654186641867418684186941870418714187241873418744187541876418774187841879418804188141882418834188441885418864188741888418894189041891418924189341894418954189641897418984189941900419014190241903419044190541906419074190841909419104191141912419134191441915419164191741918419194192041921419224192341924419254192641927419284192941930419314193241933419344193541936419374193841939419404194141942419434194441945419464194741948419494195041951419524195341954419554195641957419584195941960419614196241963419644196541966419674196841969419704197141972419734197441975419764197741978419794198041981419824198341984419854198641987419884198941990419914199241993419944199541996419974199841999420004200142002420034200442005420064200742008420094201042011420124201342014420154201642017420184201942020420214202242023420244202542026420274202842029420304203142032420334203442035420364203742038420394204042041420424204342044420454204642047420484204942050420514205242053420544205542056420574205842059420604206142062420634206442065420664206742068420694207042071420724207342074420754207642077420784207942080420814208242083420844208542086420874208842089420904209142092420934209442095420964209742098420994210042101421024210342104421054210642107421084210942110421114211242113421144211542116421174211842119421204212142122421234212442125421264212742128421294213042131421324213342134421354213642137421384213942140421414214242143421444214542146421474214842149421504215142152421534215442155421564215742158421594216042161421624216342164421654216642167421684216942170421714217242173421744217542176421774217842179421804218142182421834218442185421864218742188421894219042191421924219342194421954219642197421984219942200422014220242203422044220542206422074220842209422104221142212422134221442215422164221742218422194222042221422224222342224422254222642227422284222942230422314223242233422344223542236422374223842239422404224142242422434224442245422464224742248422494225042251422524225342254422554225642257422584225942260422614226242263422644226542266422674226842269422704227142272422734227442275422764227742278422794228042281422824228342284422854228642287422884228942290422914229242293422944229542296422974229842299423004230142302423034230442305423064230742308423094231042311423124231342314423154231642317423184231942320423214232242323423244232542326423274232842329423304233142332423334233442335423364233742338423394234042341423424234342344423454234642347423484234942350423514235242353423544235542356423574235842359423604236142362423634236442365423664236742368423694237042371423724237342374423754237642377423784237942380423814238242383423844238542386423874238842389423904239142392423934239442395423964239742398423994240042401424024240342404424054240642407424084240942410424114241242413424144241542416424174241842419424204242142422424234242442425424264242742428424294243042431424324243342434424354243642437424384243942440424414244242443424444244542446424474244842449424504245142452424534245442455424564245742458424594246042461424624246342464424654246642467424684246942470424714247242473424744247542476424774247842479424804248142482424834248442485424864248742488424894249042491424924249342494424954249642497424984249942500425014250242503425044250542506425074250842509425104251142512425134251442515425164251742518425194252042521425224252342524425254252642527425284252942530425314253242533425344253542536425374253842539425404254142542425434254442545425464254742548425494255042551425524255342554425554255642557425584255942560425614256242563425644256542566425674256842569425704257142572425734257442575425764257742578425794258042581425824258342584425854258642587425884258942590425914259242593425944259542596425974259842599426004260142602426034260442605426064260742608426094261042611426124261342614426154261642617426184261942620426214262242623426244262542626426274262842629426304263142632426334263442635426364263742638426394264042641426424264342644426454264642647426484264942650426514265242653426544265542656426574265842659426604266142662426634266442665426664266742668426694267042671426724267342674426754267642677426784267942680426814268242683426844268542686426874268842689426904269142692426934269442695426964269742698426994270042701427024270342704427054270642707427084270942710427114271242713427144271542716427174271842719427204272142722427234272442725427264272742728427294273042731427324273342734427354273642737427384273942740427414274242743427444274542746427474274842749427504275142752427534275442755427564275742758427594276042761427624276342764427654276642767427684276942770427714277242773427744277542776427774277842779427804278142782427834278442785427864278742788427894279042791427924279342794427954279642797427984279942800428014280242803428044280542806428074280842809428104281142812428134281442815428164281742818428194282042821428224282342824428254282642827428284282942830428314283242833428344283542836428374283842839428404284142842428434284442845428464284742848428494285042851428524285342854428554285642857428584285942860428614286242863428644286542866428674286842869428704287142872428734287442875428764287742878428794288042881428824288342884428854288642887428884288942890428914289242893428944289542896428974289842899429004290142902429034290442905429064290742908429094291042911429124291342914429154291642917429184291942920429214292242923429244292542926429274292842929429304293142932429334293442935429364293742938429394294042941429424294342944429454294642947429484294942950429514295242953429544295542956429574295842959429604296142962429634296442965429664296742968429694297042971429724297342974429754297642977429784297942980429814298242983429844298542986429874298842989429904299142992429934299442995429964299742998429994300043001430024300343004430054300643007430084300943010430114301243013430144301543016430174301843019430204302143022430234302443025430264302743028430294303043031430324303343034430354303643037430384303943040430414304243043430444304543046430474304843049430504305143052430534305443055430564305743058430594306043061430624306343064430654306643067430684306943070430714307243073430744307543076430774307843079430804308143082430834308443085430864308743088430894309043091430924309343094430954309643097430984309943100431014310243103431044310543106431074310843109431104311143112431134311443115431164311743118431194312043121431224312343124431254312643127431284312943130431314313243133431344313543136431374313843139431404314143142431434314443145431464314743148431494315043151431524315343154431554315643157431584315943160431614316243163431644316543166431674316843169431704317143172431734317443175431764317743178431794318043181431824318343184431854318643187431884318943190431914319243193431944319543196431974319843199432004320143202432034320443205432064320743208432094321043211432124321343214432154321643217432184321943220432214322243223432244322543226432274322843229432304323143232432334323443235432364323743238432394324043241432424324343244432454324643247432484324943250432514325243253432544325543256432574325843259432604326143262432634326443265432664326743268432694327043271432724327343274432754327643277432784327943280432814328243283432844328543286432874328843289432904329143292432934329443295432964329743298432994330043301433024330343304433054330643307433084330943310433114331243313433144331543316433174331843319433204332143322433234332443325433264332743328433294333043331433324333343334433354333643337433384333943340433414334243343433444334543346433474334843349433504335143352433534335443355433564335743358433594336043361433624336343364433654336643367433684336943370433714337243373433744337543376433774337843379433804338143382433834338443385433864338743388433894339043391433924339343394433954339643397433984339943400434014340243403434044340543406434074340843409434104341143412434134341443415434164341743418434194342043421434224342343424434254342643427434284342943430434314343243433434344343543436434374343843439434404344143442434434344443445434464344743448434494345043451434524345343454434554345643457434584345943460434614346243463434644346543466434674346843469434704347143472434734347443475434764347743478434794348043481434824348343484434854348643487434884348943490434914349243493434944349543496434974349843499435004350143502435034350443505435064350743508435094351043511435124351343514435154351643517435184351943520435214352243523435244352543526435274352843529435304353143532435334353443535435364353743538435394354043541435424354343544435454354643547435484354943550435514355243553435544355543556435574355843559435604356143562435634356443565435664356743568435694357043571435724357343574435754357643577435784357943580435814358243583435844358543586435874358843589435904359143592435934359443595435964359743598435994360043601436024360343604436054360643607436084360943610436114361243613436144361543616436174361843619436204362143622436234362443625436264362743628436294363043631436324363343634436354363643637436384363943640436414364243643436444364543646436474364843649436504365143652436534365443655436564365743658436594366043661436624366343664436654366643667436684366943670436714367243673436744367543676436774367843679436804368143682436834368443685436864368743688436894369043691436924369343694436954369643697436984369943700437014370243703437044370543706437074370843709437104371143712437134371443715437164371743718437194372043721437224372343724437254372643727437284372943730437314373243733437344373543736437374373843739437404374143742437434374443745437464374743748437494375043751437524375343754437554375643757437584375943760437614376243763437644376543766437674376843769437704377143772437734377443775437764377743778437794378043781437824378343784437854378643787437884378943790437914379243793437944379543796437974379843799438004380143802438034380443805438064380743808438094381043811438124381343814438154381643817438184381943820438214382243823438244382543826438274382843829438304383143832438334383443835438364383743838438394384043841438424384343844438454384643847438484384943850438514385243853438544385543856438574385843859438604386143862438634386443865438664386743868438694387043871438724387343874438754387643877438784387943880438814388243883438844388543886438874388843889438904389143892438934389443895438964389743898438994390043901439024390343904439054390643907439084390943910439114391243913439144391543916439174391843919439204392143922439234392443925439264392743928439294393043931439324393343934439354393643937439384393943940439414394243943439444394543946439474394843949439504395143952439534395443955439564395743958439594396043961439624396343964439654396643967439684396943970439714397243973439744397543976439774397843979439804398143982439834398443985439864398743988439894399043991439924399343994439954399643997439984399944000440014400244003440044400544006440074400844009440104401144012440134401444015440164401744018440194402044021440224402344024440254402644027440284402944030440314403244033440344403544036440374403844039440404404144042440434404444045440464404744048440494405044051440524405344054440554405644057440584405944060440614406244063440644406544066440674406844069440704407144072440734407444075440764407744078440794408044081440824408344084440854408644087440884408944090440914409244093440944409544096440974409844099441004410144102441034410444105441064410744108441094411044111441124411344114441154411644117441184411944120441214412244123441244412544126441274412844129441304413144132441334413444135441364413744138441394414044141441424414344144441454414644147441484414944150441514415244153441544415544156441574415844159441604416144162441634416444165441664416744168441694417044171441724417344174441754417644177441784417944180441814418244183441844418544186441874418844189441904419144192441934419444195441964419744198441994420044201442024420344204442054420644207442084420944210442114421244213442144421544216442174421844219442204422144222442234422444225442264422744228442294423044231442324423344234442354423644237442384423944240442414424244243442444424544246442474424844249442504425144252442534425444255442564425744258442594426044261442624426344264442654426644267442684426944270442714427244273442744427544276442774427844279442804428144282442834428444285442864428744288442894429044291442924429344294442954429644297442984429944300443014430244303443044430544306443074430844309443104431144312443134431444315443164431744318443194432044321443224432344324443254432644327443284432944330443314433244333443344433544336443374433844339443404434144342443434434444345443464434744348443494435044351443524435344354443554435644357443584435944360443614436244363443644436544366443674436844369443704437144372443734437444375443764437744378443794438044381443824438344384443854438644387443884438944390443914439244393443944439544396443974439844399444004440144402444034440444405444064440744408444094441044411444124441344414444154441644417444184441944420444214442244423444244442544426444274442844429444304443144432444334443444435444364443744438444394444044441444424444344444444454444644447444484444944450444514445244453444544445544456444574445844459444604446144462444634446444465444664446744468444694447044471444724447344474444754447644477444784447944480444814448244483444844448544486444874448844489444904449144492444934449444495444964449744498444994450044501445024450344504445054450644507445084450944510445114451244513445144451544516445174451844519445204452144522445234452444525445264452744528445294453044531445324453344534445354453644537445384453944540445414454244543445444454544546445474454844549445504455144552445534455444555445564455744558445594456044561445624456344564445654456644567445684456944570445714457244573445744457544576445774457844579445804458144582445834458444585445864458744588445894459044591445924459344594445954459644597445984459944600446014460244603446044460544606446074460844609446104461144612446134461444615446164461744618446194462044621446224462344624446254462644627446284462944630446314463244633446344463544636446374463844639446404464144642446434464444645446464464744648446494465044651446524465344654446554465644657446584465944660446614466244663446644466544666446674466844669446704467144672446734467444675446764467744678446794468044681446824468344684446854468644687446884468944690446914469244693446944469544696446974469844699447004470144702447034470444705447064470744708447094471044711447124471344714447154471644717447184471944720447214472244723447244472544726447274472844729447304473144732447334473444735447364473744738447394474044741447424474344744447454474644747447484474944750447514475244753447544475544756447574475844759447604476144762447634476444765447664476744768447694477044771447724477344774447754477644777447784477944780447814478244783447844478544786447874478844789447904479144792447934479444795447964479744798447994480044801448024480344804448054480644807448084480944810448114481244813448144481544816448174481844819448204482144822448234482444825448264482744828448294483044831448324483344834448354483644837448384483944840448414484244843448444484544846448474484844849448504485144852448534485444855448564485744858448594486044861448624486344864448654486644867448684486944870448714487244873448744487544876448774487844879448804488144882448834488444885448864488744888448894489044891448924489344894448954489644897448984489944900449014490244903449044490544906449074490844909449104491144912449134491444915449164491744918449194492044921449224492344924449254492644927449284492944930449314493244933449344493544936449374493844939449404494144942449434494444945449464494744948449494495044951449524495344954449554495644957449584495944960449614496244963449644496544966449674496844969449704497144972449734497444975449764497744978449794498044981449824498344984449854498644987449884498944990449914499244993449944499544996449974499844999450004500145002450034500445005450064500745008450094501045011450124501345014450154501645017450184501945020450214502245023450244502545026450274502845029450304503145032450334503445035450364503745038450394504045041450424504345044450454504645047450484504945050450514505245053450544505545056450574505845059450604506145062450634506445065450664506745068450694507045071450724507345074450754507645077450784507945080450814508245083450844508545086450874508845089450904509145092450934509445095450964509745098450994510045101451024510345104451054510645107451084510945110451114511245113451144511545116451174511845119451204512145122451234512445125451264512745128451294513045131451324513345134451354513645137451384513945140451414514245143451444514545146451474514845149451504515145152451534515445155451564515745158451594516045161451624516345164451654516645167451684516945170451714517245173451744517545176451774517845179451804518145182451834518445185451864518745188451894519045191451924519345194451954519645197451984519945200452014520245203452044520545206452074520845209452104521145212452134521445215452164521745218452194522045221452224522345224452254522645227452284522945230452314523245233452344523545236452374523845239452404524145242452434524445245452464524745248452494525045251452524525345254452554525645257452584525945260452614526245263452644526545266452674526845269452704527145272452734527445275452764527745278452794528045281452824528345284452854528645287452884528945290452914529245293452944529545296452974529845299453004530145302453034530445305453064530745308453094531045311453124531345314453154531645317453184531945320453214532245323453244532545326453274532845329453304533145332453334533445335453364533745338453394534045341453424534345344453454534645347453484534945350453514535245353453544535545356453574535845359453604536145362453634536445365453664536745368453694537045371453724537345374453754537645377453784537945380453814538245383453844538545386453874538845389453904539145392453934539445395453964539745398453994540045401454024540345404454054540645407454084540945410454114541245413454144541545416454174541845419454204542145422454234542445425454264542745428454294543045431454324543345434454354543645437454384543945440454414544245443454444544545446454474544845449454504545145452454534545445455454564545745458454594546045461454624546345464454654546645467454684546945470454714547245473454744547545476454774547845479454804548145482454834548445485454864548745488454894549045491454924549345494454954549645497454984549945500455014550245503455044550545506455074550845509455104551145512455134551445515455164551745518455194552045521455224552345524455254552645527455284552945530455314553245533455344553545536455374553845539455404554145542455434554445545455464554745548455494555045551455524555345554455554555645557455584555945560455614556245563455644556545566455674556845569455704557145572455734557445575455764557745578455794558045581455824558345584455854558645587455884558945590455914559245593455944559545596455974559845599456004560145602456034560445605456064560745608456094561045611456124561345614456154561645617456184561945620456214562245623456244562545626456274562845629456304563145632456334563445635456364563745638456394564045641456424564345644456454564645647456484564945650456514565245653456544565545656456574565845659456604566145662456634566445665456664566745668456694567045671456724567345674456754567645677456784567945680456814568245683456844568545686456874568845689456904569145692456934569445695456964569745698456994570045701457024570345704457054570645707457084570945710457114571245713
  1. /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
  3. /* Copyright 2012 Mozilla Foundation
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. /*jshint globalstrict: false */
  18. /* globals PDFJS */
  19. // Initializing PDFJS global object (if still undefined)
  20. if (typeof PDFJS === 'undefined') {
  21. (typeof window !== 'undefined' ? window : this).PDFJS = {};
  22. }
  23. PDFJS.version = '1.1.147';
  24. PDFJS.build = '73545fb';
  25. (function pdfjsWrapper() {
  26. // Use strict in our context only - users might not want it
  27. 'use strict';
  28. /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  29. /* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
  30. /* Copyright 2012 Mozilla Foundation
  31. *
  32. * Licensed under the Apache License, Version 2.0 (the "License");
  33. * you may not use this file except in compliance with the License.
  34. * You may obtain a copy of the License at
  35. *
  36. * http://www.apache.org/licenses/LICENSE-2.0
  37. *
  38. * Unless required by applicable law or agreed to in writing, software
  39. * distributed under the License is distributed on an "AS IS" BASIS,
  40. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  41. * See the License for the specific language governing permissions and
  42. * limitations under the License.
  43. */
  44. /* globals Cmd, ColorSpace, Dict, MozBlobBuilder, Name, PDFJS, Ref, URL,
  45. Promise */
  46. 'use strict';
  47. var globalScope = (typeof window === 'undefined') ? this : window;
  48. var isWorker = (typeof window === 'undefined');
  49. var FONT_IDENTITY_MATRIX = [0.001, 0, 0, 0.001, 0, 0];
  50. var TextRenderingMode = {
  51. FILL: 0,
  52. STROKE: 1,
  53. FILL_STROKE: 2,
  54. INVISIBLE: 3,
  55. FILL_ADD_TO_PATH: 4,
  56. STROKE_ADD_TO_PATH: 5,
  57. FILL_STROKE_ADD_TO_PATH: 6,
  58. ADD_TO_PATH: 7,
  59. FILL_STROKE_MASK: 3,
  60. ADD_TO_PATH_FLAG: 4
  61. };
  62. var ImageKind = {
  63. GRAYSCALE_1BPP: 1,
  64. RGB_24BPP: 2,
  65. RGBA_32BPP: 3
  66. };
  67. var AnnotationType = {
  68. WIDGET: 1,
  69. TEXT: 2,
  70. LINK: 3
  71. };
  72. var StreamType = {
  73. UNKNOWN: 0,
  74. FLATE: 1,
  75. LZW: 2,
  76. DCT: 3,
  77. JPX: 4,
  78. JBIG: 5,
  79. A85: 6,
  80. AHX: 7,
  81. CCF: 8,
  82. RL: 9
  83. };
  84. var FontType = {
  85. UNKNOWN: 0,
  86. TYPE1: 1,
  87. TYPE1C: 2,
  88. CIDFONTTYPE0: 3,
  89. CIDFONTTYPE0C: 4,
  90. TRUETYPE: 5,
  91. CIDFONTTYPE2: 6,
  92. TYPE3: 7,
  93. OPENTYPE: 8,
  94. TYPE0: 9,
  95. MMTYPE1: 10
  96. };
  97. // The global PDFJS object exposes the API
  98. // In production, it will be declared outside a global wrapper
  99. // In development, it will be declared here
  100. if (!globalScope.PDFJS) {
  101. globalScope.PDFJS = {};
  102. }
  103. globalScope.PDFJS.pdfBug = false;
  104. PDFJS.VERBOSITY_LEVELS = {
  105. errors: 0,
  106. warnings: 1,
  107. infos: 5
  108. };
  109. // All the possible operations for an operator list.
  110. var OPS = PDFJS.OPS = {
  111. // Intentionally start from 1 so it is easy to spot bad operators that will be
  112. // 0's.
  113. dependency: 1,
  114. setLineWidth: 2,
  115. setLineCap: 3,
  116. setLineJoin: 4,
  117. setMiterLimit: 5,
  118. setDash: 6,
  119. setRenderingIntent: 7,
  120. setFlatness: 8,
  121. setGState: 9,
  122. save: 10,
  123. restore: 11,
  124. transform: 12,
  125. moveTo: 13,
  126. lineTo: 14,
  127. curveTo: 15,
  128. curveTo2: 16,
  129. curveTo3: 17,
  130. closePath: 18,
  131. rectangle: 19,
  132. stroke: 20,
  133. closeStroke: 21,
  134. fill: 22,
  135. eoFill: 23,
  136. fillStroke: 24,
  137. eoFillStroke: 25,
  138. closeFillStroke: 26,
  139. closeEOFillStroke: 27,
  140. endPath: 28,
  141. clip: 29,
  142. eoClip: 30,
  143. beginText: 31,
  144. endText: 32,
  145. setCharSpacing: 33,
  146. setWordSpacing: 34,
  147. setHScale: 35,
  148. setLeading: 36,
  149. setFont: 37,
  150. setTextRenderingMode: 38,
  151. setTextRise: 39,
  152. moveText: 40,
  153. setLeadingMoveText: 41,
  154. setTextMatrix: 42,
  155. nextLine: 43,
  156. showText: 44,
  157. showSpacedText: 45,
  158. nextLineShowText: 46,
  159. nextLineSetSpacingShowText: 47,
  160. setCharWidth: 48,
  161. setCharWidthAndBounds: 49,
  162. setStrokeColorSpace: 50,
  163. setFillColorSpace: 51,
  164. setStrokeColor: 52,
  165. setStrokeColorN: 53,
  166. setFillColor: 54,
  167. setFillColorN: 55,
  168. setStrokeGray: 56,
  169. setFillGray: 57,
  170. setStrokeRGBColor: 58,
  171. setFillRGBColor: 59,
  172. setStrokeCMYKColor: 60,
  173. setFillCMYKColor: 61,
  174. shadingFill: 62,
  175. beginInlineImage: 63,
  176. beginImageData: 64,
  177. endInlineImage: 65,
  178. paintXObject: 66,
  179. markPoint: 67,
  180. markPointProps: 68,
  181. beginMarkedContent: 69,
  182. beginMarkedContentProps: 70,
  183. endMarkedContent: 71,
  184. beginCompat: 72,
  185. endCompat: 73,
  186. paintFormXObjectBegin: 74,
  187. paintFormXObjectEnd: 75,
  188. beginGroup: 76,
  189. endGroup: 77,
  190. beginAnnotations: 78,
  191. endAnnotations: 79,
  192. beginAnnotation: 80,
  193. endAnnotation: 81,
  194. paintJpegXObject: 82,
  195. paintImageMaskXObject: 83,
  196. paintImageMaskXObjectGroup: 84,
  197. paintImageXObject: 85,
  198. paintInlineImageXObject: 86,
  199. paintInlineImageXObjectGroup: 87,
  200. paintImageXObjectRepeat: 88,
  201. paintImageMaskXObjectRepeat: 89,
  202. paintSolidColorImageMask: 90,
  203. constructPath: 91
  204. };
  205. // A notice for devs. These are good for things that are helpful to devs, such
  206. // as warning that Workers were disabled, which is important to devs but not
  207. // end users.
  208. function info(msg) {
  209. if (PDFJS.verbosity >= PDFJS.VERBOSITY_LEVELS.infos) {
  210. console.log('Info: ' + msg);
  211. }
  212. }
  213. // Non-fatal warnings.
  214. function warn(msg) {
  215. if (PDFJS.verbosity >= PDFJS.VERBOSITY_LEVELS.warnings) {
  216. console.log('Warning: ' + msg);
  217. }
  218. }
  219. // Fatal errors that should trigger the fallback UI and halt execution by
  220. // throwing an exception.
  221. function error(msg) {
  222. if (PDFJS.verbosity >= PDFJS.VERBOSITY_LEVELS.errors) {
  223. console.log('Error: ' + msg);
  224. console.log(backtrace());
  225. }
  226. UnsupportedManager.notify(UNSUPPORTED_FEATURES.unknown);
  227. throw new Error(msg);
  228. }
  229. function backtrace() {
  230. try {
  231. throw new Error();
  232. } catch (e) {
  233. return e.stack ? e.stack.split('\n').slice(2).join('\n') : '';
  234. }
  235. }
  236. function assert(cond, msg) {
  237. if (!cond) {
  238. error(msg);
  239. }
  240. }
  241. var UNSUPPORTED_FEATURES = PDFJS.UNSUPPORTED_FEATURES = {
  242. unknown: 'unknown',
  243. forms: 'forms',
  244. javaScript: 'javaScript',
  245. smask: 'smask',
  246. shadingPattern: 'shadingPattern',
  247. font: 'font'
  248. };
  249. var UnsupportedManager = PDFJS.UnsupportedManager =
  250. (function UnsupportedManagerClosure() {
  251. var listeners = [];
  252. return {
  253. listen: function (cb) {
  254. listeners.push(cb);
  255. },
  256. notify: function (featureId) {
  257. warn('Unsupported feature "' + featureId + '"');
  258. for (var i = 0, ii = listeners.length; i < ii; i++) {
  259. listeners[i](featureId);
  260. }
  261. }
  262. };
  263. })();
  264. // Combines two URLs. The baseUrl shall be absolute URL. If the url is an
  265. // absolute URL, it will be returned as is.
  266. function combineUrl(baseUrl, url) {
  267. if (!url) {
  268. return baseUrl;
  269. }
  270. if (/^[a-z][a-z0-9+\-.]*:/i.test(url)) {
  271. return url;
  272. }
  273. var i;
  274. if (url.charAt(0) === '/') {
  275. // absolute path
  276. i = baseUrl.indexOf('://');
  277. if (url.charAt(1) === '/') {
  278. ++i;
  279. } else {
  280. i = baseUrl.indexOf('/', i + 3);
  281. }
  282. return baseUrl.substring(0, i) + url;
  283. } else {
  284. // relative path
  285. var pathLength = baseUrl.length;
  286. i = baseUrl.lastIndexOf('#');
  287. pathLength = i >= 0 ? i : pathLength;
  288. i = baseUrl.lastIndexOf('?', pathLength);
  289. pathLength = i >= 0 ? i : pathLength;
  290. var prefixLength = baseUrl.lastIndexOf('/', pathLength);
  291. return baseUrl.substring(0, prefixLength + 1) + url;
  292. }
  293. }
  294. // Validates if URL is safe and allowed, e.g. to avoid XSS.
  295. function isValidUrl(url, allowRelative) {
  296. if (!url) {
  297. return false;
  298. }
  299. // RFC 3986 (http://tools.ietf.org/html/rfc3986#section-3.1)
  300. // scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
  301. var protocol = /^[a-z][a-z0-9+\-.]*(?=:)/i.exec(url);
  302. if (!protocol) {
  303. return allowRelative;
  304. }
  305. protocol = protocol[0].toLowerCase();
  306. switch (protocol) {
  307. case 'http':
  308. case 'https':
  309. case 'ftp':
  310. case 'mailto':
  311. case 'tel':
  312. return true;
  313. default:
  314. return false;
  315. }
  316. }
  317. PDFJS.isValidUrl = isValidUrl;
  318. function shadow(obj, prop, value) {
  319. Object.defineProperty(obj, prop, { value: value,
  320. enumerable: true,
  321. configurable: true,
  322. writable: false });
  323. return value;
  324. }
  325. PDFJS.shadow = shadow;
  326. var PasswordResponses = PDFJS.PasswordResponses = {
  327. NEED_PASSWORD: 1,
  328. INCORRECT_PASSWORD: 2
  329. };
  330. var PasswordException = (function PasswordExceptionClosure() {
  331. function PasswordException(msg, code) {
  332. this.name = 'PasswordException';
  333. this.message = msg;
  334. this.code = code;
  335. }
  336. PasswordException.prototype = new Error();
  337. PasswordException.constructor = PasswordException;
  338. return PasswordException;
  339. })();
  340. PDFJS.PasswordException = PasswordException;
  341. var UnknownErrorException = (function UnknownErrorExceptionClosure() {
  342. function UnknownErrorException(msg, details) {
  343. this.name = 'UnknownErrorException';
  344. this.message = msg;
  345. this.details = details;
  346. }
  347. UnknownErrorException.prototype = new Error();
  348. UnknownErrorException.constructor = UnknownErrorException;
  349. return UnknownErrorException;
  350. })();
  351. PDFJS.UnknownErrorException = UnknownErrorException;
  352. var InvalidPDFException = (function InvalidPDFExceptionClosure() {
  353. function InvalidPDFException(msg) {
  354. this.name = 'InvalidPDFException';
  355. this.message = msg;
  356. }
  357. InvalidPDFException.prototype = new Error();
  358. InvalidPDFException.constructor = InvalidPDFException;
  359. return InvalidPDFException;
  360. })();
  361. PDFJS.InvalidPDFException = InvalidPDFException;
  362. var MissingPDFException = (function MissingPDFExceptionClosure() {
  363. function MissingPDFException(msg) {
  364. this.name = 'MissingPDFException';
  365. this.message = msg;
  366. }
  367. MissingPDFException.prototype = new Error();
  368. MissingPDFException.constructor = MissingPDFException;
  369. return MissingPDFException;
  370. })();
  371. PDFJS.MissingPDFException = MissingPDFException;
  372. var UnexpectedResponseException =
  373. (function UnexpectedResponseExceptionClosure() {
  374. function UnexpectedResponseException(msg, status) {
  375. this.name = 'UnexpectedResponseException';
  376. this.message = msg;
  377. this.status = status;
  378. }
  379. UnexpectedResponseException.prototype = new Error();
  380. UnexpectedResponseException.constructor = UnexpectedResponseException;
  381. return UnexpectedResponseException;
  382. })();
  383. PDFJS.UnexpectedResponseException = UnexpectedResponseException;
  384. var NotImplementedException = (function NotImplementedExceptionClosure() {
  385. function NotImplementedException(msg) {
  386. this.message = msg;
  387. }
  388. NotImplementedException.prototype = new Error();
  389. NotImplementedException.prototype.name = 'NotImplementedException';
  390. NotImplementedException.constructor = NotImplementedException;
  391. return NotImplementedException;
  392. })();
  393. var MissingDataException = (function MissingDataExceptionClosure() {
  394. function MissingDataException(begin, end) {
  395. this.begin = begin;
  396. this.end = end;
  397. this.message = 'Missing data [' + begin + ', ' + end + ')';
  398. }
  399. MissingDataException.prototype = new Error();
  400. MissingDataException.prototype.name = 'MissingDataException';
  401. MissingDataException.constructor = MissingDataException;
  402. return MissingDataException;
  403. })();
  404. var XRefParseException = (function XRefParseExceptionClosure() {
  405. function XRefParseException(msg) {
  406. this.message = msg;
  407. }
  408. XRefParseException.prototype = new Error();
  409. XRefParseException.prototype.name = 'XRefParseException';
  410. XRefParseException.constructor = XRefParseException;
  411. return XRefParseException;
  412. })();
  413. function bytesToString(bytes) {
  414. assert(bytes !== null && typeof bytes === 'object' &&
  415. bytes.length !== undefined, 'Invalid argument for bytesToString');
  416. var length = bytes.length;
  417. var MAX_ARGUMENT_COUNT = 8192;
  418. if (length < MAX_ARGUMENT_COUNT) {
  419. return String.fromCharCode.apply(null, bytes);
  420. }
  421. var strBuf = [];
  422. for (var i = 0; i < length; i += MAX_ARGUMENT_COUNT) {
  423. var chunkEnd = Math.min(i + MAX_ARGUMENT_COUNT, length);
  424. var chunk = bytes.subarray(i, chunkEnd);
  425. strBuf.push(String.fromCharCode.apply(null, chunk));
  426. }
  427. return strBuf.join('');
  428. }
  429. function stringToBytes(str) {
  430. assert(typeof str === 'string', 'Invalid argument for stringToBytes');
  431. var length = str.length;
  432. var bytes = new Uint8Array(length);
  433. for (var i = 0; i < length; ++i) {
  434. bytes[i] = str.charCodeAt(i) & 0xFF;
  435. }
  436. return bytes;
  437. }
  438. function string32(value) {
  439. return String.fromCharCode((value >> 24) & 0xff, (value >> 16) & 0xff,
  440. (value >> 8) & 0xff, value & 0xff);
  441. }
  442. function log2(x) {
  443. var n = 1, i = 0;
  444. while (x > n) {
  445. n <<= 1;
  446. i++;
  447. }
  448. return i;
  449. }
  450. function readInt8(data, start) {
  451. return (data[start] << 24) >> 24;
  452. }
  453. function readUint16(data, offset) {
  454. return (data[offset] << 8) | data[offset + 1];
  455. }
  456. function readUint32(data, offset) {
  457. return ((data[offset] << 24) | (data[offset + 1] << 16) |
  458. (data[offset + 2] << 8) | data[offset + 3]) >>> 0;
  459. }
  460. // Lazy test the endianness of the platform
  461. // NOTE: This will be 'true' for simulated TypedArrays
  462. function isLittleEndian() {
  463. var buffer8 = new Uint8Array(2);
  464. buffer8[0] = 1;
  465. var buffer16 = new Uint16Array(buffer8.buffer);
  466. return (buffer16[0] === 1);
  467. }
  468. Object.defineProperty(PDFJS, 'isLittleEndian', {
  469. configurable: true,
  470. get: function PDFJS_isLittleEndian() {
  471. return shadow(PDFJS, 'isLittleEndian', isLittleEndian());
  472. }
  473. });
  474. // Lazy test if the userAgant support CanvasTypedArrays
  475. function hasCanvasTypedArrays() {
  476. var canvas = document.createElement('canvas');
  477. canvas.width = canvas.height = 1;
  478. var ctx = canvas.getContext('2d');
  479. var imageData = ctx.createImageData(1, 1);
  480. return (typeof imageData.data.buffer !== 'undefined');
  481. }
  482. Object.defineProperty(PDFJS, 'hasCanvasTypedArrays', {
  483. configurable: true,
  484. get: function PDFJS_hasCanvasTypedArrays() {
  485. return shadow(PDFJS, 'hasCanvasTypedArrays', hasCanvasTypedArrays());
  486. }
  487. });
  488. var Uint32ArrayView = (function Uint32ArrayViewClosure() {
  489. function Uint32ArrayView(buffer, length) {
  490. this.buffer = buffer;
  491. this.byteLength = buffer.length;
  492. this.length = length === undefined ? (this.byteLength >> 2) : length;
  493. ensureUint32ArrayViewProps(this.length);
  494. }
  495. Uint32ArrayView.prototype = Object.create(null);
  496. var uint32ArrayViewSetters = 0;
  497. function createUint32ArrayProp(index) {
  498. return {
  499. get: function () {
  500. var buffer = this.buffer, offset = index << 2;
  501. return (buffer[offset] | (buffer[offset + 1] << 8) |
  502. (buffer[offset + 2] << 16) | (buffer[offset + 3] << 24)) >>> 0;
  503. },
  504. set: function (value) {
  505. var buffer = this.buffer, offset = index << 2;
  506. buffer[offset] = value & 255;
  507. buffer[offset + 1] = (value >> 8) & 255;
  508. buffer[offset + 2] = (value >> 16) & 255;
  509. buffer[offset + 3] = (value >>> 24) & 255;
  510. }
  511. };
  512. }
  513. function ensureUint32ArrayViewProps(length) {
  514. while (uint32ArrayViewSetters < length) {
  515. Object.defineProperty(Uint32ArrayView.prototype,
  516. uint32ArrayViewSetters,
  517. createUint32ArrayProp(uint32ArrayViewSetters));
  518. uint32ArrayViewSetters++;
  519. }
  520. }
  521. return Uint32ArrayView;
  522. })();
  523. var IDENTITY_MATRIX = [1, 0, 0, 1, 0, 0];
  524. var Util = PDFJS.Util = (function UtilClosure() {
  525. function Util() {}
  526. var rgbBuf = ['rgb(', 0, ',', 0, ',', 0, ')'];
  527. // makeCssRgb() can be called thousands of times. Using |rgbBuf| avoids
  528. // creating many intermediate strings.
  529. Util.makeCssRgb = function Util_makeCssRgb(r, g, b) {
  530. rgbBuf[1] = r;
  531. rgbBuf[3] = g;
  532. rgbBuf[5] = b;
  533. return rgbBuf.join('');
  534. };
  535. // Concatenates two transformation matrices together and returns the result.
  536. Util.transform = function Util_transform(m1, m2) {
  537. return [
  538. m1[0] * m2[0] + m1[2] * m2[1],
  539. m1[1] * m2[0] + m1[3] * m2[1],
  540. m1[0] * m2[2] + m1[2] * m2[3],
  541. m1[1] * m2[2] + m1[3] * m2[3],
  542. m1[0] * m2[4] + m1[2] * m2[5] + m1[4],
  543. m1[1] * m2[4] + m1[3] * m2[5] + m1[5]
  544. ];
  545. };
  546. // For 2d affine transforms
  547. Util.applyTransform = function Util_applyTransform(p, m) {
  548. var xt = p[0] * m[0] + p[1] * m[2] + m[4];
  549. var yt = p[0] * m[1] + p[1] * m[3] + m[5];
  550. return [xt, yt];
  551. };
  552. Util.applyInverseTransform = function Util_applyInverseTransform(p, m) {
  553. var d = m[0] * m[3] - m[1] * m[2];
  554. var xt = (p[0] * m[3] - p[1] * m[2] + m[2] * m[5] - m[4] * m[3]) / d;
  555. var yt = (-p[0] * m[1] + p[1] * m[0] + m[4] * m[1] - m[5] * m[0]) / d;
  556. return [xt, yt];
  557. };
  558. // Applies the transform to the rectangle and finds the minimum axially
  559. // aligned bounding box.
  560. Util.getAxialAlignedBoundingBox =
  561. function Util_getAxialAlignedBoundingBox(r, m) {
  562. var p1 = Util.applyTransform(r, m);
  563. var p2 = Util.applyTransform(r.slice(2, 4), m);
  564. var p3 = Util.applyTransform([r[0], r[3]], m);
  565. var p4 = Util.applyTransform([r[2], r[1]], m);
  566. return [
  567. Math.min(p1[0], p2[0], p3[0], p4[0]),
  568. Math.min(p1[1], p2[1], p3[1], p4[1]),
  569. Math.max(p1[0], p2[0], p3[0], p4[0]),
  570. Math.max(p1[1], p2[1], p3[1], p4[1])
  571. ];
  572. };
  573. Util.inverseTransform = function Util_inverseTransform(m) {
  574. var d = m[0] * m[3] - m[1] * m[2];
  575. return [m[3] / d, -m[1] / d, -m[2] / d, m[0] / d,
  576. (m[2] * m[5] - m[4] * m[3]) / d, (m[4] * m[1] - m[5] * m[0]) / d];
  577. };
  578. // Apply a generic 3d matrix M on a 3-vector v:
  579. // | a b c | | X |
  580. // | d e f | x | Y |
  581. // | g h i | | Z |
  582. // M is assumed to be serialized as [a,b,c,d,e,f,g,h,i],
  583. // with v as [X,Y,Z]
  584. Util.apply3dTransform = function Util_apply3dTransform(m, v) {
  585. return [
  586. m[0] * v[0] + m[1] * v[1] + m[2] * v[2],
  587. m[3] * v[0] + m[4] * v[1] + m[5] * v[2],
  588. m[6] * v[0] + m[7] * v[1] + m[8] * v[2]
  589. ];
  590. };
  591. // This calculation uses Singular Value Decomposition.
  592. // The SVD can be represented with formula A = USV. We are interested in the
  593. // matrix S here because it represents the scale values.
  594. Util.singularValueDecompose2dScale =
  595. function Util_singularValueDecompose2dScale(m) {
  596. var transpose = [m[0], m[2], m[1], m[3]];
  597. // Multiply matrix m with its transpose.
  598. var a = m[0] * transpose[0] + m[1] * transpose[2];
  599. var b = m[0] * transpose[1] + m[1] * transpose[3];
  600. var c = m[2] * transpose[0] + m[3] * transpose[2];
  601. var d = m[2] * transpose[1] + m[3] * transpose[3];
  602. // Solve the second degree polynomial to get roots.
  603. var first = (a + d) / 2;
  604. var second = Math.sqrt((a + d) * (a + d) - 4 * (a * d - c * b)) / 2;
  605. var sx = first + second || 1;
  606. var sy = first - second || 1;
  607. // Scale values are the square roots of the eigenvalues.
  608. return [Math.sqrt(sx), Math.sqrt(sy)];
  609. };
  610. // Normalize rectangle rect=[x1, y1, x2, y2] so that (x1,y1) < (x2,y2)
  611. // For coordinate systems whose origin lies in the bottom-left, this
  612. // means normalization to (BL,TR) ordering. For systems with origin in the
  613. // top-left, this means (TL,BR) ordering.
  614. Util.normalizeRect = function Util_normalizeRect(rect) {
  615. var r = rect.slice(0); // clone rect
  616. if (rect[0] > rect[2]) {
  617. r[0] = rect[2];
  618. r[2] = rect[0];
  619. }
  620. if (rect[1] > rect[3]) {
  621. r[1] = rect[3];
  622. r[3] = rect[1];
  623. }
  624. return r;
  625. };
  626. // Returns a rectangle [x1, y1, x2, y2] corresponding to the
  627. // intersection of rect1 and rect2. If no intersection, returns 'false'
  628. // The rectangle coordinates of rect1, rect2 should be [x1, y1, x2, y2]
  629. Util.intersect = function Util_intersect(rect1, rect2) {
  630. function compare(a, b) {
  631. return a - b;
  632. }
  633. // Order points along the axes
  634. var orderedX = [rect1[0], rect1[2], rect2[0], rect2[2]].sort(compare),
  635. orderedY = [rect1[1], rect1[3], rect2[1], rect2[3]].sort(compare),
  636. result = [];
  637. rect1 = Util.normalizeRect(rect1);
  638. rect2 = Util.normalizeRect(rect2);
  639. // X: first and second points belong to different rectangles?
  640. if ((orderedX[0] === rect1[0] && orderedX[1] === rect2[0]) ||
  641. (orderedX[0] === rect2[0] && orderedX[1] === rect1[0])) {
  642. // Intersection must be between second and third points
  643. result[0] = orderedX[1];
  644. result[2] = orderedX[2];
  645. } else {
  646. return false;
  647. }
  648. // Y: first and second points belong to different rectangles?
  649. if ((orderedY[0] === rect1[1] && orderedY[1] === rect2[1]) ||
  650. (orderedY[0] === rect2[1] && orderedY[1] === rect1[1])) {
  651. // Intersection must be between second and third points
  652. result[1] = orderedY[1];
  653. result[3] = orderedY[2];
  654. } else {
  655. return false;
  656. }
  657. return result;
  658. };
  659. Util.sign = function Util_sign(num) {
  660. return num < 0 ? -1 : 1;
  661. };
  662. Util.appendToArray = function Util_appendToArray(arr1, arr2) {
  663. Array.prototype.push.apply(arr1, arr2);
  664. };
  665. Util.prependToArray = function Util_prependToArray(arr1, arr2) {
  666. Array.prototype.unshift.apply(arr1, arr2);
  667. };
  668. Util.extendObj = function extendObj(obj1, obj2) {
  669. for (var key in obj2) {
  670. obj1[key] = obj2[key];
  671. }
  672. };
  673. Util.getInheritableProperty = function Util_getInheritableProperty(dict,
  674. name) {
  675. while (dict && !dict.has(name)) {
  676. dict = dict.get('Parent');
  677. }
  678. if (!dict) {
  679. return null;
  680. }
  681. return dict.get(name);
  682. };
  683. Util.inherit = function Util_inherit(sub, base, prototype) {
  684. sub.prototype = Object.create(base.prototype);
  685. sub.prototype.constructor = sub;
  686. for (var prop in prototype) {
  687. sub.prototype[prop] = prototype[prop];
  688. }
  689. };
  690. Util.loadScript = function Util_loadScript(src, callback) {
  691. var script = document.createElement('script');
  692. var loaded = false;
  693. script.setAttribute('src', src);
  694. if (callback) {
  695. script.onload = function() {
  696. if (!loaded) {
  697. callback();
  698. }
  699. loaded = true;
  700. };
  701. }
  702. document.getElementsByTagName('head')[0].appendChild(script);
  703. };
  704. return Util;
  705. })();
  706. /**
  707. * PDF page viewport created based on scale, rotation and offset.
  708. * @class
  709. * @alias PDFJS.PageViewport
  710. */
  711. var PageViewport = PDFJS.PageViewport = (function PageViewportClosure() {
  712. /**
  713. * @constructor
  714. * @private
  715. * @param viewBox {Array} xMin, yMin, xMax and yMax coordinates.
  716. * @param scale {number} scale of the viewport.
  717. * @param rotation {number} rotations of the viewport in degrees.
  718. * @param offsetX {number} offset X
  719. * @param offsetY {number} offset Y
  720. * @param dontFlip {boolean} if true, axis Y will not be flipped.
  721. */
  722. function PageViewport(viewBox, scale, rotation, offsetX, offsetY, dontFlip) {
  723. this.viewBox = viewBox;
  724. this.scale = scale;
  725. this.rotation = rotation;
  726. this.offsetX = offsetX;
  727. this.offsetY = offsetY;
  728. // creating transform to convert pdf coordinate system to the normal
  729. // canvas like coordinates taking in account scale and rotation
  730. var centerX = (viewBox[2] + viewBox[0]) / 2;
  731. var centerY = (viewBox[3] + viewBox[1]) / 2;
  732. var rotateA, rotateB, rotateC, rotateD;
  733. rotation = rotation % 360;
  734. rotation = rotation < 0 ? rotation + 360 : rotation;
  735. switch (rotation) {
  736. case 180:
  737. rotateA = -1; rotateB = 0; rotateC = 0; rotateD = 1;
  738. break;
  739. case 90:
  740. rotateA = 0; rotateB = 1; rotateC = 1; rotateD = 0;
  741. break;
  742. case 270:
  743. rotateA = 0; rotateB = -1; rotateC = -1; rotateD = 0;
  744. break;
  745. //case 0:
  746. default:
  747. rotateA = 1; rotateB = 0; rotateC = 0; rotateD = -1;
  748. break;
  749. }
  750. if (dontFlip) {
  751. rotateC = -rotateC; rotateD = -rotateD;
  752. }
  753. var offsetCanvasX, offsetCanvasY;
  754. var width, height;
  755. if (rotateA === 0) {
  756. offsetCanvasX = Math.abs(centerY - viewBox[1]) * scale + offsetX;
  757. offsetCanvasY = Math.abs(centerX - viewBox[0]) * scale + offsetY;
  758. width = Math.abs(viewBox[3] - viewBox[1]) * scale;
  759. height = Math.abs(viewBox[2] - viewBox[0]) * scale;
  760. } else {
  761. offsetCanvasX = Math.abs(centerX - viewBox[0]) * scale + offsetX;
  762. offsetCanvasY = Math.abs(centerY - viewBox[1]) * scale + offsetY;
  763. width = Math.abs(viewBox[2] - viewBox[0]) * scale;
  764. height = Math.abs(viewBox[3] - viewBox[1]) * scale;
  765. }
  766. // creating transform for the following operations:
  767. // translate(-centerX, -centerY), rotate and flip vertically,
  768. // scale, and translate(offsetCanvasX, offsetCanvasY)
  769. this.transform = [
  770. rotateA * scale,
  771. rotateB * scale,
  772. rotateC * scale,
  773. rotateD * scale,
  774. offsetCanvasX - rotateA * scale * centerX - rotateC * scale * centerY,
  775. offsetCanvasY - rotateB * scale * centerX - rotateD * scale * centerY
  776. ];
  777. this.width = width;
  778. this.height = height;
  779. this.fontScale = scale;
  780. }
  781. PageViewport.prototype = /** @lends PDFJS.PageViewport.prototype */ {
  782. /**
  783. * Clones viewport with additional properties.
  784. * @param args {Object} (optional) If specified, may contain the 'scale' or
  785. * 'rotation' properties to override the corresponding properties in
  786. * the cloned viewport.
  787. * @returns {PDFJS.PageViewport} Cloned viewport.
  788. */
  789. clone: function PageViewPort_clone(args) {
  790. args = args || {};
  791. var scale = 'scale' in args ? args.scale : this.scale;
  792. var rotation = 'rotation' in args ? args.rotation : this.rotation;
  793. return new PageViewport(this.viewBox.slice(), scale, rotation,
  794. this.offsetX, this.offsetY, args.dontFlip);
  795. },
  796. /**
  797. * Converts PDF point to the viewport coordinates. For examples, useful for
  798. * converting PDF location into canvas pixel coordinates.
  799. * @param x {number} X coordinate.
  800. * @param y {number} Y coordinate.
  801. * @returns {Object} Object that contains 'x' and 'y' properties of the
  802. * point in the viewport coordinate space.
  803. * @see {@link convertToPdfPoint}
  804. * @see {@link convertToViewportRectangle}
  805. */
  806. convertToViewportPoint: function PageViewport_convertToViewportPoint(x, y) {
  807. return Util.applyTransform([x, y], this.transform);
  808. },
  809. /**
  810. * Converts PDF rectangle to the viewport coordinates.
  811. * @param rect {Array} xMin, yMin, xMax and yMax coordinates.
  812. * @returns {Array} Contains corresponding coordinates of the rectangle
  813. * in the viewport coordinate space.
  814. * @see {@link convertToViewportPoint}
  815. */
  816. convertToViewportRectangle:
  817. function PageViewport_convertToViewportRectangle(rect) {
  818. var tl = Util.applyTransform([rect[0], rect[1]], this.transform);
  819. var br = Util.applyTransform([rect[2], rect[3]], this.transform);
  820. return [tl[0], tl[1], br[0], br[1]];
  821. },
  822. /**
  823. * Converts viewport coordinates to the PDF location. For examples, useful
  824. * for converting canvas pixel location into PDF one.
  825. * @param x {number} X coordinate.
  826. * @param y {number} Y coordinate.
  827. * @returns {Object} Object that contains 'x' and 'y' properties of the
  828. * point in the PDF coordinate space.
  829. * @see {@link convertToViewportPoint}
  830. */
  831. convertToPdfPoint: function PageViewport_convertToPdfPoint(x, y) {
  832. return Util.applyInverseTransform([x, y], this.transform);
  833. }
  834. };
  835. return PageViewport;
  836. })();
  837. var PDFStringTranslateTable = [
  838. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  839. 0x2D8, 0x2C7, 0x2C6, 0x2D9, 0x2DD, 0x2DB, 0x2DA, 0x2DC, 0, 0, 0, 0, 0, 0, 0,
  840. 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,
  841. 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,
  842. 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,
  843. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x2022, 0x2020, 0x2021, 0x2026, 0x2014,
  844. 0x2013, 0x192, 0x2044, 0x2039, 0x203A, 0x2212, 0x2030, 0x201E, 0x201C,
  845. 0x201D, 0x2018, 0x2019, 0x201A, 0x2122, 0xFB01, 0xFB02, 0x141, 0x152, 0x160,
  846. 0x178, 0x17D, 0x131, 0x142, 0x153, 0x161, 0x17E, 0, 0x20AC
  847. ];
  848. function stringToPDFString(str) {
  849. var i, n = str.length, strBuf = [];
  850. if (str[0] === '\xFE' && str[1] === '\xFF') {
  851. // UTF16BE BOM
  852. for (i = 2; i < n; i += 2) {
  853. strBuf.push(String.fromCharCode(
  854. (str.charCodeAt(i) << 8) | str.charCodeAt(i + 1)));
  855. }
  856. } else {
  857. for (i = 0; i < n; ++i) {
  858. var code = PDFStringTranslateTable[str.charCodeAt(i)];
  859. strBuf.push(code ? String.fromCharCode(code) : str.charAt(i));
  860. }
  861. }
  862. return strBuf.join('');
  863. }
  864. function stringToUTF8String(str) {
  865. return decodeURIComponent(escape(str));
  866. }
  867. function isEmptyObj(obj) {
  868. for (var key in obj) {
  869. return false;
  870. }
  871. return true;
  872. }
  873. function isBool(v) {
  874. return typeof v === 'boolean';
  875. }
  876. function isInt(v) {
  877. return typeof v === 'number' && ((v | 0) === v);
  878. }
  879. function isNum(v) {
  880. return typeof v === 'number';
  881. }
  882. function isString(v) {
  883. return typeof v === 'string';
  884. }
  885. function isName(v) {
  886. return v instanceof Name;
  887. }
  888. function isCmd(v, cmd) {
  889. return v instanceof Cmd && (cmd === undefined || v.cmd === cmd);
  890. }
  891. function isDict(v, type) {
  892. if (!(v instanceof Dict)) {
  893. return false;
  894. }
  895. if (!type) {
  896. return true;
  897. }
  898. var dictType = v.get('Type');
  899. return isName(dictType) && dictType.name === type;
  900. }
  901. function isArray(v) {
  902. return v instanceof Array;
  903. }
  904. function isStream(v) {
  905. return typeof v === 'object' && v !== null && v.getBytes !== undefined;
  906. }
  907. function isArrayBuffer(v) {
  908. return typeof v === 'object' && v !== null && v.byteLength !== undefined;
  909. }
  910. function isRef(v) {
  911. return v instanceof Ref;
  912. }
  913. /**
  914. * Promise Capability object.
  915. *
  916. * @typedef {Object} PromiseCapability
  917. * @property {Promise} promise - A promise object.
  918. * @property {function} resolve - Fullfills the promise.
  919. * @property {function} reject - Rejects the promise.
  920. */
  921. /**
  922. * Creates a promise capability object.
  923. * @alias PDFJS.createPromiseCapability
  924. *
  925. * @return {PromiseCapability} A capability object contains:
  926. * - a Promise, resolve and reject methods.
  927. */
  928. function createPromiseCapability() {
  929. var capability = {};
  930. capability.promise = new Promise(function (resolve, reject) {
  931. capability.resolve = resolve;
  932. capability.reject = reject;
  933. });
  934. return capability;
  935. }
  936. PDFJS.createPromiseCapability = createPromiseCapability;
  937. /**
  938. * Polyfill for Promises:
  939. * The following promise implementation tries to generally implement the
  940. * Promise/A+ spec. Some notable differences from other promise libaries are:
  941. * - There currently isn't a seperate deferred and promise object.
  942. * - Unhandled rejections eventually show an error if they aren't handled.
  943. *
  944. * Based off of the work in:
  945. * https://bugzilla.mozilla.org/show_bug.cgi?id=810490
  946. */
  947. (function PromiseClosure() {
  948. if (globalScope.Promise) {
  949. // Promises existing in the DOM/Worker, checking presence of all/resolve
  950. if (typeof globalScope.Promise.all !== 'function') {
  951. globalScope.Promise.all = function (iterable) {
  952. var count = 0, results = [], resolve, reject;
  953. var promise = new globalScope.Promise(function (resolve_, reject_) {
  954. resolve = resolve_;
  955. reject = reject_;
  956. });
  957. iterable.forEach(function (p, i) {
  958. count++;
  959. p.then(function (result) {
  960. results[i] = result;
  961. count--;
  962. if (count === 0) {
  963. resolve(results);
  964. }
  965. }, reject);
  966. });
  967. if (count === 0) {
  968. resolve(results);
  969. }
  970. return promise;
  971. };
  972. }
  973. if (typeof globalScope.Promise.resolve !== 'function') {
  974. globalScope.Promise.resolve = function (value) {
  975. return new globalScope.Promise(function (resolve) { resolve(value); });
  976. };
  977. }
  978. if (typeof globalScope.Promise.reject !== 'function') {
  979. globalScope.Promise.reject = function (reason) {
  980. return new globalScope.Promise(function (resolve, reject) {
  981. reject(reason);
  982. });
  983. };
  984. }
  985. if (typeof globalScope.Promise.prototype.catch !== 'function') {
  986. globalScope.Promise.prototype.catch = function (onReject) {
  987. return globalScope.Promise.prototype.then(undefined, onReject);
  988. };
  989. }
  990. return;
  991. }
  992. var STATUS_PENDING = 0;
  993. var STATUS_RESOLVED = 1;
  994. var STATUS_REJECTED = 2;
  995. // In an attempt to avoid silent exceptions, unhandled rejections are
  996. // tracked and if they aren't handled in a certain amount of time an
  997. // error is logged.
  998. var REJECTION_TIMEOUT = 500;
  999. var HandlerManager = {
  1000. handlers: [],
  1001. running: false,
  1002. unhandledRejections: [],
  1003. pendingRejectionCheck: false,
  1004. scheduleHandlers: function scheduleHandlers(promise) {
  1005. if (promise._status === STATUS_PENDING) {
  1006. return;
  1007. }
  1008. this.handlers = this.handlers.concat(promise._handlers);
  1009. promise._handlers = [];
  1010. if (this.running) {
  1011. return;
  1012. }
  1013. this.running = true;
  1014. setTimeout(this.runHandlers.bind(this), 0);
  1015. },
  1016. runHandlers: function runHandlers() {
  1017. var RUN_TIMEOUT = 1; // ms
  1018. var timeoutAt = Date.now() + RUN_TIMEOUT;
  1019. while (this.handlers.length > 0) {
  1020. var handler = this.handlers.shift();
  1021. var nextStatus = handler.thisPromise._status;
  1022. var nextValue = handler.thisPromise._value;
  1023. try {
  1024. if (nextStatus === STATUS_RESOLVED) {
  1025. if (typeof handler.onResolve === 'function') {
  1026. nextValue = handler.onResolve(nextValue);
  1027. }
  1028. } else if (typeof handler.onReject === 'function') {
  1029. nextValue = handler.onReject(nextValue);
  1030. nextStatus = STATUS_RESOLVED;
  1031. if (handler.thisPromise._unhandledRejection) {
  1032. this.removeUnhandeledRejection(handler.thisPromise);
  1033. }
  1034. }
  1035. } catch (ex) {
  1036. nextStatus = STATUS_REJECTED;
  1037. nextValue = ex;
  1038. }
  1039. handler.nextPromise._updateStatus(nextStatus, nextValue);
  1040. if (Date.now() >= timeoutAt) {
  1041. break;
  1042. }
  1043. }
  1044. if (this.handlers.length > 0) {
  1045. setTimeout(this.runHandlers.bind(this), 0);
  1046. return;
  1047. }
  1048. this.running = false;
  1049. },
  1050. addUnhandledRejection: function addUnhandledRejection(promise) {
  1051. this.unhandledRejections.push({
  1052. promise: promise,
  1053. time: Date.now()
  1054. });
  1055. this.scheduleRejectionCheck();
  1056. },
  1057. removeUnhandeledRejection: function removeUnhandeledRejection(promise) {
  1058. promise._unhandledRejection = false;
  1059. for (var i = 0; i < this.unhandledRejections.length; i++) {
  1060. if (this.unhandledRejections[i].promise === promise) {
  1061. this.unhandledRejections.splice(i);
  1062. i--;
  1063. }
  1064. }
  1065. },
  1066. scheduleRejectionCheck: function scheduleRejectionCheck() {
  1067. if (this.pendingRejectionCheck) {
  1068. return;
  1069. }
  1070. this.pendingRejectionCheck = true;
  1071. setTimeout(function rejectionCheck() {
  1072. this.pendingRejectionCheck = false;
  1073. var now = Date.now();
  1074. for (var i = 0; i < this.unhandledRejections.length; i++) {
  1075. if (now - this.unhandledRejections[i].time > REJECTION_TIMEOUT) {
  1076. var unhandled = this.unhandledRejections[i].promise._value;
  1077. var msg = 'Unhandled rejection: ' + unhandled;
  1078. if (unhandled.stack) {
  1079. msg += '\n' + unhandled.stack;
  1080. }
  1081. warn(msg);
  1082. this.unhandledRejections.splice(i);
  1083. i--;
  1084. }
  1085. }
  1086. if (this.unhandledRejections.length) {
  1087. this.scheduleRejectionCheck();
  1088. }
  1089. }.bind(this), REJECTION_TIMEOUT);
  1090. }
  1091. };
  1092. function Promise(resolver) {
  1093. this._status = STATUS_PENDING;
  1094. this._handlers = [];
  1095. try {
  1096. resolver.call(this, this._resolve.bind(this), this._reject.bind(this));
  1097. } catch (e) {
  1098. this._reject(e);
  1099. }
  1100. }
  1101. /**
  1102. * Builds a promise that is resolved when all the passed in promises are
  1103. * resolved.
  1104. * @param {array} array of data and/or promises to wait for.
  1105. * @return {Promise} New dependant promise.
  1106. */
  1107. Promise.all = function Promise_all(promises) {
  1108. var resolveAll, rejectAll;
  1109. var deferred = new Promise(function (resolve, reject) {
  1110. resolveAll = resolve;
  1111. rejectAll = reject;
  1112. });
  1113. var unresolved = promises.length;
  1114. var results = [];
  1115. if (unresolved === 0) {
  1116. resolveAll(results);
  1117. return deferred;
  1118. }
  1119. function reject(reason) {
  1120. if (deferred._status === STATUS_REJECTED) {
  1121. return;
  1122. }
  1123. results = [];
  1124. rejectAll(reason);
  1125. }
  1126. for (var i = 0, ii = promises.length; i < ii; ++i) {
  1127. var promise = promises[i];
  1128. var resolve = (function(i) {
  1129. return function(value) {
  1130. if (deferred._status === STATUS_REJECTED) {
  1131. return;
  1132. }
  1133. results[i] = value;
  1134. unresolved--;
  1135. if (unresolved === 0) {
  1136. resolveAll(results);
  1137. }
  1138. };
  1139. })(i);
  1140. if (Promise.isPromise(promise)) {
  1141. promise.then(resolve, reject);
  1142. } else {
  1143. resolve(promise);
  1144. }
  1145. }
  1146. return deferred;
  1147. };
  1148. /**
  1149. * Checks if the value is likely a promise (has a 'then' function).
  1150. * @return {boolean} true if value is thenable
  1151. */
  1152. Promise.isPromise = function Promise_isPromise(value) {
  1153. return value && typeof value.then === 'function';
  1154. };
  1155. /**
  1156. * Creates resolved promise
  1157. * @param value resolve value
  1158. * @returns {Promise}
  1159. */
  1160. Promise.resolve = function Promise_resolve(value) {
  1161. return new Promise(function (resolve) { resolve(value); });
  1162. };
  1163. /**
  1164. * Creates rejected promise
  1165. * @param reason rejection value
  1166. * @returns {Promise}
  1167. */
  1168. Promise.reject = function Promise_reject(reason) {
  1169. return new Promise(function (resolve, reject) { reject(reason); });
  1170. };
  1171. Promise.prototype = {
  1172. _status: null,
  1173. _value: null,
  1174. _handlers: null,
  1175. _unhandledRejection: null,
  1176. _updateStatus: function Promise__updateStatus(status, value) {
  1177. if (this._status === STATUS_RESOLVED ||
  1178. this._status === STATUS_REJECTED) {
  1179. return;
  1180. }
  1181. if (status === STATUS_RESOLVED &&
  1182. Promise.isPromise(value)) {
  1183. value.then(this._updateStatus.bind(this, STATUS_RESOLVED),
  1184. this._updateStatus.bind(this, STATUS_REJECTED));
  1185. return;
  1186. }
  1187. this._status = status;
  1188. this._value = value;
  1189. if (status === STATUS_REJECTED && this._handlers.length === 0) {
  1190. this._unhandledRejection = true;
  1191. HandlerManager.addUnhandledRejection(this);
  1192. }
  1193. HandlerManager.scheduleHandlers(this);
  1194. },
  1195. _resolve: function Promise_resolve(value) {
  1196. this._updateStatus(STATUS_RESOLVED, value);
  1197. },
  1198. _reject: function Promise_reject(reason) {
  1199. this._updateStatus(STATUS_REJECTED, reason);
  1200. },
  1201. then: function Promise_then(onResolve, onReject) {
  1202. var nextPromise = new Promise(function (resolve, reject) {
  1203. this.resolve = resolve;
  1204. this.reject = reject;
  1205. });
  1206. this._handlers.push({
  1207. thisPromise: this,
  1208. onResolve: onResolve,
  1209. onReject: onReject,
  1210. nextPromise: nextPromise
  1211. });
  1212. HandlerManager.scheduleHandlers(this);
  1213. return nextPromise;
  1214. },
  1215. catch: function Promise_catch(onReject) {
  1216. return this.then(undefined, onReject);
  1217. }
  1218. };
  1219. globalScope.Promise = Promise;
  1220. })();
  1221. var StatTimer = (function StatTimerClosure() {
  1222. function rpad(str, pad, length) {
  1223. while (str.length < length) {
  1224. str += pad;
  1225. }
  1226. return str;
  1227. }
  1228. function StatTimer() {
  1229. this.started = {};
  1230. this.times = [];
  1231. this.enabled = true;
  1232. }
  1233. StatTimer.prototype = {
  1234. time: function StatTimer_time(name) {
  1235. if (!this.enabled) {
  1236. return;
  1237. }
  1238. if (name in this.started) {
  1239. warn('Timer is already running for ' + name);
  1240. }
  1241. this.started[name] = Date.now();
  1242. },
  1243. timeEnd: function StatTimer_timeEnd(name) {
  1244. if (!this.enabled) {
  1245. return;
  1246. }
  1247. if (!(name in this.started)) {
  1248. warn('Timer has not been started for ' + name);
  1249. }
  1250. this.times.push({
  1251. 'name': name,
  1252. 'start': this.started[name],
  1253. 'end': Date.now()
  1254. });
  1255. // Remove timer from started so it can be called again.
  1256. delete this.started[name];
  1257. },
  1258. toString: function StatTimer_toString() {
  1259. var i, ii;
  1260. var times = this.times;
  1261. var out = '';
  1262. // Find the longest name for padding purposes.
  1263. var longest = 0;
  1264. for (i = 0, ii = times.length; i < ii; ++i) {
  1265. var name = times[i]['name'];
  1266. if (name.length > longest) {
  1267. longest = name.length;
  1268. }
  1269. }
  1270. for (i = 0, ii = times.length; i < ii; ++i) {
  1271. var span = times[i];
  1272. var duration = span.end - span.start;
  1273. out += rpad(span['name'], ' ', longest) + ' ' + duration + 'ms\n';
  1274. }
  1275. return out;
  1276. }
  1277. };
  1278. return StatTimer;
  1279. })();
  1280. PDFJS.createBlob = function createBlob(data, contentType) {
  1281. if (typeof Blob !== 'undefined') {
  1282. return new Blob([data], { type: contentType });
  1283. }
  1284. // Blob builder is deprecated in FF14 and removed in FF18.
  1285. var bb = new MozBlobBuilder();
  1286. bb.append(data);
  1287. return bb.getBlob(contentType);
  1288. };
  1289. PDFJS.createObjectURL = (function createObjectURLClosure() {
  1290. // Blob/createObjectURL is not available, falling back to data schema.
  1291. var digits =
  1292. 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
  1293. return function createObjectURL(data, contentType) {
  1294. if (!PDFJS.disableCreateObjectURL &&
  1295. typeof URL !== 'undefined' && URL.createObjectURL) {
  1296. var blob = PDFJS.createBlob(data, contentType);
  1297. return URL.createObjectURL(blob);
  1298. }
  1299. var buffer = 'data:' + contentType + ';base64,';
  1300. for (var i = 0, ii = data.length; i < ii; i += 3) {
  1301. var b1 = data[i] & 0xFF;
  1302. var b2 = data[i + 1] & 0xFF;
  1303. var b3 = data[i + 2] & 0xFF;
  1304. var d1 = b1 >> 2, d2 = ((b1 & 3) << 4) | (b2 >> 4);
  1305. var d3 = i + 1 < ii ? ((b2 & 0xF) << 2) | (b3 >> 6) : 64;
  1306. var d4 = i + 2 < ii ? (b3 & 0x3F) : 64;
  1307. buffer += digits[d1] + digits[d2] + digits[d3] + digits[d4];
  1308. }
  1309. return buffer;
  1310. };
  1311. })();
  1312. function MessageHandler(name, comObj) {
  1313. this.name = name;
  1314. this.comObj = comObj;
  1315. this.callbackIndex = 1;
  1316. this.postMessageTransfers = true;
  1317. var callbacksCapabilities = this.callbacksCapabilities = {};
  1318. var ah = this.actionHandler = {};
  1319. ah['console_log'] = [function ahConsoleLog(data) {
  1320. console.log.apply(console, data);
  1321. }];
  1322. ah['console_error'] = [function ahConsoleError(data) {
  1323. console.error.apply(console, data);
  1324. }];
  1325. ah['_unsupported_feature'] = [function ah_unsupportedFeature(data) {
  1326. UnsupportedManager.notify(data);
  1327. }];
  1328. comObj.onmessage = function messageHandlerComObjOnMessage(event) {
  1329. var data = event.data;
  1330. if (data.isReply) {
  1331. var callbackId = data.callbackId;
  1332. if (data.callbackId in callbacksCapabilities) {
  1333. var callback = callbacksCapabilities[callbackId];
  1334. delete callbacksCapabilities[callbackId];
  1335. if ('error' in data) {
  1336. callback.reject(data.error);
  1337. } else {
  1338. callback.resolve(data.data);
  1339. }
  1340. } else {
  1341. error('Cannot resolve callback ' + callbackId);
  1342. }
  1343. } else if (data.action in ah) {
  1344. var action = ah[data.action];
  1345. if (data.callbackId) {
  1346. Promise.resolve().then(function () {
  1347. return action[0].call(action[1], data.data);
  1348. }).then(function (result) {
  1349. comObj.postMessage({
  1350. isReply: true,
  1351. callbackId: data.callbackId,
  1352. data: result
  1353. });
  1354. }, function (reason) {
  1355. comObj.postMessage({
  1356. isReply: true,
  1357. callbackId: data.callbackId,
  1358. error: reason
  1359. });
  1360. });
  1361. } else {
  1362. action[0].call(action[1], data.data);
  1363. }
  1364. } else {
  1365. error('Unknown action from worker: ' + data.action);
  1366. }
  1367. };
  1368. }
  1369. MessageHandler.prototype = {
  1370. on: function messageHandlerOn(actionName, handler, scope) {
  1371. var ah = this.actionHandler;
  1372. if (ah[actionName]) {
  1373. error('There is already an actionName called "' + actionName + '"');
  1374. }
  1375. ah[actionName] = [handler, scope];
  1376. },
  1377. /**
  1378. * Sends a message to the comObj to invoke the action with the supplied data.
  1379. * @param {String} actionName Action to call.
  1380. * @param {JSON} data JSON data to send.
  1381. * @param {Array} [transfers] Optional list of transfers/ArrayBuffers
  1382. */
  1383. send: function messageHandlerSend(actionName, data, transfers) {
  1384. var message = {
  1385. action: actionName,
  1386. data: data
  1387. };
  1388. this.postMessage(message, transfers);
  1389. },
  1390. /**
  1391. * Sends a message to the comObj to invoke the action with the supplied data.
  1392. * Expects that other side will callback with the response.
  1393. * @param {String} actionName Action to call.
  1394. * @param {JSON} data JSON data to send.
  1395. * @param {Array} [transfers] Optional list of transfers/ArrayBuffers.
  1396. * @returns {Promise} Promise to be resolved with response data.
  1397. */
  1398. sendWithPromise:
  1399. function messageHandlerSendWithPromise(actionName, data, transfers) {
  1400. var callbackId = this.callbackIndex++;
  1401. var message = {
  1402. action: actionName,
  1403. data: data,
  1404. callbackId: callbackId
  1405. };
  1406. var capability = createPromiseCapability();
  1407. this.callbacksCapabilities[callbackId] = capability;
  1408. try {
  1409. this.postMessage(message, transfers);
  1410. } catch (e) {
  1411. capability.reject(e);
  1412. }
  1413. return capability.promise;
  1414. },
  1415. /**
  1416. * Sends raw message to the comObj.
  1417. * @private
  1418. * @param message {Object} Raw message.
  1419. * @param transfers List of transfers/ArrayBuffers, or undefined.
  1420. */
  1421. postMessage: function (message, transfers) {
  1422. if (transfers && this.postMessageTransfers) {
  1423. this.comObj.postMessage(message, transfers);
  1424. } else {
  1425. this.comObj.postMessage(message);
  1426. }
  1427. }
  1428. };
  1429. function loadJpegStream(id, imageUrl, objs) {
  1430. var img = new Image();
  1431. img.onload = (function loadJpegStream_onloadClosure() {
  1432. objs.resolve(id, img);
  1433. });
  1434. img.onerror = (function loadJpegStream_onerrorClosure() {
  1435. objs.resolve(id, null);
  1436. warn('Error during JPEG image loading');
  1437. });
  1438. img.src = imageUrl;
  1439. }
  1440. /**
  1441. * The maximum allowed image size in total pixels e.g. width * height. Images
  1442. * above this value will not be drawn. Use -1 for no limit.
  1443. * @var {number}
  1444. */
  1445. PDFJS.maxImageSize = (PDFJS.maxImageSize === undefined ?
  1446. -1 : PDFJS.maxImageSize);
  1447. /**
  1448. * The url of where the predefined Adobe CMaps are located. Include trailing
  1449. * slash.
  1450. * @var {string}
  1451. */
  1452. PDFJS.cMapUrl = (PDFJS.cMapUrl === undefined ? null : PDFJS.cMapUrl);
  1453. /**
  1454. * Specifies if CMaps are binary packed.
  1455. * @var {boolean}
  1456. */
  1457. PDFJS.cMapPacked = PDFJS.cMapPacked === undefined ? false : PDFJS.cMapPacked;
  1458. /**
  1459. * By default fonts are converted to OpenType fonts and loaded via font face
  1460. * rules. If disabled, the font will be rendered using a built in font renderer
  1461. * that constructs the glyphs with primitive path commands.
  1462. * @var {boolean}
  1463. */
  1464. PDFJS.disableFontFace = (PDFJS.disableFontFace === undefined ?
  1465. false : PDFJS.disableFontFace);
  1466. /**
  1467. * Path for image resources, mainly for annotation icons. Include trailing
  1468. * slash.
  1469. * @var {string}
  1470. */
  1471. PDFJS.imageResourcesPath = (PDFJS.imageResourcesPath === undefined ?
  1472. '' : PDFJS.imageResourcesPath);
  1473. /**
  1474. * Disable the web worker and run all code on the main thread. This will happen
  1475. * automatically if the browser doesn't support workers or sending typed arrays
  1476. * to workers.
  1477. * @var {boolean}
  1478. */
  1479. PDFJS.disableWorker = (PDFJS.disableWorker === undefined ?
  1480. false : PDFJS.disableWorker);
  1481. /**
  1482. * Path and filename of the worker file. Required when the worker is enabled in
  1483. * development mode. If unspecified in the production build, the worker will be
  1484. * loaded based on the location of the pdf.js file.
  1485. * @var {string}
  1486. */
  1487. PDFJS.workerSrc = (PDFJS.workerSrc === undefined ? null : PDFJS.workerSrc);
  1488. /**
  1489. * Disable range request loading of PDF files. When enabled and if the server
  1490. * supports partial content requests then the PDF will be fetched in chunks.
  1491. * Enabled (false) by default.
  1492. * @var {boolean}
  1493. */
  1494. PDFJS.disableRange = (PDFJS.disableRange === undefined ?
  1495. false : PDFJS.disableRange);
  1496. /**
  1497. * Disable streaming of PDF file data. By default PDF.js attempts to load PDF
  1498. * in chunks. This default behavior can be disabled.
  1499. * @var {boolean}
  1500. */
  1501. PDFJS.disableStream = (PDFJS.disableStream === undefined ?
  1502. false : PDFJS.disableStream);
  1503. /**
  1504. * Disable pre-fetching of PDF file data. When range requests are enabled PDF.js
  1505. * will automatically keep fetching more data even if it isn't needed to display
  1506. * the current page. This default behavior can be disabled.
  1507. *
  1508. * NOTE: It is also necessary to disable streaming, see above,
  1509. * in order for disabling of pre-fetching to work correctly.
  1510. * @var {boolean}
  1511. */
  1512. PDFJS.disableAutoFetch = (PDFJS.disableAutoFetch === undefined ?
  1513. false : PDFJS.disableAutoFetch);
  1514. /**
  1515. * Enables special hooks for debugging PDF.js.
  1516. * @var {boolean}
  1517. */
  1518. PDFJS.pdfBug = (PDFJS.pdfBug === undefined ? false : PDFJS.pdfBug);
  1519. /**
  1520. * Enables transfer usage in postMessage for ArrayBuffers.
  1521. * @var {boolean}
  1522. */
  1523. PDFJS.postMessageTransfers = (PDFJS.postMessageTransfers === undefined ?
  1524. true : PDFJS.postMessageTransfers);
  1525. /**
  1526. * Disables URL.createObjectURL usage.
  1527. * @var {boolean}
  1528. */
  1529. PDFJS.disableCreateObjectURL = (PDFJS.disableCreateObjectURL === undefined ?
  1530. false : PDFJS.disableCreateObjectURL);
  1531. /**
  1532. * Disables WebGL usage.
  1533. * @var {boolean}
  1534. */
  1535. PDFJS.disableWebGL = (PDFJS.disableWebGL === undefined ?
  1536. true : PDFJS.disableWebGL);
  1537. /**
  1538. * Disables fullscreen support, and by extension Presentation Mode,
  1539. * in browsers which support the fullscreen API.
  1540. * @var {boolean}
  1541. */
  1542. PDFJS.disableFullscreen = (PDFJS.disableFullscreen === undefined ?
  1543. false : PDFJS.disableFullscreen);
  1544. /**
  1545. * Enables CSS only zooming.
  1546. * @var {boolean}
  1547. */
  1548. PDFJS.useOnlyCssZoom = (PDFJS.useOnlyCssZoom === undefined ?
  1549. false : PDFJS.useOnlyCssZoom);
  1550. /**
  1551. * Controls the logging level.
  1552. * The constants from PDFJS.VERBOSITY_LEVELS should be used:
  1553. * - errors
  1554. * - warnings [default]
  1555. * - infos
  1556. * @var {number}
  1557. */
  1558. PDFJS.verbosity = (PDFJS.verbosity === undefined ?
  1559. PDFJS.VERBOSITY_LEVELS.warnings : PDFJS.verbosity);
  1560. /**
  1561. * The maximum supported canvas size in total pixels e.g. width * height.
  1562. * The default value is 4096 * 4096. Use -1 for no limit.
  1563. * @var {number}
  1564. */
  1565. PDFJS.maxCanvasPixels = (PDFJS.maxCanvasPixels === undefined ?
  1566. 16777216 : PDFJS.maxCanvasPixels);
  1567. /**
  1568. * Opens external links in a new window if enabled. The default behavior opens
  1569. * external links in the PDF.js window.
  1570. * @var {boolean}
  1571. */
  1572. PDFJS.openExternalLinksInNewWindow = (
  1573. PDFJS.openExternalLinksInNewWindow === undefined ?
  1574. false : PDFJS.openExternalLinksInNewWindow);
  1575. /**
  1576. * Document initialization / loading parameters object.
  1577. *
  1578. * @typedef {Object} DocumentInitParameters
  1579. * @property {string} url - The URL of the PDF.
  1580. * @property {TypedArray|Array|string} data - Binary PDF data. Use typed arrays
  1581. * (Uint8Array) to improve the memory usage. If PDF data is BASE64-encoded,
  1582. * use atob() to convert it to a binary string first.
  1583. * @property {Object} httpHeaders - Basic authentication headers.
  1584. * @property {boolean} withCredentials - Indicates whether or not cross-site
  1585. * Access-Control requests should be made using credentials such as cookies
  1586. * or authorization headers. The default is false.
  1587. * @property {string} password - For decrypting password-protected PDFs.
  1588. * @property {TypedArray} initialData - A typed array with the first portion or
  1589. * all of the pdf data. Used by the extension since some data is already
  1590. * loaded before the switch to range requests.
  1591. * @property {number} length - The PDF file length. It's used for progress
  1592. * reports and range requests operations.
  1593. * @property {PDFDataRangeTransport} range
  1594. */
  1595. /**
  1596. * @typedef {Object} PDFDocumentStats
  1597. * @property {Array} streamTypes - Used stream types in the document (an item
  1598. * is set to true if specific stream ID was used in the document).
  1599. * @property {Array} fontTypes - Used font type in the document (an item is set
  1600. * to true if specific font ID was used in the document).
  1601. */
  1602. /**
  1603. * This is the main entry point for loading a PDF and interacting with it.
  1604. * NOTE: If a URL is used to fetch the PDF data a standard XMLHttpRequest(XHR)
  1605. * is used, which means it must follow the same origin rules that any XHR does
  1606. * e.g. No cross domain requests without CORS.
  1607. *
  1608. * @param {string|TypedArray|DocumentInitParameters|PDFDataRangeTransport} src
  1609. * Can be a url to where a PDF is located, a typed array (Uint8Array)
  1610. * already populated with data or parameter object.
  1611. *
  1612. * @param {PDFDataRangeTransport} pdfDataRangeTransport (deprecated) It is used
  1613. * if you want to manually serve range requests for data in the PDF.
  1614. *
  1615. * @param {function} passwordCallback (deprecated) It is used to request a
  1616. * password if wrong or no password was provided. The callback receives two
  1617. * parameters: function that needs to be called with new password and reason
  1618. * (see {PasswordResponses}).
  1619. *
  1620. * @param {function} progressCallback (deprecated) It is used to be able to
  1621. * monitor the loading progress of the PDF file (necessary to implement e.g.
  1622. * a loading bar). The callback receives an {Object} with the properties:
  1623. * {number} loaded and {number} total.
  1624. *
  1625. * @return {PDFDocumentLoadingTask}
  1626. */
  1627. PDFJS.getDocument = function getDocument(src,
  1628. pdfDataRangeTransport,
  1629. passwordCallback,
  1630. progressCallback) {
  1631. var task = new PDFDocumentLoadingTask();
  1632. // Support of the obsolete arguments (for compatibility with API v1.0)
  1633. if (pdfDataRangeTransport) {
  1634. if (!(pdfDataRangeTransport instanceof PDFDataRangeTransport)) {
  1635. // Not a PDFDataRangeTransport instance, trying to add missing properties.
  1636. pdfDataRangeTransport = Object.create(pdfDataRangeTransport);
  1637. pdfDataRangeTransport.length = src.length;
  1638. pdfDataRangeTransport.initialData = src.initialData;
  1639. }
  1640. src = Object.create(src);
  1641. src.range = pdfDataRangeTransport;
  1642. }
  1643. task.onPassword = passwordCallback || null;
  1644. task.onProgress = progressCallback || null;
  1645. var workerInitializedCapability, transport;
  1646. var source;
  1647. if (typeof src === 'string') {
  1648. source = { url: src };
  1649. } else if (isArrayBuffer(src)) {
  1650. source = { data: src };
  1651. } else if (src instanceof PDFDataRangeTransport) {
  1652. source = { range: src };
  1653. } else {
  1654. if (typeof src !== 'object') {
  1655. error('Invalid parameter in getDocument, need either Uint8Array, ' +
  1656. 'string or a parameter object');
  1657. }
  1658. if (!src.url && !src.data && !src.range) {
  1659. error('Invalid parameter object: need either .data, .range or .url');
  1660. }
  1661. source = src;
  1662. }
  1663. var params = {};
  1664. for (var key in source) {
  1665. if (key === 'url' && typeof window !== 'undefined') {
  1666. // The full path is required in the 'url' field.
  1667. params[key] = combineUrl(window.location.href, source[key]);
  1668. continue;
  1669. } else if (key === 'range') {
  1670. continue;
  1671. } else if (key === 'data' && !(source[key] instanceof Uint8Array)) {
  1672. // Converting string or array-like data to Uint8Array.
  1673. var pdfBytes = source[key];
  1674. if (typeof pdfBytes === 'string') {
  1675. params[key] = stringToBytes(pdfBytes);
  1676. } else if (typeof pdfBytes === 'object' && pdfBytes !== null &&
  1677. !isNaN(pdfBytes.length)) {
  1678. params[key] = new Uint8Array(pdfBytes);
  1679. } else {
  1680. error('Invalid PDF binary data: either typed array, string or ' +
  1681. 'array-like object is expected in the data property.');
  1682. }
  1683. continue;
  1684. }
  1685. params[key] = source[key];
  1686. }
  1687. workerInitializedCapability = createPromiseCapability();
  1688. transport = new WorkerTransport(workerInitializedCapability, source.range);
  1689. workerInitializedCapability.promise.then(function transportInitialized() {
  1690. transport.fetchDocument(task, params);
  1691. });
  1692. return task;
  1693. };
  1694. /**
  1695. * PDF document loading operation.
  1696. * @class
  1697. */
  1698. var PDFDocumentLoadingTask = (function PDFDocumentLoadingTaskClosure() {
  1699. /** @constructs PDFDocumentLoadingTask */
  1700. function PDFDocumentLoadingTask() {
  1701. this._capability = createPromiseCapability();
  1702. /**
  1703. * Callback to request a password if wrong or no password was provided.
  1704. * The callback receives two parameters: function that needs to be called
  1705. * with new password and reason (see {PasswordResponses}).
  1706. */
  1707. this.onPassword = null;
  1708. /**
  1709. * Callback to be able to monitor the loading progress of the PDF file
  1710. * (necessary to implement e.g. a loading bar). The callback receives
  1711. * an {Object} with the properties: {number} loaded and {number} total.
  1712. */
  1713. this.onProgress = null;
  1714. }
  1715. PDFDocumentLoadingTask.prototype =
  1716. /** @lends PDFDocumentLoadingTask.prototype */ {
  1717. /**
  1718. * @return {Promise}
  1719. */
  1720. get promise() {
  1721. return this._capability.promise;
  1722. },
  1723. // TODO add cancel or abort method
  1724. /**
  1725. * Registers callbacks to indicate the document loading completion.
  1726. *
  1727. * @param {function} onFulfilled The callback for the loading completion.
  1728. * @param {function} onRejected The callback for the loading failure.
  1729. * @return {Promise} A promise that is resolved after the onFulfilled or
  1730. * onRejected callback.
  1731. */
  1732. then: function PDFDocumentLoadingTask_then(onFulfilled, onRejected) {
  1733. return this.promise.then.apply(this.promise, arguments);
  1734. }
  1735. };
  1736. return PDFDocumentLoadingTask;
  1737. })();
  1738. /**
  1739. * Abstract class to support range requests file loading.
  1740. * @class
  1741. */
  1742. var PDFDataRangeTransport = (function pdfDataRangeTransportClosure() {
  1743. /**
  1744. * @constructs PDFDataRangeTransport
  1745. * @param {number} length
  1746. * @param {Uint8Array} initialData
  1747. */
  1748. function PDFDataRangeTransport(length, initialData) {
  1749. this.length = length;
  1750. this.initialData = initialData;
  1751. this._rangeListeners = [];
  1752. this._progressListeners = [];
  1753. this._progressiveReadListeners = [];
  1754. this._readyCapability = createPromiseCapability();
  1755. }
  1756. PDFDataRangeTransport.prototype =
  1757. /** @lends PDFDataRangeTransport.prototype */ {
  1758. addRangeListener:
  1759. function PDFDataRangeTransport_addRangeListener(listener) {
  1760. this._rangeListeners.push(listener);
  1761. },
  1762. addProgressListener:
  1763. function PDFDataRangeTransport_addProgressListener(listener) {
  1764. this._progressListeners.push(listener);
  1765. },
  1766. addProgressiveReadListener:
  1767. function PDFDataRangeTransport_addProgressiveReadListener(listener) {
  1768. this._progressiveReadListeners.push(listener);
  1769. },
  1770. onDataRange: function PDFDataRangeTransport_onDataRange(begin, chunk) {
  1771. var listeners = this._rangeListeners;
  1772. for (var i = 0, n = listeners.length; i < n; ++i) {
  1773. listeners[i](begin, chunk);
  1774. }
  1775. },
  1776. onDataProgress: function PDFDataRangeTransport_onDataProgress(loaded) {
  1777. this._readyCapability.promise.then(function () {
  1778. var listeners = this._progressListeners;
  1779. for (var i = 0, n = listeners.length; i < n; ++i) {
  1780. listeners[i](loaded);
  1781. }
  1782. }.bind(this));
  1783. },
  1784. onDataProgressiveRead:
  1785. function PDFDataRangeTransport_onDataProgress(chunk) {
  1786. this._readyCapability.promise.then(function () {
  1787. var listeners = this._progressiveReadListeners;
  1788. for (var i = 0, n = listeners.length; i < n; ++i) {
  1789. listeners[i](chunk);
  1790. }
  1791. }.bind(this));
  1792. },
  1793. transportReady: function PDFDataRangeTransport_transportReady() {
  1794. this._readyCapability.resolve();
  1795. },
  1796. requestDataRange:
  1797. function PDFDataRangeTransport_requestDataRange(begin, end) {
  1798. throw new Error('Abstract method PDFDataRangeTransport.requestDataRange');
  1799. }
  1800. };
  1801. return PDFDataRangeTransport;
  1802. })();
  1803. PDFJS.PDFDataRangeTransport = PDFDataRangeTransport;
  1804. /**
  1805. * Proxy to a PDFDocument in the worker thread. Also, contains commonly used
  1806. * properties that can be read synchronously.
  1807. * @class
  1808. */
  1809. var PDFDocumentProxy = (function PDFDocumentProxyClosure() {
  1810. function PDFDocumentProxy(pdfInfo, transport) {
  1811. this.pdfInfo = pdfInfo;
  1812. this.transport = transport;
  1813. }
  1814. PDFDocumentProxy.prototype = /** @lends PDFDocumentProxy.prototype */ {
  1815. /**
  1816. * @return {number} Total number of pages the PDF contains.
  1817. */
  1818. get numPages() {
  1819. return this.pdfInfo.numPages;
  1820. },
  1821. /**
  1822. * @return {string} A unique ID to identify a PDF. Not guaranteed to be
  1823. * unique.
  1824. */
  1825. get fingerprint() {
  1826. return this.pdfInfo.fingerprint;
  1827. },
  1828. /**
  1829. * @param {number} pageNumber The page number to get. The first page is 1.
  1830. * @return {Promise} A promise that is resolved with a {@link PDFPageProxy}
  1831. * object.
  1832. */
  1833. getPage: function PDFDocumentProxy_getPage(pageNumber) {
  1834. return this.transport.getPage(pageNumber);
  1835. },
  1836. /**
  1837. * @param {{num: number, gen: number}} ref The page reference. Must have
  1838. * the 'num' and 'gen' properties.
  1839. * @return {Promise} A promise that is resolved with the page index that is
  1840. * associated with the reference.
  1841. */
  1842. getPageIndex: function PDFDocumentProxy_getPageIndex(ref) {
  1843. return this.transport.getPageIndex(ref);
  1844. },
  1845. /**
  1846. * @return {Promise} A promise that is resolved with a lookup table for
  1847. * mapping named destinations to reference numbers.
  1848. *
  1849. * This can be slow for large documents: use getDestination instead
  1850. */
  1851. getDestinations: function PDFDocumentProxy_getDestinations() {
  1852. return this.transport.getDestinations();
  1853. },
  1854. /**
  1855. * @param {string} id The named destination to get.
  1856. * @return {Promise} A promise that is resolved with all information
  1857. * of the given named destination.
  1858. */
  1859. getDestination: function PDFDocumentProxy_getDestination(id) {
  1860. return this.transport.getDestination(id);
  1861. },
  1862. /**
  1863. * @return {Promise} A promise that is resolved with a lookup table for
  1864. * mapping named attachments to their content.
  1865. */
  1866. getAttachments: function PDFDocumentProxy_getAttachments() {
  1867. return this.transport.getAttachments();
  1868. },
  1869. /**
  1870. * @return {Promise} A promise that is resolved with an array of all the
  1871. * JavaScript strings in the name tree.
  1872. */
  1873. getJavaScript: function PDFDocumentProxy_getJavaScript() {
  1874. return this.transport.getJavaScript();
  1875. },
  1876. /**
  1877. * @return {Promise} A promise that is resolved with an {Array} that is a
  1878. * tree outline (if it has one) of the PDF. The tree is in the format of:
  1879. * [
  1880. * {
  1881. * title: string,
  1882. * bold: boolean,
  1883. * italic: boolean,
  1884. * color: rgb array,
  1885. * dest: dest obj,
  1886. * items: array of more items like this
  1887. * },
  1888. * ...
  1889. * ].
  1890. */
  1891. getOutline: function PDFDocumentProxy_getOutline() {
  1892. return this.transport.getOutline();
  1893. },
  1894. /**
  1895. * @return {Promise} A promise that is resolved with an {Object} that has
  1896. * info and metadata properties. Info is an {Object} filled with anything
  1897. * available in the information dictionary and similarly metadata is a
  1898. * {Metadata} object with information from the metadata section of the PDF.
  1899. */
  1900. getMetadata: function PDFDocumentProxy_getMetadata() {
  1901. return this.transport.getMetadata();
  1902. },
  1903. /**
  1904. * @return {Promise} A promise that is resolved with a TypedArray that has
  1905. * the raw data from the PDF.
  1906. */
  1907. getData: function PDFDocumentProxy_getData() {
  1908. return this.transport.getData();
  1909. },
  1910. /**
  1911. * @return {Promise} A promise that is resolved when the document's data
  1912. * is loaded. It is resolved with an {Object} that contains the length
  1913. * property that indicates size of the PDF data in bytes.
  1914. */
  1915. getDownloadInfo: function PDFDocumentProxy_getDownloadInfo() {
  1916. return this.transport.downloadInfoCapability.promise;
  1917. },
  1918. /**
  1919. * @return {Promise} A promise this is resolved with current stats about
  1920. * document structures (see {@link PDFDocumentStats}).
  1921. */
  1922. getStats: function PDFDocumentProxy_getStats() {
  1923. return this.transport.getStats();
  1924. },
  1925. /**
  1926. * Cleans up resources allocated by the document, e.g. created @font-face.
  1927. */
  1928. cleanup: function PDFDocumentProxy_cleanup() {
  1929. this.transport.startCleanup();
  1930. },
  1931. /**
  1932. * Destroys current document instance and terminates worker.
  1933. */
  1934. destroy: function PDFDocumentProxy_destroy() {
  1935. this.transport.destroy();
  1936. }
  1937. };
  1938. return PDFDocumentProxy;
  1939. })();
  1940. /**
  1941. * Page text content.
  1942. *
  1943. * @typedef {Object} TextContent
  1944. * @property {array} items - array of {@link TextItem}
  1945. * @property {Object} styles - {@link TextStyles} objects, indexed by font
  1946. * name.
  1947. */
  1948. /**
  1949. * Page text content part.
  1950. *
  1951. * @typedef {Object} TextItem
  1952. * @property {string} str - text content.
  1953. * @property {string} dir - text direction: 'ttb', 'ltr' or 'rtl'.
  1954. * @property {array} transform - transformation matrix.
  1955. * @property {number} width - width in device space.
  1956. * @property {number} height - height in device space.
  1957. * @property {string} fontName - font name used by pdf.js for converted font.
  1958. */
  1959. /**
  1960. * Text style.
  1961. *
  1962. * @typedef {Object} TextStyle
  1963. * @property {number} ascent - font ascent.
  1964. * @property {number} descent - font descent.
  1965. * @property {boolean} vertical - text is in vertical mode.
  1966. * @property {string} fontFamily - possible font family
  1967. */
  1968. /**
  1969. * Page render parameters.
  1970. *
  1971. * @typedef {Object} RenderParameters
  1972. * @property {Object} canvasContext - A 2D context of a DOM Canvas object.
  1973. * @property {PDFJS.PageViewport} viewport - Rendering viewport obtained by
  1974. * calling of PDFPage.getViewport method.
  1975. * @property {string} intent - Rendering intent, can be 'display' or 'print'
  1976. * (default value is 'display').
  1977. * @property {Object} imageLayer - (optional) An object that has beginLayout,
  1978. * endLayout and appendImage functions.
  1979. * @property {function} continueCallback - (deprecated) A function that will be
  1980. * called each time the rendering is paused. To continue
  1981. * rendering call the function that is the first argument
  1982. * to the callback.
  1983. */
  1984. /**
  1985. * PDF page operator list.
  1986. *
  1987. * @typedef {Object} PDFOperatorList
  1988. * @property {Array} fnArray - Array containing the operator functions.
  1989. * @property {Array} argsArray - Array containing the arguments of the
  1990. * functions.
  1991. */
  1992. /**
  1993. * Proxy to a PDFPage in the worker thread.
  1994. * @class
  1995. */
  1996. var PDFPageProxy = (function PDFPageProxyClosure() {
  1997. function PDFPageProxy(pageIndex, pageInfo, transport) {
  1998. this.pageIndex = pageIndex;
  1999. this.pageInfo = pageInfo;
  2000. this.transport = transport;
  2001. this.stats = new StatTimer();
  2002. this.stats.enabled = !!globalScope.PDFJS.enableStats;
  2003. this.commonObjs = transport.commonObjs;
  2004. this.objs = new PDFObjects();
  2005. this.cleanupAfterRender = false;
  2006. this.pendingDestroy = false;
  2007. this.intentStates = {};
  2008. }
  2009. PDFPageProxy.prototype = /** @lends PDFPageProxy.prototype */ {
  2010. /**
  2011. * @return {number} Page number of the page. First page is 1.
  2012. */
  2013. get pageNumber() {
  2014. return this.pageIndex + 1;
  2015. },
  2016. /**
  2017. * @return {number} The number of degrees the page is rotated clockwise.
  2018. */
  2019. get rotate() {
  2020. return this.pageInfo.rotate;
  2021. },
  2022. /**
  2023. * @return {Object} The reference that points to this page. It has 'num' and
  2024. * 'gen' properties.
  2025. */
  2026. get ref() {
  2027. return this.pageInfo.ref;
  2028. },
  2029. /**
  2030. * @return {Array} An array of the visible portion of the PDF page in the
  2031. * user space units - [x1, y1, x2, y2].
  2032. */
  2033. get view() {
  2034. return this.pageInfo.view;
  2035. },
  2036. /**
  2037. * @param {number} scale The desired scale of the viewport.
  2038. * @param {number} rotate Degrees to rotate the viewport. If omitted this
  2039. * defaults to the page rotation.
  2040. * @return {PDFJS.PageViewport} Contains 'width' and 'height' properties
  2041. * along with transforms required for rendering.
  2042. */
  2043. getViewport: function PDFPageProxy_getViewport(scale, rotate) {
  2044. if (arguments.length < 2) {
  2045. rotate = this.rotate;
  2046. }
  2047. return new PDFJS.PageViewport(this.view, scale, rotate, 0, 0);
  2048. },
  2049. /**
  2050. * @return {Promise} A promise that is resolved with an {Array} of the
  2051. * annotation objects.
  2052. */
  2053. getAnnotations: function PDFPageProxy_getAnnotations() {
  2054. if (this.annotationsPromise) {
  2055. return this.annotationsPromise;
  2056. }
  2057. var promise = this.transport.getAnnotations(this.pageIndex);
  2058. this.annotationsPromise = promise;
  2059. return promise;
  2060. },
  2061. /**
  2062. * Begins the process of rendering a page to the desired context.
  2063. * @param {RenderParameters} params Page render parameters.
  2064. * @return {RenderTask} An object that contains the promise, which
  2065. * is resolved when the page finishes rendering.
  2066. */
  2067. render: function PDFPageProxy_render(params) {
  2068. var stats = this.stats;
  2069. stats.time('Overall');
  2070. // If there was a pending destroy cancel it so no cleanup happens during
  2071. // this call to render.
  2072. this.pendingDestroy = false;
  2073. var renderingIntent = (params.intent === 'print' ? 'print' : 'display');
  2074. if (!this.intentStates[renderingIntent]) {
  2075. this.intentStates[renderingIntent] = {};
  2076. }
  2077. var intentState = this.intentStates[renderingIntent];
  2078. // If there's no displayReadyCapability yet, then the operatorList
  2079. // was never requested before. Make the request and create the promise.
  2080. if (!intentState.displayReadyCapability) {
  2081. intentState.receivingOperatorList = true;
  2082. intentState.displayReadyCapability = createPromiseCapability();
  2083. intentState.operatorList = {
  2084. fnArray: [],
  2085. argsArray: [],
  2086. lastChunk: false
  2087. };
  2088. this.stats.time('Page Request');
  2089. this.transport.messageHandler.send('RenderPageRequest', {
  2090. pageIndex: this.pageNumber - 1,
  2091. intent: renderingIntent
  2092. });
  2093. }
  2094. var internalRenderTask = new InternalRenderTask(complete, params,
  2095. this.objs,
  2096. this.commonObjs,
  2097. intentState.operatorList,
  2098. this.pageNumber);
  2099. internalRenderTask.useRequestAnimationFrame = renderingIntent !== 'print';
  2100. if (!intentState.renderTasks) {
  2101. intentState.renderTasks = [];
  2102. }
  2103. intentState.renderTasks.push(internalRenderTask);
  2104. var renderTask = internalRenderTask.task;
  2105. // Obsolete parameter support
  2106. if (params.continueCallback) {
  2107. renderTask.onContinue = params.continueCallback;
  2108. }
  2109. var self = this;
  2110. intentState.displayReadyCapability.promise.then(
  2111. function pageDisplayReadyPromise(transparency) {
  2112. if (self.pendingDestroy) {
  2113. complete();
  2114. return;
  2115. }
  2116. stats.time('Rendering');
  2117. internalRenderTask.initalizeGraphics(transparency);
  2118. internalRenderTask.operatorListChanged();
  2119. },
  2120. function pageDisplayReadPromiseError(reason) {
  2121. complete(reason);
  2122. }
  2123. );
  2124. function complete(error) {
  2125. var i = intentState.renderTasks.indexOf(internalRenderTask);
  2126. if (i >= 0) {
  2127. intentState.renderTasks.splice(i, 1);
  2128. }
  2129. if (self.cleanupAfterRender) {
  2130. self.pendingDestroy = true;
  2131. }
  2132. self._tryDestroy();
  2133. if (error) {
  2134. internalRenderTask.capability.reject(error);
  2135. } else {
  2136. internalRenderTask.capability.resolve();
  2137. }
  2138. stats.timeEnd('Rendering');
  2139. stats.timeEnd('Overall');
  2140. }
  2141. return renderTask;
  2142. },
  2143. /**
  2144. * @return {Promise} A promise resolved with an {@link PDFOperatorList}
  2145. * object that represents page's operator list.
  2146. */
  2147. getOperatorList: function PDFPageProxy_getOperatorList() {
  2148. function operatorListChanged() {
  2149. if (intentState.operatorList.lastChunk) {
  2150. intentState.opListReadCapability.resolve(intentState.operatorList);
  2151. }
  2152. }
  2153. var renderingIntent = 'oplist';
  2154. if (!this.intentStates[renderingIntent]) {
  2155. this.intentStates[renderingIntent] = {};
  2156. }
  2157. var intentState = this.intentStates[renderingIntent];
  2158. if (!intentState.opListReadCapability) {
  2159. var opListTask = {};
  2160. opListTask.operatorListChanged = operatorListChanged;
  2161. intentState.receivingOperatorList = true;
  2162. intentState.opListReadCapability = createPromiseCapability();
  2163. intentState.renderTasks = [];
  2164. intentState.renderTasks.push(opListTask);
  2165. intentState.operatorList = {
  2166. fnArray: [],
  2167. argsArray: [],
  2168. lastChunk: false
  2169. };
  2170. this.transport.messageHandler.send('RenderPageRequest', {
  2171. pageIndex: this.pageIndex,
  2172. intent: renderingIntent
  2173. });
  2174. }
  2175. return intentState.opListReadCapability.promise;
  2176. },
  2177. /**
  2178. * @return {Promise} That is resolved a {@link TextContent}
  2179. * object that represent the page text content.
  2180. */
  2181. getTextContent: function PDFPageProxy_getTextContent() {
  2182. return this.transport.messageHandler.sendWithPromise('GetTextContent', {
  2183. pageIndex: this.pageNumber - 1
  2184. });
  2185. },
  2186. /**
  2187. * Destroys resources allocated by the page.
  2188. */
  2189. destroy: function PDFPageProxy_destroy() {
  2190. this.pendingDestroy = true;
  2191. this._tryDestroy();
  2192. },
  2193. /**
  2194. * For internal use only. Attempts to clean up if rendering is in a state
  2195. * where that's possible.
  2196. * @ignore
  2197. */
  2198. _tryDestroy: function PDFPageProxy__destroy() {
  2199. if (!this.pendingDestroy ||
  2200. Object.keys(this.intentStates).some(function(intent) {
  2201. var intentState = this.intentStates[intent];
  2202. return (intentState.renderTasks.length !== 0 ||
  2203. intentState.receivingOperatorList);
  2204. }, this)) {
  2205. return;
  2206. }
  2207. Object.keys(this.intentStates).forEach(function(intent) {
  2208. delete this.intentStates[intent];
  2209. }, this);
  2210. this.objs.clear();
  2211. this.annotationsPromise = null;
  2212. this.pendingDestroy = false;
  2213. },
  2214. /**
  2215. * For internal use only.
  2216. * @ignore
  2217. */
  2218. _startRenderPage: function PDFPageProxy_startRenderPage(transparency,
  2219. intent) {
  2220. var intentState = this.intentStates[intent];
  2221. // TODO Refactor RenderPageRequest to separate rendering
  2222. // and operator list logic
  2223. if (intentState.displayReadyCapability) {
  2224. intentState.displayReadyCapability.resolve(transparency);
  2225. }
  2226. },
  2227. /**
  2228. * For internal use only.
  2229. * @ignore
  2230. */
  2231. _renderPageChunk: function PDFPageProxy_renderPageChunk(operatorListChunk,
  2232. intent) {
  2233. var intentState = this.intentStates[intent];
  2234. var i, ii;
  2235. // Add the new chunk to the current operator list.
  2236. for (i = 0, ii = operatorListChunk.length; i < ii; i++) {
  2237. intentState.operatorList.fnArray.push(operatorListChunk.fnArray[i]);
  2238. intentState.operatorList.argsArray.push(
  2239. operatorListChunk.argsArray[i]);
  2240. }
  2241. intentState.operatorList.lastChunk = operatorListChunk.lastChunk;
  2242. // Notify all the rendering tasks there are more operators to be consumed.
  2243. for (i = 0; i < intentState.renderTasks.length; i++) {
  2244. intentState.renderTasks[i].operatorListChanged();
  2245. }
  2246. if (operatorListChunk.lastChunk) {
  2247. intentState.receivingOperatorList = false;
  2248. this._tryDestroy();
  2249. }
  2250. }
  2251. };
  2252. return PDFPageProxy;
  2253. })();
  2254. /**
  2255. * For internal use only.
  2256. * @ignore
  2257. */
  2258. var WorkerTransport = (function WorkerTransportClosure() {
  2259. function WorkerTransport(workerInitializedCapability, pdfDataRangeTransport) {
  2260. this.pdfDataRangeTransport = pdfDataRangeTransport;
  2261. this.workerInitializedCapability = workerInitializedCapability;
  2262. this.commonObjs = new PDFObjects();
  2263. this.loadingTask = null;
  2264. this.pageCache = [];
  2265. this.pagePromises = [];
  2266. this.downloadInfoCapability = createPromiseCapability();
  2267. // If worker support isn't disabled explicit and the browser has worker
  2268. // support, create a new web worker and test if it/the browser fullfills
  2269. // all requirements to run parts of pdf.js in a web worker.
  2270. // Right now, the requirement is, that an Uint8Array is still an Uint8Array
  2271. // as it arrives on the worker. Chrome added this with version 15.
  2272. // Either workers are disabled, not supported or have thrown an exception.
  2273. // Thus, we fallback to a faked worker.
  2274. this.setupFakeWorker();
  2275. }
  2276. WorkerTransport.prototype = {
  2277. destroy: function WorkerTransport_destroy() {
  2278. this.pageCache = [];
  2279. this.pagePromises = [];
  2280. var self = this;
  2281. this.messageHandler.sendWithPromise('Terminate', null).then(function () {
  2282. FontLoader.clear();
  2283. if (self.worker) {
  2284. self.worker.terminate();
  2285. }
  2286. });
  2287. },
  2288. setupFakeWorker: function WorkerTransport_setupFakeWorker() {
  2289. globalScope.PDFJS.disableWorker = true;
  2290. if (!PDFJS.fakeWorkerFilesLoadedCapability) {
  2291. PDFJS.fakeWorkerFilesLoadedCapability = createPromiseCapability();
  2292. // In the developer build load worker_loader which in turn loads all the
  2293. // other files and resolves the promise. In production only the
  2294. // pdf.worker.js file is needed.
  2295. PDFJS.fakeWorkerFilesLoadedCapability.resolve();
  2296. }
  2297. PDFJS.fakeWorkerFilesLoadedCapability.promise.then(function () {
  2298. warn('Setting up fake worker.');
  2299. // If we don't use a worker, just post/sendMessage to the main thread.
  2300. var fakeWorker = {
  2301. postMessage: function WorkerTransport_postMessage(obj) {
  2302. fakeWorker.onmessage({data: obj});
  2303. },
  2304. terminate: function WorkerTransport_terminate() {}
  2305. };
  2306. var messageHandler = new MessageHandler('main', fakeWorker);
  2307. this.setupMessageHandler(messageHandler);
  2308. // If the main thread is our worker, setup the handling for the messages
  2309. // the main thread sends to it self.
  2310. PDFJS.WorkerMessageHandler.setup(messageHandler);
  2311. this.workerInitializedCapability.resolve();
  2312. }.bind(this));
  2313. },
  2314. setupMessageHandler:
  2315. function WorkerTransport_setupMessageHandler(messageHandler) {
  2316. this.messageHandler = messageHandler;
  2317. function updatePassword(password) {
  2318. messageHandler.send('UpdatePassword', password);
  2319. }
  2320. var pdfDataRangeTransport = this.pdfDataRangeTransport;
  2321. if (pdfDataRangeTransport) {
  2322. pdfDataRangeTransport.addRangeListener(function(begin, chunk) {
  2323. messageHandler.send('OnDataRange', {
  2324. begin: begin,
  2325. chunk: chunk
  2326. });
  2327. });
  2328. pdfDataRangeTransport.addProgressListener(function(loaded) {
  2329. messageHandler.send('OnDataProgress', {
  2330. loaded: loaded
  2331. });
  2332. });
  2333. pdfDataRangeTransport.addProgressiveReadListener(function(chunk) {
  2334. messageHandler.send('OnDataRange', {
  2335. chunk: chunk
  2336. });
  2337. });
  2338. messageHandler.on('RequestDataRange',
  2339. function transportDataRange(data) {
  2340. pdfDataRangeTransport.requestDataRange(data.begin, data.end);
  2341. }, this);
  2342. }
  2343. messageHandler.on('GetDoc', function transportDoc(data) {
  2344. var pdfInfo = data.pdfInfo;
  2345. this.numPages = data.pdfInfo.numPages;
  2346. var pdfDocument = new PDFDocumentProxy(pdfInfo, this);
  2347. this.pdfDocument = pdfDocument;
  2348. this.loadingTask._capability.resolve(pdfDocument);
  2349. }, this);
  2350. messageHandler.on('NeedPassword',
  2351. function transportNeedPassword(exception) {
  2352. var loadingTask = this.loadingTask;
  2353. if (loadingTask.onPassword) {
  2354. return loadingTask.onPassword(updatePassword,
  2355. PasswordResponses.NEED_PASSWORD);
  2356. }
  2357. loadingTask._capability.reject(
  2358. new PasswordException(exception.message, exception.code));
  2359. }, this);
  2360. messageHandler.on('IncorrectPassword',
  2361. function transportIncorrectPassword(exception) {
  2362. var loadingTask = this.loadingTask;
  2363. if (loadingTask.onPassword) {
  2364. return loadingTask.onPassword(updatePassword,
  2365. PasswordResponses.INCORRECT_PASSWORD);
  2366. }
  2367. loadingTask._capability.reject(
  2368. new PasswordException(exception.message, exception.code));
  2369. }, this);
  2370. messageHandler.on('InvalidPDF', function transportInvalidPDF(exception) {
  2371. this.loadingTask._capability.reject(
  2372. new InvalidPDFException(exception.message));
  2373. }, this);
  2374. messageHandler.on('MissingPDF', function transportMissingPDF(exception) {
  2375. this.loadingTask._capability.reject(
  2376. new MissingPDFException(exception.message));
  2377. }, this);
  2378. messageHandler.on('UnexpectedResponse',
  2379. function transportUnexpectedResponse(exception) {
  2380. this.loadingTask._capability.reject(
  2381. new UnexpectedResponseException(exception.message, exception.status));
  2382. }, this);
  2383. messageHandler.on('UnknownError',
  2384. function transportUnknownError(exception) {
  2385. this.loadingTask._capability.reject(
  2386. new UnknownErrorException(exception.message, exception.details));
  2387. }, this);
  2388. messageHandler.on('DataLoaded', function transportPage(data) {
  2389. this.downloadInfoCapability.resolve(data);
  2390. }, this);
  2391. messageHandler.on('PDFManagerReady', function transportPage(data) {
  2392. if (this.pdfDataRangeTransport) {
  2393. this.pdfDataRangeTransport.transportReady();
  2394. }
  2395. }, this);
  2396. messageHandler.on('StartRenderPage', function transportRender(data) {
  2397. var page = this.pageCache[data.pageIndex];
  2398. page.stats.timeEnd('Page Request');
  2399. page._startRenderPage(data.transparency, data.intent);
  2400. }, this);
  2401. messageHandler.on('RenderPageChunk', function transportRender(data) {
  2402. var page = this.pageCache[data.pageIndex];
  2403. page._renderPageChunk(data.operatorList, data.intent);
  2404. }, this);
  2405. messageHandler.on('commonobj', function transportObj(data) {
  2406. var id = data[0];
  2407. var type = data[1];
  2408. if (this.commonObjs.hasData(id)) {
  2409. return;
  2410. }
  2411. switch (type) {
  2412. case 'Font':
  2413. var exportedData = data[2];
  2414. var font;
  2415. if ('error' in exportedData) {
  2416. var error = exportedData.error;
  2417. warn('Error during font loading: ' + error);
  2418. this.commonObjs.resolve(id, error);
  2419. break;
  2420. } else {
  2421. font = new FontFaceObject(exportedData);
  2422. }
  2423. FontLoader.bind(
  2424. [font],
  2425. function fontReady(fontObjs) {
  2426. this.commonObjs.resolve(id, font);
  2427. }.bind(this)
  2428. );
  2429. break;
  2430. case 'FontPath':
  2431. this.commonObjs.resolve(id, data[2]);
  2432. break;
  2433. default:
  2434. error('Got unknown common object type ' + type);
  2435. }
  2436. }, this);
  2437. messageHandler.on('obj', function transportObj(data) {
  2438. var id = data[0];
  2439. var pageIndex = data[1];
  2440. var type = data[2];
  2441. var pageProxy = this.pageCache[pageIndex];
  2442. var imageData;
  2443. if (pageProxy.objs.hasData(id)) {
  2444. return;
  2445. }
  2446. switch (type) {
  2447. case 'JpegStream':
  2448. imageData = data[3];
  2449. loadJpegStream(id, imageData, pageProxy.objs);
  2450. break;
  2451. case 'Image':
  2452. imageData = data[3];
  2453. pageProxy.objs.resolve(id, imageData);
  2454. // heuristics that will allow not to store large data
  2455. var MAX_IMAGE_SIZE_TO_STORE = 8000000;
  2456. if (imageData && 'data' in imageData &&
  2457. imageData.data.length > MAX_IMAGE_SIZE_TO_STORE) {
  2458. pageProxy.cleanupAfterRender = true;
  2459. }
  2460. break;
  2461. default:
  2462. error('Got unknown object type ' + type);
  2463. }
  2464. }, this);
  2465. messageHandler.on('DocProgress', function transportDocProgress(data) {
  2466. var loadingTask = this.loadingTask;
  2467. if (loadingTask.onProgress) {
  2468. loadingTask.onProgress({
  2469. loaded: data.loaded,
  2470. total: data.total
  2471. });
  2472. }
  2473. }, this);
  2474. messageHandler.on('PageError', function transportError(data) {
  2475. var page = this.pageCache[data.pageNum - 1];
  2476. var intentState = page.intentStates[data.intent];
  2477. if (intentState.displayReadyCapability) {
  2478. intentState.displayReadyCapability.reject(data.error);
  2479. } else {
  2480. error(data.error);
  2481. }
  2482. }, this);
  2483. messageHandler.on('JpegDecode', function(data) {
  2484. var imageUrl = data[0];
  2485. var components = data[1];
  2486. if (components !== 3 && components !== 1) {
  2487. return Promise.reject(
  2488. new Error('Only 3 components or 1 component can be returned'));
  2489. }
  2490. return new Promise(function (resolve, reject) {
  2491. var img = new Image();
  2492. img.onload = function () {
  2493. var width = img.width;
  2494. var height = img.height;
  2495. var size = width * height;
  2496. var rgbaLength = size * 4;
  2497. var buf = new Uint8Array(size * components);
  2498. var tmpCanvas = createScratchCanvas(width, height);
  2499. var tmpCtx = tmpCanvas.getContext('2d');
  2500. tmpCtx.drawImage(img, 0, 0);
  2501. var data = tmpCtx.getImageData(0, 0, width, height).data;
  2502. var i, j;
  2503. if (components === 3) {
  2504. for (i = 0, j = 0; i < rgbaLength; i += 4, j += 3) {
  2505. buf[j] = data[i];
  2506. buf[j + 1] = data[i + 1];
  2507. buf[j + 2] = data[i + 2];
  2508. }
  2509. } else if (components === 1) {
  2510. for (i = 0, j = 0; i < rgbaLength; i += 4, j++) {
  2511. buf[j] = data[i];
  2512. }
  2513. }
  2514. resolve({ data: buf, width: width, height: height});
  2515. };
  2516. img.onerror = function () {
  2517. reject(new Error('JpegDecode failed to load image'));
  2518. };
  2519. img.src = imageUrl;
  2520. });
  2521. });
  2522. },
  2523. fetchDocument: function WorkerTransport_fetchDocument(loadingTask, source) {
  2524. this.loadingTask = loadingTask;
  2525. source.disableAutoFetch = PDFJS.disableAutoFetch;
  2526. source.disableStream = PDFJS.disableStream;
  2527. source.chunkedViewerLoading = !!this.pdfDataRangeTransport;
  2528. if (this.pdfDataRangeTransport) {
  2529. source.length = this.pdfDataRangeTransport.length;
  2530. source.initialData = this.pdfDataRangeTransport.initialData;
  2531. }
  2532. this.messageHandler.send('GetDocRequest', {
  2533. source: source,
  2534. disableRange: PDFJS.disableRange,
  2535. maxImageSize: PDFJS.maxImageSize,
  2536. cMapUrl: PDFJS.cMapUrl,
  2537. cMapPacked: PDFJS.cMapPacked,
  2538. disableFontFace: PDFJS.disableFontFace,
  2539. disableCreateObjectURL: PDFJS.disableCreateObjectURL,
  2540. verbosity: PDFJS.verbosity
  2541. });
  2542. },
  2543. getData: function WorkerTransport_getData() {
  2544. return this.messageHandler.sendWithPromise('GetData', null);
  2545. },
  2546. getPage: function WorkerTransport_getPage(pageNumber, capability) {
  2547. if (pageNumber <= 0 || pageNumber > this.numPages ||
  2548. (pageNumber|0) !== pageNumber) {
  2549. return Promise.reject(new Error('Invalid page request'));
  2550. }
  2551. var pageIndex = pageNumber - 1;
  2552. if (pageIndex in this.pagePromises) {
  2553. return this.pagePromises[pageIndex];
  2554. }
  2555. var promise = this.messageHandler.sendWithPromise('GetPage', {
  2556. pageIndex: pageIndex
  2557. }).then(function (pageInfo) {
  2558. var page = new PDFPageProxy(pageIndex, pageInfo, this);
  2559. this.pageCache[pageIndex] = page;
  2560. return page;
  2561. }.bind(this));
  2562. this.pagePromises[pageIndex] = promise;
  2563. return promise;
  2564. },
  2565. getPageIndex: function WorkerTransport_getPageIndexByRef(ref) {
  2566. return this.messageHandler.sendWithPromise('GetPageIndex', { ref: ref });
  2567. },
  2568. getAnnotations: function WorkerTransport_getAnnotations(pageIndex) {
  2569. return this.messageHandler.sendWithPromise('GetAnnotations',
  2570. { pageIndex: pageIndex });
  2571. },
  2572. getDestinations: function WorkerTransport_getDestinations() {
  2573. return this.messageHandler.sendWithPromise('GetDestinations', null);
  2574. },
  2575. getDestination: function WorkerTransport_getDestination(id) {
  2576. return this.messageHandler.sendWithPromise('GetDestination', { id: id } );
  2577. },
  2578. getAttachments: function WorkerTransport_getAttachments() {
  2579. return this.messageHandler.sendWithPromise('GetAttachments', null);
  2580. },
  2581. getJavaScript: function WorkerTransport_getJavaScript() {
  2582. return this.messageHandler.sendWithPromise('GetJavaScript', null);
  2583. },
  2584. getOutline: function WorkerTransport_getOutline() {
  2585. return this.messageHandler.sendWithPromise('GetOutline', null);
  2586. },
  2587. getMetadata: function WorkerTransport_getMetadata() {
  2588. return this.messageHandler.sendWithPromise('GetMetadata', null).
  2589. then(function transportMetadata(results) {
  2590. return {
  2591. info: results[0],
  2592. metadata: (results[1] ? new PDFJS.Metadata(results[1]) : null)
  2593. };
  2594. });
  2595. },
  2596. getStats: function WorkerTransport_getStats() {
  2597. return this.messageHandler.sendWithPromise('GetStats', null);
  2598. },
  2599. startCleanup: function WorkerTransport_startCleanup() {
  2600. this.messageHandler.sendWithPromise('Cleanup', null).
  2601. then(function endCleanup() {
  2602. for (var i = 0, ii = this.pageCache.length; i < ii; i++) {
  2603. var page = this.pageCache[i];
  2604. if (page) {
  2605. page.destroy();
  2606. }
  2607. }
  2608. this.commonObjs.clear();
  2609. FontLoader.clear();
  2610. }.bind(this));
  2611. }
  2612. };
  2613. return WorkerTransport;
  2614. })();
  2615. /**
  2616. * A PDF document and page is built of many objects. E.g. there are objects
  2617. * for fonts, images, rendering code and such. These objects might get processed
  2618. * inside of a worker. The `PDFObjects` implements some basic functions to
  2619. * manage these objects.
  2620. * @ignore
  2621. */
  2622. var PDFObjects = (function PDFObjectsClosure() {
  2623. function PDFObjects() {
  2624. this.objs = {};
  2625. }
  2626. PDFObjects.prototype = {
  2627. /**
  2628. * Internal function.
  2629. * Ensures there is an object defined for `objId`.
  2630. */
  2631. ensureObj: function PDFObjects_ensureObj(objId) {
  2632. if (this.objs[objId]) {
  2633. return this.objs[objId];
  2634. }
  2635. var obj = {
  2636. capability: createPromiseCapability(),
  2637. data: null,
  2638. resolved: false
  2639. };
  2640. this.objs[objId] = obj;
  2641. return obj;
  2642. },
  2643. /**
  2644. * If called *without* callback, this returns the data of `objId` but the
  2645. * object needs to be resolved. If it isn't, this function throws.
  2646. *
  2647. * If called *with* a callback, the callback is called with the data of the
  2648. * object once the object is resolved. That means, if you call this
  2649. * function and the object is already resolved, the callback gets called
  2650. * right away.
  2651. */
  2652. get: function PDFObjects_get(objId, callback) {
  2653. // If there is a callback, then the get can be async and the object is
  2654. // not required to be resolved right now
  2655. if (callback) {
  2656. this.ensureObj(objId).capability.promise.then(callback);
  2657. return null;
  2658. }
  2659. // If there isn't a callback, the user expects to get the resolved data
  2660. // directly.
  2661. var obj = this.objs[objId];
  2662. // If there isn't an object yet or the object isn't resolved, then the
  2663. // data isn't ready yet!
  2664. if (!obj || !obj.resolved) {
  2665. error('Requesting object that isn\'t resolved yet ' + objId);
  2666. }
  2667. return obj.data;
  2668. },
  2669. /**
  2670. * Resolves the object `objId` with optional `data`.
  2671. */
  2672. resolve: function PDFObjects_resolve(objId, data) {
  2673. var obj = this.ensureObj(objId);
  2674. obj.resolved = true;
  2675. obj.data = data;
  2676. obj.capability.resolve(data);
  2677. },
  2678. isResolved: function PDFObjects_isResolved(objId) {
  2679. var objs = this.objs;
  2680. if (!objs[objId]) {
  2681. return false;
  2682. } else {
  2683. return objs[objId].resolved;
  2684. }
  2685. },
  2686. hasData: function PDFObjects_hasData(objId) {
  2687. return this.isResolved(objId);
  2688. },
  2689. /**
  2690. * Returns the data of `objId` if object exists, null otherwise.
  2691. */
  2692. getData: function PDFObjects_getData(objId) {
  2693. var objs = this.objs;
  2694. if (!objs[objId] || !objs[objId].resolved) {
  2695. return null;
  2696. } else {
  2697. return objs[objId].data;
  2698. }
  2699. },
  2700. clear: function PDFObjects_clear() {
  2701. this.objs = {};
  2702. }
  2703. };
  2704. return PDFObjects;
  2705. })();
  2706. /**
  2707. * Allows controlling of the rendering tasks.
  2708. * @class
  2709. */
  2710. var RenderTask = (function RenderTaskClosure() {
  2711. function RenderTask(internalRenderTask) {
  2712. this._internalRenderTask = internalRenderTask;
  2713. /**
  2714. * Callback for incremental rendering -- a function that will be called
  2715. * each time the rendering is paused. To continue rendering call the
  2716. * function that is the first argument to the callback.
  2717. * @type {function}
  2718. */
  2719. this.onContinue = null;
  2720. }
  2721. RenderTask.prototype = /** @lends RenderTask.prototype */ {
  2722. /**
  2723. * Promise for rendering task completion.
  2724. * @return {Promise}
  2725. */
  2726. get promise() {
  2727. return this._internalRenderTask.capability.promise;
  2728. },
  2729. /**
  2730. * Cancels the rendering task. If the task is currently rendering it will
  2731. * not be cancelled until graphics pauses with a timeout. The promise that
  2732. * this object extends will resolved when cancelled.
  2733. */
  2734. cancel: function RenderTask_cancel() {
  2735. this._internalRenderTask.cancel();
  2736. },
  2737. /**
  2738. * Registers callbacks to indicate the rendering task completion.
  2739. *
  2740. * @param {function} onFulfilled The callback for the rendering completion.
  2741. * @param {function} onRejected The callback for the rendering failure.
  2742. * @return {Promise} A promise that is resolved after the onFulfilled or
  2743. * onRejected callback.
  2744. */
  2745. then: function RenderTask_then(onFulfilled, onRejected) {
  2746. return this.promise.then.apply(this.promise, arguments);
  2747. }
  2748. };
  2749. return RenderTask;
  2750. })();
  2751. /**
  2752. * For internal use only.
  2753. * @ignore
  2754. */
  2755. var InternalRenderTask = (function InternalRenderTaskClosure() {
  2756. function InternalRenderTask(callback, params, objs, commonObjs, operatorList,
  2757. pageNumber) {
  2758. this.callback = callback;
  2759. this.params = params;
  2760. this.objs = objs;
  2761. this.commonObjs = commonObjs;
  2762. this.operatorListIdx = null;
  2763. this.operatorList = operatorList;
  2764. this.pageNumber = pageNumber;
  2765. this.running = false;
  2766. this.graphicsReadyCallback = null;
  2767. this.graphicsReady = false;
  2768. this.useRequestAnimationFrame = false;
  2769. this.cancelled = false;
  2770. this.capability = createPromiseCapability();
  2771. this.task = new RenderTask(this);
  2772. // caching this-bound methods
  2773. this._continueBound = this._continue.bind(this);
  2774. this._scheduleNextBound = this._scheduleNext.bind(this);
  2775. this._nextBound = this._next.bind(this);
  2776. }
  2777. InternalRenderTask.prototype = {
  2778. initalizeGraphics:
  2779. function InternalRenderTask_initalizeGraphics(transparency) {
  2780. if (this.cancelled) {
  2781. return;
  2782. }
  2783. if (PDFJS.pdfBug && 'StepperManager' in globalScope &&
  2784. globalScope.StepperManager.enabled) {
  2785. this.stepper = globalScope.StepperManager.create(this.pageNumber - 1);
  2786. this.stepper.init(this.operatorList);
  2787. this.stepper.nextBreakPoint = this.stepper.getNextBreakPoint();
  2788. }
  2789. var params = this.params;
  2790. this.gfx = new CanvasGraphics(params.canvasContext, this.commonObjs,
  2791. this.objs, params.imageLayer);
  2792. this.gfx.beginDrawing(params.viewport, transparency);
  2793. this.operatorListIdx = 0;
  2794. this.graphicsReady = true;
  2795. if (this.graphicsReadyCallback) {
  2796. this.graphicsReadyCallback();
  2797. }
  2798. },
  2799. cancel: function InternalRenderTask_cancel() {
  2800. this.running = false;
  2801. this.cancelled = true;
  2802. this.callback('cancelled');
  2803. },
  2804. operatorListChanged: function InternalRenderTask_operatorListChanged() {
  2805. if (!this.graphicsReady) {
  2806. if (!this.graphicsReadyCallback) {
  2807. this.graphicsReadyCallback = this._continueBound;
  2808. }
  2809. return;
  2810. }
  2811. if (this.stepper) {
  2812. this.stepper.updateOperatorList(this.operatorList);
  2813. }
  2814. if (this.running) {
  2815. return;
  2816. }
  2817. this._continue();
  2818. },
  2819. _continue: function InternalRenderTask__continue() {
  2820. this.running = true;
  2821. if (this.cancelled) {
  2822. return;
  2823. }
  2824. if (this.task.onContinue) {
  2825. this.task.onContinue.call(this.task, this._scheduleNextBound);
  2826. } else {
  2827. this._scheduleNext();
  2828. }
  2829. },
  2830. _scheduleNext: function InternalRenderTask__scheduleNext() {
  2831. if (this.useRequestAnimationFrame) {
  2832. window.requestAnimationFrame(this._nextBound);
  2833. } else {
  2834. Promise.resolve(undefined).then(this._nextBound);
  2835. }
  2836. },
  2837. _next: function InternalRenderTask__next() {
  2838. if (this.cancelled) {
  2839. return;
  2840. }
  2841. this.operatorListIdx = this.gfx.executeOperatorList(this.operatorList,
  2842. this.operatorListIdx,
  2843. this._continueBound,
  2844. this.stepper);
  2845. if (this.operatorListIdx === this.operatorList.argsArray.length) {
  2846. this.running = false;
  2847. if (this.operatorList.lastChunk) {
  2848. this.gfx.endDrawing();
  2849. this.callback();
  2850. }
  2851. }
  2852. }
  2853. };
  2854. return InternalRenderTask;
  2855. })();
  2856. var Metadata = PDFJS.Metadata = (function MetadataClosure() {
  2857. function fixMetadata(meta) {
  2858. return meta.replace(/>\\376\\377([^<]+)/g, function(all, codes) {
  2859. var bytes = codes.replace(/\\([0-3])([0-7])([0-7])/g,
  2860. function(code, d1, d2, d3) {
  2861. return String.fromCharCode(d1 * 64 + d2 * 8 + d3 * 1);
  2862. });
  2863. var chars = '';
  2864. for (var i = 0; i < bytes.length; i += 2) {
  2865. var code = bytes.charCodeAt(i) * 256 + bytes.charCodeAt(i + 1);
  2866. chars += code >= 32 && code < 127 && code !== 60 && code !== 62 &&
  2867. code !== 38 && false ? String.fromCharCode(code) :
  2868. '&#x' + (0x10000 + code).toString(16).substring(1) + ';';
  2869. }
  2870. return '>' + chars;
  2871. });
  2872. }
  2873. function Metadata(meta) {
  2874. if (typeof meta === 'string') {
  2875. // Ghostscript produces invalid metadata
  2876. meta = fixMetadata(meta);
  2877. var parser = new DOMParser();
  2878. meta = parser.parseFromString(meta, 'application/xml');
  2879. } else if (!(meta instanceof Document)) {
  2880. error('Metadata: Invalid metadata object');
  2881. }
  2882. this.metaDocument = meta;
  2883. this.metadata = {};
  2884. this.parse();
  2885. }
  2886. Metadata.prototype = {
  2887. parse: function Metadata_parse() {
  2888. var doc = this.metaDocument;
  2889. var rdf = doc.documentElement;
  2890. if (rdf.nodeName.toLowerCase() !== 'rdf:rdf') { // Wrapped in <xmpmeta>
  2891. rdf = rdf.firstChild;
  2892. while (rdf && rdf.nodeName.toLowerCase() !== 'rdf:rdf') {
  2893. rdf = rdf.nextSibling;
  2894. }
  2895. }
  2896. var nodeName = (rdf) ? rdf.nodeName.toLowerCase() : null;
  2897. if (!rdf || nodeName !== 'rdf:rdf' || !rdf.hasChildNodes()) {
  2898. return;
  2899. }
  2900. var children = rdf.childNodes, desc, entry, name, i, ii, length, iLength;
  2901. for (i = 0, length = children.length; i < length; i++) {
  2902. desc = children[i];
  2903. if (desc.nodeName.toLowerCase() !== 'rdf:description') {
  2904. continue;
  2905. }
  2906. for (ii = 0, iLength = desc.childNodes.length; ii < iLength; ii++) {
  2907. if (desc.childNodes[ii].nodeName.toLowerCase() !== '#text') {
  2908. entry = desc.childNodes[ii];
  2909. name = entry.nodeName.toLowerCase();
  2910. this.metadata[name] = entry.textContent.trim();
  2911. }
  2912. }
  2913. }
  2914. },
  2915. get: function Metadata_get(name) {
  2916. return this.metadata[name] || null;
  2917. },
  2918. has: function Metadata_has(name) {
  2919. return typeof this.metadata[name] !== 'undefined';
  2920. }
  2921. };
  2922. return Metadata;
  2923. })();
  2924. // <canvas> contexts store most of the state we need natively.
  2925. // However, PDF needs a bit more state, which we store here.
  2926. // Minimal font size that would be used during canvas fillText operations.
  2927. var MIN_FONT_SIZE = 16;
  2928. // Maximum font size that would be used during canvas fillText operations.
  2929. var MAX_FONT_SIZE = 100;
  2930. var MAX_GROUP_SIZE = 4096;
  2931. // Heuristic value used when enforcing minimum line widths.
  2932. var MIN_WIDTH_FACTOR = 0.65;
  2933. var COMPILE_TYPE3_GLYPHS = true;
  2934. var MAX_SIZE_TO_COMPILE = 1000;
  2935. var FULL_CHUNK_HEIGHT = 16;
  2936. function createScratchCanvas(width, height) {
  2937. var canvas = document.createElement('canvas');
  2938. canvas.width = width;
  2939. canvas.height = height;
  2940. return canvas;
  2941. }
  2942. function addContextCurrentTransform(ctx) {
  2943. // If the context doesn't expose a `mozCurrentTransform`, add a JS based one.
  2944. if (!ctx.mozCurrentTransform) {
  2945. ctx._originalSave = ctx.save;
  2946. ctx._originalRestore = ctx.restore;
  2947. ctx._originalRotate = ctx.rotate;
  2948. ctx._originalScale = ctx.scale;
  2949. ctx._originalTranslate = ctx.translate;
  2950. ctx._originalTransform = ctx.transform;
  2951. ctx._originalSetTransform = ctx.setTransform;
  2952. ctx._transformMatrix = ctx._transformMatrix || [1, 0, 0, 1, 0, 0];
  2953. ctx._transformStack = [];
  2954. Object.defineProperty(ctx, 'mozCurrentTransform', {
  2955. get: function getCurrentTransform() {
  2956. return this._transformMatrix;
  2957. }
  2958. });
  2959. Object.defineProperty(ctx, 'mozCurrentTransformInverse', {
  2960. get: function getCurrentTransformInverse() {
  2961. // Calculation done using WolframAlpha:
  2962. // http://www.wolframalpha.com/input/?
  2963. // i=Inverse+{{a%2C+c%2C+e}%2C+{b%2C+d%2C+f}%2C+{0%2C+0%2C+1}}
  2964. var m = this._transformMatrix;
  2965. var a = m[0], b = m[1], c = m[2], d = m[3], e = m[4], f = m[5];
  2966. var ad_bc = a * d - b * c;
  2967. var bc_ad = b * c - a * d;
  2968. return [
  2969. d / ad_bc,
  2970. b / bc_ad,
  2971. c / bc_ad,
  2972. a / ad_bc,
  2973. (d * e - c * f) / bc_ad,
  2974. (b * e - a * f) / ad_bc
  2975. ];
  2976. }
  2977. });
  2978. ctx.save = function ctxSave() {
  2979. var old = this._transformMatrix;
  2980. this._transformStack.push(old);
  2981. this._transformMatrix = old.slice(0, 6);
  2982. this._originalSave();
  2983. };
  2984. ctx.restore = function ctxRestore() {
  2985. var prev = this._transformStack.pop();
  2986. if (prev) {
  2987. this._transformMatrix = prev;
  2988. this._originalRestore();
  2989. }
  2990. };
  2991. ctx.translate = function ctxTranslate(x, y) {
  2992. var m = this._transformMatrix;
  2993. m[4] = m[0] * x + m[2] * y + m[4];
  2994. m[5] = m[1] * x + m[3] * y + m[5];
  2995. this._originalTranslate(x, y);
  2996. };
  2997. ctx.scale = function ctxScale(x, y) {
  2998. var m = this._transformMatrix;
  2999. m[0] = m[0] * x;
  3000. m[1] = m[1] * x;
  3001. m[2] = m[2] * y;
  3002. m[3] = m[3] * y;
  3003. this._originalScale(x, y);
  3004. };
  3005. ctx.transform = function ctxTransform(a, b, c, d, e, f) {
  3006. var m = this._transformMatrix;
  3007. this._transformMatrix = [
  3008. m[0] * a + m[2] * b,
  3009. m[1] * a + m[3] * b,
  3010. m[0] * c + m[2] * d,
  3011. m[1] * c + m[3] * d,
  3012. m[0] * e + m[2] * f + m[4],
  3013. m[1] * e + m[3] * f + m[5]
  3014. ];
  3015. ctx._originalTransform(a, b, c, d, e, f);
  3016. };
  3017. ctx.setTransform = function ctxSetTransform(a, b, c, d, e, f) {
  3018. this._transformMatrix = [a, b, c, d, e, f];
  3019. ctx._originalSetTransform(a, b, c, d, e, f);
  3020. };
  3021. ctx.rotate = function ctxRotate(angle) {
  3022. var cosValue = Math.cos(angle);
  3023. var sinValue = Math.sin(angle);
  3024. var m = this._transformMatrix;
  3025. this._transformMatrix = [
  3026. m[0] * cosValue + m[2] * sinValue,
  3027. m[1] * cosValue + m[3] * sinValue,
  3028. m[0] * (-sinValue) + m[2] * cosValue,
  3029. m[1] * (-sinValue) + m[3] * cosValue,
  3030. m[4],
  3031. m[5]
  3032. ];
  3033. this._originalRotate(angle);
  3034. };
  3035. }
  3036. }
  3037. var CachedCanvases = (function CachedCanvasesClosure() {
  3038. var cache = {};
  3039. return {
  3040. getCanvas: function CachedCanvases_getCanvas(id, width, height,
  3041. trackTransform) {
  3042. var canvasEntry;
  3043. if (cache[id] !== undefined) {
  3044. canvasEntry = cache[id];
  3045. canvasEntry.canvas.width = width;
  3046. canvasEntry.canvas.height = height;
  3047. // reset canvas transform for emulated mozCurrentTransform, if needed
  3048. canvasEntry.context.setTransform(1, 0, 0, 1, 0, 0);
  3049. } else {
  3050. var canvas = createScratchCanvas(width, height);
  3051. var ctx = canvas.getContext('2d');
  3052. if (trackTransform) {
  3053. addContextCurrentTransform(ctx);
  3054. }
  3055. cache[id] = canvasEntry = {canvas: canvas, context: ctx};
  3056. }
  3057. return canvasEntry;
  3058. },
  3059. clear: function () {
  3060. for (var id in cache) {
  3061. var canvasEntry = cache[id];
  3062. // Zeroing the width and height causes Firefox to release graphics
  3063. // resources immediately, which can greatly reduce memory consumption.
  3064. canvasEntry.canvas.width = 0;
  3065. canvasEntry.canvas.height = 0;
  3066. delete cache[id];
  3067. }
  3068. }
  3069. };
  3070. })();
  3071. function compileType3Glyph(imgData) {
  3072. var POINT_TO_PROCESS_LIMIT = 1000;
  3073. var width = imgData.width, height = imgData.height;
  3074. var i, j, j0, width1 = width + 1;
  3075. var points = new Uint8Array(width1 * (height + 1));
  3076. var POINT_TYPES =
  3077. new Uint8Array([0, 2, 4, 0, 1, 0, 5, 4, 8, 10, 0, 8, 0, 2, 1, 0]);
  3078. // decodes bit-packed mask data
  3079. var lineSize = (width + 7) & ~7, data0 = imgData.data;
  3080. var data = new Uint8Array(lineSize * height), pos = 0, ii;
  3081. for (i = 0, ii = data0.length; i < ii; i++) {
  3082. var mask = 128, elem = data0[i];
  3083. while (mask > 0) {
  3084. data[pos++] = (elem & mask) ? 0 : 255;
  3085. mask >>= 1;
  3086. }
  3087. }
  3088. // finding iteresting points: every point is located between mask pixels,
  3089. // so there will be points of the (width + 1)x(height + 1) grid. Every point
  3090. // will have flags assigned based on neighboring mask pixels:
  3091. // 4 | 8
  3092. // --P--
  3093. // 2 | 1
  3094. // We are interested only in points with the flags:
  3095. // - outside corners: 1, 2, 4, 8;
  3096. // - inside corners: 7, 11, 13, 14;
  3097. // - and, intersections: 5, 10.
  3098. var count = 0;
  3099. pos = 0;
  3100. if (data[pos] !== 0) {
  3101. points[0] = 1;
  3102. ++count;
  3103. }
  3104. for (j = 1; j < width; j++) {
  3105. if (data[pos] !== data[pos + 1]) {
  3106. points[j] = data[pos] ? 2 : 1;
  3107. ++count;
  3108. }
  3109. pos++;
  3110. }
  3111. if (data[pos] !== 0) {
  3112. points[j] = 2;
  3113. ++count;
  3114. }
  3115. for (i = 1; i < height; i++) {
  3116. pos = i * lineSize;
  3117. j0 = i * width1;
  3118. if (data[pos - lineSize] !== data[pos]) {
  3119. points[j0] = data[pos] ? 1 : 8;
  3120. ++count;
  3121. }
  3122. // 'sum' is the position of the current pixel configuration in the 'TYPES'
  3123. // array (in order 8-1-2-4, so we can use '>>2' to shift the column).
  3124. var sum = (data[pos] ? 4 : 0) + (data[pos - lineSize] ? 8 : 0);
  3125. for (j = 1; j < width; j++) {
  3126. sum = (sum >> 2) + (data[pos + 1] ? 4 : 0) +
  3127. (data[pos - lineSize + 1] ? 8 : 0);
  3128. if (POINT_TYPES[sum]) {
  3129. points[j0 + j] = POINT_TYPES[sum];
  3130. ++count;
  3131. }
  3132. pos++;
  3133. }
  3134. if (data[pos - lineSize] !== data[pos]) {
  3135. points[j0 + j] = data[pos] ? 2 : 4;
  3136. ++count;
  3137. }
  3138. if (count > POINT_TO_PROCESS_LIMIT) {
  3139. return null;
  3140. }
  3141. }
  3142. pos = lineSize * (height - 1);
  3143. j0 = i * width1;
  3144. if (data[pos] !== 0) {
  3145. points[j0] = 8;
  3146. ++count;
  3147. }
  3148. for (j = 1; j < width; j++) {
  3149. if (data[pos] !== data[pos + 1]) {
  3150. points[j0 + j] = data[pos] ? 4 : 8;
  3151. ++count;
  3152. }
  3153. pos++;
  3154. }
  3155. if (data[pos] !== 0) {
  3156. points[j0 + j] = 4;
  3157. ++count;
  3158. }
  3159. if (count > POINT_TO_PROCESS_LIMIT) {
  3160. return null;
  3161. }
  3162. // building outlines
  3163. var steps = new Int32Array([0, width1, -1, 0, -width1, 0, 0, 0, 1]);
  3164. var outlines = [];
  3165. for (i = 0; count && i <= height; i++) {
  3166. var p = i * width1;
  3167. var end = p + width;
  3168. while (p < end && !points[p]) {
  3169. p++;
  3170. }
  3171. if (p === end) {
  3172. continue;
  3173. }
  3174. var coords = [p % width1, i];
  3175. var type = points[p], p0 = p, pp;
  3176. do {
  3177. var step = steps[type];
  3178. do {
  3179. p += step;
  3180. } while (!points[p]);
  3181. pp = points[p];
  3182. if (pp !== 5 && pp !== 10) {
  3183. // set new direction
  3184. type = pp;
  3185. // delete mark
  3186. points[p] = 0;
  3187. } else { // type is 5 or 10, ie, a crossing
  3188. // set new direction
  3189. type = pp & ((0x33 * type) >> 4);
  3190. // set new type for "future hit"
  3191. points[p] &= (type >> 2 | type << 2);
  3192. }
  3193. coords.push(p % width1);
  3194. coords.push((p / width1) | 0);
  3195. --count;
  3196. } while (p0 !== p);
  3197. outlines.push(coords);
  3198. --i;
  3199. }
  3200. var drawOutline = function(c) {
  3201. c.save();
  3202. // the path shall be painted in [0..1]x[0..1] space
  3203. c.scale(1 / width, -1 / height);
  3204. c.translate(0, -height);
  3205. c.beginPath();
  3206. for (var i = 0, ii = outlines.length; i < ii; i++) {
  3207. var o = outlines[i];
  3208. c.moveTo(o[0], o[1]);
  3209. for (var j = 2, jj = o.length; j < jj; j += 2) {
  3210. c.lineTo(o[j], o[j+1]);
  3211. }
  3212. }
  3213. c.fill();
  3214. c.beginPath();
  3215. c.restore();
  3216. };
  3217. return drawOutline;
  3218. }
  3219. var CanvasExtraState = (function CanvasExtraStateClosure() {
  3220. function CanvasExtraState(old) {
  3221. // Are soft masks and alpha values shapes or opacities?
  3222. this.alphaIsShape = false;
  3223. this.fontSize = 0;
  3224. this.fontSizeScale = 1;
  3225. this.textMatrix = IDENTITY_MATRIX;
  3226. this.textMatrixScale = 1;
  3227. this.fontMatrix = FONT_IDENTITY_MATRIX;
  3228. this.leading = 0;
  3229. // Current point (in user coordinates)
  3230. this.x = 0;
  3231. this.y = 0;
  3232. // Start of text line (in text coordinates)
  3233. this.lineX = 0;
  3234. this.lineY = 0;
  3235. // Character and word spacing
  3236. this.charSpacing = 0;
  3237. this.wordSpacing = 0;
  3238. this.textHScale = 1;
  3239. this.textRenderingMode = TextRenderingMode.FILL;
  3240. this.textRise = 0;
  3241. // Default fore and background colors
  3242. this.fillColor = '#000000';
  3243. this.strokeColor = '#000000';
  3244. this.patternFill = false;
  3245. // Note: fill alpha applies to all non-stroking operations
  3246. this.fillAlpha = 1;
  3247. this.strokeAlpha = 1;
  3248. this.lineWidth = 1;
  3249. this.activeSMask = null; // nonclonable field (see the save method below)
  3250. this.old = old;
  3251. }
  3252. CanvasExtraState.prototype = {
  3253. clone: function CanvasExtraState_clone() {
  3254. return Object.create(this);
  3255. },
  3256. setCurrentPoint: function CanvasExtraState_setCurrentPoint(x, y) {
  3257. this.x = x;
  3258. this.y = y;
  3259. }
  3260. };
  3261. return CanvasExtraState;
  3262. })();
  3263. var CanvasGraphics = (function CanvasGraphicsClosure() {
  3264. // Defines the time the executeOperatorList is going to be executing
  3265. // before it stops and shedules a continue of execution.
  3266. var EXECUTION_TIME = 15;
  3267. // Defines the number of steps before checking the execution time
  3268. var EXECUTION_STEPS = 10;
  3269. function CanvasGraphics(canvasCtx, commonObjs, objs, imageLayer) {
  3270. this.ctx = canvasCtx;
  3271. this.current = new CanvasExtraState();
  3272. this.stateStack = [];
  3273. this.pendingClip = null;
  3274. this.pendingEOFill = false;
  3275. this.res = null;
  3276. this.xobjs = null;
  3277. this.commonObjs = commonObjs;
  3278. this.objs = objs;
  3279. this.imageLayer = imageLayer;
  3280. this.groupStack = [];
  3281. this.processingType3 = null;
  3282. // Patterns are painted relative to the initial page/form transform, see pdf
  3283. // spec 8.7.2 NOTE 1.
  3284. this.baseTransform = null;
  3285. this.baseTransformStack = [];
  3286. this.groupLevel = 0;
  3287. this.smaskStack = [];
  3288. this.smaskCounter = 0;
  3289. this.tempSMask = null;
  3290. if (canvasCtx) {
  3291. // NOTE: if mozCurrentTransform is polyfilled, then the current state of
  3292. // the transformation must already be set in canvasCtx._transformMatrix.
  3293. addContextCurrentTransform(canvasCtx);
  3294. }
  3295. this.cachedGetSinglePixelWidth = null;
  3296. }
  3297. function putBinaryImageData(ctx, imgData) {
  3298. if (typeof ImageData !== 'undefined' && imgData instanceof ImageData) {
  3299. ctx.putImageData(imgData, 0, 0);
  3300. return;
  3301. }
  3302. // Put the image data to the canvas in chunks, rather than putting the
  3303. // whole image at once. This saves JS memory, because the ImageData object
  3304. // is smaller. It also possibly saves C++ memory within the implementation
  3305. // of putImageData(). (E.g. in Firefox we make two short-lived copies of
  3306. // the data passed to putImageData()). |n| shouldn't be too small, however,
  3307. // because too many putImageData() calls will slow things down.
  3308. //
  3309. // Note: as written, if the last chunk is partial, the putImageData() call
  3310. // will (conceptually) put pixels past the bounds of the canvas. But
  3311. // that's ok; any such pixels are ignored.
  3312. var height = imgData.height, width = imgData.width;
  3313. var partialChunkHeight = height % FULL_CHUNK_HEIGHT;
  3314. var fullChunks = (height - partialChunkHeight) / FULL_CHUNK_HEIGHT;
  3315. var totalChunks = partialChunkHeight === 0 ? fullChunks : fullChunks + 1;
  3316. var chunkImgData = ctx.createImageData(width, FULL_CHUNK_HEIGHT);
  3317. var srcPos = 0, destPos;
  3318. var src = imgData.data;
  3319. var dest = chunkImgData.data;
  3320. var i, j, thisChunkHeight, elemsInThisChunk;
  3321. // There are multiple forms in which the pixel data can be passed, and
  3322. // imgData.kind tells us which one this is.
  3323. if (imgData.kind === ImageKind.GRAYSCALE_1BPP) {
  3324. // Grayscale, 1 bit per pixel (i.e. black-and-white).
  3325. var srcLength = src.byteLength;
  3326. var dest32 = PDFJS.hasCanvasTypedArrays ? new Uint32Array(dest.buffer) :
  3327. new Uint32ArrayView(dest);
  3328. var dest32DataLength = dest32.length;
  3329. var fullSrcDiff = (width + 7) >> 3;
  3330. var white = 0xFFFFFFFF;
  3331. var black = (PDFJS.isLittleEndian || !PDFJS.hasCanvasTypedArrays) ?
  3332. 0xFF000000 : 0x000000FF;
  3333. for (i = 0; i < totalChunks; i++) {
  3334. thisChunkHeight =
  3335. (i < fullChunks) ? FULL_CHUNK_HEIGHT : partialChunkHeight;
  3336. destPos = 0;
  3337. for (j = 0; j < thisChunkHeight; j++) {
  3338. var srcDiff = srcLength - srcPos;
  3339. var k = 0;
  3340. var kEnd = (srcDiff > fullSrcDiff) ? width : srcDiff * 8 - 7;
  3341. var kEndUnrolled = kEnd & ~7;
  3342. var mask = 0;
  3343. var srcByte = 0;
  3344. for (; k < kEndUnrolled; k += 8) {
  3345. srcByte = src[srcPos++];
  3346. dest32[destPos++] = (srcByte & 128) ? white : black;
  3347. dest32[destPos++] = (srcByte & 64) ? white : black;
  3348. dest32[destPos++] = (srcByte & 32) ? white : black;
  3349. dest32[destPos++] = (srcByte & 16) ? white : black;
  3350. dest32[destPos++] = (srcByte & 8) ? white : black;
  3351. dest32[destPos++] = (srcByte & 4) ? white : black;
  3352. dest32[destPos++] = (srcByte & 2) ? white : black;
  3353. dest32[destPos++] = (srcByte & 1) ? white : black;
  3354. }
  3355. for (; k < kEnd; k++) {
  3356. if (mask === 0) {
  3357. srcByte = src[srcPos++];
  3358. mask = 128;
  3359. }
  3360. dest32[destPos++] = (srcByte & mask) ? white : black;
  3361. mask >>= 1;
  3362. }
  3363. }
  3364. // We ran out of input. Make all remaining pixels transparent.
  3365. while (destPos < dest32DataLength) {
  3366. dest32[destPos++] = 0;
  3367. }
  3368. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  3369. }
  3370. } else if (imgData.kind === ImageKind.RGBA_32BPP) {
  3371. // RGBA, 32-bits per pixel.
  3372. j = 0;
  3373. elemsInThisChunk = width * FULL_CHUNK_HEIGHT * 4;
  3374. for (i = 0; i < fullChunks; i++) {
  3375. dest.set(src.subarray(srcPos, srcPos + elemsInThisChunk));
  3376. srcPos += elemsInThisChunk;
  3377. ctx.putImageData(chunkImgData, 0, j);
  3378. j += FULL_CHUNK_HEIGHT;
  3379. }
  3380. if (i < totalChunks) {
  3381. elemsInThisChunk = width * partialChunkHeight * 4;
  3382. dest.set(src.subarray(srcPos, srcPos + elemsInThisChunk));
  3383. ctx.putImageData(chunkImgData, 0, j);
  3384. }
  3385. } else if (imgData.kind === ImageKind.RGB_24BPP) {
  3386. // RGB, 24-bits per pixel.
  3387. thisChunkHeight = FULL_CHUNK_HEIGHT;
  3388. elemsInThisChunk = width * thisChunkHeight;
  3389. for (i = 0; i < totalChunks; i++) {
  3390. if (i >= fullChunks) {
  3391. thisChunkHeight = partialChunkHeight;
  3392. elemsInThisChunk = width * thisChunkHeight;
  3393. }
  3394. destPos = 0;
  3395. for (j = elemsInThisChunk; j--;) {
  3396. dest[destPos++] = src[srcPos++];
  3397. dest[destPos++] = src[srcPos++];
  3398. dest[destPos++] = src[srcPos++];
  3399. dest[destPos++] = 255;
  3400. }
  3401. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  3402. }
  3403. } else {
  3404. error('bad image kind: ' + imgData.kind);
  3405. }
  3406. }
  3407. function putBinaryImageMask(ctx, imgData) {
  3408. var height = imgData.height, width = imgData.width;
  3409. var partialChunkHeight = height % FULL_CHUNK_HEIGHT;
  3410. var fullChunks = (height - partialChunkHeight) / FULL_CHUNK_HEIGHT;
  3411. var totalChunks = partialChunkHeight === 0 ? fullChunks : fullChunks + 1;
  3412. var chunkImgData = ctx.createImageData(width, FULL_CHUNK_HEIGHT);
  3413. var srcPos = 0;
  3414. var src = imgData.data;
  3415. var dest = chunkImgData.data;
  3416. for (var i = 0; i < totalChunks; i++) {
  3417. var thisChunkHeight =
  3418. (i < fullChunks) ? FULL_CHUNK_HEIGHT : partialChunkHeight;
  3419. // Expand the mask so it can be used by the canvas. Any required
  3420. // inversion has already been handled.
  3421. var destPos = 3; // alpha component offset
  3422. for (var j = 0; j < thisChunkHeight; j++) {
  3423. var mask = 0;
  3424. for (var k = 0; k < width; k++) {
  3425. if (!mask) {
  3426. var elem = src[srcPos++];
  3427. mask = 128;
  3428. }
  3429. dest[destPos] = (elem & mask) ? 0 : 255;
  3430. destPos += 4;
  3431. mask >>= 1;
  3432. }
  3433. }
  3434. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  3435. }
  3436. }
  3437. function copyCtxState(sourceCtx, destCtx) {
  3438. var properties = ['strokeStyle', 'fillStyle', 'fillRule', 'globalAlpha',
  3439. 'lineWidth', 'lineCap', 'lineJoin', 'miterLimit',
  3440. 'globalCompositeOperation', 'font'];
  3441. for (var i = 0, ii = properties.length; i < ii; i++) {
  3442. var property = properties[i];
  3443. if (sourceCtx[property] !== undefined) {
  3444. destCtx[property] = sourceCtx[property];
  3445. }
  3446. }
  3447. if (sourceCtx.setLineDash !== undefined) {
  3448. destCtx.setLineDash(sourceCtx.getLineDash());
  3449. destCtx.lineDashOffset = sourceCtx.lineDashOffset;
  3450. } else if (sourceCtx.mozDashOffset !== undefined) {
  3451. destCtx.mozDash = sourceCtx.mozDash;
  3452. destCtx.mozDashOffset = sourceCtx.mozDashOffset;
  3453. }
  3454. }
  3455. function composeSMaskBackdrop(bytes, r0, g0, b0) {
  3456. var length = bytes.length;
  3457. for (var i = 3; i < length; i += 4) {
  3458. var alpha = bytes[i];
  3459. if (alpha === 0) {
  3460. bytes[i - 3] = r0;
  3461. bytes[i - 2] = g0;
  3462. bytes[i - 1] = b0;
  3463. } else if (alpha < 255) {
  3464. var alpha_ = 255 - alpha;
  3465. bytes[i - 3] = (bytes[i - 3] * alpha + r0 * alpha_) >> 8;
  3466. bytes[i - 2] = (bytes[i - 2] * alpha + g0 * alpha_) >> 8;
  3467. bytes[i - 1] = (bytes[i - 1] * alpha + b0 * alpha_) >> 8;
  3468. }
  3469. }
  3470. }
  3471. function composeSMaskAlpha(maskData, layerData) {
  3472. var length = maskData.length;
  3473. var scale = 1 / 255;
  3474. for (var i = 3; i < length; i += 4) {
  3475. var alpha = maskData[i];
  3476. layerData[i] = (layerData[i] * alpha * scale) | 0;
  3477. }
  3478. }
  3479. function composeSMaskLuminosity(maskData, layerData) {
  3480. var length = maskData.length;
  3481. for (var i = 3; i < length; i += 4) {
  3482. var y = (maskData[i - 3] * 77) + // * 0.3 / 255 * 0x10000
  3483. (maskData[i - 2] * 152) + // * 0.59 ....
  3484. (maskData[i - 1] * 28); // * 0.11 ....
  3485. layerData[i] = (layerData[i] * y) >> 16;
  3486. }
  3487. }
  3488. function genericComposeSMask(maskCtx, layerCtx, width, height,
  3489. subtype, backdrop) {
  3490. var hasBackdrop = !!backdrop;
  3491. var r0 = hasBackdrop ? backdrop[0] : 0;
  3492. var g0 = hasBackdrop ? backdrop[1] : 0;
  3493. var b0 = hasBackdrop ? backdrop[2] : 0;
  3494. var composeFn;
  3495. if (subtype === 'Luminosity') {
  3496. composeFn = composeSMaskLuminosity;
  3497. } else {
  3498. composeFn = composeSMaskAlpha;
  3499. }
  3500. // processing image in chunks to save memory
  3501. var PIXELS_TO_PROCESS = 1048576;
  3502. var chunkSize = Math.min(height, Math.ceil(PIXELS_TO_PROCESS / width));
  3503. for (var row = 0; row < height; row += chunkSize) {
  3504. var chunkHeight = Math.min(chunkSize, height - row);
  3505. var maskData = maskCtx.getImageData(0, row, width, chunkHeight);
  3506. var layerData = layerCtx.getImageData(0, row, width, chunkHeight);
  3507. if (hasBackdrop) {
  3508. composeSMaskBackdrop(maskData.data, r0, g0, b0);
  3509. }
  3510. composeFn(maskData.data, layerData.data);
  3511. maskCtx.putImageData(layerData, 0, row);
  3512. }
  3513. }
  3514. function composeSMask(ctx, smask, layerCtx) {
  3515. var mask = smask.canvas;
  3516. var maskCtx = smask.context;
  3517. ctx.setTransform(smask.scaleX, 0, 0, smask.scaleY,
  3518. smask.offsetX, smask.offsetY);
  3519. var backdrop = smask.backdrop || null;
  3520. if (WebGLUtils.isEnabled) {
  3521. var composed = WebGLUtils.composeSMask(layerCtx.canvas, mask,
  3522. {subtype: smask.subtype, backdrop: backdrop});
  3523. ctx.setTransform(1, 0, 0, 1, 0, 0);
  3524. ctx.drawImage(composed, smask.offsetX, smask.offsetY);
  3525. return;
  3526. }
  3527. genericComposeSMask(maskCtx, layerCtx, mask.width, mask.height,
  3528. smask.subtype, backdrop);
  3529. ctx.drawImage(mask, 0, 0);
  3530. }
  3531. var LINE_CAP_STYLES = ['butt', 'round', 'square'];
  3532. var LINE_JOIN_STYLES = ['miter', 'round', 'bevel'];
  3533. var NORMAL_CLIP = {};
  3534. var EO_CLIP = {};
  3535. CanvasGraphics.prototype = {
  3536. beginDrawing: function CanvasGraphics_beginDrawing(viewport, transparency) {
  3537. // For pdfs that use blend modes we have to clear the canvas else certain
  3538. // blend modes can look wrong since we'd be blending with a white
  3539. // backdrop. The problem with a transparent backdrop though is we then
  3540. // don't get sub pixel anti aliasing on text, so we fill with white if
  3541. // we can.
  3542. var width = this.ctx.canvas.width;
  3543. var height = this.ctx.canvas.height;
  3544. if (transparency) {
  3545. this.ctx.clearRect(0, 0, width, height);
  3546. } else {
  3547. this.ctx.mozOpaque = true;
  3548. this.ctx.save();
  3549. this.ctx.fillStyle = 'rgb(255, 255, 255)';
  3550. this.ctx.fillRect(0, 0, width, height);
  3551. this.ctx.restore();
  3552. }
  3553. var transform = viewport.transform;
  3554. this.ctx.save();
  3555. this.ctx.transform.apply(this.ctx, transform);
  3556. this.baseTransform = this.ctx.mozCurrentTransform.slice();
  3557. if (this.imageLayer) {
  3558. this.imageLayer.beginLayout();
  3559. }
  3560. },
  3561. executeOperatorList: function CanvasGraphics_executeOperatorList(
  3562. operatorList,
  3563. executionStartIdx, continueCallback,
  3564. stepper) {
  3565. var argsArray = operatorList.argsArray;
  3566. var fnArray = operatorList.fnArray;
  3567. var i = executionStartIdx || 0;
  3568. var argsArrayLen = argsArray.length;
  3569. // Sometimes the OperatorList to execute is empty.
  3570. if (argsArrayLen === i) {
  3571. return i;
  3572. }
  3573. var chunkOperations = (argsArrayLen - i > EXECUTION_STEPS &&
  3574. typeof continueCallback === 'function');
  3575. var endTime = chunkOperations ? Date.now() + EXECUTION_TIME : 0;
  3576. var steps = 0;
  3577. var commonObjs = this.commonObjs;
  3578. var objs = this.objs;
  3579. var fnId;
  3580. while (true) {
  3581. if (stepper !== undefined && i === stepper.nextBreakPoint) {
  3582. stepper.breakIt(i, continueCallback);
  3583. return i;
  3584. }
  3585. fnId = fnArray[i];
  3586. if (fnId !== OPS.dependency) {
  3587. this[fnId].apply(this, argsArray[i]);
  3588. } else {
  3589. var deps = argsArray[i];
  3590. for (var n = 0, nn = deps.length; n < nn; n++) {
  3591. var depObjId = deps[n];
  3592. var common = depObjId[0] === 'g' && depObjId[1] === '_';
  3593. var objsPool = common ? commonObjs : objs;
  3594. // If the promise isn't resolved yet, add the continueCallback
  3595. // to the promise and bail out.
  3596. if (!objsPool.isResolved(depObjId)) {
  3597. objsPool.get(depObjId, continueCallback);
  3598. return i;
  3599. }
  3600. }
  3601. }
  3602. i++;
  3603. // If the entire operatorList was executed, stop as were done.
  3604. if (i === argsArrayLen) {
  3605. return i;
  3606. }
  3607. // If the execution took longer then a certain amount of time and
  3608. // `continueCallback` is specified, interrupt the execution.
  3609. if (chunkOperations && ++steps > EXECUTION_STEPS) {
  3610. if (Date.now() > endTime) {
  3611. continueCallback();
  3612. return i;
  3613. }
  3614. steps = 0;
  3615. }
  3616. // If the operatorList isn't executed completely yet OR the execution
  3617. // time was short enough, do another execution round.
  3618. }
  3619. },
  3620. endDrawing: function CanvasGraphics_endDrawing() {
  3621. this.ctx.restore();
  3622. CachedCanvases.clear();
  3623. WebGLUtils.clear();
  3624. if (this.imageLayer) {
  3625. this.imageLayer.endLayout();
  3626. }
  3627. },
  3628. // Graphics state
  3629. setLineWidth: function CanvasGraphics_setLineWidth(width) {
  3630. this.current.lineWidth = width;
  3631. this.ctx.lineWidth = width;
  3632. },
  3633. setLineCap: function CanvasGraphics_setLineCap(style) {
  3634. this.ctx.lineCap = LINE_CAP_STYLES[style];
  3635. },
  3636. setLineJoin: function CanvasGraphics_setLineJoin(style) {
  3637. this.ctx.lineJoin = LINE_JOIN_STYLES[style];
  3638. },
  3639. setMiterLimit: function CanvasGraphics_setMiterLimit(limit) {
  3640. this.ctx.miterLimit = limit;
  3641. },
  3642. setDash: function CanvasGraphics_setDash(dashArray, dashPhase) {
  3643. var ctx = this.ctx;
  3644. if (ctx.setLineDash !== undefined) {
  3645. ctx.setLineDash(dashArray);
  3646. ctx.lineDashOffset = dashPhase;
  3647. } else {
  3648. ctx.mozDash = dashArray;
  3649. ctx.mozDashOffset = dashPhase;
  3650. }
  3651. },
  3652. setRenderingIntent: function CanvasGraphics_setRenderingIntent(intent) {
  3653. // Maybe if we one day fully support color spaces this will be important
  3654. // for now we can ignore.
  3655. // TODO set rendering intent?
  3656. },
  3657. setFlatness: function CanvasGraphics_setFlatness(flatness) {
  3658. // There's no way to control this with canvas, but we can safely ignore.
  3659. // TODO set flatness?
  3660. },
  3661. setGState: function CanvasGraphics_setGState(states) {
  3662. for (var i = 0, ii = states.length; i < ii; i++) {
  3663. var state = states[i];
  3664. var key = state[0];
  3665. var value = state[1];
  3666. switch (key) {
  3667. case 'LW':
  3668. this.setLineWidth(value);
  3669. break;
  3670. case 'LC':
  3671. this.setLineCap(value);
  3672. break;
  3673. case 'LJ':
  3674. this.setLineJoin(value);
  3675. break;
  3676. case 'ML':
  3677. this.setMiterLimit(value);
  3678. break;
  3679. case 'D':
  3680. this.setDash(value[0], value[1]);
  3681. break;
  3682. case 'RI':
  3683. this.setRenderingIntent(value);
  3684. break;
  3685. case 'FL':
  3686. this.setFlatness(value);
  3687. break;
  3688. case 'Font':
  3689. this.setFont(value[0], value[1]);
  3690. break;
  3691. case 'CA':
  3692. this.current.strokeAlpha = state[1];
  3693. break;
  3694. case 'ca':
  3695. this.current.fillAlpha = state[1];
  3696. this.ctx.globalAlpha = state[1];
  3697. break;
  3698. case 'BM':
  3699. if (value && value.name && (value.name !== 'Normal')) {
  3700. var mode = value.name.replace(/([A-Z])/g,
  3701. function(c) {
  3702. return '-' + c.toLowerCase();
  3703. }
  3704. ).substring(1);
  3705. this.ctx.globalCompositeOperation = mode;
  3706. if (this.ctx.globalCompositeOperation !== mode) {
  3707. warn('globalCompositeOperation "' + mode +
  3708. '" is not supported');
  3709. }
  3710. } else {
  3711. this.ctx.globalCompositeOperation = 'source-over';
  3712. }
  3713. break;
  3714. case 'SMask':
  3715. if (this.current.activeSMask) {
  3716. this.endSMaskGroup();
  3717. }
  3718. this.current.activeSMask = value ? this.tempSMask : null;
  3719. if (this.current.activeSMask) {
  3720. this.beginSMaskGroup();
  3721. }
  3722. this.tempSMask = null;
  3723. break;
  3724. }
  3725. }
  3726. },
  3727. beginSMaskGroup: function CanvasGraphics_beginSMaskGroup() {
  3728. var activeSMask = this.current.activeSMask;
  3729. var drawnWidth = activeSMask.canvas.width;
  3730. var drawnHeight = activeSMask.canvas.height;
  3731. var cacheId = 'smaskGroupAt' + this.groupLevel;
  3732. var scratchCanvas = CachedCanvases.getCanvas(
  3733. cacheId, drawnWidth, drawnHeight, true);
  3734. var currentCtx = this.ctx;
  3735. var currentTransform = currentCtx.mozCurrentTransform;
  3736. this.ctx.save();
  3737. var groupCtx = scratchCanvas.context;
  3738. groupCtx.scale(1 / activeSMask.scaleX, 1 / activeSMask.scaleY);
  3739. groupCtx.translate(-activeSMask.offsetX, -activeSMask.offsetY);
  3740. groupCtx.transform.apply(groupCtx, currentTransform);
  3741. copyCtxState(currentCtx, groupCtx);
  3742. this.ctx = groupCtx;
  3743. this.setGState([
  3744. ['BM', 'Normal'],
  3745. ['ca', 1],
  3746. ['CA', 1]
  3747. ]);
  3748. this.groupStack.push(currentCtx);
  3749. this.groupLevel++;
  3750. },
  3751. endSMaskGroup: function CanvasGraphics_endSMaskGroup() {
  3752. var groupCtx = this.ctx;
  3753. this.groupLevel--;
  3754. this.ctx = this.groupStack.pop();
  3755. composeSMask(this.ctx, this.current.activeSMask, groupCtx);
  3756. this.ctx.restore();
  3757. },
  3758. save: function CanvasGraphics_save() {
  3759. this.ctx.save();
  3760. var old = this.current;
  3761. this.stateStack.push(old);
  3762. this.current = old.clone();
  3763. this.current.activeSMask = null;
  3764. },
  3765. restore: function CanvasGraphics_restore() {
  3766. if (this.stateStack.length !== 0) {
  3767. if (this.current.activeSMask !== null) {
  3768. this.endSMaskGroup();
  3769. }
  3770. this.current = this.stateStack.pop();
  3771. this.ctx.restore();
  3772. this.cachedGetSinglePixelWidth = null;
  3773. }
  3774. },
  3775. transform: function CanvasGraphics_transform(a, b, c, d, e, f) {
  3776. this.ctx.transform(a, b, c, d, e, f);
  3777. this.cachedGetSinglePixelWidth = null;
  3778. },
  3779. // Path
  3780. constructPath: function CanvasGraphics_constructPath(ops, args) {
  3781. var ctx = this.ctx;
  3782. var current = this.current;
  3783. var x = current.x, y = current.y;
  3784. for (var i = 0, j = 0, ii = ops.length; i < ii; i++) {
  3785. switch (ops[i] | 0) {
  3786. case OPS.rectangle:
  3787. x = args[j++];
  3788. y = args[j++];
  3789. var width = args[j++];
  3790. var height = args[j++];
  3791. if (width === 0) {
  3792. width = this.getSinglePixelWidth();
  3793. }
  3794. if (height === 0) {
  3795. height = this.getSinglePixelWidth();
  3796. }
  3797. var xw = x + width;
  3798. var yh = y + height;
  3799. this.ctx.moveTo(x, y);
  3800. this.ctx.lineTo(xw, y);
  3801. this.ctx.lineTo(xw, yh);
  3802. this.ctx.lineTo(x, yh);
  3803. this.ctx.lineTo(x, y);
  3804. this.ctx.closePath();
  3805. break;
  3806. case OPS.moveTo:
  3807. x = args[j++];
  3808. y = args[j++];
  3809. ctx.moveTo(x, y);
  3810. break;
  3811. case OPS.lineTo:
  3812. x = args[j++];
  3813. y = args[j++];
  3814. ctx.lineTo(x, y);
  3815. break;
  3816. case OPS.curveTo:
  3817. x = args[j + 4];
  3818. y = args[j + 5];
  3819. ctx.bezierCurveTo(args[j], args[j + 1], args[j + 2], args[j + 3],
  3820. x, y);
  3821. j += 6;
  3822. break;
  3823. case OPS.curveTo2:
  3824. ctx.bezierCurveTo(x, y, args[j], args[j + 1],
  3825. args[j + 2], args[j + 3]);
  3826. x = args[j + 2];
  3827. y = args[j + 3];
  3828. j += 4;
  3829. break;
  3830. case OPS.curveTo3:
  3831. x = args[j + 2];
  3832. y = args[j + 3];
  3833. ctx.bezierCurveTo(args[j], args[j + 1], x, y, x, y);
  3834. j += 4;
  3835. break;
  3836. case OPS.closePath:
  3837. ctx.closePath();
  3838. break;
  3839. }
  3840. }
  3841. current.setCurrentPoint(x, y);
  3842. },
  3843. closePath: function CanvasGraphics_closePath() {
  3844. this.ctx.closePath();
  3845. },
  3846. stroke: function CanvasGraphics_stroke(consumePath) {
  3847. consumePath = typeof consumePath !== 'undefined' ? consumePath : true;
  3848. var ctx = this.ctx;
  3849. var strokeColor = this.current.strokeColor;
  3850. // Prevent drawing too thin lines by enforcing a minimum line width.
  3851. ctx.lineWidth = Math.max(this.getSinglePixelWidth() * MIN_WIDTH_FACTOR,
  3852. this.current.lineWidth);
  3853. // For stroke we want to temporarily change the global alpha to the
  3854. // stroking alpha.
  3855. ctx.globalAlpha = this.current.strokeAlpha;
  3856. if (strokeColor && strokeColor.hasOwnProperty('type') &&
  3857. strokeColor.type === 'Pattern') {
  3858. // for patterns, we transform to pattern space, calculate
  3859. // the pattern, call stroke, and restore to user space
  3860. ctx.save();
  3861. ctx.strokeStyle = strokeColor.getPattern(ctx, this);
  3862. ctx.stroke();
  3863. ctx.restore();
  3864. } else {
  3865. ctx.stroke();
  3866. }
  3867. if (consumePath) {
  3868. this.consumePath();
  3869. }
  3870. // Restore the global alpha to the fill alpha
  3871. ctx.globalAlpha = this.current.fillAlpha;
  3872. },
  3873. closeStroke: function CanvasGraphics_closeStroke() {
  3874. this.closePath();
  3875. this.stroke();
  3876. },
  3877. fill: function CanvasGraphics_fill(consumePath) {
  3878. consumePath = typeof consumePath !== 'undefined' ? consumePath : true;
  3879. var ctx = this.ctx;
  3880. var fillColor = this.current.fillColor;
  3881. var isPatternFill = this.current.patternFill;
  3882. var needRestore = false;
  3883. if (isPatternFill) {
  3884. ctx.save();
  3885. ctx.fillStyle = fillColor.getPattern(ctx, this);
  3886. needRestore = true;
  3887. }
  3888. if (this.pendingEOFill) {
  3889. if (ctx.mozFillRule !== undefined) {
  3890. ctx.mozFillRule = 'evenodd';
  3891. ctx.fill();
  3892. ctx.mozFillRule = 'nonzero';
  3893. } else {
  3894. try {
  3895. ctx.fill('evenodd');
  3896. } catch (ex) {
  3897. // shouldn't really happen, but browsers might think differently
  3898. ctx.fill();
  3899. }
  3900. }
  3901. this.pendingEOFill = false;
  3902. } else {
  3903. ctx.fill();
  3904. }
  3905. if (needRestore) {
  3906. ctx.restore();
  3907. }
  3908. if (consumePath) {
  3909. this.consumePath();
  3910. }
  3911. },
  3912. eoFill: function CanvasGraphics_eoFill() {
  3913. this.pendingEOFill = true;
  3914. this.fill();
  3915. },
  3916. fillStroke: function CanvasGraphics_fillStroke() {
  3917. this.fill(false);
  3918. this.stroke(false);
  3919. this.consumePath();
  3920. },
  3921. eoFillStroke: function CanvasGraphics_eoFillStroke() {
  3922. this.pendingEOFill = true;
  3923. this.fillStroke();
  3924. },
  3925. closeFillStroke: function CanvasGraphics_closeFillStroke() {
  3926. this.closePath();
  3927. this.fillStroke();
  3928. },
  3929. closeEOFillStroke: function CanvasGraphics_closeEOFillStroke() {
  3930. this.pendingEOFill = true;
  3931. this.closePath();
  3932. this.fillStroke();
  3933. },
  3934. endPath: function CanvasGraphics_endPath() {
  3935. this.consumePath();
  3936. },
  3937. // Clipping
  3938. clip: function CanvasGraphics_clip() {
  3939. this.pendingClip = NORMAL_CLIP;
  3940. },
  3941. eoClip: function CanvasGraphics_eoClip() {
  3942. this.pendingClip = EO_CLIP;
  3943. },
  3944. // Text
  3945. beginText: function CanvasGraphics_beginText() {
  3946. this.current.textMatrix = IDENTITY_MATRIX;
  3947. this.current.textMatrixScale = 1;
  3948. this.current.x = this.current.lineX = 0;
  3949. this.current.y = this.current.lineY = 0;
  3950. },
  3951. endText: function CanvasGraphics_endText() {
  3952. var paths = this.pendingTextPaths;
  3953. var ctx = this.ctx;
  3954. if (paths === undefined) {
  3955. ctx.beginPath();
  3956. return;
  3957. }
  3958. ctx.save();
  3959. ctx.beginPath();
  3960. for (var i = 0; i < paths.length; i++) {
  3961. var path = paths[i];
  3962. ctx.setTransform.apply(ctx, path.transform);
  3963. ctx.translate(path.x, path.y);
  3964. path.addToPath(ctx, path.fontSize);
  3965. }
  3966. ctx.restore();
  3967. ctx.clip();
  3968. ctx.beginPath();
  3969. delete this.pendingTextPaths;
  3970. },
  3971. setCharSpacing: function CanvasGraphics_setCharSpacing(spacing) {
  3972. this.current.charSpacing = spacing;
  3973. },
  3974. setWordSpacing: function CanvasGraphics_setWordSpacing(spacing) {
  3975. this.current.wordSpacing = spacing;
  3976. },
  3977. setHScale: function CanvasGraphics_setHScale(scale) {
  3978. this.current.textHScale = scale / 100;
  3979. },
  3980. setLeading: function CanvasGraphics_setLeading(leading) {
  3981. this.current.leading = -leading;
  3982. },
  3983. setFont: function CanvasGraphics_setFont(fontRefName, size) {
  3984. var fontObj = this.commonObjs.get(fontRefName);
  3985. var current = this.current;
  3986. if (!fontObj) {
  3987. error('Can\'t find font for ' + fontRefName);
  3988. }
  3989. current.fontMatrix = (fontObj.fontMatrix ?
  3990. fontObj.fontMatrix : FONT_IDENTITY_MATRIX);
  3991. // A valid matrix needs all main diagonal elements to be non-zero
  3992. // This also ensures we bypass FF bugzilla bug #719844.
  3993. if (current.fontMatrix[0] === 0 ||
  3994. current.fontMatrix[3] === 0) {
  3995. warn('Invalid font matrix for font ' + fontRefName);
  3996. }
  3997. // The spec for Tf (setFont) says that 'size' specifies the font 'scale',
  3998. // and in some docs this can be negative (inverted x-y axes).
  3999. if (size < 0) {
  4000. size = -size;
  4001. current.fontDirection = -1;
  4002. } else {
  4003. current.fontDirection = 1;
  4004. }
  4005. this.current.font = fontObj;
  4006. this.current.fontSize = size;
  4007. if (fontObj.isType3Font) {
  4008. return; // we don't need ctx.font for Type3 fonts
  4009. }
  4010. var name = fontObj.loadedName || 'sans-serif';
  4011. var bold = fontObj.black ? (fontObj.bold ? 'bolder' : 'bold') :
  4012. (fontObj.bold ? 'bold' : 'normal');
  4013. var italic = fontObj.italic ? 'italic' : 'normal';
  4014. var typeface = '"' + name + '", ' + fontObj.fallbackName;
  4015. // Some font backends cannot handle fonts below certain size.
  4016. // Keeping the font at minimal size and using the fontSizeScale to change
  4017. // the current transformation matrix before the fillText/strokeText.
  4018. // See https://bugzilla.mozilla.org/show_bug.cgi?id=726227
  4019. var browserFontSize = size < MIN_FONT_SIZE ? MIN_FONT_SIZE :
  4020. size > MAX_FONT_SIZE ? MAX_FONT_SIZE : size;
  4021. this.current.fontSizeScale = size / browserFontSize;
  4022. var rule = italic + ' ' + bold + ' ' + browserFontSize + 'px ' + typeface;
  4023. this.ctx.font = rule;
  4024. },
  4025. setTextRenderingMode: function CanvasGraphics_setTextRenderingMode(mode) {
  4026. this.current.textRenderingMode = mode;
  4027. },
  4028. setTextRise: function CanvasGraphics_setTextRise(rise) {
  4029. this.current.textRise = rise;
  4030. },
  4031. moveText: function CanvasGraphics_moveText(x, y) {
  4032. this.current.x = this.current.lineX += x;
  4033. this.current.y = this.current.lineY += y;
  4034. },
  4035. setLeadingMoveText: function CanvasGraphics_setLeadingMoveText(x, y) {
  4036. this.setLeading(-y);
  4037. this.moveText(x, y);
  4038. },
  4039. setTextMatrix: function CanvasGraphics_setTextMatrix(a, b, c, d, e, f) {
  4040. this.current.textMatrix = [a, b, c, d, e, f];
  4041. this.current.textMatrixScale = Math.sqrt(a * a + b * b);
  4042. this.current.x = this.current.lineX = 0;
  4043. this.current.y = this.current.lineY = 0;
  4044. },
  4045. nextLine: function CanvasGraphics_nextLine() {
  4046. this.moveText(0, this.current.leading);
  4047. },
  4048. paintChar: function CanvasGraphics_paintChar(character, x, y) {
  4049. var ctx = this.ctx;
  4050. var current = this.current;
  4051. var font = current.font;
  4052. var textRenderingMode = current.textRenderingMode;
  4053. var fontSize = current.fontSize / current.fontSizeScale;
  4054. var fillStrokeMode = textRenderingMode &
  4055. TextRenderingMode.FILL_STROKE_MASK;
  4056. var isAddToPathSet = !!(textRenderingMode &
  4057. TextRenderingMode.ADD_TO_PATH_FLAG);
  4058. var addToPath;
  4059. if (font.disableFontFace || isAddToPathSet) {
  4060. addToPath = font.getPathGenerator(this.commonObjs, character);
  4061. }
  4062. if (font.disableFontFace) {
  4063. ctx.save();
  4064. ctx.translate(x, y);
  4065. ctx.beginPath();
  4066. addToPath(ctx, fontSize);
  4067. if (fillStrokeMode === TextRenderingMode.FILL ||
  4068. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  4069. ctx.fill();
  4070. }
  4071. if (fillStrokeMode === TextRenderingMode.STROKE ||
  4072. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  4073. ctx.stroke();
  4074. }
  4075. ctx.restore();
  4076. } else {
  4077. if (fillStrokeMode === TextRenderingMode.FILL ||
  4078. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  4079. ctx.fillText(character, x, y);
  4080. }
  4081. if (fillStrokeMode === TextRenderingMode.STROKE ||
  4082. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  4083. ctx.strokeText(character, x, y);
  4084. }
  4085. }
  4086. if (isAddToPathSet) {
  4087. var paths = this.pendingTextPaths || (this.pendingTextPaths = []);
  4088. paths.push({
  4089. transform: ctx.mozCurrentTransform,
  4090. x: x,
  4091. y: y,
  4092. fontSize: fontSize,
  4093. addToPath: addToPath
  4094. });
  4095. }
  4096. },
  4097. get isFontSubpixelAAEnabled() {
  4098. // Checks if anti-aliasing is enabled when scaled text is painted.
  4099. // On Windows GDI scaled fonts looks bad.
  4100. var ctx = document.createElement('canvas').getContext('2d');
  4101. ctx.scale(1.5, 1);
  4102. ctx.fillText('I', 0, 10);
  4103. var data = ctx.getImageData(0, 0, 10, 10).data;
  4104. var enabled = false;
  4105. for (var i = 3; i < data.length; i += 4) {
  4106. if (data[i] > 0 && data[i] < 255) {
  4107. enabled = true;
  4108. break;
  4109. }
  4110. }
  4111. return shadow(this, 'isFontSubpixelAAEnabled', enabled);
  4112. },
  4113. showText: function CanvasGraphics_showText(glyphs) {
  4114. var current = this.current;
  4115. var font = current.font;
  4116. if (font.isType3Font) {
  4117. return this.showType3Text(glyphs);
  4118. }
  4119. var fontSize = current.fontSize;
  4120. if (fontSize === 0) {
  4121. return;
  4122. }
  4123. var ctx = this.ctx;
  4124. var fontSizeScale = current.fontSizeScale;
  4125. var charSpacing = current.charSpacing;
  4126. var wordSpacing = current.wordSpacing;
  4127. var fontDirection = current.fontDirection;
  4128. var textHScale = current.textHScale * fontDirection;
  4129. var glyphsLength = glyphs.length;
  4130. var vertical = font.vertical;
  4131. var defaultVMetrics = font.defaultVMetrics;
  4132. var widthAdvanceScale = fontSize * current.fontMatrix[0];
  4133. var simpleFillText =
  4134. current.textRenderingMode === TextRenderingMode.FILL &&
  4135. !font.disableFontFace;
  4136. ctx.save();
  4137. ctx.transform.apply(ctx, current.textMatrix);
  4138. ctx.translate(current.x, current.y + current.textRise);
  4139. if (fontDirection > 0) {
  4140. ctx.scale(textHScale, -1);
  4141. } else {
  4142. ctx.scale(textHScale, 1);
  4143. }
  4144. var lineWidth = current.lineWidth;
  4145. var scale = current.textMatrixScale;
  4146. if (scale === 0 || lineWidth === 0) {
  4147. var fillStrokeMode = current.textRenderingMode &
  4148. TextRenderingMode.FILL_STROKE_MASK;
  4149. if (fillStrokeMode === TextRenderingMode.STROKE ||
  4150. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  4151. this.cachedGetSinglePixelWidth = null;
  4152. lineWidth = this.getSinglePixelWidth() * MIN_WIDTH_FACTOR;
  4153. }
  4154. } else {
  4155. lineWidth /= scale;
  4156. }
  4157. if (fontSizeScale !== 1.0) {
  4158. ctx.scale(fontSizeScale, fontSizeScale);
  4159. lineWidth /= fontSizeScale;
  4160. }
  4161. ctx.lineWidth = lineWidth;
  4162. var x = 0, i;
  4163. for (i = 0; i < glyphsLength; ++i) {
  4164. var glyph = glyphs[i];
  4165. if (glyph === null) {
  4166. // word break
  4167. x += fontDirection * wordSpacing;
  4168. continue;
  4169. } else if (isNum(glyph)) {
  4170. x += -glyph * fontSize * 0.001;
  4171. continue;
  4172. }
  4173. var restoreNeeded = false;
  4174. var character = glyph.fontChar;
  4175. var accent = glyph.accent;
  4176. var scaledX, scaledY, scaledAccentX, scaledAccentY;
  4177. var width = glyph.width;
  4178. if (vertical) {
  4179. var vmetric, vx, vy;
  4180. vmetric = glyph.vmetric || defaultVMetrics;
  4181. vx = glyph.vmetric ? vmetric[1] : width * 0.5;
  4182. vx = -vx * widthAdvanceScale;
  4183. vy = vmetric[2] * widthAdvanceScale;
  4184. width = vmetric ? -vmetric[0] : width;
  4185. scaledX = vx / fontSizeScale;
  4186. scaledY = (x + vy) / fontSizeScale;
  4187. } else {
  4188. scaledX = x / fontSizeScale;
  4189. scaledY = 0;
  4190. }
  4191. if (font.remeasure && width > 0 && this.isFontSubpixelAAEnabled) {
  4192. // some standard fonts may not have the exact width, trying to
  4193. // rescale per character
  4194. var measuredWidth = ctx.measureText(character).width * 1000 /
  4195. fontSize * fontSizeScale;
  4196. var characterScaleX = width / measuredWidth;
  4197. restoreNeeded = true;
  4198. ctx.save();
  4199. ctx.scale(characterScaleX, 1);
  4200. scaledX /= characterScaleX;
  4201. }
  4202. if (simpleFillText && !accent) {
  4203. // common case
  4204. ctx.fillText(character, scaledX, scaledY);
  4205. } else {
  4206. this.paintChar(character, scaledX, scaledY);
  4207. if (accent) {
  4208. scaledAccentX = scaledX + accent.offset.x / fontSizeScale;
  4209. scaledAccentY = scaledY - accent.offset.y / fontSizeScale;
  4210. this.paintChar(accent.fontChar, scaledAccentX, scaledAccentY);
  4211. }
  4212. }
  4213. var charWidth = width * widthAdvanceScale + charSpacing * fontDirection;
  4214. x += charWidth;
  4215. if (restoreNeeded) {
  4216. ctx.restore();
  4217. }
  4218. }
  4219. if (vertical) {
  4220. current.y -= x * textHScale;
  4221. } else {
  4222. current.x += x * textHScale;
  4223. }
  4224. ctx.restore();
  4225. },
  4226. showType3Text: function CanvasGraphics_showType3Text(glyphs) {
  4227. // Type3 fonts - each glyph is a "mini-PDF"
  4228. var ctx = this.ctx;
  4229. var current = this.current;
  4230. var font = current.font;
  4231. var fontSize = current.fontSize;
  4232. var fontDirection = current.fontDirection;
  4233. var charSpacing = current.charSpacing;
  4234. var wordSpacing = current.wordSpacing;
  4235. var textHScale = current.textHScale * fontDirection;
  4236. var fontMatrix = current.fontMatrix || FONT_IDENTITY_MATRIX;
  4237. var glyphsLength = glyphs.length;
  4238. var isTextInvisible =
  4239. current.textRenderingMode === TextRenderingMode.INVISIBLE;
  4240. var i, glyph, width;
  4241. if (isTextInvisible || fontSize === 0) {
  4242. return;
  4243. }
  4244. ctx.save();
  4245. ctx.transform.apply(ctx, current.textMatrix);
  4246. ctx.translate(current.x, current.y);
  4247. ctx.scale(textHScale, fontDirection);
  4248. for (i = 0; i < glyphsLength; ++i) {
  4249. glyph = glyphs[i];
  4250. if (glyph === null) {
  4251. // word break
  4252. this.ctx.translate(wordSpacing, 0);
  4253. current.x += wordSpacing * textHScale;
  4254. continue;
  4255. } else if (isNum(glyph)) {
  4256. var spacingLength = -glyph * 0.001 * fontSize;
  4257. this.ctx.translate(spacingLength, 0);
  4258. current.x += spacingLength * textHScale;
  4259. continue;
  4260. }
  4261. var operatorList = font.charProcOperatorList[glyph.operatorListId];
  4262. if (!operatorList) {
  4263. warn('Type3 character \"' + glyph.operatorListId +
  4264. '\" is not available');
  4265. continue;
  4266. }
  4267. this.processingType3 = glyph;
  4268. this.save();
  4269. ctx.scale(fontSize, fontSize);
  4270. ctx.transform.apply(ctx, fontMatrix);
  4271. this.executeOperatorList(operatorList);
  4272. this.restore();
  4273. var transformed = Util.applyTransform([glyph.width, 0], fontMatrix);
  4274. width = transformed[0] * fontSize + charSpacing;
  4275. ctx.translate(width, 0);
  4276. current.x += width * textHScale;
  4277. }
  4278. ctx.restore();
  4279. this.processingType3 = null;
  4280. },
  4281. // Type3 fonts
  4282. setCharWidth: function CanvasGraphics_setCharWidth(xWidth, yWidth) {
  4283. // We can safely ignore this since the width should be the same
  4284. // as the width in the Widths array.
  4285. },
  4286. setCharWidthAndBounds: function CanvasGraphics_setCharWidthAndBounds(xWidth,
  4287. yWidth,
  4288. llx,
  4289. lly,
  4290. urx,
  4291. ury) {
  4292. // TODO According to the spec we're also suppose to ignore any operators
  4293. // that set color or include images while processing this type3 font.
  4294. this.ctx.rect(llx, lly, urx - llx, ury - lly);
  4295. this.clip();
  4296. this.endPath();
  4297. },
  4298. // Color
  4299. getColorN_Pattern: function CanvasGraphics_getColorN_Pattern(IR) {
  4300. var pattern;
  4301. if (IR[0] === 'TilingPattern') {
  4302. var color = IR[1];
  4303. pattern = new TilingPattern(IR, color, this.ctx, this.objs,
  4304. this.commonObjs, this.baseTransform);
  4305. } else {
  4306. pattern = getShadingPatternFromIR(IR);
  4307. }
  4308. return pattern;
  4309. },
  4310. setStrokeColorN: function CanvasGraphics_setStrokeColorN(/*...*/) {
  4311. this.current.strokeColor = this.getColorN_Pattern(arguments);
  4312. },
  4313. setFillColorN: function CanvasGraphics_setFillColorN(/*...*/) {
  4314. this.current.fillColor = this.getColorN_Pattern(arguments);
  4315. this.current.patternFill = true;
  4316. },
  4317. setStrokeRGBColor: function CanvasGraphics_setStrokeRGBColor(r, g, b) {
  4318. var color = Util.makeCssRgb(r, g, b);
  4319. this.ctx.strokeStyle = color;
  4320. this.current.strokeColor = color;
  4321. },
  4322. setFillRGBColor: function CanvasGraphics_setFillRGBColor(r, g, b) {
  4323. var color = Util.makeCssRgb(r, g, b);
  4324. this.ctx.fillStyle = color;
  4325. this.current.fillColor = color;
  4326. this.current.patternFill = false;
  4327. },
  4328. shadingFill: function CanvasGraphics_shadingFill(patternIR) {
  4329. var ctx = this.ctx;
  4330. this.save();
  4331. var pattern = getShadingPatternFromIR(patternIR);
  4332. ctx.fillStyle = pattern.getPattern(ctx, this, true);
  4333. var inv = ctx.mozCurrentTransformInverse;
  4334. if (inv) {
  4335. var canvas = ctx.canvas;
  4336. var width = canvas.width;
  4337. var height = canvas.height;
  4338. var bl = Util.applyTransform([0, 0], inv);
  4339. var br = Util.applyTransform([0, height], inv);
  4340. var ul = Util.applyTransform([width, 0], inv);
  4341. var ur = Util.applyTransform([width, height], inv);
  4342. var x0 = Math.min(bl[0], br[0], ul[0], ur[0]);
  4343. var y0 = Math.min(bl[1], br[1], ul[1], ur[1]);
  4344. var x1 = Math.max(bl[0], br[0], ul[0], ur[0]);
  4345. var y1 = Math.max(bl[1], br[1], ul[1], ur[1]);
  4346. this.ctx.fillRect(x0, y0, x1 - x0, y1 - y0);
  4347. } else {
  4348. // HACK to draw the gradient onto an infinite rectangle.
  4349. // PDF gradients are drawn across the entire image while
  4350. // Canvas only allows gradients to be drawn in a rectangle
  4351. // The following bug should allow us to remove this.
  4352. // https://bugzilla.mozilla.org/show_bug.cgi?id=664884
  4353. this.ctx.fillRect(-1e10, -1e10, 2e10, 2e10);
  4354. }
  4355. this.restore();
  4356. },
  4357. // Images
  4358. beginInlineImage: function CanvasGraphics_beginInlineImage() {
  4359. error('Should not call beginInlineImage');
  4360. },
  4361. beginImageData: function CanvasGraphics_beginImageData() {
  4362. error('Should not call beginImageData');
  4363. },
  4364. paintFormXObjectBegin: function CanvasGraphics_paintFormXObjectBegin(matrix,
  4365. bbox) {
  4366. this.save();
  4367. this.baseTransformStack.push(this.baseTransform);
  4368. if (isArray(matrix) && 6 === matrix.length) {
  4369. this.transform.apply(this, matrix);
  4370. }
  4371. this.baseTransform = this.ctx.mozCurrentTransform;
  4372. if (isArray(bbox) && 4 === bbox.length) {
  4373. var width = bbox[2] - bbox[0];
  4374. var height = bbox[3] - bbox[1];
  4375. this.ctx.rect(bbox[0], bbox[1], width, height);
  4376. this.clip();
  4377. this.endPath();
  4378. }
  4379. },
  4380. paintFormXObjectEnd: function CanvasGraphics_paintFormXObjectEnd() {
  4381. this.restore();
  4382. this.baseTransform = this.baseTransformStack.pop();
  4383. },
  4384. beginGroup: function CanvasGraphics_beginGroup(group) {
  4385. this.save();
  4386. var currentCtx = this.ctx;
  4387. // TODO non-isolated groups - according to Rik at adobe non-isolated
  4388. // group results aren't usually that different and they even have tools
  4389. // that ignore this setting. Notes from Rik on implmenting:
  4390. // - When you encounter an transparency group, create a new canvas with
  4391. // the dimensions of the bbox
  4392. // - copy the content from the previous canvas to the new canvas
  4393. // - draw as usual
  4394. // - remove the backdrop alpha:
  4395. // alphaNew = 1 - (1 - alpha)/(1 - alphaBackdrop) with 'alpha' the alpha
  4396. // value of your transparency group and 'alphaBackdrop' the alpha of the
  4397. // backdrop
  4398. // - remove background color:
  4399. // colorNew = color - alphaNew *colorBackdrop /(1 - alphaNew)
  4400. if (!group.isolated) {
  4401. info('TODO: Support non-isolated groups.');
  4402. }
  4403. // TODO knockout - supposedly possible with the clever use of compositing
  4404. // modes.
  4405. if (group.knockout) {
  4406. warn('Knockout groups not supported.');
  4407. }
  4408. var currentTransform = currentCtx.mozCurrentTransform;
  4409. if (group.matrix) {
  4410. currentCtx.transform.apply(currentCtx, group.matrix);
  4411. }
  4412. assert(group.bbox, 'Bounding box is required.');
  4413. // Based on the current transform figure out how big the bounding box
  4414. // will actually be.
  4415. var bounds = Util.getAxialAlignedBoundingBox(
  4416. group.bbox,
  4417. currentCtx.mozCurrentTransform);
  4418. // Clip the bounding box to the current canvas.
  4419. var canvasBounds = [0,
  4420. 0,
  4421. currentCtx.canvas.width,
  4422. currentCtx.canvas.height];
  4423. bounds = Util.intersect(bounds, canvasBounds) || [0, 0, 0, 0];
  4424. // Use ceil in case we're between sizes so we don't create canvas that is
  4425. // too small and make the canvas at least 1x1 pixels.
  4426. var offsetX = Math.floor(bounds[0]);
  4427. var offsetY = Math.floor(bounds[1]);
  4428. var drawnWidth = Math.max(Math.ceil(bounds[2]) - offsetX, 1);
  4429. var drawnHeight = Math.max(Math.ceil(bounds[3]) - offsetY, 1);
  4430. var scaleX = 1, scaleY = 1;
  4431. if (drawnWidth > MAX_GROUP_SIZE) {
  4432. scaleX = drawnWidth / MAX_GROUP_SIZE;
  4433. drawnWidth = MAX_GROUP_SIZE;
  4434. }
  4435. if (drawnHeight > MAX_GROUP_SIZE) {
  4436. scaleY = drawnHeight / MAX_GROUP_SIZE;
  4437. drawnHeight = MAX_GROUP_SIZE;
  4438. }
  4439. var cacheId = 'groupAt' + this.groupLevel;
  4440. if (group.smask) {
  4441. // Using two cache entries is case if masks are used one after another.
  4442. cacheId += '_smask_' + ((this.smaskCounter++) % 2);
  4443. }
  4444. var scratchCanvas = CachedCanvases.getCanvas(
  4445. cacheId, drawnWidth, drawnHeight, true);
  4446. var groupCtx = scratchCanvas.context;
  4447. // Since we created a new canvas that is just the size of the bounding box
  4448. // we have to translate the group ctx.
  4449. groupCtx.scale(1 / scaleX, 1 / scaleY);
  4450. groupCtx.translate(-offsetX, -offsetY);
  4451. groupCtx.transform.apply(groupCtx, currentTransform);
  4452. if (group.smask) {
  4453. // Saving state and cached mask to be used in setGState.
  4454. this.smaskStack.push({
  4455. canvas: scratchCanvas.canvas,
  4456. context: groupCtx,
  4457. offsetX: offsetX,
  4458. offsetY: offsetY,
  4459. scaleX: scaleX,
  4460. scaleY: scaleY,
  4461. subtype: group.smask.subtype,
  4462. backdrop: group.smask.backdrop
  4463. });
  4464. } else {
  4465. // Setup the current ctx so when the group is popped we draw it at the
  4466. // right location.
  4467. currentCtx.setTransform(1, 0, 0, 1, 0, 0);
  4468. currentCtx.translate(offsetX, offsetY);
  4469. currentCtx.scale(scaleX, scaleY);
  4470. }
  4471. // The transparency group inherits all off the current graphics state
  4472. // except the blend mode, soft mask, and alpha constants.
  4473. copyCtxState(currentCtx, groupCtx);
  4474. this.ctx = groupCtx;
  4475. this.setGState([
  4476. ['BM', 'Normal'],
  4477. ['ca', 1],
  4478. ['CA', 1]
  4479. ]);
  4480. this.groupStack.push(currentCtx);
  4481. this.groupLevel++;
  4482. },
  4483. endGroup: function CanvasGraphics_endGroup(group) {
  4484. this.groupLevel--;
  4485. var groupCtx = this.ctx;
  4486. this.ctx = this.groupStack.pop();
  4487. // Turn off image smoothing to avoid sub pixel interpolation which can
  4488. // look kind of blurry for some pdfs.
  4489. if (this.ctx.imageSmoothingEnabled !== undefined) {
  4490. this.ctx.imageSmoothingEnabled = false;
  4491. } else {
  4492. this.ctx.mozImageSmoothingEnabled = false;
  4493. }
  4494. if (group.smask) {
  4495. this.tempSMask = this.smaskStack.pop();
  4496. } else {
  4497. this.ctx.drawImage(groupCtx.canvas, 0, 0);
  4498. }
  4499. this.restore();
  4500. },
  4501. beginAnnotations: function CanvasGraphics_beginAnnotations() {
  4502. this.save();
  4503. this.current = new CanvasExtraState();
  4504. },
  4505. endAnnotations: function CanvasGraphics_endAnnotations() {
  4506. this.restore();
  4507. },
  4508. beginAnnotation: function CanvasGraphics_beginAnnotation(rect, transform,
  4509. matrix) {
  4510. this.save();
  4511. if (isArray(rect) && 4 === rect.length) {
  4512. var width = rect[2] - rect[0];
  4513. var height = rect[3] - rect[1];
  4514. this.ctx.rect(rect[0], rect[1], width, height);
  4515. this.clip();
  4516. this.endPath();
  4517. }
  4518. this.transform.apply(this, transform);
  4519. this.transform.apply(this, matrix);
  4520. },
  4521. endAnnotation: function CanvasGraphics_endAnnotation() {
  4522. this.restore();
  4523. },
  4524. paintJpegXObject: function CanvasGraphics_paintJpegXObject(objId, w, h) {
  4525. var domImage = this.objs.get(objId);
  4526. if (!domImage) {
  4527. warn('Dependent image isn\'t ready yet');
  4528. return;
  4529. }
  4530. this.save();
  4531. var ctx = this.ctx;
  4532. // scale the image to the unit square
  4533. ctx.scale(1 / w, -1 / h);
  4534. ctx.drawImage(domImage, 0, 0, domImage.width, domImage.height,
  4535. 0, -h, w, h);
  4536. if (this.imageLayer) {
  4537. var currentTransform = ctx.mozCurrentTransformInverse;
  4538. var position = this.getCanvasPosition(0, 0);
  4539. this.imageLayer.appendImage({
  4540. objId: objId,
  4541. left: position[0],
  4542. top: position[1],
  4543. width: w / currentTransform[0],
  4544. height: h / currentTransform[3]
  4545. });
  4546. }
  4547. this.restore();
  4548. },
  4549. paintImageMaskXObject: function CanvasGraphics_paintImageMaskXObject(img) {
  4550. var ctx = this.ctx;
  4551. var width = img.width, height = img.height;
  4552. var fillColor = this.current.fillColor;
  4553. var isPatternFill = this.current.patternFill;
  4554. var glyph = this.processingType3;
  4555. if (COMPILE_TYPE3_GLYPHS && glyph && glyph.compiled === undefined) {
  4556. if (width <= MAX_SIZE_TO_COMPILE && height <= MAX_SIZE_TO_COMPILE) {
  4557. glyph.compiled =
  4558. compileType3Glyph({data: img.data, width: width, height: height});
  4559. } else {
  4560. glyph.compiled = null;
  4561. }
  4562. }
  4563. if (glyph && glyph.compiled) {
  4564. glyph.compiled(ctx);
  4565. return;
  4566. }
  4567. var maskCanvas = CachedCanvases.getCanvas('maskCanvas', width, height);
  4568. var maskCtx = maskCanvas.context;
  4569. maskCtx.save();
  4570. putBinaryImageMask(maskCtx, img);
  4571. maskCtx.globalCompositeOperation = 'source-in';
  4572. maskCtx.fillStyle = isPatternFill ?
  4573. fillColor.getPattern(maskCtx, this) : fillColor;
  4574. maskCtx.fillRect(0, 0, width, height);
  4575. maskCtx.restore();
  4576. this.paintInlineImageXObject(maskCanvas.canvas);
  4577. },
  4578. paintImageMaskXObjectRepeat:
  4579. function CanvasGraphics_paintImageMaskXObjectRepeat(imgData, scaleX,
  4580. scaleY, positions) {
  4581. var width = imgData.width;
  4582. var height = imgData.height;
  4583. var fillColor = this.current.fillColor;
  4584. var isPatternFill = this.current.patternFill;
  4585. var maskCanvas = CachedCanvases.getCanvas('maskCanvas', width, height);
  4586. var maskCtx = maskCanvas.context;
  4587. maskCtx.save();
  4588. putBinaryImageMask(maskCtx, imgData);
  4589. maskCtx.globalCompositeOperation = 'source-in';
  4590. maskCtx.fillStyle = isPatternFill ?
  4591. fillColor.getPattern(maskCtx, this) : fillColor;
  4592. maskCtx.fillRect(0, 0, width, height);
  4593. maskCtx.restore();
  4594. var ctx = this.ctx;
  4595. for (var i = 0, ii = positions.length; i < ii; i += 2) {
  4596. ctx.save();
  4597. ctx.transform(scaleX, 0, 0, scaleY, positions[i], positions[i + 1]);
  4598. ctx.scale(1, -1);
  4599. ctx.drawImage(maskCanvas.canvas, 0, 0, width, height,
  4600. 0, -1, 1, 1);
  4601. ctx.restore();
  4602. }
  4603. },
  4604. paintImageMaskXObjectGroup:
  4605. function CanvasGraphics_paintImageMaskXObjectGroup(images) {
  4606. var ctx = this.ctx;
  4607. var fillColor = this.current.fillColor;
  4608. var isPatternFill = this.current.patternFill;
  4609. for (var i = 0, ii = images.length; i < ii; i++) {
  4610. var image = images[i];
  4611. var width = image.width, height = image.height;
  4612. var maskCanvas = CachedCanvases.getCanvas('maskCanvas', width, height);
  4613. var maskCtx = maskCanvas.context;
  4614. maskCtx.save();
  4615. putBinaryImageMask(maskCtx, image);
  4616. maskCtx.globalCompositeOperation = 'source-in';
  4617. maskCtx.fillStyle = isPatternFill ?
  4618. fillColor.getPattern(maskCtx, this) : fillColor;
  4619. maskCtx.fillRect(0, 0, width, height);
  4620. maskCtx.restore();
  4621. ctx.save();
  4622. ctx.transform.apply(ctx, image.transform);
  4623. ctx.scale(1, -1);
  4624. ctx.drawImage(maskCanvas.canvas, 0, 0, width, height,
  4625. 0, -1, 1, 1);
  4626. ctx.restore();
  4627. }
  4628. },
  4629. paintImageXObject: function CanvasGraphics_paintImageXObject(objId) {
  4630. var imgData = this.objs.get(objId);
  4631. if (!imgData) {
  4632. warn('Dependent image isn\'t ready yet');
  4633. return;
  4634. }
  4635. this.paintInlineImageXObject(imgData);
  4636. },
  4637. paintImageXObjectRepeat:
  4638. function CanvasGraphics_paintImageXObjectRepeat(objId, scaleX, scaleY,
  4639. positions) {
  4640. var imgData = this.objs.get(objId);
  4641. if (!imgData) {
  4642. warn('Dependent image isn\'t ready yet');
  4643. return;
  4644. }
  4645. var width = imgData.width;
  4646. var height = imgData.height;
  4647. var map = [];
  4648. for (var i = 0, ii = positions.length; i < ii; i += 2) {
  4649. map.push({transform: [scaleX, 0, 0, scaleY, positions[i],
  4650. positions[i + 1]], x: 0, y: 0, w: width, h: height});
  4651. }
  4652. this.paintInlineImageXObjectGroup(imgData, map);
  4653. },
  4654. paintInlineImageXObject:
  4655. function CanvasGraphics_paintInlineImageXObject(imgData) {
  4656. var width = imgData.width;
  4657. var height = imgData.height;
  4658. var ctx = this.ctx;
  4659. this.save();
  4660. // scale the image to the unit square
  4661. ctx.scale(1 / width, -1 / height);
  4662. var currentTransform = ctx.mozCurrentTransformInverse;
  4663. var a = currentTransform[0], b = currentTransform[1];
  4664. var widthScale = Math.max(Math.sqrt(a * a + b * b), 1);
  4665. var c = currentTransform[2], d = currentTransform[3];
  4666. var heightScale = Math.max(Math.sqrt(c * c + d * d), 1);
  4667. var imgToPaint, tmpCanvas;
  4668. // instanceof HTMLElement does not work in jsdom node.js module
  4669. if (imgData instanceof HTMLElement || !imgData.data) {
  4670. imgToPaint = imgData;
  4671. } else {
  4672. tmpCanvas = CachedCanvases.getCanvas('inlineImage', width, height);
  4673. var tmpCtx = tmpCanvas.context;
  4674. putBinaryImageData(tmpCtx, imgData);
  4675. imgToPaint = tmpCanvas.canvas;
  4676. }
  4677. var paintWidth = width, paintHeight = height;
  4678. var tmpCanvasId = 'prescale1';
  4679. // Vertial or horizontal scaling shall not be more than 2 to not loose the
  4680. // pixels during drawImage operation, painting on the temporary canvas(es)
  4681. // that are twice smaller in size
  4682. while ((widthScale > 2 && paintWidth > 1) ||
  4683. (heightScale > 2 && paintHeight > 1)) {
  4684. var newWidth = paintWidth, newHeight = paintHeight;
  4685. if (widthScale > 2 && paintWidth > 1) {
  4686. newWidth = Math.ceil(paintWidth / 2);
  4687. widthScale /= paintWidth / newWidth;
  4688. }
  4689. if (heightScale > 2 && paintHeight > 1) {
  4690. newHeight = Math.ceil(paintHeight / 2);
  4691. heightScale /= paintHeight / newHeight;
  4692. }
  4693. tmpCanvas = CachedCanvases.getCanvas(tmpCanvasId, newWidth, newHeight);
  4694. tmpCtx = tmpCanvas.context;
  4695. tmpCtx.clearRect(0, 0, newWidth, newHeight);
  4696. tmpCtx.drawImage(imgToPaint, 0, 0, paintWidth, paintHeight,
  4697. 0, 0, newWidth, newHeight);
  4698. imgToPaint = tmpCanvas.canvas;
  4699. paintWidth = newWidth;
  4700. paintHeight = newHeight;
  4701. tmpCanvasId = tmpCanvasId === 'prescale1' ? 'prescale2' : 'prescale1';
  4702. }
  4703. ctx.drawImage(imgToPaint, 0, 0, paintWidth, paintHeight,
  4704. 0, -height, width, height);
  4705. if (this.imageLayer) {
  4706. var position = this.getCanvasPosition(0, -height);
  4707. this.imageLayer.appendImage({
  4708. imgData: imgData,
  4709. left: position[0],
  4710. top: position[1],
  4711. width: width / currentTransform[0],
  4712. height: height / currentTransform[3]
  4713. });
  4714. }
  4715. this.restore();
  4716. },
  4717. paintInlineImageXObjectGroup:
  4718. function CanvasGraphics_paintInlineImageXObjectGroup(imgData, map) {
  4719. var ctx = this.ctx;
  4720. var w = imgData.width;
  4721. var h = imgData.height;
  4722. var tmpCanvas = CachedCanvases.getCanvas('inlineImage', w, h);
  4723. var tmpCtx = tmpCanvas.context;
  4724. putBinaryImageData(tmpCtx, imgData);
  4725. for (var i = 0, ii = map.length; i < ii; i++) {
  4726. var entry = map[i];
  4727. ctx.save();
  4728. ctx.transform.apply(ctx, entry.transform);
  4729. ctx.scale(1, -1);
  4730. ctx.drawImage(tmpCanvas.canvas, entry.x, entry.y, entry.w, entry.h,
  4731. 0, -1, 1, 1);
  4732. if (this.imageLayer) {
  4733. var position = this.getCanvasPosition(entry.x, entry.y);
  4734. this.imageLayer.appendImage({
  4735. imgData: imgData,
  4736. left: position[0],
  4737. top: position[1],
  4738. width: w,
  4739. height: h
  4740. });
  4741. }
  4742. ctx.restore();
  4743. }
  4744. },
  4745. paintSolidColorImageMask:
  4746. function CanvasGraphics_paintSolidColorImageMask() {
  4747. this.ctx.fillRect(0, 0, 1, 1);
  4748. },
  4749. // Marked content
  4750. markPoint: function CanvasGraphics_markPoint(tag) {
  4751. // TODO Marked content.
  4752. },
  4753. markPointProps: function CanvasGraphics_markPointProps(tag, properties) {
  4754. // TODO Marked content.
  4755. },
  4756. beginMarkedContent: function CanvasGraphics_beginMarkedContent(tag) {
  4757. // TODO Marked content.
  4758. },
  4759. beginMarkedContentProps: function CanvasGraphics_beginMarkedContentProps(
  4760. tag, properties) {
  4761. // TODO Marked content.
  4762. },
  4763. endMarkedContent: function CanvasGraphics_endMarkedContent() {
  4764. // TODO Marked content.
  4765. },
  4766. // Compatibility
  4767. beginCompat: function CanvasGraphics_beginCompat() {
  4768. // TODO ignore undefined operators (should we do that anyway?)
  4769. },
  4770. endCompat: function CanvasGraphics_endCompat() {
  4771. // TODO stop ignoring undefined operators
  4772. },
  4773. // Helper functions
  4774. consumePath: function CanvasGraphics_consumePath() {
  4775. var ctx = this.ctx;
  4776. if (this.pendingClip) {
  4777. if (this.pendingClip === EO_CLIP) {
  4778. if (ctx.mozFillRule !== undefined) {
  4779. ctx.mozFillRule = 'evenodd';
  4780. ctx.clip();
  4781. ctx.mozFillRule = 'nonzero';
  4782. } else {
  4783. try {
  4784. ctx.clip('evenodd');
  4785. } catch (ex) {
  4786. // shouldn't really happen, but browsers might think differently
  4787. ctx.clip();
  4788. }
  4789. }
  4790. } else {
  4791. ctx.clip();
  4792. }
  4793. this.pendingClip = null;
  4794. }
  4795. ctx.beginPath();
  4796. },
  4797. getSinglePixelWidth: function CanvasGraphics_getSinglePixelWidth(scale) {
  4798. if (this.cachedGetSinglePixelWidth === null) {
  4799. var inverse = this.ctx.mozCurrentTransformInverse;
  4800. // max of the current horizontal and vertical scale
  4801. this.cachedGetSinglePixelWidth = Math.sqrt(Math.max(
  4802. (inverse[0] * inverse[0] + inverse[1] * inverse[1]),
  4803. (inverse[2] * inverse[2] + inverse[3] * inverse[3])));
  4804. }
  4805. return this.cachedGetSinglePixelWidth;
  4806. },
  4807. getCanvasPosition: function CanvasGraphics_getCanvasPosition(x, y) {
  4808. var transform = this.ctx.mozCurrentTransform;
  4809. return [
  4810. transform[0] * x + transform[2] * y + transform[4],
  4811. transform[1] * x + transform[3] * y + transform[5]
  4812. ];
  4813. }
  4814. };
  4815. for (var op in OPS) {
  4816. CanvasGraphics.prototype[OPS[op]] = CanvasGraphics.prototype[op];
  4817. }
  4818. return CanvasGraphics;
  4819. })();
  4820. var WebGLUtils = (function WebGLUtilsClosure() {
  4821. function loadShader(gl, code, shaderType) {
  4822. var shader = gl.createShader(shaderType);
  4823. gl.shaderSource(shader, code);
  4824. gl.compileShader(shader);
  4825. var compiled = gl.getShaderParameter(shader, gl.COMPILE_STATUS);
  4826. if (!compiled) {
  4827. var errorMsg = gl.getShaderInfoLog(shader);
  4828. throw new Error('Error during shader compilation: ' + errorMsg);
  4829. }
  4830. return shader;
  4831. }
  4832. function createVertexShader(gl, code) {
  4833. return loadShader(gl, code, gl.VERTEX_SHADER);
  4834. }
  4835. function createFragmentShader(gl, code) {
  4836. return loadShader(gl, code, gl.FRAGMENT_SHADER);
  4837. }
  4838. function createProgram(gl, shaders) {
  4839. var program = gl.createProgram();
  4840. for (var i = 0, ii = shaders.length; i < ii; ++i) {
  4841. gl.attachShader(program, shaders[i]);
  4842. }
  4843. gl.linkProgram(program);
  4844. var linked = gl.getProgramParameter(program, gl.LINK_STATUS);
  4845. if (!linked) {
  4846. var errorMsg = gl.getProgramInfoLog(program);
  4847. throw new Error('Error during program linking: ' + errorMsg);
  4848. }
  4849. return program;
  4850. }
  4851. function createTexture(gl, image, textureId) {
  4852. gl.activeTexture(textureId);
  4853. var texture = gl.createTexture();
  4854. gl.bindTexture(gl.TEXTURE_2D, texture);
  4855. // Set the parameters so we can render any size image.
  4856. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
  4857. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
  4858. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
  4859. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
  4860. // Upload the image into the texture.
  4861. gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image);
  4862. return texture;
  4863. }
  4864. var currentGL, currentCanvas;
  4865. function generateGL() {
  4866. if (currentGL) {
  4867. return;
  4868. }
  4869. currentCanvas = document.createElement('canvas');
  4870. currentGL = currentCanvas.getContext('webgl',
  4871. { premultipliedalpha: false });
  4872. }
  4873. var smaskVertexShaderCode = '\
  4874. attribute vec2 a_position; \
  4875. attribute vec2 a_texCoord; \
  4876. \
  4877. uniform vec2 u_resolution; \
  4878. \
  4879. varying vec2 v_texCoord; \
  4880. \
  4881. void main() { \
  4882. vec2 clipSpace = (a_position / u_resolution) * 2.0 - 1.0; \
  4883. gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1); \
  4884. \
  4885. v_texCoord = a_texCoord; \
  4886. } ';
  4887. var smaskFragmentShaderCode = '\
  4888. precision mediump float; \
  4889. \
  4890. uniform vec4 u_backdrop; \
  4891. uniform int u_subtype; \
  4892. uniform sampler2D u_image; \
  4893. uniform sampler2D u_mask; \
  4894. \
  4895. varying vec2 v_texCoord; \
  4896. \
  4897. void main() { \
  4898. vec4 imageColor = texture2D(u_image, v_texCoord); \
  4899. vec4 maskColor = texture2D(u_mask, v_texCoord); \
  4900. if (u_backdrop.a > 0.0) { \
  4901. maskColor.rgb = maskColor.rgb * maskColor.a + \
  4902. u_backdrop.rgb * (1.0 - maskColor.a); \
  4903. } \
  4904. float lum; \
  4905. if (u_subtype == 0) { \
  4906. lum = maskColor.a; \
  4907. } else { \
  4908. lum = maskColor.r * 0.3 + maskColor.g * 0.59 + \
  4909. maskColor.b * 0.11; \
  4910. } \
  4911. imageColor.a *= lum; \
  4912. imageColor.rgb *= imageColor.a; \
  4913. gl_FragColor = imageColor; \
  4914. } ';
  4915. var smaskCache = null;
  4916. function initSmaskGL() {
  4917. var canvas, gl;
  4918. generateGL();
  4919. canvas = currentCanvas;
  4920. currentCanvas = null;
  4921. gl = currentGL;
  4922. currentGL = null;
  4923. // setup a GLSL program
  4924. var vertexShader = createVertexShader(gl, smaskVertexShaderCode);
  4925. var fragmentShader = createFragmentShader(gl, smaskFragmentShaderCode);
  4926. var program = createProgram(gl, [vertexShader, fragmentShader]);
  4927. gl.useProgram(program);
  4928. var cache = {};
  4929. cache.gl = gl;
  4930. cache.canvas = canvas;
  4931. cache.resolutionLocation = gl.getUniformLocation(program, 'u_resolution');
  4932. cache.positionLocation = gl.getAttribLocation(program, 'a_position');
  4933. cache.backdropLocation = gl.getUniformLocation(program, 'u_backdrop');
  4934. cache.subtypeLocation = gl.getUniformLocation(program, 'u_subtype');
  4935. var texCoordLocation = gl.getAttribLocation(program, 'a_texCoord');
  4936. var texLayerLocation = gl.getUniformLocation(program, 'u_image');
  4937. var texMaskLocation = gl.getUniformLocation(program, 'u_mask');
  4938. // provide texture coordinates for the rectangle.
  4939. var texCoordBuffer = gl.createBuffer();
  4940. gl.bindBuffer(gl.ARRAY_BUFFER, texCoordBuffer);
  4941. gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
  4942. 0.0, 0.0,
  4943. 1.0, 0.0,
  4944. 0.0, 1.0,
  4945. 0.0, 1.0,
  4946. 1.0, 0.0,
  4947. 1.0, 1.0]), gl.STATIC_DRAW);
  4948. gl.enableVertexAttribArray(texCoordLocation);
  4949. gl.vertexAttribPointer(texCoordLocation, 2, gl.FLOAT, false, 0, 0);
  4950. gl.uniform1i(texLayerLocation, 0);
  4951. gl.uniform1i(texMaskLocation, 1);
  4952. smaskCache = cache;
  4953. }
  4954. function composeSMask(layer, mask, properties) {
  4955. var width = layer.width, height = layer.height;
  4956. if (!smaskCache) {
  4957. initSmaskGL();
  4958. }
  4959. var cache = smaskCache,canvas = cache.canvas, gl = cache.gl;
  4960. canvas.width = width;
  4961. canvas.height = height;
  4962. gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
  4963. gl.uniform2f(cache.resolutionLocation, width, height);
  4964. if (properties.backdrop) {
  4965. gl.uniform4f(cache.resolutionLocation, properties.backdrop[0],
  4966. properties.backdrop[1], properties.backdrop[2], 1);
  4967. } else {
  4968. gl.uniform4f(cache.resolutionLocation, 0, 0, 0, 0);
  4969. }
  4970. gl.uniform1i(cache.subtypeLocation,
  4971. properties.subtype === 'Luminosity' ? 1 : 0);
  4972. // Create a textures
  4973. var texture = createTexture(gl, layer, gl.TEXTURE0);
  4974. var maskTexture = createTexture(gl, mask, gl.TEXTURE1);
  4975. // Create a buffer and put a single clipspace rectangle in
  4976. // it (2 triangles)
  4977. var buffer = gl.createBuffer();
  4978. gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
  4979. gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
  4980. 0, 0,
  4981. width, 0,
  4982. 0, height,
  4983. 0, height,
  4984. width, 0,
  4985. width, height]), gl.STATIC_DRAW);
  4986. gl.enableVertexAttribArray(cache.positionLocation);
  4987. gl.vertexAttribPointer(cache.positionLocation, 2, gl.FLOAT, false, 0, 0);
  4988. // draw
  4989. gl.clearColor(0, 0, 0, 0);
  4990. gl.enable(gl.BLEND);
  4991. gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
  4992. gl.clear(gl.COLOR_BUFFER_BIT);
  4993. gl.drawArrays(gl.TRIANGLES, 0, 6);
  4994. gl.flush();
  4995. gl.deleteTexture(texture);
  4996. gl.deleteTexture(maskTexture);
  4997. gl.deleteBuffer(buffer);
  4998. return canvas;
  4999. }
  5000. var figuresVertexShaderCode = '\
  5001. attribute vec2 a_position; \
  5002. attribute vec3 a_color; \
  5003. \
  5004. uniform vec2 u_resolution; \
  5005. uniform vec2 u_scale; \
  5006. uniform vec2 u_offset; \
  5007. \
  5008. varying vec4 v_color; \
  5009. \
  5010. void main() { \
  5011. vec2 position = (a_position + u_offset) * u_scale; \
  5012. vec2 clipSpace = (position / u_resolution) * 2.0 - 1.0; \
  5013. gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1); \
  5014. \
  5015. v_color = vec4(a_color / 255.0, 1.0); \
  5016. } ';
  5017. var figuresFragmentShaderCode = '\
  5018. precision mediump float; \
  5019. \
  5020. varying vec4 v_color; \
  5021. \
  5022. void main() { \
  5023. gl_FragColor = v_color; \
  5024. } ';
  5025. var figuresCache = null;
  5026. function initFiguresGL() {
  5027. var canvas, gl;
  5028. generateGL();
  5029. canvas = currentCanvas;
  5030. currentCanvas = null;
  5031. gl = currentGL;
  5032. currentGL = null;
  5033. // setup a GLSL program
  5034. var vertexShader = createVertexShader(gl, figuresVertexShaderCode);
  5035. var fragmentShader = createFragmentShader(gl, figuresFragmentShaderCode);
  5036. var program = createProgram(gl, [vertexShader, fragmentShader]);
  5037. gl.useProgram(program);
  5038. var cache = {};
  5039. cache.gl = gl;
  5040. cache.canvas = canvas;
  5041. cache.resolutionLocation = gl.getUniformLocation(program, 'u_resolution');
  5042. cache.scaleLocation = gl.getUniformLocation(program, 'u_scale');
  5043. cache.offsetLocation = gl.getUniformLocation(program, 'u_offset');
  5044. cache.positionLocation = gl.getAttribLocation(program, 'a_position');
  5045. cache.colorLocation = gl.getAttribLocation(program, 'a_color');
  5046. figuresCache = cache;
  5047. }
  5048. function drawFigures(width, height, backgroundColor, figures, context) {
  5049. if (!figuresCache) {
  5050. initFiguresGL();
  5051. }
  5052. var cache = figuresCache, canvas = cache.canvas, gl = cache.gl;
  5053. canvas.width = width;
  5054. canvas.height = height;
  5055. gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
  5056. gl.uniform2f(cache.resolutionLocation, width, height);
  5057. // count triangle points
  5058. var count = 0;
  5059. var i, ii, rows;
  5060. for (i = 0, ii = figures.length; i < ii; i++) {
  5061. switch (figures[i].type) {
  5062. case 'lattice':
  5063. rows = (figures[i].coords.length / figures[i].verticesPerRow) | 0;
  5064. count += (rows - 1) * (figures[i].verticesPerRow - 1) * 6;
  5065. break;
  5066. case 'triangles':
  5067. count += figures[i].coords.length;
  5068. break;
  5069. }
  5070. }
  5071. // transfer data
  5072. var coords = new Float32Array(count * 2);
  5073. var colors = new Uint8Array(count * 3);
  5074. var coordsMap = context.coords, colorsMap = context.colors;
  5075. var pIndex = 0, cIndex = 0;
  5076. for (i = 0, ii = figures.length; i < ii; i++) {
  5077. var figure = figures[i], ps = figure.coords, cs = figure.colors;
  5078. switch (figure.type) {
  5079. case 'lattice':
  5080. var cols = figure.verticesPerRow;
  5081. rows = (ps.length / cols) | 0;
  5082. for (var row = 1; row < rows; row++) {
  5083. var offset = row * cols + 1;
  5084. for (var col = 1; col < cols; col++, offset++) {
  5085. coords[pIndex] = coordsMap[ps[offset - cols - 1]];
  5086. coords[pIndex + 1] = coordsMap[ps[offset - cols - 1] + 1];
  5087. coords[pIndex + 2] = coordsMap[ps[offset - cols]];
  5088. coords[pIndex + 3] = coordsMap[ps[offset - cols] + 1];
  5089. coords[pIndex + 4] = coordsMap[ps[offset - 1]];
  5090. coords[pIndex + 5] = coordsMap[ps[offset - 1] + 1];
  5091. colors[cIndex] = colorsMap[cs[offset - cols - 1]];
  5092. colors[cIndex + 1] = colorsMap[cs[offset - cols - 1] + 1];
  5093. colors[cIndex + 2] = colorsMap[cs[offset - cols - 1] + 2];
  5094. colors[cIndex + 3] = colorsMap[cs[offset - cols]];
  5095. colors[cIndex + 4] = colorsMap[cs[offset - cols] + 1];
  5096. colors[cIndex + 5] = colorsMap[cs[offset - cols] + 2];
  5097. colors[cIndex + 6] = colorsMap[cs[offset - 1]];
  5098. colors[cIndex + 7] = colorsMap[cs[offset - 1] + 1];
  5099. colors[cIndex + 8] = colorsMap[cs[offset - 1] + 2];
  5100. coords[pIndex + 6] = coords[pIndex + 2];
  5101. coords[pIndex + 7] = coords[pIndex + 3];
  5102. coords[pIndex + 8] = coords[pIndex + 4];
  5103. coords[pIndex + 9] = coords[pIndex + 5];
  5104. coords[pIndex + 10] = coordsMap[ps[offset]];
  5105. coords[pIndex + 11] = coordsMap[ps[offset] + 1];
  5106. colors[cIndex + 9] = colors[cIndex + 3];
  5107. colors[cIndex + 10] = colors[cIndex + 4];
  5108. colors[cIndex + 11] = colors[cIndex + 5];
  5109. colors[cIndex + 12] = colors[cIndex + 6];
  5110. colors[cIndex + 13] = colors[cIndex + 7];
  5111. colors[cIndex + 14] = colors[cIndex + 8];
  5112. colors[cIndex + 15] = colorsMap[cs[offset]];
  5113. colors[cIndex + 16] = colorsMap[cs[offset] + 1];
  5114. colors[cIndex + 17] = colorsMap[cs[offset] + 2];
  5115. pIndex += 12;
  5116. cIndex += 18;
  5117. }
  5118. }
  5119. break;
  5120. case 'triangles':
  5121. for (var j = 0, jj = ps.length; j < jj; j++) {
  5122. coords[pIndex] = coordsMap[ps[j]];
  5123. coords[pIndex + 1] = coordsMap[ps[j] + 1];
  5124. colors[cIndex] = colorsMap[cs[i]];
  5125. colors[cIndex + 1] = colorsMap[cs[j] + 1];
  5126. colors[cIndex + 2] = colorsMap[cs[j] + 2];
  5127. pIndex += 2;
  5128. cIndex += 3;
  5129. }
  5130. break;
  5131. }
  5132. }
  5133. // draw
  5134. if (backgroundColor) {
  5135. gl.clearColor(backgroundColor[0] / 255, backgroundColor[1] / 255,
  5136. backgroundColor[2] / 255, 1.0);
  5137. } else {
  5138. gl.clearColor(0, 0, 0, 0);
  5139. }
  5140. gl.clear(gl.COLOR_BUFFER_BIT);
  5141. var coordsBuffer = gl.createBuffer();
  5142. gl.bindBuffer(gl.ARRAY_BUFFER, coordsBuffer);
  5143. gl.bufferData(gl.ARRAY_BUFFER, coords, gl.STATIC_DRAW);
  5144. gl.enableVertexAttribArray(cache.positionLocation);
  5145. gl.vertexAttribPointer(cache.positionLocation, 2, gl.FLOAT, false, 0, 0);
  5146. var colorsBuffer = gl.createBuffer();
  5147. gl.bindBuffer(gl.ARRAY_BUFFER, colorsBuffer);
  5148. gl.bufferData(gl.ARRAY_BUFFER, colors, gl.STATIC_DRAW);
  5149. gl.enableVertexAttribArray(cache.colorLocation);
  5150. gl.vertexAttribPointer(cache.colorLocation, 3, gl.UNSIGNED_BYTE, false,
  5151. 0, 0);
  5152. gl.uniform2f(cache.scaleLocation, context.scaleX, context.scaleY);
  5153. gl.uniform2f(cache.offsetLocation, context.offsetX, context.offsetY);
  5154. gl.drawArrays(gl.TRIANGLES, 0, count);
  5155. gl.flush();
  5156. gl.deleteBuffer(coordsBuffer);
  5157. gl.deleteBuffer(colorsBuffer);
  5158. return canvas;
  5159. }
  5160. function cleanup() {
  5161. if (smaskCache && smaskCache.canvas) {
  5162. smaskCache.canvas.width = 0;
  5163. smaskCache.canvas.height = 0;
  5164. }
  5165. if (figuresCache && figuresCache.canvas) {
  5166. figuresCache.canvas.width = 0;
  5167. figuresCache.canvas.height = 0;
  5168. }
  5169. smaskCache = null;
  5170. figuresCache = null;
  5171. }
  5172. return {
  5173. get isEnabled() {
  5174. if (PDFJS.disableWebGL) {
  5175. return false;
  5176. }
  5177. var enabled = false;
  5178. try {
  5179. generateGL();
  5180. enabled = !!currentGL;
  5181. } catch (e) { }
  5182. return shadow(this, 'isEnabled', enabled);
  5183. },
  5184. composeSMask: composeSMask,
  5185. drawFigures: drawFigures,
  5186. clear: cleanup
  5187. };
  5188. })();
  5189. var ShadingIRs = {};
  5190. ShadingIRs.RadialAxial = {
  5191. fromIR: function RadialAxial_fromIR(raw) {
  5192. var type = raw[1];
  5193. var colorStops = raw[2];
  5194. var p0 = raw[3];
  5195. var p1 = raw[4];
  5196. var r0 = raw[5];
  5197. var r1 = raw[6];
  5198. return {
  5199. type: 'Pattern',
  5200. getPattern: function RadialAxial_getPattern(ctx) {
  5201. var grad;
  5202. if (type === 'axial') {
  5203. grad = ctx.createLinearGradient(p0[0], p0[1], p1[0], p1[1]);
  5204. } else if (type === 'radial') {
  5205. grad = ctx.createRadialGradient(p0[0], p0[1], r0, p1[0], p1[1], r1);
  5206. }
  5207. for (var i = 0, ii = colorStops.length; i < ii; ++i) {
  5208. var c = colorStops[i];
  5209. grad.addColorStop(c[0], c[1]);
  5210. }
  5211. return grad;
  5212. }
  5213. };
  5214. }
  5215. };
  5216. var createMeshCanvas = (function createMeshCanvasClosure() {
  5217. function drawTriangle(data, context, p1, p2, p3, c1, c2, c3) {
  5218. // Very basic Gouraud-shaded triangle rasterization algorithm.
  5219. var coords = context.coords, colors = context.colors;
  5220. var bytes = data.data, rowSize = data.width * 4;
  5221. var tmp;
  5222. if (coords[p1 + 1] > coords[p2 + 1]) {
  5223. tmp = p1; p1 = p2; p2 = tmp; tmp = c1; c1 = c2; c2 = tmp;
  5224. }
  5225. if (coords[p2 + 1] > coords[p3 + 1]) {
  5226. tmp = p2; p2 = p3; p3 = tmp; tmp = c2; c2 = c3; c3 = tmp;
  5227. }
  5228. if (coords[p1 + 1] > coords[p2 + 1]) {
  5229. tmp = p1; p1 = p2; p2 = tmp; tmp = c1; c1 = c2; c2 = tmp;
  5230. }
  5231. var x1 = (coords[p1] + context.offsetX) * context.scaleX;
  5232. var y1 = (coords[p1 + 1] + context.offsetY) * context.scaleY;
  5233. var x2 = (coords[p2] + context.offsetX) * context.scaleX;
  5234. var y2 = (coords[p2 + 1] + context.offsetY) * context.scaleY;
  5235. var x3 = (coords[p3] + context.offsetX) * context.scaleX;
  5236. var y3 = (coords[p3 + 1] + context.offsetY) * context.scaleY;
  5237. if (y1 >= y3) {
  5238. return;
  5239. }
  5240. var c1r = colors[c1], c1g = colors[c1 + 1], c1b = colors[c1 + 2];
  5241. var c2r = colors[c2], c2g = colors[c2 + 1], c2b = colors[c2 + 2];
  5242. var c3r = colors[c3], c3g = colors[c3 + 1], c3b = colors[c3 + 2];
  5243. var minY = Math.round(y1), maxY = Math.round(y3);
  5244. var xa, car, cag, cab;
  5245. var xb, cbr, cbg, cbb;
  5246. var k;
  5247. for (var y = minY; y <= maxY; y++) {
  5248. if (y < y2) {
  5249. k = y < y1 ? 0 : y1 === y2 ? 1 : (y1 - y) / (y1 - y2);
  5250. xa = x1 - (x1 - x2) * k;
  5251. car = c1r - (c1r - c2r) * k;
  5252. cag = c1g - (c1g - c2g) * k;
  5253. cab = c1b - (c1b - c2b) * k;
  5254. } else {
  5255. k = y > y3 ? 1 : y2 === y3 ? 0 : (y2 - y) / (y2 - y3);
  5256. xa = x2 - (x2 - x3) * k;
  5257. car = c2r - (c2r - c3r) * k;
  5258. cag = c2g - (c2g - c3g) * k;
  5259. cab = c2b - (c2b - c3b) * k;
  5260. }
  5261. k = y < y1 ? 0 : y > y3 ? 1 : (y1 - y) / (y1 - y3);
  5262. xb = x1 - (x1 - x3) * k;
  5263. cbr = c1r - (c1r - c3r) * k;
  5264. cbg = c1g - (c1g - c3g) * k;
  5265. cbb = c1b - (c1b - c3b) * k;
  5266. var x1_ = Math.round(Math.min(xa, xb));
  5267. var x2_ = Math.round(Math.max(xa, xb));
  5268. var j = rowSize * y + x1_ * 4;
  5269. for (var x = x1_; x <= x2_; x++) {
  5270. k = (xa - x) / (xa - xb);
  5271. k = k < 0 ? 0 : k > 1 ? 1 : k;
  5272. bytes[j++] = (car - (car - cbr) * k) | 0;
  5273. bytes[j++] = (cag - (cag - cbg) * k) | 0;
  5274. bytes[j++] = (cab - (cab - cbb) * k) | 0;
  5275. bytes[j++] = 255;
  5276. }
  5277. }
  5278. }
  5279. function drawFigure(data, figure, context) {
  5280. var ps = figure.coords;
  5281. var cs = figure.colors;
  5282. var i, ii;
  5283. switch (figure.type) {
  5284. case 'lattice':
  5285. var verticesPerRow = figure.verticesPerRow;
  5286. var rows = Math.floor(ps.length / verticesPerRow) - 1;
  5287. var cols = verticesPerRow - 1;
  5288. for (i = 0; i < rows; i++) {
  5289. var q = i * verticesPerRow;
  5290. for (var j = 0; j < cols; j++, q++) {
  5291. drawTriangle(data, context,
  5292. ps[q], ps[q + 1], ps[q + verticesPerRow],
  5293. cs[q], cs[q + 1], cs[q + verticesPerRow]);
  5294. drawTriangle(data, context,
  5295. ps[q + verticesPerRow + 1], ps[q + 1], ps[q + verticesPerRow],
  5296. cs[q + verticesPerRow + 1], cs[q + 1], cs[q + verticesPerRow]);
  5297. }
  5298. }
  5299. break;
  5300. case 'triangles':
  5301. for (i = 0, ii = ps.length; i < ii; i += 3) {
  5302. drawTriangle(data, context,
  5303. ps[i], ps[i + 1], ps[i + 2],
  5304. cs[i], cs[i + 1], cs[i + 2]);
  5305. }
  5306. break;
  5307. default:
  5308. error('illigal figure');
  5309. break;
  5310. }
  5311. }
  5312. function createMeshCanvas(bounds, combinesScale, coords, colors, figures,
  5313. backgroundColor) {
  5314. // we will increase scale on some weird factor to let antialiasing take
  5315. // care of "rough" edges
  5316. var EXPECTED_SCALE = 1.1;
  5317. // MAX_PATTERN_SIZE is used to avoid OOM situation.
  5318. var MAX_PATTERN_SIZE = 3000; // 10in @ 300dpi shall be enough
  5319. var offsetX = Math.floor(bounds[0]);
  5320. var offsetY = Math.floor(bounds[1]);
  5321. var boundsWidth = Math.ceil(bounds[2]) - offsetX;
  5322. var boundsHeight = Math.ceil(bounds[3]) - offsetY;
  5323. var width = Math.min(Math.ceil(Math.abs(boundsWidth * combinesScale[0] *
  5324. EXPECTED_SCALE)), MAX_PATTERN_SIZE);
  5325. var height = Math.min(Math.ceil(Math.abs(boundsHeight * combinesScale[1] *
  5326. EXPECTED_SCALE)), MAX_PATTERN_SIZE);
  5327. var scaleX = boundsWidth / width;
  5328. var scaleY = boundsHeight / height;
  5329. var context = {
  5330. coords: coords,
  5331. colors: colors,
  5332. offsetX: -offsetX,
  5333. offsetY: -offsetY,
  5334. scaleX: 1 / scaleX,
  5335. scaleY: 1 / scaleY
  5336. };
  5337. var canvas, tmpCanvas, i, ii;
  5338. if (WebGLUtils.isEnabled) {
  5339. canvas = WebGLUtils.drawFigures(width, height, backgroundColor,
  5340. figures, context);
  5341. // https://bugzilla.mozilla.org/show_bug.cgi?id=972126
  5342. tmpCanvas = CachedCanvases.getCanvas('mesh', width, height, false);
  5343. tmpCanvas.context.drawImage(canvas, 0, 0);
  5344. canvas = tmpCanvas.canvas;
  5345. } else {
  5346. tmpCanvas = CachedCanvases.getCanvas('mesh', width, height, false);
  5347. var tmpCtx = tmpCanvas.context;
  5348. var data = tmpCtx.createImageData(width, height);
  5349. if (backgroundColor) {
  5350. var bytes = data.data;
  5351. for (i = 0, ii = bytes.length; i < ii; i += 4) {
  5352. bytes[i] = backgroundColor[0];
  5353. bytes[i + 1] = backgroundColor[1];
  5354. bytes[i + 2] = backgroundColor[2];
  5355. bytes[i + 3] = 255;
  5356. }
  5357. }
  5358. for (i = 0; i < figures.length; i++) {
  5359. drawFigure(data, figures[i], context);
  5360. }
  5361. tmpCtx.putImageData(data, 0, 0);
  5362. canvas = tmpCanvas.canvas;
  5363. }
  5364. return {canvas: canvas, offsetX: offsetX, offsetY: offsetY,
  5365. scaleX: scaleX, scaleY: scaleY};
  5366. }
  5367. return createMeshCanvas;
  5368. })();
  5369. ShadingIRs.Mesh = {
  5370. fromIR: function Mesh_fromIR(raw) {
  5371. //var type = raw[1];
  5372. var coords = raw[2];
  5373. var colors = raw[3];
  5374. var figures = raw[4];
  5375. var bounds = raw[5];
  5376. var matrix = raw[6];
  5377. //var bbox = raw[7];
  5378. var background = raw[8];
  5379. return {
  5380. type: 'Pattern',
  5381. getPattern: function Mesh_getPattern(ctx, owner, shadingFill) {
  5382. var scale;
  5383. if (shadingFill) {
  5384. scale = Util.singularValueDecompose2dScale(ctx.mozCurrentTransform);
  5385. } else {
  5386. // Obtain scale from matrix and current transformation matrix.
  5387. scale = Util.singularValueDecompose2dScale(owner.baseTransform);
  5388. if (matrix) {
  5389. var matrixScale = Util.singularValueDecompose2dScale(matrix);
  5390. scale = [scale[0] * matrixScale[0],
  5391. scale[1] * matrixScale[1]];
  5392. }
  5393. }
  5394. // Rasterizing on the main thread since sending/queue large canvases
  5395. // might cause OOM.
  5396. var temporaryPatternCanvas = createMeshCanvas(bounds, scale, coords,
  5397. colors, figures, shadingFill ? null : background);
  5398. if (!shadingFill) {
  5399. ctx.setTransform.apply(ctx, owner.baseTransform);
  5400. if (matrix) {
  5401. ctx.transform.apply(ctx, matrix);
  5402. }
  5403. }
  5404. ctx.translate(temporaryPatternCanvas.offsetX,
  5405. temporaryPatternCanvas.offsetY);
  5406. ctx.scale(temporaryPatternCanvas.scaleX,
  5407. temporaryPatternCanvas.scaleY);
  5408. return ctx.createPattern(temporaryPatternCanvas.canvas, 'no-repeat');
  5409. }
  5410. };
  5411. }
  5412. };
  5413. ShadingIRs.Dummy = {
  5414. fromIR: function Dummy_fromIR() {
  5415. return {
  5416. type: 'Pattern',
  5417. getPattern: function Dummy_fromIR_getPattern() {
  5418. return 'hotpink';
  5419. }
  5420. };
  5421. }
  5422. };
  5423. function getShadingPatternFromIR(raw) {
  5424. var shadingIR = ShadingIRs[raw[0]];
  5425. if (!shadingIR) {
  5426. error('Unknown IR type: ' + raw[0]);
  5427. }
  5428. return shadingIR.fromIR(raw);
  5429. }
  5430. var TilingPattern = (function TilingPatternClosure() {
  5431. var PaintType = {
  5432. COLORED: 1,
  5433. UNCOLORED: 2
  5434. };
  5435. var MAX_PATTERN_SIZE = 3000; // 10in @ 300dpi shall be enough
  5436. function TilingPattern(IR, color, ctx, objs, commonObjs, baseTransform) {
  5437. this.operatorList = IR[2];
  5438. this.matrix = IR[3] || [1, 0, 0, 1, 0, 0];
  5439. this.bbox = IR[4];
  5440. this.xstep = IR[5];
  5441. this.ystep = IR[6];
  5442. this.paintType = IR[7];
  5443. this.tilingType = IR[8];
  5444. this.color = color;
  5445. this.objs = objs;
  5446. this.commonObjs = commonObjs;
  5447. this.baseTransform = baseTransform;
  5448. this.type = 'Pattern';
  5449. this.ctx = ctx;
  5450. }
  5451. TilingPattern.prototype = {
  5452. createPatternCanvas: function TilinPattern_createPatternCanvas(owner) {
  5453. var operatorList = this.operatorList;
  5454. var bbox = this.bbox;
  5455. var xstep = this.xstep;
  5456. var ystep = this.ystep;
  5457. var paintType = this.paintType;
  5458. var tilingType = this.tilingType;
  5459. var color = this.color;
  5460. var objs = this.objs;
  5461. var commonObjs = this.commonObjs;
  5462. info('TilingType: ' + tilingType);
  5463. var x0 = bbox[0], y0 = bbox[1], x1 = bbox[2], y1 = bbox[3];
  5464. var topLeft = [x0, y0];
  5465. // we want the canvas to be as large as the step size
  5466. var botRight = [x0 + xstep, y0 + ystep];
  5467. var width = botRight[0] - topLeft[0];
  5468. var height = botRight[1] - topLeft[1];
  5469. // Obtain scale from matrix and current transformation matrix.
  5470. var matrixScale = Util.singularValueDecompose2dScale(this.matrix);
  5471. var curMatrixScale = Util.singularValueDecompose2dScale(
  5472. this.baseTransform);
  5473. var combinedScale = [matrixScale[0] * curMatrixScale[0],
  5474. matrixScale[1] * curMatrixScale[1]];
  5475. // MAX_PATTERN_SIZE is used to avoid OOM situation.
  5476. // Use width and height values that are as close as possible to the end
  5477. // result when the pattern is used. Too low value makes the pattern look
  5478. // blurry. Too large value makes it look too crispy.
  5479. width = Math.min(Math.ceil(Math.abs(width * combinedScale[0])),
  5480. MAX_PATTERN_SIZE);
  5481. height = Math.min(Math.ceil(Math.abs(height * combinedScale[1])),
  5482. MAX_PATTERN_SIZE);
  5483. var tmpCanvas = CachedCanvases.getCanvas('pattern', width, height, true);
  5484. var tmpCtx = tmpCanvas.context;
  5485. var graphics = new CanvasGraphics(tmpCtx, commonObjs, objs);
  5486. graphics.groupLevel = owner.groupLevel;
  5487. this.setFillAndStrokeStyleToContext(tmpCtx, paintType, color);
  5488. this.setScale(width, height, xstep, ystep);
  5489. this.transformToScale(graphics);
  5490. // transform coordinates to pattern space
  5491. var tmpTranslate = [1, 0, 0, 1, -topLeft[0], -topLeft[1]];
  5492. graphics.transform.apply(graphics, tmpTranslate);
  5493. this.clipBbox(graphics, bbox, x0, y0, x1, y1);
  5494. graphics.executeOperatorList(operatorList);
  5495. return tmpCanvas.canvas;
  5496. },
  5497. setScale: function TilingPattern_setScale(width, height, xstep, ystep) {
  5498. this.scale = [width / xstep, height / ystep];
  5499. },
  5500. transformToScale: function TilingPattern_transformToScale(graphics) {
  5501. var scale = this.scale;
  5502. var tmpScale = [scale[0], 0, 0, scale[1], 0, 0];
  5503. graphics.transform.apply(graphics, tmpScale);
  5504. },
  5505. scaleToContext: function TilingPattern_scaleToContext() {
  5506. var scale = this.scale;
  5507. this.ctx.scale(1 / scale[0], 1 / scale[1]);
  5508. },
  5509. clipBbox: function clipBbox(graphics, bbox, x0, y0, x1, y1) {
  5510. if (bbox && isArray(bbox) && bbox.length === 4) {
  5511. var bboxWidth = x1 - x0;
  5512. var bboxHeight = y1 - y0;
  5513. graphics.ctx.rect(x0, y0, bboxWidth, bboxHeight);
  5514. graphics.clip();
  5515. graphics.endPath();
  5516. }
  5517. },
  5518. setFillAndStrokeStyleToContext:
  5519. function setFillAndStrokeStyleToContext(context, paintType, color) {
  5520. switch (paintType) {
  5521. case PaintType.COLORED:
  5522. var ctx = this.ctx;
  5523. context.fillStyle = ctx.fillStyle;
  5524. context.strokeStyle = ctx.strokeStyle;
  5525. break;
  5526. case PaintType.UNCOLORED:
  5527. var cssColor = Util.makeCssRgb(color[0], color[1], color[2]);
  5528. context.fillStyle = cssColor;
  5529. context.strokeStyle = cssColor;
  5530. break;
  5531. default:
  5532. error('Unsupported paint type: ' + paintType);
  5533. }
  5534. },
  5535. getPattern: function TilingPattern_getPattern(ctx, owner) {
  5536. var temporaryPatternCanvas = this.createPatternCanvas(owner);
  5537. ctx = this.ctx;
  5538. ctx.setTransform.apply(ctx, this.baseTransform);
  5539. ctx.transform.apply(ctx, this.matrix);
  5540. this.scaleToContext();
  5541. return ctx.createPattern(temporaryPatternCanvas, 'repeat');
  5542. }
  5543. };
  5544. return TilingPattern;
  5545. })();
  5546. PDFJS.disableFontFace = false;
  5547. var FontLoader = {
  5548. insertRule: function fontLoaderInsertRule(rule) {
  5549. var styleElement = document.getElementById('PDFJS_FONT_STYLE_TAG');
  5550. if (!styleElement) {
  5551. styleElement = document.createElement('style');
  5552. styleElement.id = 'PDFJS_FONT_STYLE_TAG';
  5553. document.documentElement.getElementsByTagName('head')[0].appendChild(
  5554. styleElement);
  5555. }
  5556. var styleSheet = styleElement.sheet;
  5557. styleSheet.insertRule(rule, styleSheet.cssRules.length);
  5558. },
  5559. clear: function fontLoaderClear() {
  5560. var styleElement = document.getElementById('PDFJS_FONT_STYLE_TAG');
  5561. if (styleElement) {
  5562. styleElement.parentNode.removeChild(styleElement);
  5563. }
  5564. this.nativeFontFaces.forEach(function(nativeFontFace) {
  5565. document.fonts.delete(nativeFontFace);
  5566. });
  5567. this.nativeFontFaces.length = 0;
  5568. },
  5569. get loadTestFont() {
  5570. // This is a CFF font with 1 glyph for '.' that fills its entire width and
  5571. // height.
  5572. return shadow(this, 'loadTestFont', atob(
  5573. 'T1RUTwALAIAAAwAwQ0ZGIDHtZg4AAAOYAAAAgUZGVE1lkzZwAAAEHAAAABxHREVGABQAFQ' +
  5574. 'AABDgAAAAeT1MvMlYNYwkAAAEgAAAAYGNtYXABDQLUAAACNAAAAUJoZWFk/xVFDQAAALwA' +
  5575. 'AAA2aGhlYQdkA+oAAAD0AAAAJGhtdHgD6AAAAAAEWAAAAAZtYXhwAAJQAAAAARgAAAAGbm' +
  5576. 'FtZVjmdH4AAAGAAAAAsXBvc3T/hgAzAAADeAAAACAAAQAAAAEAALZRFsRfDzz1AAsD6AAA' +
  5577. 'AADOBOTLAAAAAM4KHDwAAAAAA+gDIQAAAAgAAgAAAAAAAAABAAADIQAAAFoD6AAAAAAD6A' +
  5578. 'ABAAAAAAAAAAAAAAAAAAAAAQAAUAAAAgAAAAQD6AH0AAUAAAKKArwAAACMAooCvAAAAeAA' +
  5579. 'MQECAAACAAYJAAAAAAAAAAAAAQAAAAAAAAAAAAAAAFBmRWQAwAAuAC4DIP84AFoDIQAAAA' +
  5580. 'AAAQAAAAAAAAAAACAAIAABAAAADgCuAAEAAAAAAAAAAQAAAAEAAAAAAAEAAQAAAAEAAAAA' +
  5581. 'AAIAAQAAAAEAAAAAAAMAAQAAAAEAAAAAAAQAAQAAAAEAAAAAAAUAAQAAAAEAAAAAAAYAAQ' +
  5582. 'AAAAMAAQQJAAAAAgABAAMAAQQJAAEAAgABAAMAAQQJAAIAAgABAAMAAQQJAAMAAgABAAMA' +
  5583. 'AQQJAAQAAgABAAMAAQQJAAUAAgABAAMAAQQJAAYAAgABWABYAAAAAAAAAwAAAAMAAAAcAA' +
  5584. 'EAAAAAADwAAwABAAAAHAAEACAAAAAEAAQAAQAAAC7//wAAAC7////TAAEAAAAAAAABBgAA' +
  5585. 'AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAA' +
  5586. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' +
  5587. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' +
  5588. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' +
  5589. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMAAA' +
  5590. 'AAAAD/gwAyAAAAAQAAAAAAAAAAAAAAAAAAAAABAAQEAAEBAQJYAAEBASH4DwD4GwHEAvgc' +
  5591. 'A/gXBIwMAYuL+nz5tQXkD5j3CBLnEQACAQEBIVhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWF' +
  5592. 'hYWFhYWFhYAAABAQAADwACAQEEE/t3Dov6fAH6fAT+fPp8+nwHDosMCvm1Cvm1DAz6fBQA' +
  5593. 'AAAAAAABAAAAAMmJbzEAAAAAzgTjFQAAAADOBOQpAAEAAAAAAAAADAAUAAQAAAABAAAAAg' +
  5594. 'ABAAAAAAAAAAAD6AAAAAAAAA=='
  5595. ));
  5596. },
  5597. loadTestFontId: 0,
  5598. loadingContext: {
  5599. requests: [],
  5600. nextRequestId: 0
  5601. },
  5602. isSyncFontLoadingSupported: (function detectSyncFontLoadingSupport() {
  5603. if (isWorker) {
  5604. return false;
  5605. }
  5606. // User agent string sniffing is bad, but there is no reliable way to tell
  5607. // if font is fully loaded and ready to be used with canvas.
  5608. var userAgent = window.navigator.userAgent;
  5609. var m = /Mozilla\/5.0.*?rv:(\d+).*? Gecko/.exec(userAgent);
  5610. if (m && m[1] >= 14) {
  5611. return true;
  5612. }
  5613. // TODO other browsers
  5614. if (userAgent === 'node') {
  5615. return true;
  5616. }
  5617. return false;
  5618. })(),
  5619. nativeFontFaces: [],
  5620. isFontLoadingAPISupported: (!isWorker && typeof document !== 'undefined' &&
  5621. !!document.fonts),
  5622. addNativeFontFace: function fontLoader_addNativeFontFace(nativeFontFace) {
  5623. this.nativeFontFaces.push(nativeFontFace);
  5624. document.fonts.add(nativeFontFace);
  5625. },
  5626. bind: function fontLoaderBind(fonts, callback) {
  5627. assert(!isWorker, 'bind() shall be called from main thread');
  5628. var rules = [];
  5629. var fontsToLoad = [];
  5630. var fontLoadPromises = [];
  5631. for (var i = 0, ii = fonts.length; i < ii; i++) {
  5632. var font = fonts[i];
  5633. // Add the font to the DOM only once or skip if the font
  5634. // is already loaded.
  5635. if (font.attached || font.loading === false) {
  5636. continue;
  5637. }
  5638. font.attached = true;
  5639. if (this.isFontLoadingAPISupported) {
  5640. var nativeFontFace = font.createNativeFontFace();
  5641. if (nativeFontFace) {
  5642. fontLoadPromises.push(nativeFontFace.loaded);
  5643. }
  5644. } else {
  5645. var rule = font.bindDOM();
  5646. if (rule) {
  5647. rules.push(rule);
  5648. fontsToLoad.push(font);
  5649. }
  5650. }
  5651. }
  5652. var request = FontLoader.queueLoadingCallback(callback);
  5653. if (this.isFontLoadingAPISupported) {
  5654. Promise.all(fontsToLoad).then(function() {
  5655. request.complete();
  5656. });
  5657. } else if (rules.length > 0 && !this.isSyncFontLoadingSupported) {
  5658. FontLoader.prepareFontLoadEvent(rules, fontsToLoad, request);
  5659. } else {
  5660. request.complete();
  5661. }
  5662. },
  5663. queueLoadingCallback: function FontLoader_queueLoadingCallback(callback) {
  5664. function LoadLoader_completeRequest() {
  5665. assert(!request.end, 'completeRequest() cannot be called twice');
  5666. request.end = Date.now();
  5667. // sending all completed requests in order how they were queued
  5668. while (context.requests.length > 0 && context.requests[0].end) {
  5669. var otherRequest = context.requests.shift();
  5670. setTimeout(otherRequest.callback, 0);
  5671. }
  5672. }
  5673. var context = FontLoader.loadingContext;
  5674. var requestId = 'pdfjs-font-loading-' + (context.nextRequestId++);
  5675. var request = {
  5676. id: requestId,
  5677. complete: LoadLoader_completeRequest,
  5678. callback: callback,
  5679. started: Date.now()
  5680. };
  5681. context.requests.push(request);
  5682. return request;
  5683. },
  5684. prepareFontLoadEvent: function fontLoaderPrepareFontLoadEvent(rules,
  5685. fonts,
  5686. request) {
  5687. /** Hack begin */
  5688. // There's currently no event when a font has finished downloading so the
  5689. // following code is a dirty hack to 'guess' when a font is
  5690. // ready. It's assumed fonts are loaded in order, so add a known test
  5691. // font after the desired fonts and then test for the loading of that
  5692. // test font.
  5693. function int32(data, offset) {
  5694. return (data.charCodeAt(offset) << 24) |
  5695. (data.charCodeAt(offset + 1) << 16) |
  5696. (data.charCodeAt(offset + 2) << 8) |
  5697. (data.charCodeAt(offset + 3) & 0xff);
  5698. }
  5699. function spliceString(s, offset, remove, insert) {
  5700. var chunk1 = s.substr(0, offset);
  5701. var chunk2 = s.substr(offset + remove);
  5702. return chunk1 + insert + chunk2;
  5703. }
  5704. var i, ii;
  5705. var canvas = document.createElement('canvas');
  5706. canvas.width = 1;
  5707. canvas.height = 1;
  5708. var ctx = canvas.getContext('2d');
  5709. var called = 0;
  5710. function isFontReady(name, callback) {
  5711. called++;
  5712. // With setTimeout clamping this gives the font ~100ms to load.
  5713. if(called > 30) {
  5714. warn('Load test font never loaded.');
  5715. callback();
  5716. return;
  5717. }
  5718. ctx.font = '30px ' + name;
  5719. ctx.fillText('.', 0, 20);
  5720. var imageData = ctx.getImageData(0, 0, 1, 1);
  5721. if (imageData.data[3] > 0) {
  5722. callback();
  5723. return;
  5724. }
  5725. setTimeout(isFontReady.bind(null, name, callback));
  5726. }
  5727. var loadTestFontId = 'lt' + Date.now() + this.loadTestFontId++;
  5728. // Chromium seems to cache fonts based on a hash of the actual font data,
  5729. // so the font must be modified for each load test else it will appear to
  5730. // be loaded already.
  5731. // TODO: This could maybe be made faster by avoiding the btoa of the full
  5732. // font by splitting it in chunks before hand and padding the font id.
  5733. var data = this.loadTestFont;
  5734. var COMMENT_OFFSET = 976; // has to be on 4 byte boundary (for checksum)
  5735. data = spliceString(data, COMMENT_OFFSET, loadTestFontId.length,
  5736. loadTestFontId);
  5737. // CFF checksum is important for IE, adjusting it
  5738. var CFF_CHECKSUM_OFFSET = 16;
  5739. var XXXX_VALUE = 0x58585858; // the "comment" filled with 'X'
  5740. var checksum = int32(data, CFF_CHECKSUM_OFFSET);
  5741. for (i = 0, ii = loadTestFontId.length - 3; i < ii; i += 4) {
  5742. checksum = (checksum - XXXX_VALUE + int32(loadTestFontId, i)) | 0;
  5743. }
  5744. if (i < loadTestFontId.length) { // align to 4 bytes boundary
  5745. checksum = (checksum - XXXX_VALUE +
  5746. int32(loadTestFontId + 'XXX', i)) | 0;
  5747. }
  5748. data = spliceString(data, CFF_CHECKSUM_OFFSET, 4, string32(checksum));
  5749. var url = 'url(data:font/opentype;base64,' + btoa(data) + ');';
  5750. var rule = '@font-face { font-family:"' + loadTestFontId + '";src:' +
  5751. url + '}';
  5752. FontLoader.insertRule(rule);
  5753. var names = [];
  5754. for (i = 0, ii = fonts.length; i < ii; i++) {
  5755. names.push(fonts[i].loadedName);
  5756. }
  5757. names.push(loadTestFontId);
  5758. var div = document.createElement('div');
  5759. div.setAttribute('style',
  5760. 'visibility: hidden;' +
  5761. 'width: 10px; height: 10px;' +
  5762. 'position: absolute; top: 0px; left: 0px;');
  5763. for (i = 0, ii = names.length; i < ii; ++i) {
  5764. var span = document.createElement('span');
  5765. span.textContent = 'Hi';
  5766. span.style.fontFamily = names[i];
  5767. div.appendChild(span);
  5768. }
  5769. document.body.appendChild(div);
  5770. isFontReady(loadTestFontId, function() {
  5771. document.body.removeChild(div);
  5772. request.complete();
  5773. });
  5774. /** Hack end */
  5775. }
  5776. };
  5777. var FontFaceObject = (function FontFaceObjectClosure() {
  5778. function FontFaceObject(name, file, properties) {
  5779. this.compiledGlyphs = {};
  5780. if (arguments.length === 1) {
  5781. // importing translated data
  5782. var data = arguments[0];
  5783. for (var i in data) {
  5784. this[i] = data[i];
  5785. }
  5786. return;
  5787. }
  5788. }
  5789. FontFaceObject.prototype = {
  5790. createNativeFontFace: function FontFaceObject_createNativeFontFace() {
  5791. if (!this.data) {
  5792. return null;
  5793. }
  5794. if (PDFJS.disableFontFace) {
  5795. this.disableFontFace = true;
  5796. return null;
  5797. }
  5798. var nativeFontFace = new FontFace(this.loadedName, this.data, {});
  5799. FontLoader.addNativeFontFace(nativeFontFace);
  5800. if (PDFJS.pdfBug && 'FontInspector' in globalScope &&
  5801. globalScope['FontInspector'].enabled) {
  5802. globalScope['FontInspector'].fontAdded(this);
  5803. }
  5804. return nativeFontFace;
  5805. },
  5806. bindDOM: function FontFaceObject_bindDOM() {
  5807. if (!this.data) {
  5808. return null;
  5809. }
  5810. if (PDFJS.disableFontFace) {
  5811. this.disableFontFace = true;
  5812. return null;
  5813. }
  5814. var data = bytesToString(new Uint8Array(this.data));
  5815. var fontName = this.loadedName;
  5816. // Add the font-face rule to the document
  5817. var url = ('url(data:' + this.mimetype + ';base64,' +
  5818. window.btoa(data) + ');');
  5819. var rule = '@font-face { font-family:"' + fontName + '";src:' + url + '}';
  5820. FontLoader.insertRule(rule);
  5821. if (PDFJS.pdfBug && 'FontInspector' in globalScope &&
  5822. globalScope['FontInspector'].enabled) {
  5823. globalScope['FontInspector'].fontAdded(this, url);
  5824. }
  5825. return rule;
  5826. },
  5827. getPathGenerator: function FontLoader_getPathGenerator(objs, character) {
  5828. if (!(character in this.compiledGlyphs)) {
  5829. var js = objs.get(this.loadedName + '_path_' + character);
  5830. /*jshint -W054 */
  5831. this.compiledGlyphs[character] = new Function('c', 'size', js);
  5832. }
  5833. return this.compiledGlyphs[character];
  5834. }
  5835. };
  5836. return FontFaceObject;
  5837. })();
  5838. var ANNOT_MIN_SIZE = 10; // px
  5839. var AnnotationUtils = (function AnnotationUtilsClosure() {
  5840. // TODO(mack): This dupes some of the logic in CanvasGraphics.setFont()
  5841. function setTextStyles(element, item, fontObj) {
  5842. var style = element.style;
  5843. style.fontSize = item.fontSize + 'px';
  5844. style.direction = item.fontDirection < 0 ? 'rtl': 'ltr';
  5845. if (!fontObj) {
  5846. return;
  5847. }
  5848. style.fontWeight = fontObj.black ?
  5849. (fontObj.bold ? 'bolder' : 'bold') :
  5850. (fontObj.bold ? 'bold' : 'normal');
  5851. style.fontStyle = fontObj.italic ? 'italic' : 'normal';
  5852. var fontName = fontObj.loadedName;
  5853. var fontFamily = fontName ? '"' + fontName + '", ' : '';
  5854. // Use a reasonable default font if the font doesn't specify a fallback
  5855. var fallbackName = fontObj.fallbackName || 'Helvetica, sans-serif';
  5856. style.fontFamily = fontFamily + fallbackName;
  5857. }
  5858. function initContainer(item, drawBorder) {
  5859. var container = document.createElement('section');
  5860. var cstyle = container.style;
  5861. var width = item.rect[2] - item.rect[0];
  5862. var height = item.rect[3] - item.rect[1];
  5863. var bWidth = item.borderWidth || 0;
  5864. if (bWidth) {
  5865. width = width - 2 * bWidth;
  5866. height = height - 2 * bWidth;
  5867. cstyle.borderWidth = bWidth + 'px';
  5868. var color = item.color;
  5869. if (drawBorder && color) {
  5870. cstyle.borderStyle = 'solid';
  5871. cstyle.borderColor = Util.makeCssRgb(Math.round(color[0] * 255),
  5872. Math.round(color[1] * 255),
  5873. Math.round(color[2] * 255));
  5874. }
  5875. }
  5876. cstyle.width = width + 'px';
  5877. cstyle.height = height + 'px';
  5878. return container;
  5879. }
  5880. function getHtmlElementForTextWidgetAnnotation(item, commonObjs) {
  5881. var element = document.createElement('div');
  5882. var width = item.rect[2] - item.rect[0];
  5883. var height = item.rect[3] - item.rect[1];
  5884. element.style.width = width + 'px';
  5885. element.style.height = height + 'px';
  5886. element.style.display = 'table';
  5887. var content = document.createElement('div');
  5888. content.textContent = item.fieldValue;
  5889. var textAlignment = item.textAlignment;
  5890. content.style.textAlign = ['left', 'center', 'right'][textAlignment];
  5891. content.style.verticalAlign = 'middle';
  5892. content.style.display = 'table-cell';
  5893. var fontObj = item.fontRefName ?
  5894. commonObjs.getData(item.fontRefName) : null;
  5895. setTextStyles(content, item, fontObj);
  5896. element.appendChild(content);
  5897. return element;
  5898. }
  5899. function getHtmlElementForTextAnnotation(item) {
  5900. var rect = item.rect;
  5901. // sanity check because of OOo-generated PDFs
  5902. if ((rect[3] - rect[1]) < ANNOT_MIN_SIZE) {
  5903. rect[3] = rect[1] + ANNOT_MIN_SIZE;
  5904. }
  5905. if ((rect[2] - rect[0]) < ANNOT_MIN_SIZE) {
  5906. rect[2] = rect[0] + (rect[3] - rect[1]); // make it square
  5907. }
  5908. var container = initContainer(item, false);
  5909. container.className = 'annotText';
  5910. var image = document.createElement('img');
  5911. image.style.height = container.style.height;
  5912. image.style.width = container.style.width;
  5913. var iconName = item.name;
  5914. image.src = PDFJS.imageResourcesPath + 'annotation-' +
  5915. iconName.toLowerCase() + '.svg';
  5916. image.alt = '[{{type}} Annotation]';
  5917. image.dataset.l10nId = 'text_annotation_type';
  5918. image.dataset.l10nArgs = JSON.stringify({type: iconName});
  5919. var contentWrapper = document.createElement('div');
  5920. contentWrapper.className = 'annotTextContentWrapper';
  5921. contentWrapper.style.left = Math.floor(rect[2] - rect[0] + 5) + 'px';
  5922. contentWrapper.style.top = '-10px';
  5923. var content = document.createElement('div');
  5924. content.className = 'annotTextContent';
  5925. content.setAttribute('hidden', true);
  5926. var i, ii;
  5927. if (item.hasBgColor) {
  5928. var color = item.color;
  5929. // Enlighten the color (70%)
  5930. var BACKGROUND_ENLIGHT = 0.7;
  5931. var r = BACKGROUND_ENLIGHT * (1.0 - color[0]) + color[0];
  5932. var g = BACKGROUND_ENLIGHT * (1.0 - color[1]) + color[1];
  5933. var b = BACKGROUND_ENLIGHT * (1.0 - color[2]) + color[2];
  5934. content.style.backgroundColor = Util.makeCssRgb((r * 255) | 0,
  5935. (g * 255) | 0,
  5936. (b * 255) | 0);
  5937. }
  5938. var title = document.createElement('h1');
  5939. var text = document.createElement('p');
  5940. title.textContent = item.title;
  5941. if (!item.content && !item.title) {
  5942. content.setAttribute('hidden', true);
  5943. } else {
  5944. var e = document.createElement('span');
  5945. var lines = item.content.split(/(?:\r\n?|\n)/);
  5946. for (i = 0, ii = lines.length; i < ii; ++i) {
  5947. var line = lines[i];
  5948. e.appendChild(document.createTextNode(line));
  5949. if (i < (ii - 1)) {
  5950. e.appendChild(document.createElement('br'));
  5951. }
  5952. }
  5953. text.appendChild(e);
  5954. var pinned = false;
  5955. var showAnnotation = function showAnnotation(pin) {
  5956. if (pin) {
  5957. pinned = true;
  5958. }
  5959. if (content.hasAttribute('hidden')) {
  5960. container.style.zIndex += 1;
  5961. content.removeAttribute('hidden');
  5962. }
  5963. };
  5964. var hideAnnotation = function hideAnnotation(unpin) {
  5965. if (unpin) {
  5966. pinned = false;
  5967. }
  5968. if (!content.hasAttribute('hidden') && !pinned) {
  5969. container.style.zIndex -= 1;
  5970. content.setAttribute('hidden', true);
  5971. }
  5972. };
  5973. var toggleAnnotation = function toggleAnnotation() {
  5974. if (pinned) {
  5975. hideAnnotation(true);
  5976. } else {
  5977. showAnnotation(true);
  5978. }
  5979. };
  5980. image.addEventListener('click', function image_clickHandler() {
  5981. toggleAnnotation();
  5982. }, false);
  5983. image.addEventListener('mouseover', function image_mouseOverHandler() {
  5984. showAnnotation();
  5985. }, false);
  5986. image.addEventListener('mouseout', function image_mouseOutHandler() {
  5987. hideAnnotation();
  5988. }, false);
  5989. content.addEventListener('click', function content_clickHandler() {
  5990. hideAnnotation(true);
  5991. }, false);
  5992. }
  5993. content.appendChild(title);
  5994. content.appendChild(text);
  5995. contentWrapper.appendChild(content);
  5996. container.appendChild(image);
  5997. container.appendChild(contentWrapper);
  5998. return container;
  5999. }
  6000. function getHtmlElementForLinkAnnotation(item) {
  6001. var container = initContainer(item, true);
  6002. container.className = 'annotLink';
  6003. var link = document.createElement('a');
  6004. link.href = link.title = item.url || '';
  6005. if (item.url && PDFJS.openExternalLinksInNewWindow) {
  6006. link.target = '_blank';
  6007. }
  6008. container.appendChild(link);
  6009. return container;
  6010. }
  6011. function getHtmlElement(data, objs) {
  6012. switch (data.annotationType) {
  6013. case AnnotationType.WIDGET:
  6014. return getHtmlElementForTextWidgetAnnotation(data, objs);
  6015. case AnnotationType.TEXT:
  6016. return getHtmlElementForTextAnnotation(data);
  6017. case AnnotationType.LINK:
  6018. return getHtmlElementForLinkAnnotation(data);
  6019. default:
  6020. throw new Error('Unsupported annotationType: ' + data.annotationType);
  6021. }
  6022. }
  6023. return {
  6024. getHtmlElement: getHtmlElement
  6025. };
  6026. })();
  6027. PDFJS.AnnotationUtils = AnnotationUtils;
  6028. var SVG_DEFAULTS = {
  6029. fontStyle: 'normal',
  6030. fontWeight: 'normal',
  6031. fillColor: '#000000'
  6032. };
  6033. var convertImgDataToPng = (function convertImgDataToPngClosure() {
  6034. var PNG_HEADER =
  6035. new Uint8Array([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);
  6036. var CHUNK_WRAPPER_SIZE = 12;
  6037. var crcTable = new Int32Array(256);
  6038. for (var i = 0; i < 256; i++) {
  6039. var c = i;
  6040. for (var h = 0; h < 8; h++) {
  6041. if (c & 1) {
  6042. c = 0xedB88320 ^ ((c >> 1) & 0x7fffffff);
  6043. } else {
  6044. c = (c >> 1) & 0x7fffffff;
  6045. }
  6046. }
  6047. crcTable[i] = c;
  6048. }
  6049. function crc32(data, start, end) {
  6050. var crc = -1;
  6051. for (var i = start; i < end; i++) {
  6052. var a = (crc ^ data[i]) & 0xff;
  6053. var b = crcTable[a];
  6054. crc = (crc >>> 8) ^ b;
  6055. }
  6056. return crc ^ -1;
  6057. }
  6058. function writePngChunk(type, body, data, offset) {
  6059. var p = offset;
  6060. var len = body.length;
  6061. data[p] = len >> 24 & 0xff;
  6062. data[p + 1] = len >> 16 & 0xff;
  6063. data[p + 2] = len >> 8 & 0xff;
  6064. data[p + 3] = len & 0xff;
  6065. p += 4;
  6066. data[p] = type.charCodeAt(0) & 0xff;
  6067. data[p + 1] = type.charCodeAt(1) & 0xff;
  6068. data[p + 2] = type.charCodeAt(2) & 0xff;
  6069. data[p + 3] = type.charCodeAt(3) & 0xff;
  6070. p += 4;
  6071. data.set(body, p);
  6072. p += body.length;
  6073. var crc = crc32(data, offset + 4, p);
  6074. data[p] = crc >> 24 & 0xff;
  6075. data[p + 1] = crc >> 16 & 0xff;
  6076. data[p + 2] = crc >> 8 & 0xff;
  6077. data[p + 3] = crc & 0xff;
  6078. }
  6079. function adler32(data, start, end) {
  6080. var a = 1;
  6081. var b = 0;
  6082. for (var i = start; i < end; ++i) {
  6083. a = (a + (data[i] & 0xff)) % 65521;
  6084. b = (b + a) % 65521;
  6085. }
  6086. return (b << 16) | a;
  6087. }
  6088. function encode(imgData, kind) {
  6089. var width = imgData.width;
  6090. var height = imgData.height;
  6091. var bitDepth, colorType, lineSize;
  6092. var bytes = imgData.data;
  6093. switch (kind) {
  6094. case ImageKind.GRAYSCALE_1BPP:
  6095. colorType = 0;
  6096. bitDepth = 1;
  6097. lineSize = (width + 7) >> 3;
  6098. break;
  6099. case ImageKind.RGB_24BPP:
  6100. colorType = 2;
  6101. bitDepth = 8;
  6102. lineSize = width * 3;
  6103. break;
  6104. case ImageKind.RGBA_32BPP:
  6105. colorType = 6;
  6106. bitDepth = 8;
  6107. lineSize = width * 4;
  6108. break;
  6109. default:
  6110. throw new Error('invalid format');
  6111. }
  6112. // prefix every row with predictor 0
  6113. var literals = new Uint8Array((1 + lineSize) * height);
  6114. var offsetLiterals = 0, offsetBytes = 0;
  6115. var y, i;
  6116. for (y = 0; y < height; ++y) {
  6117. literals[offsetLiterals++] = 0; // no prediction
  6118. literals.set(bytes.subarray(offsetBytes, offsetBytes + lineSize),
  6119. offsetLiterals);
  6120. offsetBytes += lineSize;
  6121. offsetLiterals += lineSize;
  6122. }
  6123. if (kind === ImageKind.GRAYSCALE_1BPP) {
  6124. // inverting for B/W
  6125. offsetLiterals = 0;
  6126. for (y = 0; y < height; y++) {
  6127. offsetLiterals++; // skipping predictor
  6128. for (i = 0; i < lineSize; i++) {
  6129. literals[offsetLiterals++] ^= 0xFF;
  6130. }
  6131. }
  6132. }
  6133. var ihdr = new Uint8Array([
  6134. width >> 24 & 0xff,
  6135. width >> 16 & 0xff,
  6136. width >> 8 & 0xff,
  6137. width & 0xff,
  6138. height >> 24 & 0xff,
  6139. height >> 16 & 0xff,
  6140. height >> 8 & 0xff,
  6141. height & 0xff,
  6142. bitDepth, // bit depth
  6143. colorType, // color type
  6144. 0x00, // compression method
  6145. 0x00, // filter method
  6146. 0x00 // interlace method
  6147. ]);
  6148. var len = literals.length;
  6149. var maxBlockLength = 0xFFFF;
  6150. var deflateBlocks = Math.ceil(len / maxBlockLength);
  6151. var idat = new Uint8Array(2 + len + deflateBlocks * 5 + 4);
  6152. var pi = 0;
  6153. idat[pi++] = 0x78; // compression method and flags
  6154. idat[pi++] = 0x9c; // flags
  6155. var pos = 0;
  6156. while (len > maxBlockLength) {
  6157. // writing non-final DEFLATE blocks type 0 and length of 65535
  6158. idat[pi++] = 0x00;
  6159. idat[pi++] = 0xff;
  6160. idat[pi++] = 0xff;
  6161. idat[pi++] = 0x00;
  6162. idat[pi++] = 0x00;
  6163. idat.set(literals.subarray(pos, pos + maxBlockLength), pi);
  6164. pi += maxBlockLength;
  6165. pos += maxBlockLength;
  6166. len -= maxBlockLength;
  6167. }
  6168. // writing non-final DEFLATE blocks type 0
  6169. idat[pi++] = 0x01;
  6170. idat[pi++] = len & 0xff;
  6171. idat[pi++] = len >> 8 & 0xff;
  6172. idat[pi++] = (~len & 0xffff) & 0xff;
  6173. idat[pi++] = (~len & 0xffff) >> 8 & 0xff;
  6174. idat.set(literals.subarray(pos), pi);
  6175. pi += literals.length - pos;
  6176. var adler = adler32(literals, 0, literals.length); // checksum
  6177. idat[pi++] = adler >> 24 & 0xff;
  6178. idat[pi++] = adler >> 16 & 0xff;
  6179. idat[pi++] = adler >> 8 & 0xff;
  6180. idat[pi++] = adler & 0xff;
  6181. // PNG will consists: header, IHDR+data, IDAT+data, and IEND.
  6182. var pngLength = PNG_HEADER.length + (CHUNK_WRAPPER_SIZE * 3) +
  6183. ihdr.length + idat.length;
  6184. var data = new Uint8Array(pngLength);
  6185. var offset = 0;
  6186. data.set(PNG_HEADER, offset);
  6187. offset += PNG_HEADER.length;
  6188. writePngChunk('IHDR', ihdr, data, offset);
  6189. offset += CHUNK_WRAPPER_SIZE + ihdr.length;
  6190. writePngChunk('IDATA', idat, data, offset);
  6191. offset += CHUNK_WRAPPER_SIZE + idat.length;
  6192. writePngChunk('IEND', new Uint8Array(0), data, offset);
  6193. return PDFJS.createObjectURL(data, 'image/png');
  6194. }
  6195. return function convertImgDataToPng(imgData) {
  6196. var kind = (imgData.kind === undefined ?
  6197. ImageKind.GRAYSCALE_1BPP : imgData.kind);
  6198. return encode(imgData, kind);
  6199. };
  6200. })();
  6201. var SVGExtraState = (function SVGExtraStateClosure() {
  6202. function SVGExtraState() {
  6203. this.fontSizeScale = 1;
  6204. this.fontWeight = SVG_DEFAULTS.fontWeight;
  6205. this.fontSize = 0;
  6206. this.textMatrix = IDENTITY_MATRIX;
  6207. this.fontMatrix = FONT_IDENTITY_MATRIX;
  6208. this.leading = 0;
  6209. // Current point (in user coordinates)
  6210. this.x = 0;
  6211. this.y = 0;
  6212. // Start of text line (in text coordinates)
  6213. this.lineX = 0;
  6214. this.lineY = 0;
  6215. // Character and word spacing
  6216. this.charSpacing = 0;
  6217. this.wordSpacing = 0;
  6218. this.textHScale = 1;
  6219. this.textRise = 0;
  6220. // Default foreground and background colors
  6221. this.fillColor = SVG_DEFAULTS.fillColor;
  6222. this.strokeColor = '#000000';
  6223. this.fillAlpha = 1;
  6224. this.strokeAlpha = 1;
  6225. this.lineWidth = 1;
  6226. this.lineJoin = '';
  6227. this.lineCap = '';
  6228. this.miterLimit = 0;
  6229. this.dashArray = [];
  6230. this.dashPhase = 0;
  6231. this.dependencies = [];
  6232. // Clipping
  6233. this.clipId = '';
  6234. this.pendingClip = false;
  6235. this.maskId = '';
  6236. }
  6237. SVGExtraState.prototype = {
  6238. clone: function SVGExtraState_clone() {
  6239. return Object.create(this);
  6240. },
  6241. setCurrentPoint: function SVGExtraState_setCurrentPoint(x, y) {
  6242. this.x = x;
  6243. this.y = y;
  6244. }
  6245. };
  6246. return SVGExtraState;
  6247. })();
  6248. var SVGGraphics = (function SVGGraphicsClosure() {
  6249. function createScratchSVG(width, height) {
  6250. var NS = 'http://www.w3.org/2000/svg';
  6251. var svg = document.createElementNS(NS, 'svg:svg');
  6252. svg.setAttributeNS(null, 'version', '1.1');
  6253. svg.setAttributeNS(null, 'width', width + 'px');
  6254. svg.setAttributeNS(null, 'height', height + 'px');
  6255. svg.setAttributeNS(null, 'viewBox', '0 0 ' + width + ' ' + height);
  6256. return svg;
  6257. }
  6258. function opListToTree(opList) {
  6259. var opTree = [];
  6260. var tmp = [];
  6261. var opListLen = opList.length;
  6262. for (var x = 0; x < opListLen; x++) {
  6263. if (opList[x].fn === 'save') {
  6264. opTree.push({'fnId': 92, 'fn': 'group', 'items': []});
  6265. tmp.push(opTree);
  6266. opTree = opTree[opTree.length - 1].items;
  6267. continue;
  6268. }
  6269. if(opList[x].fn === 'restore') {
  6270. opTree = tmp.pop();
  6271. } else {
  6272. opTree.push(opList[x]);
  6273. }
  6274. }
  6275. return opTree;
  6276. }
  6277. /**
  6278. * Formats float number.
  6279. * @param value {number} number to format.
  6280. * @returns {string}
  6281. */
  6282. function pf(value) {
  6283. if (value === (value | 0)) { // integer number
  6284. return value.toString();
  6285. }
  6286. var s = value.toFixed(10);
  6287. var i = s.length - 1;
  6288. if (s[i] !== '0') {
  6289. return s;
  6290. }
  6291. // removing trailing zeros
  6292. do {
  6293. i--;
  6294. } while (s[i] === '0');
  6295. return s.substr(0, s[i] === '.' ? i : i + 1);
  6296. }
  6297. /**
  6298. * Formats transform matrix. The standard rotation, scale and translate
  6299. * matrices are replaced by their shorter forms, and for identity matrix
  6300. * returns empty string to save the memory.
  6301. * @param m {Array} matrix to format.
  6302. * @returns {string}
  6303. */
  6304. function pm(m) {
  6305. if (m[4] === 0 && m[5] === 0) {
  6306. if (m[1] === 0 && m[2] === 0) {
  6307. if (m[0] === 1 && m[3] === 1) {
  6308. return '';
  6309. }
  6310. return 'scale(' + pf(m[0]) + ' ' + pf(m[3]) + ')';
  6311. }
  6312. if (m[0] === m[3] && m[1] === -m[2]) {
  6313. var a = Math.acos(m[0]) * 180 / Math.PI;
  6314. return 'rotate(' + pf(a) + ')';
  6315. }
  6316. } else {
  6317. if (m[0] === 1 && m[1] === 0 && m[2] === 0 && m[3] === 1) {
  6318. return 'translate(' + pf(m[4]) + ' ' + pf(m[5]) + ')';
  6319. }
  6320. }
  6321. return 'matrix(' + pf(m[0]) + ' ' + pf(m[1]) + ' ' + pf(m[2]) + ' ' +
  6322. pf(m[3]) + ' ' + pf(m[4]) + ' ' + pf(m[5]) + ')';
  6323. }
  6324. function SVGGraphics(commonObjs, objs) {
  6325. this.current = new SVGExtraState();
  6326. this.transformMatrix = IDENTITY_MATRIX; // Graphics state matrix
  6327. this.transformStack = [];
  6328. this.extraStack = [];
  6329. this.commonObjs = commonObjs;
  6330. this.objs = objs;
  6331. this.pendingEOFill = false;
  6332. this.embedFonts = false;
  6333. this.embeddedFonts = {};
  6334. this.cssStyle = null;
  6335. }
  6336. var NS = 'http://www.w3.org/2000/svg';
  6337. var XML_NS = 'http://www.w3.org/XML/1998/namespace';
  6338. var XLINK_NS = 'http://www.w3.org/1999/xlink';
  6339. var LINE_CAP_STYLES = ['butt', 'round', 'square'];
  6340. var LINE_JOIN_STYLES = ['miter', 'round', 'bevel'];
  6341. var clipCount = 0;
  6342. var maskCount = 0;
  6343. SVGGraphics.prototype = {
  6344. save: function SVGGraphics_save() {
  6345. this.transformStack.push(this.transformMatrix);
  6346. var old = this.current;
  6347. this.extraStack.push(old);
  6348. this.current = old.clone();
  6349. },
  6350. restore: function SVGGraphics_restore() {
  6351. this.transformMatrix = this.transformStack.pop();
  6352. this.current = this.extraStack.pop();
  6353. this.tgrp = document.createElementNS(NS, 'svg:g');
  6354. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  6355. this.pgrp.appendChild(this.tgrp);
  6356. },
  6357. group: function SVGGraphics_group(items) {
  6358. this.save();
  6359. this.executeOpTree(items);
  6360. this.restore();
  6361. },
  6362. loadDependencies: function SVGGraphics_loadDependencies(operatorList) {
  6363. var fnArray = operatorList.fnArray;
  6364. var fnArrayLen = fnArray.length;
  6365. var argsArray = operatorList.argsArray;
  6366. var self = this;
  6367. for (var i = 0; i < fnArrayLen; i++) {
  6368. if (OPS.dependency === fnArray[i]) {
  6369. var deps = argsArray[i];
  6370. for (var n = 0, nn = deps.length; n < nn; n++) {
  6371. var obj = deps[n];
  6372. var common = obj.substring(0, 2) === 'g_';
  6373. var promise;
  6374. if (common) {
  6375. promise = new Promise(function(resolve) {
  6376. self.commonObjs.get(obj, resolve);
  6377. });
  6378. } else {
  6379. promise = new Promise(function(resolve) {
  6380. self.objs.get(obj, resolve);
  6381. });
  6382. }
  6383. this.current.dependencies.push(promise);
  6384. }
  6385. }
  6386. }
  6387. return Promise.all(this.current.dependencies);
  6388. },
  6389. transform: function SVGGraphics_transform(a, b, c, d, e, f) {
  6390. var transformMatrix = [a, b, c, d, e, f];
  6391. this.transformMatrix = PDFJS.Util.transform(this.transformMatrix,
  6392. transformMatrix);
  6393. this.tgrp = document.createElementNS(NS, 'svg:g');
  6394. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  6395. },
  6396. getSVG: function SVGGraphics_getSVG(operatorList, viewport) {
  6397. this.svg = createScratchSVG(viewport.width, viewport.height);
  6398. this.viewport = viewport;
  6399. return this.loadDependencies(operatorList).then(function () {
  6400. this.transformMatrix = IDENTITY_MATRIX;
  6401. this.pgrp = document.createElementNS(NS, 'svg:g'); // Parent group
  6402. this.pgrp.setAttributeNS(null, 'transform', pm(viewport.transform));
  6403. this.tgrp = document.createElementNS(NS, 'svg:g'); // Transform group
  6404. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  6405. this.defs = document.createElementNS(NS, 'svg:defs');
  6406. this.pgrp.appendChild(this.defs);
  6407. this.pgrp.appendChild(this.tgrp);
  6408. this.svg.appendChild(this.pgrp);
  6409. var opTree = this.convertOpList(operatorList);
  6410. this.executeOpTree(opTree);
  6411. return this.svg;
  6412. }.bind(this));
  6413. },
  6414. convertOpList: function SVGGraphics_convertOpList(operatorList) {
  6415. var argsArray = operatorList.argsArray;
  6416. var fnArray = operatorList.fnArray;
  6417. var fnArrayLen = fnArray.length;
  6418. var REVOPS = [];
  6419. var opList = [];
  6420. for (var op in OPS) {
  6421. REVOPS[OPS[op]] = op;
  6422. }
  6423. for (var x = 0; x < fnArrayLen; x++) {
  6424. var fnId = fnArray[x];
  6425. opList.push({'fnId' : fnId, 'fn': REVOPS[fnId], 'args': argsArray[x]});
  6426. }
  6427. return opListToTree(opList);
  6428. },
  6429. executeOpTree: function SVGGraphics_executeOpTree(opTree) {
  6430. var opTreeLen = opTree.length;
  6431. for(var x = 0; x < opTreeLen; x++) {
  6432. var fn = opTree[x].fn;
  6433. var fnId = opTree[x].fnId;
  6434. var args = opTree[x].args;
  6435. switch (fnId | 0) {
  6436. case OPS.beginText:
  6437. this.beginText();
  6438. break;
  6439. case OPS.setLeading:
  6440. this.setLeading(args);
  6441. break;
  6442. case OPS.setLeadingMoveText:
  6443. this.setLeadingMoveText(args[0], args[1]);
  6444. break;
  6445. case OPS.setFont:
  6446. this.setFont(args);
  6447. break;
  6448. case OPS.showText:
  6449. this.showText(args[0]);
  6450. break;
  6451. case OPS.showSpacedText:
  6452. this.showText(args[0]);
  6453. break;
  6454. case OPS.endText:
  6455. this.endText();
  6456. break;
  6457. case OPS.moveText:
  6458. this.moveText(args[0], args[1]);
  6459. break;
  6460. case OPS.setCharSpacing:
  6461. this.setCharSpacing(args[0]);
  6462. break;
  6463. case OPS.setWordSpacing:
  6464. this.setWordSpacing(args[0]);
  6465. break;
  6466. case OPS.setHScale:
  6467. this.setHScale(args[0]);
  6468. break;
  6469. case OPS.setTextMatrix:
  6470. this.setTextMatrix(args[0], args[1], args[2],
  6471. args[3], args[4], args[5]);
  6472. break;
  6473. case OPS.setLineWidth:
  6474. this.setLineWidth(args[0]);
  6475. break;
  6476. case OPS.setLineJoin:
  6477. this.setLineJoin(args[0]);
  6478. break;
  6479. case OPS.setLineCap:
  6480. this.setLineCap(args[0]);
  6481. break;
  6482. case OPS.setMiterLimit:
  6483. this.setMiterLimit(args[0]);
  6484. break;
  6485. case OPS.setFillRGBColor:
  6486. this.setFillRGBColor(args[0], args[1], args[2]);
  6487. break;
  6488. case OPS.setStrokeRGBColor:
  6489. this.setStrokeRGBColor(args[0], args[1], args[2]);
  6490. break;
  6491. case OPS.setDash:
  6492. this.setDash(args[0], args[1]);
  6493. break;
  6494. case OPS.setGState:
  6495. this.setGState(args[0]);
  6496. break;
  6497. case OPS.fill:
  6498. this.fill();
  6499. break;
  6500. case OPS.eoFill:
  6501. this.eoFill();
  6502. break;
  6503. case OPS.stroke:
  6504. this.stroke();
  6505. break;
  6506. case OPS.fillStroke:
  6507. this.fillStroke();
  6508. break;
  6509. case OPS.eoFillStroke:
  6510. this.eoFillStroke();
  6511. break;
  6512. case OPS.clip:
  6513. this.clip('nonzero');
  6514. break;
  6515. case OPS.eoClip:
  6516. this.clip('evenodd');
  6517. break;
  6518. case OPS.paintSolidColorImageMask:
  6519. this.paintSolidColorImageMask();
  6520. break;
  6521. case OPS.paintJpegXObject:
  6522. this.paintJpegXObject(args[0], args[1], args[2]);
  6523. break;
  6524. case OPS.paintImageXObject:
  6525. this.paintImageXObject(args[0]);
  6526. break;
  6527. case OPS.paintInlineImageXObject:
  6528. this.paintInlineImageXObject(args[0]);
  6529. break;
  6530. case OPS.paintImageMaskXObject:
  6531. this.paintImageMaskXObject(args[0]);
  6532. break;
  6533. case OPS.paintFormXObjectBegin:
  6534. this.paintFormXObjectBegin(args[0], args[1]);
  6535. break;
  6536. case OPS.paintFormXObjectEnd:
  6537. this.paintFormXObjectEnd();
  6538. break;
  6539. case OPS.closePath:
  6540. this.closePath();
  6541. break;
  6542. case OPS.closeStroke:
  6543. this.closeStroke();
  6544. break;
  6545. case OPS.closeFillStroke:
  6546. this.closeFillStroke();
  6547. break;
  6548. case OPS.nextLine:
  6549. this.nextLine();
  6550. break;
  6551. case OPS.transform:
  6552. this.transform(args[0], args[1], args[2], args[3],
  6553. args[4], args[5]);
  6554. break;
  6555. case OPS.constructPath:
  6556. this.constructPath(args[0], args[1]);
  6557. break;
  6558. case OPS.endPath:
  6559. this.endPath();
  6560. break;
  6561. case 92:
  6562. this.group(opTree[x].items);
  6563. break;
  6564. default:
  6565. warn('Unimplemented method '+ fn);
  6566. break;
  6567. }
  6568. }
  6569. },
  6570. setWordSpacing: function SVGGraphics_setWordSpacing(wordSpacing) {
  6571. this.current.wordSpacing = wordSpacing;
  6572. },
  6573. setCharSpacing: function SVGGraphics_setCharSpacing(charSpacing) {
  6574. this.current.charSpacing = charSpacing;
  6575. },
  6576. nextLine: function SVGGraphics_nextLine() {
  6577. this.moveText(0, this.current.leading);
  6578. },
  6579. setTextMatrix: function SVGGraphics_setTextMatrix(a, b, c, d, e, f) {
  6580. var current = this.current;
  6581. this.current.textMatrix = this.current.lineMatrix = [a, b, c, d, e, f];
  6582. this.current.x = this.current.lineX = 0;
  6583. this.current.y = this.current.lineY = 0;
  6584. current.xcoords = [];
  6585. current.tspan = document.createElementNS(NS, 'svg:tspan');
  6586. current.tspan.setAttributeNS(null, 'font-family', current.fontFamily);
  6587. current.tspan.setAttributeNS(null, 'font-size',
  6588. pf(current.fontSize) + 'px');
  6589. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  6590. current.txtElement = document.createElementNS(NS, 'svg:text');
  6591. current.txtElement.appendChild(current.tspan);
  6592. },
  6593. beginText: function SVGGraphics_beginText() {
  6594. this.current.x = this.current.lineX = 0;
  6595. this.current.y = this.current.lineY = 0;
  6596. this.current.textMatrix = IDENTITY_MATRIX;
  6597. this.current.lineMatrix = IDENTITY_MATRIX;
  6598. this.current.tspan = document.createElementNS(NS, 'svg:tspan');
  6599. this.current.txtElement = document.createElementNS(NS, 'svg:text');
  6600. this.current.txtgrp = document.createElementNS(NS, 'svg:g');
  6601. this.current.xcoords = [];
  6602. },
  6603. moveText: function SVGGraphics_moveText(x, y) {
  6604. var current = this.current;
  6605. this.current.x = this.current.lineX += x;
  6606. this.current.y = this.current.lineY += y;
  6607. current.xcoords = [];
  6608. current.tspan = document.createElementNS(NS, 'svg:tspan');
  6609. current.tspan.setAttributeNS(null, 'font-family', current.fontFamily);
  6610. current.tspan.setAttributeNS(null, 'font-size',
  6611. pf(current.fontSize) + 'px');
  6612. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  6613. },
  6614. showText: function SVGGraphics_showText(glyphs) {
  6615. var current = this.current;
  6616. var font = current.font;
  6617. var fontSize = current.fontSize;
  6618. if (fontSize === 0) {
  6619. return;
  6620. }
  6621. var charSpacing = current.charSpacing;
  6622. var wordSpacing = current.wordSpacing;
  6623. var fontDirection = current.fontDirection;
  6624. var textHScale = current.textHScale * fontDirection;
  6625. var glyphsLength = glyphs.length;
  6626. var vertical = font.vertical;
  6627. var widthAdvanceScale = fontSize * current.fontMatrix[0];
  6628. var x = 0, i;
  6629. for (i = 0; i < glyphsLength; ++i) {
  6630. var glyph = glyphs[i];
  6631. if (glyph === null) {
  6632. // word break
  6633. x += fontDirection * wordSpacing;
  6634. continue;
  6635. } else if (isNum(glyph)) {
  6636. x += -glyph * fontSize * 0.001;
  6637. continue;
  6638. }
  6639. current.xcoords.push(current.x + x * textHScale);
  6640. var width = glyph.width;
  6641. var character = glyph.fontChar;
  6642. var charWidth = width * widthAdvanceScale + charSpacing * fontDirection;
  6643. x += charWidth;
  6644. current.tspan.textContent += character;
  6645. }
  6646. if (vertical) {
  6647. current.y -= x * textHScale;
  6648. } else {
  6649. current.x += x * textHScale;
  6650. }
  6651. current.tspan.setAttributeNS(null, 'x',
  6652. current.xcoords.map(pf).join(' '));
  6653. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  6654. current.tspan.setAttributeNS(null, 'font-family', current.fontFamily);
  6655. current.tspan.setAttributeNS(null, 'font-size',
  6656. pf(current.fontSize) + 'px');
  6657. if (current.fontStyle !== SVG_DEFAULTS.fontStyle) {
  6658. current.tspan.setAttributeNS(null, 'font-style', current.fontStyle);
  6659. }
  6660. if (current.fontWeight !== SVG_DEFAULTS.fontWeight) {
  6661. current.tspan.setAttributeNS(null, 'font-weight', current.fontWeight);
  6662. }
  6663. if (current.fillColor !== SVG_DEFAULTS.fillColor) {
  6664. current.tspan.setAttributeNS(null, 'fill', current.fillColor);
  6665. }
  6666. current.txtElement.setAttributeNS(null, 'transform',
  6667. pm(current.textMatrix) +
  6668. ' scale(1, -1)' );
  6669. current.txtElement.setAttributeNS(XML_NS, 'xml:space', 'preserve');
  6670. current.txtElement.appendChild(current.tspan);
  6671. current.txtgrp.appendChild(current.txtElement);
  6672. this.tgrp.appendChild(current.txtElement);
  6673. },
  6674. setLeadingMoveText: function SVGGraphics_setLeadingMoveText(x, y) {
  6675. this.setLeading(-y);
  6676. this.moveText(x, y);
  6677. },
  6678. addFontStyle: function SVGGraphics_addFontStyle(fontObj) {
  6679. if (!this.cssStyle) {
  6680. this.cssStyle = document.createElementNS(NS, 'svg:style');
  6681. this.cssStyle.setAttributeNS(null, 'type', 'text/css');
  6682. this.defs.appendChild(this.cssStyle);
  6683. }
  6684. var url = PDFJS.createObjectURL(fontObj.data, fontObj.mimetype);
  6685. this.cssStyle.textContent +=
  6686. '@font-face { font-family: "' + fontObj.loadedName + '";' +
  6687. ' src: url(' + url + '); }\n';
  6688. },
  6689. setFont: function SVGGraphics_setFont(details) {
  6690. var current = this.current;
  6691. var fontObj = this.commonObjs.get(details[0]);
  6692. var size = details[1];
  6693. this.current.font = fontObj;
  6694. if (this.embedFonts && fontObj.data &&
  6695. !this.embeddedFonts[fontObj.loadedName]) {
  6696. this.addFontStyle(fontObj);
  6697. this.embeddedFonts[fontObj.loadedName] = fontObj;
  6698. }
  6699. current.fontMatrix = (fontObj.fontMatrix ?
  6700. fontObj.fontMatrix : FONT_IDENTITY_MATRIX);
  6701. var bold = fontObj.black ? (fontObj.bold ? 'bolder' : 'bold') :
  6702. (fontObj.bold ? 'bold' : 'normal');
  6703. var italic = fontObj.italic ? 'italic' : 'normal';
  6704. if (size < 0) {
  6705. size = -size;
  6706. current.fontDirection = -1;
  6707. } else {
  6708. current.fontDirection = 1;
  6709. }
  6710. current.fontSize = size;
  6711. current.fontFamily = fontObj.loadedName;
  6712. current.fontWeight = bold;
  6713. current.fontStyle = italic;
  6714. current.tspan = document.createElementNS(NS, 'svg:tspan');
  6715. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  6716. current.xcoords = [];
  6717. },
  6718. endText: function SVGGraphics_endText() {
  6719. if (this.current.pendingClip) {
  6720. this.cgrp.appendChild(this.tgrp);
  6721. this.pgrp.appendChild(this.cgrp);
  6722. } else {
  6723. this.pgrp.appendChild(this.tgrp);
  6724. }
  6725. this.tgrp = document.createElementNS(NS, 'svg:g');
  6726. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  6727. },
  6728. // Path properties
  6729. setLineWidth: function SVGGraphics_setLineWidth(width) {
  6730. this.current.lineWidth = width;
  6731. },
  6732. setLineCap: function SVGGraphics_setLineCap(style) {
  6733. this.current.lineCap = LINE_CAP_STYLES[style];
  6734. },
  6735. setLineJoin: function SVGGraphics_setLineJoin(style) {
  6736. this.current.lineJoin = LINE_JOIN_STYLES[style];
  6737. },
  6738. setMiterLimit: function SVGGraphics_setMiterLimit(limit) {
  6739. this.current.miterLimit = limit;
  6740. },
  6741. setStrokeRGBColor: function SVGGraphics_setStrokeRGBColor(r, g, b) {
  6742. var color = Util.makeCssRgb(r, g, b);
  6743. this.current.strokeColor = color;
  6744. },
  6745. setFillRGBColor: function SVGGraphics_setFillRGBColor(r, g, b) {
  6746. var color = Util.makeCssRgb(r, g, b);
  6747. this.current.fillColor = color;
  6748. this.current.tspan = document.createElementNS(NS, 'svg:tspan');
  6749. this.current.xcoords = [];
  6750. },
  6751. setDash: function SVGGraphics_setDash(dashArray, dashPhase) {
  6752. this.current.dashArray = dashArray;
  6753. this.current.dashPhase = dashPhase;
  6754. },
  6755. constructPath: function SVGGraphics_constructPath(ops, args) {
  6756. var current = this.current;
  6757. var x = current.x, y = current.y;
  6758. current.path = document.createElementNS(NS, 'svg:path');
  6759. var d = [];
  6760. var opLength = ops.length;
  6761. for (var i = 0, j = 0; i < opLength; i++) {
  6762. switch (ops[i] | 0) {
  6763. case OPS.rectangle:
  6764. x = args[j++];
  6765. y = args[j++];
  6766. var width = args[j++];
  6767. var height = args[j++];
  6768. var xw = x + width;
  6769. var yh = y + height;
  6770. d.push('M', pf(x), pf(y), 'L', pf(xw) , pf(y), 'L', pf(xw), pf(yh),
  6771. 'L', pf(x), pf(yh), 'Z');
  6772. break;
  6773. case OPS.moveTo:
  6774. x = args[j++];
  6775. y = args[j++];
  6776. d.push('M', pf(x), pf(y));
  6777. break;
  6778. case OPS.lineTo:
  6779. x = args[j++];
  6780. y = args[j++];
  6781. d.push('L', pf(x) , pf(y));
  6782. break;
  6783. case OPS.curveTo:
  6784. x = args[j + 4];
  6785. y = args[j + 5];
  6786. d.push('C', pf(args[j]), pf(args[j + 1]), pf(args[j + 2]),
  6787. pf(args[j + 3]), pf(x), pf(y));
  6788. j += 6;
  6789. break;
  6790. case OPS.curveTo2:
  6791. x = args[j + 2];
  6792. y = args[j + 3];
  6793. d.push('C', pf(x), pf(y), pf(args[j]), pf(args[j + 1]),
  6794. pf(args[j + 2]), pf(args[j + 3]));
  6795. j += 4;
  6796. break;
  6797. case OPS.curveTo3:
  6798. x = args[j + 2];
  6799. y = args[j + 3];
  6800. d.push('C', pf(args[j]), pf(args[j + 1]), pf(x), pf(y),
  6801. pf(x), pf(y));
  6802. j += 4;
  6803. break;
  6804. case OPS.closePath:
  6805. d.push('Z');
  6806. break;
  6807. }
  6808. }
  6809. current.path.setAttributeNS(null, 'd', d.join(' '));
  6810. current.path.setAttributeNS(null, 'stroke-miterlimit',
  6811. pf(current.miterLimit));
  6812. current.path.setAttributeNS(null, 'stroke-linecap', current.lineCap);
  6813. current.path.setAttributeNS(null, 'stroke-linejoin', current.lineJoin);
  6814. current.path.setAttributeNS(null, 'stroke-width',
  6815. pf(current.lineWidth) + 'px');
  6816. current.path.setAttributeNS(null, 'stroke-dasharray',
  6817. current.dashArray.map(pf).join(' '));
  6818. current.path.setAttributeNS(null, 'stroke-dashoffset',
  6819. pf(current.dashPhase) + 'px');
  6820. current.path.setAttributeNS(null, 'fill', 'none');
  6821. this.tgrp.appendChild(current.path);
  6822. if (current.pendingClip) {
  6823. this.cgrp.appendChild(this.tgrp);
  6824. this.pgrp.appendChild(this.cgrp);
  6825. } else {
  6826. this.pgrp.appendChild(this.tgrp);
  6827. }
  6828. // Saving a reference in current.element so that it can be addressed
  6829. // in 'fill' and 'stroke'
  6830. current.element = current.path;
  6831. current.setCurrentPoint(x, y);
  6832. },
  6833. endPath: function SVGGraphics_endPath() {
  6834. var current = this.current;
  6835. if (current.pendingClip) {
  6836. this.cgrp.appendChild(this.tgrp);
  6837. this.pgrp.appendChild(this.cgrp);
  6838. } else {
  6839. this.pgrp.appendChild(this.tgrp);
  6840. }
  6841. this.tgrp = document.createElementNS(NS, 'svg:g');
  6842. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  6843. },
  6844. clip: function SVGGraphics_clip(type) {
  6845. var current = this.current;
  6846. // Add current path to clipping path
  6847. current.clipId = 'clippath' + clipCount;
  6848. clipCount++;
  6849. this.clippath = document.createElementNS(NS, 'svg:clipPath');
  6850. this.clippath.setAttributeNS(null, 'id', current.clipId);
  6851. var clipElement = current.element.cloneNode();
  6852. if (type === 'evenodd') {
  6853. clipElement.setAttributeNS(null, 'clip-rule', 'evenodd');
  6854. } else {
  6855. clipElement.setAttributeNS(null, 'clip-rule', 'nonzero');
  6856. }
  6857. this.clippath.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  6858. this.clippath.appendChild(clipElement);
  6859. this.defs.appendChild(this.clippath);
  6860. // Create a new group with that attribute
  6861. current.pendingClip = true;
  6862. this.cgrp = document.createElementNS(NS, 'svg:g');
  6863. this.cgrp.setAttributeNS(null, 'clip-path',
  6864. 'url(#' + current.clipId + ')');
  6865. this.pgrp.appendChild(this.cgrp);
  6866. },
  6867. closePath: function SVGGraphics_closePath() {
  6868. var current = this.current;
  6869. var d = current.path.getAttributeNS(null, 'd');
  6870. d += 'Z';
  6871. current.path.setAttributeNS(null, 'd', d);
  6872. },
  6873. setLeading: function SVGGraphics_setLeading(leading) {
  6874. this.current.leading = -leading;
  6875. },
  6876. setTextRise: function SVGGraphics_setTextRise(textRise) {
  6877. this.current.textRise = textRise;
  6878. },
  6879. setHScale: function SVGGraphics_setHScale(scale) {
  6880. this.current.textHScale = scale / 100;
  6881. },
  6882. setGState: function SVGGraphics_setGState(states) {
  6883. for (var i = 0, ii = states.length; i < ii; i++) {
  6884. var state = states[i];
  6885. var key = state[0];
  6886. var value = state[1];
  6887. switch (key) {
  6888. case 'LW':
  6889. this.setLineWidth(value);
  6890. break;
  6891. case 'LC':
  6892. this.setLineCap(value);
  6893. break;
  6894. case 'LJ':
  6895. this.setLineJoin(value);
  6896. break;
  6897. case 'ML':
  6898. this.setMiterLimit(value);
  6899. break;
  6900. case 'D':
  6901. this.setDash(value[0], value[1]);
  6902. break;
  6903. case 'RI':
  6904. break;
  6905. case 'FL':
  6906. break;
  6907. case 'Font':
  6908. this.setFont(value);
  6909. break;
  6910. case 'CA':
  6911. break;
  6912. case 'ca':
  6913. break;
  6914. case 'BM':
  6915. break;
  6916. case 'SMask':
  6917. break;
  6918. }
  6919. }
  6920. },
  6921. fill: function SVGGraphics_fill() {
  6922. var current = this.current;
  6923. current.element.setAttributeNS(null, 'fill', current.fillColor);
  6924. },
  6925. stroke: function SVGGraphics_stroke() {
  6926. var current = this.current;
  6927. current.element.setAttributeNS(null, 'stroke', current.strokeColor);
  6928. current.element.setAttributeNS(null, 'fill', 'none');
  6929. },
  6930. eoFill: function SVGGraphics_eoFill() {
  6931. var current = this.current;
  6932. current.element.setAttributeNS(null, 'fill', current.fillColor);
  6933. current.element.setAttributeNS(null, 'fill-rule', 'evenodd');
  6934. },
  6935. fillStroke: function SVGGraphics_fillStroke() {
  6936. // Order is important since stroke wants fill to be none.
  6937. // First stroke, then if fill needed, it will be overwritten.
  6938. this.stroke();
  6939. this.fill();
  6940. },
  6941. eoFillStroke: function SVGGraphics_eoFillStroke() {
  6942. this.current.element.setAttributeNS(null, 'fill-rule', 'evenodd');
  6943. this.fillStroke();
  6944. },
  6945. closeStroke: function SVGGraphics_closeStroke() {
  6946. this.closePath();
  6947. this.stroke();
  6948. },
  6949. closeFillStroke: function SVGGraphics_closeFillStroke() {
  6950. this.closePath();
  6951. this.fillStroke();
  6952. },
  6953. paintSolidColorImageMask:
  6954. function SVGGraphics_paintSolidColorImageMask() {
  6955. var current = this.current;
  6956. var rect = document.createElementNS(NS, 'svg:rect');
  6957. rect.setAttributeNS(null, 'x', '0');
  6958. rect.setAttributeNS(null, 'y', '0');
  6959. rect.setAttributeNS(null, 'width', '1px');
  6960. rect.setAttributeNS(null, 'height', '1px');
  6961. rect.setAttributeNS(null, 'fill', current.fillColor);
  6962. this.tgrp.appendChild(rect);
  6963. },
  6964. paintJpegXObject: function SVGGraphics_paintJpegXObject(objId, w, h) {
  6965. var current = this.current;
  6966. var imgObj = this.objs.get(objId);
  6967. var imgEl = document.createElementNS(NS, 'svg:image');
  6968. imgEl.setAttributeNS(XLINK_NS, 'xlink:href', imgObj.src);
  6969. imgEl.setAttributeNS(null, 'width', imgObj.width + 'px');
  6970. imgEl.setAttributeNS(null, 'height', imgObj.height + 'px');
  6971. imgEl.setAttributeNS(null, 'x', '0');
  6972. imgEl.setAttributeNS(null, 'y', pf(-h));
  6973. imgEl.setAttributeNS(null, 'transform',
  6974. 'scale(' + pf(1 / w) + ' ' + pf(-1 / h) + ')');
  6975. this.tgrp.appendChild(imgEl);
  6976. if (current.pendingClip) {
  6977. this.cgrp.appendChild(this.tgrp);
  6978. this.pgrp.appendChild(this.cgrp);
  6979. } else {
  6980. this.pgrp.appendChild(this.tgrp);
  6981. }
  6982. },
  6983. paintImageXObject: function SVGGraphics_paintImageXObject(objId) {
  6984. var imgData = this.objs.get(objId);
  6985. if (!imgData) {
  6986. warn('Dependent image isn\'t ready yet');
  6987. return;
  6988. }
  6989. this.paintInlineImageXObject(imgData);
  6990. },
  6991. paintInlineImageXObject:
  6992. function SVGGraphics_paintInlineImageXObject(imgData, mask) {
  6993. var current = this.current;
  6994. var width = imgData.width;
  6995. var height = imgData.height;
  6996. var imgSrc = convertImgDataToPng(imgData);
  6997. var cliprect = document.createElementNS(NS, 'svg:rect');
  6998. cliprect.setAttributeNS(null, 'x', '0');
  6999. cliprect.setAttributeNS(null, 'y', '0');
  7000. cliprect.setAttributeNS(null, 'width', pf(width));
  7001. cliprect.setAttributeNS(null, 'height', pf(height));
  7002. current.element = cliprect;
  7003. this.clip('nonzero');
  7004. var imgEl = document.createElementNS(NS, 'svg:image');
  7005. imgEl.setAttributeNS(XLINK_NS, 'xlink:href', imgSrc);
  7006. imgEl.setAttributeNS(null, 'x', '0');
  7007. imgEl.setAttributeNS(null, 'y', pf(-height));
  7008. imgEl.setAttributeNS(null, 'width', pf(width) + 'px');
  7009. imgEl.setAttributeNS(null, 'height', pf(height) + 'px');
  7010. imgEl.setAttributeNS(null, 'transform',
  7011. 'scale(' + pf(1 / width) + ' ' +
  7012. pf(-1 / height) + ')');
  7013. if (mask) {
  7014. mask.appendChild(imgEl);
  7015. } else {
  7016. this.tgrp.appendChild(imgEl);
  7017. }
  7018. if (current.pendingClip) {
  7019. this.cgrp.appendChild(this.tgrp);
  7020. this.pgrp.appendChild(this.cgrp);
  7021. } else {
  7022. this.pgrp.appendChild(this.tgrp);
  7023. }
  7024. },
  7025. paintImageMaskXObject:
  7026. function SVGGraphics_paintImageMaskXObject(imgData) {
  7027. var current = this.current;
  7028. var width = imgData.width;
  7029. var height = imgData.height;
  7030. var fillColor = current.fillColor;
  7031. current.maskId = 'mask' + maskCount++;
  7032. var mask = document.createElementNS(NS, 'svg:mask');
  7033. mask.setAttributeNS(null, 'id', current.maskId);
  7034. var rect = document.createElementNS(NS, 'svg:rect');
  7035. rect.setAttributeNS(null, 'x', '0');
  7036. rect.setAttributeNS(null, 'y', '0');
  7037. rect.setAttributeNS(null, 'width', pf(width));
  7038. rect.setAttributeNS(null, 'height', pf(height));
  7039. rect.setAttributeNS(null, 'fill', fillColor);
  7040. rect.setAttributeNS(null, 'mask', 'url(#' + current.maskId +')');
  7041. this.defs.appendChild(mask);
  7042. this.tgrp.appendChild(rect);
  7043. this.paintInlineImageXObject(imgData, mask);
  7044. },
  7045. paintFormXObjectBegin:
  7046. function SVGGraphics_paintFormXObjectBegin(matrix, bbox) {
  7047. this.save();
  7048. if (isArray(matrix) && matrix.length === 6) {
  7049. this.transform(matrix[0], matrix[1], matrix[2],
  7050. matrix[3], matrix[4], matrix[5]);
  7051. }
  7052. if (isArray(bbox) && bbox.length === 4) {
  7053. var width = bbox[2] - bbox[0];
  7054. var height = bbox[3] - bbox[1];
  7055. var cliprect = document.createElementNS(NS, 'svg:rect');
  7056. cliprect.setAttributeNS(null, 'x', bbox[0]);
  7057. cliprect.setAttributeNS(null, 'y', bbox[1]);
  7058. cliprect.setAttributeNS(null, 'width', pf(width));
  7059. cliprect.setAttributeNS(null, 'height', pf(height));
  7060. this.current.element = cliprect;
  7061. this.clip('nonzero');
  7062. this.endPath();
  7063. }
  7064. },
  7065. paintFormXObjectEnd:
  7066. function SVGGraphics_paintFormXObjectEnd() {
  7067. this.restore();
  7068. }
  7069. };
  7070. return SVGGraphics;
  7071. })();
  7072. PDFJS.SVGGraphics = SVGGraphics;
  7073. var NetworkManager = (function NetworkManagerClosure() {
  7074. var OK_RESPONSE = 200;
  7075. var PARTIAL_CONTENT_RESPONSE = 206;
  7076. function NetworkManager(url, args) {
  7077. this.url = url;
  7078. args = args || {};
  7079. this.isHttp = /^https?:/i.test(url);
  7080. this.httpHeaders = (this.isHttp && args.httpHeaders) || {};
  7081. this.withCredentials = args.withCredentials || false;
  7082. this.getXhr = args.getXhr ||
  7083. function NetworkManager_getXhr() {
  7084. return new XMLHttpRequest();
  7085. };
  7086. this.currXhrId = 0;
  7087. this.pendingRequests = {};
  7088. this.loadedRequests = {};
  7089. }
  7090. function getArrayBuffer(xhr) {
  7091. var data = xhr.response;
  7092. if (typeof data !== 'string') {
  7093. return data;
  7094. }
  7095. var length = data.length;
  7096. var array = new Uint8Array(length);
  7097. for (var i = 0; i < length; i++) {
  7098. array[i] = data.charCodeAt(i) & 0xFF;
  7099. }
  7100. return array.buffer;
  7101. }
  7102. NetworkManager.prototype = {
  7103. requestRange: function NetworkManager_requestRange(begin, end, listeners) {
  7104. var args = {
  7105. begin: begin,
  7106. end: end
  7107. };
  7108. for (var prop in listeners) {
  7109. args[prop] = listeners[prop];
  7110. }
  7111. return this.request(args);
  7112. },
  7113. requestFull: function NetworkManager_requestFull(listeners) {
  7114. return this.request(listeners);
  7115. },
  7116. request: function NetworkManager_request(args) {
  7117. var xhr = this.getXhr();
  7118. var xhrId = this.currXhrId++;
  7119. var pendingRequest = this.pendingRequests[xhrId] = {
  7120. xhr: xhr
  7121. };
  7122. xhr.open('GET', this.url);
  7123. xhr.withCredentials = this.withCredentials;
  7124. for (var property in this.httpHeaders) {
  7125. var value = this.httpHeaders[property];
  7126. if (typeof value === 'undefined') {
  7127. continue;
  7128. }
  7129. xhr.setRequestHeader(property, value);
  7130. }
  7131. if (this.isHttp && 'begin' in args && 'end' in args) {
  7132. var rangeStr = args.begin + '-' + (args.end - 1);
  7133. xhr.setRequestHeader('Range', 'bytes=' + rangeStr);
  7134. pendingRequest.expectedStatus = 206;
  7135. } else {
  7136. pendingRequest.expectedStatus = 200;
  7137. }
  7138. if (args.onProgressiveData) {
  7139. // Some legacy browsers might throw an exception.
  7140. try {
  7141. xhr.responseType = 'moz-chunked-arraybuffer';
  7142. } catch(e) {}
  7143. if (xhr.responseType === 'moz-chunked-arraybuffer') {
  7144. pendingRequest.onProgressiveData = args.onProgressiveData;
  7145. pendingRequest.mozChunked = true;
  7146. } else {
  7147. xhr.responseType = 'arraybuffer';
  7148. }
  7149. } else {
  7150. xhr.responseType = 'arraybuffer';
  7151. }
  7152. if (args.onError) {
  7153. xhr.onerror = function(evt) {
  7154. args.onError(xhr.status);
  7155. };
  7156. }
  7157. xhr.onreadystatechange = this.onStateChange.bind(this, xhrId);
  7158. xhr.onprogress = this.onProgress.bind(this, xhrId);
  7159. pendingRequest.onHeadersReceived = args.onHeadersReceived;
  7160. pendingRequest.onDone = args.onDone;
  7161. pendingRequest.onError = args.onError;
  7162. pendingRequest.onProgress = args.onProgress;
  7163. xhr.send(null);
  7164. return xhrId;
  7165. },
  7166. onProgress: function NetworkManager_onProgress(xhrId, evt) {
  7167. var pendingRequest = this.pendingRequests[xhrId];
  7168. if (!pendingRequest) {
  7169. // Maybe abortRequest was called...
  7170. return;
  7171. }
  7172. if (pendingRequest.mozChunked) {
  7173. var chunk = getArrayBuffer(pendingRequest.xhr);
  7174. pendingRequest.onProgressiveData(chunk);
  7175. }
  7176. var onProgress = pendingRequest.onProgress;
  7177. if (onProgress) {
  7178. onProgress(evt);
  7179. }
  7180. },
  7181. onStateChange: function NetworkManager_onStateChange(xhrId, evt) {
  7182. var pendingRequest = this.pendingRequests[xhrId];
  7183. if (!pendingRequest) {
  7184. // Maybe abortRequest was called...
  7185. return;
  7186. }
  7187. var xhr = pendingRequest.xhr;
  7188. if (xhr.readyState >= 2 && pendingRequest.onHeadersReceived) {
  7189. pendingRequest.onHeadersReceived();
  7190. delete pendingRequest.onHeadersReceived;
  7191. }
  7192. if (xhr.readyState !== 4) {
  7193. return;
  7194. }
  7195. if (!(xhrId in this.pendingRequests)) {
  7196. // The XHR request might have been aborted in onHeadersReceived()
  7197. // callback, in which case we should abort request
  7198. return;
  7199. }
  7200. delete this.pendingRequests[xhrId];
  7201. // success status == 0 can be on ftp, file and other protocols
  7202. if (xhr.status === 0 && this.isHttp) {
  7203. if (pendingRequest.onError) {
  7204. pendingRequest.onError(xhr.status);
  7205. }
  7206. return;
  7207. }
  7208. var xhrStatus = xhr.status || OK_RESPONSE;
  7209. // From http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35.2:
  7210. // "A server MAY ignore the Range header". This means it's possible to
  7211. // get a 200 rather than a 206 response from a range request.
  7212. var ok_response_on_range_request =
  7213. xhrStatus === OK_RESPONSE &&
  7214. pendingRequest.expectedStatus === PARTIAL_CONTENT_RESPONSE;
  7215. if (!ok_response_on_range_request &&
  7216. xhrStatus !== pendingRequest.expectedStatus) {
  7217. if (pendingRequest.onError) {
  7218. pendingRequest.onError(xhr.status);
  7219. }
  7220. return;
  7221. }
  7222. this.loadedRequests[xhrId] = true;
  7223. var chunk = getArrayBuffer(xhr);
  7224. if (xhrStatus === PARTIAL_CONTENT_RESPONSE) {
  7225. var rangeHeader = xhr.getResponseHeader('Content-Range');
  7226. var matches = /bytes (\d+)-(\d+)\/(\d+)/.exec(rangeHeader);
  7227. var begin = parseInt(matches[1], 10);
  7228. pendingRequest.onDone({
  7229. begin: begin,
  7230. chunk: chunk
  7231. });
  7232. } else if (pendingRequest.onProgressiveData) {
  7233. pendingRequest.onDone(null);
  7234. } else {
  7235. pendingRequest.onDone({
  7236. begin: 0,
  7237. chunk: chunk
  7238. });
  7239. }
  7240. },
  7241. hasPendingRequests: function NetworkManager_hasPendingRequests() {
  7242. for (var xhrId in this.pendingRequests) {
  7243. return true;
  7244. }
  7245. return false;
  7246. },
  7247. getRequestXhr: function NetworkManager_getXhr(xhrId) {
  7248. return this.pendingRequests[xhrId].xhr;
  7249. },
  7250. isStreamingRequest: function NetworkManager_isStreamingRequest(xhrId) {
  7251. return !!(this.pendingRequests[xhrId].onProgressiveData);
  7252. },
  7253. isPendingRequest: function NetworkManager_isPendingRequest(xhrId) {
  7254. return xhrId in this.pendingRequests;
  7255. },
  7256. isLoadedRequest: function NetworkManager_isLoadedRequest(xhrId) {
  7257. return xhrId in this.loadedRequests;
  7258. },
  7259. abortAllRequests: function NetworkManager_abortAllRequests() {
  7260. for (var xhrId in this.pendingRequests) {
  7261. this.abortRequest(xhrId | 0);
  7262. }
  7263. },
  7264. abortRequest: function NetworkManager_abortRequest(xhrId) {
  7265. var xhr = this.pendingRequests[xhrId].xhr;
  7266. delete this.pendingRequests[xhrId];
  7267. xhr.abort();
  7268. }
  7269. };
  7270. return NetworkManager;
  7271. })();
  7272. var ChunkedStream = (function ChunkedStreamClosure() {
  7273. function ChunkedStream(length, chunkSize, manager) {
  7274. this.bytes = new Uint8Array(length);
  7275. this.start = 0;
  7276. this.pos = 0;
  7277. this.end = length;
  7278. this.chunkSize = chunkSize;
  7279. this.loadedChunks = [];
  7280. this.numChunksLoaded = 0;
  7281. this.numChunks = Math.ceil(length / chunkSize);
  7282. this.manager = manager;
  7283. this.progressiveDataLength = 0;
  7284. this.lastSuccessfulEnsureByteChunk = -1; // a single-entry cache
  7285. }
  7286. // required methods for a stream. if a particular stream does not
  7287. // implement these, an error should be thrown
  7288. ChunkedStream.prototype = {
  7289. getMissingChunks: function ChunkedStream_getMissingChunks() {
  7290. var chunks = [];
  7291. for (var chunk = 0, n = this.numChunks; chunk < n; ++chunk) {
  7292. if (!this.loadedChunks[chunk]) {
  7293. chunks.push(chunk);
  7294. }
  7295. }
  7296. return chunks;
  7297. },
  7298. getBaseStreams: function ChunkedStream_getBaseStreams() {
  7299. return [this];
  7300. },
  7301. allChunksLoaded: function ChunkedStream_allChunksLoaded() {
  7302. return this.numChunksLoaded === this.numChunks;
  7303. },
  7304. onReceiveData: function ChunkedStream_onReceiveData(begin, chunk) {
  7305. var end = begin + chunk.byteLength;
  7306. assert(begin % this.chunkSize === 0, 'Bad begin offset: ' + begin);
  7307. // Using this.length is inaccurate here since this.start can be moved
  7308. // See ChunkedStream.moveStart()
  7309. var length = this.bytes.length;
  7310. assert(end % this.chunkSize === 0 || end === length,
  7311. 'Bad end offset: ' + end);
  7312. this.bytes.set(new Uint8Array(chunk), begin);
  7313. var chunkSize = this.chunkSize;
  7314. var beginChunk = Math.floor(begin / chunkSize);
  7315. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  7316. var curChunk;
  7317. for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  7318. if (!this.loadedChunks[curChunk]) {
  7319. this.loadedChunks[curChunk] = true;
  7320. ++this.numChunksLoaded;
  7321. }
  7322. }
  7323. },
  7324. onReceiveProgressiveData:
  7325. function ChunkedStream_onReceiveProgressiveData(data) {
  7326. var position = this.progressiveDataLength;
  7327. var beginChunk = Math.floor(position / this.chunkSize);
  7328. this.bytes.set(new Uint8Array(data), position);
  7329. position += data.byteLength;
  7330. this.progressiveDataLength = position;
  7331. var endChunk = position >= this.end ? this.numChunks :
  7332. Math.floor(position / this.chunkSize);
  7333. var curChunk;
  7334. for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  7335. if (!this.loadedChunks[curChunk]) {
  7336. this.loadedChunks[curChunk] = true;
  7337. ++this.numChunksLoaded;
  7338. }
  7339. }
  7340. },
  7341. ensureByte: function ChunkedStream_ensureByte(pos) {
  7342. var chunk = Math.floor(pos / this.chunkSize);
  7343. if (chunk === this.lastSuccessfulEnsureByteChunk) {
  7344. return;
  7345. }
  7346. if (!this.loadedChunks[chunk]) {
  7347. throw new MissingDataException(pos, pos + 1);
  7348. }
  7349. this.lastSuccessfulEnsureByteChunk = chunk;
  7350. },
  7351. ensureRange: function ChunkedStream_ensureRange(begin, end) {
  7352. if (begin >= end) {
  7353. return;
  7354. }
  7355. if (end <= this.progressiveDataLength) {
  7356. return;
  7357. }
  7358. var chunkSize = this.chunkSize;
  7359. var beginChunk = Math.floor(begin / chunkSize);
  7360. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  7361. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  7362. if (!this.loadedChunks[chunk]) {
  7363. throw new MissingDataException(begin, end);
  7364. }
  7365. }
  7366. },
  7367. nextEmptyChunk: function ChunkedStream_nextEmptyChunk(beginChunk) {
  7368. var chunk, n;
  7369. for (chunk = beginChunk, n = this.numChunks; chunk < n; ++chunk) {
  7370. if (!this.loadedChunks[chunk]) {
  7371. return chunk;
  7372. }
  7373. }
  7374. // Wrap around to beginning
  7375. for (chunk = 0; chunk < beginChunk; ++chunk) {
  7376. if (!this.loadedChunks[chunk]) {
  7377. return chunk;
  7378. }
  7379. }
  7380. return null;
  7381. },
  7382. hasChunk: function ChunkedStream_hasChunk(chunk) {
  7383. return !!this.loadedChunks[chunk];
  7384. },
  7385. get length() {
  7386. return this.end - this.start;
  7387. },
  7388. get isEmpty() {
  7389. return this.length === 0;
  7390. },
  7391. getByte: function ChunkedStream_getByte() {
  7392. var pos = this.pos;
  7393. if (pos >= this.end) {
  7394. return -1;
  7395. }
  7396. this.ensureByte(pos);
  7397. return this.bytes[this.pos++];
  7398. },
  7399. getUint16: function ChunkedStream_getUint16() {
  7400. var b0 = this.getByte();
  7401. var b1 = this.getByte();
  7402. if (b0 === -1 || b1 === -1) {
  7403. return -1;
  7404. }
  7405. return (b0 << 8) + b1;
  7406. },
  7407. getInt32: function ChunkedStream_getInt32() {
  7408. var b0 = this.getByte();
  7409. var b1 = this.getByte();
  7410. var b2 = this.getByte();
  7411. var b3 = this.getByte();
  7412. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  7413. },
  7414. // returns subarray of original buffer
  7415. // should only be read
  7416. getBytes: function ChunkedStream_getBytes(length) {
  7417. var bytes = this.bytes;
  7418. var pos = this.pos;
  7419. var strEnd = this.end;
  7420. if (!length) {
  7421. this.ensureRange(pos, strEnd);
  7422. return bytes.subarray(pos, strEnd);
  7423. }
  7424. var end = pos + length;
  7425. if (end > strEnd) {
  7426. end = strEnd;
  7427. }
  7428. this.ensureRange(pos, end);
  7429. this.pos = end;
  7430. return bytes.subarray(pos, end);
  7431. },
  7432. peekByte: function ChunkedStream_peekByte() {
  7433. var peekedByte = this.getByte();
  7434. this.pos--;
  7435. return peekedByte;
  7436. },
  7437. peekBytes: function ChunkedStream_peekBytes(length) {
  7438. var bytes = this.getBytes(length);
  7439. this.pos -= bytes.length;
  7440. return bytes;
  7441. },
  7442. getByteRange: function ChunkedStream_getBytes(begin, end) {
  7443. this.ensureRange(begin, end);
  7444. return this.bytes.subarray(begin, end);
  7445. },
  7446. skip: function ChunkedStream_skip(n) {
  7447. if (!n) {
  7448. n = 1;
  7449. }
  7450. this.pos += n;
  7451. },
  7452. reset: function ChunkedStream_reset() {
  7453. this.pos = this.start;
  7454. },
  7455. moveStart: function ChunkedStream_moveStart() {
  7456. this.start = this.pos;
  7457. },
  7458. makeSubStream: function ChunkedStream_makeSubStream(start, length, dict) {
  7459. this.ensureRange(start, start + length);
  7460. function ChunkedStreamSubstream() {}
  7461. ChunkedStreamSubstream.prototype = Object.create(this);
  7462. ChunkedStreamSubstream.prototype.getMissingChunks = function() {
  7463. var chunkSize = this.chunkSize;
  7464. var beginChunk = Math.floor(this.start / chunkSize);
  7465. var endChunk = Math.floor((this.end - 1) / chunkSize) + 1;
  7466. var missingChunks = [];
  7467. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  7468. if (!this.loadedChunks[chunk]) {
  7469. missingChunks.push(chunk);
  7470. }
  7471. }
  7472. return missingChunks;
  7473. };
  7474. var subStream = new ChunkedStreamSubstream();
  7475. subStream.pos = subStream.start = start;
  7476. subStream.end = start + length || this.end;
  7477. subStream.dict = dict;
  7478. return subStream;
  7479. },
  7480. isStream: true
  7481. };
  7482. return ChunkedStream;
  7483. })();
  7484. var ChunkedStreamManager = (function ChunkedStreamManagerClosure() {
  7485. function ChunkedStreamManager(length, chunkSize, url, args) {
  7486. this.stream = new ChunkedStream(length, chunkSize, this);
  7487. this.length = length;
  7488. this.chunkSize = chunkSize;
  7489. this.url = url;
  7490. this.disableAutoFetch = args.disableAutoFetch;
  7491. var msgHandler = this.msgHandler = args.msgHandler;
  7492. if (args.chunkedViewerLoading) {
  7493. msgHandler.on('OnDataRange', this.onReceiveData.bind(this));
  7494. msgHandler.on('OnDataProgress', this.onProgress.bind(this));
  7495. this.sendRequest = function ChunkedStreamManager_sendRequest(begin, end) {
  7496. msgHandler.send('RequestDataRange', { begin: begin, end: end });
  7497. };
  7498. } else {
  7499. var getXhr = function getXhr() {
  7500. return new XMLHttpRequest();
  7501. };
  7502. this.networkManager = new NetworkManager(this.url, {
  7503. getXhr: getXhr,
  7504. httpHeaders: args.httpHeaders,
  7505. withCredentials: args.withCredentials
  7506. });
  7507. this.sendRequest = function ChunkedStreamManager_sendRequest(begin, end) {
  7508. this.networkManager.requestRange(begin, end, {
  7509. onDone: this.onReceiveData.bind(this),
  7510. onProgress: this.onProgress.bind(this)
  7511. });
  7512. };
  7513. }
  7514. this.currRequestId = 0;
  7515. this.chunksNeededByRequest = {};
  7516. this.requestsByChunk = {};
  7517. this.callbacksByRequest = {};
  7518. this.progressiveDataLength = 0;
  7519. this._loadedStreamCapability = createPromiseCapability();
  7520. if (args.initialData) {
  7521. this.onReceiveData({chunk: args.initialData});
  7522. }
  7523. }
  7524. ChunkedStreamManager.prototype = {
  7525. onLoadedStream: function ChunkedStreamManager_getLoadedStream() {
  7526. return this._loadedStreamCapability.promise;
  7527. },
  7528. // Get all the chunks that are not yet loaded and groups them into
  7529. // contiguous ranges to load in as few requests as possible
  7530. requestAllChunks: function ChunkedStreamManager_requestAllChunks() {
  7531. var missingChunks = this.stream.getMissingChunks();
  7532. this.requestChunks(missingChunks);
  7533. return this._loadedStreamCapability.promise;
  7534. },
  7535. requestChunks: function ChunkedStreamManager_requestChunks(chunks,
  7536. callback) {
  7537. var requestId = this.currRequestId++;
  7538. var chunksNeeded;
  7539. var i, ii;
  7540. this.chunksNeededByRequest[requestId] = chunksNeeded = {};
  7541. for (i = 0, ii = chunks.length; i < ii; i++) {
  7542. if (!this.stream.hasChunk(chunks[i])) {
  7543. chunksNeeded[chunks[i]] = true;
  7544. }
  7545. }
  7546. if (isEmptyObj(chunksNeeded)) {
  7547. if (callback) {
  7548. callback();
  7549. }
  7550. return;
  7551. }
  7552. this.callbacksByRequest[requestId] = callback;
  7553. var chunksToRequest = [];
  7554. for (var chunk in chunksNeeded) {
  7555. chunk = chunk | 0;
  7556. if (!(chunk in this.requestsByChunk)) {
  7557. this.requestsByChunk[chunk] = [];
  7558. chunksToRequest.push(chunk);
  7559. }
  7560. this.requestsByChunk[chunk].push(requestId);
  7561. }
  7562. if (!chunksToRequest.length) {
  7563. return;
  7564. }
  7565. var groupedChunksToRequest = this.groupChunks(chunksToRequest);
  7566. for (i = 0; i < groupedChunksToRequest.length; ++i) {
  7567. var groupedChunk = groupedChunksToRequest[i];
  7568. var begin = groupedChunk.beginChunk * this.chunkSize;
  7569. var end = Math.min(groupedChunk.endChunk * this.chunkSize, this.length);
  7570. this.sendRequest(begin, end);
  7571. }
  7572. },
  7573. getStream: function ChunkedStreamManager_getStream() {
  7574. return this.stream;
  7575. },
  7576. // Loads any chunks in the requested range that are not yet loaded
  7577. requestRange: function ChunkedStreamManager_requestRange(
  7578. begin, end, callback) {
  7579. end = Math.min(end, this.length);
  7580. var beginChunk = this.getBeginChunk(begin);
  7581. var endChunk = this.getEndChunk(end);
  7582. var chunks = [];
  7583. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  7584. chunks.push(chunk);
  7585. }
  7586. this.requestChunks(chunks, callback);
  7587. },
  7588. requestRanges: function ChunkedStreamManager_requestRanges(ranges,
  7589. callback) {
  7590. ranges = ranges || [];
  7591. var chunksToRequest = [];
  7592. for (var i = 0; i < ranges.length; i++) {
  7593. var beginChunk = this.getBeginChunk(ranges[i].begin);
  7594. var endChunk = this.getEndChunk(ranges[i].end);
  7595. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  7596. if (chunksToRequest.indexOf(chunk) < 0) {
  7597. chunksToRequest.push(chunk);
  7598. }
  7599. }
  7600. }
  7601. chunksToRequest.sort(function(a, b) { return a - b; });
  7602. this.requestChunks(chunksToRequest, callback);
  7603. },
  7604. // Groups a sorted array of chunks into as few continguous larger
  7605. // chunks as possible
  7606. groupChunks: function ChunkedStreamManager_groupChunks(chunks) {
  7607. var groupedChunks = [];
  7608. var beginChunk = -1;
  7609. var prevChunk = -1;
  7610. for (var i = 0; i < chunks.length; ++i) {
  7611. var chunk = chunks[i];
  7612. if (beginChunk < 0) {
  7613. beginChunk = chunk;
  7614. }
  7615. if (prevChunk >= 0 && prevChunk + 1 !== chunk) {
  7616. groupedChunks.push({ beginChunk: beginChunk,
  7617. endChunk: prevChunk + 1 });
  7618. beginChunk = chunk;
  7619. }
  7620. if (i + 1 === chunks.length) {
  7621. groupedChunks.push({ beginChunk: beginChunk,
  7622. endChunk: chunk + 1 });
  7623. }
  7624. prevChunk = chunk;
  7625. }
  7626. return groupedChunks;
  7627. },
  7628. onProgress: function ChunkedStreamManager_onProgress(args) {
  7629. var bytesLoaded = (this.stream.numChunksLoaded * this.chunkSize +
  7630. args.loaded);
  7631. this.msgHandler.send('DocProgress', {
  7632. loaded: bytesLoaded,
  7633. total: this.length
  7634. });
  7635. },
  7636. onReceiveData: function ChunkedStreamManager_onReceiveData(args) {
  7637. var chunk = args.chunk;
  7638. var isProgressive = args.begin === undefined;
  7639. var begin = isProgressive ? this.progressiveDataLength : args.begin;
  7640. var end = begin + chunk.byteLength;
  7641. var beginChunk = Math.floor(begin / this.chunkSize);
  7642. var endChunk = end < this.length ? Math.floor(end / this.chunkSize) :
  7643. Math.ceil(end / this.chunkSize);
  7644. if (isProgressive) {
  7645. this.stream.onReceiveProgressiveData(chunk);
  7646. this.progressiveDataLength = end;
  7647. } else {
  7648. this.stream.onReceiveData(begin, chunk);
  7649. }
  7650. if (this.stream.allChunksLoaded()) {
  7651. this._loadedStreamCapability.resolve(this.stream);
  7652. }
  7653. var loadedRequests = [];
  7654. var i, requestId;
  7655. for (chunk = beginChunk; chunk < endChunk; ++chunk) {
  7656. // The server might return more chunks than requested
  7657. var requestIds = this.requestsByChunk[chunk] || [];
  7658. delete this.requestsByChunk[chunk];
  7659. for (i = 0; i < requestIds.length; ++i) {
  7660. requestId = requestIds[i];
  7661. var chunksNeeded = this.chunksNeededByRequest[requestId];
  7662. if (chunk in chunksNeeded) {
  7663. delete chunksNeeded[chunk];
  7664. }
  7665. if (!isEmptyObj(chunksNeeded)) {
  7666. continue;
  7667. }
  7668. loadedRequests.push(requestId);
  7669. }
  7670. }
  7671. // If there are no pending requests, automatically fetch the next
  7672. // unfetched chunk of the PDF
  7673. if (!this.disableAutoFetch && isEmptyObj(this.requestsByChunk)) {
  7674. var nextEmptyChunk;
  7675. if (this.stream.numChunksLoaded === 1) {
  7676. // This is a special optimization so that after fetching the first
  7677. // chunk, rather than fetching the second chunk, we fetch the last
  7678. // chunk.
  7679. var lastChunk = this.stream.numChunks - 1;
  7680. if (!this.stream.hasChunk(lastChunk)) {
  7681. nextEmptyChunk = lastChunk;
  7682. }
  7683. } else {
  7684. nextEmptyChunk = this.stream.nextEmptyChunk(endChunk);
  7685. }
  7686. if (isInt(nextEmptyChunk)) {
  7687. this.requestChunks([nextEmptyChunk]);
  7688. }
  7689. }
  7690. for (i = 0; i < loadedRequests.length; ++i) {
  7691. requestId = loadedRequests[i];
  7692. var callback = this.callbacksByRequest[requestId];
  7693. delete this.callbacksByRequest[requestId];
  7694. if (callback) {
  7695. callback();
  7696. }
  7697. }
  7698. this.msgHandler.send('DocProgress', {
  7699. loaded: this.stream.numChunksLoaded * this.chunkSize,
  7700. total: this.length
  7701. });
  7702. },
  7703. onError: function ChunkedStreamManager_onError(err) {
  7704. this._loadedStreamCapability.reject(err);
  7705. },
  7706. getBeginChunk: function ChunkedStreamManager_getBeginChunk(begin) {
  7707. var chunk = Math.floor(begin / this.chunkSize);
  7708. return chunk;
  7709. },
  7710. getEndChunk: function ChunkedStreamManager_getEndChunk(end) {
  7711. if (end % this.chunkSize === 0) {
  7712. return end / this.chunkSize;
  7713. }
  7714. // 0 -> 0
  7715. // 1 -> 1
  7716. // 99 -> 1
  7717. // 100 -> 1
  7718. // 101 -> 2
  7719. var chunk = Math.floor((end - 1) / this.chunkSize) + 1;
  7720. return chunk;
  7721. }
  7722. };
  7723. return ChunkedStreamManager;
  7724. })();
  7725. // The maximum number of bytes fetched per range request
  7726. var RANGE_CHUNK_SIZE = 65536;
  7727. // TODO(mack): Make use of PDFJS.Util.inherit() when it becomes available
  7728. var BasePdfManager = (function BasePdfManagerClosure() {
  7729. function BasePdfManager() {
  7730. throw new Error('Cannot initialize BaseManagerManager');
  7731. }
  7732. BasePdfManager.prototype = {
  7733. onLoadedStream: function BasePdfManager_onLoadedStream() {
  7734. throw new NotImplementedException();
  7735. },
  7736. ensureDoc: function BasePdfManager_ensureDoc(prop, args) {
  7737. return this.ensure(this.pdfDocument, prop, args);
  7738. },
  7739. ensureXRef: function BasePdfManager_ensureXRef(prop, args) {
  7740. return this.ensure(this.pdfDocument.xref, prop, args);
  7741. },
  7742. ensureCatalog: function BasePdfManager_ensureCatalog(prop, args) {
  7743. return this.ensure(this.pdfDocument.catalog, prop, args);
  7744. },
  7745. getPage: function BasePdfManager_pagePage(pageIndex) {
  7746. return this.pdfDocument.getPage(pageIndex);
  7747. },
  7748. cleanup: function BasePdfManager_cleanup() {
  7749. return this.pdfDocument.cleanup();
  7750. },
  7751. ensure: function BasePdfManager_ensure(obj, prop, args) {
  7752. return new NotImplementedException();
  7753. },
  7754. requestRange: function BasePdfManager_ensure(begin, end) {
  7755. return new NotImplementedException();
  7756. },
  7757. requestLoadedStream: function BasePdfManager_requestLoadedStream() {
  7758. return new NotImplementedException();
  7759. },
  7760. sendProgressiveData: function BasePdfManager_sendProgressiveData(chunk) {
  7761. return new NotImplementedException();
  7762. },
  7763. updatePassword: function BasePdfManager_updatePassword(password) {
  7764. this.pdfDocument.xref.password = this.password = password;
  7765. if (this._passwordChangedCapability) {
  7766. this._passwordChangedCapability.resolve();
  7767. }
  7768. },
  7769. passwordChanged: function BasePdfManager_passwordChanged() {
  7770. this._passwordChangedCapability = createPromiseCapability();
  7771. return this._passwordChangedCapability.promise;
  7772. },
  7773. terminate: function BasePdfManager_terminate() {
  7774. return new NotImplementedException();
  7775. }
  7776. };
  7777. return BasePdfManager;
  7778. })();
  7779. var LocalPdfManager = (function LocalPdfManagerClosure() {
  7780. function LocalPdfManager(data, password) {
  7781. var stream = new Stream(data);
  7782. this.pdfDocument = new PDFDocument(this, stream, password);
  7783. this._loadedStreamCapability = createPromiseCapability();
  7784. this._loadedStreamCapability.resolve(stream);
  7785. }
  7786. LocalPdfManager.prototype = Object.create(BasePdfManager.prototype);
  7787. LocalPdfManager.prototype.constructor = LocalPdfManager;
  7788. LocalPdfManager.prototype.ensure =
  7789. function LocalPdfManager_ensure(obj, prop, args) {
  7790. return new Promise(function (resolve, reject) {
  7791. try {
  7792. var value = obj[prop];
  7793. var result;
  7794. if (typeof value === 'function') {
  7795. result = value.apply(obj, args);
  7796. } else {
  7797. result = value;
  7798. }
  7799. resolve(result);
  7800. } catch (e) {
  7801. reject(e);
  7802. }
  7803. });
  7804. };
  7805. LocalPdfManager.prototype.requestRange =
  7806. function LocalPdfManager_requestRange(begin, end) {
  7807. return Promise.resolve();
  7808. };
  7809. LocalPdfManager.prototype.requestLoadedStream =
  7810. function LocalPdfManager_requestLoadedStream() {
  7811. };
  7812. LocalPdfManager.prototype.onLoadedStream =
  7813. function LocalPdfManager_getLoadedStream() {
  7814. return this._loadedStreamCapability.promise;
  7815. };
  7816. LocalPdfManager.prototype.terminate =
  7817. function LocalPdfManager_terminate() {
  7818. return;
  7819. };
  7820. return LocalPdfManager;
  7821. })();
  7822. var NetworkPdfManager = (function NetworkPdfManagerClosure() {
  7823. function NetworkPdfManager(args, msgHandler) {
  7824. this.msgHandler = msgHandler;
  7825. var params = {
  7826. msgHandler: msgHandler,
  7827. httpHeaders: args.httpHeaders,
  7828. withCredentials: args.withCredentials,
  7829. chunkedViewerLoading: args.chunkedViewerLoading,
  7830. disableAutoFetch: args.disableAutoFetch,
  7831. initialData: args.initialData
  7832. };
  7833. this.streamManager = new ChunkedStreamManager(args.length, RANGE_CHUNK_SIZE,
  7834. args.url, params);
  7835. this.pdfDocument = new PDFDocument(this, this.streamManager.getStream(),
  7836. args.password);
  7837. }
  7838. NetworkPdfManager.prototype = Object.create(BasePdfManager.prototype);
  7839. NetworkPdfManager.prototype.constructor = NetworkPdfManager;
  7840. NetworkPdfManager.prototype.ensure =
  7841. function NetworkPdfManager_ensure(obj, prop, args) {
  7842. var pdfManager = this;
  7843. return new Promise(function (resolve, reject) {
  7844. function ensureHelper() {
  7845. try {
  7846. var result;
  7847. var value = obj[prop];
  7848. if (typeof value === 'function') {
  7849. result = value.apply(obj, args);
  7850. } else {
  7851. result = value;
  7852. }
  7853. resolve(result);
  7854. } catch(e) {
  7855. if (!(e instanceof MissingDataException)) {
  7856. reject(e);
  7857. return;
  7858. }
  7859. pdfManager.streamManager.requestRange(e.begin, e.end, ensureHelper);
  7860. }
  7861. }
  7862. ensureHelper();
  7863. });
  7864. };
  7865. NetworkPdfManager.prototype.requestRange =
  7866. function NetworkPdfManager_requestRange(begin, end) {
  7867. return new Promise(function (resolve) {
  7868. this.streamManager.requestRange(begin, end, function() {
  7869. resolve();
  7870. });
  7871. }.bind(this));
  7872. };
  7873. NetworkPdfManager.prototype.requestLoadedStream =
  7874. function NetworkPdfManager_requestLoadedStream() {
  7875. this.streamManager.requestAllChunks();
  7876. };
  7877. NetworkPdfManager.prototype.sendProgressiveData =
  7878. function NetworkPdfManager_sendProgressiveData(chunk) {
  7879. this.streamManager.onReceiveData({ chunk: chunk });
  7880. };
  7881. NetworkPdfManager.prototype.onLoadedStream =
  7882. function NetworkPdfManager_getLoadedStream() {
  7883. return this.streamManager.onLoadedStream();
  7884. };
  7885. NetworkPdfManager.prototype.terminate =
  7886. function NetworkPdfManager_terminate() {
  7887. this.streamManager.networkManager.abortAllRequests();
  7888. };
  7889. return NetworkPdfManager;
  7890. })();
  7891. var Page = (function PageClosure() {
  7892. var LETTER_SIZE_MEDIABOX = [0, 0, 612, 792];
  7893. function Page(pdfManager, xref, pageIndex, pageDict, ref, fontCache) {
  7894. this.pdfManager = pdfManager;
  7895. this.pageIndex = pageIndex;
  7896. this.pageDict = pageDict;
  7897. this.xref = xref;
  7898. this.ref = ref;
  7899. this.fontCache = fontCache;
  7900. this.idCounters = {
  7901. obj: 0
  7902. };
  7903. this.resourcesPromise = null;
  7904. }
  7905. Page.prototype = {
  7906. getPageProp: function Page_getPageProp(key) {
  7907. return this.pageDict.get(key);
  7908. },
  7909. getInheritedPageProp: function Page_inheritPageProp(key) {
  7910. var dict = this.pageDict;
  7911. var value = dict.get(key);
  7912. while (value === undefined) {
  7913. dict = dict.get('Parent');
  7914. if (!dict) {
  7915. break;
  7916. }
  7917. value = dict.get(key);
  7918. }
  7919. return value;
  7920. },
  7921. get content() {
  7922. return this.getPageProp('Contents');
  7923. },
  7924. get resources() {
  7925. var value = this.getInheritedPageProp('Resources');
  7926. // For robustness: The spec states that a \Resources entry has to be
  7927. // present, but can be empty. Some document omit it still. In this case
  7928. // return an empty dictionary:
  7929. if (value === undefined) {
  7930. value = Dict.empty;
  7931. }
  7932. return shadow(this, 'resources', value);
  7933. },
  7934. get mediaBox() {
  7935. var obj = this.getInheritedPageProp('MediaBox');
  7936. // Reset invalid media box to letter size.
  7937. if (!isArray(obj) || obj.length !== 4) {
  7938. obj = LETTER_SIZE_MEDIABOX;
  7939. }
  7940. return shadow(this, 'mediaBox', obj);
  7941. },
  7942. get view() {
  7943. var mediaBox = this.mediaBox;
  7944. var cropBox = this.getInheritedPageProp('CropBox');
  7945. if (!isArray(cropBox) || cropBox.length !== 4) {
  7946. return shadow(this, 'view', mediaBox);
  7947. }
  7948. // From the spec, 6th ed., p.963:
  7949. // "The crop, bleed, trim, and art boxes should not ordinarily
  7950. // extend beyond the boundaries of the media box. If they do, they are
  7951. // effectively reduced to their intersection with the media box."
  7952. cropBox = Util.intersect(cropBox, mediaBox);
  7953. if (!cropBox) {
  7954. return shadow(this, 'view', mediaBox);
  7955. }
  7956. return shadow(this, 'view', cropBox);
  7957. },
  7958. get annotationRefs() {
  7959. return shadow(this, 'annotationRefs',
  7960. this.getInheritedPageProp('Annots'));
  7961. },
  7962. get rotate() {
  7963. var rotate = this.getInheritedPageProp('Rotate') || 0;
  7964. // Normalize rotation so it's a multiple of 90 and between 0 and 270
  7965. if (rotate % 90 !== 0) {
  7966. rotate = 0;
  7967. } else if (rotate >= 360) {
  7968. rotate = rotate % 360;
  7969. } else if (rotate < 0) {
  7970. // The spec doesn't cover negatives, assume its counterclockwise
  7971. // rotation. The following is the other implementation of modulo.
  7972. rotate = ((rotate % 360) + 360) % 360;
  7973. }
  7974. return shadow(this, 'rotate', rotate);
  7975. },
  7976. getContentStream: function Page_getContentStream() {
  7977. var content = this.content;
  7978. var stream;
  7979. if (isArray(content)) {
  7980. // fetching items
  7981. var xref = this.xref;
  7982. var i, n = content.length;
  7983. var streams = [];
  7984. for (i = 0; i < n; ++i) {
  7985. streams.push(xref.fetchIfRef(content[i]));
  7986. }
  7987. stream = new StreamsSequenceStream(streams);
  7988. } else if (isStream(content)) {
  7989. stream = content;
  7990. } else {
  7991. // replacing non-existent page content with empty one
  7992. stream = new NullStream();
  7993. }
  7994. return stream;
  7995. },
  7996. loadResources: function Page_loadResources(keys) {
  7997. if (!this.resourcesPromise) {
  7998. // TODO: add async getInheritedPageProp and remove this.
  7999. this.resourcesPromise = this.pdfManager.ensure(this, 'resources');
  8000. }
  8001. return this.resourcesPromise.then(function resourceSuccess() {
  8002. var objectLoader = new ObjectLoader(this.resources.map,
  8003. keys,
  8004. this.xref);
  8005. return objectLoader.load();
  8006. }.bind(this));
  8007. },
  8008. getOperatorList: function Page_getOperatorList(handler, intent) {
  8009. var self = this;
  8010. var pdfManager = this.pdfManager;
  8011. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
  8012. []);
  8013. var resourcesPromise = this.loadResources([
  8014. 'ExtGState',
  8015. 'ColorSpace',
  8016. 'Pattern',
  8017. 'Shading',
  8018. 'XObject',
  8019. 'Font'
  8020. // ProcSet
  8021. // Properties
  8022. ]);
  8023. var partialEvaluator = new PartialEvaluator(pdfManager, this.xref,
  8024. handler, this.pageIndex,
  8025. 'p' + this.pageIndex + '_',
  8026. this.idCounters,
  8027. this.fontCache);
  8028. var dataPromises = Promise.all([contentStreamPromise, resourcesPromise]);
  8029. var pageListPromise = dataPromises.then(function(data) {
  8030. var contentStream = data[0];
  8031. var opList = new OperatorList(intent, handler, self.pageIndex);
  8032. handler.send('StartRenderPage', {
  8033. transparency: partialEvaluator.hasBlendModes(self.resources),
  8034. pageIndex: self.pageIndex,
  8035. intent: intent
  8036. });
  8037. return partialEvaluator.getOperatorList(contentStream, self.resources,
  8038. opList).then(function () {
  8039. return opList;
  8040. });
  8041. });
  8042. var annotationsPromise = pdfManager.ensure(this, 'annotations');
  8043. return Promise.all([pageListPromise, annotationsPromise]).then(
  8044. function(datas) {
  8045. var pageOpList = datas[0];
  8046. var annotations = datas[1];
  8047. if (annotations.length === 0) {
  8048. pageOpList.flush(true);
  8049. return pageOpList;
  8050. }
  8051. var annotationsReadyPromise = Annotation.appendToOperatorList(
  8052. annotations, pageOpList, pdfManager, partialEvaluator, intent);
  8053. return annotationsReadyPromise.then(function () {
  8054. pageOpList.flush(true);
  8055. return pageOpList;
  8056. });
  8057. });
  8058. },
  8059. extractTextContent: function Page_extractTextContent() {
  8060. var handler = {
  8061. on: function nullHandlerOn() {},
  8062. send: function nullHandlerSend() {}
  8063. };
  8064. var self = this;
  8065. var pdfManager = this.pdfManager;
  8066. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
  8067. []);
  8068. var resourcesPromise = this.loadResources([
  8069. 'ExtGState',
  8070. 'XObject',
  8071. 'Font'
  8072. ]);
  8073. var dataPromises = Promise.all([contentStreamPromise,
  8074. resourcesPromise]);
  8075. return dataPromises.then(function(data) {
  8076. var contentStream = data[0];
  8077. var partialEvaluator = new PartialEvaluator(pdfManager, self.xref,
  8078. handler, self.pageIndex,
  8079. 'p' + self.pageIndex + '_',
  8080. self.idCounters,
  8081. self.fontCache);
  8082. return partialEvaluator.getTextContent(contentStream,
  8083. self.resources);
  8084. });
  8085. },
  8086. getAnnotationsData: function Page_getAnnotationsData() {
  8087. var annotations = this.annotations;
  8088. var annotationsData = [];
  8089. for (var i = 0, n = annotations.length; i < n; ++i) {
  8090. annotationsData.push(annotations[i].getData());
  8091. }
  8092. return annotationsData;
  8093. },
  8094. get annotations() {
  8095. var annotations = [];
  8096. var annotationRefs = (this.annotationRefs || []);
  8097. for (var i = 0, n = annotationRefs.length; i < n; ++i) {
  8098. var annotationRef = annotationRefs[i];
  8099. var annotation = Annotation.fromRef(this.xref, annotationRef);
  8100. if (annotation) {
  8101. annotations.push(annotation);
  8102. }
  8103. }
  8104. return shadow(this, 'annotations', annotations);
  8105. }
  8106. };
  8107. return Page;
  8108. })();
  8109. /**
  8110. * The `PDFDocument` holds all the data of the PDF file. Compared to the
  8111. * `PDFDoc`, this one doesn't have any job management code.
  8112. * Right now there exists one PDFDocument on the main thread + one object
  8113. * for each worker. If there is no worker support enabled, there are two
  8114. * `PDFDocument` objects on the main thread created.
  8115. */
  8116. var PDFDocument = (function PDFDocumentClosure() {
  8117. var FINGERPRINT_FIRST_BYTES = 1024;
  8118. var EMPTY_FINGERPRINT = '\x00\x00\x00\x00\x00\x00\x00' +
  8119. '\x00\x00\x00\x00\x00\x00\x00\x00\x00';
  8120. function PDFDocument(pdfManager, arg, password) {
  8121. if (isStream(arg)) {
  8122. init.call(this, pdfManager, arg, password);
  8123. } else if (isArrayBuffer(arg)) {
  8124. init.call(this, pdfManager, new Stream(arg), password);
  8125. } else {
  8126. error('PDFDocument: Unknown argument type');
  8127. }
  8128. }
  8129. function init(pdfManager, stream, password) {
  8130. assert(stream.length > 0, 'stream must have data');
  8131. this.pdfManager = pdfManager;
  8132. this.stream = stream;
  8133. var xref = new XRef(this.stream, password, pdfManager);
  8134. this.xref = xref;
  8135. }
  8136. function find(stream, needle, limit, backwards) {
  8137. var pos = stream.pos;
  8138. var end = stream.end;
  8139. var strBuf = [];
  8140. if (pos + limit > end) {
  8141. limit = end - pos;
  8142. }
  8143. for (var n = 0; n < limit; ++n) {
  8144. strBuf.push(String.fromCharCode(stream.getByte()));
  8145. }
  8146. var str = strBuf.join('');
  8147. stream.pos = pos;
  8148. var index = backwards ? str.lastIndexOf(needle) : str.indexOf(needle);
  8149. if (index === -1) {
  8150. return false; /* not found */
  8151. }
  8152. stream.pos += index;
  8153. return true; /* found */
  8154. }
  8155. var DocumentInfoValidators = {
  8156. get entries() {
  8157. // Lazily build this since all the validation functions below are not
  8158. // defined until after this file loads.
  8159. return shadow(this, 'entries', {
  8160. Title: isString,
  8161. Author: isString,
  8162. Subject: isString,
  8163. Keywords: isString,
  8164. Creator: isString,
  8165. Producer: isString,
  8166. CreationDate: isString,
  8167. ModDate: isString,
  8168. Trapped: isName
  8169. });
  8170. }
  8171. };
  8172. PDFDocument.prototype = {
  8173. parse: function PDFDocument_parse(recoveryMode) {
  8174. this.setup(recoveryMode);
  8175. try {
  8176. // checking if AcroForm is present
  8177. this.acroForm = this.catalog.catDict.get('AcroForm');
  8178. if (this.acroForm) {
  8179. this.xfa = this.acroForm.get('XFA');
  8180. var fields = this.acroForm.get('Fields');
  8181. if ((!fields || !isArray(fields) || fields.length === 0) &&
  8182. !this.xfa) {
  8183. // no fields and no XFA -- not a form (?)
  8184. this.acroForm = null;
  8185. }
  8186. }
  8187. } catch (ex) {
  8188. info('Something wrong with AcroForm entry');
  8189. this.acroForm = null;
  8190. }
  8191. },
  8192. get linearization() {
  8193. var linearization = null;
  8194. if (this.stream.length) {
  8195. try {
  8196. linearization = Linearization.create(this.stream);
  8197. } catch (err) {
  8198. if (err instanceof MissingDataException) {
  8199. throw err;
  8200. }
  8201. info(err);
  8202. }
  8203. }
  8204. // shadow the prototype getter with a data property
  8205. return shadow(this, 'linearization', linearization);
  8206. },
  8207. get startXRef() {
  8208. var stream = this.stream;
  8209. var startXRef = 0;
  8210. var linearization = this.linearization;
  8211. if (linearization) {
  8212. // Find end of first obj.
  8213. stream.reset();
  8214. if (find(stream, 'endobj', 1024)) {
  8215. startXRef = stream.pos + 6;
  8216. }
  8217. } else {
  8218. // Find startxref by jumping backward from the end of the file.
  8219. var step = 1024;
  8220. var found = false, pos = stream.end;
  8221. while (!found && pos > 0) {
  8222. pos -= step - 'startxref'.length;
  8223. if (pos < 0) {
  8224. pos = 0;
  8225. }
  8226. stream.pos = pos;
  8227. found = find(stream, 'startxref', step, true);
  8228. }
  8229. if (found) {
  8230. stream.skip(9);
  8231. var ch;
  8232. do {
  8233. ch = stream.getByte();
  8234. } while (Lexer.isSpace(ch));
  8235. var str = '';
  8236. while (ch >= 0x20 && ch <= 0x39) { // < '9'
  8237. str += String.fromCharCode(ch);
  8238. ch = stream.getByte();
  8239. }
  8240. startXRef = parseInt(str, 10);
  8241. if (isNaN(startXRef)) {
  8242. startXRef = 0;
  8243. }
  8244. }
  8245. }
  8246. // shadow the prototype getter with a data property
  8247. return shadow(this, 'startXRef', startXRef);
  8248. },
  8249. get mainXRefEntriesOffset() {
  8250. var mainXRefEntriesOffset = 0;
  8251. var linearization = this.linearization;
  8252. if (linearization) {
  8253. mainXRefEntriesOffset = linearization.mainXRefEntriesOffset;
  8254. }
  8255. // shadow the prototype getter with a data property
  8256. return shadow(this, 'mainXRefEntriesOffset', mainXRefEntriesOffset);
  8257. },
  8258. // Find the header, remove leading garbage and setup the stream
  8259. // starting from the header.
  8260. checkHeader: function PDFDocument_checkHeader() {
  8261. var stream = this.stream;
  8262. stream.reset();
  8263. if (find(stream, '%PDF-', 1024)) {
  8264. // Found the header, trim off any garbage before it.
  8265. stream.moveStart();
  8266. // Reading file format version
  8267. var MAX_VERSION_LENGTH = 12;
  8268. var version = '', ch;
  8269. while ((ch = stream.getByte()) > 0x20) { // SPACE
  8270. if (version.length >= MAX_VERSION_LENGTH) {
  8271. break;
  8272. }
  8273. version += String.fromCharCode(ch);
  8274. }
  8275. // removing "%PDF-"-prefix
  8276. this.pdfFormatVersion = version.substring(5);
  8277. return;
  8278. }
  8279. // May not be a PDF file, continue anyway.
  8280. },
  8281. parseStartXRef: function PDFDocument_parseStartXRef() {
  8282. var startXRef = this.startXRef;
  8283. this.xref.setStartXRef(startXRef);
  8284. },
  8285. setup: function PDFDocument_setup(recoveryMode) {
  8286. this.xref.parse(recoveryMode);
  8287. this.catalog = new Catalog(this.pdfManager, this.xref);
  8288. },
  8289. get numPages() {
  8290. var linearization = this.linearization;
  8291. var num = linearization ? linearization.numPages : this.catalog.numPages;
  8292. // shadow the prototype getter
  8293. return shadow(this, 'numPages', num);
  8294. },
  8295. get documentInfo() {
  8296. var docInfo = {
  8297. PDFFormatVersion: this.pdfFormatVersion,
  8298. IsAcroFormPresent: !!this.acroForm,
  8299. IsXFAPresent: !!this.xfa
  8300. };
  8301. var infoDict;
  8302. try {
  8303. infoDict = this.xref.trailer.get('Info');
  8304. } catch (err) {
  8305. info('The document information dictionary is invalid.');
  8306. }
  8307. if (infoDict) {
  8308. var validEntries = DocumentInfoValidators.entries;
  8309. // Only fill the document info with valid entries from the spec.
  8310. for (var key in validEntries) {
  8311. if (infoDict.has(key)) {
  8312. var value = infoDict.get(key);
  8313. // Make sure the value conforms to the spec.
  8314. if (validEntries[key](value)) {
  8315. docInfo[key] = (typeof value !== 'string' ?
  8316. value : stringToPDFString(value));
  8317. } else {
  8318. info('Bad value in document info for "' + key + '"');
  8319. }
  8320. }
  8321. }
  8322. }
  8323. return shadow(this, 'documentInfo', docInfo);
  8324. },
  8325. get fingerprint() {
  8326. var xref = this.xref, idArray, hash, fileID = '';
  8327. if (xref.trailer.has('ID')) {
  8328. idArray = xref.trailer.get('ID');
  8329. }
  8330. if (idArray && isArray(idArray) && idArray[0] !== EMPTY_FINGERPRINT) {
  8331. hash = stringToBytes(idArray[0]);
  8332. } else {
  8333. if (this.stream.ensureRange) {
  8334. this.stream.ensureRange(0,
  8335. Math.min(FINGERPRINT_FIRST_BYTES, this.stream.end));
  8336. }
  8337. hash = calculateMD5(this.stream.bytes.subarray(0,
  8338. FINGERPRINT_FIRST_BYTES), 0, FINGERPRINT_FIRST_BYTES);
  8339. }
  8340. for (var i = 0, n = hash.length; i < n; i++) {
  8341. var hex = hash[i].toString(16);
  8342. fileID += hex.length === 1 ? '0' + hex : hex;
  8343. }
  8344. return shadow(this, 'fingerprint', fileID);
  8345. },
  8346. getPage: function PDFDocument_getPage(pageIndex) {
  8347. return this.catalog.getPage(pageIndex);
  8348. },
  8349. cleanup: function PDFDocument_cleanup() {
  8350. return this.catalog.cleanup();
  8351. }
  8352. };
  8353. return PDFDocument;
  8354. })();
  8355. var Name = (function NameClosure() {
  8356. function Name(name) {
  8357. this.name = name;
  8358. }
  8359. Name.prototype = {};
  8360. var nameCache = {};
  8361. Name.get = function Name_get(name) {
  8362. var nameValue = nameCache[name];
  8363. return (nameValue ? nameValue : (nameCache[name] = new Name(name)));
  8364. };
  8365. return Name;
  8366. })();
  8367. var Cmd = (function CmdClosure() {
  8368. function Cmd(cmd) {
  8369. this.cmd = cmd;
  8370. }
  8371. Cmd.prototype = {};
  8372. var cmdCache = {};
  8373. Cmd.get = function Cmd_get(cmd) {
  8374. var cmdValue = cmdCache[cmd];
  8375. return (cmdValue ? cmdValue : (cmdCache[cmd] = new Cmd(cmd)));
  8376. };
  8377. return Cmd;
  8378. })();
  8379. var Dict = (function DictClosure() {
  8380. var nonSerializable = function nonSerializableClosure() {
  8381. return nonSerializable; // creating closure on some variable
  8382. };
  8383. var GETALL_DICTIONARY_TYPES_WHITELIST = {
  8384. 'Background': true,
  8385. 'ExtGState': true,
  8386. 'Halftone': true,
  8387. 'Layout': true,
  8388. 'Mask': true,
  8389. 'Pagination': true,
  8390. 'Printing': true
  8391. };
  8392. function isRecursionAllowedFor(dict) {
  8393. if (!isName(dict.Type)) {
  8394. return true;
  8395. }
  8396. var dictType = dict.Type.name;
  8397. return GETALL_DICTIONARY_TYPES_WHITELIST[dictType] === true;
  8398. }
  8399. // xref is optional
  8400. function Dict(xref) {
  8401. // Map should only be used internally, use functions below to access.
  8402. this.map = Object.create(null);
  8403. this.xref = xref;
  8404. this.objId = null;
  8405. this.__nonSerializable__ = nonSerializable; // disable cloning of the Dict
  8406. }
  8407. Dict.prototype = {
  8408. assignXref: function Dict_assignXref(newXref) {
  8409. this.xref = newXref;
  8410. },
  8411. // automatically dereferences Ref objects
  8412. get: function Dict_get(key1, key2, key3) {
  8413. var value;
  8414. var xref = this.xref;
  8415. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
  8416. typeof key2 === 'undefined') {
  8417. return xref ? xref.fetchIfRef(value) : value;
  8418. }
  8419. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
  8420. typeof key3 === 'undefined') {
  8421. return xref ? xref.fetchIfRef(value) : value;
  8422. }
  8423. value = this.map[key3] || null;
  8424. return xref ? xref.fetchIfRef(value) : value;
  8425. },
  8426. // Same as get(), but returns a promise and uses fetchIfRefAsync().
  8427. getAsync: function Dict_getAsync(key1, key2, key3) {
  8428. var value;
  8429. var xref = this.xref;
  8430. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
  8431. typeof key2 === 'undefined') {
  8432. if (xref) {
  8433. return xref.fetchIfRefAsync(value);
  8434. }
  8435. return Promise.resolve(value);
  8436. }
  8437. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
  8438. typeof key3 === 'undefined') {
  8439. if (xref) {
  8440. return xref.fetchIfRefAsync(value);
  8441. }
  8442. return Promise.resolve(value);
  8443. }
  8444. value = this.map[key3] || null;
  8445. if (xref) {
  8446. return xref.fetchIfRefAsync(value);
  8447. }
  8448. return Promise.resolve(value);
  8449. },
  8450. // no dereferencing
  8451. getRaw: function Dict_getRaw(key) {
  8452. return this.map[key];
  8453. },
  8454. // creates new map and dereferences all Refs
  8455. getAll: function Dict_getAll() {
  8456. var all = Object.create(null);
  8457. var queue = null;
  8458. var key, obj;
  8459. for (key in this.map) {
  8460. obj = this.get(key);
  8461. if (obj instanceof Dict) {
  8462. if (isRecursionAllowedFor(obj)) {
  8463. (queue || (queue = [])).push({target: all, key: key, obj: obj});
  8464. } else {
  8465. all[key] = this.getRaw(key);
  8466. }
  8467. } else {
  8468. all[key] = obj;
  8469. }
  8470. }
  8471. if (!queue) {
  8472. return all;
  8473. }
  8474. // trying to take cyclic references into the account
  8475. var processed = Object.create(null);
  8476. while (queue.length > 0) {
  8477. var item = queue.shift();
  8478. var itemObj = item.obj;
  8479. var objId = itemObj.objId;
  8480. if (objId && objId in processed) {
  8481. item.target[item.key] = processed[objId];
  8482. continue;
  8483. }
  8484. var dereferenced = Object.create(null);
  8485. for (key in itemObj.map) {
  8486. obj = itemObj.get(key);
  8487. if (obj instanceof Dict) {
  8488. if (isRecursionAllowedFor(obj)) {
  8489. queue.push({target: dereferenced, key: key, obj: obj});
  8490. } else {
  8491. dereferenced[key] = itemObj.getRaw(key);
  8492. }
  8493. } else {
  8494. dereferenced[key] = obj;
  8495. }
  8496. }
  8497. if (objId) {
  8498. processed[objId] = dereferenced;
  8499. }
  8500. item.target[item.key] = dereferenced;
  8501. }
  8502. return all;
  8503. },
  8504. getKeys: function Dict_getKeys() {
  8505. return Object.keys(this.map);
  8506. },
  8507. set: function Dict_set(key, value) {
  8508. this.map[key] = value;
  8509. },
  8510. has: function Dict_has(key) {
  8511. return key in this.map;
  8512. },
  8513. forEach: function Dict_forEach(callback) {
  8514. for (var key in this.map) {
  8515. callback(key, this.get(key));
  8516. }
  8517. }
  8518. };
  8519. Dict.empty = new Dict(null);
  8520. return Dict;
  8521. })();
  8522. var Ref = (function RefClosure() {
  8523. function Ref(num, gen) {
  8524. this.num = num;
  8525. this.gen = gen;
  8526. }
  8527. Ref.prototype = {
  8528. toString: function Ref_toString() {
  8529. // This function is hot, so we make the string as compact as possible.
  8530. // |this.gen| is almost always zero, so we treat that case specially.
  8531. var str = this.num + 'R';
  8532. if (this.gen !== 0) {
  8533. str += this.gen;
  8534. }
  8535. return str;
  8536. }
  8537. };
  8538. return Ref;
  8539. })();
  8540. // The reference is identified by number and generation.
  8541. // This structure stores only one instance of the reference.
  8542. var RefSet = (function RefSetClosure() {
  8543. function RefSet() {
  8544. this.dict = {};
  8545. }
  8546. RefSet.prototype = {
  8547. has: function RefSet_has(ref) {
  8548. return ref.toString() in this.dict;
  8549. },
  8550. put: function RefSet_put(ref) {
  8551. this.dict[ref.toString()] = true;
  8552. },
  8553. remove: function RefSet_remove(ref) {
  8554. delete this.dict[ref.toString()];
  8555. }
  8556. };
  8557. return RefSet;
  8558. })();
  8559. var RefSetCache = (function RefSetCacheClosure() {
  8560. function RefSetCache() {
  8561. this.dict = Object.create(null);
  8562. }
  8563. RefSetCache.prototype = {
  8564. get: function RefSetCache_get(ref) {
  8565. return this.dict[ref.toString()];
  8566. },
  8567. has: function RefSetCache_has(ref) {
  8568. return ref.toString() in this.dict;
  8569. },
  8570. put: function RefSetCache_put(ref, obj) {
  8571. this.dict[ref.toString()] = obj;
  8572. },
  8573. putAlias: function RefSetCache_putAlias(ref, aliasRef) {
  8574. this.dict[ref.toString()] = this.get(aliasRef);
  8575. },
  8576. forEach: function RefSetCache_forEach(fn, thisArg) {
  8577. for (var i in this.dict) {
  8578. fn.call(thisArg, this.dict[i]);
  8579. }
  8580. },
  8581. clear: function RefSetCache_clear() {
  8582. this.dict = Object.create(null);
  8583. }
  8584. };
  8585. return RefSetCache;
  8586. })();
  8587. var Catalog = (function CatalogClosure() {
  8588. function Catalog(pdfManager, xref) {
  8589. this.pdfManager = pdfManager;
  8590. this.xref = xref;
  8591. this.catDict = xref.getCatalogObj();
  8592. this.fontCache = new RefSetCache();
  8593. assert(isDict(this.catDict),
  8594. 'catalog object is not a dictionary');
  8595. this.pagePromises = [];
  8596. }
  8597. Catalog.prototype = {
  8598. get metadata() {
  8599. var streamRef = this.catDict.getRaw('Metadata');
  8600. if (!isRef(streamRef)) {
  8601. return shadow(this, 'metadata', null);
  8602. }
  8603. var encryptMetadata = (!this.xref.encrypt ? false :
  8604. this.xref.encrypt.encryptMetadata);
  8605. var stream = this.xref.fetch(streamRef, !encryptMetadata);
  8606. var metadata;
  8607. if (stream && isDict(stream.dict)) {
  8608. var type = stream.dict.get('Type');
  8609. var subtype = stream.dict.get('Subtype');
  8610. if (isName(type) && isName(subtype) &&
  8611. type.name === 'Metadata' && subtype.name === 'XML') {
  8612. // XXX: This should examine the charset the XML document defines,
  8613. // however since there are currently no real means to decode
  8614. // arbitrary charsets, let's just hope that the author of the PDF
  8615. // was reasonable enough to stick with the XML default charset,
  8616. // which is UTF-8.
  8617. try {
  8618. metadata = stringToUTF8String(bytesToString(stream.getBytes()));
  8619. } catch (e) {
  8620. info('Skipping invalid metadata.');
  8621. }
  8622. }
  8623. }
  8624. return shadow(this, 'metadata', metadata);
  8625. },
  8626. get toplevelPagesDict() {
  8627. var pagesObj = this.catDict.get('Pages');
  8628. assert(isDict(pagesObj), 'invalid top-level pages dictionary');
  8629. // shadow the prototype getter
  8630. return shadow(this, 'toplevelPagesDict', pagesObj);
  8631. },
  8632. get documentOutline() {
  8633. var obj = null;
  8634. try {
  8635. obj = this.readDocumentOutline();
  8636. } catch (ex) {
  8637. if (ex instanceof MissingDataException) {
  8638. throw ex;
  8639. }
  8640. warn('Unable to read document outline');
  8641. }
  8642. return shadow(this, 'documentOutline', obj);
  8643. },
  8644. readDocumentOutline: function Catalog_readDocumentOutline() {
  8645. var xref = this.xref;
  8646. var obj = this.catDict.get('Outlines');
  8647. var root = { items: [] };
  8648. if (isDict(obj)) {
  8649. obj = obj.getRaw('First');
  8650. var processed = new RefSet();
  8651. if (isRef(obj)) {
  8652. var queue = [{obj: obj, parent: root}];
  8653. // to avoid recursion keeping track of the items
  8654. // in the processed dictionary
  8655. processed.put(obj);
  8656. while (queue.length > 0) {
  8657. var i = queue.shift();
  8658. var outlineDict = xref.fetchIfRef(i.obj);
  8659. if (outlineDict === null) {
  8660. continue;
  8661. }
  8662. if (!outlineDict.has('Title')) {
  8663. error('Invalid outline item');
  8664. }
  8665. var dest = outlineDict.get('A');
  8666. if (dest) {
  8667. dest = dest.get('D');
  8668. } else if (outlineDict.has('Dest')) {
  8669. dest = outlineDict.getRaw('Dest');
  8670. if (isName(dest)) {
  8671. dest = dest.name;
  8672. }
  8673. }
  8674. var title = outlineDict.get('Title');
  8675. var outlineItem = {
  8676. dest: dest,
  8677. title: stringToPDFString(title),
  8678. color: outlineDict.get('C') || [0, 0, 0],
  8679. count: outlineDict.get('Count'),
  8680. bold: !!(outlineDict.get('F') & 2),
  8681. italic: !!(outlineDict.get('F') & 1),
  8682. items: []
  8683. };
  8684. i.parent.items.push(outlineItem);
  8685. obj = outlineDict.getRaw('First');
  8686. if (isRef(obj) && !processed.has(obj)) {
  8687. queue.push({obj: obj, parent: outlineItem});
  8688. processed.put(obj);
  8689. }
  8690. obj = outlineDict.getRaw('Next');
  8691. if (isRef(obj) && !processed.has(obj)) {
  8692. queue.push({obj: obj, parent: i.parent});
  8693. processed.put(obj);
  8694. }
  8695. }
  8696. }
  8697. }
  8698. return (root.items.length > 0 ? root.items : null);
  8699. },
  8700. get numPages() {
  8701. var obj = this.toplevelPagesDict.get('Count');
  8702. assert(
  8703. isInt(obj),
  8704. 'page count in top level pages object is not an integer'
  8705. );
  8706. // shadow the prototype getter
  8707. return shadow(this, 'num', obj);
  8708. },
  8709. get destinations() {
  8710. function fetchDestination(dest) {
  8711. return isDict(dest) ? dest.get('D') : dest;
  8712. }
  8713. var xref = this.xref;
  8714. var dests = {}, nameTreeRef, nameDictionaryRef;
  8715. var obj = this.catDict.get('Names');
  8716. if (obj && obj.has('Dests')) {
  8717. nameTreeRef = obj.getRaw('Dests');
  8718. } else if (this.catDict.has('Dests')) {
  8719. nameDictionaryRef = this.catDict.get('Dests');
  8720. }
  8721. if (nameDictionaryRef) {
  8722. // reading simple destination dictionary
  8723. obj = nameDictionaryRef;
  8724. obj.forEach(function catalogForEach(key, value) {
  8725. if (!value) {
  8726. return;
  8727. }
  8728. dests[key] = fetchDestination(value);
  8729. });
  8730. }
  8731. if (nameTreeRef) {
  8732. var nameTree = new NameTree(nameTreeRef, xref);
  8733. var names = nameTree.getAll();
  8734. for (var name in names) {
  8735. if (!names.hasOwnProperty(name)) {
  8736. continue;
  8737. }
  8738. dests[name] = fetchDestination(names[name]);
  8739. }
  8740. }
  8741. return shadow(this, 'destinations', dests);
  8742. },
  8743. getDestination: function Catalog_getDestination(destinationId) {
  8744. function fetchDestination(dest) {
  8745. return isDict(dest) ? dest.get('D') : dest;
  8746. }
  8747. var xref = this.xref;
  8748. var dest, nameTreeRef, nameDictionaryRef;
  8749. var obj = this.catDict.get('Names');
  8750. if (obj && obj.has('Dests')) {
  8751. nameTreeRef = obj.getRaw('Dests');
  8752. } else if (this.catDict.has('Dests')) {
  8753. nameDictionaryRef = this.catDict.get('Dests');
  8754. }
  8755. if (nameDictionaryRef) {
  8756. // reading simple destination dictionary
  8757. obj = nameDictionaryRef;
  8758. obj.forEach(function catalogForEach(key, value) {
  8759. if (!value) {
  8760. return;
  8761. }
  8762. if (key === destinationId) {
  8763. dest = fetchDestination(value);
  8764. }
  8765. });
  8766. }
  8767. if (nameTreeRef) {
  8768. var nameTree = new NameTree(nameTreeRef, xref);
  8769. dest = fetchDestination(nameTree.get(destinationId));
  8770. }
  8771. return dest;
  8772. },
  8773. get attachments() {
  8774. var xref = this.xref;
  8775. var attachments = null, nameTreeRef;
  8776. var obj = this.catDict.get('Names');
  8777. if (obj) {
  8778. nameTreeRef = obj.getRaw('EmbeddedFiles');
  8779. }
  8780. if (nameTreeRef) {
  8781. var nameTree = new NameTree(nameTreeRef, xref);
  8782. var names = nameTree.getAll();
  8783. for (var name in names) {
  8784. if (!names.hasOwnProperty(name)) {
  8785. continue;
  8786. }
  8787. var fs = new FileSpec(names[name], xref);
  8788. if (!attachments) {
  8789. attachments = {};
  8790. }
  8791. attachments[stringToPDFString(name)] = fs.serializable;
  8792. }
  8793. }
  8794. return shadow(this, 'attachments', attachments);
  8795. },
  8796. get javaScript() {
  8797. var xref = this.xref;
  8798. var obj = this.catDict.get('Names');
  8799. var javaScript = [];
  8800. if (obj && obj.has('JavaScript')) {
  8801. var nameTree = new NameTree(obj.getRaw('JavaScript'), xref);
  8802. var names = nameTree.getAll();
  8803. for (var name in names) {
  8804. if (!names.hasOwnProperty(name)) {
  8805. continue;
  8806. }
  8807. // We don't really use the JavaScript right now. This code is
  8808. // defensive so we don't cause errors on document load.
  8809. var jsDict = names[name];
  8810. if (!isDict(jsDict)) {
  8811. continue;
  8812. }
  8813. var type = jsDict.get('S');
  8814. if (!isName(type) || type.name !== 'JavaScript') {
  8815. continue;
  8816. }
  8817. var js = jsDict.get('JS');
  8818. if (!isString(js) && !isStream(js)) {
  8819. continue;
  8820. }
  8821. if (isStream(js)) {
  8822. js = bytesToString(js.getBytes());
  8823. }
  8824. javaScript.push(stringToPDFString(js));
  8825. }
  8826. }
  8827. // Append OpenAction actions to javaScript array
  8828. var openactionDict = this.catDict.get('OpenAction');
  8829. if (isDict(openactionDict)) {
  8830. var objType = openactionDict.get('Type');
  8831. var actionType = openactionDict.get('S');
  8832. var action = openactionDict.get('N');
  8833. var isPrintAction = (isName(objType) && objType.name === 'Action' &&
  8834. isName(actionType) && actionType.name === 'Named' &&
  8835. isName(action) && action.name === 'Print');
  8836. if (isPrintAction) {
  8837. javaScript.push('print(true);');
  8838. }
  8839. }
  8840. return shadow(this, 'javaScript', javaScript);
  8841. },
  8842. cleanup: function Catalog_cleanup() {
  8843. var promises = [];
  8844. this.fontCache.forEach(function (promise) {
  8845. promises.push(promise);
  8846. });
  8847. return Promise.all(promises).then(function (translatedFonts) {
  8848. for (var i = 0, ii = translatedFonts.length; i < ii; i++) {
  8849. var font = translatedFonts[i].dict;
  8850. delete font.translated;
  8851. }
  8852. this.fontCache.clear();
  8853. }.bind(this));
  8854. },
  8855. getPage: function Catalog_getPage(pageIndex) {
  8856. if (!(pageIndex in this.pagePromises)) {
  8857. this.pagePromises[pageIndex] = this.getPageDict(pageIndex).then(
  8858. function (a) {
  8859. var dict = a[0];
  8860. var ref = a[1];
  8861. return new Page(this.pdfManager, this.xref, pageIndex, dict, ref,
  8862. this.fontCache);
  8863. }.bind(this)
  8864. );
  8865. }
  8866. return this.pagePromises[pageIndex];
  8867. },
  8868. getPageDict: function Catalog_getPageDict(pageIndex) {
  8869. var capability = createPromiseCapability();
  8870. var nodesToVisit = [this.catDict.getRaw('Pages')];
  8871. var currentPageIndex = 0;
  8872. var xref = this.xref;
  8873. var checkAllKids = false;
  8874. function next() {
  8875. while (nodesToVisit.length) {
  8876. var currentNode = nodesToVisit.pop();
  8877. if (isRef(currentNode)) {
  8878. xref.fetchAsync(currentNode).then(function (obj) {
  8879. if (isDict(obj, 'Page') || (isDict(obj) && !obj.has('Kids'))) {
  8880. if (pageIndex === currentPageIndex) {
  8881. capability.resolve([obj, currentNode]);
  8882. } else {
  8883. currentPageIndex++;
  8884. next();
  8885. }
  8886. return;
  8887. }
  8888. nodesToVisit.push(obj);
  8889. next();
  8890. }, capability.reject);
  8891. return;
  8892. }
  8893. // Must be a child page dictionary.
  8894. assert(
  8895. isDict(currentNode),
  8896. 'page dictionary kid reference points to wrong type of object'
  8897. );
  8898. var count = currentNode.get('Count');
  8899. // If the current node doesn't have any children, avoid getting stuck
  8900. // in an empty node further down in the tree (see issue5644.pdf).
  8901. if (count === 0) {
  8902. checkAllKids = true;
  8903. }
  8904. // Skip nodes where the page can't be.
  8905. if (currentPageIndex + count <= pageIndex) {
  8906. currentPageIndex += count;
  8907. continue;
  8908. }
  8909. var kids = currentNode.get('Kids');
  8910. assert(isArray(kids), 'page dictionary kids object is not an array');
  8911. if (!checkAllKids && count === kids.length) {
  8912. // Nodes that don't have the page have been skipped and this is the
  8913. // bottom of the tree which means the page requested must be a
  8914. // descendant of this pages node. Ideally we would just resolve the
  8915. // promise with the page ref here, but there is the case where more
  8916. // pages nodes could link to single a page (see issue 3666 pdf). To
  8917. // handle this push it back on the queue so if it is a pages node it
  8918. // will be descended into.
  8919. nodesToVisit = [kids[pageIndex - currentPageIndex]];
  8920. currentPageIndex = pageIndex;
  8921. continue;
  8922. } else {
  8923. for (var last = kids.length - 1; last >= 0; last--) {
  8924. nodesToVisit.push(kids[last]);
  8925. }
  8926. }
  8927. }
  8928. capability.reject('Page index ' + pageIndex + ' not found.');
  8929. }
  8930. next();
  8931. return capability.promise;
  8932. },
  8933. getPageIndex: function Catalog_getPageIndex(ref) {
  8934. // The page tree nodes have the count of all the leaves below them. To get
  8935. // how many pages are before we just have to walk up the tree and keep
  8936. // adding the count of siblings to the left of the node.
  8937. var xref = this.xref;
  8938. function pagesBeforeRef(kidRef) {
  8939. var total = 0;
  8940. var parentRef;
  8941. return xref.fetchAsync(kidRef).then(function (node) {
  8942. if (!node) {
  8943. return null;
  8944. }
  8945. parentRef = node.getRaw('Parent');
  8946. return node.getAsync('Parent');
  8947. }).then(function (parent) {
  8948. if (!parent) {
  8949. return null;
  8950. }
  8951. return parent.getAsync('Kids');
  8952. }).then(function (kids) {
  8953. if (!kids) {
  8954. return null;
  8955. }
  8956. var kidPromises = [];
  8957. var found = false;
  8958. for (var i = 0; i < kids.length; i++) {
  8959. var kid = kids[i];
  8960. assert(isRef(kid), 'kids must be a ref');
  8961. if (kid.num === kidRef.num) {
  8962. found = true;
  8963. break;
  8964. }
  8965. kidPromises.push(xref.fetchAsync(kid).then(function (kid) {
  8966. if (kid.has('Count')) {
  8967. var count = kid.get('Count');
  8968. total += count;
  8969. } else { // page leaf node
  8970. total++;
  8971. }
  8972. }));
  8973. }
  8974. if (!found) {
  8975. error('kid ref not found in parents kids');
  8976. }
  8977. return Promise.all(kidPromises).then(function () {
  8978. return [total, parentRef];
  8979. });
  8980. });
  8981. }
  8982. var total = 0;
  8983. function next(ref) {
  8984. return pagesBeforeRef(ref).then(function (args) {
  8985. if (!args) {
  8986. return total;
  8987. }
  8988. var count = args[0];
  8989. var parentRef = args[1];
  8990. total += count;
  8991. return next(parentRef);
  8992. });
  8993. }
  8994. return next(ref);
  8995. }
  8996. };
  8997. return Catalog;
  8998. })();
  8999. var XRef = (function XRefClosure() {
  9000. function XRef(stream, password) {
  9001. this.stream = stream;
  9002. this.entries = [];
  9003. this.xrefstms = {};
  9004. // prepare the XRef cache
  9005. this.cache = [];
  9006. this.password = password;
  9007. this.stats = {
  9008. streamTypes: [],
  9009. fontTypes: []
  9010. };
  9011. }
  9012. XRef.prototype = {
  9013. setStartXRef: function XRef_setStartXRef(startXRef) {
  9014. // Store the starting positions of xref tables as we process them
  9015. // so we can recover from missing data errors
  9016. this.startXRefQueue = [startXRef];
  9017. },
  9018. parse: function XRef_parse(recoveryMode) {
  9019. var trailerDict;
  9020. if (!recoveryMode) {
  9021. trailerDict = this.readXRef();
  9022. } else {
  9023. warn('Indexing all PDF objects');
  9024. trailerDict = this.indexObjects();
  9025. }
  9026. trailerDict.assignXref(this);
  9027. this.trailer = trailerDict;
  9028. var encrypt = trailerDict.get('Encrypt');
  9029. if (encrypt) {
  9030. var ids = trailerDict.get('ID');
  9031. var fileId = (ids && ids.length) ? ids[0] : '';
  9032. this.encrypt = new CipherTransformFactory(encrypt, fileId,
  9033. this.password);
  9034. }
  9035. // get the root dictionary (catalog) object
  9036. if (!(this.root = trailerDict.get('Root'))) {
  9037. error('Invalid root reference');
  9038. }
  9039. },
  9040. processXRefTable: function XRef_processXRefTable(parser) {
  9041. if (!('tableState' in this)) {
  9042. // Stores state of the table as we process it so we can resume
  9043. // from middle of table in case of missing data error
  9044. this.tableState = {
  9045. entryNum: 0,
  9046. streamPos: parser.lexer.stream.pos,
  9047. parserBuf1: parser.buf1,
  9048. parserBuf2: parser.buf2
  9049. };
  9050. }
  9051. var obj = this.readXRefTable(parser);
  9052. // Sanity check
  9053. if (!isCmd(obj, 'trailer')) {
  9054. error('Invalid XRef table: could not find trailer dictionary');
  9055. }
  9056. // Read trailer dictionary, e.g.
  9057. // trailer
  9058. // << /Size 22
  9059. // /Root 20R
  9060. // /Info 10R
  9061. // /ID [ <81b14aafa313db63dbd6f981e49f94f4> ]
  9062. // >>
  9063. // The parser goes through the entire stream << ... >> and provides
  9064. // a getter interface for the key-value table
  9065. var dict = parser.getObj();
  9066. // The pdflib PDF generator can generate a nested trailer dictionary
  9067. if (!isDict(dict) && dict.dict) {
  9068. dict = dict.dict;
  9069. }
  9070. if (!isDict(dict)) {
  9071. error('Invalid XRef table: could not parse trailer dictionary');
  9072. }
  9073. delete this.tableState;
  9074. return dict;
  9075. },
  9076. readXRefTable: function XRef_readXRefTable(parser) {
  9077. // Example of cross-reference table:
  9078. // xref
  9079. // 0 1 <-- subsection header (first obj #, obj count)
  9080. // 0000000000 65535 f <-- actual object (offset, generation #, f/n)
  9081. // 23 2 <-- subsection header ... and so on ...
  9082. // 0000025518 00002 n
  9083. // 0000025635 00000 n
  9084. // trailer
  9085. // ...
  9086. var stream = parser.lexer.stream;
  9087. var tableState = this.tableState;
  9088. stream.pos = tableState.streamPos;
  9089. parser.buf1 = tableState.parserBuf1;
  9090. parser.buf2 = tableState.parserBuf2;
  9091. // Outer loop is over subsection headers
  9092. var obj;
  9093. while (true) {
  9094. if (!('firstEntryNum' in tableState) || !('entryCount' in tableState)) {
  9095. if (isCmd(obj = parser.getObj(), 'trailer')) {
  9096. break;
  9097. }
  9098. tableState.firstEntryNum = obj;
  9099. tableState.entryCount = parser.getObj();
  9100. }
  9101. var first = tableState.firstEntryNum;
  9102. var count = tableState.entryCount;
  9103. if (!isInt(first) || !isInt(count)) {
  9104. error('Invalid XRef table: wrong types in subsection header');
  9105. }
  9106. // Inner loop is over objects themselves
  9107. for (var i = tableState.entryNum; i < count; i++) {
  9108. tableState.streamPos = stream.pos;
  9109. tableState.entryNum = i;
  9110. tableState.parserBuf1 = parser.buf1;
  9111. tableState.parserBuf2 = parser.buf2;
  9112. var entry = {};
  9113. entry.offset = parser.getObj();
  9114. entry.gen = parser.getObj();
  9115. var type = parser.getObj();
  9116. if (isCmd(type, 'f')) {
  9117. entry.free = true;
  9118. } else if (isCmd(type, 'n')) {
  9119. entry.uncompressed = true;
  9120. }
  9121. // Validate entry obj
  9122. if (!isInt(entry.offset) || !isInt(entry.gen) ||
  9123. !(entry.free || entry.uncompressed)) {
  9124. error('Invalid entry in XRef subsection: ' + first + ', ' + count);
  9125. }
  9126. if (!this.entries[i + first]) {
  9127. this.entries[i + first] = entry;
  9128. }
  9129. }
  9130. tableState.entryNum = 0;
  9131. tableState.streamPos = stream.pos;
  9132. tableState.parserBuf1 = parser.buf1;
  9133. tableState.parserBuf2 = parser.buf2;
  9134. delete tableState.firstEntryNum;
  9135. delete tableState.entryCount;
  9136. }
  9137. // Per issue 3248: hp scanners generate bad XRef
  9138. if (first === 1 && this.entries[1] && this.entries[1].free) {
  9139. // shifting the entries
  9140. this.entries.shift();
  9141. }
  9142. // Sanity check: as per spec, first object must be free
  9143. if (this.entries[0] && !this.entries[0].free) {
  9144. error('Invalid XRef table: unexpected first object');
  9145. }
  9146. return obj;
  9147. },
  9148. processXRefStream: function XRef_processXRefStream(stream) {
  9149. if (!('streamState' in this)) {
  9150. // Stores state of the stream as we process it so we can resume
  9151. // from middle of stream in case of missing data error
  9152. var streamParameters = stream.dict;
  9153. var byteWidths = streamParameters.get('W');
  9154. var range = streamParameters.get('Index');
  9155. if (!range) {
  9156. range = [0, streamParameters.get('Size')];
  9157. }
  9158. this.streamState = {
  9159. entryRanges: range,
  9160. byteWidths: byteWidths,
  9161. entryNum: 0,
  9162. streamPos: stream.pos
  9163. };
  9164. }
  9165. this.readXRefStream(stream);
  9166. delete this.streamState;
  9167. return stream.dict;
  9168. },
  9169. readXRefStream: function XRef_readXRefStream(stream) {
  9170. var i, j;
  9171. var streamState = this.streamState;
  9172. stream.pos = streamState.streamPos;
  9173. var byteWidths = streamState.byteWidths;
  9174. var typeFieldWidth = byteWidths[0];
  9175. var offsetFieldWidth = byteWidths[1];
  9176. var generationFieldWidth = byteWidths[2];
  9177. var entryRanges = streamState.entryRanges;
  9178. while (entryRanges.length > 0) {
  9179. var first = entryRanges[0];
  9180. var n = entryRanges[1];
  9181. if (!isInt(first) || !isInt(n)) {
  9182. error('Invalid XRef range fields: ' + first + ', ' + n);
  9183. }
  9184. if (!isInt(typeFieldWidth) || !isInt(offsetFieldWidth) ||
  9185. !isInt(generationFieldWidth)) {
  9186. error('Invalid XRef entry fields length: ' + first + ', ' + n);
  9187. }
  9188. for (i = streamState.entryNum; i < n; ++i) {
  9189. streamState.entryNum = i;
  9190. streamState.streamPos = stream.pos;
  9191. var type = 0, offset = 0, generation = 0;
  9192. for (j = 0; j < typeFieldWidth; ++j) {
  9193. type = (type << 8) | stream.getByte();
  9194. }
  9195. // if type field is absent, its default value is 1
  9196. if (typeFieldWidth === 0) {
  9197. type = 1;
  9198. }
  9199. for (j = 0; j < offsetFieldWidth; ++j) {
  9200. offset = (offset << 8) | stream.getByte();
  9201. }
  9202. for (j = 0; j < generationFieldWidth; ++j) {
  9203. generation = (generation << 8) | stream.getByte();
  9204. }
  9205. var entry = {};
  9206. entry.offset = offset;
  9207. entry.gen = generation;
  9208. switch (type) {
  9209. case 0:
  9210. entry.free = true;
  9211. break;
  9212. case 1:
  9213. entry.uncompressed = true;
  9214. break;
  9215. case 2:
  9216. break;
  9217. default:
  9218. error('Invalid XRef entry type: ' + type);
  9219. }
  9220. if (!this.entries[first + i]) {
  9221. this.entries[first + i] = entry;
  9222. }
  9223. }
  9224. streamState.entryNum = 0;
  9225. streamState.streamPos = stream.pos;
  9226. entryRanges.splice(0, 2);
  9227. }
  9228. },
  9229. indexObjects: function XRef_indexObjects() {
  9230. // Simple scan through the PDF content to find objects,
  9231. // trailers and XRef streams.
  9232. function readToken(data, offset) {
  9233. var token = '', ch = data[offset];
  9234. while (ch !== 13 && ch !== 10) {
  9235. if (++offset >= data.length) {
  9236. break;
  9237. }
  9238. token += String.fromCharCode(ch);
  9239. ch = data[offset];
  9240. }
  9241. return token;
  9242. }
  9243. function skipUntil(data, offset, what) {
  9244. var length = what.length, dataLength = data.length;
  9245. var skipped = 0;
  9246. // finding byte sequence
  9247. while (offset < dataLength) {
  9248. var i = 0;
  9249. while (i < length && data[offset + i] === what[i]) {
  9250. ++i;
  9251. }
  9252. if (i >= length) {
  9253. break; // sequence found
  9254. }
  9255. offset++;
  9256. skipped++;
  9257. }
  9258. return skipped;
  9259. }
  9260. var trailerBytes = new Uint8Array([116, 114, 97, 105, 108, 101, 114]);
  9261. var startxrefBytes = new Uint8Array([115, 116, 97, 114, 116, 120, 114,
  9262. 101, 102]);
  9263. var endobjBytes = new Uint8Array([101, 110, 100, 111, 98, 106]);
  9264. var xrefBytes = new Uint8Array([47, 88, 82, 101, 102]);
  9265. var stream = this.stream;
  9266. stream.pos = 0;
  9267. var buffer = stream.getBytes();
  9268. var position = stream.start, length = buffer.length;
  9269. var trailers = [], xrefStms = [];
  9270. while (position < length) {
  9271. var ch = buffer[position];
  9272. if (ch === 32 || ch === 9 || ch === 13 || ch === 10) {
  9273. ++position;
  9274. continue;
  9275. }
  9276. if (ch === 37) { // %-comment
  9277. do {
  9278. ++position;
  9279. if (position >= length) {
  9280. break;
  9281. }
  9282. ch = buffer[position];
  9283. } while (ch !== 13 && ch !== 10);
  9284. continue;
  9285. }
  9286. var token = readToken(buffer, position);
  9287. var m;
  9288. if (token === 'xref') {
  9289. position += skipUntil(buffer, position, trailerBytes);
  9290. trailers.push(position);
  9291. position += skipUntil(buffer, position, startxrefBytes);
  9292. } else if ((m = /^(\d+)\s+(\d+)\s+obj\b/.exec(token))) {
  9293. if (typeof this.entries[m[1]] === 'undefined') {
  9294. this.entries[m[1]] = {
  9295. offset: position,
  9296. gen: m[2] | 0,
  9297. uncompressed: true
  9298. };
  9299. }
  9300. var contentLength = skipUntil(buffer, position, endobjBytes) + 7;
  9301. var content = buffer.subarray(position, position + contentLength);
  9302. // checking XRef stream suspect
  9303. // (it shall have '/XRef' and next char is not a letter)
  9304. var xrefTagOffset = skipUntil(content, 0, xrefBytes);
  9305. if (xrefTagOffset < contentLength &&
  9306. content[xrefTagOffset + 5] < 64) {
  9307. xrefStms.push(position);
  9308. this.xrefstms[position] = 1; // don't read it recursively
  9309. }
  9310. position += contentLength;
  9311. } else {
  9312. position += token.length + 1;
  9313. }
  9314. }
  9315. // reading XRef streams
  9316. var i, ii;
  9317. for (i = 0, ii = xrefStms.length; i < ii; ++i) {
  9318. this.startXRefQueue.push(xrefStms[i]);
  9319. this.readXRef(/* recoveryMode */ true);
  9320. }
  9321. // finding main trailer
  9322. var dict;
  9323. for (i = 0, ii = trailers.length; i < ii; ++i) {
  9324. stream.pos = trailers[i];
  9325. var parser = new Parser(new Lexer(stream), true, this);
  9326. var obj = parser.getObj();
  9327. if (!isCmd(obj, 'trailer')) {
  9328. continue;
  9329. }
  9330. // read the trailer dictionary
  9331. if (!isDict(dict = parser.getObj())) {
  9332. continue;
  9333. }
  9334. // taking the first one with 'ID'
  9335. if (dict.has('ID')) {
  9336. return dict;
  9337. }
  9338. }
  9339. // no tailer with 'ID', taking last one (if exists)
  9340. if (dict) {
  9341. return dict;
  9342. }
  9343. // nothing helps
  9344. // calling error() would reject worker with an UnknownErrorException.
  9345. throw new InvalidPDFException('Invalid PDF structure');
  9346. },
  9347. readXRef: function XRef_readXRef(recoveryMode) {
  9348. var stream = this.stream;
  9349. try {
  9350. while (this.startXRefQueue.length) {
  9351. var startXRef = this.startXRefQueue[0];
  9352. stream.pos = startXRef + stream.start;
  9353. var parser = new Parser(new Lexer(stream), true, this);
  9354. var obj = parser.getObj();
  9355. var dict;
  9356. // Get dictionary
  9357. if (isCmd(obj, 'xref')) {
  9358. // Parse end-of-file XRef
  9359. dict = this.processXRefTable(parser);
  9360. if (!this.topDict) {
  9361. this.topDict = dict;
  9362. }
  9363. // Recursively get other XRefs 'XRefStm', if any
  9364. obj = dict.get('XRefStm');
  9365. if (isInt(obj)) {
  9366. var pos = obj;
  9367. // ignore previously loaded xref streams
  9368. // (possible infinite recursion)
  9369. if (!(pos in this.xrefstms)) {
  9370. this.xrefstms[pos] = 1;
  9371. this.startXRefQueue.push(pos);
  9372. }
  9373. }
  9374. } else if (isInt(obj)) {
  9375. // Parse in-stream XRef
  9376. if (!isInt(parser.getObj()) ||
  9377. !isCmd(parser.getObj(), 'obj') ||
  9378. !isStream(obj = parser.getObj())) {
  9379. error('Invalid XRef stream');
  9380. }
  9381. dict = this.processXRefStream(obj);
  9382. if (!this.topDict) {
  9383. this.topDict = dict;
  9384. }
  9385. if (!dict) {
  9386. error('Failed to read XRef stream');
  9387. }
  9388. } else {
  9389. error('Invalid XRef stream header');
  9390. }
  9391. // Recursively get previous dictionary, if any
  9392. obj = dict.get('Prev');
  9393. if (isInt(obj)) {
  9394. this.startXRefQueue.push(obj);
  9395. } else if (isRef(obj)) {
  9396. // The spec says Prev must not be a reference, i.e. "/Prev NNN"
  9397. // This is a fallback for non-compliant PDFs, i.e. "/Prev NNN 0 R"
  9398. this.startXRefQueue.push(obj.num);
  9399. }
  9400. this.startXRefQueue.shift();
  9401. }
  9402. return this.topDict;
  9403. } catch (e) {
  9404. if (e instanceof MissingDataException) {
  9405. throw e;
  9406. }
  9407. info('(while reading XRef): ' + e);
  9408. }
  9409. if (recoveryMode) {
  9410. return;
  9411. }
  9412. throw new XRefParseException();
  9413. },
  9414. getEntry: function XRef_getEntry(i) {
  9415. var xrefEntry = this.entries[i];
  9416. if (xrefEntry && !xrefEntry.free && xrefEntry.offset) {
  9417. return xrefEntry;
  9418. }
  9419. return null;
  9420. },
  9421. fetchIfRef: function XRef_fetchIfRef(obj) {
  9422. if (!isRef(obj)) {
  9423. return obj;
  9424. }
  9425. return this.fetch(obj);
  9426. },
  9427. fetch: function XRef_fetch(ref, suppressEncryption) {
  9428. assert(isRef(ref), 'ref object is not a reference');
  9429. var num = ref.num;
  9430. if (num in this.cache) {
  9431. var cacheEntry = this.cache[num];
  9432. return cacheEntry;
  9433. }
  9434. var xrefEntry = this.getEntry(num);
  9435. // the referenced entry can be free
  9436. if (xrefEntry === null) {
  9437. return (this.cache[num] = null);
  9438. }
  9439. if (xrefEntry.uncompressed) {
  9440. xrefEntry = this.fetchUncompressed(ref, xrefEntry, suppressEncryption);
  9441. } else {
  9442. xrefEntry = this.fetchCompressed(xrefEntry, suppressEncryption);
  9443. }
  9444. if (isDict(xrefEntry)){
  9445. xrefEntry.objId = ref.toString();
  9446. } else if (isStream(xrefEntry)) {
  9447. xrefEntry.dict.objId = ref.toString();
  9448. }
  9449. return xrefEntry;
  9450. },
  9451. fetchUncompressed: function XRef_fetchUncompressed(ref, xrefEntry,
  9452. suppressEncryption) {
  9453. var gen = ref.gen;
  9454. var num = ref.num;
  9455. if (xrefEntry.gen !== gen) {
  9456. error('inconsistent generation in XRef');
  9457. }
  9458. var stream = this.stream.makeSubStream(xrefEntry.offset +
  9459. this.stream.start);
  9460. var parser = new Parser(new Lexer(stream), true, this);
  9461. var obj1 = parser.getObj();
  9462. var obj2 = parser.getObj();
  9463. var obj3 = parser.getObj();
  9464. if (!isInt(obj1) || parseInt(obj1, 10) !== num ||
  9465. !isInt(obj2) || parseInt(obj2, 10) !== gen ||
  9466. !isCmd(obj3)) {
  9467. error('bad XRef entry');
  9468. }
  9469. if (!isCmd(obj3, 'obj')) {
  9470. // some bad PDFs use "obj1234" and really mean 1234
  9471. if (obj3.cmd.indexOf('obj') === 0) {
  9472. num = parseInt(obj3.cmd.substring(3), 10);
  9473. if (!isNaN(num)) {
  9474. return num;
  9475. }
  9476. }
  9477. error('bad XRef entry');
  9478. }
  9479. if (this.encrypt && !suppressEncryption) {
  9480. xrefEntry = parser.getObj(this.encrypt.createCipherTransform(num, gen));
  9481. } else {
  9482. xrefEntry = parser.getObj();
  9483. }
  9484. if (!isStream(xrefEntry)) {
  9485. this.cache[num] = xrefEntry;
  9486. }
  9487. return xrefEntry;
  9488. },
  9489. fetchCompressed: function XRef_fetchCompressed(xrefEntry,
  9490. suppressEncryption) {
  9491. var tableOffset = xrefEntry.offset;
  9492. var stream = this.fetch(new Ref(tableOffset, 0));
  9493. if (!isStream(stream)) {
  9494. error('bad ObjStm stream');
  9495. }
  9496. var first = stream.dict.get('First');
  9497. var n = stream.dict.get('N');
  9498. if (!isInt(first) || !isInt(n)) {
  9499. error('invalid first and n parameters for ObjStm stream');
  9500. }
  9501. var parser = new Parser(new Lexer(stream), false, this);
  9502. parser.allowStreams = true;
  9503. var i, entries = [], num, nums = [];
  9504. // read the object numbers to populate cache
  9505. for (i = 0; i < n; ++i) {
  9506. num = parser.getObj();
  9507. if (!isInt(num)) {
  9508. error('invalid object number in the ObjStm stream: ' + num);
  9509. }
  9510. nums.push(num);
  9511. var offset = parser.getObj();
  9512. if (!isInt(offset)) {
  9513. error('invalid object offset in the ObjStm stream: ' + offset);
  9514. }
  9515. }
  9516. // read stream objects for cache
  9517. for (i = 0; i < n; ++i) {
  9518. entries.push(parser.getObj());
  9519. num = nums[i];
  9520. var entry = this.entries[num];
  9521. if (entry && entry.offset === tableOffset && entry.gen === i) {
  9522. this.cache[num] = entries[i];
  9523. }
  9524. }
  9525. xrefEntry = entries[xrefEntry.gen];
  9526. if (xrefEntry === undefined) {
  9527. error('bad XRef entry for compressed object');
  9528. }
  9529. return xrefEntry;
  9530. },
  9531. fetchIfRefAsync: function XRef_fetchIfRefAsync(obj) {
  9532. if (!isRef(obj)) {
  9533. return Promise.resolve(obj);
  9534. }
  9535. return this.fetchAsync(obj);
  9536. },
  9537. fetchAsync: function XRef_fetchAsync(ref, suppressEncryption) {
  9538. var streamManager = this.stream.manager;
  9539. var xref = this;
  9540. return new Promise(function tryFetch(resolve, reject) {
  9541. try {
  9542. resolve(xref.fetch(ref, suppressEncryption));
  9543. } catch (e) {
  9544. if (e instanceof MissingDataException) {
  9545. streamManager.requestRange(e.begin, e.end, function () {
  9546. tryFetch(resolve, reject);
  9547. });
  9548. return;
  9549. }
  9550. reject(e);
  9551. }
  9552. });
  9553. },
  9554. getCatalogObj: function XRef_getCatalogObj() {
  9555. return this.root;
  9556. }
  9557. };
  9558. return XRef;
  9559. })();
  9560. /**
  9561. * A NameTree is like a Dict but has some advantageous properties, see the
  9562. * spec (7.9.6) for more details.
  9563. * TODO: implement all the Dict functions and make this more efficent.
  9564. */
  9565. var NameTree = (function NameTreeClosure() {
  9566. function NameTree(root, xref) {
  9567. this.root = root;
  9568. this.xref = xref;
  9569. }
  9570. NameTree.prototype = {
  9571. getAll: function NameTree_getAll() {
  9572. var dict = {};
  9573. if (!this.root) {
  9574. return dict;
  9575. }
  9576. var xref = this.xref;
  9577. // reading name tree
  9578. var processed = new RefSet();
  9579. processed.put(this.root);
  9580. var queue = [this.root];
  9581. while (queue.length > 0) {
  9582. var i, n;
  9583. var obj = xref.fetchIfRef(queue.shift());
  9584. if (!isDict(obj)) {
  9585. continue;
  9586. }
  9587. if (obj.has('Kids')) {
  9588. var kids = obj.get('Kids');
  9589. for (i = 0, n = kids.length; i < n; i++) {
  9590. var kid = kids[i];
  9591. if (processed.has(kid)) {
  9592. error('invalid destinations');
  9593. }
  9594. queue.push(kid);
  9595. processed.put(kid);
  9596. }
  9597. continue;
  9598. }
  9599. var names = obj.get('Names');
  9600. if (names) {
  9601. for (i = 0, n = names.length; i < n; i += 2) {
  9602. dict[names[i]] = xref.fetchIfRef(names[i + 1]);
  9603. }
  9604. }
  9605. }
  9606. return dict;
  9607. },
  9608. get: function NameTree_get(destinationId) {
  9609. if (!this.root) {
  9610. return null;
  9611. }
  9612. var xref = this.xref;
  9613. var kidsOrNames = xref.fetchIfRef(this.root);
  9614. var loopCount = 0;
  9615. var MAX_NAMES_LEVELS = 10;
  9616. var l, r, m;
  9617. // Perform a binary search to quickly find the entry that
  9618. // contains the named destination we are looking for.
  9619. while (kidsOrNames.has('Kids')) {
  9620. loopCount++;
  9621. if (loopCount > MAX_NAMES_LEVELS) {
  9622. warn('Search depth limit for named destionations has been reached.');
  9623. return null;
  9624. }
  9625. var kids = kidsOrNames.get('Kids');
  9626. if (!isArray(kids)) {
  9627. return null;
  9628. }
  9629. l = 0;
  9630. r = kids.length - 1;
  9631. while (l <= r) {
  9632. m = (l + r) >> 1;
  9633. var kid = xref.fetchIfRef(kids[m]);
  9634. var limits = kid.get('Limits');
  9635. if (destinationId < limits[0]) {
  9636. r = m - 1;
  9637. } else if (destinationId > limits[1]) {
  9638. l = m + 1;
  9639. } else {
  9640. kidsOrNames = xref.fetchIfRef(kids[m]);
  9641. break;
  9642. }
  9643. }
  9644. if (l > r) {
  9645. return null;
  9646. }
  9647. }
  9648. // If we get here, then we have found the right entry. Now
  9649. // go through the named destinations in the Named dictionary
  9650. // until we find the exact destination we're looking for.
  9651. var names = kidsOrNames.get('Names');
  9652. if (isArray(names)) {
  9653. // Perform a binary search to reduce the lookup time.
  9654. l = 0;
  9655. r = names.length - 2;
  9656. while (l <= r) {
  9657. // Check only even indices (0, 2, 4, ...) because the
  9658. // odd indices contain the actual D array.
  9659. m = (l + r) & ~1;
  9660. if (destinationId < names[m]) {
  9661. r = m - 2;
  9662. } else if (destinationId > names[m]) {
  9663. l = m + 2;
  9664. } else {
  9665. return xref.fetchIfRef(names[m + 1]);
  9666. }
  9667. }
  9668. }
  9669. return null;
  9670. }
  9671. };
  9672. return NameTree;
  9673. })();
  9674. /**
  9675. * "A PDF file can refer to the contents of another file by using a File
  9676. * Specification (PDF 1.1)", see the spec (7.11) for more details.
  9677. * NOTE: Only embedded files are supported (as part of the attachments support)
  9678. * TODO: support the 'URL' file system (with caching if !/V), portable
  9679. * collections attributes and related files (/RF)
  9680. */
  9681. var FileSpec = (function FileSpecClosure() {
  9682. function FileSpec(root, xref) {
  9683. if (!root || !isDict(root)) {
  9684. return;
  9685. }
  9686. this.xref = xref;
  9687. this.root = root;
  9688. if (root.has('FS')) {
  9689. this.fs = root.get('FS');
  9690. }
  9691. this.description = root.has('Desc') ?
  9692. stringToPDFString(root.get('Desc')) :
  9693. '';
  9694. if (root.has('RF')) {
  9695. warn('Related file specifications are not supported');
  9696. }
  9697. this.contentAvailable = true;
  9698. if (!root.has('EF')) {
  9699. this.contentAvailable = false;
  9700. warn('Non-embedded file specifications are not supported');
  9701. }
  9702. }
  9703. function pickPlatformItem(dict) {
  9704. // Look for the filename in this order:
  9705. // UF, F, Unix, Mac, DOS
  9706. if (dict.has('UF')) {
  9707. return dict.get('UF');
  9708. } else if (dict.has('F')) {
  9709. return dict.get('F');
  9710. } else if (dict.has('Unix')) {
  9711. return dict.get('Unix');
  9712. } else if (dict.has('Mac')) {
  9713. return dict.get('Mac');
  9714. } else if (dict.has('DOS')) {
  9715. return dict.get('DOS');
  9716. } else {
  9717. return null;
  9718. }
  9719. }
  9720. FileSpec.prototype = {
  9721. get filename() {
  9722. if (!this._filename && this.root) {
  9723. var filename = pickPlatformItem(this.root) || 'unnamed';
  9724. this._filename = stringToPDFString(filename).
  9725. replace(/\\\\/g, '\\').
  9726. replace(/\\\//g, '/').
  9727. replace(/\\/g, '/');
  9728. }
  9729. return this._filename;
  9730. },
  9731. get content() {
  9732. if (!this.contentAvailable) {
  9733. return null;
  9734. }
  9735. if (!this.contentRef && this.root) {
  9736. this.contentRef = pickPlatformItem(this.root.get('EF'));
  9737. }
  9738. var content = null;
  9739. if (this.contentRef) {
  9740. var xref = this.xref;
  9741. var fileObj = xref.fetchIfRef(this.contentRef);
  9742. if (fileObj && isStream(fileObj)) {
  9743. content = fileObj.getBytes();
  9744. } else {
  9745. warn('Embedded file specification points to non-existing/invalid ' +
  9746. 'content');
  9747. }
  9748. } else {
  9749. warn('Embedded file specification does not have a content');
  9750. }
  9751. return content;
  9752. },
  9753. get serializable() {
  9754. return {
  9755. filename: this.filename,
  9756. content: this.content
  9757. };
  9758. }
  9759. };
  9760. return FileSpec;
  9761. })();
  9762. /**
  9763. * A helper for loading missing data in object graphs. It traverses the graph
  9764. * depth first and queues up any objects that have missing data. Once it has
  9765. * has traversed as many objects that are available it attempts to bundle the
  9766. * missing data requests and then resume from the nodes that weren't ready.
  9767. *
  9768. * NOTE: It provides protection from circular references by keeping track of
  9769. * of loaded references. However, you must be careful not to load any graphs
  9770. * that have references to the catalog or other pages since that will cause the
  9771. * entire PDF document object graph to be traversed.
  9772. */
  9773. var ObjectLoader = (function() {
  9774. function mayHaveChildren(value) {
  9775. return isRef(value) || isDict(value) || isArray(value) || isStream(value);
  9776. }
  9777. function addChildren(node, nodesToVisit) {
  9778. var value;
  9779. if (isDict(node) || isStream(node)) {
  9780. var map;
  9781. if (isDict(node)) {
  9782. map = node.map;
  9783. } else {
  9784. map = node.dict.map;
  9785. }
  9786. for (var key in map) {
  9787. value = map[key];
  9788. if (mayHaveChildren(value)) {
  9789. nodesToVisit.push(value);
  9790. }
  9791. }
  9792. } else if (isArray(node)) {
  9793. for (var i = 0, ii = node.length; i < ii; i++) {
  9794. value = node[i];
  9795. if (mayHaveChildren(value)) {
  9796. nodesToVisit.push(value);
  9797. }
  9798. }
  9799. }
  9800. }
  9801. function ObjectLoader(obj, keys, xref) {
  9802. this.obj = obj;
  9803. this.keys = keys;
  9804. this.xref = xref;
  9805. this.refSet = null;
  9806. }
  9807. ObjectLoader.prototype = {
  9808. load: function ObjectLoader_load() {
  9809. var keys = this.keys;
  9810. this.capability = createPromiseCapability();
  9811. // Don't walk the graph if all the data is already loaded.
  9812. if (!(this.xref.stream instanceof ChunkedStream) ||
  9813. this.xref.stream.getMissingChunks().length === 0) {
  9814. this.capability.resolve();
  9815. return this.capability.promise;
  9816. }
  9817. this.refSet = new RefSet();
  9818. // Setup the initial nodes to visit.
  9819. var nodesToVisit = [];
  9820. for (var i = 0; i < keys.length; i++) {
  9821. nodesToVisit.push(this.obj[keys[i]]);
  9822. }
  9823. this.walk(nodesToVisit);
  9824. return this.capability.promise;
  9825. },
  9826. walk: function ObjectLoader_walk(nodesToVisit) {
  9827. var nodesToRevisit = [];
  9828. var pendingRequests = [];
  9829. // DFS walk of the object graph.
  9830. while (nodesToVisit.length) {
  9831. var currentNode = nodesToVisit.pop();
  9832. // Only references or chunked streams can cause missing data exceptions.
  9833. if (isRef(currentNode)) {
  9834. // Skip nodes that have already been visited.
  9835. if (this.refSet.has(currentNode)) {
  9836. continue;
  9837. }
  9838. try {
  9839. var ref = currentNode;
  9840. this.refSet.put(ref);
  9841. currentNode = this.xref.fetch(currentNode);
  9842. } catch (e) {
  9843. if (!(e instanceof MissingDataException)) {
  9844. throw e;
  9845. }
  9846. nodesToRevisit.push(currentNode);
  9847. pendingRequests.push({ begin: e.begin, end: e.end });
  9848. }
  9849. }
  9850. if (currentNode && currentNode.getBaseStreams) {
  9851. var baseStreams = currentNode.getBaseStreams();
  9852. var foundMissingData = false;
  9853. for (var i = 0; i < baseStreams.length; i++) {
  9854. var stream = baseStreams[i];
  9855. if (stream.getMissingChunks && stream.getMissingChunks().length) {
  9856. foundMissingData = true;
  9857. pendingRequests.push({
  9858. begin: stream.start,
  9859. end: stream.end
  9860. });
  9861. }
  9862. }
  9863. if (foundMissingData) {
  9864. nodesToRevisit.push(currentNode);
  9865. }
  9866. }
  9867. addChildren(currentNode, nodesToVisit);
  9868. }
  9869. if (pendingRequests.length) {
  9870. this.xref.stream.manager.requestRanges(pendingRequests,
  9871. function pendingRequestCallback() {
  9872. nodesToVisit = nodesToRevisit;
  9873. for (var i = 0; i < nodesToRevisit.length; i++) {
  9874. var node = nodesToRevisit[i];
  9875. // Remove any reference nodes from the currrent refset so they
  9876. // aren't skipped when we revist them.
  9877. if (isRef(node)) {
  9878. this.refSet.remove(node);
  9879. }
  9880. }
  9881. this.walk(nodesToVisit);
  9882. }.bind(this));
  9883. return;
  9884. }
  9885. // Everything is loaded.
  9886. this.refSet = null;
  9887. this.capability.resolve();
  9888. }
  9889. };
  9890. return ObjectLoader;
  9891. })();
  9892. var ISOAdobeCharset = [
  9893. '.notdef', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar',
  9894. 'percent', 'ampersand', 'quoteright', 'parenleft', 'parenright',
  9895. 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash', 'zero',
  9896. 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',
  9897. 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater', 'question',
  9898. 'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
  9899. 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
  9900. 'bracketleft', 'backslash', 'bracketright', 'asciicircum', 'underscore',
  9901. 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
  9902. 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
  9903. 'braceleft', 'bar', 'braceright', 'asciitilde', 'exclamdown', 'cent',
  9904. 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  9905. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  9906. 'guilsinglright', 'fi', 'fl', 'endash', 'dagger', 'daggerdbl',
  9907. 'periodcentered', 'paragraph', 'bullet', 'quotesinglbase',
  9908. 'quotedblbase', 'quotedblright', 'guillemotright', 'ellipsis',
  9909. 'perthousand', 'questiondown', 'grave', 'acute', 'circumflex', 'tilde',
  9910. 'macron', 'breve', 'dotaccent', 'dieresis', 'ring', 'cedilla',
  9911. 'hungarumlaut', 'ogonek', 'caron', 'emdash', 'AE', 'ordfeminine',
  9912. 'Lslash', 'Oslash', 'OE', 'ordmasculine', 'ae', 'dotlessi', 'lslash',
  9913. 'oslash', 'oe', 'germandbls', 'onesuperior', 'logicalnot', 'mu',
  9914. 'trademark', 'Eth', 'onehalf', 'plusminus', 'Thorn', 'onequarter',
  9915. 'divide', 'brokenbar', 'degree', 'thorn', 'threequarters', 'twosuperior',
  9916. 'registered', 'minus', 'eth', 'multiply', 'threesuperior', 'copyright',
  9917. 'Aacute', 'Acircumflex', 'Adieresis', 'Agrave', 'Aring', 'Atilde',
  9918. 'Ccedilla', 'Eacute', 'Ecircumflex', 'Edieresis', 'Egrave', 'Iacute',
  9919. 'Icircumflex', 'Idieresis', 'Igrave', 'Ntilde', 'Oacute', 'Ocircumflex',
  9920. 'Odieresis', 'Ograve', 'Otilde', 'Scaron', 'Uacute', 'Ucircumflex',
  9921. 'Udieresis', 'Ugrave', 'Yacute', 'Ydieresis', 'Zcaron', 'aacute',
  9922. 'acircumflex', 'adieresis', 'agrave', 'aring', 'atilde', 'ccedilla',
  9923. 'eacute', 'ecircumflex', 'edieresis', 'egrave', 'iacute', 'icircumflex',
  9924. 'idieresis', 'igrave', 'ntilde', 'oacute', 'ocircumflex', 'odieresis',
  9925. 'ograve', 'otilde', 'scaron', 'uacute', 'ucircumflex', 'udieresis',
  9926. 'ugrave', 'yacute', 'ydieresis', 'zcaron'
  9927. ];
  9928. var ExpertCharset = [
  9929. '.notdef', 'space', 'exclamsmall', 'Hungarumlautsmall', 'dollaroldstyle',
  9930. 'dollarsuperior', 'ampersandsmall', 'Acutesmall', 'parenleftsuperior',
  9931. 'parenrightsuperior', 'twodotenleader', 'onedotenleader', 'comma',
  9932. 'hyphen', 'period', 'fraction', 'zerooldstyle', 'oneoldstyle',
  9933. 'twooldstyle', 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle',
  9934. 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle',
  9935. 'colon', 'semicolon', 'commasuperior', 'threequartersemdash',
  9936. 'periodsuperior', 'questionsmall', 'asuperior', 'bsuperior',
  9937. 'centsuperior', 'dsuperior', 'esuperior', 'isuperior', 'lsuperior',
  9938. 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  9939. 'tsuperior', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior',
  9940. 'parenrightinferior', 'Circumflexsmall', 'hyphensuperior', 'Gravesmall',
  9941. 'Asmall', 'Bsmall', 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall',
  9942. 'Hsmall', 'Ismall', 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall',
  9943. 'Osmall', 'Psmall', 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall',
  9944. 'Vsmall', 'Wsmall', 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary',
  9945. 'onefitted', 'rupiah', 'Tildesmall', 'exclamdownsmall', 'centoldstyle',
  9946. 'Lslashsmall', 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall',
  9947. 'Brevesmall', 'Caronsmall', 'Dotaccentsmall', 'Macronsmall',
  9948. 'figuredash', 'hypheninferior', 'Ogoneksmall', 'Ringsmall',
  9949. 'Cedillasmall', 'onequarter', 'onehalf', 'threequarters',
  9950. 'questiondownsmall', 'oneeighth', 'threeeighths', 'fiveeighths',
  9951. 'seveneighths', 'onethird', 'twothirds', 'zerosuperior', 'onesuperior',
  9952. 'twosuperior', 'threesuperior', 'foursuperior', 'fivesuperior',
  9953. 'sixsuperior', 'sevensuperior', 'eightsuperior', 'ninesuperior',
  9954. 'zeroinferior', 'oneinferior', 'twoinferior', 'threeinferior',
  9955. 'fourinferior', 'fiveinferior', 'sixinferior', 'seveninferior',
  9956. 'eightinferior', 'nineinferior', 'centinferior', 'dollarinferior',
  9957. 'periodinferior', 'commainferior', 'Agravesmall', 'Aacutesmall',
  9958. 'Acircumflexsmall', 'Atildesmall', 'Adieresissmall', 'Aringsmall',
  9959. 'AEsmall', 'Ccedillasmall', 'Egravesmall', 'Eacutesmall',
  9960. 'Ecircumflexsmall', 'Edieresissmall', 'Igravesmall', 'Iacutesmall',
  9961. 'Icircumflexsmall', 'Idieresissmall', 'Ethsmall', 'Ntildesmall',
  9962. 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall', 'Otildesmall',
  9963. 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall', 'Uacutesmall',
  9964. 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall', 'Thornsmall',
  9965. 'Ydieresissmall'
  9966. ];
  9967. var ExpertSubsetCharset = [
  9968. '.notdef', 'space', 'dollaroldstyle', 'dollarsuperior',
  9969. 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  9970. 'onedotenleader', 'comma', 'hyphen', 'period', 'fraction',
  9971. 'zerooldstyle', 'oneoldstyle', 'twooldstyle', 'threeoldstyle',
  9972. 'fouroldstyle', 'fiveoldstyle', 'sixoldstyle', 'sevenoldstyle',
  9973. 'eightoldstyle', 'nineoldstyle', 'colon', 'semicolon', 'commasuperior',
  9974. 'threequartersemdash', 'periodsuperior', 'asuperior', 'bsuperior',
  9975. 'centsuperior', 'dsuperior', 'esuperior', 'isuperior', 'lsuperior',
  9976. 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  9977. 'tsuperior', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior',
  9978. 'parenrightinferior', 'hyphensuperior', 'colonmonetary', 'onefitted',
  9979. 'rupiah', 'centoldstyle', 'figuredash', 'hypheninferior', 'onequarter',
  9980. 'onehalf', 'threequarters', 'oneeighth', 'threeeighths', 'fiveeighths',
  9981. 'seveneighths', 'onethird', 'twothirds', 'zerosuperior', 'onesuperior',
  9982. 'twosuperior', 'threesuperior', 'foursuperior', 'fivesuperior',
  9983. 'sixsuperior', 'sevensuperior', 'eightsuperior', 'ninesuperior',
  9984. 'zeroinferior', 'oneinferior', 'twoinferior', 'threeinferior',
  9985. 'fourinferior', 'fiveinferior', 'sixinferior', 'seveninferior',
  9986. 'eightinferior', 'nineinferior', 'centinferior', 'dollarinferior',
  9987. 'periodinferior', 'commainferior'
  9988. ];
  9989. var DEFAULT_ICON_SIZE = 22; // px
  9990. var SUPPORTED_TYPES = ['Link', 'Text', 'Widget'];
  9991. var Annotation = (function AnnotationClosure() {
  9992. // 12.5.5: Algorithm: Appearance streams
  9993. function getTransformMatrix(rect, bbox, matrix) {
  9994. var bounds = Util.getAxialAlignedBoundingBox(bbox, matrix);
  9995. var minX = bounds[0];
  9996. var minY = bounds[1];
  9997. var maxX = bounds[2];
  9998. var maxY = bounds[3];
  9999. if (minX === maxX || minY === maxY) {
  10000. // From real-life file, bbox was [0, 0, 0, 0]. In this case,
  10001. // just apply the transform for rect
  10002. return [1, 0, 0, 1, rect[0], rect[1]];
  10003. }
  10004. var xRatio = (rect[2] - rect[0]) / (maxX - minX);
  10005. var yRatio = (rect[3] - rect[1]) / (maxY - minY);
  10006. return [
  10007. xRatio,
  10008. 0,
  10009. 0,
  10010. yRatio,
  10011. rect[0] - minX * xRatio,
  10012. rect[1] - minY * yRatio
  10013. ];
  10014. }
  10015. function getDefaultAppearance(dict) {
  10016. var appearanceState = dict.get('AP');
  10017. if (!isDict(appearanceState)) {
  10018. return;
  10019. }
  10020. var appearance;
  10021. var appearances = appearanceState.get('N');
  10022. if (isDict(appearances)) {
  10023. var as = dict.get('AS');
  10024. if (as && appearances.has(as.name)) {
  10025. appearance = appearances.get(as.name);
  10026. }
  10027. } else {
  10028. appearance = appearances;
  10029. }
  10030. return appearance;
  10031. }
  10032. function Annotation(params) {
  10033. var dict = params.dict;
  10034. var data = this.data = {};
  10035. data.subtype = dict.get('Subtype').name;
  10036. var rect = dict.get('Rect') || [0, 0, 0, 0];
  10037. data.rect = Util.normalizeRect(rect);
  10038. data.annotationFlags = dict.get('F');
  10039. var color = dict.get('C');
  10040. if (!color) {
  10041. // The PDF spec does not mention how a missing color array is interpreted.
  10042. // Adobe Reader seems to default to black in this case.
  10043. data.color = [0, 0, 0];
  10044. } else if (isArray(color)) {
  10045. switch (color.length) {
  10046. case 0:
  10047. // Empty array denotes transparent border.
  10048. data.color = null;
  10049. break;
  10050. case 1:
  10051. // TODO: implement DeviceGray
  10052. break;
  10053. case 3:
  10054. data.color = color;
  10055. break;
  10056. case 4:
  10057. // TODO: implement DeviceCMYK
  10058. break;
  10059. }
  10060. }
  10061. // Some types of annotations have border style dict which has more
  10062. // info than the border array
  10063. if (dict.has('BS')) {
  10064. var borderStyle = dict.get('BS');
  10065. data.borderWidth = borderStyle.has('W') ? borderStyle.get('W') : 1;
  10066. } else {
  10067. var borderArray = dict.get('Border') || [0, 0, 1];
  10068. data.borderWidth = borderArray[2] || 0;
  10069. // TODO: implement proper support for annotations with line dash patterns.
  10070. var dashArray = borderArray[3];
  10071. if (data.borderWidth > 0 && dashArray) {
  10072. if (!isArray(dashArray)) {
  10073. // Ignore the border if dashArray is not actually an array,
  10074. // this is consistent with the behaviour in Adobe Reader.
  10075. data.borderWidth = 0;
  10076. } else {
  10077. var dashArrayLength = dashArray.length;
  10078. if (dashArrayLength > 0) {
  10079. // According to the PDF specification: the elements in a dashArray
  10080. // shall be numbers that are nonnegative and not all equal to zero.
  10081. var isInvalid = false;
  10082. var numPositive = 0;
  10083. for (var i = 0; i < dashArrayLength; i++) {
  10084. var validNumber = (+dashArray[i] >= 0);
  10085. if (!validNumber) {
  10086. isInvalid = true;
  10087. break;
  10088. } else if (dashArray[i] > 0) {
  10089. numPositive++;
  10090. }
  10091. }
  10092. if (isInvalid || numPositive === 0) {
  10093. data.borderWidth = 0;
  10094. }
  10095. }
  10096. }
  10097. }
  10098. }
  10099. this.appearance = getDefaultAppearance(dict);
  10100. data.hasAppearance = !!this.appearance;
  10101. data.id = params.ref.num;
  10102. }
  10103. Annotation.prototype = {
  10104. getData: function Annotation_getData() {
  10105. return this.data;
  10106. },
  10107. isInvisible: function Annotation_isInvisible() {
  10108. var data = this.data;
  10109. if (data && SUPPORTED_TYPES.indexOf(data.subtype) !== -1) {
  10110. return false;
  10111. } else {
  10112. return !!(data &&
  10113. data.annotationFlags && // Default: not invisible
  10114. data.annotationFlags & 0x1); // Invisible
  10115. }
  10116. },
  10117. isViewable: function Annotation_isViewable() {
  10118. var data = this.data;
  10119. return !!(!this.isInvisible() &&
  10120. data &&
  10121. (!data.annotationFlags ||
  10122. !(data.annotationFlags & 0x22)) && // Hidden or NoView
  10123. data.rect); // rectangle is necessary
  10124. },
  10125. isPrintable: function Annotation_isPrintable() {
  10126. var data = this.data;
  10127. return !!(!this.isInvisible() &&
  10128. data &&
  10129. data.annotationFlags && // Default: not printable
  10130. data.annotationFlags & 0x4 && // Print
  10131. !(data.annotationFlags & 0x2) && // Hidden
  10132. data.rect); // rectangle is necessary
  10133. },
  10134. loadResources: function Annotation_loadResources(keys) {
  10135. return new Promise(function (resolve, reject) {
  10136. this.appearance.dict.getAsync('Resources').then(function (resources) {
  10137. if (!resources) {
  10138. resolve();
  10139. return;
  10140. }
  10141. var objectLoader = new ObjectLoader(resources.map,
  10142. keys,
  10143. resources.xref);
  10144. objectLoader.load().then(function() {
  10145. resolve(resources);
  10146. }, reject);
  10147. }, reject);
  10148. }.bind(this));
  10149. },
  10150. getOperatorList: function Annotation_getOperatorList(evaluator) {
  10151. if (!this.appearance) {
  10152. return Promise.resolve(new OperatorList());
  10153. }
  10154. var data = this.data;
  10155. var appearanceDict = this.appearance.dict;
  10156. var resourcesPromise = this.loadResources([
  10157. 'ExtGState',
  10158. 'ColorSpace',
  10159. 'Pattern',
  10160. 'Shading',
  10161. 'XObject',
  10162. 'Font'
  10163. // ProcSet
  10164. // Properties
  10165. ]);
  10166. var bbox = appearanceDict.get('BBox') || [0, 0, 1, 1];
  10167. var matrix = appearanceDict.get('Matrix') || [1, 0, 0, 1, 0 ,0];
  10168. var transform = getTransformMatrix(data.rect, bbox, matrix);
  10169. var self = this;
  10170. return resourcesPromise.then(function(resources) {
  10171. var opList = new OperatorList();
  10172. opList.addOp(OPS.beginAnnotation, [data.rect, transform, matrix]);
  10173. return evaluator.getOperatorList(self.appearance, resources, opList).
  10174. then(function () {
  10175. opList.addOp(OPS.endAnnotation, []);
  10176. self.appearance.reset();
  10177. return opList;
  10178. });
  10179. });
  10180. }
  10181. };
  10182. Annotation.getConstructor =
  10183. function Annotation_getConstructor(subtype, fieldType) {
  10184. if (!subtype) {
  10185. return;
  10186. }
  10187. // TODO(mack): Implement FreeText annotations
  10188. if (subtype === 'Link') {
  10189. return LinkAnnotation;
  10190. } else if (subtype === 'Text') {
  10191. return TextAnnotation;
  10192. } else if (subtype === 'Widget') {
  10193. if (!fieldType) {
  10194. return;
  10195. }
  10196. if (fieldType === 'Tx') {
  10197. return TextWidgetAnnotation;
  10198. } else {
  10199. return WidgetAnnotation;
  10200. }
  10201. } else {
  10202. return Annotation;
  10203. }
  10204. };
  10205. Annotation.fromRef = function Annotation_fromRef(xref, ref) {
  10206. var dict = xref.fetchIfRef(ref);
  10207. if (!isDict(dict)) {
  10208. return;
  10209. }
  10210. var subtype = dict.get('Subtype');
  10211. subtype = isName(subtype) ? subtype.name : '';
  10212. if (!subtype) {
  10213. return;
  10214. }
  10215. var fieldType = Util.getInheritableProperty(dict, 'FT');
  10216. fieldType = isName(fieldType) ? fieldType.name : '';
  10217. var Constructor = Annotation.getConstructor(subtype, fieldType);
  10218. if (!Constructor) {
  10219. return;
  10220. }
  10221. var params = {
  10222. dict: dict,
  10223. ref: ref,
  10224. };
  10225. var annotation = new Constructor(params);
  10226. if (annotation.isViewable() || annotation.isPrintable()) {
  10227. return annotation;
  10228. } else {
  10229. if (SUPPORTED_TYPES.indexOf(subtype) === -1) {
  10230. warn('unimplemented annotation type: ' + subtype);
  10231. }
  10232. }
  10233. };
  10234. Annotation.appendToOperatorList = function Annotation_appendToOperatorList(
  10235. annotations, opList, pdfManager, partialEvaluator, intent) {
  10236. function reject(e) {
  10237. annotationsReadyCapability.reject(e);
  10238. }
  10239. var annotationsReadyCapability = createPromiseCapability();
  10240. var annotationPromises = [];
  10241. for (var i = 0, n = annotations.length; i < n; ++i) {
  10242. if (intent === 'display' && annotations[i].isViewable() ||
  10243. intent === 'print' && annotations[i].isPrintable()) {
  10244. annotationPromises.push(
  10245. annotations[i].getOperatorList(partialEvaluator));
  10246. }
  10247. }
  10248. Promise.all(annotationPromises).then(function(datas) {
  10249. opList.addOp(OPS.beginAnnotations, []);
  10250. for (var i = 0, n = datas.length; i < n; ++i) {
  10251. var annotOpList = datas[i];
  10252. opList.addOpList(annotOpList);
  10253. }
  10254. opList.addOp(OPS.endAnnotations, []);
  10255. annotationsReadyCapability.resolve();
  10256. }, reject);
  10257. return annotationsReadyCapability.promise;
  10258. };
  10259. return Annotation;
  10260. })();
  10261. var WidgetAnnotation = (function WidgetAnnotationClosure() {
  10262. function WidgetAnnotation(params) {
  10263. Annotation.call(this, params);
  10264. var dict = params.dict;
  10265. var data = this.data;
  10266. data.fieldValue = stringToPDFString(
  10267. Util.getInheritableProperty(dict, 'V') || '');
  10268. data.alternativeText = stringToPDFString(dict.get('TU') || '');
  10269. data.defaultAppearance = Util.getInheritableProperty(dict, 'DA') || '';
  10270. var fieldType = Util.getInheritableProperty(dict, 'FT');
  10271. data.fieldType = isName(fieldType) ? fieldType.name : '';
  10272. data.fieldFlags = Util.getInheritableProperty(dict, 'Ff') || 0;
  10273. this.fieldResources = Util.getInheritableProperty(dict, 'DR') || Dict.empty;
  10274. // Building the full field name by collecting the field and
  10275. // its ancestors 'T' data and joining them using '.'.
  10276. var fieldName = [];
  10277. var namedItem = dict;
  10278. var ref = params.ref;
  10279. while (namedItem) {
  10280. var parent = namedItem.get('Parent');
  10281. var parentRef = namedItem.getRaw('Parent');
  10282. var name = namedItem.get('T');
  10283. if (name) {
  10284. fieldName.unshift(stringToPDFString(name));
  10285. } else if (parent && ref) {
  10286. // The field name is absent, that means more than one field
  10287. // with the same name may exist. Replacing the empty name
  10288. // with the '`' plus index in the parent's 'Kids' array.
  10289. // This is not in the PDF spec but necessary to id the
  10290. // the input controls.
  10291. var kids = parent.get('Kids');
  10292. var j, jj;
  10293. for (j = 0, jj = kids.length; j < jj; j++) {
  10294. var kidRef = kids[j];
  10295. if (kidRef.num === ref.num && kidRef.gen === ref.gen) {
  10296. break;
  10297. }
  10298. }
  10299. fieldName.unshift('`' + j);
  10300. }
  10301. namedItem = parent;
  10302. ref = parentRef;
  10303. }
  10304. data.fullName = fieldName.join('.');
  10305. }
  10306. var parent = Annotation.prototype;
  10307. Util.inherit(WidgetAnnotation, Annotation, {
  10308. isViewable: function WidgetAnnotation_isViewable() {
  10309. if (this.data.fieldType === 'Sig') {
  10310. warn('unimplemented annotation type: Widget signature');
  10311. return false;
  10312. }
  10313. return parent.isViewable.call(this);
  10314. }
  10315. });
  10316. return WidgetAnnotation;
  10317. })();
  10318. var TextWidgetAnnotation = (function TextWidgetAnnotationClosure() {
  10319. function TextWidgetAnnotation(params) {
  10320. WidgetAnnotation.call(this, params);
  10321. this.data.textAlignment = Util.getInheritableProperty(params.dict, 'Q');
  10322. this.data.annotationType = AnnotationType.WIDGET;
  10323. this.data.hasHtml = !this.data.hasAppearance && !!this.data.fieldValue;
  10324. }
  10325. Util.inherit(TextWidgetAnnotation, WidgetAnnotation, {
  10326. getOperatorList: function TextWidgetAnnotation_getOperatorList(evaluator) {
  10327. if (this.appearance) {
  10328. return Annotation.prototype.getOperatorList.call(this, evaluator);
  10329. }
  10330. var opList = new OperatorList();
  10331. var data = this.data;
  10332. // Even if there is an appearance stream, ignore it. This is the
  10333. // behaviour used by Adobe Reader.
  10334. if (!data.defaultAppearance) {
  10335. return Promise.resolve(opList);
  10336. }
  10337. var stream = new Stream(stringToBytes(data.defaultAppearance));
  10338. return evaluator.getOperatorList(stream, this.fieldResources, opList).
  10339. then(function () {
  10340. return opList;
  10341. });
  10342. }
  10343. });
  10344. return TextWidgetAnnotation;
  10345. })();
  10346. var InteractiveAnnotation = (function InteractiveAnnotationClosure() {
  10347. function InteractiveAnnotation(params) {
  10348. Annotation.call(this, params);
  10349. this.data.hasHtml = true;
  10350. }
  10351. Util.inherit(InteractiveAnnotation, Annotation, { });
  10352. return InteractiveAnnotation;
  10353. })();
  10354. var TextAnnotation = (function TextAnnotationClosure() {
  10355. function TextAnnotation(params) {
  10356. InteractiveAnnotation.call(this, params);
  10357. var dict = params.dict;
  10358. var data = this.data;
  10359. var content = dict.get('Contents');
  10360. var title = dict.get('T');
  10361. data.annotationType = AnnotationType.TEXT;
  10362. data.content = stringToPDFString(content || '');
  10363. data.title = stringToPDFString(title || '');
  10364. if (data.hasAppearance) {
  10365. data.name = 'NoIcon';
  10366. } else {
  10367. data.rect[1] = data.rect[3] - DEFAULT_ICON_SIZE;
  10368. data.rect[2] = data.rect[0] + DEFAULT_ICON_SIZE;
  10369. data.name = dict.has('Name') ? dict.get('Name').name : 'Note';
  10370. }
  10371. if (dict.has('C')) {
  10372. data.hasBgColor = true;
  10373. }
  10374. }
  10375. Util.inherit(TextAnnotation, InteractiveAnnotation, { });
  10376. return TextAnnotation;
  10377. })();
  10378. var LinkAnnotation = (function LinkAnnotationClosure() {
  10379. function LinkAnnotation(params) {
  10380. InteractiveAnnotation.call(this, params);
  10381. var dict = params.dict;
  10382. var data = this.data;
  10383. data.annotationType = AnnotationType.LINK;
  10384. var action = dict.get('A');
  10385. if (action && isDict(action)) {
  10386. var linkType = action.get('S').name;
  10387. if (linkType === 'URI') {
  10388. var url = action.get('URI');
  10389. if (isName(url)) {
  10390. // Some bad PDFs do not put parentheses around relative URLs.
  10391. url = '/' + url.name;
  10392. } else if (url) {
  10393. url = addDefaultProtocolToUrl(url);
  10394. }
  10395. // TODO: pdf spec mentions urls can be relative to a Base
  10396. // entry in the dictionary.
  10397. if (!isValidUrl(url, false)) {
  10398. url = '';
  10399. }
  10400. // According to ISO 32000-1:2008, section 12.6.4.7,
  10401. // URI should to be encoded in 7-bit ASCII.
  10402. // Some bad PDFs may have URIs in UTF-8 encoding, see Bugzilla 1122280.
  10403. try {
  10404. data.url = stringToUTF8String(url);
  10405. } catch (e) {
  10406. // Fall back to a simple copy.
  10407. data.url = url;
  10408. }
  10409. } else if (linkType === 'GoTo') {
  10410. data.dest = action.get('D');
  10411. } else if (linkType === 'GoToR') {
  10412. var urlDict = action.get('F');
  10413. if (isDict(urlDict)) {
  10414. // We assume that the 'url' is a Filspec dictionary
  10415. // and fetch the url without checking any further
  10416. url = urlDict.get('F') || '';
  10417. }
  10418. // TODO: pdf reference says that GoToR
  10419. // can also have 'NewWindow' attribute
  10420. if (!isValidUrl(url, false)) {
  10421. url = '';
  10422. }
  10423. data.url = url;
  10424. data.dest = action.get('D');
  10425. } else if (linkType === 'Named') {
  10426. data.action = action.get('N').name;
  10427. } else {
  10428. warn('unrecognized link type: ' + linkType);
  10429. }
  10430. } else if (dict.has('Dest')) {
  10431. // simple destination link
  10432. var dest = dict.get('Dest');
  10433. data.dest = isName(dest) ? dest.name : dest;
  10434. }
  10435. }
  10436. // Lets URLs beginning with 'www.' default to using the 'http://' protocol.
  10437. function addDefaultProtocolToUrl(url) {
  10438. if (url && url.indexOf('www.') === 0) {
  10439. return ('http://' + url);
  10440. }
  10441. return url;
  10442. }
  10443. Util.inherit(LinkAnnotation, InteractiveAnnotation, { });
  10444. return LinkAnnotation;
  10445. })();
  10446. var PDFFunction = (function PDFFunctionClosure() {
  10447. var CONSTRUCT_SAMPLED = 0;
  10448. var CONSTRUCT_INTERPOLATED = 2;
  10449. var CONSTRUCT_STICHED = 3;
  10450. var CONSTRUCT_POSTSCRIPT = 4;
  10451. return {
  10452. getSampleArray: function PDFFunction_getSampleArray(size, outputSize, bps,
  10453. str) {
  10454. var i, ii;
  10455. var length = 1;
  10456. for (i = 0, ii = size.length; i < ii; i++) {
  10457. length *= size[i];
  10458. }
  10459. length *= outputSize;
  10460. var array = new Array(length);
  10461. var codeSize = 0;
  10462. var codeBuf = 0;
  10463. // 32 is a valid bps so shifting won't work
  10464. var sampleMul = 1.0 / (Math.pow(2.0, bps) - 1);
  10465. var strBytes = str.getBytes((length * bps + 7) / 8);
  10466. var strIdx = 0;
  10467. for (i = 0; i < length; i++) {
  10468. while (codeSize < bps) {
  10469. codeBuf <<= 8;
  10470. codeBuf |= strBytes[strIdx++];
  10471. codeSize += 8;
  10472. }
  10473. codeSize -= bps;
  10474. array[i] = (codeBuf >> codeSize) * sampleMul;
  10475. codeBuf &= (1 << codeSize) - 1;
  10476. }
  10477. return array;
  10478. },
  10479. getIR: function PDFFunction_getIR(xref, fn) {
  10480. var dict = fn.dict;
  10481. if (!dict) {
  10482. dict = fn;
  10483. }
  10484. var types = [this.constructSampled,
  10485. null,
  10486. this.constructInterpolated,
  10487. this.constructStiched,
  10488. this.constructPostScript];
  10489. var typeNum = dict.get('FunctionType');
  10490. var typeFn = types[typeNum];
  10491. if (!typeFn) {
  10492. error('Unknown type of function');
  10493. }
  10494. return typeFn.call(this, fn, dict, xref);
  10495. },
  10496. fromIR: function PDFFunction_fromIR(IR) {
  10497. var type = IR[0];
  10498. switch (type) {
  10499. case CONSTRUCT_SAMPLED:
  10500. return this.constructSampledFromIR(IR);
  10501. case CONSTRUCT_INTERPOLATED:
  10502. return this.constructInterpolatedFromIR(IR);
  10503. case CONSTRUCT_STICHED:
  10504. return this.constructStichedFromIR(IR);
  10505. //case CONSTRUCT_POSTSCRIPT:
  10506. default:
  10507. return this.constructPostScriptFromIR(IR);
  10508. }
  10509. },
  10510. parse: function PDFFunction_parse(xref, fn) {
  10511. var IR = this.getIR(xref, fn);
  10512. return this.fromIR(IR);
  10513. },
  10514. parseArray: function PDFFunction_parseArray(xref, fnObj) {
  10515. if (!isArray(fnObj)) {
  10516. // not an array -- parsing as regular function
  10517. return this.parse(xref, fnObj);
  10518. }
  10519. var fnArray = [];
  10520. for (var j = 0, jj = fnObj.length; j < jj; j++) {
  10521. var obj = xref.fetchIfRef(fnObj[j]);
  10522. fnArray.push(PDFFunction.parse(xref, obj));
  10523. }
  10524. return function (src, srcOffset, dest, destOffset) {
  10525. for (var i = 0, ii = fnArray.length; i < ii; i++) {
  10526. fnArray[i](src, srcOffset, dest, destOffset + i);
  10527. }
  10528. };
  10529. },
  10530. constructSampled: function PDFFunction_constructSampled(str, dict) {
  10531. function toMultiArray(arr) {
  10532. var inputLength = arr.length;
  10533. var out = [];
  10534. var index = 0;
  10535. for (var i = 0; i < inputLength; i += 2) {
  10536. out[index] = [arr[i], arr[i + 1]];
  10537. ++index;
  10538. }
  10539. return out;
  10540. }
  10541. var domain = dict.get('Domain');
  10542. var range = dict.get('Range');
  10543. if (!domain || !range) {
  10544. error('No domain or range');
  10545. }
  10546. var inputSize = domain.length / 2;
  10547. var outputSize = range.length / 2;
  10548. domain = toMultiArray(domain);
  10549. range = toMultiArray(range);
  10550. var size = dict.get('Size');
  10551. var bps = dict.get('BitsPerSample');
  10552. var order = dict.get('Order') || 1;
  10553. if (order !== 1) {
  10554. // No description how cubic spline interpolation works in PDF32000:2008
  10555. // As in poppler, ignoring order, linear interpolation may work as good
  10556. info('No support for cubic spline interpolation: ' + order);
  10557. }
  10558. var encode = dict.get('Encode');
  10559. if (!encode) {
  10560. encode = [];
  10561. for (var i = 0; i < inputSize; ++i) {
  10562. encode.push(0);
  10563. encode.push(size[i] - 1);
  10564. }
  10565. }
  10566. encode = toMultiArray(encode);
  10567. var decode = dict.get('Decode');
  10568. if (!decode) {
  10569. decode = range;
  10570. } else {
  10571. decode = toMultiArray(decode);
  10572. }
  10573. var samples = this.getSampleArray(size, outputSize, bps, str);
  10574. return [
  10575. CONSTRUCT_SAMPLED, inputSize, domain, encode, decode, samples, size,
  10576. outputSize, Math.pow(2, bps) - 1, range
  10577. ];
  10578. },
  10579. constructSampledFromIR: function PDFFunction_constructSampledFromIR(IR) {
  10580. // See chapter 3, page 109 of the PDF reference
  10581. function interpolate(x, xmin, xmax, ymin, ymax) {
  10582. return ymin + ((x - xmin) * ((ymax - ymin) / (xmax - xmin)));
  10583. }
  10584. return function constructSampledFromIRResult(src, srcOffset,
  10585. dest, destOffset) {
  10586. // See chapter 3, page 110 of the PDF reference.
  10587. var m = IR[1];
  10588. var domain = IR[2];
  10589. var encode = IR[3];
  10590. var decode = IR[4];
  10591. var samples = IR[5];
  10592. var size = IR[6];
  10593. var n = IR[7];
  10594. //var mask = IR[8];
  10595. var range = IR[9];
  10596. // Building the cube vertices: its part and sample index
  10597. // http://rjwagner49.com/Mathematics/Interpolation.pdf
  10598. var cubeVertices = 1 << m;
  10599. var cubeN = new Float64Array(cubeVertices);
  10600. var cubeVertex = new Uint32Array(cubeVertices);
  10601. var i, j;
  10602. for (j = 0; j < cubeVertices; j++) {
  10603. cubeN[j] = 1;
  10604. }
  10605. var k = n, pos = 1;
  10606. // Map x_i to y_j for 0 <= i < m using the sampled function.
  10607. for (i = 0; i < m; ++i) {
  10608. // x_i' = min(max(x_i, Domain_2i), Domain_2i+1)
  10609. var domain_2i = domain[i][0];
  10610. var domain_2i_1 = domain[i][1];
  10611. var xi = Math.min(Math.max(src[srcOffset +i], domain_2i),
  10612. domain_2i_1);
  10613. // e_i = Interpolate(x_i', Domain_2i, Domain_2i+1,
  10614. // Encode_2i, Encode_2i+1)
  10615. var e = interpolate(xi, domain_2i, domain_2i_1,
  10616. encode[i][0], encode[i][1]);
  10617. // e_i' = min(max(e_i, 0), Size_i - 1)
  10618. var size_i = size[i];
  10619. e = Math.min(Math.max(e, 0), size_i - 1);
  10620. // Adjusting the cube: N and vertex sample index
  10621. var e0 = e < size_i - 1 ? Math.floor(e) : e - 1; // e1 = e0 + 1;
  10622. var n0 = e0 + 1 - e; // (e1 - e) / (e1 - e0);
  10623. var n1 = e - e0; // (e - e0) / (e1 - e0);
  10624. var offset0 = e0 * k;
  10625. var offset1 = offset0 + k; // e1 * k
  10626. for (j = 0; j < cubeVertices; j++) {
  10627. if (j & pos) {
  10628. cubeN[j] *= n1;
  10629. cubeVertex[j] += offset1;
  10630. } else {
  10631. cubeN[j] *= n0;
  10632. cubeVertex[j] += offset0;
  10633. }
  10634. }
  10635. k *= size_i;
  10636. pos <<= 1;
  10637. }
  10638. for (j = 0; j < n; ++j) {
  10639. // Sum all cube vertices' samples portions
  10640. var rj = 0;
  10641. for (i = 0; i < cubeVertices; i++) {
  10642. rj += samples[cubeVertex[i] + j] * cubeN[i];
  10643. }
  10644. // r_j' = Interpolate(r_j, 0, 2^BitsPerSample - 1,
  10645. // Decode_2j, Decode_2j+1)
  10646. rj = interpolate(rj, 0, 1, decode[j][0], decode[j][1]);
  10647. // y_j = min(max(r_j, range_2j), range_2j+1)
  10648. dest[destOffset + j] = Math.min(Math.max(rj, range[j][0]),
  10649. range[j][1]);
  10650. }
  10651. };
  10652. },
  10653. constructInterpolated: function PDFFunction_constructInterpolated(str,
  10654. dict) {
  10655. var c0 = dict.get('C0') || [0];
  10656. var c1 = dict.get('C1') || [1];
  10657. var n = dict.get('N');
  10658. if (!isArray(c0) || !isArray(c1)) {
  10659. error('Illegal dictionary for interpolated function');
  10660. }
  10661. var length = c0.length;
  10662. var diff = [];
  10663. for (var i = 0; i < length; ++i) {
  10664. diff.push(c1[i] - c0[i]);
  10665. }
  10666. return [CONSTRUCT_INTERPOLATED, c0, diff, n];
  10667. },
  10668. constructInterpolatedFromIR:
  10669. function PDFFunction_constructInterpolatedFromIR(IR) {
  10670. var c0 = IR[1];
  10671. var diff = IR[2];
  10672. var n = IR[3];
  10673. var length = diff.length;
  10674. return function constructInterpolatedFromIRResult(src, srcOffset,
  10675. dest, destOffset) {
  10676. var x = n === 1 ? src[srcOffset] : Math.pow(src[srcOffset], n);
  10677. for (var j = 0; j < length; ++j) {
  10678. dest[destOffset + j] = c0[j] + (x * diff[j]);
  10679. }
  10680. };
  10681. },
  10682. constructStiched: function PDFFunction_constructStiched(fn, dict, xref) {
  10683. var domain = dict.get('Domain');
  10684. if (!domain) {
  10685. error('No domain');
  10686. }
  10687. var inputSize = domain.length / 2;
  10688. if (inputSize !== 1) {
  10689. error('Bad domain for stiched function');
  10690. }
  10691. var fnRefs = dict.get('Functions');
  10692. var fns = [];
  10693. for (var i = 0, ii = fnRefs.length; i < ii; ++i) {
  10694. fns.push(PDFFunction.getIR(xref, xref.fetchIfRef(fnRefs[i])));
  10695. }
  10696. var bounds = dict.get('Bounds');
  10697. var encode = dict.get('Encode');
  10698. return [CONSTRUCT_STICHED, domain, bounds, encode, fns];
  10699. },
  10700. constructStichedFromIR: function PDFFunction_constructStichedFromIR(IR) {
  10701. var domain = IR[1];
  10702. var bounds = IR[2];
  10703. var encode = IR[3];
  10704. var fnsIR = IR[4];
  10705. var fns = [];
  10706. var tmpBuf = new Float32Array(1);
  10707. for (var i = 0, ii = fnsIR.length; i < ii; i++) {
  10708. fns.push(PDFFunction.fromIR(fnsIR[i]));
  10709. }
  10710. return function constructStichedFromIRResult(src, srcOffset,
  10711. dest, destOffset) {
  10712. var clip = function constructStichedFromIRClip(v, min, max) {
  10713. if (v > max) {
  10714. v = max;
  10715. } else if (v < min) {
  10716. v = min;
  10717. }
  10718. return v;
  10719. };
  10720. // clip to domain
  10721. var v = clip(src[srcOffset], domain[0], domain[1]);
  10722. // calulate which bound the value is in
  10723. for (var i = 0, ii = bounds.length; i < ii; ++i) {
  10724. if (v < bounds[i]) {
  10725. break;
  10726. }
  10727. }
  10728. // encode value into domain of function
  10729. var dmin = domain[0];
  10730. if (i > 0) {
  10731. dmin = bounds[i - 1];
  10732. }
  10733. var dmax = domain[1];
  10734. if (i < bounds.length) {
  10735. dmax = bounds[i];
  10736. }
  10737. var rmin = encode[2 * i];
  10738. var rmax = encode[2 * i + 1];
  10739. tmpBuf[0] = rmin + (v - dmin) * (rmax - rmin) / (dmax - dmin);
  10740. // call the appropriate function
  10741. fns[i](tmpBuf, 0, dest, destOffset);
  10742. };
  10743. },
  10744. constructPostScript: function PDFFunction_constructPostScript(fn, dict,
  10745. xref) {
  10746. var domain = dict.get('Domain');
  10747. var range = dict.get('Range');
  10748. if (!domain) {
  10749. error('No domain.');
  10750. }
  10751. if (!range) {
  10752. error('No range.');
  10753. }
  10754. var lexer = new PostScriptLexer(fn);
  10755. var parser = new PostScriptParser(lexer);
  10756. var code = parser.parse();
  10757. return [CONSTRUCT_POSTSCRIPT, domain, range, code];
  10758. },
  10759. constructPostScriptFromIR: function PDFFunction_constructPostScriptFromIR(
  10760. IR) {
  10761. var domain = IR[1];
  10762. var range = IR[2];
  10763. var code = IR[3];
  10764. var compiled = (new PostScriptCompiler()).compile(code, domain, range);
  10765. if (compiled) {
  10766. // Compiled function consists of simple expressions such as addition,
  10767. // subtraction, Math.max, and also contains 'var' and 'return'
  10768. // statements. See the generation in the PostScriptCompiler below.
  10769. /*jshint -W054 */
  10770. return new Function('src', 'srcOffset', 'dest', 'destOffset', compiled);
  10771. }
  10772. info('Unable to compile PS function');
  10773. var numOutputs = range.length >> 1;
  10774. var numInputs = domain.length >> 1;
  10775. var evaluator = new PostScriptEvaluator(code);
  10776. // Cache the values for a big speed up, the cache size is limited though
  10777. // since the number of possible values can be huge from a PS function.
  10778. var cache = {};
  10779. // The MAX_CACHE_SIZE is set to ~4x the maximum number of distinct values
  10780. // seen in our tests.
  10781. var MAX_CACHE_SIZE = 2048 * 4;
  10782. var cache_available = MAX_CACHE_SIZE;
  10783. var tmpBuf = new Float32Array(numInputs);
  10784. return function constructPostScriptFromIRResult(src, srcOffset,
  10785. dest, destOffset) {
  10786. var i, value;
  10787. var key = '';
  10788. var input = tmpBuf;
  10789. for (i = 0; i < numInputs; i++) {
  10790. value = src[srcOffset + i];
  10791. input[i] = value;
  10792. key += value + '_';
  10793. }
  10794. var cachedValue = cache[key];
  10795. if (cachedValue !== undefined) {
  10796. dest.set(cachedValue, destOffset);
  10797. return;
  10798. }
  10799. var output = new Float32Array(numOutputs);
  10800. var stack = evaluator.execute(input);
  10801. var stackIndex = stack.length - numOutputs;
  10802. for (i = 0; i < numOutputs; i++) {
  10803. value = stack[stackIndex + i];
  10804. var bound = range[i * 2];
  10805. if (value < bound) {
  10806. value = bound;
  10807. } else {
  10808. bound = range[i * 2 +1];
  10809. if (value > bound) {
  10810. value = bound;
  10811. }
  10812. }
  10813. output[i] = value;
  10814. }
  10815. if (cache_available > 0) {
  10816. cache_available--;
  10817. cache[key] = output;
  10818. }
  10819. dest.set(output, destOffset);
  10820. };
  10821. }
  10822. };
  10823. })();
  10824. function isPDFFunction(v) {
  10825. var fnDict;
  10826. if (typeof v !== 'object') {
  10827. return false;
  10828. } else if (isDict(v)) {
  10829. fnDict = v;
  10830. } else if (isStream(v)) {
  10831. fnDict = v.dict;
  10832. } else {
  10833. return false;
  10834. }
  10835. return fnDict.has('FunctionType');
  10836. }
  10837. var PostScriptStack = (function PostScriptStackClosure() {
  10838. var MAX_STACK_SIZE = 100;
  10839. function PostScriptStack(initialStack) {
  10840. this.stack = !initialStack ? [] :
  10841. Array.prototype.slice.call(initialStack, 0);
  10842. }
  10843. PostScriptStack.prototype = {
  10844. push: function PostScriptStack_push(value) {
  10845. if (this.stack.length >= MAX_STACK_SIZE) {
  10846. error('PostScript function stack overflow.');
  10847. }
  10848. this.stack.push(value);
  10849. },
  10850. pop: function PostScriptStack_pop() {
  10851. if (this.stack.length <= 0) {
  10852. error('PostScript function stack underflow.');
  10853. }
  10854. return this.stack.pop();
  10855. },
  10856. copy: function PostScriptStack_copy(n) {
  10857. if (this.stack.length + n >= MAX_STACK_SIZE) {
  10858. error('PostScript function stack overflow.');
  10859. }
  10860. var stack = this.stack;
  10861. for (var i = stack.length - n, j = n - 1; j >= 0; j--, i++) {
  10862. stack.push(stack[i]);
  10863. }
  10864. },
  10865. index: function PostScriptStack_index(n) {
  10866. this.push(this.stack[this.stack.length - n - 1]);
  10867. },
  10868. // rotate the last n stack elements p times
  10869. roll: function PostScriptStack_roll(n, p) {
  10870. var stack = this.stack;
  10871. var l = stack.length - n;
  10872. var r = stack.length - 1, c = l + (p - Math.floor(p / n) * n), i, j, t;
  10873. for (i = l, j = r; i < j; i++, j--) {
  10874. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  10875. }
  10876. for (i = l, j = c - 1; i < j; i++, j--) {
  10877. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  10878. }
  10879. for (i = c, j = r; i < j; i++, j--) {
  10880. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  10881. }
  10882. }
  10883. };
  10884. return PostScriptStack;
  10885. })();
  10886. var PostScriptEvaluator = (function PostScriptEvaluatorClosure() {
  10887. function PostScriptEvaluator(operators) {
  10888. this.operators = operators;
  10889. }
  10890. PostScriptEvaluator.prototype = {
  10891. execute: function PostScriptEvaluator_execute(initialStack) {
  10892. var stack = new PostScriptStack(initialStack);
  10893. var counter = 0;
  10894. var operators = this.operators;
  10895. var length = operators.length;
  10896. var operator, a, b;
  10897. while (counter < length) {
  10898. operator = operators[counter++];
  10899. if (typeof operator === 'number') {
  10900. // Operator is really an operand and should be pushed to the stack.
  10901. stack.push(operator);
  10902. continue;
  10903. }
  10904. switch (operator) {
  10905. // non standard ps operators
  10906. case 'jz': // jump if false
  10907. b = stack.pop();
  10908. a = stack.pop();
  10909. if (!a) {
  10910. counter = b;
  10911. }
  10912. break;
  10913. case 'j': // jump
  10914. a = stack.pop();
  10915. counter = a;
  10916. break;
  10917. // all ps operators in alphabetical order (excluding if/ifelse)
  10918. case 'abs':
  10919. a = stack.pop();
  10920. stack.push(Math.abs(a));
  10921. break;
  10922. case 'add':
  10923. b = stack.pop();
  10924. a = stack.pop();
  10925. stack.push(a + b);
  10926. break;
  10927. case 'and':
  10928. b = stack.pop();
  10929. a = stack.pop();
  10930. if (isBool(a) && isBool(b)) {
  10931. stack.push(a && b);
  10932. } else {
  10933. stack.push(a & b);
  10934. }
  10935. break;
  10936. case 'atan':
  10937. a = stack.pop();
  10938. stack.push(Math.atan(a));
  10939. break;
  10940. case 'bitshift':
  10941. b = stack.pop();
  10942. a = stack.pop();
  10943. if (a > 0) {
  10944. stack.push(a << b);
  10945. } else {
  10946. stack.push(a >> b);
  10947. }
  10948. break;
  10949. case 'ceiling':
  10950. a = stack.pop();
  10951. stack.push(Math.ceil(a));
  10952. break;
  10953. case 'copy':
  10954. a = stack.pop();
  10955. stack.copy(a);
  10956. break;
  10957. case 'cos':
  10958. a = stack.pop();
  10959. stack.push(Math.cos(a));
  10960. break;
  10961. case 'cvi':
  10962. a = stack.pop() | 0;
  10963. stack.push(a);
  10964. break;
  10965. case 'cvr':
  10966. // noop
  10967. break;
  10968. case 'div':
  10969. b = stack.pop();
  10970. a = stack.pop();
  10971. stack.push(a / b);
  10972. break;
  10973. case 'dup':
  10974. stack.copy(1);
  10975. break;
  10976. case 'eq':
  10977. b = stack.pop();
  10978. a = stack.pop();
  10979. stack.push(a === b);
  10980. break;
  10981. case 'exch':
  10982. stack.roll(2, 1);
  10983. break;
  10984. case 'exp':
  10985. b = stack.pop();
  10986. a = stack.pop();
  10987. stack.push(Math.pow(a, b));
  10988. break;
  10989. case 'false':
  10990. stack.push(false);
  10991. break;
  10992. case 'floor':
  10993. a = stack.pop();
  10994. stack.push(Math.floor(a));
  10995. break;
  10996. case 'ge':
  10997. b = stack.pop();
  10998. a = stack.pop();
  10999. stack.push(a >= b);
  11000. break;
  11001. case 'gt':
  11002. b = stack.pop();
  11003. a = stack.pop();
  11004. stack.push(a > b);
  11005. break;
  11006. case 'idiv':
  11007. b = stack.pop();
  11008. a = stack.pop();
  11009. stack.push((a / b) | 0);
  11010. break;
  11011. case 'index':
  11012. a = stack.pop();
  11013. stack.index(a);
  11014. break;
  11015. case 'le':
  11016. b = stack.pop();
  11017. a = stack.pop();
  11018. stack.push(a <= b);
  11019. break;
  11020. case 'ln':
  11021. a = stack.pop();
  11022. stack.push(Math.log(a));
  11023. break;
  11024. case 'log':
  11025. a = stack.pop();
  11026. stack.push(Math.log(a) / Math.LN10);
  11027. break;
  11028. case 'lt':
  11029. b = stack.pop();
  11030. a = stack.pop();
  11031. stack.push(a < b);
  11032. break;
  11033. case 'mod':
  11034. b = stack.pop();
  11035. a = stack.pop();
  11036. stack.push(a % b);
  11037. break;
  11038. case 'mul':
  11039. b = stack.pop();
  11040. a = stack.pop();
  11041. stack.push(a * b);
  11042. break;
  11043. case 'ne':
  11044. b = stack.pop();
  11045. a = stack.pop();
  11046. stack.push(a !== b);
  11047. break;
  11048. case 'neg':
  11049. a = stack.pop();
  11050. stack.push(-a);
  11051. break;
  11052. case 'not':
  11053. a = stack.pop();
  11054. if (isBool(a)) {
  11055. stack.push(!a);
  11056. } else {
  11057. stack.push(~a);
  11058. }
  11059. break;
  11060. case 'or':
  11061. b = stack.pop();
  11062. a = stack.pop();
  11063. if (isBool(a) && isBool(b)) {
  11064. stack.push(a || b);
  11065. } else {
  11066. stack.push(a | b);
  11067. }
  11068. break;
  11069. case 'pop':
  11070. stack.pop();
  11071. break;
  11072. case 'roll':
  11073. b = stack.pop();
  11074. a = stack.pop();
  11075. stack.roll(a, b);
  11076. break;
  11077. case 'round':
  11078. a = stack.pop();
  11079. stack.push(Math.round(a));
  11080. break;
  11081. case 'sin':
  11082. a = stack.pop();
  11083. stack.push(Math.sin(a));
  11084. break;
  11085. case 'sqrt':
  11086. a = stack.pop();
  11087. stack.push(Math.sqrt(a));
  11088. break;
  11089. case 'sub':
  11090. b = stack.pop();
  11091. a = stack.pop();
  11092. stack.push(a - b);
  11093. break;
  11094. case 'true':
  11095. stack.push(true);
  11096. break;
  11097. case 'truncate':
  11098. a = stack.pop();
  11099. a = a < 0 ? Math.ceil(a) : Math.floor(a);
  11100. stack.push(a);
  11101. break;
  11102. case 'xor':
  11103. b = stack.pop();
  11104. a = stack.pop();
  11105. if (isBool(a) && isBool(b)) {
  11106. stack.push(a !== b);
  11107. } else {
  11108. stack.push(a ^ b);
  11109. }
  11110. break;
  11111. default:
  11112. error('Unknown operator ' + operator);
  11113. break;
  11114. }
  11115. }
  11116. return stack.stack;
  11117. }
  11118. };
  11119. return PostScriptEvaluator;
  11120. })();
  11121. // Most of the PDFs functions consist of simple operations such as:
  11122. // roll, exch, sub, cvr, pop, index, dup, mul, if, gt, add.
  11123. //
  11124. // We can compile most of such programs, and at the same moment, we can
  11125. // optimize some expressions using basic math properties. Keeping track of
  11126. // min/max values will allow us to avoid extra Math.min/Math.max calls.
  11127. var PostScriptCompiler = (function PostScriptCompilerClosure() {
  11128. function AstNode(type) {
  11129. this.type = type;
  11130. }
  11131. AstNode.prototype.visit = function (visitor) {
  11132. throw new Error('abstract method');
  11133. };
  11134. function AstArgument(index, min, max) {
  11135. AstNode.call(this, 'args');
  11136. this.index = index;
  11137. this.min = min;
  11138. this.max = max;
  11139. }
  11140. AstArgument.prototype = Object.create(AstNode.prototype);
  11141. AstArgument.prototype.visit = function (visitor) {
  11142. visitor.visitArgument(this);
  11143. };
  11144. function AstLiteral(number) {
  11145. AstNode.call(this, 'literal');
  11146. this.number = number;
  11147. this.min = number;
  11148. this.max = number;
  11149. }
  11150. AstLiteral.prototype = Object.create(AstNode.prototype);
  11151. AstLiteral.prototype.visit = function (visitor) {
  11152. visitor.visitLiteral(this);
  11153. };
  11154. function AstBinaryOperation(op, arg1, arg2, min, max) {
  11155. AstNode.call(this, 'binary');
  11156. this.op = op;
  11157. this.arg1 = arg1;
  11158. this.arg2 = arg2;
  11159. this.min = min;
  11160. this.max = max;
  11161. }
  11162. AstBinaryOperation.prototype = Object.create(AstNode.prototype);
  11163. AstBinaryOperation.prototype.visit = function (visitor) {
  11164. visitor.visitBinaryOperation(this);
  11165. };
  11166. function AstMin(arg, max) {
  11167. AstNode.call(this, 'max');
  11168. this.arg = arg;
  11169. this.min = arg.min;
  11170. this.max = max;
  11171. }
  11172. AstMin.prototype = Object.create(AstNode.prototype);
  11173. AstMin.prototype.visit = function (visitor) {
  11174. visitor.visitMin(this);
  11175. };
  11176. function AstVariable(index, min, max) {
  11177. AstNode.call(this, 'var');
  11178. this.index = index;
  11179. this.min = min;
  11180. this.max = max;
  11181. }
  11182. AstVariable.prototype = Object.create(AstNode.prototype);
  11183. AstVariable.prototype.visit = function (visitor) {
  11184. visitor.visitVariable(this);
  11185. };
  11186. function AstVariableDefinition(variable, arg) {
  11187. AstNode.call(this, 'definition');
  11188. this.variable = variable;
  11189. this.arg = arg;
  11190. }
  11191. AstVariableDefinition.prototype = Object.create(AstNode.prototype);
  11192. AstVariableDefinition.prototype.visit = function (visitor) {
  11193. visitor.visitVariableDefinition(this);
  11194. };
  11195. function ExpressionBuilderVisitor() {
  11196. this.parts = [];
  11197. }
  11198. ExpressionBuilderVisitor.prototype = {
  11199. visitArgument: function (arg) {
  11200. this.parts.push('Math.max(', arg.min, ', Math.min(',
  11201. arg.max, ', src[srcOffset + ', arg.index, ']))');
  11202. },
  11203. visitVariable: function (variable) {
  11204. this.parts.push('v', variable.index);
  11205. },
  11206. visitLiteral: function (literal) {
  11207. this.parts.push(literal.number);
  11208. },
  11209. visitBinaryOperation: function (operation) {
  11210. this.parts.push('(');
  11211. operation.arg1.visit(this);
  11212. this.parts.push(' ', operation.op, ' ');
  11213. operation.arg2.visit(this);
  11214. this.parts.push(')');
  11215. },
  11216. visitVariableDefinition: function (definition) {
  11217. this.parts.push('var ');
  11218. definition.variable.visit(this);
  11219. this.parts.push(' = ');
  11220. definition.arg.visit(this);
  11221. this.parts.push(';');
  11222. },
  11223. visitMin: function (max) {
  11224. this.parts.push('Math.min(');
  11225. max.arg.visit(this);
  11226. this.parts.push(', ', max.max, ')');
  11227. },
  11228. toString: function () {
  11229. return this.parts.join('');
  11230. }
  11231. };
  11232. function buildAddOperation(num1, num2) {
  11233. if (num2.type === 'literal' && num2.number === 0) {
  11234. // optimization: second operand is 0
  11235. return num1;
  11236. }
  11237. if (num1.type === 'literal' && num1.number === 0) {
  11238. // optimization: first operand is 0
  11239. return num2;
  11240. }
  11241. if (num2.type === 'literal' && num1.type === 'literal') {
  11242. // optimization: operands operand are literals
  11243. return new AstLiteral(num1.number + num2.number);
  11244. }
  11245. return new AstBinaryOperation('+', num1, num2,
  11246. num1.min + num2.min, num1.max + num2.max);
  11247. }
  11248. function buildMulOperation(num1, num2) {
  11249. if (num2.type === 'literal') {
  11250. // optimization: second operands is a literal...
  11251. if (num2.number === 0) {
  11252. return new AstLiteral(0); // and it's 0
  11253. } else if (num2.number === 1) {
  11254. return num1; // and it's 1
  11255. } else if (num1.type === 'literal') {
  11256. // ... and first operands is a literal too
  11257. return new AstLiteral(num1.number * num2.number);
  11258. }
  11259. }
  11260. if (num1.type === 'literal') {
  11261. // optimization: first operands is a literal...
  11262. if (num1.number === 0) {
  11263. return new AstLiteral(0); // and it's 0
  11264. } else if (num1.number === 1) {
  11265. return num2; // and it's 1
  11266. }
  11267. }
  11268. var min = Math.min(num1.min * num2.min, num1.min * num2.max,
  11269. num1.max * num2.min, num1.max * num2.max);
  11270. var max = Math.max(num1.min * num2.min, num1.min * num2.max,
  11271. num1.max * num2.min, num1.max * num2.max);
  11272. return new AstBinaryOperation('*', num1, num2, min, max);
  11273. }
  11274. function buildSubOperation(num1, num2) {
  11275. if (num2.type === 'literal') {
  11276. // optimization: second operands is a literal...
  11277. if (num2.number === 0) {
  11278. return num1; // ... and it's 0
  11279. } else if (num1.type === 'literal') {
  11280. // ... and first operands is a literal too
  11281. return new AstLiteral(num1.number - num2.number);
  11282. }
  11283. }
  11284. if (num2.type === 'binary' && num2.op === '-' &&
  11285. num1.type === 'literal' && num1.number === 1 &&
  11286. num2.arg1.type === 'literal' && num2.arg1.number === 1) {
  11287. // optimization for case: 1 - (1 - x)
  11288. return num2.arg2;
  11289. }
  11290. return new AstBinaryOperation('-', num1, num2,
  11291. num1.min - num2.max, num1.max - num2.min);
  11292. }
  11293. function buildMinOperation(num1, max) {
  11294. if (num1.min >= max) {
  11295. // optimization: num1 min value is not less than required max
  11296. return new AstLiteral(max); // just returning max
  11297. } else if (num1.max <= max) {
  11298. // optimization: num1 max value is not greater than required max
  11299. return num1; // just returning an argument
  11300. }
  11301. return new AstMin(num1, max);
  11302. }
  11303. function PostScriptCompiler() {}
  11304. PostScriptCompiler.prototype = {
  11305. compile: function PostScriptCompiler_compile(code, domain, range) {
  11306. var stack = [];
  11307. var i, ii;
  11308. var instructions = [];
  11309. var inputSize = domain.length >> 1, outputSize = range.length >> 1;
  11310. var lastRegister = 0;
  11311. var n, j, min, max;
  11312. var num1, num2, ast1, ast2, tmpVar, item;
  11313. for (i = 0; i < inputSize; i++) {
  11314. stack.push(new AstArgument(i, domain[i * 2], domain[i * 2 + 1]));
  11315. }
  11316. for (i = 0, ii = code.length; i < ii; i++) {
  11317. item = code[i];
  11318. if (typeof item === 'number') {
  11319. stack.push(new AstLiteral(item));
  11320. continue;
  11321. }
  11322. switch (item) {
  11323. case 'add':
  11324. if (stack.length < 2) {
  11325. return null;
  11326. }
  11327. num2 = stack.pop();
  11328. num1 = stack.pop();
  11329. stack.push(buildAddOperation(num1, num2));
  11330. break;
  11331. case 'cvr':
  11332. if (stack.length < 1) {
  11333. return null;
  11334. }
  11335. break;
  11336. case 'mul':
  11337. if (stack.length < 2) {
  11338. return null;
  11339. }
  11340. num2 = stack.pop();
  11341. num1 = stack.pop();
  11342. stack.push(buildMulOperation(num1, num2));
  11343. break;
  11344. case 'sub':
  11345. if (stack.length < 2) {
  11346. return null;
  11347. }
  11348. num2 = stack.pop();
  11349. num1 = stack.pop();
  11350. stack.push(buildSubOperation(num1, num2));
  11351. break;
  11352. case 'exch':
  11353. if (stack.length < 2) {
  11354. return null;
  11355. }
  11356. ast1 = stack.pop(); ast2 = stack.pop();
  11357. stack.push(ast1, ast2);
  11358. break;
  11359. case 'pop':
  11360. if (stack.length < 1) {
  11361. return null;
  11362. }
  11363. stack.pop();
  11364. break;
  11365. case 'index':
  11366. if (stack.length < 1) {
  11367. return null;
  11368. }
  11369. num1 = stack.pop();
  11370. if (num1.type !== 'literal') {
  11371. return null;
  11372. }
  11373. n = num1.number;
  11374. if (n < 0 || (n|0) !== n || stack.length < n) {
  11375. return null;
  11376. }
  11377. ast1 = stack[stack.length - n - 1];
  11378. if (ast1.type === 'literal' || ast1.type === 'var') {
  11379. stack.push(ast1);
  11380. break;
  11381. }
  11382. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  11383. stack[stack.length - n - 1] = tmpVar;
  11384. stack.push(tmpVar);
  11385. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  11386. break;
  11387. case 'dup':
  11388. if (stack.length < 1) {
  11389. return null;
  11390. }
  11391. if (typeof code[i + 1] === 'number' && code[i + 2] === 'gt' &&
  11392. code[i + 3] === i + 7 && code[i + 4] === 'jz' &&
  11393. code[i + 5] === 'pop' && code[i + 6] === code[i + 1]) {
  11394. // special case of the commands sequence for the min operation
  11395. num1 = stack.pop();
  11396. stack.push(buildMinOperation(num1, code[i + 1]));
  11397. i += 6;
  11398. break;
  11399. }
  11400. ast1 = stack[stack.length - 1];
  11401. if (ast1.type === 'literal' || ast1.type === 'var') {
  11402. // we don't have to save into intermediate variable a literal or
  11403. // variable.
  11404. stack.push(ast1);
  11405. break;
  11406. }
  11407. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  11408. stack[stack.length - 1] = tmpVar;
  11409. stack.push(tmpVar);
  11410. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  11411. break;
  11412. case 'roll':
  11413. if (stack.length < 2) {
  11414. return null;
  11415. }
  11416. num2 = stack.pop();
  11417. num1 = stack.pop();
  11418. if (num2.type !== 'literal' || num1.type !== 'literal') {
  11419. // both roll operands must be numbers
  11420. return null;
  11421. }
  11422. j = num2.number;
  11423. n = num1.number;
  11424. if (n <= 0 || (n|0) !== n || (j|0) !== j || stack.length < n) {
  11425. // ... and integers
  11426. return null;
  11427. }
  11428. j = ((j % n) + n) % n;
  11429. if (j === 0) {
  11430. break; // just skipping -- there are nothing to rotate
  11431. }
  11432. Array.prototype.push.apply(stack,
  11433. stack.splice(stack.length - n, n - j));
  11434. break;
  11435. default:
  11436. return null; // unsupported operator
  11437. }
  11438. }
  11439. if (stack.length !== outputSize) {
  11440. return null;
  11441. }
  11442. var result = [];
  11443. instructions.forEach(function (instruction) {
  11444. var statementBuilder = new ExpressionBuilderVisitor();
  11445. instruction.visit(statementBuilder);
  11446. result.push(statementBuilder.toString());
  11447. });
  11448. stack.forEach(function (expr, i) {
  11449. var statementBuilder = new ExpressionBuilderVisitor();
  11450. expr.visit(statementBuilder);
  11451. var min = range[i * 2], max = range[i * 2 + 1];
  11452. var out = [statementBuilder.toString()];
  11453. if (min > expr.min) {
  11454. out.unshift('Math.max(', min, ', ');
  11455. out.push(')');
  11456. }
  11457. if (max < expr.max) {
  11458. out.unshift('Math.min(', max, ', ');
  11459. out.push(')');
  11460. }
  11461. out.unshift('dest[destOffset + ', i, '] = ');
  11462. out.push(';');
  11463. result.push(out.join(''));
  11464. });
  11465. return result.join('\n');
  11466. }
  11467. };
  11468. return PostScriptCompiler;
  11469. })();
  11470. var ColorSpace = (function ColorSpaceClosure() {
  11471. // Constructor should define this.numComps, this.defaultColor, this.name
  11472. function ColorSpace() {
  11473. error('should not call ColorSpace constructor');
  11474. }
  11475. ColorSpace.prototype = {
  11476. /**
  11477. * Converts the color value to the RGB color. The color components are
  11478. * located in the src array starting from the srcOffset. Returns the array
  11479. * of the rgb components, each value ranging from [0,255].
  11480. */
  11481. getRgb: function ColorSpace_getRgb(src, srcOffset) {
  11482. var rgb = new Uint8Array(3);
  11483. this.getRgbItem(src, srcOffset, rgb, 0);
  11484. return rgb;
  11485. },
  11486. /**
  11487. * Converts the color value to the RGB color, similar to the getRgb method.
  11488. * The result placed into the dest array starting from the destOffset.
  11489. */
  11490. getRgbItem: function ColorSpace_getRgbItem(src, srcOffset,
  11491. dest, destOffset) {
  11492. error('Should not call ColorSpace.getRgbItem');
  11493. },
  11494. /**
  11495. * Converts the specified number of the color values to the RGB colors.
  11496. * The colors are located in the src array starting from the srcOffset.
  11497. * The result is placed into the dest array starting from the destOffset.
  11498. * The src array items shall be in [0,2^bits) range, the dest array items
  11499. * will be in [0,255] range. alpha01 indicates how many alpha components
  11500. * there are in the dest array; it will be either 0 (RGB array) or 1 (RGBA
  11501. * array).
  11502. */
  11503. getRgbBuffer: function ColorSpace_getRgbBuffer(src, srcOffset, count,
  11504. dest, destOffset, bits,
  11505. alpha01) {
  11506. error('Should not call ColorSpace.getRgbBuffer');
  11507. },
  11508. /**
  11509. * Determines the number of bytes required to store the result of the
  11510. * conversion done by the getRgbBuffer method. As in getRgbBuffer,
  11511. * |alpha01| is either 0 (RGB output) or 1 (RGBA output).
  11512. */
  11513. getOutputLength: function ColorSpace_getOutputLength(inputLength,
  11514. alpha01) {
  11515. error('Should not call ColorSpace.getOutputLength');
  11516. },
  11517. /**
  11518. * Returns true if source data will be equal the result/output data.
  11519. */
  11520. isPassthrough: function ColorSpace_isPassthrough(bits) {
  11521. return false;
  11522. },
  11523. /**
  11524. * Fills in the RGB colors in the destination buffer. alpha01 indicates
  11525. * how many alpha components there are in the dest array; it will be either
  11526. * 0 (RGB array) or 1 (RGBA array).
  11527. */
  11528. fillRgb: function ColorSpace_fillRgb(dest, originalWidth,
  11529. originalHeight, width, height,
  11530. actualHeight, bpc, comps, alpha01) {
  11531. var count = originalWidth * originalHeight;
  11532. var rgbBuf = null;
  11533. var numComponentColors = 1 << bpc;
  11534. var needsResizing = originalHeight !== height || originalWidth !== width;
  11535. var i, ii;
  11536. if (this.isPassthrough(bpc)) {
  11537. rgbBuf = comps;
  11538. } else if (this.numComps === 1 && count > numComponentColors &&
  11539. this.name !== 'DeviceGray' && this.name !== 'DeviceRGB') {
  11540. // Optimization: create a color map when there is just one component and
  11541. // we are converting more colors than the size of the color map. We
  11542. // don't build the map if the colorspace is gray or rgb since those
  11543. // methods are faster than building a map. This mainly offers big speed
  11544. // ups for indexed and alternate colorspaces.
  11545. //
  11546. // TODO it may be worth while to cache the color map. While running
  11547. // testing I never hit a cache so I will leave that out for now (perhaps
  11548. // we are reparsing colorspaces too much?).
  11549. var allColors = bpc <= 8 ? new Uint8Array(numComponentColors) :
  11550. new Uint16Array(numComponentColors);
  11551. var key;
  11552. for (i = 0; i < numComponentColors; i++) {
  11553. allColors[i] = i;
  11554. }
  11555. var colorMap = new Uint8Array(numComponentColors * 3);
  11556. this.getRgbBuffer(allColors, 0, numComponentColors, colorMap, 0, bpc,
  11557. /* alpha01 = */ 0);
  11558. var destPos, rgbPos;
  11559. if (!needsResizing) {
  11560. // Fill in the RGB values directly into |dest|.
  11561. destPos = 0;
  11562. for (i = 0; i < count; ++i) {
  11563. key = comps[i] * 3;
  11564. dest[destPos++] = colorMap[key];
  11565. dest[destPos++] = colorMap[key + 1];
  11566. dest[destPos++] = colorMap[key + 2];
  11567. destPos += alpha01;
  11568. }
  11569. } else {
  11570. rgbBuf = new Uint8Array(count * 3);
  11571. rgbPos = 0;
  11572. for (i = 0; i < count; ++i) {
  11573. key = comps[i] * 3;
  11574. rgbBuf[rgbPos++] = colorMap[key];
  11575. rgbBuf[rgbPos++] = colorMap[key + 1];
  11576. rgbBuf[rgbPos++] = colorMap[key + 2];
  11577. }
  11578. }
  11579. } else {
  11580. if (!needsResizing) {
  11581. // Fill in the RGB values directly into |dest|.
  11582. this.getRgbBuffer(comps, 0, width * actualHeight, dest, 0, bpc,
  11583. alpha01);
  11584. } else {
  11585. rgbBuf = new Uint8Array(count * 3);
  11586. this.getRgbBuffer(comps, 0, count, rgbBuf, 0, bpc,
  11587. /* alpha01 = */ 0);
  11588. }
  11589. }
  11590. if (rgbBuf) {
  11591. if (needsResizing) {
  11592. PDFImage.resize(rgbBuf, bpc, 3, originalWidth, originalHeight, width,
  11593. height, dest, alpha01);
  11594. } else {
  11595. rgbPos = 0;
  11596. destPos = 0;
  11597. for (i = 0, ii = width * actualHeight; i < ii; i++) {
  11598. dest[destPos++] = rgbBuf[rgbPos++];
  11599. dest[destPos++] = rgbBuf[rgbPos++];
  11600. dest[destPos++] = rgbBuf[rgbPos++];
  11601. destPos += alpha01;
  11602. }
  11603. }
  11604. }
  11605. },
  11606. /**
  11607. * True if the colorspace has components in the default range of [0, 1].
  11608. * This should be true for all colorspaces except for lab color spaces
  11609. * which are [0,100], [-128, 127], [-128, 127].
  11610. */
  11611. usesZeroToOneRange: true
  11612. };
  11613. ColorSpace.parse = function ColorSpace_parse(cs, xref, res) {
  11614. var IR = ColorSpace.parseToIR(cs, xref, res);
  11615. if (IR instanceof AlternateCS) {
  11616. return IR;
  11617. }
  11618. return ColorSpace.fromIR(IR);
  11619. };
  11620. ColorSpace.fromIR = function ColorSpace_fromIR(IR) {
  11621. var name = isArray(IR) ? IR[0] : IR;
  11622. var whitePoint, blackPoint, gamma;
  11623. switch (name) {
  11624. case 'DeviceGrayCS':
  11625. return this.singletons.gray;
  11626. case 'DeviceRgbCS':
  11627. return this.singletons.rgb;
  11628. case 'DeviceCmykCS':
  11629. return this.singletons.cmyk;
  11630. case 'CalGrayCS':
  11631. whitePoint = IR[1].WhitePoint;
  11632. blackPoint = IR[1].BlackPoint;
  11633. gamma = IR[1].Gamma;
  11634. return new CalGrayCS(whitePoint, blackPoint, gamma);
  11635. case 'CalRGBCS':
  11636. whitePoint = IR[1].WhitePoint;
  11637. blackPoint = IR[1].BlackPoint;
  11638. gamma = IR[1].Gamma;
  11639. var matrix = IR[1].Matrix;
  11640. return new CalRGBCS(whitePoint, blackPoint, gamma, matrix);
  11641. case 'PatternCS':
  11642. var basePatternCS = IR[1];
  11643. if (basePatternCS) {
  11644. basePatternCS = ColorSpace.fromIR(basePatternCS);
  11645. }
  11646. return new PatternCS(basePatternCS);
  11647. case 'IndexedCS':
  11648. var baseIndexedCS = IR[1];
  11649. var hiVal = IR[2];
  11650. var lookup = IR[3];
  11651. return new IndexedCS(ColorSpace.fromIR(baseIndexedCS), hiVal, lookup);
  11652. case 'AlternateCS':
  11653. var numComps = IR[1];
  11654. var alt = IR[2];
  11655. var tintFnIR = IR[3];
  11656. return new AlternateCS(numComps, ColorSpace.fromIR(alt),
  11657. PDFFunction.fromIR(tintFnIR));
  11658. case 'LabCS':
  11659. whitePoint = IR[1].WhitePoint;
  11660. blackPoint = IR[1].BlackPoint;
  11661. var range = IR[1].Range;
  11662. return new LabCS(whitePoint, blackPoint, range);
  11663. default:
  11664. error('Unknown name ' + name);
  11665. }
  11666. return null;
  11667. };
  11668. ColorSpace.parseToIR = function ColorSpace_parseToIR(cs, xref, res) {
  11669. if (isName(cs)) {
  11670. var colorSpaces = res.get('ColorSpace');
  11671. if (isDict(colorSpaces)) {
  11672. var refcs = colorSpaces.get(cs.name);
  11673. if (refcs) {
  11674. cs = refcs;
  11675. }
  11676. }
  11677. }
  11678. cs = xref.fetchIfRef(cs);
  11679. var mode;
  11680. if (isName(cs)) {
  11681. mode = cs.name;
  11682. this.mode = mode;
  11683. switch (mode) {
  11684. case 'DeviceGray':
  11685. case 'G':
  11686. return 'DeviceGrayCS';
  11687. case 'DeviceRGB':
  11688. case 'RGB':
  11689. return 'DeviceRgbCS';
  11690. case 'DeviceCMYK':
  11691. case 'CMYK':
  11692. return 'DeviceCmykCS';
  11693. case 'Pattern':
  11694. return ['PatternCS', null];
  11695. default:
  11696. error('unrecognized colorspace ' + mode);
  11697. }
  11698. } else if (isArray(cs)) {
  11699. mode = cs[0].name;
  11700. this.mode = mode;
  11701. var numComps, params;
  11702. switch (mode) {
  11703. case 'DeviceGray':
  11704. case 'G':
  11705. return 'DeviceGrayCS';
  11706. case 'DeviceRGB':
  11707. case 'RGB':
  11708. return 'DeviceRgbCS';
  11709. case 'DeviceCMYK':
  11710. case 'CMYK':
  11711. return 'DeviceCmykCS';
  11712. case 'CalGray':
  11713. params = xref.fetchIfRef(cs[1]).getAll();
  11714. return ['CalGrayCS', params];
  11715. case 'CalRGB':
  11716. params = xref.fetchIfRef(cs[1]).getAll();
  11717. return ['CalRGBCS', params];
  11718. case 'ICCBased':
  11719. var stream = xref.fetchIfRef(cs[1]);
  11720. var dict = stream.dict;
  11721. numComps = dict.get('N');
  11722. if (numComps === 1) {
  11723. return 'DeviceGrayCS';
  11724. } else if (numComps === 3) {
  11725. return 'DeviceRgbCS';
  11726. } else if (numComps === 4) {
  11727. return 'DeviceCmykCS';
  11728. }
  11729. break;
  11730. case 'Pattern':
  11731. var basePatternCS = cs[1];
  11732. if (basePatternCS) {
  11733. basePatternCS = ColorSpace.parseToIR(basePatternCS, xref, res);
  11734. }
  11735. return ['PatternCS', basePatternCS];
  11736. case 'Indexed':
  11737. case 'I':
  11738. var baseIndexedCS = ColorSpace.parseToIR(cs[1], xref, res);
  11739. var hiVal = cs[2] + 1;
  11740. var lookup = xref.fetchIfRef(cs[3]);
  11741. if (isStream(lookup)) {
  11742. lookup = lookup.getBytes();
  11743. }
  11744. return ['IndexedCS', baseIndexedCS, hiVal, lookup];
  11745. case 'Separation':
  11746. case 'DeviceN':
  11747. var name = cs[1];
  11748. numComps = 1;
  11749. if (isName(name)) {
  11750. numComps = 1;
  11751. } else if (isArray(name)) {
  11752. numComps = name.length;
  11753. }
  11754. var alt = ColorSpace.parseToIR(cs[2], xref, res);
  11755. var tintFnIR = PDFFunction.getIR(xref, xref.fetchIfRef(cs[3]));
  11756. return ['AlternateCS', numComps, alt, tintFnIR];
  11757. case 'Lab':
  11758. params = cs[1].getAll();
  11759. return ['LabCS', params];
  11760. default:
  11761. error('unimplemented color space object "' + mode + '"');
  11762. }
  11763. } else {
  11764. error('unrecognized color space object: "' + cs + '"');
  11765. }
  11766. return null;
  11767. };
  11768. /**
  11769. * Checks if a decode map matches the default decode map for a color space.
  11770. * This handles the general decode maps where there are two values per
  11771. * component. e.g. [0, 1, 0, 1, 0, 1] for a RGB color.
  11772. * This does not handle Lab, Indexed, or Pattern decode maps since they are
  11773. * slightly different.
  11774. * @param {Array} decode Decode map (usually from an image).
  11775. * @param {Number} n Number of components the color space has.
  11776. */
  11777. ColorSpace.isDefaultDecode = function ColorSpace_isDefaultDecode(decode, n) {
  11778. if (!decode) {
  11779. return true;
  11780. }
  11781. if (n * 2 !== decode.length) {
  11782. warn('The decode map is not the correct length');
  11783. return true;
  11784. }
  11785. for (var i = 0, ii = decode.length; i < ii; i += 2) {
  11786. if (decode[i] !== 0 || decode[i + 1] !== 1) {
  11787. return false;
  11788. }
  11789. }
  11790. return true;
  11791. };
  11792. ColorSpace.singletons = {
  11793. get gray() {
  11794. return shadow(this, 'gray', new DeviceGrayCS());
  11795. },
  11796. get rgb() {
  11797. return shadow(this, 'rgb', new DeviceRgbCS());
  11798. },
  11799. get cmyk() {
  11800. return shadow(this, 'cmyk', new DeviceCmykCS());
  11801. }
  11802. };
  11803. return ColorSpace;
  11804. })();
  11805. /**
  11806. * Alternate color space handles both Separation and DeviceN color spaces. A
  11807. * Separation color space is actually just a DeviceN with one color component.
  11808. * Both color spaces use a tinting function to convert colors to a base color
  11809. * space.
  11810. */
  11811. var AlternateCS = (function AlternateCSClosure() {
  11812. function AlternateCS(numComps, base, tintFn) {
  11813. this.name = 'Alternate';
  11814. this.numComps = numComps;
  11815. this.defaultColor = new Float32Array(numComps);
  11816. for (var i = 0; i < numComps; ++i) {
  11817. this.defaultColor[i] = 1;
  11818. }
  11819. this.base = base;
  11820. this.tintFn = tintFn;
  11821. this.tmpBuf = new Float32Array(base.numComps);
  11822. }
  11823. AlternateCS.prototype = {
  11824. getRgb: ColorSpace.prototype.getRgb,
  11825. getRgbItem: function AlternateCS_getRgbItem(src, srcOffset,
  11826. dest, destOffset) {
  11827. var tmpBuf = this.tmpBuf;
  11828. this.tintFn(src, srcOffset, tmpBuf, 0);
  11829. this.base.getRgbItem(tmpBuf, 0, dest, destOffset);
  11830. },
  11831. getRgbBuffer: function AlternateCS_getRgbBuffer(src, srcOffset, count,
  11832. dest, destOffset, bits,
  11833. alpha01) {
  11834. var tintFn = this.tintFn;
  11835. var base = this.base;
  11836. var scale = 1 / ((1 << bits) - 1);
  11837. var baseNumComps = base.numComps;
  11838. var usesZeroToOneRange = base.usesZeroToOneRange;
  11839. var isPassthrough = (base.isPassthrough(8) || !usesZeroToOneRange) &&
  11840. alpha01 === 0;
  11841. var pos = isPassthrough ? destOffset : 0;
  11842. var baseBuf = isPassthrough ? dest : new Uint8Array(baseNumComps * count);
  11843. var numComps = this.numComps;
  11844. var scaled = new Float32Array(numComps);
  11845. var tinted = new Float32Array(baseNumComps);
  11846. var i, j;
  11847. if (usesZeroToOneRange) {
  11848. for (i = 0; i < count; i++) {
  11849. for (j = 0; j < numComps; j++) {
  11850. scaled[j] = src[srcOffset++] * scale;
  11851. }
  11852. tintFn(scaled, 0, tinted, 0);
  11853. for (j = 0; j < baseNumComps; j++) {
  11854. baseBuf[pos++] = tinted[j] * 255;
  11855. }
  11856. }
  11857. } else {
  11858. for (i = 0; i < count; i++) {
  11859. for (j = 0; j < numComps; j++) {
  11860. scaled[j] = src[srcOffset++] * scale;
  11861. }
  11862. tintFn(scaled, 0, tinted, 0);
  11863. base.getRgbItem(tinted, 0, baseBuf, pos);
  11864. pos += baseNumComps;
  11865. }
  11866. }
  11867. if (!isPassthrough) {
  11868. base.getRgbBuffer(baseBuf, 0, count, dest, destOffset, 8, alpha01);
  11869. }
  11870. },
  11871. getOutputLength: function AlternateCS_getOutputLength(inputLength,
  11872. alpha01) {
  11873. return this.base.getOutputLength(inputLength *
  11874. this.base.numComps / this.numComps,
  11875. alpha01);
  11876. },
  11877. isPassthrough: ColorSpace.prototype.isPassthrough,
  11878. fillRgb: ColorSpace.prototype.fillRgb,
  11879. isDefaultDecode: function AlternateCS_isDefaultDecode(decodeMap) {
  11880. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  11881. },
  11882. usesZeroToOneRange: true
  11883. };
  11884. return AlternateCS;
  11885. })();
  11886. var PatternCS = (function PatternCSClosure() {
  11887. function PatternCS(baseCS) {
  11888. this.name = 'Pattern';
  11889. this.base = baseCS;
  11890. }
  11891. PatternCS.prototype = {};
  11892. return PatternCS;
  11893. })();
  11894. var IndexedCS = (function IndexedCSClosure() {
  11895. function IndexedCS(base, highVal, lookup) {
  11896. this.name = 'Indexed';
  11897. this.numComps = 1;
  11898. this.defaultColor = new Uint8Array([0]);
  11899. this.base = base;
  11900. this.highVal = highVal;
  11901. var baseNumComps = base.numComps;
  11902. var length = baseNumComps * highVal;
  11903. var lookupArray;
  11904. if (isStream(lookup)) {
  11905. lookupArray = new Uint8Array(length);
  11906. var bytes = lookup.getBytes(length);
  11907. lookupArray.set(bytes);
  11908. } else if (isString(lookup)) {
  11909. lookupArray = new Uint8Array(length);
  11910. for (var i = 0; i < length; ++i) {
  11911. lookupArray[i] = lookup.charCodeAt(i);
  11912. }
  11913. } else if (lookup instanceof Uint8Array || lookup instanceof Array) {
  11914. lookupArray = lookup;
  11915. } else {
  11916. error('Unrecognized lookup table: ' + lookup);
  11917. }
  11918. this.lookup = lookupArray;
  11919. }
  11920. IndexedCS.prototype = {
  11921. getRgb: ColorSpace.prototype.getRgb,
  11922. getRgbItem: function IndexedCS_getRgbItem(src, srcOffset,
  11923. dest, destOffset) {
  11924. var numComps = this.base.numComps;
  11925. var start = src[srcOffset] * numComps;
  11926. this.base.getRgbItem(this.lookup, start, dest, destOffset);
  11927. },
  11928. getRgbBuffer: function IndexedCS_getRgbBuffer(src, srcOffset, count,
  11929. dest, destOffset, bits,
  11930. alpha01) {
  11931. var base = this.base;
  11932. var numComps = base.numComps;
  11933. var outputDelta = base.getOutputLength(numComps, alpha01);
  11934. var lookup = this.lookup;
  11935. for (var i = 0; i < count; ++i) {
  11936. var lookupPos = src[srcOffset++] * numComps;
  11937. base.getRgbBuffer(lookup, lookupPos, 1, dest, destOffset, 8, alpha01);
  11938. destOffset += outputDelta;
  11939. }
  11940. },
  11941. getOutputLength: function IndexedCS_getOutputLength(inputLength, alpha01) {
  11942. return this.base.getOutputLength(inputLength * this.base.numComps,
  11943. alpha01);
  11944. },
  11945. isPassthrough: ColorSpace.prototype.isPassthrough,
  11946. fillRgb: ColorSpace.prototype.fillRgb,
  11947. isDefaultDecode: function IndexedCS_isDefaultDecode(decodeMap) {
  11948. // indexed color maps shouldn't be changed
  11949. return true;
  11950. },
  11951. usesZeroToOneRange: true
  11952. };
  11953. return IndexedCS;
  11954. })();
  11955. var DeviceGrayCS = (function DeviceGrayCSClosure() {
  11956. function DeviceGrayCS() {
  11957. this.name = 'DeviceGray';
  11958. this.numComps = 1;
  11959. this.defaultColor = new Float32Array([0]);
  11960. }
  11961. DeviceGrayCS.prototype = {
  11962. getRgb: ColorSpace.prototype.getRgb,
  11963. getRgbItem: function DeviceGrayCS_getRgbItem(src, srcOffset,
  11964. dest, destOffset) {
  11965. var c = (src[srcOffset] * 255) | 0;
  11966. c = c < 0 ? 0 : c > 255 ? 255 : c;
  11967. dest[destOffset] = dest[destOffset + 1] = dest[destOffset + 2] = c;
  11968. },
  11969. getRgbBuffer: function DeviceGrayCS_getRgbBuffer(src, srcOffset, count,
  11970. dest, destOffset, bits,
  11971. alpha01) {
  11972. var scale = 255 / ((1 << bits) - 1);
  11973. var j = srcOffset, q = destOffset;
  11974. for (var i = 0; i < count; ++i) {
  11975. var c = (scale * src[j++]) | 0;
  11976. dest[q++] = c;
  11977. dest[q++] = c;
  11978. dest[q++] = c;
  11979. q += alpha01;
  11980. }
  11981. },
  11982. getOutputLength: function DeviceGrayCS_getOutputLength(inputLength,
  11983. alpha01) {
  11984. return inputLength * (3 + alpha01);
  11985. },
  11986. isPassthrough: ColorSpace.prototype.isPassthrough,
  11987. fillRgb: ColorSpace.prototype.fillRgb,
  11988. isDefaultDecode: function DeviceGrayCS_isDefaultDecode(decodeMap) {
  11989. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  11990. },
  11991. usesZeroToOneRange: true
  11992. };
  11993. return DeviceGrayCS;
  11994. })();
  11995. var DeviceRgbCS = (function DeviceRgbCSClosure() {
  11996. function DeviceRgbCS() {
  11997. this.name = 'DeviceRGB';
  11998. this.numComps = 3;
  11999. this.defaultColor = new Float32Array([0, 0, 0]);
  12000. }
  12001. DeviceRgbCS.prototype = {
  12002. getRgb: ColorSpace.prototype.getRgb,
  12003. getRgbItem: function DeviceRgbCS_getRgbItem(src, srcOffset,
  12004. dest, destOffset) {
  12005. var r = (src[srcOffset] * 255) | 0;
  12006. var g = (src[srcOffset + 1] * 255) | 0;
  12007. var b = (src[srcOffset + 2] * 255) | 0;
  12008. dest[destOffset] = r < 0 ? 0 : r > 255 ? 255 : r;
  12009. dest[destOffset + 1] = g < 0 ? 0 : g > 255 ? 255 : g;
  12010. dest[destOffset + 2] = b < 0 ? 0 : b > 255 ? 255 : b;
  12011. },
  12012. getRgbBuffer: function DeviceRgbCS_getRgbBuffer(src, srcOffset, count,
  12013. dest, destOffset, bits,
  12014. alpha01) {
  12015. if (bits === 8 && alpha01 === 0) {
  12016. dest.set(src.subarray(srcOffset, srcOffset + count * 3), destOffset);
  12017. return;
  12018. }
  12019. var scale = 255 / ((1 << bits) - 1);
  12020. var j = srcOffset, q = destOffset;
  12021. for (var i = 0; i < count; ++i) {
  12022. dest[q++] = (scale * src[j++]) | 0;
  12023. dest[q++] = (scale * src[j++]) | 0;
  12024. dest[q++] = (scale * src[j++]) | 0;
  12025. q += alpha01;
  12026. }
  12027. },
  12028. getOutputLength: function DeviceRgbCS_getOutputLength(inputLength,
  12029. alpha01) {
  12030. return (inputLength * (3 + alpha01) / 3) | 0;
  12031. },
  12032. isPassthrough: function DeviceRgbCS_isPassthrough(bits) {
  12033. return bits === 8;
  12034. },
  12035. fillRgb: ColorSpace.prototype.fillRgb,
  12036. isDefaultDecode: function DeviceRgbCS_isDefaultDecode(decodeMap) {
  12037. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  12038. },
  12039. usesZeroToOneRange: true
  12040. };
  12041. return DeviceRgbCS;
  12042. })();
  12043. var DeviceCmykCS = (function DeviceCmykCSClosure() {
  12044. // The coefficients below was found using numerical analysis: the method of
  12045. // steepest descent for the sum((f_i - color_value_i)^2) for r/g/b colors,
  12046. // where color_value is the tabular value from the table of sampled RGB colors
  12047. // from CMYK US Web Coated (SWOP) colorspace, and f_i is the corresponding
  12048. // CMYK color conversion using the estimation below:
  12049. // f(A, B,.. N) = Acc+Bcm+Ccy+Dck+c+Fmm+Gmy+Hmk+Im+Jyy+Kyk+Ly+Mkk+Nk+255
  12050. function convertToRgb(src, srcOffset, srcScale, dest, destOffset) {
  12051. var c = src[srcOffset + 0] * srcScale;
  12052. var m = src[srcOffset + 1] * srcScale;
  12053. var y = src[srcOffset + 2] * srcScale;
  12054. var k = src[srcOffset + 3] * srcScale;
  12055. var r =
  12056. (c * (-4.387332384609988 * c + 54.48615194189176 * m +
  12057. 18.82290502165302 * y + 212.25662451639585 * k +
  12058. -285.2331026137004) +
  12059. m * (1.7149763477362134 * m - 5.6096736904047315 * y +
  12060. -17.873870861415444 * k - 5.497006427196366) +
  12061. y * (-2.5217340131683033 * y - 21.248923337353073 * k +
  12062. 17.5119270841813) +
  12063. k * (-21.86122147463605 * k - 189.48180835922747) + 255) | 0;
  12064. var g =
  12065. (c * (8.841041422036149 * c + 60.118027045597366 * m +
  12066. 6.871425592049007 * y + 31.159100130055922 * k +
  12067. -79.2970844816548) +
  12068. m * (-15.310361306967817 * m + 17.575251261109482 * y +
  12069. 131.35250912493976 * k - 190.9453302588951) +
  12070. y * (4.444339102852739 * y + 9.8632861493405 * k - 24.86741582555878) +
  12071. k * (-20.737325471181034 * k - 187.80453709719578) + 255) | 0;
  12072. var b =
  12073. (c * (0.8842522430003296 * c + 8.078677503112928 * m +
  12074. 30.89978309703729 * y - 0.23883238689178934 * k +
  12075. -14.183576799673286) +
  12076. m * (10.49593273432072 * m + 63.02378494754052 * y +
  12077. 50.606957656360734 * k - 112.23884253719248) +
  12078. y * (0.03296041114873217 * y + 115.60384449646641 * k +
  12079. -193.58209356861505) +
  12080. k * (-22.33816807309886 * k - 180.12613974708367) + 255) | 0;
  12081. dest[destOffset] = r > 255 ? 255 : r < 0 ? 0 : r;
  12082. dest[destOffset + 1] = g > 255 ? 255 : g < 0 ? 0 : g;
  12083. dest[destOffset + 2] = b > 255 ? 255 : b < 0 ? 0 : b;
  12084. }
  12085. function DeviceCmykCS() {
  12086. this.name = 'DeviceCMYK';
  12087. this.numComps = 4;
  12088. this.defaultColor = new Float32Array([0, 0, 0, 1]);
  12089. }
  12090. DeviceCmykCS.prototype = {
  12091. getRgb: ColorSpace.prototype.getRgb,
  12092. getRgbItem: function DeviceCmykCS_getRgbItem(src, srcOffset,
  12093. dest, destOffset) {
  12094. convertToRgb(src, srcOffset, 1, dest, destOffset);
  12095. },
  12096. getRgbBuffer: function DeviceCmykCS_getRgbBuffer(src, srcOffset, count,
  12097. dest, destOffset, bits,
  12098. alpha01) {
  12099. var scale = 1 / ((1 << bits) - 1);
  12100. for (var i = 0; i < count; i++) {
  12101. convertToRgb(src, srcOffset, scale, dest, destOffset);
  12102. srcOffset += 4;
  12103. destOffset += 3 + alpha01;
  12104. }
  12105. },
  12106. getOutputLength: function DeviceCmykCS_getOutputLength(inputLength,
  12107. alpha01) {
  12108. return (inputLength / 4 * (3 + alpha01)) | 0;
  12109. },
  12110. isPassthrough: ColorSpace.prototype.isPassthrough,
  12111. fillRgb: ColorSpace.prototype.fillRgb,
  12112. isDefaultDecode: function DeviceCmykCS_isDefaultDecode(decodeMap) {
  12113. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  12114. },
  12115. usesZeroToOneRange: true
  12116. };
  12117. return DeviceCmykCS;
  12118. })();
  12119. //
  12120. // CalGrayCS: Based on "PDF Reference, Sixth Ed", p.245
  12121. //
  12122. var CalGrayCS = (function CalGrayCSClosure() {
  12123. function CalGrayCS(whitePoint, blackPoint, gamma) {
  12124. this.name = 'CalGray';
  12125. this.numComps = 1;
  12126. this.defaultColor = new Float32Array([0]);
  12127. if (!whitePoint) {
  12128. error('WhitePoint missing - required for color space CalGray');
  12129. }
  12130. blackPoint = blackPoint || [0, 0, 0];
  12131. gamma = gamma || 1;
  12132. // Translate arguments to spec variables.
  12133. this.XW = whitePoint[0];
  12134. this.YW = whitePoint[1];
  12135. this.ZW = whitePoint[2];
  12136. this.XB = blackPoint[0];
  12137. this.YB = blackPoint[1];
  12138. this.ZB = blackPoint[2];
  12139. this.G = gamma;
  12140. // Validate variables as per spec.
  12141. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  12142. error('Invalid WhitePoint components for ' + this.name +
  12143. ', no fallback available');
  12144. }
  12145. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  12146. info('Invalid BlackPoint for ' + this.name + ', falling back to default');
  12147. this.XB = this.YB = this.ZB = 0;
  12148. }
  12149. if (this.XB !== 0 || this.YB !== 0 || this.ZB !== 0) {
  12150. warn(this.name + ', BlackPoint: XB: ' + this.XB + ', YB: ' + this.YB +
  12151. ', ZB: ' + this.ZB + ', only default values are supported.');
  12152. }
  12153. if (this.G < 1) {
  12154. info('Invalid Gamma: ' + this.G + ' for ' + this.name +
  12155. ', falling back to default');
  12156. this.G = 1;
  12157. }
  12158. }
  12159. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  12160. // A represents a gray component of a calibrated gray space.
  12161. // A <---> AG in the spec
  12162. var A = src[srcOffset] * scale;
  12163. var AG = Math.pow(A, cs.G);
  12164. // Computes L as per spec. ( = cs.YW * AG )
  12165. // Except if other than default BlackPoint values are used.
  12166. var L = cs.YW * AG;
  12167. // http://www.poynton.com/notes/colour_and_gamma/ColorFAQ.html, Ch 4.
  12168. // Convert values to rgb range [0, 255].
  12169. var val = Math.max(295.8 * Math.pow(L, 0.333333333333333333) - 40.8, 0) | 0;
  12170. dest[destOffset] = val;
  12171. dest[destOffset + 1] = val;
  12172. dest[destOffset + 2] = val;
  12173. }
  12174. CalGrayCS.prototype = {
  12175. getRgb: ColorSpace.prototype.getRgb,
  12176. getRgbItem: function CalGrayCS_getRgbItem(src, srcOffset,
  12177. dest, destOffset) {
  12178. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  12179. },
  12180. getRgbBuffer: function CalGrayCS_getRgbBuffer(src, srcOffset, count,
  12181. dest, destOffset, bits,
  12182. alpha01) {
  12183. var scale = 1 / ((1 << bits) - 1);
  12184. for (var i = 0; i < count; ++i) {
  12185. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  12186. srcOffset += 1;
  12187. destOffset += 3 + alpha01;
  12188. }
  12189. },
  12190. getOutputLength: function CalGrayCS_getOutputLength(inputLength, alpha01) {
  12191. return inputLength * (3 + alpha01);
  12192. },
  12193. isPassthrough: ColorSpace.prototype.isPassthrough,
  12194. fillRgb: ColorSpace.prototype.fillRgb,
  12195. isDefaultDecode: function CalGrayCS_isDefaultDecode(decodeMap) {
  12196. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  12197. },
  12198. usesZeroToOneRange: true
  12199. };
  12200. return CalGrayCS;
  12201. })();
  12202. //
  12203. // CalRGBCS: Based on "PDF Reference, Sixth Ed", p.247
  12204. //
  12205. var CalRGBCS = (function CalRGBCSClosure() {
  12206. // See http://www.brucelindbloom.com/index.html?Eqn_ChromAdapt.html for these
  12207. // matrices.
  12208. var BRADFORD_SCALE_MATRIX = new Float32Array([
  12209. 0.8951, 0.2664, -0.1614,
  12210. -0.7502, 1.7135, 0.0367,
  12211. 0.0389, -0.0685, 1.0296]);
  12212. var BRADFORD_SCALE_INVERSE_MATRIX = new Float32Array([
  12213. 0.9869929, -0.1470543, 0.1599627,
  12214. 0.4323053, 0.5183603, 0.0492912,
  12215. -0.0085287, 0.0400428, 0.9684867]);
  12216. // See http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html.
  12217. var SRGB_D65_XYZ_TO_RGB_MATRIX = new Float32Array([
  12218. 3.2404542, -1.5371385, -0.4985314,
  12219. -0.9692660, 1.8760108, 0.0415560,
  12220. 0.0556434, -0.2040259, 1.0572252]);
  12221. var FLAT_WHITEPOINT_MATRIX = new Float32Array([1, 1, 1]);
  12222. var tempNormalizeMatrix = new Float32Array(3);
  12223. var tempConvertMatrix1 = new Float32Array(3);
  12224. var tempConvertMatrix2 = new Float32Array(3);
  12225. var DECODE_L_CONSTANT = Math.pow(((8 + 16) / 116), 3) / 8.0;
  12226. function CalRGBCS(whitePoint, blackPoint, gamma, matrix) {
  12227. this.name = 'CalRGB';
  12228. this.numComps = 3;
  12229. this.defaultColor = new Float32Array(3);
  12230. if (!whitePoint) {
  12231. error('WhitePoint missing - required for color space CalRGB');
  12232. }
  12233. blackPoint = blackPoint || new Float32Array(3);
  12234. gamma = gamma || new Float32Array([1, 1, 1]);
  12235. matrix = matrix || new Float32Array([1, 0, 0, 0, 1, 0, 0, 0, 1]);
  12236. // Translate arguments to spec variables.
  12237. var XW = whitePoint[0];
  12238. var YW = whitePoint[1];
  12239. var ZW = whitePoint[2];
  12240. this.whitePoint = whitePoint;
  12241. var XB = blackPoint[0];
  12242. var YB = blackPoint[1];
  12243. var ZB = blackPoint[2];
  12244. this.blackPoint = blackPoint;
  12245. this.GR = gamma[0];
  12246. this.GG = gamma[1];
  12247. this.GB = gamma[2];
  12248. this.MXA = matrix[0];
  12249. this.MYA = matrix[1];
  12250. this.MZA = matrix[2];
  12251. this.MXB = matrix[3];
  12252. this.MYB = matrix[4];
  12253. this.MZB = matrix[5];
  12254. this.MXC = matrix[6];
  12255. this.MYC = matrix[7];
  12256. this.MZC = matrix[8];
  12257. // Validate variables as per spec.
  12258. if (XW < 0 || ZW < 0 || YW !== 1) {
  12259. error('Invalid WhitePoint components for ' + this.name +
  12260. ', no fallback available');
  12261. }
  12262. if (XB < 0 || YB < 0 || ZB < 0) {
  12263. info('Invalid BlackPoint for ' + this.name + ' [' + XB + ', ' + YB +
  12264. ', ' + ZB + '], falling back to default');
  12265. this.blackPoint = new Float32Array(3);
  12266. }
  12267. if (this.GR < 0 || this.GG < 0 || this.GB < 0) {
  12268. info('Invalid Gamma [' + this.GR + ', ' + this.GG + ', ' + this.GB +
  12269. '] for ' + this.name + ', falling back to default');
  12270. this.GR = this.GG = this.GB = 1;
  12271. }
  12272. if (this.MXA < 0 || this.MYA < 0 || this.MZA < 0 ||
  12273. this.MXB < 0 || this.MYB < 0 || this.MZB < 0 ||
  12274. this.MXC < 0 || this.MYC < 0 || this.MZC < 0) {
  12275. info('Invalid Matrix for ' + this.name + ' [' +
  12276. this.MXA + ', ' + this.MYA + ', ' + this.MZA +
  12277. this.MXB + ', ' + this.MYB + ', ' + this.MZB +
  12278. this.MXC + ', ' + this.MYC + ', ' + this.MZC +
  12279. '], falling back to default');
  12280. this.MXA = this.MYB = this.MZC = 1;
  12281. this.MXB = this.MYA = this.MZA = this.MXC = this.MYC = this.MZB = 0;
  12282. }
  12283. }
  12284. function matrixProduct(a, b, result) {
  12285. result[0] = a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
  12286. result[1] = a[3] * b[0] + a[4] * b[1] + a[5] * b[2];
  12287. result[2] = a[6] * b[0] + a[7] * b[1] + a[8] * b[2];
  12288. }
  12289. function convertToFlat(sourceWhitePoint, LMS, result) {
  12290. result[0] = LMS[0] * 1 / sourceWhitePoint[0];
  12291. result[1] = LMS[1] * 1 / sourceWhitePoint[1];
  12292. result[2] = LMS[2] * 1 / sourceWhitePoint[2];
  12293. }
  12294. function convertToD65(sourceWhitePoint, LMS, result) {
  12295. var D65X = 0.95047;
  12296. var D65Y = 1;
  12297. var D65Z = 1.08883;
  12298. result[0] = LMS[0] * D65X / sourceWhitePoint[0];
  12299. result[1] = LMS[1] * D65Y / sourceWhitePoint[1];
  12300. result[2] = LMS[2] * D65Z / sourceWhitePoint[2];
  12301. }
  12302. function sRGBTransferFunction(color) {
  12303. // See http://en.wikipedia.org/wiki/SRGB.
  12304. if (color <= 0.0031308){
  12305. return adjustToRange(0, 1, 12.92 * color);
  12306. }
  12307. return adjustToRange(0, 1, (1 + 0.055) * Math.pow(color, 1 / 2.4) - 0.055);
  12308. }
  12309. function adjustToRange(min, max, value) {
  12310. return Math.max(min, Math.min(max, value));
  12311. }
  12312. function decodeL(L) {
  12313. if (L < 0) {
  12314. return -decodeL(-L);
  12315. }
  12316. if (L > 8.0) {
  12317. return Math.pow(((L + 16) / 116), 3);
  12318. }
  12319. return L * DECODE_L_CONSTANT;
  12320. }
  12321. function compensateBlackPoint(sourceBlackPoint, XYZ_Flat, result) {
  12322. // In case the blackPoint is already the default blackPoint then there is
  12323. // no need to do compensation.
  12324. if (sourceBlackPoint[0] === 0 &&
  12325. sourceBlackPoint[1] === 0 &&
  12326. sourceBlackPoint[2] === 0) {
  12327. result[0] = XYZ_Flat[0];
  12328. result[1] = XYZ_Flat[1];
  12329. result[2] = XYZ_Flat[2];
  12330. return;
  12331. }
  12332. // For the blackPoint calculation details, please see
  12333. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  12334. // AdobeBPC.pdf.
  12335. // The destination blackPoint is the default blackPoint [0, 0, 0].
  12336. var zeroDecodeL = decodeL(0);
  12337. var X_DST = zeroDecodeL;
  12338. var X_SRC = decodeL(sourceBlackPoint[0]);
  12339. var Y_DST = zeroDecodeL;
  12340. var Y_SRC = decodeL(sourceBlackPoint[1]);
  12341. var Z_DST = zeroDecodeL;
  12342. var Z_SRC = decodeL(sourceBlackPoint[2]);
  12343. var X_Scale = (1 - X_DST) / (1 - X_SRC);
  12344. var X_Offset = 1 - X_Scale;
  12345. var Y_Scale = (1 - Y_DST) / (1 - Y_SRC);
  12346. var Y_Offset = 1 - Y_Scale;
  12347. var Z_Scale = (1 - Z_DST) / (1 - Z_SRC);
  12348. var Z_Offset = 1 - Z_Scale;
  12349. result[0] = XYZ_Flat[0] * X_Scale + X_Offset;
  12350. result[1] = XYZ_Flat[1] * Y_Scale + Y_Offset;
  12351. result[2] = XYZ_Flat[2] * Z_Scale + Z_Offset;
  12352. }
  12353. function normalizeWhitePointToFlat(sourceWhitePoint, XYZ_In, result) {
  12354. // In case the whitePoint is already flat then there is no need to do
  12355. // normalization.
  12356. if (sourceWhitePoint[0] === 1 && sourceWhitePoint[2] === 1) {
  12357. result[0] = XYZ_In[0];
  12358. result[1] = XYZ_In[1];
  12359. result[2] = XYZ_In[2];
  12360. return;
  12361. }
  12362. var LMS = result;
  12363. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  12364. var LMS_Flat = tempNormalizeMatrix;
  12365. convertToFlat(sourceWhitePoint, LMS, LMS_Flat);
  12366. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_Flat, result);
  12367. }
  12368. function normalizeWhitePointToD65(sourceWhitePoint, XYZ_In, result) {
  12369. var LMS = result;
  12370. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  12371. var LMS_D65 = tempNormalizeMatrix;
  12372. convertToD65(sourceWhitePoint, LMS, LMS_D65);
  12373. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_D65, result);
  12374. }
  12375. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  12376. // A, B and C represent a red, green and blue components of a calibrated
  12377. // rgb space.
  12378. var A = adjustToRange(0, 1, src[srcOffset] * scale);
  12379. var B = adjustToRange(0, 1, src[srcOffset + 1] * scale);
  12380. var C = adjustToRange(0, 1, src[srcOffset + 2] * scale);
  12381. // A <---> AGR in the spec
  12382. // B <---> BGG in the spec
  12383. // C <---> CGB in the spec
  12384. var AGR = Math.pow(A, cs.GR);
  12385. var BGG = Math.pow(B, cs.GG);
  12386. var CGB = Math.pow(C, cs.GB);
  12387. // Computes intermediate variables L, M, N as per spec.
  12388. // To decode X, Y, Z values map L, M, N directly to them.
  12389. var X = cs.MXA * AGR + cs.MXB * BGG + cs.MXC * CGB;
  12390. var Y = cs.MYA * AGR + cs.MYB * BGG + cs.MYC * CGB;
  12391. var Z = cs.MZA * AGR + cs.MZB * BGG + cs.MZC * CGB;
  12392. // The following calculations are based on this document:
  12393. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  12394. // AdobeBPC.pdf.
  12395. var XYZ = tempConvertMatrix1;
  12396. XYZ[0] = X;
  12397. XYZ[1] = Y;
  12398. XYZ[2] = Z;
  12399. var XYZ_Flat = tempConvertMatrix2;
  12400. normalizeWhitePointToFlat(cs.whitePoint, XYZ, XYZ_Flat);
  12401. var XYZ_Black = tempConvertMatrix1;
  12402. compensateBlackPoint(cs.blackPoint, XYZ_Flat, XYZ_Black);
  12403. var XYZ_D65 = tempConvertMatrix2;
  12404. normalizeWhitePointToD65(FLAT_WHITEPOINT_MATRIX, XYZ_Black, XYZ_D65);
  12405. var SRGB = tempConvertMatrix1;
  12406. matrixProduct(SRGB_D65_XYZ_TO_RGB_MATRIX, XYZ_D65, SRGB);
  12407. var sR = sRGBTransferFunction(SRGB[0]);
  12408. var sG = sRGBTransferFunction(SRGB[1]);
  12409. var sB = sRGBTransferFunction(SRGB[2]);
  12410. // Convert the values to rgb range [0, 255].
  12411. dest[destOffset] = Math.round(sR * 255);
  12412. dest[destOffset + 1] = Math.round(sG * 255);
  12413. dest[destOffset + 2] = Math.round(sB * 255);
  12414. }
  12415. CalRGBCS.prototype = {
  12416. getRgb: function CalRGBCS_getRgb(src, srcOffset) {
  12417. var rgb = new Uint8Array(3);
  12418. this.getRgbItem(src, srcOffset, rgb, 0);
  12419. return rgb;
  12420. },
  12421. getRgbItem: function CalRGBCS_getRgbItem(src, srcOffset,
  12422. dest, destOffset) {
  12423. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  12424. },
  12425. getRgbBuffer: function CalRGBCS_getRgbBuffer(src, srcOffset, count,
  12426. dest, destOffset, bits,
  12427. alpha01) {
  12428. var scale = 1 / ((1 << bits) - 1);
  12429. for (var i = 0; i < count; ++i) {
  12430. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  12431. srcOffset += 3;
  12432. destOffset += 3 + alpha01;
  12433. }
  12434. },
  12435. getOutputLength: function CalRGBCS_getOutputLength(inputLength, alpha01) {
  12436. return (inputLength * (3 + alpha01) / 3) | 0;
  12437. },
  12438. isPassthrough: ColorSpace.prototype.isPassthrough,
  12439. fillRgb: ColorSpace.prototype.fillRgb,
  12440. isDefaultDecode: function CalRGBCS_isDefaultDecode(decodeMap) {
  12441. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  12442. },
  12443. usesZeroToOneRange: true
  12444. };
  12445. return CalRGBCS;
  12446. })();
  12447. //
  12448. // LabCS: Based on "PDF Reference, Sixth Ed", p.250
  12449. //
  12450. var LabCS = (function LabCSClosure() {
  12451. function LabCS(whitePoint, blackPoint, range) {
  12452. this.name = 'Lab';
  12453. this.numComps = 3;
  12454. this.defaultColor = new Float32Array([0, 0, 0]);
  12455. if (!whitePoint) {
  12456. error('WhitePoint missing - required for color space Lab');
  12457. }
  12458. blackPoint = blackPoint || [0, 0, 0];
  12459. range = range || [-100, 100, -100, 100];
  12460. // Translate args to spec variables
  12461. this.XW = whitePoint[0];
  12462. this.YW = whitePoint[1];
  12463. this.ZW = whitePoint[2];
  12464. this.amin = range[0];
  12465. this.amax = range[1];
  12466. this.bmin = range[2];
  12467. this.bmax = range[3];
  12468. // These are here just for completeness - the spec doesn't offer any
  12469. // formulas that use BlackPoint in Lab
  12470. this.XB = blackPoint[0];
  12471. this.YB = blackPoint[1];
  12472. this.ZB = blackPoint[2];
  12473. // Validate vars as per spec
  12474. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  12475. error('Invalid WhitePoint components, no fallback available');
  12476. }
  12477. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  12478. info('Invalid BlackPoint, falling back to default');
  12479. this.XB = this.YB = this.ZB = 0;
  12480. }
  12481. if (this.amin > this.amax || this.bmin > this.bmax) {
  12482. info('Invalid Range, falling back to defaults');
  12483. this.amin = -100;
  12484. this.amax = 100;
  12485. this.bmin = -100;
  12486. this.bmax = 100;
  12487. }
  12488. }
  12489. // Function g(x) from spec
  12490. function fn_g(x) {
  12491. if (x >= 6 / 29) {
  12492. return x * x * x;
  12493. } else {
  12494. return (108 / 841) * (x - 4 / 29);
  12495. }
  12496. }
  12497. function decode(value, high1, low2, high2) {
  12498. return low2 + (value) * (high2 - low2) / (high1);
  12499. }
  12500. // If decoding is needed maxVal should be 2^bits per component - 1.
  12501. function convertToRgb(cs, src, srcOffset, maxVal, dest, destOffset) {
  12502. // XXX: Lab input is in the range of [0, 100], [amin, amax], [bmin, bmax]
  12503. // not the usual [0, 1]. If a command like setFillColor is used the src
  12504. // values will already be within the correct range. However, if we are
  12505. // converting an image we have to map the values to the correct range given
  12506. // above.
  12507. // Ls,as,bs <---> L*,a*,b* in the spec
  12508. var Ls = src[srcOffset];
  12509. var as = src[srcOffset + 1];
  12510. var bs = src[srcOffset + 2];
  12511. if (maxVal !== false) {
  12512. Ls = decode(Ls, maxVal, 0, 100);
  12513. as = decode(as, maxVal, cs.amin, cs.amax);
  12514. bs = decode(bs, maxVal, cs.bmin, cs.bmax);
  12515. }
  12516. // Adjust limits of 'as' and 'bs'
  12517. as = as > cs.amax ? cs.amax : as < cs.amin ? cs.amin : as;
  12518. bs = bs > cs.bmax ? cs.bmax : bs < cs.bmin ? cs.bmin : bs;
  12519. // Computes intermediate variables X,Y,Z as per spec
  12520. var M = (Ls + 16) / 116;
  12521. var L = M + (as / 500);
  12522. var N = M - (bs / 200);
  12523. var X = cs.XW * fn_g(L);
  12524. var Y = cs.YW * fn_g(M);
  12525. var Z = cs.ZW * fn_g(N);
  12526. var r, g, b;
  12527. // Using different conversions for D50 and D65 white points,
  12528. // per http://www.color.org/srgb.pdf
  12529. if (cs.ZW < 1) {
  12530. // Assuming D50 (X=0.9642, Y=1.00, Z=0.8249)
  12531. r = X * 3.1339 + Y * -1.6170 + Z * -0.4906;
  12532. g = X * -0.9785 + Y * 1.9160 + Z * 0.0333;
  12533. b = X * 0.0720 + Y * -0.2290 + Z * 1.4057;
  12534. } else {
  12535. // Assuming D65 (X=0.9505, Y=1.00, Z=1.0888)
  12536. r = X * 3.2406 + Y * -1.5372 + Z * -0.4986;
  12537. g = X * -0.9689 + Y * 1.8758 + Z * 0.0415;
  12538. b = X * 0.0557 + Y * -0.2040 + Z * 1.0570;
  12539. }
  12540. // clamp color values to [0,1] range then convert to [0,255] range.
  12541. dest[destOffset] = r <= 0 ? 0 : r >= 1 ? 255 : Math.sqrt(r) * 255 | 0;
  12542. dest[destOffset + 1] = g <= 0 ? 0 : g >= 1 ? 255 : Math.sqrt(g) * 255 | 0;
  12543. dest[destOffset + 2] = b <= 0 ? 0 : b >= 1 ? 255 : Math.sqrt(b) * 255 | 0;
  12544. }
  12545. LabCS.prototype = {
  12546. getRgb: ColorSpace.prototype.getRgb,
  12547. getRgbItem: function LabCS_getRgbItem(src, srcOffset, dest, destOffset) {
  12548. convertToRgb(this, src, srcOffset, false, dest, destOffset);
  12549. },
  12550. getRgbBuffer: function LabCS_getRgbBuffer(src, srcOffset, count,
  12551. dest, destOffset, bits,
  12552. alpha01) {
  12553. var maxVal = (1 << bits) - 1;
  12554. for (var i = 0; i < count; i++) {
  12555. convertToRgb(this, src, srcOffset, maxVal, dest, destOffset);
  12556. srcOffset += 3;
  12557. destOffset += 3 + alpha01;
  12558. }
  12559. },
  12560. getOutputLength: function LabCS_getOutputLength(inputLength, alpha01) {
  12561. return (inputLength * (3 + alpha01) / 3) | 0;
  12562. },
  12563. isPassthrough: ColorSpace.prototype.isPassthrough,
  12564. fillRgb: ColorSpace.prototype.fillRgb,
  12565. isDefaultDecode: function LabCS_isDefaultDecode(decodeMap) {
  12566. // XXX: Decoding is handled with the lab conversion because of the strange
  12567. // ranges that are used.
  12568. return true;
  12569. },
  12570. usesZeroToOneRange: false
  12571. };
  12572. return LabCS;
  12573. })();
  12574. var ARCFourCipher = (function ARCFourCipherClosure() {
  12575. function ARCFourCipher(key) {
  12576. this.a = 0;
  12577. this.b = 0;
  12578. var s = new Uint8Array(256);
  12579. var i, j = 0, tmp, keyLength = key.length;
  12580. for (i = 0; i < 256; ++i) {
  12581. s[i] = i;
  12582. }
  12583. for (i = 0; i < 256; ++i) {
  12584. tmp = s[i];
  12585. j = (j + tmp + key[i % keyLength]) & 0xFF;
  12586. s[i] = s[j];
  12587. s[j] = tmp;
  12588. }
  12589. this.s = s;
  12590. }
  12591. ARCFourCipher.prototype = {
  12592. encryptBlock: function ARCFourCipher_encryptBlock(data) {
  12593. var i, n = data.length, tmp, tmp2;
  12594. var a = this.a, b = this.b, s = this.s;
  12595. var output = new Uint8Array(n);
  12596. for (i = 0; i < n; ++i) {
  12597. a = (a + 1) & 0xFF;
  12598. tmp = s[a];
  12599. b = (b + tmp) & 0xFF;
  12600. tmp2 = s[b];
  12601. s[a] = tmp2;
  12602. s[b] = tmp;
  12603. output[i] = data[i] ^ s[(tmp + tmp2) & 0xFF];
  12604. }
  12605. this.a = a;
  12606. this.b = b;
  12607. return output;
  12608. }
  12609. };
  12610. ARCFourCipher.prototype.decryptBlock = ARCFourCipher.prototype.encryptBlock;
  12611. return ARCFourCipher;
  12612. })();
  12613. var calculateMD5 = (function calculateMD5Closure() {
  12614. var r = new Uint8Array([
  12615. 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22,
  12616. 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20,
  12617. 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23,
  12618. 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21]);
  12619. var k = new Int32Array([
  12620. -680876936, -389564586, 606105819, -1044525330, -176418897, 1200080426,
  12621. -1473231341, -45705983, 1770035416, -1958414417, -42063, -1990404162,
  12622. 1804603682, -40341101, -1502002290, 1236535329, -165796510, -1069501632,
  12623. 643717713, -373897302, -701558691, 38016083, -660478335, -405537848,
  12624. 568446438, -1019803690, -187363961, 1163531501, -1444681467, -51403784,
  12625. 1735328473, -1926607734, -378558, -2022574463, 1839030562, -35309556,
  12626. -1530992060, 1272893353, -155497632, -1094730640, 681279174, -358537222,
  12627. -722521979, 76029189, -640364487, -421815835, 530742520, -995338651,
  12628. -198630844, 1126891415, -1416354905, -57434055, 1700485571, -1894986606,
  12629. -1051523, -2054922799, 1873313359, -30611744, -1560198380, 1309151649,
  12630. -145523070, -1120210379, 718787259, -343485551]);
  12631. function hash(data, offset, length) {
  12632. var h0 = 1732584193, h1 = -271733879, h2 = -1732584194, h3 = 271733878;
  12633. // pre-processing
  12634. var paddedLength = (length + 72) & ~63; // data + 9 extra bytes
  12635. var padded = new Uint8Array(paddedLength);
  12636. var i, j, n;
  12637. for (i = 0; i < length; ++i) {
  12638. padded[i] = data[offset++];
  12639. }
  12640. padded[i++] = 0x80;
  12641. n = paddedLength - 8;
  12642. while (i < n) {
  12643. padded[i++] = 0;
  12644. }
  12645. padded[i++] = (length << 3) & 0xFF;
  12646. padded[i++] = (length >> 5) & 0xFF;
  12647. padded[i++] = (length >> 13) & 0xFF;
  12648. padded[i++] = (length >> 21) & 0xFF;
  12649. padded[i++] = (length >>> 29) & 0xFF;
  12650. padded[i++] = 0;
  12651. padded[i++] = 0;
  12652. padded[i++] = 0;
  12653. var w = new Int32Array(16);
  12654. for (i = 0; i < paddedLength;) {
  12655. for (j = 0; j < 16; ++j, i += 4) {
  12656. w[j] = (padded[i] | (padded[i + 1] << 8) |
  12657. (padded[i + 2] << 16) | (padded[i + 3] << 24));
  12658. }
  12659. var a = h0, b = h1, c = h2, d = h3, f, g;
  12660. for (j = 0; j < 64; ++j) {
  12661. if (j < 16) {
  12662. f = (b & c) | ((~b) & d);
  12663. g = j;
  12664. } else if (j < 32) {
  12665. f = (d & b) | ((~d) & c);
  12666. g = (5 * j + 1) & 15;
  12667. } else if (j < 48) {
  12668. f = b ^ c ^ d;
  12669. g = (3 * j + 5) & 15;
  12670. } else {
  12671. f = c ^ (b | (~d));
  12672. g = (7 * j) & 15;
  12673. }
  12674. var tmp = d, rotateArg = (a + f + k[j] + w[g]) | 0, rotate = r[j];
  12675. d = c;
  12676. c = b;
  12677. b = (b + ((rotateArg << rotate) | (rotateArg >>> (32 - rotate)))) | 0;
  12678. a = tmp;
  12679. }
  12680. h0 = (h0 + a) | 0;
  12681. h1 = (h1 + b) | 0;
  12682. h2 = (h2 + c) | 0;
  12683. h3 = (h3 + d) | 0;
  12684. }
  12685. return new Uint8Array([
  12686. h0 & 0xFF, (h0 >> 8) & 0xFF, (h0 >> 16) & 0xFF, (h0 >>> 24) & 0xFF,
  12687. h1 & 0xFF, (h1 >> 8) & 0xFF, (h1 >> 16) & 0xFF, (h1 >>> 24) & 0xFF,
  12688. h2 & 0xFF, (h2 >> 8) & 0xFF, (h2 >> 16) & 0xFF, (h2 >>> 24) & 0xFF,
  12689. h3 & 0xFF, (h3 >> 8) & 0xFF, (h3 >> 16) & 0xFF, (h3 >>> 24) & 0xFF
  12690. ]);
  12691. }
  12692. return hash;
  12693. })();
  12694. var Word64 = (function Word64Closure() {
  12695. function Word64(highInteger, lowInteger) {
  12696. this.high = highInteger | 0;
  12697. this.low = lowInteger | 0;
  12698. }
  12699. Word64.prototype = {
  12700. and: function Word64_and(word) {
  12701. this.high &= word.high;
  12702. this.low &= word.low;
  12703. },
  12704. xor: function Word64_xor(word) {
  12705. this.high ^= word.high;
  12706. this.low ^= word.low;
  12707. },
  12708. or: function Word64_or(word) {
  12709. this.high |= word.high;
  12710. this.low |= word.low;
  12711. },
  12712. shiftRight: function Word64_shiftRight(places) {
  12713. if (places >= 32) {
  12714. this.low = (this.high >>> (places - 32)) | 0;
  12715. this.high = 0;
  12716. } else {
  12717. this.low = (this.low >>> places) | (this.high << (32 - places));
  12718. this.high = (this.high >>> places) | 0;
  12719. }
  12720. },
  12721. shiftLeft: function Word64_shiftLeft(places) {
  12722. if (places >= 32) {
  12723. this.high = this.low << (places - 32);
  12724. this.low = 0;
  12725. } else {
  12726. this.high = (this.high << places) | (this.low >>> (32 - places));
  12727. this.low = this.low << places;
  12728. }
  12729. },
  12730. rotateRight: function Word64_rotateRight(places) {
  12731. var low, high;
  12732. if (places & 32) {
  12733. high = this.low;
  12734. low = this.high;
  12735. } else {
  12736. low = this.low;
  12737. high = this.high;
  12738. }
  12739. places &= 31;
  12740. this.low = (low >>> places) | (high << (32 - places));
  12741. this.high = (high >>> places) | (low << (32 - places));
  12742. },
  12743. not: function Word64_not() {
  12744. this.high = ~this.high;
  12745. this.low = ~this.low;
  12746. },
  12747. add: function Word64_add(word) {
  12748. var lowAdd = (this.low >>> 0) + (word.low >>> 0);
  12749. var highAdd = (this.high >>> 0) + (word.high >>> 0);
  12750. if (lowAdd > 0xFFFFFFFF) {
  12751. highAdd += 1;
  12752. }
  12753. this.low = lowAdd | 0;
  12754. this.high = highAdd | 0;
  12755. },
  12756. copyTo: function Word64_copyTo(bytes, offset) {
  12757. bytes[offset] = (this.high >>> 24) & 0xFF;
  12758. bytes[offset + 1] = (this.high >> 16) & 0xFF;
  12759. bytes[offset + 2] = (this.high >> 8) & 0xFF;
  12760. bytes[offset + 3] = this.high & 0xFF;
  12761. bytes[offset + 4] = (this.low >>> 24) & 0xFF;
  12762. bytes[offset + 5] = (this.low >> 16) & 0xFF;
  12763. bytes[offset + 6] = (this.low >> 8) & 0xFF;
  12764. bytes[offset + 7] = this.low & 0xFF;
  12765. },
  12766. assign: function Word64_assign(word) {
  12767. this.high = word.high;
  12768. this.low = word.low;
  12769. }
  12770. };
  12771. return Word64;
  12772. })();
  12773. var calculateSHA256 = (function calculateSHA256Closure() {
  12774. function rotr(x, n) {
  12775. return (x >>> n) | (x << 32 - n);
  12776. }
  12777. function ch(x, y, z) {
  12778. return (x & y) ^ (~x & z);
  12779. }
  12780. function maj(x, y, z) {
  12781. return (x & y) ^ (x & z) ^ (y & z);
  12782. }
  12783. function sigma(x) {
  12784. return rotr(x, 2) ^ rotr(x, 13) ^ rotr(x, 22);
  12785. }
  12786. function sigmaPrime(x) {
  12787. return rotr(x, 6) ^ rotr(x, 11) ^ rotr(x, 25);
  12788. }
  12789. function littleSigma(x) {
  12790. return rotr(x, 7) ^ rotr(x, 18) ^ x >>> 3;
  12791. }
  12792. function littleSigmaPrime(x) {
  12793. return rotr(x, 17) ^ rotr(x, 19) ^ x >>> 10;
  12794. }
  12795. var k = [0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
  12796. 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
  12797. 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
  12798. 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
  12799. 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
  12800. 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
  12801. 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
  12802. 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
  12803. 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
  12804. 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
  12805. 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
  12806. 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
  12807. 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
  12808. 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
  12809. 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
  12810. 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2];
  12811. function hash(data, offset, length) {
  12812. // initial hash values
  12813. var h0 = 0x6a09e667, h1 = 0xbb67ae85, h2 = 0x3c6ef372,
  12814. h3 = 0xa54ff53a, h4 = 0x510e527f, h5 = 0x9b05688c,
  12815. h6 = 0x1f83d9ab, h7 = 0x5be0cd19;
  12816. // pre-processing
  12817. var paddedLength = Math.ceil((length + 9) / 64) * 64;
  12818. var padded = new Uint8Array(paddedLength);
  12819. var i, j, n;
  12820. for (i = 0; i < length; ++i) {
  12821. padded[i] = data[offset++];
  12822. }
  12823. padded[i++] = 0x80;
  12824. n = paddedLength - 8;
  12825. while (i < n) {
  12826. padded[i++] = 0;
  12827. }
  12828. padded[i++] = 0;
  12829. padded[i++] = 0;
  12830. padded[i++] = 0;
  12831. padded[i++] = (length >>> 29) & 0xFF;
  12832. padded[i++] = (length >> 21) & 0xFF;
  12833. padded[i++] = (length >> 13) & 0xFF;
  12834. padded[i++] = (length >> 5) & 0xFF;
  12835. padded[i++] = (length << 3) & 0xFF;
  12836. var w = new Uint32Array(64);
  12837. // for each 512 bit block
  12838. for (i = 0; i < paddedLength;) {
  12839. for (j = 0; j < 16; ++j) {
  12840. w[j] = (padded[i] << 24 | (padded[i + 1] << 16) |
  12841. (padded[i + 2] << 8) | (padded[i + 3]));
  12842. i += 4;
  12843. }
  12844. for (j = 16; j < 64; ++j) {
  12845. w[j] = littleSigmaPrime(w[j - 2]) + w[j - 7] +
  12846. littleSigma(w[j - 15]) + w[j - 16] | 0;
  12847. }
  12848. var a = h0, b = h1, c = h2, d = h3, e = h4,
  12849. f = h5, g = h6, h = h7, t1, t2;
  12850. for (j = 0; j < 64; ++j) {
  12851. t1 = h + sigmaPrime(e) + ch(e, f, g) + k[j] + w[j];
  12852. t2 = sigma(a) + maj(a, b, c);
  12853. h = g;
  12854. g = f;
  12855. f = e;
  12856. e = (d + t1) | 0;
  12857. d = c;
  12858. c = b;
  12859. b = a;
  12860. a = (t1 + t2) | 0;
  12861. }
  12862. h0 = (h0 + a) | 0;
  12863. h1 = (h1 + b) | 0;
  12864. h2 = (h2 + c) | 0;
  12865. h3 = (h3 + d) | 0;
  12866. h4 = (h4 + e) | 0;
  12867. h5 = (h5 + f) | 0;
  12868. h6 = (h6 + g) | 0;
  12869. h7 = (h7 + h) | 0;
  12870. }
  12871. return new Uint8Array([
  12872. (h0 >> 24) & 0xFF, (h0 >> 16) & 0xFF, (h0 >> 8) & 0xFF, (h0) & 0xFF,
  12873. (h1 >> 24) & 0xFF, (h1 >> 16) & 0xFF, (h1 >> 8) & 0xFF, (h1) & 0xFF,
  12874. (h2 >> 24) & 0xFF, (h2 >> 16) & 0xFF, (h2 >> 8) & 0xFF, (h2) & 0xFF,
  12875. (h3 >> 24) & 0xFF, (h3 >> 16) & 0xFF, (h3 >> 8) & 0xFF, (h3) & 0xFF,
  12876. (h4 >> 24) & 0xFF, (h4 >> 16) & 0xFF, (h4 >> 8) & 0xFF, (h4) & 0xFF,
  12877. (h5 >> 24) & 0xFF, (h5 >> 16) & 0xFF, (h5 >> 8) & 0xFF, (h5) & 0xFF,
  12878. (h6 >> 24) & 0xFF, (h6 >> 16) & 0xFF, (h6 >> 8) & 0xFF, (h6) & 0xFF,
  12879. (h7 >> 24) & 0xFF, (h7 >> 16) & 0xFF, (h7 >> 8) & 0xFF, (h7) & 0xFF
  12880. ]);
  12881. }
  12882. return hash;
  12883. })();
  12884. var calculateSHA512 = (function calculateSHA512Closure() {
  12885. function ch(result, x, y, z, tmp) {
  12886. result.assign(x);
  12887. result.and(y);
  12888. tmp.assign(x);
  12889. tmp.not();
  12890. tmp.and(z);
  12891. result.xor(tmp);
  12892. }
  12893. function maj(result, x, y, z, tmp) {
  12894. result.assign(x);
  12895. result.and(y);
  12896. tmp.assign(x);
  12897. tmp.and(z);
  12898. result.xor(tmp);
  12899. tmp.assign(y);
  12900. tmp.and(z);
  12901. result.xor(tmp);
  12902. }
  12903. function sigma(result, x, tmp) {
  12904. result.assign(x);
  12905. result.rotateRight(28);
  12906. tmp.assign(x);
  12907. tmp.rotateRight(34);
  12908. result.xor(tmp);
  12909. tmp.assign(x);
  12910. tmp.rotateRight(39);
  12911. result.xor(tmp);
  12912. }
  12913. function sigmaPrime(result, x, tmp) {
  12914. result.assign(x);
  12915. result.rotateRight(14);
  12916. tmp.assign(x);
  12917. tmp.rotateRight(18);
  12918. result.xor(tmp);
  12919. tmp.assign(x);
  12920. tmp.rotateRight(41);
  12921. result.xor(tmp);
  12922. }
  12923. function littleSigma(result, x, tmp) {
  12924. result.assign(x);
  12925. result.rotateRight(1);
  12926. tmp.assign(x);
  12927. tmp.rotateRight(8);
  12928. result.xor(tmp);
  12929. tmp.assign(x);
  12930. tmp.shiftRight(7);
  12931. result.xor(tmp);
  12932. }
  12933. function littleSigmaPrime(result, x, tmp) {
  12934. result.assign(x);
  12935. result.rotateRight(19);
  12936. tmp.assign(x);
  12937. tmp.rotateRight(61);
  12938. result.xor(tmp);
  12939. tmp.assign(x);
  12940. tmp.shiftRight(6);
  12941. result.xor(tmp);
  12942. }
  12943. var k = [
  12944. new Word64(0x428a2f98, 0xd728ae22), new Word64(0x71374491, 0x23ef65cd),
  12945. new Word64(0xb5c0fbcf, 0xec4d3b2f), new Word64(0xe9b5dba5, 0x8189dbbc),
  12946. new Word64(0x3956c25b, 0xf348b538), new Word64(0x59f111f1, 0xb605d019),
  12947. new Word64(0x923f82a4, 0xaf194f9b), new Word64(0xab1c5ed5, 0xda6d8118),
  12948. new Word64(0xd807aa98, 0xa3030242), new Word64(0x12835b01, 0x45706fbe),
  12949. new Word64(0x243185be, 0x4ee4b28c), new Word64(0x550c7dc3, 0xd5ffb4e2),
  12950. new Word64(0x72be5d74, 0xf27b896f), new Word64(0x80deb1fe, 0x3b1696b1),
  12951. new Word64(0x9bdc06a7, 0x25c71235), new Word64(0xc19bf174, 0xcf692694),
  12952. new Word64(0xe49b69c1, 0x9ef14ad2), new Word64(0xefbe4786, 0x384f25e3),
  12953. new Word64(0x0fc19dc6, 0x8b8cd5b5), new Word64(0x240ca1cc, 0x77ac9c65),
  12954. new Word64(0x2de92c6f, 0x592b0275), new Word64(0x4a7484aa, 0x6ea6e483),
  12955. new Word64(0x5cb0a9dc, 0xbd41fbd4), new Word64(0x76f988da, 0x831153b5),
  12956. new Word64(0x983e5152, 0xee66dfab), new Word64(0xa831c66d, 0x2db43210),
  12957. new Word64(0xb00327c8, 0x98fb213f), new Word64(0xbf597fc7, 0xbeef0ee4),
  12958. new Word64(0xc6e00bf3, 0x3da88fc2), new Word64(0xd5a79147, 0x930aa725),
  12959. new Word64(0x06ca6351, 0xe003826f), new Word64(0x14292967, 0x0a0e6e70),
  12960. new Word64(0x27b70a85, 0x46d22ffc), new Word64(0x2e1b2138, 0x5c26c926),
  12961. new Word64(0x4d2c6dfc, 0x5ac42aed), new Word64(0x53380d13, 0x9d95b3df),
  12962. new Word64(0x650a7354, 0x8baf63de), new Word64(0x766a0abb, 0x3c77b2a8),
  12963. new Word64(0x81c2c92e, 0x47edaee6), new Word64(0x92722c85, 0x1482353b),
  12964. new Word64(0xa2bfe8a1, 0x4cf10364), new Word64(0xa81a664b, 0xbc423001),
  12965. new Word64(0xc24b8b70, 0xd0f89791), new Word64(0xc76c51a3, 0x0654be30),
  12966. new Word64(0xd192e819, 0xd6ef5218), new Word64(0xd6990624, 0x5565a910),
  12967. new Word64(0xf40e3585, 0x5771202a), new Word64(0x106aa070, 0x32bbd1b8),
  12968. new Word64(0x19a4c116, 0xb8d2d0c8), new Word64(0x1e376c08, 0x5141ab53),
  12969. new Word64(0x2748774c, 0xdf8eeb99), new Word64(0x34b0bcb5, 0xe19b48a8),
  12970. new Word64(0x391c0cb3, 0xc5c95a63), new Word64(0x4ed8aa4a, 0xe3418acb),
  12971. new Word64(0x5b9cca4f, 0x7763e373), new Word64(0x682e6ff3, 0xd6b2b8a3),
  12972. new Word64(0x748f82ee, 0x5defb2fc), new Word64(0x78a5636f, 0x43172f60),
  12973. new Word64(0x84c87814, 0xa1f0ab72), new Word64(0x8cc70208, 0x1a6439ec),
  12974. new Word64(0x90befffa, 0x23631e28), new Word64(0xa4506ceb, 0xde82bde9),
  12975. new Word64(0xbef9a3f7, 0xb2c67915), new Word64(0xc67178f2, 0xe372532b),
  12976. new Word64(0xca273ece, 0xea26619c), new Word64(0xd186b8c7, 0x21c0c207),
  12977. new Word64(0xeada7dd6, 0xcde0eb1e), new Word64(0xf57d4f7f, 0xee6ed178),
  12978. new Word64(0x06f067aa, 0x72176fba), new Word64(0x0a637dc5, 0xa2c898a6),
  12979. new Word64(0x113f9804, 0xbef90dae), new Word64(0x1b710b35, 0x131c471b),
  12980. new Word64(0x28db77f5, 0x23047d84), new Word64(0x32caab7b, 0x40c72493),
  12981. new Word64(0x3c9ebe0a, 0x15c9bebc), new Word64(0x431d67c4, 0x9c100d4c),
  12982. new Word64(0x4cc5d4be, 0xcb3e42b6), new Word64(0x597f299c, 0xfc657e2a),
  12983. new Word64(0x5fcb6fab, 0x3ad6faec), new Word64(0x6c44198c, 0x4a475817)];
  12984. function hash(data, offset, length, mode384) {
  12985. mode384 = !!mode384;
  12986. // initial hash values
  12987. var h0, h1, h2, h3, h4, h5, h6, h7;
  12988. if (!mode384) {
  12989. h0 = new Word64(0x6a09e667, 0xf3bcc908);
  12990. h1 = new Word64(0xbb67ae85, 0x84caa73b);
  12991. h2 = new Word64(0x3c6ef372, 0xfe94f82b);
  12992. h3 = new Word64(0xa54ff53a, 0x5f1d36f1);
  12993. h4 = new Word64(0x510e527f, 0xade682d1);
  12994. h5 = new Word64(0x9b05688c, 0x2b3e6c1f);
  12995. h6 = new Word64(0x1f83d9ab, 0xfb41bd6b);
  12996. h7 = new Word64(0x5be0cd19, 0x137e2179);
  12997. }
  12998. else {
  12999. // SHA384 is exactly the same
  13000. // except with different starting values and a trimmed result
  13001. h0 = new Word64(0xcbbb9d5d, 0xc1059ed8);
  13002. h1 = new Word64(0x629a292a, 0x367cd507);
  13003. h2 = new Word64(0x9159015a, 0x3070dd17);
  13004. h3 = new Word64(0x152fecd8, 0xf70e5939);
  13005. h4 = new Word64(0x67332667, 0xffc00b31);
  13006. h5 = new Word64(0x8eb44a87, 0x68581511);
  13007. h6 = new Word64(0xdb0c2e0d, 0x64f98fa7);
  13008. h7 = new Word64(0x47b5481d, 0xbefa4fa4);
  13009. }
  13010. // pre-processing
  13011. var paddedLength = Math.ceil((length + 17) / 128) * 128;
  13012. var padded = new Uint8Array(paddedLength);
  13013. var i, j, n;
  13014. for (i = 0; i < length; ++i) {
  13015. padded[i] = data[offset++];
  13016. }
  13017. padded[i++] = 0x80;
  13018. n = paddedLength - 16;
  13019. while (i < n) {
  13020. padded[i++] = 0;
  13021. }
  13022. padded[i++] = 0;
  13023. padded[i++] = 0;
  13024. padded[i++] = 0;
  13025. padded[i++] = 0;
  13026. padded[i++] = 0;
  13027. padded[i++] = 0;
  13028. padded[i++] = 0;
  13029. padded[i++] = 0;
  13030. padded[i++] = 0;
  13031. padded[i++] = 0;
  13032. padded[i++] = 0;
  13033. padded[i++] = (length >>> 29) & 0xFF;
  13034. padded[i++] = (length >> 21) & 0xFF;
  13035. padded[i++] = (length >> 13) & 0xFF;
  13036. padded[i++] = (length >> 5) & 0xFF;
  13037. padded[i++] = (length << 3) & 0xFF;
  13038. var w = new Array(80);
  13039. for (i = 0; i < 80; i++) {
  13040. w[i] = new Word64(0, 0);
  13041. }
  13042. var a = new Word64(0, 0), b = new Word64(0, 0), c = new Word64(0, 0);
  13043. var d = new Word64(0, 0), e = new Word64(0, 0), f = new Word64(0, 0);
  13044. var g = new Word64(0, 0), h = new Word64(0, 0);
  13045. var t1 = new Word64(0, 0), t2 = new Word64(0, 0);
  13046. var tmp1 = new Word64(0, 0), tmp2 = new Word64(0, 0), tmp3;
  13047. // for each 1024 bit block
  13048. for (i = 0; i < paddedLength;) {
  13049. for (j = 0; j < 16; ++j) {
  13050. w[j].high = (padded[i] << 24) | (padded[i + 1] << 16) |
  13051. (padded[i + 2] << 8) | (padded[i + 3]);
  13052. w[j].low = (padded[i + 4]) << 24 | (padded[i + 5]) << 16 |
  13053. (padded[i + 6]) << 8 | (padded[i + 7]);
  13054. i += 8;
  13055. }
  13056. for (j = 16; j < 80; ++j) {
  13057. tmp3 = w[j];
  13058. littleSigmaPrime(tmp3, w[j - 2], tmp2);
  13059. tmp3.add(w[j - 7]);
  13060. littleSigma(tmp1, w[j - 15], tmp2);
  13061. tmp3.add(tmp1);
  13062. tmp3.add(w[j - 16]);
  13063. }
  13064. a.assign(h0); b.assign(h1); c.assign(h2); d.assign(h3);
  13065. e.assign(h4); f.assign(h5); g.assign(h6); h.assign(h7);
  13066. for (j = 0; j < 80; ++j) {
  13067. t1.assign(h);
  13068. sigmaPrime(tmp1, e, tmp2);
  13069. t1.add(tmp1);
  13070. ch(tmp1, e, f, g, tmp2);
  13071. t1.add(tmp1);
  13072. t1.add(k[j]);
  13073. t1.add(w[j]);
  13074. sigma(t2, a, tmp2);
  13075. maj(tmp1, a, b, c, tmp2);
  13076. t2.add(tmp1);
  13077. tmp3 = h;
  13078. h = g;
  13079. g = f;
  13080. f = e;
  13081. d.add(t1);
  13082. e = d;
  13083. d = c;
  13084. c = b;
  13085. b = a;
  13086. tmp3.assign(t1);
  13087. tmp3.add(t2);
  13088. a = tmp3;
  13089. }
  13090. h0.add(a);
  13091. h1.add(b);
  13092. h2.add(c);
  13093. h3.add(d);
  13094. h4.add(e);
  13095. h5.add(f);
  13096. h6.add(g);
  13097. h7.add(h);
  13098. }
  13099. var result;
  13100. if (!mode384) {
  13101. result = new Uint8Array(64);
  13102. h0.copyTo(result,0);
  13103. h1.copyTo(result,8);
  13104. h2.copyTo(result,16);
  13105. h3.copyTo(result,24);
  13106. h4.copyTo(result,32);
  13107. h5.copyTo(result,40);
  13108. h6.copyTo(result,48);
  13109. h7.copyTo(result,56);
  13110. }
  13111. else {
  13112. result = new Uint8Array(48);
  13113. h0.copyTo(result,0);
  13114. h1.copyTo(result,8);
  13115. h2.copyTo(result,16);
  13116. h3.copyTo(result,24);
  13117. h4.copyTo(result,32);
  13118. h5.copyTo(result,40);
  13119. }
  13120. return result;
  13121. }
  13122. return hash;
  13123. })();
  13124. var calculateSHA384 = (function calculateSHA384Closure() {
  13125. function hash(data, offset, length) {
  13126. return calculateSHA512(data, offset, length, true);
  13127. }
  13128. return hash;
  13129. })();
  13130. var NullCipher = (function NullCipherClosure() {
  13131. function NullCipher() {
  13132. }
  13133. NullCipher.prototype = {
  13134. decryptBlock: function NullCipher_decryptBlock(data) {
  13135. return data;
  13136. }
  13137. };
  13138. return NullCipher;
  13139. })();
  13140. var AES128Cipher = (function AES128CipherClosure() {
  13141. var rcon = new Uint8Array([
  13142. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  13143. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  13144. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  13145. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  13146. 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  13147. 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
  13148. 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
  13149. 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
  13150. 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
  13151. 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
  13152. 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
  13153. 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
  13154. 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
  13155. 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
  13156. 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
  13157. 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
  13158. 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
  13159. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  13160. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  13161. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  13162. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  13163. 0x74, 0xe8, 0xcb, 0x8d]);
  13164. var s = new Uint8Array([
  13165. 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
  13166. 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
  13167. 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
  13168. 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
  13169. 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
  13170. 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
  13171. 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
  13172. 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
  13173. 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
  13174. 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
  13175. 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
  13176. 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
  13177. 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
  13178. 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
  13179. 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
  13180. 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
  13181. 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
  13182. 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
  13183. 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
  13184. 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
  13185. 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
  13186. 0xb0, 0x54, 0xbb, 0x16]);
  13187. var inv_s = new Uint8Array([
  13188. 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
  13189. 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
  13190. 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
  13191. 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
  13192. 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
  13193. 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
  13194. 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
  13195. 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
  13196. 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
  13197. 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
  13198. 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
  13199. 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
  13200. 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
  13201. 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
  13202. 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
  13203. 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
  13204. 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
  13205. 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
  13206. 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
  13207. 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
  13208. 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
  13209. 0x55, 0x21, 0x0c, 0x7d]);
  13210. var mixCol = new Uint8Array(256);
  13211. for (var i = 0; i < 256; i++) {
  13212. if (i < 128) {
  13213. mixCol[i] = i << 1;
  13214. } else {
  13215. mixCol[i] = (i << 1) ^ 0x1b;
  13216. }
  13217. }
  13218. var mix = new Uint32Array([
  13219. 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
  13220. 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
  13221. 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
  13222. 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
  13223. 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
  13224. 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
  13225. 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
  13226. 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
  13227. 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
  13228. 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
  13229. 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
  13230. 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
  13231. 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
  13232. 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
  13233. 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
  13234. 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
  13235. 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
  13236. 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
  13237. 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
  13238. 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
  13239. 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
  13240. 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
  13241. 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
  13242. 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
  13243. 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
  13244. 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
  13245. 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
  13246. 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
  13247. 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
  13248. 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
  13249. 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
  13250. 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
  13251. 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
  13252. 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
  13253. 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
  13254. 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
  13255. 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
  13256. 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
  13257. 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
  13258. 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
  13259. 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
  13260. 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
  13261. 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
  13262. function expandKey128(cipherKey) {
  13263. var b = 176, result = new Uint8Array(b);
  13264. result.set(cipherKey);
  13265. for (var j = 16, i = 1; j < b; ++i) {
  13266. // RotWord
  13267. var t1 = result[j - 3], t2 = result[j - 2],
  13268. t3 = result[j - 1], t4 = result[j - 4];
  13269. // SubWord
  13270. t1 = s[t1];
  13271. t2 = s[t2];
  13272. t3 = s[t3];
  13273. t4 = s[t4];
  13274. // Rcon
  13275. t1 = t1 ^ rcon[i];
  13276. for (var n = 0; n < 4; ++n) {
  13277. result[j] = (t1 ^= result[j - 16]);
  13278. j++;
  13279. result[j] = (t2 ^= result[j - 16]);
  13280. j++;
  13281. result[j] = (t3 ^= result[j - 16]);
  13282. j++;
  13283. result[j] = (t4 ^= result[j - 16]);
  13284. j++;
  13285. }
  13286. }
  13287. return result;
  13288. }
  13289. function decrypt128(input, key) {
  13290. var state = new Uint8Array(16);
  13291. state.set(input);
  13292. var i, j, k;
  13293. var t, u, v;
  13294. // AddRoundKey
  13295. for (j = 0, k = 160; j < 16; ++j, ++k) {
  13296. state[j] ^= key[k];
  13297. }
  13298. for (i = 9; i >= 1; --i) {
  13299. // InvShiftRows
  13300. t = state[13];
  13301. state[13] = state[9];
  13302. state[9] = state[5];
  13303. state[5] = state[1];
  13304. state[1] = t;
  13305. t = state[14];
  13306. u = state[10];
  13307. state[14] = state[6];
  13308. state[10] = state[2];
  13309. state[6] = t;
  13310. state[2] = u;
  13311. t = state[15];
  13312. u = state[11];
  13313. v = state[7];
  13314. state[15] = state[3];
  13315. state[11] = t;
  13316. state[7] = u;
  13317. state[3] = v;
  13318. // InvSubBytes
  13319. for (j = 0; j < 16; ++j) {
  13320. state[j] = inv_s[state[j]];
  13321. }
  13322. // AddRoundKey
  13323. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  13324. state[j] ^= key[k];
  13325. }
  13326. // InvMixColumns
  13327. for (j = 0; j < 16; j += 4) {
  13328. var s0 = mix[state[j]], s1 = mix[state[j + 1]],
  13329. s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  13330. t = (s0 ^ (s1 >>> 8) ^ (s1 << 24) ^ (s2 >>> 16) ^ (s2 << 16) ^
  13331. (s3 >>> 24) ^ (s3 << 8));
  13332. state[j] = (t >>> 24) & 0xFF;
  13333. state[j + 1] = (t >> 16) & 0xFF;
  13334. state[j + 2] = (t >> 8) & 0xFF;
  13335. state[j + 3] = t & 0xFF;
  13336. }
  13337. }
  13338. // InvShiftRows
  13339. t = state[13];
  13340. state[13] = state[9];
  13341. state[9] = state[5];
  13342. state[5] = state[1];
  13343. state[1] = t;
  13344. t = state[14];
  13345. u = state[10];
  13346. state[14] = state[6];
  13347. state[10] = state[2];
  13348. state[6] = t;
  13349. state[2] = u;
  13350. t = state[15];
  13351. u = state[11];
  13352. v = state[7];
  13353. state[15] = state[3];
  13354. state[11] = t;
  13355. state[7] = u;
  13356. state[3] = v;
  13357. for (j = 0; j < 16; ++j) {
  13358. // InvSubBytes
  13359. state[j] = inv_s[state[j]];
  13360. // AddRoundKey
  13361. state[j] ^= key[j];
  13362. }
  13363. return state;
  13364. }
  13365. function encrypt128(input, key) {
  13366. var t, u, v, k;
  13367. var state = new Uint8Array(16);
  13368. state.set(input);
  13369. for (j = 0; j < 16; ++j) {
  13370. // AddRoundKey
  13371. state[j] ^= key[j];
  13372. }
  13373. for (i = 1; i < 10; i++) {
  13374. //SubBytes
  13375. for (j = 0; j < 16; ++j) {
  13376. state[j] = s[state[j]];
  13377. }
  13378. //ShiftRows
  13379. v = state[1];
  13380. state[1] = state[5];
  13381. state[5] = state[9];
  13382. state[9] = state[13];
  13383. state[13] = v;
  13384. v = state[2];
  13385. u = state[6];
  13386. state[2] = state[10];
  13387. state[6] = state[14];
  13388. state[10] = v;
  13389. state[14] = u;
  13390. v = state[3];
  13391. u = state[7];
  13392. t = state[11];
  13393. state[3] = state[15];
  13394. state[7] = v;
  13395. state[11] = u;
  13396. state[15] = t;
  13397. //MixColumns
  13398. for (var j = 0; j < 16; j += 4) {
  13399. var s0 = state[j + 0], s1 = state[j + 1];
  13400. var s2 = state[j + 2], s3 = state[j + 3];
  13401. t = s0 ^ s1 ^ s2 ^ s3;
  13402. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  13403. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  13404. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  13405. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  13406. }
  13407. //AddRoundKey
  13408. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  13409. state[j] ^= key[k];
  13410. }
  13411. }
  13412. //SubBytes
  13413. for (j = 0; j < 16; ++j) {
  13414. state[j] = s[state[j]];
  13415. }
  13416. //ShiftRows
  13417. v = state[1];
  13418. state[1] = state[5];
  13419. state[5] = state[9];
  13420. state[9] = state[13];
  13421. state[13] = v;
  13422. v = state[2];
  13423. u = state[6];
  13424. state[2] = state[10];
  13425. state[6] = state[14];
  13426. state[10] = v;
  13427. state[14] = u;
  13428. v = state[3];
  13429. u = state[7];
  13430. t = state[11];
  13431. state[3] = state[15];
  13432. state[7] = v;
  13433. state[11] = u;
  13434. state[15] = t;
  13435. //AddRoundKey
  13436. for (j = 0, k = 160; j < 16; ++j, ++k) {
  13437. state[j] ^= key[k];
  13438. }
  13439. return state;
  13440. }
  13441. function AES128Cipher(key) {
  13442. this.key = expandKey128(key);
  13443. this.buffer = new Uint8Array(16);
  13444. this.bufferPosition = 0;
  13445. }
  13446. function decryptBlock2(data, finalize) {
  13447. var i, j, ii, sourceLength = data.length,
  13448. buffer = this.buffer, bufferLength = this.bufferPosition,
  13449. result = [], iv = this.iv;
  13450. for (i = 0; i < sourceLength; ++i) {
  13451. buffer[bufferLength] = data[i];
  13452. ++bufferLength;
  13453. if (bufferLength < 16) {
  13454. continue;
  13455. }
  13456. // buffer is full, decrypting
  13457. var plain = decrypt128(buffer, this.key);
  13458. // xor-ing the IV vector to get plain text
  13459. for (j = 0; j < 16; ++j) {
  13460. plain[j] ^= iv[j];
  13461. }
  13462. iv = buffer;
  13463. result.push(plain);
  13464. buffer = new Uint8Array(16);
  13465. bufferLength = 0;
  13466. }
  13467. // saving incomplete buffer
  13468. this.buffer = buffer;
  13469. this.bufferLength = bufferLength;
  13470. this.iv = iv;
  13471. if (result.length === 0) {
  13472. return new Uint8Array([]);
  13473. }
  13474. // combining plain text blocks into one
  13475. var outputLength = 16 * result.length;
  13476. if (finalize) {
  13477. // undo a padding that is described in RFC 2898
  13478. var lastBlock = result[result.length - 1];
  13479. var psLen = lastBlock[15];
  13480. if (psLen <= 16) {
  13481. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  13482. if (lastBlock[i] !== psLen) {
  13483. // Invalid padding, assume that the block has no padding.
  13484. psLen = 0;
  13485. break;
  13486. }
  13487. }
  13488. outputLength -= psLen;
  13489. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  13490. }
  13491. }
  13492. var output = new Uint8Array(outputLength);
  13493. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  13494. output.set(result[i], j);
  13495. }
  13496. return output;
  13497. }
  13498. AES128Cipher.prototype = {
  13499. decryptBlock: function AES128Cipher_decryptBlock(data, finalize) {
  13500. var i, sourceLength = data.length;
  13501. var buffer = this.buffer, bufferLength = this.bufferPosition;
  13502. // waiting for IV values -- they are at the start of the stream
  13503. for (i = 0; bufferLength < 16 && i < sourceLength; ++i, ++bufferLength) {
  13504. buffer[bufferLength] = data[i];
  13505. }
  13506. if (bufferLength < 16) {
  13507. // need more data
  13508. this.bufferLength = bufferLength;
  13509. return new Uint8Array([]);
  13510. }
  13511. this.iv = buffer;
  13512. this.buffer = new Uint8Array(16);
  13513. this.bufferLength = 0;
  13514. // starting decryption
  13515. this.decryptBlock = decryptBlock2;
  13516. return this.decryptBlock(data.subarray(16), finalize);
  13517. },
  13518. encrypt: function AES128Cipher_encrypt(data, iv) {
  13519. var i, j, ii, sourceLength = data.length,
  13520. buffer = this.buffer, bufferLength = this.bufferPosition,
  13521. result = [];
  13522. if (!iv) {
  13523. iv = new Uint8Array(16);
  13524. }
  13525. for (i = 0; i < sourceLength; ++i) {
  13526. buffer[bufferLength] = data[i];
  13527. ++bufferLength;
  13528. if (bufferLength < 16) {
  13529. continue;
  13530. }
  13531. for (j = 0; j < 16; ++j) {
  13532. buffer[j] ^= iv[j];
  13533. }
  13534. // buffer is full, encrypting
  13535. var cipher = encrypt128(buffer, this.key);
  13536. iv = cipher;
  13537. result.push(cipher);
  13538. buffer = new Uint8Array(16);
  13539. bufferLength = 0;
  13540. }
  13541. // saving incomplete buffer
  13542. this.buffer = buffer;
  13543. this.bufferLength = bufferLength;
  13544. this.iv = iv;
  13545. if (result.length === 0) {
  13546. return new Uint8Array([]);
  13547. }
  13548. // combining plain text blocks into one
  13549. var outputLength = 16 * result.length;
  13550. var output = new Uint8Array(outputLength);
  13551. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  13552. output.set(result[i], j);
  13553. }
  13554. return output;
  13555. }
  13556. };
  13557. return AES128Cipher;
  13558. })();
  13559. var AES256Cipher = (function AES256CipherClosure() {
  13560. var rcon = new Uint8Array([
  13561. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  13562. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  13563. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  13564. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  13565. 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  13566. 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
  13567. 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
  13568. 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
  13569. 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
  13570. 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
  13571. 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
  13572. 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
  13573. 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
  13574. 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
  13575. 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
  13576. 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
  13577. 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
  13578. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  13579. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  13580. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  13581. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  13582. 0x74, 0xe8, 0xcb, 0x8d]);
  13583. var s = new Uint8Array([
  13584. 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
  13585. 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
  13586. 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
  13587. 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
  13588. 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
  13589. 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
  13590. 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
  13591. 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
  13592. 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
  13593. 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
  13594. 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
  13595. 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
  13596. 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
  13597. 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
  13598. 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
  13599. 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
  13600. 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
  13601. 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
  13602. 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
  13603. 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
  13604. 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
  13605. 0xb0, 0x54, 0xbb, 0x16]);
  13606. var inv_s = new Uint8Array([
  13607. 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
  13608. 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
  13609. 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
  13610. 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
  13611. 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
  13612. 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
  13613. 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
  13614. 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
  13615. 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
  13616. 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
  13617. 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
  13618. 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
  13619. 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
  13620. 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
  13621. 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
  13622. 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
  13623. 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
  13624. 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
  13625. 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
  13626. 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
  13627. 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
  13628. 0x55, 0x21, 0x0c, 0x7d]);
  13629. var mixCol = new Uint8Array(256);
  13630. for (var i = 0; i < 256; i++) {
  13631. if (i < 128) {
  13632. mixCol[i] = i << 1;
  13633. } else {
  13634. mixCol[i] = (i << 1) ^ 0x1b;
  13635. }
  13636. }
  13637. var mix = new Uint32Array([
  13638. 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
  13639. 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
  13640. 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
  13641. 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
  13642. 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
  13643. 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
  13644. 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
  13645. 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
  13646. 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
  13647. 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
  13648. 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
  13649. 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
  13650. 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
  13651. 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
  13652. 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
  13653. 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
  13654. 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
  13655. 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
  13656. 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
  13657. 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
  13658. 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
  13659. 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
  13660. 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
  13661. 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
  13662. 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
  13663. 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
  13664. 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
  13665. 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
  13666. 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
  13667. 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
  13668. 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
  13669. 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
  13670. 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
  13671. 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
  13672. 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
  13673. 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
  13674. 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
  13675. 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
  13676. 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
  13677. 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
  13678. 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
  13679. 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
  13680. 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
  13681. function expandKey256(cipherKey) {
  13682. var b = 240, result = new Uint8Array(b);
  13683. var r = 1;
  13684. result.set(cipherKey);
  13685. for (var j = 32, i = 1; j < b; ++i) {
  13686. if (j % 32 === 16) {
  13687. t1 = s[t1];
  13688. t2 = s[t2];
  13689. t3 = s[t3];
  13690. t4 = s[t4];
  13691. } else if (j % 32 === 0) {
  13692. // RotWord
  13693. var t1 = result[j - 3], t2 = result[j - 2],
  13694. t3 = result[j - 1], t4 = result[j - 4];
  13695. // SubWord
  13696. t1 = s[t1];
  13697. t2 = s[t2];
  13698. t3 = s[t3];
  13699. t4 = s[t4];
  13700. // Rcon
  13701. t1 = t1 ^ r;
  13702. if ((r <<= 1) >= 256) {
  13703. r = (r ^ 0x1b) & 0xFF;
  13704. }
  13705. }
  13706. for (var n = 0; n < 4; ++n) {
  13707. result[j] = (t1 ^= result[j - 32]);
  13708. j++;
  13709. result[j] = (t2 ^= result[j - 32]);
  13710. j++;
  13711. result[j] = (t3 ^= result[j - 32]);
  13712. j++;
  13713. result[j] = (t4 ^= result[j - 32]);
  13714. j++;
  13715. }
  13716. }
  13717. return result;
  13718. }
  13719. function decrypt256(input, key) {
  13720. var state = new Uint8Array(16);
  13721. state.set(input);
  13722. var i, j, k;
  13723. var t, u, v;
  13724. // AddRoundKey
  13725. for (j = 0, k = 224; j < 16; ++j, ++k) {
  13726. state[j] ^= key[k];
  13727. }
  13728. for (i = 13; i >= 1; --i) {
  13729. // InvShiftRows
  13730. t = state[13];
  13731. state[13] = state[9];
  13732. state[9] = state[5];
  13733. state[5] = state[1];
  13734. state[1] = t;
  13735. t = state[14];
  13736. u = state[10];
  13737. state[14] = state[6];
  13738. state[10] = state[2];
  13739. state[6] = t;
  13740. state[2] = u;
  13741. t = state[15];
  13742. u = state[11];
  13743. v = state[7];
  13744. state[15] = state[3];
  13745. state[11] = t;
  13746. state[7] = u;
  13747. state[3] = v;
  13748. // InvSubBytes
  13749. for (j = 0; j < 16; ++j) {
  13750. state[j] = inv_s[state[j]];
  13751. }
  13752. // AddRoundKey
  13753. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  13754. state[j] ^= key[k];
  13755. }
  13756. // InvMixColumns
  13757. for (j = 0; j < 16; j += 4) {
  13758. var s0 = mix[state[j]], s1 = mix[state[j + 1]],
  13759. s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  13760. t = (s0 ^ (s1 >>> 8) ^ (s1 << 24) ^ (s2 >>> 16) ^ (s2 << 16) ^
  13761. (s3 >>> 24) ^ (s3 << 8));
  13762. state[j] = (t >>> 24) & 0xFF;
  13763. state[j + 1] = (t >> 16) & 0xFF;
  13764. state[j + 2] = (t >> 8) & 0xFF;
  13765. state[j + 3] = t & 0xFF;
  13766. }
  13767. }
  13768. // InvShiftRows
  13769. t = state[13];
  13770. state[13] = state[9];
  13771. state[9] = state[5];
  13772. state[5] = state[1];
  13773. state[1] = t;
  13774. t = state[14];
  13775. u = state[10];
  13776. state[14] = state[6];
  13777. state[10] = state[2];
  13778. state[6] = t;
  13779. state[2] = u;
  13780. t = state[15];
  13781. u = state[11];
  13782. v = state[7];
  13783. state[15] = state[3];
  13784. state[11] = t;
  13785. state[7] = u;
  13786. state[3] = v;
  13787. for (j = 0; j < 16; ++j) {
  13788. // InvSubBytes
  13789. state[j] = inv_s[state[j]];
  13790. // AddRoundKey
  13791. state[j] ^= key[j];
  13792. }
  13793. return state;
  13794. }
  13795. function encrypt256(input, key) {
  13796. var t, u, v, k;
  13797. var state = new Uint8Array(16);
  13798. state.set(input);
  13799. for (j = 0; j < 16; ++j) {
  13800. // AddRoundKey
  13801. state[j] ^= key[j];
  13802. }
  13803. for (i = 1; i < 14; i++) {
  13804. //SubBytes
  13805. for (j = 0; j < 16; ++j) {
  13806. state[j] = s[state[j]];
  13807. }
  13808. //ShiftRows
  13809. v = state[1];
  13810. state[1] = state[5];
  13811. state[5] = state[9];
  13812. state[9] = state[13];
  13813. state[13] = v;
  13814. v = state[2];
  13815. u = state[6];
  13816. state[2] = state[10];
  13817. state[6] = state[14];
  13818. state[10] = v;
  13819. state[14] = u;
  13820. v = state[3];
  13821. u = state[7];
  13822. t = state[11];
  13823. state[3] = state[15];
  13824. state[7] = v;
  13825. state[11] = u;
  13826. state[15] = t;
  13827. //MixColumns
  13828. for (var j = 0; j < 16; j += 4) {
  13829. var s0 = state[j + 0], s1 = state[j + 1];
  13830. var s2 = state[j + 2], s3 = state[j + 3];
  13831. t = s0 ^ s1 ^ s2 ^ s3;
  13832. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  13833. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  13834. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  13835. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  13836. }
  13837. //AddRoundKey
  13838. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  13839. state[j] ^= key[k];
  13840. }
  13841. }
  13842. //SubBytes
  13843. for (j = 0; j < 16; ++j) {
  13844. state[j] = s[state[j]];
  13845. }
  13846. //ShiftRows
  13847. v = state[1];
  13848. state[1] = state[5];
  13849. state[5] = state[9];
  13850. state[9] = state[13];
  13851. state[13] = v;
  13852. v = state[2];
  13853. u = state[6];
  13854. state[2] = state[10];
  13855. state[6] = state[14];
  13856. state[10] = v;
  13857. state[14] = u;
  13858. v = state[3];
  13859. u = state[7];
  13860. t = state[11];
  13861. state[3] = state[15];
  13862. state[7] = v;
  13863. state[11] = u;
  13864. state[15] = t;
  13865. //AddRoundKey
  13866. for (j = 0, k = 224; j < 16; ++j, ++k) {
  13867. state[j] ^= key[k];
  13868. }
  13869. return state;
  13870. }
  13871. function AES256Cipher(key) {
  13872. this.key = expandKey256(key);
  13873. this.buffer = new Uint8Array(16);
  13874. this.bufferPosition = 0;
  13875. }
  13876. function decryptBlock2(data, finalize) {
  13877. var i, j, ii, sourceLength = data.length,
  13878. buffer = this.buffer, bufferLength = this.bufferPosition,
  13879. result = [], iv = this.iv;
  13880. for (i = 0; i < sourceLength; ++i) {
  13881. buffer[bufferLength] = data[i];
  13882. ++bufferLength;
  13883. if (bufferLength < 16) {
  13884. continue;
  13885. }
  13886. // buffer is full, decrypting
  13887. var plain = decrypt256(buffer, this.key);
  13888. // xor-ing the IV vector to get plain text
  13889. for (j = 0; j < 16; ++j) {
  13890. plain[j] ^= iv[j];
  13891. }
  13892. iv = buffer;
  13893. result.push(plain);
  13894. buffer = new Uint8Array(16);
  13895. bufferLength = 0;
  13896. }
  13897. // saving incomplete buffer
  13898. this.buffer = buffer;
  13899. this.bufferLength = bufferLength;
  13900. this.iv = iv;
  13901. if (result.length === 0) {
  13902. return new Uint8Array([]);
  13903. }
  13904. // combining plain text blocks into one
  13905. var outputLength = 16 * result.length;
  13906. if (finalize) {
  13907. // undo a padding that is described in RFC 2898
  13908. var lastBlock = result[result.length - 1];
  13909. var psLen = lastBlock[15];
  13910. if (psLen <= 16) {
  13911. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  13912. if (lastBlock[i] !== psLen) {
  13913. // Invalid padding, assume that the block has no padding.
  13914. psLen = 0;
  13915. break;
  13916. }
  13917. }
  13918. outputLength -= psLen;
  13919. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  13920. }
  13921. }
  13922. var output = new Uint8Array(outputLength);
  13923. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  13924. output.set(result[i], j);
  13925. }
  13926. return output;
  13927. }
  13928. AES256Cipher.prototype = {
  13929. decryptBlock: function AES256Cipher_decryptBlock(data, finalize, iv) {
  13930. var i, sourceLength = data.length;
  13931. var buffer = this.buffer, bufferLength = this.bufferPosition;
  13932. // if not supplied an IV wait for IV values
  13933. // they are at the start of the stream
  13934. if (iv) {
  13935. this.iv = iv;
  13936. } else {
  13937. for (i = 0; bufferLength < 16 &&
  13938. i < sourceLength; ++i, ++bufferLength) {
  13939. buffer[bufferLength] = data[i];
  13940. }
  13941. if (bufferLength < 16) {
  13942. //need more data
  13943. this.bufferLength = bufferLength;
  13944. return new Uint8Array([]);
  13945. }
  13946. this.iv = buffer;
  13947. data = data.subarray(16);
  13948. }
  13949. this.buffer = new Uint8Array(16);
  13950. this.bufferLength = 0;
  13951. // starting decryption
  13952. this.decryptBlock = decryptBlock2;
  13953. return this.decryptBlock(data, finalize);
  13954. },
  13955. encrypt: function AES256Cipher_encrypt(data, iv) {
  13956. var i, j, ii, sourceLength = data.length,
  13957. buffer = this.buffer, bufferLength = this.bufferPosition,
  13958. result = [];
  13959. if (!iv) {
  13960. iv = new Uint8Array(16);
  13961. }
  13962. for (i = 0; i < sourceLength; ++i) {
  13963. buffer[bufferLength] = data[i];
  13964. ++bufferLength;
  13965. if (bufferLength < 16) {
  13966. continue;
  13967. }
  13968. for (j = 0; j < 16; ++j) {
  13969. buffer[j] ^= iv[j];
  13970. }
  13971. // buffer is full, encrypting
  13972. var cipher = encrypt256(buffer, this.key);
  13973. this.iv = cipher;
  13974. result.push(cipher);
  13975. buffer = new Uint8Array(16);
  13976. bufferLength = 0;
  13977. }
  13978. // saving incomplete buffer
  13979. this.buffer = buffer;
  13980. this.bufferLength = bufferLength;
  13981. this.iv = iv;
  13982. if (result.length === 0) {
  13983. return new Uint8Array([]);
  13984. }
  13985. // combining plain text blocks into one
  13986. var outputLength = 16 * result.length;
  13987. var output = new Uint8Array(outputLength);
  13988. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  13989. output.set(result[i], j);
  13990. }
  13991. return output;
  13992. }
  13993. };
  13994. return AES256Cipher;
  13995. })();
  13996. var PDF17 = (function PDF17Closure() {
  13997. function compareByteArrays(array1, array2) {
  13998. if (array1.length !== array2.length) {
  13999. return false;
  14000. }
  14001. for (var i = 0; i < array1.length; i++) {
  14002. if (array1[i] !== array2[i]) {
  14003. return false;
  14004. }
  14005. }
  14006. return true;
  14007. }
  14008. function PDF17() {
  14009. }
  14010. PDF17.prototype = {
  14011. checkOwnerPassword: function PDF17_checkOwnerPassword(password,
  14012. ownerValidationSalt,
  14013. userBytes,
  14014. ownerPassword) {
  14015. var hashData = new Uint8Array(password.length + 56);
  14016. hashData.set(password, 0);
  14017. hashData.set(ownerValidationSalt, password.length);
  14018. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  14019. var result = calculateSHA256(hashData, 0, hashData.length);
  14020. return compareByteArrays(result, ownerPassword);
  14021. },
  14022. checkUserPassword: function PDF17_checkUserPassword(password,
  14023. userValidationSalt,
  14024. userPassword) {
  14025. var hashData = new Uint8Array(password.length + 8);
  14026. hashData.set(password, 0);
  14027. hashData.set(userValidationSalt, password.length);
  14028. var result = calculateSHA256(hashData, 0, hashData.length);
  14029. return compareByteArrays(result, userPassword);
  14030. },
  14031. getOwnerKey: function PDF17_getOwnerKey(password, ownerKeySalt, userBytes,
  14032. ownerEncryption) {
  14033. var hashData = new Uint8Array(password.length + 56);
  14034. hashData.set(password, 0);
  14035. hashData.set(ownerKeySalt, password.length);
  14036. hashData.set(userBytes, password.length + ownerKeySalt.length);
  14037. var key = calculateSHA256(hashData, 0, hashData.length);
  14038. var cipher = new AES256Cipher(key);
  14039. return cipher.decryptBlock(ownerEncryption,
  14040. false,
  14041. new Uint8Array(16));
  14042. },
  14043. getUserKey: function PDF17_getUserKey(password, userKeySalt,
  14044. userEncryption) {
  14045. var hashData = new Uint8Array(password.length + 8);
  14046. hashData.set(password, 0);
  14047. hashData.set(userKeySalt, password.length);
  14048. //key is the decryption key for the UE string
  14049. var key = calculateSHA256(hashData, 0, hashData.length);
  14050. var cipher = new AES256Cipher(key);
  14051. return cipher.decryptBlock(userEncryption,
  14052. false,
  14053. new Uint8Array(16));
  14054. }
  14055. };
  14056. return PDF17;
  14057. })();
  14058. var PDF20 = (function PDF20Closure() {
  14059. function concatArrays(array1, array2) {
  14060. var t = new Uint8Array(array1.length + array2.length);
  14061. t.set(array1, 0);
  14062. t.set(array2, array1.length);
  14063. return t;
  14064. }
  14065. function calculatePDF20Hash(password, input, userBytes) {
  14066. //This refers to Algorithm 2.B as defined in ISO 32000-2
  14067. var k = calculateSHA256(input, 0, input.length).subarray(0, 32);
  14068. var e = [0];
  14069. var i = 0;
  14070. while (i < 64 || e[e.length - 1] > i - 32) {
  14071. var arrayLength = password.length + k.length + userBytes.length;
  14072. var k1 = new Uint8Array(arrayLength * 64);
  14073. var array = concatArrays(password, k);
  14074. array = concatArrays(array, userBytes);
  14075. for (var j = 0, pos = 0; j < 64; j++, pos += arrayLength) {
  14076. k1.set(array, pos);
  14077. }
  14078. //AES128 CBC NO PADDING with
  14079. //first 16 bytes of k as the key and the second 16 as the iv.
  14080. var cipher = new AES128Cipher(k.subarray(0, 16));
  14081. e = cipher.encrypt(k1, k.subarray(16, 32));
  14082. //Now we have to take the first 16 bytes of an unsigned
  14083. //big endian integer... and compute the remainder
  14084. //modulo 3.... That is a fairly large number and
  14085. //JavaScript isn't going to handle that well...
  14086. //So we're using a trick that allows us to perform
  14087. //modulo math byte by byte
  14088. var remainder = 0;
  14089. for (var z = 0; z < 16; z++) {
  14090. remainder *= (256 % 3);
  14091. remainder %= 3;
  14092. remainder += ((e[z] >>> 0) % 3);
  14093. remainder %= 3;
  14094. }
  14095. if (remainder === 0) {
  14096. k = calculateSHA256(e, 0, e.length);
  14097. }
  14098. else if (remainder === 1) {
  14099. k = calculateSHA384(e, 0, e.length);
  14100. }
  14101. else if (remainder === 2) {
  14102. k = calculateSHA512(e, 0, e.length);
  14103. }
  14104. i++;
  14105. }
  14106. return k.subarray(0, 32);
  14107. }
  14108. function PDF20() {
  14109. }
  14110. function compareByteArrays(array1, array2) {
  14111. if (array1.length !== array2.length) {
  14112. return false;
  14113. }
  14114. for (var i = 0; i < array1.length; i++) {
  14115. if (array1[i] !== array2[i]) {
  14116. return false;
  14117. }
  14118. }
  14119. return true;
  14120. }
  14121. PDF20.prototype = {
  14122. hash: function PDF20_hash(password, concatBytes, userBytes) {
  14123. return calculatePDF20Hash(password, concatBytes, userBytes);
  14124. },
  14125. checkOwnerPassword: function PDF20_checkOwnerPassword(password,
  14126. ownerValidationSalt,
  14127. userBytes,
  14128. ownerPassword) {
  14129. var hashData = new Uint8Array(password.length + 56);
  14130. hashData.set(password, 0);
  14131. hashData.set(ownerValidationSalt, password.length);
  14132. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  14133. var result = calculatePDF20Hash(password, hashData, userBytes);
  14134. return compareByteArrays(result, ownerPassword);
  14135. },
  14136. checkUserPassword: function PDF20_checkUserPassword(password,
  14137. userValidationSalt,
  14138. userPassword) {
  14139. var hashData = new Uint8Array(password.length + 8);
  14140. hashData.set(password, 0);
  14141. hashData.set(userValidationSalt, password.length);
  14142. var result = calculatePDF20Hash(password, hashData, []);
  14143. return compareByteArrays(result, userPassword);
  14144. },
  14145. getOwnerKey: function PDF20_getOwnerKey(password, ownerKeySalt, userBytes,
  14146. ownerEncryption) {
  14147. var hashData = new Uint8Array(password.length + 56);
  14148. hashData.set(password, 0);
  14149. hashData.set(ownerKeySalt, password.length);
  14150. hashData.set(userBytes, password.length + ownerKeySalt.length);
  14151. var key = calculatePDF20Hash(password, hashData, userBytes);
  14152. var cipher = new AES256Cipher(key);
  14153. return cipher.decryptBlock(ownerEncryption,
  14154. false,
  14155. new Uint8Array(16));
  14156. },
  14157. getUserKey: function PDF20_getUserKey(password, userKeySalt,
  14158. userEncryption) {
  14159. var hashData = new Uint8Array(password.length + 8);
  14160. hashData.set(password, 0);
  14161. hashData.set(userKeySalt, password.length);
  14162. //key is the decryption key for the UE string
  14163. var key = calculatePDF20Hash(password, hashData, []);
  14164. var cipher = new AES256Cipher(key);
  14165. return cipher.decryptBlock(userEncryption,
  14166. false,
  14167. new Uint8Array(16));
  14168. }
  14169. };
  14170. return PDF20;
  14171. })();
  14172. var CipherTransform = (function CipherTransformClosure() {
  14173. function CipherTransform(stringCipherConstructor, streamCipherConstructor) {
  14174. this.stringCipherConstructor = stringCipherConstructor;
  14175. this.streamCipherConstructor = streamCipherConstructor;
  14176. }
  14177. CipherTransform.prototype = {
  14178. createStream: function CipherTransform_createStream(stream, length) {
  14179. var cipher = new this.streamCipherConstructor();
  14180. return new DecryptStream(stream, length,
  14181. function cipherTransformDecryptStream(data, finalize) {
  14182. return cipher.decryptBlock(data, finalize);
  14183. }
  14184. );
  14185. },
  14186. decryptString: function CipherTransform_decryptString(s) {
  14187. var cipher = new this.stringCipherConstructor();
  14188. var data = stringToBytes(s);
  14189. data = cipher.decryptBlock(data, true);
  14190. return bytesToString(data);
  14191. }
  14192. };
  14193. return CipherTransform;
  14194. })();
  14195. var CipherTransformFactory = (function CipherTransformFactoryClosure() {
  14196. var defaultPasswordBytes = new Uint8Array([
  14197. 0x28, 0xBF, 0x4E, 0x5E, 0x4E, 0x75, 0x8A, 0x41,
  14198. 0x64, 0x00, 0x4E, 0x56, 0xFF, 0xFA, 0x01, 0x08,
  14199. 0x2E, 0x2E, 0x00, 0xB6, 0xD0, 0x68, 0x3E, 0x80,
  14200. 0x2F, 0x0C, 0xA9, 0xFE, 0x64, 0x53, 0x69, 0x7A]);
  14201. function createEncryptionKey20(revision, password, ownerPassword,
  14202. ownerValidationSalt, ownerKeySalt, uBytes,
  14203. userPassword, userValidationSalt, userKeySalt,
  14204. ownerEncryption, userEncryption, perms) {
  14205. if (password) {
  14206. var passwordLength = Math.min(127, password.length);
  14207. password = password.subarray(0, passwordLength);
  14208. } else {
  14209. password = [];
  14210. }
  14211. var pdfAlgorithm;
  14212. if (revision === 6) {
  14213. pdfAlgorithm = new PDF20();
  14214. } else {
  14215. pdfAlgorithm = new PDF17();
  14216. }
  14217. if (pdfAlgorithm) {
  14218. if (pdfAlgorithm.checkUserPassword(password, userValidationSalt,
  14219. userPassword)) {
  14220. return pdfAlgorithm.getUserKey(password, userKeySalt, userEncryption);
  14221. } else if (pdfAlgorithm.checkOwnerPassword(password, ownerValidationSalt,
  14222. uBytes,
  14223. ownerPassword)) {
  14224. return pdfAlgorithm.getOwnerKey(password, ownerKeySalt, uBytes,
  14225. ownerEncryption);
  14226. }
  14227. }
  14228. return null;
  14229. }
  14230. function prepareKeyData(fileId, password, ownerPassword, userPassword,
  14231. flags, revision, keyLength, encryptMetadata) {
  14232. var hashDataSize = 40 + ownerPassword.length + fileId.length;
  14233. var hashData = new Uint8Array(hashDataSize), i = 0, j, n;
  14234. if (password) {
  14235. n = Math.min(32, password.length);
  14236. for (; i < n; ++i) {
  14237. hashData[i] = password[i];
  14238. }
  14239. }
  14240. j = 0;
  14241. while (i < 32) {
  14242. hashData[i++] = defaultPasswordBytes[j++];
  14243. }
  14244. // as now the padded password in the hashData[0..i]
  14245. for (j = 0, n = ownerPassword.length; j < n; ++j) {
  14246. hashData[i++] = ownerPassword[j];
  14247. }
  14248. hashData[i++] = flags & 0xFF;
  14249. hashData[i++] = (flags >> 8) & 0xFF;
  14250. hashData[i++] = (flags >> 16) & 0xFF;
  14251. hashData[i++] = (flags >>> 24) & 0xFF;
  14252. for (j = 0, n = fileId.length; j < n; ++j) {
  14253. hashData[i++] = fileId[j];
  14254. }
  14255. if (revision >= 4 && !encryptMetadata) {
  14256. hashData[i++] = 0xFF;
  14257. hashData[i++] = 0xFF;
  14258. hashData[i++] = 0xFF;
  14259. hashData[i++] = 0xFF;
  14260. }
  14261. var hash = calculateMD5(hashData, 0, i);
  14262. var keyLengthInBytes = keyLength >> 3;
  14263. if (revision >= 3) {
  14264. for (j = 0; j < 50; ++j) {
  14265. hash = calculateMD5(hash, 0, keyLengthInBytes);
  14266. }
  14267. }
  14268. var encryptionKey = hash.subarray(0, keyLengthInBytes);
  14269. var cipher, checkData;
  14270. if (revision >= 3) {
  14271. for (i = 0; i < 32; ++i) {
  14272. hashData[i] = defaultPasswordBytes[i];
  14273. }
  14274. for (j = 0, n = fileId.length; j < n; ++j) {
  14275. hashData[i++] = fileId[j];
  14276. }
  14277. cipher = new ARCFourCipher(encryptionKey);
  14278. checkData = cipher.encryptBlock(calculateMD5(hashData, 0, i));
  14279. n = encryptionKey.length;
  14280. var derivedKey = new Uint8Array(n), k;
  14281. for (j = 1; j <= 19; ++j) {
  14282. for (k = 0; k < n; ++k) {
  14283. derivedKey[k] = encryptionKey[k] ^ j;
  14284. }
  14285. cipher = new ARCFourCipher(derivedKey);
  14286. checkData = cipher.encryptBlock(checkData);
  14287. }
  14288. for (j = 0, n = checkData.length; j < n; ++j) {
  14289. if (userPassword[j] !== checkData[j]) {
  14290. return null;
  14291. }
  14292. }
  14293. } else {
  14294. cipher = new ARCFourCipher(encryptionKey);
  14295. checkData = cipher.encryptBlock(defaultPasswordBytes);
  14296. for (j = 0, n = checkData.length; j < n; ++j) {
  14297. if (userPassword[j] !== checkData[j]) {
  14298. return null;
  14299. }
  14300. }
  14301. }
  14302. return encryptionKey;
  14303. }
  14304. function decodeUserPassword(password, ownerPassword, revision, keyLength) {
  14305. var hashData = new Uint8Array(32), i = 0, j, n;
  14306. n = Math.min(32, password.length);
  14307. for (; i < n; ++i) {
  14308. hashData[i] = password[i];
  14309. }
  14310. j = 0;
  14311. while (i < 32) {
  14312. hashData[i++] = defaultPasswordBytes[j++];
  14313. }
  14314. var hash = calculateMD5(hashData, 0, i);
  14315. var keyLengthInBytes = keyLength >> 3;
  14316. if (revision >= 3) {
  14317. for (j = 0; j < 50; ++j) {
  14318. hash = calculateMD5(hash, 0, hash.length);
  14319. }
  14320. }
  14321. var cipher, userPassword;
  14322. if (revision >= 3) {
  14323. userPassword = ownerPassword;
  14324. var derivedKey = new Uint8Array(keyLengthInBytes), k;
  14325. for (j = 19; j >= 0; j--) {
  14326. for (k = 0; k < keyLengthInBytes; ++k) {
  14327. derivedKey[k] = hash[k] ^ j;
  14328. }
  14329. cipher = new ARCFourCipher(derivedKey);
  14330. userPassword = cipher.encryptBlock(userPassword);
  14331. }
  14332. } else {
  14333. cipher = new ARCFourCipher(hash.subarray(0, keyLengthInBytes));
  14334. userPassword = cipher.encryptBlock(ownerPassword);
  14335. }
  14336. return userPassword;
  14337. }
  14338. var identityName = Name.get('Identity');
  14339. function CipherTransformFactory(dict, fileId, password) {
  14340. var filter = dict.get('Filter');
  14341. if (!isName(filter) || filter.name !== 'Standard') {
  14342. error('unknown encryption method');
  14343. }
  14344. this.dict = dict;
  14345. var algorithm = dict.get('V');
  14346. if (!isInt(algorithm) ||
  14347. (algorithm !== 1 && algorithm !== 2 && algorithm !== 4 &&
  14348. algorithm !== 5)) {
  14349. error('unsupported encryption algorithm');
  14350. }
  14351. this.algorithm = algorithm;
  14352. var keyLength = dict.get('Length') || 40;
  14353. if (!isInt(keyLength) ||
  14354. keyLength < 40 || (keyLength % 8) !== 0) {
  14355. error('invalid key length');
  14356. }
  14357. // prepare keys
  14358. var ownerPassword = stringToBytes(dict.get('O')).subarray(0, 32);
  14359. var userPassword = stringToBytes(dict.get('U')).subarray(0, 32);
  14360. var flags = dict.get('P');
  14361. var revision = dict.get('R');
  14362. // meaningful when V is 4 or 5
  14363. var encryptMetadata = ((algorithm === 4 || algorithm === 5) &&
  14364. dict.get('EncryptMetadata') !== false);
  14365. this.encryptMetadata = encryptMetadata;
  14366. var fileIdBytes = stringToBytes(fileId);
  14367. var passwordBytes;
  14368. if (password) {
  14369. passwordBytes = stringToBytes(password);
  14370. }
  14371. var encryptionKey;
  14372. if (algorithm !== 5) {
  14373. encryptionKey = prepareKeyData(fileIdBytes, passwordBytes,
  14374. ownerPassword, userPassword, flags,
  14375. revision, keyLength, encryptMetadata);
  14376. }
  14377. else {
  14378. var ownerValidationSalt = stringToBytes(dict.get('O')).subarray(32, 40);
  14379. var ownerKeySalt = stringToBytes(dict.get('O')).subarray(40, 48);
  14380. var uBytes = stringToBytes(dict.get('U')).subarray(0, 48);
  14381. var userValidationSalt = stringToBytes(dict.get('U')).subarray(32, 40);
  14382. var userKeySalt = stringToBytes(dict.get('U')).subarray(40, 48);
  14383. var ownerEncryption = stringToBytes(dict.get('OE'));
  14384. var userEncryption = stringToBytes(dict.get('UE'));
  14385. var perms = stringToBytes(dict.get('Perms'));
  14386. encryptionKey =
  14387. createEncryptionKey20(revision, passwordBytes,
  14388. ownerPassword, ownerValidationSalt,
  14389. ownerKeySalt, uBytes,
  14390. userPassword, userValidationSalt,
  14391. userKeySalt, ownerEncryption,
  14392. userEncryption, perms);
  14393. }
  14394. if (!encryptionKey && !password) {
  14395. throw new PasswordException('No password given',
  14396. PasswordResponses.NEED_PASSWORD);
  14397. } else if (!encryptionKey && password) {
  14398. // Attempting use the password as an owner password
  14399. var decodedPassword = decodeUserPassword(passwordBytes, ownerPassword,
  14400. revision, keyLength);
  14401. encryptionKey = prepareKeyData(fileIdBytes, decodedPassword,
  14402. ownerPassword, userPassword, flags,
  14403. revision, keyLength, encryptMetadata);
  14404. }
  14405. if (!encryptionKey) {
  14406. throw new PasswordException('Incorrect Password',
  14407. PasswordResponses.INCORRECT_PASSWORD);
  14408. }
  14409. this.encryptionKey = encryptionKey;
  14410. if (algorithm >= 4) {
  14411. this.cf = dict.get('CF');
  14412. this.stmf = dict.get('StmF') || identityName;
  14413. this.strf = dict.get('StrF') || identityName;
  14414. this.eff = dict.get('EFF') || this.stmf;
  14415. }
  14416. }
  14417. function buildObjectKey(num, gen, encryptionKey, isAes) {
  14418. var key = new Uint8Array(encryptionKey.length + 9), i, n;
  14419. for (i = 0, n = encryptionKey.length; i < n; ++i) {
  14420. key[i] = encryptionKey[i];
  14421. }
  14422. key[i++] = num & 0xFF;
  14423. key[i++] = (num >> 8) & 0xFF;
  14424. key[i++] = (num >> 16) & 0xFF;
  14425. key[i++] = gen & 0xFF;
  14426. key[i++] = (gen >> 8) & 0xFF;
  14427. if (isAes) {
  14428. key[i++] = 0x73;
  14429. key[i++] = 0x41;
  14430. key[i++] = 0x6C;
  14431. key[i++] = 0x54;
  14432. }
  14433. var hash = calculateMD5(key, 0, i);
  14434. return hash.subarray(0, Math.min(encryptionKey.length + 5, 16));
  14435. }
  14436. function buildCipherConstructor(cf, name, num, gen, key) {
  14437. var cryptFilter = cf.get(name.name);
  14438. var cfm;
  14439. if (cryptFilter !== null && cryptFilter !== undefined) {
  14440. cfm = cryptFilter.get('CFM');
  14441. }
  14442. if (!cfm || cfm.name === 'None') {
  14443. return function cipherTransformFactoryBuildCipherConstructorNone() {
  14444. return new NullCipher();
  14445. };
  14446. }
  14447. if ('V2' === cfm.name) {
  14448. return function cipherTransformFactoryBuildCipherConstructorV2() {
  14449. return new ARCFourCipher(buildObjectKey(num, gen, key, false));
  14450. };
  14451. }
  14452. if ('AESV2' === cfm.name) {
  14453. return function cipherTransformFactoryBuildCipherConstructorAESV2() {
  14454. return new AES128Cipher(buildObjectKey(num, gen, key, true));
  14455. };
  14456. }
  14457. if ('AESV3' === cfm.name) {
  14458. return function cipherTransformFactoryBuildCipherConstructorAESV3() {
  14459. return new AES256Cipher(key);
  14460. };
  14461. }
  14462. error('Unknown crypto method');
  14463. }
  14464. CipherTransformFactory.prototype = {
  14465. createCipherTransform:
  14466. function CipherTransformFactory_createCipherTransform(num, gen) {
  14467. if (this.algorithm === 4 || this.algorithm === 5) {
  14468. return new CipherTransform(
  14469. buildCipherConstructor(this.cf, this.stmf,
  14470. num, gen, this.encryptionKey),
  14471. buildCipherConstructor(this.cf, this.strf,
  14472. num, gen, this.encryptionKey));
  14473. }
  14474. // algorithms 1 and 2
  14475. var key = buildObjectKey(num, gen, this.encryptionKey, false);
  14476. var cipherConstructor = function buildCipherCipherConstructor() {
  14477. return new ARCFourCipher(key);
  14478. };
  14479. return new CipherTransform(cipherConstructor, cipherConstructor);
  14480. }
  14481. };
  14482. return CipherTransformFactory;
  14483. })();
  14484. var PatternType = {
  14485. FUNCTION_BASED: 1,
  14486. AXIAL: 2,
  14487. RADIAL: 3,
  14488. FREE_FORM_MESH: 4,
  14489. LATTICE_FORM_MESH: 5,
  14490. COONS_PATCH_MESH: 6,
  14491. TENSOR_PATCH_MESH: 7
  14492. };
  14493. var Pattern = (function PatternClosure() {
  14494. // Constructor should define this.getPattern
  14495. function Pattern() {
  14496. error('should not call Pattern constructor');
  14497. }
  14498. Pattern.prototype = {
  14499. // Input: current Canvas context
  14500. // Output: the appropriate fillStyle or strokeStyle
  14501. getPattern: function Pattern_getPattern(ctx) {
  14502. error('Should not call Pattern.getStyle: ' + ctx);
  14503. }
  14504. };
  14505. Pattern.parseShading = function Pattern_parseShading(shading, matrix, xref,
  14506. res) {
  14507. var dict = isStream(shading) ? shading.dict : shading;
  14508. var type = dict.get('ShadingType');
  14509. try {
  14510. switch (type) {
  14511. case PatternType.AXIAL:
  14512. case PatternType.RADIAL:
  14513. // Both radial and axial shadings are handled by RadialAxial shading.
  14514. return new Shadings.RadialAxial(dict, matrix, xref, res);
  14515. case PatternType.FREE_FORM_MESH:
  14516. case PatternType.LATTICE_FORM_MESH:
  14517. case PatternType.COONS_PATCH_MESH:
  14518. case PatternType.TENSOR_PATCH_MESH:
  14519. return new Shadings.Mesh(shading, matrix, xref, res);
  14520. default:
  14521. throw new Error('Unknown PatternType: ' + type);
  14522. }
  14523. } catch (ex) {
  14524. if (ex instanceof MissingDataException) {
  14525. throw ex;
  14526. }
  14527. UnsupportedManager.notify(UNSUPPORTED_FEATURES.shadingPattern);
  14528. warn(ex);
  14529. return new Shadings.Dummy();
  14530. }
  14531. };
  14532. return Pattern;
  14533. })();
  14534. var Shadings = {};
  14535. // A small number to offset the first/last color stops so we can insert ones to
  14536. // support extend. Number.MIN_VALUE appears to be too small and breaks the
  14537. // extend. 1e-7 works in FF but chrome seems to use an even smaller sized number
  14538. // internally so we have to go bigger.
  14539. Shadings.SMALL_NUMBER = 1e-2;
  14540. // Radial and axial shading have very similar implementations
  14541. // If needed, the implementations can be broken into two classes
  14542. Shadings.RadialAxial = (function RadialAxialClosure() {
  14543. function RadialAxial(dict, matrix, xref, res) {
  14544. this.matrix = matrix;
  14545. this.coordsArr = dict.get('Coords');
  14546. this.shadingType = dict.get('ShadingType');
  14547. this.type = 'Pattern';
  14548. var cs = dict.get('ColorSpace', 'CS');
  14549. cs = ColorSpace.parse(cs, xref, res);
  14550. this.cs = cs;
  14551. var t0 = 0.0, t1 = 1.0;
  14552. if (dict.has('Domain')) {
  14553. var domainArr = dict.get('Domain');
  14554. t0 = domainArr[0];
  14555. t1 = domainArr[1];
  14556. }
  14557. var extendStart = false, extendEnd = false;
  14558. if (dict.has('Extend')) {
  14559. var extendArr = dict.get('Extend');
  14560. extendStart = extendArr[0];
  14561. extendEnd = extendArr[1];
  14562. }
  14563. if (this.shadingType === PatternType.RADIAL &&
  14564. (!extendStart || !extendEnd)) {
  14565. // Radial gradient only currently works if either circle is fully within
  14566. // the other circle.
  14567. var x1 = this.coordsArr[0];
  14568. var y1 = this.coordsArr[1];
  14569. var r1 = this.coordsArr[2];
  14570. var x2 = this.coordsArr[3];
  14571. var y2 = this.coordsArr[4];
  14572. var r2 = this.coordsArr[5];
  14573. var distance = Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
  14574. if (r1 <= r2 + distance &&
  14575. r2 <= r1 + distance) {
  14576. warn('Unsupported radial gradient.');
  14577. }
  14578. }
  14579. this.extendStart = extendStart;
  14580. this.extendEnd = extendEnd;
  14581. var fnObj = dict.get('Function');
  14582. var fn = PDFFunction.parseArray(xref, fnObj);
  14583. // 10 samples seems good enough for now, but probably won't work
  14584. // if there are sharp color changes. Ideally, we would implement
  14585. // the spec faithfully and add lossless optimizations.
  14586. var diff = t1 - t0;
  14587. var step = diff / 10;
  14588. var colorStops = this.colorStops = [];
  14589. // Protect against bad domains so we don't end up in an infinte loop below.
  14590. if (t0 >= t1 || step <= 0) {
  14591. // Acrobat doesn't seem to handle these cases so we'll ignore for
  14592. // now.
  14593. info('Bad shading domain.');
  14594. return;
  14595. }
  14596. var color = new Float32Array(cs.numComps), ratio = new Float32Array(1);
  14597. var rgbColor;
  14598. for (var i = t0; i <= t1; i += step) {
  14599. ratio[0] = i;
  14600. fn(ratio, 0, color, 0);
  14601. rgbColor = cs.getRgb(color, 0);
  14602. var cssColor = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
  14603. colorStops.push([(i - t0) / diff, cssColor]);
  14604. }
  14605. var background = 'transparent';
  14606. if (dict.has('Background')) {
  14607. rgbColor = cs.getRgb(dict.get('Background'), 0);
  14608. background = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
  14609. }
  14610. if (!extendStart) {
  14611. // Insert a color stop at the front and offset the first real color stop
  14612. // so it doesn't conflict with the one we insert.
  14613. colorStops.unshift([0, background]);
  14614. colorStops[1][0] += Shadings.SMALL_NUMBER;
  14615. }
  14616. if (!extendEnd) {
  14617. // Same idea as above in extendStart but for the end.
  14618. colorStops[colorStops.length - 1][0] -= Shadings.SMALL_NUMBER;
  14619. colorStops.push([1, background]);
  14620. }
  14621. this.colorStops = colorStops;
  14622. }
  14623. RadialAxial.prototype = {
  14624. getIR: function RadialAxial_getIR() {
  14625. var coordsArr = this.coordsArr;
  14626. var shadingType = this.shadingType;
  14627. var type, p0, p1, r0, r1;
  14628. if (shadingType === PatternType.AXIAL) {
  14629. p0 = [coordsArr[0], coordsArr[1]];
  14630. p1 = [coordsArr[2], coordsArr[3]];
  14631. r0 = null;
  14632. r1 = null;
  14633. type = 'axial';
  14634. } else if (shadingType === PatternType.RADIAL) {
  14635. p0 = [coordsArr[0], coordsArr[1]];
  14636. p1 = [coordsArr[3], coordsArr[4]];
  14637. r0 = coordsArr[2];
  14638. r1 = coordsArr[5];
  14639. type = 'radial';
  14640. } else {
  14641. error('getPattern type unknown: ' + shadingType);
  14642. }
  14643. var matrix = this.matrix;
  14644. if (matrix) {
  14645. p0 = Util.applyTransform(p0, matrix);
  14646. p1 = Util.applyTransform(p1, matrix);
  14647. }
  14648. return ['RadialAxial', type, this.colorStops, p0, p1, r0, r1];
  14649. }
  14650. };
  14651. return RadialAxial;
  14652. })();
  14653. // All mesh shading. For now, they will be presented as set of the triangles
  14654. // to be drawn on the canvas and rgb color for each vertex.
  14655. Shadings.Mesh = (function MeshClosure() {
  14656. function MeshStreamReader(stream, context) {
  14657. this.stream = stream;
  14658. this.context = context;
  14659. this.buffer = 0;
  14660. this.bufferLength = 0;
  14661. var numComps = context.numComps;
  14662. this.tmpCompsBuf = new Float32Array(numComps);
  14663. var csNumComps = context.colorSpace;
  14664. this.tmpCsCompsBuf = context.colorFn ? new Float32Array(csNumComps) :
  14665. this.tmpCompsBuf;
  14666. }
  14667. MeshStreamReader.prototype = {
  14668. get hasData() {
  14669. if (this.stream.end) {
  14670. return this.stream.pos < this.stream.end;
  14671. }
  14672. if (this.bufferLength > 0) {
  14673. return true;
  14674. }
  14675. var nextByte = this.stream.getByte();
  14676. if (nextByte < 0) {
  14677. return false;
  14678. }
  14679. this.buffer = nextByte;
  14680. this.bufferLength = 8;
  14681. return true;
  14682. },
  14683. readBits: function MeshStreamReader_readBits(n) {
  14684. var buffer = this.buffer;
  14685. var bufferLength = this.bufferLength;
  14686. if (n === 32) {
  14687. if (bufferLength === 0) {
  14688. return ((this.stream.getByte() << 24) |
  14689. (this.stream.getByte() << 16) | (this.stream.getByte() << 8) |
  14690. this.stream.getByte()) >>> 0;
  14691. }
  14692. buffer = (buffer << 24) | (this.stream.getByte() << 16) |
  14693. (this.stream.getByte() << 8) | this.stream.getByte();
  14694. var nextByte = this.stream.getByte();
  14695. this.buffer = nextByte & ((1 << bufferLength) - 1);
  14696. return ((buffer << (8 - bufferLength)) |
  14697. ((nextByte & 0xFF) >> bufferLength)) >>> 0;
  14698. }
  14699. if (n === 8 && bufferLength === 0) {
  14700. return this.stream.getByte();
  14701. }
  14702. while (bufferLength < n) {
  14703. buffer = (buffer << 8) | this.stream.getByte();
  14704. bufferLength += 8;
  14705. }
  14706. bufferLength -= n;
  14707. this.bufferLength = bufferLength;
  14708. this.buffer = buffer & ((1 << bufferLength) - 1);
  14709. return buffer >> bufferLength;
  14710. },
  14711. align: function MeshStreamReader_align() {
  14712. this.buffer = 0;
  14713. this.bufferLength = 0;
  14714. },
  14715. readFlag: function MeshStreamReader_readFlag() {
  14716. return this.readBits(this.context.bitsPerFlag);
  14717. },
  14718. readCoordinate: function MeshStreamReader_readCoordinate() {
  14719. var bitsPerCoordinate = this.context.bitsPerCoordinate;
  14720. var xi = this.readBits(bitsPerCoordinate);
  14721. var yi = this.readBits(bitsPerCoordinate);
  14722. var decode = this.context.decode;
  14723. var scale = bitsPerCoordinate < 32 ? 1 / ((1 << bitsPerCoordinate) - 1) :
  14724. 2.3283064365386963e-10; // 2 ^ -32
  14725. return [
  14726. xi * scale * (decode[1] - decode[0]) + decode[0],
  14727. yi * scale * (decode[3] - decode[2]) + decode[2]
  14728. ];
  14729. },
  14730. readComponents: function MeshStreamReader_readComponents() {
  14731. var numComps = this.context.numComps;
  14732. var bitsPerComponent = this.context.bitsPerComponent;
  14733. var scale = bitsPerComponent < 32 ? 1 / ((1 << bitsPerComponent) - 1) :
  14734. 2.3283064365386963e-10; // 2 ^ -32
  14735. var decode = this.context.decode;
  14736. var components = this.tmpCompsBuf;
  14737. for (var i = 0, j = 4; i < numComps; i++, j += 2) {
  14738. var ci = this.readBits(bitsPerComponent);
  14739. components[i] = ci * scale * (decode[j + 1] - decode[j]) + decode[j];
  14740. }
  14741. var color = this.tmpCsCompsBuf;
  14742. if (this.context.colorFn) {
  14743. this.context.colorFn(components, 0, color, 0);
  14744. }
  14745. return this.context.colorSpace.getRgb(color, 0);
  14746. }
  14747. };
  14748. function decodeType4Shading(mesh, reader) {
  14749. var coords = mesh.coords;
  14750. var colors = mesh.colors;
  14751. var operators = [];
  14752. var ps = []; // not maintaining cs since that will match ps
  14753. var verticesLeft = 0; // assuming we have all data to start a new triangle
  14754. while (reader.hasData) {
  14755. var f = reader.readFlag();
  14756. var coord = reader.readCoordinate();
  14757. var color = reader.readComponents();
  14758. if (verticesLeft === 0) { // ignoring flags if we started a triangle
  14759. assert(0 <= f && f <= 2, 'Unknown type4 flag');
  14760. switch (f) {
  14761. case 0:
  14762. verticesLeft = 3;
  14763. break;
  14764. case 1:
  14765. ps.push(ps[ps.length - 2], ps[ps.length - 1]);
  14766. verticesLeft = 1;
  14767. break;
  14768. case 2:
  14769. ps.push(ps[ps.length - 3], ps[ps.length - 1]);
  14770. verticesLeft = 1;
  14771. break;
  14772. }
  14773. operators.push(f);
  14774. }
  14775. ps.push(coords.length);
  14776. coords.push(coord);
  14777. colors.push(color);
  14778. verticesLeft--;
  14779. reader.align();
  14780. }
  14781. var psPacked = new Int32Array(ps);
  14782. mesh.figures.push({
  14783. type: 'triangles',
  14784. coords: psPacked,
  14785. colors: psPacked
  14786. });
  14787. }
  14788. function decodeType5Shading(mesh, reader, verticesPerRow) {
  14789. var coords = mesh.coords;
  14790. var colors = mesh.colors;
  14791. var ps = []; // not maintaining cs since that will match ps
  14792. while (reader.hasData) {
  14793. var coord = reader.readCoordinate();
  14794. var color = reader.readComponents();
  14795. ps.push(coords.length);
  14796. coords.push(coord);
  14797. colors.push(color);
  14798. }
  14799. var psPacked = new Int32Array(ps);
  14800. mesh.figures.push({
  14801. type: 'lattice',
  14802. coords: psPacked,
  14803. colors: psPacked,
  14804. verticesPerRow: verticesPerRow
  14805. });
  14806. }
  14807. var MIN_SPLIT_PATCH_CHUNKS_AMOUNT = 3;
  14808. var MAX_SPLIT_PATCH_CHUNKS_AMOUNT = 20;
  14809. var TRIANGLE_DENSITY = 20; // count of triangles per entire mesh bounds
  14810. var getB = (function getBClosure() {
  14811. function buildB(count) {
  14812. var lut = [];
  14813. for (var i = 0; i <= count; i++) {
  14814. var t = i / count, t_ = 1 - t;
  14815. lut.push(new Float32Array([t_ * t_ * t_, 3 * t * t_ * t_,
  14816. 3 * t * t * t_, t * t * t]));
  14817. }
  14818. return lut;
  14819. }
  14820. var cache = [];
  14821. return function getB(count) {
  14822. if (!cache[count]) {
  14823. cache[count] = buildB(count);
  14824. }
  14825. return cache[count];
  14826. };
  14827. })();
  14828. function buildFigureFromPatch(mesh, index) {
  14829. var figure = mesh.figures[index];
  14830. assert(figure.type === 'patch', 'Unexpected patch mesh figure');
  14831. var coords = mesh.coords, colors = mesh.colors;
  14832. var pi = figure.coords;
  14833. var ci = figure.colors;
  14834. var figureMinX = Math.min(coords[pi[0]][0], coords[pi[3]][0],
  14835. coords[pi[12]][0], coords[pi[15]][0]);
  14836. var figureMinY = Math.min(coords[pi[0]][1], coords[pi[3]][1],
  14837. coords[pi[12]][1], coords[pi[15]][1]);
  14838. var figureMaxX = Math.max(coords[pi[0]][0], coords[pi[3]][0],
  14839. coords[pi[12]][0], coords[pi[15]][0]);
  14840. var figureMaxY = Math.max(coords[pi[0]][1], coords[pi[3]][1],
  14841. coords[pi[12]][1], coords[pi[15]][1]);
  14842. var splitXBy = Math.ceil((figureMaxX - figureMinX) * TRIANGLE_DENSITY /
  14843. (mesh.bounds[2] - mesh.bounds[0]));
  14844. splitXBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
  14845. Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitXBy));
  14846. var splitYBy = Math.ceil((figureMaxY - figureMinY) * TRIANGLE_DENSITY /
  14847. (mesh.bounds[3] - mesh.bounds[1]));
  14848. splitYBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
  14849. Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitYBy));
  14850. var verticesPerRow = splitXBy + 1;
  14851. var figureCoords = new Int32Array((splitYBy + 1) * verticesPerRow);
  14852. var figureColors = new Int32Array((splitYBy + 1) * verticesPerRow);
  14853. var k = 0;
  14854. var cl = new Uint8Array(3), cr = new Uint8Array(3);
  14855. var c0 = colors[ci[0]], c1 = colors[ci[1]],
  14856. c2 = colors[ci[2]], c3 = colors[ci[3]];
  14857. var bRow = getB(splitYBy), bCol = getB(splitXBy);
  14858. for (var row = 0; row <= splitYBy; row++) {
  14859. cl[0] = ((c0[0] * (splitYBy - row) + c2[0] * row) / splitYBy) | 0;
  14860. cl[1] = ((c0[1] * (splitYBy - row) + c2[1] * row) / splitYBy) | 0;
  14861. cl[2] = ((c0[2] * (splitYBy - row) + c2[2] * row) / splitYBy) | 0;
  14862. cr[0] = ((c1[0] * (splitYBy - row) + c3[0] * row) / splitYBy) | 0;
  14863. cr[1] = ((c1[1] * (splitYBy - row) + c3[1] * row) / splitYBy) | 0;
  14864. cr[2] = ((c1[2] * (splitYBy - row) + c3[2] * row) / splitYBy) | 0;
  14865. for (var col = 0; col <= splitXBy; col++, k++) {
  14866. if ((row === 0 || row === splitYBy) &&
  14867. (col === 0 || col === splitXBy)) {
  14868. continue;
  14869. }
  14870. var x = 0, y = 0;
  14871. var q = 0;
  14872. for (var i = 0; i <= 3; i++) {
  14873. for (var j = 0; j <= 3; j++, q++) {
  14874. var m = bRow[row][i] * bCol[col][j];
  14875. x += coords[pi[q]][0] * m;
  14876. y += coords[pi[q]][1] * m;
  14877. }
  14878. }
  14879. figureCoords[k] = coords.length;
  14880. coords.push([x, y]);
  14881. figureColors[k] = colors.length;
  14882. var newColor = new Uint8Array(3);
  14883. newColor[0] = ((cl[0] * (splitXBy - col) + cr[0] * col) / splitXBy) | 0;
  14884. newColor[1] = ((cl[1] * (splitXBy - col) + cr[1] * col) / splitXBy) | 0;
  14885. newColor[2] = ((cl[2] * (splitXBy - col) + cr[2] * col) / splitXBy) | 0;
  14886. colors.push(newColor);
  14887. }
  14888. }
  14889. figureCoords[0] = pi[0];
  14890. figureColors[0] = ci[0];
  14891. figureCoords[splitXBy] = pi[3];
  14892. figureColors[splitXBy] = ci[1];
  14893. figureCoords[verticesPerRow * splitYBy] = pi[12];
  14894. figureColors[verticesPerRow * splitYBy] = ci[2];
  14895. figureCoords[verticesPerRow * splitYBy + splitXBy] = pi[15];
  14896. figureColors[verticesPerRow * splitYBy + splitXBy] = ci[3];
  14897. mesh.figures[index] = {
  14898. type: 'lattice',
  14899. coords: figureCoords,
  14900. colors: figureColors,
  14901. verticesPerRow: verticesPerRow
  14902. };
  14903. }
  14904. function decodeType6Shading(mesh, reader) {
  14905. // A special case of Type 7. The p11, p12, p21, p22 automatically filled
  14906. var coords = mesh.coords;
  14907. var colors = mesh.colors;
  14908. var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
  14909. var cs = new Int32Array(4); // c00, c30, c03, c33
  14910. while (reader.hasData) {
  14911. var f = reader.readFlag();
  14912. assert(0 <= f && f <= 3, 'Unknown type6 flag');
  14913. var i, ii;
  14914. var pi = coords.length;
  14915. for (i = 0, ii = (f !== 0 ? 8 : 12); i < ii; i++) {
  14916. coords.push(reader.readCoordinate());
  14917. }
  14918. var ci = colors.length;
  14919. for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
  14920. colors.push(reader.readComponents());
  14921. }
  14922. var tmp1, tmp2, tmp3, tmp4;
  14923. switch (f) {
  14924. case 0:
  14925. ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
  14926. ps[ 8] = pi + 2; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 7;
  14927. ps[ 4] = pi + 1; /* calculated below */ ps[ 7] = pi + 8;
  14928. ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
  14929. cs[2] = ci + 1; cs[3] = ci + 2;
  14930. cs[0] = ci; cs[1] = ci + 3;
  14931. break;
  14932. case 1:
  14933. tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
  14934. ps[12] = pi + 5; ps[13] = pi + 4; ps[14] = pi + 3; ps[15] = pi + 2;
  14935. ps[ 8] = pi + 6; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 1;
  14936. ps[ 4] = pi + 7; /* calculated below */ ps[ 7] = pi;
  14937. ps[ 0] = tmp1; ps[ 1] = tmp2; ps[ 2] = tmp3; ps[ 3] = tmp4;
  14938. tmp1 = cs[2]; tmp2 = cs[3];
  14939. cs[2] = ci + 1; cs[3] = ci;
  14940. cs[0] = tmp1; cs[1] = tmp2;
  14941. break;
  14942. case 2:
  14943. ps[12] = ps[15]; ps[13] = pi + 7; ps[14] = pi + 6; ps[15] = pi + 5;
  14944. ps[ 8] = ps[11]; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 4;
  14945. ps[ 4] = ps[7]; /* calculated below */ ps[ 7] = pi + 3;
  14946. ps[ 0] = ps[3]; ps[ 1] = pi; ps[ 2] = pi + 1; ps[ 3] = pi + 2;
  14947. cs[2] = cs[3]; cs[3] = ci + 1;
  14948. cs[0] = cs[1]; cs[1] = ci;
  14949. break;
  14950. case 3:
  14951. ps[12] = ps[0]; ps[13] = ps[1]; ps[14] = ps[2]; ps[15] = ps[3];
  14952. ps[ 8] = pi; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 7;
  14953. ps[ 4] = pi + 1; /* calculated below */ ps[ 7] = pi + 6;
  14954. ps[ 0] = pi + 2; ps[ 1] = pi + 3; ps[ 2] = pi + 4; ps[ 3] = pi + 5;
  14955. cs[2] = cs[0]; cs[3] = cs[1];
  14956. cs[0] = ci; cs[1] = ci + 1;
  14957. break;
  14958. }
  14959. // set p11, p12, p21, p22
  14960. ps[5] = coords.length;
  14961. coords.push([
  14962. (-4 * coords[ps[0]][0] - coords[ps[15]][0] +
  14963. 6 * (coords[ps[4]][0] + coords[ps[1]][0]) -
  14964. 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
  14965. 3 * (coords[ps[13]][0] + coords[ps[7]][0])) / 9,
  14966. (-4 * coords[ps[0]][1] - coords[ps[15]][1] +
  14967. 6 * (coords[ps[4]][1] + coords[ps[1]][1]) -
  14968. 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
  14969. 3 * (coords[ps[13]][1] + coords[ps[7]][1])) / 9
  14970. ]);
  14971. ps[6] = coords.length;
  14972. coords.push([
  14973. (-4 * coords[ps[3]][0] - coords[ps[12]][0] +
  14974. 6 * (coords[ps[2]][0] + coords[ps[7]][0]) -
  14975. 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
  14976. 3 * (coords[ps[4]][0] + coords[ps[14]][0])) / 9,
  14977. (-4 * coords[ps[3]][1] - coords[ps[12]][1] +
  14978. 6 * (coords[ps[2]][1] + coords[ps[7]][1]) -
  14979. 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
  14980. 3 * (coords[ps[4]][1] + coords[ps[14]][1])) / 9
  14981. ]);
  14982. ps[9] = coords.length;
  14983. coords.push([
  14984. (-4 * coords[ps[12]][0] - coords[ps[3]][0] +
  14985. 6 * (coords[ps[8]][0] + coords[ps[13]][0]) -
  14986. 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
  14987. 3 * (coords[ps[11]][0] + coords[ps[1]][0])) / 9,
  14988. (-4 * coords[ps[12]][1] - coords[ps[3]][1] +
  14989. 6 * (coords[ps[8]][1] + coords[ps[13]][1]) -
  14990. 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
  14991. 3 * (coords[ps[11]][1] + coords[ps[1]][1])) / 9
  14992. ]);
  14993. ps[10] = coords.length;
  14994. coords.push([
  14995. (-4 * coords[ps[15]][0] - coords[ps[0]][0] +
  14996. 6 * (coords[ps[11]][0] + coords[ps[14]][0]) -
  14997. 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
  14998. 3 * (coords[ps[2]][0] + coords[ps[8]][0])) / 9,
  14999. (-4 * coords[ps[15]][1] - coords[ps[0]][1] +
  15000. 6 * (coords[ps[11]][1] + coords[ps[14]][1]) -
  15001. 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
  15002. 3 * (coords[ps[2]][1] + coords[ps[8]][1])) / 9
  15003. ]);
  15004. mesh.figures.push({
  15005. type: 'patch',
  15006. coords: new Int32Array(ps), // making copies of ps and cs
  15007. colors: new Int32Array(cs)
  15008. });
  15009. }
  15010. }
  15011. function decodeType7Shading(mesh, reader) {
  15012. var coords = mesh.coords;
  15013. var colors = mesh.colors;
  15014. var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
  15015. var cs = new Int32Array(4); // c00, c30, c03, c33
  15016. while (reader.hasData) {
  15017. var f = reader.readFlag();
  15018. assert(0 <= f && f <= 3, 'Unknown type7 flag');
  15019. var i, ii;
  15020. var pi = coords.length;
  15021. for (i = 0, ii = (f !== 0 ? 12 : 16); i < ii; i++) {
  15022. coords.push(reader.readCoordinate());
  15023. }
  15024. var ci = colors.length;
  15025. for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
  15026. colors.push(reader.readComponents());
  15027. }
  15028. var tmp1, tmp2, tmp3, tmp4;
  15029. switch (f) {
  15030. case 0:
  15031. ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
  15032. ps[ 8] = pi + 2; ps[ 9] = pi + 13; ps[10] = pi + 14; ps[11] = pi + 7;
  15033. ps[ 4] = pi + 1; ps[ 5] = pi + 12; ps[ 6] = pi + 15; ps[ 7] = pi + 8;
  15034. ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
  15035. cs[2] = ci + 1; cs[3] = ci + 2;
  15036. cs[0] = ci; cs[1] = ci + 3;
  15037. break;
  15038. case 1:
  15039. tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
  15040. ps[12] = pi + 5; ps[13] = pi + 4; ps[14] = pi + 3; ps[15] = pi + 2;
  15041. ps[ 8] = pi + 6; ps[ 9] = pi + 11; ps[10] = pi + 10; ps[11] = pi + 1;
  15042. ps[ 4] = pi + 7; ps[ 5] = pi + 8; ps[ 6] = pi + 9; ps[ 7] = pi;
  15043. ps[ 0] = tmp1; ps[ 1] = tmp2; ps[ 2] = tmp3; ps[ 3] = tmp4;
  15044. tmp1 = cs[2]; tmp2 = cs[3];
  15045. cs[2] = ci + 1; cs[3] = ci;
  15046. cs[0] = tmp1; cs[1] = tmp2;
  15047. break;
  15048. case 2:
  15049. ps[12] = ps[15]; ps[13] = pi + 7; ps[14] = pi + 6; ps[15] = pi + 5;
  15050. ps[ 8] = ps[11]; ps[ 9] = pi + 8; ps[10] = pi + 11; ps[11] = pi + 4;
  15051. ps[ 4] = ps[7]; ps[ 5] = pi + 9; ps[ 6] = pi + 10; ps[ 7] = pi + 3;
  15052. ps[ 0] = ps[3]; ps[ 1] = pi; ps[ 2] = pi + 1; ps[ 3] = pi + 2;
  15053. cs[2] = cs[3]; cs[3] = ci + 1;
  15054. cs[0] = cs[1]; cs[1] = ci;
  15055. break;
  15056. case 3:
  15057. ps[12] = ps[0]; ps[13] = ps[1]; ps[14] = ps[2]; ps[15] = ps[3];
  15058. ps[ 8] = pi; ps[ 9] = pi + 9; ps[10] = pi + 8; ps[11] = pi + 7;
  15059. ps[ 4] = pi + 1; ps[ 5] = pi + 10; ps[ 6] = pi + 11; ps[ 7] = pi + 6;
  15060. ps[ 0] = pi + 2; ps[ 1] = pi + 3; ps[ 2] = pi + 4; ps[ 3] = pi + 5;
  15061. cs[2] = cs[0]; cs[3] = cs[1];
  15062. cs[0] = ci; cs[1] = ci + 1;
  15063. break;
  15064. }
  15065. mesh.figures.push({
  15066. type: 'patch',
  15067. coords: new Int32Array(ps), // making copies of ps and cs
  15068. colors: new Int32Array(cs)
  15069. });
  15070. }
  15071. }
  15072. function updateBounds(mesh) {
  15073. var minX = mesh.coords[0][0], minY = mesh.coords[0][1],
  15074. maxX = minX, maxY = minY;
  15075. for (var i = 1, ii = mesh.coords.length; i < ii; i++) {
  15076. var x = mesh.coords[i][0], y = mesh.coords[i][1];
  15077. minX = minX > x ? x : minX;
  15078. minY = minY > y ? y : minY;
  15079. maxX = maxX < x ? x : maxX;
  15080. maxY = maxY < y ? y : maxY;
  15081. }
  15082. mesh.bounds = [minX, minY, maxX, maxY];
  15083. }
  15084. function packData(mesh) {
  15085. var i, ii, j, jj;
  15086. var coords = mesh.coords;
  15087. var coordsPacked = new Float32Array(coords.length * 2);
  15088. for (i = 0, j = 0, ii = coords.length; i < ii; i++) {
  15089. var xy = coords[i];
  15090. coordsPacked[j++] = xy[0];
  15091. coordsPacked[j++] = xy[1];
  15092. }
  15093. mesh.coords = coordsPacked;
  15094. var colors = mesh.colors;
  15095. var colorsPacked = new Uint8Array(colors.length * 3);
  15096. for (i = 0, j = 0, ii = colors.length; i < ii; i++) {
  15097. var c = colors[i];
  15098. colorsPacked[j++] = c[0];
  15099. colorsPacked[j++] = c[1];
  15100. colorsPacked[j++] = c[2];
  15101. }
  15102. mesh.colors = colorsPacked;
  15103. var figures = mesh.figures;
  15104. for (i = 0, ii = figures.length; i < ii; i++) {
  15105. var figure = figures[i], ps = figure.coords, cs = figure.colors;
  15106. for (j = 0, jj = ps.length; j < jj; j++) {
  15107. ps[j] *= 2;
  15108. cs[j] *= 3;
  15109. }
  15110. }
  15111. }
  15112. function Mesh(stream, matrix, xref, res) {
  15113. assert(isStream(stream), 'Mesh data is not a stream');
  15114. var dict = stream.dict;
  15115. this.matrix = matrix;
  15116. this.shadingType = dict.get('ShadingType');
  15117. this.type = 'Pattern';
  15118. this.bbox = dict.get('BBox');
  15119. var cs = dict.get('ColorSpace', 'CS');
  15120. cs = ColorSpace.parse(cs, xref, res);
  15121. this.cs = cs;
  15122. this.background = dict.has('Background') ?
  15123. cs.getRgb(dict.get('Background'), 0) : null;
  15124. var fnObj = dict.get('Function');
  15125. var fn = fnObj ? PDFFunction.parseArray(xref, fnObj) : null;
  15126. this.coords = [];
  15127. this.colors = [];
  15128. this.figures = [];
  15129. var decodeContext = {
  15130. bitsPerCoordinate: dict.get('BitsPerCoordinate'),
  15131. bitsPerComponent: dict.get('BitsPerComponent'),
  15132. bitsPerFlag: dict.get('BitsPerFlag'),
  15133. decode: dict.get('Decode'),
  15134. colorFn: fn,
  15135. colorSpace: cs,
  15136. numComps: fn ? 1 : cs.numComps
  15137. };
  15138. var reader = new MeshStreamReader(stream, decodeContext);
  15139. var patchMesh = false;
  15140. switch (this.shadingType) {
  15141. case PatternType.FREE_FORM_MESH:
  15142. decodeType4Shading(this, reader);
  15143. break;
  15144. case PatternType.LATTICE_FORM_MESH:
  15145. var verticesPerRow = dict.get('VerticesPerRow') | 0;
  15146. assert(verticesPerRow >= 2, 'Invalid VerticesPerRow');
  15147. decodeType5Shading(this, reader, verticesPerRow);
  15148. break;
  15149. case PatternType.COONS_PATCH_MESH:
  15150. decodeType6Shading(this, reader);
  15151. patchMesh = true;
  15152. break;
  15153. case PatternType.TENSOR_PATCH_MESH:
  15154. decodeType7Shading(this, reader);
  15155. patchMesh = true;
  15156. break;
  15157. default:
  15158. error('Unsupported mesh type.');
  15159. break;
  15160. }
  15161. if (patchMesh) {
  15162. // dirty bounds calculation for determining, how dense shall be triangles
  15163. updateBounds(this);
  15164. for (var i = 0, ii = this.figures.length; i < ii; i++) {
  15165. buildFigureFromPatch(this, i);
  15166. }
  15167. }
  15168. // calculate bounds
  15169. updateBounds(this);
  15170. packData(this);
  15171. }
  15172. Mesh.prototype = {
  15173. getIR: function Mesh_getIR() {
  15174. return ['Mesh', this.shadingType, this.coords, this.colors, this.figures,
  15175. this.bounds, this.matrix, this.bbox, this.background];
  15176. }
  15177. };
  15178. return Mesh;
  15179. })();
  15180. Shadings.Dummy = (function DummyClosure() {
  15181. function Dummy() {
  15182. this.type = 'Pattern';
  15183. }
  15184. Dummy.prototype = {
  15185. getIR: function Dummy_getIR() {
  15186. return ['Dummy'];
  15187. }
  15188. };
  15189. return Dummy;
  15190. })();
  15191. function getTilingPatternIR(operatorList, dict, args) {
  15192. var matrix = dict.get('Matrix');
  15193. var bbox = dict.get('BBox');
  15194. var xstep = dict.get('XStep');
  15195. var ystep = dict.get('YStep');
  15196. var paintType = dict.get('PaintType');
  15197. var tilingType = dict.get('TilingType');
  15198. return [
  15199. 'TilingPattern', args, operatorList, matrix, bbox, xstep, ystep,
  15200. paintType, tilingType
  15201. ];
  15202. }
  15203. var PartialEvaluator = (function PartialEvaluatorClosure() {
  15204. function PartialEvaluator(pdfManager, xref, handler, pageIndex,
  15205. uniquePrefix, idCounters, fontCache) {
  15206. this.pdfManager = pdfManager;
  15207. this.xref = xref;
  15208. this.handler = handler;
  15209. this.pageIndex = pageIndex;
  15210. this.uniquePrefix = uniquePrefix;
  15211. this.idCounters = idCounters;
  15212. this.fontCache = fontCache;
  15213. }
  15214. // Trying to minimize Date.now() usage and check every 100 time
  15215. var TIME_SLOT_DURATION_MS = 20;
  15216. var CHECK_TIME_EVERY = 100;
  15217. function TimeSlotManager() {
  15218. this.reset();
  15219. }
  15220. TimeSlotManager.prototype = {
  15221. check: function TimeSlotManager_check() {
  15222. if (++this.checked < CHECK_TIME_EVERY) {
  15223. return false;
  15224. }
  15225. this.checked = 0;
  15226. return this.endTime <= Date.now();
  15227. },
  15228. reset: function TimeSlotManager_reset() {
  15229. this.endTime = Date.now() + TIME_SLOT_DURATION_MS;
  15230. this.checked = 0;
  15231. }
  15232. };
  15233. var deferred = Promise.resolve();
  15234. var TILING_PATTERN = 1, SHADING_PATTERN = 2;
  15235. PartialEvaluator.prototype = {
  15236. hasBlendModes: function PartialEvaluator_hasBlendModes(resources) {
  15237. if (!isDict(resources)) {
  15238. return false;
  15239. }
  15240. var processed = Object.create(null);
  15241. if (resources.objId) {
  15242. processed[resources.objId] = true;
  15243. }
  15244. var nodes = [resources];
  15245. while (nodes.length) {
  15246. var key;
  15247. var node = nodes.shift();
  15248. // First check the current resources for blend modes.
  15249. var graphicStates = node.get('ExtGState');
  15250. if (isDict(graphicStates)) {
  15251. graphicStates = graphicStates.getAll();
  15252. for (key in graphicStates) {
  15253. var graphicState = graphicStates[key];
  15254. var bm = graphicState['BM'];
  15255. if (isName(bm) && bm.name !== 'Normal') {
  15256. return true;
  15257. }
  15258. }
  15259. }
  15260. // Descend into the XObjects to look for more resources and blend modes.
  15261. var xObjects = node.get('XObject');
  15262. if (!isDict(xObjects)) {
  15263. continue;
  15264. }
  15265. xObjects = xObjects.getAll();
  15266. for (key in xObjects) {
  15267. var xObject = xObjects[key];
  15268. if (!isStream(xObject)) {
  15269. continue;
  15270. }
  15271. if (xObject.dict.objId) {
  15272. if (processed[xObject.dict.objId]) {
  15273. // stream has objId and is processed already
  15274. continue;
  15275. }
  15276. processed[xObject.dict.objId] = true;
  15277. }
  15278. var xResources = xObject.dict.get('Resources');
  15279. // Checking objId to detect an infinite loop.
  15280. if (isDict(xResources) &&
  15281. (!xResources.objId || !processed[xResources.objId])) {
  15282. nodes.push(xResources);
  15283. if (xResources.objId) {
  15284. processed[xResources.objId] = true;
  15285. }
  15286. }
  15287. }
  15288. }
  15289. return false;
  15290. },
  15291. buildFormXObject: function PartialEvaluator_buildFormXObject(resources,
  15292. xobj, smask,
  15293. operatorList,
  15294. initialState) {
  15295. var matrix = xobj.dict.get('Matrix');
  15296. var bbox = xobj.dict.get('BBox');
  15297. var group = xobj.dict.get('Group');
  15298. if (group) {
  15299. var groupOptions = {
  15300. matrix: matrix,
  15301. bbox: bbox,
  15302. smask: smask,
  15303. isolated: false,
  15304. knockout: false
  15305. };
  15306. var groupSubtype = group.get('S');
  15307. var colorSpace;
  15308. if (isName(groupSubtype) && groupSubtype.name === 'Transparency') {
  15309. groupOptions.isolated = (group.get('I') || false);
  15310. groupOptions.knockout = (group.get('K') || false);
  15311. colorSpace = (group.has('CS') ?
  15312. ColorSpace.parse(group.get('CS'), this.xref, resources) : null);
  15313. }
  15314. if (smask && smask.backdrop) {
  15315. colorSpace = colorSpace || ColorSpace.singletons.rgb;
  15316. smask.backdrop = colorSpace.getRgb(smask.backdrop, 0);
  15317. }
  15318. operatorList.addOp(OPS.beginGroup, [groupOptions]);
  15319. }
  15320. operatorList.addOp(OPS.paintFormXObjectBegin, [matrix, bbox]);
  15321. return this.getOperatorList(xobj,
  15322. (xobj.dict.get('Resources') || resources), operatorList, initialState).
  15323. then(function () {
  15324. operatorList.addOp(OPS.paintFormXObjectEnd, []);
  15325. if (group) {
  15326. operatorList.addOp(OPS.endGroup, [groupOptions]);
  15327. }
  15328. });
  15329. },
  15330. buildPaintImageXObject:
  15331. function PartialEvaluator_buildPaintImageXObject(resources, image,
  15332. inline, operatorList,
  15333. cacheKey, imageCache) {
  15334. var self = this;
  15335. var dict = image.dict;
  15336. var w = dict.get('Width', 'W');
  15337. var h = dict.get('Height', 'H');
  15338. if (!(w && isNum(w)) || !(h && isNum(h))) {
  15339. warn('Image dimensions are missing, or not numbers.');
  15340. return;
  15341. }
  15342. if (PDFJS.maxImageSize !== -1 && w * h > PDFJS.maxImageSize) {
  15343. warn('Image exceeded maximum allowed size and was removed.');
  15344. return;
  15345. }
  15346. var imageMask = (dict.get('ImageMask', 'IM') || false);
  15347. var imgData, args;
  15348. if (imageMask) {
  15349. // This depends on a tmpCanvas being filled with the
  15350. // current fillStyle, such that processing the pixel
  15351. // data can't be done here. Instead of creating a
  15352. // complete PDFImage, only read the information needed
  15353. // for later.
  15354. var width = dict.get('Width', 'W');
  15355. var height = dict.get('Height', 'H');
  15356. var bitStrideLength = (width + 7) >> 3;
  15357. var imgArray = image.getBytes(bitStrideLength * height);
  15358. var decode = dict.get('Decode', 'D');
  15359. var inverseDecode = (!!decode && decode[0] > 0);
  15360. imgData = PDFImage.createMask(imgArray, width, height,
  15361. image instanceof DecodeStream,
  15362. inverseDecode);
  15363. imgData.cached = true;
  15364. args = [imgData];
  15365. operatorList.addOp(OPS.paintImageMaskXObject, args);
  15366. if (cacheKey) {
  15367. imageCache[cacheKey] = {
  15368. fn: OPS.paintImageMaskXObject,
  15369. args: args
  15370. };
  15371. }
  15372. return;
  15373. }
  15374. var softMask = (dict.get('SMask', 'SM') || false);
  15375. var mask = (dict.get('Mask') || false);
  15376. var SMALL_IMAGE_DIMENSIONS = 200;
  15377. // Inlining small images into the queue as RGB data
  15378. if (inline && !softMask && !mask && !(image instanceof JpegStream) &&
  15379. (w + h) < SMALL_IMAGE_DIMENSIONS) {
  15380. var imageObj = new PDFImage(this.xref, resources, image,
  15381. inline, null, null);
  15382. // We force the use of RGBA_32BPP images here, because we can't handle
  15383. // any other kind.
  15384. imgData = imageObj.createImageData(/* forceRGBA = */ true);
  15385. operatorList.addOp(OPS.paintInlineImageXObject, [imgData]);
  15386. return;
  15387. }
  15388. // If there is no imageMask, create the PDFImage and a lot
  15389. // of image processing can be done here.
  15390. var uniquePrefix = (this.uniquePrefix || '');
  15391. var objId = 'img_' + uniquePrefix + (++this.idCounters.obj);
  15392. operatorList.addDependency(objId);
  15393. args = [objId, w, h];
  15394. if (!softMask && !mask && image instanceof JpegStream &&
  15395. image.isNativelySupported(this.xref, resources)) {
  15396. // These JPEGs don't need any more processing so we can just send it.
  15397. operatorList.addOp(OPS.paintJpegXObject, args);
  15398. this.handler.send('obj',
  15399. [objId, this.pageIndex, 'JpegStream', image.getIR()]);
  15400. return;
  15401. }
  15402. PDFImage.buildImage(self.handler, self.xref, resources, image, inline).
  15403. then(function(imageObj) {
  15404. var imgData = imageObj.createImageData(/* forceRGBA = */ false);
  15405. self.handler.send('obj', [objId, self.pageIndex, 'Image', imgData],
  15406. [imgData.data.buffer]);
  15407. }).then(undefined, function (reason) {
  15408. warn('Unable to decode image: ' + reason);
  15409. self.handler.send('obj', [objId, self.pageIndex, 'Image', null]);
  15410. });
  15411. operatorList.addOp(OPS.paintImageXObject, args);
  15412. if (cacheKey) {
  15413. imageCache[cacheKey] = {
  15414. fn: OPS.paintImageXObject,
  15415. args: args
  15416. };
  15417. }
  15418. },
  15419. handleSMask: function PartialEvaluator_handleSmask(smask, resources,
  15420. operatorList,
  15421. stateManager) {
  15422. var smaskContent = smask.get('G');
  15423. var smaskOptions = {
  15424. subtype: smask.get('S').name,
  15425. backdrop: smask.get('BC')
  15426. };
  15427. return this.buildFormXObject(resources, smaskContent, smaskOptions,
  15428. operatorList, stateManager.state.clone());
  15429. },
  15430. handleTilingType:
  15431. function PartialEvaluator_handleTilingType(fn, args, resources,
  15432. pattern, patternDict,
  15433. operatorList) {
  15434. // Create an IR of the pattern code.
  15435. var tilingOpList = new OperatorList();
  15436. return this.getOperatorList(pattern,
  15437. (patternDict.get('Resources') || resources), tilingOpList).
  15438. then(function () {
  15439. // Add the dependencies to the parent operator list so they are
  15440. // resolved before sub operator list is executed synchronously.
  15441. operatorList.addDependencies(tilingOpList.dependencies);
  15442. operatorList.addOp(fn, getTilingPatternIR({
  15443. fnArray: tilingOpList.fnArray,
  15444. argsArray: tilingOpList.argsArray
  15445. }, patternDict, args));
  15446. });
  15447. },
  15448. handleSetFont:
  15449. function PartialEvaluator_handleSetFont(resources, fontArgs, fontRef,
  15450. operatorList, state) {
  15451. // TODO(mack): Not needed?
  15452. var fontName;
  15453. if (fontArgs) {
  15454. fontArgs = fontArgs.slice();
  15455. fontName = fontArgs[0].name;
  15456. }
  15457. var self = this;
  15458. return this.loadFont(fontName, fontRef, this.xref, resources).then(
  15459. function (translated) {
  15460. if (!translated.font.isType3Font) {
  15461. return translated;
  15462. }
  15463. return translated.loadType3Data(self, resources, operatorList).then(
  15464. function () {
  15465. return translated;
  15466. });
  15467. }).then(function (translated) {
  15468. state.font = translated.font;
  15469. translated.send(self.handler);
  15470. return translated.loadedName;
  15471. });
  15472. },
  15473. handleText: function PartialEvaluator_handleText(chars, state) {
  15474. var font = state.font;
  15475. var glyphs = font.charsToGlyphs(chars);
  15476. var isAddToPathSet = !!(state.textRenderingMode &
  15477. TextRenderingMode.ADD_TO_PATH_FLAG);
  15478. if (font.data && (isAddToPathSet || PDFJS.disableFontFace)) {
  15479. var buildPath = function (fontChar) {
  15480. if (!font.renderer.hasBuiltPath(fontChar)) {
  15481. var path = font.renderer.getPathJs(fontChar);
  15482. this.handler.send('commonobj', [
  15483. font.loadedName + '_path_' + fontChar,
  15484. 'FontPath',
  15485. path
  15486. ]);
  15487. }
  15488. }.bind(this);
  15489. for (var i = 0, ii = glyphs.length; i < ii; i++) {
  15490. var glyph = glyphs[i];
  15491. if (glyph === null) {
  15492. continue;
  15493. }
  15494. buildPath(glyph.fontChar);
  15495. // If the glyph has an accent we need to build a path for its
  15496. // fontChar too, otherwise CanvasGraphics_paintChar will fail.
  15497. var accent = glyph.accent;
  15498. if (accent && accent.fontChar) {
  15499. buildPath(accent.fontChar);
  15500. }
  15501. }
  15502. }
  15503. return glyphs;
  15504. },
  15505. setGState: function PartialEvaluator_setGState(resources, gState,
  15506. operatorList, xref,
  15507. stateManager) {
  15508. // This array holds the converted/processed state data.
  15509. var gStateObj = [];
  15510. var gStateMap = gState.map;
  15511. var self = this;
  15512. var promise = Promise.resolve();
  15513. for (var key in gStateMap) {
  15514. var value = gStateMap[key];
  15515. switch (key) {
  15516. case 'Type':
  15517. break;
  15518. case 'LW':
  15519. case 'LC':
  15520. case 'LJ':
  15521. case 'ML':
  15522. case 'D':
  15523. case 'RI':
  15524. case 'FL':
  15525. case 'CA':
  15526. case 'ca':
  15527. gStateObj.push([key, value]);
  15528. break;
  15529. case 'Font':
  15530. promise = promise.then(function () {
  15531. return self.handleSetFont(resources, null, value[0],
  15532. operatorList, stateManager.state).
  15533. then(function (loadedName) {
  15534. operatorList.addDependency(loadedName);
  15535. gStateObj.push([key, [loadedName, value[1]]]);
  15536. });
  15537. });
  15538. break;
  15539. case 'BM':
  15540. gStateObj.push([key, value]);
  15541. break;
  15542. case 'SMask':
  15543. if (isName(value) && value.name === 'None') {
  15544. gStateObj.push([key, false]);
  15545. break;
  15546. }
  15547. var dict = xref.fetchIfRef(value);
  15548. if (isDict(dict)) {
  15549. promise = promise.then(function () {
  15550. return self.handleSMask(dict, resources, operatorList,
  15551. stateManager);
  15552. });
  15553. gStateObj.push([key, true]);
  15554. } else {
  15555. warn('Unsupported SMask type');
  15556. }
  15557. break;
  15558. // Only generate info log messages for the following since
  15559. // they are unlikely to have a big impact on the rendering.
  15560. case 'OP':
  15561. case 'op':
  15562. case 'OPM':
  15563. case 'BG':
  15564. case 'BG2':
  15565. case 'UCR':
  15566. case 'UCR2':
  15567. case 'TR':
  15568. case 'TR2':
  15569. case 'HT':
  15570. case 'SM':
  15571. case 'SA':
  15572. case 'AIS':
  15573. case 'TK':
  15574. // TODO implement these operators.
  15575. info('graphic state operator ' + key);
  15576. break;
  15577. default:
  15578. info('Unknown graphic state operator ' + key);
  15579. break;
  15580. }
  15581. }
  15582. return promise.then(function () {
  15583. if (gStateObj.length >= 0) {
  15584. operatorList.addOp(OPS.setGState, [gStateObj]);
  15585. }
  15586. });
  15587. },
  15588. loadFont: function PartialEvaluator_loadFont(fontName, font, xref,
  15589. resources) {
  15590. function errorFont() {
  15591. return Promise.resolve(new TranslatedFont('g_font_error',
  15592. new ErrorFont('Font ' + fontName + ' is not available'), font));
  15593. }
  15594. var fontRef;
  15595. if (font) { // Loading by ref.
  15596. assert(isRef(font));
  15597. fontRef = font;
  15598. } else { // Loading by name.
  15599. var fontRes = resources.get('Font');
  15600. if (fontRes) {
  15601. fontRef = fontRes.getRaw(fontName);
  15602. } else {
  15603. warn('fontRes not available');
  15604. return errorFont();
  15605. }
  15606. }
  15607. if (!fontRef) {
  15608. warn('fontRef not available');
  15609. return errorFont();
  15610. }
  15611. if (this.fontCache.has(fontRef)) {
  15612. return this.fontCache.get(fontRef);
  15613. }
  15614. font = xref.fetchIfRef(fontRef);
  15615. if (!isDict(font)) {
  15616. return errorFont();
  15617. }
  15618. // We are holding font.translated references just for fontRef that are not
  15619. // dictionaries (Dict). See explanation below.
  15620. if (font.translated) {
  15621. return font.translated;
  15622. }
  15623. var fontCapability = createPromiseCapability();
  15624. var preEvaluatedFont = this.preEvaluateFont(font, xref);
  15625. var descriptor = preEvaluatedFont.descriptor;
  15626. var fontID = fontRef.num + '_' + fontRef.gen;
  15627. if (isDict(descriptor)) {
  15628. if (!descriptor.fontAliases) {
  15629. descriptor.fontAliases = Object.create(null);
  15630. }
  15631. var fontAliases = descriptor.fontAliases;
  15632. var hash = preEvaluatedFont.hash;
  15633. if (fontAliases[hash]) {
  15634. var aliasFontRef = fontAliases[hash].aliasRef;
  15635. if (aliasFontRef && this.fontCache.has(aliasFontRef)) {
  15636. this.fontCache.putAlias(fontRef, aliasFontRef);
  15637. return this.fontCache.get(fontRef);
  15638. }
  15639. }
  15640. if (!fontAliases[hash]) {
  15641. fontAliases[hash] = {
  15642. fontID: Font.getFontID()
  15643. };
  15644. }
  15645. fontAliases[hash].aliasRef = fontRef;
  15646. fontID = fontAliases[hash].fontID;
  15647. }
  15648. // Workaround for bad PDF generators that don't reference fonts
  15649. // properly, i.e. by not using an object identifier.
  15650. // Check if the fontRef is a Dict (as opposed to a standard object),
  15651. // in which case we don't cache the font and instead reference it by
  15652. // fontName in font.loadedName below.
  15653. var fontRefIsDict = isDict(fontRef);
  15654. if (!fontRefIsDict) {
  15655. this.fontCache.put(fontRef, fontCapability.promise);
  15656. }
  15657. // Keep track of each font we translated so the caller can
  15658. // load them asynchronously before calling display on a page.
  15659. font.loadedName = 'g_font_' + (fontRefIsDict ?
  15660. fontName.replace(/\W/g, '') : fontID);
  15661. font.translated = fontCapability.promise;
  15662. // TODO move promises into translate font
  15663. var translatedPromise;
  15664. try {
  15665. translatedPromise = Promise.resolve(
  15666. this.translateFont(preEvaluatedFont, xref));
  15667. } catch (e) {
  15668. translatedPromise = Promise.reject(e);
  15669. }
  15670. translatedPromise.then(function (translatedFont) {
  15671. if (translatedFont.fontType !== undefined) {
  15672. var xrefFontStats = xref.stats.fontTypes;
  15673. xrefFontStats[translatedFont.fontType] = true;
  15674. }
  15675. fontCapability.resolve(new TranslatedFont(font.loadedName,
  15676. translatedFont, font));
  15677. }, function (reason) {
  15678. // TODO fontCapability.reject?
  15679. UnsupportedManager.notify(UNSUPPORTED_FEATURES.font);
  15680. try {
  15681. // error, but it's still nice to have font type reported
  15682. var descriptor = preEvaluatedFont.descriptor;
  15683. var fontFile3 = descriptor && descriptor.get('FontFile3');
  15684. var subtype = fontFile3 && fontFile3.get('Subtype');
  15685. var fontType = getFontType(preEvaluatedFont.type,
  15686. subtype && subtype.name);
  15687. var xrefFontStats = xref.stats.fontTypes;
  15688. xrefFontStats[fontType] = true;
  15689. } catch (ex) { }
  15690. fontCapability.resolve(new TranslatedFont(font.loadedName,
  15691. new ErrorFont(reason instanceof Error ? reason.message : reason),
  15692. font));
  15693. });
  15694. return fontCapability.promise;
  15695. },
  15696. buildPath: function PartialEvaluator_buildPath(operatorList, fn, args) {
  15697. var lastIndex = operatorList.length - 1;
  15698. if (!args) {
  15699. args = [];
  15700. }
  15701. if (lastIndex < 0 ||
  15702. operatorList.fnArray[lastIndex] !== OPS.constructPath) {
  15703. operatorList.addOp(OPS.constructPath, [[fn], args]);
  15704. } else {
  15705. var opArgs = operatorList.argsArray[lastIndex];
  15706. opArgs[0].push(fn);
  15707. Array.prototype.push.apply(opArgs[1], args);
  15708. }
  15709. },
  15710. handleColorN: function PartialEvaluator_handleColorN(operatorList, fn, args,
  15711. cs, patterns, resources, xref) {
  15712. // compile tiling patterns
  15713. var patternName = args[args.length - 1];
  15714. // SCN/scn applies patterns along with normal colors
  15715. var pattern;
  15716. if (isName(patternName) &&
  15717. (pattern = patterns.get(patternName.name))) {
  15718. var dict = (isStream(pattern) ? pattern.dict : pattern);
  15719. var typeNum = dict.get('PatternType');
  15720. if (typeNum === TILING_PATTERN) {
  15721. var color = cs.base ? cs.base.getRgb(args, 0) : null;
  15722. return this.handleTilingType(fn, color, resources, pattern,
  15723. dict, operatorList);
  15724. } else if (typeNum === SHADING_PATTERN) {
  15725. var shading = dict.get('Shading');
  15726. var matrix = dict.get('Matrix');
  15727. pattern = Pattern.parseShading(shading, matrix, xref, resources);
  15728. operatorList.addOp(fn, pattern.getIR());
  15729. return Promise.resolve();
  15730. } else {
  15731. return Promise.reject('Unknown PatternType: ' + typeNum);
  15732. }
  15733. }
  15734. // TODO shall we fail here?
  15735. operatorList.addOp(fn, args);
  15736. return Promise.resolve();
  15737. },
  15738. getOperatorList: function PartialEvaluator_getOperatorList(stream,
  15739. resources,
  15740. operatorList,
  15741. initialState) {
  15742. var self = this;
  15743. var xref = this.xref;
  15744. var imageCache = {};
  15745. assert(operatorList);
  15746. resources = (resources || Dict.empty);
  15747. var xobjs = (resources.get('XObject') || Dict.empty);
  15748. var patterns = (resources.get('Pattern') || Dict.empty);
  15749. var stateManager = new StateManager(initialState || new EvalState());
  15750. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  15751. var timeSlotManager = new TimeSlotManager();
  15752. return new Promise(function next(resolve, reject) {
  15753. timeSlotManager.reset();
  15754. var stop, operation = {}, i, ii, cs;
  15755. while (!(stop = timeSlotManager.check())) {
  15756. // The arguments parsed by read() are used beyond this loop, so we
  15757. // cannot reuse the same array on each iteration. Therefore we pass
  15758. // in |null| as the initial value (see the comment on
  15759. // EvaluatorPreprocessor_read() for why).
  15760. operation.args = null;
  15761. if (!(preprocessor.read(operation))) {
  15762. break;
  15763. }
  15764. var args = operation.args;
  15765. var fn = operation.fn;
  15766. switch (fn | 0) {
  15767. case OPS.paintXObject:
  15768. if (args[0].code) {
  15769. break;
  15770. }
  15771. // eagerly compile XForm objects
  15772. var name = args[0].name;
  15773. if (imageCache[name] !== undefined) {
  15774. operatorList.addOp(imageCache[name].fn, imageCache[name].args);
  15775. args = null;
  15776. continue;
  15777. }
  15778. var xobj = xobjs.get(name);
  15779. if (xobj) {
  15780. assert(isStream(xobj), 'XObject should be a stream');
  15781. var type = xobj.dict.get('Subtype');
  15782. assert(isName(type),
  15783. 'XObject should have a Name subtype');
  15784. if (type.name === 'Form') {
  15785. stateManager.save();
  15786. return self.buildFormXObject(resources, xobj, null,
  15787. operatorList,
  15788. stateManager.state.clone()).
  15789. then(function () {
  15790. stateManager.restore();
  15791. next(resolve, reject);
  15792. }, reject);
  15793. } else if (type.name === 'Image') {
  15794. self.buildPaintImageXObject(resources, xobj, false,
  15795. operatorList, name, imageCache);
  15796. args = null;
  15797. continue;
  15798. } else if (type.name === 'PS') {
  15799. // PostScript XObjects are unused when viewing documents.
  15800. // See section 4.7.1 of Adobe's PDF reference.
  15801. info('Ignored XObject subtype PS');
  15802. continue;
  15803. } else {
  15804. error('Unhandled XObject subtype ' + type.name);
  15805. }
  15806. }
  15807. break;
  15808. case OPS.setFont:
  15809. var fontSize = args[1];
  15810. // eagerly collect all fonts
  15811. return self.handleSetFont(resources, args, null,
  15812. operatorList, stateManager.state).
  15813. then(function (loadedName) {
  15814. operatorList.addDependency(loadedName);
  15815. operatorList.addOp(OPS.setFont, [loadedName, fontSize]);
  15816. next(resolve, reject);
  15817. }, reject);
  15818. case OPS.endInlineImage:
  15819. var cacheKey = args[0].cacheKey;
  15820. if (cacheKey) {
  15821. var cacheEntry = imageCache[cacheKey];
  15822. if (cacheEntry !== undefined) {
  15823. operatorList.addOp(cacheEntry.fn, cacheEntry.args);
  15824. args = null;
  15825. continue;
  15826. }
  15827. }
  15828. self.buildPaintImageXObject(resources, args[0], true,
  15829. operatorList, cacheKey, imageCache);
  15830. args = null;
  15831. continue;
  15832. case OPS.showText:
  15833. args[0] = self.handleText(args[0], stateManager.state);
  15834. break;
  15835. case OPS.showSpacedText:
  15836. var arr = args[0];
  15837. var combinedGlyphs = [];
  15838. var arrLength = arr.length;
  15839. for (i = 0; i < arrLength; ++i) {
  15840. var arrItem = arr[i];
  15841. if (isString(arrItem)) {
  15842. Array.prototype.push.apply(combinedGlyphs,
  15843. self.handleText(arrItem, stateManager.state));
  15844. } else if (isNum(arrItem)) {
  15845. combinedGlyphs.push(arrItem);
  15846. }
  15847. }
  15848. args[0] = combinedGlyphs;
  15849. fn = OPS.showText;
  15850. break;
  15851. case OPS.nextLineShowText:
  15852. operatorList.addOp(OPS.nextLine);
  15853. args[0] = self.handleText(args[0], stateManager.state);
  15854. fn = OPS.showText;
  15855. break;
  15856. case OPS.nextLineSetSpacingShowText:
  15857. operatorList.addOp(OPS.nextLine);
  15858. operatorList.addOp(OPS.setWordSpacing, [args.shift()]);
  15859. operatorList.addOp(OPS.setCharSpacing, [args.shift()]);
  15860. args[0] = self.handleText(args[0], stateManager.state);
  15861. fn = OPS.showText;
  15862. break;
  15863. case OPS.setTextRenderingMode:
  15864. stateManager.state.textRenderingMode = args[0];
  15865. break;
  15866. case OPS.setFillColorSpace:
  15867. stateManager.state.fillColorSpace =
  15868. ColorSpace.parse(args[0], xref, resources);
  15869. continue;
  15870. case OPS.setStrokeColorSpace:
  15871. stateManager.state.strokeColorSpace =
  15872. ColorSpace.parse(args[0], xref, resources);
  15873. continue;
  15874. case OPS.setFillColor:
  15875. cs = stateManager.state.fillColorSpace;
  15876. args = cs.getRgb(args, 0);
  15877. fn = OPS.setFillRGBColor;
  15878. break;
  15879. case OPS.setStrokeColor:
  15880. cs = stateManager.state.strokeColorSpace;
  15881. args = cs.getRgb(args, 0);
  15882. fn = OPS.setStrokeRGBColor;
  15883. break;
  15884. case OPS.setFillGray:
  15885. stateManager.state.fillColorSpace = ColorSpace.singletons.gray;
  15886. args = ColorSpace.singletons.gray.getRgb(args, 0);
  15887. fn = OPS.setFillRGBColor;
  15888. break;
  15889. case OPS.setStrokeGray:
  15890. stateManager.state.strokeColorSpace = ColorSpace.singletons.gray;
  15891. args = ColorSpace.singletons.gray.getRgb(args, 0);
  15892. fn = OPS.setStrokeRGBColor;
  15893. break;
  15894. case OPS.setFillCMYKColor:
  15895. stateManager.state.fillColorSpace = ColorSpace.singletons.cmyk;
  15896. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  15897. fn = OPS.setFillRGBColor;
  15898. break;
  15899. case OPS.setStrokeCMYKColor:
  15900. stateManager.state.strokeColorSpace = ColorSpace.singletons.cmyk;
  15901. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  15902. fn = OPS.setStrokeRGBColor;
  15903. break;
  15904. case OPS.setFillRGBColor:
  15905. stateManager.state.fillColorSpace = ColorSpace.singletons.rgb;
  15906. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  15907. break;
  15908. case OPS.setStrokeRGBColor:
  15909. stateManager.state.strokeColorSpace = ColorSpace.singletons.rgb;
  15910. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  15911. break;
  15912. case OPS.setFillColorN:
  15913. cs = stateManager.state.fillColorSpace;
  15914. if (cs.name === 'Pattern') {
  15915. return self.handleColorN(operatorList, OPS.setFillColorN,
  15916. args, cs, patterns, resources, xref).then(function() {
  15917. next(resolve, reject);
  15918. }, reject);
  15919. }
  15920. args = cs.getRgb(args, 0);
  15921. fn = OPS.setFillRGBColor;
  15922. break;
  15923. case OPS.setStrokeColorN:
  15924. cs = stateManager.state.strokeColorSpace;
  15925. if (cs.name === 'Pattern') {
  15926. return self.handleColorN(operatorList, OPS.setStrokeColorN,
  15927. args, cs, patterns, resources, xref).then(function() {
  15928. next(resolve, reject);
  15929. }, reject);
  15930. }
  15931. args = cs.getRgb(args, 0);
  15932. fn = OPS.setStrokeRGBColor;
  15933. break;
  15934. case OPS.shadingFill:
  15935. var shadingRes = resources.get('Shading');
  15936. if (!shadingRes) {
  15937. error('No shading resource found');
  15938. }
  15939. var shading = shadingRes.get(args[0].name);
  15940. if (!shading) {
  15941. error('No shading object found');
  15942. }
  15943. var shadingFill = Pattern.parseShading(shading, null, xref,
  15944. resources);
  15945. var patternIR = shadingFill.getIR();
  15946. args = [patternIR];
  15947. fn = OPS.shadingFill;
  15948. break;
  15949. case OPS.setGState:
  15950. var dictName = args[0];
  15951. var extGState = resources.get('ExtGState');
  15952. if (!isDict(extGState) || !extGState.has(dictName.name)) {
  15953. break;
  15954. }
  15955. var gState = extGState.get(dictName.name);
  15956. return self.setGState(resources, gState, operatorList, xref,
  15957. stateManager).then(function() {
  15958. next(resolve, reject);
  15959. }, reject);
  15960. case OPS.moveTo:
  15961. case OPS.lineTo:
  15962. case OPS.curveTo:
  15963. case OPS.curveTo2:
  15964. case OPS.curveTo3:
  15965. case OPS.closePath:
  15966. self.buildPath(operatorList, fn, args);
  15967. continue;
  15968. case OPS.rectangle:
  15969. self.buildPath(operatorList, fn, args);
  15970. continue;
  15971. }
  15972. operatorList.addOp(fn, args);
  15973. }
  15974. if (stop) {
  15975. deferred.then(function () {
  15976. next(resolve, reject);
  15977. });
  15978. return;
  15979. }
  15980. // Some PDFs don't close all restores inside object/form.
  15981. // Closing those for them.
  15982. for (i = 0, ii = preprocessor.savedStatesDepth; i < ii; i++) {
  15983. operatorList.addOp(OPS.restore, []);
  15984. }
  15985. resolve();
  15986. });
  15987. },
  15988. getTextContent: function PartialEvaluator_getTextContent(stream, resources,
  15989. stateManager) {
  15990. stateManager = (stateManager || new StateManager(new TextState()));
  15991. var textContent = {
  15992. items: [],
  15993. styles: Object.create(null)
  15994. };
  15995. var bidiTexts = textContent.items;
  15996. var SPACE_FACTOR = 0.3;
  15997. var MULTI_SPACE_FACTOR = 1.5;
  15998. var self = this;
  15999. var xref = this.xref;
  16000. resources = (xref.fetchIfRef(resources) || Dict.empty);
  16001. // The xobj is parsed iff it's needed, e.g. if there is a `DO` cmd.
  16002. var xobjs = null;
  16003. var xobjsCache = {};
  16004. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  16005. var textState;
  16006. function newTextChunk() {
  16007. var font = textState.font;
  16008. if (!(font.loadedName in textContent.styles)) {
  16009. textContent.styles[font.loadedName] = {
  16010. fontFamily: font.fallbackName,
  16011. ascent: font.ascent,
  16012. descent: font.descent,
  16013. vertical: font.vertical
  16014. };
  16015. }
  16016. return {
  16017. // |str| is initially an array which we push individual chars to, and
  16018. // then runBidi() overwrites it with the final string.
  16019. str: [],
  16020. dir: null,
  16021. width: 0,
  16022. height: 0,
  16023. transform: null,
  16024. fontName: font.loadedName
  16025. };
  16026. }
  16027. function runBidi(textChunk) {
  16028. var str = textChunk.str.join('');
  16029. var bidiResult = PDFJS.bidi(str, -1, textState.font.vertical);
  16030. textChunk.str = bidiResult.str;
  16031. textChunk.dir = bidiResult.dir;
  16032. return textChunk;
  16033. }
  16034. function handleSetFont(fontName, fontRef) {
  16035. return self.loadFont(fontName, fontRef, xref, resources).
  16036. then(function (translated) {
  16037. textState.font = translated.font;
  16038. textState.fontMatrix = translated.font.fontMatrix ||
  16039. FONT_IDENTITY_MATRIX;
  16040. });
  16041. }
  16042. function buildTextGeometry(chars, textChunk) {
  16043. var font = textState.font;
  16044. textChunk = textChunk || newTextChunk();
  16045. if (!textChunk.transform) {
  16046. // 9.4.4 Text Space Details
  16047. var tsm = [textState.fontSize * textState.textHScale, 0,
  16048. 0, textState.fontSize,
  16049. 0, textState.textRise];
  16050. if (font.isType3Font &&
  16051. textState.fontMatrix !== FONT_IDENTITY_MATRIX &&
  16052. textState.fontSize === 1) {
  16053. var glyphHeight = font.bbox[3] - font.bbox[1];
  16054. if (glyphHeight > 0) {
  16055. glyphHeight = glyphHeight * textState.fontMatrix[3];
  16056. tsm[3] *= glyphHeight;
  16057. }
  16058. }
  16059. var trm = textChunk.transform = Util.transform(textState.ctm,
  16060. Util.transform(textState.textMatrix, tsm));
  16061. if (!font.vertical) {
  16062. textChunk.height = Math.sqrt(trm[2] * trm[2] + trm[3] * trm[3]);
  16063. } else {
  16064. textChunk.width = Math.sqrt(trm[0] * trm[0] + trm[1] * trm[1]);
  16065. }
  16066. }
  16067. var width = 0;
  16068. var height = 0;
  16069. var glyphs = font.charsToGlyphs(chars);
  16070. var defaultVMetrics = font.defaultVMetrics;
  16071. for (var i = 0; i < glyphs.length; i++) {
  16072. var glyph = glyphs[i];
  16073. if (!glyph) { // Previous glyph was a space.
  16074. width += textState.wordSpacing * textState.textHScale;
  16075. continue;
  16076. }
  16077. var vMetricX = null;
  16078. var vMetricY = null;
  16079. var glyphWidth = null;
  16080. if (font.vertical) {
  16081. if (glyph.vmetric) {
  16082. glyphWidth = glyph.vmetric[0];
  16083. vMetricX = glyph.vmetric[1];
  16084. vMetricY = glyph.vmetric[2];
  16085. } else {
  16086. glyphWidth = glyph.width;
  16087. vMetricX = glyph.width * 0.5;
  16088. vMetricY = defaultVMetrics[2];
  16089. }
  16090. } else {
  16091. glyphWidth = glyph.width;
  16092. }
  16093. var glyphUnicode = glyph.unicode;
  16094. if (NormalizedUnicodes[glyphUnicode] !== undefined) {
  16095. glyphUnicode = NormalizedUnicodes[glyphUnicode];
  16096. }
  16097. glyphUnicode = reverseIfRtl(glyphUnicode);
  16098. // The following will calculate the x and y of the individual glyphs.
  16099. // if (font.vertical) {
  16100. // tsm[4] -= vMetricX * Math.abs(textState.fontSize) *
  16101. // textState.fontMatrix[0];
  16102. // tsm[5] -= vMetricY * textState.fontSize *
  16103. // textState.fontMatrix[0];
  16104. // }
  16105. // var trm = Util.transform(textState.textMatrix, tsm);
  16106. // var pt = Util.applyTransform([trm[4], trm[5]], textState.ctm);
  16107. // var x = pt[0];
  16108. // var y = pt[1];
  16109. var charSpacing = 0;
  16110. if (textChunk.str.length > 0) {
  16111. // Apply char spacing only when there are chars.
  16112. // As a result there is only spacing between glyphs.
  16113. charSpacing = textState.charSpacing;
  16114. }
  16115. var tx = 0;
  16116. var ty = 0;
  16117. if (!font.vertical) {
  16118. var w0 = glyphWidth * textState.fontMatrix[0];
  16119. tx = (w0 * textState.fontSize + charSpacing) *
  16120. textState.textHScale;
  16121. width += tx;
  16122. } else {
  16123. var w1 = glyphWidth * textState.fontMatrix[0];
  16124. ty = w1 * textState.fontSize + charSpacing;
  16125. height += ty;
  16126. }
  16127. textState.translateTextMatrix(tx, ty);
  16128. textChunk.str.push(glyphUnicode);
  16129. }
  16130. var a = textState.textLineMatrix[0];
  16131. var b = textState.textLineMatrix[1];
  16132. var scaleLineX = Math.sqrt(a * a + b * b);
  16133. a = textState.ctm[0];
  16134. b = textState.ctm[1];
  16135. var scaleCtmX = Math.sqrt(a * a + b * b);
  16136. if (!font.vertical) {
  16137. textChunk.width += width * scaleCtmX * scaleLineX;
  16138. } else {
  16139. textChunk.height += Math.abs(height * scaleCtmX * scaleLineX);
  16140. }
  16141. return textChunk;
  16142. }
  16143. var timeSlotManager = new TimeSlotManager();
  16144. return new Promise(function next(resolve, reject) {
  16145. timeSlotManager.reset();
  16146. var stop, operation = {}, args = [];
  16147. while (!(stop = timeSlotManager.check())) {
  16148. // The arguments parsed by read() are not used beyond this loop, so
  16149. // we can reuse the same array on every iteration, thus avoiding
  16150. // unnecessary allocations.
  16151. args.length = 0;
  16152. operation.args = args;
  16153. if (!(preprocessor.read(operation))) {
  16154. break;
  16155. }
  16156. textState = stateManager.state;
  16157. var fn = operation.fn;
  16158. args = operation.args;
  16159. switch (fn | 0) {
  16160. case OPS.setFont:
  16161. textState.fontSize = args[1];
  16162. return handleSetFont(args[0].name).then(function() {
  16163. next(resolve, reject);
  16164. }, reject);
  16165. case OPS.setTextRise:
  16166. textState.textRise = args[0];
  16167. break;
  16168. case OPS.setHScale:
  16169. textState.textHScale = args[0] / 100;
  16170. break;
  16171. case OPS.setLeading:
  16172. textState.leading = args[0];
  16173. break;
  16174. case OPS.moveText:
  16175. textState.translateTextLineMatrix(args[0], args[1]);
  16176. textState.textMatrix = textState.textLineMatrix.slice();
  16177. break;
  16178. case OPS.setLeadingMoveText:
  16179. textState.leading = -args[1];
  16180. textState.translateTextLineMatrix(args[0], args[1]);
  16181. textState.textMatrix = textState.textLineMatrix.slice();
  16182. break;
  16183. case OPS.nextLine:
  16184. textState.carriageReturn();
  16185. break;
  16186. case OPS.setTextMatrix:
  16187. textState.setTextMatrix(args[0], args[1], args[2], args[3],
  16188. args[4], args[5]);
  16189. textState.setTextLineMatrix(args[0], args[1], args[2], args[3],
  16190. args[4], args[5]);
  16191. break;
  16192. case OPS.setCharSpacing:
  16193. textState.charSpacing = args[0];
  16194. break;
  16195. case OPS.setWordSpacing:
  16196. textState.wordSpacing = args[0];
  16197. break;
  16198. case OPS.beginText:
  16199. textState.textMatrix = IDENTITY_MATRIX.slice();
  16200. textState.textLineMatrix = IDENTITY_MATRIX.slice();
  16201. break;
  16202. case OPS.showSpacedText:
  16203. var items = args[0];
  16204. var textChunk = newTextChunk();
  16205. var offset;
  16206. for (var j = 0, jj = items.length; j < jj; j++) {
  16207. if (typeof items[j] === 'string') {
  16208. buildTextGeometry(items[j], textChunk);
  16209. } else {
  16210. var val = items[j] / 1000;
  16211. if (!textState.font.vertical) {
  16212. offset = -val * textState.fontSize * textState.textHScale *
  16213. textState.textMatrix[0];
  16214. textState.translateTextMatrix(offset, 0);
  16215. textChunk.width += offset;
  16216. } else {
  16217. offset = -val * textState.fontSize *
  16218. textState.textMatrix[3];
  16219. textState.translateTextMatrix(0, offset);
  16220. textChunk.height += offset;
  16221. }
  16222. if (items[j] < 0 && textState.font.spaceWidth > 0) {
  16223. var fakeSpaces = -items[j] / textState.font.spaceWidth;
  16224. if (fakeSpaces > MULTI_SPACE_FACTOR) {
  16225. fakeSpaces = Math.round(fakeSpaces);
  16226. while (fakeSpaces--) {
  16227. textChunk.str.push(' ');
  16228. }
  16229. } else if (fakeSpaces > SPACE_FACTOR) {
  16230. textChunk.str.push(' ');
  16231. }
  16232. }
  16233. }
  16234. }
  16235. bidiTexts.push(runBidi(textChunk));
  16236. break;
  16237. case OPS.showText:
  16238. bidiTexts.push(runBidi(buildTextGeometry(args[0])));
  16239. break;
  16240. case OPS.nextLineShowText:
  16241. textState.carriageReturn();
  16242. bidiTexts.push(runBidi(buildTextGeometry(args[0])));
  16243. break;
  16244. case OPS.nextLineSetSpacingShowText:
  16245. textState.wordSpacing = args[0];
  16246. textState.charSpacing = args[1];
  16247. textState.carriageReturn();
  16248. bidiTexts.push(runBidi(buildTextGeometry(args[2])));
  16249. break;
  16250. case OPS.paintXObject:
  16251. if (args[0].code) {
  16252. break;
  16253. }
  16254. if (!xobjs) {
  16255. xobjs = (resources.get('XObject') || Dict.empty);
  16256. }
  16257. var name = args[0].name;
  16258. if (xobjsCache.key === name) {
  16259. if (xobjsCache.texts) {
  16260. Util.appendToArray(bidiTexts, xobjsCache.texts.items);
  16261. Util.extendObj(textContent.styles, xobjsCache.texts.styles);
  16262. }
  16263. break;
  16264. }
  16265. var xobj = xobjs.get(name);
  16266. if (!xobj) {
  16267. break;
  16268. }
  16269. assert(isStream(xobj), 'XObject should be a stream');
  16270. var type = xobj.dict.get('Subtype');
  16271. assert(isName(type),
  16272. 'XObject should have a Name subtype');
  16273. if ('Form' !== type.name) {
  16274. xobjsCache.key = name;
  16275. xobjsCache.texts = null;
  16276. break;
  16277. }
  16278. stateManager.save();
  16279. var matrix = xobj.dict.get('Matrix');
  16280. if (isArray(matrix) && matrix.length === 6) {
  16281. stateManager.transform(matrix);
  16282. }
  16283. return self.getTextContent(xobj,
  16284. xobj.dict.get('Resources') || resources, stateManager).
  16285. then(function (formTextContent) {
  16286. Util.appendToArray(bidiTexts, formTextContent.items);
  16287. Util.extendObj(textContent.styles, formTextContent.styles);
  16288. stateManager.restore();
  16289. xobjsCache.key = name;
  16290. xobjsCache.texts = formTextContent;
  16291. next(resolve, reject);
  16292. }, reject);
  16293. case OPS.setGState:
  16294. var dictName = args[0];
  16295. var extGState = resources.get('ExtGState');
  16296. if (!isDict(extGState) || !extGState.has(dictName.name)) {
  16297. break;
  16298. }
  16299. var gsStateMap = extGState.get(dictName.name);
  16300. var gsStateFont = null;
  16301. for (var key in gsStateMap) {
  16302. if (key === 'Font') {
  16303. assert(!gsStateFont);
  16304. gsStateFont = gsStateMap[key];
  16305. }
  16306. }
  16307. if (gsStateFont) {
  16308. textState.fontSize = gsStateFont[1];
  16309. return handleSetFont(gsStateFont[0]).then(function() {
  16310. next(resolve, reject);
  16311. }, reject);
  16312. }
  16313. break;
  16314. } // switch
  16315. } // while
  16316. if (stop) {
  16317. deferred.then(function () {
  16318. next(resolve, reject);
  16319. });
  16320. return;
  16321. }
  16322. resolve(textContent);
  16323. });
  16324. },
  16325. extractDataStructures: function
  16326. partialEvaluatorExtractDataStructures(dict, baseDict,
  16327. xref, properties) {
  16328. // 9.10.2
  16329. var toUnicode = (dict.get('ToUnicode') || baseDict.get('ToUnicode'));
  16330. if (toUnicode) {
  16331. properties.toUnicode = this.readToUnicode(toUnicode);
  16332. }
  16333. if (properties.composite) {
  16334. // CIDSystemInfo helps to match CID to glyphs
  16335. var cidSystemInfo = dict.get('CIDSystemInfo');
  16336. if (isDict(cidSystemInfo)) {
  16337. properties.cidSystemInfo = {
  16338. registry: cidSystemInfo.get('Registry'),
  16339. ordering: cidSystemInfo.get('Ordering'),
  16340. supplement: cidSystemInfo.get('Supplement')
  16341. };
  16342. }
  16343. var cidToGidMap = dict.get('CIDToGIDMap');
  16344. if (isStream(cidToGidMap)) {
  16345. properties.cidToGidMap = this.readCidToGidMap(cidToGidMap);
  16346. }
  16347. }
  16348. // Based on 9.6.6 of the spec the encoding can come from multiple places
  16349. // and depends on the font type. The base encoding and differences are
  16350. // read here, but the encoding that is actually used is chosen during
  16351. // glyph mapping in the font.
  16352. // TODO: Loading the built in encoding in the font would allow the
  16353. // differences to be merged in here not require us to hold on to it.
  16354. var differences = [];
  16355. var baseEncodingName = null;
  16356. var encoding;
  16357. if (dict.has('Encoding')) {
  16358. encoding = dict.get('Encoding');
  16359. if (isDict(encoding)) {
  16360. baseEncodingName = encoding.get('BaseEncoding');
  16361. baseEncodingName = (isName(baseEncodingName) ?
  16362. baseEncodingName.name : null);
  16363. // Load the differences between the base and original
  16364. if (encoding.has('Differences')) {
  16365. var diffEncoding = encoding.get('Differences');
  16366. var index = 0;
  16367. for (var j = 0, jj = diffEncoding.length; j < jj; j++) {
  16368. var data = diffEncoding[j];
  16369. if (isNum(data)) {
  16370. index = data;
  16371. } else if (isName(data)) {
  16372. differences[index++] = data.name;
  16373. } else if (isRef(data)) {
  16374. diffEncoding[j--] = xref.fetch(data);
  16375. continue;
  16376. } else {
  16377. error('Invalid entry in \'Differences\' array: ' + data);
  16378. }
  16379. }
  16380. }
  16381. } else if (isName(encoding)) {
  16382. baseEncodingName = encoding.name;
  16383. } else {
  16384. error('Encoding is not a Name nor a Dict');
  16385. }
  16386. // According to table 114 if the encoding is a named encoding it must be
  16387. // one of these predefined encodings.
  16388. if ((baseEncodingName !== 'MacRomanEncoding' &&
  16389. baseEncodingName !== 'MacExpertEncoding' &&
  16390. baseEncodingName !== 'WinAnsiEncoding')) {
  16391. baseEncodingName = null;
  16392. }
  16393. }
  16394. if (baseEncodingName) {
  16395. properties.defaultEncoding = Encodings[baseEncodingName].slice();
  16396. } else {
  16397. encoding = (properties.type === 'TrueType' ?
  16398. Encodings.WinAnsiEncoding : Encodings.StandardEncoding);
  16399. // The Symbolic attribute can be misused for regular fonts
  16400. // Heuristic: we have to check if the font is a standard one also
  16401. if (!!(properties.flags & FontFlags.Symbolic)) {
  16402. encoding = Encodings.MacRomanEncoding;
  16403. if (!properties.file) {
  16404. if (/Symbol/i.test(properties.name)) {
  16405. encoding = Encodings.SymbolSetEncoding;
  16406. } else if (/Dingbats/i.test(properties.name)) {
  16407. encoding = Encodings.ZapfDingbatsEncoding;
  16408. }
  16409. }
  16410. }
  16411. properties.defaultEncoding = encoding;
  16412. }
  16413. properties.differences = differences;
  16414. properties.baseEncodingName = baseEncodingName;
  16415. properties.dict = dict;
  16416. },
  16417. readToUnicode: function PartialEvaluator_readToUnicode(toUnicode) {
  16418. var cmap, cmapObj = toUnicode;
  16419. if (isName(cmapObj)) {
  16420. cmap = CMapFactory.create(cmapObj,
  16421. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  16422. if (cmap instanceof IdentityCMap) {
  16423. return new IdentityToUnicodeMap(0, 0xFFFF);
  16424. }
  16425. return new ToUnicodeMap(cmap.getMap());
  16426. } else if (isStream(cmapObj)) {
  16427. cmap = CMapFactory.create(cmapObj,
  16428. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  16429. if (cmap instanceof IdentityCMap) {
  16430. return new IdentityToUnicodeMap(0, 0xFFFF);
  16431. }
  16432. cmap = cmap.getMap();
  16433. // Convert UTF-16BE
  16434. // NOTE: cmap can be a sparse array, so use forEach instead of for(;;)
  16435. // to iterate over all keys.
  16436. cmap.forEach(function(token, i) {
  16437. var str = [];
  16438. for (var k = 0; k < token.length; k += 2) {
  16439. var w1 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
  16440. if ((w1 & 0xF800) !== 0xD800) { // w1 < 0xD800 || w1 > 0xDFFF
  16441. str.push(w1);
  16442. continue;
  16443. }
  16444. k += 2;
  16445. var w2 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
  16446. str.push(((w1 & 0x3ff) << 10) + (w2 & 0x3ff) + 0x10000);
  16447. }
  16448. cmap[i] = String.fromCharCode.apply(String, str);
  16449. });
  16450. return new ToUnicodeMap(cmap);
  16451. }
  16452. return null;
  16453. },
  16454. readCidToGidMap: function PartialEvaluator_readCidToGidMap(cidToGidStream) {
  16455. // Extract the encoding from the CIDToGIDMap
  16456. var glyphsData = cidToGidStream.getBytes();
  16457. // Set encoding 0 to later verify the font has an encoding
  16458. var result = [];
  16459. for (var j = 0, jj = glyphsData.length; j < jj; j++) {
  16460. var glyphID = (glyphsData[j++] << 8) | glyphsData[j];
  16461. if (glyphID === 0) {
  16462. continue;
  16463. }
  16464. var code = j >> 1;
  16465. result[code] = glyphID;
  16466. }
  16467. return result;
  16468. },
  16469. extractWidths: function PartialEvaluator_extractWidths(dict, xref,
  16470. descriptor,
  16471. properties) {
  16472. var glyphsWidths = [];
  16473. var defaultWidth = 0;
  16474. var glyphsVMetrics = [];
  16475. var defaultVMetrics;
  16476. var i, ii, j, jj, start, code, widths;
  16477. if (properties.composite) {
  16478. defaultWidth = dict.get('DW') || 1000;
  16479. widths = dict.get('W');
  16480. if (widths) {
  16481. for (i = 0, ii = widths.length; i < ii; i++) {
  16482. start = widths[i++];
  16483. code = xref.fetchIfRef(widths[i]);
  16484. if (isArray(code)) {
  16485. for (j = 0, jj = code.length; j < jj; j++) {
  16486. glyphsWidths[start++] = code[j];
  16487. }
  16488. } else {
  16489. var width = widths[++i];
  16490. for (j = start; j <= code; j++) {
  16491. glyphsWidths[j] = width;
  16492. }
  16493. }
  16494. }
  16495. }
  16496. if (properties.vertical) {
  16497. var vmetrics = (dict.get('DW2') || [880, -1000]);
  16498. defaultVMetrics = [vmetrics[1], defaultWidth * 0.5, vmetrics[0]];
  16499. vmetrics = dict.get('W2');
  16500. if (vmetrics) {
  16501. for (i = 0, ii = vmetrics.length; i < ii; i++) {
  16502. start = vmetrics[i++];
  16503. code = xref.fetchIfRef(vmetrics[i]);
  16504. if (isArray(code)) {
  16505. for (j = 0, jj = code.length; j < jj; j++) {
  16506. glyphsVMetrics[start++] = [code[j++], code[j++], code[j]];
  16507. }
  16508. } else {
  16509. var vmetric = [vmetrics[++i], vmetrics[++i], vmetrics[++i]];
  16510. for (j = start; j <= code; j++) {
  16511. glyphsVMetrics[j] = vmetric;
  16512. }
  16513. }
  16514. }
  16515. }
  16516. }
  16517. } else {
  16518. var firstChar = properties.firstChar;
  16519. widths = dict.get('Widths');
  16520. if (widths) {
  16521. j = firstChar;
  16522. for (i = 0, ii = widths.length; i < ii; i++) {
  16523. glyphsWidths[j++] = widths[i];
  16524. }
  16525. defaultWidth = (parseFloat(descriptor.get('MissingWidth')) || 0);
  16526. } else {
  16527. // Trying get the BaseFont metrics (see comment above).
  16528. var baseFontName = dict.get('BaseFont');
  16529. if (isName(baseFontName)) {
  16530. var metrics = this.getBaseFontMetrics(baseFontName.name);
  16531. glyphsWidths = this.buildCharCodeToWidth(metrics.widths,
  16532. properties);
  16533. defaultWidth = metrics.defaultWidth;
  16534. }
  16535. }
  16536. }
  16537. // Heuristic: detection of monospace font by checking all non-zero widths
  16538. var isMonospace = true;
  16539. var firstWidth = defaultWidth;
  16540. for (var glyph in glyphsWidths) {
  16541. var glyphWidth = glyphsWidths[glyph];
  16542. if (!glyphWidth) {
  16543. continue;
  16544. }
  16545. if (!firstWidth) {
  16546. firstWidth = glyphWidth;
  16547. continue;
  16548. }
  16549. if (firstWidth !== glyphWidth) {
  16550. isMonospace = false;
  16551. break;
  16552. }
  16553. }
  16554. if (isMonospace) {
  16555. properties.flags |= FontFlags.FixedPitch;
  16556. }
  16557. properties.defaultWidth = defaultWidth;
  16558. properties.widths = glyphsWidths;
  16559. properties.defaultVMetrics = defaultVMetrics;
  16560. properties.vmetrics = glyphsVMetrics;
  16561. },
  16562. isSerifFont: function PartialEvaluator_isSerifFont(baseFontName) {
  16563. // Simulating descriptor flags attribute
  16564. var fontNameWoStyle = baseFontName.split('-')[0];
  16565. return (fontNameWoStyle in serifFonts) ||
  16566. (fontNameWoStyle.search(/serif/gi) !== -1);
  16567. },
  16568. getBaseFontMetrics: function PartialEvaluator_getBaseFontMetrics(name) {
  16569. var defaultWidth = 0;
  16570. var widths = [];
  16571. var monospace = false;
  16572. var lookupName = (stdFontMap[name] || name);
  16573. if (!(lookupName in Metrics)) {
  16574. // Use default fonts for looking up font metrics if the passed
  16575. // font is not a base font
  16576. if (this.isSerifFont(name)) {
  16577. lookupName = 'Times-Roman';
  16578. } else {
  16579. lookupName = 'Helvetica';
  16580. }
  16581. }
  16582. var glyphWidths = Metrics[lookupName];
  16583. if (isNum(glyphWidths)) {
  16584. defaultWidth = glyphWidths;
  16585. monospace = true;
  16586. } else {
  16587. widths = glyphWidths;
  16588. }
  16589. return {
  16590. defaultWidth: defaultWidth,
  16591. monospace: monospace,
  16592. widths: widths
  16593. };
  16594. },
  16595. buildCharCodeToWidth:
  16596. function PartialEvaluator_bulildCharCodeToWidth(widthsByGlyphName,
  16597. properties) {
  16598. var widths = Object.create(null);
  16599. var differences = properties.differences;
  16600. var encoding = properties.defaultEncoding;
  16601. for (var charCode = 0; charCode < 256; charCode++) {
  16602. if (charCode in differences &&
  16603. widthsByGlyphName[differences[charCode]]) {
  16604. widths[charCode] = widthsByGlyphName[differences[charCode]];
  16605. continue;
  16606. }
  16607. if (charCode in encoding && widthsByGlyphName[encoding[charCode]]) {
  16608. widths[charCode] = widthsByGlyphName[encoding[charCode]];
  16609. continue;
  16610. }
  16611. }
  16612. return widths;
  16613. },
  16614. preEvaluateFont: function PartialEvaluator_preEvaluateFont(dict, xref) {
  16615. var baseDict = dict;
  16616. var type = dict.get('Subtype');
  16617. assert(isName(type), 'invalid font Subtype');
  16618. var composite = false;
  16619. var uint8array;
  16620. if (type.name === 'Type0') {
  16621. // If font is a composite
  16622. // - get the descendant font
  16623. // - set the type according to the descendant font
  16624. // - get the FontDescriptor from the descendant font
  16625. var df = dict.get('DescendantFonts');
  16626. if (!df) {
  16627. error('Descendant fonts are not specified');
  16628. }
  16629. dict = (isArray(df) ? xref.fetchIfRef(df[0]) : df);
  16630. type = dict.get('Subtype');
  16631. assert(isName(type), 'invalid font Subtype');
  16632. composite = true;
  16633. }
  16634. var descriptor = dict.get('FontDescriptor');
  16635. if (descriptor) {
  16636. var hash = new MurmurHash3_64();
  16637. var encoding = baseDict.getRaw('Encoding');
  16638. if (isName(encoding)) {
  16639. hash.update(encoding.name);
  16640. } else if (isRef(encoding)) {
  16641. hash.update(encoding.num + '_' + encoding.gen);
  16642. } else if (isDict(encoding)) {
  16643. var keys = encoding.getKeys();
  16644. for (var i = 0, ii = keys.length; i < ii; i++) {
  16645. var entry = encoding.getRaw(keys[i]);
  16646. if (isName(entry)) {
  16647. hash.update(entry.name);
  16648. } else if (isRef(entry)) {
  16649. hash.update(entry.num + '_' + entry.gen);
  16650. } else if (isArray(entry)) { // 'Differences' entry.
  16651. // Ideally we should check the contents of the array, but to avoid
  16652. // parsing it here and then again in |extractDataStructures|,
  16653. // we only use the array length for now (fixes bug1157493.pdf).
  16654. hash.update(entry.length.toString());
  16655. }
  16656. }
  16657. }
  16658. var toUnicode = dict.get('ToUnicode') || baseDict.get('ToUnicode');
  16659. if (isStream(toUnicode)) {
  16660. var stream = toUnicode.str || toUnicode;
  16661. uint8array = stream.buffer ?
  16662. new Uint8Array(stream.buffer.buffer, 0, stream.bufferLength) :
  16663. new Uint8Array(stream.bytes.buffer,
  16664. stream.start, stream.end - stream.start);
  16665. hash.update(uint8array);
  16666. } else if (isName(toUnicode)) {
  16667. hash.update(toUnicode.name);
  16668. }
  16669. var widths = dict.get('Widths') || baseDict.get('Widths');
  16670. if (widths) {
  16671. uint8array = new Uint8Array(new Uint32Array(widths).buffer);
  16672. hash.update(uint8array);
  16673. }
  16674. }
  16675. return {
  16676. descriptor: descriptor,
  16677. dict: dict,
  16678. baseDict: baseDict,
  16679. composite: composite,
  16680. type: type.name,
  16681. hash: hash ? hash.hexdigest() : ''
  16682. };
  16683. },
  16684. translateFont: function PartialEvaluator_translateFont(preEvaluatedFont,
  16685. xref) {
  16686. var baseDict = preEvaluatedFont.baseDict;
  16687. var dict = preEvaluatedFont.dict;
  16688. var composite = preEvaluatedFont.composite;
  16689. var descriptor = preEvaluatedFont.descriptor;
  16690. var type = preEvaluatedFont.type;
  16691. var maxCharIndex = (composite ? 0xFFFF : 0xFF);
  16692. var properties;
  16693. if (!descriptor) {
  16694. if (type === 'Type3') {
  16695. // FontDescriptor is only required for Type3 fonts when the document
  16696. // is a tagged pdf. Create a barbebones one to get by.
  16697. descriptor = new Dict(null);
  16698. descriptor.set('FontName', Name.get(type));
  16699. descriptor.set('FontBBox', dict.get('FontBBox'));
  16700. } else {
  16701. // Before PDF 1.5 if the font was one of the base 14 fonts, having a
  16702. // FontDescriptor was not required.
  16703. // This case is here for compatibility.
  16704. var baseFontName = dict.get('BaseFont');
  16705. if (!isName(baseFontName)) {
  16706. error('Base font is not specified');
  16707. }
  16708. // Using base font name as a font name.
  16709. baseFontName = baseFontName.name.replace(/[,_]/g, '-');
  16710. var metrics = this.getBaseFontMetrics(baseFontName);
  16711. // Simulating descriptor flags attribute
  16712. var fontNameWoStyle = baseFontName.split('-')[0];
  16713. var flags =
  16714. (this.isSerifFont(fontNameWoStyle) ? FontFlags.Serif : 0) |
  16715. (metrics.monospace ? FontFlags.FixedPitch : 0) |
  16716. (symbolsFonts[fontNameWoStyle] ? FontFlags.Symbolic :
  16717. FontFlags.Nonsymbolic);
  16718. properties = {
  16719. type: type,
  16720. name: baseFontName,
  16721. widths: metrics.widths,
  16722. defaultWidth: metrics.defaultWidth,
  16723. flags: flags,
  16724. firstChar: 0,
  16725. lastChar: maxCharIndex
  16726. };
  16727. this.extractDataStructures(dict, dict, xref, properties);
  16728. properties.widths = this.buildCharCodeToWidth(metrics.widths,
  16729. properties);
  16730. return new Font(baseFontName, null, properties);
  16731. }
  16732. }
  16733. // According to the spec if 'FontDescriptor' is declared, 'FirstChar',
  16734. // 'LastChar' and 'Widths' should exist too, but some PDF encoders seem
  16735. // to ignore this rule when a variant of a standart font is used.
  16736. // TODO Fill the width array depending on which of the base font this is
  16737. // a variant.
  16738. var firstChar = (dict.get('FirstChar') || 0);
  16739. var lastChar = (dict.get('LastChar') || maxCharIndex);
  16740. var fontName = descriptor.get('FontName');
  16741. var baseFont = dict.get('BaseFont');
  16742. // Some bad PDFs have a string as the font name.
  16743. if (isString(fontName)) {
  16744. fontName = Name.get(fontName);
  16745. }
  16746. if (isString(baseFont)) {
  16747. baseFont = Name.get(baseFont);
  16748. }
  16749. if (type !== 'Type3') {
  16750. var fontNameStr = fontName && fontName.name;
  16751. var baseFontStr = baseFont && baseFont.name;
  16752. if (fontNameStr !== baseFontStr) {
  16753. info('The FontDescriptor\'s FontName is "' + fontNameStr +
  16754. '" but should be the same as the Font\'s BaseFont "' +
  16755. baseFontStr + '"');
  16756. // Workaround for cases where e.g. fontNameStr = 'Arial' and
  16757. // baseFontStr = 'Arial,Bold' (needed when no font file is embedded).
  16758. if (fontNameStr && baseFontStr &&
  16759. baseFontStr.indexOf(fontNameStr) === 0) {
  16760. fontName = baseFont;
  16761. }
  16762. }
  16763. }
  16764. fontName = (fontName || baseFont);
  16765. assert(isName(fontName), 'invalid font name');
  16766. var fontFile = descriptor.get('FontFile', 'FontFile2', 'FontFile3');
  16767. if (fontFile) {
  16768. if (fontFile.dict) {
  16769. var subtype = fontFile.dict.get('Subtype');
  16770. if (subtype) {
  16771. subtype = subtype.name;
  16772. }
  16773. var length1 = fontFile.dict.get('Length1');
  16774. var length2 = fontFile.dict.get('Length2');
  16775. }
  16776. }
  16777. properties = {
  16778. type: type,
  16779. name: fontName.name,
  16780. subtype: subtype,
  16781. file: fontFile,
  16782. length1: length1,
  16783. length2: length2,
  16784. loadedName: baseDict.loadedName,
  16785. composite: composite,
  16786. wideChars: composite,
  16787. fixedPitch: false,
  16788. fontMatrix: (dict.get('FontMatrix') || FONT_IDENTITY_MATRIX),
  16789. firstChar: firstChar || 0,
  16790. lastChar: (lastChar || maxCharIndex),
  16791. bbox: descriptor.get('FontBBox'),
  16792. ascent: descriptor.get('Ascent'),
  16793. descent: descriptor.get('Descent'),
  16794. xHeight: descriptor.get('XHeight'),
  16795. capHeight: descriptor.get('CapHeight'),
  16796. flags: descriptor.get('Flags'),
  16797. italicAngle: descriptor.get('ItalicAngle'),
  16798. coded: false
  16799. };
  16800. if (composite) {
  16801. var cidEncoding = baseDict.get('Encoding');
  16802. if (isName(cidEncoding)) {
  16803. properties.cidEncoding = cidEncoding.name;
  16804. }
  16805. properties.cMap = CMapFactory.create(cidEncoding,
  16806. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  16807. properties.vertical = properties.cMap.vertical;
  16808. }
  16809. this.extractDataStructures(dict, baseDict, xref, properties);
  16810. this.extractWidths(dict, xref, descriptor, properties);
  16811. if (type === 'Type3') {
  16812. properties.isType3Font = true;
  16813. }
  16814. return new Font(fontName.name, fontFile, properties);
  16815. }
  16816. };
  16817. return PartialEvaluator;
  16818. })();
  16819. var TranslatedFont = (function TranslatedFontClosure() {
  16820. function TranslatedFont(loadedName, font, dict) {
  16821. this.loadedName = loadedName;
  16822. this.font = font;
  16823. this.dict = dict;
  16824. this.type3Loaded = null;
  16825. this.sent = false;
  16826. }
  16827. TranslatedFont.prototype = {
  16828. send: function (handler) {
  16829. if (this.sent) {
  16830. return;
  16831. }
  16832. var fontData = this.font.exportData();
  16833. handler.send('commonobj', [
  16834. this.loadedName,
  16835. 'Font',
  16836. fontData
  16837. ]);
  16838. this.sent = true;
  16839. },
  16840. loadType3Data: function (evaluator, resources, parentOperatorList) {
  16841. assert(this.font.isType3Font);
  16842. if (this.type3Loaded) {
  16843. return this.type3Loaded;
  16844. }
  16845. var translatedFont = this.font;
  16846. var loadCharProcsPromise = Promise.resolve();
  16847. var charProcs = this.dict.get('CharProcs').getAll();
  16848. var fontResources = this.dict.get('Resources') || resources;
  16849. var charProcKeys = Object.keys(charProcs);
  16850. var charProcOperatorList = {};
  16851. for (var i = 0, n = charProcKeys.length; i < n; ++i) {
  16852. loadCharProcsPromise = loadCharProcsPromise.then(function (key) {
  16853. var glyphStream = charProcs[key];
  16854. var operatorList = new OperatorList();
  16855. return evaluator.getOperatorList(glyphStream, fontResources,
  16856. operatorList).then(function () {
  16857. charProcOperatorList[key] = operatorList.getIR();
  16858. // Add the dependencies to the parent operator list so they are
  16859. // resolved before sub operator list is executed synchronously.
  16860. parentOperatorList.addDependencies(operatorList.dependencies);
  16861. }, function (reason) {
  16862. warn('Type3 font resource \"' + key + '\" is not available');
  16863. var operatorList = new OperatorList();
  16864. charProcOperatorList[key] = operatorList.getIR();
  16865. });
  16866. }.bind(this, charProcKeys[i]));
  16867. }
  16868. this.type3Loaded = loadCharProcsPromise.then(function () {
  16869. translatedFont.charProcOperatorList = charProcOperatorList;
  16870. });
  16871. return this.type3Loaded;
  16872. }
  16873. };
  16874. return TranslatedFont;
  16875. })();
  16876. var OperatorList = (function OperatorListClosure() {
  16877. var CHUNK_SIZE = 1000;
  16878. var CHUNK_SIZE_ABOUT = CHUNK_SIZE - 5; // close to chunk size
  16879. function getTransfers(queue) {
  16880. var transfers = [];
  16881. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  16882. for (var i = 0, ii = queue.length; i < ii; i++) {
  16883. switch (fnArray[i]) {
  16884. case OPS.paintInlineImageXObject:
  16885. case OPS.paintInlineImageXObjectGroup:
  16886. case OPS.paintImageMaskXObject:
  16887. var arg = argsArray[i][0]; // first param in imgData
  16888. if (!arg.cached) {
  16889. transfers.push(arg.data.buffer);
  16890. }
  16891. break;
  16892. }
  16893. }
  16894. return transfers;
  16895. }
  16896. function OperatorList(intent, messageHandler, pageIndex) {
  16897. this.messageHandler = messageHandler;
  16898. this.fnArray = [];
  16899. this.argsArray = [];
  16900. this.dependencies = {};
  16901. this.pageIndex = pageIndex;
  16902. this.intent = intent;
  16903. }
  16904. OperatorList.prototype = {
  16905. get length() {
  16906. return this.argsArray.length;
  16907. },
  16908. addOp: function(fn, args) {
  16909. this.fnArray.push(fn);
  16910. this.argsArray.push(args);
  16911. if (this.messageHandler) {
  16912. if (this.fnArray.length >= CHUNK_SIZE) {
  16913. this.flush();
  16914. } else if (this.fnArray.length >= CHUNK_SIZE_ABOUT &&
  16915. (fn === OPS.restore || fn === OPS.endText)) {
  16916. // heuristic to flush on boundary of restore or endText
  16917. this.flush();
  16918. }
  16919. }
  16920. },
  16921. addDependency: function(dependency) {
  16922. if (dependency in this.dependencies) {
  16923. return;
  16924. }
  16925. this.dependencies[dependency] = true;
  16926. this.addOp(OPS.dependency, [dependency]);
  16927. },
  16928. addDependencies: function(dependencies) {
  16929. for (var key in dependencies) {
  16930. this.addDependency(key);
  16931. }
  16932. },
  16933. addOpList: function(opList) {
  16934. Util.extendObj(this.dependencies, opList.dependencies);
  16935. for (var i = 0, ii = opList.length; i < ii; i++) {
  16936. this.addOp(opList.fnArray[i], opList.argsArray[i]);
  16937. }
  16938. },
  16939. getIR: function() {
  16940. return {
  16941. fnArray: this.fnArray,
  16942. argsArray: this.argsArray,
  16943. length: this.length
  16944. };
  16945. },
  16946. flush: function(lastChunk) {
  16947. if (this.intent !== 'oplist') {
  16948. new QueueOptimizer().optimize(this);
  16949. }
  16950. var transfers = getTransfers(this);
  16951. this.messageHandler.send('RenderPageChunk', {
  16952. operatorList: {
  16953. fnArray: this.fnArray,
  16954. argsArray: this.argsArray,
  16955. lastChunk: lastChunk,
  16956. length: this.length
  16957. },
  16958. pageIndex: this.pageIndex,
  16959. intent: this.intent
  16960. }, transfers);
  16961. this.dependencies = {};
  16962. this.fnArray.length = 0;
  16963. this.argsArray.length = 0;
  16964. }
  16965. };
  16966. return OperatorList;
  16967. })();
  16968. var StateManager = (function StateManagerClosure() {
  16969. function StateManager(initialState) {
  16970. this.state = initialState;
  16971. this.stateStack = [];
  16972. }
  16973. StateManager.prototype = {
  16974. save: function () {
  16975. var old = this.state;
  16976. this.stateStack.push(this.state);
  16977. this.state = old.clone();
  16978. },
  16979. restore: function () {
  16980. var prev = this.stateStack.pop();
  16981. if (prev) {
  16982. this.state = prev;
  16983. }
  16984. },
  16985. transform: function (args) {
  16986. this.state.ctm = Util.transform(this.state.ctm, args);
  16987. }
  16988. };
  16989. return StateManager;
  16990. })();
  16991. var TextState = (function TextStateClosure() {
  16992. function TextState() {
  16993. this.ctm = new Float32Array(IDENTITY_MATRIX);
  16994. this.fontSize = 0;
  16995. this.font = null;
  16996. this.fontMatrix = FONT_IDENTITY_MATRIX;
  16997. this.textMatrix = IDENTITY_MATRIX.slice();
  16998. this.textLineMatrix = IDENTITY_MATRIX.slice();
  16999. this.charSpacing = 0;
  17000. this.wordSpacing = 0;
  17001. this.leading = 0;
  17002. this.textHScale = 1;
  17003. this.textRise = 0;
  17004. }
  17005. TextState.prototype = {
  17006. setTextMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  17007. var m = this.textMatrix;
  17008. m[0] = a; m[1] = b; m[2] = c; m[3] = d; m[4] = e; m[5] = f;
  17009. },
  17010. setTextLineMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  17011. var m = this.textLineMatrix;
  17012. m[0] = a; m[1] = b; m[2] = c; m[3] = d; m[4] = e; m[5] = f;
  17013. },
  17014. translateTextMatrix: function TextState_translateTextMatrix(x, y) {
  17015. var m = this.textMatrix;
  17016. m[4] = m[0] * x + m[2] * y + m[4];
  17017. m[5] = m[1] * x + m[3] * y + m[5];
  17018. },
  17019. translateTextLineMatrix: function TextState_translateTextMatrix(x, y) {
  17020. var m = this.textLineMatrix;
  17021. m[4] = m[0] * x + m[2] * y + m[4];
  17022. m[5] = m[1] * x + m[3] * y + m[5];
  17023. },
  17024. calcRenderMatrix: function TextState_calcRendeMatrix(ctm) {
  17025. // 9.4.4 Text Space Details
  17026. var tsm = [this.fontSize * this.textHScale, 0,
  17027. 0, this.fontSize,
  17028. 0, this.textRise];
  17029. return Util.transform(ctm, Util.transform(this.textMatrix, tsm));
  17030. },
  17031. carriageReturn: function TextState_carriageReturn() {
  17032. this.translateTextLineMatrix(0, -this.leading);
  17033. this.textMatrix = this.textLineMatrix.slice();
  17034. },
  17035. clone: function TextState_clone() {
  17036. var clone = Object.create(this);
  17037. clone.textMatrix = this.textMatrix.slice();
  17038. clone.textLineMatrix = this.textLineMatrix.slice();
  17039. clone.fontMatrix = this.fontMatrix.slice();
  17040. return clone;
  17041. }
  17042. };
  17043. return TextState;
  17044. })();
  17045. var EvalState = (function EvalStateClosure() {
  17046. function EvalState() {
  17047. this.ctm = new Float32Array(IDENTITY_MATRIX);
  17048. this.font = null;
  17049. this.textRenderingMode = TextRenderingMode.FILL;
  17050. this.fillColorSpace = ColorSpace.singletons.gray;
  17051. this.strokeColorSpace = ColorSpace.singletons.gray;
  17052. }
  17053. EvalState.prototype = {
  17054. clone: function CanvasExtraState_clone() {
  17055. return Object.create(this);
  17056. },
  17057. };
  17058. return EvalState;
  17059. })();
  17060. var EvaluatorPreprocessor = (function EvaluatorPreprocessorClosure() {
  17061. // Specifies properties for each command
  17062. //
  17063. // If variableArgs === true: [0, `numArgs`] expected
  17064. // If variableArgs === false: exactly `numArgs` expected
  17065. var OP_MAP = {
  17066. // Graphic state
  17067. w: { id: OPS.setLineWidth, numArgs: 1, variableArgs: false },
  17068. J: { id: OPS.setLineCap, numArgs: 1, variableArgs: false },
  17069. j: { id: OPS.setLineJoin, numArgs: 1, variableArgs: false },
  17070. M: { id: OPS.setMiterLimit, numArgs: 1, variableArgs: false },
  17071. d: { id: OPS.setDash, numArgs: 2, variableArgs: false },
  17072. ri: { id: OPS.setRenderingIntent, numArgs: 1, variableArgs: false },
  17073. i: { id: OPS.setFlatness, numArgs: 1, variableArgs: false },
  17074. gs: { id: OPS.setGState, numArgs: 1, variableArgs: false },
  17075. q: { id: OPS.save, numArgs: 0, variableArgs: false },
  17076. Q: { id: OPS.restore, numArgs: 0, variableArgs: false },
  17077. cm: { id: OPS.transform, numArgs: 6, variableArgs: false },
  17078. // Path
  17079. m: { id: OPS.moveTo, numArgs: 2, variableArgs: false },
  17080. l: { id: OPS.lineTo, numArgs: 2, variableArgs: false },
  17081. c: { id: OPS.curveTo, numArgs: 6, variableArgs: false },
  17082. v: { id: OPS.curveTo2, numArgs: 4, variableArgs: false },
  17083. y: { id: OPS.curveTo3, numArgs: 4, variableArgs: false },
  17084. h: { id: OPS.closePath, numArgs: 0, variableArgs: false },
  17085. re: { id: OPS.rectangle, numArgs: 4, variableArgs: false },
  17086. S: { id: OPS.stroke, numArgs: 0, variableArgs: false },
  17087. s: { id: OPS.closeStroke, numArgs: 0, variableArgs: false },
  17088. f: { id: OPS.fill, numArgs: 0, variableArgs: false },
  17089. F: { id: OPS.fill, numArgs: 0, variableArgs: false },
  17090. 'f*': { id: OPS.eoFill, numArgs: 0, variableArgs: false },
  17091. B: { id: OPS.fillStroke, numArgs: 0, variableArgs: false },
  17092. 'B*': { id: OPS.eoFillStroke, numArgs: 0, variableArgs: false },
  17093. b: { id: OPS.closeFillStroke, numArgs: 0, variableArgs: false },
  17094. 'b*': { id: OPS.closeEOFillStroke, numArgs: 0, variableArgs: false },
  17095. n: { id: OPS.endPath, numArgs: 0, variableArgs: false },
  17096. // Clipping
  17097. W: { id: OPS.clip, numArgs: 0, variableArgs: false },
  17098. 'W*': { id: OPS.eoClip, numArgs: 0, variableArgs: false },
  17099. // Text
  17100. BT: { id: OPS.beginText, numArgs: 0, variableArgs: false },
  17101. ET: { id: OPS.endText, numArgs: 0, variableArgs: false },
  17102. Tc: { id: OPS.setCharSpacing, numArgs: 1, variableArgs: false },
  17103. Tw: { id: OPS.setWordSpacing, numArgs: 1, variableArgs: false },
  17104. Tz: { id: OPS.setHScale, numArgs: 1, variableArgs: false },
  17105. TL: { id: OPS.setLeading, numArgs: 1, variableArgs: false },
  17106. Tf: { id: OPS.setFont, numArgs: 2, variableArgs: false },
  17107. Tr: { id: OPS.setTextRenderingMode, numArgs: 1, variableArgs: false },
  17108. Ts: { id: OPS.setTextRise, numArgs: 1, variableArgs: false },
  17109. Td: { id: OPS.moveText, numArgs: 2, variableArgs: false },
  17110. TD: { id: OPS.setLeadingMoveText, numArgs: 2, variableArgs: false },
  17111. Tm: { id: OPS.setTextMatrix, numArgs: 6, variableArgs: false },
  17112. 'T*': { id: OPS.nextLine, numArgs: 0, variableArgs: false },
  17113. Tj: { id: OPS.showText, numArgs: 1, variableArgs: false },
  17114. TJ: { id: OPS.showSpacedText, numArgs: 1, variableArgs: false },
  17115. '\'': { id: OPS.nextLineShowText, numArgs: 1, variableArgs: false },
  17116. '"': { id: OPS.nextLineSetSpacingShowText, numArgs: 3,
  17117. variableArgs: false },
  17118. // Type3 fonts
  17119. d0: { id: OPS.setCharWidth, numArgs: 2, variableArgs: false },
  17120. d1: { id: OPS.setCharWidthAndBounds, numArgs: 6, variableArgs: false },
  17121. // Color
  17122. CS: { id: OPS.setStrokeColorSpace, numArgs: 1, variableArgs: false },
  17123. cs: { id: OPS.setFillColorSpace, numArgs: 1, variableArgs: false },
  17124. SC: { id: OPS.setStrokeColor, numArgs: 4, variableArgs: true },
  17125. SCN: { id: OPS.setStrokeColorN, numArgs: 33, variableArgs: true },
  17126. sc: { id: OPS.setFillColor, numArgs: 4, variableArgs: true },
  17127. scn: { id: OPS.setFillColorN, numArgs: 33, variableArgs: true },
  17128. G: { id: OPS.setStrokeGray, numArgs: 1, variableArgs: false },
  17129. g: { id: OPS.setFillGray, numArgs: 1, variableArgs: false },
  17130. RG: { id: OPS.setStrokeRGBColor, numArgs: 3, variableArgs: false },
  17131. rg: { id: OPS.setFillRGBColor, numArgs: 3, variableArgs: false },
  17132. K: { id: OPS.setStrokeCMYKColor, numArgs: 4, variableArgs: false },
  17133. k: { id: OPS.setFillCMYKColor, numArgs: 4, variableArgs: false },
  17134. // Shading
  17135. sh: { id: OPS.shadingFill, numArgs: 1, variableArgs: false },
  17136. // Images
  17137. BI: { id: OPS.beginInlineImage, numArgs: 0, variableArgs: false },
  17138. ID: { id: OPS.beginImageData, numArgs: 0, variableArgs: false },
  17139. EI: { id: OPS.endInlineImage, numArgs: 1, variableArgs: false },
  17140. // XObjects
  17141. Do: { id: OPS.paintXObject, numArgs: 1, variableArgs: false },
  17142. MP: { id: OPS.markPoint, numArgs: 1, variableArgs: false },
  17143. DP: { id: OPS.markPointProps, numArgs: 2, variableArgs: false },
  17144. BMC: { id: OPS.beginMarkedContent, numArgs: 1, variableArgs: false },
  17145. BDC: { id: OPS.beginMarkedContentProps, numArgs: 2,
  17146. variableArgs: false },
  17147. EMC: { id: OPS.endMarkedContent, numArgs: 0, variableArgs: false },
  17148. // Compatibility
  17149. BX: { id: OPS.beginCompat, numArgs: 0, variableArgs: false },
  17150. EX: { id: OPS.endCompat, numArgs: 0, variableArgs: false },
  17151. // (reserved partial commands for the lexer)
  17152. BM: null,
  17153. BD: null,
  17154. 'true': null,
  17155. fa: null,
  17156. fal: null,
  17157. fals: null,
  17158. 'false': null,
  17159. nu: null,
  17160. nul: null,
  17161. 'null': null
  17162. };
  17163. function EvaluatorPreprocessor(stream, xref, stateManager) {
  17164. // TODO(mduan): pass array of knownCommands rather than OP_MAP
  17165. // dictionary
  17166. this.parser = new Parser(new Lexer(stream, OP_MAP), false, xref);
  17167. this.stateManager = stateManager;
  17168. this.nonProcessedArgs = [];
  17169. }
  17170. EvaluatorPreprocessor.prototype = {
  17171. get savedStatesDepth() {
  17172. return this.stateManager.stateStack.length;
  17173. },
  17174. // |operation| is an object with two fields:
  17175. //
  17176. // - |fn| is an out param.
  17177. //
  17178. // - |args| is an inout param. On entry, it should have one of two values.
  17179. //
  17180. // - An empty array. This indicates that the caller is providing the
  17181. // array in which the args will be stored in. The caller should use
  17182. // this value if it can reuse a single array for each call to read().
  17183. //
  17184. // - |null|. This indicates that the caller needs this function to create
  17185. // the array in which any args are stored in. If there are zero args,
  17186. // this function will leave |operation.args| as |null| (thus avoiding
  17187. // allocations that would occur if we used an empty array to represent
  17188. // zero arguments). Otherwise, it will replace |null| with a new array
  17189. // containing the arguments. The caller should use this value if it
  17190. // cannot reuse an array for each call to read().
  17191. //
  17192. // These two modes are present because this function is very hot and so
  17193. // avoiding allocations where possible is worthwhile.
  17194. //
  17195. read: function EvaluatorPreprocessor_read(operation) {
  17196. var args = operation.args;
  17197. while (true) {
  17198. var obj = this.parser.getObj();
  17199. if (isCmd(obj)) {
  17200. var cmd = obj.cmd;
  17201. // Check that the command is valid
  17202. var opSpec = OP_MAP[cmd];
  17203. if (!opSpec) {
  17204. warn('Unknown command "' + cmd + '"');
  17205. continue;
  17206. }
  17207. var fn = opSpec.id;
  17208. var numArgs = opSpec.numArgs;
  17209. var argsLength = args !== null ? args.length : 0;
  17210. if (!opSpec.variableArgs) {
  17211. // Postscript commands can be nested, e.g. /F2 /GS2 gs 5.711 Tf
  17212. if (argsLength !== numArgs) {
  17213. var nonProcessedArgs = this.nonProcessedArgs;
  17214. while (argsLength > numArgs) {
  17215. nonProcessedArgs.push(args.shift());
  17216. argsLength--;
  17217. }
  17218. while (argsLength < numArgs && nonProcessedArgs.length !== 0) {
  17219. if (!args) {
  17220. args = [];
  17221. }
  17222. args.unshift(nonProcessedArgs.pop());
  17223. argsLength++;
  17224. }
  17225. }
  17226. if (argsLength < numArgs) {
  17227. // If we receive too few args, it's not possible to possible
  17228. // to execute the command, so skip the command
  17229. info('Command ' + fn + ': because expected ' +
  17230. numArgs + ' args, but received ' + argsLength +
  17231. ' args; skipping');
  17232. args = null;
  17233. continue;
  17234. }
  17235. } else if (argsLength > numArgs) {
  17236. info('Command ' + fn + ': expected [0,' + numArgs +
  17237. '] args, but received ' + argsLength + ' args');
  17238. }
  17239. // TODO figure out how to type-check vararg functions
  17240. this.preprocessCommand(fn, args);
  17241. operation.fn = fn;
  17242. operation.args = args;
  17243. return true;
  17244. } else {
  17245. if (isEOF(obj)) {
  17246. return false; // no more commands
  17247. }
  17248. // argument
  17249. if (obj !== null) {
  17250. if (!args) {
  17251. args = [];
  17252. }
  17253. args.push((obj instanceof Dict ? obj.getAll() : obj));
  17254. assert(args.length <= 33, 'Too many arguments');
  17255. }
  17256. }
  17257. }
  17258. },
  17259. preprocessCommand:
  17260. function EvaluatorPreprocessor_preprocessCommand(fn, args) {
  17261. switch (fn | 0) {
  17262. case OPS.save:
  17263. this.stateManager.save();
  17264. break;
  17265. case OPS.restore:
  17266. this.stateManager.restore();
  17267. break;
  17268. case OPS.transform:
  17269. this.stateManager.transform(args);
  17270. break;
  17271. }
  17272. }
  17273. };
  17274. return EvaluatorPreprocessor;
  17275. })();
  17276. var QueueOptimizer = (function QueueOptimizerClosure() {
  17277. function addState(parentState, pattern, fn) {
  17278. var state = parentState;
  17279. for (var i = 0, ii = pattern.length - 1; i < ii; i++) {
  17280. var item = pattern[i];
  17281. state = (state[item] || (state[item] = []));
  17282. }
  17283. state[pattern[pattern.length - 1]] = fn;
  17284. }
  17285. function handlePaintSolidColorImageMask(iFirstSave, count, fnArray,
  17286. argsArray) {
  17287. // Handles special case of mainly LaTeX documents which use image masks to
  17288. // draw lines with the current fill style.
  17289. // 'count' groups of (save, transform, paintImageMaskXObject, restore)+
  17290. // have been found at iFirstSave.
  17291. var iFirstPIMXO = iFirstSave + 2;
  17292. for (var i = 0; i < count; i++) {
  17293. var arg = argsArray[iFirstPIMXO + 4 * i];
  17294. var imageMask = arg.length === 1 && arg[0];
  17295. if (imageMask && imageMask.width === 1 && imageMask.height === 1 &&
  17296. (!imageMask.data.length ||
  17297. (imageMask.data.length === 1 && imageMask.data[0] === 0))) {
  17298. fnArray[iFirstPIMXO + 4 * i] = OPS.paintSolidColorImageMask;
  17299. continue;
  17300. }
  17301. break;
  17302. }
  17303. return count - i;
  17304. }
  17305. var InitialState = [];
  17306. // This replaces (save, transform, paintInlineImageXObject, restore)+
  17307. // sequences with one |paintInlineImageXObjectGroup| operation.
  17308. addState(InitialState,
  17309. [OPS.save, OPS.transform, OPS.paintInlineImageXObject, OPS.restore],
  17310. function foundInlineImageGroup(context) {
  17311. var MIN_IMAGES_IN_INLINE_IMAGES_BLOCK = 10;
  17312. var MAX_IMAGES_IN_INLINE_IMAGES_BLOCK = 200;
  17313. var MAX_WIDTH = 1000;
  17314. var IMAGE_PADDING = 1;
  17315. var fnArray = context.fnArray, argsArray = context.argsArray;
  17316. var curr = context.iCurr;
  17317. var iFirstSave = curr - 3;
  17318. var iFirstTransform = curr - 2;
  17319. var iFirstPIIXO = curr - 1;
  17320. // Look for the quartets.
  17321. var i = iFirstSave + 4;
  17322. var ii = fnArray.length;
  17323. while (i + 3 < ii) {
  17324. if (fnArray[i] !== OPS.save ||
  17325. fnArray[i + 1] !== OPS.transform ||
  17326. fnArray[i + 2] !== OPS.paintInlineImageXObject ||
  17327. fnArray[i + 3] !== OPS.restore) {
  17328. break; // ops don't match
  17329. }
  17330. i += 4;
  17331. }
  17332. // At this point, i is the index of the first op past the last valid
  17333. // quartet.
  17334. var count = Math.min((i - iFirstSave) / 4,
  17335. MAX_IMAGES_IN_INLINE_IMAGES_BLOCK);
  17336. if (count < MIN_IMAGES_IN_INLINE_IMAGES_BLOCK) {
  17337. return i;
  17338. }
  17339. // assuming that heights of those image is too small (~1 pixel)
  17340. // packing as much as possible by lines
  17341. var maxX = 0;
  17342. var map = [], maxLineHeight = 0;
  17343. var currentX = IMAGE_PADDING, currentY = IMAGE_PADDING;
  17344. var q;
  17345. for (q = 0; q < count; q++) {
  17346. var transform = argsArray[iFirstTransform + (q << 2)];
  17347. var img = argsArray[iFirstPIIXO + (q << 2)][0];
  17348. if (currentX + img.width > MAX_WIDTH) {
  17349. // starting new line
  17350. maxX = Math.max(maxX, currentX);
  17351. currentY += maxLineHeight + 2 * IMAGE_PADDING;
  17352. currentX = 0;
  17353. maxLineHeight = 0;
  17354. }
  17355. map.push({
  17356. transform: transform,
  17357. x: currentX, y: currentY,
  17358. w: img.width, h: img.height
  17359. });
  17360. currentX += img.width + 2 * IMAGE_PADDING;
  17361. maxLineHeight = Math.max(maxLineHeight, img.height);
  17362. }
  17363. var imgWidth = Math.max(maxX, currentX) + IMAGE_PADDING;
  17364. var imgHeight = currentY + maxLineHeight + IMAGE_PADDING;
  17365. var imgData = new Uint8Array(imgWidth * imgHeight * 4);
  17366. var imgRowSize = imgWidth << 2;
  17367. for (q = 0; q < count; q++) {
  17368. var data = argsArray[iFirstPIIXO + (q << 2)][0].data;
  17369. // Copy image by lines and extends pixels into padding.
  17370. var rowSize = map[q].w << 2;
  17371. var dataOffset = 0;
  17372. var offset = (map[q].x + map[q].y * imgWidth) << 2;
  17373. imgData.set(data.subarray(0, rowSize), offset - imgRowSize);
  17374. for (var k = 0, kk = map[q].h; k < kk; k++) {
  17375. imgData.set(data.subarray(dataOffset, dataOffset + rowSize), offset);
  17376. dataOffset += rowSize;
  17377. offset += imgRowSize;
  17378. }
  17379. imgData.set(data.subarray(dataOffset - rowSize, dataOffset), offset);
  17380. while (offset >= 0) {
  17381. data[offset - 4] = data[offset];
  17382. data[offset - 3] = data[offset + 1];
  17383. data[offset - 2] = data[offset + 2];
  17384. data[offset - 1] = data[offset + 3];
  17385. data[offset + rowSize] = data[offset + rowSize - 4];
  17386. data[offset + rowSize + 1] = data[offset + rowSize - 3];
  17387. data[offset + rowSize + 2] = data[offset + rowSize - 2];
  17388. data[offset + rowSize + 3] = data[offset + rowSize - 1];
  17389. offset -= imgRowSize;
  17390. }
  17391. }
  17392. // Replace queue items.
  17393. fnArray.splice(iFirstSave, count * 4, OPS.paintInlineImageXObjectGroup);
  17394. argsArray.splice(iFirstSave, count * 4,
  17395. [{ width: imgWidth, height: imgHeight, kind: ImageKind.RGBA_32BPP,
  17396. data: imgData }, map]);
  17397. return iFirstSave + 1;
  17398. });
  17399. // This replaces (save, transform, paintImageMaskXObject, restore)+
  17400. // sequences with one |paintImageMaskXObjectGroup| or one
  17401. // |paintImageMaskXObjectRepeat| operation.
  17402. addState(InitialState,
  17403. [OPS.save, OPS.transform, OPS.paintImageMaskXObject, OPS.restore],
  17404. function foundImageMaskGroup(context) {
  17405. var MIN_IMAGES_IN_MASKS_BLOCK = 10;
  17406. var MAX_IMAGES_IN_MASKS_BLOCK = 100;
  17407. var MAX_SAME_IMAGES_IN_MASKS_BLOCK = 1000;
  17408. var fnArray = context.fnArray, argsArray = context.argsArray;
  17409. var curr = context.iCurr;
  17410. var iFirstSave = curr - 3;
  17411. var iFirstTransform = curr - 2;
  17412. var iFirstPIMXO = curr - 1;
  17413. // Look for the quartets.
  17414. var i = iFirstSave + 4;
  17415. var ii = fnArray.length;
  17416. while (i + 3 < ii) {
  17417. if (fnArray[i] !== OPS.save ||
  17418. fnArray[i + 1] !== OPS.transform ||
  17419. fnArray[i + 2] !== OPS.paintImageMaskXObject ||
  17420. fnArray[i + 3] !== OPS.restore) {
  17421. break; // ops don't match
  17422. }
  17423. i += 4;
  17424. }
  17425. // At this point, i is the index of the first op past the last valid
  17426. // quartet.
  17427. var count = (i - iFirstSave) / 4;
  17428. count = handlePaintSolidColorImageMask(iFirstSave, count, fnArray,
  17429. argsArray);
  17430. if (count < MIN_IMAGES_IN_MASKS_BLOCK) {
  17431. return i;
  17432. }
  17433. var q;
  17434. var isSameImage = false;
  17435. var iTransform, transformArgs;
  17436. var firstPIMXOArg0 = argsArray[iFirstPIMXO][0];
  17437. if (argsArray[iFirstTransform][1] === 0 &&
  17438. argsArray[iFirstTransform][2] === 0) {
  17439. isSameImage = true;
  17440. var firstTransformArg0 = argsArray[iFirstTransform][0];
  17441. var firstTransformArg3 = argsArray[iFirstTransform][3];
  17442. iTransform = iFirstTransform + 4;
  17443. var iPIMXO = iFirstPIMXO + 4;
  17444. for (q = 1; q < count; q++, iTransform += 4, iPIMXO += 4) {
  17445. transformArgs = argsArray[iTransform];
  17446. if (argsArray[iPIMXO][0] !== firstPIMXOArg0 ||
  17447. transformArgs[0] !== firstTransformArg0 ||
  17448. transformArgs[1] !== 0 ||
  17449. transformArgs[2] !== 0 ||
  17450. transformArgs[3] !== firstTransformArg3) {
  17451. if (q < MIN_IMAGES_IN_MASKS_BLOCK) {
  17452. isSameImage = false;
  17453. } else {
  17454. count = q;
  17455. }
  17456. break; // different image or transform
  17457. }
  17458. }
  17459. }
  17460. if (isSameImage) {
  17461. count = Math.min(count, MAX_SAME_IMAGES_IN_MASKS_BLOCK);
  17462. var positions = new Float32Array(count * 2);
  17463. iTransform = iFirstTransform;
  17464. for (q = 0; q < count; q++, iTransform += 4) {
  17465. transformArgs = argsArray[iTransform];
  17466. positions[(q << 1)] = transformArgs[4];
  17467. positions[(q << 1) + 1] = transformArgs[5];
  17468. }
  17469. // Replace queue items.
  17470. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectRepeat);
  17471. argsArray.splice(iFirstSave, count * 4,
  17472. [firstPIMXOArg0, firstTransformArg0, firstTransformArg3, positions]);
  17473. } else {
  17474. count = Math.min(count, MAX_IMAGES_IN_MASKS_BLOCK);
  17475. var images = [];
  17476. for (q = 0; q < count; q++) {
  17477. transformArgs = argsArray[iFirstTransform + (q << 2)];
  17478. var maskParams = argsArray[iFirstPIMXO + (q << 2)][0];
  17479. images.push({ data: maskParams.data, width: maskParams.width,
  17480. height: maskParams.height,
  17481. transform: transformArgs });
  17482. }
  17483. // Replace queue items.
  17484. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectGroup);
  17485. argsArray.splice(iFirstSave, count * 4, [images]);
  17486. }
  17487. return iFirstSave + 1;
  17488. });
  17489. // This replaces (save, transform, paintImageXObject, restore)+ sequences
  17490. // with one paintImageXObjectRepeat operation, if the |transform| and
  17491. // |paintImageXObjectRepeat| ops are appropriate.
  17492. addState(InitialState,
  17493. [OPS.save, OPS.transform, OPS.paintImageXObject, OPS.restore],
  17494. function (context) {
  17495. var MIN_IMAGES_IN_BLOCK = 3;
  17496. var MAX_IMAGES_IN_BLOCK = 1000;
  17497. var fnArray = context.fnArray, argsArray = context.argsArray;
  17498. var curr = context.iCurr;
  17499. var iFirstSave = curr - 3;
  17500. var iFirstTransform = curr - 2;
  17501. var iFirstPIXO = curr - 1;
  17502. var iFirstRestore = curr;
  17503. if (argsArray[iFirstTransform][1] !== 0 ||
  17504. argsArray[iFirstTransform][2] !== 0) {
  17505. return iFirstRestore + 1; // transform has the wrong form
  17506. }
  17507. // Look for the quartets.
  17508. var firstPIXOArg0 = argsArray[iFirstPIXO][0];
  17509. var firstTransformArg0 = argsArray[iFirstTransform][0];
  17510. var firstTransformArg3 = argsArray[iFirstTransform][3];
  17511. var i = iFirstSave + 4;
  17512. var ii = fnArray.length;
  17513. while (i + 3 < ii) {
  17514. if (fnArray[i] !== OPS.save ||
  17515. fnArray[i + 1] !== OPS.transform ||
  17516. fnArray[i + 2] !== OPS.paintImageXObject ||
  17517. fnArray[i + 3] !== OPS.restore) {
  17518. break; // ops don't match
  17519. }
  17520. if (argsArray[i + 1][0] !== firstTransformArg0 ||
  17521. argsArray[i + 1][1] !== 0 ||
  17522. argsArray[i + 1][2] !== 0 ||
  17523. argsArray[i + 1][3] !== firstTransformArg3) {
  17524. break; // transforms don't match
  17525. }
  17526. if (argsArray[i + 2][0] !== firstPIXOArg0) {
  17527. break; // images don't match
  17528. }
  17529. i += 4;
  17530. }
  17531. // At this point, i is the index of the first op past the last valid
  17532. // quartet.
  17533. var count = Math.min((i - iFirstSave) / 4, MAX_IMAGES_IN_BLOCK);
  17534. if (count < MIN_IMAGES_IN_BLOCK) {
  17535. return i;
  17536. }
  17537. // Extract the (x,y) positions from all of the matching transforms.
  17538. var positions = new Float32Array(count * 2);
  17539. var iTransform = iFirstTransform;
  17540. for (var q = 0; q < count; q++, iTransform += 4) {
  17541. var transformArgs = argsArray[iTransform];
  17542. positions[(q << 1)] = transformArgs[4];
  17543. positions[(q << 1) + 1] = transformArgs[5];
  17544. }
  17545. // Replace queue items.
  17546. var args = [firstPIXOArg0, firstTransformArg0, firstTransformArg3,
  17547. positions];
  17548. fnArray.splice(iFirstSave, count * 4, OPS.paintImageXObjectRepeat);
  17549. argsArray.splice(iFirstSave, count * 4, args);
  17550. return iFirstSave + 1;
  17551. });
  17552. // This replaces (beginText, setFont, setTextMatrix, showText, endText)+
  17553. // sequences with (beginText, setFont, (setTextMatrix, showText)+, endText)+
  17554. // sequences, if the font for each one is the same.
  17555. addState(InitialState,
  17556. [OPS.beginText, OPS.setFont, OPS.setTextMatrix, OPS.showText, OPS.endText],
  17557. function (context) {
  17558. var MIN_CHARS_IN_BLOCK = 3;
  17559. var MAX_CHARS_IN_BLOCK = 1000;
  17560. var fnArray = context.fnArray, argsArray = context.argsArray;
  17561. var curr = context.iCurr;
  17562. var iFirstBeginText = curr - 4;
  17563. var iFirstSetFont = curr - 3;
  17564. var iFirstSetTextMatrix = curr - 2;
  17565. var iFirstShowText = curr - 1;
  17566. var iFirstEndText = curr;
  17567. // Look for the quintets.
  17568. var firstSetFontArg0 = argsArray[iFirstSetFont][0];
  17569. var firstSetFontArg1 = argsArray[iFirstSetFont][1];
  17570. var i = iFirstBeginText + 5;
  17571. var ii = fnArray.length;
  17572. while (i + 4 < ii) {
  17573. if (fnArray[i] !== OPS.beginText ||
  17574. fnArray[i + 1] !== OPS.setFont ||
  17575. fnArray[i + 2] !== OPS.setTextMatrix ||
  17576. fnArray[i + 3] !== OPS.showText ||
  17577. fnArray[i + 4] !== OPS.endText) {
  17578. break; // ops don't match
  17579. }
  17580. if (argsArray[i + 1][0] !== firstSetFontArg0 ||
  17581. argsArray[i + 1][1] !== firstSetFontArg1) {
  17582. break; // fonts don't match
  17583. }
  17584. i += 5;
  17585. }
  17586. // At this point, i is the index of the first op past the last valid
  17587. // quintet.
  17588. var count = Math.min(((i - iFirstBeginText) / 5), MAX_CHARS_IN_BLOCK);
  17589. if (count < MIN_CHARS_IN_BLOCK) {
  17590. return i;
  17591. }
  17592. // If the preceding quintet is (<something>, setFont, setTextMatrix,
  17593. // showText, endText), include that as well. (E.g. <something> might be
  17594. // |dependency|.)
  17595. var iFirst = iFirstBeginText;
  17596. if (iFirstBeginText >= 4 &&
  17597. fnArray[iFirstBeginText - 4] === fnArray[iFirstSetFont] &&
  17598. fnArray[iFirstBeginText - 3] === fnArray[iFirstSetTextMatrix] &&
  17599. fnArray[iFirstBeginText - 2] === fnArray[iFirstShowText] &&
  17600. fnArray[iFirstBeginText - 1] === fnArray[iFirstEndText] &&
  17601. argsArray[iFirstBeginText - 4][0] === firstSetFontArg0 &&
  17602. argsArray[iFirstBeginText - 4][1] === firstSetFontArg1) {
  17603. count++;
  17604. iFirst -= 5;
  17605. }
  17606. // Remove (endText, beginText, setFont) trios.
  17607. var iEndText = iFirst + 4;
  17608. for (var q = 1; q < count; q++) {
  17609. fnArray.splice(iEndText, 3);
  17610. argsArray.splice(iEndText, 3);
  17611. iEndText += 2;
  17612. }
  17613. return iEndText + 1;
  17614. });
  17615. function QueueOptimizer() {}
  17616. QueueOptimizer.prototype = {
  17617. optimize: function QueueOptimizer_optimize(queue) {
  17618. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  17619. var context = {
  17620. iCurr: 0,
  17621. fnArray: fnArray,
  17622. argsArray: argsArray
  17623. };
  17624. var state;
  17625. var i = 0, ii = fnArray.length;
  17626. while (i < ii) {
  17627. state = (state || InitialState)[fnArray[i]];
  17628. if (typeof state === 'function') { // we found some handler
  17629. context.iCurr = i;
  17630. // state() returns the index of the first non-matching op (if we
  17631. // didn't match) or the first op past the modified ops (if we did
  17632. // match and replace).
  17633. i = state(context);
  17634. state = undefined; // reset the state machine
  17635. ii = context.fnArray.length;
  17636. } else {
  17637. i++;
  17638. }
  17639. }
  17640. }
  17641. };
  17642. return QueueOptimizer;
  17643. })();
  17644. var BUILT_IN_CMAPS = [
  17645. // << Start unicode maps.
  17646. 'Adobe-GB1-UCS2',
  17647. 'Adobe-CNS1-UCS2',
  17648. 'Adobe-Japan1-UCS2',
  17649. 'Adobe-Korea1-UCS2',
  17650. // >> End unicode maps.
  17651. '78-EUC-H',
  17652. '78-EUC-V',
  17653. '78-H',
  17654. '78-RKSJ-H',
  17655. '78-RKSJ-V',
  17656. '78-V',
  17657. '78ms-RKSJ-H',
  17658. '78ms-RKSJ-V',
  17659. '83pv-RKSJ-H',
  17660. '90ms-RKSJ-H',
  17661. '90ms-RKSJ-V',
  17662. '90msp-RKSJ-H',
  17663. '90msp-RKSJ-V',
  17664. '90pv-RKSJ-H',
  17665. '90pv-RKSJ-V',
  17666. 'Add-H',
  17667. 'Add-RKSJ-H',
  17668. 'Add-RKSJ-V',
  17669. 'Add-V',
  17670. 'Adobe-CNS1-0',
  17671. 'Adobe-CNS1-1',
  17672. 'Adobe-CNS1-2',
  17673. 'Adobe-CNS1-3',
  17674. 'Adobe-CNS1-4',
  17675. 'Adobe-CNS1-5',
  17676. 'Adobe-CNS1-6',
  17677. 'Adobe-GB1-0',
  17678. 'Adobe-GB1-1',
  17679. 'Adobe-GB1-2',
  17680. 'Adobe-GB1-3',
  17681. 'Adobe-GB1-4',
  17682. 'Adobe-GB1-5',
  17683. 'Adobe-Japan1-0',
  17684. 'Adobe-Japan1-1',
  17685. 'Adobe-Japan1-2',
  17686. 'Adobe-Japan1-3',
  17687. 'Adobe-Japan1-4',
  17688. 'Adobe-Japan1-5',
  17689. 'Adobe-Japan1-6',
  17690. 'Adobe-Korea1-0',
  17691. 'Adobe-Korea1-1',
  17692. 'Adobe-Korea1-2',
  17693. 'B5-H',
  17694. 'B5-V',
  17695. 'B5pc-H',
  17696. 'B5pc-V',
  17697. 'CNS-EUC-H',
  17698. 'CNS-EUC-V',
  17699. 'CNS1-H',
  17700. 'CNS1-V',
  17701. 'CNS2-H',
  17702. 'CNS2-V',
  17703. 'ETHK-B5-H',
  17704. 'ETHK-B5-V',
  17705. 'ETen-B5-H',
  17706. 'ETen-B5-V',
  17707. 'ETenms-B5-H',
  17708. 'ETenms-B5-V',
  17709. 'EUC-H',
  17710. 'EUC-V',
  17711. 'Ext-H',
  17712. 'Ext-RKSJ-H',
  17713. 'Ext-RKSJ-V',
  17714. 'Ext-V',
  17715. 'GB-EUC-H',
  17716. 'GB-EUC-V',
  17717. 'GB-H',
  17718. 'GB-V',
  17719. 'GBK-EUC-H',
  17720. 'GBK-EUC-V',
  17721. 'GBK2K-H',
  17722. 'GBK2K-V',
  17723. 'GBKp-EUC-H',
  17724. 'GBKp-EUC-V',
  17725. 'GBT-EUC-H',
  17726. 'GBT-EUC-V',
  17727. 'GBT-H',
  17728. 'GBT-V',
  17729. 'GBTpc-EUC-H',
  17730. 'GBTpc-EUC-V',
  17731. 'GBpc-EUC-H',
  17732. 'GBpc-EUC-V',
  17733. 'H',
  17734. 'HKdla-B5-H',
  17735. 'HKdla-B5-V',
  17736. 'HKdlb-B5-H',
  17737. 'HKdlb-B5-V',
  17738. 'HKgccs-B5-H',
  17739. 'HKgccs-B5-V',
  17740. 'HKm314-B5-H',
  17741. 'HKm314-B5-V',
  17742. 'HKm471-B5-H',
  17743. 'HKm471-B5-V',
  17744. 'HKscs-B5-H',
  17745. 'HKscs-B5-V',
  17746. 'Hankaku',
  17747. 'Hiragana',
  17748. 'KSC-EUC-H',
  17749. 'KSC-EUC-V',
  17750. 'KSC-H',
  17751. 'KSC-Johab-H',
  17752. 'KSC-Johab-V',
  17753. 'KSC-V',
  17754. 'KSCms-UHC-H',
  17755. 'KSCms-UHC-HW-H',
  17756. 'KSCms-UHC-HW-V',
  17757. 'KSCms-UHC-V',
  17758. 'KSCpc-EUC-H',
  17759. 'KSCpc-EUC-V',
  17760. 'Katakana',
  17761. 'NWP-H',
  17762. 'NWP-V',
  17763. 'RKSJ-H',
  17764. 'RKSJ-V',
  17765. 'Roman',
  17766. 'UniCNS-UCS2-H',
  17767. 'UniCNS-UCS2-V',
  17768. 'UniCNS-UTF16-H',
  17769. 'UniCNS-UTF16-V',
  17770. 'UniCNS-UTF32-H',
  17771. 'UniCNS-UTF32-V',
  17772. 'UniCNS-UTF8-H',
  17773. 'UniCNS-UTF8-V',
  17774. 'UniGB-UCS2-H',
  17775. 'UniGB-UCS2-V',
  17776. 'UniGB-UTF16-H',
  17777. 'UniGB-UTF16-V',
  17778. 'UniGB-UTF32-H',
  17779. 'UniGB-UTF32-V',
  17780. 'UniGB-UTF8-H',
  17781. 'UniGB-UTF8-V',
  17782. 'UniJIS-UCS2-H',
  17783. 'UniJIS-UCS2-HW-H',
  17784. 'UniJIS-UCS2-HW-V',
  17785. 'UniJIS-UCS2-V',
  17786. 'UniJIS-UTF16-H',
  17787. 'UniJIS-UTF16-V',
  17788. 'UniJIS-UTF32-H',
  17789. 'UniJIS-UTF32-V',
  17790. 'UniJIS-UTF8-H',
  17791. 'UniJIS-UTF8-V',
  17792. 'UniJIS2004-UTF16-H',
  17793. 'UniJIS2004-UTF16-V',
  17794. 'UniJIS2004-UTF32-H',
  17795. 'UniJIS2004-UTF32-V',
  17796. 'UniJIS2004-UTF8-H',
  17797. 'UniJIS2004-UTF8-V',
  17798. 'UniJISPro-UCS2-HW-V',
  17799. 'UniJISPro-UCS2-V',
  17800. 'UniJISPro-UTF8-V',
  17801. 'UniJISX0213-UTF32-H',
  17802. 'UniJISX0213-UTF32-V',
  17803. 'UniJISX02132004-UTF32-H',
  17804. 'UniJISX02132004-UTF32-V',
  17805. 'UniKS-UCS2-H',
  17806. 'UniKS-UCS2-V',
  17807. 'UniKS-UTF16-H',
  17808. 'UniKS-UTF16-V',
  17809. 'UniKS-UTF32-H',
  17810. 'UniKS-UTF32-V',
  17811. 'UniKS-UTF8-H',
  17812. 'UniKS-UTF8-V',
  17813. 'V',
  17814. 'WP-Symbol'];
  17815. // CMap, not to be confused with TrueType's cmap.
  17816. var CMap = (function CMapClosure() {
  17817. function CMap(builtInCMap) {
  17818. // Codespace ranges are stored as follows:
  17819. // [[1BytePairs], [2BytePairs], [3BytePairs], [4BytePairs]]
  17820. // where nBytePairs are ranges e.g. [low1, high1, low2, high2, ...]
  17821. this.codespaceRanges = [[], [], [], []];
  17822. this.numCodespaceRanges = 0;
  17823. // Map entries have one of two forms.
  17824. // - cid chars are 16-bit unsigned integers, stored as integers.
  17825. // - bf chars are variable-length byte sequences, stored as strings, with
  17826. // one byte per character.
  17827. this._map = [];
  17828. this.name = '';
  17829. this.vertical = false;
  17830. this.useCMap = null;
  17831. this.builtInCMap = builtInCMap;
  17832. }
  17833. CMap.prototype = {
  17834. addCodespaceRange: function(n, low, high) {
  17835. this.codespaceRanges[n - 1].push(low, high);
  17836. this.numCodespaceRanges++;
  17837. },
  17838. mapCidRange: function(low, high, dstLow) {
  17839. while (low <= high) {
  17840. this._map[low++] = dstLow++;
  17841. }
  17842. },
  17843. mapBfRange: function(low, high, dstLow) {
  17844. var lastByte = dstLow.length - 1;
  17845. while (low <= high) {
  17846. this._map[low++] = dstLow;
  17847. // Only the last byte has to be incremented.
  17848. dstLow = dstLow.substr(0, lastByte) +
  17849. String.fromCharCode(dstLow.charCodeAt(lastByte) + 1);
  17850. }
  17851. },
  17852. mapBfRangeToArray: function(low, high, array) {
  17853. var i = 0, ii = array.length;
  17854. while (low <= high && i < ii) {
  17855. this._map[low] = array[i++];
  17856. ++low;
  17857. }
  17858. },
  17859. // This is used for both bf and cid chars.
  17860. mapOne: function(src, dst) {
  17861. this._map[src] = dst;
  17862. },
  17863. lookup: function(code) {
  17864. return this._map[code];
  17865. },
  17866. contains: function(code) {
  17867. return this._map[code] !== undefined;
  17868. },
  17869. forEach: function(callback) {
  17870. // Most maps have fewer than 65536 entries, and for those we use normal
  17871. // array iteration. But really sparse tables are possible -- e.g. with
  17872. // indices in the *billions*. For such tables we use for..in, which isn't
  17873. // ideal because it stringifies the indices for all present elements, but
  17874. // it does avoid iterating over every undefined entry.
  17875. var map = this._map;
  17876. var length = map.length;
  17877. var i;
  17878. if (length <= 0x10000) {
  17879. for (i = 0; i < length; i++) {
  17880. if (map[i] !== undefined) {
  17881. callback(i, map[i]);
  17882. }
  17883. }
  17884. } else {
  17885. for (i in this._map) {
  17886. callback(i, map[i]);
  17887. }
  17888. }
  17889. },
  17890. charCodeOf: function(value) {
  17891. return this._map.indexOf(value);
  17892. },
  17893. getMap: function() {
  17894. return this._map;
  17895. },
  17896. readCharCode: function(str, offset, out) {
  17897. var c = 0;
  17898. var codespaceRanges = this.codespaceRanges;
  17899. var codespaceRangesLen = this.codespaceRanges.length;
  17900. // 9.7.6.2 CMap Mapping
  17901. // The code length is at most 4.
  17902. for (var n = 0; n < codespaceRangesLen; n++) {
  17903. c = ((c << 8) | str.charCodeAt(offset + n)) >>> 0;
  17904. // Check each codespace range to see if it falls within.
  17905. var codespaceRange = codespaceRanges[n];
  17906. for (var k = 0, kk = codespaceRange.length; k < kk;) {
  17907. var low = codespaceRange[k++];
  17908. var high = codespaceRange[k++];
  17909. if (c >= low && c <= high) {
  17910. out.charcode = c;
  17911. out.length = n + 1;
  17912. return;
  17913. }
  17914. }
  17915. }
  17916. out.charcode = 0;
  17917. out.length = 1;
  17918. },
  17919. get isIdentityCMap() {
  17920. if (!(this.name === 'Identity-H' || this.name === 'Identity-V')) {
  17921. return false;
  17922. }
  17923. if (this._map.length !== 0x10000) {
  17924. return false;
  17925. }
  17926. for (var i = 0; i < 0x10000; i++) {
  17927. if (this._map[i] !== i) {
  17928. return false;
  17929. }
  17930. }
  17931. return true;
  17932. }
  17933. };
  17934. return CMap;
  17935. })();
  17936. // A special case of CMap, where the _map array implicitly has a length of
  17937. // 65536 and each element is equal to its index.
  17938. var IdentityCMap = (function IdentityCMapClosure() {
  17939. function IdentityCMap(vertical, n) {
  17940. CMap.call(this);
  17941. this.vertical = vertical;
  17942. this.addCodespaceRange(n, 0, 0xffff);
  17943. }
  17944. Util.inherit(IdentityCMap, CMap, {});
  17945. IdentityCMap.prototype = {
  17946. addCodespaceRange: CMap.prototype.addCodespaceRange,
  17947. mapCidRange: function(low, high, dstLow) {
  17948. error('should not call mapCidRange');
  17949. },
  17950. mapBfRange: function(low, high, dstLow) {
  17951. error('should not call mapBfRange');
  17952. },
  17953. mapBfRangeToArray: function(low, high, array) {
  17954. error('should not call mapBfRangeToArray');
  17955. },
  17956. mapOne: function(src, dst) {
  17957. error('should not call mapCidOne');
  17958. },
  17959. lookup: function(code) {
  17960. return (isInt(code) && code <= 0xffff) ? code : undefined;
  17961. },
  17962. contains: function(code) {
  17963. return isInt(code) && code <= 0xffff;
  17964. },
  17965. forEach: function(callback) {
  17966. for (var i = 0; i <= 0xffff; i++) {
  17967. callback(i, i);
  17968. }
  17969. },
  17970. charCodeOf: function(value) {
  17971. return (isInt(value) && value <= 0xffff) ? value : -1;
  17972. },
  17973. getMap: function() {
  17974. // Sometimes identity maps must be instantiated, but it's rare.
  17975. var map = new Array(0x10000);
  17976. for (var i = 0; i <= 0xffff; i++) {
  17977. map[i] = i;
  17978. }
  17979. return map;
  17980. },
  17981. readCharCode: CMap.prototype.readCharCode,
  17982. get isIdentityCMap() {
  17983. error('should not access .isIdentityCMap');
  17984. }
  17985. };
  17986. return IdentityCMap;
  17987. })();
  17988. var BinaryCMapReader = (function BinaryCMapReaderClosure() {
  17989. function fetchBinaryData(url) {
  17990. var nonBinaryRequest = PDFJS.disableWorker;
  17991. var request = new XMLHttpRequest();
  17992. request.open('GET', url, false);
  17993. if (!nonBinaryRequest) {
  17994. try {
  17995. request.responseType = 'arraybuffer';
  17996. nonBinaryRequest = request.responseType !== 'arraybuffer';
  17997. } catch (e) {
  17998. nonBinaryRequest = true;
  17999. }
  18000. }
  18001. if (nonBinaryRequest && request.overrideMimeType) {
  18002. request.overrideMimeType('text/plain; charset=x-user-defined');
  18003. }
  18004. request.send(null);
  18005. if (nonBinaryRequest ? !request.responseText : !request.response) {
  18006. error('Unable to get binary cMap at: ' + url);
  18007. }
  18008. if (nonBinaryRequest) {
  18009. var data = Array.prototype.map.call(request.responseText, function (ch) {
  18010. return ch.charCodeAt(0) & 255;
  18011. });
  18012. return new Uint8Array(data);
  18013. }
  18014. return new Uint8Array(request.response);
  18015. }
  18016. function hexToInt(a, size) {
  18017. var n = 0;
  18018. for (var i = 0; i <= size; i++) {
  18019. n = (n << 8) | a[i];
  18020. }
  18021. return n >>> 0;
  18022. }
  18023. function hexToStr(a, size) {
  18024. // This code is hot. Special-case some common values to avoid creating an
  18025. // object with subarray().
  18026. if (size === 1) {
  18027. return String.fromCharCode(a[0], a[1]);
  18028. }
  18029. if (size === 3) {
  18030. return String.fromCharCode(a[0], a[1], a[2], a[3]);
  18031. }
  18032. return String.fromCharCode.apply(null, a.subarray(0, size + 1));
  18033. }
  18034. function addHex(a, b, size) {
  18035. var c = 0;
  18036. for (var i = size; i >= 0; i--) {
  18037. c += a[i] + b[i];
  18038. a[i] = c & 255;
  18039. c >>= 8;
  18040. }
  18041. }
  18042. function incHex(a, size) {
  18043. var c = 1;
  18044. for (var i = size; i >= 0 && c > 0; i--) {
  18045. c += a[i];
  18046. a[i] = c & 255;
  18047. c >>= 8;
  18048. }
  18049. }
  18050. var MAX_NUM_SIZE = 16;
  18051. var MAX_ENCODED_NUM_SIZE = 19; // ceil(MAX_NUM_SIZE * 7 / 8)
  18052. function BinaryCMapStream(data) {
  18053. this.buffer = data;
  18054. this.pos = 0;
  18055. this.end = data.length;
  18056. this.tmpBuf = new Uint8Array(MAX_ENCODED_NUM_SIZE);
  18057. }
  18058. BinaryCMapStream.prototype = {
  18059. readByte: function () {
  18060. if (this.pos >= this.end) {
  18061. return -1;
  18062. }
  18063. return this.buffer[this.pos++];
  18064. },
  18065. readNumber: function () {
  18066. var n = 0;
  18067. var last;
  18068. do {
  18069. var b = this.readByte();
  18070. if (b < 0) {
  18071. error('unexpected EOF in bcmap');
  18072. }
  18073. last = !(b & 0x80);
  18074. n = (n << 7) | (b & 0x7F);
  18075. } while (!last);
  18076. return n;
  18077. },
  18078. readSigned: function () {
  18079. var n = this.readNumber();
  18080. return (n & 1) ? ~(n >>> 1) : n >>> 1;
  18081. },
  18082. readHex: function (num, size) {
  18083. num.set(this.buffer.subarray(this.pos,
  18084. this.pos + size + 1));
  18085. this.pos += size + 1;
  18086. },
  18087. readHexNumber: function (num, size) {
  18088. var last;
  18089. var stack = this.tmpBuf, sp = 0;
  18090. do {
  18091. var b = this.readByte();
  18092. if (b < 0) {
  18093. error('unexpected EOF in bcmap');
  18094. }
  18095. last = !(b & 0x80);
  18096. stack[sp++] = b & 0x7F;
  18097. } while (!last);
  18098. var i = size, buffer = 0, bufferSize = 0;
  18099. while (i >= 0) {
  18100. while (bufferSize < 8 && stack.length > 0) {
  18101. buffer = (stack[--sp] << bufferSize) | buffer;
  18102. bufferSize += 7;
  18103. }
  18104. num[i] = buffer & 255;
  18105. i--;
  18106. buffer >>= 8;
  18107. bufferSize -= 8;
  18108. }
  18109. },
  18110. readHexSigned: function (num, size) {
  18111. this.readHexNumber(num, size);
  18112. var sign = num[size] & 1 ? 255 : 0;
  18113. var c = 0;
  18114. for (var i = 0; i <= size; i++) {
  18115. c = ((c & 1) << 8) | num[i];
  18116. num[i] = (c >> 1) ^ sign;
  18117. }
  18118. },
  18119. readString: function () {
  18120. var len = this.readNumber();
  18121. var s = '';
  18122. for (var i = 0; i < len; i++) {
  18123. s += String.fromCharCode(this.readNumber());
  18124. }
  18125. return s;
  18126. }
  18127. };
  18128. function processBinaryCMap(url, cMap, extend) {
  18129. var data = fetchBinaryData(url);
  18130. var stream = new BinaryCMapStream(data);
  18131. var header = stream.readByte();
  18132. cMap.vertical = !!(header & 1);
  18133. var useCMap = null;
  18134. var start = new Uint8Array(MAX_NUM_SIZE);
  18135. var end = new Uint8Array(MAX_NUM_SIZE);
  18136. var char = new Uint8Array(MAX_NUM_SIZE);
  18137. var charCode = new Uint8Array(MAX_NUM_SIZE);
  18138. var tmp = new Uint8Array(MAX_NUM_SIZE);
  18139. var code;
  18140. var b;
  18141. while ((b = stream.readByte()) >= 0) {
  18142. var type = b >> 5;
  18143. if (type === 7) { // metadata, e.g. comment or usecmap
  18144. switch (b & 0x1F) {
  18145. case 0:
  18146. stream.readString(); // skipping comment
  18147. break;
  18148. case 1:
  18149. useCMap = stream.readString();
  18150. break;
  18151. }
  18152. continue;
  18153. }
  18154. var sequence = !!(b & 0x10);
  18155. var dataSize = b & 15;
  18156. assert(dataSize + 1 <= MAX_NUM_SIZE);
  18157. var ucs2DataSize = 1;
  18158. var subitemsCount = stream.readNumber();
  18159. var i;
  18160. switch (type) {
  18161. case 0: // codespacerange
  18162. stream.readHex(start, dataSize);
  18163. stream.readHexNumber(end, dataSize);
  18164. addHex(end, start, dataSize);
  18165. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
  18166. hexToInt(end, dataSize));
  18167. for (i = 1; i < subitemsCount; i++) {
  18168. incHex(end, dataSize);
  18169. stream.readHexNumber(start, dataSize);
  18170. addHex(start, end, dataSize);
  18171. stream.readHexNumber(end, dataSize);
  18172. addHex(end, start, dataSize);
  18173. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
  18174. hexToInt(end, dataSize));
  18175. }
  18176. break;
  18177. case 1: // notdefrange
  18178. stream.readHex(start, dataSize);
  18179. stream.readHexNumber(end, dataSize);
  18180. addHex(end, start, dataSize);
  18181. code = stream.readNumber();
  18182. // undefined range, skipping
  18183. for (i = 1; i < subitemsCount; i++) {
  18184. incHex(end, dataSize);
  18185. stream.readHexNumber(start, dataSize);
  18186. addHex(start, end, dataSize);
  18187. stream.readHexNumber(end, dataSize);
  18188. addHex(end, start, dataSize);
  18189. code = stream.readNumber();
  18190. // nop
  18191. }
  18192. break;
  18193. case 2: // cidchar
  18194. stream.readHex(char, dataSize);
  18195. code = stream.readNumber();
  18196. cMap.mapOne(hexToInt(char, dataSize), code);
  18197. for (i = 1; i < subitemsCount; i++) {
  18198. incHex(char, dataSize);
  18199. if (!sequence) {
  18200. stream.readHexNumber(tmp, dataSize);
  18201. addHex(char, tmp, dataSize);
  18202. }
  18203. code = stream.readSigned() + (code + 1);
  18204. cMap.mapOne(hexToInt(char, dataSize), code);
  18205. }
  18206. break;
  18207. case 3: // cidrange
  18208. stream.readHex(start, dataSize);
  18209. stream.readHexNumber(end, dataSize);
  18210. addHex(end, start, dataSize);
  18211. code = stream.readNumber();
  18212. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize),
  18213. code);
  18214. for (i = 1; i < subitemsCount; i++) {
  18215. incHex(end, dataSize);
  18216. if (!sequence) {
  18217. stream.readHexNumber(start, dataSize);
  18218. addHex(start, end, dataSize);
  18219. } else {
  18220. start.set(end);
  18221. }
  18222. stream.readHexNumber(end, dataSize);
  18223. addHex(end, start, dataSize);
  18224. code = stream.readNumber();
  18225. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize),
  18226. code);
  18227. }
  18228. break;
  18229. case 4: // bfchar
  18230. stream.readHex(char, ucs2DataSize);
  18231. stream.readHex(charCode, dataSize);
  18232. cMap.mapOne(hexToInt(char, ucs2DataSize),
  18233. hexToStr(charCode, dataSize));
  18234. for (i = 1; i < subitemsCount; i++) {
  18235. incHex(char, ucs2DataSize);
  18236. if (!sequence) {
  18237. stream.readHexNumber(tmp, ucs2DataSize);
  18238. addHex(char, tmp, ucs2DataSize);
  18239. }
  18240. incHex(charCode, dataSize);
  18241. stream.readHexSigned(tmp, dataSize);
  18242. addHex(charCode, tmp, dataSize);
  18243. cMap.mapOne(hexToInt(char, ucs2DataSize),
  18244. hexToStr(charCode, dataSize));
  18245. }
  18246. break;
  18247. case 5: // bfrange
  18248. stream.readHex(start, ucs2DataSize);
  18249. stream.readHexNumber(end, ucs2DataSize);
  18250. addHex(end, start, ucs2DataSize);
  18251. stream.readHex(charCode, dataSize);
  18252. cMap.mapBfRange(hexToInt(start, ucs2DataSize),
  18253. hexToInt(end, ucs2DataSize),
  18254. hexToStr(charCode, dataSize));
  18255. for (i = 1; i < subitemsCount; i++) {
  18256. incHex(end, ucs2DataSize);
  18257. if (!sequence) {
  18258. stream.readHexNumber(start, ucs2DataSize);
  18259. addHex(start, end, ucs2DataSize);
  18260. } else {
  18261. start.set(end);
  18262. }
  18263. stream.readHexNumber(end, ucs2DataSize);
  18264. addHex(end, start, ucs2DataSize);
  18265. stream.readHex(charCode, dataSize);
  18266. cMap.mapBfRange(hexToInt(start, ucs2DataSize),
  18267. hexToInt(end, ucs2DataSize),
  18268. hexToStr(charCode, dataSize));
  18269. }
  18270. break;
  18271. default:
  18272. error('Unknown type: ' + type);
  18273. break;
  18274. }
  18275. }
  18276. if (useCMap) {
  18277. extend(useCMap);
  18278. }
  18279. return cMap;
  18280. }
  18281. function BinaryCMapReader() {}
  18282. BinaryCMapReader.prototype = {
  18283. read: processBinaryCMap
  18284. };
  18285. return BinaryCMapReader;
  18286. })();
  18287. var CMapFactory = (function CMapFactoryClosure() {
  18288. function strToInt(str) {
  18289. var a = 0;
  18290. for (var i = 0; i < str.length; i++) {
  18291. a = (a << 8) | str.charCodeAt(i);
  18292. }
  18293. return a >>> 0;
  18294. }
  18295. function expectString(obj) {
  18296. if (!isString(obj)) {
  18297. error('Malformed CMap: expected string.');
  18298. }
  18299. }
  18300. function expectInt(obj) {
  18301. if (!isInt(obj)) {
  18302. error('Malformed CMap: expected int.');
  18303. }
  18304. }
  18305. function parseBfChar(cMap, lexer) {
  18306. while (true) {
  18307. var obj = lexer.getObj();
  18308. if (isEOF(obj)) {
  18309. break;
  18310. }
  18311. if (isCmd(obj, 'endbfchar')) {
  18312. return;
  18313. }
  18314. expectString(obj);
  18315. var src = strToInt(obj);
  18316. obj = lexer.getObj();
  18317. // TODO are /dstName used?
  18318. expectString(obj);
  18319. var dst = obj;
  18320. cMap.mapOne(src, dst);
  18321. }
  18322. }
  18323. function parseBfRange(cMap, lexer) {
  18324. while (true) {
  18325. var obj = lexer.getObj();
  18326. if (isEOF(obj)) {
  18327. break;
  18328. }
  18329. if (isCmd(obj, 'endbfrange')) {
  18330. return;
  18331. }
  18332. expectString(obj);
  18333. var low = strToInt(obj);
  18334. obj = lexer.getObj();
  18335. expectString(obj);
  18336. var high = strToInt(obj);
  18337. obj = lexer.getObj();
  18338. if (isInt(obj) || isString(obj)) {
  18339. var dstLow = isInt(obj) ? String.fromCharCode(obj) : obj;
  18340. cMap.mapBfRange(low, high, dstLow);
  18341. } else if (isCmd(obj, '[')) {
  18342. obj = lexer.getObj();
  18343. var array = [];
  18344. while (!isCmd(obj, ']') && !isEOF(obj)) {
  18345. array.push(obj);
  18346. obj = lexer.getObj();
  18347. }
  18348. cMap.mapBfRangeToArray(low, high, array);
  18349. } else {
  18350. break;
  18351. }
  18352. }
  18353. error('Invalid bf range.');
  18354. }
  18355. function parseCidChar(cMap, lexer) {
  18356. while (true) {
  18357. var obj = lexer.getObj();
  18358. if (isEOF(obj)) {
  18359. break;
  18360. }
  18361. if (isCmd(obj, 'endcidchar')) {
  18362. return;
  18363. }
  18364. expectString(obj);
  18365. var src = strToInt(obj);
  18366. obj = lexer.getObj();
  18367. expectInt(obj);
  18368. var dst = obj;
  18369. cMap.mapOne(src, dst);
  18370. }
  18371. }
  18372. function parseCidRange(cMap, lexer) {
  18373. while (true) {
  18374. var obj = lexer.getObj();
  18375. if (isEOF(obj)) {
  18376. break;
  18377. }
  18378. if (isCmd(obj, 'endcidrange')) {
  18379. return;
  18380. }
  18381. expectString(obj);
  18382. var low = strToInt(obj);
  18383. obj = lexer.getObj();
  18384. expectString(obj);
  18385. var high = strToInt(obj);
  18386. obj = lexer.getObj();
  18387. expectInt(obj);
  18388. var dstLow = obj;
  18389. cMap.mapCidRange(low, high, dstLow);
  18390. }
  18391. }
  18392. function parseCodespaceRange(cMap, lexer) {
  18393. while (true) {
  18394. var obj = lexer.getObj();
  18395. if (isEOF(obj)) {
  18396. break;
  18397. }
  18398. if (isCmd(obj, 'endcodespacerange')) {
  18399. return;
  18400. }
  18401. if (!isString(obj)) {
  18402. break;
  18403. }
  18404. var low = strToInt(obj);
  18405. obj = lexer.getObj();
  18406. if (!isString(obj)) {
  18407. break;
  18408. }
  18409. var high = strToInt(obj);
  18410. cMap.addCodespaceRange(obj.length, low, high);
  18411. }
  18412. error('Invalid codespace range.');
  18413. }
  18414. function parseWMode(cMap, lexer) {
  18415. var obj = lexer.getObj();
  18416. if (isInt(obj)) {
  18417. cMap.vertical = !!obj;
  18418. }
  18419. }
  18420. function parseCMapName(cMap, lexer) {
  18421. var obj = lexer.getObj();
  18422. if (isName(obj) && isString(obj.name)) {
  18423. cMap.name = obj.name;
  18424. }
  18425. }
  18426. function parseCMap(cMap, lexer, builtInCMapParams, useCMap) {
  18427. var previous;
  18428. var embededUseCMap;
  18429. objLoop: while (true) {
  18430. var obj = lexer.getObj();
  18431. if (isEOF(obj)) {
  18432. break;
  18433. } else if (isName(obj)) {
  18434. if (obj.name === 'WMode') {
  18435. parseWMode(cMap, lexer);
  18436. } else if (obj.name === 'CMapName') {
  18437. parseCMapName(cMap, lexer);
  18438. }
  18439. previous = obj;
  18440. } else if (isCmd(obj)) {
  18441. switch (obj.cmd) {
  18442. case 'endcmap':
  18443. break objLoop;
  18444. case 'usecmap':
  18445. if (isName(previous)) {
  18446. embededUseCMap = previous.name;
  18447. }
  18448. break;
  18449. case 'begincodespacerange':
  18450. parseCodespaceRange(cMap, lexer);
  18451. break;
  18452. case 'beginbfchar':
  18453. parseBfChar(cMap, lexer);
  18454. break;
  18455. case 'begincidchar':
  18456. parseCidChar(cMap, lexer);
  18457. break;
  18458. case 'beginbfrange':
  18459. parseBfRange(cMap, lexer);
  18460. break;
  18461. case 'begincidrange':
  18462. parseCidRange(cMap, lexer);
  18463. break;
  18464. }
  18465. }
  18466. }
  18467. if (!useCMap && embededUseCMap) {
  18468. // Load the usecmap definition from the file only if there wasn't one
  18469. // specified.
  18470. useCMap = embededUseCMap;
  18471. }
  18472. if (useCMap) {
  18473. extendCMap(cMap, builtInCMapParams, useCMap);
  18474. }
  18475. }
  18476. function extendCMap(cMap, builtInCMapParams, useCMap) {
  18477. cMap.useCMap = createBuiltInCMap(useCMap, builtInCMapParams);
  18478. // If there aren't any code space ranges defined clone all the parent ones
  18479. // into this cMap.
  18480. if (cMap.numCodespaceRanges === 0) {
  18481. var useCodespaceRanges = cMap.useCMap.codespaceRanges;
  18482. for (var i = 0; i < useCodespaceRanges.length; i++) {
  18483. cMap.codespaceRanges[i] = useCodespaceRanges[i].slice();
  18484. }
  18485. cMap.numCodespaceRanges = cMap.useCMap.numCodespaceRanges;
  18486. }
  18487. // Merge the map into the current one, making sure not to override
  18488. // any previously defined entries.
  18489. cMap.useCMap.forEach(function(key, value) {
  18490. if (!cMap.contains(key)) {
  18491. cMap.mapOne(key, cMap.useCMap.lookup(key));
  18492. }
  18493. });
  18494. }
  18495. function parseBinaryCMap(name, builtInCMapParams) {
  18496. var url = builtInCMapParams.url + name + '.bcmap';
  18497. var cMap = new CMap(true);
  18498. new BinaryCMapReader().read(url, cMap, function (useCMap) {
  18499. extendCMap(cMap, builtInCMapParams, useCMap);
  18500. });
  18501. return cMap;
  18502. }
  18503. function createBuiltInCMap(name, builtInCMapParams) {
  18504. if (name === 'Identity-H') {
  18505. return new IdentityCMap(false, 2);
  18506. } else if (name === 'Identity-V') {
  18507. return new IdentityCMap(true, 2);
  18508. }
  18509. if (BUILT_IN_CMAPS.indexOf(name) === -1) {
  18510. error('Unknown cMap name: ' + name);
  18511. }
  18512. assert(builtInCMapParams, 'built-in cMap parameters are not provided');
  18513. if (builtInCMapParams.packed) {
  18514. return parseBinaryCMap(name, builtInCMapParams);
  18515. }
  18516. var request = new XMLHttpRequest();
  18517. var url = builtInCMapParams.url + name;
  18518. request.open('GET', url, false);
  18519. request.send(null);
  18520. if (!request.responseText) {
  18521. error('Unable to get cMap at: ' + url);
  18522. }
  18523. var cMap = new CMap(true);
  18524. var lexer = new Lexer(new StringStream(request.responseText));
  18525. parseCMap(cMap, lexer, builtInCMapParams, null);
  18526. return cMap;
  18527. }
  18528. return {
  18529. create: function (encoding, builtInCMapParams, useCMap) {
  18530. if (isName(encoding)) {
  18531. return createBuiltInCMap(encoding.name, builtInCMapParams);
  18532. } else if (isStream(encoding)) {
  18533. var cMap = new CMap();
  18534. var lexer = new Lexer(encoding);
  18535. try {
  18536. parseCMap(cMap, lexer, builtInCMapParams, useCMap);
  18537. } catch (e) {
  18538. warn('Invalid CMap data. ' + e);
  18539. }
  18540. if (cMap.isIdentityCMap) {
  18541. return createBuiltInCMap(cMap.name, builtInCMapParams);
  18542. }
  18543. return cMap;
  18544. }
  18545. error('Encoding required.');
  18546. }
  18547. };
  18548. })();
  18549. // Unicode Private Use Area
  18550. var PRIVATE_USE_OFFSET_START = 0xE000;
  18551. var PRIVATE_USE_OFFSET_END = 0xF8FF;
  18552. var SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = false;
  18553. // PDF Glyph Space Units are one Thousandth of a TextSpace Unit
  18554. // except for Type 3 fonts
  18555. var PDF_GLYPH_SPACE_UNITS = 1000;
  18556. // Hinting is currently disabled due to unknown problems on windows
  18557. // in tracemonkey and various other pdfs with type1 fonts.
  18558. var HINTING_ENABLED = false;
  18559. // Accented charactars are not displayed properly on windows, using this flag
  18560. // to control analysis of seac charstrings.
  18561. var SEAC_ANALYSIS_ENABLED = false;
  18562. var FontFlags = {
  18563. FixedPitch: 1,
  18564. Serif: 2,
  18565. Symbolic: 4,
  18566. Script: 8,
  18567. Nonsymbolic: 32,
  18568. Italic: 64,
  18569. AllCap: 65536,
  18570. SmallCap: 131072,
  18571. ForceBold: 262144
  18572. };
  18573. var Encodings = {
  18574. ExpertEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18575. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18576. 'space', 'exclamsmall', 'Hungarumlautsmall', '', 'dollaroldstyle',
  18577. 'dollarsuperior', 'ampersandsmall', 'Acutesmall', 'parenleftsuperior',
  18578. 'parenrightsuperior', 'twodotenleader', 'onedotenleader', 'comma',
  18579. 'hyphen', 'period', 'fraction', 'zerooldstyle', 'oneoldstyle',
  18580. 'twooldstyle', 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle',
  18581. 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle', 'colon',
  18582. 'semicolon', 'commasuperior', 'threequartersemdash', 'periodsuperior',
  18583. 'questionsmall', '', 'asuperior', 'bsuperior', 'centsuperior', 'dsuperior',
  18584. 'esuperior', '', '', 'isuperior', '', '', 'lsuperior', 'msuperior',
  18585. 'nsuperior', 'osuperior', '', '', 'rsuperior', 'ssuperior', 'tsuperior',
  18586. '', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior', '',
  18587. 'parenrightinferior', 'Circumflexsmall', 'hyphensuperior', 'Gravesmall',
  18588. 'Asmall', 'Bsmall', 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall',
  18589. 'Hsmall', 'Ismall', 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall',
  18590. 'Osmall', 'Psmall', 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall',
  18591. 'Vsmall', 'Wsmall', 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary',
  18592. 'onefitted', 'rupiah', 'Tildesmall', '', '', '', '', '', '', '', '', '',
  18593. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18594. '', '', '', '', '', '', 'exclamdownsmall', 'centoldstyle', 'Lslashsmall',
  18595. '', '', 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall', 'Brevesmall',
  18596. 'Caronsmall', '', 'Dotaccentsmall', '', '', 'Macronsmall', '', '',
  18597. 'figuredash', 'hypheninferior', '', '', 'Ogoneksmall', 'Ringsmall',
  18598. 'Cedillasmall', '', '', '', 'onequarter', 'onehalf', 'threequarters',
  18599. 'questiondownsmall', 'oneeighth', 'threeeighths', 'fiveeighths',
  18600. 'seveneighths', 'onethird', 'twothirds', '', '', 'zerosuperior',
  18601. 'onesuperior', 'twosuperior', 'threesuperior', 'foursuperior',
  18602. 'fivesuperior', 'sixsuperior', 'sevensuperior', 'eightsuperior',
  18603. 'ninesuperior', 'zeroinferior', 'oneinferior', 'twoinferior',
  18604. 'threeinferior', 'fourinferior', 'fiveinferior', 'sixinferior',
  18605. 'seveninferior', 'eightinferior', 'nineinferior', 'centinferior',
  18606. 'dollarinferior', 'periodinferior', 'commainferior', 'Agravesmall',
  18607. 'Aacutesmall', 'Acircumflexsmall', 'Atildesmall', 'Adieresissmall',
  18608. 'Aringsmall', 'AEsmall', 'Ccedillasmall', 'Egravesmall', 'Eacutesmall',
  18609. 'Ecircumflexsmall', 'Edieresissmall', 'Igravesmall', 'Iacutesmall',
  18610. 'Icircumflexsmall', 'Idieresissmall', 'Ethsmall', 'Ntildesmall',
  18611. 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall', 'Otildesmall',
  18612. 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall', 'Uacutesmall',
  18613. 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall', 'Thornsmall',
  18614. 'Ydieresissmall'],
  18615. MacExpertEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18616. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18617. 'space', 'exclamsmall', 'Hungarumlautsmall', 'centoldstyle',
  18618. 'dollaroldstyle', 'dollarsuperior', 'ampersandsmall', 'Acutesmall',
  18619. 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  18620. 'onedotenleader', 'comma', 'hyphen', 'period', 'fraction', 'zerooldstyle',
  18621. 'oneoldstyle', 'twooldstyle', 'threeoldstyle', 'fouroldstyle',
  18622. 'fiveoldstyle', 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle',
  18623. 'nineoldstyle', 'colon', 'semicolon', '', 'threequartersemdash', '',
  18624. 'questionsmall', '', '', '', '', 'Ethsmall', '', '', 'onequarter',
  18625. 'onehalf', 'threequarters', 'oneeighth', 'threeeighths', 'fiveeighths',
  18626. 'seveneighths', 'onethird', 'twothirds', '', '', '', '', '', '', 'ff',
  18627. 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior', '', 'parenrightinferior',
  18628. 'Circumflexsmall', 'hypheninferior', 'Gravesmall', 'Asmall', 'Bsmall',
  18629. 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall', 'Hsmall', 'Ismall',
  18630. 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall', 'Osmall', 'Psmall',
  18631. 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall', 'Vsmall', 'Wsmall',
  18632. 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary', 'onefitted', 'rupiah',
  18633. 'Tildesmall', '', '', 'asuperior', 'centsuperior', '', '', '', '',
  18634. 'Aacutesmall', 'Agravesmall', 'Acircumflexsmall', 'Adieresissmall',
  18635. 'Atildesmall', 'Aringsmall', 'Ccedillasmall', 'Eacutesmall', 'Egravesmall',
  18636. 'Ecircumflexsmall', 'Edieresissmall', 'Iacutesmall', 'Igravesmall',
  18637. 'Icircumflexsmall', 'Idieresissmall', 'Ntildesmall', 'Oacutesmall',
  18638. 'Ogravesmall', 'Ocircumflexsmall', 'Odieresissmall', 'Otildesmall',
  18639. 'Uacutesmall', 'Ugravesmall', 'Ucircumflexsmall', 'Udieresissmall', '',
  18640. 'eightsuperior', 'fourinferior', 'threeinferior', 'sixinferior',
  18641. 'eightinferior', 'seveninferior', 'Scaronsmall', '', 'centinferior',
  18642. 'twoinferior', '', 'Dieresissmall', '', 'Caronsmall', 'osuperior',
  18643. 'fiveinferior', '', 'commainferior', 'periodinferior', 'Yacutesmall', '',
  18644. 'dollarinferior', '', 'Thornsmall', '', 'nineinferior', 'zeroinferior',
  18645. 'Zcaronsmall', 'AEsmall', 'Oslashsmall', 'questiondownsmall',
  18646. 'oneinferior', 'Lslashsmall', '', '', '', '', '', '', 'Cedillasmall', '',
  18647. '', '', '', '', 'OEsmall', 'figuredash', 'hyphensuperior', '', '', '', '',
  18648. 'exclamdownsmall', '', 'Ydieresissmall', '', 'onesuperior', 'twosuperior',
  18649. 'threesuperior', 'foursuperior', 'fivesuperior', 'sixsuperior',
  18650. 'sevensuperior', 'ninesuperior', 'zerosuperior', '', 'esuperior',
  18651. 'rsuperior', 'tsuperior', '', '', 'isuperior', 'ssuperior', 'dsuperior',
  18652. '', '', '', '', '', 'lsuperior', 'Ogoneksmall', 'Brevesmall',
  18653. 'Macronsmall', 'bsuperior', 'nsuperior', 'msuperior', 'commasuperior',
  18654. 'periodsuperior', 'Dotaccentsmall', 'Ringsmall'],
  18655. MacRomanEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18656. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18657. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  18658. 'ampersand', 'quotesingle', 'parenleft', 'parenright', 'asterisk', 'plus',
  18659. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  18660. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  18661. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  18662. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  18663. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  18664. 'asciicircum', 'underscore', 'grave', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
  18665. 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
  18666. 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde', '',
  18667. 'Adieresis', 'Aring', 'Ccedilla', 'Eacute', 'Ntilde', 'Odieresis',
  18668. 'Udieresis', 'aacute', 'agrave', 'acircumflex', 'adieresis', 'atilde',
  18669. 'aring', 'ccedilla', 'eacute', 'egrave', 'ecircumflex', 'edieresis',
  18670. 'iacute', 'igrave', 'icircumflex', 'idieresis', 'ntilde', 'oacute',
  18671. 'ograve', 'ocircumflex', 'odieresis', 'otilde', 'uacute', 'ugrave',
  18672. 'ucircumflex', 'udieresis', 'dagger', 'degree', 'cent', 'sterling',
  18673. 'section', 'bullet', 'paragraph', 'germandbls', 'registered', 'copyright',
  18674. 'trademark', 'acute', 'dieresis', 'notequal', 'AE', 'Oslash', 'infinity',
  18675. 'plusminus', 'lessequal', 'greaterequal', 'yen', 'mu', 'partialdiff',
  18676. 'summation', 'product', 'pi', 'integral', 'ordfeminine', 'ordmasculine',
  18677. 'Omega', 'ae', 'oslash', 'questiondown', 'exclamdown', 'logicalnot',
  18678. 'radical', 'florin', 'approxequal', 'Delta', 'guillemotleft',
  18679. 'guillemotright', 'ellipsis', 'space', 'Agrave', 'Atilde', 'Otilde', 'OE',
  18680. 'oe', 'endash', 'emdash', 'quotedblleft', 'quotedblright', 'quoteleft',
  18681. 'quoteright', 'divide', 'lozenge', 'ydieresis', 'Ydieresis', 'fraction',
  18682. 'currency', 'guilsinglleft', 'guilsinglright', 'fi', 'fl', 'daggerdbl',
  18683. 'periodcentered', 'quotesinglbase', 'quotedblbase', 'perthousand',
  18684. 'Acircumflex', 'Ecircumflex', 'Aacute', 'Edieresis', 'Egrave', 'Iacute',
  18685. 'Icircumflex', 'Idieresis', 'Igrave', 'Oacute', 'Ocircumflex', 'apple',
  18686. 'Ograve', 'Uacute', 'Ucircumflex', 'Ugrave', 'dotlessi', 'circumflex',
  18687. 'tilde', 'macron', 'breve', 'dotaccent', 'ring', 'cedilla', 'hungarumlaut',
  18688. 'ogonek', 'caron'],
  18689. StandardEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18690. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18691. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  18692. 'ampersand', 'quoteright', 'parenleft', 'parenright', 'asterisk', 'plus',
  18693. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  18694. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  18695. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  18696. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  18697. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  18698. 'asciicircum', 'underscore', 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f',
  18699. 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u',
  18700. 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde',
  18701. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18702. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', 'exclamdown',
  18703. 'cent', 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  18704. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  18705. 'guilsinglright', 'fi', 'fl', '', 'endash', 'dagger', 'daggerdbl',
  18706. 'periodcentered', '', 'paragraph', 'bullet', 'quotesinglbase',
  18707. 'quotedblbase', 'quotedblright', 'guillemotright', 'ellipsis',
  18708. 'perthousand', '', 'questiondown', '', 'grave', 'acute', 'circumflex',
  18709. 'tilde', 'macron', 'breve', 'dotaccent', 'dieresis', '', 'ring', 'cedilla',
  18710. '', 'hungarumlaut', 'ogonek', 'caron', 'emdash', '', '', '', '', '', '',
  18711. '', '', '', '', '', '', '', '', '', '', 'AE', '', 'ordfeminine', '', '',
  18712. '', '', 'Lslash', 'Oslash', 'OE', 'ordmasculine', '', '', '', '', '', 'ae',
  18713. '', '', '', 'dotlessi', '', '', 'lslash', 'oslash', 'oe', 'germandbls'],
  18714. WinAnsiEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18715. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18716. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  18717. 'ampersand', 'quotesingle', 'parenleft', 'parenright', 'asterisk', 'plus',
  18718. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  18719. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  18720. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  18721. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  18722. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  18723. 'asciicircum', 'underscore', 'grave', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
  18724. 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
  18725. 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde',
  18726. 'bullet', 'Euro', 'bullet', 'quotesinglbase', 'florin', 'quotedblbase',
  18727. 'ellipsis', 'dagger', 'daggerdbl', 'circumflex', 'perthousand', 'Scaron',
  18728. 'guilsinglleft', 'OE', 'bullet', 'Zcaron', 'bullet', 'bullet', 'quoteleft',
  18729. 'quoteright', 'quotedblleft', 'quotedblright', 'bullet', 'endash',
  18730. 'emdash', 'tilde', 'trademark', 'scaron', 'guilsinglright', 'oe', 'bullet',
  18731. 'zcaron', 'Ydieresis', 'space', 'exclamdown', 'cent', 'sterling',
  18732. 'currency', 'yen', 'brokenbar', 'section', 'dieresis', 'copyright',
  18733. 'ordfeminine', 'guillemotleft', 'logicalnot', 'hyphen', 'registered',
  18734. 'macron', 'degree', 'plusminus', 'twosuperior', 'threesuperior', 'acute',
  18735. 'mu', 'paragraph', 'periodcentered', 'cedilla', 'onesuperior',
  18736. 'ordmasculine', 'guillemotright', 'onequarter', 'onehalf', 'threequarters',
  18737. 'questiondown', 'Agrave', 'Aacute', 'Acircumflex', 'Atilde', 'Adieresis',
  18738. 'Aring', 'AE', 'Ccedilla', 'Egrave', 'Eacute', 'Ecircumflex', 'Edieresis',
  18739. 'Igrave', 'Iacute', 'Icircumflex', 'Idieresis', 'Eth', 'Ntilde', 'Ograve',
  18740. 'Oacute', 'Ocircumflex', 'Otilde', 'Odieresis', 'multiply', 'Oslash',
  18741. 'Ugrave', 'Uacute', 'Ucircumflex', 'Udieresis', 'Yacute', 'Thorn',
  18742. 'germandbls', 'agrave', 'aacute', 'acircumflex', 'atilde', 'adieresis',
  18743. 'aring', 'ae', 'ccedilla', 'egrave', 'eacute', 'ecircumflex', 'edieresis',
  18744. 'igrave', 'iacute', 'icircumflex', 'idieresis', 'eth', 'ntilde', 'ograve',
  18745. 'oacute', 'ocircumflex', 'otilde', 'odieresis', 'divide', 'oslash',
  18746. 'ugrave', 'uacute', 'ucircumflex', 'udieresis', 'yacute', 'thorn',
  18747. 'ydieresis'],
  18748. SymbolSetEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18749. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18750. 'space', 'exclam', 'universal', 'numbersign', 'existential', 'percent',
  18751. 'ampersand', 'suchthat', 'parenleft', 'parenright', 'asteriskmath', 'plus',
  18752. 'comma', 'minus', 'period', 'slash', 'zero', 'one', 'two', 'three', 'four',
  18753. 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon', 'less',
  18754. 'equal', 'greater', 'question', 'congruent', 'Alpha', 'Beta', 'Chi',
  18755. 'Delta', 'Epsilon', 'Phi', 'Gamma', 'Eta', 'Iota', 'theta1', 'Kappa',
  18756. 'Lambda', 'Mu', 'Nu', 'Omicron', 'Pi', 'Theta', 'Rho', 'Sigma', 'Tau',
  18757. 'Upsilon', 'sigma1', 'Omega', 'Xi', 'Psi', 'Zeta', 'bracketleft',
  18758. 'therefore', 'bracketright', 'perpendicular', 'underscore', 'radicalex',
  18759. 'alpha', 'beta', 'chi', 'delta', 'epsilon', 'phi', 'gamma', 'eta', 'iota',
  18760. 'phi1', 'kappa', 'lambda', 'mu', 'nu', 'omicron', 'pi', 'theta', 'rho',
  18761. 'sigma', 'tau', 'upsilon', 'omega1', 'omega', 'xi', 'psi', 'zeta',
  18762. 'braceleft', 'bar', 'braceright', 'similar', '', '', '', '', '', '', '',
  18763. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18764. '', '', '', '', '', '', '', 'Euro', 'Upsilon1', 'minute', 'lessequal',
  18765. 'fraction', 'infinity', 'florin', 'club', 'diamond', 'heart', 'spade',
  18766. 'arrowboth', 'arrowleft', 'arrowup', 'arrowright', 'arrowdown', 'degree',
  18767. 'plusminus', 'second', 'greaterequal', 'multiply', 'proportional',
  18768. 'partialdiff', 'bullet', 'divide', 'notequal', 'equivalence',
  18769. 'approxequal', 'ellipsis', 'arrowvertex', 'arrowhorizex', 'carriagereturn',
  18770. 'aleph', 'Ifraktur', 'Rfraktur', 'weierstrass', 'circlemultiply',
  18771. 'circleplus', 'emptyset', 'intersection', 'union', 'propersuperset',
  18772. 'reflexsuperset', 'notsubset', 'propersubset', 'reflexsubset', 'element',
  18773. 'notelement', 'angle', 'gradient', 'registerserif', 'copyrightserif',
  18774. 'trademarkserif', 'product', 'radical', 'dotmath', 'logicalnot',
  18775. 'logicaland', 'logicalor', 'arrowdblboth', 'arrowdblleft', 'arrowdblup',
  18776. 'arrowdblright', 'arrowdbldown', 'lozenge', 'angleleft', 'registersans',
  18777. 'copyrightsans', 'trademarksans', 'summation', 'parenlefttp',
  18778. 'parenleftex', 'parenleftbt', 'bracketlefttp', 'bracketleftex',
  18779. 'bracketleftbt', 'bracelefttp', 'braceleftmid', 'braceleftbt', 'braceex',
  18780. '', 'angleright', 'integral', 'integraltp', 'integralex', 'integralbt',
  18781. 'parenrighttp', 'parenrightex', 'parenrightbt', 'bracketrighttp',
  18782. 'bracketrightex', 'bracketrightbt', 'bracerighttp', 'bracerightmid',
  18783. 'bracerightbt'],
  18784. ZapfDingbatsEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18785. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18786. 'space', 'a1', 'a2', 'a202', 'a3', 'a4', 'a5', 'a119', 'a118', 'a117',
  18787. 'a11', 'a12', 'a13', 'a14', 'a15', 'a16', 'a105', 'a17', 'a18', 'a19',
  18788. 'a20', 'a21', 'a22', 'a23', 'a24', 'a25', 'a26', 'a27', 'a28', 'a6', 'a7',
  18789. 'a8', 'a9', 'a10', 'a29', 'a30', 'a31', 'a32', 'a33', 'a34', 'a35', 'a36',
  18790. 'a37', 'a38', 'a39', 'a40', 'a41', 'a42', 'a43', 'a44', 'a45', 'a46',
  18791. 'a47', 'a48', 'a49', 'a50', 'a51', 'a52', 'a53', 'a54', 'a55', 'a56',
  18792. 'a57', 'a58', 'a59', 'a60', 'a61', 'a62', 'a63', 'a64', 'a65', 'a66',
  18793. 'a67', 'a68', 'a69', 'a70', 'a71', 'a72', 'a73', 'a74', 'a203', 'a75',
  18794. 'a204', 'a76', 'a77', 'a78', 'a79', 'a81', 'a82', 'a83', 'a84', 'a97',
  18795. 'a98', 'a99', 'a100', '', 'a89', 'a90', 'a93', 'a94', 'a91', 'a92', 'a205',
  18796. 'a85', 'a206', 'a86', 'a87', 'a88', 'a95', 'a96', '', '', '', '', '', '',
  18797. '', '', '', '', '', '', '', '', '', '', '', '', '', 'a101', 'a102', 'a103',
  18798. 'a104', 'a106', 'a107', 'a108', 'a112', 'a111', 'a110', 'a109', 'a120',
  18799. 'a121', 'a122', 'a123', 'a124', 'a125', 'a126', 'a127', 'a128', 'a129',
  18800. 'a130', 'a131', 'a132', 'a133', 'a134', 'a135', 'a136', 'a137', 'a138',
  18801. 'a139', 'a140', 'a141', 'a142', 'a143', 'a144', 'a145', 'a146', 'a147',
  18802. 'a148', 'a149', 'a150', 'a151', 'a152', 'a153', 'a154', 'a155', 'a156',
  18803. 'a157', 'a158', 'a159', 'a160', 'a161', 'a163', 'a164', 'a196', 'a165',
  18804. 'a192', 'a166', 'a167', 'a168', 'a169', 'a170', 'a171', 'a172', 'a173',
  18805. 'a162', 'a174', 'a175', 'a176', 'a177', 'a178', 'a179', 'a193', 'a180',
  18806. 'a199', 'a181', 'a200', 'a182', '', 'a201', 'a183', 'a184', 'a197', 'a185',
  18807. 'a194', 'a198', 'a186', 'a195', 'a187', 'a188', 'a189', 'a190', 'a191']
  18808. };
  18809. /**
  18810. * Hold a map of decoded fonts and of the standard fourteen Type1
  18811. * fonts and their acronyms.
  18812. */
  18813. var stdFontMap = {
  18814. 'ArialNarrow': 'Helvetica',
  18815. 'ArialNarrow-Bold': 'Helvetica-Bold',
  18816. 'ArialNarrow-BoldItalic': 'Helvetica-BoldOblique',
  18817. 'ArialNarrow-Italic': 'Helvetica-Oblique',
  18818. 'ArialBlack': 'Helvetica',
  18819. 'ArialBlack-Bold': 'Helvetica-Bold',
  18820. 'ArialBlack-BoldItalic': 'Helvetica-BoldOblique',
  18821. 'ArialBlack-Italic': 'Helvetica-Oblique',
  18822. 'Arial': 'Helvetica',
  18823. 'Arial-Bold': 'Helvetica-Bold',
  18824. 'Arial-BoldItalic': 'Helvetica-BoldOblique',
  18825. 'Arial-Italic': 'Helvetica-Oblique',
  18826. 'Arial-BoldItalicMT': 'Helvetica-BoldOblique',
  18827. 'Arial-BoldMT': 'Helvetica-Bold',
  18828. 'Arial-ItalicMT': 'Helvetica-Oblique',
  18829. 'ArialMT': 'Helvetica',
  18830. 'Courier-Bold': 'Courier-Bold',
  18831. 'Courier-BoldItalic': 'Courier-BoldOblique',
  18832. 'Courier-Italic': 'Courier-Oblique',
  18833. 'CourierNew': 'Courier',
  18834. 'CourierNew-Bold': 'Courier-Bold',
  18835. 'CourierNew-BoldItalic': 'Courier-BoldOblique',
  18836. 'CourierNew-Italic': 'Courier-Oblique',
  18837. 'CourierNewPS-BoldItalicMT': 'Courier-BoldOblique',
  18838. 'CourierNewPS-BoldMT': 'Courier-Bold',
  18839. 'CourierNewPS-ItalicMT': 'Courier-Oblique',
  18840. 'CourierNewPSMT': 'Courier',
  18841. 'Helvetica': 'Helvetica',
  18842. 'Helvetica-Bold': 'Helvetica-Bold',
  18843. 'Helvetica-BoldItalic': 'Helvetica-BoldOblique',
  18844. 'Helvetica-BoldOblique': 'Helvetica-BoldOblique',
  18845. 'Helvetica-Italic': 'Helvetica-Oblique',
  18846. 'Helvetica-Oblique':'Helvetica-Oblique',
  18847. 'Symbol-Bold': 'Symbol',
  18848. 'Symbol-BoldItalic': 'Symbol',
  18849. 'Symbol-Italic': 'Symbol',
  18850. 'TimesNewRoman': 'Times-Roman',
  18851. 'TimesNewRoman-Bold': 'Times-Bold',
  18852. 'TimesNewRoman-BoldItalic': 'Times-BoldItalic',
  18853. 'TimesNewRoman-Italic': 'Times-Italic',
  18854. 'TimesNewRomanPS': 'Times-Roman',
  18855. 'TimesNewRomanPS-Bold': 'Times-Bold',
  18856. 'TimesNewRomanPS-BoldItalic': 'Times-BoldItalic',
  18857. 'TimesNewRomanPS-BoldItalicMT': 'Times-BoldItalic',
  18858. 'TimesNewRomanPS-BoldMT': 'Times-Bold',
  18859. 'TimesNewRomanPS-Italic': 'Times-Italic',
  18860. 'TimesNewRomanPS-ItalicMT': 'Times-Italic',
  18861. 'TimesNewRomanPSMT': 'Times-Roman',
  18862. 'TimesNewRomanPSMT-Bold': 'Times-Bold',
  18863. 'TimesNewRomanPSMT-BoldItalic': 'Times-BoldItalic',
  18864. 'TimesNewRomanPSMT-Italic': 'Times-Italic'
  18865. };
  18866. /**
  18867. * Holds the map of the non-standard fonts that might be included as a standard
  18868. * fonts without glyph data.
  18869. */
  18870. var nonStdFontMap = {
  18871. 'CenturyGothic': 'Helvetica',
  18872. 'CenturyGothic-Bold': 'Helvetica-Bold',
  18873. 'CenturyGothic-BoldItalic': 'Helvetica-BoldOblique',
  18874. 'CenturyGothic-Italic': 'Helvetica-Oblique',
  18875. 'ComicSansMS': 'Comic Sans MS',
  18876. 'ComicSansMS-Bold': 'Comic Sans MS-Bold',
  18877. 'ComicSansMS-BoldItalic': 'Comic Sans MS-BoldItalic',
  18878. 'ComicSansMS-Italic': 'Comic Sans MS-Italic',
  18879. 'LucidaConsole': 'Courier',
  18880. 'LucidaConsole-Bold': 'Courier-Bold',
  18881. 'LucidaConsole-BoldItalic': 'Courier-BoldOblique',
  18882. 'LucidaConsole-Italic': 'Courier-Oblique',
  18883. 'MS-Gothic': 'MS Gothic',
  18884. 'MS-Gothic-Bold': 'MS Gothic-Bold',
  18885. 'MS-Gothic-BoldItalic': 'MS Gothic-BoldItalic',
  18886. 'MS-Gothic-Italic': 'MS Gothic-Italic',
  18887. 'MS-Mincho': 'MS Mincho',
  18888. 'MS-Mincho-Bold': 'MS Mincho-Bold',
  18889. 'MS-Mincho-BoldItalic': 'MS Mincho-BoldItalic',
  18890. 'MS-Mincho-Italic': 'MS Mincho-Italic',
  18891. 'MS-PGothic': 'MS PGothic',
  18892. 'MS-PGothic-Bold': 'MS PGothic-Bold',
  18893. 'MS-PGothic-BoldItalic': 'MS PGothic-BoldItalic',
  18894. 'MS-PGothic-Italic': 'MS PGothic-Italic',
  18895. 'MS-PMincho': 'MS PMincho',
  18896. 'MS-PMincho-Bold': 'MS PMincho-Bold',
  18897. 'MS-PMincho-BoldItalic': 'MS PMincho-BoldItalic',
  18898. 'MS-PMincho-Italic': 'MS PMincho-Italic',
  18899. 'Wingdings': 'ZapfDingbats'
  18900. };
  18901. var serifFonts = {
  18902. 'Adobe Jenson': true, 'Adobe Text': true, 'Albertus': true,
  18903. 'Aldus': true, 'Alexandria': true, 'Algerian': true,
  18904. 'American Typewriter': true, 'Antiqua': true, 'Apex': true,
  18905. 'Arno': true, 'Aster': true, 'Aurora': true,
  18906. 'Baskerville': true, 'Bell': true, 'Bembo': true,
  18907. 'Bembo Schoolbook': true, 'Benguiat': true, 'Berkeley Old Style': true,
  18908. 'Bernhard Modern': true, 'Berthold City': true, 'Bodoni': true,
  18909. 'Bauer Bodoni': true, 'Book Antiqua': true, 'Bookman': true,
  18910. 'Bordeaux Roman': true, 'Californian FB': true, 'Calisto': true,
  18911. 'Calvert': true, 'Capitals': true, 'Cambria': true,
  18912. 'Cartier': true, 'Caslon': true, 'Catull': true,
  18913. 'Centaur': true, 'Century Old Style': true, 'Century Schoolbook': true,
  18914. 'Chaparral': true, 'Charis SIL': true, 'Cheltenham': true,
  18915. 'Cholla Slab': true, 'Clarendon': true, 'Clearface': true,
  18916. 'Cochin': true, 'Colonna': true, 'Computer Modern': true,
  18917. 'Concrete Roman': true, 'Constantia': true, 'Cooper Black': true,
  18918. 'Corona': true, 'Ecotype': true, 'Egyptienne': true,
  18919. 'Elephant': true, 'Excelsior': true, 'Fairfield': true,
  18920. 'FF Scala': true, 'Folkard': true, 'Footlight': true,
  18921. 'FreeSerif': true, 'Friz Quadrata': true, 'Garamond': true,
  18922. 'Gentium': true, 'Georgia': true, 'Gloucester': true,
  18923. 'Goudy Old Style': true, 'Goudy Schoolbook': true, 'Goudy Pro Font': true,
  18924. 'Granjon': true, 'Guardian Egyptian': true, 'Heather': true,
  18925. 'Hercules': true, 'High Tower Text': true, 'Hiroshige': true,
  18926. 'Hoefler Text': true, 'Humana Serif': true, 'Imprint': true,
  18927. 'Ionic No. 5': true, 'Janson': true, 'Joanna': true,
  18928. 'Korinna': true, 'Lexicon': true, 'Liberation Serif': true,
  18929. 'Linux Libertine': true, 'Literaturnaya': true, 'Lucida': true,
  18930. 'Lucida Bright': true, 'Melior': true, 'Memphis': true,
  18931. 'Miller': true, 'Minion': true, 'Modern': true,
  18932. 'Mona Lisa': true, 'Mrs Eaves': true, 'MS Serif': true,
  18933. 'Museo Slab': true, 'New York': true, 'Nimbus Roman': true,
  18934. 'NPS Rawlinson Roadway': true, 'Palatino': true, 'Perpetua': true,
  18935. 'Plantin': true, 'Plantin Schoolbook': true, 'Playbill': true,
  18936. 'Poor Richard': true, 'Rawlinson Roadway': true, 'Renault': true,
  18937. 'Requiem': true, 'Rockwell': true, 'Roman': true,
  18938. 'Rotis Serif': true, 'Sabon': true, 'Scala': true,
  18939. 'Seagull': true, 'Sistina': true, 'Souvenir': true,
  18940. 'STIX': true, 'Stone Informal': true, 'Stone Serif': true,
  18941. 'Sylfaen': true, 'Times': true, 'Trajan': true,
  18942. 'Trinité': true, 'Trump Mediaeval': true, 'Utopia': true,
  18943. 'Vale Type': true, 'Bitstream Vera': true, 'Vera Serif': true,
  18944. 'Versailles': true, 'Wanted': true, 'Weiss': true,
  18945. 'Wide Latin': true, 'Windsor': true, 'XITS': true
  18946. };
  18947. var symbolsFonts = {
  18948. 'Dingbats': true, 'Symbol': true, 'ZapfDingbats': true
  18949. };
  18950. // Glyph map for well-known standard fonts. Sometimes Ghostscript uses CID fonts
  18951. // but does not embed the CID to GID mapping. The mapping is incomplete for all
  18952. // glyphs, but common for some set of the standard fonts.
  18953. var GlyphMapForStandardFonts = {
  18954. '2': 10, '3': 32, '4': 33, '5': 34, '6': 35, '7': 36, '8': 37, '9': 38,
  18955. '10': 39, '11': 40, '12': 41, '13': 42, '14': 43, '15': 44, '16': 45,
  18956. '17': 46, '18': 47, '19': 48, '20': 49, '21': 50, '22': 51, '23': 52,
  18957. '24': 53, '25': 54, '26': 55, '27': 56, '28': 57, '29': 58, '30': 894,
  18958. '31': 60, '32': 61, '33': 62, '34': 63, '35': 64, '36': 65, '37': 66,
  18959. '38': 67, '39': 68, '40': 69, '41': 70, '42': 71, '43': 72, '44': 73,
  18960. '45': 74, '46': 75, '47': 76, '48': 77, '49': 78, '50': 79, '51': 80,
  18961. '52': 81, '53': 82, '54': 83, '55': 84, '56': 85, '57': 86, '58': 87,
  18962. '59': 88, '60': 89, '61': 90, '62': 91, '63': 92, '64': 93, '65': 94,
  18963. '66': 95, '67': 96, '68': 97, '69': 98, '70': 99, '71': 100, '72': 101,
  18964. '73': 102, '74': 103, '75': 104, '76': 105, '77': 106, '78': 107, '79': 108,
  18965. '80': 109, '81': 110, '82': 111, '83': 112, '84': 113, '85': 114, '86': 115,
  18966. '87': 116, '88': 117, '89': 118, '90': 119, '91': 120, '92': 121, '93': 122,
  18967. '94': 123, '95': 124, '96': 125, '97': 126, '98': 196, '99': 197, '100': 199,
  18968. '101': 201, '102': 209, '103': 214, '104': 220, '105': 225, '106': 224,
  18969. '107': 226, '108': 228, '109': 227, '110': 229, '111': 231, '112': 233,
  18970. '113': 232, '114': 234, '115': 235, '116': 237, '117': 236, '118': 238,
  18971. '119': 239, '120': 241, '121': 243, '122': 242, '123': 244, '124': 246,
  18972. '125': 245, '126': 250, '127': 249, '128': 251, '129': 252, '130': 8224,
  18973. '131': 176, '132': 162, '133': 163, '134': 167, '135': 8226, '136': 182,
  18974. '137': 223, '138': 174, '139': 169, '140': 8482, '141': 180, '142': 168,
  18975. '143': 8800, '144': 198, '145': 216, '146': 8734, '147': 177, '148': 8804,
  18976. '149': 8805, '150': 165, '151': 181, '152': 8706, '153': 8721, '154': 8719,
  18977. '156': 8747, '157': 170, '158': 186, '159': 8486, '160': 230, '161': 248,
  18978. '162': 191, '163': 161, '164': 172, '165': 8730, '166': 402, '167': 8776,
  18979. '168': 8710, '169': 171, '170': 187, '171': 8230, '210': 218, '223': 711,
  18980. '224': 321, '225': 322, '227': 353, '229': 382, '234': 253, '252': 263,
  18981. '253': 268, '254': 269, '258': 258, '260': 260, '261': 261, '265': 280,
  18982. '266': 281, '268': 283, '269': 313, '275': 323, '276': 324, '278': 328,
  18983. '284': 345, '285': 346, '286': 347, '292': 367, '295': 377, '296': 378,
  18984. '298': 380, '305': 963,
  18985. '306': 964, '307': 966, '308': 8215, '309': 8252, '310': 8319, '311': 8359,
  18986. '312': 8592, '313': 8593, '337': 9552, '493': 1039, '494': 1040, '705': 1524,
  18987. '706': 8362, '710': 64288, '711': 64298, '759': 1617, '761': 1776,
  18988. '763': 1778, '775': 1652, '777': 1764, '778': 1780, '779': 1781, '780': 1782,
  18989. '782': 771, '783': 64726, '786': 8363, '788': 8532, '790': 768, '791': 769,
  18990. '792': 768, '795': 803, '797': 64336, '798': 64337, '799': 64342,
  18991. '800': 64343, '801': 64344, '802': 64345, '803': 64362, '804': 64363,
  18992. '805': 64364, '2424': 7821, '2425': 7822, '2426': 7823, '2427': 7824,
  18993. '2428': 7825, '2429': 7826, '2430': 7827, '2433': 7682, '2678': 8045,
  18994. '2679': 8046, '2830': 1552, '2838': 686, '2840': 751, '2842': 753,
  18995. '2843': 754, '2844': 755, '2846': 757, '2856': 767, '2857': 848, '2858': 849,
  18996. '2862': 853, '2863': 854, '2864': 855, '2865': 861, '2866': 862, '2906': 7460,
  18997. '2908': 7462, '2909': 7463, '2910': 7464, '2912': 7466, '2913': 7467,
  18998. '2914': 7468, '2916': 7470, '2917': 7471, '2918': 7472, '2920': 7474,
  18999. '2921': 7475, '2922': 7476, '2924': 7478, '2925': 7479, '2926': 7480,
  19000. '2928': 7482, '2929': 7483, '2930': 7484, '2932': 7486, '2933': 7487,
  19001. '2934': 7488, '2936': 7490, '2937': 7491, '2938': 7492, '2940': 7494,
  19002. '2941': 7495, '2942': 7496, '2944': 7498, '2946': 7500, '2948': 7502,
  19003. '2950': 7504, '2951': 7505, '2952': 7506, '2954': 7508, '2955': 7509,
  19004. '2956': 7510, '2958': 7512, '2959': 7513, '2960': 7514, '2962': 7516,
  19005. '2963': 7517, '2964': 7518, '2966': 7520, '2967': 7521, '2968': 7522,
  19006. '2970': 7524, '2971': 7525, '2972': 7526, '2974': 7528, '2975': 7529,
  19007. '2976': 7530, '2978': 1537, '2979': 1538, '2980': 1539, '2982': 1549,
  19008. '2983': 1551, '2984': 1552, '2986': 1554, '2987': 1555, '2988': 1556,
  19009. '2990': 1623, '2991': 1624, '2995': 1775, '2999': 1791, '3002': 64290,
  19010. '3003': 64291, '3004': 64292, '3006': 64294, '3007': 64295, '3008': 64296,
  19011. '3011': 1900, '3014': 8223, '3015': 8244, '3017': 7532, '3018': 7533,
  19012. '3019': 7534, '3075': 7590, '3076': 7591, '3079': 7594, '3080': 7595,
  19013. '3083': 7598, '3084': 7599, '3087': 7602, '3088': 7603, '3091': 7606,
  19014. '3092': 7607, '3095': 7610, '3096': 7611, '3099': 7614, '3100': 7615,
  19015. '3103': 7618, '3104': 7619, '3107': 8337, '3108': 8338, '3116': 1884,
  19016. '3119': 1885, '3120': 1885, '3123': 1886, '3124': 1886, '3127': 1887,
  19017. '3128': 1887, '3131': 1888, '3132': 1888, '3135': 1889, '3136': 1889,
  19018. '3139': 1890, '3140': 1890, '3143': 1891, '3144': 1891, '3147': 1892,
  19019. '3148': 1892, '3153': 580, '3154': 581, '3157': 584, '3158': 585, '3161': 588,
  19020. '3162': 589, '3165': 891, '3166': 892, '3169': 1274, '3170': 1275,
  19021. '3173': 1278, '3174': 1279, '3181': 7622, '3182': 7623, '3282': 11799,
  19022. '3316': 578, '3379': 42785, '3393': 1159, '3416': 8377
  19023. };
  19024. // Some characters, e.g. copyrightserif, are mapped to the private use area and
  19025. // might not be displayed using standard fonts. Mapping/hacking well-known chars
  19026. // to the similar equivalents in the normal characters range.
  19027. var SpecialPUASymbols = {
  19028. '63721': 0x00A9, // copyrightsans (0xF8E9) => copyright
  19029. '63193': 0x00A9, // copyrightserif (0xF6D9) => copyright
  19030. '63720': 0x00AE, // registersans (0xF8E8) => registered
  19031. '63194': 0x00AE, // registerserif (0xF6DA) => registered
  19032. '63722': 0x2122, // trademarksans (0xF8EA) => trademark
  19033. '63195': 0x2122, // trademarkserif (0xF6DB) => trademark
  19034. '63729': 0x23A7, // bracelefttp (0xF8F1)
  19035. '63730': 0x23A8, // braceleftmid (0xF8F2)
  19036. '63731': 0x23A9, // braceleftbt (0xF8F3)
  19037. '63740': 0x23AB, // bracerighttp (0xF8FC)
  19038. '63741': 0x23AC, // bracerightmid (0xF8FD)
  19039. '63742': 0x23AD, // bracerightbt (0xF8FE)
  19040. '63726': 0x23A1, // bracketlefttp (0xF8EE)
  19041. '63727': 0x23A2, // bracketleftex (0xF8EF)
  19042. '63728': 0x23A3, // bracketleftbt (0xF8F0)
  19043. '63737': 0x23A4, // bracketrighttp (0xF8F9)
  19044. '63738': 0x23A5, // bracketrightex (0xF8FA)
  19045. '63739': 0x23A6, // bracketrightbt (0xF8FB)
  19046. '63723': 0x239B, // parenlefttp (0xF8EB)
  19047. '63724': 0x239C, // parenleftex (0xF8EC)
  19048. '63725': 0x239D, // parenleftbt (0xF8ED)
  19049. '63734': 0x239E, // parenrighttp (0xF8F6)
  19050. '63735': 0x239F, // parenrightex (0xF8F7)
  19051. '63736': 0x23A0, // parenrightbt (0xF8F8)
  19052. };
  19053. function mapSpecialUnicodeValues(code) {
  19054. if (code >= 0xFFF0 && code <= 0xFFFF) { // Specials unicode block.
  19055. return 0;
  19056. } else if (code >= 0xF600 && code <= 0xF8FF) {
  19057. return (SpecialPUASymbols[code] || code);
  19058. }
  19059. return code;
  19060. }
  19061. var UnicodeRanges = [
  19062. { 'begin': 0x0000, 'end': 0x007F }, // Basic Latin
  19063. { 'begin': 0x0080, 'end': 0x00FF }, // Latin-1 Supplement
  19064. { 'begin': 0x0100, 'end': 0x017F }, // Latin Extended-A
  19065. { 'begin': 0x0180, 'end': 0x024F }, // Latin Extended-B
  19066. { 'begin': 0x0250, 'end': 0x02AF }, // IPA Extensions
  19067. { 'begin': 0x02B0, 'end': 0x02FF }, // Spacing Modifier Letters
  19068. { 'begin': 0x0300, 'end': 0x036F }, // Combining Diacritical Marks
  19069. { 'begin': 0x0370, 'end': 0x03FF }, // Greek and Coptic
  19070. { 'begin': 0x2C80, 'end': 0x2CFF }, // Coptic
  19071. { 'begin': 0x0400, 'end': 0x04FF }, // Cyrillic
  19072. { 'begin': 0x0530, 'end': 0x058F }, // Armenian
  19073. { 'begin': 0x0590, 'end': 0x05FF }, // Hebrew
  19074. { 'begin': 0xA500, 'end': 0xA63F }, // Vai
  19075. { 'begin': 0x0600, 'end': 0x06FF }, // Arabic
  19076. { 'begin': 0x07C0, 'end': 0x07FF }, // NKo
  19077. { 'begin': 0x0900, 'end': 0x097F }, // Devanagari
  19078. { 'begin': 0x0980, 'end': 0x09FF }, // Bengali
  19079. { 'begin': 0x0A00, 'end': 0x0A7F }, // Gurmukhi
  19080. { 'begin': 0x0A80, 'end': 0x0AFF }, // Gujarati
  19081. { 'begin': 0x0B00, 'end': 0x0B7F }, // Oriya
  19082. { 'begin': 0x0B80, 'end': 0x0BFF }, // Tamil
  19083. { 'begin': 0x0C00, 'end': 0x0C7F }, // Telugu
  19084. { 'begin': 0x0C80, 'end': 0x0CFF }, // Kannada
  19085. { 'begin': 0x0D00, 'end': 0x0D7F }, // Malayalam
  19086. { 'begin': 0x0E00, 'end': 0x0E7F }, // Thai
  19087. { 'begin': 0x0E80, 'end': 0x0EFF }, // Lao
  19088. { 'begin': 0x10A0, 'end': 0x10FF }, // Georgian
  19089. { 'begin': 0x1B00, 'end': 0x1B7F }, // Balinese
  19090. { 'begin': 0x1100, 'end': 0x11FF }, // Hangul Jamo
  19091. { 'begin': 0x1E00, 'end': 0x1EFF }, // Latin Extended Additional
  19092. { 'begin': 0x1F00, 'end': 0x1FFF }, // Greek Extended
  19093. { 'begin': 0x2000, 'end': 0x206F }, // General Punctuation
  19094. { 'begin': 0x2070, 'end': 0x209F }, // Superscripts And Subscripts
  19095. { 'begin': 0x20A0, 'end': 0x20CF }, // Currency Symbol
  19096. { 'begin': 0x20D0, 'end': 0x20FF }, // Combining Diacritical Marks For Symbols
  19097. { 'begin': 0x2100, 'end': 0x214F }, // Letterlike Symbols
  19098. { 'begin': 0x2150, 'end': 0x218F }, // Number Forms
  19099. { 'begin': 0x2190, 'end': 0x21FF }, // Arrows
  19100. { 'begin': 0x2200, 'end': 0x22FF }, // Mathematical Operators
  19101. { 'begin': 0x2300, 'end': 0x23FF }, // Miscellaneous Technical
  19102. { 'begin': 0x2400, 'end': 0x243F }, // Control Pictures
  19103. { 'begin': 0x2440, 'end': 0x245F }, // Optical Character Recognition
  19104. { 'begin': 0x2460, 'end': 0x24FF }, // Enclosed Alphanumerics
  19105. { 'begin': 0x2500, 'end': 0x257F }, // Box Drawing
  19106. { 'begin': 0x2580, 'end': 0x259F }, // Block Elements
  19107. { 'begin': 0x25A0, 'end': 0x25FF }, // Geometric Shapes
  19108. { 'begin': 0x2600, 'end': 0x26FF }, // Miscellaneous Symbols
  19109. { 'begin': 0x2700, 'end': 0x27BF }, // Dingbats
  19110. { 'begin': 0x3000, 'end': 0x303F }, // CJK Symbols And Punctuation
  19111. { 'begin': 0x3040, 'end': 0x309F }, // Hiragana
  19112. { 'begin': 0x30A0, 'end': 0x30FF }, // Katakana
  19113. { 'begin': 0x3100, 'end': 0x312F }, // Bopomofo
  19114. { 'begin': 0x3130, 'end': 0x318F }, // Hangul Compatibility Jamo
  19115. { 'begin': 0xA840, 'end': 0xA87F }, // Phags-pa
  19116. { 'begin': 0x3200, 'end': 0x32FF }, // Enclosed CJK Letters And Months
  19117. { 'begin': 0x3300, 'end': 0x33FF }, // CJK Compatibility
  19118. { 'begin': 0xAC00, 'end': 0xD7AF }, // Hangul Syllables
  19119. { 'begin': 0xD800, 'end': 0xDFFF }, // Non-Plane 0 *
  19120. { 'begin': 0x10900, 'end': 0x1091F }, // Phoenicia
  19121. { 'begin': 0x4E00, 'end': 0x9FFF }, // CJK Unified Ideographs
  19122. { 'begin': 0xE000, 'end': 0xF8FF }, // Private Use Area (plane 0)
  19123. { 'begin': 0x31C0, 'end': 0x31EF }, // CJK Strokes
  19124. { 'begin': 0xFB00, 'end': 0xFB4F }, // Alphabetic Presentation Forms
  19125. { 'begin': 0xFB50, 'end': 0xFDFF }, // Arabic Presentation Forms-A
  19126. { 'begin': 0xFE20, 'end': 0xFE2F }, // Combining Half Marks
  19127. { 'begin': 0xFE10, 'end': 0xFE1F }, // Vertical Forms
  19128. { 'begin': 0xFE50, 'end': 0xFE6F }, // Small Form Variants
  19129. { 'begin': 0xFE70, 'end': 0xFEFF }, // Arabic Presentation Forms-B
  19130. { 'begin': 0xFF00, 'end': 0xFFEF }, // Halfwidth And Fullwidth Forms
  19131. { 'begin': 0xFFF0, 'end': 0xFFFF }, // Specials
  19132. { 'begin': 0x0F00, 'end': 0x0FFF }, // Tibetan
  19133. { 'begin': 0x0700, 'end': 0x074F }, // Syriac
  19134. { 'begin': 0x0780, 'end': 0x07BF }, // Thaana
  19135. { 'begin': 0x0D80, 'end': 0x0DFF }, // Sinhala
  19136. { 'begin': 0x1000, 'end': 0x109F }, // Myanmar
  19137. { 'begin': 0x1200, 'end': 0x137F }, // Ethiopic
  19138. { 'begin': 0x13A0, 'end': 0x13FF }, // Cherokee
  19139. { 'begin': 0x1400, 'end': 0x167F }, // Unified Canadian Aboriginal Syllabics
  19140. { 'begin': 0x1680, 'end': 0x169F }, // Ogham
  19141. { 'begin': 0x16A0, 'end': 0x16FF }, // Runic
  19142. { 'begin': 0x1780, 'end': 0x17FF }, // Khmer
  19143. { 'begin': 0x1800, 'end': 0x18AF }, // Mongolian
  19144. { 'begin': 0x2800, 'end': 0x28FF }, // Braille Patterns
  19145. { 'begin': 0xA000, 'end': 0xA48F }, // Yi Syllables
  19146. { 'begin': 0x1700, 'end': 0x171F }, // Tagalog
  19147. { 'begin': 0x10300, 'end': 0x1032F }, // Old Italic
  19148. { 'begin': 0x10330, 'end': 0x1034F }, // Gothic
  19149. { 'begin': 0x10400, 'end': 0x1044F }, // Deseret
  19150. { 'begin': 0x1D000, 'end': 0x1D0FF }, // Byzantine Musical Symbols
  19151. { 'begin': 0x1D400, 'end': 0x1D7FF }, // Mathematical Alphanumeric Symbols
  19152. { 'begin': 0xFF000, 'end': 0xFFFFD }, // Private Use (plane 15)
  19153. { 'begin': 0xFE00, 'end': 0xFE0F }, // Variation Selectors
  19154. { 'begin': 0xE0000, 'end': 0xE007F }, // Tags
  19155. { 'begin': 0x1900, 'end': 0x194F }, // Limbu
  19156. { 'begin': 0x1950, 'end': 0x197F }, // Tai Le
  19157. { 'begin': 0x1980, 'end': 0x19DF }, // New Tai Lue
  19158. { 'begin': 0x1A00, 'end': 0x1A1F }, // Buginese
  19159. { 'begin': 0x2C00, 'end': 0x2C5F }, // Glagolitic
  19160. { 'begin': 0x2D30, 'end': 0x2D7F }, // Tifinagh
  19161. { 'begin': 0x4DC0, 'end': 0x4DFF }, // Yijing Hexagram Symbols
  19162. { 'begin': 0xA800, 'end': 0xA82F }, // Syloti Nagri
  19163. { 'begin': 0x10000, 'end': 0x1007F }, // Linear B Syllabary
  19164. { 'begin': 0x10140, 'end': 0x1018F }, // Ancient Greek Numbers
  19165. { 'begin': 0x10380, 'end': 0x1039F }, // Ugaritic
  19166. { 'begin': 0x103A0, 'end': 0x103DF }, // Old Persian
  19167. { 'begin': 0x10450, 'end': 0x1047F }, // Shavian
  19168. { 'begin': 0x10480, 'end': 0x104AF }, // Osmanya
  19169. { 'begin': 0x10800, 'end': 0x1083F }, // Cypriot Syllabary
  19170. { 'begin': 0x10A00, 'end': 0x10A5F }, // Kharoshthi
  19171. { 'begin': 0x1D300, 'end': 0x1D35F }, // Tai Xuan Jing Symbols
  19172. { 'begin': 0x12000, 'end': 0x123FF }, // Cuneiform
  19173. { 'begin': 0x1D360, 'end': 0x1D37F }, // Counting Rod Numerals
  19174. { 'begin': 0x1B80, 'end': 0x1BBF }, // Sundanese
  19175. { 'begin': 0x1C00, 'end': 0x1C4F }, // Lepcha
  19176. { 'begin': 0x1C50, 'end': 0x1C7F }, // Ol Chiki
  19177. { 'begin': 0xA880, 'end': 0xA8DF }, // Saurashtra
  19178. { 'begin': 0xA900, 'end': 0xA92F }, // Kayah Li
  19179. { 'begin': 0xA930, 'end': 0xA95F }, // Rejang
  19180. { 'begin': 0xAA00, 'end': 0xAA5F }, // Cham
  19181. { 'begin': 0x10190, 'end': 0x101CF }, // Ancient Symbols
  19182. { 'begin': 0x101D0, 'end': 0x101FF }, // Phaistos Disc
  19183. { 'begin': 0x102A0, 'end': 0x102DF }, // Carian
  19184. { 'begin': 0x1F030, 'end': 0x1F09F } // Domino Tiles
  19185. ];
  19186. var MacStandardGlyphOrdering = [
  19187. '.notdef', '.null', 'nonmarkingreturn', 'space', 'exclam', 'quotedbl',
  19188. 'numbersign', 'dollar', 'percent', 'ampersand', 'quotesingle', 'parenleft',
  19189. 'parenright', 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash',
  19190. 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',
  19191. 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater', 'question', 'at',
  19192. 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
  19193. 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'bracketleft',
  19194. 'backslash', 'bracketright', 'asciicircum', 'underscore', 'grave', 'a', 'b',
  19195. 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q',
  19196. 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright',
  19197. 'asciitilde', 'Adieresis', 'Aring', 'Ccedilla', 'Eacute', 'Ntilde',
  19198. 'Odieresis', 'Udieresis', 'aacute', 'agrave', 'acircumflex', 'adieresis',
  19199. 'atilde', 'aring', 'ccedilla', 'eacute', 'egrave', 'ecircumflex', 'edieresis',
  19200. 'iacute', 'igrave', 'icircumflex', 'idieresis', 'ntilde', 'oacute', 'ograve',
  19201. 'ocircumflex', 'odieresis', 'otilde', 'uacute', 'ugrave', 'ucircumflex',
  19202. 'udieresis', 'dagger', 'degree', 'cent', 'sterling', 'section', 'bullet',
  19203. 'paragraph', 'germandbls', 'registered', 'copyright', 'trademark', 'acute',
  19204. 'dieresis', 'notequal', 'AE', 'Oslash', 'infinity', 'plusminus', 'lessequal',
  19205. 'greaterequal', 'yen', 'mu', 'partialdiff', 'summation', 'product', 'pi',
  19206. 'integral', 'ordfeminine', 'ordmasculine', 'Omega', 'ae', 'oslash',
  19207. 'questiondown', 'exclamdown', 'logicalnot', 'radical', 'florin',
  19208. 'approxequal', 'Delta', 'guillemotleft', 'guillemotright', 'ellipsis',
  19209. 'nonbreakingspace', 'Agrave', 'Atilde', 'Otilde', 'OE', 'oe', 'endash',
  19210. 'emdash', 'quotedblleft', 'quotedblright', 'quoteleft', 'quoteright',
  19211. 'divide', 'lozenge', 'ydieresis', 'Ydieresis', 'fraction', 'currency',
  19212. 'guilsinglleft', 'guilsinglright', 'fi', 'fl', 'daggerdbl', 'periodcentered',
  19213. 'quotesinglbase', 'quotedblbase', 'perthousand', 'Acircumflex',
  19214. 'Ecircumflex', 'Aacute', 'Edieresis', 'Egrave', 'Iacute', 'Icircumflex',
  19215. 'Idieresis', 'Igrave', 'Oacute', 'Ocircumflex', 'apple', 'Ograve', 'Uacute',
  19216. 'Ucircumflex', 'Ugrave', 'dotlessi', 'circumflex', 'tilde', 'macron',
  19217. 'breve', 'dotaccent', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron',
  19218. 'Lslash', 'lslash', 'Scaron', 'scaron', 'Zcaron', 'zcaron', 'brokenbar',
  19219. 'Eth', 'eth', 'Yacute', 'yacute', 'Thorn', 'thorn', 'minus', 'multiply',
  19220. 'onesuperior', 'twosuperior', 'threesuperior', 'onehalf', 'onequarter',
  19221. 'threequarters', 'franc', 'Gbreve', 'gbreve', 'Idotaccent', 'Scedilla',
  19222. 'scedilla', 'Cacute', 'cacute', 'Ccaron', 'ccaron', 'dcroat'];
  19223. function getUnicodeRangeFor(value) {
  19224. for (var i = 0, ii = UnicodeRanges.length; i < ii; i++) {
  19225. var range = UnicodeRanges[i];
  19226. if (value >= range.begin && value < range.end) {
  19227. return i;
  19228. }
  19229. }
  19230. return -1;
  19231. }
  19232. function isRTLRangeFor(value) {
  19233. var range = UnicodeRanges[13];
  19234. if (value >= range.begin && value < range.end) {
  19235. return true;
  19236. }
  19237. range = UnicodeRanges[11];
  19238. if (value >= range.begin && value < range.end) {
  19239. return true;
  19240. }
  19241. return false;
  19242. }
  19243. // The normalization table is obtained by filtering the Unicode characters
  19244. // database with <compat> entries.
  19245. var NormalizedUnicodes = {
  19246. '\u00A8': '\u0020\u0308',
  19247. '\u00AF': '\u0020\u0304',
  19248. '\u00B4': '\u0020\u0301',
  19249. '\u00B5': '\u03BC',
  19250. '\u00B8': '\u0020\u0327',
  19251. '\u0132': '\u0049\u004A',
  19252. '\u0133': '\u0069\u006A',
  19253. '\u013F': '\u004C\u00B7',
  19254. '\u0140': '\u006C\u00B7',
  19255. '\u0149': '\u02BC\u006E',
  19256. '\u017F': '\u0073',
  19257. '\u01C4': '\u0044\u017D',
  19258. '\u01C5': '\u0044\u017E',
  19259. '\u01C6': '\u0064\u017E',
  19260. '\u01C7': '\u004C\u004A',
  19261. '\u01C8': '\u004C\u006A',
  19262. '\u01C9': '\u006C\u006A',
  19263. '\u01CA': '\u004E\u004A',
  19264. '\u01CB': '\u004E\u006A',
  19265. '\u01CC': '\u006E\u006A',
  19266. '\u01F1': '\u0044\u005A',
  19267. '\u01F2': '\u0044\u007A',
  19268. '\u01F3': '\u0064\u007A',
  19269. '\u02D8': '\u0020\u0306',
  19270. '\u02D9': '\u0020\u0307',
  19271. '\u02DA': '\u0020\u030A',
  19272. '\u02DB': '\u0020\u0328',
  19273. '\u02DC': '\u0020\u0303',
  19274. '\u02DD': '\u0020\u030B',
  19275. '\u037A': '\u0020\u0345',
  19276. '\u0384': '\u0020\u0301',
  19277. '\u03D0': '\u03B2',
  19278. '\u03D1': '\u03B8',
  19279. '\u03D2': '\u03A5',
  19280. '\u03D5': '\u03C6',
  19281. '\u03D6': '\u03C0',
  19282. '\u03F0': '\u03BA',
  19283. '\u03F1': '\u03C1',
  19284. '\u03F2': '\u03C2',
  19285. '\u03F4': '\u0398',
  19286. '\u03F5': '\u03B5',
  19287. '\u03F9': '\u03A3',
  19288. '\u0587': '\u0565\u0582',
  19289. '\u0675': '\u0627\u0674',
  19290. '\u0676': '\u0648\u0674',
  19291. '\u0677': '\u06C7\u0674',
  19292. '\u0678': '\u064A\u0674',
  19293. '\u0E33': '\u0E4D\u0E32',
  19294. '\u0EB3': '\u0ECD\u0EB2',
  19295. '\u0EDC': '\u0EAB\u0E99',
  19296. '\u0EDD': '\u0EAB\u0EA1',
  19297. '\u0F77': '\u0FB2\u0F81',
  19298. '\u0F79': '\u0FB3\u0F81',
  19299. '\u1E9A': '\u0061\u02BE',
  19300. '\u1FBD': '\u0020\u0313',
  19301. '\u1FBF': '\u0020\u0313',
  19302. '\u1FC0': '\u0020\u0342',
  19303. '\u1FFE': '\u0020\u0314',
  19304. '\u2002': '\u0020',
  19305. '\u2003': '\u0020',
  19306. '\u2004': '\u0020',
  19307. '\u2005': '\u0020',
  19308. '\u2006': '\u0020',
  19309. '\u2008': '\u0020',
  19310. '\u2009': '\u0020',
  19311. '\u200A': '\u0020',
  19312. '\u2017': '\u0020\u0333',
  19313. '\u2024': '\u002E',
  19314. '\u2025': '\u002E\u002E',
  19315. '\u2026': '\u002E\u002E\u002E',
  19316. '\u2033': '\u2032\u2032',
  19317. '\u2034': '\u2032\u2032\u2032',
  19318. '\u2036': '\u2035\u2035',
  19319. '\u2037': '\u2035\u2035\u2035',
  19320. '\u203C': '\u0021\u0021',
  19321. '\u203E': '\u0020\u0305',
  19322. '\u2047': '\u003F\u003F',
  19323. '\u2048': '\u003F\u0021',
  19324. '\u2049': '\u0021\u003F',
  19325. '\u2057': '\u2032\u2032\u2032\u2032',
  19326. '\u205F': '\u0020',
  19327. '\u20A8': '\u0052\u0073',
  19328. '\u2100': '\u0061\u002F\u0063',
  19329. '\u2101': '\u0061\u002F\u0073',
  19330. '\u2103': '\u00B0\u0043',
  19331. '\u2105': '\u0063\u002F\u006F',
  19332. '\u2106': '\u0063\u002F\u0075',
  19333. '\u2107': '\u0190',
  19334. '\u2109': '\u00B0\u0046',
  19335. '\u2116': '\u004E\u006F',
  19336. '\u2121': '\u0054\u0045\u004C',
  19337. '\u2135': '\u05D0',
  19338. '\u2136': '\u05D1',
  19339. '\u2137': '\u05D2',
  19340. '\u2138': '\u05D3',
  19341. '\u213B': '\u0046\u0041\u0058',
  19342. '\u2160': '\u0049',
  19343. '\u2161': '\u0049\u0049',
  19344. '\u2162': '\u0049\u0049\u0049',
  19345. '\u2163': '\u0049\u0056',
  19346. '\u2164': '\u0056',
  19347. '\u2165': '\u0056\u0049',
  19348. '\u2166': '\u0056\u0049\u0049',
  19349. '\u2167': '\u0056\u0049\u0049\u0049',
  19350. '\u2168': '\u0049\u0058',
  19351. '\u2169': '\u0058',
  19352. '\u216A': '\u0058\u0049',
  19353. '\u216B': '\u0058\u0049\u0049',
  19354. '\u216C': '\u004C',
  19355. '\u216D': '\u0043',
  19356. '\u216E': '\u0044',
  19357. '\u216F': '\u004D',
  19358. '\u2170': '\u0069',
  19359. '\u2171': '\u0069\u0069',
  19360. '\u2172': '\u0069\u0069\u0069',
  19361. '\u2173': '\u0069\u0076',
  19362. '\u2174': '\u0076',
  19363. '\u2175': '\u0076\u0069',
  19364. '\u2176': '\u0076\u0069\u0069',
  19365. '\u2177': '\u0076\u0069\u0069\u0069',
  19366. '\u2178': '\u0069\u0078',
  19367. '\u2179': '\u0078',
  19368. '\u217A': '\u0078\u0069',
  19369. '\u217B': '\u0078\u0069\u0069',
  19370. '\u217C': '\u006C',
  19371. '\u217D': '\u0063',
  19372. '\u217E': '\u0064',
  19373. '\u217F': '\u006D',
  19374. '\u222C': '\u222B\u222B',
  19375. '\u222D': '\u222B\u222B\u222B',
  19376. '\u222F': '\u222E\u222E',
  19377. '\u2230': '\u222E\u222E\u222E',
  19378. '\u2474': '\u0028\u0031\u0029',
  19379. '\u2475': '\u0028\u0032\u0029',
  19380. '\u2476': '\u0028\u0033\u0029',
  19381. '\u2477': '\u0028\u0034\u0029',
  19382. '\u2478': '\u0028\u0035\u0029',
  19383. '\u2479': '\u0028\u0036\u0029',
  19384. '\u247A': '\u0028\u0037\u0029',
  19385. '\u247B': '\u0028\u0038\u0029',
  19386. '\u247C': '\u0028\u0039\u0029',
  19387. '\u247D': '\u0028\u0031\u0030\u0029',
  19388. '\u247E': '\u0028\u0031\u0031\u0029',
  19389. '\u247F': '\u0028\u0031\u0032\u0029',
  19390. '\u2480': '\u0028\u0031\u0033\u0029',
  19391. '\u2481': '\u0028\u0031\u0034\u0029',
  19392. '\u2482': '\u0028\u0031\u0035\u0029',
  19393. '\u2483': '\u0028\u0031\u0036\u0029',
  19394. '\u2484': '\u0028\u0031\u0037\u0029',
  19395. '\u2485': '\u0028\u0031\u0038\u0029',
  19396. '\u2486': '\u0028\u0031\u0039\u0029',
  19397. '\u2487': '\u0028\u0032\u0030\u0029',
  19398. '\u2488': '\u0031\u002E',
  19399. '\u2489': '\u0032\u002E',
  19400. '\u248A': '\u0033\u002E',
  19401. '\u248B': '\u0034\u002E',
  19402. '\u248C': '\u0035\u002E',
  19403. '\u248D': '\u0036\u002E',
  19404. '\u248E': '\u0037\u002E',
  19405. '\u248F': '\u0038\u002E',
  19406. '\u2490': '\u0039\u002E',
  19407. '\u2491': '\u0031\u0030\u002E',
  19408. '\u2492': '\u0031\u0031\u002E',
  19409. '\u2493': '\u0031\u0032\u002E',
  19410. '\u2494': '\u0031\u0033\u002E',
  19411. '\u2495': '\u0031\u0034\u002E',
  19412. '\u2496': '\u0031\u0035\u002E',
  19413. '\u2497': '\u0031\u0036\u002E',
  19414. '\u2498': '\u0031\u0037\u002E',
  19415. '\u2499': '\u0031\u0038\u002E',
  19416. '\u249A': '\u0031\u0039\u002E',
  19417. '\u249B': '\u0032\u0030\u002E',
  19418. '\u249C': '\u0028\u0061\u0029',
  19419. '\u249D': '\u0028\u0062\u0029',
  19420. '\u249E': '\u0028\u0063\u0029',
  19421. '\u249F': '\u0028\u0064\u0029',
  19422. '\u24A0': '\u0028\u0065\u0029',
  19423. '\u24A1': '\u0028\u0066\u0029',
  19424. '\u24A2': '\u0028\u0067\u0029',
  19425. '\u24A3': '\u0028\u0068\u0029',
  19426. '\u24A4': '\u0028\u0069\u0029',
  19427. '\u24A5': '\u0028\u006A\u0029',
  19428. '\u24A6': '\u0028\u006B\u0029',
  19429. '\u24A7': '\u0028\u006C\u0029',
  19430. '\u24A8': '\u0028\u006D\u0029',
  19431. '\u24A9': '\u0028\u006E\u0029',
  19432. '\u24AA': '\u0028\u006F\u0029',
  19433. '\u24AB': '\u0028\u0070\u0029',
  19434. '\u24AC': '\u0028\u0071\u0029',
  19435. '\u24AD': '\u0028\u0072\u0029',
  19436. '\u24AE': '\u0028\u0073\u0029',
  19437. '\u24AF': '\u0028\u0074\u0029',
  19438. '\u24B0': '\u0028\u0075\u0029',
  19439. '\u24B1': '\u0028\u0076\u0029',
  19440. '\u24B2': '\u0028\u0077\u0029',
  19441. '\u24B3': '\u0028\u0078\u0029',
  19442. '\u24B4': '\u0028\u0079\u0029',
  19443. '\u24B5': '\u0028\u007A\u0029',
  19444. '\u2A0C': '\u222B\u222B\u222B\u222B',
  19445. '\u2A74': '\u003A\u003A\u003D',
  19446. '\u2A75': '\u003D\u003D',
  19447. '\u2A76': '\u003D\u003D\u003D',
  19448. '\u2E9F': '\u6BCD',
  19449. '\u2EF3': '\u9F9F',
  19450. '\u2F00': '\u4E00',
  19451. '\u2F01': '\u4E28',
  19452. '\u2F02': '\u4E36',
  19453. '\u2F03': '\u4E3F',
  19454. '\u2F04': '\u4E59',
  19455. '\u2F05': '\u4E85',
  19456. '\u2F06': '\u4E8C',
  19457. '\u2F07': '\u4EA0',
  19458. '\u2F08': '\u4EBA',
  19459. '\u2F09': '\u513F',
  19460. '\u2F0A': '\u5165',
  19461. '\u2F0B': '\u516B',
  19462. '\u2F0C': '\u5182',
  19463. '\u2F0D': '\u5196',
  19464. '\u2F0E': '\u51AB',
  19465. '\u2F0F': '\u51E0',
  19466. '\u2F10': '\u51F5',
  19467. '\u2F11': '\u5200',
  19468. '\u2F12': '\u529B',
  19469. '\u2F13': '\u52F9',
  19470. '\u2F14': '\u5315',
  19471. '\u2F15': '\u531A',
  19472. '\u2F16': '\u5338',
  19473. '\u2F17': '\u5341',
  19474. '\u2F18': '\u535C',
  19475. '\u2F19': '\u5369',
  19476. '\u2F1A': '\u5382',
  19477. '\u2F1B': '\u53B6',
  19478. '\u2F1C': '\u53C8',
  19479. '\u2F1D': '\u53E3',
  19480. '\u2F1E': '\u56D7',
  19481. '\u2F1F': '\u571F',
  19482. '\u2F20': '\u58EB',
  19483. '\u2F21': '\u5902',
  19484. '\u2F22': '\u590A',
  19485. '\u2F23': '\u5915',
  19486. '\u2F24': '\u5927',
  19487. '\u2F25': '\u5973',
  19488. '\u2F26': '\u5B50',
  19489. '\u2F27': '\u5B80',
  19490. '\u2F28': '\u5BF8',
  19491. '\u2F29': '\u5C0F',
  19492. '\u2F2A': '\u5C22',
  19493. '\u2F2B': '\u5C38',
  19494. '\u2F2C': '\u5C6E',
  19495. '\u2F2D': '\u5C71',
  19496. '\u2F2E': '\u5DDB',
  19497. '\u2F2F': '\u5DE5',
  19498. '\u2F30': '\u5DF1',
  19499. '\u2F31': '\u5DFE',
  19500. '\u2F32': '\u5E72',
  19501. '\u2F33': '\u5E7A',
  19502. '\u2F34': '\u5E7F',
  19503. '\u2F35': '\u5EF4',
  19504. '\u2F36': '\u5EFE',
  19505. '\u2F37': '\u5F0B',
  19506. '\u2F38': '\u5F13',
  19507. '\u2F39': '\u5F50',
  19508. '\u2F3A': '\u5F61',
  19509. '\u2F3B': '\u5F73',
  19510. '\u2F3C': '\u5FC3',
  19511. '\u2F3D': '\u6208',
  19512. '\u2F3E': '\u6236',
  19513. '\u2F3F': '\u624B',
  19514. '\u2F40': '\u652F',
  19515. '\u2F41': '\u6534',
  19516. '\u2F42': '\u6587',
  19517. '\u2F43': '\u6597',
  19518. '\u2F44': '\u65A4',
  19519. '\u2F45': '\u65B9',
  19520. '\u2F46': '\u65E0',
  19521. '\u2F47': '\u65E5',
  19522. '\u2F48': '\u66F0',
  19523. '\u2F49': '\u6708',
  19524. '\u2F4A': '\u6728',
  19525. '\u2F4B': '\u6B20',
  19526. '\u2F4C': '\u6B62',
  19527. '\u2F4D': '\u6B79',
  19528. '\u2F4E': '\u6BB3',
  19529. '\u2F4F': '\u6BCB',
  19530. '\u2F50': '\u6BD4',
  19531. '\u2F51': '\u6BDB',
  19532. '\u2F52': '\u6C0F',
  19533. '\u2F53': '\u6C14',
  19534. '\u2F54': '\u6C34',
  19535. '\u2F55': '\u706B',
  19536. '\u2F56': '\u722A',
  19537. '\u2F57': '\u7236',
  19538. '\u2F58': '\u723B',
  19539. '\u2F59': '\u723F',
  19540. '\u2F5A': '\u7247',
  19541. '\u2F5B': '\u7259',
  19542. '\u2F5C': '\u725B',
  19543. '\u2F5D': '\u72AC',
  19544. '\u2F5E': '\u7384',
  19545. '\u2F5F': '\u7389',
  19546. '\u2F60': '\u74DC',
  19547. '\u2F61': '\u74E6',
  19548. '\u2F62': '\u7518',
  19549. '\u2F63': '\u751F',
  19550. '\u2F64': '\u7528',
  19551. '\u2F65': '\u7530',
  19552. '\u2F66': '\u758B',
  19553. '\u2F67': '\u7592',
  19554. '\u2F68': '\u7676',
  19555. '\u2F69': '\u767D',
  19556. '\u2F6A': '\u76AE',
  19557. '\u2F6B': '\u76BF',
  19558. '\u2F6C': '\u76EE',
  19559. '\u2F6D': '\u77DB',
  19560. '\u2F6E': '\u77E2',
  19561. '\u2F6F': '\u77F3',
  19562. '\u2F70': '\u793A',
  19563. '\u2F71': '\u79B8',
  19564. '\u2F72': '\u79BE',
  19565. '\u2F73': '\u7A74',
  19566. '\u2F74': '\u7ACB',
  19567. '\u2F75': '\u7AF9',
  19568. '\u2F76': '\u7C73',
  19569. '\u2F77': '\u7CF8',
  19570. '\u2F78': '\u7F36',
  19571. '\u2F79': '\u7F51',
  19572. '\u2F7A': '\u7F8A',
  19573. '\u2F7B': '\u7FBD',
  19574. '\u2F7C': '\u8001',
  19575. '\u2F7D': '\u800C',
  19576. '\u2F7E': '\u8012',
  19577. '\u2F7F': '\u8033',
  19578. '\u2F80': '\u807F',
  19579. '\u2F81': '\u8089',
  19580. '\u2F82': '\u81E3',
  19581. '\u2F83': '\u81EA',
  19582. '\u2F84': '\u81F3',
  19583. '\u2F85': '\u81FC',
  19584. '\u2F86': '\u820C',
  19585. '\u2F87': '\u821B',
  19586. '\u2F88': '\u821F',
  19587. '\u2F89': '\u826E',
  19588. '\u2F8A': '\u8272',
  19589. '\u2F8B': '\u8278',
  19590. '\u2F8C': '\u864D',
  19591. '\u2F8D': '\u866B',
  19592. '\u2F8E': '\u8840',
  19593. '\u2F8F': '\u884C',
  19594. '\u2F90': '\u8863',
  19595. '\u2F91': '\u897E',
  19596. '\u2F92': '\u898B',
  19597. '\u2F93': '\u89D2',
  19598. '\u2F94': '\u8A00',
  19599. '\u2F95': '\u8C37',
  19600. '\u2F96': '\u8C46',
  19601. '\u2F97': '\u8C55',
  19602. '\u2F98': '\u8C78',
  19603. '\u2F99': '\u8C9D',
  19604. '\u2F9A': '\u8D64',
  19605. '\u2F9B': '\u8D70',
  19606. '\u2F9C': '\u8DB3',
  19607. '\u2F9D': '\u8EAB',
  19608. '\u2F9E': '\u8ECA',
  19609. '\u2F9F': '\u8F9B',
  19610. '\u2FA0': '\u8FB0',
  19611. '\u2FA1': '\u8FB5',
  19612. '\u2FA2': '\u9091',
  19613. '\u2FA3': '\u9149',
  19614. '\u2FA4': '\u91C6',
  19615. '\u2FA5': '\u91CC',
  19616. '\u2FA6': '\u91D1',
  19617. '\u2FA7': '\u9577',
  19618. '\u2FA8': '\u9580',
  19619. '\u2FA9': '\u961C',
  19620. '\u2FAA': '\u96B6',
  19621. '\u2FAB': '\u96B9',
  19622. '\u2FAC': '\u96E8',
  19623. '\u2FAD': '\u9751',
  19624. '\u2FAE': '\u975E',
  19625. '\u2FAF': '\u9762',
  19626. '\u2FB0': '\u9769',
  19627. '\u2FB1': '\u97CB',
  19628. '\u2FB2': '\u97ED',
  19629. '\u2FB3': '\u97F3',
  19630. '\u2FB4': '\u9801',
  19631. '\u2FB5': '\u98A8',
  19632. '\u2FB6': '\u98DB',
  19633. '\u2FB7': '\u98DF',
  19634. '\u2FB8': '\u9996',
  19635. '\u2FB9': '\u9999',
  19636. '\u2FBA': '\u99AC',
  19637. '\u2FBB': '\u9AA8',
  19638. '\u2FBC': '\u9AD8',
  19639. '\u2FBD': '\u9ADF',
  19640. '\u2FBE': '\u9B25',
  19641. '\u2FBF': '\u9B2F',
  19642. '\u2FC0': '\u9B32',
  19643. '\u2FC1': '\u9B3C',
  19644. '\u2FC2': '\u9B5A',
  19645. '\u2FC3': '\u9CE5',
  19646. '\u2FC4': '\u9E75',
  19647. '\u2FC5': '\u9E7F',
  19648. '\u2FC6': '\u9EA5',
  19649. '\u2FC7': '\u9EBB',
  19650. '\u2FC8': '\u9EC3',
  19651. '\u2FC9': '\u9ECD',
  19652. '\u2FCA': '\u9ED1',
  19653. '\u2FCB': '\u9EF9',
  19654. '\u2FCC': '\u9EFD',
  19655. '\u2FCD': '\u9F0E',
  19656. '\u2FCE': '\u9F13',
  19657. '\u2FCF': '\u9F20',
  19658. '\u2FD0': '\u9F3B',
  19659. '\u2FD1': '\u9F4A',
  19660. '\u2FD2': '\u9F52',
  19661. '\u2FD3': '\u9F8D',
  19662. '\u2FD4': '\u9F9C',
  19663. '\u2FD5': '\u9FA0',
  19664. '\u3036': '\u3012',
  19665. '\u3038': '\u5341',
  19666. '\u3039': '\u5344',
  19667. '\u303A': '\u5345',
  19668. '\u309B': '\u0020\u3099',
  19669. '\u309C': '\u0020\u309A',
  19670. '\u3131': '\u1100',
  19671. '\u3132': '\u1101',
  19672. '\u3133': '\u11AA',
  19673. '\u3134': '\u1102',
  19674. '\u3135': '\u11AC',
  19675. '\u3136': '\u11AD',
  19676. '\u3137': '\u1103',
  19677. '\u3138': '\u1104',
  19678. '\u3139': '\u1105',
  19679. '\u313A': '\u11B0',
  19680. '\u313B': '\u11B1',
  19681. '\u313C': '\u11B2',
  19682. '\u313D': '\u11B3',
  19683. '\u313E': '\u11B4',
  19684. '\u313F': '\u11B5',
  19685. '\u3140': '\u111A',
  19686. '\u3141': '\u1106',
  19687. '\u3142': '\u1107',
  19688. '\u3143': '\u1108',
  19689. '\u3144': '\u1121',
  19690. '\u3145': '\u1109',
  19691. '\u3146': '\u110A',
  19692. '\u3147': '\u110B',
  19693. '\u3148': '\u110C',
  19694. '\u3149': '\u110D',
  19695. '\u314A': '\u110E',
  19696. '\u314B': '\u110F',
  19697. '\u314C': '\u1110',
  19698. '\u314D': '\u1111',
  19699. '\u314E': '\u1112',
  19700. '\u314F': '\u1161',
  19701. '\u3150': '\u1162',
  19702. '\u3151': '\u1163',
  19703. '\u3152': '\u1164',
  19704. '\u3153': '\u1165',
  19705. '\u3154': '\u1166',
  19706. '\u3155': '\u1167',
  19707. '\u3156': '\u1168',
  19708. '\u3157': '\u1169',
  19709. '\u3158': '\u116A',
  19710. '\u3159': '\u116B',
  19711. '\u315A': '\u116C',
  19712. '\u315B': '\u116D',
  19713. '\u315C': '\u116E',
  19714. '\u315D': '\u116F',
  19715. '\u315E': '\u1170',
  19716. '\u315F': '\u1171',
  19717. '\u3160': '\u1172',
  19718. '\u3161': '\u1173',
  19719. '\u3162': '\u1174',
  19720. '\u3163': '\u1175',
  19721. '\u3164': '\u1160',
  19722. '\u3165': '\u1114',
  19723. '\u3166': '\u1115',
  19724. '\u3167': '\u11C7',
  19725. '\u3168': '\u11C8',
  19726. '\u3169': '\u11CC',
  19727. '\u316A': '\u11CE',
  19728. '\u316B': '\u11D3',
  19729. '\u316C': '\u11D7',
  19730. '\u316D': '\u11D9',
  19731. '\u316E': '\u111C',
  19732. '\u316F': '\u11DD',
  19733. '\u3170': '\u11DF',
  19734. '\u3171': '\u111D',
  19735. '\u3172': '\u111E',
  19736. '\u3173': '\u1120',
  19737. '\u3174': '\u1122',
  19738. '\u3175': '\u1123',
  19739. '\u3176': '\u1127',
  19740. '\u3177': '\u1129',
  19741. '\u3178': '\u112B',
  19742. '\u3179': '\u112C',
  19743. '\u317A': '\u112D',
  19744. '\u317B': '\u112E',
  19745. '\u317C': '\u112F',
  19746. '\u317D': '\u1132',
  19747. '\u317E': '\u1136',
  19748. '\u317F': '\u1140',
  19749. '\u3180': '\u1147',
  19750. '\u3181': '\u114C',
  19751. '\u3182': '\u11F1',
  19752. '\u3183': '\u11F2',
  19753. '\u3184': '\u1157',
  19754. '\u3185': '\u1158',
  19755. '\u3186': '\u1159',
  19756. '\u3187': '\u1184',
  19757. '\u3188': '\u1185',
  19758. '\u3189': '\u1188',
  19759. '\u318A': '\u1191',
  19760. '\u318B': '\u1192',
  19761. '\u318C': '\u1194',
  19762. '\u318D': '\u119E',
  19763. '\u318E': '\u11A1',
  19764. '\u3200': '\u0028\u1100\u0029',
  19765. '\u3201': '\u0028\u1102\u0029',
  19766. '\u3202': '\u0028\u1103\u0029',
  19767. '\u3203': '\u0028\u1105\u0029',
  19768. '\u3204': '\u0028\u1106\u0029',
  19769. '\u3205': '\u0028\u1107\u0029',
  19770. '\u3206': '\u0028\u1109\u0029',
  19771. '\u3207': '\u0028\u110B\u0029',
  19772. '\u3208': '\u0028\u110C\u0029',
  19773. '\u3209': '\u0028\u110E\u0029',
  19774. '\u320A': '\u0028\u110F\u0029',
  19775. '\u320B': '\u0028\u1110\u0029',
  19776. '\u320C': '\u0028\u1111\u0029',
  19777. '\u320D': '\u0028\u1112\u0029',
  19778. '\u320E': '\u0028\u1100\u1161\u0029',
  19779. '\u320F': '\u0028\u1102\u1161\u0029',
  19780. '\u3210': '\u0028\u1103\u1161\u0029',
  19781. '\u3211': '\u0028\u1105\u1161\u0029',
  19782. '\u3212': '\u0028\u1106\u1161\u0029',
  19783. '\u3213': '\u0028\u1107\u1161\u0029',
  19784. '\u3214': '\u0028\u1109\u1161\u0029',
  19785. '\u3215': '\u0028\u110B\u1161\u0029',
  19786. '\u3216': '\u0028\u110C\u1161\u0029',
  19787. '\u3217': '\u0028\u110E\u1161\u0029',
  19788. '\u3218': '\u0028\u110F\u1161\u0029',
  19789. '\u3219': '\u0028\u1110\u1161\u0029',
  19790. '\u321A': '\u0028\u1111\u1161\u0029',
  19791. '\u321B': '\u0028\u1112\u1161\u0029',
  19792. '\u321C': '\u0028\u110C\u116E\u0029',
  19793. '\u321D': '\u0028\u110B\u1169\u110C\u1165\u11AB\u0029',
  19794. '\u321E': '\u0028\u110B\u1169\u1112\u116E\u0029',
  19795. '\u3220': '\u0028\u4E00\u0029',
  19796. '\u3221': '\u0028\u4E8C\u0029',
  19797. '\u3222': '\u0028\u4E09\u0029',
  19798. '\u3223': '\u0028\u56DB\u0029',
  19799. '\u3224': '\u0028\u4E94\u0029',
  19800. '\u3225': '\u0028\u516D\u0029',
  19801. '\u3226': '\u0028\u4E03\u0029',
  19802. '\u3227': '\u0028\u516B\u0029',
  19803. '\u3228': '\u0028\u4E5D\u0029',
  19804. '\u3229': '\u0028\u5341\u0029',
  19805. '\u322A': '\u0028\u6708\u0029',
  19806. '\u322B': '\u0028\u706B\u0029',
  19807. '\u322C': '\u0028\u6C34\u0029',
  19808. '\u322D': '\u0028\u6728\u0029',
  19809. '\u322E': '\u0028\u91D1\u0029',
  19810. '\u322F': '\u0028\u571F\u0029',
  19811. '\u3230': '\u0028\u65E5\u0029',
  19812. '\u3231': '\u0028\u682A\u0029',
  19813. '\u3232': '\u0028\u6709\u0029',
  19814. '\u3233': '\u0028\u793E\u0029',
  19815. '\u3234': '\u0028\u540D\u0029',
  19816. '\u3235': '\u0028\u7279\u0029',
  19817. '\u3236': '\u0028\u8CA1\u0029',
  19818. '\u3237': '\u0028\u795D\u0029',
  19819. '\u3238': '\u0028\u52B4\u0029',
  19820. '\u3239': '\u0028\u4EE3\u0029',
  19821. '\u323A': '\u0028\u547C\u0029',
  19822. '\u323B': '\u0028\u5B66\u0029',
  19823. '\u323C': '\u0028\u76E3\u0029',
  19824. '\u323D': '\u0028\u4F01\u0029',
  19825. '\u323E': '\u0028\u8CC7\u0029',
  19826. '\u323F': '\u0028\u5354\u0029',
  19827. '\u3240': '\u0028\u796D\u0029',
  19828. '\u3241': '\u0028\u4F11\u0029',
  19829. '\u3242': '\u0028\u81EA\u0029',
  19830. '\u3243': '\u0028\u81F3\u0029',
  19831. '\u32C0': '\u0031\u6708',
  19832. '\u32C1': '\u0032\u6708',
  19833. '\u32C2': '\u0033\u6708',
  19834. '\u32C3': '\u0034\u6708',
  19835. '\u32C4': '\u0035\u6708',
  19836. '\u32C5': '\u0036\u6708',
  19837. '\u32C6': '\u0037\u6708',
  19838. '\u32C7': '\u0038\u6708',
  19839. '\u32C8': '\u0039\u6708',
  19840. '\u32C9': '\u0031\u0030\u6708',
  19841. '\u32CA': '\u0031\u0031\u6708',
  19842. '\u32CB': '\u0031\u0032\u6708',
  19843. '\u3358': '\u0030\u70B9',
  19844. '\u3359': '\u0031\u70B9',
  19845. '\u335A': '\u0032\u70B9',
  19846. '\u335B': '\u0033\u70B9',
  19847. '\u335C': '\u0034\u70B9',
  19848. '\u335D': '\u0035\u70B9',
  19849. '\u335E': '\u0036\u70B9',
  19850. '\u335F': '\u0037\u70B9',
  19851. '\u3360': '\u0038\u70B9',
  19852. '\u3361': '\u0039\u70B9',
  19853. '\u3362': '\u0031\u0030\u70B9',
  19854. '\u3363': '\u0031\u0031\u70B9',
  19855. '\u3364': '\u0031\u0032\u70B9',
  19856. '\u3365': '\u0031\u0033\u70B9',
  19857. '\u3366': '\u0031\u0034\u70B9',
  19858. '\u3367': '\u0031\u0035\u70B9',
  19859. '\u3368': '\u0031\u0036\u70B9',
  19860. '\u3369': '\u0031\u0037\u70B9',
  19861. '\u336A': '\u0031\u0038\u70B9',
  19862. '\u336B': '\u0031\u0039\u70B9',
  19863. '\u336C': '\u0032\u0030\u70B9',
  19864. '\u336D': '\u0032\u0031\u70B9',
  19865. '\u336E': '\u0032\u0032\u70B9',
  19866. '\u336F': '\u0032\u0033\u70B9',
  19867. '\u3370': '\u0032\u0034\u70B9',
  19868. '\u33E0': '\u0031\u65E5',
  19869. '\u33E1': '\u0032\u65E5',
  19870. '\u33E2': '\u0033\u65E5',
  19871. '\u33E3': '\u0034\u65E5',
  19872. '\u33E4': '\u0035\u65E5',
  19873. '\u33E5': '\u0036\u65E5',
  19874. '\u33E6': '\u0037\u65E5',
  19875. '\u33E7': '\u0038\u65E5',
  19876. '\u33E8': '\u0039\u65E5',
  19877. '\u33E9': '\u0031\u0030\u65E5',
  19878. '\u33EA': '\u0031\u0031\u65E5',
  19879. '\u33EB': '\u0031\u0032\u65E5',
  19880. '\u33EC': '\u0031\u0033\u65E5',
  19881. '\u33ED': '\u0031\u0034\u65E5',
  19882. '\u33EE': '\u0031\u0035\u65E5',
  19883. '\u33EF': '\u0031\u0036\u65E5',
  19884. '\u33F0': '\u0031\u0037\u65E5',
  19885. '\u33F1': '\u0031\u0038\u65E5',
  19886. '\u33F2': '\u0031\u0039\u65E5',
  19887. '\u33F3': '\u0032\u0030\u65E5',
  19888. '\u33F4': '\u0032\u0031\u65E5',
  19889. '\u33F5': '\u0032\u0032\u65E5',
  19890. '\u33F6': '\u0032\u0033\u65E5',
  19891. '\u33F7': '\u0032\u0034\u65E5',
  19892. '\u33F8': '\u0032\u0035\u65E5',
  19893. '\u33F9': '\u0032\u0036\u65E5',
  19894. '\u33FA': '\u0032\u0037\u65E5',
  19895. '\u33FB': '\u0032\u0038\u65E5',
  19896. '\u33FC': '\u0032\u0039\u65E5',
  19897. '\u33FD': '\u0033\u0030\u65E5',
  19898. '\u33FE': '\u0033\u0031\u65E5',
  19899. '\uFB00': '\u0066\u0066',
  19900. '\uFB01': '\u0066\u0069',
  19901. '\uFB02': '\u0066\u006C',
  19902. '\uFB03': '\u0066\u0066\u0069',
  19903. '\uFB04': '\u0066\u0066\u006C',
  19904. '\uFB05': '\u017F\u0074',
  19905. '\uFB06': '\u0073\u0074',
  19906. '\uFB13': '\u0574\u0576',
  19907. '\uFB14': '\u0574\u0565',
  19908. '\uFB15': '\u0574\u056B',
  19909. '\uFB16': '\u057E\u0576',
  19910. '\uFB17': '\u0574\u056D',
  19911. '\uFB4F': '\u05D0\u05DC',
  19912. '\uFB50': '\u0671',
  19913. '\uFB51': '\u0671',
  19914. '\uFB52': '\u067B',
  19915. '\uFB53': '\u067B',
  19916. '\uFB54': '\u067B',
  19917. '\uFB55': '\u067B',
  19918. '\uFB56': '\u067E',
  19919. '\uFB57': '\u067E',
  19920. '\uFB58': '\u067E',
  19921. '\uFB59': '\u067E',
  19922. '\uFB5A': '\u0680',
  19923. '\uFB5B': '\u0680',
  19924. '\uFB5C': '\u0680',
  19925. '\uFB5D': '\u0680',
  19926. '\uFB5E': '\u067A',
  19927. '\uFB5F': '\u067A',
  19928. '\uFB60': '\u067A',
  19929. '\uFB61': '\u067A',
  19930. '\uFB62': '\u067F',
  19931. '\uFB63': '\u067F',
  19932. '\uFB64': '\u067F',
  19933. '\uFB65': '\u067F',
  19934. '\uFB66': '\u0679',
  19935. '\uFB67': '\u0679',
  19936. '\uFB68': '\u0679',
  19937. '\uFB69': '\u0679',
  19938. '\uFB6A': '\u06A4',
  19939. '\uFB6B': '\u06A4',
  19940. '\uFB6C': '\u06A4',
  19941. '\uFB6D': '\u06A4',
  19942. '\uFB6E': '\u06A6',
  19943. '\uFB6F': '\u06A6',
  19944. '\uFB70': '\u06A6',
  19945. '\uFB71': '\u06A6',
  19946. '\uFB72': '\u0684',
  19947. '\uFB73': '\u0684',
  19948. '\uFB74': '\u0684',
  19949. '\uFB75': '\u0684',
  19950. '\uFB76': '\u0683',
  19951. '\uFB77': '\u0683',
  19952. '\uFB78': '\u0683',
  19953. '\uFB79': '\u0683',
  19954. '\uFB7A': '\u0686',
  19955. '\uFB7B': '\u0686',
  19956. '\uFB7C': '\u0686',
  19957. '\uFB7D': '\u0686',
  19958. '\uFB7E': '\u0687',
  19959. '\uFB7F': '\u0687',
  19960. '\uFB80': '\u0687',
  19961. '\uFB81': '\u0687',
  19962. '\uFB82': '\u068D',
  19963. '\uFB83': '\u068D',
  19964. '\uFB84': '\u068C',
  19965. '\uFB85': '\u068C',
  19966. '\uFB86': '\u068E',
  19967. '\uFB87': '\u068E',
  19968. '\uFB88': '\u0688',
  19969. '\uFB89': '\u0688',
  19970. '\uFB8A': '\u0698',
  19971. '\uFB8B': '\u0698',
  19972. '\uFB8C': '\u0691',
  19973. '\uFB8D': '\u0691',
  19974. '\uFB8E': '\u06A9',
  19975. '\uFB8F': '\u06A9',
  19976. '\uFB90': '\u06A9',
  19977. '\uFB91': '\u06A9',
  19978. '\uFB92': '\u06AF',
  19979. '\uFB93': '\u06AF',
  19980. '\uFB94': '\u06AF',
  19981. '\uFB95': '\u06AF',
  19982. '\uFB96': '\u06B3',
  19983. '\uFB97': '\u06B3',
  19984. '\uFB98': '\u06B3',
  19985. '\uFB99': '\u06B3',
  19986. '\uFB9A': '\u06B1',
  19987. '\uFB9B': '\u06B1',
  19988. '\uFB9C': '\u06B1',
  19989. '\uFB9D': '\u06B1',
  19990. '\uFB9E': '\u06BA',
  19991. '\uFB9F': '\u06BA',
  19992. '\uFBA0': '\u06BB',
  19993. '\uFBA1': '\u06BB',
  19994. '\uFBA2': '\u06BB',
  19995. '\uFBA3': '\u06BB',
  19996. '\uFBA4': '\u06C0',
  19997. '\uFBA5': '\u06C0',
  19998. '\uFBA6': '\u06C1',
  19999. '\uFBA7': '\u06C1',
  20000. '\uFBA8': '\u06C1',
  20001. '\uFBA9': '\u06C1',
  20002. '\uFBAA': '\u06BE',
  20003. '\uFBAB': '\u06BE',
  20004. '\uFBAC': '\u06BE',
  20005. '\uFBAD': '\u06BE',
  20006. '\uFBAE': '\u06D2',
  20007. '\uFBAF': '\u06D2',
  20008. '\uFBB0': '\u06D3',
  20009. '\uFBB1': '\u06D3',
  20010. '\uFBD3': '\u06AD',
  20011. '\uFBD4': '\u06AD',
  20012. '\uFBD5': '\u06AD',
  20013. '\uFBD6': '\u06AD',
  20014. '\uFBD7': '\u06C7',
  20015. '\uFBD8': '\u06C7',
  20016. '\uFBD9': '\u06C6',
  20017. '\uFBDA': '\u06C6',
  20018. '\uFBDB': '\u06C8',
  20019. '\uFBDC': '\u06C8',
  20020. '\uFBDD': '\u0677',
  20021. '\uFBDE': '\u06CB',
  20022. '\uFBDF': '\u06CB',
  20023. '\uFBE0': '\u06C5',
  20024. '\uFBE1': '\u06C5',
  20025. '\uFBE2': '\u06C9',
  20026. '\uFBE3': '\u06C9',
  20027. '\uFBE4': '\u06D0',
  20028. '\uFBE5': '\u06D0',
  20029. '\uFBE6': '\u06D0',
  20030. '\uFBE7': '\u06D0',
  20031. '\uFBE8': '\u0649',
  20032. '\uFBE9': '\u0649',
  20033. '\uFBEA': '\u0626\u0627',
  20034. '\uFBEB': '\u0626\u0627',
  20035. '\uFBEC': '\u0626\u06D5',
  20036. '\uFBED': '\u0626\u06D5',
  20037. '\uFBEE': '\u0626\u0648',
  20038. '\uFBEF': '\u0626\u0648',
  20039. '\uFBF0': '\u0626\u06C7',
  20040. '\uFBF1': '\u0626\u06C7',
  20041. '\uFBF2': '\u0626\u06C6',
  20042. '\uFBF3': '\u0626\u06C6',
  20043. '\uFBF4': '\u0626\u06C8',
  20044. '\uFBF5': '\u0626\u06C8',
  20045. '\uFBF6': '\u0626\u06D0',
  20046. '\uFBF7': '\u0626\u06D0',
  20047. '\uFBF8': '\u0626\u06D0',
  20048. '\uFBF9': '\u0626\u0649',
  20049. '\uFBFA': '\u0626\u0649',
  20050. '\uFBFB': '\u0626\u0649',
  20051. '\uFBFC': '\u06CC',
  20052. '\uFBFD': '\u06CC',
  20053. '\uFBFE': '\u06CC',
  20054. '\uFBFF': '\u06CC',
  20055. '\uFC00': '\u0626\u062C',
  20056. '\uFC01': '\u0626\u062D',
  20057. '\uFC02': '\u0626\u0645',
  20058. '\uFC03': '\u0626\u0649',
  20059. '\uFC04': '\u0626\u064A',
  20060. '\uFC05': '\u0628\u062C',
  20061. '\uFC06': '\u0628\u062D',
  20062. '\uFC07': '\u0628\u062E',
  20063. '\uFC08': '\u0628\u0645',
  20064. '\uFC09': '\u0628\u0649',
  20065. '\uFC0A': '\u0628\u064A',
  20066. '\uFC0B': '\u062A\u062C',
  20067. '\uFC0C': '\u062A\u062D',
  20068. '\uFC0D': '\u062A\u062E',
  20069. '\uFC0E': '\u062A\u0645',
  20070. '\uFC0F': '\u062A\u0649',
  20071. '\uFC10': '\u062A\u064A',
  20072. '\uFC11': '\u062B\u062C',
  20073. '\uFC12': '\u062B\u0645',
  20074. '\uFC13': '\u062B\u0649',
  20075. '\uFC14': '\u062B\u064A',
  20076. '\uFC15': '\u062C\u062D',
  20077. '\uFC16': '\u062C\u0645',
  20078. '\uFC17': '\u062D\u062C',
  20079. '\uFC18': '\u062D\u0645',
  20080. '\uFC19': '\u062E\u062C',
  20081. '\uFC1A': '\u062E\u062D',
  20082. '\uFC1B': '\u062E\u0645',
  20083. '\uFC1C': '\u0633\u062C',
  20084. '\uFC1D': '\u0633\u062D',
  20085. '\uFC1E': '\u0633\u062E',
  20086. '\uFC1F': '\u0633\u0645',
  20087. '\uFC20': '\u0635\u062D',
  20088. '\uFC21': '\u0635\u0645',
  20089. '\uFC22': '\u0636\u062C',
  20090. '\uFC23': '\u0636\u062D',
  20091. '\uFC24': '\u0636\u062E',
  20092. '\uFC25': '\u0636\u0645',
  20093. '\uFC26': '\u0637\u062D',
  20094. '\uFC27': '\u0637\u0645',
  20095. '\uFC28': '\u0638\u0645',
  20096. '\uFC29': '\u0639\u062C',
  20097. '\uFC2A': '\u0639\u0645',
  20098. '\uFC2B': '\u063A\u062C',
  20099. '\uFC2C': '\u063A\u0645',
  20100. '\uFC2D': '\u0641\u062C',
  20101. '\uFC2E': '\u0641\u062D',
  20102. '\uFC2F': '\u0641\u062E',
  20103. '\uFC30': '\u0641\u0645',
  20104. '\uFC31': '\u0641\u0649',
  20105. '\uFC32': '\u0641\u064A',
  20106. '\uFC33': '\u0642\u062D',
  20107. '\uFC34': '\u0642\u0645',
  20108. '\uFC35': '\u0642\u0649',
  20109. '\uFC36': '\u0642\u064A',
  20110. '\uFC37': '\u0643\u0627',
  20111. '\uFC38': '\u0643\u062C',
  20112. '\uFC39': '\u0643\u062D',
  20113. '\uFC3A': '\u0643\u062E',
  20114. '\uFC3B': '\u0643\u0644',
  20115. '\uFC3C': '\u0643\u0645',
  20116. '\uFC3D': '\u0643\u0649',
  20117. '\uFC3E': '\u0643\u064A',
  20118. '\uFC3F': '\u0644\u062C',
  20119. '\uFC40': '\u0644\u062D',
  20120. '\uFC41': '\u0644\u062E',
  20121. '\uFC42': '\u0644\u0645',
  20122. '\uFC43': '\u0644\u0649',
  20123. '\uFC44': '\u0644\u064A',
  20124. '\uFC45': '\u0645\u062C',
  20125. '\uFC46': '\u0645\u062D',
  20126. '\uFC47': '\u0645\u062E',
  20127. '\uFC48': '\u0645\u0645',
  20128. '\uFC49': '\u0645\u0649',
  20129. '\uFC4A': '\u0645\u064A',
  20130. '\uFC4B': '\u0646\u062C',
  20131. '\uFC4C': '\u0646\u062D',
  20132. '\uFC4D': '\u0646\u062E',
  20133. '\uFC4E': '\u0646\u0645',
  20134. '\uFC4F': '\u0646\u0649',
  20135. '\uFC50': '\u0646\u064A',
  20136. '\uFC51': '\u0647\u062C',
  20137. '\uFC52': '\u0647\u0645',
  20138. '\uFC53': '\u0647\u0649',
  20139. '\uFC54': '\u0647\u064A',
  20140. '\uFC55': '\u064A\u062C',
  20141. '\uFC56': '\u064A\u062D',
  20142. '\uFC57': '\u064A\u062E',
  20143. '\uFC58': '\u064A\u0645',
  20144. '\uFC59': '\u064A\u0649',
  20145. '\uFC5A': '\u064A\u064A',
  20146. '\uFC5B': '\u0630\u0670',
  20147. '\uFC5C': '\u0631\u0670',
  20148. '\uFC5D': '\u0649\u0670',
  20149. '\uFC5E': '\u0020\u064C\u0651',
  20150. '\uFC5F': '\u0020\u064D\u0651',
  20151. '\uFC60': '\u0020\u064E\u0651',
  20152. '\uFC61': '\u0020\u064F\u0651',
  20153. '\uFC62': '\u0020\u0650\u0651',
  20154. '\uFC63': '\u0020\u0651\u0670',
  20155. '\uFC64': '\u0626\u0631',
  20156. '\uFC65': '\u0626\u0632',
  20157. '\uFC66': '\u0626\u0645',
  20158. '\uFC67': '\u0626\u0646',
  20159. '\uFC68': '\u0626\u0649',
  20160. '\uFC69': '\u0626\u064A',
  20161. '\uFC6A': '\u0628\u0631',
  20162. '\uFC6B': '\u0628\u0632',
  20163. '\uFC6C': '\u0628\u0645',
  20164. '\uFC6D': '\u0628\u0646',
  20165. '\uFC6E': '\u0628\u0649',
  20166. '\uFC6F': '\u0628\u064A',
  20167. '\uFC70': '\u062A\u0631',
  20168. '\uFC71': '\u062A\u0632',
  20169. '\uFC72': '\u062A\u0645',
  20170. '\uFC73': '\u062A\u0646',
  20171. '\uFC74': '\u062A\u0649',
  20172. '\uFC75': '\u062A\u064A',
  20173. '\uFC76': '\u062B\u0631',
  20174. '\uFC77': '\u062B\u0632',
  20175. '\uFC78': '\u062B\u0645',
  20176. '\uFC79': '\u062B\u0646',
  20177. '\uFC7A': '\u062B\u0649',
  20178. '\uFC7B': '\u062B\u064A',
  20179. '\uFC7C': '\u0641\u0649',
  20180. '\uFC7D': '\u0641\u064A',
  20181. '\uFC7E': '\u0642\u0649',
  20182. '\uFC7F': '\u0642\u064A',
  20183. '\uFC80': '\u0643\u0627',
  20184. '\uFC81': '\u0643\u0644',
  20185. '\uFC82': '\u0643\u0645',
  20186. '\uFC83': '\u0643\u0649',
  20187. '\uFC84': '\u0643\u064A',
  20188. '\uFC85': '\u0644\u0645',
  20189. '\uFC86': '\u0644\u0649',
  20190. '\uFC87': '\u0644\u064A',
  20191. '\uFC88': '\u0645\u0627',
  20192. '\uFC89': '\u0645\u0645',
  20193. '\uFC8A': '\u0646\u0631',
  20194. '\uFC8B': '\u0646\u0632',
  20195. '\uFC8C': '\u0646\u0645',
  20196. '\uFC8D': '\u0646\u0646',
  20197. '\uFC8E': '\u0646\u0649',
  20198. '\uFC8F': '\u0646\u064A',
  20199. '\uFC90': '\u0649\u0670',
  20200. '\uFC91': '\u064A\u0631',
  20201. '\uFC92': '\u064A\u0632',
  20202. '\uFC93': '\u064A\u0645',
  20203. '\uFC94': '\u064A\u0646',
  20204. '\uFC95': '\u064A\u0649',
  20205. '\uFC96': '\u064A\u064A',
  20206. '\uFC97': '\u0626\u062C',
  20207. '\uFC98': '\u0626\u062D',
  20208. '\uFC99': '\u0626\u062E',
  20209. '\uFC9A': '\u0626\u0645',
  20210. '\uFC9B': '\u0626\u0647',
  20211. '\uFC9C': '\u0628\u062C',
  20212. '\uFC9D': '\u0628\u062D',
  20213. '\uFC9E': '\u0628\u062E',
  20214. '\uFC9F': '\u0628\u0645',
  20215. '\uFCA0': '\u0628\u0647',
  20216. '\uFCA1': '\u062A\u062C',
  20217. '\uFCA2': '\u062A\u062D',
  20218. '\uFCA3': '\u062A\u062E',
  20219. '\uFCA4': '\u062A\u0645',
  20220. '\uFCA5': '\u062A\u0647',
  20221. '\uFCA6': '\u062B\u0645',
  20222. '\uFCA7': '\u062C\u062D',
  20223. '\uFCA8': '\u062C\u0645',
  20224. '\uFCA9': '\u062D\u062C',
  20225. '\uFCAA': '\u062D\u0645',
  20226. '\uFCAB': '\u062E\u062C',
  20227. '\uFCAC': '\u062E\u0645',
  20228. '\uFCAD': '\u0633\u062C',
  20229. '\uFCAE': '\u0633\u062D',
  20230. '\uFCAF': '\u0633\u062E',
  20231. '\uFCB0': '\u0633\u0645',
  20232. '\uFCB1': '\u0635\u062D',
  20233. '\uFCB2': '\u0635\u062E',
  20234. '\uFCB3': '\u0635\u0645',
  20235. '\uFCB4': '\u0636\u062C',
  20236. '\uFCB5': '\u0636\u062D',
  20237. '\uFCB6': '\u0636\u062E',
  20238. '\uFCB7': '\u0636\u0645',
  20239. '\uFCB8': '\u0637\u062D',
  20240. '\uFCB9': '\u0638\u0645',
  20241. '\uFCBA': '\u0639\u062C',
  20242. '\uFCBB': '\u0639\u0645',
  20243. '\uFCBC': '\u063A\u062C',
  20244. '\uFCBD': '\u063A\u0645',
  20245. '\uFCBE': '\u0641\u062C',
  20246. '\uFCBF': '\u0641\u062D',
  20247. '\uFCC0': '\u0641\u062E',
  20248. '\uFCC1': '\u0641\u0645',
  20249. '\uFCC2': '\u0642\u062D',
  20250. '\uFCC3': '\u0642\u0645',
  20251. '\uFCC4': '\u0643\u062C',
  20252. '\uFCC5': '\u0643\u062D',
  20253. '\uFCC6': '\u0643\u062E',
  20254. '\uFCC7': '\u0643\u0644',
  20255. '\uFCC8': '\u0643\u0645',
  20256. '\uFCC9': '\u0644\u062C',
  20257. '\uFCCA': '\u0644\u062D',
  20258. '\uFCCB': '\u0644\u062E',
  20259. '\uFCCC': '\u0644\u0645',
  20260. '\uFCCD': '\u0644\u0647',
  20261. '\uFCCE': '\u0645\u062C',
  20262. '\uFCCF': '\u0645\u062D',
  20263. '\uFCD0': '\u0645\u062E',
  20264. '\uFCD1': '\u0645\u0645',
  20265. '\uFCD2': '\u0646\u062C',
  20266. '\uFCD3': '\u0646\u062D',
  20267. '\uFCD4': '\u0646\u062E',
  20268. '\uFCD5': '\u0646\u0645',
  20269. '\uFCD6': '\u0646\u0647',
  20270. '\uFCD7': '\u0647\u062C',
  20271. '\uFCD8': '\u0647\u0645',
  20272. '\uFCD9': '\u0647\u0670',
  20273. '\uFCDA': '\u064A\u062C',
  20274. '\uFCDB': '\u064A\u062D',
  20275. '\uFCDC': '\u064A\u062E',
  20276. '\uFCDD': '\u064A\u0645',
  20277. '\uFCDE': '\u064A\u0647',
  20278. '\uFCDF': '\u0626\u0645',
  20279. '\uFCE0': '\u0626\u0647',
  20280. '\uFCE1': '\u0628\u0645',
  20281. '\uFCE2': '\u0628\u0647',
  20282. '\uFCE3': '\u062A\u0645',
  20283. '\uFCE4': '\u062A\u0647',
  20284. '\uFCE5': '\u062B\u0645',
  20285. '\uFCE6': '\u062B\u0647',
  20286. '\uFCE7': '\u0633\u0645',
  20287. '\uFCE8': '\u0633\u0647',
  20288. '\uFCE9': '\u0634\u0645',
  20289. '\uFCEA': '\u0634\u0647',
  20290. '\uFCEB': '\u0643\u0644',
  20291. '\uFCEC': '\u0643\u0645',
  20292. '\uFCED': '\u0644\u0645',
  20293. '\uFCEE': '\u0646\u0645',
  20294. '\uFCEF': '\u0646\u0647',
  20295. '\uFCF0': '\u064A\u0645',
  20296. '\uFCF1': '\u064A\u0647',
  20297. '\uFCF2': '\u0640\u064E\u0651',
  20298. '\uFCF3': '\u0640\u064F\u0651',
  20299. '\uFCF4': '\u0640\u0650\u0651',
  20300. '\uFCF5': '\u0637\u0649',
  20301. '\uFCF6': '\u0637\u064A',
  20302. '\uFCF7': '\u0639\u0649',
  20303. '\uFCF8': '\u0639\u064A',
  20304. '\uFCF9': '\u063A\u0649',
  20305. '\uFCFA': '\u063A\u064A',
  20306. '\uFCFB': '\u0633\u0649',
  20307. '\uFCFC': '\u0633\u064A',
  20308. '\uFCFD': '\u0634\u0649',
  20309. '\uFCFE': '\u0634\u064A',
  20310. '\uFCFF': '\u062D\u0649',
  20311. '\uFD00': '\u062D\u064A',
  20312. '\uFD01': '\u062C\u0649',
  20313. '\uFD02': '\u062C\u064A',
  20314. '\uFD03': '\u062E\u0649',
  20315. '\uFD04': '\u062E\u064A',
  20316. '\uFD05': '\u0635\u0649',
  20317. '\uFD06': '\u0635\u064A',
  20318. '\uFD07': '\u0636\u0649',
  20319. '\uFD08': '\u0636\u064A',
  20320. '\uFD09': '\u0634\u062C',
  20321. '\uFD0A': '\u0634\u062D',
  20322. '\uFD0B': '\u0634\u062E',
  20323. '\uFD0C': '\u0634\u0645',
  20324. '\uFD0D': '\u0634\u0631',
  20325. '\uFD0E': '\u0633\u0631',
  20326. '\uFD0F': '\u0635\u0631',
  20327. '\uFD10': '\u0636\u0631',
  20328. '\uFD11': '\u0637\u0649',
  20329. '\uFD12': '\u0637\u064A',
  20330. '\uFD13': '\u0639\u0649',
  20331. '\uFD14': '\u0639\u064A',
  20332. '\uFD15': '\u063A\u0649',
  20333. '\uFD16': '\u063A\u064A',
  20334. '\uFD17': '\u0633\u0649',
  20335. '\uFD18': '\u0633\u064A',
  20336. '\uFD19': '\u0634\u0649',
  20337. '\uFD1A': '\u0634\u064A',
  20338. '\uFD1B': '\u062D\u0649',
  20339. '\uFD1C': '\u062D\u064A',
  20340. '\uFD1D': '\u062C\u0649',
  20341. '\uFD1E': '\u062C\u064A',
  20342. '\uFD1F': '\u062E\u0649',
  20343. '\uFD20': '\u062E\u064A',
  20344. '\uFD21': '\u0635\u0649',
  20345. '\uFD22': '\u0635\u064A',
  20346. '\uFD23': '\u0636\u0649',
  20347. '\uFD24': '\u0636\u064A',
  20348. '\uFD25': '\u0634\u062C',
  20349. '\uFD26': '\u0634\u062D',
  20350. '\uFD27': '\u0634\u062E',
  20351. '\uFD28': '\u0634\u0645',
  20352. '\uFD29': '\u0634\u0631',
  20353. '\uFD2A': '\u0633\u0631',
  20354. '\uFD2B': '\u0635\u0631',
  20355. '\uFD2C': '\u0636\u0631',
  20356. '\uFD2D': '\u0634\u062C',
  20357. '\uFD2E': '\u0634\u062D',
  20358. '\uFD2F': '\u0634\u062E',
  20359. '\uFD30': '\u0634\u0645',
  20360. '\uFD31': '\u0633\u0647',
  20361. '\uFD32': '\u0634\u0647',
  20362. '\uFD33': '\u0637\u0645',
  20363. '\uFD34': '\u0633\u062C',
  20364. '\uFD35': '\u0633\u062D',
  20365. '\uFD36': '\u0633\u062E',
  20366. '\uFD37': '\u0634\u062C',
  20367. '\uFD38': '\u0634\u062D',
  20368. '\uFD39': '\u0634\u062E',
  20369. '\uFD3A': '\u0637\u0645',
  20370. '\uFD3B': '\u0638\u0645',
  20371. '\uFD3C': '\u0627\u064B',
  20372. '\uFD3D': '\u0627\u064B',
  20373. '\uFD50': '\u062A\u062C\u0645',
  20374. '\uFD51': '\u062A\u062D\u062C',
  20375. '\uFD52': '\u062A\u062D\u062C',
  20376. '\uFD53': '\u062A\u062D\u0645',
  20377. '\uFD54': '\u062A\u062E\u0645',
  20378. '\uFD55': '\u062A\u0645\u062C',
  20379. '\uFD56': '\u062A\u0645\u062D',
  20380. '\uFD57': '\u062A\u0645\u062E',
  20381. '\uFD58': '\u062C\u0645\u062D',
  20382. '\uFD59': '\u062C\u0645\u062D',
  20383. '\uFD5A': '\u062D\u0645\u064A',
  20384. '\uFD5B': '\u062D\u0645\u0649',
  20385. '\uFD5C': '\u0633\u062D\u062C',
  20386. '\uFD5D': '\u0633\u062C\u062D',
  20387. '\uFD5E': '\u0633\u062C\u0649',
  20388. '\uFD5F': '\u0633\u0645\u062D',
  20389. '\uFD60': '\u0633\u0645\u062D',
  20390. '\uFD61': '\u0633\u0645\u062C',
  20391. '\uFD62': '\u0633\u0645\u0645',
  20392. '\uFD63': '\u0633\u0645\u0645',
  20393. '\uFD64': '\u0635\u062D\u062D',
  20394. '\uFD65': '\u0635\u062D\u062D',
  20395. '\uFD66': '\u0635\u0645\u0645',
  20396. '\uFD67': '\u0634\u062D\u0645',
  20397. '\uFD68': '\u0634\u062D\u0645',
  20398. '\uFD69': '\u0634\u062C\u064A',
  20399. '\uFD6A': '\u0634\u0645\u062E',
  20400. '\uFD6B': '\u0634\u0645\u062E',
  20401. '\uFD6C': '\u0634\u0645\u0645',
  20402. '\uFD6D': '\u0634\u0645\u0645',
  20403. '\uFD6E': '\u0636\u062D\u0649',
  20404. '\uFD6F': '\u0636\u062E\u0645',
  20405. '\uFD70': '\u0636\u062E\u0645',
  20406. '\uFD71': '\u0637\u0645\u062D',
  20407. '\uFD72': '\u0637\u0645\u062D',
  20408. '\uFD73': '\u0637\u0645\u0645',
  20409. '\uFD74': '\u0637\u0645\u064A',
  20410. '\uFD75': '\u0639\u062C\u0645',
  20411. '\uFD76': '\u0639\u0645\u0645',
  20412. '\uFD77': '\u0639\u0645\u0645',
  20413. '\uFD78': '\u0639\u0645\u0649',
  20414. '\uFD79': '\u063A\u0645\u0645',
  20415. '\uFD7A': '\u063A\u0645\u064A',
  20416. '\uFD7B': '\u063A\u0645\u0649',
  20417. '\uFD7C': '\u0641\u062E\u0645',
  20418. '\uFD7D': '\u0641\u062E\u0645',
  20419. '\uFD7E': '\u0642\u0645\u062D',
  20420. '\uFD7F': '\u0642\u0645\u0645',
  20421. '\uFD80': '\u0644\u062D\u0645',
  20422. '\uFD81': '\u0644\u062D\u064A',
  20423. '\uFD82': '\u0644\u062D\u0649',
  20424. '\uFD83': '\u0644\u062C\u062C',
  20425. '\uFD84': '\u0644\u062C\u062C',
  20426. '\uFD85': '\u0644\u062E\u0645',
  20427. '\uFD86': '\u0644\u062E\u0645',
  20428. '\uFD87': '\u0644\u0645\u062D',
  20429. '\uFD88': '\u0644\u0645\u062D',
  20430. '\uFD89': '\u0645\u062D\u062C',
  20431. '\uFD8A': '\u0645\u062D\u0645',
  20432. '\uFD8B': '\u0645\u062D\u064A',
  20433. '\uFD8C': '\u0645\u062C\u062D',
  20434. '\uFD8D': '\u0645\u062C\u0645',
  20435. '\uFD8E': '\u0645\u062E\u062C',
  20436. '\uFD8F': '\u0645\u062E\u0645',
  20437. '\uFD92': '\u0645\u062C\u062E',
  20438. '\uFD93': '\u0647\u0645\u062C',
  20439. '\uFD94': '\u0647\u0645\u0645',
  20440. '\uFD95': '\u0646\u062D\u0645',
  20441. '\uFD96': '\u0646\u062D\u0649',
  20442. '\uFD97': '\u0646\u062C\u0645',
  20443. '\uFD98': '\u0646\u062C\u0645',
  20444. '\uFD99': '\u0646\u062C\u0649',
  20445. '\uFD9A': '\u0646\u0645\u064A',
  20446. '\uFD9B': '\u0646\u0645\u0649',
  20447. '\uFD9C': '\u064A\u0645\u0645',
  20448. '\uFD9D': '\u064A\u0645\u0645',
  20449. '\uFD9E': '\u0628\u062E\u064A',
  20450. '\uFD9F': '\u062A\u062C\u064A',
  20451. '\uFDA0': '\u062A\u062C\u0649',
  20452. '\uFDA1': '\u062A\u062E\u064A',
  20453. '\uFDA2': '\u062A\u062E\u0649',
  20454. '\uFDA3': '\u062A\u0645\u064A',
  20455. '\uFDA4': '\u062A\u0645\u0649',
  20456. '\uFDA5': '\u062C\u0645\u064A',
  20457. '\uFDA6': '\u062C\u062D\u0649',
  20458. '\uFDA7': '\u062C\u0645\u0649',
  20459. '\uFDA8': '\u0633\u062E\u0649',
  20460. '\uFDA9': '\u0635\u062D\u064A',
  20461. '\uFDAA': '\u0634\u062D\u064A',
  20462. '\uFDAB': '\u0636\u062D\u064A',
  20463. '\uFDAC': '\u0644\u062C\u064A',
  20464. '\uFDAD': '\u0644\u0645\u064A',
  20465. '\uFDAE': '\u064A\u062D\u064A',
  20466. '\uFDAF': '\u064A\u062C\u064A',
  20467. '\uFDB0': '\u064A\u0645\u064A',
  20468. '\uFDB1': '\u0645\u0645\u064A',
  20469. '\uFDB2': '\u0642\u0645\u064A',
  20470. '\uFDB3': '\u0646\u062D\u064A',
  20471. '\uFDB4': '\u0642\u0645\u062D',
  20472. '\uFDB5': '\u0644\u062D\u0645',
  20473. '\uFDB6': '\u0639\u0645\u064A',
  20474. '\uFDB7': '\u0643\u0645\u064A',
  20475. '\uFDB8': '\u0646\u062C\u062D',
  20476. '\uFDB9': '\u0645\u062E\u064A',
  20477. '\uFDBA': '\u0644\u062C\u0645',
  20478. '\uFDBB': '\u0643\u0645\u0645',
  20479. '\uFDBC': '\u0644\u062C\u0645',
  20480. '\uFDBD': '\u0646\u062C\u062D',
  20481. '\uFDBE': '\u062C\u062D\u064A',
  20482. '\uFDBF': '\u062D\u062C\u064A',
  20483. '\uFDC0': '\u0645\u062C\u064A',
  20484. '\uFDC1': '\u0641\u0645\u064A',
  20485. '\uFDC2': '\u0628\u062D\u064A',
  20486. '\uFDC3': '\u0643\u0645\u0645',
  20487. '\uFDC4': '\u0639\u062C\u0645',
  20488. '\uFDC5': '\u0635\u0645\u0645',
  20489. '\uFDC6': '\u0633\u062E\u064A',
  20490. '\uFDC7': '\u0646\u062C\u064A',
  20491. '\uFE49': '\u203E',
  20492. '\uFE4A': '\u203E',
  20493. '\uFE4B': '\u203E',
  20494. '\uFE4C': '\u203E',
  20495. '\uFE4D': '\u005F',
  20496. '\uFE4E': '\u005F',
  20497. '\uFE4F': '\u005F',
  20498. '\uFE80': '\u0621',
  20499. '\uFE81': '\u0622',
  20500. '\uFE82': '\u0622',
  20501. '\uFE83': '\u0623',
  20502. '\uFE84': '\u0623',
  20503. '\uFE85': '\u0624',
  20504. '\uFE86': '\u0624',
  20505. '\uFE87': '\u0625',
  20506. '\uFE88': '\u0625',
  20507. '\uFE89': '\u0626',
  20508. '\uFE8A': '\u0626',
  20509. '\uFE8B': '\u0626',
  20510. '\uFE8C': '\u0626',
  20511. '\uFE8D': '\u0627',
  20512. '\uFE8E': '\u0627',
  20513. '\uFE8F': '\u0628',
  20514. '\uFE90': '\u0628',
  20515. '\uFE91': '\u0628',
  20516. '\uFE92': '\u0628',
  20517. '\uFE93': '\u0629',
  20518. '\uFE94': '\u0629',
  20519. '\uFE95': '\u062A',
  20520. '\uFE96': '\u062A',
  20521. '\uFE97': '\u062A',
  20522. '\uFE98': '\u062A',
  20523. '\uFE99': '\u062B',
  20524. '\uFE9A': '\u062B',
  20525. '\uFE9B': '\u062B',
  20526. '\uFE9C': '\u062B',
  20527. '\uFE9D': '\u062C',
  20528. '\uFE9E': '\u062C',
  20529. '\uFE9F': '\u062C',
  20530. '\uFEA0': '\u062C',
  20531. '\uFEA1': '\u062D',
  20532. '\uFEA2': '\u062D',
  20533. '\uFEA3': '\u062D',
  20534. '\uFEA4': '\u062D',
  20535. '\uFEA5': '\u062E',
  20536. '\uFEA6': '\u062E',
  20537. '\uFEA7': '\u062E',
  20538. '\uFEA8': '\u062E',
  20539. '\uFEA9': '\u062F',
  20540. '\uFEAA': '\u062F',
  20541. '\uFEAB': '\u0630',
  20542. '\uFEAC': '\u0630',
  20543. '\uFEAD': '\u0631',
  20544. '\uFEAE': '\u0631',
  20545. '\uFEAF': '\u0632',
  20546. '\uFEB0': '\u0632',
  20547. '\uFEB1': '\u0633',
  20548. '\uFEB2': '\u0633',
  20549. '\uFEB3': '\u0633',
  20550. '\uFEB4': '\u0633',
  20551. '\uFEB5': '\u0634',
  20552. '\uFEB6': '\u0634',
  20553. '\uFEB7': '\u0634',
  20554. '\uFEB8': '\u0634',
  20555. '\uFEB9': '\u0635',
  20556. '\uFEBA': '\u0635',
  20557. '\uFEBB': '\u0635',
  20558. '\uFEBC': '\u0635',
  20559. '\uFEBD': '\u0636',
  20560. '\uFEBE': '\u0636',
  20561. '\uFEBF': '\u0636',
  20562. '\uFEC0': '\u0636',
  20563. '\uFEC1': '\u0637',
  20564. '\uFEC2': '\u0637',
  20565. '\uFEC3': '\u0637',
  20566. '\uFEC4': '\u0637',
  20567. '\uFEC5': '\u0638',
  20568. '\uFEC6': '\u0638',
  20569. '\uFEC7': '\u0638',
  20570. '\uFEC8': '\u0638',
  20571. '\uFEC9': '\u0639',
  20572. '\uFECA': '\u0639',
  20573. '\uFECB': '\u0639',
  20574. '\uFECC': '\u0639',
  20575. '\uFECD': '\u063A',
  20576. '\uFECE': '\u063A',
  20577. '\uFECF': '\u063A',
  20578. '\uFED0': '\u063A',
  20579. '\uFED1': '\u0641',
  20580. '\uFED2': '\u0641',
  20581. '\uFED3': '\u0641',
  20582. '\uFED4': '\u0641',
  20583. '\uFED5': '\u0642',
  20584. '\uFED6': '\u0642',
  20585. '\uFED7': '\u0642',
  20586. '\uFED8': '\u0642',
  20587. '\uFED9': '\u0643',
  20588. '\uFEDA': '\u0643',
  20589. '\uFEDB': '\u0643',
  20590. '\uFEDC': '\u0643',
  20591. '\uFEDD': '\u0644',
  20592. '\uFEDE': '\u0644',
  20593. '\uFEDF': '\u0644',
  20594. '\uFEE0': '\u0644',
  20595. '\uFEE1': '\u0645',
  20596. '\uFEE2': '\u0645',
  20597. '\uFEE3': '\u0645',
  20598. '\uFEE4': '\u0645',
  20599. '\uFEE5': '\u0646',
  20600. '\uFEE6': '\u0646',
  20601. '\uFEE7': '\u0646',
  20602. '\uFEE8': '\u0646',
  20603. '\uFEE9': '\u0647',
  20604. '\uFEEA': '\u0647',
  20605. '\uFEEB': '\u0647',
  20606. '\uFEEC': '\u0647',
  20607. '\uFEED': '\u0648',
  20608. '\uFEEE': '\u0648',
  20609. '\uFEEF': '\u0649',
  20610. '\uFEF0': '\u0649',
  20611. '\uFEF1': '\u064A',
  20612. '\uFEF2': '\u064A',
  20613. '\uFEF3': '\u064A',
  20614. '\uFEF4': '\u064A',
  20615. '\uFEF5': '\u0644\u0622',
  20616. '\uFEF6': '\u0644\u0622',
  20617. '\uFEF7': '\u0644\u0623',
  20618. '\uFEF8': '\u0644\u0623',
  20619. '\uFEF9': '\u0644\u0625',
  20620. '\uFEFA': '\u0644\u0625',
  20621. '\uFEFB': '\u0644\u0627',
  20622. '\uFEFC': '\u0644\u0627'
  20623. };
  20624. function reverseIfRtl(chars) {
  20625. var charsLength = chars.length;
  20626. //reverse an arabic ligature
  20627. if (charsLength <= 1 || !isRTLRangeFor(chars.charCodeAt(0))) {
  20628. return chars;
  20629. }
  20630. var s = '';
  20631. for (var ii = charsLength - 1; ii >= 0; ii--) {
  20632. s += chars[ii];
  20633. }
  20634. return s;
  20635. }
  20636. function adjustWidths(properties) {
  20637. if (properties.fontMatrix[0] === FONT_IDENTITY_MATRIX[0]) {
  20638. return;
  20639. }
  20640. // adjusting width to fontMatrix scale
  20641. var scale = 0.001 / properties.fontMatrix[0];
  20642. var glyphsWidths = properties.widths;
  20643. for (var glyph in glyphsWidths) {
  20644. glyphsWidths[glyph] *= scale;
  20645. }
  20646. properties.defaultWidth *= scale;
  20647. }
  20648. function getFontType(type, subtype) {
  20649. switch (type) {
  20650. case 'Type1':
  20651. return subtype === 'Type1C' ? FontType.TYPE1C : FontType.TYPE1;
  20652. case 'CIDFontType0':
  20653. return subtype === 'CIDFontType0C' ? FontType.CIDFONTTYPE0C :
  20654. FontType.CIDFONTTYPE0;
  20655. case 'OpenType':
  20656. return FontType.OPENTYPE;
  20657. case 'TrueType':
  20658. return FontType.TRUETYPE;
  20659. case 'CIDFontType2':
  20660. return FontType.CIDFONTTYPE2;
  20661. case 'MMType1':
  20662. return FontType.MMTYPE1;
  20663. case 'Type0':
  20664. return FontType.TYPE0;
  20665. default:
  20666. return FontType.UNKNOWN;
  20667. }
  20668. }
  20669. var Glyph = (function GlyphClosure() {
  20670. function Glyph(fontChar, unicode, accent, width, vmetric, operatorListId) {
  20671. this.fontChar = fontChar;
  20672. this.unicode = unicode;
  20673. this.accent = accent;
  20674. this.width = width;
  20675. this.vmetric = vmetric;
  20676. this.operatorListId = operatorListId;
  20677. }
  20678. Glyph.prototype.matchesForCache =
  20679. function(fontChar, unicode, accent, width, vmetric, operatorListId) {
  20680. return this.fontChar === fontChar &&
  20681. this.unicode === unicode &&
  20682. this.accent === accent &&
  20683. this.width === width &&
  20684. this.vmetric === vmetric &&
  20685. this.operatorListId === operatorListId;
  20686. };
  20687. return Glyph;
  20688. })();
  20689. var ToUnicodeMap = (function ToUnicodeMapClosure() {
  20690. function ToUnicodeMap(cmap) {
  20691. // The elements of this._map can be integers or strings, depending on how
  20692. // |cmap| was created.
  20693. this._map = cmap;
  20694. }
  20695. ToUnicodeMap.prototype = {
  20696. get length() {
  20697. return this._map.length;
  20698. },
  20699. forEach: function(callback) {
  20700. for (var charCode in this._map) {
  20701. callback(charCode, this._map[charCode].charCodeAt(0));
  20702. }
  20703. },
  20704. has: function(i) {
  20705. return this._map[i] !== undefined;
  20706. },
  20707. get: function(i) {
  20708. return this._map[i];
  20709. },
  20710. charCodeOf: function(v) {
  20711. return this._map.indexOf(v);
  20712. }
  20713. };
  20714. return ToUnicodeMap;
  20715. })();
  20716. var IdentityToUnicodeMap = (function IdentityToUnicodeMapClosure() {
  20717. function IdentityToUnicodeMap(firstChar, lastChar) {
  20718. this.firstChar = firstChar;
  20719. this.lastChar = lastChar;
  20720. }
  20721. IdentityToUnicodeMap.prototype = {
  20722. get length() {
  20723. return (this.lastChar + 1) - this.firstChar;
  20724. },
  20725. forEach: function (callback) {
  20726. for (var i = this.firstChar, ii = this.lastChar; i <= ii; i++) {
  20727. callback(i, i);
  20728. }
  20729. },
  20730. has: function (i) {
  20731. return this.firstChar <= i && i <= this.lastChar;
  20732. },
  20733. get: function (i) {
  20734. if (this.firstChar <= i && i <= this.lastChar) {
  20735. return String.fromCharCode(i);
  20736. }
  20737. return undefined;
  20738. },
  20739. charCodeOf: function (v) {
  20740. error('should not call .charCodeOf');
  20741. }
  20742. };
  20743. return IdentityToUnicodeMap;
  20744. })();
  20745. var OpenTypeFileBuilder = (function OpenTypeFileBuilderClosure() {
  20746. function writeInt16(dest, offset, num) {
  20747. dest[offset] = (num >> 8) & 0xFF;
  20748. dest[offset + 1] = num & 0xFF;
  20749. }
  20750. function writeInt32(dest, offset, num) {
  20751. dest[offset] = (num >> 24) & 0xFF;
  20752. dest[offset + 1] = (num >> 16) & 0xFF;
  20753. dest[offset + 2] = (num >> 8) & 0xFF;
  20754. dest[offset + 3] = num & 0xFF;
  20755. }
  20756. function writeData(dest, offset, data) {
  20757. var i, ii;
  20758. if (data instanceof Uint8Array) {
  20759. dest.set(data, offset);
  20760. } else if (typeof data === 'string') {
  20761. for (i = 0, ii = data.length; i < ii; i++) {
  20762. dest[offset++] = data.charCodeAt(i) & 0xFF;
  20763. }
  20764. } else {
  20765. // treating everything else as array
  20766. for (i = 0, ii = data.length; i < ii; i++) {
  20767. dest[offset++] = data[i] & 0xFF;
  20768. }
  20769. }
  20770. }
  20771. function OpenTypeFileBuilder(sfnt) {
  20772. this.sfnt = sfnt;
  20773. this.tables = Object.create(null);
  20774. }
  20775. OpenTypeFileBuilder.getSearchParams =
  20776. function OpenTypeFileBuilder_getSearchParams(entriesCount, entrySize) {
  20777. var maxPower2 = 1, log2 = 0;
  20778. while ((maxPower2 ^ entriesCount) > maxPower2) {
  20779. maxPower2 <<= 1;
  20780. log2++;
  20781. }
  20782. var searchRange = maxPower2 * entrySize;
  20783. return {
  20784. range: searchRange,
  20785. entry: log2,
  20786. rangeShift: entrySize * entriesCount - searchRange
  20787. };
  20788. };
  20789. var OTF_HEADER_SIZE = 12;
  20790. var OTF_TABLE_ENTRY_SIZE = 16;
  20791. OpenTypeFileBuilder.prototype = {
  20792. toArray: function OpenTypeFileBuilder_toArray() {
  20793. var sfnt = this.sfnt;
  20794. // Tables needs to be written by ascendant alphabetic order
  20795. var tables = this.tables;
  20796. var tablesNames = Object.keys(tables);
  20797. tablesNames.sort();
  20798. var numTables = tablesNames.length;
  20799. var i, j, jj, table, tableName;
  20800. // layout the tables data
  20801. var offset = OTF_HEADER_SIZE + numTables * OTF_TABLE_ENTRY_SIZE;
  20802. var tableOffsets = [offset];
  20803. for (i = 0; i < numTables; i++) {
  20804. table = tables[tablesNames[i]];
  20805. var paddedLength = ((table.length + 3) & ~3) >>> 0;
  20806. offset += paddedLength;
  20807. tableOffsets.push(offset);
  20808. }
  20809. var file = new Uint8Array(offset);
  20810. // write the table data first (mostly for checksum)
  20811. for (i = 0; i < numTables; i++) {
  20812. table = tables[tablesNames[i]];
  20813. writeData(file, tableOffsets[i], table);
  20814. }
  20815. // sfnt version (4 bytes)
  20816. if (sfnt === 'true') {
  20817. // Windows hates the Mac TrueType sfnt version number
  20818. sfnt = string32(0x00010000);
  20819. }
  20820. file[0] = sfnt.charCodeAt(0) & 0xFF;
  20821. file[1] = sfnt.charCodeAt(1) & 0xFF;
  20822. file[2] = sfnt.charCodeAt(2) & 0xFF;
  20823. file[3] = sfnt.charCodeAt(3) & 0xFF;
  20824. // numTables (2 bytes)
  20825. writeInt16(file, 4, numTables);
  20826. var searchParams = OpenTypeFileBuilder.getSearchParams(numTables, 16);
  20827. // searchRange (2 bytes)
  20828. writeInt16(file, 6, searchParams.range);
  20829. // entrySelector (2 bytes)
  20830. writeInt16(file, 8, searchParams.entry);
  20831. // rangeShift (2 bytes)
  20832. writeInt16(file, 10, searchParams.rangeShift);
  20833. offset = OTF_HEADER_SIZE;
  20834. // writing table entries
  20835. for (i = 0; i < numTables; i++) {
  20836. tableName = tablesNames[i];
  20837. file[offset] = tableName.charCodeAt(0) & 0xFF;
  20838. file[offset + 1] = tableName.charCodeAt(1) & 0xFF;
  20839. file[offset + 2] = tableName.charCodeAt(2) & 0xFF;
  20840. file[offset + 3] = tableName.charCodeAt(3) & 0xFF;
  20841. // checksum
  20842. var checksum = 0;
  20843. for (j = tableOffsets[i], jj = tableOffsets[i + 1]; j < jj; j += 4) {
  20844. var quad = (file[j] << 24) + (file[j + 1] << 16) +
  20845. (file[j + 2] << 8) + file[j + 3];
  20846. checksum = (checksum + quad) | 0;
  20847. }
  20848. writeInt32(file, offset + 4, checksum);
  20849. // offset
  20850. writeInt32(file, offset + 8, tableOffsets[i]);
  20851. // length
  20852. writeInt32(file, offset + 12, tables[tableName].length);
  20853. offset += OTF_TABLE_ENTRY_SIZE;
  20854. }
  20855. return file;
  20856. },
  20857. addTable: function OpenTypeFileBuilder_addTable(tag, data) {
  20858. if (tag in this.tables) {
  20859. throw new Error('Table ' + tag + ' already exists');
  20860. }
  20861. this.tables[tag] = data;
  20862. }
  20863. };
  20864. return OpenTypeFileBuilder;
  20865. })();
  20866. /**
  20867. * 'Font' is the class the outside world should use, it encapsulate all the font
  20868. * decoding logics whatever type it is (assuming the font type is supported).
  20869. *
  20870. * For example to read a Type1 font and to attach it to the document:
  20871. * var type1Font = new Font("MyFontName", binaryFile, propertiesObject);
  20872. * type1Font.bind();
  20873. */
  20874. var Font = (function FontClosure() {
  20875. function Font(name, file, properties) {
  20876. var charCode, glyphName, fontChar;
  20877. this.name = name;
  20878. this.loadedName = properties.loadedName;
  20879. this.isType3Font = properties.isType3Font;
  20880. this.sizes = [];
  20881. this.glyphCache = {};
  20882. var names = name.split('+');
  20883. names = names.length > 1 ? names[1] : names[0];
  20884. names = names.split(/[-,_]/g)[0];
  20885. this.isSerifFont = !!(properties.flags & FontFlags.Serif);
  20886. this.isSymbolicFont = !!(properties.flags & FontFlags.Symbolic);
  20887. this.isMonospace = !!(properties.flags & FontFlags.FixedPitch);
  20888. var type = properties.type;
  20889. var subtype = properties.subtype;
  20890. this.type = type;
  20891. this.fallbackName = (this.isMonospace ? 'monospace' :
  20892. (this.isSerifFont ? 'serif' : 'sans-serif'));
  20893. this.differences = properties.differences;
  20894. this.widths = properties.widths;
  20895. this.defaultWidth = properties.defaultWidth;
  20896. this.composite = properties.composite;
  20897. this.wideChars = properties.wideChars;
  20898. this.cMap = properties.cMap;
  20899. this.ascent = properties.ascent / PDF_GLYPH_SPACE_UNITS;
  20900. this.descent = properties.descent / PDF_GLYPH_SPACE_UNITS;
  20901. this.fontMatrix = properties.fontMatrix;
  20902. this.bbox = properties.bbox;
  20903. this.toUnicode = properties.toUnicode = this.buildToUnicode(properties);
  20904. this.toFontChar = [];
  20905. if (properties.type === 'Type3') {
  20906. for (charCode = 0; charCode < 256; charCode++) {
  20907. this.toFontChar[charCode] = (this.differences[charCode] ||
  20908. properties.defaultEncoding[charCode]);
  20909. }
  20910. this.fontType = FontType.TYPE3;
  20911. return;
  20912. }
  20913. this.cidEncoding = properties.cidEncoding;
  20914. this.vertical = properties.vertical;
  20915. if (this.vertical) {
  20916. this.vmetrics = properties.vmetrics;
  20917. this.defaultVMetrics = properties.defaultVMetrics;
  20918. }
  20919. if (!file || file.isEmpty) {
  20920. if (file) {
  20921. // Some bad PDF generators will include empty font files,
  20922. // attempting to recover by assuming that no file exists.
  20923. warn('Font file is empty in "' + name + '" (' + this.loadedName + ')');
  20924. }
  20925. this.missingFile = true;
  20926. // The file data is not specified. Trying to fix the font name
  20927. // to be used with the canvas.font.
  20928. var fontName = name.replace(/[,_]/g, '-');
  20929. var isStandardFont = !!stdFontMap[fontName] ||
  20930. !!(nonStdFontMap[fontName] && stdFontMap[nonStdFontMap[fontName]]);
  20931. fontName = stdFontMap[fontName] || nonStdFontMap[fontName] || fontName;
  20932. this.bold = (fontName.search(/bold/gi) !== -1);
  20933. this.italic = ((fontName.search(/oblique/gi) !== -1) ||
  20934. (fontName.search(/italic/gi) !== -1));
  20935. // Use 'name' instead of 'fontName' here because the original
  20936. // name ArialBlack for example will be replaced by Helvetica.
  20937. this.black = (name.search(/Black/g) !== -1);
  20938. // if at least one width is present, remeasure all chars when exists
  20939. this.remeasure = Object.keys(this.widths).length > 0;
  20940. if (isStandardFont && type === 'CIDFontType2' &&
  20941. properties.cidEncoding.indexOf('Identity-') === 0) {
  20942. // Standard fonts might be embedded as CID font without glyph mapping.
  20943. // Building one based on GlyphMapForStandardFonts.
  20944. var map = [];
  20945. for (var code in GlyphMapForStandardFonts) {
  20946. map[+code] = GlyphMapForStandardFonts[code];
  20947. }
  20948. var isIdentityUnicode = this.toUnicode instanceof IdentityToUnicodeMap;
  20949. if (!isIdentityUnicode) {
  20950. this.toUnicode.forEach(function(charCode, unicodeCharCode) {
  20951. map[+charCode] = unicodeCharCode;
  20952. });
  20953. }
  20954. this.toFontChar = map;
  20955. this.toUnicode = new ToUnicodeMap(map);
  20956. } else if (/Symbol/i.test(fontName)) {
  20957. var symbols = Encodings.SymbolSetEncoding;
  20958. for (charCode in symbols) {
  20959. fontChar = GlyphsUnicode[symbols[charCode]];
  20960. if (!fontChar) {
  20961. continue;
  20962. }
  20963. this.toFontChar[charCode] = fontChar;
  20964. }
  20965. for (charCode in properties.differences) {
  20966. fontChar = GlyphsUnicode[properties.differences[charCode]];
  20967. if (!fontChar) {
  20968. continue;
  20969. }
  20970. this.toFontChar[charCode] = fontChar;
  20971. }
  20972. } else if (/Dingbats/i.test(fontName)) {
  20973. if (/Wingdings/i.test(name)) {
  20974. warn('Wingdings font without embedded font file, ' +
  20975. 'falling back to the ZapfDingbats encoding.');
  20976. }
  20977. var dingbats = Encodings.ZapfDingbatsEncoding;
  20978. for (charCode in dingbats) {
  20979. fontChar = DingbatsGlyphsUnicode[dingbats[charCode]];
  20980. if (!fontChar) {
  20981. continue;
  20982. }
  20983. this.toFontChar[charCode] = fontChar;
  20984. }
  20985. for (charCode in properties.differences) {
  20986. fontChar = DingbatsGlyphsUnicode[properties.differences[charCode]];
  20987. if (!fontChar) {
  20988. continue;
  20989. }
  20990. this.toFontChar[charCode] = fontChar;
  20991. }
  20992. } else if (isStandardFont) {
  20993. this.toFontChar = [];
  20994. for (charCode in properties.defaultEncoding) {
  20995. glyphName = (properties.differences[charCode] ||
  20996. properties.defaultEncoding[charCode]);
  20997. this.toFontChar[charCode] = GlyphsUnicode[glyphName];
  20998. }
  20999. } else {
  21000. var unicodeCharCode, notCidFont = (type.indexOf('CIDFontType') === -1);
  21001. this.toUnicode.forEach(function(charCode, unicodeCharCode) {
  21002. if (notCidFont) {
  21003. glyphName = (properties.differences[charCode] ||
  21004. properties.defaultEncoding[charCode]);
  21005. unicodeCharCode = (GlyphsUnicode[glyphName] || unicodeCharCode);
  21006. }
  21007. this.toFontChar[charCode] = unicodeCharCode;
  21008. }.bind(this));
  21009. }
  21010. this.loadedName = fontName.split('-')[0];
  21011. this.loading = false;
  21012. this.fontType = getFontType(type, subtype);
  21013. return;
  21014. }
  21015. // Some fonts might use wrong font types for Type1C or CIDFontType0C
  21016. if (subtype === 'Type1C' && (type !== 'Type1' && type !== 'MMType1')) {
  21017. // Some TrueType fonts by mistake claim Type1C
  21018. if (isTrueTypeFile(file)) {
  21019. subtype = 'TrueType';
  21020. } else {
  21021. type = 'Type1';
  21022. }
  21023. }
  21024. if (subtype === 'CIDFontType0C' && type !== 'CIDFontType0') {
  21025. type = 'CIDFontType0';
  21026. }
  21027. if (subtype === 'OpenType') {
  21028. type = 'OpenType';
  21029. }
  21030. // Some CIDFontType0C fonts by mistake claim CIDFontType0.
  21031. if (type === 'CIDFontType0') {
  21032. subtype = isType1File(file) ? 'CIDFontType0' : 'CIDFontType0C';
  21033. }
  21034. var data;
  21035. switch (type) {
  21036. case 'MMType1':
  21037. info('MMType1 font (' + name + '), falling back to Type1.');
  21038. /* falls through */
  21039. case 'Type1':
  21040. case 'CIDFontType0':
  21041. this.mimetype = 'font/opentype';
  21042. var cff = (subtype === 'Type1C' || subtype === 'CIDFontType0C') ?
  21043. new CFFFont(file, properties) : new Type1Font(name, file, properties);
  21044. adjustWidths(properties);
  21045. // Wrap the CFF data inside an OTF font file
  21046. data = this.convert(name, cff, properties);
  21047. break;
  21048. case 'OpenType':
  21049. case 'TrueType':
  21050. case 'CIDFontType2':
  21051. this.mimetype = 'font/opentype';
  21052. // Repair the TrueType file. It is can be damaged in the point of
  21053. // view of the sanitizer
  21054. data = this.checkAndRepair(name, file, properties);
  21055. if (this.isOpenType) {
  21056. type = 'OpenType';
  21057. }
  21058. break;
  21059. default:
  21060. error('Font ' + type + ' is not supported');
  21061. break;
  21062. }
  21063. this.data = data;
  21064. this.fontType = getFontType(type, subtype);
  21065. // Transfer some properties again that could change during font conversion
  21066. this.fontMatrix = properties.fontMatrix;
  21067. this.widths = properties.widths;
  21068. this.defaultWidth = properties.defaultWidth;
  21069. this.encoding = properties.baseEncoding;
  21070. this.seacMap = properties.seacMap;
  21071. this.loading = true;
  21072. }
  21073. Font.getFontID = (function () {
  21074. var ID = 1;
  21075. return function Font_getFontID() {
  21076. return String(ID++);
  21077. };
  21078. })();
  21079. function int16(b0, b1) {
  21080. return (b0 << 8) + b1;
  21081. }
  21082. function int32(b0, b1, b2, b3) {
  21083. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  21084. }
  21085. function string16(value) {
  21086. return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
  21087. }
  21088. function safeString16(value) {
  21089. // clamp value to the 16-bit int range
  21090. value = (value > 0x7FFF ? 0x7FFF : (value < -0x8000 ? -0x8000 : value));
  21091. return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
  21092. }
  21093. function isTrueTypeFile(file) {
  21094. var header = file.peekBytes(4);
  21095. return readUint32(header, 0) === 0x00010000;
  21096. }
  21097. function isType1File(file) {
  21098. var header = file.peekBytes(2);
  21099. // All Type1 font programs must begin with the comment '%!' (0x25 + 0x21).
  21100. if (header[0] === 0x25 && header[1] === 0x21) {
  21101. return true;
  21102. }
  21103. // ... obviously some fonts violate that part of the specification,
  21104. // please refer to the comment in |Type1Font| below.
  21105. if (header[0] === 0x80 && header[1] === 0x01) { // pfb file header.
  21106. return true;
  21107. }
  21108. return false;
  21109. }
  21110. /**
  21111. * Helper function for |adjustMapping|.
  21112. * @return {boolean}
  21113. */
  21114. function isProblematicUnicodeLocation(code) {
  21115. if (code <= 0x1F) { // Control chars
  21116. return true;
  21117. }
  21118. if (code >= 0x80 && code <= 0x9F) { // Control chars
  21119. return true;
  21120. }
  21121. if ((code >= 0x2000 && code <= 0x200F) || // General punctuation chars
  21122. (code >= 0x2028 && code <= 0x202F) ||
  21123. (code >= 0x2060 && code <= 0x206F)) {
  21124. return true;
  21125. }
  21126. if (code >= 0xFFF0 && code <= 0xFFFF) { // Specials Unicode block
  21127. return true;
  21128. }
  21129. switch (code) {
  21130. case 0x7F: // Control char
  21131. case 0xA0: // Non breaking space
  21132. case 0xAD: // Soft hyphen
  21133. case 0x0E33: // Thai character SARA AM
  21134. case 0x2011: // Non breaking hyphen
  21135. case 0x205F: // Medium mathematical space
  21136. case 0x25CC: // Dotted circle (combining mark)
  21137. return true;
  21138. }
  21139. return false;
  21140. }
  21141. /**
  21142. * Rebuilds the char code to glyph ID map by trying to replace the char codes
  21143. * with their unicode value. It also moves char codes that are in known
  21144. * problematic locations.
  21145. * @return {Object} Two properties:
  21146. * 'toFontChar' - maps original char codes(the value that will be read
  21147. * from commands such as show text) to the char codes that will be used in the
  21148. * font that we build
  21149. * 'charCodeToGlyphId' - maps the new font char codes to glyph ids
  21150. */
  21151. function adjustMapping(charCodeToGlyphId, properties) {
  21152. var toUnicode = properties.toUnicode;
  21153. var isSymbolic = !!(properties.flags & FontFlags.Symbolic);
  21154. var isIdentityUnicode =
  21155. properties.toUnicode instanceof IdentityToUnicodeMap;
  21156. var newMap = Object.create(null);
  21157. var toFontChar = [];
  21158. var usedFontCharCodes = [];
  21159. var nextAvailableFontCharCode = PRIVATE_USE_OFFSET_START;
  21160. for (var originalCharCode in charCodeToGlyphId) {
  21161. originalCharCode |= 0;
  21162. var glyphId = charCodeToGlyphId[originalCharCode];
  21163. var fontCharCode = originalCharCode;
  21164. // First try to map the value to a unicode position if a non identity map
  21165. // was created.
  21166. if (!isIdentityUnicode && toUnicode.has(originalCharCode)) {
  21167. var unicode = toUnicode.get(fontCharCode);
  21168. // TODO: Try to map ligatures to the correct spot.
  21169. if (unicode.length === 1) {
  21170. fontCharCode = unicode.charCodeAt(0);
  21171. }
  21172. }
  21173. // Try to move control characters, special characters and already mapped
  21174. // characters to the private use area since they will not be drawn by
  21175. // canvas if left in their current position. Also, move characters if the
  21176. // font was symbolic and there is only an identity unicode map since the
  21177. // characters probably aren't in the correct position (fixes an issue
  21178. // with firefox and thuluthfont).
  21179. if ((usedFontCharCodes[fontCharCode] !== undefined ||
  21180. isProblematicUnicodeLocation(fontCharCode) ||
  21181. (isSymbolic && isIdentityUnicode)) &&
  21182. nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END) { // Room left.
  21183. // Loop to try and find a free spot in the private use area.
  21184. do {
  21185. fontCharCode = nextAvailableFontCharCode++;
  21186. if (SKIP_PRIVATE_USE_RANGE_F000_TO_F01F && fontCharCode === 0xF000) {
  21187. fontCharCode = 0xF020;
  21188. nextAvailableFontCharCode = fontCharCode + 1;
  21189. }
  21190. } while (usedFontCharCodes[fontCharCode] !== undefined &&
  21191. nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END);
  21192. }
  21193. newMap[fontCharCode] = glyphId;
  21194. toFontChar[originalCharCode] = fontCharCode;
  21195. usedFontCharCodes[fontCharCode] = true;
  21196. }
  21197. return {
  21198. toFontChar: toFontChar,
  21199. charCodeToGlyphId: newMap,
  21200. nextAvailableFontCharCode: nextAvailableFontCharCode
  21201. };
  21202. }
  21203. function getRanges(glyphs) {
  21204. // Array.sort() sorts by characters, not numerically, so convert to an
  21205. // array of characters.
  21206. var codes = [];
  21207. for (var charCode in glyphs) {
  21208. codes.push({ fontCharCode: charCode | 0, glyphId: glyphs[charCode] });
  21209. }
  21210. codes.sort(function fontGetRangesSort(a, b) {
  21211. return a.fontCharCode - b.fontCharCode;
  21212. });
  21213. // Split the sorted codes into ranges.
  21214. var ranges = [];
  21215. var length = codes.length;
  21216. for (var n = 0; n < length; ) {
  21217. var start = codes[n].fontCharCode;
  21218. var codeIndices = [codes[n].glyphId];
  21219. ++n;
  21220. var end = start;
  21221. while (n < length && end + 1 === codes[n].fontCharCode) {
  21222. codeIndices.push(codes[n].glyphId);
  21223. ++end;
  21224. ++n;
  21225. if (end === 0xFFFF) {
  21226. break;
  21227. }
  21228. }
  21229. ranges.push([start, end, codeIndices]);
  21230. }
  21231. return ranges;
  21232. }
  21233. function createCmapTable(glyphs) {
  21234. var ranges = getRanges(glyphs);
  21235. var numTables = ranges[ranges.length - 1][1] > 0xFFFF ? 2 : 1;
  21236. var cmap = '\x00\x00' + // version
  21237. string16(numTables) + // numTables
  21238. '\x00\x03' + // platformID
  21239. '\x00\x01' + // encodingID
  21240. string32(4 + numTables * 8); // start of the table record
  21241. var i, ii, j, jj;
  21242. for (i = ranges.length - 1; i >= 0; --i) {
  21243. if (ranges[i][0] <= 0xFFFF) { break; }
  21244. }
  21245. var bmpLength = i + 1;
  21246. if (ranges[i][0] < 0xFFFF && ranges[i][1] === 0xFFFF) {
  21247. ranges[i][1] = 0xFFFE;
  21248. }
  21249. var trailingRangesCount = ranges[i][1] < 0xFFFF ? 1 : 0;
  21250. var segCount = bmpLength + trailingRangesCount;
  21251. var searchParams = OpenTypeFileBuilder.getSearchParams(segCount, 2);
  21252. // Fill up the 4 parallel arrays describing the segments.
  21253. var startCount = '';
  21254. var endCount = '';
  21255. var idDeltas = '';
  21256. var idRangeOffsets = '';
  21257. var glyphsIds = '';
  21258. var bias = 0;
  21259. var range, start, end, codes;
  21260. for (i = 0, ii = bmpLength; i < ii; i++) {
  21261. range = ranges[i];
  21262. start = range[0];
  21263. end = range[1];
  21264. startCount += string16(start);
  21265. endCount += string16(end);
  21266. codes = range[2];
  21267. var contiguous = true;
  21268. for (j = 1, jj = codes.length; j < jj; ++j) {
  21269. if (codes[j] !== codes[j - 1] + 1) {
  21270. contiguous = false;
  21271. break;
  21272. }
  21273. }
  21274. if (!contiguous) {
  21275. var offset = (segCount - i) * 2 + bias * 2;
  21276. bias += (end - start + 1);
  21277. idDeltas += string16(0);
  21278. idRangeOffsets += string16(offset);
  21279. for (j = 0, jj = codes.length; j < jj; ++j) {
  21280. glyphsIds += string16(codes[j]);
  21281. }
  21282. } else {
  21283. var startCode = codes[0];
  21284. idDeltas += string16((startCode - start) & 0xFFFF);
  21285. idRangeOffsets += string16(0);
  21286. }
  21287. }
  21288. if (trailingRangesCount > 0) {
  21289. endCount += '\xFF\xFF';
  21290. startCount += '\xFF\xFF';
  21291. idDeltas += '\x00\x01';
  21292. idRangeOffsets += '\x00\x00';
  21293. }
  21294. var format314 = '\x00\x00' + // language
  21295. string16(2 * segCount) +
  21296. string16(searchParams.range) +
  21297. string16(searchParams.entry) +
  21298. string16(searchParams.rangeShift) +
  21299. endCount + '\x00\x00' + startCount +
  21300. idDeltas + idRangeOffsets + glyphsIds;
  21301. var format31012 = '';
  21302. var header31012 = '';
  21303. if (numTables > 1) {
  21304. cmap += '\x00\x03' + // platformID
  21305. '\x00\x0A' + // encodingID
  21306. string32(4 + numTables * 8 +
  21307. 4 + format314.length); // start of the table record
  21308. format31012 = '';
  21309. for (i = 0, ii = ranges.length; i < ii; i++) {
  21310. range = ranges[i];
  21311. start = range[0];
  21312. codes = range[2];
  21313. var code = codes[0];
  21314. for (j = 1, jj = codes.length; j < jj; ++j) {
  21315. if (codes[j] !== codes[j - 1] + 1) {
  21316. end = range[0] + j - 1;
  21317. format31012 += string32(start) + // startCharCode
  21318. string32(end) + // endCharCode
  21319. string32(code); // startGlyphID
  21320. start = end + 1;
  21321. code = codes[j];
  21322. }
  21323. }
  21324. format31012 += string32(start) + // startCharCode
  21325. string32(range[1]) + // endCharCode
  21326. string32(code); // startGlyphID
  21327. }
  21328. header31012 = '\x00\x0C' + // format
  21329. '\x00\x00' + // reserved
  21330. string32(format31012.length + 16) + // length
  21331. '\x00\x00\x00\x00' + // language
  21332. string32(format31012.length / 12); // nGroups
  21333. }
  21334. return cmap + '\x00\x04' + // format
  21335. string16(format314.length + 4) + // length
  21336. format314 + header31012 + format31012;
  21337. }
  21338. function validateOS2Table(os2) {
  21339. var stream = new Stream(os2.data);
  21340. var version = stream.getUint16();
  21341. // TODO verify all OS/2 tables fields, but currently we validate only those
  21342. // that give us issues
  21343. stream.getBytes(60); // skipping type, misc sizes, panose, unicode ranges
  21344. var selection = stream.getUint16();
  21345. if (version < 4 && (selection & 0x0300)) {
  21346. return false;
  21347. }
  21348. var firstChar = stream.getUint16();
  21349. var lastChar = stream.getUint16();
  21350. if (firstChar > lastChar) {
  21351. return false;
  21352. }
  21353. stream.getBytes(6); // skipping sTypoAscender/Descender/LineGap
  21354. var usWinAscent = stream.getUint16();
  21355. if (usWinAscent === 0) { // makes font unreadable by windows
  21356. return false;
  21357. }
  21358. // OS/2 appears to be valid, resetting some fields
  21359. os2.data[8] = os2.data[9] = 0; // IE rejects fonts if fsType != 0
  21360. return true;
  21361. }
  21362. function createOS2Table(properties, charstrings, override) {
  21363. override = override || {
  21364. unitsPerEm: 0,
  21365. yMax: 0,
  21366. yMin: 0,
  21367. ascent: 0,
  21368. descent: 0
  21369. };
  21370. var ulUnicodeRange1 = 0;
  21371. var ulUnicodeRange2 = 0;
  21372. var ulUnicodeRange3 = 0;
  21373. var ulUnicodeRange4 = 0;
  21374. var firstCharIndex = null;
  21375. var lastCharIndex = 0;
  21376. if (charstrings) {
  21377. for (var code in charstrings) {
  21378. code |= 0;
  21379. if (firstCharIndex > code || !firstCharIndex) {
  21380. firstCharIndex = code;
  21381. }
  21382. if (lastCharIndex < code) {
  21383. lastCharIndex = code;
  21384. }
  21385. var position = getUnicodeRangeFor(code);
  21386. if (position < 32) {
  21387. ulUnicodeRange1 |= 1 << position;
  21388. } else if (position < 64) {
  21389. ulUnicodeRange2 |= 1 << position - 32;
  21390. } else if (position < 96) {
  21391. ulUnicodeRange3 |= 1 << position - 64;
  21392. } else if (position < 123) {
  21393. ulUnicodeRange4 |= 1 << position - 96;
  21394. } else {
  21395. error('Unicode ranges Bits > 123 are reserved for internal usage');
  21396. }
  21397. }
  21398. } else {
  21399. // TODO
  21400. firstCharIndex = 0;
  21401. lastCharIndex = 255;
  21402. }
  21403. var bbox = properties.bbox || [0, 0, 0, 0];
  21404. var unitsPerEm = (override.unitsPerEm ||
  21405. 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0]);
  21406. // if the font units differ to the PDF glyph space units
  21407. // then scale up the values
  21408. var scale = (properties.ascentScaled ? 1.0 :
  21409. unitsPerEm / PDF_GLYPH_SPACE_UNITS);
  21410. var typoAscent = (override.ascent ||
  21411. Math.round(scale * (properties.ascent || bbox[3])));
  21412. var typoDescent = (override.descent ||
  21413. Math.round(scale * (properties.descent || bbox[1])));
  21414. if (typoDescent > 0 && properties.descent > 0 && bbox[1] < 0) {
  21415. typoDescent = -typoDescent; // fixing incorrect descent
  21416. }
  21417. var winAscent = override.yMax || typoAscent;
  21418. var winDescent = -override.yMin || -typoDescent;
  21419. return '\x00\x03' + // version
  21420. '\x02\x24' + // xAvgCharWidth
  21421. '\x01\xF4' + // usWeightClass
  21422. '\x00\x05' + // usWidthClass
  21423. '\x00\x00' + // fstype (0 to let the font loads via font-face on IE)
  21424. '\x02\x8A' + // ySubscriptXSize
  21425. '\x02\xBB' + // ySubscriptYSize
  21426. '\x00\x00' + // ySubscriptXOffset
  21427. '\x00\x8C' + // ySubscriptYOffset
  21428. '\x02\x8A' + // ySuperScriptXSize
  21429. '\x02\xBB' + // ySuperScriptYSize
  21430. '\x00\x00' + // ySuperScriptXOffset
  21431. '\x01\xDF' + // ySuperScriptYOffset
  21432. '\x00\x31' + // yStrikeOutSize
  21433. '\x01\x02' + // yStrikeOutPosition
  21434. '\x00\x00' + // sFamilyClass
  21435. '\x00\x00\x06' +
  21436. String.fromCharCode(properties.fixedPitch ? 0x09 : 0x00) +
  21437. '\x00\x00\x00\x00\x00\x00' + // Panose
  21438. string32(ulUnicodeRange1) + // ulUnicodeRange1 (Bits 0-31)
  21439. string32(ulUnicodeRange2) + // ulUnicodeRange2 (Bits 32-63)
  21440. string32(ulUnicodeRange3) + // ulUnicodeRange3 (Bits 64-95)
  21441. string32(ulUnicodeRange4) + // ulUnicodeRange4 (Bits 96-127)
  21442. '\x2A\x32\x31\x2A' + // achVendID
  21443. string16(properties.italicAngle ? 1 : 0) + // fsSelection
  21444. string16(firstCharIndex ||
  21445. properties.firstChar) + // usFirstCharIndex
  21446. string16(lastCharIndex || properties.lastChar) + // usLastCharIndex
  21447. string16(typoAscent) + // sTypoAscender
  21448. string16(typoDescent) + // sTypoDescender
  21449. '\x00\x64' + // sTypoLineGap (7%-10% of the unitsPerEM value)
  21450. string16(winAscent) + // usWinAscent
  21451. string16(winDescent) + // usWinDescent
  21452. '\x00\x00\x00\x00' + // ulCodePageRange1 (Bits 0-31)
  21453. '\x00\x00\x00\x00' + // ulCodePageRange2 (Bits 32-63)
  21454. string16(properties.xHeight) + // sxHeight
  21455. string16(properties.capHeight) + // sCapHeight
  21456. string16(0) + // usDefaultChar
  21457. string16(firstCharIndex || properties.firstChar) + // usBreakChar
  21458. '\x00\x03'; // usMaxContext
  21459. }
  21460. function createPostTable(properties) {
  21461. var angle = Math.floor(properties.italicAngle * (Math.pow(2, 16)));
  21462. return ('\x00\x03\x00\x00' + // Version number
  21463. string32(angle) + // italicAngle
  21464. '\x00\x00' + // underlinePosition
  21465. '\x00\x00' + // underlineThickness
  21466. string32(properties.fixedPitch) + // isFixedPitch
  21467. '\x00\x00\x00\x00' + // minMemType42
  21468. '\x00\x00\x00\x00' + // maxMemType42
  21469. '\x00\x00\x00\x00' + // minMemType1
  21470. '\x00\x00\x00\x00'); // maxMemType1
  21471. }
  21472. function createNameTable(name, proto) {
  21473. if (!proto) {
  21474. proto = [[], []]; // no strings and unicode strings
  21475. }
  21476. var strings = [
  21477. proto[0][0] || 'Original licence', // 0.Copyright
  21478. proto[0][1] || name, // 1.Font family
  21479. proto[0][2] || 'Unknown', // 2.Font subfamily (font weight)
  21480. proto[0][3] || 'uniqueID', // 3.Unique ID
  21481. proto[0][4] || name, // 4.Full font name
  21482. proto[0][5] || 'Version 0.11', // 5.Version
  21483. proto[0][6] || '', // 6.Postscript name
  21484. proto[0][7] || 'Unknown', // 7.Trademark
  21485. proto[0][8] || 'Unknown', // 8.Manufacturer
  21486. proto[0][9] || 'Unknown' // 9.Designer
  21487. ];
  21488. // Mac want 1-byte per character strings while Windows want
  21489. // 2-bytes per character, so duplicate the names table
  21490. var stringsUnicode = [];
  21491. var i, ii, j, jj, str;
  21492. for (i = 0, ii = strings.length; i < ii; i++) {
  21493. str = proto[1][i] || strings[i];
  21494. var strBufUnicode = [];
  21495. for (j = 0, jj = str.length; j < jj; j++) {
  21496. strBufUnicode.push(string16(str.charCodeAt(j)));
  21497. }
  21498. stringsUnicode.push(strBufUnicode.join(''));
  21499. }
  21500. var names = [strings, stringsUnicode];
  21501. var platforms = ['\x00\x01', '\x00\x03'];
  21502. var encodings = ['\x00\x00', '\x00\x01'];
  21503. var languages = ['\x00\x00', '\x04\x09'];
  21504. var namesRecordCount = strings.length * platforms.length;
  21505. var nameTable =
  21506. '\x00\x00' + // format
  21507. string16(namesRecordCount) + // Number of names Record
  21508. string16(namesRecordCount * 12 + 6); // Storage
  21509. // Build the name records field
  21510. var strOffset = 0;
  21511. for (i = 0, ii = platforms.length; i < ii; i++) {
  21512. var strs = names[i];
  21513. for (j = 0, jj = strs.length; j < jj; j++) {
  21514. str = strs[j];
  21515. var nameRecord =
  21516. platforms[i] + // platform ID
  21517. encodings[i] + // encoding ID
  21518. languages[i] + // language ID
  21519. string16(j) + // name ID
  21520. string16(str.length) +
  21521. string16(strOffset);
  21522. nameTable += nameRecord;
  21523. strOffset += str.length;
  21524. }
  21525. }
  21526. nameTable += strings.join('') + stringsUnicode.join('');
  21527. return nameTable;
  21528. }
  21529. Font.prototype = {
  21530. name: null,
  21531. font: null,
  21532. mimetype: null,
  21533. encoding: null,
  21534. get renderer() {
  21535. var renderer = FontRendererFactory.create(this);
  21536. return shadow(this, 'renderer', renderer);
  21537. },
  21538. exportData: function Font_exportData() {
  21539. var data = {};
  21540. for (var i in this) {
  21541. if (this.hasOwnProperty(i)) {
  21542. data[i] = this[i];
  21543. }
  21544. }
  21545. return data;
  21546. },
  21547. checkAndRepair: function Font_checkAndRepair(name, font, properties) {
  21548. function readTableEntry(file) {
  21549. var tag = bytesToString(file.getBytes(4));
  21550. var checksum = file.getInt32();
  21551. var offset = file.getInt32() >>> 0;
  21552. var length = file.getInt32() >>> 0;
  21553. // Read the table associated data
  21554. var previousPosition = file.pos;
  21555. file.pos = file.start ? file.start : 0;
  21556. file.skip(offset);
  21557. var data = file.getBytes(length);
  21558. file.pos = previousPosition;
  21559. if (tag === 'head') {
  21560. // clearing checksum adjustment
  21561. data[8] = data[9] = data[10] = data[11] = 0;
  21562. data[17] |= 0x20; //Set font optimized for cleartype flag
  21563. }
  21564. return {
  21565. tag: tag,
  21566. checksum: checksum,
  21567. length: length,
  21568. offset: offset,
  21569. data: data
  21570. };
  21571. }
  21572. function readOpenTypeHeader(ttf) {
  21573. return {
  21574. version: bytesToString(ttf.getBytes(4)),
  21575. numTables: ttf.getUint16(),
  21576. searchRange: ttf.getUint16(),
  21577. entrySelector: ttf.getUint16(),
  21578. rangeShift: ttf.getUint16()
  21579. };
  21580. }
  21581. /**
  21582. * Read the appropriate subtable from the cmap according to 9.6.6.4 from
  21583. * PDF spec
  21584. */
  21585. function readCmapTable(cmap, font, isSymbolicFont) {
  21586. var segment;
  21587. var start = (font.start ? font.start : 0) + cmap.offset;
  21588. font.pos = start;
  21589. var version = font.getUint16();
  21590. var numTables = font.getUint16();
  21591. var potentialTable;
  21592. var canBreak = false;
  21593. // There's an order of preference in terms of which cmap subtable to
  21594. // use:
  21595. // - non-symbolic fonts the preference is a 3,1 table then a 1,0 table
  21596. // - symbolic fonts the preference is a 3,0 table then a 1,0 table
  21597. // The following takes advantage of the fact that the tables are sorted
  21598. // to work.
  21599. for (var i = 0; i < numTables; i++) {
  21600. var platformId = font.getUint16();
  21601. var encodingId = font.getUint16();
  21602. var offset = font.getInt32() >>> 0;
  21603. var useTable = false;
  21604. if (platformId === 0 && encodingId === 0) {
  21605. useTable = true;
  21606. // Continue the loop since there still may be a higher priority
  21607. // table.
  21608. } else if (platformId === 1 && encodingId === 0) {
  21609. useTable = true;
  21610. // Continue the loop since there still may be a higher priority
  21611. // table.
  21612. } else if (platformId === 3 && encodingId === 1 &&
  21613. (!isSymbolicFont || !potentialTable)) {
  21614. useTable = true;
  21615. if (!isSymbolicFont) {
  21616. canBreak = true;
  21617. }
  21618. } else if (isSymbolicFont && platformId === 3 && encodingId === 0) {
  21619. useTable = true;
  21620. canBreak = true;
  21621. }
  21622. if (useTable) {
  21623. potentialTable = {
  21624. platformId: platformId,
  21625. encodingId: encodingId,
  21626. offset: offset
  21627. };
  21628. }
  21629. if (canBreak) {
  21630. break;
  21631. }
  21632. }
  21633. if (potentialTable) {
  21634. font.pos = start + potentialTable.offset;
  21635. }
  21636. if (!potentialTable || font.peekByte() === -1) {
  21637. warn('Could not find a preferred cmap table.');
  21638. return {
  21639. platformId: -1,
  21640. encodingId: -1,
  21641. mappings: [],
  21642. hasShortCmap: false
  21643. };
  21644. }
  21645. var format = font.getUint16();
  21646. var length = font.getUint16();
  21647. var language = font.getUint16();
  21648. var hasShortCmap = false;
  21649. var mappings = [];
  21650. var j, glyphId;
  21651. // TODO(mack): refactor this cmap subtable reading logic out
  21652. if (format === 0) {
  21653. for (j = 0; j < 256; j++) {
  21654. var index = font.getByte();
  21655. if (!index) {
  21656. continue;
  21657. }
  21658. mappings.push({
  21659. charCode: j,
  21660. glyphId: index
  21661. });
  21662. }
  21663. hasShortCmap = true;
  21664. } else if (format === 4) {
  21665. // re-creating the table in format 4 since the encoding
  21666. // might be changed
  21667. var segCount = (font.getUint16() >> 1);
  21668. font.getBytes(6); // skipping range fields
  21669. var segIndex, segments = [];
  21670. for (segIndex = 0; segIndex < segCount; segIndex++) {
  21671. segments.push({ end: font.getUint16() });
  21672. }
  21673. font.getUint16();
  21674. for (segIndex = 0; segIndex < segCount; segIndex++) {
  21675. segments[segIndex].start = font.getUint16();
  21676. }
  21677. for (segIndex = 0; segIndex < segCount; segIndex++) {
  21678. segments[segIndex].delta = font.getUint16();
  21679. }
  21680. var offsetsCount = 0;
  21681. for (segIndex = 0; segIndex < segCount; segIndex++) {
  21682. segment = segments[segIndex];
  21683. var rangeOffset = font.getUint16();
  21684. if (!rangeOffset) {
  21685. segment.offsetIndex = -1;
  21686. continue;
  21687. }
  21688. var offsetIndex = (rangeOffset >> 1) - (segCount - segIndex);
  21689. segment.offsetIndex = offsetIndex;
  21690. offsetsCount = Math.max(offsetsCount, offsetIndex +
  21691. segment.end - segment.start + 1);
  21692. }
  21693. var offsets = [];
  21694. for (j = 0; j < offsetsCount; j++) {
  21695. offsets.push(font.getUint16());
  21696. }
  21697. for (segIndex = 0; segIndex < segCount; segIndex++) {
  21698. segment = segments[segIndex];
  21699. start = segment.start;
  21700. var end = segment.end;
  21701. var delta = segment.delta;
  21702. offsetIndex = segment.offsetIndex;
  21703. for (j = start; j <= end; j++) {
  21704. if (j === 0xFFFF) {
  21705. continue;
  21706. }
  21707. glyphId = (offsetIndex < 0 ?
  21708. j : offsets[offsetIndex + j - start]);
  21709. glyphId = (glyphId + delta) & 0xFFFF;
  21710. if (glyphId === 0) {
  21711. continue;
  21712. }
  21713. mappings.push({
  21714. charCode: j,
  21715. glyphId: glyphId
  21716. });
  21717. }
  21718. }
  21719. } else if (format === 6) {
  21720. // Format 6 is a 2-bytes dense mapping, which means the font data
  21721. // lives glue together even if they are pretty far in the unicode
  21722. // table. (This looks weird, so I can have missed something), this
  21723. // works on Linux but seems to fails on Mac so let's rewrite the
  21724. // cmap table to a 3-1-4 style
  21725. var firstCode = font.getUint16();
  21726. var entryCount = font.getUint16();
  21727. for (j = 0; j < entryCount; j++) {
  21728. glyphId = font.getUint16();
  21729. var charCode = firstCode + j;
  21730. mappings.push({
  21731. charCode: charCode,
  21732. glyphId: glyphId
  21733. });
  21734. }
  21735. } else {
  21736. error('cmap table has unsupported format: ' + format);
  21737. }
  21738. // removing duplicate entries
  21739. mappings.sort(function (a, b) {
  21740. return a.charCode - b.charCode;
  21741. });
  21742. for (i = 1; i < mappings.length; i++) {
  21743. if (mappings[i - 1].charCode === mappings[i].charCode) {
  21744. mappings.splice(i, 1);
  21745. i--;
  21746. }
  21747. }
  21748. return {
  21749. platformId: potentialTable.platformId,
  21750. encodingId: potentialTable.encodingId,
  21751. mappings: mappings,
  21752. hasShortCmap: hasShortCmap
  21753. };
  21754. }
  21755. function sanitizeMetrics(font, header, metrics, numGlyphs) {
  21756. if (!header) {
  21757. if (metrics) {
  21758. metrics.data = null;
  21759. }
  21760. return;
  21761. }
  21762. font.pos = (font.start ? font.start : 0) + header.offset;
  21763. font.pos += header.length - 2;
  21764. var numOfMetrics = font.getUint16();
  21765. if (numOfMetrics > numGlyphs) {
  21766. info('The numOfMetrics (' + numOfMetrics + ') should not be ' +
  21767. 'greater than the numGlyphs (' + numGlyphs + ')');
  21768. // Reduce numOfMetrics if it is greater than numGlyphs
  21769. numOfMetrics = numGlyphs;
  21770. header.data[34] = (numOfMetrics & 0xff00) >> 8;
  21771. header.data[35] = numOfMetrics & 0x00ff;
  21772. }
  21773. var numOfSidebearings = numGlyphs - numOfMetrics;
  21774. var numMissing = numOfSidebearings -
  21775. ((metrics.length - numOfMetrics * 4) >> 1);
  21776. if (numMissing > 0) {
  21777. // For each missing glyph, we set both the width and lsb to 0 (zero).
  21778. // Since we need to add two properties for each glyph, this explains
  21779. // the use of |numMissing * 2| when initializing the typed array.
  21780. var entries = new Uint8Array(metrics.length + numMissing * 2);
  21781. entries.set(metrics.data);
  21782. metrics.data = entries;
  21783. }
  21784. }
  21785. function sanitizeGlyph(source, sourceStart, sourceEnd, dest, destStart,
  21786. hintsValid) {
  21787. if (sourceEnd - sourceStart <= 12) {
  21788. // glyph with data less than 12 is invalid one
  21789. return 0;
  21790. }
  21791. var glyf = source.subarray(sourceStart, sourceEnd);
  21792. var contoursCount = (glyf[0] << 8) | glyf[1];
  21793. if (contoursCount & 0x8000) {
  21794. // complex glyph, writing as is
  21795. dest.set(glyf, destStart);
  21796. return glyf.length;
  21797. }
  21798. var i, j = 10, flagsCount = 0;
  21799. for (i = 0; i < contoursCount; i++) {
  21800. var endPoint = (glyf[j] << 8) | glyf[j + 1];
  21801. flagsCount = endPoint + 1;
  21802. j += 2;
  21803. }
  21804. // skipping instructions
  21805. var instructionsStart = j;
  21806. var instructionsLength = (glyf[j] << 8) | glyf[j + 1];
  21807. j += 2 + instructionsLength;
  21808. var instructionsEnd = j;
  21809. // validating flags
  21810. var coordinatesLength = 0;
  21811. for (i = 0; i < flagsCount; i++) {
  21812. var flag = glyf[j++];
  21813. if (flag & 0xC0) {
  21814. // reserved flags must be zero, cleaning up
  21815. glyf[j - 1] = flag & 0x3F;
  21816. }
  21817. var xyLength = ((flag & 2) ? 1 : (flag & 16) ? 0 : 2) +
  21818. ((flag & 4) ? 1 : (flag & 32) ? 0 : 2);
  21819. coordinatesLength += xyLength;
  21820. if (flag & 8) {
  21821. var repeat = glyf[j++];
  21822. i += repeat;
  21823. coordinatesLength += repeat * xyLength;
  21824. }
  21825. }
  21826. // glyph without coordinates will be rejected
  21827. if (coordinatesLength === 0) {
  21828. return 0;
  21829. }
  21830. var glyphDataLength = j + coordinatesLength;
  21831. if (glyphDataLength > glyf.length) {
  21832. // not enough data for coordinates
  21833. return 0;
  21834. }
  21835. if (!hintsValid && instructionsLength > 0) {
  21836. dest.set(glyf.subarray(0, instructionsStart), destStart);
  21837. dest.set([0, 0], destStart + instructionsStart);
  21838. dest.set(glyf.subarray(instructionsEnd, glyphDataLength),
  21839. destStart + instructionsStart + 2);
  21840. glyphDataLength -= instructionsLength;
  21841. if (glyf.length - glyphDataLength > 3) {
  21842. glyphDataLength = (glyphDataLength + 3) & ~3;
  21843. }
  21844. return glyphDataLength;
  21845. }
  21846. if (glyf.length - glyphDataLength > 3) {
  21847. // truncating and aligning to 4 bytes the long glyph data
  21848. glyphDataLength = (glyphDataLength + 3) & ~3;
  21849. dest.set(glyf.subarray(0, glyphDataLength), destStart);
  21850. return glyphDataLength;
  21851. }
  21852. // glyph data is fine
  21853. dest.set(glyf, destStart);
  21854. return glyf.length;
  21855. }
  21856. function sanitizeHead(head, numGlyphs, locaLength) {
  21857. var data = head.data;
  21858. // Validate version:
  21859. // Should always be 0x00010000
  21860. var version = int32(data[0], data[1], data[2], data[3]);
  21861. if (version >> 16 !== 1) {
  21862. info('Attempting to fix invalid version in head table: ' + version);
  21863. data[0] = 0;
  21864. data[1] = 1;
  21865. data[2] = 0;
  21866. data[3] = 0;
  21867. }
  21868. var indexToLocFormat = int16(data[50], data[51]);
  21869. if (indexToLocFormat < 0 || indexToLocFormat > 1) {
  21870. info('Attempting to fix invalid indexToLocFormat in head table: ' +
  21871. indexToLocFormat);
  21872. // The value of indexToLocFormat should be 0 if the loca table
  21873. // consists of short offsets, and should be 1 if the loca table
  21874. // consists of long offsets.
  21875. //
  21876. // The number of entries in the loca table should be numGlyphs + 1.
  21877. //
  21878. // Using this information, we can work backwards to deduce if the
  21879. // size of each offset in the loca table, and thus figure out the
  21880. // appropriate value for indexToLocFormat.
  21881. var numGlyphsPlusOne = numGlyphs + 1;
  21882. if (locaLength === numGlyphsPlusOne << 1) {
  21883. // 0x0000 indicates the loca table consists of short offsets
  21884. data[50] = 0;
  21885. data[51] = 0;
  21886. } else if (locaLength === numGlyphsPlusOne << 2) {
  21887. // 0x0001 indicates the loca table consists of long offsets
  21888. data[50] = 0;
  21889. data[51] = 1;
  21890. } else {
  21891. warn('Could not fix indexToLocFormat: ' + indexToLocFormat);
  21892. }
  21893. }
  21894. }
  21895. function sanitizeGlyphLocations(loca, glyf, numGlyphs,
  21896. isGlyphLocationsLong, hintsValid,
  21897. dupFirstEntry) {
  21898. var itemSize, itemDecode, itemEncode;
  21899. if (isGlyphLocationsLong) {
  21900. itemSize = 4;
  21901. itemDecode = function fontItemDecodeLong(data, offset) {
  21902. return (data[offset] << 24) | (data[offset + 1] << 16) |
  21903. (data[offset + 2] << 8) | data[offset + 3];
  21904. };
  21905. itemEncode = function fontItemEncodeLong(data, offset, value) {
  21906. data[offset] = (value >>> 24) & 0xFF;
  21907. data[offset + 1] = (value >> 16) & 0xFF;
  21908. data[offset + 2] = (value >> 8) & 0xFF;
  21909. data[offset + 3] = value & 0xFF;
  21910. };
  21911. } else {
  21912. itemSize = 2;
  21913. itemDecode = function fontItemDecode(data, offset) {
  21914. return (data[offset] << 9) | (data[offset + 1] << 1);
  21915. };
  21916. itemEncode = function fontItemEncode(data, offset, value) {
  21917. data[offset] = (value >> 9) & 0xFF;
  21918. data[offset + 1] = (value >> 1) & 0xFF;
  21919. };
  21920. }
  21921. var locaData = loca.data;
  21922. var locaDataSize = itemSize * (1 + numGlyphs);
  21923. // is loca.data too short or long?
  21924. if (locaData.length !== locaDataSize) {
  21925. locaData = new Uint8Array(locaDataSize);
  21926. locaData.set(loca.data.subarray(0, locaDataSize));
  21927. loca.data = locaData;
  21928. }
  21929. // removing the invalid glyphs
  21930. var oldGlyfData = glyf.data;
  21931. var oldGlyfDataLength = oldGlyfData.length;
  21932. var newGlyfData = new Uint8Array(oldGlyfDataLength);
  21933. var startOffset = itemDecode(locaData, 0);
  21934. var writeOffset = 0;
  21935. var missingGlyphData = {};
  21936. itemEncode(locaData, 0, writeOffset);
  21937. var i, j;
  21938. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  21939. var endOffset = itemDecode(locaData, j);
  21940. if (endOffset > oldGlyfDataLength &&
  21941. ((oldGlyfDataLength + 3) & ~3) === endOffset) {
  21942. // Aspose breaks fonts by aligning the glyphs to the qword, but not
  21943. // the glyf table size, which makes last glyph out of range.
  21944. endOffset = oldGlyfDataLength;
  21945. }
  21946. if (endOffset > oldGlyfDataLength) {
  21947. // glyph end offset points outside glyf data, rejecting the glyph
  21948. itemEncode(locaData, j, writeOffset);
  21949. startOffset = endOffset;
  21950. continue;
  21951. }
  21952. if (startOffset === endOffset) {
  21953. missingGlyphData[i] = true;
  21954. }
  21955. var newLength = sanitizeGlyph(oldGlyfData, startOffset, endOffset,
  21956. newGlyfData, writeOffset, hintsValid);
  21957. writeOffset += newLength;
  21958. itemEncode(locaData, j, writeOffset);
  21959. startOffset = endOffset;
  21960. }
  21961. if (writeOffset === 0) {
  21962. // glyf table cannot be empty -- redoing the glyf and loca tables
  21963. // to have single glyph with one point
  21964. var simpleGlyph = new Uint8Array(
  21965. [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 49, 0]);
  21966. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  21967. itemEncode(locaData, j, simpleGlyph.length);
  21968. }
  21969. glyf.data = simpleGlyph;
  21970. return missingGlyphData;
  21971. }
  21972. if (dupFirstEntry) {
  21973. var firstEntryLength = itemDecode(locaData, itemSize);
  21974. if (newGlyfData.length > firstEntryLength + writeOffset) {
  21975. glyf.data = newGlyfData.subarray(0, firstEntryLength + writeOffset);
  21976. } else {
  21977. glyf.data = new Uint8Array(firstEntryLength + writeOffset);
  21978. glyf.data.set(newGlyfData.subarray(0, writeOffset));
  21979. }
  21980. glyf.data.set(newGlyfData.subarray(0, firstEntryLength), writeOffset);
  21981. itemEncode(loca.data, locaData.length - itemSize,
  21982. writeOffset + firstEntryLength);
  21983. } else {
  21984. glyf.data = newGlyfData.subarray(0, writeOffset);
  21985. }
  21986. return missingGlyphData;
  21987. }
  21988. function readPostScriptTable(post, properties, maxpNumGlyphs) {
  21989. var start = (font.start ? font.start : 0) + post.offset;
  21990. font.pos = start;
  21991. var length = post.length, end = start + length;
  21992. var version = font.getInt32();
  21993. // skip rest to the tables
  21994. font.getBytes(28);
  21995. var glyphNames;
  21996. var valid = true;
  21997. var i;
  21998. switch (version) {
  21999. case 0x00010000:
  22000. glyphNames = MacStandardGlyphOrdering;
  22001. break;
  22002. case 0x00020000:
  22003. var numGlyphs = font.getUint16();
  22004. if (numGlyphs !== maxpNumGlyphs) {
  22005. valid = false;
  22006. break;
  22007. }
  22008. var glyphNameIndexes = [];
  22009. for (i = 0; i < numGlyphs; ++i) {
  22010. var index = font.getUint16();
  22011. if (index >= 32768) {
  22012. valid = false;
  22013. break;
  22014. }
  22015. glyphNameIndexes.push(index);
  22016. }
  22017. if (!valid) {
  22018. break;
  22019. }
  22020. var customNames = [];
  22021. var strBuf = [];
  22022. while (font.pos < end) {
  22023. var stringLength = font.getByte();
  22024. strBuf.length = stringLength;
  22025. for (i = 0; i < stringLength; ++i) {
  22026. strBuf[i] = String.fromCharCode(font.getByte());
  22027. }
  22028. customNames.push(strBuf.join(''));
  22029. }
  22030. glyphNames = [];
  22031. for (i = 0; i < numGlyphs; ++i) {
  22032. var j = glyphNameIndexes[i];
  22033. if (j < 258) {
  22034. glyphNames.push(MacStandardGlyphOrdering[j]);
  22035. continue;
  22036. }
  22037. glyphNames.push(customNames[j - 258]);
  22038. }
  22039. break;
  22040. case 0x00030000:
  22041. break;
  22042. default:
  22043. warn('Unknown/unsupported post table version ' + version);
  22044. valid = false;
  22045. if (properties.defaultEncoding) {
  22046. glyphNames = properties.defaultEncoding;
  22047. }
  22048. break;
  22049. }
  22050. properties.glyphNames = glyphNames;
  22051. return valid;
  22052. }
  22053. function readNameTable(nameTable) {
  22054. var start = (font.start ? font.start : 0) + nameTable.offset;
  22055. font.pos = start;
  22056. var names = [[], []];
  22057. var length = nameTable.length, end = start + length;
  22058. var format = font.getUint16();
  22059. var FORMAT_0_HEADER_LENGTH = 6;
  22060. if (format !== 0 || length < FORMAT_0_HEADER_LENGTH) {
  22061. // unsupported name table format or table "too" small
  22062. return names;
  22063. }
  22064. var numRecords = font.getUint16();
  22065. var stringsStart = font.getUint16();
  22066. var records = [];
  22067. var NAME_RECORD_LENGTH = 12;
  22068. var i, ii;
  22069. for (i = 0; i < numRecords &&
  22070. font.pos + NAME_RECORD_LENGTH <= end; i++) {
  22071. var r = {
  22072. platform: font.getUint16(),
  22073. encoding: font.getUint16(),
  22074. language: font.getUint16(),
  22075. name: font.getUint16(),
  22076. length: font.getUint16(),
  22077. offset: font.getUint16()
  22078. };
  22079. // using only Macintosh and Windows platform/encoding names
  22080. if ((r.platform === 1 && r.encoding === 0 && r.language === 0) ||
  22081. (r.platform === 3 && r.encoding === 1 && r.language === 0x409)) {
  22082. records.push(r);
  22083. }
  22084. }
  22085. for (i = 0, ii = records.length; i < ii; i++) {
  22086. var record = records[i];
  22087. var pos = start + stringsStart + record.offset;
  22088. if (pos + record.length > end) {
  22089. continue; // outside of name table, ignoring
  22090. }
  22091. font.pos = pos;
  22092. var nameIndex = record.name;
  22093. if (record.encoding) {
  22094. // unicode
  22095. var str = '';
  22096. for (var j = 0, jj = record.length; j < jj; j += 2) {
  22097. str += String.fromCharCode(font.getUint16());
  22098. }
  22099. names[1][nameIndex] = str;
  22100. } else {
  22101. names[0][nameIndex] = bytesToString(font.getBytes(record.length));
  22102. }
  22103. }
  22104. return names;
  22105. }
  22106. var TTOpsStackDeltas = [
  22107. 0, 0, 0, 0, 0, 0, 0, 0, -2, -2, -2, -2, 0, 0, -2, -5,
  22108. -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, -1, -1,
  22109. 1, -1, -999, 0, 1, 0, -1, -2, 0, -1, -2, -1, -1, 0, -1, -1,
  22110. 0, 0, -999, -999, -1, -1, -1, -1, -2, -999, -2, -2, -999, 0, -2, -2,
  22111. 0, 0, -2, 0, -2, 0, 0, 0, -2, -1, -1, 1, 1, 0, 0, -1,
  22112. -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, 0, -999, -1, -1,
  22113. -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  22114. -2, -999, -999, -999, -999, -999, -1, -1, -2, -2, 0, 0, 0, 0, -1, -1,
  22115. -999, -2, -2, 0, 0, -1, -2, -2, 0, 0, 0, -1, -1, -1, -2];
  22116. // 0xC0-DF == -1 and 0xE0-FF == -2
  22117. function sanitizeTTProgram(table, ttContext) {
  22118. var data = table.data;
  22119. var i = 0, j, n, b, funcId, pc, lastEndf = 0, lastDeff = 0;
  22120. var stack = [];
  22121. var callstack = [];
  22122. var functionsCalled = [];
  22123. var tooComplexToFollowFunctions =
  22124. ttContext.tooComplexToFollowFunctions;
  22125. var inFDEF = false, ifLevel = 0, inELSE = 0;
  22126. for (var ii = data.length; i < ii;) {
  22127. var op = data[i++];
  22128. // The TrueType instruction set docs can be found at
  22129. // https://developer.apple.com/fonts/TTRefMan/RM05/Chap5.html
  22130. if (op === 0x40) { // NPUSHB - pushes n bytes
  22131. n = data[i++];
  22132. if (inFDEF || inELSE) {
  22133. i += n;
  22134. } else {
  22135. for (j = 0; j < n; j++) {
  22136. stack.push(data[i++]);
  22137. }
  22138. }
  22139. } else if (op === 0x41) { // NPUSHW - pushes n words
  22140. n = data[i++];
  22141. if (inFDEF || inELSE) {
  22142. i += n * 2;
  22143. } else {
  22144. for (j = 0; j < n; j++) {
  22145. b = data[i++];
  22146. stack.push((b << 8) | data[i++]);
  22147. }
  22148. }
  22149. } else if ((op & 0xF8) === 0xB0) { // PUSHB - pushes bytes
  22150. n = op - 0xB0 + 1;
  22151. if (inFDEF || inELSE) {
  22152. i += n;
  22153. } else {
  22154. for (j = 0; j < n; j++) {
  22155. stack.push(data[i++]);
  22156. }
  22157. }
  22158. } else if ((op & 0xF8) === 0xB8) { // PUSHW - pushes words
  22159. n = op - 0xB8 + 1;
  22160. if (inFDEF || inELSE) {
  22161. i += n * 2;
  22162. } else {
  22163. for (j = 0; j < n; j++) {
  22164. b = data[i++];
  22165. stack.push((b << 8) | data[i++]);
  22166. }
  22167. }
  22168. } else if (op === 0x2B && !tooComplexToFollowFunctions) { // CALL
  22169. if (!inFDEF && !inELSE) {
  22170. // collecting inforamtion about which functions are used
  22171. funcId = stack[stack.length - 1];
  22172. ttContext.functionsUsed[funcId] = true;
  22173. if (funcId in ttContext.functionsStackDeltas) {
  22174. stack.length += ttContext.functionsStackDeltas[funcId];
  22175. } else if (funcId in ttContext.functionsDefined &&
  22176. functionsCalled.indexOf(funcId) < 0) {
  22177. callstack.push({data: data, i: i, stackTop: stack.length - 1});
  22178. functionsCalled.push(funcId);
  22179. pc = ttContext.functionsDefined[funcId];
  22180. if (!pc) {
  22181. warn('TT: CALL non-existent function');
  22182. ttContext.hintsValid = false;
  22183. return;
  22184. }
  22185. data = pc.data;
  22186. i = pc.i;
  22187. }
  22188. }
  22189. } else if (op === 0x2C && !tooComplexToFollowFunctions) { // FDEF
  22190. if (inFDEF || inELSE) {
  22191. warn('TT: nested FDEFs not allowed');
  22192. tooComplexToFollowFunctions = true;
  22193. }
  22194. inFDEF = true;
  22195. // collecting inforamtion about which functions are defined
  22196. lastDeff = i;
  22197. funcId = stack.pop();
  22198. ttContext.functionsDefined[funcId] = {data: data, i: i};
  22199. } else if (op === 0x2D) { // ENDF - end of function
  22200. if (inFDEF) {
  22201. inFDEF = false;
  22202. lastEndf = i;
  22203. } else {
  22204. pc = callstack.pop();
  22205. if (!pc) {
  22206. warn('TT: ENDF bad stack');
  22207. ttContext.hintsValid = false;
  22208. return;
  22209. }
  22210. funcId = functionsCalled.pop();
  22211. data = pc.data;
  22212. i = pc.i;
  22213. ttContext.functionsStackDeltas[funcId] =
  22214. stack.length - pc.stackTop;
  22215. }
  22216. } else if (op === 0x89) { // IDEF - instruction definition
  22217. if (inFDEF || inELSE) {
  22218. warn('TT: nested IDEFs not allowed');
  22219. tooComplexToFollowFunctions = true;
  22220. }
  22221. inFDEF = true;
  22222. // recording it as a function to track ENDF
  22223. lastDeff = i;
  22224. } else if (op === 0x58) { // IF
  22225. ++ifLevel;
  22226. } else if (op === 0x1B) { // ELSE
  22227. inELSE = ifLevel;
  22228. } else if (op === 0x59) { // EIF
  22229. if (inELSE === ifLevel) {
  22230. inELSE = 0;
  22231. }
  22232. --ifLevel;
  22233. } else if (op === 0x1C) { // JMPR
  22234. if (!inFDEF && !inELSE) {
  22235. var offset = stack[stack.length - 1];
  22236. // only jumping forward to prevent infinite loop
  22237. if (offset > 0) {
  22238. i += offset - 1;
  22239. }
  22240. }
  22241. }
  22242. // Adjusting stack not extactly, but just enough to get function id
  22243. if (!inFDEF && !inELSE) {
  22244. var stackDelta = op <= 0x8E ? TTOpsStackDeltas[op] :
  22245. op >= 0xC0 && op <= 0xDF ? -1 : op >= 0xE0 ? -2 : 0;
  22246. if (op >= 0x71 && op <= 0x75) {
  22247. n = stack.pop();
  22248. if (n === n) {
  22249. stackDelta = -n * 2;
  22250. }
  22251. }
  22252. while (stackDelta < 0 && stack.length > 0) {
  22253. stack.pop();
  22254. stackDelta++;
  22255. }
  22256. while (stackDelta > 0) {
  22257. stack.push(NaN); // pushing any number into stack
  22258. stackDelta--;
  22259. }
  22260. }
  22261. }
  22262. ttContext.tooComplexToFollowFunctions = tooComplexToFollowFunctions;
  22263. var content = [data];
  22264. if (i > data.length) {
  22265. content.push(new Uint8Array(i - data.length));
  22266. }
  22267. if (lastDeff > lastEndf) {
  22268. warn('TT: complementing a missing function tail');
  22269. // new function definition started, but not finished
  22270. // complete function by [CLEAR, ENDF]
  22271. content.push(new Uint8Array([0x22, 0x2D]));
  22272. }
  22273. foldTTTable(table, content);
  22274. }
  22275. function checkInvalidFunctions(ttContext, maxFunctionDefs) {
  22276. if (ttContext.tooComplexToFollowFunctions) {
  22277. return;
  22278. }
  22279. if (ttContext.functionsDefined.length > maxFunctionDefs) {
  22280. warn('TT: more functions defined than expected');
  22281. ttContext.hintsValid = false;
  22282. return;
  22283. }
  22284. for (var j = 0, jj = ttContext.functionsUsed.length; j < jj; j++) {
  22285. if (j > maxFunctionDefs) {
  22286. warn('TT: invalid function id: ' + j);
  22287. ttContext.hintsValid = false;
  22288. return;
  22289. }
  22290. if (ttContext.functionsUsed[j] && !ttContext.functionsDefined[j]) {
  22291. warn('TT: undefined function: ' + j);
  22292. ttContext.hintsValid = false;
  22293. return;
  22294. }
  22295. }
  22296. }
  22297. function foldTTTable(table, content) {
  22298. if (content.length > 1) {
  22299. // concatenating the content items
  22300. var newLength = 0;
  22301. var j, jj;
  22302. for (j = 0, jj = content.length; j < jj; j++) {
  22303. newLength += content[j].length;
  22304. }
  22305. newLength = (newLength + 3) & ~3;
  22306. var result = new Uint8Array(newLength);
  22307. var pos = 0;
  22308. for (j = 0, jj = content.length; j < jj; j++) {
  22309. result.set(content[j], pos);
  22310. pos += content[j].length;
  22311. }
  22312. table.data = result;
  22313. table.length = newLength;
  22314. }
  22315. }
  22316. function sanitizeTTPrograms(fpgm, prep, cvt) {
  22317. var ttContext = {
  22318. functionsDefined: [],
  22319. functionsUsed: [],
  22320. functionsStackDeltas: [],
  22321. tooComplexToFollowFunctions: false,
  22322. hintsValid: true
  22323. };
  22324. if (fpgm) {
  22325. sanitizeTTProgram(fpgm, ttContext);
  22326. }
  22327. if (prep) {
  22328. sanitizeTTProgram(prep, ttContext);
  22329. }
  22330. if (fpgm) {
  22331. checkInvalidFunctions(ttContext, maxFunctionDefs);
  22332. }
  22333. if (cvt && (cvt.length & 1)) {
  22334. var cvtData = new Uint8Array(cvt.length + 1);
  22335. cvtData.set(cvt.data);
  22336. cvt.data = cvtData;
  22337. }
  22338. return ttContext.hintsValid;
  22339. }
  22340. // The following steps modify the original font data, making copy
  22341. font = new Stream(new Uint8Array(font.getBytes()));
  22342. var VALID_TABLES = ['OS/2', 'cmap', 'head', 'hhea', 'hmtx', 'maxp',
  22343. 'name', 'post', 'loca', 'glyf', 'fpgm', 'prep', 'cvt ', 'CFF '];
  22344. var header = readOpenTypeHeader(font);
  22345. var numTables = header.numTables;
  22346. var cff, cffFile;
  22347. var tables = { 'OS/2': null, cmap: null, head: null, hhea: null,
  22348. hmtx: null, maxp: null, name: null, post: null };
  22349. var table;
  22350. for (var i = 0; i < numTables; i++) {
  22351. table = readTableEntry(font);
  22352. if (VALID_TABLES.indexOf(table.tag) < 0) {
  22353. continue; // skipping table if it's not a required or optional table
  22354. }
  22355. if (table.length === 0) {
  22356. continue; // skipping empty tables
  22357. }
  22358. tables[table.tag] = table;
  22359. }
  22360. var isTrueType = !tables['CFF '];
  22361. if (!isTrueType) {
  22362. // OpenType font
  22363. if (header.version === 'OTTO' ||
  22364. !tables.head || !tables.hhea || !tables.maxp || !tables.post) {
  22365. // no major tables: throwing everything at CFFFont
  22366. cffFile = new Stream(tables['CFF '].data);
  22367. cff = new CFFFont(cffFile, properties);
  22368. return this.convert(name, cff, properties);
  22369. }
  22370. delete tables.glyf;
  22371. delete tables.loca;
  22372. delete tables.fpgm;
  22373. delete tables.prep;
  22374. delete tables['cvt '];
  22375. this.isOpenType = true;
  22376. } else {
  22377. if (!tables.glyf || !tables.loca) {
  22378. error('Required "glyf" or "loca" tables are not found');
  22379. }
  22380. this.isOpenType = false;
  22381. }
  22382. if (!tables.maxp) {
  22383. error('Required "maxp" table is not found');
  22384. }
  22385. font.pos = (font.start || 0) + tables.maxp.offset;
  22386. var version = font.getInt32();
  22387. var numGlyphs = font.getUint16();
  22388. var maxFunctionDefs = 0;
  22389. if (version >= 0x00010000 && tables.maxp.length >= 22) {
  22390. // maxZones can be invalid
  22391. font.pos += 8;
  22392. var maxZones = font.getUint16();
  22393. if (maxZones > 2) { // reset to 2 if font has invalid maxZones
  22394. tables.maxp.data[14] = 0;
  22395. tables.maxp.data[15] = 2;
  22396. }
  22397. font.pos += 4;
  22398. maxFunctionDefs = font.getUint16();
  22399. }
  22400. var dupFirstEntry = false;
  22401. if (properties.type === 'CIDFontType2' && properties.toUnicode &&
  22402. properties.toUnicode.get(0) > '\u0000') {
  22403. // oracle's defect (see 3427), duplicating first entry
  22404. dupFirstEntry = true;
  22405. numGlyphs++;
  22406. tables.maxp.data[4] = numGlyphs >> 8;
  22407. tables.maxp.data[5] = numGlyphs & 255;
  22408. }
  22409. var hintsValid = sanitizeTTPrograms(tables.fpgm, tables.prep,
  22410. tables['cvt '], maxFunctionDefs);
  22411. if (!hintsValid) {
  22412. delete tables.fpgm;
  22413. delete tables.prep;
  22414. delete tables['cvt '];
  22415. }
  22416. // Ensure the hmtx table contains the advance width and
  22417. // sidebearings information for numGlyphs in the maxp table
  22418. sanitizeMetrics(font, tables.hhea, tables.hmtx, numGlyphs);
  22419. if (!tables.head) {
  22420. error('Required "head" table is not found');
  22421. }
  22422. sanitizeHead(tables.head, numGlyphs, isTrueType ? tables.loca.length : 0);
  22423. var missingGlyphs = {};
  22424. if (isTrueType) {
  22425. var isGlyphLocationsLong = int16(tables.head.data[50],
  22426. tables.head.data[51]);
  22427. missingGlyphs = sanitizeGlyphLocations(tables.loca, tables.glyf,
  22428. numGlyphs, isGlyphLocationsLong,
  22429. hintsValid, dupFirstEntry);
  22430. }
  22431. if (!tables.hhea) {
  22432. error('Required "hhea" table is not found');
  22433. }
  22434. // Sanitizer reduces the glyph advanceWidth to the maxAdvanceWidth
  22435. // Sometimes it's 0. That needs to be fixed
  22436. if (tables.hhea.data[10] === 0 && tables.hhea.data[11] === 0) {
  22437. tables.hhea.data[10] = 0xFF;
  22438. tables.hhea.data[11] = 0xFF;
  22439. }
  22440. // The 'post' table has glyphs names.
  22441. if (tables.post) {
  22442. var valid = readPostScriptTable(tables.post, properties, numGlyphs);
  22443. if (!valid) {
  22444. tables.post = null;
  22445. }
  22446. }
  22447. var charCodeToGlyphId = [], charCode, toUnicode = properties.toUnicode;
  22448. function hasGlyph(glyphId, charCode) {
  22449. if (!missingGlyphs[glyphId]) {
  22450. return true;
  22451. }
  22452. if (charCode >= 0 && toUnicode.has(charCode)) {
  22453. return true;
  22454. }
  22455. return false;
  22456. }
  22457. if (properties.type === 'CIDFontType2') {
  22458. var cidToGidMap = properties.cidToGidMap || [];
  22459. var isCidToGidMapEmpty = cidToGidMap.length === 0;
  22460. properties.cMap.forEach(function(charCode, cid) {
  22461. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  22462. var glyphId = -1;
  22463. if (isCidToGidMapEmpty) {
  22464. glyphId = charCode;
  22465. } else if (cidToGidMap[cid] !== undefined) {
  22466. glyphId = cidToGidMap[cid];
  22467. }
  22468. if (glyphId >= 0 && glyphId < numGlyphs &&
  22469. hasGlyph(glyphId, charCode)) {
  22470. charCodeToGlyphId[charCode] = glyphId;
  22471. }
  22472. });
  22473. if (dupFirstEntry) {
  22474. charCodeToGlyphId[0] = numGlyphs - 1;
  22475. }
  22476. } else {
  22477. // Most of the following logic in this code branch is based on the
  22478. // 9.6.6.4 of the PDF spec.
  22479. var cmapTable = readCmapTable(tables.cmap, font, this.isSymbolicFont);
  22480. var cmapPlatformId = cmapTable.platformId;
  22481. var cmapEncodingId = cmapTable.encodingId;
  22482. var cmapMappings = cmapTable.mappings;
  22483. var cmapMappingsLength = cmapMappings.length;
  22484. var hasEncoding = properties.differences.length ||
  22485. !!properties.baseEncodingName;
  22486. // The spec seems to imply that if the font is symbolic the encoding
  22487. // should be ignored, this doesn't appear to work for 'preistabelle.pdf'
  22488. // where the the font is symbolic and it has an encoding.
  22489. if (hasEncoding &&
  22490. (cmapPlatformId === 3 && cmapEncodingId === 1 ||
  22491. cmapPlatformId === 1 && cmapEncodingId === 0) ||
  22492. (cmapPlatformId === -1 && cmapEncodingId === -1 && // Temporary hack
  22493. !!Encodings[properties.baseEncodingName])) { // Temporary hack
  22494. // When no preferred cmap table was found and |baseEncodingName| is
  22495. // one of the predefined encodings, we seem to obtain a better
  22496. // |charCodeToGlyphId| map from the code below (fixes bug 1057544).
  22497. // TODO: Note that this is a hack which should be removed as soon as
  22498. // we have proper support for more exotic cmap tables.
  22499. var baseEncoding = [];
  22500. if (properties.baseEncodingName === 'MacRomanEncoding' ||
  22501. properties.baseEncodingName === 'WinAnsiEncoding') {
  22502. baseEncoding = Encodings[properties.baseEncodingName];
  22503. }
  22504. for (charCode = 0; charCode < 256; charCode++) {
  22505. var glyphName;
  22506. if (this.differences && charCode in this.differences) {
  22507. glyphName = this.differences[charCode];
  22508. } else if (charCode in baseEncoding &&
  22509. baseEncoding[charCode] !== '') {
  22510. glyphName = baseEncoding[charCode];
  22511. } else {
  22512. glyphName = Encodings.StandardEncoding[charCode];
  22513. }
  22514. if (!glyphName) {
  22515. continue;
  22516. }
  22517. var unicodeOrCharCode;
  22518. if (cmapPlatformId === 3 && cmapEncodingId === 1) {
  22519. unicodeOrCharCode = GlyphsUnicode[glyphName];
  22520. } else if (cmapPlatformId === 1 && cmapEncodingId === 0) {
  22521. // TODO: the encoding needs to be updated with mac os table.
  22522. unicodeOrCharCode = Encodings.MacRomanEncoding.indexOf(glyphName);
  22523. }
  22524. var found = false;
  22525. for (i = 0; i < cmapMappingsLength; ++i) {
  22526. if (cmapMappings[i].charCode === unicodeOrCharCode &&
  22527. hasGlyph(cmapMappings[i].glyphId, unicodeOrCharCode)) {
  22528. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  22529. found = true;
  22530. break;
  22531. }
  22532. }
  22533. if (!found && properties.glyphNames) {
  22534. // Try to map using the post table. There are currently no known
  22535. // pdfs that this fixes.
  22536. var glyphId = properties.glyphNames.indexOf(glyphName);
  22537. if (glyphId > 0 && hasGlyph(glyphId, -1)) {
  22538. charCodeToGlyphId[charCode] = glyphId;
  22539. }
  22540. }
  22541. }
  22542. } else if (cmapPlatformId === 0 && cmapEncodingId === 0) {
  22543. // Default Unicode semantics, use the charcodes as is.
  22544. for (i = 0; i < cmapMappingsLength; ++i) {
  22545. charCodeToGlyphId[cmapMappings[i].charCode] =
  22546. cmapMappings[i].glyphId;
  22547. }
  22548. } else {
  22549. // For (3, 0) cmap tables:
  22550. // The charcode key being stored in charCodeToGlyphId is the lower
  22551. // byte of the two-byte charcodes of the cmap table since according to
  22552. // the spec: 'each byte from the string shall be prepended with the
  22553. // high byte of the range [of charcodes in the cmap table], to form
  22554. // a two-byte character, which shall be used to select the
  22555. // associated glyph description from the subtable'.
  22556. //
  22557. // For (1, 0) cmap tables:
  22558. // 'single bytes from the string shall be used to look up the
  22559. // associated glyph descriptions from the subtable'. This means
  22560. // charcodes in the cmap will be single bytes, so no-op since
  22561. // glyph.charCode & 0xFF === glyph.charCode
  22562. for (i = 0; i < cmapMappingsLength; ++i) {
  22563. charCode = cmapMappings[i].charCode & 0xFF;
  22564. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  22565. }
  22566. }
  22567. }
  22568. if (charCodeToGlyphId.length === 0) {
  22569. // defines at least one glyph
  22570. charCodeToGlyphId[0] = 0;
  22571. }
  22572. // Converting glyphs and ids into font's cmap table
  22573. var newMapping = adjustMapping(charCodeToGlyphId, properties);
  22574. this.toFontChar = newMapping.toFontChar;
  22575. tables.cmap = {
  22576. tag: 'cmap',
  22577. data: createCmapTable(newMapping.charCodeToGlyphId)
  22578. };
  22579. if (!tables['OS/2'] || !validateOS2Table(tables['OS/2'])) {
  22580. // extract some more font properties from the OpenType head and
  22581. // hhea tables; yMin and descent value are always negative
  22582. var override = {
  22583. unitsPerEm: int16(tables.head.data[18], tables.head.data[19]),
  22584. yMax: int16(tables.head.data[42], tables.head.data[43]),
  22585. yMin: int16(tables.head.data[38], tables.head.data[39]) - 0x10000,
  22586. ascent: int16(tables.hhea.data[4], tables.hhea.data[5]),
  22587. descent: int16(tables.hhea.data[6], tables.hhea.data[7]) - 0x10000
  22588. };
  22589. tables['OS/2'] = {
  22590. tag: 'OS/2',
  22591. data: createOS2Table(properties, newMapping.charCodeToGlyphId,
  22592. override)
  22593. };
  22594. }
  22595. // Rewrite the 'post' table if needed
  22596. if (!tables.post) {
  22597. tables.post = {
  22598. tag: 'post',
  22599. data: createPostTable(properties)
  22600. };
  22601. }
  22602. if (!isTrueType) {
  22603. try {
  22604. // Trying to repair CFF file
  22605. cffFile = new Stream(tables['CFF '].data);
  22606. var parser = new CFFParser(cffFile, properties);
  22607. cff = parser.parse();
  22608. var compiler = new CFFCompiler(cff);
  22609. tables['CFF '].data = compiler.compile();
  22610. } catch (e) {
  22611. warn('Failed to compile font ' + properties.loadedName);
  22612. }
  22613. }
  22614. // Re-creating 'name' table
  22615. if (!tables.name) {
  22616. tables.name = {
  22617. tag: 'name',
  22618. data: createNameTable(this.name)
  22619. };
  22620. } else {
  22621. // ... using existing 'name' table as prototype
  22622. var namePrototype = readNameTable(tables.name);
  22623. tables.name.data = createNameTable(name, namePrototype);
  22624. }
  22625. var builder = new OpenTypeFileBuilder(header.version);
  22626. for (var tableTag in tables) {
  22627. builder.addTable(tableTag, tables[tableTag].data);
  22628. }
  22629. return builder.toArray();
  22630. },
  22631. convert: function Font_convert(fontName, font, properties) {
  22632. // TODO: Check the charstring widths to determine this.
  22633. properties.fixedPitch = false;
  22634. var mapping = font.getGlyphMapping(properties);
  22635. var newMapping = adjustMapping(mapping, properties);
  22636. this.toFontChar = newMapping.toFontChar;
  22637. var numGlyphs = font.numGlyphs;
  22638. function getCharCodes(charCodeToGlyphId, glyphId) {
  22639. var charCodes = null;
  22640. for (var charCode in charCodeToGlyphId) {
  22641. if (glyphId === charCodeToGlyphId[charCode]) {
  22642. if (!charCodes) {
  22643. charCodes = [];
  22644. }
  22645. charCodes.push(charCode | 0);
  22646. }
  22647. }
  22648. return charCodes;
  22649. }
  22650. function createCharCode(charCodeToGlyphId, glyphId) {
  22651. for (var charCode in charCodeToGlyphId) {
  22652. if (glyphId === charCodeToGlyphId[charCode]) {
  22653. return charCode | 0;
  22654. }
  22655. }
  22656. newMapping.charCodeToGlyphId[newMapping.nextAvailableFontCharCode] =
  22657. glyphId;
  22658. return newMapping.nextAvailableFontCharCode++;
  22659. }
  22660. var seacs = font.seacs;
  22661. if (SEAC_ANALYSIS_ENABLED && seacs && seacs.length) {
  22662. var matrix = properties.fontMatrix || FONT_IDENTITY_MATRIX;
  22663. var charset = font.getCharset();
  22664. var seacMap = Object.create(null);
  22665. for (var glyphId in seacs) {
  22666. glyphId |= 0;
  22667. var seac = seacs[glyphId];
  22668. var baseGlyphName = Encodings.StandardEncoding[seac[2]];
  22669. var accentGlyphName = Encodings.StandardEncoding[seac[3]];
  22670. var baseGlyphId = charset.indexOf(baseGlyphName);
  22671. var accentGlyphId = charset.indexOf(accentGlyphName);
  22672. if (baseGlyphId < 0 || accentGlyphId < 0) {
  22673. continue;
  22674. }
  22675. var accentOffset = {
  22676. x: seac[0] * matrix[0] + seac[1] * matrix[2] + matrix[4],
  22677. y: seac[0] * matrix[1] + seac[1] * matrix[3] + matrix[5]
  22678. };
  22679. var charCodes = getCharCodes(mapping, glyphId);
  22680. if (!charCodes) {
  22681. // There's no point in mapping it if the char code was never mapped
  22682. // to begin with.
  22683. continue;
  22684. }
  22685. for (var i = 0, ii = charCodes.length; i < ii; i++) {
  22686. var charCode = charCodes[i];
  22687. // Find a fontCharCode that maps to the base and accent glyphs.
  22688. // If one doesn't exists, create it.
  22689. var charCodeToGlyphId = newMapping.charCodeToGlyphId;
  22690. var baseFontCharCode = createCharCode(charCodeToGlyphId,
  22691. baseGlyphId);
  22692. var accentFontCharCode = createCharCode(charCodeToGlyphId,
  22693. accentGlyphId);
  22694. seacMap[charCode] = {
  22695. baseFontCharCode: baseFontCharCode,
  22696. accentFontCharCode: accentFontCharCode,
  22697. accentOffset: accentOffset
  22698. };
  22699. }
  22700. }
  22701. properties.seacMap = seacMap;
  22702. }
  22703. var unitsPerEm = 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0];
  22704. var builder = new OpenTypeFileBuilder('\x4F\x54\x54\x4F');
  22705. // PostScript Font Program
  22706. builder.addTable('CFF ', font.data);
  22707. // OS/2 and Windows Specific metrics
  22708. builder.addTable('OS/2', createOS2Table(properties,
  22709. newMapping.charCodeToGlyphId));
  22710. // Character to glyphs mapping
  22711. builder.addTable('cmap', createCmapTable(newMapping.charCodeToGlyphId));
  22712. // Font header
  22713. builder.addTable('head',
  22714. '\x00\x01\x00\x00' + // Version number
  22715. '\x00\x00\x10\x00' + // fontRevision
  22716. '\x00\x00\x00\x00' + // checksumAdjustement
  22717. '\x5F\x0F\x3C\xF5' + // magicNumber
  22718. '\x00\x00' + // Flags
  22719. safeString16(unitsPerEm) + // unitsPerEM
  22720. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // creation date
  22721. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // modifification date
  22722. '\x00\x00' + // xMin
  22723. safeString16(properties.descent) + // yMin
  22724. '\x0F\xFF' + // xMax
  22725. safeString16(properties.ascent) + // yMax
  22726. string16(properties.italicAngle ? 2 : 0) + // macStyle
  22727. '\x00\x11' + // lowestRecPPEM
  22728. '\x00\x00' + // fontDirectionHint
  22729. '\x00\x00' + // indexToLocFormat
  22730. '\x00\x00'); // glyphDataFormat
  22731. // Horizontal header
  22732. builder.addTable('hhea',
  22733. '\x00\x01\x00\x00' + // Version number
  22734. safeString16(properties.ascent) + // Typographic Ascent
  22735. safeString16(properties.descent) + // Typographic Descent
  22736. '\x00\x00' + // Line Gap
  22737. '\xFF\xFF' + // advanceWidthMax
  22738. '\x00\x00' + // minLeftSidebearing
  22739. '\x00\x00' + // minRightSidebearing
  22740. '\x00\x00' + // xMaxExtent
  22741. safeString16(properties.capHeight) + // caretSlopeRise
  22742. safeString16(Math.tan(properties.italicAngle) *
  22743. properties.xHeight) + // caretSlopeRun
  22744. '\x00\x00' + // caretOffset
  22745. '\x00\x00' + // -reserved-
  22746. '\x00\x00' + // -reserved-
  22747. '\x00\x00' + // -reserved-
  22748. '\x00\x00' + // -reserved-
  22749. '\x00\x00' + // metricDataFormat
  22750. string16(numGlyphs)); // Number of HMetrics
  22751. // Horizontal metrics
  22752. builder.addTable('hmtx', (function fontFieldsHmtx() {
  22753. var charstrings = font.charstrings;
  22754. var cffWidths = font.cff ? font.cff.widths : null;
  22755. var hmtx = '\x00\x00\x00\x00'; // Fake .notdef
  22756. for (var i = 1, ii = numGlyphs; i < ii; i++) {
  22757. var width = 0;
  22758. if (charstrings) {
  22759. var charstring = charstrings[i - 1];
  22760. width = 'width' in charstring ? charstring.width : 0;
  22761. } else if (cffWidths) {
  22762. width = Math.ceil(cffWidths[i] || 0);
  22763. }
  22764. hmtx += string16(width) + string16(0);
  22765. }
  22766. return hmtx;
  22767. })());
  22768. // Maximum profile
  22769. builder.addTable('maxp',
  22770. '\x00\x00\x50\x00' + // Version number
  22771. string16(numGlyphs)); // Num of glyphs
  22772. // Naming tables
  22773. builder.addTable('name', createNameTable(fontName));
  22774. // PostScript informations
  22775. builder.addTable('post', createPostTable(properties));
  22776. return builder.toArray();
  22777. },
  22778. /**
  22779. * Builds a char code to unicode map based on section 9.10 of the spec.
  22780. * @param {Object} properties Font properties object.
  22781. * @return {Object} A ToUnicodeMap object.
  22782. */
  22783. buildToUnicode: function Font_buildToUnicode(properties) {
  22784. // Section 9.10.2 Mapping Character Codes to Unicode Values
  22785. if (properties.toUnicode && properties.toUnicode.length !== 0) {
  22786. return properties.toUnicode;
  22787. }
  22788. // According to the spec if the font is a simple font we should only map
  22789. // to unicode if the base encoding is MacRoman, MacExpert, or WinAnsi or
  22790. // the differences array only contains adobe standard or symbol set names,
  22791. // in pratice it seems better to always try to create a toUnicode
  22792. // map based of the default encoding.
  22793. var toUnicode, charcode;
  22794. if (!properties.composite /* is simple font */) {
  22795. toUnicode = [];
  22796. var encoding = properties.defaultEncoding.slice();
  22797. var baseEncodingName = properties.baseEncodingName;
  22798. // Merge in the differences array.
  22799. var differences = properties.differences;
  22800. for (charcode in differences) {
  22801. encoding[charcode] = differences[charcode];
  22802. }
  22803. for (charcode in encoding) {
  22804. // a) Map the character code to a character name.
  22805. var glyphName = encoding[charcode];
  22806. // b) Look up the character name in the Adobe Glyph List (see the
  22807. // Bibliography) to obtain the corresponding Unicode value.
  22808. if (glyphName === '') {
  22809. continue;
  22810. } else if (GlyphsUnicode[glyphName] === undefined) {
  22811. // (undocumented) c) Few heuristics to recognize unknown glyphs
  22812. // NOTE: Adobe Reader does not do this step, but OSX Preview does
  22813. var code = 0;
  22814. switch (glyphName[0]) {
  22815. case 'G': // Gxx glyph
  22816. if (glyphName.length === 3) {
  22817. code = parseInt(glyphName.substr(1), 16);
  22818. }
  22819. break;
  22820. case 'g': // g00xx glyph
  22821. if (glyphName.length === 5) {
  22822. code = parseInt(glyphName.substr(1), 16);
  22823. }
  22824. break;
  22825. case 'C': // Cddd glyph
  22826. case 'c': // cddd glyph
  22827. if (glyphName.length >= 3) {
  22828. code = +glyphName.substr(1);
  22829. }
  22830. break;
  22831. }
  22832. if (code) {
  22833. // If |baseEncodingName| is one the predefined encodings,
  22834. // and |code| equals |charcode|, using the glyph defined in the
  22835. // baseEncoding seems to yield a better |toUnicode| mapping
  22836. // (fixes issue 5070).
  22837. if (baseEncodingName && code === +charcode) {
  22838. var baseEncoding = Encodings[baseEncodingName];
  22839. if (baseEncoding && (glyphName = baseEncoding[charcode])) {
  22840. toUnicode[charcode] =
  22841. String.fromCharCode(GlyphsUnicode[glyphName]);
  22842. continue;
  22843. }
  22844. }
  22845. toUnicode[charcode] = String.fromCharCode(code);
  22846. }
  22847. continue;
  22848. }
  22849. toUnicode[charcode] = String.fromCharCode(GlyphsUnicode[glyphName]);
  22850. }
  22851. return new ToUnicodeMap(toUnicode);
  22852. }
  22853. // If the font is a composite font that uses one of the predefined CMaps
  22854. // listed in Table 118 (except Identity–H and Identity–V) or whose
  22855. // descendant CIDFont uses the Adobe-GB1, Adobe-CNS1, Adobe-Japan1, or
  22856. // Adobe-Korea1 character collection:
  22857. if (properties.composite && (
  22858. (properties.cMap.builtInCMap &&
  22859. !(properties.cMap instanceof IdentityCMap)) ||
  22860. (properties.cidSystemInfo.registry === 'Adobe' &&
  22861. (properties.cidSystemInfo.ordering === 'GB1' ||
  22862. properties.cidSystemInfo.ordering === 'CNS1' ||
  22863. properties.cidSystemInfo.ordering === 'Japan1' ||
  22864. properties.cidSystemInfo.ordering === 'Korea1')))) {
  22865. // Then:
  22866. // a) Map the character code to a character identifier (CID) according
  22867. // to the font’s CMap.
  22868. // b) Obtain the registry and ordering of the character collection used
  22869. // by the font’s CMap (for example, Adobe and Japan1) from its
  22870. // CIDSystemInfo dictionary.
  22871. var registry = properties.cidSystemInfo.registry;
  22872. var ordering = properties.cidSystemInfo.ordering;
  22873. // c) Construct a second CMap name by concatenating the registry and
  22874. // ordering obtained in step (b) in the format registry–ordering–UCS2
  22875. // (for example, Adobe–Japan1–UCS2).
  22876. var ucs2CMapName = new Name(registry + '-' + ordering + '-UCS2');
  22877. // d) Obtain the CMap with the name constructed in step (c) (available
  22878. // from the ASN Web site; see the Bibliography).
  22879. var ucs2CMap = CMapFactory.create(ucs2CMapName,
  22880. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  22881. var cMap = properties.cMap;
  22882. toUnicode = [];
  22883. cMap.forEach(function(charcode, cid) {
  22884. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  22885. // e) Map the CID obtained in step (a) according to the CMap obtained
  22886. // in step (d), producing a Unicode value.
  22887. var ucs2 = ucs2CMap.lookup(cid);
  22888. if (ucs2) {
  22889. toUnicode[charcode] =
  22890. String.fromCharCode((ucs2.charCodeAt(0) << 8) +
  22891. ucs2.charCodeAt(1));
  22892. }
  22893. });
  22894. return new ToUnicodeMap(toUnicode);
  22895. }
  22896. // The viewer's choice, just use an identity map.
  22897. return new IdentityToUnicodeMap(properties.firstChar,
  22898. properties.lastChar);
  22899. },
  22900. get spaceWidth() {
  22901. if ('_shadowWidth' in this) {
  22902. return this._shadowWidth;
  22903. }
  22904. // trying to estimate space character width
  22905. var possibleSpaceReplacements = ['space', 'minus', 'one', 'i'];
  22906. var width;
  22907. for (var i = 0, ii = possibleSpaceReplacements.length; i < ii; i++) {
  22908. var glyphName = possibleSpaceReplacements[i];
  22909. // if possible, getting width by glyph name
  22910. if (glyphName in this.widths) {
  22911. width = this.widths[glyphName];
  22912. break;
  22913. }
  22914. var glyphUnicode = GlyphsUnicode[glyphName];
  22915. // finding the charcode via unicodeToCID map
  22916. var charcode = 0;
  22917. if (this.composite) {
  22918. if (this.cMap.contains(glyphUnicode)) {
  22919. charcode = this.cMap.lookup(glyphUnicode);
  22920. }
  22921. }
  22922. // ... via toUnicode map
  22923. if (!charcode && 'toUnicode' in this) {
  22924. charcode = this.toUnicode.charCodeOf(glyphUnicode);
  22925. }
  22926. // setting it to unicode if negative or undefined
  22927. if (charcode <= 0) {
  22928. charcode = glyphUnicode;
  22929. }
  22930. // trying to get width via charcode
  22931. width = this.widths[charcode];
  22932. if (width) {
  22933. break; // the non-zero width found
  22934. }
  22935. }
  22936. width = width || this.defaultWidth;
  22937. // Do not shadow the property here. See discussion:
  22938. // https://github.com/mozilla/pdf.js/pull/2127#discussion_r1662280
  22939. this._shadowWidth = width;
  22940. return width;
  22941. },
  22942. charToGlyph: function Font_charToGlyph(charcode) {
  22943. var fontCharCode, width, operatorListId;
  22944. var widthCode = charcode;
  22945. if (this.cMap && this.cMap.contains(charcode)) {
  22946. widthCode = this.cMap.lookup(charcode);
  22947. }
  22948. width = this.widths[widthCode];
  22949. width = isNum(width) ? width : this.defaultWidth;
  22950. var vmetric = this.vmetrics && this.vmetrics[widthCode];
  22951. var unicode = this.toUnicode.get(charcode) || charcode;
  22952. if (typeof unicode === 'number') {
  22953. unicode = String.fromCharCode(unicode);
  22954. }
  22955. // First try the toFontChar map, if it's not there then try falling
  22956. // back to the char code.
  22957. fontCharCode = this.toFontChar[charcode] || charcode;
  22958. if (this.missingFile) {
  22959. fontCharCode = mapSpecialUnicodeValues(fontCharCode);
  22960. }
  22961. if (this.isType3Font) {
  22962. // Font char code in this case is actually a glyph name.
  22963. operatorListId = fontCharCode;
  22964. }
  22965. var accent = null;
  22966. if (this.seacMap && this.seacMap[charcode]) {
  22967. var seac = this.seacMap[charcode];
  22968. fontCharCode = seac.baseFontCharCode;
  22969. accent = {
  22970. fontChar: String.fromCharCode(seac.accentFontCharCode),
  22971. offset: seac.accentOffset
  22972. };
  22973. }
  22974. var fontChar = String.fromCharCode(fontCharCode);
  22975. var glyph = this.glyphCache[charcode];
  22976. if (!glyph ||
  22977. !glyph.matchesForCache(fontChar, unicode, accent, width, vmetric,
  22978. operatorListId)) {
  22979. glyph = new Glyph(fontChar, unicode, accent, width, vmetric,
  22980. operatorListId);
  22981. this.glyphCache[charcode] = glyph;
  22982. }
  22983. return glyph;
  22984. },
  22985. charsToGlyphs: function Font_charsToGlyphs(chars) {
  22986. var charsCache = this.charsCache;
  22987. var glyphs, glyph, charcode;
  22988. // if we translated this string before, just grab it from the cache
  22989. if (charsCache) {
  22990. glyphs = charsCache[chars];
  22991. if (glyphs) {
  22992. return glyphs;
  22993. }
  22994. }
  22995. // lazily create the translation cache
  22996. if (!charsCache) {
  22997. charsCache = this.charsCache = Object.create(null);
  22998. }
  22999. glyphs = [];
  23000. var charsCacheKey = chars;
  23001. var i = 0, ii;
  23002. if (this.cMap) {
  23003. // composite fonts have multi-byte strings convert the string from
  23004. // single-byte to multi-byte
  23005. var c = {};
  23006. while (i < chars.length) {
  23007. this.cMap.readCharCode(chars, i, c);
  23008. charcode = c.charcode;
  23009. var length = c.length;
  23010. i += length;
  23011. glyph = this.charToGlyph(charcode);
  23012. glyphs.push(glyph);
  23013. // placing null after each word break charcode (ASCII SPACE)
  23014. // Ignore occurences of 0x20 in multiple-byte codes.
  23015. if (length === 1 && chars.charCodeAt(i - 1) === 0x20) {
  23016. glyphs.push(null);
  23017. }
  23018. }
  23019. } else {
  23020. for (i = 0, ii = chars.length; i < ii; ++i) {
  23021. charcode = chars.charCodeAt(i);
  23022. glyph = this.charToGlyph(charcode);
  23023. glyphs.push(glyph);
  23024. if (charcode === 0x20) {
  23025. glyphs.push(null);
  23026. }
  23027. }
  23028. }
  23029. // Enter the translated string into the cache
  23030. return (charsCache[charsCacheKey] = glyphs);
  23031. }
  23032. };
  23033. return Font;
  23034. })();
  23035. var ErrorFont = (function ErrorFontClosure() {
  23036. function ErrorFont(error) {
  23037. this.error = error;
  23038. this.loadedName = 'g_font_error';
  23039. this.loading = false;
  23040. }
  23041. ErrorFont.prototype = {
  23042. charsToGlyphs: function ErrorFont_charsToGlyphs() {
  23043. return [];
  23044. },
  23045. exportData: function ErrorFont_exportData() {
  23046. return {error: this.error};
  23047. }
  23048. };
  23049. return ErrorFont;
  23050. })();
  23051. /**
  23052. * Shared logic for building a char code to glyph id mapping for Type1 and
  23053. * simple CFF fonts. See section 9.6.6.2 of the spec.
  23054. * @param {Object} properties Font properties object.
  23055. * @param {Object} builtInEncoding The encoding contained within the actual font
  23056. * data.
  23057. * @param {Array} Array of glyph names where the index is the glyph ID.
  23058. * @returns {Object} A char code to glyph ID map.
  23059. */
  23060. function type1FontGlyphMapping(properties, builtInEncoding, glyphNames) {
  23061. var charCodeToGlyphId = Object.create(null);
  23062. var glyphId, charCode, baseEncoding;
  23063. if (properties.baseEncodingName) {
  23064. // If a valid base encoding name was used, the mapping is initialized with
  23065. // that.
  23066. baseEncoding = Encodings[properties.baseEncodingName];
  23067. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  23068. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  23069. if (glyphId >= 0) {
  23070. charCodeToGlyphId[charCode] = glyphId;
  23071. } else {
  23072. charCodeToGlyphId[charCode] = 0; // notdef
  23073. }
  23074. }
  23075. } else if (!!(properties.flags & FontFlags.Symbolic)) {
  23076. // For a symbolic font the encoding should be the fonts built-in
  23077. // encoding.
  23078. for (charCode in builtInEncoding) {
  23079. charCodeToGlyphId[charCode] = builtInEncoding[charCode];
  23080. }
  23081. } else {
  23082. // For non-symbolic fonts that don't have a base encoding the standard
  23083. // encoding should be used.
  23084. baseEncoding = Encodings.StandardEncoding;
  23085. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  23086. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  23087. if (glyphId >= 0) {
  23088. charCodeToGlyphId[charCode] = glyphId;
  23089. } else {
  23090. charCodeToGlyphId[charCode] = 0; // notdef
  23091. }
  23092. }
  23093. }
  23094. // Lastly, merge in the differences.
  23095. var differences = properties.differences;
  23096. if (differences) {
  23097. for (charCode in differences) {
  23098. var glyphName = differences[charCode];
  23099. glyphId = glyphNames.indexOf(glyphName);
  23100. if (glyphId >= 0) {
  23101. charCodeToGlyphId[charCode] = glyphId;
  23102. } else {
  23103. charCodeToGlyphId[charCode] = 0; // notdef
  23104. }
  23105. }
  23106. }
  23107. return charCodeToGlyphId;
  23108. }
  23109. /*
  23110. * CharStrings are encoded following the the CharString Encoding sequence
  23111. * describe in Chapter 6 of the "Adobe Type1 Font Format" specification.
  23112. * The value in a byte indicates a command, a number, or subsequent bytes
  23113. * that are to be interpreted in a special way.
  23114. *
  23115. * CharString Number Encoding:
  23116. * A CharString byte containing the values from 32 through 255 inclusive
  23117. * indicate an integer. These values are decoded in four ranges.
  23118. *
  23119. * 1. A CharString byte containing a value, v, between 32 and 246 inclusive,
  23120. * indicate the integer v - 139. Thus, the integer values from -107 through
  23121. * 107 inclusive may be encoded in single byte.
  23122. *
  23123. * 2. A CharString byte containing a value, v, between 247 and 250 inclusive,
  23124. * indicates an integer involving the next byte, w, according to the formula:
  23125. * [(v - 247) x 256] + w + 108
  23126. *
  23127. * 3. A CharString byte containing a value, v, between 251 and 254 inclusive,
  23128. * indicates an integer involving the next byte, w, according to the formula:
  23129. * -[(v - 251) * 256] - w - 108
  23130. *
  23131. * 4. A CharString containing the value 255 indicates that the next 4 bytes
  23132. * are a two complement signed integer. The first of these bytes contains the
  23133. * highest order bits, the second byte contains the next higher order bits
  23134. * and the fourth byte contain the lowest order bits.
  23135. *
  23136. *
  23137. * CharString Command Encoding:
  23138. * CharStrings commands are encoded in 1 or 2 bytes.
  23139. *
  23140. * Single byte commands are encoded in 1 byte that contains a value between
  23141. * 0 and 31 inclusive.
  23142. * If a command byte contains the value 12, then the value in the next byte
  23143. * indicates a command. This "escape" mechanism allows many extra commands
  23144. * to be encoded and this encoding technique helps to minimize the length of
  23145. * the charStrings.
  23146. */
  23147. var Type1CharString = (function Type1CharStringClosure() {
  23148. var COMMAND_MAP = {
  23149. 'hstem': [1],
  23150. 'vstem': [3],
  23151. 'vmoveto': [4],
  23152. 'rlineto': [5],
  23153. 'hlineto': [6],
  23154. 'vlineto': [7],
  23155. 'rrcurveto': [8],
  23156. 'callsubr': [10],
  23157. 'flex': [12, 35],
  23158. 'drop' : [12, 18],
  23159. 'endchar': [14],
  23160. 'rmoveto': [21],
  23161. 'hmoveto': [22],
  23162. 'vhcurveto': [30],
  23163. 'hvcurveto': [31]
  23164. };
  23165. function Type1CharString() {
  23166. this.width = 0;
  23167. this.lsb = 0;
  23168. this.flexing = false;
  23169. this.output = [];
  23170. this.stack = [];
  23171. }
  23172. Type1CharString.prototype = {
  23173. convert: function Type1CharString_convert(encoded, subrs) {
  23174. var count = encoded.length;
  23175. var error = false;
  23176. var wx, sbx, subrNumber;
  23177. for (var i = 0; i < count; i++) {
  23178. var value = encoded[i];
  23179. if (value < 32) {
  23180. if (value === 12) {
  23181. value = (value << 8) + encoded[++i];
  23182. }
  23183. switch (value) {
  23184. case 1: // hstem
  23185. if (!HINTING_ENABLED) {
  23186. this.stack = [];
  23187. break;
  23188. }
  23189. error = this.executeCommand(2, COMMAND_MAP.hstem);
  23190. break;
  23191. case 3: // vstem
  23192. if (!HINTING_ENABLED) {
  23193. this.stack = [];
  23194. break;
  23195. }
  23196. error = this.executeCommand(2, COMMAND_MAP.vstem);
  23197. break;
  23198. case 4: // vmoveto
  23199. if (this.flexing) {
  23200. if (this.stack.length < 1) {
  23201. error = true;
  23202. break;
  23203. }
  23204. // Add the dx for flex and but also swap the values so they are
  23205. // the right order.
  23206. var dy = this.stack.pop();
  23207. this.stack.push(0, dy);
  23208. break;
  23209. }
  23210. error = this.executeCommand(1, COMMAND_MAP.vmoveto);
  23211. break;
  23212. case 5: // rlineto
  23213. error = this.executeCommand(2, COMMAND_MAP.rlineto);
  23214. break;
  23215. case 6: // hlineto
  23216. error = this.executeCommand(1, COMMAND_MAP.hlineto);
  23217. break;
  23218. case 7: // vlineto
  23219. error = this.executeCommand(1, COMMAND_MAP.vlineto);
  23220. break;
  23221. case 8: // rrcurveto
  23222. error = this.executeCommand(6, COMMAND_MAP.rrcurveto);
  23223. break;
  23224. case 9: // closepath
  23225. // closepath is a Type1 command that does not take argument and is
  23226. // useless in Type2 and it can simply be ignored.
  23227. this.stack = [];
  23228. break;
  23229. case 10: // callsubr
  23230. if (this.stack.length < 1) {
  23231. error = true;
  23232. break;
  23233. }
  23234. subrNumber = this.stack.pop();
  23235. error = this.convert(subrs[subrNumber], subrs);
  23236. break;
  23237. case 11: // return
  23238. return error;
  23239. case 13: // hsbw
  23240. if (this.stack.length < 2) {
  23241. error = true;
  23242. break;
  23243. }
  23244. // To convert to type2 we have to move the width value to the
  23245. // first part of the charstring and then use hmoveto with lsb.
  23246. wx = this.stack.pop();
  23247. sbx = this.stack.pop();
  23248. this.lsb = sbx;
  23249. this.width = wx;
  23250. this.stack.push(wx, sbx);
  23251. error = this.executeCommand(2, COMMAND_MAP.hmoveto);
  23252. break;
  23253. case 14: // endchar
  23254. this.output.push(COMMAND_MAP.endchar[0]);
  23255. break;
  23256. case 21: // rmoveto
  23257. if (this.flexing) {
  23258. break;
  23259. }
  23260. error = this.executeCommand(2, COMMAND_MAP.rmoveto);
  23261. break;
  23262. case 22: // hmoveto
  23263. if (this.flexing) {
  23264. // Add the dy for flex.
  23265. this.stack.push(0);
  23266. break;
  23267. }
  23268. error = this.executeCommand(1, COMMAND_MAP.hmoveto);
  23269. break;
  23270. case 30: // vhcurveto
  23271. error = this.executeCommand(4, COMMAND_MAP.vhcurveto);
  23272. break;
  23273. case 31: // hvcurveto
  23274. error = this.executeCommand(4, COMMAND_MAP.hvcurveto);
  23275. break;
  23276. case (12 << 8) + 0: // dotsection
  23277. // dotsection is a Type1 command to specify some hinting feature
  23278. // for dots that do not take a parameter and it can safely be
  23279. // ignored for Type2.
  23280. this.stack = [];
  23281. break;
  23282. case (12 << 8) + 1: // vstem3
  23283. if (!HINTING_ENABLED) {
  23284. this.stack = [];
  23285. break;
  23286. }
  23287. // [vh]stem3 are Type1 only and Type2 supports [vh]stem with
  23288. // multiple parameters, so instead of returning [vh]stem3 take a
  23289. // shortcut and return [vhstem] instead.
  23290. error = this.executeCommand(2, COMMAND_MAP.vstem);
  23291. break;
  23292. case (12 << 8) + 2: // hstem3
  23293. if (!HINTING_ENABLED) {
  23294. this.stack = [];
  23295. break;
  23296. }
  23297. // See vstem3.
  23298. error = this.executeCommand(2, COMMAND_MAP.hstem);
  23299. break;
  23300. case (12 << 8) + 6: // seac
  23301. // seac is like type 2's special endchar but it doesn't use the
  23302. // first argument asb, so remove it.
  23303. if (SEAC_ANALYSIS_ENABLED) {
  23304. this.seac = this.stack.splice(-4, 4);
  23305. error = this.executeCommand(0, COMMAND_MAP.endchar);
  23306. } else {
  23307. error = this.executeCommand(4, COMMAND_MAP.endchar);
  23308. }
  23309. break;
  23310. case (12 << 8) + 7: // sbw
  23311. if (this.stack.length < 4) {
  23312. error = true;
  23313. break;
  23314. }
  23315. // To convert to type2 we have to move the width value to the
  23316. // first part of the charstring and then use rmoveto with
  23317. // (dx, dy). The height argument will not be used for vmtx and
  23318. // vhea tables reconstruction -- ignoring it.
  23319. var wy = this.stack.pop();
  23320. wx = this.stack.pop();
  23321. var sby = this.stack.pop();
  23322. sbx = this.stack.pop();
  23323. this.lsb = sbx;
  23324. this.width = wx;
  23325. this.stack.push(wx, sbx, sby);
  23326. error = this.executeCommand(3, COMMAND_MAP.rmoveto);
  23327. break;
  23328. case (12 << 8) + 12: // div
  23329. if (this.stack.length < 2) {
  23330. error = true;
  23331. break;
  23332. }
  23333. var num2 = this.stack.pop();
  23334. var num1 = this.stack.pop();
  23335. this.stack.push(num1 / num2);
  23336. break;
  23337. case (12 << 8) + 16: // callothersubr
  23338. if (this.stack.length < 2) {
  23339. error = true;
  23340. break;
  23341. }
  23342. subrNumber = this.stack.pop();
  23343. var numArgs = this.stack.pop();
  23344. if (subrNumber === 0 && numArgs === 3) {
  23345. var flexArgs = this.stack.splice(this.stack.length - 17, 17);
  23346. this.stack.push(
  23347. flexArgs[2] + flexArgs[0], // bcp1x + rpx
  23348. flexArgs[3] + flexArgs[1], // bcp1y + rpy
  23349. flexArgs[4], // bcp2x
  23350. flexArgs[5], // bcp2y
  23351. flexArgs[6], // p2x
  23352. flexArgs[7], // p2y
  23353. flexArgs[8], // bcp3x
  23354. flexArgs[9], // bcp3y
  23355. flexArgs[10], // bcp4x
  23356. flexArgs[11], // bcp4y
  23357. flexArgs[12], // p3x
  23358. flexArgs[13], // p3y
  23359. flexArgs[14] // flexDepth
  23360. // 15 = finalx unused by flex
  23361. // 16 = finaly unused by flex
  23362. );
  23363. error = this.executeCommand(13, COMMAND_MAP.flex, true);
  23364. this.flexing = false;
  23365. this.stack.push(flexArgs[15], flexArgs[16]);
  23366. } else if (subrNumber === 1 && numArgs === 0) {
  23367. this.flexing = true;
  23368. }
  23369. break;
  23370. case (12 << 8) + 17: // pop
  23371. // Ignore this since it is only used with othersubr.
  23372. break;
  23373. case (12 << 8) + 33: // setcurrentpoint
  23374. // Ignore for now.
  23375. this.stack = [];
  23376. break;
  23377. default:
  23378. warn('Unknown type 1 charstring command of "' + value + '"');
  23379. break;
  23380. }
  23381. if (error) {
  23382. break;
  23383. }
  23384. continue;
  23385. } else if (value <= 246) {
  23386. value = value - 139;
  23387. } else if (value <= 250) {
  23388. value = ((value - 247) * 256) + encoded[++i] + 108;
  23389. } else if (value <= 254) {
  23390. value = -((value - 251) * 256) - encoded[++i] - 108;
  23391. } else {
  23392. value = (encoded[++i] & 0xff) << 24 | (encoded[++i] & 0xff) << 16 |
  23393. (encoded[++i] & 0xff) << 8 | (encoded[++i] & 0xff) << 0;
  23394. }
  23395. this.stack.push(value);
  23396. }
  23397. return error;
  23398. },
  23399. executeCommand: function(howManyArgs, command, keepStack) {
  23400. var stackLength = this.stack.length;
  23401. if (howManyArgs > stackLength) {
  23402. return true;
  23403. }
  23404. var start = stackLength - howManyArgs;
  23405. for (var i = start; i < stackLength; i++) {
  23406. var value = this.stack[i];
  23407. if (value === (value | 0)) { // int
  23408. this.output.push(28, (value >> 8) & 0xff, value & 0xff);
  23409. } else { // fixed point
  23410. value = (65536 * value) | 0;
  23411. this.output.push(255,
  23412. (value >> 24) & 0xFF,
  23413. (value >> 16) & 0xFF,
  23414. (value >> 8) & 0xFF,
  23415. value & 0xFF);
  23416. }
  23417. }
  23418. this.output.push.apply(this.output, command);
  23419. if (keepStack) {
  23420. this.stack.splice(start, howManyArgs);
  23421. } else {
  23422. this.stack.length = 0;
  23423. }
  23424. return false;
  23425. }
  23426. };
  23427. return Type1CharString;
  23428. })();
  23429. /*
  23430. * Type1Parser encapsulate the needed code for parsing a Type1 font
  23431. * program. Some of its logic depends on the Type2 charstrings
  23432. * structure.
  23433. * Note: this doesn't really parse the font since that would require evaluation
  23434. * of PostScript, but it is possible in most cases to extract what we need
  23435. * without a full parse.
  23436. */
  23437. var Type1Parser = (function Type1ParserClosure() {
  23438. /*
  23439. * Decrypt a Sequence of Ciphertext Bytes to Produce the Original Sequence
  23440. * of Plaintext Bytes. The function took a key as a parameter which can be
  23441. * for decrypting the eexec block of for decoding charStrings.
  23442. */
  23443. var EEXEC_ENCRYPT_KEY = 55665;
  23444. var CHAR_STRS_ENCRYPT_KEY = 4330;
  23445. function isHexDigit(code) {
  23446. return code >= 48 && code <= 57 || // '0'-'9'
  23447. code >= 65 && code <= 70 || // 'A'-'F'
  23448. code >= 97 && code <= 102; // 'a'-'f'
  23449. }
  23450. function decrypt(data, key, discardNumber) {
  23451. var r = key | 0, c1 = 52845, c2 = 22719;
  23452. var count = data.length;
  23453. var decrypted = new Uint8Array(count);
  23454. for (var i = 0; i < count; i++) {
  23455. var value = data[i];
  23456. decrypted[i] = value ^ (r >> 8);
  23457. r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
  23458. }
  23459. return Array.prototype.slice.call(decrypted, discardNumber);
  23460. }
  23461. function decryptAscii(data, key, discardNumber) {
  23462. var r = key | 0, c1 = 52845, c2 = 22719;
  23463. var count = data.length, maybeLength = count >>> 1;
  23464. var decrypted = new Uint8Array(maybeLength);
  23465. var i, j;
  23466. for (i = 0, j = 0; i < count; i++) {
  23467. var digit1 = data[i];
  23468. if (!isHexDigit(digit1)) {
  23469. continue;
  23470. }
  23471. i++;
  23472. var digit2;
  23473. while (i < count && !isHexDigit(digit2 = data[i])) {
  23474. i++;
  23475. }
  23476. if (i < count) {
  23477. var value = parseInt(String.fromCharCode(digit1, digit2), 16);
  23478. decrypted[j++] = value ^ (r >> 8);
  23479. r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
  23480. }
  23481. }
  23482. return Array.prototype.slice.call(decrypted, discardNumber, j);
  23483. }
  23484. function isSpecial(c) {
  23485. return c === 0x2F || // '/'
  23486. c === 0x5B || c === 0x5D || // '[', ']'
  23487. c === 0x7B || c === 0x7D || // '{', '}'
  23488. c === 0x28 || c === 0x29; // '(', ')'
  23489. }
  23490. function Type1Parser(stream, encrypted) {
  23491. if (encrypted) {
  23492. var data = stream.getBytes();
  23493. var isBinary = !(isHexDigit(data[0]) && isHexDigit(data[1]) &&
  23494. isHexDigit(data[2]) && isHexDigit(data[3]));
  23495. stream = new Stream(isBinary ? decrypt(data, EEXEC_ENCRYPT_KEY, 4) :
  23496. decryptAscii(data, EEXEC_ENCRYPT_KEY, 4));
  23497. }
  23498. this.stream = stream;
  23499. this.nextChar();
  23500. }
  23501. Type1Parser.prototype = {
  23502. readNumberArray: function Type1Parser_readNumberArray() {
  23503. this.getToken(); // read '[' or '{' (arrays can start with either)
  23504. var array = [];
  23505. while (true) {
  23506. var token = this.getToken();
  23507. if (token === null || token === ']' || token === '}') {
  23508. break;
  23509. }
  23510. array.push(parseFloat(token || 0));
  23511. }
  23512. return array;
  23513. },
  23514. readNumber: function Type1Parser_readNumber() {
  23515. var token = this.getToken();
  23516. return parseFloat(token || 0);
  23517. },
  23518. readInt: function Type1Parser_readInt() {
  23519. // Use '| 0' to prevent setting a double into length such as the double
  23520. // does not flow into the loop variable.
  23521. var token = this.getToken();
  23522. return parseInt(token || 0, 10) | 0;
  23523. },
  23524. readBoolean: function Type1Parser_readBoolean() {
  23525. var token = this.getToken();
  23526. // Use 1 and 0 since that's what type2 charstrings use.
  23527. return token === 'true' ? 1 : 0;
  23528. },
  23529. nextChar : function Type1_nextChar() {
  23530. return (this.currentChar = this.stream.getByte());
  23531. },
  23532. getToken: function Type1Parser_getToken() {
  23533. // Eat whitespace and comments.
  23534. var comment = false;
  23535. var ch = this.currentChar;
  23536. while (true) {
  23537. if (ch === -1) {
  23538. return null;
  23539. }
  23540. if (comment) {
  23541. if (ch === 0x0A || ch === 0x0D) {
  23542. comment = false;
  23543. }
  23544. } else if (ch === 0x25) { // '%'
  23545. comment = true;
  23546. } else if (!Lexer.isSpace(ch)) {
  23547. break;
  23548. }
  23549. ch = this.nextChar();
  23550. }
  23551. if (isSpecial(ch)) {
  23552. this.nextChar();
  23553. return String.fromCharCode(ch);
  23554. }
  23555. var token = '';
  23556. do {
  23557. token += String.fromCharCode(ch);
  23558. ch = this.nextChar();
  23559. } while (ch >= 0 && !Lexer.isSpace(ch) && !isSpecial(ch));
  23560. return token;
  23561. },
  23562. /*
  23563. * Returns an object containing a Subrs array and a CharStrings
  23564. * array extracted from and eexec encrypted block of data
  23565. */
  23566. extractFontProgram: function Type1Parser_extractFontProgram() {
  23567. var stream = this.stream;
  23568. var subrs = [], charstrings = [];
  23569. var program = {
  23570. subrs: [],
  23571. charstrings: [],
  23572. properties: {
  23573. 'privateData': {
  23574. 'lenIV': 4
  23575. }
  23576. }
  23577. };
  23578. var token, length, data, lenIV, encoded;
  23579. while ((token = this.getToken()) !== null) {
  23580. if (token !== '/') {
  23581. continue;
  23582. }
  23583. token = this.getToken();
  23584. switch (token) {
  23585. case 'CharStrings':
  23586. // The number immediately following CharStrings must be greater or
  23587. // equal to the number of CharStrings.
  23588. this.getToken();
  23589. this.getToken(); // read in 'dict'
  23590. this.getToken(); // read in 'dup'
  23591. this.getToken(); // read in 'begin'
  23592. while(true) {
  23593. token = this.getToken();
  23594. if (token === null || token === 'end') {
  23595. break;
  23596. }
  23597. if (token !== '/') {
  23598. continue;
  23599. }
  23600. var glyph = this.getToken();
  23601. length = this.readInt();
  23602. this.getToken(); // read in 'RD' or '-|'
  23603. data = stream.makeSubStream(stream.pos, length);
  23604. lenIV = program.properties.privateData['lenIV'];
  23605. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  23606. // Skip past the required space and binary data.
  23607. stream.skip(length);
  23608. this.nextChar();
  23609. token = this.getToken(); // read in 'ND' or '|-'
  23610. if (token === 'noaccess') {
  23611. this.getToken(); // read in 'def'
  23612. }
  23613. charstrings.push({
  23614. glyph: glyph,
  23615. encoded: encoded
  23616. });
  23617. }
  23618. break;
  23619. case 'Subrs':
  23620. var num = this.readInt();
  23621. this.getToken(); // read in 'array'
  23622. while ((token = this.getToken()) === 'dup') {
  23623. var index = this.readInt();
  23624. length = this.readInt();
  23625. this.getToken(); // read in 'RD' or '-|'
  23626. data = stream.makeSubStream(stream.pos, length);
  23627. lenIV = program.properties.privateData['lenIV'];
  23628. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  23629. // Skip past the required space and binary data.
  23630. stream.skip(length);
  23631. this.nextChar();
  23632. token = this.getToken(); // read in 'NP' or '|'
  23633. if (token === 'noaccess') {
  23634. this.getToken(); // read in 'put'
  23635. }
  23636. subrs[index] = encoded;
  23637. }
  23638. break;
  23639. case 'BlueValues':
  23640. case 'OtherBlues':
  23641. case 'FamilyBlues':
  23642. case 'FamilyOtherBlues':
  23643. var blueArray = this.readNumberArray();
  23644. // *Blue* values may contain invalid data: disables reading of
  23645. // those values when hinting is disabled.
  23646. if (blueArray.length > 0 && (blueArray.length % 2) === 0 &&
  23647. HINTING_ENABLED) {
  23648. program.properties.privateData[token] = blueArray;
  23649. }
  23650. break;
  23651. case 'StemSnapH':
  23652. case 'StemSnapV':
  23653. program.properties.privateData[token] = this.readNumberArray();
  23654. break;
  23655. case 'StdHW':
  23656. case 'StdVW':
  23657. program.properties.privateData[token] =
  23658. this.readNumberArray()[0];
  23659. break;
  23660. case 'BlueShift':
  23661. case 'lenIV':
  23662. case 'BlueFuzz':
  23663. case 'BlueScale':
  23664. case 'LanguageGroup':
  23665. case 'ExpansionFactor':
  23666. program.properties.privateData[token] = this.readNumber();
  23667. break;
  23668. case 'ForceBold':
  23669. program.properties.privateData[token] = this.readBoolean();
  23670. break;
  23671. }
  23672. }
  23673. for (var i = 0; i < charstrings.length; i++) {
  23674. glyph = charstrings[i].glyph;
  23675. encoded = charstrings[i].encoded;
  23676. var charString = new Type1CharString();
  23677. var error = charString.convert(encoded, subrs);
  23678. var output = charString.output;
  23679. if (error) {
  23680. // It seems when FreeType encounters an error while evaluating a glyph
  23681. // that it completely ignores the glyph so we'll mimic that behaviour
  23682. // here and put an endchar to make the validator happy.
  23683. output = [14];
  23684. }
  23685. program.charstrings.push({
  23686. glyphName: glyph,
  23687. charstring: output,
  23688. width: charString.width,
  23689. lsb: charString.lsb,
  23690. seac: charString.seac
  23691. });
  23692. }
  23693. return program;
  23694. },
  23695. extractFontHeader: function Type1Parser_extractFontHeader(properties) {
  23696. var token;
  23697. while ((token = this.getToken()) !== null) {
  23698. if (token !== '/') {
  23699. continue;
  23700. }
  23701. token = this.getToken();
  23702. switch (token) {
  23703. case 'FontMatrix':
  23704. var matrix = this.readNumberArray();
  23705. properties.fontMatrix = matrix;
  23706. break;
  23707. case 'Encoding':
  23708. var encodingArg = this.getToken();
  23709. var encoding;
  23710. if (!/^\d+$/.test(encodingArg)) {
  23711. // encoding name is specified
  23712. encoding = Encodings[encodingArg];
  23713. } else {
  23714. encoding = [];
  23715. var size = parseInt(encodingArg, 10) | 0;
  23716. this.getToken(); // read in 'array'
  23717. for (var j = 0; j < size; j++) {
  23718. token = this.getToken();
  23719. // skipping till first dup or def (e.g. ignoring for statement)
  23720. while (token !== 'dup' && token !== 'def') {
  23721. token = this.getToken();
  23722. if (token === null) {
  23723. return; // invalid header
  23724. }
  23725. }
  23726. if (token === 'def') {
  23727. break; // read all array data
  23728. }
  23729. var index = this.readInt();
  23730. this.getToken(); // read in '/'
  23731. var glyph = this.getToken();
  23732. encoding[index] = glyph;
  23733. this.getToken(); // read the in 'put'
  23734. }
  23735. }
  23736. properties.builtInEncoding = encoding;
  23737. break;
  23738. case 'FontBBox':
  23739. var fontBBox = this.readNumberArray();
  23740. // adjusting ascent/descent
  23741. properties.ascent = fontBBox[3];
  23742. properties.descent = fontBBox[1];
  23743. properties.ascentScaled = true;
  23744. break;
  23745. }
  23746. }
  23747. }
  23748. };
  23749. return Type1Parser;
  23750. })();
  23751. /**
  23752. * The CFF class takes a Type1 file and wrap it into a
  23753. * 'Compact Font Format' which itself embed Type2 charstrings.
  23754. */
  23755. var CFFStandardStrings = [
  23756. '.notdef', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  23757. 'ampersand', 'quoteright', 'parenleft', 'parenright', 'asterisk', 'plus',
  23758. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three', 'four',
  23759. 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon', 'less',
  23760. 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
  23761. 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
  23762. 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright', 'asciicircum',
  23763. 'underscore', 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
  23764. 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y',
  23765. 'z', 'braceleft', 'bar', 'braceright', 'asciitilde', 'exclamdown', 'cent',
  23766. 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  23767. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  23768. 'guilsinglright', 'fi', 'fl', 'endash', 'dagger', 'daggerdbl',
  23769. 'periodcentered', 'paragraph', 'bullet', 'quotesinglbase', 'quotedblbase',
  23770. 'quotedblright', 'guillemotright', 'ellipsis', 'perthousand', 'questiondown',
  23771. 'grave', 'acute', 'circumflex', 'tilde', 'macron', 'breve', 'dotaccent',
  23772. 'dieresis', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron', 'emdash',
  23773. 'AE', 'ordfeminine', 'Lslash', 'Oslash', 'OE', 'ordmasculine', 'ae',
  23774. 'dotlessi', 'lslash', 'oslash', 'oe', 'germandbls', 'onesuperior',
  23775. 'logicalnot', 'mu', 'trademark', 'Eth', 'onehalf', 'plusminus', 'Thorn',
  23776. 'onequarter', 'divide', 'brokenbar', 'degree', 'thorn', 'threequarters',
  23777. 'twosuperior', 'registered', 'minus', 'eth', 'multiply', 'threesuperior',
  23778. 'copyright', 'Aacute', 'Acircumflex', 'Adieresis', 'Agrave', 'Aring',
  23779. 'Atilde', 'Ccedilla', 'Eacute', 'Ecircumflex', 'Edieresis', 'Egrave',
  23780. 'Iacute', 'Icircumflex', 'Idieresis', 'Igrave', 'Ntilde', 'Oacute',
  23781. 'Ocircumflex', 'Odieresis', 'Ograve', 'Otilde', 'Scaron', 'Uacute',
  23782. 'Ucircumflex', 'Udieresis', 'Ugrave', 'Yacute', 'Ydieresis', 'Zcaron',
  23783. 'aacute', 'acircumflex', 'adieresis', 'agrave', 'aring', 'atilde',
  23784. 'ccedilla', 'eacute', 'ecircumflex', 'edieresis', 'egrave', 'iacute',
  23785. 'icircumflex', 'idieresis', 'igrave', 'ntilde', 'oacute', 'ocircumflex',
  23786. 'odieresis', 'ograve', 'otilde', 'scaron', 'uacute', 'ucircumflex',
  23787. 'udieresis', 'ugrave', 'yacute', 'ydieresis', 'zcaron', 'exclamsmall',
  23788. 'Hungarumlautsmall', 'dollaroldstyle', 'dollarsuperior', 'ampersandsmall',
  23789. 'Acutesmall', 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  23790. 'onedotenleader', 'zerooldstyle', 'oneoldstyle', 'twooldstyle',
  23791. 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle', 'sixoldstyle',
  23792. 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle', 'commasuperior',
  23793. 'threequartersemdash', 'periodsuperior', 'questionsmall', 'asuperior',
  23794. 'bsuperior', 'centsuperior', 'dsuperior', 'esuperior', 'isuperior',
  23795. 'lsuperior', 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  23796. 'tsuperior', 'ff', 'ffi', 'ffl', 'parenleftinferior', 'parenrightinferior',
  23797. 'Circumflexsmall', 'hyphensuperior', 'Gravesmall', 'Asmall', 'Bsmall',
  23798. 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall', 'Hsmall', 'Ismall',
  23799. 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall', 'Osmall', 'Psmall',
  23800. 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall', 'Vsmall', 'Wsmall',
  23801. 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary', 'onefitted', 'rupiah',
  23802. 'Tildesmall', 'exclamdownsmall', 'centoldstyle', 'Lslashsmall',
  23803. 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall', 'Brevesmall', 'Caronsmall',
  23804. 'Dotaccentsmall', 'Macronsmall', 'figuredash', 'hypheninferior',
  23805. 'Ogoneksmall', 'Ringsmall', 'Cedillasmall', 'questiondownsmall', 'oneeighth',
  23806. 'threeeighths', 'fiveeighths', 'seveneighths', 'onethird', 'twothirds',
  23807. 'zerosuperior', 'foursuperior', 'fivesuperior', 'sixsuperior',
  23808. 'sevensuperior', 'eightsuperior', 'ninesuperior', 'zeroinferior',
  23809. 'oneinferior', 'twoinferior', 'threeinferior', 'fourinferior',
  23810. 'fiveinferior', 'sixinferior', 'seveninferior', 'eightinferior',
  23811. 'nineinferior', 'centinferior', 'dollarinferior', 'periodinferior',
  23812. 'commainferior', 'Agravesmall', 'Aacutesmall', 'Acircumflexsmall',
  23813. 'Atildesmall', 'Adieresissmall', 'Aringsmall', 'AEsmall', 'Ccedillasmall',
  23814. 'Egravesmall', 'Eacutesmall', 'Ecircumflexsmall', 'Edieresissmall',
  23815. 'Igravesmall', 'Iacutesmall', 'Icircumflexsmall', 'Idieresissmall',
  23816. 'Ethsmall', 'Ntildesmall', 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall',
  23817. 'Otildesmall', 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall',
  23818. 'Uacutesmall', 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall',
  23819. 'Thornsmall', 'Ydieresissmall', '001.000', '001.001', '001.002', '001.003',
  23820. 'Black', 'Bold', 'Book', 'Light', 'Medium', 'Regular', 'Roman', 'Semibold'
  23821. ];
  23822. // Type1Font is also a CIDFontType0.
  23823. var Type1Font = function Type1Font(name, file, properties) {
  23824. // Some bad generators embed pfb file as is, we have to strip 6-byte headers.
  23825. // Also, length1 and length2 might be off by 6 bytes as well.
  23826. // http://www.math.ubc.ca/~cass/piscript/type1.pdf
  23827. var PFB_HEADER_SIZE = 6;
  23828. var headerBlockLength = properties.length1;
  23829. var eexecBlockLength = properties.length2;
  23830. var pfbHeader = file.peekBytes(PFB_HEADER_SIZE);
  23831. var pfbHeaderPresent = pfbHeader[0] === 0x80 && pfbHeader[1] === 0x01;
  23832. if (pfbHeaderPresent) {
  23833. file.skip(PFB_HEADER_SIZE);
  23834. headerBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
  23835. (pfbHeader[3] << 8) | pfbHeader[2];
  23836. }
  23837. // Get the data block containing glyphs and subrs informations
  23838. var headerBlock = new Stream(file.getBytes(headerBlockLength));
  23839. var headerBlockParser = new Type1Parser(headerBlock);
  23840. headerBlockParser.extractFontHeader(properties);
  23841. if (pfbHeaderPresent) {
  23842. pfbHeader = file.getBytes(PFB_HEADER_SIZE);
  23843. eexecBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
  23844. (pfbHeader[3] << 8) | pfbHeader[2];
  23845. }
  23846. // Decrypt the data blocks and retrieve it's content
  23847. var eexecBlock = new Stream(file.getBytes(eexecBlockLength));
  23848. var eexecBlockParser = new Type1Parser(eexecBlock, true);
  23849. var data = eexecBlockParser.extractFontProgram();
  23850. for (var info in data.properties) {
  23851. properties[info] = data.properties[info];
  23852. }
  23853. var charstrings = data.charstrings;
  23854. var type2Charstrings = this.getType2Charstrings(charstrings);
  23855. var subrs = this.getType2Subrs(data.subrs);
  23856. this.charstrings = charstrings;
  23857. this.data = this.wrap(name, type2Charstrings, this.charstrings,
  23858. subrs, properties);
  23859. this.seacs = this.getSeacs(data.charstrings);
  23860. };
  23861. Type1Font.prototype = {
  23862. get numGlyphs() {
  23863. return this.charstrings.length + 1;
  23864. },
  23865. getCharset: function Type1Font_getCharset() {
  23866. var charset = ['.notdef'];
  23867. var charstrings = this.charstrings;
  23868. for (var glyphId = 0; glyphId < charstrings.length; glyphId++) {
  23869. charset.push(charstrings[glyphId].glyphName);
  23870. }
  23871. return charset;
  23872. },
  23873. getGlyphMapping: function Type1Font_getGlyphMapping(properties) {
  23874. var charstrings = this.charstrings;
  23875. var glyphNames = ['.notdef'], glyphId;
  23876. for (glyphId = 0; glyphId < charstrings.length; glyphId++) {
  23877. glyphNames.push(charstrings[glyphId].glyphName);
  23878. }
  23879. var encoding = properties.builtInEncoding;
  23880. if (encoding) {
  23881. var builtInEncoding = {};
  23882. for (var charCode in encoding) {
  23883. glyphId = glyphNames.indexOf(encoding[charCode]);
  23884. if (glyphId >= 0) {
  23885. builtInEncoding[charCode] = glyphId;
  23886. }
  23887. }
  23888. }
  23889. return type1FontGlyphMapping(properties, builtInEncoding, glyphNames);
  23890. },
  23891. getSeacs: function Type1Font_getSeacs(charstrings) {
  23892. var i, ii;
  23893. var seacMap = [];
  23894. for (i = 0, ii = charstrings.length; i < ii; i++) {
  23895. var charstring = charstrings[i];
  23896. if (charstring.seac) {
  23897. // Offset by 1 for .notdef
  23898. seacMap[i + 1] = charstring.seac;
  23899. }
  23900. }
  23901. return seacMap;
  23902. },
  23903. getType2Charstrings: function Type1Font_getType2Charstrings(
  23904. type1Charstrings) {
  23905. var type2Charstrings = [];
  23906. for (var i = 0, ii = type1Charstrings.length; i < ii; i++) {
  23907. type2Charstrings.push(type1Charstrings[i].charstring);
  23908. }
  23909. return type2Charstrings;
  23910. },
  23911. getType2Subrs: function Type1Font_getType2Subrs(type1Subrs) {
  23912. var bias = 0;
  23913. var count = type1Subrs.length;
  23914. if (count < 1133) {
  23915. bias = 107;
  23916. } else if (count < 33769) {
  23917. bias = 1131;
  23918. } else {
  23919. bias = 32768;
  23920. }
  23921. // Add a bunch of empty subrs to deal with the Type2 bias
  23922. var type2Subrs = [];
  23923. var i;
  23924. for (i = 0; i < bias; i++) {
  23925. type2Subrs.push([0x0B]);
  23926. }
  23927. for (i = 0; i < count; i++) {
  23928. type2Subrs.push(type1Subrs[i]);
  23929. }
  23930. return type2Subrs;
  23931. },
  23932. wrap: function Type1Font_wrap(name, glyphs, charstrings, subrs, properties) {
  23933. var cff = new CFF();
  23934. cff.header = new CFFHeader(1, 0, 4, 4);
  23935. cff.names = [name];
  23936. var topDict = new CFFTopDict();
  23937. // CFF strings IDs 0...390 are predefined names, so refering
  23938. // to entries in our own String INDEX starts at SID 391.
  23939. topDict.setByName('version', 391);
  23940. topDict.setByName('Notice', 392);
  23941. topDict.setByName('FullName', 393);
  23942. topDict.setByName('FamilyName', 394);
  23943. topDict.setByName('Weight', 395);
  23944. topDict.setByName('Encoding', null); // placeholder
  23945. topDict.setByName('FontMatrix', properties.fontMatrix);
  23946. topDict.setByName('FontBBox', properties.bbox);
  23947. topDict.setByName('charset', null); // placeholder
  23948. topDict.setByName('CharStrings', null); // placeholder
  23949. topDict.setByName('Private', null); // placeholder
  23950. cff.topDict = topDict;
  23951. var strings = new CFFStrings();
  23952. strings.add('Version 0.11'); // Version
  23953. strings.add('See original notice'); // Notice
  23954. strings.add(name); // FullName
  23955. strings.add(name); // FamilyName
  23956. strings.add('Medium'); // Weight
  23957. cff.strings = strings;
  23958. cff.globalSubrIndex = new CFFIndex();
  23959. var count = glyphs.length;
  23960. var charsetArray = [0];
  23961. var i, ii;
  23962. for (i = 0; i < count; i++) {
  23963. var index = CFFStandardStrings.indexOf(charstrings[i].glyphName);
  23964. // TODO: Insert the string and correctly map it. Previously it was
  23965. // thought mapping names that aren't in the standard strings to .notdef
  23966. // was fine, however in issue818 when mapping them all to .notdef the
  23967. // adieresis glyph no longer worked.
  23968. if (index === -1) {
  23969. index = 0;
  23970. }
  23971. charsetArray.push((index >> 8) & 0xff, index & 0xff);
  23972. }
  23973. cff.charset = new CFFCharset(false, 0, [], charsetArray);
  23974. var charStringsIndex = new CFFIndex();
  23975. charStringsIndex.add([0x8B, 0x0E]); // .notdef
  23976. for (i = 0; i < count; i++) {
  23977. charStringsIndex.add(glyphs[i]);
  23978. }
  23979. cff.charStrings = charStringsIndex;
  23980. var privateDict = new CFFPrivateDict();
  23981. privateDict.setByName('Subrs', null); // placeholder
  23982. var fields = [
  23983. 'BlueValues',
  23984. 'OtherBlues',
  23985. 'FamilyBlues',
  23986. 'FamilyOtherBlues',
  23987. 'StemSnapH',
  23988. 'StemSnapV',
  23989. 'BlueShift',
  23990. 'BlueFuzz',
  23991. 'BlueScale',
  23992. 'LanguageGroup',
  23993. 'ExpansionFactor',
  23994. 'ForceBold',
  23995. 'StdHW',
  23996. 'StdVW'
  23997. ];
  23998. for (i = 0, ii = fields.length; i < ii; i++) {
  23999. var field = fields[i];
  24000. if (!properties.privateData.hasOwnProperty(field)) {
  24001. continue;
  24002. }
  24003. var value = properties.privateData[field];
  24004. if (isArray(value)) {
  24005. // All of the private dictionary array data in CFF must be stored as
  24006. // "delta-encoded" numbers.
  24007. for (var j = value.length - 1; j > 0; j--) {
  24008. value[j] -= value[j - 1]; // ... difference from previous value
  24009. }
  24010. }
  24011. privateDict.setByName(field, value);
  24012. }
  24013. cff.topDict.privateDict = privateDict;
  24014. var subrIndex = new CFFIndex();
  24015. for (i = 0, ii = subrs.length; i < ii; i++) {
  24016. subrIndex.add(subrs[i]);
  24017. }
  24018. privateDict.subrsIndex = subrIndex;
  24019. var compiler = new CFFCompiler(cff);
  24020. return compiler.compile();
  24021. }
  24022. };
  24023. var CFFFont = (function CFFFontClosure() {
  24024. function CFFFont(file, properties) {
  24025. this.properties = properties;
  24026. var parser = new CFFParser(file, properties);
  24027. this.cff = parser.parse();
  24028. var compiler = new CFFCompiler(this.cff);
  24029. this.seacs = this.cff.seacs;
  24030. try {
  24031. this.data = compiler.compile();
  24032. } catch (e) {
  24033. warn('Failed to compile font ' + properties.loadedName);
  24034. // There may have just been an issue with the compiler, set the data
  24035. // anyway and hope the font loaded.
  24036. this.data = file;
  24037. }
  24038. }
  24039. CFFFont.prototype = {
  24040. get numGlyphs() {
  24041. return this.cff.charStrings.count;
  24042. },
  24043. getCharset: function CFFFont_getCharset() {
  24044. return this.cff.charset.charset;
  24045. },
  24046. getGlyphMapping: function CFFFont_getGlyphMapping() {
  24047. var cff = this.cff;
  24048. var properties = this.properties;
  24049. var charsets = cff.charset.charset;
  24050. var charCodeToGlyphId;
  24051. var glyphId;
  24052. if (properties.composite) {
  24053. charCodeToGlyphId = Object.create(null);
  24054. if (cff.isCIDFont) {
  24055. // If the font is actually a CID font then we should use the charset
  24056. // to map CIDs to GIDs.
  24057. for (glyphId = 0; glyphId < charsets.length; glyphId++) {
  24058. var cid = charsets[glyphId];
  24059. var charCode = properties.cMap.charCodeOf(cid);
  24060. charCodeToGlyphId[charCode] = glyphId;
  24061. }
  24062. } else {
  24063. // If it is NOT actually a CID font then CIDs should be mapped
  24064. // directly to GIDs.
  24065. for (glyphId = 0; glyphId < cff.charStrings.count; glyphId++) {
  24066. charCodeToGlyphId[glyphId] = glyphId;
  24067. }
  24068. }
  24069. return charCodeToGlyphId;
  24070. }
  24071. var encoding = cff.encoding ? cff.encoding.encoding : null;
  24072. charCodeToGlyphId = type1FontGlyphMapping(properties, encoding, charsets);
  24073. return charCodeToGlyphId;
  24074. }
  24075. };
  24076. return CFFFont;
  24077. })();
  24078. var CFFParser = (function CFFParserClosure() {
  24079. var CharstringValidationData = [
  24080. null,
  24081. { id: 'hstem', min: 2, stackClearing: true, stem: true },
  24082. null,
  24083. { id: 'vstem', min: 2, stackClearing: true, stem: true },
  24084. { id: 'vmoveto', min: 1, stackClearing: true },
  24085. { id: 'rlineto', min: 2, resetStack: true },
  24086. { id: 'hlineto', min: 1, resetStack: true },
  24087. { id: 'vlineto', min: 1, resetStack: true },
  24088. { id: 'rrcurveto', min: 6, resetStack: true },
  24089. null,
  24090. { id: 'callsubr', min: 1, undefStack: true },
  24091. { id: 'return', min: 0, undefStack: true },
  24092. null, // 12
  24093. null,
  24094. { id: 'endchar', min: 0, stackClearing: true },
  24095. null,
  24096. null,
  24097. null,
  24098. { id: 'hstemhm', min: 2, stackClearing: true, stem: true },
  24099. { id: 'hintmask', min: 0, stackClearing: true },
  24100. { id: 'cntrmask', min: 0, stackClearing: true },
  24101. { id: 'rmoveto', min: 2, stackClearing: true },
  24102. { id: 'hmoveto', min: 1, stackClearing: true },
  24103. { id: 'vstemhm', min: 2, stackClearing: true, stem: true },
  24104. { id: 'rcurveline', min: 8, resetStack: true },
  24105. { id: 'rlinecurve', min: 8, resetStack: true },
  24106. { id: 'vvcurveto', min: 4, resetStack: true },
  24107. { id: 'hhcurveto', min: 4, resetStack: true },
  24108. null, // shortint
  24109. { id: 'callgsubr', min: 1, undefStack: true },
  24110. { id: 'vhcurveto', min: 4, resetStack: true },
  24111. { id: 'hvcurveto', min: 4, resetStack: true }
  24112. ];
  24113. var CharstringValidationData12 = [
  24114. null,
  24115. null,
  24116. null,
  24117. { id: 'and', min: 2, stackDelta: -1 },
  24118. { id: 'or', min: 2, stackDelta: -1 },
  24119. { id: 'not', min: 1, stackDelta: 0 },
  24120. null,
  24121. null,
  24122. null,
  24123. { id: 'abs', min: 1, stackDelta: 0 },
  24124. { id: 'add', min: 2, stackDelta: -1,
  24125. stackFn: function stack_div(stack, index) {
  24126. stack[index - 2] = stack[index - 2] + stack[index - 1];
  24127. }
  24128. },
  24129. { id: 'sub', min: 2, stackDelta: -1,
  24130. stackFn: function stack_div(stack, index) {
  24131. stack[index - 2] = stack[index - 2] - stack[index - 1];
  24132. }
  24133. },
  24134. { id: 'div', min: 2, stackDelta: -1,
  24135. stackFn: function stack_div(stack, index) {
  24136. stack[index - 2] = stack[index - 2] / stack[index - 1];
  24137. }
  24138. },
  24139. null,
  24140. { id: 'neg', min: 1, stackDelta: 0,
  24141. stackFn: function stack_div(stack, index) {
  24142. stack[index - 1] = -stack[index - 1];
  24143. }
  24144. },
  24145. { id: 'eq', min: 2, stackDelta: -1 },
  24146. null,
  24147. null,
  24148. { id: 'drop', min: 1, stackDelta: -1 },
  24149. null,
  24150. { id: 'put', min: 2, stackDelta: -2 },
  24151. { id: 'get', min: 1, stackDelta: 0 },
  24152. { id: 'ifelse', min: 4, stackDelta: -3 },
  24153. { id: 'random', min: 0, stackDelta: 1 },
  24154. { id: 'mul', min: 2, stackDelta: -1,
  24155. stackFn: function stack_div(stack, index) {
  24156. stack[index - 2] = stack[index - 2] * stack[index - 1];
  24157. }
  24158. },
  24159. null,
  24160. { id: 'sqrt', min: 1, stackDelta: 0 },
  24161. { id: 'dup', min: 1, stackDelta: 1 },
  24162. { id: 'exch', min: 2, stackDelta: 0 },
  24163. { id: 'index', min: 2, stackDelta: 0 },
  24164. { id: 'roll', min: 3, stackDelta: -2 },
  24165. null,
  24166. null,
  24167. null,
  24168. { id: 'hflex', min: 7, resetStack: true },
  24169. { id: 'flex', min: 13, resetStack: true },
  24170. { id: 'hflex1', min: 9, resetStack: true },
  24171. { id: 'flex1', min: 11, resetStack: true }
  24172. ];
  24173. function CFFParser(file, properties) {
  24174. this.bytes = file.getBytes();
  24175. this.properties = properties;
  24176. }
  24177. CFFParser.prototype = {
  24178. parse: function CFFParser_parse() {
  24179. var properties = this.properties;
  24180. var cff = new CFF();
  24181. this.cff = cff;
  24182. // The first five sections must be in order, all the others are reached
  24183. // via offsets contained in one of the below.
  24184. var header = this.parseHeader();
  24185. var nameIndex = this.parseIndex(header.endPos);
  24186. var topDictIndex = this.parseIndex(nameIndex.endPos);
  24187. var stringIndex = this.parseIndex(topDictIndex.endPos);
  24188. var globalSubrIndex = this.parseIndex(stringIndex.endPos);
  24189. var topDictParsed = this.parseDict(topDictIndex.obj.get(0));
  24190. var topDict = this.createDict(CFFTopDict, topDictParsed, cff.strings);
  24191. cff.header = header.obj;
  24192. cff.names = this.parseNameIndex(nameIndex.obj);
  24193. cff.strings = this.parseStringIndex(stringIndex.obj);
  24194. cff.topDict = topDict;
  24195. cff.globalSubrIndex = globalSubrIndex.obj;
  24196. this.parsePrivateDict(cff.topDict);
  24197. cff.isCIDFont = topDict.hasName('ROS');
  24198. var charStringOffset = topDict.getByName('CharStrings');
  24199. var charStringsAndSeacs = this.parseCharStrings(charStringOffset);
  24200. cff.charStrings = charStringsAndSeacs.charStrings;
  24201. cff.seacs = charStringsAndSeacs.seacs;
  24202. cff.widths = charStringsAndSeacs.widths;
  24203. var fontMatrix = topDict.getByName('FontMatrix');
  24204. if (fontMatrix) {
  24205. properties.fontMatrix = fontMatrix;
  24206. }
  24207. var fontBBox = topDict.getByName('FontBBox');
  24208. if (fontBBox) {
  24209. // adjusting ascent/descent
  24210. properties.ascent = fontBBox[3];
  24211. properties.descent = fontBBox[1];
  24212. properties.ascentScaled = true;
  24213. }
  24214. var charset, encoding;
  24215. if (cff.isCIDFont) {
  24216. var fdArrayIndex = this.parseIndex(topDict.getByName('FDArray')).obj;
  24217. for (var i = 0, ii = fdArrayIndex.count; i < ii; ++i) {
  24218. var dictRaw = fdArrayIndex.get(i);
  24219. var fontDict = this.createDict(CFFTopDict, this.parseDict(dictRaw),
  24220. cff.strings);
  24221. this.parsePrivateDict(fontDict);
  24222. cff.fdArray.push(fontDict);
  24223. }
  24224. // cid fonts don't have an encoding
  24225. encoding = null;
  24226. charset = this.parseCharsets(topDict.getByName('charset'),
  24227. cff.charStrings.count, cff.strings, true);
  24228. cff.fdSelect = this.parseFDSelect(topDict.getByName('FDSelect'),
  24229. cff.charStrings.count);
  24230. } else {
  24231. charset = this.parseCharsets(topDict.getByName('charset'),
  24232. cff.charStrings.count, cff.strings, false);
  24233. encoding = this.parseEncoding(topDict.getByName('Encoding'),
  24234. properties,
  24235. cff.strings, charset.charset);
  24236. }
  24237. cff.charset = charset;
  24238. cff.encoding = encoding;
  24239. return cff;
  24240. },
  24241. parseHeader: function CFFParser_parseHeader() {
  24242. var bytes = this.bytes;
  24243. var bytesLength = bytes.length;
  24244. var offset = 0;
  24245. // Prevent an infinite loop, by checking that the offset is within the
  24246. // bounds of the bytes array. Necessary in empty, or invalid, font files.
  24247. while (offset < bytesLength && bytes[offset] !== 1) {
  24248. ++offset;
  24249. }
  24250. if (offset >= bytesLength) {
  24251. error('Invalid CFF header');
  24252. } else if (offset !== 0) {
  24253. info('cff data is shifted');
  24254. bytes = bytes.subarray(offset);
  24255. this.bytes = bytes;
  24256. }
  24257. var major = bytes[0];
  24258. var minor = bytes[1];
  24259. var hdrSize = bytes[2];
  24260. var offSize = bytes[3];
  24261. var header = new CFFHeader(major, minor, hdrSize, offSize);
  24262. return { obj: header, endPos: hdrSize };
  24263. },
  24264. parseDict: function CFFParser_parseDict(dict) {
  24265. var pos = 0;
  24266. function parseOperand() {
  24267. var value = dict[pos++];
  24268. if (value === 30) {
  24269. return parseFloatOperand(pos);
  24270. } else if (value === 28) {
  24271. value = dict[pos++];
  24272. value = ((value << 24) | (dict[pos++] << 16)) >> 16;
  24273. return value;
  24274. } else if (value === 29) {
  24275. value = dict[pos++];
  24276. value = (value << 8) | dict[pos++];
  24277. value = (value << 8) | dict[pos++];
  24278. value = (value << 8) | dict[pos++];
  24279. return value;
  24280. } else if (value >= 32 && value <= 246) {
  24281. return value - 139;
  24282. } else if (value >= 247 && value <= 250) {
  24283. return ((value - 247) * 256) + dict[pos++] + 108;
  24284. } else if (value >= 251 && value <= 254) {
  24285. return -((value - 251) * 256) - dict[pos++] - 108;
  24286. } else {
  24287. error('255 is not a valid DICT command');
  24288. }
  24289. return -1;
  24290. }
  24291. function parseFloatOperand() {
  24292. var str = '';
  24293. var eof = 15;
  24294. var lookup = ['0', '1', '2', '3', '4', '5', '6', '7', '8',
  24295. '9', '.', 'E', 'E-', null, '-'];
  24296. var length = dict.length;
  24297. while (pos < length) {
  24298. var b = dict[pos++];
  24299. var b1 = b >> 4;
  24300. var b2 = b & 15;
  24301. if (b1 === eof) {
  24302. break;
  24303. }
  24304. str += lookup[b1];
  24305. if (b2 === eof) {
  24306. break;
  24307. }
  24308. str += lookup[b2];
  24309. }
  24310. return parseFloat(str);
  24311. }
  24312. var operands = [];
  24313. var entries = [];
  24314. pos = 0;
  24315. var end = dict.length;
  24316. while (pos < end) {
  24317. var b = dict[pos];
  24318. if (b <= 21) {
  24319. if (b === 12) {
  24320. b = (b << 8) | dict[++pos];
  24321. }
  24322. entries.push([b, operands]);
  24323. operands = [];
  24324. ++pos;
  24325. } else {
  24326. operands.push(parseOperand());
  24327. }
  24328. }
  24329. return entries;
  24330. },
  24331. parseIndex: function CFFParser_parseIndex(pos) {
  24332. var cffIndex = new CFFIndex();
  24333. var bytes = this.bytes;
  24334. var count = (bytes[pos++] << 8) | bytes[pos++];
  24335. var offsets = [];
  24336. var end = pos;
  24337. var i, ii;
  24338. if (count !== 0) {
  24339. var offsetSize = bytes[pos++];
  24340. // add 1 for offset to determine size of last object
  24341. var startPos = pos + ((count + 1) * offsetSize) - 1;
  24342. for (i = 0, ii = count + 1; i < ii; ++i) {
  24343. var offset = 0;
  24344. for (var j = 0; j < offsetSize; ++j) {
  24345. offset <<= 8;
  24346. offset += bytes[pos++];
  24347. }
  24348. offsets.push(startPos + offset);
  24349. }
  24350. end = offsets[count];
  24351. }
  24352. for (i = 0, ii = offsets.length - 1; i < ii; ++i) {
  24353. var offsetStart = offsets[i];
  24354. var offsetEnd = offsets[i + 1];
  24355. cffIndex.add(bytes.subarray(offsetStart, offsetEnd));
  24356. }
  24357. return {obj: cffIndex, endPos: end};
  24358. },
  24359. parseNameIndex: function CFFParser_parseNameIndex(index) {
  24360. var names = [];
  24361. for (var i = 0, ii = index.count; i < ii; ++i) {
  24362. var name = index.get(i);
  24363. // OTS doesn't allow names to be over 127 characters.
  24364. var length = Math.min(name.length, 127);
  24365. var data = [];
  24366. // OTS also only permits certain characters in the name.
  24367. for (var j = 0; j < length; ++j) {
  24368. var c = name[j];
  24369. if (j === 0 && c === 0) {
  24370. data[j] = c;
  24371. continue;
  24372. }
  24373. if ((c < 33 || c > 126) || c === 91 /* [ */ || c === 93 /* ] */ ||
  24374. c === 40 /* ( */ || c === 41 /* ) */ || c === 123 /* { */ ||
  24375. c === 125 /* } */ || c === 60 /* < */ || c === 62 /* > */ ||
  24376. c === 47 /* / */ || c === 37 /* % */ || c === 35 /* # */) {
  24377. data[j] = 95;
  24378. continue;
  24379. }
  24380. data[j] = c;
  24381. }
  24382. names.push(bytesToString(data));
  24383. }
  24384. return names;
  24385. },
  24386. parseStringIndex: function CFFParser_parseStringIndex(index) {
  24387. var strings = new CFFStrings();
  24388. for (var i = 0, ii = index.count; i < ii; ++i) {
  24389. var data = index.get(i);
  24390. strings.add(bytesToString(data));
  24391. }
  24392. return strings;
  24393. },
  24394. createDict: function CFFParser_createDict(Type, dict, strings) {
  24395. var cffDict = new Type(strings);
  24396. for (var i = 0, ii = dict.length; i < ii; ++i) {
  24397. var pair = dict[i];
  24398. var key = pair[0];
  24399. var value = pair[1];
  24400. cffDict.setByKey(key, value);
  24401. }
  24402. return cffDict;
  24403. },
  24404. parseCharStrings: function CFFParser_parseCharStrings(charStringOffset) {
  24405. var charStrings = this.parseIndex(charStringOffset).obj;
  24406. var seacs = [];
  24407. var widths = [];
  24408. var count = charStrings.count;
  24409. for (var i = 0; i < count; i++) {
  24410. var charstring = charStrings.get(i);
  24411. var stackSize = 0;
  24412. var stack = [];
  24413. var undefStack = true;
  24414. var hints = 0;
  24415. var valid = true;
  24416. var data = charstring;
  24417. var length = data.length;
  24418. var firstStackClearing = true;
  24419. for (var j = 0; j < length;) {
  24420. var value = data[j++];
  24421. var validationCommand = null;
  24422. if (value === 12) {
  24423. var q = data[j++];
  24424. if (q === 0) {
  24425. // The CFF specification state that the 'dotsection' command
  24426. // (12, 0) is deprecated and treated as a no-op, but all Type2
  24427. // charstrings processors should support them. Unfortunately
  24428. // the font sanitizer don't. As a workaround the sequence (12, 0)
  24429. // is replaced by a useless (0, hmoveto).
  24430. data[j - 2] = 139;
  24431. data[j - 1] = 22;
  24432. stackSize = 0;
  24433. } else {
  24434. validationCommand = CharstringValidationData12[q];
  24435. }
  24436. } else if (value === 28) { // number (16 bit)
  24437. stack[stackSize] = ((data[j] << 24) | (data[j + 1] << 16)) >> 16;
  24438. j += 2;
  24439. stackSize++;
  24440. } else if (value === 14) {
  24441. if (stackSize >= 4) {
  24442. stackSize -= 4;
  24443. if (SEAC_ANALYSIS_ENABLED) {
  24444. seacs[i] = stack.slice(stackSize, stackSize + 4);
  24445. valid = false;
  24446. }
  24447. }
  24448. validationCommand = CharstringValidationData[value];
  24449. } else if (value >= 32 && value <= 246) { // number
  24450. stack[stackSize] = value - 139;
  24451. stackSize++;
  24452. } else if (value >= 247 && value <= 254) { // number (+1 bytes)
  24453. stack[stackSize] = (value < 251 ?
  24454. ((value - 247) << 8) + data[j] + 108 :
  24455. -((value - 251) << 8) - data[j] - 108);
  24456. j++;
  24457. stackSize++;
  24458. } else if (value === 255) { // number (32 bit)
  24459. stack[stackSize] = ((data[j] << 24) | (data[j + 1] << 16) |
  24460. (data[j + 2] << 8) | data[j + 3]) / 65536;
  24461. j += 4;
  24462. stackSize++;
  24463. } else if (value === 19 || value === 20) {
  24464. hints += stackSize >> 1;
  24465. j += (hints + 7) >> 3; // skipping right amount of hints flag data
  24466. stackSize %= 2;
  24467. validationCommand = CharstringValidationData[value];
  24468. } else {
  24469. validationCommand = CharstringValidationData[value];
  24470. }
  24471. if (validationCommand) {
  24472. if (validationCommand.stem) {
  24473. hints += stackSize >> 1;
  24474. }
  24475. if ('min' in validationCommand) {
  24476. if (!undefStack && stackSize < validationCommand.min) {
  24477. warn('Not enough parameters for ' + validationCommand.id +
  24478. '; actual: ' + stackSize +
  24479. ', expected: ' + validationCommand.min);
  24480. valid = false;
  24481. break;
  24482. }
  24483. }
  24484. if (firstStackClearing && validationCommand.stackClearing) {
  24485. firstStackClearing = false;
  24486. // the optional character width can be found before the first
  24487. // stack-clearing command arguments
  24488. stackSize -= validationCommand.min;
  24489. if (stackSize >= 2 && validationCommand.stem) {
  24490. // there are even amount of arguments for stem commands
  24491. stackSize %= 2;
  24492. } else if (stackSize > 1) {
  24493. warn('Found too many parameters for stack-clearing command');
  24494. }
  24495. if (stackSize > 0 && stack[stackSize - 1] >= 0) {
  24496. widths[i] = stack[stackSize - 1];
  24497. }
  24498. }
  24499. if ('stackDelta' in validationCommand) {
  24500. if ('stackFn' in validationCommand) {
  24501. validationCommand.stackFn(stack, stackSize);
  24502. }
  24503. stackSize += validationCommand.stackDelta;
  24504. } else if (validationCommand.stackClearing) {
  24505. stackSize = 0;
  24506. } else if (validationCommand.resetStack) {
  24507. stackSize = 0;
  24508. undefStack = false;
  24509. } else if (validationCommand.undefStack) {
  24510. stackSize = 0;
  24511. undefStack = true;
  24512. firstStackClearing = false;
  24513. }
  24514. }
  24515. }
  24516. if (!valid) {
  24517. // resetting invalid charstring to single 'endchar'
  24518. charStrings.set(i, new Uint8Array([14]));
  24519. }
  24520. }
  24521. return { charStrings: charStrings, seacs: seacs, widths: widths };
  24522. },
  24523. emptyPrivateDictionary:
  24524. function CFFParser_emptyPrivateDictionary(parentDict) {
  24525. var privateDict = this.createDict(CFFPrivateDict, [],
  24526. parentDict.strings);
  24527. parentDict.setByKey(18, [0, 0]);
  24528. parentDict.privateDict = privateDict;
  24529. },
  24530. parsePrivateDict: function CFFParser_parsePrivateDict(parentDict) {
  24531. // no private dict, do nothing
  24532. if (!parentDict.hasName('Private')) {
  24533. this.emptyPrivateDictionary(parentDict);
  24534. return;
  24535. }
  24536. var privateOffset = parentDict.getByName('Private');
  24537. // make sure the params are formatted correctly
  24538. if (!isArray(privateOffset) || privateOffset.length !== 2) {
  24539. parentDict.removeByName('Private');
  24540. return;
  24541. }
  24542. var size = privateOffset[0];
  24543. var offset = privateOffset[1];
  24544. // remove empty dicts or ones that refer to invalid location
  24545. if (size === 0 || offset >= this.bytes.length) {
  24546. this.emptyPrivateDictionary(parentDict);
  24547. return;
  24548. }
  24549. var privateDictEnd = offset + size;
  24550. var dictData = this.bytes.subarray(offset, privateDictEnd);
  24551. var dict = this.parseDict(dictData);
  24552. var privateDict = this.createDict(CFFPrivateDict, dict,
  24553. parentDict.strings);
  24554. parentDict.privateDict = privateDict;
  24555. // Parse the Subrs index also since it's relative to the private dict.
  24556. if (!privateDict.getByName('Subrs')) {
  24557. return;
  24558. }
  24559. var subrsOffset = privateDict.getByName('Subrs');
  24560. var relativeOffset = offset + subrsOffset;
  24561. // Validate the offset.
  24562. if (subrsOffset === 0 || relativeOffset >= this.bytes.length) {
  24563. this.emptyPrivateDictionary(parentDict);
  24564. return;
  24565. }
  24566. var subrsIndex = this.parseIndex(relativeOffset);
  24567. privateDict.subrsIndex = subrsIndex.obj;
  24568. },
  24569. parseCharsets: function CFFParser_parseCharsets(pos, length, strings, cid) {
  24570. if (pos === 0) {
  24571. return new CFFCharset(true, CFFCharsetPredefinedTypes.ISO_ADOBE,
  24572. ISOAdobeCharset);
  24573. } else if (pos === 1) {
  24574. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT,
  24575. ExpertCharset);
  24576. } else if (pos === 2) {
  24577. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT_SUBSET,
  24578. ExpertSubsetCharset);
  24579. }
  24580. var bytes = this.bytes;
  24581. var start = pos;
  24582. var format = bytes[pos++];
  24583. var charset = ['.notdef'];
  24584. var id, count, i;
  24585. // subtract 1 for the .notdef glyph
  24586. length -= 1;
  24587. switch (format) {
  24588. case 0:
  24589. for (i = 0; i < length; i++) {
  24590. id = (bytes[pos++] << 8) | bytes[pos++];
  24591. charset.push(cid ? id : strings.get(id));
  24592. }
  24593. break;
  24594. case 1:
  24595. while (charset.length <= length) {
  24596. id = (bytes[pos++] << 8) | bytes[pos++];
  24597. count = bytes[pos++];
  24598. for (i = 0; i <= count; i++) {
  24599. charset.push(cid ? id++ : strings.get(id++));
  24600. }
  24601. }
  24602. break;
  24603. case 2:
  24604. while (charset.length <= length) {
  24605. id = (bytes[pos++] << 8) | bytes[pos++];
  24606. count = (bytes[pos++] << 8) | bytes[pos++];
  24607. for (i = 0; i <= count; i++) {
  24608. charset.push(cid ? id++ : strings.get(id++));
  24609. }
  24610. }
  24611. break;
  24612. default:
  24613. error('Unknown charset format');
  24614. }
  24615. // Raw won't be needed if we actually compile the charset.
  24616. var end = pos;
  24617. var raw = bytes.subarray(start, end);
  24618. return new CFFCharset(false, format, charset, raw);
  24619. },
  24620. parseEncoding: function CFFParser_parseEncoding(pos,
  24621. properties,
  24622. strings,
  24623. charset) {
  24624. var encoding = {};
  24625. var bytes = this.bytes;
  24626. var predefined = false;
  24627. var hasSupplement = false;
  24628. var format, i, ii;
  24629. var raw = null;
  24630. function readSupplement() {
  24631. var supplementsCount = bytes[pos++];
  24632. for (i = 0; i < supplementsCount; i++) {
  24633. var code = bytes[pos++];
  24634. var sid = (bytes[pos++] << 8) + (bytes[pos++] & 0xff);
  24635. encoding[code] = charset.indexOf(strings.get(sid));
  24636. }
  24637. }
  24638. if (pos === 0 || pos === 1) {
  24639. predefined = true;
  24640. format = pos;
  24641. var baseEncoding = pos ? Encodings.ExpertEncoding :
  24642. Encodings.StandardEncoding;
  24643. for (i = 0, ii = charset.length; i < ii; i++) {
  24644. var index = baseEncoding.indexOf(charset[i]);
  24645. if (index !== -1) {
  24646. encoding[index] = i;
  24647. }
  24648. }
  24649. } else {
  24650. var dataStart = pos;
  24651. format = bytes[pos++];
  24652. switch (format & 0x7f) {
  24653. case 0:
  24654. var glyphsCount = bytes[pos++];
  24655. for (i = 1; i <= glyphsCount; i++) {
  24656. encoding[bytes[pos++]] = i;
  24657. }
  24658. break;
  24659. case 1:
  24660. var rangesCount = bytes[pos++];
  24661. var gid = 1;
  24662. for (i = 0; i < rangesCount; i++) {
  24663. var start = bytes[pos++];
  24664. var left = bytes[pos++];
  24665. for (var j = start; j <= start + left; j++) {
  24666. encoding[j] = gid++;
  24667. }
  24668. }
  24669. break;
  24670. default:
  24671. error('Unknow encoding format: ' + format + ' in CFF');
  24672. break;
  24673. }
  24674. var dataEnd = pos;
  24675. if (format & 0x80) {
  24676. // The font sanitizer does not support CFF encoding with a
  24677. // supplement, since the encoding is not really used to map
  24678. // between gid to glyph, let's overwrite what is declared in
  24679. // the top dictionary to let the sanitizer think the font use
  24680. // StandardEncoding, that's a lie but that's ok.
  24681. bytes[dataStart] &= 0x7f;
  24682. readSupplement();
  24683. hasSupplement = true;
  24684. }
  24685. raw = bytes.subarray(dataStart, dataEnd);
  24686. }
  24687. format = format & 0x7f;
  24688. return new CFFEncoding(predefined, format, encoding, raw);
  24689. },
  24690. parseFDSelect: function CFFParser_parseFDSelect(pos, length) {
  24691. var start = pos;
  24692. var bytes = this.bytes;
  24693. var format = bytes[pos++];
  24694. var fdSelect = [];
  24695. var i;
  24696. switch (format) {
  24697. case 0:
  24698. for (i = 0; i < length; ++i) {
  24699. var id = bytes[pos++];
  24700. fdSelect.push(id);
  24701. }
  24702. break;
  24703. case 3:
  24704. var rangesCount = (bytes[pos++] << 8) | bytes[pos++];
  24705. for (i = 0; i < rangesCount; ++i) {
  24706. var first = (bytes[pos++] << 8) | bytes[pos++];
  24707. var fdIndex = bytes[pos++];
  24708. var next = (bytes[pos] << 8) | bytes[pos + 1];
  24709. for (var j = first; j < next; ++j) {
  24710. fdSelect.push(fdIndex);
  24711. }
  24712. }
  24713. // Advance past the sentinel(next).
  24714. pos += 2;
  24715. break;
  24716. default:
  24717. error('Unknown fdselect format ' + format);
  24718. break;
  24719. }
  24720. var end = pos;
  24721. return new CFFFDSelect(fdSelect, bytes.subarray(start, end));
  24722. }
  24723. };
  24724. return CFFParser;
  24725. })();
  24726. // Compact Font Format
  24727. var CFF = (function CFFClosure() {
  24728. function CFF() {
  24729. this.header = null;
  24730. this.names = [];
  24731. this.topDict = null;
  24732. this.strings = new CFFStrings();
  24733. this.globalSubrIndex = null;
  24734. // The following could really be per font, but since we only have one font
  24735. // store them here.
  24736. this.encoding = null;
  24737. this.charset = null;
  24738. this.charStrings = null;
  24739. this.fdArray = [];
  24740. this.fdSelect = null;
  24741. this.isCIDFont = false;
  24742. }
  24743. return CFF;
  24744. })();
  24745. var CFFHeader = (function CFFHeaderClosure() {
  24746. function CFFHeader(major, minor, hdrSize, offSize) {
  24747. this.major = major;
  24748. this.minor = minor;
  24749. this.hdrSize = hdrSize;
  24750. this.offSize = offSize;
  24751. }
  24752. return CFFHeader;
  24753. })();
  24754. var CFFStrings = (function CFFStringsClosure() {
  24755. function CFFStrings() {
  24756. this.strings = [];
  24757. }
  24758. CFFStrings.prototype = {
  24759. get: function CFFStrings_get(index) {
  24760. if (index >= 0 && index <= 390) {
  24761. return CFFStandardStrings[index];
  24762. }
  24763. if (index - 391 <= this.strings.length) {
  24764. return this.strings[index - 391];
  24765. }
  24766. return CFFStandardStrings[0];
  24767. },
  24768. add: function CFFStrings_add(value) {
  24769. this.strings.push(value);
  24770. },
  24771. get count() {
  24772. return this.strings.length;
  24773. }
  24774. };
  24775. return CFFStrings;
  24776. })();
  24777. var CFFIndex = (function CFFIndexClosure() {
  24778. function CFFIndex() {
  24779. this.objects = [];
  24780. this.length = 0;
  24781. }
  24782. CFFIndex.prototype = {
  24783. add: function CFFIndex_add(data) {
  24784. this.length += data.length;
  24785. this.objects.push(data);
  24786. },
  24787. set: function CFFIndex_set(index, data) {
  24788. this.length += data.length - this.objects[index].length;
  24789. this.objects[index] = data;
  24790. },
  24791. get: function CFFIndex_get(index) {
  24792. return this.objects[index];
  24793. },
  24794. get count() {
  24795. return this.objects.length;
  24796. }
  24797. };
  24798. return CFFIndex;
  24799. })();
  24800. var CFFDict = (function CFFDictClosure() {
  24801. function CFFDict(tables, strings) {
  24802. this.keyToNameMap = tables.keyToNameMap;
  24803. this.nameToKeyMap = tables.nameToKeyMap;
  24804. this.defaults = tables.defaults;
  24805. this.types = tables.types;
  24806. this.opcodes = tables.opcodes;
  24807. this.order = tables.order;
  24808. this.strings = strings;
  24809. this.values = {};
  24810. }
  24811. CFFDict.prototype = {
  24812. // value should always be an array
  24813. setByKey: function CFFDict_setByKey(key, value) {
  24814. if (!(key in this.keyToNameMap)) {
  24815. return false;
  24816. }
  24817. // ignore empty values
  24818. if (value.length === 0) {
  24819. return true;
  24820. }
  24821. var type = this.types[key];
  24822. // remove the array wrapping these types of values
  24823. if (type === 'num' || type === 'sid' || type === 'offset') {
  24824. value = value[0];
  24825. }
  24826. this.values[key] = value;
  24827. return true;
  24828. },
  24829. setByName: function CFFDict_setByName(name, value) {
  24830. if (!(name in this.nameToKeyMap)) {
  24831. error('Invalid dictionary name "' + name + '"');
  24832. }
  24833. this.values[this.nameToKeyMap[name]] = value;
  24834. },
  24835. hasName: function CFFDict_hasName(name) {
  24836. return this.nameToKeyMap[name] in this.values;
  24837. },
  24838. getByName: function CFFDict_getByName(name) {
  24839. if (!(name in this.nameToKeyMap)) {
  24840. error('Invalid dictionary name "' + name + '"');
  24841. }
  24842. var key = this.nameToKeyMap[name];
  24843. if (!(key in this.values)) {
  24844. return this.defaults[key];
  24845. }
  24846. return this.values[key];
  24847. },
  24848. removeByName: function CFFDict_removeByName(name) {
  24849. delete this.values[this.nameToKeyMap[name]];
  24850. }
  24851. };
  24852. CFFDict.createTables = function CFFDict_createTables(layout) {
  24853. var tables = {
  24854. keyToNameMap: {},
  24855. nameToKeyMap: {},
  24856. defaults: {},
  24857. types: {},
  24858. opcodes: {},
  24859. order: []
  24860. };
  24861. for (var i = 0, ii = layout.length; i < ii; ++i) {
  24862. var entry = layout[i];
  24863. var key = isArray(entry[0]) ? (entry[0][0] << 8) + entry[0][1] : entry[0];
  24864. tables.keyToNameMap[key] = entry[1];
  24865. tables.nameToKeyMap[entry[1]] = key;
  24866. tables.types[key] = entry[2];
  24867. tables.defaults[key] = entry[3];
  24868. tables.opcodes[key] = isArray(entry[0]) ? entry[0] : [entry[0]];
  24869. tables.order.push(key);
  24870. }
  24871. return tables;
  24872. };
  24873. return CFFDict;
  24874. })();
  24875. var CFFTopDict = (function CFFTopDictClosure() {
  24876. var layout = [
  24877. [[12, 30], 'ROS', ['sid', 'sid', 'num'], null],
  24878. [[12, 20], 'SyntheticBase', 'num', null],
  24879. [0, 'version', 'sid', null],
  24880. [1, 'Notice', 'sid', null],
  24881. [[12, 0], 'Copyright', 'sid', null],
  24882. [2, 'FullName', 'sid', null],
  24883. [3, 'FamilyName', 'sid', null],
  24884. [4, 'Weight', 'sid', null],
  24885. [[12, 1], 'isFixedPitch', 'num', 0],
  24886. [[12, 2], 'ItalicAngle', 'num', 0],
  24887. [[12, 3], 'UnderlinePosition', 'num', -100],
  24888. [[12, 4], 'UnderlineThickness', 'num', 50],
  24889. [[12, 5], 'PaintType', 'num', 0],
  24890. [[12, 6], 'CharstringType', 'num', 2],
  24891. [[12, 7], 'FontMatrix', ['num', 'num', 'num', 'num', 'num', 'num'],
  24892. [0.001, 0, 0, 0.001, 0, 0]],
  24893. [13, 'UniqueID', 'num', null],
  24894. [5, 'FontBBox', ['num', 'num', 'num', 'num'], [0, 0, 0, 0]],
  24895. [[12, 8], 'StrokeWidth', 'num', 0],
  24896. [14, 'XUID', 'array', null],
  24897. [15, 'charset', 'offset', 0],
  24898. [16, 'Encoding', 'offset', 0],
  24899. [17, 'CharStrings', 'offset', 0],
  24900. [18, 'Private', ['offset', 'offset'], null],
  24901. [[12, 21], 'PostScript', 'sid', null],
  24902. [[12, 22], 'BaseFontName', 'sid', null],
  24903. [[12, 23], 'BaseFontBlend', 'delta', null],
  24904. [[12, 31], 'CIDFontVersion', 'num', 0],
  24905. [[12, 32], 'CIDFontRevision', 'num', 0],
  24906. [[12, 33], 'CIDFontType', 'num', 0],
  24907. [[12, 34], 'CIDCount', 'num', 8720],
  24908. [[12, 35], 'UIDBase', 'num', null],
  24909. // XXX: CID Fonts on DirectWrite 6.1 only seem to work if FDSelect comes
  24910. // before FDArray.
  24911. [[12, 37], 'FDSelect', 'offset', null],
  24912. [[12, 36], 'FDArray', 'offset', null],
  24913. [[12, 38], 'FontName', 'sid', null]
  24914. ];
  24915. var tables = null;
  24916. function CFFTopDict(strings) {
  24917. if (tables === null) {
  24918. tables = CFFDict.createTables(layout);
  24919. }
  24920. CFFDict.call(this, tables, strings);
  24921. this.privateDict = null;
  24922. }
  24923. CFFTopDict.prototype = Object.create(CFFDict.prototype);
  24924. return CFFTopDict;
  24925. })();
  24926. var CFFPrivateDict = (function CFFPrivateDictClosure() {
  24927. var layout = [
  24928. [6, 'BlueValues', 'delta', null],
  24929. [7, 'OtherBlues', 'delta', null],
  24930. [8, 'FamilyBlues', 'delta', null],
  24931. [9, 'FamilyOtherBlues', 'delta', null],
  24932. [[12, 9], 'BlueScale', 'num', 0.039625],
  24933. [[12, 10], 'BlueShift', 'num', 7],
  24934. [[12, 11], 'BlueFuzz', 'num', 1],
  24935. [10, 'StdHW', 'num', null],
  24936. [11, 'StdVW', 'num', null],
  24937. [[12, 12], 'StemSnapH', 'delta', null],
  24938. [[12, 13], 'StemSnapV', 'delta', null],
  24939. [[12, 14], 'ForceBold', 'num', 0],
  24940. [[12, 17], 'LanguageGroup', 'num', 0],
  24941. [[12, 18], 'ExpansionFactor', 'num', 0.06],
  24942. [[12, 19], 'initialRandomSeed', 'num', 0],
  24943. [20, 'defaultWidthX', 'num', 0],
  24944. [21, 'nominalWidthX', 'num', 0],
  24945. [19, 'Subrs', 'offset', null]
  24946. ];
  24947. var tables = null;
  24948. function CFFPrivateDict(strings) {
  24949. if (tables === null) {
  24950. tables = CFFDict.createTables(layout);
  24951. }
  24952. CFFDict.call(this, tables, strings);
  24953. this.subrsIndex = null;
  24954. }
  24955. CFFPrivateDict.prototype = Object.create(CFFDict.prototype);
  24956. return CFFPrivateDict;
  24957. })();
  24958. var CFFCharsetPredefinedTypes = {
  24959. ISO_ADOBE: 0,
  24960. EXPERT: 1,
  24961. EXPERT_SUBSET: 2
  24962. };
  24963. var CFFCharset = (function CFFCharsetClosure() {
  24964. function CFFCharset(predefined, format, charset, raw) {
  24965. this.predefined = predefined;
  24966. this.format = format;
  24967. this.charset = charset;
  24968. this.raw = raw;
  24969. }
  24970. return CFFCharset;
  24971. })();
  24972. var CFFEncoding = (function CFFEncodingClosure() {
  24973. function CFFEncoding(predefined, format, encoding, raw) {
  24974. this.predefined = predefined;
  24975. this.format = format;
  24976. this.encoding = encoding;
  24977. this.raw = raw;
  24978. }
  24979. return CFFEncoding;
  24980. })();
  24981. var CFFFDSelect = (function CFFFDSelectClosure() {
  24982. function CFFFDSelect(fdSelect, raw) {
  24983. this.fdSelect = fdSelect;
  24984. this.raw = raw;
  24985. }
  24986. return CFFFDSelect;
  24987. })();
  24988. // Helper class to keep track of where an offset is within the data and helps
  24989. // filling in that offset once it's known.
  24990. var CFFOffsetTracker = (function CFFOffsetTrackerClosure() {
  24991. function CFFOffsetTracker() {
  24992. this.offsets = {};
  24993. }
  24994. CFFOffsetTracker.prototype = {
  24995. isTracking: function CFFOffsetTracker_isTracking(key) {
  24996. return key in this.offsets;
  24997. },
  24998. track: function CFFOffsetTracker_track(key, location) {
  24999. if (key in this.offsets) {
  25000. error('Already tracking location of ' + key);
  25001. }
  25002. this.offsets[key] = location;
  25003. },
  25004. offset: function CFFOffsetTracker_offset(value) {
  25005. for (var key in this.offsets) {
  25006. this.offsets[key] += value;
  25007. }
  25008. },
  25009. setEntryLocation: function CFFOffsetTracker_setEntryLocation(key,
  25010. values,
  25011. output) {
  25012. if (!(key in this.offsets)) {
  25013. error('Not tracking location of ' + key);
  25014. }
  25015. var data = output.data;
  25016. var dataOffset = this.offsets[key];
  25017. var size = 5;
  25018. for (var i = 0, ii = values.length; i < ii; ++i) {
  25019. var offset0 = i * size + dataOffset;
  25020. var offset1 = offset0 + 1;
  25021. var offset2 = offset0 + 2;
  25022. var offset3 = offset0 + 3;
  25023. var offset4 = offset0 + 4;
  25024. // It's easy to screw up offsets so perform this sanity check.
  25025. if (data[offset0] !== 0x1d || data[offset1] !== 0 ||
  25026. data[offset2] !== 0 || data[offset3] !== 0 || data[offset4] !== 0) {
  25027. error('writing to an offset that is not empty');
  25028. }
  25029. var value = values[i];
  25030. data[offset0] = 0x1d;
  25031. data[offset1] = (value >> 24) & 0xFF;
  25032. data[offset2] = (value >> 16) & 0xFF;
  25033. data[offset3] = (value >> 8) & 0xFF;
  25034. data[offset4] = value & 0xFF;
  25035. }
  25036. }
  25037. };
  25038. return CFFOffsetTracker;
  25039. })();
  25040. // Takes a CFF and converts it to the binary representation.
  25041. var CFFCompiler = (function CFFCompilerClosure() {
  25042. function CFFCompiler(cff) {
  25043. this.cff = cff;
  25044. }
  25045. CFFCompiler.prototype = {
  25046. compile: function CFFCompiler_compile() {
  25047. var cff = this.cff;
  25048. var output = {
  25049. data: [],
  25050. length: 0,
  25051. add: function CFFCompiler_add(data) {
  25052. this.data = this.data.concat(data);
  25053. this.length = this.data.length;
  25054. }
  25055. };
  25056. // Compile the five entries that must be in order.
  25057. var header = this.compileHeader(cff.header);
  25058. output.add(header);
  25059. var nameIndex = this.compileNameIndex(cff.names);
  25060. output.add(nameIndex);
  25061. if (cff.isCIDFont) {
  25062. // The spec is unclear on how font matrices should relate to each other
  25063. // when there is one in the main top dict and the sub top dicts.
  25064. // Windows handles this differently than linux and osx so we have to
  25065. // normalize to work on all.
  25066. // Rules based off of some mailing list discussions:
  25067. // - If main font has a matrix and subfont doesn't, use the main matrix.
  25068. // - If no main font matrix and there is a subfont matrix, use the
  25069. // subfont matrix.
  25070. // - If both have matrices, concat together.
  25071. // - If neither have matrices, use default.
  25072. // To make this work on all platforms we move the top matrix into each
  25073. // sub top dict and concat if necessary.
  25074. if (cff.topDict.hasName('FontMatrix')) {
  25075. var base = cff.topDict.getByName('FontMatrix');
  25076. cff.topDict.removeByName('FontMatrix');
  25077. for (var i = 0, ii = cff.fdArray.length; i < ii; i++) {
  25078. var subDict = cff.fdArray[i];
  25079. var matrix = base.slice(0);
  25080. if (subDict.hasName('FontMatrix')) {
  25081. matrix = Util.transform(matrix, subDict.getByName('FontMatrix'));
  25082. }
  25083. subDict.setByName('FontMatrix', matrix);
  25084. }
  25085. }
  25086. }
  25087. var compiled = this.compileTopDicts([cff.topDict],
  25088. output.length,
  25089. cff.isCIDFont);
  25090. output.add(compiled.output);
  25091. var topDictTracker = compiled.trackers[0];
  25092. var stringIndex = this.compileStringIndex(cff.strings.strings);
  25093. output.add(stringIndex);
  25094. var globalSubrIndex = this.compileIndex(cff.globalSubrIndex);
  25095. output.add(globalSubrIndex);
  25096. // Now start on the other entries that have no specfic order.
  25097. if (cff.encoding && cff.topDict.hasName('Encoding')) {
  25098. if (cff.encoding.predefined) {
  25099. topDictTracker.setEntryLocation('Encoding', [cff.encoding.format],
  25100. output);
  25101. } else {
  25102. var encoding = this.compileEncoding(cff.encoding);
  25103. topDictTracker.setEntryLocation('Encoding', [output.length], output);
  25104. output.add(encoding);
  25105. }
  25106. }
  25107. if (cff.charset && cff.topDict.hasName('charset')) {
  25108. if (cff.charset.predefined) {
  25109. topDictTracker.setEntryLocation('charset', [cff.charset.format],
  25110. output);
  25111. } else {
  25112. var charset = this.compileCharset(cff.charset);
  25113. topDictTracker.setEntryLocation('charset', [output.length], output);
  25114. output.add(charset);
  25115. }
  25116. }
  25117. var charStrings = this.compileCharStrings(cff.charStrings);
  25118. topDictTracker.setEntryLocation('CharStrings', [output.length], output);
  25119. output.add(charStrings);
  25120. if (cff.isCIDFont) {
  25121. // For some reason FDSelect must be in front of FDArray on windows. OSX
  25122. // and linux don't seem to care.
  25123. topDictTracker.setEntryLocation('FDSelect', [output.length], output);
  25124. var fdSelect = this.compileFDSelect(cff.fdSelect.raw);
  25125. output.add(fdSelect);
  25126. // It is unclear if the sub font dictionary can have CID related
  25127. // dictionary keys, but the sanitizer doesn't like them so remove them.
  25128. compiled = this.compileTopDicts(cff.fdArray, output.length, true);
  25129. topDictTracker.setEntryLocation('FDArray', [output.length], output);
  25130. output.add(compiled.output);
  25131. var fontDictTrackers = compiled.trackers;
  25132. this.compilePrivateDicts(cff.fdArray, fontDictTrackers, output);
  25133. }
  25134. this.compilePrivateDicts([cff.topDict], [topDictTracker], output);
  25135. // If the font data ends with INDEX whose object data is zero-length,
  25136. // the sanitizer will bail out. Add a dummy byte to avoid that.
  25137. output.add([0]);
  25138. return output.data;
  25139. },
  25140. encodeNumber: function CFFCompiler_encodeNumber(value) {
  25141. if (parseFloat(value) === parseInt(value, 10) && !isNaN(value)) { // isInt
  25142. return this.encodeInteger(value);
  25143. } else {
  25144. return this.encodeFloat(value);
  25145. }
  25146. },
  25147. encodeFloat: function CFFCompiler_encodeFloat(num) {
  25148. var value = num.toString();
  25149. // rounding inaccurate doubles
  25150. var m = /\.(\d*?)(?:9{5,20}|0{5,20})\d{0,2}(?:e(.+)|$)/.exec(value);
  25151. if (m) {
  25152. var epsilon = parseFloat('1e' + ((m[2] ? +m[2] : 0) + m[1].length));
  25153. value = (Math.round(num * epsilon) / epsilon).toString();
  25154. }
  25155. var nibbles = '';
  25156. var i, ii;
  25157. for (i = 0, ii = value.length; i < ii; ++i) {
  25158. var a = value[i];
  25159. if (a === 'e') {
  25160. nibbles += value[++i] === '-' ? 'c' : 'b';
  25161. } else if (a === '.') {
  25162. nibbles += 'a';
  25163. } else if (a === '-') {
  25164. nibbles += 'e';
  25165. } else {
  25166. nibbles += a;
  25167. }
  25168. }
  25169. nibbles += (nibbles.length & 1) ? 'f' : 'ff';
  25170. var out = [30];
  25171. for (i = 0, ii = nibbles.length; i < ii; i += 2) {
  25172. out.push(parseInt(nibbles.substr(i, 2), 16));
  25173. }
  25174. return out;
  25175. },
  25176. encodeInteger: function CFFCompiler_encodeInteger(value) {
  25177. var code;
  25178. if (value >= -107 && value <= 107) {
  25179. code = [value + 139];
  25180. } else if (value >= 108 && value <= 1131) {
  25181. value = [value - 108];
  25182. code = [(value >> 8) + 247, value & 0xFF];
  25183. } else if (value >= -1131 && value <= -108) {
  25184. value = -value - 108;
  25185. code = [(value >> 8) + 251, value & 0xFF];
  25186. } else if (value >= -32768 && value <= 32767) {
  25187. code = [0x1c, (value >> 8) & 0xFF, value & 0xFF];
  25188. } else {
  25189. code = [0x1d,
  25190. (value >> 24) & 0xFF,
  25191. (value >> 16) & 0xFF,
  25192. (value >> 8) & 0xFF,
  25193. value & 0xFF];
  25194. }
  25195. return code;
  25196. },
  25197. compileHeader: function CFFCompiler_compileHeader(header) {
  25198. return [
  25199. header.major,
  25200. header.minor,
  25201. header.hdrSize,
  25202. header.offSize
  25203. ];
  25204. },
  25205. compileNameIndex: function CFFCompiler_compileNameIndex(names) {
  25206. var nameIndex = new CFFIndex();
  25207. for (var i = 0, ii = names.length; i < ii; ++i) {
  25208. nameIndex.add(stringToBytes(names[i]));
  25209. }
  25210. return this.compileIndex(nameIndex);
  25211. },
  25212. compileTopDicts: function CFFCompiler_compileTopDicts(dicts,
  25213. length,
  25214. removeCidKeys) {
  25215. var fontDictTrackers = [];
  25216. var fdArrayIndex = new CFFIndex();
  25217. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  25218. var fontDict = dicts[i];
  25219. if (removeCidKeys) {
  25220. fontDict.removeByName('CIDFontVersion');
  25221. fontDict.removeByName('CIDFontRevision');
  25222. fontDict.removeByName('CIDFontType');
  25223. fontDict.removeByName('CIDCount');
  25224. fontDict.removeByName('UIDBase');
  25225. }
  25226. var fontDictTracker = new CFFOffsetTracker();
  25227. var fontDictData = this.compileDict(fontDict, fontDictTracker);
  25228. fontDictTrackers.push(fontDictTracker);
  25229. fdArrayIndex.add(fontDictData);
  25230. fontDictTracker.offset(length);
  25231. }
  25232. fdArrayIndex = this.compileIndex(fdArrayIndex, fontDictTrackers);
  25233. return {
  25234. trackers: fontDictTrackers,
  25235. output: fdArrayIndex
  25236. };
  25237. },
  25238. compilePrivateDicts: function CFFCompiler_compilePrivateDicts(dicts,
  25239. trackers,
  25240. output) {
  25241. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  25242. var fontDict = dicts[i];
  25243. assert(fontDict.privateDict && fontDict.hasName('Private'),
  25244. 'There must be an private dictionary.');
  25245. var privateDict = fontDict.privateDict;
  25246. var privateDictTracker = new CFFOffsetTracker();
  25247. var privateDictData = this.compileDict(privateDict, privateDictTracker);
  25248. var outputLength = output.length;
  25249. privateDictTracker.offset(outputLength);
  25250. if (!privateDictData.length) {
  25251. // The private dictionary was empty, set the output length to zero to
  25252. // ensure the offset length isn't out of bounds in the eyes of the
  25253. // sanitizer.
  25254. outputLength = 0;
  25255. }
  25256. trackers[i].setEntryLocation('Private',
  25257. [privateDictData.length, outputLength],
  25258. output);
  25259. output.add(privateDictData);
  25260. if (privateDict.subrsIndex && privateDict.hasName('Subrs')) {
  25261. var subrs = this.compileIndex(privateDict.subrsIndex);
  25262. privateDictTracker.setEntryLocation('Subrs', [privateDictData.length],
  25263. output);
  25264. output.add(subrs);
  25265. }
  25266. }
  25267. },
  25268. compileDict: function CFFCompiler_compileDict(dict, offsetTracker) {
  25269. var out = [];
  25270. // The dictionary keys must be in a certain order.
  25271. var order = dict.order;
  25272. for (var i = 0; i < order.length; ++i) {
  25273. var key = order[i];
  25274. if (!(key in dict.values)) {
  25275. continue;
  25276. }
  25277. var values = dict.values[key];
  25278. var types = dict.types[key];
  25279. if (!isArray(types)) {
  25280. types = [types];
  25281. }
  25282. if (!isArray(values)) {
  25283. values = [values];
  25284. }
  25285. // Remove any empty dict values.
  25286. if (values.length === 0) {
  25287. continue;
  25288. }
  25289. for (var j = 0, jj = types.length; j < jj; ++j) {
  25290. var type = types[j];
  25291. var value = values[j];
  25292. switch (type) {
  25293. case 'num':
  25294. case 'sid':
  25295. out = out.concat(this.encodeNumber(value));
  25296. break;
  25297. case 'offset':
  25298. // For offsets we just insert a 32bit integer so we don't have to
  25299. // deal with figuring out the length of the offset when it gets
  25300. // replaced later on by the compiler.
  25301. var name = dict.keyToNameMap[key];
  25302. // Some offsets have the offset and the length, so just record the
  25303. // position of the first one.
  25304. if (!offsetTracker.isTracking(name)) {
  25305. offsetTracker.track(name, out.length);
  25306. }
  25307. out = out.concat([0x1d, 0, 0, 0, 0]);
  25308. break;
  25309. case 'array':
  25310. case 'delta':
  25311. out = out.concat(this.encodeNumber(value));
  25312. for (var k = 1, kk = values.length; k < kk; ++k) {
  25313. out = out.concat(this.encodeNumber(values[k]));
  25314. }
  25315. break;
  25316. default:
  25317. error('Unknown data type of ' + type);
  25318. break;
  25319. }
  25320. }
  25321. out = out.concat(dict.opcodes[key]);
  25322. }
  25323. return out;
  25324. },
  25325. compileStringIndex: function CFFCompiler_compileStringIndex(strings) {
  25326. var stringIndex = new CFFIndex();
  25327. for (var i = 0, ii = strings.length; i < ii; ++i) {
  25328. stringIndex.add(stringToBytes(strings[i]));
  25329. }
  25330. return this.compileIndex(stringIndex);
  25331. },
  25332. compileGlobalSubrIndex: function CFFCompiler_compileGlobalSubrIndex() {
  25333. var globalSubrIndex = this.cff.globalSubrIndex;
  25334. this.out.writeByteArray(this.compileIndex(globalSubrIndex));
  25335. },
  25336. compileCharStrings: function CFFCompiler_compileCharStrings(charStrings) {
  25337. return this.compileIndex(charStrings);
  25338. },
  25339. compileCharset: function CFFCompiler_compileCharset(charset) {
  25340. return this.compileTypedArray(charset.raw);
  25341. },
  25342. compileEncoding: function CFFCompiler_compileEncoding(encoding) {
  25343. return this.compileTypedArray(encoding.raw);
  25344. },
  25345. compileFDSelect: function CFFCompiler_compileFDSelect(fdSelect) {
  25346. return this.compileTypedArray(fdSelect);
  25347. },
  25348. compileTypedArray: function CFFCompiler_compileTypedArray(data) {
  25349. var out = [];
  25350. for (var i = 0, ii = data.length; i < ii; ++i) {
  25351. out[i] = data[i];
  25352. }
  25353. return out;
  25354. },
  25355. compileIndex: function CFFCompiler_compileIndex(index, trackers) {
  25356. trackers = trackers || [];
  25357. var objects = index.objects;
  25358. // First 2 bytes contains the number of objects contained into this index
  25359. var count = objects.length;
  25360. // If there is no object, just create an index. This technically
  25361. // should just be [0, 0] but OTS has an issue with that.
  25362. if (count === 0) {
  25363. return [0, 0, 0];
  25364. }
  25365. var data = [(count >> 8) & 0xFF, count & 0xff];
  25366. var lastOffset = 1, i;
  25367. for (i = 0; i < count; ++i) {
  25368. lastOffset += objects[i].length;
  25369. }
  25370. var offsetSize;
  25371. if (lastOffset < 0x100) {
  25372. offsetSize = 1;
  25373. } else if (lastOffset < 0x10000) {
  25374. offsetSize = 2;
  25375. } else if (lastOffset < 0x1000000) {
  25376. offsetSize = 3;
  25377. } else {
  25378. offsetSize = 4;
  25379. }
  25380. // Next byte contains the offset size use to reference object in the file
  25381. data.push(offsetSize);
  25382. // Add another offset after this one because we need a new offset
  25383. var relativeOffset = 1;
  25384. for (i = 0; i < count + 1; i++) {
  25385. if (offsetSize === 1) {
  25386. data.push(relativeOffset & 0xFF);
  25387. } else if (offsetSize === 2) {
  25388. data.push((relativeOffset >> 8) & 0xFF,
  25389. relativeOffset & 0xFF);
  25390. } else if (offsetSize === 3) {
  25391. data.push((relativeOffset >> 16) & 0xFF,
  25392. (relativeOffset >> 8) & 0xFF,
  25393. relativeOffset & 0xFF);
  25394. } else {
  25395. data.push((relativeOffset >>> 24) & 0xFF,
  25396. (relativeOffset >> 16) & 0xFF,
  25397. (relativeOffset >> 8) & 0xFF,
  25398. relativeOffset & 0xFF);
  25399. }
  25400. if (objects[i]) {
  25401. relativeOffset += objects[i].length;
  25402. }
  25403. }
  25404. for (i = 0; i < count; i++) {
  25405. // Notify the tracker where the object will be offset in the data.
  25406. if (trackers[i]) {
  25407. trackers[i].offset(data.length);
  25408. }
  25409. for (var j = 0, jj = objects[i].length; j < jj; j++) {
  25410. data.push(objects[i][j]);
  25411. }
  25412. }
  25413. return data;
  25414. }
  25415. };
  25416. return CFFCompiler;
  25417. })();
  25418. // Workaround for seac on Windows.
  25419. (function checkSeacSupport() {
  25420. if (/Windows/.test(navigator.userAgent)) {
  25421. SEAC_ANALYSIS_ENABLED = true;
  25422. }
  25423. })();
  25424. // Workaround for Private Use Area characters in Chrome on Windows
  25425. // http://code.google.com/p/chromium/issues/detail?id=122465
  25426. // https://github.com/mozilla/pdf.js/issues/1689
  25427. (function checkChromeWindows() {
  25428. if (/Windows.*Chrome/.test(navigator.userAgent)) {
  25429. SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = true;
  25430. }
  25431. })();
  25432. var FontRendererFactory = (function FontRendererFactoryClosure() {
  25433. function getLong(data, offset) {
  25434. return (data[offset] << 24) | (data[offset + 1] << 16) |
  25435. (data[offset + 2] << 8) | data[offset + 3];
  25436. }
  25437. function getUshort(data, offset) {
  25438. return (data[offset] << 8) | data[offset + 1];
  25439. }
  25440. function parseCmap(data, start, end) {
  25441. var offset = (getUshort(data, start + 2) === 1 ?
  25442. getLong(data, start + 8) : getLong(data, start + 16));
  25443. var format = getUshort(data, start + offset);
  25444. var length, ranges, p, i;
  25445. if (format === 4) {
  25446. length = getUshort(data, start + offset + 2);
  25447. var segCount = getUshort(data, start + offset + 6) >> 1;
  25448. p = start + offset + 14;
  25449. ranges = [];
  25450. for (i = 0; i < segCount; i++, p += 2) {
  25451. ranges[i] = {end: getUshort(data, p)};
  25452. }
  25453. p += 2;
  25454. for (i = 0; i < segCount; i++, p += 2) {
  25455. ranges[i].start = getUshort(data, p);
  25456. }
  25457. for (i = 0; i < segCount; i++, p += 2) {
  25458. ranges[i].idDelta = getUshort(data, p);
  25459. }
  25460. for (i = 0; i < segCount; i++, p += 2) {
  25461. var idOffset = getUshort(data, p);
  25462. if (idOffset === 0) {
  25463. continue;
  25464. }
  25465. ranges[i].ids = [];
  25466. for (var j = 0, jj = ranges[i].end - ranges[i].start + 1; j < jj; j++) {
  25467. ranges[i].ids[j] = getUshort(data, p + idOffset);
  25468. idOffset += 2;
  25469. }
  25470. }
  25471. return ranges;
  25472. } else if (format === 12) {
  25473. length = getLong(data, start + offset + 4);
  25474. var groups = getLong(data, start + offset + 12);
  25475. p = start + offset + 16;
  25476. ranges = [];
  25477. for (i = 0; i < groups; i++) {
  25478. ranges.push({
  25479. start: getLong(data, p),
  25480. end: getLong(data, p + 4),
  25481. idDelta: getLong(data, p + 8) - getLong(data, p)
  25482. });
  25483. p += 12;
  25484. }
  25485. return ranges;
  25486. }
  25487. error('not supported cmap: ' + format);
  25488. }
  25489. function parseCff(data, start, end) {
  25490. var properties = {};
  25491. var parser = new CFFParser(new Stream(data, start, end - start),
  25492. properties);
  25493. var cff = parser.parse();
  25494. return {
  25495. glyphs: cff.charStrings.objects,
  25496. subrs: (cff.topDict.privateDict && cff.topDict.privateDict.subrsIndex &&
  25497. cff.topDict.privateDict.subrsIndex.objects),
  25498. gsubrs: cff.globalSubrIndex && cff.globalSubrIndex.objects
  25499. };
  25500. }
  25501. function parseGlyfTable(glyf, loca, isGlyphLocationsLong) {
  25502. var itemSize, itemDecode;
  25503. if (isGlyphLocationsLong) {
  25504. itemSize = 4;
  25505. itemDecode = function fontItemDecodeLong(data, offset) {
  25506. return (data[offset] << 24) | (data[offset + 1] << 16) |
  25507. (data[offset + 2] << 8) | data[offset + 3];
  25508. };
  25509. } else {
  25510. itemSize = 2;
  25511. itemDecode = function fontItemDecode(data, offset) {
  25512. return (data[offset] << 9) | (data[offset + 1] << 1);
  25513. };
  25514. }
  25515. var glyphs = [];
  25516. var startOffset = itemDecode(loca, 0);
  25517. for (var j = itemSize; j < loca.length; j += itemSize) {
  25518. var endOffset = itemDecode(loca, j);
  25519. glyphs.push(glyf.subarray(startOffset, endOffset));
  25520. startOffset = endOffset;
  25521. }
  25522. return glyphs;
  25523. }
  25524. function lookupCmap(ranges, unicode) {
  25525. var code = unicode.charCodeAt(0);
  25526. var l = 0, r = ranges.length - 1;
  25527. while (l < r) {
  25528. var c = (l + r + 1) >> 1;
  25529. if (code < ranges[c].start) {
  25530. r = c - 1;
  25531. } else {
  25532. l = c;
  25533. }
  25534. }
  25535. if (ranges[l].start <= code && code <= ranges[l].end) {
  25536. return (ranges[l].idDelta + (ranges[l].ids ?
  25537. ranges[l].ids[code - ranges[l].start] : code)) & 0xFFFF;
  25538. }
  25539. return 0;
  25540. }
  25541. function compileGlyf(code, js, font) {
  25542. function moveTo(x, y) {
  25543. js.push('c.moveTo(' + x + ',' + y + ');');
  25544. }
  25545. function lineTo(x, y) {
  25546. js.push('c.lineTo(' + x + ',' + y + ');');
  25547. }
  25548. function quadraticCurveTo(xa, ya, x, y) {
  25549. js.push('c.quadraticCurveTo(' + xa + ',' + ya + ',' +
  25550. x + ',' + y + ');');
  25551. }
  25552. var i = 0;
  25553. var numberOfContours = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  25554. var flags;
  25555. var x = 0, y = 0;
  25556. i += 10;
  25557. if (numberOfContours < 0) {
  25558. // composite glyph
  25559. do {
  25560. flags = (code[i] << 8) | code[i + 1];
  25561. var glyphIndex = (code[i + 2] << 8) | code[i + 3];
  25562. i += 4;
  25563. var arg1, arg2;
  25564. if ((flags & 0x01)) {
  25565. arg1 = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  25566. arg2 = ((code[i + 2] << 24) | (code[i + 3] << 16)) >> 16;
  25567. i += 4;
  25568. } else {
  25569. arg1 = code[i++]; arg2 = code[i++];
  25570. }
  25571. if ((flags & 0x02)) {
  25572. x = arg1;
  25573. y = arg2;
  25574. } else {
  25575. x = 0; y = 0; // TODO "they are points" ?
  25576. }
  25577. var scaleX = 1, scaleY = 1, scale01 = 0, scale10 = 0;
  25578. if ((flags & 0x08)) {
  25579. scaleX =
  25580. scaleY = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  25581. i += 2;
  25582. } else if ((flags & 0x40)) {
  25583. scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  25584. scaleY = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
  25585. i += 4;
  25586. } else if ((flags & 0x80)) {
  25587. scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  25588. scale01 = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
  25589. scale10 = ((code[i + 4] << 24) | (code[i + 5] << 16)) / 1073741824;
  25590. scaleY = ((code[i + 6] << 24) | (code[i + 7] << 16)) / 1073741824;
  25591. i += 8;
  25592. }
  25593. var subglyph = font.glyphs[glyphIndex];
  25594. if (subglyph) {
  25595. js.push('c.save();');
  25596. js.push('c.transform(' + scaleX + ',' + scale01 + ',' +
  25597. scale10 + ',' + scaleY + ',' + x + ',' + y + ');');
  25598. compileGlyf(subglyph, js, font);
  25599. js.push('c.restore();');
  25600. }
  25601. } while ((flags & 0x20));
  25602. } else {
  25603. // simple glyph
  25604. var endPtsOfContours = [];
  25605. var j, jj;
  25606. for (j = 0; j < numberOfContours; j++) {
  25607. endPtsOfContours.push((code[i] << 8) | code[i + 1]);
  25608. i += 2;
  25609. }
  25610. var instructionLength = (code[i] << 8) | code[i + 1];
  25611. i += 2 + instructionLength; // skipping the instructions
  25612. var numberOfPoints = endPtsOfContours[endPtsOfContours.length - 1] + 1;
  25613. var points = [];
  25614. while (points.length < numberOfPoints) {
  25615. flags = code[i++];
  25616. var repeat = 1;
  25617. if ((flags & 0x08)) {
  25618. repeat += code[i++];
  25619. }
  25620. while (repeat-- > 0) {
  25621. points.push({flags: flags});
  25622. }
  25623. }
  25624. for (j = 0; j < numberOfPoints; j++) {
  25625. switch (points[j].flags & 0x12) {
  25626. case 0x00:
  25627. x += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  25628. i += 2;
  25629. break;
  25630. case 0x02:
  25631. x -= code[i++];
  25632. break;
  25633. case 0x12:
  25634. x += code[i++];
  25635. break;
  25636. }
  25637. points[j].x = x;
  25638. }
  25639. for (j = 0; j < numberOfPoints; j++) {
  25640. switch (points[j].flags & 0x24) {
  25641. case 0x00:
  25642. y += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  25643. i += 2;
  25644. break;
  25645. case 0x04:
  25646. y -= code[i++];
  25647. break;
  25648. case 0x24:
  25649. y += code[i++];
  25650. break;
  25651. }
  25652. points[j].y = y;
  25653. }
  25654. var startPoint = 0;
  25655. for (i = 0; i < numberOfContours; i++) {
  25656. var endPoint = endPtsOfContours[i];
  25657. // contours might have implicit points, which is located in the middle
  25658. // between two neighboring off-curve points
  25659. var contour = points.slice(startPoint, endPoint + 1);
  25660. if ((contour[0].flags & 1)) {
  25661. contour.push(contour[0]); // using start point at the contour end
  25662. } else if ((contour[contour.length - 1].flags & 1)) {
  25663. // first is off-curve point, trying to use one from the end
  25664. contour.unshift(contour[contour.length - 1]);
  25665. } else {
  25666. // start and end are off-curve points, creating implicit one
  25667. var p = {
  25668. flags: 1,
  25669. x: (contour[0].x + contour[contour.length - 1].x) / 2,
  25670. y: (contour[0].y + contour[contour.length - 1].y) / 2
  25671. };
  25672. contour.unshift(p);
  25673. contour.push(p);
  25674. }
  25675. moveTo(contour[0].x, contour[0].y);
  25676. for (j = 1, jj = contour.length; j < jj; j++) {
  25677. if ((contour[j].flags & 1)) {
  25678. lineTo(contour[j].x, contour[j].y);
  25679. } else if ((contour[j + 1].flags & 1)){
  25680. quadraticCurveTo(contour[j].x, contour[j].y,
  25681. contour[j + 1].x, contour[j + 1].y);
  25682. j++;
  25683. } else {
  25684. quadraticCurveTo(contour[j].x, contour[j].y,
  25685. (contour[j].x + contour[j + 1].x) / 2,
  25686. (contour[j].y + contour[j + 1].y) / 2);
  25687. }
  25688. }
  25689. startPoint = endPoint + 1;
  25690. }
  25691. }
  25692. }
  25693. function compileCharString(code, js, font) {
  25694. var stack = [];
  25695. var x = 0, y = 0;
  25696. var stems = 0;
  25697. function moveTo(x, y) {
  25698. js.push('c.moveTo(' + x + ',' + y + ');');
  25699. }
  25700. function lineTo(x, y) {
  25701. js.push('c.lineTo(' + x + ',' + y + ');');
  25702. }
  25703. function bezierCurveTo(x1, y1, x2, y2, x, y) {
  25704. js.push('c.bezierCurveTo(' + x1 + ',' + y1 + ',' + x2 + ',' + y2 + ',' +
  25705. x + ',' + y + ');');
  25706. }
  25707. function parse(code) {
  25708. var i = 0;
  25709. while (i < code.length) {
  25710. var stackClean = false;
  25711. var v = code[i++];
  25712. var xa, xb, ya, yb, y1, y2, y3, n, subrCode;
  25713. switch (v) {
  25714. case 1: // hstem
  25715. stems += stack.length >> 1;
  25716. stackClean = true;
  25717. break;
  25718. case 3: // vstem
  25719. stems += stack.length >> 1;
  25720. stackClean = true;
  25721. break;
  25722. case 4: // vmoveto
  25723. y += stack.pop();
  25724. moveTo(x, y);
  25725. stackClean = true;
  25726. break;
  25727. case 5: // rlineto
  25728. while (stack.length > 0) {
  25729. x += stack.shift();
  25730. y += stack.shift();
  25731. lineTo(x, y);
  25732. }
  25733. break;
  25734. case 6: // hlineto
  25735. while (stack.length > 0) {
  25736. x += stack.shift();
  25737. lineTo(x, y);
  25738. if (stack.length === 0) {
  25739. break;
  25740. }
  25741. y += stack.shift();
  25742. lineTo(x, y);
  25743. }
  25744. break;
  25745. case 7: // vlineto
  25746. while (stack.length > 0) {
  25747. y += stack.shift();
  25748. lineTo(x, y);
  25749. if (stack.length === 0) {
  25750. break;
  25751. }
  25752. x += stack.shift();
  25753. lineTo(x, y);
  25754. }
  25755. break;
  25756. case 8: // rrcurveto
  25757. while (stack.length > 0) {
  25758. xa = x + stack.shift(); ya = y + stack.shift();
  25759. xb = xa + stack.shift(); yb = ya + stack.shift();
  25760. x = xb + stack.shift(); y = yb + stack.shift();
  25761. bezierCurveTo(xa, ya, xb, yb, x, y);
  25762. }
  25763. break;
  25764. case 10: // callsubr
  25765. n = stack.pop() + font.subrsBias;
  25766. subrCode = font.subrs[n];
  25767. if (subrCode) {
  25768. parse(subrCode);
  25769. }
  25770. break;
  25771. case 11: // return
  25772. return;
  25773. case 12:
  25774. v = code[i++];
  25775. switch (v) {
  25776. case 34: // flex
  25777. xa = x + stack.shift();
  25778. xb = xa + stack.shift(); y1 = y + stack.shift();
  25779. x = xb + stack.shift();
  25780. bezierCurveTo(xa, y, xb, y1, x, y1);
  25781. xa = x + stack.shift();
  25782. xb = xa + stack.shift();
  25783. x = xb + stack.shift();
  25784. bezierCurveTo(xa, y1, xb, y, x, y);
  25785. break;
  25786. case 35: // flex
  25787. xa = x + stack.shift(); ya = y + stack.shift();
  25788. xb = xa + stack.shift(); yb = ya + stack.shift();
  25789. x = xb + stack.shift(); y = yb + stack.shift();
  25790. bezierCurveTo(xa, ya, xb, yb, x, y);
  25791. xa = x + stack.shift(); ya = y + stack.shift();
  25792. xb = xa + stack.shift(); yb = ya + stack.shift();
  25793. x = xb + stack.shift(); y = yb + stack.shift();
  25794. bezierCurveTo(xa, ya, xb, yb, x, y);
  25795. stack.pop(); // fd
  25796. break;
  25797. case 36: // hflex1
  25798. xa = x + stack.shift(); y1 = y + stack.shift();
  25799. xb = xa + stack.shift(); y2 = y1 + stack.shift();
  25800. x = xb + stack.shift();
  25801. bezierCurveTo(xa, y1, xb, y2, x, y2);
  25802. xa = x + stack.shift();
  25803. xb = xa + stack.shift(); y3 = y2 + stack.shift();
  25804. x = xb + stack.shift();
  25805. bezierCurveTo(xa, y2, xb, y3, x, y);
  25806. break;
  25807. case 37: // flex1
  25808. var x0 = x, y0 = y;
  25809. xa = x + stack.shift(); ya = y + stack.shift();
  25810. xb = xa + stack.shift(); yb = ya + stack.shift();
  25811. x = xb + stack.shift(); y = yb + stack.shift();
  25812. bezierCurveTo(xa, ya, xb, yb, x, y);
  25813. xa = x + stack.shift(); ya = y + stack.shift();
  25814. xb = xa + stack.shift(); yb = ya + stack.shift();
  25815. x = xb; y = yb;
  25816. if (Math.abs(x - x0) > Math.abs(y - y0)) {
  25817. x += stack.shift();
  25818. } else {
  25819. y += stack.shift();
  25820. }
  25821. bezierCurveTo(xa, ya, xb, yb, x, y);
  25822. break;
  25823. default:
  25824. error('unknown operator: 12 ' + v);
  25825. }
  25826. break;
  25827. case 14: // endchar
  25828. if (stack.length >= 4) {
  25829. var achar = stack.pop();
  25830. var bchar = stack.pop();
  25831. y = stack.pop();
  25832. x = stack.pop();
  25833. js.push('c.save();');
  25834. js.push('c.translate('+ x + ',' + y + ');');
  25835. var gid = lookupCmap(font.cmap, String.fromCharCode(
  25836. font.glyphNameMap[Encodings.StandardEncoding[achar]]));
  25837. compileCharString(font.glyphs[gid], js, font);
  25838. js.push('c.restore();');
  25839. gid = lookupCmap(font.cmap, String.fromCharCode(
  25840. font.glyphNameMap[Encodings.StandardEncoding[bchar]]));
  25841. compileCharString(font.glyphs[gid], js, font);
  25842. }
  25843. return;
  25844. case 18: // hstemhm
  25845. stems += stack.length >> 1;
  25846. stackClean = true;
  25847. break;
  25848. case 19: // hintmask
  25849. stems += stack.length >> 1;
  25850. i += (stems + 7) >> 3;
  25851. stackClean = true;
  25852. break;
  25853. case 20: // cntrmask
  25854. stems += stack.length >> 1;
  25855. i += (stems + 7) >> 3;
  25856. stackClean = true;
  25857. break;
  25858. case 21: // rmoveto
  25859. y += stack.pop();
  25860. x += stack.pop();
  25861. moveTo(x, y);
  25862. stackClean = true;
  25863. break;
  25864. case 22: // hmoveto
  25865. x += stack.pop();
  25866. moveTo(x, y);
  25867. stackClean = true;
  25868. break;
  25869. case 23: // vstemhm
  25870. stems += stack.length >> 1;
  25871. stackClean = true;
  25872. break;
  25873. case 24: // rcurveline
  25874. while (stack.length > 2) {
  25875. xa = x + stack.shift(); ya = y + stack.shift();
  25876. xb = xa + stack.shift(); yb = ya + stack.shift();
  25877. x = xb + stack.shift(); y = yb + stack.shift();
  25878. bezierCurveTo(xa, ya, xb, yb, x, y);
  25879. }
  25880. x += stack.shift();
  25881. y += stack.shift();
  25882. lineTo(x, y);
  25883. break;
  25884. case 25: // rlinecurve
  25885. while (stack.length > 6) {
  25886. x += stack.shift();
  25887. y += stack.shift();
  25888. lineTo(x, y);
  25889. }
  25890. xa = x + stack.shift(); ya = y + stack.shift();
  25891. xb = xa + stack.shift(); yb = ya + stack.shift();
  25892. x = xb + stack.shift(); y = yb + stack.shift();
  25893. bezierCurveTo(xa, ya, xb, yb, x, y);
  25894. break;
  25895. case 26: // vvcurveto
  25896. if (stack.length % 2) {
  25897. x += stack.shift();
  25898. }
  25899. while (stack.length > 0) {
  25900. xa = x; ya = y + stack.shift();
  25901. xb = xa + stack.shift(); yb = ya + stack.shift();
  25902. x = xb; y = yb + stack.shift();
  25903. bezierCurveTo(xa, ya, xb, yb, x, y);
  25904. }
  25905. break;
  25906. case 27: // hhcurveto
  25907. if (stack.length % 2) {
  25908. y += stack.shift();
  25909. }
  25910. while (stack.length > 0) {
  25911. xa = x + stack.shift(); ya = y;
  25912. xb = xa + stack.shift(); yb = ya + stack.shift();
  25913. x = xb + stack.shift(); y = yb;
  25914. bezierCurveTo(xa, ya, xb, yb, x, y);
  25915. }
  25916. break;
  25917. case 28:
  25918. stack.push(((code[i] << 24) | (code[i + 1] << 16)) >> 16);
  25919. i += 2;
  25920. break;
  25921. case 29: // callgsubr
  25922. n = stack.pop() + font.gsubrsBias;
  25923. subrCode = font.gsubrs[n];
  25924. if (subrCode) {
  25925. parse(subrCode);
  25926. }
  25927. break;
  25928. case 30: // vhcurveto
  25929. while (stack.length > 0) {
  25930. xa = x; ya = y + stack.shift();
  25931. xb = xa + stack.shift(); yb = ya + stack.shift();
  25932. x = xb + stack.shift();
  25933. y = yb + (stack.length === 1 ? stack.shift() : 0);
  25934. bezierCurveTo(xa, ya, xb, yb, x, y);
  25935. if (stack.length === 0) {
  25936. break;
  25937. }
  25938. xa = x + stack.shift(); ya = y;
  25939. xb = xa + stack.shift(); yb = ya + stack.shift();
  25940. y = yb + stack.shift();
  25941. x = xb + (stack.length === 1 ? stack.shift() : 0);
  25942. bezierCurveTo(xa, ya, xb, yb, x, y);
  25943. }
  25944. break;
  25945. case 31: // hvcurveto
  25946. while (stack.length > 0) {
  25947. xa = x + stack.shift(); ya = y;
  25948. xb = xa + stack.shift(); yb = ya + stack.shift();
  25949. y = yb + stack.shift();
  25950. x = xb + (stack.length === 1 ? stack.shift() : 0);
  25951. bezierCurveTo(xa, ya, xb, yb, x, y);
  25952. if (stack.length === 0) {
  25953. break;
  25954. }
  25955. xa = x; ya = y + stack.shift();
  25956. xb = xa + stack.shift(); yb = ya + stack.shift();
  25957. x = xb + stack.shift();
  25958. y = yb + (stack.length === 1 ? stack.shift() : 0);
  25959. bezierCurveTo(xa, ya, xb, yb, x, y);
  25960. }
  25961. break;
  25962. default:
  25963. if (v < 32) {
  25964. error('unknown operator: ' + v);
  25965. }
  25966. if (v < 247) {
  25967. stack.push(v - 139);
  25968. } else if (v < 251) {
  25969. stack.push((v - 247) * 256 + code[i++] + 108);
  25970. } else if (v < 255) {
  25971. stack.push(-(v - 251) * 256 - code[i++] - 108);
  25972. } else {
  25973. stack.push(((code[i] << 24) | (code[i + 1] << 16) |
  25974. (code[i + 2] << 8) | code[i + 3]) / 65536);
  25975. i += 4;
  25976. }
  25977. break;
  25978. }
  25979. if (stackClean) {
  25980. stack.length = 0;
  25981. }
  25982. }
  25983. }
  25984. parse(code);
  25985. }
  25986. var noop = '';
  25987. function CompiledFont(fontMatrix) {
  25988. this.compiledGlyphs = {};
  25989. this.fontMatrix = fontMatrix;
  25990. }
  25991. CompiledFont.prototype = {
  25992. getPathJs: function (unicode) {
  25993. var gid = lookupCmap(this.cmap, unicode);
  25994. var fn = this.compiledGlyphs[gid];
  25995. if (!fn) {
  25996. this.compiledGlyphs[gid] = fn = this.compileGlyph(this.glyphs[gid]);
  25997. }
  25998. return fn;
  25999. },
  26000. compileGlyph: function (code) {
  26001. if (!code || code.length === 0 || code[0] === 14) {
  26002. return noop;
  26003. }
  26004. var js = [];
  26005. js.push('c.save();');
  26006. js.push('c.transform(' + this.fontMatrix.join(',') + ');');
  26007. js.push('c.scale(size, -size);');
  26008. this.compileGlyphImpl(code, js);
  26009. js.push('c.restore();');
  26010. return js.join('\n');
  26011. },
  26012. compileGlyphImpl: function () {
  26013. error('Children classes should implement this.');
  26014. },
  26015. hasBuiltPath: function (unicode) {
  26016. var gid = lookupCmap(this.cmap, unicode);
  26017. return gid in this.compiledGlyphs;
  26018. }
  26019. };
  26020. function TrueTypeCompiled(glyphs, cmap, fontMatrix) {
  26021. fontMatrix = fontMatrix || [0.000488, 0, 0, 0.000488, 0, 0];
  26022. CompiledFont.call(this, fontMatrix);
  26023. this.glyphs = glyphs;
  26024. this.cmap = cmap;
  26025. this.compiledGlyphs = [];
  26026. }
  26027. Util.inherit(TrueTypeCompiled, CompiledFont, {
  26028. compileGlyphImpl: function (code, js) {
  26029. compileGlyf(code, js, this);
  26030. }
  26031. });
  26032. function Type2Compiled(cffInfo, cmap, fontMatrix, glyphNameMap) {
  26033. fontMatrix = fontMatrix || [0.001, 0, 0, 0.001, 0, 0];
  26034. CompiledFont.call(this, fontMatrix);
  26035. this.glyphs = cffInfo.glyphs;
  26036. this.gsubrs = cffInfo.gsubrs || [];
  26037. this.subrs = cffInfo.subrs || [];
  26038. this.cmap = cmap;
  26039. this.glyphNameMap = glyphNameMap || GlyphsUnicode;
  26040. this.compiledGlyphs = [];
  26041. this.gsubrsBias = (this.gsubrs.length < 1240 ?
  26042. 107 : (this.gsubrs.length < 33900 ? 1131 : 32768));
  26043. this.subrsBias = (this.subrs.length < 1240 ?
  26044. 107 : (this.subrs.length < 33900 ? 1131 : 32768));
  26045. }
  26046. Util.inherit(Type2Compiled, CompiledFont, {
  26047. compileGlyphImpl: function (code, js) {
  26048. compileCharString(code, js, this);
  26049. }
  26050. });
  26051. return {
  26052. create: function FontRendererFactory_create(font) {
  26053. var data = new Uint8Array(font.data);
  26054. var cmap, glyf, loca, cff, indexToLocFormat, unitsPerEm;
  26055. var numTables = getUshort(data, 4);
  26056. for (var i = 0, p = 12; i < numTables; i++, p += 16) {
  26057. var tag = bytesToString(data.subarray(p, p + 4));
  26058. var offset = getLong(data, p + 8);
  26059. var length = getLong(data, p + 12);
  26060. switch (tag) {
  26061. case 'cmap':
  26062. cmap = parseCmap(data, offset, offset + length);
  26063. break;
  26064. case 'glyf':
  26065. glyf = data.subarray(offset, offset + length);
  26066. break;
  26067. case 'loca':
  26068. loca = data.subarray(offset, offset + length);
  26069. break;
  26070. case 'head':
  26071. unitsPerEm = getUshort(data, offset + 18);
  26072. indexToLocFormat = getUshort(data, offset + 50);
  26073. break;
  26074. case 'CFF ':
  26075. cff = parseCff(data, offset, offset + length);
  26076. break;
  26077. }
  26078. }
  26079. if (glyf) {
  26080. var fontMatrix = (!unitsPerEm ? font.fontMatrix :
  26081. [1 / unitsPerEm, 0, 0, 1 / unitsPerEm, 0, 0]);
  26082. return new TrueTypeCompiled(
  26083. parseGlyfTable(glyf, loca, indexToLocFormat), cmap, fontMatrix);
  26084. } else {
  26085. return new Type2Compiled(cff, cmap, font.fontMatrix, font.glyphNameMap);
  26086. }
  26087. }
  26088. };
  26089. })();
  26090. var GlyphsUnicode = {
  26091. A: 0x0041,
  26092. AE: 0x00C6,
  26093. AEacute: 0x01FC,
  26094. AEmacron: 0x01E2,
  26095. AEsmall: 0xF7E6,
  26096. Aacute: 0x00C1,
  26097. Aacutesmall: 0xF7E1,
  26098. Abreve: 0x0102,
  26099. Abreveacute: 0x1EAE,
  26100. Abrevecyrillic: 0x04D0,
  26101. Abrevedotbelow: 0x1EB6,
  26102. Abrevegrave: 0x1EB0,
  26103. Abrevehookabove: 0x1EB2,
  26104. Abrevetilde: 0x1EB4,
  26105. Acaron: 0x01CD,
  26106. Acircle: 0x24B6,
  26107. Acircumflex: 0x00C2,
  26108. Acircumflexacute: 0x1EA4,
  26109. Acircumflexdotbelow: 0x1EAC,
  26110. Acircumflexgrave: 0x1EA6,
  26111. Acircumflexhookabove: 0x1EA8,
  26112. Acircumflexsmall: 0xF7E2,
  26113. Acircumflextilde: 0x1EAA,
  26114. Acute: 0xF6C9,
  26115. Acutesmall: 0xF7B4,
  26116. Acyrillic: 0x0410,
  26117. Adblgrave: 0x0200,
  26118. Adieresis: 0x00C4,
  26119. Adieresiscyrillic: 0x04D2,
  26120. Adieresismacron: 0x01DE,
  26121. Adieresissmall: 0xF7E4,
  26122. Adotbelow: 0x1EA0,
  26123. Adotmacron: 0x01E0,
  26124. Agrave: 0x00C0,
  26125. Agravesmall: 0xF7E0,
  26126. Ahookabove: 0x1EA2,
  26127. Aiecyrillic: 0x04D4,
  26128. Ainvertedbreve: 0x0202,
  26129. Alpha: 0x0391,
  26130. Alphatonos: 0x0386,
  26131. Amacron: 0x0100,
  26132. Amonospace: 0xFF21,
  26133. Aogonek: 0x0104,
  26134. Aring: 0x00C5,
  26135. Aringacute: 0x01FA,
  26136. Aringbelow: 0x1E00,
  26137. Aringsmall: 0xF7E5,
  26138. Asmall: 0xF761,
  26139. Atilde: 0x00C3,
  26140. Atildesmall: 0xF7E3,
  26141. Aybarmenian: 0x0531,
  26142. B: 0x0042,
  26143. Bcircle: 0x24B7,
  26144. Bdotaccent: 0x1E02,
  26145. Bdotbelow: 0x1E04,
  26146. Becyrillic: 0x0411,
  26147. Benarmenian: 0x0532,
  26148. Beta: 0x0392,
  26149. Bhook: 0x0181,
  26150. Blinebelow: 0x1E06,
  26151. Bmonospace: 0xFF22,
  26152. Brevesmall: 0xF6F4,
  26153. Bsmall: 0xF762,
  26154. Btopbar: 0x0182,
  26155. C: 0x0043,
  26156. Caarmenian: 0x053E,
  26157. Cacute: 0x0106,
  26158. Caron: 0xF6CA,
  26159. Caronsmall: 0xF6F5,
  26160. Ccaron: 0x010C,
  26161. Ccedilla: 0x00C7,
  26162. Ccedillaacute: 0x1E08,
  26163. Ccedillasmall: 0xF7E7,
  26164. Ccircle: 0x24B8,
  26165. Ccircumflex: 0x0108,
  26166. Cdot: 0x010A,
  26167. Cdotaccent: 0x010A,
  26168. Cedillasmall: 0xF7B8,
  26169. Chaarmenian: 0x0549,
  26170. Cheabkhasiancyrillic: 0x04BC,
  26171. Checyrillic: 0x0427,
  26172. Chedescenderabkhasiancyrillic: 0x04BE,
  26173. Chedescendercyrillic: 0x04B6,
  26174. Chedieresiscyrillic: 0x04F4,
  26175. Cheharmenian: 0x0543,
  26176. Chekhakassiancyrillic: 0x04CB,
  26177. Cheverticalstrokecyrillic: 0x04B8,
  26178. Chi: 0x03A7,
  26179. Chook: 0x0187,
  26180. Circumflexsmall: 0xF6F6,
  26181. Cmonospace: 0xFF23,
  26182. Coarmenian: 0x0551,
  26183. Csmall: 0xF763,
  26184. D: 0x0044,
  26185. DZ: 0x01F1,
  26186. DZcaron: 0x01C4,
  26187. Daarmenian: 0x0534,
  26188. Dafrican: 0x0189,
  26189. Dcaron: 0x010E,
  26190. Dcedilla: 0x1E10,
  26191. Dcircle: 0x24B9,
  26192. Dcircumflexbelow: 0x1E12,
  26193. Dcroat: 0x0110,
  26194. Ddotaccent: 0x1E0A,
  26195. Ddotbelow: 0x1E0C,
  26196. Decyrillic: 0x0414,
  26197. Deicoptic: 0x03EE,
  26198. Delta: 0x2206,
  26199. Deltagreek: 0x0394,
  26200. Dhook: 0x018A,
  26201. Dieresis: 0xF6CB,
  26202. DieresisAcute: 0xF6CC,
  26203. DieresisGrave: 0xF6CD,
  26204. Dieresissmall: 0xF7A8,
  26205. Digammagreek: 0x03DC,
  26206. Djecyrillic: 0x0402,
  26207. Dlinebelow: 0x1E0E,
  26208. Dmonospace: 0xFF24,
  26209. Dotaccentsmall: 0xF6F7,
  26210. Dslash: 0x0110,
  26211. Dsmall: 0xF764,
  26212. Dtopbar: 0x018B,
  26213. Dz: 0x01F2,
  26214. Dzcaron: 0x01C5,
  26215. Dzeabkhasiancyrillic: 0x04E0,
  26216. Dzecyrillic: 0x0405,
  26217. Dzhecyrillic: 0x040F,
  26218. E: 0x0045,
  26219. Eacute: 0x00C9,
  26220. Eacutesmall: 0xF7E9,
  26221. Ebreve: 0x0114,
  26222. Ecaron: 0x011A,
  26223. Ecedillabreve: 0x1E1C,
  26224. Echarmenian: 0x0535,
  26225. Ecircle: 0x24BA,
  26226. Ecircumflex: 0x00CA,
  26227. Ecircumflexacute: 0x1EBE,
  26228. Ecircumflexbelow: 0x1E18,
  26229. Ecircumflexdotbelow: 0x1EC6,
  26230. Ecircumflexgrave: 0x1EC0,
  26231. Ecircumflexhookabove: 0x1EC2,
  26232. Ecircumflexsmall: 0xF7EA,
  26233. Ecircumflextilde: 0x1EC4,
  26234. Ecyrillic: 0x0404,
  26235. Edblgrave: 0x0204,
  26236. Edieresis: 0x00CB,
  26237. Edieresissmall: 0xF7EB,
  26238. Edot: 0x0116,
  26239. Edotaccent: 0x0116,
  26240. Edotbelow: 0x1EB8,
  26241. Efcyrillic: 0x0424,
  26242. Egrave: 0x00C8,
  26243. Egravesmall: 0xF7E8,
  26244. Eharmenian: 0x0537,
  26245. Ehookabove: 0x1EBA,
  26246. Eightroman: 0x2167,
  26247. Einvertedbreve: 0x0206,
  26248. Eiotifiedcyrillic: 0x0464,
  26249. Elcyrillic: 0x041B,
  26250. Elevenroman: 0x216A,
  26251. Emacron: 0x0112,
  26252. Emacronacute: 0x1E16,
  26253. Emacrongrave: 0x1E14,
  26254. Emcyrillic: 0x041C,
  26255. Emonospace: 0xFF25,
  26256. Encyrillic: 0x041D,
  26257. Endescendercyrillic: 0x04A2,
  26258. Eng: 0x014A,
  26259. Enghecyrillic: 0x04A4,
  26260. Enhookcyrillic: 0x04C7,
  26261. Eogonek: 0x0118,
  26262. Eopen: 0x0190,
  26263. Epsilon: 0x0395,
  26264. Epsilontonos: 0x0388,
  26265. Ercyrillic: 0x0420,
  26266. Ereversed: 0x018E,
  26267. Ereversedcyrillic: 0x042D,
  26268. Escyrillic: 0x0421,
  26269. Esdescendercyrillic: 0x04AA,
  26270. Esh: 0x01A9,
  26271. Esmall: 0xF765,
  26272. Eta: 0x0397,
  26273. Etarmenian: 0x0538,
  26274. Etatonos: 0x0389,
  26275. Eth: 0x00D0,
  26276. Ethsmall: 0xF7F0,
  26277. Etilde: 0x1EBC,
  26278. Etildebelow: 0x1E1A,
  26279. Euro: 0x20AC,
  26280. Ezh: 0x01B7,
  26281. Ezhcaron: 0x01EE,
  26282. Ezhreversed: 0x01B8,
  26283. F: 0x0046,
  26284. Fcircle: 0x24BB,
  26285. Fdotaccent: 0x1E1E,
  26286. Feharmenian: 0x0556,
  26287. Feicoptic: 0x03E4,
  26288. Fhook: 0x0191,
  26289. Fitacyrillic: 0x0472,
  26290. Fiveroman: 0x2164,
  26291. Fmonospace: 0xFF26,
  26292. Fourroman: 0x2163,
  26293. Fsmall: 0xF766,
  26294. G: 0x0047,
  26295. GBsquare: 0x3387,
  26296. Gacute: 0x01F4,
  26297. Gamma: 0x0393,
  26298. Gammaafrican: 0x0194,
  26299. Gangiacoptic: 0x03EA,
  26300. Gbreve: 0x011E,
  26301. Gcaron: 0x01E6,
  26302. Gcedilla: 0x0122,
  26303. Gcircle: 0x24BC,
  26304. Gcircumflex: 0x011C,
  26305. Gcommaaccent: 0x0122,
  26306. Gdot: 0x0120,
  26307. Gdotaccent: 0x0120,
  26308. Gecyrillic: 0x0413,
  26309. Ghadarmenian: 0x0542,
  26310. Ghemiddlehookcyrillic: 0x0494,
  26311. Ghestrokecyrillic: 0x0492,
  26312. Gheupturncyrillic: 0x0490,
  26313. Ghook: 0x0193,
  26314. Gimarmenian: 0x0533,
  26315. Gjecyrillic: 0x0403,
  26316. Gmacron: 0x1E20,
  26317. Gmonospace: 0xFF27,
  26318. Grave: 0xF6CE,
  26319. Gravesmall: 0xF760,
  26320. Gsmall: 0xF767,
  26321. Gsmallhook: 0x029B,
  26322. Gstroke: 0x01E4,
  26323. H: 0x0048,
  26324. H18533: 0x25CF,
  26325. H18543: 0x25AA,
  26326. H18551: 0x25AB,
  26327. H22073: 0x25A1,
  26328. HPsquare: 0x33CB,
  26329. Haabkhasiancyrillic: 0x04A8,
  26330. Hadescendercyrillic: 0x04B2,
  26331. Hardsigncyrillic: 0x042A,
  26332. Hbar: 0x0126,
  26333. Hbrevebelow: 0x1E2A,
  26334. Hcedilla: 0x1E28,
  26335. Hcircle: 0x24BD,
  26336. Hcircumflex: 0x0124,
  26337. Hdieresis: 0x1E26,
  26338. Hdotaccent: 0x1E22,
  26339. Hdotbelow: 0x1E24,
  26340. Hmonospace: 0xFF28,
  26341. Hoarmenian: 0x0540,
  26342. Horicoptic: 0x03E8,
  26343. Hsmall: 0xF768,
  26344. Hungarumlaut: 0xF6CF,
  26345. Hungarumlautsmall: 0xF6F8,
  26346. Hzsquare: 0x3390,
  26347. I: 0x0049,
  26348. IAcyrillic: 0x042F,
  26349. IJ: 0x0132,
  26350. IUcyrillic: 0x042E,
  26351. Iacute: 0x00CD,
  26352. Iacutesmall: 0xF7ED,
  26353. Ibreve: 0x012C,
  26354. Icaron: 0x01CF,
  26355. Icircle: 0x24BE,
  26356. Icircumflex: 0x00CE,
  26357. Icircumflexsmall: 0xF7EE,
  26358. Icyrillic: 0x0406,
  26359. Idblgrave: 0x0208,
  26360. Idieresis: 0x00CF,
  26361. Idieresisacute: 0x1E2E,
  26362. Idieresiscyrillic: 0x04E4,
  26363. Idieresissmall: 0xF7EF,
  26364. Idot: 0x0130,
  26365. Idotaccent: 0x0130,
  26366. Idotbelow: 0x1ECA,
  26367. Iebrevecyrillic: 0x04D6,
  26368. Iecyrillic: 0x0415,
  26369. Ifraktur: 0x2111,
  26370. Igrave: 0x00CC,
  26371. Igravesmall: 0xF7EC,
  26372. Ihookabove: 0x1EC8,
  26373. Iicyrillic: 0x0418,
  26374. Iinvertedbreve: 0x020A,
  26375. Iishortcyrillic: 0x0419,
  26376. Imacron: 0x012A,
  26377. Imacroncyrillic: 0x04E2,
  26378. Imonospace: 0xFF29,
  26379. Iniarmenian: 0x053B,
  26380. Iocyrillic: 0x0401,
  26381. Iogonek: 0x012E,
  26382. Iota: 0x0399,
  26383. Iotaafrican: 0x0196,
  26384. Iotadieresis: 0x03AA,
  26385. Iotatonos: 0x038A,
  26386. Ismall: 0xF769,
  26387. Istroke: 0x0197,
  26388. Itilde: 0x0128,
  26389. Itildebelow: 0x1E2C,
  26390. Izhitsacyrillic: 0x0474,
  26391. Izhitsadblgravecyrillic: 0x0476,
  26392. J: 0x004A,
  26393. Jaarmenian: 0x0541,
  26394. Jcircle: 0x24BF,
  26395. Jcircumflex: 0x0134,
  26396. Jecyrillic: 0x0408,
  26397. Jheharmenian: 0x054B,
  26398. Jmonospace: 0xFF2A,
  26399. Jsmall: 0xF76A,
  26400. K: 0x004B,
  26401. KBsquare: 0x3385,
  26402. KKsquare: 0x33CD,
  26403. Kabashkircyrillic: 0x04A0,
  26404. Kacute: 0x1E30,
  26405. Kacyrillic: 0x041A,
  26406. Kadescendercyrillic: 0x049A,
  26407. Kahookcyrillic: 0x04C3,
  26408. Kappa: 0x039A,
  26409. Kastrokecyrillic: 0x049E,
  26410. Kaverticalstrokecyrillic: 0x049C,
  26411. Kcaron: 0x01E8,
  26412. Kcedilla: 0x0136,
  26413. Kcircle: 0x24C0,
  26414. Kcommaaccent: 0x0136,
  26415. Kdotbelow: 0x1E32,
  26416. Keharmenian: 0x0554,
  26417. Kenarmenian: 0x053F,
  26418. Khacyrillic: 0x0425,
  26419. Kheicoptic: 0x03E6,
  26420. Khook: 0x0198,
  26421. Kjecyrillic: 0x040C,
  26422. Klinebelow: 0x1E34,
  26423. Kmonospace: 0xFF2B,
  26424. Koppacyrillic: 0x0480,
  26425. Koppagreek: 0x03DE,
  26426. Ksicyrillic: 0x046E,
  26427. Ksmall: 0xF76B,
  26428. L: 0x004C,
  26429. LJ: 0x01C7,
  26430. LL: 0xF6BF,
  26431. Lacute: 0x0139,
  26432. Lambda: 0x039B,
  26433. Lcaron: 0x013D,
  26434. Lcedilla: 0x013B,
  26435. Lcircle: 0x24C1,
  26436. Lcircumflexbelow: 0x1E3C,
  26437. Lcommaaccent: 0x013B,
  26438. Ldot: 0x013F,
  26439. Ldotaccent: 0x013F,
  26440. Ldotbelow: 0x1E36,
  26441. Ldotbelowmacron: 0x1E38,
  26442. Liwnarmenian: 0x053C,
  26443. Lj: 0x01C8,
  26444. Ljecyrillic: 0x0409,
  26445. Llinebelow: 0x1E3A,
  26446. Lmonospace: 0xFF2C,
  26447. Lslash: 0x0141,
  26448. Lslashsmall: 0xF6F9,
  26449. Lsmall: 0xF76C,
  26450. M: 0x004D,
  26451. MBsquare: 0x3386,
  26452. Macron: 0xF6D0,
  26453. Macronsmall: 0xF7AF,
  26454. Macute: 0x1E3E,
  26455. Mcircle: 0x24C2,
  26456. Mdotaccent: 0x1E40,
  26457. Mdotbelow: 0x1E42,
  26458. Menarmenian: 0x0544,
  26459. Mmonospace: 0xFF2D,
  26460. Msmall: 0xF76D,
  26461. Mturned: 0x019C,
  26462. Mu: 0x039C,
  26463. N: 0x004E,
  26464. NJ: 0x01CA,
  26465. Nacute: 0x0143,
  26466. Ncaron: 0x0147,
  26467. Ncedilla: 0x0145,
  26468. Ncircle: 0x24C3,
  26469. Ncircumflexbelow: 0x1E4A,
  26470. Ncommaaccent: 0x0145,
  26471. Ndotaccent: 0x1E44,
  26472. Ndotbelow: 0x1E46,
  26473. Nhookleft: 0x019D,
  26474. Nineroman: 0x2168,
  26475. Nj: 0x01CB,
  26476. Njecyrillic: 0x040A,
  26477. Nlinebelow: 0x1E48,
  26478. Nmonospace: 0xFF2E,
  26479. Nowarmenian: 0x0546,
  26480. Nsmall: 0xF76E,
  26481. Ntilde: 0x00D1,
  26482. Ntildesmall: 0xF7F1,
  26483. Nu: 0x039D,
  26484. O: 0x004F,
  26485. OE: 0x0152,
  26486. OEsmall: 0xF6FA,
  26487. Oacute: 0x00D3,
  26488. Oacutesmall: 0xF7F3,
  26489. Obarredcyrillic: 0x04E8,
  26490. Obarreddieresiscyrillic: 0x04EA,
  26491. Obreve: 0x014E,
  26492. Ocaron: 0x01D1,
  26493. Ocenteredtilde: 0x019F,
  26494. Ocircle: 0x24C4,
  26495. Ocircumflex: 0x00D4,
  26496. Ocircumflexacute: 0x1ED0,
  26497. Ocircumflexdotbelow: 0x1ED8,
  26498. Ocircumflexgrave: 0x1ED2,
  26499. Ocircumflexhookabove: 0x1ED4,
  26500. Ocircumflexsmall: 0xF7F4,
  26501. Ocircumflextilde: 0x1ED6,
  26502. Ocyrillic: 0x041E,
  26503. Odblacute: 0x0150,
  26504. Odblgrave: 0x020C,
  26505. Odieresis: 0x00D6,
  26506. Odieresiscyrillic: 0x04E6,
  26507. Odieresissmall: 0xF7F6,
  26508. Odotbelow: 0x1ECC,
  26509. Ogoneksmall: 0xF6FB,
  26510. Ograve: 0x00D2,
  26511. Ogravesmall: 0xF7F2,
  26512. Oharmenian: 0x0555,
  26513. Ohm: 0x2126,
  26514. Ohookabove: 0x1ECE,
  26515. Ohorn: 0x01A0,
  26516. Ohornacute: 0x1EDA,
  26517. Ohorndotbelow: 0x1EE2,
  26518. Ohorngrave: 0x1EDC,
  26519. Ohornhookabove: 0x1EDE,
  26520. Ohorntilde: 0x1EE0,
  26521. Ohungarumlaut: 0x0150,
  26522. Oi: 0x01A2,
  26523. Oinvertedbreve: 0x020E,
  26524. Omacron: 0x014C,
  26525. Omacronacute: 0x1E52,
  26526. Omacrongrave: 0x1E50,
  26527. Omega: 0x2126,
  26528. Omegacyrillic: 0x0460,
  26529. Omegagreek: 0x03A9,
  26530. Omegaroundcyrillic: 0x047A,
  26531. Omegatitlocyrillic: 0x047C,
  26532. Omegatonos: 0x038F,
  26533. Omicron: 0x039F,
  26534. Omicrontonos: 0x038C,
  26535. Omonospace: 0xFF2F,
  26536. Oneroman: 0x2160,
  26537. Oogonek: 0x01EA,
  26538. Oogonekmacron: 0x01EC,
  26539. Oopen: 0x0186,
  26540. Oslash: 0x00D8,
  26541. Oslashacute: 0x01FE,
  26542. Oslashsmall: 0xF7F8,
  26543. Osmall: 0xF76F,
  26544. Ostrokeacute: 0x01FE,
  26545. Otcyrillic: 0x047E,
  26546. Otilde: 0x00D5,
  26547. Otildeacute: 0x1E4C,
  26548. Otildedieresis: 0x1E4E,
  26549. Otildesmall: 0xF7F5,
  26550. P: 0x0050,
  26551. Pacute: 0x1E54,
  26552. Pcircle: 0x24C5,
  26553. Pdotaccent: 0x1E56,
  26554. Pecyrillic: 0x041F,
  26555. Peharmenian: 0x054A,
  26556. Pemiddlehookcyrillic: 0x04A6,
  26557. Phi: 0x03A6,
  26558. Phook: 0x01A4,
  26559. Pi: 0x03A0,
  26560. Piwrarmenian: 0x0553,
  26561. Pmonospace: 0xFF30,
  26562. Psi: 0x03A8,
  26563. Psicyrillic: 0x0470,
  26564. Psmall: 0xF770,
  26565. Q: 0x0051,
  26566. Qcircle: 0x24C6,
  26567. Qmonospace: 0xFF31,
  26568. Qsmall: 0xF771,
  26569. R: 0x0052,
  26570. Raarmenian: 0x054C,
  26571. Racute: 0x0154,
  26572. Rcaron: 0x0158,
  26573. Rcedilla: 0x0156,
  26574. Rcircle: 0x24C7,
  26575. Rcommaaccent: 0x0156,
  26576. Rdblgrave: 0x0210,
  26577. Rdotaccent: 0x1E58,
  26578. Rdotbelow: 0x1E5A,
  26579. Rdotbelowmacron: 0x1E5C,
  26580. Reharmenian: 0x0550,
  26581. Rfraktur: 0x211C,
  26582. Rho: 0x03A1,
  26583. Ringsmall: 0xF6FC,
  26584. Rinvertedbreve: 0x0212,
  26585. Rlinebelow: 0x1E5E,
  26586. Rmonospace: 0xFF32,
  26587. Rsmall: 0xF772,
  26588. Rsmallinverted: 0x0281,
  26589. Rsmallinvertedsuperior: 0x02B6,
  26590. S: 0x0053,
  26591. SF010000: 0x250C,
  26592. SF020000: 0x2514,
  26593. SF030000: 0x2510,
  26594. SF040000: 0x2518,
  26595. SF050000: 0x253C,
  26596. SF060000: 0x252C,
  26597. SF070000: 0x2534,
  26598. SF080000: 0x251C,
  26599. SF090000: 0x2524,
  26600. SF100000: 0x2500,
  26601. SF110000: 0x2502,
  26602. SF190000: 0x2561,
  26603. SF200000: 0x2562,
  26604. SF210000: 0x2556,
  26605. SF220000: 0x2555,
  26606. SF230000: 0x2563,
  26607. SF240000: 0x2551,
  26608. SF250000: 0x2557,
  26609. SF260000: 0x255D,
  26610. SF270000: 0x255C,
  26611. SF280000: 0x255B,
  26612. SF360000: 0x255E,
  26613. SF370000: 0x255F,
  26614. SF380000: 0x255A,
  26615. SF390000: 0x2554,
  26616. SF400000: 0x2569,
  26617. SF410000: 0x2566,
  26618. SF420000: 0x2560,
  26619. SF430000: 0x2550,
  26620. SF440000: 0x256C,
  26621. SF450000: 0x2567,
  26622. SF460000: 0x2568,
  26623. SF470000: 0x2564,
  26624. SF480000: 0x2565,
  26625. SF490000: 0x2559,
  26626. SF500000: 0x2558,
  26627. SF510000: 0x2552,
  26628. SF520000: 0x2553,
  26629. SF530000: 0x256B,
  26630. SF540000: 0x256A,
  26631. Sacute: 0x015A,
  26632. Sacutedotaccent: 0x1E64,
  26633. Sampigreek: 0x03E0,
  26634. Scaron: 0x0160,
  26635. Scarondotaccent: 0x1E66,
  26636. Scaronsmall: 0xF6FD,
  26637. Scedilla: 0x015E,
  26638. Schwa: 0x018F,
  26639. Schwacyrillic: 0x04D8,
  26640. Schwadieresiscyrillic: 0x04DA,
  26641. Scircle: 0x24C8,
  26642. Scircumflex: 0x015C,
  26643. Scommaaccent: 0x0218,
  26644. Sdotaccent: 0x1E60,
  26645. Sdotbelow: 0x1E62,
  26646. Sdotbelowdotaccent: 0x1E68,
  26647. Seharmenian: 0x054D,
  26648. Sevenroman: 0x2166,
  26649. Shaarmenian: 0x0547,
  26650. Shacyrillic: 0x0428,
  26651. Shchacyrillic: 0x0429,
  26652. Sheicoptic: 0x03E2,
  26653. Shhacyrillic: 0x04BA,
  26654. Shimacoptic: 0x03EC,
  26655. Sigma: 0x03A3,
  26656. Sixroman: 0x2165,
  26657. Smonospace: 0xFF33,
  26658. Softsigncyrillic: 0x042C,
  26659. Ssmall: 0xF773,
  26660. Stigmagreek: 0x03DA,
  26661. T: 0x0054,
  26662. Tau: 0x03A4,
  26663. Tbar: 0x0166,
  26664. Tcaron: 0x0164,
  26665. Tcedilla: 0x0162,
  26666. Tcircle: 0x24C9,
  26667. Tcircumflexbelow: 0x1E70,
  26668. Tcommaaccent: 0x0162,
  26669. Tdotaccent: 0x1E6A,
  26670. Tdotbelow: 0x1E6C,
  26671. Tecyrillic: 0x0422,
  26672. Tedescendercyrillic: 0x04AC,
  26673. Tenroman: 0x2169,
  26674. Tetsecyrillic: 0x04B4,
  26675. Theta: 0x0398,
  26676. Thook: 0x01AC,
  26677. Thorn: 0x00DE,
  26678. Thornsmall: 0xF7FE,
  26679. Threeroman: 0x2162,
  26680. Tildesmall: 0xF6FE,
  26681. Tiwnarmenian: 0x054F,
  26682. Tlinebelow: 0x1E6E,
  26683. Tmonospace: 0xFF34,
  26684. Toarmenian: 0x0539,
  26685. Tonefive: 0x01BC,
  26686. Tonesix: 0x0184,
  26687. Tonetwo: 0x01A7,
  26688. Tretroflexhook: 0x01AE,
  26689. Tsecyrillic: 0x0426,
  26690. Tshecyrillic: 0x040B,
  26691. Tsmall: 0xF774,
  26692. Twelveroman: 0x216B,
  26693. Tworoman: 0x2161,
  26694. U: 0x0055,
  26695. Uacute: 0x00DA,
  26696. Uacutesmall: 0xF7FA,
  26697. Ubreve: 0x016C,
  26698. Ucaron: 0x01D3,
  26699. Ucircle: 0x24CA,
  26700. Ucircumflex: 0x00DB,
  26701. Ucircumflexbelow: 0x1E76,
  26702. Ucircumflexsmall: 0xF7FB,
  26703. Ucyrillic: 0x0423,
  26704. Udblacute: 0x0170,
  26705. Udblgrave: 0x0214,
  26706. Udieresis: 0x00DC,
  26707. Udieresisacute: 0x01D7,
  26708. Udieresisbelow: 0x1E72,
  26709. Udieresiscaron: 0x01D9,
  26710. Udieresiscyrillic: 0x04F0,
  26711. Udieresisgrave: 0x01DB,
  26712. Udieresismacron: 0x01D5,
  26713. Udieresissmall: 0xF7FC,
  26714. Udotbelow: 0x1EE4,
  26715. Ugrave: 0x00D9,
  26716. Ugravesmall: 0xF7F9,
  26717. Uhookabove: 0x1EE6,
  26718. Uhorn: 0x01AF,
  26719. Uhornacute: 0x1EE8,
  26720. Uhorndotbelow: 0x1EF0,
  26721. Uhorngrave: 0x1EEA,
  26722. Uhornhookabove: 0x1EEC,
  26723. Uhorntilde: 0x1EEE,
  26724. Uhungarumlaut: 0x0170,
  26725. Uhungarumlautcyrillic: 0x04F2,
  26726. Uinvertedbreve: 0x0216,
  26727. Ukcyrillic: 0x0478,
  26728. Umacron: 0x016A,
  26729. Umacroncyrillic: 0x04EE,
  26730. Umacrondieresis: 0x1E7A,
  26731. Umonospace: 0xFF35,
  26732. Uogonek: 0x0172,
  26733. Upsilon: 0x03A5,
  26734. Upsilon1: 0x03D2,
  26735. Upsilonacutehooksymbolgreek: 0x03D3,
  26736. Upsilonafrican: 0x01B1,
  26737. Upsilondieresis: 0x03AB,
  26738. Upsilondieresishooksymbolgreek: 0x03D4,
  26739. Upsilonhooksymbol: 0x03D2,
  26740. Upsilontonos: 0x038E,
  26741. Uring: 0x016E,
  26742. Ushortcyrillic: 0x040E,
  26743. Usmall: 0xF775,
  26744. Ustraightcyrillic: 0x04AE,
  26745. Ustraightstrokecyrillic: 0x04B0,
  26746. Utilde: 0x0168,
  26747. Utildeacute: 0x1E78,
  26748. Utildebelow: 0x1E74,
  26749. V: 0x0056,
  26750. Vcircle: 0x24CB,
  26751. Vdotbelow: 0x1E7E,
  26752. Vecyrillic: 0x0412,
  26753. Vewarmenian: 0x054E,
  26754. Vhook: 0x01B2,
  26755. Vmonospace: 0xFF36,
  26756. Voarmenian: 0x0548,
  26757. Vsmall: 0xF776,
  26758. Vtilde: 0x1E7C,
  26759. W: 0x0057,
  26760. Wacute: 0x1E82,
  26761. Wcircle: 0x24CC,
  26762. Wcircumflex: 0x0174,
  26763. Wdieresis: 0x1E84,
  26764. Wdotaccent: 0x1E86,
  26765. Wdotbelow: 0x1E88,
  26766. Wgrave: 0x1E80,
  26767. Wmonospace: 0xFF37,
  26768. Wsmall: 0xF777,
  26769. X: 0x0058,
  26770. Xcircle: 0x24CD,
  26771. Xdieresis: 0x1E8C,
  26772. Xdotaccent: 0x1E8A,
  26773. Xeharmenian: 0x053D,
  26774. Xi: 0x039E,
  26775. Xmonospace: 0xFF38,
  26776. Xsmall: 0xF778,
  26777. Y: 0x0059,
  26778. Yacute: 0x00DD,
  26779. Yacutesmall: 0xF7FD,
  26780. Yatcyrillic: 0x0462,
  26781. Ycircle: 0x24CE,
  26782. Ycircumflex: 0x0176,
  26783. Ydieresis: 0x0178,
  26784. Ydieresissmall: 0xF7FF,
  26785. Ydotaccent: 0x1E8E,
  26786. Ydotbelow: 0x1EF4,
  26787. Yericyrillic: 0x042B,
  26788. Yerudieresiscyrillic: 0x04F8,
  26789. Ygrave: 0x1EF2,
  26790. Yhook: 0x01B3,
  26791. Yhookabove: 0x1EF6,
  26792. Yiarmenian: 0x0545,
  26793. Yicyrillic: 0x0407,
  26794. Yiwnarmenian: 0x0552,
  26795. Ymonospace: 0xFF39,
  26796. Ysmall: 0xF779,
  26797. Ytilde: 0x1EF8,
  26798. Yusbigcyrillic: 0x046A,
  26799. Yusbigiotifiedcyrillic: 0x046C,
  26800. Yuslittlecyrillic: 0x0466,
  26801. Yuslittleiotifiedcyrillic: 0x0468,
  26802. Z: 0x005A,
  26803. Zaarmenian: 0x0536,
  26804. Zacute: 0x0179,
  26805. Zcaron: 0x017D,
  26806. Zcaronsmall: 0xF6FF,
  26807. Zcircle: 0x24CF,
  26808. Zcircumflex: 0x1E90,
  26809. Zdot: 0x017B,
  26810. Zdotaccent: 0x017B,
  26811. Zdotbelow: 0x1E92,
  26812. Zecyrillic: 0x0417,
  26813. Zedescendercyrillic: 0x0498,
  26814. Zedieresiscyrillic: 0x04DE,
  26815. Zeta: 0x0396,
  26816. Zhearmenian: 0x053A,
  26817. Zhebrevecyrillic: 0x04C1,
  26818. Zhecyrillic: 0x0416,
  26819. Zhedescendercyrillic: 0x0496,
  26820. Zhedieresiscyrillic: 0x04DC,
  26821. Zlinebelow: 0x1E94,
  26822. Zmonospace: 0xFF3A,
  26823. Zsmall: 0xF77A,
  26824. Zstroke: 0x01B5,
  26825. a: 0x0061,
  26826. aabengali: 0x0986,
  26827. aacute: 0x00E1,
  26828. aadeva: 0x0906,
  26829. aagujarati: 0x0A86,
  26830. aagurmukhi: 0x0A06,
  26831. aamatragurmukhi: 0x0A3E,
  26832. aarusquare: 0x3303,
  26833. aavowelsignbengali: 0x09BE,
  26834. aavowelsigndeva: 0x093E,
  26835. aavowelsigngujarati: 0x0ABE,
  26836. abbreviationmarkarmenian: 0x055F,
  26837. abbreviationsigndeva: 0x0970,
  26838. abengali: 0x0985,
  26839. abopomofo: 0x311A,
  26840. abreve: 0x0103,
  26841. abreveacute: 0x1EAF,
  26842. abrevecyrillic: 0x04D1,
  26843. abrevedotbelow: 0x1EB7,
  26844. abrevegrave: 0x1EB1,
  26845. abrevehookabove: 0x1EB3,
  26846. abrevetilde: 0x1EB5,
  26847. acaron: 0x01CE,
  26848. acircle: 0x24D0,
  26849. acircumflex: 0x00E2,
  26850. acircumflexacute: 0x1EA5,
  26851. acircumflexdotbelow: 0x1EAD,
  26852. acircumflexgrave: 0x1EA7,
  26853. acircumflexhookabove: 0x1EA9,
  26854. acircumflextilde: 0x1EAB,
  26855. acute: 0x00B4,
  26856. acutebelowcmb: 0x0317,
  26857. acutecmb: 0x0301,
  26858. acutecomb: 0x0301,
  26859. acutedeva: 0x0954,
  26860. acutelowmod: 0x02CF,
  26861. acutetonecmb: 0x0341,
  26862. acyrillic: 0x0430,
  26863. adblgrave: 0x0201,
  26864. addakgurmukhi: 0x0A71,
  26865. adeva: 0x0905,
  26866. adieresis: 0x00E4,
  26867. adieresiscyrillic: 0x04D3,
  26868. adieresismacron: 0x01DF,
  26869. adotbelow: 0x1EA1,
  26870. adotmacron: 0x01E1,
  26871. ae: 0x00E6,
  26872. aeacute: 0x01FD,
  26873. aekorean: 0x3150,
  26874. aemacron: 0x01E3,
  26875. afii00208: 0x2015,
  26876. afii08941: 0x20A4,
  26877. afii10017: 0x0410,
  26878. afii10018: 0x0411,
  26879. afii10019: 0x0412,
  26880. afii10020: 0x0413,
  26881. afii10021: 0x0414,
  26882. afii10022: 0x0415,
  26883. afii10023: 0x0401,
  26884. afii10024: 0x0416,
  26885. afii10025: 0x0417,
  26886. afii10026: 0x0418,
  26887. afii10027: 0x0419,
  26888. afii10028: 0x041A,
  26889. afii10029: 0x041B,
  26890. afii10030: 0x041C,
  26891. afii10031: 0x041D,
  26892. afii10032: 0x041E,
  26893. afii10033: 0x041F,
  26894. afii10034: 0x0420,
  26895. afii10035: 0x0421,
  26896. afii10036: 0x0422,
  26897. afii10037: 0x0423,
  26898. afii10038: 0x0424,
  26899. afii10039: 0x0425,
  26900. afii10040: 0x0426,
  26901. afii10041: 0x0427,
  26902. afii10042: 0x0428,
  26903. afii10043: 0x0429,
  26904. afii10044: 0x042A,
  26905. afii10045: 0x042B,
  26906. afii10046: 0x042C,
  26907. afii10047: 0x042D,
  26908. afii10048: 0x042E,
  26909. afii10049: 0x042F,
  26910. afii10050: 0x0490,
  26911. afii10051: 0x0402,
  26912. afii10052: 0x0403,
  26913. afii10053: 0x0404,
  26914. afii10054: 0x0405,
  26915. afii10055: 0x0406,
  26916. afii10056: 0x0407,
  26917. afii10057: 0x0408,
  26918. afii10058: 0x0409,
  26919. afii10059: 0x040A,
  26920. afii10060: 0x040B,
  26921. afii10061: 0x040C,
  26922. afii10062: 0x040E,
  26923. afii10063: 0xF6C4,
  26924. afii10064: 0xF6C5,
  26925. afii10065: 0x0430,
  26926. afii10066: 0x0431,
  26927. afii10067: 0x0432,
  26928. afii10068: 0x0433,
  26929. afii10069: 0x0434,
  26930. afii10070: 0x0435,
  26931. afii10071: 0x0451,
  26932. afii10072: 0x0436,
  26933. afii10073: 0x0437,
  26934. afii10074: 0x0438,
  26935. afii10075: 0x0439,
  26936. afii10076: 0x043A,
  26937. afii10077: 0x043B,
  26938. afii10078: 0x043C,
  26939. afii10079: 0x043D,
  26940. afii10080: 0x043E,
  26941. afii10081: 0x043F,
  26942. afii10082: 0x0440,
  26943. afii10083: 0x0441,
  26944. afii10084: 0x0442,
  26945. afii10085: 0x0443,
  26946. afii10086: 0x0444,
  26947. afii10087: 0x0445,
  26948. afii10088: 0x0446,
  26949. afii10089: 0x0447,
  26950. afii10090: 0x0448,
  26951. afii10091: 0x0449,
  26952. afii10092: 0x044A,
  26953. afii10093: 0x044B,
  26954. afii10094: 0x044C,
  26955. afii10095: 0x044D,
  26956. afii10096: 0x044E,
  26957. afii10097: 0x044F,
  26958. afii10098: 0x0491,
  26959. afii10099: 0x0452,
  26960. afii10100: 0x0453,
  26961. afii10101: 0x0454,
  26962. afii10102: 0x0455,
  26963. afii10103: 0x0456,
  26964. afii10104: 0x0457,
  26965. afii10105: 0x0458,
  26966. afii10106: 0x0459,
  26967. afii10107: 0x045A,
  26968. afii10108: 0x045B,
  26969. afii10109: 0x045C,
  26970. afii10110: 0x045E,
  26971. afii10145: 0x040F,
  26972. afii10146: 0x0462,
  26973. afii10147: 0x0472,
  26974. afii10148: 0x0474,
  26975. afii10192: 0xF6C6,
  26976. afii10193: 0x045F,
  26977. afii10194: 0x0463,
  26978. afii10195: 0x0473,
  26979. afii10196: 0x0475,
  26980. afii10831: 0xF6C7,
  26981. afii10832: 0xF6C8,
  26982. afii10846: 0x04D9,
  26983. afii299: 0x200E,
  26984. afii300: 0x200F,
  26985. afii301: 0x200D,
  26986. afii57381: 0x066A,
  26987. afii57388: 0x060C,
  26988. afii57392: 0x0660,
  26989. afii57393: 0x0661,
  26990. afii57394: 0x0662,
  26991. afii57395: 0x0663,
  26992. afii57396: 0x0664,
  26993. afii57397: 0x0665,
  26994. afii57398: 0x0666,
  26995. afii57399: 0x0667,
  26996. afii57400: 0x0668,
  26997. afii57401: 0x0669,
  26998. afii57403: 0x061B,
  26999. afii57407: 0x061F,
  27000. afii57409: 0x0621,
  27001. afii57410: 0x0622,
  27002. afii57411: 0x0623,
  27003. afii57412: 0x0624,
  27004. afii57413: 0x0625,
  27005. afii57414: 0x0626,
  27006. afii57415: 0x0627,
  27007. afii57416: 0x0628,
  27008. afii57417: 0x0629,
  27009. afii57418: 0x062A,
  27010. afii57419: 0x062B,
  27011. afii57420: 0x062C,
  27012. afii57421: 0x062D,
  27013. afii57422: 0x062E,
  27014. afii57423: 0x062F,
  27015. afii57424: 0x0630,
  27016. afii57425: 0x0631,
  27017. afii57426: 0x0632,
  27018. afii57427: 0x0633,
  27019. afii57428: 0x0634,
  27020. afii57429: 0x0635,
  27021. afii57430: 0x0636,
  27022. afii57431: 0x0637,
  27023. afii57432: 0x0638,
  27024. afii57433: 0x0639,
  27025. afii57434: 0x063A,
  27026. afii57440: 0x0640,
  27027. afii57441: 0x0641,
  27028. afii57442: 0x0642,
  27029. afii57443: 0x0643,
  27030. afii57444: 0x0644,
  27031. afii57445: 0x0645,
  27032. afii57446: 0x0646,
  27033. afii57448: 0x0648,
  27034. afii57449: 0x0649,
  27035. afii57450: 0x064A,
  27036. afii57451: 0x064B,
  27037. afii57452: 0x064C,
  27038. afii57453: 0x064D,
  27039. afii57454: 0x064E,
  27040. afii57455: 0x064F,
  27041. afii57456: 0x0650,
  27042. afii57457: 0x0651,
  27043. afii57458: 0x0652,
  27044. afii57470: 0x0647,
  27045. afii57505: 0x06A4,
  27046. afii57506: 0x067E,
  27047. afii57507: 0x0686,
  27048. afii57508: 0x0698,
  27049. afii57509: 0x06AF,
  27050. afii57511: 0x0679,
  27051. afii57512: 0x0688,
  27052. afii57513: 0x0691,
  27053. afii57514: 0x06BA,
  27054. afii57519: 0x06D2,
  27055. afii57534: 0x06D5,
  27056. afii57636: 0x20AA,
  27057. afii57645: 0x05BE,
  27058. afii57658: 0x05C3,
  27059. afii57664: 0x05D0,
  27060. afii57665: 0x05D1,
  27061. afii57666: 0x05D2,
  27062. afii57667: 0x05D3,
  27063. afii57668: 0x05D4,
  27064. afii57669: 0x05D5,
  27065. afii57670: 0x05D6,
  27066. afii57671: 0x05D7,
  27067. afii57672: 0x05D8,
  27068. afii57673: 0x05D9,
  27069. afii57674: 0x05DA,
  27070. afii57675: 0x05DB,
  27071. afii57676: 0x05DC,
  27072. afii57677: 0x05DD,
  27073. afii57678: 0x05DE,
  27074. afii57679: 0x05DF,
  27075. afii57680: 0x05E0,
  27076. afii57681: 0x05E1,
  27077. afii57682: 0x05E2,
  27078. afii57683: 0x05E3,
  27079. afii57684: 0x05E4,
  27080. afii57685: 0x05E5,
  27081. afii57686: 0x05E6,
  27082. afii57687: 0x05E7,
  27083. afii57688: 0x05E8,
  27084. afii57689: 0x05E9,
  27085. afii57690: 0x05EA,
  27086. afii57694: 0xFB2A,
  27087. afii57695: 0xFB2B,
  27088. afii57700: 0xFB4B,
  27089. afii57705: 0xFB1F,
  27090. afii57716: 0x05F0,
  27091. afii57717: 0x05F1,
  27092. afii57718: 0x05F2,
  27093. afii57723: 0xFB35,
  27094. afii57793: 0x05B4,
  27095. afii57794: 0x05B5,
  27096. afii57795: 0x05B6,
  27097. afii57796: 0x05BB,
  27098. afii57797: 0x05B8,
  27099. afii57798: 0x05B7,
  27100. afii57799: 0x05B0,
  27101. afii57800: 0x05B2,
  27102. afii57801: 0x05B1,
  27103. afii57802: 0x05B3,
  27104. afii57803: 0x05C2,
  27105. afii57804: 0x05C1,
  27106. afii57806: 0x05B9,
  27107. afii57807: 0x05BC,
  27108. afii57839: 0x05BD,
  27109. afii57841: 0x05BF,
  27110. afii57842: 0x05C0,
  27111. afii57929: 0x02BC,
  27112. afii61248: 0x2105,
  27113. afii61289: 0x2113,
  27114. afii61352: 0x2116,
  27115. afii61573: 0x202C,
  27116. afii61574: 0x202D,
  27117. afii61575: 0x202E,
  27118. afii61664: 0x200C,
  27119. afii63167: 0x066D,
  27120. afii64937: 0x02BD,
  27121. agrave: 0x00E0,
  27122. agujarati: 0x0A85,
  27123. agurmukhi: 0x0A05,
  27124. ahiragana: 0x3042,
  27125. ahookabove: 0x1EA3,
  27126. aibengali: 0x0990,
  27127. aibopomofo: 0x311E,
  27128. aideva: 0x0910,
  27129. aiecyrillic: 0x04D5,
  27130. aigujarati: 0x0A90,
  27131. aigurmukhi: 0x0A10,
  27132. aimatragurmukhi: 0x0A48,
  27133. ainarabic: 0x0639,
  27134. ainfinalarabic: 0xFECA,
  27135. aininitialarabic: 0xFECB,
  27136. ainmedialarabic: 0xFECC,
  27137. ainvertedbreve: 0x0203,
  27138. aivowelsignbengali: 0x09C8,
  27139. aivowelsigndeva: 0x0948,
  27140. aivowelsigngujarati: 0x0AC8,
  27141. akatakana: 0x30A2,
  27142. akatakanahalfwidth: 0xFF71,
  27143. akorean: 0x314F,
  27144. alef: 0x05D0,
  27145. alefarabic: 0x0627,
  27146. alefdageshhebrew: 0xFB30,
  27147. aleffinalarabic: 0xFE8E,
  27148. alefhamzaabovearabic: 0x0623,
  27149. alefhamzaabovefinalarabic: 0xFE84,
  27150. alefhamzabelowarabic: 0x0625,
  27151. alefhamzabelowfinalarabic: 0xFE88,
  27152. alefhebrew: 0x05D0,
  27153. aleflamedhebrew: 0xFB4F,
  27154. alefmaddaabovearabic: 0x0622,
  27155. alefmaddaabovefinalarabic: 0xFE82,
  27156. alefmaksuraarabic: 0x0649,
  27157. alefmaksurafinalarabic: 0xFEF0,
  27158. alefmaksurainitialarabic: 0xFEF3,
  27159. alefmaksuramedialarabic: 0xFEF4,
  27160. alefpatahhebrew: 0xFB2E,
  27161. alefqamatshebrew: 0xFB2F,
  27162. aleph: 0x2135,
  27163. allequal: 0x224C,
  27164. alpha: 0x03B1,
  27165. alphatonos: 0x03AC,
  27166. amacron: 0x0101,
  27167. amonospace: 0xFF41,
  27168. ampersand: 0x0026,
  27169. ampersandmonospace: 0xFF06,
  27170. ampersandsmall: 0xF726,
  27171. amsquare: 0x33C2,
  27172. anbopomofo: 0x3122,
  27173. angbopomofo: 0x3124,
  27174. angbracketleft: 0x3008, // This glyph is missing from Adobe's original list.
  27175. angbracketright: 0x3009, // This glyph is missing from Adobe's original list.
  27176. angkhankhuthai: 0x0E5A,
  27177. angle: 0x2220,
  27178. anglebracketleft: 0x3008,
  27179. anglebracketleftvertical: 0xFE3F,
  27180. anglebracketright: 0x3009,
  27181. anglebracketrightvertical: 0xFE40,
  27182. angleleft: 0x2329,
  27183. angleright: 0x232A,
  27184. angstrom: 0x212B,
  27185. anoteleia: 0x0387,
  27186. anudattadeva: 0x0952,
  27187. anusvarabengali: 0x0982,
  27188. anusvaradeva: 0x0902,
  27189. anusvaragujarati: 0x0A82,
  27190. aogonek: 0x0105,
  27191. apaatosquare: 0x3300,
  27192. aparen: 0x249C,
  27193. apostrophearmenian: 0x055A,
  27194. apostrophemod: 0x02BC,
  27195. apple: 0xF8FF,
  27196. approaches: 0x2250,
  27197. approxequal: 0x2248,
  27198. approxequalorimage: 0x2252,
  27199. approximatelyequal: 0x2245,
  27200. araeaekorean: 0x318E,
  27201. araeakorean: 0x318D,
  27202. arc: 0x2312,
  27203. arighthalfring: 0x1E9A,
  27204. aring: 0x00E5,
  27205. aringacute: 0x01FB,
  27206. aringbelow: 0x1E01,
  27207. arrowboth: 0x2194,
  27208. arrowdashdown: 0x21E3,
  27209. arrowdashleft: 0x21E0,
  27210. arrowdashright: 0x21E2,
  27211. arrowdashup: 0x21E1,
  27212. arrowdblboth: 0x21D4,
  27213. arrowdbldown: 0x21D3,
  27214. arrowdblleft: 0x21D0,
  27215. arrowdblright: 0x21D2,
  27216. arrowdblup: 0x21D1,
  27217. arrowdown: 0x2193,
  27218. arrowdownleft: 0x2199,
  27219. arrowdownright: 0x2198,
  27220. arrowdownwhite: 0x21E9,
  27221. arrowheaddownmod: 0x02C5,
  27222. arrowheadleftmod: 0x02C2,
  27223. arrowheadrightmod: 0x02C3,
  27224. arrowheadupmod: 0x02C4,
  27225. arrowhorizex: 0xF8E7,
  27226. arrowleft: 0x2190,
  27227. arrowleftdbl: 0x21D0,
  27228. arrowleftdblstroke: 0x21CD,
  27229. arrowleftoverright: 0x21C6,
  27230. arrowleftwhite: 0x21E6,
  27231. arrowright: 0x2192,
  27232. arrowrightdblstroke: 0x21CF,
  27233. arrowrightheavy: 0x279E,
  27234. arrowrightoverleft: 0x21C4,
  27235. arrowrightwhite: 0x21E8,
  27236. arrowtableft: 0x21E4,
  27237. arrowtabright: 0x21E5,
  27238. arrowup: 0x2191,
  27239. arrowupdn: 0x2195,
  27240. arrowupdnbse: 0x21A8,
  27241. arrowupdownbase: 0x21A8,
  27242. arrowupleft: 0x2196,
  27243. arrowupleftofdown: 0x21C5,
  27244. arrowupright: 0x2197,
  27245. arrowupwhite: 0x21E7,
  27246. arrowvertex: 0xF8E6,
  27247. asciicircum: 0x005E,
  27248. asciicircummonospace: 0xFF3E,
  27249. asciitilde: 0x007E,
  27250. asciitildemonospace: 0xFF5E,
  27251. ascript: 0x0251,
  27252. ascriptturned: 0x0252,
  27253. asmallhiragana: 0x3041,
  27254. asmallkatakana: 0x30A1,
  27255. asmallkatakanahalfwidth: 0xFF67,
  27256. asterisk: 0x002A,
  27257. asteriskaltonearabic: 0x066D,
  27258. asteriskarabic: 0x066D,
  27259. asteriskmath: 0x2217,
  27260. asteriskmonospace: 0xFF0A,
  27261. asterisksmall: 0xFE61,
  27262. asterism: 0x2042,
  27263. asuperior: 0xF6E9,
  27264. asymptoticallyequal: 0x2243,
  27265. at: 0x0040,
  27266. atilde: 0x00E3,
  27267. atmonospace: 0xFF20,
  27268. atsmall: 0xFE6B,
  27269. aturned: 0x0250,
  27270. aubengali: 0x0994,
  27271. aubopomofo: 0x3120,
  27272. audeva: 0x0914,
  27273. augujarati: 0x0A94,
  27274. augurmukhi: 0x0A14,
  27275. aulengthmarkbengali: 0x09D7,
  27276. aumatragurmukhi: 0x0A4C,
  27277. auvowelsignbengali: 0x09CC,
  27278. auvowelsigndeva: 0x094C,
  27279. auvowelsigngujarati: 0x0ACC,
  27280. avagrahadeva: 0x093D,
  27281. aybarmenian: 0x0561,
  27282. ayin: 0x05E2,
  27283. ayinaltonehebrew: 0xFB20,
  27284. ayinhebrew: 0x05E2,
  27285. b: 0x0062,
  27286. babengali: 0x09AC,
  27287. backslash: 0x005C,
  27288. backslashmonospace: 0xFF3C,
  27289. badeva: 0x092C,
  27290. bagujarati: 0x0AAC,
  27291. bagurmukhi: 0x0A2C,
  27292. bahiragana: 0x3070,
  27293. bahtthai: 0x0E3F,
  27294. bakatakana: 0x30D0,
  27295. bar: 0x007C,
  27296. barmonospace: 0xFF5C,
  27297. bbopomofo: 0x3105,
  27298. bcircle: 0x24D1,
  27299. bdotaccent: 0x1E03,
  27300. bdotbelow: 0x1E05,
  27301. beamedsixteenthnotes: 0x266C,
  27302. because: 0x2235,
  27303. becyrillic: 0x0431,
  27304. beharabic: 0x0628,
  27305. behfinalarabic: 0xFE90,
  27306. behinitialarabic: 0xFE91,
  27307. behiragana: 0x3079,
  27308. behmedialarabic: 0xFE92,
  27309. behmeeminitialarabic: 0xFC9F,
  27310. behmeemisolatedarabic: 0xFC08,
  27311. behnoonfinalarabic: 0xFC6D,
  27312. bekatakana: 0x30D9,
  27313. benarmenian: 0x0562,
  27314. bet: 0x05D1,
  27315. beta: 0x03B2,
  27316. betasymbolgreek: 0x03D0,
  27317. betdagesh: 0xFB31,
  27318. betdageshhebrew: 0xFB31,
  27319. bethebrew: 0x05D1,
  27320. betrafehebrew: 0xFB4C,
  27321. bhabengali: 0x09AD,
  27322. bhadeva: 0x092D,
  27323. bhagujarati: 0x0AAD,
  27324. bhagurmukhi: 0x0A2D,
  27325. bhook: 0x0253,
  27326. bihiragana: 0x3073,
  27327. bikatakana: 0x30D3,
  27328. bilabialclick: 0x0298,
  27329. bindigurmukhi: 0x0A02,
  27330. birusquare: 0x3331,
  27331. blackcircle: 0x25CF,
  27332. blackdiamond: 0x25C6,
  27333. blackdownpointingtriangle: 0x25BC,
  27334. blackleftpointingpointer: 0x25C4,
  27335. blackleftpointingtriangle: 0x25C0,
  27336. blacklenticularbracketleft: 0x3010,
  27337. blacklenticularbracketleftvertical: 0xFE3B,
  27338. blacklenticularbracketright: 0x3011,
  27339. blacklenticularbracketrightvertical: 0xFE3C,
  27340. blacklowerlefttriangle: 0x25E3,
  27341. blacklowerrighttriangle: 0x25E2,
  27342. blackrectangle: 0x25AC,
  27343. blackrightpointingpointer: 0x25BA,
  27344. blackrightpointingtriangle: 0x25B6,
  27345. blacksmallsquare: 0x25AA,
  27346. blacksmilingface: 0x263B,
  27347. blacksquare: 0x25A0,
  27348. blackstar: 0x2605,
  27349. blackupperlefttriangle: 0x25E4,
  27350. blackupperrighttriangle: 0x25E5,
  27351. blackuppointingsmalltriangle: 0x25B4,
  27352. blackuppointingtriangle: 0x25B2,
  27353. blank: 0x2423,
  27354. blinebelow: 0x1E07,
  27355. block: 0x2588,
  27356. bmonospace: 0xFF42,
  27357. bobaimaithai: 0x0E1A,
  27358. bohiragana: 0x307C,
  27359. bokatakana: 0x30DC,
  27360. bparen: 0x249D,
  27361. bqsquare: 0x33C3,
  27362. braceex: 0xF8F4,
  27363. braceleft: 0x007B,
  27364. braceleftbt: 0xF8F3,
  27365. braceleftmid: 0xF8F2,
  27366. braceleftmonospace: 0xFF5B,
  27367. braceleftsmall: 0xFE5B,
  27368. bracelefttp: 0xF8F1,
  27369. braceleftvertical: 0xFE37,
  27370. braceright: 0x007D,
  27371. bracerightbt: 0xF8FE,
  27372. bracerightmid: 0xF8FD,
  27373. bracerightmonospace: 0xFF5D,
  27374. bracerightsmall: 0xFE5C,
  27375. bracerighttp: 0xF8FC,
  27376. bracerightvertical: 0xFE38,
  27377. bracketleft: 0x005B,
  27378. bracketleftbt: 0xF8F0,
  27379. bracketleftex: 0xF8EF,
  27380. bracketleftmonospace: 0xFF3B,
  27381. bracketlefttp: 0xF8EE,
  27382. bracketright: 0x005D,
  27383. bracketrightbt: 0xF8FB,
  27384. bracketrightex: 0xF8FA,
  27385. bracketrightmonospace: 0xFF3D,
  27386. bracketrighttp: 0xF8F9,
  27387. breve: 0x02D8,
  27388. brevebelowcmb: 0x032E,
  27389. brevecmb: 0x0306,
  27390. breveinvertedbelowcmb: 0x032F,
  27391. breveinvertedcmb: 0x0311,
  27392. breveinverteddoublecmb: 0x0361,
  27393. bridgebelowcmb: 0x032A,
  27394. bridgeinvertedbelowcmb: 0x033A,
  27395. brokenbar: 0x00A6,
  27396. bstroke: 0x0180,
  27397. bsuperior: 0xF6EA,
  27398. btopbar: 0x0183,
  27399. buhiragana: 0x3076,
  27400. bukatakana: 0x30D6,
  27401. bullet: 0x2022,
  27402. bulletinverse: 0x25D8,
  27403. bulletoperator: 0x2219,
  27404. bullseye: 0x25CE,
  27405. c: 0x0063,
  27406. caarmenian: 0x056E,
  27407. cabengali: 0x099A,
  27408. cacute: 0x0107,
  27409. cadeva: 0x091A,
  27410. cagujarati: 0x0A9A,
  27411. cagurmukhi: 0x0A1A,
  27412. calsquare: 0x3388,
  27413. candrabindubengali: 0x0981,
  27414. candrabinducmb: 0x0310,
  27415. candrabindudeva: 0x0901,
  27416. candrabindugujarati: 0x0A81,
  27417. capslock: 0x21EA,
  27418. careof: 0x2105,
  27419. caron: 0x02C7,
  27420. caronbelowcmb: 0x032C,
  27421. caroncmb: 0x030C,
  27422. carriagereturn: 0x21B5,
  27423. cbopomofo: 0x3118,
  27424. ccaron: 0x010D,
  27425. ccedilla: 0x00E7,
  27426. ccedillaacute: 0x1E09,
  27427. ccircle: 0x24D2,
  27428. ccircumflex: 0x0109,
  27429. ccurl: 0x0255,
  27430. cdot: 0x010B,
  27431. cdotaccent: 0x010B,
  27432. cdsquare: 0x33C5,
  27433. cedilla: 0x00B8,
  27434. cedillacmb: 0x0327,
  27435. cent: 0x00A2,
  27436. centigrade: 0x2103,
  27437. centinferior: 0xF6DF,
  27438. centmonospace: 0xFFE0,
  27439. centoldstyle: 0xF7A2,
  27440. centsuperior: 0xF6E0,
  27441. chaarmenian: 0x0579,
  27442. chabengali: 0x099B,
  27443. chadeva: 0x091B,
  27444. chagujarati: 0x0A9B,
  27445. chagurmukhi: 0x0A1B,
  27446. chbopomofo: 0x3114,
  27447. cheabkhasiancyrillic: 0x04BD,
  27448. checkmark: 0x2713,
  27449. checyrillic: 0x0447,
  27450. chedescenderabkhasiancyrillic: 0x04BF,
  27451. chedescendercyrillic: 0x04B7,
  27452. chedieresiscyrillic: 0x04F5,
  27453. cheharmenian: 0x0573,
  27454. chekhakassiancyrillic: 0x04CC,
  27455. cheverticalstrokecyrillic: 0x04B9,
  27456. chi: 0x03C7,
  27457. chieuchacirclekorean: 0x3277,
  27458. chieuchaparenkorean: 0x3217,
  27459. chieuchcirclekorean: 0x3269,
  27460. chieuchkorean: 0x314A,
  27461. chieuchparenkorean: 0x3209,
  27462. chochangthai: 0x0E0A,
  27463. chochanthai: 0x0E08,
  27464. chochingthai: 0x0E09,
  27465. chochoethai: 0x0E0C,
  27466. chook: 0x0188,
  27467. cieucacirclekorean: 0x3276,
  27468. cieucaparenkorean: 0x3216,
  27469. cieuccirclekorean: 0x3268,
  27470. cieuckorean: 0x3148,
  27471. cieucparenkorean: 0x3208,
  27472. cieucuparenkorean: 0x321C,
  27473. circle: 0x25CB,
  27474. circlecopyrt: 0x00A9, // This glyph is missing from Adobe's original list.
  27475. circlemultiply: 0x2297,
  27476. circleot: 0x2299,
  27477. circleplus: 0x2295,
  27478. circlepostalmark: 0x3036,
  27479. circlewithlefthalfblack: 0x25D0,
  27480. circlewithrighthalfblack: 0x25D1,
  27481. circumflex: 0x02C6,
  27482. circumflexbelowcmb: 0x032D,
  27483. circumflexcmb: 0x0302,
  27484. clear: 0x2327,
  27485. clickalveolar: 0x01C2,
  27486. clickdental: 0x01C0,
  27487. clicklateral: 0x01C1,
  27488. clickretroflex: 0x01C3,
  27489. club: 0x2663,
  27490. clubsuitblack: 0x2663,
  27491. clubsuitwhite: 0x2667,
  27492. cmcubedsquare: 0x33A4,
  27493. cmonospace: 0xFF43,
  27494. cmsquaredsquare: 0x33A0,
  27495. coarmenian: 0x0581,
  27496. colon: 0x003A,
  27497. colonmonetary: 0x20A1,
  27498. colonmonospace: 0xFF1A,
  27499. colonsign: 0x20A1,
  27500. colonsmall: 0xFE55,
  27501. colontriangularhalfmod: 0x02D1,
  27502. colontriangularmod: 0x02D0,
  27503. comma: 0x002C,
  27504. commaabovecmb: 0x0313,
  27505. commaaboverightcmb: 0x0315,
  27506. commaaccent: 0xF6C3,
  27507. commaarabic: 0x060C,
  27508. commaarmenian: 0x055D,
  27509. commainferior: 0xF6E1,
  27510. commamonospace: 0xFF0C,
  27511. commareversedabovecmb: 0x0314,
  27512. commareversedmod: 0x02BD,
  27513. commasmall: 0xFE50,
  27514. commasuperior: 0xF6E2,
  27515. commaturnedabovecmb: 0x0312,
  27516. commaturnedmod: 0x02BB,
  27517. compass: 0x263C,
  27518. congruent: 0x2245,
  27519. contourintegral: 0x222E,
  27520. control: 0x2303,
  27521. controlACK: 0x0006,
  27522. controlBEL: 0x0007,
  27523. controlBS: 0x0008,
  27524. controlCAN: 0x0018,
  27525. controlCR: 0x000D,
  27526. controlDC1: 0x0011,
  27527. controlDC2: 0x0012,
  27528. controlDC3: 0x0013,
  27529. controlDC4: 0x0014,
  27530. controlDEL: 0x007F,
  27531. controlDLE: 0x0010,
  27532. controlEM: 0x0019,
  27533. controlENQ: 0x0005,
  27534. controlEOT: 0x0004,
  27535. controlESC: 0x001B,
  27536. controlETB: 0x0017,
  27537. controlETX: 0x0003,
  27538. controlFF: 0x000C,
  27539. controlFS: 0x001C,
  27540. controlGS: 0x001D,
  27541. controlHT: 0x0009,
  27542. controlLF: 0x000A,
  27543. controlNAK: 0x0015,
  27544. controlRS: 0x001E,
  27545. controlSI: 0x000F,
  27546. controlSO: 0x000E,
  27547. controlSOT: 0x0002,
  27548. controlSTX: 0x0001,
  27549. controlSUB: 0x001A,
  27550. controlSYN: 0x0016,
  27551. controlUS: 0x001F,
  27552. controlVT: 0x000B,
  27553. copyright: 0x00A9,
  27554. copyrightsans: 0xF8E9,
  27555. copyrightserif: 0xF6D9,
  27556. cornerbracketleft: 0x300C,
  27557. cornerbracketlefthalfwidth: 0xFF62,
  27558. cornerbracketleftvertical: 0xFE41,
  27559. cornerbracketright: 0x300D,
  27560. cornerbracketrighthalfwidth: 0xFF63,
  27561. cornerbracketrightvertical: 0xFE42,
  27562. corporationsquare: 0x337F,
  27563. cosquare: 0x33C7,
  27564. coverkgsquare: 0x33C6,
  27565. cparen: 0x249E,
  27566. cruzeiro: 0x20A2,
  27567. cstretched: 0x0297,
  27568. curlyand: 0x22CF,
  27569. curlyor: 0x22CE,
  27570. currency: 0x00A4,
  27571. cyrBreve: 0xF6D1,
  27572. cyrFlex: 0xF6D2,
  27573. cyrbreve: 0xF6D4,
  27574. cyrflex: 0xF6D5,
  27575. d: 0x0064,
  27576. daarmenian: 0x0564,
  27577. dabengali: 0x09A6,
  27578. dadarabic: 0x0636,
  27579. dadeva: 0x0926,
  27580. dadfinalarabic: 0xFEBE,
  27581. dadinitialarabic: 0xFEBF,
  27582. dadmedialarabic: 0xFEC0,
  27583. dagesh: 0x05BC,
  27584. dageshhebrew: 0x05BC,
  27585. dagger: 0x2020,
  27586. daggerdbl: 0x2021,
  27587. dagujarati: 0x0AA6,
  27588. dagurmukhi: 0x0A26,
  27589. dahiragana: 0x3060,
  27590. dakatakana: 0x30C0,
  27591. dalarabic: 0x062F,
  27592. dalet: 0x05D3,
  27593. daletdagesh: 0xFB33,
  27594. daletdageshhebrew: 0xFB33,
  27595. dalethebrew: 0x05D3,
  27596. dalfinalarabic: 0xFEAA,
  27597. dammaarabic: 0x064F,
  27598. dammalowarabic: 0x064F,
  27599. dammatanaltonearabic: 0x064C,
  27600. dammatanarabic: 0x064C,
  27601. danda: 0x0964,
  27602. dargahebrew: 0x05A7,
  27603. dargalefthebrew: 0x05A7,
  27604. dasiapneumatacyrilliccmb: 0x0485,
  27605. dblGrave: 0xF6D3,
  27606. dblanglebracketleft: 0x300A,
  27607. dblanglebracketleftvertical: 0xFE3D,
  27608. dblanglebracketright: 0x300B,
  27609. dblanglebracketrightvertical: 0xFE3E,
  27610. dblarchinvertedbelowcmb: 0x032B,
  27611. dblarrowleft: 0x21D4,
  27612. dblarrowright: 0x21D2,
  27613. dbldanda: 0x0965,
  27614. dblgrave: 0xF6D6,
  27615. dblgravecmb: 0x030F,
  27616. dblintegral: 0x222C,
  27617. dbllowline: 0x2017,
  27618. dbllowlinecmb: 0x0333,
  27619. dbloverlinecmb: 0x033F,
  27620. dblprimemod: 0x02BA,
  27621. dblverticalbar: 0x2016,
  27622. dblverticallineabovecmb: 0x030E,
  27623. dbopomofo: 0x3109,
  27624. dbsquare: 0x33C8,
  27625. dcaron: 0x010F,
  27626. dcedilla: 0x1E11,
  27627. dcircle: 0x24D3,
  27628. dcircumflexbelow: 0x1E13,
  27629. dcroat: 0x0111,
  27630. ddabengali: 0x09A1,
  27631. ddadeva: 0x0921,
  27632. ddagujarati: 0x0AA1,
  27633. ddagurmukhi: 0x0A21,
  27634. ddalarabic: 0x0688,
  27635. ddalfinalarabic: 0xFB89,
  27636. dddhadeva: 0x095C,
  27637. ddhabengali: 0x09A2,
  27638. ddhadeva: 0x0922,
  27639. ddhagujarati: 0x0AA2,
  27640. ddhagurmukhi: 0x0A22,
  27641. ddotaccent: 0x1E0B,
  27642. ddotbelow: 0x1E0D,
  27643. decimalseparatorarabic: 0x066B,
  27644. decimalseparatorpersian: 0x066B,
  27645. decyrillic: 0x0434,
  27646. degree: 0x00B0,
  27647. dehihebrew: 0x05AD,
  27648. dehiragana: 0x3067,
  27649. deicoptic: 0x03EF,
  27650. dekatakana: 0x30C7,
  27651. deleteleft: 0x232B,
  27652. deleteright: 0x2326,
  27653. delta: 0x03B4,
  27654. deltaturned: 0x018D,
  27655. denominatorminusonenumeratorbengali: 0x09F8,
  27656. dezh: 0x02A4,
  27657. dhabengali: 0x09A7,
  27658. dhadeva: 0x0927,
  27659. dhagujarati: 0x0AA7,
  27660. dhagurmukhi: 0x0A27,
  27661. dhook: 0x0257,
  27662. dialytikatonos: 0x0385,
  27663. dialytikatonoscmb: 0x0344,
  27664. diamond: 0x2666,
  27665. diamondsuitwhite: 0x2662,
  27666. dieresis: 0x00A8,
  27667. dieresisacute: 0xF6D7,
  27668. dieresisbelowcmb: 0x0324,
  27669. dieresiscmb: 0x0308,
  27670. dieresisgrave: 0xF6D8,
  27671. dieresistonos: 0x0385,
  27672. dihiragana: 0x3062,
  27673. dikatakana: 0x30C2,
  27674. dittomark: 0x3003,
  27675. divide: 0x00F7,
  27676. divides: 0x2223,
  27677. divisionslash: 0x2215,
  27678. djecyrillic: 0x0452,
  27679. dkshade: 0x2593,
  27680. dlinebelow: 0x1E0F,
  27681. dlsquare: 0x3397,
  27682. dmacron: 0x0111,
  27683. dmonospace: 0xFF44,
  27684. dnblock: 0x2584,
  27685. dochadathai: 0x0E0E,
  27686. dodekthai: 0x0E14,
  27687. dohiragana: 0x3069,
  27688. dokatakana: 0x30C9,
  27689. dollar: 0x0024,
  27690. dollarinferior: 0xF6E3,
  27691. dollarmonospace: 0xFF04,
  27692. dollaroldstyle: 0xF724,
  27693. dollarsmall: 0xFE69,
  27694. dollarsuperior: 0xF6E4,
  27695. dong: 0x20AB,
  27696. dorusquare: 0x3326,
  27697. dotaccent: 0x02D9,
  27698. dotaccentcmb: 0x0307,
  27699. dotbelowcmb: 0x0323,
  27700. dotbelowcomb: 0x0323,
  27701. dotkatakana: 0x30FB,
  27702. dotlessi: 0x0131,
  27703. dotlessj: 0xF6BE,
  27704. dotlessjstrokehook: 0x0284,
  27705. dotmath: 0x22C5,
  27706. dottedcircle: 0x25CC,
  27707. doubleyodpatah: 0xFB1F,
  27708. doubleyodpatahhebrew: 0xFB1F,
  27709. downtackbelowcmb: 0x031E,
  27710. downtackmod: 0x02D5,
  27711. dparen: 0x249F,
  27712. dsuperior: 0xF6EB,
  27713. dtail: 0x0256,
  27714. dtopbar: 0x018C,
  27715. duhiragana: 0x3065,
  27716. dukatakana: 0x30C5,
  27717. dz: 0x01F3,
  27718. dzaltone: 0x02A3,
  27719. dzcaron: 0x01C6,
  27720. dzcurl: 0x02A5,
  27721. dzeabkhasiancyrillic: 0x04E1,
  27722. dzecyrillic: 0x0455,
  27723. dzhecyrillic: 0x045F,
  27724. e: 0x0065,
  27725. eacute: 0x00E9,
  27726. earth: 0x2641,
  27727. ebengali: 0x098F,
  27728. ebopomofo: 0x311C,
  27729. ebreve: 0x0115,
  27730. ecandradeva: 0x090D,
  27731. ecandragujarati: 0x0A8D,
  27732. ecandravowelsigndeva: 0x0945,
  27733. ecandravowelsigngujarati: 0x0AC5,
  27734. ecaron: 0x011B,
  27735. ecedillabreve: 0x1E1D,
  27736. echarmenian: 0x0565,
  27737. echyiwnarmenian: 0x0587,
  27738. ecircle: 0x24D4,
  27739. ecircumflex: 0x00EA,
  27740. ecircumflexacute: 0x1EBF,
  27741. ecircumflexbelow: 0x1E19,
  27742. ecircumflexdotbelow: 0x1EC7,
  27743. ecircumflexgrave: 0x1EC1,
  27744. ecircumflexhookabove: 0x1EC3,
  27745. ecircumflextilde: 0x1EC5,
  27746. ecyrillic: 0x0454,
  27747. edblgrave: 0x0205,
  27748. edeva: 0x090F,
  27749. edieresis: 0x00EB,
  27750. edot: 0x0117,
  27751. edotaccent: 0x0117,
  27752. edotbelow: 0x1EB9,
  27753. eegurmukhi: 0x0A0F,
  27754. eematragurmukhi: 0x0A47,
  27755. efcyrillic: 0x0444,
  27756. egrave: 0x00E8,
  27757. egujarati: 0x0A8F,
  27758. eharmenian: 0x0567,
  27759. ehbopomofo: 0x311D,
  27760. ehiragana: 0x3048,
  27761. ehookabove: 0x1EBB,
  27762. eibopomofo: 0x311F,
  27763. eight: 0x0038,
  27764. eightarabic: 0x0668,
  27765. eightbengali: 0x09EE,
  27766. eightcircle: 0x2467,
  27767. eightcircleinversesansserif: 0x2791,
  27768. eightdeva: 0x096E,
  27769. eighteencircle: 0x2471,
  27770. eighteenparen: 0x2485,
  27771. eighteenperiod: 0x2499,
  27772. eightgujarati: 0x0AEE,
  27773. eightgurmukhi: 0x0A6E,
  27774. eighthackarabic: 0x0668,
  27775. eighthangzhou: 0x3028,
  27776. eighthnotebeamed: 0x266B,
  27777. eightideographicparen: 0x3227,
  27778. eightinferior: 0x2088,
  27779. eightmonospace: 0xFF18,
  27780. eightoldstyle: 0xF738,
  27781. eightparen: 0x247B,
  27782. eightperiod: 0x248F,
  27783. eightpersian: 0x06F8,
  27784. eightroman: 0x2177,
  27785. eightsuperior: 0x2078,
  27786. eightthai: 0x0E58,
  27787. einvertedbreve: 0x0207,
  27788. eiotifiedcyrillic: 0x0465,
  27789. ekatakana: 0x30A8,
  27790. ekatakanahalfwidth: 0xFF74,
  27791. ekonkargurmukhi: 0x0A74,
  27792. ekorean: 0x3154,
  27793. elcyrillic: 0x043B,
  27794. element: 0x2208,
  27795. elevencircle: 0x246A,
  27796. elevenparen: 0x247E,
  27797. elevenperiod: 0x2492,
  27798. elevenroman: 0x217A,
  27799. ellipsis: 0x2026,
  27800. ellipsisvertical: 0x22EE,
  27801. emacron: 0x0113,
  27802. emacronacute: 0x1E17,
  27803. emacrongrave: 0x1E15,
  27804. emcyrillic: 0x043C,
  27805. emdash: 0x2014,
  27806. emdashvertical: 0xFE31,
  27807. emonospace: 0xFF45,
  27808. emphasismarkarmenian: 0x055B,
  27809. emptyset: 0x2205,
  27810. enbopomofo: 0x3123,
  27811. encyrillic: 0x043D,
  27812. endash: 0x2013,
  27813. endashvertical: 0xFE32,
  27814. endescendercyrillic: 0x04A3,
  27815. eng: 0x014B,
  27816. engbopomofo: 0x3125,
  27817. enghecyrillic: 0x04A5,
  27818. enhookcyrillic: 0x04C8,
  27819. enspace: 0x2002,
  27820. eogonek: 0x0119,
  27821. eokorean: 0x3153,
  27822. eopen: 0x025B,
  27823. eopenclosed: 0x029A,
  27824. eopenreversed: 0x025C,
  27825. eopenreversedclosed: 0x025E,
  27826. eopenreversedhook: 0x025D,
  27827. eparen: 0x24A0,
  27828. epsilon: 0x03B5,
  27829. epsilontonos: 0x03AD,
  27830. equal: 0x003D,
  27831. equalmonospace: 0xFF1D,
  27832. equalsmall: 0xFE66,
  27833. equalsuperior: 0x207C,
  27834. equivalence: 0x2261,
  27835. erbopomofo: 0x3126,
  27836. ercyrillic: 0x0440,
  27837. ereversed: 0x0258,
  27838. ereversedcyrillic: 0x044D,
  27839. escyrillic: 0x0441,
  27840. esdescendercyrillic: 0x04AB,
  27841. esh: 0x0283,
  27842. eshcurl: 0x0286,
  27843. eshortdeva: 0x090E,
  27844. eshortvowelsigndeva: 0x0946,
  27845. eshreversedloop: 0x01AA,
  27846. eshsquatreversed: 0x0285,
  27847. esmallhiragana: 0x3047,
  27848. esmallkatakana: 0x30A7,
  27849. esmallkatakanahalfwidth: 0xFF6A,
  27850. estimated: 0x212E,
  27851. esuperior: 0xF6EC,
  27852. eta: 0x03B7,
  27853. etarmenian: 0x0568,
  27854. etatonos: 0x03AE,
  27855. eth: 0x00F0,
  27856. etilde: 0x1EBD,
  27857. etildebelow: 0x1E1B,
  27858. etnahtafoukhhebrew: 0x0591,
  27859. etnahtafoukhlefthebrew: 0x0591,
  27860. etnahtahebrew: 0x0591,
  27861. etnahtalefthebrew: 0x0591,
  27862. eturned: 0x01DD,
  27863. eukorean: 0x3161,
  27864. euro: 0x20AC,
  27865. evowelsignbengali: 0x09C7,
  27866. evowelsigndeva: 0x0947,
  27867. evowelsigngujarati: 0x0AC7,
  27868. exclam: 0x0021,
  27869. exclamarmenian: 0x055C,
  27870. exclamdbl: 0x203C,
  27871. exclamdown: 0x00A1,
  27872. exclamdownsmall: 0xF7A1,
  27873. exclammonospace: 0xFF01,
  27874. exclamsmall: 0xF721,
  27875. existential: 0x2203,
  27876. ezh: 0x0292,
  27877. ezhcaron: 0x01EF,
  27878. ezhcurl: 0x0293,
  27879. ezhreversed: 0x01B9,
  27880. ezhtail: 0x01BA,
  27881. f: 0x0066,
  27882. fadeva: 0x095E,
  27883. fagurmukhi: 0x0A5E,
  27884. fahrenheit: 0x2109,
  27885. fathaarabic: 0x064E,
  27886. fathalowarabic: 0x064E,
  27887. fathatanarabic: 0x064B,
  27888. fbopomofo: 0x3108,
  27889. fcircle: 0x24D5,
  27890. fdotaccent: 0x1E1F,
  27891. feharabic: 0x0641,
  27892. feharmenian: 0x0586,
  27893. fehfinalarabic: 0xFED2,
  27894. fehinitialarabic: 0xFED3,
  27895. fehmedialarabic: 0xFED4,
  27896. feicoptic: 0x03E5,
  27897. female: 0x2640,
  27898. ff: 0xFB00,
  27899. ffi: 0xFB03,
  27900. ffl: 0xFB04,
  27901. fi: 0xFB01,
  27902. fifteencircle: 0x246E,
  27903. fifteenparen: 0x2482,
  27904. fifteenperiod: 0x2496,
  27905. figuredash: 0x2012,
  27906. filledbox: 0x25A0,
  27907. filledrect: 0x25AC,
  27908. finalkaf: 0x05DA,
  27909. finalkafdagesh: 0xFB3A,
  27910. finalkafdageshhebrew: 0xFB3A,
  27911. finalkafhebrew: 0x05DA,
  27912. finalmem: 0x05DD,
  27913. finalmemhebrew: 0x05DD,
  27914. finalnun: 0x05DF,
  27915. finalnunhebrew: 0x05DF,
  27916. finalpe: 0x05E3,
  27917. finalpehebrew: 0x05E3,
  27918. finaltsadi: 0x05E5,
  27919. finaltsadihebrew: 0x05E5,
  27920. firsttonechinese: 0x02C9,
  27921. fisheye: 0x25C9,
  27922. fitacyrillic: 0x0473,
  27923. five: 0x0035,
  27924. fivearabic: 0x0665,
  27925. fivebengali: 0x09EB,
  27926. fivecircle: 0x2464,
  27927. fivecircleinversesansserif: 0x278E,
  27928. fivedeva: 0x096B,
  27929. fiveeighths: 0x215D,
  27930. fivegujarati: 0x0AEB,
  27931. fivegurmukhi: 0x0A6B,
  27932. fivehackarabic: 0x0665,
  27933. fivehangzhou: 0x3025,
  27934. fiveideographicparen: 0x3224,
  27935. fiveinferior: 0x2085,
  27936. fivemonospace: 0xFF15,
  27937. fiveoldstyle: 0xF735,
  27938. fiveparen: 0x2478,
  27939. fiveperiod: 0x248C,
  27940. fivepersian: 0x06F5,
  27941. fiveroman: 0x2174,
  27942. fivesuperior: 0x2075,
  27943. fivethai: 0x0E55,
  27944. fl: 0xFB02,
  27945. florin: 0x0192,
  27946. fmonospace: 0xFF46,
  27947. fmsquare: 0x3399,
  27948. fofanthai: 0x0E1F,
  27949. fofathai: 0x0E1D,
  27950. fongmanthai: 0x0E4F,
  27951. forall: 0x2200,
  27952. four: 0x0034,
  27953. fourarabic: 0x0664,
  27954. fourbengali: 0x09EA,
  27955. fourcircle: 0x2463,
  27956. fourcircleinversesansserif: 0x278D,
  27957. fourdeva: 0x096A,
  27958. fourgujarati: 0x0AEA,
  27959. fourgurmukhi: 0x0A6A,
  27960. fourhackarabic: 0x0664,
  27961. fourhangzhou: 0x3024,
  27962. fourideographicparen: 0x3223,
  27963. fourinferior: 0x2084,
  27964. fourmonospace: 0xFF14,
  27965. fournumeratorbengali: 0x09F7,
  27966. fouroldstyle: 0xF734,
  27967. fourparen: 0x2477,
  27968. fourperiod: 0x248B,
  27969. fourpersian: 0x06F4,
  27970. fourroman: 0x2173,
  27971. foursuperior: 0x2074,
  27972. fourteencircle: 0x246D,
  27973. fourteenparen: 0x2481,
  27974. fourteenperiod: 0x2495,
  27975. fourthai: 0x0E54,
  27976. fourthtonechinese: 0x02CB,
  27977. fparen: 0x24A1,
  27978. fraction: 0x2044,
  27979. franc: 0x20A3,
  27980. g: 0x0067,
  27981. gabengali: 0x0997,
  27982. gacute: 0x01F5,
  27983. gadeva: 0x0917,
  27984. gafarabic: 0x06AF,
  27985. gaffinalarabic: 0xFB93,
  27986. gafinitialarabic: 0xFB94,
  27987. gafmedialarabic: 0xFB95,
  27988. gagujarati: 0x0A97,
  27989. gagurmukhi: 0x0A17,
  27990. gahiragana: 0x304C,
  27991. gakatakana: 0x30AC,
  27992. gamma: 0x03B3,
  27993. gammalatinsmall: 0x0263,
  27994. gammasuperior: 0x02E0,
  27995. gangiacoptic: 0x03EB,
  27996. gbopomofo: 0x310D,
  27997. gbreve: 0x011F,
  27998. gcaron: 0x01E7,
  27999. gcedilla: 0x0123,
  28000. gcircle: 0x24D6,
  28001. gcircumflex: 0x011D,
  28002. gcommaaccent: 0x0123,
  28003. gdot: 0x0121,
  28004. gdotaccent: 0x0121,
  28005. gecyrillic: 0x0433,
  28006. gehiragana: 0x3052,
  28007. gekatakana: 0x30B2,
  28008. geometricallyequal: 0x2251,
  28009. gereshaccenthebrew: 0x059C,
  28010. gereshhebrew: 0x05F3,
  28011. gereshmuqdamhebrew: 0x059D,
  28012. germandbls: 0x00DF,
  28013. gershayimaccenthebrew: 0x059E,
  28014. gershayimhebrew: 0x05F4,
  28015. getamark: 0x3013,
  28016. ghabengali: 0x0998,
  28017. ghadarmenian: 0x0572,
  28018. ghadeva: 0x0918,
  28019. ghagujarati: 0x0A98,
  28020. ghagurmukhi: 0x0A18,
  28021. ghainarabic: 0x063A,
  28022. ghainfinalarabic: 0xFECE,
  28023. ghaininitialarabic: 0xFECF,
  28024. ghainmedialarabic: 0xFED0,
  28025. ghemiddlehookcyrillic: 0x0495,
  28026. ghestrokecyrillic: 0x0493,
  28027. gheupturncyrillic: 0x0491,
  28028. ghhadeva: 0x095A,
  28029. ghhagurmukhi: 0x0A5A,
  28030. ghook: 0x0260,
  28031. ghzsquare: 0x3393,
  28032. gihiragana: 0x304E,
  28033. gikatakana: 0x30AE,
  28034. gimarmenian: 0x0563,
  28035. gimel: 0x05D2,
  28036. gimeldagesh: 0xFB32,
  28037. gimeldageshhebrew: 0xFB32,
  28038. gimelhebrew: 0x05D2,
  28039. gjecyrillic: 0x0453,
  28040. glottalinvertedstroke: 0x01BE,
  28041. glottalstop: 0x0294,
  28042. glottalstopinverted: 0x0296,
  28043. glottalstopmod: 0x02C0,
  28044. glottalstopreversed: 0x0295,
  28045. glottalstopreversedmod: 0x02C1,
  28046. glottalstopreversedsuperior: 0x02E4,
  28047. glottalstopstroke: 0x02A1,
  28048. glottalstopstrokereversed: 0x02A2,
  28049. gmacron: 0x1E21,
  28050. gmonospace: 0xFF47,
  28051. gohiragana: 0x3054,
  28052. gokatakana: 0x30B4,
  28053. gparen: 0x24A2,
  28054. gpasquare: 0x33AC,
  28055. gradient: 0x2207,
  28056. grave: 0x0060,
  28057. gravebelowcmb: 0x0316,
  28058. gravecmb: 0x0300,
  28059. gravecomb: 0x0300,
  28060. gravedeva: 0x0953,
  28061. gravelowmod: 0x02CE,
  28062. gravemonospace: 0xFF40,
  28063. gravetonecmb: 0x0340,
  28064. greater: 0x003E,
  28065. greaterequal: 0x2265,
  28066. greaterequalorless: 0x22DB,
  28067. greatermonospace: 0xFF1E,
  28068. greaterorequivalent: 0x2273,
  28069. greaterorless: 0x2277,
  28070. greateroverequal: 0x2267,
  28071. greatersmall: 0xFE65,
  28072. gscript: 0x0261,
  28073. gstroke: 0x01E5,
  28074. guhiragana: 0x3050,
  28075. guillemotleft: 0x00AB,
  28076. guillemotright: 0x00BB,
  28077. guilsinglleft: 0x2039,
  28078. guilsinglright: 0x203A,
  28079. gukatakana: 0x30B0,
  28080. guramusquare: 0x3318,
  28081. gysquare: 0x33C9,
  28082. h: 0x0068,
  28083. haabkhasiancyrillic: 0x04A9,
  28084. haaltonearabic: 0x06C1,
  28085. habengali: 0x09B9,
  28086. hadescendercyrillic: 0x04B3,
  28087. hadeva: 0x0939,
  28088. hagujarati: 0x0AB9,
  28089. hagurmukhi: 0x0A39,
  28090. haharabic: 0x062D,
  28091. hahfinalarabic: 0xFEA2,
  28092. hahinitialarabic: 0xFEA3,
  28093. hahiragana: 0x306F,
  28094. hahmedialarabic: 0xFEA4,
  28095. haitusquare: 0x332A,
  28096. hakatakana: 0x30CF,
  28097. hakatakanahalfwidth: 0xFF8A,
  28098. halantgurmukhi: 0x0A4D,
  28099. hamzaarabic: 0x0621,
  28100. hamzalowarabic: 0x0621,
  28101. hangulfiller: 0x3164,
  28102. hardsigncyrillic: 0x044A,
  28103. harpoonleftbarbup: 0x21BC,
  28104. harpoonrightbarbup: 0x21C0,
  28105. hasquare: 0x33CA,
  28106. hatafpatah: 0x05B2,
  28107. hatafpatah16: 0x05B2,
  28108. hatafpatah23: 0x05B2,
  28109. hatafpatah2f: 0x05B2,
  28110. hatafpatahhebrew: 0x05B2,
  28111. hatafpatahnarrowhebrew: 0x05B2,
  28112. hatafpatahquarterhebrew: 0x05B2,
  28113. hatafpatahwidehebrew: 0x05B2,
  28114. hatafqamats: 0x05B3,
  28115. hatafqamats1b: 0x05B3,
  28116. hatafqamats28: 0x05B3,
  28117. hatafqamats34: 0x05B3,
  28118. hatafqamatshebrew: 0x05B3,
  28119. hatafqamatsnarrowhebrew: 0x05B3,
  28120. hatafqamatsquarterhebrew: 0x05B3,
  28121. hatafqamatswidehebrew: 0x05B3,
  28122. hatafsegol: 0x05B1,
  28123. hatafsegol17: 0x05B1,
  28124. hatafsegol24: 0x05B1,
  28125. hatafsegol30: 0x05B1,
  28126. hatafsegolhebrew: 0x05B1,
  28127. hatafsegolnarrowhebrew: 0x05B1,
  28128. hatafsegolquarterhebrew: 0x05B1,
  28129. hatafsegolwidehebrew: 0x05B1,
  28130. hbar: 0x0127,
  28131. hbopomofo: 0x310F,
  28132. hbrevebelow: 0x1E2B,
  28133. hcedilla: 0x1E29,
  28134. hcircle: 0x24D7,
  28135. hcircumflex: 0x0125,
  28136. hdieresis: 0x1E27,
  28137. hdotaccent: 0x1E23,
  28138. hdotbelow: 0x1E25,
  28139. he: 0x05D4,
  28140. heart: 0x2665,
  28141. heartsuitblack: 0x2665,
  28142. heartsuitwhite: 0x2661,
  28143. hedagesh: 0xFB34,
  28144. hedageshhebrew: 0xFB34,
  28145. hehaltonearabic: 0x06C1,
  28146. heharabic: 0x0647,
  28147. hehebrew: 0x05D4,
  28148. hehfinalaltonearabic: 0xFBA7,
  28149. hehfinalalttwoarabic: 0xFEEA,
  28150. hehfinalarabic: 0xFEEA,
  28151. hehhamzaabovefinalarabic: 0xFBA5,
  28152. hehhamzaaboveisolatedarabic: 0xFBA4,
  28153. hehinitialaltonearabic: 0xFBA8,
  28154. hehinitialarabic: 0xFEEB,
  28155. hehiragana: 0x3078,
  28156. hehmedialaltonearabic: 0xFBA9,
  28157. hehmedialarabic: 0xFEEC,
  28158. heiseierasquare: 0x337B,
  28159. hekatakana: 0x30D8,
  28160. hekatakanahalfwidth: 0xFF8D,
  28161. hekutaarusquare: 0x3336,
  28162. henghook: 0x0267,
  28163. herutusquare: 0x3339,
  28164. het: 0x05D7,
  28165. hethebrew: 0x05D7,
  28166. hhook: 0x0266,
  28167. hhooksuperior: 0x02B1,
  28168. hieuhacirclekorean: 0x327B,
  28169. hieuhaparenkorean: 0x321B,
  28170. hieuhcirclekorean: 0x326D,
  28171. hieuhkorean: 0x314E,
  28172. hieuhparenkorean: 0x320D,
  28173. hihiragana: 0x3072,
  28174. hikatakana: 0x30D2,
  28175. hikatakanahalfwidth: 0xFF8B,
  28176. hiriq: 0x05B4,
  28177. hiriq14: 0x05B4,
  28178. hiriq21: 0x05B4,
  28179. hiriq2d: 0x05B4,
  28180. hiriqhebrew: 0x05B4,
  28181. hiriqnarrowhebrew: 0x05B4,
  28182. hiriqquarterhebrew: 0x05B4,
  28183. hiriqwidehebrew: 0x05B4,
  28184. hlinebelow: 0x1E96,
  28185. hmonospace: 0xFF48,
  28186. hoarmenian: 0x0570,
  28187. hohipthai: 0x0E2B,
  28188. hohiragana: 0x307B,
  28189. hokatakana: 0x30DB,
  28190. hokatakanahalfwidth: 0xFF8E,
  28191. holam: 0x05B9,
  28192. holam19: 0x05B9,
  28193. holam26: 0x05B9,
  28194. holam32: 0x05B9,
  28195. holamhebrew: 0x05B9,
  28196. holamnarrowhebrew: 0x05B9,
  28197. holamquarterhebrew: 0x05B9,
  28198. holamwidehebrew: 0x05B9,
  28199. honokhukthai: 0x0E2E,
  28200. hookabovecomb: 0x0309,
  28201. hookcmb: 0x0309,
  28202. hookpalatalizedbelowcmb: 0x0321,
  28203. hookretroflexbelowcmb: 0x0322,
  28204. hoonsquare: 0x3342,
  28205. horicoptic: 0x03E9,
  28206. horizontalbar: 0x2015,
  28207. horncmb: 0x031B,
  28208. hotsprings: 0x2668,
  28209. house: 0x2302,
  28210. hparen: 0x24A3,
  28211. hsuperior: 0x02B0,
  28212. hturned: 0x0265,
  28213. huhiragana: 0x3075,
  28214. huiitosquare: 0x3333,
  28215. hukatakana: 0x30D5,
  28216. hukatakanahalfwidth: 0xFF8C,
  28217. hungarumlaut: 0x02DD,
  28218. hungarumlautcmb: 0x030B,
  28219. hv: 0x0195,
  28220. hyphen: 0x002D,
  28221. hypheninferior: 0xF6E5,
  28222. hyphenmonospace: 0xFF0D,
  28223. hyphensmall: 0xFE63,
  28224. hyphensuperior: 0xF6E6,
  28225. hyphentwo: 0x2010,
  28226. i: 0x0069,
  28227. iacute: 0x00ED,
  28228. iacyrillic: 0x044F,
  28229. ibengali: 0x0987,
  28230. ibopomofo: 0x3127,
  28231. ibreve: 0x012D,
  28232. icaron: 0x01D0,
  28233. icircle: 0x24D8,
  28234. icircumflex: 0x00EE,
  28235. icyrillic: 0x0456,
  28236. idblgrave: 0x0209,
  28237. ideographearthcircle: 0x328F,
  28238. ideographfirecircle: 0x328B,
  28239. ideographicallianceparen: 0x323F,
  28240. ideographiccallparen: 0x323A,
  28241. ideographiccentrecircle: 0x32A5,
  28242. ideographicclose: 0x3006,
  28243. ideographiccomma: 0x3001,
  28244. ideographiccommaleft: 0xFF64,
  28245. ideographiccongratulationparen: 0x3237,
  28246. ideographiccorrectcircle: 0x32A3,
  28247. ideographicearthparen: 0x322F,
  28248. ideographicenterpriseparen: 0x323D,
  28249. ideographicexcellentcircle: 0x329D,
  28250. ideographicfestivalparen: 0x3240,
  28251. ideographicfinancialcircle: 0x3296,
  28252. ideographicfinancialparen: 0x3236,
  28253. ideographicfireparen: 0x322B,
  28254. ideographichaveparen: 0x3232,
  28255. ideographichighcircle: 0x32A4,
  28256. ideographiciterationmark: 0x3005,
  28257. ideographiclaborcircle: 0x3298,
  28258. ideographiclaborparen: 0x3238,
  28259. ideographicleftcircle: 0x32A7,
  28260. ideographiclowcircle: 0x32A6,
  28261. ideographicmedicinecircle: 0x32A9,
  28262. ideographicmetalparen: 0x322E,
  28263. ideographicmoonparen: 0x322A,
  28264. ideographicnameparen: 0x3234,
  28265. ideographicperiod: 0x3002,
  28266. ideographicprintcircle: 0x329E,
  28267. ideographicreachparen: 0x3243,
  28268. ideographicrepresentparen: 0x3239,
  28269. ideographicresourceparen: 0x323E,
  28270. ideographicrightcircle: 0x32A8,
  28271. ideographicsecretcircle: 0x3299,
  28272. ideographicselfparen: 0x3242,
  28273. ideographicsocietyparen: 0x3233,
  28274. ideographicspace: 0x3000,
  28275. ideographicspecialparen: 0x3235,
  28276. ideographicstockparen: 0x3231,
  28277. ideographicstudyparen: 0x323B,
  28278. ideographicsunparen: 0x3230,
  28279. ideographicsuperviseparen: 0x323C,
  28280. ideographicwaterparen: 0x322C,
  28281. ideographicwoodparen: 0x322D,
  28282. ideographiczero: 0x3007,
  28283. ideographmetalcircle: 0x328E,
  28284. ideographmooncircle: 0x328A,
  28285. ideographnamecircle: 0x3294,
  28286. ideographsuncircle: 0x3290,
  28287. ideographwatercircle: 0x328C,
  28288. ideographwoodcircle: 0x328D,
  28289. ideva: 0x0907,
  28290. idieresis: 0x00EF,
  28291. idieresisacute: 0x1E2F,
  28292. idieresiscyrillic: 0x04E5,
  28293. idotbelow: 0x1ECB,
  28294. iebrevecyrillic: 0x04D7,
  28295. iecyrillic: 0x0435,
  28296. ieungacirclekorean: 0x3275,
  28297. ieungaparenkorean: 0x3215,
  28298. ieungcirclekorean: 0x3267,
  28299. ieungkorean: 0x3147,
  28300. ieungparenkorean: 0x3207,
  28301. igrave: 0x00EC,
  28302. igujarati: 0x0A87,
  28303. igurmukhi: 0x0A07,
  28304. ihiragana: 0x3044,
  28305. ihookabove: 0x1EC9,
  28306. iibengali: 0x0988,
  28307. iicyrillic: 0x0438,
  28308. iideva: 0x0908,
  28309. iigujarati: 0x0A88,
  28310. iigurmukhi: 0x0A08,
  28311. iimatragurmukhi: 0x0A40,
  28312. iinvertedbreve: 0x020B,
  28313. iishortcyrillic: 0x0439,
  28314. iivowelsignbengali: 0x09C0,
  28315. iivowelsigndeva: 0x0940,
  28316. iivowelsigngujarati: 0x0AC0,
  28317. ij: 0x0133,
  28318. ikatakana: 0x30A4,
  28319. ikatakanahalfwidth: 0xFF72,
  28320. ikorean: 0x3163,
  28321. ilde: 0x02DC,
  28322. iluyhebrew: 0x05AC,
  28323. imacron: 0x012B,
  28324. imacroncyrillic: 0x04E3,
  28325. imageorapproximatelyequal: 0x2253,
  28326. imatragurmukhi: 0x0A3F,
  28327. imonospace: 0xFF49,
  28328. increment: 0x2206,
  28329. infinity: 0x221E,
  28330. iniarmenian: 0x056B,
  28331. integral: 0x222B,
  28332. integralbottom: 0x2321,
  28333. integralbt: 0x2321,
  28334. integralex: 0xF8F5,
  28335. integraltop: 0x2320,
  28336. integraltp: 0x2320,
  28337. intersection: 0x2229,
  28338. intisquare: 0x3305,
  28339. invbullet: 0x25D8,
  28340. invcircle: 0x25D9,
  28341. invsmileface: 0x263B,
  28342. iocyrillic: 0x0451,
  28343. iogonek: 0x012F,
  28344. iota: 0x03B9,
  28345. iotadieresis: 0x03CA,
  28346. iotadieresistonos: 0x0390,
  28347. iotalatin: 0x0269,
  28348. iotatonos: 0x03AF,
  28349. iparen: 0x24A4,
  28350. irigurmukhi: 0x0A72,
  28351. ismallhiragana: 0x3043,
  28352. ismallkatakana: 0x30A3,
  28353. ismallkatakanahalfwidth: 0xFF68,
  28354. issharbengali: 0x09FA,
  28355. istroke: 0x0268,
  28356. isuperior: 0xF6ED,
  28357. iterationhiragana: 0x309D,
  28358. iterationkatakana: 0x30FD,
  28359. itilde: 0x0129,
  28360. itildebelow: 0x1E2D,
  28361. iubopomofo: 0x3129,
  28362. iucyrillic: 0x044E,
  28363. ivowelsignbengali: 0x09BF,
  28364. ivowelsigndeva: 0x093F,
  28365. ivowelsigngujarati: 0x0ABF,
  28366. izhitsacyrillic: 0x0475,
  28367. izhitsadblgravecyrillic: 0x0477,
  28368. j: 0x006A,
  28369. jaarmenian: 0x0571,
  28370. jabengali: 0x099C,
  28371. jadeva: 0x091C,
  28372. jagujarati: 0x0A9C,
  28373. jagurmukhi: 0x0A1C,
  28374. jbopomofo: 0x3110,
  28375. jcaron: 0x01F0,
  28376. jcircle: 0x24D9,
  28377. jcircumflex: 0x0135,
  28378. jcrossedtail: 0x029D,
  28379. jdotlessstroke: 0x025F,
  28380. jecyrillic: 0x0458,
  28381. jeemarabic: 0x062C,
  28382. jeemfinalarabic: 0xFE9E,
  28383. jeeminitialarabic: 0xFE9F,
  28384. jeemmedialarabic: 0xFEA0,
  28385. jeharabic: 0x0698,
  28386. jehfinalarabic: 0xFB8B,
  28387. jhabengali: 0x099D,
  28388. jhadeva: 0x091D,
  28389. jhagujarati: 0x0A9D,
  28390. jhagurmukhi: 0x0A1D,
  28391. jheharmenian: 0x057B,
  28392. jis: 0x3004,
  28393. jmonospace: 0xFF4A,
  28394. jparen: 0x24A5,
  28395. jsuperior: 0x02B2,
  28396. k: 0x006B,
  28397. kabashkircyrillic: 0x04A1,
  28398. kabengali: 0x0995,
  28399. kacute: 0x1E31,
  28400. kacyrillic: 0x043A,
  28401. kadescendercyrillic: 0x049B,
  28402. kadeva: 0x0915,
  28403. kaf: 0x05DB,
  28404. kafarabic: 0x0643,
  28405. kafdagesh: 0xFB3B,
  28406. kafdageshhebrew: 0xFB3B,
  28407. kaffinalarabic: 0xFEDA,
  28408. kafhebrew: 0x05DB,
  28409. kafinitialarabic: 0xFEDB,
  28410. kafmedialarabic: 0xFEDC,
  28411. kafrafehebrew: 0xFB4D,
  28412. kagujarati: 0x0A95,
  28413. kagurmukhi: 0x0A15,
  28414. kahiragana: 0x304B,
  28415. kahookcyrillic: 0x04C4,
  28416. kakatakana: 0x30AB,
  28417. kakatakanahalfwidth: 0xFF76,
  28418. kappa: 0x03BA,
  28419. kappasymbolgreek: 0x03F0,
  28420. kapyeounmieumkorean: 0x3171,
  28421. kapyeounphieuphkorean: 0x3184,
  28422. kapyeounpieupkorean: 0x3178,
  28423. kapyeounssangpieupkorean: 0x3179,
  28424. karoriisquare: 0x330D,
  28425. kashidaautoarabic: 0x0640,
  28426. kashidaautonosidebearingarabic: 0x0640,
  28427. kasmallkatakana: 0x30F5,
  28428. kasquare: 0x3384,
  28429. kasraarabic: 0x0650,
  28430. kasratanarabic: 0x064D,
  28431. kastrokecyrillic: 0x049F,
  28432. katahiraprolongmarkhalfwidth: 0xFF70,
  28433. kaverticalstrokecyrillic: 0x049D,
  28434. kbopomofo: 0x310E,
  28435. kcalsquare: 0x3389,
  28436. kcaron: 0x01E9,
  28437. kcedilla: 0x0137,
  28438. kcircle: 0x24DA,
  28439. kcommaaccent: 0x0137,
  28440. kdotbelow: 0x1E33,
  28441. keharmenian: 0x0584,
  28442. kehiragana: 0x3051,
  28443. kekatakana: 0x30B1,
  28444. kekatakanahalfwidth: 0xFF79,
  28445. kenarmenian: 0x056F,
  28446. kesmallkatakana: 0x30F6,
  28447. kgreenlandic: 0x0138,
  28448. khabengali: 0x0996,
  28449. khacyrillic: 0x0445,
  28450. khadeva: 0x0916,
  28451. khagujarati: 0x0A96,
  28452. khagurmukhi: 0x0A16,
  28453. khaharabic: 0x062E,
  28454. khahfinalarabic: 0xFEA6,
  28455. khahinitialarabic: 0xFEA7,
  28456. khahmedialarabic: 0xFEA8,
  28457. kheicoptic: 0x03E7,
  28458. khhadeva: 0x0959,
  28459. khhagurmukhi: 0x0A59,
  28460. khieukhacirclekorean: 0x3278,
  28461. khieukhaparenkorean: 0x3218,
  28462. khieukhcirclekorean: 0x326A,
  28463. khieukhkorean: 0x314B,
  28464. khieukhparenkorean: 0x320A,
  28465. khokhaithai: 0x0E02,
  28466. khokhonthai: 0x0E05,
  28467. khokhuatthai: 0x0E03,
  28468. khokhwaithai: 0x0E04,
  28469. khomutthai: 0x0E5B,
  28470. khook: 0x0199,
  28471. khorakhangthai: 0x0E06,
  28472. khzsquare: 0x3391,
  28473. kihiragana: 0x304D,
  28474. kikatakana: 0x30AD,
  28475. kikatakanahalfwidth: 0xFF77,
  28476. kiroguramusquare: 0x3315,
  28477. kiromeetorusquare: 0x3316,
  28478. kirosquare: 0x3314,
  28479. kiyeokacirclekorean: 0x326E,
  28480. kiyeokaparenkorean: 0x320E,
  28481. kiyeokcirclekorean: 0x3260,
  28482. kiyeokkorean: 0x3131,
  28483. kiyeokparenkorean: 0x3200,
  28484. kiyeoksioskorean: 0x3133,
  28485. kjecyrillic: 0x045C,
  28486. klinebelow: 0x1E35,
  28487. klsquare: 0x3398,
  28488. kmcubedsquare: 0x33A6,
  28489. kmonospace: 0xFF4B,
  28490. kmsquaredsquare: 0x33A2,
  28491. kohiragana: 0x3053,
  28492. kohmsquare: 0x33C0,
  28493. kokaithai: 0x0E01,
  28494. kokatakana: 0x30B3,
  28495. kokatakanahalfwidth: 0xFF7A,
  28496. kooposquare: 0x331E,
  28497. koppacyrillic: 0x0481,
  28498. koreanstandardsymbol: 0x327F,
  28499. koroniscmb: 0x0343,
  28500. kparen: 0x24A6,
  28501. kpasquare: 0x33AA,
  28502. ksicyrillic: 0x046F,
  28503. ktsquare: 0x33CF,
  28504. kturned: 0x029E,
  28505. kuhiragana: 0x304F,
  28506. kukatakana: 0x30AF,
  28507. kukatakanahalfwidth: 0xFF78,
  28508. kvsquare: 0x33B8,
  28509. kwsquare: 0x33BE,
  28510. l: 0x006C,
  28511. labengali: 0x09B2,
  28512. lacute: 0x013A,
  28513. ladeva: 0x0932,
  28514. lagujarati: 0x0AB2,
  28515. lagurmukhi: 0x0A32,
  28516. lakkhangyaothai: 0x0E45,
  28517. lamaleffinalarabic: 0xFEFC,
  28518. lamalefhamzaabovefinalarabic: 0xFEF8,
  28519. lamalefhamzaaboveisolatedarabic: 0xFEF7,
  28520. lamalefhamzabelowfinalarabic: 0xFEFA,
  28521. lamalefhamzabelowisolatedarabic: 0xFEF9,
  28522. lamalefisolatedarabic: 0xFEFB,
  28523. lamalefmaddaabovefinalarabic: 0xFEF6,
  28524. lamalefmaddaaboveisolatedarabic: 0xFEF5,
  28525. lamarabic: 0x0644,
  28526. lambda: 0x03BB,
  28527. lambdastroke: 0x019B,
  28528. lamed: 0x05DC,
  28529. lameddagesh: 0xFB3C,
  28530. lameddageshhebrew: 0xFB3C,
  28531. lamedhebrew: 0x05DC,
  28532. lamfinalarabic: 0xFEDE,
  28533. lamhahinitialarabic: 0xFCCA,
  28534. laminitialarabic: 0xFEDF,
  28535. lamjeeminitialarabic: 0xFCC9,
  28536. lamkhahinitialarabic: 0xFCCB,
  28537. lamlamhehisolatedarabic: 0xFDF2,
  28538. lammedialarabic: 0xFEE0,
  28539. lammeemhahinitialarabic: 0xFD88,
  28540. lammeeminitialarabic: 0xFCCC,
  28541. largecircle: 0x25EF,
  28542. lbar: 0x019A,
  28543. lbelt: 0x026C,
  28544. lbopomofo: 0x310C,
  28545. lcaron: 0x013E,
  28546. lcedilla: 0x013C,
  28547. lcircle: 0x24DB,
  28548. lcircumflexbelow: 0x1E3D,
  28549. lcommaaccent: 0x013C,
  28550. ldot: 0x0140,
  28551. ldotaccent: 0x0140,
  28552. ldotbelow: 0x1E37,
  28553. ldotbelowmacron: 0x1E39,
  28554. leftangleabovecmb: 0x031A,
  28555. lefttackbelowcmb: 0x0318,
  28556. less: 0x003C,
  28557. lessequal: 0x2264,
  28558. lessequalorgreater: 0x22DA,
  28559. lessmonospace: 0xFF1C,
  28560. lessorequivalent: 0x2272,
  28561. lessorgreater: 0x2276,
  28562. lessoverequal: 0x2266,
  28563. lesssmall: 0xFE64,
  28564. lezh: 0x026E,
  28565. lfblock: 0x258C,
  28566. lhookretroflex: 0x026D,
  28567. lira: 0x20A4,
  28568. liwnarmenian: 0x056C,
  28569. lj: 0x01C9,
  28570. ljecyrillic: 0x0459,
  28571. ll: 0xF6C0,
  28572. lladeva: 0x0933,
  28573. llagujarati: 0x0AB3,
  28574. llinebelow: 0x1E3B,
  28575. llladeva: 0x0934,
  28576. llvocalicbengali: 0x09E1,
  28577. llvocalicdeva: 0x0961,
  28578. llvocalicvowelsignbengali: 0x09E3,
  28579. llvocalicvowelsigndeva: 0x0963,
  28580. lmiddletilde: 0x026B,
  28581. lmonospace: 0xFF4C,
  28582. lmsquare: 0x33D0,
  28583. lochulathai: 0x0E2C,
  28584. logicaland: 0x2227,
  28585. logicalnot: 0x00AC,
  28586. logicalnotreversed: 0x2310,
  28587. logicalor: 0x2228,
  28588. lolingthai: 0x0E25,
  28589. longs: 0x017F,
  28590. lowlinecenterline: 0xFE4E,
  28591. lowlinecmb: 0x0332,
  28592. lowlinedashed: 0xFE4D,
  28593. lozenge: 0x25CA,
  28594. lparen: 0x24A7,
  28595. lslash: 0x0142,
  28596. lsquare: 0x2113,
  28597. lsuperior: 0xF6EE,
  28598. ltshade: 0x2591,
  28599. luthai: 0x0E26,
  28600. lvocalicbengali: 0x098C,
  28601. lvocalicdeva: 0x090C,
  28602. lvocalicvowelsignbengali: 0x09E2,
  28603. lvocalicvowelsigndeva: 0x0962,
  28604. lxsquare: 0x33D3,
  28605. m: 0x006D,
  28606. mabengali: 0x09AE,
  28607. macron: 0x00AF,
  28608. macronbelowcmb: 0x0331,
  28609. macroncmb: 0x0304,
  28610. macronlowmod: 0x02CD,
  28611. macronmonospace: 0xFFE3,
  28612. macute: 0x1E3F,
  28613. madeva: 0x092E,
  28614. magujarati: 0x0AAE,
  28615. magurmukhi: 0x0A2E,
  28616. mahapakhhebrew: 0x05A4,
  28617. mahapakhlefthebrew: 0x05A4,
  28618. mahiragana: 0x307E,
  28619. maichattawalowleftthai: 0xF895,
  28620. maichattawalowrightthai: 0xF894,
  28621. maichattawathai: 0x0E4B,
  28622. maichattawaupperleftthai: 0xF893,
  28623. maieklowleftthai: 0xF88C,
  28624. maieklowrightthai: 0xF88B,
  28625. maiekthai: 0x0E48,
  28626. maiekupperleftthai: 0xF88A,
  28627. maihanakatleftthai: 0xF884,
  28628. maihanakatthai: 0x0E31,
  28629. maitaikhuleftthai: 0xF889,
  28630. maitaikhuthai: 0x0E47,
  28631. maitholowleftthai: 0xF88F,
  28632. maitholowrightthai: 0xF88E,
  28633. maithothai: 0x0E49,
  28634. maithoupperleftthai: 0xF88D,
  28635. maitrilowleftthai: 0xF892,
  28636. maitrilowrightthai: 0xF891,
  28637. maitrithai: 0x0E4A,
  28638. maitriupperleftthai: 0xF890,
  28639. maiyamokthai: 0x0E46,
  28640. makatakana: 0x30DE,
  28641. makatakanahalfwidth: 0xFF8F,
  28642. male: 0x2642,
  28643. mansyonsquare: 0x3347,
  28644. maqafhebrew: 0x05BE,
  28645. mars: 0x2642,
  28646. masoracirclehebrew: 0x05AF,
  28647. masquare: 0x3383,
  28648. mbopomofo: 0x3107,
  28649. mbsquare: 0x33D4,
  28650. mcircle: 0x24DC,
  28651. mcubedsquare: 0x33A5,
  28652. mdotaccent: 0x1E41,
  28653. mdotbelow: 0x1E43,
  28654. meemarabic: 0x0645,
  28655. meemfinalarabic: 0xFEE2,
  28656. meeminitialarabic: 0xFEE3,
  28657. meemmedialarabic: 0xFEE4,
  28658. meemmeeminitialarabic: 0xFCD1,
  28659. meemmeemisolatedarabic: 0xFC48,
  28660. meetorusquare: 0x334D,
  28661. mehiragana: 0x3081,
  28662. meizierasquare: 0x337E,
  28663. mekatakana: 0x30E1,
  28664. mekatakanahalfwidth: 0xFF92,
  28665. mem: 0x05DE,
  28666. memdagesh: 0xFB3E,
  28667. memdageshhebrew: 0xFB3E,
  28668. memhebrew: 0x05DE,
  28669. menarmenian: 0x0574,
  28670. merkhahebrew: 0x05A5,
  28671. merkhakefulahebrew: 0x05A6,
  28672. merkhakefulalefthebrew: 0x05A6,
  28673. merkhalefthebrew: 0x05A5,
  28674. mhook: 0x0271,
  28675. mhzsquare: 0x3392,
  28676. middledotkatakanahalfwidth: 0xFF65,
  28677. middot: 0x00B7,
  28678. mieumacirclekorean: 0x3272,
  28679. mieumaparenkorean: 0x3212,
  28680. mieumcirclekorean: 0x3264,
  28681. mieumkorean: 0x3141,
  28682. mieumpansioskorean: 0x3170,
  28683. mieumparenkorean: 0x3204,
  28684. mieumpieupkorean: 0x316E,
  28685. mieumsioskorean: 0x316F,
  28686. mihiragana: 0x307F,
  28687. mikatakana: 0x30DF,
  28688. mikatakanahalfwidth: 0xFF90,
  28689. minus: 0x2212,
  28690. minusbelowcmb: 0x0320,
  28691. minuscircle: 0x2296,
  28692. minusmod: 0x02D7,
  28693. minusplus: 0x2213,
  28694. minute: 0x2032,
  28695. miribaarusquare: 0x334A,
  28696. mirisquare: 0x3349,
  28697. mlonglegturned: 0x0270,
  28698. mlsquare: 0x3396,
  28699. mmcubedsquare: 0x33A3,
  28700. mmonospace: 0xFF4D,
  28701. mmsquaredsquare: 0x339F,
  28702. mohiragana: 0x3082,
  28703. mohmsquare: 0x33C1,
  28704. mokatakana: 0x30E2,
  28705. mokatakanahalfwidth: 0xFF93,
  28706. molsquare: 0x33D6,
  28707. momathai: 0x0E21,
  28708. moverssquare: 0x33A7,
  28709. moverssquaredsquare: 0x33A8,
  28710. mparen: 0x24A8,
  28711. mpasquare: 0x33AB,
  28712. mssquare: 0x33B3,
  28713. msuperior: 0xF6EF,
  28714. mturned: 0x026F,
  28715. mu: 0x00B5,
  28716. mu1: 0x00B5,
  28717. muasquare: 0x3382,
  28718. muchgreater: 0x226B,
  28719. muchless: 0x226A,
  28720. mufsquare: 0x338C,
  28721. mugreek: 0x03BC,
  28722. mugsquare: 0x338D,
  28723. muhiragana: 0x3080,
  28724. mukatakana: 0x30E0,
  28725. mukatakanahalfwidth: 0xFF91,
  28726. mulsquare: 0x3395,
  28727. multiply: 0x00D7,
  28728. mumsquare: 0x339B,
  28729. munahhebrew: 0x05A3,
  28730. munahlefthebrew: 0x05A3,
  28731. musicalnote: 0x266A,
  28732. musicalnotedbl: 0x266B,
  28733. musicflatsign: 0x266D,
  28734. musicsharpsign: 0x266F,
  28735. mussquare: 0x33B2,
  28736. muvsquare: 0x33B6,
  28737. muwsquare: 0x33BC,
  28738. mvmegasquare: 0x33B9,
  28739. mvsquare: 0x33B7,
  28740. mwmegasquare: 0x33BF,
  28741. mwsquare: 0x33BD,
  28742. n: 0x006E,
  28743. nabengali: 0x09A8,
  28744. nabla: 0x2207,
  28745. nacute: 0x0144,
  28746. nadeva: 0x0928,
  28747. nagujarati: 0x0AA8,
  28748. nagurmukhi: 0x0A28,
  28749. nahiragana: 0x306A,
  28750. nakatakana: 0x30CA,
  28751. nakatakanahalfwidth: 0xFF85,
  28752. napostrophe: 0x0149,
  28753. nasquare: 0x3381,
  28754. nbopomofo: 0x310B,
  28755. nbspace: 0x00A0,
  28756. ncaron: 0x0148,
  28757. ncedilla: 0x0146,
  28758. ncircle: 0x24DD,
  28759. ncircumflexbelow: 0x1E4B,
  28760. ncommaaccent: 0x0146,
  28761. ndotaccent: 0x1E45,
  28762. ndotbelow: 0x1E47,
  28763. nehiragana: 0x306D,
  28764. nekatakana: 0x30CD,
  28765. nekatakanahalfwidth: 0xFF88,
  28766. newsheqelsign: 0x20AA,
  28767. nfsquare: 0x338B,
  28768. ngabengali: 0x0999,
  28769. ngadeva: 0x0919,
  28770. ngagujarati: 0x0A99,
  28771. ngagurmukhi: 0x0A19,
  28772. ngonguthai: 0x0E07,
  28773. nhiragana: 0x3093,
  28774. nhookleft: 0x0272,
  28775. nhookretroflex: 0x0273,
  28776. nieunacirclekorean: 0x326F,
  28777. nieunaparenkorean: 0x320F,
  28778. nieuncieuckorean: 0x3135,
  28779. nieuncirclekorean: 0x3261,
  28780. nieunhieuhkorean: 0x3136,
  28781. nieunkorean: 0x3134,
  28782. nieunpansioskorean: 0x3168,
  28783. nieunparenkorean: 0x3201,
  28784. nieunsioskorean: 0x3167,
  28785. nieuntikeutkorean: 0x3166,
  28786. nihiragana: 0x306B,
  28787. nikatakana: 0x30CB,
  28788. nikatakanahalfwidth: 0xFF86,
  28789. nikhahitleftthai: 0xF899,
  28790. nikhahitthai: 0x0E4D,
  28791. nine: 0x0039,
  28792. ninearabic: 0x0669,
  28793. ninebengali: 0x09EF,
  28794. ninecircle: 0x2468,
  28795. ninecircleinversesansserif: 0x2792,
  28796. ninedeva: 0x096F,
  28797. ninegujarati: 0x0AEF,
  28798. ninegurmukhi: 0x0A6F,
  28799. ninehackarabic: 0x0669,
  28800. ninehangzhou: 0x3029,
  28801. nineideographicparen: 0x3228,
  28802. nineinferior: 0x2089,
  28803. ninemonospace: 0xFF19,
  28804. nineoldstyle: 0xF739,
  28805. nineparen: 0x247C,
  28806. nineperiod: 0x2490,
  28807. ninepersian: 0x06F9,
  28808. nineroman: 0x2178,
  28809. ninesuperior: 0x2079,
  28810. nineteencircle: 0x2472,
  28811. nineteenparen: 0x2486,
  28812. nineteenperiod: 0x249A,
  28813. ninethai: 0x0E59,
  28814. nj: 0x01CC,
  28815. njecyrillic: 0x045A,
  28816. nkatakana: 0x30F3,
  28817. nkatakanahalfwidth: 0xFF9D,
  28818. nlegrightlong: 0x019E,
  28819. nlinebelow: 0x1E49,
  28820. nmonospace: 0xFF4E,
  28821. nmsquare: 0x339A,
  28822. nnabengali: 0x09A3,
  28823. nnadeva: 0x0923,
  28824. nnagujarati: 0x0AA3,
  28825. nnagurmukhi: 0x0A23,
  28826. nnnadeva: 0x0929,
  28827. nohiragana: 0x306E,
  28828. nokatakana: 0x30CE,
  28829. nokatakanahalfwidth: 0xFF89,
  28830. nonbreakingspace: 0x00A0,
  28831. nonenthai: 0x0E13,
  28832. nonuthai: 0x0E19,
  28833. noonarabic: 0x0646,
  28834. noonfinalarabic: 0xFEE6,
  28835. noonghunnaarabic: 0x06BA,
  28836. noonghunnafinalarabic: 0xFB9F,
  28837. nooninitialarabic: 0xFEE7,
  28838. noonjeeminitialarabic: 0xFCD2,
  28839. noonjeemisolatedarabic: 0xFC4B,
  28840. noonmedialarabic: 0xFEE8,
  28841. noonmeeminitialarabic: 0xFCD5,
  28842. noonmeemisolatedarabic: 0xFC4E,
  28843. noonnoonfinalarabic: 0xFC8D,
  28844. notcontains: 0x220C,
  28845. notelement: 0x2209,
  28846. notelementof: 0x2209,
  28847. notequal: 0x2260,
  28848. notgreater: 0x226F,
  28849. notgreaternorequal: 0x2271,
  28850. notgreaternorless: 0x2279,
  28851. notidentical: 0x2262,
  28852. notless: 0x226E,
  28853. notlessnorequal: 0x2270,
  28854. notparallel: 0x2226,
  28855. notprecedes: 0x2280,
  28856. notsubset: 0x2284,
  28857. notsucceeds: 0x2281,
  28858. notsuperset: 0x2285,
  28859. nowarmenian: 0x0576,
  28860. nparen: 0x24A9,
  28861. nssquare: 0x33B1,
  28862. nsuperior: 0x207F,
  28863. ntilde: 0x00F1,
  28864. nu: 0x03BD,
  28865. nuhiragana: 0x306C,
  28866. nukatakana: 0x30CC,
  28867. nukatakanahalfwidth: 0xFF87,
  28868. nuktabengali: 0x09BC,
  28869. nuktadeva: 0x093C,
  28870. nuktagujarati: 0x0ABC,
  28871. nuktagurmukhi: 0x0A3C,
  28872. numbersign: 0x0023,
  28873. numbersignmonospace: 0xFF03,
  28874. numbersignsmall: 0xFE5F,
  28875. numeralsigngreek: 0x0374,
  28876. numeralsignlowergreek: 0x0375,
  28877. numero: 0x2116,
  28878. nun: 0x05E0,
  28879. nundagesh: 0xFB40,
  28880. nundageshhebrew: 0xFB40,
  28881. nunhebrew: 0x05E0,
  28882. nvsquare: 0x33B5,
  28883. nwsquare: 0x33BB,
  28884. nyabengali: 0x099E,
  28885. nyadeva: 0x091E,
  28886. nyagujarati: 0x0A9E,
  28887. nyagurmukhi: 0x0A1E,
  28888. o: 0x006F,
  28889. oacute: 0x00F3,
  28890. oangthai: 0x0E2D,
  28891. obarred: 0x0275,
  28892. obarredcyrillic: 0x04E9,
  28893. obarreddieresiscyrillic: 0x04EB,
  28894. obengali: 0x0993,
  28895. obopomofo: 0x311B,
  28896. obreve: 0x014F,
  28897. ocandradeva: 0x0911,
  28898. ocandragujarati: 0x0A91,
  28899. ocandravowelsigndeva: 0x0949,
  28900. ocandravowelsigngujarati: 0x0AC9,
  28901. ocaron: 0x01D2,
  28902. ocircle: 0x24DE,
  28903. ocircumflex: 0x00F4,
  28904. ocircumflexacute: 0x1ED1,
  28905. ocircumflexdotbelow: 0x1ED9,
  28906. ocircumflexgrave: 0x1ED3,
  28907. ocircumflexhookabove: 0x1ED5,
  28908. ocircumflextilde: 0x1ED7,
  28909. ocyrillic: 0x043E,
  28910. odblacute: 0x0151,
  28911. odblgrave: 0x020D,
  28912. odeva: 0x0913,
  28913. odieresis: 0x00F6,
  28914. odieresiscyrillic: 0x04E7,
  28915. odotbelow: 0x1ECD,
  28916. oe: 0x0153,
  28917. oekorean: 0x315A,
  28918. ogonek: 0x02DB,
  28919. ogonekcmb: 0x0328,
  28920. ograve: 0x00F2,
  28921. ogujarati: 0x0A93,
  28922. oharmenian: 0x0585,
  28923. ohiragana: 0x304A,
  28924. ohookabove: 0x1ECF,
  28925. ohorn: 0x01A1,
  28926. ohornacute: 0x1EDB,
  28927. ohorndotbelow: 0x1EE3,
  28928. ohorngrave: 0x1EDD,
  28929. ohornhookabove: 0x1EDF,
  28930. ohorntilde: 0x1EE1,
  28931. ohungarumlaut: 0x0151,
  28932. oi: 0x01A3,
  28933. oinvertedbreve: 0x020F,
  28934. okatakana: 0x30AA,
  28935. okatakanahalfwidth: 0xFF75,
  28936. okorean: 0x3157,
  28937. olehebrew: 0x05AB,
  28938. omacron: 0x014D,
  28939. omacronacute: 0x1E53,
  28940. omacrongrave: 0x1E51,
  28941. omdeva: 0x0950,
  28942. omega: 0x03C9,
  28943. omega1: 0x03D6,
  28944. omegacyrillic: 0x0461,
  28945. omegalatinclosed: 0x0277,
  28946. omegaroundcyrillic: 0x047B,
  28947. omegatitlocyrillic: 0x047D,
  28948. omegatonos: 0x03CE,
  28949. omgujarati: 0x0AD0,
  28950. omicron: 0x03BF,
  28951. omicrontonos: 0x03CC,
  28952. omonospace: 0xFF4F,
  28953. one: 0x0031,
  28954. onearabic: 0x0661,
  28955. onebengali: 0x09E7,
  28956. onecircle: 0x2460,
  28957. onecircleinversesansserif: 0x278A,
  28958. onedeva: 0x0967,
  28959. onedotenleader: 0x2024,
  28960. oneeighth: 0x215B,
  28961. onefitted: 0xF6DC,
  28962. onegujarati: 0x0AE7,
  28963. onegurmukhi: 0x0A67,
  28964. onehackarabic: 0x0661,
  28965. onehalf: 0x00BD,
  28966. onehangzhou: 0x3021,
  28967. oneideographicparen: 0x3220,
  28968. oneinferior: 0x2081,
  28969. onemonospace: 0xFF11,
  28970. onenumeratorbengali: 0x09F4,
  28971. oneoldstyle: 0xF731,
  28972. oneparen: 0x2474,
  28973. oneperiod: 0x2488,
  28974. onepersian: 0x06F1,
  28975. onequarter: 0x00BC,
  28976. oneroman: 0x2170,
  28977. onesuperior: 0x00B9,
  28978. onethai: 0x0E51,
  28979. onethird: 0x2153,
  28980. oogonek: 0x01EB,
  28981. oogonekmacron: 0x01ED,
  28982. oogurmukhi: 0x0A13,
  28983. oomatragurmukhi: 0x0A4B,
  28984. oopen: 0x0254,
  28985. oparen: 0x24AA,
  28986. openbullet: 0x25E6,
  28987. option: 0x2325,
  28988. ordfeminine: 0x00AA,
  28989. ordmasculine: 0x00BA,
  28990. orthogonal: 0x221F,
  28991. oshortdeva: 0x0912,
  28992. oshortvowelsigndeva: 0x094A,
  28993. oslash: 0x00F8,
  28994. oslashacute: 0x01FF,
  28995. osmallhiragana: 0x3049,
  28996. osmallkatakana: 0x30A9,
  28997. osmallkatakanahalfwidth: 0xFF6B,
  28998. ostrokeacute: 0x01FF,
  28999. osuperior: 0xF6F0,
  29000. otcyrillic: 0x047F,
  29001. otilde: 0x00F5,
  29002. otildeacute: 0x1E4D,
  29003. otildedieresis: 0x1E4F,
  29004. oubopomofo: 0x3121,
  29005. overline: 0x203E,
  29006. overlinecenterline: 0xFE4A,
  29007. overlinecmb: 0x0305,
  29008. overlinedashed: 0xFE49,
  29009. overlinedblwavy: 0xFE4C,
  29010. overlinewavy: 0xFE4B,
  29011. overscore: 0x00AF,
  29012. ovowelsignbengali: 0x09CB,
  29013. ovowelsigndeva: 0x094B,
  29014. ovowelsigngujarati: 0x0ACB,
  29015. p: 0x0070,
  29016. paampssquare: 0x3380,
  29017. paasentosquare: 0x332B,
  29018. pabengali: 0x09AA,
  29019. pacute: 0x1E55,
  29020. padeva: 0x092A,
  29021. pagedown: 0x21DF,
  29022. pageup: 0x21DE,
  29023. pagujarati: 0x0AAA,
  29024. pagurmukhi: 0x0A2A,
  29025. pahiragana: 0x3071,
  29026. paiyannoithai: 0x0E2F,
  29027. pakatakana: 0x30D1,
  29028. palatalizationcyrilliccmb: 0x0484,
  29029. palochkacyrillic: 0x04C0,
  29030. pansioskorean: 0x317F,
  29031. paragraph: 0x00B6,
  29032. parallel: 0x2225,
  29033. parenleft: 0x0028,
  29034. parenleftaltonearabic: 0xFD3E,
  29035. parenleftbt: 0xF8ED,
  29036. parenleftex: 0xF8EC,
  29037. parenleftinferior: 0x208D,
  29038. parenleftmonospace: 0xFF08,
  29039. parenleftsmall: 0xFE59,
  29040. parenleftsuperior: 0x207D,
  29041. parenlefttp: 0xF8EB,
  29042. parenleftvertical: 0xFE35,
  29043. parenright: 0x0029,
  29044. parenrightaltonearabic: 0xFD3F,
  29045. parenrightbt: 0xF8F8,
  29046. parenrightex: 0xF8F7,
  29047. parenrightinferior: 0x208E,
  29048. parenrightmonospace: 0xFF09,
  29049. parenrightsmall: 0xFE5A,
  29050. parenrightsuperior: 0x207E,
  29051. parenrighttp: 0xF8F6,
  29052. parenrightvertical: 0xFE36,
  29053. partialdiff: 0x2202,
  29054. paseqhebrew: 0x05C0,
  29055. pashtahebrew: 0x0599,
  29056. pasquare: 0x33A9,
  29057. patah: 0x05B7,
  29058. patah11: 0x05B7,
  29059. patah1d: 0x05B7,
  29060. patah2a: 0x05B7,
  29061. patahhebrew: 0x05B7,
  29062. patahnarrowhebrew: 0x05B7,
  29063. patahquarterhebrew: 0x05B7,
  29064. patahwidehebrew: 0x05B7,
  29065. pazerhebrew: 0x05A1,
  29066. pbopomofo: 0x3106,
  29067. pcircle: 0x24DF,
  29068. pdotaccent: 0x1E57,
  29069. pe: 0x05E4,
  29070. pecyrillic: 0x043F,
  29071. pedagesh: 0xFB44,
  29072. pedageshhebrew: 0xFB44,
  29073. peezisquare: 0x333B,
  29074. pefinaldageshhebrew: 0xFB43,
  29075. peharabic: 0x067E,
  29076. peharmenian: 0x057A,
  29077. pehebrew: 0x05E4,
  29078. pehfinalarabic: 0xFB57,
  29079. pehinitialarabic: 0xFB58,
  29080. pehiragana: 0x307A,
  29081. pehmedialarabic: 0xFB59,
  29082. pekatakana: 0x30DA,
  29083. pemiddlehookcyrillic: 0x04A7,
  29084. perafehebrew: 0xFB4E,
  29085. percent: 0x0025,
  29086. percentarabic: 0x066A,
  29087. percentmonospace: 0xFF05,
  29088. percentsmall: 0xFE6A,
  29089. period: 0x002E,
  29090. periodarmenian: 0x0589,
  29091. periodcentered: 0x00B7,
  29092. periodhalfwidth: 0xFF61,
  29093. periodinferior: 0xF6E7,
  29094. periodmonospace: 0xFF0E,
  29095. periodsmall: 0xFE52,
  29096. periodsuperior: 0xF6E8,
  29097. perispomenigreekcmb: 0x0342,
  29098. perpendicular: 0x22A5,
  29099. perthousand: 0x2030,
  29100. peseta: 0x20A7,
  29101. pfsquare: 0x338A,
  29102. phabengali: 0x09AB,
  29103. phadeva: 0x092B,
  29104. phagujarati: 0x0AAB,
  29105. phagurmukhi: 0x0A2B,
  29106. phi: 0x03C6,
  29107. phi1: 0x03D5,
  29108. phieuphacirclekorean: 0x327A,
  29109. phieuphaparenkorean: 0x321A,
  29110. phieuphcirclekorean: 0x326C,
  29111. phieuphkorean: 0x314D,
  29112. phieuphparenkorean: 0x320C,
  29113. philatin: 0x0278,
  29114. phinthuthai: 0x0E3A,
  29115. phisymbolgreek: 0x03D5,
  29116. phook: 0x01A5,
  29117. phophanthai: 0x0E1E,
  29118. phophungthai: 0x0E1C,
  29119. phosamphaothai: 0x0E20,
  29120. pi: 0x03C0,
  29121. pieupacirclekorean: 0x3273,
  29122. pieupaparenkorean: 0x3213,
  29123. pieupcieuckorean: 0x3176,
  29124. pieupcirclekorean: 0x3265,
  29125. pieupkiyeokkorean: 0x3172,
  29126. pieupkorean: 0x3142,
  29127. pieupparenkorean: 0x3205,
  29128. pieupsioskiyeokkorean: 0x3174,
  29129. pieupsioskorean: 0x3144,
  29130. pieupsiostikeutkorean: 0x3175,
  29131. pieupthieuthkorean: 0x3177,
  29132. pieuptikeutkorean: 0x3173,
  29133. pihiragana: 0x3074,
  29134. pikatakana: 0x30D4,
  29135. pisymbolgreek: 0x03D6,
  29136. piwrarmenian: 0x0583,
  29137. plus: 0x002B,
  29138. plusbelowcmb: 0x031F,
  29139. pluscircle: 0x2295,
  29140. plusminus: 0x00B1,
  29141. plusmod: 0x02D6,
  29142. plusmonospace: 0xFF0B,
  29143. plussmall: 0xFE62,
  29144. plussuperior: 0x207A,
  29145. pmonospace: 0xFF50,
  29146. pmsquare: 0x33D8,
  29147. pohiragana: 0x307D,
  29148. pointingindexdownwhite: 0x261F,
  29149. pointingindexleftwhite: 0x261C,
  29150. pointingindexrightwhite: 0x261E,
  29151. pointingindexupwhite: 0x261D,
  29152. pokatakana: 0x30DD,
  29153. poplathai: 0x0E1B,
  29154. postalmark: 0x3012,
  29155. postalmarkface: 0x3020,
  29156. pparen: 0x24AB,
  29157. precedes: 0x227A,
  29158. prescription: 0x211E,
  29159. primemod: 0x02B9,
  29160. primereversed: 0x2035,
  29161. product: 0x220F,
  29162. projective: 0x2305,
  29163. prolongedkana: 0x30FC,
  29164. propellor: 0x2318,
  29165. propersubset: 0x2282,
  29166. propersuperset: 0x2283,
  29167. proportion: 0x2237,
  29168. proportional: 0x221D,
  29169. psi: 0x03C8,
  29170. psicyrillic: 0x0471,
  29171. psilipneumatacyrilliccmb: 0x0486,
  29172. pssquare: 0x33B0,
  29173. puhiragana: 0x3077,
  29174. pukatakana: 0x30D7,
  29175. pvsquare: 0x33B4,
  29176. pwsquare: 0x33BA,
  29177. q: 0x0071,
  29178. qadeva: 0x0958,
  29179. qadmahebrew: 0x05A8,
  29180. qafarabic: 0x0642,
  29181. qaffinalarabic: 0xFED6,
  29182. qafinitialarabic: 0xFED7,
  29183. qafmedialarabic: 0xFED8,
  29184. qamats: 0x05B8,
  29185. qamats10: 0x05B8,
  29186. qamats1a: 0x05B8,
  29187. qamats1c: 0x05B8,
  29188. qamats27: 0x05B8,
  29189. qamats29: 0x05B8,
  29190. qamats33: 0x05B8,
  29191. qamatsde: 0x05B8,
  29192. qamatshebrew: 0x05B8,
  29193. qamatsnarrowhebrew: 0x05B8,
  29194. qamatsqatanhebrew: 0x05B8,
  29195. qamatsqatannarrowhebrew: 0x05B8,
  29196. qamatsqatanquarterhebrew: 0x05B8,
  29197. qamatsqatanwidehebrew: 0x05B8,
  29198. qamatsquarterhebrew: 0x05B8,
  29199. qamatswidehebrew: 0x05B8,
  29200. qarneyparahebrew: 0x059F,
  29201. qbopomofo: 0x3111,
  29202. qcircle: 0x24E0,
  29203. qhook: 0x02A0,
  29204. qmonospace: 0xFF51,
  29205. qof: 0x05E7,
  29206. qofdagesh: 0xFB47,
  29207. qofdageshhebrew: 0xFB47,
  29208. qofhebrew: 0x05E7,
  29209. qparen: 0x24AC,
  29210. quarternote: 0x2669,
  29211. qubuts: 0x05BB,
  29212. qubuts18: 0x05BB,
  29213. qubuts25: 0x05BB,
  29214. qubuts31: 0x05BB,
  29215. qubutshebrew: 0x05BB,
  29216. qubutsnarrowhebrew: 0x05BB,
  29217. qubutsquarterhebrew: 0x05BB,
  29218. qubutswidehebrew: 0x05BB,
  29219. question: 0x003F,
  29220. questionarabic: 0x061F,
  29221. questionarmenian: 0x055E,
  29222. questiondown: 0x00BF,
  29223. questiondownsmall: 0xF7BF,
  29224. questiongreek: 0x037E,
  29225. questionmonospace: 0xFF1F,
  29226. questionsmall: 0xF73F,
  29227. quotedbl: 0x0022,
  29228. quotedblbase: 0x201E,
  29229. quotedblleft: 0x201C,
  29230. quotedblmonospace: 0xFF02,
  29231. quotedblprime: 0x301E,
  29232. quotedblprimereversed: 0x301D,
  29233. quotedblright: 0x201D,
  29234. quoteleft: 0x2018,
  29235. quoteleftreversed: 0x201B,
  29236. quotereversed: 0x201B,
  29237. quoteright: 0x2019,
  29238. quoterightn: 0x0149,
  29239. quotesinglbase: 0x201A,
  29240. quotesingle: 0x0027,
  29241. quotesinglemonospace: 0xFF07,
  29242. r: 0x0072,
  29243. raarmenian: 0x057C,
  29244. rabengali: 0x09B0,
  29245. racute: 0x0155,
  29246. radeva: 0x0930,
  29247. radical: 0x221A,
  29248. radicalex: 0xF8E5,
  29249. radoverssquare: 0x33AE,
  29250. radoverssquaredsquare: 0x33AF,
  29251. radsquare: 0x33AD,
  29252. rafe: 0x05BF,
  29253. rafehebrew: 0x05BF,
  29254. ragujarati: 0x0AB0,
  29255. ragurmukhi: 0x0A30,
  29256. rahiragana: 0x3089,
  29257. rakatakana: 0x30E9,
  29258. rakatakanahalfwidth: 0xFF97,
  29259. ralowerdiagonalbengali: 0x09F1,
  29260. ramiddlediagonalbengali: 0x09F0,
  29261. ramshorn: 0x0264,
  29262. ratio: 0x2236,
  29263. rbopomofo: 0x3116,
  29264. rcaron: 0x0159,
  29265. rcedilla: 0x0157,
  29266. rcircle: 0x24E1,
  29267. rcommaaccent: 0x0157,
  29268. rdblgrave: 0x0211,
  29269. rdotaccent: 0x1E59,
  29270. rdotbelow: 0x1E5B,
  29271. rdotbelowmacron: 0x1E5D,
  29272. referencemark: 0x203B,
  29273. reflexsubset: 0x2286,
  29274. reflexsuperset: 0x2287,
  29275. registered: 0x00AE,
  29276. registersans: 0xF8E8,
  29277. registerserif: 0xF6DA,
  29278. reharabic: 0x0631,
  29279. reharmenian: 0x0580,
  29280. rehfinalarabic: 0xFEAE,
  29281. rehiragana: 0x308C,
  29282. rekatakana: 0x30EC,
  29283. rekatakanahalfwidth: 0xFF9A,
  29284. resh: 0x05E8,
  29285. reshdageshhebrew: 0xFB48,
  29286. reshhebrew: 0x05E8,
  29287. reversedtilde: 0x223D,
  29288. reviahebrew: 0x0597,
  29289. reviamugrashhebrew: 0x0597,
  29290. revlogicalnot: 0x2310,
  29291. rfishhook: 0x027E,
  29292. rfishhookreversed: 0x027F,
  29293. rhabengali: 0x09DD,
  29294. rhadeva: 0x095D,
  29295. rho: 0x03C1,
  29296. rhook: 0x027D,
  29297. rhookturned: 0x027B,
  29298. rhookturnedsuperior: 0x02B5,
  29299. rhosymbolgreek: 0x03F1,
  29300. rhotichookmod: 0x02DE,
  29301. rieulacirclekorean: 0x3271,
  29302. rieulaparenkorean: 0x3211,
  29303. rieulcirclekorean: 0x3263,
  29304. rieulhieuhkorean: 0x3140,
  29305. rieulkiyeokkorean: 0x313A,
  29306. rieulkiyeoksioskorean: 0x3169,
  29307. rieulkorean: 0x3139,
  29308. rieulmieumkorean: 0x313B,
  29309. rieulpansioskorean: 0x316C,
  29310. rieulparenkorean: 0x3203,
  29311. rieulphieuphkorean: 0x313F,
  29312. rieulpieupkorean: 0x313C,
  29313. rieulpieupsioskorean: 0x316B,
  29314. rieulsioskorean: 0x313D,
  29315. rieulthieuthkorean: 0x313E,
  29316. rieultikeutkorean: 0x316A,
  29317. rieulyeorinhieuhkorean: 0x316D,
  29318. rightangle: 0x221F,
  29319. righttackbelowcmb: 0x0319,
  29320. righttriangle: 0x22BF,
  29321. rihiragana: 0x308A,
  29322. rikatakana: 0x30EA,
  29323. rikatakanahalfwidth: 0xFF98,
  29324. ring: 0x02DA,
  29325. ringbelowcmb: 0x0325,
  29326. ringcmb: 0x030A,
  29327. ringhalfleft: 0x02BF,
  29328. ringhalfleftarmenian: 0x0559,
  29329. ringhalfleftbelowcmb: 0x031C,
  29330. ringhalfleftcentered: 0x02D3,
  29331. ringhalfright: 0x02BE,
  29332. ringhalfrightbelowcmb: 0x0339,
  29333. ringhalfrightcentered: 0x02D2,
  29334. rinvertedbreve: 0x0213,
  29335. rittorusquare: 0x3351,
  29336. rlinebelow: 0x1E5F,
  29337. rlongleg: 0x027C,
  29338. rlonglegturned: 0x027A,
  29339. rmonospace: 0xFF52,
  29340. rohiragana: 0x308D,
  29341. rokatakana: 0x30ED,
  29342. rokatakanahalfwidth: 0xFF9B,
  29343. roruathai: 0x0E23,
  29344. rparen: 0x24AD,
  29345. rrabengali: 0x09DC,
  29346. rradeva: 0x0931,
  29347. rragurmukhi: 0x0A5C,
  29348. rreharabic: 0x0691,
  29349. rrehfinalarabic: 0xFB8D,
  29350. rrvocalicbengali: 0x09E0,
  29351. rrvocalicdeva: 0x0960,
  29352. rrvocalicgujarati: 0x0AE0,
  29353. rrvocalicvowelsignbengali: 0x09C4,
  29354. rrvocalicvowelsigndeva: 0x0944,
  29355. rrvocalicvowelsigngujarati: 0x0AC4,
  29356. rsuperior: 0xF6F1,
  29357. rtblock: 0x2590,
  29358. rturned: 0x0279,
  29359. rturnedsuperior: 0x02B4,
  29360. ruhiragana: 0x308B,
  29361. rukatakana: 0x30EB,
  29362. rukatakanahalfwidth: 0xFF99,
  29363. rupeemarkbengali: 0x09F2,
  29364. rupeesignbengali: 0x09F3,
  29365. rupiah: 0xF6DD,
  29366. ruthai: 0x0E24,
  29367. rvocalicbengali: 0x098B,
  29368. rvocalicdeva: 0x090B,
  29369. rvocalicgujarati: 0x0A8B,
  29370. rvocalicvowelsignbengali: 0x09C3,
  29371. rvocalicvowelsigndeva: 0x0943,
  29372. rvocalicvowelsigngujarati: 0x0AC3,
  29373. s: 0x0073,
  29374. sabengali: 0x09B8,
  29375. sacute: 0x015B,
  29376. sacutedotaccent: 0x1E65,
  29377. sadarabic: 0x0635,
  29378. sadeva: 0x0938,
  29379. sadfinalarabic: 0xFEBA,
  29380. sadinitialarabic: 0xFEBB,
  29381. sadmedialarabic: 0xFEBC,
  29382. sagujarati: 0x0AB8,
  29383. sagurmukhi: 0x0A38,
  29384. sahiragana: 0x3055,
  29385. sakatakana: 0x30B5,
  29386. sakatakanahalfwidth: 0xFF7B,
  29387. sallallahoualayhewasallamarabic: 0xFDFA,
  29388. samekh: 0x05E1,
  29389. samekhdagesh: 0xFB41,
  29390. samekhdageshhebrew: 0xFB41,
  29391. samekhhebrew: 0x05E1,
  29392. saraaathai: 0x0E32,
  29393. saraaethai: 0x0E41,
  29394. saraaimaimalaithai: 0x0E44,
  29395. saraaimaimuanthai: 0x0E43,
  29396. saraamthai: 0x0E33,
  29397. saraathai: 0x0E30,
  29398. saraethai: 0x0E40,
  29399. saraiileftthai: 0xF886,
  29400. saraiithai: 0x0E35,
  29401. saraileftthai: 0xF885,
  29402. saraithai: 0x0E34,
  29403. saraothai: 0x0E42,
  29404. saraueeleftthai: 0xF888,
  29405. saraueethai: 0x0E37,
  29406. saraueleftthai: 0xF887,
  29407. sarauethai: 0x0E36,
  29408. sarauthai: 0x0E38,
  29409. sarauuthai: 0x0E39,
  29410. sbopomofo: 0x3119,
  29411. scaron: 0x0161,
  29412. scarondotaccent: 0x1E67,
  29413. scedilla: 0x015F,
  29414. schwa: 0x0259,
  29415. schwacyrillic: 0x04D9,
  29416. schwadieresiscyrillic: 0x04DB,
  29417. schwahook: 0x025A,
  29418. scircle: 0x24E2,
  29419. scircumflex: 0x015D,
  29420. scommaaccent: 0x0219,
  29421. sdotaccent: 0x1E61,
  29422. sdotbelow: 0x1E63,
  29423. sdotbelowdotaccent: 0x1E69,
  29424. seagullbelowcmb: 0x033C,
  29425. second: 0x2033,
  29426. secondtonechinese: 0x02CA,
  29427. section: 0x00A7,
  29428. seenarabic: 0x0633,
  29429. seenfinalarabic: 0xFEB2,
  29430. seeninitialarabic: 0xFEB3,
  29431. seenmedialarabic: 0xFEB4,
  29432. segol: 0x05B6,
  29433. segol13: 0x05B6,
  29434. segol1f: 0x05B6,
  29435. segol2c: 0x05B6,
  29436. segolhebrew: 0x05B6,
  29437. segolnarrowhebrew: 0x05B6,
  29438. segolquarterhebrew: 0x05B6,
  29439. segoltahebrew: 0x0592,
  29440. segolwidehebrew: 0x05B6,
  29441. seharmenian: 0x057D,
  29442. sehiragana: 0x305B,
  29443. sekatakana: 0x30BB,
  29444. sekatakanahalfwidth: 0xFF7E,
  29445. semicolon: 0x003B,
  29446. semicolonarabic: 0x061B,
  29447. semicolonmonospace: 0xFF1B,
  29448. semicolonsmall: 0xFE54,
  29449. semivoicedmarkkana: 0x309C,
  29450. semivoicedmarkkanahalfwidth: 0xFF9F,
  29451. sentisquare: 0x3322,
  29452. sentosquare: 0x3323,
  29453. seven: 0x0037,
  29454. sevenarabic: 0x0667,
  29455. sevenbengali: 0x09ED,
  29456. sevencircle: 0x2466,
  29457. sevencircleinversesansserif: 0x2790,
  29458. sevendeva: 0x096D,
  29459. seveneighths: 0x215E,
  29460. sevengujarati: 0x0AED,
  29461. sevengurmukhi: 0x0A6D,
  29462. sevenhackarabic: 0x0667,
  29463. sevenhangzhou: 0x3027,
  29464. sevenideographicparen: 0x3226,
  29465. seveninferior: 0x2087,
  29466. sevenmonospace: 0xFF17,
  29467. sevenoldstyle: 0xF737,
  29468. sevenparen: 0x247A,
  29469. sevenperiod: 0x248E,
  29470. sevenpersian: 0x06F7,
  29471. sevenroman: 0x2176,
  29472. sevensuperior: 0x2077,
  29473. seventeencircle: 0x2470,
  29474. seventeenparen: 0x2484,
  29475. seventeenperiod: 0x2498,
  29476. seventhai: 0x0E57,
  29477. sfthyphen: 0x00AD,
  29478. shaarmenian: 0x0577,
  29479. shabengali: 0x09B6,
  29480. shacyrillic: 0x0448,
  29481. shaddaarabic: 0x0651,
  29482. shaddadammaarabic: 0xFC61,
  29483. shaddadammatanarabic: 0xFC5E,
  29484. shaddafathaarabic: 0xFC60,
  29485. shaddakasraarabic: 0xFC62,
  29486. shaddakasratanarabic: 0xFC5F,
  29487. shade: 0x2592,
  29488. shadedark: 0x2593,
  29489. shadelight: 0x2591,
  29490. shademedium: 0x2592,
  29491. shadeva: 0x0936,
  29492. shagujarati: 0x0AB6,
  29493. shagurmukhi: 0x0A36,
  29494. shalshelethebrew: 0x0593,
  29495. shbopomofo: 0x3115,
  29496. shchacyrillic: 0x0449,
  29497. sheenarabic: 0x0634,
  29498. sheenfinalarabic: 0xFEB6,
  29499. sheeninitialarabic: 0xFEB7,
  29500. sheenmedialarabic: 0xFEB8,
  29501. sheicoptic: 0x03E3,
  29502. sheqel: 0x20AA,
  29503. sheqelhebrew: 0x20AA,
  29504. sheva: 0x05B0,
  29505. sheva115: 0x05B0,
  29506. sheva15: 0x05B0,
  29507. sheva22: 0x05B0,
  29508. sheva2e: 0x05B0,
  29509. shevahebrew: 0x05B0,
  29510. shevanarrowhebrew: 0x05B0,
  29511. shevaquarterhebrew: 0x05B0,
  29512. shevawidehebrew: 0x05B0,
  29513. shhacyrillic: 0x04BB,
  29514. shimacoptic: 0x03ED,
  29515. shin: 0x05E9,
  29516. shindagesh: 0xFB49,
  29517. shindageshhebrew: 0xFB49,
  29518. shindageshshindot: 0xFB2C,
  29519. shindageshshindothebrew: 0xFB2C,
  29520. shindageshsindot: 0xFB2D,
  29521. shindageshsindothebrew: 0xFB2D,
  29522. shindothebrew: 0x05C1,
  29523. shinhebrew: 0x05E9,
  29524. shinshindot: 0xFB2A,
  29525. shinshindothebrew: 0xFB2A,
  29526. shinsindot: 0xFB2B,
  29527. shinsindothebrew: 0xFB2B,
  29528. shook: 0x0282,
  29529. sigma: 0x03C3,
  29530. sigma1: 0x03C2,
  29531. sigmafinal: 0x03C2,
  29532. sigmalunatesymbolgreek: 0x03F2,
  29533. sihiragana: 0x3057,
  29534. sikatakana: 0x30B7,
  29535. sikatakanahalfwidth: 0xFF7C,
  29536. siluqhebrew: 0x05BD,
  29537. siluqlefthebrew: 0x05BD,
  29538. similar: 0x223C,
  29539. sindothebrew: 0x05C2,
  29540. siosacirclekorean: 0x3274,
  29541. siosaparenkorean: 0x3214,
  29542. sioscieuckorean: 0x317E,
  29543. sioscirclekorean: 0x3266,
  29544. sioskiyeokkorean: 0x317A,
  29545. sioskorean: 0x3145,
  29546. siosnieunkorean: 0x317B,
  29547. siosparenkorean: 0x3206,
  29548. siospieupkorean: 0x317D,
  29549. siostikeutkorean: 0x317C,
  29550. six: 0x0036,
  29551. sixarabic: 0x0666,
  29552. sixbengali: 0x09EC,
  29553. sixcircle: 0x2465,
  29554. sixcircleinversesansserif: 0x278F,
  29555. sixdeva: 0x096C,
  29556. sixgujarati: 0x0AEC,
  29557. sixgurmukhi: 0x0A6C,
  29558. sixhackarabic: 0x0666,
  29559. sixhangzhou: 0x3026,
  29560. sixideographicparen: 0x3225,
  29561. sixinferior: 0x2086,
  29562. sixmonospace: 0xFF16,
  29563. sixoldstyle: 0xF736,
  29564. sixparen: 0x2479,
  29565. sixperiod: 0x248D,
  29566. sixpersian: 0x06F6,
  29567. sixroman: 0x2175,
  29568. sixsuperior: 0x2076,
  29569. sixteencircle: 0x246F,
  29570. sixteencurrencydenominatorbengali: 0x09F9,
  29571. sixteenparen: 0x2483,
  29572. sixteenperiod: 0x2497,
  29573. sixthai: 0x0E56,
  29574. slash: 0x002F,
  29575. slashmonospace: 0xFF0F,
  29576. slong: 0x017F,
  29577. slongdotaccent: 0x1E9B,
  29578. smileface: 0x263A,
  29579. smonospace: 0xFF53,
  29580. sofpasuqhebrew: 0x05C3,
  29581. softhyphen: 0x00AD,
  29582. softsigncyrillic: 0x044C,
  29583. sohiragana: 0x305D,
  29584. sokatakana: 0x30BD,
  29585. sokatakanahalfwidth: 0xFF7F,
  29586. soliduslongoverlaycmb: 0x0338,
  29587. solidusshortoverlaycmb: 0x0337,
  29588. sorusithai: 0x0E29,
  29589. sosalathai: 0x0E28,
  29590. sosothai: 0x0E0B,
  29591. sosuathai: 0x0E2A,
  29592. space: 0x0020,
  29593. spacehackarabic: 0x0020,
  29594. spade: 0x2660,
  29595. spadesuitblack: 0x2660,
  29596. spadesuitwhite: 0x2664,
  29597. sparen: 0x24AE,
  29598. squarebelowcmb: 0x033B,
  29599. squarecc: 0x33C4,
  29600. squarecm: 0x339D,
  29601. squarediagonalcrosshatchfill: 0x25A9,
  29602. squarehorizontalfill: 0x25A4,
  29603. squarekg: 0x338F,
  29604. squarekm: 0x339E,
  29605. squarekmcapital: 0x33CE,
  29606. squareln: 0x33D1,
  29607. squarelog: 0x33D2,
  29608. squaremg: 0x338E,
  29609. squaremil: 0x33D5,
  29610. squaremm: 0x339C,
  29611. squaremsquared: 0x33A1,
  29612. squareorthogonalcrosshatchfill: 0x25A6,
  29613. squareupperlefttolowerrightfill: 0x25A7,
  29614. squareupperrighttolowerleftfill: 0x25A8,
  29615. squareverticalfill: 0x25A5,
  29616. squarewhitewithsmallblack: 0x25A3,
  29617. srsquare: 0x33DB,
  29618. ssabengali: 0x09B7,
  29619. ssadeva: 0x0937,
  29620. ssagujarati: 0x0AB7,
  29621. ssangcieuckorean: 0x3149,
  29622. ssanghieuhkorean: 0x3185,
  29623. ssangieungkorean: 0x3180,
  29624. ssangkiyeokkorean: 0x3132,
  29625. ssangnieunkorean: 0x3165,
  29626. ssangpieupkorean: 0x3143,
  29627. ssangsioskorean: 0x3146,
  29628. ssangtikeutkorean: 0x3138,
  29629. ssuperior: 0xF6F2,
  29630. sterling: 0x00A3,
  29631. sterlingmonospace: 0xFFE1,
  29632. strokelongoverlaycmb: 0x0336,
  29633. strokeshortoverlaycmb: 0x0335,
  29634. subset: 0x2282,
  29635. subsetnotequal: 0x228A,
  29636. subsetorequal: 0x2286,
  29637. succeeds: 0x227B,
  29638. suchthat: 0x220B,
  29639. suhiragana: 0x3059,
  29640. sukatakana: 0x30B9,
  29641. sukatakanahalfwidth: 0xFF7D,
  29642. sukunarabic: 0x0652,
  29643. summation: 0x2211,
  29644. sun: 0x263C,
  29645. superset: 0x2283,
  29646. supersetnotequal: 0x228B,
  29647. supersetorequal: 0x2287,
  29648. svsquare: 0x33DC,
  29649. syouwaerasquare: 0x337C,
  29650. t: 0x0074,
  29651. tabengali: 0x09A4,
  29652. tackdown: 0x22A4,
  29653. tackleft: 0x22A3,
  29654. tadeva: 0x0924,
  29655. tagujarati: 0x0AA4,
  29656. tagurmukhi: 0x0A24,
  29657. taharabic: 0x0637,
  29658. tahfinalarabic: 0xFEC2,
  29659. tahinitialarabic: 0xFEC3,
  29660. tahiragana: 0x305F,
  29661. tahmedialarabic: 0xFEC4,
  29662. taisyouerasquare: 0x337D,
  29663. takatakana: 0x30BF,
  29664. takatakanahalfwidth: 0xFF80,
  29665. tatweelarabic: 0x0640,
  29666. tau: 0x03C4,
  29667. tav: 0x05EA,
  29668. tavdages: 0xFB4A,
  29669. tavdagesh: 0xFB4A,
  29670. tavdageshhebrew: 0xFB4A,
  29671. tavhebrew: 0x05EA,
  29672. tbar: 0x0167,
  29673. tbopomofo: 0x310A,
  29674. tcaron: 0x0165,
  29675. tccurl: 0x02A8,
  29676. tcedilla: 0x0163,
  29677. tcheharabic: 0x0686,
  29678. tchehfinalarabic: 0xFB7B,
  29679. tchehinitialarabic: 0xFB7C,
  29680. tchehmedialarabic: 0xFB7D,
  29681. tcircle: 0x24E3,
  29682. tcircumflexbelow: 0x1E71,
  29683. tcommaaccent: 0x0163,
  29684. tdieresis: 0x1E97,
  29685. tdotaccent: 0x1E6B,
  29686. tdotbelow: 0x1E6D,
  29687. tecyrillic: 0x0442,
  29688. tedescendercyrillic: 0x04AD,
  29689. teharabic: 0x062A,
  29690. tehfinalarabic: 0xFE96,
  29691. tehhahinitialarabic: 0xFCA2,
  29692. tehhahisolatedarabic: 0xFC0C,
  29693. tehinitialarabic: 0xFE97,
  29694. tehiragana: 0x3066,
  29695. tehjeeminitialarabic: 0xFCA1,
  29696. tehjeemisolatedarabic: 0xFC0B,
  29697. tehmarbutaarabic: 0x0629,
  29698. tehmarbutafinalarabic: 0xFE94,
  29699. tehmedialarabic: 0xFE98,
  29700. tehmeeminitialarabic: 0xFCA4,
  29701. tehmeemisolatedarabic: 0xFC0E,
  29702. tehnoonfinalarabic: 0xFC73,
  29703. tekatakana: 0x30C6,
  29704. tekatakanahalfwidth: 0xFF83,
  29705. telephone: 0x2121,
  29706. telephoneblack: 0x260E,
  29707. telishagedolahebrew: 0x05A0,
  29708. telishaqetanahebrew: 0x05A9,
  29709. tencircle: 0x2469,
  29710. tenideographicparen: 0x3229,
  29711. tenparen: 0x247D,
  29712. tenperiod: 0x2491,
  29713. tenroman: 0x2179,
  29714. tesh: 0x02A7,
  29715. tet: 0x05D8,
  29716. tetdagesh: 0xFB38,
  29717. tetdageshhebrew: 0xFB38,
  29718. tethebrew: 0x05D8,
  29719. tetsecyrillic: 0x04B5,
  29720. tevirhebrew: 0x059B,
  29721. tevirlefthebrew: 0x059B,
  29722. thabengali: 0x09A5,
  29723. thadeva: 0x0925,
  29724. thagujarati: 0x0AA5,
  29725. thagurmukhi: 0x0A25,
  29726. thalarabic: 0x0630,
  29727. thalfinalarabic: 0xFEAC,
  29728. thanthakhatlowleftthai: 0xF898,
  29729. thanthakhatlowrightthai: 0xF897,
  29730. thanthakhatthai: 0x0E4C,
  29731. thanthakhatupperleftthai: 0xF896,
  29732. theharabic: 0x062B,
  29733. thehfinalarabic: 0xFE9A,
  29734. thehinitialarabic: 0xFE9B,
  29735. thehmedialarabic: 0xFE9C,
  29736. thereexists: 0x2203,
  29737. therefore: 0x2234,
  29738. theta: 0x03B8,
  29739. theta1: 0x03D1,
  29740. thetasymbolgreek: 0x03D1,
  29741. thieuthacirclekorean: 0x3279,
  29742. thieuthaparenkorean: 0x3219,
  29743. thieuthcirclekorean: 0x326B,
  29744. thieuthkorean: 0x314C,
  29745. thieuthparenkorean: 0x320B,
  29746. thirteencircle: 0x246C,
  29747. thirteenparen: 0x2480,
  29748. thirteenperiod: 0x2494,
  29749. thonangmonthothai: 0x0E11,
  29750. thook: 0x01AD,
  29751. thophuthaothai: 0x0E12,
  29752. thorn: 0x00FE,
  29753. thothahanthai: 0x0E17,
  29754. thothanthai: 0x0E10,
  29755. thothongthai: 0x0E18,
  29756. thothungthai: 0x0E16,
  29757. thousandcyrillic: 0x0482,
  29758. thousandsseparatorarabic: 0x066C,
  29759. thousandsseparatorpersian: 0x066C,
  29760. three: 0x0033,
  29761. threearabic: 0x0663,
  29762. threebengali: 0x09E9,
  29763. threecircle: 0x2462,
  29764. threecircleinversesansserif: 0x278C,
  29765. threedeva: 0x0969,
  29766. threeeighths: 0x215C,
  29767. threegujarati: 0x0AE9,
  29768. threegurmukhi: 0x0A69,
  29769. threehackarabic: 0x0663,
  29770. threehangzhou: 0x3023,
  29771. threeideographicparen: 0x3222,
  29772. threeinferior: 0x2083,
  29773. threemonospace: 0xFF13,
  29774. threenumeratorbengali: 0x09F6,
  29775. threeoldstyle: 0xF733,
  29776. threeparen: 0x2476,
  29777. threeperiod: 0x248A,
  29778. threepersian: 0x06F3,
  29779. threequarters: 0x00BE,
  29780. threequartersemdash: 0xF6DE,
  29781. threeroman: 0x2172,
  29782. threesuperior: 0x00B3,
  29783. threethai: 0x0E53,
  29784. thzsquare: 0x3394,
  29785. tihiragana: 0x3061,
  29786. tikatakana: 0x30C1,
  29787. tikatakanahalfwidth: 0xFF81,
  29788. tikeutacirclekorean: 0x3270,
  29789. tikeutaparenkorean: 0x3210,
  29790. tikeutcirclekorean: 0x3262,
  29791. tikeutkorean: 0x3137,
  29792. tikeutparenkorean: 0x3202,
  29793. tilde: 0x02DC,
  29794. tildebelowcmb: 0x0330,
  29795. tildecmb: 0x0303,
  29796. tildecomb: 0x0303,
  29797. tildedoublecmb: 0x0360,
  29798. tildeoperator: 0x223C,
  29799. tildeoverlaycmb: 0x0334,
  29800. tildeverticalcmb: 0x033E,
  29801. timescircle: 0x2297,
  29802. tipehahebrew: 0x0596,
  29803. tipehalefthebrew: 0x0596,
  29804. tippigurmukhi: 0x0A70,
  29805. titlocyrilliccmb: 0x0483,
  29806. tiwnarmenian: 0x057F,
  29807. tlinebelow: 0x1E6F,
  29808. tmonospace: 0xFF54,
  29809. toarmenian: 0x0569,
  29810. tohiragana: 0x3068,
  29811. tokatakana: 0x30C8,
  29812. tokatakanahalfwidth: 0xFF84,
  29813. tonebarextrahighmod: 0x02E5,
  29814. tonebarextralowmod: 0x02E9,
  29815. tonebarhighmod: 0x02E6,
  29816. tonebarlowmod: 0x02E8,
  29817. tonebarmidmod: 0x02E7,
  29818. tonefive: 0x01BD,
  29819. tonesix: 0x0185,
  29820. tonetwo: 0x01A8,
  29821. tonos: 0x0384,
  29822. tonsquare: 0x3327,
  29823. topatakthai: 0x0E0F,
  29824. tortoiseshellbracketleft: 0x3014,
  29825. tortoiseshellbracketleftsmall: 0xFE5D,
  29826. tortoiseshellbracketleftvertical: 0xFE39,
  29827. tortoiseshellbracketright: 0x3015,
  29828. tortoiseshellbracketrightsmall: 0xFE5E,
  29829. tortoiseshellbracketrightvertical: 0xFE3A,
  29830. totaothai: 0x0E15,
  29831. tpalatalhook: 0x01AB,
  29832. tparen: 0x24AF,
  29833. trademark: 0x2122,
  29834. trademarksans: 0xF8EA,
  29835. trademarkserif: 0xF6DB,
  29836. tretroflexhook: 0x0288,
  29837. triagdn: 0x25BC,
  29838. triaglf: 0x25C4,
  29839. triagrt: 0x25BA,
  29840. triagup: 0x25B2,
  29841. ts: 0x02A6,
  29842. tsadi: 0x05E6,
  29843. tsadidagesh: 0xFB46,
  29844. tsadidageshhebrew: 0xFB46,
  29845. tsadihebrew: 0x05E6,
  29846. tsecyrillic: 0x0446,
  29847. tsere: 0x05B5,
  29848. tsere12: 0x05B5,
  29849. tsere1e: 0x05B5,
  29850. tsere2b: 0x05B5,
  29851. tserehebrew: 0x05B5,
  29852. tserenarrowhebrew: 0x05B5,
  29853. tserequarterhebrew: 0x05B5,
  29854. tserewidehebrew: 0x05B5,
  29855. tshecyrillic: 0x045B,
  29856. tsuperior: 0xF6F3,
  29857. ttabengali: 0x099F,
  29858. ttadeva: 0x091F,
  29859. ttagujarati: 0x0A9F,
  29860. ttagurmukhi: 0x0A1F,
  29861. tteharabic: 0x0679,
  29862. ttehfinalarabic: 0xFB67,
  29863. ttehinitialarabic: 0xFB68,
  29864. ttehmedialarabic: 0xFB69,
  29865. tthabengali: 0x09A0,
  29866. tthadeva: 0x0920,
  29867. tthagujarati: 0x0AA0,
  29868. tthagurmukhi: 0x0A20,
  29869. tturned: 0x0287,
  29870. tuhiragana: 0x3064,
  29871. tukatakana: 0x30C4,
  29872. tukatakanahalfwidth: 0xFF82,
  29873. tusmallhiragana: 0x3063,
  29874. tusmallkatakana: 0x30C3,
  29875. tusmallkatakanahalfwidth: 0xFF6F,
  29876. twelvecircle: 0x246B,
  29877. twelveparen: 0x247F,
  29878. twelveperiod: 0x2493,
  29879. twelveroman: 0x217B,
  29880. twentycircle: 0x2473,
  29881. twentyhangzhou: 0x5344,
  29882. twentyparen: 0x2487,
  29883. twentyperiod: 0x249B,
  29884. two: 0x0032,
  29885. twoarabic: 0x0662,
  29886. twobengali: 0x09E8,
  29887. twocircle: 0x2461,
  29888. twocircleinversesansserif: 0x278B,
  29889. twodeva: 0x0968,
  29890. twodotenleader: 0x2025,
  29891. twodotleader: 0x2025,
  29892. twodotleadervertical: 0xFE30,
  29893. twogujarati: 0x0AE8,
  29894. twogurmukhi: 0x0A68,
  29895. twohackarabic: 0x0662,
  29896. twohangzhou: 0x3022,
  29897. twoideographicparen: 0x3221,
  29898. twoinferior: 0x2082,
  29899. twomonospace: 0xFF12,
  29900. twonumeratorbengali: 0x09F5,
  29901. twooldstyle: 0xF732,
  29902. twoparen: 0x2475,
  29903. twoperiod: 0x2489,
  29904. twopersian: 0x06F2,
  29905. tworoman: 0x2171,
  29906. twostroke: 0x01BB,
  29907. twosuperior: 0x00B2,
  29908. twothai: 0x0E52,
  29909. twothirds: 0x2154,
  29910. u: 0x0075,
  29911. uacute: 0x00FA,
  29912. ubar: 0x0289,
  29913. ubengali: 0x0989,
  29914. ubopomofo: 0x3128,
  29915. ubreve: 0x016D,
  29916. ucaron: 0x01D4,
  29917. ucircle: 0x24E4,
  29918. ucircumflex: 0x00FB,
  29919. ucircumflexbelow: 0x1E77,
  29920. ucyrillic: 0x0443,
  29921. udattadeva: 0x0951,
  29922. udblacute: 0x0171,
  29923. udblgrave: 0x0215,
  29924. udeva: 0x0909,
  29925. udieresis: 0x00FC,
  29926. udieresisacute: 0x01D8,
  29927. udieresisbelow: 0x1E73,
  29928. udieresiscaron: 0x01DA,
  29929. udieresiscyrillic: 0x04F1,
  29930. udieresisgrave: 0x01DC,
  29931. udieresismacron: 0x01D6,
  29932. udotbelow: 0x1EE5,
  29933. ugrave: 0x00F9,
  29934. ugujarati: 0x0A89,
  29935. ugurmukhi: 0x0A09,
  29936. uhiragana: 0x3046,
  29937. uhookabove: 0x1EE7,
  29938. uhorn: 0x01B0,
  29939. uhornacute: 0x1EE9,
  29940. uhorndotbelow: 0x1EF1,
  29941. uhorngrave: 0x1EEB,
  29942. uhornhookabove: 0x1EED,
  29943. uhorntilde: 0x1EEF,
  29944. uhungarumlaut: 0x0171,
  29945. uhungarumlautcyrillic: 0x04F3,
  29946. uinvertedbreve: 0x0217,
  29947. ukatakana: 0x30A6,
  29948. ukatakanahalfwidth: 0xFF73,
  29949. ukcyrillic: 0x0479,
  29950. ukorean: 0x315C,
  29951. umacron: 0x016B,
  29952. umacroncyrillic: 0x04EF,
  29953. umacrondieresis: 0x1E7B,
  29954. umatragurmukhi: 0x0A41,
  29955. umonospace: 0xFF55,
  29956. underscore: 0x005F,
  29957. underscoredbl: 0x2017,
  29958. underscoremonospace: 0xFF3F,
  29959. underscorevertical: 0xFE33,
  29960. underscorewavy: 0xFE4F,
  29961. union: 0x222A,
  29962. universal: 0x2200,
  29963. uogonek: 0x0173,
  29964. uparen: 0x24B0,
  29965. upblock: 0x2580,
  29966. upperdothebrew: 0x05C4,
  29967. upsilon: 0x03C5,
  29968. upsilondieresis: 0x03CB,
  29969. upsilondieresistonos: 0x03B0,
  29970. upsilonlatin: 0x028A,
  29971. upsilontonos: 0x03CD,
  29972. uptackbelowcmb: 0x031D,
  29973. uptackmod: 0x02D4,
  29974. uragurmukhi: 0x0A73,
  29975. uring: 0x016F,
  29976. ushortcyrillic: 0x045E,
  29977. usmallhiragana: 0x3045,
  29978. usmallkatakana: 0x30A5,
  29979. usmallkatakanahalfwidth: 0xFF69,
  29980. ustraightcyrillic: 0x04AF,
  29981. ustraightstrokecyrillic: 0x04B1,
  29982. utilde: 0x0169,
  29983. utildeacute: 0x1E79,
  29984. utildebelow: 0x1E75,
  29985. uubengali: 0x098A,
  29986. uudeva: 0x090A,
  29987. uugujarati: 0x0A8A,
  29988. uugurmukhi: 0x0A0A,
  29989. uumatragurmukhi: 0x0A42,
  29990. uuvowelsignbengali: 0x09C2,
  29991. uuvowelsigndeva: 0x0942,
  29992. uuvowelsigngujarati: 0x0AC2,
  29993. uvowelsignbengali: 0x09C1,
  29994. uvowelsigndeva: 0x0941,
  29995. uvowelsigngujarati: 0x0AC1,
  29996. v: 0x0076,
  29997. vadeva: 0x0935,
  29998. vagujarati: 0x0AB5,
  29999. vagurmukhi: 0x0A35,
  30000. vakatakana: 0x30F7,
  30001. vav: 0x05D5,
  30002. vavdagesh: 0xFB35,
  30003. vavdagesh65: 0xFB35,
  30004. vavdageshhebrew: 0xFB35,
  30005. vavhebrew: 0x05D5,
  30006. vavholam: 0xFB4B,
  30007. vavholamhebrew: 0xFB4B,
  30008. vavvavhebrew: 0x05F0,
  30009. vavyodhebrew: 0x05F1,
  30010. vcircle: 0x24E5,
  30011. vdotbelow: 0x1E7F,
  30012. vecyrillic: 0x0432,
  30013. veharabic: 0x06A4,
  30014. vehfinalarabic: 0xFB6B,
  30015. vehinitialarabic: 0xFB6C,
  30016. vehmedialarabic: 0xFB6D,
  30017. vekatakana: 0x30F9,
  30018. venus: 0x2640,
  30019. verticalbar: 0x007C,
  30020. verticallineabovecmb: 0x030D,
  30021. verticallinebelowcmb: 0x0329,
  30022. verticallinelowmod: 0x02CC,
  30023. verticallinemod: 0x02C8,
  30024. vewarmenian: 0x057E,
  30025. vhook: 0x028B,
  30026. vikatakana: 0x30F8,
  30027. viramabengali: 0x09CD,
  30028. viramadeva: 0x094D,
  30029. viramagujarati: 0x0ACD,
  30030. visargabengali: 0x0983,
  30031. visargadeva: 0x0903,
  30032. visargagujarati: 0x0A83,
  30033. vmonospace: 0xFF56,
  30034. voarmenian: 0x0578,
  30035. voicediterationhiragana: 0x309E,
  30036. voicediterationkatakana: 0x30FE,
  30037. voicedmarkkana: 0x309B,
  30038. voicedmarkkanahalfwidth: 0xFF9E,
  30039. vokatakana: 0x30FA,
  30040. vparen: 0x24B1,
  30041. vtilde: 0x1E7D,
  30042. vturned: 0x028C,
  30043. vuhiragana: 0x3094,
  30044. vukatakana: 0x30F4,
  30045. w: 0x0077,
  30046. wacute: 0x1E83,
  30047. waekorean: 0x3159,
  30048. wahiragana: 0x308F,
  30049. wakatakana: 0x30EF,
  30050. wakatakanahalfwidth: 0xFF9C,
  30051. wakorean: 0x3158,
  30052. wasmallhiragana: 0x308E,
  30053. wasmallkatakana: 0x30EE,
  30054. wattosquare: 0x3357,
  30055. wavedash: 0x301C,
  30056. wavyunderscorevertical: 0xFE34,
  30057. wawarabic: 0x0648,
  30058. wawfinalarabic: 0xFEEE,
  30059. wawhamzaabovearabic: 0x0624,
  30060. wawhamzaabovefinalarabic: 0xFE86,
  30061. wbsquare: 0x33DD,
  30062. wcircle: 0x24E6,
  30063. wcircumflex: 0x0175,
  30064. wdieresis: 0x1E85,
  30065. wdotaccent: 0x1E87,
  30066. wdotbelow: 0x1E89,
  30067. wehiragana: 0x3091,
  30068. weierstrass: 0x2118,
  30069. wekatakana: 0x30F1,
  30070. wekorean: 0x315E,
  30071. weokorean: 0x315D,
  30072. wgrave: 0x1E81,
  30073. whitebullet: 0x25E6,
  30074. whitecircle: 0x25CB,
  30075. whitecircleinverse: 0x25D9,
  30076. whitecornerbracketleft: 0x300E,
  30077. whitecornerbracketleftvertical: 0xFE43,
  30078. whitecornerbracketright: 0x300F,
  30079. whitecornerbracketrightvertical: 0xFE44,
  30080. whitediamond: 0x25C7,
  30081. whitediamondcontainingblacksmalldiamond: 0x25C8,
  30082. whitedownpointingsmalltriangle: 0x25BF,
  30083. whitedownpointingtriangle: 0x25BD,
  30084. whiteleftpointingsmalltriangle: 0x25C3,
  30085. whiteleftpointingtriangle: 0x25C1,
  30086. whitelenticularbracketleft: 0x3016,
  30087. whitelenticularbracketright: 0x3017,
  30088. whiterightpointingsmalltriangle: 0x25B9,
  30089. whiterightpointingtriangle: 0x25B7,
  30090. whitesmallsquare: 0x25AB,
  30091. whitesmilingface: 0x263A,
  30092. whitesquare: 0x25A1,
  30093. whitestar: 0x2606,
  30094. whitetelephone: 0x260F,
  30095. whitetortoiseshellbracketleft: 0x3018,
  30096. whitetortoiseshellbracketright: 0x3019,
  30097. whiteuppointingsmalltriangle: 0x25B5,
  30098. whiteuppointingtriangle: 0x25B3,
  30099. wihiragana: 0x3090,
  30100. wikatakana: 0x30F0,
  30101. wikorean: 0x315F,
  30102. wmonospace: 0xFF57,
  30103. wohiragana: 0x3092,
  30104. wokatakana: 0x30F2,
  30105. wokatakanahalfwidth: 0xFF66,
  30106. won: 0x20A9,
  30107. wonmonospace: 0xFFE6,
  30108. wowaenthai: 0x0E27,
  30109. wparen: 0x24B2,
  30110. wring: 0x1E98,
  30111. wsuperior: 0x02B7,
  30112. wturned: 0x028D,
  30113. wynn: 0x01BF,
  30114. x: 0x0078,
  30115. xabovecmb: 0x033D,
  30116. xbopomofo: 0x3112,
  30117. xcircle: 0x24E7,
  30118. xdieresis: 0x1E8D,
  30119. xdotaccent: 0x1E8B,
  30120. xeharmenian: 0x056D,
  30121. xi: 0x03BE,
  30122. xmonospace: 0xFF58,
  30123. xparen: 0x24B3,
  30124. xsuperior: 0x02E3,
  30125. y: 0x0079,
  30126. yaadosquare: 0x334E,
  30127. yabengali: 0x09AF,
  30128. yacute: 0x00FD,
  30129. yadeva: 0x092F,
  30130. yaekorean: 0x3152,
  30131. yagujarati: 0x0AAF,
  30132. yagurmukhi: 0x0A2F,
  30133. yahiragana: 0x3084,
  30134. yakatakana: 0x30E4,
  30135. yakatakanahalfwidth: 0xFF94,
  30136. yakorean: 0x3151,
  30137. yamakkanthai: 0x0E4E,
  30138. yasmallhiragana: 0x3083,
  30139. yasmallkatakana: 0x30E3,
  30140. yasmallkatakanahalfwidth: 0xFF6C,
  30141. yatcyrillic: 0x0463,
  30142. ycircle: 0x24E8,
  30143. ycircumflex: 0x0177,
  30144. ydieresis: 0x00FF,
  30145. ydotaccent: 0x1E8F,
  30146. ydotbelow: 0x1EF5,
  30147. yeharabic: 0x064A,
  30148. yehbarreearabic: 0x06D2,
  30149. yehbarreefinalarabic: 0xFBAF,
  30150. yehfinalarabic: 0xFEF2,
  30151. yehhamzaabovearabic: 0x0626,
  30152. yehhamzaabovefinalarabic: 0xFE8A,
  30153. yehhamzaaboveinitialarabic: 0xFE8B,
  30154. yehhamzaabovemedialarabic: 0xFE8C,
  30155. yehinitialarabic: 0xFEF3,
  30156. yehmedialarabic: 0xFEF4,
  30157. yehmeeminitialarabic: 0xFCDD,
  30158. yehmeemisolatedarabic: 0xFC58,
  30159. yehnoonfinalarabic: 0xFC94,
  30160. yehthreedotsbelowarabic: 0x06D1,
  30161. yekorean: 0x3156,
  30162. yen: 0x00A5,
  30163. yenmonospace: 0xFFE5,
  30164. yeokorean: 0x3155,
  30165. yeorinhieuhkorean: 0x3186,
  30166. yerahbenyomohebrew: 0x05AA,
  30167. yerahbenyomolefthebrew: 0x05AA,
  30168. yericyrillic: 0x044B,
  30169. yerudieresiscyrillic: 0x04F9,
  30170. yesieungkorean: 0x3181,
  30171. yesieungpansioskorean: 0x3183,
  30172. yesieungsioskorean: 0x3182,
  30173. yetivhebrew: 0x059A,
  30174. ygrave: 0x1EF3,
  30175. yhook: 0x01B4,
  30176. yhookabove: 0x1EF7,
  30177. yiarmenian: 0x0575,
  30178. yicyrillic: 0x0457,
  30179. yikorean: 0x3162,
  30180. yinyang: 0x262F,
  30181. yiwnarmenian: 0x0582,
  30182. ymonospace: 0xFF59,
  30183. yod: 0x05D9,
  30184. yoddagesh: 0xFB39,
  30185. yoddageshhebrew: 0xFB39,
  30186. yodhebrew: 0x05D9,
  30187. yodyodhebrew: 0x05F2,
  30188. yodyodpatahhebrew: 0xFB1F,
  30189. yohiragana: 0x3088,
  30190. yoikorean: 0x3189,
  30191. yokatakana: 0x30E8,
  30192. yokatakanahalfwidth: 0xFF96,
  30193. yokorean: 0x315B,
  30194. yosmallhiragana: 0x3087,
  30195. yosmallkatakana: 0x30E7,
  30196. yosmallkatakanahalfwidth: 0xFF6E,
  30197. yotgreek: 0x03F3,
  30198. yoyaekorean: 0x3188,
  30199. yoyakorean: 0x3187,
  30200. yoyakthai: 0x0E22,
  30201. yoyingthai: 0x0E0D,
  30202. yparen: 0x24B4,
  30203. ypogegrammeni: 0x037A,
  30204. ypogegrammenigreekcmb: 0x0345,
  30205. yr: 0x01A6,
  30206. yring: 0x1E99,
  30207. ysuperior: 0x02B8,
  30208. ytilde: 0x1EF9,
  30209. yturned: 0x028E,
  30210. yuhiragana: 0x3086,
  30211. yuikorean: 0x318C,
  30212. yukatakana: 0x30E6,
  30213. yukatakanahalfwidth: 0xFF95,
  30214. yukorean: 0x3160,
  30215. yusbigcyrillic: 0x046B,
  30216. yusbigiotifiedcyrillic: 0x046D,
  30217. yuslittlecyrillic: 0x0467,
  30218. yuslittleiotifiedcyrillic: 0x0469,
  30219. yusmallhiragana: 0x3085,
  30220. yusmallkatakana: 0x30E5,
  30221. yusmallkatakanahalfwidth: 0xFF6D,
  30222. yuyekorean: 0x318B,
  30223. yuyeokorean: 0x318A,
  30224. yyabengali: 0x09DF,
  30225. yyadeva: 0x095F,
  30226. z: 0x007A,
  30227. zaarmenian: 0x0566,
  30228. zacute: 0x017A,
  30229. zadeva: 0x095B,
  30230. zagurmukhi: 0x0A5B,
  30231. zaharabic: 0x0638,
  30232. zahfinalarabic: 0xFEC6,
  30233. zahinitialarabic: 0xFEC7,
  30234. zahiragana: 0x3056,
  30235. zahmedialarabic: 0xFEC8,
  30236. zainarabic: 0x0632,
  30237. zainfinalarabic: 0xFEB0,
  30238. zakatakana: 0x30B6,
  30239. zaqefgadolhebrew: 0x0595,
  30240. zaqefqatanhebrew: 0x0594,
  30241. zarqahebrew: 0x0598,
  30242. zayin: 0x05D6,
  30243. zayindagesh: 0xFB36,
  30244. zayindageshhebrew: 0xFB36,
  30245. zayinhebrew: 0x05D6,
  30246. zbopomofo: 0x3117,
  30247. zcaron: 0x017E,
  30248. zcircle: 0x24E9,
  30249. zcircumflex: 0x1E91,
  30250. zcurl: 0x0291,
  30251. zdot: 0x017C,
  30252. zdotaccent: 0x017C,
  30253. zdotbelow: 0x1E93,
  30254. zecyrillic: 0x0437,
  30255. zedescendercyrillic: 0x0499,
  30256. zedieresiscyrillic: 0x04DF,
  30257. zehiragana: 0x305C,
  30258. zekatakana: 0x30BC,
  30259. zero: 0x0030,
  30260. zeroarabic: 0x0660,
  30261. zerobengali: 0x09E6,
  30262. zerodeva: 0x0966,
  30263. zerogujarati: 0x0AE6,
  30264. zerogurmukhi: 0x0A66,
  30265. zerohackarabic: 0x0660,
  30266. zeroinferior: 0x2080,
  30267. zeromonospace: 0xFF10,
  30268. zerooldstyle: 0xF730,
  30269. zeropersian: 0x06F0,
  30270. zerosuperior: 0x2070,
  30271. zerothai: 0x0E50,
  30272. zerowidthjoiner: 0xFEFF,
  30273. zerowidthnonjoiner: 0x200C,
  30274. zerowidthspace: 0x200B,
  30275. zeta: 0x03B6,
  30276. zhbopomofo: 0x3113,
  30277. zhearmenian: 0x056A,
  30278. zhebrevecyrillic: 0x04C2,
  30279. zhecyrillic: 0x0436,
  30280. zhedescendercyrillic: 0x0497,
  30281. zhedieresiscyrillic: 0x04DD,
  30282. zihiragana: 0x3058,
  30283. zikatakana: 0x30B8,
  30284. zinorhebrew: 0x05AE,
  30285. zlinebelow: 0x1E95,
  30286. zmonospace: 0xFF5A,
  30287. zohiragana: 0x305E,
  30288. zokatakana: 0x30BE,
  30289. zparen: 0x24B5,
  30290. zretroflexhook: 0x0290,
  30291. zstroke: 0x01B6,
  30292. zuhiragana: 0x305A,
  30293. zukatakana: 0x30BA,
  30294. '.notdef': 0x0000
  30295. };
  30296. var DingbatsGlyphsUnicode = {
  30297. space: 0x0020,
  30298. a1: 0x2701,
  30299. a2: 0x2702,
  30300. a202: 0x2703,
  30301. a3: 0x2704,
  30302. a4: 0x260E,
  30303. a5: 0x2706,
  30304. a119: 0x2707,
  30305. a118: 0x2708,
  30306. a117: 0x2709,
  30307. a11: 0x261B,
  30308. a12: 0x261E,
  30309. a13: 0x270C,
  30310. a14: 0x270D,
  30311. a15: 0x270E,
  30312. a16: 0x270F,
  30313. a105: 0x2710,
  30314. a17: 0x2711,
  30315. a18: 0x2712,
  30316. a19: 0x2713,
  30317. a20: 0x2714,
  30318. a21: 0x2715,
  30319. a22: 0x2716,
  30320. a23: 0x2717,
  30321. a24: 0x2718,
  30322. a25: 0x2719,
  30323. a26: 0x271A,
  30324. a27: 0x271B,
  30325. a28: 0x271C,
  30326. a6: 0x271D,
  30327. a7: 0x271E,
  30328. a8: 0x271F,
  30329. a9: 0x2720,
  30330. a10: 0x2721,
  30331. a29: 0x2722,
  30332. a30: 0x2723,
  30333. a31: 0x2724,
  30334. a32: 0x2725,
  30335. a33: 0x2726,
  30336. a34: 0x2727,
  30337. a35: 0x2605,
  30338. a36: 0x2729,
  30339. a37: 0x272A,
  30340. a38: 0x272B,
  30341. a39: 0x272C,
  30342. a40: 0x272D,
  30343. a41: 0x272E,
  30344. a42: 0x272F,
  30345. a43: 0x2730,
  30346. a44: 0x2731,
  30347. a45: 0x2732,
  30348. a46: 0x2733,
  30349. a47: 0x2734,
  30350. a48: 0x2735,
  30351. a49: 0x2736,
  30352. a50: 0x2737,
  30353. a51: 0x2738,
  30354. a52: 0x2739,
  30355. a53: 0x273A,
  30356. a54: 0x273B,
  30357. a55: 0x273C,
  30358. a56: 0x273D,
  30359. a57: 0x273E,
  30360. a58: 0x273F,
  30361. a59: 0x2740,
  30362. a60: 0x2741,
  30363. a61: 0x2742,
  30364. a62: 0x2743,
  30365. a63: 0x2744,
  30366. a64: 0x2745,
  30367. a65: 0x2746,
  30368. a66: 0x2747,
  30369. a67: 0x2748,
  30370. a68: 0x2749,
  30371. a69: 0x274A,
  30372. a70: 0x274B,
  30373. a71: 0x25CF,
  30374. a72: 0x274D,
  30375. a73: 0x25A0,
  30376. a74: 0x274F,
  30377. a203: 0x2750,
  30378. a75: 0x2751,
  30379. a204: 0x2752,
  30380. a76: 0x25B2,
  30381. a77: 0x25BC,
  30382. a78: 0x25C6,
  30383. a79: 0x2756,
  30384. a81: 0x25D7,
  30385. a82: 0x2758,
  30386. a83: 0x2759,
  30387. a84: 0x275A,
  30388. a97: 0x275B,
  30389. a98: 0x275C,
  30390. a99: 0x275D,
  30391. a100: 0x275E,
  30392. a101: 0x2761,
  30393. a102: 0x2762,
  30394. a103: 0x2763,
  30395. a104: 0x2764,
  30396. a106: 0x2765,
  30397. a107: 0x2766,
  30398. a108: 0x2767,
  30399. a112: 0x2663,
  30400. a111: 0x2666,
  30401. a110: 0x2665,
  30402. a109: 0x2660,
  30403. a120: 0x2460,
  30404. a121: 0x2461,
  30405. a122: 0x2462,
  30406. a123: 0x2463,
  30407. a124: 0x2464,
  30408. a125: 0x2465,
  30409. a126: 0x2466,
  30410. a127: 0x2467,
  30411. a128: 0x2468,
  30412. a129: 0x2469,
  30413. a130: 0x2776,
  30414. a131: 0x2777,
  30415. a132: 0x2778,
  30416. a133: 0x2779,
  30417. a134: 0x277A,
  30418. a135: 0x277B,
  30419. a136: 0x277C,
  30420. a137: 0x277D,
  30421. a138: 0x277E,
  30422. a139: 0x277F,
  30423. a140: 0x2780,
  30424. a141: 0x2781,
  30425. a142: 0x2782,
  30426. a143: 0x2783,
  30427. a144: 0x2784,
  30428. a145: 0x2785,
  30429. a146: 0x2786,
  30430. a147: 0x2787,
  30431. a148: 0x2788,
  30432. a149: 0x2789,
  30433. a150: 0x278A,
  30434. a151: 0x278B,
  30435. a152: 0x278C,
  30436. a153: 0x278D,
  30437. a154: 0x278E,
  30438. a155: 0x278F,
  30439. a156: 0x2790,
  30440. a157: 0x2791,
  30441. a158: 0x2792,
  30442. a159: 0x2793,
  30443. a160: 0x2794,
  30444. a161: 0x2192,
  30445. a163: 0x2194,
  30446. a164: 0x2195,
  30447. a196: 0x2798,
  30448. a165: 0x2799,
  30449. a192: 0x279A,
  30450. a166: 0x279B,
  30451. a167: 0x279C,
  30452. a168: 0x279D,
  30453. a169: 0x279E,
  30454. a170: 0x279F,
  30455. a171: 0x27A0,
  30456. a172: 0x27A1,
  30457. a173: 0x27A2,
  30458. a162: 0x27A3,
  30459. a174: 0x27A4,
  30460. a175: 0x27A5,
  30461. a176: 0x27A6,
  30462. a177: 0x27A7,
  30463. a178: 0x27A8,
  30464. a179: 0x27A9,
  30465. a193: 0x27AA,
  30466. a180: 0x27AB,
  30467. a199: 0x27AC,
  30468. a181: 0x27AD,
  30469. a200: 0x27AE,
  30470. a182: 0x27AF,
  30471. a201: 0x27B1,
  30472. a183: 0x27B2,
  30473. a184: 0x27B3,
  30474. a197: 0x27B4,
  30475. a185: 0x27B5,
  30476. a194: 0x27B6,
  30477. a198: 0x27B7,
  30478. a186: 0x27B8,
  30479. a195: 0x27B9,
  30480. a187: 0x27BA,
  30481. a188: 0x27BB,
  30482. a189: 0x27BC,
  30483. a190: 0x27BD,
  30484. a191: 0x27BE,
  30485. a89: 0x2768, // 0xF8D7
  30486. a90: 0x2769, // 0xF8D8
  30487. a93: 0x276A, // 0xF8D9
  30488. a94: 0x276B, // 0xF8DA
  30489. a91: 0x276C, // 0xF8DB
  30490. a92: 0x276D, // 0xF8DC
  30491. a205: 0x276E, // 0xF8DD
  30492. a85: 0x276F, // 0xF8DE
  30493. a206: 0x2770, // 0xF8DF
  30494. a86: 0x2771, // 0xF8E0
  30495. a87: 0x2772, // 0xF8E1
  30496. a88: 0x2773, // 0xF8E2
  30497. a95: 0x2774, // 0xF8E3
  30498. a96: 0x2775, // 0xF8E4
  30499. '.notdef': 0x0000
  30500. };
  30501. var PDFImage = (function PDFImageClosure() {
  30502. /**
  30503. * Decode the image in the main thread if it supported. Resovles the promise
  30504. * when the image data is ready.
  30505. */
  30506. function handleImageData(handler, xref, res, image) {
  30507. if (image instanceof JpegStream && image.isNativelyDecodable(xref, res)) {
  30508. // For natively supported jpegs send them to the main thread for decoding.
  30509. var dict = image.dict;
  30510. var colorSpace = dict.get('ColorSpace', 'CS');
  30511. colorSpace = ColorSpace.parse(colorSpace, xref, res);
  30512. var numComps = colorSpace.numComps;
  30513. var decodePromise = handler.sendWithPromise('JpegDecode',
  30514. [image.getIR(), numComps]);
  30515. return decodePromise.then(function (message) {
  30516. var data = message.data;
  30517. return new Stream(data, 0, data.length, image.dict);
  30518. });
  30519. } else {
  30520. return Promise.resolve(image);
  30521. }
  30522. }
  30523. /**
  30524. * Decode and clamp a value. The formula is different from the spec because we
  30525. * don't decode to float range [0,1], we decode it in the [0,max] range.
  30526. */
  30527. function decodeAndClamp(value, addend, coefficient, max) {
  30528. value = addend + value * coefficient;
  30529. // Clamp the value to the range
  30530. return (value < 0 ? 0 : (value > max ? max : value));
  30531. }
  30532. function PDFImage(xref, res, image, inline, smask, mask, isMask) {
  30533. this.image = image;
  30534. var dict = image.dict;
  30535. if (dict.has('Filter')) {
  30536. var filter = dict.get('Filter').name;
  30537. if (filter === 'JPXDecode') {
  30538. var jpxImage = new JpxImage();
  30539. jpxImage.parseImageProperties(image.stream);
  30540. image.stream.reset();
  30541. image.bitsPerComponent = jpxImage.bitsPerComponent;
  30542. image.numComps = jpxImage.componentsCount;
  30543. } else if (filter === 'JBIG2Decode') {
  30544. image.bitsPerComponent = 1;
  30545. image.numComps = 1;
  30546. }
  30547. }
  30548. // TODO cache rendered images?
  30549. this.width = dict.get('Width', 'W');
  30550. this.height = dict.get('Height', 'H');
  30551. if (this.width < 1 || this.height < 1) {
  30552. error('Invalid image width: ' + this.width + ' or height: ' +
  30553. this.height);
  30554. }
  30555. this.interpolate = dict.get('Interpolate', 'I') || false;
  30556. this.imageMask = dict.get('ImageMask', 'IM') || false;
  30557. this.matte = dict.get('Matte') || false;
  30558. var bitsPerComponent = image.bitsPerComponent;
  30559. if (!bitsPerComponent) {
  30560. bitsPerComponent = dict.get('BitsPerComponent', 'BPC');
  30561. if (!bitsPerComponent) {
  30562. if (this.imageMask) {
  30563. bitsPerComponent = 1;
  30564. } else {
  30565. error('Bits per component missing in image: ' + this.imageMask);
  30566. }
  30567. }
  30568. }
  30569. this.bpc = bitsPerComponent;
  30570. if (!this.imageMask) {
  30571. var colorSpace = dict.get('ColorSpace', 'CS');
  30572. if (!colorSpace) {
  30573. info('JPX images (which do not require color spaces)');
  30574. switch (image.numComps) {
  30575. case 1:
  30576. colorSpace = Name.get('DeviceGray');
  30577. break;
  30578. case 3:
  30579. colorSpace = Name.get('DeviceRGB');
  30580. break;
  30581. case 4:
  30582. colorSpace = Name.get('DeviceCMYK');
  30583. break;
  30584. default:
  30585. error('JPX images with ' + this.numComps +
  30586. ' color components not supported.');
  30587. }
  30588. }
  30589. this.colorSpace = ColorSpace.parse(colorSpace, xref, res);
  30590. this.numComps = this.colorSpace.numComps;
  30591. }
  30592. this.decode = dict.get('Decode', 'D');
  30593. this.needsDecode = false;
  30594. if (this.decode &&
  30595. ((this.colorSpace && !this.colorSpace.isDefaultDecode(this.decode)) ||
  30596. (isMask && !ColorSpace.isDefaultDecode(this.decode, 1)))) {
  30597. this.needsDecode = true;
  30598. // Do some preprocessing to avoid more math.
  30599. var max = (1 << bitsPerComponent) - 1;
  30600. this.decodeCoefficients = [];
  30601. this.decodeAddends = [];
  30602. for (var i = 0, j = 0; i < this.decode.length; i += 2, ++j) {
  30603. var dmin = this.decode[i];
  30604. var dmax = this.decode[i + 1];
  30605. this.decodeCoefficients[j] = dmax - dmin;
  30606. this.decodeAddends[j] = max * dmin;
  30607. }
  30608. }
  30609. if (smask) {
  30610. this.smask = new PDFImage(xref, res, smask, false);
  30611. } else if (mask) {
  30612. if (isStream(mask)) {
  30613. this.mask = new PDFImage(xref, res, mask, false, null, null, true);
  30614. } else {
  30615. // Color key mask (just an array).
  30616. this.mask = mask;
  30617. }
  30618. }
  30619. }
  30620. /**
  30621. * Handles processing of image data and returns the Promise that is resolved
  30622. * with a PDFImage when the image is ready to be used.
  30623. */
  30624. PDFImage.buildImage = function PDFImage_buildImage(handler, xref,
  30625. res, image, inline) {
  30626. var imagePromise = handleImageData(handler, xref, res, image);
  30627. var smaskPromise;
  30628. var maskPromise;
  30629. var smask = image.dict.get('SMask');
  30630. var mask = image.dict.get('Mask');
  30631. if (smask) {
  30632. smaskPromise = handleImageData(handler, xref, res, smask);
  30633. maskPromise = Promise.resolve(null);
  30634. } else {
  30635. smaskPromise = Promise.resolve(null);
  30636. if (mask) {
  30637. if (isStream(mask)) {
  30638. maskPromise = handleImageData(handler, xref, res, mask);
  30639. } else if (isArray(mask)) {
  30640. maskPromise = Promise.resolve(mask);
  30641. } else {
  30642. warn('Unsupported mask format.');
  30643. maskPromise = Promise.resolve(null);
  30644. }
  30645. } else {
  30646. maskPromise = Promise.resolve(null);
  30647. }
  30648. }
  30649. return Promise.all([imagePromise, smaskPromise, maskPromise]).then(
  30650. function(results) {
  30651. var imageData = results[0];
  30652. var smaskData = results[1];
  30653. var maskData = results[2];
  30654. return new PDFImage(xref, res, imageData, inline, smaskData, maskData);
  30655. });
  30656. };
  30657. /**
  30658. * Resize an image using the nearest neighbor algorithm. Currently only
  30659. * supports one and three component images.
  30660. * @param {TypedArray} pixels The original image with one component.
  30661. * @param {Number} bpc Number of bits per component.
  30662. * @param {Number} components Number of color components, 1 or 3 is supported.
  30663. * @param {Number} w1 Original width.
  30664. * @param {Number} h1 Original height.
  30665. * @param {Number} w2 New width.
  30666. * @param {Number} h2 New height.
  30667. * @param {TypedArray} dest (Optional) The destination buffer.
  30668. * @param {Number} alpha01 (Optional) Size reserved for the alpha channel.
  30669. * @return {TypedArray} Resized image data.
  30670. */
  30671. PDFImage.resize = function PDFImage_resize(pixels, bpc, components,
  30672. w1, h1, w2, h2, dest, alpha01) {
  30673. if (components !== 1 && components !== 3) {
  30674. error('Unsupported component count for resizing.');
  30675. }
  30676. var length = w2 * h2 * components;
  30677. var temp = dest ? dest : (bpc <= 8 ? new Uint8Array(length) :
  30678. (bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length)));
  30679. var xRatio = w1 / w2;
  30680. var yRatio = h1 / h2;
  30681. var i, j, py, newIndex = 0, oldIndex;
  30682. var xScaled = new Uint16Array(w2);
  30683. var w1Scanline = w1 * components;
  30684. if (alpha01 !== 1) {
  30685. alpha01 = 0;
  30686. }
  30687. for (j = 0; j < w2; j++) {
  30688. xScaled[j] = Math.floor(j * xRatio) * components;
  30689. }
  30690. if (components === 1) {
  30691. for (i = 0; i < h2; i++) {
  30692. py = Math.floor(i * yRatio) * w1Scanline;
  30693. for (j = 0; j < w2; j++) {
  30694. oldIndex = py + xScaled[j];
  30695. temp[newIndex++] = pixels[oldIndex];
  30696. }
  30697. }
  30698. } else if (components === 3) {
  30699. for (i = 0; i < h2; i++) {
  30700. py = Math.floor(i * yRatio) * w1Scanline;
  30701. for (j = 0; j < w2; j++) {
  30702. oldIndex = py + xScaled[j];
  30703. temp[newIndex++] = pixels[oldIndex++];
  30704. temp[newIndex++] = pixels[oldIndex++];
  30705. temp[newIndex++] = pixels[oldIndex++];
  30706. newIndex += alpha01;
  30707. }
  30708. }
  30709. }
  30710. return temp;
  30711. };
  30712. PDFImage.createMask =
  30713. function PDFImage_createMask(imgArray, width, height,
  30714. imageIsFromDecodeStream, inverseDecode) {
  30715. // |imgArray| might not contain full data for every pixel of the mask, so
  30716. // we need to distinguish between |computedLength| and |actualLength|.
  30717. // In particular, if inverseDecode is true, then the array we return must
  30718. // have a length of |computedLength|.
  30719. var computedLength = ((width + 7) >> 3) * height;
  30720. var actualLength = imgArray.byteLength;
  30721. var haveFullData = computedLength === actualLength;
  30722. var data, i;
  30723. if (imageIsFromDecodeStream && (!inverseDecode || haveFullData)) {
  30724. // imgArray came from a DecodeStream and its data is in an appropriate
  30725. // form, so we can just transfer it.
  30726. data = imgArray;
  30727. } else if (!inverseDecode) {
  30728. data = new Uint8Array(actualLength);
  30729. data.set(imgArray);
  30730. } else {
  30731. data = new Uint8Array(computedLength);
  30732. data.set(imgArray);
  30733. for (i = actualLength; i < computedLength; i++) {
  30734. data[i] = 0xff;
  30735. }
  30736. }
  30737. // If necessary, invert the original mask data (but not any extra we might
  30738. // have added above). It's safe to modify the array -- whether it's the
  30739. // original or a copy, we're about to transfer it anyway, so nothing else
  30740. // in this thread can be relying on its contents.
  30741. if (inverseDecode) {
  30742. for (i = 0; i < actualLength; i++) {
  30743. data[i] = ~data[i];
  30744. }
  30745. }
  30746. return {data: data, width: width, height: height};
  30747. };
  30748. PDFImage.prototype = {
  30749. get drawWidth() {
  30750. return Math.max(this.width,
  30751. this.smask && this.smask.width || 0,
  30752. this.mask && this.mask.width || 0);
  30753. },
  30754. get drawHeight() {
  30755. return Math.max(this.height,
  30756. this.smask && this.smask.height || 0,
  30757. this.mask && this.mask.height || 0);
  30758. },
  30759. decodeBuffer: function PDFImage_decodeBuffer(buffer) {
  30760. var bpc = this.bpc;
  30761. var numComps = this.numComps;
  30762. var decodeAddends = this.decodeAddends;
  30763. var decodeCoefficients = this.decodeCoefficients;
  30764. var max = (1 << bpc) - 1;
  30765. var i, ii;
  30766. if (bpc === 1) {
  30767. // If the buffer needed decode that means it just needs to be inverted.
  30768. for (i = 0, ii = buffer.length; i < ii; i++) {
  30769. buffer[i] = +!(buffer[i]);
  30770. }
  30771. return;
  30772. }
  30773. var index = 0;
  30774. for (i = 0, ii = this.width * this.height; i < ii; i++) {
  30775. for (var j = 0; j < numComps; j++) {
  30776. buffer[index] = decodeAndClamp(buffer[index], decodeAddends[j],
  30777. decodeCoefficients[j], max);
  30778. index++;
  30779. }
  30780. }
  30781. },
  30782. getComponents: function PDFImage_getComponents(buffer) {
  30783. var bpc = this.bpc;
  30784. // This image doesn't require any extra work.
  30785. if (bpc === 8) {
  30786. return buffer;
  30787. }
  30788. var width = this.width;
  30789. var height = this.height;
  30790. var numComps = this.numComps;
  30791. var length = width * height * numComps;
  30792. var bufferPos = 0;
  30793. var output = (bpc <= 8 ? new Uint8Array(length) :
  30794. (bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length)));
  30795. var rowComps = width * numComps;
  30796. var max = (1 << bpc) - 1;
  30797. var i = 0, ii, buf;
  30798. if (bpc === 1) {
  30799. // Optimization for reading 1 bpc images.
  30800. var mask, loop1End, loop2End;
  30801. for (var j = 0; j < height; j++) {
  30802. loop1End = i + (rowComps & ~7);
  30803. loop2End = i + rowComps;
  30804. // unroll loop for all full bytes
  30805. while (i < loop1End) {
  30806. buf = buffer[bufferPos++];
  30807. output[i] = (buf >> 7) & 1;
  30808. output[i + 1] = (buf >> 6) & 1;
  30809. output[i + 2] = (buf >> 5) & 1;
  30810. output[i + 3] = (buf >> 4) & 1;
  30811. output[i + 4] = (buf >> 3) & 1;
  30812. output[i + 5] = (buf >> 2) & 1;
  30813. output[i + 6] = (buf >> 1) & 1;
  30814. output[i + 7] = buf & 1;
  30815. i += 8;
  30816. }
  30817. // handle remaing bits
  30818. if (i < loop2End) {
  30819. buf = buffer[bufferPos++];
  30820. mask = 128;
  30821. while (i < loop2End) {
  30822. output[i++] = +!!(buf & mask);
  30823. mask >>= 1;
  30824. }
  30825. }
  30826. }
  30827. } else {
  30828. // The general case that handles all other bpc values.
  30829. var bits = 0;
  30830. buf = 0;
  30831. for (i = 0, ii = length; i < ii; ++i) {
  30832. if (i % rowComps === 0) {
  30833. buf = 0;
  30834. bits = 0;
  30835. }
  30836. while (bits < bpc) {
  30837. buf = (buf << 8) | buffer[bufferPos++];
  30838. bits += 8;
  30839. }
  30840. var remainingBits = bits - bpc;
  30841. var value = buf >> remainingBits;
  30842. output[i] = (value < 0 ? 0 : (value > max ? max : value));
  30843. buf = buf & ((1 << remainingBits) - 1);
  30844. bits = remainingBits;
  30845. }
  30846. }
  30847. return output;
  30848. },
  30849. fillOpacity: function PDFImage_fillOpacity(rgbaBuf, width, height,
  30850. actualHeight, image) {
  30851. var smask = this.smask;
  30852. var mask = this.mask;
  30853. var alphaBuf, sw, sh, i, ii, j;
  30854. if (smask) {
  30855. sw = smask.width;
  30856. sh = smask.height;
  30857. alphaBuf = new Uint8Array(sw * sh);
  30858. smask.fillGrayBuffer(alphaBuf);
  30859. if (sw !== width || sh !== height) {
  30860. alphaBuf = PDFImage.resize(alphaBuf, smask.bpc, 1, sw, sh, width,
  30861. height);
  30862. }
  30863. } else if (mask) {
  30864. if (mask instanceof PDFImage) {
  30865. sw = mask.width;
  30866. sh = mask.height;
  30867. alphaBuf = new Uint8Array(sw * sh);
  30868. mask.numComps = 1;
  30869. mask.fillGrayBuffer(alphaBuf);
  30870. // Need to invert values in rgbaBuf
  30871. for (i = 0, ii = sw * sh; i < ii; ++i) {
  30872. alphaBuf[i] = 255 - alphaBuf[i];
  30873. }
  30874. if (sw !== width || sh !== height) {
  30875. alphaBuf = PDFImage.resize(alphaBuf, mask.bpc, 1, sw, sh, width,
  30876. height);
  30877. }
  30878. } else if (isArray(mask)) {
  30879. // Color key mask: if any of the compontents are outside the range
  30880. // then they should be painted.
  30881. alphaBuf = new Uint8Array(width * height);
  30882. var numComps = this.numComps;
  30883. for (i = 0, ii = width * height; i < ii; ++i) {
  30884. var opacity = 0;
  30885. var imageOffset = i * numComps;
  30886. for (j = 0; j < numComps; ++j) {
  30887. var color = image[imageOffset + j];
  30888. var maskOffset = j * 2;
  30889. if (color < mask[maskOffset] || color > mask[maskOffset + 1]) {
  30890. opacity = 255;
  30891. break;
  30892. }
  30893. }
  30894. alphaBuf[i] = opacity;
  30895. }
  30896. } else {
  30897. error('Unknown mask format.');
  30898. }
  30899. }
  30900. if (alphaBuf) {
  30901. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  30902. rgbaBuf[j] = alphaBuf[i];
  30903. }
  30904. } else {
  30905. // No mask.
  30906. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  30907. rgbaBuf[j] = 255;
  30908. }
  30909. }
  30910. },
  30911. undoPreblend: function PDFImage_undoPreblend(buffer, width, height) {
  30912. var matte = this.smask && this.smask.matte;
  30913. if (!matte) {
  30914. return;
  30915. }
  30916. var matteRgb = this.colorSpace.getRgb(matte, 0);
  30917. var matteR = matteRgb[0];
  30918. var matteG = matteRgb[1];
  30919. var matteB = matteRgb[2];
  30920. var length = width * height * 4;
  30921. var r, g, b;
  30922. for (var i = 0; i < length; i += 4) {
  30923. var alpha = buffer[i + 3];
  30924. if (alpha === 0) {
  30925. // according formula we have to get Infinity in all components
  30926. // making it white (typical paper color) should be okay
  30927. buffer[i] = 255;
  30928. buffer[i + 1] = 255;
  30929. buffer[i + 2] = 255;
  30930. continue;
  30931. }
  30932. var k = 255 / alpha;
  30933. r = (buffer[i] - matteR) * k + matteR;
  30934. g = (buffer[i + 1] - matteG) * k + matteG;
  30935. b = (buffer[i + 2] - matteB) * k + matteB;
  30936. buffer[i] = r <= 0 ? 0 : r >= 255 ? 255 : r | 0;
  30937. buffer[i + 1] = g <= 0 ? 0 : g >= 255 ? 255 : g | 0;
  30938. buffer[i + 2] = b <= 0 ? 0 : b >= 255 ? 255 : b | 0;
  30939. }
  30940. },
  30941. createImageData: function PDFImage_createImageData(forceRGBA) {
  30942. var drawWidth = this.drawWidth;
  30943. var drawHeight = this.drawHeight;
  30944. var imgData = { // other fields are filled in below
  30945. width: drawWidth,
  30946. height: drawHeight
  30947. };
  30948. var numComps = this.numComps;
  30949. var originalWidth = this.width;
  30950. var originalHeight = this.height;
  30951. var bpc = this.bpc;
  30952. // Rows start at byte boundary.
  30953. var rowBytes = (originalWidth * numComps * bpc + 7) >> 3;
  30954. var imgArray;
  30955. if (!forceRGBA) {
  30956. // If it is a 1-bit-per-pixel grayscale (i.e. black-and-white) image
  30957. // without any complications, we pass a same-sized copy to the main
  30958. // thread rather than expanding by 32x to RGBA form. This saves *lots*
  30959. // of memory for many scanned documents. It's also much faster.
  30960. //
  30961. // Similarly, if it is a 24-bit-per pixel RGB image without any
  30962. // complications, we avoid expanding by 1.333x to RGBA form.
  30963. var kind;
  30964. if (this.colorSpace.name === 'DeviceGray' && bpc === 1) {
  30965. kind = ImageKind.GRAYSCALE_1BPP;
  30966. } else if (this.colorSpace.name === 'DeviceRGB' && bpc === 8 &&
  30967. !this.needsDecode) {
  30968. kind = ImageKind.RGB_24BPP;
  30969. }
  30970. if (kind && !this.smask && !this.mask &&
  30971. drawWidth === originalWidth && drawHeight === originalHeight) {
  30972. imgData.kind = kind;
  30973. imgArray = this.getImageBytes(originalHeight * rowBytes);
  30974. // If imgArray came from a DecodeStream, we're safe to transfer it
  30975. // (and thus neuter it) because it will constitute the entire
  30976. // DecodeStream's data. But if it came from a Stream, we need to
  30977. // copy it because it'll only be a portion of the Stream's data, and
  30978. // the rest will be read later on.
  30979. if (this.image instanceof DecodeStream) {
  30980. imgData.data = imgArray;
  30981. } else {
  30982. var newArray = new Uint8Array(imgArray.length);
  30983. newArray.set(imgArray);
  30984. imgData.data = newArray;
  30985. }
  30986. if (this.needsDecode) {
  30987. // Invert the buffer (which must be grayscale if we reached here).
  30988. assert(kind === ImageKind.GRAYSCALE_1BPP);
  30989. var buffer = imgData.data;
  30990. for (var i = 0, ii = buffer.length; i < ii; i++) {
  30991. buffer[i] ^= 0xff;
  30992. }
  30993. }
  30994. return imgData;
  30995. }
  30996. if (this.image instanceof JpegStream && !this.smask && !this.mask) {
  30997. imgData.kind = ImageKind.RGB_24BPP;
  30998. imgData.data = this.getImageBytes(originalHeight * rowBytes,
  30999. drawWidth, drawHeight, true);
  31000. return imgData;
  31001. }
  31002. }
  31003. imgArray = this.getImageBytes(originalHeight * rowBytes);
  31004. // imgArray can be incomplete (e.g. after CCITT fax encoding).
  31005. var actualHeight = 0 | (imgArray.length / rowBytes *
  31006. drawHeight / originalHeight);
  31007. var comps = this.getComponents(imgArray);
  31008. // If opacity data is present, use RGBA_32BPP form. Otherwise, use the
  31009. // more compact RGB_24BPP form if allowable.
  31010. var alpha01, maybeUndoPreblend;
  31011. if (!forceRGBA && !this.smask && !this.mask) {
  31012. imgData.kind = ImageKind.RGB_24BPP;
  31013. imgData.data = new Uint8Array(drawWidth * drawHeight * 3);
  31014. alpha01 = 0;
  31015. maybeUndoPreblend = false;
  31016. } else {
  31017. imgData.kind = ImageKind.RGBA_32BPP;
  31018. imgData.data = new Uint8Array(drawWidth * drawHeight * 4);
  31019. alpha01 = 1;
  31020. maybeUndoPreblend = true;
  31021. // Color key masking (opacity) must be performed before decoding.
  31022. this.fillOpacity(imgData.data, drawWidth, drawHeight, actualHeight,
  31023. comps);
  31024. }
  31025. if (this.needsDecode) {
  31026. this.decodeBuffer(comps);
  31027. }
  31028. this.colorSpace.fillRgb(imgData.data, originalWidth, originalHeight,
  31029. drawWidth, drawHeight, actualHeight, bpc, comps,
  31030. alpha01);
  31031. if (maybeUndoPreblend) {
  31032. this.undoPreblend(imgData.data, drawWidth, actualHeight);
  31033. }
  31034. return imgData;
  31035. },
  31036. fillGrayBuffer: function PDFImage_fillGrayBuffer(buffer) {
  31037. var numComps = this.numComps;
  31038. if (numComps !== 1) {
  31039. error('Reading gray scale from a color image: ' + numComps);
  31040. }
  31041. var width = this.width;
  31042. var height = this.height;
  31043. var bpc = this.bpc;
  31044. // rows start at byte boundary
  31045. var rowBytes = (width * numComps * bpc + 7) >> 3;
  31046. var imgArray = this.getImageBytes(height * rowBytes);
  31047. var comps = this.getComponents(imgArray);
  31048. var i, length;
  31049. if (bpc === 1) {
  31050. // inline decoding (= inversion) for 1 bpc images
  31051. length = width * height;
  31052. if (this.needsDecode) {
  31053. // invert and scale to {0, 255}
  31054. for (i = 0; i < length; ++i) {
  31055. buffer[i] = (comps[i] - 1) & 255;
  31056. }
  31057. } else {
  31058. // scale to {0, 255}
  31059. for (i = 0; i < length; ++i) {
  31060. buffer[i] = (-comps[i]) & 255;
  31061. }
  31062. }
  31063. return;
  31064. }
  31065. if (this.needsDecode) {
  31066. this.decodeBuffer(comps);
  31067. }
  31068. length = width * height;
  31069. // we aren't using a colorspace so we need to scale the value
  31070. var scale = 255 / ((1 << bpc) - 1);
  31071. for (i = 0; i < length; ++i) {
  31072. buffer[i] = (scale * comps[i]) | 0;
  31073. }
  31074. },
  31075. getImageBytes: function PDFImage_getImageBytes(length,
  31076. drawWidth, drawHeight,
  31077. forceRGB) {
  31078. this.image.reset();
  31079. this.image.drawWidth = drawWidth || this.width;
  31080. this.image.drawHeight = drawHeight || this.height;
  31081. this.image.forceRGB = !!forceRGB;
  31082. return this.image.getBytes(length);
  31083. }
  31084. };
  31085. return PDFImage;
  31086. })();
  31087. // The Metrics object contains glyph widths (in glyph space units).
  31088. // As per PDF spec, for most fonts (Type 3 being an exception) a glyph
  31089. // space unit corresponds to 1/1000th of text space unit.
  31090. var Metrics = {
  31091. 'Courier': 600,
  31092. 'Courier-Bold': 600,
  31093. 'Courier-BoldOblique': 600,
  31094. 'Courier-Oblique': 600,
  31095. 'Helvetica' : {
  31096. 'space': 278,
  31097. 'exclam': 278,
  31098. 'quotedbl': 355,
  31099. 'numbersign': 556,
  31100. 'dollar': 556,
  31101. 'percent': 889,
  31102. 'ampersand': 667,
  31103. 'quoteright': 222,
  31104. 'parenleft': 333,
  31105. 'parenright': 333,
  31106. 'asterisk': 389,
  31107. 'plus': 584,
  31108. 'comma': 278,
  31109. 'hyphen': 333,
  31110. 'period': 278,
  31111. 'slash': 278,
  31112. 'zero': 556,
  31113. 'one': 556,
  31114. 'two': 556,
  31115. 'three': 556,
  31116. 'four': 556,
  31117. 'five': 556,
  31118. 'six': 556,
  31119. 'seven': 556,
  31120. 'eight': 556,
  31121. 'nine': 556,
  31122. 'colon': 278,
  31123. 'semicolon': 278,
  31124. 'less': 584,
  31125. 'equal': 584,
  31126. 'greater': 584,
  31127. 'question': 556,
  31128. 'at': 1015,
  31129. 'A': 667,
  31130. 'B': 667,
  31131. 'C': 722,
  31132. 'D': 722,
  31133. 'E': 667,
  31134. 'F': 611,
  31135. 'G': 778,
  31136. 'H': 722,
  31137. 'I': 278,
  31138. 'J': 500,
  31139. 'K': 667,
  31140. 'L': 556,
  31141. 'M': 833,
  31142. 'N': 722,
  31143. 'O': 778,
  31144. 'P': 667,
  31145. 'Q': 778,
  31146. 'R': 722,
  31147. 'S': 667,
  31148. 'T': 611,
  31149. 'U': 722,
  31150. 'V': 667,
  31151. 'W': 944,
  31152. 'X': 667,
  31153. 'Y': 667,
  31154. 'Z': 611,
  31155. 'bracketleft': 278,
  31156. 'backslash': 278,
  31157. 'bracketright': 278,
  31158. 'asciicircum': 469,
  31159. 'underscore': 556,
  31160. 'quoteleft': 222,
  31161. 'a': 556,
  31162. 'b': 556,
  31163. 'c': 500,
  31164. 'd': 556,
  31165. 'e': 556,
  31166. 'f': 278,
  31167. 'g': 556,
  31168. 'h': 556,
  31169. 'i': 222,
  31170. 'j': 222,
  31171. 'k': 500,
  31172. 'l': 222,
  31173. 'm': 833,
  31174. 'n': 556,
  31175. 'o': 556,
  31176. 'p': 556,
  31177. 'q': 556,
  31178. 'r': 333,
  31179. 's': 500,
  31180. 't': 278,
  31181. 'u': 556,
  31182. 'v': 500,
  31183. 'w': 722,
  31184. 'x': 500,
  31185. 'y': 500,
  31186. 'z': 500,
  31187. 'braceleft': 334,
  31188. 'bar': 260,
  31189. 'braceright': 334,
  31190. 'asciitilde': 584,
  31191. 'exclamdown': 333,
  31192. 'cent': 556,
  31193. 'sterling': 556,
  31194. 'fraction': 167,
  31195. 'yen': 556,
  31196. 'florin': 556,
  31197. 'section': 556,
  31198. 'currency': 556,
  31199. 'quotesingle': 191,
  31200. 'quotedblleft': 333,
  31201. 'guillemotleft': 556,
  31202. 'guilsinglleft': 333,
  31203. 'guilsinglright': 333,
  31204. 'fi': 500,
  31205. 'fl': 500,
  31206. 'endash': 556,
  31207. 'dagger': 556,
  31208. 'daggerdbl': 556,
  31209. 'periodcentered': 278,
  31210. 'paragraph': 537,
  31211. 'bullet': 350,
  31212. 'quotesinglbase': 222,
  31213. 'quotedblbase': 333,
  31214. 'quotedblright': 333,
  31215. 'guillemotright': 556,
  31216. 'ellipsis': 1000,
  31217. 'perthousand': 1000,
  31218. 'questiondown': 611,
  31219. 'grave': 333,
  31220. 'acute': 333,
  31221. 'circumflex': 333,
  31222. 'tilde': 333,
  31223. 'macron': 333,
  31224. 'breve': 333,
  31225. 'dotaccent': 333,
  31226. 'dieresis': 333,
  31227. 'ring': 333,
  31228. 'cedilla': 333,
  31229. 'hungarumlaut': 333,
  31230. 'ogonek': 333,
  31231. 'caron': 333,
  31232. 'emdash': 1000,
  31233. 'AE': 1000,
  31234. 'ordfeminine': 370,
  31235. 'Lslash': 556,
  31236. 'Oslash': 778,
  31237. 'OE': 1000,
  31238. 'ordmasculine': 365,
  31239. 'ae': 889,
  31240. 'dotlessi': 278,
  31241. 'lslash': 222,
  31242. 'oslash': 611,
  31243. 'oe': 944,
  31244. 'germandbls': 611,
  31245. 'Idieresis': 278,
  31246. 'eacute': 556,
  31247. 'abreve': 556,
  31248. 'uhungarumlaut': 556,
  31249. 'ecaron': 556,
  31250. 'Ydieresis': 667,
  31251. 'divide': 584,
  31252. 'Yacute': 667,
  31253. 'Acircumflex': 667,
  31254. 'aacute': 556,
  31255. 'Ucircumflex': 722,
  31256. 'yacute': 500,
  31257. 'scommaaccent': 500,
  31258. 'ecircumflex': 556,
  31259. 'Uring': 722,
  31260. 'Udieresis': 722,
  31261. 'aogonek': 556,
  31262. 'Uacute': 722,
  31263. 'uogonek': 556,
  31264. 'Edieresis': 667,
  31265. 'Dcroat': 722,
  31266. 'commaaccent': 250,
  31267. 'copyright': 737,
  31268. 'Emacron': 667,
  31269. 'ccaron': 500,
  31270. 'aring': 556,
  31271. 'Ncommaaccent': 722,
  31272. 'lacute': 222,
  31273. 'agrave': 556,
  31274. 'Tcommaaccent': 611,
  31275. 'Cacute': 722,
  31276. 'atilde': 556,
  31277. 'Edotaccent': 667,
  31278. 'scaron': 500,
  31279. 'scedilla': 500,
  31280. 'iacute': 278,
  31281. 'lozenge': 471,
  31282. 'Rcaron': 722,
  31283. 'Gcommaaccent': 778,
  31284. 'ucircumflex': 556,
  31285. 'acircumflex': 556,
  31286. 'Amacron': 667,
  31287. 'rcaron': 333,
  31288. 'ccedilla': 500,
  31289. 'Zdotaccent': 611,
  31290. 'Thorn': 667,
  31291. 'Omacron': 778,
  31292. 'Racute': 722,
  31293. 'Sacute': 667,
  31294. 'dcaron': 643,
  31295. 'Umacron': 722,
  31296. 'uring': 556,
  31297. 'threesuperior': 333,
  31298. 'Ograve': 778,
  31299. 'Agrave': 667,
  31300. 'Abreve': 667,
  31301. 'multiply': 584,
  31302. 'uacute': 556,
  31303. 'Tcaron': 611,
  31304. 'partialdiff': 476,
  31305. 'ydieresis': 500,
  31306. 'Nacute': 722,
  31307. 'icircumflex': 278,
  31308. 'Ecircumflex': 667,
  31309. 'adieresis': 556,
  31310. 'edieresis': 556,
  31311. 'cacute': 500,
  31312. 'nacute': 556,
  31313. 'umacron': 556,
  31314. 'Ncaron': 722,
  31315. 'Iacute': 278,
  31316. 'plusminus': 584,
  31317. 'brokenbar': 260,
  31318. 'registered': 737,
  31319. 'Gbreve': 778,
  31320. 'Idotaccent': 278,
  31321. 'summation': 600,
  31322. 'Egrave': 667,
  31323. 'racute': 333,
  31324. 'omacron': 556,
  31325. 'Zacute': 611,
  31326. 'Zcaron': 611,
  31327. 'greaterequal': 549,
  31328. 'Eth': 722,
  31329. 'Ccedilla': 722,
  31330. 'lcommaaccent': 222,
  31331. 'tcaron': 317,
  31332. 'eogonek': 556,
  31333. 'Uogonek': 722,
  31334. 'Aacute': 667,
  31335. 'Adieresis': 667,
  31336. 'egrave': 556,
  31337. 'zacute': 500,
  31338. 'iogonek': 222,
  31339. 'Oacute': 778,
  31340. 'oacute': 556,
  31341. 'amacron': 556,
  31342. 'sacute': 500,
  31343. 'idieresis': 278,
  31344. 'Ocircumflex': 778,
  31345. 'Ugrave': 722,
  31346. 'Delta': 612,
  31347. 'thorn': 556,
  31348. 'twosuperior': 333,
  31349. 'Odieresis': 778,
  31350. 'mu': 556,
  31351. 'igrave': 278,
  31352. 'ohungarumlaut': 556,
  31353. 'Eogonek': 667,
  31354. 'dcroat': 556,
  31355. 'threequarters': 834,
  31356. 'Scedilla': 667,
  31357. 'lcaron': 299,
  31358. 'Kcommaaccent': 667,
  31359. 'Lacute': 556,
  31360. 'trademark': 1000,
  31361. 'edotaccent': 556,
  31362. 'Igrave': 278,
  31363. 'Imacron': 278,
  31364. 'Lcaron': 556,
  31365. 'onehalf': 834,
  31366. 'lessequal': 549,
  31367. 'ocircumflex': 556,
  31368. 'ntilde': 556,
  31369. 'Uhungarumlaut': 722,
  31370. 'Eacute': 667,
  31371. 'emacron': 556,
  31372. 'gbreve': 556,
  31373. 'onequarter': 834,
  31374. 'Scaron': 667,
  31375. 'Scommaaccent': 667,
  31376. 'Ohungarumlaut': 778,
  31377. 'degree': 400,
  31378. 'ograve': 556,
  31379. 'Ccaron': 722,
  31380. 'ugrave': 556,
  31381. 'radical': 453,
  31382. 'Dcaron': 722,
  31383. 'rcommaaccent': 333,
  31384. 'Ntilde': 722,
  31385. 'otilde': 556,
  31386. 'Rcommaaccent': 722,
  31387. 'Lcommaaccent': 556,
  31388. 'Atilde': 667,
  31389. 'Aogonek': 667,
  31390. 'Aring': 667,
  31391. 'Otilde': 778,
  31392. 'zdotaccent': 500,
  31393. 'Ecaron': 667,
  31394. 'Iogonek': 278,
  31395. 'kcommaaccent': 500,
  31396. 'minus': 584,
  31397. 'Icircumflex': 278,
  31398. 'ncaron': 556,
  31399. 'tcommaaccent': 278,
  31400. 'logicalnot': 584,
  31401. 'odieresis': 556,
  31402. 'udieresis': 556,
  31403. 'notequal': 549,
  31404. 'gcommaaccent': 556,
  31405. 'eth': 556,
  31406. 'zcaron': 500,
  31407. 'ncommaaccent': 556,
  31408. 'onesuperior': 333,
  31409. 'imacron': 278,
  31410. 'Euro': 556
  31411. },
  31412. 'Helvetica-Bold': {
  31413. 'space': 278,
  31414. 'exclam': 333,
  31415. 'quotedbl': 474,
  31416. 'numbersign': 556,
  31417. 'dollar': 556,
  31418. 'percent': 889,
  31419. 'ampersand': 722,
  31420. 'quoteright': 278,
  31421. 'parenleft': 333,
  31422. 'parenright': 333,
  31423. 'asterisk': 389,
  31424. 'plus': 584,
  31425. 'comma': 278,
  31426. 'hyphen': 333,
  31427. 'period': 278,
  31428. 'slash': 278,
  31429. 'zero': 556,
  31430. 'one': 556,
  31431. 'two': 556,
  31432. 'three': 556,
  31433. 'four': 556,
  31434. 'five': 556,
  31435. 'six': 556,
  31436. 'seven': 556,
  31437. 'eight': 556,
  31438. 'nine': 556,
  31439. 'colon': 333,
  31440. 'semicolon': 333,
  31441. 'less': 584,
  31442. 'equal': 584,
  31443. 'greater': 584,
  31444. 'question': 611,
  31445. 'at': 975,
  31446. 'A': 722,
  31447. 'B': 722,
  31448. 'C': 722,
  31449. 'D': 722,
  31450. 'E': 667,
  31451. 'F': 611,
  31452. 'G': 778,
  31453. 'H': 722,
  31454. 'I': 278,
  31455. 'J': 556,
  31456. 'K': 722,
  31457. 'L': 611,
  31458. 'M': 833,
  31459. 'N': 722,
  31460. 'O': 778,
  31461. 'P': 667,
  31462. 'Q': 778,
  31463. 'R': 722,
  31464. 'S': 667,
  31465. 'T': 611,
  31466. 'U': 722,
  31467. 'V': 667,
  31468. 'W': 944,
  31469. 'X': 667,
  31470. 'Y': 667,
  31471. 'Z': 611,
  31472. 'bracketleft': 333,
  31473. 'backslash': 278,
  31474. 'bracketright': 333,
  31475. 'asciicircum': 584,
  31476. 'underscore': 556,
  31477. 'quoteleft': 278,
  31478. 'a': 556,
  31479. 'b': 611,
  31480. 'c': 556,
  31481. 'd': 611,
  31482. 'e': 556,
  31483. 'f': 333,
  31484. 'g': 611,
  31485. 'h': 611,
  31486. 'i': 278,
  31487. 'j': 278,
  31488. 'k': 556,
  31489. 'l': 278,
  31490. 'm': 889,
  31491. 'n': 611,
  31492. 'o': 611,
  31493. 'p': 611,
  31494. 'q': 611,
  31495. 'r': 389,
  31496. 's': 556,
  31497. 't': 333,
  31498. 'u': 611,
  31499. 'v': 556,
  31500. 'w': 778,
  31501. 'x': 556,
  31502. 'y': 556,
  31503. 'z': 500,
  31504. 'braceleft': 389,
  31505. 'bar': 280,
  31506. 'braceright': 389,
  31507. 'asciitilde': 584,
  31508. 'exclamdown': 333,
  31509. 'cent': 556,
  31510. 'sterling': 556,
  31511. 'fraction': 167,
  31512. 'yen': 556,
  31513. 'florin': 556,
  31514. 'section': 556,
  31515. 'currency': 556,
  31516. 'quotesingle': 238,
  31517. 'quotedblleft': 500,
  31518. 'guillemotleft': 556,
  31519. 'guilsinglleft': 333,
  31520. 'guilsinglright': 333,
  31521. 'fi': 611,
  31522. 'fl': 611,
  31523. 'endash': 556,
  31524. 'dagger': 556,
  31525. 'daggerdbl': 556,
  31526. 'periodcentered': 278,
  31527. 'paragraph': 556,
  31528. 'bullet': 350,
  31529. 'quotesinglbase': 278,
  31530. 'quotedblbase': 500,
  31531. 'quotedblright': 500,
  31532. 'guillemotright': 556,
  31533. 'ellipsis': 1000,
  31534. 'perthousand': 1000,
  31535. 'questiondown': 611,
  31536. 'grave': 333,
  31537. 'acute': 333,
  31538. 'circumflex': 333,
  31539. 'tilde': 333,
  31540. 'macron': 333,
  31541. 'breve': 333,
  31542. 'dotaccent': 333,
  31543. 'dieresis': 333,
  31544. 'ring': 333,
  31545. 'cedilla': 333,
  31546. 'hungarumlaut': 333,
  31547. 'ogonek': 333,
  31548. 'caron': 333,
  31549. 'emdash': 1000,
  31550. 'AE': 1000,
  31551. 'ordfeminine': 370,
  31552. 'Lslash': 611,
  31553. 'Oslash': 778,
  31554. 'OE': 1000,
  31555. 'ordmasculine': 365,
  31556. 'ae': 889,
  31557. 'dotlessi': 278,
  31558. 'lslash': 278,
  31559. 'oslash': 611,
  31560. 'oe': 944,
  31561. 'germandbls': 611,
  31562. 'Idieresis': 278,
  31563. 'eacute': 556,
  31564. 'abreve': 556,
  31565. 'uhungarumlaut': 611,
  31566. 'ecaron': 556,
  31567. 'Ydieresis': 667,
  31568. 'divide': 584,
  31569. 'Yacute': 667,
  31570. 'Acircumflex': 722,
  31571. 'aacute': 556,
  31572. 'Ucircumflex': 722,
  31573. 'yacute': 556,
  31574. 'scommaaccent': 556,
  31575. 'ecircumflex': 556,
  31576. 'Uring': 722,
  31577. 'Udieresis': 722,
  31578. 'aogonek': 556,
  31579. 'Uacute': 722,
  31580. 'uogonek': 611,
  31581. 'Edieresis': 667,
  31582. 'Dcroat': 722,
  31583. 'commaaccent': 250,
  31584. 'copyright': 737,
  31585. 'Emacron': 667,
  31586. 'ccaron': 556,
  31587. 'aring': 556,
  31588. 'Ncommaaccent': 722,
  31589. 'lacute': 278,
  31590. 'agrave': 556,
  31591. 'Tcommaaccent': 611,
  31592. 'Cacute': 722,
  31593. 'atilde': 556,
  31594. 'Edotaccent': 667,
  31595. 'scaron': 556,
  31596. 'scedilla': 556,
  31597. 'iacute': 278,
  31598. 'lozenge': 494,
  31599. 'Rcaron': 722,
  31600. 'Gcommaaccent': 778,
  31601. 'ucircumflex': 611,
  31602. 'acircumflex': 556,
  31603. 'Amacron': 722,
  31604. 'rcaron': 389,
  31605. 'ccedilla': 556,
  31606. 'Zdotaccent': 611,
  31607. 'Thorn': 667,
  31608. 'Omacron': 778,
  31609. 'Racute': 722,
  31610. 'Sacute': 667,
  31611. 'dcaron': 743,
  31612. 'Umacron': 722,
  31613. 'uring': 611,
  31614. 'threesuperior': 333,
  31615. 'Ograve': 778,
  31616. 'Agrave': 722,
  31617. 'Abreve': 722,
  31618. 'multiply': 584,
  31619. 'uacute': 611,
  31620. 'Tcaron': 611,
  31621. 'partialdiff': 494,
  31622. 'ydieresis': 556,
  31623. 'Nacute': 722,
  31624. 'icircumflex': 278,
  31625. 'Ecircumflex': 667,
  31626. 'adieresis': 556,
  31627. 'edieresis': 556,
  31628. 'cacute': 556,
  31629. 'nacute': 611,
  31630. 'umacron': 611,
  31631. 'Ncaron': 722,
  31632. 'Iacute': 278,
  31633. 'plusminus': 584,
  31634. 'brokenbar': 280,
  31635. 'registered': 737,
  31636. 'Gbreve': 778,
  31637. 'Idotaccent': 278,
  31638. 'summation': 600,
  31639. 'Egrave': 667,
  31640. 'racute': 389,
  31641. 'omacron': 611,
  31642. 'Zacute': 611,
  31643. 'Zcaron': 611,
  31644. 'greaterequal': 549,
  31645. 'Eth': 722,
  31646. 'Ccedilla': 722,
  31647. 'lcommaaccent': 278,
  31648. 'tcaron': 389,
  31649. 'eogonek': 556,
  31650. 'Uogonek': 722,
  31651. 'Aacute': 722,
  31652. 'Adieresis': 722,
  31653. 'egrave': 556,
  31654. 'zacute': 500,
  31655. 'iogonek': 278,
  31656. 'Oacute': 778,
  31657. 'oacute': 611,
  31658. 'amacron': 556,
  31659. 'sacute': 556,
  31660. 'idieresis': 278,
  31661. 'Ocircumflex': 778,
  31662. 'Ugrave': 722,
  31663. 'Delta': 612,
  31664. 'thorn': 611,
  31665. 'twosuperior': 333,
  31666. 'Odieresis': 778,
  31667. 'mu': 611,
  31668. 'igrave': 278,
  31669. 'ohungarumlaut': 611,
  31670. 'Eogonek': 667,
  31671. 'dcroat': 611,
  31672. 'threequarters': 834,
  31673. 'Scedilla': 667,
  31674. 'lcaron': 400,
  31675. 'Kcommaaccent': 722,
  31676. 'Lacute': 611,
  31677. 'trademark': 1000,
  31678. 'edotaccent': 556,
  31679. 'Igrave': 278,
  31680. 'Imacron': 278,
  31681. 'Lcaron': 611,
  31682. 'onehalf': 834,
  31683. 'lessequal': 549,
  31684. 'ocircumflex': 611,
  31685. 'ntilde': 611,
  31686. 'Uhungarumlaut': 722,
  31687. 'Eacute': 667,
  31688. 'emacron': 556,
  31689. 'gbreve': 611,
  31690. 'onequarter': 834,
  31691. 'Scaron': 667,
  31692. 'Scommaaccent': 667,
  31693. 'Ohungarumlaut': 778,
  31694. 'degree': 400,
  31695. 'ograve': 611,
  31696. 'Ccaron': 722,
  31697. 'ugrave': 611,
  31698. 'radical': 549,
  31699. 'Dcaron': 722,
  31700. 'rcommaaccent': 389,
  31701. 'Ntilde': 722,
  31702. 'otilde': 611,
  31703. 'Rcommaaccent': 722,
  31704. 'Lcommaaccent': 611,
  31705. 'Atilde': 722,
  31706. 'Aogonek': 722,
  31707. 'Aring': 722,
  31708. 'Otilde': 778,
  31709. 'zdotaccent': 500,
  31710. 'Ecaron': 667,
  31711. 'Iogonek': 278,
  31712. 'kcommaaccent': 556,
  31713. 'minus': 584,
  31714. 'Icircumflex': 278,
  31715. 'ncaron': 611,
  31716. 'tcommaaccent': 333,
  31717. 'logicalnot': 584,
  31718. 'odieresis': 611,
  31719. 'udieresis': 611,
  31720. 'notequal': 549,
  31721. 'gcommaaccent': 611,
  31722. 'eth': 611,
  31723. 'zcaron': 500,
  31724. 'ncommaaccent': 611,
  31725. 'onesuperior': 333,
  31726. 'imacron': 278,
  31727. 'Euro': 556
  31728. },
  31729. 'Helvetica-BoldOblique': {
  31730. 'space': 278,
  31731. 'exclam': 333,
  31732. 'quotedbl': 474,
  31733. 'numbersign': 556,
  31734. 'dollar': 556,
  31735. 'percent': 889,
  31736. 'ampersand': 722,
  31737. 'quoteright': 278,
  31738. 'parenleft': 333,
  31739. 'parenright': 333,
  31740. 'asterisk': 389,
  31741. 'plus': 584,
  31742. 'comma': 278,
  31743. 'hyphen': 333,
  31744. 'period': 278,
  31745. 'slash': 278,
  31746. 'zero': 556,
  31747. 'one': 556,
  31748. 'two': 556,
  31749. 'three': 556,
  31750. 'four': 556,
  31751. 'five': 556,
  31752. 'six': 556,
  31753. 'seven': 556,
  31754. 'eight': 556,
  31755. 'nine': 556,
  31756. 'colon': 333,
  31757. 'semicolon': 333,
  31758. 'less': 584,
  31759. 'equal': 584,
  31760. 'greater': 584,
  31761. 'question': 611,
  31762. 'at': 975,
  31763. 'A': 722,
  31764. 'B': 722,
  31765. 'C': 722,
  31766. 'D': 722,
  31767. 'E': 667,
  31768. 'F': 611,
  31769. 'G': 778,
  31770. 'H': 722,
  31771. 'I': 278,
  31772. 'J': 556,
  31773. 'K': 722,
  31774. 'L': 611,
  31775. 'M': 833,
  31776. 'N': 722,
  31777. 'O': 778,
  31778. 'P': 667,
  31779. 'Q': 778,
  31780. 'R': 722,
  31781. 'S': 667,
  31782. 'T': 611,
  31783. 'U': 722,
  31784. 'V': 667,
  31785. 'W': 944,
  31786. 'X': 667,
  31787. 'Y': 667,
  31788. 'Z': 611,
  31789. 'bracketleft': 333,
  31790. 'backslash': 278,
  31791. 'bracketright': 333,
  31792. 'asciicircum': 584,
  31793. 'underscore': 556,
  31794. 'quoteleft': 278,
  31795. 'a': 556,
  31796. 'b': 611,
  31797. 'c': 556,
  31798. 'd': 611,
  31799. 'e': 556,
  31800. 'f': 333,
  31801. 'g': 611,
  31802. 'h': 611,
  31803. 'i': 278,
  31804. 'j': 278,
  31805. 'k': 556,
  31806. 'l': 278,
  31807. 'm': 889,
  31808. 'n': 611,
  31809. 'o': 611,
  31810. 'p': 611,
  31811. 'q': 611,
  31812. 'r': 389,
  31813. 's': 556,
  31814. 't': 333,
  31815. 'u': 611,
  31816. 'v': 556,
  31817. 'w': 778,
  31818. 'x': 556,
  31819. 'y': 556,
  31820. 'z': 500,
  31821. 'braceleft': 389,
  31822. 'bar': 280,
  31823. 'braceright': 389,
  31824. 'asciitilde': 584,
  31825. 'exclamdown': 333,
  31826. 'cent': 556,
  31827. 'sterling': 556,
  31828. 'fraction': 167,
  31829. 'yen': 556,
  31830. 'florin': 556,
  31831. 'section': 556,
  31832. 'currency': 556,
  31833. 'quotesingle': 238,
  31834. 'quotedblleft': 500,
  31835. 'guillemotleft': 556,
  31836. 'guilsinglleft': 333,
  31837. 'guilsinglright': 333,
  31838. 'fi': 611,
  31839. 'fl': 611,
  31840. 'endash': 556,
  31841. 'dagger': 556,
  31842. 'daggerdbl': 556,
  31843. 'periodcentered': 278,
  31844. 'paragraph': 556,
  31845. 'bullet': 350,
  31846. 'quotesinglbase': 278,
  31847. 'quotedblbase': 500,
  31848. 'quotedblright': 500,
  31849. 'guillemotright': 556,
  31850. 'ellipsis': 1000,
  31851. 'perthousand': 1000,
  31852. 'questiondown': 611,
  31853. 'grave': 333,
  31854. 'acute': 333,
  31855. 'circumflex': 333,
  31856. 'tilde': 333,
  31857. 'macron': 333,
  31858. 'breve': 333,
  31859. 'dotaccent': 333,
  31860. 'dieresis': 333,
  31861. 'ring': 333,
  31862. 'cedilla': 333,
  31863. 'hungarumlaut': 333,
  31864. 'ogonek': 333,
  31865. 'caron': 333,
  31866. 'emdash': 1000,
  31867. 'AE': 1000,
  31868. 'ordfeminine': 370,
  31869. 'Lslash': 611,
  31870. 'Oslash': 778,
  31871. 'OE': 1000,
  31872. 'ordmasculine': 365,
  31873. 'ae': 889,
  31874. 'dotlessi': 278,
  31875. 'lslash': 278,
  31876. 'oslash': 611,
  31877. 'oe': 944,
  31878. 'germandbls': 611,
  31879. 'Idieresis': 278,
  31880. 'eacute': 556,
  31881. 'abreve': 556,
  31882. 'uhungarumlaut': 611,
  31883. 'ecaron': 556,
  31884. 'Ydieresis': 667,
  31885. 'divide': 584,
  31886. 'Yacute': 667,
  31887. 'Acircumflex': 722,
  31888. 'aacute': 556,
  31889. 'Ucircumflex': 722,
  31890. 'yacute': 556,
  31891. 'scommaaccent': 556,
  31892. 'ecircumflex': 556,
  31893. 'Uring': 722,
  31894. 'Udieresis': 722,
  31895. 'aogonek': 556,
  31896. 'Uacute': 722,
  31897. 'uogonek': 611,
  31898. 'Edieresis': 667,
  31899. 'Dcroat': 722,
  31900. 'commaaccent': 250,
  31901. 'copyright': 737,
  31902. 'Emacron': 667,
  31903. 'ccaron': 556,
  31904. 'aring': 556,
  31905. 'Ncommaaccent': 722,
  31906. 'lacute': 278,
  31907. 'agrave': 556,
  31908. 'Tcommaaccent': 611,
  31909. 'Cacute': 722,
  31910. 'atilde': 556,
  31911. 'Edotaccent': 667,
  31912. 'scaron': 556,
  31913. 'scedilla': 556,
  31914. 'iacute': 278,
  31915. 'lozenge': 494,
  31916. 'Rcaron': 722,
  31917. 'Gcommaaccent': 778,
  31918. 'ucircumflex': 611,
  31919. 'acircumflex': 556,
  31920. 'Amacron': 722,
  31921. 'rcaron': 389,
  31922. 'ccedilla': 556,
  31923. 'Zdotaccent': 611,
  31924. 'Thorn': 667,
  31925. 'Omacron': 778,
  31926. 'Racute': 722,
  31927. 'Sacute': 667,
  31928. 'dcaron': 743,
  31929. 'Umacron': 722,
  31930. 'uring': 611,
  31931. 'threesuperior': 333,
  31932. 'Ograve': 778,
  31933. 'Agrave': 722,
  31934. 'Abreve': 722,
  31935. 'multiply': 584,
  31936. 'uacute': 611,
  31937. 'Tcaron': 611,
  31938. 'partialdiff': 494,
  31939. 'ydieresis': 556,
  31940. 'Nacute': 722,
  31941. 'icircumflex': 278,
  31942. 'Ecircumflex': 667,
  31943. 'adieresis': 556,
  31944. 'edieresis': 556,
  31945. 'cacute': 556,
  31946. 'nacute': 611,
  31947. 'umacron': 611,
  31948. 'Ncaron': 722,
  31949. 'Iacute': 278,
  31950. 'plusminus': 584,
  31951. 'brokenbar': 280,
  31952. 'registered': 737,
  31953. 'Gbreve': 778,
  31954. 'Idotaccent': 278,
  31955. 'summation': 600,
  31956. 'Egrave': 667,
  31957. 'racute': 389,
  31958. 'omacron': 611,
  31959. 'Zacute': 611,
  31960. 'Zcaron': 611,
  31961. 'greaterequal': 549,
  31962. 'Eth': 722,
  31963. 'Ccedilla': 722,
  31964. 'lcommaaccent': 278,
  31965. 'tcaron': 389,
  31966. 'eogonek': 556,
  31967. 'Uogonek': 722,
  31968. 'Aacute': 722,
  31969. 'Adieresis': 722,
  31970. 'egrave': 556,
  31971. 'zacute': 500,
  31972. 'iogonek': 278,
  31973. 'Oacute': 778,
  31974. 'oacute': 611,
  31975. 'amacron': 556,
  31976. 'sacute': 556,
  31977. 'idieresis': 278,
  31978. 'Ocircumflex': 778,
  31979. 'Ugrave': 722,
  31980. 'Delta': 612,
  31981. 'thorn': 611,
  31982. 'twosuperior': 333,
  31983. 'Odieresis': 778,
  31984. 'mu': 611,
  31985. 'igrave': 278,
  31986. 'ohungarumlaut': 611,
  31987. 'Eogonek': 667,
  31988. 'dcroat': 611,
  31989. 'threequarters': 834,
  31990. 'Scedilla': 667,
  31991. 'lcaron': 400,
  31992. 'Kcommaaccent': 722,
  31993. 'Lacute': 611,
  31994. 'trademark': 1000,
  31995. 'edotaccent': 556,
  31996. 'Igrave': 278,
  31997. 'Imacron': 278,
  31998. 'Lcaron': 611,
  31999. 'onehalf': 834,
  32000. 'lessequal': 549,
  32001. 'ocircumflex': 611,
  32002. 'ntilde': 611,
  32003. 'Uhungarumlaut': 722,
  32004. 'Eacute': 667,
  32005. 'emacron': 556,
  32006. 'gbreve': 611,
  32007. 'onequarter': 834,
  32008. 'Scaron': 667,
  32009. 'Scommaaccent': 667,
  32010. 'Ohungarumlaut': 778,
  32011. 'degree': 400,
  32012. 'ograve': 611,
  32013. 'Ccaron': 722,
  32014. 'ugrave': 611,
  32015. 'radical': 549,
  32016. 'Dcaron': 722,
  32017. 'rcommaaccent': 389,
  32018. 'Ntilde': 722,
  32019. 'otilde': 611,
  32020. 'Rcommaaccent': 722,
  32021. 'Lcommaaccent': 611,
  32022. 'Atilde': 722,
  32023. 'Aogonek': 722,
  32024. 'Aring': 722,
  32025. 'Otilde': 778,
  32026. 'zdotaccent': 500,
  32027. 'Ecaron': 667,
  32028. 'Iogonek': 278,
  32029. 'kcommaaccent': 556,
  32030. 'minus': 584,
  32031. 'Icircumflex': 278,
  32032. 'ncaron': 611,
  32033. 'tcommaaccent': 333,
  32034. 'logicalnot': 584,
  32035. 'odieresis': 611,
  32036. 'udieresis': 611,
  32037. 'notequal': 549,
  32038. 'gcommaaccent': 611,
  32039. 'eth': 611,
  32040. 'zcaron': 500,
  32041. 'ncommaaccent': 611,
  32042. 'onesuperior': 333,
  32043. 'imacron': 278,
  32044. 'Euro': 556
  32045. },
  32046. 'Helvetica-Oblique' : {
  32047. 'space': 278,
  32048. 'exclam': 278,
  32049. 'quotedbl': 355,
  32050. 'numbersign': 556,
  32051. 'dollar': 556,
  32052. 'percent': 889,
  32053. 'ampersand': 667,
  32054. 'quoteright': 222,
  32055. 'parenleft': 333,
  32056. 'parenright': 333,
  32057. 'asterisk': 389,
  32058. 'plus': 584,
  32059. 'comma': 278,
  32060. 'hyphen': 333,
  32061. 'period': 278,
  32062. 'slash': 278,
  32063. 'zero': 556,
  32064. 'one': 556,
  32065. 'two': 556,
  32066. 'three': 556,
  32067. 'four': 556,
  32068. 'five': 556,
  32069. 'six': 556,
  32070. 'seven': 556,
  32071. 'eight': 556,
  32072. 'nine': 556,
  32073. 'colon': 278,
  32074. 'semicolon': 278,
  32075. 'less': 584,
  32076. 'equal': 584,
  32077. 'greater': 584,
  32078. 'question': 556,
  32079. 'at': 1015,
  32080. 'A': 667,
  32081. 'B': 667,
  32082. 'C': 722,
  32083. 'D': 722,
  32084. 'E': 667,
  32085. 'F': 611,
  32086. 'G': 778,
  32087. 'H': 722,
  32088. 'I': 278,
  32089. 'J': 500,
  32090. 'K': 667,
  32091. 'L': 556,
  32092. 'M': 833,
  32093. 'N': 722,
  32094. 'O': 778,
  32095. 'P': 667,
  32096. 'Q': 778,
  32097. 'R': 722,
  32098. 'S': 667,
  32099. 'T': 611,
  32100. 'U': 722,
  32101. 'V': 667,
  32102. 'W': 944,
  32103. 'X': 667,
  32104. 'Y': 667,
  32105. 'Z': 611,
  32106. 'bracketleft': 278,
  32107. 'backslash': 278,
  32108. 'bracketright': 278,
  32109. 'asciicircum': 469,
  32110. 'underscore': 556,
  32111. 'quoteleft': 222,
  32112. 'a': 556,
  32113. 'b': 556,
  32114. 'c': 500,
  32115. 'd': 556,
  32116. 'e': 556,
  32117. 'f': 278,
  32118. 'g': 556,
  32119. 'h': 556,
  32120. 'i': 222,
  32121. 'j': 222,
  32122. 'k': 500,
  32123. 'l': 222,
  32124. 'm': 833,
  32125. 'n': 556,
  32126. 'o': 556,
  32127. 'p': 556,
  32128. 'q': 556,
  32129. 'r': 333,
  32130. 's': 500,
  32131. 't': 278,
  32132. 'u': 556,
  32133. 'v': 500,
  32134. 'w': 722,
  32135. 'x': 500,
  32136. 'y': 500,
  32137. 'z': 500,
  32138. 'braceleft': 334,
  32139. 'bar': 260,
  32140. 'braceright': 334,
  32141. 'asciitilde': 584,
  32142. 'exclamdown': 333,
  32143. 'cent': 556,
  32144. 'sterling': 556,
  32145. 'fraction': 167,
  32146. 'yen': 556,
  32147. 'florin': 556,
  32148. 'section': 556,
  32149. 'currency': 556,
  32150. 'quotesingle': 191,
  32151. 'quotedblleft': 333,
  32152. 'guillemotleft': 556,
  32153. 'guilsinglleft': 333,
  32154. 'guilsinglright': 333,
  32155. 'fi': 500,
  32156. 'fl': 500,
  32157. 'endash': 556,
  32158. 'dagger': 556,
  32159. 'daggerdbl': 556,
  32160. 'periodcentered': 278,
  32161. 'paragraph': 537,
  32162. 'bullet': 350,
  32163. 'quotesinglbase': 222,
  32164. 'quotedblbase': 333,
  32165. 'quotedblright': 333,
  32166. 'guillemotright': 556,
  32167. 'ellipsis': 1000,
  32168. 'perthousand': 1000,
  32169. 'questiondown': 611,
  32170. 'grave': 333,
  32171. 'acute': 333,
  32172. 'circumflex': 333,
  32173. 'tilde': 333,
  32174. 'macron': 333,
  32175. 'breve': 333,
  32176. 'dotaccent': 333,
  32177. 'dieresis': 333,
  32178. 'ring': 333,
  32179. 'cedilla': 333,
  32180. 'hungarumlaut': 333,
  32181. 'ogonek': 333,
  32182. 'caron': 333,
  32183. 'emdash': 1000,
  32184. 'AE': 1000,
  32185. 'ordfeminine': 370,
  32186. 'Lslash': 556,
  32187. 'Oslash': 778,
  32188. 'OE': 1000,
  32189. 'ordmasculine': 365,
  32190. 'ae': 889,
  32191. 'dotlessi': 278,
  32192. 'lslash': 222,
  32193. 'oslash': 611,
  32194. 'oe': 944,
  32195. 'germandbls': 611,
  32196. 'Idieresis': 278,
  32197. 'eacute': 556,
  32198. 'abreve': 556,
  32199. 'uhungarumlaut': 556,
  32200. 'ecaron': 556,
  32201. 'Ydieresis': 667,
  32202. 'divide': 584,
  32203. 'Yacute': 667,
  32204. 'Acircumflex': 667,
  32205. 'aacute': 556,
  32206. 'Ucircumflex': 722,
  32207. 'yacute': 500,
  32208. 'scommaaccent': 500,
  32209. 'ecircumflex': 556,
  32210. 'Uring': 722,
  32211. 'Udieresis': 722,
  32212. 'aogonek': 556,
  32213. 'Uacute': 722,
  32214. 'uogonek': 556,
  32215. 'Edieresis': 667,
  32216. 'Dcroat': 722,
  32217. 'commaaccent': 250,
  32218. 'copyright': 737,
  32219. 'Emacron': 667,
  32220. 'ccaron': 500,
  32221. 'aring': 556,
  32222. 'Ncommaaccent': 722,
  32223. 'lacute': 222,
  32224. 'agrave': 556,
  32225. 'Tcommaaccent': 611,
  32226. 'Cacute': 722,
  32227. 'atilde': 556,
  32228. 'Edotaccent': 667,
  32229. 'scaron': 500,
  32230. 'scedilla': 500,
  32231. 'iacute': 278,
  32232. 'lozenge': 471,
  32233. 'Rcaron': 722,
  32234. 'Gcommaaccent': 778,
  32235. 'ucircumflex': 556,
  32236. 'acircumflex': 556,
  32237. 'Amacron': 667,
  32238. 'rcaron': 333,
  32239. 'ccedilla': 500,
  32240. 'Zdotaccent': 611,
  32241. 'Thorn': 667,
  32242. 'Omacron': 778,
  32243. 'Racute': 722,
  32244. 'Sacute': 667,
  32245. 'dcaron': 643,
  32246. 'Umacron': 722,
  32247. 'uring': 556,
  32248. 'threesuperior': 333,
  32249. 'Ograve': 778,
  32250. 'Agrave': 667,
  32251. 'Abreve': 667,
  32252. 'multiply': 584,
  32253. 'uacute': 556,
  32254. 'Tcaron': 611,
  32255. 'partialdiff': 476,
  32256. 'ydieresis': 500,
  32257. 'Nacute': 722,
  32258. 'icircumflex': 278,
  32259. 'Ecircumflex': 667,
  32260. 'adieresis': 556,
  32261. 'edieresis': 556,
  32262. 'cacute': 500,
  32263. 'nacute': 556,
  32264. 'umacron': 556,
  32265. 'Ncaron': 722,
  32266. 'Iacute': 278,
  32267. 'plusminus': 584,
  32268. 'brokenbar': 260,
  32269. 'registered': 737,
  32270. 'Gbreve': 778,
  32271. 'Idotaccent': 278,
  32272. 'summation': 600,
  32273. 'Egrave': 667,
  32274. 'racute': 333,
  32275. 'omacron': 556,
  32276. 'Zacute': 611,
  32277. 'Zcaron': 611,
  32278. 'greaterequal': 549,
  32279. 'Eth': 722,
  32280. 'Ccedilla': 722,
  32281. 'lcommaaccent': 222,
  32282. 'tcaron': 317,
  32283. 'eogonek': 556,
  32284. 'Uogonek': 722,
  32285. 'Aacute': 667,
  32286. 'Adieresis': 667,
  32287. 'egrave': 556,
  32288. 'zacute': 500,
  32289. 'iogonek': 222,
  32290. 'Oacute': 778,
  32291. 'oacute': 556,
  32292. 'amacron': 556,
  32293. 'sacute': 500,
  32294. 'idieresis': 278,
  32295. 'Ocircumflex': 778,
  32296. 'Ugrave': 722,
  32297. 'Delta': 612,
  32298. 'thorn': 556,
  32299. 'twosuperior': 333,
  32300. 'Odieresis': 778,
  32301. 'mu': 556,
  32302. 'igrave': 278,
  32303. 'ohungarumlaut': 556,
  32304. 'Eogonek': 667,
  32305. 'dcroat': 556,
  32306. 'threequarters': 834,
  32307. 'Scedilla': 667,
  32308. 'lcaron': 299,
  32309. 'Kcommaaccent': 667,
  32310. 'Lacute': 556,
  32311. 'trademark': 1000,
  32312. 'edotaccent': 556,
  32313. 'Igrave': 278,
  32314. 'Imacron': 278,
  32315. 'Lcaron': 556,
  32316. 'onehalf': 834,
  32317. 'lessequal': 549,
  32318. 'ocircumflex': 556,
  32319. 'ntilde': 556,
  32320. 'Uhungarumlaut': 722,
  32321. 'Eacute': 667,
  32322. 'emacron': 556,
  32323. 'gbreve': 556,
  32324. 'onequarter': 834,
  32325. 'Scaron': 667,
  32326. 'Scommaaccent': 667,
  32327. 'Ohungarumlaut': 778,
  32328. 'degree': 400,
  32329. 'ograve': 556,
  32330. 'Ccaron': 722,
  32331. 'ugrave': 556,
  32332. 'radical': 453,
  32333. 'Dcaron': 722,
  32334. 'rcommaaccent': 333,
  32335. 'Ntilde': 722,
  32336. 'otilde': 556,
  32337. 'Rcommaaccent': 722,
  32338. 'Lcommaaccent': 556,
  32339. 'Atilde': 667,
  32340. 'Aogonek': 667,
  32341. 'Aring': 667,
  32342. 'Otilde': 778,
  32343. 'zdotaccent': 500,
  32344. 'Ecaron': 667,
  32345. 'Iogonek': 278,
  32346. 'kcommaaccent': 500,
  32347. 'minus': 584,
  32348. 'Icircumflex': 278,
  32349. 'ncaron': 556,
  32350. 'tcommaaccent': 278,
  32351. 'logicalnot': 584,
  32352. 'odieresis': 556,
  32353. 'udieresis': 556,
  32354. 'notequal': 549,
  32355. 'gcommaaccent': 556,
  32356. 'eth': 556,
  32357. 'zcaron': 500,
  32358. 'ncommaaccent': 556,
  32359. 'onesuperior': 333,
  32360. 'imacron': 278,
  32361. 'Euro': 556
  32362. },
  32363. 'Symbol': {
  32364. 'space': 250,
  32365. 'exclam': 333,
  32366. 'universal': 713,
  32367. 'numbersign': 500,
  32368. 'existential': 549,
  32369. 'percent': 833,
  32370. 'ampersand': 778,
  32371. 'suchthat': 439,
  32372. 'parenleft': 333,
  32373. 'parenright': 333,
  32374. 'asteriskmath': 500,
  32375. 'plus': 549,
  32376. 'comma': 250,
  32377. 'minus': 549,
  32378. 'period': 250,
  32379. 'slash': 278,
  32380. 'zero': 500,
  32381. 'one': 500,
  32382. 'two': 500,
  32383. 'three': 500,
  32384. 'four': 500,
  32385. 'five': 500,
  32386. 'six': 500,
  32387. 'seven': 500,
  32388. 'eight': 500,
  32389. 'nine': 500,
  32390. 'colon': 278,
  32391. 'semicolon': 278,
  32392. 'less': 549,
  32393. 'equal': 549,
  32394. 'greater': 549,
  32395. 'question': 444,
  32396. 'congruent': 549,
  32397. 'Alpha': 722,
  32398. 'Beta': 667,
  32399. 'Chi': 722,
  32400. 'Delta': 612,
  32401. 'Epsilon': 611,
  32402. 'Phi': 763,
  32403. 'Gamma': 603,
  32404. 'Eta': 722,
  32405. 'Iota': 333,
  32406. 'theta1': 631,
  32407. 'Kappa': 722,
  32408. 'Lambda': 686,
  32409. 'Mu': 889,
  32410. 'Nu': 722,
  32411. 'Omicron': 722,
  32412. 'Pi': 768,
  32413. 'Theta': 741,
  32414. 'Rho': 556,
  32415. 'Sigma': 592,
  32416. 'Tau': 611,
  32417. 'Upsilon': 690,
  32418. 'sigma1': 439,
  32419. 'Omega': 768,
  32420. 'Xi': 645,
  32421. 'Psi': 795,
  32422. 'Zeta': 611,
  32423. 'bracketleft': 333,
  32424. 'therefore': 863,
  32425. 'bracketright': 333,
  32426. 'perpendicular': 658,
  32427. 'underscore': 500,
  32428. 'radicalex': 500,
  32429. 'alpha': 631,
  32430. 'beta': 549,
  32431. 'chi': 549,
  32432. 'delta': 494,
  32433. 'epsilon': 439,
  32434. 'phi': 521,
  32435. 'gamma': 411,
  32436. 'eta': 603,
  32437. 'iota': 329,
  32438. 'phi1': 603,
  32439. 'kappa': 549,
  32440. 'lambda': 549,
  32441. 'mu': 576,
  32442. 'nu': 521,
  32443. 'omicron': 549,
  32444. 'pi': 549,
  32445. 'theta': 521,
  32446. 'rho': 549,
  32447. 'sigma': 603,
  32448. 'tau': 439,
  32449. 'upsilon': 576,
  32450. 'omega1': 713,
  32451. 'omega': 686,
  32452. 'xi': 493,
  32453. 'psi': 686,
  32454. 'zeta': 494,
  32455. 'braceleft': 480,
  32456. 'bar': 200,
  32457. 'braceright': 480,
  32458. 'similar': 549,
  32459. 'Euro': 750,
  32460. 'Upsilon1': 620,
  32461. 'minute': 247,
  32462. 'lessequal': 549,
  32463. 'fraction': 167,
  32464. 'infinity': 713,
  32465. 'florin': 500,
  32466. 'club': 753,
  32467. 'diamond': 753,
  32468. 'heart': 753,
  32469. 'spade': 753,
  32470. 'arrowboth': 1042,
  32471. 'arrowleft': 987,
  32472. 'arrowup': 603,
  32473. 'arrowright': 987,
  32474. 'arrowdown': 603,
  32475. 'degree': 400,
  32476. 'plusminus': 549,
  32477. 'second': 411,
  32478. 'greaterequal': 549,
  32479. 'multiply': 549,
  32480. 'proportional': 713,
  32481. 'partialdiff': 494,
  32482. 'bullet': 460,
  32483. 'divide': 549,
  32484. 'notequal': 549,
  32485. 'equivalence': 549,
  32486. 'approxequal': 549,
  32487. 'ellipsis': 1000,
  32488. 'arrowvertex': 603,
  32489. 'arrowhorizex': 1000,
  32490. 'carriagereturn': 658,
  32491. 'aleph': 823,
  32492. 'Ifraktur': 686,
  32493. 'Rfraktur': 795,
  32494. 'weierstrass': 987,
  32495. 'circlemultiply': 768,
  32496. 'circleplus': 768,
  32497. 'emptyset': 823,
  32498. 'intersection': 768,
  32499. 'union': 768,
  32500. 'propersuperset': 713,
  32501. 'reflexsuperset': 713,
  32502. 'notsubset': 713,
  32503. 'propersubset': 713,
  32504. 'reflexsubset': 713,
  32505. 'element': 713,
  32506. 'notelement': 713,
  32507. 'angle': 768,
  32508. 'gradient': 713,
  32509. 'registerserif': 790,
  32510. 'copyrightserif': 790,
  32511. 'trademarkserif': 890,
  32512. 'product': 823,
  32513. 'radical': 549,
  32514. 'dotmath': 250,
  32515. 'logicalnot': 713,
  32516. 'logicaland': 603,
  32517. 'logicalor': 603,
  32518. 'arrowdblboth': 1042,
  32519. 'arrowdblleft': 987,
  32520. 'arrowdblup': 603,
  32521. 'arrowdblright': 987,
  32522. 'arrowdbldown': 603,
  32523. 'lozenge': 494,
  32524. 'angleleft': 329,
  32525. 'registersans': 790,
  32526. 'copyrightsans': 790,
  32527. 'trademarksans': 786,
  32528. 'summation': 713,
  32529. 'parenlefttp': 384,
  32530. 'parenleftex': 384,
  32531. 'parenleftbt': 384,
  32532. 'bracketlefttp': 384,
  32533. 'bracketleftex': 384,
  32534. 'bracketleftbt': 384,
  32535. 'bracelefttp': 494,
  32536. 'braceleftmid': 494,
  32537. 'braceleftbt': 494,
  32538. 'braceex': 494,
  32539. 'angleright': 329,
  32540. 'integral': 274,
  32541. 'integraltp': 686,
  32542. 'integralex': 686,
  32543. 'integralbt': 686,
  32544. 'parenrighttp': 384,
  32545. 'parenrightex': 384,
  32546. 'parenrightbt': 384,
  32547. 'bracketrighttp': 384,
  32548. 'bracketrightex': 384,
  32549. 'bracketrightbt': 384,
  32550. 'bracerighttp': 494,
  32551. 'bracerightmid': 494,
  32552. 'bracerightbt': 494,
  32553. 'apple': 790
  32554. },
  32555. 'Times-Roman': {
  32556. 'space': 250,
  32557. 'exclam': 333,
  32558. 'quotedbl': 408,
  32559. 'numbersign': 500,
  32560. 'dollar': 500,
  32561. 'percent': 833,
  32562. 'ampersand': 778,
  32563. 'quoteright': 333,
  32564. 'parenleft': 333,
  32565. 'parenright': 333,
  32566. 'asterisk': 500,
  32567. 'plus': 564,
  32568. 'comma': 250,
  32569. 'hyphen': 333,
  32570. 'period': 250,
  32571. 'slash': 278,
  32572. 'zero': 500,
  32573. 'one': 500,
  32574. 'two': 500,
  32575. 'three': 500,
  32576. 'four': 500,
  32577. 'five': 500,
  32578. 'six': 500,
  32579. 'seven': 500,
  32580. 'eight': 500,
  32581. 'nine': 500,
  32582. 'colon': 278,
  32583. 'semicolon': 278,
  32584. 'less': 564,
  32585. 'equal': 564,
  32586. 'greater': 564,
  32587. 'question': 444,
  32588. 'at': 921,
  32589. 'A': 722,
  32590. 'B': 667,
  32591. 'C': 667,
  32592. 'D': 722,
  32593. 'E': 611,
  32594. 'F': 556,
  32595. 'G': 722,
  32596. 'H': 722,
  32597. 'I': 333,
  32598. 'J': 389,
  32599. 'K': 722,
  32600. 'L': 611,
  32601. 'M': 889,
  32602. 'N': 722,
  32603. 'O': 722,
  32604. 'P': 556,
  32605. 'Q': 722,
  32606. 'R': 667,
  32607. 'S': 556,
  32608. 'T': 611,
  32609. 'U': 722,
  32610. 'V': 722,
  32611. 'W': 944,
  32612. 'X': 722,
  32613. 'Y': 722,
  32614. 'Z': 611,
  32615. 'bracketleft': 333,
  32616. 'backslash': 278,
  32617. 'bracketright': 333,
  32618. 'asciicircum': 469,
  32619. 'underscore': 500,
  32620. 'quoteleft': 333,
  32621. 'a': 444,
  32622. 'b': 500,
  32623. 'c': 444,
  32624. 'd': 500,
  32625. 'e': 444,
  32626. 'f': 333,
  32627. 'g': 500,
  32628. 'h': 500,
  32629. 'i': 278,
  32630. 'j': 278,
  32631. 'k': 500,
  32632. 'l': 278,
  32633. 'm': 778,
  32634. 'n': 500,
  32635. 'o': 500,
  32636. 'p': 500,
  32637. 'q': 500,
  32638. 'r': 333,
  32639. 's': 389,
  32640. 't': 278,
  32641. 'u': 500,
  32642. 'v': 500,
  32643. 'w': 722,
  32644. 'x': 500,
  32645. 'y': 500,
  32646. 'z': 444,
  32647. 'braceleft': 480,
  32648. 'bar': 200,
  32649. 'braceright': 480,
  32650. 'asciitilde': 541,
  32651. 'exclamdown': 333,
  32652. 'cent': 500,
  32653. 'sterling': 500,
  32654. 'fraction': 167,
  32655. 'yen': 500,
  32656. 'florin': 500,
  32657. 'section': 500,
  32658. 'currency': 500,
  32659. 'quotesingle': 180,
  32660. 'quotedblleft': 444,
  32661. 'guillemotleft': 500,
  32662. 'guilsinglleft': 333,
  32663. 'guilsinglright': 333,
  32664. 'fi': 556,
  32665. 'fl': 556,
  32666. 'endash': 500,
  32667. 'dagger': 500,
  32668. 'daggerdbl': 500,
  32669. 'periodcentered': 250,
  32670. 'paragraph': 453,
  32671. 'bullet': 350,
  32672. 'quotesinglbase': 333,
  32673. 'quotedblbase': 444,
  32674. 'quotedblright': 444,
  32675. 'guillemotright': 500,
  32676. 'ellipsis': 1000,
  32677. 'perthousand': 1000,
  32678. 'questiondown': 444,
  32679. 'grave': 333,
  32680. 'acute': 333,
  32681. 'circumflex': 333,
  32682. 'tilde': 333,
  32683. 'macron': 333,
  32684. 'breve': 333,
  32685. 'dotaccent': 333,
  32686. 'dieresis': 333,
  32687. 'ring': 333,
  32688. 'cedilla': 333,
  32689. 'hungarumlaut': 333,
  32690. 'ogonek': 333,
  32691. 'caron': 333,
  32692. 'emdash': 1000,
  32693. 'AE': 889,
  32694. 'ordfeminine': 276,
  32695. 'Lslash': 611,
  32696. 'Oslash': 722,
  32697. 'OE': 889,
  32698. 'ordmasculine': 310,
  32699. 'ae': 667,
  32700. 'dotlessi': 278,
  32701. 'lslash': 278,
  32702. 'oslash': 500,
  32703. 'oe': 722,
  32704. 'germandbls': 500,
  32705. 'Idieresis': 333,
  32706. 'eacute': 444,
  32707. 'abreve': 444,
  32708. 'uhungarumlaut': 500,
  32709. 'ecaron': 444,
  32710. 'Ydieresis': 722,
  32711. 'divide': 564,
  32712. 'Yacute': 722,
  32713. 'Acircumflex': 722,
  32714. 'aacute': 444,
  32715. 'Ucircumflex': 722,
  32716. 'yacute': 500,
  32717. 'scommaaccent': 389,
  32718. 'ecircumflex': 444,
  32719. 'Uring': 722,
  32720. 'Udieresis': 722,
  32721. 'aogonek': 444,
  32722. 'Uacute': 722,
  32723. 'uogonek': 500,
  32724. 'Edieresis': 611,
  32725. 'Dcroat': 722,
  32726. 'commaaccent': 250,
  32727. 'copyright': 760,
  32728. 'Emacron': 611,
  32729. 'ccaron': 444,
  32730. 'aring': 444,
  32731. 'Ncommaaccent': 722,
  32732. 'lacute': 278,
  32733. 'agrave': 444,
  32734. 'Tcommaaccent': 611,
  32735. 'Cacute': 667,
  32736. 'atilde': 444,
  32737. 'Edotaccent': 611,
  32738. 'scaron': 389,
  32739. 'scedilla': 389,
  32740. 'iacute': 278,
  32741. 'lozenge': 471,
  32742. 'Rcaron': 667,
  32743. 'Gcommaaccent': 722,
  32744. 'ucircumflex': 500,
  32745. 'acircumflex': 444,
  32746. 'Amacron': 722,
  32747. 'rcaron': 333,
  32748. 'ccedilla': 444,
  32749. 'Zdotaccent': 611,
  32750. 'Thorn': 556,
  32751. 'Omacron': 722,
  32752. 'Racute': 667,
  32753. 'Sacute': 556,
  32754. 'dcaron': 588,
  32755. 'Umacron': 722,
  32756. 'uring': 500,
  32757. 'threesuperior': 300,
  32758. 'Ograve': 722,
  32759. 'Agrave': 722,
  32760. 'Abreve': 722,
  32761. 'multiply': 564,
  32762. 'uacute': 500,
  32763. 'Tcaron': 611,
  32764. 'partialdiff': 476,
  32765. 'ydieresis': 500,
  32766. 'Nacute': 722,
  32767. 'icircumflex': 278,
  32768. 'Ecircumflex': 611,
  32769. 'adieresis': 444,
  32770. 'edieresis': 444,
  32771. 'cacute': 444,
  32772. 'nacute': 500,
  32773. 'umacron': 500,
  32774. 'Ncaron': 722,
  32775. 'Iacute': 333,
  32776. 'plusminus': 564,
  32777. 'brokenbar': 200,
  32778. 'registered': 760,
  32779. 'Gbreve': 722,
  32780. 'Idotaccent': 333,
  32781. 'summation': 600,
  32782. 'Egrave': 611,
  32783. 'racute': 333,
  32784. 'omacron': 500,
  32785. 'Zacute': 611,
  32786. 'Zcaron': 611,
  32787. 'greaterequal': 549,
  32788. 'Eth': 722,
  32789. 'Ccedilla': 667,
  32790. 'lcommaaccent': 278,
  32791. 'tcaron': 326,
  32792. 'eogonek': 444,
  32793. 'Uogonek': 722,
  32794. 'Aacute': 722,
  32795. 'Adieresis': 722,
  32796. 'egrave': 444,
  32797. 'zacute': 444,
  32798. 'iogonek': 278,
  32799. 'Oacute': 722,
  32800. 'oacute': 500,
  32801. 'amacron': 444,
  32802. 'sacute': 389,
  32803. 'idieresis': 278,
  32804. 'Ocircumflex': 722,
  32805. 'Ugrave': 722,
  32806. 'Delta': 612,
  32807. 'thorn': 500,
  32808. 'twosuperior': 300,
  32809. 'Odieresis': 722,
  32810. 'mu': 500,
  32811. 'igrave': 278,
  32812. 'ohungarumlaut': 500,
  32813. 'Eogonek': 611,
  32814. 'dcroat': 500,
  32815. 'threequarters': 750,
  32816. 'Scedilla': 556,
  32817. 'lcaron': 344,
  32818. 'Kcommaaccent': 722,
  32819. 'Lacute': 611,
  32820. 'trademark': 980,
  32821. 'edotaccent': 444,
  32822. 'Igrave': 333,
  32823. 'Imacron': 333,
  32824. 'Lcaron': 611,
  32825. 'onehalf': 750,
  32826. 'lessequal': 549,
  32827. 'ocircumflex': 500,
  32828. 'ntilde': 500,
  32829. 'Uhungarumlaut': 722,
  32830. 'Eacute': 611,
  32831. 'emacron': 444,
  32832. 'gbreve': 500,
  32833. 'onequarter': 750,
  32834. 'Scaron': 556,
  32835. 'Scommaaccent': 556,
  32836. 'Ohungarumlaut': 722,
  32837. 'degree': 400,
  32838. 'ograve': 500,
  32839. 'Ccaron': 667,
  32840. 'ugrave': 500,
  32841. 'radical': 453,
  32842. 'Dcaron': 722,
  32843. 'rcommaaccent': 333,
  32844. 'Ntilde': 722,
  32845. 'otilde': 500,
  32846. 'Rcommaaccent': 667,
  32847. 'Lcommaaccent': 611,
  32848. 'Atilde': 722,
  32849. 'Aogonek': 722,
  32850. 'Aring': 722,
  32851. 'Otilde': 722,
  32852. 'zdotaccent': 444,
  32853. 'Ecaron': 611,
  32854. 'Iogonek': 333,
  32855. 'kcommaaccent': 500,
  32856. 'minus': 564,
  32857. 'Icircumflex': 333,
  32858. 'ncaron': 500,
  32859. 'tcommaaccent': 278,
  32860. 'logicalnot': 564,
  32861. 'odieresis': 500,
  32862. 'udieresis': 500,
  32863. 'notequal': 549,
  32864. 'gcommaaccent': 500,
  32865. 'eth': 500,
  32866. 'zcaron': 444,
  32867. 'ncommaaccent': 500,
  32868. 'onesuperior': 300,
  32869. 'imacron': 278,
  32870. 'Euro': 500
  32871. },
  32872. 'Times-Bold': {
  32873. 'space': 250,
  32874. 'exclam': 333,
  32875. 'quotedbl': 555,
  32876. 'numbersign': 500,
  32877. 'dollar': 500,
  32878. 'percent': 1000,
  32879. 'ampersand': 833,
  32880. 'quoteright': 333,
  32881. 'parenleft': 333,
  32882. 'parenright': 333,
  32883. 'asterisk': 500,
  32884. 'plus': 570,
  32885. 'comma': 250,
  32886. 'hyphen': 333,
  32887. 'period': 250,
  32888. 'slash': 278,
  32889. 'zero': 500,
  32890. 'one': 500,
  32891. 'two': 500,
  32892. 'three': 500,
  32893. 'four': 500,
  32894. 'five': 500,
  32895. 'six': 500,
  32896. 'seven': 500,
  32897. 'eight': 500,
  32898. 'nine': 500,
  32899. 'colon': 333,
  32900. 'semicolon': 333,
  32901. 'less': 570,
  32902. 'equal': 570,
  32903. 'greater': 570,
  32904. 'question': 500,
  32905. 'at': 930,
  32906. 'A': 722,
  32907. 'B': 667,
  32908. 'C': 722,
  32909. 'D': 722,
  32910. 'E': 667,
  32911. 'F': 611,
  32912. 'G': 778,
  32913. 'H': 778,
  32914. 'I': 389,
  32915. 'J': 500,
  32916. 'K': 778,
  32917. 'L': 667,
  32918. 'M': 944,
  32919. 'N': 722,
  32920. 'O': 778,
  32921. 'P': 611,
  32922. 'Q': 778,
  32923. 'R': 722,
  32924. 'S': 556,
  32925. 'T': 667,
  32926. 'U': 722,
  32927. 'V': 722,
  32928. 'W': 1000,
  32929. 'X': 722,
  32930. 'Y': 722,
  32931. 'Z': 667,
  32932. 'bracketleft': 333,
  32933. 'backslash': 278,
  32934. 'bracketright': 333,
  32935. 'asciicircum': 581,
  32936. 'underscore': 500,
  32937. 'quoteleft': 333,
  32938. 'a': 500,
  32939. 'b': 556,
  32940. 'c': 444,
  32941. 'd': 556,
  32942. 'e': 444,
  32943. 'f': 333,
  32944. 'g': 500,
  32945. 'h': 556,
  32946. 'i': 278,
  32947. 'j': 333,
  32948. 'k': 556,
  32949. 'l': 278,
  32950. 'm': 833,
  32951. 'n': 556,
  32952. 'o': 500,
  32953. 'p': 556,
  32954. 'q': 556,
  32955. 'r': 444,
  32956. 's': 389,
  32957. 't': 333,
  32958. 'u': 556,
  32959. 'v': 500,
  32960. 'w': 722,
  32961. 'x': 500,
  32962. 'y': 500,
  32963. 'z': 444,
  32964. 'braceleft': 394,
  32965. 'bar': 220,
  32966. 'braceright': 394,
  32967. 'asciitilde': 520,
  32968. 'exclamdown': 333,
  32969. 'cent': 500,
  32970. 'sterling': 500,
  32971. 'fraction': 167,
  32972. 'yen': 500,
  32973. 'florin': 500,
  32974. 'section': 500,
  32975. 'currency': 500,
  32976. 'quotesingle': 278,
  32977. 'quotedblleft': 500,
  32978. 'guillemotleft': 500,
  32979. 'guilsinglleft': 333,
  32980. 'guilsinglright': 333,
  32981. 'fi': 556,
  32982. 'fl': 556,
  32983. 'endash': 500,
  32984. 'dagger': 500,
  32985. 'daggerdbl': 500,
  32986. 'periodcentered': 250,
  32987. 'paragraph': 540,
  32988. 'bullet': 350,
  32989. 'quotesinglbase': 333,
  32990. 'quotedblbase': 500,
  32991. 'quotedblright': 500,
  32992. 'guillemotright': 500,
  32993. 'ellipsis': 1000,
  32994. 'perthousand': 1000,
  32995. 'questiondown': 500,
  32996. 'grave': 333,
  32997. 'acute': 333,
  32998. 'circumflex': 333,
  32999. 'tilde': 333,
  33000. 'macron': 333,
  33001. 'breve': 333,
  33002. 'dotaccent': 333,
  33003. 'dieresis': 333,
  33004. 'ring': 333,
  33005. 'cedilla': 333,
  33006. 'hungarumlaut': 333,
  33007. 'ogonek': 333,
  33008. 'caron': 333,
  33009. 'emdash': 1000,
  33010. 'AE': 1000,
  33011. 'ordfeminine': 300,
  33012. 'Lslash': 667,
  33013. 'Oslash': 778,
  33014. 'OE': 1000,
  33015. 'ordmasculine': 330,
  33016. 'ae': 722,
  33017. 'dotlessi': 278,
  33018. 'lslash': 278,
  33019. 'oslash': 500,
  33020. 'oe': 722,
  33021. 'germandbls': 556,
  33022. 'Idieresis': 389,
  33023. 'eacute': 444,
  33024. 'abreve': 500,
  33025. 'uhungarumlaut': 556,
  33026. 'ecaron': 444,
  33027. 'Ydieresis': 722,
  33028. 'divide': 570,
  33029. 'Yacute': 722,
  33030. 'Acircumflex': 722,
  33031. 'aacute': 500,
  33032. 'Ucircumflex': 722,
  33033. 'yacute': 500,
  33034. 'scommaaccent': 389,
  33035. 'ecircumflex': 444,
  33036. 'Uring': 722,
  33037. 'Udieresis': 722,
  33038. 'aogonek': 500,
  33039. 'Uacute': 722,
  33040. 'uogonek': 556,
  33041. 'Edieresis': 667,
  33042. 'Dcroat': 722,
  33043. 'commaaccent': 250,
  33044. 'copyright': 747,
  33045. 'Emacron': 667,
  33046. 'ccaron': 444,
  33047. 'aring': 500,
  33048. 'Ncommaaccent': 722,
  33049. 'lacute': 278,
  33050. 'agrave': 500,
  33051. 'Tcommaaccent': 667,
  33052. 'Cacute': 722,
  33053. 'atilde': 500,
  33054. 'Edotaccent': 667,
  33055. 'scaron': 389,
  33056. 'scedilla': 389,
  33057. 'iacute': 278,
  33058. 'lozenge': 494,
  33059. 'Rcaron': 722,
  33060. 'Gcommaaccent': 778,
  33061. 'ucircumflex': 556,
  33062. 'acircumflex': 500,
  33063. 'Amacron': 722,
  33064. 'rcaron': 444,
  33065. 'ccedilla': 444,
  33066. 'Zdotaccent': 667,
  33067. 'Thorn': 611,
  33068. 'Omacron': 778,
  33069. 'Racute': 722,
  33070. 'Sacute': 556,
  33071. 'dcaron': 672,
  33072. 'Umacron': 722,
  33073. 'uring': 556,
  33074. 'threesuperior': 300,
  33075. 'Ograve': 778,
  33076. 'Agrave': 722,
  33077. 'Abreve': 722,
  33078. 'multiply': 570,
  33079. 'uacute': 556,
  33080. 'Tcaron': 667,
  33081. 'partialdiff': 494,
  33082. 'ydieresis': 500,
  33083. 'Nacute': 722,
  33084. 'icircumflex': 278,
  33085. 'Ecircumflex': 667,
  33086. 'adieresis': 500,
  33087. 'edieresis': 444,
  33088. 'cacute': 444,
  33089. 'nacute': 556,
  33090. 'umacron': 556,
  33091. 'Ncaron': 722,
  33092. 'Iacute': 389,
  33093. 'plusminus': 570,
  33094. 'brokenbar': 220,
  33095. 'registered': 747,
  33096. 'Gbreve': 778,
  33097. 'Idotaccent': 389,
  33098. 'summation': 600,
  33099. 'Egrave': 667,
  33100. 'racute': 444,
  33101. 'omacron': 500,
  33102. 'Zacute': 667,
  33103. 'Zcaron': 667,
  33104. 'greaterequal': 549,
  33105. 'Eth': 722,
  33106. 'Ccedilla': 722,
  33107. 'lcommaaccent': 278,
  33108. 'tcaron': 416,
  33109. 'eogonek': 444,
  33110. 'Uogonek': 722,
  33111. 'Aacute': 722,
  33112. 'Adieresis': 722,
  33113. 'egrave': 444,
  33114. 'zacute': 444,
  33115. 'iogonek': 278,
  33116. 'Oacute': 778,
  33117. 'oacute': 500,
  33118. 'amacron': 500,
  33119. 'sacute': 389,
  33120. 'idieresis': 278,
  33121. 'Ocircumflex': 778,
  33122. 'Ugrave': 722,
  33123. 'Delta': 612,
  33124. 'thorn': 556,
  33125. 'twosuperior': 300,
  33126. 'Odieresis': 778,
  33127. 'mu': 556,
  33128. 'igrave': 278,
  33129. 'ohungarumlaut': 500,
  33130. 'Eogonek': 667,
  33131. 'dcroat': 556,
  33132. 'threequarters': 750,
  33133. 'Scedilla': 556,
  33134. 'lcaron': 394,
  33135. 'Kcommaaccent': 778,
  33136. 'Lacute': 667,
  33137. 'trademark': 1000,
  33138. 'edotaccent': 444,
  33139. 'Igrave': 389,
  33140. 'Imacron': 389,
  33141. 'Lcaron': 667,
  33142. 'onehalf': 750,
  33143. 'lessequal': 549,
  33144. 'ocircumflex': 500,
  33145. 'ntilde': 556,
  33146. 'Uhungarumlaut': 722,
  33147. 'Eacute': 667,
  33148. 'emacron': 444,
  33149. 'gbreve': 500,
  33150. 'onequarter': 750,
  33151. 'Scaron': 556,
  33152. 'Scommaaccent': 556,
  33153. 'Ohungarumlaut': 778,
  33154. 'degree': 400,
  33155. 'ograve': 500,
  33156. 'Ccaron': 722,
  33157. 'ugrave': 556,
  33158. 'radical': 549,
  33159. 'Dcaron': 722,
  33160. 'rcommaaccent': 444,
  33161. 'Ntilde': 722,
  33162. 'otilde': 500,
  33163. 'Rcommaaccent': 722,
  33164. 'Lcommaaccent': 667,
  33165. 'Atilde': 722,
  33166. 'Aogonek': 722,
  33167. 'Aring': 722,
  33168. 'Otilde': 778,
  33169. 'zdotaccent': 444,
  33170. 'Ecaron': 667,
  33171. 'Iogonek': 389,
  33172. 'kcommaaccent': 556,
  33173. 'minus': 570,
  33174. 'Icircumflex': 389,
  33175. 'ncaron': 556,
  33176. 'tcommaaccent': 333,
  33177. 'logicalnot': 570,
  33178. 'odieresis': 500,
  33179. 'udieresis': 556,
  33180. 'notequal': 549,
  33181. 'gcommaaccent': 500,
  33182. 'eth': 500,
  33183. 'zcaron': 444,
  33184. 'ncommaaccent': 556,
  33185. 'onesuperior': 300,
  33186. 'imacron': 278,
  33187. 'Euro': 500
  33188. },
  33189. 'Times-BoldItalic': {
  33190. 'space': 250,
  33191. 'exclam': 389,
  33192. 'quotedbl': 555,
  33193. 'numbersign': 500,
  33194. 'dollar': 500,
  33195. 'percent': 833,
  33196. 'ampersand': 778,
  33197. 'quoteright': 333,
  33198. 'parenleft': 333,
  33199. 'parenright': 333,
  33200. 'asterisk': 500,
  33201. 'plus': 570,
  33202. 'comma': 250,
  33203. 'hyphen': 333,
  33204. 'period': 250,
  33205. 'slash': 278,
  33206. 'zero': 500,
  33207. 'one': 500,
  33208. 'two': 500,
  33209. 'three': 500,
  33210. 'four': 500,
  33211. 'five': 500,
  33212. 'six': 500,
  33213. 'seven': 500,
  33214. 'eight': 500,
  33215. 'nine': 500,
  33216. 'colon': 333,
  33217. 'semicolon': 333,
  33218. 'less': 570,
  33219. 'equal': 570,
  33220. 'greater': 570,
  33221. 'question': 500,
  33222. 'at': 832,
  33223. 'A': 667,
  33224. 'B': 667,
  33225. 'C': 667,
  33226. 'D': 722,
  33227. 'E': 667,
  33228. 'F': 667,
  33229. 'G': 722,
  33230. 'H': 778,
  33231. 'I': 389,
  33232. 'J': 500,
  33233. 'K': 667,
  33234. 'L': 611,
  33235. 'M': 889,
  33236. 'N': 722,
  33237. 'O': 722,
  33238. 'P': 611,
  33239. 'Q': 722,
  33240. 'R': 667,
  33241. 'S': 556,
  33242. 'T': 611,
  33243. 'U': 722,
  33244. 'V': 667,
  33245. 'W': 889,
  33246. 'X': 667,
  33247. 'Y': 611,
  33248. 'Z': 611,
  33249. 'bracketleft': 333,
  33250. 'backslash': 278,
  33251. 'bracketright': 333,
  33252. 'asciicircum': 570,
  33253. 'underscore': 500,
  33254. 'quoteleft': 333,
  33255. 'a': 500,
  33256. 'b': 500,
  33257. 'c': 444,
  33258. 'd': 500,
  33259. 'e': 444,
  33260. 'f': 333,
  33261. 'g': 500,
  33262. 'h': 556,
  33263. 'i': 278,
  33264. 'j': 278,
  33265. 'k': 500,
  33266. 'l': 278,
  33267. 'm': 778,
  33268. 'n': 556,
  33269. 'o': 500,
  33270. 'p': 500,
  33271. 'q': 500,
  33272. 'r': 389,
  33273. 's': 389,
  33274. 't': 278,
  33275. 'u': 556,
  33276. 'v': 444,
  33277. 'w': 667,
  33278. 'x': 500,
  33279. 'y': 444,
  33280. 'z': 389,
  33281. 'braceleft': 348,
  33282. 'bar': 220,
  33283. 'braceright': 348,
  33284. 'asciitilde': 570,
  33285. 'exclamdown': 389,
  33286. 'cent': 500,
  33287. 'sterling': 500,
  33288. 'fraction': 167,
  33289. 'yen': 500,
  33290. 'florin': 500,
  33291. 'section': 500,
  33292. 'currency': 500,
  33293. 'quotesingle': 278,
  33294. 'quotedblleft': 500,
  33295. 'guillemotleft': 500,
  33296. 'guilsinglleft': 333,
  33297. 'guilsinglright': 333,
  33298. 'fi': 556,
  33299. 'fl': 556,
  33300. 'endash': 500,
  33301. 'dagger': 500,
  33302. 'daggerdbl': 500,
  33303. 'periodcentered': 250,
  33304. 'paragraph': 500,
  33305. 'bullet': 350,
  33306. 'quotesinglbase': 333,
  33307. 'quotedblbase': 500,
  33308. 'quotedblright': 500,
  33309. 'guillemotright': 500,
  33310. 'ellipsis': 1000,
  33311. 'perthousand': 1000,
  33312. 'questiondown': 500,
  33313. 'grave': 333,
  33314. 'acute': 333,
  33315. 'circumflex': 333,
  33316. 'tilde': 333,
  33317. 'macron': 333,
  33318. 'breve': 333,
  33319. 'dotaccent': 333,
  33320. 'dieresis': 333,
  33321. 'ring': 333,
  33322. 'cedilla': 333,
  33323. 'hungarumlaut': 333,
  33324. 'ogonek': 333,
  33325. 'caron': 333,
  33326. 'emdash': 1000,
  33327. 'AE': 944,
  33328. 'ordfeminine': 266,
  33329. 'Lslash': 611,
  33330. 'Oslash': 722,
  33331. 'OE': 944,
  33332. 'ordmasculine': 300,
  33333. 'ae': 722,
  33334. 'dotlessi': 278,
  33335. 'lslash': 278,
  33336. 'oslash': 500,
  33337. 'oe': 722,
  33338. 'germandbls': 500,
  33339. 'Idieresis': 389,
  33340. 'eacute': 444,
  33341. 'abreve': 500,
  33342. 'uhungarumlaut': 556,
  33343. 'ecaron': 444,
  33344. 'Ydieresis': 611,
  33345. 'divide': 570,
  33346. 'Yacute': 611,
  33347. 'Acircumflex': 667,
  33348. 'aacute': 500,
  33349. 'Ucircumflex': 722,
  33350. 'yacute': 444,
  33351. 'scommaaccent': 389,
  33352. 'ecircumflex': 444,
  33353. 'Uring': 722,
  33354. 'Udieresis': 722,
  33355. 'aogonek': 500,
  33356. 'Uacute': 722,
  33357. 'uogonek': 556,
  33358. 'Edieresis': 667,
  33359. 'Dcroat': 722,
  33360. 'commaaccent': 250,
  33361. 'copyright': 747,
  33362. 'Emacron': 667,
  33363. 'ccaron': 444,
  33364. 'aring': 500,
  33365. 'Ncommaaccent': 722,
  33366. 'lacute': 278,
  33367. 'agrave': 500,
  33368. 'Tcommaaccent': 611,
  33369. 'Cacute': 667,
  33370. 'atilde': 500,
  33371. 'Edotaccent': 667,
  33372. 'scaron': 389,
  33373. 'scedilla': 389,
  33374. 'iacute': 278,
  33375. 'lozenge': 494,
  33376. 'Rcaron': 667,
  33377. 'Gcommaaccent': 722,
  33378. 'ucircumflex': 556,
  33379. 'acircumflex': 500,
  33380. 'Amacron': 667,
  33381. 'rcaron': 389,
  33382. 'ccedilla': 444,
  33383. 'Zdotaccent': 611,
  33384. 'Thorn': 611,
  33385. 'Omacron': 722,
  33386. 'Racute': 667,
  33387. 'Sacute': 556,
  33388. 'dcaron': 608,
  33389. 'Umacron': 722,
  33390. 'uring': 556,
  33391. 'threesuperior': 300,
  33392. 'Ograve': 722,
  33393. 'Agrave': 667,
  33394. 'Abreve': 667,
  33395. 'multiply': 570,
  33396. 'uacute': 556,
  33397. 'Tcaron': 611,
  33398. 'partialdiff': 494,
  33399. 'ydieresis': 444,
  33400. 'Nacute': 722,
  33401. 'icircumflex': 278,
  33402. 'Ecircumflex': 667,
  33403. 'adieresis': 500,
  33404. 'edieresis': 444,
  33405. 'cacute': 444,
  33406. 'nacute': 556,
  33407. 'umacron': 556,
  33408. 'Ncaron': 722,
  33409. 'Iacute': 389,
  33410. 'plusminus': 570,
  33411. 'brokenbar': 220,
  33412. 'registered': 747,
  33413. 'Gbreve': 722,
  33414. 'Idotaccent': 389,
  33415. 'summation': 600,
  33416. 'Egrave': 667,
  33417. 'racute': 389,
  33418. 'omacron': 500,
  33419. 'Zacute': 611,
  33420. 'Zcaron': 611,
  33421. 'greaterequal': 549,
  33422. 'Eth': 722,
  33423. 'Ccedilla': 667,
  33424. 'lcommaaccent': 278,
  33425. 'tcaron': 366,
  33426. 'eogonek': 444,
  33427. 'Uogonek': 722,
  33428. 'Aacute': 667,
  33429. 'Adieresis': 667,
  33430. 'egrave': 444,
  33431. 'zacute': 389,
  33432. 'iogonek': 278,
  33433. 'Oacute': 722,
  33434. 'oacute': 500,
  33435. 'amacron': 500,
  33436. 'sacute': 389,
  33437. 'idieresis': 278,
  33438. 'Ocircumflex': 722,
  33439. 'Ugrave': 722,
  33440. 'Delta': 612,
  33441. 'thorn': 500,
  33442. 'twosuperior': 300,
  33443. 'Odieresis': 722,
  33444. 'mu': 576,
  33445. 'igrave': 278,
  33446. 'ohungarumlaut': 500,
  33447. 'Eogonek': 667,
  33448. 'dcroat': 500,
  33449. 'threequarters': 750,
  33450. 'Scedilla': 556,
  33451. 'lcaron': 382,
  33452. 'Kcommaaccent': 667,
  33453. 'Lacute': 611,
  33454. 'trademark': 1000,
  33455. 'edotaccent': 444,
  33456. 'Igrave': 389,
  33457. 'Imacron': 389,
  33458. 'Lcaron': 611,
  33459. 'onehalf': 750,
  33460. 'lessequal': 549,
  33461. 'ocircumflex': 500,
  33462. 'ntilde': 556,
  33463. 'Uhungarumlaut': 722,
  33464. 'Eacute': 667,
  33465. 'emacron': 444,
  33466. 'gbreve': 500,
  33467. 'onequarter': 750,
  33468. 'Scaron': 556,
  33469. 'Scommaaccent': 556,
  33470. 'Ohungarumlaut': 722,
  33471. 'degree': 400,
  33472. 'ograve': 500,
  33473. 'Ccaron': 667,
  33474. 'ugrave': 556,
  33475. 'radical': 549,
  33476. 'Dcaron': 722,
  33477. 'rcommaaccent': 389,
  33478. 'Ntilde': 722,
  33479. 'otilde': 500,
  33480. 'Rcommaaccent': 667,
  33481. 'Lcommaaccent': 611,
  33482. 'Atilde': 667,
  33483. 'Aogonek': 667,
  33484. 'Aring': 667,
  33485. 'Otilde': 722,
  33486. 'zdotaccent': 389,
  33487. 'Ecaron': 667,
  33488. 'Iogonek': 389,
  33489. 'kcommaaccent': 500,
  33490. 'minus': 606,
  33491. 'Icircumflex': 389,
  33492. 'ncaron': 556,
  33493. 'tcommaaccent': 278,
  33494. 'logicalnot': 606,
  33495. 'odieresis': 500,
  33496. 'udieresis': 556,
  33497. 'notequal': 549,
  33498. 'gcommaaccent': 500,
  33499. 'eth': 500,
  33500. 'zcaron': 389,
  33501. 'ncommaaccent': 556,
  33502. 'onesuperior': 300,
  33503. 'imacron': 278,
  33504. 'Euro': 500
  33505. },
  33506. 'Times-Italic': {
  33507. 'space': 250,
  33508. 'exclam': 333,
  33509. 'quotedbl': 420,
  33510. 'numbersign': 500,
  33511. 'dollar': 500,
  33512. 'percent': 833,
  33513. 'ampersand': 778,
  33514. 'quoteright': 333,
  33515. 'parenleft': 333,
  33516. 'parenright': 333,
  33517. 'asterisk': 500,
  33518. 'plus': 675,
  33519. 'comma': 250,
  33520. 'hyphen': 333,
  33521. 'period': 250,
  33522. 'slash': 278,
  33523. 'zero': 500,
  33524. 'one': 500,
  33525. 'two': 500,
  33526. 'three': 500,
  33527. 'four': 500,
  33528. 'five': 500,
  33529. 'six': 500,
  33530. 'seven': 500,
  33531. 'eight': 500,
  33532. 'nine': 500,
  33533. 'colon': 333,
  33534. 'semicolon': 333,
  33535. 'less': 675,
  33536. 'equal': 675,
  33537. 'greater': 675,
  33538. 'question': 500,
  33539. 'at': 920,
  33540. 'A': 611,
  33541. 'B': 611,
  33542. 'C': 667,
  33543. 'D': 722,
  33544. 'E': 611,
  33545. 'F': 611,
  33546. 'G': 722,
  33547. 'H': 722,
  33548. 'I': 333,
  33549. 'J': 444,
  33550. 'K': 667,
  33551. 'L': 556,
  33552. 'M': 833,
  33553. 'N': 667,
  33554. 'O': 722,
  33555. 'P': 611,
  33556. 'Q': 722,
  33557. 'R': 611,
  33558. 'S': 500,
  33559. 'T': 556,
  33560. 'U': 722,
  33561. 'V': 611,
  33562. 'W': 833,
  33563. 'X': 611,
  33564. 'Y': 556,
  33565. 'Z': 556,
  33566. 'bracketleft': 389,
  33567. 'backslash': 278,
  33568. 'bracketright': 389,
  33569. 'asciicircum': 422,
  33570. 'underscore': 500,
  33571. 'quoteleft': 333,
  33572. 'a': 500,
  33573. 'b': 500,
  33574. 'c': 444,
  33575. 'd': 500,
  33576. 'e': 444,
  33577. 'f': 278,
  33578. 'g': 500,
  33579. 'h': 500,
  33580. 'i': 278,
  33581. 'j': 278,
  33582. 'k': 444,
  33583. 'l': 278,
  33584. 'm': 722,
  33585. 'n': 500,
  33586. 'o': 500,
  33587. 'p': 500,
  33588. 'q': 500,
  33589. 'r': 389,
  33590. 's': 389,
  33591. 't': 278,
  33592. 'u': 500,
  33593. 'v': 444,
  33594. 'w': 667,
  33595. 'x': 444,
  33596. 'y': 444,
  33597. 'z': 389,
  33598. 'braceleft': 400,
  33599. 'bar': 275,
  33600. 'braceright': 400,
  33601. 'asciitilde': 541,
  33602. 'exclamdown': 389,
  33603. 'cent': 500,
  33604. 'sterling': 500,
  33605. 'fraction': 167,
  33606. 'yen': 500,
  33607. 'florin': 500,
  33608. 'section': 500,
  33609. 'currency': 500,
  33610. 'quotesingle': 214,
  33611. 'quotedblleft': 556,
  33612. 'guillemotleft': 500,
  33613. 'guilsinglleft': 333,
  33614. 'guilsinglright': 333,
  33615. 'fi': 500,
  33616. 'fl': 500,
  33617. 'endash': 500,
  33618. 'dagger': 500,
  33619. 'daggerdbl': 500,
  33620. 'periodcentered': 250,
  33621. 'paragraph': 523,
  33622. 'bullet': 350,
  33623. 'quotesinglbase': 333,
  33624. 'quotedblbase': 556,
  33625. 'quotedblright': 556,
  33626. 'guillemotright': 500,
  33627. 'ellipsis': 889,
  33628. 'perthousand': 1000,
  33629. 'questiondown': 500,
  33630. 'grave': 333,
  33631. 'acute': 333,
  33632. 'circumflex': 333,
  33633. 'tilde': 333,
  33634. 'macron': 333,
  33635. 'breve': 333,
  33636. 'dotaccent': 333,
  33637. 'dieresis': 333,
  33638. 'ring': 333,
  33639. 'cedilla': 333,
  33640. 'hungarumlaut': 333,
  33641. 'ogonek': 333,
  33642. 'caron': 333,
  33643. 'emdash': 889,
  33644. 'AE': 889,
  33645. 'ordfeminine': 276,
  33646. 'Lslash': 556,
  33647. 'Oslash': 722,
  33648. 'OE': 944,
  33649. 'ordmasculine': 310,
  33650. 'ae': 667,
  33651. 'dotlessi': 278,
  33652. 'lslash': 278,
  33653. 'oslash': 500,
  33654. 'oe': 667,
  33655. 'germandbls': 500,
  33656. 'Idieresis': 333,
  33657. 'eacute': 444,
  33658. 'abreve': 500,
  33659. 'uhungarumlaut': 500,
  33660. 'ecaron': 444,
  33661. 'Ydieresis': 556,
  33662. 'divide': 675,
  33663. 'Yacute': 556,
  33664. 'Acircumflex': 611,
  33665. 'aacute': 500,
  33666. 'Ucircumflex': 722,
  33667. 'yacute': 444,
  33668. 'scommaaccent': 389,
  33669. 'ecircumflex': 444,
  33670. 'Uring': 722,
  33671. 'Udieresis': 722,
  33672. 'aogonek': 500,
  33673. 'Uacute': 722,
  33674. 'uogonek': 500,
  33675. 'Edieresis': 611,
  33676. 'Dcroat': 722,
  33677. 'commaaccent': 250,
  33678. 'copyright': 760,
  33679. 'Emacron': 611,
  33680. 'ccaron': 444,
  33681. 'aring': 500,
  33682. 'Ncommaaccent': 667,
  33683. 'lacute': 278,
  33684. 'agrave': 500,
  33685. 'Tcommaaccent': 556,
  33686. 'Cacute': 667,
  33687. 'atilde': 500,
  33688. 'Edotaccent': 611,
  33689. 'scaron': 389,
  33690. 'scedilla': 389,
  33691. 'iacute': 278,
  33692. 'lozenge': 471,
  33693. 'Rcaron': 611,
  33694. 'Gcommaaccent': 722,
  33695. 'ucircumflex': 500,
  33696. 'acircumflex': 500,
  33697. 'Amacron': 611,
  33698. 'rcaron': 389,
  33699. 'ccedilla': 444,
  33700. 'Zdotaccent': 556,
  33701. 'Thorn': 611,
  33702. 'Omacron': 722,
  33703. 'Racute': 611,
  33704. 'Sacute': 500,
  33705. 'dcaron': 544,
  33706. 'Umacron': 722,
  33707. 'uring': 500,
  33708. 'threesuperior': 300,
  33709. 'Ograve': 722,
  33710. 'Agrave': 611,
  33711. 'Abreve': 611,
  33712. 'multiply': 675,
  33713. 'uacute': 500,
  33714. 'Tcaron': 556,
  33715. 'partialdiff': 476,
  33716. 'ydieresis': 444,
  33717. 'Nacute': 667,
  33718. 'icircumflex': 278,
  33719. 'Ecircumflex': 611,
  33720. 'adieresis': 500,
  33721. 'edieresis': 444,
  33722. 'cacute': 444,
  33723. 'nacute': 500,
  33724. 'umacron': 500,
  33725. 'Ncaron': 667,
  33726. 'Iacute': 333,
  33727. 'plusminus': 675,
  33728. 'brokenbar': 275,
  33729. 'registered': 760,
  33730. 'Gbreve': 722,
  33731. 'Idotaccent': 333,
  33732. 'summation': 600,
  33733. 'Egrave': 611,
  33734. 'racute': 389,
  33735. 'omacron': 500,
  33736. 'Zacute': 556,
  33737. 'Zcaron': 556,
  33738. 'greaterequal': 549,
  33739. 'Eth': 722,
  33740. 'Ccedilla': 667,
  33741. 'lcommaaccent': 278,
  33742. 'tcaron': 300,
  33743. 'eogonek': 444,
  33744. 'Uogonek': 722,
  33745. 'Aacute': 611,
  33746. 'Adieresis': 611,
  33747. 'egrave': 444,
  33748. 'zacute': 389,
  33749. 'iogonek': 278,
  33750. 'Oacute': 722,
  33751. 'oacute': 500,
  33752. 'amacron': 500,
  33753. 'sacute': 389,
  33754. 'idieresis': 278,
  33755. 'Ocircumflex': 722,
  33756. 'Ugrave': 722,
  33757. 'Delta': 612,
  33758. 'thorn': 500,
  33759. 'twosuperior': 300,
  33760. 'Odieresis': 722,
  33761. 'mu': 500,
  33762. 'igrave': 278,
  33763. 'ohungarumlaut': 500,
  33764. 'Eogonek': 611,
  33765. 'dcroat': 500,
  33766. 'threequarters': 750,
  33767. 'Scedilla': 500,
  33768. 'lcaron': 300,
  33769. 'Kcommaaccent': 667,
  33770. 'Lacute': 556,
  33771. 'trademark': 980,
  33772. 'edotaccent': 444,
  33773. 'Igrave': 333,
  33774. 'Imacron': 333,
  33775. 'Lcaron': 611,
  33776. 'onehalf': 750,
  33777. 'lessequal': 549,
  33778. 'ocircumflex': 500,
  33779. 'ntilde': 500,
  33780. 'Uhungarumlaut': 722,
  33781. 'Eacute': 611,
  33782. 'emacron': 444,
  33783. 'gbreve': 500,
  33784. 'onequarter': 750,
  33785. 'Scaron': 500,
  33786. 'Scommaaccent': 500,
  33787. 'Ohungarumlaut': 722,
  33788. 'degree': 400,
  33789. 'ograve': 500,
  33790. 'Ccaron': 667,
  33791. 'ugrave': 500,
  33792. 'radical': 453,
  33793. 'Dcaron': 722,
  33794. 'rcommaaccent': 389,
  33795. 'Ntilde': 667,
  33796. 'otilde': 500,
  33797. 'Rcommaaccent': 611,
  33798. 'Lcommaaccent': 556,
  33799. 'Atilde': 611,
  33800. 'Aogonek': 611,
  33801. 'Aring': 611,
  33802. 'Otilde': 722,
  33803. 'zdotaccent': 389,
  33804. 'Ecaron': 611,
  33805. 'Iogonek': 333,
  33806. 'kcommaaccent': 444,
  33807. 'minus': 675,
  33808. 'Icircumflex': 333,
  33809. 'ncaron': 500,
  33810. 'tcommaaccent': 278,
  33811. 'logicalnot': 675,
  33812. 'odieresis': 500,
  33813. 'udieresis': 500,
  33814. 'notequal': 549,
  33815. 'gcommaaccent': 500,
  33816. 'eth': 500,
  33817. 'zcaron': 389,
  33818. 'ncommaaccent': 500,
  33819. 'onesuperior': 300,
  33820. 'imacron': 278,
  33821. 'Euro': 500
  33822. },
  33823. 'ZapfDingbats': {
  33824. 'space': 278,
  33825. 'a1': 974,
  33826. 'a2': 961,
  33827. 'a202': 974,
  33828. 'a3': 980,
  33829. 'a4': 719,
  33830. 'a5': 789,
  33831. 'a119': 790,
  33832. 'a118': 791,
  33833. 'a117': 690,
  33834. 'a11': 960,
  33835. 'a12': 939,
  33836. 'a13': 549,
  33837. 'a14': 855,
  33838. 'a15': 911,
  33839. 'a16': 933,
  33840. 'a105': 911,
  33841. 'a17': 945,
  33842. 'a18': 974,
  33843. 'a19': 755,
  33844. 'a20': 846,
  33845. 'a21': 762,
  33846. 'a22': 761,
  33847. 'a23': 571,
  33848. 'a24': 677,
  33849. 'a25': 763,
  33850. 'a26': 760,
  33851. 'a27': 759,
  33852. 'a28': 754,
  33853. 'a6': 494,
  33854. 'a7': 552,
  33855. 'a8': 537,
  33856. 'a9': 577,
  33857. 'a10': 692,
  33858. 'a29': 786,
  33859. 'a30': 788,
  33860. 'a31': 788,
  33861. 'a32': 790,
  33862. 'a33': 793,
  33863. 'a34': 794,
  33864. 'a35': 816,
  33865. 'a36': 823,
  33866. 'a37': 789,
  33867. 'a38': 841,
  33868. 'a39': 823,
  33869. 'a40': 833,
  33870. 'a41': 816,
  33871. 'a42': 831,
  33872. 'a43': 923,
  33873. 'a44': 744,
  33874. 'a45': 723,
  33875. 'a46': 749,
  33876. 'a47': 790,
  33877. 'a48': 792,
  33878. 'a49': 695,
  33879. 'a50': 776,
  33880. 'a51': 768,
  33881. 'a52': 792,
  33882. 'a53': 759,
  33883. 'a54': 707,
  33884. 'a55': 708,
  33885. 'a56': 682,
  33886. 'a57': 701,
  33887. 'a58': 826,
  33888. 'a59': 815,
  33889. 'a60': 789,
  33890. 'a61': 789,
  33891. 'a62': 707,
  33892. 'a63': 687,
  33893. 'a64': 696,
  33894. 'a65': 689,
  33895. 'a66': 786,
  33896. 'a67': 787,
  33897. 'a68': 713,
  33898. 'a69': 791,
  33899. 'a70': 785,
  33900. 'a71': 791,
  33901. 'a72': 873,
  33902. 'a73': 761,
  33903. 'a74': 762,
  33904. 'a203': 762,
  33905. 'a75': 759,
  33906. 'a204': 759,
  33907. 'a76': 892,
  33908. 'a77': 892,
  33909. 'a78': 788,
  33910. 'a79': 784,
  33911. 'a81': 438,
  33912. 'a82': 138,
  33913. 'a83': 277,
  33914. 'a84': 415,
  33915. 'a97': 392,
  33916. 'a98': 392,
  33917. 'a99': 668,
  33918. 'a100': 668,
  33919. 'a89': 390,
  33920. 'a90': 390,
  33921. 'a93': 317,
  33922. 'a94': 317,
  33923. 'a91': 276,
  33924. 'a92': 276,
  33925. 'a205': 509,
  33926. 'a85': 509,
  33927. 'a206': 410,
  33928. 'a86': 410,
  33929. 'a87': 234,
  33930. 'a88': 234,
  33931. 'a95': 334,
  33932. 'a96': 334,
  33933. 'a101': 732,
  33934. 'a102': 544,
  33935. 'a103': 544,
  33936. 'a104': 910,
  33937. 'a106': 667,
  33938. 'a107': 760,
  33939. 'a108': 760,
  33940. 'a112': 776,
  33941. 'a111': 595,
  33942. 'a110': 694,
  33943. 'a109': 626,
  33944. 'a120': 788,
  33945. 'a121': 788,
  33946. 'a122': 788,
  33947. 'a123': 788,
  33948. 'a124': 788,
  33949. 'a125': 788,
  33950. 'a126': 788,
  33951. 'a127': 788,
  33952. 'a128': 788,
  33953. 'a129': 788,
  33954. 'a130': 788,
  33955. 'a131': 788,
  33956. 'a132': 788,
  33957. 'a133': 788,
  33958. 'a134': 788,
  33959. 'a135': 788,
  33960. 'a136': 788,
  33961. 'a137': 788,
  33962. 'a138': 788,
  33963. 'a139': 788,
  33964. 'a140': 788,
  33965. 'a141': 788,
  33966. 'a142': 788,
  33967. 'a143': 788,
  33968. 'a144': 788,
  33969. 'a145': 788,
  33970. 'a146': 788,
  33971. 'a147': 788,
  33972. 'a148': 788,
  33973. 'a149': 788,
  33974. 'a150': 788,
  33975. 'a151': 788,
  33976. 'a152': 788,
  33977. 'a153': 788,
  33978. 'a154': 788,
  33979. 'a155': 788,
  33980. 'a156': 788,
  33981. 'a157': 788,
  33982. 'a158': 788,
  33983. 'a159': 788,
  33984. 'a160': 894,
  33985. 'a161': 838,
  33986. 'a163': 1016,
  33987. 'a164': 458,
  33988. 'a196': 748,
  33989. 'a165': 924,
  33990. 'a192': 748,
  33991. 'a166': 918,
  33992. 'a167': 927,
  33993. 'a168': 928,
  33994. 'a169': 928,
  33995. 'a170': 834,
  33996. 'a171': 873,
  33997. 'a172': 828,
  33998. 'a173': 924,
  33999. 'a162': 924,
  34000. 'a174': 917,
  34001. 'a175': 930,
  34002. 'a176': 931,
  34003. 'a177': 463,
  34004. 'a178': 883,
  34005. 'a179': 836,
  34006. 'a193': 836,
  34007. 'a180': 867,
  34008. 'a199': 867,
  34009. 'a181': 696,
  34010. 'a200': 696,
  34011. 'a182': 874,
  34012. 'a201': 874,
  34013. 'a183': 760,
  34014. 'a184': 946,
  34015. 'a197': 771,
  34016. 'a185': 865,
  34017. 'a194': 771,
  34018. 'a198': 888,
  34019. 'a186': 967,
  34020. 'a195': 888,
  34021. 'a187': 831,
  34022. 'a188': 873,
  34023. 'a189': 927,
  34024. 'a190': 970,
  34025. 'a191': 918
  34026. }
  34027. };
  34028. var EOF = {};
  34029. function isEOF(v) {
  34030. return (v === EOF);
  34031. }
  34032. var MAX_LENGTH_TO_CACHE = 1000;
  34033. var Parser = (function ParserClosure() {
  34034. function Parser(lexer, allowStreams, xref) {
  34035. this.lexer = lexer;
  34036. this.allowStreams = allowStreams;
  34037. this.xref = xref;
  34038. this.imageCache = {};
  34039. this.refill();
  34040. }
  34041. Parser.prototype = {
  34042. refill: function Parser_refill() {
  34043. this.buf1 = this.lexer.getObj();
  34044. this.buf2 = this.lexer.getObj();
  34045. },
  34046. shift: function Parser_shift() {
  34047. if (isCmd(this.buf2, 'ID')) {
  34048. this.buf1 = this.buf2;
  34049. this.buf2 = null;
  34050. } else {
  34051. this.buf1 = this.buf2;
  34052. this.buf2 = this.lexer.getObj();
  34053. }
  34054. },
  34055. getObj: function Parser_getObj(cipherTransform) {
  34056. var buf1 = this.buf1;
  34057. this.shift();
  34058. if (buf1 instanceof Cmd) {
  34059. switch (buf1.cmd) {
  34060. case 'BI': // inline image
  34061. return this.makeInlineImage(cipherTransform);
  34062. case '[': // array
  34063. var array = [];
  34064. while (!isCmd(this.buf1, ']') && !isEOF(this.buf1)) {
  34065. array.push(this.getObj(cipherTransform));
  34066. }
  34067. if (isEOF(this.buf1)) {
  34068. error('End of file inside array');
  34069. }
  34070. this.shift();
  34071. return array;
  34072. case '<<': // dictionary or stream
  34073. var dict = new Dict(this.xref);
  34074. while (!isCmd(this.buf1, '>>') && !isEOF(this.buf1)) {
  34075. if (!isName(this.buf1)) {
  34076. info('Malformed dictionary: key must be a name object');
  34077. this.shift();
  34078. continue;
  34079. }
  34080. var key = this.buf1.name;
  34081. this.shift();
  34082. if (isEOF(this.buf1)) {
  34083. break;
  34084. }
  34085. dict.set(key, this.getObj(cipherTransform));
  34086. }
  34087. if (isEOF(this.buf1)) {
  34088. error('End of file inside dictionary');
  34089. }
  34090. // Stream objects are not allowed inside content streams or
  34091. // object streams.
  34092. if (isCmd(this.buf2, 'stream')) {
  34093. return (this.allowStreams ?
  34094. this.makeStream(dict, cipherTransform) : dict);
  34095. }
  34096. this.shift();
  34097. return dict;
  34098. default: // simple object
  34099. return buf1;
  34100. }
  34101. }
  34102. if (isInt(buf1)) { // indirect reference or integer
  34103. var num = buf1;
  34104. if (isInt(this.buf1) && isCmd(this.buf2, 'R')) {
  34105. var ref = new Ref(num, this.buf1);
  34106. this.shift();
  34107. this.shift();
  34108. return ref;
  34109. }
  34110. return num;
  34111. }
  34112. if (isString(buf1)) { // string
  34113. var str = buf1;
  34114. if (cipherTransform) {
  34115. str = cipherTransform.decryptString(str);
  34116. }
  34117. return str;
  34118. }
  34119. // simple object
  34120. return buf1;
  34121. },
  34122. /**
  34123. * Find the end of the stream by searching for the /EI\s/.
  34124. * @returns {number} The inline stream length.
  34125. */
  34126. findDefaultInlineStreamEnd:
  34127. function Parser_findDefaultInlineStreamEnd(stream) {
  34128. var E = 0x45, I = 0x49, SPACE = 0x20, LF = 0xA, CR = 0xD;
  34129. var startPos = stream.pos, state = 0, ch, i, n, followingBytes;
  34130. while ((ch = stream.getByte()) !== -1) {
  34131. if (state === 0) {
  34132. state = (ch === E) ? 1 : 0;
  34133. } else if (state === 1) {
  34134. state = (ch === I) ? 2 : 0;
  34135. } else {
  34136. assert(state === 2);
  34137. if (ch === SPACE || ch === LF || ch === CR) {
  34138. // Let's check the next five bytes are ASCII... just be sure.
  34139. n = 5;
  34140. followingBytes = stream.peekBytes(n);
  34141. for (i = 0; i < n; i++) {
  34142. ch = followingBytes[i];
  34143. if (ch !== LF && ch !== CR && (ch < SPACE || ch > 0x7F)) {
  34144. // Not a LF, CR, SPACE or any visible ASCII character, i.e.
  34145. // it's binary stuff. Resetting the state.
  34146. state = 0;
  34147. break;
  34148. }
  34149. }
  34150. if (state === 2) {
  34151. break; // Finished!
  34152. }
  34153. } else {
  34154. state = 0;
  34155. }
  34156. }
  34157. }
  34158. return ((stream.pos - 4) - startPos);
  34159. },
  34160. /**
  34161. * Find the EOI (end-of-image) marker 0xFFD9 of the stream.
  34162. * @returns {number} The inline stream length.
  34163. */
  34164. findDCTDecodeInlineStreamEnd:
  34165. function Parser_findDCTDecodeInlineStreamEnd(stream) {
  34166. var startPos = stream.pos, foundEOI = false, b, markerLength, length;
  34167. while ((b = stream.getByte()) !== -1) {
  34168. if (b !== 0xFF) { // Not a valid marker.
  34169. continue;
  34170. }
  34171. switch (stream.getByte()) {
  34172. case 0x00: // Byte stuffing.
  34173. // 0xFF00 appears to be a very common byte sequence in JPEG images.
  34174. break;
  34175. case 0xFF: // Fill byte.
  34176. // Avoid skipping a valid marker, resetting the stream position.
  34177. stream.skip(-1);
  34178. break;
  34179. case 0xD9: // EOI
  34180. foundEOI = true;
  34181. break;
  34182. case 0xC0: // SOF0
  34183. case 0xC1: // SOF1
  34184. case 0xC2: // SOF2
  34185. case 0xC3: // SOF3
  34186. case 0xC5: // SOF5
  34187. case 0xC6: // SOF6
  34188. case 0xC7: // SOF7
  34189. case 0xC9: // SOF9
  34190. case 0xCA: // SOF10
  34191. case 0xCB: // SOF11
  34192. case 0xCD: // SOF13
  34193. case 0xCE: // SOF14
  34194. case 0xCF: // SOF15
  34195. case 0xC4: // DHT
  34196. case 0xCC: // DAC
  34197. case 0xDA: // SOS
  34198. case 0xDB: // DQT
  34199. case 0xDC: // DNL
  34200. case 0xDD: // DRI
  34201. case 0xDE: // DHP
  34202. case 0xDF: // EXP
  34203. case 0xE0: // APP0
  34204. case 0xE1: // APP1
  34205. case 0xE2: // APP2
  34206. case 0xE3: // APP3
  34207. case 0xE4: // APP4
  34208. case 0xE5: // APP5
  34209. case 0xE6: // APP6
  34210. case 0xE7: // APP7
  34211. case 0xE8: // APP8
  34212. case 0xE9: // APP9
  34213. case 0xEA: // APP10
  34214. case 0xEB: // APP11
  34215. case 0xEC: // APP12
  34216. case 0xED: // APP13
  34217. case 0xEE: // APP14
  34218. case 0xEF: // APP15
  34219. case 0xFE: // COM
  34220. // The marker should be followed by the length of the segment.
  34221. markerLength = stream.getUint16();
  34222. if (markerLength > 2) {
  34223. // |markerLength| contains the byte length of the marker segment,
  34224. // including its own length (2 bytes) and excluding the marker.
  34225. stream.skip(markerLength - 2); // Jump to the next marker.
  34226. } else {
  34227. // The marker length is invalid, resetting the stream position.
  34228. stream.skip(-2);
  34229. }
  34230. break;
  34231. }
  34232. if (foundEOI) {
  34233. break;
  34234. }
  34235. }
  34236. length = stream.pos - startPos;
  34237. if (b === -1) {
  34238. warn('Inline DCTDecode image stream: ' +
  34239. 'EOI marker not found, searching for /EI/ instead.');
  34240. stream.skip(-length); // Reset the stream position.
  34241. return this.findDefaultInlineStreamEnd(stream);
  34242. }
  34243. this.inlineStreamSkipEI(stream);
  34244. return length;
  34245. },
  34246. /**
  34247. * Find the EOD (end-of-data) marker '~>' (i.e. TILDE + GT) of the stream.
  34248. * @returns {number} The inline stream length.
  34249. */
  34250. findASCII85DecodeInlineStreamEnd:
  34251. function Parser_findASCII85DecodeInlineStreamEnd(stream) {
  34252. var TILDE = 0x7E, GT = 0x3E;
  34253. var startPos = stream.pos, ch, length;
  34254. while ((ch = stream.getByte()) !== -1) {
  34255. if (ch === TILDE && stream.peekByte() === GT) {
  34256. stream.skip();
  34257. break;
  34258. }
  34259. }
  34260. length = stream.pos - startPos;
  34261. if (ch === -1) {
  34262. warn('Inline ASCII85Decode image stream: ' +
  34263. 'EOD marker not found, searching for /EI/ instead.');
  34264. stream.skip(-length); // Reset the stream position.
  34265. return this.findDefaultInlineStreamEnd(stream);
  34266. }
  34267. this.inlineStreamSkipEI(stream);
  34268. return length;
  34269. },
  34270. /**
  34271. * Find the EOD (end-of-data) marker '>' (i.e. GT) of the stream.
  34272. * @returns {number} The inline stream length.
  34273. */
  34274. findASCIIHexDecodeInlineStreamEnd:
  34275. function Parser_findASCIIHexDecodeInlineStreamEnd(stream) {
  34276. var GT = 0x3E;
  34277. var startPos = stream.pos, ch, length;
  34278. while ((ch = stream.getByte()) !== -1) {
  34279. if (ch === GT) {
  34280. break;
  34281. }
  34282. }
  34283. length = stream.pos - startPos;
  34284. if (ch === -1) {
  34285. warn('Inline ASCIIHexDecode image stream: ' +
  34286. 'EOD marker not found, searching for /EI/ instead.');
  34287. stream.skip(-length); // Reset the stream position.
  34288. return this.findDefaultInlineStreamEnd(stream);
  34289. }
  34290. this.inlineStreamSkipEI(stream);
  34291. return length;
  34292. },
  34293. /**
  34294. * Skip over the /EI/ for streams where we search for an EOD marker.
  34295. */
  34296. inlineStreamSkipEI: function Parser_inlineStreamSkipEI(stream) {
  34297. var E = 0x45, I = 0x49;
  34298. var state = 0, ch;
  34299. while ((ch = stream.getByte()) !== -1) {
  34300. if (state === 0) {
  34301. state = (ch === E) ? 1 : 0;
  34302. } else if (state === 1) {
  34303. state = (ch === I) ? 2 : 0;
  34304. } else if (state === 2) {
  34305. break;
  34306. }
  34307. }
  34308. },
  34309. makeInlineImage: function Parser_makeInlineImage(cipherTransform) {
  34310. var lexer = this.lexer;
  34311. var stream = lexer.stream;
  34312. // Parse dictionary.
  34313. var dict = new Dict(null);
  34314. while (!isCmd(this.buf1, 'ID') && !isEOF(this.buf1)) {
  34315. if (!isName(this.buf1)) {
  34316. error('Dictionary key must be a name object');
  34317. }
  34318. var key = this.buf1.name;
  34319. this.shift();
  34320. if (isEOF(this.buf1)) {
  34321. break;
  34322. }
  34323. dict.set(key, this.getObj(cipherTransform));
  34324. }
  34325. // Extract the name of the first (i.e. the current) image filter.
  34326. var filter = this.fetchIfRef(dict.get('Filter', 'F')), filterName;
  34327. if (isName(filter)) {
  34328. filterName = filter.name;
  34329. } else if (isArray(filter) && isName(filter[0])) {
  34330. filterName = filter[0].name;
  34331. }
  34332. // Parse image stream.
  34333. var startPos = stream.pos, length, i, ii;
  34334. if (filterName === 'DCTDecode' || filterName === 'DCT') {
  34335. length = this.findDCTDecodeInlineStreamEnd(stream);
  34336. } else if (filterName === 'ASCII85Decide' || filterName === 'A85') {
  34337. length = this.findASCII85DecodeInlineStreamEnd(stream);
  34338. } else if (filterName === 'ASCIIHexDecode' || filterName === 'AHx') {
  34339. length = this.findASCIIHexDecodeInlineStreamEnd(stream);
  34340. } else {
  34341. length = this.findDefaultInlineStreamEnd(stream);
  34342. }
  34343. var imageStream = stream.makeSubStream(startPos, length, dict);
  34344. // Cache all images below the MAX_LENGTH_TO_CACHE threshold by their
  34345. // adler32 checksum.
  34346. var adler32;
  34347. if (length < MAX_LENGTH_TO_CACHE) {
  34348. var imageBytes = imageStream.getBytes();
  34349. imageStream.reset();
  34350. var a = 1;
  34351. var b = 0;
  34352. for (i = 0, ii = imageBytes.length; i < ii; ++i) {
  34353. // No modulo required in the loop if imageBytes.length < 5552.
  34354. a += imageBytes[i] & 0xff;
  34355. b += a;
  34356. }
  34357. adler32 = ((b % 65521) << 16) | (a % 65521);
  34358. if (this.imageCache.adler32 === adler32) {
  34359. this.buf2 = Cmd.get('EI');
  34360. this.shift();
  34361. this.imageCache[adler32].reset();
  34362. return this.imageCache[adler32];
  34363. }
  34364. }
  34365. if (cipherTransform) {
  34366. imageStream = cipherTransform.createStream(imageStream, length);
  34367. }
  34368. imageStream = this.filter(imageStream, dict, length);
  34369. imageStream.dict = dict;
  34370. if (adler32 !== undefined) {
  34371. imageStream.cacheKey = 'inline_' + length + '_' + adler32;
  34372. this.imageCache[adler32] = imageStream;
  34373. }
  34374. this.buf2 = Cmd.get('EI');
  34375. this.shift();
  34376. return imageStream;
  34377. },
  34378. fetchIfRef: function Parser_fetchIfRef(obj) {
  34379. // not relying on the xref.fetchIfRef -- xref might not be set
  34380. return (isRef(obj) ? this.xref.fetch(obj) : obj);
  34381. },
  34382. makeStream: function Parser_makeStream(dict, cipherTransform) {
  34383. var lexer = this.lexer;
  34384. var stream = lexer.stream;
  34385. // get stream start position
  34386. lexer.skipToNextLine();
  34387. var pos = stream.pos - 1;
  34388. // get length
  34389. var length = this.fetchIfRef(dict.get('Length'));
  34390. if (!isInt(length)) {
  34391. info('Bad ' + length + ' attribute in stream');
  34392. length = 0;
  34393. }
  34394. // skip over the stream data
  34395. stream.pos = pos + length;
  34396. lexer.nextChar();
  34397. this.shift(); // '>>'
  34398. this.shift(); // 'stream'
  34399. if (!isCmd(this.buf1, 'endstream')) {
  34400. // bad stream length, scanning for endstream
  34401. stream.pos = pos;
  34402. var SCAN_BLOCK_SIZE = 2048;
  34403. var ENDSTREAM_SIGNATURE_LENGTH = 9;
  34404. var ENDSTREAM_SIGNATURE = [0x65, 0x6E, 0x64, 0x73, 0x74, 0x72, 0x65,
  34405. 0x61, 0x6D];
  34406. var skipped = 0, found = false, i, j;
  34407. while (stream.pos < stream.end) {
  34408. var scanBytes = stream.peekBytes(SCAN_BLOCK_SIZE);
  34409. var scanLength = scanBytes.length - ENDSTREAM_SIGNATURE_LENGTH;
  34410. if (scanLength <= 0) {
  34411. break;
  34412. }
  34413. found = false;
  34414. for (i = 0, j = 0; i < scanLength; i++) {
  34415. var b = scanBytes[i];
  34416. if (b !== ENDSTREAM_SIGNATURE[j]) {
  34417. i -= j;
  34418. j = 0;
  34419. } else {
  34420. j++;
  34421. if (j >= ENDSTREAM_SIGNATURE_LENGTH) {
  34422. i++;
  34423. found = true;
  34424. break;
  34425. }
  34426. }
  34427. }
  34428. if (found) {
  34429. skipped += i - ENDSTREAM_SIGNATURE_LENGTH;
  34430. stream.pos += i - ENDSTREAM_SIGNATURE_LENGTH;
  34431. break;
  34432. }
  34433. skipped += scanLength;
  34434. stream.pos += scanLength;
  34435. }
  34436. if (!found) {
  34437. error('Missing endstream');
  34438. }
  34439. length = skipped;
  34440. lexer.nextChar();
  34441. this.shift();
  34442. this.shift();
  34443. }
  34444. this.shift(); // 'endstream'
  34445. stream = stream.makeSubStream(pos, length, dict);
  34446. if (cipherTransform) {
  34447. stream = cipherTransform.createStream(stream, length);
  34448. }
  34449. stream = this.filter(stream, dict, length);
  34450. stream.dict = dict;
  34451. return stream;
  34452. },
  34453. filter: function Parser_filter(stream, dict, length) {
  34454. var filter = this.fetchIfRef(dict.get('Filter', 'F'));
  34455. var params = this.fetchIfRef(dict.get('DecodeParms', 'DP'));
  34456. if (isName(filter)) {
  34457. return this.makeFilter(stream, filter.name, length, params);
  34458. }
  34459. var maybeLength = length;
  34460. if (isArray(filter)) {
  34461. var filterArray = filter;
  34462. var paramsArray = params;
  34463. for (var i = 0, ii = filterArray.length; i < ii; ++i) {
  34464. filter = filterArray[i];
  34465. if (!isName(filter)) {
  34466. error('Bad filter name: ' + filter);
  34467. }
  34468. params = null;
  34469. if (isArray(paramsArray) && (i in paramsArray)) {
  34470. params = paramsArray[i];
  34471. }
  34472. stream = this.makeFilter(stream, filter.name, maybeLength, params);
  34473. // after the first stream the length variable is invalid
  34474. maybeLength = null;
  34475. }
  34476. }
  34477. return stream;
  34478. },
  34479. makeFilter: function Parser_makeFilter(stream, name, maybeLength, params) {
  34480. if (stream.dict.get('Length') === 0) {
  34481. return new NullStream(stream);
  34482. }
  34483. try {
  34484. if (params) {
  34485. params = this.fetchIfRef(params);
  34486. }
  34487. var xrefStreamStats = this.xref.stats.streamTypes;
  34488. if (name === 'FlateDecode' || name === 'Fl') {
  34489. xrefStreamStats[StreamType.FLATE] = true;
  34490. if (params) {
  34491. return new PredictorStream(new FlateStream(stream, maybeLength),
  34492. maybeLength, params);
  34493. }
  34494. return new FlateStream(stream, maybeLength);
  34495. }
  34496. if (name === 'LZWDecode' || name === 'LZW') {
  34497. xrefStreamStats[StreamType.LZW] = true;
  34498. var earlyChange = 1;
  34499. if (params) {
  34500. if (params.has('EarlyChange')) {
  34501. earlyChange = params.get('EarlyChange');
  34502. }
  34503. return new PredictorStream(
  34504. new LZWStream(stream, maybeLength, earlyChange),
  34505. maybeLength, params);
  34506. }
  34507. return new LZWStream(stream, maybeLength, earlyChange);
  34508. }
  34509. if (name === 'DCTDecode' || name === 'DCT') {
  34510. xrefStreamStats[StreamType.DCT] = true;
  34511. return new JpegStream(stream, maybeLength, stream.dict, this.xref);
  34512. }
  34513. if (name === 'JPXDecode' || name === 'JPX') {
  34514. xrefStreamStats[StreamType.JPX] = true;
  34515. return new JpxStream(stream, maybeLength, stream.dict);
  34516. }
  34517. if (name === 'ASCII85Decode' || name === 'A85') {
  34518. xrefStreamStats[StreamType.A85] = true;
  34519. return new Ascii85Stream(stream, maybeLength);
  34520. }
  34521. if (name === 'ASCIIHexDecode' || name === 'AHx') {
  34522. xrefStreamStats[StreamType.AHX] = true;
  34523. return new AsciiHexStream(stream, maybeLength);
  34524. }
  34525. if (name === 'CCITTFaxDecode' || name === 'CCF') {
  34526. xrefStreamStats[StreamType.CCF] = true;
  34527. return new CCITTFaxStream(stream, maybeLength, params);
  34528. }
  34529. if (name === 'RunLengthDecode' || name === 'RL') {
  34530. xrefStreamStats[StreamType.RL] = true;
  34531. return new RunLengthStream(stream, maybeLength);
  34532. }
  34533. if (name === 'JBIG2Decode') {
  34534. xrefStreamStats[StreamType.JBIG] = true;
  34535. return new Jbig2Stream(stream, maybeLength, stream.dict);
  34536. }
  34537. warn('filter "' + name + '" not supported yet');
  34538. return stream;
  34539. } catch (ex) {
  34540. if (ex instanceof MissingDataException) {
  34541. throw ex;
  34542. }
  34543. warn('Invalid stream: \"' + ex + '\"');
  34544. return new NullStream(stream);
  34545. }
  34546. }
  34547. };
  34548. return Parser;
  34549. })();
  34550. var Lexer = (function LexerClosure() {
  34551. function Lexer(stream, knownCommands) {
  34552. this.stream = stream;
  34553. this.nextChar();
  34554. // While lexing, we build up many strings one char at a time. Using += for
  34555. // this can result in lots of garbage strings. It's better to build an
  34556. // array of single-char strings and then join() them together at the end.
  34557. // And reusing a single array (i.e. |this.strBuf|) over and over for this
  34558. // purpose uses less memory than using a new array for each string.
  34559. this.strBuf = [];
  34560. // The PDFs might have "glued" commands with other commands, operands or
  34561. // literals, e.g. "q1". The knownCommands is a dictionary of the valid
  34562. // commands and their prefixes. The prefixes are built the following way:
  34563. // if there a command that is a prefix of the other valid command or
  34564. // literal (e.g. 'f' and 'false') the following prefixes must be included,
  34565. // 'fa', 'fal', 'fals'. The prefixes are not needed, if the command has no
  34566. // other commands or literals as a prefix. The knowCommands is optional.
  34567. this.knownCommands = knownCommands;
  34568. }
  34569. Lexer.isSpace = function Lexer_isSpace(ch) {
  34570. // Space is one of the following characters: SPACE, TAB, CR or LF.
  34571. return (ch === 0x20 || ch === 0x09 || ch === 0x0D || ch === 0x0A);
  34572. };
  34573. // A '1' in this array means the character is white space. A '1' or
  34574. // '2' means the character ends a name or command.
  34575. var specialChars = [
  34576. 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, // 0x
  34577. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 1x
  34578. 1, 0, 0, 0, 0, 2, 0, 0, 2, 2, 0, 0, 0, 0, 0, 2, // 2x
  34579. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, // 3x
  34580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 4x
  34581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 5x
  34582. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 6x
  34583. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 7x
  34584. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 8x
  34585. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 9x
  34586. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ax
  34587. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // bx
  34588. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // cx
  34589. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // dx
  34590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ex
  34591. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 // fx
  34592. ];
  34593. function toHexDigit(ch) {
  34594. if (ch >= 0x30 && ch <= 0x39) { // '0'-'9'
  34595. return ch & 0x0F;
  34596. }
  34597. if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
  34598. // 'A'-'F', 'a'-'f'
  34599. return (ch & 0x0F) + 9;
  34600. }
  34601. return -1;
  34602. }
  34603. Lexer.prototype = {
  34604. nextChar: function Lexer_nextChar() {
  34605. return (this.currentChar = this.stream.getByte());
  34606. },
  34607. peekChar: function Lexer_peekChar() {
  34608. return this.stream.peekByte();
  34609. },
  34610. getNumber: function Lexer_getNumber() {
  34611. var ch = this.currentChar;
  34612. var eNotation = false;
  34613. var divideBy = 0; // different from 0 if it's a floating point value
  34614. var sign = 1;
  34615. if (ch === 0x2D) { // '-'
  34616. sign = -1;
  34617. ch = this.nextChar();
  34618. } else if (ch === 0x2B) { // '+'
  34619. ch = this.nextChar();
  34620. }
  34621. if (ch === 0x2E) { // '.'
  34622. divideBy = 10;
  34623. ch = this.nextChar();
  34624. }
  34625. if (ch < 0x30 || ch > 0x39) { // '0' - '9'
  34626. error('Invalid number: ' + String.fromCharCode(ch));
  34627. return 0;
  34628. }
  34629. var baseValue = ch - 0x30; // '0'
  34630. var powerValue = 0;
  34631. var powerValueSign = 1;
  34632. while ((ch = this.nextChar()) >= 0) {
  34633. if (0x30 <= ch && ch <= 0x39) { // '0' - '9'
  34634. var currentDigit = ch - 0x30; // '0'
  34635. if (eNotation) { // We are after an 'e' or 'E'
  34636. powerValue = powerValue * 10 + currentDigit;
  34637. } else {
  34638. if (divideBy !== 0) { // We are after a point
  34639. divideBy *= 10;
  34640. }
  34641. baseValue = baseValue * 10 + currentDigit;
  34642. }
  34643. } else if (ch === 0x2E) { // '.'
  34644. if (divideBy === 0) {
  34645. divideBy = 1;
  34646. } else {
  34647. // A number can have only one '.'
  34648. break;
  34649. }
  34650. } else if (ch === 0x2D) { // '-'
  34651. // ignore minus signs in the middle of numbers to match
  34652. // Adobe's behavior
  34653. warn('Badly formated number');
  34654. } else if (ch === 0x45 || ch === 0x65) { // 'E', 'e'
  34655. // 'E' can be either a scientific notation or the beginning of a new
  34656. // operator
  34657. ch = this.peekChar();
  34658. if (ch === 0x2B || ch === 0x2D) { // '+', '-'
  34659. powerValueSign = (ch === 0x2D) ? -1 : 1;
  34660. this.nextChar(); // Consume the sign character
  34661. } else if (ch < 0x30 || ch > 0x39) { // '0' - '9'
  34662. // The 'E' must be the beginning of a new operator
  34663. break;
  34664. }
  34665. eNotation = true;
  34666. } else {
  34667. // the last character doesn't belong to us
  34668. break;
  34669. }
  34670. }
  34671. if (divideBy !== 0) {
  34672. baseValue /= divideBy;
  34673. }
  34674. if (eNotation) {
  34675. baseValue *= Math.pow(10, powerValueSign * powerValue);
  34676. }
  34677. return sign * baseValue;
  34678. },
  34679. getString: function Lexer_getString() {
  34680. var numParen = 1;
  34681. var done = false;
  34682. var strBuf = this.strBuf;
  34683. strBuf.length = 0;
  34684. var ch = this.nextChar();
  34685. while (true) {
  34686. var charBuffered = false;
  34687. switch (ch | 0) {
  34688. case -1:
  34689. warn('Unterminated string');
  34690. done = true;
  34691. break;
  34692. case 0x28: // '('
  34693. ++numParen;
  34694. strBuf.push('(');
  34695. break;
  34696. case 0x29: // ')'
  34697. if (--numParen === 0) {
  34698. this.nextChar(); // consume strings ')'
  34699. done = true;
  34700. } else {
  34701. strBuf.push(')');
  34702. }
  34703. break;
  34704. case 0x5C: // '\\'
  34705. ch = this.nextChar();
  34706. switch (ch) {
  34707. case -1:
  34708. warn('Unterminated string');
  34709. done = true;
  34710. break;
  34711. case 0x6E: // 'n'
  34712. strBuf.push('\n');
  34713. break;
  34714. case 0x72: // 'r'
  34715. strBuf.push('\r');
  34716. break;
  34717. case 0x74: // 't'
  34718. strBuf.push('\t');
  34719. break;
  34720. case 0x62: // 'b'
  34721. strBuf.push('\b');
  34722. break;
  34723. case 0x66: // 'f'
  34724. strBuf.push('\f');
  34725. break;
  34726. case 0x5C: // '\'
  34727. case 0x28: // '('
  34728. case 0x29: // ')'
  34729. strBuf.push(String.fromCharCode(ch));
  34730. break;
  34731. case 0x30: case 0x31: case 0x32: case 0x33: // '0'-'3'
  34732. case 0x34: case 0x35: case 0x36: case 0x37: // '4'-'7'
  34733. var x = ch & 0x0F;
  34734. ch = this.nextChar();
  34735. charBuffered = true;
  34736. if (ch >= 0x30 && ch <= 0x37) { // '0'-'7'
  34737. x = (x << 3) + (ch & 0x0F);
  34738. ch = this.nextChar();
  34739. if (ch >= 0x30 && ch <= 0x37) { // '0'-'7'
  34740. charBuffered = false;
  34741. x = (x << 3) + (ch & 0x0F);
  34742. }
  34743. }
  34744. strBuf.push(String.fromCharCode(x));
  34745. break;
  34746. case 0x0D: // CR
  34747. if (this.peekChar() === 0x0A) { // LF
  34748. this.nextChar();
  34749. }
  34750. break;
  34751. case 0x0A: // LF
  34752. break;
  34753. default:
  34754. strBuf.push(String.fromCharCode(ch));
  34755. break;
  34756. }
  34757. break;
  34758. default:
  34759. strBuf.push(String.fromCharCode(ch));
  34760. break;
  34761. }
  34762. if (done) {
  34763. break;
  34764. }
  34765. if (!charBuffered) {
  34766. ch = this.nextChar();
  34767. }
  34768. }
  34769. return strBuf.join('');
  34770. },
  34771. getName: function Lexer_getName() {
  34772. var ch;
  34773. var strBuf = this.strBuf;
  34774. strBuf.length = 0;
  34775. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  34776. if (ch === 0x23) { // '#'
  34777. ch = this.nextChar();
  34778. var x = toHexDigit(ch);
  34779. if (x !== -1) {
  34780. var x2 = toHexDigit(this.nextChar());
  34781. if (x2 === -1) {
  34782. error('Illegal digit in hex char in name: ' + x2);
  34783. }
  34784. strBuf.push(String.fromCharCode((x << 4) | x2));
  34785. } else {
  34786. strBuf.push('#', String.fromCharCode(ch));
  34787. }
  34788. } else {
  34789. strBuf.push(String.fromCharCode(ch));
  34790. }
  34791. }
  34792. if (strBuf.length > 128) {
  34793. error('Warning: name token is longer than allowed by the spec: ' +
  34794. strBuf.length);
  34795. }
  34796. return Name.get(strBuf.join(''));
  34797. },
  34798. getHexString: function Lexer_getHexString() {
  34799. var strBuf = this.strBuf;
  34800. strBuf.length = 0;
  34801. var ch = this.currentChar;
  34802. var isFirstHex = true;
  34803. var firstDigit;
  34804. var secondDigit;
  34805. while (true) {
  34806. if (ch < 0) {
  34807. warn('Unterminated hex string');
  34808. break;
  34809. } else if (ch === 0x3E) { // '>'
  34810. this.nextChar();
  34811. break;
  34812. } else if (specialChars[ch] === 1) {
  34813. ch = this.nextChar();
  34814. continue;
  34815. } else {
  34816. if (isFirstHex) {
  34817. firstDigit = toHexDigit(ch);
  34818. if (firstDigit === -1) {
  34819. warn('Ignoring invalid character "' + ch + '" in hex string');
  34820. ch = this.nextChar();
  34821. continue;
  34822. }
  34823. } else {
  34824. secondDigit = toHexDigit(ch);
  34825. if (secondDigit === -1) {
  34826. warn('Ignoring invalid character "' + ch + '" in hex string');
  34827. ch = this.nextChar();
  34828. continue;
  34829. }
  34830. strBuf.push(String.fromCharCode((firstDigit << 4) | secondDigit));
  34831. }
  34832. isFirstHex = !isFirstHex;
  34833. ch = this.nextChar();
  34834. }
  34835. }
  34836. return strBuf.join('');
  34837. },
  34838. getObj: function Lexer_getObj() {
  34839. // skip whitespace and comments
  34840. var comment = false;
  34841. var ch = this.currentChar;
  34842. while (true) {
  34843. if (ch < 0) {
  34844. return EOF;
  34845. }
  34846. if (comment) {
  34847. if (ch === 0x0A || ch === 0x0D) { // LF, CR
  34848. comment = false;
  34849. }
  34850. } else if (ch === 0x25) { // '%'
  34851. comment = true;
  34852. } else if (specialChars[ch] !== 1) {
  34853. break;
  34854. }
  34855. ch = this.nextChar();
  34856. }
  34857. // start reading token
  34858. switch (ch | 0) {
  34859. case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: // '0'-'4'
  34860. case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: // '5'-'9'
  34861. case 0x2B: case 0x2D: case 0x2E: // '+', '-', '.'
  34862. return this.getNumber();
  34863. case 0x28: // '('
  34864. return this.getString();
  34865. case 0x2F: // '/'
  34866. return this.getName();
  34867. // array punctuation
  34868. case 0x5B: // '['
  34869. this.nextChar();
  34870. return Cmd.get('[');
  34871. case 0x5D: // ']'
  34872. this.nextChar();
  34873. return Cmd.get(']');
  34874. // hex string or dict punctuation
  34875. case 0x3C: // '<'
  34876. ch = this.nextChar();
  34877. if (ch === 0x3C) {
  34878. // dict punctuation
  34879. this.nextChar();
  34880. return Cmd.get('<<');
  34881. }
  34882. return this.getHexString();
  34883. // dict punctuation
  34884. case 0x3E: // '>'
  34885. ch = this.nextChar();
  34886. if (ch === 0x3E) {
  34887. this.nextChar();
  34888. return Cmd.get('>>');
  34889. }
  34890. return Cmd.get('>');
  34891. case 0x7B: // '{'
  34892. this.nextChar();
  34893. return Cmd.get('{');
  34894. case 0x7D: // '}'
  34895. this.nextChar();
  34896. return Cmd.get('}');
  34897. case 0x29: // ')'
  34898. error('Illegal character: ' + ch);
  34899. break;
  34900. }
  34901. // command
  34902. var str = String.fromCharCode(ch);
  34903. var knownCommands = this.knownCommands;
  34904. var knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  34905. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  34906. // stop if known command is found and next character does not make
  34907. // the str a command
  34908. var possibleCommand = str + String.fromCharCode(ch);
  34909. if (knownCommandFound && knownCommands[possibleCommand] === undefined) {
  34910. break;
  34911. }
  34912. if (str.length === 128) {
  34913. error('Command token too long: ' + str.length);
  34914. }
  34915. str = possibleCommand;
  34916. knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  34917. }
  34918. if (str === 'true') {
  34919. return true;
  34920. }
  34921. if (str === 'false') {
  34922. return false;
  34923. }
  34924. if (str === 'null') {
  34925. return null;
  34926. }
  34927. return Cmd.get(str);
  34928. },
  34929. skipToNextLine: function Lexer_skipToNextLine() {
  34930. var ch = this.currentChar;
  34931. while (ch >= 0) {
  34932. if (ch === 0x0D) { // CR
  34933. ch = this.nextChar();
  34934. if (ch === 0x0A) { // LF
  34935. this.nextChar();
  34936. }
  34937. break;
  34938. } else if (ch === 0x0A) { // LF
  34939. this.nextChar();
  34940. break;
  34941. }
  34942. ch = this.nextChar();
  34943. }
  34944. }
  34945. };
  34946. return Lexer;
  34947. })();
  34948. var Linearization = {
  34949. create: function LinearizationCreate(stream) {
  34950. function getInt(name, allowZeroValue) {
  34951. var obj = linDict.get(name);
  34952. if (isInt(obj) && (allowZeroValue ? obj >= 0 : obj > 0)) {
  34953. return obj;
  34954. }
  34955. throw new Error('The "' + name + '" parameter in the linearization ' +
  34956. 'dictionary is invalid.');
  34957. }
  34958. function getHints() {
  34959. var hints = linDict.get('H'), hintsLength, item;
  34960. if (isArray(hints) &&
  34961. ((hintsLength = hints.length) === 2 || hintsLength === 4)) {
  34962. for (var index = 0; index < hintsLength; index++) {
  34963. if (!(isInt(item = hints[index]) && item > 0)) {
  34964. throw new Error('Hint (' + index +
  34965. ') in the linearization dictionary is invalid.');
  34966. }
  34967. }
  34968. return hints;
  34969. }
  34970. throw new Error('Hint array in the linearization dictionary is invalid.');
  34971. }
  34972. var parser = new Parser(new Lexer(stream), false, null);
  34973. var obj1 = parser.getObj();
  34974. var obj2 = parser.getObj();
  34975. var obj3 = parser.getObj();
  34976. var linDict = parser.getObj();
  34977. var obj, length;
  34978. if (!(isInt(obj1) && isInt(obj2) && isCmd(obj3, 'obj') && isDict(linDict) &&
  34979. isNum(obj = linDict.get('Linearized')) && obj > 0)) {
  34980. return null; // No valid linearization dictionary found.
  34981. } else if ((length = getInt('L')) !== stream.length) {
  34982. throw new Error('The "L" parameter in the linearization dictionary ' +
  34983. 'does not equal the stream length.');
  34984. }
  34985. return {
  34986. length: length,
  34987. hints: getHints(),
  34988. objectNumberFirst: getInt('O'),
  34989. endFirst: getInt('E'),
  34990. numPages: getInt('N'),
  34991. mainXRefEntriesOffset: getInt('T'),
  34992. pageFirst: (linDict.has('P') ? getInt('P', true) : 0)
  34993. };
  34994. }
  34995. };
  34996. var PostScriptParser = (function PostScriptParserClosure() {
  34997. function PostScriptParser(lexer) {
  34998. this.lexer = lexer;
  34999. this.operators = [];
  35000. this.token = null;
  35001. this.prev = null;
  35002. }
  35003. PostScriptParser.prototype = {
  35004. nextToken: function PostScriptParser_nextToken() {
  35005. this.prev = this.token;
  35006. this.token = this.lexer.getToken();
  35007. },
  35008. accept: function PostScriptParser_accept(type) {
  35009. if (this.token.type === type) {
  35010. this.nextToken();
  35011. return true;
  35012. }
  35013. return false;
  35014. },
  35015. expect: function PostScriptParser_expect(type) {
  35016. if (this.accept(type)) {
  35017. return true;
  35018. }
  35019. error('Unexpected symbol: found ' + this.token.type + ' expected ' +
  35020. type + '.');
  35021. },
  35022. parse: function PostScriptParser_parse() {
  35023. this.nextToken();
  35024. this.expect(PostScriptTokenTypes.LBRACE);
  35025. this.parseBlock();
  35026. this.expect(PostScriptTokenTypes.RBRACE);
  35027. return this.operators;
  35028. },
  35029. parseBlock: function PostScriptParser_parseBlock() {
  35030. while (true) {
  35031. if (this.accept(PostScriptTokenTypes.NUMBER)) {
  35032. this.operators.push(this.prev.value);
  35033. } else if (this.accept(PostScriptTokenTypes.OPERATOR)) {
  35034. this.operators.push(this.prev.value);
  35035. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  35036. this.parseCondition();
  35037. } else {
  35038. return;
  35039. }
  35040. }
  35041. },
  35042. parseCondition: function PostScriptParser_parseCondition() {
  35043. // Add two place holders that will be updated later
  35044. var conditionLocation = this.operators.length;
  35045. this.operators.push(null, null);
  35046. this.parseBlock();
  35047. this.expect(PostScriptTokenTypes.RBRACE);
  35048. if (this.accept(PostScriptTokenTypes.IF)) {
  35049. // The true block is right after the 'if' so it just falls through on
  35050. // true else it jumps and skips the true block.
  35051. this.operators[conditionLocation] = this.operators.length;
  35052. this.operators[conditionLocation + 1] = 'jz';
  35053. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  35054. var jumpLocation = this.operators.length;
  35055. this.operators.push(null, null);
  35056. var endOfTrue = this.operators.length;
  35057. this.parseBlock();
  35058. this.expect(PostScriptTokenTypes.RBRACE);
  35059. this.expect(PostScriptTokenTypes.IFELSE);
  35060. // The jump is added at the end of the true block to skip the false
  35061. // block.
  35062. this.operators[jumpLocation] = this.operators.length;
  35063. this.operators[jumpLocation + 1] = 'j';
  35064. this.operators[conditionLocation] = endOfTrue;
  35065. this.operators[conditionLocation + 1] = 'jz';
  35066. } else {
  35067. error('PS Function: error parsing conditional.');
  35068. }
  35069. }
  35070. };
  35071. return PostScriptParser;
  35072. })();
  35073. var PostScriptTokenTypes = {
  35074. LBRACE: 0,
  35075. RBRACE: 1,
  35076. NUMBER: 2,
  35077. OPERATOR: 3,
  35078. IF: 4,
  35079. IFELSE: 5
  35080. };
  35081. var PostScriptToken = (function PostScriptTokenClosure() {
  35082. function PostScriptToken(type, value) {
  35083. this.type = type;
  35084. this.value = value;
  35085. }
  35086. var opCache = {};
  35087. PostScriptToken.getOperator = function PostScriptToken_getOperator(op) {
  35088. var opValue = opCache[op];
  35089. if (opValue) {
  35090. return opValue;
  35091. }
  35092. return opCache[op] = new PostScriptToken(PostScriptTokenTypes.OPERATOR, op);
  35093. };
  35094. PostScriptToken.LBRACE = new PostScriptToken(PostScriptTokenTypes.LBRACE,
  35095. '{');
  35096. PostScriptToken.RBRACE = new PostScriptToken(PostScriptTokenTypes.RBRACE,
  35097. '}');
  35098. PostScriptToken.IF = new PostScriptToken(PostScriptTokenTypes.IF, 'IF');
  35099. PostScriptToken.IFELSE = new PostScriptToken(PostScriptTokenTypes.IFELSE,
  35100. 'IFELSE');
  35101. return PostScriptToken;
  35102. })();
  35103. var PostScriptLexer = (function PostScriptLexerClosure() {
  35104. function PostScriptLexer(stream) {
  35105. this.stream = stream;
  35106. this.nextChar();
  35107. this.strBuf = [];
  35108. }
  35109. PostScriptLexer.prototype = {
  35110. nextChar: function PostScriptLexer_nextChar() {
  35111. return (this.currentChar = this.stream.getByte());
  35112. },
  35113. getToken: function PostScriptLexer_getToken() {
  35114. var comment = false;
  35115. var ch = this.currentChar;
  35116. // skip comments
  35117. while (true) {
  35118. if (ch < 0) {
  35119. return EOF;
  35120. }
  35121. if (comment) {
  35122. if (ch === 0x0A || ch === 0x0D) {
  35123. comment = false;
  35124. }
  35125. } else if (ch === 0x25) { // '%'
  35126. comment = true;
  35127. } else if (!Lexer.isSpace(ch)) {
  35128. break;
  35129. }
  35130. ch = this.nextChar();
  35131. }
  35132. switch (ch | 0) {
  35133. case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: // '0'-'4'
  35134. case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: // '5'-'9'
  35135. case 0x2B: case 0x2D: case 0x2E: // '+', '-', '.'
  35136. return new PostScriptToken(PostScriptTokenTypes.NUMBER,
  35137. this.getNumber());
  35138. case 0x7B: // '{'
  35139. this.nextChar();
  35140. return PostScriptToken.LBRACE;
  35141. case 0x7D: // '}'
  35142. this.nextChar();
  35143. return PostScriptToken.RBRACE;
  35144. }
  35145. // operator
  35146. var strBuf = this.strBuf;
  35147. strBuf.length = 0;
  35148. strBuf[0] = String.fromCharCode(ch);
  35149. while ((ch = this.nextChar()) >= 0 && // and 'A'-'Z', 'a'-'z'
  35150. ((ch >= 0x41 && ch <= 0x5A) || (ch >= 0x61 && ch <= 0x7A))) {
  35151. strBuf.push(String.fromCharCode(ch));
  35152. }
  35153. var str = strBuf.join('');
  35154. switch (str.toLowerCase()) {
  35155. case 'if':
  35156. return PostScriptToken.IF;
  35157. case 'ifelse':
  35158. return PostScriptToken.IFELSE;
  35159. default:
  35160. return PostScriptToken.getOperator(str);
  35161. }
  35162. },
  35163. getNumber: function PostScriptLexer_getNumber() {
  35164. var ch = this.currentChar;
  35165. var strBuf = this.strBuf;
  35166. strBuf.length = 0;
  35167. strBuf[0] = String.fromCharCode(ch);
  35168. while ((ch = this.nextChar()) >= 0) {
  35169. if ((ch >= 0x30 && ch <= 0x39) || // '0'-'9'
  35170. ch === 0x2D || ch === 0x2E) { // '-', '.'
  35171. strBuf.push(String.fromCharCode(ch));
  35172. } else {
  35173. break;
  35174. }
  35175. }
  35176. var value = parseFloat(strBuf.join(''));
  35177. if (isNaN(value)) {
  35178. error('Invalid floating point number: ' + value);
  35179. }
  35180. return value;
  35181. }
  35182. };
  35183. return PostScriptLexer;
  35184. })();
  35185. var Stream = (function StreamClosure() {
  35186. function Stream(arrayBuffer, start, length, dict) {
  35187. this.bytes = (arrayBuffer instanceof Uint8Array ?
  35188. arrayBuffer : new Uint8Array(arrayBuffer));
  35189. this.start = start || 0;
  35190. this.pos = this.start;
  35191. this.end = (start + length) || this.bytes.length;
  35192. this.dict = dict;
  35193. }
  35194. // required methods for a stream. if a particular stream does not
  35195. // implement these, an error should be thrown
  35196. Stream.prototype = {
  35197. get length() {
  35198. return this.end - this.start;
  35199. },
  35200. get isEmpty() {
  35201. return this.length === 0;
  35202. },
  35203. getByte: function Stream_getByte() {
  35204. if (this.pos >= this.end) {
  35205. return -1;
  35206. }
  35207. return this.bytes[this.pos++];
  35208. },
  35209. getUint16: function Stream_getUint16() {
  35210. var b0 = this.getByte();
  35211. var b1 = this.getByte();
  35212. if (b0 === -1 || b1 === -1) {
  35213. return -1;
  35214. }
  35215. return (b0 << 8) + b1;
  35216. },
  35217. getInt32: function Stream_getInt32() {
  35218. var b0 = this.getByte();
  35219. var b1 = this.getByte();
  35220. var b2 = this.getByte();
  35221. var b3 = this.getByte();
  35222. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  35223. },
  35224. // returns subarray of original buffer
  35225. // should only be read
  35226. getBytes: function Stream_getBytes(length) {
  35227. var bytes = this.bytes;
  35228. var pos = this.pos;
  35229. var strEnd = this.end;
  35230. if (!length) {
  35231. return bytes.subarray(pos, strEnd);
  35232. }
  35233. var end = pos + length;
  35234. if (end > strEnd) {
  35235. end = strEnd;
  35236. }
  35237. this.pos = end;
  35238. return bytes.subarray(pos, end);
  35239. },
  35240. peekByte: function Stream_peekByte() {
  35241. var peekedByte = this.getByte();
  35242. this.pos--;
  35243. return peekedByte;
  35244. },
  35245. peekBytes: function Stream_peekBytes(length) {
  35246. var bytes = this.getBytes(length);
  35247. this.pos -= bytes.length;
  35248. return bytes;
  35249. },
  35250. skip: function Stream_skip(n) {
  35251. if (!n) {
  35252. n = 1;
  35253. }
  35254. this.pos += n;
  35255. },
  35256. reset: function Stream_reset() {
  35257. this.pos = this.start;
  35258. },
  35259. moveStart: function Stream_moveStart() {
  35260. this.start = this.pos;
  35261. },
  35262. makeSubStream: function Stream_makeSubStream(start, length, dict) {
  35263. return new Stream(this.bytes.buffer, start, length, dict);
  35264. },
  35265. isStream: true
  35266. };
  35267. return Stream;
  35268. })();
  35269. var StringStream = (function StringStreamClosure() {
  35270. function StringStream(str) {
  35271. var length = str.length;
  35272. var bytes = new Uint8Array(length);
  35273. for (var n = 0; n < length; ++n) {
  35274. bytes[n] = str.charCodeAt(n);
  35275. }
  35276. Stream.call(this, bytes);
  35277. }
  35278. StringStream.prototype = Stream.prototype;
  35279. return StringStream;
  35280. })();
  35281. // super class for the decoding streams
  35282. var DecodeStream = (function DecodeStreamClosure() {
  35283. // Lots of DecodeStreams are created whose buffers are never used. For these
  35284. // we share a single empty buffer. This is (a) space-efficient and (b) avoids
  35285. // having special cases that would be required if we used |null| for an empty
  35286. // buffer.
  35287. var emptyBuffer = new Uint8Array(0);
  35288. function DecodeStream(maybeMinBufferLength) {
  35289. this.pos = 0;
  35290. this.bufferLength = 0;
  35291. this.eof = false;
  35292. this.buffer = emptyBuffer;
  35293. this.minBufferLength = 512;
  35294. if (maybeMinBufferLength) {
  35295. // Compute the first power of two that is as big as maybeMinBufferLength.
  35296. while (this.minBufferLength < maybeMinBufferLength) {
  35297. this.minBufferLength *= 2;
  35298. }
  35299. }
  35300. }
  35301. DecodeStream.prototype = {
  35302. get isEmpty() {
  35303. while (!this.eof && this.bufferLength === 0) {
  35304. this.readBlock();
  35305. }
  35306. return this.bufferLength === 0;
  35307. },
  35308. ensureBuffer: function DecodeStream_ensureBuffer(requested) {
  35309. var buffer = this.buffer;
  35310. if (requested <= buffer.byteLength) {
  35311. return buffer;
  35312. }
  35313. var size = this.minBufferLength;
  35314. while (size < requested) {
  35315. size *= 2;
  35316. }
  35317. var buffer2 = new Uint8Array(size);
  35318. buffer2.set(buffer);
  35319. return (this.buffer = buffer2);
  35320. },
  35321. getByte: function DecodeStream_getByte() {
  35322. var pos = this.pos;
  35323. while (this.bufferLength <= pos) {
  35324. if (this.eof) {
  35325. return -1;
  35326. }
  35327. this.readBlock();
  35328. }
  35329. return this.buffer[this.pos++];
  35330. },
  35331. getUint16: function DecodeStream_getUint16() {
  35332. var b0 = this.getByte();
  35333. var b1 = this.getByte();
  35334. if (b0 === -1 || b1 === -1) {
  35335. return -1;
  35336. }
  35337. return (b0 << 8) + b1;
  35338. },
  35339. getInt32: function DecodeStream_getInt32() {
  35340. var b0 = this.getByte();
  35341. var b1 = this.getByte();
  35342. var b2 = this.getByte();
  35343. var b3 = this.getByte();
  35344. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  35345. },
  35346. getBytes: function DecodeStream_getBytes(length) {
  35347. var end, pos = this.pos;
  35348. if (length) {
  35349. this.ensureBuffer(pos + length);
  35350. end = pos + length;
  35351. while (!this.eof && this.bufferLength < end) {
  35352. this.readBlock();
  35353. }
  35354. var bufEnd = this.bufferLength;
  35355. if (end > bufEnd) {
  35356. end = bufEnd;
  35357. }
  35358. } else {
  35359. while (!this.eof) {
  35360. this.readBlock();
  35361. }
  35362. end = this.bufferLength;
  35363. }
  35364. this.pos = end;
  35365. return this.buffer.subarray(pos, end);
  35366. },
  35367. peekByte: function DecodeStream_peekByte() {
  35368. var peekedByte = this.getByte();
  35369. this.pos--;
  35370. return peekedByte;
  35371. },
  35372. peekBytes: function DecodeStream_peekBytes(length) {
  35373. var bytes = this.getBytes(length);
  35374. this.pos -= bytes.length;
  35375. return bytes;
  35376. },
  35377. makeSubStream: function DecodeStream_makeSubStream(start, length, dict) {
  35378. var end = start + length;
  35379. while (this.bufferLength <= end && !this.eof) {
  35380. this.readBlock();
  35381. }
  35382. return new Stream(this.buffer, start, length, dict);
  35383. },
  35384. skip: function DecodeStream_skip(n) {
  35385. if (!n) {
  35386. n = 1;
  35387. }
  35388. this.pos += n;
  35389. },
  35390. reset: function DecodeStream_reset() {
  35391. this.pos = 0;
  35392. },
  35393. getBaseStreams: function DecodeStream_getBaseStreams() {
  35394. if (this.str && this.str.getBaseStreams) {
  35395. return this.str.getBaseStreams();
  35396. }
  35397. return [];
  35398. }
  35399. };
  35400. return DecodeStream;
  35401. })();
  35402. var StreamsSequenceStream = (function StreamsSequenceStreamClosure() {
  35403. function StreamsSequenceStream(streams) {
  35404. this.streams = streams;
  35405. DecodeStream.call(this, /* maybeLength = */ null);
  35406. }
  35407. StreamsSequenceStream.prototype = Object.create(DecodeStream.prototype);
  35408. StreamsSequenceStream.prototype.readBlock =
  35409. function streamSequenceStreamReadBlock() {
  35410. var streams = this.streams;
  35411. if (streams.length === 0) {
  35412. this.eof = true;
  35413. return;
  35414. }
  35415. var stream = streams.shift();
  35416. var chunk = stream.getBytes();
  35417. var bufferLength = this.bufferLength;
  35418. var newLength = bufferLength + chunk.length;
  35419. var buffer = this.ensureBuffer(newLength);
  35420. buffer.set(chunk, bufferLength);
  35421. this.bufferLength = newLength;
  35422. };
  35423. StreamsSequenceStream.prototype.getBaseStreams =
  35424. function StreamsSequenceStream_getBaseStreams() {
  35425. var baseStreams = [];
  35426. for (var i = 0, ii = this.streams.length; i < ii; i++) {
  35427. var stream = this.streams[i];
  35428. if (stream.getBaseStreams) {
  35429. Util.appendToArray(baseStreams, stream.getBaseStreams());
  35430. }
  35431. }
  35432. return baseStreams;
  35433. };
  35434. return StreamsSequenceStream;
  35435. })();
  35436. var FlateStream = (function FlateStreamClosure() {
  35437. var codeLenCodeMap = new Int32Array([
  35438. 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15
  35439. ]);
  35440. var lengthDecode = new Int32Array([
  35441. 0x00003, 0x00004, 0x00005, 0x00006, 0x00007, 0x00008, 0x00009, 0x0000a,
  35442. 0x1000b, 0x1000d, 0x1000f, 0x10011, 0x20013, 0x20017, 0x2001b, 0x2001f,
  35443. 0x30023, 0x3002b, 0x30033, 0x3003b, 0x40043, 0x40053, 0x40063, 0x40073,
  35444. 0x50083, 0x500a3, 0x500c3, 0x500e3, 0x00102, 0x00102, 0x00102
  35445. ]);
  35446. var distDecode = new Int32Array([
  35447. 0x00001, 0x00002, 0x00003, 0x00004, 0x10005, 0x10007, 0x20009, 0x2000d,
  35448. 0x30011, 0x30019, 0x40021, 0x40031, 0x50041, 0x50061, 0x60081, 0x600c1,
  35449. 0x70101, 0x70181, 0x80201, 0x80301, 0x90401, 0x90601, 0xa0801, 0xa0c01,
  35450. 0xb1001, 0xb1801, 0xc2001, 0xc3001, 0xd4001, 0xd6001
  35451. ]);
  35452. var fixedLitCodeTab = [new Int32Array([
  35453. 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c0,
  35454. 0x70108, 0x80060, 0x80020, 0x900a0, 0x80000, 0x80080, 0x80040, 0x900e0,
  35455. 0x70104, 0x80058, 0x80018, 0x90090, 0x70114, 0x80078, 0x80038, 0x900d0,
  35456. 0x7010c, 0x80068, 0x80028, 0x900b0, 0x80008, 0x80088, 0x80048, 0x900f0,
  35457. 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c8,
  35458. 0x7010a, 0x80064, 0x80024, 0x900a8, 0x80004, 0x80084, 0x80044, 0x900e8,
  35459. 0x70106, 0x8005c, 0x8001c, 0x90098, 0x70116, 0x8007c, 0x8003c, 0x900d8,
  35460. 0x7010e, 0x8006c, 0x8002c, 0x900b8, 0x8000c, 0x8008c, 0x8004c, 0x900f8,
  35461. 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c4,
  35462. 0x70109, 0x80062, 0x80022, 0x900a4, 0x80002, 0x80082, 0x80042, 0x900e4,
  35463. 0x70105, 0x8005a, 0x8001a, 0x90094, 0x70115, 0x8007a, 0x8003a, 0x900d4,
  35464. 0x7010d, 0x8006a, 0x8002a, 0x900b4, 0x8000a, 0x8008a, 0x8004a, 0x900f4,
  35465. 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cc,
  35466. 0x7010b, 0x80066, 0x80026, 0x900ac, 0x80006, 0x80086, 0x80046, 0x900ec,
  35467. 0x70107, 0x8005e, 0x8001e, 0x9009c, 0x70117, 0x8007e, 0x8003e, 0x900dc,
  35468. 0x7010f, 0x8006e, 0x8002e, 0x900bc, 0x8000e, 0x8008e, 0x8004e, 0x900fc,
  35469. 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c2,
  35470. 0x70108, 0x80061, 0x80021, 0x900a2, 0x80001, 0x80081, 0x80041, 0x900e2,
  35471. 0x70104, 0x80059, 0x80019, 0x90092, 0x70114, 0x80079, 0x80039, 0x900d2,
  35472. 0x7010c, 0x80069, 0x80029, 0x900b2, 0x80009, 0x80089, 0x80049, 0x900f2,
  35473. 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900ca,
  35474. 0x7010a, 0x80065, 0x80025, 0x900aa, 0x80005, 0x80085, 0x80045, 0x900ea,
  35475. 0x70106, 0x8005d, 0x8001d, 0x9009a, 0x70116, 0x8007d, 0x8003d, 0x900da,
  35476. 0x7010e, 0x8006d, 0x8002d, 0x900ba, 0x8000d, 0x8008d, 0x8004d, 0x900fa,
  35477. 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c6,
  35478. 0x70109, 0x80063, 0x80023, 0x900a6, 0x80003, 0x80083, 0x80043, 0x900e6,
  35479. 0x70105, 0x8005b, 0x8001b, 0x90096, 0x70115, 0x8007b, 0x8003b, 0x900d6,
  35480. 0x7010d, 0x8006b, 0x8002b, 0x900b6, 0x8000b, 0x8008b, 0x8004b, 0x900f6,
  35481. 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900ce,
  35482. 0x7010b, 0x80067, 0x80027, 0x900ae, 0x80007, 0x80087, 0x80047, 0x900ee,
  35483. 0x70107, 0x8005f, 0x8001f, 0x9009e, 0x70117, 0x8007f, 0x8003f, 0x900de,
  35484. 0x7010f, 0x8006f, 0x8002f, 0x900be, 0x8000f, 0x8008f, 0x8004f, 0x900fe,
  35485. 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c1,
  35486. 0x70108, 0x80060, 0x80020, 0x900a1, 0x80000, 0x80080, 0x80040, 0x900e1,
  35487. 0x70104, 0x80058, 0x80018, 0x90091, 0x70114, 0x80078, 0x80038, 0x900d1,
  35488. 0x7010c, 0x80068, 0x80028, 0x900b1, 0x80008, 0x80088, 0x80048, 0x900f1,
  35489. 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c9,
  35490. 0x7010a, 0x80064, 0x80024, 0x900a9, 0x80004, 0x80084, 0x80044, 0x900e9,
  35491. 0x70106, 0x8005c, 0x8001c, 0x90099, 0x70116, 0x8007c, 0x8003c, 0x900d9,
  35492. 0x7010e, 0x8006c, 0x8002c, 0x900b9, 0x8000c, 0x8008c, 0x8004c, 0x900f9,
  35493. 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c5,
  35494. 0x70109, 0x80062, 0x80022, 0x900a5, 0x80002, 0x80082, 0x80042, 0x900e5,
  35495. 0x70105, 0x8005a, 0x8001a, 0x90095, 0x70115, 0x8007a, 0x8003a, 0x900d5,
  35496. 0x7010d, 0x8006a, 0x8002a, 0x900b5, 0x8000a, 0x8008a, 0x8004a, 0x900f5,
  35497. 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cd,
  35498. 0x7010b, 0x80066, 0x80026, 0x900ad, 0x80006, 0x80086, 0x80046, 0x900ed,
  35499. 0x70107, 0x8005e, 0x8001e, 0x9009d, 0x70117, 0x8007e, 0x8003e, 0x900dd,
  35500. 0x7010f, 0x8006e, 0x8002e, 0x900bd, 0x8000e, 0x8008e, 0x8004e, 0x900fd,
  35501. 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c3,
  35502. 0x70108, 0x80061, 0x80021, 0x900a3, 0x80001, 0x80081, 0x80041, 0x900e3,
  35503. 0x70104, 0x80059, 0x80019, 0x90093, 0x70114, 0x80079, 0x80039, 0x900d3,
  35504. 0x7010c, 0x80069, 0x80029, 0x900b3, 0x80009, 0x80089, 0x80049, 0x900f3,
  35505. 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900cb,
  35506. 0x7010a, 0x80065, 0x80025, 0x900ab, 0x80005, 0x80085, 0x80045, 0x900eb,
  35507. 0x70106, 0x8005d, 0x8001d, 0x9009b, 0x70116, 0x8007d, 0x8003d, 0x900db,
  35508. 0x7010e, 0x8006d, 0x8002d, 0x900bb, 0x8000d, 0x8008d, 0x8004d, 0x900fb,
  35509. 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c7,
  35510. 0x70109, 0x80063, 0x80023, 0x900a7, 0x80003, 0x80083, 0x80043, 0x900e7,
  35511. 0x70105, 0x8005b, 0x8001b, 0x90097, 0x70115, 0x8007b, 0x8003b, 0x900d7,
  35512. 0x7010d, 0x8006b, 0x8002b, 0x900b7, 0x8000b, 0x8008b, 0x8004b, 0x900f7,
  35513. 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900cf,
  35514. 0x7010b, 0x80067, 0x80027, 0x900af, 0x80007, 0x80087, 0x80047, 0x900ef,
  35515. 0x70107, 0x8005f, 0x8001f, 0x9009f, 0x70117, 0x8007f, 0x8003f, 0x900df,
  35516. 0x7010f, 0x8006f, 0x8002f, 0x900bf, 0x8000f, 0x8008f, 0x8004f, 0x900ff
  35517. ]), 9];
  35518. var fixedDistCodeTab = [new Int32Array([
  35519. 0x50000, 0x50010, 0x50008, 0x50018, 0x50004, 0x50014, 0x5000c, 0x5001c,
  35520. 0x50002, 0x50012, 0x5000a, 0x5001a, 0x50006, 0x50016, 0x5000e, 0x00000,
  35521. 0x50001, 0x50011, 0x50009, 0x50019, 0x50005, 0x50015, 0x5000d, 0x5001d,
  35522. 0x50003, 0x50013, 0x5000b, 0x5001b, 0x50007, 0x50017, 0x5000f, 0x00000
  35523. ]), 5];
  35524. function FlateStream(str, maybeLength) {
  35525. this.str = str;
  35526. this.dict = str.dict;
  35527. var cmf = str.getByte();
  35528. var flg = str.getByte();
  35529. if (cmf === -1 || flg === -1) {
  35530. error('Invalid header in flate stream: ' + cmf + ', ' + flg);
  35531. }
  35532. if ((cmf & 0x0f) !== 0x08) {
  35533. error('Unknown compression method in flate stream: ' + cmf + ', ' + flg);
  35534. }
  35535. if ((((cmf << 8) + flg) % 31) !== 0) {
  35536. error('Bad FCHECK in flate stream: ' + cmf + ', ' + flg);
  35537. }
  35538. if (flg & 0x20) {
  35539. error('FDICT bit set in flate stream: ' + cmf + ', ' + flg);
  35540. }
  35541. this.codeSize = 0;
  35542. this.codeBuf = 0;
  35543. DecodeStream.call(this, maybeLength);
  35544. }
  35545. FlateStream.prototype = Object.create(DecodeStream.prototype);
  35546. FlateStream.prototype.getBits = function FlateStream_getBits(bits) {
  35547. var str = this.str;
  35548. var codeSize = this.codeSize;
  35549. var codeBuf = this.codeBuf;
  35550. var b;
  35551. while (codeSize < bits) {
  35552. if ((b = str.getByte()) === -1) {
  35553. error('Bad encoding in flate stream');
  35554. }
  35555. codeBuf |= b << codeSize;
  35556. codeSize += 8;
  35557. }
  35558. b = codeBuf & ((1 << bits) - 1);
  35559. this.codeBuf = codeBuf >> bits;
  35560. this.codeSize = codeSize -= bits;
  35561. return b;
  35562. };
  35563. FlateStream.prototype.getCode = function FlateStream_getCode(table) {
  35564. var str = this.str;
  35565. var codes = table[0];
  35566. var maxLen = table[1];
  35567. var codeSize = this.codeSize;
  35568. var codeBuf = this.codeBuf;
  35569. var b;
  35570. while (codeSize < maxLen) {
  35571. if ((b = str.getByte()) === -1) {
  35572. // premature end of stream. code might however still be valid.
  35573. // codeSize < codeLen check below guards against incomplete codeVal.
  35574. break;
  35575. }
  35576. codeBuf |= (b << codeSize);
  35577. codeSize += 8;
  35578. }
  35579. var code = codes[codeBuf & ((1 << maxLen) - 1)];
  35580. var codeLen = code >> 16;
  35581. var codeVal = code & 0xffff;
  35582. if (codeLen < 1 || codeSize < codeLen) {
  35583. error('Bad encoding in flate stream');
  35584. }
  35585. this.codeBuf = (codeBuf >> codeLen);
  35586. this.codeSize = (codeSize - codeLen);
  35587. return codeVal;
  35588. };
  35589. FlateStream.prototype.generateHuffmanTable =
  35590. function flateStreamGenerateHuffmanTable(lengths) {
  35591. var n = lengths.length;
  35592. // find max code length
  35593. var maxLen = 0;
  35594. var i;
  35595. for (i = 0; i < n; ++i) {
  35596. if (lengths[i] > maxLen) {
  35597. maxLen = lengths[i];
  35598. }
  35599. }
  35600. // build the table
  35601. var size = 1 << maxLen;
  35602. var codes = new Int32Array(size);
  35603. for (var len = 1, code = 0, skip = 2;
  35604. len <= maxLen;
  35605. ++len, code <<= 1, skip <<= 1) {
  35606. for (var val = 0; val < n; ++val) {
  35607. if (lengths[val] === len) {
  35608. // bit-reverse the code
  35609. var code2 = 0;
  35610. var t = code;
  35611. for (i = 0; i < len; ++i) {
  35612. code2 = (code2 << 1) | (t & 1);
  35613. t >>= 1;
  35614. }
  35615. // fill the table entries
  35616. for (i = code2; i < size; i += skip) {
  35617. codes[i] = (len << 16) | val;
  35618. }
  35619. ++code;
  35620. }
  35621. }
  35622. }
  35623. return [codes, maxLen];
  35624. };
  35625. FlateStream.prototype.readBlock = function FlateStream_readBlock() {
  35626. var buffer, len;
  35627. var str = this.str;
  35628. // read block header
  35629. var hdr = this.getBits(3);
  35630. if (hdr & 1) {
  35631. this.eof = true;
  35632. }
  35633. hdr >>= 1;
  35634. if (hdr === 0) { // uncompressed block
  35635. var b;
  35636. if ((b = str.getByte()) === -1) {
  35637. error('Bad block header in flate stream');
  35638. }
  35639. var blockLen = b;
  35640. if ((b = str.getByte()) === -1) {
  35641. error('Bad block header in flate stream');
  35642. }
  35643. blockLen |= (b << 8);
  35644. if ((b = str.getByte()) === -1) {
  35645. error('Bad block header in flate stream');
  35646. }
  35647. var check = b;
  35648. if ((b = str.getByte()) === -1) {
  35649. error('Bad block header in flate stream');
  35650. }
  35651. check |= (b << 8);
  35652. if (check !== (~blockLen & 0xffff) &&
  35653. (blockLen !== 0 || check !== 0)) {
  35654. // Ignoring error for bad "empty" block (see issue 1277)
  35655. error('Bad uncompressed block length in flate stream');
  35656. }
  35657. this.codeBuf = 0;
  35658. this.codeSize = 0;
  35659. var bufferLength = this.bufferLength;
  35660. buffer = this.ensureBuffer(bufferLength + blockLen);
  35661. var end = bufferLength + blockLen;
  35662. this.bufferLength = end;
  35663. if (blockLen === 0) {
  35664. if (str.peekByte() === -1) {
  35665. this.eof = true;
  35666. }
  35667. } else {
  35668. for (var n = bufferLength; n < end; ++n) {
  35669. if ((b = str.getByte()) === -1) {
  35670. this.eof = true;
  35671. break;
  35672. }
  35673. buffer[n] = b;
  35674. }
  35675. }
  35676. return;
  35677. }
  35678. var litCodeTable;
  35679. var distCodeTable;
  35680. if (hdr === 1) { // compressed block, fixed codes
  35681. litCodeTable = fixedLitCodeTab;
  35682. distCodeTable = fixedDistCodeTab;
  35683. } else if (hdr === 2) { // compressed block, dynamic codes
  35684. var numLitCodes = this.getBits(5) + 257;
  35685. var numDistCodes = this.getBits(5) + 1;
  35686. var numCodeLenCodes = this.getBits(4) + 4;
  35687. // build the code lengths code table
  35688. var codeLenCodeLengths = new Uint8Array(codeLenCodeMap.length);
  35689. var i;
  35690. for (i = 0; i < numCodeLenCodes; ++i) {
  35691. codeLenCodeLengths[codeLenCodeMap[i]] = this.getBits(3);
  35692. }
  35693. var codeLenCodeTab = this.generateHuffmanTable(codeLenCodeLengths);
  35694. // build the literal and distance code tables
  35695. len = 0;
  35696. i = 0;
  35697. var codes = numLitCodes + numDistCodes;
  35698. var codeLengths = new Uint8Array(codes);
  35699. var bitsLength, bitsOffset, what;
  35700. while (i < codes) {
  35701. var code = this.getCode(codeLenCodeTab);
  35702. if (code === 16) {
  35703. bitsLength = 2; bitsOffset = 3; what = len;
  35704. } else if (code === 17) {
  35705. bitsLength = 3; bitsOffset = 3; what = (len = 0);
  35706. } else if (code === 18) {
  35707. bitsLength = 7; bitsOffset = 11; what = (len = 0);
  35708. } else {
  35709. codeLengths[i++] = len = code;
  35710. continue;
  35711. }
  35712. var repeatLength = this.getBits(bitsLength) + bitsOffset;
  35713. while (repeatLength-- > 0) {
  35714. codeLengths[i++] = what;
  35715. }
  35716. }
  35717. litCodeTable =
  35718. this.generateHuffmanTable(codeLengths.subarray(0, numLitCodes));
  35719. distCodeTable =
  35720. this.generateHuffmanTable(codeLengths.subarray(numLitCodes, codes));
  35721. } else {
  35722. error('Unknown block type in flate stream');
  35723. }
  35724. buffer = this.buffer;
  35725. var limit = buffer ? buffer.length : 0;
  35726. var pos = this.bufferLength;
  35727. while (true) {
  35728. var code1 = this.getCode(litCodeTable);
  35729. if (code1 < 256) {
  35730. if (pos + 1 >= limit) {
  35731. buffer = this.ensureBuffer(pos + 1);
  35732. limit = buffer.length;
  35733. }
  35734. buffer[pos++] = code1;
  35735. continue;
  35736. }
  35737. if (code1 === 256) {
  35738. this.bufferLength = pos;
  35739. return;
  35740. }
  35741. code1 -= 257;
  35742. code1 = lengthDecode[code1];
  35743. var code2 = code1 >> 16;
  35744. if (code2 > 0) {
  35745. code2 = this.getBits(code2);
  35746. }
  35747. len = (code1 & 0xffff) + code2;
  35748. code1 = this.getCode(distCodeTable);
  35749. code1 = distDecode[code1];
  35750. code2 = code1 >> 16;
  35751. if (code2 > 0) {
  35752. code2 = this.getBits(code2);
  35753. }
  35754. var dist = (code1 & 0xffff) + code2;
  35755. if (pos + len >= limit) {
  35756. buffer = this.ensureBuffer(pos + len);
  35757. limit = buffer.length;
  35758. }
  35759. for (var k = 0; k < len; ++k, ++pos) {
  35760. buffer[pos] = buffer[pos - dist];
  35761. }
  35762. }
  35763. };
  35764. return FlateStream;
  35765. })();
  35766. var PredictorStream = (function PredictorStreamClosure() {
  35767. function PredictorStream(str, maybeLength, params) {
  35768. var predictor = this.predictor = params.get('Predictor') || 1;
  35769. if (predictor <= 1) {
  35770. return str; // no prediction
  35771. }
  35772. if (predictor !== 2 && (predictor < 10 || predictor > 15)) {
  35773. error('Unsupported predictor: ' + predictor);
  35774. }
  35775. if (predictor === 2) {
  35776. this.readBlock = this.readBlockTiff;
  35777. } else {
  35778. this.readBlock = this.readBlockPng;
  35779. }
  35780. this.str = str;
  35781. this.dict = str.dict;
  35782. var colors = this.colors = params.get('Colors') || 1;
  35783. var bits = this.bits = params.get('BitsPerComponent') || 8;
  35784. var columns = this.columns = params.get('Columns') || 1;
  35785. this.pixBytes = (colors * bits + 7) >> 3;
  35786. this.rowBytes = (columns * colors * bits + 7) >> 3;
  35787. DecodeStream.call(this, maybeLength);
  35788. return this;
  35789. }
  35790. PredictorStream.prototype = Object.create(DecodeStream.prototype);
  35791. PredictorStream.prototype.readBlockTiff =
  35792. function predictorStreamReadBlockTiff() {
  35793. var rowBytes = this.rowBytes;
  35794. var bufferLength = this.bufferLength;
  35795. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  35796. var bits = this.bits;
  35797. var colors = this.colors;
  35798. var rawBytes = this.str.getBytes(rowBytes);
  35799. this.eof = !rawBytes.length;
  35800. if (this.eof) {
  35801. return;
  35802. }
  35803. var inbuf = 0, outbuf = 0;
  35804. var inbits = 0, outbits = 0;
  35805. var pos = bufferLength;
  35806. var i;
  35807. if (bits === 1) {
  35808. for (i = 0; i < rowBytes; ++i) {
  35809. var c = rawBytes[i];
  35810. inbuf = (inbuf << 8) | c;
  35811. // bitwise addition is exclusive or
  35812. // first shift inbuf and then add
  35813. buffer[pos++] = (c ^ (inbuf >> colors)) & 0xFF;
  35814. // truncate inbuf (assumes colors < 16)
  35815. inbuf &= 0xFFFF;
  35816. }
  35817. } else if (bits === 8) {
  35818. for (i = 0; i < colors; ++i) {
  35819. buffer[pos++] = rawBytes[i];
  35820. }
  35821. for (; i < rowBytes; ++i) {
  35822. buffer[pos] = buffer[pos - colors] + rawBytes[i];
  35823. pos++;
  35824. }
  35825. } else {
  35826. var compArray = new Uint8Array(colors + 1);
  35827. var bitMask = (1 << bits) - 1;
  35828. var j = 0, k = bufferLength;
  35829. var columns = this.columns;
  35830. for (i = 0; i < columns; ++i) {
  35831. for (var kk = 0; kk < colors; ++kk) {
  35832. if (inbits < bits) {
  35833. inbuf = (inbuf << 8) | (rawBytes[j++] & 0xFF);
  35834. inbits += 8;
  35835. }
  35836. compArray[kk] = (compArray[kk] +
  35837. (inbuf >> (inbits - bits))) & bitMask;
  35838. inbits -= bits;
  35839. outbuf = (outbuf << bits) | compArray[kk];
  35840. outbits += bits;
  35841. if (outbits >= 8) {
  35842. buffer[k++] = (outbuf >> (outbits - 8)) & 0xFF;
  35843. outbits -= 8;
  35844. }
  35845. }
  35846. }
  35847. if (outbits > 0) {
  35848. buffer[k++] = (outbuf << (8 - outbits)) +
  35849. (inbuf & ((1 << (8 - outbits)) - 1));
  35850. }
  35851. }
  35852. this.bufferLength += rowBytes;
  35853. };
  35854. PredictorStream.prototype.readBlockPng =
  35855. function predictorStreamReadBlockPng() {
  35856. var rowBytes = this.rowBytes;
  35857. var pixBytes = this.pixBytes;
  35858. var predictor = this.str.getByte();
  35859. var rawBytes = this.str.getBytes(rowBytes);
  35860. this.eof = !rawBytes.length;
  35861. if (this.eof) {
  35862. return;
  35863. }
  35864. var bufferLength = this.bufferLength;
  35865. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  35866. var prevRow = buffer.subarray(bufferLength - rowBytes, bufferLength);
  35867. if (prevRow.length === 0) {
  35868. prevRow = new Uint8Array(rowBytes);
  35869. }
  35870. var i, j = bufferLength, up, c;
  35871. switch (predictor) {
  35872. case 0:
  35873. for (i = 0; i < rowBytes; ++i) {
  35874. buffer[j++] = rawBytes[i];
  35875. }
  35876. break;
  35877. case 1:
  35878. for (i = 0; i < pixBytes; ++i) {
  35879. buffer[j++] = rawBytes[i];
  35880. }
  35881. for (; i < rowBytes; ++i) {
  35882. buffer[j] = (buffer[j - pixBytes] + rawBytes[i]) & 0xFF;
  35883. j++;
  35884. }
  35885. break;
  35886. case 2:
  35887. for (i = 0; i < rowBytes; ++i) {
  35888. buffer[j++] = (prevRow[i] + rawBytes[i]) & 0xFF;
  35889. }
  35890. break;
  35891. case 3:
  35892. for (i = 0; i < pixBytes; ++i) {
  35893. buffer[j++] = (prevRow[i] >> 1) + rawBytes[i];
  35894. }
  35895. for (; i < rowBytes; ++i) {
  35896. buffer[j] = (((prevRow[i] + buffer[j - pixBytes]) >> 1) +
  35897. rawBytes[i]) & 0xFF;
  35898. j++;
  35899. }
  35900. break;
  35901. case 4:
  35902. // we need to save the up left pixels values. the simplest way
  35903. // is to create a new buffer
  35904. for (i = 0; i < pixBytes; ++i) {
  35905. up = prevRow[i];
  35906. c = rawBytes[i];
  35907. buffer[j++] = up + c;
  35908. }
  35909. for (; i < rowBytes; ++i) {
  35910. up = prevRow[i];
  35911. var upLeft = prevRow[i - pixBytes];
  35912. var left = buffer[j - pixBytes];
  35913. var p = left + up - upLeft;
  35914. var pa = p - left;
  35915. if (pa < 0) {
  35916. pa = -pa;
  35917. }
  35918. var pb = p - up;
  35919. if (pb < 0) {
  35920. pb = -pb;
  35921. }
  35922. var pc = p - upLeft;
  35923. if (pc < 0) {
  35924. pc = -pc;
  35925. }
  35926. c = rawBytes[i];
  35927. if (pa <= pb && pa <= pc) {
  35928. buffer[j++] = left + c;
  35929. } else if (pb <= pc) {
  35930. buffer[j++] = up + c;
  35931. } else {
  35932. buffer[j++] = upLeft + c;
  35933. }
  35934. }
  35935. break;
  35936. default:
  35937. error('Unsupported predictor: ' + predictor);
  35938. }
  35939. this.bufferLength += rowBytes;
  35940. };
  35941. return PredictorStream;
  35942. })();
  35943. /**
  35944. * Depending on the type of JPEG a JpegStream is handled in different ways. For
  35945. * JPEG's that are supported natively such as DeviceGray and DeviceRGB the image
  35946. * data is stored and then loaded by the browser. For unsupported JPEG's we use
  35947. * a library to decode these images and the stream behaves like all the other
  35948. * DecodeStreams.
  35949. */
  35950. var JpegStream = (function JpegStreamClosure() {
  35951. function JpegStream(stream, maybeLength, dict, xref) {
  35952. // Some images may contain 'junk' before the SOI (start-of-image) marker.
  35953. // Note: this seems to mainly affect inline images.
  35954. var ch;
  35955. while ((ch = stream.getByte()) !== -1) {
  35956. if (ch === 0xFF) { // Find the first byte of the SOI marker (0xFFD8).
  35957. stream.skip(-1); // Reset the stream position to the SOI.
  35958. break;
  35959. }
  35960. }
  35961. this.stream = stream;
  35962. this.maybeLength = maybeLength;
  35963. this.dict = dict;
  35964. DecodeStream.call(this, maybeLength);
  35965. }
  35966. JpegStream.prototype = Object.create(DecodeStream.prototype);
  35967. Object.defineProperty(JpegStream.prototype, 'bytes', {
  35968. get: function JpegStream_bytes() {
  35969. // If this.maybeLength is null, we'll get the entire stream.
  35970. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  35971. },
  35972. configurable: true
  35973. });
  35974. JpegStream.prototype.ensureBuffer = function JpegStream_ensureBuffer(req) {
  35975. if (this.bufferLength) {
  35976. return;
  35977. }
  35978. try {
  35979. var jpegImage = new JpegImage();
  35980. // checking if values needs to be transformed before conversion
  35981. if (this.forceRGB && this.dict && isArray(this.dict.get('Decode'))) {
  35982. var decodeArr = this.dict.get('Decode');
  35983. var bitsPerComponent = this.dict.get('BitsPerComponent') || 8;
  35984. var decodeArrLength = decodeArr.length;
  35985. var transform = new Int32Array(decodeArrLength);
  35986. var transformNeeded = false;
  35987. var maxValue = (1 << bitsPerComponent) - 1;
  35988. for (var i = 0; i < decodeArrLength; i += 2) {
  35989. transform[i] = ((decodeArr[i + 1] - decodeArr[i]) * 256) | 0;
  35990. transform[i + 1] = (decodeArr[i] * maxValue) | 0;
  35991. if (transform[i] !== 256 || transform[i + 1] !== 0) {
  35992. transformNeeded = true;
  35993. }
  35994. }
  35995. if (transformNeeded) {
  35996. jpegImage.decodeTransform = transform;
  35997. }
  35998. }
  35999. jpegImage.parse(this.bytes);
  36000. var data = jpegImage.getData(this.drawWidth, this.drawHeight,
  36001. this.forceRGB);
  36002. this.buffer = data;
  36003. this.bufferLength = data.length;
  36004. this.eof = true;
  36005. } catch (e) {
  36006. error('JPEG error: ' + e);
  36007. }
  36008. };
  36009. JpegStream.prototype.getBytes = function JpegStream_getBytes(length) {
  36010. this.ensureBuffer();
  36011. return this.buffer;
  36012. };
  36013. JpegStream.prototype.getIR = function JpegStream_getIR() {
  36014. return PDFJS.createObjectURL(this.bytes, 'image/jpeg');
  36015. };
  36016. /**
  36017. * Checks if the image can be decoded and displayed by the browser without any
  36018. * further processing such as color space conversions.
  36019. */
  36020. JpegStream.prototype.isNativelySupported =
  36021. function JpegStream_isNativelySupported(xref, res) {
  36022. var cs = ColorSpace.parse(this.dict.get('ColorSpace', 'CS'), xref, res);
  36023. return cs.name === 'DeviceGray' || cs.name === 'DeviceRGB';
  36024. };
  36025. /**
  36026. * Checks if the image can be decoded by the browser.
  36027. */
  36028. JpegStream.prototype.isNativelyDecodable =
  36029. function JpegStream_isNativelyDecodable(xref, res) {
  36030. var cs = ColorSpace.parse(this.dict.get('ColorSpace', 'CS'), xref, res);
  36031. var numComps = cs.numComps;
  36032. return numComps === 1 || numComps === 3;
  36033. };
  36034. return JpegStream;
  36035. })();
  36036. /**
  36037. * For JPEG 2000's we use a library to decode these images and
  36038. * the stream behaves like all the other DecodeStreams.
  36039. */
  36040. var JpxStream = (function JpxStreamClosure() {
  36041. function JpxStream(stream, maybeLength, dict) {
  36042. this.stream = stream;
  36043. this.maybeLength = maybeLength;
  36044. this.dict = dict;
  36045. DecodeStream.call(this, maybeLength);
  36046. }
  36047. JpxStream.prototype = Object.create(DecodeStream.prototype);
  36048. Object.defineProperty(JpxStream.prototype, 'bytes', {
  36049. get: function JpxStream_bytes() {
  36050. // If this.maybeLength is null, we'll get the entire stream.
  36051. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  36052. },
  36053. configurable: true
  36054. });
  36055. JpxStream.prototype.ensureBuffer = function JpxStream_ensureBuffer(req) {
  36056. if (this.bufferLength) {
  36057. return;
  36058. }
  36059. var jpxImage = new JpxImage();
  36060. jpxImage.parse(this.bytes);
  36061. var width = jpxImage.width;
  36062. var height = jpxImage.height;
  36063. var componentsCount = jpxImage.componentsCount;
  36064. var tileCount = jpxImage.tiles.length;
  36065. if (tileCount === 1) {
  36066. this.buffer = jpxImage.tiles[0].items;
  36067. } else {
  36068. var data = new Uint8Array(width * height * componentsCount);
  36069. for (var k = 0; k < tileCount; k++) {
  36070. var tileComponents = jpxImage.tiles[k];
  36071. var tileWidth = tileComponents.width;
  36072. var tileHeight = tileComponents.height;
  36073. var tileLeft = tileComponents.left;
  36074. var tileTop = tileComponents.top;
  36075. var src = tileComponents.items;
  36076. var srcPosition = 0;
  36077. var dataPosition = (width * tileTop + tileLeft) * componentsCount;
  36078. var imgRowSize = width * componentsCount;
  36079. var tileRowSize = tileWidth * componentsCount;
  36080. for (var j = 0; j < tileHeight; j++) {
  36081. var rowBytes = src.subarray(srcPosition, srcPosition + tileRowSize);
  36082. data.set(rowBytes, dataPosition);
  36083. srcPosition += tileRowSize;
  36084. dataPosition += imgRowSize;
  36085. }
  36086. }
  36087. this.buffer = data;
  36088. }
  36089. this.bufferLength = this.buffer.length;
  36090. this.eof = true;
  36091. };
  36092. return JpxStream;
  36093. })();
  36094. /**
  36095. * For JBIG2's we use a library to decode these images and
  36096. * the stream behaves like all the other DecodeStreams.
  36097. */
  36098. var Jbig2Stream = (function Jbig2StreamClosure() {
  36099. function Jbig2Stream(stream, maybeLength, dict) {
  36100. this.stream = stream;
  36101. this.maybeLength = maybeLength;
  36102. this.dict = dict;
  36103. DecodeStream.call(this, maybeLength);
  36104. }
  36105. Jbig2Stream.prototype = Object.create(DecodeStream.prototype);
  36106. Object.defineProperty(Jbig2Stream.prototype, 'bytes', {
  36107. get: function Jbig2Stream_bytes() {
  36108. // If this.maybeLength is null, we'll get the entire stream.
  36109. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  36110. },
  36111. configurable: true
  36112. });
  36113. Jbig2Stream.prototype.ensureBuffer = function Jbig2Stream_ensureBuffer(req) {
  36114. if (this.bufferLength) {
  36115. return;
  36116. }
  36117. var jbig2Image = new Jbig2Image();
  36118. var chunks = [], xref = this.dict.xref;
  36119. var decodeParams = xref.fetchIfRef(this.dict.get('DecodeParms'));
  36120. // According to the PDF specification, DecodeParms can be either
  36121. // a dictionary, or an array whose elements are dictionaries.
  36122. if (isArray(decodeParams)) {
  36123. if (decodeParams.length > 1) {
  36124. warn('JBIG2 - \'DecodeParms\' array with multiple elements ' +
  36125. 'not supported.');
  36126. }
  36127. decodeParams = xref.fetchIfRef(decodeParams[0]);
  36128. }
  36129. if (decodeParams && decodeParams.has('JBIG2Globals')) {
  36130. var globalsStream = decodeParams.get('JBIG2Globals');
  36131. var globals = globalsStream.getBytes();
  36132. chunks.push({data: globals, start: 0, end: globals.length});
  36133. }
  36134. chunks.push({data: this.bytes, start: 0, end: this.bytes.length});
  36135. var data = jbig2Image.parseChunks(chunks);
  36136. var dataLength = data.length;
  36137. // JBIG2 had black as 1 and white as 0, inverting the colors
  36138. for (var i = 0; i < dataLength; i++) {
  36139. data[i] ^= 0xFF;
  36140. }
  36141. this.buffer = data;
  36142. this.bufferLength = dataLength;
  36143. this.eof = true;
  36144. };
  36145. return Jbig2Stream;
  36146. })();
  36147. var DecryptStream = (function DecryptStreamClosure() {
  36148. function DecryptStream(str, maybeLength, decrypt) {
  36149. this.str = str;
  36150. this.dict = str.dict;
  36151. this.decrypt = decrypt;
  36152. this.nextChunk = null;
  36153. this.initialized = false;
  36154. DecodeStream.call(this, maybeLength);
  36155. }
  36156. var chunkSize = 512;
  36157. DecryptStream.prototype = Object.create(DecodeStream.prototype);
  36158. DecryptStream.prototype.readBlock = function DecryptStream_readBlock() {
  36159. var chunk;
  36160. if (this.initialized) {
  36161. chunk = this.nextChunk;
  36162. } else {
  36163. chunk = this.str.getBytes(chunkSize);
  36164. this.initialized = true;
  36165. }
  36166. if (!chunk || chunk.length === 0) {
  36167. this.eof = true;
  36168. return;
  36169. }
  36170. this.nextChunk = this.str.getBytes(chunkSize);
  36171. var hasMoreData = this.nextChunk && this.nextChunk.length > 0;
  36172. var decrypt = this.decrypt;
  36173. chunk = decrypt(chunk, !hasMoreData);
  36174. var bufferLength = this.bufferLength;
  36175. var i, n = chunk.length;
  36176. var buffer = this.ensureBuffer(bufferLength + n);
  36177. for (i = 0; i < n; i++) {
  36178. buffer[bufferLength++] = chunk[i];
  36179. }
  36180. this.bufferLength = bufferLength;
  36181. };
  36182. return DecryptStream;
  36183. })();
  36184. var Ascii85Stream = (function Ascii85StreamClosure() {
  36185. function Ascii85Stream(str, maybeLength) {
  36186. this.str = str;
  36187. this.dict = str.dict;
  36188. this.input = new Uint8Array(5);
  36189. // Most streams increase in size when decoded, but Ascii85 streams
  36190. // typically shrink by ~20%.
  36191. if (maybeLength) {
  36192. maybeLength = 0.8 * maybeLength;
  36193. }
  36194. DecodeStream.call(this, maybeLength);
  36195. }
  36196. Ascii85Stream.prototype = Object.create(DecodeStream.prototype);
  36197. Ascii85Stream.prototype.readBlock = function Ascii85Stream_readBlock() {
  36198. var TILDA_CHAR = 0x7E; // '~'
  36199. var Z_LOWER_CHAR = 0x7A; // 'z'
  36200. var EOF = -1;
  36201. var str = this.str;
  36202. var c = str.getByte();
  36203. while (Lexer.isSpace(c)) {
  36204. c = str.getByte();
  36205. }
  36206. if (c === EOF || c === TILDA_CHAR) {
  36207. this.eof = true;
  36208. return;
  36209. }
  36210. var bufferLength = this.bufferLength, buffer;
  36211. var i;
  36212. // special code for z
  36213. if (c === Z_LOWER_CHAR) {
  36214. buffer = this.ensureBuffer(bufferLength + 4);
  36215. for (i = 0; i < 4; ++i) {
  36216. buffer[bufferLength + i] = 0;
  36217. }
  36218. this.bufferLength += 4;
  36219. } else {
  36220. var input = this.input;
  36221. input[0] = c;
  36222. for (i = 1; i < 5; ++i) {
  36223. c = str.getByte();
  36224. while (Lexer.isSpace(c)) {
  36225. c = str.getByte();
  36226. }
  36227. input[i] = c;
  36228. if (c === EOF || c === TILDA_CHAR) {
  36229. break;
  36230. }
  36231. }
  36232. buffer = this.ensureBuffer(bufferLength + i - 1);
  36233. this.bufferLength += i - 1;
  36234. // partial ending;
  36235. if (i < 5) {
  36236. for (; i < 5; ++i) {
  36237. input[i] = 0x21 + 84;
  36238. }
  36239. this.eof = true;
  36240. }
  36241. var t = 0;
  36242. for (i = 0; i < 5; ++i) {
  36243. t = t * 85 + (input[i] - 0x21);
  36244. }
  36245. for (i = 3; i >= 0; --i) {
  36246. buffer[bufferLength + i] = t & 0xFF;
  36247. t >>= 8;
  36248. }
  36249. }
  36250. };
  36251. return Ascii85Stream;
  36252. })();
  36253. var AsciiHexStream = (function AsciiHexStreamClosure() {
  36254. function AsciiHexStream(str, maybeLength) {
  36255. this.str = str;
  36256. this.dict = str.dict;
  36257. this.firstDigit = -1;
  36258. // Most streams increase in size when decoded, but AsciiHex streams shrink
  36259. // by 50%.
  36260. if (maybeLength) {
  36261. maybeLength = 0.5 * maybeLength;
  36262. }
  36263. DecodeStream.call(this, maybeLength);
  36264. }
  36265. AsciiHexStream.prototype = Object.create(DecodeStream.prototype);
  36266. AsciiHexStream.prototype.readBlock = function AsciiHexStream_readBlock() {
  36267. var UPSTREAM_BLOCK_SIZE = 8000;
  36268. var bytes = this.str.getBytes(UPSTREAM_BLOCK_SIZE);
  36269. if (!bytes.length) {
  36270. this.eof = true;
  36271. return;
  36272. }
  36273. var maxDecodeLength = (bytes.length + 1) >> 1;
  36274. var buffer = this.ensureBuffer(this.bufferLength + maxDecodeLength);
  36275. var bufferLength = this.bufferLength;
  36276. var firstDigit = this.firstDigit;
  36277. for (var i = 0, ii = bytes.length; i < ii; i++) {
  36278. var ch = bytes[i], digit;
  36279. if (ch >= 0x30 && ch <= 0x39) { // '0'-'9'
  36280. digit = ch & 0x0F;
  36281. } else if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
  36282. // 'A'-'Z', 'a'-'z'
  36283. digit = (ch & 0x0F) + 9;
  36284. } else if (ch === 0x3E) { // '>'
  36285. this.eof = true;
  36286. break;
  36287. } else { // probably whitespace
  36288. continue; // ignoring
  36289. }
  36290. if (firstDigit < 0) {
  36291. firstDigit = digit;
  36292. } else {
  36293. buffer[bufferLength++] = (firstDigit << 4) | digit;
  36294. firstDigit = -1;
  36295. }
  36296. }
  36297. if (firstDigit >= 0 && this.eof) {
  36298. // incomplete byte
  36299. buffer[bufferLength++] = (firstDigit << 4);
  36300. firstDigit = -1;
  36301. }
  36302. this.firstDigit = firstDigit;
  36303. this.bufferLength = bufferLength;
  36304. };
  36305. return AsciiHexStream;
  36306. })();
  36307. var RunLengthStream = (function RunLengthStreamClosure() {
  36308. function RunLengthStream(str, maybeLength) {
  36309. this.str = str;
  36310. this.dict = str.dict;
  36311. DecodeStream.call(this, maybeLength);
  36312. }
  36313. RunLengthStream.prototype = Object.create(DecodeStream.prototype);
  36314. RunLengthStream.prototype.readBlock = function RunLengthStream_readBlock() {
  36315. // The repeatHeader has following format. The first byte defines type of run
  36316. // and amount of bytes to repeat/copy: n = 0 through 127 - copy next n bytes
  36317. // (in addition to the second byte from the header), n = 129 through 255 -
  36318. // duplicate the second byte from the header (257 - n) times, n = 128 - end.
  36319. var repeatHeader = this.str.getBytes(2);
  36320. if (!repeatHeader || repeatHeader.length < 2 || repeatHeader[0] === 128) {
  36321. this.eof = true;
  36322. return;
  36323. }
  36324. var buffer;
  36325. var bufferLength = this.bufferLength;
  36326. var n = repeatHeader[0];
  36327. if (n < 128) {
  36328. // copy n bytes
  36329. buffer = this.ensureBuffer(bufferLength + n + 1);
  36330. buffer[bufferLength++] = repeatHeader[1];
  36331. if (n > 0) {
  36332. var source = this.str.getBytes(n);
  36333. buffer.set(source, bufferLength);
  36334. bufferLength += n;
  36335. }
  36336. } else {
  36337. n = 257 - n;
  36338. var b = repeatHeader[1];
  36339. buffer = this.ensureBuffer(bufferLength + n + 1);
  36340. for (var i = 0; i < n; i++) {
  36341. buffer[bufferLength++] = b;
  36342. }
  36343. }
  36344. this.bufferLength = bufferLength;
  36345. };
  36346. return RunLengthStream;
  36347. })();
  36348. var CCITTFaxStream = (function CCITTFaxStreamClosure() {
  36349. var ccittEOL = -2;
  36350. var twoDimPass = 0;
  36351. var twoDimHoriz = 1;
  36352. var twoDimVert0 = 2;
  36353. var twoDimVertR1 = 3;
  36354. var twoDimVertL1 = 4;
  36355. var twoDimVertR2 = 5;
  36356. var twoDimVertL2 = 6;
  36357. var twoDimVertR3 = 7;
  36358. var twoDimVertL3 = 8;
  36359. var twoDimTable = [
  36360. [-1, -1], [-1, -1], // 000000x
  36361. [7, twoDimVertL3], // 0000010
  36362. [7, twoDimVertR3], // 0000011
  36363. [6, twoDimVertL2], [6, twoDimVertL2], // 000010x
  36364. [6, twoDimVertR2], [6, twoDimVertR2], // 000011x
  36365. [4, twoDimPass], [4, twoDimPass], // 0001xxx
  36366. [4, twoDimPass], [4, twoDimPass],
  36367. [4, twoDimPass], [4, twoDimPass],
  36368. [4, twoDimPass], [4, twoDimPass],
  36369. [3, twoDimHoriz], [3, twoDimHoriz], // 001xxxx
  36370. [3, twoDimHoriz], [3, twoDimHoriz],
  36371. [3, twoDimHoriz], [3, twoDimHoriz],
  36372. [3, twoDimHoriz], [3, twoDimHoriz],
  36373. [3, twoDimHoriz], [3, twoDimHoriz],
  36374. [3, twoDimHoriz], [3, twoDimHoriz],
  36375. [3, twoDimHoriz], [3, twoDimHoriz],
  36376. [3, twoDimHoriz], [3, twoDimHoriz],
  36377. [3, twoDimVertL1], [3, twoDimVertL1], // 010xxxx
  36378. [3, twoDimVertL1], [3, twoDimVertL1],
  36379. [3, twoDimVertL1], [3, twoDimVertL1],
  36380. [3, twoDimVertL1], [3, twoDimVertL1],
  36381. [3, twoDimVertL1], [3, twoDimVertL1],
  36382. [3, twoDimVertL1], [3, twoDimVertL1],
  36383. [3, twoDimVertL1], [3, twoDimVertL1],
  36384. [3, twoDimVertL1], [3, twoDimVertL1],
  36385. [3, twoDimVertR1], [3, twoDimVertR1], // 011xxxx
  36386. [3, twoDimVertR1], [3, twoDimVertR1],
  36387. [3, twoDimVertR1], [3, twoDimVertR1],
  36388. [3, twoDimVertR1], [3, twoDimVertR1],
  36389. [3, twoDimVertR1], [3, twoDimVertR1],
  36390. [3, twoDimVertR1], [3, twoDimVertR1],
  36391. [3, twoDimVertR1], [3, twoDimVertR1],
  36392. [3, twoDimVertR1], [3, twoDimVertR1],
  36393. [1, twoDimVert0], [1, twoDimVert0], // 1xxxxxx
  36394. [1, twoDimVert0], [1, twoDimVert0],
  36395. [1, twoDimVert0], [1, twoDimVert0],
  36396. [1, twoDimVert0], [1, twoDimVert0],
  36397. [1, twoDimVert0], [1, twoDimVert0],
  36398. [1, twoDimVert0], [1, twoDimVert0],
  36399. [1, twoDimVert0], [1, twoDimVert0],
  36400. [1, twoDimVert0], [1, twoDimVert0],
  36401. [1, twoDimVert0], [1, twoDimVert0],
  36402. [1, twoDimVert0], [1, twoDimVert0],
  36403. [1, twoDimVert0], [1, twoDimVert0],
  36404. [1, twoDimVert0], [1, twoDimVert0],
  36405. [1, twoDimVert0], [1, twoDimVert0],
  36406. [1, twoDimVert0], [1, twoDimVert0],
  36407. [1, twoDimVert0], [1, twoDimVert0],
  36408. [1, twoDimVert0], [1, twoDimVert0],
  36409. [1, twoDimVert0], [1, twoDimVert0],
  36410. [1, twoDimVert0], [1, twoDimVert0],
  36411. [1, twoDimVert0], [1, twoDimVert0],
  36412. [1, twoDimVert0], [1, twoDimVert0],
  36413. [1, twoDimVert0], [1, twoDimVert0],
  36414. [1, twoDimVert0], [1, twoDimVert0],
  36415. [1, twoDimVert0], [1, twoDimVert0],
  36416. [1, twoDimVert0], [1, twoDimVert0],
  36417. [1, twoDimVert0], [1, twoDimVert0],
  36418. [1, twoDimVert0], [1, twoDimVert0],
  36419. [1, twoDimVert0], [1, twoDimVert0],
  36420. [1, twoDimVert0], [1, twoDimVert0],
  36421. [1, twoDimVert0], [1, twoDimVert0],
  36422. [1, twoDimVert0], [1, twoDimVert0],
  36423. [1, twoDimVert0], [1, twoDimVert0],
  36424. [1, twoDimVert0], [1, twoDimVert0]
  36425. ];
  36426. var whiteTable1 = [
  36427. [-1, -1], // 00000
  36428. [12, ccittEOL], // 00001
  36429. [-1, -1], [-1, -1], // 0001x
  36430. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 001xx
  36431. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 010xx
  36432. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 011xx
  36433. [11, 1792], [11, 1792], // 1000x
  36434. [12, 1984], // 10010
  36435. [12, 2048], // 10011
  36436. [12, 2112], // 10100
  36437. [12, 2176], // 10101
  36438. [12, 2240], // 10110
  36439. [12, 2304], // 10111
  36440. [11, 1856], [11, 1856], // 1100x
  36441. [11, 1920], [11, 1920], // 1101x
  36442. [12, 2368], // 11100
  36443. [12, 2432], // 11101
  36444. [12, 2496], // 11110
  36445. [12, 2560] // 11111
  36446. ];
  36447. var whiteTable2 = [
  36448. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000000xx
  36449. [8, 29], [8, 29], // 00000010x
  36450. [8, 30], [8, 30], // 00000011x
  36451. [8, 45], [8, 45], // 00000100x
  36452. [8, 46], [8, 46], // 00000101x
  36453. [7, 22], [7, 22], [7, 22], [7, 22], // 0000011xx
  36454. [7, 23], [7, 23], [7, 23], [7, 23], // 0000100xx
  36455. [8, 47], [8, 47], // 00001010x
  36456. [8, 48], [8, 48], // 00001011x
  36457. [6, 13], [6, 13], [6, 13], [6, 13], // 000011xxx
  36458. [6, 13], [6, 13], [6, 13], [6, 13],
  36459. [7, 20], [7, 20], [7, 20], [7, 20], // 0001000xx
  36460. [8, 33], [8, 33], // 00010010x
  36461. [8, 34], [8, 34], // 00010011x
  36462. [8, 35], [8, 35], // 00010100x
  36463. [8, 36], [8, 36], // 00010101x
  36464. [8, 37], [8, 37], // 00010110x
  36465. [8, 38], [8, 38], // 00010111x
  36466. [7, 19], [7, 19], [7, 19], [7, 19], // 0001100xx
  36467. [8, 31], [8, 31], // 00011010x
  36468. [8, 32], [8, 32], // 00011011x
  36469. [6, 1], [6, 1], [6, 1], [6, 1], // 000111xxx
  36470. [6, 1], [6, 1], [6, 1], [6, 1],
  36471. [6, 12], [6, 12], [6, 12], [6, 12], // 001000xxx
  36472. [6, 12], [6, 12], [6, 12], [6, 12],
  36473. [8, 53], [8, 53], // 00100100x
  36474. [8, 54], [8, 54], // 00100101x
  36475. [7, 26], [7, 26], [7, 26], [7, 26], // 0010011xx
  36476. [8, 39], [8, 39], // 00101000x
  36477. [8, 40], [8, 40], // 00101001x
  36478. [8, 41], [8, 41], // 00101010x
  36479. [8, 42], [8, 42], // 00101011x
  36480. [8, 43], [8, 43], // 00101100x
  36481. [8, 44], [8, 44], // 00101101x
  36482. [7, 21], [7, 21], [7, 21], [7, 21], // 0010111xx
  36483. [7, 28], [7, 28], [7, 28], [7, 28], // 0011000xx
  36484. [8, 61], [8, 61], // 00110010x
  36485. [8, 62], [8, 62], // 00110011x
  36486. [8, 63], [8, 63], // 00110100x
  36487. [8, 0], [8, 0], // 00110101x
  36488. [8, 320], [8, 320], // 00110110x
  36489. [8, 384], [8, 384], // 00110111x
  36490. [5, 10], [5, 10], [5, 10], [5, 10], // 00111xxxx
  36491. [5, 10], [5, 10], [5, 10], [5, 10],
  36492. [5, 10], [5, 10], [5, 10], [5, 10],
  36493. [5, 10], [5, 10], [5, 10], [5, 10],
  36494. [5, 11], [5, 11], [5, 11], [5, 11], // 01000xxxx
  36495. [5, 11], [5, 11], [5, 11], [5, 11],
  36496. [5, 11], [5, 11], [5, 11], [5, 11],
  36497. [5, 11], [5, 11], [5, 11], [5, 11],
  36498. [7, 27], [7, 27], [7, 27], [7, 27], // 0100100xx
  36499. [8, 59], [8, 59], // 01001010x
  36500. [8, 60], [8, 60], // 01001011x
  36501. [9, 1472], // 010011000
  36502. [9, 1536], // 010011001
  36503. [9, 1600], // 010011010
  36504. [9, 1728], // 010011011
  36505. [7, 18], [7, 18], [7, 18], [7, 18], // 0100111xx
  36506. [7, 24], [7, 24], [7, 24], [7, 24], // 0101000xx
  36507. [8, 49], [8, 49], // 01010010x
  36508. [8, 50], [8, 50], // 01010011x
  36509. [8, 51], [8, 51], // 01010100x
  36510. [8, 52], [8, 52], // 01010101x
  36511. [7, 25], [7, 25], [7, 25], [7, 25], // 0101011xx
  36512. [8, 55], [8, 55], // 01011000x
  36513. [8, 56], [8, 56], // 01011001x
  36514. [8, 57], [8, 57], // 01011010x
  36515. [8, 58], [8, 58], // 01011011x
  36516. [6, 192], [6, 192], [6, 192], [6, 192], // 010111xxx
  36517. [6, 192], [6, 192], [6, 192], [6, 192],
  36518. [6, 1664], [6, 1664], [6, 1664], [6, 1664], // 011000xxx
  36519. [6, 1664], [6, 1664], [6, 1664], [6, 1664],
  36520. [8, 448], [8, 448], // 01100100x
  36521. [8, 512], [8, 512], // 01100101x
  36522. [9, 704], // 011001100
  36523. [9, 768], // 011001101
  36524. [8, 640], [8, 640], // 01100111x
  36525. [8, 576], [8, 576], // 01101000x
  36526. [9, 832], // 011010010
  36527. [9, 896], // 011010011
  36528. [9, 960], // 011010100
  36529. [9, 1024], // 011010101
  36530. [9, 1088], // 011010110
  36531. [9, 1152], // 011010111
  36532. [9, 1216], // 011011000
  36533. [9, 1280], // 011011001
  36534. [9, 1344], // 011011010
  36535. [9, 1408], // 011011011
  36536. [7, 256], [7, 256], [7, 256], [7, 256], // 0110111xx
  36537. [4, 2], [4, 2], [4, 2], [4, 2], // 0111xxxxx
  36538. [4, 2], [4, 2], [4, 2], [4, 2],
  36539. [4, 2], [4, 2], [4, 2], [4, 2],
  36540. [4, 2], [4, 2], [4, 2], [4, 2],
  36541. [4, 2], [4, 2], [4, 2], [4, 2],
  36542. [4, 2], [4, 2], [4, 2], [4, 2],
  36543. [4, 2], [4, 2], [4, 2], [4, 2],
  36544. [4, 2], [4, 2], [4, 2], [4, 2],
  36545. [4, 3], [4, 3], [4, 3], [4, 3], // 1000xxxxx
  36546. [4, 3], [4, 3], [4, 3], [4, 3],
  36547. [4, 3], [4, 3], [4, 3], [4, 3],
  36548. [4, 3], [4, 3], [4, 3], [4, 3],
  36549. [4, 3], [4, 3], [4, 3], [4, 3],
  36550. [4, 3], [4, 3], [4, 3], [4, 3],
  36551. [4, 3], [4, 3], [4, 3], [4, 3],
  36552. [4, 3], [4, 3], [4, 3], [4, 3],
  36553. [5, 128], [5, 128], [5, 128], [5, 128], // 10010xxxx
  36554. [5, 128], [5, 128], [5, 128], [5, 128],
  36555. [5, 128], [5, 128], [5, 128], [5, 128],
  36556. [5, 128], [5, 128], [5, 128], [5, 128],
  36557. [5, 8], [5, 8], [5, 8], [5, 8], // 10011xxxx
  36558. [5, 8], [5, 8], [5, 8], [5, 8],
  36559. [5, 8], [5, 8], [5, 8], [5, 8],
  36560. [5, 8], [5, 8], [5, 8], [5, 8],
  36561. [5, 9], [5, 9], [5, 9], [5, 9], // 10100xxxx
  36562. [5, 9], [5, 9], [5, 9], [5, 9],
  36563. [5, 9], [5, 9], [5, 9], [5, 9],
  36564. [5, 9], [5, 9], [5, 9], [5, 9],
  36565. [6, 16], [6, 16], [6, 16], [6, 16], // 101010xxx
  36566. [6, 16], [6, 16], [6, 16], [6, 16],
  36567. [6, 17], [6, 17], [6, 17], [6, 17], // 101011xxx
  36568. [6, 17], [6, 17], [6, 17], [6, 17],
  36569. [4, 4], [4, 4], [4, 4], [4, 4], // 1011xxxxx
  36570. [4, 4], [4, 4], [4, 4], [4, 4],
  36571. [4, 4], [4, 4], [4, 4], [4, 4],
  36572. [4, 4], [4, 4], [4, 4], [4, 4],
  36573. [4, 4], [4, 4], [4, 4], [4, 4],
  36574. [4, 4], [4, 4], [4, 4], [4, 4],
  36575. [4, 4], [4, 4], [4, 4], [4, 4],
  36576. [4, 4], [4, 4], [4, 4], [4, 4],
  36577. [4, 5], [4, 5], [4, 5], [4, 5], // 1100xxxxx
  36578. [4, 5], [4, 5], [4, 5], [4, 5],
  36579. [4, 5], [4, 5], [4, 5], [4, 5],
  36580. [4, 5], [4, 5], [4, 5], [4, 5],
  36581. [4, 5], [4, 5], [4, 5], [4, 5],
  36582. [4, 5], [4, 5], [4, 5], [4, 5],
  36583. [4, 5], [4, 5], [4, 5], [4, 5],
  36584. [4, 5], [4, 5], [4, 5], [4, 5],
  36585. [6, 14], [6, 14], [6, 14], [6, 14], // 110100xxx
  36586. [6, 14], [6, 14], [6, 14], [6, 14],
  36587. [6, 15], [6, 15], [6, 15], [6, 15], // 110101xxx
  36588. [6, 15], [6, 15], [6, 15], [6, 15],
  36589. [5, 64], [5, 64], [5, 64], [5, 64], // 11011xxxx
  36590. [5, 64], [5, 64], [5, 64], [5, 64],
  36591. [5, 64], [5, 64], [5, 64], [5, 64],
  36592. [5, 64], [5, 64], [5, 64], [5, 64],
  36593. [4, 6], [4, 6], [4, 6], [4, 6], // 1110xxxxx
  36594. [4, 6], [4, 6], [4, 6], [4, 6],
  36595. [4, 6], [4, 6], [4, 6], [4, 6],
  36596. [4, 6], [4, 6], [4, 6], [4, 6],
  36597. [4, 6], [4, 6], [4, 6], [4, 6],
  36598. [4, 6], [4, 6], [4, 6], [4, 6],
  36599. [4, 6], [4, 6], [4, 6], [4, 6],
  36600. [4, 6], [4, 6], [4, 6], [4, 6],
  36601. [4, 7], [4, 7], [4, 7], [4, 7], // 1111xxxxx
  36602. [4, 7], [4, 7], [4, 7], [4, 7],
  36603. [4, 7], [4, 7], [4, 7], [4, 7],
  36604. [4, 7], [4, 7], [4, 7], [4, 7],
  36605. [4, 7], [4, 7], [4, 7], [4, 7],
  36606. [4, 7], [4, 7], [4, 7], [4, 7],
  36607. [4, 7], [4, 7], [4, 7], [4, 7],
  36608. [4, 7], [4, 7], [4, 7], [4, 7]
  36609. ];
  36610. var blackTable1 = [
  36611. [-1, -1], [-1, -1], // 000000000000x
  36612. [12, ccittEOL], [12, ccittEOL], // 000000000001x
  36613. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000001xx
  36614. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000010xx
  36615. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000011xx
  36616. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000100xx
  36617. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000101xx
  36618. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000110xx
  36619. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000111xx
  36620. [11, 1792], [11, 1792], [11, 1792], [11, 1792], // 00000001000xx
  36621. [12, 1984], [12, 1984], // 000000010010x
  36622. [12, 2048], [12, 2048], // 000000010011x
  36623. [12, 2112], [12, 2112], // 000000010100x
  36624. [12, 2176], [12, 2176], // 000000010101x
  36625. [12, 2240], [12, 2240], // 000000010110x
  36626. [12, 2304], [12, 2304], // 000000010111x
  36627. [11, 1856], [11, 1856], [11, 1856], [11, 1856], // 00000001100xx
  36628. [11, 1920], [11, 1920], [11, 1920], [11, 1920], // 00000001101xx
  36629. [12, 2368], [12, 2368], // 000000011100x
  36630. [12, 2432], [12, 2432], // 000000011101x
  36631. [12, 2496], [12, 2496], // 000000011110x
  36632. [12, 2560], [12, 2560], // 000000011111x
  36633. [10, 18], [10, 18], [10, 18], [10, 18], // 0000001000xxx
  36634. [10, 18], [10, 18], [10, 18], [10, 18],
  36635. [12, 52], [12, 52], // 000000100100x
  36636. [13, 640], // 0000001001010
  36637. [13, 704], // 0000001001011
  36638. [13, 768], // 0000001001100
  36639. [13, 832], // 0000001001101
  36640. [12, 55], [12, 55], // 000000100111x
  36641. [12, 56], [12, 56], // 000000101000x
  36642. [13, 1280], // 0000001010010
  36643. [13, 1344], // 0000001010011
  36644. [13, 1408], // 0000001010100
  36645. [13, 1472], // 0000001010101
  36646. [12, 59], [12, 59], // 000000101011x
  36647. [12, 60], [12, 60], // 000000101100x
  36648. [13, 1536], // 0000001011010
  36649. [13, 1600], // 0000001011011
  36650. [11, 24], [11, 24], [11, 24], [11, 24], // 00000010111xx
  36651. [11, 25], [11, 25], [11, 25], [11, 25], // 00000011000xx
  36652. [13, 1664], // 0000001100100
  36653. [13, 1728], // 0000001100101
  36654. [12, 320], [12, 320], // 000000110011x
  36655. [12, 384], [12, 384], // 000000110100x
  36656. [12, 448], [12, 448], // 000000110101x
  36657. [13, 512], // 0000001101100
  36658. [13, 576], // 0000001101101
  36659. [12, 53], [12, 53], // 000000110111x
  36660. [12, 54], [12, 54], // 000000111000x
  36661. [13, 896], // 0000001110010
  36662. [13, 960], // 0000001110011
  36663. [13, 1024], // 0000001110100
  36664. [13, 1088], // 0000001110101
  36665. [13, 1152], // 0000001110110
  36666. [13, 1216], // 0000001110111
  36667. [10, 64], [10, 64], [10, 64], [10, 64], // 0000001111xxx
  36668. [10, 64], [10, 64], [10, 64], [10, 64]
  36669. ];
  36670. var blackTable2 = [
  36671. [8, 13], [8, 13], [8, 13], [8, 13], // 00000100xxxx
  36672. [8, 13], [8, 13], [8, 13], [8, 13],
  36673. [8, 13], [8, 13], [8, 13], [8, 13],
  36674. [8, 13], [8, 13], [8, 13], [8, 13],
  36675. [11, 23], [11, 23], // 00000101000x
  36676. [12, 50], // 000001010010
  36677. [12, 51], // 000001010011
  36678. [12, 44], // 000001010100
  36679. [12, 45], // 000001010101
  36680. [12, 46], // 000001010110
  36681. [12, 47], // 000001010111
  36682. [12, 57], // 000001011000
  36683. [12, 58], // 000001011001
  36684. [12, 61], // 000001011010
  36685. [12, 256], // 000001011011
  36686. [10, 16], [10, 16], [10, 16], [10, 16], // 0000010111xx
  36687. [10, 17], [10, 17], [10, 17], [10, 17], // 0000011000xx
  36688. [12, 48], // 000001100100
  36689. [12, 49], // 000001100101
  36690. [12, 62], // 000001100110
  36691. [12, 63], // 000001100111
  36692. [12, 30], // 000001101000
  36693. [12, 31], // 000001101001
  36694. [12, 32], // 000001101010
  36695. [12, 33], // 000001101011
  36696. [12, 40], // 000001101100
  36697. [12, 41], // 000001101101
  36698. [11, 22], [11, 22], // 00000110111x
  36699. [8, 14], [8, 14], [8, 14], [8, 14], // 00000111xxxx
  36700. [8, 14], [8, 14], [8, 14], [8, 14],
  36701. [8, 14], [8, 14], [8, 14], [8, 14],
  36702. [8, 14], [8, 14], [8, 14], [8, 14],
  36703. [7, 10], [7, 10], [7, 10], [7, 10], // 0000100xxxxx
  36704. [7, 10], [7, 10], [7, 10], [7, 10],
  36705. [7, 10], [7, 10], [7, 10], [7, 10],
  36706. [7, 10], [7, 10], [7, 10], [7, 10],
  36707. [7, 10], [7, 10], [7, 10], [7, 10],
  36708. [7, 10], [7, 10], [7, 10], [7, 10],
  36709. [7, 10], [7, 10], [7, 10], [7, 10],
  36710. [7, 10], [7, 10], [7, 10], [7, 10],
  36711. [7, 11], [7, 11], [7, 11], [7, 11], // 0000101xxxxx
  36712. [7, 11], [7, 11], [7, 11], [7, 11],
  36713. [7, 11], [7, 11], [7, 11], [7, 11],
  36714. [7, 11], [7, 11], [7, 11], [7, 11],
  36715. [7, 11], [7, 11], [7, 11], [7, 11],
  36716. [7, 11], [7, 11], [7, 11], [7, 11],
  36717. [7, 11], [7, 11], [7, 11], [7, 11],
  36718. [7, 11], [7, 11], [7, 11], [7, 11],
  36719. [9, 15], [9, 15], [9, 15], [9, 15], // 000011000xxx
  36720. [9, 15], [9, 15], [9, 15], [9, 15],
  36721. [12, 128], // 000011001000
  36722. [12, 192], // 000011001001
  36723. [12, 26], // 000011001010
  36724. [12, 27], // 000011001011
  36725. [12, 28], // 000011001100
  36726. [12, 29], // 000011001101
  36727. [11, 19], [11, 19], // 00001100111x
  36728. [11, 20], [11, 20], // 00001101000x
  36729. [12, 34], // 000011010010
  36730. [12, 35], // 000011010011
  36731. [12, 36], // 000011010100
  36732. [12, 37], // 000011010101
  36733. [12, 38], // 000011010110
  36734. [12, 39], // 000011010111
  36735. [11, 21], [11, 21], // 00001101100x
  36736. [12, 42], // 000011011010
  36737. [12, 43], // 000011011011
  36738. [10, 0], [10, 0], [10, 0], [10, 0], // 0000110111xx
  36739. [7, 12], [7, 12], [7, 12], [7, 12], // 0000111xxxxx
  36740. [7, 12], [7, 12], [7, 12], [7, 12],
  36741. [7, 12], [7, 12], [7, 12], [7, 12],
  36742. [7, 12], [7, 12], [7, 12], [7, 12],
  36743. [7, 12], [7, 12], [7, 12], [7, 12],
  36744. [7, 12], [7, 12], [7, 12], [7, 12],
  36745. [7, 12], [7, 12], [7, 12], [7, 12],
  36746. [7, 12], [7, 12], [7, 12], [7, 12]
  36747. ];
  36748. var blackTable3 = [
  36749. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000xx
  36750. [6, 9], // 000100
  36751. [6, 8], // 000101
  36752. [5, 7], [5, 7], // 00011x
  36753. [4, 6], [4, 6], [4, 6], [4, 6], // 0010xx
  36754. [4, 5], [4, 5], [4, 5], [4, 5], // 0011xx
  36755. [3, 1], [3, 1], [3, 1], [3, 1], // 010xxx
  36756. [3, 1], [3, 1], [3, 1], [3, 1],
  36757. [3, 4], [3, 4], [3, 4], [3, 4], // 011xxx
  36758. [3, 4], [3, 4], [3, 4], [3, 4],
  36759. [2, 3], [2, 3], [2, 3], [2, 3], // 10xxxx
  36760. [2, 3], [2, 3], [2, 3], [2, 3],
  36761. [2, 3], [2, 3], [2, 3], [2, 3],
  36762. [2, 3], [2, 3], [2, 3], [2, 3],
  36763. [2, 2], [2, 2], [2, 2], [2, 2], // 11xxxx
  36764. [2, 2], [2, 2], [2, 2], [2, 2],
  36765. [2, 2], [2, 2], [2, 2], [2, 2],
  36766. [2, 2], [2, 2], [2, 2], [2, 2]
  36767. ];
  36768. function CCITTFaxStream(str, maybeLength, params) {
  36769. this.str = str;
  36770. this.dict = str.dict;
  36771. params = params || Dict.empty;
  36772. this.encoding = params.get('K') || 0;
  36773. this.eoline = params.get('EndOfLine') || false;
  36774. this.byteAlign = params.get('EncodedByteAlign') || false;
  36775. this.columns = params.get('Columns') || 1728;
  36776. this.rows = params.get('Rows') || 0;
  36777. var eoblock = params.get('EndOfBlock');
  36778. if (eoblock === null || eoblock === undefined) {
  36779. eoblock = true;
  36780. }
  36781. this.eoblock = eoblock;
  36782. this.black = params.get('BlackIs1') || false;
  36783. this.codingLine = new Uint32Array(this.columns + 1);
  36784. this.refLine = new Uint32Array(this.columns + 2);
  36785. this.codingLine[0] = this.columns;
  36786. this.codingPos = 0;
  36787. this.row = 0;
  36788. this.nextLine2D = this.encoding < 0;
  36789. this.inputBits = 0;
  36790. this.inputBuf = 0;
  36791. this.outputBits = 0;
  36792. var code1;
  36793. while ((code1 = this.lookBits(12)) === 0) {
  36794. this.eatBits(1);
  36795. }
  36796. if (code1 === 1) {
  36797. this.eatBits(12);
  36798. }
  36799. if (this.encoding > 0) {
  36800. this.nextLine2D = !this.lookBits(1);
  36801. this.eatBits(1);
  36802. }
  36803. DecodeStream.call(this, maybeLength);
  36804. }
  36805. CCITTFaxStream.prototype = Object.create(DecodeStream.prototype);
  36806. CCITTFaxStream.prototype.readBlock = function CCITTFaxStream_readBlock() {
  36807. while (!this.eof) {
  36808. var c = this.lookChar();
  36809. this.ensureBuffer(this.bufferLength + 1);
  36810. this.buffer[this.bufferLength++] = c;
  36811. }
  36812. };
  36813. CCITTFaxStream.prototype.addPixels =
  36814. function ccittFaxStreamAddPixels(a1, blackPixels) {
  36815. var codingLine = this.codingLine;
  36816. var codingPos = this.codingPos;
  36817. if (a1 > codingLine[codingPos]) {
  36818. if (a1 > this.columns) {
  36819. info('row is wrong length');
  36820. this.err = true;
  36821. a1 = this.columns;
  36822. }
  36823. if ((codingPos & 1) ^ blackPixels) {
  36824. ++codingPos;
  36825. }
  36826. codingLine[codingPos] = a1;
  36827. }
  36828. this.codingPos = codingPos;
  36829. };
  36830. CCITTFaxStream.prototype.addPixelsNeg =
  36831. function ccittFaxStreamAddPixelsNeg(a1, blackPixels) {
  36832. var codingLine = this.codingLine;
  36833. var codingPos = this.codingPos;
  36834. if (a1 > codingLine[codingPos]) {
  36835. if (a1 > this.columns) {
  36836. info('row is wrong length');
  36837. this.err = true;
  36838. a1 = this.columns;
  36839. }
  36840. if ((codingPos & 1) ^ blackPixels) {
  36841. ++codingPos;
  36842. }
  36843. codingLine[codingPos] = a1;
  36844. } else if (a1 < codingLine[codingPos]) {
  36845. if (a1 < 0) {
  36846. info('invalid code');
  36847. this.err = true;
  36848. a1 = 0;
  36849. }
  36850. while (codingPos > 0 && a1 < codingLine[codingPos - 1]) {
  36851. --codingPos;
  36852. }
  36853. codingLine[codingPos] = a1;
  36854. }
  36855. this.codingPos = codingPos;
  36856. };
  36857. CCITTFaxStream.prototype.lookChar = function CCITTFaxStream_lookChar() {
  36858. var refLine = this.refLine;
  36859. var codingLine = this.codingLine;
  36860. var columns = this.columns;
  36861. var refPos, blackPixels, bits, i;
  36862. if (this.outputBits === 0) {
  36863. if (this.eof) {
  36864. return null;
  36865. }
  36866. this.err = false;
  36867. var code1, code2, code3;
  36868. if (this.nextLine2D) {
  36869. for (i = 0; codingLine[i] < columns; ++i) {
  36870. refLine[i] = codingLine[i];
  36871. }
  36872. refLine[i++] = columns;
  36873. refLine[i] = columns;
  36874. codingLine[0] = 0;
  36875. this.codingPos = 0;
  36876. refPos = 0;
  36877. blackPixels = 0;
  36878. while (codingLine[this.codingPos] < columns) {
  36879. code1 = this.getTwoDimCode();
  36880. switch (code1) {
  36881. case twoDimPass:
  36882. this.addPixels(refLine[refPos + 1], blackPixels);
  36883. if (refLine[refPos + 1] < columns) {
  36884. refPos += 2;
  36885. }
  36886. break;
  36887. case twoDimHoriz:
  36888. code1 = code2 = 0;
  36889. if (blackPixels) {
  36890. do {
  36891. code1 += (code3 = this.getBlackCode());
  36892. } while (code3 >= 64);
  36893. do {
  36894. code2 += (code3 = this.getWhiteCode());
  36895. } while (code3 >= 64);
  36896. } else {
  36897. do {
  36898. code1 += (code3 = this.getWhiteCode());
  36899. } while (code3 >= 64);
  36900. do {
  36901. code2 += (code3 = this.getBlackCode());
  36902. } while (code3 >= 64);
  36903. }
  36904. this.addPixels(codingLine[this.codingPos] +
  36905. code1, blackPixels);
  36906. if (codingLine[this.codingPos] < columns) {
  36907. this.addPixels(codingLine[this.codingPos] + code2,
  36908. blackPixels ^ 1);
  36909. }
  36910. while (refLine[refPos] <= codingLine[this.codingPos] &&
  36911. refLine[refPos] < columns) {
  36912. refPos += 2;
  36913. }
  36914. break;
  36915. case twoDimVertR3:
  36916. this.addPixels(refLine[refPos] + 3, blackPixels);
  36917. blackPixels ^= 1;
  36918. if (codingLine[this.codingPos] < columns) {
  36919. ++refPos;
  36920. while (refLine[refPos] <= codingLine[this.codingPos] &&
  36921. refLine[refPos] < columns) {
  36922. refPos += 2;
  36923. }
  36924. }
  36925. break;
  36926. case twoDimVertR2:
  36927. this.addPixels(refLine[refPos] + 2, blackPixels);
  36928. blackPixels ^= 1;
  36929. if (codingLine[this.codingPos] < columns) {
  36930. ++refPos;
  36931. while (refLine[refPos] <= codingLine[this.codingPos] &&
  36932. refLine[refPos] < columns) {
  36933. refPos += 2;
  36934. }
  36935. }
  36936. break;
  36937. case twoDimVertR1:
  36938. this.addPixels(refLine[refPos] + 1, blackPixels);
  36939. blackPixels ^= 1;
  36940. if (codingLine[this.codingPos] < columns) {
  36941. ++refPos;
  36942. while (refLine[refPos] <= codingLine[this.codingPos] &&
  36943. refLine[refPos] < columns) {
  36944. refPos += 2;
  36945. }
  36946. }
  36947. break;
  36948. case twoDimVert0:
  36949. this.addPixels(refLine[refPos], blackPixels);
  36950. blackPixels ^= 1;
  36951. if (codingLine[this.codingPos] < columns) {
  36952. ++refPos;
  36953. while (refLine[refPos] <= codingLine[this.codingPos] &&
  36954. refLine[refPos] < columns) {
  36955. refPos += 2;
  36956. }
  36957. }
  36958. break;
  36959. case twoDimVertL3:
  36960. this.addPixelsNeg(refLine[refPos] - 3, blackPixels);
  36961. blackPixels ^= 1;
  36962. if (codingLine[this.codingPos] < columns) {
  36963. if (refPos > 0) {
  36964. --refPos;
  36965. } else {
  36966. ++refPos;
  36967. }
  36968. while (refLine[refPos] <= codingLine[this.codingPos] &&
  36969. refLine[refPos] < columns) {
  36970. refPos += 2;
  36971. }
  36972. }
  36973. break;
  36974. case twoDimVertL2:
  36975. this.addPixelsNeg(refLine[refPos] - 2, blackPixels);
  36976. blackPixels ^= 1;
  36977. if (codingLine[this.codingPos] < columns) {
  36978. if (refPos > 0) {
  36979. --refPos;
  36980. } else {
  36981. ++refPos;
  36982. }
  36983. while (refLine[refPos] <= codingLine[this.codingPos] &&
  36984. refLine[refPos] < columns) {
  36985. refPos += 2;
  36986. }
  36987. }
  36988. break;
  36989. case twoDimVertL1:
  36990. this.addPixelsNeg(refLine[refPos] - 1, blackPixels);
  36991. blackPixels ^= 1;
  36992. if (codingLine[this.codingPos] < columns) {
  36993. if (refPos > 0) {
  36994. --refPos;
  36995. } else {
  36996. ++refPos;
  36997. }
  36998. while (refLine[refPos] <= codingLine[this.codingPos] &&
  36999. refLine[refPos] < columns) {
  37000. refPos += 2;
  37001. }
  37002. }
  37003. break;
  37004. case EOF:
  37005. this.addPixels(columns, 0);
  37006. this.eof = true;
  37007. break;
  37008. default:
  37009. info('bad 2d code');
  37010. this.addPixels(columns, 0);
  37011. this.err = true;
  37012. }
  37013. }
  37014. } else {
  37015. codingLine[0] = 0;
  37016. this.codingPos = 0;
  37017. blackPixels = 0;
  37018. while (codingLine[this.codingPos] < columns) {
  37019. code1 = 0;
  37020. if (blackPixels) {
  37021. do {
  37022. code1 += (code3 = this.getBlackCode());
  37023. } while (code3 >= 64);
  37024. } else {
  37025. do {
  37026. code1 += (code3 = this.getWhiteCode());
  37027. } while (code3 >= 64);
  37028. }
  37029. this.addPixels(codingLine[this.codingPos] + code1, blackPixels);
  37030. blackPixels ^= 1;
  37031. }
  37032. }
  37033. var gotEOL = false;
  37034. if (this.byteAlign) {
  37035. this.inputBits &= ~7;
  37036. }
  37037. if (!this.eoblock && this.row === this.rows - 1) {
  37038. this.eof = true;
  37039. } else {
  37040. code1 = this.lookBits(12);
  37041. if (this.eoline) {
  37042. while (code1 !== EOF && code1 !== 1) {
  37043. this.eatBits(1);
  37044. code1 = this.lookBits(12);
  37045. }
  37046. } else {
  37047. while (code1 === 0) {
  37048. this.eatBits(1);
  37049. code1 = this.lookBits(12);
  37050. }
  37051. }
  37052. if (code1 === 1) {
  37053. this.eatBits(12);
  37054. gotEOL = true;
  37055. } else if (code1 === EOF) {
  37056. this.eof = true;
  37057. }
  37058. }
  37059. if (!this.eof && this.encoding > 0) {
  37060. this.nextLine2D = !this.lookBits(1);
  37061. this.eatBits(1);
  37062. }
  37063. if (this.eoblock && gotEOL && this.byteAlign) {
  37064. code1 = this.lookBits(12);
  37065. if (code1 === 1) {
  37066. this.eatBits(12);
  37067. if (this.encoding > 0) {
  37068. this.lookBits(1);
  37069. this.eatBits(1);
  37070. }
  37071. if (this.encoding >= 0) {
  37072. for (i = 0; i < 4; ++i) {
  37073. code1 = this.lookBits(12);
  37074. if (code1 !== 1) {
  37075. info('bad rtc code: ' + code1);
  37076. }
  37077. this.eatBits(12);
  37078. if (this.encoding > 0) {
  37079. this.lookBits(1);
  37080. this.eatBits(1);
  37081. }
  37082. }
  37083. }
  37084. this.eof = true;
  37085. }
  37086. } else if (this.err && this.eoline) {
  37087. while (true) {
  37088. code1 = this.lookBits(13);
  37089. if (code1 === EOF) {
  37090. this.eof = true;
  37091. return null;
  37092. }
  37093. if ((code1 >> 1) === 1) {
  37094. break;
  37095. }
  37096. this.eatBits(1);
  37097. }
  37098. this.eatBits(12);
  37099. if (this.encoding > 0) {
  37100. this.eatBits(1);
  37101. this.nextLine2D = !(code1 & 1);
  37102. }
  37103. }
  37104. if (codingLine[0] > 0) {
  37105. this.outputBits = codingLine[this.codingPos = 0];
  37106. } else {
  37107. this.outputBits = codingLine[this.codingPos = 1];
  37108. }
  37109. this.row++;
  37110. }
  37111. var c;
  37112. if (this.outputBits >= 8) {
  37113. c = (this.codingPos & 1) ? 0 : 0xFF;
  37114. this.outputBits -= 8;
  37115. if (this.outputBits === 0 && codingLine[this.codingPos] < columns) {
  37116. this.codingPos++;
  37117. this.outputBits = (codingLine[this.codingPos] -
  37118. codingLine[this.codingPos - 1]);
  37119. }
  37120. } else {
  37121. bits = 8;
  37122. c = 0;
  37123. do {
  37124. if (this.outputBits > bits) {
  37125. c <<= bits;
  37126. if (!(this.codingPos & 1)) {
  37127. c |= 0xFF >> (8 - bits);
  37128. }
  37129. this.outputBits -= bits;
  37130. bits = 0;
  37131. } else {
  37132. c <<= this.outputBits;
  37133. if (!(this.codingPos & 1)) {
  37134. c |= 0xFF >> (8 - this.outputBits);
  37135. }
  37136. bits -= this.outputBits;
  37137. this.outputBits = 0;
  37138. if (codingLine[this.codingPos] < columns) {
  37139. this.codingPos++;
  37140. this.outputBits = (codingLine[this.codingPos] -
  37141. codingLine[this.codingPos - 1]);
  37142. } else if (bits > 0) {
  37143. c <<= bits;
  37144. bits = 0;
  37145. }
  37146. }
  37147. } while (bits);
  37148. }
  37149. if (this.black) {
  37150. c ^= 0xFF;
  37151. }
  37152. return c;
  37153. };
  37154. // This functions returns the code found from the table.
  37155. // The start and end parameters set the boundaries for searching the table.
  37156. // The limit parameter is optional. Function returns an array with three
  37157. // values. The first array element indicates whether a valid code is being
  37158. // returned. The second array element is the actual code. The third array
  37159. // element indicates whether EOF was reached.
  37160. CCITTFaxStream.prototype.findTableCode =
  37161. function ccittFaxStreamFindTableCode(start, end, table, limit) {
  37162. var limitValue = limit || 0;
  37163. for (var i = start; i <= end; ++i) {
  37164. var code = this.lookBits(i);
  37165. if (code === EOF) {
  37166. return [true, 1, false];
  37167. }
  37168. if (i < end) {
  37169. code <<= end - i;
  37170. }
  37171. if (!limitValue || code >= limitValue) {
  37172. var p = table[code - limitValue];
  37173. if (p[0] === i) {
  37174. this.eatBits(i);
  37175. return [true, p[1], true];
  37176. }
  37177. }
  37178. }
  37179. return [false, 0, false];
  37180. };
  37181. CCITTFaxStream.prototype.getTwoDimCode =
  37182. function ccittFaxStreamGetTwoDimCode() {
  37183. var code = 0;
  37184. var p;
  37185. if (this.eoblock) {
  37186. code = this.lookBits(7);
  37187. p = twoDimTable[code];
  37188. if (p && p[0] > 0) {
  37189. this.eatBits(p[0]);
  37190. return p[1];
  37191. }
  37192. } else {
  37193. var result = this.findTableCode(1, 7, twoDimTable);
  37194. if (result[0] && result[2]) {
  37195. return result[1];
  37196. }
  37197. }
  37198. info('Bad two dim code');
  37199. return EOF;
  37200. };
  37201. CCITTFaxStream.prototype.getWhiteCode =
  37202. function ccittFaxStreamGetWhiteCode() {
  37203. var code = 0;
  37204. var p;
  37205. if (this.eoblock) {
  37206. code = this.lookBits(12);
  37207. if (code === EOF) {
  37208. return 1;
  37209. }
  37210. if ((code >> 5) === 0) {
  37211. p = whiteTable1[code];
  37212. } else {
  37213. p = whiteTable2[code >> 3];
  37214. }
  37215. if (p[0] > 0) {
  37216. this.eatBits(p[0]);
  37217. return p[1];
  37218. }
  37219. } else {
  37220. var result = this.findTableCode(1, 9, whiteTable2);
  37221. if (result[0]) {
  37222. return result[1];
  37223. }
  37224. result = this.findTableCode(11, 12, whiteTable1);
  37225. if (result[0]) {
  37226. return result[1];
  37227. }
  37228. }
  37229. info('bad white code');
  37230. this.eatBits(1);
  37231. return 1;
  37232. };
  37233. CCITTFaxStream.prototype.getBlackCode =
  37234. function ccittFaxStreamGetBlackCode() {
  37235. var code, p;
  37236. if (this.eoblock) {
  37237. code = this.lookBits(13);
  37238. if (code === EOF) {
  37239. return 1;
  37240. }
  37241. if ((code >> 7) === 0) {
  37242. p = blackTable1[code];
  37243. } else if ((code >> 9) === 0 && (code >> 7) !== 0) {
  37244. p = blackTable2[(code >> 1) - 64];
  37245. } else {
  37246. p = blackTable3[code >> 7];
  37247. }
  37248. if (p[0] > 0) {
  37249. this.eatBits(p[0]);
  37250. return p[1];
  37251. }
  37252. } else {
  37253. var result = this.findTableCode(2, 6, blackTable3);
  37254. if (result[0]) {
  37255. return result[1];
  37256. }
  37257. result = this.findTableCode(7, 12, blackTable2, 64);
  37258. if (result[0]) {
  37259. return result[1];
  37260. }
  37261. result = this.findTableCode(10, 13, blackTable1);
  37262. if (result[0]) {
  37263. return result[1];
  37264. }
  37265. }
  37266. info('bad black code');
  37267. this.eatBits(1);
  37268. return 1;
  37269. };
  37270. CCITTFaxStream.prototype.lookBits = function CCITTFaxStream_lookBits(n) {
  37271. var c;
  37272. while (this.inputBits < n) {
  37273. if ((c = this.str.getByte()) === -1) {
  37274. if (this.inputBits === 0) {
  37275. return EOF;
  37276. }
  37277. return ((this.inputBuf << (n - this.inputBits)) &
  37278. (0xFFFF >> (16 - n)));
  37279. }
  37280. this.inputBuf = (this.inputBuf << 8) + c;
  37281. this.inputBits += 8;
  37282. }
  37283. return (this.inputBuf >> (this.inputBits - n)) & (0xFFFF >> (16 - n));
  37284. };
  37285. CCITTFaxStream.prototype.eatBits = function CCITTFaxStream_eatBits(n) {
  37286. if ((this.inputBits -= n) < 0) {
  37287. this.inputBits = 0;
  37288. }
  37289. };
  37290. return CCITTFaxStream;
  37291. })();
  37292. var LZWStream = (function LZWStreamClosure() {
  37293. function LZWStream(str, maybeLength, earlyChange) {
  37294. this.str = str;
  37295. this.dict = str.dict;
  37296. this.cachedData = 0;
  37297. this.bitsCached = 0;
  37298. var maxLzwDictionarySize = 4096;
  37299. var lzwState = {
  37300. earlyChange: earlyChange,
  37301. codeLength: 9,
  37302. nextCode: 258,
  37303. dictionaryValues: new Uint8Array(maxLzwDictionarySize),
  37304. dictionaryLengths: new Uint16Array(maxLzwDictionarySize),
  37305. dictionaryPrevCodes: new Uint16Array(maxLzwDictionarySize),
  37306. currentSequence: new Uint8Array(maxLzwDictionarySize),
  37307. currentSequenceLength: 0
  37308. };
  37309. for (var i = 0; i < 256; ++i) {
  37310. lzwState.dictionaryValues[i] = i;
  37311. lzwState.dictionaryLengths[i] = 1;
  37312. }
  37313. this.lzwState = lzwState;
  37314. DecodeStream.call(this, maybeLength);
  37315. }
  37316. LZWStream.prototype = Object.create(DecodeStream.prototype);
  37317. LZWStream.prototype.readBits = function LZWStream_readBits(n) {
  37318. var bitsCached = this.bitsCached;
  37319. var cachedData = this.cachedData;
  37320. while (bitsCached < n) {
  37321. var c = this.str.getByte();
  37322. if (c === -1) {
  37323. this.eof = true;
  37324. return null;
  37325. }
  37326. cachedData = (cachedData << 8) | c;
  37327. bitsCached += 8;
  37328. }
  37329. this.bitsCached = (bitsCached -= n);
  37330. this.cachedData = cachedData;
  37331. this.lastCode = null;
  37332. return (cachedData >>> bitsCached) & ((1 << n) - 1);
  37333. };
  37334. LZWStream.prototype.readBlock = function LZWStream_readBlock() {
  37335. var blockSize = 512;
  37336. var estimatedDecodedSize = blockSize * 2, decodedSizeDelta = blockSize;
  37337. var i, j, q;
  37338. var lzwState = this.lzwState;
  37339. if (!lzwState) {
  37340. return; // eof was found
  37341. }
  37342. var earlyChange = lzwState.earlyChange;
  37343. var nextCode = lzwState.nextCode;
  37344. var dictionaryValues = lzwState.dictionaryValues;
  37345. var dictionaryLengths = lzwState.dictionaryLengths;
  37346. var dictionaryPrevCodes = lzwState.dictionaryPrevCodes;
  37347. var codeLength = lzwState.codeLength;
  37348. var prevCode = lzwState.prevCode;
  37349. var currentSequence = lzwState.currentSequence;
  37350. var currentSequenceLength = lzwState.currentSequenceLength;
  37351. var decodedLength = 0;
  37352. var currentBufferLength = this.bufferLength;
  37353. var buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  37354. for (i = 0; i < blockSize; i++) {
  37355. var code = this.readBits(codeLength);
  37356. var hasPrev = currentSequenceLength > 0;
  37357. if (code < 256) {
  37358. currentSequence[0] = code;
  37359. currentSequenceLength = 1;
  37360. } else if (code >= 258) {
  37361. if (code < nextCode) {
  37362. currentSequenceLength = dictionaryLengths[code];
  37363. for (j = currentSequenceLength - 1, q = code; j >= 0; j--) {
  37364. currentSequence[j] = dictionaryValues[q];
  37365. q = dictionaryPrevCodes[q];
  37366. }
  37367. } else {
  37368. currentSequence[currentSequenceLength++] = currentSequence[0];
  37369. }
  37370. } else if (code === 256) {
  37371. codeLength = 9;
  37372. nextCode = 258;
  37373. currentSequenceLength = 0;
  37374. continue;
  37375. } else {
  37376. this.eof = true;
  37377. delete this.lzwState;
  37378. break;
  37379. }
  37380. if (hasPrev) {
  37381. dictionaryPrevCodes[nextCode] = prevCode;
  37382. dictionaryLengths[nextCode] = dictionaryLengths[prevCode] + 1;
  37383. dictionaryValues[nextCode] = currentSequence[0];
  37384. nextCode++;
  37385. codeLength = (nextCode + earlyChange) & (nextCode + earlyChange - 1) ?
  37386. codeLength : Math.min(Math.log(nextCode + earlyChange) /
  37387. 0.6931471805599453 + 1, 12) | 0;
  37388. }
  37389. prevCode = code;
  37390. decodedLength += currentSequenceLength;
  37391. if (estimatedDecodedSize < decodedLength) {
  37392. do {
  37393. estimatedDecodedSize += decodedSizeDelta;
  37394. } while (estimatedDecodedSize < decodedLength);
  37395. buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  37396. }
  37397. for (j = 0; j < currentSequenceLength; j++) {
  37398. buffer[currentBufferLength++] = currentSequence[j];
  37399. }
  37400. }
  37401. lzwState.nextCode = nextCode;
  37402. lzwState.codeLength = codeLength;
  37403. lzwState.prevCode = prevCode;
  37404. lzwState.currentSequenceLength = currentSequenceLength;
  37405. this.bufferLength = currentBufferLength;
  37406. };
  37407. return LZWStream;
  37408. })();
  37409. var NullStream = (function NullStreamClosure() {
  37410. function NullStream() {
  37411. Stream.call(this, new Uint8Array(0));
  37412. }
  37413. NullStream.prototype = Stream.prototype;
  37414. return NullStream;
  37415. })();
  37416. var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
  37417. setup: function wphSetup(handler) {
  37418. var pdfManager;
  37419. function loadDocument(recoveryMode) {
  37420. var loadDocumentCapability = createPromiseCapability();
  37421. var parseSuccess = function parseSuccess() {
  37422. var numPagesPromise = pdfManager.ensureDoc('numPages');
  37423. var fingerprintPromise = pdfManager.ensureDoc('fingerprint');
  37424. var encryptedPromise = pdfManager.ensureXRef('encrypt');
  37425. Promise.all([numPagesPromise, fingerprintPromise,
  37426. encryptedPromise]).then(function onDocReady(results) {
  37427. var doc = {
  37428. numPages: results[0],
  37429. fingerprint: results[1],
  37430. encrypted: !!results[2],
  37431. };
  37432. loadDocumentCapability.resolve(doc);
  37433. },
  37434. parseFailure);
  37435. };
  37436. var parseFailure = function parseFailure(e) {
  37437. loadDocumentCapability.reject(e);
  37438. };
  37439. pdfManager.ensureDoc('checkHeader', []).then(function() {
  37440. pdfManager.ensureDoc('parseStartXRef', []).then(function() {
  37441. pdfManager.ensureDoc('parse', [recoveryMode]).then(
  37442. parseSuccess, parseFailure);
  37443. }, parseFailure);
  37444. }, parseFailure);
  37445. return loadDocumentCapability.promise;
  37446. }
  37447. function getPdfManager(data) {
  37448. var pdfManagerCapability = createPromiseCapability();
  37449. var source = data.source;
  37450. var disableRange = data.disableRange;
  37451. if (source.data) {
  37452. try {
  37453. pdfManager = new LocalPdfManager(source.data, source.password);
  37454. pdfManagerCapability.resolve();
  37455. } catch (ex) {
  37456. pdfManagerCapability.reject(ex);
  37457. }
  37458. return pdfManagerCapability.promise;
  37459. } else if (source.chunkedViewerLoading) {
  37460. try {
  37461. pdfManager = new NetworkPdfManager(source, handler);
  37462. pdfManagerCapability.resolve();
  37463. } catch (ex) {
  37464. pdfManagerCapability.reject(ex);
  37465. }
  37466. return pdfManagerCapability.promise;
  37467. }
  37468. var networkManager = new NetworkManager(source.url, {
  37469. httpHeaders: source.httpHeaders,
  37470. withCredentials: source.withCredentials
  37471. });
  37472. var cachedChunks = [];
  37473. var fullRequestXhrId = networkManager.requestFull({
  37474. onHeadersReceived: function onHeadersReceived() {
  37475. if (disableRange) {
  37476. return;
  37477. }
  37478. var fullRequestXhr = networkManager.getRequestXhr(fullRequestXhrId);
  37479. if (fullRequestXhr.getResponseHeader('Accept-Ranges') !== 'bytes') {
  37480. return;
  37481. }
  37482. var contentEncoding =
  37483. fullRequestXhr.getResponseHeader('Content-Encoding') || 'identity';
  37484. if (contentEncoding !== 'identity') {
  37485. return;
  37486. }
  37487. var length = fullRequestXhr.getResponseHeader('Content-Length');
  37488. length = parseInt(length, 10);
  37489. if (!isInt(length)) {
  37490. return;
  37491. }
  37492. source.length = length;
  37493. if (length <= 2 * RANGE_CHUNK_SIZE) {
  37494. // The file size is smaller than the size of two chunks, so it does
  37495. // not make any sense to abort the request and retry with a range
  37496. // request.
  37497. return;
  37498. }
  37499. if (networkManager.isStreamingRequest(fullRequestXhrId)) {
  37500. // We can continue fetching when progressive loading is enabled,
  37501. // and we don't need the autoFetch feature.
  37502. source.disableAutoFetch = true;
  37503. } else {
  37504. // NOTE: by cancelling the full request, and then issuing range
  37505. // requests, there will be an issue for sites where you can only
  37506. // request the pdf once. However, if this is the case, then the
  37507. // server should not be returning that it can support range
  37508. // requests.
  37509. networkManager.abortRequest(fullRequestXhrId);
  37510. }
  37511. try {
  37512. pdfManager = new NetworkPdfManager(source, handler);
  37513. pdfManagerCapability.resolve(pdfManager);
  37514. } catch (ex) {
  37515. pdfManagerCapability.reject(ex);
  37516. }
  37517. },
  37518. onProgressiveData: source.disableStream ? null :
  37519. function onProgressiveData(chunk) {
  37520. if (!pdfManager) {
  37521. cachedChunks.push(chunk);
  37522. return;
  37523. }
  37524. pdfManager.sendProgressiveData(chunk);
  37525. },
  37526. onDone: function onDone(args) {
  37527. if (pdfManager) {
  37528. return; // already processed
  37529. }
  37530. var pdfFile;
  37531. if (args === null) {
  37532. // TODO add some streaming manager, e.g. for unknown length files.
  37533. // The data was returned in the onProgressiveData, combining...
  37534. var pdfFileLength = 0, pos = 0;
  37535. cachedChunks.forEach(function (chunk) {
  37536. pdfFileLength += chunk.byteLength;
  37537. });
  37538. if (source.length && pdfFileLength !== source.length) {
  37539. warn('reported HTTP length is different from actual');
  37540. }
  37541. var pdfFileArray = new Uint8Array(pdfFileLength);
  37542. cachedChunks.forEach(function (chunk) {
  37543. pdfFileArray.set(new Uint8Array(chunk), pos);
  37544. pos += chunk.byteLength;
  37545. });
  37546. pdfFile = pdfFileArray.buffer;
  37547. } else {
  37548. pdfFile = args.chunk;
  37549. }
  37550. // the data is array, instantiating directly from it
  37551. try {
  37552. pdfManager = new LocalPdfManager(pdfFile, source.password);
  37553. pdfManagerCapability.resolve();
  37554. } catch (ex) {
  37555. pdfManagerCapability.reject(ex);
  37556. }
  37557. },
  37558. onError: function onError(status) {
  37559. var exception;
  37560. if (status === 404) {
  37561. exception = new MissingPDFException('Missing PDF "' +
  37562. source.url + '".');
  37563. handler.send('MissingPDF', exception);
  37564. } else {
  37565. exception = new UnexpectedResponseException(
  37566. 'Unexpected server response (' + status +
  37567. ') while retrieving PDF "' + source.url + '".', status);
  37568. handler.send('UnexpectedResponse', exception);
  37569. }
  37570. },
  37571. onProgress: function onProgress(evt) {
  37572. handler.send('DocProgress', {
  37573. loaded: evt.loaded,
  37574. total: evt.lengthComputable ? evt.total : source.length
  37575. });
  37576. }
  37577. });
  37578. return pdfManagerCapability.promise;
  37579. }
  37580. handler.on('test', function wphSetupTest(data) {
  37581. // check if Uint8Array can be sent to worker
  37582. if (!(data instanceof Uint8Array)) {
  37583. handler.send('test', false);
  37584. return;
  37585. }
  37586. // making sure postMessage transfers are working
  37587. var supportTransfers = data[0] === 255;
  37588. handler.postMessageTransfers = supportTransfers;
  37589. // check if the response property is supported by xhr
  37590. var xhr = new XMLHttpRequest();
  37591. var responseExists = 'response' in xhr;
  37592. // check if the property is actually implemented
  37593. try {
  37594. var dummy = xhr.responseType;
  37595. } catch (e) {
  37596. responseExists = false;
  37597. }
  37598. if (!responseExists) {
  37599. handler.send('test', false);
  37600. return;
  37601. }
  37602. handler.send('test', {
  37603. supportTypedArray: true,
  37604. supportTransfers: supportTransfers
  37605. });
  37606. });
  37607. handler.on('GetDocRequest', function wphSetupDoc(data) {
  37608. var onSuccess = function(doc) {
  37609. handler.send('GetDoc', { pdfInfo: doc });
  37610. };
  37611. var onFailure = function(e) {
  37612. if (e instanceof PasswordException) {
  37613. if (e.code === PasswordResponses.NEED_PASSWORD) {
  37614. handler.send('NeedPassword', e);
  37615. } else if (e.code === PasswordResponses.INCORRECT_PASSWORD) {
  37616. handler.send('IncorrectPassword', e);
  37617. }
  37618. } else if (e instanceof InvalidPDFException) {
  37619. handler.send('InvalidPDF', e);
  37620. } else if (e instanceof MissingPDFException) {
  37621. handler.send('MissingPDF', e);
  37622. } else if (e instanceof UnexpectedResponseException) {
  37623. handler.send('UnexpectedResponse', e);
  37624. } else {
  37625. handler.send('UnknownError',
  37626. new UnknownErrorException(e.message, e.toString()));
  37627. }
  37628. };
  37629. PDFJS.maxImageSize = data.maxImageSize === undefined ?
  37630. -1 : data.maxImageSize;
  37631. PDFJS.disableFontFace = data.disableFontFace;
  37632. PDFJS.disableCreateObjectURL = data.disableCreateObjectURL;
  37633. PDFJS.verbosity = data.verbosity;
  37634. PDFJS.cMapUrl = data.cMapUrl === undefined ?
  37635. null : data.cMapUrl;
  37636. PDFJS.cMapPacked = data.cMapPacked === true;
  37637. getPdfManager(data).then(function () {
  37638. handler.send('PDFManagerReady', null);
  37639. pdfManager.onLoadedStream().then(function(stream) {
  37640. handler.send('DataLoaded', { length: stream.bytes.byteLength });
  37641. });
  37642. }).then(function pdfManagerReady() {
  37643. loadDocument(false).then(onSuccess, function loadFailure(ex) {
  37644. // Try again with recoveryMode == true
  37645. if (!(ex instanceof XRefParseException)) {
  37646. if (ex instanceof PasswordException) {
  37647. // after password exception prepare to receive a new password
  37648. // to repeat loading
  37649. pdfManager.passwordChanged().then(pdfManagerReady);
  37650. }
  37651. onFailure(ex);
  37652. return;
  37653. }
  37654. pdfManager.requestLoadedStream();
  37655. pdfManager.onLoadedStream().then(function() {
  37656. loadDocument(true).then(onSuccess, onFailure);
  37657. });
  37658. }, onFailure);
  37659. }, onFailure);
  37660. });
  37661. handler.on('GetPage', function wphSetupGetPage(data) {
  37662. return pdfManager.getPage(data.pageIndex).then(function(page) {
  37663. var rotatePromise = pdfManager.ensure(page, 'rotate');
  37664. var refPromise = pdfManager.ensure(page, 'ref');
  37665. var viewPromise = pdfManager.ensure(page, 'view');
  37666. return Promise.all([rotatePromise, refPromise, viewPromise]).then(
  37667. function(results) {
  37668. return {
  37669. rotate: results[0],
  37670. ref: results[1],
  37671. view: results[2]
  37672. };
  37673. });
  37674. });
  37675. });
  37676. handler.on('GetPageIndex', function wphSetupGetPageIndex(data) {
  37677. var ref = new Ref(data.ref.num, data.ref.gen);
  37678. var catalog = pdfManager.pdfDocument.catalog;
  37679. return catalog.getPageIndex(ref);
  37680. });
  37681. handler.on('GetDestinations',
  37682. function wphSetupGetDestinations(data) {
  37683. return pdfManager.ensureCatalog('destinations');
  37684. }
  37685. );
  37686. handler.on('GetDestination',
  37687. function wphSetupGetDestination(data) {
  37688. return pdfManager.ensureCatalog('getDestination', [ data.id ]);
  37689. }
  37690. );
  37691. handler.on('GetAttachments',
  37692. function wphSetupGetAttachments(data) {
  37693. return pdfManager.ensureCatalog('attachments');
  37694. }
  37695. );
  37696. handler.on('GetJavaScript',
  37697. function wphSetupGetJavaScript(data) {
  37698. return pdfManager.ensureCatalog('javaScript');
  37699. }
  37700. );
  37701. handler.on('GetOutline',
  37702. function wphSetupGetOutline(data) {
  37703. return pdfManager.ensureCatalog('documentOutline');
  37704. }
  37705. );
  37706. handler.on('GetMetadata',
  37707. function wphSetupGetMetadata(data) {
  37708. return Promise.all([pdfManager.ensureDoc('documentInfo'),
  37709. pdfManager.ensureCatalog('metadata')]);
  37710. }
  37711. );
  37712. handler.on('GetData', function wphSetupGetData(data) {
  37713. pdfManager.requestLoadedStream();
  37714. return pdfManager.onLoadedStream().then(function(stream) {
  37715. return stream.bytes;
  37716. });
  37717. });
  37718. handler.on('GetStats',
  37719. function wphSetupGetStats(data) {
  37720. return pdfManager.pdfDocument.xref.stats;
  37721. }
  37722. );
  37723. handler.on('UpdatePassword', function wphSetupUpdatePassword(data) {
  37724. pdfManager.updatePassword(data);
  37725. });
  37726. handler.on('GetAnnotations', function wphSetupGetAnnotations(data) {
  37727. return pdfManager.getPage(data.pageIndex).then(function(page) {
  37728. return pdfManager.ensure(page, 'getAnnotationsData', []);
  37729. });
  37730. });
  37731. handler.on('RenderPageRequest', function wphSetupRenderPage(data) {
  37732. pdfManager.getPage(data.pageIndex).then(function(page) {
  37733. var pageNum = data.pageIndex + 1;
  37734. var start = Date.now();
  37735. // Pre compile the pdf page and fetch the fonts/images.
  37736. page.getOperatorList(handler, data.intent).then(function(operatorList) {
  37737. info('page=' + pageNum + ' - getOperatorList: time=' +
  37738. (Date.now() - start) + 'ms, len=' + operatorList.fnArray.length);
  37739. }, function(e) {
  37740. var minimumStackMessage =
  37741. 'worker.js: while trying to getPage() and getOperatorList()';
  37742. var wrappedException;
  37743. // Turn the error into an obj that can be serialized
  37744. if (typeof e === 'string') {
  37745. wrappedException = {
  37746. message: e,
  37747. stack: minimumStackMessage
  37748. };
  37749. } else if (typeof e === 'object') {
  37750. wrappedException = {
  37751. message: e.message || e.toString(),
  37752. stack: e.stack || minimumStackMessage
  37753. };
  37754. } else {
  37755. wrappedException = {
  37756. message: 'Unknown exception type: ' + (typeof e),
  37757. stack: minimumStackMessage
  37758. };
  37759. }
  37760. handler.send('PageError', {
  37761. pageNum: pageNum,
  37762. error: wrappedException,
  37763. intent: data.intent
  37764. });
  37765. });
  37766. });
  37767. }, this);
  37768. handler.on('GetTextContent', function wphExtractText(data) {
  37769. return pdfManager.getPage(data.pageIndex).then(function(page) {
  37770. var pageNum = data.pageIndex + 1;
  37771. var start = Date.now();
  37772. return page.extractTextContent().then(function(textContent) {
  37773. info('text indexing: page=' + pageNum + ' - time=' +
  37774. (Date.now() - start) + 'ms');
  37775. return textContent;
  37776. });
  37777. });
  37778. });
  37779. handler.on('Cleanup', function wphCleanup(data) {
  37780. return pdfManager.cleanup();
  37781. });
  37782. handler.on('Terminate', function wphTerminate(data) {
  37783. pdfManager.terminate();
  37784. });
  37785. }
  37786. };
  37787. var consoleTimer = {};
  37788. var workerConsole = {
  37789. log: function log() {
  37790. var args = Array.prototype.slice.call(arguments);
  37791. globalScope.postMessage({
  37792. action: 'console_log',
  37793. data: args
  37794. });
  37795. },
  37796. error: function error() {
  37797. var args = Array.prototype.slice.call(arguments);
  37798. globalScope.postMessage({
  37799. action: 'console_error',
  37800. data: args
  37801. });
  37802. throw 'pdf.js execution error';
  37803. },
  37804. time: function time(name) {
  37805. consoleTimer[name] = Date.now();
  37806. },
  37807. timeEnd: function timeEnd(name) {
  37808. var time = consoleTimer[name];
  37809. if (!time) {
  37810. error('Unknown timer name ' + name);
  37811. }
  37812. this.log('Timer:', name, Date.now() - time);
  37813. }
  37814. };
  37815. // Worker thread?
  37816. if (typeof window === 'undefined') {
  37817. if (!('console' in globalScope)) {
  37818. globalScope.console = workerConsole;
  37819. }
  37820. // Listen for unsupported features so we can pass them on to the main thread.
  37821. PDFJS.UnsupportedManager.listen(function (msg) {
  37822. globalScope.postMessage({
  37823. action: '_unsupported_feature',
  37824. data: msg
  37825. });
  37826. });
  37827. var handler = new MessageHandler('worker_processor', this);
  37828. WorkerMessageHandler.setup(handler);
  37829. }
  37830. /* This class implements the QM Coder decoding as defined in
  37831. * JPEG 2000 Part I Final Committee Draft Version 1.0
  37832. * Annex C.3 Arithmetic decoding procedure
  37833. * available at http://www.jpeg.org/public/fcd15444-1.pdf
  37834. *
  37835. * The arithmetic decoder is used in conjunction with context models to decode
  37836. * JPEG2000 and JBIG2 streams.
  37837. */
  37838. var ArithmeticDecoder = (function ArithmeticDecoderClosure() {
  37839. // Table C-2
  37840. var QeTable = [
  37841. {qe: 0x5601, nmps: 1, nlps: 1, switchFlag: 1},
  37842. {qe: 0x3401, nmps: 2, nlps: 6, switchFlag: 0},
  37843. {qe: 0x1801, nmps: 3, nlps: 9, switchFlag: 0},
  37844. {qe: 0x0AC1, nmps: 4, nlps: 12, switchFlag: 0},
  37845. {qe: 0x0521, nmps: 5, nlps: 29, switchFlag: 0},
  37846. {qe: 0x0221, nmps: 38, nlps: 33, switchFlag: 0},
  37847. {qe: 0x5601, nmps: 7, nlps: 6, switchFlag: 1},
  37848. {qe: 0x5401, nmps: 8, nlps: 14, switchFlag: 0},
  37849. {qe: 0x4801, nmps: 9, nlps: 14, switchFlag: 0},
  37850. {qe: 0x3801, nmps: 10, nlps: 14, switchFlag: 0},
  37851. {qe: 0x3001, nmps: 11, nlps: 17, switchFlag: 0},
  37852. {qe: 0x2401, nmps: 12, nlps: 18, switchFlag: 0},
  37853. {qe: 0x1C01, nmps: 13, nlps: 20, switchFlag: 0},
  37854. {qe: 0x1601, nmps: 29, nlps: 21, switchFlag: 0},
  37855. {qe: 0x5601, nmps: 15, nlps: 14, switchFlag: 1},
  37856. {qe: 0x5401, nmps: 16, nlps: 14, switchFlag: 0},
  37857. {qe: 0x5101, nmps: 17, nlps: 15, switchFlag: 0},
  37858. {qe: 0x4801, nmps: 18, nlps: 16, switchFlag: 0},
  37859. {qe: 0x3801, nmps: 19, nlps: 17, switchFlag: 0},
  37860. {qe: 0x3401, nmps: 20, nlps: 18, switchFlag: 0},
  37861. {qe: 0x3001, nmps: 21, nlps: 19, switchFlag: 0},
  37862. {qe: 0x2801, nmps: 22, nlps: 19, switchFlag: 0},
  37863. {qe: 0x2401, nmps: 23, nlps: 20, switchFlag: 0},
  37864. {qe: 0x2201, nmps: 24, nlps: 21, switchFlag: 0},
  37865. {qe: 0x1C01, nmps: 25, nlps: 22, switchFlag: 0},
  37866. {qe: 0x1801, nmps: 26, nlps: 23, switchFlag: 0},
  37867. {qe: 0x1601, nmps: 27, nlps: 24, switchFlag: 0},
  37868. {qe: 0x1401, nmps: 28, nlps: 25, switchFlag: 0},
  37869. {qe: 0x1201, nmps: 29, nlps: 26, switchFlag: 0},
  37870. {qe: 0x1101, nmps: 30, nlps: 27, switchFlag: 0},
  37871. {qe: 0x0AC1, nmps: 31, nlps: 28, switchFlag: 0},
  37872. {qe: 0x09C1, nmps: 32, nlps: 29, switchFlag: 0},
  37873. {qe: 0x08A1, nmps: 33, nlps: 30, switchFlag: 0},
  37874. {qe: 0x0521, nmps: 34, nlps: 31, switchFlag: 0},
  37875. {qe: 0x0441, nmps: 35, nlps: 32, switchFlag: 0},
  37876. {qe: 0x02A1, nmps: 36, nlps: 33, switchFlag: 0},
  37877. {qe: 0x0221, nmps: 37, nlps: 34, switchFlag: 0},
  37878. {qe: 0x0141, nmps: 38, nlps: 35, switchFlag: 0},
  37879. {qe: 0x0111, nmps: 39, nlps: 36, switchFlag: 0},
  37880. {qe: 0x0085, nmps: 40, nlps: 37, switchFlag: 0},
  37881. {qe: 0x0049, nmps: 41, nlps: 38, switchFlag: 0},
  37882. {qe: 0x0025, nmps: 42, nlps: 39, switchFlag: 0},
  37883. {qe: 0x0015, nmps: 43, nlps: 40, switchFlag: 0},
  37884. {qe: 0x0009, nmps: 44, nlps: 41, switchFlag: 0},
  37885. {qe: 0x0005, nmps: 45, nlps: 42, switchFlag: 0},
  37886. {qe: 0x0001, nmps: 45, nlps: 43, switchFlag: 0},
  37887. {qe: 0x5601, nmps: 46, nlps: 46, switchFlag: 0}
  37888. ];
  37889. // C.3.5 Initialisation of the decoder (INITDEC)
  37890. function ArithmeticDecoder(data, start, end) {
  37891. this.data = data;
  37892. this.bp = start;
  37893. this.dataEnd = end;
  37894. this.chigh = data[start];
  37895. this.clow = 0;
  37896. this.byteIn();
  37897. this.chigh = ((this.chigh << 7) & 0xFFFF) | ((this.clow >> 9) & 0x7F);
  37898. this.clow = (this.clow << 7) & 0xFFFF;
  37899. this.ct -= 7;
  37900. this.a = 0x8000;
  37901. }
  37902. ArithmeticDecoder.prototype = {
  37903. // C.3.4 Compressed data input (BYTEIN)
  37904. byteIn: function ArithmeticDecoder_byteIn() {
  37905. var data = this.data;
  37906. var bp = this.bp;
  37907. if (data[bp] === 0xFF) {
  37908. var b1 = data[bp + 1];
  37909. if (b1 > 0x8F) {
  37910. this.clow += 0xFF00;
  37911. this.ct = 8;
  37912. } else {
  37913. bp++;
  37914. this.clow += (data[bp] << 9);
  37915. this.ct = 7;
  37916. this.bp = bp;
  37917. }
  37918. } else {
  37919. bp++;
  37920. this.clow += bp < this.dataEnd ? (data[bp] << 8) : 0xFF00;
  37921. this.ct = 8;
  37922. this.bp = bp;
  37923. }
  37924. if (this.clow > 0xFFFF) {
  37925. this.chigh += (this.clow >> 16);
  37926. this.clow &= 0xFFFF;
  37927. }
  37928. },
  37929. // C.3.2 Decoding a decision (DECODE)
  37930. readBit: function ArithmeticDecoder_readBit(contexts, pos) {
  37931. // contexts are packed into 1 byte:
  37932. // highest 7 bits carry cx.index, lowest bit carries cx.mps
  37933. var cx_index = contexts[pos] >> 1, cx_mps = contexts[pos] & 1;
  37934. var qeTableIcx = QeTable[cx_index];
  37935. var qeIcx = qeTableIcx.qe;
  37936. var d;
  37937. var a = this.a - qeIcx;
  37938. if (this.chigh < qeIcx) {
  37939. // exchangeLps
  37940. if (a < qeIcx) {
  37941. a = qeIcx;
  37942. d = cx_mps;
  37943. cx_index = qeTableIcx.nmps;
  37944. } else {
  37945. a = qeIcx;
  37946. d = 1 ^ cx_mps;
  37947. if (qeTableIcx.switchFlag === 1) {
  37948. cx_mps = d;
  37949. }
  37950. cx_index = qeTableIcx.nlps;
  37951. }
  37952. } else {
  37953. this.chigh -= qeIcx;
  37954. if ((a & 0x8000) !== 0) {
  37955. this.a = a;
  37956. return cx_mps;
  37957. }
  37958. // exchangeMps
  37959. if (a < qeIcx) {
  37960. d = 1 ^ cx_mps;
  37961. if (qeTableIcx.switchFlag === 1) {
  37962. cx_mps = d;
  37963. }
  37964. cx_index = qeTableIcx.nlps;
  37965. } else {
  37966. d = cx_mps;
  37967. cx_index = qeTableIcx.nmps;
  37968. }
  37969. }
  37970. // C.3.3 renormD;
  37971. do {
  37972. if (this.ct === 0) {
  37973. this.byteIn();
  37974. }
  37975. a <<= 1;
  37976. this.chigh = ((this.chigh << 1) & 0xFFFF) | ((this.clow >> 15) & 1);
  37977. this.clow = (this.clow << 1) & 0xFFFF;
  37978. this.ct--;
  37979. } while ((a & 0x8000) === 0);
  37980. this.a = a;
  37981. contexts[pos] = cx_index << 1 | cx_mps;
  37982. return d;
  37983. }
  37984. };
  37985. return ArithmeticDecoder;
  37986. })();
  37987. var JpegImage = (function jpegImage() {
  37988. var dctZigZag = new Uint8Array([
  37989. 0,
  37990. 1, 8,
  37991. 16, 9, 2,
  37992. 3, 10, 17, 24,
  37993. 32, 25, 18, 11, 4,
  37994. 5, 12, 19, 26, 33, 40,
  37995. 48, 41, 34, 27, 20, 13, 6,
  37996. 7, 14, 21, 28, 35, 42, 49, 56,
  37997. 57, 50, 43, 36, 29, 22, 15,
  37998. 23, 30, 37, 44, 51, 58,
  37999. 59, 52, 45, 38, 31,
  38000. 39, 46, 53, 60,
  38001. 61, 54, 47,
  38002. 55, 62,
  38003. 63
  38004. ]);
  38005. var dctCos1 = 4017; // cos(pi/16)
  38006. var dctSin1 = 799; // sin(pi/16)
  38007. var dctCos3 = 3406; // cos(3*pi/16)
  38008. var dctSin3 = 2276; // sin(3*pi/16)
  38009. var dctCos6 = 1567; // cos(6*pi/16)
  38010. var dctSin6 = 3784; // sin(6*pi/16)
  38011. var dctSqrt2 = 5793; // sqrt(2)
  38012. var dctSqrt1d2 = 2896; // sqrt(2) / 2
  38013. function constructor() {
  38014. }
  38015. function buildHuffmanTable(codeLengths, values) {
  38016. var k = 0, code = [], i, j, length = 16;
  38017. while (length > 0 && !codeLengths[length - 1]) {
  38018. length--;
  38019. }
  38020. code.push({children: [], index: 0});
  38021. var p = code[0], q;
  38022. for (i = 0; i < length; i++) {
  38023. for (j = 0; j < codeLengths[i]; j++) {
  38024. p = code.pop();
  38025. p.children[p.index] = values[k];
  38026. while (p.index > 0) {
  38027. p = code.pop();
  38028. }
  38029. p.index++;
  38030. code.push(p);
  38031. while (code.length <= i) {
  38032. code.push(q = {children: [], index: 0});
  38033. p.children[p.index] = q.children;
  38034. p = q;
  38035. }
  38036. k++;
  38037. }
  38038. if (i + 1 < length) {
  38039. // p here points to last code
  38040. code.push(q = {children: [], index: 0});
  38041. p.children[p.index] = q.children;
  38042. p = q;
  38043. }
  38044. }
  38045. return code[0].children;
  38046. }
  38047. function getBlockBufferOffset(component, row, col) {
  38048. return 64 * ((component.blocksPerLine + 1) * row + col);
  38049. }
  38050. function decodeScan(data, offset, frame, components, resetInterval,
  38051. spectralStart, spectralEnd, successivePrev, successive) {
  38052. var precision = frame.precision;
  38053. var samplesPerLine = frame.samplesPerLine;
  38054. var scanLines = frame.scanLines;
  38055. var mcusPerLine = frame.mcusPerLine;
  38056. var progressive = frame.progressive;
  38057. var maxH = frame.maxH, maxV = frame.maxV;
  38058. var startOffset = offset, bitsData = 0, bitsCount = 0;
  38059. function readBit() {
  38060. if (bitsCount > 0) {
  38061. bitsCount--;
  38062. return (bitsData >> bitsCount) & 1;
  38063. }
  38064. bitsData = data[offset++];
  38065. if (bitsData === 0xFF) {
  38066. var nextByte = data[offset++];
  38067. if (nextByte) {
  38068. throw 'unexpected marker: ' +
  38069. ((bitsData << 8) | nextByte).toString(16);
  38070. }
  38071. // unstuff 0
  38072. }
  38073. bitsCount = 7;
  38074. return bitsData >>> 7;
  38075. }
  38076. function decodeHuffman(tree) {
  38077. var node = tree;
  38078. while (true) {
  38079. node = node[readBit()];
  38080. if (typeof node === 'number') {
  38081. return node;
  38082. }
  38083. if (typeof node !== 'object') {
  38084. throw 'invalid huffman sequence';
  38085. }
  38086. }
  38087. }
  38088. function receive(length) {
  38089. var n = 0;
  38090. while (length > 0) {
  38091. n = (n << 1) | readBit();
  38092. length--;
  38093. }
  38094. return n;
  38095. }
  38096. function receiveAndExtend(length) {
  38097. if (length === 1) {
  38098. return readBit() === 1 ? 1 : -1;
  38099. }
  38100. var n = receive(length);
  38101. if (n >= 1 << (length - 1)) {
  38102. return n;
  38103. }
  38104. return n + (-1 << length) + 1;
  38105. }
  38106. function decodeBaseline(component, offset) {
  38107. var t = decodeHuffman(component.huffmanTableDC);
  38108. var diff = t === 0 ? 0 : receiveAndExtend(t);
  38109. component.blockData[offset] = (component.pred += diff);
  38110. var k = 1;
  38111. while (k < 64) {
  38112. var rs = decodeHuffman(component.huffmanTableAC);
  38113. var s = rs & 15, r = rs >> 4;
  38114. if (s === 0) {
  38115. if (r < 15) {
  38116. break;
  38117. }
  38118. k += 16;
  38119. continue;
  38120. }
  38121. k += r;
  38122. var z = dctZigZag[k];
  38123. component.blockData[offset + z] = receiveAndExtend(s);
  38124. k++;
  38125. }
  38126. }
  38127. function decodeDCFirst(component, offset) {
  38128. var t = decodeHuffman(component.huffmanTableDC);
  38129. var diff = t === 0 ? 0 : (receiveAndExtend(t) << successive);
  38130. component.blockData[offset] = (component.pred += diff);
  38131. }
  38132. function decodeDCSuccessive(component, offset) {
  38133. component.blockData[offset] |= readBit() << successive;
  38134. }
  38135. var eobrun = 0;
  38136. function decodeACFirst(component, offset) {
  38137. if (eobrun > 0) {
  38138. eobrun--;
  38139. return;
  38140. }
  38141. var k = spectralStart, e = spectralEnd;
  38142. while (k <= e) {
  38143. var rs = decodeHuffman(component.huffmanTableAC);
  38144. var s = rs & 15, r = rs >> 4;
  38145. if (s === 0) {
  38146. if (r < 15) {
  38147. eobrun = receive(r) + (1 << r) - 1;
  38148. break;
  38149. }
  38150. k += 16;
  38151. continue;
  38152. }
  38153. k += r;
  38154. var z = dctZigZag[k];
  38155. component.blockData[offset + z] =
  38156. receiveAndExtend(s) * (1 << successive);
  38157. k++;
  38158. }
  38159. }
  38160. var successiveACState = 0, successiveACNextValue;
  38161. function decodeACSuccessive(component, offset) {
  38162. var k = spectralStart;
  38163. var e = spectralEnd;
  38164. var r = 0;
  38165. var s;
  38166. var rs;
  38167. while (k <= e) {
  38168. var z = dctZigZag[k];
  38169. switch (successiveACState) {
  38170. case 0: // initial state
  38171. rs = decodeHuffman(component.huffmanTableAC);
  38172. s = rs & 15;
  38173. r = rs >> 4;
  38174. if (s === 0) {
  38175. if (r < 15) {
  38176. eobrun = receive(r) + (1 << r);
  38177. successiveACState = 4;
  38178. } else {
  38179. r = 16;
  38180. successiveACState = 1;
  38181. }
  38182. } else {
  38183. if (s !== 1) {
  38184. throw 'invalid ACn encoding';
  38185. }
  38186. successiveACNextValue = receiveAndExtend(s);
  38187. successiveACState = r ? 2 : 3;
  38188. }
  38189. continue;
  38190. case 1: // skipping r zero items
  38191. case 2:
  38192. if (component.blockData[offset + z]) {
  38193. component.blockData[offset + z] += (readBit() << successive);
  38194. } else {
  38195. r--;
  38196. if (r === 0) {
  38197. successiveACState = successiveACState === 2 ? 3 : 0;
  38198. }
  38199. }
  38200. break;
  38201. case 3: // set value for a zero item
  38202. if (component.blockData[offset + z]) {
  38203. component.blockData[offset + z] += (readBit() << successive);
  38204. } else {
  38205. component.blockData[offset + z] =
  38206. successiveACNextValue << successive;
  38207. successiveACState = 0;
  38208. }
  38209. break;
  38210. case 4: // eob
  38211. if (component.blockData[offset + z]) {
  38212. component.blockData[offset + z] += (readBit() << successive);
  38213. }
  38214. break;
  38215. }
  38216. k++;
  38217. }
  38218. if (successiveACState === 4) {
  38219. eobrun--;
  38220. if (eobrun === 0) {
  38221. successiveACState = 0;
  38222. }
  38223. }
  38224. }
  38225. function decodeMcu(component, decode, mcu, row, col) {
  38226. var mcuRow = (mcu / mcusPerLine) | 0;
  38227. var mcuCol = mcu % mcusPerLine;
  38228. var blockRow = mcuRow * component.v + row;
  38229. var blockCol = mcuCol * component.h + col;
  38230. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  38231. decode(component, offset);
  38232. }
  38233. function decodeBlock(component, decode, mcu) {
  38234. var blockRow = (mcu / component.blocksPerLine) | 0;
  38235. var blockCol = mcu % component.blocksPerLine;
  38236. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  38237. decode(component, offset);
  38238. }
  38239. var componentsLength = components.length;
  38240. var component, i, j, k, n;
  38241. var decodeFn;
  38242. if (progressive) {
  38243. if (spectralStart === 0) {
  38244. decodeFn = successivePrev === 0 ? decodeDCFirst : decodeDCSuccessive;
  38245. } else {
  38246. decodeFn = successivePrev === 0 ? decodeACFirst : decodeACSuccessive;
  38247. }
  38248. } else {
  38249. decodeFn = decodeBaseline;
  38250. }
  38251. var mcu = 0, marker;
  38252. var mcuExpected;
  38253. if (componentsLength === 1) {
  38254. mcuExpected = components[0].blocksPerLine * components[0].blocksPerColumn;
  38255. } else {
  38256. mcuExpected = mcusPerLine * frame.mcusPerColumn;
  38257. }
  38258. if (!resetInterval) {
  38259. resetInterval = mcuExpected;
  38260. }
  38261. var h, v;
  38262. while (mcu < mcuExpected) {
  38263. // reset interval stuff
  38264. for (i = 0; i < componentsLength; i++) {
  38265. components[i].pred = 0;
  38266. }
  38267. eobrun = 0;
  38268. if (componentsLength === 1) {
  38269. component = components[0];
  38270. for (n = 0; n < resetInterval; n++) {
  38271. decodeBlock(component, decodeFn, mcu);
  38272. mcu++;
  38273. }
  38274. } else {
  38275. for (n = 0; n < resetInterval; n++) {
  38276. for (i = 0; i < componentsLength; i++) {
  38277. component = components[i];
  38278. h = component.h;
  38279. v = component.v;
  38280. for (j = 0; j < v; j++) {
  38281. for (k = 0; k < h; k++) {
  38282. decodeMcu(component, decodeFn, mcu, j, k);
  38283. }
  38284. }
  38285. }
  38286. mcu++;
  38287. }
  38288. }
  38289. // find marker
  38290. bitsCount = 0;
  38291. marker = (data[offset] << 8) | data[offset + 1];
  38292. if (marker <= 0xFF00) {
  38293. throw 'marker was not found';
  38294. }
  38295. if (marker >= 0xFFD0 && marker <= 0xFFD7) { // RSTx
  38296. offset += 2;
  38297. } else {
  38298. break;
  38299. }
  38300. }
  38301. return offset - startOffset;
  38302. }
  38303. // A port of poppler's IDCT method which in turn is taken from:
  38304. // Christoph Loeffler, Adriaan Ligtenberg, George S. Moschytz,
  38305. // 'Practical Fast 1-D DCT Algorithms with 11 Multiplications',
  38306. // IEEE Intl. Conf. on Acoustics, Speech & Signal Processing, 1989,
  38307. // 988-991.
  38308. function quantizeAndInverse(component, blockBufferOffset, p) {
  38309. var qt = component.quantizationTable, blockData = component.blockData;
  38310. var v0, v1, v2, v3, v4, v5, v6, v7;
  38311. var p0, p1, p2, p3, p4, p5, p6, p7;
  38312. var t;
  38313. // inverse DCT on rows
  38314. for (var row = 0; row < 64; row += 8) {
  38315. // gather block data
  38316. p0 = blockData[blockBufferOffset + row];
  38317. p1 = blockData[blockBufferOffset + row + 1];
  38318. p2 = blockData[blockBufferOffset + row + 2];
  38319. p3 = blockData[blockBufferOffset + row + 3];
  38320. p4 = blockData[blockBufferOffset + row + 4];
  38321. p5 = blockData[blockBufferOffset + row + 5];
  38322. p6 = blockData[blockBufferOffset + row + 6];
  38323. p7 = blockData[blockBufferOffset + row + 7];
  38324. // dequant p0
  38325. p0 *= qt[row];
  38326. // check for all-zero AC coefficients
  38327. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  38328. t = (dctSqrt2 * p0 + 512) >> 10;
  38329. p[row] = t;
  38330. p[row + 1] = t;
  38331. p[row + 2] = t;
  38332. p[row + 3] = t;
  38333. p[row + 4] = t;
  38334. p[row + 5] = t;
  38335. p[row + 6] = t;
  38336. p[row + 7] = t;
  38337. continue;
  38338. }
  38339. // dequant p1 ... p7
  38340. p1 *= qt[row + 1];
  38341. p2 *= qt[row + 2];
  38342. p3 *= qt[row + 3];
  38343. p4 *= qt[row + 4];
  38344. p5 *= qt[row + 5];
  38345. p6 *= qt[row + 6];
  38346. p7 *= qt[row + 7];
  38347. // stage 4
  38348. v0 = (dctSqrt2 * p0 + 128) >> 8;
  38349. v1 = (dctSqrt2 * p4 + 128) >> 8;
  38350. v2 = p2;
  38351. v3 = p6;
  38352. v4 = (dctSqrt1d2 * (p1 - p7) + 128) >> 8;
  38353. v7 = (dctSqrt1d2 * (p1 + p7) + 128) >> 8;
  38354. v5 = p3 << 4;
  38355. v6 = p5 << 4;
  38356. // stage 3
  38357. v0 = (v0 + v1 + 1) >> 1;
  38358. v1 = v0 - v1;
  38359. t = (v2 * dctSin6 + v3 * dctCos6 + 128) >> 8;
  38360. v2 = (v2 * dctCos6 - v3 * dctSin6 + 128) >> 8;
  38361. v3 = t;
  38362. v4 = (v4 + v6 + 1) >> 1;
  38363. v6 = v4 - v6;
  38364. v7 = (v7 + v5 + 1) >> 1;
  38365. v5 = v7 - v5;
  38366. // stage 2
  38367. v0 = (v0 + v3 + 1) >> 1;
  38368. v3 = v0 - v3;
  38369. v1 = (v1 + v2 + 1) >> 1;
  38370. v2 = v1 - v2;
  38371. t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12;
  38372. v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12;
  38373. v7 = t;
  38374. t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12;
  38375. v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12;
  38376. v6 = t;
  38377. // stage 1
  38378. p[row] = v0 + v7;
  38379. p[row + 7] = v0 - v7;
  38380. p[row + 1] = v1 + v6;
  38381. p[row + 6] = v1 - v6;
  38382. p[row + 2] = v2 + v5;
  38383. p[row + 5] = v2 - v5;
  38384. p[row + 3] = v3 + v4;
  38385. p[row + 4] = v3 - v4;
  38386. }
  38387. // inverse DCT on columns
  38388. for (var col = 0; col < 8; ++col) {
  38389. p0 = p[col];
  38390. p1 = p[col + 8];
  38391. p2 = p[col + 16];
  38392. p3 = p[col + 24];
  38393. p4 = p[col + 32];
  38394. p5 = p[col + 40];
  38395. p6 = p[col + 48];
  38396. p7 = p[col + 56];
  38397. // check for all-zero AC coefficients
  38398. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  38399. t = (dctSqrt2 * p0 + 8192) >> 14;
  38400. // convert to 8 bit
  38401. t = (t < -2040) ? 0 : (t >= 2024) ? 255 : (t + 2056) >> 4;
  38402. blockData[blockBufferOffset + col] = t;
  38403. blockData[blockBufferOffset + col + 8] = t;
  38404. blockData[blockBufferOffset + col + 16] = t;
  38405. blockData[blockBufferOffset + col + 24] = t;
  38406. blockData[blockBufferOffset + col + 32] = t;
  38407. blockData[blockBufferOffset + col + 40] = t;
  38408. blockData[blockBufferOffset + col + 48] = t;
  38409. blockData[blockBufferOffset + col + 56] = t;
  38410. continue;
  38411. }
  38412. // stage 4
  38413. v0 = (dctSqrt2 * p0 + 2048) >> 12;
  38414. v1 = (dctSqrt2 * p4 + 2048) >> 12;
  38415. v2 = p2;
  38416. v3 = p6;
  38417. v4 = (dctSqrt1d2 * (p1 - p7) + 2048) >> 12;
  38418. v7 = (dctSqrt1d2 * (p1 + p7) + 2048) >> 12;
  38419. v5 = p3;
  38420. v6 = p5;
  38421. // stage 3
  38422. // Shift v0 by 128.5 << 5 here, so we don't need to shift p0...p7 when
  38423. // converting to UInt8 range later.
  38424. v0 = ((v0 + v1 + 1) >> 1) + 4112;
  38425. v1 = v0 - v1;
  38426. t = (v2 * dctSin6 + v3 * dctCos6 + 2048) >> 12;
  38427. v2 = (v2 * dctCos6 - v3 * dctSin6 + 2048) >> 12;
  38428. v3 = t;
  38429. v4 = (v4 + v6 + 1) >> 1;
  38430. v6 = v4 - v6;
  38431. v7 = (v7 + v5 + 1) >> 1;
  38432. v5 = v7 - v5;
  38433. // stage 2
  38434. v0 = (v0 + v3 + 1) >> 1;
  38435. v3 = v0 - v3;
  38436. v1 = (v1 + v2 + 1) >> 1;
  38437. v2 = v1 - v2;
  38438. t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12;
  38439. v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12;
  38440. v7 = t;
  38441. t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12;
  38442. v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12;
  38443. v6 = t;
  38444. // stage 1
  38445. p0 = v0 + v7;
  38446. p7 = v0 - v7;
  38447. p1 = v1 + v6;
  38448. p6 = v1 - v6;
  38449. p2 = v2 + v5;
  38450. p5 = v2 - v5;
  38451. p3 = v3 + v4;
  38452. p4 = v3 - v4;
  38453. // convert to 8-bit integers
  38454. p0 = (p0 < 16) ? 0 : (p0 >= 4080) ? 255 : p0 >> 4;
  38455. p1 = (p1 < 16) ? 0 : (p1 >= 4080) ? 255 : p1 >> 4;
  38456. p2 = (p2 < 16) ? 0 : (p2 >= 4080) ? 255 : p2 >> 4;
  38457. p3 = (p3 < 16) ? 0 : (p3 >= 4080) ? 255 : p3 >> 4;
  38458. p4 = (p4 < 16) ? 0 : (p4 >= 4080) ? 255 : p4 >> 4;
  38459. p5 = (p5 < 16) ? 0 : (p5 >= 4080) ? 255 : p5 >> 4;
  38460. p6 = (p6 < 16) ? 0 : (p6 >= 4080) ? 255 : p6 >> 4;
  38461. p7 = (p7 < 16) ? 0 : (p7 >= 4080) ? 255 : p7 >> 4;
  38462. // store block data
  38463. blockData[blockBufferOffset + col] = p0;
  38464. blockData[blockBufferOffset + col + 8] = p1;
  38465. blockData[blockBufferOffset + col + 16] = p2;
  38466. blockData[blockBufferOffset + col + 24] = p3;
  38467. blockData[blockBufferOffset + col + 32] = p4;
  38468. blockData[blockBufferOffset + col + 40] = p5;
  38469. blockData[blockBufferOffset + col + 48] = p6;
  38470. blockData[blockBufferOffset + col + 56] = p7;
  38471. }
  38472. }
  38473. function buildComponentData(frame, component) {
  38474. var blocksPerLine = component.blocksPerLine;
  38475. var blocksPerColumn = component.blocksPerColumn;
  38476. var computationBuffer = new Int16Array(64);
  38477. for (var blockRow = 0; blockRow < blocksPerColumn; blockRow++) {
  38478. for (var blockCol = 0; blockCol < blocksPerLine; blockCol++) {
  38479. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  38480. quantizeAndInverse(component, offset, computationBuffer);
  38481. }
  38482. }
  38483. return component.blockData;
  38484. }
  38485. function clamp0to255(a) {
  38486. return a <= 0 ? 0 : a >= 255 ? 255 : a;
  38487. }
  38488. constructor.prototype = {
  38489. parse: function parse(data) {
  38490. function readUint16() {
  38491. var value = (data[offset] << 8) | data[offset + 1];
  38492. offset += 2;
  38493. return value;
  38494. }
  38495. function readDataBlock() {
  38496. var length = readUint16();
  38497. var array = data.subarray(offset, offset + length - 2);
  38498. offset += array.length;
  38499. return array;
  38500. }
  38501. function prepareComponents(frame) {
  38502. var mcusPerLine = Math.ceil(frame.samplesPerLine / 8 / frame.maxH);
  38503. var mcusPerColumn = Math.ceil(frame.scanLines / 8 / frame.maxV);
  38504. for (var i = 0; i < frame.components.length; i++) {
  38505. component = frame.components[i];
  38506. var blocksPerLine = Math.ceil(Math.ceil(frame.samplesPerLine / 8) *
  38507. component.h / frame.maxH);
  38508. var blocksPerColumn = Math.ceil(Math.ceil(frame.scanLines / 8) *
  38509. component.v / frame.maxV);
  38510. var blocksPerLineForMcu = mcusPerLine * component.h;
  38511. var blocksPerColumnForMcu = mcusPerColumn * component.v;
  38512. var blocksBufferSize = 64 * blocksPerColumnForMcu *
  38513. (blocksPerLineForMcu + 1);
  38514. component.blockData = new Int16Array(blocksBufferSize);
  38515. component.blocksPerLine = blocksPerLine;
  38516. component.blocksPerColumn = blocksPerColumn;
  38517. }
  38518. frame.mcusPerLine = mcusPerLine;
  38519. frame.mcusPerColumn = mcusPerColumn;
  38520. }
  38521. var offset = 0, length = data.length;
  38522. var jfif = null;
  38523. var adobe = null;
  38524. var pixels = null;
  38525. var frame, resetInterval;
  38526. var quantizationTables = [];
  38527. var huffmanTablesAC = [], huffmanTablesDC = [];
  38528. var fileMarker = readUint16();
  38529. if (fileMarker !== 0xFFD8) { // SOI (Start of Image)
  38530. throw 'SOI not found';
  38531. }
  38532. fileMarker = readUint16();
  38533. while (fileMarker !== 0xFFD9) { // EOI (End of image)
  38534. var i, j, l;
  38535. switch(fileMarker) {
  38536. case 0xFFE0: // APP0 (Application Specific)
  38537. case 0xFFE1: // APP1
  38538. case 0xFFE2: // APP2
  38539. case 0xFFE3: // APP3
  38540. case 0xFFE4: // APP4
  38541. case 0xFFE5: // APP5
  38542. case 0xFFE6: // APP6
  38543. case 0xFFE7: // APP7
  38544. case 0xFFE8: // APP8
  38545. case 0xFFE9: // APP9
  38546. case 0xFFEA: // APP10
  38547. case 0xFFEB: // APP11
  38548. case 0xFFEC: // APP12
  38549. case 0xFFED: // APP13
  38550. case 0xFFEE: // APP14
  38551. case 0xFFEF: // APP15
  38552. case 0xFFFE: // COM (Comment)
  38553. var appData = readDataBlock();
  38554. if (fileMarker === 0xFFE0) {
  38555. if (appData[0] === 0x4A && appData[1] === 0x46 &&
  38556. appData[2] === 0x49 && appData[3] === 0x46 &&
  38557. appData[4] === 0) { // 'JFIF\x00'
  38558. jfif = {
  38559. version: { major: appData[5], minor: appData[6] },
  38560. densityUnits: appData[7],
  38561. xDensity: (appData[8] << 8) | appData[9],
  38562. yDensity: (appData[10] << 8) | appData[11],
  38563. thumbWidth: appData[12],
  38564. thumbHeight: appData[13],
  38565. thumbData: appData.subarray(14, 14 +
  38566. 3 * appData[12] * appData[13])
  38567. };
  38568. }
  38569. }
  38570. // TODO APP1 - Exif
  38571. if (fileMarker === 0xFFEE) {
  38572. if (appData[0] === 0x41 && appData[1] === 0x64 &&
  38573. appData[2] === 0x6F && appData[3] === 0x62 &&
  38574. appData[4] === 0x65) { // 'Adobe'
  38575. adobe = {
  38576. version: (appData[5] << 8) | appData[6],
  38577. flags0: (appData[7] << 8) | appData[8],
  38578. flags1: (appData[9] << 8) | appData[10],
  38579. transformCode: appData[11]
  38580. };
  38581. }
  38582. }
  38583. break;
  38584. case 0xFFDB: // DQT (Define Quantization Tables)
  38585. var quantizationTablesLength = readUint16();
  38586. var quantizationTablesEnd = quantizationTablesLength + offset - 2;
  38587. var z;
  38588. while (offset < quantizationTablesEnd) {
  38589. var quantizationTableSpec = data[offset++];
  38590. var tableData = new Uint16Array(64);
  38591. if ((quantizationTableSpec >> 4) === 0) { // 8 bit values
  38592. for (j = 0; j < 64; j++) {
  38593. z = dctZigZag[j];
  38594. tableData[z] = data[offset++];
  38595. }
  38596. } else if ((quantizationTableSpec >> 4) === 1) { //16 bit
  38597. for (j = 0; j < 64; j++) {
  38598. z = dctZigZag[j];
  38599. tableData[z] = readUint16();
  38600. }
  38601. } else {
  38602. throw 'DQT: invalid table spec';
  38603. }
  38604. quantizationTables[quantizationTableSpec & 15] = tableData;
  38605. }
  38606. break;
  38607. case 0xFFC0: // SOF0 (Start of Frame, Baseline DCT)
  38608. case 0xFFC1: // SOF1 (Start of Frame, Extended DCT)
  38609. case 0xFFC2: // SOF2 (Start of Frame, Progressive DCT)
  38610. if (frame) {
  38611. throw 'Only single frame JPEGs supported';
  38612. }
  38613. readUint16(); // skip data length
  38614. frame = {};
  38615. frame.extended = (fileMarker === 0xFFC1);
  38616. frame.progressive = (fileMarker === 0xFFC2);
  38617. frame.precision = data[offset++];
  38618. frame.scanLines = readUint16();
  38619. frame.samplesPerLine = readUint16();
  38620. frame.components = [];
  38621. frame.componentIds = {};
  38622. var componentsCount = data[offset++], componentId;
  38623. var maxH = 0, maxV = 0;
  38624. for (i = 0; i < componentsCount; i++) {
  38625. componentId = data[offset];
  38626. var h = data[offset + 1] >> 4;
  38627. var v = data[offset + 1] & 15;
  38628. if (maxH < h) {
  38629. maxH = h;
  38630. }
  38631. if (maxV < v) {
  38632. maxV = v;
  38633. }
  38634. var qId = data[offset + 2];
  38635. l = frame.components.push({
  38636. h: h,
  38637. v: v,
  38638. quantizationTable: quantizationTables[qId]
  38639. });
  38640. frame.componentIds[componentId] = l - 1;
  38641. offset += 3;
  38642. }
  38643. frame.maxH = maxH;
  38644. frame.maxV = maxV;
  38645. prepareComponents(frame);
  38646. break;
  38647. case 0xFFC4: // DHT (Define Huffman Tables)
  38648. var huffmanLength = readUint16();
  38649. for (i = 2; i < huffmanLength;) {
  38650. var huffmanTableSpec = data[offset++];
  38651. var codeLengths = new Uint8Array(16);
  38652. var codeLengthSum = 0;
  38653. for (j = 0; j < 16; j++, offset++) {
  38654. codeLengthSum += (codeLengths[j] = data[offset]);
  38655. }
  38656. var huffmanValues = new Uint8Array(codeLengthSum);
  38657. for (j = 0; j < codeLengthSum; j++, offset++) {
  38658. huffmanValues[j] = data[offset];
  38659. }
  38660. i += 17 + codeLengthSum;
  38661. ((huffmanTableSpec >> 4) === 0 ?
  38662. huffmanTablesDC : huffmanTablesAC)[huffmanTableSpec & 15] =
  38663. buildHuffmanTable(codeLengths, huffmanValues);
  38664. }
  38665. break;
  38666. case 0xFFDD: // DRI (Define Restart Interval)
  38667. readUint16(); // skip data length
  38668. resetInterval = readUint16();
  38669. break;
  38670. case 0xFFDA: // SOS (Start of Scan)
  38671. var scanLength = readUint16();
  38672. var selectorsCount = data[offset++];
  38673. var components = [], component;
  38674. for (i = 0; i < selectorsCount; i++) {
  38675. var componentIndex = frame.componentIds[data[offset++]];
  38676. component = frame.components[componentIndex];
  38677. var tableSpec = data[offset++];
  38678. component.huffmanTableDC = huffmanTablesDC[tableSpec >> 4];
  38679. component.huffmanTableAC = huffmanTablesAC[tableSpec & 15];
  38680. components.push(component);
  38681. }
  38682. var spectralStart = data[offset++];
  38683. var spectralEnd = data[offset++];
  38684. var successiveApproximation = data[offset++];
  38685. var processed = decodeScan(data, offset,
  38686. frame, components, resetInterval,
  38687. spectralStart, spectralEnd,
  38688. successiveApproximation >> 4, successiveApproximation & 15);
  38689. offset += processed;
  38690. break;
  38691. case 0xFFFF: // Fill bytes
  38692. if (data[offset] !== 0xFF) { // Avoid skipping a valid marker.
  38693. offset--;
  38694. }
  38695. break;
  38696. default:
  38697. if (data[offset - 3] === 0xFF &&
  38698. data[offset - 2] >= 0xC0 && data[offset - 2] <= 0xFE) {
  38699. // could be incorrect encoding -- last 0xFF byte of the previous
  38700. // block was eaten by the encoder
  38701. offset -= 3;
  38702. break;
  38703. }
  38704. throw 'unknown JPEG marker ' + fileMarker.toString(16);
  38705. }
  38706. fileMarker = readUint16();
  38707. }
  38708. this.width = frame.samplesPerLine;
  38709. this.height = frame.scanLines;
  38710. this.jfif = jfif;
  38711. this.adobe = adobe;
  38712. this.components = [];
  38713. for (i = 0; i < frame.components.length; i++) {
  38714. component = frame.components[i];
  38715. this.components.push({
  38716. output: buildComponentData(frame, component),
  38717. scaleX: component.h / frame.maxH,
  38718. scaleY: component.v / frame.maxV,
  38719. blocksPerLine: component.blocksPerLine,
  38720. blocksPerColumn: component.blocksPerColumn
  38721. });
  38722. }
  38723. this.numComponents = this.components.length;
  38724. },
  38725. _getLinearizedBlockData: function getLinearizedBlockData(width, height) {
  38726. var scaleX = this.width / width, scaleY = this.height / height;
  38727. var component, componentScaleX, componentScaleY, blocksPerScanline;
  38728. var x, y, i, j, k;
  38729. var index;
  38730. var offset = 0;
  38731. var output;
  38732. var numComponents = this.components.length;
  38733. var dataLength = width * height * numComponents;
  38734. var data = new Uint8Array(dataLength);
  38735. var xScaleBlockOffset = new Uint32Array(width);
  38736. var mask3LSB = 0xfffffff8; // used to clear the 3 LSBs
  38737. for (i = 0; i < numComponents; i++) {
  38738. component = this.components[i];
  38739. componentScaleX = component.scaleX * scaleX;
  38740. componentScaleY = component.scaleY * scaleY;
  38741. offset = i;
  38742. output = component.output;
  38743. blocksPerScanline = (component.blocksPerLine + 1) << 3;
  38744. // precalculate the xScaleBlockOffset
  38745. for (x = 0; x < width; x++) {
  38746. j = 0 | (x * componentScaleX);
  38747. xScaleBlockOffset[x] = ((j & mask3LSB) << 3) | (j & 7);
  38748. }
  38749. // linearize the blocks of the component
  38750. for (y = 0; y < height; y++) {
  38751. j = 0 | (y * componentScaleY);
  38752. index = blocksPerScanline * (j & mask3LSB) | ((j & 7) << 3);
  38753. for (x = 0; x < width; x++) {
  38754. data[offset] = output[index + xScaleBlockOffset[x]];
  38755. offset += numComponents;
  38756. }
  38757. }
  38758. }
  38759. // decodeTransform contains pairs of multiplier (-256..256) and additive
  38760. var transform = this.decodeTransform;
  38761. if (transform) {
  38762. for (i = 0; i < dataLength;) {
  38763. for (j = 0, k = 0; j < numComponents; j++, i++, k += 2) {
  38764. data[i] = ((data[i] * transform[k]) >> 8) + transform[k + 1];
  38765. }
  38766. }
  38767. }
  38768. return data;
  38769. },
  38770. _isColorConversionNeeded: function isColorConversionNeeded() {
  38771. if (this.adobe && this.adobe.transformCode) {
  38772. // The adobe transform marker overrides any previous setting
  38773. return true;
  38774. } else if (this.numComponents === 3) {
  38775. return true;
  38776. } else {
  38777. return false;
  38778. }
  38779. },
  38780. _convertYccToRgb: function convertYccToRgb(data) {
  38781. var Y, Cb, Cr;
  38782. for (var i = 0, length = data.length; i < length; i += 3) {
  38783. Y = data[i ];
  38784. Cb = data[i + 1];
  38785. Cr = data[i + 2];
  38786. data[i ] = clamp0to255(Y - 179.456 + 1.402 * Cr);
  38787. data[i + 1] = clamp0to255(Y + 135.459 - 0.344 * Cb - 0.714 * Cr);
  38788. data[i + 2] = clamp0to255(Y - 226.816 + 1.772 * Cb);
  38789. }
  38790. return data;
  38791. },
  38792. _convertYcckToRgb: function convertYcckToRgb(data) {
  38793. var Y, Cb, Cr, k;
  38794. var offset = 0;
  38795. for (var i = 0, length = data.length; i < length; i += 4) {
  38796. Y = data[i];
  38797. Cb = data[i + 1];
  38798. Cr = data[i + 2];
  38799. k = data[i + 3];
  38800. var r = -122.67195406894 +
  38801. Cb * (-6.60635669420364e-5 * Cb + 0.000437130475926232 * Cr -
  38802. 5.4080610064599e-5 * Y + 0.00048449797120281 * k -
  38803. 0.154362151871126) +
  38804. Cr * (-0.000957964378445773 * Cr + 0.000817076911346625 * Y -
  38805. 0.00477271405408747 * k + 1.53380253221734) +
  38806. Y * (0.000961250184130688 * Y - 0.00266257332283933 * k +
  38807. 0.48357088451265) +
  38808. k * (-0.000336197177618394 * k + 0.484791561490776);
  38809. var g = 107.268039397724 +
  38810. Cb * (2.19927104525741e-5 * Cb - 0.000640992018297945 * Cr +
  38811. 0.000659397001245577 * Y + 0.000426105652938837 * k -
  38812. 0.176491792462875) +
  38813. Cr * (-0.000778269941513683 * Cr + 0.00130872261408275 * Y +
  38814. 0.000770482631801132 * k - 0.151051492775562) +
  38815. Y * (0.00126935368114843 * Y - 0.00265090189010898 * k +
  38816. 0.25802910206845) +
  38817. k * (-0.000318913117588328 * k - 0.213742400323665);
  38818. var b = -20.810012546947 +
  38819. Cb * (-0.000570115196973677 * Cb - 2.63409051004589e-5 * Cr +
  38820. 0.0020741088115012 * Y - 0.00288260236853442 * k +
  38821. 0.814272968359295) +
  38822. Cr * (-1.53496057440975e-5 * Cr - 0.000132689043961446 * Y +
  38823. 0.000560833691242812 * k - 0.195152027534049) +
  38824. Y * (0.00174418132927582 * Y - 0.00255243321439347 * k +
  38825. 0.116935020465145) +
  38826. k * (-0.000343531996510555 * k + 0.24165260232407);
  38827. data[offset++] = clamp0to255(r);
  38828. data[offset++] = clamp0to255(g);
  38829. data[offset++] = clamp0to255(b);
  38830. }
  38831. return data;
  38832. },
  38833. _convertYcckToCmyk: function convertYcckToCmyk(data) {
  38834. var Y, Cb, Cr;
  38835. for (var i = 0, length = data.length; i < length; i += 4) {
  38836. Y = data[i];
  38837. Cb = data[i + 1];
  38838. Cr = data[i + 2];
  38839. data[i ] = clamp0to255(434.456 - Y - 1.402 * Cr);
  38840. data[i + 1] = clamp0to255(119.541 - Y + 0.344 * Cb + 0.714 * Cr);
  38841. data[i + 2] = clamp0to255(481.816 - Y - 1.772 * Cb);
  38842. // K in data[i + 3] is unchanged
  38843. }
  38844. return data;
  38845. },
  38846. _convertCmykToRgb: function convertCmykToRgb(data) {
  38847. var c, m, y, k;
  38848. var offset = 0;
  38849. var min = -255 * 255 * 255;
  38850. var scale = 1 / 255 / 255;
  38851. for (var i = 0, length = data.length; i < length; i += 4) {
  38852. c = data[i];
  38853. m = data[i + 1];
  38854. y = data[i + 2];
  38855. k = data[i + 3];
  38856. var r =
  38857. c * (-4.387332384609988 * c + 54.48615194189176 * m +
  38858. 18.82290502165302 * y + 212.25662451639585 * k -
  38859. 72734.4411664936) +
  38860. m * (1.7149763477362134 * m - 5.6096736904047315 * y -
  38861. 17.873870861415444 * k - 1401.7366389350734) +
  38862. y * (-2.5217340131683033 * y - 21.248923337353073 * k +
  38863. 4465.541406466231) -
  38864. k * (21.86122147463605 * k + 48317.86113160301);
  38865. var g =
  38866. c * (8.841041422036149 * c + 60.118027045597366 * m +
  38867. 6.871425592049007 * y + 31.159100130055922 * k -
  38868. 20220.756542821975) +
  38869. m * (-15.310361306967817 * m + 17.575251261109482 * y +
  38870. 131.35250912493976 * k - 48691.05921601825) +
  38871. y * (4.444339102852739 * y + 9.8632861493405 * k -
  38872. 6341.191035517494) -
  38873. k * (20.737325471181034 * k + 47890.15695978492);
  38874. var b =
  38875. c * (0.8842522430003296 * c + 8.078677503112928 * m +
  38876. 30.89978309703729 * y - 0.23883238689178934 * k -
  38877. 3616.812083916688) +
  38878. m * (10.49593273432072 * m + 63.02378494754052 * y +
  38879. 50.606957656360734 * k - 28620.90484698408) +
  38880. y * (0.03296041114873217 * y + 115.60384449646641 * k -
  38881. 49363.43385999684) -
  38882. k * (22.33816807309886 * k + 45932.16563550634);
  38883. data[offset++] = r >= 0 ? 255 : r <= min ? 0 : 255 + r * scale | 0;
  38884. data[offset++] = g >= 0 ? 255 : g <= min ? 0 : 255 + g * scale | 0;
  38885. data[offset++] = b >= 0 ? 255 : b <= min ? 0 : 255 + b * scale | 0;
  38886. }
  38887. return data;
  38888. },
  38889. getData: function getData(width, height, forceRGBoutput) {
  38890. if (this.numComponents > 4) {
  38891. throw 'Unsupported color mode';
  38892. }
  38893. // type of data: Uint8Array(width * height * numComponents)
  38894. var data = this._getLinearizedBlockData(width, height);
  38895. if (this.numComponents === 3) {
  38896. return this._convertYccToRgb(data);
  38897. } else if (this.numComponents === 4) {
  38898. if (this._isColorConversionNeeded()) {
  38899. if (forceRGBoutput) {
  38900. return this._convertYcckToRgb(data);
  38901. } else {
  38902. return this._convertYcckToCmyk(data);
  38903. }
  38904. } else if (forceRGBoutput) {
  38905. return this._convertCmykToRgb(data);
  38906. }
  38907. }
  38908. return data;
  38909. }
  38910. };
  38911. return constructor;
  38912. })();
  38913. var JpxImage = (function JpxImageClosure() {
  38914. // Table E.1
  38915. var SubbandsGainLog2 = {
  38916. 'LL': 0,
  38917. 'LH': 1,
  38918. 'HL': 1,
  38919. 'HH': 2
  38920. };
  38921. function JpxImage() {
  38922. this.failOnCorruptedImage = false;
  38923. }
  38924. JpxImage.prototype = {
  38925. parse: function JpxImage_parse(data) {
  38926. var head = readUint16(data, 0);
  38927. // No box header, immediate start of codestream (SOC)
  38928. if (head === 0xFF4F) {
  38929. this.parseCodestream(data, 0, data.length);
  38930. return;
  38931. }
  38932. var position = 0, length = data.length;
  38933. while (position < length) {
  38934. var headerSize = 8;
  38935. var lbox = readUint32(data, position);
  38936. var tbox = readUint32(data, position + 4);
  38937. position += headerSize;
  38938. if (lbox === 1) {
  38939. // XLBox: read UInt64 according to spec.
  38940. // JavaScript's int precision of 53 bit should be sufficient here.
  38941. lbox = readUint32(data, position) * 4294967296 +
  38942. readUint32(data, position + 4);
  38943. position += 8;
  38944. headerSize += 8;
  38945. }
  38946. if (lbox === 0) {
  38947. lbox = length - position + headerSize;
  38948. }
  38949. if (lbox < headerSize) {
  38950. throw new Error('JPX Error: Invalid box field size');
  38951. }
  38952. var dataLength = lbox - headerSize;
  38953. var jumpDataLength = true;
  38954. switch (tbox) {
  38955. case 0x6A703268: // 'jp2h'
  38956. jumpDataLength = false; // parsing child boxes
  38957. break;
  38958. case 0x636F6C72: // 'colr'
  38959. // Colorspaces are not used, the CS from the PDF is used.
  38960. var method = data[position];
  38961. var precedence = data[position + 1];
  38962. var approximation = data[position + 2];
  38963. if (method === 1) {
  38964. // enumerated colorspace
  38965. var colorspace = readUint32(data, position + 3);
  38966. switch (colorspace) {
  38967. case 16: // this indicates a sRGB colorspace
  38968. case 17: // this indicates a grayscale colorspace
  38969. case 18: // this indicates a YUV colorspace
  38970. break;
  38971. default:
  38972. warn('Unknown colorspace ' + colorspace);
  38973. break;
  38974. }
  38975. } else if (method === 2) {
  38976. info('ICC profile not supported');
  38977. }
  38978. break;
  38979. case 0x6A703263: // 'jp2c'
  38980. this.parseCodestream(data, position, position + dataLength);
  38981. break;
  38982. case 0x6A502020: // 'jP\024\024'
  38983. if (0x0d0a870a !== readUint32(data, position)) {
  38984. warn('Invalid JP2 signature');
  38985. }
  38986. break;
  38987. // The following header types are valid but currently not used:
  38988. case 0x6A501A1A: // 'jP\032\032'
  38989. case 0x66747970: // 'ftyp'
  38990. case 0x72726571: // 'rreq'
  38991. case 0x72657320: // 'res '
  38992. case 0x69686472: // 'ihdr'
  38993. break;
  38994. default:
  38995. var headerType = String.fromCharCode((tbox >> 24) & 0xFF,
  38996. (tbox >> 16) & 0xFF,
  38997. (tbox >> 8) & 0xFF,
  38998. tbox & 0xFF);
  38999. warn('Unsupported header type ' + tbox + ' (' + headerType + ')');
  39000. break;
  39001. }
  39002. if (jumpDataLength) {
  39003. position += dataLength;
  39004. }
  39005. }
  39006. },
  39007. parseImageProperties: function JpxImage_parseImageProperties(stream) {
  39008. var newByte = stream.getByte();
  39009. while (newByte >= 0) {
  39010. var oldByte = newByte;
  39011. newByte = stream.getByte();
  39012. var code = (oldByte << 8) | newByte;
  39013. // Image and tile size (SIZ)
  39014. if (code === 0xFF51) {
  39015. stream.skip(4);
  39016. var Xsiz = stream.getInt32() >>> 0; // Byte 4
  39017. var Ysiz = stream.getInt32() >>> 0; // Byte 8
  39018. var XOsiz = stream.getInt32() >>> 0; // Byte 12
  39019. var YOsiz = stream.getInt32() >>> 0; // Byte 16
  39020. stream.skip(16);
  39021. var Csiz = stream.getUint16(); // Byte 36
  39022. this.width = Xsiz - XOsiz;
  39023. this.height = Ysiz - YOsiz;
  39024. this.componentsCount = Csiz;
  39025. // Results are always returned as Uint8Arrays
  39026. this.bitsPerComponent = 8;
  39027. return;
  39028. }
  39029. }
  39030. throw new Error('JPX Error: No size marker found in JPX stream');
  39031. },
  39032. parseCodestream: function JpxImage_parseCodestream(data, start, end) {
  39033. var context = {};
  39034. try {
  39035. var doNotRecover = false;
  39036. var position = start;
  39037. while (position + 1 < end) {
  39038. var code = readUint16(data, position);
  39039. position += 2;
  39040. var length = 0, j, sqcd, spqcds, spqcdSize, scalarExpounded, tile;
  39041. switch (code) {
  39042. case 0xFF4F: // Start of codestream (SOC)
  39043. context.mainHeader = true;
  39044. break;
  39045. case 0xFFD9: // End of codestream (EOC)
  39046. break;
  39047. case 0xFF51: // Image and tile size (SIZ)
  39048. length = readUint16(data, position);
  39049. var siz = {};
  39050. siz.Xsiz = readUint32(data, position + 4);
  39051. siz.Ysiz = readUint32(data, position + 8);
  39052. siz.XOsiz = readUint32(data, position + 12);
  39053. siz.YOsiz = readUint32(data, position + 16);
  39054. siz.XTsiz = readUint32(data, position + 20);
  39055. siz.YTsiz = readUint32(data, position + 24);
  39056. siz.XTOsiz = readUint32(data, position + 28);
  39057. siz.YTOsiz = readUint32(data, position + 32);
  39058. var componentsCount = readUint16(data, position + 36);
  39059. siz.Csiz = componentsCount;
  39060. var components = [];
  39061. j = position + 38;
  39062. for (var i = 0; i < componentsCount; i++) {
  39063. var component = {
  39064. precision: (data[j] & 0x7F) + 1,
  39065. isSigned: !!(data[j] & 0x80),
  39066. XRsiz: data[j + 1],
  39067. YRsiz: data[j + 1]
  39068. };
  39069. calculateComponentDimensions(component, siz);
  39070. components.push(component);
  39071. }
  39072. context.SIZ = siz;
  39073. context.components = components;
  39074. calculateTileGrids(context, components);
  39075. context.QCC = [];
  39076. context.COC = [];
  39077. break;
  39078. case 0xFF5C: // Quantization default (QCD)
  39079. length = readUint16(data, position);
  39080. var qcd = {};
  39081. j = position + 2;
  39082. sqcd = data[j++];
  39083. switch (sqcd & 0x1F) {
  39084. case 0:
  39085. spqcdSize = 8;
  39086. scalarExpounded = true;
  39087. break;
  39088. case 1:
  39089. spqcdSize = 16;
  39090. scalarExpounded = false;
  39091. break;
  39092. case 2:
  39093. spqcdSize = 16;
  39094. scalarExpounded = true;
  39095. break;
  39096. default:
  39097. throw new Error('JPX Error: Invalid SQcd value ' + sqcd);
  39098. }
  39099. qcd.noQuantization = (spqcdSize === 8);
  39100. qcd.scalarExpounded = scalarExpounded;
  39101. qcd.guardBits = sqcd >> 5;
  39102. spqcds = [];
  39103. while (j < length + position) {
  39104. var spqcd = {};
  39105. if (spqcdSize === 8) {
  39106. spqcd.epsilon = data[j++] >> 3;
  39107. spqcd.mu = 0;
  39108. } else {
  39109. spqcd.epsilon = data[j] >> 3;
  39110. spqcd.mu = ((data[j] & 0x7) << 8) | data[j + 1];
  39111. j += 2;
  39112. }
  39113. spqcds.push(spqcd);
  39114. }
  39115. qcd.SPqcds = spqcds;
  39116. if (context.mainHeader) {
  39117. context.QCD = qcd;
  39118. } else {
  39119. context.currentTile.QCD = qcd;
  39120. context.currentTile.QCC = [];
  39121. }
  39122. break;
  39123. case 0xFF5D: // Quantization component (QCC)
  39124. length = readUint16(data, position);
  39125. var qcc = {};
  39126. j = position + 2;
  39127. var cqcc;
  39128. if (context.SIZ.Csiz < 257) {
  39129. cqcc = data[j++];
  39130. } else {
  39131. cqcc = readUint16(data, j);
  39132. j += 2;
  39133. }
  39134. sqcd = data[j++];
  39135. switch (sqcd & 0x1F) {
  39136. case 0:
  39137. spqcdSize = 8;
  39138. scalarExpounded = true;
  39139. break;
  39140. case 1:
  39141. spqcdSize = 16;
  39142. scalarExpounded = false;
  39143. break;
  39144. case 2:
  39145. spqcdSize = 16;
  39146. scalarExpounded = true;
  39147. break;
  39148. default:
  39149. throw new Error('JPX Error: Invalid SQcd value ' + sqcd);
  39150. }
  39151. qcc.noQuantization = (spqcdSize === 8);
  39152. qcc.scalarExpounded = scalarExpounded;
  39153. qcc.guardBits = sqcd >> 5;
  39154. spqcds = [];
  39155. while (j < (length + position)) {
  39156. spqcd = {};
  39157. if (spqcdSize === 8) {
  39158. spqcd.epsilon = data[j++] >> 3;
  39159. spqcd.mu = 0;
  39160. } else {
  39161. spqcd.epsilon = data[j] >> 3;
  39162. spqcd.mu = ((data[j] & 0x7) << 8) | data[j + 1];
  39163. j += 2;
  39164. }
  39165. spqcds.push(spqcd);
  39166. }
  39167. qcc.SPqcds = spqcds;
  39168. if (context.mainHeader) {
  39169. context.QCC[cqcc] = qcc;
  39170. } else {
  39171. context.currentTile.QCC[cqcc] = qcc;
  39172. }
  39173. break;
  39174. case 0xFF52: // Coding style default (COD)
  39175. length = readUint16(data, position);
  39176. var cod = {};
  39177. j = position + 2;
  39178. var scod = data[j++];
  39179. cod.entropyCoderWithCustomPrecincts = !!(scod & 1);
  39180. cod.sopMarkerUsed = !!(scod & 2);
  39181. cod.ephMarkerUsed = !!(scod & 4);
  39182. cod.progressionOrder = data[j++];
  39183. cod.layersCount = readUint16(data, j);
  39184. j += 2;
  39185. cod.multipleComponentTransform = data[j++];
  39186. cod.decompositionLevelsCount = data[j++];
  39187. cod.xcb = (data[j++] & 0xF) + 2;
  39188. cod.ycb = (data[j++] & 0xF) + 2;
  39189. var blockStyle = data[j++];
  39190. cod.selectiveArithmeticCodingBypass = !!(blockStyle & 1);
  39191. cod.resetContextProbabilities = !!(blockStyle & 2);
  39192. cod.terminationOnEachCodingPass = !!(blockStyle & 4);
  39193. cod.verticalyStripe = !!(blockStyle & 8);
  39194. cod.predictableTermination = !!(blockStyle & 16);
  39195. cod.segmentationSymbolUsed = !!(blockStyle & 32);
  39196. cod.reversibleTransformation = data[j++];
  39197. if (cod.entropyCoderWithCustomPrecincts) {
  39198. var precinctsSizes = [];
  39199. while (j < length + position) {
  39200. var precinctsSize = data[j++];
  39201. precinctsSizes.push({
  39202. PPx: precinctsSize & 0xF,
  39203. PPy: precinctsSize >> 4
  39204. });
  39205. }
  39206. cod.precinctsSizes = precinctsSizes;
  39207. }
  39208. var unsupported = [];
  39209. if (cod.selectiveArithmeticCodingBypass) {
  39210. unsupported.push('selectiveArithmeticCodingBypass');
  39211. }
  39212. if (cod.resetContextProbabilities) {
  39213. unsupported.push('resetContextProbabilities');
  39214. }
  39215. if (cod.terminationOnEachCodingPass) {
  39216. unsupported.push('terminationOnEachCodingPass');
  39217. }
  39218. if (cod.verticalyStripe) {
  39219. unsupported.push('verticalyStripe');
  39220. }
  39221. if (cod.predictableTermination) {
  39222. unsupported.push('predictableTermination');
  39223. }
  39224. if (unsupported.length > 0) {
  39225. doNotRecover = true;
  39226. throw new Error('JPX Error: Unsupported COD options (' +
  39227. unsupported.join(', ') + ')');
  39228. }
  39229. if (context.mainHeader) {
  39230. context.COD = cod;
  39231. } else {
  39232. context.currentTile.COD = cod;
  39233. context.currentTile.COC = [];
  39234. }
  39235. break;
  39236. case 0xFF90: // Start of tile-part (SOT)
  39237. length = readUint16(data, position);
  39238. tile = {};
  39239. tile.index = readUint16(data, position + 2);
  39240. tile.length = readUint32(data, position + 4);
  39241. tile.dataEnd = tile.length + position - 2;
  39242. tile.partIndex = data[position + 8];
  39243. tile.partsCount = data[position + 9];
  39244. context.mainHeader = false;
  39245. if (tile.partIndex === 0) {
  39246. // reset component specific settings
  39247. tile.COD = context.COD;
  39248. tile.COC = context.COC.slice(0); // clone of the global COC
  39249. tile.QCD = context.QCD;
  39250. tile.QCC = context.QCC.slice(0); // clone of the global COC
  39251. }
  39252. context.currentTile = tile;
  39253. break;
  39254. case 0xFF93: // Start of data (SOD)
  39255. tile = context.currentTile;
  39256. if (tile.partIndex === 0) {
  39257. initializeTile(context, tile.index);
  39258. buildPackets(context);
  39259. }
  39260. // moving to the end of the data
  39261. length = tile.dataEnd - position;
  39262. parseTilePackets(context, data, position, length);
  39263. break;
  39264. case 0xFF55: // Tile-part lengths, main header (TLM)
  39265. case 0xFF57: // Packet length, main header (PLM)
  39266. case 0xFF58: // Packet length, tile-part header (PLT)
  39267. case 0xFF64: // Comment (COM)
  39268. length = readUint16(data, position);
  39269. // skipping content
  39270. break;
  39271. case 0xFF53: // Coding style component (COC)
  39272. throw new Error('JPX Error: Codestream code 0xFF53 (COC) is ' +
  39273. 'not implemented');
  39274. default:
  39275. throw new Error('JPX Error: Unknown codestream code: ' +
  39276. code.toString(16));
  39277. }
  39278. position += length;
  39279. }
  39280. } catch (e) {
  39281. if (doNotRecover || this.failOnCorruptedImage) {
  39282. throw e;
  39283. } else {
  39284. warn('Trying to recover from ' + e.message);
  39285. }
  39286. }
  39287. this.tiles = transformComponents(context);
  39288. this.width = context.SIZ.Xsiz - context.SIZ.XOsiz;
  39289. this.height = context.SIZ.Ysiz - context.SIZ.YOsiz;
  39290. this.componentsCount = context.SIZ.Csiz;
  39291. }
  39292. };
  39293. function calculateComponentDimensions(component, siz) {
  39294. // Section B.2 Component mapping
  39295. component.x0 = Math.ceil(siz.XOsiz / component.XRsiz);
  39296. component.x1 = Math.ceil(siz.Xsiz / component.XRsiz);
  39297. component.y0 = Math.ceil(siz.YOsiz / component.YRsiz);
  39298. component.y1 = Math.ceil(siz.Ysiz / component.YRsiz);
  39299. component.width = component.x1 - component.x0;
  39300. component.height = component.y1 - component.y0;
  39301. }
  39302. function calculateTileGrids(context, components) {
  39303. var siz = context.SIZ;
  39304. // Section B.3 Division into tile and tile-components
  39305. var tile, tiles = [];
  39306. var numXtiles = Math.ceil((siz.Xsiz - siz.XTOsiz) / siz.XTsiz);
  39307. var numYtiles = Math.ceil((siz.Ysiz - siz.YTOsiz) / siz.YTsiz);
  39308. for (var q = 0; q < numYtiles; q++) {
  39309. for (var p = 0; p < numXtiles; p++) {
  39310. tile = {};
  39311. tile.tx0 = Math.max(siz.XTOsiz + p * siz.XTsiz, siz.XOsiz);
  39312. tile.ty0 = Math.max(siz.YTOsiz + q * siz.YTsiz, siz.YOsiz);
  39313. tile.tx1 = Math.min(siz.XTOsiz + (p + 1) * siz.XTsiz, siz.Xsiz);
  39314. tile.ty1 = Math.min(siz.YTOsiz + (q + 1) * siz.YTsiz, siz.Ysiz);
  39315. tile.width = tile.tx1 - tile.tx0;
  39316. tile.height = tile.ty1 - tile.ty0;
  39317. tile.components = [];
  39318. tiles.push(tile);
  39319. }
  39320. }
  39321. context.tiles = tiles;
  39322. var componentsCount = siz.Csiz;
  39323. for (var i = 0, ii = componentsCount; i < ii; i++) {
  39324. var component = components[i];
  39325. for (var j = 0, jj = tiles.length; j < jj; j++) {
  39326. var tileComponent = {};
  39327. tile = tiles[j];
  39328. tileComponent.tcx0 = Math.ceil(tile.tx0 / component.XRsiz);
  39329. tileComponent.tcy0 = Math.ceil(tile.ty0 / component.YRsiz);
  39330. tileComponent.tcx1 = Math.ceil(tile.tx1 / component.XRsiz);
  39331. tileComponent.tcy1 = Math.ceil(tile.ty1 / component.YRsiz);
  39332. tileComponent.width = tileComponent.tcx1 - tileComponent.tcx0;
  39333. tileComponent.height = tileComponent.tcy1 - tileComponent.tcy0;
  39334. tile.components[i] = tileComponent;
  39335. }
  39336. }
  39337. }
  39338. function getBlocksDimensions(context, component, r) {
  39339. var codOrCoc = component.codingStyleParameters;
  39340. var result = {};
  39341. if (!codOrCoc.entropyCoderWithCustomPrecincts) {
  39342. result.PPx = 15;
  39343. result.PPy = 15;
  39344. } else {
  39345. result.PPx = codOrCoc.precinctsSizes[r].PPx;
  39346. result.PPy = codOrCoc.precinctsSizes[r].PPy;
  39347. }
  39348. // calculate codeblock size as described in section B.7
  39349. result.xcb_ = (r > 0 ? Math.min(codOrCoc.xcb, result.PPx - 1) :
  39350. Math.min(codOrCoc.xcb, result.PPx));
  39351. result.ycb_ = (r > 0 ? Math.min(codOrCoc.ycb, result.PPy - 1) :
  39352. Math.min(codOrCoc.ycb, result.PPy));
  39353. return result;
  39354. }
  39355. function buildPrecincts(context, resolution, dimensions) {
  39356. // Section B.6 Division resolution to precincts
  39357. var precinctWidth = 1 << dimensions.PPx;
  39358. var precinctHeight = 1 << dimensions.PPy;
  39359. // Jasper introduces codeblock groups for mapping each subband codeblocks
  39360. // to precincts. Precinct partition divides a resolution according to width
  39361. // and height parameters. The subband that belongs to the resolution level
  39362. // has a different size than the level, unless it is the zero resolution.
  39363. // From Jasper documentation: jpeg2000.pdf, section K: Tier-2 coding:
  39364. // The precinct partitioning for a particular subband is derived from a
  39365. // partitioning of its parent LL band (i.e., the LL band at the next higher
  39366. // resolution level)... The LL band associated with each resolution level is
  39367. // divided into precincts... Each of the resulting precinct regions is then
  39368. // mapped into its child subbands (if any) at the next lower resolution
  39369. // level. This is accomplished by using the coordinate transformation
  39370. // (u, v) = (ceil(x/2), ceil(y/2)) where (x, y) and (u, v) are the
  39371. // coordinates of a point in the LL band and child subband, respectively.
  39372. var isZeroRes = resolution.resLevel === 0;
  39373. var precinctWidthInSubband = 1 << (dimensions.PPx + (isZeroRes ? 0 : -1));
  39374. var precinctHeightInSubband = 1 << (dimensions.PPy + (isZeroRes ? 0 : -1));
  39375. var numprecinctswide = (resolution.trx1 > resolution.trx0 ?
  39376. Math.ceil(resolution.trx1 / precinctWidth) -
  39377. Math.floor(resolution.trx0 / precinctWidth) : 0);
  39378. var numprecinctshigh = (resolution.try1 > resolution.try0 ?
  39379. Math.ceil(resolution.try1 / precinctHeight) -
  39380. Math.floor(resolution.try0 / precinctHeight) : 0);
  39381. var numprecincts = numprecinctswide * numprecinctshigh;
  39382. resolution.precinctParameters = {
  39383. precinctWidth: precinctWidth,
  39384. precinctHeight: precinctHeight,
  39385. numprecinctswide: numprecinctswide,
  39386. numprecinctshigh: numprecinctshigh,
  39387. numprecincts: numprecincts,
  39388. precinctWidthInSubband: precinctWidthInSubband,
  39389. precinctHeightInSubband: precinctHeightInSubband
  39390. };
  39391. }
  39392. function buildCodeblocks(context, subband, dimensions) {
  39393. // Section B.7 Division sub-band into code-blocks
  39394. var xcb_ = dimensions.xcb_;
  39395. var ycb_ = dimensions.ycb_;
  39396. var codeblockWidth = 1 << xcb_;
  39397. var codeblockHeight = 1 << ycb_;
  39398. var cbx0 = subband.tbx0 >> xcb_;
  39399. var cby0 = subband.tby0 >> ycb_;
  39400. var cbx1 = (subband.tbx1 + codeblockWidth - 1) >> xcb_;
  39401. var cby1 = (subband.tby1 + codeblockHeight - 1) >> ycb_;
  39402. var precinctParameters = subband.resolution.precinctParameters;
  39403. var codeblocks = [];
  39404. var precincts = [];
  39405. var i, j, codeblock, precinctNumber;
  39406. for (j = cby0; j < cby1; j++) {
  39407. for (i = cbx0; i < cbx1; i++) {
  39408. codeblock = {
  39409. cbx: i,
  39410. cby: j,
  39411. tbx0: codeblockWidth * i,
  39412. tby0: codeblockHeight * j,
  39413. tbx1: codeblockWidth * (i + 1),
  39414. tby1: codeblockHeight * (j + 1)
  39415. };
  39416. codeblock.tbx0_ = Math.max(subband.tbx0, codeblock.tbx0);
  39417. codeblock.tby0_ = Math.max(subband.tby0, codeblock.tby0);
  39418. codeblock.tbx1_ = Math.min(subband.tbx1, codeblock.tbx1);
  39419. codeblock.tby1_ = Math.min(subband.tby1, codeblock.tby1);
  39420. // Calculate precinct number for this codeblock, codeblock position
  39421. // should be relative to its subband, use actual dimension and position
  39422. // See comment about codeblock group width and height
  39423. var pi = Math.floor((codeblock.tbx0_ - subband.tbx0) /
  39424. precinctParameters.precinctWidthInSubband);
  39425. var pj = Math.floor((codeblock.tby0_ - subband.tby0) /
  39426. precinctParameters.precinctHeightInSubband);
  39427. precinctNumber = pi + (pj * precinctParameters.numprecinctswide);
  39428. codeblock.precinctNumber = precinctNumber;
  39429. codeblock.subbandType = subband.type;
  39430. codeblock.Lblock = 3;
  39431. if (codeblock.tbx1_ <= codeblock.tbx0_ ||
  39432. codeblock.tby1_ <= codeblock.tby0_) {
  39433. continue;
  39434. }
  39435. codeblocks.push(codeblock);
  39436. // building precinct for the sub-band
  39437. var precinct = precincts[precinctNumber];
  39438. if (precinct !== undefined) {
  39439. if (i < precinct.cbxMin) {
  39440. precinct.cbxMin = i;
  39441. } else if (i > precinct.cbxMax) {
  39442. precinct.cbxMax = i;
  39443. }
  39444. if (j < precinct.cbyMin) {
  39445. precinct.cbxMin = j;
  39446. } else if (j > precinct.cbyMax) {
  39447. precinct.cbyMax = j;
  39448. }
  39449. } else {
  39450. precincts[precinctNumber] = precinct = {
  39451. cbxMin: i,
  39452. cbyMin: j,
  39453. cbxMax: i,
  39454. cbyMax: j
  39455. };
  39456. }
  39457. codeblock.precinct = precinct;
  39458. }
  39459. }
  39460. subband.codeblockParameters = {
  39461. codeblockWidth: xcb_,
  39462. codeblockHeight: ycb_,
  39463. numcodeblockwide: cbx1 - cbx0 + 1,
  39464. numcodeblockhigh: cby1 - cby0 + 1
  39465. };
  39466. subband.codeblocks = codeblocks;
  39467. subband.precincts = precincts;
  39468. }
  39469. function createPacket(resolution, precinctNumber, layerNumber) {
  39470. var precinctCodeblocks = [];
  39471. // Section B.10.8 Order of info in packet
  39472. var subbands = resolution.subbands;
  39473. // sub-bands already ordered in 'LL', 'HL', 'LH', and 'HH' sequence
  39474. for (var i = 0, ii = subbands.length; i < ii; i++) {
  39475. var subband = subbands[i];
  39476. var codeblocks = subband.codeblocks;
  39477. for (var j = 0, jj = codeblocks.length; j < jj; j++) {
  39478. var codeblock = codeblocks[j];
  39479. if (codeblock.precinctNumber !== precinctNumber) {
  39480. continue;
  39481. }
  39482. precinctCodeblocks.push(codeblock);
  39483. }
  39484. }
  39485. return {
  39486. layerNumber: layerNumber,
  39487. codeblocks: precinctCodeblocks
  39488. };
  39489. }
  39490. function LayerResolutionComponentPositionIterator(context) {
  39491. var siz = context.SIZ;
  39492. var tileIndex = context.currentTile.index;
  39493. var tile = context.tiles[tileIndex];
  39494. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  39495. var componentsCount = siz.Csiz;
  39496. var maxDecompositionLevelsCount = 0;
  39497. for (var q = 0; q < componentsCount; q++) {
  39498. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  39499. tile.components[q].codingStyleParameters.decompositionLevelsCount);
  39500. }
  39501. var l = 0, r = 0, i = 0, k = 0;
  39502. this.nextPacket = function JpxImage_nextPacket() {
  39503. // Section B.12.1.1 Layer-resolution-component-position
  39504. for (; l < layersCount; l++) {
  39505. for (; r <= maxDecompositionLevelsCount; r++) {
  39506. for (; i < componentsCount; i++) {
  39507. var component = tile.components[i];
  39508. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  39509. continue;
  39510. }
  39511. var resolution = component.resolutions[r];
  39512. var numprecincts = resolution.precinctParameters.numprecincts;
  39513. for (; k < numprecincts;) {
  39514. var packet = createPacket(resolution, k, l);
  39515. k++;
  39516. return packet;
  39517. }
  39518. k = 0;
  39519. }
  39520. i = 0;
  39521. }
  39522. r = 0;
  39523. }
  39524. throw new Error('JPX Error: Out of packets');
  39525. };
  39526. }
  39527. function ResolutionLayerComponentPositionIterator(context) {
  39528. var siz = context.SIZ;
  39529. var tileIndex = context.currentTile.index;
  39530. var tile = context.tiles[tileIndex];
  39531. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  39532. var componentsCount = siz.Csiz;
  39533. var maxDecompositionLevelsCount = 0;
  39534. for (var q = 0; q < componentsCount; q++) {
  39535. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  39536. tile.components[q].codingStyleParameters.decompositionLevelsCount);
  39537. }
  39538. var r = 0, l = 0, i = 0, k = 0;
  39539. this.nextPacket = function JpxImage_nextPacket() {
  39540. // Section B.12.1.2 Resolution-layer-component-position
  39541. for (; r <= maxDecompositionLevelsCount; r++) {
  39542. for (; l < layersCount; l++) {
  39543. for (; i < componentsCount; i++) {
  39544. var component = tile.components[i];
  39545. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  39546. continue;
  39547. }
  39548. var resolution = component.resolutions[r];
  39549. var numprecincts = resolution.precinctParameters.numprecincts;
  39550. for (; k < numprecincts;) {
  39551. var packet = createPacket(resolution, k, l);
  39552. k++;
  39553. return packet;
  39554. }
  39555. k = 0;
  39556. }
  39557. i = 0;
  39558. }
  39559. l = 0;
  39560. }
  39561. throw new Error('JPX Error: Out of packets');
  39562. };
  39563. }
  39564. function ResolutionPositionComponentLayerIterator(context) {
  39565. var siz = context.SIZ;
  39566. var tileIndex = context.currentTile.index;
  39567. var tile = context.tiles[tileIndex];
  39568. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  39569. var componentsCount = siz.Csiz;
  39570. var l, r, c, p;
  39571. var maxDecompositionLevelsCount = 0;
  39572. for (c = 0; c < componentsCount; c++) {
  39573. var component = tile.components[c];
  39574. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  39575. component.codingStyleParameters.decompositionLevelsCount);
  39576. }
  39577. var maxNumPrecinctsInLevel = new Int32Array(
  39578. maxDecompositionLevelsCount + 1);
  39579. for (r = 0; r <= maxDecompositionLevelsCount; ++r) {
  39580. var maxNumPrecincts = 0;
  39581. for (c = 0; c < componentsCount; ++c) {
  39582. var resolutions = tile.components[c].resolutions;
  39583. if (r < resolutions.length) {
  39584. maxNumPrecincts = Math.max(maxNumPrecincts,
  39585. resolutions[r].precinctParameters.numprecincts);
  39586. }
  39587. }
  39588. maxNumPrecinctsInLevel[r] = maxNumPrecincts;
  39589. }
  39590. l = 0;
  39591. r = 0;
  39592. c = 0;
  39593. p = 0;
  39594. this.nextPacket = function JpxImage_nextPacket() {
  39595. // Section B.12.1.3 Resolution-position-component-layer
  39596. for (; r <= maxDecompositionLevelsCount; r++) {
  39597. for (; p < maxNumPrecinctsInLevel[r]; p++) {
  39598. for (; c < componentsCount; c++) {
  39599. var component = tile.components[c];
  39600. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  39601. continue;
  39602. }
  39603. var resolution = component.resolutions[r];
  39604. var numprecincts = resolution.precinctParameters.numprecincts;
  39605. if (p >= numprecincts) {
  39606. continue;
  39607. }
  39608. for (; l < layersCount;) {
  39609. var packet = createPacket(resolution, p, l);
  39610. l++;
  39611. return packet;
  39612. }
  39613. l = 0;
  39614. }
  39615. c = 0;
  39616. }
  39617. p = 0;
  39618. }
  39619. throw new Error('JPX Error: Out of packets');
  39620. };
  39621. }
  39622. function PositionComponentResolutionLayerIterator(context) {
  39623. var siz = context.SIZ;
  39624. var tileIndex = context.currentTile.index;
  39625. var tile = context.tiles[tileIndex];
  39626. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  39627. var componentsCount = siz.Csiz;
  39628. var precinctsSizes = getPrecinctSizesInImageScale(tile);
  39629. var precinctsIterationSizes = precinctsSizes;
  39630. var l = 0, r = 0, c = 0, px = 0, py = 0;
  39631. this.nextPacket = function JpxImage_nextPacket() {
  39632. // Section B.12.1.4 Position-component-resolution-layer
  39633. for (; py < precinctsIterationSizes.maxNumHigh; py++) {
  39634. for (; px < precinctsIterationSizes.maxNumWide; px++) {
  39635. for (; c < componentsCount; c++) {
  39636. var component = tile.components[c];
  39637. var decompositionLevelsCount =
  39638. component.codingStyleParameters.decompositionLevelsCount;
  39639. for (; r <= decompositionLevelsCount; r++) {
  39640. var resolution = component.resolutions[r];
  39641. var sizeInImageScale =
  39642. precinctsSizes.components[c].resolutions[r];
  39643. var k = getPrecinctIndexIfExist(
  39644. px,
  39645. py,
  39646. sizeInImageScale,
  39647. precinctsIterationSizes,
  39648. resolution);
  39649. if (k === null) {
  39650. continue;
  39651. }
  39652. for (; l < layersCount;) {
  39653. var packet = createPacket(resolution, k, l);
  39654. l++;
  39655. return packet;
  39656. }
  39657. l = 0;
  39658. }
  39659. r = 0;
  39660. }
  39661. c = 0;
  39662. }
  39663. px = 0;
  39664. }
  39665. throw new Error('JPX Error: Out of packets');
  39666. };
  39667. }
  39668. function ComponentPositionResolutionLayerIterator(context) {
  39669. var siz = context.SIZ;
  39670. var tileIndex = context.currentTile.index;
  39671. var tile = context.tiles[tileIndex];
  39672. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  39673. var componentsCount = siz.Csiz;
  39674. var precinctsSizes = getPrecinctSizesInImageScale(tile);
  39675. var l = 0, r = 0, c = 0, px = 0, py = 0;
  39676. this.nextPacket = function JpxImage_nextPacket() {
  39677. // Section B.12.1.5 Component-position-resolution-layer
  39678. for (; c < componentsCount; ++c) {
  39679. var component = tile.components[c];
  39680. var precinctsIterationSizes = precinctsSizes.components[c];
  39681. var decompositionLevelsCount =
  39682. component.codingStyleParameters.decompositionLevelsCount;
  39683. for (; py < precinctsIterationSizes.maxNumHigh; py++) {
  39684. for (; px < precinctsIterationSizes.maxNumWide; px++) {
  39685. for (; r <= decompositionLevelsCount; r++) {
  39686. var resolution = component.resolutions[r];
  39687. var sizeInImageScale = precinctsIterationSizes.resolutions[r];
  39688. var k = getPrecinctIndexIfExist(
  39689. px,
  39690. py,
  39691. sizeInImageScale,
  39692. precinctsIterationSizes,
  39693. resolution);
  39694. if (k === null) {
  39695. continue;
  39696. }
  39697. for (; l < layersCount;) {
  39698. var packet = createPacket(resolution, k, l);
  39699. l++;
  39700. return packet;
  39701. }
  39702. l = 0;
  39703. }
  39704. r = 0;
  39705. }
  39706. px = 0;
  39707. }
  39708. py = 0;
  39709. }
  39710. throw new Error('JPX Error: Out of packets');
  39711. };
  39712. }
  39713. function getPrecinctIndexIfExist(
  39714. pxIndex, pyIndex, sizeInImageScale, precinctIterationSizes, resolution) {
  39715. var posX = pxIndex * precinctIterationSizes.minWidth;
  39716. var posY = pyIndex * precinctIterationSizes.minHeight;
  39717. if (posX % sizeInImageScale.width !== 0 ||
  39718. posY % sizeInImageScale.height !== 0) {
  39719. return null;
  39720. }
  39721. var startPrecinctRowIndex =
  39722. (posY / sizeInImageScale.width) *
  39723. resolution.precinctParameters.numprecinctswide;
  39724. return (posX / sizeInImageScale.height) + startPrecinctRowIndex;
  39725. }
  39726. function getPrecinctSizesInImageScale(tile) {
  39727. var componentsCount = tile.components.length;
  39728. var minWidth = Number.MAX_VALUE;
  39729. var minHeight = Number.MAX_VALUE;
  39730. var maxNumWide = 0;
  39731. var maxNumHigh = 0;
  39732. var sizePerComponent = new Array(componentsCount);
  39733. for (var c = 0; c < componentsCount; c++) {
  39734. var component = tile.components[c];
  39735. var decompositionLevelsCount =
  39736. component.codingStyleParameters.decompositionLevelsCount;
  39737. var sizePerResolution = new Array(decompositionLevelsCount + 1);
  39738. var minWidthCurrentComponent = Number.MAX_VALUE;
  39739. var minHeightCurrentComponent = Number.MAX_VALUE;
  39740. var maxNumWideCurrentComponent = 0;
  39741. var maxNumHighCurrentComponent = 0;
  39742. var scale = 1;
  39743. for (var r = decompositionLevelsCount; r >= 0; --r) {
  39744. var resolution = component.resolutions[r];
  39745. var widthCurrentResolution =
  39746. scale * resolution.precinctParameters.precinctWidth;
  39747. var heightCurrentResolution =
  39748. scale * resolution.precinctParameters.precinctHeight;
  39749. minWidthCurrentComponent = Math.min(
  39750. minWidthCurrentComponent,
  39751. widthCurrentResolution);
  39752. minHeightCurrentComponent = Math.min(
  39753. minHeightCurrentComponent,
  39754. heightCurrentResolution);
  39755. maxNumWideCurrentComponent = Math.max(maxNumWideCurrentComponent,
  39756. resolution.precinctParameters.numprecinctswide);
  39757. maxNumHighCurrentComponent = Math.max(maxNumHighCurrentComponent,
  39758. resolution.precinctParameters.numprecinctshigh);
  39759. sizePerResolution[r] = {
  39760. width: widthCurrentResolution,
  39761. height: heightCurrentResolution
  39762. };
  39763. scale <<= 1;
  39764. }
  39765. minWidth = Math.min(minWidth, minWidthCurrentComponent);
  39766. minHeight = Math.min(minHeight, minHeightCurrentComponent);
  39767. maxNumWide = Math.max(maxNumWide, maxNumWideCurrentComponent);
  39768. maxNumHigh = Math.max(maxNumHigh, maxNumHighCurrentComponent);
  39769. sizePerComponent[c] = {
  39770. resolutions: sizePerResolution,
  39771. minWidth: minWidthCurrentComponent,
  39772. minHeight: minHeightCurrentComponent,
  39773. maxNumWide: maxNumWideCurrentComponent,
  39774. maxNumHigh: maxNumHighCurrentComponent
  39775. };
  39776. }
  39777. return {
  39778. components: sizePerComponent,
  39779. minWidth: minWidth,
  39780. minHeight: minHeight,
  39781. maxNumWide: maxNumWide,
  39782. maxNumHigh: maxNumHigh
  39783. };
  39784. }
  39785. function buildPackets(context) {
  39786. var siz = context.SIZ;
  39787. var tileIndex = context.currentTile.index;
  39788. var tile = context.tiles[tileIndex];
  39789. var componentsCount = siz.Csiz;
  39790. // Creating resolutions and sub-bands for each component
  39791. for (var c = 0; c < componentsCount; c++) {
  39792. var component = tile.components[c];
  39793. var decompositionLevelsCount =
  39794. component.codingStyleParameters.decompositionLevelsCount;
  39795. // Section B.5 Resolution levels and sub-bands
  39796. var resolutions = [];
  39797. var subbands = [];
  39798. for (var r = 0; r <= decompositionLevelsCount; r++) {
  39799. var blocksDimensions = getBlocksDimensions(context, component, r);
  39800. var resolution = {};
  39801. var scale = 1 << (decompositionLevelsCount - r);
  39802. resolution.trx0 = Math.ceil(component.tcx0 / scale);
  39803. resolution.try0 = Math.ceil(component.tcy0 / scale);
  39804. resolution.trx1 = Math.ceil(component.tcx1 / scale);
  39805. resolution.try1 = Math.ceil(component.tcy1 / scale);
  39806. resolution.resLevel = r;
  39807. buildPrecincts(context, resolution, blocksDimensions);
  39808. resolutions.push(resolution);
  39809. var subband;
  39810. if (r === 0) {
  39811. // one sub-band (LL) with last decomposition
  39812. subband = {};
  39813. subband.type = 'LL';
  39814. subband.tbx0 = Math.ceil(component.tcx0 / scale);
  39815. subband.tby0 = Math.ceil(component.tcy0 / scale);
  39816. subband.tbx1 = Math.ceil(component.tcx1 / scale);
  39817. subband.tby1 = Math.ceil(component.tcy1 / scale);
  39818. subband.resolution = resolution;
  39819. buildCodeblocks(context, subband, blocksDimensions);
  39820. subbands.push(subband);
  39821. resolution.subbands = [subband];
  39822. } else {
  39823. var bscale = 1 << (decompositionLevelsCount - r + 1);
  39824. var resolutionSubbands = [];
  39825. // three sub-bands (HL, LH and HH) with rest of decompositions
  39826. subband = {};
  39827. subband.type = 'HL';
  39828. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  39829. subband.tby0 = Math.ceil(component.tcy0 / bscale);
  39830. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  39831. subband.tby1 = Math.ceil(component.tcy1 / bscale);
  39832. subband.resolution = resolution;
  39833. buildCodeblocks(context, subband, blocksDimensions);
  39834. subbands.push(subband);
  39835. resolutionSubbands.push(subband);
  39836. subband = {};
  39837. subband.type = 'LH';
  39838. subband.tbx0 = Math.ceil(component.tcx0 / bscale);
  39839. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  39840. subband.tbx1 = Math.ceil(component.tcx1 / bscale);
  39841. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  39842. subband.resolution = resolution;
  39843. buildCodeblocks(context, subband, blocksDimensions);
  39844. subbands.push(subband);
  39845. resolutionSubbands.push(subband);
  39846. subband = {};
  39847. subband.type = 'HH';
  39848. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  39849. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  39850. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  39851. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  39852. subband.resolution = resolution;
  39853. buildCodeblocks(context, subband, blocksDimensions);
  39854. subbands.push(subband);
  39855. resolutionSubbands.push(subband);
  39856. resolution.subbands = resolutionSubbands;
  39857. }
  39858. }
  39859. component.resolutions = resolutions;
  39860. component.subbands = subbands;
  39861. }
  39862. // Generate the packets sequence
  39863. var progressionOrder = tile.codingStyleDefaultParameters.progressionOrder;
  39864. switch (progressionOrder) {
  39865. case 0:
  39866. tile.packetsIterator =
  39867. new LayerResolutionComponentPositionIterator(context);
  39868. break;
  39869. case 1:
  39870. tile.packetsIterator =
  39871. new ResolutionLayerComponentPositionIterator(context);
  39872. break;
  39873. case 2:
  39874. tile.packetsIterator =
  39875. new ResolutionPositionComponentLayerIterator(context);
  39876. break;
  39877. case 3:
  39878. tile.packetsIterator =
  39879. new PositionComponentResolutionLayerIterator(context);
  39880. break;
  39881. case 4:
  39882. tile.packetsIterator =
  39883. new ComponentPositionResolutionLayerIterator(context);
  39884. break;
  39885. default:
  39886. throw new Error('JPX Error: Unsupported progression order ' +
  39887. progressionOrder);
  39888. }
  39889. }
  39890. function parseTilePackets(context, data, offset, dataLength) {
  39891. var position = 0;
  39892. var buffer, bufferSize = 0, skipNextBit = false;
  39893. function readBits(count) {
  39894. while (bufferSize < count) {
  39895. var b = data[offset + position];
  39896. position++;
  39897. if (skipNextBit) {
  39898. buffer = (buffer << 7) | b;
  39899. bufferSize += 7;
  39900. skipNextBit = false;
  39901. } else {
  39902. buffer = (buffer << 8) | b;
  39903. bufferSize += 8;
  39904. }
  39905. if (b === 0xFF) {
  39906. skipNextBit = true;
  39907. }
  39908. }
  39909. bufferSize -= count;
  39910. return (buffer >>> bufferSize) & ((1 << count) - 1);
  39911. }
  39912. function skipMarkerIfEqual(value) {
  39913. if (data[offset + position - 1] === 0xFF &&
  39914. data[offset + position] === value) {
  39915. skipBytes(1);
  39916. return true;
  39917. } else if (data[offset + position] === 0xFF &&
  39918. data[offset + position + 1] === value) {
  39919. skipBytes(2);
  39920. return true;
  39921. }
  39922. return false;
  39923. }
  39924. function skipBytes(count) {
  39925. position += count;
  39926. }
  39927. function alignToByte() {
  39928. bufferSize = 0;
  39929. if (skipNextBit) {
  39930. position++;
  39931. skipNextBit = false;
  39932. }
  39933. }
  39934. function readCodingpasses() {
  39935. if (readBits(1) === 0) {
  39936. return 1;
  39937. }
  39938. if (readBits(1) === 0) {
  39939. return 2;
  39940. }
  39941. var value = readBits(2);
  39942. if (value < 3) {
  39943. return value + 3;
  39944. }
  39945. value = readBits(5);
  39946. if (value < 31) {
  39947. return value + 6;
  39948. }
  39949. value = readBits(7);
  39950. return value + 37;
  39951. }
  39952. var tileIndex = context.currentTile.index;
  39953. var tile = context.tiles[tileIndex];
  39954. var sopMarkerUsed = context.COD.sopMarkerUsed;
  39955. var ephMarkerUsed = context.COD.ephMarkerUsed;
  39956. var packetsIterator = tile.packetsIterator;
  39957. while (position < dataLength) {
  39958. alignToByte();
  39959. if (sopMarkerUsed && skipMarkerIfEqual(0x91)) {
  39960. // Skip also marker segment length and packet sequence ID
  39961. skipBytes(4);
  39962. }
  39963. var packet = packetsIterator.nextPacket();
  39964. if (!readBits(1)) {
  39965. continue;
  39966. }
  39967. var layerNumber = packet.layerNumber;
  39968. var queue = [], codeblock;
  39969. for (var i = 0, ii = packet.codeblocks.length; i < ii; i++) {
  39970. codeblock = packet.codeblocks[i];
  39971. var precinct = codeblock.precinct;
  39972. var codeblockColumn = codeblock.cbx - precinct.cbxMin;
  39973. var codeblockRow = codeblock.cby - precinct.cbyMin;
  39974. var codeblockIncluded = false;
  39975. var firstTimeInclusion = false;
  39976. var valueReady;
  39977. if (codeblock['included'] !== undefined) {
  39978. codeblockIncluded = !!readBits(1);
  39979. } else {
  39980. // reading inclusion tree
  39981. precinct = codeblock.precinct;
  39982. var inclusionTree, zeroBitPlanesTree;
  39983. if (precinct['inclusionTree'] !== undefined) {
  39984. inclusionTree = precinct.inclusionTree;
  39985. } else {
  39986. // building inclusion and zero bit-planes trees
  39987. var width = precinct.cbxMax - precinct.cbxMin + 1;
  39988. var height = precinct.cbyMax - precinct.cbyMin + 1;
  39989. inclusionTree = new InclusionTree(width, height, layerNumber);
  39990. zeroBitPlanesTree = new TagTree(width, height);
  39991. precinct.inclusionTree = inclusionTree;
  39992. precinct.zeroBitPlanesTree = zeroBitPlanesTree;
  39993. }
  39994. if (inclusionTree.reset(codeblockColumn, codeblockRow, layerNumber)) {
  39995. while (true) {
  39996. if (readBits(1)) {
  39997. valueReady = !inclusionTree.nextLevel();
  39998. if (valueReady) {
  39999. codeblock.included = true;
  40000. codeblockIncluded = firstTimeInclusion = true;
  40001. break;
  40002. }
  40003. } else {
  40004. inclusionTree.incrementValue(layerNumber);
  40005. break;
  40006. }
  40007. }
  40008. }
  40009. }
  40010. if (!codeblockIncluded) {
  40011. continue;
  40012. }
  40013. if (firstTimeInclusion) {
  40014. zeroBitPlanesTree = precinct.zeroBitPlanesTree;
  40015. zeroBitPlanesTree.reset(codeblockColumn, codeblockRow);
  40016. while (true) {
  40017. if (readBits(1)) {
  40018. valueReady = !zeroBitPlanesTree.nextLevel();
  40019. if (valueReady) {
  40020. break;
  40021. }
  40022. } else {
  40023. zeroBitPlanesTree.incrementValue();
  40024. }
  40025. }
  40026. codeblock.zeroBitPlanes = zeroBitPlanesTree.value;
  40027. }
  40028. var codingpasses = readCodingpasses();
  40029. while (readBits(1)) {
  40030. codeblock.Lblock++;
  40031. }
  40032. var codingpassesLog2 = log2(codingpasses);
  40033. // rounding down log2
  40034. var bits = ((codingpasses < (1 << codingpassesLog2)) ?
  40035. codingpassesLog2 - 1 : codingpassesLog2) + codeblock.Lblock;
  40036. var codedDataLength = readBits(bits);
  40037. queue.push({
  40038. codeblock: codeblock,
  40039. codingpasses: codingpasses,
  40040. dataLength: codedDataLength
  40041. });
  40042. }
  40043. alignToByte();
  40044. if (ephMarkerUsed) {
  40045. skipMarkerIfEqual(0x92);
  40046. }
  40047. while (queue.length > 0) {
  40048. var packetItem = queue.shift();
  40049. codeblock = packetItem.codeblock;
  40050. if (codeblock['data'] === undefined) {
  40051. codeblock.data = [];
  40052. }
  40053. codeblock.data.push({
  40054. data: data,
  40055. start: offset + position,
  40056. end: offset + position + packetItem.dataLength,
  40057. codingpasses: packetItem.codingpasses
  40058. });
  40059. position += packetItem.dataLength;
  40060. }
  40061. }
  40062. return position;
  40063. }
  40064. function copyCoefficients(coefficients, levelWidth, levelHeight, subband,
  40065. delta, mb, reversible, segmentationSymbolUsed) {
  40066. var x0 = subband.tbx0;
  40067. var y0 = subband.tby0;
  40068. var width = subband.tbx1 - subband.tbx0;
  40069. var codeblocks = subband.codeblocks;
  40070. var right = subband.type.charAt(0) === 'H' ? 1 : 0;
  40071. var bottom = subband.type.charAt(1) === 'H' ? levelWidth : 0;
  40072. for (var i = 0, ii = codeblocks.length; i < ii; ++i) {
  40073. var codeblock = codeblocks[i];
  40074. var blockWidth = codeblock.tbx1_ - codeblock.tbx0_;
  40075. var blockHeight = codeblock.tby1_ - codeblock.tby0_;
  40076. if (blockWidth === 0 || blockHeight === 0) {
  40077. continue;
  40078. }
  40079. if (codeblock['data'] === undefined) {
  40080. continue;
  40081. }
  40082. var bitModel, currentCodingpassType;
  40083. bitModel = new BitModel(blockWidth, blockHeight, codeblock.subbandType,
  40084. codeblock.zeroBitPlanes, mb);
  40085. currentCodingpassType = 2; // first bit plane starts from cleanup
  40086. // collect data
  40087. var data = codeblock.data, totalLength = 0, codingpasses = 0;
  40088. var j, jj, dataItem;
  40089. for (j = 0, jj = data.length; j < jj; j++) {
  40090. dataItem = data[j];
  40091. totalLength += dataItem.end - dataItem.start;
  40092. codingpasses += dataItem.codingpasses;
  40093. }
  40094. var encodedData = new Uint8Array(totalLength);
  40095. var position = 0;
  40096. for (j = 0, jj = data.length; j < jj; j++) {
  40097. dataItem = data[j];
  40098. var chunk = dataItem.data.subarray(dataItem.start, dataItem.end);
  40099. encodedData.set(chunk, position);
  40100. position += chunk.length;
  40101. }
  40102. // decoding the item
  40103. var decoder = new ArithmeticDecoder(encodedData, 0, totalLength);
  40104. bitModel.setDecoder(decoder);
  40105. for (j = 0; j < codingpasses; j++) {
  40106. switch (currentCodingpassType) {
  40107. case 0:
  40108. bitModel.runSignificancePropogationPass();
  40109. break;
  40110. case 1:
  40111. bitModel.runMagnitudeRefinementPass();
  40112. break;
  40113. case 2:
  40114. bitModel.runCleanupPass();
  40115. if (segmentationSymbolUsed) {
  40116. bitModel.checkSegmentationSymbol();
  40117. }
  40118. break;
  40119. }
  40120. currentCodingpassType = (currentCodingpassType + 1) % 3;
  40121. }
  40122. var offset = (codeblock.tbx0_ - x0) + (codeblock.tby0_ - y0) * width;
  40123. var sign = bitModel.coefficentsSign;
  40124. var magnitude = bitModel.coefficentsMagnitude;
  40125. var bitsDecoded = bitModel.bitsDecoded;
  40126. var magnitudeCorrection = reversible ? 0 : 0.5;
  40127. var k, n, nb;
  40128. position = 0;
  40129. // Do the interleaving of Section F.3.3 here, so we do not need
  40130. // to copy later. LL level is not interleaved, just copied.
  40131. var interleave = (subband.type !== 'LL');
  40132. for (j = 0; j < blockHeight; j++) {
  40133. var row = (offset / width) | 0; // row in the non-interleaved subband
  40134. var levelOffset = 2 * row * (levelWidth - width) + right + bottom;
  40135. for (k = 0; k < blockWidth; k++) {
  40136. n = magnitude[position];
  40137. if (n !== 0) {
  40138. n = (n + magnitudeCorrection) * delta;
  40139. if (sign[position] !== 0) {
  40140. n = -n;
  40141. }
  40142. nb = bitsDecoded[position];
  40143. var pos = interleave ? (levelOffset + (offset << 1)) : offset;
  40144. if (reversible && (nb >= mb)) {
  40145. coefficients[pos] = n;
  40146. } else {
  40147. coefficients[pos] = n * (1 << (mb - nb));
  40148. }
  40149. }
  40150. offset++;
  40151. position++;
  40152. }
  40153. offset += width - blockWidth;
  40154. }
  40155. }
  40156. }
  40157. function transformTile(context, tile, c) {
  40158. var component = tile.components[c];
  40159. var codingStyleParameters = component.codingStyleParameters;
  40160. var quantizationParameters = component.quantizationParameters;
  40161. var decompositionLevelsCount =
  40162. codingStyleParameters.decompositionLevelsCount;
  40163. var spqcds = quantizationParameters.SPqcds;
  40164. var scalarExpounded = quantizationParameters.scalarExpounded;
  40165. var guardBits = quantizationParameters.guardBits;
  40166. var segmentationSymbolUsed = codingStyleParameters.segmentationSymbolUsed;
  40167. var precision = context.components[c].precision;
  40168. var reversible = codingStyleParameters.reversibleTransformation;
  40169. var transform = (reversible ? new ReversibleTransform() :
  40170. new IrreversibleTransform());
  40171. var subbandCoefficients = [];
  40172. var b = 0;
  40173. for (var i = 0; i <= decompositionLevelsCount; i++) {
  40174. var resolution = component.resolutions[i];
  40175. var width = resolution.trx1 - resolution.trx0;
  40176. var height = resolution.try1 - resolution.try0;
  40177. // Allocate space for the whole sublevel.
  40178. var coefficients = new Float32Array(width * height);
  40179. for (var j = 0, jj = resolution.subbands.length; j < jj; j++) {
  40180. var mu, epsilon;
  40181. if (!scalarExpounded) {
  40182. // formula E-5
  40183. mu = spqcds[0].mu;
  40184. epsilon = spqcds[0].epsilon + (i > 0 ? 1 - i : 0);
  40185. } else {
  40186. mu = spqcds[b].mu;
  40187. epsilon = spqcds[b].epsilon;
  40188. b++;
  40189. }
  40190. var subband = resolution.subbands[j];
  40191. var gainLog2 = SubbandsGainLog2[subband.type];
  40192. // calulate quantization coefficient (Section E.1.1.1)
  40193. var delta = (reversible ? 1 :
  40194. Math.pow(2, precision + gainLog2 - epsilon) * (1 + mu / 2048));
  40195. var mb = (guardBits + epsilon - 1);
  40196. // In the first resolution level, copyCoefficients will fill the
  40197. // whole array with coefficients. In the succeding passes,
  40198. // copyCoefficients will consecutively fill in the values that belong
  40199. // to the interleaved positions of the HL, LH, and HH coefficients.
  40200. // The LL coefficients will then be interleaved in Transform.iterate().
  40201. copyCoefficients(coefficients, width, height, subband, delta, mb,
  40202. reversible, segmentationSymbolUsed);
  40203. }
  40204. subbandCoefficients.push({
  40205. width: width,
  40206. height: height,
  40207. items: coefficients
  40208. });
  40209. }
  40210. var result = transform.calculate(subbandCoefficients,
  40211. component.tcx0, component.tcy0);
  40212. return {
  40213. left: component.tcx0,
  40214. top: component.tcy0,
  40215. width: result.width,
  40216. height: result.height,
  40217. items: result.items
  40218. };
  40219. }
  40220. function transformComponents(context) {
  40221. var siz = context.SIZ;
  40222. var components = context.components;
  40223. var componentsCount = siz.Csiz;
  40224. var resultImages = [];
  40225. for (var i = 0, ii = context.tiles.length; i < ii; i++) {
  40226. var tile = context.tiles[i];
  40227. var transformedTiles = [];
  40228. var c;
  40229. for (c = 0; c < componentsCount; c++) {
  40230. transformedTiles[c] = transformTile(context, tile, c);
  40231. }
  40232. var tile0 = transformedTiles[0];
  40233. var out = new Uint8Array(tile0.items.length * componentsCount);
  40234. var result = {
  40235. left: tile0.left,
  40236. top: tile0.top,
  40237. width: tile0.width,
  40238. height: tile0.height,
  40239. items: out
  40240. };
  40241. // Section G.2.2 Inverse multi component transform
  40242. var shift, offset, max, min, maxK;
  40243. var pos = 0, j, jj, y0, y1, y2, r, g, b, k, val;
  40244. if (tile.codingStyleDefaultParameters.multipleComponentTransform) {
  40245. var fourComponents = componentsCount === 4;
  40246. var y0items = transformedTiles[0].items;
  40247. var y1items = transformedTiles[1].items;
  40248. var y2items = transformedTiles[2].items;
  40249. var y3items = fourComponents ? transformedTiles[3].items : null;
  40250. // HACK: The multiple component transform formulas below assume that
  40251. // all components have the same precision. With this in mind, we
  40252. // compute shift and offset only once.
  40253. shift = components[0].precision - 8;
  40254. offset = (128 << shift) + 0.5;
  40255. max = 255 * (1 << shift);
  40256. maxK = max * 0.5;
  40257. min = -maxK;
  40258. var component0 = tile.components[0];
  40259. var alpha01 = componentsCount - 3;
  40260. jj = y0items.length;
  40261. if (!component0.codingStyleParameters.reversibleTransformation) {
  40262. // inverse irreversible multiple component transform
  40263. for (j = 0; j < jj; j++, pos += alpha01) {
  40264. y0 = y0items[j] + offset;
  40265. y1 = y1items[j];
  40266. y2 = y2items[j];
  40267. r = y0 + 1.402 * y2;
  40268. g = y0 - 0.34413 * y1 - 0.71414 * y2;
  40269. b = y0 + 1.772 * y1;
  40270. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  40271. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  40272. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  40273. }
  40274. } else {
  40275. // inverse reversible multiple component transform
  40276. for (j = 0; j < jj; j++, pos += alpha01) {
  40277. y0 = y0items[j] + offset;
  40278. y1 = y1items[j];
  40279. y2 = y2items[j];
  40280. g = y0 - ((y2 + y1) >> 2);
  40281. r = g + y2;
  40282. b = g + y1;
  40283. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  40284. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  40285. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  40286. }
  40287. }
  40288. if (fourComponents) {
  40289. for (j = 0, pos = 3; j < jj; j++, pos += 4) {
  40290. k = y3items[j];
  40291. out[pos] = k <= min ? 0 : k >= maxK ? 255 : (k + offset) >> shift;
  40292. }
  40293. }
  40294. } else { // no multi-component transform
  40295. for (c = 0; c < componentsCount; c++) {
  40296. var items = transformedTiles[c].items;
  40297. shift = components[c].precision - 8;
  40298. offset = (128 << shift) + 0.5;
  40299. max = (127.5 * (1 << shift));
  40300. min = -max;
  40301. for (pos = c, j = 0, jj = items.length; j < jj; j++) {
  40302. val = items[j];
  40303. out[pos] = val <= min ? 0 :
  40304. val >= max ? 255 : (val + offset) >> shift;
  40305. pos += componentsCount;
  40306. }
  40307. }
  40308. }
  40309. resultImages.push(result);
  40310. }
  40311. return resultImages;
  40312. }
  40313. function initializeTile(context, tileIndex) {
  40314. var siz = context.SIZ;
  40315. var componentsCount = siz.Csiz;
  40316. var tile = context.tiles[tileIndex];
  40317. for (var c = 0; c < componentsCount; c++) {
  40318. var component = tile.components[c];
  40319. var qcdOrQcc = (context.currentTile.QCC[c] !== undefined ?
  40320. context.currentTile.QCC[c] : context.currentTile.QCD);
  40321. component.quantizationParameters = qcdOrQcc;
  40322. var codOrCoc = (context.currentTile.COC[c] !== undefined ?
  40323. context.currentTile.COC[c] : context.currentTile.COD);
  40324. component.codingStyleParameters = codOrCoc;
  40325. }
  40326. tile.codingStyleDefaultParameters = context.currentTile.COD;
  40327. }
  40328. // Section B.10.2 Tag trees
  40329. var TagTree = (function TagTreeClosure() {
  40330. function TagTree(width, height) {
  40331. var levelsLength = log2(Math.max(width, height)) + 1;
  40332. this.levels = [];
  40333. for (var i = 0; i < levelsLength; i++) {
  40334. var level = {
  40335. width: width,
  40336. height: height,
  40337. items: []
  40338. };
  40339. this.levels.push(level);
  40340. width = Math.ceil(width / 2);
  40341. height = Math.ceil(height / 2);
  40342. }
  40343. }
  40344. TagTree.prototype = {
  40345. reset: function TagTree_reset(i, j) {
  40346. var currentLevel = 0, value = 0, level;
  40347. while (currentLevel < this.levels.length) {
  40348. level = this.levels[currentLevel];
  40349. var index = i + j * level.width;
  40350. if (level.items[index] !== undefined) {
  40351. value = level.items[index];
  40352. break;
  40353. }
  40354. level.index = index;
  40355. i >>= 1;
  40356. j >>= 1;
  40357. currentLevel++;
  40358. }
  40359. currentLevel--;
  40360. level = this.levels[currentLevel];
  40361. level.items[level.index] = value;
  40362. this.currentLevel = currentLevel;
  40363. delete this.value;
  40364. },
  40365. incrementValue: function TagTree_incrementValue() {
  40366. var level = this.levels[this.currentLevel];
  40367. level.items[level.index]++;
  40368. },
  40369. nextLevel: function TagTree_nextLevel() {
  40370. var currentLevel = this.currentLevel;
  40371. var level = this.levels[currentLevel];
  40372. var value = level.items[level.index];
  40373. currentLevel--;
  40374. if (currentLevel < 0) {
  40375. this.value = value;
  40376. return false;
  40377. }
  40378. this.currentLevel = currentLevel;
  40379. level = this.levels[currentLevel];
  40380. level.items[level.index] = value;
  40381. return true;
  40382. }
  40383. };
  40384. return TagTree;
  40385. })();
  40386. var InclusionTree = (function InclusionTreeClosure() {
  40387. function InclusionTree(width, height, defaultValue) {
  40388. var levelsLength = log2(Math.max(width, height)) + 1;
  40389. this.levels = [];
  40390. for (var i = 0; i < levelsLength; i++) {
  40391. var items = new Uint8Array(width * height);
  40392. for (var j = 0, jj = items.length; j < jj; j++) {
  40393. items[j] = defaultValue;
  40394. }
  40395. var level = {
  40396. width: width,
  40397. height: height,
  40398. items: items
  40399. };
  40400. this.levels.push(level);
  40401. width = Math.ceil(width / 2);
  40402. height = Math.ceil(height / 2);
  40403. }
  40404. }
  40405. InclusionTree.prototype = {
  40406. reset: function InclusionTree_reset(i, j, stopValue) {
  40407. var currentLevel = 0;
  40408. while (currentLevel < this.levels.length) {
  40409. var level = this.levels[currentLevel];
  40410. var index = i + j * level.width;
  40411. level.index = index;
  40412. var value = level.items[index];
  40413. if (value === 0xFF) {
  40414. break;
  40415. }
  40416. if (value > stopValue) {
  40417. this.currentLevel = currentLevel;
  40418. // already know about this one, propagating the value to top levels
  40419. this.propagateValues();
  40420. return false;
  40421. }
  40422. i >>= 1;
  40423. j >>= 1;
  40424. currentLevel++;
  40425. }
  40426. this.currentLevel = currentLevel - 1;
  40427. return true;
  40428. },
  40429. incrementValue: function InclusionTree_incrementValue(stopValue) {
  40430. var level = this.levels[this.currentLevel];
  40431. level.items[level.index] = stopValue + 1;
  40432. this.propagateValues();
  40433. },
  40434. propagateValues: function InclusionTree_propagateValues() {
  40435. var levelIndex = this.currentLevel;
  40436. var level = this.levels[levelIndex];
  40437. var currentValue = level.items[level.index];
  40438. while (--levelIndex >= 0) {
  40439. level = this.levels[levelIndex];
  40440. level.items[level.index] = currentValue;
  40441. }
  40442. },
  40443. nextLevel: function InclusionTree_nextLevel() {
  40444. var currentLevel = this.currentLevel;
  40445. var level = this.levels[currentLevel];
  40446. var value = level.items[level.index];
  40447. level.items[level.index] = 0xFF;
  40448. currentLevel--;
  40449. if (currentLevel < 0) {
  40450. return false;
  40451. }
  40452. this.currentLevel = currentLevel;
  40453. level = this.levels[currentLevel];
  40454. level.items[level.index] = value;
  40455. return true;
  40456. }
  40457. };
  40458. return InclusionTree;
  40459. })();
  40460. // Section D. Coefficient bit modeling
  40461. var BitModel = (function BitModelClosure() {
  40462. var UNIFORM_CONTEXT = 17;
  40463. var RUNLENGTH_CONTEXT = 18;
  40464. // Table D-1
  40465. // The index is binary presentation: 0dddvvhh, ddd - sum of Di (0..4),
  40466. // vv - sum of Vi (0..2), and hh - sum of Hi (0..2)
  40467. var LLAndLHContextsLabel = new Uint8Array([
  40468. 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,
  40469. 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,
  40470. 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
  40471. ]);
  40472. var HLContextLabel = new Uint8Array([
  40473. 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,
  40474. 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,
  40475. 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
  40476. ]);
  40477. var HHContextLabel = new Uint8Array([
  40478. 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,
  40479. 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,
  40480. 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
  40481. ]);
  40482. function BitModel(width, height, subband, zeroBitPlanes, mb) {
  40483. this.width = width;
  40484. this.height = height;
  40485. this.contextLabelTable = (subband === 'HH' ? HHContextLabel :
  40486. (subband === 'HL' ? HLContextLabel : LLAndLHContextsLabel));
  40487. var coefficientCount = width * height;
  40488. // coefficients outside the encoding region treated as insignificant
  40489. // add border state cells for significanceState
  40490. this.neighborsSignificance = new Uint8Array(coefficientCount);
  40491. this.coefficentsSign = new Uint8Array(coefficientCount);
  40492. this.coefficentsMagnitude = mb > 14 ? new Uint32Array(coefficientCount) :
  40493. mb > 6 ? new Uint16Array(coefficientCount) :
  40494. new Uint8Array(coefficientCount);
  40495. this.processingFlags = new Uint8Array(coefficientCount);
  40496. var bitsDecoded = new Uint8Array(coefficientCount);
  40497. if (zeroBitPlanes !== 0) {
  40498. for (var i = 0; i < coefficientCount; i++) {
  40499. bitsDecoded[i] = zeroBitPlanes;
  40500. }
  40501. }
  40502. this.bitsDecoded = bitsDecoded;
  40503. this.reset();
  40504. }
  40505. BitModel.prototype = {
  40506. setDecoder: function BitModel_setDecoder(decoder) {
  40507. this.decoder = decoder;
  40508. },
  40509. reset: function BitModel_reset() {
  40510. // We have 17 contexts that are accessed via context labels,
  40511. // plus the uniform and runlength context.
  40512. this.contexts = new Int8Array(19);
  40513. // Contexts are packed into 1 byte:
  40514. // highest 7 bits carry the index, lowest bit carries mps
  40515. this.contexts[0] = (4 << 1) | 0;
  40516. this.contexts[UNIFORM_CONTEXT] = (46 << 1) | 0;
  40517. this.contexts[RUNLENGTH_CONTEXT] = (3 << 1) | 0;
  40518. },
  40519. setNeighborsSignificance:
  40520. function BitModel_setNeighborsSignificance(row, column, index) {
  40521. var neighborsSignificance = this.neighborsSignificance;
  40522. var width = this.width, height = this.height;
  40523. var left = (column > 0);
  40524. var right = (column + 1 < width);
  40525. var i;
  40526. if (row > 0) {
  40527. i = index - width;
  40528. if (left) {
  40529. neighborsSignificance[i - 1] += 0x10;
  40530. }
  40531. if (right) {
  40532. neighborsSignificance[i + 1] += 0x10;
  40533. }
  40534. neighborsSignificance[i] += 0x04;
  40535. }
  40536. if (row + 1 < height) {
  40537. i = index + width;
  40538. if (left) {
  40539. neighborsSignificance[i - 1] += 0x10;
  40540. }
  40541. if (right) {
  40542. neighborsSignificance[i + 1] += 0x10;
  40543. }
  40544. neighborsSignificance[i] += 0x04;
  40545. }
  40546. if (left) {
  40547. neighborsSignificance[index - 1] += 0x01;
  40548. }
  40549. if (right) {
  40550. neighborsSignificance[index + 1] += 0x01;
  40551. }
  40552. neighborsSignificance[index] |= 0x80;
  40553. },
  40554. runSignificancePropogationPass:
  40555. function BitModel_runSignificancePropogationPass() {
  40556. var decoder = this.decoder;
  40557. var width = this.width, height = this.height;
  40558. var coefficentsMagnitude = this.coefficentsMagnitude;
  40559. var coefficentsSign = this.coefficentsSign;
  40560. var neighborsSignificance = this.neighborsSignificance;
  40561. var processingFlags = this.processingFlags;
  40562. var contexts = this.contexts;
  40563. var labels = this.contextLabelTable;
  40564. var bitsDecoded = this.bitsDecoded;
  40565. var processedInverseMask = ~1;
  40566. var processedMask = 1;
  40567. var firstMagnitudeBitMask = 2;
  40568. for (var i0 = 0; i0 < height; i0 += 4) {
  40569. for (var j = 0; j < width; j++) {
  40570. var index = i0 * width + j;
  40571. for (var i1 = 0; i1 < 4; i1++, index += width) {
  40572. var i = i0 + i1;
  40573. if (i >= height) {
  40574. break;
  40575. }
  40576. // clear processed flag first
  40577. processingFlags[index] &= processedInverseMask;
  40578. if (coefficentsMagnitude[index] ||
  40579. !neighborsSignificance[index]) {
  40580. continue;
  40581. }
  40582. var contextLabel = labels[neighborsSignificance[index]];
  40583. var decision = decoder.readBit(contexts, contextLabel);
  40584. if (decision) {
  40585. var sign = this.decodeSignBit(i, j, index);
  40586. coefficentsSign[index] = sign;
  40587. coefficentsMagnitude[index] = 1;
  40588. this.setNeighborsSignificance(i, j, index);
  40589. processingFlags[index] |= firstMagnitudeBitMask;
  40590. }
  40591. bitsDecoded[index]++;
  40592. processingFlags[index] |= processedMask;
  40593. }
  40594. }
  40595. }
  40596. },
  40597. decodeSignBit: function BitModel_decodeSignBit(row, column, index) {
  40598. var width = this.width, height = this.height;
  40599. var coefficentsMagnitude = this.coefficentsMagnitude;
  40600. var coefficentsSign = this.coefficentsSign;
  40601. var contribution, sign0, sign1, significance1;
  40602. var contextLabel, decoded;
  40603. // calculate horizontal contribution
  40604. significance1 = (column > 0 && coefficentsMagnitude[index - 1] !== 0);
  40605. if (column + 1 < width && coefficentsMagnitude[index + 1] !== 0) {
  40606. sign1 = coefficentsSign[index + 1];
  40607. if (significance1) {
  40608. sign0 = coefficentsSign[index - 1];
  40609. contribution = 1 - sign1 - sign0;
  40610. } else {
  40611. contribution = 1 - sign1 - sign1;
  40612. }
  40613. } else if (significance1) {
  40614. sign0 = coefficentsSign[index - 1];
  40615. contribution = 1 - sign0 - sign0;
  40616. } else {
  40617. contribution = 0;
  40618. }
  40619. var horizontalContribution = 3 * contribution;
  40620. // calculate vertical contribution and combine with the horizontal
  40621. significance1 = (row > 0 && coefficentsMagnitude[index - width] !== 0);
  40622. if (row + 1 < height && coefficentsMagnitude[index + width] !== 0) {
  40623. sign1 = coefficentsSign[index + width];
  40624. if (significance1) {
  40625. sign0 = coefficentsSign[index - width];
  40626. contribution = 1 - sign1 - sign0 + horizontalContribution;
  40627. } else {
  40628. contribution = 1 - sign1 - sign1 + horizontalContribution;
  40629. }
  40630. } else if (significance1) {
  40631. sign0 = coefficentsSign[index - width];
  40632. contribution = 1 - sign0 - sign0 + horizontalContribution;
  40633. } else {
  40634. contribution = horizontalContribution;
  40635. }
  40636. if (contribution >= 0) {
  40637. contextLabel = 9 + contribution;
  40638. decoded = this.decoder.readBit(this.contexts, contextLabel);
  40639. } else {
  40640. contextLabel = 9 - contribution;
  40641. decoded = this.decoder.readBit(this.contexts, contextLabel) ^ 1;
  40642. }
  40643. return decoded;
  40644. },
  40645. runMagnitudeRefinementPass:
  40646. function BitModel_runMagnitudeRefinementPass() {
  40647. var decoder = this.decoder;
  40648. var width = this.width, height = this.height;
  40649. var coefficentsMagnitude = this.coefficentsMagnitude;
  40650. var neighborsSignificance = this.neighborsSignificance;
  40651. var contexts = this.contexts;
  40652. var bitsDecoded = this.bitsDecoded;
  40653. var processingFlags = this.processingFlags;
  40654. var processedMask = 1;
  40655. var firstMagnitudeBitMask = 2;
  40656. var length = width * height;
  40657. var width4 = width * 4;
  40658. for (var index0 = 0, indexNext; index0 < length; index0 = indexNext) {
  40659. indexNext = Math.min(length, index0 + width4);
  40660. for (var j = 0; j < width; j++) {
  40661. for (var index = index0 + j; index < indexNext; index += width) {
  40662. // significant but not those that have just become
  40663. if (!coefficentsMagnitude[index] ||
  40664. (processingFlags[index] & processedMask) !== 0) {
  40665. continue;
  40666. }
  40667. var contextLabel = 16;
  40668. if ((processingFlags[index] & firstMagnitudeBitMask) !== 0) {
  40669. processingFlags[index] ^= firstMagnitudeBitMask;
  40670. // first refinement
  40671. var significance = neighborsSignificance[index] & 127;
  40672. contextLabel = significance === 0 ? 15 : 14;
  40673. }
  40674. var bit = decoder.readBit(contexts, contextLabel);
  40675. coefficentsMagnitude[index] =
  40676. (coefficentsMagnitude[index] << 1) | bit;
  40677. bitsDecoded[index]++;
  40678. processingFlags[index] |= processedMask;
  40679. }
  40680. }
  40681. }
  40682. },
  40683. runCleanupPass: function BitModel_runCleanupPass() {
  40684. var decoder = this.decoder;
  40685. var width = this.width, height = this.height;
  40686. var neighborsSignificance = this.neighborsSignificance;
  40687. var coefficentsMagnitude = this.coefficentsMagnitude;
  40688. var coefficentsSign = this.coefficentsSign;
  40689. var contexts = this.contexts;
  40690. var labels = this.contextLabelTable;
  40691. var bitsDecoded = this.bitsDecoded;
  40692. var processingFlags = this.processingFlags;
  40693. var processedMask = 1;
  40694. var firstMagnitudeBitMask = 2;
  40695. var oneRowDown = width;
  40696. var twoRowsDown = width * 2;
  40697. var threeRowsDown = width * 3;
  40698. var iNext;
  40699. for (var i0 = 0; i0 < height; i0 = iNext) {
  40700. iNext = Math.min(i0 + 4, height);
  40701. var indexBase = i0 * width;
  40702. var checkAllEmpty = i0 + 3 < height;
  40703. for (var j = 0; j < width; j++) {
  40704. var index0 = indexBase + j;
  40705. // using the property: labels[neighborsSignificance[index]] === 0
  40706. // when neighborsSignificance[index] === 0
  40707. var allEmpty = (checkAllEmpty &&
  40708. processingFlags[index0] === 0 &&
  40709. processingFlags[index0 + oneRowDown] === 0 &&
  40710. processingFlags[index0 + twoRowsDown] === 0 &&
  40711. processingFlags[index0 + threeRowsDown] === 0 &&
  40712. neighborsSignificance[index0] === 0 &&
  40713. neighborsSignificance[index0 + oneRowDown] === 0 &&
  40714. neighborsSignificance[index0 + twoRowsDown] === 0 &&
  40715. neighborsSignificance[index0 + threeRowsDown] === 0);
  40716. var i1 = 0, index = index0;
  40717. var i = i0, sign;
  40718. if (allEmpty) {
  40719. var hasSignificantCoefficent =
  40720. decoder.readBit(contexts, RUNLENGTH_CONTEXT);
  40721. if (!hasSignificantCoefficent) {
  40722. bitsDecoded[index0]++;
  40723. bitsDecoded[index0 + oneRowDown]++;
  40724. bitsDecoded[index0 + twoRowsDown]++;
  40725. bitsDecoded[index0 + threeRowsDown]++;
  40726. continue; // next column
  40727. }
  40728. i1 = (decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
  40729. decoder.readBit(contexts, UNIFORM_CONTEXT);
  40730. if (i1 !== 0) {
  40731. i = i0 + i1;
  40732. index += i1 * width;
  40733. }
  40734. sign = this.decodeSignBit(i, j, index);
  40735. coefficentsSign[index] = sign;
  40736. coefficentsMagnitude[index] = 1;
  40737. this.setNeighborsSignificance(i, j, index);
  40738. processingFlags[index] |= firstMagnitudeBitMask;
  40739. index = index0;
  40740. for (var i2 = i0; i2 <= i; i2++, index += width) {
  40741. bitsDecoded[index]++;
  40742. }
  40743. i1++;
  40744. }
  40745. for (i = i0 + i1; i < iNext; i++, index += width) {
  40746. if (coefficentsMagnitude[index] ||
  40747. (processingFlags[index] & processedMask) !== 0) {
  40748. continue;
  40749. }
  40750. var contextLabel = labels[neighborsSignificance[index]];
  40751. var decision = decoder.readBit(contexts, contextLabel);
  40752. if (decision === 1) {
  40753. sign = this.decodeSignBit(i, j, index);
  40754. coefficentsSign[index] = sign;
  40755. coefficentsMagnitude[index] = 1;
  40756. this.setNeighborsSignificance(i, j, index);
  40757. processingFlags[index] |= firstMagnitudeBitMask;
  40758. }
  40759. bitsDecoded[index]++;
  40760. }
  40761. }
  40762. }
  40763. },
  40764. checkSegmentationSymbol: function BitModel_checkSegmentationSymbol() {
  40765. var decoder = this.decoder;
  40766. var contexts = this.contexts;
  40767. var symbol = (decoder.readBit(contexts, UNIFORM_CONTEXT) << 3) |
  40768. (decoder.readBit(contexts, UNIFORM_CONTEXT) << 2) |
  40769. (decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
  40770. decoder.readBit(contexts, UNIFORM_CONTEXT);
  40771. if (symbol !== 0xA) {
  40772. throw new Error('JPX Error: Invalid segmentation symbol');
  40773. }
  40774. }
  40775. };
  40776. return BitModel;
  40777. })();
  40778. // Section F, Discrete wavelet transformation
  40779. var Transform = (function TransformClosure() {
  40780. function Transform() {}
  40781. Transform.prototype.calculate =
  40782. function transformCalculate(subbands, u0, v0) {
  40783. var ll = subbands[0];
  40784. for (var i = 1, ii = subbands.length; i < ii; i++) {
  40785. ll = this.iterate(ll, subbands[i], u0, v0);
  40786. }
  40787. return ll;
  40788. };
  40789. Transform.prototype.extend = function extend(buffer, offset, size) {
  40790. // Section F.3.7 extending... using max extension of 4
  40791. var i1 = offset - 1, j1 = offset + 1;
  40792. var i2 = offset + size - 2, j2 = offset + size;
  40793. buffer[i1--] = buffer[j1++];
  40794. buffer[j2++] = buffer[i2--];
  40795. buffer[i1--] = buffer[j1++];
  40796. buffer[j2++] = buffer[i2--];
  40797. buffer[i1--] = buffer[j1++];
  40798. buffer[j2++] = buffer[i2--];
  40799. buffer[i1] = buffer[j1];
  40800. buffer[j2] = buffer[i2];
  40801. };
  40802. Transform.prototype.iterate = function Transform_iterate(ll, hl_lh_hh,
  40803. u0, v0) {
  40804. var llWidth = ll.width, llHeight = ll.height, llItems = ll.items;
  40805. var width = hl_lh_hh.width;
  40806. var height = hl_lh_hh.height;
  40807. var items = hl_lh_hh.items;
  40808. var i, j, k, l, u, v;
  40809. // Interleave LL according to Section F.3.3
  40810. for (k = 0, i = 0; i < llHeight; i++) {
  40811. l = i * 2 * width;
  40812. for (j = 0; j < llWidth; j++, k++, l += 2) {
  40813. items[l] = llItems[k];
  40814. }
  40815. }
  40816. // The LL band is not needed anymore.
  40817. llItems = ll.items = null;
  40818. var bufferPadding = 4;
  40819. var rowBuffer = new Float32Array(width + 2 * bufferPadding);
  40820. // Section F.3.4 HOR_SR
  40821. if (width === 1) {
  40822. // if width = 1, when u0 even keep items as is, when odd divide by 2
  40823. if ((u0 & 1) !== 0) {
  40824. for (v = 0, k = 0; v < height; v++, k += width) {
  40825. items[k] *= 0.5;
  40826. }
  40827. }
  40828. } else {
  40829. for (v = 0, k = 0; v < height; v++, k += width) {
  40830. rowBuffer.set(items.subarray(k, k + width), bufferPadding);
  40831. this.extend(rowBuffer, bufferPadding, width);
  40832. this.filter(rowBuffer, bufferPadding, width);
  40833. items.set(
  40834. rowBuffer.subarray(bufferPadding, bufferPadding + width),
  40835. k);
  40836. }
  40837. }
  40838. // Accesses to the items array can take long, because it may not fit into
  40839. // CPU cache and has to be fetched from main memory. Since subsequent
  40840. // accesses to the items array are not local when reading columns, we
  40841. // have a cache miss every time. To reduce cache misses, get up to
  40842. // 'numBuffers' items at a time and store them into the individual
  40843. // buffers. The colBuffers should be small enough to fit into CPU cache.
  40844. var numBuffers = 16;
  40845. var colBuffers = [];
  40846. for (i = 0; i < numBuffers; i++) {
  40847. colBuffers.push(new Float32Array(height + 2 * bufferPadding));
  40848. }
  40849. var b, currentBuffer = 0;
  40850. ll = bufferPadding + height;
  40851. // Section F.3.5 VER_SR
  40852. if (height === 1) {
  40853. // if height = 1, when v0 even keep items as is, when odd divide by 2
  40854. if ((v0 & 1) !== 0) {
  40855. for (u = 0; u < width; u++) {
  40856. items[u] *= 0.5;
  40857. }
  40858. }
  40859. } else {
  40860. for (u = 0; u < width; u++) {
  40861. // if we ran out of buffers, copy several image columns at once
  40862. if (currentBuffer === 0) {
  40863. numBuffers = Math.min(width - u, numBuffers);
  40864. for (k = u, l = bufferPadding; l < ll; k += width, l++) {
  40865. for (b = 0; b < numBuffers; b++) {
  40866. colBuffers[b][l] = items[k + b];
  40867. }
  40868. }
  40869. currentBuffer = numBuffers;
  40870. }
  40871. currentBuffer--;
  40872. var buffer = colBuffers[currentBuffer];
  40873. this.extend(buffer, bufferPadding, height);
  40874. this.filter(buffer, bufferPadding, height);
  40875. // If this is last buffer in this group of buffers, flush all buffers.
  40876. if (currentBuffer === 0) {
  40877. k = u - numBuffers + 1;
  40878. for (l = bufferPadding; l < ll; k += width, l++) {
  40879. for (b = 0; b < numBuffers; b++) {
  40880. items[k + b] = colBuffers[b][l];
  40881. }
  40882. }
  40883. }
  40884. }
  40885. }
  40886. return {
  40887. width: width,
  40888. height: height,
  40889. items: items
  40890. };
  40891. };
  40892. return Transform;
  40893. })();
  40894. // Section 3.8.2 Irreversible 9-7 filter
  40895. var IrreversibleTransform = (function IrreversibleTransformClosure() {
  40896. function IrreversibleTransform() {
  40897. Transform.call(this);
  40898. }
  40899. IrreversibleTransform.prototype = Object.create(Transform.prototype);
  40900. IrreversibleTransform.prototype.filter =
  40901. function irreversibleTransformFilter(x, offset, length) {
  40902. var len = length >> 1;
  40903. offset = offset | 0;
  40904. var j, n, current, next;
  40905. var alpha = -1.586134342059924;
  40906. var beta = -0.052980118572961;
  40907. var gamma = 0.882911075530934;
  40908. var delta = 0.443506852043971;
  40909. var K = 1.230174104914001;
  40910. var K_ = 1 / K;
  40911. // step 1 is combined with step 3
  40912. // step 2
  40913. j = offset - 3;
  40914. for (n = len + 4; n--; j += 2) {
  40915. x[j] *= K_;
  40916. }
  40917. // step 1 & 3
  40918. j = offset - 2;
  40919. current = delta * x[j -1];
  40920. for (n = len + 3; n--; j += 2) {
  40921. next = delta * x[j + 1];
  40922. x[j] = K * x[j] - current - next;
  40923. if (n--) {
  40924. j += 2;
  40925. current = delta * x[j + 1];
  40926. x[j] = K * x[j] - current - next;
  40927. } else {
  40928. break;
  40929. }
  40930. }
  40931. // step 4
  40932. j = offset - 1;
  40933. current = gamma * x[j - 1];
  40934. for (n = len + 2; n--; j += 2) {
  40935. next = gamma * x[j + 1];
  40936. x[j] -= current + next;
  40937. if (n--) {
  40938. j += 2;
  40939. current = gamma * x[j + 1];
  40940. x[j] -= current + next;
  40941. } else {
  40942. break;
  40943. }
  40944. }
  40945. // step 5
  40946. j = offset;
  40947. current = beta * x[j - 1];
  40948. for (n = len + 1; n--; j += 2) {
  40949. next = beta * x[j + 1];
  40950. x[j] -= current + next;
  40951. if (n--) {
  40952. j += 2;
  40953. current = beta * x[j + 1];
  40954. x[j] -= current + next;
  40955. } else {
  40956. break;
  40957. }
  40958. }
  40959. // step 6
  40960. if (len !== 0) {
  40961. j = offset + 1;
  40962. current = alpha * x[j - 1];
  40963. for (n = len; n--; j += 2) {
  40964. next = alpha * x[j + 1];
  40965. x[j] -= current + next;
  40966. if (n--) {
  40967. j += 2;
  40968. current = alpha * x[j + 1];
  40969. x[j] -= current + next;
  40970. } else {
  40971. break;
  40972. }
  40973. }
  40974. }
  40975. };
  40976. return IrreversibleTransform;
  40977. })();
  40978. // Section 3.8.1 Reversible 5-3 filter
  40979. var ReversibleTransform = (function ReversibleTransformClosure() {
  40980. function ReversibleTransform() {
  40981. Transform.call(this);
  40982. }
  40983. ReversibleTransform.prototype = Object.create(Transform.prototype);
  40984. ReversibleTransform.prototype.filter =
  40985. function reversibleTransformFilter(x, offset, length) {
  40986. var len = length >> 1;
  40987. offset = offset | 0;
  40988. var j, n;
  40989. for (j = offset, n = len + 1; n--; j += 2) {
  40990. x[j] -= (x[j - 1] + x[j + 1] + 2) >> 2;
  40991. }
  40992. for (j = offset + 1, n = len; n--; j += 2) {
  40993. x[j] += (x[j - 1] + x[j + 1]) >> 1;
  40994. }
  40995. };
  40996. return ReversibleTransform;
  40997. })();
  40998. return JpxImage;
  40999. })();
  41000. var Jbig2Image = (function Jbig2ImageClosure() {
  41001. // Utility data structures
  41002. function ContextCache() {}
  41003. ContextCache.prototype = {
  41004. getContexts: function(id) {
  41005. if (id in this) {
  41006. return this[id];
  41007. }
  41008. return (this[id] = new Int8Array(1 << 16));
  41009. }
  41010. };
  41011. function DecodingContext(data, start, end) {
  41012. this.data = data;
  41013. this.start = start;
  41014. this.end = end;
  41015. }
  41016. DecodingContext.prototype = {
  41017. get decoder() {
  41018. var decoder = new ArithmeticDecoder(this.data, this.start, this.end);
  41019. return shadow(this, 'decoder', decoder);
  41020. },
  41021. get contextCache() {
  41022. var cache = new ContextCache();
  41023. return shadow(this, 'contextCache', cache);
  41024. }
  41025. };
  41026. // Annex A. Arithmetic Integer Decoding Procedure
  41027. // A.2 Procedure for decoding values
  41028. function decodeInteger(contextCache, procedure, decoder) {
  41029. var contexts = contextCache.getContexts(procedure);
  41030. var prev = 1;
  41031. function readBits(length) {
  41032. var v = 0;
  41033. for (var i = 0; i < length; i++) {
  41034. var bit = decoder.readBit(contexts, prev);
  41035. prev = (prev < 256 ? (prev << 1) | bit :
  41036. (((prev << 1) | bit) & 511) | 256);
  41037. v = (v << 1) | bit;
  41038. }
  41039. return v >>> 0;
  41040. }
  41041. var sign = readBits(1);
  41042. var value = readBits(1) ?
  41043. (readBits(1) ?
  41044. (readBits(1) ?
  41045. (readBits(1) ?
  41046. (readBits(1) ?
  41047. (readBits(32) + 4436) :
  41048. readBits(12) + 340) :
  41049. readBits(8) + 84) :
  41050. readBits(6) + 20) :
  41051. readBits(4) + 4) :
  41052. readBits(2);
  41053. return (sign === 0 ? value : (value > 0 ? -value : null));
  41054. }
  41055. // A.3 The IAID decoding procedure
  41056. function decodeIAID(contextCache, decoder, codeLength) {
  41057. var contexts = contextCache.getContexts('IAID');
  41058. var prev = 1;
  41059. for (var i = 0; i < codeLength; i++) {
  41060. var bit = decoder.readBit(contexts, prev);
  41061. prev = (prev << 1) | bit;
  41062. }
  41063. if (codeLength < 31) {
  41064. return prev & ((1 << codeLength) - 1);
  41065. }
  41066. return prev & 0x7FFFFFFF;
  41067. }
  41068. // 7.3 Segment types
  41069. var SegmentTypes = [
  41070. 'SymbolDictionary', null, null, null, 'IntermediateTextRegion', null,
  41071. 'ImmediateTextRegion', 'ImmediateLosslessTextRegion', null, null, null,
  41072. null, null, null, null, null, 'patternDictionary', null, null, null,
  41073. 'IntermediateHalftoneRegion', null, 'ImmediateHalftoneRegion',
  41074. 'ImmediateLosslessHalftoneRegion', null, null, null, null, null, null, null,
  41075. null, null, null, null, null, 'IntermediateGenericRegion', null,
  41076. 'ImmediateGenericRegion', 'ImmediateLosslessGenericRegion',
  41077. 'IntermediateGenericRefinementRegion', null,
  41078. 'ImmediateGenericRefinementRegion',
  41079. 'ImmediateLosslessGenericRefinementRegion', null, null, null, null,
  41080. 'PageInformation', 'EndOfPage', 'EndOfStripe', 'EndOfFile', 'Profiles',
  41081. 'Tables', null, null, null, null, null, null, null, null,
  41082. 'Extension'
  41083. ];
  41084. var CodingTemplates = [
  41085. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: -2, y: -1},
  41086. {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: 2, y: -1},
  41087. {x: -4, y: 0}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}],
  41088. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: 2, y: -2},
  41089. {x: -2, y: -1}, {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1},
  41090. {x: 2, y: -1}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}],
  41091. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: -2, y: -1},
  41092. {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: -2, y: 0},
  41093. {x: -1, y: 0}],
  41094. [{x: -3, y: -1}, {x: -2, y: -1}, {x: -1, y: -1}, {x: 0, y: -1},
  41095. {x: 1, y: -1}, {x: -4, y: 0}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}]
  41096. ];
  41097. var RefinementTemplates = [
  41098. {
  41099. coding: [{x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}],
  41100. reference: [{x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}, {x: 0, y: 0},
  41101. {x: 1, y: 0}, {x: -1, y: 1}, {x: 0, y: 1}, {x: 1, y: 1}]
  41102. },
  41103. {
  41104. coding: [{x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}],
  41105. reference: [{x: 0, y: -1}, {x: -1, y: 0}, {x: 0, y: 0}, {x: 1, y: 0},
  41106. {x: 0, y: 1}, {x: 1, y: 1}]
  41107. }
  41108. ];
  41109. // See 6.2.5.7 Decoding the bitmap.
  41110. var ReusedContexts = [
  41111. 0x9B25, // 10011 0110010 0101
  41112. 0x0795, // 0011 110010 101
  41113. 0x00E5, // 001 11001 01
  41114. 0x0195 // 011001 0101
  41115. ];
  41116. var RefinementReusedContexts = [
  41117. 0x0020, // '000' + '0' (coding) + '00010000' + '0' (reference)
  41118. 0x0008 // '0000' + '001000'
  41119. ];
  41120. function decodeBitmapTemplate0(width, height, decodingContext) {
  41121. var decoder = decodingContext.decoder;
  41122. var contexts = decodingContext.contextCache.getContexts('GB');
  41123. var contextLabel, i, j, pixel, row, row1, row2, bitmap = [];
  41124. // ...ooooo....
  41125. // ..ooooooo... Context template for current pixel (X)
  41126. // .ooooX...... (concatenate values of 'o'-pixels to get contextLabel)
  41127. var OLD_PIXEL_MASK = 0x7BF7; // 01111 0111111 0111
  41128. for (i = 0; i < height; i++) {
  41129. row = bitmap[i] = new Uint8Array(width);
  41130. row1 = (i < 1) ? row : bitmap[i - 1];
  41131. row2 = (i < 2) ? row : bitmap[i - 2];
  41132. // At the beginning of each row:
  41133. // Fill contextLabel with pixels that are above/right of (X)
  41134. contextLabel = (row2[0] << 13) | (row2[1] << 12) | (row2[2] << 11) |
  41135. (row1[0] << 7) | (row1[1] << 6) | (row1[2] << 5) |
  41136. (row1[3] << 4);
  41137. for (j = 0; j < width; j++) {
  41138. row[j] = pixel = decoder.readBit(contexts, contextLabel);
  41139. // At each pixel: Clear contextLabel pixels that are shifted
  41140. // out of the context, then add new ones.
  41141. contextLabel = ((contextLabel & OLD_PIXEL_MASK) << 1) |
  41142. (j + 3 < width ? row2[j + 3] << 11 : 0) |
  41143. (j + 4 < width ? row1[j + 4] << 4 : 0) | pixel;
  41144. }
  41145. }
  41146. return bitmap;
  41147. }
  41148. // 6.2 Generic Region Decoding Procedure
  41149. function decodeBitmap(mmr, width, height, templateIndex, prediction, skip, at,
  41150. decodingContext) {
  41151. if (mmr) {
  41152. error('JBIG2 error: MMR encoding is not supported');
  41153. }
  41154. // Use optimized version for the most common case
  41155. if (templateIndex === 0 && !skip && !prediction && at.length === 4 &&
  41156. at[0].x === 3 && at[0].y === -1 && at[1].x === -3 && at[1].y === -1 &&
  41157. at[2].x === 2 && at[2].y === -2 && at[3].x === -2 && at[3].y === -2) {
  41158. return decodeBitmapTemplate0(width, height, decodingContext);
  41159. }
  41160. var useskip = !!skip;
  41161. var template = CodingTemplates[templateIndex].concat(at);
  41162. // Sorting is non-standard, and it is not required. But sorting increases
  41163. // the number of template bits that can be reused from the previous
  41164. // contextLabel in the main loop.
  41165. template.sort(function (a, b) {
  41166. return (a.y - b.y) || (a.x - b.x);
  41167. });
  41168. var templateLength = template.length;
  41169. var templateX = new Int8Array(templateLength);
  41170. var templateY = new Int8Array(templateLength);
  41171. var changingTemplateEntries = [];
  41172. var reuseMask = 0, minX = 0, maxX = 0, minY = 0;
  41173. var c, k;
  41174. for (k = 0; k < templateLength; k++) {
  41175. templateX[k] = template[k].x;
  41176. templateY[k] = template[k].y;
  41177. minX = Math.min(minX, template[k].x);
  41178. maxX = Math.max(maxX, template[k].x);
  41179. minY = Math.min(minY, template[k].y);
  41180. // Check if the template pixel appears in two consecutive context labels,
  41181. // so it can be reused. Otherwise, we add it to the list of changing
  41182. // template entries.
  41183. if (k < templateLength - 1 &&
  41184. template[k].y === template[k + 1].y &&
  41185. template[k].x === template[k + 1].x - 1) {
  41186. reuseMask |= 1 << (templateLength - 1 - k);
  41187. } else {
  41188. changingTemplateEntries.push(k);
  41189. }
  41190. }
  41191. var changingEntriesLength = changingTemplateEntries.length;
  41192. var changingTemplateX = new Int8Array(changingEntriesLength);
  41193. var changingTemplateY = new Int8Array(changingEntriesLength);
  41194. var changingTemplateBit = new Uint16Array(changingEntriesLength);
  41195. for (c = 0; c < changingEntriesLength; c++) {
  41196. k = changingTemplateEntries[c];
  41197. changingTemplateX[c] = template[k].x;
  41198. changingTemplateY[c] = template[k].y;
  41199. changingTemplateBit[c] = 1 << (templateLength - 1 - k);
  41200. }
  41201. // Get the safe bounding box edges from the width, height, minX, maxX, minY
  41202. var sbb_left = -minX;
  41203. var sbb_top = -minY;
  41204. var sbb_right = width - maxX;
  41205. var pseudoPixelContext = ReusedContexts[templateIndex];
  41206. var row = new Uint8Array(width);
  41207. var bitmap = [];
  41208. var decoder = decodingContext.decoder;
  41209. var contexts = decodingContext.contextCache.getContexts('GB');
  41210. var ltp = 0, j, i0, j0, contextLabel = 0, bit, shift;
  41211. for (var i = 0; i < height; i++) {
  41212. if (prediction) {
  41213. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  41214. ltp ^= sltp;
  41215. if (ltp) {
  41216. bitmap.push(row); // duplicate previous row
  41217. continue;
  41218. }
  41219. }
  41220. row = new Uint8Array(row);
  41221. bitmap.push(row);
  41222. for (j = 0; j < width; j++) {
  41223. if (useskip && skip[i][j]) {
  41224. row[j] = 0;
  41225. continue;
  41226. }
  41227. // Are we in the middle of a scanline, so we can reuse contextLabel
  41228. // bits?
  41229. if (j >= sbb_left && j < sbb_right && i >= sbb_top) {
  41230. // If yes, we can just shift the bits that are reusable and only
  41231. // fetch the remaining ones.
  41232. contextLabel = (contextLabel << 1) & reuseMask;
  41233. for (k = 0; k < changingEntriesLength; k++) {
  41234. i0 = i + changingTemplateY[k];
  41235. j0 = j + changingTemplateX[k];
  41236. bit = bitmap[i0][j0];
  41237. if (bit) {
  41238. bit = changingTemplateBit[k];
  41239. contextLabel |= bit;
  41240. }
  41241. }
  41242. } else {
  41243. // compute the contextLabel from scratch
  41244. contextLabel = 0;
  41245. shift = templateLength - 1;
  41246. for (k = 0; k < templateLength; k++, shift--) {
  41247. j0 = j + templateX[k];
  41248. if (j0 >= 0 && j0 < width) {
  41249. i0 = i + templateY[k];
  41250. if (i0 >= 0) {
  41251. bit = bitmap[i0][j0];
  41252. if (bit) {
  41253. contextLabel |= bit << shift;
  41254. }
  41255. }
  41256. }
  41257. }
  41258. }
  41259. var pixel = decoder.readBit(contexts, contextLabel);
  41260. row[j] = pixel;
  41261. }
  41262. }
  41263. return bitmap;
  41264. }
  41265. // 6.3.2 Generic Refinement Region Decoding Procedure
  41266. function decodeRefinement(width, height, templateIndex, referenceBitmap,
  41267. offsetX, offsetY, prediction, at,
  41268. decodingContext) {
  41269. var codingTemplate = RefinementTemplates[templateIndex].coding;
  41270. if (templateIndex === 0) {
  41271. codingTemplate = codingTemplate.concat([at[0]]);
  41272. }
  41273. var codingTemplateLength = codingTemplate.length;
  41274. var codingTemplateX = new Int32Array(codingTemplateLength);
  41275. var codingTemplateY = new Int32Array(codingTemplateLength);
  41276. var k;
  41277. for (k = 0; k < codingTemplateLength; k++) {
  41278. codingTemplateX[k] = codingTemplate[k].x;
  41279. codingTemplateY[k] = codingTemplate[k].y;
  41280. }
  41281. var referenceTemplate = RefinementTemplates[templateIndex].reference;
  41282. if (templateIndex === 0) {
  41283. referenceTemplate = referenceTemplate.concat([at[1]]);
  41284. }
  41285. var referenceTemplateLength = referenceTemplate.length;
  41286. var referenceTemplateX = new Int32Array(referenceTemplateLength);
  41287. var referenceTemplateY = new Int32Array(referenceTemplateLength);
  41288. for (k = 0; k < referenceTemplateLength; k++) {
  41289. referenceTemplateX[k] = referenceTemplate[k].x;
  41290. referenceTemplateY[k] = referenceTemplate[k].y;
  41291. }
  41292. var referenceWidth = referenceBitmap[0].length;
  41293. var referenceHeight = referenceBitmap.length;
  41294. var pseudoPixelContext = RefinementReusedContexts[templateIndex];
  41295. var bitmap = [];
  41296. var decoder = decodingContext.decoder;
  41297. var contexts = decodingContext.contextCache.getContexts('GR');
  41298. var ltp = 0;
  41299. for (var i = 0; i < height; i++) {
  41300. if (prediction) {
  41301. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  41302. ltp ^= sltp;
  41303. if (ltp) {
  41304. error('JBIG2 error: prediction is not supported');
  41305. }
  41306. }
  41307. var row = new Uint8Array(width);
  41308. bitmap.push(row);
  41309. for (var j = 0; j < width; j++) {
  41310. var i0, j0;
  41311. var contextLabel = 0;
  41312. for (k = 0; k < codingTemplateLength; k++) {
  41313. i0 = i + codingTemplateY[k];
  41314. j0 = j + codingTemplateX[k];
  41315. if (i0 < 0 || j0 < 0 || j0 >= width) {
  41316. contextLabel <<= 1; // out of bound pixel
  41317. } else {
  41318. contextLabel = (contextLabel << 1) | bitmap[i0][j0];
  41319. }
  41320. }
  41321. for (k = 0; k < referenceTemplateLength; k++) {
  41322. i0 = i + referenceTemplateY[k] + offsetY;
  41323. j0 = j + referenceTemplateX[k] + offsetX;
  41324. if (i0 < 0 || i0 >= referenceHeight || j0 < 0 ||
  41325. j0 >= referenceWidth) {
  41326. contextLabel <<= 1; // out of bound pixel
  41327. } else {
  41328. contextLabel = (contextLabel << 1) | referenceBitmap[i0][j0];
  41329. }
  41330. }
  41331. var pixel = decoder.readBit(contexts, contextLabel);
  41332. row[j] = pixel;
  41333. }
  41334. }
  41335. return bitmap;
  41336. }
  41337. // 6.5.5 Decoding the symbol dictionary
  41338. function decodeSymbolDictionary(huffman, refinement, symbols,
  41339. numberOfNewSymbols, numberOfExportedSymbols,
  41340. huffmanTables, templateIndex, at,
  41341. refinementTemplateIndex, refinementAt,
  41342. decodingContext) {
  41343. if (huffman) {
  41344. error('JBIG2 error: huffman is not supported');
  41345. }
  41346. var newSymbols = [];
  41347. var currentHeight = 0;
  41348. var symbolCodeLength = log2(symbols.length + numberOfNewSymbols);
  41349. var decoder = decodingContext.decoder;
  41350. var contextCache = decodingContext.contextCache;
  41351. while (newSymbols.length < numberOfNewSymbols) {
  41352. var deltaHeight = decodeInteger(contextCache, 'IADH', decoder); // 6.5.6
  41353. currentHeight += deltaHeight;
  41354. var currentWidth = 0;
  41355. var totalWidth = 0;
  41356. while (true) {
  41357. var deltaWidth = decodeInteger(contextCache, 'IADW', decoder); // 6.5.7
  41358. if (deltaWidth === null) {
  41359. break; // OOB
  41360. }
  41361. currentWidth += deltaWidth;
  41362. totalWidth += currentWidth;
  41363. var bitmap;
  41364. if (refinement) {
  41365. // 6.5.8.2 Refinement/aggregate-coded symbol bitmap
  41366. var numberOfInstances = decodeInteger(contextCache, 'IAAI', decoder);
  41367. if (numberOfInstances > 1) {
  41368. bitmap = decodeTextRegion(huffman, refinement,
  41369. currentWidth, currentHeight, 0,
  41370. numberOfInstances, 1, //strip size
  41371. symbols.concat(newSymbols),
  41372. symbolCodeLength,
  41373. 0, //transposed
  41374. 0, //ds offset
  41375. 1, //top left 7.4.3.1.1
  41376. 0, //OR operator
  41377. huffmanTables,
  41378. refinementTemplateIndex, refinementAt,
  41379. decodingContext);
  41380. } else {
  41381. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  41382. var rdx = decodeInteger(contextCache, 'IARDX', decoder); // 6.4.11.3
  41383. var rdy = decodeInteger(contextCache, 'IARDY', decoder); // 6.4.11.4
  41384. var symbol = (symbolId < symbols.length ? symbols[symbolId] :
  41385. newSymbols[symbolId - symbols.length]);
  41386. bitmap = decodeRefinement(currentWidth, currentHeight,
  41387. refinementTemplateIndex, symbol, rdx, rdy, false, refinementAt,
  41388. decodingContext);
  41389. }
  41390. } else {
  41391. // 6.5.8.1 Direct-coded symbol bitmap
  41392. bitmap = decodeBitmap(false, currentWidth, currentHeight,
  41393. templateIndex, false, null, at, decodingContext);
  41394. }
  41395. newSymbols.push(bitmap);
  41396. }
  41397. }
  41398. // 6.5.10 Exported symbols
  41399. var exportedSymbols = [];
  41400. var flags = [], currentFlag = false;
  41401. var totalSymbolsLength = symbols.length + numberOfNewSymbols;
  41402. while (flags.length < totalSymbolsLength) {
  41403. var runLength = decodeInteger(contextCache, 'IAEX', decoder);
  41404. while (runLength--) {
  41405. flags.push(currentFlag);
  41406. }
  41407. currentFlag = !currentFlag;
  41408. }
  41409. for (var i = 0, ii = symbols.length; i < ii; i++) {
  41410. if (flags[i]) {
  41411. exportedSymbols.push(symbols[i]);
  41412. }
  41413. }
  41414. for (var j = 0; j < numberOfNewSymbols; i++, j++) {
  41415. if (flags[i]) {
  41416. exportedSymbols.push(newSymbols[j]);
  41417. }
  41418. }
  41419. return exportedSymbols;
  41420. }
  41421. function decodeTextRegion(huffman, refinement, width, height,
  41422. defaultPixelValue, numberOfSymbolInstances,
  41423. stripSize, inputSymbols, symbolCodeLength,
  41424. transposed, dsOffset, referenceCorner,
  41425. combinationOperator, huffmanTables,
  41426. refinementTemplateIndex, refinementAt,
  41427. decodingContext) {
  41428. if (huffman) {
  41429. error('JBIG2 error: huffman is not supported');
  41430. }
  41431. // Prepare bitmap
  41432. var bitmap = [];
  41433. var i, row;
  41434. for (i = 0; i < height; i++) {
  41435. row = new Uint8Array(width);
  41436. if (defaultPixelValue) {
  41437. for (var j = 0; j < width; j++) {
  41438. row[j] = defaultPixelValue;
  41439. }
  41440. }
  41441. bitmap.push(row);
  41442. }
  41443. var decoder = decodingContext.decoder;
  41444. var contextCache = decodingContext.contextCache;
  41445. var stripT = -decodeInteger(contextCache, 'IADT', decoder); // 6.4.6
  41446. var firstS = 0;
  41447. i = 0;
  41448. while (i < numberOfSymbolInstances) {
  41449. var deltaT = decodeInteger(contextCache, 'IADT', decoder); // 6.4.6
  41450. stripT += deltaT;
  41451. var deltaFirstS = decodeInteger(contextCache, 'IAFS', decoder); // 6.4.7
  41452. firstS += deltaFirstS;
  41453. var currentS = firstS;
  41454. do {
  41455. var currentT = (stripSize === 1 ? 0 :
  41456. decodeInteger(contextCache, 'IAIT', decoder)); // 6.4.9
  41457. var t = stripSize * stripT + currentT;
  41458. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  41459. var applyRefinement = (refinement &&
  41460. decodeInteger(contextCache, 'IARI', decoder));
  41461. var symbolBitmap = inputSymbols[symbolId];
  41462. var symbolWidth = symbolBitmap[0].length;
  41463. var symbolHeight = symbolBitmap.length;
  41464. if (applyRefinement) {
  41465. var rdw = decodeInteger(contextCache, 'IARDW', decoder); // 6.4.11.1
  41466. var rdh = decodeInteger(contextCache, 'IARDH', decoder); // 6.4.11.2
  41467. var rdx = decodeInteger(contextCache, 'IARDX', decoder); // 6.4.11.3
  41468. var rdy = decodeInteger(contextCache, 'IARDY', decoder); // 6.4.11.4
  41469. symbolWidth += rdw;
  41470. symbolHeight += rdh;
  41471. symbolBitmap = decodeRefinement(symbolWidth, symbolHeight,
  41472. refinementTemplateIndex, symbolBitmap, (rdw >> 1) + rdx,
  41473. (rdh >> 1) + rdy, false, refinementAt,
  41474. decodingContext);
  41475. }
  41476. var offsetT = t - ((referenceCorner & 1) ? 0 : symbolHeight);
  41477. var offsetS = currentS - ((referenceCorner & 2) ? symbolWidth : 0);
  41478. var s2, t2, symbolRow;
  41479. if (transposed) {
  41480. // Place Symbol Bitmap from T1,S1
  41481. for (s2 = 0; s2 < symbolHeight; s2++) {
  41482. row = bitmap[offsetS + s2];
  41483. if (!row) {
  41484. continue;
  41485. }
  41486. symbolRow = symbolBitmap[s2];
  41487. // To ignore Parts of Symbol bitmap which goes
  41488. // outside bitmap region
  41489. var maxWidth = Math.min(width - offsetT, symbolWidth);
  41490. switch (combinationOperator) {
  41491. case 0: // OR
  41492. for (t2 = 0; t2 < maxWidth; t2++) {
  41493. row[offsetT + t2] |= symbolRow[t2];
  41494. }
  41495. break;
  41496. case 2: // XOR
  41497. for (t2 = 0; t2 < maxWidth; t2++) {
  41498. row[offsetT + t2] ^= symbolRow[t2];
  41499. }
  41500. break;
  41501. default:
  41502. error('JBIG2 error: operator ' + combinationOperator +
  41503. ' is not supported');
  41504. }
  41505. }
  41506. currentS += symbolHeight - 1;
  41507. } else {
  41508. for (t2 = 0; t2 < symbolHeight; t2++) {
  41509. row = bitmap[offsetT + t2];
  41510. if (!row) {
  41511. continue;
  41512. }
  41513. symbolRow = symbolBitmap[t2];
  41514. switch (combinationOperator) {
  41515. case 0: // OR
  41516. for (s2 = 0; s2 < symbolWidth; s2++) {
  41517. row[offsetS + s2] |= symbolRow[s2];
  41518. }
  41519. break;
  41520. case 2: // XOR
  41521. for (s2 = 0; s2 < symbolWidth; s2++) {
  41522. row[offsetS + s2] ^= symbolRow[s2];
  41523. }
  41524. break;
  41525. default:
  41526. error('JBIG2 error: operator ' + combinationOperator +
  41527. ' is not supported');
  41528. }
  41529. }
  41530. currentS += symbolWidth - 1;
  41531. }
  41532. i++;
  41533. var deltaS = decodeInteger(contextCache, 'IADS', decoder); // 6.4.8
  41534. if (deltaS === null) {
  41535. break; // OOB
  41536. }
  41537. currentS += deltaS + dsOffset;
  41538. } while (true);
  41539. }
  41540. return bitmap;
  41541. }
  41542. function readSegmentHeader(data, start) {
  41543. var segmentHeader = {};
  41544. segmentHeader.number = readUint32(data, start);
  41545. var flags = data[start + 4];
  41546. var segmentType = flags & 0x3F;
  41547. if (!SegmentTypes[segmentType]) {
  41548. error('JBIG2 error: invalid segment type: ' + segmentType);
  41549. }
  41550. segmentHeader.type = segmentType;
  41551. segmentHeader.typeName = SegmentTypes[segmentType];
  41552. segmentHeader.deferredNonRetain = !!(flags & 0x80);
  41553. var pageAssociationFieldSize = !!(flags & 0x40);
  41554. var referredFlags = data[start + 5];
  41555. var referredToCount = (referredFlags >> 5) & 7;
  41556. var retainBits = [referredFlags & 31];
  41557. var position = start + 6;
  41558. if (referredFlags === 7) {
  41559. referredToCount = readUint32(data, position - 1) & 0x1FFFFFFF;
  41560. position += 3;
  41561. var bytes = (referredToCount + 7) >> 3;
  41562. retainBits[0] = data[position++];
  41563. while (--bytes > 0) {
  41564. retainBits.push(data[position++]);
  41565. }
  41566. } else if (referredFlags === 5 || referredFlags === 6) {
  41567. error('JBIG2 error: invalid referred-to flags');
  41568. }
  41569. segmentHeader.retainBits = retainBits;
  41570. var referredToSegmentNumberSize = (segmentHeader.number <= 256 ? 1 :
  41571. (segmentHeader.number <= 65536 ? 2 : 4));
  41572. var referredTo = [];
  41573. var i, ii;
  41574. for (i = 0; i < referredToCount; i++) {
  41575. var number = (referredToSegmentNumberSize === 1 ? data[position] :
  41576. (referredToSegmentNumberSize === 2 ? readUint16(data, position) :
  41577. readUint32(data, position)));
  41578. referredTo.push(number);
  41579. position += referredToSegmentNumberSize;
  41580. }
  41581. segmentHeader.referredTo = referredTo;
  41582. if (!pageAssociationFieldSize) {
  41583. segmentHeader.pageAssociation = data[position++];
  41584. } else {
  41585. segmentHeader.pageAssociation = readUint32(data, position);
  41586. position += 4;
  41587. }
  41588. segmentHeader.length = readUint32(data, position);
  41589. position += 4;
  41590. if (segmentHeader.length === 0xFFFFFFFF) {
  41591. // 7.2.7 Segment data length, unknown segment length
  41592. if (segmentType === 38) { // ImmediateGenericRegion
  41593. var genericRegionInfo = readRegionSegmentInformation(data, position);
  41594. var genericRegionSegmentFlags = data[position +
  41595. RegionSegmentInformationFieldLength];
  41596. var genericRegionMmr = !!(genericRegionSegmentFlags & 1);
  41597. // searching for the segment end
  41598. var searchPatternLength = 6;
  41599. var searchPattern = new Uint8Array(searchPatternLength);
  41600. if (!genericRegionMmr) {
  41601. searchPattern[0] = 0xFF;
  41602. searchPattern[1] = 0xAC;
  41603. }
  41604. searchPattern[2] = (genericRegionInfo.height >>> 24) & 0xFF;
  41605. searchPattern[3] = (genericRegionInfo.height >> 16) & 0xFF;
  41606. searchPattern[4] = (genericRegionInfo.height >> 8) & 0xFF;
  41607. searchPattern[5] = genericRegionInfo.height & 0xFF;
  41608. for (i = position, ii = data.length; i < ii; i++) {
  41609. var j = 0;
  41610. while (j < searchPatternLength && searchPattern[j] === data[i + j]) {
  41611. j++;
  41612. }
  41613. if (j === searchPatternLength) {
  41614. segmentHeader.length = i + searchPatternLength;
  41615. break;
  41616. }
  41617. }
  41618. if (segmentHeader.length === 0xFFFFFFFF) {
  41619. error('JBIG2 error: segment end was not found');
  41620. }
  41621. } else {
  41622. error('JBIG2 error: invalid unknown segment length');
  41623. }
  41624. }
  41625. segmentHeader.headerEnd = position;
  41626. return segmentHeader;
  41627. }
  41628. function readSegments(header, data, start, end) {
  41629. var segments = [];
  41630. var position = start;
  41631. while (position < end) {
  41632. var segmentHeader = readSegmentHeader(data, position);
  41633. position = segmentHeader.headerEnd;
  41634. var segment = {
  41635. header: segmentHeader,
  41636. data: data
  41637. };
  41638. if (!header.randomAccess) {
  41639. segment.start = position;
  41640. position += segmentHeader.length;
  41641. segment.end = position;
  41642. }
  41643. segments.push(segment);
  41644. if (segmentHeader.type === 51) {
  41645. break; // end of file is found
  41646. }
  41647. }
  41648. if (header.randomAccess) {
  41649. for (var i = 0, ii = segments.length; i < ii; i++) {
  41650. segments[i].start = position;
  41651. position += segments[i].header.length;
  41652. segments[i].end = position;
  41653. }
  41654. }
  41655. return segments;
  41656. }
  41657. // 7.4.1 Region segment information field
  41658. function readRegionSegmentInformation(data, start) {
  41659. return {
  41660. width: readUint32(data, start),
  41661. height: readUint32(data, start + 4),
  41662. x: readUint32(data, start + 8),
  41663. y: readUint32(data, start + 12),
  41664. combinationOperator: data[start + 16] & 7
  41665. };
  41666. }
  41667. var RegionSegmentInformationFieldLength = 17;
  41668. function processSegment(segment, visitor) {
  41669. var header = segment.header;
  41670. var data = segment.data, position = segment.start, end = segment.end;
  41671. var args, at, i, atLength;
  41672. switch (header.type) {
  41673. case 0: // SymbolDictionary
  41674. // 7.4.2 Symbol dictionary segment syntax
  41675. var dictionary = {};
  41676. var dictionaryFlags = readUint16(data, position); // 7.4.2.1.1
  41677. dictionary.huffman = !!(dictionaryFlags & 1);
  41678. dictionary.refinement = !!(dictionaryFlags & 2);
  41679. dictionary.huffmanDHSelector = (dictionaryFlags >> 2) & 3;
  41680. dictionary.huffmanDWSelector = (dictionaryFlags >> 4) & 3;
  41681. dictionary.bitmapSizeSelector = (dictionaryFlags >> 6) & 1;
  41682. dictionary.aggregationInstancesSelector = (dictionaryFlags >> 7) & 1;
  41683. dictionary.bitmapCodingContextUsed = !!(dictionaryFlags & 256);
  41684. dictionary.bitmapCodingContextRetained = !!(dictionaryFlags & 512);
  41685. dictionary.template = (dictionaryFlags >> 10) & 3;
  41686. dictionary.refinementTemplate = (dictionaryFlags >> 12) & 1;
  41687. position += 2;
  41688. if (!dictionary.huffman) {
  41689. atLength = dictionary.template === 0 ? 4 : 1;
  41690. at = [];
  41691. for (i = 0; i < atLength; i++) {
  41692. at.push({
  41693. x: readInt8(data, position),
  41694. y: readInt8(data, position + 1)
  41695. });
  41696. position += 2;
  41697. }
  41698. dictionary.at = at;
  41699. }
  41700. if (dictionary.refinement && !dictionary.refinementTemplate) {
  41701. at = [];
  41702. for (i = 0; i < 2; i++) {
  41703. at.push({
  41704. x: readInt8(data, position),
  41705. y: readInt8(data, position + 1)
  41706. });
  41707. position += 2;
  41708. }
  41709. dictionary.refinementAt = at;
  41710. }
  41711. dictionary.numberOfExportedSymbols = readUint32(data, position);
  41712. position += 4;
  41713. dictionary.numberOfNewSymbols = readUint32(data, position);
  41714. position += 4;
  41715. args = [dictionary, header.number, header.referredTo,
  41716. data, position, end];
  41717. break;
  41718. case 6: // ImmediateTextRegion
  41719. case 7: // ImmediateLosslessTextRegion
  41720. var textRegion = {};
  41721. textRegion.info = readRegionSegmentInformation(data, position);
  41722. position += RegionSegmentInformationFieldLength;
  41723. var textRegionSegmentFlags = readUint16(data, position);
  41724. position += 2;
  41725. textRegion.huffman = !!(textRegionSegmentFlags & 1);
  41726. textRegion.refinement = !!(textRegionSegmentFlags & 2);
  41727. textRegion.stripSize = 1 << ((textRegionSegmentFlags >> 2) & 3);
  41728. textRegion.referenceCorner = (textRegionSegmentFlags >> 4) & 3;
  41729. textRegion.transposed = !!(textRegionSegmentFlags & 64);
  41730. textRegion.combinationOperator = (textRegionSegmentFlags >> 7) & 3;
  41731. textRegion.defaultPixelValue = (textRegionSegmentFlags >> 9) & 1;
  41732. textRegion.dsOffset = (textRegionSegmentFlags << 17) >> 27;
  41733. textRegion.refinementTemplate = (textRegionSegmentFlags >> 15) & 1;
  41734. if (textRegion.huffman) {
  41735. var textRegionHuffmanFlags = readUint16(data, position);
  41736. position += 2;
  41737. textRegion.huffmanFS = (textRegionHuffmanFlags) & 3;
  41738. textRegion.huffmanDS = (textRegionHuffmanFlags >> 2) & 3;
  41739. textRegion.huffmanDT = (textRegionHuffmanFlags >> 4) & 3;
  41740. textRegion.huffmanRefinementDW = (textRegionHuffmanFlags >> 6) & 3;
  41741. textRegion.huffmanRefinementDH = (textRegionHuffmanFlags >> 8) & 3;
  41742. textRegion.huffmanRefinementDX = (textRegionHuffmanFlags >> 10) & 3;
  41743. textRegion.huffmanRefinementDY = (textRegionHuffmanFlags >> 12) & 3;
  41744. textRegion.huffmanRefinementSizeSelector =
  41745. !!(textRegionHuffmanFlags & 14);
  41746. }
  41747. if (textRegion.refinement && !textRegion.refinementTemplate) {
  41748. at = [];
  41749. for (i = 0; i < 2; i++) {
  41750. at.push({
  41751. x: readInt8(data, position),
  41752. y: readInt8(data, position + 1)
  41753. });
  41754. position += 2;
  41755. }
  41756. textRegion.refinementAt = at;
  41757. }
  41758. textRegion.numberOfSymbolInstances = readUint32(data, position);
  41759. position += 4;
  41760. // TODO 7.4.3.1.7 Symbol ID Huffman table decoding
  41761. if (textRegion.huffman) {
  41762. error('JBIG2 error: huffman is not supported');
  41763. }
  41764. args = [textRegion, header.referredTo, data, position, end];
  41765. break;
  41766. case 38: // ImmediateGenericRegion
  41767. case 39: // ImmediateLosslessGenericRegion
  41768. var genericRegion = {};
  41769. genericRegion.info = readRegionSegmentInformation(data, position);
  41770. position += RegionSegmentInformationFieldLength;
  41771. var genericRegionSegmentFlags = data[position++];
  41772. genericRegion.mmr = !!(genericRegionSegmentFlags & 1);
  41773. genericRegion.template = (genericRegionSegmentFlags >> 1) & 3;
  41774. genericRegion.prediction = !!(genericRegionSegmentFlags & 8);
  41775. if (!genericRegion.mmr) {
  41776. atLength = genericRegion.template === 0 ? 4 : 1;
  41777. at = [];
  41778. for (i = 0; i < atLength; i++) {
  41779. at.push({
  41780. x: readInt8(data, position),
  41781. y: readInt8(data, position + 1)
  41782. });
  41783. position += 2;
  41784. }
  41785. genericRegion.at = at;
  41786. }
  41787. args = [genericRegion, data, position, end];
  41788. break;
  41789. case 48: // PageInformation
  41790. var pageInfo = {
  41791. width: readUint32(data, position),
  41792. height: readUint32(data, position + 4),
  41793. resolutionX: readUint32(data, position + 8),
  41794. resolutionY: readUint32(data, position + 12)
  41795. };
  41796. if (pageInfo.height === 0xFFFFFFFF) {
  41797. delete pageInfo.height;
  41798. }
  41799. var pageSegmentFlags = data[position + 16];
  41800. var pageStripingInformatiom = readUint16(data, position + 17);
  41801. pageInfo.lossless = !!(pageSegmentFlags & 1);
  41802. pageInfo.refinement = !!(pageSegmentFlags & 2);
  41803. pageInfo.defaultPixelValue = (pageSegmentFlags >> 2) & 1;
  41804. pageInfo.combinationOperator = (pageSegmentFlags >> 3) & 3;
  41805. pageInfo.requiresBuffer = !!(pageSegmentFlags & 32);
  41806. pageInfo.combinationOperatorOverride = !!(pageSegmentFlags & 64);
  41807. args = [pageInfo];
  41808. break;
  41809. case 49: // EndOfPage
  41810. break;
  41811. case 50: // EndOfStripe
  41812. break;
  41813. case 51: // EndOfFile
  41814. break;
  41815. case 62: // 7.4.15 defines 2 extension types which
  41816. // are comments and can be ignored.
  41817. break;
  41818. default:
  41819. error('JBIG2 error: segment type ' + header.typeName + '(' +
  41820. header.type + ') is not implemented');
  41821. }
  41822. var callbackName = 'on' + header.typeName;
  41823. if (callbackName in visitor) {
  41824. visitor[callbackName].apply(visitor, args);
  41825. }
  41826. }
  41827. function processSegments(segments, visitor) {
  41828. for (var i = 0, ii = segments.length; i < ii; i++) {
  41829. processSegment(segments[i], visitor);
  41830. }
  41831. }
  41832. function parseJbig2(data, start, end) {
  41833. var position = start;
  41834. if (data[position] !== 0x97 || data[position + 1] !== 0x4A ||
  41835. data[position + 2] !== 0x42 || data[position + 3] !== 0x32 ||
  41836. data[position + 4] !== 0x0D || data[position + 5] !== 0x0A ||
  41837. data[position + 6] !== 0x1A || data[position + 7] !== 0x0A) {
  41838. error('JBIG2 error: invalid header');
  41839. }
  41840. var header = {};
  41841. position += 8;
  41842. var flags = data[position++];
  41843. header.randomAccess = !(flags & 1);
  41844. if (!(flags & 2)) {
  41845. header.numberOfPages = readUint32(data, position);
  41846. position += 4;
  41847. }
  41848. var segments = readSegments(header, data, position, end);
  41849. error('Not implemented');
  41850. // processSegments(segments, new SimpleSegmentVisitor());
  41851. }
  41852. function parseJbig2Chunks(chunks) {
  41853. var visitor = new SimpleSegmentVisitor();
  41854. for (var i = 0, ii = chunks.length; i < ii; i++) {
  41855. var chunk = chunks[i];
  41856. var segments = readSegments({}, chunk.data, chunk.start, chunk.end);
  41857. processSegments(segments, visitor);
  41858. }
  41859. return visitor.buffer;
  41860. }
  41861. function SimpleSegmentVisitor() {}
  41862. SimpleSegmentVisitor.prototype = {
  41863. onPageInformation: function SimpleSegmentVisitor_onPageInformation(info) {
  41864. this.currentPageInfo = info;
  41865. var rowSize = (info.width + 7) >> 3;
  41866. var buffer = new Uint8Array(rowSize * info.height);
  41867. // The contents of ArrayBuffers are initialized to 0.
  41868. // Fill the buffer with 0xFF only if info.defaultPixelValue is set
  41869. if (info.defaultPixelValue) {
  41870. for (var i = 0, ii = buffer.length; i < ii; i++) {
  41871. buffer[i] = 0xFF;
  41872. }
  41873. }
  41874. this.buffer = buffer;
  41875. },
  41876. drawBitmap: function SimpleSegmentVisitor_drawBitmap(regionInfo, bitmap) {
  41877. var pageInfo = this.currentPageInfo;
  41878. var width = regionInfo.width, height = regionInfo.height;
  41879. var rowSize = (pageInfo.width + 7) >> 3;
  41880. var combinationOperator = pageInfo.combinationOperatorOverride ?
  41881. regionInfo.combinationOperator : pageInfo.combinationOperator;
  41882. var buffer = this.buffer;
  41883. var mask0 = 128 >> (regionInfo.x & 7);
  41884. var offset0 = regionInfo.y * rowSize + (regionInfo.x >> 3);
  41885. var i, j, mask, offset;
  41886. switch (combinationOperator) {
  41887. case 0: // OR
  41888. for (i = 0; i < height; i++) {
  41889. mask = mask0;
  41890. offset = offset0;
  41891. for (j = 0; j < width; j++) {
  41892. if (bitmap[i][j]) {
  41893. buffer[offset] |= mask;
  41894. }
  41895. mask >>= 1;
  41896. if (!mask) {
  41897. mask = 128;
  41898. offset++;
  41899. }
  41900. }
  41901. offset0 += rowSize;
  41902. }
  41903. break;
  41904. case 2: // XOR
  41905. for (i = 0; i < height; i++) {
  41906. mask = mask0;
  41907. offset = offset0;
  41908. for (j = 0; j < width; j++) {
  41909. if (bitmap[i][j]) {
  41910. buffer[offset] ^= mask;
  41911. }
  41912. mask >>= 1;
  41913. if (!mask) {
  41914. mask = 128;
  41915. offset++;
  41916. }
  41917. }
  41918. offset0 += rowSize;
  41919. }
  41920. break;
  41921. default:
  41922. error('JBIG2 error: operator ' + combinationOperator +
  41923. ' is not supported');
  41924. }
  41925. },
  41926. onImmediateGenericRegion:
  41927. function SimpleSegmentVisitor_onImmediateGenericRegion(region, data,
  41928. start, end) {
  41929. var regionInfo = region.info;
  41930. var decodingContext = new DecodingContext(data, start, end);
  41931. var bitmap = decodeBitmap(region.mmr, regionInfo.width, regionInfo.height,
  41932. region.template, region.prediction, null,
  41933. region.at, decodingContext);
  41934. this.drawBitmap(regionInfo, bitmap);
  41935. },
  41936. onImmediateLosslessGenericRegion:
  41937. function SimpleSegmentVisitor_onImmediateLosslessGenericRegion() {
  41938. this.onImmediateGenericRegion.apply(this, arguments);
  41939. },
  41940. onSymbolDictionary:
  41941. function SimpleSegmentVisitor_onSymbolDictionary(dictionary,
  41942. currentSegment,
  41943. referredSegments,
  41944. data, start, end) {
  41945. var huffmanTables;
  41946. if (dictionary.huffman) {
  41947. error('JBIG2 error: huffman is not supported');
  41948. }
  41949. // Combines exported symbols from all referred segments
  41950. var symbols = this.symbols;
  41951. if (!symbols) {
  41952. this.symbols = symbols = {};
  41953. }
  41954. var inputSymbols = [];
  41955. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  41956. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  41957. }
  41958. var decodingContext = new DecodingContext(data, start, end);
  41959. symbols[currentSegment] = decodeSymbolDictionary(dictionary.huffman,
  41960. dictionary.refinement, inputSymbols, dictionary.numberOfNewSymbols,
  41961. dictionary.numberOfExportedSymbols, huffmanTables,
  41962. dictionary.template, dictionary.at,
  41963. dictionary.refinementTemplate, dictionary.refinementAt,
  41964. decodingContext);
  41965. },
  41966. onImmediateTextRegion:
  41967. function SimpleSegmentVisitor_onImmediateTextRegion(region,
  41968. referredSegments,
  41969. data, start, end) {
  41970. var regionInfo = region.info;
  41971. var huffmanTables;
  41972. // Combines exported symbols from all referred segments
  41973. var symbols = this.symbols;
  41974. var inputSymbols = [];
  41975. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  41976. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  41977. }
  41978. var symbolCodeLength = log2(inputSymbols.length);
  41979. var decodingContext = new DecodingContext(data, start, end);
  41980. var bitmap = decodeTextRegion(region.huffman, region.refinement,
  41981. regionInfo.width, regionInfo.height, region.defaultPixelValue,
  41982. region.numberOfSymbolInstances, region.stripSize, inputSymbols,
  41983. symbolCodeLength, region.transposed, region.dsOffset,
  41984. region.referenceCorner, region.combinationOperator, huffmanTables,
  41985. region.refinementTemplate, region.refinementAt, decodingContext);
  41986. this.drawBitmap(regionInfo, bitmap);
  41987. },
  41988. onImmediateLosslessTextRegion:
  41989. function SimpleSegmentVisitor_onImmediateLosslessTextRegion() {
  41990. this.onImmediateTextRegion.apply(this, arguments);
  41991. }
  41992. };
  41993. function Jbig2Image() {}
  41994. Jbig2Image.prototype = {
  41995. parseChunks: function Jbig2Image_parseChunks(chunks) {
  41996. return parseJbig2Chunks(chunks);
  41997. }
  41998. };
  41999. return Jbig2Image;
  42000. })();
  42001. var bidi = PDFJS.bidi = (function bidiClosure() {
  42002. // Character types for symbols from 0000 to 00FF.
  42003. var baseTypes = [
  42004. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'S', 'B', 'S', 'WS',
  42005. 'B', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  42006. 'BN', 'BN', 'B', 'B', 'B', 'S', 'WS', 'ON', 'ON', 'ET', 'ET', 'ET', 'ON',
  42007. 'ON', 'ON', 'ON', 'ON', 'ON', 'CS', 'ON', 'CS', 'ON', 'EN', 'EN', 'EN',
  42008. 'EN', 'EN', 'EN', 'EN', 'EN', 'EN', 'EN', 'ON', 'ON', 'ON', 'ON', 'ON',
  42009. 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  42010. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'ON', 'ON',
  42011. 'ON', 'ON', 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  42012. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  42013. 'L', 'ON', 'ON', 'ON', 'ON', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'B', 'BN',
  42014. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  42015. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  42016. 'BN', 'CS', 'ON', 'ET', 'ET', 'ET', 'ET', 'ON', 'ON', 'ON', 'ON', 'L', 'ON',
  42017. 'ON', 'ON', 'ON', 'ON', 'ET', 'ET', 'EN', 'EN', 'ON', 'L', 'ON', 'ON', 'ON',
  42018. 'EN', 'L', 'ON', 'ON', 'ON', 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  42019. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  42020. 'L', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  42021. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  42022. 'L', 'L', 'L', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L'
  42023. ];
  42024. // Character types for symbols from 0600 to 06FF
  42025. var arabicTypes = [
  42026. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  42027. 'CS', 'AL', 'ON', 'ON', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'AL',
  42028. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  42029. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  42030. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  42031. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  42032. 'AL', 'AL', 'AL', 'AL', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM',
  42033. 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'AL', 'AL', 'AL', 'AL',
  42034. 'AL', 'AL', 'AL', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN',
  42035. 'AN', 'ET', 'AN', 'AN', 'AL', 'AL', 'AL', 'NSM', 'AL', 'AL', 'AL', 'AL',
  42036. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  42037. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  42038. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  42039. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  42040. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  42041. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  42042. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  42043. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  42044. 'AL', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM',
  42045. 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'ON', 'NSM',
  42046. 'NSM', 'NSM', 'NSM', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  42047. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL'
  42048. ];
  42049. function isOdd(i) {
  42050. return (i & 1) !== 0;
  42051. }
  42052. function isEven(i) {
  42053. return (i & 1) === 0;
  42054. }
  42055. function findUnequal(arr, start, value) {
  42056. for (var j = start, jj = arr.length; j < jj; ++j) {
  42057. if (arr[j] !== value) {
  42058. return j;
  42059. }
  42060. }
  42061. return j;
  42062. }
  42063. function setValues(arr, start, end, value) {
  42064. for (var j = start; j < end; ++j) {
  42065. arr[j] = value;
  42066. }
  42067. }
  42068. function reverseValues(arr, start, end) {
  42069. for (var i = start, j = end - 1; i < j; ++i, --j) {
  42070. var temp = arr[i];
  42071. arr[i] = arr[j];
  42072. arr[j] = temp;
  42073. }
  42074. }
  42075. function createBidiText(str, isLTR, vertical) {
  42076. return {
  42077. str: str,
  42078. dir: (vertical ? 'ttb' : (isLTR ? 'ltr' : 'rtl'))
  42079. };
  42080. }
  42081. // These are used in bidi(), which is called frequently. We re-use them on
  42082. // each call to avoid unnecessary allocations.
  42083. var chars = [];
  42084. var types = [];
  42085. function bidi(str, startLevel, vertical) {
  42086. var isLTR = true;
  42087. var strLength = str.length;
  42088. if (strLength === 0 || vertical) {
  42089. return createBidiText(str, isLTR, vertical);
  42090. }
  42091. // Get types and fill arrays
  42092. chars.length = strLength;
  42093. types.length = strLength;
  42094. var numBidi = 0;
  42095. var i, ii;
  42096. for (i = 0; i < strLength; ++i) {
  42097. chars[i] = str.charAt(i);
  42098. var charCode = str.charCodeAt(i);
  42099. var charType = 'L';
  42100. if (charCode <= 0x00ff) {
  42101. charType = baseTypes[charCode];
  42102. } else if (0x0590 <= charCode && charCode <= 0x05f4) {
  42103. charType = 'R';
  42104. } else if (0x0600 <= charCode && charCode <= 0x06ff) {
  42105. charType = arabicTypes[charCode & 0xff];
  42106. } else if (0x0700 <= charCode && charCode <= 0x08AC) {
  42107. charType = 'AL';
  42108. }
  42109. if (charType === 'R' || charType === 'AL' || charType === 'AN') {
  42110. numBidi++;
  42111. }
  42112. types[i] = charType;
  42113. }
  42114. // Detect the bidi method
  42115. // - If there are no rtl characters then no bidi needed
  42116. // - If less than 30% chars are rtl then string is primarily ltr
  42117. // - If more than 30% chars are rtl then string is primarily rtl
  42118. if (numBidi === 0) {
  42119. isLTR = true;
  42120. return createBidiText(str, isLTR);
  42121. }
  42122. if (startLevel === -1) {
  42123. if ((strLength / numBidi) < 0.3) {
  42124. isLTR = true;
  42125. startLevel = 0;
  42126. } else {
  42127. isLTR = false;
  42128. startLevel = 1;
  42129. }
  42130. }
  42131. var levels = [];
  42132. for (i = 0; i < strLength; ++i) {
  42133. levels[i] = startLevel;
  42134. }
  42135. /*
  42136. X1-X10: skip most of this, since we are NOT doing the embeddings.
  42137. */
  42138. var e = (isOdd(startLevel) ? 'R' : 'L');
  42139. var sor = e;
  42140. var eor = sor;
  42141. /*
  42142. W1. Examine each non-spacing mark (NSM) in the level run, and change the
  42143. type of the NSM to the type of the previous character. If the NSM is at the
  42144. start of the level run, it will get the type of sor.
  42145. */
  42146. var lastType = sor;
  42147. for (i = 0; i < strLength; ++i) {
  42148. if (types[i] === 'NSM') {
  42149. types[i] = lastType;
  42150. } else {
  42151. lastType = types[i];
  42152. }
  42153. }
  42154. /*
  42155. W2. Search backwards from each instance of a European number until the
  42156. first strong type (R, L, AL, or sor) is found. If an AL is found, change
  42157. the type of the European number to Arabic number.
  42158. */
  42159. lastType = sor;
  42160. var t;
  42161. for (i = 0; i < strLength; ++i) {
  42162. t = types[i];
  42163. if (t === 'EN') {
  42164. types[i] = (lastType === 'AL') ? 'AN' : 'EN';
  42165. } else if (t === 'R' || t === 'L' || t === 'AL') {
  42166. lastType = t;
  42167. }
  42168. }
  42169. /*
  42170. W3. Change all ALs to R.
  42171. */
  42172. for (i = 0; i < strLength; ++i) {
  42173. t = types[i];
  42174. if (t === 'AL') {
  42175. types[i] = 'R';
  42176. }
  42177. }
  42178. /*
  42179. W4. A single European separator between two European numbers changes to a
  42180. European number. A single common separator between two numbers of the same
  42181. type changes to that type:
  42182. */
  42183. for (i = 1; i < strLength - 1; ++i) {
  42184. if (types[i] === 'ES' && types[i - 1] === 'EN' && types[i + 1] === 'EN') {
  42185. types[i] = 'EN';
  42186. }
  42187. if (types[i] === 'CS' &&
  42188. (types[i - 1] === 'EN' || types[i - 1] === 'AN') &&
  42189. types[i + 1] === types[i - 1]) {
  42190. types[i] = types[i - 1];
  42191. }
  42192. }
  42193. /*
  42194. W5. A sequence of European terminators adjacent to European numbers changes
  42195. to all European numbers:
  42196. */
  42197. for (i = 0; i < strLength; ++i) {
  42198. if (types[i] === 'EN') {
  42199. // do before
  42200. var j;
  42201. for (j = i - 1; j >= 0; --j) {
  42202. if (types[j] !== 'ET') {
  42203. break;
  42204. }
  42205. types[j] = 'EN';
  42206. }
  42207. // do after
  42208. for (j = i + 1; j < strLength; --j) {
  42209. if (types[j] !== 'ET') {
  42210. break;
  42211. }
  42212. types[j] = 'EN';
  42213. }
  42214. }
  42215. }
  42216. /*
  42217. W6. Otherwise, separators and terminators change to Other Neutral:
  42218. */
  42219. for (i = 0; i < strLength; ++i) {
  42220. t = types[i];
  42221. if (t === 'WS' || t === 'ES' || t === 'ET' || t === 'CS') {
  42222. types[i] = 'ON';
  42223. }
  42224. }
  42225. /*
  42226. W7. Search backwards from each instance of a European number until the
  42227. first strong type (R, L, or sor) is found. If an L is found, then change
  42228. the type of the European number to L.
  42229. */
  42230. lastType = sor;
  42231. for (i = 0; i < strLength; ++i) {
  42232. t = types[i];
  42233. if (t === 'EN') {
  42234. types[i] = ((lastType === 'L') ? 'L' : 'EN');
  42235. } else if (t === 'R' || t === 'L') {
  42236. lastType = t;
  42237. }
  42238. }
  42239. /*
  42240. N1. A sequence of neutrals takes the direction of the surrounding strong
  42241. text if the text on both sides has the same direction. European and Arabic
  42242. numbers are treated as though they were R. Start-of-level-run (sor) and
  42243. end-of-level-run (eor) are used at level run boundaries.
  42244. */
  42245. for (i = 0; i < strLength; ++i) {
  42246. if (types[i] === 'ON') {
  42247. var end = findUnequal(types, i + 1, 'ON');
  42248. var before = sor;
  42249. if (i > 0) {
  42250. before = types[i - 1];
  42251. }
  42252. var after = eor;
  42253. if (end + 1 < strLength) {
  42254. after = types[end + 1];
  42255. }
  42256. if (before !== 'L') {
  42257. before = 'R';
  42258. }
  42259. if (after !== 'L') {
  42260. after = 'R';
  42261. }
  42262. if (before === after) {
  42263. setValues(types, i, end, before);
  42264. }
  42265. i = end - 1; // reset to end (-1 so next iteration is ok)
  42266. }
  42267. }
  42268. /*
  42269. N2. Any remaining neutrals take the embedding direction.
  42270. */
  42271. for (i = 0; i < strLength; ++i) {
  42272. if (types[i] === 'ON') {
  42273. types[i] = e;
  42274. }
  42275. }
  42276. /*
  42277. I1. For all characters with an even (left-to-right) embedding direction,
  42278. those of type R go up one level and those of type AN or EN go up two
  42279. levels.
  42280. I2. For all characters with an odd (right-to-left) embedding direction,
  42281. those of type L, EN or AN go up one level.
  42282. */
  42283. for (i = 0; i < strLength; ++i) {
  42284. t = types[i];
  42285. if (isEven(levels[i])) {
  42286. if (t === 'R') {
  42287. levels[i] += 1;
  42288. } else if (t === 'AN' || t === 'EN') {
  42289. levels[i] += 2;
  42290. }
  42291. } else { // isOdd
  42292. if (t === 'L' || t === 'AN' || t === 'EN') {
  42293. levels[i] += 1;
  42294. }
  42295. }
  42296. }
  42297. /*
  42298. L1. On each line, reset the embedding level of the following characters to
  42299. the paragraph embedding level:
  42300. segment separators,
  42301. paragraph separators,
  42302. any sequence of whitespace characters preceding a segment separator or
  42303. paragraph separator, and any sequence of white space characters at the end
  42304. of the line.
  42305. */
  42306. // don't bother as text is only single line
  42307. /*
  42308. L2. From the highest level found in the text to the lowest odd level on
  42309. each line, reverse any contiguous sequence of characters that are at that
  42310. level or higher.
  42311. */
  42312. // find highest level & lowest odd level
  42313. var highestLevel = -1;
  42314. var lowestOddLevel = 99;
  42315. var level;
  42316. for (i = 0, ii = levels.length; i < ii; ++i) {
  42317. level = levels[i];
  42318. if (highestLevel < level) {
  42319. highestLevel = level;
  42320. }
  42321. if (lowestOddLevel > level && isOdd(level)) {
  42322. lowestOddLevel = level;
  42323. }
  42324. }
  42325. // now reverse between those limits
  42326. for (level = highestLevel; level >= lowestOddLevel; --level) {
  42327. // find segments to reverse
  42328. var start = -1;
  42329. for (i = 0, ii = levels.length; i < ii; ++i) {
  42330. if (levels[i] < level) {
  42331. if (start >= 0) {
  42332. reverseValues(chars, start, i);
  42333. start = -1;
  42334. }
  42335. } else if (start < 0) {
  42336. start = i;
  42337. }
  42338. }
  42339. if (start >= 0) {
  42340. reverseValues(chars, start, levels.length);
  42341. }
  42342. }
  42343. /*
  42344. L3. Combining marks applied to a right-to-left base character will at this
  42345. point precede their base character. If the rendering engine expects them to
  42346. follow the base characters in the final display process, then the ordering
  42347. of the marks and the base character must be reversed.
  42348. */
  42349. // don't bother for now
  42350. /*
  42351. L4. A character that possesses the mirrored property as specified by
  42352. Section 4.7, Mirrored, must be depicted by a mirrored glyph if the resolved
  42353. directionality of that character is R.
  42354. */
  42355. // don't mirror as characters are already mirrored in the pdf
  42356. // Finally, return string
  42357. var result = '';
  42358. for (i = 0, ii = chars.length; i < ii; ++i) {
  42359. var ch = chars[i];
  42360. if (ch !== '<' && ch !== '>') {
  42361. result += ch;
  42362. }
  42363. }
  42364. return createBidiText(result, isLTR);
  42365. }
  42366. return bidi;
  42367. })();
  42368. /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  42369. /* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
  42370. /* Copyright 2014 Opera Software ASA
  42371. *
  42372. * Licensed under the Apache License, Version 2.0 (the "License");
  42373. * you may not use this file except in compliance with the License.
  42374. * You may obtain a copy of the License at
  42375. *
  42376. * http://www.apache.org/licenses/LICENSE-2.0
  42377. *
  42378. * Unless required by applicable law or agreed to in writing, software
  42379. * distributed under the License is distributed on an "AS IS" BASIS,
  42380. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  42381. * See the License for the specific language governing permissions and
  42382. * limitations under the License.
  42383. *
  42384. *
  42385. * Based on https://code.google.com/p/smhasher/wiki/MurmurHash3.
  42386. * Hashes roughly 100 KB per millisecond on i7 3.4 GHz.
  42387. */
  42388. /* globals Uint32ArrayView */
  42389. 'use strict';
  42390. var MurmurHash3_64 = (function MurmurHash3_64Closure (seed) {
  42391. // Workaround for missing math precison in JS.
  42392. var MASK_HIGH = 0xffff0000;
  42393. var MASK_LOW = 0xffff;
  42394. function MurmurHash3_64 (seed) {
  42395. var SEED = 0xc3d2e1f0;
  42396. this.h1 = seed ? seed & 0xffffffff : SEED;
  42397. this.h2 = seed ? seed & 0xffffffff : SEED;
  42398. }
  42399. var alwaysUseUint32ArrayView = false;
  42400. // old webkits have issues with non-aligned arrays
  42401. try {
  42402. new Uint32Array(new Uint8Array(5).buffer, 0, 1);
  42403. } catch (e) {
  42404. alwaysUseUint32ArrayView = true;
  42405. }
  42406. MurmurHash3_64.prototype = {
  42407. update: function MurmurHash3_64_update(input) {
  42408. var useUint32ArrayView = alwaysUseUint32ArrayView;
  42409. var i;
  42410. if (typeof input === 'string') {
  42411. var data = new Uint8Array(input.length * 2);
  42412. var length = 0;
  42413. for (i = 0; i < input.length; i++) {
  42414. var code = input.charCodeAt(i);
  42415. if (code <= 0xff) {
  42416. data[length++] = code;
  42417. }
  42418. else {
  42419. data[length++] = code >>> 8;
  42420. data[length++] = code & 0xff;
  42421. }
  42422. }
  42423. } else if (input instanceof Uint8Array) {
  42424. data = input;
  42425. length = data.length;
  42426. } else if (typeof input === 'object' && ('length' in input)) {
  42427. // processing regular arrays as well, e.g. for IE9
  42428. data = input;
  42429. length = data.length;
  42430. useUint32ArrayView = true;
  42431. } else {
  42432. throw new Error('Wrong data format in MurmurHash3_64_update. ' +
  42433. 'Input must be a string or array.');
  42434. }
  42435. var blockCounts = length >> 2;
  42436. var tailLength = length - blockCounts * 4;
  42437. // we don't care about endianness here
  42438. var dataUint32 = useUint32ArrayView ?
  42439. new Uint32ArrayView(data, blockCounts) :
  42440. new Uint32Array(data.buffer, 0, blockCounts);
  42441. var k1 = 0;
  42442. var k2 = 0;
  42443. var h1 = this.h1;
  42444. var h2 = this.h2;
  42445. var C1 = 0xcc9e2d51;
  42446. var C2 = 0x1b873593;
  42447. var C1_LOW = C1 & MASK_LOW;
  42448. var C2_LOW = C2 & MASK_LOW;
  42449. for (i = 0; i < blockCounts; i++) {
  42450. if (i & 1) {
  42451. k1 = dataUint32[i];
  42452. k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);
  42453. k1 = k1 << 15 | k1 >>> 17;
  42454. k1 = (k1 * C2 & MASK_HIGH) | (k1 * C2_LOW & MASK_LOW);
  42455. h1 ^= k1;
  42456. h1 = h1 << 13 | h1 >>> 19;
  42457. h1 = h1 * 5 + 0xe6546b64;
  42458. } else {
  42459. k2 = dataUint32[i];
  42460. k2 = (k2 * C1 & MASK_HIGH) | (k2 * C1_LOW & MASK_LOW);
  42461. k2 = k2 << 15 | k2 >>> 17;
  42462. k2 = (k2 * C2 & MASK_HIGH) | (k2 * C2_LOW & MASK_LOW);
  42463. h2 ^= k2;
  42464. h2 = h2 << 13 | h2 >>> 19;
  42465. h2 = h2 * 5 + 0xe6546b64;
  42466. }
  42467. }
  42468. k1 = 0;
  42469. switch (tailLength) {
  42470. case 3:
  42471. k1 ^= data[blockCounts * 4 + 2] << 16;
  42472. /* falls through */
  42473. case 2:
  42474. k1 ^= data[blockCounts * 4 + 1] << 8;
  42475. /* falls through */
  42476. case 1:
  42477. k1 ^= data[blockCounts * 4];
  42478. /* falls through */
  42479. k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);
  42480. k1 = k1 << 15 | k1 >>> 17;
  42481. k1 = (k1 * C2 & MASK_HIGH) | (k1 * C2_LOW & MASK_LOW);
  42482. if (blockCounts & 1) {
  42483. h1 ^= k1;
  42484. } else {
  42485. h2 ^= k1;
  42486. }
  42487. }
  42488. this.h1 = h1;
  42489. this.h2 = h2;
  42490. return this;
  42491. },
  42492. hexdigest: function MurmurHash3_64_hexdigest () {
  42493. var h1 = this.h1;
  42494. var h2 = this.h2;
  42495. h1 ^= h2 >>> 1;
  42496. h1 = (h1 * 0xed558ccd & MASK_HIGH) | (h1 * 0x8ccd & MASK_LOW);
  42497. h2 = (h2 * 0xff51afd7 & MASK_HIGH) |
  42498. (((h2 << 16 | h1 >>> 16) * 0xafd7ed55 & MASK_HIGH) >>> 16);
  42499. h1 ^= h2 >>> 1;
  42500. h1 = (h1 * 0x1a85ec53 & MASK_HIGH) | (h1 * 0xec53 & MASK_LOW);
  42501. h2 = (h2 * 0xc4ceb9fe & MASK_HIGH) |
  42502. (((h2 << 16 | h1 >>> 16) * 0xb9fe1a85 & MASK_HIGH) >>> 16);
  42503. h1 ^= h2 >>> 1;
  42504. for (var i = 0, arr = [h1, h2], str = ''; i < arr.length; i++) {
  42505. var hex = (arr[i] >>> 0).toString(16);
  42506. while (hex.length < 8) {
  42507. hex = '0' + hex;
  42508. }
  42509. str += hex;
  42510. }
  42511. return str;
  42512. }
  42513. };
  42514. return MurmurHash3_64;
  42515. })();
  42516. }).call((typeof window === 'undefined') ? this : window);
  42517. if (!PDFJS.workerSrc && typeof document !== 'undefined') {
  42518. // workerSrc is not set -- using last script url to define default location
  42519. PDFJS.workerSrc = (function () {
  42520. 'use strict';
  42521. var scriptTagContainer = document.body ||
  42522. document.getElementsByTagName('head')[0];
  42523. var pdfjsSrc = scriptTagContainer.lastChild.src;
  42524. return pdfjsSrc && pdfjsSrc.replace(/\.js$/i, '.worker.js');
  42525. })();
  42526. }